From 4c8a6937d3e485bde60518b8a722c6b99c465fa9 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 7 Oct 2024 22:38:12 +0200 Subject: [PATCH 1/3] getting back on track --- Ramses/home/CorpStatus.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ramses/home/CorpStatus.txt b/Ramses/home/CorpStatus.txt index 1835133..9790284 100644 --- a/Ramses/home/CorpStatus.txt +++ b/Ramses/home/CorpStatus.txt @@ -1 +1 @@ -{"nStep":200} \ No newline at end of file +{"nStep":0} \ No newline at end of file From 17e69b057891bee34c9c6ba888656c457bb4909b Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 7 Oct 2024 23:45:18 +0200 Subject: [PATCH 2/3] Next round of corp-control done --- Ramses/home/CorpControl.js | 28 +++++++++++++++++++++++----- Ramses/home/CorpStatus.txt | 2 +- Ramses/home/corp/GetCorpData.js | 4 ++++ Ramses/home/corp/GetDivisionsData.js | 4 ++++ Ramses/home/corp/GetOfficeData.js | 5 +++++ Ramses/home/corp/UpgradeOffice.js | 3 +-- 6 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 Ramses/home/corp/GetCorpData.js create mode 100644 Ramses/home/corp/GetDivisionsData.js create mode 100644 Ramses/home/corp/GetOfficeData.js diff --git a/Ramses/home/CorpControl.js b/Ramses/home/CorpControl.js index bfa514b..6abb42f 100644 --- a/Ramses/home/CorpControl.js +++ b/Ramses/home/CorpControl.js @@ -8,26 +8,44 @@ export async function main(ns) { }; let oCorpStatus = JSON.parse(ns.read("CorpStatus.txt")) || { nStep: 0 }; let nStep = oCorpStatus.nStep; + let nListenPID = 0; + let oCorpData = {}; + let oDivisionData = {}; + let oOfficeData = {} ns.tprint(oCorpStatus); - while (nStep < 200) { - + while (nStep < 199) { nStep = oCorpStatus.nStep; ns.tprint(nStep); + nListenPID = ns.run("/corp/GetCorpData.js"); + await ns.nextPortWrite(nListenPID); + oCorpData = ns.readPort(nListenPID); switch (nStep) { case 0: - await ns.nextPortWrite(ns.run("/corp/CorpStart.js", 1, sDivisionName, "Agriculture")) + if (!oCorpData.divisions.length > 0) { + nListenPID = ns.run("/corp/CorpStart.js", 1, sDivisionName, "Agriculture"); + await ns.nextPortWrite(nListenPID); + }; oCorpStatus.nStep = 10; break; case 10: for (let sCity of aCitites) { - if (sCity !== "Sector-12") await ns.nextPortWrite(ns.run("/corp/CorpExpandCity.js", 1, sDivisionName, sCity)) + nListenPID = ns.run("/corp/GetDivisionsData.js", 1, sDivisionName); + await ns.nextPortWrite(nListenPID); + oDivisionData = ns.readPort(nListenPID); + if (sCity !== "Sector-12" && !oDivisionData.cities.includes(sCity)) { + nListenPID = ns.run("/corp/CorpExpandCity.js", 1, sDivisionName, sCity); + await ns.nextPortWrite(nListenPID); + } } oCorpStatus.nStep = 20; break; case 20: let nTargetSize = 4; for (let sCity of aCitites) { - await ns.nextPortWrite(ns.run("/corp/UpgradeOffice.js", 1, sDivisionName, sCity, nTargetSize)) + nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity); + await ns.nextPortWrite(nListenPID); + oOfficeData = ns.readPort(nListenPID); + await ns.nextPortWrite(ns.run("/corp/UpgradeOffice.js", 1, sDivisionName, sCity, nTargetSize, oOfficeData.size)) } oCorpStatus.nStep = 200; break; diff --git a/Ramses/home/CorpStatus.txt b/Ramses/home/CorpStatus.txt index 9790284..1835133 100644 --- a/Ramses/home/CorpStatus.txt +++ b/Ramses/home/CorpStatus.txt @@ -1 +1 @@ -{"nStep":0} \ No newline at end of file +{"nStep":200} \ No newline at end of file diff --git a/Ramses/home/corp/GetCorpData.js b/Ramses/home/corp/GetCorpData.js new file mode 100644 index 0000000..e433075 --- /dev/null +++ b/Ramses/home/corp/GetCorpData.js @@ -0,0 +1,4 @@ +/** @param {NS} ns */ +export async function main(ns) { + ns.writePort(ns.pid,ns.corporation.getCorporation()) +} \ No newline at end of file diff --git a/Ramses/home/corp/GetDivisionsData.js b/Ramses/home/corp/GetDivisionsData.js new file mode 100644 index 0000000..adbc2aa --- /dev/null +++ b/Ramses/home/corp/GetDivisionsData.js @@ -0,0 +1,4 @@ +/** @param {NS} ns */ +export async function main(ns) { + ns.writePort(ns.pid,ns.corporation.getDivision(ns.args[0])) +} \ No newline at end of file diff --git a/Ramses/home/corp/GetOfficeData.js b/Ramses/home/corp/GetOfficeData.js new file mode 100644 index 0000000..bbd219e --- /dev/null +++ b/Ramses/home/corp/GetOfficeData.js @@ -0,0 +1,5 @@ +/** @param {NS} ns */ +export async function main(ns) { + let [sDivName, sCity] = ns.args; + ns.writePort(ns.pid, ns.corporation.getOffice(sDivName, sCity)) +} \ No newline at end of file diff --git a/Ramses/home/corp/UpgradeOffice.js b/Ramses/home/corp/UpgradeOffice.js index 977ff94..617a0ad 100644 --- a/Ramses/home/corp/UpgradeOffice.js +++ b/Ramses/home/corp/UpgradeOffice.js @@ -1,7 +1,6 @@ /** @param {NS} ns */ export async function main(ns) { - let [sDivName, sCity, nTargetSize] = ns.args; - let nCurrentSize = ns.corporation.getOffice(sDivName, sCity).size; + let [sDivName, sCity, nTargetSize, nCurrentSize] = ns.args; if (nCurrentSize < nTargetSize) { ns.corporation.upgradeOfficeSize(sDivName, sCity, nTargetSize - nCurrentSize); }; From c8cfb4f008f6287b18d724016e0a4c5561be67a2 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 8 Oct 2024 10:36:44 +0200 Subject: [PATCH 3/3] small sync --- Ramses/home/CorpControl.js | 13 +++++++++++-- Ramses/home/CorpStatus.txt | 2 +- Ramses/home/corp/HireWorkers.js | 3 +-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Ramses/home/CorpControl.js b/Ramses/home/CorpControl.js index 6abb42f..1dd9ecf 100644 --- a/Ramses/home/CorpControl.js +++ b/Ramses/home/CorpControl.js @@ -47,9 +47,18 @@ export async function main(ns) { oOfficeData = ns.readPort(nListenPID); await ns.nextPortWrite(ns.run("/corp/UpgradeOffice.js", 1, sDivisionName, sCity, nTargetSize, oOfficeData.size)) } - oCorpStatus.nStep = 200; + oCorpStatus.nStep = 30; break; case 30: + for (let sCity of aCitites) { + nListenPID = ns.run("/corp/GetOfficeData.js", 1, sDivisionName, sCity); + await ns.nextPortWrite(nListenPID); + oOfficeData = ns.readPort(nListenPID); + ns.tprint(oOfficeData); + nListenPID = ns.run("/corp/HireWorkers.js", 1, sDivisionName, sCity, oOfficeData); + await ns.nextPortWrite(nListenPID); + } + oCorpStatus.nStep = 200; break; case 40: break; @@ -69,6 +78,6 @@ export async function main(ns) { break; } ns.write("CorpStatus.txt", JSON.stringify(oCorpStatus), "w") - await ns.sleep(1000) + await ns.sleep(1) } } \ No newline at end of file diff --git a/Ramses/home/CorpStatus.txt b/Ramses/home/CorpStatus.txt index 1835133..4d87a63 100644 --- a/Ramses/home/CorpStatus.txt +++ b/Ramses/home/CorpStatus.txt @@ -1 +1 @@ -{"nStep":200} \ No newline at end of file +{"nStep":30} \ No newline at end of file diff --git a/Ramses/home/corp/HireWorkers.js b/Ramses/home/corp/HireWorkers.js index 6e71c93..e9989fc 100644 --- a/Ramses/home/corp/HireWorkers.js +++ b/Ramses/home/corp/HireWorkers.js @@ -1,7 +1,6 @@ /** @param {NS} ns */ export async function main(ns) { - let [sDivName, sCity, nTargetSize] = ns.args; - let oCurrentOffice = ns.corporation.getOffice(sDivName, sCity); + let [sDivName, sCity, oCurrentOffice] = ns.args; if (oCurrentOffice.numEmployees < oCurrentOffice.size) { (oCurrentOffice.employeeJobs.Operations < 1) ? ns.corporation.hireEmployee(sDivName, sCity,"Operations") : ""; (oCurrentOffice.employeeJobs.Engineer < 1) ? ns.corporation.hireEmployee(sDivName, sCity,"Engineer") : "";