Merge task #24: nights by count, per-night enemy speed and HP, F3 night jump

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-06 16:05:39 -04:00
commit f5bfdc4bef
9 changed files with 259 additions and 22 deletions

View file

@ -304,8 +304,10 @@ From the user (2026-10-03): the game is "extraordinarily easy". There are too fe
come too spread out, and the game feels slow. The vacation should grow from 5 days to 30, with
the scale following. That rework comes next, before or as part of Step 12. Step 11's screens
read the night count from `GameConfig.campaign_nights` (range now 1–60): the menus, results,
saves, and ending aren't tied to five nights. The night plans are still a list of five files in
`FarmSim.NIGHT_PLANS`, and the last one repeats for any nights after it.
saves, and ending aren't tied to five nights. The night plans were then still a list of five
files in `FarmSim.NIGHT_PLANS`, and the last one repeated for any nights after it. (Since #24 they
load by count: `FarmSim.night_plan_path(n)`, `game/resources/nights/night_<n>.tres` for n in
1..`campaign_nights`. A missing file is an error, and that night plays the last plan that loaded.)
## After Step 11: 5x enemies, outside gathering, co-op, music (2026-10-03)

View file

@ -147,6 +147,11 @@ How enemies steal (the enemy types are in **The enemies**, below):
Implemented in Step 9. The type table is `GameConfig.enemy_types`.
**Per-night scales.** A night's plan can make its enemies faster and tougher than the table:
`enemy_speed_scale` multiplies every enemy's speed that night (fleeing and carrying included), and
`enemy_hp_scale` its HP, rounded down but never below the table's (a crow stays one hit; at 1.6 a
thief has 4, a breaker 9). Both are 1 unless the plan says otherwise.
| | Crow | Thief | Fence breaker |
|---|---|---|---|
| Moves | Flies at 5.5 m/s | Walks at 3 m/s | Walks at 1.9 m/s |

View file

@ -4,6 +4,8 @@ extends CanvasLayer
## F1 show / hide this readout
## F2 cycle tonight's plan through the debug scenarios (one enemy type, then
## pairs, then all three; game/resources/scenarios/) and back to the real one
## F3 / Shift+F3 in the morning review: jump to the next / previous day's morning, farm as
## it is (jump_morning; debug builds only, not on a co-op partner's machine)
## N start the night early (only when GameConfig.allow_early_night is on)
## R after Game Over: retry the night; after the farmers return: new vacation
## F6 end the current phase now
@ -62,6 +64,8 @@ func _unhandled_input(event: InputEvent) -> void:
_label.visible = not _label.visible
KEY_F2:
cycle_scenario()
KEY_F3:
jump_morning(-1 if key.shift_pressed else 1)
KEY_N:
campaign.start_night_early()
KEY_F6:
@ -75,6 +79,34 @@ func _unhandled_input(event: InputEvent) -> void:
s.strip()
## Debug builds, in the morning review only: to the morning of the next (step 1) or previous
## (step -1) day, within the vacation. The farm stays as it is and nights_survived follows as
## night - 1. It's the campaign's own new-morning path (CampaignController.load_state with the
## current state), so everything a real morning does happens: dormant crop fields sprout (or go
## dormant again) by nights_survived, the Workbench is granted from nights_survived 1 on, the
## retry snapshot is retaken, and the review panel refreshes. As at a real night's end, the
## Workbench and the sprouted crops are in the state before that snapshot. The save file is left
## alone. Returns whether it moved.
func jump_morning(step: int) -> bool:
var s := campaign.state
if not OS.is_debug_build() or s.phase != CampaignController.Phase.MORNING or campaign.remote_request.is_valid():
return false
var night := clampi(s.night + step, 1, campaign.config.campaign_nights)
if night == s.night:
return false
s.night = night
s.nights_survived = night - 1
if sim != null: # what the night's end does first (CampaignController.night_ending)
if s.nights_survived >= 1:
sim.structures.grant_workbench()
sim.loot.grow_crops_total(s.nights_survived)
var path := campaign.save_path
campaign.save_path = "" # no autosave: a jump isn't a morning the player reached
campaign.load_state(s)
campaign.save_path = path
return true
## Next debug scenario as tonight's plan (after the last, the real plan again).
func cycle_scenario() -> void:
if sim == null:
@ -115,5 +147,5 @@ func _describe() -> String:
lines.append("[N] start the night early")
if sim != null and sim.waves.debug_plan != null:
lines.append("Scenario: %s (F2 next)" % sim.waves.debug_plan.title)
lines.append("F1 hide · F2 scenario · F6 next phase · F7 speed · F9 scarecrow to 0 HP · F10 strip farm · T/G/H thief/crow/breaker")
lines.append("F1 hide · F2 scenario · F3 / Shift+F3 next / previous morning · F6 next phase · F7 speed · F9 scarecrow to 0 HP · F10 strip farm · T/G/H thief/crow/breaker")
return "\n".join(lines)

