Implemented valid route setting
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package vehicles
|
||||
|
||||
import "core:math/rand"
|
||||
import "core:fmt"
|
||||
import rl "vendor:raylib"
|
||||
import sc "core:strconv"
|
||||
|
||||
import "../common"
|
||||
import inf "../infrastructure"
|
||||
@@ -36,15 +37,21 @@ car_init :: proc(spawn_node: u32, nodes: []inf.Node) -> Car {
|
||||
}
|
||||
}
|
||||
|
||||
// Sets a (valid) route for the car
|
||||
//
|
||||
// Does NOT guarantee the route is reachable (TODO!)
|
||||
car_set_route :: proc(self: ^Car, nodes_len: u32) {
|
||||
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.pos.type == .Node && self.pos.ref == old_ref do self.pos.ref = new_ref
|
||||
if self.destination == old_ref do self.destination = new_ref
|
||||
}
|
||||
|
||||
// Prints car's route
|
||||
car_print_route :: proc(id: Maybe(u32) = nil, self: ^Car) {
|
||||
val, ok := self.destination.?
|
||||
destination := ok ? fmt.aprintf("N%d", val) : "/"
|
||||
source_type := self.pos.type == .Node ? 'N' : 'R'
|
||||
|
||||
car_id, ok_val := id.?
|
||||
buf: [100]u8
|
||||
id_str := ok_val ? sc.write_uint(buf[:], u64(car_id), 10) : "N/A"
|
||||
|
||||
fmt.printfln("ID=%s Source=%c%d, Destination=%s", id_str, source_type, self.pos.ref, destination)
|
||||
}
|
||||
Reference in New Issue
Block a user