diff --git a/src/hexyz.lua b/src/hexyz.lua index 122e658..dc5539f 100644 --- a/src/hexyz.lua +++ b/src/hexyz.lua @@ -517,7 +517,7 @@ end -- function (from, to) -- from and to are vec2's -- return some numeric value -- -function hex_Astar(map, start, goal, heuristic, cost_f) +function hex_Astar(map, start, goal, cost_f, neighbour_f, heuristic) local path = {} hex_map_set(path, start, false) @@ -536,7 +536,7 @@ function hex_Astar(map, start, goal, heuristic, cost_f) break end - for _,next_ in pairs(map.neighbours(current.hex)) do + for _,next_ in pairs(neighbour_f(map, current.hex)) do local new_cost = hex_map_get(path_so_far, current.hex.x, current.hex.y) + cost_f(map, current.hex, next_) local next_cost = hex_map_get(path_so_far, next_.x, next_.y) diff --git a/src/mob.lua b/src/mob.lua index c41c3d3..76ddc0a 100644 --- a/src/mob.lua +++ b/src/mob.lua @@ -120,10 +120,6 @@ function make_mob_node(mob_type, mob) end end -function get_mob_path(mob, map, start, goal) - return Astar(map, goal, start, grid_heuristic, grid_cost) -end - local function get_spawn_hex() -- ensure we spawn on an random tile along the map's edges local roll = math.random(HEX_GRID_WIDTH * 2 + HEX_GRID_HEIGHT * 2) - 1 diff --git a/src/tower.lua b/src/tower.lua index cea96dd..769d5a5 100644 --- a/src/tower.lua +++ b/src/tower.lua @@ -441,7 +441,7 @@ function update_tower_lighthouse(tower, tower_index) -- is within some angle range...? if the mob is heading directly away from the tower, then -- the lighthouse shouldn't do much - local path, made_it = hex_Astar(state.map, tower.hex, m.hex, grid_heuristic, grid_cost) + local path, made_it = hex_Astar(state.map, tower.hex, m.hex, grid_neighbours, grid_cost, heuristic) if made_it then m.path = path