CORPORATION: remove unneeded "state" property from Divisions (#857)

This commit is contained in:
Caldwell 2023-10-08 05:25:46 +02:00 committed by GitHub
parent 2f40b66789
commit 6fa149ff08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

@ -115,7 +115,7 @@ export class Corporation {
ind.resetImports(state); ind.resetImports(state);
} }
for (const ind of this.divisions.values()) { for (const ind of this.divisions.values()) {
ind.process(marketCycles, state, this); ind.process(marketCycles, this);
} }
// Process cooldowns // Process cooldowns

@ -73,7 +73,6 @@ export class Division {
thisCycleRevenue = 0; thisCycleRevenue = 0;
thisCycleExpenses = 0; thisCycleExpenses = 0;
state: CorpStateName = "START";
newInd = true; newInd = true;
// Sector 12 office and warehouse are added by default, these entries are added in the constructor. // Sector 12 office and warehouse are added by default, these entries are added in the constructor.
@ -142,9 +141,8 @@ export class Division {
} }
} }
process(marketCycles = 1, state: CorpStateName, corporation: Corporation): void { process(marketCycles = 1, corporation: Corporation): void {
this.state = state; const state = corporation.state.getState();
//At the start of a cycle, store and reset revenue/expenses //At the start of a cycle, store and reset revenue/expenses
//Then calculate salaries and process the markets //Then calculate salaries and process the markets
if (state === "START") { if (state === "START") {
@ -266,6 +264,7 @@ export class Division {
//Process production, purchase, and import/export of materials //Process production, purchase, and import/export of materials
processMaterials(marketCycles = 1, corporation: Corporation): [number, number] { processMaterials(marketCycles = 1, corporation: Corporation): [number, number] {
const state = corporation.state.getState();
let revenue = 0; let revenue = 0;
let expenses = 0; let expenses = 0;
this.calculateProductionFactors(); this.calculateProductionFactors();
@ -285,7 +284,7 @@ export class Division {
const warehouse = this.warehouses[city]; const warehouse = this.warehouses[city];
if (!warehouse) continue; if (!warehouse) continue;
switch (this.state) { switch (state) {
case "PURCHASE": { case "PURCHASE": {
const smartBuy: PartialRecord<CorpMaterialName, [buyAmt: number, reqMat: number]> = {}; const smartBuy: PartialRecord<CorpMaterialName, [buyAmt: number, reqMat: number]> = {};
@ -708,7 +707,7 @@ export class Division {
case "START": case "START":
break; break;
default: default:
console.error(`Invalid state: ${this.state}`); console.error(`Invalid state: ${state}`);
break; break;
} //End switch(this.state) } //End switch(this.state)
this.updateWarehouseSizeUsed(warehouse); this.updateWarehouseSizeUsed(warehouse);
@ -718,6 +717,7 @@ export class Division {
/** Process product development and production/sale */ /** Process product development and production/sale */
processProducts(marketCycles = 1, corporation: Corporation): [number, number] { processProducts(marketCycles = 1, corporation: Corporation): [number, number] {
const state = corporation.state.getState();
let revenue = 0; let revenue = 0;
const expenses = 0; const expenses = 0;
@ -725,7 +725,7 @@ export class Division {
for (const [name, product] of this.products) { for (const [name, product] of this.products) {
if (!product.finished) { if (!product.finished) {
// Product still under development // Product still under development
if (this.state !== "PRODUCTION") continue; if (state !== "PRODUCTION") continue;
const city = product.creationCity; const city = product.creationCity;
const office = this.offices[city]; const office = this.offices[city];
if (!office) { if (!office) {
@ -746,11 +746,12 @@ export class Division {
//Processes FINISHED products //Processes FINISHED products
processProduct(marketCycles = 1, product: Product, corporation: Corporation): number { processProduct(marketCycles = 1, product: Product, corporation: Corporation): number {
const state = corporation.state.getState();
let totalProfit = 0; let totalProfit = 0;
for (const [city, office] of getRecordEntries(this.offices)) { for (const [city, office] of getRecordEntries(this.offices)) {
const warehouse = this.warehouses[city]; const warehouse = this.warehouses[city];
if (!warehouse) continue; if (!warehouse) continue;
switch (this.state) { switch (state) {
case "PRODUCTION": { case "PRODUCTION": {
//Calculate the maximum production of this material based //Calculate the maximum production of this material based
//on the office's productivity //on the office's productivity
@ -942,14 +943,14 @@ export class Division {
case "EXPORT": case "EXPORT":
break; break;
default: default:
console.error(`Invalid State: ${this.state}`); console.error(`Invalid State: ${state}`);
break; break;
} //End switch(this.state) } //End switch(this.state)
} }
return totalProfit; return totalProfit;
} }
resetImports(state: string): void { resetImports(state: CorpStateName): void {
//At the start of the export state, set the imports of everything to 0 //At the start of the export state, set the imports of everything to 0
if (state === "EXPORT") { if (state === "EXPORT") {
for (const warehouse of getRecordValues(this.warehouses)) { for (const warehouse of getRecordValues(this.warehouses)) {

@ -59,8 +59,9 @@ function WarehouseRoot(props: WarehouseProps): React.ReactElement {
} }
// Next state which will be processed: // Next state which will be processed:
const state = corp.state.getState();
let stateText; let stateText;
switch (division.state) { switch (state) {
case "START": case "START":
stateText = "Next state: Preparing"; stateText = "Next state: Preparing";
break; break;
@ -77,7 +78,7 @@ function WarehouseRoot(props: WarehouseProps): React.ReactElement {
stateText = "Next state: Exporting materials and/or products"; stateText = "Next state: Exporting materials and/or products";
break; break;
default: default:
console.error(`Invalid state: ${division.state}`); console.error(`Invalid state: ${state}`);
break; break;
} }