cthulu3/
cthulu3/backup/
cthulu3/distribution/
cthulu3/gods/
cthulu3/html/help/basic/
cthulu3/html/help/skills/
cthulu3/log/
cthulu3/player/
<HTML>
<HEAD>
<TITLE>CthulhuMud - Events</TITLE>
</HEAD>
<BODY LINK="#0000ff" VLINK="#800080" BACKGROUND="paper.jpg">
<CENTER>
<HR>
<H1>CthulhuMud - Events</H1>
<HR>
[ <A HREF="index.html">Index</A> ]
<HR>
</CENTER>
<P>An event is an encapsualtion of something that has happened within the 
mud.
Events consists of a description of the occurance combined with the 
<A HREF="context.html">context</A> that the event occured within.</P>
<P>Events are routed to all mobs in all involved rooms, all mobs 
<A HREF="monitor.html">monitoring</A> those rooms and maybe some objects.
Eventually the events wind up at mobs who view them and react to them.
Players are shown the text within the event that is relevent to them (this is
primarily how they receive all of their successful action notifications). 
Mobs pass the event through triggers, which may cause the mob to run a script 
in response to the event.</P>
<HR>
<H2>Information Contained in an Event</H2>
<P>Each event contains the following:</P>
<DL>
<DT><B>event type</B> (integer)
<DD>This indicates the general nature of the event.
<DT><B>event subtype</B> (integer)
<DD>This is a more specific indication of the nature of the event.
<DT><B>event context</B> (<A HREF="context.html">context</A>)
<DD>This contains details of the mobs, objects directions, location and other
things involved in the event.
<DT><B>actors message</B> (string)
<DD>This is a text message, with substitution parameters, that should be sent
to the actor.
It will only be formatted and sent if the actor is a player.
<DT><B>victims message</B> (string)
<DD>This is a text message, with substitution parameters, that should be sent
to the victim.
It will only be formatted and sent if the victim is a player.
<DT><B>observers message</B> (string)
<DD>This is a text message, with substitution parameters that should be sent
to everyone observing the event who is neither the victim nor the actor.
It is only formatted and sent for observers who are players.
</DL>
<P>The master numbers for event types and subtypes are defined in the 
<I>wev.h</I> file.
<HR>
<H2>Event Routing - Challanges and Reactions</H2>
<H3>Generating Events</H3>
<P>Events are generated by things happening, generally mobs trying to do things.
<P>When a mob attempts an action, its parms are processed and resolved.
A context describing the involved parties and the parameters of the action is 
then created.
An event is then created, based upon the context, but adding the event description
and the messages. 
The event is then issued as a Challange Event.
<H3>Challange Events</H3>
<P>At this point the action described has not happened and if any mob in the
room (or <A HREF="monitor.html">monitoring</A> the room) has a 
challange trigger which matches it, the action will be denied.
That is to say that the action will not occur and the command processing
will simply end.</P>
<P>It is up to the mob whose challange trigger matched the event to run a 
script and provide an explanation to the player of why their action
was disallowed.
The MPSTOP command can be useful here.</P>
<H3>Action</H3>
<P>If action was not denied it will now occur.</P>
<P>The event will then be issued again, this time as a Reaction Event.</P>
<H3>Reaction Events</H3>
<P>The reaction event describes the completed event and will be sent to all
mobs in the room (and who are monitoring the room).
Players will be sent the appropriate formatted message, while mobs get
to run the events through their reaction triggers to see if they want to
react to it.</P>
<H3>Exceptions</H3>
<P>There are, of couse a number of exceptions to the above flows.</P>
<UL>
<LI>When a character arrives in a room, there is no challange event.
A mob in a room cannot stop a mob in another room from entering their 
room.
There is a challange event for the departure of the mob though.
<P>This arrival reaction event is <I>in addition</I> to the depart reaction event 
that was issued in the rom that the moving mob left.<P>
<LI>Time and pulse events are sent directly from the update() code to the
mobs who wish to receive them.
They are not routed through rooms.
<LI>OOC communication events are sent directly to to the players concerned,
without any routing through rooms or mobs.
Mobs cannot react to OOC communications.
<LI>Wide area IC communication events (Shout and Scream) are routed to all rooms 
(and all mobs within those rooms) where they can be heard.
This allows mobs in those rooms (or monitoring those rooms) to hear and 
react to those events (but is fairly expensive CPU wise).
<LI>In combat the attack event is only issued as a challange, mainly to reduce
message clutter.
It will always be followed by another combat event that describes the result
of the attack.
<LI>Death events are issued reaction only.
It is not possible for a mob to deny someone permission to die.
<LI>If one of the objects or actors would be destoryed by the action,
the distruction is delayed until after the reaction event has been
processed.
This lets mobs and players examine the thing being destroyed.
</UL>
<HR>
<H2>Example Event Flows</H2>
<P>In this example a character (Chen) walks into a room containg a mob (Orc)
whom he then attacks.
He injures the Orc, parries the Orcs blow and then kills the Orc before 
looting and sacrificing its corpse.</P>
<P>The events generated are:</P>
<OL>
<LI>Arrive, walking, Chen
<LI>Look, room, Chen
<LI>Look, mob, Chen, Orc
<LI>Combat, attack, Chen, Orc (challange only)
<LI>Combat, hit, Chen, Orc, 35
<LI>Damage, hurt, Orc, Chen, 35 
<LI>Combat, attack, Orc, Chen (challange only)
<LI>Combat, parry, Chen, Orc
<LI>Combat, attack, Chen, Orc (challange only)
<LI>Combat, hit, Chen, Orc, 42
<LI>Damage, hurt, Orc, Chen, 42
<LI>Damage, injured, Orc, Chen, -12
<LI>Death, slain, Orc, Chen (reaction only)
<LI>Get, item_from_container, Chen, Sword, Corpse of Orc
<LI>Get, gold_from_container, Chen, Corpse of Orc, 25
<LI>Sacrifice, npc_corpse, Chen, Corpse of Orc
</OL>
<P>The <I>damage, hurt</I> events are issued when a mob takes damage greater
than 25% of its hit points (the number is the ammount of damage the mob 
suffered).
The <I>Damage, injured</I> events are issued when a mob has less than 25%
of its hit points left (the number is the number of hit points the mob has 
left).
Not that for these events 9and the death event), then actor and victim roles
are switched from the attack that caused the wound.
This is because the acts here are being seriously injured and dieing.</P>
<HR>
<H2>Performance Concerns</H2>
<P>Yes, this is a lot of work.
But it runs very efficiently, being mainly pointer manipulation and
integer comparisons.
The triggers and scripts are considerably more efficient than many other 
mobprog implementations (no interpreted progs to parse).
Memory thrashing is avoided by reusing the same blocks of memory over and
over.
Typically the entire mud will have only ever allocate 2 or 3 event or context
structures.</P> 
<P>It gets expensive when:</P>
<UL>
<LI>Wevs are sent to lots of rooms or a room contains lots of mobs.
Shout and scream are (at the moment) the worse for this, although some of
the wide area echo commands may be worse once they are converted.
<LI>Mobs with triggers that check the text associated with the event which
are placed in rooms where a lots of such events are generated.
An example might be a mob which responses to a character saying something IC
being in a room where players traditionally hang out and idly talk together.
In general text based checks are much more expensive than integer or
pointer based ones.
<LI>People with bad language skills participating in IC conversations.
This is because the text message formatting routine will run garble code
on what they say for every recipient (with the amount of garbling depending 
upon the skills of both the speaker and the listener).
</UL>
<HR>
[ <A HREF="index.html">Index</A> ]
</BODY>
</HTML>