diff --git a/devNotes/Useful JS Function Documentation.txt b/devNotes/Useful JS Function Documentation.txt index dc49283b8ecad54e8d14074b13dee6a43832bf6e..25502b5fa51f4273cd32c0419d40a550b4142ba6 100644 --- a/devNotes/Useful JS Function Documentation.txt +++ b/devNotes/Useful JS Function Documentation.txt @@ -225,8 +225,10 @@ UtilJS [script] weightedArray2HashMap() - between(a, low, high) - outputs the value down the middle of two inputs e.g. - between($trees, 1, 3) returns $trees = 2 + 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. diff --git a/js/utils.js b/js/utils.js index 2026efe2e9c794e6c0fb3abed122be3709f2735c..112b768fdcabcad130b4d56b8a24d0e7d4209881 100644 --- a/js/utils.js +++ b/js/utils.js @@ -28,12 +28,17 @@ function isFloat(n) { * @param {number} a * @param {number} low * @param {number} high + * @param {string} mode, deafults to 'exclusive' but also supports 'inclusive'. * @returns {boolean} */ -function between(a, low, high) { +function between(a, low, high, mode = 'exclusive') { if (low === null) { low = -Infinity; } if (high === null) { high = Infinity; } - return (a > low && a < high); + if (mode === 'exclusive') { + return a > low && a < high; + } else if (mode === 'inclusive') { + return a >= low && a <= high; + } } /** diff --git a/src/js/slaveCostJS.js b/src/js/slaveCostJS.js index 8f805e46b4d573872fbadbd14117a392ee54036d..fbfc900bf5e03f5c70f2fcfcfe8ad60497718eaf 100644 --- a/src/js/slaveCostJS.js +++ b/src/js/slaveCostJS.js @@ -415,7 +415,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)) { + if (between(V.retirementAge, 30, 60, 'inclusive')) { 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 */ } }