vehicle.h
changeset 555 02df8a1b7f33
parent 445 beafc0fb8f12
child 567 e63b977925f7
equal deleted inserted replaced
554:a4ba0fbbf018 555:02df8a1b7f33
     1 #ifndef VEHICLE_H
     1 #ifndef VEHICLE_H
     2 #define VEHICLE_H
     2 #define VEHICLE_H
     3 
     3 
     4 #include "vehicle_gui.h"
     4 #include "vehicle_gui.h"
       
     5 
       
     6 typedef struct Order {
       
     7 	uint8 type:4;
       
     8 	uint8 flags:4;
       
     9 	uint8 station;
       
    10 } Order;
       
    11 
       
    12 static inline uint16 PackOrder(const Order *order)
       
    13 {
       
    14 	return order->station << 8 | order->flags << 4 | order->type;
       
    15 }
       
    16 
       
    17 static inline Order UnpackOrder(uint16 packed)
       
    18 {
       
    19 	Order order = {
       
    20 		(packed & 0x000f),
       
    21 		(packed & 0x00f0) >> 4,
       
    22 		(packed & 0xff00) >> 8
       
    23 	};
       
    24 	return order;
       
    25 }
     5 
    26 
     6 typedef struct VehicleRail {
    27 typedef struct VehicleRail {
     7 	uint16 last_speed;		// NOSAVE: only used in UI
    28 	uint16 last_speed;		// NOSAVE: only used in UI
     8 	uint16 crash_anim_pos;
    29 	uint16 crash_anim_pos;
     9 	uint16 days_since_order_progr;
    30 	uint16 days_since_order_progr;
   143 	byte tick_counter;// increased by one for each tick
   164 	byte tick_counter;// increased by one for each tick
   144 
   165 
   145 	// related to the current order
   166 	// related to the current order
   146 	byte cur_order_index;
   167 	byte cur_order_index;
   147 	byte num_orders;
   168 	byte num_orders;
   148 	byte next_order;
   169 	Order current_order;
   149 	byte next_order_param;
   170 	Order *schedule_ptr;
   150 	uint16 *schedule_ptr;
       
   151 
   171 
   152 	// Boundaries for the current position in the world and a next hash link.
   172 	// Boundaries for the current position in the world and a next hash link.
   153 	// NOSAVE: All of those can be updated with VehiclePositionChanged()
   173 	// NOSAVE: All of those can be updated with VehiclePositionChanged()
   154 	int16 left_coord, top_coord, right_coord, bottom_coord;
   174 	int16 left_coord, top_coord, right_coord, bottom_coord;
   155 	uint16 next_hash;
   175 	uint16 next_hash;
   218 	OT_GOTO_DEPOT = 2,
   238 	OT_GOTO_DEPOT = 2,
   219 	OT_LOADING = 3,
   239 	OT_LOADING = 3,
   220 	OT_LEAVESTATION = 4,
   240 	OT_LEAVESTATION = 4,
   221 	OT_DUMMY = 5,
   241 	OT_DUMMY = 5,
   222 	OT_GOTO_WAYPOINT = 6,
   242 	OT_GOTO_WAYPOINT = 6,
   223 
       
   224 	OT_MASK = 0x1F,
       
   225 };
   243 };
   226 
   244 
   227 /* Order flags */
   245 /* Order flags */
   228 enum {
   246 enum {
   229 	OF_UNLOAD = 0x20,
   247 	OF_UNLOAD    = 0x2,
   230 	OF_FULL_LOAD = 0x40, // Also used when to force an aircraft into a depot.
   248 	OF_FULL_LOAD = 0x4, // Also used when to force an aircraft into a depot
   231 	OF_NON_STOP = 0x80,
   249 	OF_NON_STOP  = 0x8
   232 	OF_MASK = 0xE0,
       
   233 };
   250 };
   234 
   251 
   235 
   252 
   236 enum VehStatus {
   253 enum VehStatus {
   237 	VS_HIDDEN = 1,
   254 	VS_HIDDEN = 1,
   267 
   284 
   268 typedef void VehicleTickProc(Vehicle *v);
   285 typedef void VehicleTickProc(Vehicle *v);
   269 typedef void *VehicleFromPosProc(Vehicle *v, void *data);
   286 typedef void *VehicleFromPosProc(Vehicle *v, void *data);
   270 
   287 
   271 typedef struct {
   288 typedef struct {
       
   289 	VehicleID clone;
   272 	byte orderindex;
   290 	byte orderindex;
   273 	uint16 order[41];
   291 	Order order[41];
   274 	uint16 service_interval;
   292 	uint16 service_interval;
   275 	char name[32];
   293 	char name[32];
   276 } BackuppedOrders;
   294 } BackuppedOrders;
   277 
   295 
   278 void BackupVehicleOrders(Vehicle *v, BackuppedOrders *order);
   296 void BackupVehicleOrders(Vehicle *v, BackuppedOrders *order);
   335 void DecreaseVehicleValue(Vehicle *v);
   353 void DecreaseVehicleValue(Vehicle *v);
   336 void CheckVehicleBreakdown(Vehicle *v);
   354 void CheckVehicleBreakdown(Vehicle *v);
   337 void AgeVehicle(Vehicle *v);
   355 void AgeVehicle(Vehicle *v);
   338 void MaybeRenewVehicle(Vehicle *v, int32 build_cost);
   356 void MaybeRenewVehicle(Vehicle *v, int32 build_cost);
   339 
   357 
   340 void DeleteCommandFromVehicleSchedule(uint cmd);
   358 void DeleteCommandFromVehicleSchedule(Order cmd);
   341 
   359 
   342 void BeginVehicleMove(Vehicle *v);
   360 void BeginVehicleMove(Vehicle *v);
   343 void EndVehicleMove(Vehicle *v);
   361 void EndVehicleMove(Vehicle *v);
   344 
   362 
   345 bool IsAircraftHangarTile(TileIndex tile);
   363 bool IsAircraftHangarTile(TileIndex tile);
   359 void UpdateTrainAcceleration(Vehicle *v);
   377 void UpdateTrainAcceleration(Vehicle *v);
   360 int32 GetTrainRunningCost(Vehicle *v);
   378 int32 GetTrainRunningCost(Vehicle *v);
   361 
   379 
   362 int CheckStoppedInDepot(Vehicle *v);
   380 int CheckStoppedInDepot(Vehicle *v);
   363 
   381 
   364 int ScheduleHasDepotOrders(uint16 *schedule);
   382 int ScheduleHasDepotOrders(const Order *schedule);
   365 int CheckOrders(Vehicle *v);
   383 int CheckOrders(Vehicle *v);
   366 
   384 
   367 typedef struct GetNewVehiclePosResult {
   385 typedef struct GetNewVehiclePosResult {
   368 	int x,y;
   386 	int x,y;
   369 	uint old_tile;
   387 	uint old_tile;
   387 	NUM_VEHICLES = NUM_NORMAL_VEHICLES + NUM_SPECIAL_VEHICLES
   405 	NUM_VEHICLES = NUM_NORMAL_VEHICLES + NUM_SPECIAL_VEHICLES
   388 };
   406 };
   389 
   407 
   390 VARDEF Vehicle _vehicles[NUM_VEHICLES];
   408 VARDEF Vehicle _vehicles[NUM_VEHICLES];
   391 
   409 
   392 VARDEF uint16 _order_array[5000];
   410 VARDEF Order _order_array[5000];
   393 VARDEF uint16 *_ptr_to_next_order;
   411 VARDEF Order *_ptr_to_next_order;
   394 
   412 
   395 VARDEF Depot _depots[255];
   413 VARDEF Depot _depots[255];
   396 
   414 
   397 // 128 waypoints
   415 // 128 waypoints
   398 VARDEF Waypoint _waypoints[128];
   416 VARDEF Waypoint _waypoints[128];