[MUD-Dev] Ticks?

Miroslav Silovic miro at vams.com
Tue Jun 11 12:13:38 CEST 2002


Chris Jacobson wrote:

> AvP:MUD uses an event based system; very few pieces of code is
> allowed to alter hitpoints, and that's "Character::AlterHit()".
> This calls another function (which any other code that alters
> hitpoints must do) which will see if the character's hits and
> moves are below maximum, and if so, start an event.  This event
> will, every X tenth-seconds, pulse a bit of HP into the character.
> Once the character is full, the event is removed.

The efficient way to handle things that change predictably with time
is to create accessor methods for both reading and writing (for
example, GetHit() and SetHit()). Anything that wants to read or
write the hit points will then go via these method. Now, each time
you modify HP, you update the timestamp of the last modification. On
access, you compare the current time with timestamp, set the
timestamp to the current time, and update HP as many times as needed
to catch up; then you return the value. You will also have to update
HP whenever you change some property that modifies the healing speed
(for example, each time you call hunger-tic, which should be much
more rare than healing tic).

The advantage of this is that you only need to heal the mobs that
are in combat and players, which get healed when they get prompted
for input (provided that input prompt prints HP).

This can be generalised to any property that exists on a large
number of objects, changes with time, and is not accessed as often
as it can change.

    Miro


_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev



More information about the mud-dev-archive mailing list