From 131844c17c00436415d0026d962be20bda27e64e Mon Sep 17 00:00:00 2001 From: CatLover <152669316+catloversg@users.noreply.github.com> Date: Sun, 1 Dec 2024 11:01:52 +0700 Subject: [PATCH] CORPORATION: Fix wrong warning of sellAmt being negative --- src/Corporation/Division.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Corporation/Division.ts b/src/Corporation/Division.ts index 12c958a41e..529893d5c6 100644 --- a/src/Corporation/Division.ts +++ b/src/Corporation/Division.ts @@ -559,6 +559,10 @@ export class Division { ); continue; } + // sellAmt must be a non-negative number. + if (sellAmt < 0) { + sellAmt = 0; + } // Determine the cost that the material will be sold at const markupLimit = mat.getMarkupLimit(); @@ -638,7 +642,7 @@ export class Division { sellAmt = sellAmt * corpConstants.secondsPerMarketCycle * marketCycles; sellAmt = Math.min(mat.stored, sellAmt); if (sellAmt < 0) { - console.warn(`sellAmt calculated to be negative for ${matName} in ${city}`); + console.error(`sellAmt calculated to be negative for ${matName} in ${city}`); mat.actualSellAmount = 0; continue; } @@ -916,10 +920,11 @@ export class Division { // break the case "SALE" break; } - + // sellAmt must be a non-negative number. if (sellAmt < 0) { sellAmt = 0; } + if (product.markup === 0) { exceptionAlert(new Error("product.markup is 0")); product.markup = 1; @@ -997,9 +1002,16 @@ export class Division { businessFactor * advertisingFactor * this.getSalesMultiplier(); + sellAmt = Math.min(product.maxSellAmount, sellAmt); sellAmt = sellAmt * corpConstants.secondsPerMarketCycle * marketCycles; sellAmt = Math.min(product.cityData[city].stored, sellAmt); //data[0] is qty + if (sellAmt < 0) { + console.error(`sellAmt calculated to be negative for ${product.name} in ${city}`); + product.cityData[city].actualSellAmount = 0; + // break the case "SALE" + break; + } if (sellAmt && sCost >= 0) { product.cityData[city].stored -= sellAmt; //data[0] is qty totalProfit += sellAmt * sCost;