Re: Auto DHIT

From: Con (raro94ab@hp4.econ.cbs.dk)
Date: 06/04/96


On Tue, 4 Jun 1996, Tarot wrote:

> Ok, call me a moron, but does anyone know why this code (from the end of
> fight.c) causes the mud to crash?
> 
> /* Auto DHIT */
>     if (GET_LEVEL(ch) >= 15 && GET_CLASS(ch) == CLASS_WARRIOR && !IS_NPC(ch)) 
>       hit(ch, FIGHTING(ch), TYPE_UNDEFINED);
> /* end of Auto DHIT */
>     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, "");
> I think I might have missed something earlyer in the code, but not quite
> sure.  I player hits and then Dhits then the prompt appears and the mud crashes.

Hehe, well, the obvious thing I'd suggest is to make a check like

if FIGHTING(ch)
  blah blah, for each of the hit() calls.. 

The reason why the mud crashes is 99% sure because of you not checking. I 
can't remember if the perform_violence() routine checks for the fact 
wether or not you're fighting at the beginning, but even if it does so, 
here is the reason why you crash:

By calling perform_violence (which was set up as a single attack procedure)
you'r char is 'cleared', as beeing able to fight.

then you call the first hit(), and it does the hit stuff.. but 
coincidence does, that the mob/char you fight dies (which means the 
char_data structire FIGHTING(ch) is reffering to, no longer exists), so 
now you call it once again (dual hit:), and as you call the hit() 
procedure with somethign that does not exist (In real code I just think 
it refferences to a code segment which the program no longer owns), the 
mud will SEGFAULT..

bottom line, add a if(FIGHTING(ch)) at each hit() call..

Regards,
Con.

d.
--
     Rasmus Rønlev DOEK'94      WWW: http://www.econ.cbs.dk/people/raro94ab  
     Student instructor         MUD: exiled.mud.circlemud.org 5000
                                         199.199.16.100 5000
       Student, B.Sc in Computer Science and Business Administration. 



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