1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* support for battles in creature banks (hopefully)

This commit is contained in:
mateuszb 2009-08-17 10:47:08 +00:00
parent fbc117b034
commit e892913635
8 changed files with 164 additions and 135 deletions

View File

@ -76,7 +76,7 @@ void processCommand(const std::string &message);
static void setScreenRes(int w, int h, int bpp, bool fullscreen); static void setScreenRes(int w, int h, int bpp, bool fullscreen);
void dispose(); void dispose();
void playIntro(); void playIntro();
void listenForEvents(); void listenForEvents();
void startGame(StartInfo * options); void startGame(StartInfo * options);
void init() void init()
@ -414,95 +414,95 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen)
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
} }
void listenForEvents() void listenForEvents()
{ {
SDL_Event *ev = NULL; SDL_Event *ev = NULL;
while(1) //main SDL events loop while(1) //main SDL events loop
{ {
ev = new SDL_Event(); ev = new SDL_Event();
int ret = SDL_WaitEvent(ev); int ret = SDL_WaitEvent(ev);
if(ret == 0 || (ev->type==SDL_QUIT) || (ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4 && (ev->key.keysym.mod & KMOD_ALT))) if(ret == 0 || (ev->type==SDL_QUIT) || (ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4 && (ev->key.keysym.mod & KMOD_ALT)))
{ {
LOCPLINT->pim->lock(); LOCPLINT->pim->lock();
client->close(); client->close();
console->end(); console->end();
SDL_Delay(750); SDL_Delay(750);
tlog0 << "Ending...\n"; tlog0 << "Ending...\n";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
else if(ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4) else if(ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4)
{ {
boost::unique_lock<boost::recursive_mutex> lock(*LOCPLINT->pim); boost::unique_lock<boost::recursive_mutex> lock(*LOCPLINT->pim);
bool full = !(screen->flags&SDL_FULLSCREEN); bool full = !(screen->flags&SDL_FULLSCREEN);
setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,full); setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,full);
GH.totalRedraw(); GH.totalRedraw();
} }
eventsM.lock(); eventsM.lock();
events.push(ev); events.push(ev);
eventsM.unlock(); eventsM.unlock();
} }
} }
void startGame(StartInfo * options) void startGame(StartInfo * options)
{ {
if(gOnlyAI) if(gOnlyAI)
{ {
for (size_t i =0; i < options->playerInfos.size(); i++) for (size_t i =0; i < options->playerInfos.size(); i++)
{ {
options->playerInfos[i].human = false; options->playerInfos[i].human = false;
} }
} }
if(screen->w != conf.cc.resx || screen->h != conf.cc.resy) if(screen->w != conf.cc.resx || screen->h != conf.cc.resy)
{ {
setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,conf.cc.fullscreen); setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,conf.cc.fullscreen);
} }
CClient cl; CClient cl;
if(options->mode == 0) //new game if(options->mode == 0) //new game
{ {
timeHandler pomtime; timeHandler pomtime;
char portc[10]; char portc[10];
SDL_itoa(conf.cc.port,portc,10); SDL_itoa(conf.cc.port,portc,10);
CClient::runServer(portc); CClient::runServer(portc);
tlog0<<"Preparing shared memory and starting server: "<<pomtime.getDif()<<std::endl; tlog0<<"Preparing shared memory and starting server: "<<pomtime.getDif()<<std::endl;
pomtime.getDif();//reset timers pomtime.getDif();//reset timers
CConnection *c=NULL; CConnection *c=NULL;
//wait until server is ready //wait until server is ready
tlog0<<"Waiting for server... "; tlog0<<"Waiting for server... ";
cl.waitForServer(); cl.waitForServer();
tlog0 << pomtime.getDif()<<std::endl; tlog0 << pomtime.getDif()<<std::endl;
while(!c) while(!c)
{ {
try try
{ {
tlog0 << "Establishing connection...\n"; tlog0 << "Establishing connection...\n";
c = new CConnection(conf.cc.server,portc,NAME); c = new CConnection(conf.cc.server,portc,NAME);
} }
catch(...) catch(...)
{ {
tlog1 << "\nCannot establish connection! Retrying within 2 seconds" <<std::endl; tlog1 << "\nCannot establish connection! Retrying within 2 seconds" <<std::endl;
SDL_Delay(2000); SDL_Delay(2000);
} }
} }
THC tlog0<<"\tConnecting to the server: "<<pomtime.getDif()<<std::endl; THC tlog0<<"\tConnecting to the server: "<<pomtime.getDif()<<std::endl;
cl.newGame(c,options); cl.newGame(c,options);
client = &cl; client = &cl;
CGI->musich->stopMusic(); CGI->musich->stopMusic();
client->run(); client->run();
//boost::thread t(boost::bind(&CClient::run,&cl)); //boost::thread t(boost::bind(&CClient::run,&cl));
} }
else //load game else //load game
{ {
std::string fname = options->mapname; std::string fname = options->mapname;
boost::algorithm::erase_last(fname,".vlgm1"); boost::algorithm::erase_last(fname,".vlgm1");
cl.load(fname); cl.load(fname);
client = &cl; client = &cl;
CGI->musich->stopMusic(); CGI->musich->stopMusic();
client->run(); client->run();
//boost::thread t(boost::bind(&CClient::run,&cl)); //boost::thread t(boost::bind(&CClient::run,&cl));
} }
} }

