diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 9e8f9cf9d..6ab6b8da4 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -53,6 +53,7 @@ import { CorporationUnlockUpgrades } from "../Corporation/data/CorporationUnlock import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades"; import { EmployeePositions } from "../Corporation/EmployeePositions"; import { calculateIntelligenceBonus } from "../PersonObjects/formulas/intelligence"; +import { Industry } from "../Corporation/Industry"; export function NetscriptCorporation( player: IPlayer, @@ -133,6 +134,28 @@ export function NetscriptCorporation( throw helper.makeRuntimeErrorMsg(`corporation.${func}`, "You do not have access to this API."); } + function getSafeDivision(division: Industry): NSDivision { + const cities: string[] = []; + for (const office of Object.values(division.offices)) { + if (office === 0) continue; + cities.push(office.loc); + } + return { + name: division.name, + type: division.type, + awareness: division.awareness, + popularity: division.popularity, + prodMult: division.prodMult, + research: division.sciResearch.qty, + lastCycleRevenue: division.lastCycleRevenue, + lastCycleExpenses: division.lastCycleExpenses, + thisCycleRevenue: division.thisCycleRevenue, + thisCycleExpenses: division.thisCycleExpenses, + upgrades: division.upgrades, + cities: cities, + }; + } + const warehouseAPI: WarehouseAPI = { getWarehouse: function (adivisionName: any, acityName: any): NSWarehouse { checkAccess("getWarehouse", 7); @@ -478,25 +501,7 @@ export function NetscriptCorporation( checkAccess("getDivision"); const divisionName = helper.string("getDivision", "divisionName", adivisionName); const division = getDivision(divisionName); - const cities: string[] = []; - for (const office of Object.values(division.offices)) { - if (office === 0) continue; - cities.push(office.loc); - } - return { - name: division.name, - type: division.type, - awareness: division.awareness, - popularity: division.popularity, - prodMult: division.prodMult, - research: division.sciResearch.qty, - lastCycleRevenue: division.lastCycleRevenue, - lastCycleExpenses: division.lastCycleExpenses, - thisCycleRevenue: division.thisCycleRevenue, - thisCycleExpenses: division.thisCycleExpenses, - upgrades: division.upgrades, - cities: cities, - }; + return getSafeDivision(division); }, createCorporation: function (corporationName: string, selfFund = true): boolean { return createCorporation(corporationName, selfFund); @@ -516,6 +521,7 @@ export function NetscriptCorporation( issuedShares: corporation.issuedShares, sharePrice: corporation.sharePrice, state: corporation.state.getState(), + divisions: corporation.divisions.map((division): NSDivision => getSafeDivision(division)), }; }, }; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 7e84763c6..0a1e935a4 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6388,6 +6388,8 @@ interface CorporationInfo { sharePrice: number; /** State of the corporation. Possible states are START, PURCHASE, PRODUCTION, SALE, EXPORT. */ state: string; + /** Array of all divisions */ + divisions: Division[]; } /**