diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index 6ae89e116988058bcc822e265e15a07063e7dcd3..98b66a44388e435ac40f3bc7a3791e9a17cac9c1 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -545,10 +545,6 @@ App.Data.resetOnNGPlus = { PCvictories: 0, PClosses: 0, - /* buildings */ - woundType: 0, - /* 0:no wound, 1:mute, 2:blind, 3:amputee, 4<:health */ - reminderEntry: "", reminderWeek: "", lastWeeksCashIncome: {}, diff --git a/src/Mods/SecExp/attackHandler.tw b/src/Mods/SecExp/attackHandler.tw index 3b5a7102d831bd231a10048a928fb7b82fc74ea6..21134caec5f9fcd3225674bd20f1628b5d1295bc 100644 --- a/src/Mods/SecExp/attackHandler.tw +++ b/src/Mods/SecExp/attackHandler.tw @@ -314,23 +314,6 @@ <<set _mercMod -= 0.2>> <<set _SFMod -= 0.2>> <<set _enemyMod += 0.2>> - <<set $woundType = random(1,10)>> - <<set _i = $slaveIndices[$Bodyguard.ID]>> - <<if $woundType == 1>> - <<set $slaves[_i].voice = 0>> - <<run healthDamage($slaves[$i], 60)>> - <<elseif $woundType == 2>> - <<run eyeSurgery($slaves[_i], "both", "blind"), healthDamage($slaves[$i], 30)>> - <<elseif $woundType == 3>> - <<run removeLimbs($slaves[_i], "all")>> - <<run healthDamage($slaves[$i], 80)>> - <<elseif $woundType >= 4>> - <<if $slaves[_i].health.health >= -60>> - <<run healthDamage($slaves[$i], 30)>> - <<else>> - <<run healthDamage($slaves[$i], -90 - $slaves[$i].health.health)>> - <</if>> - <</if>> <</if>> /* 60% chance of getting combat skill if not already have it */ <<if $Bodyguard.skill.combat == 0 && random(1,100) <= 60>> @@ -439,23 +422,6 @@ <<set _mercMod -= 0.2>> <<set _SFMod -= 0.2>> <<set _enemyMod += 0.2>> - <<set $woundType = random(1,10)>> - <<set _i = $slaveIndices[$HeadGirl.ID]>> - <<if $woundType == 1>> - <<set $slaves[_i].voice = 0>> - <<run healthDamage($slaves[$i], 60)>> - <<elseif $woundType == 2>> - <<set eyeSurgery($slaves[_i], "both", "blind"), healthDamage($slaves[$i], 30)>> - <<elseif $woundType == 3>> - <<run removeLimbs($slaves[_i], "all")>> - <<run healthDamage($slaves[$i], 80)>> - <<elseif $woundType >= 4>> - <<if $slaves[_i].health.health >= -60>> - <<run healthDamage($slaves[$i], 30)>> - <<else>> - <<run healthDamage($slaves[$i], -90 - $slaves[$i].health.health)>> - <</if>> - <</if>> <</if>> /* 60% chance of getting combat skill if not already have it */ <<if $HeadGirl.skill.combat == 0 && random(1,100) <= 60>> diff --git a/src/Mods/SecExp/attackReport.tw b/src/Mods/SecExp/attackReport.tw index 3d92154f759cf10cbf5c02957d47bd4e55e5581b..65d8d802a2d4f0c708f50762fa4c6a281439adf2 100644 --- a/src/Mods/SecExp/attackReport.tw +++ b/src/Mods/SecExp/attackReport.tw @@ -945,15 +945,18 @@ <<if $gainedCombat == 1>> During the battle, $he had to fight for $his life, giving $him experience in modern combat. $He is now proficient with modern firearms and hand to hand combat. <</if>> - <<if $woundType != 0>> + <<if $leaderWounded == 1>> Unfortunately, @@.red;$he sustained major injuries.@@ - <<if $woundType == 1>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Bodyguard.ID))>> + <<if _woundType == "voice">> A stray bullet hit $his neck. While $he fortunately avoided fatal hemorrhaging, $his vocal cords were irreparably damaged. - <<elseif $woundType == 2>> + <<elseif _woundType == "eyes">> Some shrapnel found $his eyes as their final target, blinding $him permanently. - <<elseif $woundType == 3>> - A grenade landed close to $him, rendering $him a quadruple amputee. - <<elseif $woundType >= 4>> + <<elseif _woundType == "legs">> + A grenade landed close to $him, and $his badly mangled legs had to be amputated. + <<elseif _woundType == "arm">> + A shrapnel blast mangled one of $his arms, which had to be amputated. + <<elseif _woundType == "flesh">> While gravely wounded, it seems $he will be able to fully recover, given enough time. <</if>> Your troops were greatly affected by the loss of their leader. @@ -1079,15 +1082,18 @@ <<if $gainedCombat == 1>> During the battle, $he had to fight for $his life, giving $him experience in modern combat. $He is now proficient with modern firearms and hand to hand combat. <</if>> - <<if $woundType != 0>> - Unfortunately, @@.red;$he sustained severe injuries.@@ - <<if $woundType == 1>> + <<if $leaderWounded == 1>> + Unfortunately, @@.red;$he sustained major injuries.@@ + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Bodyguard.ID))>> + <<if _woundType == "voice">> A stray bullet hit $his neck. While $he fortunately avoided fatal hemorrhaging, $his vocal cords were irreparably damaged. - <<elseif $woundType == 2>> - Some shrapnel found $his eyes as final their target, blinding $him permanently. - <<elseif $woundType == 3>> - A grenade landed close to $him, rendering $him a quadruple amputee. - <<elseif $woundType >= 4>> + <<elseif _woundType == "eyes">> + Some shrapnel found $his eyes as their final target, blinding $him permanently. + <<elseif _woundType == "legs">> + A grenade landed close to $him, and $his badly mangled legs had to be amputated. + <<elseif _woundType == "arm">> + A shrapnel blast mangled one of $his arms, which had to be amputated. + <<elseif _woundType == "flesh">> While gravely wounded, it seems $he will be able to fully recover, given enough time. <</if>> Your troops were greatly affected by the loss of their leader. @@ -1500,7 +1506,6 @@ <<run delete $bribeCost>> <<set $leaderWounded = 0>> <<set $gainedWarfare = 0>> -<<set $woundType = 0>> <<set $tacticsSuccessful = 0>> <<set $attackType = "none">> <<set $chosenTactic = "none">> diff --git a/src/Mods/SecExp/js/secExp.js b/src/Mods/SecExp/js/secExp.js index 25d6d41a695de4b12e5fe4bfc81335f08d3999ae..d58a4381715773d2f4a484239122ff0d97ba5c20 100644 --- a/src/Mods/SecExp/js/secExp.js +++ b/src/Mods/SecExp/js/secExp.js @@ -904,3 +904,72 @@ App.SecExp.Manpower = { return this.employedMerc + this.employedMilitia + this.employedSlave; } }; + +App.SecExp.inflictBattleWound = (function() { + /** @typedef {object} Wound + * @property {number} weight + * @property {function(App.Entity.SlaveState):boolean} allowed + * @property {function(App.Entity.SlaveState):void} effects + */ + /** @type { Object<string, Wound> } */ + const wounds = { + eyes: { + weight: 10, + allowed: (s) => canSee(s), + effects: (s) => { clampedDamage(s, 30); eyeSurgery(s, "both", "blind"); } + }, + voice: { + weight: 10, + allowed: (s) => canTalk(s), + effects: (s) => { clampedDamage(s, 60); s.voice = 0; } + }, + legs: { + weight: 5, + allowed: (s) => hasAnyNaturalLegs(s), + effects: (s) => { clampedDamage(s, 80); removeLimbs(s, "left leg"); removeLimbs(s, "right leg"); } + }, + arm: { + weight: 5, + allowed: (s) => hasAnyNaturalArms(s), + effects: (s) => { clampedDamage(s, 60); removeLimbs(s, jsEither(["left arm", "right arm"])); } + }, + flesh: { + weight: 70, + allowed: () => true, + effects: (s) => { clampedDamage(s, 30); } + } + // TODO: add more wound types? destroy prosthetics? + }; + + /** Inflicts a large amount of damage upon a slave without killing them (i.e. leaving their health total above -90) + * @param {App.Entity.SlaveState} slave + * @param {number} magnitude + */ + function clampedDamage(slave, magnitude) { + if ((slave.health.health - magnitude) > -90) { + healthDamage(slave, magnitude); + } else { + healthDamage(slave, 90 + slave.health.health); + } + } + + /** Inflicts a wound upon a slave during a battle. Returns the wound type from the wound table (see above) so it can be described. + * @param {App.Entity.SlaveState} slave + * @returns {string} + */ + function doWound(slave) { + let woundHash = {}; + for (const w of Object.keys(wounds)) { + if (wounds[w].allowed(slave)) { + woundHash[w] = wounds[w].weight; + } + } + /** @type {string} */ + // @ts-ignore - FIXME: hashChoice has bad JSDoc + const wound = hashChoice(woundHash); + wounds[wound].effects(slave); + return wound; + } + + return doWound; +})(); diff --git a/src/Mods/SecExp/rebellionHandler.tw b/src/Mods/SecExp/rebellionHandler.tw index ae14f8f02ccea25fc49addc0d46ee2e71902966c..2682d53b923997f71f86cae2c302738f0a01d76b 100644 --- a/src/Mods/SecExp/rebellionHandler.tw +++ b/src/Mods/SecExp/rebellionHandler.tw @@ -137,6 +137,7 @@ <</if>> <<set _armyMod = Math.trunc(_armyMod)>> +<<set _rebellingSlaves = 0, _rebellingMilitia = 0, _rebellingMercs = 0>> <<if $slaveRebellion == 1>> <<set _rebellingSlaves = 1>> <<set _unit = App.SecExp.getIrregularUnit("Slaves", $attackTroops, $attackEquip)>> diff --git a/src/Mods/SecExp/rebellionReport.tw b/src/Mods/SecExp/rebellionReport.tw index 47661795c5aa89473c34174eeab5eba78da79bd0..179172865190ce9618280a183721a45a36168e92 100644 --- a/src/Mods/SecExp/rebellionReport.tw +++ b/src/Mods/SecExp/rebellionReport.tw @@ -603,23 +603,17 @@ <<set _woundChance *= random(2,4)>> <<if random(1,100) <= _woundChance>> Your Concubine was unfortunately caught in the crossfire and - <<set $woundType = random(1,10)>> - <<if $woundType == 1>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Concubine.ID))>> + <<if _woundType == "voice">> a splinter pierced $his throat, severing $his vocal cords. - <<set $Concubine.voice = 0>> - <<elseif $woundType == 2>> + <<elseif _woundType == "eyes">> a splinter hit $his face, severely damaging $his eyes. - <<run eyeSurgery($Concubine, "both", "blind")>> - <<elseif $woundType == 3>> - an explosion near $him caused the loss of all $his limbs. - <<run removeLimbs($Concubine, "all")>> - <<elseif $woundType >= 4>> + <<elseif _woundType == "legs">> + an explosion near $him caused the loss of both of $his legs. + <<elseif _woundType == "arm">> + an explosion near $him caused the loss of one of $his arms. + <<elseif _woundType == "flesh">> a stray shot severely wounded $him. - <<if $Concubine.health.health >= -60>> - <<run healthDamage($Concubine, 30)>> - <<else>> - <<run healthDamage($Concubine, -90 - $Concubine.health.health)>> - <</if>> <</if>> <</if>> <</if>> @@ -664,23 +658,17 @@ <<set _woundChance *= random(2,4)>> <<if random(1,100) <= _woundChance>> During one of the assaults your Bodyguard was hit. - <<set $woundType = random(1,10)>> - <<if $woundType == 1>> - A splinter pierced _his2 throat, severing _his2 vocal cords. - <<set $Bodyguard.voice = 0>> - <<elseif $woundType == 2>> - A splinter hit _his2 face, severely damaging _his2 eyes. - <<run eyeSurgery($Bodyguard, "both", "blind")>> - <<elseif $woundType == 3>> - An explosion near _him2 caused the loss of all _his2 limbs. - <<run removeLimbs($Bodyguard, "all")>> - <<elseif $woundType >= 4>> - A stray shot severely wounded _him2. - <<if $Bodyguard.health.health >= -60>> - <<run healthDamage($Bodyguard, 30)>> - <<else>> - <<run healthDamage($Bodyguard, $Bodyguard.health.health + 90)>> - <</if>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Bodyguard.ID))>> + <<if _woundType == "voice">> + A splinter pierced $his throat, severing $his vocal cords. + <<elseif _woundType == "eyes">> + A splinter hit $his face, severely damaging $his eyes. + <<elseif _woundType == "legs">> + An explosion near $him caused the loss of both of $his legs. + <<elseif _woundType == "arm">> + An explosion near $him caused the loss of one of $his arms. + <<elseif _woundType == "flesh">> + A stray shot severely wounded $him. <</if>> <</if>> The damage to the structure will be @@.red;costly to repair.@@ @@ -772,23 +760,17 @@ <<set _woundChance *= random(2,4)>> <<if random(1,100) <= _woundChance>> Your Concubine was unfortunately caught in the crossfire and - <<set $woundType = random(1,10)>> - <<if $woundType == 1>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Concubine.ID))>> + <<if _woundType == "voice">> a splinter pierced $his throat, severing $his vocal cords. - <<set $Concubine.voice = 0>> - <<elseif $woundType == 2>> + <<elseif _woundType == "eyes">> a splinter hit $his face, severely damaging $his eyes. - <<run eyeSurgery($Concubine, "both", "blind")>> - <<elseif $woundType == 3>> - an explosion near $him caused the loss of all $his limbs. - <<run removeLimbs($Concubine, "all")>> - <<elseif $woundType >= 4>> + <<elseif _woundType == "legs">> + an explosion near $him caused the loss of both of $his legs. + <<elseif _woundType == "arm">> + an explosion near $him caused the loss of one of $his arms. + <<elseif _woundType == "flesh">> a stray shot severely wounded $him. - <<if $Concubine.health.health >= -60>> - <<run healthDamage($Concubine, 30)>> - <<else>> - <<run healthDamage($Concubine, $Concubine.health.health + 90)>> - <</if>> <</if>> <</if>> <</if>> @@ -881,23 +863,17 @@ <<set _woundChance *= random(2,4)>> <<if random(1,100) <= _woundChance>> Your Concubine was unfortunately caught in the crossfire and - <<set $woundType = random(1,10)>> - <<if $woundType == 1>> + <<set _woundType = App.SecExp.inflictBattleWound(getSlave($Concubine.ID))>> + <<if _woundType == "voice">> a splinter pierced $his throat, severing $his vocal cords. - <<set $Concubine.voice = 0>> - <<elseif $woundType == 2>> + <<elseif _woundType == "eyes">> a splinter hit $his face, severely damaging $his eyes. - <<run eyeSurgery($Concubine, "both", "blind")>> - <<elseif $woundType == 3>> - an explosion near $him caused the loss of all $his limbs. - <<run removeLimbs($Concubine, "all")>> - <<elseif $woundType >= 4>> + <<elseif _woundType == "legs">> + an explosion near $him caused the loss of both of $his legs. + <<elseif _woundType == "arm">> + an explosion near $him caused the loss of one of $his arms. + <<elseif _woundType == "flesh">> a stray shot severely wounded $him. - <<if $Concubine.health.health >= -60>> - <<run healthDamage($Concubine, 30)>> - <<else>> - <<run healthDamage($Concubine, -90 - $Concubine.health.health)>> - <</if>> <</if>> <</if>> <</if>>