Task #12: animals start loose; herd into the player-built pen
Adds LootSystem.Status.LOOSE: animals now start scattered at GameConfig. animal_loose_spots outside the pen rect and graze in place (AnimalSystem, anchored to their own spot instead of the pen) instead of starting HOME or escaping down the field. A thief can still claim and carry a loose animal off (same DROPPED/escape rules as before); the scarecrow's existing follow-trail recovery now also picks up a loose animal directly, and entering the pen makes it HOME as before. FarmState gains penned_animals (which ids are currently penned), set whenever an animal becomes HOME (led in, or auto-returned at the dawn grace) and cleared when it's lost. LootSystem.sync_from_state() uses it each morning/retry/load to restore penned animals HOME and leave the rest LOOSE, instead of resetting the whole herd into the pen. Bumped FarmState. VERSION to 5 with a migration step that pens every surviving animal for older saves (which always kept them in the pen). test_targets.gd's existing pen-mechanics suite (containment, straying, leading in) now pens every animal up front to keep covering that behavior; a new _loose_start check covers the loose start itself: animals spawn loose and scattered, graze in place, a thief can still claim and steal a loose one, leading one in with the follow-trail mechanic pens it, and a morning resync keeps the penned one home and the rest loose. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
186c9c44cb
commit
13efe6603f
7 changed files with 252 additions and 41 deletions
|
|
@ -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