From 12a677d9007b93893fab0c223a297a5a5c207693 Mon Sep 17 00:00:00 2001 From: Nipun Garg Date: Tue, 25 Jun 2019 00:31:03 +0530 Subject: HDB: Add legalMove functions --- engines/hdb/ai-funcs.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ engines/hdb/ai.h | 4 ++- 2 files changed, 80 insertions(+), 1 deletion(-) (limited to 'engines') 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::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(); -- cgit v1.2.3