1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

change town events to vector + use getDefaultAllowed for spells

This commit is contained in:
godric3 2024-07-16 21:16:26 +02:00
parent c212b1bf36
commit fa3fef8a0f
5 changed files with 18 additions and 30 deletions

View File

@ -1207,22 +1207,12 @@ void CGTownInstance::serializeJsonOptions(JsonSerializeFormat & handler)
{
handler.serializeIdArray( "possibleSpells", possibleSpells);
handler.serializeIdArray( "obligatorySpells", obligatorySpells);
}
if (handler.saving)
{
auto eventsHandler = handler.enterArray("events");
std::vector<CCastleEvent> temp(events.begin(), events.end());
eventsHandler.serializeStruct(temp);
}
else
{
auto eventsHandler = handler.enterArray("events");
std::vector<CCastleEvent> temp;
eventsHandler.serializeStruct(temp);
events.clear();
events.insert(events.begin(), temp.begin(), temp.end());
}
{
auto eventsHandler = handler.enterArray("events");
eventsHandler.syncSize(events, JsonNode::JsonType::DATA_VECTOR);
eventsHandler.serializeStruct(events);
}
}

View File

@ -64,7 +64,7 @@ public:
std::vector<CGTownBuilding*> bonusingBuildings;
std::vector<SpellID> possibleSpells, obligatorySpells;
std::vector<std::vector<SpellID> > spells; //spells[level] -> vector of spells, first will be available in guild
std::list<CCastleEvent> events;
std::vector<CCastleEvent> events;
std::pair<si32, si32> bonusValue;//var to store town bonuses (rampart = resources from mystic pond);
//////////////////////////////////////////////////////////////////////////

View File

@ -561,7 +561,7 @@ struct DLL_LINKAGE UpdateMapEvents : public CPackForClient
struct DLL_LINKAGE UpdateCastleEvents : public CPackForClient
{
ObjectInstanceID town;
std::list<CCastleEvent> events;
std::vector<CCastleEvent> events;
void applyGs(CGameState * gs) const;
void visitTyped(ICPackVisitor & visitor) override;

View File

@ -50,29 +50,27 @@ void TownSpellsWidget::resetSpells()
{
town.possibleSpells.clear();
town.obligatorySpells.clear();
for (auto spell : VLC->spellh->objects)
{
if (!spell->isSpecial() && !spell->isCreatureAbility())
town.possibleSpells.push_back(spell->id);
}
for (auto spellID : VLC->spellh->getDefaultAllowed())
town.possibleSpells.push_back(spellID);
}
void TownSpellsWidget::initSpellLists()
{
QListWidget * possibleSpellLists[] = { ui->possibleSpellList1, ui->possibleSpellList2, ui->possibleSpellList3, ui->possibleSpellList4, ui->possibleSpellList5 };
QListWidget * requiredSpellLists[] = { ui->requiredSpellList1, ui->requiredSpellList2, ui->requiredSpellList3, ui->requiredSpellList4, ui->requiredSpellList5 };
auto spells = VLC->spellh->objects;
auto spells = VLC->spellh->getDefaultAllowed();
for (int i = 0; i < GameConstants::SPELL_LEVELS; i++)
{
std::vector<std::shared_ptr<CSpell>> spellsByLevel;
auto getSpellsByLevel = [i](auto spell) {
return spell->getLevel() == i + 1 && !spell->isSpecial() && !spell->isCreatureAbility();
std::vector<SpellID> spellsByLevel;
auto getSpellsByLevel = [i](auto spellID) {
return spellID.toEntity(VLC)->getLevel() == i + 1;
};
vstd::copy_if(spells, std::back_inserter(spellsByLevel), getSpellsByLevel);
possibleSpellLists[i]->clear();
requiredSpellLists[i]->clear();
for (auto spell : spellsByLevel)
for (auto spellID : spellsByLevel)
{
auto spell = spellID.toEntity(VLC);
auto * possibleItem = new QListWidgetItem(QString::fromStdString(spell->getNameTranslated()));
possibleItem->setData(Qt::UserRole, QVariant::fromValue(spell->getIndex()));
possibleItem->setFlags(possibleItem->flags() | Qt::ItemIsUserCheckable);

View File

@ -3413,7 +3413,7 @@ void CGameHandler::handleTimeEvents()
void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n)
{
town->events.sort(evntCmp);
std::sort(town->events.begin(), town->events.end(), evntCmp);
while(town->events.size() && town->events.front().firstOccurrence == gs->day)
{
PlayerColor player = town->tempOwner;
@ -3474,7 +3474,7 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n)
if (ev.nextOccurrence)
{
town->events.pop_front();
town->events.erase(town->events.begin());
ev.firstOccurrence += ev.nextOccurrence;
auto it = town->events.begin();
@ -3484,7 +3484,7 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n)
}
else
{
town->events.pop_front();
town->events.erase(town->events.begin());
}
}