diff --git a/devNotes/standaloneFunctions.md b/devNotes/standaloneFunctions.md index 778be13a60a117c38f8936adb09a37cfc8febb04..7526fe940f275543534d33b0508f7be921ff8991 100644 --- a/devNotes/standaloneFunctions.md +++ b/devNotes/standaloneFunctions.md @@ -27,6 +27,3 @@ Collection of custom functions without dependencies on FC specific variables/dat * `jsDef(x)`: Returns whether x is undefined. A JS port of SugarCube's def. - -* `between(a, low, high)`: - Returns `true` if `a` is between `low` and `high`, otherwise `false`. diff --git a/devNotes/usefulJSFunctionDocumentation.txt b/devNotes/usefulJSFunctionDocumentation.txt index 4c85aa3bc1b94c90092265880080414451b19365..0108b253a8c74b72104c2048239bafb36f69aab1 100644 --- a/devNotes/usefulJSFunctionDocumentation.txt +++ b/devNotes/usefulJSFunctionDocumentation.txt @@ -238,11 +238,6 @@ UtilJS [script] weightedArray2HashMap() - between(a, low, high, mode = 'exclusive') - checks if the value is between low and high inputs. mode: defaults to exclusive but also supports 'inclusive'. e.g. - $trees === 1. - exclusive - between($trees, 1, 3) -> false - inclusive - between($trees, 1, 3) -> true - def() - Returns whether the input is defined, similar to SugarCube's def. Core Slave Functions: diff --git a/devTools/types/extensions.d.ts b/devTools/types/extensions.d.ts index b9b32455c007436a957ba03a8cf9afb982b2aeef..3b69613e15631488e2508f0b97dd86b14776765b 100644 --- a/devTools/types/extensions.d.ts +++ b/devTools/types/extensions.d.ts @@ -3,6 +3,16 @@ interface MousetrapStatic { record(callback: (this: MousetrapStatic, sequence: string[]) => void): void; } +interface Number { + /** + * Returns whether the value is between the given bounds, with optional inclusivity. + * @param min The minimum value to check against. + * @param max The maximum value to check against. + * @param inclusive Whether to include the bounds values. + */ + isBetween(min: number, max: number, inclusive?: boolean): boolean; +} + // d3-dtree declare namespace d3dTree { diff --git a/js/extensions/number.extension.js b/js/extensions/number.extension.js new file mode 100644 index 0000000000000000000000000000000000000000..4100d71828586408ac09ad1d87ade1bd922d709a --- /dev/null +++ b/js/extensions/number.extension.js @@ -0,0 +1,3 @@ +Number.prototype.isBetween = function(min, max, inclusive = false) { + return inclusive ? this >= min && this <= max : this > min && this < max; +}; diff --git a/js/utils.js b/js/utils.js index 09a51932aa4f3a140d97b20ffaa438b2eb55386e..32ff8ed53793bc6e54a4e7504f4ea816c63cbda2 100644 --- a/js/utils.js +++ b/js/utils.js @@ -13,24 +13,6 @@ function jsDef(x) { return !(typeof x === "undefined" || x === null || x === undefined); } -/** - * Determines if a is between low and high - * @param {number} a - * @param {number} low - * @param {number} high - * @param {"exclusive"|"inclusive"} [mode='exclusive'] defaults to 'exclusive' but also supports 'inclusive'. - * @returns {boolean} - */ -function between(a, low, high, mode = 'exclusive') { - if (low === null) { low = -Infinity; } - if (high === null) { high = Infinity; } - if (mode === 'exclusive') { - return a > low && a < high; - } else if (mode === 'inclusive') { - return a >= low && a <= high; - } -} - /** * @template {PropertyKey} T * @param {Object.<T, number>} obj diff --git a/src/Mods/SecExp/js/secExpBC.js b/src/Mods/SecExp/js/secExpBC.js index 7274b6d7b5525b789415e5db991cce632a7fdf59..cd64d30599ab68d3ab4f743296aa45562f9a6eea 100644 --- a/src/Mods/SecExp/js/secExpBC.js +++ b/src/Mods/SecExp/js/secExpBC.js @@ -40,7 +40,7 @@ App.SecExp.generalBC = function() { V.SecExp.edicts.SFSupportLevel = V.SecExp.edicts.SFSupportLevel || V.SFSupportLevel || 0; V.SecExp.edicts.limitImmigration = V.SecExp.edicts.limitImmigration || V.limitImmigration || 0; V.SecExp.edicts.openBorders = V.SecExp.edicts.openBorders || V.openBorders || 0; - V.SecExp.edicts.weaponsLaw = V.weaponsLaw || between(V.SecExp.edicts.weaponsLaw, 0, 3, 'inclusive') ? V.SecExp.edicts.weaponsLaw : 3; + V.SecExp.edicts.weaponsLaw = V.weaponsLaw || V.SecExp.edicts.weaponsLaw.isBetween(0, 3, true) ? V.SecExp.edicts.weaponsLaw : 3; V.SecExp.edicts.defense.soldierWages = V.SecExp.edicts.defense.soldierWages || V.soldierWages || 1; V.SecExp.edicts.defense.slavesOfficers = V.SecExp.edicts.defense.slavesOfficers || V.slavesOfficers || 0; diff --git a/src/Mods/SpecialForce/SpecialForce.js b/src/Mods/SpecialForce/SpecialForce.js index 7eff80ab62eeba5ea720eaf19d516e035add653a..e736864af8311eefd84f18295e113230bd948d9b 100644 --- a/src/Mods/SpecialForce/SpecialForce.js +++ b/src/Mods/SpecialForce/SpecialForce.js @@ -1393,7 +1393,7 @@ App.SF.AAR = function(endWeekCall = 1) { upkeep *= 0.75 + (V.SF.ArmySize/10000); } - if (between(V.economy, 33, 100)) { + if (V.economy.isBetween(33, 100)) { let multiplier = (1.75 * Math.sqrt(Math.trunc(100000/V.economy-1000)/10)) + (0.2 * (Math.trunc(100000/V.economy-1000)/10)); income *= (1 + multiplier/100); } else if (V.economy <= 33) { // There comes a point where a worse global economy no longer benefits your Special Forces. diff --git a/src/endWeek/saServeYourOtherSlaves.js b/src/endWeek/saServeYourOtherSlaves.js index a1c0b9f79dfb472c9924c2868cee4f50380f3598..974f646cf6142796e82b4b9f88389aef4fed30a7 100644 --- a/src/endWeek/saServeYourOtherSlaves.js +++ b/src/endWeek/saServeYourOtherSlaves.js @@ -1456,7 +1456,7 @@ App.SlaveAssignment.serveYourOtherSlaves = (function() { if (slave.fetishStrength < 100) { slave.fetishStrength++; } - } else if (fetishChange > jsRandom(0, 100) && slave.fetish !== "masochist" && slave.fetish !== "submissive" && between(App.EndWeek.saVars.subSlaveRatio, 0, 0.8)) { + } else if (fetishChange > jsRandom(0, 100) && slave.fetish !== "masochist" && slave.fetish !== "submissive" && App.EndWeek.saVars.subSlaveRatio.isBetween(0, 0.8)) { r.push(`Being used as much as ${he} is starts to take a toll on ${him} sexuality; <span class="lightcoral">${he} begins to enjoy being your chattel's fucktoy.</span>`); slave.fetish = "submissive"; slave.fetishStrength = 65; diff --git a/src/js/rulesAssistant.js b/src/js/rulesAssistant.js index c524403210c586ba7b2fb4920d67a380ff3edb2d..e16b7e61a74b24600a499455f6c4aead3e866b94 100644 --- a/src/js/rulesAssistant.js +++ b/src/js/rulesAssistant.js @@ -142,10 +142,7 @@ globalThis.ruleAppliesP = function(rule, slave) { slave ); } - flag = between( - slaveAttribute, - cond.data.value[0], - cond.data.value[1]); + flag = slaveAttribute.isBetween(cond.data.value[0], cond.data.value[1]); if (cond.applyRuleOnce && flag) { V.rulesToApplyOnce[rule.ID].push(slave.ID); } diff --git a/src/js/slaveCostJS.js b/src/js/slaveCostJS.js index fcbb4a71a861ce6cad4e6a41a41be5bc9b5c1838..778d7f550bdff8e9eb1c1fd130d985616c0da4d1 100644 --- a/src/js/slaveCostJS.js +++ b/src/js/slaveCostJS.js @@ -433,7 +433,7 @@ globalThis.BeautyArray = (function() { adjustBeauty("Age: Youth Preferentialist", ((30 - slave.visualAge) / (30 - V.minimumSlaveAge) * ((arcology.FSYouthPreferentialist / 2) + (arcology.FSYouthPreferentialistLaw * 10)))); /* max 60 */ } } else if (arcology.FSMaturityPreferentialist !== "unset") { - if (between(V.retirementAge, 30, 60, 'inclusive')) { + if (V.retirementAge.isBetween(30, 60, true)) { adjustBeauty("Age: Maturity Preferentialist", ((30 - slave.visualAge) / (30 - V.retirementAge) * ((arcology.FSMaturityPreferentialist / 2) + (arcology.FSMaturityPreferentialistLaw * 10)))); /* max 60, problems if retirementAge is 30 or under */ } } diff --git a/src/pregmod/eliteBreedingExam.js b/src/pregmod/eliteBreedingExam.js index c5c2a3afa28cbc58ec241e1336e7fad06e41d6aa..bc5ebdf955f4c8cca87f01984512433cd14e6839 100644 --- a/src/pregmod/eliteBreedingExam.js +++ b/src/pregmod/eliteBreedingExam.js @@ -199,7 +199,7 @@ globalThis.eliteBreedingExam = function(slave = null) { } r.push(`Must not be overweight. ${result()}`); if (slave) { - test = between(slave.muscles, musclesMin, musclesMax); + test = slave.muscles.isBetween(musclesMin, musclesMax); fixable = (slave.muscles <= musclesMin && slave.muscles > musclesMax - musclesMin) || (slave.muscles >= musclesMax && slave.muscles < musclesMin + 30); if (fixable && passing === 0) { passing = 2;