From d13b302887d0b68fe8344f84daddd55aa45faa4b Mon Sep 17 00:00:00 2001 From: hexall90 <hexall90@gmail.com> Date: Wed, 1 Nov 2017 17:22:50 +0100 Subject: [PATCH] fixes and widgets --- src/SecExp/SecExpBackwardCompatibility.tw | 6 +- src/SecExp/attackHandler.tw | 46 ++++++++++++-- src/SecExp/attackReport.tw | 4 +- src/SecExp/secBarracks.tw | 3 + src/SecExp/secInit.tw | 3 - src/SecExp/seeUnit.tw | 32 ++++++++-- src/SecExp/unitsBattleReport.tw | 4 +- src/SecExp/widgets/miscSecExpWidgets.tw | 74 +++++++++++++++++++++++ src/SecExp/widgets/unitsWidgets.tw | 2 +- 9 files changed, 158 insertions(+), 16 deletions(-) diff --git a/src/SecExp/SecExpBackwardCompatibility.tw b/src/SecExp/SecExpBackwardCompatibility.tw index a9c592a5626..021f4381a5d 100644 --- a/src/SecExp/SecExpBackwardCompatibility.tw +++ b/src/SecExp/SecExpBackwardCompatibility.tw @@ -704,10 +704,14 @@ <</if>> /* recalculation widgets */ +<<fixBrokenUnits>> +<<fixBrokenStats>> <<recalcSecRestPoint>> <<recalcCrimeCap>> <<recalcReqHelots>> <<recalcManpower>> <<recalcEdictsUpkeep>> -Missing Security Expansion variables set. All done! \ No newline at end of file +<<set $wasToggledBefore = 1>> + +<br>Missing Security Expansion variables set. All done! \ No newline at end of file diff --git a/src/SecExp/attackHandler.tw b/src/SecExp/attackHandler.tw index ff9f8a1131e..4ea43625ee0 100644 --- a/src/SecExp/attackHandler.tw +++ b/src/SecExp/attackHandler.tw @@ -996,6 +996,31 @@ <<set _enemyBaseHp = $ffBaseHp>> <</if>> +<<if isNaN(_attack)>> + <br>@@.red;Error: attack value reported NaN@@ +<</if>> +<<if isNaN(_defense)>> + <br>@@.red;Error: defense value reported NaN@@ +<</if>> +<<if isNaN(_hp)>> + <br>@@.red;Error: hp value reported NaN@@ +<</if>> +<<if isNaN(_morale)>> + <br>@@.red;Error: morale value reported NaN@@ +<</if>> +<<if isNaN(_enemyAttack)>> + <br>@@.red;Error: enemy attack value reported NaN@@ +<</if>> +<<if isNaN(_enemyDefense)>> + <br>@@.red;Error: enemy defense value reported NaN@@ +<</if>> +<<if isNaN(_enemyHp)>> + <br>@@.red;Error: enemy hp value reported NaN@@ +<</if>> +<<if isNaN(_enemyMorale)>> + <br>@@.red;Error: enemy morale value reported NaN@@ +<</if>> + <<if $showBattleStatistics == 1>> <<set _atkMod -= 1, _defMod -= 1, _militiaMod -= 1, _mercMod -= 1, _slaveMod -= 1, _SFMod -= 1, _enemyMod -= 1>> <<set _atkMod = Math.round(_atkMod * 100)>> @@ -1005,6 +1030,7 @@ <<set _slaveMod = Math.round(_slaveMod * 100)>> <<set _SFMod = Math.round(_SFMod * 100)>> <<set _enemyMod = Math.round(_enemyMod * 100)>> +<<set _barracksBonus = $secBarracksUpgrades.luxury * 5>> <br>attack: <<print Math.round(_attack)>> <br>defense: <<print Math.round(_defense)>> @@ -1019,6 +1045,9 @@ <<if $SFIntervention == 1>> <br>security force morale modifier: <<if _SFMod > 0>>+<</if>>_SFMod% <</if>> +<<if $secBarracksUpgrades.luxury >= 1>> +<br>Barracks bnous morale modifier: +<<print _barracksBonus>>% +<</if>> <br>tactic chance of success: <<print Math.round(_tacChance * 100)>>% <br>was tactic chosen successful?: <<if $tacticsSuccessful == 1>> yes <<else>> no<</if>> <br>enemy attack: <<print Math.round(_enemyAttack)>> @@ -1037,7 +1066,7 @@ /* player army attacks */ <<set _damage = _attack - _enemyDefense>> <<if _damage <= 0>> - <<set _damage = random(0,5)>> + <<set _damage = random(0,1)>> <</if>> <br> <<if $showBattleStatistics == 1>> player damage: <<print Math.round(_damage)>><</if>> @@ -1049,6 +1078,7 @@ <br> <<if $showBattleStatistics == 1>> remaining enemy morale: <<print Math.round(_enemyMorale)>><</if>> <<if _enemyHp <= 0 || _enemyMorale <= 0>> + <br> <<if $showBattleStatistics == 1>> <br>Victory!<</if>> <<set $battleResult = 3>> <<set $battleTurns = _i>> @@ -1058,18 +1088,19 @@ /* attacker army attacks */ <<set _damage = _enemyAttack - _defense>> <<if _damage <= 0>> - <<set _damage = random(0,5)>> + <<set _damage = random(0,1)>> <</if>> <br> <<if $showBattleStatistics == 1>> enemy damage: <<print Math.round(_damage)>><</if>> <<set _hp -= _damage>> <br> <<if $showBattleStatistics == 1>> remaining hp: <<print Math.round(_hp)>><</if>> - <<set $losses = _damage / _baseHp>> + <<set $losses += _damage / _baseHp>> <<set _morale -= (_damage + _damage / _baseHp)>> <br> <<if $showBattleStatistics == 1>> remaining morale: <<print Math.round(_morale)>><</if>> <<if _hp <= 0 || _morale <= 0>> + <br> <<if $showBattleStatistics == 1>> <br>Defeat!<</if>> <<set $battleResult = -3>> <<set $battleTurns = _i>> @@ -1077,6 +1108,7 @@ <</if>> <</for>> <<if $battleResult != 3 && $battleResult != -3>> + <br> <<if _morale > _enemyMorale>> <<if $showBattleStatistics == 1>> <br>Partial victory!<</if>> <<set $battleResult = 2>> @@ -1086,8 +1118,14 @@ <</if>> <</if>> +<<if $showBattleStatistics == 1>> + <br> + <br>Losses: <<print Math.trunc($losses)>> + <br>Enemy losses: <<print Math.trunc($enemyLosses)>> +<</if>> + <<if $battleResult > 3 || $battleResult < -3>> - <br>@@.red;Error: failed to determine battle result@@ + <br><br>@@.red;Error: failed to determine battle result@@ <</if>> <<if $showBattleStatistics == 1 && $majorBattle == 1 && $majorBattleGameOver == 1 && $battleResult == -3>> diff --git a/src/SecExp/attackReport.tw b/src/SecExp/attackReport.tw index e960d688581..5372f74e108 100644 --- a/src/SecExp/attackReport.tw +++ b/src/SecExp/attackReport.tw @@ -198,7 +198,7 @@ You gave your troops the order to surrender, obediently they stand down. <<elseif $battleResult == 0>> You decided in favor of a financial approach rather than open hostilities. Your troops remain inside the arcology's walls. - <<elseif 4battleResult == 1>> + <<elseif $battleResult == 1>> You decided in favor of a financial approach rather than open hostilities. Your troops remain inside the arcology's walls. <</if>> <<elseif $attackType == "freedom fighters">> @@ -261,7 +261,7 @@ You gave your troops the order to surrender, obediently they stand down. <<elseif $battleResult == 0>> You decided in favor of a financial approach rather than open hostilities. Your troops remain inside the arcology's walls. - <<elseif 4battleResult == 1>> + <<elseif $battleResult == 1>> You decided in favor of a financial approach rather than open hostilities. Your troops remain inside the arcology's walls. <</if>> <<elseif $attackType == "old world">> diff --git a/src/SecExp/secBarracks.tw b/src/SecExp/secBarracks.tw index f834f012c44..b8104a8c7ab 100644 --- a/src/SecExp/secBarracks.tw +++ b/src/SecExp/secBarracks.tw @@ -203,6 +203,7 @@ You are free to organize your menial slaves into fighting units. Currently you h training: 0, loyalty: 0, medics: 0, + SF: 0, battlesFought: 0}>> <<set $slaveUnits.push(_newUnit)>> <<set $slavesEmployedManpower += _newUnit.troops>> @@ -359,6 +360,7 @@ __Militia__ training: 0, loyalty: 0, medics: 0, + SF: 0, battlesFought: 0}>> <<set $militiaUnits.push(_newUnit)>> <<set $militiaEmployedManpower += _newUnit.troops>> @@ -499,6 +501,7 @@ __Mercenaries__ training: 0, loyalty: 7, medics: 0, + SF: 0, battlesFought: 0}>> <<set $mercUnits.push(_newUnit)>> <<set $mercFreeManpower -= 30>> diff --git a/src/SecExp/secInit.tw b/src/SecExp/secInit.tw index b7c6b6d689a..092c564b7c5 100644 --- a/src/SecExp/secInit.tw +++ b/src/SecExp/secInit.tw @@ -164,9 +164,6 @@ <<set $mercTotalManpower = 0>> <<set $mercEmployedManpower = 0>> <<set $mercTotalCasualties = 0>> -<<set $militiaLoyalty = 0>> -<<set $slaveArmyLoyalty = 0>> -<<set $mercLoyalty = 0>> <<set $soldierUpkeep = 10>> <<set $createdSlavesUnits = 0>> <<set $createdMilitiaUnits = 0>> diff --git a/src/SecExp/seeUnit.tw b/src/SecExp/seeUnit.tw index c326c337537..8b748cca236 100644 --- a/src/SecExp/seeUnit.tw +++ b/src/SecExp/seeUnit.tw @@ -32,7 +32,13 @@ <<else>> Your drones are equipped with top tier weaponry and armor. <</if>> - + <<if $showBattleStatistics == 1>> + <br> + <br>Security drones base attack: $secBotsBaseAttack + <br>Security drones base defense: $secBotsBaseDefense + <br>Security drones base morale: $secBotsMorale + <br>Security drones base hp: $secBotsBaseHp + <</if>> <<elseif $targetUnit == "militiaUnits">> <<militiaUnitsDescription $militiaUnits[$targetIndex]>> <br><br> @@ -87,7 +93,13 @@ The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers. <</if>> <</if>> - + <<if $showBattleStatistics == 1>> + <br> + <br>Militia base attack: $militiaBaseAttack + <br>Militia base defense: $militiaBaseDefense + <br>Militia base morale: $militiaBaseMorale + <br>Militia base hp: $militiaBaseHp + <</if>> <<elseif $targetUnit == "slaveUnits">> <<slaveUnitsDescription $slaveUnits[$targetIndex]>> <br><br> @@ -142,7 +154,13 @@ The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers. <</if>> <</if>> - + <<if $showBattleStatistics == 1>> + <br> + <br>Slaves base attack: $slaveBaseAttack + <br>Slaves base defense: $slaveBaseDefense + <br>Slaves base morale: $slaveBaseMorale + <br>Slaves base hp: $slaveBaseHp + <</if>> <<elseif $targetUnit == "mercUnits">> <<mercUnitsDescription $mercUnits[$targetIndex]>> <br><br> @@ -197,5 +215,11 @@ The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers. <</if>> <</if>> - + <<if $showBattleStatistics == 1>> + <br> + <br>Mercenaries base attack: $mercBaseAttack + <br>Mercenaries base defense: $mercBaseDefense + <br>Mercenaries base morale: $mercBaseMorale + <br>Mercenaries base hp: $mercBaseHp + <</if>> <</if>> \ No newline at end of file diff --git a/src/SecExp/unitsBattleReport.tw b/src/SecExp/unitsBattleReport.tw index 55b196ee18e..bea207069a6 100644 --- a/src/SecExp/unitsBattleReport.tw +++ b/src/SecExp/unitsBattleReport.tw @@ -35,7 +35,7 @@ <</for>> <</if>> -<<else>> +<<elseif $losses > 0>> /* if the losses are more than zero */ <<if $SFIntervention == 1>> <<set $deployedUnits++>> @@ -242,4 +242,6 @@ <</if>> <</for>> <</if>> +<<else>> + <br>@@.red;Error: losses are a negative number or NaN@@ <</if>> /* closes check for more than zero casualties */ \ No newline at end of file diff --git a/src/SecExp/widgets/miscSecExpWidgets.tw b/src/SecExp/widgets/miscSecExpWidgets.tw index ddbc935dc7f..8ca26d3a44c 100644 --- a/src/SecExp/widgets/miscSecExpWidgets.tw +++ b/src/SecExp/widgets/miscSecExpWidgets.tw @@ -35,6 +35,9 @@ <<if $mercEmployedManpower != _correctEmployedMP>> <<set $mercEmployedManpower = _correctEmployedMP>> <</if>> + + <<set $militiaTotalManpower = $militiaEmployedManpower + $militiaFreeManpower>> + <<set $mercTotalManpower = $mercEmployedManpower + $mercFreeManpower>> <</widget>> <<widget "recalcSecRestPoint">> @@ -193,4 +196,75 @@ <<set $edictsUpkeep = _newUpkeep>> <<set $edictsAuthUpkeep = _newAuthUpkeep>> +<</widget>> + +<<widget "fixBrokenUnits">> + <<for _i = 0; _i < $militiaUnits.length; _i++>> + <<if ndef $militiaUnits[_i].SF>> + <br>Set militia missing flag + <<set $militiaUnits[_i].SF = 0>> + <</if>> + <<if !Number.isInteger($militiaUnits[_i].troops)>> + <<set $militiaUnits[_i].troops = $militiaUnits[_i].maxTroops>> + <br>Fixed militia unit wrong troop count. + <</if>> + <</for>> + + <<for _i = 0; _i < $slaveUnits.length; _i++>> + <<if ndef $slaveUnits[_i].SF>> + <br>Set slave missing flag + <<set $slaveUnits[_i].SF = 0>> + <</if>> + <<if !Number.isInteger($slaveUnits[_i].troops)>> + <<set $slaveUnits[_i].troops = $slaveUnits[_i].maxTroops>> + <br>Fixed slave unit wrong troop count. + <</if>> + <</for>> + + <<for _i = 0; _i < $mercUnits.length; _i++>> + <<if ndef $mercUnits[_i].SF>> + <br>Set merc missing flag + <<set $mercUnits[_i].SF = 0>> + <</if>> + <<if !Number.isInteger($mercUnits[_i].troops)>> + <<set $mercUnits[_i].troops = $mercUnits[_i].maxTroops>> + <br>Fixed merc unit wrong troop count. + <</if>> + <</for>> +<</widget>> + +<<widget "fixBrokenStats">> + <<if !Number.isInteger($totalKills)>> + <<set $totalKills = 0>> + <</if>> + <<if !Number.isInteger($mercTotalCasualties)>> + <<set $mercTotalCasualties = 0>> + <</if>> + <<if !Number.isInteger($mercEmployedManpower)>> + <<set $mercEmployedManpower = 0>> + <</if>> + <<if !Number.isInteger($mercTotalManpower)>> + <<set $mercTotalManpower = 0>> + <</if>> + <<if !Number.isInteger($slavesTotalCasualties)>> + <<set $slavesTotalCasualties = 0>> + <</if>> + <<if !Number.isInteger($slavesEmployedManpower)>> + <<set $slavesEmployedManpower = 0>> + <</if>> + <<if !Number.isInteger($militiaTotalCasualties)>> + <<set $militiaTotalCasualties = 0>> + <</if>> + <<if !Number.isInteger($militiaEmployedManpower)>> + <<set $militiaEmployedManpower = 0>> + <</if>> + <<if !Number.isInteger($militiaFreeManpower)>> + <<set $militiaFreeManpower = 0>> + <</if>> + <<if !Number.isInteger($militiaTotalManpower)>> + <<set $militiaTotalManpower = 0>> + <</if>> + <<if !Number.isInteger($battlesCount)>> + <<set $battlesCount = 0>> + <</if>> <</widget>> \ No newline at end of file diff --git a/src/SecExp/widgets/unitsWidgets.tw b/src/SecExp/widgets/unitsWidgets.tw index 5bcaeca6185..e7fb0b99121 100644 --- a/src/SecExp/widgets/unitsWidgets.tw +++ b/src/SecExp/widgets/unitsWidgets.tw @@ -98,7 +98,7 @@ <<widget "secBotsDescription">> <<if $secBots.active == 1>> - <strong>The security drones</strong> assemble in an ordered line in front of you, ready to receive their orders. + <strong>The security drones</strong> assemble in an ordered line in front of you, ready to receive their orders. All <<print $secBots.troops>> stand before you in absolute silence. <<if $secBots.troops < $secBots.maxTroops>> The unit is not at its full strength of $secBots.maxTroops drones.<</if>> <<if $secBots.equip == 0>> They are equipped with light weaponry, mainly anti-riot non lethal weapons. Not particularly effective in battle. -- GitLab