Explorar o código

SiegeInfo: add foundation for drawbridge mechanics support

EDrawbridgeState enum represent current state of drawbridge.
BattleDrawbridgeStateChanged netpack to pass bridge state changes to client.
Arseniy Shestakov %!s(int64=9) %!d(string=hai) anos
pai
achega
1e008b9756
Modificáronse 6 ficheiros con 32 adicións e 1 borrados
  1. 2 0
      lib/BattleState.cpp
  2. 2 1
      lib/BattleState.h
  3. 9 0
      lib/GameConstants.h
  4. 13 0
      lib/NetPacks.h
  5. 5 0
      lib/NetPacksLib.cpp
  6. 1 0
      lib/registerTypes/RegisterTypes.h

+ 2 - 0
lib/BattleState.cpp

@@ -327,6 +327,8 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, ETerrainType terrain, BFieldTyp
 	//setting up siege obstacles
 	if (town && town->hasFort())
 	{
+		curB->si.drawbridgeState = EDrawbridgeState::RAISED;
+
 		for (int b = 0; b < curB->si.wallState.size(); ++b)
 		{
 			curB->si.wallState[b] = EWallState::INTACT;

+ 2 - 1
lib/BattleState.h

@@ -33,6 +33,7 @@ class CRandomGenerator;
 struct DLL_LINKAGE SiegeInfo
 {
 	std::array<si8, EWallPart::PARTS_COUNT> wallState;
+	EDrawbridgeState drawbridgeState;
 
 	// return EWallState decreased by value of damage points
 	static EWallState::EWallState applyDamage(EWallState::EWallState state, unsigned int value)
@@ -51,7 +52,7 @@ struct DLL_LINKAGE SiegeInfo
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & wallState;
+		h & wallState & drawbridgeState;
 	}
 };
 

+ 9 - 0
lib/GameConstants.h

@@ -510,6 +510,15 @@ namespace EWallState
 	};
 }
 
+enum class EDrawbridgeState
+{
+	NONE,
+	RAISED,
+	RAISED_BLOCKED, //dead or alive stack blocking from outside
+	LOWERED,
+	LOWERED_BORKED //gate is destroyed
+};
+
 namespace ETileType
 {
 	enum ETileType

+ 13 - 0
lib/NetPacks.h

@@ -1689,6 +1689,19 @@ struct BattleObstaclePlaced : public CPackForClient //3020
 	}
 };
 
+struct BattleDrawbridgeStateChanged : public CPackForClient//3021
+{
+	BattleDrawbridgeStateChanged(){type = 3021;};
+
+	DLL_LINKAGE void applyGs(CGameState *gs);
+
+	EDrawbridgeState state;
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & state;
+	}
+};
+
 
 struct ShowInInfobox : public CPackForClient //107
 {

+ 5 - 0
lib/NetPacksLib.cpp

@@ -1208,6 +1208,11 @@ DLL_LINKAGE void BattleObstaclePlaced::applyGs( CGameState *gs )
 	gs->curB->obstacles.push_back(obstacle);
 }
 
+DLL_LINKAGE void BattleDrawbridgeStateChanged::applyGs(CGameState *gs)
+{
+	gs->curB->si.drawbridgeState = state;
+}
+
 void BattleResult::applyGs( CGameState *gs )
 {
 	for (CStack *s : gs->curB->stacks)

+ 1 - 0
lib/registerTypes/RegisterTypes.h

@@ -270,6 +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, BattleSetStackProperty>();
 	s.template registerType<CPackForClient, StacksInjured>();
 	s.template registerType<CPackForClient, BattleResultsApplied>();