1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-04 00:15:53 +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:
Ivan Savenko 2023-08-24 18:53:58 +03:00
parent c171a3d6be
commit ee8adbe85f
4 changed files with 15 additions and 45 deletions

View File

@ -124,15 +124,6 @@ void TavernHeroesPool::onNewDay()
hero.second->setMovementPoints(hero.second->movementPointsLimit(true)); hero.second->setMovementPoints(hero.second->movementPointsLimit(true));
hero.second->mana = hero.second->manaLimit(); 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) void TavernHeroesPool::addHeroToPool(CGHeroInstance * hero)

View File

@ -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 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 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, // 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, // hero was owned by player before, but have surrendered in battle and kept some troops
SURRENDERED_TODAY,
}; };
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -611,6 +611,11 @@ void CGameHandler::onPlayerTurnEnded(PlayerColor which)
{ {
// 7 days without castle // 7 days without castle
checkVictoryLossConditionsForPlayer(which); 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() void CGameHandler::onNewTurn()
@ -702,13 +707,13 @@ void CGameHandler::onNewTurn()
{ {
if (elem.first == PlayerColor::NEUTRAL) if (elem.first == PlayerColor::NEUTRAL)
continue; 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]); std::pair<PlayerColor, si32> playerGold(elem.first, elem.second.resources[EGameResID::GOLD]);
hadGold.insert(playerGold); hadGold.insert(playerGold);
if (newWeek) //new heroes in tavern if (firstTurn)
heroPool->onNewWeek(elem.first); heroPool->onNewWeek(elem.first);
n.res[elem.first] = elem.second.resources; n.res[elem.first] = elem.second.resources;

View File

@ -68,9 +68,6 @@ TavernHeroSlot HeroPoolProcessor::selectSlotForRole(const PlayerColor & player,
void HeroPoolProcessor::onHeroSurrendered(const PlayerColor & color, const CGHeroInstance * hero) void HeroPoolProcessor::onHeroSurrendered(const PlayerColor & color, const CGHeroInstance * hero)
{ {
SetAvailableHero sah; SetAvailableHero sah;
if (gameHandler->turnOrder->playerAwaitsNewDay(color))
sah.roleID = TavernSlotRole::SURRENDERED_TODAY;
else
sah.roleID = TavernSlotRole::SURRENDERED; sah.roleID = TavernSlotRole::SURRENDERED;
sah.slotID = selectSlotForRole(color, sah.roleID); 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) void HeroPoolProcessor::onHeroEscaped(const PlayerColor & color, const CGHeroInstance * hero)
{ {
SetAvailableHero sah; SetAvailableHero sah;
if (gameHandler->turnOrder->playerAwaitsNewDay(color))
sah.roleID = TavernSlotRole::RETREATED_TODAY;
else
sah.roleID = TavernSlotRole::RETREATED; sah.roleID = TavernSlotRole::RETREATED;
sah.slotID = selectSlotForRole(color, sah.roleID); sah.slotID = selectSlotForRole(color, sah.roleID);
@ -139,25 +133,9 @@ void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHe
void HeroPoolProcessor::onNewWeek(const PlayerColor & color) 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); clearHeroFromSlot(color, TavernHeroSlot::NATIVE);
if (resetRandomSlot)
clearHeroFromSlot(color, TavernHeroSlot::RANDOM); clearHeroFromSlot(color, TavernHeroSlot::RANDOM);
if (resetNativeSlot)
selectNewHeroForSlot(color, TavernHeroSlot::NATIVE, true, true); selectNewHeroForSlot(color, TavernHeroSlot::NATIVE, true, true);
if (resetRandomSlot)
selectNewHeroForSlot(color, TavernHeroSlot::RANDOM, false, true); selectNewHeroForSlot(color, TavernHeroSlot::RANDOM, false, true);
} }