From d28aabaf7c55956f1b6dd135e8930e8ed6a06b14 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Thu, 21 Nov 2024 19:19:10 +0200 Subject: [PATCH] chore: rename canSwap to allowSwap so we don't think it's a precomputed value of something --- .../unciv/logic/automation/unit/WorkerAutomation.kt | 4 ++-- .../unciv/logic/map/mapunit/movement/UnitMovement.kt | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt index 7622043432..0599a250bb 100644 --- a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt @@ -85,8 +85,8 @@ class WorkerAutomation( if (tileToWork != currentTile && tileToWork != null) { debug("WorkerAutomation: %s -> head towards %s", unit.toString(), tileToWork) - if (unit.movement.canReachInCurrentTurn(tileToWork) && unit.movement.canMoveTo(tileToWork, canSwap = true)) { - if (!unit.movement.canMoveTo(tileToWork, canSwap = false) && unit.movement.canUnitSwapTo(tileToWork)) { + if (unit.movement.canReachInCurrentTurn(tileToWork) && unit.movement.canMoveTo(tileToWork, allowSwap = true)) { + if (!unit.movement.canMoveTo(tileToWork, allowSwap = false) && unit.movement.canUnitSwapTo(tileToWork)) { // There must be a unit on the target tile! Lets swap with it. unit.movement.swapMoveToTile(tileToWork) } diff --git a/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt b/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt index c278e5fb70..3c9233c189 100644 --- a/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt +++ b/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt @@ -333,8 +333,8 @@ class UnitMovement(val unit: MapUnit) { || otherUnit.cache.cannotMove // redundant, line below would cover it too || !otherUnit.movement.canReachInCurrentTurn(ourPosition)) return false - if (!canMoveTo(reachableTile, canSwap = true)) return false - if (!otherUnit.movement.canMoveTo(ourPosition, canSwap = true)) return false + if (!canMoveTo(reachableTile, allowSwap = true)) return false + if (!otherUnit.movement.canMoveTo(ourPosition, allowSwap = true)) return false // All clear! return true } @@ -583,7 +583,7 @@ class UnitMovement(val unit: MapUnit) { * @param includeOtherEscortUnit determines whether or not this method will also check if the other escort unit [canMoveTo] if it has one. * Leave it as default unless you know what [canMoveTo] does. */ - fun canMoveTo(tile: Tile, assumeCanPassThrough: Boolean = false, canSwap: Boolean = false, includeOtherEscortUnit: Boolean = true): Boolean { + fun canMoveTo(tile: Tile, assumeCanPassThrough: Boolean = false, allowSwap: Boolean = false, includeOtherEscortUnit: Boolean = true): Boolean { if (unit.baseUnit.movesLikeAirUnits) return canAirUnitMoveTo(tile, unit) @@ -595,15 +595,15 @@ class UnitMovement(val unit: MapUnit) { return false if (includeOtherEscortUnit && unit.isEscorting() - && !unit.getOtherEscortUnit()!!.movement.canMoveTo(tile, assumeCanPassThrough,canSwap, includeOtherEscortUnit = false)) + && !unit.getOtherEscortUnit()!!.movement.canMoveTo(tile, assumeCanPassThrough, allowSwap, includeOtherEscortUnit = false)) return false return if (unit.isCivilian()) - (tile.civilianUnit == null || (canSwap && tile.civilianUnit!!.owner == unit.owner)) + (tile.civilianUnit == null || (allowSwap && tile.civilianUnit!!.owner == unit.owner)) && (tile.militaryUnit == null || tile.militaryUnit!!.owner == unit.owner) else // can skip checking for airUnit since not a city - (tile.militaryUnit == null || (canSwap && tile.militaryUnit!!.owner == unit.owner)) + (tile.militaryUnit == null || (allowSwap && tile.militaryUnit!!.owner == unit.owner)) && (tile.civilianUnit == null || tile.civilianUnit!!.owner == unit.owner || unit.civ.isAtWarWith(tile.civilianUnit!!.civ)) }