Merge task #21: animals roam the whole farm, never lost on their own
Loose animals roam the playable map day and night; dropped, leash-broken and open-pen animals become LOOSE instead of running for the edge. Only an Alien carrying one off the map loses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
9d26f29299
8 changed files with 379 additions and 226 deletions
|
|
@ -1,20 +1,25 @@
|
|||
extends RefCounted
|
||||
## All three farm targets on the real farm, with FarmSim stepped by hand at 60 Hz: task #12's
|
||||
## loose start (animals scattered outside the pen, grazing in place, claimable by thieves, and led
|
||||
## in with the follow-trail mechanic); then, with every animal penned up front the old way, the
|
||||
## animals in the pen (wandering, kept in by the pen's gate), an animal thief breaking in, catching
|
||||
## and carrying one off, a dropped animal running for the farm's edge, leading animals back (at most
|
||||
## three, through a gate), a pen breach letting animals wander out at night (and not by day), supply
|
||||
## thieves taking bundles from the shed's piles (never more than there is), dropping, recovering,
|
||||
## and losing them, the piles growing and shrinking with the stock, thieves falling back to another
|
||||
## target, the asset HUD, the end of the dawn grace, retry, and a farm stripped of all three.
|
||||
## All three farm targets on the real farm, with FarmSim stepped by hand at 60 Hz: tasks #12 and
|
||||
## #21's loose animals (scattered outside the pen at the start, roaming the whole farm day and
|
||||
## night without ever leaving it, wandering into the pen, or getting lost on their own, back at
|
||||
## their spots each morning, claimable by thieves, loose again where a killed carrier drops them,
|
||||
## and led in with the follow-trail mechanic); then, with every animal penned up front the old
|
||||
## way, the animals in the pen (wandering, kept in by the pen's gate), an animal thief breaking in,
|
||||
## catching and carrying one off, a dropped animal loose where it fell, leading animals back (at
|
||||
## most three, through a gate), a pen breach letting animals out at night as loose animals (and
|
||||
## not by day; none lost), an unopposed thief carrying one off the farm, supply thieves taking
|
||||
## bundles from the shed's piles (never more than there is), dropping, recovering, and losing
|
||||
## them, the piles growing and shrinking with the stock, thieves falling back to another target,
|
||||
## the asset HUD, the end of the dawn grace, retry, and a farm stripped of all three.
|
||||
|
||||
const P := CampaignController.Phase
|
||||
const S := LootSystem.Status
|
||||
const C := LootSystem.Category
|
||||
const T := ThiefBehavior.State
|
||||
const DT := 1.0 / 60.0
|
||||
const AWAY := Vector3(-11.0, 0.0, 13.0)
|
||||
## Where the scarecrow waits when it isn't needed: off the playable map, so loose animals (#21: they
|
||||
## roam the whole map) never come within reach and start following it.
|
||||
const AWAY := Vector3(-20.0, 0.0, 13.0)
|
||||
|
||||
var _events: Array = [] # [kind, id]
|
||||
|
||||
|
|
@ -55,11 +60,15 @@ func run(r: GameTestRunner) -> void:
|
|||
await r.process_frame
|
||||
|
||||
|
||||
## Task #12: animals start loose, scattered outside the pen, grazing in place; a thief can still
|
||||
## claim and steal one (raising the same theft alert as for a penned one, and same rule as any
|
||||
## theft once it's dropped); the player leads one in with the follow-trail mechanic, entering the
|
||||
## pen makes it home, and FarmState records it as penned so a morning resync keeps it home (and the
|
||||
## rest loose) instead of resetting the herd into the pen.
|
||||
## Tasks #12 and #21: animals start loose, scattered outside the pen. A thief can still claim and
|
||||
## steal a loose animal (raising the same theft alert as for a penned one); killed, it drops the
|
||||
## animal loose where it fell, not lost. Over a long day and night (no thieves) loose animals roam
|
||||
## the whole farm, well away from where they started, but never off the playable map, never into
|
||||
## the (unbuilt) pen, and never lost on their own; each morning they're back at their spots. The
|
||||
## player leads one in with the follow-trail mechanic: entering the pen makes it home, and
|
||||
## FarmState records it as penned so a morning resync keeps it home (and the rest loose) instead of
|
||||
## resetting the herd into the pen. Last, an unopposed thief carries one off the farm: the only way
|
||||
## to lose an animal.
|
||||
func _loose_start(r: GameTestRunner) -> void:
|
||||
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
|
||||
r.root.add_child(farm)
|
||||
|
|
@ -72,29 +81,20 @@ func _loose_start(r: GameTestRunner) -> void:
|
|||
player.global_position = AWAY
|
||||
var loot := sim.loot
|
||||
var animals := sim.animals
|
||||
sim.campaign.begin_day()
|
||||
var c := sim.campaign
|
||||
var s := c.state
|
||||
c.begin_day()
|
||||
var pen := sim.zones.zone(FarmZone.Kind.ANIMAL_PEN).rect()
|
||||
var playable := sim.zones.playable
|
||||
var all_loose := true
|
||||
var all_outside := true
|
||||
for id in range(1, animals.count + 1):
|
||||
all_loose = all_loose and loot.status[loot.animal_item(id)] == S.LOOSE
|
||||
all_outside = all_outside and not pen.has_point(animals.position(id))
|
||||
r.check(all_loose and all_outside and sim.campaign.state.penned_animals.is_empty(),
|
||||
r.check(all_loose and all_outside and s.penned_animals.is_empty(),
|
||||
"%d animals start loose, scattered outside the (unbuilt) pen" % animals.count)
|
||||
# They graze in place near their own spot, not down the escape field toward the edge.
|
||||
var start := animals.pos.duplicate()
|
||||
_step(sim, 600)
|
||||
var moved := 0
|
||||
var strayed := false
|
||||
for id in range(1, animals.count + 1):
|
||||
var d := animals.position(id).distance_to(start[id])
|
||||
if d > 0.2:
|
||||
moved += 1
|
||||
if d > 4.0:
|
||||
strayed = true
|
||||
r.check(moved > 0 and not strayed, "loose animals graze in place (%d of %d moved a little, none wandered off)" % [moved, animals.count])
|
||||
# A thief can still claim and steal a loose animal; killed, it drops the animal, which still
|
||||
# runs for the edge (unchanged DROPPED rule).
|
||||
# A thief can still claim and steal a loose animal; killed, it drops the animal loose where it
|
||||
# fell (#21: not DROPPED, and it doesn't run for the edge).
|
||||
var h := sim.spawn_thief(C.ANIMAL, animals.position(1) + Vector2(1.5, 0.0))
|
||||
_step(sim, 1)
|
||||
var item1 := sim.enemies.target[sim.enemies.resolve_handle(h)]
|
||||
|
|
@ -106,22 +106,72 @@ func _loose_start(r: GameTestRunner) -> void:
|
|||
var caught := _until(sim, func() -> bool: return loot.status[item1] == S.CARRIED, 60.0)
|
||||
r.check(caught < 60.0, "and catches it (%.1f s)" % caught)
|
||||
var dh := sim.enemies.resolve_handle(h)
|
||||
var fell := Vector2(sim.enemies.pos_x[dh], sim.enemies.pos_z[dh])
|
||||
sim.enemies.apply_hit(dh, 99)
|
||||
_step(sim, 1)
|
||||
r.check(loot.status[item1] == S.DROPPED, "killed, it drops the animal loose again (same rule as any theft)")
|
||||
var stolen_index := loot.animal_index(item1)
|
||||
# Build the pen and lead a different (still-loose) animal in.
|
||||
r.check(loot.status[item1] == S.LOOSE and animals.position(stolen_index).distance_to(fell) < 0.2,
|
||||
"killed, it drops the animal loose where it fell (not lost)")
|
||||
# A long day and night with no thieves: they roam the whole farm, and stay on it.
|
||||
var farthest := {"day": PackedFloat32Array(), "night": PackedFloat32Array()}
|
||||
var off_map := 0
|
||||
var into_pen := 0
|
||||
for part: String in ["day", "night"]:
|
||||
if part == "night":
|
||||
_to_night(sim)
|
||||
var start := animals.pos.duplicate()
|
||||
var far := PackedFloat32Array()
|
||||
far.resize(animals.count + 1)
|
||||
for i in 90 * 60:
|
||||
sim.step(DT)
|
||||
if i % 10 != 0:
|
||||
continue
|
||||
for id in range(1, animals.count + 1):
|
||||
var at := animals.position(id)
|
||||
far[id] = maxf(far[id], at.distance_to(start[id]))
|
||||
if not playable.has_point(at):
|
||||
off_map += 1
|
||||
if pen.has_point(at):
|
||||
into_pen += 1
|
||||
farthest[part] = far
|
||||
for part: String in ["day", "night"]:
|
||||
var far: PackedFloat32Array = farthest[part]
|
||||
var roamed := 0
|
||||
var least := INF
|
||||
var most := 0.0
|
||||
for id in range(1, animals.count + 1):
|
||||
if far[id] > 4.0:
|
||||
roamed += 1
|
||||
least = minf(least, far[id])
|
||||
most = maxf(most, far[id])
|
||||
r.info("loose animals over 90 s of %s: %.1f..%.1f m from where they started" % [part, least, most])
|
||||
r.check(roamed == animals.count, "over 90 s of %s, all %d loose animals roam more than 4 m (the least %.1f m, the most %.1f m)"
|
||||
% [part, animals.count, least, most])
|
||||
r.check(off_map == 0 and into_pen == 0 and s.phase == P.NIGHT,
|
||||
"and they stay on the farm: never off the playable map, never into the pen")
|
||||
r.check(loot.count(S.LOOSE, C.ANIMAL) == animals.count and s.lost_animals.is_empty(), "none of them is lost without a thief")
|
||||
# The next morning puts every loose animal back at its spot.
|
||||
c.advance_phase()
|
||||
c.advance_phase()
|
||||
r.check(s.phase == P.MORNING and loot.count(S.LOOSE, C.ANIMAL) == animals.count and _at_loose_spots(sim),
|
||||
"the next morning every loose animal is back at its spot")
|
||||
c.begin_day()
|
||||
# Build the pen and lead a different (still-loose) animal in through its gate. The others are
|
||||
# put back at their spots, south of the pen, so the walk (from east of the gate, straight in
|
||||
# along its line) passes no other animal.
|
||||
PenRing.build_full(sim)
|
||||
_settle(sim)
|
||||
var lead_id := 1
|
||||
animals.sync_from_state()
|
||||
var lead_id := animals.count
|
||||
while lead_id == stolen_index:
|
||||
lead_id += 1
|
||||
lead_id -= 1
|
||||
var item := loot.animal_item(lead_id)
|
||||
var p := animals.position(lead_id)
|
||||
var p := Vector2(PenRing.EAST_X + 10.0, PenRing.GATE_Z)
|
||||
animals.place(lead_id, p)
|
||||
player.global_position = Vector3(p.x + 0.8, 0.0, p.y)
|
||||
_step(sim, 1)
|
||||
r.check(loot.status[item] == S.FOLLOWING, "walking up to a loose animal starts it following, same as a dropped one")
|
||||
var path: Array[Vector2] = [Vector2(p.x, -2.0), Vector2(7.5, -2.0), Vector2(7.5, -6.0), Vector2(0.0, -6.0), Vector2(-3.0, -6.0)]
|
||||
var path: Array[Vector2] = [Vector2(0.0, PenRing.GATE_Z), Vector2(-3.0, PenRing.GATE_Z)]
|
||||
var from := Vector2(player.global_position.x, player.global_position.z)
|
||||
for target in path:
|
||||
while from.distance_to(target) > 0.05:
|
||||
|
|
@ -129,19 +179,23 @@ func _loose_start(r: GameTestRunner) -> void:
|
|||
player.global_position = Vector3(from.x, 0.0, from.y)
|
||||
sim.step(DT)
|
||||
_step(sim, 60)
|
||||
r.check(loot.status[item] == S.HOME and sim.campaign.state.is_animal_penned(lead_id),
|
||||
r.check(loot.status[item] == S.HOME and s.is_animal_penned(lead_id) and loot.followers() == 0,
|
||||
"led through the gate into the pen: it's home, and FarmState records it as penned")
|
||||
player.global_position = AWAY
|
||||
_step(sim, 600)
|
||||
r.check(pen.has_point(animals.position(lead_id)), "once penned, it stays in the pen by day like any other")
|
||||
# A new morning keeps the penned one home and the rest loose, not reset into the pen.
|
||||
# A new morning keeps the penned one home and the rest loose (at their spots), not reset into
|
||||
# the pen.
|
||||
loot.sync_from_state()
|
||||
animals.sync_from_state()
|
||||
var other_id := 1
|
||||
while other_id == stolen_index or other_id == lead_id:
|
||||
other_id += 1
|
||||
r.check(loot.status[item] == S.HOME and sim.campaign.state.is_animal_penned(lead_id), "a new morning keeps the penned one home")
|
||||
r.check(loot.status[loot.animal_item(other_id)] == S.LOOSE, "and a never-led animal loose, not reset into the pen")
|
||||
r.check(loot.status[item] == S.HOME and s.is_animal_penned(lead_id) and s.penned_animals.size() == 1, "a new morning keeps the penned one home")
|
||||
r.check(loot.count(S.LOOSE, C.ANIMAL) == animals.count - 1 and _at_loose_spots(sim), "and every never-led animal loose at its spot, not reset into the pen")
|
||||
# The one way to lose an animal: a thief carrying it off the farm. (Sent in amid the loose
|
||||
# spots, so every loose animal is in plain view.)
|
||||
var h2 := sim.spawn_thief(C.ANIMAL, Vector2(1.5, 0.5))
|
||||
var gone := _until(sim, func() -> bool: return sim.enemies.resolve_handle(h2) == -1, 90.0)
|
||||
r.check(gone < 90.0 and s.lost_animals.size() == 1 and loot.count(S.LOST, C.ANIMAL) == 1,
|
||||
"an unopposed thief carries an animal off the farm: that one, and only that one, is lost (%.1f s)" % gone)
|
||||
farm.queue_free()
|
||||
await r.process_frame
|
||||
|
||||
|
|
@ -189,7 +243,8 @@ func _pen_by_day(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
|
||||
|
||||
## An animal thief breaks the pen's gate, catches an animal, and carries it; killed, it drops the
|
||||
## animal, which runs for the edge of the farm; touched, the animal follows the scarecrow.
|
||||
## animal loose where it fell (#21: no longer penned, but it stays on the farm instead of running
|
||||
## for the edge); touched, the animal follows the scarecrow.
|
||||
func _animal_theft(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
||||
var es := sim.enemies
|
||||
var loot := sim.loot
|
||||
|
|
@ -221,23 +276,23 @@ func _animal_theft(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) ->
|
|||
var at := Vector2(es.pos_x[d], es.pos_z[d])
|
||||
es.apply_hit(d, 99)
|
||||
_step(sim, 1)
|
||||
r.check(loot.status[item] == S.DROPPED and sim.animals.position(index).distance_to(at) < 0.2, "killing the carrier drops the animal where it fell")
|
||||
var near_edge := _edge_distance(sim, sim.animals.position(index))
|
||||
_step(sim, 300)
|
||||
var later := _edge_distance(sim, sim.animals.position(index))
|
||||
r.check(loot.status[item] == S.DROPPED and later < near_edge - 2.0, "the loose animal makes for the edge of the farm (%.1f m -> %.1f m from it)" % [near_edge, later])
|
||||
r.check(loot.status[item] == S.LOOSE and sim.animals.position(index).distance_to(at) < 0.2 and not s.is_animal_penned(index),
|
||||
"killing the carrier drops the animal where it fell: loose (no longer penned), not lost")
|
||||
_step(sim, 1200)
|
||||
r.check(loot.status[item] == S.LOOSE and not s.is_animal_lost(index) and sim.zones.playable.has_point(sim.animals.position(index)),
|
||||
"20 s later it's still loose on the farm (it doesn't run for the edge)")
|
||||
var p := sim.animals.position(index)
|
||||
player.global_position = Vector3(p.x + 0.8, 0.0, p.y)
|
||||
_step(sim, 1)
|
||||
r.check(loot.status[item] == S.FOLLOWING and _has(&"following", item), "walking up to it: it follows the scarecrow")
|
||||
loot.status[item] = S.DROPPED # loose again for the next part
|
||||
sim.animals.place(index, p)
|
||||
_make_loose(sim, index, p) # loose again for the next part
|
||||
player.global_position = AWAY
|
||||
_step(sim, 1)
|
||||
|
||||
|
||||
## Lead loose animals back: at most three follow at once; they pass through a gate behind the
|
||||
## scarecrow, and inside the pen they are home.
|
||||
## scarecrow, and inside the pen they are home. An animal dropped inside the pen (its carrier
|
||||
## stopped there) is home again.
|
||||
func _leading(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
||||
var loot := sim.loot
|
||||
var st := sim.structures
|
||||
|
|
@ -248,7 +303,7 @@ func _leading(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
|||
r.check(not sim.animals.pen_open, "the pen is shut again")
|
||||
var loose: Array[int] = []
|
||||
for id in range(1, sim.animals.count + 1):
|
||||
if loot.status[loot.animal_item(id)] == S.DROPPED:
|
||||
if loot.status[loot.animal_item(id)] == S.LOOSE:
|
||||
loose.append(id)
|
||||
for id in range(1, sim.animals.count + 1):
|
||||
if loose.size() < 4 and loot.status[loot.animal_item(id)] == S.HOME:
|
||||
|
|
@ -259,7 +314,7 @@ func _leading(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
|||
for k in loose.size():
|
||||
player.global_position = Vector3(9.0 + k * 3.0 + 0.6, 0.0, -2.0)
|
||||
_step(sim, 1)
|
||||
r.check(loot.followers() == sim.config.max_following_animals and loot.status[loot.animal_item(loose[3])] == S.DROPPED
|
||||
r.check(loot.followers() == sim.config.max_following_animals and loot.status[loot.animal_item(loose[3])] == S.LOOSE
|
||||
and _has(&"follow_full", loot.animal_item(loose[3])), "three animals follow; the fourth waits (and the scarecrow is told why)")
|
||||
# Walk the line in through the gate: east of the pen, then west through the opening.
|
||||
var path: Array[Vector2] = [Vector2(15.0, -2.0), Vector2(7.5, -2.0), Vector2(7.5, -6.0), Vector2(0.0, -6.0), Vector2(-3.0, -6.0)]
|
||||
|
|
@ -276,20 +331,28 @@ func _leading(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
|||
home += 1
|
||||
r.check(home == 3 and not st.validate("gate", 4.0, -6.0, 2, Vector2(6.0, -6.0)).is_empty(), "the three follow the scarecrow through the gate into the pen")
|
||||
r.check(int(s.night_events.get("animals_recovered", 0)) == recovered_before + 3, "each counts as led back")
|
||||
_make_loose(sim, loose[3], Vector2(-1.0, -2.5)) # the fourth wanders back in by itself
|
||||
# #21: loose animals never wander into the pen by themselves, but one dropped inside it (its
|
||||
# carrier stopped there) is home again, and penned.
|
||||
_events.clear()
|
||||
_make_loose(sim, loose[3], Vector2(-1.0, -2.5))
|
||||
_step(sim, 1)
|
||||
r.check(loot.status[loot.animal_item(loose[3])] == S.HOME, "a loose animal inside the pen is home again")
|
||||
r.check(loot.status[loot.animal_item(loose[3])] == S.HOME and s.is_animal_penned(loose[3]) and _has(&"returned", loot.animal_item(loose[3])),
|
||||
"an animal dropped inside the pen is home again")
|
||||
player.global_position = AWAY
|
||||
_step(sim, 1)
|
||||
|
||||
|
||||
## With the gate down at night, animals wander out of the pen one at a time; a loose one that
|
||||
## reaches the farm's edge is lost. By day an open pen keeps its animals. The end of the dawn grace brings
|
||||
## loose ones back; retry restores the morning.
|
||||
## With the gate down at night, penned animals get out of the pen one at a time: each is loose at
|
||||
## once (#21: no longer penned), walks out through the opening, and roams the farm; none is lost
|
||||
## without a thief. By day an open pen keeps its animals. The next morning the ones that got out
|
||||
## are back at their loose spots (not in the pen) and the rest in the pen. An unopposed thief still
|
||||
## carries one off the farm; retry restores the morning.
|
||||
func _breach(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
||||
var c := sim.campaign
|
||||
var loot := sim.loot
|
||||
var st := sim.structures
|
||||
var s := c.state
|
||||
var pen := sim.zones.zone(FarmZone.Kind.ANIMAL_PEN).rect()
|
||||
var gate := sim.nav.structure_at[sim.nav.cell_of(4.0, -6.0)]
|
||||
st.damage(gate, 999)
|
||||
_settle(sim)
|
||||
|
|
@ -299,39 +362,55 @@ func _breach(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
|||
r.check(not _has(&"strayed", -1) and loot.count(S.HOME, C.ANIMAL) == loot.animal_count - loot.count(S.LOST, C.ANIMAL),
|
||||
"by day the animals stay in an open pen")
|
||||
_to_night(sim)
|
||||
var morning_lost := c.state.lost_animals.duplicate()
|
||||
var morning_lost := s.lost_animals.duplicate()
|
||||
var first := _until(sim, func() -> bool: return _has(&"strayed", -1), sim.config.animal_wander_interval + 1.0)
|
||||
r.check(first <= sim.config.animal_wander_interval * 0.3 + 0.1, "at night an animal soon wanders out of the open pen (%.1f s)" % first)
|
||||
r.check(first <= sim.config.animal_wander_interval * 0.3 + 0.1, "at night an animal soon gets out of the open pen (%.1f s)" % first)
|
||||
var out_item: int = _events.filter(func(e: Array) -> bool: return e[0] == &"strayed")[0][1]
|
||||
var out_id := loot.animal_index(out_item)
|
||||
r.check(loot.status[out_item] == S.LOOSE and not s.is_animal_penned(out_id), "it's loose at once (no longer penned), not dropped or lost")
|
||||
var strays := _until(sim, func() -> bool: return _count(&"strayed") >= 2, sim.config.animal_wander_interval + 1.0)
|
||||
r.check(strays <= sim.config.animal_wander_interval + 0.1, "then another every %.0f s" % sim.config.animal_wander_interval)
|
||||
var lost := _until(sim, func() -> bool: return c.state.lost_animals.size() > morning_lost.size(), 90.0)
|
||||
r.check(lost < 90.0, "a wandering animal that reaches the farm's edge is lost (%.1f s later)" % lost)
|
||||
var loose_at_dawn := loot.count(S.DROPPED, C.ANIMAL)
|
||||
r.check(loose_at_dawn > 0, "some are still loose on the farm (%d)" % loose_at_dawn)
|
||||
var still_lost := c.state.lost_animals.duplicate()
|
||||
var walked := _until(sim, func() -> bool: return not pen.grow(0.75).has_point(sim.animals.position(out_id)), 30.0)
|
||||
r.check(walked < 30.0 and loot.status[out_item] == S.LOOSE, "the first walks out of the pen through the opening")
|
||||
_step(sim, 80 * 60)
|
||||
var roaming := 0
|
||||
var on_farm := true
|
||||
for id in range(1, sim.animals.count + 1):
|
||||
if loot.status[loot.animal_item(id)] == S.LOOSE:
|
||||
roaming += 1
|
||||
var at := sim.animals.position(id)
|
||||
on_farm = on_farm and sim.zones.playable.has_point(at) and not pen.has_point(at)
|
||||
r.check(s.phase == P.NIGHT and roaming >= 2 and on_farm and s.lost_animals == morning_lost and loot.count(S.LOST, C.ANIMAL) == morning_lost.size(),
|
||||
"late in the night %d animals that got out roam the farm outside the pen, and none is lost" % roaming)
|
||||
c.advance_phase()
|
||||
c.advance_phase()
|
||||
r.check(c.state.phase == P.MORNING and loot.count(S.DROPPED, C.ANIMAL) == 0 and c.state.lost_animals == still_lost
|
||||
and loot.count(S.HOME, C.ANIMAL) == loot.animal_count - still_lost.size(), "the end of the dawn grace brings the loose ones back to the pen")
|
||||
var pen := sim.zones.zone(FarmZone.Kind.ANIMAL_PEN).rect()
|
||||
var penned := s.penned_animals.size()
|
||||
r.check(s.phase == P.MORNING and s.lost_animals == morning_lost and loot.count(S.HOME, C.ANIMAL) == penned
|
||||
and loot.count(S.LOOSE, C.ANIMAL) == loot.animal_count - morning_lost.size() - penned and penned < loot.animal_count - morning_lost.size(),
|
||||
"the next morning the ones that got out are still loose (not put back in the pen), the rest penned")
|
||||
var inside := true
|
||||
for id in range(1, sim.animals.count + 1):
|
||||
if loot.status[loot.animal_item(id)] == S.HOME:
|
||||
inside = inside and pen.has_point(sim.animals.position(id))
|
||||
r.check(inside and sim.animals.pen_open, "every animal left is in the pen (still open: the gate is gone)")
|
||||
r.check(inside and _at_loose_spots(sim) and sim.animals.pen_open,
|
||||
"every penned animal is in the pen and every loose one at its spot (the pen still open: the gate is gone)")
|
||||
r.check(sim.review_panel._body.text.contains("The pen is open"), "the morning review says the pen is open")
|
||||
var e: Dictionary = c.state.night_log[c.state.night_log.size() - 1]
|
||||
r.check(e["animals_lost"] == still_lost.size() - morning_lost.size() and e["animals_strayed"] >= 2, "the night's record: %s" % [e])
|
||||
# Retry: lose another one tonight, fall, and the morning comes back.
|
||||
var morning := c.state.to_dict()
|
||||
var e: Dictionary = s.night_log[s.night_log.size() - 1]
|
||||
r.check(e["animals_lost"] == 0 and e["animals_strayed"] >= 2, "the night's record: %s" % [e])
|
||||
# Retry: lose one to a thief tonight (the only way to lose an animal), fall, and the morning
|
||||
# comes back. The thief is sent in amid the loose spots: it takes a loose animal in plain view,
|
||||
# or breaks into the pen (right behind it) for a penned one. (A thief after a loose animal it
|
||||
# can't see heads for the pen meanwhile and gives up on it after a while.)
|
||||
var still_lost := s.lost_animals.duplicate()
|
||||
var morning := s.to_dict()
|
||||
c.begin_day()
|
||||
c.state.resources.shed = {"wood": 50, "scrap": 50, "straw": 50}
|
||||
s.resources.shed = {"wood": 50, "scrap": 50, "straw": 50}
|
||||
st.place("gate", 4.0, -6.0, 2)
|
||||
_to_night(sim)
|
||||
var h := sim.spawn_thief(C.ANIMAL, GameTestRunner.EDGE["west"])
|
||||
var h := sim.spawn_thief(C.ANIMAL, Vector2(1.5, 0.5))
|
||||
_until(sim, func() -> bool: return sim.enemies.resolve_handle(h) == -1, 90.0)
|
||||
r.check(c.state.lost_animals.size() >= still_lost.size() + 1, "an unopposed animal thief carries one off the farm")
|
||||
c.state.scarecrow_hp = 0
|
||||
r.check(s.lost_animals.size() >= still_lost.size() + 1, "an unopposed animal thief carries one off the farm")
|
||||
s.scarecrow_hp = 0
|
||||
_step(sim, 1)
|
||||
c.retry_night()
|
||||
_step(sim, 1)
|
||||
|
|
@ -503,15 +582,23 @@ func _stripped(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
"carried off with nothing else left: the farm is stripped (D2)")
|
||||
|
||||
|
||||
## Puts an animal loose at p (as if dropped there).
|
||||
## Puts an animal loose at p, as if its carrier was stopped there (#21: LOOSE and no longer penned;
|
||||
## inside the pen it's home again on the next tick).
|
||||
func _make_loose(sim: FarmSim, id: int, p: Vector2) -> void:
|
||||
var item := sim.loot.animal_item(id)
|
||||
sim.loot.status[item] = S.DROPPED
|
||||
sim.loot.holder[item] = -1
|
||||
sim.loot.ground[item] = p
|
||||
sim.loot.animal_loose(sim.loot.animal_item(id), p)
|
||||
sim.animals.place(id, p)
|
||||
|
||||
|
||||
## Every loose animal stands at its own GameConfig.animal_loose_spots spot.
|
||||
func _at_loose_spots(sim: FarmSim) -> bool:
|
||||
var spots := sim.config.animal_loose_spots
|
||||
for id in range(1, sim.animals.count + 1):
|
||||
if sim.loot.status[sim.loot.animal_item(id)] == S.LOOSE \
|
||||
and sim.animals.position(id).distance_to(spots[(id - 1) % spots.size()]) > 0.01:
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func _to_night(sim: FarmSim) -> void:
|
||||
var c := sim.campaign
|
||||
while c.state.phase != P.NIGHT:
|
||||
|
|
@ -536,10 +623,6 @@ func _count(kind: StringName) -> int:
|
|||
return n
|
||||
|
||||
|
||||
func _edge_distance(sim: FarmSim, p: Vector2) -> float:
|
||||
return sim.nav.meters(sim.escape_field[sim.nav.cell_of(p.x, p.y)])
|
||||
|
||||
|
||||
func _edge_cell(sim: FarmSim, side: String) -> int:
|
||||
var p: Vector2 = GameTestRunner.EDGE[side]
|
||||
return sim.nav.nearest_free(sim.nav.cell_of(p.x, p.y))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue