diff --git a/CCallback.cpp b/CCallback.cpp index 6bee1c91f..1cc5b6240 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -596,11 +596,19 @@ bool CCallback::battleCanCastSpell() return gs->curB->castSpells[1] == 0 && gs->getHero(gs->curB->hero2)->getArt(17); } -bool CCallback:: battleCanFlee() +bool CCallback::battleCanFlee() { return gs->battleCanFlee(player); } +const CGTownInstance *CCallback::battleGetDefendedTown() +{ + if(!gs->curB || gs->curB->tid == -1) + return NULL; + + return gs->map->towns[gs->curB->tid]; +} + void CCallback::swapGarrisonHero( const CGTownInstance *town ) { if(town->tempOwner != player) return; diff --git a/CCallback.h b/CCallback.h index 75fa7940d..ef32ae61d 100644 --- a/CCallback.h +++ b/CCallback.h @@ -174,6 +174,7 @@ public: virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest virtual bool battleCanCastSpell()=0; //returns true, if caller can cast a spell virtual bool battleCanFlee()=0; //returns true if caller can flee from the battle + virtual const CGTownInstance * battleGetDefendedTown()=0; //returns defended town if current battle is a siege, NULL instead }; struct HeroMoveDetails @@ -275,6 +276,7 @@ public: bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest bool battleCanCastSpell(); //returns true, if caller can cast a spell bool battleCanFlee(); //returns true if caller can flee from the battle + const CGTownInstance * battleGetDefendedTown(); //returns defended town if current battle is a siege, NULL instead //XXX hmmm _tmain on _GNUC_ wtf? //friends diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index 9682c9273..614cc7928 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -23,6 +23,7 @@ #include "../lib/NetPacks.h" #include "CPlayerInterface.h" #include "../hch/CVideoHandler.h" +#include "../hch/CTownHandler.h" #include #ifndef __GNUC__ const double M_PI = 3.14159265358979323846; @@ -75,7 +76,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C : attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), mouseHoveredStack(-1), previouslyHoveredHex(-1), currentlyHoveredHex(-1), spellDestSelectMode(false), spellToCast(NULL), attackingInfo(NULL), givenCommand(NULL), myTurn(false), resWindow(NULL), - showStackQueue(false), moveStarted(false), moveSh(-1) + showStackQueue(false), moveStarted(false), moveSh(-1), siegeH(NULL) { pos = myRect; strongInterest = true; @@ -88,9 +89,27 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C { newStack(b->second.ID); } + + + //preparing siege info + const CGTownInstance * town = LOCPLINT->cb->battleGetDefendedTown(); + if(town) + { + siegeH = new SiegeHelper(town); + } + //preparing menu background and terrain - std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; - background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); + if(siegeH) + { + background = BitmapHandler::loadBitmap( siegeH->getBackgroundName() ); + } + else + { + std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; + background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); + } + + //preparign menu background menu = BitmapHandler::loadBitmap("CBAR.BMP"); graphics->blueToPlayersAdv(menu, hero1->tempOwner); @@ -277,6 +296,7 @@ CBattleInterface::~CBattleInterface() for(std::map< int, CDefHandler * >::iterator g=idToObstacle.begin(); g!=idToObstacle.end(); ++g) delete g->second; + delete siegeH; LOCPLINT->battleInt = NULL; } @@ -3146,3 +3166,15 @@ void CBattleOptionsWindow::bExitf() { GH.popIntTotally(this); } + +std::string CBattleInterface::SiegeHelper::townTypeInfixes[F_NUMBER] = {"CS", "RM", "TW", "IN", "NC", "DN", "ST", "FR" "EL"}; + +CBattleInterface::SiegeHelper::SiegeHelper(const CGTownInstance *siegeTown) +: town(siegeTown) +{ +} + +std::string CBattleInterface::SiegeHelper::getBackgroundName() const +{ + return "SG" + townTypeInfixes[town->town->typeID] + "BACK.BMP"; +} diff --git a/client/CBattleInterface.h b/client/CBattleInterface.h index 342f6acea..e201350a6 100644 --- a/client/CBattleInterface.h +++ b/client/CBattleInterface.h @@ -28,6 +28,7 @@ struct SpellCast; template struct CondSh; struct SetStackEffect;; struct BattleAction; +class CGTownInstance; class CBattleInterface; @@ -225,6 +226,18 @@ private: CDefHandler * anim; //animation to display }; std::list battleEffects; //different animations to display on the screen like spell effects + + class SiegeHelper + { + private: + static std::string townTypeInfixes[F_NUMBER]; //for internal use only - to build filenames + public: + const CGTownInstance * town; //besieged town + SiegeHelper(const CGTownInstance * siegeTown); //c-tor + + //filename getters + std::string getBackgroundName() const; + } * siegeH; public: CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect); //c-tor ~CBattleInterface(); //d-tor diff --git a/lib/CGameState.h b/lib/CGameState.h index 3702bc834..2861e0a7b 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -120,7 +120,7 @@ struct DLL_EXPORT BattleInfo template void serialize(Handler &h, const int version) { - h & side1 & side2 & round & activeStack & siege & tile & stacks & army1 & army2 & hero1 & hero2 & obstacles + h & side1 & side2 & round & activeStack & siege & tid & tile & stacks & army1 & army2 & hero1 & hero2 & obstacles & castSpells; } CStack * getNextStack(); //which stack will have turn after current one