From e45487e4074ed7f3ea66b89bf40cdf7591928474 Mon Sep 17 00:00:00 2001
From: Jones <Jones>
Date: Fri, 3 Apr 2020 20:59:01 +0200
Subject: [PATCH] Initial

---
 js/003-data/gameVariableData.js               |   3 +
 .../backwardsCompatibility/datatypeCleanup.js |   2 +
 src/js/economyJS.js                           | 128 +++++++++---------
 src/uncategorized/brothel.tw                  |   3 +
 src/uncategorized/slaveAssignmentsReport.tw   |  37 +++--
 5 files changed, 98 insertions(+), 75 deletions(-)

diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js
index 3bb94b11dbd..7e292644edd 100644
--- a/js/003-data/gameVariableData.js
+++ b/js/003-data/gameVariableData.js
@@ -622,6 +622,9 @@ App.Data.resetOnNGPlus = {
 	brothelName: "the Brothel",
 	brothelNameCaps: "The Brothel",
 	brothel: 0,
+	brothelBoost: {
+		selected: 0, eligable: 0 
+	},
 	dairyDecoration: "standard",
 	dairyPrepUpgrade: 0,
 	dairyStimulatorsUpgrade: 0,
diff --git a/src/data/backwardsCompatibility/datatypeCleanup.js b/src/data/backwardsCompatibility/datatypeCleanup.js
index 675c392070c..6d5d69aeb34 100644
--- a/src/data/backwardsCompatibility/datatypeCleanup.js
+++ b/src/data/backwardsCompatibility/datatypeCleanup.js
@@ -2079,6 +2079,8 @@ window.FacilityDatatypeCleanup = (function() {
 		/* upgrades */
 		V.brothel = Math.max(+V.brothel, 0) || 0;
 		V.brothelUpgradeDrugs = Math.clamp(+V.brothelUpgradeDrugs, 0, 2) || 0;
+		V.brothelBoost.selected = Math.clamp(+V.brothelBoost.selected, 0, 10) || 0;
+		V.brothelBoost.eligable = Math.clamp(+V.brothelBoost.eligable, 0, 10) || 0;
 		/* madam */
 		V.Madam = V.slaves.find(s => s.assignment === "be the Madam") || 0;
 		V.MadamIgnoresFlaws = Math.clamp(+V.MadamIgnoresFlaws, 0, 1) || 0;
diff --git a/src/js/economyJS.js b/src/js/economyJS.js
index 1e759df775e..9f222c4126c 100644
--- a/src/js/economyJS.js
+++ b/src/js/economyJS.js
@@ -1114,8 +1114,9 @@ window.slaveJobValues = function(lowerClassSexDemandRef, middleClassSexDemandRef
 			lowerClass: 0,
 			middleClass: 0,
 			upperClass: 0,
-			topClass: 0
-		} // A list of values for each tier of whore (low, middle, upper, top)
+			topClass: 0,
+			boost: 0
+		} // A list of values for each tier of whore (low, middle, upper, top) and a variable for the amount of money earned through the boost
 	};
 	let clubSpots;
 	let brothelSpots;
@@ -1621,6 +1622,9 @@ window.slaveJobValues = function(lowerClassSexDemandRef, middleClassSexDemandRef
 			let income = s.sexAmount * s.sexQuality;
 			let sexMin;
 			let sexBudget;
+			let targetBudget; // Finding the right budget target
+			let fuckMin; // minimum amount of fucks
+			let fuckDev = 3; // standard deviation of fucks
 			const initialHealthPenalty = healthPenalty(s);
 			s.effectiveWhoreClass = effectiveWhoreClass(s);
 			s.maxWhoreClass = s.effectiveWhoreClass;
@@ -1637,6 +1641,8 @@ window.slaveJobValues = function(lowerClassSexDemandRef, middleClassSexDemandRef
 			const lowerClubSupply = slaveJobValues.club * slaveJobValues.clubSP * (lowerClassSexDemandRef / (lowerClassSexDemandRef + middleClassSexDemandRef));
 			const lowerSupply = slaveJobValues.brothel.lowerClass + lowerClubSupply;
 			const lowerSDRatio = lowerSupply / (lowerClassSexDemandRef - V.NPCSexSupply.lowerClass);
+			const demandBoost = 1 + V.brothelBoost.eligable / 50;
+			const priceBoost = 1 + V.brothelBoost.eligable / 20;
 			if (s.effectiveWhoreClass === 4 && topSDRatio > 1 && topSDRatio > upperSDRatio) {
 				s.effectiveWhoreClass -= 1;
 			}
@@ -1647,71 +1653,61 @@ window.slaveJobValues = function(lowerClassSexDemandRef, middleClassSexDemandRef
 				s.effectiveWhoreClass -= 1;
 			}
 
-			// Calculate the stats
-			if (s.effectiveWhoreClass === 4) {
-				sexMin = normalRandInt(30, 2); // The minimum of fucks per week; can increase if needed
-				sexBudget = Math.trunc(V.whoreBudget.topClass * 0.2); // initial maximum price per fuck; can increase if needed
-				while (income > sexBudget * sexMin) { // if the income can not be caught within the initial values of sexMin and sexBudget we increase both as needed in this loop
-					sexMin = Math.trunc(sexMin * 1.1);
-					if (income > sexBudget * sexMin) {
-						sexBudget = Math.trunc(sexBudget * 1.1);
-					}
-				}
-				s.sexAmount = sexMin;
-				tiredFucks(s); // adding tiredness based on number of fucks and then adjusting income in case the tiredness penalty changed as a result.
-				if (healthPenalty(s) < initialHealthPenalty) {
-					income *= healthPenalty(s) / initialHealthPenalty;
-				}
-				s.sexQuality = Math.trunc(income / s.sexAmount);
-				slaveJobValues.brothel.topClass += s.sexAmount * s.sexQuality; // Registering the job value in the right slot
-			} else if (s.effectiveWhoreClass === 3) {
-				sexMin = normalRandInt(40, 3);
-				sexBudget = Math.trunc(V.whoreBudget.upperClass * 0.5);
-				while (income > sexBudget * sexMin) {
-					sexMin = Math.trunc(sexMin * 1.1);
-					if (income > sexBudget * sexMin) {
-						sexBudget = Math.trunc(sexBudget * 1.1);
-					}
-				}
-				s.sexAmount = sexMin;
-				tiredFucks(s);
-				if (healthPenalty(s) < initialHealthPenalty) {
-					income *= healthPenalty(s) / initialHealthPenalty;
-				}
-				s.sexQuality = Math.trunc(income / s.sexAmount);
-				slaveJobValues.brothel.upperClass += s.sexAmount * s.sexQuality;
-			} else if (s.effectiveWhoreClass === 2) {
-				sexMin = normalRandInt(50, 3);
-				sexBudget = V.whoreBudget.middleClass;
-				while (income > sexBudget * sexMin) {
-					sexMin = Math.trunc(sexMin * 1.1);
-					if (income > sexBudget * sexMin) {
-						sexBudget = Math.trunc(sexBudget * 1.1);
-					}
-				}
-				s.sexAmount = sexMin;
-				tiredFucks(s);
-				if (healthPenalty(s) < initialHealthPenalty) {
-					income *= healthPenalty(s) / initialHealthPenalty;
-				}
-				s.sexQuality = Math.trunc(income / s.sexAmount);
-				slaveJobValues.brothel.middleClass += s.sexAmount * s.sexQuality;
-			} else {
-				sexMin = normalRandInt(60, 3);
-				sexBudget = V.whoreBudget.lowerClass * 3;
-				while (income > sexBudget * sexMin) {
-					sexMin = Math.trunc(sexMin * 1.1);
-					if (income > sexBudget * sexMin) {
-						sexBudget = Math.trunc(sexBudget * 1.1);
-					}
-				}
-				s.sexAmount = sexMin;
-				tiredFucks(s);
-				if (healthPenalty(s) < initialHealthPenalty) {
-					income *= healthPenalty(s) / initialHealthPenalty;
+			switch (s.effectiveWhoreClass) {
+				case 1:
+					targetBudget = V.whoreBudget.lowerClass * 3;
+					fuckMin = 60;
+					break;
+				case 2:
+					targetBudget = V.whoreBudget.middleClass;
+					fuckMin = 50;
+					break;
+				case 3:
+					targetBudget = V.whoreBudget.upperClass * 0.5;
+					fuckMin = 40;
+					break;
+				case 4:
+					targetBudget = V.whoreBudget.topClass * 0.2;
+					fuckMin = 30;
+					fuckDev = 2;
+					break;
+				default:
+					targetBudget = V.whoreBudget.lowerClass * 3;
+					fuckMin = 60;
+			}
+
+			sexMin = normalRandInt(fuckMin, fuckDev); // The minimum of fucks per week; can increase if needed
+			sexBudget = Math.trunc(targetBudget); // initial maximum price per fuck; can increase if needed
+			while (income > sexBudget * sexMin) { // if the income can not be caught within the initial values of sexMin and sexBudget we increase both as needed in this loop
+				sexMin = Math.trunc(sexMin * 1.1);
+				if (income > sexBudget * sexMin) {
+					sexBudget = Math.trunc(sexBudget * 1.1);
 				}
-				s.sexQuality = Math.max(Math.trunc(income / s.sexAmount), 2); // The lower class will pay a minimum of 2 per fuck
-				slaveJobValues.brothel.lowerClass += s.sexAmount * s.sexQuality;
+			}
+			s.sexAmount = Math.round(sexMin * demandBoost);
+			tiredFucks(s); // adding tiredness based on number of fucks and then adjusting income in case the tiredness penalty changed as a result.
+			if (healthPenalty(s) < initialHealthPenalty) {
+				income *= healthPenalty(s) / initialHealthPenalty;
+			}
+
+			s.sexQuality = Math.trunc((income * demandBoost * priceBoost) / s.sexAmount);
+			slaveJobValues.brothel.boost += Math.max(Math.trunc(s.sexQuality * s.sexAmount / demandBoost) - Math.trunc(income), 0); // Keeping track of additional benefits from boosting the brothel on the price side and not the amount side.
+
+			switch (s.effectiveWhoreClass) {
+				case 1:
+					slaveJobValues.brothel.lowerClass += s.sexAmount * s.sexQuality;
+					break;
+				case 2:
+					slaveJobValues.brothel.middleClass += s.sexAmount * s.sexQuality; // Registering the job value in the right slot
+					break;
+				case 3:
+					slaveJobValues.brothel.upperClass += s.sexAmount * s.sexQuality;
+					break;
+				case 4:
+					slaveJobValues.brothel.topClass += s.sexAmount * s.sexQuality;
+					break;
+				default:
+					slaveJobValues.brothel.lowerClass += s.sexAmount * s.sexQuality;
 			}
 		}
 
diff --git a/src/uncategorized/brothel.tw b/src/uncategorized/brothel.tw
index 17898fb95ca..9c4a618f615 100644
--- a/src/uncategorized/brothel.tw
+++ b/src/uncategorized/brothel.tw
@@ -151,6 +151,9 @@
 			<</link>>
 		</div>
 	<</if>>
+	<br>The brothel could be more profitable if started spending time in the brothel you would otherwise spend in public. Your reputation will suffer, but paying customers may seek out your whores if they think it means you'll lend them your ear.
+	<br>Boost: <<if $brothelBoost.selected != 0>>[[None|Brothel][$brothelBoost.selected = 0]]<<else>>None<</if>> | <<if $brothelBoost.selected != 1>>[[5%|Brothel][$brothelBoost.selected = 1]]<<else>>5%<</if>> | <<if $brothelBoost.selected != 2>>[[10%|Brothel][$brothelBoost.selected = 2]]<<else>>10%<</if>> | <<if $brothelBoost.selected != 3>>[[15%|Brothel][$brothelBoost.selected = 3]]<<else>>15%<</if>> | <<if $brothelBoost.selected != 4>>[[20%|Brothel][$brothelBoost.selected = 4]]<<else>>20%<</if>> | <<if $brothelBoost.selected != 5>>[[25%|Brothel][$brothelBoost.selected = 5]]<<else>>25%<</if>> | <<if $brothelBoost.selected != 6>>[[30%|Brothel][$brothelBoost.selected = 6]]<<else>>30%<</if>> | <<if $brothelBoost.selected != 7>>[[35%|Brothel][$brothelBoost.selected = 7]]<<else>>35%<</if>> | <<if $brothelBoost.selected != 8>>[[40%|Brothel][$brothelBoost.selected = 8]]<<else>>40%<</if>> | <<if $brothelBoost.selected != 9>>[[45%|Brothel][$brothelBoost.selected = 9]]<<else>>45%<</if>> | <<if $brothelBoost.selected != 10>>[[50%|Brothel][$brothelBoost.selected = 10]]<<else>>50%<</if>>
+	<br>Every 5% you attempt to boost income also increases the amount of customers by 2% and costs 50 reputation more. A minimum of 2500 reputation is required and every additional level increases this by another 500. You may choose whichever level you please, only the highest level you are eligable for will be used at any time.
 </p>
 
 <div>
diff --git a/src/uncategorized/slaveAssignmentsReport.tw b/src/uncategorized/slaveAssignmentsReport.tw
index 162e3e5550b..d6994eed910 100644
--- a/src/uncategorized/slaveAssignmentsReport.tw
+++ b/src/uncategorized/slaveAssignmentsReport.tw
@@ -28,6 +28,15 @@
 Depending on the conditions they may derive more or less 'utility' out of their credits spent
 i.e. a highly paternalist arcology with little choice for its lower class but Fuckdolls may still put money into them but not get the same satisfaction out of it*/
 /*Low rent increases demand/available money for sexual services, high rent decreases it*/
+<<if $rep < $brothelBoost.selected * 500 + 2000>>
+	<<set $brothelBoost.eligable = Math.trunc((rep - 2000) / 500)>>
+	<<if $brothelBoost.eligable < 0>>
+		<<set $brothelBoost.eligable = 0>>
+	<</if>>
+<<else>>
+	<<set $brothelBoost.eligable = $brothelBoost.selected>>
+<</if>>
+<<run repX(forceNeg(50 * $brothelBoost.eligable), "brothel")>>
 <<set _lowerClassSexDemand = Math.trunc($lowerClass * $whoreBudget.lowerClass) * 2,
 _lowerClassSexDemandRef = Math.max(_lowerClassSexDemand, 1),
 _visitorsSexDemand = Math.trunc($visitors) * 40,
@@ -39,11 +48,14 @@ _topClassSexDemand = Math.trunc($topClass * $whoreBudget.topClass) * 2,
 _topClassSexDemandRef = Math.max(_topClassSexDemand, 1),
 _arcadeSupply = {lowerClass: 0, middleClass: 0, upperClass: 0},
 _clubSupply = {lowerClass: 0, middleClass: 0},
+_brothelBoostDemand = {lowerClass: Math.trunc(_lowerClassSexDemandRef * $brothelBoost.eligable / 50), middleClass: Math.trunc(_middleClassSexDemandRef * $brothelBoost.eligable / 50), upperClass: Math.trunc(_upperClassSexDemandRef * $brothelBoost.eligable / 50), topClass: Math.trunc(_topClassSexDemandRef * $brothelBoost.eligable / 50)},
+_maxBrothelBoost = Math.trunc(100 * Math.pow(1.26, $brothelBoost.eligable - 1)) * 50 * $brothelBoost.eligable,
 $whorePriceAdjustment = {lowerClass: 0, middleClass: 0, upperClass: 0, topClass: 0},
 $NPCMarketShare = {lowerClass: 0, middleClass: 0, upperClass: 0, topClass: 0},
 $sexDemandResult = {lowerClass: 0, middleClass: 0, upperClass: 0, topClass: 0},
-$slaveJobValues = slaveJobValues(_lowerClassSexDemandRef, _middleClassSexDemandRef, _upperClassSexDemandRef, _topClassSexDemandRef)>>
+$slaveJobValues = slaveJobValues(_lowerClassSexDemandRef + _brothelBoostDemand.lowerClass, _middleClassSexDemandRef + _brothelBoostDemand.middleClass, _upperClassSexDemandRef + _brothelBoostDemand.upperClass, _topClassSexDemandRef + _brothelBoostDemand.topClass)>>
 
+<<print _brothelBoostDemand.lowerClass>>
 /*Arcade Specific Demand for Degradationists to give it higher priority*/
 <<if $arcologies[0].FSDegradationist != "unset">>
 	<<set _lowerClassArcadeSexDemand = Math.trunc(_lowerClassSexDemand * $arcologies[0].FSDegradationist * 0.0015),
@@ -105,33 +117,40 @@ _middleClassClubRatio = _middleClassSexDemand / _clubDemand>>
 <<set _clubSupply.lowerClass = Math.trunc($slaveJobValues.club * $slaveJobValues.clubSP * _lowerClassClubRatio),
 _clubSupply.middleClass = Math.trunc($slaveJobValues.club * $slaveJobValues.clubSP * _middleClassClubRatio)>>
 
+values: <<print $slaveJobValues.brothel.lowerClass>> | <<print $slaveJobValues.brothel.middleClass>> | <<print $slaveJobValues.brothel.boost>> | <<print $slaveJobValues.club>> 
 /*Brothel or street whore sex supply*/
+<<if $slaveJobValues.brothel.boost > _maxBrothelBoost>>
+	<<set _boostPriceAdjustment = _maxBrothelBoost / $slaveJobValues.brothel.boost>>
+<<else>>
+	<<set _boostPriceAdjustment = 1>>
+<</if>>
 <<if _lowerClassSexDemand < $slaveJobValues.brothel.lowerClass>>
-	<<set $whorePriceAdjustment.lowerClass = Math.max(Math.pow(_lowerClassSexDemand / ($slaveJobValues.brothel.lowerClass + $NPCSexSupply.lowerClass), 1.513), 0.3),
+	/*_brothelBoostDemand gets included in the price calculation to counteract the additional use of whores lowering the price unintentionally. The boost is supposed to improve profits, suppressing them again here would not be great. The boost is not included in the demand calculations, those remain as is. The boost demand isn't 'real' demand for sex, it is demand for favours from the PC bought through the brothel*/
+	<<set $whorePriceAdjustment.lowerClass = Math.max(Math.pow(_lowerClassSexDemand + _brothelBoostDemand.lowerClass / ($slaveJobValues.brothel.lowerClass + $NPCSexSupply.lowerClass), 1.513) * _boostPriceAdjustment, 0.3),
 	_lowerClassSexDemand = 0>> /*This accounts for people having too much choice and getting more picky how they spend their money*/
 <<else>>
-	<<set $whorePriceAdjustment.lowerClass = Math.pow(_lowerClassSexDemand / ($slaveJobValues.brothel.lowerClass + $NPCSexSupply.lowerClass), 0.5),
+	<<set $whorePriceAdjustment.lowerClass = Math.pow(_lowerClassSexDemand + _brothelBoostDemand.lowerClass / ($slaveJobValues.brothel.lowerClass + $NPCSexSupply.lowerClass), 0.5) * _boostPriceAdjustment,
 	_lowerClassSexDemand -= $slaveJobValues.brothel.lowerClass>> /* People are willing to pay more for a scarce good, but within reason */
 <</if>>
 <<if _middleClassSexDemand < $slaveJobValues.brothel.middleClass>>
-	<<set $whorePriceAdjustment.middleClass = Math.max(Math.pow((_middleClassSexDemand * 1.1) / ($slaveJobValues.brothel.middleClass + $NPCSexSupply.middleClass), 1.513), 0.33),
+	<<set $whorePriceAdjustment.middleClass = Math.max(Math.pow(((_middleClassSexDemand + _brothelBoostDemand.middleClass) * 1.1) / ($slaveJobValues.brothel.middleClass + $NPCSexSupply.middleClass), 1.513) * _boostPriceAdjustment, 0.33),
 	_middleClassSexDemand = 0>>
 <<else>>
-	<<set $whorePriceAdjustment.middleClass = Math.pow((_middleClassSexDemand * 1.1) / ($slaveJobValues.brothel.middleClass + $NPCSexSupply.middleClass), 0.5),
+	<<set $whorePriceAdjustment.middleClass = Math.pow(((_middleClassSexDemand + _brothelBoostDemand.middleClass) * 1.1) / ($slaveJobValues.brothel.middleClass + $NPCSexSupply.middleClass), 0.5) * _boostPriceAdjustment,
 	_middleClassSexDemand -= $slaveJobValues.brothel.middleClass>>
 <</if>>
 <<if _upperClassSexDemand < $slaveJobValues.brothel.upperClass>>
-	<<set $whorePriceAdjustment.upperClass = Math.max(Math.pow((_upperClassSexDemand * 1.21) / ($slaveJobValues.brothel.upperClass + $NPCSexSupply.upperClass), 1.513), 0.363),
+	<<set $whorePriceAdjustment.upperClass = Math.max(Math.pow(((_upperClassSexDemand + _brothelBoostDemand.upperClass) * 1.21) / ($slaveJobValues.brothel.upperClass + $NPCSexSupply.upperClass), 1.513) * _boostPriceAdjustment, 0.363),
 	_upperClassSexDemand = 0>>
 <<else>>
-	<<set $whorePriceAdjustment.upperClass = Math.pow((_upperClassSexDemand * 1.21) / ($slaveJobValues.brothel.upperClass + $NPCSexSupply.upperClass), 0.5),
+	<<set $whorePriceAdjustment.upperClass = Math.pow(((_upperClassSexDemand + _brothelBoostDemand.upperClass) * 1.21) / ($slaveJobValues.brothel.upperClass + $NPCSexSupply.upperClass), 0.5) * _boostPriceAdjustment,
 	_upperClassSexDemand -= $slaveJobValues.brothel.upperClass>>
 <</if>>
 <<if _topClassSexDemand < $slaveJobValues.brothel.topClass>>
-	<<set $whorePriceAdjustment.topClass = Math.max(Math.pow((_topClassSexDemand * 1.331) / ($slaveJobValues.brothel.topClass + $NPCSexSupply.topClass), 1.513), 0.3993),
+	<<set $whorePriceAdjustment.topClass = Math.max(Math.pow(((_topClassSexDemand + _brothelBoostDemand.topClass) * 1.331) / ($slaveJobValues.brothel.topClass + $NPCSexSupply.topClass), 1.513) * _boostPriceAdjustment, 0.3993),
 	_topClassSexDemand = 0>>
 <<else>>
-	<<set $whorePriceAdjustment.topClass = Math.pow((_topClassSexDemand * 1.331) / ($slaveJobValues.brothel.topClass + $NPCSexSupply.topClass), 0.5),
+	<<set $whorePriceAdjustment.topClass = Math.pow(((_topClassSexDemand + _brothelBoostDemand.topClass) * 1.331) / ($slaveJobValues.brothel.topClass + $NPCSexSupply.topClass), 0.5) * _boostPriceAdjustment,
 	_topClassSexDemand -= $slaveJobValues.brothel.topClass>>
 <</if>>
 
-- 
GitLab