diff options
author | Nipun Garg | 2019-06-25 00:31:03 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:16:59 +0200 |
commit | 12a677d9007b93893fab0c223a297a5a5c207693 (patch) | |
tree | 749d286b611ca9a15992ddc3de78a26479270217 | |
parent | 4be327e39470ffc35611e5746895540a8820a899 (diff) | |
download | scummvm-rg350-12a677d9007b93893fab0c223a297a5a5c207693.tar.gz scummvm-rg350-12a677d9007b93893fab0c223a297a5a5c207693.tar.bz2 scummvm-rg350-12a677d9007b93893fab0c223a297a5a5c207693.zip |
HDB: Add legalMove functions
-rw-r--r-- | engines/hdb/ai-funcs.cpp | 77 | ||||
-rw-r--r-- | engines/hdb/ai.h | 4 |
2 files changed, 80 insertions, 1 deletions
diff --git a/engines/hdb/ai-funcs.cpp b/engines/hdb/ai-funcs.cpp index 4f6bf35a2b..4d265d1e8d 100644 --- a/engines/hdb/ai-funcs.cpp +++ b/engines/hdb/ai-funcs.cpp @@ -1375,6 +1375,83 @@ int AI::checkForTouchplate(int x, int y) { return 0; } +AIEntity *AI::legalMove(int tileX, int tileY, int level, int *result) { + uint32 bgFlags = g_hdb->_map->getMapBGTileFlags(tileX, tileY); + uint32 fgFlags = g_hdb->_map->getMapFGTileFlags(tileX, tileY); + AIEntity *hit = findEntity(tileX, tileY); + + if (hit && hit->state != STATE_FLOATING) + // If player and entity are not at the same level, are they on stairs? + if (hit->level != level) + if (level == 1 && !(bgFlags & kFlagStairTop)) + hit = NULL; + else if (level == 1 && !(bgFlags & kFlagStairBot)) + hit = NULL; + + if (level == 1) { + if (bgFlags & kFlagSolid) { + *result = 0; + return hit; + } + + if (bgFlags & (kFlagWater | kFlagSlime)) { + if (hit && hit->state == STATE_FLOATING) { + *result = 1; + return NULL; + } else + *result = 0; + return hit; + } else + *result = 1; + } else { + if (fgFlags & kFlagSolid) { + *result = 0; + return hit; + } else if (fgFlags & kFlagGrating) { + *result = 1; + return hit; + } else if (fgFlags & kFlagSolid) { + *result = 0; + return hit; + } + + if (bgFlags & (kFlagWater | kFlagSlime | kFlagPlummet)) { + if (hit && hit->state == STATE_FLOATING) { + *result = 1; + return NULL; + } else + *result = 0; + return hit; + } else + *result = 1; + } + return hit; +} + +AIEntity *AI::legalMoveOverWater(int tileX, int tileY, int level, int *result) { + uint32 bgFlags = g_hdb->_map->getMapBGTileFlags(tileX, tileY); + uint32 fgFlags = g_hdb->_map->getMapFGTileFlags(tileX, tileY); + AIEntity *hit = findEntity(tileX, tileY); + + if (level == 1 ? (bgFlags & kFlagMonsterBlock) : (!(fgFlags &kFlagGrating) && ((fgFlags & kFlagSolid) || (bgFlags & kFlagMonsterBlock)))) + *result = 0; + else + *result = 1; + return hit; +} + +AIEntity *AI::legalMoveOverWaterIgnore(int tileX, int tileY, int level, int *result, AIEntity *ignore) { + uint32 bgFlags = g_hdb->_map->getMapBGTileFlags(tileX, tileY); + uint32 fgFlags = g_hdb->_map->getMapFGTileFlags(tileX, tileY); + AIEntity *hit = findEntityIgnore(tileX, tileY, ignore); + + if (level == 1 ? (bgFlags & kFlagMonsterBlock) : (!(fgFlags &kFlagGrating) && ((fgFlags & kFlagSolid) || (bgFlags & kFlagMonsterBlock)))) + *result = 0; + else + *result = 1; + return hit; +} + bool AI::checkFloating(int x, int y) { for (Common::Array<AIEntity *>::iterator it = _floats->begin(); it != _floats->end(); it++) { if ((*it)->tileX == x && (*it)->tileY == y) diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index e228ebd499..04c20187d3 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -646,7 +646,9 @@ public: void moveEnts(); int checkForTouchplate(int x, int y); - + AIEntity *legalMove(int tileX, int tileY, int level, int *result); + AIEntity *legalMoveOverWater(int tileX, int tileY, int level, int *result); + AIEntity *legalMoveOverWaterIgnore(int tileX, int tileY, int level, int *result, AIEntity *ignore); void addAnimateTarget(int x, int y, int start, int end, AnimSpeed speed, bool killAuto, bool inMap, const char *tileName); void animateTargets(); |