CORPORATION: Happiness/Energy/Morale trend down even for productive corps (#157)

This commit is contained in:
Snarling 2022-10-25 10:32:20 -04:00 committed by GitHub
parent a79621612f
commit 5b2a96fa0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 33 deletions

@ -15,7 +15,7 @@ import { EmployeePositions } from "./EmployeePositions";
import { ResearchMap } from "./ResearchMap";
import { isRelevantMaterial } from "./ui/Helpers";
import { checkEnum } from "../utils/helpers/checkEnum";
import { CityName } from "src/Locations/data/CityNames";
import { CityName } from "../Locations/data/CityNames";
export function NewIndustry(corporation: Corporation, industry: IndustryType, name: string): void {
if (corporation.divisions.find(({ type }) => industry == type))
@ -46,7 +46,7 @@ export function NewIndustry(corporation: Corporation, industry: IndustryType, na
}
}
export function NewCity(corporation: Corporation, division: Industry, city: string): void {
export function NewCity(corporation: Corporation, division: Industry, city: CityName): void {
if (corporation.funds < CorporationConstants.OfficeInitialCost) {
throw new Error("You don't have enough company funds to open a new office!");
}
@ -389,7 +389,7 @@ export function HireAdVert(corp: Corporation, division: Industry): void {
export function MakeProduct(
corp: Corporation,
division: Industry,
city: string,
city: CityName,
productName: string,
designInvest: number,
marketingInvest: number,

@ -64,7 +64,7 @@ export class Industry {
warehouses: Record<CityName, Warehouse | 0>;
//Maps locations to offices. 0 if no office at that location
offices: { [key: string]: OfficeSpace | 0 } = {
offices: Record<CityName, OfficeSpace | 0> = {
[CityName.Aevum]: 0,
[CityName.Chongqing]: 0,
[CityName.Sector12]: new OfficeSpace({
@ -194,7 +194,7 @@ export class Industry {
// Process offices (and the employees in them)
let employeeSalary = 0;
for (const officeLoc of Object.keys(this.offices)) {
for (const officeLoc of Object.values(CityName)) {
const office = this.offices[officeLoc];
if (office) employeeSalary += office.process(marketCycles, corporation, this);
}

@ -121,7 +121,7 @@ export class OfficeSpace {
if (corporation.funds < 0 && industry.lastCycleRevenue < 0) {
perfMult = Math.pow(0.995, marketCycles);
} else if (corporation.funds > 0 && industry.lastCycleRevenue > 0) {
perfMult = Math.pow(1.005, marketCycles);
perfMult = Math.pow(0.999, marketCycles);
}
if (this.autoCoffee) {

@ -7,13 +7,14 @@ import { createCityMap } from "../Locations/createCityMap";
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver";
import { getRandomInt } from "../utils/helpers/getRandomInt";
import { CityName } from "../Locations/data/CityNames";
interface IConstructorParams {
name?: string;
demand?: number;
competition?: number;
markup?: number;
createCity?: string;
createCity?: CityName;
designCost?: number;
advCost?: number;
quality?: number;
@ -50,7 +51,7 @@ export class Product {
// Variables for handling the creation process of this Product
fin = false; // Whether this Product has finished being created
prog = 0; // Creation progress - A number between 0-100 representing percentage
createCity = ""; // City in which the product is/was being created
createCity = CityName.Sector12; // City in which the product is/was being created
designCost = 0; // How much money was invested into designing this Product
advCost = 0; // How much money was invested into advertising this Product
@ -112,7 +113,7 @@ export class Product {
this.dmd = params.demand ? params.demand : 0;
this.cmp = params.competition ? params.competition : 0;
this.mku = params.markup ? params.markup : 0;
this.createCity = params.createCity ? params.createCity : "";
this.createCity = params.createCity ? params.createCity : CityName.Sector12;
this.designCost = params.designCost ? params.designCost : 0;
this.advCost = params.advCost ? params.advCost : 0;
this.qlt = params.quality ? params.quality : 0;

@ -18,17 +18,24 @@ export function CityTabs(props: IProps): React.ReactElement {
const division = useDivision();
const [city, setCity] = useState(props.city);
const office = division.offices[city];
if (office === 0) {
setCity(CityName.Sector12);
return <></>;
let mainContent: JSX.Element;
if (city === "Expand") {
mainContent = <ExpandNewCity cityStateSetter={setCity} />;
} else {
const office = division.offices[city];
if (office === 0) {
setCity(CityName.Sector12);
return <></>;
}
mainContent = (
<Industry rerender={props.rerender} city={city} warehouse={division.warehouses[city]} office={office} />
);
}
const canExpand =
Object.keys(division.offices).filter((cityName: string) => division.offices[cityName] === 0).length > 0;
const canExpand = Object.values(CityName).filter((cityName) => division.offices[cityName] === 0).length > 0;
function handleChange(event: React.SyntheticEvent, tab: CityName | "Expand"): void {
setCity(tab);
}
return (
<>
<Tabs variant="fullWidth" value={city} onChange={handleChange} sx={{ maxWidth: "65vw" }}>
@ -37,18 +44,7 @@ export function CityTabs(props: IProps): React.ReactElement {
)}
{canExpand && <Tab label={"Expand"} value={"Expand"} />}
</Tabs>
{city !== "Expand" ? (
<Industry
key={city}
rerender={props.rerender}
city={city}
warehouse={division.warehouses[city]}
office={office}
/>
) : (
<ExpandNewCity cityStateSetter={setCity} />
)}
{mainContent}
</>
);
}

@ -21,10 +21,11 @@ import Paper from "@mui/material/Paper";
import Button from "@mui/material/Button";
import Box from "@mui/material/Box";
import { LimitMaterialProductionModal } from "./modals/LimitMaterialProductionModal";
import { CityName } from "../../Locations/data/CityNames";
interface IMaterialProps {
warehouse: Warehouse;
city: string;
city: CityName;
mat: Material;
rerender: () => void;
}

@ -11,6 +11,7 @@ import MenuItem from "@mui/material/MenuItem";
import Select, { SelectChangeEvent } from "@mui/material/Select";
import { KEY } from "../../../utils/helpers/keyCodes";
import { NumberInput } from "../../../ui/React/NumberInput";
import { CityName } from "../../../Locations/data/CityNames";
interface IProps {
open: boolean;
@ -32,8 +33,8 @@ function productPlaceholder(type: string): string {
export function MakeProductModal(props: IProps): React.ReactElement {
const corp = useCorporation();
const division = useDivision();
const allCities = Object.keys(division.offices).filter((cityName) => division.offices[cityName] !== 0);
const [city, setCity] = useState(allCities.length > 0 ? allCities[0] : "");
const allCities = Object.values(CityName).filter((cityName) => division.offices[cityName] !== 0);
const [city, setCity] = useState(allCities.length > 0 ? allCities[0] : CityName.Sector12);
const [name, setName] = useState("");
const [design, setDesign] = useState<number>(NaN);
const [marketing, setMarketing] = useState<number>(NaN);
@ -51,7 +52,7 @@ export function MakeProductModal(props: IProps): React.ReactElement {
}
function onCityChange(event: SelectChangeEvent<string>): void {
setCity(event.target.value);
setCity(event.target.value as CityName);
}
function onProductNameChange(event: React.ChangeEvent<HTMLInputElement>): void {

@ -223,7 +223,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
function getOffice(divisionName: string, cityName: string): OfficeSpace {
const division = getDivision(divisionName);
if (!(cityName in division.offices)) throw new Error(`Invalid city name '${cityName}'`);
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city name '${cityName}'`);
const office = division.offices[cityName];
if (office === 0) throw new Error(`${division.name} has not expanded to '${cityName}'`);
return office;