Skip to content

Commit

Permalink
CORPORATION: Fix wrong warning of sellAmt being negative
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg committed Dec 1, 2024
1 parent 67704f2 commit 131844c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Corporation/Division.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 131844c

Please sign in to comment.