Pathfinding initial implementation [2 errors]
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import rl "vendor:raylib"
|
||||
import "core:math/rand"
|
||||
|
||||
import "common"
|
||||
import inf "infrastructure"
|
||||
@@ -99,5 +100,19 @@ delete_entity :: proc(self: ^Simulator, entity_index: u32, type: common.Entity)
|
||||
|
||||
// Returns a random node that has no cars on it
|
||||
get_free_node :: proc(self: ^Simulator) -> u32 {
|
||||
car_occupied_nodes: [dynamic]u32
|
||||
|
||||
for car in self.cars {
|
||||
node, ok := car.node_pos.?
|
||||
if !ok do continue
|
||||
|
||||
if common.list_contains(car_occupied_nodes[:], node) do continue
|
||||
append(&car_occupied_nodes, node)
|
||||
}
|
||||
|
||||
for {
|
||||
node := rand.uint32_max(u32(len(self.nodes)))
|
||||
|
||||
if !common.list_contains(car_occupied_nodes[:], node) do return node
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user