From c5cfc8467f3c04faf61a80f1e3aff680cbeef233 Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Sat, 13 Feb 2016 17:40:31 +0300 Subject: [PATCH] Battles: change naming from drawbridge to gate for everything This way code is shorter and cleaner while in future we may support towns with gate only. --- client/CPlayerInterface.cpp | 4 +-- client/CPlayerInterface.h | 2 +- client/NetPacksClient.cpp | 4 +-- client/battle/CBattleInterface.cpp | 18 +++++----- client/battle/CBattleInterface.h | 2 +- lib/BattleState.cpp | 2 +- lib/BattleState.h | 4 +-- lib/CBattleCallback.cpp | 14 ++++---- lib/CBattleCallback.h | 2 +- lib/GameConstants.h | 10 +++--- lib/IGameEventsReceiver.h | 2 +- lib/NetPacks.h | 6 ++-- lib/NetPacksLib.cpp | 4 +-- lib/registerTypes/RegisterTypes.h | 2 +- server/CGameHandler.cpp | 54 +++++++++++++++--------------- server/CGameHandler.h | 2 +- 16 files changed, 66 insertions(+), 66 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index dedfe5074..e62d2c966 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1012,12 +1012,12 @@ void CPlayerInterface::battleObstaclePlaced(const CObstacleInstance &obstacle) battleInt->obstaclePlaced(obstacle); } -void CPlayerInterface::battleDrawbridgeStateChanged(const EDrawbridgeState state) +void CPlayerInterface::battleGateStateChanged(const EGateState state) { EVENT_HANDLER_CALLED_BY_CLIENT; BATTLE_EVENT_POSSIBLE_RETURN; - battleInt->drawbridgeStateChanged(state); + battleInt->gateStateChanged(state); } void CPlayerInterface::yourTacticPhase(int distance) diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index 5dd707e14..6751ffe54 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -220,7 +220,7 @@ public: void battleCatapultAttacked(const CatapultAttack & ca) override; //called when catapult makes an attack void battleStacksRemoved(const BattleStacksRemoved & bsr) override; //called when certain stack is completely removed from battlefield void battleObstaclePlaced(const CObstacleInstance &obstacle) override; - void battleDrawbridgeStateChanged(const EDrawbridgeState state) override; + void battleGateStateChanged(const EGateState state) override; void yourTacticPhase(int distance) override; //-------------// diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 6e5d299de..229ce2a2a 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -658,9 +658,9 @@ void BattleObstaclePlaced::applyCl(CClient * cl) BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleObstaclePlaced, *obstacle); } -void BattleDrawbridgeStateChanged::applyFirstCl(CClient * cl) +void BattleUpdateGateState::applyFirstCl(CClient * cl) { - BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleDrawbridgeStateChanged, state); + BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleGateStateChanged, state); } void BattleResult::applyFirstCl( CClient *cl ) diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index 51dc6e13e..228b4f668 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -2729,26 +2729,26 @@ void CBattleInterface::obstaclePlaced(const CObstacleInstance & oi) //CCS->soundh->playSound(sound); } -void CBattleInterface::drawbridgeStateChanged(const EDrawbridgeState state) +void CBattleInterface::gateStateChanged(const EGateState state) { - auto oldState = curInt->cb->battleGetDrawbridgeState(); + auto oldState = curInt->cb->battleGetGateState(); bool playSound = false; int stateId = EWallState::NONE; switch(state) { - case EDrawbridgeState::RAISED: - if(oldState != EDrawbridgeState::RAISED_BLOCKED) + case EGateState::CLOSED: + if(oldState != EGateState::BLOCKED) playSound = true; break; - case EDrawbridgeState::RAISED_BLOCKED: - if(oldState != EDrawbridgeState::RAISED) + case EGateState::BLOCKED: + if(oldState != EGateState::CLOSED) playSound = true; break; - case EDrawbridgeState::LOWERED: + case EGateState::OPENED: playSound = true; stateId = EWallState::DAMAGED; break; - case EDrawbridgeState::LOWERED_BORKED: + case EGateState::DESTROYED: stateId = EWallState::DESTROYED; break; } @@ -2821,7 +2821,7 @@ CBattleInterface::SiegeHelper::SiegeHelper(const CGTownInstance *siegeTown, cons { for(int g = 0; g < ARRAY_COUNT(walls); ++g) { - //drawbridge have no displayed bitmap when raised + //gate have no displayed bitmap when drawbridge is raised if(g == SiegeHelper::GATE) walls[g] = nullptr; else diff --git a/client/battle/CBattleInterface.h b/client/battle/CBattleInterface.h index 51318c598..ca459771e 100644 --- a/client/battle/CBattleInterface.h +++ b/client/battle/CBattleInterface.h @@ -357,7 +357,7 @@ public: BattleHex fromWhichHexAttack(BattleHex myNumber); void obstaclePlaced(const CObstacleInstance & oi); - void drawbridgeStateChanged(const EDrawbridgeState state); + void gateStateChanged(const EGateState state); const CGHeroInstance * currentHero() const; InfoAboutHero enemyHero() const; diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index 0639ebc18..6230ddf8f 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -327,7 +327,7 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, ETerrainType terrain, BFieldTyp //setting up siege obstacles if (town && town->hasFort()) { - curB->si.drawbridgeState = EDrawbridgeState::RAISED; + curB->si.gateState = EGateState::CLOSED; for (int b = 0; b < curB->si.wallState.size(); ++b) { diff --git a/lib/BattleState.h b/lib/BattleState.h index 6aee4678f..7ac358766 100644 --- a/lib/BattleState.h +++ b/lib/BattleState.h @@ -33,7 +33,7 @@ class CRandomGenerator; struct DLL_LINKAGE SiegeInfo { std::array wallState; - EDrawbridgeState drawbridgeState; + EGateState gateState; // return EWallState decreased by value of damage points static EWallState::EWallState applyDamage(EWallState::EWallState state, unsigned int value) @@ -52,7 +52,7 @@ struct DLL_LINKAGE SiegeInfo template void serialize(Handler &h, const int version) { - h & wallState & drawbridgeState; + h & wallState & gateState; } }; diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index 0635f4833..08de2e8a7 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -442,13 +442,13 @@ si8 CBattleInfoEssentials::battleGetWallState(int partOfWall) const return getBattle()->si.wallState[partOfWall]; } -EDrawbridgeState CBattleInfoEssentials::battleGetDrawbridgeState() const +EGateState CBattleInfoEssentials::battleGetGateState() const { - RETURN_IF_NOT_BATTLE(EDrawbridgeState::NONE); + RETURN_IF_NOT_BATTLE(EGateState::NONE); if(getBattle()->town == nullptr || getBattle()->town->fortLevel() == CGTownInstance::NONE) - return EDrawbridgeState::NONE; + return EGateState::NONE; - return getBattle()->si.drawbridgeState; + return getBattle()->si.gateState; } si8 CBattleInfoCallback::battleHasWallPenalty( const CStack * stack, BattleHex destHex ) const @@ -1141,13 +1141,13 @@ AccessibilityInfo CBattleInfoCallback::getAccesibility() const if(battleGetSiegeLevel() > 0) { EAccessibility::EAccessibility accessability = EAccessibility::ACCESSIBLE; - switch(battleGetDrawbridgeState()) + switch(battleGetGateState()) { - case EDrawbridgeState::RAISED: + case EGateState::CLOSED: accessability = EAccessibility::GATE; break; - case EDrawbridgeState::RAISED_BLOCKED: + case EGateState::BLOCKED: accessability = EAccessibility::UNAVAILABLE; break; } diff --git a/lib/CBattleCallback.h b/lib/CBattleCallback.h index 8d2fe69c0..289efa7e7 100644 --- a/lib/CBattleCallback.h +++ b/lib/CBattleCallback.h @@ -199,7 +199,7 @@ public: // for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall, // [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle si8 battleGetWallState(int partOfWall) const; - EDrawbridgeState battleGetDrawbridgeState() const; + EGateState battleGetGateState() const; //helpers ///returns all stacks, alive or dead or undead or mechanical :) diff --git a/lib/GameConstants.h b/lib/GameConstants.h index 9258a221e..a21cca17e 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -510,13 +510,13 @@ namespace EWallState }; } -enum class EDrawbridgeState : ui8 +enum class EGateState : ui8 { NONE, - RAISED, - RAISED_BLOCKED, //dead or alive stack blocking from outside - LOWERED, - LOWERED_BORKED //gate is destroyed + CLOSED, + BLOCKED, //dead or alive stack blocking from outside + OPENED, + DESTROYED }; namespace ESiegeHex diff --git a/lib/IGameEventsReceiver.h b/lib/IGameEventsReceiver.h index 9f6ed89ff..66774aeb9 100644 --- a/lib/IGameEventsReceiver.h +++ b/lib/IGameEventsReceiver.h @@ -69,7 +69,7 @@ public: virtual void battleCatapultAttacked(const CatapultAttack & ca){}; //called when catapult makes an attack virtual void battleStacksRemoved(const BattleStacksRemoved & bsr){}; //called when certain stack is completely removed from battlefield virtual void battleObstaclePlaced(const CObstacleInstance &obstacle){}; - virtual void battleDrawbridgeStateChanged(const EDrawbridgeState state){}; + virtual void battleGateStateChanged(const EGateState state){}; }; class DLL_LINKAGE IGameEventsReceiver diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 66fb6a2c4..eaec28181 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -1689,15 +1689,15 @@ struct BattleObstaclePlaced : public CPackForClient //3020 } }; -struct BattleDrawbridgeStateChanged : public CPackForClient//3021 +struct BattleUpdateGateState : public CPackForClient//3021 { - BattleDrawbridgeStateChanged(){type = 3021;}; + BattleUpdateGateState(){type = 3021;}; void applyFirstCl(CClient *cl); DLL_LINKAGE void applyGs(CGameState *gs); - EDrawbridgeState state; + EGateState state; template void serialize(Handler &h, const int version) { h & state; diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 701423902..e6c88a72d 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1208,10 +1208,10 @@ DLL_LINKAGE void BattleObstaclePlaced::applyGs( CGameState *gs ) gs->curB->obstacles.push_back(obstacle); } -DLL_LINKAGE void BattleDrawbridgeStateChanged::applyGs(CGameState *gs) +DLL_LINKAGE void BattleUpdateGateState::applyGs(CGameState *gs) { if(gs->curB) - gs->curB->si.drawbridgeState = state; + gs->curB->si.gateState = state; } void BattleResult::applyGs( CGameState *gs ) diff --git a/lib/registerTypes/RegisterTypes.h b/lib/registerTypes/RegisterTypes.h index 4c697d91f..f4b217045 100644 --- a/lib/registerTypes/RegisterTypes.h +++ b/lib/registerTypes/RegisterTypes.h @@ -270,7 +270,7 @@ void registerTypesClientPacks2(Serializer &s) s.template registerType(); s.template registerType(); s.template registerType(); - s.template registerType(); + s.template registerType(); s.template registerType(); s.template registerType(); s.template registerType(); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 2221ec8df..5ee89e334 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1033,13 +1033,13 @@ int CGameHandler::moveStack(int stack, BattleHex dest) return 0; } - bool canUseDrawbridge = false; - auto dbState = gs->curB->si.drawbridgeState; + bool canUseGate = false; + auto dbState = gs->curB->si.gateState; if(battleGetSiegeLevel() > 0 && !curStack->attackerOwned && - dbState != EDrawbridgeState::LOWERED_BORKED && - dbState != EDrawbridgeState::RAISED_BLOCKED) + dbState != EGateState::DESTROYED && + dbState != EGateState::BLOCKED) { - canUseDrawbridge = true; + canUseGate = true; } std::pair< std::vector, int > path = gs->curB->getPath(start, dest, curStack); @@ -1079,11 +1079,11 @@ int CGameHandler::moveStack(int stack, BattleHex dest) { if(path.second <= creSpeed && path.first.size() > 0) { - if(canUseDrawbridge && dbState != EDrawbridgeState::LOWERED && + if(canUseGate && dbState != EGateState::OPENED && occupyGateDrawbridgeHex(dest)) { - BattleDrawbridgeStateChanged db; - db.state = EDrawbridgeState::LOWERED; + BattleUpdateGateState db; + db.state = EGateState::OPENED; sendAndApply(&db); } @@ -1108,7 +1108,7 @@ int CGameHandler::moveStack(int stack, BattleHex dest) // check if gate need to be open or closed at some point BattleHex openGateAtHex, gateMayCloseAtHex; - if(canUseDrawbridge) + if(canUseGate) { for(int i = path.first.size()-1; i >= 0; i--) { @@ -1125,7 +1125,7 @@ int CGameHandler::moveStack(int stack, BattleHex dest) }; auto hex = path.first[i]; - if(!openGateAtHex.isValid() && dbState != EDrawbridgeState::LOWERED) + if(!openGateAtHex.isValid() && dbState != EGateState::OPENED) { if(needOpenGates(hex)) openGateAtHex = path.first[i+1]; @@ -1141,10 +1141,10 @@ int CGameHandler::moveStack(int stack, BattleHex dest) //gate may be opened and then closed during stack movement, but not other way around if(openGateAtHex.isValid()) - dbState = EDrawbridgeState::LOWERED; + dbState = EGateState::OPENED; } - if(!gateMayCloseAtHex.isValid() && dbState != EDrawbridgeState::RAISED) + if(!gateMayCloseAtHex.isValid() && dbState != EGateState::CLOSED) { if(hex == ESiegeHex::GATE_INNER && i-1 >= 0 && path.first[i-1] != ESiegeHex::GATE_OUTER) { @@ -1254,15 +1254,15 @@ int CGameHandler::moveStack(int stack, BattleHex dest) //only open gate if stack is still alive if(curStack->alive()) { - BattleDrawbridgeStateChanged db; - db.state = EDrawbridgeState::LOWERED; + BattleUpdateGateState db; + db.state = EGateState::OPENED; sendAndApply(&db); } } else if(curStack->position == gateMayCloseAtHex) { gateMayCloseAtHex = BattleHex(); - updateDrawbridgeState(); + updateGateState(); } } } @@ -1862,7 +1862,7 @@ void CGameHandler::checkBattleStateChanges() { //check if drawbridge state need to be changes if(battleGetSiegeLevel() > 0) - updateDrawbridgeState(); + updateGateState(); //check if battle ended if(auto result = battleIsFinished()) @@ -3598,15 +3598,15 @@ bool CGameHandler::queryReply(QueryID qid, ui32 answer, PlayerColor player) static EndAction end_action; -void CGameHandler::updateDrawbridgeState() +void CGameHandler::updateGateState() { - BattleDrawbridgeStateChanged db; - db.state = gs->curB->si.drawbridgeState; + BattleUpdateGateState db; + db.state = gs->curB->si.gateState; if(gs->curB->si.wallState[EWallPart::GATE] == EWallState::DESTROYED) { - db.state = EDrawbridgeState::LOWERED_BORKED; + db.state = EGateState::DESTROYED; } - else if(db.state == EDrawbridgeState::LOWERED) + else if(db.state == EGateState::OPENED) { if(!gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_OUTER), false) && !gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_INNER), false)) @@ -3614,20 +3614,20 @@ void CGameHandler::updateDrawbridgeState() if(gs->curB->town->subID == ETownType::FORTRESS) { if(!gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_BRIDGE), false)) - db.state = EDrawbridgeState::RAISED; + db.state = EGateState::CLOSED; } else if(gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_BRIDGE))) - db.state = EDrawbridgeState::RAISED_BLOCKED; + db.state = EGateState::BLOCKED; else - db.state = EDrawbridgeState::RAISED; + db.state = EGateState::CLOSED; } } else if(gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_BRIDGE), false)) - db.state = EDrawbridgeState::RAISED_BLOCKED; + db.state = EGateState::BLOCKED; else - db.state = EDrawbridgeState::RAISED; + db.state = EGateState::CLOSED; - if(db.state != gs->curB->si.drawbridgeState) + if(db.state != gs->curB->si.gateState) sendAndApply(&db); } diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 27c915492..f9e42332c 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -200,7 +200,7 @@ public: PlayerColor getPlayerAt(CConnection *c) const; void playerMessage( PlayerColor player, const std::string &message, ObjectInstanceID currObj); - void updateDrawbridgeState(); + void updateGateState(); bool makeBattleAction(BattleAction &ba); bool makeAutomaticAction(const CStack *stack, BattleAction &ba); //used when action is taken by stack without volition of player (eg. unguided catapult attack) bool makeCustomAction(BattleAction &ba);