Re: Delay Structure

From: Wolfram Schroeder (ws@Informatik.Uni-Bremen.DE)
Date: 10/09/95


I did not implement any general system for the task you described but
several similar things, like coaches etc. There are 2 methods of doing
so: 1) Through ticks and 2) Through ticks but in a trickier way :-)

1) Set up a new tick in comm.c where mobile_activity is called in a
   similar manner. You would implement a function which is called and
   goes e.g. through every playing character in the MUD, checking a
   field called maybe delay_mode if it has a value which yields activity.
   The code should then look like this:

    switch(ch->specials.delayed_mode) {
    case DELAYED_MODE_WARN_EXPLODE:
	warn_explode(ch);
        ch->specials.delayed_mode = DELAYED_MODE_ABOUT_TO_EXPLODE;
        break;
    case DELAYED_MODE_ABOUT_TO_EXPLODE:
	explode(ch);
        ch->specials.delayed_mode = DELAYED_MODE_NONE;
        break;

    (other funny things here)
    }

   This is the straight-forward solution suitable for maybe two or three
   different delayed commands, but not suitable for a large amount of
   delays, since this would lead to coarse code and it suffers from various
   problems like: How to deal with characters going away ? How to handle
   object's activity which is delayed (a bomb which is about to explode is
   a delay in the object, not in the char) etc. etc. Now, let's switch to

2) the trickier way to do this is to set up a resizable array of
   timer-functions+delays and to hanlde them in a tick. You need functions to
   add a timerfunction like add_timer(function*, delay) and sureley a
   function like the above in comm.c, say timer_activity(). What you do there
   is to decrease every delay variable in the mentioned array function+delay
   and to call the timer-function via the function-pointer in the array if
   it becomes 0. Afterwards you remove the entry in the array, indeed.
   Additionally, a set of void* should be in the array for parameter passing
   to the timer-function.

   This is the general way to handle delays and activity based on ticks,
   but has several flaws as well: 1) the timerfunction will have to know
   what it is dealing with, and if it still exist etc. etc. and 2) the
   stuff is not that easy to implement.

Well, good luck, and report if you found or have been told a better way,

Wolfram Schroeder
Karl@Realm of Magic (p106.informatik.uni-bremen.de 4000)

-------------------------------------------------------------------------------
 ||      |  //""                                 Send your flames, opinions,
 ||     ||  \\_.                                 ideas and deepest thoughts 
 || /\\ ||   `"\\                                to the address besides.
 `_// \_''  \..// @informatik.uni-bremen.de



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