diff options
author | Nipun Garg | 2019-06-22 08:59:33 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:16:55 +0200 |
commit | c3755f74ceb5f8df2ad15d39d9874be0c2b47b18 (patch) | |
tree | 83e11b333c8b71be5078e93182be3da78ac48088 | |
parent | ab0402622eb48d7df68466c98ff08686b1d46603 (diff) | |
download | scummvm-rg350-c3755f74ceb5f8df2ad15d39d9874be0c2b47b18.tar.gz scummvm-rg350-c3755f74ceb5f8df2ad15d39d9874be0c2b47b18.tar.bz2 scummvm-rg350-c3755f74ceb5f8df2ad15d39d9874be0c2b47b18.zip |
HDB: Add addToActionList() and checkActionList()
-rw-r--r-- | engines/hdb/ai-lists.cpp | 88 | ||||
-rw-r--r-- | engines/hdb/ai.h | 2 | ||||
-rw-r--r-- | engines/hdb/hdb.h | 1 |
3 files changed, 91 insertions, 0 deletions
diff --git a/engines/hdb/ai-lists.cpp b/engines/hdb/ai-lists.cpp index 5165313252..79ad0a6fd8 100644 --- a/engines/hdb/ai-lists.cpp +++ b/engines/hdb/ai-lists.cpp @@ -134,6 +134,94 @@ void AI::animateTargets() { } } +// Add an action location to the list of possible actions +// Each action must be paired with another of the same number +void AI::addToActionList(int actionIndex, int x, int y, char *luaFuncInt, char *luaFuncUse) { + + if (!_actions[actionIndex].x1) { + _actions[actionIndex].x1 = x; + _actions[actionIndex].y1 = y; + if (luaFuncInt[0] != '*') + strcpy(_actions[actionIndex].luaFuncInit, luaFuncInt); + if (luaFuncInt[0] != '*') + strcpy(_actions[actionIndex].luaFuncUse, luaFuncUse); + + if (_actions[actionIndex].luaFuncInit[0]) { + g_hdb->_lua->callFunction(_actions[actionIndex].luaFuncInit, 2); + strcpy(_actions[actionIndex].entityName, g_hdb->_lua->getStringOffStack()); + strcpy(_actions[actionIndex].entityName, g_hdb->_lua->getStringOffStack()); + } + return; + } + + if (!_actions[actionIndex].x2) { + _actions[actionIndex].x2 = x; + _actions[actionIndex].y2 = y; + if (luaFuncInt[0] != '*') + strcpy(_actions[actionIndex].luaFuncInit, luaFuncInt); + if (luaFuncInt[0] != '*') + strcpy(_actions[actionIndex].luaFuncUse, luaFuncUse); + + if (_actions[actionIndex].luaFuncInit[0]) { + g_hdb->_lua->callFunction(_actions[actionIndex].luaFuncInit, 2); + strcpy(_actions[actionIndex].entityName, g_hdb->_lua->getStringOffStack()); + strcpy(_actions[actionIndex].entityName, g_hdb->_lua->getStringOffStack()); + } + return; + } + + warning("Adding a 3rd action to ACTION-%d is illegal", actionIndex); +} + +// Checks if the location passed-in matches an action pair. +// If so, activate it if possible. Returns TRUE for finding pair. +bool AI::checkActionList(AIEntity *e, int x, int y, bool lookAndGrab) { + for (int i = 0;i < kMaxActions;i++) { + if ((_actions[i].x1 == x && _actions[i].y1 == y) || (_actions[i].x2 == x && _actions[i].y2 == y)) { + int targetX = _actions[i].x2; + int targetY = _actions[i].y2; + bool success; + + // Choose target co-ordinates + if (x == targetX && y == targetY) { + targetX = _actions[i].x1; + targetY = _actions[i].y1; + } + + // Is this an actual switch? + uint32 flags = g_hdb->_map->getMapFGTileFlags(x, y); + if (!flags) + flags = g_hdb->_map->getMapBGTileFlags(x, y); + if (!(flags & kFlagSolid) && (_player->tileX != x && _player->tileY != y)) + return false; + // Closing on something? + if (findEntity(targetX, targetY)) + return false; + + success = activateAction(e, x, y, targetX, targetY); + + // If successful, remove action from list + if (success) { + _actions[i].x1 = _actions[i].y1 = _actions[i].x2 = _actions[i].y2 = 0; + + // Call Lua Use function if it exists + if (_actions[i].luaFuncUse[0]) + g_hdb->_lua->callFunction(_actions[i].luaFuncUse, 0); + } else if (e == _player && !checkForTouchplate(x, y)) + addWaypoint(e->tileX, e->tileY, x, y, e->level); + + if (lookAndGrab && e == _player) { + lookAtXY(x, y); + animGrabbing(); + } + + return true; + } + } + + return false; +} + void AI::addToAutoList(int x, int y, const char *luaFuncInit, const char *luaFuncUse) { const char *get; diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index 334725c217..2a1206107e 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -633,6 +633,8 @@ public: void animateTargets(); // List functions + void addToActionList(int actionIndex, int x, int y, char *funcLuaInit, char *funcLuaUse); + bool checkActionList(AIEntity *e, int x, int y, bool lookAndGrab); void addToAutoList(int x, int y, const char *luaFuncInt, const char *luaFuncUse); void autoDeactivate(int x, int y); bool activateAction(AIEntity *e, int x, int y, int targetX, int targetY); diff --git a/engines/hdb/hdb.h b/engines/hdb/hdb.h index 0a3e0a4a1d..bd2f82d880 100644 --- a/engines/hdb/hdb.h +++ b/engines/hdb/hdb.h @@ -69,6 +69,7 @@ enum GameState { }; enum Flag { + kFlagSolid = 0x3, kFlagPlayerDie = 0x8, kFlagInvisible = 0x20, kFlagForeground = 0x80, |