Implemented removal of cars if the node they're on gets removed

This commit is contained in:
2026-04-27 15:29:16 +02:00
parent 205c630dbf
commit da5c60d76b
5 changed files with 44 additions and 23 deletions

View File

@@ -14,18 +14,13 @@ Car :: struct {
// Pathfinding
// Car's origin node
origin: u32,
// Car's current node/road
pos: common.Car_Position,
// Car's destination node
destination: Maybe(u32),
// Tracks on which node car has been last
//
// 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,
// tracks absolute pos (within canvas)
absolute_pos: rl.Vector2,
}
// Constructor
@@ -33,9 +28,11 @@ car_init :: proc(spawn_node: u32, nodes: []inf.Node) -> Car {
return {
fuel_level = common.FUEL_MAX,
max_speed = common.CAR_MAX_SPEED,
origin = spawn_node,
node_pos = spawn_node,
actual_pos = nodes[spawn_node].pos
pos = common.Car_Position {
type = .Node,
ref = spawn_node,
},
absolute_pos = nodes[spawn_node].pos
}
}
@@ -43,11 +40,11 @@ car_init :: proc(spawn_node: u32, nodes: []inf.Node) -> Car {
//
// Does NOT guarantee the route is reachable (TODO!)
car_set_route :: proc(self: ^Car, nodes_len: u32) {
for self.origin == self.destination do self.destination = rand.uint32_max(nodes_len)
for self.pos.type == .Node && self.pos.ref == self.destination do self.destination = rand.uint32_max(nodes_len)
}
// Updates (origin and destination) node reference
car_update_node_reference :: proc(self: ^Car, old_ref: u32, new_ref: u32) {
if self.origin == old_ref do self.origin = new_ref
if self.pos.type == .Node && self.pos.ref == old_ref do self.pos.ref = new_ref
if self.destination == old_ref do self.destination = new_ref
}