1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

code review

This commit is contained in:
Laserlicht 2024-01-21 18:12:46 +01:00 committed by GitHub
parent b82a51d184
commit 0a4b5dbe10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 27 deletions

View File

@ -409,12 +409,12 @@ void OptionsTabBase::recreate()
if(auto buttonCheatAllowed = widget<CToggleButton>("buttonCheatAllowed")) if(auto buttonCheatAllowed = widget<CToggleButton>("buttonCheatAllowed"))
{ {
buttonCheatAllowed->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.cheatsAllowed); buttonCheatAllowed->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.cheatsAllowed);
buttonCheatAllowed->setInputEnabled(SEL->screenType != ESelectionScreen::loadGame); buttonCheatAllowed->block(SEL->screenType == ESelectionScreen::loadGame);
} }
if(auto buttonUnlimitedReplay = widget<CToggleButton>("buttonUnlimitedReplay")) if(auto buttonUnlimitedReplay = widget<CToggleButton>("buttonUnlimitedReplay"))
{ {
buttonUnlimitedReplay->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.unlimitedReplay); buttonUnlimitedReplay->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.unlimitedReplay);
buttonUnlimitedReplay->setInputEnabled(SEL->screenType != ESelectionScreen::loadGame); buttonUnlimitedReplay->block(SEL->screenType == ESelectionScreen::loadGame);
} }
} }

View File

@ -519,25 +519,25 @@ void CTavernWindow::addInvite()
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
if(VLC->settings()->getBoolean(EGameSettings::HEROES_INVITE)) if(!VLC->settings()->getBoolean(EGameSettings::HEROES_TAVERN_INVITE))
return;
const auto & heroesPool = CSH->client->gameState()->heroesPool;
for(auto & elem : heroesPool->unusedHeroesFromPool())
{ {
const auto & heroesPool = CSH->client->gameState()->heroesPool; bool heroAvailable = heroesPool->isHeroAvailableFor(elem.first, tavernObj->getOwner());
for(auto & elem : heroesPool->unusedHeroesFromPool()) if(heroAvailable)
{ inviteableHeroes[elem.first] = elem.second;
bool heroAvailable = heroesPool->isHeroAvailableFor(elem.first, tavernObj->getOwner()); }
if(heroAvailable)
inviteableHeroes[elem.first] = elem.second;
}
if(inviteableHeroes.size() > 0) if(inviteableHeroes.size() > 0)
{ {
if(!heroToInvite) if(!heroToInvite)
heroToInvite = (*RandomGeneratorUtil::nextItem(inviteableHeroes, CRandomGenerator::getDefault())).second; heroToInvite = (*RandomGeneratorUtil::nextItem(inviteableHeroes, CRandomGenerator::getDefault())).second;
inviteHero = std::make_shared<CLabel>(170, 444, EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->translate("vcmi.tavernWindow.inviteHero")); inviteHero = std::make_shared<CLabel>(170, 444, EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->translate("vcmi.tavernWindow.inviteHero"));
inviteHeroImage = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsSmall"), (*CGI->heroh)[heroToInvite->getHeroType()]->imageIndex, 0, 245, 428); inviteHeroImage = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsSmall"), (*CGI->heroh)[heroToInvite->getHeroType()]->imageIndex, 0, 245, 428);
inviteHeroImageArea = std::make_shared<LRClickableArea>(Rect(245, 428, 48, 32), [&](){ GH.windows().createAndPushWindow<HeroSelector>(inviteableHeroes, [&](CGHeroInstance* h){ heroToInvite = h; addInvite(); }); }, [&](){ GH.windows().createAndPushWindow<CRClickPopupInt>(std::make_shared<CHeroWindow>(heroToInvite)); }); inviteHeroImageArea = std::make_shared<LRClickableArea>(Rect(245, 428, 48, 32), [&](){ GH.windows().createAndPushWindow<HeroSelector>(inviteableHeroes, [&](CGHeroInstance* h){ heroToInvite = h; addInvite(); }); }, [&](){ GH.windows().createAndPushWindow<CRClickPopupInt>(std::make_shared<CHeroWindow>(heroToInvite)); });
}
} }
} }

View File

@ -291,7 +291,7 @@
// number of artifacts that can fit in a backpack. -1 is unlimited. // number of artifacts that can fit in a backpack. -1 is unlimited.
"backpackSize" : -1, "backpackSize" : -1,
// if heroes are invitable in tavern // if heroes are invitable in tavern
"invite" : false "tavernInvite" : false
}, },
"towns": "towns":

View File

