mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 10:49:17 +07:00
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 <yairm210@hotmail.com>
This commit is contained in:
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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!")
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user