Genius (Programming)
---++ $genius (#9967)
The generic genius is an NPC with the ability to run persistent 'plans' -- verbs which remain suspended for long periods of time, managing the NPC's actions.
Plans are verbs on the NPC of the form 'p_something' -- p_defend(), p_walkto(), etc. These plan verbs can be triggered by external stimuli such as event handlers, or internally generated on the NPC's heartbeat under particular conditions. They can even be called by other plan verbs -- for instance, p_defend() will use p_walkto(), if its target isn't already in the room.
These plan verbs run persistently -- that is, rather than terminating with an action, they queue actions and then suspend themselves, waking up again after the action has completed. This is done by using a different version of :queue_action(), called :plan_action(). This verb takes the same arguments as :queue_action(), with an important difference -- :plan_action() doesn't return until the creature actually finishes the action. It returns 1 or 0 to indicate whether the action actually happened.
Plans are launched by calling genius:change_plan("p_someplanverb", arg, arg...). The extra args are simply passed on to the plan verb to be launched. If a plan is already in progress, :change_plan() will cancel it in favor of the new plan.
Look at the :p_defend() or :p_walkto() code to get an idea of how to write plan code.
-- Main.GilMore - 10 Jun 2004