Refactor world gold and combat

This commit is contained in:
2026-06-26 20:41:39 -07:00
parent e75dd82a76
commit 4d9c52c56a
7 changed files with 45 additions and 34 deletions
+13 -13
View File
@@ -88,7 +88,7 @@ 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.gold < arch.cost do return false
if world.economy.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
@@ -130,7 +130,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 {
for placed_tower in world.combat.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.gold < cost do return false
if world.economy.gold < cost do return false
world.gold -= cost
world.economy.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.gold -= arch.cost
world.economy.gold -= arch.cost
append(
&world.towers,
&world.combat.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.towers) {
t := &world.towers[i]
for i in 0 ..< len(world.combat.towers) {
t := &world.combat.towers[i]
arch := get_archetype(t.kind)
if gx >= t.anchor_gx &&
gx < t.anchor_gx + arch.footprint_w &&
@@ -206,7 +206,7 @@ find_target_slot :: proc(tower: Tower, world: ^World) -> int {
best_dist: f32 = 999999
for i in 0 ..< MAX_ENEMIES {
e := &world.enemies[i]
e := &world.combat.enemies[i]
if !e.active do continue
if e.path_index >= len(world.path) do continue
@@ -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.towers) {
t := &world.towers[i]
for i in 0 ..< len(world.combat.towers) {
t := &world.combat.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.enemies[slot]
e := &world.combat.enemies[slot]
if !e.active do return nil
return e
}
render_towers :: proc(world: ^World) {
for t in world.towers {
for t in world.combat.towers {
archetype := get_archetype(t.kind)
pixel_width := f32(archetype.footprint_w * TILE_SIZE)
pixel_height := f32(archetype.footprint_h * TILE_SIZE)