Re: Multi-attack for mobs

From: Glenn Campbell (glenn@cgc.ns.ca)
Date: 10/26/95


At 12:00 AM 10/26/95 -0500, you wrote:
>I'm stumped.  I am trying to implement multi-attacks for mobs that is 
>independent of the skill based multi-attack that PCs have.  I have it set up
>as a field in the enhanced mobile field.  I am using Circle3.0 bpl8.
>I altered the code in this manner:
>
>In db.c in function interpret_espec I added a case
>
>  CASE("NumAttacks") {
>    RANGE(1, 10);
>    mob_proto[i].mob_specials.numattacks = num_arg;
>  }
>
>In utils.c I added
>
>  #define GET_MOB_ATT(ch)         ((ch)->mob_specials.numattacks)
>
>In structs.h, in the structure mob_special_data, I added a field
>
>  int numattacks;          /* Number of attacks */
>
>And finally, in fight.c, the relevant code in perform_violence looks like 
>this:
>
>     hit(ch, FIGHTING(ch), TYPE_UNDEFINED);
>     if (FIGHTING(ch) == NULL || ch->in_room != FIGHTING(ch)->in_room) {
>       stop_fighting(ch);
>       continue;
>     } else if (!IS_NPC(ch)) {
>       percent = number(1, 101); /* 101% is complete failure */
>     if (percent < GET_SKILL(ch, SKILL_SECOND_ATTACK))
>       hit(ch, FIGHTING(ch), TYPE_UNDEFINED);
>     } else if (IS_NPC(ch) && GET_MOB_ATT(ch) > 1) {
>       for (j = 2; j < (GET_MOB_ATT(ch) + 1); j++)
>         hit(ch, FIGHTING(ch), TYPE_UNDEFINED);
>     }
>     if (MOB_FLAGGED(ch, MOB_SPEC) && mob_index[GET_MOB_RNUM(ch)].func != 
>NULL)
>       (mob_index[GET_MOB_RNUM(ch)].func) (ch, ch, 0, "");
>   }
> }
>
>The added code is between the first hit function and the if (MOB_FLAGGED)
>statement.
>
>The first else if is for the player.  It works fine.
>The second else if does not work properly.
>
>I sure I defined everything, I can see no flaw in the logic, but I'm getting
>unexpected results.
>
>1. I created a hydra with 9 attacks
>2. I have the hydra attack Puff
>3. Puff gets 9 attacks against the Hydra.  The hydra only gets one.
>4. I have the hydra attack Jupiter.  Both only get one attack.
>
>Based on the result from Puff, I tried to reverse the arguments in hit(), but
>that caused a segmentation fault.  Normally, I view stuff like this as a good
>learning experience (much like my troubles implementing racial maximums), but
>this problem makes no sense to me.
>
>Could someone please point out my mistake, or, better yet, tell me a better
>way of doing it?
>
>

Well , when I coded multiple attacks it was a little tricky at first, but I
used a pretty simple method.

A) I set up mob action bitstrings for 2,3 and 4 attacks
B) I altered perform_violence() in fight.c to do a check like this :

int num_attacks=0;
int counter=0;

        if (MOB_FLAGGED(MOB_2ATTACKS,ch))
          num_attacks+=2
        else counter++;
        if (MOB_FLAGGED(MOB_3ATTACKS,ch))
          num_attacks+=3;
        else counter++;
        if (MOB_FLAGGED(MOB_4ATTACKS,ch))
          num_attacks+=4;
        else counter++

        if (counter==3)
          num_attacks=1;


Below this was the checks for the warrior and thief multiple attacks skills
etc ..
  
      

  As can be seen above, although this method leaves a bit to be desired when
it comes to customizing the number of attacks
I can have mobs that have 1,2,3,4,5,6,7 or 9 attacks. Kinda clugy - but it
was my first hack.  I found that the key to make everything work was that I
do a while loop in the hit() function until num_attacks=0. If I simply
called the hit() function x number of times from perform_violence it didn't
work properly and caused seg faults sometimes. Anyway, this method worked
fine for me and I will probably never have a mob on my mud that has more
than 9 attacks (too much spam). 

Good Luck

Maistro/Malador/Grimlock/Groo

--
  _______________________________________________________________________(_) 
 (_)  Glenn Campbell                   Voice:902-564-3660 (136)
|
 |  |  Computer Systems Specialist      Fax:902-562-6113
|
 |  |  Canadian Coast Guard College     Voice Mail:902-565-6563 (20 second )
|
 |  |_______________________________________________________________________)
 (_)



This archive was generated by hypermail 2b30 : 12/07/00 PST