[MUD-Dev] [TECH] Event Queue System

John Robert Arras johna at wam.umd.edu
Fri Feb 15 14:27:00 CET 2002


the_sage2000 at juno.com wrote:

>  1) Has anyone implemented an event queue system and can give me
>  advise on doing it?
 
>  2) Can anyone give me more information on it than what I am about
>  to present?
 
>  3) Is the way I'm going to present it totally wrong?

<snip event queue description>

I tried something that appears less flexible, but it seems simpler
to start with:

The world is filled with things and they each have a list of events
on them that are mainly there for cleanup when the thing gets
destroyed or changes state requiring ongoing activities to stop. The
events are in a global table of lists/heaps such that one list gets
checked every pulse vs the internal game time. All of the events
with times <= game_time fire.

I don't have events for every little tiny thing that the game
objects can do. I use them for large-scale hard-coded routines that
many things will use such as:

  combat_update   (every couple of seconds)
  track_update    (every couple of seconds)
  thing_update    (every 10 seconds)
  hour_update     (every 80 seconds)

that can be applied to things when they're created, or when they
change state. 

When an event is added to a thing, it gets added to the thing's
list, and it gets added to the table an appropriate number of steps
into the future, so it fires later on.

All things get an hour_update and this deals with removing flags and
other "hourly" timers from things. This update also makes timed
items disappear.

Things that can move or fight get a thing_update (roughly speaking
these are mobs). This updates hps healing, and lets them wander
around, or if they're in a society, they may mine for some metals
and things like that.

If a thing that can fight gets into a fight, it gets a combat_update
event given to it and it fights a round of combat every 2 seconds or
so.

If a thing starts moving or tracking or pathfinding, it gets a
track_event added to it that attempts to move it one space every
couple of seconds.

These are the basic events. They take the global all-at-once updates
and spread them out so each event updates itself and schedules its
next update. You could use haste and slow here in interesting ways.

Then, there are extra events like command events where you delay a
command and you interrupt the command execution if the thing gets
disturbed.

As a side note: This let me do something neat-looking that's very
simple to code now. When a mob is attacked, it may yell for help. If
you're in a room with sleeping allies of that mob, they will wake up
slowly at random times rather than having them all stand up at once
and attack.

There are ways to do this with function pointers or a really good
internal softcode language so you can get much more generality in
the events code from the get-go, but I didn't do that. My internal
script language is, ahem, "limited", and has its own event queue.

John



_______________________________________________
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