mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
* fixed 8 hero limit to check only for wandering heroes (not garrisoned)
* srand at the beginning of handleConnection
This commit is contained in:
parent
e3222fd34f
commit
7a9e323297
@ -145,10 +145,10 @@ const CGTownInstance * CCallback::getTownInfo(int val, bool mode) const //mode =
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
int CCallback::howManyHeroes() const
|
||||
int CCallback::howManyHeroes(bool includeGarrisoned) const
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
return gs->players[player].heroes.size();
|
||||
return cl->getHeroCount(player,includeGarrisoned);
|
||||
}
|
||||
const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()const =0; //returns visibility map (TODO: make it const)
|
||||
virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
virtual int getResourceAmount(int type)const =0;
|
||||
virtual int howManyHeroes()const =0;
|
||||
virtual int howManyHeroes(bool includeGarrisoned = true)const =0;
|
||||
virtual const CGTownInstance * getTownInfo(int val, bool mode)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
virtual int howManyTowns()const =0;
|
||||
virtual std::vector < std::string > getObjDescriptions(int3 pos)const =0; //returns descriptions of objects at pos in order from the lowest to the highest
|
||||
@ -148,7 +148,7 @@ public:
|
||||
const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
int getResourceAmount(int type) const;
|
||||
std::vector<si32> getResourceAmount() const;
|
||||
int howManyHeroes() const;
|
||||
int howManyHeroes(bool includeGarrisoned = true) const;
|
||||
const CGTownInstance * getTownInfo(int val, bool mode) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true) const;
|
||||
int howManyTowns()const;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/assign/std/vector.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
using namespace boost::assign;
|
||||
@ -252,8 +253,25 @@ void CHeroGSlot::clickLeft(boost::logic::tribool down)
|
||||
}
|
||||
else if(other->hero && other->highlight)
|
||||
{
|
||||
bool allow = true;
|
||||
if(upg) //moving hero out of town - check if it is allowed
|
||||
{
|
||||
if(!hero && LOCPLINT->cb->howManyHeroes(false) >= 8)
|
||||
{
|
||||
std::string tmp = CGI->generaltexth->allTexts[18]; //You already have %d adventuring heroes under your command.
|
||||
boost::algorithm::replace_first(tmp,"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes(false)));
|
||||
LOCPLINT->showInfoDialog(tmp,std::vector<SComponent*>());
|
||||
allow = false;
|
||||
}
|
||||
else if(!other->hero->army.slots.size()) //hero has no creatures - strange, but if we have appropriate error message...
|
||||
{
|
||||
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[19],std::vector<SComponent*>()); //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside.
|
||||
allow = false;
|
||||
}
|
||||
}
|
||||
other->highlight = highlight = false;
|
||||
LOCPLINT->cb->swapGarrisonHero(owner->town);
|
||||
if(allow)
|
||||
LOCPLINT->cb->swapGarrisonHero(owner->town);
|
||||
}
|
||||
else if(hero)
|
||||
{
|
||||
|
@ -4426,7 +4426,7 @@ CTavernWindow::CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2,
|
||||
recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[0]; //Cannot afford a Hero
|
||||
recruit->block(2);
|
||||
}
|
||||
else if(LOCPLINT->cb->howManyHeroes() >= 8)
|
||||
else if(LOCPLINT->cb->howManyHeroes(false) >= 8)
|
||||
{
|
||||
recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[1]; //Cannot recruit. You already have %d Heroes.
|
||||
boost::algorithm::replace_first(recruit->hoverTexts[0],"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes()));
|
||||
|
@ -24,7 +24,6 @@ DLL_EXPORT std::ostream *logfile = NULL
|
||||
;
|
||||
DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile)
|
||||
{
|
||||
srand(time(NULL));
|
||||
console = Console;
|
||||
logfile = Logfile;
|
||||
bitmaph=b;
|
||||
|
@ -485,6 +485,7 @@ void CGameHandler::prepareAttack(BattleAttack &bat, CStack *att, CStack *def)
|
||||
}
|
||||
void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
|
||||
{
|
||||
srand(time(NULL));
|
||||
CPack *pack = NULL;
|
||||
try
|
||||
{
|
||||
@ -1746,6 +1747,13 @@ void CGameHandler::garrisonSwap(si32 tid)
|
||||
}
|
||||
else if (town->garrisonHero && !town->visitingHero) //move hero out of the garrison
|
||||
{
|
||||
//check if moving hero out of town will break 8 wandering heroes limit
|
||||
if(getHeroCount(town->garrisonHero->tempOwner,true) >= 8)
|
||||
{
|
||||
complain("Cannot move hero out of the garrison, there are already 8 wandering heroes!");
|
||||
return;
|
||||
}
|
||||
|
||||
SetHeroesInTown intown;
|
||||
intown.tid = tid;
|
||||
intown.garrison = -1;
|
||||
@ -1870,7 +1878,7 @@ void CGameHandler::hireHero( ui32 tid, ui8 hid )
|
||||
if(!vstd::contains(t->builtBuildings,5) //no tavern in the town
|
||||
|| gs->getPlayer(t->tempOwner)->resources[6]<2500 //not enough gold
|
||||
|| t->visitingHero //there is visiting hero - no place
|
||||
|| gs->getPlayer(t->tempOwner)->heroes.size()>7 //8 hero limit
|
||||
|| getHeroCount(t->tempOwner,false) >= 8 && complain("Cannot hire hero, only 8 wandering heroes are allowed!")
|
||||
)
|
||||
return;
|
||||
CGHeroInstance *nh = gs->getPlayer(t->tempOwner)->availableHeroes[hid];
|
||||
|
Loading…
Reference in New Issue
Block a user