mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
| 	//-------------// | ||||
|   | ||||
| @@ -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 ) | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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) | ||||
| 		{ | ||||
|   | ||||
| @@ -33,7 +33,7 @@ class CRandomGenerator; | ||||
| struct DLL_LINKAGE SiegeInfo | ||||
| { | ||||
| 	std::array<si8, EWallPart::PARTS_COUNT> 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 <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
| 		h & wallState & drawbridgeState; | ||||
| 		h & wallState & gateState; | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
| 		} | ||||
|   | ||||
| @@ -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 :) | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
| 		h & state; | ||||
|   | ||||
| @@ -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 ) | ||||
|   | ||||
| @@ -270,7 +270,7 @@ void registerTypesClientPacks2(Serializer &s) | ||||
| 	s.template registerType<CPackForClient, SetStackEffect>(); | ||||
| 	s.template registerType<CPackForClient, BattleTriggerEffect>(); | ||||
| 	s.template registerType<CPackForClient, BattleObstaclePlaced>(); | ||||
| 	s.template registerType<CPackForClient, BattleDrawbridgeStateChanged>(); | ||||
| 	s.template registerType<CPackForClient, BattleUpdateGateState>(); | ||||
| 	s.template registerType<CPackForClient, BattleSetStackProperty>(); | ||||
| 	s.template registerType<CPackForClient, StacksInjured>(); | ||||
| 	s.template registerType<CPackForClient, BattleResultsApplied>(); | ||||
|   | ||||
| @@ -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<BattleHex>, 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); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user