diff --git a/src/Company/Company.ts b/src/Company/Company.ts index 3a1e65c2a..43f6fa855 100644 --- a/src/Company/Company.ts +++ b/src/Company/Company.ts @@ -1,7 +1,7 @@ import { CompanyPosition } from "./CompanyPosition"; import * as posNames from "./data/companypositionnames"; +import { favorToRep, repToFavor } from "./formulas/favor"; -import { CONSTANTS } from "../Constants"; import { IMap } from "../types"; import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver"; @@ -71,7 +71,6 @@ export class Company { isPlayerEmployed: boolean; playerReputation: number; favor: number; - rolloverRep: number; constructor(p: IConstructorParams = DefaultConstructorParams) { this.name = p.name; @@ -84,7 +83,6 @@ export class Company { this.isPlayerEmployed = false; this.playerReputation = 1; this.favor = 0; - this.rolloverRep = 0; this.isMegacorp = false; if (p.isMegacorp) this.isMegacorp = true; } @@ -137,39 +135,17 @@ export class Company { if (this.favor == null) { this.favor = 0; } - if (this.rolloverRep == null) { - this.rolloverRep = 0; - } - const res = this.getFavorGain(); - if (res.length != 2) { - console.error("Invalid result from getFavorGain() function"); - return; - } - - this.favor += res[0]; - this.rolloverRep = res[1]; + this.favor += this.getFavorGain(); } - getFavorGain(): number[] { + getFavorGain(): number { if (this.favor == null) { this.favor = 0; } - if (this.rolloverRep == null) { - this.rolloverRep = 0; - } - let favorGain = 0, - rep = this.playerReputation + this.rolloverRep; - let reqdRep = CONSTANTS.CompanyReputationToFavorBase * Math.pow(CONSTANTS.CompanyReputationToFavorMult, this.favor); - while (rep > 0) { - if (rep >= reqdRep) { - ++favorGain; - rep -= reqdRep; - } else { - break; - } - reqdRep *= CONSTANTS.FactionReputationToFavorMult; - } - return [favorGain, rep]; + const storedRep = Math.max(0, favorToRep(this.favor)); + const totalRep = storedRep + this.playerReputation; + const newFavor = repToFavor(totalRep); + return newFavor - this.favor; } /** diff --git a/src/Company/formulas/favor.ts b/src/Company/formulas/favor.ts new file mode 100644 index 000000000..73790544b --- /dev/null +++ b/src/Company/formulas/favor.ts @@ -0,0 +1,13 @@ +// The initial formulas was sum 0 to f of 500*1.02^f. +// see https://en.wikipedia.org/wiki/Geometric_series#Closed-form_formula +// for information on how to calculate this + +export function favorToRep(f: number): number { + const raw = 25000 * (Math.pow(1.02, f) - 1); + return Math.round(raw * 10000) / 10000; // round to make things easier. +} + +export function repToFavor(r: number): number { + const raw = Math.log(r / 25000 + 1) / Math.log(1.02); + return Math.round(raw * 10000) / 10000; // round to make things easier. +} diff --git a/src/Locations/ui/CompanyLocation.tsx b/src/Locations/ui/CompanyLocation.tsx index 1a7ab0130..acc2f86cb 100644 --- a/src/Locations/ui/CompanyLocation.tsx +++ b/src/Locations/ui/CompanyLocation.tsx @@ -198,7 +198,7 @@ export function CompanyLocation(props: IProps): React.ReactElement { - You will have company favor upon resetting after + You will have company favor upon resetting after installing Augmentations }