Stop potential exploit where you switch employees around right before a product finishes

This commit is contained in:
Staszek Welsh 2022-06-02 22:11:34 +01:00
parent 1ed19168f6
commit b29c8e0039
2 changed files with 74 additions and 63 deletions

@ -1002,23 +1002,9 @@ export class Industry implements IIndustry {
const office = this.offices[city]; const office = this.offices[city];
if (office === 0) continue; if (office === 0) continue;
// Designing/Creating a Product is based mostly off Engineers prod.createProduct(marketCycles, office.employeeProd);
const engrProd = office.employeeProd[EmployeePositions.Engineer];
const mgmtProd = office.employeeProd[EmployeePositions.Management];
const opProd = office.employeeProd[EmployeePositions.Operations];
const total = engrProd + mgmtProd + opProd;
if (total <= 0) {
break;
}
// Management is a multiplier for the production from Engineers
const mgmtFactor = 1 + mgmtProd / (1.2 * total);
const progress = (Math.pow(engrProd, 0.34) + Math.pow(opProd, 0.2)) * mgmtFactor;
prod.createProduct(marketCycles, progress);
if (prod.prog >= 100) { if (prod.prog >= 100) {
prod.finishProduct(office.employeeProd, this); prod.finishProduct(this);
} }
break; break;
} }

