Setting up groundwork for vehicle (car) and pathfinding implementation

This commit is contained in:
2026-04-26 16:53:46 +02:00
parent ae5e68e2a5
commit 533b6b1c00
8 changed files with 131 additions and 24 deletions

44
src/vehicles/car.odin Normal file
View 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
}