CODE: Somebody mention Multi-hit? (fwd)

From: Billy H. Chan (bhchan@po.EECS.Berkeley.EDU)
Date: 05/14/96


From: George <gagreer@dragon.ham.muohio.edu>

  Someone mentioned multihitting in relation to a fountain of code or
  something and since it's pretty easy, here goes:

heh, the fount of code (if it could be named such) is in the 
ftp.circlemud.org contrib directory... called Lostlands1.05.tgz 
(orsomething similar).  Based on pl8, modified by yours truly.
On to george's code:
The for(j = 1; j <=4; j++) loop for attacks seems slightly less efficient 
where it is, since it means that you go through combat_list 4 times, and
when there's a great lot of players on, this could equate to lag. (maybe)
Instead, if you move take out that for, and change the if (j > numhits)
to something like while (numhits-- > 0), it should work.  (at least, it
looks similar to the one I'm using).  THe problem with the change is,
though it makes it more efficient (I think), it makes each ch attack their
full amount at one time, where as George's code allows 'staggered'
combat.  (which, if you don't mind the hypothetical extra processor time,
is preferenciably better). (code below, with my comments in [])

 void perform_violence(void) {
  [code snip]

  for (j = 1;j <= 4;j++) {
                 ^^^-- Change the 4 if you add more than 4 attacks/round
[ ^^ THIS FOR IS THE ONE I"M TALKING ABOUT]

  for (ch = combat_list; ch; ch = next_combat_list) {
    next_combat_list = ch->next_fighting;
    switch GET_CLASS(ch) {
      case CLASS_CLERIC:
	numhits = GET_LEVEL(ch) / HIT_CLERIC;
	break;
      case CLASS_WARRIOR:
	numhits = GET_LEVEL(ch) / HIT_WARRIOR;
	break;
      case CLASS_THIEF:
	numhits = GET_LEVEL(ch) / HIT_THIEF;
	break;
      case CLASS_MAGIC_USER:
	numhits = GET_LEVEL(ch) / HIT_MAGIC;
	break;
      default:
        numhits = GET_LEVEL(ch) / HIT_MOB;
    }
    numhits = MAX(1, numhits); << Without this line you will have _0_
				attacks per round (you just sit there)
    if (numhits >= j) {
[    ^^^ CHANGE THIS TO: while (numhits-- > 0) ]
      if (FIGHTING(ch) == NULL || ch->in_room != FIGHTING(ch)->in_room) {
        stop_fighting(ch);
        continue;
      }

      [npc scrambling snip]

      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, "");
  }
}

Note: The {}'s might not line up as I had to cut out some of my custom
      code, but you should get the idea...

-George




-- Billy  H. Chan     bhchan@po.eecs.berkeley.edu  bhchan@csua.berkeley.edu
   CogSci/CompSci     http://www.csua.berkeley.edu/~bhchan     ResumeInside



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