diff --git a/android/assets/jsons/Civilizations.json b/android/assets/jsons/Civilizations.json index 2868a2df6c..d35c3c1630 100644 --- a/android/assets/jsons/Civilizations.json +++ b/android/assets/jsons/Civilizations.json @@ -2,5 +2,9 @@ { name:"Babylon", RGB:[220,20,60] - } + }, + { + name:"Barbarians", + RGB:[200,200,200] + } ] \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 94639e9875..e552c995a6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 31 - versionName "1.3.4" + versionCode 32 + versionName "1.3.5" } buildTypes { release { diff --git a/core/src/com/unciv/logic/Battle.kt b/core/src/com/unciv/logic/Battle.kt new file mode 100644 index 0000000000..0c1cb49552 --- /dev/null +++ b/core/src/com/unciv/logic/Battle.kt @@ -0,0 +1,13 @@ +package com.unciv.logic + +import com.unciv.logic.map.MapUnit + +/** + * Created by LENOVO on 3/26/2018. + */ + +class Battle(){ + fun calculateDamage(attacker:MapUnit, defender:MapUnit): Int { + return (attacker.strength*attacker.health*5) / (defender.strength*defender.health) + } +} \ No newline at end of file diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 97d0d0fcd9..8c44aa3a72 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -7,18 +7,27 @@ import com.unciv.models.gamebasics.TileImprovement import java.text.DecimalFormat +enum class UnitType{ + Civilian, + Melee, + Ranged +} + class MapUnit { @Transient lateinit var civInfo: CivilizationInfo - @JvmField var owner: String? = null - @JvmField var name: String? = null - @JvmField var maxMovement: Int = 0 - @JvmField var currentMovement: Float = 0f - @JvmField var action: String? = null // work, automation, fortifying, I dunno what. + var owner: String? = null + var name: String? = null + var maxMovement: Int = 0 + var currentMovement: Float = 0f + lateinit var unitType:UnitType + var health:Int = 10 + var strength:Int = 1 + var rangedStrength:Int = 0 + var action: String? = null // work, automation, fortifying, I dunno what. - val movementString: String - get() = DecimalFormat("0.#").format(currentMovement.toDouble()) + "/" + maxMovement + fun getMovementString(): String = DecimalFormat("0.#").format(currentMovement.toDouble()) + "/" + maxMovement fun doPreTurnAction(tile: TileInfo) { if (currentMovement == 0f) return // We've already done stuff this turn, and can't do any more stuff diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 6eac5d4b4d..05b7e082a1 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -154,7 +154,7 @@ class TileInfo { if (roadStatus !== RoadStatus.None && !isCityCenter) SB.appendln(roadStatus) if (improvement != null) SB.appendln(improvement!!) if (improvementInProgress != null) SB.appendln("$improvementInProgress in ${this.turnsToImprovement} turns") - if (unit != null) SB.appendln(unit!!.name + "(" + unit!!.movementString + ")") + if (unit != null) SB.appendln(unit!!.name + "(" + unit!!.getMovementString() + ")") return SB.toString() } diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 1e0127c751..41f9217273 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -115,7 +115,8 @@ class TileMap { val unit = GameBasics.Units[unitName]!!.mapUnit unit.owner = civInfo.civName unit.civInfo = civInfo - getTilesInDistance(position, 2).first { it.unit == null }.unit = unit // And if there's none, then kill me. + val tilesInDistance = getTilesInDistance(position, 2) + tilesInDistance.first { it.unit == null }.unit = unit // And if there's none, then kill me. } fun getViewableTiles(position: Vector2, sightDistance: Int): MutableList { diff --git a/core/src/com/unciv/ui/UnCivGame.kt b/core/src/com/unciv/ui/UnCivGame.kt index d41137a789..e6cd40c517 100644 --- a/core/src/com/unciv/ui/UnCivGame.kt +++ b/core/src/com/unciv/ui/UnCivGame.kt @@ -44,7 +44,11 @@ class UnCivGame : Game() { gameInfo = GameInfo() gameInfo.tileMap = TileMap(20) gameInfo.civilizations.add(CivilizationInfo("Babylon", Vector2.Zero, gameInfo)) + val barbarians = CivilizationInfo() + barbarians.civName = "Barbarians" + gameInfo.civilizations.add(barbarians) gameInfo.setTransients() + gameInfo.tileMap.placeUnitNearTile(Vector2.Zero,"Scout",barbarians) worldScreen = WorldScreen() setWorldScreen() diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 402796ae94..b4befff91a 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -2,8 +2,11 @@ package com.unciv.ui.worldscreen import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.scenes.scene2d.ui.Label +import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.unciv.logic.Battle import com.unciv.logic.civilization.CivilizationInfo +import com.unciv.logic.map.MapUnit import com.unciv.ui.cityscreen.addClickListener import com.unciv.ui.pickerscreens.PolicyPickerScreen import com.unciv.ui.pickerscreens.TechPickerScreen @@ -25,6 +28,7 @@ class WorldScreen : CameraStageBaseScreen() { internal val optionsTable: WorldScreenOptionsTable private val notificationsScroll: NotificationsScroll internal val unitTable = UnitTable(this) + internal val battleTable = BattleTable(this) init { val gameInfo = game.gameInfo @@ -41,6 +45,7 @@ class WorldScreen : CameraStageBaseScreen() { optionsTable = WorldScreenOptionsTable(this, civInfo) Label("", CameraStageBaseScreen.skin).style.font.data.setScale(game.settings.labelScale) + tileMapHolder.addTiles() stage.addActor(tileMapHolder) @@ -50,6 +55,7 @@ class WorldScreen : CameraStageBaseScreen() { stage.addActor(techButton) stage.addActor(notificationsScroll) stage.addActor(unitTable) + stage.addActor(battleTable) update() @@ -66,7 +72,8 @@ class WorldScreen : CameraStageBaseScreen() { } updateTechButton() - if (tileMapHolder.selectedTile != null) tileInfoTable.updateTileTable(tileMapHolder.selectedTile!!) + if (tileMapHolder.selectedTile != null) + tileInfoTable.updateTileTable(tileMapHolder.selectedTile!!) tileMapHolder.updateTiles() civTable.update(this) notificationsScroll.update() @@ -74,6 +81,13 @@ class WorldScreen : CameraStageBaseScreen() { notificationsScroll.setPosition(stage.width - notificationsScroll.width - 5f, nextTurnButton.y - notificationsScroll.height - 5f) unitTable.update() + + if(tileMapHolder.selectedTile!=null + && tileMapHolder.selectedTile!!.unit!=null + && tileMapHolder.selectedTile!!.unit!!.owner!=civInfo.civName + && unitTable.selectedUnitTile!=null) + battleTable.simulateBattle(unitTable.getSelectedUnit(), tileMapHolder.selectedTile!!.unit!!) + else battleTable.clear() } private fun updateTechButton() { @@ -130,3 +144,26 @@ class WorldScreen : CameraStageBaseScreen() { } } +class BattleTable(val worldScreen: WorldScreen): Table() { + fun simulateBattle(attacker:MapUnit,defender:MapUnit){ + clear() + add(Label(attacker.name, CameraStageBaseScreen.skin)) + add(Label(defender.name, CameraStageBaseScreen.skin)) + row() + + val battle = Battle() + val damageToAttacker = battle.calculateDamage(attacker,defender) + add(Label(attacker.health.toString()+"/10 -> " + +(attacker.health-damageToAttacker)+"/10", + CameraStageBaseScreen.skin)) + + val damageToDefender = battle.calculateDamage(defender,attacker) + add(Label(defender.health.toString()+"/10 -> " + +(defender.health-damageToDefender)+"/10", + CameraStageBaseScreen.skin)) + pack() + setPosition(worldScreen.stage.width/2-width/2, + 5f) + } +} + diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt index cf66484d8f..8acf8056e4 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitTable.kt @@ -40,7 +40,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ if(selectedUnitTile!=null && selectedUnitTile!!.unit==null) selectedUnitTile=null // The unit that was there no longer exists if(selectedUnitTile!=null) { - unitLabel.setText(getSelectedUnit().name+" "+getSelectedUnit().movementString) + unitLabel.setText(getSelectedUnit().name+" "+getSelectedUnit().getMovementString()) for (button in UnitActions().getUnitActions(selectedUnitTile!!,worldScreen)) unitActionsTable.add(button).colspan(2).pad(5f) .size(button.width * worldScreen.buttonScale, button.height * worldScreen.buttonScale).row() @@ -61,7 +61,8 @@ class UnitTable(val worldScreen: WorldScreen) : Table(){ currentlyExecutingAction = null } - if(selectedTile.unit!=null) selectedUnitTile = selectedTile + if(selectedTile.unit!=null && selectedTile.unit!!.civInfo == worldScreen.civInfo) + selectedUnitTile = selectedTile } private fun getDistanceToTiles(): HashMap {