|
@@ -10,51 +10,37 @@
|
|
|
#include "StdInc.h"
|
|
|
#include "CBattleSiegeController.h"
|
|
|
|
|
|
-#include "../CMusicHandler.h"
|
|
|
-#include "../../lib/NetPacks.h"
|
|
|
-#include "../CGameInfo.h"
|
|
|
-#include "../../CCallback.h"
|
|
|
-#include "../CBitmapHandler.h"
|
|
|
-#include "../CPlayerInterface.h"
|
|
|
-#include "../../lib/CStack.h"
|
|
|
-#include "../../lib/mapObjects/CGTownInstance.h"
|
|
|
-#include "CBattleInterface.h"
|
|
|
#include "CBattleAnimations.h"
|
|
|
+#include "CBattleInterface.h"
|
|
|
#include "CBattleInterfaceClasses.h"
|
|
|
#include "CBattleStacksController.h"
|
|
|
|
|
|
-CBattleSiegeController::~CBattleSiegeController()
|
|
|
-{
|
|
|
- auto gateState = owner->curInt->cb->battleGetGateState();
|
|
|
- for (int g = 0; g < ARRAY_COUNT(walls); ++g)
|
|
|
- {
|
|
|
- if (g != EWallVisual::GATE || (gateState != EGateState::NONE && gateState != EGateState::CLOSED && gateState != EGateState::BLOCKED))
|
|
|
- SDL_FreeSurface(walls[g]);
|
|
|
- }
|
|
|
-
|
|
|
- SDL_FreeSurface(moatSurface);
|
|
|
- SDL_FreeSurface(mlipSurface);
|
|
|
-}
|
|
|
+#include "../CMusicHandler.h"
|
|
|
+#include "../CGameInfo.h"
|
|
|
+#include "../CPlayerInterface.h"
|
|
|
+#include "../gui/CAnimation.h"
|
|
|
|
|
|
-std::string CBattleSiegeController::getSiegeName(ui16 what) const
|
|
|
-{
|
|
|
- return getSiegeName(what, EWallState::INTACT);
|
|
|
-}
|
|
|
+#include "../../CCallback.h"
|
|
|
+#include "../../lib/NetPacks.h"
|
|
|
+#include "../../lib/CStack.h"
|
|
|
+#include "../../lib/mapObjects/CGTownInstance.h"
|
|
|
|
|
|
-std::string CBattleSiegeController::getSiegeName(ui16 what, int state) const
|
|
|
+std::string CBattleSiegeController::getWallPieceImageName(EWallVisual::EWallVisual what, EWallState::EWallState state) const
|
|
|
{
|
|
|
auto getImageIndex = [&]() -> int
|
|
|
{
|
|
|
switch (state)
|
|
|
{
|
|
|
- case EWallState::INTACT : return 1;
|
|
|
+ case EWallState::INTACT :
|
|
|
+ return 1;
|
|
|
case EWallState::DAMAGED :
|
|
|
- if(what == 2 || what == 3 || what == 8) // towers don't have separate image here - INTACT and DAMAGED is 1, DESTROYED is 2
|
|
|
+ // towers don't have separate image here - INTACT and DAMAGED is 1, DESTROYED is 2
|
|
|
+ if(what == EWallVisual::KEEP || what == EWallVisual::BOTTOM_TOWER || what == EWallVisual::UPPER_TOWER)
|
|
|
return 1;
|
|
|
else
|
|
|
return 2;
|
|
|
case EWallState::DESTROYED :
|
|
|
- if (what == 2 || what == 3 || what == 8)
|
|
|
+ if (what == EWallVisual::KEEP || what == EWallVisual::BOTTOM_TOWER || what == EWallVisual::UPPER_TOWER)
|
|
|
return 2;
|
|
|
else
|
|
|
return 3;
|
|
@@ -67,8 +53,6 @@ std::string CBattleSiegeController::getSiegeName(ui16 what, int state) const
|
|
|
|
|
|
switch(what)
|
|
|
{
|
|
|
- case EWallVisual::BACKGROUND:
|
|
|
- return prefix + "BACK.BMP";
|
|
|
case EWallVisual::BACKGROUND_WALL:
|
|
|
{
|
|
|
switch(town->town->faction->index)
|
|
@@ -119,38 +103,64 @@ std::string CBattleSiegeController::getSiegeName(ui16 what, int state) const
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CBattleSiegeController::printPartOfWall(SDL_Surface *to, int what)
|
|
|
+void CBattleSiegeController::showWallPiece(SDL_Surface *to, EWallVisual::EWallVisual what)
|
|
|
{
|
|
|
- Point pos = Point(-1, -1);
|
|
|
auto & ci = town->town->clientInfo;
|
|
|
+ auto const & pos = ci.siegePositions[what];
|
|
|
|
|
|
- if (vstd::iswithin(what, 1, 17))
|
|
|
- {
|
|
|
- pos.x = ci.siegePositions[what].x + owner->pos.x;
|
|
|
- pos.y = ci.siegePositions[what].y + owner->pos.y;
|
|
|
- }
|
|
|
+ wallPieceImages[what]->draw(to, pos.x + owner->pos.x, pos.y + owner->pos.y);
|
|
|
+}
|
|
|
+
|
|
|
+std::string CBattleSiegeController::getBattleBackgroundName() const
|
|
|
+{
|
|
|
+ const std::string & prefix = town->town->clientInfo.siegePrefix;
|
|
|
+ return prefix + "BACK.BMP";
|
|
|
+}
|
|
|
|
|
|
- if (town->town->faction->index == ETownType::TOWER
|
|
|
- && (what == EWallVisual::MOAT || what == EWallVisual::BACKGROUND_MOAT))
|
|
|
- return; // no moat in Tower. TODO: remove hardcode somehow?
|
|
|
+bool CBattleSiegeController::getWallPieceExistance(EWallVisual::EWallVisual what) const
|
|
|
+{
|
|
|
+ //FIXME: use this instead of buildings test?
|
|
|
+ //ui8 siegeLevel = owner->curInt->cb->battleGetSiegeLevel();
|
|
|
|
|
|
- if (pos.x != -1)
|
|
|
- {
|
|
|
- //gate have no displayed bitmap when drawbridge is raised
|
|
|
- if (what == EWallVisual::GATE)
|
|
|
- {
|
|
|
- auto gateState = owner->curInt->cb->battleGetGateState();
|
|
|
- if (gateState != EGateState::OPENED && gateState != EGateState::DESTROYED)
|
|
|
- return;
|
|
|
- }
|
|
|
+ bool isMoat = (what == EWallVisual::BACKGROUND_MOAT || what == EWallVisual::MOAT);
|
|
|
+ bool isKeep = what == EWallVisual::KEEP_BATTLEMENT;
|
|
|
+ bool isTower = (what == EWallVisual::UPPER_BATTLEMENT || what == EWallVisual::BOTTOM_BATTLEMENT);
|
|
|
|
|
|
- blitAt(walls[what], pos.x, pos.y, to);
|
|
|
- }
|
|
|
+ bool hasMoat = town->hasBuilt(BuildingID::CITADEL) && town->town->faction->index != ETownType::TOWER;
|
|
|
+ bool hasKeep = town->hasBuilt(BuildingID::CITADEL);
|
|
|
+ bool hasTower = town->hasBuilt(BuildingID::CASTLE);
|
|
|
+
|
|
|
+ if ( isMoat ) return hasMoat;
|
|
|
+ if ( isKeep ) return hasKeep;
|
|
|
+ if ( isTower ) return hasTower;
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
-std::string CBattleSiegeController::getBattleBackgroundName()
|
|
|
+BattleHex CBattleSiegeController::getWallPiecePosition(EWallVisual::EWallVisual what) const
|
|
|
{
|
|
|
- return getSiegeName(0);
|
|
|
+ static const std::array<BattleHex, 18> wallsPositions = {
|
|
|
+ BattleHex::INVALID, // background, handled separately
|
|
|
+ BattleHex::HEX_BEFORE_ALL,
|
|
|
+ 135,
|
|
|
+ BattleHex::HEX_AFTER_ALL,
|
|
|
+ 182,
|
|
|
+ 130,
|
|
|
+ 78,
|
|
|
+ 12,
|
|
|
+ BattleHex::HEX_BEFORE_ALL,
|
|
|
+ 94,
|
|
|
+ 112,
|
|
|
+ 165,
|
|
|
+ 45,
|
|
|
+ BattleHex::INVALID, //moat, printed as obstacle // BattleHex::HEX_BEFORE_ALL,
|
|
|
+ BattleHex::INVALID, //moat, printed as obstacle
|
|
|
+ 135,
|
|
|
+ BattleHex::HEX_AFTER_ALL,
|
|
|
+ BattleHex::HEX_BEFORE_ALL
|
|
|
+ };
|
|
|
+
|
|
|
+ return wallsPositions[what];
|
|
|
}
|
|
|
|
|
|
CBattleSiegeController::CBattleSiegeController(CBattleInterface * owner, const CGTownInstance *siegeTown):
|
|
@@ -159,35 +169,37 @@ CBattleSiegeController::CBattleSiegeController(CBattleInterface * owner, const C
|
|
|
{
|
|
|
assert(owner->fieldController.get() == nullptr); // must be created after this
|
|
|
|
|
|
- moatSurface = BitmapHandler::loadBitmap( getSiegeName(13) );
|
|
|
- mlipSurface = BitmapHandler::loadBitmap( getSiegeName(14) );
|
|
|
-
|
|
|
- for (int g = 0; g < ARRAY_COUNT(walls); ++g)
|
|
|
+ for (int g = 0; g < wallPieceImages.size(); ++g)
|
|
|
{
|
|
|
- if (g != EWallVisual::GATE)
|
|
|
- walls[g] = BitmapHandler::loadBitmap(getSiegeName(g));
|
|
|
+ if ( g == EWallVisual::GATE ) // gate is initially closed and has no image to display in this state
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if ( !getWallPieceExistance(EWallVisual::EWallVisual(g)) )
|
|
|
+ continue;
|
|
|
+
|
|
|
+ wallPieceImages[g] = IImage::createFromFile(getWallPieceImageName(EWallVisual::EWallVisual(g), EWallState::INTACT));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const CCreature *CBattleSiegeController::turretCreature()
|
|
|
+const CCreature *CBattleSiegeController::getTurretCreature() const
|
|
|
{
|
|
|
return CGI->creh->objects[town->town->clientInfo.siegeShooter];
|
|
|
}
|
|
|
|
|
|
-Point CBattleSiegeController::turretCreaturePosition( BattleHex position )
|
|
|
+Point CBattleSiegeController::getTurretCreaturePosition( BattleHex position ) const
|
|
|
{
|
|
|
// Turret positions are read out of the config/wall_pos.txt
|
|
|
int posID = 0;
|
|
|
switch (position)
|
|
|
{
|
|
|
case BattleHex::CASTLE_CENTRAL_TOWER: // keep creature
|
|
|
- posID = 18;
|
|
|
+ posID = EWallVisual::CREATURE_KEEP;
|
|
|
break;
|
|
|
case BattleHex::CASTLE_BOTTOM_TOWER: // bottom creature
|
|
|
- posID = 19;
|
|
|
+ posID = EWallVisual::CREATURE_BOTTOM_TOWER;
|
|
|
break;
|
|
|
case BattleHex::CASTLE_UPPER_TOWER: // upper creature
|
|
|
- posID = 20;
|
|
|
+ posID = EWallVisual::CREATURE_UPPER_TOWER;
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -203,12 +215,11 @@ Point CBattleSiegeController::turretCreaturePosition( BattleHex position )
|
|
|
return Point(0,0);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void CBattleSiegeController::gateStateChanged(const EGateState state)
|
|
|
{
|
|
|
auto oldState = owner->curInt->cb->battleGetGateState();
|
|
|
bool playSound = false;
|
|
|
- int stateId = EWallState::NONE;
|
|
|
+ auto stateId = EWallState::NONE;
|
|
|
switch(state)
|
|
|
{
|
|
|
case EGateState::CLOSED:
|
|
@@ -229,102 +240,87 @@ void CBattleSiegeController::gateStateChanged(const EGateState state)
|
|
|
}
|
|
|
|
|
|
if (oldState != EGateState::NONE && oldState != EGateState::CLOSED && oldState != EGateState::BLOCKED)
|
|
|
- SDL_FreeSurface(walls[EWallVisual::GATE]);
|
|
|
+ wallPieceImages[EWallVisual::GATE] = nullptr;
|
|
|
|
|
|
if (stateId != EWallState::NONE)
|
|
|
- walls[EWallVisual::GATE] = BitmapHandler::loadBitmap(getSiegeName(EWallVisual::GATE, stateId));
|
|
|
+ wallPieceImages[EWallVisual::GATE] = IImage::createFromFile(getWallPieceImageName(EWallVisual::GATE, stateId));
|
|
|
+
|
|
|
if (playSound)
|
|
|
CCS->soundh->playSound(soundBase::DRAWBRG);
|
|
|
}
|
|
|
|
|
|
void CBattleSiegeController::showAbsoluteObstacles(SDL_Surface * to)
|
|
|
{
|
|
|
- ui8 siegeLevel = owner->curInt->cb->battleGetSiegeLevel();
|
|
|
- if (siegeLevel >= 2) //citadel or castle
|
|
|
- {
|
|
|
- //print moat/mlip
|
|
|
-
|
|
|
- auto & info = town->town->clientInfo;
|
|
|
- Point moatPos(info.siegePositions[13].x, info.siegePositions[13].y);
|
|
|
- Point mlipPos(info.siegePositions[14].x, info.siegePositions[14].y);
|
|
|
+ auto & info = town->town->clientInfo;
|
|
|
|
|
|
- if (moatSurface) //eg. tower has no moat
|
|
|
- blitAt(moatSurface, moatPos.x + owner->pos.x, moatPos.y + owner->pos.y, to);
|
|
|
- if (mlipSurface) //eg. tower has no mlip
|
|
|
- blitAt(mlipSurface, mlipPos.x + owner->pos.x, mlipPos.y + owner->pos.y, to);
|
|
|
-
|
|
|
- printPartOfWall(to, EWallVisual::BACKGROUND_MOAT);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void CBattleSiegeController::sortObjectsByHex(BattleObjectsByHex & sorted)
|
|
|
-{
|
|
|
- sorted.beforeAll.walls.push_back(EWallVisual::BACKGROUND_WALL);
|
|
|
- sorted.hex[135].walls.push_back(EWallVisual::KEEP);
|
|
|
- sorted.afterAll.walls.push_back(EWallVisual::BOTTOM_TOWER);
|
|
|
- sorted.hex[182].walls.push_back(EWallVisual::BOTTOM_WALL);
|
|
|
- sorted.hex[130].walls.push_back(EWallVisual::WALL_BELLOW_GATE);
|
|
|
- sorted.hex[78].walls.push_back(EWallVisual::WALL_OVER_GATE);
|
|
|
- sorted.hex[12].walls.push_back(EWallVisual::UPPER_WALL);
|
|
|
- sorted.beforeAll.walls.push_back(EWallVisual::UPPER_TOWER);
|
|
|
- sorted.hex[94].walls.push_back(EWallVisual::GATE);
|
|
|
- sorted.hex[112].walls.push_back(EWallVisual::GATE_ARCH);
|
|
|
- sorted.hex[165].walls.push_back(EWallVisual::BOTTOM_STATIC_WALL);
|
|
|
- sorted.hex[45].walls.push_back(EWallVisual::UPPER_STATIC_WALL);
|
|
|
-
|
|
|
- if (town->hasBuilt(BuildingID::CITADEL))
|
|
|
+ if (getWallPieceExistance(EWallVisual::MOAT))
|
|
|
{
|
|
|
- sorted.beforeAll.walls.push_back(EWallVisual::MOAT);
|
|
|
- //sorted.beforeAll.walls.push_back(EWallVisual::BACKGROUND_MOAT); // blit as absolute obstacle
|
|
|
- sorted.hex[135].walls.push_back(EWallVisual::KEEP_BATTLEMENT);
|
|
|
+ auto const & pos = info.siegePositions[EWallVisual::MOAT];
|
|
|
+ wallPieceImages[EWallVisual::MOAT]->draw(to, pos.x + owner->pos.x, pos.y + owner->pos.y);
|
|
|
}
|
|
|
- if (town->hasBuilt(BuildingID::CASTLE))
|
|
|
+
|
|
|
+ if (getWallPieceExistance(EWallVisual::BACKGROUND_MOAT))
|
|
|
{
|
|
|
- sorted.afterAll.walls.push_back(EWallVisual::BOTTOM_BATTLEMENT);
|
|
|
- sorted.beforeAll.walls.push_back(EWallVisual::UPPER_BATTLEMENT);
|
|
|
+ auto const & pos = info.siegePositions[EWallVisual::BACKGROUND_MOAT];
|
|
|
+ wallPieceImages[EWallVisual::BACKGROUND_MOAT]->draw(to, pos.x + owner->pos.x, pos.y + owner->pos.y);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void CBattleSiegeController::showPiecesOfWall(SDL_Surface *to, std::vector<int> pieces)
|
|
|
+void CBattleSiegeController::showBattlefieldObjects(SDL_Surface *to, const BattleHex & location )
|
|
|
{
|
|
|
- for (auto piece : pieces)
|
|
|
+ for (int i = EWallVisual::WALL_FIRST; i <= EWallVisual::WALL_LAST; ++i)
|
|
|
{
|
|
|
- if (piece < 15) // not a tower - just print
|
|
|
- printPartOfWall(to, piece);
|
|
|
- else // tower. find if tower is built and not destroyed - stack is present
|
|
|
+ auto wallPiece = EWallVisual::EWallVisual(i);
|
|
|
+
|
|
|
+ if ( !getWallPieceExistance(wallPiece))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if ( getWallPiecePosition(wallPiece) != location)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (wallPiece != EWallVisual::KEEP_BATTLEMENT &&
|
|
|
+ wallPiece != EWallVisual::BOTTOM_BATTLEMENT &&
|
|
|
+ wallPiece != EWallVisual::UPPER_BATTLEMENT)
|
|
|
{
|
|
|
- // PieceID StackID
|
|
|
- // 15 = keep, -2
|
|
|
- // 16 = lower, -3
|
|
|
- // 17 = upper, -4
|
|
|
+ showWallPiece(to, wallPiece);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- // tower. check if tower is alive - stack is found
|
|
|
- int stackPos = 13 - piece;
|
|
|
+ // tower. check if tower is alive - stack is found
|
|
|
+ BattleHex stackPos;
|
|
|
+ switch(wallPiece)
|
|
|
+ {
|
|
|
+ case EWallVisual::KEEP_BATTLEMENT:
|
|
|
+ stackPos = BattleHex::CASTLE_CENTRAL_TOWER;
|
|
|
+ break;
|
|
|
+ case EWallVisual::BOTTOM_BATTLEMENT:
|
|
|
+ stackPos = BattleHex::CASTLE_BOTTOM_TOWER;
|
|
|
+ break;
|
|
|
+ case EWallVisual::UPPER_BATTLEMENT:
|
|
|
+ stackPos = BattleHex::CASTLE_UPPER_TOWER;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- const CStack *turret = nullptr;
|
|
|
+ const CStack *turret = nullptr;
|
|
|
|
|
|
- for (auto & stack : owner->curInt->cb->battleGetAllStacks(true))
|
|
|
+ for (auto & stack : owner->curInt->cb->battleGetAllStacks(true))
|
|
|
+ {
|
|
|
+ if(stack->initialPosition == stackPos)
|
|
|
{
|
|
|
- if(stack->initialPosition == stackPos)
|
|
|
- {
|
|
|
- turret = stack;
|
|
|
- break;
|
|
|
- }
|
|
|
+ turret = stack;
|
|
|
+ break;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (turret)
|
|
|
- {
|
|
|
- std::vector<const CStack *> stackList(1, turret);
|
|
|
- owner->stacksController->showStacks(to, stackList);
|
|
|
- printPartOfWall(to, piece);
|
|
|
- }
|
|
|
+ if (turret)
|
|
|
+ {
|
|
|
+ owner->stacksController->showStack(to, turret);
|
|
|
+ showWallPiece(to, wallPiece);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-bool CBattleSiegeController::isCatapultAttackable(BattleHex hex) const
|
|
|
+bool CBattleSiegeController::isAttackableByCatapult(BattleHex hex) const
|
|
|
{
|
|
|
if (owner->tacticsMode)
|
|
|
return false;
|
|
@@ -362,13 +358,13 @@ void CBattleSiegeController::stackIsCatapulting(const CatapultAttack & ca)
|
|
|
|
|
|
for (auto attackInfo : ca.attackedParts)
|
|
|
{
|
|
|
- int wallId = attackInfo.attackedPart + 2;
|
|
|
+ int wallId = attackInfo.attackedPart + EWallVisual::DESTRUCTIBLE_FIRST;
|
|
|
//gate state changing handled separately
|
|
|
if (wallId == EWallVisual::GATE)
|
|
|
continue;
|
|
|
|
|
|
- SDL_FreeSurface(walls[wallId]);
|
|
|
- walls[wallId] = BitmapHandler::loadBitmap(
|
|
|
- getSiegeName(wallId, owner->curInt->cb->battleGetWallState(attackInfo.attackedPart)));
|
|
|
+ auto wallState = EWallState::EWallState(owner->curInt->cb->battleGetWallState(attackInfo.attackedPart));
|
|
|
+
|
|
|
+ wallPieceImages[wallId] = IImage::createFromFile(getWallPieceImageName(EWallVisual::EWallVisual(wallId), wallState));
|
|
|
}
|
|
|
}
|