Events, messages and actions¶
This page documents how behaviour runs in Glacier and how objects talk to each other: the event objects the engine attaches to geoms and updates every frame, the ZMSG messages that geoms, events and scene scripts send each other, and the action system that offers 47 doors, pickups and other interactions. Everything here comes from the decompiled source in src/engine/ and src/hitman3/, and the layouts are checked against the debug type dump of extracted/HITMAN3.ELF (analysis/recovered-types.h).
- For geoms, class infos, properties and the serializer, see objects.
- For startup and the main loop that drives the event update, see engine core.
- For 47, actors and AI, see characters.
- For level control, scene loading and saves, see missions.
- For the scene scripts and the conversion of their message payloads on the port, see scene scripts and message payload layouts.
- For the Lua hooks on messages and actions, see the mod API.
Event classes¶
An event is a small object attached to one geom that gives it behaviour: a frame update, a timer, a message handler. The source calls these objects events (ZEventBase), control routines (ZBaseConRout, and the m_Control_Routine_* fields of a geom's event list) and, in scene files, controllers, which ZEngineDataBase::LoadPropertiesRecursive reads from a Controllers container, one ControllerName each.
ZEventBase (src/engine/geomsbase/baseevent.h) derives from RTP::cBase, which gives it a vtable and a property description, and from ZListNode<ZEventBase, 0>, which links it into the engine's update lists. ZBaseConRout adds the class info the factory made it from, and every factory-made event is one. Most classes derive from CBaseEvent<T> (src/engine/geomsbase/cbaseevent.h), whose only addition is a typed view of the geom:
template <class T>
struct CBaseEvent : public ZBaseConRout {
virtual ~CBaseEvent() {}
T &GetGeom() const { return *(T *)m_pBaseGeom; }
};
The type dump lists 206 types derived from ZEventBase. Seventeen are ZBaseConRout and the CBaseEvent<T> and CWinEvent<T> instantiations, which leaves 189 named event classes. The source registers 182 of them with the factory, one ZROUTCLASSINFO each:
| Directory | Registered classes |
|---|---|
src/engine/eventsbase/ (and audio/) |
59 + 11 |
src/hitman3/background/ |
49 |
src/hitman3/levelcontrol/ |
17 |
src/hitman3/gui/ (and menu/system/) |
14 + 1 |
src/hitman3/characters/ |
10 |
src/engine/geomsextend/, src/engine/fysix/ |
6, 6 |
src/engine/zwindows/xmlinterface/system/ |
4 |
src/hitman3/camera/ |
2 |
src/engine/rendervideo/, src/engine/geomsbase/, src/engine/camera/ |
1 each |
CBaseEvent<ZGEOM> has 90 direct subclasses in the source, CBaseEvent<ZGROUP> 12, and CBaseEvent<ZSNDOBJ> and CBaseEvent<ZLIST> 11 each.
Base layout¶
| Offset | Field | Type | Use |
|---|---|---|---|
0x00 |
vtable | 35 slots for ZEventBase, 37 for ZBaseConRout |
|
0x04 |
m_Next, m_Prev |
ZListNode<ZEventBase, 0> |
Position in one of the ten ZEventList lists |
0x0c |
m_Ref |
REF |
Handle into ZEventBuffer |
0x10 |
m_TimerInterval |
float |
Seconds between TimeUpdate calls, 0.1 by default |
0x14 |
m_fTimePassed |
TIMETYPE |
Time of the next TimeUpdate (fixed point, 1/1024 s) |
0x18 |
m_lRoutCases |
uint32 |
ERoutCase bits the event asks for |
0x1c |
m_lEventLists |
uint32 |
ERoutCase bits it is registered for now |
0x20 |
m_ClassCall |
uint8 |
1 for a class-call event that forwards to its geom |
0x21 |
m_Status |
uint8 |
EStatus |
0x22 |
m_lEventAllocSize |
uint16 |
Allocation size in words |
0x24 |
m_pBaseGeom |
ZGEOM * |
Geom the event is attached to |
0x28 |
m_pScheduleEvent |
ZScheduledEvent * |
Scheduler thread, if any |
0x2c |
m_pRoutClassInfo |
ZROUTCLASSINFO * |
ZBaseConRout only; subclass fields start at 0x30 |
Virtual methods¶
Slots 0 to 12 are the destructors and the ZSerializable/RTP::cBase methods (objects); ZEventBase overrides PostLoad (slot 5). A subclass overrides the rest:
| Slot | Method | Base behaviour | Called from |
|---|---|---|---|
| 13 | GetProperties |
returns ZEventBase::Info |
property system |
| 14 | GetEventPriority |
PRIORITY_Normal |
ZEventList::ActivateFrameUpdate |
| 15 to 18 | Init, Init2, PostInit, PostInit2 |
empty | ZEventBase::ChangeStatus |
| 19 | CopyData(ZEventBase *pSource) |
empty | ZGEOM::CopyEvent |
| 20 | EventName |
0; ZBaseConRout returns the routine name |
ZGEOM::FindEvent, saving |
| 21 | ExpandBounds |
empty | ZGEOM::ExpandBounds |
| 22 | PreSaveGame |
empty | ZGEOM::PreSaveGame |
| 23 | RegisterInstance(uint32) |
empty | scene load, with the class's instance count |
| 24, 25 | CheckPointSave, CheckPointLoad |
empty | no recovered caller (see Checkpoints) |
| 26 | Reset |
empty | |
| 27, 28 | TimeUpdate, FrameUpdate |
empty | ZBaseConRout::DoEvent |
| 29 | Command(ZMSG Msg, void *pData) |
returns 0 | ZBaseConRout::DoEvent |
| 30 | DoEvent(int32 lType, int32 lParam, void *pData) |
ZBaseConRout dispatches on lType |
ZEventBase::Call, ZGEOM::CallEvents |
| 31 | End |
empty | ChangeStatus, leaving STATUS_Remove |
| 32 | EditorCommand |
empty | |
| 33 | Remove |
ChangeStatus(this, STATUS_Remove, false) |
event code |
| 34 | SchedUpdate |
empty | DoEvent with ROUTCASE_ScheduleUpdate |
| 35 | InitBaseConRout |
stores the class info and its rout cases | ZFactoryProducer<T>::Create |
| 36 | UnknownCommand |
returns 0 | no recovered caller |
Registration¶
Each class has a static ZROUTCLASSINFO and two ZFactoryProducer objects, one under the class info name and one under the short routine name. From src/engine/eventsbase/relaymessage.cpp:
ZROUTCLASSINFO ZGEOM_RelayMessage_ClassInfo("ZGEOM_RelayMessage", sizeof(ZRelayMessage), 0, "RelayMessage", "ZGEOM", 0, ZEventBase::ROUTCASE_Command, 0);
ZFactoryProducer<ZRelayMessage> ZRelayMessage_Producer("ZGEOM_RelayMessage",
ZGEOM_RelayMessage_ClassInfo);
ZFactoryProducer<ZRelayMessage> ZRelayMessage_Producer2("RelayMessage",
ZGEOM_RelayMessage_ClassInfo);
The arguments are the class info name, the size, a parameter string, the routine name (m_szRoutName, at 0x20 of the 0x34-byte ZROUTCLASSINFO), the geom class name, a priority (m_lPrio) and the starting ERoutCase bits (m_lRoutCases, at 0x2c). No recovered function reads m_lPrio or m_szGeomName back. Five classes (ZScriptC, ZMsgForward, ZCutSeqBlood, ZSetZDefine, ZPostFilterEvent) also pass bit 0x200, which has no name in ERoutCase and which no recovered function tests.
Event memory¶
Events live in their own heap, ZEventBuffer (src/engine/enginedata/eventbuffer.cpp), which ZGeomBuffer::Initialize creates. ZEngineDataBase::CreateGeoms sizes it from SPackedGeomsHeader::StartQuad[7] of the scene plus 0x57800 bytes, at least 0x40000, with other additions for m10_main (0x70800) and m09_main (0x53000).
ZFactoryProducer<T>::Create builds an event with new (eventBuffer) T, and the ZEventBufferTag placement operator new calls AllocEventRam. That rounds the size up to four bytes, stops in the debugger above 0x3ffff, takes a block rounded up to 16 bytes from a ZOffsetAlloc and writes the size in words to m_lEventAllocSize before the constructor runs. The ZEventBase constructor never touches that field. It staggers the first timer, adds the event to the inactive list and takes a REF from m_EventRefs, a ZFixedSizeMemoryManager<ZEventBase *> of 0x2000 slots. While a save game loads, m_DirectRef is set and AllocRefDirect gives the event its saved REF back. ConvEventRefToPtr returns 0 for a freed REF, which is how ZEventBase::Call notices an event that destroyed itself during the call.
static void operator delete(void *pEvent) {
ZDebugBreak();
ZEventBuffer::Instance().FreeEventRam(static_cast<ZEventBase *>(pEvent));
}
Because of this operator delete, every deleting destructor of an event class contains a break. The engine destroys events in ZEventBase::ChangeStatus, which calls the virtual destructor and FreeEventRam itself.
ZEventBuffer::SaveObject writes NumberOfEvents, the live REFs and one REFTypes name per REF: the event's EventName(), "" for a nameless class-call event, or @ when SkipSave finds a ZSkipSaveGroup above its geom. LoadObject deletes events whose REFs are not in the list and recreates missing ones through the factory by name; an empty name makes a bare ZEventBase and @ makes nothing.
Life cycle¶
Attaching to a geom¶
A geom keeps its events in ExGeomData::_Events (ZGEOM::pExData, offset 0x2 of the extension block), a ZGeomEventList of event REFs. One REF is stored directly in three bytes (SGeomEvent_Direct_Id::SetVal breaks on a REF that needs more); a second event moves the list into the shared ZGeomEventListBuffers (up to 256 buffers of 255 entries). ZGEOM has the event API as virtual methods (src/engine/geomsbase/zgeom.cpp):
| Method | What it does |
|---|---|
AddEvent(const char *event_name) |
Factory lookup by name, AttachEvent, then ZEventBase::DoInit |
AttachEvent(ZEventBase &event) |
Sets m_pBaseGeom, creates pExData, adds m_Ref, calls ChangeEventActivity |
FindEvent(const char *), GetEventData |
First event whose EventName() matches, ignoring case |
CopyEvents, CopyEvent |
Recreate each event of another geom by class info name and call CopyData |
EnableClassCall, DisableClassCall, SetClassTimerInterval |
Manage the geom's class-call event |
CallEvents(Type, Param1, Param2, pCaller) |
Deliver an update or a message to the attached events |
FreeEvent, FreeEvents |
Delete one or all events |
RemoveEventFromList |
Called by ~ZEventBase; frees the list when it empties |
ChangeEventsActivity |
ChangeEventActivity on every attached event |
Status¶
m_Status moves up one step at a time in ZEventBase::ChangeStatus, and each step calls one virtual:
EStatus |
Value | Callback on leaving it |
|---|---|---|
STATUS_New |
0 | Init |
STATUS_Init |
1 | Init2 |
STATUS_Init2 |
2 | none |
STATUS_Loaded |
3 | PostInit |
STATUS_PostInit |
4 | PostInit2 |
STATUS_PostInit2 (STATUS_OK) |
5 | none |
STATUS_Remove |
6 | End |
STATUS_End |
7 | destroyed when allowed |
DoInit advances an event to ZEventBase::m_DefaultStatus. That static is STATUS_New while a scene loads (DoUnloadScene resets it), so the events created from the scene's Controllers wait. ZEngineDataBase::AllocSequence runs CreateGeoms (which creates them), Init, the saved game's data when loading one, PostInit and PostInit2. Init sets m_DefaultStatus to STATUS_Init and then STATUS_Init2, and PostInit and PostInit2 set their own status. After each step ZEventList::DoInit collects the REFs of all events and then advances each one still alive. The default stays at STATUS_PostInit2 afterwards, so an event added during play runs all four init callbacks inside AddEvent. ZEventBase::Call and ZGEOM::CallEvents pass updates and messages only to running events, those from STATUS_Init to STATUS_PostInit2 (IsRunning).
Removal¶
Remove() asks for STATUS_Remove without destroying. An event that has not reached STATUS_PostInit2 jumps straight to STATUS_End, and its End never runs. Delete() asks for STATUS_End with destruction allowed. Removing inside a callback is safe: the caller sees the raised status after the call returns and finishes the job (ChangeStatus destroys an event that reached STATUS_End during DoInit, and Call and CallEvents delete one whose status passed STATUS_PostInit2). ZMoveTo (src/engine/eventsbase/moveto.cpp) is a one-shot event built on this. Its Init attaches the geom to the group in m_rGroup and calls Remove(), so DoInit destroys the event as soon as Init returns.
Updates¶
enum ERoutCase {
ROUTCASE_TimeUpdate = 0x8,
ROUTCASE_FrameUpdate = 0x10,
ROUTCASE_Command = 0x20,
ROUTCASE_FrameUpdateWhenPaused = 0x100,
ROUTCASE_ScheduleUpdate = 0x1000
};
m_lRoutCases holds what the event wants and m_lEventLists what it is registered for. ActivateFrameUpdate(bool run_when_pause), ActivateTimeUpdate(float timer_interval) and the Deactivate* functions change the first and call ChangeEventActivity, which reconciles the second. It drops the time, frame and schedule bits while the geom's base geom is not Active(), moves the event between lists in ZEventList, and adds it to or removes it from the scheduler.
The event lists¶
ZEventList (src/engine/enginedata/eventlist.cpp, at 0x30 of ZEngineDataBase) holds ten intrusive lists indexed by EEventPriority (src/engine/camera/basecamera.h). A new event goes to the end of INACTIVE_LIST; activation moves it to the front of the list its GetEventPriority names.
| Value | EEventPriority |
Classes that return it |
|---|---|---|
| 0 | PRIORITY_Normal |
the default |
| 1 | PRIORITY_AboveNormal |
ZHM3LevelControl, the cut sequence classes, CInventory, the in-game menus, ZXMLGUISystem, ZCollisionDamage |
| 2 | PRIORITY_Elevator |
CElevatorHouse |
| 3 | PRIORITY_High |
ZSelectNotify, CElevatorTarget, ZM02_JacuzziShooter |
| 4 | PRIORITY_VeryHigh |
ZVertAnim, ZTextureAnim, ZParamAnim, ZMatPosAnim, CTimeOutDelete |
| 5 | PRIORITY_SuperHigh |
ZAdoptVisibility, ZHM3WeaponUpgradeProperty |
| 6 | PRIORITY_BaseCamera |
ZBaseCamera |
| 7, 8 | PRIORITY_PostFilter, PRIORITY_PostFilterHigh |
the post filter events |
| 9 | INACTIVE_LIST |
events with no frame or time update |
Each frame, unless the engine is frozen (m_bFrozen), ZEngineDataBase::MainLoop calls ScheduledUpdate and then FrameUpdate, which calls ZEventList::FrameUpdate between the game data's PreFrameUpdate and PostFrameUpdate. ZEventList::FrameUpdate walks lists 8 down to 0, so post filters update first and normal events last. For each event it:
- skips it while the game is paused unless it has
ROUTCASE_FrameUpdateWhenPaused, and skips every event but one whileZEventBase::OnlyUpdateMehas setm_pOnlyEventUpdate; - if it is registered for
ROUTCASE_FrameUpdate, calls the geom'sClassFrameUpdatefor a class-call event, orCall(ROUTCASE_FrameUpdate, 0, 0); - if it is registered for
ROUTCASE_TimeUpdateandFrameTime >= m_fTimePassed, addsm_TimerIntervaltom_fTimePassedand callsClassTimeUpdateorCall(ROUTCASE_TimeUpdate, 0, 0).
ZEventList keeps the iterator and the current event in members. RemoveEvent and DeactivateFrameUpdate move the iterator on when they take out the next event to visit, and clear the current event when it leaves during its own frame update, which skips its time update. The constructor and ActivateTimeUpdate set the first deadline to FrameTime + m_TimerInterval * m_fEvenOutTimers and add 0.1 to m_fEvenOutTimers, wrapping at 1.0, so the timers of consecutive events fire a tenth of an interval apart.
A class-call event is a bare ZEventBase with m_ClassCall = 1 (ZEngineDataBase::AllocGeomCallEvent) that ZGEOM::EnableClassCall attaches. It lets a geom class receive ClassFrameUpdate and ClassTimeUpdate without an event class of its own; ZActionArbiter::ClassInit calls EnableClassCall(ZEventBase::ROUTCASE_FrameUpdate).
ROUTCASE_ScheduleUpdate puts the event on ZScheduledUpdate (src/engine/enginedata/scheduledevent.cpp), a cooperative scheduler with 16 priority run lists, a sleeping list sorted by wake time and a cycle budget per frame. Only ZScriptC registers with that bit, and AddEvent gives an event named ScriptC a ZScheduledScript thread; missions covers the scripts that run on it.
Messages¶
Message numbers¶
A ZMSG is a 16-bit number. ZEngineDataBase::RegisterZMsg(const char *pMsgName, uint32 lForcedValue, char *pFile, int32 Line) lowercases the name and looks it up in three places:
- the script message table
ZScriptC_ZMessages(src/engine/zstdlib/zscriptc.cpp, installed byScriptEngine::InstallScriptMessages), a character tree thatScriptEngine::GetRegisterZMessageIDwalks. Its numbers run from 0x800 to 0xb3e; the generated script SDK (port/scriptsdk/include/openblood/engine.h) defines them as 831MSG_*constants, andZMSG_Sizes[831]insrc/engine/zstdlib/zscriptc_messages.cholds each payload size; - the hash of names registered so far;
- a new number from
++m_iNumRegisteredMessages, with the name stored inm_pZMsgStrings[1024], whichGetZMsgNamereads.
So "ActionHide" registered by the engine gets the script number 0x850, the same as MSG_actionhide, while an engine-only name such as "OperateDoor" gets a small number that changes with registration order. src/engine/zstdlib/zscriptc_messages.h names 57 fixed numbers as ZMSG_* constants, among them ZMSG_RequestDoorOpen (0x82f) and the window message ZMSG_WND_MESSAGE (0x8000).
Code gets a number in two ways. It calls g_pEngineData->RegisterZMsg("ScriptEvent", 0, 0, 0) at the point of use (414 calls with a literal name), or it declares a static ZMessageResolver (src/engine/serializerlib/ext_zmsg.h, 396 of them) that converts to uint32. ZEngineDataBase::CreateGeoms resolves every resolver after the scene's geoms exist, and FreeMsgValues clears them. After lowercasing, the literal names in the two forms come to 387 distinct messages.
Sending a message¶
void ZGEOM::SendCommand(ZGEOM *pTarget, ZMSG Msg, void *pData) {
pTarget->ClassCommand(Msg, pData);
pTarget->CallEvents(ZEventBase::ROUTCASE_Command, pData, Msg, this);
}
The other overloads take a target REF, or send to the geom itself with an explicit caller. A geom class handles messages in its ClassCommand override, and an event in its Command override. CallEvents copies the geom's event REFs into a REFTAB32 first, dropping dead ones. For every running event that is not a class-call event and has not been removed, it calls DoEvent(Type, Msg, pData), which ZBaseConRout::DoEvent turns into Command(Msg, pData). A message goes to every running event on the target whatever its m_lRoutCases. If the handler destroyed the target geom, CallEvents stops and returns 0; if it removed the event, CallEvents deletes it. ZGROUP::SendCommandRecursive reaches the group and every geom below it, and ZLIST::SendCommandToList each member of a list.
Payloads¶
pData is untyped, and the sender and receiver agree on its meaning per message. The source uses four conventions:
| Convention | Example |
|---|---|
| Pointer to a struct | ZMSG_RequestDoorOpen carries zmsg_dooropen { REF roperator; } (src/external/j/jamout_hitman3/scriptc/headers/messages/, 100 payload headers) |
| A REF or number cast to a pointer | MSG_ENTERITEMRANGE carries the object's REF, ActivateObject the REF of a ZAction |
| A slot the receiver fills | Action_GetActionList passes an ActionArray **; CanOperateObject passes a ZAction ** and the answer is the value 1 |
| A generic event record | ScriptEvent carries a struct that starts with a name string (SScriptEventPos, SScriptEventRef in zactionarbiter.cpp) |
Relay events¶
Three engine events exist to pass messages along without code:
| Class (routine name) | Fields | Behaviour |
|---|---|---|
ZRelayMessage (RelayMessage) |
m_msgIn 0x30, m_msgOut 0x32, m_rReceiver 0x34, m_bSendRecursive 0x38 |
On m_msgIn, sends m_msgOut to the receiver, recursively when it is a group; with both messages 0 it forwards every message |
ZRelayMessageList (RelayMessageList) |
m_Receivers 0x34, m_fTimeDelay 0x50 |
Sends m_msgOut to every receiver, after m_fTimeDelay seconds through a frame update when the delay is set |
ZMsgForward (MsgForward) |
m_rReceiver 0x30, m_msgFilter 0x34 |
Forwards every message, or only m_msgFilter, to the receiver; the receiver defaults to the parent group |
Scene scripts¶
A scene script runs inside a ZScriptC event (routine name ScriptC, src/engine/eventsbase/scriptc.cpp). ZScriptC::Command delivers a message to each of the event's script threads. A thread whose root script state has SSF_NOMESSAGES set gets nothing, and one with SSF_MESSAGECUE set gets a queued copy of the payload, GetMessageBodySize(Msg) bytes, with duplicates of the same message and bytes dropped. Otherwise the current state controller's ProcessMessage runs, or the first ProcessMessage up the script's m_pParentCreator chain. Scripts send through the service table: SF.SendCommand is ScriptEngine::SendCommand, a normal ZGEOM::SendCommand with the caller resolved from its REF, and SF.SendScriptCommand reaches only the ScriptC events of the target (as ScriptSendCommand does for engine code). Scene scripts describes the handlers' C shape, payload layouts how the port converts payloads at each crossing, and the mod API obm.scripts.send and obm.scripts.on_message.
Actions¶
Two systems carry the name. src/engine/system/actions_new.cpp maps input to named actions, and ZAction (src/engine/eventsbase/action.cpp) is the event that offers an interaction on an object.
Input actions¶
A binding string assigns expressions to names inside named blocks. Action::ZStaticBinds objects (15 in the source) register default strings at static initialisation, the ZActionManager constructor parses them all, and LoadBindings parses the configuration file on top. From src/hitman3/characters/zhitman3inputcontrol.cpp:
static const char *HitmanControlDefs =
"HMControl={ReloadWeapon=tap(kb,r);"
"FireWeapon=hold(ms,left);"
"MoveHor=- get(MoveRight) get(MoveLeft);"
"UseAction=fasttap(kb,e);"
"LeanOutLeft=& hold(kb,z) ! get(LeanOutLeftShoot);"
ZTokenStream reads the keywords tap, hold, release, downedge, fasttap, doubleclick, holddown, clickhold, press, ana, rel, seq, get, true and false and the prefix operators |, &, !, <, >, +, - and *, and ZActionManager::ParseExp builds a tree of 0x40-byte ZActionMapTree nodes from them. Game code reads an action through a static Action::ZHandle (137 in the source) such as Action::ZHandle a_UseAction("UseAction"). ZHandle::CheckMap looks the name up again whenever ZActionManager::m_iSeq has changed since its last lookup, and Digital() or Analog() evaluates the tree, over every game controller when controllers are joined. Devices and polling belong to engine core.
Object actions¶
ZAction is a CBaseEvent<ZGEOM> of 0xfc bytes, registered as ZGEOM_Action. Game code adds one with ZAction::AddAction(pGeom, szActionName, szOptionName, eType, msgMessage, rReceiver, lPriority, rItemTemplate), which calls pGeom->AddEvent("ZGEOM_Action"), localises the name and stores the rest.
| Offset | Field | Use |
|---|---|---|
0x30 |
m_eType |
EActionType |
0x34, 0x38 |
m_msgMessage, m_rReceiver |
Message sent when a generic or place action runs, and its target |
0x3c |
m_lPriority |
Weight in 47's choice |
0x48 |
m_lActionControl |
ACTIONCONTROL_Hidden 1, ACTIONCONTROL_OutOfRange 2, ACTIONCONTROL_Disabled 4 |
0x4c |
m_bIsMaster |
This action owns the geom's action array |
0x5c |
m_NearObjects |
Up to two characters in range |
0x68, 0x6c |
m_szOriginalString, m_szActionName |
Name key and localised name |
0x70, 0xf4 |
m_ActionArray, m_pActiveActionArray |
ZStackArray<32, ZAction *> and the array this action belongs to |
0xf8 |
UserData |
Item template REF |
EActionType (src/engine/eventsbase/action.h) has 42 types from AT_PICKUP to AT_STEALTAPE; AT_LAST (42) doubles as AT_COMBINE in zhitman3actioncontrol.h. The classes that add actions in code:
| Source | Types |
|---|---|
src/hitman3/background/doors.cpp (CDoorBase::PostInit2, priority 400) |
AT_OPERATEDOOR |
src/engine/geomsextend/zitem.cpp |
AT_PLACEITEM, AT_RETRIEVEITEM |
src/hitman3/background/elevator.cpp |
AT_ELEVATORBUTTON, AT_CLIMBHATCH, AT_STRANGELINELEVATOR |
src/hitman3/characters/hm3actor.cpp |
AT_CLOTHES |
bodycontainer.cpp, keycardreader.cpp, lightswitch.cpp, placebomb.cpp, placeitemtopos.cpp, vcr.cpp, FriskBox.cpp |
AT_BODYCONTAINER, AT_USEKEYCARD, AT_USELIGHTSWITCH, AT_PLACEBOMB, AT_PLACEITEMTOPOS, AT_STEALTAPE, AT_SURRENDWEAPON |
actiontoggle.cpp, src/hitman3/levelcontrol/levelcontrolm10.cpp |
AT_GENERIC |
How an action is offered¶
ZAction::Initmarks the action out of range and asks its geom for an array withAction_GetActionList. The first action on a geom gets no answer, becomes the master and uses its ownm_ActionArray; later actions join it. The master registers with the scene'sZActionController, anActionControllerlist geom created on demand, whose REF is in the scene COM valuerActionController.ZHitman3::ClassInit2registers 47 withZActionController::AddEvaluator(four evaluators at most). Each evaluator gets aZDistCheckcopy that sorts up to 1024 master actions into eight distance bands (band 0 nearer than 500 units, band n up to500 << n, band 7 unbounded) and re-sorts one band per frame, chosen so near bands come round more often.ZActionController::FrameUpdatecallsZAction::FrameUpdate(activator)on a fifth (rounded up) of the nearest band per frame, round robin.UpdateObjectsInRangetests every action in the array withInRange. A hidden or disabled action is never in range and anAT_ALWAYSINRANGEone always is; otherwise the player decides throughCanOperateObject(ZHitman3::CanOperateObjectfor 47), and anyone else through aCanOperateObjectmessage. It sets or clearsACTIONCONTROL_OutOfRangeand sendsACTIONCHANGEto the geom on a change.- When any action is in range, the master sends
MSG_ENTERITEMRANGEwith its geom's REF to the character, which adds it to its near items (ZLNKWHANDS::AddNearItem);MSG_LEAVEITEMRANGEremoves it again.
How 47 chooses and runs one¶
ZHitman3::GetNearestActionObject asks each near item for its array and scores every action that is not hidden, out of range, disabled, a pickup or a change of clothes as fDev * priority / fDist. fDist is the distance to the object and fDev the dot product of the offset with the first three floats of 47's root matrix, over fDist. ZHM3ActionControl::Update takes the winner, lets special cases take over (human shield, suitcase, body disposal, leaving a keyhole or closet), and maps the EActionType to one of 60 EHM3Action values. For AT_OPERATEDOOR, GetCurrentActionDoorContextEnum picks eOpenDoor, eCloseDoor, eUnLockDoor or eLookKeyhole from the door's state.
When the UseAction input fires, ZHM3ActionControl::ActOnCurrentAction handles 44 of those values itself. A door gets ZMSG_RequestDoorOpen or ZMSG_RequestDoorClose with a zmsg_dooropen or zmsg_doorclose payload, and an elevator button or eTalk gets the action's m_msgMessage. For the rest (pickup, clothes, drag, grab, generic) ZHitman3::ActOnAction calls ZHitman3::OperateObject, a switch on the type whose default calls ZAction::RunMultiple. That runs every action in the array with the same name. For AT_GENERIC and AT_PLACEITEM (after a PlaceItem2 message to the activator), ZAction::Run sends m_msgMessage to m_rReceiver with the activator's REF. ZHitman3::ClassCommand also runs an action whose REF arrives with an ActivateObject message, once CanOperateObject agrees. Messages to the geom change its actions at run time: ActionHide and ActionShow (registered in ZAction::Initialize) hide and show its actions, ActionRemove removes them, and the master handles EnableAction, DisableAction and RemoveNamedAction by name.
ZActionToggle (src/hitman3/background/actiontoggle.cpp) puts the pieces together. Init2 adds an AT_GENERIC action whose receiver is its own geom. When 47 runs it, the action sends m_msg1 to that geom, ZActionToggle::Command forwards it to m_rReceiver (to every member of a list, or recursively into a group), hides the action, swaps in the second name and message, and uses ActivateTimeUpdate to show it again after m_fDelay seconds.
ZActionArbiter (src/engine/geomsextend/zactionarbiter.cpp) is a ZLIST geom class that coordinates the actors in its list. Its methods broadcast a named message or a ScriptEvent to the members (BroadcastMessage, BroadcastMessagePos, BroadcastMessageClosestN), send ReportNewTarget script events to the members (at once to those within m_fWarnRange of an attacker in AttackingTarget, or to all of them m_fBroadCastDelay seconds after BroadcastTarget), and throttle on-screen warnings sent to the scene COM's rIngameBriefer (MSG_DISPWARNING, MSG_DISPINFO).
Cut sequences and timed behaviour¶
A cut sequence is a list geom with a CCutSequenceList event (src/engine/eventsbase/cutsequence.cpp), whose members are sequence lists with a CCutSequence event each; the list asks for their fStart and fEnd (in frames) with a CutSequenceRequestData message. CutSequence_Start or CutSequence_StartScene, with the activating geom as payload, starts it, or queues it while the scene COM value HitmanDisabled is set, 47's death sequence runs or another full-screen sequence plays. CCutSequenceEvent subclasses (CCutSequenceCommand, CExternCutSequenceCommand, CCutSequenceShowHide, CCutsequenceShowSubtitle) find the CutSequenceList event on their geom in Init2 and register by m_iFrameNr in a sorted table. CCutSequenceList::FrameUpdate counts 25 frames per second from m_fStartTime, starts and stops each sequence's objects at its frames, and calls Run on every event whose frame has passed; CCutSequenceCommand::Run sends m_msgMessage with m_lParameter to a receiver given by REF, by name or by scene COM value. At the end, or when DropCutSequence or DropCutSequence2 is pressed and released on a sequence without m_bMustFinish, it sends CutSequence_LastFrame (after CutSequence_Cancel for a skip) to the activator and to its own geom. In cutsequence2.cpp, ZCutSequenceCamera plays recorded camera cuts (SCut records of SKeyFrame position, orientation and field of view), and ZCutSequencePlayer walks its list in pairs of a cut sequence list and a camera, sending CutSequence_Start to the first and CutSequence_StartScene to the second.
Everything else that waits uses the event machinery above: a TimeUpdate with m_TimerInterval, an update that compares FrameTime with a stored deadline (ZRelayMessageList::FrameUpdate, ZActionToggle::TimeUpdate), or a script thread sleeping in the scheduler.
Checkpoints¶
ZEventBase has CheckPointSave and CheckPointLoad slots, and ZCheckVisible::CheckPointLoad is the only override (it clears its seers' visibility flags). ZCheckVisible::Init registers itself with g_pGameData->AddEventToCheckPoint(this), but ZGameData::AddEventToCheckPoint, CheckPointSave and CheckPointLoad are empty, and ZHM3GameData keeps those slots (tools/vtable_evidence.py ZHM3GameData). ZGEOM::CheckPointSave and CheckPointLoad are empty too. ZCheckPointBuffer (src/engine/enginedata/checkpointbuffer.cpp) has only read operators, src/engine/enginedata/checkpoint.cpp is empty, and no recovered function calls the event slots. Saved games go through the serializer instead; missions covers them.