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>
This commit is contained in:
Forrest 2026-10-05 14:43:46 -04:00
parent 30e64ebeec
commit 34358d0641
14 changed files with 147 additions and 17 deletions

View file

@ -40,7 +40,7 @@ static func of(s: FarmState, cfg: GameConfig) -> Dictionary:
## "50 crows, 20 thieves and 6 fence breakers" (or "none").
static func enemies_line(t: Dictionary) -> String:
var parts := PackedStringArray()
for type in [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER]:
for type in [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER, EnemySystem.TYPE_UFO]:
var n := int(t.get("killed_" + EnemySystem.TYPE_NAMES[type], 0))
if n == 1:
parts.append("1 " + EnemySystem.NAMES[type])

View file

@ -24,13 +24,14 @@ const HURT_FADE := 4.0
const TYPE_THIEF := 0
const TYPE_CROW := 1
const TYPE_BREAKER := 2
const TYPE_UFO := 3
## GameConfig.enemy_types keys, by type id.
const TYPE_NAMES: Array[String] = ["thief", "crow", "breaker"]
const TYPE_NAMES: Array[String] = ["thief", "crow", "breaker", "ufo"]
## Display names, singular and plural.
const NAMES: Array[String] = ["alien", "crow", "alien robot"]
const PLURALS: Array[String] = ["aliens", "crows", "alien robots"]
const NAMES: Array[String] = ["alien", "crow", "alien robot", "UFO"]
const PLURALS: Array[String] = ["aliens", "crows", "alien robots", "UFOs"]
## "a" or "an" for NAMES[t], by type id.
const ARTICLES: Array[String] = ["an", "a", "an"]
const ARTICLES: Array[String] = ["an", "a", "an", "a"]
const NB_DX: Array[int] = [0, -1, 0, 1, -1, 1, -1, 0, 1]
const NB_DZ: Array[int] = [0, -1, -1, -1, 0, 0, 1, 1, 1]

View file

@ -218,7 +218,9 @@ func setup(p_sim: FarmSim) -> void:
sim.waves.arrived.connect(func(h: int, at: Vector2) -> void:
var d := sim.enemies.resolve_handle(h)
var type := sim.enemies.type[d] if d >= 0 else EnemySystem.TYPE_THIEF
play(["thief_arrive", "crow_arrive", "breaker_arrive"][type], Vector3(at.x, 0.0, at.y)))
# thief, crow, breaker, and a UFO (no cue of its own yet: it flies in like a crow).
var arrive_cues := ["thief_arrive", "crow_arrive", "breaker_arrive", "crow_arrive"]
play(arrive_cues[type], Vector3(at.x, 0.0, at.y)))
var kit := sim.scarecrow
kit.damaged.connect(func(hp: int) -> void: play("fall" if hp <= 0 else "hurt"))
kit.fear_used.connect(func(_p: Vector3, _n: int) -> void: play("fear"))

View file

@ -698,6 +698,8 @@ static func arrival_message(type: int, side: String) -> String:
return "A crow flew in" + from
EnemySystem.TYPE_BREAKER:
return "An alien robot came in" + from
EnemySystem.TYPE_UFO:
return "A UFO swept in" + from
return "An alien slipped in" + from

View file

