Re: Spell Delay

From: Gary Barnett (gbarnett@POLARNET.COM)
Date: 09/21/97


On Sunday, September 21, 1997 10:40 AM, Tim Davis [SMTP:ar782@CHEBUCTO.NS.CA]
wrote:
> Ok.  I need to do the following:
>
> (casting a spell)
>
> 500hp 500mn 500mv> cast 'create water' wineskin
> You rub your hands and intone mystical phrases
>
> 500hp 500mn 500mv>
> You point at a empty wineskin.
>
> 500hp 480mn 500mv>
> You ~~cast~~ create water
>
> 500hp 480mn 500mv>
> A wineskin is filled
>
> Ok, im not asking for the code for create water.  :)
> What i am asking for is a means by which to make the character wait a
> round before each step in casting.  Could this be accomplised using the
> delay function defined in one of the C library Headers (dont know which
> one)?
> I already experimented with creating a loop that would have the same
> effect, but it just lagged the WHOLE mud.  :)

I did something like this for my recipe system, and the fast affects
system and timed scripts and aiming and ..

(you'll lots of places to put in event queus, imho -- They are a lot of fun
for the players.)

The way I did it was to create two linked lists.

List 1: List of pointers to characters who are performing actions.

struct event_user_data {
  struct char_data *char;
  struct event_user_data *next;
};

(global) struct event_user_data *event_users;

List 2: List of actions being performed by a character.
 struct event_data {
    sh_int duration;
    sh_int command;
    sh_int subcmd;
    sh_int misc
    struct char_data *vict;
    struct obj_data *obj;
 }
 (char_specials) struct event_data *events

Then you need a routine to be called in heartbeat once a second
to update all the actions. Another routine called every once in a
while can serve to cleanup the old events. I do it this way because
it makes the code less complex. Also put a check in extract_char
to clean up your queue.

Just run through the first list looking for characters to process, and
then process their lists, aging out the old ones and sending
messages, or the like, for the ones still in progress. Skip each event
if it's duration is 0 (it's waiting to be purged)

As far as adding a new event, just add them to list 1, if they aren't
already there, then add the event to list 2 with the proper info.

In your example above you could define a command type to cast the
spell, and as it's duration decreases, the code could send messages,
and so on, then when it's duration reaches 0 it completes the spell.

Take a look at the event queue code on the ftp site. Play with it,
extend it and modify it. Then junk it and use the knowledge to create
a queue system for your mud that handles what you want to be able
to do, and includes the capability to grow as you add new features to
it.

Performance is an issue here, as the routine has to be called once a
second and with a large number of events could take a considerable
amount of time to process them all. Good tight code is warranted.

my $0.02

--Mallory



I can picture in my mind a world without war, a world without hate.
And I can picture us attacking that world, because they'd never
expect it.     - Jack Handey


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



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