View File

@ -32,7 +32,7 @@
* Full text of license available in license.txt file, in main folder * Full text of license available in license.txt file, in main folder
* *
*/ */
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
void startGame(StartInfo * options); void startGame(StartInfo * options);
CGPreGame * CGP; CGPreGame * CGP;

View File

@ -101,9 +101,9 @@ public:
void heroVisitCastle(int obj, int heroID){}; void heroVisitCastle(int obj, int heroID){};
void stopHeroVisitCastle(int obj, int heroID){}; void stopHeroVisitCastle(int obj, int heroID){};
void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb = 0){}; //use hero=NULL for no hero void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank, boost::function<void(BattleResult*)> cb = 0){}; //use hero=NULL for no hero
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb = 0){}; //if any of armies is hero, hero will be used void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, bool creatureBank, boost::function<void(BattleResult*)> cb = 0){}; //if any of armies is hero, hero will be used
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb = 0){}; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, bool creatureBank, boost::function<void(BattleResult*)> cb = 0){}; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
void setAmount(int objid, ui32 val){}; void setAmount(int objid, ui32 val){};
bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255){return false;}; bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255){return false;};
void giveHeroBonus(GiveBonus * bonus){}; void giveHeroBonus(GiveBonus * bonus){};

View File

@ -31,4 +31,21 @@
66 83 117 134 66 83 117 134
66 83 100 117 134 66 83 100 117 134
49 66 83 117 134 151 49 66 83 117 134 151
49 66 83 100 117 134 151 49 66 83 100 117 134 151
//creature_bank
//attacker
57
57 61
57 61 90
57 61 90 93
57 61 90 93 96
57 61 90 93 96 125
57 61 90 93 96 125 129
//defender
2
2 15
2 15 100
2 15 100 185
2 15 100 185 172
2 15 100 185 172 87
2 15 100 185 172 87 8

View File

