mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 19:43:13 -04:00
Add Transform Action for mods (#8120)
* Initial version of code * Enable cost=0 for buttons * Add Conditional to Transform * Fix translation file * Add icon Allow other Conditionals * Updated icon * Add credit * switch hotkey * Fix icon * Remove Conditional Costs * Remove vestigal Stats costs for Transform * Minor cleanup
This commit is contained in:
parent
9fee185f5d
commit
22f9936a34
BIN
android/Images.Construction/UnitActionIcons/Transform.png
Normal file
BIN
android/Images.Construction/UnitActionIcons/Transform.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 159 KiB |
@ -946,6 +946,8 @@ Add in capital =
|
|||||||
Add to [comment] =
|
Add to [comment] =
|
||||||
Upgrade to [unitType] ([goldCost] gold) =
|
Upgrade to [unitType] ([goldCost] gold) =
|
||||||
Upgrade to [unitType]\n([goldCost] gold, [resources]) =
|
Upgrade to [unitType]\n([goldCost] gold, [resources]) =
|
||||||
|
Transform to [unitType] =
|
||||||
|
Transform to [unitType]\n([resources]) =
|
||||||
Found city =
|
Found city =
|
||||||
Promote =
|
Promote =
|
||||||
Health =
|
Health =
|
||||||
@ -1330,6 +1332,7 @@ Can upgrade from [unit] =
|
|||||||
Can upgrade from: =
|
Can upgrade from: =
|
||||||
Upgrades to [upgradedUnit] =
|
Upgrades to [upgradedUnit] =
|
||||||
Obsolete with [obsoleteTech] =
|
Obsolete with [obsoleteTech] =
|
||||||
|
Can Transform to [upgradedUnit] =
|
||||||
Occurs on [listOfTerrains] =
|
Occurs on [listOfTerrains] =
|
||||||
Occurs on: =
|
Occurs on: =
|
||||||
Placed on [terrainType] =
|
Placed on [terrainType] =
|
||||||
|
@ -1235,7 +1235,7 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
|
|||||||
Stat.Culture -> policies.storedCulture
|
Stat.Culture -> policies.storedCulture
|
||||||
Stat.Science -> {
|
Stat.Science -> {
|
||||||
if (tech.currentTechnology() == null) 0
|
if (tech.currentTechnology() == null) 0
|
||||||
else tech.remainingScienceToTech(tech.currentTechnology()!!.name)
|
else tech.researchOfTech(tech.currentTechnology()!!.name)
|
||||||
}
|
}
|
||||||
Stat.Gold -> gold
|
Stat.Gold -> gold
|
||||||
Stat.Faith -> religionManager.storedFaith
|
Stat.Faith -> religionManager.storedFaith
|
||||||
|
@ -83,6 +83,8 @@ enum class UnitActionType(
|
|||||||
{ ImageGetter.getUnitActionPortrait("Promote") }, 'o', false, UncivSound.Promote),
|
{ ImageGetter.getUnitActionPortrait("Promote") }, 'o', false, UncivSound.Promote),
|
||||||
Upgrade("Upgrade",
|
Upgrade("Upgrade",
|
||||||
{ ImageGetter.getUnitActionPortrait("Upgrade") }, 'u', UncivSound.Upgrade),
|
{ ImageGetter.getUnitActionPortrait("Upgrade") }, 'u', UncivSound.Upgrade),
|
||||||
|
Transform("Transform",
|
||||||
|
{ ImageGetter.getUnitActionPortrait("Transform") }, 'k', UncivSound.Upgrade),
|
||||||
Pillage("Pillage",
|
Pillage("Pillage",
|
||||||
{ ImageGetter.getUnitActionPortrait("Pillage") }, 'p', false),
|
{ ImageGetter.getUnitActionPortrait("Pillage") }, 'p', false),
|
||||||
Paradrop("Paradrop",
|
Paradrop("Paradrop",
|
||||||
|
@ -480,7 +480,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
|||||||
CanHurryResearch("Can hurry technology research", UniqueTarget.Unit),
|
CanHurryResearch("Can hurry technology research", UniqueTarget.Unit),
|
||||||
CanTradeWithCityStateForGoldAndInfluence("Can undertake a trade mission with City-State, giving a large sum of gold and [amount] Influence", UniqueTarget.Unit),
|
CanTradeWithCityStateForGoldAndInfluence("Can undertake a trade mission with City-State, giving a large sum of gold and [amount] Influence", UniqueTarget.Unit),
|
||||||
|
|
||||||
|
CanTransform("Can transform to [unit]", UniqueTarget.Unit),
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import com.unciv.models.UncivSound
|
|||||||
import com.unciv.models.UnitAction
|
import com.unciv.models.UnitAction
|
||||||
import com.unciv.models.UnitActionType
|
import com.unciv.models.UnitActionType
|
||||||
import com.unciv.models.ruleset.Building
|
import com.unciv.models.ruleset.Building
|
||||||
|
import com.unciv.models.ruleset.unique.StateForConditionals
|
||||||
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
import com.unciv.models.stats.Stat
|
import com.unciv.models.stats.Stat
|
||||||
@ -57,6 +58,7 @@ object UnitActions {
|
|||||||
|
|
||||||
addPromoteAction(unit, actionList)
|
addPromoteAction(unit, actionList)
|
||||||
addUnitUpgradeAction(unit, actionList)
|
addUnitUpgradeAction(unit, actionList)
|
||||||
|
addTransformAction(unit, actionList)
|
||||||
addPillageAction(unit, actionList, worldScreen)
|
addPillageAction(unit, actionList, worldScreen)
|
||||||
addParadropAction(unit, actionList)
|
addParadropAction(unit, actionList)
|
||||||
addAirSweepAction(unit, actionList)
|
addAirSweepAction(unit, actionList)
|
||||||
@ -472,6 +474,70 @@ object UnitActions {
|
|||||||
fun getAncientRuinsUpgradeAction(unit: MapUnit) =
|
fun getAncientRuinsUpgradeAction(unit: MapUnit) =
|
||||||
getUpgradeAction(unit, isFree = true, isSpecial = true)
|
getUpgradeAction(unit, isFree = true, isSpecial = true)
|
||||||
|
|
||||||
|
private fun addTransformAction(
|
||||||
|
unit: MapUnit,
|
||||||
|
actionList: ArrayList<UnitAction>,
|
||||||
|
maxSteps: Int = Int.MAX_VALUE
|
||||||
|
) {
|
||||||
|
val upgradeAction = getTransformAction(unit)
|
||||||
|
if (upgradeAction != null) actionList += upgradeAction
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
private fun getTransformAction(
|
||||||
|
unit: MapUnit
|
||||||
|
): ArrayList<UnitAction>? {
|
||||||
|
if (!unit.baseUnit().hasUnique(UniqueType.CanTransform)) return null // can't upgrade to anything
|
||||||
|
val unitTile = unit.getTile()
|
||||||
|
val civInfo = unit.civInfo
|
||||||
|
val transformList = ArrayList<UnitAction>()
|
||||||
|
for (unique in unit.baseUnit().getMatchingUniques(UniqueType.CanTransform,
|
||||||
|
StateForConditionals(unit = unit, civInfo = civInfo, tile = unitTile))) {
|
||||||
|
val upgradedUnit = civInfo.getEquivalentUnit(unique.params[0])
|
||||||
|
// don't show if haven't researched/is obsolete
|
||||||
|
if (!unit.canUpgrade(unitToUpgradeTo = upgradedUnit)) continue
|
||||||
|
|
||||||
|
// Check _new_ resource requirements
|
||||||
|
// Using Counter to aggregate is a bit exaggerated, but - respect the mad modder.
|
||||||
|
val resourceRequirementsDelta = Counter<String>()
|
||||||
|
for ((resource, amount) in unit.baseUnit().getResourceRequirements())
|
||||||
|
resourceRequirementsDelta.add(resource, -amount)
|
||||||
|
for ((resource, amount) in upgradedUnit.getResourceRequirements())
|
||||||
|
resourceRequirementsDelta.add(resource, amount)
|
||||||
|
val newResourceRequirementsString = resourceRequirementsDelta.entries
|
||||||
|
.filter { it.value > 0 }
|
||||||
|
.joinToString { "${it.value} {${it.key}}".tr() }
|
||||||
|
|
||||||
|
val title = if (newResourceRequirementsString.isEmpty())
|
||||||
|
"Transform to [${upgradedUnit.name}]"
|
||||||
|
else "Transform to [${upgradedUnit.name}]\n([$newResourceRequirementsString])"
|
||||||
|
|
||||||
|
transformList.add(UnitAction(UnitActionType.Transform,
|
||||||
|
title = title,
|
||||||
|
action = {
|
||||||
|
unit.destroy()
|
||||||
|
val newUnit = civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)
|
||||||
|
|
||||||
|
/** We were UNABLE to place the new unit, which means that the unit failed to upgrade!
|
||||||
|
* The only known cause of this currently is "land units upgrading to water units" which fail to be placed.
|
||||||
|
*/
|
||||||
|
if (newUnit == null) {
|
||||||
|
val resurrectedUnit = civInfo.placeUnitNearTile(unitTile.position, unit.name)!!
|
||||||
|
unit.copyStatisticsTo(resurrectedUnit)
|
||||||
|
} else { // Managed to upgrade
|
||||||
|
unit.copyStatisticsTo(newUnit)
|
||||||
|
newUnit.currentMovement = 0f
|
||||||
|
}
|
||||||
|
}.takeIf {
|
||||||
|
unit.currentMovement > 0
|
||||||
|
&& !unit.isEmbarked()
|
||||||
|
&& unit.canUpgrade(unitToUpgradeTo = upgradedUnit)
|
||||||
|
}
|
||||||
|
) )
|
||||||
|
}
|
||||||
|
return transformList
|
||||||
|
}
|
||||||
|
|
||||||
private fun addBuildingImprovementsAction(unit: MapUnit, actionList: ArrayList<UnitAction>, tile: TileInfo, worldScreen: WorldScreen, unitTable: UnitTable) {
|
private fun addBuildingImprovementsAction(unit: MapUnit, actionList: ArrayList<UnitAction>, tile: TileInfo, worldScreen: WorldScreen, unitTable: UnitTable) {
|
||||||
if (!unit.hasUniqueToBuildImprovements) return
|
if (!unit.hasUniqueToBuildImprovements) return
|
||||||
if (unit.isEmbarked()) return
|
if (unit.isEmbarked()) return
|
||||||
|
@ -768,6 +768,7 @@ Unless otherwise specified, all the following are from [the Noun Project](https:
|
|||||||
- [Trade](https://www.flaticon.com/free-icon/trade_4257019) created by Smashicons for Conduct Trade Mission
|
- [Trade](https://www.flaticon.com/free-icon/trade_4257019) created by Smashicons for Conduct Trade Mission
|
||||||
- [Nothing](https://www.flaticon.com/free-icon/nothing_5084125) created by Freepik for Nothing construction process
|
- [Nothing](https://www.flaticon.com/free-icon/nothing_5084125) created by Freepik for Nothing construction process
|
||||||
- Icon for Unique created by [vegeta1k95](https://github.com/vegeta1k95)
|
- Icon for Unique created by [vegeta1k95](https://github.com/vegeta1k95)
|
||||||
|
- [Transform] created by letstalkaboutdune
|
||||||
|
|
||||||
### Main menu
|
### Main menu
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user