Explorar el Código

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
Ivan Savenko hace 2 años
padre
commit
ee8adbe85f

+ 0 - 9
lib/gameState/TavernHeroesPool.cpp

@@ -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)

+ 1 - 5
lib/gameState/TavernSlot.h

@@ -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

+ 8 - 3
server/CGameHandler.cpp

@@ -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;

+ 6 - 28
server/processors/HeroPoolProcessor.cpp

@@ -68,10 +68,7 @@ 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.roleID = TavernSlotRole::SURRENDERED;
 
 	sah.slotID = selectSlotForRole(color, sah.roleID);
 	sah.player = color;
@@ -82,10 +79,7 @@ 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.roleID = TavernSlotRole::RETREATED;
 
 	sah.slotID = selectSlotForRole(color, sah.roleID);
 	sah.player = color;
@@ -139,26 +133,10 @@ 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);
+	clearHeroFromSlot(color, TavernHeroSlot::NATIVE);
+	clearHeroFromSlot(color, TavernHeroSlot::RANDOM);
+	selectNewHeroForSlot(color, TavernHeroSlot::NATIVE, true, true);
+	selectNewHeroForSlot(color, TavernHeroSlot::RANDOM, false, true);
 }
 
 bool HeroPoolProcessor::hireHero(const ObjectInstanceID & objectID, const HeroTypeID & heroToRecruit, const PlayerColor & player)