Repository navigation
111 worked example a data driven vehicle selector
Question (issue #15, the last of the four issues from document 110's "agnostic engine" audit): the vehicle-select hangar has four bays and a hardcoded neighbour table tied to the original's own four types. Since step 6 a map's roster can be reordered, shrunk, or grown past four -- none of that is reachable from the actual in-game selection screen. The user's own constraint, given directly once the design was underway: the hangar always shows exactly 4 bays, visually.
MatchController.selection was used as both "which bay is the cursor on" and "which vehicle_type is chosen" -- fine as long as those were the same number, which they always were, because the original always shows Tank/Jeep/MSV/Heli in the same four bays in the same order. vehicle_stock[selection], SELECT_NEIGHBOURS[selection], vehicle.set_vehicle_type(selection) -- every one of these silently assumed bay index and vehicle type were interchangeable.
Once a roster can reorder or resize, that assumption breaks: a mod's roster with a new 5th vehicle has no bay for it at all in a 4-entry neighbour table, and a roster that puts a different vehicle first no longer matches SELECT_NEIGHBOURS[0]'s meaning ("the Tank's neighbours"). The fix isn't to make the table bigger -- the hangar's own art (cel 2075) only has four physical slots, and the user was explicit that this stays four, visually, regardless of roster size. The fix is to stop conflating the two numbers.
var selector_roster: Array[int] = [] ## vehicle_type per roster position, this level's effective roster
var selector_page := 0 ## which group of 4 roster entries the hangar currently shows
var selection := 0 ## a BAY INDEX (0-3), not a vehicle_type
func _bay_type(bay: int, page: int = -1) -> int:
var p := selector_page if page < 0 else page
var i := p * 4 + bay
return selector_roster[i] if i >= 0 and i < selector_roster.size() else -1selector_roster is built once, when the choice opens, straight from the same effective roster step 6 already computes:
func _open_selection() -> void:
selector_roster = []
for entry in pack.roster_for(level):
var t := pack.vehicle_index(String(entry.get("id", "")))
if t >= 0:
selector_roster.append(t)
...For the unmodified original roster (rf.tank, rf.jeep, rf.msv, rf.heli, in that order -- vehicles/roster.json) this is exactly [0, 1, 2, 3]. Bay 0 is vehicle_type 0 (the Tank), bay 1 is vehicle_type 1 (the Jeep), and so on -- identical to the old, conflated behaviour. That's not a coincidence to verify once; it's the reason every existing test (select_check.gd, stock_check.gd, dock_check.gd, preraise_sound_check.gd, and others that read or set mc.selection directly) needed zero changes and still passed. They were never testing "bay == vehicle_type" as an assumption to preserve; they were testing the original game's own behaviour, which this refactor doesn't touch for the original roster.
SELECT_NEIGHBOURS was a hardcoded const in match_controller.gd -- [[0, 1, 3, 0], [0, 1, 2, 1], [3, 2, 2, 1], [3, 2, 3, 0]]. But selector.json (built by tools/extract_selector.py, document 78) already carries the identical information per bay:
"entries": {"0": {"up": 0, "down": 1, "left": 3, "right": 0, ...}, "1": {...}, ...}The neighbour table is the hangar's physical layout -- which bay is above, below, left and right of which -- and that never had anything to do with which vehicle sits in a bay. It doesn't need to become "data-driven"; it already was data, just copied into a second, redundant place in code. Deleting the constant and reading the pack directly removes the duplication as a side effect of the real fix:
func _bay_neighbour(bay: int, dir: int) -> int:
var e: Dictionary = pack.selector_data.get("entries", {}).get(str(bay), {})
return int(e.get(["up", "down", "left", "right"][dir], bay))select_move()'s own logic (try the neighbour, fall back to its other-axis neighbours, give up and stay put) is unchanged -- only the two lookups (SELECT_NEIGHBOURS[cur][dir] -> _bay_neighbour(cur, dir)) and the two stock checks (vehicle_stock[cand] -> vehicle_stock[_bay_type(cand)], with _bay_type(cand) < 0 treated exactly like zero stock -- an empty bay) changed.
A roster with a fifth vehicle has nowhere to go in a hangar that only ever shows four bays. The user's own instruction ruled out redesigning the visual for this case, so the fix is paging: the same four bays, a different four-entry slice of the roster.
func selector_page_count() -> int:
return maxi(1, ceili(float(selector_roster.size()) / 4.0))
func select_next_page() -> void:
if not selecting or selector_page_count() <= 1:
return
for step in selector_page_count():
var page := posmod(selector_page + 1 + step, selector_page_count())
for bay in 4:
var t := _bay_type(bay, page)
if t >= 0 and vehicle_stock[t] != 0:
selector_page = page
selection = bay
selection_changed.emit()
vehicle.sound_cue.emit("GClick")
returnMarked PORT-ONLY in the code (bound to Tab) -- the original never had a fifth vehicle to choose from, so there is no trace to follow here, the same honest labelling this project already uses for other port-only additions (quick_swap_enabled, RF_TEAM_COLOURS).
selector.json's sprites.pictures list has exactly four entries -- cel 2094 + type * 2 + team, one pair per original vehicle type. A mod's own new vehicle was never drawn by the original game at all, so there is no traced picture for it, full stop; no amount of data-driving the bay layout conjures art that was never rendered by RFIRE.BIN.
Vehicle definitions gained an optional selector.picture field ([tan_id, green_id]) so a mod can supply one, built for the original four from the same registry lookup selector.json's own table already uses:
picture_cel = 2094 + index * 2
picture = [registry[str(picture_cel)]["id"], registry[str(picture_cel + 1)]["id"]]
d["selector"]["picture"] = pictureselector_screen.gd reads a vehicle's own selector.picture first, falling back to the shared table only for a definition that doesn't set one:
var own_picture: Variant = mc.pack.vehicle_value(t, "selector.picture")
var ids: Array = own_picture if own_picture is Array else (pictures[t] if t < pictures.size() else [])
var has_picture := ids.size() >= 2A mod vehicle with neither still shows its selection box and pointer when chosen -- just no picture in the bay. That's a real, marked gap (there is genuinely no art to show), not a bug to chase further; giving a modder an easy way to supply one is editor work (EDITOR_PLAN.md 4, not yet built), not something this pass needed to solve.
tools/tests/selector_roster_check.gd: a mod adds a fifth vehicle to RFMAP001's roster -- the effective roster is [0, 1, 2, 3, 4], needs 2 pages, opens on page 0 exactly like the original always did, and select_next_page() lands on the new vehicle's own bay (the other three empty, no sixth/seventh/eighth vehicle to fill them); confirming it there creates that vehicle, not vehicle_type 0. A second mod removes the Heli from the roster -- three entries, one page, bay 3 (the Heli's own physical slot) sits empty, its stock reads 0, same as step 6 already made a removed vehicle behave everywhere else. The default roster's own behaviour was checked the direct way: a real screenshot of the hangar (RF_DEBUG_DOCK=1 RF_DEBUG_FIRE=1) came back pixel-identical to before -- Heli top-left, Tank top-right and selected, MSV bottom-left, Jeep bottom-right, panel reading "Tank 3 / 150" -- and the entire existing suite passed with no changes needed anywhere outside match_controller.gd and selector_screen.gd themselves.
Return Fire, rebuilt
Elsewhere