Setting up groundwork for vehicle (car) and pathfinding implementation
This commit is contained in:
44
src/vehicles/car.odin
Normal file
44
src/vehicles/car.odin
Normal file
@@ -0,0 +1,44 @@
|
||||
package vehicles
|
||||
|
||||
import "core:math/rand"
|
||||
|
||||
import "../common"
|
||||
|
||||
Car :: struct {
|
||||
// Fuel level 0-100%
|
||||
fuel_level: u8,
|
||||
// Vehicle's maximum speed
|
||||
max_speed: u8,
|
||||
|
||||
// Pathfinding
|
||||
|
||||
// Car's origin node
|
||||
origin: u32,
|
||||
// Car's destination node
|
||||
destination: Maybe(u32),
|
||||
}
|
||||
|
||||
// Constructor
|
||||
car_init :: proc(nodes_len: u32) -> Car {
|
||||
return {
|
||||
fuel_level = common.FUEL_MAX,
|
||||
max_speed = common.CAR_MAX_SPEED,
|
||||
origin = rand.uint32_max(nodes_len)
|
||||
}
|
||||
}
|
||||
|
||||
// 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.origin == self.destination {
|
||||
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.origin == old_ref do self.origin = new_ref
|
||||
if self.destination == old_ref do self.destination = new_ref
|
||||
}
|
||||
Reference in New Issue
Block a user