@ -24,7 +24,7 @@ const STRUCTURE_KEYS: Array[String] = ["id", "type", "x", "z", "rot", "hp"]
const EVENTS: Array[String] = [
"crops_stolen", "crops_recovered", "animals_stolen", "animals_strayed", "animals_recovered",
"supplies_stolen", "supplies_recovered", "supplies_lost",
"killed_crow", "killed_thief", "killed_breaker", "escaped",
"killed_crow", "killed_thief", "killed_breaker", "killed_ufo", "escaped",
"scarecrow_damage", "patches",
"structures_built", "structures_damaged", "structures_destroyed", "repairs", "upgrades_bought",
"gathered_wood", "gathered_scrap", "gathered_straw", "gathered_alien_goop",
@ -35,7 +35,7 @@ const LOG_KEYS: Array[String] = [
"night", "crops_lost", "animals_lost",
"crops_stolen", "crops_recovered", "animals_stolen", "animals_strayed", "animals_recovered",
"supplies_stolen", "supplies_recovered", "supplies_lost",
"killed_crow", "killed_thief", "killed_breaker", "escaped",
"killed_crow", "killed_thief", "killed_breaker", "killed_ufo", "escaped",
"scarecrow_damage", "patches",
"structures_built", "structures_damaged", "structures_destroyed", "repairs", "upgrades_bought",
"gathered_wood", "gathered_scrap", "gathered_straw", "gathered_alien_goop",

View file

@ -243,6 +243,11 @@ extends Resource
"breaker": {"speed": 1.9, "acceleration": 8.0, "hp": 6, "flying": false, "targets": ["structures"],
"steal_time": 0.0, "carry_speed": 0.0, "structure_damage": 8, "damage": 2, "hit_interval": 1.5,
"aggression": "fight", "hit_radius": 0.55, "aggro_range": 4.0},
## Fast, fragile, and always spoiling for a fight: a UFO heads straight for the scarecrow (no
## loot, so no targets) and dives in for a strafing pass every hit_interval (ThiefBehavior).
"ufo": {"speed": 7.0, "acceleration": 20.0, "hp": 2, "flying": true, "targets": [],
"steal_time": 0.0, "carry_speed": 0.0, "structure_damage": 0, "damage": 1, "hit_interval": 1.5,
"aggression": "fight", "hit_radius": 0.5, "aggro_range": 10.0},
}
## Flyers cruise at this visual altitude and come down to land_altitude to take a crop.
@export var cruise_altitude: float = 3.2

View file

@ -8,7 +8,7 @@ extends Resource
## time seconds after nightfall when the group's first enemy arrives
## count how many arrive
## every seconds between them
## type enemy type: "thief", "crow", or "breaker"
## 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
@ -66,7 +66,7 @@ func problems(length: float, count_scale: float = 1.0, spacing_scale: float = 1.
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"]}
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:

View file

@ -167,7 +167,7 @@ static func on_the_farm(es: EnemySystem) -> String:
if es.alive[d] == 1:
counts[es.type[d]] += 1
var parts := PackedStringArray()
for t in [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER]:
for t in [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER, EnemySystem.TYPE_UFO]:
if counts[t] == 1:
parts.append(EnemySystem.ARTICLES[t] + " " + EnemySystem.NAMES[t])
elif counts[t] > 1:

View file

@ -1,6 +1,6 @@
class_name ThiefBehavior
extends RefCounted
## What each enemy wants, decided every tick (EnemySystem turns it into motion). Three types
## What each enemy wants, decided every tick (EnemySystem turns it into motion). Four types
## (stats in GameConfig.enemy_types):
## thief on foot, after its type's targets (animals and supplies): the theft lifecycle of
## game/RULES.md below. Routes around barriers when it can, breaks through when not.
@ -11,6 +11,10 @@ extends RefCounted
## barrier guarding the crops, the pen, or the shed and smashes it, then goes for the
## next. It turns on the scarecrow when it comes close or shoots it, and hunts the
## scarecrow when nothing is left to break.
## ufo flies, steals nothing, and goes straight to FIGHT the moment it arrives (fences,
## gates, and traps mean nothing to it, same as a crow). Strafes the scarecrow: dives
## toward it while its attack is off cooldown, then peels away and swings around for
## another pass once it lands a hit (altitude dips for the dive, climbs on the pull-up).
## States:
## SEEK claim something to take (LootSystem.claim, limited to the type's categories: dropped
## loot in view first, then its wanted category, EnemySystem.want, then the others),
@ -97,6 +101,8 @@ func update(es: EnemySystem, dt: float) -> void:
State.SEEK:
if t == EnemySystem.TYPE_CROW:
_crow_seek(es, i)
elif t == EnemySystem.TYPE_UFO:
_start_fight(es, i)
elif es.t_breaks[t] == 1:
_breaker_seek(es, i)
else:
@ -113,7 +119,10 @@ func update(es: EnemySystem, dt: float) -> void:
State.BREAK:
_break(es, i)
State.FIGHT:
_fight(es, i)
if t == EnemySystem.TYPE_UFO:
_ufo_fight(es, i)
else:
_fight(es, i)
_:
if es.t_flying[t] == 1:
_fly_off(es, i, EnemySystem.Removal.LEFT)
@ -184,7 +193,7 @@ func retreat_all(es: EnemySystem) -> void:
## A flyer's visual altitude: cruising, coming down as it nears its crop, sitting on it while it
## takes it.
## takes it. A UFO dives low for its attack run and climbs again once it has landed a hit.
func altitude_for(es: EnemySystem, i: int) -> float:
match es.state[i]:
State.STEAL:
@ -194,9 +203,17 @@ func altitude_for(es: EnemySystem, i: int) -> float:
if unit > 0:
var d := loot.position_of(unit).distance_to(Vector2(es.pos_x[i], es.pos_z[i]))
return lerpf(cfg.land_altitude, cfg.cruise_altitude, clampf((d - 0.5) / 4.0, 0.0, 1.0))
State.FIGHT:
if es.type[i] == EnemySystem.TYPE_UFO:
return cfg.cruise_altitude if es.attack_cd[i] > 0.0 else cfg.land_altitude
return cfg.cruise_altitude
## Body contact range for an attack: the enemy's hit proxy, the scarecrow's, and the melee reach.
func _attack_reach() -> float:
return cfg.enemy_radius + FarmSim.SCARECROW_RADIUS + cfg.enemy_attack_reach
func _seek(es: EnemySystem, i: int, dt: float) -> void:
var h := es.handle_of(i)
var p := Vector2(es.pos_x[i], es.pos_z[i])
@ -390,6 +407,26 @@ func _fight(es: EnemySystem, i: int) -> void:
es.desire_z[i] = to.y / d
## A UFO's strafing run: straight at the scarecrow while its attack is off cooldown (diving in),
## straight away from it right after landing a hit (pulling up and swinging around for the next
## pass). No scarecrow left standing: leave like anything else at the end of a fight.
func _ufo_fight(es: EnemySystem, i: int) -> void:
var p := Vector2(es.pos_x[i], es.pos_z[i])
var sc := nearest_scarecrow(p)
if not sc.is_finite():
es.state[i] = State.RETREAT
return
var to := sc - p
var d := maxf(to.length(), 1e-4)
es.pace[i] = 1.0
if es.attack_cd[i] > 0.0 and d <= _attack_reach() * 2.0:
es.desire_x[i] = -to.x / d
es.desire_z[i] = -to.y / d
else:
es.desire_x[i] = to.x / d
es.desire_z[i] = to.y / d
## The flow field toward an item's home: the crop rows, the pen, or its sack's pile at the shed.
func field_for(id: int) -> PackedInt32Array:
match loot.category[id]:

View file

@ -1,7 +1,7 @@
class_name WaveDirector
extends Node3D
## Night arrivals. By default it runs the night's NightPlan: each group's enemies (thieves, crows,
## or fence breakers) arrive at their times after nightfall, each at its own random point along
## fence breakers, or UFOs) arrive at their times after nightfall, each at its own random point along
## the farm's edge (FarmZones.edge): on foot GameConfig.spawn_margin outside the map, at a free
## cell with a route onto the farm (ground_spawns); flyers flyer_spawn_margin out. They go for the
## group's target (crops, animals, supplies, or any of their type's targets by
@ -108,6 +108,8 @@ static func entry_label(entry: Array) -> String:
return "Crows"
EnemySystem.TYPE_BREAKER:
return "Alien robots"
EnemySystem.TYPE_UFO:
return "UFOs"
match int(entry[1]):
LootSystem.Category.CROP:
return "Aliens after the crops"