Remove industry upgrades

There are only two industry upgrades, one of which is buying coffee
which is not an upgrade, and for the office not the industry. Moving
that to the office leaves just hiring AdVerts, which is better as an
explicitly named set of methods.
This commit is contained in:
Staszek Welsh 2022-06-02 02:43:22 +01:00
parent 18a80d3fe9
commit ba7b76369b
7 changed files with 59 additions and 139 deletions

@ -14,7 +14,6 @@ import { CorporationUpgrade } from "./data/CorporationUpgrades";
import { Cities } from "../Locations/Cities";
import { EmployeePositions } from "./EmployeePositions";
import { Employee } from "./Employee";
import { IndustryUpgrades } from "./IndustryUpgrades";
import { ResearchMap } from "./ResearchMap";
import { isRelevantMaterial } from "./ui/Helpers";
@ -334,7 +333,7 @@ export function UpgradeOfficeSize(corp: ICorporation, office: OfficeSpace, size:
}
export function BuyCoffee(corp: ICorporation, office: OfficeSpace): boolean {
const cost = 500e3 * office.employees.length;
const cost = office.getCoffeeCost();
if (corp.funds < cost) { return false; }
if (!office.setCoffee()) { return false; }
@ -381,15 +380,11 @@ export function UpgradeWarehouse(corp: ICorporation, division: IIndustry, wareho
corp.funds = corp.funds - sizeUpgradeCost;
}
export function HireAdVert(corp: ICorporation, division: IIndustry, office: OfficeSpace): void {
const upgrade = IndustryUpgrades[1];
const cost = upgrade[1] * Math.pow(upgrade[2], division.upgrades[1]);
export function HireAdVert(corp: ICorporation, division: IIndustry): void {
const cost = division.getAdVertCost();
if (corp.funds < cost) return;
corp.funds = corp.funds - cost;
division.upgrade(upgrade, {
corporation: corp,
office: office,
});
division.applyAdVert(corp);
}
export function MakeProduct(

@ -3,7 +3,6 @@ import { Warehouse } from "./Warehouse";
import { ICorporation } from "./ICorporation";
import { OfficeSpace } from "./OfficeSpace";
import { Product } from "./Product";
import { IndustryUpgrade } from "./IndustryUpgrades";
export interface IIndustry {
name: string;
@ -36,12 +35,11 @@ export interface IIndustry {
thisCycleRevenue: number;
thisCycleExpenses: number;
upgrades: number[];
state: string;
newInd: boolean;
warehouses: { [key: string]: Warehouse | 0 };
offices: { [key: string]: OfficeSpace | 0 };
numAdVerts: number;
init(): void;
getProductDescriptionText(): string;
@ -56,7 +54,8 @@ export interface IIndustry {
processProducts(marketCycles: number, corporation: ICorporation): [number, number];
processProduct(marketCycles: number, product: Product, corporation: ICorporation): number;
discontinueProduct(product: Product): void;
upgrade(upgrade: IndustryUpgrade, refs: { corporation: ICorporation; office: OfficeSpace }): void;
getAdVertCost(): number;
applyAdVert(corporation: ICorporation): void;
getOfficeProductivity(office: OfficeSpace, params?: { forProduct?: boolean }): number;
getBusinessFactor(office: OfficeSpace): number;
getAdvertisingFactors(): [number, number, number, number];

@ -14,7 +14,6 @@ import { MaterialSizes } from "./MaterialSizes";
import { Warehouse } from "./Warehouse";
import { ICorporation } from "./ICorporation";
import { IIndustry } from "./IIndustry";
import { IndustryUpgrade, IndustryUpgrades } from "./IndustryUpgrades";
interface IParams {
name?: string;
@ -59,9 +58,6 @@ export class Industry implements IIndustry {
thisCycleRevenue: number;
thisCycleExpenses: number;
//Upgrades
upgrades: number[] = Array(Object.keys(IndustryUpgrades).length).fill(0);
state = "START";
newInd = true;
@ -81,6 +77,8 @@ export class Industry implements IIndustry {
[CityName.Volhaven]: 0,
};
numAdVerts = 0;
constructor(params: IParams = {}) {
this.name = params.name ? params.name : "";
this.type = params.type ? params.type : Industries.Agriculture;
@ -1262,38 +1260,19 @@ export class Industry implements IIndustry {
}
}
upgrade(upgrade: IndustryUpgrade, refs: { corporation: ICorporation; office: OfficeSpace }): void {
const corporation = refs.corporation;
const office = refs.office;
const upgN = upgrade[0];
while (this.upgrades.length <= upgN) {
this.upgrades.push(0);
getAdVertCost(): number {
return 1e9 * Math.pow(1.06, this.numAdVerts);
}
++this.upgrades[upgN];
switch (upgN) {
case 0: {
//Coffee, 5% energy per employee
for (let i = 0; i < office.employees.length; ++i) {
office.employees[i].ene = Math.min(office.employees[i].ene * 1.05, office.maxEne);
}
break;
}
case 1: {
//AdVert.Inc,
applyAdVert(corporation: ICorporation): void {
const advMult = corporation.getAdvertisingMultiplier() * this.getAdvertisingMultiplier();
const awareness = (this.awareness + 3 * advMult) * (1.01 * advMult);
this.awareness = Math.min(awareness, Number.MAX_VALUE);
const popularity = (this.popularity + 1 * advMult) * ((1 + getRandomInt(1, 3) / 100) * advMult);
this.popularity = Math.min(popularity, Number.MAX_VALUE);
break;
}
default: {
console.error(`Un-implemented function index: ${upgN}`);
break;
}
}
++this.numAdVerts;
}
// Returns how much of a material can be produced based of office productivity (employee stats)

@ -1,22 +0,0 @@
import { IMap } from "../types";
export type IndustryUpgrade = [number, number, number, number, string, string];
// Industry upgrades
// The data structure is an array with the following format:
// [index in array, base price, price mult, benefit mult (if applicable), name, desc]
export const IndustryUpgrades: IMap<IndustryUpgrade> = {
"0": [0, 500e3, 1, 1.05, "Coffee", "Provide your employees with coffee, increasing their energy by 5%."],
"1": [
1,
1e9,
1.06,
1.03,
"AdVert.Inc",
"Hire AdVert.Inc to advertise your company. Each level of " +
"this upgrade grants your company a static increase of 3 and 1 to its awareness and " +
"popularity, respectively. It will then increase your company's awareness by 1%, and its popularity " +
"by a random percentage between 1% and 3%. These effects are increased by other upgrades " +
"that increase the power of your advertising.",
],
};

@ -251,6 +251,10 @@ export class OfficeSpace {
return count === target;
}
getCoffeeCost(): number {
return 500e3 * this.employees.length;
}
setCoffee(mult = 1.05): boolean {
if (mult > 1 && this.coffeeMult === 0 && !this.autoCoffee && this.employees.length > 0) {
this.coffeeMult = mult;

@ -2,11 +2,9 @@
// (top-left panel in the Industry UI)
import React, { useState } from "react";
import { BuyCoffee } from "../Actions";
import { OfficeSpace } from "../OfficeSpace";
import { Industries } from "../IndustryData";
import { IndustryUpgrades } from "../IndustryUpgrades";
import { BuyCoffee, HireAdVert } from "../Actions";
import { numeralWrapper } from "../../ui/numeralFormat";
import { createProgressBarText } from "../../utils/helpers/createProgressBarText";
import { MakeProductModal } from "./modals/MakeProductModal";
@ -209,67 +207,38 @@ function Text(): React.ReactElement {
</Button>
<ResearchModal open={researchOpen} onClose={() => setResearchOpen(false)} industry={division} />
</Box>
</>
);
}
function Upgrades(props: { office: OfficeSpace; rerender: () => void }): React.ReactElement {
const corp = useCorporation();
const division = useDivision();
const upgrades = [];
for (const index of Object.keys(IndustryUpgrades)) {
const upgrade = IndustryUpgrades[index];
<Typography>Purchases & Upgrades</Typography>
// AutoBrew research disables the Coffee upgrade
if (division.hasResearch("AutoBrew") && upgrade[4] === "Coffee") {
continue;
}
const i = upgrade[0];
const baseCost = upgrade[1];
const priceMult = upgrade[2];
let cost = 0;
let disabled = false;
switch (i) {
case 0: //Coffee, cost is static per employee
cost = props.office.employees.length * baseCost;
disabled = cost > corp.funds || props.office.coffeeMult > 0;
break;
default:
cost = baseCost * Math.pow(priceMult, division.upgrades[i]);
disabled = cost > corp.funds;
break;
}
function onClick(): void {
if (corp.funds < cost) return;
corp.funds = corp.funds - cost;
if (i == 0) {
BuyCoffee(corp, props.office);
} else {
division.upgrade(upgrade, {
corporation: corp,
office: props.office,
});
}
props.rerender();
}
upgrades.push(
<Tooltip key={index} title={upgrade[5]}>
<Box display="flex" alignItems="center">
<Tooltip title={"Provide your employees with coffee, increasing their energy by 5%."}>
<span>
<Button disabled={disabled} onClick={onClick}>
{upgrade[4]} -&nbsp;
<MoneyCost money={cost} corp={corp} />
<Button disabled={false} onClick={() => undefined}>
{"coffee"} -&nbsp;
<MoneyCost money={1e6} corp={corp} />
</Button>
</span>
</Tooltip>,
</Tooltip>
<Tooltip
title={
<Typography>
Hire AdVert.Inc to advertise your company. Each level of
this upgrade grants your company a static increase of 3 and 1 to its awareness and
popularity, respectively. It will then increase your company's awareness by 1%, and its popularity
by a random percentage between 1% and 3%. These effects are increased by other upgrades
that increase the power of your advertising.
</Typography>
}>
<span>
<Button disabled={division.getAdVertCost() > corp.funds} onClick={() => HireAdVert(corp, division)}>
{"Hire AdVert"} -&nbsp;
<MoneyCost money={division.getAdVertCost()} corp={corp} />
</Button>
</span>
</Tooltip>
</Box>
</>
);
}
return <>{upgrades}</>;
}
interface IProps {
@ -285,8 +254,6 @@ export function IndustryOverview(props: IProps): React.ReactElement {
<Paper>
<Text />
<br />
<Typography>Purchases & Upgrades</Typography>
<Upgrades office={props.office} rerender={props.rerender} /> <br />
{division.makesProducts && <MakeProductButton />}
</Paper>
);

@ -64,7 +64,6 @@ import { calculateIntelligenceBonus } from "../PersonObjects/formulas/intelligen
import { Industry } from "../Corporation/Industry";
import { IndustryResearchTrees, IndustryStartingCosts } from "../Corporation/IndustryData";
import { CorporationConstants } from "../Corporation/data/Constants";
import { IndustryUpgrades } from "../Corporation/IndustryUpgrades";
import { ResearchMap } from "../Corporation/ResearchMap";
import { Factions } from "../Faction/Factions";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
@ -303,7 +302,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
lastCycleExpenses: division.lastCycleExpenses,
thisCycleRevenue: division.thisCycleRevenue,
thisCycleExpenses: division.thisCycleExpenses,
upgrades: division.upgrades.slice(),
upgrades: [0, division.numAdVerts],
cities: cities,
products: division.products === undefined ? [] : Object.keys(division.products),
makesProducts: division.makesProducts,
@ -659,8 +658,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
checkAccess(ctx, 8);
const divisionName = ctx.helper.string("divisionName", _divisionName);
const division = getDivision(divisionName);
const upgrade = IndustryUpgrades[1];
return upgrade[1] * Math.pow(upgrade[2], division.upgrades[1]);
return division.getAdVertCost();
},
getHireAdVertCount:
(ctx: NetscriptContext) =>
@ -668,7 +666,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
checkAccess(ctx, 8);
const divisionName = ctx.helper.string("divisionName", _divisionName);
const division = getDivision(divisionName);
return division.upgrades[1];
return division.numAdVerts;
},
getResearchCost:
(ctx: NetscriptContext) =>
@ -802,7 +800,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
checkAccess(ctx, 8);
const divisionName = ctx.helper.string("divisionName", _divisionName);
const corporation = getCorporation();
HireAdVert(corporation, getDivision(divisionName), getOffice(divisionName, "Sector-12"));
HireAdVert(corporation, getDivision(divisionName));
},
research:
(ctx: NetscriptContext) =>