Damage calculations are now according to extrapolated Civ V rules

This commit is contained in:
Yair Morgenstern 2018-05-09 18:24:30 +03:00
parent a230676325
commit 9625a12ba2
3 changed files with 37 additions and 23 deletions

View File

@ -21,7 +21,7 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 48
versionCode 49
versionName "2.1.0"
}
buildTypes {

View File

@ -7,9 +7,13 @@ import com.unciv.logic.map.UnitType
import java.util.*
import kotlin.collections.HashMap
/**
* Damage calculations according to civ v wiki and https://steamcommunity.com/sharedfiles/filedetails/?id=170194443
*/
class Battle(val gameInfo:GameInfo) {
fun getGeneralModifiers(combatant: ICombatant, enemy: ICombatant): HashMap<String, Float> {
val modifiers = HashMap<String, Float>()
if (combatant is MapUnitCombatant) {
@ -62,6 +66,12 @@ class Battle(val gameInfo:GameInfo) {
return modifier
}
fun getHealthDependantDamageRatio(combatant: ICombatant): Float {
if (combatant.getUnitType() == UnitType.City) return 1f;
return 1 / 2f + combatant.getHealth() / 200f // Each point of health reduces damage dealt by 0.5%
}
/**
* Includes attack modifiers
*/
@ -81,11 +91,13 @@ class Battle(val gameInfo:GameInfo) {
fun calculateDamageToAttacker(attacker: ICombatant, defender: ICombatant): Int {
if(attacker.isRanged()) return 0
return (getDefendingStrength(attacker,defender) * 50 / getAttackingStrength(attacker,defender)).toInt()
val ratio = getDefendingStrength(attacker,defender) / getAttackingStrength(attacker,defender)
return (ratio * 30 * getHealthDependantDamageRatio(defender)).toInt()
}
fun calculateDamageToDefender(attacker: ICombatant, defender: ICombatant): Int {
return (getAttackingStrength(attacker, defender)*50/ getDefendingStrength(attacker,defender)).toInt()
val ratio = getAttackingStrength(attacker,defender) / getDefendingStrength(attacker,defender)
return (ratio * 30 * getHealthDependantDamageRatio(attacker)).toInt()
}
fun attack(attacker: ICombatant, defender: ICombatant) {

View File

@ -39,6 +39,7 @@ class CivStatsTable(val screen: WorldScreen) : Table() {
resourceLabels.put(resource.name, resourceLabel)
resourceTable.add(resourceLabel)
}
resourceTable.pack()
add(resourceTable).row()
@ -50,11 +51,12 @@ class CivStatsTable(val screen: WorldScreen) : Table() {
statsTable.add(scienceLabel.apply { setAlignment(Align.center) })
statsTable.add(happinessLabel.apply { setAlignment(Align.center) })
statsTable.add(cultureLabel.apply { setAlignment(Align.center) })
add(statsTable)
statsTable.pack()
statsTable.width = screen.stage.width - 20
add(statsTable)
pack()
width = screen.stage.width - 20
statsTable.width = width
}
internal fun getMenuButton(): TextButton {