mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
Update auto save promotions (#13045)
* Settler settle best tile when not escort and dangerous Tiles instead of running away Settler unit will now settle on best tile in dangerous Tiles without escort instead of running away. * Update WorkerAutomation.kt * Update SpecificUnitAutomation.kt * Update WorkerAutomation.kt * Update SpecificUnitAutomation.kt * Now city states get mad when you steal their Lands * new version * change to getDiplomacyManagerOrMeet * added text to template.properties and changed AlertPopup.kt * Update template.properties * with period at the end :b * add flag now * Made Option to declare war when a city state is bullied unavailable * added option to change the Maximum Autosave turns stored * remove print * change letter * should fix issue with building test * update with changes * Added UniqueType.FoundPuppetCity with "Founds a new puppet city" in "uniques" of an unit in Units.json. Making it so you can now settle a puppet city. * Added save promotion * Updated for PR * Updated with requested changes * Removed unnecessary check * updated PR * Update PromotionPickerScreen.kt to save promotion cells too * change name and added ! * updated name of variable * updated version from unitType to BaseUnit * updated variable name * Added unitType to reduce the xp cost of promotions for all units in a civ This was a unique type that the Zulu have in civ 5 * updated name * remove UniqueTarget.FollowerBelief * Experience from to XP * fix ? * XP * change it back to Experience because it didn't want to build on git :( * back to XP then * update auto promotion and fix negative XP on unit * Fix build issues and remove the XPForPromotionModifier from xpForNextPromotion and xpForNextNPromotions * remove XPForPromotionModifier * re added Statuses and remove duplicate comment * remove some white space and 1 used import "com.unciv.ui.components.extensions.toPercent" * remove unique from uniques.md * update * update to auto promotion. * Change comments * fix misspelling. * now removed auto promotion from city when moved * Now applying auto promotion in a using promotion tree Node * Remove sorted function and fix negative properly.
This commit is contained in:
parent
6c351fbae6
commit
a4464f5628
@ -33,6 +33,7 @@ import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.components.fonts.Fonts
|
||||
import com.unciv.ui.screens.civilopediascreen.CivilopediaCategories
|
||||
import com.unciv.ui.screens.civilopediascreen.FormattedLine
|
||||
import com.unciv.ui.screens.pickerscreens.PromotionTree
|
||||
import com.unciv.utils.withItem
|
||||
import com.unciv.utils.withoutItem
|
||||
import kotlin.math.ceil
|
||||
@ -465,17 +466,33 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
unit = construction.construct(this, null)
|
||||
?: return false // unable to place unit
|
||||
|
||||
// checking if it's true that we should load saved promotion for the unitType
|
||||
// Check if the player want to rebuild the unit the saved promotion
|
||||
// and null check.
|
||||
// and finally check if the current unit has enough XP.
|
||||
/* check if it's true that we should load saved promotion for the unitType,
|
||||
Then check if the player want to rebuild the unit the saved promotion,
|
||||
and do a null check.
|
||||
and finally check if the current unit has enough XP. */
|
||||
val possiblePromotions = hashSetOf<String>()
|
||||
|
||||
// to get promotion in order from nodes
|
||||
val prmotionTreeOrder = mutableSetOf<String>()
|
||||
|
||||
/* Added all the possible Prmotion that the unit can be promoted,
|
||||
to avoid edge case where upgrading a scout to spearman
|
||||
whould give the rest of the spearman the "ignore terrain cost" promotion
|
||||
when built with auto promotion. */
|
||||
for (promotion in PromotionTree(unit).possiblePromotions) possiblePromotions.add(promotion.name)
|
||||
for (roots in PromotionTree(unit).allNodes()) prmotionTreeOrder.add(roots.promotion.name)
|
||||
|
||||
val savedPromotion = city.unitToPromotions[unit.baseUnit.name]
|
||||
|
||||
if (city.unitShouldUseSavedPromotion[unit.baseUnit.name] == true &&
|
||||
savedPromotion != null && unit.promotions.XP >= savedPromotion.XP) {
|
||||
// sorting it to avoid getting Accuracy III before Accuracy I
|
||||
for (promotions in savedPromotion.promotions.sorted()) {
|
||||
if (unit.promotions.XP >= savedPromotion.XP) {
|
||||
unit.promotions.addPromotion(promotions)
|
||||
// this variable is the filted promotion from savedPrmotion to only get promotion that are possible for this unit.
|
||||
val possiblePromotionFilted = savedPromotion.promotions.filter { it in possiblePromotions }
|
||||
// sort in order to avoid getting Accuracy III before Accuracy I
|
||||
for (promotions in prmotionTreeOrder) {
|
||||
// check if here is enough XP for the next promotion
|
||||
if (unit.promotions.XP-unit.promotions.xpForNextPromotion() >= 0) {
|
||||
if (promotions in possiblePromotionFilted) unit.promotions.addPromotion(promotions)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.unciv.logic.civilization.NotificationCategory
|
||||
import com.unciv.logic.civilization.NotificationIcon
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||
import com.unciv.logic.map.mapunit.UnitPromotions
|
||||
import com.unciv.logic.trade.TradeLogic
|
||||
import com.unciv.logic.trade.TradeOffer
|
||||
import com.unciv.logic.trade.TradeOfferType
|
||||
@ -49,6 +50,11 @@ class CityConquestFunctions(val city: City) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeAutoPromotion() {
|
||||
city.unitShouldUseSavedPromotion = HashMap<String, Boolean>()
|
||||
city.unitToPromotions = HashMap<String, UnitPromotions>()
|
||||
}
|
||||
|
||||
private fun removeBuildingsOnMoveToCiv() {
|
||||
// Remove all buildings provided for free to this city
|
||||
// At this point, the city has *not* yet moved to the new civ
|
||||
@ -276,6 +282,9 @@ class CityConquestFunctions(val city: City) {
|
||||
// Remove their free buildings from this city and remove free buildings provided by the city from their cities
|
||||
removeBuildingsOnMoveToCiv()
|
||||
|
||||
// Remove auto promotion from city that is being moved
|
||||
removeAutoPromotion()
|
||||
|
||||
// catch-all - should ideally not happen as we catch the individual cases with an appropriate notification
|
||||
city.espionage.removeAllPresentSpies(SpyFleeReason.Other)
|
||||
|
||||
|
@ -200,7 +200,11 @@ class PromotionPickerScreen private constructor(
|
||||
// adds the checkBoxs to choice to save unit promotion.
|
||||
private fun saveUnitTypePromotionForCity() {
|
||||
// if you are not in a city tile then don't show up
|
||||
if (unit.currentTile.getCity() == null) return
|
||||
// then player should not be able to save promotion in enermy tiles/puppet citys
|
||||
// even their own because you can't build any unit there.
|
||||
val currentCity = unit.currentTile.getCity() ?: return
|
||||
if (currentCity.civ.civName != unit.civ.civName) return
|
||||
if (currentCity.isPuppet) return
|
||||
val checkBoxSaveUnitPromotion = "Default promotions for [${unit.baseUnit.name}]".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it}
|
||||
promotionsTable.add(checkBoxSaveUnitPromotion)
|
||||
}
|
||||
@ -208,7 +212,6 @@ class PromotionPickerScreen private constructor(
|
||||
// going to reuse this bit of code 2 time so turn it into a funtion
|
||||
private fun checkSaveUnitTypePrormotion() {
|
||||
if (!saveUnitTypePromotion) return
|
||||
|
||||
val unitCurrentCity = unit.currentTile.getCity()
|
||||
if (unitCurrentCity != null) {
|
||||
// If you are clicked the save baseUnit promotion, you want the next baseUnit to have the same promotion.
|
||||
|
Loading…
x
Reference in New Issue
Block a user