diff --git a/README.md b/README.md index 12467d9..7d0f9d4 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ node index.js --max-resources --no-copy | `--max-resources` | Set all capped resources (`max > 0`) to their max | | `--set-crafted=N` | Set all unlimited/crafted resources (`max == -1`) to N | | `--only=a,b,c` | Only affect listed resources (comma-separated, case-insensitive). Matches resource names (e.g. `Food`) or internal keys (e.g. `food`). Applies to `--max-resources` and `--set-crafted`. | +| `--max-soldiers` | Fill garrison to max capacity and heal all wounded soldiers | | `--no-copy` | Print the edited save to stdout instead of clipboard | | `--help` | Show help | diff --git a/index.js b/index.js index c96a9a3..59179d8 100644 --- a/index.js +++ b/index.js @@ -94,6 +94,33 @@ function listResources(data) { } } +function maxSoldiers(data) { + const garrison = data.civic?.garrison; + if (!garrison || !garrison.max) { + return "No garrison found in save."; + } + + const lines = []; + const oldWorkers = garrison.workers ?? 0; + const max = garrison.max; + const oldWounded = garrison.wounded ?? 0; + + if (oldWorkers < max) { + garrison.workers = max; + lines.push(` Soldiers: ${oldWorkers} -> ${max} (max)`); + } else { + lines.push(` Soldiers: already at max (${max})`); + } + + if (oldWounded > 0) { + garrison.wounded = 0; + lines.push(` Wounded: ${oldWounded} -> 0 (healed)`); + } + + if (lines.length === 0) return "Garrison already at full strength."; + return `Garrison:\n${lines.join("\n")}`; +} + function setGeology(data) { // Max bonus depends on White Hole achievement: top = 30 + level * 5 const whLevel = data.stats?.achieve?.whitehole?.l ?? 0; @@ -160,7 +187,7 @@ function main() { } } - const hasAction = flags.has("--max-resources") || flags.has("--max-time") || flags.has("--max-geology") || flags.has("--list") || craftedValue !== null; + const hasAction = flags.has("--max-resources") || flags.has("--max-time") || flags.has("--max-geology") || flags.has("--max-soldiers") || flags.has("--list") || craftedValue !== null; if (flags.has("--help")) { console.log(`Usage: node index.js [options] [save-string] @@ -172,6 +199,7 @@ Options: --max-resources Set all capped resources to their max --set-crafted=N Set all unlimited (crafted) resources to N --only=a,b,c Only affect listed resources (comma-separated names or keys) + --max-soldiers Fill garrison to max and heal all wounded --max-geology Set 4 geology resource bonuses at max values --max-time Set accelerated time (AT) to 8 hours --no-copy Print result instead of copying to clipboard @@ -194,7 +222,7 @@ Save string can be passed as argument, piped via stdin, or read from clipboard.` if (flags.has("--list")) { listResources(data); - if (!flags.has("--max-resources") && !flags.has("--max-geology") && !flags.has("--max-time") && craftedValue === null) { + if (!flags.has("--max-resources") && !flags.has("--max-soldiers") && !flags.has("--max-geology") && !flags.has("--max-time") && craftedValue === null) { process.exit(0); } } @@ -209,6 +237,10 @@ Save string can be passed as argument, piped via stdin, or read from clipboard.` } } + if (flags.has("--max-soldiers")) { + console.log(maxSoldiers(data)); + } + if (flags.has("--max-geology")) { console.log(setGeology(data)); } @@ -314,6 +346,7 @@ async function interactiveMode() { choices: [ { value: "max-resources", name: "Max capped resources" }, { value: "set-crafted", name: "Set crafted resources" }, + { value: "max-soldiers", name: "Max soldiers & heal wounded" }, { value: "max-geology", name: "Max geology bonuses" }, { value: "max-time", name: "Max accelerated time" }, { value: "list", name: "List all resources" }, @@ -353,6 +386,15 @@ async function interactiveMode() { continue; } + if (action === "max-soldiers") { + const result = maxSoldiers(data); + console.log(result); + if (!result.includes("No garrison") && !result.includes("already at")) { + modified = true; + } + continue; + } + if (action === "max-geology") { console.log(setGeology(data)); modified = true;