Merge task #8: Radar, a hidden Supply Shed item that reveals enemies on a minimap

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-05 16:09:39 -04:00
commit 94ac35015e
9 changed files with 219 additions and 1 deletions

View file

@ -57,6 +57,10 @@ costs = {
"scrap": 6,
"straw": 16
},
"radar": {
"scrap": 8,
"wood": 6
},
"rapid_fire": {
"scrap": 12,
"straw": 12,
@ -152,6 +156,13 @@ upgrades = {
"text": "Fear recharges 20% faster",
"track": "Fear"
},
"radar": {
"hidden": true,
"name": "Radar",
"shop": "shed",
"text": "A minimap showing nearby enemy positions",
"track": "Item"
},
"rapid_fire": {
"mult": 3.0,
"name": "Rapid fire",

View file

@ -289,6 +289,11 @@ func _ready() -> void:
review_panel.refresh()
if hud != null:
hud.setup(scarecrow, campaign, combat)
if hud != null and hud.get_parent() != null:
var radar_hud := RadarHud.new()
radar_hud.name = "RadarHud"
hud.get_parent().add_child(radar_hud)
radar_hud.setup(self)
ending = FarmersReturn.new()
ending.name = "FarmersReturn"
add_child(ending)

View file

@ -130,6 +130,7 @@ extends Resource
"reinforced_fences": {"wood": 20, "scrap": 6},
"long_range": {"scrap": 14, "wood": 10},
"sticky_tar": {"straw": 14, "scrap": 6},
"radar": {"scrap": 8, "wood": 6},
"fence": {"wood": 2},
"gate": {"wood": 4, "scrap": 1},
"slowing_trap": {"scrap": 3, "wood": 1},
@ -153,6 +154,7 @@ extends Resource
"shurikens": {"name": "Shurikens", "text": "Fast, cheap throws for a quick hit", "track": "Weapon", "shop": "shed"},
"propane_torch": {"name": "Propane torch", "text": "A short-range jet of flame that burns everything in its cone while held", "track": "Weapon", "shop": "shed"},
"alien_ray": {"name": "Alien ray", "text": "A salvaged alien weapon: a fast, powerful beam", "track": "Weapon", "shop": "shed", "hidden": true},
"radar": {"name": "Radar", "text": "A minimap showing nearby enemy positions", "track": "Item", "shop": "shed", "hidden": true},
"wide_fear": {"name": "Wide fear", "text": "Fear reaches 30% farther", "track": "Fear", "stat": "fear_radius", "mult": 1.3},
"quick_fear": {"name": "Quick fear", "text": "Fear recharges 20% faster", "track": "Fear", "stat": "fear_cooldown", "mult": 0.8},
"straw_stuffing": {"name": "Straw stuffing", "text": "+2 max health", "track": "Scarecrow", "stat": "scarecrow_max_hp", "add": 2},
@ -297,6 +299,16 @@ extends Resource
@export var alien_ray_speed: float = 50.0
@export var alien_ray_lifetime: float = 2.0
@export_group("Radar")
## Radar (the Radar item, bought at the supply shed, hidden until hidden_reveal_goop Alien Goop is
## collected, #8): once owned, a minimap shows every alive enemy within radar_range meters of the
## local scarecrow, redrawn every radar_refresh seconds (RadarHud). 40 m is generous: it covers
## most of the playable farm (60x60) from a central position, so the minimap is useful without
## needing to be perfectly centered on the scarecrow at all times. A quarter-second refresh keeps
## the dots responsive without redrawing every frame.
@export var radar_range: float = 40.0
@export var radar_refresh: float = 0.25
@export_group("Enemies")
@export_range(1, 1024) var enemy_capacity: int = 800
## The enemy roster (EnemySystem.TYPE_NAMES), one row per type:

114
game/scripts/radar_hud.gd Normal file
View file

@ -0,0 +1,114 @@
class_name RadarHud
extends Control
## Top-right minimap, under ResourceHud's materials readout (Task #8): the playable farm's
## outline scaled into a small panel, a white dot for the local scarecrow, and one dot per alive
## enemy within GameConfig.radar_range meters of it, colored by type. Hidden unless the Radar
## upgrade is bought (Upgrades.owned(state, "radar")); like the Alien Ray, it's a hidden shed item
## revealed once enough Alien Goop has been collected (Upgrades.revealed). Redrawn every
## GameConfig.radar_refresh seconds rather than every frame, matching the "sweep" feel of a radar
## rather than a live camera.
## Panel size, and its offset from the screen's top-right corner (below ResourceHud, which uses
## roughly the top 120 px of that corner: PhaseHud/AssetHud/ScarecrowHud/CoopHud leave the rest of
## the right side clear).
const MAP_SIZE := Vector2(190.0, 190.0)
const MARGIN_RIGHT := 24.0
const MARGIN_TOP := 140.0
const DOT_RADIUS := 4.0
const PLAYER_RADIUS := 5.0
## thief (alien), crow, breaker (alien robot), ufo: EnemySystem.TYPE_*.
const TYPE_COLORS: Array[Color] = [Color(1.0, 0.3, 0.25), Color(0.95, 0.85, 0.3), Color(0.8, 0.4, 1.0), Color(0.4, 1.0, 0.55)]
var sim: FarmSim
var _title: Label
var _refresh_left: float = 0.0
## The last plotted enemy dots: {"pos": Vector2 (world x, z), "type": int}. Exposed for tests.
var dots: Array[Dictionary] = []
## Whether the scarecrow was plotted this refresh (false until the first refresh happens).
var player_plotted := false
var _player_pos := Vector2.ZERO
func setup(p_sim: FarmSim) -> void:
sim = p_sim
_refresh_left = 0.0
func _ready() -> void:
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
mouse_filter = Control.MOUSE_FILTER_IGNORE
_title = Label.new()
_title.text = "Radar"
_title.add_theme_font_size_override("font_size", 18)
_title.add_theme_color_override("font_outline_color", Color.BLACK)
_title.add_theme_constant_override("outline_size", 6)
_title.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(_title)
func _process(delta: float) -> void:
visible = sim != null and sim.campaign != null and Upgrades.owned(sim.campaign.state, "radar")
if not visible:
return
_title.position = _rect().position + Vector2(10.0, 6.0)
_refresh_left -= delta
if _refresh_left <= 0.0:
_refresh()
_refresh_left = sim.campaign.config.radar_refresh
queue_redraw()
## Rebuilds `dots` from the live enemy positions, filtered to radar_range of the local scarecrow
## (EnemySystem's dense arrays: alive, pos_x/pos_z, type). Works the same on a co-op replica,
## whose EnemySystem gets the host's positions synced into it.
func _refresh() -> void:
dots.clear()
player_plotted = false
if sim == null or sim.enemies == null or sim.local_avatar == null or sim.campaign == null:
return
var cfg := sim.campaign.config
_player_pos = sim.local_avatar.position()
player_plotted = true
var es := sim.enemies
for d in es.active_count:
if es.alive[d] == 1:
var p := Vector2(es.pos_x[d], es.pos_z[d])
if _player_pos.distance_to(p) <= cfg.radar_range:
dots.append({"pos": p, "type": int(es.type[d])})
## How many enemy dots are currently plotted (tests).
func dot_count() -> int:
return dots.size()
func _draw() -> void:
if not visible:
return
var r := _rect()
draw_rect(r, Color(0.0, 0.0, 0.0, 0.42))
var inner := Rect2(r.position + Vector2(10.0, 30.0), r.size - Vector2(20.0, 40.0))
draw_rect(inner, Color(0.08, 0.14, 0.08, 0.85))
draw_rect(inner, Color(0.5, 0.7, 0.5, 0.6), false, 1.5)
if sim == null or sim.zones == null:
return
var playable: Rect2 = sim.zones.playable
if player_plotted:
draw_circle(_to_map(inner, playable, _player_pos), PLAYER_RADIUS, Color(1.0, 1.0, 1.0))
for dot: Dictionary in dots:
var t := int(dot["type"])
var color := TYPE_COLORS[t] if t < TYPE_COLORS.size() else Color.WHITE
draw_circle(_to_map(inner, playable, dot["pos"]), DOT_RADIUS, color)
## A world point (x, z) placed proportionally inside the minimap's inner rect (clamped: an enemy
## within radar_range but outside the playable rect still shows, pinned to the nearest edge).
static func _to_map(inner: Rect2, playable: Rect2, world: Vector2) -> Vector2:
var fx := (world.x - playable.position.x) / playable.size.x
var fy := (world.y - playable.position.y) / playable.size.y
return inner.position + Vector2(clampf(fx, 0.0, 1.0), clampf(fy, 0.0, 1.0)) * inner.size
func _rect() -> Rect2:
return Rect2(Vector2(size.x - MARGIN_RIGHT - MAP_SIZE.x, MARGIN_TOP), MAP_SIZE)

View file

@ -0,0 +1 @@
uid://by4nfx6ob5nsn

View file

@ -16,7 +16,7 @@ extends RefCounted
## Menu order, grouped by track.
const ORDER: Array[String] = ["corn_shooter", "rapid_fire", "heavy_seeds", "pumpkin_bomb", "potato_cannon", "shurikens",
"propane_torch", "alien_ray", "wide_fear", "quick_fear",
"propane_torch", "alien_ray", "radar", "wide_fear", "quick_fear",
"straw_stuffing", "pouch_upgrade", "sprint", "reinforced_fences", "long_range", "sticky_tar"]

View file

@ -17,6 +17,7 @@ const SUITES := [
"res://game/tests/test_economy.gd",
"res://game/tests/test_structures.gd",
"res://game/tests/test_targets.gd",
"res://game/tests/test_radar.gd",
"res://game/tests/test_roster.gd",
"res://game/tests/test_nights.gd",
"res://game/tests/test_cycle.gd",

73
game/tests/test_radar.gd Normal file
View file

@ -0,0 +1,73 @@
extends RefCounted
## Task #8: Radar, a hidden Supply Shed item (minimap reveal, Decision 16). Hidden (a "?" row,
## unbuyable) until enough Alien Goop is collected, like the Alien Ray; buyable once revealed; the
## RadarHud minimap stays hidden until it's bought, then shows a dot for every alive enemy within
## GameConfig.radar_range of the local scarecrow (farther ones excluded) plus the scarecrow
## itself; ownership survives a FarmState JSON round trip (FarmState.upgrades is saved).
const DT := 1.0 / 60.0
const SPOT := Vector2(8.0, -10.0) # open ground between the pen, the shed, and the field
func run(r: GameTestRunner) -> void:
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
r.root.add_child(farm)
await r.process_frame
await r.physics_frame
var sim := farm.get_node("FarmSim") as FarmSim
sim.set_physics_process(false)
sim.waves.enabled = false
var player := farm.get_node("Player") as PlayerCharacter
player.global_position = Vector3(SPOT.x, 0.0, SPOT.y)
var radar := farm.get_node("Hud/RadarHud") as RadarHud
var shed_panel := farm.get_node("Hud/ShedPanel") as UpgradePanel
var c := sim.campaign
var s := c.state
var cfg := sim.config
radar._process(0.0)
r.check(radar != null and not radar.visible, "the radar minimap is hidden before the Radar item is bought")
r.check(Upgrades.blocker(c, "radar") == "Not discovered yet", "radar is unbuyable with no Alien Goop collected: '%s'" % Upgrades.blocker(c, "radar"))
shed_panel.refresh()
r.check((shed_panel._rows["radar"] as Button).text == "?", "radar's shed row shows only '?' before it's revealed")
c.begin_day()
s.resources.shed = {"wood": 50, "scrap": 50, "straw": 50, "alien_goop": 0}
r.check(not Upgrades.revealed(s, cfg, "radar"), "still not revealed with zero goop collected")
s.night_events["gathered_alien_goop"] = cfg.hidden_reveal_goop # enough to reveal it, like the Alien Ray
r.check(Upgrades.revealed(s, cfg, "radar"), "revealed once hidden_reveal_goop (%d) is collected" % cfg.hidden_reveal_goop)
shed_panel.refresh()
r.check((shed_panel._rows["radar"] as Button).text.begins_with("Radar —"), "radar's shed row shows its name once revealed: '%s'" % (shed_panel._rows["radar"] as Button).text)
var text := Upgrades.buy(c, "radar", sim.structures)
r.check(Upgrades.owned(s, "radar") and text.contains("done:"), "radar bought: '%s'" % text)
radar._process(0.0)
r.check(radar.visible, "the radar minimap shows once the Radar item is bought")
var es := sim.enemies
var near_thief := es.spawn(EnemySystem.TYPE_THIEF, SPOT.x + 5.0, SPOT.y, Vector2.LEFT)
var near_crow := es.spawn(EnemySystem.TYPE_CROW, SPOT.x, SPOT.y - 6.0, Vector2.UP)
var far_breaker := es.spawn(EnemySystem.TYPE_BREAKER, SPOT.x + cfg.radar_range + 20.0, SPOT.y, Vector2.LEFT)
radar._refresh()
r.check(radar.dot_count() == 2, "two alive enemies within radar_range are plotted (got %d)" % radar.dot_count())
r.check(radar.player_plotted, "the scarecrow itself is plotted on the minimap")
var types: Array = []
for dot: Dictionary in radar.dots:
types.append(int(dot["type"]))
types.sort()
r.check(types == [EnemySystem.TYPE_THIEF, EnemySystem.TYPE_CROW],
"the plotted dots are the near thief and crow, not the far-off breaker (got %s)" % [types])
# Killing the two in-range enemies drops the plotted count back to zero.
es.apply_hit(es.resolve_handle(near_thief), 99)
es.apply_hit(es.resolve_handle(near_crow), 99)
radar._refresh()
r.check(radar.dot_count() == 0, "no dots once the in-range enemies are dead (the far breaker was never counted)")
es.apply_hit(es.resolve_handle(far_breaker), 99)
# Ownership survives a save round trip (FarmState.to_dict/from_dict, same as SaveGame does through JSON).
var round_tripped := FarmState.from_dict(JSON.parse_string(JSON.stringify(s.to_dict())))
r.check(round_tripped != null and Upgrades.owned(round_tripped, "radar"), "radar ownership survives a FarmState JSON round trip")
farm.queue_free()
await r.process_frame

View file

@ -0,0 +1 @@
uid://r4rkv2vhuack