CODE: Somebody mention Multi-hit? (fwd)

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

From: George <>

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

  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;
      case CLASS_WARRIOR:
	numhits = GET_LEVEL(ch) / HIT_WARRIOR;
      case CLASS_THIEF:
	numhits = GET_LEVEL(ch) / HIT_THIEF;
      case CLASS_MAGIC_USER:
	numhits = GET_LEVEL(ch) / HIT_MAGIC;
        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) {

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


-- Billy  H. Chan
   CogSci/CompSci     ResumeInside

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