Hit/Miss formula explanation

Posted by Oblisgr on Sat 01 Feb 2020 06:07 PM — 12 posts, 35,667 views.

#0
Can you please explain me the if line?

I believe <diceroll> is something like the dice but i cant find in the rest of the code where is calculated.

Can you help?


if( diceroll == 0 || ( diceroll != 19 && diceroll < thac0 - victim_ac ) )
   {
      /*
       * Miss. 
       */
      if( prof_gsn != -1 )
         learn_from_failure( ch, prof_gsn );
      damage( ch, victim, 0, dt );
      tail_chain(  );
      return rNONE;
Amended on Sat 01 Feb 2020 09:58 PM by Fiendish
USA Global Moderator #1
Quote:
i cant find in the rest of the code where is calculated


This is one of those places where the original coders did something stupid and dangerous.

In fight.c look for lines that say
while( ( diceroll = number_bits( 5 ) ) >= 20 )
The first part of that assigns it the value returned by number_bits( 5 ). Note how it's only one = and not two.
#2

while( ( diceroll = number_bits( 5 ) ) >= 20 )


whats the meaning of < number_bits( 5 ) >
can you please explain me with simple words?

And why i am looking for that:

i made in my damage printf some lines that will print the formula tohit with numbers.

for example:


Rolling dice: 14 - 8 = 6


where 8 is thac0 and 6 the result. i miss the 14 that will be the dice. if you have played ad&d you will understand what i m saying...
USA Global Moderator #3
Quote:
whats the meaning of < number_bits( 5 ) >

number_bits is a function in db.c
It looks like it generates a random number of the given number of bits.
In this case, I guess a random number between 0 and 31, because 2^5 is 32.
Amended on Sat 01 Feb 2020 10:17 PM by Fiendish
#4
so how i call that incide this lines?
i tried %d and hitroll but i get complile error

      snprintf( buf1, 256, "Rolling the dice: %d - %d = %d \n&R[$n] &Wdamages &R[$N] &Wfor &Y[%d] &Whp. \n&B$N's condition:(%d%%)&W", hitroll, vict_thac0, vict_attack, dam, hpcnt);
      snprintf( buf2, 256, "Rolling the dice: %d - %d = %d \n&R[$n] &Wdamages &R[$N] &Wfor &Y[%d] &Whp. \n&B$N's condition:(%d%%)&W", hitroll, vict_thac0, vict_attack, dam, hpcnt);
      snprintf( buf3, 256, "Rolling the dice: %d - %d = %d \n&R[$n] &Wdamages &R[$N] &Wfor &Y[%d] &Whp. \n&B$N's condition:(%d%%)&W", hitroll, vict_thac0, vict_attack, dam, hpcnt);
USA Global Moderator #5
Quote:
but i get complile error

Please provide better information when asking questions. If you get an error, show us the error. If you add some code, show us where.
#6

  Compiling o/fight.o....
fight.c: In function ‘void new_dam_message(CHAR_DATA*, CHAR_DATA*, int, unsigned int, OBJ_DATA*)’:
fight.c:3850:135: error: ‘hitroll’ was not declared in this scope
  "Rolling the dice: %d - %d = %d \n&R[$n] &Wdamages &R[$N] &Wfor &Y[%d] &Whp. \n&B$N's condition:(%d%%)&W", hitroll, vict_thac0, vict_attack, dam, hpcnt);
                                                                                                             ^~~~~~~
fight.c:3850:135: note: suggested alternative: ‘strtoll’
  "Rolling the dice: %d - %d = %d \n&R[$n] &Wdamages &R[$N] &Wfor &Y[%d] &Whp. \n&B$N's condition:(%d%%)&W", hitroll, vict_thac0, vict_attack, dam, hpcnt);
                                                                                                             ^~~~~~~
                                                                                                                                       strtoll
Makefile:101: recipe for target 'o/fight.o' failed
make[1]: *** [o/fight.o] Error 1
Makefile:46: recipe for target 'all' failed
make: *** [all] Error 2



 vs = s_message_table[w_index][d_index];
   vp = p_message_table[w_index][d_index];

   punct = ( dampc <= 30 ) ? '.' : '!';

   int hpcnt;
   hpcnt = victim->hit * 100 / victim->max_hit;
   
   int vict_dice = victim->hitroll;
   int vict_thac0 = victim->mobthac0;
   int vict_attack = vict_thac0 - vict_dice; 

   if( dam == 0 && ( !IS_NPC( ch ) && ( IS_SET( ch->pcdata->flags, PCFLAG_GAG ) ) ) )
      gcflag = TRUE;

   if( dam == 0 && ( !IS_NPC( victim ) && ( IS_SET( victim->pcdata->flags, PCFLAG_GAG ) ) ) )
      gvflag = TRUE;

   if( dt >= 0 && dt < ( unsigned int )num_skills )
      skill = skill_table[dt];

   if( dt == TYPE_HIT )
   {
      snprintf( buf1, 256, "Rolling the dice: %d - %d = %d \n&R[$n] &Wdamages &R[$N] &Wfor &Y[%d] &Whp. \n&B$N's condition:(%d%%)&W", hitroll, vict_thac0, vict_attack, dam, hpcnt);
      snprintf( buf2, 256, "Rolling the dice: %d - %d = %d \n&R[$n] &Wdamages &R[$N] &Wfor &Y[%d] &Whp. \n&B$N's condition:(%d%%)&W", hitroll, vict_thac0, vict_attack, dam, hpcnt);
      snprintf( buf3, 256, "Rolling the dice: %d - %d = %d \n&R[$n] &Wdamages &R[$N] &Wfor &Y[%d] &Whp. \n&B$N's condition:(%d%%)&W", hitroll, vict_thac0, vict_attack, dam, hpcnt);
   }
   else if( dt > TYPE_HIT && is_wielding_poisoned( ch ) )
   {
      if( dt < TYPE_HIT + sizeof( attack_table ) / sizeof( attack_table[0] ) )
         attack = attack_table[dt - TYPE_HIT];
      else
      {
         bug( "Dam_message: bad dt %d from %s in %d.", dt, ch->name, ch->in_room->vnum );
         dt = TYPE_HIT;
         attack = attack_table[0];
      }
USA Global Moderator #7
Just read the error message.
Quote:
error: ‘hitroll’ was not declared in this scope
#8
I really dont know how to fix this. If you can help me i will be grateful. I am a very beginer...
USA Global Moderator #9
Do you have a variable called "hitroll"? Is it inside that function? Maybe you want to use vict_dice instead of hitroll in that sprintf?
Amended on Sun 02 Feb 2020 06:36 PM by Fiendish
#10
I myself added that variable there on checking.vict_hitroll unfortunatelly returns the hitroll score of the mob, not the dice number generated in

while( ( diceroll = number_bits( 5 ) ) >= 20 )


I want to print (if possible) the dice rolled in the upper code.
USA Global Moderator #11
In order to print in the new_dam_message function that diceroll value from the one_hit and projectile_hit functions, you'll need to either store the diceroll value in a global variable or find a way to pass it in through the damage and dam_message functions. In this particular case, I would suggest just using a global variable for expediency.

You won't get far in programming without learning about local and global variable scope. Try reading this resource: https://www.tutorialspoint.com/cprogramming/c_scope_rules.htm