From 761c90e62a1c7f01d38420834119a4fa697a3950 Mon Sep 17 00:00:00 2001 From: Nipun Garg Date: Thu, 27 Jun 2019 22:29:49 +0530 Subject: HDB: Add functions related to _callbacks --- engines/hdb/ai-lists.cpp | 29 +++++++++++++++++++++++++++++ engines/hdb/ai.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/engines/hdb/ai-lists.cpp b/engines/hdb/ai-lists.cpp index 389b3ab880..a8598863a2 100644 --- a/engines/hdb/ai-lists.cpp +++ b/engines/hdb/ai-lists.cpp @@ -434,6 +434,35 @@ bool AI::autoActive(int x, int y) { return false; } +CallbackDef allCallbacks[] = { + {NO_FUNCTION, NULL}, + {AI_BARREL_EXPLOSION_END, aiBarrelExplosionEnd}, + {CALLBACK_DOOR_OPEN_CLOSE, callbackDoorOpenClose}, + {CALLBACK_AUTODOOR_OPEN_CLOSE, callbackAutoDoorOpenClose}, + {CALLBACK_END, NULL} +}; + +void AI::addCallback(CallbackType type, int x, int y, int delay) { + for(int i= kMaxCallbacks; i >= 0; i--) + if (_callbacks[i].type == NO_FUNCTION) { + _callbacks[i].type = type; + _callbacks[i].x = x; + _callbacks[i].y = y; + _callbacks[i].delay = delay; + return; + } +} + +void AI::processCallbackList() { + for (int i = 0; i < kMaxCallbacks; i++) + if (_callbacks[i].type != NO_FUNCTION) { + allCallbacks[_callbacks[i].type].function(_callbacks[i].x, _callbacks[i].y); + _callbacks[i].type = NO_FUNCTION; + _callbacks[i].x = _callbacks[i].y = 0; + return; + } +} + void AI::addToLuaList(int x, int y, int value1, int value2, char *luaFuncInit, char *luaFuncAction, char *luaFuncUse) { for (int i = 0; i < kMaxLuaEnts; i++) { if (!_luaList[i].luaFuncInit[0] && !_luaList[i].luaFuncAction[0] && !_luaList[i].luaFuncUse[0]) { diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index 6f5653ad6c..690e868fa7 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -752,6 +752,8 @@ public: bool activateAction(AIEntity *e, int x, int y, int targetX, int targetY); bool checkAutoList(AIEntity *e, int x, int y); bool autoActive(int x, int y); + void addCallback(CallbackType type, int x, int y, int delay); + void processCallbackList(); void addToLuaList(int x, int y, int value1, int value2, char *luaFuncInit, char *luaFuncAction, char *luaFuncUse); bool checkLuaList(AIEntity *e, int x, int y); bool luaExistAtXY(int x, int y); -- cgit v1.2.3