Error maxxing
This commit is contained in:
@@ -99,7 +99,7 @@ delete_entity :: proc(self: ^Simulator, entity_index: u32, type: common.Entity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns a random node that has no cars on it
|
// Returns a random node that has no cars on it
|
||||||
get_free_node :: proc(self: ^Simulator) -> u32 {
|
get_free_node :: proc(self: ^Simulator) -> Maybe(u32) {
|
||||||
car_occupied_nodes: [dynamic]u32
|
car_occupied_nodes: [dynamic]u32
|
||||||
|
|
||||||
for car in self.cars {
|
for car in self.cars {
|
||||||
@@ -110,6 +110,8 @@ get_free_node :: proc(self: ^Simulator) -> u32 {
|
|||||||
append(&car_occupied_nodes, node)
|
append(&car_occupied_nodes, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(car_occupied_nodes) == len(self.nodes) do return nil
|
||||||
|
|
||||||
for {
|
for {
|
||||||
node := rand.uint32_max(u32(len(self.nodes)))
|
node := rand.uint32_max(u32(len(self.nodes)))
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ handle_keyboard_input :: proc(self: ^Simulator) {
|
|||||||
|
|
||||||
if !rl.IsKeyReleased(.N) || len(self.nodes) == 0 do return
|
if !rl.IsKeyReleased(.N) || len(self.nodes) == 0 do return
|
||||||
|
|
||||||
car := v.car_init(u32(len(self.nodes)))
|
car := v.car_init(get_free_node(self), self.nodes[:])
|
||||||
append(&self.cars, car)
|
append(&self.cars, car)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ get_path_to_destination :: proc(self: ^Simulator, source: u32, destination: u32)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns if path is reachable from node => destination
|
// Returns if path is reachable from node => destination
|
||||||
get_destination_reachable :: proc(self: ^Simulator, node_to_search: u32, destination: u32, nodes_to_ignore: ^[]u32) -> bool {
|
get_destination_reachable :: proc(self: ^Simulator, node_to_search: u32, destination: u32, nodes_to_ignore: ^[dynamic]u32) -> bool {
|
||||||
if !self.nodes[node_to_search].enabled || common.list_contains(nodes_to_ignore[:], node_to_search) do return false
|
if !self.nodes[node_to_search].enabled || common.list_contains(nodes_to_ignore[:], node_to_search) do return false
|
||||||
append(nodes_to_ignore, node_to_search)
|
append(nodes_to_ignore, node_to_search)
|
||||||
|
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ Car :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
car_init :: proc(node: u32, nodes: []inf.Node) -> Car {
|
car_init :: proc(spawn_node: u32, nodes: []inf.Node) -> Car {
|
||||||
return {
|
return {
|
||||||
fuel_level = common.FUEL_MAX,
|
fuel_level = common.FUEL_MAX,
|
||||||
max_speed = common.CAR_MAX_SPEED,
|
max_speed = common.CAR_MAX_SPEED,
|
||||||
origin = node,
|
origin = spawn_node,
|
||||||
node_pos = node,
|
node_pos = spawn_node,
|
||||||
actual_pos = nodes[node].pos
|
actual_pos = nodes[spawn_node].pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user