Files @ r1891:c5c5466afa35
Branch filter:

Location: cpp/openttd-patchpack/source/engine.h - annotation

Darkvater
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r405:af2e0e5f1331
r405:af2e0e5f1331
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r922:c6224817ada1
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r1786:f4dff9cc496a
r0:d63b455452f6
r0:d63b455452f6
r1786:f4dff9cc496a
r819:e1432f9501d6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r0:d63b455452f6
r1093:18f56ef2d029
r1093:18f56ef2d029
r0:d63b455452f6
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r0:d63b455452f6
r0:d63b455452f6
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1883:9315515934d3
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r1802:acc0f0bda113
r0:d63b455452f6
r1802:acc0f0bda113
r1802:acc0f0bda113
r369:ebd9677c1a5a
r369:ebd9677c1a5a
r0:d63b455452f6
r1475:89b98bad154a
r1883:9315515934d3
r414:3caabc7691a6
r414:3caabc7691a6
r0:d63b455452f6
r1477:d0fe35adb3c4
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r445:8bbc3f73289f
r1477:d0fe35adb3c4
r1477:d0fe35adb3c4
r445:8bbc3f73289f
r1329:88de95f6e7d3
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r1786:f4dff9cc496a
r0:d63b455452f6
r1093:18f56ef2d029
r1093:18f56ef2d029
r0:d63b455452f6
r1197:5c12672cee22
r1474:03cff91e43a0
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r376:4e13dd244445
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r0:d63b455452f6
r0:d63b455452f6
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r1786:f4dff9cc496a
r376:4e13dd244445
r376:4e13dd244445
r0:d63b455452f6
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r376:4e13dd244445
r538:c4b9f109ad6c
r539:6383330746de
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r538:c4b9f109ad6c
r405:af2e0e5f1331
r0:d63b455452f6
#ifndef ENGINE_H
#define ENGINE_H

#include "sprite.h"

typedef struct RailVehicleInfo {
	byte image_index;
	byte flags; /* 1=multihead engine, 2=wagon */
	byte base_cost;
	uint16 max_speed;
	uint16 power;
	byte weight;
	byte running_cost_base;
	byte engclass; // 0: steam, 1: diesel, 2: electric
	byte capacity;
	byte cargo_type;
} RailVehicleInfo;

typedef struct ShipVehicleInfo {
	byte image_index;
	byte base_cost;
	uint16 max_speed;
	byte cargo_type;
	uint16 capacity;
	byte running_cost;
	byte sfx;
	byte refittable;
} ShipVehicleInfo;

typedef struct AircraftVehicleInfo {
	byte image_index;
	byte base_cost;
	byte running_cost;
	byte subtype;
	byte sfx;
	byte acceleration;
	byte max_speed;
	byte mail_capacity;
	uint16 passenger_capacity;
} AircraftVehicleInfo;

typedef struct RoadVehicleInfo {
	byte image_index;
	byte base_cost;
	byte running_cost;
	byte sfx;
	byte max_speed;
	byte capacity;
	byte cargo_type;
} RoadVehicleInfo;

typedef struct EngineInfo {
	uint16 base_intro;
	byte unk2;
	byte lifelength;
	byte base_life;
	byte railtype_climates;
} EngineInfo;

typedef struct Engine {
	uint16 intro_date;
	uint16 age;
	uint16 reliability;
	uint16 reliability_spd_dec;
	uint16 reliability_start, reliability_max, reliability_final;
	uint16 duration_phase_1, duration_phase_2, duration_phase_3;
	byte lifelength;
	byte flags;
	PlayerID preview_player;
	byte preview_wait;
	byte railtype;
	PlayerID player_avail;
	byte type;				// type, ie VEH_Road, VEH_Train, etc. Same as in vehicle.h
} Engine;


enum {
	RVI_MULTIHEAD = 1,
	RVI_WAGON = 2,
};

enum {
	NUM_VEHICLE_TYPES = 6
};

void AddTypeToEngines(void);
void StartupEngines(void);

enum GlobalCargo {
	GC_PASSENGERS   =   0,
	GC_COAL         =   1,
	GC_MAIL         =   2,
	GC_OIL          =   3,
	GC_LIVESTOCK    =   4,
	GC_GOODS        =   5,
	GC_GRAIN        =   6, // GC_WHEAT / GC_MAIZE
	GC_WOOD         =   7,
	GC_IRON_ORE     =   8,
	GC_STEEL        =   9,
	GC_VALUABLES    =  10, // GC_GOLD / GC_DIAMONDS
	GC_PAPER        =  11,
	GC_FOOD         =  12,
	GC_FRUIT        =  13,
	GC_COPPER_ORE   =  14,
	GC_WATER        =  15,
	GC_RUBBER       =  16,
	GC_SUGAR        =  17,
	GC_TOYS         =  18,
	GC_BATTERIES    =  19,
	GC_CANDY        =  20,
	GC_TOFFEE       =  21,
	GC_COLA         =  22,
	GC_COTTON_CANDY =  23,
	GC_BUBBLES      =  24,
	GC_PLASTIC      =  25,
	GC_FIZZY_DRINKS =  26,
	GC_PAPER_TEMP   =  27,
	GC_UNDEFINED    =  28, // undefined; unused slot in arctic climate
	GC_DEFAULT      =  29,
	GC_PURCHASE     =  30,
	GC_INVALID      = 255,
	NUM_GLOBAL_CID  =  31
};

