[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Hit/Miss formula explanation

Hit/Miss formula explanation

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Oblisgr   (123 posts)  [Biography] bio
Date Sat 01 Feb 2020 06:07 PM (UTC)

Amended on Sat 01 Feb 2020 09:58 PM (UTC) by Fiendish

Message
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;
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sat 01 Feb 2020 10:01 PM (UTC)
Message
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.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #2 on Sat 01 Feb 2020 10:08 PM (UTC)
Message

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...
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Sat 01 Feb 2020 10:13 PM (UTC)

Amended on Sat 01 Feb 2020 10:17 PM (UTC) by Fiendish

Message
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.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #4 on Sun 02 Feb 2020 03:33 PM (UTC)
Message
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);
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Sun 02 Feb 2020 04:00 PM (UTC)
Message
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.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #6 on Sun 02 Feb 2020 04:29 PM (UTC)
Message

  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];
      }
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #7 on Sun 02 Feb 2020 04:40 PM (UTC)
Message
Just read the error message.
Quote:
error: ‘hitroll’ was not declared in this scope

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #8 on Sun 02 Feb 2020 05:13 PM (UTC)
Message
I really dont know how to fix this. If you can help me i will be grateful. I am a very beginer...
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #9 on Sun 02 Feb 2020 06:35 PM (UTC)

Amended on Sun 02 Feb 2020 06:36 PM (UTC) by Fiendish

Message
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?

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Oblisgr   (123 posts)  [Biography] bio
Date Reply #10 on Sun 02 Feb 2020 06:48 PM (UTC)
Message
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.
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #11 on Sun 02 Feb 2020 08:10 PM (UTC)

Amended on Sun 02 Feb 2020 08:16 PM (UTC) by Fiendish

Message
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

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


19,758 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]