diff --git a/src/init/storyInit.tw b/src/init/storyInit.tw index e3277b1ec7cd8547d838f19a3a907b10cecc6605..d99d83e008df786a43e7d4c44c6a59eb78293d12 100644 --- a/src/init/storyInit.tw +++ b/src/init/storyInit.tw @@ -1066,7 +1066,9 @@ You should have received a copy of the GNU General Public License along with thi <<set $elapsedSupplyTimer = 0>> <<set $slaveCostRandom = 0>> <<set $deltaDemand = 0>> +<<set $deltaDemandOld = 0>> <<set $deltaSupply = 0>> +<<set $deltaSupplyOld = 0>> <<set $NPCSexSupply = {lowerClass: 3000, middleClass: 3000, upperClass: 3000, topClass: 3000}>> <<set $NPCMarketShare = {lowerClass: 1000, middleClass: 1000, upperClass: 1000, topClass: 1000}>> <<set $sexSubsidies = {lowerClass: 0, middleClass: 0, upperClass: 0, topClass: 0}>> diff --git a/src/js/datatypeCleanupJS.js b/src/js/datatypeCleanupJS.js index 859baf790e0554996c062e1c845f7ac1445175da..6660be9704146b0f034fc9e413b34e360ba92a90 100644 --- a/src/js/datatypeCleanupJS.js +++ b/src/js/datatypeCleanupJS.js @@ -1766,8 +1766,10 @@ window.EconomyDatatypeCleanup = function EconomyDatatypeCleanup() { V.elapsedDemandTimer = Math.max(+V.elapsedDemandTimer, 0) || 0; V.supplyTimer = Math.max(+V.supplyTimer, 0) || 0; V.elapsedSupplyTimer = Math.max(+V.elapsedSupplyTimer, 0) || 0; - V.deltaSupply = Math.clamp(+V.deltaSupply, -3000, 3000) || 0; - V.deltaDemand = Math.clamp(+V.deltaDemand, -3000, 3000) || 0; + V.deltaSupply = Math.clamp(+V.deltaSupply, -6500, 6500) || 0; + V.deltaDemand = Math.clamp(+V.deltaDemand, -6500, 6500) || 0; + V.deltaSupplyOld = Math.clamp(+V.deltaSupply, -6500, 6500) || 0; + V.deltaDemandOld = Math.clamp(+V.deltaDemand, -6500, 6500) || 0; V.sexSubsidies.lowerClass = Math.clamp(+V.sexSubsidies.lowerClass, 0, 4) || 0; V.sexSubsidies.middleClass = Math.clamp(+V.sexSubsidies.middleClass, 0, 4) || 0; V.sexSubsidies.upperClass = Math.clamp(+V.sexSubsidies.upperClass, 0, 4) || 0; diff --git a/src/js/economyJS.js b/src/js/economyJS.js index 79fab073eb7e96ee09516ef27e1d0da041abe74e..136e4193bacfd9beb893d0216a9f3e71850f5957 100644 --- a/src/js/economyJS.js +++ b/src/js/economyJS.js @@ -1005,9 +1005,12 @@ window.getSlaveCost = function(s) { return getSlaveCostArray(s).reduce((result, {value})=>result + value, 0); }; -// Supply and Demand for slaves (linear, simple) -// PC buying slaves reduces supply, selling slaves reduces demand. - +/** + * Supply and Demand for slaves (linear, simple) + * PC buying slaves reduces supply, selling slaves reduces demand. + * @param {Number} q + * @returns {Number} + */ window.menialSlaveCost = function(q = 0) { const demand = State.variables.menialDemandFactor; const supply = State.variables.menialSupplyFactor; @@ -1747,6 +1750,140 @@ window.effectiveWhoreClass = function(s) { return result; }; +/** + * End week function to handle the (menial) slave market prices through supply and demand + * @returns {void} + */ +window.endWeekSlaveMarket = function() { + const demandVariance = jsRandom(-10, 10) * 20; + const supplyVariance = jsRandom(-10, 10) * 20; + const demand = V.menialDemandFactor; + const supply = V.menialSupplyFactor; + const relativeDemand = Math.trunc(Math.pow(Math.abs(demand) / 10000, 2)); // A variable that gets much greater the further demand is from 0 + const relativeSupply = Math.trunc(Math.pow(Math.abs(supply) / 10000, 2)); + let randomDemand; + let randomSupply; + V.slaveCostRandom = jsRandom(-3, 3); + + if (V.demandTimer === 0) { // First week setup + let random = jsRandom(1, 100); + if (random > 55) { + V.deltaDemand = normalRandInt(350, 60) * 10; + } else if (random <= 45) { + V.deltaDemand = normalRandInt(-350, 60) * 10; + } else { + V.deltaDemand = 0; + } + newTimer(); + random = jsRandom(1, 100); + if (random > 55) { + V.deltaDemand = normalRandInt(350, 60) * 10; + } else if (random <= 45) { + V.deltaDemand = normalRandInt(-350, 60) * 10; + } else { + V.deltaDemand = 0; + } + } + + if (demand >= 50000 && V.deltaDemand >= 0) { // Turning the market around if demand hits the upper bound + newTimer(); + V.deltaDemand = normalRandInt(-500, 40) * 10; // Force with which the market moves + } else if (demand <= -50000 && V.deltaDemand <= 0) { // Turning the market around if demand hits the lower bound + newTimer(); + V.deltaDemand = normalRandInt(500, 40) * 10; + } + + if (V.elapsedDemandTimer >= V.demandTimer) { // Changing the delta once the timer runs out + newTimer(); + randomDemand = jsRandom(1, 100) - relativeDemand * 2; // A variable used to determine if demand will go up, down or remain stable while taking into account relativeDemand, thus making movement towards the extreme less likely + if (demand >= 0) { // If demand is currently positive (or 0) the chances for even greater demand are reduced by randomDemand + if (randomDemand > 55) { + V.deltaDemand = normalRandInt(350, 60) * 10; + } else if (randomDemand <= 45) { + V.deltaDemand = normalRandInt(-350, 60) * 10; + } else { + V.deltaDemand = 0; + } + } else { // If demand is currently negative the chances for even lower demand are reduced by randomDemand + if (randomDemand > 55) { + V.deltaDemand = normalRandInt(-350, 60) * 10; + } else if (randomDemand <= 45) { + V.deltaDemand = normalRandInt(350, 60) * 10; + } else { + V.deltaDemand = 0; + } + } + } + V.elapsedDemandTimer += 1; + const relativeTimeDemand = V.elapsedDemandTimer / V.demandTimer; + V.menialDemandFactor += demandVariance + Math.trunc(relativeTimeDemand * V.deltaDemand + (1 - relativeTimeDemand) * V.deltaDemandOld); // Actual movement of demand gradually shifts from old to 'new' deltaDemand + + if (V.supplyTimer === 0) { // First week setup + let random = jsRandom(1, 100); + if (random > 55) { + V.deltaSupply = normalRandInt(350, 60) * 10; + } else if (random <= 45) { + V.deltaSupply = normalRandInt(-350, 60) * 10; + } else { + V.deltaSupply = 0; + } + newTimer("supply"); + random = jsRandom(1, 100); + if (random > 55) { + V.deltaSupply = normalRandInt(350, 60) * 10; + } else if (random <= 45) { + V.deltaSupply = normalRandInt(-350, 60) * 10; + } else { + V.deltaSupply = 0; + } + } + + if (supply >= 50000 && V.deltaSupply >= 0) { // Turning the market around if supply hits the upper bound + newTimer("supply"); + V.deltaSupply = normalRandInt(-500, 40) * 10; // Force with which the market moves + } else if (supply <= -50000 && V.deltaSupply <= 0) { // Turning the market around if supply hits the lower bound + newTimer("supply"); + V.deltaSupply = normalRandInt(500, 40) * 10; + } + + if (V.elapsedSupplyTimer >= V.supplyTimer) { // Changing the delta once the timer runs out + newTimer("supply"); + randomSupply = jsRandom(1, 100) - relativeSupply * 2; + if (supply >= 0) { // If supply is currently positive (or 0) the chances for even greater supply are reduced by randomSupply + if (randomSupply > 55) { + V.deltaSupply = normalRandInt(350, 60) * 10; + } else if (randomSupply <= 45) { + V.deltaSupply = normalRandInt(-350, 60) * 10; + } else { + V.deltaSupply = 0; + } + } else { // If supply is currently negative the chances for even lower supply are reduced by randomSupply + if (randomSupply > 55) { + V.deltaSupply = normalRandInt(-350, 60) * 10; + } else if (randomSupply <= 45) { + V.deltaSupply = normalRandInt(350, 60) * 10; + } else { + V.deltaSupply = 0; + } + } + } + V.elapsedSupplyTimer += 1; + const relativeTimeSupply = V.elapsedSupplyTimer / V.supplyTimer; + V.menialSupplyFactor += supplyVariance + Math.trunc(relativeTimeSupply * V.deltaSupply + (1 - relativeTimeSupply) * V.deltaSupplyOld); // Actual movement of supply gradually shifts from old to 'new' deltaSupply + + function newTimer(side="demand") { + if (side === "demand") { + V.demandTimer = jsRandom(6, 10); + V.elapsedDemandTimer = 0; + V.deltaDemandOld = V.deltaDemand; + } else if (side === "supply") { + V.supplyTimer = jsRandom(6, 10); + V.elapsedSupplyTimer = 0; + V.deltaSupplyOld = V.deltaSupply; + } + } +}; + /** * @param {App.Entity.SlaveState} s * @param {Object|undefined} facility diff --git a/src/uncategorized/persBusiness.tw b/src/uncategorized/persBusiness.tw index fe6e161bf3c2c6ca6404927c564c629850803903..79c02e466f03dfeb59bdb7e7b6daeb952bcaf1ef 100644 --- a/src/uncategorized/persBusiness.tw +++ b/src/uncategorized/persBusiness.tw @@ -883,154 +883,98 @@ Routine upkeep of your demesne costs @@.yellow;<<print cashFormat($costs)>>.@@ <</if>> /*Adding random changes to slave demand and supply*/ -/*Without events triggering and a relatively average supply/demand situation, the best case scenario is an increase/decrease in the price of slaves of 10 in one week. Chance of these conditions happening are 1/25. For demand or supply to go from average to their maximum will take 25 weeks if rolling highest growth each time a roll is made and all other luck is average. Because of the properties of the market and how it develops the likely prices one will encounter are distributed in a bell-shaped fashion, centered around 1000. Minimum possible price is 750, maximum 1250. At +/- 35000 chances of supply or demand getting even more extreme are reduced.*/ -<<set _demandSlaveVar = random(-10,10)*10>> -<<set _supplySlaveVar = random(-10,10)*10>> -<<set $slaveCostRandom = random(-3,3)>> -<<if $menialDemandFactor <= -50000>> - <<set $deltaDemand = random(1,3) * 1000>> - <<set $demandTimer = random(7,12)>> - <<set $elapsedDemandTimer = 1>> - <<set $menialDemandFactor += $deltaDemand + _demandSlaveVar>> -<<elseif $menialDemandFactor >= 50000>> - <<set $deltaDemand = random(-3,-1) * 1000>> - <<set $demandTimer = random(7,12)>> - <<set $elapsedDemandTimer = 1>> - <<set $menialDemandFactor += $deltaDemand + _demandSlaveVar>> -<<elseif $demandTimer - $elapsedDemandTimer <= 0>> - <<set $demandTimer = random(7,12)>> - <<set $elapsedDemandTimer = 1>> - <<if $menialDemandFactor > 35000>> - <<set $deltaDemand = random(-3,1) * 1000>> - <<elseif $menialDemandFactor < -35000>> - <<set $deltaDemand = random(-1,3) * 1000>> +<<run endWeekSlaveMarket()>> +<<if $menialDemandFactor <= -35000>> + <br>Demand for slaves is approaching a @@.red;''historic low'',@@ forecasts predict + <<if $deltaDemand > 0>> + the market will turn soon and @@.green;''demand will rise''.@@ + <<elseif $deltaDemand < 0>> + @@.red;''demand will continue to weaken'',@@ but warn the bottom is in sight. <<else>> - <<set $deltaDemand = random(-2,2) * 1000>> + the current demand will @@.yellow;''stabilize''.@@ <</if>> - <<set $menialDemandFactor += $deltaDemand + _demandSlaveVar>> - <<if $menialDemandFactor <= -35000>> - <br>Demand for slaves is approaching a @@.red;''historic low'',@@ forecasts predict - <<if $deltaDemand > 0>> - the market will turn and @@.green;''demand will rise''.@@ - <<elseif $deltaDemand < 0>> - @@.red;''demand will continue to weaken'',@@ but warn the bottom is in sight. - <<else>> - the current demand will @@.yellow;''remain stable''@@ for the coming months. - <</if>> - <<elseif $menialDemandFactor <= 20000>> - <br>Demand for slaves is @@.red;''very low'',@@ forecasts predict - <<if $deltaDemand > 0>> - the market will turn and @@.green;''demand will rise''.@@ - <<elseif $deltaDemand < 0>> - @@.red;''demand will continue to weaken''.@@ - <<else>> - the current demand will @@.yellow;''remain stable''@@ for the coming months. - <</if>> - <<elseif $menialDemandFactor >= 35000>> - <br>Demand for slaves is approaching a @@.green;''historic high'',@@ forecasts predict - <<if $deltaDemand > 0>> - @@.green;''demand will continue to rise'',@@ but warn the peak is in sight. - <<elseif $deltaDemand < 0>> - the market will turn and @@.red;''demand will weaken''.@@ - <<else>> - the current demand will @@.yellow;''remain stable''@@ for the coming months. - <</if>> - <<elseif $menialDemandFactor >= 20000>> - <br>Demand for slaves is @@.green;''very high'',@@ forecasts predict - <<if $deltaDemand > 0>> - @@.green;''demand will continue to rise''.@@ - <<elseif $deltaDemand < 0>> - the market will turn and @@.red;''demand will weaken''.@@ - <<else>> - the current demand will @@.yellow;''remain stable''@@ for the coming months. - <</if>> +<<elseif $menialDemandFactor <= -20000>> + <br>Demand for slaves is @@.red;''very low'',@@ forecasts predict + <<if $deltaDemand > 0>> + the market will turn soon and @@.green;''demand will rise''.@@ + <<elseif $deltaDemand < 0>> + @@.red;''demand will continue to weaken''.@@ <<else>> - <br>Demand for slaves is @@.yellow;''average'',@@ forecasts predict - <<if $deltaDemand > 0>> - the market will see @@.green;''rising demand''.@@ - <<elseif $deltaDemand < 0>> - the market will see @@.red;''weakening demand''.@@ - <<else>> - @@.yellow;''no change''@@ for the coming months. - <</if>> + the current demand will @@.yellow;''stabilize''.@@ + <</if>> +<<elseif $menialDemandFactor >= 35000>> + <br>Demand for slaves is approaching a @@.green;''historic high'',@@ forecasts predict + <<if $deltaDemand > 0>> + @@.green;''demand will continue to rise'',@@ but warn the peak is in sight. + <<elseif $deltaDemand < 0>> + the market will turn soon and @@.red;''demand will weaken''.@@ + <<else>> + the current demand will @@.yellow;''stabilize''.@@ + <</if>> +<<elseif $menialDemandFactor >= 20000>> + <br>Demand for slaves is @@.green;''very high'',@@ forecasts predict + <<if $deltaDemand > 0>> + @@.green;''demand will continue to rise''.@@ + <<elseif $deltaDemand < 0>> + the market will turn soon and @@.red;''demand will weaken''.@@ + <<else>> + the current demand will @@.yellow;''stabilize''.@@ <</if>> <<else>> - <<set $elapsedDemandTimer += 1>> - <<set $menialDemandFactor += $deltaDemand + _demandSlaveVar>> - <<set $menialDemandFactor = Math.clamp($menialDemandFactor,-50000,50000)>> + <br>Demand for slaves is @@.yellow;''average'',@@ forecasts predict + <<if $deltaDemand > 0>> + the market will see @@.green;''rising demand''.@@ + <<elseif $deltaDemand < 0>> + the market will see @@.red;''weakening demand''.@@ + <<else>> + it will @@.yellow;''remain stable''@@ for the coming months. + <</if>> <</if>> - -<<if $menialSupplyFactor <= -50000>> - <<set $deltaSupply = random(1,3) * 1000>> - <<set $supplyTimer = random(7,12)>> - <<set $elapsedSupplyTimer = 1>> - <<set $menialSupplyFactor += $deltaSupply + _demandSlaveVar>> -<<elseif $menialSupplyFactor >= 50000>> - <<set $deltaSupply = random(-3,-1) * 1000>> - <<set $supplyTimer = random(7,12)>> - <<set $elapsedSupplyTimer = 1>> - <<set $menialSupplyFactor += $deltaSupply + _demandSlaveVar>> -<<elseif $supplyTimer - $elapsedSupplyTimer <= 0>> - <<set $supplyTimer = random(7,12)>> - <<set $elapsedSupplyTimer = 1>> - <<if $menialSupplyFactor > 35000>> - <<set $deltaSupply = random(-3,1) * 1000>> - <<elseif $menialSupplyFactor < -35000>> - <<set $deltaSupply = random(-1,3) * 1000>> +<<if $menialSupplyFactor <= -35000>> + <br>Supply of slaves is approaching a @@.green;''historic low'',@@ forecasts predict + <<if $deltaSupply > 0>> + the market will turn soon and @@.red;''supply will rise''.@@ + <<elseif $deltaSupply < 0>> + @@.green;''supply will continue to weaken'',@@ but warn the bottom is in sight. <<else>> - <<set $deltaSupply = random(-2,2) * 1000>> + the current supply will @@.yellow;''stabilize''.@@ <</if>> - <<set $menialSupplyFactor += $deltaSupply + _supplySlaveVar>> - <<if $menialSupplyFactor <= -35000>> - <br>Supply of slaves is approaching a @@.green;''historic low'',@@ forecasts predict - <<if $deltaSupply > 0>> - the market will turn and @@.red;''supply will rise''.@@ - <<elseif $deltaSupply < 0>> - @@.green;''supply will continue to weaken'',@@ but warn the bottom is in sight. - <<else>> - the current supply will @@.yellow;''remain stable''@@ for the coming months. - <</if>> - <<elseif $menialSupplyFactor <= 20000>> - <br>Supply for slaves is @@.green;''very low'',@@ forecasts predict - <<if $deltaSupply > 0>> - the market will turn and @@.red;''supply will rise''.@@ - <<elseif $deltaSupply < 0>> - @@.green;''supply will continue to weaken''.@@ - <<else>> - the current supply will @@.yellow;''remain stable''@@ for the coming months. - <</if>> - <<elseif $menialSupplyFactor >= 35000>> - <br>Supply for slaves is approaching a @@.red;''historic high'',@@ forecasts predict - <<if $deltaSupply > 0>> - @@.red;''supply will continue to rise'',@@ but warn the peak is in sight. - <<elseif $deltaSupply < 0>> - the market will turn and @@.green;''supply will weaken''.@@ - <<else>> - the current supply will @@.yellow;''remain stable''@@ for the coming months. - <</if>> - <<elseif $menialSupplyFactor >= 20000>> - <br>Supply for slaves is @@.red;''very high'',@@ forecasts predict - <<if $deltaSupply > 0>> - @@.red;''supply will continue to rise''.@@ - <<elseif $deltaSupply < 0>> - the market will turn and @@.green;''supply will weaken''.@@ - <<else>> - the current supply will @@.yellow;''remain stable''@@ for the coming months. - <</if>> +<<elseif $menialSupplyFactor <= -20000>> + <br>Supply for slaves is @@.green;''very low'',@@ forecasts predict + <<if $deltaSupply > 0>> + the market will turn soon and @@.red;''supply will rise''.@@ + <<elseif $deltaSupply < 0>> + @@.green;''supply will continue to weaken''.@@ <<else>> - <br>Supply for slaves is @@.yellow;''average'',@@ forecasts predict - <<if $deltaSupply > 0>> - the market will see @@.red;''rising supply''.@@ - <<elseif $deltaSupply < 0>> - the market will see @@.green;''weakening supply''.@@ - <<else>> - @@.yellow;''no change''@@ for the coming months. - <</if>> + the current supply will @@.yellow;''stabilize''.@@ + <</if>> +<<elseif $menialSupplyFactor >= 35000>> + <br>Supply for slaves is approaching a @@.red;''historic high'',@@ forecasts predict + <<if $deltaSupply > 0>> + @@.red;''supply will continue to rise'',@@ but warn the peak is in sight. + <<elseif $deltaSupply < 0>> + the market will turn soon and @@.green;''supply will weaken''.@@ + <<else>> + the current supply will @@.yellow;''stabilize''.@@ + <</if>> +<<elseif $menialSupplyFactor >= 20000>> + <br>Supply for slaves is @@.red;''very high'',@@ forecasts predict + <<if $deltaSupply > 0>> + @@.red;''supply will continue to rise''.@@ + <<elseif $deltaSupply < 0>> + the market will turn soon and @@.green;''supply will weaken''.@@ + <<else>> + the current supply will @@.yellow;''stabilize''.@@ <</if>> <<else>> - <<set $elapsedSupplyTimer += 1>> - <<set $menialSupplyFactor += $deltaSupply + _supplySlaveVar>> - <<set $menialSupplyFactor = Math.clamp($menialSupplyFactor,-50000,50000)>> + <br>Supply for slaves is @@.yellow;''average'',@@ forecasts predict + <<if $deltaSupply > 0>> + the market will see @@.red;''rising supply''.@@ + <<elseif $deltaSupply < 0>> + the market will see @@.green;''weakening supply''.@@ + <<else>> + it will @@.yellow;''remain stable''@@ for the coming months. + <</if>> <</if>> /* Menial and regular slave markets are part of the same market, e.a. if (menial)slave supply goes up, all slave prices fall.