// This enum only lists implemented callbacks
enum CallbackID {
	// Refit capacity, the passed vehicle needs to have its ->cargo_type set to
	// the cargo we are refitting to, returns the new cargo capacity
	CB_REFIT_CAP = 0x15,
};

enum {
	CALLBACK_FAILED = 0xFFFF
};

VARDEF const uint32 _default_refitmasks[NUM_VEHICLE_TYPES];
VARDEF const CargoID _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO];
VARDEF const uint32 _landscape_global_cargo_mask[NUM_LANDSCAPE];
VARDEF const CargoID _local_cargo_id_ctype[NUM_GLOBAL_CID];

VARDEF uint32 _engine_refit_masks[256];
VARDEF byte _engine_original_sprites[256];
void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group, byte *train_id, int trains);
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group);
// loaded is in percents, overriding_engine 0xffff is none
int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction);
uint16 GetCallBackResult(uint16 callback_info, byte engine, const Vehicle *v);
#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)

typedef enum VehicleTrigger {
	VEHICLE_TRIGGER_NEW_CARGO = 1,
	// Externally triggered only for the first vehicle in chain
	VEHICLE_TRIGGER_DEPOT = 2,
	// Externally triggered only for the first vehicle in chain, only if whole chain is empty
	VEHICLE_TRIGGER_EMPTY = 4,
	// Not triggered externally (called for the whole chain if we got NEW_CARGO)
	VEHICLE_TRIGGER_ANY_NEW_CARGO = 8,
} VehicleTrigger;
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);

void SetCustomEngineName(int engine, const char *name);
StringID GetCustomEngineName(int engine);


void DrawTrainEngine(int x, int y, int engine, uint32 image_ormod);
void DrawRoadVehEngine(int x, int y, int engine, uint32 image_ormod);
void DrawShipEngine(int x, int y, int engine, uint32 image_ormod);
void DrawAircraftEngine(int x, int y, int engine, uint32 image_ormod);

void DrawTrainEngineInfo(int engine, int x, int y, int maxw);
void DrawRoadVehEngineInfo(int engine, int x, int y, int maxw);
void DrawShipEngineInfo(int engine, int x, int y, int maxw);
void DrawAircraftEngineInfo(int engine, int x, int y, int maxw);

void AcceptEnginePreview(Engine *e, PlayerID player);

void LoadCustomEngineNames(void);
void DeleteCustomEngineNames(void);

bool IsEngineBuildable(uint engine, byte type);
void UnInitNewgrEngines(void);

enum {
	NUM_NORMAL_RAIL_ENGINES = 54,
	NUM_MONORAIL_ENGINES = 30,
	NUM_MAGLEV_ENGINES = 32,
	NUM_TRAIN_ENGINES = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES,
	NUM_ROAD_ENGINES = 88,
	NUM_SHIP_ENGINES = 11,
	NUM_AIRCRAFT_ENGINES = 41,
	TOTAL_NUM_ENGINES = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
	AIRCRAFT_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES,
	SHIP_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
	ROAD_ENGINES_INDEX = NUM_TRAIN_ENGINES,
};
VARDEF Engine _engines[TOTAL_NUM_ENGINES];
#define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
#define DEREF_ENGINE(i) (GetEngine(i))
static inline Engine* GetEngine(uint i)
{
  assert(i < lengthof(_engines));
  return &_engines[i];
}

VARDEF StringID _engine_name_strings[TOTAL_NUM_ENGINES];

static inline bool IsEngineIndex(uint index)
{
	return index < TOTAL_NUM_ENGINES;
}

/* Access Vehicle Data */
//#include "table/engines.h"
extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
extern RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];

static inline RailVehicleInfo *RailVehInfo(uint e)
{
	assert(e < lengthof(_rail_vehicle_info));
	return &_rail_vehicle_info[e];
}

static inline ShipVehicleInfo *ShipVehInfo(uint e)
{
	assert(e - SHIP_ENGINES_INDEX < lengthof(_ship_vehicle_info));
	return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX];
}

static inline AircraftVehicleInfo *AircraftVehInfo(uint e)
{
	assert(e - AIRCRAFT_ENGINES_INDEX < lengthof(_aircraft_vehicle_info));
	return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX];
}

static inline RoadVehicleInfo *RoadVehInfo(uint e)
{
	assert(e - ROAD_ENGINES_INDEX < lengthof(_road_vehicle_info));
	return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
}

#endif