Merge task #9: Workbench arrives after Night 1, targetable, repair-only
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
4e3692b99d
12 changed files with 312 additions and 23 deletions
|
|
@ -93,6 +93,10 @@ costs = {
|
||||||
"wide_fear": {
|
"wide_fear": {
|
||||||
"straw": 20,
|
"straw": 20,
|
||||||
"wood": 4
|
"wood": 4
|
||||||
|
},
|
||||||
|
"workbench": {
|
||||||
|
"scrap": 4,
|
||||||
|
"wood": 6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
upgrades = {
|
upgrades = {
|
||||||
|
|
|
||||||
|
|
@ -547,7 +547,11 @@ func _do_request(r: Array) -> void:
|
||||||
_events.append(["toast", "Dismantled the %s%s" % [StructureSystem.NAMES[e["type"]].to_lower(),
|
_events.append(["toast", "Dismantled the %s%s" % [StructureSystem.NAMES[e["type"]].to_lower(),
|
||||||
(": %s back in the shed" % ResourceStore.describe(back)) if not back.is_empty() else ""], Color(0.85, 0.95, 1.0)])
|
(": %s back in the shed" % ResourceStore.describe(back)) if not back.is_empty() else ""], Color(0.85, 0.95, 1.0)])
|
||||||
"buy":
|
"buy":
|
||||||
var text := Upgrades.buy(c, String(r[1]), sim.structures)
|
var id := String(r[1])
|
||||||
|
if Upgrades.shop_of(c.config, id) == "workbench" and (sim.structures == null or not sim.structures.workbench_available()):
|
||||||
|
_events.append(["toast", "The work area isn't available", Color(1.0, 0.8, 0.5)])
|
||||||
|
return
|
||||||
|
var text := Upgrades.buy(c, id, sim.structures)
|
||||||
_events.append(["toast", text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5)])
|
_events.append(["toast", text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5)])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,11 @@ func _rasterize(hull: PackedVector2Array, inflate: float) -> void:
|
||||||
|
|
||||||
|
|
||||||
## Marks the cells within inflate of a convex outline: as blocked (id < 0) or, for free cells,
|
## Marks the cells within inflate of a convex outline: as blocked (id < 0) or, for free cells,
|
||||||
## as belonging to structure id.
|
## as belonging to structure id. A structure (id >= 0) is tagged even over an already-blocked
|
||||||
|
## cell (#9: the Workbench, granted onto its own scene prop's real collision, bypassing the
|
||||||
|
## build-on-free-ground check every player-placed structure goes through in validate() -- without
|
||||||
|
## this, it would be invisible to _adjacent_structure()/barrier_ahead(), undetectable and
|
||||||
|
## unbreakable); this never changes anything for a structure that is on free ground to begin with.
|
||||||
func _rasterize_into(hull: PackedVector2Array, inflate: float, id: int) -> void:
|
func _rasterize_into(hull: PackedVector2Array, inflate: float, id: int) -> void:
|
||||||
var lo := hull[0]
|
var lo := hull[0]
|
||||||
var hi := hull[0]
|
var hi := hull[0]
|
||||||
|
|
@ -304,7 +308,7 @@ func _rasterize_into(hull: PackedVector2Array, inflate: float, id: int) -> void:
|
||||||
for cz in range(c0 / width, c1 / width + 1):
|
for cz in range(c0 / width, c1 / width + 1):
|
||||||
for cx in range(c0 % width, c1 % width + 1):
|
for cx in range(c0 % width, c1 % width + 1):
|
||||||
var i := cz * width + cx
|
var i := cz * width + cx
|
||||||
if blocked[i] == 1:
|
if blocked[i] == 1 and id < 0:
|
||||||
continue
|
continue
|
||||||
var p := cell_center(i)
|
var p := cell_center(i)
|
||||||
if (solid and Geometry2D.is_point_in_polygon(p, hull)) or _dist2_to_outline(p, hull) <= r2:
|
if (solid and Geometry2D.is_point_in_polygon(p, hull)) or _dist2_to_outline(p, hull) <= r2:
|
||||||
|
|
|
||||||
|
|
@ -693,7 +693,12 @@ func _breaker_goals() -> PackedInt32Array:
|
||||||
for e in campaign.state.structures:
|
for e in campaign.state.structures:
|
||||||
if not structures.blocks(e["type"]):
|
if not structures.blocks(e["type"]):
|
||||||
continue
|
continue
|
||||||
|
if e["type"] == "workbench" and int(e["hp"]) <= 0:
|
||||||
|
continue # broken: nothing left to gain by sending a breaker at it
|
||||||
barriers.append(e)
|
barriers.append(e)
|
||||||
|
if e["type"] == "workbench":
|
||||||
|
guarding.append(e) # #9 Decision 3: it guards its own work area, unconditionally
|
||||||
|
continue
|
||||||
var at := Vector2(e["x"], e["z"])
|
var at := Vector2(e["x"], e["z"])
|
||||||
for a in areas:
|
for a in areas:
|
||||||
if a.grow(config.guard_range).has_point(at):
|
if a.grow(config.guard_range).has_point(at):
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,10 @@ extends Resource
|
||||||
@export_range(1, 500) var gate_hp: int = 30
|
@export_range(1, 500) var gate_hp: int = 30
|
||||||
@export_range(1, 500) var trap_triggers: int = 10
|
@export_range(1, 500) var trap_triggers: int = 10
|
||||||
@export_range(1, 500) var turret_hp: int = 25
|
@export_range(1, 500) var turret_hp: int = 25
|
||||||
|
## The Workbench (#9): not built by the player (it's granted once Night 1 is survived --
|
||||||
|
## StructureSystem.grant_workbench()), but it has HP, can be damaged, and is repaired like any
|
||||||
|
## other structure (repair-only: it stays, broken, at 0 HP instead of being destroyed).
|
||||||
|
@export_range(1, 500) var workbench_hp: int = 50
|
||||||
## A ground enemy crossing a slowing trap moves at this share of its speed for this long.
|
## A ground enemy crossing a slowing trap moves at this share of its speed for this long.
|
||||||
@export_range(0.05, 1.0) var trap_slow_factor: float = 0.5
|
@export_range(0.05, 1.0) var trap_slow_factor: float = 0.5
|
||||||
@export var trap_slow_time: float = 2.0
|
@export var trap_slow_time: float = 2.0
|
||||||
|
|
@ -391,6 +395,8 @@ func structure_hp(type: String) -> int:
|
||||||
return gate_hp
|
return gate_hp
|
||||||
"slowing_trap":
|
"slowing_trap":
|
||||||
return trap_triggers
|
return trap_triggers
|
||||||
|
"workbench":
|
||||||
|
return workbench_hp
|
||||||
return turret_hp
|
return turret_hp
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ extends Node3D
|
||||||
## Letting go, a hit, fear, nightfall, or a full pouch cancels it.
|
## Letting go, a hit, fear, nightfall, or a full pouch cancels it.
|
||||||
## * Workbench / shed counter: press interact by day to open that shop's menu (UpgradePanel,
|
## * Workbench / shed counter: press interact by day to open that shop's menu (UpgradePanel,
|
||||||
## shop "workbench" or "shed"); interact again, walking away, or nightfall closes it. Nothing
|
## shop "workbench" or "shed"); interact again, walking away, or nightfall closes it. Nothing
|
||||||
## else happens here while one is open.
|
## else happens here while one is open. The Workbench itself doesn't exist (no prompt, no
|
||||||
|
## focus, its shop can't be opened) until StructureSystem grants it, after Night 1 (#9); once
|
||||||
|
## it exists but is broken (0 HP), its shop is refused until it's repaired instead.
|
||||||
## * Repair: a damaged structure within REPAIR_REACH comes first. Hold interact for
|
## * Repair: a damaged structure within REPAIR_REACH comes first. Hold interact for
|
||||||
## repair_time (any phase) to repair it fully for StructureSystem.repair_cost (paid at the
|
## repair_time (any phase) to repair it fully for StructureSystem.repair_cost (paid at the
|
||||||
## end); it is refused, once per press, without the materials.
|
## end); it is refused, once per press, without the materials.
|
||||||
|
|
@ -258,7 +260,9 @@ func step(dt: float) -> void:
|
||||||
_denied = true
|
_denied = true
|
||||||
message.emit(why, Color(1.0, 0.8, 0.5))
|
message.emit(why, Color(1.0, 0.8, 0.5))
|
||||||
elif focus is Workbench and pressed:
|
elif focus is Workbench and pressed:
|
||||||
if not campaign.is_daytime():
|
if structures != null and structures.is_broken(structures.workbench_id()):
|
||||||
|
message.emit("Broken -- repair it", Color(1.0, 0.8, 0.5))
|
||||||
|
elif not campaign.is_daytime():
|
||||||
message.emit("The work area is for daytime", Color(1.0, 0.8, 0.5))
|
message.emit("The work area is for daytime", Color(1.0, 0.8, 0.5))
|
||||||
elif upgrade_panel != null:
|
elif upgrade_panel != null:
|
||||||
upgrade_panel.open()
|
upgrade_panel.open()
|
||||||
|
|
@ -349,7 +353,7 @@ func _nearest(p: Vector2) -> Node3D:
|
||||||
if d <= n.reach and score < best_d:
|
if d <= n.reach and score < best_d:
|
||||||
best = n
|
best = n
|
||||||
best_d = score
|
best_d = score
|
||||||
if workbench != null:
|
if workbench != null and structures != null and structures.has_workbench():
|
||||||
var d := Vector2(workbench.global_position.x, workbench.global_position.z).distance_to(p)
|
var d := Vector2(workbench.global_position.x, workbench.global_position.z).distance_to(p)
|
||||||
if d <= workbench.reach and d < best_d:
|
if d <= workbench.reach and d < best_d:
|
||||||
best = workbench
|
best = workbench
|
||||||
|
|
@ -389,8 +393,9 @@ func _process(delta: float) -> void:
|
||||||
prompt = "[E / X] Gather" if why == "" else why
|
prompt = "[E / X] Gather" if why == "" else why
|
||||||
n.show_state(charges(n), near and kit.alive, prompt)
|
n.show_state(charges(n), near and kit.alive, prompt)
|
||||||
if workbench != null and show_labels:
|
if workbench != null and show_labels:
|
||||||
var near := Vector2(workbench.global_position.x - p.x, workbench.global_position.z - p.z).length() < LABEL_RANGE
|
var granted := structures != null and structures.has_workbench()
|
||||||
workbench.show_state(campaign, near and kit.alive, focus == workbench)
|
var near := granted and Vector2(workbench.global_position.x - p.x, workbench.global_position.z - p.z).length() < LABEL_RANGE
|
||||||
|
workbench.show_state(campaign, near and kit.alive, focus == workbench, granted and structures.is_broken(structures.workbench_id()))
|
||||||
if shed_counter != null and show_labels:
|
if shed_counter != null and show_labels:
|
||||||
var near := Vector2(shed_counter.global_position.x - p.x, shed_counter.global_position.z - p.z).length() < LABEL_RANGE
|
var near := Vector2(shed_counter.global_position.x - p.x, shed_counter.global_position.z - p.z).length() < LABEL_RANGE
|
||||||
shed_counter.show_state(campaign, near and kit.alive, focus == shed_counter)
|
shed_counter.show_state(campaign, near and kit.alive, focus == shed_counter)
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,10 @@ func refresh() -> void:
|
||||||
lines.append("In the shed: %s. In the pouch: %s." % [_or_none(ResourceStore.describe(r.shed)), _or_none(ResourceStore.describe(r.pouch))])
|
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
|
var plan := waves.tonight() if waves != null else null
|
||||||
if plan != null and plan.title != "":
|
if plan != null and plan.title != "":
|
||||||
lines.append("Tonight: %s. Upgrades at the work area: %d of %d done." % [plan.title, _upgrades_done(), Upgrades.ORDER.size()])
|
if structures != null and structures.has_workbench():
|
||||||
|
lines.append("Tonight: %s. Upgrades at the work area: %d of %d done." % [plan.title, _upgrades_done(), Upgrades.ORDER.size()])
|
||||||
|
else: # #9: the Workbench hasn't been granted yet -- it arrives once Night 1 is survived
|
||||||
|
lines.append("Tonight: %s. The work area will be set up once you survive tonight." % plan.title)
|
||||||
_body.text = "\n".join(lines)
|
_body.text = "\n".join(lines)
|
||||||
_start.grab_focus.call_deferred()
|
_start.grab_focus.call_deferred()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,15 @@ extends Node3D
|
||||||
## fires turret_l3_projectiles shots at once in a fan. A tar patch's footprint and visual grow by
|
## fires turret_l3_projectiles shots at once in a fan. A tar patch's footprint and visual grow by
|
||||||
## trap_level_size_mult[level - 1] (L2 double, L3 triple its L1 size); upgrading refuses with a
|
## trap_level_size_mult[level - 1] (L2 double, L3 triple its L1 size); upgrading refuses with a
|
||||||
## reason if the bigger footprint would overlap another structure or the world.
|
## reason if the bigger footprint would overlap another structure or the world.
|
||||||
|
##
|
||||||
|
## workbench (#9): not built by the player -- not in ORDER, never validated or paid for. Granted
|
||||||
|
## once (grant_workbench(), idempotent) at the scene's Workbench node when Night 1 is survived
|
||||||
|
## (CampaignController.night_ending), and derived again on load/retry (sync_from_state(), when
|
||||||
|
## FarmState.nights_survived >= 1 and no "workbench" record exists yet) in case it was missed.
|
||||||
|
## Its view is the existing Workbench scene node (hidden until granted), not a built mesh, so it
|
||||||
|
## shares every other structure's damage/repair/HP bar/tint/wobble/nav/save pipeline for free.
|
||||||
|
## Repair-only: at 0 HP it's "broken" (Interactions refuses to open its shop) but, unlike every
|
||||||
|
## other structure, damage() never removes its record -- there's no rebuilding it from scratch.
|
||||||
|
|
||||||
signal layout_changed
|
signal layout_changed
|
||||||
signal built(id: int, type: String)
|
signal built(id: int, type: String)
|
||||||
|
|
@ -43,6 +52,7 @@ const NAMES := {
|
||||||
"gate": "Gate",
|
"gate": "Gate",
|
||||||
"slowing_trap": "Tar patch",
|
"slowing_trap": "Tar patch",
|
||||||
"automated_defense": "Turret",
|
"automated_defense": "Turret",
|
||||||
|
"workbench": "Workbench",
|
||||||
}
|
}
|
||||||
## Structure types with a per-instance level (#10); every other type is always level 1.
|
## Structure types with a per-instance level (#10); every other type is always level 1.
|
||||||
const LEVELABLE: Array[String] = ["automated_defense", "slowing_trap"]
|
const LEVELABLE: Array[String] = ["automated_defense", "slowing_trap"]
|
||||||
|
|
@ -67,6 +77,10 @@ var player: PlayerCharacter
|
||||||
## Co-op: player 2's scarecrow (gates open for it too, and nothing is built onto it).
|
## Co-op: player 2's scarecrow (gates open for it too, and nothing is built onto it).
|
||||||
var partner: Node3D
|
var partner: Node3D
|
||||||
|
|
||||||
|
## The scene's Workbench node (Zones/WorkArea/Workbench), found in setup(): its view once
|
||||||
|
## granted, not built -- see grant_workbench().
|
||||||
|
var _workbench_node: Workbench
|
||||||
|
|
||||||
var _views := {} # id -> Node3D
|
var _views := {} # id -> Node3D
|
||||||
var _bars := {} # id -> MeshInstance3D
|
var _bars := {} # id -> MeshInstance3D
|
||||||
var _bodies := {} # id -> Array[RID] (physics bodies to leave out of placement queries)
|
var _bodies := {} # id -> Array[RID] (physics bodies to leave out of placement queries)
|
||||||
|
|
@ -93,6 +107,11 @@ func setup(p_campaign: CampaignController, p_nav: FarmNavigation, p_zones: FarmZ
|
||||||
player = p_player
|
player = p_player
|
||||||
nav.set_barrier_cost(roundi(config.barrier_detour / nav.cell_size * FarmNavigation.COST_ORTH))
|
nav.set_barrier_cost(roundi(config.barrier_detour / nav.cell_size * FarmNavigation.COST_ORTH))
|
||||||
_bar_shader = load("res://game/resources/hp_bar.gdshader") as Shader
|
_bar_shader = load("res://game/resources/hp_bar.gdshader") as Shader
|
||||||
|
for n in zones.find_children("*", "Node3D", true, false):
|
||||||
|
if n is Workbench:
|
||||||
|
_workbench_node = n
|
||||||
|
break
|
||||||
|
campaign.night_ending.connect(_on_night_ending)
|
||||||
for u in zones.crop_units():
|
for u in zones.crop_units():
|
||||||
var lo := Vector2(INF, INF)
|
var lo := Vector2(INF, INF)
|
||||||
var hi := Vector2(-INF, -INF)
|
var hi := Vector2(-INF, -INF)
|
||||||
|
|
@ -233,11 +252,65 @@ func place(type: String, x: float, z: float, rot: int) -> int:
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
|
||||||
|
## A non-purchased, unvalidated place(): adds a structure record at (x, z) without validate() or
|
||||||
|
## pay(), through the rest of the normal pipeline (record, view, nav, built). For structures the
|
||||||
|
## game grants itself (the Workbench -- grant_workbench()), not ones the player builds.
|
||||||
|
func grant(type: String, x: float, z: float, rot: int) -> int:
|
||||||
|
var s := campaign.state
|
||||||
|
var id := s.next_structure_id
|
||||||
|
s.next_structure_id += 1
|
||||||
|
s.structures.append({"id": id, "type": type, "x": x, "z": z, "rot": rot, "hp": max_hp(type), "level": 1})
|
||||||
|
_add_view(s.structures[s.structures.size() - 1])
|
||||||
|
_update_nav()
|
||||||
|
built.emit(id, type)
|
||||||
|
return id
|
||||||
|
|
||||||
|
|
||||||
|
## Idempotent: grants the Workbench at the scene node's position if it isn't a structure record
|
||||||
|
## yet. Called when Night 1 is survived (_on_night_ending) and, to derive it on load/retry, from
|
||||||
|
## sync_from_state() (guarded there to FarmState.nights_survived >= 1); tests may call it directly
|
||||||
|
## to have the workbench from the start, regardless of the night.
|
||||||
|
func grant_workbench() -> void:
|
||||||
|
if has_workbench() or _workbench_node == null:
|
||||||
|
return
|
||||||
|
var p := _workbench_node.global_position
|
||||||
|
grant("workbench", p.x, p.z, 0)
|
||||||
|
|
||||||
|
|
||||||
|
func has_workbench() -> bool:
|
||||||
|
return workbench_id() >= 0
|
||||||
|
|
||||||
|
|
||||||
|
## The granted Workbench's structure id, or -1 before it exists.
|
||||||
|
func workbench_id() -> int:
|
||||||
|
for e in campaign.state.structures:
|
||||||
|
if e["type"] == "workbench":
|
||||||
|
return int(e["id"])
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
## 0 HP: still a record (repair-only, never removed -- see damage()), but its shop can't be opened.
|
||||||
|
func is_broken(id: int) -> bool:
|
||||||
|
var e := campaign.state.structure(id)
|
||||||
|
return not e.is_empty() and int(e["hp"]) <= 0
|
||||||
|
|
||||||
|
|
||||||
|
## Granted and not broken: whether its shop (and a co-op "buy" request for one of its items) may
|
||||||
|
## open right now.
|
||||||
|
func workbench_available() -> bool:
|
||||||
|
var id := workbench_id()
|
||||||
|
return id >= 0 and not is_broken(id)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_night_ending() -> void:
|
||||||
|
grant_workbench()
|
||||||
|
|
||||||
|
|
||||||
## Takes a structure down, refunding dismantle_refund of its cost into the shed. Returns the
|
## Takes a structure down, refunding dismantle_refund of its cost into the shed. Returns the
|
||||||
## refund.
|
## refund. The Workbench is never dismantlable (it isn't built in the first place).
|
||||||
func dismantle(id: int) -> Dictionary:
|
func dismantle(id: int) -> Dictionary:
|
||||||
var e := campaign.state.structure(id)
|
var e := campaign.state.structure(id)
|
||||||
if e.is_empty():
|
if e.is_empty() or e["type"] == "workbench":
|
||||||
return {}
|
return {}
|
||||||
var refund := {}
|
var refund := {}
|
||||||
var cost: Dictionary = config.costs.get(e["type"], {})
|
var cost: Dictionary = config.costs.get(e["type"], {})
|
||||||
|
|
@ -250,7 +323,8 @@ func dismantle(id: int) -> Dictionary:
|
||||||
return refund
|
return refund
|
||||||
|
|
||||||
|
|
||||||
## Damages a structure; at 0 HP it breaks (debris, destroyed). Returns true if it broke.
|
## Damages a structure; at 0 HP it breaks (debris, destroyed). Returns true if it broke. The
|
||||||
|
## Workbench is repair-only: at 0 HP it's "broken" (hurt, not destroyed) and its record stays.
|
||||||
func damage(id: int, amount: int) -> bool:
|
func damage(id: int, amount: int) -> bool:
|
||||||
var e := campaign.state.structure(id)
|
var e := campaign.state.structure(id)
|
||||||
if e.is_empty():
|
if e.is_empty():
|
||||||
|
|
@ -258,7 +332,7 @@ func damage(id: int, amount: int) -> bool:
|
||||||
campaign.state.record_event("structures_damaged", mini(amount, int(e["hp"])))
|
campaign.state.record_event("structures_damaged", mini(amount, int(e["hp"])))
|
||||||
e["hp"] = maxi(int(e["hp"]) - amount, 0)
|
e["hp"] = maxi(int(e["hp"]) - amount, 0)
|
||||||
_wobble[id] = WOBBLE_TIME
|
_wobble[id] = WOBBLE_TIME
|
||||||
if int(e["hp"]) > 0:
|
if int(e["hp"]) > 0 or e["type"] == "workbench":
|
||||||
hurt.emit(id, Vector3(e["x"], 0.0, e["z"]))
|
hurt.emit(id, Vector3(e["x"], 0.0, e["z"]))
|
||||||
return false
|
return false
|
||||||
campaign.state.record_event("structures_destroyed")
|
campaign.state.record_event("structures_destroyed")
|
||||||
|
|
@ -455,10 +529,20 @@ func step(dt: float) -> void:
|
||||||
head.rotation.y = atan2(-dir.x, -dir.z)
|
head.rotation.y = atan2(-dir.x, -dir.z)
|
||||||
|
|
||||||
|
|
||||||
## Rebuilds every view and the navigation layer from the farm state (new vacation, retry).
|
## Rebuilds every view and the navigation layer from the farm state (new vacation, retry). The
|
||||||
|
## Workbench's view is the scene's own node, not a built one: hide it rather than free it, and
|
||||||
|
## derive its presence again (nights_survived >= 1, no record yet -- an older save, or a retry
|
||||||
|
## that somehow missed it) once the state's own structures are back.
|
||||||
func sync_from_state() -> void:
|
func sync_from_state() -> void:
|
||||||
for id in _views.keys():
|
for id in _views.keys():
|
||||||
(_views[id] as Node3D).queue_free()
|
var v: Node3D = _views[id]
|
||||||
|
if v == _workbench_node:
|
||||||
|
v.visible = false
|
||||||
|
var old_bar: MeshInstance3D = _bars.get(id)
|
||||||
|
if old_bar != null: # its own HP bar is a real child of the scene node: free it by hand
|
||||||
|
old_bar.queue_free()
|
||||||
|
else:
|
||||||
|
v.queue_free()
|
||||||
_views.clear()
|
_views.clear()
|
||||||
_bars.clear()
|
_bars.clear()
|
||||||
_bodies.clear()
|
_bodies.clear()
|
||||||
|
|
@ -469,6 +553,8 @@ func sync_from_state() -> void:
|
||||||
_gate_open.clear()
|
_gate_open.clear()
|
||||||
for e in campaign.state.structures:
|
for e in campaign.state.structures:
|
||||||
_add_view(e)
|
_add_view(e)
|
||||||
|
if campaign.state.nights_survived >= 1:
|
||||||
|
grant_workbench()
|
||||||
_update_nav()
|
_update_nav()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -525,7 +611,7 @@ func _remove(id: int) -> void:
|
||||||
s.structures.remove_at(i)
|
s.structures.remove_at(i)
|
||||||
break
|
break
|
||||||
var view: Node3D = _views.get(id)
|
var view: Node3D = _views.get(id)
|
||||||
if view != null:
|
if view != null and view != _workbench_node: # the scene's own node is hidden, never freed
|
||||||
view.queue_free()
|
view.queue_free()
|
||||||
for d in [_views, _bars, _bodies, _tints, _wobble, _heads, _turret_cd, _gate_open]:
|
for d in [_views, _bars, _bodies, _tints, _wobble, _heads, _turret_cd, _gate_open]:
|
||||||
(d as Dictionary).erase(id)
|
(d as Dictionary).erase(id)
|
||||||
|
|
@ -555,13 +641,20 @@ func _update_nav() -> void:
|
||||||
layout_changed.emit()
|
layout_changed.emit()
|
||||||
|
|
||||||
|
|
||||||
|
## The Workbench reuses the scene's own node (shown, not built) instead of a fresh _build_view(),
|
||||||
|
## so there's only ever the one mesh; every other type is built and parented here as usual.
|
||||||
func _add_view(e: Dictionary) -> void:
|
func _add_view(e: Dictionary) -> void:
|
||||||
var id: int = e["id"]
|
var id: int = e["id"]
|
||||||
var view := _build_view(e["type"], e["rot"], int(e.get("level", 1)))
|
var view: Node3D
|
||||||
view.name = "%s_%d" % [e["type"], id]
|
if e["type"] == "workbench" and _workbench_node != null:
|
||||||
add_child(view)
|
view = _workbench_node
|
||||||
|
view.visible = true
|
||||||
|
else:
|
||||||
|
view = _build_view(e["type"], e["rot"], int(e.get("level", 1)))
|
||||||
|
view.name = "%s_%d" % [e["type"], id]
|
||||||
|
add_child(view)
|
||||||
|
view.global_position = Vector3(e["x"], _ground_y(Vector2(e["x"], e["z"])), e["z"])
|
||||||
_views[id] = view
|
_views[id] = view
|
||||||
view.global_position = Vector3(e["x"], _ground_y(Vector2(e["x"], e["z"])), e["z"])
|
|
||||||
var rids: Array[RID] = []
|
var rids: Array[RID] = []
|
||||||
for body in view.find_children("*", "StaticBody3D", true, false):
|
for body in view.find_children("*", "StaticBody3D", true, false):
|
||||||
rids.append((body as StaticBody3D).get_rid())
|
rids.append((body as StaticBody3D).get_rid())
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,23 @@ class_name Workbench
|
||||||
extends Node3D
|
extends Node3D
|
||||||
## The work area's tool table, where the scarecrow buys upgrades (Upgrades, UpgradePanel): press
|
## The work area's tool table, where the scarecrow buys upgrades (Upgrades, UpgradePanel): press
|
||||||
## interact here by day to open the menu. Its label shows how many are done.
|
## interact here by day to open the menu. Its label shows how many are done.
|
||||||
|
## #9: not there from the start -- StructureSystem grants it once Night 1 is survived, reusing
|
||||||
|
## this very node as its view (hidden until then, StructureSystem._add_view toggles it back on;
|
||||||
|
## see grant_workbench()). It then has HP like any other structure, and can be damaged and
|
||||||
|
## repaired; at 0 HP it's broken (show_state's broken prompt) until repaired, instead of being
|
||||||
|
## destroyed.
|
||||||
|
|
||||||
## How close the scarecrow's center has to be to this node's origin.
|
## How close the scarecrow's center has to be to this node's origin.
|
||||||
@export var reach: float = 2.2
|
@export var reach: float = 2.2
|
||||||
|
|
||||||
|
const NORMAL_COLOR := Color(0.85, 0.75, 1.0)
|
||||||
|
const BROKEN_COLOR := Color(1.0, 0.55, 0.45)
|
||||||
|
|
||||||
var _label: Label3D
|
var _label: Label3D
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
visible = false # granted, not built -- StructureSystem shows it once that's happened
|
||||||
_label = Label3D.new()
|
_label = Label3D.new()
|
||||||
_label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
_label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
||||||
_label.no_depth_test = true
|
_label.no_depth_test = true
|
||||||
|
|
@ -17,16 +26,22 @@ func _ready() -> void:
|
||||||
_label.font_size = 40
|
_label.font_size = 40
|
||||||
_label.outline_size = 10
|
_label.outline_size = 10
|
||||||
_label.pixel_size = 0.0075
|
_label.pixel_size = 0.0075
|
||||||
_label.modulate = Color(0.85, 0.75, 1.0)
|
_label.modulate = NORMAL_COLOR
|
||||||
_label.position = Vector3(0.0, 2.2, 0.0)
|
_label.position = Vector3(0.0, 2.2, 0.0)
|
||||||
_label.visible = false
|
_label.visible = false
|
||||||
add_child(_label)
|
add_child(_label)
|
||||||
|
|
||||||
|
|
||||||
func show_state(campaign: CampaignController, show: bool, focused: bool) -> void:
|
## broken (0 HP): the shop can't be opened until it's repaired.
|
||||||
|
func show_state(campaign: CampaignController, show: bool, focused: bool, broken: bool = false) -> void:
|
||||||
_label.visible = show
|
_label.visible = show
|
||||||
if not show:
|
if not show:
|
||||||
return
|
return
|
||||||
|
if broken:
|
||||||
|
_label.modulate = BROKEN_COLOR
|
||||||
|
_label.text = "Broken -- repair it" if focused else "Broken"
|
||||||
|
return
|
||||||
|
_label.modulate = NORMAL_COLOR
|
||||||
var done := 0
|
var done := 0
|
||||||
for id in Upgrades.ORDER:
|
for id in Upgrades.ORDER:
|
||||||
if Upgrades.owned(campaign.state, id):
|
if Upgrades.owned(campaign.state, id):
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ func run(r: GameTestRunner) -> void:
|
||||||
sim.waves.rng.seed = 1 # tonight's 11 arrival points, drawn the same every run
|
sim.waves.rng.seed = 1 # tonight's 11 arrival points, drawn the same every run
|
||||||
var player := farm.get_node("Player") as PlayerCharacter
|
var player := farm.get_node("Player") as PlayerCharacter
|
||||||
player.global_position = AWAY
|
player.global_position = AWAY
|
||||||
|
sim.structures.grant_workbench() # #9: granted up front so it doesn't shift the structure
|
||||||
|
# counts this test tracks across night 1 (it isn't about the Workbench itself)
|
||||||
var review := farm.get_node("Hud/ReviewPanel") as ReviewPanel
|
var review := farm.get_node("Hud/ReviewPanel") as ReviewPanel
|
||||||
var hud := farm.get_node("Hud/PhaseHud") as PhaseHud
|
var hud := farm.get_node("Hud/PhaseHud") as PhaseHud
|
||||||
var assets := farm.get_node("Hud/AssetHud") as AssetHud
|
var assets := farm.get_node("Hud/AssetHud") as AssetHud
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,9 @@ func _five_nights(r: GameTestRunner, farm: Node3D, sim: FarmSim, player: PlayerC
|
||||||
var hud := farm.get_node("Hud/PhaseHud") as PhaseHud
|
var hud := farm.get_node("Hud/PhaseHud") as PhaseHud
|
||||||
c.new_campaign()
|
c.new_campaign()
|
||||||
_step(sim, 1)
|
_step(sim, 1)
|
||||||
|
sim.structures.grant_workbench() # #9: granted once, up front, so the per-night structure
|
||||||
|
# count below (broken aside) doesn't trip over the night-1 grant itself
|
||||||
|
c._morning_snapshot = c.state.to_dict() # ...and this morning's snapshot (the loop checks it) agrees
|
||||||
sim.waves.enabled = true
|
sim.waves.enabled = true
|
||||||
player.global_position = AWAY
|
player.global_position = AWAY
|
||||||
var arrivals := {}
|
var arrivals := {}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,11 @@ extends RefCounted
|
||||||
## persistence and retry, an A/B night: the same attack on an open and on a fenced crop field, and
|
## persistence and retry, an A/B night: the same attack on an open and on a fenced crop field, and
|
||||||
## per-instance leveling (#10): a turret's fire rate and L3 volley, a tar patch's footprint, paid
|
## per-instance leveling (#10): a turret's fire rate and L3 volley, a tar patch's footprint, paid
|
||||||
## independently per placed structure, the rules around it (repair first, room, afford), and that
|
## independently per placed structure, the rules around it (repair first, room, afford), and that
|
||||||
## the level survives a save/retry round trip.
|
## the level survives a save/retry round trip; and the Workbench (#9): absent and inaccessible
|
||||||
|
## (no prompt, no shop, including over a co-op request) before Night 1, granted into state before
|
||||||
|
## the morning snapshot once it's survived, then damaged by an enemy like any barrier, "broken"
|
||||||
|
## (not destroyed) at 0 HP with its shop refused, repaired at the normal proportional cost, and
|
||||||
|
## its presence and HP surviving a save and a retry.
|
||||||
|
|
||||||
const P := CampaignController.Phase
|
const P := CampaignController.Phase
|
||||||
const T := ThiefBehavior.State
|
const T := ThiefBehavior.State
|
||||||
|
|
@ -40,6 +44,7 @@ func run(r: GameTestRunner) -> void:
|
||||||
_repair_and_dismantle(r, sim, player)
|
_repair_and_dismantle(r, sim, player)
|
||||||
_persistence(r, sim)
|
_persistence(r, sim)
|
||||||
_ab_night(r, sim, player)
|
_ab_night(r, sim, player)
|
||||||
|
_workbench(r, sim, player)
|
||||||
farm.queue_free()
|
farm.queue_free()
|
||||||
await r.process_frame
|
await r.process_frame
|
||||||
|
|
||||||
|
|
@ -554,6 +559,146 @@ func _ab_night(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
|
||||||
r.check(defended[0] < open[0], "defenses change the outcome of the same attack (%d < %d units lost)" % [defended[0], open[0]])
|
r.check(defended[0] < open[0], "defenses change the outcome of the same attack (%d < %d units lost)" % [defended[0], open[0]])
|
||||||
|
|
||||||
|
|
||||||
|
## Task #9: the Workbench is granted (not built) once Night 1 is survived. A fresh new_campaign()
|
||||||
|
## (the A/B nights above leave the campaign well past night 1) so "before Night 1" means something.
|
||||||
|
func _workbench(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
||||||
|
var c := sim.campaign
|
||||||
|
var st := sim.structures
|
||||||
|
var it := sim.interactions
|
||||||
|
var bench := it.workbench
|
||||||
|
var es := sim.enemies
|
||||||
|
c.new_campaign()
|
||||||
|
_step(sim, 1)
|
||||||
|
r.check(not st.has_workbench() and st.workbench_id() == -1 and not bench.visible,
|
||||||
|
"a fresh vacation, morning of night 1: the Workbench isn't a structure yet, and its scene node is hidden")
|
||||||
|
_rich(c)
|
||||||
|
c.begin_day()
|
||||||
|
player.global_position = bench.global_position + Vector3(0.0, 0.0, 1.2)
|
||||||
|
var msgs: Array[String] = []
|
||||||
|
it.message.connect(func(t: String, _col: Color) -> void: msgs.append(t))
|
||||||
|
Input.action_release("interact")
|
||||||
|
_tap(sim, "interact")
|
||||||
|
r.check(not sim.upgrade_panel.is_open, "standing where it will be, before night 1, interact opens no shop")
|
||||||
|
r.check(msgs.is_empty(), "and no workbench prompt or message fires either (it isn't focused: it doesn't exist) (%s)" % [msgs])
|
||||||
|
var coop := CoopSession.new()
|
||||||
|
coop.sim = sim
|
||||||
|
coop._do_request(["buy", "straw_stuffing"])
|
||||||
|
r.check(not Upgrades.owned(c.state, "straw_stuffing"), "a co-op 'buy' request for a workbench-shop item is refused before the workbench exists")
|
||||||
|
|
||||||
|
# Survive night 1: DAY -> DUSK -> NIGHT -> DAWN -> MORNING. night_ending grants it (before the
|
||||||
|
# morning snapshot/save, like #13's crop growth).
|
||||||
|
c.advance_phase()
|
||||||
|
c.advance_phase()
|
||||||
|
c.advance_phase()
|
||||||
|
c.advance_phase()
|
||||||
|
r.check(c.state.phase == P.MORNING and c.state.nights_survived == 1, "night 1 is behind us")
|
||||||
|
var id := st.workbench_id()
|
||||||
|
r.check(id >= 1 and st.has_workbench() and bench.visible and not StructureSystem.ORDER.has("workbench"),
|
||||||
|
"the Workbench now exists as a real (but not buildable) structure, and its scene node shows")
|
||||||
|
r.check(int(c.state.structure(id)["hp"]) == st.max_hp("workbench"), "granted at full HP")
|
||||||
|
var morning_structs: Array = c.state.to_dict()["structures"]
|
||||||
|
r.check(morning_structs.any(func(e: Dictionary) -> bool: return String(e["type"]) == "workbench"),
|
||||||
|
"it was already in state before the morning snapshot was taken")
|
||||||
|
|
||||||
|
c.begin_day()
|
||||||
|
player.global_position = bench.global_position + Vector3(0.0, 0.0, 1.2)
|
||||||
|
msgs.clear()
|
||||||
|
_tap(sim, "interact")
|
||||||
|
r.check(sim.upgrade_panel.is_open, "now its shop opens like any other workbench day")
|
||||||
|
_tap(sim, "interact")
|
||||||
|
|
||||||
|
# Targeting (Decision 3): FarmSim._breaker_goals() treats an unbroken Workbench as guarding its
|
||||||
|
# own work area, alongside whatever else is actually guarding something -- PenRing.build_gate_only
|
||||||
|
# places one real guarding structure (the same single-gate setup test_roster.gd's own fence-
|
||||||
|
# breaker test uses), so this proves the Workbench joins a non-empty guarding set, not just a
|
||||||
|
# fallback when nothing else guards anything.
|
||||||
|
var gate_id := PenRing.build_gate_only(sim)
|
||||||
|
_settle(sim)
|
||||||
|
var goals := sim._breaker_goals()
|
||||||
|
r.check(_goals_near(sim, goals, bench.global_position) and _goals_near(sim, goals, Vector3(PenRing.EAST_X, 0.0, PenRing.GATE_Z)),
|
||||||
|
"an unbroken Workbench is in the breaker goals alongside the pen gate guarding the pen")
|
||||||
|
# Spawned far closer to the Work Area than to the pen, a fence breaker -- with no hand-set
|
||||||
|
# state or barrier, driven only by its own AI -- heads for and smashes the Workbench on its own.
|
||||||
|
# The scarecrow stays well clear (AWAY): close by, the breaker would aggro onto it instead
|
||||||
|
# (ThiefBehavior._aggro, aggro_range 4 m) and never reach BREAK.
|
||||||
|
player.global_position = AWAY
|
||||||
|
var hb := sim.spawn_enemy(EnemySystem.TYPE_BREAKER, LootSystem.ANY, GameTestRunner.EDGE["driveway"])
|
||||||
|
var at := _until(sim, func() -> bool: return es.resolve_handle(hb) >= 0 and es.state[es.resolve_handle(hb)] == T.BREAK, 40.0)
|
||||||
|
var dh := es.resolve_handle(hb)
|
||||||
|
r.check(at < 40.0 and dh >= 0 and es.barrier[dh] == id,
|
||||||
|
"a fence breaker (no hand-set state) targets and walks to the Workbench on its own (%.1f s)" % at)
|
||||||
|
var hp0 := int(c.state.structure(id)["hp"])
|
||||||
|
_step(sim, roundi(es.t_hit_interval[EnemySystem.TYPE_BREAKER] * 60.0) + 4)
|
||||||
|
r.check(int(c.state.structure(id)["hp"]) < hp0, "and actually damages it")
|
||||||
|
es.apply_hit_handle(hb, 99)
|
||||||
|
_step(sim, 1)
|
||||||
|
st.dismantle(gate_id)
|
||||||
|
_settle(sim)
|
||||||
|
|
||||||
|
# Broken at 0 HP: the record stays (repair-only, not destroyed/removed); its shop is refused,
|
||||||
|
# and it drops out of the breaker goals (nothing left to gain by sending another breaker at it).
|
||||||
|
var destroyed: Array[String] = []
|
||||||
|
st.destroyed.connect(func(_i: int, t: String, _at: Vector3) -> void: destroyed.append(t))
|
||||||
|
r.check(not st.damage(id, 9999) and not c.state.structure(id).is_empty() and int(c.state.structure(id)["hp"]) == 0,
|
||||||
|
"damaging it to 0 HP leaves it 'broken', not destroyed: the record stays")
|
||||||
|
r.check(destroyed.is_empty(), "no breach/destroyed signal for it")
|
||||||
|
r.check(not _goals_near(sim, sim._breaker_goals(), bench.global_position), "a broken Workbench drops out of the breaker goals")
|
||||||
|
# Just outside REPAIR_REACH (1.4 m to the footprint's edge, 0.5 m out from center) but inside
|
||||||
|
# the Workbench's own reach (2.2 m, to its center): repair takes priority within REPAIR_REACH
|
||||||
|
# (Interactions), so this is where its shop's own refusal shows.
|
||||||
|
player.global_position = bench.global_position + Vector3(0.0, 0.0, 2.0)
|
||||||
|
msgs.clear()
|
||||||
|
_tap(sim, "interact")
|
||||||
|
r.check(not sim.upgrade_panel.is_open and msgs.has("Broken -- repair it"), "its shop refuses to open while broken (%s)" % [msgs])
|
||||||
|
coop._do_request(["buy", "straw_stuffing"])
|
||||||
|
r.check(not Upgrades.owned(c.state, "straw_stuffing"), "a co-op 'buy' request is refused while it's broken too")
|
||||||
|
|
||||||
|
# Repaired at the normal proportional cost (StructureSystem.repair_cost/repair), from within
|
||||||
|
# REPAIR_REACH.
|
||||||
|
var cost := st.repair_cost(id)
|
||||||
|
r.check(not cost.is_empty() and cost == sim.config.costs["workbench"], "broken (0 of its HP), repairing costs the full amount (%s)" % [cost])
|
||||||
|
c.state.resources.shed = cost.duplicate()
|
||||||
|
player.global_position = bench.global_position + Vector3(0.0, 0.0, 1.2)
|
||||||
|
Input.action_press("interact")
|
||||||
|
_step(sim, roundi(sim.config.repair_time * 60.0) + 2)
|
||||||
|
Input.action_release("interact")
|
||||||
|
_step(sim, 1)
|
||||||
|
r.check(int(c.state.structure(id)["hp"]) == st.max_hp("workbench"), "holding interact repairs it fully, for the proportional cost")
|
||||||
|
msgs.clear()
|
||||||
|
_tap(sim, "interact")
|
||||||
|
r.check(sim.upgrade_panel.is_open, "repaired, its shop opens again")
|
||||||
|
_tap(sim, "interact")
|
||||||
|
|
||||||
|
# Persistence: presence and HP survive a save (JSON) round trip and a retry.
|
||||||
|
var d2 := c.state.to_dict()
|
||||||
|
var back := FarmState.from_dict(JSON.parse_string(JSON.stringify(d2, "", true, true)))
|
||||||
|
r.check(back != null and back.structure(id)["type"] == "workbench" and int(back.structure(id)["hp"]) == st.max_hp("workbench"),
|
||||||
|
"its presence and HP survive a save (JSON) round trip")
|
||||||
|
st.damage(id, 5)
|
||||||
|
c.advance_phase() # DAY -> DUSK
|
||||||
|
c.advance_phase() # DUSK -> NIGHT
|
||||||
|
c.state.scarecrow_hp = 0
|
||||||
|
_step(sim, 1)
|
||||||
|
c.retry_night()
|
||||||
|
_step(sim, 1)
|
||||||
|
r.check(st.has_workbench() and int(c.state.structure(st.workbench_id())["hp"]) == st.max_hp("workbench"),
|
||||||
|
"a retry restores the morning's Workbench, undamaged by what happened after")
|
||||||
|
player.global_position = AWAY
|
||||||
|
_settle(sim)
|
||||||
|
|
||||||
|
|
||||||
|
## Whether any of FarmSim._breaker_goals()'s cells (walkable cells near a guarding barrier's
|
||||||
|
## footprint) sit near a world position -- 3 m is generous (the goal cells themselves are within
|
||||||
|
## ~1.1 m of a footprint's edge) but well short of the distance between the Workbench and the pen
|
||||||
|
## gate used alongside it above, so it can't mistake one guarding structure's goals for the other's.
|
||||||
|
func _goals_near(sim: FarmSim, goals: PackedInt32Array, at: Vector3) -> bool:
|
||||||
|
var p := Vector2(at.x, at.z)
|
||||||
|
for cell in goals:
|
||||||
|
if sim.nav.cell_center(cell).distance_to(p) <= 3.0:
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
func _field_fences() -> Array:
|
func _field_fences() -> Array:
|
||||||
var parts: Array = []
|
var parts: Array = []
|
||||||
for k in 15:
|
for k in 15:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue