1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Moved roll for week type to NewTurnProcessor

This commit is contained in:
Ivan Savenko 2024-08-25 19:39:34 +00:00
parent 020f1d1f46
commit c09c414f5a
3 changed files with 59 additions and 56 deletions

View File

@ -651,62 +651,9 @@ void CGameHandler::onNewTurn()
if (newWeek && !firstTurn)
{
n.specialWeek = EWeekType::NORMAL;
bool deityOfFireBuilt = false;
for (const CGTownInstance *t : gs->map->towns)
{
if (t->hasBuilt(BuildingID::GRAIL, ETownType::INFERNO))
{
deityOfFireBuilt = true;
break;
}
}
if (deityOfFireBuilt)
{
n.specialWeek = EWeekType::DEITYOFFIRE;
n.creatureid = CreatureID::IMP;
}
else if(VLC->settings()->getBoolean(EGameSettings::CREATURES_ALLOW_RANDOM_SPECIAL_WEEKS))
{
int monthType = getRandomGenerator().nextInt(99);
if (newMonth) //new month
{
if (monthType < 40) //double growth
{
n.specialWeek = EWeekType::DOUBLE_GROWTH;
if (VLC->settings()->getBoolean(EGameSettings::CREATURES_ALLOW_ALL_FOR_DOUBLE_MONTH))
{
n.creatureid = VLC->creh->pickRandomMonster(getRandomGenerator());
}
else if (VLC->creh->doubledCreatures.size())
{
n.creatureid = *RandomGeneratorUtil::nextItem(VLC->creh->doubledCreatures, getRandomGenerator());
}
else
{
complain("Cannot find creature that can be spawned!");
n.specialWeek = EWeekType::NORMAL;
}
}
else if (monthType < 50)
n.specialWeek = EWeekType::PLAGUE;
}
else //it's a week, but not full month
{
if (monthType < 25)
{
n.specialWeek = EWeekType::BONUS_GROWTH; //+5
std::pair<int, CreatureID> newMonster(54, CreatureID());
do
{
newMonster.second = VLC->creh->pickRandomMonster(getRandomGenerator());
} while (VLC->creh->objects[newMonster.second] &&
(*VLC->townh)[VLC->creatures()->getById(newMonster.second)->getFaction()]->town == nullptr); // find first non neutral creature
n.creatureid = newMonster.second;
}
}
}
auto [specialWeek, creatureID] = newTurnProcessor->pickWeekType(newMonth);
n.specialWeek = specialWeek;
n.creatureid = creatureID;
}
for (auto & elem : gs->players)

View File

@ -282,3 +282,58 @@ RumorState NewTurnProcessor::pickNewRumor()
return newRumor;
}
std::tuple<EWeekType, CreatureID> NewTurnProcessor::pickWeekType(bool newMonth)
{
for (const CGTownInstance *t : gameHandler->gameState()->map->towns)
{
if (t->hasBuilt(BuildingID::GRAIL, ETownType::INFERNO))
return { EWeekType::DEITYOFFIRE, CreatureID::IMP };
}
if(!VLC->settings()->getBoolean(EGameSettings::CREATURES_ALLOW_RANDOM_SPECIAL_WEEKS))
return { EWeekType::NORMAL, CreatureID::NONE};
int monthType = gameHandler->getRandomGenerator().nextInt(99);
if (newMonth) //new month
{
if (monthType < 40) //double growth
{
if (VLC->settings()->getBoolean(EGameSettings::CREATURES_ALLOW_ALL_FOR_DOUBLE_MONTH))
{
CreatureID creatureID = VLC->creh->pickRandomMonster(gameHandler->getRandomGenerator());
return { EWeekType::DOUBLE_GROWTH, creatureID};
}
else if (VLC->creh->doubledCreatures.size())
{
CreatureID creatureID = *RandomGeneratorUtil::nextItem(VLC->creh->doubledCreatures, gameHandler->getRandomGenerator());
return { EWeekType::DOUBLE_GROWTH, creatureID};
}
else
{
gameHandler->complain("Cannot find creature that can be spawned!");
return { EWeekType::NORMAL, CreatureID::NONE};
}
}
if (monthType < 50)
return { EWeekType::PLAGUE, CreatureID::NONE};
return { EWeekType::NORMAL, CreatureID::NONE};
}
else //it's a week, but not full month
{
if (monthType < 25)
{
std::pair<int, CreatureID> newMonster(54, CreatureID());
do
{
newMonster.second = VLC->creh->pickRandomMonster(gameHandler->getRandomGenerator());
} while (VLC->creh->objects[newMonster.second] &&
(*VLC->townh)[VLC->creatures()->getById(newMonster.second)->getFaction()]->town == nullptr); // find first non neutral creature
return { EWeekType::BONUS_GROWTH, newMonster.second};
}
return { EWeekType::NORMAL, CreatureID::NONE};
}
}

View File

@ -30,6 +30,7 @@ public:
ResourceSet generatePlayerIncome(PlayerColor playerID, bool newWeek);
SetAvailableCreatures generateTownGrowth(const CGTownInstance * town, EWeekType weekType, CreatureID creatureWeek, bool firstDay);
RumorState pickNewRumor();
std::tuple<EWeekType, CreatureID> pickWeekType(bool newMonth);
void onPlayerTurnStarted(PlayerColor color);
void onPlayerTurnEnded(PlayerColor color);