@ -74,7 +74,7 @@ void GameSettings::load(const JsonNode & input)
{EGameSettings::HEROES_RETREAT_ON_WIN_WITHOUT_TROOPS, "heroes", "retreatOnWinWithoutTroops" }, {EGameSettings::HEROES_RETREAT_ON_WIN_WITHOUT_TROOPS, "heroes", "retreatOnWinWithoutTroops" },
{EGameSettings::HEROES_STARTING_STACKS_CHANCES, "heroes", "startingStackChances" }, {EGameSettings::HEROES_STARTING_STACKS_CHANCES, "heroes", "startingStackChances" },
{EGameSettings::HEROES_BACKPACK_CAP, "heroes", "backpackSize" }, {EGameSettings::HEROES_BACKPACK_CAP, "heroes", "backpackSize" },
{EGameSettings::HEROES_INVITE, "heroes", "invite" }, {EGameSettings::HEROES_TAVERN_INVITE, "heroes", "tavernInvite" },
{EGameSettings::MAP_FORMAT_RESTORATION_OF_ERATHIA, "mapFormat", "restorationOfErathia" }, {EGameSettings::MAP_FORMAT_RESTORATION_OF_ERATHIA, "mapFormat", "restorationOfErathia" },
{EGameSettings::MAP_FORMAT_ARMAGEDDONS_BLADE, "mapFormat", "armageddonsBlade" }, {EGameSettings::MAP_FORMAT_ARMAGEDDONS_BLADE, "mapFormat", "armageddonsBlade" },
{EGameSettings::MAP_FORMAT_SHADOW_OF_DEATH, "mapFormat", "shadowOfDeath" }, {EGameSettings::MAP_FORMAT_SHADOW_OF_DEATH, "mapFormat", "shadowOfDeath" },

View File

@ -38,7 +38,7 @@ enum class EGameSettings
HEROES_RETREAT_ON_WIN_WITHOUT_TROOPS, HEROES_RETREAT_ON_WIN_WITHOUT_TROOPS,
HEROES_STARTING_STACKS_CHANCES, HEROES_STARTING_STACKS_CHANCES,
HEROES_BACKPACK_CAP, HEROES_BACKPACK_CAP,
HEROES_INVITE, HEROES_TAVERN_INVITE,
MARKETS_BLACK_MARKET_RESTOCK_PERIOD, MARKETS_BLACK_MARKET_RESTOCK_PERIOD,
BANKS_SHOW_GUARDS_COMPOSITION, BANKS_SHOW_GUARDS_COMPOSITION,
MODULE_COMMANDERS, MODULE_COMMANDERS,

View File

@ -112,11 +112,7 @@ void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHe
sah.slotID = slot; sah.slotID = slot;
sah.replenishPoints = true; sah.replenishPoints = true;
CGHeroInstance *newHero = pickHeroFor(needNativeHero, color); CGHeroInstance *newHero = (nextHero == HeroTypeID::NONE) ? pickHeroFor(needNativeHero, color) : gameHandler->gameState()->heroesPool->unusedHeroesFromPool()[nextHero];
const auto & heroesPool = gameHandler->gameState()->heroesPool;
if(VLC->settings()->getBoolean(EGameSettings::HEROES_INVITE) && heroesPool->unusedHeroesFromPool().count(nextHero) && heroesPool->isHeroAvailableFor(nextHero, color))
newHero = heroesPool->unusedHeroesFromPool()[nextHero];
if (newHero) if (newHero)
{ {
@ -155,6 +151,7 @@ bool HeroPoolProcessor::hireHero(const ObjectInstanceID & objectID, const HeroTy
const PlayerState * playerState = gameHandler->getPlayerState(player); const PlayerState * playerState = gameHandler->getPlayerState(player);
const CGObjectInstance * mapObject = gameHandler->getObj(objectID); const CGObjectInstance * mapObject = gameHandler->getObj(objectID);
const CGTownInstance * town = gameHandler->getTown(objectID); const CGTownInstance * town = gameHandler->getTown(objectID);
const auto & heroesPool = gameHandler->gameState()->heroesPool;
if (!mapObject && gameHandler->complain("Invalid map object!")) if (!mapObject && gameHandler->complain("Invalid map object!"))
return false; return false;
@ -171,6 +168,10 @@ bool HeroPoolProcessor::hireHero(const ObjectInstanceID & objectID, const HeroTy
if (gameHandler->getHeroCount(player, true) >= VLC->settings()->getInteger(EGameSettings::HEROES_PER_PLAYER_TOTAL_CAP) && gameHandler->complain("Cannot hire hero, too many heroes garrizoned and wandering already!")) if (gameHandler->getHeroCount(player, true) >= VLC->settings()->getInteger(EGameSettings::HEROES_PER_PLAYER_TOTAL_CAP) && gameHandler->complain("Cannot hire hero, too many heroes garrizoned and wandering already!"))
return false; return false;
if(VLC->settings()->getBoolean(EGameSettings::HEROES_TAVERN_INVITE) && nextHero != HeroTypeID::NONE)
if(!heroesPool->unusedHeroesFromPool().count(nextHero) && !heroesPool->isHeroAvailableFor(nextHero, player) && gameHandler->complain("Cannot set next hero!"))
return false;
if(town) //tavern in town if(town) //tavern in town
{ {
if(gameHandler->getPlayerRelations(mapObject->tempOwner, player) == PlayerRelations::ENEMIES && gameHandler->complain("Can't buy hero in enemy town!")) if(gameHandler->getPlayerRelations(mapObject->tempOwner, player) == PlayerRelations::ENEMIES && gameHandler->complain("Can't buy hero in enemy town!"))
@ -197,7 +198,7 @@ bool HeroPoolProcessor::hireHero(const ObjectInstanceID & objectID, const HeroTy
return false; return false;
} }
auto recruitableHeroes = gameHandler->gameState()->heroesPool->getHeroesFor(player); auto recruitableHeroes = heroesPool->getHeroesFor(player);
const CGHeroInstance * recruitedHero = nullptr; const CGHeroInstance * recruitedHero = nullptr;