View file

@ -68,6 +68,10 @@ var t_hit_interval := PackedFloat32Array()
var t_aggression := PackedByteArray()
var t_aggro_range := PackedFloat32Array()
var t_hit_radius := PackedFloat32Array()
## Tonight's scales (NightPlan.enemy_speed_scale / enemy_hp_scale, set by WaveDirector at
## nightfall): every enemy moves at t_speed x night_speed_scale, and arrives with full_hp().
var night_speed_scale: float = 1.0
var night_hp_scale: float = 1.0
var capacity: int = 0
var active_count: int = 0
@ -199,11 +203,18 @@ func is_flying(d: int) -> bool:
return t_flying[type[d]] == 1
## The fastest any enemy moves tonight.
func max_speed() -> float:
var best := 0.0
for v in t_speed:
best = maxf(best, v)
return best
return best * night_speed_scale
## The HP an enemy of type arrives with tonight: t_hp x night_hp_scale, rounded down, but never
## less than t_hp.
func full_hp(enemy_type: int) -> int:
return maxi(t_hp[enemy_type], floori(t_hp[enemy_type] * night_hp_scale + 1e-6))
## Releases every enemy at once, without removal events (used when the farm state is replaced,
@ -258,7 +269,7 @@ func spawn(enemy_type: int, x: float, z: float, heading: Vector2, p_want: int =
attack_cd[d] = 0.0
slow_left[d] = 0.0
alt[d] = config.cruise_altitude
health[d] = t_hp[enemy_type]
health[d] = full_hp(enemy_type)
target[d] = -1
carry[d] = -1
barrier[d] = -1
@ -381,7 +392,7 @@ func step(dt: float, scarecrow: Vector2, scarecrow_radius: float) -> void:
continue
var t := type[i]
var flying := t_flying[t] == 1
var speed := t_speed[t]
var speed := t_speed[t] * night_speed_scale
var accel := t_accel[t] * dt
if flying:
var want_alt := behavior.altitude_for(self, i) if behavior != null else cfg.cruise_altitude

View file

@ -29,11 +29,8 @@ extends Node
const SCARECROW_RADIUS := 0.4
const HUNT_INTERVAL := 0.4
const NIGHT_PLANS: Array[String] = [
"res://game/resources/nights/night_1.tres", "res://game/resources/nights/night_2.tres",
"res://game/resources/nights/night_3.tres", "res://game/resources/nights/night_4.tres",
"res://game/resources/nights/night_5.tres",
]
## Night n's plan file (night_plan_path), for n in 1..GameConfig.campaign_nights.
const NIGHT_PLAN_PATH := "res://game/resources/nights/night_%d.tres"
@export var campaign: CampaignController
@export var zones: FarmZones
@ -116,6 +113,28 @@ var _rebuild_ticks: int = 0
var _goop_rng := RandomNumberGenerator.new()
## Where night n's plan lives: game/resources/nights/night_<n>.tres.
static func night_plan_path(n: int) -> String:
return NIGHT_PLAN_PATH % n
## The plans of nights 1..nights, by night_plan_path. A missing (or unreadable) file is an error,
## and that night plays the last plan that loaded (as WaveDirector.plan_for does past the end).
static func load_night_plans(nights: int) -> Array[NightPlan]:
var plans: Array[NightPlan] = []
var last: NightPlan = null
for n in range(1, nights + 1):
var path := night_plan_path(n)
var plan: NightPlan = load(path) as NightPlan if ResourceLoader.exists(path) else null
if plan == null:
push_error("Night %d has no plan at %s: it plays %s" % [n, path, "night %d's" % (n - 1) if last != null else "none"])
plan = last
else:
last = plan
plans.append(plan)
return plans
func _ready() -> void:
var t0 := Time.get_ticks_msec()
config = campaign.config
@ -240,10 +259,7 @@ func _ready() -> void:
waves = WaveDirector.new()
waves.name = "Waves"
add_child(waves)
var plans: Array[NightPlan] = []
for path in NIGHT_PLANS:
plans.append(load(path) as NightPlan)
waves.setup(campaign, enemies, zones, plans)
waves.setup(campaign, enemies, zones, load_night_plans(config.campaign_nights))
for c in _goals["escape"]:
if animal_field[c] < FarmNavigation.UNREACHABLE: # not shut in by the props around it
waves.ground_spawns.append(nav.cell_center(c))

View file

@ -5,7 +5,8 @@ extends Resource
## starting value to tune during balancing.
@export_group("Campaign")
## Nights the scarecrow must survive before the farmers return.
## Nights the scarecrow must survive before the farmers return. Night n plays the plan in
## game/resources/nights/night_<n>.tres (FarmSim.night_plan_path), so there must be one per night.
@export_range(1, 60) var campaign_nights: int = 5
@export_group("Waves")

View file

@ -3,8 +3,9 @@ extends Resource
## One night (the plan's NightDefinition): its title, the hint shown at dusk, an optional length,
## and groups of enemies, each arriving at a time into the night. Where is not planned: every
## enemy arrives at its own random point along the farm's edge (WaveDirector).
## game/resources/nights/night_1..5.tres are the vacation's nights; game/resources/scenarios/
## holds debug plans.
## game/resources/nights/night_<n>.tres, for n in 1..GameConfig.campaign_nights
## (FarmSim.night_plan_path), are the vacation's nights; game/resources/scenarios/ holds debug
## plans.
## time seconds after nightfall when the group's first enemy arrives
## count how many arrive
## every seconds between them
@ -13,7 +14,9 @@ extends Resource
## The plans are the nights' designs; GameConfig.wave_count_scale and wave_spacing_scale scale
## every group when the night is played (count_scale x the enemies, spacing_scale x the time
## between them), so the whole vacation's pressure is tuned in one place. A plan can set its own
## scales instead (night 1 plays as designed, at 1 and 1).
## scales instead (night 1 plays as designed, at 1 and 1). enemy_speed_scale and enemy_hp_scale
## make tonight's enemies faster and tougher than GameConfig.enemy_types says (WaveDirector hands
## them to EnemySystem at nightfall).
@export var title: String = ""
## What the HUD tells the player at dusk about tonight.
@ -23,6 +26,10 @@ extends Resource
## This night's own scales; 0 uses GameConfig.wave_count_scale / wave_spacing_scale.
@export var count_scale: float = 0.0
@export var spacing_scale: float = 0.0
## Tonight's enemies move at speed x this (fleeing and carrying too, as shares of it), and arrive
## with HP x this, rounded down but never below the type's own (a 1 HP crow stays one hit).
@export var enemy_speed_scale: float = 1.0
@export var enemy_hp_scale: float = 1.0
@export var groups: Array[Dictionary] = []
@ -52,11 +59,13 @@ func total(count_scale: float = 1.0) -> int:
## What's wrong with the plan (empty when it's fine): unknown enemy types, a target the type
## doesn't take, or arrivals outside the night (as scaled).
## doesn't take, arrivals outside the night (as scaled), or an enemy scale that isn't positive.
func problems(length: float, count_scale: float = 1.0, spacing_scale: float = 1.0) -> PackedStringArray:
var out := PackedStringArray()
if groups.is_empty():
out.append("no groups")
if enemy_speed_scale <= 0.0 or enemy_hp_scale <= 0.0:
out.append("enemy scales must be positive")
for k in groups.size():
var g: Dictionary = groups[k]
var where := "group %d" % (k + 1)

View file

@ -190,7 +190,11 @@ func step(dt: float) -> void:
_next += 1
## Nightfall: tonight's arrivals are queued and its enemy scales (NightPlan.enemy_speed_scale and
## enemy_hp_scale; the debug plan's when set) go to EnemySystem, until the morning (then 1 again).
func _on_phase_changed(phase: CampaignController.Phase, _previous: CampaignController.Phase) -> void:
if phase == CampaignController.Phase.MORNING:
_set_enemy_scales(null)
if phase != CampaignController.Phase.NIGHT:
return
night_time = 0.0
@ -199,9 +203,16 @@ func _on_phase_changed(phase: CampaignController.Phase, _previous: CampaignContr
_queue.clear()
_next = 0
var plan := tonight()
_set_enemy_scales(plan)
if plan != null:
for g in plan.groups:
var every := NightPlan.scaled_every(g, plan.spacing_scale_in(config))
for k in NightPlan.scaled_count(g, plan.count_scale_in(config)):
_queue.append([float(g.get("time", 0.0)) + k * every, want_of(g), type_of(g)])
_queue.sort_custom(func(a: Array, b: Array) -> bool: return float(a[0]) < float(b[0]))
## A plan's enemy scales on EnemySystem (1 and 1 without a plan, or for a scale that isn't positive).
func _set_enemy_scales(plan: NightPlan) -> void:
enemies.night_speed_scale = plan.enemy_speed_scale if plan != null and plan.enemy_speed_scale > 0.0 else 1.0
enemies.night_hp_scale = plan.enemy_hp_scale if plan != null and plan.enemy_hp_scale > 0.0 else 1.0

View file

@ -2,8 +2,9 @@ extends RefCounted
## The five-night progression (Step 10): every night plan and debug scenario is valid (markers
## exist and suit the enemy type, types and targets are known, arrivals fit the night), each night
## tests what the plan says it should, the upgrades apply to the systems they change and persist
## (next morning, JSON, retry), and the five nights play back to back to the farmers' return, each
## with its own plan and morning snapshot, everything carrying over.
## (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 the five nights play back to back to the
## farmers' return, each with its own plan and morning snapshot, everything carrying over.
const P := CampaignController.Phase
const T := ThiefBehavior.State
@ -25,6 +26,9 @@ func run(r: GameTestRunner) -> void:
_validation(r, sim)
_designs(r, sim)
_upgrades(r, sim, player)
_plan_paths(r, sim)
_enemy_scales(r, sim)
_night_jump(r, farm, sim)
_five_nights(r, farm, sim, player)
farm.queue_free()
await r.process_frame
@ -199,6 +203,152 @@ func _upgrades(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
player.global_position = AWAY
## #24: the plans load by count, night_plan_path(n) for every night of the vacation; a missing
## file plays the last plan that loaded.
func _plan_paths(r: GameTestRunner, sim: FarmSim) -> void:
var nights := sim.config.campaign_nights
var all_load := sim.waves.plans.size() == nights
for n in range(1, nights + 1):
var path := FarmSim.night_plan_path(n)
var plan: NightPlan = load(path) as NightPlan if ResourceLoader.exists(path) else null
all_load = all_load and path == "res://game/resources/nights/night_%d.tres" % n and plan != null and sim.waves.plans[n - 1] == plan
r.check(all_load, "night_plan_path(n) loads a plan for every night 1..%d, in order" % nights)
r.info("(the error just below, about night %d's missing plan, is expected)" % (nights + 1))
var more := FarmSim.load_night_plans(nights + 1)
r.check(more.size() == nights + 1 and more[nights] == more[nights - 1] and more[nights] != null,
"a night without a plan file plays the last plan that loaded")
## #24: tonight's enemy scales. The vacation's own plans keep every enemy as it was; a plan with
## enemy_speed_scale and enemy_hp_scale makes that night's enemies faster and tougher (HP rounded
## down, never below the type's: a crow stays one hit); the morning puts them back to 1.
func _enemy_scales(r: GameTestRunner, sim: FarmSim) -> void:
var c := sim.campaign
var es := sim.enemies
var w := sim.waves
c.new_campaign()
_step(sim, 1)
var fastest := 0.0
for v in es.t_speed:
fastest = maxf(fastest, v)
var unscaled := true
for p in w.plans:
unscaled = unscaled and p.enemy_speed_scale == 1.0 and p.enemy_hp_scale == 1.0
r.check(unscaled, "the vacation's %d nights keep the enemies' own speed and HP (scales 1)" % w.plans.size())
# A plan with the default scales: as before.
while c.state.phase != P.NIGHT:
c.advance_phase()
var hp := _spawn_hp(es)
var top := _top_speed(sim, EnemySystem.TYPE_CROW)
r.check(es.night_speed_scale == 1.0 and es.night_hp_scale == 1.0 and hp == Array(es.t_hp)
and absf(top - es.t_speed[EnemySystem.TYPE_CROW]) < 0.05 and is_equal_approx(es.max_speed(), fastest),
"a night at the default scales: HP %s, a crow flies at %.2f m/s, as before" % [hp, top])
while c.state.phase != P.MORNING:
c.advance_phase()
# A night at 1.6 (the debug plan's own scales stand for tonight's).
var tough := NightPlan.new()
tough.title = "Tough"
tough.enemy_speed_scale = 1.6
tough.enemy_hp_scale = 1.6
tough.groups = [{"type": "crow", "target": "crops", "time": 5.0, "count": 1, "every": 1.0}]
w.debug_plan = tough
while c.state.phase != P.NIGHT:
c.advance_phase()
hp = _spawn_hp(es)
top = _top_speed(sim, EnemySystem.TYPE_CROW)
var ids := [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER, EnemySystem.TYPE_UFO]
r.check(hp[ids[0]] == 1 and hp[ids[1]] == 4 and hp[ids[2]] == 9 and hp[ids[3]] == 3,
"at HP x1.6 a crow stays at 1 HP, a thief goes 3 -> %d, a breaker 6 -> %d, a UFO 2 -> %d" % [hp[ids[1]], hp[ids[2]], hp[ids[3]]])
r.check(absf(top - es.t_speed[EnemySystem.TYPE_CROW] * 1.6) < 0.05 and is_equal_approx(es.max_speed(), fastest * 1.6),
"at speed x1.6 a crow flies at %.2f m/s (its own %.1f)" % [top, es.t_speed[EnemySystem.TYPE_CROW]])
while c.state.phase != P.MORNING:
c.advance_phase()
r.check(es.night_speed_scale == 1.0 and es.night_hp_scale == 1.0 and es.full_hp(EnemySystem.TYPE_THIEF) == es.t_hp[EnemySystem.TYPE_THIEF],
"the morning puts the scales back to 1")
w.debug_plan = null
c.new_campaign()
_step(sim, 1)
## The HP each enemy type arrives with right now (by type id); they leave again at once.
func _spawn_hp(es: EnemySystem) -> Array:
var out := []
for t in EnemySystem.TYPE_NAMES.size():
var h := es.spawn(t, 12.0 + 3.0 * t, -2.0, Vector2.UP)
out.append(es.health[es.resolve_handle(h)] if h >= 0 else -1)
es.remove_all()
return out
## How fast an enemy of type goes flat out (full desire, no behavior) after a second.
func _top_speed(sim: FarmSim, type: int) -> float:
var es := sim.enemies
var keep := es.behavior
es.behavior = null
var d := es.resolve_handle(es.spawn(type, 0.0, 0.0, Vector2.RIGHT))
var speed := -1.0
if d >= 0:
for i in 60:
es.desire_x[d] = 1.0
es.desire_z[d] = 0.0
es.pace[d] = 1.0
es.step(DT, Vector2(INF, INF), FarmSim.SCARECROW_RADIUS)
speed = Vector2(es.vel_x[d], es.vel_z[d]).length()
es.remove_all()
es.behavior = keep
return speed
## #24: F3 (CampaignDebug.jump_morning) moves the morning review to the next day's morning and
## Shift+F3 to the previous one, with the farm as it is: nights_survived follows, the Workbench
## comes, a field sprouts, the retry snapshot and the review panel are the new morning's, and
## nothing is saved.
func _night_jump(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
var c := sim.campaign
var debug := farm.get_node("CampaignDebug") as CampaignDebug
var st := sim.structures
c.new_campaign()
_step(sim, 1)
var s := c.state
s.resources.shed = {"wood": 99, "scrap": 99, "straw": 99}
var fence := st.place("fence", 8.0, -8.0, 0)
s.scarecrow_hp = s.scarecrow_max_hp - 1
var shed := s.resources.shed.duplicate()
var crops := s.crops_total
var dormant := sim.loot.count(LootSystem.Status.DORMANT)
var keep_path := c.save_path
c.save_path = "user://test_night_jump.json"
if FileAccess.file_exists(c.save_path):
DirAccess.remove_absolute(c.save_path)
r.check(not debug.jump_morning(-1) and s.night == 1, "Shift+F3 on the first morning stays there")
var f3 := InputEventKey.new()
f3.physical_keycode = KEY_F3
f3.pressed = true
debug._unhandled_input(f3)
var tonight := sim.waves.plan_for(2).title
var body := (sim.review_panel._body as Label).text
r.check(c.state == s and s.night == 2 and s.nights_survived == 1 and s.phase == P.MORNING,
"F3: the morning of day 2 (%d survived)" % s.nights_survived)
r.check(s.structure(fence).size() > 0 and s.resources.shed == shed and s.scarecrow_hp == s.scarecrow_max_hp - 1
and s.crops_total == crops and st.has_workbench(),
"the farm is as it was (the fence, the shed, the scarecrow's HP), and the Workbench is granted")
r.check(c.morning_snapshot() == s.to_dict() and sim.review_panel.visible and body.contains("Tonight: %s." % tonight),
"the retry snapshot and the review panel are day 2's")
debug._unhandled_input(f3)
r.check(s.night == 3 and s.nights_survived == 2 and s.crops_total == crops + 10 and sim.loot.count(LootSystem.Status.DORMANT) == dormant - 10,
"F3 again: day 3, and the field due after night 2 sprouts (%d crops)" % s.crops_total)
var back := f3.duplicate() as InputEventKey
back.shift_pressed = true
debug._unhandled_input(back)
r.check(s.night == 2 and s.nights_survived == 1 and c.morning_snapshot()["night"] == 2, "Shift+F3: back to day 2")
r.check(not FileAccess.file_exists(c.save_path), "a jump doesn't autosave")
c.begin_day()
r.check(not debug.jump_morning(1) and s.night == 2, "F3 only works in the morning review")
c.save_path = keep_path
c.new_campaign()
_step(sim, 1)
## All five nights back to back, each with its own plan and morning snapshot, to the farmers'
## return. The farm is defended, and the scarecrow kept out of harm.
func _five_nights(r: GameTestRunner, farm: Node3D, sim: FarmSim, player: PlayerCharacter) -> void: