-
Notifications
You must be signed in to change notification settings - Fork 0
Humanoid Actions
Humanoids are a subclass of entities - specifically, the entities which can walk or otherwise move about. As they are mobile, some system is required to keep track of where they are going, or what they are doing, as well as where or what they will be doing soon. At the moment, an action queue system is employed for this task. This document should assist in understanding how the action system works.
Each humanoid has it's own action queue. An action queue contains one or more actions, with the head of this queue being called the current action. The remainder of the queue holds actions which will probably happen after the current action finishes, though for various reasons they may not happen.
The important things to remember are that the current action has complete control over the humanoid, and the action queue cannot be empty (as otherwise there would be no current action).
There are are three key methods on a Humanoid for manipulating the action queue of said humanoid:
The idea behind this method is for it to erase the entire action queue, and replace it with a new queue containing just the given action. In practice, things aren't usually that simple. To allow for clean termination of the current action, it is more common for some tail of the action queue to be replaced by the given action, and for the remaining actions to be asked asked to finish quickly.
Hence a statement like human:setNextAction(X)
should be interpreted as asking human to finish whatever it is currently doing, forget about anything else it had previously been asked to do, and then do X.
In the most simple case, this method appends the given action onto the end of the existing action queue. In the slightly more complex case, it inserts the given action at some position into the existing action queue. The only complication which arises is when the given action is inserted at the very front of the action queue, thus becoming the current action.
Hence a statement like human:queueAction(X)
should be interpreted as asking human to do X after everything else which it has been asked to do, a statement like human:queueAction(X, N)
for non-zero N should be interpreted as asking human to do X after finishing the N actions at the front of the queue, then continuing with the rest of it's tasks after doing X, and a statement like human:queueAction(X, 0)
should be interpreted as telling human to do X right now, and then go back to doing whatever it was doing (and was going to do) after X is finished.
The method simply removes the current action from the action queue, making the action following it the current action.
From a practical point of view, an action is just a Lua table. As such, it has fields, some of which are mandatory, some of which are optional. The fields with status "Special" are rarely used and often fix a graphical glitch or similar.
Field | Status | Default | Purpose |
---|---|---|---|
name |
Mandatory | n/a | A string giving the general type of the action. Must match one of the names given below. |
must_happen |
Optional | false |
Used for marking an action as being one which should not be removed from the head of the action queue, apart from by being the current action and finishing. |
on_interrupt |
Optional | function () end |
Provides a function to be called in order to try and cause the action to finish earlier than it otherwise would have. |
until_leave_queue |
Optional | nil |
Used for marking an action which should be discarded from the head of the action queue when the humanoid leaves a waiting queue. The value of the field should be the waiting queue in question. |
This action tells the patient to immediately die. As of March 2010 all patients die by going to heaven.
An idle humanoid does not do anything but stand still. By default this action does never end.
Field | Status | Default | Purpose |
---|---|---|---|
count |
Optional | nil | If set the action will last count ticks before ending by itself. If after_use below is set that function will be called before finishing this action. |
loop_callback |
Optional | function () end |
This function is called once the idle action has been initialized. |
after_use |
Optional | function () end |
If this function is set it will be called when the number of ticks according to count has passed, just before ending the current action. Note that if count is not set this function will still be called when the action is interrupted. |
This action makes the patient knock on the door specified. To avoid graphical glitches he/she has to stand next to the door when this action is started.
Field | Status | Default | Purpose |
---|---|---|---|
door |
Mandatory | n/a | The door that the patient should knock on. |
The meander action lets the humanoid walk a little, possibly idle for a while, and then repeat this process over again. Note: If there are no free tiles in the vicinity the humanoid will turn idle instead or, if there are actions in the action queue, move on to the next action.
Field | Status | Default | Purpose |
---|---|---|---|
count |
Optional | "infinity" | By default the humanoid will continue to meander forever, but this field sets how many times it should happen before continuing to the next action. |
loop_callback |
Optional | function() end |
If count is not set a function can be specified that will be called each time a new meander action is about to begin. Note that if this function sets count to 0 one more meander action will still be carried out. |
When two humanoids are about to use an object, this is the action to choose. One of the humanoids get the actual action while the other one should be idling. Interrupting this action when prolonged_usage is set to true
will abort the loop and finish the action in a nice way.
Field | Status | Default | Purpose |
---|---|---|---|
use_with |
Mandatory | n/a | Specifies which other humanoid is involved when using the object . |
object |
Mandatory | n/a | The object to use together with the use_width humanoid. |
prolonged_usage |
Optional | nil | If true the in_use animation of the object will loop until this variable has been changed to false , preferably in the loop_callback function. |
loop_callback |
Optional | function () end |
If this function is set it will be called each time an in_use animation sequence is about to begin and prolonged_usage is still set to true , i.e. no calls if it is not set. |
after_use |
Optional | function () end |
When the object has been used this function is called prior to starting the next action in the humanoid's action queue. |
layer3 |
Special | nil | This field changes layer 3 of the humanoid when the action is underway. |
invisible_phase_span |
Special | nil | In some cases the secondary user should not turn invisible right away (check blood machine for example), so by setting this field to a table with two values the humanoid will only be invisible between those phases. For example phase -3 is begin_use_3 and if this field is set to {-2, 1} the humanoid will be visible in phase -3, turn invisible and then become visible again after phase 1 (finish_use). |
Field | Status | Default | Purpose |
---|---|---|---|
ui |
Mandatory | n/a | The active ui. |
todo_close |
Optional | nil | This window will be closed as soon as the action starts. |
Field | Status | Default | Purpose |
---|---|---|---|
queue |
Mandatory | n/a | The queue to start queueing in. Most often the queue is associated with a room (door), but it could also be any other object. |
x |
Mandatory | n/a | This is the x coordinate of the starting point of the queue. |
y |
Mandatory | n/a | The y coordinate of the starting point of the queue. |
face_x |
Optional | nil | Specifies the x coordinate of the tile relative to the queue starting point the humanoid at the front of the queue should face. |
face_y |
Optional | nil | The y coordinate of the tile mentioned above. |
reserve_when_done |
Optional | nil | This is the door object that should be reserved when the patient is about to enter the associated room. |
Simply tells the patient to try to find a reception nearby and start queueing for it. If the desk is far away the patient will first walk towards it.
This action tells the patient to try to find the specified room. If it is not found and the room is a diagnosis room other possible diagnosis rooms for the patient's disease will be tried, and after that a fax will be created (depending on hospital policy of course). If it is a treatment room and it is not found a fax is sent immediately.
Field | Status | Default | Purpose |
---|---|---|---|
room_type |
Mandatory | n/a | The id of the room to try to find. |
diagnosis_room |
Optional | nil | The diagnosis room that should be found. Both tells the action what room to remove from the list on success, and that other rooms need to be sought on failure. |
Just asks the staff member to try to find a staff room nearby. If none is found nothing will be done either.
Another seek action that tries to find some toilets nearby.
This action is (almost) always the first and last action to be issued for patients.
Field | Status | Default | Purpose |
---|---|---|---|
mode |
Mandatory | n/a | Should be either "spawn" or "despawn" |
point |
Mandatory | n/a | The point ({x, y, direction}) and direction at which to spawn/despawn. If despawning the patient will first go to this point. |
offset |
Optional | {2, 2} |
The offset away from the actual spawn tile the patient should start walking. Only the coordinate in the current walk direction is considered. |
The action issued to receptionists when standing in the reception.
Field | Status | Default | Purpose |
---|---|---|---|
object |
Mandatory | n/a | The object to use. |
prolonged_usage |
Optional | nil | If true the in_use animation of the object will loop until this variable has been changed to false , preferably in the loop_callback function. Not that if it is not set at all, and both begin_use , in_use and finish_use exist for the object it will still be set to true. |
loop_callback |
Optional | function () end |
If this function is set it will be called each time an in_use animation sequence is about to begin and prolonged_usage is still set to true , i.e. no calls if it is not set. |
after_use |
Optional | function () end |
When the object has been used this function is called prior to starting the next action in the humanoid's action queue. |
When a patient is using the screen in rooms this is the active action.
Field | Status | Default | Purpose |
---|---|---|---|
object |
Mandatory | n/a | The screen to use. |
after_use |
Optional | function () end |
When the screen has been used this function is called prior to starting the next action in the patient's action queue. |
When inside a staff room this action is responsible for making staff use various leisure equipment in the room, and tell them when fully rested.
A very common action which tells the humanoid to walk to a specified tile. By default this action truncates the path and ends prematurely if it is interrupted.
Field | Status | Default | Purpose |
---|---|---|---|
x |
Mandatory | n/a | This is the x coordinate of the destination. |
y |
Mandatory | n/a | The y coordinate of the destination. |
no_truncate |
Optional | false | Set to true to force the whole path to be taken before ending the action. |
is_entering |
Optional | false | A flag used when a humanoid is ordered to enter a room. Is automatically set if the createEnterAction function of the room is used. |
is_leaving |
Optional | false | Flag to set when the humanoid is leaving a room. Automatically set if createLeaveAction is used. |
Back to the Home page