From d88f4fb7c0a8600d57652419faa51b175a0aac10 Mon Sep 17 00:00:00 2001 From: Nipun Garg Date: Wed, 3 Jul 2019 05:50:36 +0530 Subject: HDB: Add callbackDoorOpenClose() and use function --- engines/hdb/ai-player.cpp | 4 ---- engines/hdb/ai-use.cpp | 24 ++++++++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/engines/hdb/ai-player.cpp b/engines/hdb/ai-player.cpp index 6a32df5f2d..ca5797c591 100644 --- a/engines/hdb/ai-player.cpp +++ b/engines/hdb/ai-player.cpp @@ -1444,10 +1444,6 @@ void aiNoneInit2(AIEntity *e) { warning("STUB: AI: aiNoneInit2 required"); } -void callbackDoorOpenClose(int x, int y) { - warning("STUB: AI: callbackDoorOpenClose required"); -} - // Utility Functions void aiAnimateStanddown(AIEntity *e, int speed) { if (e->value2-- > 0) diff --git a/engines/hdb/ai-use.cpp b/engines/hdb/ai-use.cpp index 83a294d86a..188244ce1f 100644 --- a/engines/hdb/ai-use.cpp +++ b/engines/hdb/ai-use.cpp @@ -67,10 +67,30 @@ bool AI::useTouchplateOn(AIEntity *e, int x, int y, int targetX, int targetY, in return false; } +void callbackDoorOpenClose(int x, int y) { + int tileIndex = g_hdb->_map->getMapBGTileIndex(x, y); + + // is the door gonna close on something? if so, wait again + if (!g_hdb->_ai->findEntity(x, y)) { + g_hdb->_ai->addCallback(CALLBACK_DOOR_OPEN_CLOSE, x, y, kDelay5Seconds); + return; + } + + g_hdb->_ai->addAnimateTarget(x, y, tileIndex, tileIndex + 3, ANIM_SLOW, false, true, NULL); + if (g_hdb->_map->onScreen(x, y)) + warning("STUB: Play SND_DOOR_OPEN_CLOSE"); + return; +} + // Normal Door bool AI::useDoorOpenClose(AIEntity *e, int x, int y) { - warning("STUB: Define useDoorOpenClose"); - return false; + int tileIndex = g_hdb->_map->getMapBGTileIndex(x, y); + + addAnimateTarget(x, y, tileIndex, tileIndex - 3, ANIM_SLOW, false, true, NULL); + addCallback(CALLBACK_DOOR_OPEN_CLOSE, x, y, kDelay5Seconds); + if (g_hdb->_map->onScreen(x, y)) + warning("Play SND_DOOR_OPEN_CLOSE"); + return true; } void callbackAutoDoorOpenClose(int x, int y) { -- cgit v1.2.3