Task #21: animals roam the whole farm, never lost on their own
Loose animals now roam the whole playable map, day and night. Each walk goes to a goal 4-8 m away that is walkable, in a clear straight line, at least 2 m inside FarmZones.playable (passed into AnimalSystem.setup), and neither inside the pen nor across it. Every morning a loose animal is back at its loose spot (no save change). Animals no longer escape on their own: - _stray and LootSystem.animal_escaped are gone. - A new LootSystem.animal_loose makes an animal LOOSE where it stands and unpens it. It covers a carrier killed or scared (drop), a broken follow leash, and an animal getting out of an open pen (animal_strays, which still records animals_strayed). - An animal dropped inside the pen is home again. - An animal let out of an open pen walks out along the escape field, then roams. If the pen shuts first, it stays home. - return_dropped still pens followers at dawn's end, but leaves loose animals loose. - The only loss paths left are a carrier leaving the farm (thief escape, or removal with reason LEFT). Loose spots at x = -12 move inward to (6|9|12, 0.5). The toast, review-panel, dropped-animal toast, RULES.md and header text no longer promise animals wander off or run for the edge. test_targets: _loose_start has a 90 s day + 90 s night roam run (every animal >4 m, never off the map or into the pen, none lost), a morning reset to the spots, a killed carrier leaving the animal loose, and an unopposed thief carrying one off. _animal_theft, _leading, _breach and _make_loose follow the new rules. AWAY moves off the map so roaming animals can't start following the parked scarecrow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
26b735d3e6
commit
aaf5a81b4e
8 changed files with 379 additions and 226 deletions
|
|
@ -12,18 +12,20 @@ extends Node3D
|
|||
## HOME in its plot, the pen, or the shed. One thief at a time may claim it: it is then
|
||||
## targeted ("!" marker) and, while being taken, shows a filling progress ring.
|
||||
## CARRIED on a thief, outlined in its category's color, with a badge over it.
|
||||
## DROPPED its carrier was stopped. A crop or a sack lies on the ground, glowing; an animal is
|
||||
## loose and makes for the farm's edge (AnimalSystem). The scarecrow walks up to it to
|
||||
## recover it (a loose animal then follows it, at most max_following_animals at once),
|
||||
## and another thief may claim it.
|
||||
## FOLLOWING animals only: following the scarecrow; back inside the pen it is home.
|
||||
## LOOSE animals only (#12): starts here, scattered outside the pen, grazing calmly in place
|
||||
## (AnimalSystem) instead of making for the edge. A thief may still claim and carry one
|
||||
## off (then it's DROPPED, same as any theft: it runs for the edge). The scarecrow
|
||||
## walking up to it starts it following, same as a dropped animal; entering the pen
|
||||
## makes it HOME, and FarmState records it as penned so sync_from_state() keeps it
|
||||
## home each morning instead of resetting it loose.
|
||||
## LOST carried (or, for an animal, wandered) off the farm. Crops and animals are recorded
|
||||
## DROPPED crops and sacks: its carrier was stopped, and it lies on the ground, glowing. The
|
||||
## scarecrow walks up to it to recover it, and another thief may claim it. (An animal
|
||||
## whose carrier was stopped is LOOSE where it fell instead, #21.)
|
||||
## FOLLOWING animals only: following the scarecrow (at most max_following_animals at once);
|
||||
## back inside the pen it is home.
|
||||
## LOOSE animals only (#12, #21): out of the pen, roaming the whole farm (AnimalSystem),
|
||||
## never off it on its own. Every animal starts here; one also gets here when its
|
||||
## carrier is stopped (animal_loose; inside the pen it's home again), when it gets out
|
||||
## of an open pen at night (animal_strays), or when its scarecrow got too far ahead.
|
||||
## FarmState stops counting it as penned, so the next morning puts it back at its
|
||||
## loose spot. A thief may claim and carry one off. The scarecrow walking up to it
|
||||
## starts it following; entering the pen makes it HOME, and FarmState records it as
|
||||
## penned so sync_from_state() keeps it home each morning.
|
||||
## LOST carried off the farm, the only way to lose an item. Crops and animals are recorded
|
||||
## in FarmState and gone for the rest of the run; a sack's contents are gone and the
|
||||
## sack is free for the next theft.
|
||||
## DORMANT crops only (#13): a unit of one of the later fields (lettuce/cabbage, corn) that
|
||||
|
|
@ -67,8 +69,8 @@ const THREAT_COLORS := {
|
|||
|
||||
## kind: &"targeted", &"stolen", &"dropped", &"recovered", &"returned" (back home without the
|
||||
## scarecrow's help: auto at dawn, or an animal dropped inside the pen), &"lost", &"following",
|
||||
## &"follow_full" (the scarecrow already leads the most animals it can), &"strayed" (an animal
|
||||
## wandered out of an open pen).
|
||||
## &"follow_full" (the scarecrow already leads the most animals it can), &"strayed" (an animal got
|
||||
## out of an open pen: it's loose now).
|
||||
signal loot_event(kind: StringName, id: int, position: Vector3)
|
||||
|
||||
var campaign: CampaignController
|
||||
|
|
@ -390,15 +392,18 @@ func pick_up(id: int, handle: int) -> bool:
|
|||
return true
|
||||
|
||||
|
||||
## The carrier was stopped at (x, z).
|
||||
## The carrier was stopped at (x, z). A crop or sack lies there DROPPED; an animal is loose there
|
||||
## (#21), and AnimalSystem makes it home again if that's inside the pen.
|
||||
func drop(id: int, handle: int, x: float, z: float) -> void:
|
||||
if not is_valid_unit(id) or status[id] != Status.CARRIED or holder[id] != handle:
|
||||
return
|
||||
status[id] = Status.DROPPED
|
||||
holder[id] = -1
|
||||
ground[id] = Vector2(x, z)
|
||||
if category[id] == Category.ANIMAL and animals != null:
|
||||
animals.place(animal_index(id), ground[id])
|
||||
if category[id] == Category.ANIMAL:
|
||||
animal_loose(id, ground[id])
|
||||
if animals != null:
|
||||
animals.place(animal_index(id), ground[id])
|
||||
loot_event.emit(&"dropped", id, _world(ground[id]))
|
||||
|
||||
|
||||
|
|
@ -409,9 +414,9 @@ func escape(id: int, handle: int) -> void:
|
|||
_lose(id)
|
||||
|
||||
|
||||
## The scarecrow got a dropped (or loose, #12) item back: a crop returns to its plot, a sack to
|
||||
## the shed, and an animal starts following (if the scarecrow has room for another) -- a dropped
|
||||
## one recovered from a thief exactly as before, and a loose one led in for the first time.
|
||||
## The scarecrow got a dropped item (or a loose animal, #12) back: a crop returns to its plot, a
|
||||
## sack to the shed, and a loose animal starts following (if the scarecrow has room for another),
|
||||
## whether a thief dropped it, it got out of the pen, or it was never led in.
|
||||
func recover(id: int) -> bool:
|
||||
if not is_valid_unit(id):
|
||||
return false
|
||||
|
|
@ -441,11 +446,12 @@ func recover(id: int) -> bool:
|
|||
return true
|
||||
|
||||
|
||||
## An animal (loose, or following the scarecrow) is back inside the pen.
|
||||
## An animal (following the scarecrow, or loose: dropped inside the pen, or shut in before it got
|
||||
## out) is back inside the pen.
|
||||
func animal_home(id: int) -> void:
|
||||
if not is_valid_unit(id) or category[id] != Category.ANIMAL:
|
||||
return
|
||||
if status[id] != Status.FOLLOWING and status[id] != Status.DROPPED:
|
||||
if status[id] != Status.FOLLOWING and status[id] != Status.DROPPED and status[id] != Status.LOOSE:
|
||||
return
|
||||
var led := status[id] == Status.FOLLOWING
|
||||
status[id] = Status.HOME
|
||||
|
|
@ -457,29 +463,37 @@ func animal_home(id: int) -> void:
|
|||
loot_event.emit(&"recovered" if led else &"returned", id, _world(position_of(id)))
|
||||
|
||||
|
||||
## An animal at home walks out of the open pen: it is loose now.
|
||||
## An animal at home gets out of the open pen: it is loose now (and roams; it isn't lost).
|
||||
func animal_strays(id: int) -> void:
|
||||
if not is_valid_unit(id) or category[id] != Category.ANIMAL or status[id] != Status.HOME or holder[id] != -1:
|
||||
return
|
||||
status[id] = Status.DROPPED
|
||||
ground[id] = position_of(id)
|
||||
animal_loose(id, position_of(id))
|
||||
campaign.state.record_event("animals_strayed")
|
||||
loot_event.emit(&"strayed", id, _world(ground[id]))
|
||||
|
||||
|
||||
## A loose animal got off the farm on its own.
|
||||
func animal_escaped(id: int) -> void:
|
||||
if not is_valid_unit(id) or category[id] != Category.ANIMAL or status[id] != Status.DROPPED:
|
||||
## #21: an animal is loose at `at` -- its carrier was stopped there, it got out of the open pen, or
|
||||
## its scarecrow got too far ahead -- and no longer penned in FarmState, so the next morning puts it
|
||||
## back at its loose spot. Animals are never lost on their own; only a carrier leaving the farm
|
||||
## loses one (escape).
|
||||
func animal_loose(id: int, at: Vector2) -> void:
|
||||
if not is_valid_unit(id) or category[id] != Category.ANIMAL or status[id] == Status.LOST:
|
||||
return
|
||||
_lose(id)
|
||||
status[id] = Status.LOOSE
|
||||
holder[id] = -1
|
||||
progress[id] = 0.0
|
||||
ground[id] = at
|
||||
campaign.state.unpen_animal(animal_index(id))
|
||||
|
||||
|
||||
## End of the dawn grace (D6): dropped items still on the ground go home (crops to their plots,
|
||||
## sacks to the shed); loose and following animals are back in the pen.
|
||||
## sacks to the shed), and animals still following the scarecrow are back in the pen. Loose
|
||||
## animals stay loose (#21): the next morning puts them back at their loose spots.
|
||||
func return_dropped() -> void:
|
||||
for id in range(1, item_count + 1):
|
||||
var st := status[id]
|
||||
if st == Status.DROPPED or (st == Status.FOLLOWING and category[id] == Category.ANIMAL):
|
||||
var animal := category[id] == Category.ANIMAL
|
||||
if (st == Status.DROPPED and not animal) or (st == Status.FOLLOWING and animal):
|
||||
var at := _world(position_of(id))
|
||||
if category[id] == Category.SUPPLY:
|
||||
_empty_sack(id, true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue