mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-09 20:29:50 +07:00
Fixed edge-case bug when units try to be created but aren't, and then get assigned an Alhambra promotion, triggering viewableTile update
This commit is contained in:
parent
e8bdb8a2e4
commit
99d7b0ea1a
@ -511,7 +511,7 @@ class CivilizationInfo {
|
||||
addNotification("A [$greatPerson] has been born!".tr(), city.location, Color.GOLD)
|
||||
}
|
||||
|
||||
fun placeUnitNearTile(location: Vector2, unitName: String): MapUnit {
|
||||
fun placeUnitNearTile(location: Vector2, unitName: String): MapUnit? {
|
||||
return gameInfo.tileMap.placeUnitNearTile(location, unitName, this)
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ class TileMap {
|
||||
.filter {contains(it)}.map { get(it) }.toList()
|
||||
}
|
||||
|
||||
fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit {
|
||||
fun placeUnitNearTile(position: Vector2, unitName: String, civInfo: CivilizationInfo): MapUnit? {
|
||||
val unit = GameBasics.Units[unitName]!!.getMapUnit()
|
||||
val tilesInDistance = getTilesInDistance(position, 2)
|
||||
unit.assignOwner(civInfo) // both the civ name and actual civ need to be in here in order to calculate the canMoveTo...Darn
|
||||
@ -89,7 +89,10 @@ class TileMap {
|
||||
for(promotion in unit.baseUnit.promotions)
|
||||
unit.promotions.addPromotion(promotion,true)
|
||||
}
|
||||
else civInfo.removeUnit(unit) // since we added it to the civ units in the previous assignOwner
|
||||
else {
|
||||
civInfo.removeUnit(unit) // since we added it to the civ units in the previous assignOwner
|
||||
return null // we didn't actually create a unit...
|
||||
}
|
||||
|
||||
return unit
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class UnitPromotions{
|
||||
fun xpForNextPromotion() = (numberOfPromotions+1)*10
|
||||
fun canBePromoted() = XP >= xpForNextPromotion()
|
||||
|
||||
fun addPromotion(promotionName:String, isFree:Boolean = false){
|
||||
fun addPromotion(promotionName:String, isFree:Boolean = false, updateViewableTiles:Boolean=true){
|
||||
if (!isFree) {
|
||||
XP -= xpForNextPromotion()
|
||||
numberOfPromotions++
|
||||
@ -28,6 +28,11 @@ class UnitPromotions{
|
||||
else promotions.add(promotionName)
|
||||
|
||||
unit.updateUniques()
|
||||
|
||||
// Since some units get promotions upon construction, they will get the addPromotion from the unit.postBuildEvent
|
||||
// upon creation, BEFORE they are assigned to a tile, so the updateViewableTiles() would crash.
|
||||
// So, if the addPromotion was triggered from there, simply don't update
|
||||
// if(updateViewableTiles)
|
||||
unit.updateViewableTiles() // some promotions/uniques give the unit bonus sight
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.unciv.models.gamebasics.unit
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.logic.city.CityConstructions
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.Constants
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.ICivilopedia
|
||||
import com.unciv.models.gamebasics.Translations
|
||||
@ -144,6 +144,7 @@ class BaseUnit : INamed, IConstruction, ICivilopedia {
|
||||
|
||||
override fun postBuildEvent(construction: CityConstructions) {
|
||||
val unit = construction.cityInfo.civInfo.placeUnitNearTile(construction.cityInfo.location, name)
|
||||
if(unit==null) return // couldn't place the unit, so there's actually no unit =(
|
||||
unit.promotions.XP += construction.getBuiltBuildings().sumBy { it.xpForNewUnits }
|
||||
if(construction.cityInfo.civInfo.policies.isAdopted("Total War"))
|
||||
unit.promotions.XP += 15
|
||||
|
@ -94,7 +94,7 @@ class UnitActions {
|
||||
unit.civInfo.gold -= goldCostOfUpgrade
|
||||
val unitTile = unit.getTile()
|
||||
unit.destroy()
|
||||
val newunit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)
|
||||
val newunit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)!!
|
||||
newunit.health = unit.health
|
||||
newunit.promotions = unit.promotions
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user