Merge task #12: animals start loose (new LOOSE status), penned set persisted
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
b2eae679f8
8 changed files with 257 additions and 42 deletions
|
|
@ -85,7 +85,7 @@ func collect() -> Array[Dictionary]:
|
|||
continue
|
||||
var p := Vector2(enemies.pos_x[d], enemies.pos_z[d])
|
||||
raw.append(_alert(Kind.ESCAPE, enemies.type[d], loot.category[id], p, _escalation(d, p)))
|
||||
LootSystem.Status.HOME:
|
||||
LootSystem.Status.HOME, LootSystem.Status.LOOSE:
|
||||
var d := enemies.resolve_handle(loot.holder[id]) if loot.holder[id] >= 0 else -1
|
||||
if d >= 0:
|
||||
raw.append(_alert(Kind.THEFT, enemies.type[d], loot.category[id], loot.position_of(id), 0.0))
|
||||
|
|
|
|||
|
|
@ -2,18 +2,24 @@ class_name AnimalSystem
|
|||
extends Node3D
|
||||
## The pen's animals as moving entities. Their theft state lives in LootSystem; this moves and
|
||||
## shows them:
|
||||
## 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.
|
||||
## loose (DROPPED) dropped by its thief, or wandered out: 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.
|
||||
## 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.
|
||||
## carried held under its thief, wriggling.
|
||||
## 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.
|
||||
## 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.
|
||||
## carried held under its thief, wriggling.
|
||||
## 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.
|
||||
|
|
@ -25,6 +31,8 @@ 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
|
||||
|
||||
## The pen opened (its gate broken or taken down) or was shut again.
|
||||
signal pen_changed(open: bool)
|
||||
|
|
@ -59,6 +67,9 @@ 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.
|
||||
var _loose_spot := PackedVector2Array()
|
||||
var _pivots: Array[Node3D] = []
|
||||
var _meshes: Array = [] # per animal: Array[MeshInstance3D]
|
||||
## Co-op: the scarecrows animals can follow (player 1's, player 2's), each with its trail, and
|
||||
|
|
@ -95,7 +106,7 @@ func setup(p_campaign: CampaignController, pen_zone: FarmZone, p_nav: FarmNaviga
|
|||
var found := find_animals(pen_zone)
|
||||
count = found.size()
|
||||
var n := count + 1
|
||||
for a: PackedVector2Array in [pos, prev, goal, _start]:
|
||||
for a: PackedVector2Array in [pos, prev, goal, _start, _loose_spot]:
|
||||
a.resize(n)
|
||||
for a: PackedFloat32Array in [yaw, speed, timer, calm, phase, _start_yaw]:
|
||||
a.resize(n)
|
||||
|
|
@ -125,22 +136,26 @@ func setup(p_campaign: CampaignController, pen_zone: FarmZone, p_nav: FarmNaviga
|
|||
_meshes[id] = meshes
|
||||
_start[id] = Vector2(world.x, world.z)
|
||||
_start_yaw[id] = atan2(forward.x, forward.z)
|
||||
_loose_spot[id] = config.animal_loose_spots[(id - 1) % config.animal_loose_spots.size()] \
|
||||
if not config.animal_loose_spots.is_empty() else _start[id]
|
||||
phase[id] = _rng.randf() * TAU
|
||||
sync_from_state()
|
||||
|
||||
|
||||
## Every animal back at its spot in the pen (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
|
||||
## (or hidden if lost) -- nobody following (new morning, retry).
|
||||
func sync_from_state() -> void:
|
||||
for k in _trails.size():
|
||||
_trails[k] = PackedVector2Array()
|
||||
_wander_wait = config.animal_wander_interval * 0.3
|
||||
for id in range(1, count + 1):
|
||||
pos[id] = _start[id]
|
||||
prev[id] = _start[id]
|
||||
var item := loot.animal_item(id)
|
||||
var home_spot := _start[id] if loot.status[item] == LootSystem.Status.HOME else _loose_spot[id]
|
||||
pos[id] = home_spot
|
||||
prev[id] = home_spot
|
||||
yaw[id] = _start_yaw[id]
|
||||
speed[id] = 0.0
|
||||
goal[id] = _start[id]
|
||||
goal[id] = home_spot
|
||||
timer[id] = _rng.randf_range(0.5, 3.0)
|
||||
calm[id] = 0.0
|
||||
slot[id] = -1
|
||||
|
|
@ -251,6 +266,9 @@ func step(dt: float) -> void:
|
|||
LootSystem.Status.HOME:
|
||||
slot[id] = -1
|
||||
_wander(id, item, dt)
|
||||
LootSystem.Status.LOOSE:
|
||||
slot[id] = -1
|
||||
_wander(id, item, dt)
|
||||
LootSystem.Status.DROPPED:
|
||||
slot[id] = -1
|
||||
if not in_pen(pos[id]):
|
||||
|
|
@ -290,7 +308,7 @@ func _wander(id: int, item: int, dt: float) -> void:
|
|||
timer[id] -= dt
|
||||
if speed[id] == 0.0:
|
||||
if timer[id] <= 0.0:
|
||||
goal[id] = _wander_goal()
|
||||
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
|
||||
return
|
||||
|
|
@ -366,13 +384,23 @@ func _rest(id: int) -> void:
|
|||
timer[id] = _rng.randf_range(1.5, 4.0)
|
||||
|
||||
|
||||
func _wander_goal() -> Vector2:
|
||||
var area := pen.grow(-1.2)
|
||||
## A HOME animal wanders inside the pen; a LOOSE one grazes within LOOSE_WANDER_RADIUS of its own
|
||||
## loose spot instead.
|
||||
func _wander_goal(id: int, item: int) -> Vector2:
|
||||
if loot.status[item] == LootSystem.Status.HOME:
|
||||
var area := pen.grow(-1.2)
|
||||
for attempt in 12:
|
||||
var p := Vector2(_rng.randf_range(area.position.x, area.end.x), _rng.randf_range(area.position.y, area.end.y))
|
||||
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 := Vector2(_rng.randf_range(area.position.x, area.end.x), _rng.randf_range(area.position.y, area.end.y))
|
||||
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 area.get_center()
|
||||
return center
|
||||
|
||||
|
||||
## At night, while the pen is open, a calm animal walks out now and then.
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ extends RefCounted
|
|||
## pouch live in resources). Gather points below full, bought upgrades, and the built structures
|
||||
## are kept too.
|
||||
|
||||
const VERSION := 4
|
||||
const VERSION := 5
|
||||
const KEYS: Array[String] = [
|
||||
"night", "nights_survived", "phase", "phase_time_left", "scarecrow_max_hp", "scarecrow_hp",
|
||||
"crops_total", "lost_crops", "animals_total", "lost_animals", "supplies_total", "shed_raided",
|
||||
"resources", "gather_charges", "upgrades", "structures", "next_structure_id", "night_events",
|
||||
"night_log", "coop", "partner_max_hp", "partner_hp",
|
||||
"crops_total", "lost_crops", "animals_total", "lost_animals", "penned_animals", "supplies_total",
|
||||
"shed_raided", "resources", "gather_charges", "upgrades", "structures", "next_structure_id",
|
||||
"night_events", "night_log", "coop", "partner_max_hp", "partner_hp",
|
||||
]
|
||||
const STRUCTURE_KEYS: Array[String] = ["id", "type", "x", "z", "rot", "hp"]
|
||||
## Events counted from the morning to the end of the dawn grace, copied into the night's log
|
||||
|
|
@ -65,6 +65,10 @@ var lost_crops := PackedInt32Array()
|
|||
var animals_total: int = 0
|
||||
## Ids of the animals that are gone for good (carried or wandered off the farm), sorted.
|
||||
var lost_animals := PackedInt32Array()
|
||||
## Ids of the animals currently penned (#12): led into a built pen (or auto-returned there after
|
||||
## being dropped), so sync_from_state() keeps them LootSystem.Status.HOME each morning; an id not
|
||||
## here (and not lost) is loose, grazing outside the pen until led in. Never overlaps lost_animals.
|
||||
var penned_animals := PackedInt32Array()
|
||||
## The shed's stock when the vacation started (0 = supplies not in play).
|
||||
var supplies_total: int = 0
|
||||
## The shed was last emptied by thieves (not by spending). Only then do empty supplies count
|
||||
|
|
@ -160,6 +164,7 @@ func lose_animal(id: int) -> bool:
|
|||
return false
|
||||
lost_animals.append(id)
|
||||
lost_animals.sort()
|
||||
unpen_animal(id)
|
||||
return true
|
||||
|
||||
|
||||
|
|
@ -168,6 +173,35 @@ func lose_all_animals() -> void:
|
|||
lose_animal(id)
|
||||
|
||||
|
||||
func is_animal_penned(id: int) -> bool:
|
||||
return penned_animals.has(id)
|
||||
|
||||
|
||||
## Marks an animal as penned (led into the pen, or auto-returned there). Returns false for an
|
||||
## unknown, already-penned, or lost animal.
|
||||
func pen_animal(id: int) -> bool:
|
||||
if id < 1 or id > animals_total or penned_animals.has(id) or lost_animals.has(id):
|
||||
return false
|
||||
penned_animals.append(id)
|
||||
penned_animals.sort()
|
||||
return true
|
||||
|
||||
|
||||
## Marks an animal as loose again. Returns false if it wasn't penned.
|
||||
func unpen_animal(id: int) -> bool:
|
||||
var i := penned_animals.find(id)
|
||||
if i < 0:
|
||||
return false
|
||||
penned_animals.remove_at(i)
|
||||
return true
|
||||
|
||||
|
||||
## Debug and tests: every surviving animal penned at once (the old always-in-the-pen behavior).
|
||||
func pen_all_animals() -> void:
|
||||
for id in range(1, animals_total + 1):
|
||||
pen_animal(id)
|
||||
|
||||
|
||||
## Debug and tests: every asset gone, the shed emptied by thieves.
|
||||
func strip() -> void:
|
||||
lose_all_crops()
|
||||
|
|
@ -263,6 +297,9 @@ func to_dict() -> Dictionary:
|
|||
var lost_a: Array = []
|
||||
for id in lost_animals:
|
||||
lost_a.append(id)
|
||||
var penned: Array = []
|
||||
for id in penned_animals:
|
||||
penned.append(id)
|
||||
return {
|
||||
"version": VERSION,
|
||||
"night": night,
|
||||
|
|
@ -275,6 +312,7 @@ func to_dict() -> Dictionary:
|
|||
"lost_crops": lost,
|
||||
"animals_total": animals_total,
|
||||
"lost_animals": lost_a,
|
||||
"penned_animals": penned,
|
||||
"supplies_total": supplies_total,
|
||||
"shed_raided": shed_raided,
|
||||
"resources": resources.to_dict(),
|
||||
|
|
@ -301,7 +339,8 @@ static func from_dict(d: Dictionary) -> FarmState:
|
|||
var phase_value := int(d["phase"])
|
||||
if not CampaignController.Phase.values().has(phase_value):
|
||||
return null
|
||||
if not (d["night_log"] is Array and d["lost_crops"] is Array and d["lost_animals"] is Array and d["night_events"] is Dictionary
|
||||
if not (d["night_log"] is Array and d["lost_crops"] is Array and d["lost_animals"] is Array and d["penned_animals"] is Array
|
||||
and d["night_events"] is Dictionary
|
||||
and d["gather_charges"] is Dictionary and d["upgrades"] is Dictionary and d["structures"] is Array):
|
||||
return null
|
||||
var store := ResourceStore.from_dict(d["resources"])
|
||||
|
|
@ -325,6 +364,9 @@ static func from_dict(d: Dictionary) -> FarmState:
|
|||
for id in d["lost_animals"]:
|
||||
if not s.lose_animal(int(id)):
|
||||
return null
|
||||
for id in d["penned_animals"]:
|
||||
if not s.pen_animal(int(id)):
|
||||
return null # unknown, duplicate, or already-lost animal id
|
||||
s.supplies_total = int(d["supplies_total"])
|
||||
s.shed_raided = bool(d["shed_raided"])
|
||||
s.resources = store
|
||||
|
|
@ -394,4 +436,5 @@ func is_valid() -> bool:
|
|||
and partner_max_hp >= 1 and partner_hp >= 0 and partner_hp <= partner_max_hp \
|
||||
and crops_total >= 0 and lost_crops.size() <= crops_total \
|
||||
and animals_total >= 0 and lost_animals.size() <= animals_total \
|
||||
and penned_animals.size() <= animals_total - lost_animals.size() \
|
||||
and supplies_total >= 0 and supplies_in_transit >= 0
|
||||
|
|
|
|||
|
|
@ -85,6 +85,14 @@ extends Resource
|
|||
@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.
|
||||
@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),
|
||||
]
|
||||
## 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.
|
||||
@export var target_weights: Dictionary = {"crops": 2.0, "animals": 1.0, "supplies": 1.0}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@ extends Node3D
|
|||
## 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
|
||||
## 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.
|
||||
|
|
@ -26,7 +32,7 @@ extends Node3D
|
|||
## recoveries, strays, and supply losses count toward the night's record.
|
||||
|
||||
enum Category { CROP, ANIMAL, SUPPLY }
|
||||
enum Status { HOME, CARRIED, DROPPED, LOST, FOLLOWING }
|
||||
enum Status { HOME, CARRIED, DROPPED, LOST, FOLLOWING, LOOSE }
|
||||
enum Threat { NONE, TARGETED, CARRIED, DROPPED }
|
||||
|
||||
## EnemySystem.want for a thief with no set target (it goes by GameConfig.target_weights).
|
||||
|
|
@ -174,7 +180,13 @@ func sync_from_state() -> void:
|
|||
status[id] = Status.LOST if s.is_crop_lost(id) else Status.HOME
|
||||
_units[id].visible = status[id] == Status.HOME
|
||||
Category.ANIMAL:
|
||||
status[id] = Status.LOST if s.is_animal_lost(animal_index(id)) else Status.HOME
|
||||
var aid := animal_index(id)
|
||||
if s.is_animal_lost(aid):
|
||||
status[id] = Status.LOST
|
||||
elif s.is_animal_penned(aid):
|
||||
status[id] = Status.HOME
|
||||
else:
|
||||
status[id] = Status.LOOSE
|
||||
Category.SUPPLY:
|
||||
status[id] = Status.HOME
|
||||
sack_amount[id] = 0
|
||||
|
|
@ -238,7 +250,7 @@ func first_sack() -> int:
|
|||
|
||||
func is_claimed_by(id: int, handle: int) -> bool:
|
||||
return is_valid_unit(id) and handle >= 0 and holder[id] == handle \
|
||||
and (status[id] == Status.HOME or status[id] == Status.DROPPED)
|
||||
and (status[id] == Status.HOME or status[id] == Status.DROPPED or status[id] == Status.LOOSE)
|
||||
|
||||
|
||||
## Where a thief has to go for this item: its plot, the animal itself, the shed pile, or where it
|
||||
|
|
@ -290,14 +302,14 @@ func claim(handle: int, from: Vector2, nav: FarmNavigation, view_range: float, w
|
|||
return best
|
||||
|
||||
|
||||
## Whether a thief could claim anything at home in this category right now.
|
||||
## Whether a thief could claim anything at home (or, for an animal, loose) in this category now.
|
||||
func available(c: Category) -> bool:
|
||||
match c:
|
||||
Category.SUPPLY:
|
||||
return campaign.state.resources.shed_total() > 0 and _free_sack() > 0
|
||||
_:
|
||||
for id in _ids(c):
|
||||
if status[id] == Status.HOME and holder[id] == -1:
|
||||
if (status[id] == Status.HOME or status[id] == Status.LOOSE) and holder[id] == -1:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
|
@ -368,10 +380,14 @@ func escape(id: int, handle: int) -> void:
|
|||
_lose(id)
|
||||
|
||||
|
||||
## The scarecrow got a dropped item 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).
|
||||
## 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.
|
||||
func recover(id: int) -> bool:
|
||||
if not is_valid_unit(id) or status[id] != Status.DROPPED:
|
||||
if not is_valid_unit(id):
|
||||
return false
|
||||
var loose_animal := category[id] == Category.ANIMAL and status[id] == Status.LOOSE
|
||||
if status[id] != Status.DROPPED and not loose_animal:
|
||||
return false
|
||||
var s := campaign.state
|
||||
match category[id]:
|
||||
|
|
@ -406,6 +422,7 @@ func animal_home(id: int) -> void:
|
|||
status[id] = Status.HOME
|
||||
holder[id] = -1
|
||||
progress[id] = 0.0
|
||||
campaign.state.pen_animal(animal_index(id))
|
||||
if led:
|
||||
campaign.state.record_event("animals_recovered")
|
||||
loot_event.emit(&"recovered" if led else &"returned", id, _world(position_of(id)))
|
||||
|
|
@ -465,7 +482,8 @@ func step(scarecrow: Vector2, who: int = 0) -> void:
|
|||
recoverer = who
|
||||
var r2 := config.pickup_radius * config.pickup_radius
|
||||
for id in range(1, item_count + 1):
|
||||
if status[id] != Status.DROPPED:
|
||||
var recoverable := status[id] == Status.DROPPED or (category[id] == Category.ANIMAL and status[id] == Status.LOOSE)
|
||||
if not recoverable:
|
||||
_warned[id] = 0
|
||||
continue
|
||||
var near := position_of(id).distance_squared_to(scarecrow) <= r2
|
||||
|
|
@ -629,7 +647,7 @@ func _claim_home(c: int) -> int:
|
|||
return sack
|
||||
var free: Array[int] = []
|
||||
for id in _ids(c):
|
||||
if status[id] == Status.HOME and holder[id] == -1:
|
||||
if (status[id] == Status.HOME or status[id] == Status.LOOSE) and holder[id] == -1:
|
||||
free.append(id)
|
||||
if free.is_empty():
|
||||
return -1
|
||||
|
|
@ -681,6 +699,8 @@ func _return_home(id: int) -> void:
|
|||
progress[id] = 0.0
|
||||
if category[id] == Category.CROP:
|
||||
_units[id].visible = true
|
||||
elif category[id] == Category.ANIMAL:
|
||||
campaign.state.pen_animal(animal_index(id))
|
||||
|
||||
|
||||
func _world(p: Vector2) -> Vector3:
|
||||
|
|
|
|||
|
|
@ -88,6 +88,19 @@ static func migrate(d: Dictionary) -> Dictionary:
|
|||
out["partner_max_hp"] = int(out.get("scarecrow_max_hp", 10))
|
||||
out["partner_hp"] = int(out.get("scarecrow_max_hp", 10))
|
||||
out["version"] = 4
|
||||
4:
|
||||
# Version 5 adds the Animal Pen's loose/penned state (#12). Older saves always kept
|
||||
# every surviving animal in the pen, so migrate them in as already penned.
|
||||
var total := int(out.get("animals_total", 0))
|
||||
var lost := {} # id (int) -> true; Array.has() won't match a float to an int
|
||||
for raw: Variant in out.get("lost_animals", []):
|
||||
lost[int(raw)] = true
|
||||
var penned: Array = []
|
||||
for id in range(1, total + 1):
|
||||
if not lost.has(id):
|
||||
penned.append(id)
|
||||
out["penned_animals"] = penned
|
||||
out["version"] = 5
|
||||
_:
|
||||
return {}
|
||||
return out
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue