diff options
author | peter1138 <peter1138@openttd.org> | 2005-09-26 18:43:58 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2005-09-26 18:43:58 +0000 |
commit | 2314431a596c25b7e48cfbc7dda452c66cd5ca32 (patch) | |
tree | 97e69b85dba3e191ef56496b77c23e2cececc839 | |
parent | c76f01b6ff9221dd2ebdfc09031c9707d5404ce5 (diff) | |
download | openttd-2314431a596c25b7e48cfbc7dda452c66cd5ca32.tar.xz |
(svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
-rw-r--r-- | engine.h | 26 | ||||
-rw-r--r-- | newgrf.c | 16 | ||||
-rw-r--r-- | table/engines.h | 10 | ||||
-rw-r--r-- | train_cmd.c | 2 |
4 files changed, 38 insertions, 16 deletions
@@ -241,31 +241,37 @@ static inline bool IsEngineIndex(uint index) /* 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) +extern const EngineInfo orig_engine_info[TOTAL_NUM_ENGINES]; +extern const RailVehicleInfo orig_rail_vehicle_info[NUM_TRAIN_ENGINES]; +extern const ShipVehicleInfo orig_ship_vehicle_info[NUM_SHIP_ENGINES]; +extern const AircraftVehicleInfo orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES]; +extern const RoadVehicleInfo orig_road_vehicle_info[NUM_ROAD_ENGINES]; + +EngineInfo _engine_info[TOTAL_NUM_ENGINES]; +RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES]; +ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES]; +AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES]; +RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES]; + +static inline const RailVehicleInfo *RailVehInfo(uint e) { assert(e < lengthof(_rail_vehicle_info)); return &_rail_vehicle_info[e]; } -static inline ShipVehicleInfo *ShipVehInfo(uint e) +static inline const 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) +static inline const 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) +static inline const RoadVehicleInfo *RoadVehInfo(uint e) { assert(e - ROAD_ENGINES_INDEX < lengthof(_road_vehicle_info)); return &_road_vehicle_info[e - ROAD_ENGINES_INDEX]; @@ -2191,6 +2191,20 @@ static void InitializeGRFSpecial(void) | (_patches.wagon_speed_limits ? (1 << 0x1D) : 0); /* wagonspeedlimits */ } +/** + * Reset all NewGRF loaded data + * TODO + */ +static void ResetNewGRFData(void) +{ + // Copy/reset original engine info data + memcpy(&_engine_info, &orig_engine_info, sizeof(orig_engine_info)); + memcpy(&_rail_vehicle_info, &orig_rail_vehicle_info, sizeof(orig_rail_vehicle_info)); + memcpy(&_ship_vehicle_info, &orig_ship_vehicle_info, sizeof(orig_ship_vehicle_info)); + memcpy(&_aircraft_vehicle_info, &orig_aircraft_vehicle_info, sizeof(orig_aircraft_vehicle_info)); + memcpy(&_road_vehicle_info, &orig_road_vehicle_info, sizeof(orig_road_vehicle_info)); +} + static void InitNewGRFFile(const char* filename, int sprite_offset) { GRFFile *newfile; @@ -2374,6 +2388,8 @@ void LoadNewGRF(uint load_index, uint file_index) initialized = true; } + ResetNewGRFData(); + /* Load newgrf sprites * in each loading stage, (try to) open each file specified in the config * and load information from it. */ diff --git a/table/engines.h b/table/engines.h index a1eeada08..b8e245e4d 100644 --- a/table/engines.h +++ b/table/engines.h @@ -25,7 +25,7 @@ */ #define MW(a,b,c,d,e,f) {a,b|0x80,c,d,((e)<<4)|(f)} -EngineInfo _engine_info[TOTAL_NUM_ENGINES] = { +const EngineInfo orig_engine_info[TOTAL_NUM_ENGINES] = { MK( 1827, 20, 15, 30, 0, 1), /* 0 Kirby Paul Tank (Steam) */ MK( 12784, 20, 22, 30, 0, 6), /* 1 MJS 250 (Diesel) */ MK( 9497, 20, 20, 50, 0, 8), /* 2 Ploddyphut Choo-Choo */ @@ -284,7 +284,7 @@ EngineInfo _engine_info[TOTAL_NUM_ENGINES] = { MK( 13575, 20, 20, 99, 0, 8), /* 255 */ }; -RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES] = { +const RailVehicleInfo orig_rail_vehicle_info[NUM_TRAIN_ENGINES] = { // image_index max_speed (kph) running_cost_base callbackmask shortened factor // | flags | power (hp) | running_cost_class | powered wagons power // | | base_cost | weight | capacity | | powered wagons weight @@ -408,7 +408,7 @@ RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES] = { { 59, 2, 191, 0, 0, 18, 0, 0, 37, CT_PLASTIC , 0, 0, 0, 0, 0 }, /* 115 */ }; -ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES] = { +const ShipVehicleInfo orig_ship_vehicle_info[NUM_SHIP_ENGINES] = { // image_index cargo_type cargo_amount refittable // | base_cost | | running_cost | // | | max_speed | | sfx | @@ -428,7 +428,7 @@ ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES] = { /* subtype: &1: regular aircraft (else chopper); &2: crashes easily on small airports */ /* sfx from somewhere around SND_45_PLANE_CRASHING are toyland plane-sounds */ -AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES] = { +const AircraftVehicleInfo orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES] = { // image_index sfx acceleration // | base_cost | | max_speed // | | running_cost | | mail_capacity @@ -479,7 +479,7 @@ AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES] = { /* I hope I got the cargo types right, figuring out which is which for which * climate is a bitch */ -RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES] = { +const RoadVehicleInfo orig_road_vehicle_info[NUM_ROAD_ENGINES] = { // image_index sfx max_speed // | base_cost | | capacity // | | running_cost | | cargo_type diff --git a/train_cmd.c b/train_cmd.c index e5b3f2b1b..c863115f6 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -1516,7 +1516,7 @@ int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (!CanRefitTo(v, new_cid)) continue; if (v->cargo_cap != 0) { - RailVehicleInfo *rvi = RailVehInfo(v->engine_type); + const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); uint16 amount = CALLBACK_FAILED; if (HASBIT(rvi->callbackmask, CBM_REFIT_CAP)) { |