mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-02 00:10:22 +02:00
Update tavern on end of 7th turn of player in question
Allows removal of "retreat after 7th day" workaround and as result - more straightforward code
This commit is contained in:
parent
c171a3d6be
commit
ee8adbe85f
@ -124,15 +124,6 @@ void TavernHeroesPool::onNewDay()
|
||||
hero.second->setMovementPoints(hero.second->movementPointsLimit(true));
|
||||
hero.second->mana = hero.second->manaLimit();
|
||||
}
|
||||
|
||||
for (auto & slot : currentTavern)
|
||||
{
|
||||
if (slot.role == TavernSlotRole::RETREATED_TODAY)
|
||||
slot.role = TavernSlotRole::RETREATED;
|
||||
|
||||
if (slot.role == TavernSlotRole::SURRENDERED_TODAY)
|
||||
slot.role = TavernSlotRole::SURRENDERED;
|
||||
}
|
||||
}
|
||||
|
||||
void TavernHeroesPool::addHeroToPool(CGHeroInstance * hero)
|
||||
|
@ -24,12 +24,8 @@ enum class TavernSlotRole : int8_t
|
||||
|
||||
SINGLE_UNIT, // hero was added after buying hero from this slot, and only has 1 creature in army
|
||||
FULL_ARMY, // hero was added to tavern on new week and still has full army
|
||||
|
||||
RETREATED, // hero was owned by player before, but have retreated from battle and only has 1 creature in army
|
||||
RETREATED_TODAY,
|
||||
|
||||
SURRENDERED, // hero was owned by player before, but have surrendered in battle and kept some troops
|
||||
SURRENDERED_TODAY,
|
||||
SURRENDERED // hero was owned by player before, but have surrendered in battle and kept some troops
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -611,6 +611,11 @@ void CGameHandler::onPlayerTurnEnded(PlayerColor which)
|
||||
{
|
||||
// 7 days without castle
|
||||
checkVictoryLossConditionsForPlayer(which);
|
||||
|
||||
bool newWeek = getDate(Date::DAY_OF_WEEK) == 7; // end of 7th day
|
||||
|
||||
if (newWeek) //new heroes in tavern
|
||||
heroPool->onNewWeek(which);
|
||||
}
|
||||
|
||||
void CGameHandler::onNewTurn()
|
||||
@ -702,13 +707,13 @@ void CGameHandler::onNewTurn()
|
||||
{
|
||||
if (elem.first == PlayerColor::NEUTRAL)
|
||||
continue;
|
||||
else if (elem.first >= PlayerColor::PLAYER_LIMIT)
|
||||
assert(0); //illegal player number!
|
||||
|
||||
assert(elem.first.isValidPlayer());//illegal player number!
|
||||
|
||||
std::pair<PlayerColor, si32> playerGold(elem.first, elem.second.resources[EGameResID::GOLD]);
|
||||
hadGold.insert(playerGold);
|
||||
|
||||
if (newWeek) //new heroes in tavern
|
||||
if (firstTurn)
|
||||
heroPool->onNewWeek(elem.first);
|
||||
|
||||
n.res[elem.first] = elem.second.resources;
|
||||
|
@ -68,9 +68,6 @@ TavernHeroSlot HeroPoolProcessor::selectSlotForRole(const PlayerColor & player,
|
||||
void HeroPoolProcessor::onHeroSurrendered(const PlayerColor & color, const CGHeroInstance * hero)
|
||||
{
|
||||
SetAvailableHero sah;
|
||||
if (gameHandler->turnOrder->playerAwaitsNewDay(color))
|
||||
sah.roleID = TavernSlotRole::SURRENDERED_TODAY;
|
||||
else
|
||||
sah.roleID = TavernSlotRole::SURRENDERED;
|
||||
|
||||
sah.slotID = selectSlotForRole(color, sah.roleID);
|
||||
@ -82,9 +79,6 @@ void HeroPoolProcessor::onHeroSurrendered(const PlayerColor & color, const CGHer
|
||||
void HeroPoolProcessor::onHeroEscaped(const PlayerColor & color, const CGHeroInstance * hero)
|
||||
{
|
||||
SetAvailableHero sah;
|
||||
if (gameHandler->turnOrder->playerAwaitsNewDay(color))
|
||||
sah.roleID = TavernSlotRole::RETREATED_TODAY;
|
||||
else
|
||||
sah.roleID = TavernSlotRole::RETREATED;
|
||||
|
||||
sah.slotID = selectSlotForRole(color, sah.roleID);
|
||||
@ -139,25 +133,9 @@ void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHe
|
||||
|
||||
void HeroPoolProcessor::onNewWeek(const PlayerColor & color)
|
||||
{
|
||||
const auto & heroesPool = gameHandler->gameState()->heroesPool;
|
||||
const auto & heroes = heroesPool->getHeroesFor(color);
|
||||
|
||||
const auto nativeSlotRole = heroes.size() < 1 ? TavernSlotRole::NONE : heroesPool->getSlotRole(heroes[0]->type->getId());
|
||||
const auto randomSlotRole = heroes.size() < 2 ? TavernSlotRole::NONE : heroesPool->getSlotRole(heroes[1]->type->getId());
|
||||
|
||||
bool resetNativeSlot = nativeSlotRole != TavernSlotRole::RETREATED_TODAY && nativeSlotRole != TavernSlotRole::SURRENDERED_TODAY;
|
||||
bool resetRandomSlot = randomSlotRole != TavernSlotRole::RETREATED_TODAY && randomSlotRole != TavernSlotRole::SURRENDERED_TODAY;
|
||||
|
||||
if (resetNativeSlot)
|
||||
clearHeroFromSlot(color, TavernHeroSlot::NATIVE);
|
||||
|
||||
if (resetRandomSlot)
|
||||
clearHeroFromSlot(color, TavernHeroSlot::RANDOM);
|
||||
|
||||
if (resetNativeSlot)
|
||||
selectNewHeroForSlot(color, TavernHeroSlot::NATIVE, true, true);
|
||||
|
||||
if (resetRandomSlot)
|
||||
selectNewHeroForSlot(color, TavernHeroSlot::RANDOM, false, true);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user