1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Do not allow heroes banned for player as starting heroes

- `disposedHeroes` is now in map header, for use in map selection
- heroes that are marked as unavailable for player will now be hidden
from starting hero selection
This commit is contained in:
Ivan Savenko
2025-02-14 10:43:55 +00:00
parent 7e1ce095a1
commit 4b824d05e2
9 changed files with 67 additions and 43 deletions

View File

@ -974,10 +974,26 @@ void CVCMIServer::optionSetBonus(PlayerColor player, PlayerStartingBonus id)
bool CVCMIServer::canUseThisHero(PlayerColor player, HeroTypeID ID)
{
return VLC->heroh->size() > ID
&& si->playerInfos[player].castle == VLC->heroh->objects[ID]->heroClass->faction
&& !vstd::contains(getUsedHeroes(), ID)
&& mi->mapHeader->allowedHeroes.count(ID);
if (!ID.hasValue())
return false;
if (ID >= VLC->heroh->size())
return false;
if (si->playerInfos[player].castle != VLC->heroh->objects[ID]->heroClass->faction)
return false;
if (vstd::contains(getUsedHeroes(), ID))
return false;
if (!mi->mapHeader->allowedHeroes.count(ID))
return false;
for (const auto & disposedHero : mi->mapHeader->disposedHeroes)
if (disposedHero.heroId == ID && !disposedHero.players.count(player))
return false;
return true;
}
std::vector<HeroTypeID> CVCMIServer::getUsedHeroes()