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
|
|
@ -1,25 +1,30 @@
|
|||
class_name AnimalSystem
|
||||
extends Node3D
|
||||
## The pen's animals as moving entities. Their theft state lives in LootSystem; this moves and
|
||||
## The farm's animals as moving entities. Their theft state lives in LootSystem; this moves and
|
||||
## shows them:
|
||||
## loose (LOOSE) #12, #21: where every animal starts, at its own GameConfig.animal_loose_spots
|
||||
## spot outside the pen, and where a loose one is back every morning. It roams
|
||||
## the whole farm, day and night: each walk goes to a spot ROAM_MIN..ROAM_MAX
|
||||
## meters away that it can reach in a straight line, inside the playable map
|
||||
## (ROAM_MARGIN in from its edge) and outside the pen, and then it stops to
|
||||
## graze. Structures stop it. It never leaves the farm on its own and never
|
||||
## walks into the pen by itself. A thief may claim and carry it off; a stopped
|
||||
## carrier drops it loose where it fell (inside the pen, it's home again). The
|
||||
## scarecrow walking up to it starts it following.
|
||||
## in the pen (HOME) wander between random spots in the pen, pausing to graze; one a thief is
|
||||
## catching stands still. At night (night and dawn), while the pen is open (a
|
||||
## way out that crosses no structure: its gate broken or taken down), one calm
|
||||
## animal wanders out every animal_wander_interval and is loose (DROPPED).
|
||||
## grazing (LOOSE) #12: where every animal starts, scattered at its own GameConfig.
|
||||
## animal_loose_spots spot outside the pen. Same calm wander as a penned
|
||||
## animal, but anchored to that spot instead of the pen, and never walks the
|
||||
## escape field on its own. A thief may still claim and carry it off (then
|
||||
## it's DROPPED, below); the scarecrow walking up to it starts it following,
|
||||
## same as a dropped one.
|
||||
## loose (DROPPED) dropped by its thief, or wandered out of an open pen: walks toward the
|
||||
## farm's nearest edge along the escape field at stray_speed, stopping to
|
||||
## graze now and then, and can't pass structures. At the edge it is lost;
|
||||
## inside the pen it is home again.
|
||||
## way out that crosses no structure: nothing built yet, or its gate broken or
|
||||
## taken down), one calm animal gets out every animal_wander_interval: it's
|
||||
## loose at once (and no longer penned), walks out of the pen along the escape
|
||||
## field at stray_speed, and then roams like any loose animal. If the pen shuts
|
||||
## before it's out, it stays home.
|
||||
## following walks the scarecrow's trail (so it goes wherever the scarecrow went, gates
|
||||
## included), in line behind it. Inside the pen it is home (returned) and calm
|
||||
## for animal_calm_time.
|
||||
## for animal_calm_time. A follower whose scarecrow got FOLLOW_LEASH away is
|
||||
## loose where it stands.
|
||||
## carried held under its thief, wriggling.
|
||||
## An animal is never left DROPPED (that's for crops and sacks), and the only way to lose one is a
|
||||
## thief carrying it off the farm (LootSystem.escape).
|
||||
## The farm pack's animals are static meshes, so walking is procedural: chickens hop, pigs and
|
||||
## sheep waddle. Each scene animal (a farm-pack prefab under the pen zone) is reparented under a
|
||||
## pivot at the middle of its body.
|
||||
|
|
@ -31,8 +36,15 @@ const FOLLOW_GAP := 1.0
|
|||
const FOLLOW_FIRST := 1.5
|
||||
## A follower whose scarecrow got this far away (a retry, a fall) is loose again.
|
||||
const FOLLOW_LEASH := 20.0
|
||||
## A grazing (LOOSE) animal's wander goals stay within this many meters of its loose spot.
|
||||
const LOOSE_WANDER_RADIUS := 0.8
|
||||
## #21: a loose (LOOSE) animal's next wander goal is this many meters from where it stands...
|
||||
const ROAM_MIN := 4.0
|
||||
const ROAM_MAX := 8.0
|
||||
## ...and at least this far inside the playable map's edge.
|
||||
const ROAM_MARGIN := 2.0
|
||||
## Loose animals keep this far out of the pen's rectangle (goals), and never cut across it.
|
||||
const PEN_KEEP_OUT := 1.0
|
||||
## Seconds an animal walking out of an open pen keeps at it before it settles back in.
|
||||
const LEAVE_TIME := 30.0
|
||||
|
||||
## The pen opened (its gate broken or taken down) or was shut again.
|
||||
signal pen_changed(open: bool)
|
||||
|
|
@ -44,7 +56,10 @@ var loot: LootSystem
|
|||
var enemies: EnemySystem
|
||||
var player: Node3D
|
||||
var pen: Rect2
|
||||
## Set by FarmSim: the field loose animals walk along, toward the farm's nearest edge.
|
||||
## The playable map (FarmZones.playable): loose animals roam inside it.
|
||||
var farm_rect := Rect2()
|
||||
## Set by FarmSim: the field toward the farm's nearest edge. An animal getting out of an open pen
|
||||
## walks down it until it's out of the pen (and no further).
|
||||
var escape_field := PackedInt32Array()
|
||||
var count: int = 0
|
||||
## There's a way out of the pen that crosses no structure.
|
||||
|
|
@ -61,14 +76,14 @@ var calm := PackedFloat32Array()
|
|||
var phase := PackedFloat32Array()
|
||||
## Order in the line behind the scarecrow (0 = first), -1 when not following.
|
||||
var slot := PackedInt32Array()
|
||||
## Wandering out of the open pen and not out yet (so being inside doesn't count as home).
|
||||
## Loose and walking out of the open pen, not out yet (so being inside doesn't make it home).
|
||||
var leaving := PackedByteArray()
|
||||
var kinds: Array[String] = []
|
||||
|
||||
var _start := PackedVector2Array()
|
||||
var _start_yaw := PackedFloat32Array()
|
||||
## #12: each animal's grazing spot outside the pen, where it starts (GameConfig.animal_loose_spots,
|
||||
## cycled if there are more animals than spots) and wanders around while LOOSE.
|
||||
## #12: each animal's spot outside the pen (GameConfig.animal_loose_spots, cycled if there are
|
||||
## more animals than spots), where it starts and where it's back every morning while LOOSE.
|
||||
var _loose_spot := PackedVector2Array()
|
||||
var _pivots: Array[Node3D] = []
|
||||
var _meshes: Array = [] # per animal: Array[MeshInstance3D]
|
||||
|
|
@ -92,8 +107,10 @@ static func find_animals(pen_zone: Node3D) -> Array[Node3D]:
|
|||
return out
|
||||
|
||||
|
||||
## p_farm_rect: the playable map (FarmZones.playable), where loose animals roam; empty means the
|
||||
## whole navigation grid.
|
||||
func setup(p_campaign: CampaignController, pen_zone: FarmZone, p_nav: FarmNavigation, p_loot: LootSystem,
|
||||
p_enemies: EnemySystem, p_player: Node3D) -> void:
|
||||
p_enemies: EnemySystem, p_player: Node3D, p_farm_rect: Rect2 = Rect2()) -> void:
|
||||
campaign = p_campaign
|
||||
config = p_campaign.config
|
||||
nav = p_nav
|
||||
|
|
@ -102,6 +119,8 @@ func setup(p_campaign: CampaignController, pen_zone: FarmZone, p_nav: FarmNaviga
|
|||
player = p_player
|
||||
leaders = [p_player]
|
||||
pen = pen_zone.rect()
|
||||
farm_rect = p_farm_rect if p_farm_rect.has_area() \
|
||||
else Rect2(nav.origin_x, nav.origin_z, nav.width * nav.cell_size, nav.height * nav.cell_size).grow(-nav.cell_size)
|
||||
_rng.seed = 8061
|
||||
var found := find_animals(pen_zone)
|
||||
count = found.size()
|
||||
|
|
@ -142,8 +161,8 @@ func setup(p_campaign: CampaignController, pen_zone: FarmZone, p_nav: FarmNaviga
|
|||
sync_from_state()
|
||||
|
||||
|
||||
## Every animal back at its spot -- in the pen if penned, or its loose spot outside it otherwise
|
||||
## (or hidden if lost) -- nobody following (new morning, retry).
|
||||
## Every animal back at its spot -- in the pen if penned, or its loose spot outside it otherwise,
|
||||
## wherever it roamed (or hidden if lost) -- nobody following (new morning, retry).
|
||||
func sync_from_state() -> void:
|
||||
for k in _trails.size():
|
||||
_trails[k] = PackedVector2Array()
|
||||
|
|
@ -200,7 +219,8 @@ func place(id: int, p: Vector2) -> void:
|
|||
pos[id] = p
|
||||
prev[id] = p
|
||||
speed[id] = 0.0
|
||||
timer[id] = _rng.randf_range(0.6, 1.2) # a moment's shock before it bolts
|
||||
leaving[id] = 0
|
||||
timer[id] = _rng.randf_range(0.6, 1.2) # a moment's shock before it wanders off
|
||||
|
||||
|
||||
func start_following(id: int) -> void:
|
||||
|
|
@ -266,18 +286,17 @@ func step(dt: float) -> void:
|
|||
LootSystem.Status.HOME:
|
||||
slot[id] = -1
|
||||
_wander(id, item, dt)
|
||||
LootSystem.Status.LOOSE:
|
||||
LootSystem.Status.LOOSE, LootSystem.Status.DROPPED:
|
||||
slot[id] = -1
|
||||
_wander(id, item, dt)
|
||||
LootSystem.Status.DROPPED:
|
||||
slot[id] = -1
|
||||
if not in_pen(pos[id]):
|
||||
leaving[id] = 0
|
||||
if in_pen(pos[id]) and leaving[id] == 0:
|
||||
loot.animal_home(item)
|
||||
if loot.status[item] == LootSystem.Status.DROPPED:
|
||||
loot.animal_loose(item, pos[id]) # #21: an animal is never left lying dropped
|
||||
if leaving[id] == 1:
|
||||
_leave_pen(id, item, dt)
|
||||
elif pen.has_point(pos[id]):
|
||||
loot.animal_home(item) # dropped inside the pen: it's home again
|
||||
_rest(id)
|
||||
else:
|
||||
_stray(id, item, dt)
|
||||
_wander(id, item, dt)
|
||||
LootSystem.Status.FOLLOWING:
|
||||
var k := clampi(leader[id], 0, at.size() - 1)
|
||||
_follow(id, item, at[k], dt)
|
||||
|
|
@ -311,6 +330,8 @@ func _wander(id: int, item: int, dt: float) -> void:
|
|||
goal[id] = _wander_goal(id, item)
|
||||
speed[id] = float(WANDER_SPEED.get(kinds[id], 0.7))
|
||||
timer[id] = 8.0 # give up on a goal it can't reach
|
||||
if loot.status[item] == LootSystem.Status.LOOSE:
|
||||
timer[id] = maxf(timer[id], pos[id].distance_to(goal[id]) / speed[id] + 2.0) # a longer walk
|
||||
return
|
||||
var to := goal[id] - pos[id]
|
||||
if to.length() < 0.2 or timer[id] <= 0.0:
|
||||
|
|
@ -319,21 +340,21 @@ func _wander(id: int, item: int, dt: float) -> void:
|
|||
_move(id, to.normalized(), speed[id], dt)
|
||||
|
||||
|
||||
func _stray(id: int, item: int, dt: float) -> void:
|
||||
if escape_field.size() > 0 and escape_field[nav.cell_of(pos[id].x, pos[id].y)] == 0:
|
||||
loot.animal_escaped(item)
|
||||
speed[id] = 0.0
|
||||
return
|
||||
## A loose animal that got out of the open pen walks down the escape field until it's out of the
|
||||
## pen (then it roams like any loose animal). If the pen shuts first, or it can't get out in
|
||||
## LEAVE_TIME, it settles: back home if it's still inside the pen.
|
||||
func _leave_pen(id: int, item: int, dt: float) -> void:
|
||||
var out := not pen.grow(0.75).has_point(pos[id])
|
||||
timer[id] -= dt
|
||||
if timer[id] <= 0.0:
|
||||
if speed[id] > 0.0:
|
||||
speed[id] = 0.0 # graze a moment
|
||||
timer[id] = _rng.randf_range(0.8, 1.8)
|
||||
else:
|
||||
speed[id] = config.stray_speed
|
||||
timer[id] = _rng.randf_range(3.0, 5.0)
|
||||
if speed[id] > 0.0 and escape_field.size() > 0 and nav.flow_direction(escape_field, pos[id].x, pos[id].y, _dir):
|
||||
if not out and pen_open and timer[id] > 0.0 and escape_field.size() > 0 \
|
||||
and nav.flow_direction(escape_field, pos[id].x, pos[id].y, _dir):
|
||||
speed[id] = config.stray_speed
|
||||
_move(id, Vector2(_dir[0], _dir[1]), speed[id], dt)
|
||||
return
|
||||
leaving[id] = 0
|
||||
if pen.has_point(pos[id]):
|
||||
loot.animal_home(item)
|
||||
_rest(id)
|
||||
|
||||
|
||||
func _follow(id: int, item: int, sc: Vector2, dt: float) -> void:
|
||||
|
|
@ -344,8 +365,7 @@ func _follow(id: int, item: int, sc: Vector2, dt: float) -> void:
|
|||
_rest(id)
|
||||
return
|
||||
if pos[id].distance_to(sc) > FOLLOW_LEASH:
|
||||
loot.status[item] = LootSystem.Status.DROPPED
|
||||
loot.ground[item] = pos[id]
|
||||
loot.animal_loose(item, pos[id])
|
||||
slot[id] = -1
|
||||
_rest(id)
|
||||
return
|
||||
|
|
@ -384,8 +404,10 @@ func _rest(id: int) -> void:
|
|||
timer[id] = _rng.randf_range(1.5, 4.0)
|
||||
|
||||
|
||||
## A HOME animal wanders inside the pen; a LOOSE one grazes within LOOSE_WANDER_RADIUS of its own
|
||||
## loose spot instead.
|
||||
## A HOME animal wanders inside the pen. A LOOSE one (#21) roams the farm: its next goal is
|
||||
## ROAM_MIN..ROAM_MAX meters away, inside the playable map (ROAM_MARGIN in from the edge),
|
||||
## walkable, in a clear straight line (no obstacle or structure in the way), and neither inside the
|
||||
## pen (PEN_KEEP_OUT around it) nor across it. With no such goal it stays put a while.
|
||||
func _wander_goal(id: int, item: int) -> Vector2:
|
||||
if loot.status[item] == LootSystem.Status.HOME:
|
||||
var area := pen.grow(-1.2)
|
||||
|
|
@ -394,16 +416,35 @@ func _wander_goal(id: int, item: int) -> Vector2:
|
|||
if nav.is_walkable(nav.cell_of(p.x, p.y)):
|
||||
return p
|
||||
return area.get_center()
|
||||
var center := _loose_spot[id]
|
||||
for attempt in 12:
|
||||
var p := center + Vector2(_rng.randf_range(-LOOSE_WANDER_RADIUS, LOOSE_WANDER_RADIUS),
|
||||
_rng.randf_range(-LOOSE_WANDER_RADIUS, LOOSE_WANDER_RADIUS))
|
||||
if nav.is_walkable(nav.cell_of(p.x, p.y)):
|
||||
return p
|
||||
return center
|
||||
var from := pos[id]
|
||||
var area := farm_rect.grow(-ROAM_MARGIN)
|
||||
var keep_out := pen.grow(PEN_KEEP_OUT)
|
||||
# Dropped off the map by a carrier: reach far enough to get back on.
|
||||
var reach := ROAM_MAX + from.distance_to(Vector2(clampf(from.x, area.position.x, area.end.x),
|
||||
clampf(from.y, area.position.y, area.end.y)))
|
||||
for attempt in 16:
|
||||
var p := from + Vector2.from_angle(_rng.randf() * TAU) * _rng.randf_range(ROAM_MIN, reach)
|
||||
if not area.has_point(p) or keep_out.has_point(p) or not nav.is_walkable(nav.cell_of(p.x, p.y)):
|
||||
continue
|
||||
if _crosses(pen, from, p) or not nav.line_clear(from.x, from.y, p.x, p.y):
|
||||
continue
|
||||
return p
|
||||
return from
|
||||
|
||||
|
||||
## At night, while the pen is open, a calm animal walks out now and then.
|
||||
## Whether the segment a..b touches the rectangle.
|
||||
static func _crosses(r: Rect2, a: Vector2, b: Vector2) -> bool:
|
||||
if r.has_point(a) or r.has_point(b):
|
||||
return true
|
||||
var corners := [r.position, Vector2(r.end.x, r.position.y), r.end, Vector2(r.position.x, r.end.y)]
|
||||
for k in 4:
|
||||
if Geometry2D.segment_intersects_segment(a, b, corners[k], corners[(k + 1) % 4]) != null:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
## At night, while the pen is open, a calm animal gets out now and then: it's loose (LootSystem.
|
||||
## animal_strays) and walks out of the pen (_leave_pen).
|
||||
func _wander_out(dt: float) -> void:
|
||||
var ph := campaign.state.phase
|
||||
if not pen_open or (ph != CampaignController.Phase.NIGHT and ph != CampaignController.Phase.DAWN):
|
||||
|
|
@ -422,7 +463,7 @@ func _wander_out(dt: float) -> void:
|
|||
loot.animal_strays(loot.animal_item(id))
|
||||
leaving[id] = 1
|
||||
speed[id] = config.stray_speed
|
||||
timer[id] = 4.0
|
||||
timer[id] = LEAVE_TIME
|
||||
|
||||
|
||||
func _record_trail(k: int, sc: Vector2) -> void:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ extends Node
|
|||
## repair, shed drop-off) -> weapons (recharge, switching) -> aim and attack (pitchfork, corn
|
||||
## shooter, pumpkin bombs) -> enemies (behavior, steering, motion, collision, traps) -> enemy
|
||||
## melee -> automated defenses -> shots -> pumpkin bombs -> recovery by touch -> animals
|
||||
## (wander, stray, follow) -> night arrivals (WaveDirector) -> deferred enemy removals ->
|
||||
## (wander, roam, follow) -> night arrivals (WaveDirector) -> deferred enemy removals ->
|
||||
## flow-field rebuild slice -> render upload -> campaign phase timers and outcome.
|
||||
## Whenever the structures change (built, broken, dismantled), the flow fields are rebuilt as
|
||||
## FieldJobs in slices of flow_slice_cells per tick; thieves keep using the old fields until the
|
||||
|
|
@ -16,8 +16,8 @@ extends Node
|
|||
## escape: WaveDirector.ground_spawns are the edge cells with a route in), owns the combat and theft systems,
|
||||
## and applies the phase rules: thieves arrive only at night (the night's NightPlan, run by
|
||||
## WaveDirector), sunrise makes them retreat (carriers keep running), the end of the dawn grace
|
||||
## sends the rest off the farm with whatever they carry, returns dropped loot (and loose animals)
|
||||
## home, and regrows the gather points, and every new morning (also after a retry) resets the
|
||||
## sends the rest off the farm with whatever they carry, returns dropped loot (and the animals
|
||||
## still following the scarecrow) home, and regrows the gather points, and every new morning (also after a retry) resets the
|
||||
## theft state from the farm state. DayNight lights the phases; PhaseHud, AssetHud, ReviewPanel,
|
||||
## and the other HUD parts show them. Co-op (CoopSession): a second scarecrow (add_partner) is
|
||||
## simulated alongside the first, and on the partner's machine the farm is a replica: nothing is
|
||||
|
|
@ -182,7 +182,7 @@ func _ready() -> void:
|
|||
loot.animals = animals
|
||||
loot.shed_stock = shed_stock
|
||||
loot.setup(campaign, zones.crop_units(), enemies, AnimalSystem.find_animals(pen_zone).size())
|
||||
animals.setup(campaign, pen_zone, nav, loot, enemies, player)
|
||||
animals.setup(campaign, pen_zone, nav, loot, enemies, player, zones.playable)
|
||||
if animals.count != config.start_animals:
|
||||
push_warning("The pen holds %d animals but GameConfig.start_animals is %d" % [animals.count, config.start_animals])
|
||||
enemies.enemy_removed.connect(loot.on_enemy_removed)
|
||||
|
|
@ -334,7 +334,7 @@ func _ready() -> void:
|
|||
toasts.push("Breach! A %s was broken" % StructureSystem.NAMES[type].to_lower(), Color(1.0, 0.35, 0.3)))
|
||||
animals.pen_changed.connect(func(open: bool) -> void:
|
||||
if open and campaign.state.phase != CampaignController.Phase.MORNING:
|
||||
toasts.push("The pen is open: animals will wander out at night", Color(1.0, 0.55, 0.35)))
|
||||
toasts.push("The pen is open: at night the animals in it will get out and roam loose", Color(1.0, 0.55, 0.35)))
|
||||
scarecrow.patch_denied.connect(func(missing: Dictionary) -> void:
|
||||
toasts.push("Not enough straw to patch up: need %s more" % ResourceStore.describe(missing), Color(1.0, 0.8, 0.5)))
|
||||
if alerts != null:
|
||||
|
|
@ -768,8 +768,8 @@ func _on_phase_changed(phase: CampaignController.Phase, _previous: CampaignContr
|
|||
|
||||
|
||||
## End of the dawn grace: whoever is still on the farm leaves (carrying their loot off), and
|
||||
## loot still lying on the ground goes home (crops to their plots, sacks to the shed, loose
|
||||
## animals to the pen). #13: grows crops_total for any field that just sprouted (state.night is
|
||||
## loot still lying on the ground goes home (crops to their plots, sacks to the shed, animals
|
||||
## still following the scarecrow to the pen; #21: loose animals stay loose). #13: grows crops_total for any field that just sprouted (state.night is
|
||||
## the night that just finished; nights_survived isn't set to it until right after this signal),
|
||||
## so the morning snapshot (retry, the save file) already has it right. The new field's units
|
||||
## themselves flip from DORMANT to HOME in loot.sync_from_state(), at the morning that follows.
|
||||
|
|
|
|||
|
|
@ -76,22 +76,24 @@ extends Resource
|
|||
## A supply thief takes this many units of the material the shed holds most of (never more than
|
||||
## there is).
|
||||
@export_range(1, 100) var supply_bundle: int = 5
|
||||
## Loose animals (dropped, or wandered out of an open pen) walk toward the farm's nearest edge at
|
||||
## this speed, stopping to graze now and then; one that gets off the farm is lost.
|
||||
## An animal getting out of an open pen walks out at this speed; once it's out it's loose and
|
||||
## roams the farm like any other (AnimalSystem). Animals never leave the farm on their own.
|
||||
@export var stray_speed: float = 1.1
|
||||
## At night, while the pen is open (its gate broken or removed), one animal wanders out every
|
||||
## this many seconds. An animal brought back stays calm (won't wander out) for animal_calm_time.
|
||||
## At night, while the pen is open (nothing built yet, or its gate broken or removed), one calm
|
||||
## penned animal gets out every this many seconds and is loose. An animal brought back stays calm
|
||||
## (won't get out again) for animal_calm_time.
|
||||
@export var animal_wander_interval: float = 10.0
|
||||
@export var animal_calm_time: float = 30.0
|
||||
## Animals following the scarecrow walk its trail at up to this speed.
|
||||
@export var follow_speed: float = 6.0
|
||||
## Where loose animals start (#12): scattered open-farmyard spots outside FarmZone.Kind.ANIMAL_PEN
|
||||
## (x -10..4, z -11..-1), walkable, and clear of the future crop fields (x -11..-1 z 2..12 and
|
||||
## x 2..12 z 2..12 -- see LAYOUT.md). Each is grazed around (AnimalSystem.LOOSE_WANDER_RADIUS)
|
||||
## until the player leads that animal into a built pen. Cycles if there are more animals than spots.
|
||||
## Where loose animals start (#12), and where a loose one is back every morning (#21: in between
|
||||
## it roams the whole farm): a row of open-farmyard spots south and south-east of
|
||||
## FarmZone.Kind.ANIMAL_PEN (x -10..4, z -11..-1), walkable, clear of the crop fields (x -11..-1
|
||||
## z 2..12, x 2..12 z 2..12, and the sunflowers from x 14 -- see LAYOUT.md), and well in from the
|
||||
## farm's edge. Cycles if there are more animals than spots.
|
||||
@export var animal_loose_spots: Array[Vector2] = [
|
||||
Vector2(-9.0, 0.5), Vector2(-6.0, 0.5), Vector2(-3.0, 0.5), Vector2(0.0, 0.5), Vector2(3.0, 0.5),
|
||||
Vector2(-12.0, -3.0), Vector2(-12.0, -6.0), Vector2(-12.0, -9.0),
|
||||
Vector2(6.0, 0.5), Vector2(9.0, 0.5), Vector2(12.0, 0.5),
|
||||
]
|
||||
## What a thief with no set target goes for ("any" in a night plan), and where a thief whose target
|
||||
## is gone goes next: relative weights per category.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ func refresh() -> void:
|
|||
_title.text = "The farmers are away"
|
||||
lines.append("Keep the farm safe for %d nights until they come home: the crops, the animals in the pen, and the supplies in the shed." % nights)
|
||||
lines.append("By day, gather wood, scrap, and straw (hold E), store them at the barn, and build defenses (B). There's more to gather off the farm, to the north, east, and south.")
|
||||
lines.append("At night, stab aliens with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. A dropped animal runs off: walk up to it and lead it back to the pen. The supply shed sells a corn shooter (switch weapons with Tab or 1-2) and pumpkin bombs (throw them with right mouse).")
|
||||
lines.append("At night, stab aliens with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. Animals roam loose until you lead them into the pen: walk up to one and it follows you. The supply shed sells a corn shooter (switch weapons with Tab or 1-2) and pumpkin bombs (throw them with right mouse).")
|
||||
else:
|
||||
var e: Dictionary = s.night_log[s.night_log.size() - 1]
|
||||
_title.text = "Morning of day %d of %d" % [s.night, nights]
|
||||
|
|
@ -126,7 +126,7 @@ func refresh() -> void:
|
|||
s.animals, s.animals_total, s.supplies, s.scarecrow_hp, s.scarecrow_max_hp])
|
||||
lines.append(_damage_line())
|
||||
if animals != null and animals.pen_open and s.animals > 0:
|
||||
lines.append("The pen is open: put a gate in its opening (B) before nightfall, or animals will wander out.")
|
||||
lines.append("The pen is open: put a gate in its opening (B) before nightfall, or the animals in it will get out and roam loose.")
|
||||
var r := s.resources
|
||||
lines.append("In the shed: %s. In the pouch: %s." % [_or_none(ResourceStore.describe(r.shed)), _or_none(ResourceStore.describe(r.pouch))])
|
||||
var plan := waves.tonight() if waves != null else null
|
||||
|
|
@ -148,7 +148,7 @@ func grid_text() -> String:
|
|||
|
||||
|
||||
## Per category: (taken, recovered, lost) in a night's log entry. Animals taken include those
|
||||
## that wandered out of an open pen.
|
||||
## that got out of an open pen (loose, not lost).
|
||||
static func category_counts(e: Dictionary) -> Dictionary:
|
||||
return {
|
||||
"Crops": [int(e["crops_stolen"]), int(e["crops_recovered"]), int(e["crops_lost"])],
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const SLOTS := 5
|
|||
## Loot events per category (LootSystem.Category): the text ("%s" is the item's noun) and color.
|
||||
const MESSAGES := {
|
||||
&"stolen": [["A crop was snatched!", "A %s was grabbed!", "Aliens took %s from the shed!"], Color(1.0, 0.6, 0.15)],
|
||||
&"dropped": [["The alien dropped the crop. Grab it!", "The alien dropped the %s. Catch it before it runs off!",
|
||||
&"dropped": [["The alien dropped the crop. Grab it!", "The alien dropped the %s. Lead it back to the pen!",
|
||||
"The alien dropped %s. Grab it!"], Color(1.0, 0.9, 0.3)],
|
||||
&"recovered": [["Crop recovered", "The %s is back in the pen", "%s back in the shed"], Color(0.5, 1.0, 0.45)],
|
||||
&"returned": [["A dropped crop went back to its plot", "The %s went back to the pen", "%s went back to the shed"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue