Task #25: arrivals wait for a free character
A planned ground arrival whose type has no free character used to be
skipped (spawn_skipped) and lost. Now it waits and comes in as soon as
one frees, without holding back other types; any still waiting at
sunrise are dropped and counted.
- EnemySystem.can_spawn(type): room and, on foot, a free character
(EnemyCharacters.has_free; a corpse counts), no side effects.
- WaveDirector.step: due arrivals that can't spawn go to a per-type
FIFO; waiting ones are admitted first each tick. waited / dropped
counters next to spawned, reset at nightfall; waiting() for tests.
- GameConfig.character_pool {"thief": 48, "breaker": 20} replaces
EnemyCharacters.POOL; the pools are built from it at setup.
- RULES.md, Night plans: the real limits and the waiting rule.
- test_roster: full thief pool -> the thief waits, crows stay on time,
a freed character (corpse) lets it in, sunrise drops and counts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3bb835f7c3
commit
af48cff80d
6 changed files with 201 additions and 13 deletions
|
|
@ -5,7 +5,10 @@ extends Node3D
|
|||
## 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
|
||||
## GameConfig.target_weights); nothing arrives by day or after sunrise. From dusk until
|
||||
## GameConfig.target_weights); nothing arrives by day or after sunrise. An arrival that can't come
|
||||
## in when it's due (EnemySystem.can_spawn: on foot, every character of its type is in use) waits
|
||||
## and comes in as soon as one is free, while the other types' arrivals keep coming on time; any
|
||||
## still waiting at sunrise are dropped (waited, dropped). From dusk until
|
||||
## WARN_AFTER_NIGHTFALL into the night the phase HUD says what tonight brings (not where: they come
|
||||
## from every side; nothing is marked on the farm itself). debug_plan (F2 in debug builds)
|
||||
## replaces tonight's plan. Trickle mode (GameConfig.night_thieves > 0, for tests and soaks)
|
||||
|
|
@ -41,9 +44,18 @@ var rng := RandomNumberGenerator.new()
|
|||
## Seconds since nightfall, and arrivals so far tonight.
|
||||
var night_time: float = 0.0
|
||||
var spawned: int = 0
|
||||
## Tonight's plan arrivals that had to wait when due (they came in later, or not at all), and those
|
||||
## still waiting at sunrise, which never came. Both reset at nightfall.
|
||||
var waited: int = 0
|
||||
var dropped: int = 0
|
||||
|
||||
var _queue: Array = [] # [time, want, type], sorted
|
||||
var _next: int = 0
|
||||
## Due arrivals waiting for their type to be able to spawn, per type id: [time, want, type] entries
|
||||
## oldest first, and the index of the first one still waiting (those before it have come in).
|
||||
var _waiting: Array[Array] = []
|
||||
var _wait_head := PackedInt32Array()
|
||||
var _waiting_count: int = 0
|
||||
var _trickle_wait: float = FIRST_TRICKLE_DELAY
|
||||
|
||||
|
||||
|
|
@ -54,6 +66,7 @@ func setup(p_campaign: CampaignController, p_enemies: EnemySystem, p_zones: Farm
|
|||
zones = p_zones
|
||||
plans = p_plans
|
||||
rng.randomize()
|
||||
_reset_waiting()
|
||||
campaign.phase_changed.connect(_on_phase_changed)
|
||||
|
||||
|
||||
|
|
@ -185,20 +198,65 @@ func step(dt: float) -> void:
|
|||
spawn_next(int(TARGETS.get(config.trickle_target, LootSystem.ANY)))
|
||||
_trickle_wait = config.thief_spawn_interval
|
||||
return
|
||||
_admit_waiting()
|
||||
# Due arrivals: one comes in now unless its type can't spawn or has others waiting ahead of it
|
||||
# (then it waits behind them); either way the next due arrival, of any type, is looked at too.
|
||||
while _next < _queue.size() and float(_queue[_next][0]) <= night_time:
|
||||
spawn(int(_queue[_next][2]), int(_queue[_next][1]))
|
||||
var e: Array = _queue[_next]
|
||||
_next += 1
|
||||
var t := int(e[2])
|
||||
if _wait_head[t] < _waiting[t].size() or not enemies.can_spawn(t) or spawn(t, int(e[1])) < 0:
|
||||
_waiting[t].append(e)
|
||||
_waiting_count += 1
|
||||
waited += 1
|
||||
|
||||
|
||||
## Plan arrivals waiting right now for their type to be able to spawn.
|
||||
func waiting() -> int:
|
||||
return _waiting_count
|
||||
|
||||
|
||||
## Waiting arrivals come in, oldest first within each type, while their type can spawn. Costs
|
||||
## nothing while none wait, else one EnemySystem.can_spawn per waiting type that stays full.
|
||||
func _admit_waiting() -> void:
|
||||
if _waiting_count == 0:
|
||||
return
|
||||
for t in _waiting.size():
|
||||
var list := _waiting[t]
|
||||
while _wait_head[t] < list.size() and enemies.can_spawn(t) and spawn(t, int(list[_wait_head[t]][1])) >= 0:
|
||||
_wait_head[t] += 1
|
||||
_waiting_count -= 1
|
||||
if _wait_head[t] > 0 and _wait_head[t] == list.size():
|
||||
list.clear()
|
||||
_wait_head[t] = 0
|
||||
|
||||
|
||||
func _reset_waiting() -> void:
|
||||
_waiting.clear()
|
||||
for t in EnemySystem.TYPE_NAMES.size():
|
||||
_waiting.append([])
|
||||
_wait_head.resize(EnemySystem.TYPE_NAMES.size())
|
||||
_wait_head.fill(0)
|
||||
_waiting_count = 0
|
||||
|
||||
|
||||
## 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:
|
||||
## When the night ends (sunrise, or cut short by a retry or a game over), arrivals still waiting
|
||||
## are dropped and counted.
|
||||
func _on_phase_changed(phase: CampaignController.Phase, previous: CampaignController.Phase) -> void:
|
||||
if previous == CampaignController.Phase.NIGHT and phase != CampaignController.Phase.NIGHT:
|
||||
dropped += _waiting_count
|
||||
_reset_waiting()
|
||||
if phase == CampaignController.Phase.MORNING:
|
||||
_set_enemy_scales(null)
|
||||
if phase != CampaignController.Phase.NIGHT:
|
||||
return
|
||||
night_time = 0.0
|
||||
spawned = 0
|
||||
waited = 0
|
||||
dropped = 0
|
||||
_reset_waiting()
|
||||
_trickle_wait = FIRST_TRICKLE_DELAY
|
||||
_queue.clear()
|
||||
_next = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue