From e06d537688a7591e319dfa6d54d9825f7159a881 Mon Sep 17 00:00:00 2001 From: EdinCitaku Date: Sat, 21 Mar 2020 19:35:30 +0100 Subject: [PATCH] Feature#2081 (#2100) * Unit can now only be purchased if no other unit of same type is stationed in city center #2081 * #2081 Added unique to landsknecht and changed condition for movement panelty * Refactored when statement to if #2081 * Only one plane at a time can be purchased to a maximum of 6 that are NOT transported in a single city #2081 * removed duplicate code #2081 * refactor canPurchase() and now track bought units in a city in a mutableList #2081 * refactor canPurchase() it basicly just tracks if the unit can be placed on the center tile! if it cant then we dont allow the purchase! #2081 * Changed wording of unique and added translations #2081 * Changed wording of unique #2081 * removed unneeded imports #2081 Co-authored-by: Yair Morgenstern --- android/assets/jsons/Units.json | 2 +- .../jsons/translations/English.properties | 4 +++ .../jsons/translations/German.properties | 27 ++++++++++++++++++- .../jsons/translations/template.properties | 1 - .../com/unciv/logic/city/CityConstructions.kt | 2 +- core/src/com/unciv/logic/city/CityInfo.kt | 14 ++++++++++ .../src/com/unciv/logic/city/IConstruction.kt | 4 +-- core/src/com/unciv/models/ruleset/Building.kt | 2 +- .../com/unciv/models/ruleset/unit/BaseUnit.kt | 6 ++++- .../unciv/ui/cityscreen/ConstructionsTable.kt | 4 ++- 10 files changed, 57 insertions(+), 9 deletions(-) diff --git a/android/assets/jsons/Units.json b/android/assets/jsons/Units.json index 6e739a87..3a99dbe7 100644 --- a/android/assets/jsons/Units.json +++ b/android/assets/jsons/Units.json @@ -530,7 +530,7 @@ "strength": 16, "cost": 45, "requiredTech": "Civil Service", - "uniques": ["Bonus vs Mounted 50%"], + "uniques": ["Bonus vs Mounted 50%", "Can move immediately once bought" ], "upgradesTo": "Musketman", "obsoleteTech": "Gunpowder", "hurryCostModifier": 20, diff --git a/android/assets/jsons/translations/English.properties b/android/assets/jsons/translations/English.properties index 2a647a0f..b71c8133 100644 --- a/android/assets/jsons/translations/English.properties +++ b/android/assets/jsons/translations/English.properties @@ -3092,6 +3092,10 @@ Calcutta = # Requires translation! Lahore = # Requires translation! +All healing effects doubled = +Can move immediately once bought = + # Requires translation! +# Multiplayer Turn Checker Service Bangalore = # Requires translation! Hyderabad = diff --git a/android/assets/jsons/translations/German.properties b/android/assets/jsons/translations/German.properties index 54868125..68d1cceb 100644 --- a/android/assets/jsons/translations/German.properties +++ b/android/assets/jsons/translations/German.properties @@ -879,7 +879,32 @@ Bonus when performing air sweep [bonusAmount]% = [bonusAmount]% Bonus bei Luftra Dogfighting I = Kurvenkampf I Dogfighting II = Kurvenkampf II Dogfighting III = Kurvenkampf III - +Bonus when intercepting [bonusAmount]% = [bonusAmount]% Bonus beim Abfangen +Interception I = Abfangen I +Interception II = Abfangen II +Interception III = Abfangen III +Siege I = Belagerung I +Siege II = Belagerung II +Siege III = Belagerung III +Evasion = Ausweichen +Reduces damage taken from interception by 50% = Reduziert den empfangenden Schaden durch Abfangen um 50% +Bonus when intercepting [amount]% = [amount]% Bonus beim Abfangen +Ambush I = Lufthinterhalt I +Ambush II = Lufthinterhalt II +Armor Plating I = Panzerung I +Armor Plating II = Panzerung II +Armor Plating III = Panzerung III ++25% Combat Bonus when defending = +25% Kampfbonus bei Verteidigung +Flight Deck I = Flugdeck I +Flight Deck II = Flugdeck II +Flight Deck III = Flugdeck III +Can carry 1 extra air unit = Kann 1 zusätzliche Lufteinheit tragen +Can carry 2 aircraft = Kann 2 Flugzeuge tragen +Haka War Dance = Haka-Kriegstanz +-10% combat strength for adjacent enemy units = -10% Kampfstärke für angrenzende feindliche Einheiten +Rejuvenation = Verjüngung +All healing effects doubled = Alle Heilungseffekte verdoppelt +Can move immediately once bought = Kann sich nach dem Kauf sofort bewegen # Multiplayer Turn Checker Service Multiplayer options = Multiplayer Einstellungen diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 49da3445..c1aadea6 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -852,7 +852,6 @@ Bonus when performing air sweep [bonusAmount]% = Dogfighting I = Dogfighting II = Dogfighting III = - # Multiplayer Turn Checker Service Multiplayer options = diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 8537e823..fa034035 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -312,7 +312,7 @@ class CityConstructions { } fun purchaseConstruction(constructionName: String): Boolean { - if (!getConstruction(constructionName).postBuildEvent(this)) + if (!getConstruction(constructionName).postBuildEvent(this, true)) return false // nothing built - no pay cityInfo.civInfo.gold -= getConstruction(constructionName).getGoldCost(cityInfo.civInfo) diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 4069b767..b8f75226 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -17,6 +17,7 @@ import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeType import com.unciv.models.ruleset.tile.ResourceSupplyList import com.unciv.models.ruleset.tile.ResourceType +import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.stats.Stats import com.unciv.ui.utils.withoutItem import java.util.* @@ -582,5 +583,18 @@ class CityInfo { for(otherCiv in civsWithCloseCities) otherCiv.getDiplomacyManager(civInfo).setFlag(DiplomacyFlags.SettledCitiesNearUs,30) } + + fun canPurchase(construction : IConstruction) : Boolean { + if (construction is BaseUnit) + { + val tile = getCenterTile() + if (construction.unitType.isCivilian()) + return tile.civilianUnit == null + if (construction.unitType.isAirUnit()) + return tile.airUnits.filter { !it.isTransported }.size < 6 + else return tile.militaryUnit == null + } + return true + } //endregion } diff --git a/core/src/com/unciv/logic/city/IConstruction.kt b/core/src/com/unciv/logic/city/IConstruction.kt index e6e216a9..391120fd 100644 --- a/core/src/com/unciv/logic/city/IConstruction.kt +++ b/core/src/com/unciv/logic/city/IConstruction.kt @@ -10,7 +10,7 @@ interface IConstruction : INamed { fun getGoldCost(civInfo: CivilizationInfo): Int fun isBuildable(construction: CityConstructions): Boolean fun shouldBeDisplayed(construction: CityConstructions): Boolean - fun postBuildEvent(construction: CityConstructions): Boolean // Yes I'm hilarious. + fun postBuildEvent(construction: CityConstructions, wasBought: Boolean = false): Boolean // Yes I'm hilarious. fun canBePurchased(): Boolean } @@ -61,7 +61,7 @@ open class SpecialConstruction(override var name: String, val description: Strin throw Exception("Impossible!") } - override fun postBuildEvent(construction: CityConstructions): Boolean { + override fun postBuildEvent(construction: CityConstructions, wasBought: Boolean): Boolean { throw Exception("Impossible!") } diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index 2c360550..50614203 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -338,7 +338,7 @@ class Building : NamedStats(), IConstruction{ return getRejectionReason(construction)=="" } - override fun postBuildEvent(construction: CityConstructions): Boolean { + override fun postBuildEvent(construction: CityConstructions, wasBought: Boolean): Boolean { val civInfo = construction.cityInfo.civInfo if ("Spaceship part" in uniques) { diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index c0a42887..b2bd555f 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -151,7 +151,7 @@ class BaseUnit : INamed, IConstruction { return getRejectionReason(construction) == "" } - override fun postBuildEvent(construction: CityConstructions): Boolean { + override fun postBuildEvent(construction: CityConstructions, wasBought: Boolean): Boolean { val unit = construction.cityInfo.civInfo.placeUnitNearTile(construction.cityInfo.location, name) if(unit==null) return false // couldn't place the unit, so there's actually no unit =( @@ -165,6 +165,10 @@ class BaseUnit : INamed, IConstruction { && construction.cityInfo.containsBuildingUnique("All newly-trained melee, mounted, and armored units in this city receive the Drill I promotion")) unit.promotions.addPromotion("Drill I", isFree = true) + //movement penalty + if(!unit.hasUnique("Can move directly once bought") && wasBought) + unit.currentMovement = 0f + return true } diff --git a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt index 30549570..71177097 100644 --- a/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/ConstructionsTable.kt @@ -306,7 +306,9 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre if (construction == null || !construction.canBePurchased() || !construction.isBuildable(cityConstructions) || !UncivGame.Current.worldScreen.isPlayersTurn - || city.isPuppet || city.isInResistance()) { + || city.isPuppet || city.isInResistance() + || !city.canPurchase(construction) + ) { button.setText("Buy".tr()) button.disable() } else {