@ -55,6 +55,15 @@ export class Product {
designCost = 0; // How much money was invested into designing this Product designCost = 0; // How much money was invested into designing this Product
advCost = 0; // How much money was invested into advertising this Product advCost = 0; // How much money was invested into advertising this Product
// The average employee productivity and scientific research across the creation of the Product
creationProd: { [key: string]: number } = {
[EmployeePositions.Operations]: 0,
[EmployeePositions.Engineer]: 0,
[EmployeePositions.Business]: 0,
[EmployeePositions.Management]: 0,
[EmployeePositions.RandD]: 0,
};
// Aggregate score for this Product's 'rating' // Aggregate score for this Product's 'rating'
// This is based on the stats/properties below. The weighting of the // This is based on the stats/properties below. The weighting of the
// stats/properties below differs between different industries // stats/properties below differs between different industries
@ -117,75 +126,91 @@ export class Product {
this.reqMats = params.req ? params.req : {}; this.reqMats = params.req ? params.req : {};
} }
// empWorkMult is a multiplier that increases progress rate based on // Make progress on this product based on current employee productivity
// productivity of employees createProduct(marketCycles: number, employeeProd: typeof this["creationProd"]): void {
createProduct(marketCycles = 1, empWorkMult = 1): void { if (this.fin) { return; }
if (this.fin) {
return; // Designing/Creating a Product is based mostly off Engineers
const opProd = employeeProd[EmployeePositions.Operations];
const engrProd = employeeProd[EmployeePositions.Engineer];
const mgmtProd = employeeProd[EmployeePositions.Management];
const total = opProd + engrProd + mgmtProd;
if (total <= 0) { return; }
// Management is a multiplier for the production from Engineers
const mgmtFactor = 1 + mgmtProd / (1.2 * total);
const prodMult = (Math.pow(engrProd, 0.34) + Math.pow(opProd, 0.2)) * mgmtFactor;
const progress = Math.min(marketCycles * 0.01 * prodMult, 100 - this.prog);
if (progress <= 0) { return; }
this.prog += progress;
for (const pos of Object.keys(employeeProd)) {
this.creationProd[pos] += employeeProd[pos] * progress / 100;
} }
this.prog += marketCycles * 0.01 * empWorkMult;
} }
// @param industry - Industry object. Reference to industry that makes this Product // @param industry - Industry object. Reference to industry that makes this Product
finishProduct(employeeProd: { [key: string]: number }, industry: IIndustry): void { finishProduct(industry: IIndustry): void {
this.fin = true; this.fin = true;
//Calculate properties // Calculate properties
const engrRatio = employeeProd[EmployeePositions.Engineer] / employeeProd["total"]; const totalProd = Object.values(this.creationProd).reduce((p, q) => p + q);
const mgmtRatio = employeeProd[EmployeePositions.Management] / employeeProd["total"]; const engrRatio = this.creationProd[EmployeePositions.Engineer] / totalProd;
const rndRatio = employeeProd[EmployeePositions.RandD] / employeeProd["total"]; const mgmtRatio = this.creationProd[EmployeePositions.Management] / totalProd;
const opsRatio = employeeProd[EmployeePositions.Operations] / employeeProd["total"]; const rndRatio = this.creationProd[EmployeePositions.RandD] / totalProd;
const busRatio = employeeProd[EmployeePositions.Business] / employeeProd["total"]; const opsRatio = this.creationProd[EmployeePositions.Operations] / totalProd;
const designMult = 1 + Math.pow(this.designCost, 0.1) / 100; const busRatio = this.creationProd[EmployeePositions.Business] / totalProd;
const designMult = 1 + Math.pow(this.designCost, 0.1) / 100;
const balanceMult = 1.2 * engrRatio + 0.9 * mgmtRatio + 1.3 * rndRatio + 1.5 * opsRatio + busRatio; const balanceMult = 1.2 * engrRatio + 0.9 * mgmtRatio + 1.3 * rndRatio + 1.5 * opsRatio + busRatio;
const sciMult = 1 + Math.pow(industry.sciResearch.qty, industry.sciFac) / 800; const sciMult = 1 + Math.pow(industry.sciResearch.qty, industry.sciFac) / 800;
const totalMult = balanceMult * designMult * sciMult; const totalMult = balanceMult * designMult * sciMult;
this.qlt = this.qlt =
totalMult * totalMult *
(0.1 * employeeProd[EmployeePositions.Engineer] + (0.1 * this.creationProd[EmployeePositions.Engineer] +
0.05 * employeeProd[EmployeePositions.Management] + 0.05 * this.creationProd[EmployeePositions.Management] +
0.05 * employeeProd[EmployeePositions.RandD] + 0.05 * this.creationProd[EmployeePositions.RandD] +
0.02 * employeeProd[EmployeePositions.Operations] + 0.02 * this.creationProd[EmployeePositions.Operations] +
0.02 * employeeProd[EmployeePositions.Business]); 0.02 * this.creationProd[EmployeePositions.Business]);
this.per = this.per =
totalMult * totalMult *
(0.15 * employeeProd[EmployeePositions.Engineer] + (0.15 * this.creationProd[EmployeePositions.Engineer] +
0.02 * employeeProd[EmployeePositions.Management] + 0.02 * this.creationProd[EmployeePositions.Management] +
0.02 * employeeProd[EmployeePositions.RandD] + 0.02 * this.creationProd[EmployeePositions.RandD] +
0.02 * employeeProd[EmployeePositions.Operations] + 0.02 * this.creationProd[EmployeePositions.Operations] +
0.02 * employeeProd[EmployeePositions.Business]); 0.02 * this.creationProd[EmployeePositions.Business]);
this.dur = this.dur =
totalMult * totalMult *
(0.05 * employeeProd[EmployeePositions.Engineer] + (0.05 * this.creationProd[EmployeePositions.Engineer] +
0.02 * employeeProd[EmployeePositions.Management] + 0.02 * this.creationProd[EmployeePositions.Management] +
0.08 * employeeProd[EmployeePositions.RandD] + 0.08 * this.creationProd[EmployeePositions.RandD] +
0.05 * employeeProd[EmployeePositions.Operations] + 0.05 * this.creationProd[EmployeePositions.Operations] +
0.05 * employeeProd[EmployeePositions.Business]); 0.05 * this.creationProd[EmployeePositions.Business]);
this.rel = this.rel =
totalMult * totalMult *
(0.02 * employeeProd[EmployeePositions.Engineer] + (0.02 * this.creationProd[EmployeePositions.Engineer] +
0.08 * employeeProd[EmployeePositions.Management] + 0.08 * this.creationProd[EmployeePositions.Management] +
0.02 * employeeProd[EmployeePositions.RandD] + 0.02 * this.creationProd[EmployeePositions.RandD] +
0.05 * employeeProd[EmployeePositions.Operations] + 0.05 * this.creationProd[EmployeePositions.Operations] +
0.08 * employeeProd[EmployeePositions.Business]); 0.08 * this.creationProd[EmployeePositions.Business]);
this.aes = this.aes =
totalMult * totalMult *
(0.0 * employeeProd[EmployeePositions.Engineer] + (0.0 * this.creationProd[EmployeePositions.Engineer] +
0.08 * employeeProd[EmployeePositions.Management] + 0.08 * this.creationProd[EmployeePositions.Management] +
0.05 * employeeProd[EmployeePositions.RandD] + 0.05 * this.creationProd[EmployeePositions.RandD] +
0.02 * employeeProd[EmployeePositions.Operations] + 0.02 * this.creationProd[EmployeePositions.Operations] +
0.1 * employeeProd[EmployeePositions.Business]); 0.1 * this.creationProd[EmployeePositions.Business]);
this.fea = this.fea =
totalMult * totalMult *
(0.08 * employeeProd[EmployeePositions.Engineer] + (0.08 * this.creationProd[EmployeePositions.Engineer] +
0.05 * employeeProd[EmployeePositions.Management] + 0.05 * this.creationProd[EmployeePositions.Management] +
0.02 * employeeProd[EmployeePositions.RandD] + 0.02 * this.creationProd[EmployeePositions.RandD] +
0.05 * employeeProd[EmployeePositions.Operations] + 0.05 * this.creationProd[EmployeePositions.Operations] +
0.05 * employeeProd[EmployeePositions.Business]); 0.05 * this.creationProd[EmployeePositions.Business]);
this.calculateRating(industry); this.calculateRating(industry);
const advMult = 1 + Math.pow(this.advCost, 0.1) / 100; const advMult = 1 + Math.pow(this.advCost, 0.1) / 100;
const busmgtgRatio = Math.max(busRatio + mgmtRatio, 1 / employeeProd["total"]); const busmgtgRatio = Math.max(busRatio + mgmtRatio, 1 / totalProd);
this.mku = 100 / (advMult * Math.pow(this.qlt + 0.001, 0.65) * busmgtgRatio); this.mku = 100 / (advMult * Math.pow(this.qlt + 0.001, 0.65) * busmgtgRatio);
// I actually don't understand well enough to know if this is right. // I actually don't understand well enough to know if this is right.