mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
* first part of siege support
* minor fix
This commit is contained in:
parent
543e3c6431
commit
2c7d7f4094
@ -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;
|
||||
|
@ -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
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "../lib/NetPacks.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "../hch/CVideoHandler.h"
|
||||
#include "../hch/CTownHandler.h"
|
||||
#include <boost/assign/list_of.hpp>
|
||||
#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
|
||||
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";
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ struct SpellCast;
|
||||
template <typename T> struct CondSh;
|
||||
struct SetStackEffect;;
|
||||
struct BattleAction;
|
||||
class CGTownInstance;
|
||||
|
||||
class CBattleInterface;
|
||||
|
||||
@ -225,6 +226,18 @@ private:
|
||||
CDefHandler * anim; //animation to display
|
||||
};
|
||||
std::list<SBattleEffect> 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
|
||||
|
@ -120,7 +120,7 @@ struct DLL_EXPORT BattleInfo
|
||||
|
||||
template <typename Handler> 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
|
||||
|
Loading…
Reference in New Issue
Block a user