A simple A* pathing function that works on maps, but I'll be changing it to do the GOAP pathing.

This commit is contained in:
Zed A. Shaw 2025-03-08 23:23:29 -05:00
parent 73b0600039
commit a34becdaeb
7 changed files with 133 additions and 10 deletions

13
lel.cpp
View file

@ -43,18 +43,14 @@ namespace lel {
for(auto& row : grid) {
size_t columns = row.size();
int cell_width = grid_w / columns;
dbc::check(cell_width > 0, "invalid cell width calc");
dbc::check(cell_height > 0, "invalid cell height calc");
for(auto& name : row) {
if(name == "_") continue;
auto& cell = cells.at(name);
int cell_width = grid_w / columns;
dbc::check(cell_width > 0, "invalid cell width calc");
dbc::check(cell_height > 0, "invalid cell height calc");
cell.x = grid_x + (cell.col * cell_width);
cell.y = grid_y + (cell.row * cell_height);
// ZED: getting a bit hairy but this should work
if(cell.percent) {
// when percent mode we have to take unset to 100%
@ -73,6 +69,9 @@ namespace lel {
dbc::check(cell.h > 0, fmt::format("invalid height cell {}", name));
dbc::check(cell.w > 0, fmt::format("invalid width cell {}", name));
cell.x = grid_x + (cell.col * cell_width);
cell.y = grid_y + (cell.row * cell_height);
// keep the midpoint since it is used a lot
cell.mid_x = std::midpoint(cell.x, cell.x + cell.w);
cell.mid_y = std::midpoint(cell.y, cell.y + cell.h);