Fixed corporation bug

This commit is contained in:
danielyxie 2019-05-11 20:03:36 -07:00
parent b0918d7bd3
commit 1775ea86ff
2 changed files with 15 additions and 9 deletions

@ -252,5 +252,6 @@ export let CONSTANTS: IMap<any> = {
* Bug Fix: Netscript1.0 now works properly for multiple 'namespace' imports (import * as namespace from "script") * Bug Fix: Netscript1.0 now works properly for multiple 'namespace' imports (import * as namespace from "script")
* Bug Fix: Terminal 'wget' command now correctly evaluates directory paths * Bug Fix: Terminal 'wget' command now correctly evaluates directory paths
* Bug Fix: wget(), write(), and scp() Netscript functions now fail if an invalid filepath is passed in * Bug Fix: wget(), write(), and scp() Netscript functions now fail if an invalid filepath is passed in
* Bug Fix: Having Corporation warehouses at full capacity should no longer freeze game in certain conditions
` `
} }

@ -521,15 +521,18 @@ Industry.prototype.process = function(marketCycles=1, state, company) {
} }
// Process production, purchase, and import/export of materials // Process production, purchase, and import/export of materials
var res = this.processMaterials(marketCycles, company); let res = this.processMaterials(marketCycles, company);
if (Array.isArray(res)) {
this.thisCycleRevenue = this.thisCycleRevenue.plus(res[0]); this.thisCycleRevenue = this.thisCycleRevenue.plus(res[0]);
this.thisCycleExpenses = this.thisCycleExpenses.plus(res[1]); this.thisCycleExpenses = this.thisCycleExpenses.plus(res[1]);
}
// Process creation, production & sale of products // Process creation, production & sale of products
res = this.processProducts(marketCycles, company); res = this.processProducts(marketCycles, company);
if (Array.isArray(res)) {
this.thisCycleRevenue = this.thisCycleRevenue.plus(res[0]); this.thisCycleRevenue = this.thisCycleRevenue.plus(res[0]);
this.thisCycleExpenses = this.thisCycleExpenses.plus(res[1]); this.thisCycleExpenses = this.thisCycleExpenses.plus(res[1]);
}
} }
// Process change in demand and competition for this industry's materials // Process change in demand and competition for this industry's materials
@ -846,7 +849,7 @@ Industry.prototype.processMaterials = function(marketCycles=1, company) {
sellAmt = (sellAmt * SecsPerMarketCycle * marketCycles); sellAmt = (sellAmt * SecsPerMarketCycle * marketCycles);
sellAmt = Math.min(mat.qty, sellAmt); sellAmt = Math.min(mat.qty, sellAmt);
if (sellAmt < 0) { if (sellAmt < 0) {
console.log("sellAmt calculated to be negative"); console.warn(`sellAmt calculated to be negative for ${matName} in ${city}`);
mat.sll = 0; mat.sll = 0;
continue; continue;
} }
@ -901,7 +904,9 @@ Industry.prototype.processMaterials = function(marketCycles=1, company) {
// Make sure theres enough space in warehouse // Make sure theres enough space in warehouse
if (expWarehouse.sizeUsed >= expWarehouse.size) { if (expWarehouse.sizeUsed >= expWarehouse.size) {
return; //Warehouse at capacity // Warehouse at capacity. Exporting doesnt
// affect revenue so just return 0's
return [0, 0];
} else { } else {
var maxAmt = Math.floor((expWarehouse.size - expWarehouse.sizeUsed) / MaterialSizes[matName]); var maxAmt = Math.floor((expWarehouse.size - expWarehouse.sizeUsed) / MaterialSizes[matName]);
amt = Math.min(maxAmt, amt); amt = Math.min(maxAmt, amt);