harvest/game/scripts/night_plan.gd
Forrest 34358d0641 Task #15: UFO enemy, a fast flying fighter
Adds a 4th enemy type (TYPE_UFO=3) that reuses the generic flying-nav
infrastructure (ignores fences, gates, and traps) and gets a new
FIGHT-capable behavior in ThiefBehavior: it skips SEEK/loot entirely and
goes straight to FIGHT, strafing the scarecrow in dive-and-pull-up passes
(diving to land_altitude while its attack is off cooldown, climbing to
cruise_altitude right after landing a hit) until it's hit for every pass.
All stats (speed 7.0, hp 2, damage 1, hit_interval 1.5s, aggro_range 10.0,
etc.) live in GameConfig.enemy_types["ufo"]. It renders through the same
shared flyer MultiMesh crows use (no new art) and is wired into
NightPlan/WaveDirector composition, the HUD/assessment roster lines, kill
log keys, and the arrival sound/toast, with a generic audio fallback since
it has no cue of its own.

Per a scope addition mid-task, night 5 now also sends in a wave of 4 UFOs
late in the night (game/resources/nights/night_5.tres), which shifts
test_nights' known-flaky "arrived" baseline line by one new {3: N} entry
(the UFO counts agree between plan and arrival) and required updating its
hardcoded "all three types" check to four. A debug-only "UFOs only"
scenario is added (game/resources/scenarios/ufos.tres) but deliberately
left out of CampaignDebug.SCENARIOS, since wiring it in would change
test_roster's hardcoded scenario count and that file's existing checks
were required to stay untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-05 14:43:46 -04:00

86 lines
3.8 KiB
GDScript

class_name NightPlan
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.
## time seconds after nightfall when the group's first enemy arrives
## count how many arrive
## every seconds between them
## type enemy type: "thief", "crow", "breaker", or "ufo"
## target what they're after: "crops", "animals", "supplies", or "any" (GameConfig.target_weights)
## 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).
@export var title: String = ""
## What the HUD tells the player at dusk about tonight.
@export_multiline var dusk_hint: String = ""
## Seconds the night lasts; 0 uses GameConfig.night_length.
@export var night_length: float = 0.0
## 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
@export var groups: Array[Dictionary] = []
## The scales this night is played at: its own, or the config's.
func count_scale_in(config: GameConfig) -> float:
return count_scale if count_scale > 0.0 else config.wave_count_scale
func spacing_scale_in(config: GameConfig) -> float:
return spacing_scale if spacing_scale > 0.0 else config.wave_spacing_scale
## A group's enemies and the seconds between them, scaled.
static func scaled_count(g: Dictionary, count_scale: float = 1.0) -> int:
return maxi(roundi(int(g.get("count", 1)) * count_scale), 1)
static func scaled_every(g: Dictionary, spacing_scale: float = 1.0) -> float:
return float(g.get("every", 2.0)) * spacing_scale
func total(count_scale: float = 1.0) -> int:
var n := 0
for g in groups:
n += scaled_count(g, count_scale)
return n
## 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).
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")
for k in groups.size():
var g: Dictionary = groups[k]
var where := "group %d" % (k + 1)
var type := String(g.get("type", ""))
var t := EnemySystem.TYPE_NAMES.find(type)
if t < 0:
out.append("%s: unknown enemy type '%s'" % [where, type])
continue
var target := String(g.get("target", "any"))
var allowed := {"crow": ["crops", "any"], "thief": ["animals", "supplies", "any"], "breaker": ["any"], "ufo": ["any"]}
if not (allowed[type] as Array).has(target):
out.append("%s: a %s doesn't go for '%s'" % [where, type, target])
if int(g.get("count", 0)) < 1 or float(g.get("every", 0.0)) <= 0.0:
out.append("%s: count and spacing must be positive" % where)
var last := float(g.get("time", 0.0)) + (scaled_count(g, count_scale) - 1) * scaled_every(g, spacing_scale)
if float(g.get("time", -1.0)) < 0.0 or last >= length:
out.append("%s: arrivals (%.0f..%.0f s) outside the %.0f s night" % [where, float(g.get("time", 0.0)), last, length])
return out
## How many of each enemy type (EnemySystem type id -> count), scaled.
func type_counts(count_scale: float = 1.0) -> Dictionary:
var out := {}
for g in groups:
var t := maxi(EnemySystem.TYPE_NAMES.find(String(g.get("type", "thief"))), 0)
out[t] = int(out.get(t, 0)) + scaled_count(g, count_scale)
return out