@ -677,7 +677,7 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
else else
{ {
//battle //battle
cb->startBattleI(h, this); cb->startBattleI(h, this, false);
} }
} }
else if(ID == 62) //prison else if(ID == 62) //prison
@ -1160,7 +1160,7 @@ void CGDwelling::heroAcceptsCreatures( const CGHeroInstance *h, ui32 answer ) co
void CGDwelling::wantsFight( const CGHeroInstance *h, ui32 answer ) const void CGDwelling::wantsFight( const CGHeroInstance *h, ui32 answer ) const
{ {
if(answer) if(answer)
cb->startBattleI(h, this, boost::bind(&CGDwelling::fightOver, this, h, _1)); cb->startBattleI(h, this, false, boost::bind(&CGDwelling::fightOver, this, h, _1));
} }
void CGDwelling::fightOver(const CGHeroInstance *h, BattleResult *result) const void CGDwelling::fightOver(const CGHeroInstance *h, BattleResult *result) const
@ -1942,7 +1942,7 @@ void CGCreature::joinDecision(const CGHeroInstance *h, int cost, ui32 accept) co
void CGCreature::fight( const CGHeroInstance *h ) const void CGCreature::fight( const CGHeroInstance *h ) const
{ {
cb->startBattleI(h, this, boost::bind(&CGCreature::endBattle,this,_1)); cb->startBattleI(h, this, false, boost::bind(&CGCreature::endBattle,this,_1));
} }
void CGCreature::flee( const CGHeroInstance * h ) const void CGCreature::flee( const CGHeroInstance * h ) const
@ -2078,7 +2078,7 @@ void CGResource::collectRes( int player ) const
void CGResource::fightForRes(ui32 agreed, const CGHeroInstance *h) const void CGResource::fightForRes(ui32 agreed, const CGHeroInstance *h) const
{ {
if(agreed) if(agreed)
cb->startBattleI(h, this, boost::bind(&CGResource::endBattle,this,_1,h)); cb->startBattleI(h, this, false, boost::bind(&CGResource::endBattle,this,_1,h));
} }
void CGResource::endBattle( BattleResult *result, const CGHeroInstance *h ) const void CGResource::endBattle( BattleResult *result, const CGHeroInstance *h ) const
@ -2288,7 +2288,7 @@ void CGArtifact::pick(const CGHeroInstance * h) const
void CGArtifact::fightForArt( ui32 agreed, const CGHeroInstance *h ) const void CGArtifact::fightForArt( ui32 agreed, const CGHeroInstance *h ) const
{ {
if(agreed) if(agreed)
cb->startBattleI(h, this, boost::bind(&CGArtifact::endBattle,this,_1,h)); cb->startBattleI(h, this, false, boost::bind(&CGArtifact::endBattle,this,_1,h));
} }
void CGArtifact::endBattle( BattleResult *result, const CGHeroInstance *h ) const void CGArtifact::endBattle( BattleResult *result, const CGHeroInstance *h ) const
@ -2800,7 +2800,7 @@ void CGEvent::activated( const CGHeroInstance * h ) const
else else
iw.text.addTxt(MetaString::ADVOB_TXT, 16); iw.text.addTxt(MetaString::ADVOB_TXT, 16);
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
cb->startBattleI(h, this, boost::bind(&CGEvent::endBattle,this,h,_1)); cb->startBattleI(h, this, false, boost::bind(&CGEvent::endBattle,this,h,_1));
} }
else else
{ {
@ -2812,6 +2812,7 @@ void CGPandoraBox::initObj()
{ {
blockVisit = true; blockVisit = true;
} }
void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
{ {
BlockingDialog bd (true, false); BlockingDialog bd (true, false);
@ -2820,23 +2821,24 @@ void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
bd.text.addTxt (MetaString::ADVOB_TXT, 14); bd.text.addTxt (MetaString::ADVOB_TXT, 14);
cb->showBlockingDialog (&bd, boost::bind (&CGPandoraBox::open, this, h, _1)); cb->showBlockingDialog (&bd, boost::bind (&CGPandoraBox::open, this, h, _1));
} }
void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const
{ {
if (accept) if (accept)
{ {
if (army) if (army) //if pandora's box is protested by army
{ {
InfoWindow iw; InfoWindow iw;
iw.player = h->tempOwner; iw.player = h->tempOwner;
iw.text.addTxt(MetaString::ADVOB_TXT, 16); iw.text.addTxt(MetaString::ADVOB_TXT, 16);
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
cb->startBattleI(h, this, boost::bind(&CGPandoraBox::endBattle, this, h,_1)); cb->startBattleI(h, this, false, boost::bind(&CGPandoraBox::endBattle, this, h, _1)); //grants things after battle
} }
else if (message.size() == resources.size() == else if (message.size() == 0 && resources.size() == 0
primskills.size() == abilities.size() == && primskills.size() == 0 && abilities.size() == 0
abilityLevels.size() == artifacts.size() == && abilityLevels.size() == 0 && artifacts.size() == 0
spells.size() == creatures == && spells.size() == 0 && creatures == 0
gainedExp == manaDiff == moraleDiff == luckDiff == 0) //yeaha! && gainedExp == 0 && manaDiff == 0 && moraleDiff == 0 && luckDiff == 0) //if it gives nothing without battle
{ {
InfoWindow iw; InfoWindow iw;
iw.player = h->tempOwner; iw.player = h->tempOwner;
@ -2844,12 +2846,13 @@ void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
} }
else else //if it gives something without battle
{ {
giveContents (h, false); giveContents (h, false);
} }
} }
} }
void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) const void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) const
{ {
InfoWindow iw; InfoWindow iw;

View File

@ -77,9 +77,9 @@ public:
virtual void heroVisitCastle(int obj, int heroID)=0; virtual void heroVisitCastle(int obj, int heroID)=0;
virtual void stopHeroVisitCastle(int obj, int heroID)=0; virtual void stopHeroVisitCastle(int obj, int heroID)=0;
virtual void giveHeroArtifact(int artid, int hid, int position)=0; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack virtual void giveHeroArtifact(int artid, int hid, int position)=0; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb = 0)=0; //use hero=NULL for no hero virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank, boost::function<void(BattleResult*)> cb = 0)=0; //use hero=NULL for no hero
virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb = 0)=0; //if any of armies is hero, hero will be used virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, bool creatureBank, boost::function<void(BattleResult*)> cb = 0)=0; //if any of armies is hero, hero will be used
virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb = 0)=0; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, bool creatureBank, boost::function<void(BattleResult*)> cb = 0)=0; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
//virtual void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb)=0; //for hero<=>neutral army //virtual void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb)=0; //for hero<=>neutral army
virtual void setAmount(int objid, ui32 val)=0; virtual void setAmount(int objid, ui32 val)=0;
virtual bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255)=0; virtual bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255)=0;

View File

@ -322,10 +322,10 @@ static CCreatureSet takeCasualties(int color, const CCreatureSet &set, BattleInf
return ret; return ret;
} }
void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb) void CGameHandler::startBattle(const CArmedInstance *army1, const CArmedInstance * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank, boost::function<void(BattleResult*)> cb)
{ {
BattleInfo *curB = new BattleInfo; BattleInfo *curB = new BattleInfo;
setupBattle(curB, tile, army1->army, army2->army, hero1, hero2); //initializes stacks, places creatures on battlefield, blocks and informs player interfaces setupBattle(curB, tile, army1->army, army2->army, hero1, hero2, creatureBank); //initializes stacks, places creatures on battlefield, blocks and informs player interfaces
NEW_ROUND; NEW_ROUND;
//TODO: pre-tactic stuff, call scripts etc. //TODO: pre-tactic stuff, call scripts etc.
@ -842,7 +842,7 @@ void CGameHandler::run(bool resume)
namespace CGH namespace CGH
{ {
using namespace std; using namespace std;
static void readItTo(ifstream & input, vector< vector<int> > & dest) static void readItTo(ifstream & input, vector< vector<int> > & dest) //reads 7 lines, i-th one containing i integers, and puts it to dest
{ {
for(int j=0; j<7; ++j) for(int j=0; j<7; ++j)
{ {
@ -857,7 +857,7 @@ namespace CGH
} }
} }
void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, const CCreatureSet &army1, const CCreatureSet &army2, const CGHeroInstance * hero1, const CGHeroInstance * hero2 ) void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, const CCreatureSet &army1, const CCreatureSet &army2, const CGHeroInstance * hero1, const CGHeroInstance * hero2, bool creatureBank )
{ {
battleResult.set(NULL); battleResult.set(NULL);
std::vector<CStack*> & stacks = (curB->stacks); std::vector<CStack*> & stacks = (curB->stacks);
@ -882,7 +882,7 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, const CCreatureSet
} }
std::string dump; std::string dump;
positions>>dump; positions>>dump; positions>>dump; positions>>dump;
std::vector< std::vector<int> > attackerLoose, defenderLoose, attackerTight, defenderTight; std::vector< std::vector<int> > attackerLoose, defenderLoose, attackerTight, defenderTight, attackerCreBank, defenderCreBank;
CGH::readItTo(positions, attackerLoose); CGH::readItTo(positions, attackerLoose);
positions>>dump; positions>>dump;
CGH::readItTo(positions, defenderLoose); CGH::readItTo(positions, defenderLoose);
@ -891,6 +891,11 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, const CCreatureSet
CGH::readItTo(positions, attackerTight); CGH::readItTo(positions, attackerTight);
positions>>dump; positions>>dump;
CGH::readItTo(positions, defenderTight); CGH::readItTo(positions, defenderTight);
positions>>dump;
positions>>dump;
CGH::readItTo(positions, attackerCreBank);
positions>>dump;
CGH::readItTo(positions, defenderCreBank);
positions.close(); positions.close();
//battleStartpos read //battleStartpos read
@ -898,7 +903,9 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, const CCreatureSet
for(std::map<si32,std::pair<ui32,si32> >::const_iterator i = army1.slots.begin(); i!=army1.slots.end(); i++, k++) for(std::map<si32,std::pair<ui32,si32> >::const_iterator i = army1.slots.begin(); i!=army1.slots.end(); i++, k++)
{ {
int pos; int pos;
if(army1.formation) if(creatureBank)
pos = attackerCreBank[army1.slots.size()-1][k];
else if(army1.formation)
pos = attackerTight[army1.slots.size()-1][k]; pos = attackerTight[army1.slots.size()-1][k];
else else
pos = attackerLoose[army1.slots.size()-1][k]; pos = attackerLoose[army1.slots.size()-1][k];
@ -911,7 +918,9 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, const CCreatureSet
for(std::map<si32,std::pair<ui32,si32> >::const_iterator i = army2.slots.begin(); i!=army2.slots.end(); i++, k++) for(std::map<si32,std::pair<ui32,si32> >::const_iterator i = army2.slots.begin(); i!=army2.slots.end(); i++, k++)
{ {
int pos; int pos;
if(army2.formation) if(creatureBank)
pos = defenderCreBank[army1.slots.size()-1][k];
else if(army2.formation)
pos = defenderTight[army2.slots.size()-1][k]; pos = defenderTight[army2.slots.size()-1][k];
else else
pos = defenderLoose[army2.slots.size()-1][k]; pos = defenderLoose[army2.slots.size()-1][k];
@ -1374,7 +1383,7 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*
return true; return true;
} }
//TODO: check for ally //TODO: check for ally
startBattleI(h, dh); startBattleI(h, dh, false);
return true; return true;
} }
} }
@ -1530,7 +1539,7 @@ void CGameHandler::giveHeroArtifact(int artid, int hid, int position) //pos==-1
sendAndApply(&sha); sendAndApply(&sha);
} }
void CGameHandler::startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb) //use hero=NULL for no hero void CGameHandler::startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank, boost::function<void(BattleResult*)> cb) //use hero=NULL for no hero
{ {
engageIntoBattle(army1->tempOwner); engageIntoBattle(army1->tempOwner);
engageIntoBattle(army2->tempOwner); engageIntoBattle(army2->tempOwner);
@ -1538,20 +1547,20 @@ void CGameHandler::startBattleI(const CArmedInstance *army1, const CArmedInstanc
if(army2->tempOwner < PLAYER_LIMIT) if(army2->tempOwner < PLAYER_LIMIT)
states.setFlag(army2->tempOwner,&PlayerStatus::engagedIntoBattle,true); states.setFlag(army2->tempOwner,&PlayerStatus::engagedIntoBattle,true);
boost::thread(boost::bind(&CGameHandler::startBattle,this,army1,army2,tile,hero1,hero2,cb)); boost::thread(boost::bind(&CGameHandler::startBattle, this, army1, army2, tile, hero1, hero2, creatureBank, cb));
} }
void CGameHandler::startBattleI( const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb ) void CGameHandler::startBattleI( const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, bool creatureBank, boost::function<void(BattleResult*)> cb )
{ {
startBattleI(army1, army2, tile, startBattleI(army1, army2, tile,
army1->ID == 34 ? static_cast<const CGHeroInstance*>(army1) : NULL, army1->ID == HEROI_TYPE ? static_cast<const CGHeroInstance*>(army1) : NULL,
army2->ID == 34 ? static_cast<const CGHeroInstance*>(army2) : NULL, army2->ID == HEROI_TYPE ? static_cast<const CGHeroInstance*>(army2) : NULL,
cb); creatureBank, cb);
} }
void CGameHandler::startBattleI( const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb) void CGameHandler::startBattleI( const CArmedInstance *army1, const CArmedInstance *army2, bool creatureBank, boost::function<void(BattleResult*)> cb)
{ {
startBattleI(army1, army2, army2->pos - army2->getVisitableOffset(), cb); startBattleI(army1, army2, army2->pos - army2->getVisitableOffset(), creatureBank, cb);
} }
//void CGameHandler::startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb) //for hero<=>neutral army //void CGameHandler::startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb) //for hero<=>neutral army

View File

@ -84,11 +84,11 @@ public:
bool isAllowedExchange(int id1, int id2); bool isAllowedExchange(int id1, int id2);
void giveSpells(const CGTownInstance *t, const CGHeroInstance *h); void giveSpells(const CGTownInstance *t, const CGHeroInstance *h);
void moveStack(int stack, int dest); void moveStack(int stack, int dest);
void startBattle(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero void startBattle(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero
void prepareAttack(BattleAttack &bat, CStack *att, CStack *def); //if last parameter is true, attack is by shooting, if false it's a melee attack void prepareAttack(BattleAttack &bat, CStack *att, CStack *def); //if last parameter is true, attack is by shooting, if false it's a melee attack
void prepareAttacked(BattleStackAttacked &bsa, CStack *def); void prepareAttacked(BattleStackAttacked &bsa, CStack *def);
void checkForBattleEnd( std::vector<CStack*> &stacks ); void checkForBattleEnd( std::vector<CStack*> &stacks );
void setupBattle( BattleInfo * curB, int3 tile, const CCreatureSet &army1, const CCreatureSet &army2, const CGHeroInstance * hero1, const CGHeroInstance * hero2 ); void setupBattle( BattleInfo * curB, int3 tile, const CCreatureSet &army1, const CCreatureSet &army2, const CGHeroInstance * hero1, const CGHeroInstance * hero2, bool creatureBank );
CGameHandler(void); CGameHandler(void);
@ -122,9 +122,9 @@ public:
void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack; pos==-2 - default if available or backpack void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack; pos==-2 - default if available or backpack
void moveArtifact(int hid, int oldPosition, int destPos); void moveArtifact(int hid, int oldPosition, int destPos);
void removeArtifact(int hid, int pos); void removeArtifact(int hid, int pos);
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb); void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, bool creatureBank, boost::function<void(BattleResult*)> cb);
void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb = 0); //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, bool creatureBank, boost::function<void(BattleResult*)> cb = 0); //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
//void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb); //for hero<=>neutral army //void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb); //for hero<=>neutral army
void setAmount(int objid, ui32 val); void setAmount(int objid, ui32 val);
bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255); bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255);