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:
parent
30e64ebeec
commit
34358d0641
14 changed files with 147 additions and 17 deletions
|
|
@ -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]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue