From 1f5eb1ea3ef15cec458020912fb46f2a76d2375d Mon Sep 17 00:00:00 2001 From: Blank_Alt <12406-Blank_Alt@users.noreply.gitgud.io> Date: Fri, 11 Dec 2020 12:03:43 -0800 Subject: [PATCH] Sec exp backport units --- js/003-data/gameVariableData.js | 19 - sanityCheck.sh | 2 +- src/002-config/fc-version.js | 2 +- .../SecExp/SecExpBackwardCompatibility.tw | 4 - src/Mods/SecExp/attackHandler.tw | 16 +- src/Mods/SecExp/attackOptions.tw | 68 +- src/Mods/SecExp/attackReport.tw | 12 +- src/Mods/SecExp/buildings/secBarracks.tw | 224 +++--- .../SecExp/buildings/weaponsManufacturing.tw | 4 +- src/Mods/SecExp/js/Unit.js | 681 ++++++++++-------- src/Mods/SecExp/js/secExp.js | 99 +-- src/Mods/SecExp/js/secExpBC.js | 80 +- src/Mods/SecExp/js/securityReport.js | 18 +- src/Mods/SecExp/miscSecExpWidgets.tw | 111 --- src/Mods/SecExp/rebellionHandler.tw | 42 +- src/Mods/SecExp/rebellionOptions.tw | 65 +- src/Mods/SecExp/unitsBattleReport.tw | 154 ++-- src/Mods/SecExp/unitsRebellionReport.tw | 268 +++---- src/Mods/SpecialForce/SpecialForce.js | 2 +- .../backwardsCompatibility.js | 11 +- src/endWeek/nextWeek/nextWeek.js | 5 +- src/events/intro/initNationalities.js | 5 +- src/gui/options/optionsPassage.js | 20 +- src/js/economyJS.js | 34 +- src/uncategorized/manageArcology.tw | 4 +- src/uncategorized/pMercenaries.tw | 4 +- src/uncategorized/scheduledEvent.tw | 4 +- 27 files changed, 883 insertions(+), 1075 deletions(-) delete mode 100644 src/Mods/SecExp/SecExpBackwardCompatibility.tw delete mode 100644 src/Mods/SecExp/miscSecExpWidgets.tw diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index f4ffc5d9e72..4a221c0c40c 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -378,28 +378,9 @@ App.Data.resetOnNGPlus = { repairTime: 3, arcRepairTime: 0, garrison: {}, - /* armed forces stats */ - militiaFreeManpower: 0, - militiaTotalCasualties: 0, - slavesTotalCasualties: 0, - mercFreeManpower: 0, - mercTotalCasualties: 0, - createdSlavesUnits: 0, - createdMilitiaUnits: 0, - createdMercUnits: 0, /* battle relevant vars */ attackThisWeek: 0, majorBattle: 0, - /* units */ - /** @type {FC.SecExp.PlayerUnitData} */ - secBots: {}, - /** @type {FC.SecExp.PlayerHumanUnitData[]} */ - militiaUnits: [], - /** @type {FC.SecExp.PlayerHumanUnitData[]} */ - slaveUnits: [], - /** @type {FC.SecExp.PlayerHumanUnitData[]} */ - mercUnits: [], - /* base vars */ SecExp: {}, reminderEntry: "", diff --git a/sanityCheck.sh b/sanityCheck.sh index 432ed76ab3a..cbe5b51291d 100755 --- a/sanityCheck.sh +++ b/sanityCheck.sh @@ -40,7 +40,7 @@ $GREP -e "<<.*[(][^<>)]*[(][^<>)]*)\?[^<>)]*>>" -- "src/*" | myprint "MissingClo # Check for too many >>>. e.g.: <</if>>> $GREP "<<[^<>]*[<>]\?[^<>]*>>>" -- "src/*.tw" | myprint "TooManyAngleBrackets" # Check for wrong capitalization on 'activeslave' and other common typos -$GREP -e "\$act" --and --not -e "\$\(activeSlave\|activeChild\|activeArcology\|activeOrgan\|activeLimbs\|activeUnits\|activeLurcher\|active.\)" -- "src/*" | myprint "WrongCapitalization" +$GREP -e "\$act" --and --not -e "\$\(activeSlave\|activeChild\|activeArcology\|activeOrgan\|activeLimbs\|activeLurcher\|active.\)" -- "src/*" | myprint "WrongCapitalization" # Check for strange spaces e.g. $slaves[$i]. lips $GREP "\$slaves\[\$i\]\. " -- 'src/*' | myprint "MissingPropertyAfterSlaves" # Check using refreshmentType instead of refreshment diff --git a/src/002-config/fc-version.js b/src/002-config/fc-version.js index 94bbfb53d28..443b6ae4e3d 100644 --- a/src/002-config/fc-version.js +++ b/src/002-config/fc-version.js @@ -2,5 +2,5 @@ App.Version = { base: "0.10.7.1", // The vanilla version the mod is based off of, this should never be changed. pmod: "3.8.2", commitHash: null, - release: 1111 // When getting close to 2000, please remove the check located within the onLoad() function defined at line five of src/js/eventHandlers.js. + release: 1112 // When getting close to 2000, please remove the check located within the onLoad() function defined at line five of src/js/eventHandlers.js. }; diff --git a/src/Mods/SecExp/SecExpBackwardCompatibility.tw b/src/Mods/SecExp/SecExpBackwardCompatibility.tw deleted file mode 100644 index e0d720c1eb0..00000000000 --- a/src/Mods/SecExp/SecExpBackwardCompatibility.tw +++ /dev/null @@ -1,4 +0,0 @@ -:: SecExpBackwardCompatibility [nobr] - -<<run App.SecExp.generalBC()>> /* base stats */ -<<fixBrokenStats>> /* recalculation widgets */ \ No newline at end of file diff --git a/src/Mods/SecExp/attackHandler.tw b/src/Mods/SecExp/attackHandler.tw index 38c12b64779..2bca99e2995 100644 --- a/src/Mods/SecExp/attackHandler.tw +++ b/src/Mods/SecExp/attackHandler.tw @@ -820,24 +820,24 @@ <<set _defense += _unit.defense * _defMod>> <<set _hp += _unit.hp>> <</if>> - <<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $militiaUnits[_i].isDeployed == 1>> + <<for _i = 0; _i < $SecExp.units.militia.squads.length; _i++>> + <<if $SecExp.units.militia.squads[_i].isDeployed == 1>> <<set _unit = App.SecExp.getUnit("Militia", _i)>> <<set _attack += _unit.attack * _atkMod>> <<set _defense += _unit.defense * _defMod>> <<set _hp += _unit.hp>> <</if>> <</for>> - <<for _i = 0; _i < $slaveUnits.length; _i++>> - <<if $slaveUnits[_i].isDeployed == 1>> + <<for _i = 0; _i < $SecExp.units.slaves.squads.length; _i++>> + <<if $SecExp.units.slaves.squads[_i].isDeployed == 1>> <<set _unit = App.SecExp.getUnit("Slaves", _i)>> <<set _attack += _unit.attack * _atkMod>> <<set _defense += _unit.defense * _defMod>> <<set _hp += _unit.hp>> <</if>> <</for>> - <<for _i = 0; _i < $mercUnits.length; _i++>> - <<if $mercUnits[_i].isDeployed == 1>> + <<for _i = 0; _i < $SecExp.units.mercs.squads.length; _i++>> + <<if $SecExp.units.mercs.squads[_i].isDeployed == 1>> <<set _unit = App.SecExp.getUnit("Mercs", _i)>> <<set _attack += _unit.attack * _atkMod>> <<set _defense += _unit.defense * _defMod>> @@ -877,12 +877,12 @@ <<set _moraleTroopMod = Math.clamp(App.SecExp.battle.troopCount() / 100,1,5)>> - <<set _morale = (App.SecExp.BaseDroneUnit.morale * $secBots.isDeployed + App.SecExp.BaseMilitiaUnit.morale * _militiaMod * App.SecExp.battle.deployedUnits('militia') + App.SecExp.BaseSlaveUnit.morale * _slaveMod * App.SecExp.battle.deployedUnits('slaves') + App.SecExp.BaseMercUnit.morale * _mercMod * App.SecExp.battle.deployedUnits('mercs') + App.SecExp.BaseSpecialForcesUnit.morale * $SecExp.war.deploySF * _SFMod) / ($secBots.isDeployed + App.SecExp.battle.deployedUnits('militia') + App.SecExp.battle.deployedUnits('slaves') + App.SecExp.battle.deployedUnits('mercs') + $SecExp.war.deploySF)>> + <<set _morale = (App.SecExp.BaseDroneUnit.morale * $SecExp.units.bots.isDeployed + App.SecExp.BaseMilitiaUnit.morale * _militiaMod * App.SecExp.battle.deployedUnits('militia') + App.SecExp.BaseSlaveUnit.morale * _slaveMod * App.SecExp.battle.deployedUnits('slaves') + App.SecExp.BaseMercUnit.morale * _mercMod * App.SecExp.battle.deployedUnits('mercs') + App.SecExp.BaseSpecialForcesUnit.morale * $SecExp.war.deploySF * _SFMod) / ($SecExp.units.bots.isDeployed + App.SecExp.battle.deployedUnits('militia') + App.SecExp.battle.deployedUnits('slaves') + App.SecExp.battle.deployedUnits('mercs') + $SecExp.war.deploySF)>> <<if $SecExp.buildings.barracks>> <<set _morale = _morale + _morale * $SecExp.buildings.barracks.luxury * 0.05>> /* barracks bonus */ <</if>> <<set _morale *= _moraleTroopMod>> - <<set _baseHp = (App.SecExp.BaseDroneUnit.hp * $secBots.isDeployed + App.SecExp.BaseMilitiaUnit.hp * App.SecExp.battle.deployedUnits('militia') + App.SecExp.BaseSlaveUnit.hp * App.SecExp.battle.deployedUnits('slaves') + App.SecExp.BaseMercUnit.hp * App.SecExp.battle.deployedUnits('mercs') + App.SecExp.BaseSpecialForcesUnit.hp * $SecExp.war.deploySF) / ($secBots.isDeployed + App.SecExp.battle.deployedUnits('militia') + App.SecExp.battle.deployedUnits('slaves') + App.SecExp.battle.deployedUnits('mercs') + $SecExp.war.deploySF)>> + <<set _baseHp = (App.SecExp.BaseDroneUnit.hp * $SecExp.units.bots.isDeployed + App.SecExp.BaseMilitiaUnit.hp * App.SecExp.battle.deployedUnits('militia') + App.SecExp.BaseSlaveUnit.hp * App.SecExp.battle.deployedUnits('slaves') + App.SecExp.BaseMercUnit.hp * App.SecExp.battle.deployedUnits('mercs') + App.SecExp.BaseSpecialForcesUnit.hp * $SecExp.war.deploySF) / ($SecExp.units.bots.isDeployed + App.SecExp.battle.deployedUnits('militia') + App.SecExp.battle.deployedUnits('slaves') + App.SecExp.battle.deployedUnits('mercs') + $SecExp.war.deploySF)>> /* calculates enemy army stats */ <<if $week <= 30>> diff --git a/src/Mods/SecExp/attackOptions.tw b/src/Mods/SecExp/attackOptions.tw index 8c358d9abc9..2cea6dd306e 100644 --- a/src/Mods/SecExp/attackOptions.tw +++ b/src/Mods/SecExp/attackOptions.tw @@ -93,7 +93,7 @@ <br>Old world expeditions are usually sent to secure resources and trade routes for their nation or, more often, to provide their citizens with a bogeyman to be scared of. They are usually decently equipped and trained, which together with their generous numbers make them a tough nut to crack. However, they often lack in mobility. <</if>> <</if>> -<br><br>__Recon__: +<br><br>__Recon__: (AO: $terrain) <<set _estimatedMen = $SecExp.war.estimatedMen>> <<set _expectedEquip = $SecExp.war.expectedEquip>> <br>It seems your troops and your adversary will fight @@ -241,23 +241,11 @@ approximately <strong>_estimatedMen men</strong> are coming, they seem to be <<link "Restore saved roster" "attackOptions">> <<for _i = 0; _i < $SecExp.battles.lastSelection.length; _i++>> <<if $SecExp.battles.lastSelection[_i] == -1>> - <<set $secBots.isDeployed = 1>> + <<set $SecExp.units.bots.isDeployed = 1>> <<else>> - <<for _unit range $militiaUnits>> - <<if $SecExp.battles.lastSelection[_i] === _unit.ID>> - <<set _unit.isDeployed = 1>> - <<break>> - <</if>> - <</for>> - <<for _unit range $slaveUnits>> - <<if $SecExp.battles.lastSelection[_i] === _unit.ID>> - <<set _unit.isDeployed = 1>> - <<break>> - <</if>> - <</for>> - <<for _unit range $mercUnits>> - <<if $SecExp.battles.lastSelection[_i] === _unit.ID>> - <<set _unit.isDeployed = 1>> + <<for _squad range App.SecExp.unit.humanSquads()>> + <<if $SecExp.battles.lastSelection[_i] === _squad.ID>> + <<set _squad.isDeployed = 1>> <<break>> <</if>> <</for>> @@ -275,19 +263,9 @@ approximately <strong>_estimatedMen men</strong> are coming, they seem to be <<set _tmp = -1>> <<set $SecExp.battles.lastSelection.push(_tmp)>> <</if>> - <<for _unit range $militiaUnits>> - <<if _unit.isDeployed === 1>> - <<set $SecExp.battles.lastSelection.push(_unit.ID)>> - <</if>> - <</for>> - <<for _unit range $slaveUnits>> - <<if _unit.isDeployed === 1>> - <<set $SecExp.battles.lastSelection.push(_unit.ID)>> - <</if>> - <</for>> - <<for _unit range $mercUnits>> - <<if _unit.isDeployed === 1>> - <<set $SecExp.battles.lastSelection.push(_unit.ID)>> + <<for _squad range App.SecExp.unit.humanSquads()>> + <<if _squad.isDeployed === 1>> + <<set $SecExp.battles.lastSelection.push(_squad.ID)>> <</if>> <</for>> <<set $SecExp.war.saveValid = 1, $SecExp.battles.saved.commander = $SecExp.war.commander, $SecExp.battles.saved.sfSupport = $SecExp.war.deploySF>> @@ -298,15 +276,9 @@ approximately <strong>_estimatedMen men</strong> are coming, they seem to be | <<if App.SecExp.battle.deployedUnits() > 0>> <<link "Clear current roster" "attackOptions">> - <<set $secBots.isDeployed = 0>> - <<for _unit range $militiaUnits>> - <<set _unit.isDeployed = 0>> - <</for>> - <<for _unit range $slaveUnits>> - <<set _unit.isDeployed = 0>> - <</for>> - <<for _unit range $mercUnits>> - <<set _unit.isDeployed = 0>> + <<set $SecExp.units.bots.isDeployed = 0>> + <<for _squad range App.SecExp.unit.humanSquads()>> + <<set _squad.isDeployed = 0>> <</for>> <<set $SecExp.war.saveValid = 0>> <</link>> @@ -324,15 +296,15 @@ approximately <strong>_estimatedMen men</strong> are coming, they seem to be <<if App.SecExp.battle.deployableUnits() > 0>> With your current readiness level you can send an additional <strong><<print App.SecExp.battle.deployableUnits()>></strong> units. <</if>> -<<replenishAllUnits>> -<<set _mL = $militiaUnits.length>> -<<set _sL = $slaveUnits.length>> -<<set _meL = $mercUnits.length>> +<<includeDOM App.SecExp.unit.replenishAll()>> +<<set _mL = $SecExp.units.militia.squads.length>> +<<set _sL = $SecExp.units.slaves.squads.length>> +<<set _meL = $SecExp.units.mercs.squads.length>> <<run App.UI.tabBar.handlePreSelectedTab($tabChoice.Options)>> <<if App.SecExp.battle.deployableUnits() === 0>> <strong>Unit roster full.</strong> <</if>> -<br> <<includeDOM App.SecExp.deployUnitMenu($secBots, "bots")>> +<br> <<includeDOM App.SecExp.unit.deployMenu($SecExp.units.bots, "bots")>> <<if _mL > 0>> <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'militia')" id="tab militia">Militia: (_mL)</button> <</if>> @@ -346,21 +318,21 @@ approximately <strong>_estimatedMen men</strong> are coming, they seem to be <div id="militia" class="tab-content"> <div class="content"> <<for _i = 0; _i < _mL; _i++>> - <<includeDOM App.SecExp.deployUnitMenu($militiaUnits[_i], "militia", _i)>> + <<includeDOM App.SecExp.unit.deployMenu($SecExp.units.militia.squads[_i], "militia", _i)>> <</for>> </div> </div> <div id="slaves" class="tab-content"> <div class="content"> <<for _i = 0; _i < _sL; _i++>> - <<includeDOM App.SecExp.deployUnitMenu($slaveUnits[_i], "slaves", _i)>> + <<includeDOM App.SecExp.unit.deployMenu($SecExp.units.slaves.squads[_i], "slaves", _i)>> <</for>> </div> </div> <div id="mercs" class="tab-content"> <div class="content"> <<for _i = 0; _i < _meL; _i++>> - <<includeDOM App.SecExp.deployUnitMenu($mercUnits[_i], "mercs", _i)>> + <<includeDOM App.SecExp.unit.deployMenu($SecExp.units.mercs.squads[_i], "mercs", _i)>> <</for>> </div> -</div> +</div> \ No newline at end of file diff --git a/src/Mods/SecExp/attackReport.tw b/src/Mods/SecExp/attackReport.tw index 066f182b2c1..70533971f5f 100644 --- a/src/Mods/SecExp/attackReport.tw +++ b/src/Mods/SecExp/attackReport.tw @@ -1509,13 +1509,7 @@ /* resets variables */ <<set $attackThisWeek = 0>> <<set $majorBattle = 0>> -<<set $secBots.isDeployed = 0>> -<<for _i = 0; _i < $militiaUnits.length; _i++>> - <<set $militiaUnits[_i].isDeployed = 0>> -<</for>> -<<for _i = 0; _i < $slaveUnits.length; _i++>> - <<set $slaveUnits[_i].isDeployed = 0>> -<</for>> -<<for _i = 0; _i < $mercUnits.length; _i++>> - <<set $mercUnits[_i].isDeployed = 0>> +<<set $SecExp.units.bots.isDeployed = 0>> +<<for _squad range App.SecExp.unit.humanSquads()>> + <<set _squad.isDeployed = 0>> <</for>> \ No newline at end of file diff --git a/src/Mods/SecExp/buildings/secBarracks.tw b/src/Mods/SecExp/buildings/secBarracks.tw index 3b5378c87a2..7a4a5b2b715 100644 --- a/src/Mods/SecExp/buildings/secBarracks.tw +++ b/src/Mods/SecExp/buildings/secBarracks.tw @@ -133,7 +133,7 @@ While this a sore sight for many citizens of $arcologies[0].name, the barracks s <</if>> <hr>__Units__<br> -Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> (<<print num($secBots.maxTroops+(50*App.SecExp.battle.maxUnits()))>> troops), <<print App.SecExp.battle.activeUnits()>> (<<print num($secBots.troops+App.SecExp.Manpower.employedOverall)>> troops) are active and <<print (2 * App.SecExp.battle.deploySpeed())>> units can be deployed. <<if $SecExp.buildings.barracks.luxury > 0>>The barracks provides <<print $SecExp.buildings.barracks.luxury * 5>>% bonus morale when battle occurs.<</if>> <<if $SecExp.buildings.barracks.training > 0>>The training facility will increase the effectiveness of your units with time.<</if>> +Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> (<<print num($SecExp.units.bots.maxTroops+(50*App.SecExp.battle.maxUnits()))>> troops), <<print App.SecExp.battle.activeUnits()>> (<<print num($SecExp.units.bots.troops+App.SecExp.Manpower.employedOverall)>> troops) are active and <<print (2 * App.SecExp.battle.deploySpeed())>> units can be deployed. <<if $SecExp.buildings.barracks.luxury > 0>>The barracks provides <<print $SecExp.buildings.barracks.luxury * 5>>% bonus morale when battle occurs.<</if>> <<if $SecExp.buildings.barracks.training > 0>>The training facility will increase the effectiveness of your units with time.<</if>> <br> <<set _options = new App.UI.OptionsGroup()>> <<run _options.addOption("Unit descriptions are", "unitDescriptions", $SecExp.settings) @@ -142,7 +142,7 @@ Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> ( <<if App.SecExp.battle.activeUnits() >= App.SecExp.battle.maxUnits()>> <br>You have reached the maximum number of units. You'll have to disband one or enlarge the barracks before forming a new unit. <</if>> -<<replenishAllUnits>> +<<includeDOM App.SecExp.unit.replenishAll()>> <<if $arcologyUpgrade.drones === 0>> You have not yet installed a drone security system in your arcology, you will not be able to form a unit of drones. @@ -158,51 +158,51 @@ Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> ( <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Bots')" id="tab Bots">Security Drones</button> <</if>> <<if $SecExp.edicts.defense.militia >= 1>> - <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Militia')" id="tab Militia">Militia: ($militiaUnits.length)</button> + <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Militia')" id="tab Militia">Militia: ($SecExp.units.militia.squads.length)</button> <</if>> <<if $mercenaries >= 1>> - <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Mercs')" id="tab Mercs">Mercenaries: ($mercUnits.length)</button> + <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Mercs')" id="tab Mercs">Mercenaries: ($SecExp.units.mercs.squads.length)</button> <</if>> - <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Slaves')" id="tab Slaves">Slaves: ($slaveUnits.length)</button> + <button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Slaves')" id="tab Slaves">Slaves: ($SecExp.units.slaves.squads.length)</button> </div> <<run App.UI.tabBar.handlePreSelectedTab($tabChoice.secBarracks)>> <div id="Bots" class="tab-content"> <div class="content"> <<set _secBotsCost = 500, _secBotsUpgradeCost = 250>> <<= App.SecExp.getUnit("Bots").describe()>> <br> - <<if $secBots.active == 1>> - <<if $secBots.maxTroops > $secBots.troops>> + <<if $SecExp.units.bots.active == 1>> + <<if $SecExp.units.bots.maxTroops > $SecExp.units.bots.troops>> <<link "Replenish the unit" "secBarracks">> - <<run cashX(forceNeg(($secBots.maxTroops - $secBots.troops) * _secBotsCost), "securityExpansion")>> - <<set $secBots.troops = $secBots.maxTroops>> + <<run cashX(forceNeg(($SecExp.units.bots.maxTroops - $SecExp.units.bots.troops) * _secBotsCost), "securityExpansion")>> + <<set $SecExp.units.bots.troops = $SecExp.units.bots.maxTroops>> <</link>> <</if>> - <<if $secBots.maxTroops < 80>> <br> + <<if $SecExp.units.bots.maxTroops < 80>> <br> <<link "Improve the digital control matrix" "secBarracks">> - <<set $secBots.maxTroops += 10>> + <<set $SecExp.units.bots.maxTroops += 10>> <<run cashX(-5000, "securityExpansion")>> <</link>> Invest in the development of more refined controls for your drones to increase the maximum number of drones in the unit. <br>//Costs <<print cashFormat(5000)>> per upgrade and each will increase the max by 10// - <<elseif $SF.Toggle && $SF.Active >= 1 && $secBots.maxTroops < 100 && $SecExp.edicts.SFSupportLevel >= 1>> <br> + <<elseif $SF.Toggle && $SF.Active >= 1 && $SecExp.units.bots.maxTroops < 100 && $SecExp.edicts.SFSupportLevel >= 1>> <br> <<link "Refine the drone network with $SF.Lower assistance" "secBarracks">> - <<set $secBots.maxTroops += 10>> - <<run cashX(forceNeg(5000 + 10 * _secBotsUpgradeCost * $secBots.equip), "securityExpansion")>> + <<set $SecExp.units.bots.maxTroops += 10>> + <<run cashX(forceNeg(5000 + 10 * _secBotsUpgradeCost * $SecExp.units.bots.equip), "securityExpansion")>> <</link>> Utilize the technological developments made by $SF.Lower to further improve the control matrix of the security drones. - <br>//Costs <<print cashFormat(5000 + 10 * _secBotsUpgradeCost * $secBots.equip)>> and will increase the max by 10// + <br>//Costs <<print cashFormat(5000 + 10 * _secBotsUpgradeCost * $SecExp.units.bots.equip)>> and will increase the max by 10// <<elseif $SF.Toggle && $SF.Active >= 1 && $SecExp.edicts.SFSupportLevel === 0>> There's little left to improve in the matrix. However support from $SF.Lower might give some more room from improvement, if an assistance contract is signed. <<else>> There's little left to improve in the matrix. Your control systems are at top capacity and won't be able to handle a bigger drone unit. <</if>> - <<if $secBots.equip < 3>> <br> + <<if $SecExp.units.bots.equip < 3>> <br> <<link "Improve drone weaponry and armor" "secBarracks">> - <<set $secBots.equip += 1>> - <<run cashX(forceNeg((_secBotsUpgradeCost * $secBots.maxTroops) + 1000), "securityExpansion")>> + <<set $SecExp.units.bots.equip += 1>> + <<run cashX(forceNeg((_secBotsUpgradeCost * $SecExp.units.bots.maxTroops) + 1000), "securityExpansion")>> <</link>> Invest in better equipment for your drones to increase their battle effectiveness. - <br>//Costs <<print cashFormat((_secBotsUpgradeCost * $secBots.maxTroops) + 1000)>> and will increase attack and defense value of the unit by 15% for every upgrade.// + <br>//Costs <<print cashFormat((_secBotsUpgradeCost * $SecExp.units.bots.maxTroops) + 1000)>> and will increase attack and defense value of the unit by 15% for every upgrade.// <<else>> <br>Your drones are equipped with top tier weaponry and armor. <</if>> @@ -211,23 +211,23 @@ Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> ( <</if>> <<else>> <<link "Rebuild the unit" "secBarracks">> - <<run cashX(forceNeg(($secBots.maxTroops - $secBots.troops) * _secBotsCost), "securityExpansion")>> - <<set $secBots.troops = $secBots.maxTroops>> - <<set $secBots.active = 1>> + <<run cashX(forceNeg(($SecExp.units.bots.maxTroops - $SecExp.units.bots.troops) * _secBotsUpgradeCost), "securityExpansion")>> + <<set $SecExp.units.bots.troops = $SecExp.units.bots.maxTroops>> + <<set $SecExp.units.bots.active = 1>> <</link>> <</if>> </div> </div> <div id="Slaves" class="tab-content"> <div class="content"> - You are free to organize your menial slaves into fighting units. Currently you have <<print num($menials)>> slaves available, while <<print num(App.SecExp.Manpower.employedSlave)>> are already employed as soldiers. During all your battles you lost a total of <<print num($slavesTotalCasualties)>>. - <br>Default unit name: <<textbox "$SecExp.defaultNames.slaves" $SecExp.defaultNames.slaves "secBarracks">> | - <<if $menials > 0 && App.SecExp.battle.activeUnits() < App.SecExp.battle.maxUnits()>> + You are free to organize your menial slaves into fighting units. Currently you have <<print num($menials)>> slaves available, while <<print num(App.SecExp.Manpower.employedSlave)>> are already employed as soldiers. During all your battles you lost a total of <<print num($SecExp.units.slaves.dead)>>. + <br>Default unit name: <<textbox "$SecExp.units.slaves.defaultName" $SecExp.units.slaves.defaultName "secBarracks">> | + <<if $menials > 0 && App.SecExp.battle.activeUnits() < App.SecExp.battle.maxUnits()>> <<link "Form a new unit" "secBarracks">> - <<set $slaveUnits.push(App.SecExp.generateUnit("slaves"))>> + <<set $SecExp.units.slaves.squads.push(App.SecExp.unit.gen("slaves"))>> <</link>> | <</if>> - <<includeDOM App.SecExp.bulkUpgradeUnit($slaveUnits)>> + <<includeDOM App.SecExp.unit.bulkUpgrade($SecExp.units.slaves.squads)>> <<set _popCap = menialPopCap()>> <<set _menialPrice = menialSlaveCost()>> @@ -249,28 +249,28 @@ Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> ( <</if>> <</if>> <br> - <<set _sL = $slaveUnits.length>> + <<set _sL = $SecExp.units.slaves.squads.length>> <<for _i = 0; _i < _sL; _i++>> <<capture _i>> <<= App.SecExp.getUnit("Slaves", _i).describe()>> <br> - Rename unit <<textbox "$slaveUnits[_i].platoonName" $slaveUnits[_i].platoonName "secBarracks">> + Rename unit <<textbox "$SecExp.units.slaves.squads[_i].platoonName" $SecExp.units.slaves.squads[_i].platoonName "secBarracks">> | <<link "Disband the unit" "secBarracks">> - <<set $menials += $slaveUnits[_i].troops>> - <<set $slaveUnits.deleteAt(_i)>> + <<set $menials += $SecExp.units.slaves.squads[_i].troops>> + <<set $SecExp.units.slaves.squads.deleteAt(_i)>> <</link>> - <<if $slaveUnits[_i].active == 1>> - <<if $slaveUnits[_i].troops < $slaveUnits[_i].maxTroops && $menials > 0>> + <<if $SecExp.units.slaves.squads[_i].active == 1>> + <<if $SecExp.units.slaves.squads[_i].troops < $SecExp.units.slaves.squads[_i].maxTroops && $menials > 0>> | <<link "Replenish unit" "secBarracks">> - <<if $menials >= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>> - <<set $menials -= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>> - <<set _expLoss = ($slaveUnits[_i].maxTroops - $slaveUnits[_i].troops) / $slaveUnits[_i].troops>> - <<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>> - <<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>> + <<if $menials >= $SecExp.units.slaves.squads[_i].maxTroops - $SecExp.units.slaves.squads[_i].troops>> + <<set $menials -= $SecExp.units.slaves.squads[_i].maxTroops - $SecExp.units.slaves.squads[_i].troops>> + <<set _expLoss = ($SecExp.units.slaves.squads[_i].maxTroops - $SecExp.units.slaves.squads[_i].troops) / $SecExp.units.slaves.squads[_i].troops>> + <<set $SecExp.units.slaves.squads[_i].training -= $SecExp.units.slaves.squads[_i].training * _expLoss>> + <<set $SecExp.units.slaves.squads[_i].troops = $SecExp.units.slaves.squads[_i].maxTroops>> <<else>> - <<set _expLoss = $menials / $slaveUnits[_i].troops>> - <<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>> - <<set $slaveUnits[_i].troops += $menials>> + <<set _expLoss = $menials / $SecExp.units.slaves.squads[_i].troops>> + <<set $SecExp.units.slaves.squads[_i].training -= $SecExp.units.slaves.squads[_i].training * _expLoss>> + <<set $SecExp.units.slaves.squads[_i].troops += $menials>> <<set $menials = 0>> <</if>> <</link>> @@ -279,22 +279,22 @@ Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> ( <<if $menials > 0>> | <<link "Reform the unit" "secBarracks">> - <<if $menials >= $slaveUnits[_i].maxTroops>> - <<set $menials -= $slaveUnits[_i].maxTroops>> - <<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>> - <<set $slaveUnits[_i].training = 0>> + <<if $menials >= $SecExp.units.slaves.squads[_i].maxTroops>> + <<set $menials -= $SecExp.units.slaves.squads[_i].maxTroops>> + <<set $SecExp.units.slaves.squads[_i].troops = $SecExp.units.slaves.squads[_i].maxTroops>> + <<set $SecExp.units.slaves.squads[_i].training = 0>> <<else>> - <<set $slaveUnits[_i].troops += $menials>> + <<set $SecExp.units.slaves.squads[_i].troops += $menials>> <<set $menials = 0>> - <<set $slaveUnits[_i].training = 0>> + <<set $SecExp.units.slaves.squads[_i].training = 0>> <</if>> - <<set $slaveUnits[_i].active = 1>> + <<set $SecExp.units.slaves.squads[_i].active = 1>> <</link>> <</if>> <</if>> - | <<includeDOM App.SecExp.bulkUpgradeUnit($slaveUnits[_i])>> + | <<includeDOM App.SecExp.unit.bulkUpgrade($SecExp.units.slaves.squads[_i])>> <<if $SecExp.settings.showStats == 1>> <<= App.SecExp.getUnit("Slaves", _i).printStats()>> <</if>> - <<includeDOM App.SecExp.humanUnitUpgradeList($slaveUnits[_i])>> + <<includeDOM App.SecExp.unit.humanUpgradeList($SecExp.units.slaves.squads[_i])>> <</capture>> <</for>> </div> @@ -311,62 +311,62 @@ Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> ( <<elseif $SecExp.edicts.defense.militia === 5>> With the adoption of a militarized society, your available manpower has swelled to be <<= num(App.SecExp.militiaCap()*100)>>% of the arcology's citizens population. <</if>> - Your current total manpower is <<print num(App.SecExp.Manpower.totalMilitia)>>, of which <<print num(App.SecExp.Manpower.employedMilitia)>> is in active duty. You lost in total <<print num($militiaTotalCasualties)>> citizens, leaving you with <<print num($militiaFreeManpower)>> available citizens. - <br>Default unit name: <<textbox "$SecExp.defaultNames.militia" $SecExp.defaultNames.militia "secBarracks">> | - <<if $militiaFreeManpower > 0 && App.SecExp.battle.activeUnits() < App.SecExp.battle.maxUnits()>> + Your current total manpower is <<print num(App.SecExp.Manpower.totalMilitia)>>, of which <<print num(App.SecExp.Manpower.employedMilitia)>> is in active duty. You lost in total <<print num($SecExp.units.militia.dead)>> citizens, leaving you with <<print num($SecExp.units.militia.free)>> available citizens. + <br>Default unit name: <<textbox "$SecExp.units.militia.defaultName" $SecExp.units.militia.defaultName "secBarracks">> | + <<if $SecExp.units.militia.free > 0 && App.SecExp.battle.activeUnits() < App.SecExp.battle.maxUnits()>> <<link "Form a new unit" "secBarracks">> - <<set $militiaUnits.push(App.SecExp.generateUnit("militia"))>> + <<set $SecExp.units.militia.squads.push(App.SecExp.unit.gen("militia"))>> <</link>> | <</if>> - <<includeDOM App.SecExp.bulkUpgradeUnit($militiaUnits)>> + <<includeDOM App.SecExp.unit.bulkUpgrade($SecExp.units.militia.squads)>> <br> - <<set _mL = $militiaUnits.length>> + <<set _mL = $SecExp.units.militia.squads.length>> <<for _i = 0; _i < _mL; _i++>> <<capture _i>> <<= App.SecExp.getUnit("Militia", _i).describe()>> <br> - Rename unit <<textbox "$militiaUnits[_i].platoonName" $militiaUnits[_i].platoonName "secBarracks">> + Rename unit <<textbox "$SecExp.units.militia.squads[_i].platoonName" $SecExp.units.militia.squads[_i].platoonName "secBarracks">> | <<link "Disband the unit" "secBarracks">> - <<set $militiaFreeManpower += $militiaUnits[_i].troops>> - <<set $militiaUnits.deleteAt(_i)>> + <<set $SecExp.units.militia.free += $SecExp.units.militia.squads[_i].troops>> + <<set $SecExp.units.militia.squads.deleteAt(_i)>> <</link>> - <<if $militiaUnits[_i].active == 1>> - <<if $militiaUnits[_i].troops < $militiaUnits[_i].maxTroops && $militiaFreeManpower > 0>> + <<if $SecExp.units.militia.squads[_i].active == 1>> + <<if $SecExp.units.militia.squads[_i].troops < $SecExp.units.militia.squads[_i].maxTroops && $SecExp.units.militia.free > 0>> | <<link "Replenish unit" "secBarracks">> - <<if $militiaFreeManpower >= $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>> - <<set $militiaFreeManpower -= $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>> - <<set _expLoss = ($militiaUnits[_i].maxTroops - $militiaUnits[_i].troops) / $militiaUnits[_i].troops>> - <<set $militiaUnits[_i].training -= $militiaUnits[_i].training * _expLoss>> - <<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>> + <<if $SecExp.units.militia.free >= $SecExp.units.militia.squads[_i].maxTroops - $SecExp.units.militia.squads[_i].troops>> + <<set $SecExp.units.militia.free -= $SecExp.units.militia.squads[_i].maxTroops - $SecExp.units.militia.squads[_i].troops>> + <<set _expLoss = ($SecExp.units.militia.squads[_i].maxTroops - $SecExp.units.militia.squads[_i].troops) / $SecExp.units.militia.squads[_i].troops>> + <<set $SecExp.units.militia.squads[_i].training -= $SecExp.units.militia.squads[_i].training * _expLoss>> + <<set $SecExp.units.militia.squads[_i].troops = $SecExp.units.militia.squads[_i].maxTroops>> <<else>> - <<set _expLoss = $militiaFreeManpower / $militiaUnits[_i].troops>> - <<set $militiaUnits[_i].training -= $militiaUnits[_i].training * _expLoss>> - <<set $militiaUnits[_i].troops += $militiaFreeManpower>> - <<set $militiaFreeManpower = 0>> + <<set _expLoss = $SecExp.units.militia.free / $SecExp.units.militia.squads[_i].troops>> + <<set $SecExp.units.militia.squads[_i].training -= $SecExp.units.militia.squads[_i].training * _expLoss>> + <<set $SecExp.units.militia.squads[_i].troops += $SecExp.units.militia.free>> + <<set $SecExp.units.militia.free = 0>> <</if>> <</link>> <</if>> <<else>> - <<if $militiaFreeManpower > 0>> + <<if $SecExp.units.militia.free > 0>> | <<link "Reform the unit" "secBarracks">> - <<if $militiaFreeManpower >= $militiaUnits[_i].maxTroops>> - <<set $militiaFreeManpower -= $militiaUnits[_i].maxTroops>> - <<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>> - <<set $militiaUnits[_i].training = 0>> + <<if $SecExp.units.militia.free >= $SecExp.units.militia.squads[_i].maxTroops>> + <<set $SecExp.units.militia.free -= $SecExp.units.militia.squads[_i].maxTroops>> + <<set $SecExp.units.militia.squads[_i].troops = $SecExp.units.militia.squads[_i].maxTroops>> + <<set $SecExp.units.militia.squads[_i].training = 0>> <<else>> - <<set $militiaUnits[_i].troops += $militiaFreeManpower>> - <<set $militiaFreeManpower = 0>> - <<set $militiaUnits[_i].training = 0>> + <<set $SecExp.units.militia.squads[_i].troops += $SecExp.units.militia.free>> + <<set $SecExp.units.militia.free = 0>> + <<set $SecExp.units.militia.squads[_i].training = 0>> <</if>> - <<set $militiaUnits[_i].active = 1>> + <<set $SecExp.units.militia.squads[_i].active = 1>> <</link>> <</if>> <</if>> - | <<includeDOM App.SecExp.bulkUpgradeUnit($militiaUnits[_i])>> + | <<includeDOM App.SecExp.unit.bulkUpgrade($SecExp.units.militia.squads[_i])>> <<if $SecExp.settings.showStats == 1>> <<= App.SecExp.getUnit("Militia", _i).printStats()>> <</if>> - <<includeDOM App.SecExp.humanUnitUpgradeList($militiaUnits[_i])>> + <<includeDOM App.SecExp.unit.humanUpgradeList($SecExp.units.militia.squads[_i])>> <</capture>> <</for>> </div> @@ -374,62 +374,62 @@ Your current maximum number of units is <<print App.SecExp.battle.maxUnits()>> ( <div id="Mercs" class="tab-content"> <div class="content"> With the installation of a mercenary company in the arcology, many other are attracted to your free city, hoping to land a contract with you. - You are able to organize them in units to use in the defense of the arcology. Excluding the defense force you set up, there are <<print num(App.SecExp.Manpower.totalMerc)>> mercenaries in your arcology, of which <<print num(App.SecExp.Manpower.employedMerc)>> actively employed and <<print num($mercFreeManpower)>> not yet under contract. In total <<print num($mercTotalCasualties)>> mercenaries have died defending your arcology. - <br>Default unit name: <<textbox "$SecExp.defaultNames.mercs" $SecExp.defaultNames.mercs "secBarracks">> | - <<if $mercFreeManpower > 0 && App.SecExp.battle.activeUnits() < App.SecExp.battle.maxUnits()>> + You are able to organize them in units to use in the defense of the arcology. Excluding the defense force you set up, there are <<print num(App.SecExp.Manpower.totalMerc)>> mercenaries in your arcology, of which <<print num(App.SecExp.Manpower.employedMerc)>> actively employed and <<print num($SecExp.units.mercs.free)>> not yet under contract. In total <<print num($SecExp.units.mercs.dead)>> mercenaries have died defending your arcology. + <br>Default unit name: <<textbox "$SecExp.units.mercs.defaultName" $SecExp.units.mercs.defaultName "secBarracks">> | + <<if $SecExp.units.mercs.free > 0 && App.SecExp.battle.activeUnits() < App.SecExp.battle.maxUnits()>> <<link "Form a new unit" "secBarracks">> - <<set $mercUnits.push(App.SecExp.generateUnit("mercs"))>> + <<set $SecExp.units.mercs.squads.push(App.SecExp.unit.gen("mercs"))>> <</link>> | <</if>> - <<includeDOM App.SecExp.bulkUpgradeUnit($mercUnits)>> + <<includeDOM App.SecExp.unit.bulkUpgrade($SecExp.units.mercs.squads)>> <br> - <<set _meL = $mercUnits.length>> + <<set _meL = $SecExp.units.mercs.squads.length>> <<for _i = 0; _i < _meL; _i++>> <<capture _i>> <<= App.SecExp.getUnit("Mercs", _i).describe()>> <br> - Rename unit <<textbox "$mercUnits[_i].platoonName" $mercUnits[_i].platoonName "secBarracks">> + Rename unit <<textbox "$SecExp.units.mercs.squads[_i].platoonName" $SecExp.units.mercs.squads[_i].platoonName "secBarracks">> | <<link "Disband the unit" "secBarracks">> - <<set $mercFreeManpower += $mercUnits[_i].troops>> - <<set $mercUnits.deleteAt(_i)>> + <<set $SecExp.units.mercs.free += $SecExp.units.mercs.squads[_i].troops>> + <<set $SecExp.units.mercs.squads.deleteAt(_i)>> <</link>> - <<if $mercUnits[_i].active == 1>> - <<if $mercUnits[_i].troops < $mercUnits[_i].maxTroops && $mercFreeManpower > 0>> + <<if $SecExp.units.mercs.squads[_i].active == 1>> + <<if $SecExp.units.mercs.squads[_i].troops < $SecExp.units.mercs.squads[_i].maxTroops && $SecExp.units.mercs.free > 0>> | <<link "Replenish unit" "secBarracks">> - <<if $mercFreeManpower >= $mercUnits[_i].maxTroops - $mercUnits[_i].troops>> - <<set $mercFreeManpower -= $mercUnits[_i].maxTroops - $mercUnits[_i].troops>> - <<set _expLoss = ($mercUnits[_i].maxTroops - $mercUnits[_i].troops) / $mercUnits[_i].troops>> - <<set $mercUnits[_i].training -= $mercUnits[_i].training * _expLoss>> - <<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>> + <<if $SecExp.units.mercs.free >= $SecExp.units.mercs.squads[_i].maxTroops - $SecExp.units.mercs.squads[_i].troops>> + <<set $SecExp.units.mercs.free -= $SecExp.units.mercs.squads[_i].maxTroops - $SecExp.units.mercs.squads[_i].troops>> + <<set _expLoss = ($SecExp.units.mercs.squads[_i].maxTroops - $SecExp.units.mercs.squads[_i].troops) / $SecExp.units.mercs.squads[_i].troops>> + <<set $SecExp.units.mercs.squads[_i].training -= $SecExp.units.mercs.squads[_i].training * _expLoss>> + <<set $SecExp.units.mercs.squads[_i].troops = $SecExp.units.mercs.squads[_i].maxTroops>> <<else>> - <<set _expLoss = $mercFreeManpower / $mercUnits[_i].troops>> - <<set $mercUnits[_i].training -= $mercUnits[_i].training * _expLoss>> - <<set $mercUnits[_i].troops += $mercFreeManpower>> - <<set $mercFreeManpower = 0>> + <<set _expLoss = $SecExp.units.mercs.free / $SecExp.units.mercs.squads[_i].troops>> + <<set $SecExp.units.mercs.squads[_i].training -= $SecExp.units.mercs.squads[_i].training * _expLoss>> + <<set $SecExp.units.mercs.squads[_i].troops += $SecExp.units.mercs.free>> + <<set $SecExp.units.mercs.free = 0>> <</if>> <</link>> <</if>> <<else>> - <<if $mercFreeManpower > 0>> + <<if $SecExp.units.mercs.free > 0>> | <<link "Reform the unit" "secBarracks">> - <<if $mercFreeManpower >= $mercUnits[_i].maxTroops>> - <<set $mercFreeManpower -= $mercUnits[_i].maxTroops>> - <<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>> - <<set $mercUnits[_i].training = 0>> + <<if $SecExp.units.mercs.free >= $SecExp.units.mercs.squads[_i].maxTroops>> + <<set $SecExp.units.mercs.free -= $SecExp.units.mercs.squads[_i].maxTroops>> + <<set $SecExp.units.mercs.squads[_i].troops = $SecExp.units.mercs.squads[_i].maxTroops>> + <<set $SecExp.units.mercs.squads[_i].training = 0>> <<else>> - <<set $mercUnits[_i].troops += $mercFreeManpower>> - <<set $mercFreeManpower = 0>> - <<set $mercUnits[_i].training = 0>> + <<set $SecExp.units.mercs.squads[_i].troops += $SecExp.units.mercs.free>> + <<set $SecExp.units.mercs.free = 0>> + <<set $SecExp.units.mercs.squads[_i].training = 0>> <</if>> - <<set $mercUnits[_i].active = 1>> + <<set $SecExp.units.mercs.squads[_i].active = 1>> <</link>> <</if>> <</if>> - | <<includeDOM App.SecExp.bulkUpgradeUnit($mercUnits[_i])>> + | <<includeDOM App.SecExp.unit.bulkUpgrade($SecExp.units.mercs.squads[_i])>> <<if $SecExp.settings.showStats == 1>> <<= App.SecExp.getUnit("Mercs", _i).printStats()>> <</if>> - <<includeDOM App.SecExp.humanUnitUpgradeList($mercUnits[_i])>> + <<includeDOM App.SecExp.unit.humanUpgradeList($SecExp.units.mercs.squads[_i])>> <</capture>> <</for>> </div> diff --git a/src/Mods/SecExp/buildings/weaponsManufacturing.tw b/src/Mods/SecExp/buildings/weaponsManufacturing.tw index 2b3727df17b..f7b69551f60 100644 --- a/src/Mods/SecExp/buildings/weaponsManufacturing.tw +++ b/src/Mods/SecExp/buildings/weaponsManufacturing.tw @@ -3,8 +3,8 @@ <<set $nextButton = "Back", $nextLink = "Main", _baseUpgradeTime = App.SecExp.weapManuUpgrade.baseTime()>> This sector of the arcology has been dedicated to weapons manufacturing. These factories supply -<<if $militiaUnits.length > 0>> your militia and<</if>> -<<if $slaveUnits.length > 0>> your slave soldiers and<</if>> +<<if $SecExp.units.militia.squads.length > 0>> your militia and<</if>> +<<if $SecExp.units.slaves.squads.length > 0>> your slave soldiers and<</if>> <<if $mercenaries > 0>> your mercenaries and<</if>> many small old world nations as the advanced technology that Free Cities have available is hard to come by otherwise. <<if $SecExp.buildings.weapManu.productivity == 1>> diff --git a/src/Mods/SecExp/js/Unit.js b/src/Mods/SecExp/js/Unit.js index 16c83ff058a..4796eff75d3 100644 --- a/src/Mods/SecExp/js/Unit.js +++ b/src/Mods/SecExp/js/Unit.js @@ -1,328 +1,419 @@ -/** Creates a bulk upgrade link for the unit that is passed. - * @param {object} [unit] the unit to be checked. - */ -App.SecExp.bulkUpgradeUnit = function(unit) { - unit = Array.isArray(unit) ? unit : [unit]; - let el = document.createElement("a"); +App.SecExp.unit = (function() { + return { + list, + bulkUpgrade, + humanLoyaltyChanges, + fixBroken, + gen:generate, + deployMenu, + humanUpgradeList, + genID, + replenishAll, + isDeployed, + humanSquads + }; + + /** Lists all potential military units as an array. + * + */ + function list() { + return ['bots', 'slaves', 'militia', 'mercs']; + } - function upgradeUnit(x) { - Object.assign(x, { - maxTroops: 50, equip: 3, commissars: 2, - cyber: 1, medics: 1, SF: 1 - }); + /** Creates a bulk upgrade link for the unit that is passed. + * @param {object} [unit] the unit to be checked. + */ + function bulkUpgrade(unit) { + unit = Array.isArray(unit) ? unit : [unit]; + let el = document.createElement("a"); + + function upgradeUnit(x) { + Object.assign(x, { + maxTroops: 50, equip: 3, commissars: 2, + cyber: 1, medics: 1, SF: 1 + }); + } + + function getCost(x) { + let cost = 0; + const equipUpgradeCost = 250; + if (x.maxTroops < 50) { + cost += 5000 + (((50 - x.maxTroops) /10) * equipUpgradeCost * (x.equip + x.commissars + x.cyber + x.SF)); + } + if (x.equip < 3) { + cost += (equipUpgradeCost * x.maxTroops + 1000) * (3 - x.equip); + } + if (x.commissars < 2) { + cost += (equipUpgradeCost * x.maxTroops + 1000) * (2 - x.commissars); + } + if ((V.prostheticsUpgrade >= 2 || V.researchLab.advCombatPLimb === 1) && x.cyber === 0) { + cost += equipUpgradeCost * x.maxTroops + 2000; + } + if (x.medics === 0) { + cost += equipUpgradeCost * x.maxTroops + 1000; + } + if (V.SF.Toggle && V.SF.Active >= 1 && x.SF === 0) { + cost += equipUpgradeCost * x.maxTroops + 5000; + } + return Math.ceil(cost *= 1.1); + } + + const price = unit.map(getCost).reduce((acc, cur) => acc + cur, 0); + if (price > 0) { + el.append(App.UI.DOM.link(`Bulk upgrade for ${cashFormat(price)}`, () => { + unit.map(upgradeUnit).reduce((acc, cur) => acc + cur, 0); + cashX(-price, "securityExpansion"); + }, + [], passage() + )); + } + return el; } - function getCost(x) { - let cost = 0; - const equipUpgradeCost = 250; - if (x.maxTroops < 50) { - cost += 5000 + (((50 - x.maxTroops) /10) * equipUpgradeCost * (x.equip + x.commissars + x.cyber + x.SF)); + /** Reports changes to the supplied unit's loyalty. + * @param {FC.SecExp.PlayerHumanUnitData} input the unit type to be checked. + * @param {FC.SecExp.PlayerHumanUnitType} type + * @returns {HTMLDivElement} + */ + function humanLoyaltyChanges(input, type) { + let loyaltyChange = 0, el = document.createElement("div"); + + el.append(`${input.platoonName}: `); + if (V.SecExp.buildings.barracks && V.SecExp.buildings.barracks.loyaltyMod >= 1) { + el.append("is periodically sent to the indoctrination facility in the barracks for thought correction therapy. "); + loyaltyChange += 2 * V.SecExp.buildings.barracks.loyaltyMod; } - if (x.equip < 3) { - cost += (equipUpgradeCost * x.maxTroops + 1000) * (3 - x.equip); + if (input.commissars >= 1) { + el.append("The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination. "); + loyaltyChange += 2 * input.commissars; } - if (x.commissars < 2) { - cost += (equipUpgradeCost * x.maxTroops + 1000) * (2 - x.commissars); + if (V.SecExp.edicts.defense.soldierWages === 2) { + if (type === 'slaves') { + el.append("The slaves greatly appreciate the generous wage given to them for their service as soldiers. Occasions to earn money for a slave are scarce after all. "); + } else if (type === 'militia') { + el.append("The soldiers greatly appreciate the generous wage given to them for their service. They are proud to defend their homes while making a small fortune out of it. "); + } else if (type === 'mercs') { + el.append("The mercenaries greatly appreciate the generous wage given to them for their service. After all coin is the fastest way to reach their hearts. "); + } + loyaltyChange += random(5, 10); + } else if (V.SecExp.edicts.defense.soldierWages === 1) { + if (type === 'slaves') { + el.append("The slaves appreciate the wage given to them for their service as soldiers, despite it being just adequate. Occasions to earn money for a slave are scarce after all. "); + } else if (type === 'militia') { + el.append("The soldiers appreciate the wage given to them for their service, despite it being just adequate. They are proud to defend their homes, though at the cost of possible financial gains. "); + } else if (type === 'mercs') { + el.append("The mercenaries do not appreciate the barely adequate wage given to them for their service. Still their professionalism keeps them determined to finish their contract. "); + } + loyaltyChange += random(-5, 5); + } else { + if (type === 'slaves') { + el.append("The slaves do not appreciate the low wage given to them for their service as soldiers, but occasions to earn money for a slave are scarce, so they're not too affected by it. "); + } else if (type === 'militia') { + el.append("The soldiers do not appreciate the low wage given to them for their service. Their sense of duty keeps them proud of their role as defenders of the arcology, but many do feel its financial weight. "); + } else if (type === 'mercs') { + el.append("The mercenaries do not appreciate the low wage given to them for their service. Their skill would be better served by a better contract and this world does not lack demand for guns for hire. "); + } + loyaltyChange -= random(5, 10); } - if ((V.prostheticsUpgrade >= 2 || V.researchLab.advCombatPLimb === 1) && x.cyber === 0) { - cost += equipUpgradeCost * x.maxTroops + 2000; + if (type === 'slaves' && V.SecExp.edicts.defense.privilege.slaveSoldier) { + el.append("Allowing them to hold material possessions earns you their devotion and loyalty. "); + loyaltyChange += random(1, 2); } - if (x.medics === 0) { - cost += equipUpgradeCost * x.maxTroops + 1000; + if (type === 'militia' && V.SecExp.edicts.defense.privilege.militiaSoldier) { + el.append("Allowing them to avoid rent payment for their military service earns you their happiness and loyalty. "); + loyaltyChange += random(1, 2); } - if (V.SF.Toggle && V.SF.Active >= 1 && x.SF === 0) { - cost += equipUpgradeCost * x.maxTroops + 5000; + if (type === 'mercs' && V.SecExp.edicts.defense.privilege.mercSoldier) { + el.append("Allowing them to keep part of the loot gained from your enemies earns you their trust and loyalty. "); + loyaltyChange += random(1, 2); } - return Math.ceil(cost *= 1.1); - } - - const price = unit.map(getCost).reduce((acc, cur) => acc + cur, 0); - if (price > 0) { - el.append(App.UI.DOM.link(`Bulk upgrade for ${cashFormat(price)}`, () => { - unit.map(upgradeUnit).reduce((acc, cur) => acc + cur); - cashX(-price, "securityExpansion"); - }, - [], passage() - )); - } - return el; -}; -/** Reports changes to the supplied unit's loyalty. - * @param {FC.SecExp.PlayerHumanUnitData} input the unit type to be checked. - * @param {FC.SecExp.PlayerHumanUnitType} type - * @returns {HTMLDivElement} - */ -App.SecExp.humanUnitLoyaltyChanges = function(input, type) { - let loyaltyChange = 0, el = document.createElement("div"); - - el.append(`${input.platoonName}: `); - if (V.SecExp.buildings.barracks && V.SecExp.buildings.barracks.loyaltyMod >= 1) { - el.append("is periodically sent to the indoctrination facility in the barracks for thought correction therapy. "); - loyaltyChange += 2 * V.SecExp.buildings.barracks.loyaltyMod; - } - if (input.commissars >= 1) { - el.append("The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination. "); - loyaltyChange += 2 * input.commissars; - } - if (V.SecExp.edicts.defense.soldierWages === 2) { - if (type === 'slave') { - el.append("The slaves greatly appreciate the generous wage given to them for their service as soldiers. Occasions to earn money for a slave are scarce after all. "); - } else if (type === 'citizens') { - el.append("The soldiers greatly appreciate the generous wage given to them for their service. They are proud to defend their homes while making a small fortune out of it. "); - } else if (type === 'mercenary') { - el.append("The mercenaries greatly appreciate the generous wage given to them for their service. After all coin is the fastest way to reach their hearts. "); + el.append("This week, the loyalty of this unit "); + if (loyaltyChange > 0) { + App.UI.DOM.appendNewElement("span", el, "increased.", "green"); + } else if (loyaltyChange === 0) { + App.UI.DOM.appendNewElement("span", el, "did not change.", "yellow"); + } else { + App.UI.DOM.appendNewElement("span", el, "decreased.", "red"); } - loyaltyChange += random(5, 10); - } else if (V.SecExp.edicts.defense.soldierWages === 1) { - if (type === 'slave') { - el.append("The slaves appreciate the wage given to them for their service as soldiers, despite it being just adequate. Occasions to earn money for a slave are scarce after all. "); - } else if (type === 'citizens') { - el.append("The soldiers appreciate the wage given to them for their service, despite it being just adequate. They are proud to defend their homes, though at the cost of possible financial gains. "); - } else if (type === 'mercenary') { - el.append("The mercenaries do not appreciate the barely adequate wage given to them for their service. Still their professionalism keeps them determined to finish their contract. "); + input.loyalty = Math.clamp(input.loyalty + loyaltyChange, 0, 100); + if (input.training < 100 && V.SecExp.buildings && V.SecExp.buildings.barracks.training >= 1) { + let options = document.createElement("div"); + options.append("The unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level. "); + el.append(options); + input.training += random(2, 4) * 1.5 * V.SecExp.buildings.barracks.training; } - loyaltyChange += random(-5, 5); - } else { - if (type === 'slave') { - el.append("The slaves do not appreciate the low wage given to them for their service as soldiers, but occasions to earn money for a slave are scarce, so they're not too affected by it. "); - } else if (type === 'citizens') { - el.append("The soldiers do not appreciate the low wage given to them for their service. Their sense of duty keeps them proud of their role as defenders of the arcology, but many do feel its financial weight. "); - } else if (type === 'mercenary') { - el.append("The mercenaries do not appreciate the low wage given to them for their service. Their skill would be better served by a better contract and this world does not lack demand for guns for hire. "); - } - loyaltyChange -= random(5, 10); - } - if (type === 'slave' && V.SecExp.edicts.defense.privilege.slaveSoldier) { - el.append("Allowing them to hold material possessions earns you their devotion and loyalty. "); - loyaltyChange += random(1, 2); - } - if (type === 'citizens' && V.SecExp.edicts.defense.privilege.militiaSoldier) { - el.append("Allowing them to avoid rent payment for their military service earns you their happiness and loyalty. "); - loyaltyChange += random(1, 2); - } - if (type === 'mercenary' && V.SecExp.edicts.defense.privilege.mercSoldier) { - el.append("Allowing them to keep part of the loot gained from your enemies earns you their trust and loyalty. "); - loyaltyChange += random(1, 2); - } - el.append("This week, the loyalty of this unit "); - if (loyaltyChange > 0) { - App.UI.DOM.appendNewElement("span", el, "increased.", "green"); - } else if (loyaltyChange === 0) { - App.UI.DOM.appendNewElement("span", el, "did not change.", "yellow"); - } else { - App.UI.DOM.appendNewElement("span", el, "decreased.", "red"); + return el; } - input.loyalty = Math.clamp(input.loyalty + loyaltyChange, 0, 100); - if (input.training < 100 && V.SecExp.buildings && V.SecExp.buildings.barracks.training >= 1) { - let options = document.createElement("div"); - options.append("The unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level."); - el.append(options); - input.training += random(2, 4) * 1.5 * V.SecExp.buildings.barracks.training; + + /** Repairs unit if needed. + * @param {object} [input] the unit to be checked. + */ + function fixBroken(input) { + input.SF = input.SF || 0; + if (!jsDef(input.ID)) { + input.ID = genID(); + } + input.cyber = input.cyber || 0; + input.commissars = input.commissars || 0; + input.maxTroops = Math.min(30, input.maxTroops); + input.troops = Math.clamp(input.troops, 0, input.maxTroops); } - return el; -}; + /** Creates the requested unit object. + * @param {string} [type] the unit type to be created. + * @param {arrary} [updater] previous variables to check against. + */ + function generate(type, updater = {}) { + if (!jsDef(V.SecExp.units[type]) || Object.entries(updater).length > 0) { + V.SecExp.units[type] = V.SecExp.units[type] || {}; + if (type !== "bots") { + V.SecExp.units[type].created = V.SecExp.units[type].created || updater.count || 0; + V.SecExp.units[type].dead = V.SecExp.units[type].dead || updater.killed ||0; + V.SecExp.units[type].squads = V.SecExp.units[type].squads || updater.squads ||[]; + if (type !== 'slaves') { + V.SecExp.units[type].free = V.SecExp.units[type].free || updater.free || 0; + } + } + return; + } -/** Repairs unit if needed. - * @param {object} [input] the unit to be checked. - */ -App.SecExp.fixBrokenUnit = function(input) { - input.SF = input.SF || 0; - if (!jsDef(input.ID)) { - input.ID = App.SecExp.generateUnitID(); - } - input.cyber = input.cyber || 0; - input.commissars = input.commissars || 0; - input.maxTroops = Math.min(30, input.maxTroops); - Math.clamp(input.troops, 0, input.maxTroops); -}; + let newUnit = { + ID: -1, equip: 0, active: 1, isDeployed: 0, maxTroops: 30, troops: 30 + }; + if (type !== "bots") { + Object.assign(newUnit, { + training: 0, cyber: 0, medics: 0, + SF: 0, commissars: 0, battlesFought: 0, + loyalty: jsRandom(40, 60), + ID: genID(), + platoonName: `${ordinalSuffix(++V.SecExp.units[type].created)} ` + V.SecExp.units[type].defaultName + }); + + if (type === "slaves") { + newUnit.troops = Math.min(newUnit.maxTroops, V.menials); + V.menials -= newUnit.troops; + } else { + newUnit.troops = Math.min(newUnit.maxTroops, V.SecExp.units[type].free); + V.SecExp.units[type].free -= newUnit.troops; + } + } + return newUnit; + } -/** Creates the requested unit object. - * @param {string} [type] the unit type to be created. - */ -App.SecExp.generateUnit = function(type) { - let newUnit = { - ID: -1, equip: 0, active: 1, isDeployed: 0, maxTroops:30, troops: 30 - }; - if (type !== "bots") { - Object.assign(newUnit, { - training: 0, cyber: 0, medics: 0, - SF: 0, commissars: 0, battlesFought: 0, - loyalty: jsRandom(40, 60), - ID: App.SecExp.generateUnitID() - }); - - if (type === "slaves") { - newUnit.platoonName = `${ordinalSuffix(++V.createdSlavesUnits)} ` + V.SecExp.defaultNames[type]; - newUnit.troops = Math.min(newUnit.maxTroops, V.menials); - V.menials -= newUnit.troops; - } else if (type === "militia") { - newUnit.platoonName = `${ordinalSuffix(++V.createdMilitiaUnits)} ` + V.SecExp.defaultNames[type]; - newUnit.troops = Math.min(newUnit.maxTroops, V.militiaFreeManpower); - V.militiaFreeManpower -= newUnit.troops; - } else if (type === "mercs") { - newUnit.platoonName = `${ordinalSuffix(++V.createdMercUnits)} ` + V.SecExp.defaultNames[type]; - newUnit.troops = Math.min(newUnit.maxTroops, V.mercFreeManpower); - V.mercFreeManpower -= newUnit.troops; + /** Display's the deploy menu for the unit. + * @param {FC.SecExp.PlayerHumanUnitData} input the unit to be checked. + * @param {FC.SecExp.PlayerHumanUnitType} type + */ + function deployMenu(input, type, count = 0) { + let el = document.createElement("div"), options = document.createElement("div"); + const canDeploy = input.isDeployed === 0 && App.SecExp.battle.deployableUnits() > 0; + + if (input.active === 1 && input.troops > 0) { + if (type === "bots") { + $(el).append(App.SecExp.getUnit("Bots").describe()); + } else { + $(el).append(App.SecExp.getUnit(capFirstChar(type), count).describe()); + } + options = document.createElement("div"); + options.append(App.UI.DOM.link(`${canDeploy ? 'Deploy' : 'Remove'} the unit`, () => { + input.isDeployed = canDeploy ? 1 : 0; V.SecExp.war.saveValid = 0; + }, + [], passage() + )); } + el.append(options); + return el; } - return newUnit; -}; -/** Display's the deploy menu for the unit. - * @param {FC.SecExp.PlayerHumanUnitData} input the unit to be checked. - * @param {FC.SecExp.PlayerHumanUnitType} type - * @param {number} [count=0] - */ -App.SecExp.deployUnitMenu = function(input, type, count = 0) { - let el = document.createElement("div"), options = document.createElement("div"); - const canDeploy = input.isDeployed === 0 && App.SecExp.battle.deployableUnits() > 0; + /** Prints a list of upgrades that can be applied to the passed human unit. + * @param {FC.SecExp.PlayerHumanUnitData} input the human unit to be checked. + */ + function humanUpgradeList(input) { + const equipUpgradeCost = 250; + let el = document.createElement("div"), options = document.createElement("div"); - if (input.active === 1 && input.troops > 0) { - if (type === "bots") { - $(el).append(App.SecExp.getUnit("Bots").describe()); + if (input.maxTroops < 50) { + options.append(`For ${cashFormat(5000 + 10 * equipUpgradeCost * (input.equip + input.commissars + input.cyber + input.SF))} provide this unit's `); + options.append(App.UI.DOM.link("officers with intensive training", () => { + input.maxTroops += 10; + cashX(-(5000 + 10 * equipUpgradeCost * (input.equip + input.commissars + input.cyber + input.SF)), "securityExpansion"); + }, + [], passage() + )); + options.append(` to increase the maximum number of soldiers in the unit by 10.`); } else { - $(el).append(App.SecExp.getUnit(capFirstChar(type), count).describe()); + options.append(`Your officers reached their peak. Further training will have little impact on the number of troops they can effectively lead.`); } - options = document.createElement("div"); - options.append(App.UI.DOM.link(`${canDeploy ? 'Deploy' : 'Remove'} the unit`, () => { - input.isDeployed = canDeploy ? 1 : 0; V.SecExp.war.saveValid = 0; - }, - [], passage() - )); - } - el.append(options); - return el; -}; + el.append(options); -/** Prints a list of upgrades that can be applied to the passed human unit. - * @param {FC.SecExp.PlayerHumanUnitData} input the human unit to be checked. - */ -App.SecExp.humanUnitUpgradeList = function(input) { - const equipUpgradeCost = 250; - let el = document.createElement("div"); let options = document.createElement("div"); - - if (input.maxTroops < 50) { - options.append(`For ${cashFormat(5000 + 10 * equipUpgradeCost * (input.equip + input.commissars + input.cyber + input.SF))} provide this unit's `); - options.append(App.UI.DOM.link("officers with intensive training", () => { - input.maxTroops += 10; - cashX(-(5000 + 10 * equipUpgradeCost * (input.equip + input.commissars + input.cyber + input.SF)), "securityExpansion"); - }, - [], passage() - )); - options.append(` to increase the maximum number of soldiers in the unit by 10.`); - } else { - options.append(`Your officers reached their peak. Further training will have little impact on the number of troops they can effectively lead.`); - } - el.append(options); - - options = document.createElement("div"); - if (input.equip < 3) { - options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} invest in `); - options.append(App.UI.DOM.link("better equipment", () => { - input.equip++; - cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion"); - }, - [], passage() - )); - options.append(` to increase this unit's attack and defense by 15% per investement.`); - } else { - options.append(`The unit is equipped with state of the art weaponry and equipment.`); - } - el.append(options); - - options = document.createElement("div"); - if (input.commissars === 0) { - options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} attach `); - options.append(App.UI.DOM.link("commissars", () => { - input.commissars++; - cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion"); - }, - [], passage() - )); - options.append(` to slowly increase this unit's loyalty.`); - } else if (input.commissars < 2) { - options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} attach `); - options.append(App.UI.DOM.link("commissars", () => { - input.commissars++; - cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion"); - }, - [], passage() - )); - options.append(` to slowly increase this unit's loyalty.`); - } - if (input.commissars === 1) { - options.append(" The unit has a commissar detachment, keeping under control the ambitions of the unit's officers."); - } else if (input.commissars === 2) { - options.append(" The unit has a perfectly trained and loyal commissar detachment, keeping under control the ambitions of the unit's officers."); - } - el.append(options); - - options = document.createElement("div"); - if (V.prostheticsUpgrade >= 2 || V.researchLab.advCombatPLimb === 1) { - if (input.cyber === 0) { - options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} `); - options.append(App.UI.DOM.link("augment all soldiers of the unit", () => { - input.cyber++; - cashX(-(equipUpgradeCost * input.maxTroops + 2000), "securityExpansion"); + options = document.createElement("div"); + if (input.equip < 3) { + options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} invest in `); + options.append(App.UI.DOM.link("better equipment", () => { + input.equip++; + cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion"); }, [], passage() )); - options.append(` with high tech cyber enhancements that will increase attack, defense and base hp values.`); + options.append(` to increase this unit's attack and defense by 15% per investement.`); } else { - options.append('The unit is equipped with advanced cybernetic enhancements.'); + options.append(`The unit is equipped with state of the art weaponry and equipment.`); } - } - el.append(options); - - options = document.createElement("div"); - if (input.medics === 0) { - options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} `); - options.append(App.UI.DOM.link("attach trained medics to the unit", () => { - input.medics++; - cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion"); - }, - [], passage() - )); - options.append(' which will decrease the number of casualties suffered during battle.'); - } else { - options.append('The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers'); - } - el.append(options); + el.append(options); - if (V.SF.Toggle && V.SF.Active >= 1) { options = document.createElement("div"); + if (input.commissars < 2) { + options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} attach `); + options.append(App.UI.DOM.link("commissars", () => { + input.commissars++; + cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion"); + }, + [], passage() + )); + options.append(` to slowly increase this unit's loyalty.`); + } + if (input.commissars === 1) { + options.append(" The unit has a commissar detachment, keeping under control the ambitions of the unit's officers."); + } else if (input.commissars === 2) { + options.append(" The unit has a perfectly trained and loyal commissar detachment, keeping under control the ambitions of the unit's officers."); + } + el.append(options); + + options = document.createElement("div"); + if (V.prostheticsUpgrade >= 2 || V.researchLab.advCombatPLimb === 1) { + if (input.cyber === 0) { + options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} `); + options.append(App.UI.DOM.link("augment all soldiers of the unit", () => { + input.cyber++; + cashX(-(equipUpgradeCost * input.maxTroops + 2000), "securityExpansion"); + }, + [], passage() + )); + options.append(` with high tech cyber enhancements that will increase attack, defense and base hp values.`); + } else { + options.append('The unit is equipped with advanced cybernetic enhancements.'); + } + } + el.append(options); - if (input.SF === 0) { - options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 5000)} `); - options.append(App.UI.DOM.link("attach Special Force advisors", () => { - input.SF++; - cashX(-(equipUpgradeCost * input.maxTroops + 5000), "securityExpansion"); + options = document.createElement("div"); + if (input.medics === 0) { + options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} `); + options.append(App.UI.DOM.link("attach trained medics to the unit", () => { + input.medics++; + cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion"); }, [], passage() )); - options.append(' which will slightly increase the base stats of the unit.'); + options.append(' which will decrease the number of casualties suffered during battle.'); } else { - options.append(`The unit has attached advisors from ${V.SF.Lower} that will help the squad remain tactically aware and active.`); + options.append('The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers'); } el.append(options); + + if (V.SF.Toggle && V.SF.Active >= 1) { + options = document.createElement("div"); + + if (input.SF === 0) { + options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 5000)} `); + options.append(App.UI.DOM.link("attach Special Force advisors", () => { + input.SF++; + cashX(-(equipUpgradeCost * input.maxTroops + 5000), "securityExpansion"); + }, + [], passage() + )); + options.append(' which will slightly increase the base stats of the unit.'); + } else { + options.append(`The unit has attached advisors from ${V.SF.Lower} that will help the squad remain tactically aware and active.`); + } + el.append(options); + } + + return el; } - return el; -}; + /** Generate a unit ID for a new unit + * @returns {number} + */ + function genID() { + return Math.max( + App.SecExp.unit.humanSquads().map(u => u.ID).reduce((acc, cur) => Math.max(acc, cur), 0) + ) + 1; + } -/** Generate a unit ID for a new unit - * @returns {number} - */ -App.SecExp.generateUnitID = function() { - return Math.max( - V.militiaUnits.reduce((acc, cur) => Math.max(acc, cur.ID), 0), - V.slaveUnits.reduce((acc, cur) => Math.max(acc, cur.ID), 0), - V.mercUnits.reduce((acc, cur) => Math.max(acc, cur.ID), 0) - ) + 1; -}; + function replenishAll() { + let el = document.createElement("div"); + let woundedUnit = [], expLoss; + + function unitsFree(x) { + if (x === 'slaves') { + return V.menials; + } else { + return V.SecExp.units[x].free; + } + } + + if (V.SecExp.units.bots.troops < V.SecExp.units.bots.maxTroops && V.cash >= 500) { + woundedUnit.push('bots'); + } + + for (const unit of list().slice(1)) { + for (const squad of V.SecExp.units[unit].squads) { + if (!woundedUnit.contains(unit) && squad.troops < squad.maxTroops && unitsFree(unit) > 0) { + woundedUnit.push(unit); + } + } + } + + if (woundedUnit.length > 0) { + el.append(App.UI.DOM.link("Replenish all units", () => { + for (const unit of woundedUnit) { + if (unit === 'bots') { + cashX(-((V.SecExp.units.bots.maxTroops - V.SecExp.units.bots.troops) * 500), "securityExpansion"); + V.SecExp.units.bots.troops = V.SecExp.units.bots.maxTroops; + } else { + let freeUnits = unitsFree(unit); + for (const squad of V.SecExp.units[unit].squads) { + if (squad.troops < squad.maxTroops && freeUnits > 0) { + if (freeUnits >= squad.maxTroops - squad.troops) { + freeUnits -= squad.maxTroops - squad.troops; + expLoss = (squad.maxTroops - squad.troops) / squad.troops; + squad.troops = squad.maxTroops; + } else { + expLoss = freeUnits / squad.troops; + squad.troops += freeUnits; + freeUnits = 0; + } + squad.training -= squad.training * expLoss; + } + } + } + } + }, + [], passage() + )); + el.append(` Will replenish units as long as requirements are met.\n\n`); + } + + return el; + } + + function isDeployed(unit) { + return (V.citizenRebellion === 0 && V.slaveRebellion === 0 && unit.isDeployed === 1) || ((V.citizenRebellion > 0 || V.slaveRebellion > 0) && unit.active === 1 && !V.SecExp.war.rebellingID.includes(unit.ID)); + } + + function humanSquads() { + let array = []; + for (const unit of list().slice(1)) { + for (const squad of V.SecExp.units[unit].squads) { + array.push(squad); + } + } + return array; + } +})(); /** Player unit factory - get a unit based on its type and index * @param {PlayerHumanUnitType} type - "Bots", "Militia", "Slaves", "Mercs", or "SF" @@ -331,7 +422,7 @@ App.SecExp.generateUnitID = function() { */ App.SecExp.getUnit = function(type, index) { if (type === "Bots") { - return new App.SecExp.DroneUnit(V.secBots, App.SecExp.BaseDroneUnit); + return new App.SecExp.DroneUnit(V.SecExp.units.bots, App.SecExp.BaseDroneUnit); } else if (type === "SF") { return new App.SecExp.SFUnit(); } else if (typeof index !== "number") { @@ -340,11 +431,11 @@ App.SecExp.getUnit = function(type, index) { switch (type) { case "Militia": - return new App.SecExp.HumanUnit(V.militiaUnits[index], App.SecExp.BaseMilitiaUnit, type); + return new App.SecExp.HumanUnit(V.SecExp.units.militia.squads[index], App.SecExp.BaseMilitiaUnit, type); case "Slaves": - return new App.SecExp.HumanUnit(V.slaveUnits[index], App.SecExp.BaseSlaveUnit, type); + return new App.SecExp.HumanUnit(V.SecExp.units.slaves.squads[index], App.SecExp.BaseSlaveUnit, type); case "Mercs": - return new App.SecExp.HumanUnit(V.mercUnits[index], App.SecExp.BaseMercUnit, type); + return new App.SecExp.HumanUnit(V.SecExp.units.mercs.squads[index], App.SecExp.BaseMercUnit, type); default: throw `Unknown unit type: ${type}`; } @@ -843,7 +934,7 @@ App.SecExp.HumanUnit = class SecExpHumanUnit extends App.SecExp.Unit { }; App.SecExp.troopsFromSF = function() { - if (V.slaveRebellion !== 1 || V.citizenRebellion !== 1) { // attack: how many troops can we actually carry? + if (V.slaveRebellion === 0 && V.citizenRebellion === 0) { // attack: how many troops can we actually carry? const transportMax = Math.trunc(125 * (V.SF.Squad.GunS + (V.terrain !== "oceanic" ? ((V.SF.Squad.AV + V.SF.Squad.TV)/2) : 0))); return Math.min(transportMax, V.SF.ArmySize); } else { @@ -854,7 +945,7 @@ App.SecExp.troopsFromSF = function() { App.SecExp.SFUnit = class SFUnit extends App.SecExp.Unit { constructor() { super(null, App.SecExp.BaseSpecialForcesUnit); - this._distancePenalty = (V.slaveRebellion !== 1 || V.citizenRebellion !== 1) ? 0.10 : 0.0; + this._distancePenalty = (V.slaveRebellion === 0 && V.citizenRebellion === 0) ? 0.10 : 0.0; } get attack() { @@ -1092,7 +1183,7 @@ App.SecExp.describeUnit = (function() { })(); App.SecExp.mercenaryAvgLoyalty = function() { - return _.mean(V.mercUnits.filter((u) => u.active === 1).map((u) => u.loyalty)); + return _.mean(V.SecExp.units.mercs.squads.filter((u) => u.active === 1).map((u) => u.loyalty)); }; App.SecExp.Manpower = { @@ -1101,15 +1192,15 @@ App.SecExp.Manpower = { }, get employedMilitia() { - return V.militiaUnits.reduce((acc, cur) => acc + cur.troops, 0); + return V.SecExp.units.militia.squads.reduce((acc, cur) => acc + cur.troops, 0); }, get freeMilitia() { - return V.militiaFreeManpower; + return V.SecExp.units.militia.free; }, get employedSlave() { - return V.slaveUnits.reduce((acc, cur) => acc + cur.troops, 0); + return V.SecExp.units.slaves.squads.reduce((acc, cur) => acc + cur.troops, 0); }, get totalMerc() { @@ -1117,11 +1208,11 @@ App.SecExp.Manpower = { }, get employedMerc() { - return V.mercUnits.reduce((acc, cur) => acc + cur.troops, 0); + return V.SecExp.units.mercs.squads.reduce((acc, cur) => acc + cur.troops, 0); }, get freeMerc() { - return V.mercFreeManpower; + return V.SecExp.units.mercs.free; }, get employedOverall() { diff --git a/src/Mods/SecExp/js/secExp.js b/src/Mods/SecExp/js/secExp.js index 9592dbabc15..cfa45a88dae 100644 --- a/src/Mods/SecExp/js/secExp.js +++ b/src/Mods/SecExp/js/secExp.js @@ -224,18 +224,14 @@ App.SecExp.generator = (function() { const rebelPercent = 0.3 * authFactor; const irregularPercent = 0.2 * repFactor; - const isDisloyal = (squad) => ((squad.loyalty < 10 && random(1, 100) <= 70) || (squad.loyalty < 33 && random(1, 100) <= 30) || (squad.loyalty < 66 && random(1, 100) <= 10)); + const isDisloyal = (x) => (x < 10 && jsRandom(1, 100) <= 70) || (x < 33 && jsRandom(1, 100) <= 30) || (x < 66 && jsRandom(1, 100) <= 10); const baseValue = Math.trunc((isSlaveRebellion ? V.ASlaves : V.ACitizens) * rebelPercent * weekMod) + random(-100, 100); const highestValue = isSlaveRebellion ? V.ASlaves : V.ACitizens; V.SecExp.war.attacker.troops = Math.clamp(baseValue, 50, highestValue); V.SecExp.war.attacker.equip = Math.clamp(V.SecExp.edicts.weaponsLaw + random((isSlaveRebellion ? -2 : -1), 1), 0, 4); V.SecExp.war.irregulars = Math.clamp(Math.trunc(V.ACitizens * irregularPercent * weekMod) + random(-100, 100), 50, V.ACitizens); V.SecExp.war.engageRule = 0; - V.SecExp.war.rebellingID = [].concat( - V.slaveUnits.filter(isDisloyal).map(u => u.ID), - V.militiaUnits.filter(isDisloyal).map(u => u.ID), - V.mercUnits.filter(isDisloyal).map(u => u.ID) - ); + V.SecExp.war.rebellingID = [].concat(App.SecExp.unit.humanSquads().map(u => u.loyalty).filter(isDisloyal)); } } })(); @@ -422,15 +418,13 @@ App.SecExp.generalInit = function() { currency: "", type: "crime" }, - /* - repairTime: { + /* repairTime: { waterway: 0, assistant: 0, reactor: 0, arc: 0 - }, + }, */ units: {}, - */ edicts: { alternativeRents: 0, enslavementRights: 0, @@ -471,14 +465,12 @@ App.SecExp.generalInit = function() { pharaonTradition: 0, } }, - smilingMan: {progress: 0}, - defaultNames: { - slaves: "slave platoon", - militia: "citizens' platoon", - mercs: "mercenary platoon" - } + smilingMan: {progress: 0} }); + for (const unit of App.SecExp.unit.list()) { + App.SecExp.unit.gen(unit); + } App.SecExp.initTrade(); }; @@ -613,44 +605,33 @@ App.SecExp.battle = (function() { * @returns {number} unit count */ function deployedUnits(input = '') { - let bots = 0, militiaC = 0, slavesC = 0, mercsC = 0, init = 0; - if (V.slaveRebellion !== 1 && V.citizenRebellion !== 1) { // attack - if (V.secBots.isDeployed > 0) { - bots++; + let count = {}, init = 0; + App.SecExp.unit.list().forEach(s => { count[s] = 0; }); + if (V.slaveRebellion === 0 && V.citizenRebellion === 0) { // attack + if (V.SecExp.units.bots.isDeployed > 0) { + count.bots++; } if (V.SF.Toggle && V.SF.Active >= 1 && V.SecExp.war.deploySF) { init++; } - - militiaC += V.militiaUnits.filter((u) => u.isDeployed === 1).length; - slavesC += V.slaveUnits.filter((u) => u.isDeployed === 1).length; - mercsC += V.mercUnits.filter((u) => u.isDeployed === 1).length; } else { // rebellion - if (V.secBots.active > 0) { - bots++; + if (V.SecExp.units.bots.active > 0) { + count.bots++; } if (V.SF.Toggle && V.SF.Active >= 1) { init++; } if (V.SecExp.war.irregulars > 0) { - militiaC++; + count.militia++; } - - militiaC += V.militiaUnits.filter((u) => u.active === 1 && !V.SecExp.war.rebellingID.includes(u.ID)).length; - slavesC += V.slaveUnits.filter((u) => u.active === 1 && !V.SecExp.war.rebellingID.includes(u.ID)).length; - mercsC += V.mercUnits.filter((u) => u.active === 1 && !V.SecExp.war.rebellingID.includes(u.ID)).length; } + + App.SecExp.unit.list().slice(1).forEach(s => { count[s] += V.SecExp.units[s].squads.filter((u) => App.SecExp.unit.isDeployed(u)).length; }); if (input === '') { - return bots + militiaC + slavesC + mercsC + init; - } else if (input === 'bots') { - return bots; - } else if (input === 'militia') { - return militiaC; - } else if (input === 'slaves') { - return slavesC; - } else if (input === 'mercs') { - return mercsC; + return Object.values(count).reduce((a, b) => a + b) + init; + } else { + return count[input]; } } @@ -662,7 +643,8 @@ App.SecExp.battle = (function() { /** @param {function(FC.SecExp.PlayerHumanUnitData) : boolean} pred */ function countHumanTroops(pred) { - const arrays = [V.militiaUnits, V.slaveUnits, V.mercUnits]; + let arrays = []; + Object.values(V.SecExp.units).slice(1).forEach(s => { arrays.push(s.squads); }); for (const arr of arrays) { for (const unit of arr) { if (pred(unit)) { @@ -672,9 +654,9 @@ App.SecExp.battle = (function() { } } - if (V.slaveRebellion !== 1 && V.citizenRebellion !== 1) { // attack - if (V.secBots.isDeployed === 1) { - troops += V.secBots.troops; + if (V.slaveRebellion === 0 && V.citizenRebellion === 0) { // attack + if (V.SecExp.units.bots.isDeployed === 1) { + troops += V.SecExp.units.bots.troops; } countHumanTroops((u) => u.isDeployed === 1); if (V.SF.Toggle && V.SF.Active >= 1 && V.SecExp.war.deploySF) { @@ -684,8 +666,8 @@ App.SecExp.battle = (function() { if (V.SecExp.war.irregulars > 0) { troops += V.SecExp.war.irregulars; } - if (V.secBots.active === 1) { - troops += V.secBots.troops; + if (V.SecExp.units.bots.active === 1) { + troops += V.SecExp.units.bots.troops; } countHumanTroops((u) => u.active === 1 && !V.SecExp.war.rebellingID.includes(u.ID)); if (V.SF.Toggle && V.SF.Active >= 1) { @@ -725,27 +707,12 @@ App.SecExp.battle = (function() { */ function deployableUnits() { let init = 2 * App.SecExp.battle.deploySpeed(); - if (V.secBots.isDeployed > 0) { + if (V.SecExp.units.bots.isDeployed > 0) { init--; } - const Militia = V.militiaUnits.length; - for (let i = 0; i < Militia; i++) { - if (V.militiaUnits[i].isDeployed > 0) { - init--; - } - } - - const Slaves = V.slaveUnits.length; - for (let i = 0; i < Slaves; i++) { - if (V.slaveUnits[i].isDeployed > 0) { - init--; - } - } - - const Mercs = V.mercUnits.length; - for (let i = 0; i < Mercs; i++) { - if (V.mercUnits[i].isDeployed > 0) { + for (const squad of App.SecExp.unit.humanSquads()) { + if (squad.isDeployed > 0) { init--; } } @@ -757,7 +724,7 @@ App.SecExp.battle = (function() { * @returns {number} */ function activeUnits() { - return V.secBots.active + V.militiaUnits.length + V.slaveUnits.length + V.mercUnits.length; + return V.SecExp.units.bots.active + App.SecExp.unit.humanSquads().length; } /** Get maximum active units @@ -766,7 +733,7 @@ App.SecExp.battle = (function() { function maxUnits() { let max = 0; if (V.SecExp.buildings.barracks) { - max = 8 + (V.SecExp.buildings.barracks.size * 2); + max += 8 + (V.SecExp.buildings.barracks.size * 2); if (App.SecExp.battle.deploySpeed() === 10) { max += 2; } diff --git a/src/Mods/SecExp/js/secExpBC.js b/src/Mods/SecExp/js/secExpBC.js index ab7ac1ef1ae..3a3c9fe42af 100644 --- a/src/Mods/SecExp/js/secExpBC.js +++ b/src/Mods/SecExp/js/secExpBC.js @@ -75,58 +75,46 @@ App.SecExp.generalBC = function() { V.SecExp.edicts.defense.privilege.slaveSoldier = V.SecExp.edicts.defense.privilege.slaveSoldier || V.slaveSoldier || 0; V.SecExp.edicts.defense.privilege.mercSoldier = V.SecExp.edicts.defense.privilege.mercSoldier || V.mercSoldier || 0; - V.SecExp.defaultNames = V.SecExp.defaultNames || {}; - V.SecExp.defaultNames.slaves = V.SecExp.defaultNames.slaves || "slave platoon"; - V.SecExp.defaultNames.militia = V.SecExp.defaultNames.militia || "citizens' platoon"; - if (jsDef(V.SecExp.defaultNames.milita)) { - V.SecExp.defaultNames.militia = V.SecExp.defaultNames.milita; - delete V.SecExp.defaultNames.milita; - } - V.SecExp.defaultNames.mercs = V.SecExp.defaultNames.mercs || "mercenary platoon"; - - // V.SecExp.units = V.SecExp.units || {}; - Object.assign(V.secBots, { - active: Math.max(0, V.secBots.active) || V.arcologyUpgrade.drones > 0 ? 1 : 0, - ID: -1, - isDeployed: V.secBots.isDeployed || 0, - troops: Math.max(V.secBots.troops || 0, V.arcologyUpgrade.drones > 0 ? 30 : 0), - maxTroops: Math.max(V.secBots.maxTroops || 0, V.arcologyUpgrade.drones > 0 ? 30 : 0) - }); - /* if (V.secBots) { + V.SecExp.units = V.SecExp.units || {}; + V.SecExp.units.bots = V.SecExp.units.bots || {}; + V.SecExp.units.bots.active = Math.max(0, V.SecExp.units.bots.active) || V.arcologyUpgrade.drones > 0 ? 1 : 0; + V.SecExp.units.bots.ID = -1; + V.SecExp.units.bots.isDeployed = V.SecExp.units.bots.isDeployed || 0; + V.SecExp.units.bots.troops = Math.max(V.SecExp.units.bots.troops || 0, V.arcologyUpgrade.drones > 0 ? 30 : 0); + V.SecExp.units.bots.maxTroops = Math.max(V.SecExp.units.bots.maxTroops || 0, V.arcologyUpgrade.drones > 0 ? 30 : 0); + V.SecExp.units.bots.equip = V.SecExp.units.bots.equip || 0; + if (V.secBots) { V.SecExp.units.bots = V.secBots; } - */ - // V.SecExp.units.slaves = V.SecExp.units.slaves || {}; - // V.SecExp.units.slaves.casualties = V.SecExp.units.slaves.casualties || V.slavesTotalCasualties || 0; - // V.SecExp.units.slaves.created = V.SecExp.units.slaves.created || V.createdSlavesUnits || 0; - // V.SecExp.units.slaves.sqauds = V.SecExp.units.slaves.sqauds || V.slaveUnits || []; - for (let i = 0; i < V.slaveUnits; i++) { - App.SecExp.fixBrokenUnit(V.slaveUnits[i]); - } - - // V.SecExp.units.milita = V.SecExp.units.milita || {}; - // V.SecExp.units.milita.created = V.SecExp.units.milita.created || V.createdMilitiaUnits || 0; - // V.SecExp.units.milita.free = V.SecExp.units.milita.free || V.militiaFreeManpower || 0; - // V.SecExp.units.milita.casualties = V.SecExp.units.milita.casualties || V.militiaTotalCasualties || 0; - // V.SecExp.units.milita.sqauds = V.SecExp.units.milita.sqauds || V.militiaUnits || []; - for (let i = 0; i < V.militiaUnits; i++) { - App.SecExp.fixBrokenUnit(V.militiaUnits[i]); - } - - // V.SecExp.units.mercs = V.SecExp.units.mercs || {}; - // V.SecExp.units.mercs.created = V.SecExp.units.mercs.created || V.createdMercUnits || 0; - // V.SecExp.units.mercs.free = V.SecExp.units.mercs.free || V.mercFreeManpower || 0; - if (V.mercFreeManpower === 0) { + + App.SecExp.unit.gen('slaves', {count: V.createdSlavesUnits, killed: V.slavesTotalCasualties, squads: V.slaveUnits}); + V.SecExp.units.slaves.defaultName = V.SecExp.units.slaves.defaultName || "slave platoon"; + + App.SecExp.unit.gen('militia', {count: V.createdMilitiaUnits, killed: V.militiaTotalCasualties, squads: V.militiaUnits, free: V.militiaFreeManpower}); + V.SecExp.units.militia.defaultName = V.SecExp.units.militia.defaultName || "citizens' platoon"; + if (jsDef(V.SecExp.defaultNames) && (V.SecExp.defaultNames.milita || V.SecExp.defaultNames.militia)) { + V.SecExp.units.militia.defaultName = V.SecExp.defaultNames.milita || V.SecExp.defaultNames.militia; + delete V.SecExp.defaultNames.milita; delete V.SecExp.defaultNames.militia; + } + + App.SecExp.unit.gen('mercs', {count: V.createdMercUnits, killed: V.mercTotalCasualties, squads: V.mercUnits, free: V.mercFreeManpower}); + V.SecExp.units.mercs.defaultName = V.SecExp.units.mercs.defaultName || "mercenary platoon"; + if (V.SecExp.units.mercs.free === 0) { if (V.mercenaries === 1) { - V.mercFreeManpower = 15; + V.SecExp.units.mercs.free = 15; } else if (V.mercenaries > 1) { - V.mercFreeManpower = 30; + V.SecExp.units.mercs.free = 30; } } - // V.SecExp.units.mercs.casualties = V.SecExp.units.mercs.casualties || V.mercTotalCasualties || 0; - // V.SecExp.units.mercs.sqauds = V.SecExp.units.mercs.sqauds || V.mercUnits || []; - for (let i = 0; i < V.mercUnits; i++) { - App.SecExp.fixBrokenUnit(V.mercUnits[i]); + + for (const squad of App.SecExp.unit.humanSquads()) { + App.SecExp.unit.fixBroken(squad); + } + + if (V.SecExp.defaultNames) { + V.SecExp.units.slaves.defaultName = V.SecExp.defaultNames.slaves; + V.SecExp.units.mercs.defaultName = V.SecExp.defaultNames.mercs; + delete V.SecExp.defaultNames; } V.SecExp.smilingMan = V.SecExp.smilingMan || {}; diff --git a/src/Mods/SecExp/js/securityReport.js b/src/Mods/SecExp/js/securityReport.js index 3f655213831..8a7ee5f3cde 100644 --- a/src/Mods/SecExp/js/securityReport.js +++ b/src/Mods/SecExp/js/securityReport.js @@ -386,7 +386,7 @@ App.SecExp.securityReport = function() { const recruits = Math.trunc((recruitLimit * V.ACitizens - App.SecExp.Manpower.totalMilitia) / 20 * recruitsMultiplier); if (recruits > 0) { - V.militiaFreeManpower += recruits; + V.SecExp.units.militia.free += recruits; r.push(`This week ${recruits} citizens joined the militia.<br>`); } else if (V.SecExp.edicts.defense.militia === 5) { r.push(`No citizens joined your militia this week because your society is as militarized as it can get.<br>`); @@ -441,23 +441,19 @@ App.SecExp.securityReport = function() { } newMercs = Math.trunc(newMercs / 2); if (newMercs > 0) { - V.mercFreeManpower += newMercs; + V.SecExp.units.mercs.free += newMercs; r.push(`This week ${newMercs} mercenaries reached the arcology.<br>`); } else { r.push(`This week no new mercenaries reached the arcology.<br>`); } - V.mercFreeManpower = Math.clamp(V.mercFreeManpower, 0, 2000); + V.SecExp.units.mercs.free = Math.clamp(V.SecExp.units.mercs.free, 0, 2000); } if (activeUnits > 0) { // loyalty and training - for (const unit of V.slaveUnits) { - r.push(App.SecExp.humanUnitLoyaltyChanges(unit, 'slave')); - } - for (const unit of V.militiaUnits) { - r.push(App.SecExp.humanUnitLoyaltyChanges(unit, 'citizens')); - } - for (const unit of V.mercUnits) { - r.push(App.SecExp.humanUnitLoyaltyChanges(unit, 'mercenary')); + for (const unit of App.SecExp.unit.list().slice(1)) { + for (const squad of V.SecExp.units[unit].squads) { + r.push(App.SecExp.unit.humanLoyaltyChanges(squad, unit)); + } } } } diff --git a/src/Mods/SecExp/miscSecExpWidgets.tw b/src/Mods/SecExp/miscSecExpWidgets.tw deleted file mode 100644 index b79afeb83c3..00000000000 --- a/src/Mods/SecExp/miscSecExpWidgets.tw +++ /dev/null @@ -1,111 +0,0 @@ -:: miscSecExpWidgets [widget nobr] - -<<widget "fixBrokenStats">> - <<if !Number.isInteger($mercTotalCasualties)>> - <<set $mercTotalCasualties = 0>> - <</if>> - <<if !Number.isInteger($slavesTotalCasualties)>> - <<set $slavesTotalCasualties = 0>> - <</if>> - <<if !Number.isInteger($militiaTotalCasualties)>> - <<set $militiaTotalCasualties = 0>> - <</if>> - <<if !Number.isInteger($militiaFreeManpower)>> - <<set $militiaFreeManpower = 0>> - <</if>> -<</widget>> - -<<widget "replenishAllUnits">> - <<set _hasLossesBots = 0, _hasLossesM = 0, _hasLossesS = 0, _hasLossesMe = 0>> - - <<if $secBots.troops < $secBots.maxTroops && $cash >= 500>> - <<set _hasLossesBots = 1>> - <</if>> - - <<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $militiaUnits[_i].troops < $militiaUnits[_i].maxTroops && $militiaFreeManpower > 0>> - <<set _hasLossesM = 1>> - <<break>> - <</if>> - <</for>> - - <<for _i = 0; _i < $slaveUnits.length; _i++>> - <<if $slaveUnits[_i].troops < $slaveUnits[_i].maxTroops && $menials > 0>> - <<set _hasLossesS = 1>> - <<break>> - <</if>> - <</for>> - - <<for _i = 0; _i < $mercUnits.length; _i++>> - <<if $mercUnits[_i].troops < $mercUnits[_i].maxTroops && $mercFreeManpower > 0>> - <<set _hasLossesMe = 1>> - <<break>> - <</if>> - <</for>> - - <<if _hasLossesBots == 1 || _hasLossesM == 1 || _hasLossesS == 1 || _hasLossesMe == 1>> - <<link "Replenish all units">> - <<if _hasLossesBots == 1>> - <<run cashX(-(($secBots.maxTroops - $secBots.troops) * 500), "securityExpansion")>> - <<set $secBots.troops = $secBots.maxTroops>> - <</if>> - - <<if _hasLossesM == 1>> - <<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $militiaUnits[_i].troops < $militiaUnits[_i].maxTroops && $militiaFreeManpower > 0>> - <<if $militiaFreeManpower >= $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>> - <<set $militiaFreeManpower -= $militiaUnits[_i].maxTroops - $militiaUnits[_i].troops>> - <<set _expLoss = ($militiaUnits[_i].maxTroops - $militiaUnits[_i].troops) / $militiaUnits[_i].troops>> - <<set $militiaUnits[_i].training -= $militiaUnits[_i].training * _expLoss>> - <<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>> - <<else>> - <<set _expLoss = $militiaFreeManpower / $militiaUnits[_i].troops>> - <<set $militiaUnits[_i].training -= $militiaUnits[_i].training * _expLoss>> - <<set $militiaUnits[_i].troops += $militiaFreeManpower>> - <<set $militiaFreeManpower = 0>> - <</if>> - <</if>> - <</for>> - <</if>> - - <<if _hasLossesS == 1>> - <<for _i = 0; _i < $slaveUnits.length; _i++>> - <<if $slaveUnits[_i].troops < $slaveUnits[_i].maxTroops && $menials > 0>> - <<if $menials >= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>> - <<set $menials -= $slaveUnits[_i].maxTroops - $slaveUnits[_i].troops>> - <<set _expLoss = ($slaveUnits[_i].maxTroops - $slaveUnits[_i].troops) / $slaveUnits[_i].troops>> - <<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>> - <<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>> - <<else>> - <<set _expLoss = $menials / $slaveUnits[_i].troops>> - <<set $slaveUnits[_i].training -= $slaveUnits[_i].training * _expLoss>> - <<set $slaveUnits[_i].troops += $menials>> - <<set $menials = 0>> - <</if>> - <</if>> - <</for>> - <</if>> - - <<if _hasLossesMe == 1>> - <<for _i = 0; _i < $mercUnits.length; _i++>> - <<if $mercUnits[_i].troops < $mercUnits[_i].maxTroops && $mercFreeManpower > 0>> - <<if $mercFreeManpower >= $mercUnits[_i].maxTroops - $mercUnits[_i].troops>> - <<set $mercFreeManpower -= $mercUnits[_i].maxTroops - $mercUnits[_i].troops>> - <<set _expLoss = ($mercUnits[_i].maxTroops - $mercUnits[_i].troops) / $mercUnits[_i].troops>> - <<set $mercUnits[_i].training -= $mercUnits[_i].training * _expLoss>> - <<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>> - <<else>> - <<set _expLoss = $mercFreeManpower / $mercUnits[_i].troops>> - <<set $mercUnits[_i].training -= $mercUnits[_i].training * _expLoss>> - <<set $mercUnits[_i].troops += $mercFreeManpower>> - <<set $mercFreeManpower = 0>> - <</if>> - <</if>> - <</for>> - <</if>> - - <<= SugarCube.Engine.play(passage())>> - <</link>> - //Will replenish units as long as requirements are met.//<br> - <</if>> -<</widget>> \ No newline at end of file diff --git a/src/Mods/SecExp/rebellionHandler.tw b/src/Mods/SecExp/rebellionHandler.tw index aaeae9668b5..616d38db20b 100644 --- a/src/Mods/SecExp/rebellionHandler.tw +++ b/src/Mods/SecExp/rebellionHandler.tw @@ -47,31 +47,31 @@ <<set _hp += _unit.hp>> <</if>> -<<if $secBots.active == 1>> +<<if $SecExp.units.bots.active == 1>> <<set _unit = App.SecExp.getUnit("Bots")>> <<set _attack += _unit.attack>> <<set _defense += _unit.defense>> <<set _hp += _unit.hp>> <</if>> -<<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $militiaUnits[_i].active == 1 && (!$SecExp.war.rebellingID.includes($militiaUnits[_i].ID))>> +<<for _i = 0; _i < $SecExp.units.militia.squads.length; _i++>> + <<if $SecExp.units.militia.squads[_i].active == 1 && (!$SecExp.war.rebellingID.includes($SecExp.units.militia.squads[_i].ID))>> <<set _unit = App.SecExp.getUnit("Militia", _i)>> <<set _attack += _unit.attack>> <<set _defense += _unit.defense>> <<set _hp += _unit.hp>> <</if>> <</for>> -<<for _i = 0; _i < $slaveUnits.length; _i++>> - <<if $slaveUnits[_i].active == 1 && (!$SecExp.war.rebellingID.includes($slaveUnits[_i].ID))>> +<<for _i = 0; _i < $SecExp.units.slaves.squads.length; _i++>> + <<if $SecExp.units.slaves.squads[_i].active == 1 && (!$SecExp.war.rebellingID.includes($SecExp.units.slaves.squads[_i].ID))>> <<set _unit = App.SecExp.getUnit("Slaves", _i)>> <<set _attack += _unit.attack>> <<set _defense += _unit.defense>> <<set _hp += _unit.hp>> <</if>> <</for>> -<<for _i = 0; _i < $mercUnits.length; _i++>> - <<if $mercUnits[_i].active == 1 && (!$SecExp.war.rebellingID.includes($mercUnits[_i].ID))>> +<<for _i = 0; _i < $SecExp.units.mercs.squads.length; _i++>> + <<if $SecExp.units.mercs.squads[_i].active == 1 && (!$SecExp.war.rebellingID.includes($SecExp.units.mercs.squads[_i].ID))>> <<set _unit = App.SecExp.getUnit("Mercs", _i)>> <<set _attack += _unit.attack>> <<set _defense += _unit.defense>> @@ -114,10 +114,10 @@ <<set _moraleTroopMod = Math.clamp(App.SecExp.battle.troopCount() / 100,1,10)>> /* morale and baseHp calculation */ -<<set _morale += (App.SecExp.BaseDroneUnit.morale * $secBots.active + App.SecExp.BaseMilitiaUnit.morale * App.SecExp.battle.deployedUnits('militia') + App.SecExp.BaseSlaveUnit.morale * App.SecExp.battle.deployedUnits('slaves') + App.SecExp.BaseMercUnit.morale * App.SecExp.battle.deployedUnits('mercs') + App.SecExp.BaseSpecialForcesUnit.morale * $SF.Active) / ($secBots.active + App.SecExp.battle.deployedUnits('militia') + App.SecExp.battle.deployedUnits('slaves') + App.SecExp.battle.deployedUnits('mercs') + $SF.Active)>> +<<set _morale += (App.SecExp.BaseDroneUnit.morale * $SecExp.units.bots.active + App.SecExp.BaseMilitiaUnit.morale * App.SecExp.battle.deployedUnits('militia') + App.SecExp.BaseSlaveUnit.morale * App.SecExp.battle.deployedUnits('slaves') + App.SecExp.BaseMercUnit.morale * App.SecExp.battle.deployedUnits('mercs') + App.SecExp.BaseSpecialForcesUnit.morale * $SF.Active) / ($SecExp.units.bots.active + App.SecExp.battle.deployedUnits('militia') + App.SecExp.battle.deployedUnits('slaves') + App.SecExp.battle.deployedUnits('mercs') + $SF.Active)>> <<set _morale += _morale * $SecExp.buildings.barracks ? $SecExp.buildings.barracks.luxury * 0.05 : 0>> /* barracks bonus */ <<set _morale *= _moraleTroopMod>> -<<set _baseHp = (App.SecExp.BaseDroneUnit.hp * $secBots.active + App.SecExp.BaseMilitiaUnit.hp * App.SecExp.battle.deployedUnits('militia') + App.SecExp.BaseSlaveUnit.hp * App.SecExp.battle.deployedUnits('slaves') + App.SecExp.BaseMercUnit.hp * App.SecExp.battle.deployedUnits('mercs') + App.SecExp.BaseSpecialForcesUnit.hp * $SF.Active) / ($secBots.active + App.SecExp.battle.deployedUnits('militia') + App.SecExp.battle.deployedUnits('slaves') + App.SecExp.battle.deployedUnits('mercs') + $SF.Active)>> +<<set _baseHp = (App.SecExp.BaseDroneUnit.hp * $SecExp.units.bots.active + App.SecExp.BaseMilitiaUnit.hp * App.SecExp.battle.deployedUnits('militia') + App.SecExp.BaseSlaveUnit.hp * App.SecExp.battle.deployedUnits('slaves') + App.SecExp.BaseMercUnit.hp * App.SecExp.battle.deployedUnits('mercs') + App.SecExp.BaseSpecialForcesUnit.hp * $SF.Active) / ($SecExp.units.bots.active + App.SecExp.battle.deployedUnits('militia') + App.SecExp.battle.deployedUnits('slaves') + App.SecExp.battle.deployedUnits('mercs') + $SF.Active)>> /* calculates rebelling army stats */ <<if $week <= 30>> @@ -145,33 +145,33 @@ <<set _enemyDefense += _unit.defense * _armyMod>> <<set _enemyHp += _unit.hp>> -<<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $militiaUnits[_i].active == 1 && $SecExp.war.rebellingID.includes($militiaUnits[_i].ID)>> +<<for _i = 0; _i < $SecExp.units.militia.squads.length; _i++>> + <<if $SecExp.units.militia.squads[_i].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.militia.squads[_i].ID)>> <<set _rebellingMilitia = 1>> - <<set $SecExp.war.attacker.troops += $militiaUnits[_i].troops>> - <<set $militiaUnits[_i].loyalty = 0>> + <<set $SecExp.war.attacker.troops += $SecExp.units.militia.squads[_i].troops>> + <<set $SecExp.units.militia.squads[_i].loyalty = 0>> <<set _unit = App.SecExp.getUnit("Militia", _i)>> <<set _enemyAttack += _unit.attack>> <<set _enemyDefense += _unit.defense>> <<set _enemyHp += _unit.hp>> <</if>> <</for>> -<<for _i = 0; _i < $slaveUnits.length; _i++>> - <<if $slaveUnits[_i].active == 1 && $SecExp.war.rebellingID.includes($slaveUnits[_i].ID)>> +<<for _i = 0; _i < $SecExp.units.slaves.squads.length; _i++>> + <<if $SecExp.units.slaves.squads[_i].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.slaves.squads[_i].ID)>> <<set _rebellingSlaves = 1>> - <<set $SecExp.war.attacker.troops += $slaveUnits[_i].troops>> - <<set $slaveUnits[_i].loyalty = 0>> + <<set $SecExp.war.attacker.troops += $SecExp.units.slaves.squads[_i].troops>> + <<set $SecExp.units.slaves.squads[_i].loyalty = 0>> <<set _unit = App.SecExp.getUnit("Slaves", _i)>> <<set _enemyAttack += _unit.attack>> <<set _enemyDefense += _unit.defense>> <<set _enemyHp += _unit.hp>> <</if>> <</for>> -<<for _i = 0; _i < $mercUnits.length; _i++>> - <<if $mercUnits[_i].active == 1 && $SecExp.war.rebellingID.includes($mercUnits[_i].ID)>> +<<for _i = 0; _i < $SecExp.units.mercs.squads.length; _i++>> + <<if $SecExp.units.mercs.squads[_i].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.mercs.squads[_i].ID)>> <<set _rebellingMercs = 1>> - <<set $SecExp.war.attacker.troops += $mercUnits[_i].troops>> - <<set $mercUnits[_i].loyalty = 0>> + <<set $SecExp.war.attacker.troops += $SecExp.units.mercs.squads[_i].troops>> + <<set $SecExp.units.mercs.squads[_i].loyalty = 0>> <<set _unit = App.SecExp.getUnit("Mercs", _i)>> <<set _enemyAttack += _unit.attack>> <<set _enemyDefense += _unit.defense>> diff --git a/src/Mods/SecExp/rebellionOptions.tw b/src/Mods/SecExp/rebellionOptions.tw index 8dec36223fc..5414599c252 100644 --- a/src/Mods/SecExp/rebellionOptions.tw +++ b/src/Mods/SecExp/rebellionOptions.tw @@ -1,7 +1,7 @@ :: rebellionOptions [nobr] <<set $nextButton = " ", $encyclopedia = "Battles">> -<<set _isSlaveRebellion = $slaveRebellion === 1, _loyalUnits = $militiaUnits.length + $slaveUnits.length + $mercUnits.length - $SecExp.war.rebellingID.length>> +<<set _isSlaveRebellion = $slaveRebellion === 1, _loyalUnits = App.SecExp.unit.list().slice(1).reduce((acc, cur) => {acc + V.SecExp.units[cur].squads.length;}, 0) - $SecExp.war.rebellingID.length>> <strong> <<if _isSlaveRebellion>>Slave<<else>>Citizen<</if>> Rebellion!</strong> <hr> @@ -27,68 +27,29 @@ It appears <strong><<print num(Math.trunc($SecExp.war.attacker.troops))>></stron <<set _count = 0>> <<if $SecExp.war.rebellingID.length > 0>> <br><br> - <<for _unit range $militiaUnits>> - <<if _unit.active == 1 && ($SecExp.war.rebellingID.includes(_unit.ID))>> + <<for _squad range App.SecExp.unit.humanSquads()>> + <<if _squad.active == 1 && ($SecExp.war.rebellingID.includes(_squad.ID))>> <<set _count++>> <<if _count < $SecExp.war.rebellingID.length>> - _unit.platoonName, + _squad.platoonName, <<else>> - _unit.platoonName - <</if>> - <</if>> - <</for>> - <<for _unit range $slaveUnits>> - <<if _unit.active == 1 && ($SecExp.war.rebellingID.includes(_unit.ID))>> - <<set _count++>> - <<if _count < $SecExp.war.rebellingID.length>> - _unit.platoonName, - <<else>> - _unit.platoonName - <</if>> - <</if>> - <</for>> - <<for _unit range $mercUnits>> - <<if _unit.active == 1 && ($SecExp.war.rebellingID.includes(_unit.ID))>> - <<set _count++>> - <<if _count < $SecExp.war.rebellingID.length>> - _unit.platoonName, - <<else>> - _unit.platoonName + _squad.platoonName <</if>> <</if>> <</for>> betrayed you and joined the insurrection. <</if>> <<set _count = 0, _dualUnits = $arcologyUpgrade.drones === 1 && $SF.Toggle && $SF.Active >= 1>> -<br><br> <<if $arcologyUpgrade.drones === 1>>Your security drones<</if>><<if _loyalUnits > 0>>,<</if>> +<br><br> <<if $arcologyUpgrade.drones === 1>>Your security drones<</if>> <<if _loyalUnits > 0>> - <<for _unit range $militiaUnits>> - <<if _unit.active == 1 && (!$SecExp.war.rebellingID.includes(_unit.ID))>> - <<set _count++>> - <<if _count < _loyalUnits>> - _unit.platoonName, - <<else>> - _unit.platoonName - <</if>> - <</if>> - <</for>> - <<for _unit range $slaveUnits>> - <<if _unit.active == 1 && (!$SecExp.war.rebellingID.includes(_unit.ID))>> - <<set _count++>> - <<if _count < _loyalUnits>> - _unit.platoonName, - <<else>> - _unit.platoonName - <</if>> - <</if>> - <</for>> - <<for _unit range $mercUnits>> - <<if _unit.active == 1 && (!$SecExp.war.rebellingID.includes(_unit.ID))>> + , + <<for _squad range App.SecExp.unit.humanSquads()>> + <<if _squad.active == 1 && (!$SecExp.war.rebellingID.includes(_squad.ID))>> <<set _count++>> <<if _count < _loyalUnits>> - _unit.platoonName, + _squad.platoonName, <<else>> - _unit.platoonName + _squad.platoonName <</if>> <</if>> <</for>> @@ -144,6 +105,6 @@ In order to preserve the structural integrity of the building and the lives of o [[Discard the order|rebellionOptions][$garrison.waterway = 0]] <</if>> -<br><br> <<replenishAllUnits>> <br> +<br><br> <<includeDOM App.SecExp.unit.replenishAll()>> [[Proceed|rebellionHandler][$SecExp.war.result = 4, $foughtThisWeek = 1]] /* sets $SecExp.war.result to a value outside accepted range (-3,3) to avoid evaluation problems */ -<br>[[Surrender|rebellionReport][$SecExp.war.result = -1, $foughtThisWeek = 1]] \ No newline at end of file +<br>[[Surrender|rebellionReport][$SecExp.war.result = -1, $foughtThisWeek = 1]] diff --git a/src/Mods/SecExp/unitsBattleReport.tw b/src/Mods/SecExp/unitsBattleReport.tw index 871323bcdc4..67744f41dee 100644 --- a/src/Mods/SecExp/unitsBattleReport.tw +++ b/src/Mods/SecExp/unitsBattleReport.tw @@ -8,42 +8,42 @@ <br><<print num($SF.ArmySize)>> soldiers from $SF.Lower joined the battle: no casualties suffered. <</if>> <<if App.SecExp.battle.deployedUnits('militia') >= 1>> - <<for _j = 0; _j < $militiaUnits.length; _j++>> - <<if $militiaUnits[_j].isDeployed == 1>> - <br>$militiaUnits[_j].platoonName: no casualties. - <<set $militiaUnits[_j].battlesFought++>> - <<if $militiaUnits[_j].training < 100>> + <<for _j = 0; _j < $SecExp.units.militia.squads.length; _j++>> + <<if $SecExp.units.militia.squads[_j].isDeployed == 1>> + <br>$SecExp.units.militia.squads[_j].platoonName: no casualties. + <<set $SecExp.units.militia.squads[_j].battlesFought++>> + <<if $SecExp.units.militia.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience has increased. - <<set $militiaUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.militia.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> <</if>> <</for>> <</if>> <<if App.SecExp.battle.deployedUnits('slaves') >= 1>> - <<for _j = 0; _j < $slaveUnits.length; _j++>> - <<if $slaveUnits[_j].isDeployed == 1>> - <br>$slaveUnits[_j].platoonName: no casualties. - <<set $slaveUnits[_j].battlesFought++>> - <<if $slaveUnits[_j].training < 100>> + <<for _j = 0; _j < $SecExp.units.slaves.squads.length; _j++>> + <<if $SecExp.units.slaves.squads[_j].isDeployed == 1>> + <br>$SecExp.units.slaves.squads[_j].platoonName: no casualties. + <<set $SecExp.units.slaves.squads[_j].battlesFought++>> + <<if $SecExp.units.slaves.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience has increased. - <<set $slaveUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.slaves.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> <</if>> <</for>> <</if>> <<if App.SecExp.battle.deployedUnits('mercs') >= 1>> - <<for _j = 0; _j < $mercUnits.length; _j++>> - <<if $mercUnits[_j].isDeployed == 1>> - <br>$mercUnits[_j].platoonName: no casualties. - <<set $mercUnits[_j].battlesFought++>> - <<if $mercUnits[_j].training < 100>> + <<for _j = 0; _j < $SecExp.units.mercs.squads.length; _j++>> + <<if $SecExp.units.mercs.squads[_j].isDeployed == 1>> + <br>$SecExp.units.mercs.squads[_j].platoonName: no casualties. + <<set $SecExp.units.mercs.squads[_j].battlesFought++>> + <<if $SecExp.units.mercs.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience has increased. - <<set $mercUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.mercs.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> <</if>> @@ -92,25 +92,25 @@ /* assigns the losses and notify the player */ <<if App.SecExp.battle.deployedUnits('bots')>> <<set _loss = _lossesList.pluck()>> - <<set _loss = Math.clamp(_loss,0,$secBots.troops)>> - <<set $secBots.troops -= _loss>> + <<set _loss = Math.clamp(_loss,0,$SecExp.units.bots.troops)>> + <<set $SecExp.units.bots.troops -= _loss>> <br>Security drones: <<if _loss <= 0>> no casualties - <<elseif _loss <= $secBots.troops * 0.2>> + <<elseif _loss <= $SecExp.units.bots.troops * 0.2>> light casualties - <<elseif _loss <= $secBots.troops * 0.4>> + <<elseif _loss <= $SecExp.units.bots.troops * 0.4>> moderate casualties - <<elseif _loss <= $secBots.troops * 0.6>> + <<elseif _loss <= $SecExp.units.bots.troops * 0.6>> heavy casualties <<else>> catastrophic casualties <</if>> suffered. - <<if $secBots.troops <= 5>> - <<set $secBots.active = 0>> + <<if $SecExp.units.bots.troops <= 5>> + <<set $SecExp.units.bots.active = 0>> Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. It will take quite the investment to rebuild them. - <<elseif $secBots.troops <= 10>> + <<elseif $SecExp.units.bots.troops <= 10>> The unit has very few operatives left, it risks complete annihilation if deployed again. <</if>> <br> @@ -135,120 +135,120 @@ <br> <</if>> <<if App.SecExp.battle.deployedUnits('militia') >= 1>> - <<for _j = 0; _j < $militiaUnits.length; _j++>> - <<if $militiaUnits[_j].isDeployed == 1>> - <<set $militiaUnits[_j].battlesFought++>> + <<for _j = 0; _j < $SecExp.units.militia.squads.length; _j++>> + <<if $SecExp.units.militia.squads[_j].isDeployed == 1>> + <<set $SecExp.units.militia.squads[_j].battlesFought++>> <<set _loss = _lossesList.pluck()>> - <<set _loss = Math.clamp(_loss,0,$militiaUnits[_j].troops)>> - <br>$militiaUnits[_j].platoonName: + <<set _loss = Math.clamp(_loss,0,$SecExp.units.militia.squads[_j].troops)>> + <br>$SecExp.units.militia.squads[_j].platoonName: <<if _loss <= 0>> no casualties - <<elseif _loss <= $militiaUnits[_j].troops * 0.2>> + <<elseif _loss <= $SecExp.units.militia.squads[_j].troops * 0.2>> light casualties - <<elseif _loss <= $militiaUnits[_j].troops * 0.4>> + <<elseif _loss <= $SecExp.units.militia.squads[_j].troops * 0.4>> moderate casualties - <<elseif _loss <= $militiaUnits[_j].troops * 0.6>> + <<elseif _loss <= $SecExp.units.militia.squads[_j].troops * 0.6>> heavy casualties <<else>> catastrophic casualties <</if>> suffered. - <<set _med = Math.round(Math.clamp(_loss * $militiaUnits[_j].medics * 0.25,1,_loss))>> - <<if $militiaUnits[_j].medics == 1 && _loss > 0>> + <<set _med = Math.round(Math.clamp(_loss * $SecExp.units.militia.squads[_j].medics * 0.25,1,_loss))>> + <<if $SecExp.units.militia.squads[_j].medics == 1 && _loss > 0>> Some men were saved by their medics. <</if>> - <<set $militiaUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$militiaUnits[_j].maxTroops))>> - <<set $militiaTotalCasualties += Math.trunc(_loss - _med)>> - <<if $militiaUnits[_j].training < 100>> + <<set $SecExp.units.militia.squads[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$SecExp.units.militia.squads[_j].maxTroops))>> + <<set $SecExp.units.militia.dead += Math.trunc(_loss - _med)>> + <<if $SecExp.units.militia.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience has increased. - <<set $militiaUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.militia.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> - <<if $militiaUnits[_j].troops <= 5>> - <<set $militiaUnits[_j].active = 0>> + <<if $SecExp.units.militia.squads[_j].troops <= 5>> + <<set $SecExp.units.militia.squads[_j].active = 0>> <br>Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The remnants will be sent home honored as veterans or reorganized in a new unit. - <<elseif $militiaUnits[_j].troops <= 10>> + <<elseif $SecExp.units.militia.squads[_j].troops <= 10>> <br>The unit has very few operatives left, it risks complete annihilation if deployed again. <</if>> <</if>> <</for>> <</if>> <<if App.SecExp.battle.deployedUnits('slaves') >= 1>> - <<for _j = 0; _j < $slaveUnits.length; _j++>> - <<if $slaveUnits[_j].isDeployed == 1>> - <<set $slaveUnits[_j].battlesFought++>> + <<for _j = 0; _j < $SecExp.units.slaves.squads.length; _j++>> + <<if $SecExp.units.slaves.squads[_j].isDeployed == 1>> + <<set $SecExp.units.slaves.squads[_j].battlesFought++>> <<set _loss = _lossesList.pluck()>> - <<set _loss = Math.clamp(_loss,0,$slaveUnits[_j].troops)>> - <br>$slaveUnits[_j].platoonName: + <<set _loss = Math.clamp(_loss,0,$SecExp.units.slaves.squads[_j].troops)>> + <br>$SecExp.units.slaves.squads[_j].platoonName: <<if _loss <= 0>> no casualties - <<elseif _loss <= $slaveUnits[_j].troops * 0.2>> + <<elseif _loss <= $SecExp.units.slaves.squads[_j].troops * 0.2>> light casualties - <<elseif _loss <= $slaveUnits[_j].troops * 0.4>> + <<elseif _loss <= $SecExp.units.slaves.squads[_j].troops * 0.4>> moderate casualties - <<elseif _loss <= $slaveUnits[_j].troops * 0.6>> + <<elseif _loss <= $SecExp.units.slaves.squads[_j].troops * 0.6>> heavy casualties <<else>> catastrophic casualties <</if>> suffered. - <<set _med = Math.round(Math.clamp(_loss * $slaveUnits[_j].medics * 0.25,1,_loss))>> - <<if $slaveUnits[_j].medics == 1 && _loss > 0>> + <<set _med = Math.round(Math.clamp(_loss * $SecExp.units.slaves.squads[_j].medics * 0.25,1,_loss))>> + <<if $SecExp.units.slaves.squads[_j].medics == 1 && _loss > 0>> Some men were saved by their medics. <</if>> - <<set $slaveUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$slaveUnits[_j].maxTroops))>> - <<set $slavesTotalCasualties += Math.trunc(_loss - _med)>> - <<if $slaveUnits[_j].training < 100>> + <<set $SecExp.units.slaves.squads[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$SecExp.units.slaves.squads[_j].maxTroops))>> + <<set $SecExp.units.slaves.dead += Math.trunc(_loss - _med)>> + <<if $SecExp.units.slaves.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience has increased. - <<set $slaveUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.slaves.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> - <<if $slaveUnits[_j].troops <= 5>> - <<set $slaveUnits[_j].active = 0>> + <<if $SecExp.units.slaves.squads[_j].troops <= 5>> + <<set $SecExp.units.slaves.squads[_j].active = 0>> <br>Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The survivors will be sent home honored as veterans or reorganized in a new unit. - <<elseif $slaveUnits[_j].troops <= 10>> + <<elseif $SecExp.units.slaves.squads[_j].troops <= 10>> <br>The unit has very few operatives left, it risks complete annihilation if deployed again. <</if>> <</if>> <</for>> <</if>> <<if App.SecExp.battle.deployedUnits('mercs') >= 1>> - <<for _j = 0; _j < $mercUnits.length; _j++>> - <<if $mercUnits[_j].isDeployed == 1>> - <<set $mercUnits[_j].battlesFought++>> + <<for _j = 0; _j < $SecExp.units.mercs.squads.length; _j++>> + <<if $SecExp.units.mercs.squads[_j].isDeployed == 1>> + <<set $SecExp.units.mercs.squads[_j].battlesFought++>> <<set _loss = _lossesList.pluck()>> - <<set _loss = Math.clamp(_loss,0,$mercUnits[_j].troops)>> - <br>$mercUnits[_j].platoonName: + <<set _loss = Math.clamp(_loss,0,$SecExp.units.mercs.squads[_j].troops)>> + <br>$SecExp.units.mercs.squads[_j].platoonName: <<if _loss <= 0>> no casualties - <<elseif _loss <= $mercUnits[_j].troops * 0.2>> + <<elseif _loss <= $SecExp.units.mercs.squads[_j].troops * 0.2>> light casualties - <<elseif _loss <= $mercUnits[_j].troops * 0.4>> + <<elseif _loss <= $SecExp.units.mercs.squads[_j].troops * 0.4>> moderate casualties - <<elseif _loss <= $mercUnits[_j].troops * 0.6>> + <<elseif _loss <= $SecExp.units.mercs.squads[_j].troops * 0.6>> heavy casualties <<else>> catastrophic casualties <</if>> suffered. - <<set _med = Math.round(Math.clamp(_loss * $mercUnits[_j].medics * 0.25,1,_loss))>> - <<if $mercUnits[_j].medics == 1 && _loss > 0>> + <<set _med = Math.round(Math.clamp(_loss * $SecExp.units.mercs.squads[_j].medics * 0.25,1,_loss))>> + <<if $SecExp.units.mercs.squads[_j].medics == 1 && _loss > 0>> Some men were saved by their medics. <</if>> - <<set $mercUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$mercUnits[_j].maxTroops))>> - <<set $mercTotalCasualties += Math.trunc(_loss - _med)>> - <<if $mercUnits[_j].training < 100>> + <<set $SecExp.units.mercs.squads[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$SecExp.units.mercs.squads[_j].maxTroops))>> + <<set $SecExp.units.mercs.dead += Math.trunc(_loss - _med)>> + <<if $SecExp.units.mercs.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience has increased. - <<set $mercUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.mercs.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> - <<if $mercUnits[_j].troops <= 5>> - <<set $mercUnits[_j].active = 0>> + <<if $SecExp.units.mercs.squads[_j].troops <= 5>> + <<set $SecExp.units.mercs.squads[_j].active = 0>> <br>Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The remnants will be sent home honored as veterans or reorganized in a new unit. - <<elseif $mercUnits[_j].troops <= 10>> + <<elseif $SecExp.units.mercs.squads[_j].troops <= 10>> <br>The unit has very few operatives left, it risks complete annihilation if deployed again. <</if>> <</if>> diff --git a/src/Mods/SecExp/unitsRebellionReport.tw b/src/Mods/SecExp/unitsRebellionReport.tw index 4d9efb039a6..f017ea8c6fb 100644 --- a/src/Mods/SecExp/unitsRebellionReport.tw +++ b/src/Mods/SecExp/unitsRebellionReport.tw @@ -11,39 +11,39 @@ <br>$SF.Lower, <<print num($SF.ArmySize)>> strong, was called to join the battle: no casualties suffered. <</if>> <<set _count = 0>> - <<set _loyalUnits = $militiaUnits.length + $slaveUnits.length + $mercUnits.length - $SecExp.war.rebellingID.length>> + <<set _loyalUnits = $SecExp.units.militia.squads.length + $SecExp.units.slaves.squads.length + $SecExp.units.mercs.squads.length - $SecExp.war.rebellingID.length>> <<if _loyalUnits > 0>> <p> - <<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $militiaUnits[_i].active == 1 && (!$SecExp.war.rebellingID.includes($militiaUnits[_i].ID))>> - <<set $militiaUnits[_i].battlesFought++>> + <<for _i = 0; _i < $SecExp.units.militia.squads.length; _i++>> + <<if $SecExp.units.militia.squads[_i].active == 1 && (!$SecExp.war.rebellingID.includes($SecExp.units.militia.squads[_i].ID))>> + <<set $SecExp.units.militia.squads[_i].battlesFought++>> <<set _count++>> <<if _count < _loyalUnits>> - $militiaUnits[_i].platoonName, + $SecExp.units.militia.squads[_i].platoonName, <<else>> - $militiaUnits[_i].platoonName + $SecExp.units.militia.squads[_i].platoonName <</if>> <</if>> <</for>> - <<for _i = 0; _i < $slaveUnits.length; _i++>> - <<if $slaveUnits[_i].active == 1 && (!$SecExp.war.rebellingID.includes($slaveUnits[_i].ID))>> - <<set $slaveUnits[_i].battlesFought++>> + <<for _i = 0; _i < $SecExp.units.slaves.squads.length; _i++>> + <<if $SecExp.units.slaves.squads[_i].active == 1 && (!$SecExp.war.rebellingID.includes($SecExp.units.slaves.squads[_i].ID))>> + <<set $SecExp.units.slaves.squads[_i].battlesFought++>> <<set _count++>> <<if _count < _loyalUnits>> - $slaveUnits[_i].platoonName, + $SecExp.units.slaves.squads[_i].platoonName, <<else>> - $slaveUnits[_i].platoonName + $SecExp.units.slaves.squads[_i].platoonName <</if>> <</if>> <</for>> - <<for _i = 0; _i < $mercUnits.length; _i++>> - <<if $mercUnits[_i].active == 1 && (!$SecExp.war.rebellingID.includes($mercUnits[_i].ID))>> - <<set $mercUnits[_i].battlesFought++>> + <<for _i = 0; _i < $SecExp.units.mercs.squads.length; _i++>> + <<if $SecExp.units.mercs.squads[_i].active == 1 && (!$SecExp.war.rebellingID.includes($SecExp.units.mercs.squads[_i].ID))>> + <<set $SecExp.units.mercs.squads[_i].battlesFought++>> <<set _count++>> <<if _count < _loyalUnits>> - $mercUnits[_i].platoonName, + $SecExp.units.mercs.squads[_i].platoonName, <<else>> - $mercUnits[_i].platoonName + $SecExp.units.mercs.squads[_i].platoonName <</if>> <</if>> <</for>> @@ -131,10 +131,10 @@ <</if>> </p> <</if>> - <<if $secBots.active == 1>> + <<if $SecExp.units.bots.active == 1>> <<set _loss = _lossesList.pluck()>> - <<set _loss = Math.clamp(_loss,0,$secBots.troops)>> - <<set $secBots.troops -= _loss>> + <<set _loss = Math.clamp(_loss,0,$SecExp.units.bots.troops)>> + <<set $SecExp.units.bots.troops -= _loss>> <p>Security drones: <<if _loss <= 0>> no casualties @@ -148,10 +148,10 @@ catastrophic casualties <</if>> suffered. - <<if $secBots.troops <= 0>> - <<set $secBots.active = 0>> + <<if $SecExp.units.bots.troops <= 0>> + <<set $SecExp.units.bots.active = 0>> Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. It will take quite the investment to rebuild them. - <<elseif $secBots.troops <= 10>> + <<elseif $SecExp.units.bots.troops <= 10>> The unit has very few operatives left, it risks complete annihilation if deployed again. <</if>> </p> @@ -177,40 +177,40 @@ <</if>> <<if App.SecExp.battle.deployedUnits('militia') >= 1>> <p> <<set _med = 0>> - <<for _j = 0; _j < $militiaUnits.length; _j++>> - <<if $militiaUnits[_j].active == 1 && !$SecExp.war.rebellingID.includes($militiaUnits[_j].ID)>> - <<set $militiaUnits[_j].battlesFought++>> + <<for _j = 0; _j < $SecExp.units.militia.squads.length; _j++>> + <<if $SecExp.units.militia.squads[_j].active == 1 && !$SecExp.war.rebellingID.includes($SecExp.units.militia.squads[_j].ID)>> + <<set $SecExp.units.militia.squads[_j].battlesFought++>> <<set _loss = _lossesList.pluck()>> - <<set _loss = Math.clamp(_loss,0,$militiaUnits[_j].troops)>> - <br>$militiaUnits[_j].platoonName participated in the battle. They remained loyal to you. + <<set _loss = Math.clamp(_loss,0,$SecExp.units.militia.squads[_j].troops)>> + <br>$SecExp.units.militia.squads[_j].platoonName participated in the battle. They remained loyal to you. <<if _loss <= 0>> No casualties - <<elseif _loss <= $militiaUnits[_j].troops * 0.2>> + <<elseif _loss <= $SecExp.units.militia.squads[_j].troops * 0.2>> Light casualties - <<elseif _loss <= $militiaUnits[_j].troops * 0.4>> + <<elseif _loss <= $SecExp.units.militia.squads[_j].troops * 0.4>> Moderate casualties - <<elseif _loss <= $militiaUnits[_j].troops * 0.6>> + <<elseif _loss <= $SecExp.units.militia.squads[_j].troops * 0.6>> Heavy casualties <<else>> Catastrophic casualties <</if>> suffered. - <<set _med = Math.round(Math.clamp(_loss * $militiaUnits[_j].medics * 0.25,1,_loss))>> - <<if $militiaUnits[_j].medics == 1 && _loss > 0>> + <<set _med = Math.round(Math.clamp(_loss * $SecExp.units.militia.squads[_j].medics * 0.25,1,_loss))>> + <<if $SecExp.units.militia.squads[_j].medics == 1 && _loss > 0>> Some men were saved by their medics. <</if>> - <<set $militiaUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$militiaUnits[_j].maxTroops))>> - <<set $militiaTotalCasualties += Math.trunc(_loss - _med)>> - <<if $militiaUnits[_j].training < 100>> + <<set $SecExp.units.militia.squads[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$SecExp.units.militia.squads[_j].maxTroops))>> + <<set $SecExp.units.militia.dead += Math.trunc(_loss - _med)>> + <<if $SecExp.units.militia.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience has increased. - <<set $militiaUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.militia.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> - <<if $militiaUnits[_j].troops <= 0>> - <<set $militiaUnits[_j].active = 0>> + <<if $SecExp.units.militia.squads[_j].troops <= 0>> + <<set $SecExp.units.militia.squads[_j].active = 0>> <br>Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The remnants will be sent home honored as veterans or reorganized in a new unit. - <<elseif $militiaUnits[_j].troops <= 10>> + <<elseif $SecExp.units.militia.squads[_j].troops <= 10>> <br>The unit has very few operatives left, it risks complete annihilation if deployed again. <</if>> <</if>> @@ -219,44 +219,44 @@ <</if>> <<if App.SecExp.battle.deployedUnits('slaves') >= 1>> <p> <<set _med = 0>> - <<for _j = 0; _j < $slaveUnits.length; _j++>> - <<if $slaveUnits[_j].active == 1 && !$SecExp.war.rebellingID.includes($slaveUnits[_j].ID)>> - <<set $slaveUnits[_j].battlesFought++>> + <<for _j = 0; _j < $SecExp.units.slaves.squads.length; _j++>> + <<if $SecExp.units.slaves.squads[_j].active == 1 && !$SecExp.war.rebellingID.includes($SecExp.units.slaves.squads[_j].ID)>> + <<set $SecExp.units.slaves.squads[_j].battlesFought++>> <<set _loss = _lossesList.pluck()>> <<if !(Number.isInteger(_loss))>> <br>@@.red;Error: failed to assign losses, input was negative or NaN@@ <<break>> <</if>> - <<set _loss = Math.clamp(_loss,0,$slaveUnits[_j].troops)>> - <br>$slaveUnits[_j].platoonName participated in the battle. They remained loyal to you. + <<set _loss = Math.clamp(_loss,0,$SecExp.units.slaves.squads[_j].troops)>> + <br>$SecExp.units.slaves.squads[_j].platoonName participated in the battle. They remained loyal to you. <<if _loss <= 0>> No casualties - <<elseif _loss <= $slaveUnits[_j].troops * 0.2>> + <<elseif _loss <= $SecExp.units.slaves.squads[_j].troops * 0.2>> Light casualties - <<elseif _loss <= $slaveUnits[_j].troops * 0.4>> + <<elseif _loss <= $SecExp.units.slaves.squads[_j].troops * 0.4>> Moderate casualties - <<elseif _loss <= $slaveUnits[_j].troops * 0.6>> + <<elseif _loss <= $SecExp.units.slaves.squads[_j].troops * 0.6>> Heavy casualties <<else>> Catastrophic casualties <</if>> suffered. - <<set _med = Math.round(Math.clamp(_loss * $slaveUnits[_j].medics * 0.25,1,_loss))>> - <<if $slaveUnits[_j].medics == 1 && _loss > 0>> + <<set _med = Math.round(Math.clamp(_loss * $SecExp.units.slaves.squads[_j].medics * 0.25,1,_loss))>> + <<if $SecExp.units.slaves.squads[_j].medics == 1 && _loss > 0>> Some men were saved by their medics. <</if>> - <<set $slaveUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$slaveUnits[_j].maxTroops))>> - <<set $slavesTotalCasualties += _loss - _med>> - <<if $slaveUnits[_j].training < 100>> + <<set $SecExp.units.slaves.squads[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$SecExp.units.slaves.squads[_j].maxTroops))>> + <<set $SecExp.units.slaves.dead += _loss - _med>> + <<if $SecExp.units.slaves.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience gained. - <<set $slaveUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.slaves.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> - <<if $slaveUnits[_j].troops <= 0>> - <<set $slaveUnits[_j].active = 0>> + <<if $SecExp.units.slaves.squads[_j].troops <= 0>> + <<set $SecExp.units.slaves.squads[_j].active = 0>> <br>Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The survivors will be sent home honored as veterans or reorganized in a new unit. - <<elseif $slaveUnits[_j].troops <= 10>> + <<elseif $SecExp.units.slaves.squads[_j].troops <= 10>> <br>The unit has very few operatives left, it risks complete annihilation if deployed again. <</if>> <</if>> @@ -265,40 +265,40 @@ <</if>> <<if App.SecExp.battle.deployedUnits('mercs') >= 1>> <p> <<set _med = 0>> - <<for _j = 0; _j < $mercUnits.length; _j++>> - <<if $mercUnits[_j].active == 1 && !$SecExp.war.rebellingID.includes($mercUnits[_j].ID)>> - <<set $mercUnits[_j].battlesFought++>> + <<for _j = 0; _j < $SecExp.units.mercs.squads.length; _j++>> + <<if $SecExp.units.mercs.squads[_j].active == 1 && !$SecExp.war.rebellingID.includes($SecExp.units.mercs.squads[_j].ID)>> + <<set $SecExp.units.mercs.squads[_j].battlesFought++>> <<set _loss = _lossesList.pluck()>> - <<set _loss = Math.clamp(_loss,0,$mercUnits[_j].troops)>> - <br>$mercUnits[_j].platoonName participated in the battle. They remained loyal to you. + <<set _loss = Math.clamp(_loss,0,$SecExp.units.mercs.squads[_j].troops)>> + <br>$SecExp.units.mercs.squads[_j].platoonName participated in the battle. They remained loyal to you. <<if _loss <= 0>> No casualties - <<elseif _loss <= $mercUnits[_j].troops * 0.2>> + <<elseif _loss <= $SecExp.units.mercs.squads[_j].troops * 0.2>> Light casualties - <<elseif _loss <= $mercUnits[_j].troops * 0.4>> + <<elseif _loss <= $SecExp.units.mercs.squads[_j].troops * 0.4>> Moderate casualties - <<elseif _loss <= $mercUnits[_j].troops * 0.6>> + <<elseif _loss <= $SecExp.units.mercs.squads[_j].troops * 0.6>> Heavy casualties <<else>> Catastrophic casualties <</if>> suffered. - <<set _med = Math.round(Math.clamp(_loss * $mercUnits[_j].medics * 0.25,1,_loss))>> - <<if $mercUnits[_j].medics == 1 && _loss > 0>> + <<set _med = Math.round(Math.clamp(_loss * $SecExp.units.mercs.squads[_j].medics * 0.25,1,_loss))>> + <<if $SecExp.units.mercs.squads[_j].medics == 1 && _loss > 0>> Some men were saved by their medics. <</if>> - <<set $mercUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$mercUnits[_j].maxTroops))>> - <<set $mercTotalCasualties += Math.trunc(_loss - _med)>> - <<if $mercUnits[_j].training < 100>> + <<set $SecExp.units.mercs.squads[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$SecExp.units.mercs.squads[_j].maxTroops))>> + <<set $SecExp.units.mercs.dead += Math.trunc(_loss - _med)>> + <<if $SecExp.units.mercs.squads[_j].training < 100>> <<if random(1,100) > 60>> Experience gained. - <<set $mercUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>> + <<set $SecExp.units.mercs.squads[_j].training += random(5,15) + $majorBattle * random(5,15)>> <</if>> <</if>> - <<if $mercUnits[_j].troops <= 0>> - <<set $mercUnits[_j].active = 0>> + <<if $SecExp.units.mercs.squads[_j].troops <= 0>> + <<set $SecExp.units.mercs.squads[_j].active = 0>> <br>Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The remnants will be sent home honored as veterans or reorganized in a new unit. - <<elseif $mercUnits[_j].troops <= 10>> + <<elseif $SecExp.units.mercs.squads[_j].troops <= 10>> <br>The unit has very few operatives left, it risks complete annihilation if deployed again. <</if>> <</if>> @@ -311,22 +311,22 @@ <<if $SecExp.war.rebellingID.length > 0 && $SecExp.war.result >= 2>> /* rebellion win */ <br> <<set _militiaRebelledID = [], _militiaManpower = 0>> - <<for _j = 0; _j < $militiaUnits.length; _j++>> - <<if $militiaUnits[_j].active == 1 && $SecExp.war.rebellingID.includes($militiaUnits[_j].ID)>> - <br>$militiaUnits[_j].platoonName, - <<set _militiaRebelledID.push($militiaUnits[_j].ID)>> - <<set _militiaManpower += Math.clamp($militiaUnits[_j].troops - random(_averageLosses),0,$militiaUnits[_j].troops)>> + <<for _j = 0; _j < $SecExp.units.militia.squads.length; _j++>> + <<if $SecExp.units.militia.squads[_j].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.militia.squads[_j].ID)>> + <br>$SecExp.units.militia.squads[_j].platoonName, + <<set _militiaRebelledID.push($SecExp.units.militia.squads[_j].ID)>> + <<set _militiaManpower += Math.clamp($SecExp.units.militia.squads[_j].troops - random(_averageLosses),0,$SecExp.units.militia.squads[_j].troops)>> <</if>> <</for>> <<if _militiaRebelledID.length > 0>> had the gall to betray you and join your enemies. <span id="militiaResult"> <br><<link "Dissolve the units">> - <<run $militiaUnits.deleteWith((u) => _militiaRebelledID.includes(u.ID))>> - <<set $militiaFreeManpower += _militiaManpower>> - <<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $militiaUnits[_i].active == 1>> - <<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty - random(10,40),0,100)>> + <<run $SecExp.units.militia.squads.deleteWith((u) => _militiaRebelledID.includes(u.ID))>> + <<set $SecExp.units.militia.free += _militiaManpower>> + <<for _i = 0; _i < $SecExp.units.militia.squads.length; _i++>> + <<if $SecExp.units.militia.squads[_i].active == 1>> + <<set $SecExp.units.militia.squads[_i].loyalty = Math.clamp($SecExp.units.militia.squads[_i].loyalty - random(10,40),0,100)>> <</if>> <</for>> <<replace "#militiaResult">> @@ -335,18 +335,18 @@ <</link>> <br>//Manpower will be refunded, but will negatively influence the loyalty of the other units// <br><<link "Purge the dissidents and dissolve the units">> - <<run $militiaUnits.deleteWith((u) => _militiaRebelledID.includes(u.ID))>> - <<set $militiaFreeManpower += _militiaManpower * 0.5>> + <<run $SecExp.units.militia.squads.deleteWith((u) => _militiaRebelledID.includes(u.ID))>> + <<set $SecExp.units.militia.free += _militiaManpower * 0.5>> <<replace "#militiaResult">> <br>Dissidents purged and units dissolved. <</replace>> <</link>> <br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.// <br><<link "Execute them all">> - <<run $militiaUnits.deleteWith((u) => _militiaRebelledID.includes(u.ID))>> - <<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $militiaUnits[_i].active == 1>> - <<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty + random(10,40),0,100)>> + <<run $SecExp.units.militia.squads.deleteWith((u) => _militiaRebelledID.includes(u.ID))>> + <<for _i = 0; _i < $SecExp.units.militia.squads.length; _i++>> + <<if $SecExp.units.militia.squads[_i].active == 1>> + <<set $SecExp.units.militia.squads[_i].loyalty = Math.clamp($SecExp.units.militia.squads[_i].loyalty + random(10,40),0,100)>> <</if>> <</for>> <<replace "#militiaResult">> @@ -358,22 +358,22 @@ <</if>> <br> <<set _slaveRebelledID = [], _slaveManpower = 0>> - <<for _j = 0; _j < $slaveUnits.length; _j++>> - <<if $slaveUnits[_j].active == 1 && $SecExp.war.rebellingID.includes($slaveUnits[_j].ID)>> - <br>$slaveUnits[_j].platoonName, - <<set _slaveRebelledID.push($slaveUnits[_j].ID)>> - <<set _slaveManpower += Math.clamp($slaveUnits[_j].troops - random(_averageLosses),0,$slaveUnits[_j].troops)>> + <<for _j = 0; _j < $SecExp.units.slaves.squads.length; _j++>> + <<if $SecExp.units.slaves.squads[_j].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.slaves.squads[_j].ID)>> + <br>$SecExp.units.slaves.squads[_j].platoonName, + <<set _slaveRebelledID.push($SecExp.units.slaves.squads[_j].ID)>> + <<set _slaveManpower += Math.clamp($SecExp.units.slaves.squads[_j].troops - random(_averageLosses),0,$SecExp.units.slaves.squads[_j].troops)>> <</if>> <</for>> <<if _slaveRebelledID.length > 0>> decided in their blind arrogance to betray you. <span id="slaveResult"> <br><<link "Dissolve the units">> - <<run $slaveUnits.deleteWith((u) => _slaveRebelledID.includes(u.ID))>> + <<run $SecExp.units.slaves.squads.deleteWith((u) => _slaveRebelledID.includes(u.ID))>> <<set $menials += _slaveManpower>> - <<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $slaveUnits[_i].active == 1>> - <<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty - random(10,40),0,100)>> + <<for _i = 0; _i < $SecExp.units.militia.squads.length; _i++>> + <<if $SecExp.units.slaves.squads[_i].active == 1>> + <<set $SecExp.units.slaves.squads[_i].loyalty = Math.clamp($SecExp.units.slaves.squads[_i].loyalty - random(10,40),0,100)>> <</if>> <</for>> <<replace "#slaveResult">> @@ -382,7 +382,7 @@ <</link>> <br>//Manpower will be refunded, but will negatively influence the loyalty of the other units// <br><<link "Purge the dissidents and dissolve the units">> - <<run $slaveUnits.deleteWith((u) => _slaveRebelledID.includes(u.ID))>> + <<run $SecExp.units.slaves.squads.deleteWith((u) => _slaveRebelledID.includes(u.ID))>> <<set $menials += _slaveManpower * 0.5>> <<replace "#slaveResult">> <br>Dissidents purged and units dissolved. @@ -390,10 +390,10 @@ <</link>> <br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.// <br><<link "Execute them all">> - <<run $slaveUnits.deleteWith((u) => _slaveRebelledID.includes(u.ID))>> - <<for _i = 0; _i < $slaveUnits.length; _i++>> - <<if $slaveUnits[_i].active == 1>> - <<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty + random(10,40),0,100)>> + <<run $SecExp.units.slaves.squads.deleteWith((u) => _slaveRebelledID.includes(u.ID))>> + <<for _i = 0; _i < $SecExp.units.slaves.squads.length; _i++>> + <<if $SecExp.units.slaves.squads[_i].active == 1>> + <<set $SecExp.units.slaves.squads[_i].loyalty = Math.clamp($SecExp.units.slaves.squads[_i].loyalty + random(10,40),0,100)>> <</if>> <</for>> <<replace "#slaveResult">> @@ -405,22 +405,22 @@ <</if>> <br> <<set _mercRebelledID = [], _mercManpower = 0>> - <<for _j = 0; _j < $mercUnits.length; _j++>> - <<if $mercUnits[_j].active == 1 && $SecExp.war.rebellingID.includes($mercUnits[_j].ID)>> - <br>$mercUnits[_j].platoonName, - <<set _mercRebelledID.push($mercUnits[_j].ID)>> - <<set _mercManpower += Math.clamp($mercUnits[_j].troops - random(_averageLosses),0,$mercUnits[_j].troops)>> + <<for _j = 0; _j < $SecExp.units.mercs.squads.length; _j++>> + <<if $SecExp.units.mercs.squads[_j].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.mercs.squads[_j].ID)>> + <br>$SecExp.units.mercs.squads[_j].platoonName, + <<set _mercRebelledID.push($SecExp.units.mercs.squads[_j].ID)>> + <<set _mercManpower += Math.clamp($SecExp.units.mercs.squads[_j].troops - random(_averageLosses),0,$SecExp.units.mercs.squads[_j].troops)>> <</if>> <</for>> <<if _mercRebelledID.length > 0>> made the grave mistake of betraying you. <span id="mercResult"> <br><<link "Dissolve the units">> - <<run $mercUnits.deleteWith((u) => _mercRebelledID.includes(u.ID))>> - <<set $mercFreeManpower += _mercManpower>> - <<for _i = 0; _i < $militiaUnits.length; _i++>> - <<if $mercUnits[_i].active == 1>> - <<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty - random(10,40),0,100)>> + <<run $SecExp.units.mercs.squads.deleteWith((u) => _mercRebelledID.includes(u.ID))>> + <<set $SecExp.units.mercs.free += _mercManpower>> + <<for _i = 0; _i < $SecExp.units.militia.squads.length; _i++>> + <<if $SecExp.units.mercs.squads[_i].active == 1>> + <<set $SecExp.units.mercs.squads[_i].loyalty = Math.clamp($SecExp.units.mercs.squads[_i].loyalty - random(10,40),0,100)>> <</if>> <</for>> <<replace "#mercResult">> @@ -429,18 +429,18 @@ <</link>> <br>//Manpower will be refunded, but will negatively influence the loyalty of the other units// <br><<link "Purge the dissidents and dissolve the units">> - <<run $mercUnits.deleteWith((u) => _mercRebelledID.includes(u.ID))>> - <<set $mercFreeManpower += _mercManpower * 0.5>> + <<run $SecExp.units.mercs.squads.deleteWith((u) => _mercRebelledID.includes(u.ID))>> + <<set $SecExp.units.mercs.free += _mercManpower * 0.5>> <<replace "#mercResult">> <br>Dissidents purged and units dissolved. <</replace>> <</link>> <br>//Will not influence the loyalty of the other units, but only half the manpower will be refunded.// <br><<link "Execute them all">> - <<run $mercUnits.deleteWith((u) => _mercRebelledID.includes(u.ID))>> - <<for _i = 0; _i < $mercUnits.length; _i++>> - <<if $mercUnits[_i].active == 1>> - <<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty + random(10,40),0,100)>> + <<run $SecExp.units.mercs.squads.deleteWith((u) => _mercRebelledID.includes(u.ID))>> + <<for _i = 0; _i < $SecExp.units.mercs.squads.length; _i++>> + <<if $SecExp.units.mercs.squads[_i].active == 1>> + <<set $SecExp.units.mercs.squads[_i].loyalty = Math.clamp($SecExp.units.mercs.squads[_i].loyalty + random(10,40),0,100)>> <</if>> <</for>> <<replace "#mercResult">> @@ -454,43 +454,43 @@ /* rebellion loss */ <br><br> <<set _militiaRebelledID = []>> - <<for _j = 0; _j < $militiaUnits.length; _j++>> - <<if $militiaUnits[_j].active == 1 && $SecExp.war.rebellingID.includes($militiaUnits[_j].ID)>> - <<set _militiaRebelledID.push($militiaUnits[_j].ID)>> - $militiaUnits[_j].platoonName, + <<for _j = 0; _j < $SecExp.units.militia.squads.length; _j++>> + <<if $SecExp.units.militia.squads[_j].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.militia.squads[_j].ID)>> + <<set _militiaRebelledID.push($SecExp.units.militia.squads[_j].ID)>> + $SecExp.units.militia.squads[_j].platoonName, <</if>> <</for>> <<if _militiaRebelledID.length > 0>> had the gall to betray you and join your enemies. They participated in the looting following the battle, then vanished in the wastes. <</if>> <<run cashX(forceNeg(1000 * _militiaRebelledID.length), "war")>> - <<run $militiaUnits.deleteWith((u) => _militiaRebelledID.includes(u.ID))>> + <<run $SecExp.units.militia.squads.deleteWith((u) => _militiaRebelledID.includes(u.ID))>> <br> <<set _slaveRebelledID = []>> - <<for _j = 0; _j < $slaveUnits.length; _j++>> - <<if $slaveUnits[_j].active == 1 && $SecExp.war.rebellingID.includes($slaveUnits[_j].ID)>> - <<set _slaveRebelledID.push($slaveUnits[_j].ID)>> - $slaveUnits[_j].platoonName, + <<for _j = 0; _j < $SecExp.units.slaves.squads.length; _j++>> + <<if $SecExp.units.slaves.squads[_j].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.slaves.squads[_j].ID)>> + <<set _slaveRebelledID.push($SecExp.units.slaves.squads[_j].ID)>> + $SecExp.units.slaves.squads[_j].platoonName, <</if>> <</for>> <<if _slaveRebelledID.length > 0>> decided in their blind arrogance to betray you. They participated in the looting following the battle, then vanished in the wastes. <</if>> <<run cashX(forceNeg(1000 * _slaveRebelledID.length), "war")>> - <<run $slaveUnits.deleteWith((u) => _slaveRebelledID.includes(u.ID))>> + <<run $SecExp.units.slaves.squads.deleteWith((u) => _slaveRebelledID.includes(u.ID))>> <br> <<set _mercRebelledID = []>> <<set _count = 0>> - <<for _j = 0; _j < $mercUnits.length; _j++>> - <<if $mercUnits[_j].active == 1 && $SecExp.war.rebellingID.includes($mercUnits[_j].ID)>> - <<set _mercRebelledID.push($mercUnits[_j].ID)>> + <<for _j = 0; _j < $SecExp.units.mercs.squads.length; _j++>> + <<if $SecExp.units.mercs.squads[_j].active == 1 && $SecExp.war.rebellingID.includes($SecExp.units.mercs.squads[_j].ID)>> + <<set _mercRebelledID.push($SecExp.units.mercs.squads[_j].ID)>> <<set _count++>> - $mercUnits[_j].platoonName, + $SecExp.units.mercs.squads[_j].platoonName, <</if>> <</for>> <<if _mercRebelledID.length > 0>> made the grave mistake of betraying you. They participated in the looting following the battle, then vanished in the wastes. <</if>> <<run cashX(forceNeg(1000 * _mercRebelledID.length), "war")>> - <<run $mercUnits.deleteWith((u) => _mercRebelledID.includes(u.ID))>> + <<run $SecExp.units.mercs.squads.deleteWith((u) => _mercRebelledID.includes(u.ID))>> <</if>> diff --git a/src/Mods/SpecialForce/SpecialForce.js b/src/Mods/SpecialForce/SpecialForce.js index 3de44d1b05d..7c94b67578d 100644 --- a/src/Mods/SpecialForce/SpecialForce.js +++ b/src/Mods/SpecialForce/SpecialForce.js @@ -1496,7 +1496,7 @@ App.SF.AAR = function(endWeekCall = 1) { if (V.secExpEnabled > 0 && V.mercenaries > 0) { V.SF.MercCon.Mercs = 0; NewMercs = jsRandom(1, (tradeShowAttendes / 10)); - V.mercFreeManpower += NewMercs; + V.SecExp.units.mercs.free += NewMercs; V.SF.MercCon.TotalMercs += NewMercs; V.SF.MercCon.Mercs += NewMercs; } diff --git a/src/data/backwardsCompatibility/backwardsCompatibility.js b/src/data/backwardsCompatibility/backwardsCompatibility.js index 59b30d4611e..0e5244cac2c 100644 --- a/src/data/backwardsCompatibility/backwardsCompatibility.js +++ b/src/data/backwardsCompatibility/backwardsCompatibility.js @@ -92,15 +92,6 @@ App.Update.backwardsCompatibility = function() { jQuery('#backwards-compatibility').append(div); App.Update.arcologyLocation(div); - // Sec Exp - div = document.createElement('div'); - div.append(`Updating Security Expansion... `); - jQuery('#backwards-compatibility').append(div); - App.SecExp.generalBC(); - if (V.secExpEnabled > 0) { - div.append(App.UI.DOM.renderPassage("SecExpBackwardCompatibility")); - } - div = document.createElement('div'); div.append(`Checking for old variables... `); jQuery('#backwards-compatibility').append(div); @@ -346,7 +337,7 @@ App.Update.globalVariables = function(node) { // Incubator if (V.incubatorImprintSetting === 0) { V.incubatorImprintSetting = "trust"; } - // SF + App.SecExp.generalBC(); App.SF.BC(); // FS diff --git a/src/endWeek/nextWeek/nextWeek.js b/src/endWeek/nextWeek/nextWeek.js index 510b3c07a4c..9582f714ca8 100644 --- a/src/endWeek/nextWeek/nextWeek.js +++ b/src/endWeek/nextWeek/nextWeek.js @@ -291,10 +291,7 @@ App.EndWeek.nextWeek = function() { } if (V.secExpEnabled > 0) { - if (V.foughtThisWeek === 1) { - V.foughtThisWeek = 0; - } - + V.foughtThisWeek = 0; if (V.SecExp.buildings.riotCenter) { V.SecExp.buildings.riotCenter.sentUnitCooldown = Math.max(V.SecExp.buildings.riotCenter.sentUnitCooldown - 1, 0); } diff --git a/src/events/intro/initNationalities.js b/src/events/intro/initNationalities.js index 392e642da70..bc6fd4ce645 100644 --- a/src/events/intro/initNationalities.js +++ b/src/events/intro/initNationalities.js @@ -1,6 +1,5 @@ App.Intro.initNationalities = function() { function initSecExp() { - /* base vars */ App.SecExp.generalInit(); V.fort = { reactor: 0, @@ -67,14 +66,14 @@ App.Intro.initNationalities = function() { V.arcologyUpgrade.drones = 1; V.arcologyUpgrade.hydro = 1; if (V.secExpEnabled > 0) { - V.secBots = App.SecExp.generateUnit("bots"); + V.SecExp.units.bots = App.SecExp.unit.gen("bots"); } break; case "construction": V.trinkets.push("the blueprints of a proto-arcology you helped construct"); V.arcologyUpgrade.drones = 1; if (V.secExpEnabled > 0) { - V.secBots = App.SecExp.generateUnit("bots"); + V.SecExp.units.bots = App.SecExp.unit.gen("bots"); } case "worksite helper": V.trinkets.push("the hardhat you used to wear around worksites"); diff --git a/src/gui/options/optionsPassage.js b/src/gui/options/optionsPassage.js index 02f2dbfbe20..74cbea915f9 100644 --- a/src/gui/options/optionsPassage.js +++ b/src/gui/options/optionsPassage.js @@ -446,7 +446,7 @@ App.UI.optionsPassage = function() { if (V.secExpEnabled > 0) { if (Object.values(V.SecExp).length === 0) { - el.append(App.UI.DOM.renderPassage("SecExpBackwardCompatibility")); + App.SecExp.generalBC(); Engine.play("Options"); } App.UI.DOM.appendNewElement("h2", el, `Security Expansion mod options`); @@ -663,7 +663,7 @@ App.UI.optionsPassage = function() { links.push(App.UI.DOM.link( "Give militia manpower", () => { - V.militiaFreeManpower += 30; + V.SecExp.units.militia.free += 30; }, [], "Options" @@ -671,7 +671,7 @@ App.UI.optionsPassage = function() { links.push(App.UI.DOM.link( "Remove militia manpower", () => { - V.militiaFreeManpower = Math.max(V.militiaFreeManpower - 30, 0); + V.SecExp.units.militia.free = Math.max(V.SecExp.units.militia.free - 30, 0); }, [], "Options" @@ -685,7 +685,7 @@ App.UI.optionsPassage = function() { links.push(App.UI.DOM.link( "Give mercs manpower", () => { - V.mercFreeManpower += 30; + V.SecExp.units.mercs.free += 30; }, [], "Options" @@ -693,7 +693,7 @@ App.UI.optionsPassage = function() { links.push(App.UI.DOM.link( "Remove mercs manpower", () => { - V.mercFreeManpower = Math.max(V.mercFreeManpower - 30, 0); + V.SecExp.units.mercs.free = Math.max(V.SecExp.units.mercs.free - 30, 0); }, [], "Options" @@ -725,14 +725,8 @@ App.UI.optionsPassage = function() { ["random", [100]], ]); - for (const unit of V.militiaUnits) { - unit.loyalty = numberGenerator(); - } - for (const unit of V.slaveUnits) { - unit.loyalty = numberGenerator(); - } - for (const unit of V.mercUnits) { - unit.loyalty = numberGenerator(); + for (const squad of App.SecExp.unit.humanSquads()) { + squad.loyalty = numberGenerator(); } function numberGenerator() { diff --git a/src/js/economyJS.js b/src/js/economyJS.js index 72725c6315d..f03a1fef12e 100644 --- a/src/js/economyJS.js +++ b/src/js/economyJS.js @@ -622,6 +622,15 @@ globalThis.calculateCosts = (function() { function getSecurityExpansionCost() { let secExpCost = 0, soldierMod = 1.5; // V.SecExp.edicts.defense.soldierWages === 1 if (V.secExpEnabled > 0) { + const unitModifier = function(x) { + if (x === 'slaves') { + return 0.5; + } else if (x === 'mercs') { + return 1.5; + } + return 1; + } + secExpCost += App.SecExp.upkeep.edictsCash(); secExpCost += App.SecExp.upkeep.SF(); secExpCost += App.SecExp.upkeep.buildings(); @@ -630,27 +639,10 @@ globalThis.calculateCosts = (function() { } else if (V.SecExp.edicts.defense.soldierWages === 2) { soldierMod = 2; } - const militiaUnits = V.militiaUnits.length, slaveUnits = V.slaveUnits.length, mercUnits = V.mercUnits.length; // predefined for optimization - const soldierUpkeep = 10; - if (V.militiaUnits !== null) { - for (let i = 0; i < militiaUnits; i++) { - if (V.militiaUnits[i] !== null) { - secExpCost += V.militiaUnits[i].troops * soldierUpkeep * soldierMod; - } - } - } - if (V.slaveUnits !== null) { - for (let i = 0; i < slaveUnits; i++) { - if (V.slaveUnits[i] !== null) { - secExpCost += V.slaveUnits[i].troops * soldierUpkeep * 0.5 * soldierMod; - } - } - } - if (V.mercUnits !== null) { - for (let i = 0; i < mercUnits; i++) { - if (V.mercUnits[i] !== null) { - secExpCost += V.mercUnits[i].troops * soldierUpkeep * 1.5 * soldierMod; - } + + for (const unit of App.SecExp.unit.list().slice(1)) { + for (const squad of V.SecExp.units[unit].squads) { + secExpCost += squad.troops * 10 * unitModifier(unit) * soldierMod; } } } diff --git a/src/uncategorized/manageArcology.tw b/src/uncategorized/manageArcology.tw index 32ece54361b..e48331a2bb1 100644 --- a/src/uncategorized/manageArcology.tw +++ b/src/uncategorized/manageArcology.tw @@ -53,7 +53,7 @@ <<run cashX(-Math.trunc(5000*$upgradeMultiplierArcology), "capEx")>> <<set $arcologyUpgrade.drones = 1, $PC.skill.engineering += 1>> <<if $secExpEnabled > 0>> - <<set $secBots = App.SecExp.generateUnit("bots")>> + <<set $SecExp.units.bots = App.SecExp.unit.gen("bots")>> <</if>> <</link>> <<elseif $arcologyUpgrade.hydro != 1>> @@ -548,7 +548,7 @@ <<else>> You won <<print num($SecExp.battles.victories)>> of them, while the enemy managed to gain the upper hand in the other <<print num($SecExp.battles.losses)>>. <</if>> - During all battles you lost a total of <<print num($militiaTotalCasualties + $slavesTotalCasualties + $mercTotalCasualties)>> men, while scoring a total of <<print num($SecExp.core.totalKills)>> kills. + During all battles you lost a total of <<print num(App.SecExp.unit.list().slice(1).reduce((acc, cur) => {return acc + V.SecExp.units[cur].dead;}, 0))>> men, while scoring a total of <<print num($SecExp.core.totalKills)>> kills. <</if>> <<if $SecExp.settings.rebellion.enabled === 1 && _countRebellions > 0>> Your arcology was involved in <<print num(_countRebellions)>> rebellions. You won <<print num($SecExp.rebellions.victories)>> of them, while the rebels defeated your forces in <<print num($SecExp.rebellions.losses)>>. diff --git a/src/uncategorized/pMercenaries.tw b/src/uncategorized/pMercenaries.tw index ab117945345..53a88b27cce 100644 --- a/src/uncategorized/pMercenaries.tw +++ b/src/uncategorized/pMercenaries.tw @@ -30,7 +30,7 @@ The budgetary difficulty many old world countries are in has resulted in unemplo <<run repX(-100, "event")>> <<run cashX(forceNeg(_price), "mercenaries")>> <<set $mercenaries = 1>> - <<set $mercFreeManpower = 15>> + <<set $SecExp.units.mercs.free = 15>> <</replace>> <</link>> <<if ($PC.skill.warfare >= 50) || ($PC.career == "arcology owner")>>//This will cost <<print cashFormat(_price)>> and some upkeep, @@.springgreen;reduced by your mercenary contacts@@//<<else>>//This will cost <<print cashFormat(5000)>> and incur significant upkeep costs//<</if>> <br><<link "Install a full platoon">> @@ -39,7 +39,7 @@ The budgetary difficulty many old world countries are in has resulted in unemplo <<run repX(-500, "event")>> <<run cashX(forceNeg((_price*2)), "mercenaries")>> <<set $mercenaries = 3>> - <<set $mercFreeManpower = 30>> + <<set $SecExp.units.mercs.free = 30>> <</replace>> <</link>> <<if ($PC.skill.warfare >= 50) || ($PC.career == "arcology owner")>>//This will cost <<print cashFormat((_price*2))>> and some upkeep, @@.springgreen;reduced by your mercenary contacts@@//<<else>>//This will cost <<print cashFormat(10000)>> and incur significant upkeep costs//<</if>> <br><<link "Do not quarter troops in your arcology">> diff --git a/src/uncategorized/scheduledEvent.tw b/src/uncategorized/scheduledEvent.tw index e38e8183f4f..a3e1f99e31e 100644 --- a/src/uncategorized/scheduledEvent.tw +++ b/src/uncategorized/scheduledEvent.tw @@ -81,9 +81,9 @@ <<if $rivalOwner == -1>> <<goto "P rival initiation">> -<<elseif ($slaveRebellion === 1 || $citizenRebellion === 1) && $secExpEnabled > 0>> +<<elseif $secExpEnabled > 0 && $foughtThisWeek === 0 && ($slaveRebellion === 1 || $citizenRebellion === 1)>> <<goto "rebellionOptions">> -<<elseif $attackThisWeek == 1 && $secExpEnabled > 0>> +<<elseif $secExpEnabled > 0 && $foughtThisWeek === 0 && $attackThisWeek == 1>> <<goto "attackOptions">> <<elseif $PC.labor == 1>> <<goto "SE Player Birth">> -- GitLab