diff --git a/docs/thirty-night-soak.md b/docs/thirty-night-soak.md new file mode 100644 index 0000000..ca4ebdc --- /dev/null +++ b/docs/thirty-night-soak.md @@ -0,0 +1,542 @@ +# Thirty-night soak: pool sizes and a balance report (#28, 2026-10-06) + +The whole 30-night vacation, played headless by the scripted scarecrow for three seeds, plus a +measurement of the enemies' character pools on nights 20 and 30. This is a report, not a retune: +nothing in the game broke, so no numbers changed. The recommendations are at the end. + +## Summary + +- **Nothing broke.** 3 × 30 nights, plus 17 retried ones: no crash, every night ended on time, no + queue got stuck, and the carry-over checks passed every night. Waiting breakers came in as + others fell, and the rest were dropped at sunrise and counted, as #25 intends. +- **The scripted defense survives, with retries.** Its 3 HP first ran out on night 9. It fell on + 17 tries in all (3, 8, and 6 per seed). Seed 3 won every lost night on its retry; seed 1 went + on shielded from night 12, and seed 2 from night 29. +- **Losses start on night 2, and the farm is empty by night 8.** The animals go on nights 2–5 and + the crops mostly on nights 3 and 5. From night 8 on, every seed has 0 crops and 0 animals left, + so only the shed is at stake. The crows (91–168 a night) and the animal thieves arrive to + nothing. Softer nights 2–5 only put this off by a night or two, and a fully defended farm + dropped onto night 20 loses 40–48 of its 50 crops in that one night (Tune next, #1). +- **At most 40 enemies at once** in the soak (night 30). The breakers sit at their pool of 20 from + night 11 on; the thieves never pass 8. A farm with everything left draws more: up to 76 at + once on night 30. +- **Breakers wait from night 11.** Up to 51 a night wait for a character, and up to 50 never come + (night 30). In `test_nights`, with nobody fighting, 71 of night 30's 91 breakers never come. +- **The tick is fine.** `FarmSim.step` averages 0.4–1.6 ms a night, with the 99th percentile under + 5 ms and one-off spikes of 6–12 ms. The 60 Hz budget is 16.7 ms. +- **Pools:** thieves never need 48 (15 at once at most, in any run), and breakers fill any pool on + nights 20 and 30. The pool size barely moves the sim tick. Recommended: 32 thieves and 40 + breakers, if a visible-window check of the drawing cost passes. + +## Method + +**The soak.** Three seeds of the whole vacation, run side by side, each with its own +`XDG_DATA_HOME`: + +```sh +godot --headless --path . --script res://game/tools/soak_night.gd -- \ + --mode=cycle --cycles=30 --seed=1 --save-at=10,20,30 --save-dir=/tmp/saves_1 +# and --seed=2, --seed=3 +``` + +Each cycle plays a whole day and night at 60 ticks a second, with `FarmSim.step` called in a loop +(no frames drawn). The seed sets the arrival points, the loot RNG, and Godot's global RNG. + +**What the scripted scarecrow does.** +- **By day:** it gathers until 115 s (the nearest point with charges first, storing at the shed). + Then it puts the pen gate back if it's gone, buys the corn shooter as soon as it can, repairs + the nearest damaged structure it can pay for, and builds the 16-piece build plan in order: 7 + automated defenses, 2 slowing traps, and 6 fences on the crop field's east side. A piece that + breaks is built again. With nothing left to build or repair, it buys upgrade levels at the + workbench, lowest level first. +- **At night:** it chases the most urgent threat (carriers first). It shoots with perfect aim, + throws pumpkin bombs into crowds, uses fear on carriers and crowds, leads following animals back + to the pen, and patches up when hurt and nothing is close. + +**What it doesn't do.** It isn't a human, so read its numbers as one consistent player, not as +"the" difficulty. +- It never misses, and never hesitates. +- It's one scarecrow chasing one threat at a time, by a fixed priority. It doesn't plan, read the + dusk warning, or wait at the pen for the animal thieves. +- It stops gathering at 115 s, and walks to the nearest point first. It gets about 9 wood, 16 + scrap, and 20 straw a day: about 45 units. The farm and the four outside areas hold about 185 a + day (54 wood, 69 scrap, 62 straw), so a player who gathers more has up to four times as much. +- Building, repairing, and buying are instant once it's close (no build mode, no 2 s hold to + repair, no menus). +- It only buys the corn shooter, pumpkin bombs, and the stat upgrades. It never buys shurikens, + the potato cannon, the torch, the alien ray, radar, sprint, or the bigger pouch, so Alien Goop + is never spent. + +**When the scarecrow falls.** The night is reported, then retried once from its morning. If it +falls again, the soak carries on from a third try with the scarecrow **shielded**: it still +fights, but takes no hits (`--shield=after`, the default). That keeps the later nights measured. +HP numbers from a shielded night on mean nothing; the rows are marked. A farm stripped bare would +have stopped the run (it never happened). + +**The tick.** `Time.get_ticks_usec()` around each `FarmSim.step` during the night and the dawn +grace: the average, the 99th percentile, and the max per night. The bot's own decisions are +outside the timed call. The three seeds ran at the same time on a 16-core machine, so their ticks +are a little noisier than a lone run. The pool runs below ran one at a time. + +## Results + +The per-night tables below cover all three seeds. Some terms: +- **Waited:** plan arrivals that were due while every character of their type was in use. They + came in later, or were dropped at sunrise. +- **Supplies** are the shed's stock, every material in it: the third thing thieves steal. +- **Standing:** structures in the morning, the Workbench and the pen gate included. +- **Lost tries:** nights the scarecrow fell; each was retried from its morning. + +### Arrivals, the peak on the farm, and the tick + +Ranges are min–max over the three seeds (median in brackets); one number means all three agree. +Peaks and ticks are medians. Ticks are `FarmSim.step` over the night and dawn, in µs. + +| Night | Planned | Arrived | Waited | Dropped | Peak alive | Peak crows / thieves / breakers / UFOs | Tick avg | p99 | max | +|---|---|---|---|---|---|---|---|---|---| +| 1 | 11 | 11 | 0 | 0 | 2–3 | 2 / 0 / 0 / 0 | 425 | 478 | 8061 | +| 2 | 112 | 112 | 0 | 0 | 17–20 (18) | 14 / 13 / 0 / 0 | 558 | 984 | 11554 | +| 3 | 91 | 91 | 0 | 0 | 19–21 (20) | 17 / 11 / 7 / 0 | 821 | 3473 | 9017 | +| 4 | 133 | 133 | 0 | 0 | 28–35 (32) | 22 / 9 / 7 / 0 | 778 | 3447 | 6160 | +| 5 | 168 | 168 | 0 | 0 | 28–29 | 20 / 7 / 13 / 7 | 857 | 3405 | 6069 | +| 6 | 182 | 182 | 0 | 0 | 18–25 (22) | 5 / 7 / 7 / 11 | 648 | 3377 | 6065 | +| 7 | 189 | 189 | 0 | 0 | 21 | 2 / 7 / 19 / 8 | 785 | 3428 | 8189 | +| 8 | 203 | 203 | 0 | 0 | 19–21 (20) | 2 / 7 / 13 / 13 | 882 | 3637 | 6630 | +| 9 | 210 | 210 | 0 | 0 | 23–25 | 1 / 7 / 14 / 11 | 783 | 3515 | 6241 | +| 10 | 294 | 294 | 0 | 0 | 24–37 (29) | 2 / 7 / 13 / 10 | 933 | 3612 | 7450 | +| 11 | 231 | 231 | 2–5 (4) | 0 | 24–25 | 1 / 7 / 20 / 7 | 861 | 3577 | 7107 | +| 12 | 245 | 245 | 0–1 | 0 | 31–32 | 1 / 7 / 20 / 16 | 982 | 3620 | 6036 | +| 13 | 252 | 252 | 4–14 (13) | 0 | 27 | 1 / 7 / 20 / 7 | 1088 | 3918 | 7736 | +| 14 | 266 | 266 | 1–4 (2) | 0 | 26–27 | 1 / 7 / 20 / 11 | 1024 | 3854 | 6455 | +| 15 | 364 | 364 | 0 | 0 | 29–30 | 1 / 7 / 19 / 10 | 1360 | 3931 | 8227 | +| 16 | 287 | 273–287 | 0–14 | 0–14 | 34–42 (35) | 1 / 7 / 14 / 16 | 1068 | 3853 | 6120 | +| 17 | 301 | 301 | 0 | 0 | 24–30 (27) | 1 / 7 / 14 / 12 | 1120 | 3912 | 7525 | +| 18 | 308 | 308 | 7–12 (9) | 0 | 27–34 | 1 / 7 / 20 / 9 | 1217 | 3937 | 6318 | +| 19 | 322 | 293–322 | 13–31 (14) | 0–29 | 28–42 (33) | 1 / 7 / 20 / 17 | 915 | 3879 | 6640 | +| 20 | 427 | 384–425 (419) | 27–50 (29) | 2–43 (8) | 34–39 (38) | 1 / 7 / 20 / 13 | 1254 | 3987 | 7367 | +| 21 | 343 | 320–343 | 0–27 (5) | 0–23 | 32–38 (37) | 1 / 7 / 20 / 13 | 1026 | 3737 | 6161 | +| 22 | 357 | 331–357 | 12–27 (14) | 0–26 | 28–36 (33) | 1 / 7 / 20 / 15 | 1031 | 3719 | 8307 | +| 23 | 364 | 364 | 0–2 | 0 | 29–33 | 1 / 7 / 18 / 9 | 1329 | 3716 | 6487 | +| 24 | 378 | 354–378 | 20–36 (34) | 0–24 | 33–35 (34) | 1 / 7 / 20 / 9 | 1212 | 3650 | 6430 | +| 25 | 504 | 504 | 15–24 (16) | 0 | 36–38 (37) | 1 / 7 / 20 / 11 | 1569 | 4260 | 8433 | +| 26 | 399 | 355–399 | 4–45 (7) | 0–44 | 34–38 (36) | 1 / 7 / 20 / 13 | 1219 | 3824 | 6795 | +| 27 | 406 | 406 | 22–32 (29) | 0 | 27 | 1 / 7 / 20 / 12 | 1452 | 3837 | 6454 | +| 28 | 420 | 420 | 1–6 (2) | 0 | 34–36 (35) | 1 / 7 / 20 / 12 | 1502 | 4016 | 6479 | +| 29 | 427 | 385–427 | 12–47 | 0–42 | 34–35 | 1 / 7 / 20 / 10 | 1455 | 4103 | 6610 | +| 30 | 511 | 461–511 (498) | 27–51 (49) | 0–50 (13) | 39–40 | 2 / 7 / 20 / 14 | 999 | 3642 | 6933 | + +### The farm, each morning + +Medians over the three seeds, except where a range is given. HP is at the end of the dawn +grace; "lost" counts the tries the scarecrow fell on that night (each was retried). + +| Night | Lost crops / animals / supplies | Left crops / animals / supplies | HP at dawn | Lost tries | Levels (of 35) | Banked wood / scrap / straw / goop | Standing | +|---|---|---|---|---|---|---|---| +| 1 | 1 / 0 / 0 | 29 / 8 / 24 | 3 of 3 | | 1 | 1 / 1 / 22 / 0 | 4 | +| 2 | 0 / 3 / 0 | 33 / 5 / 47 | 3 of 3 | | 1 | 1 / 2 / 38 / 7 | 9 | +| 3 | 12 / 1 / 5 | 21 / 2 / 63 | 3 of 3 | | 1–2 | 0 / 5 / 39 / 19 | 3–6 | +| 4 | 1 / 2 / 25 | 21 / 0 / 96 | 3 of 3 | | 1–2 | 5 / 20 / 42 / 28 | 3 | +| 5 | 16 / 0 / 10 | 4 / 0 / 67 | 3 of 3 | | 2–3 | 1 / 3 / 27 / 27 | 3 | +| 6 | 3 / 0 / 5 | 1 / 0 / 56 | 3 of 3 | | 4–5 | 0 / 5 / 25 / 26 | 3 | +| 7 | 0 / 0 / 0 | 1 / 0 / 77 | 3 of 3 | | 4–5 | 0 / 7 / 39 / 32 | 3–4 | +| 8 | 1 / 0 / 0 | 0 / 0 / 126 | 2–3 of 3 | | 4–5 | 0 / 19 / 59 / 44 | 3 | +| 9 | 0 / 0 / 5 | 0 / 0 / 115 | 3 of 3 | 2 | 5–6 | 0 / 5 / 63 / 49 | 3 | +| 10 | 0 / 0 / 0 | 0 / 0 / 134 | 3 of 3 | | 5–6 | 0 / 7 / 72 / 58 | 3–4 | +| 11 | 0 / 0 / 0 | 0 / 0 / 169 | 3 of 3 | 1 | 5–6 | 1 / 17 / 90 / 69 | 3–4 | +| 12 | 0 / 0 / 5 | 0 / 0 / 213 | 2–3 of 3 (1 shielded) | 2 | 5–7 | 0 / 18 / 110 / 76 | 3 | +| 13 | 0 / 0 / 0 | 0 / 0 / 218 | 2–3 of 3 (1 shielded) | 1 | 5–7 | 0 / 9 / 124 / 86 | 3–5 | +| 14 | 0 / 0 / 10 | 0 / 0 / 237 | 3 of 3 (1 shielded) | | 5–7 | 0 / 9 / 132 / 96 | 3 | +| 15 | 0 / 0 / 5 | 0 / 0 / 248 | 2–3 of 3 (1 shielded) | | 5–7 | 0 / 10 / 128 / 111 | 3 | +| 16 | 0 / 0 / 5 | 0 / 0 / 252 | 2–3 of 3 (1 shielded) | 1 | 5–8 (7) | 0 / 11 / 105 / 121 | 3 | +| 17 | 0 / 0 / 0 | 0 / 0 / 279 | 2–3 of 3 (1 shielded) | | 5–8 (7) | 0 / 11 / 121 / 134 | 3–4 | +| 18 | 0 / 0 / 10 | 0 / 0 / 283 | 2–3 of 3 (1 shielded) | | 6–8 (7) | 0 / 13 / 139 / 143 | 3 | +| 19 | 0 / 0 / 0 | 0 / 0 / 285 | 2–3 of 3 (1 shielded) | | 6–9 (7) | 0 / 13 / 126 / 150 | 3 | +| 20 | 0 / 0 / 5 | 0 / 0 / 317 | 2–3 of 3 (1 shielded) | | 6–9 (8) | 0 / 4 / 128 / 163 | 3 | +| 21 | 0 / 0 / 25 | 0 / 0 / 270 | 2–3 of 3 (1 shielded) | 1 | 6–10 (8) | 0 / 8 / 139 / 150 | 3 | +| 22 | 0 / 0 / 5 | 0 / 0 / 301 | 2–3 of 3 (1 shielded) | | 7–10 (8) | 0 / 8 / 150 / 161 | 3 | +| 23 | 0 / 0 / 5 | 0 / 0 / 330 | 2–3 of 3 (1 shielded) | 2 | 7–10 (8) | 0 / 8 / 163 / 160 | 3 | +| 24 | 0 / 0 / 10 | 0 / 0 / 359 | 2–3 of 3 (1 shielded) | 1 | 7–10 (8) | 0 / 24 / 173 / 169 | 3 | +| 25 | 0 / 0 / 0 | 0 / 0 / 395 | 2–3 of 3 (1 shielded) | 1 | 7–10 (8) | 0 / 25 / 185 / 193 | 3 | +| 26 | 0 / 0 / 0 | 0 / 0 / 365 | 3 of 3 (1 shielded) | | 7–11 (9) | 0 / 8 / 151 / 209 | 3 | +| 27 | 0 / 0 / 5 | 0 / 0 / 388 | 2–3 of 3 (1 shielded) | | 7–11 (9) | 0 / 13 / 165 / 216 | 3 | +| 28 | 0 / 0 / 30 | 0 / 0 / 389 | 2–3 of 3 (1 shielded) | 1 | 7–11 (9) | 0 / 17 / 181 / 199 | 3 | +| 29 | 0 / 0 / 5 | 0 / 0 / 419 | 2–3 of 3 (2 shielded) | 3 | 9–11 | 0 / 15 / 199 / 204 | 3 | +| 30 | 0 / 0 / 10 | 0 / 0 / 412 | 2–3 of 3 (2 shielded) | 1 | 9–11 (10) | 0 / 11 / 185 / 216 | 3 | + +### Upgrade levels bought + +The scripted player buys levels with what's left after building and repairs, lowest level first. + +| Seed | Bought (day of each level) | Levels by night 30 | +|---|---|---| +| 1 | Corn shooter 1; Pumpkin bombs 5; Quick fear 5, 18, 29; Sticky tar 6, 22; Heavy seeds 9, 29 | 9 of 35 | +| 2 | Corn shooter 1; Pumpkin bombs 3; Heavy seeds 6, 20; Quick fear 6, 9, 26; Sticky tar 6, 12, 30 | 10 of 35 | +| 3 | Corn shooter 1; Heavy seeds 5, 16, 26; Pumpkin bombs 5; Quick fear 6, 16, 19; Sticky tar 6, 16, 21 | 11 of 35 | + +Besides the corn shooter and the pumpkin bombs, it only ever bought the three upgrades with no +wood in their cost. It never bought rapid fire, long-range defenses, reinforced fences, wide fear, +or straw stuffing: every bit of wood went into the gate and the defenses the robots broke. The +level days (8 and 16) never held it back; its second levels came on days 9–29 and its third on +days 19–30. + +## Character pools + +Enemies on foot are drawn by a fixed pool of KayKit characters per type (`character_pool`, now 48 +thieves and 20 breakers). One that's due while its pool is in use waits (#25). + +**Method.** Nights 20 and 30, three farms, three pools (thieves / breakers: 48/20, 64/28, and +48/40), seeds 1 and 2: 36 runs, one at a time. +- **Full farm, guarded:** F3's path to that morning, so nothing has been lost (50 crops, 8 animals). + The shed gets 300 of each material, so by dusk the scripted player has built the whole plan and + bought 21 levels. The scarecrow is shielded. +- **Full farm, defenses only:** the same farm, but the scarecrow stands aside at night. Only the + automated defenses fight, so the most enemies stay alive. +- **The soak's farm:** the 30-night soak's own morning of that night (seeds 1 and 2), loaded from + its save: nothing left but the shed. + +```sh +godot --headless --path . --script res://game/tools/soak_night.gd -- --mode=cycle --cycles=1 --seed=1 \ + --start=20 --stock=300 --gather=0 --shield=always --frame=1 --pool=thief:64,breaker:28 [--guard=0] +godot --headless --path . --script res://game/tools/soak_night.gd -- --mode=cycle --cycles=1 --seed=1 \ + --load=/tmp/saves_1/night_20.json --shield=always --frame=1 --pool=thief:64,breaker:28 +``` + +Pairs are seeds 1 and 2. The tick average is the mean of the two; p99 and max are the worse one +(µs). The character frame is `EnemyCharacters`' per-frame update plus its AnimationPlayers, run +once per tick: the CPU side only. + +| Farm | Night | Pool | Breakers waited | Breakers dropped | Peak breakers | Peak thieves | Peak all | Crops lost | Tick avg | p99 | max | Character frame avg / max | +|---|---|---|---|---|---|---|---|---|---|---|---|---| +| Full farm, guarded | 20 | 48/20 | 41, 29 | 26, 9 | 20, 20 | 15, 15 | 49, 50 | 48, 40 | 1425 | 6214 | 9304 | 115 / 311 | +| Full farm, guarded | 20 | 64/28 | 9, 3 | 3, 2 | 28, 28 | 15, 15 | 51, 51 | 34, 31 | 1509 | 6124 | 9374 | 116 / 340 | +| Full farm, guarded | 20 | 48/40 | 0, 0 | 0, 0 | 35, 31 | 15, 15 | 58, 51 | 35, 31 | 1505 | 6121 | 9219 | 119 / 329 | +| Full farm, guarded | 30 | 48/20 | 32, 40 | 0, 19 | 20, 20 | 15, 15 | 56, 64 | 43, 47 | 1407 | 5812 | 9801 | 130 / 297 | +| Full farm, guarded | 30 | 64/28 | 13, 24 | 0, 21 | 28, 28 | 15, 15 | 56, 64 | 35, 47 | 1409 | 5786 | 9526 | 133 / 453 | +| Full farm, guarded | 30 | 48/40 | 0, 11 | 0, 1 | 39, 40 | 15, 15 | 56, 64 | 35, 47 | 1413 | 5945 | 9661 | 143 / 575 | +| Full farm, defenses only | 20 | 48/20 | 50, 50 | 38, 39 | 20, 20 | 15, 15 | 58, 58 | 47, 47 | 947 | 3776 | 8368 | 134 / 313 | +| Full farm, defenses only | 20 | 64/28 | 40, 42 | 32, 33 | 28, 28 | 15, 15 | 64, 63 | 47, 48 | 993 | 3779 | 8277 | 182 / 467 | +| Full farm, defenses only | 20 | 48/40 | 23, 24 | 23, 24 | 40, 40 | 15, 15 | 68, 67 | 47, 50 | 1079 | 3784 | 7198 | 211 / 561 | +| Full farm, defenses only | 30 | 48/20 | 71, 68 | 59, 57 | 20, 20 | 15, 15 | 76, 73 | 48, 49 | 982 | 3798 | 7359 | 193 / 419 | +| Full farm, defenses only | 30 | 64/28 | 61, 59 | 55, 55 | 28, 28 | 15, 15 | 80, 74 | 49, 49 | 1110 | 4033 | 7092 | 240 / 620 | +| Full farm, defenses only | 30 | 48/40 | 49, 46 | 48, 45 | 40, 40 | 15, 15 | 96, 95 | 50, 48 | 1253 | 3898 | 6947 | 295 / 577 | +| The soak's farm (seeds 1, 2) | 20 | 48/20 | 23, 30 | 3, 6 | 20, 20 | 7, 8 | 34, 36 | 0, 0 | 1208 | 4080 | 6403 | 90 / 271 | +| The soak's farm (seeds 1, 2) | 20 | 64/28 | 1, 5 | 0, 1 | 28, 28 | 8, 8 | 35, 36 | 0, 0 | 1230 | 4299 | 8278 | 90 / 305 | +| The soak's farm (seeds 1, 2) | 20 | 48/40 | 0, 0 | 0, 0 | 29, 33 | 8, 8 | 35, 40 | 0, 0 | 1221 | 4279 | 8374 | 89 / 306 | +| The soak's farm (seeds 1, 2) | 30 | 48/20 | 24, 28 | 0, 0 | 20, 20 | 7, 7 | 39, 36 | 0, 0 | 1192 | 4214 | 7874 | 92 / 354 | +| The soak's farm (seeds 1, 2) | 30 | 64/28 | 10, 25 | 0, 0 | 28, 28 | 7, 7 | 48, 47 | 0, 0 | 1138 | 4548 | 7897 | 102 / 378 | +| The soak's farm (seeds 1, 2) | 30 | 48/40 | 0, 12 | 0, 12 | 33, 40 | 7, 7 | 52, 59 | 0, 0 | 1141 | 4486 | 8499 | 118 / 594 | + +**What it shows.** +- **Thieves never need 48.** At most 15 were on the farm at once in every run, guarded or not (7–8 + in the soak). No thief ever waited. +- **Breakers fill any pool on nights 20 and 30.** At 20, 23–71 a night wait and up to 59 are + dropped. At 28, a guarded full farm still drops up to 21 on night 30. At 40, a guarded farm + drops 0–1 (once 12). With nobody fighting, even 40 fill up and 23–48 are dropped. +- **The pool barely moves the tick.** Guarded, the average changes by under 6% (1.43 → 1.51 ms on + night 20), and p99 and max don't move: the max stays under 10 ms in every run. With nobody + fighting, 40 breakers alive instead of 20 cost 14–28% more on average (0.98 → 1.25 ms on night + 30). That's the extra enemies, not the pool. +- **The characters' CPU side is small:** 0.1–0.3 ms a frame on average, 0.6 ms at worst. +- **Idle characters keep animating.** A character whose enemy leaves is hidden, but its + AnimationPlayer keeps looping the last clip, through the next day too. At the end of a night, + 1–55 hidden characters were still animating, more with bigger pools. Stopping the player in + `EnemyCharacters.release()` and `clear()` would make a spare character cost nothing. (Not + changed here: it isn't a number.) + +**Recommended:** `character_pool = {"thief": 32, "breaker": 40}`, 72 characters instead of 68, if +the render check passes. +- **32 thieves:** twice the most ever seen at once. +- **40 breakers:** almost no drops on the heaviest nights while someone fights. +- If 40 robots on screen cost too much, 28 is the fallback. It helps while someone fights + (night 20, guarded: 41 waiting → 9), not when nobody does (50 → 40), so the late plans' + breakers should come down as well (Tune next, #2). + +**The render check (for you).** Headless can't measure drawing. In a visible window, set +`character_pool` on `game_config.tres` in the inspector to 32/40, F3 to the morning of day 30, +start the night, stand aside near the shed so the robots pile up, and watch the frame time +(Debugger > Monitors, or the FPS). Then compare with 48/20. + +## What broke, and what was fixed + +Nothing in the game broke. Over 3 × 30 nights (plus 17 retries) there was no crash and every +night ended on time. No queue got stuck: waiting breakers kept coming in as others fell, and the +ones still waiting at sunrise were dropped and counted. The carry-over checks passed every night, +and `make_nights.gd` still passes every plan. So no numbers changed. + +Fixed in the tools and tests: +- **The soak's carry-over check** said "6 structures at night … != 7 in the morning" after night 1. + The Workbench is granted when night 1 ends; the check now counts that grant. +- **`test_nights` `_back_to_back`** expected every planned arrival to arrive. In that test no + scarecrow fights, so the breakers past their pool of 20 wait all night and are dropped at + sunrise, as #25 intends (nights 5, 10, and 30 failed). It's now an accounting check: every + planned arrival either arrived or was dropped at sunrise; dropped ones are of a ground type whose + characters were all in use as the night ended; the drops match `WaveDirector.dropped`; and + nothing was skipped (`spawn_skipped` stays put). Its text and the night's info line still give + the planned, arrived, and dropped numbers ("night 30: 440 of 511 arrived, 71 dropped (71 + breaker)"). +- **The scripted scarecrow** (soak only), so a 30-night run means something: + - It buys the corn shooter first. Before, building spent the wood and scrap first, so it fought + night 3's robots with the pitchfork and fell 11 s in (seed 1, twice). + - It repairs damaged structures and builds broken build-plan pieces again. Before, a broken + defense stayed gone for the rest of the vacation. + - It patches at half of its real maximum health (with straw stuffing), not half of the base 3. + - The workbench's upgrades need the Workbench standing, as in the game (granted after night 1, + not broken). +- **The soak's report** now has, per night: arrivals planned / arrived / waited / dropped, the + peak alive per type, losses per category, HP at dawn, levels and what was bought, materials + banked, structures, kills, and the tick. It retries a lost night, can go on shielded, and has + measuring options (`--start`, `--load`, `--save-at`, `--stock`, `--pool`, `--frame`) and + density options for experiments (`--count-scale`, `--plan-scale`, in memory only). + +## Three things to tune next + +The density numbers in #1 come from extra soaks with the same scripted player, each changing only +the count scale (in memory; no files changed). Up to seven ran at a time, so their ticks aren't +reported. + +```sh +# nights 2-5 softened, 10 nights; a flat 3x or 2x, 30 nights; the ramp, 30 nights (seeds 1-3 each) +soak_night.gd -- --mode=cycle --cycles=10 --seed=1 --plan-scale=2:3,3:4,4:5,5:6 +soak_night.gd -- --mode=cycle --cycles=30 --seed=1 --count-scale=3 +soak_night.gd -- --mode=cycle --cycles=30 --seed=1 --plan-scale=2:2,3:2,...,9:2,10:3,...,19:3,20:4,...,30:4 +# a full farm on night 20 (seeds 1 and 2), count scale 7, 5, 4, 3, 2, 1.5 +soak_night.gd -- --mode=cycle --cycles=1 --seed=1 --start=20 --stock=300 --gather=0 --shield=always --count-scale=5 +``` + +### 1. With losses permanent, the density decides when the farm is empty + +The farm has 30 crops (50 once the fields sprout after nights 2 and 4) and 8 animals, and +nothing comes back. To still have something at the end of 30 nights, a farm can lose about 1–2 +crops a night. At today's density it loses far more. + +**Crops / animals left in the morning** (median of seeds 1–3; the same scripted player at every +density): + +| After night | 7× (today) | Nights 2–5 at 3/4/5/6×, then 7× | 3× | 2× | Ramp: 2× (2–9), 3× (10–19), 4× (20–30) | +|---|---|---|---|---|---| +| 1 | 29 / 8 | 29 / 8 | 29 / 8 | 29 / 8 | 29 / 8 | +| 2 | 33 / 5 | 36 / 8 | 36 / 8 | 38 / 8 | 38 / 8 | +| 3 | 21 / 2 | 33 / 7 | 35 / 5 | 38 / 7 | 38 / 7 | +| 4 | 21 / 0 | 31 / 5 | 37 / 5 | 42 / 7 | 42 / 7 | +| 5 | 4 / 0 | 3 / 2 | 26 / 3 | 34 / 6 | 34 / 6 | +| 6 | 1 / 0 | 1 / 0 | 11 / 2 | 27 / 5 | 27 / 5 | +| 8 | 0 / 0 | 0 / 0 | 1 / 2 | 17 / 2 | 17 / 2 | +| 10 | 0 / 0 | 0 / 0 | 1 / 0 | 4 / 1 | 2 / 1 | +| 15 | 0 / 0 | – | 0 / 0 | 1 / 0 | 0 / 0 | +| 20 | 0 / 0 | – | 0 / 0 | 1 / 0 | 0 / 0 | +| 25 | 0 / 0 | – | 0 / 0 | 0 / 0 | 0 / 0 | +| 30 | 0 / 0 | – | 0 / 0 | 0 / 0 | 0 / 0 | + +**A full farm dropped onto night 20.** F3 to day 20 (50 crops, 8 animals), 300 of each material, +the whole build plan, 21 levels, the scarecrow guarding and shielded. Crops lost in that one +night (seeds 1 and 2): + +| Count scale | 7× (427 enemies) | 5× (305) | 4× (244) | 3× (183) | 2× (122) | 1.5× (97) | +|---|---|---|---|---|---|---| +| Crops lost | 48, 40 | 37, 19 | 16, 16 | 14, 11 | 7, 6 | 4, 15 | + +What it says: +- **At 7× the farm is gone by night 8**, and 22 nights have nothing at stake but the shed. The + shed doesn't work as a stake: thieves take 0–30 a night from a stock that grows to 400. +- **Softening only nights 2–5 isn't enough.** It saves the animals for a night or two, but nights + 5 and 6 (144 and 182 arrivals) still take everything. +- **Even a strong defense can't hold the late nights.** A full farm loses 40–48 crops on night 20 + at 7×, and still 11–14 at 3×. +- **Lower density only stretches it:** at 3× the crops are gone after about night 8, at 2× after + about night 10–15. No density we tried keeps crops into the last week. + +**Try:** +- **A count scale that ramps with the nights** instead of a flat 7: each plan's own + `count_scale` (night 1 already has one), written by `make_nights.gd` and set by hand on nights + 2–5 and 30: **2 on nights 2–9, 3 on 10–19, 4 on 20–30**. Night 2 plays 32 enemies instead of + 112, night 20 plays 244 instead of 427, and night 30 292 instead of 511. Measured (the last + column above): the first week holds, with 17 crops and 2 animals left after night 8 instead of + none, and the scarecrow fell on 6 tries instead of 17. The breakers nearly fit their pool of 20 + (7–19 dropped on four nights, 23–25). The crops are still gone after night 10–15. +- **Something new to defend in the back half,** since no density we tried keeps crops into the + last week: crop fields that sprout after nights 10, 15, 20, and 25 (10 crops each: new crop + units with those sprout nights, like the fields after nights 2 and 4). Stolen crops still stay + gone, so this isn't the regrowth you turned down, but it's close to it: your call. + +The ramp undoes much of the 7× density you asked for. The soak says 7×, permanent losses, and 30 +nights don't fit together, at least for this player: if 7× stays, the farm is the shed and the +scarecrow from night 8 on. + +### 2. Match the breakers to their pool + +The plans send more robots than can be on the farm. At 7× the breakers' pool of 20 is full from +night 11; up to 50 a night are dropped in the soak, and 71 of night 30's 91 in `test_nights`. + +**Try**, at 7×: +- `character_pool` breakers 20 → **40** (if the render check passes; see Character pools), and + thieves 48 → **32**. +- `make_nights.gd`: `MIX_TO` breaker share **0.20 → 0.12**, and UFOs **0.15 → 0.23** (the shares + must add up to 1; UFOs fly, so they need no characters). Then `--force` for nights 6–29. Night + 29 goes from 84 breakers to about 50. Bring night 30's breaker groups (13 base, 91 played) + down to about 8 base (56) by hand. + +With #1's ramp, the late nights plan 48–52 breakers (night 29 at 4×: 48; night 30: 52), and a pool +of 40 covers them on its own: in the pool runs, 40 breakers dropped 0–1 a night while someone +fought. + +### 3. Straw and Alien Goop pile up; wood runs out + +- **Wood:** 27, 29, and 29 of the 30 mornings (per seed) started with 0 or 1 wood. The robots + break 2–3 structures a night (8–11 on night 3), and rebuilding the gate and fences takes all + of it. After night 3, the structures standing stayed at 3–5 (the Workbench, the gate, and one + or two more) for the rest of the vacation. +- **Straw and goop:** by night 30 the shed held about 185 straw and 216 Alien Goop, with nothing + to spend them on. At 3× and 2× it's the same: 195–218 straw, 197–220 goop, 0–5 wood. +- **Upgrades:** 9–11 of 35 levels by night 30. Past the corn shooter and the pumpkin bombs, every + level came from the three upgrades with no wood in their cost (heavy seeds, quick fear, sticky + tar). The level days (8 and 16) never held anything back. + +The scripted player only gathers 9 of the 54 wood a day there is (the farm's Woodlot and the North +Grove outside), so people may not run short of wood. They will have even more straw, though, and +goop has one use (the alien ray, 6 goop). + +**Try** (costs live in `game_config.tres`, your values, so these are suggestions): +- Let the things that break every night take straw: fence **2 wood → 1 wood + 2 straw**; gate + **4 wood + 1 scrap → 2 wood + 2 straw + 1 scrap**. +- Give goop a second use: workbench levels 2 and 3 also cost **5 and 10 Alien Goop**, and in + exchange `upgrade_cost_growth` **1.8 → 1.5** (the second and third tiers of the nine upgrades + cost 309 and 468 materials instead of 378 and 674). That needs a small code change in + `Upgrades.cost`. +- Keep `upgrade_level_days` at 8 and 16. +- Ask playtesters whether they run out of wood before changing its costs. + +## Not measured + +- **Rendering.** Headless draws nothing, so the cost of more skinned characters on screen (GPU + skinning, draw calls, shadows) is unmeasured. See "The render check" above: night 30 with + `character_pool` at 32/40 against 48/20. The character frame column in the pool table is only + the CPU side. +- **People.** The scripted scarecrow aims perfectly, gathers a quarter of what's there, and never + gets bored. Treat the tables as one consistent player; the playtest questions in + `game/PLAYTEST.md` still stand. + +## Appendix: every night, per seed + +Every try is a row, lost ones included ("scarecrow destroyed N s in"), then the retry. + +### Seed 1 + +| Night | Result | Planned / arrived / waited / dropped | Peak c / t / b / u (all) | Lost c / a / s | Left c / a / s | HP | Bought | Banked w / s / st / g | Built (rebuilt) / broken / repaired, standing | Tick avg / max | +|---|---|---|---|---|---|---|---|---|---|---| +| 1 | ok | 11 / 11 / 0 / 0 | 2 / 0 / 0 / 0 (2) | 1 / 0 / 0 | 29 / 8 / 24 | 3/3 | Corn shooter | 1 / 1 / 22 / 0 | 3 (0) / 0 / 0, 4 | 418 / 8061 | +| 2 | ok | 112 / 112 / 0 / 0 | 16 / 13 / 0 / 0 (20) | 0 / 5 / 0 | 37 / 3 / 47 | 3/3 | | 1 / 2 / 38 / 7 | 5 (0) / 0 / 0, 9 | 558 / 11536 | +| 3 | ok | 91 / 91 / 0 / 0 | 17 / 9 / 7 / 0 (19) | 13 / 1 / 5 | 24 / 2 / 72 | 3/3 | | 0 / 5 / 49 / 18 | 5 (0) / 8 / 1, 6 | 821 / 9281 | +| 4 | ok | 133 / 133 / 0 / 0 | 24 / 9 / 9 / 0 (32) | 3 / 2 / 25 | 21 / 0 / 96 | 3/3 | | 9 / 21 / 42 / 25 | 0 (0) / 3 / 0, 3 | 764 / 6347 | +| 5 | ok | 168 / 168 / 0 / 0 | 18 / 7 / 12 / 7 (29) | 14 / 0 / 10 | 7 / 0 / 47 | 3/3 | Pumpkin bombs, Quick fear I | 1 / 0 / 19 / 27 | 4 (3) / 4 / 2, 3 | 883 / 5937 | +| 6 | ok | 182 / 182 / 0 / 0 | 8 / 7 / 7 / 11 (25) | 7 / 0 / 5 | 0 / 0 / 56 | 3/3 | Sticky tar I | 0 / 5 / 25 / 26 | 1 (0) / 1 / 1, 3 | 648 / 5694 | +| 7 | ok | 189 / 189 / 0 / 0 | 1 / 8 / 20 / 8 (21) | 0 / 0 / 0 | 0 / 0 / 77 | 3/3 | | 0 / 6 / 39 / 32 | 3 (2) / 2 / 1, 4 | 748 / 7410 | +| 8 | ok | 203 / 203 / 0 / 0 | 1 / 7 / 13 / 11 (20) | 0 / 0 / 0 | 0 / 0 / 126 | 2/3 | | 4 / 19 / 59 / 44 | 1 (0) / 2 / 1, 3 | 805 / 6364 | +| 9 | scarecrow destroyed 73 s in | 210 / 112 / 0 / 0 | 1 / 7 / 8 / 11 (20) | 0 / 0 / 0 | 0 / 0 / 120 | 0/3 | Heavy seeds I | 0 / 9 / 67 / 47 | 2 (1) / 0 / 2, 5 | 863 / 4003 | +| 9 | ok, retry 1 | 210 / 210 / 0 / 0 | 1 / 8 / 14 / 10 (23) | 0 / 0 / 0 | 0 / 0 / 115 | 3/3 | Heavy seeds I | 0 / 3 / 63 / 49 | 3 (2) / 3 / 2, 3 | 783 / 7978 | +| 10 | ok | 294 / 294 / 0 / 0 | 2 / 7 / 14 / 10 (29) | 0 / 0 / 5 | 0 / 0 / 134 | 3/3 | | 0 / 4 / 72 / 58 | 3 (2) / 3 / 1, 3 | 1047 / 5896 | +| 11 | ok | 231 / 231 / 2 / 0 | 1 / 7 / 20 / 7 (24) | 0 / 0 / 0 | 0 / 0 / 169 | 3/3 | | 1 / 10 / 90 / 69 | 2 (1) / 1 / 2, 4 | 810 / 7107 | +| 12 | scarecrow destroyed 17 s in | 245 / 66 / 0 / 0 | 1 / 0 / 16 / 18 (34) | 0 / 0 / 0 | 0 / 0 / 200 | 0/3 | | 3 / 18 / 110 / 69 | 0 (0) / 1 / 2, 3 | 1301 / 7851 | +| 12 | scarecrow destroyed 82 s in, retry 1 | 245 / 133 / 0 / 0 | 1 / 7 / 19 / 18 (33) | 0 / 0 / 0 | 0 / 0 / 202 | 0/3 | | 3 / 20 / 108 / 71 | 0 (0) / 1 / 2, 3 | 1039 / 5916 | +| 12 | ok, shielded (0 hits blocked), retry 2 | 245 / 245 / 0 / 0 | 1 / 7 / 20 / 16 (32) | 0 / 0 / 0 | 0 / 0 / 213 | 3/3 | | 9 / 18 / 110 / 76 | 0 (0) / 1 / 2, 3 | 750 / 5723 | +| 13 | ok, shielded (3 hits blocked) | 252 / 252 / 4 / 0 | 1 / 7 / 20 / 7 (27) | 0 / 0 / 0 | 0 / 0 / 218 | 3/3 | | 1 / 9 / 124 / 86 | 4 (3) / 2 / 2, 5 | 940 / 8292 | +| 14 | ok, shielded (0 hits blocked) | 266 / 266 / 4 / 0 | 1 / 7 / 20 / 11 (26) | 0 / 0 / 10 | 0 / 0 / 237 | 3/3 | | 0 / 9 / 132 / 96 | 1 (1) / 3 / 3, 3 | 1024 / 8029 | +| 15 | ok, shielded (1 hits blocked) | 364 / 364 / 0 / 0 | 1 / 7 / 19 / 10 (30) | 0 / 0 / 20 | 0 / 0 / 248 | 3/3 | | 0 / 9 / 128 / 111 | 3 (2) / 3 / 1, 3 | 1353 / 7795 | +| 16 | ok, shielded (1 hits blocked) | 287 / 287 / 0 / 0 | 1 / 7 / 14 / 16 (35) | 0 / 0 / 5 | 0 / 0 / 269 | 3/3 | | 0 / 9 / 139 / 121 | 3 (2) / 3 / 1, 3 | 1185 / 6120 | +| 17 | ok, shielded (0 hits blocked) | 301 / 301 / 0 / 0 | 1 / 7 / 13 / 11 (30) | 0 / 0 / 0 | 0 / 0 / 298 | 3/3 | | 0 / 10 / 155 / 134 | 3 (2) / 2 / 1, 4 | 940 / 7525 | +| 18 | ok, shielded (8 hits blocked) | 308 / 308 / 7 / 0 | 1 / 7 / 20 / 9 (34) | 0 / 0 / 5 | 0 / 0 / 283 | 3/3 | Quick fear II | 0 / 1 / 139 / 143 | 1 (1) / 2 / 2, 3 | 1052 / 5972 | +| 19 | ok, shielded (0 hits blocked) | 322 / 322 / 14 / 0 | 1 / 7 / 20 / 15 (28) | 0 / 0 / 0 | 0 / 0 / 317 | 3/3 | | 0 / 2 / 155 / 160 | 3 (2) / 3 / 1, 3 | 1017 / 6640 | +| 20 | ok, shielded (18 hits blocked) | 427 / 425 / 29 / 2 | 1 / 8 / 20 / 11 (34) | 0 / 0 / 5 | 0 / 0 / 341 | 3/3 | | 0 / 4 / 166 / 172 | 3 (2) / 3 / 1, 3 | 1254 / 8158 | +| 21 | ok, shielded (1 hits blocked) | 343 / 343 / 5 / 0 | 1 / 7 / 20 / 13 (38) | 0 / 0 / 0 | 0 / 0 / 379 | 3/3 | | 1 / 8 / 184 / 186 | 2 (1) / 2 / 2, 3 | 1026 / 7002 | +| 22 | ok, shielded (0 hits blocked) | 357 / 331 / 27 / 26 | 1 / 7 / 20 / 15 (28) | 0 / 0 / 5 | 0 / 0 / 382 | 3/3 | Sticky tar II | 0 / 8 / 178 / 196 | 1 (0) / 1 / 1, 3 | 906 / 8307 | +| 23 | ok, shielded (4 hits blocked) | 364 / 364 / 0 / 0 | 1 / 7 / 18 / 9 (29) | 0 / 0 / 0 | 0 / 0 / 408 | 3/3 | | 0 / 8 / 194 / 210 | 3 (2) / 3 / 1, 3 | 1331 / 8198 | +| 24 | ok, shielded (5 hits blocked) | 378 / 378 / 34 / 0 | 1 / 7 / 20 / 9 (34) | 0 / 0 / 10 | 0 / 0 / 450 | 3/3 | | 0 / 24 / 214 / 212 | 1 (0) / 1 / 1, 3 | 1326 / 6430 | +| 25 | ok, shielded (62 hits blocked) | 504 / 504 / 16 / 0 | 1 / 8 / 20 / 11 (38) | 0 / 0 / 20 | 0 / 0 / 459 | 3/3 | | 0 / 25 / 220 / 214 | 3 (2) / 3 / 1, 3 | 1563 / 8444 | +| 26 | ok, shielded (35 hits blocked) | 399 / 399 / 7 / 0 | 1 / 8 / 20 / 13 (34) | 0 / 0 / 0 | 0 / 0 / 484 | 3/3 | | 0 / 25 / 236 / 226 | 3 (2) / 3 / 1, 3 | 1488 / 8195 | +| 27 | ok, shielded (7 hits blocked) | 406 / 406 / 29 / 0 | 1 / 7 / 20 / 12 (27) | 0 / 0 / 0 | 0 / 0 / 539 | 3/3 | | 0 / 40 / 256 / 243 | 1 (0) / 1 / 1, 3 | 1452 / 6319 | +| 28 | ok, shielded (31 hits blocked) | 420 / 420 / 2 / 0 | 1 / 7 / 20 / 14 (35) | 0 / 0 / 30 | 0 / 0 / 553 | 3/3 | | 1 / 45 / 249 / 258 | 2 (1) / 2 / 2, 3 | 1455 / 6479 | +| 29 | ok, shielded (3 hits blocked) | 427 / 385 / 47 / 42 | 1 / 7 / 20 / 10 (35) | 0 / 0 / 5 | 0 / 0 / 479 | 3/3 | Heavy seeds II, Quick fear III | 0 / 10 / 199 / 270 | 1 (0) / 1 / 1, 3 | 1053 / 6610 | +| 30 | farmers back, shielded (23 hits blocked) | 511 / 511 / 49 / 0 | 2 / 7 / 20 / 14 (40) | 0 / 0 / 90 | 0 / 0 / 412 | 3/3 | | 0 / 11 / 185 / 216 | 3 (2) / 3 / 1, 3 | 1423 / 6875 | + +### Seed 2 + +| Night | Result | Planned / arrived / waited / dropped | Peak c / t / b / u (all) | Lost c / a / s | Left c / a / s | HP | Bought | Banked w / s / st / g | Built (rebuilt) / broken / repaired, standing | Tick avg / max | +|---|---|---|---|---|---|---|---|---|---|---| +| 1 | ok | 11 / 11 / 0 / 0 | 2 / 0 / 0 / 0 (2) | 2 / 0 / 0 | 28 / 8 / 24 | 3/3 | Corn shooter | 1 / 1 / 22 / 0 | 3 (0) / 0 / 0, 4 | 428 / 8637 | +| 2 | ok | 112 / 112 / 0 / 0 | 14 / 13 / 0 / 0 (18) | 0 / 1 / 0 | 33 / 7 / 49 | 3/3 | | 1 / 2 / 38 / 8 | 5 (0) / 0 / 0, 9 | 568 / 11712 | +| 3 | ok | 91 / 91 / 0 / 0 | 16 / 12 / 10 / 0 (21) | 12 / 1 / 5 | 21 / 6 / 60 | 3/3 | Pumpkin bombs | 0 / 2 / 39 / 22 | 5 (0) / 11 / 1, 3 | 905 / 8113 | +| 4 | ok | 133 / 133 / 0 / 0 | 22 / 13 / 7 / 0 (35) | 1 / 6 / 50 | 20 / 0 / 54 | 3/3 | | 0 / 17 / 9 / 28 | 1 (0) / 1 / 1, 3 | 897 / 6160 | +| 5 | ok | 168 / 168 / 0 / 0 | 20 / 7 / 13 / 7 (28) | 16 / 0 / 15 | 4 / 0 / 67 | 3/3 | | 1 / 22 / 27 / 17 | 2 (1) / 2 / 2, 3 | 842 / 6296 | +| 6 | ok | 182 / 182 / 0 / 0 | 5 / 7 / 7 / 11 (22) | 3 / 0 / 5 | 1 / 0 / 27 | 3/3 | Heavy seeds I, Quick fear I, Sticky tar I | 0 / 7 / 5 / 16 | 1 (0) / 1 / 1, 3 | 643 / 6065 | +| 7 | ok | 189 / 189 / 0 / 0 | 2 / 7 / 19 / 8 (21) | 0 / 0 / 0 | 1 / 0 / 48 | 3/3 | | 0 / 7 / 21 / 21 | 3 (2) / 3 / 1, 3 | 825 / 8911 | +| 8 | ok | 203 / 203 / 0 / 0 | 2 / 7 / 11 / 13 (19) | 1 / 0 / 5 | 0 / 0 / 67 | 3/3 | | 0 / 7 / 30 / 30 | 3 (2) / 3 / 1, 3 | 930 / 7903 | +| 9 | scarecrow destroyed 22 s in | 210 / 63 / 0 / 0 | 1 / 7 / 7 / 13 (27) | 0 / 0 / 0 | 0 / 0 / 84 | 0/3 | | 0 / 8 / 46 / 32 | 3 (2) / 0 / 1, 6 | 1186 / 4127 | +| 9 | ok, retry 1 | 210 / 210 / 0 / 0 | 1 / 7 / 19 / 11 (25) | 0 / 0 / 5 | 0 / 0 / 57 | 3/3 | Quick fear II | 0 / 5 / 21 / 31 | 1 (0) / 1 / 2, 3 | 741 / 5853 | +| 10 | ok | 294 / 294 / 0 / 0 | 2 / 7 / 12 / 9 (24) | 0 / 0 / 0 | 0 / 0 / 79 | 3/3 | | 0 / 7 / 33 / 39 | 3 (2) / 2 / 1, 4 | 881 / 7450 | +| 11 | scarecrow destroyed 98 s in | 231 / 180 / 3 / 0 | 1 / 7 / 20 / 6 (26) | 0 / 0 / 0 | 0 / 0 / 121 | 0/3 | | 2 / 17 / 48 / 49 | 0 (0) / 0 / 2, 4 | 828 / 4562 | +| 11 | ok, retry 1 | 231 / 231 / 4 / 0 | 1 / 7 / 20 / 7 (24) | 0 / 0 / 0 | 0 / 0 / 119 | 3/3 | | 2 / 17 / 53 / 49 | 0 (0) / 1 / 2, 3 | 861 / 6230 | +| 12 | ok | 245 / 245 / 0 / 0 | 1 / 7 / 18 / 17 (31) | 0 / 0 / 10 | 0 / 0 / 85 | 2/3 | Sticky tar II | 0 / 0 / 41 / 45 | 4 (3) / 4 / 1, 3 | 982 / 9120 | +| 13 | scarecrow destroyed 21 s in | 252 / 48 / 6 / 6 | 0 / 7 / 20 / 7 (27) | 0 / 0 / 0 | 0 / 0 / 102 | 0/3 | | 0 / 0 / 52 / 45 | 3 (2) / 2 / 1, 4 | 1431 / 6608 | +| 13 | ok, retry 1 | 252 / 252 / 14 / 0 | 1 / 7 / 20 / 7 (27) | 0 / 0 / 0 | 0 / 0 / 128 | 2/3 | | 0 / 9 / 65 / 55 | 1 (1) / 1 / 1, 3 | 1142 / 6105 | +| 14 | ok | 266 / 266 / 2 / 0 | 1 / 7 / 20 / 11 (26) | 0 / 0 / 5 | 0 / 0 / 145 | 3/3 | | 0 / 8 / 74 / 70 | 3 (2) / 3 / 1, 3 | 1233 / 6197 | +| 15 | ok | 364 / 364 / 0 / 0 | 1 / 8 / 20 / 10 (29) | 0 / 0 / 5 | 0 / 0 / 177 | 2/3 | | 0 / 10 / 83 / 84 | 3 (2) / 3 / 1, 3 | 1589 / 8227 | +| 16 | scarecrow destroyed 113 s in | 287 / 175 / 0 / 0 | 1 / 7 / 12 / 0 (19) | 0 / 0 / 0 | 0 / 0 / 203 | 0/3 | | 0 / 11 / 99 / 93 | 3 (2) / 3 / 1, 3 | 843 / 6302 | +| 16 | ok, retry 1 | 287 / 287 / 0 / 0 | 1 / 7 / 13 / 16 (34) | 0 / 0 / 0 | 0 / 0 / 205 | 2/3 | | 0 / 11 / 99 / 96 | 3 (2) / 3 / 1, 3 | 1068 / 6608 | +| 17 | ok | 301 / 301 / 0 / 0 | 1 / 7 / 14 / 12 (24) | 0 / 0 / 0 | 0 / 0 / 226 | 2/3 | | 0 / 11 / 113 / 102 | 3 (2) / 3 / 1, 3 | 1120 / 8433 | +| 18 | ok | 308 / 308 / 9 / 0 | 1 / 7 / 20 / 9 (27) | 0 / 0 / 15 | 0 / 0 / 245 | 3/3 | | 0 / 13 / 112 / 120 | 3 (2) / 3 / 1, 3 | 1228 / 8113 | +| 19 | ok | 322 / 322 / 13 / 0 | 1 / 7 / 20 / 21 (33) | 0 / 0 / 0 | 0 / 0 / 285 | 2/3 | | 1 / 18 / 126 / 140 | 2 (1) / 2 / 2, 3 | 915 / 6132 | +| 20 | ok | 427 / 384 / 50 / 43 | 1 / 7 / 20 / 13 (38) | 0 / 0 / 15 | 0 / 0 / 273 | 2/3 | Heavy seeds II | 0 / 3 / 128 / 142 | 1 (0) / 1 / 1, 3 | 1001 / 7367 | +| 21 | ok | 343 / 343 / 0 / 0 | 1 / 7 / 17 / 11 (32) | 0 / 0 / 25 | 0 / 0 / 270 | 2/3 | | 0 / 3 / 139 / 129 | 3 (2) / 3 / 1, 3 | 1100 / 6161 | +| 22 | ok | 357 / 357 / 14 / 0 | 1 / 8 / 20 / 16 (33) | 0 / 0 / 5 | 0 / 0 / 301 | 2/3 | | 0 / 3 / 150 / 148 | 3 (2) / 3 / 1, 3 | 1225 / 8535 | +| 23 | scarecrow destroyed 81 s in | 364 / 200 / 0 / 0 | 1 / 7 / 13 / 7 (25) | 0 / 0 / 0 | 0 / 0 / 328 | 0/3 | | 1 / 8 / 163 / 151 | 2 (1) / 2 / 2, 3 | 1122 / 8266 | +| 23 | ok, retry 1 | 364 / 364 / 0 / 0 | 1 / 7 / 18 / 9 (29) | 0 / 0 / 5 | 0 / 0 / 330 | 2/3 | | 1 / 8 / 163 / 160 | 2 (1) / 2 / 2, 3 | 1329 / 6487 | +| 24 | ok | 378 / 354 / 36 / 24 | 1 / 7 / 20 / 8 (35) | 0 / 0 / 10 | 0 / 0 / 359 | 2/3 | | 0 / 17 / 173 / 169 | 1 (0) / 1 / 1, 3 | 1096 / 6443 | +| 25 | scarecrow destroyed 33 s in | 504 / 97 / 0 / 0 | 1 / 7 / 17 / 11 (29) | 0 / 0 / 0 | 0 / 0 / 375 | 0/3 | | 0 / 17 / 187 / 171 | 3 (2) / 3 / 1, 3 | 1573 / 8492 | +| 25 | ok, retry 1 | 504 / 504 / 24 / 0 | 1 / 7 / 20 / 12 (37) | 0 / 0 / 0 | 0 / 0 / 395 | 2/3 | | 0 / 17 / 185 / 193 | 3 (2) / 3 / 1, 3 | 1676 / 8433 | +| 26 | ok | 399 / 399 / 4 / 0 | 1 / 7 / 20 / 13 (36) | 0 / 0 / 5 | 0 / 0 / 365 | 3/3 | Quick fear III | 0 / 5 / 151 / 209 | 1 (0) / 1 / 2, 3 | 1219 / 6795 | +| 27 | ok | 406 / 406 / 32 / 0 | 1 / 7 / 20 / 11 (27) | 0 / 0 / 10 | 0 / 0 / 388 | 2/3 | | 0 / 7 / 165 / 216 | 3 (2) / 3 / 1, 3 | 1572 / 6454 | +| 28 | ok | 420 / 420 / 1 / 0 | 1 / 7 / 20 / 12 (34) | 0 / 0 / 30 | 0 / 0 / 389 | 2/3 | | 0 / 9 / 181 / 199 | 3 (2) / 3 / 1, 3 | 1502 / 8612 | +| 29 | scarecrow destroyed 130 s in | 427 / 418 / 17 / 0 | 1 / 9 / 20 / 10 (36) | 0 / 0 / 0 | 0 / 0 / 427 | 0/3 | | 1 / 15 / 195 / 216 | 2 (1) / 2 / 2, 3 | 1832 / 6969 | +| 29 | scarecrow destroyed 16 s in, retry 1 | 427 / 52 / 0 / 0 | 1 / 7 / 13 / 9 (28) | 0 / 0 / 0 | 0 / 0 / 414 | 0/3 | | 1 / 15 / 199 / 199 | 2 (1) / 0 / 2, 5 | 1186 / 3930 | +| 29 | ok, shielded (2 hits blocked), retry 2 | 427 / 427 / 12 / 0 | 1 / 8 / 20 / 10 (34) | 0 / 0 / 10 | 0 / 0 / 419 | 2/3 | | 1 / 15 / 199 / 204 | 2 (1) / 2 / 2, 3 | 1695 / 8715 | +| 30 | farmers back, shielded (3 hits blocked) | 511 / 461 / 51 / 50 | 2 / 7 / 20 / 16 (40) | 0 / 0 / 0 | 0 / 0 / 397 | 2/3 | Sticky tar III | 0 / 6 / 173 / 218 | 1 (0) / 1 / 1, 3 | 929 / 6980 | + +### Seed 3 + +| Night | Result | Planned / arrived / waited / dropped | Peak c / t / b / u (all) | Lost c / a / s | Left c / a / s | HP | Bought | Banked w / s / st / g | Built (rebuilt) / broken / repaired, standing | Tick avg / max | +|---|---|---|---|---|---|---|---|---|---|---| +| 1 | ok | 11 / 11 / 0 / 0 | 3 / 0 / 0 / 0 (3) | 0 / 0 / 0 | 30 / 8 / 24 | 3/3 | Corn shooter | 1 / 1 / 22 / 0 | 3 (0) / 0 / 0, 4 | 425 / 7580 | +| 2 | ok | 112 / 112 / 0 / 0 | 14 / 11 / 0 / 0 (17) | 0 / 3 / 15 | 33 / 5 / 31 | 3/3 | | 1 / 2 / 23 / 7 | 5 (0) / 0 / 0, 9 | 538 / 11554 | +| 3 | ok | 91 / 91 / 0 / 0 | 17 / 11 / 7 / 0 (20) | 12 / 3 / 0 | 21 / 2 / 63 | 3/3 | | 0 / 5 / 39 / 19 | 5 (0) / 8 / 1, 6 | 800 / 9017 | +| 4 | ok | 133 / 133 / 0 / 0 | 18 / 9 / 7 / 0 (28) | 0 / 1 / 0 | 21 / 1 / 116 | 3/3 | | 5 / 20 / 59 / 32 | 1 (0) / 4 / 0, 3 | 778 / 6146 | +| 5 | ok | 168 / 168 / 0 / 0 | 22 / 8 / 13 / 7 (29) | 19 / 1 / 5 | 2 / 0 / 90 | 3/3 | Heavy seeds I, Pumpkin bombs | 1 / 3 / 50 / 36 | 2 (1) / 2 / 2, 3 | 857 / 6069 | +| 6 | ok | 182 / 182 / 0 / 0 | 3 / 7 / 7 / 10 (18) | 1 / 0 / 10 | 1 / 0 / 69 | 3/3 | Quick fear I, Sticky tar I | 0 / 2 / 33 / 35 | 1 (0) / 1 / 1, 3 | 781 / 6237 | +| 7 | ok | 189 / 189 / 0 / 0 | 2 / 7 / 19 / 9 (21) | 0 / 0 / 0 | 1 / 0 / 100 | 3/3 | | 0 / 12 / 49 / 42 | 2 (1) / 2 / 1, 3 | 785 / 8189 | +| 8 | ok | 203 / 203 / 0 / 0 | 2 / 7 / 13 / 13 (21) | 1 / 0 / 0 | 0 / 0 / 147 | 3/3 | | 0 / 27 / 69 / 51 | 1 (0) / 1 / 1, 3 | 882 / 6630 | +| 9 | ok | 210 / 210 / 0 / 0 | 1 / 7 / 14 / 12 (23) | 0 / 0 / 5 | 0 / 0 / 165 | 3/3 | | 0 / 28 / 80 / 57 | 3 (2) / 3 / 1, 3 | 954 / 6241 | +| 10 | ok | 294 / 294 / 0 / 0 | 2 / 7 / 13 / 18 (37) | 0 / 0 / 0 | 0 / 0 / 191 | 3/3 | | 0 / 30 / 94 / 67 | 3 (2) / 3 / 1, 3 | 933 / 8119 | +| 11 | ok | 231 / 231 / 5 / 0 | 1 / 8 / 20 / 7 (25) | 0 / 0 / 0 | 0 / 0 / 217 | 3/3 | | 0 / 31 / 110 / 79 | 3 (2) / 3 / 1, 3 | 1015 / 8001 | +| 12 | ok | 245 / 245 / 1 / 0 | 1 / 7 / 20 / 14 (31) | 0 / 0 / 5 | 0 / 0 / 257 | 3/3 | | 0 / 47 / 125 / 85 | 1 (0) / 1 / 1, 3 | 1014 / 6036 | +| 13 | ok | 252 / 252 / 13 / 0 | 1 / 7 / 20 / 7 (27) | 0 / 0 / 0 | 0 / 0 / 281 | 3/3 | | 0 / 47 / 139 / 95 | 3 (2) / 3 / 1, 3 | 1088 / 7736 | +| 14 | ok | 266 / 266 / 1 / 0 | 1 / 7 / 20 / 8 (27) | 0 / 0 / 10 | 0 / 0 / 295 | 3/3 | | 0 / 48 / 145 / 102 | 3 (2) / 3 / 1, 3 | 1009 / 6455 | +| 15 | ok | 364 / 364 / 0 / 0 | 1 / 7 / 18 / 10 (29) | 0 / 0 / 5 | 0 / 0 / 332 | 3/3 | | 1 / 55 / 158 / 118 | 2 (1) / 2 / 2, 3 | 1360 / 8606 | +| 16 | ok | 287 / 273 / 14 / 14 | 1 / 7 / 20 / 15 (42) | 0 / 0 / 5 | 0 / 0 / 252 | 3/3 | Heavy seeds II, Quick fear II, Sticky tar II | 0 / 18 / 105 / 129 | 1 (0) / 1 / 1, 3 | 723 / 5974 | +| 17 | ok | 301 / 301 / 0 / 0 | 1 / 8 / 14 / 14 (27) | 0 / 0 / 0 | 0 / 0 / 279 | 2/3 | | 0 / 18 / 121 / 141 | 3 (2) / 3 / 1, 3 | 1433 / 6597 | +| 18 | ok | 308 / 308 / 12 / 0 | 1 / 7 / 20 / 8 (27) | 0 / 0 / 10 | 0 / 0 / 307 | 2/3 | | 1 / 22 / 139 / 145 | 2 (1) / 2 / 2, 3 | 1217 / 6318 | +| 19 | ok | 322 / 293 / 31 / 29 | 1 / 7 / 20 / 17 (42) | 0 / 0 / 10 | 0 / 0 / 267 | 2/3 | Quick fear III | 0 / 13 / 107 / 150 | 1 (0) / 1 / 1, 3 | 782 / 8484 | +| 20 | ok | 427 / 419 / 27 / 8 | 1 / 7 / 20 / 13 (39) | 0 / 0 / 5 | 0 / 0 / 317 | 3/3 | | 0 / 29 / 125 / 163 | 1 (0) / 1 / 1, 3 | 1320 / 6406 | +| 21 | scarecrow destroyed 18 s in | 343 / 50 / 0 / 0 | 1 / 7 / 14 / 0 (21) | 0 / 0 / 0 | 0 / 0 / 333 | 0/3 | | 0 / 29 / 141 / 153 | 3 (2) / 0 / 1, 6 | 603 / 3610 | +| 21 | ok, retry 1 | 343 / 320 / 27 / 23 | 1 / 7 / 20 / 13 (37) | 0 / 0 / 25 | 0 / 0 / 266 | 3/3 | Sticky tar III | 0 / 17 / 99 / 150 | 1 (0) / 1 / 2, 3 | 861 / 5705 | +| 22 | ok | 357 / 357 / 12 / 0 | 1 / 7 / 20 / 13 (36) | 0 / 0 / 0 | 0 / 0 / 297 | 2/3 | | 1 / 20 / 115 / 161 | 3 (2) / 3 / 0, 3 | 1031 / 6041 | +| 23 | scarecrow destroyed 52 s in | 364 / 137 / 0 / 0 | 1 / 7 / 13 / 0 (19) | 0 / 0 / 0 | 0 / 0 / 336 | 0/3 | | 0 / 31 / 135 / 170 | 1 (0) / 1 / 1, 3 | 771 / 5870 | +| 23 | ok, retry 1 | 364 / 364 / 2 / 0 | 1 / 8 / 20 / 10 (33) | 0 / 0 / 50 | 0 / 0 / 280 | 3/3 | | 0 / 31 / 129 / 120 | 1 (0) / 1 / 1, 3 | 1026 / 5581 | +| 24 | scarecrow destroyed 76 s in | 378 / 188 / 0 / 0 | 1 / 7 / 18 / 10 (31) | 0 / 0 / 0 | 0 / 0 / 309 | 0/3 | | 1 / 37 / 137 / 126 | 2 (1) / 2 / 2, 3 | 1527 / 5882 | +| 24 | ok, retry 1 | 378 / 378 / 20 / 0 | 1 / 7 / 20 / 10 (33) | 0 / 0 / 5 | 0 / 0 / 315 | 2/3 | | 0 / 40 / 144 / 131 | 1 (0) / 1 / 2, 3 | 1212 / 6417 | +| 25 | ok | 504 / 504 / 15 / 0 | 1 / 7 / 20 / 10 (36) | 0 / 0 / 0 | 0 / 0 / 346 | 3/3 | | 1 / 45 / 158 / 143 | 2 (1) / 2 / 2, 3 | 1569 / 6322 | +| 26 | ok | 399 / 355 / 45 / 44 | 1 / 7 / 20 / 12 (38) | 0 / 0 / 0 | 0 / 0 / 319 | 3/3 | Heavy seeds III | 0 / 8 / 145 / 166 | 1 (0) / 1 / 1, 3 | 875 / 6112 | +| 27 | ok | 406 / 406 / 22 / 0 | 1 / 7 / 20 / 12 (27) | 0 / 0 / 5 | 0 / 0 / 354 | 2/3 | | 1 / 13 / 163 / 177 | 2 (1) / 2 / 2, 3 | 1314 / 7632 | +| 28 | scarecrow destroyed 72 s in | 420 / 209 / 0 / 0 | 1 / 7 / 14 / 12 (31) | 0 / 0 / 0 | 0 / 0 / 393 | 0/3 | | 1 / 23 / 181 / 191 | 1 (0) / 1 / 2, 3 | 1376 / 6287 | +| 28 | ok, retry 1 | 420 / 420 / 6 / 0 | 1 / 7 / 20 / 12 (36) | 0 / 0 / 5 | 0 / 0 / 383 | 2/3 | | 0 / 17 / 181 / 185 | 2 (1) / 2 / 2, 3 | 1641 / 6246 | +| 29 | scarecrow destroyed 113 s in | 427 / 331 / 13 / 6 | 1 / 7 / 20 / 9 (35) | 0 / 0 / 0 | 0 / 0 / 413 | 0/3 | | 0 / 17 / 197 / 199 | 3 (2) / 3 / 1, 3 | 1730 / 8058 | +| 29 | ok, retry 1 | 427 / 427 / 12 / 0 | 1 / 7 / 20 / 10 (34) | 0 / 0 / 5 | 0 / 0 / 407 | 2/3 | | 0 / 17 / 192 / 198 | 3 (2) / 3 / 1, 3 | 1455 / 6446 | +| 30 | scarecrow destroyed 81 s in | 511 / 254 / 7 / 0 | 1 / 7 / 20 / 8 (35) | 0 / 0 / 0 | 0 / 0 / 436 | 0/3 | | 1 / 22 / 185 / 203 | 2 (1) / 2 / 2, 3 | 1374 / 8102 | +| 30 | farmers back, retry 1 | 511 / 498 / 27 / 13 | 2 / 8 / 20 / 13 (39) | 0 / 0 / 10 | 0 / 0 / 435 | 3/3 | | 0 / 25 / 200 / 210 | 1 (0) / 1 / 2, 3 | 999 / 6933 | diff --git a/game/tests/test_nights.gd b/game/tests/test_nights.gd index 872b4a7..458045a 100644 --- a/game/tests/test_nights.gd +++ b/game/tests/test_nights.gd @@ -6,8 +6,9 @@ extends RefCounted ## the upgrades apply to the systems they change and persist (next morning, JSON, retry), the plans ## load by count with each night's enemy speed and HP scales, the debug F3 jump moves the morning, ## and a sample of the nights (1-5, a siege, the last) plays back to back to the farmers' return, -## the rest skipped by the F3 morning path, each with its own plan and morning snapshot, -## everything carrying over. +## the rest skipped by the F3 morning path, each with its own plan and morning snapshot, every +## planned arrival accounted for (arrived, or dropped at sunrise with its pool full), everything +## carrying over. const P := CampaignController.Phase const T := ThiefBehavior.State @@ -420,9 +421,11 @@ func _night_jump(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void: ## The vacation back to back to the farmers' return: the PLAYED nights (1-5, a siege, the last), -## each with its own plan and morning snapshot and its arrivals as planned; the nights between are -## skipped on F3's morning path (CampaignDebug.jump_morning: the next morning, the farm as it is). -## The farm is defended, and the scarecrow kept out of harm. +## each with its own plan and morning snapshot; the nights between are skipped on F3's morning path +## (CampaignDebug.jump_morning: the next morning, the farm as it is). The farm is defended, and the +## scarecrow kept out of harm. Every planned arrival arrives, or waits for a free character and is +## dropped at sunrise (#25), and nothing vanishes: here no scarecrow fights and few breakers die or +## leave, so the breakers past their pool's 20 wait all night. func _back_to_back(r: GameTestRunner, farm: Node3D, sim: FarmSim, player: PlayerCharacter) -> void: var c := sim.campaign var hud := farm.get_node("Hud/PhaseHud") as PhaseHud @@ -439,6 +442,19 @@ func _back_to_back(r: GameTestRunner, farm: Node3D, sim: FarmSim, player: Player sim.waves.arrived.connect(func(h: int, _at: Vector2) -> void: var t: int = sim.enemies.type[sim.enemies.resolve_handle(h)] arrivals[t] = int(arrivals.get(t, 0)) + 1) + # Each ground type's character pool as the night ends (#25: arrivals still waiting for a free + # character are dropped then): full, or full at the end of the night's last tick before it + # (a character can come free in the very tick the night ends, after the arrivals were looked at). + var full_at_end := {} + var full_last_tick := {} + var ground: Array[int] = [] + for t in EnemySystem.TYPE_NAMES.size(): + if sim.enemies.t_flying[t] == 0: + ground.append(t) + sim.campaign.phase_changed.connect(func(phase: CampaignController.Phase, previous: CampaignController.Phase) -> void: + if previous == P.NIGHT and phase != P.NIGHT: + for t in ground: + full_at_end[t] = not sim.characters.has_free(t)) var broken: Array[int] = [] sim.structures.destroyed.connect(func(id: int, _t: String, _at: Vector3) -> void: broken.append(id)) var all_good := true @@ -465,16 +481,44 @@ func _back_to_back(r: GameTestRunner, farm: Node3D, sim: FarmSim, player: Player var plan := sim.waves.plan_for(night) var title_ok := hud._banner.text == "Night %d: %s" % [night, plan.title] arrivals.clear() + full_at_end.clear() + full_last_tick.clear() + var skipped0 := sim.enemies.spawn_skipped var structures_at_night := c.state.structures.size() broken.clear() var t_night := Time.get_ticks_msec() while c.state.phase != P.MORNING and not c.is_over(): sim.scarecrow.invulnerable_left = 1.0 sim.step(DT) + if c.state.phase == P.NIGHT and c.state.phase_time_left <= 2.0 * DT: # the night's last ticks + for t in ground: + full_last_tick[t] = not sim.characters.has_free(t) + # Every planned arrival arrived or, its type's characters all in use when the night ended, + # was still waiting for one and dropped at sunrise (#25); none vanished (spawn_skipped). var expect := plan.type_counts(plan.count_scale_in(c.config)) - r.check(arrivals == expect and title_ok, "night %d, '%s': the plan's %s arrived %s" % [night, plan.title, expect, arrivals]) + var dropped := {} + var accounted := sim.enemies.spawn_skipped == skipped0 + for t in expect: + var gone := int(expect[t]) - int(arrivals.get(t, 0)) + accounted = accounted and gone >= 0 + if gone > 0: + dropped[t] = gone + accounted = accounted and ground.has(t) and (bool(full_at_end.get(t, false)) or bool(full_last_tick.get(t, false))) + for t in arrivals: + accounted = accounted and expect.has(t) + var dropped_total := 0 + for t in dropped: + dropped_total += int(dropped[t]) + accounted = accounted and dropped_total == sim.waves.dropped + r.check(accounted and title_ok, "night %d, '%s': the plan's %s arrived %s, %s dropped at sunrise with every character of the type in use (%d skipped)" % [ + night, plan.title, expect, arrivals, dropped, sim.enemies.spawn_skipped - skipped0]) var e: Dictionary = c.state.night_log[c.state.night_log.size() - 1] - r.info("night %d: %d crops, %d animals, %d supplies lost; %d structures broken (%.1f s)" % [night, e["crops_lost"], + var dropped_names := PackedStringArray() + for t in dropped: + dropped_names.append("%d %s" % [dropped[t], EnemySystem.TYPE_NAMES[t]]) + r.info("night %d: %d of %d arrived, %d dropped%s; %d crops, %d animals, %d supplies lost; %d structures broken (%.1f s)" % [ + night, sim.waves.spawned, plan.total(plan.count_scale_in(c.config)), dropped_total, + " (%s)" % ", ".join(dropped_names) if not dropped_names.is_empty() else "", e["crops_lost"], e["animals_lost"], e["supplies_lost"], broken.size(), (Time.get_ticks_msec() - t_night) / 1000.0]) if night < nights: all_good = all_good and c.state.structures.size() == structures_at_night - broken.size() and c.state.supplies_in_transit == 0 diff --git a/game/tools/soak_night.gd b/game/tools/soak_night.gd index c042d6a..77f21d6 100644 --- a/game/tools/soak_night.gd +++ b/game/tools/soak_night.gd @@ -5,14 +5,41 @@ extends SceneTree ## godot --headless --path . --script res://game/tools/soak_night.gd -- --mode=guard ## Options: ## --mode=cycle plays whole cycles: by day it gathers until GATHER_UNTIL, then puts a -## gate back in the pen opening if it's gone and builds BUILD_PLAN in order -## (what it can afford, walking to each site), and at night it guards (as -## --mode=guard) against the night's plan. Reports each cycle (per target) -## and checks that structures, materials, and health carry over. -## --cycles=3 sets how many (5 plays the whole vacation, one night plan +## gate back in the pen opening if it's gone, buys the corn shooter as soon +## as it can, repairs damaged structures it can pay for, and builds +## BUILD_PLAN in order (what it can afford, walking to each site; a site +## whose structure was broken is built again), and at night it guards (as +## --mode=guard) against the night's plan. Reports each night: arrivals +## (planned / arrived / waited / dropped, from +## WaveDirector), the peak alive per type, losses per category, the +## scarecrow's HP at dawn, upgrade levels, materials banked, and the sim +## tick (FarmSim.step, night and dawn: average, 99th percentile, max), as +## a table and as one "ROW {json}" line per night for scripts. Checks that +## structures (the Workbench granted after night 1 aside) and materials +## carry over, and that no supplies are left in transit. +## --cycles=3 sets how many (30 plays the whole vacation, one night plan ## each); --build=0 skips building, --guard=0 leaves the night to the ## defenses. With materials left after the plan it buys upgrade levels -## (UPGRADE_ORDER) at the workbench; --upgrades=0 skips them. +## (UPGRADE_ORDER) at the workbench; --upgrades=0 skips them; --gather=0 +## skips gathering. +## A lost night (game over) is reported, then retried from its morning +## (--retries=1 times). If the scarecrow still falls, the soak carries on +## with the scarecrow shielded (it takes no hits) from that night on, so +## the later nights are still measured (--shield=after, the default); +## --shield=off stops there instead, --shield=always shields it from the +## start. A farm stripped bare stops the soak once the retries are used. +## Measuring: --start=20 skips to day 20 first (CampaignDebug's F3 path: +## the farm as it is), --load= starts from a saved morning instead +## (as written by --save-at=20,30 --save-dir=: those mornings are +## saved as /night_.json), --stock=200 adds that much wood, scrap, +## and straw to the shed on the first morning, and --frame=1 also times +## the enemy characters' per-frame update and animation (EnemyCharacters +## and its AnimationPlayers, CPU only: headless draws nothing). +## --count-scale=4 plays the nights at another GameConfig.wave_count_scale +## (every plan without its own count_scale: nights 2-30), and +## --plan-scale=2:3,3:4 gives nights their own count_scale (in memory only). +## --pool=thief:64,breaker:28 overrides GameConfig.character_pool (any mode), set before the +## farm loads. ## --mode=gather plays one day instead: the scarecrow walks (along the navigation ## grid) to the nearest gather point with charges, holds interact until it ## is used up or the pouch is full, stores the pouch at the shed, and @@ -79,6 +106,9 @@ func _run() -> void: thieves = int(arg.trim_prefix("--thieves=")) elif arg.begins_with("--seed="): seed_value = int(arg.trim_prefix("--seed=")) + elif arg.begins_with("--pool="): + _pool_override(arg.trim_prefix("--pool=")) + seed(seed_value) var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D root.add_child(farm) await process_frame @@ -88,6 +118,7 @@ func _run() -> void: _player.set_physics_process(false) var c := _sim.campaign var cfg := _sim.config + var vacation := cfg.campaign_nights cfg.night_thieves = thieves cfg.campaign_nights = 99 _sim.loot._rng.seed = seed_value @@ -99,20 +130,70 @@ func _run() -> void: return if _mode == "cycle": var cycles := 3 - for a in OS.get_cmdline_user_args(): - if String(a).begins_with("--cycles="): - cycles = int(String(a).trim_prefix("--cycles=")) + var start := 1 + var load_path := "" cfg.night_thieves = 0 # the night's plan for a in OS.get_cmdline_user_args(): - if String(a).begins_with("--thieves="): - cfg.night_thieves = int(String(a).trim_prefix("--thieves=")) - for a in OS.get_cmdline_user_args(): - if String(a) == "--build=0": + var arg := String(a) + if arg.begins_with("--cycles="): + cycles = int(arg.trim_prefix("--cycles=")) + elif arg.begins_with("--thieves="): + cfg.night_thieves = int(arg.trim_prefix("--thieves=")) + elif arg == "--build=0": _do_build = false - elif String(a) == "--guard=0": + elif arg == "--guard=0": _do_guard = false - elif String(a) == "--upgrades=0": + elif arg == "--upgrades=0": _do_upgrades = false + elif arg == "--gather=0": + _do_gather = false + elif arg == "--frame=1": + _time_frame = true + elif arg.begins_with("--retries="): + _retries = maxi(int(arg.trim_prefix("--retries=")), 0) + elif arg.begins_with("--shield="): + _shield_mode = arg.trim_prefix("--shield=") + elif arg.begins_with("--start="): + start = maxi(int(arg.trim_prefix("--start=")), 1) + elif arg.begins_with("--load="): + load_path = arg.trim_prefix("--load=") + elif arg.begins_with("--stock="): + _stock = maxi(int(arg.trim_prefix("--stock=")), 0) + elif arg.begins_with("--count-scale="): + cfg.wave_count_scale = float(arg.trim_prefix("--count-scale=")) + elif arg.begins_with("--plan-scale="): + for part in arg.trim_prefix("--plan-scale=").split(",", false): + var kv := part.split(":") + if kv.size() == 2 and _sim.waves.plan_for(int(kv[0])) != null: + _sim.waves.plan_for(int(kv[0])).count_scale = float(kv[1]) + elif arg.begins_with("--save-dir="): + _save_dir = arg.trim_prefix("--save-dir=") + elif arg.begins_with("--save-at="): + for x in arg.trim_prefix("--save-at=").split(",", false): + _save_at.append(int(x)) + if not _shield_mode in ["after", "off", "always"]: + push_error("soak: --shield is after, off, or always (not '%s')" % _shield_mode) + _quit() + return + _shielded = _shield_mode == "always" + if load_path != "": + var saved := SaveGame.read(load_path) + if saved.status != SaveGame.Status.OK: + push_error("soak: can't load %s: %s" % [load_path, saved.message]) + _quit() + return + c.load_state(saved.state) + var debug := farm.get_node("CampaignDebug") as CampaignDebug + while c.state.night < start: + if not debug.jump_morning(1): + push_error("soak: can't skip to day %d (debug builds only)" % start) + _quit() + return + # The vacation ends after its last night (the farmers' return) unless more are asked for. + cfg.campaign_nights = maxi(vacation, c.state.night + cycles - 1) + print("soak cycle: seed %d, character pool %s (thieves %d, breakers %d), wave_count_scale %.2f" % [seed_value, + cfg.character_pool, _sim.characters.pool_size(EnemySystem.TYPE_THIEF), _sim.characters.pool_size(EnemySystem.TYPE_BREAKER), + cfg.wave_count_scale]) _cycles(cycles) _quit() return @@ -155,38 +236,81 @@ func _quit() -> void: var _fields := {} -var _built := {} # BUILD_PLAN index -> true +var _skip := {} # BUILD_PLAN index -> true: it can't go at its site today +var _skip_told := {} # BUILD_PLAN index -> true: said so once +var _ever_built := {} # BUILD_PLAN index -> true once built (building it again is a rebuild) var _do_build := true var _do_guard := true var _do_upgrades := true +var _do_gather := true +var _time_frame := false +var _retries := 1 +var _shield_mode := "after" +var _shielded := false +var _stock := 0 +var _save_at: Array[int] = [] +var _save_dir := "" var _carry_errors: Array[String] = [] +## Upgrade levels bought: [day, id, level]. +var _buys: Array = [] +var _rebuilt: int = 0 +## --pool's edited GameConfig, held so the resource cache hands this one to the farm. +var _config_keep: GameConfig + + +## --pool=thief:64,breaker:28: GameConfig.character_pool for the farm about to load (the +## characters are made when it loads). +func _pool_override(spec: String) -> void: + _config_keep = load("res://game/resources/game_config.tres") as GameConfig + var pool := _config_keep.character_pool.duplicate() + for part in spec.split(",", false): + var kv := part.split(":") + if kv.size() == 2: + pool[kv[0].strip_edges()] = int(kv[1]) + _config_keep.character_pool = pool func _cycles(n: int) -> void: var c := _sim.campaign - var s := c.state - print("soak cycle: %d cycles, night plan '%s' (%d thieves), gather until %.0f s, build %s, guard %s" % [ - n, _sim.waves.tonight().title, _sim.waves.tonight().total(), GATHER_UNTIL, _do_build, _do_guard]) - print("| Night | Gathered | Built (total) | Upgrades | Crops: stolen / recovered / lost | Animals: grabbed / out / led back / lost | Supplies: taken / back / lost | Left | HP | Broken | Shed after |") - print("|---|---|---|---|---|---|---|---|---|---|") + var cfg := _sim.config + print("soak cycle: %d cycles from night %d; gather %s (until %.0f s), build %s, upgrades %s, guard %s; retries %d, shield %s, stock %d" % [ + n, c.state.night, _do_gather, GATHER_UNTIL, _do_build, _do_upgrades, _do_guard, _retries, _shield_mode, _stock]) + print("| Night | Result | Arrivals: planned / arrived / waited / dropped | Peak alive: crows / thieves / breakers / UFOs (all) | Lost: crops / animals / supplies | Left: crops / animals / supplies | HP at dawn | Levels (bought today) | Banked: wood / scrap / straw / goop | Built / broken / repaired (standing) | Tick avg / p99 / max (us) |") + print("|---|---|---|---|---|---|---|---|---|---|---|") var lost_by := {} _sim.loot.loot_event.connect(func(kind: StringName, id: int, _p: Vector3) -> void: if kind == &"lost" and _sim.loot.category[id] == LootSystem.Category.SUPPLY: lost_by[_sim.loot.sack_material[id]] = int(lost_by.get(_sim.loot.sack_material[id], 0)) + _sim.loot.sack_amount[id]) + var all_ticks := PackedInt32Array() + var lost_nights: Array[String] = [] var t0 := Time.get_ticks_msec() - for k in n: - if c.is_over(): - break - var shed0: Dictionary = s.resources.shed.duplicate() - var built0 := _sim.structures.count() + var played := 0 + var attempt := 0 + var stop := "" + while played < n: + var s := c.state + var night := s.night + if played == 0 and attempt == 0 and _stock > 0: + for m in ["wood", "scrap", "straw"]: + s.resources.shed[m] = int(s.resources.shed[m]) + _stock + c._morning_snapshot = s.to_dict() # so a retry keeps it + if attempt == 0 and _save_at.has(night) and _save_dir != "": + var path := _save_dir.path_join("night_%d.json" % night) + print("soak: the morning of night %d saved to %s (%s)" % [night, path, error_string(SaveGame.write(c.morning_snapshot(), path))]) + var ever_built0 := _ever_built.duplicate() + var buys0 := _buys.size() + _skip.clear() + _fields.clear() # the structures may have changed overnight + _rebuilt = 0 var gathered := {"wood": 0, "scrap": 0, "straw": 0} var cb := func(m: String, amount: int, _node: GatherNode) -> void: gathered[m] += amount _sim.interactions.gathered.connect(cb) + var w0 := Time.get_ticks_msec() c.begin_day() var t := 0.0 while c.is_daytime(): var me := Vector2(_player.global_position.x, _player.global_position.z) - if not (t < GATHER_UNTIL and _gather_tick(me)): + if not (_do_gather and t < GATHER_UNTIL and _gather_tick(me)): Input.action_release("interact") if _do_build: _build_tick(me) @@ -196,49 +320,240 @@ func _cycles(n: int) -> void: t += DT Input.action_release("interact") _sim.interactions.gathered.disconnect(cb) - # Night: guard. Record what should carry over. + # Night: guard, and measure. Record what should carry over. + var plan := _sim.waves.tonight() + var planned: Dictionary = plan.type_counts(plan.count_scale_in(cfg)) if plan != null else {} + var arrived := {} + var cb_in := func(h: int, _at: Vector2) -> void: + var d := _sim.enemies.resolve_handle(h) + if d >= 0: + arrived[int(_sim.enemies.type[d])] = int(arrived.get(int(_sim.enemies.type[d]), 0)) + 1 + _sim.waves.arrived.connect(cb_in) var breaks: Array[int] = [] # a lambda can't add to a captured int var cb2 := func(_i: int, _t: String, _at: Vector3) -> void: breaks.append(1) _sim.structures.destroyed.connect(cb2) var built_night := _sim.structures.count() + var had_workbench := _sim.structures.has_workbench() var res_night: Dictionary = s.resources.to_dict() + var blocked0 := _sim.scarecrow.rejected_hits lost_by.clear() - var fears0 := _fears + var ticks := PackedInt32Array() + var frames := PackedInt32Array() + var peak := [0, 0, 0, 0, 0] # per type (EnemySystem.TYPE_NAMES), then all + var waited_by := [0, 0, 0, 0] + var seen := [[null, 0], [null, 0], [null, 0], [null, 0]] + var waiting_peak := 0 + var night_t := 0.0 if not _do_guard: _player.global_position = Vector3(HOME.x, 0.0, HOME.y) while s.phase != CampaignController.Phase.MORNING and not c.is_over(): if _do_guard: _guard() + if _shielded: + _sim.scarecrow.invulnerable_left = 1.0 + var u0 := Time.get_ticks_usec() _sim.step(DT) + ticks.append(Time.get_ticks_usec() - u0) + if _time_frame: + var f0 := Time.get_ticks_usec() + _sim.characters._process(DT) + for anim: AnimationPlayer in _sim.characters._anims: + if anim.is_playing(): + anim.advance(DT) + frames.append(Time.get_ticks_usec() - f0) + if s.phase == CampaignController.Phase.NIGHT: + night_t += DT + _count_waits(waited_by, seen) + waiting_peak = maxi(waiting_peak, _sim.waves.waiting()) + if ticks.size() % 2 == 0: + _peaks(peak) + _sim.waves.arrived.disconnect(cb_in) _sim.structures.destroyed.disconnect(cb2) var broken := breaks.size() Input.action_release("patch") - if c.is_over(): - print("| %d | campaign over: %s |" % [k + 1, CampaignController.Outcome.keys()[c.outcome]]) - break - # Carry-over checks: nothing is built at night, so structures only go down by breaks; - # wood and scrap only go down by what thieves carried off (straw also by patches). - if _sim.structures.count() != built_night - broken: - _carry_errors.append("cycle %d: %d structures at night - %d broken != %d in the morning" % [k + 1, built_night, broken, _sim.structures.count()]) - var now := s.resources.to_dict() + all_ticks.append_array(ticks) + var over := c.is_over() + # The night's record: the log entry once the dawn grace is over, else (it was lost before) + # the counts so far. + var logged := not s.night_log.is_empty() and int(s.night_log[s.night_log.size() - 1]["night"]) == night + var e: Dictionary + if logged: + e = s.night_log[s.night_log.size() - 1] + else: + e = s.night_events.duplicate() + var now := s.asset_counts() + e["crops_lost"] = maxi(c._night_start[0] - now[0], 0) if c._night_start.size() == 3 else 0 + e["animals_lost"] = maxi(c._night_start[1] - now[1], 0) if c._night_start.size() == 3 else 0 + var result := "ok" + var lost := over and c.outcome != CampaignController.Outcome.VACATION_COMPLETE + if over: + match c.outcome: + CampaignController.Outcome.VACATION_COMPLETE: + result = "farmers back" + CampaignController.Outcome.GAME_OVER_SCARECROW: + result = "scarecrow destroyed %.0f s in" % night_t + CampaignController.Outcome.GAME_OVER_STRIPPED: + result = "farm stripped %.0f s in" % night_t + if _shielded: + result += ", shielded (%d hits blocked)" % (_sim.scarecrow.rejected_hits - blocked0) + if attempt > 0: + result += ", retry %d" % attempt + var bought: Array[String] = [] + for i in range(buys0, _buys.size()): + bought.append(Upgrades.name_at(cfg, _buys[i][1], _buys[i][2])) + var banked := {} + var res_now: Dictionary = s.resources.to_dict() + for m in ResourceStore.MATERIALS: + banked[m] = int(res_now["shed"].get(m, 0)) + for key in ResourceStore.POUCH_KEYS: + banked[m] += int(res_now[key].get(m, 0)) + var tick := _stats(ticks) + var frame := _stats(frames) + var hidden_animating := 0 # pool characters hidden (free) but still playing a clip + for i in _sim.characters._anims.size(): + if _sim.characters._anims[i].is_playing() and not _sim.characters._roots[i].visible: + hidden_animating += 1 + var row := { + "night": night, "title": plan.title if plan != null else "", "attempt": attempt + 1, "result": result, + "lost_night": lost, "shielded": _shielded, "night_time": snappedf(night_t, 0.1), + "planned": _sum(planned), "arrived": _sum(arrived), "waited": _sim.waves.waited, "dropped": _sim.waves.dropped, + "planned_by": _by_type(planned), "arrived_by": _by_type(arrived), "waited_by": waited_by, "waiting_peak": waiting_peak, + "peak_by": peak.slice(0, 4), "peak": peak[4], + "stolen": [int(e.get("crops_stolen", 0)), int(e.get("animals_stolen", 0)), int(e.get("supplies_stolen", 0))], + "lost": [int(e.get("crops_lost", 0)), int(e.get("animals_lost", 0)), int(e.get("supplies_lost", 0))], + "left": [s.crops, s.animals, s.supplies], "totals": [s.crops_total, s.animals_total, s.supplies_total], + "hp": s.scarecrow_hp, "max_hp": s.scarecrow_max_hp, "damage": int(e.get("scarecrow_damage", 0)), + "patches": int(e.get("patches", 0)), + "levels": Upgrades.levels_bought(cfg, s), "levels_total": Upgrades.levels_total(cfg), "bought": bought, + "banked": banked, "gathered": gathered, + "built": int(e.get("structures_built", 0)), "rebuilt": _rebuilt, "broken": broken, + "repairs": int(e.get("repairs", 0)), "standing": _sim.structures.count(), + "kills_by": [int(e.get("killed_thief", 0)), int(e.get("killed_crow", 0)), int(e.get("killed_breaker", 0)), int(e.get("killed_ufo", 0))], + "tick_avg": tick[0], "tick_p99": tick[1], "tick_max": tick[2], "ticks": ticks.size(), + "frame_avg": frame[0], "frame_p99": frame[1], "frame_max": frame[2], "hidden_animating": hidden_animating, + "pool": [_sim.characters.pool_size(EnemySystem.TYPE_THIEF), _sim.characters.pool_size(EnemySystem.TYPE_BREAKER)], + "wall": (Time.get_ticks_msec() - w0) / 1000.0, + } + var dropped_by := "" + if row["dropped"] > 0: + var parts: Array[String] = [] + for ty in EnemySystem.TYPE_NAMES.size(): + var gone: int = row["planned_by"][ty] - row["arrived_by"][ty] + if gone > 0 and not lost: + parts.append("%d %s" % [gone, EnemySystem.TYPE_NAMES[ty]]) + dropped_by = " (%s)" % ", ".join(parts) if not parts.is_empty() else "" + var pk: Array = row["peak_by"] + print("| %d %s | %s | %d / %d / %d / %d%s | %d / %d / %d / %d (%d) | %d / %d / %d | %d / %d / %d | %d/%d | %d of %d%s | %d / %d / %d / %d | %d (%d rebuilt) / %d / %d (%d) | %.0f / %d / %d |" % [ + night, row["title"], result, row["planned"], row["arrived"], row["waited"], row["dropped"], dropped_by, + pk[1], pk[0], pk[2], pk[3], row["peak"], row["lost"][0], row["lost"][1], row["lost"][2], + s.crops, s.animals, s.supplies, s.scarecrow_hp, s.scarecrow_max_hp, + row["levels"], row["levels_total"], (": " + ", ".join(bought)) if not bought.is_empty() else "", + banked["wood"], banked["scrap"], banked["straw"], banked["alien_goop"], + row["built"], _rebuilt, broken, row["repairs"], row["standing"], tick[0], tick[1], tick[2]]) + print("ROW " + JSON.stringify(row)) + if lost: + lost_nights.append("night %d, attempt %d: %s" % [night, attempt + 1, result]) + attempt += 1 + var again := attempt <= _retries + if not again and c.outcome == CampaignController.Outcome.GAME_OVER_SCARECROW and _shield_mode == "after" and not _shielded: + _shielded = true + again = true + print("soak: the scarecrow fell on night %d %d times; from here on it's shielded (it takes no hits)" % [night, attempt]) + if not again: + stop = "night %d lost: %s" % [night, result] + break + _ever_built = ever_built0 + _buys.resize(buys0) + c.retry_night() + continue + played += 1 + attempt = 0 + if over: + break # the farmers are back + # Carry-over checks: nothing is built at night, so structures only go down by breaks (and + # up by the Workbench, granted when night 1 ends); wood and scrap only go down by what + # thieves carried off (straw also by patches). + var granted := 1 if not had_workbench and _sim.structures.has_workbench() else 0 + if _sim.structures.count() != built_night - broken + granted: + _carry_errors.append("night %d: %d structures at night - %d broken + %d granted != %d in the morning" % [night, + built_night, broken, granted, _sim.structures.count()]) for m in ["wood", "scrap"]: var before := int(res_night["shed"][m]) - var after := int(now["shed"][m]) + var after := int(res_now["shed"][m]) for key in ResourceStore.POUCH_KEYS: # every scarecrow's pouch (solo: player 2's stays empty) before += int(res_night[key][m]) - after += int(now[key][m]) + after += int(res_now[key][m]) if after != before - int(lost_by.get(m, 0)): - _carry_errors.append("cycle %d: %s %d -> %d overnight, %d carried off" % [k + 1, m, before, after, int(lost_by.get(m, 0))]) + _carry_errors.append("night %d: %s %d -> %d overnight, %d carried off" % [night, m, before, after, int(lost_by.get(m, 0))]) if s.supplies_in_transit != 0: - _carry_errors.append("cycle %d: %d supplies still in transit in the morning" % [k + 1, s.supplies_in_transit]) - var e: Dictionary = s.night_log[s.night_log.size() - 1] - print("| %d %s | %s | %d (%d) | %d | %d / %d / %d | %d / %d / %d / %d | %d / %d / %d | %d crops, %d animals | %d/%d | %d | %s |" % [k + 1, - _sim.waves.plan_for(k + 1).title, ResourceStore.describe(gathered), built_night - built0, built_night, s.upgrades.size(), - e["crops_stolen"], e["crops_recovered"], e["crops_lost"], - e["animals_stolen"], e["animals_strayed"], e["animals_recovered"], e["animals_lost"], e["supplies_stolen"], e["supplies_recovered"], - e["supplies_lost"], s.crops, s.animals, s.scarecrow_hp, s.scarecrow_max_hp, broken, ResourceStore.describe(s.resources.shed)]) - print("soak cycle: carry-over %s; %.1f s of wall time" % ["OK" if _carry_errors.is_empty() else "ERRORS %s" % [_carry_errors], - (Time.get_ticks_msec() - t0) / 1000.0]) + _carry_errors.append("night %d: %d supplies still in transit in the morning" % [night, s.supplies_in_transit]) + var all := _stats(all_ticks) + print("soak cycle: %d nights played%s; carry-over %s; night tick over all nights avg %.0f / p99 %d / max %d us; %.1f s of wall time" % [ + played, (", stopped: " + stop) if stop != "" else "", "OK" if _carry_errors.is_empty() else "ERRORS %s" % [_carry_errors], + all[0], all[1], all[2], (Time.get_ticks_msec() - t0) / 1000.0]) + print("soak cycle: lost nights: %s" % ("none" if lost_nights.is_empty() else "; ".join(lost_nights))) + var days := {} + for b in _buys: + var key := String(b[1]) + days[key] = days.get(key, []) + [int(b[0])] + var lines: Array[String] = [] + for id in UPGRADE_ORDER: + if days.has(id): + lines.append("%s day %s" % [id, "/".join(PackedStringArray(days[id].map(func(d: int) -> String: return str(d))))]) + print("soak cycle: levels bought (day of each level): %s" % (", ".join(lines) if not lines.is_empty() else "none")) + print("BUYS " + JSON.stringify(_buys)) + + +## Per-type counts as an Array in EnemySystem.TYPE_NAMES order. +static func _by_type(counts: Dictionary) -> Array: + var out := [] + for t in EnemySystem.TYPE_NAMES.size(): + out.append(int(counts.get(t, 0))) + return out + + +static func _sum(counts: Dictionary) -> int: + var n := 0 + for t in counts: + n += int(counts[t]) + return n + + +## [average, 99th percentile, max] of tick times (0s when empty). +static func _stats(us: PackedInt32Array) -> Array: + if us.is_empty(): + return [0.0, 0, 0] + var sorted := us.duplicate() + sorted.sort() + var total := 0 + for u in sorted: + total += u + return [float(total) / sorted.size(), sorted[int(0.99 * (sorted.size() - 1))], sorted[sorted.size() - 1]] + + +## The peak alive so far, per type and in all. +func _peaks(peak: Array) -> void: + var es := _sim.enemies + var by := [0, 0, 0, 0] + for d in es.active_count: + if es.alive[d] == 1: + by[es.type[d]] += 1 + for t in 4: + peak[t] = maxi(peak[t], by[t]) + peak[4] = maxi(peak[4], by[0] + by[1] + by[2] + by[3]) + + +## Counts tonight's arrivals that had to wait, per type: what joined each type's waiting list +## (WaveDirector._waiting) since the last tick. seen[t] is [its first entry, its size] then: the +## same first entry means the same list grew, another one that it emptied and filled again. +func _count_waits(waited_by: Array, seen: Array) -> void: + var w := _sim.waves + for t in w._waiting.size(): + var list: Array = w._waiting[t] + var was: Array = seen[t] + var kept: int = was[1] if not list.is_empty() and int(was[1]) > 0 and is_same(list[0], was[0]) else 0 + waited_by[t] += list.size() - kept + seen[t] = [list[0] if not list.is_empty() else null, list.size()] ## One gathering tick: walk to the nearest point with charges and gather, or store a full pouch. @@ -268,8 +583,12 @@ func _gather_tick(me: Vector2) -> bool: return true -## One building tick: put a gate back in the pen opening if it's gone, else walk to the next -## BUILD_PLAN site it can afford and place it; otherwise wait in the middle of the crop field. +## One building tick: put a gate back in the pen opening if it's gone, else buy the corn shooter +## once it can, else repair the nearest damaged structure it can pay for, else walk to the next +## BUILD_PLAN site with nothing standing +## (never built, or broken since) that it can afford and build it; with nothing to build, buy +## upgrades; otherwise wait in the middle of the crop field. Building, repairing, and buying are +## instant once it's close (no build mode, no hold to repair, no menu). func _build_tick(me: Vector2) -> void: var st := _sim.structures var r := _sim.campaign.state.resources @@ -279,10 +598,14 @@ func _build_tick(me: Vector2) -> void: elif st.validate("gate", PEN_GATE.x, PEN_GATE.y, 2, me) == "": st.place("gate", PEN_GATE.x, PEN_GATE.y, 2) return + if _do_upgrades and not Upgrades.owned(_sim.campaign.state, "corn_shooter") and _upgrade_tick(me, "corn_shooter"): + return # the gun first + if _repair_tick(me): + return for i in BUILD_PLAN.size(): - if _built.has(i): - continue var part: Array = BUILD_PLAN[i] + if _skip.has(i) or _standing(part) >= 0: + continue if not r.can_afford(_sim.config.costs.get(part[0], {})): continue var at: Vector2 = part[1] @@ -292,22 +615,67 @@ func _build_tick(me: Vector2) -> void: var why := st.validate(part[0], at.x, at.y, part[2], me) if why == "": st.place(part[0], at.x, at.y, part[2]) + if _ever_built.has(i): + _rebuilt += 1 + _ever_built[i] = true else: - print("soak: can't build %s at %s: %s" % [part[0], at, why]) - _built[i] = true # built, or impossible here: either way move on + if not _skip_told.has(i): + print("soak: can't build %s at %s: %s" % [part[0], at, why]) + _skip_told[i] = true + _skip[i] = true # not today: move on return if _do_upgrades and _upgrade_tick(me): return _walk_field(Vector2(30.0, -3.0), me) +## The structure standing at a BUILD_PLAN site (its id), or -1. +func _standing(part: Array) -> int: + var at: Vector2 = part[1] + for e in _sim.campaign.state.structures: + if e["type"] == part[0] and Vector2(float(e["x"]), float(e["z"])).distance_to(at) < 0.1: + return int(e["id"]) + return -1 + + +## Walks to the nearest damaged structure it can pay to repair fully, and repairs it. Returns false +## if there's none. +func _repair_tick(me: Vector2) -> bool: + var st := _sim.structures + var r := _sim.campaign.state.resources + var pick := -1 + var at := Vector2.ZERO + var best := INF + for e in _sim.campaign.state.structures: + var cost := st.repair_cost(int(e["id"])) + if cost.is_empty() or not r.can_afford(cost): + continue + var p := Vector2(float(e["x"]), float(e["z"])) + if p.distance_to(me) < best: + best = p.distance_to(me) + pick = int(e["id"]) + at = p + if pick < 0: + return false + if best > 4.0: + _walk_field(at, me) + else: + st.repair(pick) + return true + + ## Walks to the workbench and buys the next upgrade level it can afford (one that's in stock and ## open by today), the lowest level first: every first level in UPGRADE_ORDER before any second -## one, and so on. Returns false if there's none. -func _upgrade_tick(me: Vector2) -> bool: +## one, and so on. The workbench's own upgrades need it standing (granted after night 1, not +## broken). only: that upgrade or none. Returns false if there's none. +func _upgrade_tick(me: Vector2, only: String = "") -> bool: var c := _sim.campaign var pick := "" for id in UPGRADE_ORDER: + if only != "" and id != only: + continue + if Upgrades.shop_of(c.config, id) == "workbench" and not _sim.structures.workbench_available(): + continue if Upgrades.blocker(c, id) == "" and (pick == "" or Upgrades.level(c.state, id) < Upgrades.level(c.state, pick)): pick = id if pick == "": @@ -317,7 +685,10 @@ func _upgrade_tick(me: Vector2) -> bool: if at.distance_to(me) > bench.reach - 0.3: _walk_field(at, me) else: + var before := Upgrades.level(c.state, pick) Upgrades.buy(c, pick, _sim.structures) + if Upgrades.level(c.state, pick) > before: + _buys.append([c.state.night, pick, Upgrades.level(c.state, pick)]) return true @@ -448,7 +819,7 @@ func _guard() -> void: if loot.followers() > 0 and best > -25.0: goal = PEN_INSIDE best = -25.0 - var hurt := kit.hp() <= cfg.scarecrow_max_hp / 2 + var hurt := kit.hp() <= _sim.campaign.state.scarecrow_max_hp / 2 # with straw stuffing bought if hurt and nearest_d > 8.0: Input.action_press("patch") return