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

adjust town event handling after introducing 8th creature in town

This commit is contained in:
godric3 2024-09-16 20:16:27 +02:00
parent 7209969d9d
commit 8917c753bd
2 changed files with 8 additions and 3 deletions

View File

@ -155,7 +155,12 @@ void TownEventDialog::initCreatures()
{
auto creatures = params.value("creatures").toList();
auto * ctown = town.town;
for (int i = 0; i < GameConstants::CREATURES_PER_TOWN; ++i)
if (!ctown)
ui->creaturesTable->setRowCount(GameConstants::CREATURES_PER_TOWN);
else
ui->creaturesTable->setRowCount(ctown->creatures.size());
for (int i = 0; i < ui->creaturesTable->rowCount(); ++i)
{
QString creatureNames;
if (!ctown)
@ -239,7 +244,7 @@ QVariantList TownEventDialog::buildingsToVariant()
QVariantList TownEventDialog::creaturesToVariant()
{
QVariantList creaturesList;
for (int i = 0; i < GameConstants::CREATURES_PER_TOWN; ++i)
for (int i = 0; i < ui->creaturesTable->rowCount(); ++i)
{
auto * item = static_cast<QSpinBox *>(ui->creaturesTable->cellWidget(i, 1));
creaturesList.push_back(item->value());

View File

@ -110,7 +110,7 @@ void NewTurnProcessor::handleTownEvents(const CGTownInstance * town)
for (si32 i=0;i<event.creatures.size();i++) //creature growths
{
if (!town->creatures.at(i).second.empty() && event.creatures.at(i) > 0)//there is dwelling
if (i < town->creatures.size() && !town->creatures.at(i).second.empty() && event.creatures.at(i) > 0)//there is dwelling
{
sac.creatures[i].first += event.creatures.at(i);
iw.components.emplace_back(ComponentType::CREATURE, town->creatures.at(i).second.back(), event.creatures.at(i));