Resolved #9249 - Solved AI Great Scientist crash

This commit is contained in:
Yair Morgenstern
2023-04-23 09:40:33 +03:00
parent 2b4dbe2ad2
commit 226bd85c84
2 changed files with 9 additions and 7 deletions

View File

@ -274,11 +274,13 @@ object UnitAutomation {
val isLateGame = isLateGame(unit.civ)
// Great scientist -> Hurry research if late game
if (UnitActions.getUnitActions(unit).any { it.type == UnitActionType.HurryResearch }
&& isLateGame) {
UnitActions.getUnitActions(unit)
.first { it.type == UnitActionType.HurryResearch }.action!!.invoke()
return
if (isLateGame) {
val hurryResearch = UnitActions.getUnitActions(unit)
.firstOrNull { it.type == UnitActionType.HurryResearch }?.action
if (hurryResearch != null) {
hurryResearch()
return
}
}
// Great merchant -> Conduct trade mission if late game and if not at war.
@ -286,8 +288,7 @@ object UnitAutomation {
// also have more influence.
if (unit.hasUnique(UniqueType.CanTradeWithCityStateForGoldAndInfluence)
// Don't wander around with the great merchant when at war. Barbs might also be a
// problem, but hopefully by the time we have a great merchant, they're under
// control.
// problem, but hopefully by the time we have a great merchant, they're under control.
&& !unit.civ.isAtWar()
&& isLateGame
) {

View File

@ -18,6 +18,7 @@ data class UnitAction(
val title: String = type.value,
val isCurrentAction: Boolean = false,
val uncivSound: UncivSound = type.uncivSound,
/** Action is Null is this unit *can* execute the action but *not right now* - it's embarked, out of moves, etc */
val action: (() -> Unit)? = null
) {
fun getIcon(): Actor {