implemented basic pathing checks/algorithms, implemented entities id display for easier debugging
57 lines
1.4 KiB
Odin
57 lines
1.4 KiB
Odin
package vehicles
|
|
|
|
import "core:fmt"
|
|
import rl "vendor:raylib"
|
|
import sc "core:strconv"
|
|
|
|
import "../common"
|
|
import inf "../infrastructure"
|
|
|
|
Car :: struct {
|
|
// Fuel level 0-100%
|
|
fuel_level: u8,
|
|
// Vehicle's maximum speed
|
|
max_speed: u8,
|
|
|
|
// Pathfinding
|
|
|
|
// Car's current node/road
|
|
pos: common.Car_Position,
|
|
// Car's destination node
|
|
destination: Maybe(uint),
|
|
|
|
// tracks absolute pos (within canvas)
|
|
absolute_pos: rl.Vector2,
|
|
}
|
|
|
|
// Constructor
|
|
car_init :: proc(spawn_node: uint, nodes: []inf.Node) -> Car {
|
|
return {
|
|
fuel_level = common.FUEL_MAX,
|
|
max_speed = common.CAR_MAX_SPEED,
|
|
pos = common.Car_Position {
|
|
type = .Node,
|
|
ref = spawn_node,
|
|
},
|
|
absolute_pos = nodes[spawn_node].pos
|
|
}
|
|
}
|
|
|
|
// Updates (origin and destination) node reference
|
|
car_update_node_reference :: proc(self: ^Car, old_ref: uint, new_ref: uint) {
|
|
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(uint) = 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)
|
|
} |