mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 06:51:30 -04:00
Bonus as Attacker problem fixed
This commit is contained in:
parent
185ec10f10
commit
eedc0e30f2
@ -57,7 +57,7 @@ class BattleDamage{
|
||||
|
||||
if(combatant.getCivInfo().policies.isAdopted("Discipline") && combatant.isMelee()
|
||||
&& combatant.getTile().neighbors.flatMap { it.getUnits() }
|
||||
.any { it.civInfo==combatant.getCivInfo() && !it.type.isCivilian()})
|
||||
.any { it.civInfo==combatant.getCivInfo() && !it.type.isCivilian() && !it.type.isAirUnit()})
|
||||
modifiers["Discipline"] = 0.15f
|
||||
|
||||
val requiredResource = combatant.unit.baseUnit.requiredResource
|
||||
@ -108,7 +108,7 @@ class BattleDamage{
|
||||
}
|
||||
|
||||
for (ability in attacker.unit.getUniques()) {
|
||||
val regexResult = Regex("""Bonus as Attacker (\d*)%""").matchEntire(ability) //to do: extend to defender, and penalyy
|
||||
val regexResult = Regex("""Bonus as Attacker [(\d*)]%""").matchEntire(ability) //to do: extend to defender, and penalyy
|
||||
if (regexResult == null) continue
|
||||
val bonus = regexResult.groups[1]!!.value.toFloat() / 100
|
||||
if (modifiers.containsKey("Attacker Bonus"))
|
||||
|
@ -40,6 +40,7 @@ open class TileInfo {
|
||||
val toReturn = TileInfo()
|
||||
if(militaryUnit!=null) toReturn.militaryUnit=militaryUnit!!.clone()
|
||||
if(civilianUnit!=null) toReturn.civilianUnit=civilianUnit!!.clone()
|
||||
for(airUnit in airUnits) toReturn.airUnits.add(airUnit.clone())
|
||||
toReturn.position=position.cpy()
|
||||
toReturn.baseTerrain=baseTerrain
|
||||
toReturn.terrainFeature=terrainFeature
|
||||
@ -62,12 +63,14 @@ open class TileInfo {
|
||||
}
|
||||
|
||||
//region pure functions
|
||||
|
||||
/** Returns military, civilian and air units in tile */
|
||||
fun getUnits(): List<MapUnit> {
|
||||
val list = ArrayList<MapUnit>(2)
|
||||
if(militaryUnit!=null) list.add(militaryUnit!!)
|
||||
if(civilianUnit!=null) list.add(civilianUnit!!)
|
||||
list.addAll(airUnits)
|
||||
return list
|
||||
// this used to be "return listOf(militaryUnit,civilianUnit).filterNotNull()" but profiling revealed that that took considerably longer
|
||||
}
|
||||
|
||||
fun getCity(): CityInfo? = owningCity
|
||||
@ -293,10 +296,8 @@ open class TileInfo {
|
||||
isLand = getBaseTerrain().type==TerrainType.Land
|
||||
isOcean = baseTerrain == Constants.ocean
|
||||
|
||||
if(militaryUnit!=null) militaryUnit!!.currentTile = this
|
||||
if(civilianUnit!=null) civilianUnit!!.currentTile = this
|
||||
|
||||
for (unit in getUnits()) {
|
||||
unit.currentTile = this
|
||||
unit.assignOwner(tileMap.gameInfo.getCivilization(unit.owner),false)
|
||||
unit.setTransients()
|
||||
}
|
||||
@ -311,7 +312,7 @@ open class TileInfo {
|
||||
val unitsInTile = getUnits()
|
||||
if (unitsInTile.isEmpty()) return false
|
||||
if (!unitsInTile.first().civInfo.isPlayerCivilization() &&
|
||||
unitsInTile.firstOrNull {it.isInvisible() == true} != null) {
|
||||
unitsInTile.firstOrNull { it.isInvisible() } != null) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -63,7 +63,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
|
||||
if (UnCivGame.Current.viewEntireMapForDebug || city.civInfo.isCurrentPlayer()) {
|
||||
|
||||
// So you can click anywhere on the button to go to the city
|
||||
touchable = Touchable.enabled
|
||||
touchable = Touchable.childrenOnly
|
||||
|
||||
// clicking swings the button a little down to allow selection of units there.
|
||||
// this also allows to target selected units to move to the city tile from elsewhere.
|
||||
@ -91,6 +91,7 @@ class CityButton(val city: CityInfo, internal val tileGroup: WorldTileGroup, ski
|
||||
private fun getIconTable(): Table {
|
||||
val secondaryColor = city.civInfo.getNation().getSecondaryColor()
|
||||
val iconTable = Table()
|
||||
iconTable.touchable=Touchable.enabled
|
||||
iconTable.background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
|
||||
.tint(city.civInfo.getNation().getColor())
|
||||
|
||||
|
@ -7,8 +7,10 @@ import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.FloatAction
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UnCivGame
|
||||
@ -52,6 +54,10 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
tileGroup.cityButtonLayerGroup.onClick("") {
|
||||
showAircraft(tileGroup.tileInfo.getCity()!!)
|
||||
}
|
||||
}
|
||||
|
||||
actor = allTiles
|
||||
@ -90,9 +96,10 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
unitActionOverlay?.remove()
|
||||
selectedTile = tileInfo
|
||||
|
||||
val previousSelectedUnit = worldScreen.bottomBar.unitTable.selectedUnit
|
||||
worldScreen.bottomBar.unitTable.tileSelected(tileInfo)
|
||||
val newSelectedUnit = worldScreen.bottomBar.unitTable.selectedUnit
|
||||
val unitTable = worldScreen.bottomBar.unitTable
|
||||
val previousSelectedUnit = unitTable.selectedUnit
|
||||
unitTable.tileSelected(tileInfo)
|
||||
val newSelectedUnit = unitTable.selectedUnit
|
||||
|
||||
if (previousSelectedUnit != null && previousSelectedUnit.getTile() != tileInfo
|
||||
&& previousSelectedUnit.canMoveTo(tileInfo) && previousSelectedUnit.movementAlgs().canReach(tileInfo)) {
|
||||
@ -100,6 +107,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
moveHere(previousSelectedUnit, tileInfo)
|
||||
}
|
||||
|
||||
|
||||
if(newSelectedUnit==null || newSelectedUnit.type==UnitType.Civilian){
|
||||
val unitsInTile = selectedTile!!.getUnits()
|
||||
if(unitsInTile.isNotEmpty() && unitsInTile.first().civInfo.isAtWarWith(worldScreen.currentPlayerCiv)){
|
||||
@ -108,7 +116,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
.filter { it.isCityCenter() }.map { it.getCity()!! }
|
||||
.filter { !it.attackedThisTurn }
|
||||
if(citiesThatCanBombard.isNotEmpty())
|
||||
worldScreen.bottomBar.unitTable.citySelected(citiesThatCanBombard.first())
|
||||
unitTable.citySelected(citiesThatCanBombard.first())
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +199,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
actor.center(group)
|
||||
actor.x+=group.x
|
||||
actor.y+=group.y
|
||||
group.parent.addActor(actor)
|
||||
group.parent.addActor(actor) // Add the overlay to the TileGroupMap - it's what actually displays all the tiles
|
||||
actor.toFront()
|
||||
|
||||
actor.y += actor.height
|
||||
@ -287,6 +295,25 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
|
||||
}
|
||||
}
|
||||
|
||||
private fun showAircraft(city:CityInfo){
|
||||
if (city.getCenterTile().airUnits.isEmpty()) return
|
||||
val airUnitsTable = Table().apply { defaults().pad(10f) }
|
||||
for(unit in city.getCenterTile().airUnits){
|
||||
val unitGroup = UnitGroup(unit,60f).surroundWithCircle(80f)
|
||||
unitGroup.circle.color = Color.GRAY.cpy().apply { a=0.5f }
|
||||
unitGroup.touchable=Touchable.enabled
|
||||
unitGroup.onClick {
|
||||
worldScreen.bottomBar.unitTable.selectedUnit=unit
|
||||
worldScreen.shouldUpdate=true
|
||||
unitGroup.circle.color = Color.WHITE
|
||||
}
|
||||
airUnitsTable.add(unitGroup)
|
||||
}
|
||||
airUnitsTable.height=60f
|
||||
unitActionOverlay?.remove()
|
||||
addOverlayOnTileGroup(city.getCenterTile(),airUnitsTable)
|
||||
}
|
||||
|
||||
fun setCenterPosition(vector: Vector2, immediately: Boolean = false, selectUnit: Boolean = true) {
|
||||
val tileGroup = tileGroups.values.first { it.tileInfo.position == vector }
|
||||
selectedTile = tileGroup.tileInfo
|
||||
|
Loading…
x
Reference in New Issue
Block a user