clean up get_archtype for towers and build_controls_layout function, replacing with constants

This commit is contained in:
2026-06-28 00:42:53 -07:00
parent 3026aeadc2
commit d29b4f07ea
3 changed files with 35 additions and 39 deletions
+6 -6
View File
@@ -4,7 +4,7 @@ import rl "vendor:raylib"
can_place_tower :: proc(world: ^World, gx, gy: int, kind: Tower_Kind) -> bool {
if world.phase != .Build do return false
arch := get_archetype(kind)
arch := TOWER_ARCHETYPES[kind]
if world.gold < arch.cost do return false
if !footprint_fits_map(&world.world_map, gx, gy, arch.footprint_w, arch.footprint_h) do return false
if footprint_blocked(world, gx, gy, arch.footprint_w, arch.footprint_h) do return false
@@ -48,7 +48,7 @@ footprint_fits_map :: proc(world_map: ^Map, gx, gy, footprint_w, footprint_h: in
footprint_blocked :: proc(world: ^World, gx, gy, footprint_w, footprint_h: int) -> bool {
for placed_tower in world.towers {
archetype := get_archetype(placed_tower.kind)
archetype := TOWER_ARCHETYPES[placed_tower.kind]
if rects_overlap(
gx,
gy,
@@ -69,7 +69,7 @@ footprint_blocked :: proc(world: ^World, gx, gy, footprint_w, footprint_h: int)
try_place_tower :: proc(world: ^World, gx, gy: int, kind: Tower_Kind) -> bool {
if !can_place_tower(world, gx, gy, kind) do return false
arch := get_archetype(kind)
arch := TOWER_ARCHETYPES[kind]
world.gold -= arch.cost
append(
&world.towers,
@@ -87,7 +87,7 @@ try_place_tower :: proc(world: ^World, gx, gy: int, kind: Tower_Kind) -> bool {
tower_at_grid :: proc(world: ^World, gx, gy: int) -> ^Tower {
for i in 0 ..< len(world.towers) {
t := &world.towers[i]
arch := get_archetype(t.kind)
arch := TOWER_ARCHETYPES[t.kind]
if gx >= t.anchor_gx &&
gx < t.anchor_gx + arch.footprint_w &&
gy >= t.anchor_gy &&
@@ -103,7 +103,7 @@ try_upgrade_tower :: proc(world: ^World, gx, gy: int) -> bool {
t := tower_at_grid(world, gx, gy)
if t == nil do return false
arch := get_archetype(t.kind)
arch := TOWER_ARCHETYPES[t.kind]
if t.upgrade_level >= arch.max_upgrade do return false
cost := arch.upgrade_cost + t.upgrade_level * 25
@@ -119,7 +119,7 @@ render_placement_preview :: proc(world: ^World) {
mouse := game_mouse()
gx, gy := screen_to_grid(mouse.x, mouse.y)
arch := get_archetype(world.selected_tower)
arch := TOWER_ARCHETYPES[world.selected_tower]
ok := can_place_tower(world, gx, gy, world.selected_tower)
center := footprint_center(gx, gy, arch.footprint_w, arch.footprint_h)