Przeglądaj źródła

adjust town event handling after introducing 8th creature in town

godric3 1 rok temu
rodzic
commit
8917c753bd

+ 7 - 2
mapeditor/inspector/towneventdialog.cpp

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

+ 1 - 1
server/processors/NewTurnProcessor.cpp

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