autoAssignJob streamlining

This commit is contained in:
omuretsu 2023-01-29 08:14:12 -05:00
parent d7439aae52
commit 867236e153
4 changed files with 13 additions and 31 deletions

@ -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;

@ -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;

@ -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();

@ -29,7 +29,6 @@ import {
SellProduct,
SetSmartSupply,
BuyMaterial,
AutoAssignJob,
UpgradeOfficeSize,
PurchaseWarehouse,
UpgradeWarehouse,
@ -624,7 +623,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
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);