Skip to content
Snippets Groups Projects
Commit 7995d753 authored by ezsh's avatar ezsh
Browse files

Add explicit function for autosurgery procedures sorting

parent da7e0da0
No related branches found
No related tags found
1 merge request!10545Rework cosmetic implant surgeries and the RA interface to them
...@@ -91,6 +91,15 @@ globalThis.rulesAutosurgery = (function() { ...@@ -91,6 +91,15 @@ globalThis.rulesAutosurgery = (function() {
surgeryDamage(slave, healthCost); surgeryDamage(slave, healthCost);
} }
/**
* Computes procedure efficiency for selecting the best one
* @param {App.Medicine.Surgery.Procedure} proc
*/
function procedureEfficiency(proc) {
const value = typeof proc.changeValue === "number" ? proc.changeValue : 1.;
return (value / proc.cost + value/proc.healthCost);
}
/** /**
* @param {"boobs"|"butt"} bodyPart * @param {"boobs"|"butt"} bodyPart
* @param {!FC.RA.NumericRange} range * @param {!FC.RA.NumericRange} range
...@@ -102,11 +111,12 @@ globalThis.rulesAutosurgery = (function() { ...@@ -102,11 +111,12 @@ globalThis.rulesAutosurgery = (function() {
const shallGrow = distance > 0; const shallGrow = distance > 0;
/** @type {FC.Medicine.Surgery.SizingOptions} */ /** @type {FC.Medicine.Surgery.SizingOptions} */
const options = { const options = {
types: implantTypes.length ? implantTypes : null // we can't set null via RA UI :( types: implantTypes && implantTypes.length ? implantTypes : null // we can't set null via RA UI :(
}; };
options.strictTypes = options.types && options.types.length > 0; options.strictTypes = options.types && options.types.length > 0;
const shallReplaceImplantType = slave[`${bodyPart}Implant`] > 0 && const shallReplaceImplantType = slave[`${bodyPart}Implant`] > 0 &&
options.types && !options.types.some(v => v === slave[`${bodyPart}ImplantType`]); options.types && !options.types.some(v => v === slave[`${bodyPart}ImplantType`]);
/** @type {(left: App.Medicine.Surgery.Procedure, right: App.Medicine.Surgery.Procedure) => number} */
let sorter; let sorter;
if (shallShrink) { if (shallShrink) {
if (range.max === 0) { if (range.max === 0) {
...@@ -114,11 +124,11 @@ globalThis.rulesAutosurgery = (function() { ...@@ -114,11 +124,11 @@ globalThis.rulesAutosurgery = (function() {
} }
options.reduction = true; options.reduction = true;
options.replace = true; options.replace = true;
sorter = (left, right) => -right.targetEffect / right.costs + left.targetEffect / left.costs; sorter = (left, right) => -procedureEfficiency(right) + procedureEfficiency(left);
} else if (shallGrow) { } else if (shallGrow) {
options.augmentation = true; options.augmentation = true;
options.replace = true; options.replace = true;
sorter = (left, right) => right.targetEffect / right.costs - left.targetEffect / left.costs; sorter = (left, right) => procedureEfficiency(right) - procedureEfficiency(left);
} }
if (!shallShrink && !shallGrow && !shallReplaceImplantType) { if (!shallShrink && !shallGrow && !shallReplaceImplantType) {
return; return;
...@@ -128,7 +138,7 @@ globalThis.rulesAutosurgery = (function() { ...@@ -128,7 +138,7 @@ globalThis.rulesAutosurgery = (function() {
// we allow implant removal because there might be no other way to change its type // we allow implant removal because there might be no other way to change its type
options.types = options.types ? [...options.types, "none"] : ["none"]; options.types = options.types ? [...options.types, "none"] : ["none"];
options.reduction = true; options.reduction = true;
sorter = (left, right) => right.targetEffect / right.costs - left.targetEffect / left.costs; sorter = (left, right) => procedureEfficiency(right) - procedureEfficiency(left);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment