Aggro Part III

Two updates in a single night!  The gods must be crazy.

Or at least the IMMs.

Anyway, as I pointed out last time, calling check_aggressive() in char_to_room() in handler.c turned out to be a bad idea.  In testing, a character would move into a room, get smacked, and then look.  Additionally, certain mob scripts called for a character to be pushed out of a room if he wasn’t welcome.  So the character would move into the room, get smacked, and then get pushed out.  Again, not what I intended.

Solution after the jump.

The solution was fairly obvious, although a little work intensive: find out how characters move, and add the aggro check that way.

A quick search of the .c files found a number of places where characters moved: mob scripts, loading mobs, loading characters, immortal AT command, immortal GOTO command, immortal TRANSFER command, and a lot of other ways.

So I decided instead to limit the attacking mob to voluntary movement by either the character or the mob.

Characters generally only voluntarily move from one room to another in three ways: fleeing, moving (typing n/s/e/w/u/d), or spells.  Everything else is involuntary.  It seems unnecessarily punitive to force a character to a location (say, do_transfer) and causing him to be hit right away.  May as well give him a chance to get away (at least, before mobile_actions is called and the aggro mob sees him).

Same goes for characters or mobiles loading into a room.  Players get a chance to run away.  Not much (10 seconds), but it’s still a chance.

I should also note that the do_flee function actually calls the same subfunction as normal movement, so that’s another problem solved.

Therefore, the required coding is in very few places, in act.movement only 1 place (2 if you have portals):

check_aggressive(ch);
 /*---------------------------------------------------------------------*/
 /* End: Post-move operations. */

If you have put in my portal code (which uses do_enter), search for “look_at_room” and make your code look like this:

look_at_room(ch, 0);
entry_memory_mtrigger(ch);
greet_mtrigger(ch, -1);
greet_memory_mtrigger(ch);
check_aggressive(ch);
return;

Next, move in to spells.c (which contains all of the manual spells) and search for “look_at_room”, and add the check_aggressive(ch); line nearby (preferably after looking at the room).  This should be in three places: recall, teleport, and summon.  I’ve also added one spell that moves a character (doorway, like a focused teleport), so if you’ve got any of these, make sure you add a check there as well.

That should do it.  Questions or comments are welcome.

Leave a comment