mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-07 14:02:48 +07:00
Fix errors when starting games as Maya (#11001)
* Split FreeGreatPerson and MayanGainGreatPerson * Add null check to mayan great person * Move to NextTurnAutomation to be easier to edit * Move code fromUniqueTriggerActivation to GreatPersonManager * Remove unnecessary civInfo.greatPeople
This commit is contained in:
parent
5f102b4159
commit
780c4744cc
@ -310,6 +310,37 @@ object NextTurnAutomation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun chooseGreatPerson(civInfo: Civilization) {
|
||||||
|
if (civInfo.greatPeople.freeGreatPeople == 0) return
|
||||||
|
val mayanGreatPerson = civInfo.greatPeople.mayaLimitedFreeGP > 0
|
||||||
|
val greatPeople =
|
||||||
|
if (mayanGreatPerson)
|
||||||
|
civInfo.greatPeople.getGreatPeople().filter { it.name in civInfo.greatPeople.longCountGPPool }
|
||||||
|
else civInfo.greatPeople.getGreatPeople()
|
||||||
|
|
||||||
|
if (greatPeople.isEmpty()) return
|
||||||
|
var greatPerson = greatPeople.random()
|
||||||
|
|
||||||
|
if (civInfo.wantsToFocusOn(Victory.Focus.Culture)) {
|
||||||
|
val culturalGP =
|
||||||
|
greatPeople.firstOrNull { it.uniques.contains("Great Person - [Culture]") }
|
||||||
|
if (culturalGP != null) greatPerson = culturalGP
|
||||||
|
}
|
||||||
|
if (civInfo.wantsToFocusOn(Victory.Focus.Science)) {
|
||||||
|
val scientificGP =
|
||||||
|
greatPeople.firstOrNull { it.uniques.contains("Great Person - [Science]") }
|
||||||
|
if (scientificGP != null) greatPerson = scientificGP
|
||||||
|
}
|
||||||
|
|
||||||
|
civInfo.units.addUnit(greatPerson, civInfo.cities.firstOrNull { it.isCapital() })
|
||||||
|
|
||||||
|
civInfo.greatPeople.freeGreatPeople--
|
||||||
|
if (mayanGreatPerson){
|
||||||
|
civInfo.greatPeople.longCountGPPool.remove(greatPerson.name)
|
||||||
|
civInfo.greatPeople.mayaLimitedFreeGP--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** If we are able to build a spaceship but have already spent our resources, try disbanding
|
/** If we are able to build a spaceship but have already spent our resources, try disbanding
|
||||||
* a unit and selling a building to make room. Can happen due to trades etc */
|
* a unit and selling a building to make room. Can happen due to trades etc */
|
||||||
private fun freeUpSpaceResources(civInfo: Civilization) {
|
private fun freeUpSpaceResources(civInfo: Civilization) {
|
||||||
|
@ -2,9 +2,12 @@ package com.unciv.logic.civilization.managers
|
|||||||
|
|
||||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||||
import com.unciv.logic.civilization.Civilization
|
import com.unciv.logic.civilization.Civilization
|
||||||
|
import com.unciv.logic.civilization.MayaLongCountAction
|
||||||
|
import com.unciv.logic.civilization.NotificationCategory
|
||||||
import com.unciv.models.Counter
|
import com.unciv.models.Counter
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
import com.unciv.models.ruleset.unit.BaseUnit
|
import com.unciv.models.ruleset.unit.BaseUnit
|
||||||
|
import com.unciv.ui.components.MayaCalendar
|
||||||
|
|
||||||
|
|
||||||
// todo: Great Admiral?
|
// todo: Great Admiral?
|
||||||
@ -85,6 +88,19 @@ class GreatPersonManager : IsPartOfGameInfoSerialization {
|
|||||||
greatPersonPointsCounter.add(getGreatPersonPointsForNextTurn())
|
greatPersonPointsCounter.add(getGreatPersonPointsForNextTurn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun triggerMayanGreatPerson() {
|
||||||
|
if (civInfo.isSpectator()) return
|
||||||
|
val greatPeople = getGreatPeople()
|
||||||
|
if (longCountGPPool.isEmpty())
|
||||||
|
longCountGPPool = greatPeople.map { it.name }.toHashSet()
|
||||||
|
|
||||||
|
freeGreatPeople++
|
||||||
|
mayaLimitedFreeGP++
|
||||||
|
|
||||||
|
// Anyone an idea for a good icon?
|
||||||
|
val notification = "{A new b'ak'tun has just begun!}\n{A Great Person joins you!}"
|
||||||
|
civInfo.addNotification(notification, MayaLongCountAction(), NotificationCategory.General, MayaCalendar.notificationIcon)
|
||||||
|
}
|
||||||
|
|
||||||
fun getGreatPeople(): HashSet<BaseUnit> {
|
fun getGreatPeople(): HashSet<BaseUnit> {
|
||||||
val greatPeople = civInfo.gameInfo.ruleset.units.values.asSequence()
|
val greatPeople = civInfo.gameInfo.ruleset.units.values.asSequence()
|
||||||
|
@ -3,13 +3,13 @@ package com.unciv.models.ruleset.unique
|
|||||||
import com.badlogic.gdx.math.Vector2
|
import com.badlogic.gdx.math.Vector2
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.logic.automation.civilization.NextTurnAutomation
|
||||||
import com.unciv.logic.battle.MapUnitCombatant
|
import com.unciv.logic.battle.MapUnitCombatant
|
||||||
import com.unciv.logic.city.City
|
import com.unciv.logic.city.City
|
||||||
import com.unciv.logic.civilization.CivFlags
|
import com.unciv.logic.civilization.CivFlags
|
||||||
import com.unciv.logic.civilization.Civilization
|
import com.unciv.logic.civilization.Civilization
|
||||||
import com.unciv.logic.civilization.LocationAction
|
import com.unciv.logic.civilization.LocationAction
|
||||||
import com.unciv.logic.civilization.MapUnitAction
|
import com.unciv.logic.civilization.MapUnitAction
|
||||||
import com.unciv.logic.civilization.MayaLongCountAction
|
|
||||||
import com.unciv.logic.civilization.NotificationAction
|
import com.unciv.logic.civilization.NotificationAction
|
||||||
import com.unciv.logic.civilization.NotificationCategory
|
import com.unciv.logic.civilization.NotificationCategory
|
||||||
import com.unciv.logic.civilization.NotificationIcon
|
import com.unciv.logic.civilization.NotificationIcon
|
||||||
@ -20,12 +20,10 @@ import com.unciv.logic.map.mapunit.MapUnit
|
|||||||
import com.unciv.logic.map.tile.Tile
|
import com.unciv.logic.map.tile.Tile
|
||||||
import com.unciv.models.UpgradeUnitAction
|
import com.unciv.models.UpgradeUnitAction
|
||||||
import com.unciv.models.ruleset.BeliefType
|
import com.unciv.models.ruleset.BeliefType
|
||||||
import com.unciv.models.ruleset.Victory
|
|
||||||
import com.unciv.models.stats.Stat
|
import com.unciv.models.stats.Stat
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
import com.unciv.models.translations.fillPlaceholders
|
import com.unciv.models.translations.fillPlaceholders
|
||||||
import com.unciv.models.translations.hasPlaceholderParameters
|
import com.unciv.models.translations.hasPlaceholderParameters
|
||||||
import com.unciv.ui.components.MayaCalendar
|
|
||||||
import com.unciv.ui.components.extensions.addToMapOfSets
|
import com.unciv.ui.components.extensions.addToMapOfSets
|
||||||
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsUpgrade
|
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsUpgrade
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@ -232,41 +230,18 @@ object UniqueTriggerActivation {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
UniqueType.OneTimeFreeGreatPerson, UniqueType.MayanGainGreatPerson -> {
|
UniqueType.OneTimeFreeGreatPerson -> {
|
||||||
if (civInfo.isSpectator()) return false
|
if (civInfo.isSpectator()) return false
|
||||||
val greatPeople = civInfo.greatPeople.getGreatPeople()
|
civInfo.greatPeople.freeGreatPeople++
|
||||||
if (unique.type == UniqueType.MayanGainGreatPerson && civInfo.greatPeople.longCountGPPool.isEmpty())
|
// Anyone an idea for a good icon?
|
||||||
civInfo.greatPeople.longCountGPPool = greatPeople.map { it.name }.toHashSet()
|
if (notification != null)
|
||||||
if (civInfo.isHuman() && !UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI()) {
|
civInfo.addNotification(notification, NotificationCategory.General)
|
||||||
civInfo.greatPeople.freeGreatPeople++
|
|
||||||
// Anyone an idea for a good icon?
|
if (civInfo.isAI() || UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI()) {
|
||||||
if (unique.type == UniqueType.MayanGainGreatPerson) {
|
NextTurnAutomation.chooseGreatPerson(civInfo)
|
||||||
civInfo.greatPeople.mayaLimitedFreeGP++
|
|
||||||
civInfo.addNotification(notification!!, MayaLongCountAction(), NotificationCategory.General, MayaCalendar.notificationIcon)
|
|
||||||
} else if (notification != null)
|
|
||||||
civInfo.addNotification(notification, NotificationCategory.General)
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
if (unique.type == UniqueType.MayanGainGreatPerson)
|
|
||||||
greatPeople.removeAll { it.name !in civInfo.greatPeople.longCountGPPool }
|
|
||||||
if (greatPeople.isEmpty()) return false
|
|
||||||
var greatPerson = greatPeople.random()
|
|
||||||
|
|
||||||
if (civInfo.wantsToFocusOn(Victory.Focus.Culture)) {
|
|
||||||
val culturalGP =
|
|
||||||
greatPeople.firstOrNull { it.uniques.contains("Great Person - [Culture]") }
|
|
||||||
if (culturalGP != null) greatPerson = culturalGP
|
|
||||||
}
|
|
||||||
if (civInfo.wantsToFocusOn(Victory.Focus.Science)) {
|
|
||||||
val scientificGP =
|
|
||||||
greatPeople.firstOrNull { it.uniques.contains("Great Person - [Science]") }
|
|
||||||
if (scientificGP != null) greatPerson = scientificGP
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unique.type == UniqueType.MayanGainGreatPerson)
|
|
||||||
civInfo.greatPeople.longCountGPPool.remove(greatPerson.name)
|
|
||||||
return civInfo.units.addUnit(greatPerson.name, chosenCity) != null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
UniqueType.OneTimeGainPopulation -> {
|
UniqueType.OneTimeGainPopulation -> {
|
||||||
|
@ -2,6 +2,8 @@ package com.unciv.ui.components
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.logic.automation.civilization.NextTurnAutomation
|
||||||
import com.unciv.logic.civilization.Civilization
|
import com.unciv.logic.civilization.Civilization
|
||||||
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
@ -73,12 +75,9 @@ object MayaCalendar {
|
|||||||
val game = civInfo.gameInfo
|
val game = civInfo.gameInfo
|
||||||
val year = game.getYear()
|
val year = game.getYear()
|
||||||
if (!isNewCycle(year, game.getYear(-1))) return
|
if (!isNewCycle(year, game.getYear(-1))) return
|
||||||
for (unique in civInfo.getMatchingUniques(UniqueType.MayanGainGreatPerson)) {
|
civInfo.greatPeople.triggerMayanGreatPerson()
|
||||||
UniqueTriggerActivation.triggerCivwideUnique(
|
if (civInfo.isAI() || UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI())
|
||||||
unique, civInfo,
|
NextTurnAutomation.chooseGreatPerson(civInfo)
|
||||||
notification = "{A new b'ak'tun has just begun!}\n{A Great Person joins you!}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// User interface to explain changed year display
|
// User interface to explain changed year display
|
||||||
|
Loading…
Reference in New Issue
Block a user