Revert world object refactors

This commit is contained in:
2026-06-27 23:22:45 -07:00
parent 6bdb096e1b
commit 2a99d7ecf3
11 changed files with 72 additions and 99 deletions
+16 -16
View File
@@ -88,8 +88,8 @@ tower_stats_at_level :: proc(tower: Tower) -> (damage: int, range: f32) {
can_place_tower :: proc(world: ^World, gx, gy: int, kind: Tower_Kind) -> bool {
if world.phase != .Build do return false
arch := get_archetype(kind)
if world.economy.gold < arch.cost do return false
if !footprint_fits_map(&world.world_map.current_map, gx, gy, arch.footprint_w, arch.footprint_h) do return false
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
return true
}
@@ -113,7 +113,7 @@ footprint_center :: proc(gx, gy, footprint_w, footprint_h: int) -> Vec2 {
}
}
footprint_fits_map :: proc(world_map: ^World_Map, gx, gy, footprint_w, footprint_h: int) -> bool {
footprint_fits_map :: proc(world_map: ^Map, gx, gy, footprint_w, footprint_h: int) -> bool {
if gx < 0 || gy < 0 do return false
if gx + footprint_w > MAP_W do return false
if gy + footprint_h > MAP_H do return false
@@ -130,7 +130,7 @@ footprint_fits_map :: proc(world_map: ^World_Map, gx, gy, footprint_w, footprint
}
footprint_blocked :: proc(world: ^World, gx, gy, footprint_w, footprint_h: int) -> bool {
for placed_tower in world.combat.towers {
for placed_tower in world.towers {
archetype := get_archetype(placed_tower.kind)
if rects_overlap(
gx,
@@ -162,9 +162,9 @@ try_upgrade_tower :: proc(world: ^World, gx, gy: int) -> bool {
if t.upgrade_level >= arch.max_upgrade do return false
cost := arch.upgrade_cost + t.upgrade_level * 25
if world.economy.gold < cost do return false
if world.gold < cost do return false
world.economy.gold -= cost
world.gold -= cost
t.upgrade_level += 1
return true
}
@@ -173,9 +173,9 @@ 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)
world.economy.gold -= arch.cost
world.gold -= arch.cost
append(
&world.combat.towers,
&world.towers,
Tower {
position = footprint_center(gx, gy, arch.footprint_w, arch.footprint_h),
anchor_gx = gx,
@@ -188,8 +188,8 @@ 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.combat.towers) {
t := &world.combat.towers[i]
for i in 0 ..< len(world.towers) {
t := &world.towers[i]
arch := get_archetype(t.kind)
if gx >= t.anchor_gx &&
gx < t.anchor_gx + arch.footprint_w &&
@@ -206,9 +206,9 @@ find_target_slot :: proc(tower: Tower, world: ^World) -> int {
best_dist: f32 = 999999
for i in 0 ..< MAX_ENEMIES {
e := &world.combat.enemies[i]
e := &world.enemies[i]
if !e.active do continue
if e.path_index >= len(world.world_map.path) do continue
if e.path_index >= len(world.path) do continue
d := distance(tower.position, e.position)
_, range := tower_stats_at_level(tower)
@@ -221,8 +221,8 @@ find_target_slot :: proc(tower: Tower, world: ^World) -> int {
}
update_towers :: proc(world: ^World, dt: f32) {
for i in 0 ..< len(world.combat.towers) {
t := &world.combat.towers[i]
for i in 0 ..< len(world.towers) {
t := &world.towers[i]
t.cooldown -= dt
if t.cooldown > 0 do continue
@@ -272,13 +272,13 @@ apply_ice_hit :: proc(world: ^World, target: ^Enemy, damage: int) {
enemy_at_slot :: proc(world: ^World, slot: int) -> ^Enemy {
if slot < 0 || slot >= MAX_ENEMIES do return nil
e := &world.combat.enemies[slot]
e := &world.enemies[slot]
if !e.active do return nil
return e
}
render_towers :: proc(world: ^World) {
for t in world.combat.towers {
for t in world.towers {
archetype := get_archetype(t.kind)
pixel_width := f32(archetype.footprint_w * TILE_SIZE)
pixel_height := f32(archetype.footprint_h * TILE_SIZE)