Implementation of car removal when infrastructure where car is located gets removed itself
This commit is contained in:
@@ -189,15 +189,25 @@ pub const Simulator = struct {
|
||||
const start_node = h_road.nodes[0];
|
||||
const end_node = h_road.nodes[1];
|
||||
|
||||
self.road_man.deleteRoad(self.allocator, h_road) catch |err| {
|
||||
std.debug.panic("Road deletion failed: {}\n", .{err});
|
||||
};
|
||||
try self.road_man.deleteRoad(self.allocator, h_road);
|
||||
|
||||
if (start_node.roads.items.len == 0)
|
||||
try self.node_man.deleteNode(self.allocator, start_node);
|
||||
if (start_node.roads.items.len == 0) {
|
||||
const cars = try self.car_man.getCarsOnInf(self.allocator, .{ .node = start_node });
|
||||
defer self.allocator.free(cars);
|
||||
|
||||
if (end_node.roads.items.len == 0)
|
||||
try self.node_man.deleteNode(self.allocator, end_node);
|
||||
// TODO replace with removeMultipleCars
|
||||
for (self.car_man.cars.items) |car| {
|
||||
try self.car_man.removeCar(self.allocator, car);
|
||||
}
|
||||
|
||||
try self.node_man.removeNode(self.allocator, start_node);
|
||||
}
|
||||
|
||||
if (end_node.roads.items.len == 0) {
|
||||
// TODO same as above
|
||||
try self.node_man.removeNode(self.allocator, end_node);
|
||||
// TODO after this is done, do the same with the function that removes roads
|
||||
}
|
||||
}
|
||||
|
||||
/// Clearing node and road lists without deinitialising them (only the children)
|
||||
|
||||
Reference in New Issue
Block a user