Rewritten the MapUnit.rankTileForHealing() (#1811)

This commit is contained in:
lyrjie 2020-01-31 15:04:44 +03:00 committed by GitHub
parent 3362c2128c
commit 0888e0a24d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 12 deletions

View file

@ -221,6 +221,14 @@ class DiplomacyManager() {
/** Returns the [civilizations][CivilizationInfo] that know about both sides ([civInfo] and [otherCiv]) */
fun getCommonKnownCivs(): Set<CivilizationInfo> = civInfo.getKnownCivs().intersect(otherCiv().getKnownCivs())
/** Returns true when the [civInfo]'s territory is considered allied for [otherCiv].
*
* This includes friendly and allied city-states and the open border treaties.
*/
fun isConsideredAllyTerritory(): Boolean {
return (hasOpenBorders)
|| (civInfo.isCityState() && relationshipLevel() >= RelationshipLevel.Friend)
}
//endregion
//region state-changing functions

View file

@ -386,19 +386,31 @@ class MapUnit {
if(health>100) health=100
}
fun rankTileForHealing(tileInfo:TileInfo): Int {
return when{
tileInfo.isWater && type.isLandUnit() -> 0 // Can't heal in water!
tileInfo.getOwner() == null -> 10 // no man's land (neutral)
tileInfo.isCityCenter() -> 20
!civInfo.isAtWarWith(tileInfo.getOwner()!!) -> 15 // home or allied territory
else -> { // enemy territory
if(hasUnique("This unit and all others in adjacent tiles heal 5 additional HP. This unit heals 5 additional HP outside of friendly territory.")) 10
else 5
}
}
}
/** Returns the health points [MapUnit] will receive if healing on [tileInfo] */
fun rankTileForHealing(tileInfo: TileInfo): Int {
val tileOwner = tileInfo.getOwner()
val isAlliedTerritory = if (tileOwner != null)
tileOwner == civInfo || tileOwner.getDiplomacyManager(civInfo).isConsideredAllyTerritory()
else
false
var healing = when {
tileInfo.isCityCenter() -> 20
tileInfo.isWater && isAlliedTerritory && type.isWaterUnit() -> 15 // Water unit on friendly water
tileInfo.isWater -> 0 // All other water cases
tileOwner == null -> 10 // Neutral territory
isAlliedTerritory -> 15 // Allied territory
else -> 5 // Enemy territory
}
if (hasUnique("This unit and all others in adjacent tiles heal 5 additional HP. This unit heals 5 additional HP outside of friendly territory.")
&& !isAlliedTerritory
// Additional healing from medic is only applied when the unit is able to heal
&& healing > 0)
healing += 5
return healing
}
fun endTurn() {
doPostTurnAction()