mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-01 02:14:51 +07:00
Make CivilizationInfo.gold read-only (#4074)
* Make CivilizationInfo.gold read-only * Make CivilizationInfo.gold read-only
This commit is contained in:
parent
8228d62d43
commit
fadd1684ac
@ -327,7 +327,7 @@ class CityConstructions {
|
|||||||
if (construction is Building) {
|
if (construction is Building) {
|
||||||
// Production put into wonders gets refunded
|
// Production put into wonders gets refunded
|
||||||
if (construction.isWonder && getWorkDone(constructionName) != 0) {
|
if (construction.isWonder && getWorkDone(constructionName) != 0) {
|
||||||
cityInfo.civInfo.gold += getWorkDone(constructionName)
|
cityInfo.civInfo.addGold( getWorkDone(constructionName) )
|
||||||
val buildingIcon = "BuildingIcons/${constructionName}"
|
val buildingIcon = "BuildingIcons/${constructionName}"
|
||||||
cityInfo.civInfo.addNotification("Excess production for [$constructionName] converted to [${getWorkDone(constructionName)}] gold", NotificationIcon.Gold, buildingIcon)
|
cityInfo.civInfo.addNotification("Excess production for [$constructionName] converted to [${getWorkDone(constructionName)}] gold", NotificationIcon.Gold, buildingIcon)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,9 @@ class CivilizationInfo {
|
|||||||
|
|
||||||
/** Used in online multiplayer for human players */
|
/** Used in online multiplayer for human players */
|
||||||
var playerId = ""
|
var playerId = ""
|
||||||
|
/** The Civ's gold reserves. Public get, private set - please use [addGold] method to modify. */
|
||||||
var gold = 0
|
var gold = 0
|
||||||
|
private set
|
||||||
var civName = ""
|
var civName = ""
|
||||||
var tech = TechManager()
|
var tech = TechManager()
|
||||||
var policies = PolicyManager()
|
var policies = PolicyManager()
|
||||||
@ -543,7 +545,11 @@ class CivilizationInfo {
|
|||||||
updateHasActiveGreatWall()
|
updateHasActiveGreatWall()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Modify gold by a given amount making sure it does neither overflow nor underflow.
|
||||||
|
* @param delta the amount to add (can be negative)
|
||||||
|
*/
|
||||||
fun addGold(delta: Int) {
|
fun addGold(delta: Int) {
|
||||||
|
// not using Long.coerceIn - this stays in 32 bits
|
||||||
gold = when {
|
gold = when {
|
||||||
delta > 0 && gold > Int.MAX_VALUE - delta -> Int.MAX_VALUE
|
delta > 0 && gold > Int.MAX_VALUE - delta -> Int.MAX_VALUE
|
||||||
delta < 0 && gold < Int.MIN_VALUE - delta -> Int.MIN_VALUE
|
delta < 0 && gold < Int.MIN_VALUE - delta -> Int.MIN_VALUE
|
||||||
|
Loading…
Reference in New Issue
Block a user