From 867236e15319573ad45b8ce1ca403b05490ca4e6 Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Sun, 29 Jan 2023 08:14:12 -0500 Subject: [PATCH] autoAssignJob streamlining --- src/Corporation/Actions.ts | 8 +------- src/Corporation/OfficeSpace.ts | 28 ++++++++++----------------- src/Corporation/ui/IndustryOffice.tsx | 5 +---- src/NetscriptFunctions/Corporation.ts | 3 +-- 4 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index 8faa0818a..db17cd81b 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -11,10 +11,9 @@ import { Warehouse } from "./Warehouse"; import { CorporationUnlockUpgrade } from "./data/CorporationUnlockUpgrades"; import { CorporationUpgrade } from "./data/CorporationUpgrades"; import { Cities } from "../Locations/Cities"; -import { EmployeePositions, IndustryType } from "./data/Enums"; +import { IndustryType } from "./data/Enums"; import { ResearchMap } from "./ResearchMap"; import { isRelevantMaterial } from "./ui/Helpers"; -import { checkEnum } from "../utils/helpers/enum"; import { CityName } from "../Enums"; import { getRandomInt } from "../utils/helpers/getRandomInt"; import { CorpResearchName } from "@nsdefs"; @@ -331,11 +330,6 @@ export function BuyBackShares(corporation: Corporation, numShares: number): bool return true; } -export function AutoAssignJob(office: OfficeSpace, job: string, count: number): boolean { - if (!checkEnum(EmployeePositions, job)) throw new Error(`'${job}' is not a valid job.`); - return office.autoAssignJob(job, count); -} - export function UpgradeOfficeSize(corp: Corporation, office: OfficeSpace, size: number): void { const initialPriceMult = Math.round(office.size / corpConstants.officeInitialSize); const costMultiplier = 1.09; diff --git a/src/Corporation/OfficeSpace.ts b/src/Corporation/OfficeSpace.ts index 0682875aa..792493092 100644 --- a/src/Corporation/OfficeSpace.ts +++ b/src/Corporation/OfficeSpace.ts @@ -93,21 +93,11 @@ export class OfficeSpace { this.maxHap = 100; this.maxMor = 100; - if (industry.hasResearch("Go-Juice")) { - this.maxEne += 10; - } - if (industry.hasResearch("JoyWire")) { - this.maxHap += 10; - } - if (industry.hasResearch("Sti.mu")) { - this.maxMor += 10; - } - if (industry.hasResearch("AutoBrew")) { - this.autoCoffee = true; - } - if (industry.hasResearch("AutoPartyManager")) { - this.autoParty = true; - } + if (industry.hasResearch("Go-Juice")) this.maxEne += 10; + if (industry.hasResearch("JoyWire")) this.maxHap += 10; + if (industry.hasResearch("Sti.mu")) this.maxMor += 10; + if (industry.hasResearch("AutoBrew")) this.autoCoffee = true; + if (industry.hasResearch("AutoPartyManager")) this.autoParty = true; if (this.totalEmployees > 0) { /** Multiplier for employee morale/happiness/energy based on company performance */ @@ -234,11 +224,13 @@ export class OfficeSpace { } autoAssignJob(job: EmployeePositions, target: number): boolean { + if (job === EmployeePositions.Unassigned) { + throw new Error("internal autoAssignJob function called with EmployeePositions.Unassigned"); + } const diff = target - this.employeeNextJobs[job]; - if (diff === 0) { - return true; - } else if (diff <= this.employeeNextJobs[EmployeePositions.Unassigned]) { + if (diff === 0) return true; // We are already at the desired number + else if (diff <= this.employeeNextJobs[EmployeePositions.Unassigned]) { // This covers both a negative diff (reducing the amount of employees in position) and a positive (increasing and using up unassigned employees) this.employeeNextJobs[EmployeePositions.Unassigned] -= diff; this.employeeNextJobs[job] = target; diff --git a/src/Corporation/ui/IndustryOffice.tsx b/src/Corporation/ui/IndustryOffice.tsx index fd265f91b..08d2ec950 100644 --- a/src/Corporation/ui/IndustryOffice.tsx +++ b/src/Corporation/ui/IndustryOffice.tsx @@ -56,10 +56,7 @@ function AutoAssignJob(props: IAutoAssignProps): React.ReactElement { const nextUna = props.office.employeeNextJobs[EmployeePositions.Unassigned]; function assignEmployee(): void { - if (nextUna <= 0) { - console.warn("Cannot assign employee. No unassigned employees available"); - return; - } + if (nextUna <= 0) return console.warn("Cannot assign employee. No unassigned employees available"); props.office.autoAssignJob(props.job, nextJob + 1); props.rerender(); diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 5b11d7f93..12916eedc 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -29,7 +29,6 @@ import { SellProduct, SetSmartSupply, BuyMaterial, - AutoAssignJob, UpgradeOfficeSize, PurchaseWarehouse, UpgradeWarehouse, @@ -624,7 +623,7 @@ export function NetscriptCorporation(): InternalAPI { ctx, `Unable to bring '${job} employees to ${amount}. Requires ${totalNewEmployees} unassigned employees`, ); - return AutoAssignJob(office, job, amount); + return office.autoAssignJob(job, amount); }, hireEmployee: (ctx) => (_divisionName, _cityName, _position?) => { checkAccess(ctx, 8);