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:
commit
f5bfdc4bef
9 changed files with 259 additions and 22 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue