1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Battles: move hexes enum to GameConstants and fix wall position

Before we had hex 62 marked as destructible wall while actually it's must be 78.
This commit is contained in:
Arseniy Shestakov 2016-02-09 17:38:59 +03:00
parent 01b4d0ae01
commit 11dc428b1e
5 changed files with 44 additions and 31 deletions

View File

@ -16,13 +16,6 @@
// for battle stacks' positions
struct DLL_LINKAGE BattleHex
{
enum ESiegeHexes : si16
{
GATE_BRIDGE = 94,
GATE_OUTER = 95,
GATE_INNER = 96
};
static const si16 INVALID = -1;
enum EDir { RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, LEFT, TOP_LEFT, TOP_RIGHT };

View File

@ -1151,7 +1151,7 @@ AccessibilityInfo CBattleInfoCallback::getAccesibility() const
accessability = EAccessibility::UNAVAILABLE;
break;
}
ret[95] = ret[96] = accessability;
ret[ESiegeHex::GATE_OUTER] = ret[ESiegeHex::GATE_INNER] = accessability;
}
//tiles occupied by standing stacks
@ -1172,14 +1172,19 @@ AccessibilityInfo CBattleInfoCallback::getAccesibility() const
//walls
if(battleGetSiegeLevel() > 0)
{
static const int permanentlyLocked[] = {12, 45, 78, 112, 147, 165};
static const int permanentlyLocked[] = {12, 45, 62, 112, 147, 165};
for(auto hex : permanentlyLocked)
ret[hex] = EAccessibility::UNAVAILABLE;
//TODO likely duplicated logic
static const std::pair<int, BattleHex> lockedIfNotDestroyed[] = //(which part of wall, which hex is blocked if this part of wall is not destroyed
{std::make_pair(2, BattleHex(182)), std::make_pair(3, BattleHex(130)),
std::make_pair(4, BattleHex(62)), std::make_pair(5, BattleHex(29))};
static const std::pair<int, BattleHex> lockedIfNotDestroyed[] =
{
//which part of wall, which hex is blocked if this part of wall is not destroyed
std::make_pair(2, BattleHex(ESiegeHex::DESTRUCTIBLE_WALL_4)),
std::make_pair(3, BattleHex(ESiegeHex::DESTRUCTIBLE_WALL_3)),
std::make_pair(4, BattleHex(ESiegeHex::DESTRUCTIBLE_WALL_2)),
std::make_pair(5, BattleHex(ESiegeHex::DESTRUCTIBLE_WALL_1))
};
for(auto & elem : lockedIfNotDestroyed)
{

View File

@ -510,7 +510,7 @@ namespace EWallState
};
}
enum class EDrawbridgeState
enum class EDrawbridgeState : ui8
{
NONE,
RAISED,
@ -519,6 +519,20 @@ enum class EDrawbridgeState
LOWERED_BORKED //gate is destroyed
};
namespace ESiegeHex
{
enum ESiegeHex : si16
{
DESTRUCTIBLE_WALL_1 = 29,
DESTRUCTIBLE_WALL_2 = 78,
DESTRUCTIBLE_WALL_3 = 130,
DESTRUCTIBLE_WALL_4 = 182,
GATE_BRIDGE = 94,
GATE_OUTER = 95,
GATE_INNER = 96
};
}
namespace ETileType
{
enum ETileType

View File

@ -1210,7 +1210,8 @@ DLL_LINKAGE void BattleObstaclePlaced::applyGs( CGameState *gs )
DLL_LINKAGE void BattleDrawbridgeStateChanged::applyGs(CGameState *gs)
{
gs->curB->si.drawbridgeState = state;
if(gs->curB)
gs->curB->si.drawbridgeState = state;
}
void BattleResult::applyGs( CGameState *gs )

View File

@ -1050,11 +1050,11 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
auto isGateDrawbridgeHex = [&](BattleHex hex) -> bool
{
if(gs->curB->town->subID == ETownType::FORTRESS && hex == BattleHex::GATE_BRIDGE)
if(gs->curB->town->subID == ETownType::FORTRESS && hex == ESiegeHex::GATE_BRIDGE)
return true;
if(hex == BattleHex::GATE_OUTER)
if(hex == ESiegeHex::GATE_OUTER)
return true;
if(hex == BattleHex::GATE_INNER)
if(hex == ESiegeHex::GATE_INNER)
return true;
return false;
@ -1114,11 +1114,11 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
{
auto needOpenGates = [&](BattleHex hex) -> bool
{
if(gs->curB->town->subID == ETownType::FORTRESS && hex == BattleHex::GATE_BRIDGE)
if(gs->curB->town->subID == ETownType::FORTRESS && hex == ESiegeHex::GATE_BRIDGE)
return true;
if(hex == BattleHex::GATE_BRIDGE && i-1 >= 0 && path.first[i-1] == BattleHex::GATE_OUTER)
if(hex == ESiegeHex::GATE_BRIDGE && i-1 >= 0 && path.first[i-1] == ESiegeHex::GATE_OUTER)
return true;
else if(hex == BattleHex::GATE_OUTER || hex == BattleHex::GATE_INNER)
else if(hex == ESiegeHex::GATE_OUTER || hex == ESiegeHex::GATE_INNER)
return true;
return false;
@ -1146,24 +1146,24 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
if(!gateMayCloseAtHex.isValid() && dbState != EDrawbridgeState::RAISED)
{
if(hex == BattleHex::GATE_INNER && i-1 >= 0 && path.first[i-1] != BattleHex::GATE_OUTER)
if(hex == ESiegeHex::GATE_INNER && i-1 >= 0 && path.first[i-1] != ESiegeHex::GATE_OUTER)
{
gateMayCloseAtHex = path.first[i-1];
}
if(gs->curB->town->subID == ETownType::FORTRESS)
{
if(hex == BattleHex::GATE_BRIDGE && i-1 >= 0 && path.first[i-1] != BattleHex::GATE_OUTER)
if(hex == ESiegeHex::GATE_BRIDGE && i-1 >= 0 && path.first[i-1] != ESiegeHex::GATE_OUTER)
{
gateMayCloseAtHex = path.first[i-1];
}
else if(hex == BattleHex::GATE_OUTER && i-1 >= 0 &&
path.first[i-1] != BattleHex::GATE_INNER &&
path.first[i-1] != BattleHex::GATE_BRIDGE)
else if(hex == ESiegeHex::GATE_OUTER && i-1 >= 0 &&
path.first[i-1] != ESiegeHex::GATE_INNER &&
path.first[i-1] != ESiegeHex::GATE_BRIDGE)
{
gateMayCloseAtHex = path.first[i-1];
}
}
else if(hex == BattleHex::GATE_OUTER && i-1 >= 0 && path.first[i-1] != BattleHex::GATE_INNER)
else if(hex == ESiegeHex::GATE_OUTER && i-1 >= 0 && path.first[i-1] != ESiegeHex::GATE_INNER)
{
gateMayCloseAtHex = path.first[i-1];
}
@ -3608,21 +3608,21 @@ void CGameHandler::updateDrawbridgeState()
}
else if(db.state == EDrawbridgeState::LOWERED)
{
if(!gs->curB->battleGetStackByPos(BattleHex(BattleHex::GATE_OUTER), false) &&
!gs->curB->battleGetStackByPos(BattleHex(BattleHex::GATE_INNER), false))
if(!gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_OUTER), false) &&
!gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_INNER), false))
{
if(gs->curB->town->subID == ETownType::FORTRESS)
{
if(!gs->curB->battleGetStackByPos(BattleHex(BattleHex::GATE_BRIDGE), false))
if(!gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_BRIDGE), false))
db.state = EDrawbridgeState::RAISED;
}
else if(gs->curB->battleGetStackByPos(BattleHex(BattleHex::GATE_BRIDGE)))
else if(gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_BRIDGE)))
db.state = EDrawbridgeState::RAISED_BLOCKED;
else
db.state = EDrawbridgeState::RAISED;
}
}
else if(gs->curB->battleGetStackByPos(BattleHex(BattleHex::GATE_BRIDGE), false))
else if(gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_BRIDGE), false))
db.state = EDrawbridgeState::RAISED_BLOCKED;
else
db.state = EDrawbridgeState::RAISED;