mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
@ -873,7 +873,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co
|
|||||||
if(pavailable.find(i->first)->second & 1<<player
|
if(pavailable.find(i->first)->second & 1<<player
|
||||||
&& i->second->type->heroType/2 == town->typeID)
|
&& i->second->type->heroType/2 == town->typeID)
|
||||||
{
|
{
|
||||||
pool.push_back(i->second);
|
pool.push_back(i->second); //get all avaliable heroes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!pool.size())
|
if(!pool.size())
|
||||||
@ -895,7 +895,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co
|
|||||||
if(pavailable.find(i->first)->second & 1<<player)
|
if(pavailable.find(i->first)->second & 1<<player)
|
||||||
{
|
{
|
||||||
pool.push_back(i->second);
|
pool.push_back(i->second);
|
||||||
sum += i->second->type->heroClass->selectionProbability[town->typeID];
|
sum += i->second->type->heroClass->selectionProbability[town->typeID]; //total weight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!pool.size())
|
if(!pool.size())
|
||||||
@ -905,11 +905,14 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
r = rand()%sum;
|
r = rand()%sum;
|
||||||
for(unsigned int i=0; i<pool.size(); i++)
|
for (unsigned int i=0; i<pool.size(); i++)
|
||||||
{
|
{
|
||||||
r -= pool[i]->type->heroClass->selectionProbability[town->typeID];
|
r -= pool[i]->type->heroClass->selectionProbability[town->typeID];
|
||||||
if(r<0)
|
if(r < 0)
|
||||||
|
{
|
||||||
ret = pool[i];
|
ret = pool[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!ret)
|
if(!ret)
|
||||||
ret = pool.back();
|
ret = pool.back();
|
||||||
|
@ -323,7 +323,7 @@ public:
|
|||||||
struct DLL_EXPORT HeroesPool
|
struct DLL_EXPORT HeroesPool
|
||||||
{
|
{
|
||||||
std::map<ui32,CGHeroInstance *> heroesPool; //[subID] - heroes available to buy; NULL if not available
|
std::map<ui32,CGHeroInstance *> heroesPool; //[subID] - heroes available to buy; NULL if not available
|
||||||
std::map<ui32,ui8> pavailable; // [subid] -> which players can recruit hero
|
std::map<ui32,ui8> pavailable; // [subid] -> which players can recruit hero (binary flags)
|
||||||
|
|
||||||
CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, std::map<ui32,CGHeroInstance *> &available) const;
|
CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, std::map<ui32,CGHeroInstance *> &available) const;
|
||||||
|
|
||||||
|
@ -2439,22 +2439,22 @@ bool CGameHandler::hireHero( ui32 tid, ui8 hid )
|
|||||||
hr.tile = t->pos - int3(1,0,0);
|
hr.tile = t->pos - int3(1,0,0);
|
||||||
sendAndApply(&hr);
|
sendAndApply(&hr);
|
||||||
|
|
||||||
|
|
||||||
std::map<ui32,CGHeroInstance *> pool = gs->hpool.heroesPool;
|
std::map<ui32,CGHeroInstance *> pool = gs->hpool.heroesPool;
|
||||||
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
|
||||||
for(std::vector<CGHeroInstance *>::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++)
|
|
||||||
if(*j)
|
|
||||||
pool.erase((**j).subID);
|
|
||||||
|
|
||||||
SetAvailableHeroes sah;
|
SetAvailableHeroes sah;
|
||||||
CGHeroInstance *h1 = gs->hpool.pickHeroFor(false,t->tempOwner,t->town, pool),
|
CGHeroInstance *h1 = gs->hpool.pickHeroFor(false,t->tempOwner,t->town, pool), //new hero
|
||||||
*h2 = gs->getPlayer(t->tempOwner)->availableHeroes[!hid];
|
*h2 = gs->getPlayer(t->tempOwner)->availableHeroes[!hid];
|
||||||
(hid ? sah.hid2 : sah.hid1) = h1 ? h1->subID : -1;
|
(hid ? sah.hid2 : sah.hid1) = h1 ? h1->subID : -1;
|
||||||
(hid ? sah.hid1 : sah.hid2) = h2 ? h2->subID : -1;
|
(hid ? sah.hid1 : sah.hid2) = h2 ? h2->subID : -1;
|
||||||
sah.player = t->tempOwner;
|
sah.player = t->tempOwner;
|
||||||
sah.flags = hid+1;
|
//sah.flags = hid+1; //without army - why?
|
||||||
sendAndApply(&sah);
|
sendAndApply(&sah);
|
||||||
|
|
||||||
|
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||||
|
for(std::vector<CGHeroInstance *>::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++)
|
||||||
|
if(*j)
|
||||||
|
pool.erase((**j).subID); //hero is removed from available lists
|
||||||
|
|
||||||
SetResource sr;
|
SetResource sr;
|
||||||
sr.player = t->tempOwner;
|
sr.player = t->tempOwner;
|
||||||
sr.resid = 6;
|
sr.resid = 6;
|
||||||
|
Reference in New Issue
Block a user