mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Moved NewTurn pack generation to NewTurnProcessor
This commit is contained in:
parent
10a9d777c7
commit
ce1e0b8875
@ -207,7 +207,7 @@ public:
|
|||||||
void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override {};
|
void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override {};
|
||||||
|
|
||||||
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) override {}
|
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) override {}
|
||||||
void changeFogOfWar(std::unordered_set<int3> & tiles, PlayerColor player, ETileVisibility mode) override {}
|
void changeFogOfWar(const std::unordered_set<int3> & tiles, PlayerColor player, ETileVisibility mode) override {}
|
||||||
|
|
||||||
void setObjPropertyValue(ObjectInstanceID objid, ObjProperty prop, int32_t value) override {};
|
void setObjPropertyValue(ObjectInstanceID objid, ObjProperty prop, int32_t value) override {};
|
||||||
void setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, ObjPropertyID identifier) override {};
|
void setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, ObjPropertyID identifier) override {};
|
||||||
|
@ -361,6 +361,14 @@ void ApplyClientNetPackVisitor::visitHeroVisit(HeroVisit & pack)
|
|||||||
void ApplyClientNetPackVisitor::visitNewTurn(NewTurn & pack)
|
void ApplyClientNetPackVisitor::visitNewTurn(NewTurn & pack)
|
||||||
{
|
{
|
||||||
cl.invalidatePaths();
|
cl.invalidatePaths();
|
||||||
|
|
||||||
|
if (pack.newWeekNotification)
|
||||||
|
{
|
||||||
|
const auto & newWeek = *pack.newWeekNotification;
|
||||||
|
|
||||||
|
std::string str = newWeek.text.toString();
|
||||||
|
callAllInterfaces(cl, &CGameInterface::showInfoDialog, newWeek.type, str, newWeek.components,(soundBase::soundID)newWeek.soundID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyClientNetPackVisitor::visitGiveBonus(GiveBonus & pack)
|
void ApplyClientNetPackVisitor::visitGiveBonus(GiveBonus & pack)
|
||||||
|
@ -140,7 +140,7 @@ public:
|
|||||||
virtual void sendAndApply(CPackForClient * pack) = 0;
|
virtual void sendAndApply(CPackForClient * pack) = 0;
|
||||||
virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
|
virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
|
||||||
virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) = 0;
|
virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) = 0;
|
||||||
virtual void changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor player, ETileVisibility mode) = 0;
|
virtual void changeFogOfWar(const std::unordered_set<int3> &tiles, PlayerColor player, ETileVisibility mode) = 0;
|
||||||
|
|
||||||
virtual void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) = 0;
|
virtual void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) = 0;
|
||||||
|
|
||||||
|
@ -1127,6 +1127,27 @@ struct DLL_LINKAGE HeroVisit : public CPackForClient
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
|
||||||
|
{
|
||||||
|
EInfoWindowMode type = EInfoWindowMode::MODAL;
|
||||||
|
MetaString text;
|
||||||
|
std::vector<Component> components;
|
||||||
|
PlayerColor player;
|
||||||
|
ui16 soundID = 0;
|
||||||
|
|
||||||
|
void visitTyped(ICPackVisitor & visitor) override;
|
||||||
|
|
||||||
|
template <typename Handler> void serialize(Handler & h)
|
||||||
|
{
|
||||||
|
h & type;
|
||||||
|
h & text;
|
||||||
|
h & components;
|
||||||
|
h & player;
|
||||||
|
h & soundID;
|
||||||
|
}
|
||||||
|
InfoWindow() = default;
|
||||||
|
};
|
||||||
|
|
||||||
struct DLL_LINKAGE NewTurn : public CPackForClient
|
struct DLL_LINKAGE NewTurn : public CPackForClient
|
||||||
{
|
{
|
||||||
void applyGs(CGameState * gs) override;
|
void applyGs(CGameState * gs) override;
|
||||||
@ -1142,6 +1163,7 @@ struct DLL_LINKAGE NewTurn : public CPackForClient
|
|||||||
std::vector<SetAvailableCreatures> availableCreatures;
|
std::vector<SetAvailableCreatures> availableCreatures;
|
||||||
std::map<PlayerColor, ResourceSet> playerIncome;
|
std::map<PlayerColor, ResourceSet> playerIncome;
|
||||||
std::optional<RumorState> newRumor; // only on new weeks
|
std::optional<RumorState> newRumor; // only on new weeks
|
||||||
|
std::optional<InfoWindow> newWeekNotification; // only on new week
|
||||||
|
|
||||||
NewTurn() = default;
|
NewTurn() = default;
|
||||||
|
|
||||||
@ -1155,31 +1177,11 @@ struct DLL_LINKAGE NewTurn : public CPackForClient
|
|||||||
h & availableCreatures;
|
h & availableCreatures;
|
||||||
h & playerIncome;
|
h & playerIncome;
|
||||||
h & newRumor;
|
h & newRumor;
|
||||||
|
h & newWeekNotification;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
|
|
||||||
{
|
|
||||||
EInfoWindowMode type = EInfoWindowMode::MODAL;
|
|
||||||
MetaString text;
|
|
||||||
std::vector<Component> components;
|
|
||||||
PlayerColor player;
|
|
||||||
ui16 soundID = 0;
|
|
||||||
|
|
||||||
void visitTyped(ICPackVisitor & visitor) override;
|
|
||||||
void applyGs(CGameState * gs) override {}
|
void applyGs(CGameState * gs) override {}
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler & h)
|
|
||||||
{
|
|
||||||
h & type;
|
|
||||||
h & text;
|
|
||||||
h & components;
|
|
||||||
h & player;
|
|
||||||
h & soundID;
|
|
||||||
}
|
|
||||||
InfoWindow() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DLL_LINKAGE SetObjectProperty : public CPackForClient
|
struct DLL_LINKAGE SetObjectProperty : public CPackForClient
|
||||||
{
|
{
|
||||||
void applyGs(CGameState * gs) override;
|
void applyGs(CGameState * gs) override;
|
||||||
|
@ -608,13 +608,8 @@ void CGameHandler::addStatistics(StatisticDataSet &stat) const
|
|||||||
void CGameHandler::onNewTurn()
|
void CGameHandler::onNewTurn()
|
||||||
{
|
{
|
||||||
logGlobal->trace("Turn %d", gs->day+1);
|
logGlobal->trace("Turn %d", gs->day+1);
|
||||||
NewTurn n;
|
|
||||||
n.specialWeek = EWeekType::FIRST_WEEK;
|
|
||||||
n.creatureid = CreatureID::NONE;
|
|
||||||
n.day = gs->day + 1;
|
|
||||||
|
|
||||||
bool firstTurn = !getDate(Date::DAY);
|
bool firstTurn = !getDate(Date::DAY);
|
||||||
bool newWeek = getDate(Date::DAY_OF_WEEK) == 7; //day numbers are confusing, as day was not yet switched
|
|
||||||
bool newMonth = getDate(Date::DAY_OF_MONTH) == 28;
|
bool newMonth = getDate(Date::DAY_OF_MONTH) == 28;
|
||||||
|
|
||||||
if (firstTurn)
|
if (firstTurn)
|
||||||
@ -626,53 +621,16 @@ void CGameHandler::onNewTurn()
|
|||||||
giveExperience(getHero(obj->id), 0);
|
giveExperience(getHero(obj->id), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto & elem : gs->players)
|
||||||
|
heroPool->onNewWeek(elem.first);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
addStatistics(gameState()->statistic); // write at end of turn
|
addStatistics(gameState()->statistic); // write at end of turn
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto & player : gs->players)
|
|
||||||
{
|
|
||||||
if (player.second.status != EPlayerStatus::INGAME)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (player.second.getHeroes().empty() && player.second.getTowns().empty())
|
|
||||||
throw std::runtime_error("Invalid player in player state! Player " + std::to_string(player.first.getNum()) + ", map name: " + gs->map->name.toString() + ", map description: " + gs->map->description.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!firstTurn)
|
|
||||||
{
|
|
||||||
for (const auto & player : gs->players)
|
|
||||||
n.playerIncome[player.first] = newTurnProcessor->generatePlayerIncome(player.first, newWeek);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newWeek && !firstTurn)
|
|
||||||
{
|
|
||||||
auto [specialWeek, creatureID] = newTurnProcessor->pickWeekType(newMonth);
|
|
||||||
n.specialWeek = specialWeek;
|
|
||||||
n.creatureid = creatureID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstTurn)
|
|
||||||
{
|
|
||||||
for (auto & elem : gs->players)
|
|
||||||
heroPool->onNewWeek(elem.first);
|
|
||||||
}
|
|
||||||
|
|
||||||
n.heroesMana = newTurnProcessor->updateHeroesManaPoints();
|
|
||||||
n.heroesMovement = newTurnProcessor->updateHeroesMovementPoints();
|
|
||||||
|
|
||||||
if (newWeek)
|
|
||||||
{
|
|
||||||
for (CGTownInstance *t : gs->map->towns)
|
|
||||||
if (t->hasBuilt(BuildingSubID::PORTAL_OF_SUMMONING))
|
|
||||||
setPortalDwelling(t, true, (n.specialWeek == EWeekType::PLAGUE ? true : false)); //set creatures for Portal of Summoning
|
|
||||||
|
|
||||||
for (CGTownInstance *t : gs->map->towns)
|
|
||||||
n.availableCreatures.push_back(newTurnProcessor->generateTownGrowth(t, n.specialWeek, n.creatureid, firstTurn));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CGTownInstance *t : gs->map->towns)
|
for (CGTownInstance *t : gs->map->towns)
|
||||||
{
|
{
|
||||||
PlayerColor player = t->tempOwner;
|
PlayerColor player = t->tempOwner;
|
||||||
@ -681,25 +639,27 @@ void CGameHandler::onNewTurn()
|
|||||||
&& t->town->buildings.at(BuildingID::GRAIL)->height == CBuilding::HEIGHT_SKYSHIP)
|
&& t->town->buildings.at(BuildingID::GRAIL)->height == CBuilding::HEIGHT_SKYSHIP)
|
||||||
{
|
{
|
||||||
// Skyship, probably easier to handle same as Veil of darkness
|
// Skyship, probably easier to handle same as Veil of darkness
|
||||||
//do it every new day after veils apply
|
// do it every new day before veils
|
||||||
if (player != PlayerColor::NEUTRAL) //do not reveal fow for neutral player
|
if (player.isValidPlayer())
|
||||||
{
|
{
|
||||||
FoWChange fw;
|
std::unordered_set<int3> revealedTiles;
|
||||||
fw.mode = ETileVisibility::REVEALED;
|
|
||||||
fw.player = player;
|
|
||||||
// find all hidden tiles
|
// find all hidden tiles
|
||||||
const auto & fow = getPlayerTeam(player)->fogOfWarMap;
|
const auto & fow = getPlayerTeam(player)->fogOfWarMap;
|
||||||
|
|
||||||
auto shape = fow.shape();
|
auto shape = fow.shape();
|
||||||
for(size_t z = 0; z < shape[0]; z++)
|
for(size_t z = 0; z < shape[0]; z++)
|
||||||
for(size_t x = 0; x < shape[1]; x++)
|
for(size_t x = 0; x < shape[1]; x++)
|
||||||
for(size_t y = 0; y < shape[2]; y++)
|
for(size_t y = 0; y < shape[2]; y++)
|
||||||
if (!fow[z][x][y])
|
if (!fow[z][x][y])
|
||||||
fw.tiles.insert(int3(x, y, z));
|
revealedTiles.insert(int3(x, y, z));
|
||||||
|
|
||||||
sendAndApply (&fw);
|
changeFogOfWar(revealedTiles, player, ETileVisibility::REVEALED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CGTownInstance *t : gs->map->towns)
|
||||||
|
{
|
||||||
if (t->hasBonusOfType (BonusType::DARKNESS))
|
if (t->hasBonusOfType (BonusType::DARKNESS))
|
||||||
{
|
{
|
||||||
for (auto & player : gs->players)
|
for (auto & player : gs->players)
|
||||||
@ -711,9 +671,6 @@ void CGameHandler::onNewTurn()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newWeek)
|
|
||||||
n.newRumor = newTurnProcessor->pickNewRumor();
|
|
||||||
|
|
||||||
if (newMonth)
|
if (newMonth)
|
||||||
{
|
{
|
||||||
SetAvailableArtifacts saa;
|
SetAvailableArtifacts saa;
|
||||||
@ -721,67 +678,12 @@ void CGameHandler::onNewTurn()
|
|||||||
pickAllowedArtsSet(saa.arts, getRandomGenerator());
|
pickAllowedArtsSet(saa.arts, getRandomGenerator());
|
||||||
sendAndApply(&saa);
|
sendAndApply(&saa);
|
||||||
}
|
}
|
||||||
sendAndApply(&n);
|
|
||||||
|
|
||||||
if (newWeek)
|
newTurnProcessor->onNewTurn();
|
||||||
{
|
|
||||||
//spawn wandering monsters
|
|
||||||
if (newMonth && (n.specialWeek == EWeekType::DOUBLE_GROWTH || n.specialWeek == EWeekType::DEITYOFFIRE))
|
|
||||||
{
|
|
||||||
spawnWanderingMonsters(n.creatureid);
|
|
||||||
}
|
|
||||||
|
|
||||||
//new week info popup
|
|
||||||
if (!firstTurn)
|
|
||||||
{
|
|
||||||
InfoWindow iw;
|
|
||||||
switch (n.specialWeek)
|
|
||||||
{
|
|
||||||
case EWeekType::DOUBLE_GROWTH:
|
|
||||||
iw.text.appendLocalString(EMetaText::ARRAY_TXT, 131);
|
|
||||||
iw.text.replaceNameSingular(n.creatureid);
|
|
||||||
iw.text.replaceNameSingular(n.creatureid);
|
|
||||||
break;
|
|
||||||
case EWeekType::PLAGUE:
|
|
||||||
iw.text.appendLocalString(EMetaText::ARRAY_TXT, 132);
|
|
||||||
break;
|
|
||||||
case EWeekType::BONUS_GROWTH:
|
|
||||||
iw.text.appendLocalString(EMetaText::ARRAY_TXT, 134);
|
|
||||||
iw.text.replaceNameSingular(n.creatureid);
|
|
||||||
iw.text.replaceNameSingular(n.creatureid);
|
|
||||||
break;
|
|
||||||
case EWeekType::DEITYOFFIRE:
|
|
||||||
iw.text.appendLocalString(EMetaText::ARRAY_TXT, 135);
|
|
||||||
iw.text.replaceNameSingular(CreatureID::IMP); //%s imp
|
|
||||||
iw.text.replaceNameSingular(CreatureID::IMP); //%s imp
|
|
||||||
iw.text.replacePositiveNumber(15);//%+d 15
|
|
||||||
iw.text.replaceNameSingular(CreatureID::FAMILIAR); //%s familiar
|
|
||||||
iw.text.replacePositiveNumber(15);//%+d 15
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (newMonth)
|
|
||||||
{
|
|
||||||
iw.text.appendLocalString(EMetaText::ARRAY_TXT, (130));
|
|
||||||
iw.text.replaceLocalString(EMetaText::ARRAY_TXT, getRandomGenerator().nextInt(32, 41));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iw.text.appendLocalString(EMetaText::ARRAY_TXT, (133));
|
|
||||||
iw.text.replaceLocalString(EMetaText::ARRAY_TXT, getRandomGenerator().nextInt(43, 57));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto & elem : gs->players)
|
|
||||||
{
|
|
||||||
iw.player = elem.first;
|
|
||||||
sendAndApply(&iw);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!firstTurn)
|
if (!firstTurn)
|
||||||
checkVictoryLossConditionsForAll(); // check for map turn limit
|
checkVictoryLossConditionsForAll(); // check for map turn limit
|
||||||
|
|
||||||
logGlobal->trace("Info about turn %d has been sent!", n.day);
|
|
||||||
//call objects
|
//call objects
|
||||||
for (auto & elem : gs->map->objects)
|
for (auto & elem : gs->map->objects)
|
||||||
{
|
{
|
||||||
@ -4045,19 +3947,6 @@ void CGameHandler::changeFogOfWar(int3 center, ui32 radius, PlayerColor player,
|
|||||||
if (mode == ETileVisibility::HIDDEN)
|
if (mode == ETileVisibility::HIDDEN)
|
||||||
{
|
{
|
||||||
getTilesInRange(tiles, center, radius, ETileVisibility::REVEALED, player);
|
getTilesInRange(tiles, center, radius, ETileVisibility::REVEALED, player);
|
||||||
|
|
||||||
std::unordered_set<int3> observedTiles; //do not hide tiles observed by heroes. May lead to disastrous AI problems
|
|
||||||
auto p = getPlayerState(player);
|
|
||||||
for (auto h : p->getHeroes())
|
|
||||||
{
|
|
||||||
getTilesInRange(observedTiles, h->getSightCenter(), h->getSightRadius(), ETileVisibility::REVEALED, h->tempOwner);
|
|
||||||
}
|
|
||||||
for (auto t : p->getTowns())
|
|
||||||
{
|
|
||||||
getTilesInRange(observedTiles, t->getSightCenter(), t->getSightRadius(), ETileVisibility::REVEALED, t->tempOwner);
|
|
||||||
}
|
|
||||||
for (auto tile : observedTiles)
|
|
||||||
vstd::erase_if_present (tiles, tile);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -4066,7 +3955,7 @@ void CGameHandler::changeFogOfWar(int3 center, ui32 radius, PlayerColor player,
|
|||||||
changeFogOfWar(tiles, player, mode);
|
changeFogOfWar(tiles, player, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameHandler::changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor player, ETileVisibility mode)
|
void CGameHandler::changeFogOfWar(const std::unordered_set<int3> &tiles, PlayerColor player, ETileVisibility mode)
|
||||||
{
|
{
|
||||||
if (tiles.empty())
|
if (tiles.empty())
|
||||||
return;
|
return;
|
||||||
@ -4075,6 +3964,22 @@ void CGameHandler::changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor p
|
|||||||
fow.tiles = tiles;
|
fow.tiles = tiles;
|
||||||
fow.player = player;
|
fow.player = player;
|
||||||
fow.mode = mode;
|
fow.mode = mode;
|
||||||
|
|
||||||
|
if (mode == ETileVisibility::HIDDEN)
|
||||||
|
{
|
||||||
|
//do not hide tiles observed by owned objects. May lead to disastrous AI problems
|
||||||
|
std::unordered_set<int3> observedTiles;
|
||||||
|
auto p = getPlayerState(player);
|
||||||
|
for (auto obj : p->getOwnedObjects())
|
||||||
|
getTilesInRange(observedTiles, obj->getSightCenter(), obj->getSightRadius(), ETileVisibility::REVEALED, obj->getOwner());
|
||||||
|
|
||||||
|
for (auto tile : observedTiles)
|
||||||
|
vstd::erase_if_present (fow.tiles, tile);
|
||||||
|
|
||||||
|
if (fow.tiles.empty())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sendAndApply(&fow);
|
sendAndApply(&fow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ public:
|
|||||||
void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override;
|
void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override;
|
||||||
|
|
||||||
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) override;
|
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) override;
|
||||||
void changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor player,ETileVisibility mode) override;
|
void changeFogOfWar(const std::unordered_set<int3> &tiles, PlayerColor player,ETileVisibility mode) override;
|
||||||
|
|
||||||
void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override;
|
void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override;
|
||||||
|
|
||||||
|
@ -352,7 +352,6 @@ std::vector<SetMana> NewTurnProcessor::updateHeroesManaPoints()
|
|||||||
result.emplace_back(h->id, newMana, true);
|
result.emplace_back(h->id, newMana, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,6 +371,117 @@ std::vector<SetMovePoints> NewTurnProcessor::updateHeroesMovementPoints()
|
|||||||
result.emplace_back(h->id, newMovementPoints, true);
|
result.emplace_back(h->id, newMovementPoints, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InfoWindow NewTurnProcessor::createInfoWindow(EWeekType weekType, CreatureID creatureWeek, bool newMonth)
|
||||||
|
{
|
||||||
|
InfoWindow iw;
|
||||||
|
switch (weekType)
|
||||||
|
{
|
||||||
|
case EWeekType::DOUBLE_GROWTH:
|
||||||
|
iw.text.appendLocalString(EMetaText::ARRAY_TXT, 131);
|
||||||
|
iw.text.replaceNameSingular(creatureWeek);
|
||||||
|
iw.text.replaceNameSingular(creatureWeek);
|
||||||
|
break;
|
||||||
|
case EWeekType::PLAGUE:
|
||||||
|
iw.text.appendLocalString(EMetaText::ARRAY_TXT, 132);
|
||||||
|
break;
|
||||||
|
case EWeekType::BONUS_GROWTH:
|
||||||
|
iw.text.appendLocalString(EMetaText::ARRAY_TXT, 134);
|
||||||
|
iw.text.replaceNameSingular(creatureWeek);
|
||||||
|
iw.text.replaceNameSingular(creatureWeek);
|
||||||
|
break;
|
||||||
|
case EWeekType::DEITYOFFIRE:
|
||||||
|
iw.text.appendLocalString(EMetaText::ARRAY_TXT, 135);
|
||||||
|
iw.text.replaceNameSingular(CreatureID::IMP); //%s imp
|
||||||
|
iw.text.replaceNameSingular(CreatureID::IMP); //%s imp
|
||||||
|
iw.text.replacePositiveNumber(15);//%+d 15
|
||||||
|
iw.text.replaceNameSingular(CreatureID::FAMILIAR); //%s familiar
|
||||||
|
iw.text.replacePositiveNumber(15);//%+d 15
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (newMonth)
|
||||||
|
{
|
||||||
|
iw.text.appendLocalString(EMetaText::ARRAY_TXT, (130));
|
||||||
|
iw.text.replaceLocalString(EMetaText::ARRAY_TXT, gameHandler->getRandomGenerator().nextInt(32, 41));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iw.text.appendLocalString(EMetaText::ARRAY_TXT, (133));
|
||||||
|
iw.text.replaceLocalString(EMetaText::ARRAY_TXT, gameHandler->getRandomGenerator().nextInt(43, 57));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return iw;
|
||||||
|
}
|
||||||
|
|
||||||
|
NewTurn NewTurnProcessor::generateNewTurnPack()
|
||||||
|
{
|
||||||
|
NewTurn n;
|
||||||
|
n.specialWeek = EWeekType::FIRST_WEEK;
|
||||||
|
n.creatureid = CreatureID::NONE;
|
||||||
|
n.day = gameHandler->gameState()->day + 1;
|
||||||
|
|
||||||
|
bool firstTurn = !gameHandler->getDate(Date::DAY);
|
||||||
|
bool newWeek = gameHandler->getDate(Date::DAY_OF_WEEK) == 7; //day numbers are confusing, as day was not yet switched
|
||||||
|
bool newMonth = gameHandler->getDate(Date::DAY_OF_MONTH) == 28;
|
||||||
|
|
||||||
|
if (!firstTurn)
|
||||||
|
{
|
||||||
|
for (const auto & player : gameHandler->gameState()->players)
|
||||||
|
n.playerIncome[player.first] = generatePlayerIncome(player.first, newWeek);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newWeek && !firstTurn)
|
||||||
|
{
|
||||||
|
auto [specialWeek, creatureID] = pickWeekType(newMonth);
|
||||||
|
n.specialWeek = specialWeek;
|
||||||
|
n.creatureid = creatureID;
|
||||||
|
}
|
||||||
|
|
||||||
|
n.heroesMana = updateHeroesManaPoints();
|
||||||
|
n.heroesMovement = updateHeroesMovementPoints();
|
||||||
|
|
||||||
|
if (newWeek)
|
||||||
|
{
|
||||||
|
for (CGTownInstance *t : gameHandler->gameState()->map->towns)
|
||||||
|
n.availableCreatures.push_back(generateTownGrowth(t, n.specialWeek, n.creatureid, firstTurn));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newWeek)
|
||||||
|
n.newRumor = pickNewRumor();
|
||||||
|
|
||||||
|
if (newWeek)
|
||||||
|
{
|
||||||
|
//new week info popup
|
||||||
|
if (n.specialWeek != EWeekType::FIRST_WEEK)
|
||||||
|
n.newWeekNotification = createInfoWindow(n.specialWeek, n.creatureid, newMonth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NewTurnProcessor::onNewTurn()
|
||||||
|
{
|
||||||
|
NewTurn n = generateNewTurnPack();
|
||||||
|
|
||||||
|
bool newWeek = gameHandler->getDate(Date::DAY_OF_WEEK) == 7; //day numbers are confusing, as day was not yet switched
|
||||||
|
bool newMonth = gameHandler->getDate(Date::DAY_OF_MONTH) == 28;
|
||||||
|
|
||||||
|
gameHandler->sendAndApply(&n);
|
||||||
|
|
||||||
|
if (newWeek)
|
||||||
|
{
|
||||||
|
for (CGTownInstance *t : gameHandler->gameState()->map->towns)
|
||||||
|
if (t->hasBuilt(BuildingSubID::PORTAL_OF_SUMMONING))
|
||||||
|
gameHandler->setPortalDwelling(t, true, (n.specialWeek == EWeekType::PLAGUE ? true : false)); //set creatures for Portal of Summoning
|
||||||
|
}
|
||||||
|
|
||||||
|
//spawn wandering monsters
|
||||||
|
if (newMonth && (n.specialWeek == EWeekType::DOUBLE_GROWTH || n.specialWeek == EWeekType::DEITYOFFIRE))
|
||||||
|
{
|
||||||
|
gameHandler->spawnWanderingMonsters(n.creatureid);
|
||||||
|
}
|
||||||
|
|
||||||
|
logGlobal->trace("Info about turn %d has been sent!", n.day);
|
||||||
|
}
|
||||||
|
@ -19,6 +19,8 @@ class ResourceSet;
|
|||||||
struct SetAvailableCreatures;
|
struct SetAvailableCreatures;
|
||||||
struct SetMovePoints;
|
struct SetMovePoints;
|
||||||
struct SetMana;
|
struct SetMana;
|
||||||
|
struct InfoWindow;
|
||||||
|
struct NewTurn;
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
class CGameHandler;
|
class CGameHandler;
|
||||||
@ -26,8 +28,6 @@ class CGameHandler;
|
|||||||
class NewTurnProcessor : boost::noncopyable
|
class NewTurnProcessor : boost::noncopyable
|
||||||
{
|
{
|
||||||
CGameHandler * gameHandler;
|
CGameHandler * gameHandler;
|
||||||
public:
|
|
||||||
NewTurnProcessor(CGameHandler * gameHandler);
|
|
||||||
|
|
||||||
std::vector<SetMana> updateHeroesManaPoints();
|
std::vector<SetMana> updateHeroesManaPoints();
|
||||||
std::vector<SetMovePoints> updateHeroesMovementPoints();
|
std::vector<SetMovePoints> updateHeroesMovementPoints();
|
||||||
@ -35,8 +35,15 @@ public:
|
|||||||
ResourceSet generatePlayerIncome(PlayerColor playerID, bool newWeek);
|
ResourceSet generatePlayerIncome(PlayerColor playerID, bool newWeek);
|
||||||
SetAvailableCreatures generateTownGrowth(const CGTownInstance * town, EWeekType weekType, CreatureID creatureWeek, bool firstDay);
|
SetAvailableCreatures generateTownGrowth(const CGTownInstance * town, EWeekType weekType, CreatureID creatureWeek, bool firstDay);
|
||||||
RumorState pickNewRumor();
|
RumorState pickNewRumor();
|
||||||
|
InfoWindow createInfoWindow(EWeekType weekType, CreatureID creatureWeek, bool newMonth);
|
||||||
std::tuple<EWeekType, CreatureID> pickWeekType(bool newMonth);
|
std::tuple<EWeekType, CreatureID> pickWeekType(bool newMonth);
|
||||||
|
|
||||||
|
NewTurn generateNewTurnPack();
|
||||||
|
|
||||||
|
public:
|
||||||
|
NewTurnProcessor(CGameHandler * gameHandler);
|
||||||
|
|
||||||
|
void onNewTurn();
|
||||||
void onPlayerTurnStarted(PlayerColor color);
|
void onPlayerTurnStarted(PlayerColor color);
|
||||||
void onPlayerTurnEnded(PlayerColor color);
|
void onPlayerTurnEnded(PlayerColor color);
|
||||||
};
|
};
|
||||||
|
@ -91,7 +91,7 @@ public:
|
|||||||
void changeObjPos(ObjectInstanceID objid, int3 newPos, const PlayerColor & initiator) override {}
|
void changeObjPos(ObjectInstanceID objid, int3 newPos, const PlayerColor & initiator) override {}
|
||||||
void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override {} //when two heroes meet on adventure map
|
void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override {} //when two heroes meet on adventure map
|
||||||
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) override {}
|
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) override {}
|
||||||
void changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor player, ETileVisibility mode) override {}
|
void changeFogOfWar(const std::unordered_set<int3> &tiles, PlayerColor player, ETileVisibility mode) override {}
|
||||||
void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override {}
|
void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override {}
|
||||||
|
|
||||||
///useful callback methods
|
///useful callback methods
|
||||||
|
Loading…
Reference in New Issue
Block a user