From 84b0a5c60570b5d994f2aafe4e640c9de707ed20 Mon Sep 17 00:00:00 2001 From: Svornost <11434-svornost@users.noreply.gitgud.io> Date: Fri, 28 Aug 2020 14:32:52 -0700 Subject: [PATCH] Add slave sorting by health, weight, muscles, sex drive, and pregnancy. --- src/js/assayJS.js | 35 ++++++++++++++++++++++++++++++++++- src/js/slaveListing.js | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/js/assayJS.js b/src/js/assayJS.js index 1dc09feb934..4397ae52400 100644 --- a/src/js/assayJS.js +++ b/src/js/assayJS.js @@ -1551,6 +1551,29 @@ globalThis.PaternalistName = function(slave) { }; globalThis.SlaveSort = function() { + const effectivePreg = (slave) => { + // slave.preg is only *mostly* usable for sorting + if (slave.preg > 0 && !slave.pregKnown) { + // don't reveal unknown pregnancies + return 0; + } + if (slave.pubertyXX === 0 && (slave.ovaries === 1 || slave.mpreg === 1)) { + // not ovulating yet - sort between barren slaves and slaves on contraceptives + return -1.2; + } else if (slave.ovaryAge >= 47 && (slave.ovaries === 1 || slave.mpreg === 1)) { + // menopausal - sort between barren slaves and slaves on contraceptives + return -1.1; + } else if (slave.pregWeek < 0) { + // postpartum - sort between slaves on contraceptives and fertile slaves + return -0.1; + } + return slave.preg; + }; + + const effectiveEnergy = (slave) => { + return slave.attrKnown === 1 ? slave.energy : -101; + }; + const comparators = { Aassignment: (a, b) => a.assignment < b.assignment ? -1 : 1, Dassignment: (a, b) => a.assignment > b.assignment ? -1 : 1, @@ -1569,7 +1592,17 @@ globalThis.SlaveSort = function() { AID: (a, b) => a.ID - b.ID, DID: (a, b) => b.ID - a.ID, AweeklyIncome: (a, b) => a.lastWeeksCashIncome - b.lastWeeksCashIncome, - DweeklyIncome: (a, b) => b.lastWeeksCashIncome - a.lastWeeksCashIncome + DweeklyIncome: (a, b) => b.lastWeeksCashIncome - a.lastWeeksCashIncome, + Ahealth: (a, b) => a.health.condition - b.health.condition, + Dhealth: (a, b) => b.health.condition - a.health.condition, + Aweight: (a, b) => a.weight - b.weight, + Dweight: (a, b) => b.weight - a.weight, + Amuscles: (a, b) => a.muscles - b.muscles, + Dmuscles: (a, b) => b.muscles - a.muscles, + AsexDrive: (a, b) => effectiveEnergy(a) - effectiveEnergy(b), + DsexDrive: (a, b) => effectiveEnergy(b) - effectiveEnergy(a), + Apregnancy: (a, b) => effectivePreg(a) - effectivePreg(b), + Dpregnancy: (a, b) => effectivePreg(b) - effectivePreg(a), }; return { diff --git a/src/js/slaveListing.js b/src/js/slaveListing.js index 97092d68f86..0dcd37aab3c 100644 --- a/src/js/slaveListing.js +++ b/src/js/slaveListing.js @@ -586,7 +586,7 @@ App.UI.SlaveList.sortingLinks = function(passage) { const textify = string => capFirstChar(string.replace(/([A-Z])/g, " $1")); let innerDiv = App.UI.DOM.makeElement("div", "Sort by: ", "indent"); - let order = ["devotion", "name", "assignment", "seniority", "actualAge", "visualAge", "physicalAge", "weeklyIncome"] + let order = ["devotion", "name", "assignment", "seniority", "actualAge", "visualAge", "physicalAge", "weeklyIncome", "health", "weight", "muscles", "sexDrive", "pregnancy"] .map(so => V.sortSlavesBy !== so ? App.UI.DOM.passageLink(textify(so), passage, () => { V.sortSlavesBy = so; }) : textify(so)); innerDiv.append(App.UI.DOM.arrayToList(order, " | ", " | ")); -- GitLab