Pathfinding initial implementation [2 errors]

This commit is contained in:
2026-04-27 09:42:50 +02:00
parent 697183f961
commit 620d3b56e0
5 changed files with 84 additions and 23 deletions

View File

@@ -19,32 +19,31 @@ Car :: struct {
// Car's destination node
destination: Maybe(u32),
// Tracks on which node car has been last
node_pos: u32,
//
// if null car is not on node
node_pos: Maybe(u32),
// if null car is not on road
road_pos: Maybe(u32),
// tracks absolute pos
actual_pos: rl.Vector2,
}
// Constructor
car_init :: proc(nodes: []inf.Node) -> Car {
rand_origin := rand.uint32_max(nodes_len)
car_init :: proc(node: u32, nodes: []inf.Node) -> Car {
return {
fuel_level = common.FUEL_MAX,
max_speed = common.CAR_MAX_SPEED,
origin = rand_origin,
node_pos = rand_origin,
actual_pos =
origin = node,
node_pos = node,
actual_pos = nodes[node].pos
}
}
// Sets a (valid) route for the car
//
// Does NOT guarantee the route is reachable (TODO?)
// Does NOT guarantee the route is reachable (TODO!)
car_set_route :: proc(self: ^Car, nodes_len: u32) {
for self.origin == self.destination {
self.destination = rand.uint32_max(nodes_len)
}
for self.origin == self.destination do self.destination = rand.uint32_max(nodes_len)
}
// Updates (origin and destination) node reference