diff options
author | Nipun Garg | 2019-06-25 09:25:10 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:17:00 +0200 |
commit | dc0ad525cdad76368689282aab3772e5a5e464b5 (patch) | |
tree | ffac3b78363c767dd0c0419b58133d3e7509c1ff /engines/hdb | |
parent | 69235618f248167f81054eaa599d53b1062f13fc (diff) | |
download | scummvm-rg350-dc0ad525cdad76368689282aab3772e5a5e464b5.tar.gz scummvm-rg350-dc0ad525cdad76368689282aab3772e5a5e464b5.tar.bz2 scummvm-rg350-dc0ad525cdad76368689282aab3772e5a5e464b5.zip |
HDB: Add _teleporters related functions
Diffstat (limited to 'engines/hdb')
-rw-r--r-- | engines/hdb/ai-lists.cpp | 170 | ||||
-rw-r--r-- | engines/hdb/ai.h | 135 |
2 files changed, 239 insertions, 66 deletions
diff --git a/engines/hdb/ai-lists.cpp b/engines/hdb/ai-lists.cpp index e2961029a4..3d1e235740 100644 --- a/engines/hdb/ai-lists.cpp +++ b/engines/hdb/ai-lists.cpp @@ -434,6 +434,176 @@ bool AI::autoActive(int x, int y) { return false; } +void AI::addToTeleportList(int teleIndex, int x, int y, int dir, int level, int anim, int usable, const char *luaFuncUse) { + if (!level) + level = 1; + + if (!_teleporters[teleIndex].x1) { + _teleporters[teleIndex].x1 = x; + _teleporters[teleIndex].y1 = y; + _teleporters[teleIndex].dir1 = (AIDir)dir; + _teleporters[teleIndex].level1 = level; + _teleporters[teleIndex].anim1 = anim; + _teleporters[teleIndex].usable1 = usable; + strcpy(_teleporters[teleIndex].luaFuncUse1, luaFuncUse); + if (_teleporters[teleIndex].luaFuncUse1[0] == '*') + _teleporters[teleIndex].luaFuncUse1[0] = 0; + _numTeleporters++; + return; + } + if (!_teleporters[teleIndex].x2) { + _teleporters[teleIndex].x2 = x; + _teleporters[teleIndex].y2 = y; + _teleporters[teleIndex].dir2 = (AIDir)dir; + _teleporters[teleIndex].level2 = level; + _teleporters[teleIndex].anim2 = anim; + _teleporters[teleIndex].usable2 = usable; + strcpy(_teleporters[teleIndex].luaFuncUse2, luaFuncUse); + if (_teleporters[teleIndex].luaFuncUse2[0] == '*') + _teleporters[teleIndex].luaFuncUse2[0] = 0; + _numTeleporters++; + return; + } + + warning("addToTeleporterList: Adding a 3rd teleporter is illegal"); +} + +bool AI::findTeleporterDest(int tileX, int tileY, SingleTele *info) { + for (int i = 0;i < _numTeleporters; i++) { + if ((_teleporters[i].x1 == tileX) && (_teleporters[i].x1 == tileY)) { + info->anim = _teleporters[i].anim2; + info->x = _teleporters[i].x2; + info->y = _teleporters[i].y2; + info->dir = _teleporters[i].dir2; + info->level = _teleporters[i].level2; + info->usable = _teleporters[i].usable2; + return true; + } + if ((_teleporters[i].x1 == tileX) && (_teleporters[i].x1 == tileY)) { + info->anim = _teleporters[i].anim1; + info->x = _teleporters[i].x1; + info->y = _teleporters[i].y1; + info->dir = _teleporters[i].dir1; + info->level = _teleporters[i].level1; + info->usable = _teleporters[i].usable1; + return true; + } + } + return false; +} + +bool AI::checkTeleportList(AIEntity *e, int x, int y) { + for (int i = 0; i < kMaxTeleporters; i++) { + if ((_teleporters[i].x1 == x && _teleporters[i].y1 == y) || (_teleporters[i].x2 == x && _teleporters[i].y2 == y)) { + int targetX = _teleporters[i].x1; + int targetY = _teleporters[i].y1; + int targetX2 = _teleporters[i].x2; + int targetY2 = _teleporters[i].y2; + AIDir dir1 = _teleporters[i].dir1; + AIDir dir2 = _teleporters[i].dir2; + int level1 = _teleporters[i].level1; + int level2 = _teleporters[i].level2; + int usable1 = _teleporters[i].usable1; + int usable2 = _teleporters[i].usable2; + int anim1 = _teleporters[i].anim1; + int anim2 = _teleporters[i].anim2; + const char *luaFuncUse1 = _teleporters[i].luaFuncUse1; + const char *luaFuncUse2 = _teleporters[i].luaFuncUse2; + + // Choose which set of co-ordinates is the target + if (x != targetX || y != targetY) { + targetX = _teleporters[i].x2; + targetY = _teleporters[i].y2; + targetX2 = _teleporters[i].x1; + targetY2 = _teleporters[i].y1; + dir1 = _teleporters[i].dir2; + dir2 = _teleporters[i].dir1; + level1 = _teleporters[i].level2; + level2 = _teleporters[i].level1; + usable1 = _teleporters[i].usable2; + usable2 = _teleporters[i].usable1; + anim1 = _teleporters[i].anim2; + anim2 = _teleporters[i].anim1; + luaFuncUse1 = _teleporters[i].luaFuncUse2; + luaFuncUse2 = _teleporters[i].luaFuncUse1; + } + + // We must be exactly on the teleporter + if (abs(targetX*kTileWidth - e->x) > 2 || abs(targetY*kTileHeight - e->y) > 2) + return false; + + // Can this teleporter be used? + if (usable1) + return false; + + // Move Entity to new Spot, then walk forward one tile + e->tileX = targetX2; + e->tileY = targetY2; + e->x = targetX2 * kTileWidth; + e->y = targetY2 * kTileHeight; + e->xVel = e->yVel = 0; + e->goalX = e->goalY = 0; + e->animFrame = 0; + e->drawXOff = e->drawYOff = 0; + e->dir = dir2; + e->level = level2; + + if (luaFuncUse2[0]) + g_hdb->_lua->callFunction(luaFuncUse2, 0); + + e->draw = e->standdownGfx[0]; + if (e == _player) { + memset(&_waypoints[0], 0, sizeof(_waypoints)); + _numWaypoints = 0; + } + + switch (e->dir) { + case DIR_UP: + setEntityGoal(e, e->tileX, e->tileY - 1); + break; + case DIR_DOWN: + setEntityGoal(e, e->tileX, e->tileY + 1); + break; + case DIR_LEFT: + setEntityGoal(e, e->tileX - 1, e->tileY); + break; + case DIR_RIGHT: + setEntityGoal(e, e->tileX + 1, e->tileY); + break; + case DIR_NONE: + warning("checkTeleporterList: DIR_NONE found"); + break; + } + + g_hdb->_map->centerMapXY(e->x + 16, e->y + 16); + + // Start up Teleport flash animation only if value1 is set to 1 + if (anim1 == 1 || anim2 == 2) { + addAnimateTarget(e->x, e->y, 0, 7, ANIM_NORMAL, false, false, "teleporter_flash_sit"); + warning("STUB: checkTeleporterList: Play SND_TELEPORT"); + } + + // PANIC ZONE Teleports? + warning("STUB: checkTeleporterList: Toggle Panic Zone"); + + // Is there an attack gem still floating around? + for (Common::Array<AIEntity *>::iterator it = _ents->begin(); it != _ents->end(); it++) { + if ((*it)->type == AI_GEM_ATTACK) { + int amt = getGemAmount(); + setGemAmount(amt + 1); + removeEntity(*it); + break; + } + } + + _playerEmerging = true; + return true; + } + } + + return false; +} + void AI::addToPathList(int x, int y, int type, AIDir dir) { ArrowPath *arrowPath = new ArrowPath; diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index 5761fe4506..a099deeca2 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -386,7 +386,7 @@ struct AIEntity { uint16 goalX, goalY; // where we're trying to go - TILE COORDS uint16 touchpX, touchpY, touchpTile, touchpWait; // ACTION index a touchplate is using, which you're on uint32 stunnedWait; // if we're stunned, this is the delay before being normal again - uint16 sequence; // to use for specially-coded sequences + int16 sequence; // to use for specially-coded sequences char entityName[32]; // the name of the entity, as registered by the Lua init function for the entity char printedName[32]; // the name of the entity/item, the way it should be printed @@ -702,6 +702,9 @@ 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 addToTeleportList(int teleIndex, int x, int y, int dir, int level, int anim, int usable, const char *luaFuncUse); + bool checkTeleportList(AIEntity *e, int x, int y); + bool findTeleporterDest(int tileX, int tileY, SingleTele *info); void addToPathList(int x, int y, int type, AIDir dir); ArrowPath *findArrowPath(int x, int y); @@ -896,71 +899,71 @@ public: // These variables hold the tile-indices set // in ai-init.cpp - int _useSwitchOff; // the door opening switch - int _useSwitchOn; // state, when opened - int _useHolderEmpty; // cell holding switch - int _useHolderFull; // state, when full - int _useSwitch2Off; // another switch - int _useSwitch2On; // state, when opened - int _useMailsorter; // mailsorter entity - int _useAskcomp; // askcomp entitiy - int _useTeleporter; // teleporter entity - int _useHandswitchOn; // 2-sided handswitch - int _useHandswitchOff; // 2-sided handswitch - - int _targetDoorN; // horz SILVER door - int _targetDoorP; // horz BLUE door - int _targetDoorS; // horz RED door - int _targetDoorNv; // vert SILVER door - int _targetDoorPv; // vert BLUE door - int _targetDoorSv; // vert RED door - - int _targetDoor2N; // horz SILVER door - int _targetDoor2P; // horz BLUE door - int _targetDoor2S; // horz RED door - int _targetDoor2Nv; // vert SILVER door - int _targetDoor2Pv; // vert BLUE door - int _targetDoor2Sv; // vert RED door - - int _target2DoorN; // horz SILVER door - int _target2DoorP; // horz BLUE door - int _target2DoorS; // horz RED door - int _target2DoorNv; // vert SILVER door - int _target2DoorPv; // vert BLUE door - int _target2DoorSv; // vert RED door - - int _target3DoorN; // horz SILVER door - int _target3DoorP; // horz BLUE door - int _target3DoorS; // horz RED door - int _target3DoorNv; // vert SILVER door - int _target3DoorPv; // vert BLUE door - int _target3DoorSv; // vert RED door - - int _targetBridgeU; // bridge extending UP - int _targetBridgeD; // bridge extending DOWN - int _targetBridgeL; // bridge extending LEFT - int _targetBridgeR; // bridge extending RIGHT - - int _targetBridgeMidLR; // bridge grating plank LEFT/RIGHT - int _targetBridgeMidUD; // bridge grating plank UP/DOWN - int _touchplateOn; // touchplate ON - int _touchplateOff; - int _templeTouchpOn; // touchplate ON - int _templeTouchpOff; - int _blockpole; // blockpole - - int _kcHolderWhiteOff; // keycard holders - int _kcHolderWhiteOn; - int _kcHolderBlueOff; - int _kcHolderBlueOn; - int _kcHolderRedOff; - int _kcHolderRedOn; - int _kcHolderGreenOff; - int _kcHolderGreenOn; - int _kcHolderPurpleOff; - int _kcHolderPurpleOn; - int _kcHolderBlackOff; - int _kcHolderBlackOn; + int _useSwitchOff; // the door opening switch + int _useSwitchOn; // state, when opened + int _useHolderEmpty; // cell holding switch + int _useHolderFull; // state, when full + int _useSwitch2Off; // another switch + int _useSwitch2On; // state, when opened + int _useMailsorter; // mailsorter entity + int _useAskcomp; // askcomp entitiy + int _useTeleporter; // teleporter entity + int _useHandswitchOn; // 2-sided handswitch + int _useHandswitchOff; // 2-sided handswitch + + int _targetDoorN; // horz SILVER door + int _targetDoorP; // horz BLUE door + int _targetDoorS; // horz RED door + int _targetDoorNv; // vert SILVER door + int _targetDoorPv; // vert BLUE door + int _targetDoorSv; // vert RED door + + int _targetDoor2N; // horz SILVER door + int _targetDoor2P; // horz BLUE door + int _targetDoor2S; // horz RED door + int _targetDoor2Nv; // vert SILVER door + int _targetDoor2Pv; // vert BLUE door + int _targetDoor2Sv; // vert RED door + + int _target2DoorN; // horz SILVER door + int _target2DoorP; // horz BLUE door + int _target2DoorS; // horz RED door + int _target2DoorNv; // vert SILVER door + int _target2DoorPv; // vert BLUE door + int _target2DoorSv; // vert RED door + + int _target3DoorN; // horz SILVER door + int _target3DoorP; // horz BLUE door + int _target3DoorS; // horz RED door + int _target3DoorNv; // vert SILVER door + int _target3DoorPv; // vert BLUE door + int _target3DoorSv; // vert RED door + + int _targetBridgeU; // bridge extending UP + int _targetBridgeD; // bridge extending DOWN + int _targetBridgeL; // bridge extending LEFT + int _targetBridgeR; // bridge extending RIGHT + + int _targetBridgeMidLR; // bridge grating plank LEFT/RIGHT + int _targetBridgeMidUD; // bridge grating plank UP/DOWN + int _touchplateOn; // touchplate ON + int _touchplateOff; + int _templeTouchpOn; // touchplate ON + int _templeTouchpOff; + int _blockpole; // blockpole + + int _kcHolderWhiteOff; // keycard holders + int _kcHolderWhiteOn; + int _kcHolderBlueOff; + int _kcHolderBlueOn; + int _kcHolderRedOff; + int _kcHolderRedOn; + int _kcHolderGreenOff; + int _kcHolderGreenOn; + int _kcHolderPurpleOff; + int _kcHolderPurpleOn; + int _kcHolderBlackOff; + int _kcHolderBlackOn; AIEntLevel2 _entsLevel2[kMaxLevel2Ents]; int _numLevel2Ents; |