diff options
author | rubidium <rubidium@openttd.org> | 2010-08-10 15:54:53 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-08-10 15:54:53 +0000 |
commit | 29b489a055e12033b006410d5e67a493c64ccfe2 (patch) | |
tree | a0e8bee3d26a69341484ffe0461819e98fe1bf6f | |
parent | 3d21fb44aae10d627cf24c7e42485c8f3a33ed42 (diff) | |
download | openttd-29b489a055e12033b006410d5e67a493c64ccfe2.tar.xz |
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
-rw-r--r-- | src/aircraft_cmd.cpp | 2 | ||||
-rw-r--r-- | src/engine.cpp | 6 | ||||
-rw-r--r-- | src/engine_base.h | 11 | ||||
-rw-r--r-- | src/newgrf.cpp | 12 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 34 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 2 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 2 | ||||
-rw-r--r-- | src/table/newgrf_debug_data.h | 2 | ||||
-rw-r--r-- | src/train_cmd.cpp | 16 | ||||
-rw-r--r-- | src/vehicle.cpp | 2 | ||||
-rw-r--r-- | src/vehicle_cmd.cpp | 2 |
11 files changed, 48 insertions, 43 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 6ca9f1ddd..7ec87742f 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -540,7 +540,7 @@ Money Aircraft::GetRunningCost() const { const Engine *e = Engine::Get(this->engine_type); uint cost_factor = GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, e->u.air.running_cost); - return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->grffile); + return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->grf_prop.grffile); } void Aircraft::OnNewDay() diff --git a/src/engine.cpp b/src/engine.cpp index 7809af616..e03d81cbf 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -74,7 +74,7 @@ Engine::Engine() : Engine::Engine(VehicleType type, EngineID base) { this->type = type; - this->internal_id = base; + this->grf_prop.local_id = base; this->list_position = base; /* Check if this base engine is within the original engine data range */ @@ -241,7 +241,7 @@ Money Engine::GetRunningCost() const default: NOT_REACHED(); } - return GetPrice(base_price, cost_factor, this->grffile, -8); + return GetPrice(base_price, cost_factor, this->grf_prop.grffile, -8); } /** @@ -281,7 +281,7 @@ Money Engine::GetCost() const default: NOT_REACHED(); } - return GetPrice(base_price, cost_factor, this->grffile, -8); + return GetPrice(base_price, cost_factor, this->grf_prop.grffile, -8); } /** diff --git a/src/engine_base.h b/src/engine_base.h index c7e3823d5..ac6fa1d22 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -17,6 +17,7 @@ #include "vehicle_type.h" #include "core/pool_type.hpp" #include "core/smallvec_type.hpp" +#include "newgrf_commons.h" typedef Pool<Engine, EngineID, 64, 64000> EnginePool; extern EnginePool _engine_pool; @@ -46,9 +47,13 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { } u; /* NewGRF related data */ - const struct GRFFile *grffile; - const struct SpriteGroup *group[NUM_CARGO + 2]; - uint16 internal_id; ///< ID within the GRF file + /** + * Properties related the the grf file. + * NUM_CARGO real cargo plus two pseudo cargo sprite groups. + * Used for obtaining the sprite offset of custom sprites, and for + * evaluating callbacks. + */ + GRFFilePropsBase<NUM_CARGO + 2> grf_prop; uint16 overrides_count; struct WagonOverride *overrides; uint16 list_position; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 9d6deefdd..54506a07d 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -357,7 +357,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern EngineID engine = _engine_mngr.GetID(type, internal_id, scope_grfid); if (engine != INVALID_ENGINE) { Engine *e = Engine::Get(engine); - if (e->grffile == NULL) e->grffile = file; + if (e->grf_prop.grffile == NULL) e->grf_prop.grffile = file; return e; } } @@ -367,8 +367,8 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern if (engine != INVALID_ENGINE) { Engine *e = Engine::Get(engine); - if (e->grffile == NULL) { - e->grffile = file; + if (e->grf_prop.grffile == NULL) { + e->grf_prop.grffile = file; grfmsg(5, "Replaced engine at index %d for GRFID %x, type %d, index %d", e->index, BSWAP32(file->grfid), type, internal_id); } @@ -387,7 +387,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern /* ... it's not, so create a new one based off an existing engine */ Engine *e = new Engine(type, internal_id); - e->grffile = file; + e->grf_prop.grffile = file; /* Reserve the engine slot */ assert(_engine_mngr.Length() == e->index); @@ -6925,7 +6925,7 @@ static void CalculateRefitMasks() /* Did the newgrf specify any refitting? If not, use defaults. */ if (_gted[engine].refitmask_valid) { if (ei->refit_mask != 0) { - const GRFFile *file = e->grffile; + const GRFFile *file = e->grf_prop.grffile; if (file != NULL && file->cargo_max != 0) { /* Apply cargo translation table to the refit mask */ uint num_cargo = min(32, file->cargo_max); @@ -6987,7 +6987,7 @@ static void FinaliseEngineArray() Engine *e; FOR_ALL_ENGINES(e) { - if (e->grffile == NULL) { + if (e->grf_prop.grffile == NULL) { const EngineIDMapping &eid = _engine_mngr[e->index]; if (eid.grfid != INVALID_GRFID || eid.internal_id != eid.substitute_id) { e->info.string_id = STR_NEWGRF_INVALID_ENGINE; diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index cae1d4ad2..92f6f0eb2 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -92,12 +92,12 @@ void UnloadWagonOverrides(Engine *e) void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *group) { Engine *e = Engine::Get(engine); - assert(cargo < lengthof(e->group)); + assert(cargo < lengthof(e->grf_prop.spritegroup)); - if (e->group[cargo] != NULL) { + if (e->grf_prop.spritegroup[cargo] != NULL) { grfmsg(6, "SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo); } - e->group[cargo] = group; + e->grf_prop.spritegroup[cargo] = group; } @@ -110,7 +110,7 @@ void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *grou void SetEngineGRF(EngineID engine, const GRFFile *file) { Engine *e = Engine::Get(engine); - e->grffile = file; + e->grf_prop.grffile = file; } @@ -121,7 +121,7 @@ void SetEngineGRF(EngineID engine, const GRFFile *file) */ const GRFFile *GetEngineGRF(EngineID engine) { - return Engine::Get(engine)->grffile; + return Engine::Get(engine)->grf_prop.grffile; } @@ -655,12 +655,12 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by /* Variables which use the parameter */ case 0x60: // Count consist's engine ID occurance //EngineID engine = GetNewEngineID(GetEngineGRF(v->engine_type), v->type, parameter); - if (v->type != VEH_TRAIN) return Engine::Get(v->engine_type)->internal_id == parameter; + if (v->type != VEH_TRAIN) return Engine::Get(v->engine_type)->grf_prop.local_id == parameter; { uint count = 0; for (; v != NULL; v = v->Next()) { - if (Engine::Get(v->engine_type)->internal_id == parameter) count++; + if (Engine::Get(v->engine_type)->grf_prop.local_id == parameter) count++; } return count; } @@ -745,8 +745,8 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by case 0x43: return GB(v->max_age, 8, 8); case 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; case 0x45: return v->unitnumber; - case 0x46: return Engine::Get(v->engine_type)->internal_id; - case 0x47: return GB(Engine::Get(v->engine_type)->internal_id, 8, 8); + case 0x46: return Engine::Get(v->engine_type)->grf_prop.local_id; + case 0x47: return GB(Engine::Get(v->engine_type)->grf_prop.local_id, 8, 8); case 0x48: if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum; return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD; @@ -877,7 +877,7 @@ static inline void NewVehicleResolver(ResolverObject *res, EngineID engine_type, res->count = 0; const Engine *e = Engine::Get(engine_type); - res->grffile = (e != NULL ? e->grffile : NULL); + res->grffile = (e != NULL ? e->grf_prop.grffile : NULL); } @@ -914,12 +914,12 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle * const Engine *e = Engine::Get(engine); - assert(cargo < lengthof(e->group)); - group = e->group[cargo]; + assert(cargo < lengthof(e->grf_prop.spritegroup)); + group = e->grf_prop.spritegroup[cargo]; if (group != NULL) return group; /* Fall back to the default set if the selected cargo type is not defined */ - return e->group[CT_DEFAULT]; + return e->grf_prop.spritegroup[CT_DEFAULT]; } @@ -1133,10 +1133,10 @@ void TriggerVehicle(Vehicle *v, VehicleTrigger trigger) uint ListPositionOfEngine(EngineID engine) { const Engine *e = Engine::Get(engine); - if (e->grffile == NULL) return e->list_position; + if (e->grf_prop.grffile == NULL) return e->list_position; /* Crude sorting to group by GRF ID */ - return (e->grffile->grfid * 256) + e->list_position; + return (e->grf_prop.grffile->grfid * 256) + e->list_position; } struct ListOrderChange { @@ -1173,8 +1173,8 @@ void CommitVehicleListOrderChanges() /* Populate map with current list positions */ Engine *e; FOR_ALL_ENGINES_OF_TYPE(e, source_e->type) { - if (!_settings_game.vehicle.dynamic_engines || e->grffile == source_e->grffile) { - if (e->internal_id == target) target_e = e; + if (!_settings_game.vehicle.dynamic_engines || e->grf_prop.grffile == source_e->grf_prop.grffile) { + if (e->grf_prop.local_id == target) target_e = e; lptr_map[e->list_position] = e; } } diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index f6135d585..5df63c9e5 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1650,7 +1650,7 @@ Money RoadVehicle::GetRunningCost() const uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, e->u.road.running_cost); if (cost_factor == 0) return 0; - return GetPrice(e->u.road.running_cost_class, cost_factor, e->grffile); + return GetPrice(e->u.road.running_cost_class, cost_factor, e->grf_prop.grffile); } bool RoadVehicle::Tick() diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 1f8f2d0d6..5ec206648 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -162,7 +162,7 @@ Money Ship::GetRunningCost() const { const Engine *e = Engine::Get(this->engine_type); uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost); - return GetPrice(PR_RUNNING_SHIP, cost_factor, e->grffile); + return GetPrice(PR_RUNNING_SHIP, cost_factor, e->grf_prop.grffile); } void Ship::OnNewDay() diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 4b8fe1b47..028854891 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -61,7 +61,7 @@ static const NIVariable _niv_vehicles[] = { }; class NIHVehicle : public NIHelper { - bool IsInspectable(uint index) const { return Engine::Get(Vehicle::Get(index)->engine_type)->grffile != NULL; } + bool IsInspectable(uint index) const { return Engine::Get(Vehicle::Get(index)->engine_type)->grf_prop.grffile != NULL; } uint GetParent(uint index) const { const Vehicle *first = Vehicle::Get(index)->First(); return GetInspectWindowNumber(GetGrfSpecFeature(first->type), first->index); } const void *GetInstance(uint index)const { return Vehicle::Get(index); } const void *GetSpec(uint index) const { return Engine::Get(Vehicle::Get(index)->engine_type); } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 8d75bfcde..e2745a175 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -98,9 +98,9 @@ static void RailVehicleLengthChanged(const Train *u) { /* show a warning once for each engine in whole game and once for each GRF after each game load */ const Engine *engine = Engine::Get(u->engine_type); - uint32 grfid = engine->grffile->grfid; + uint32 grfid = engine->grf_prop.grffile->grfid; GRFConfig *grfconfig = GetGRFConfig(grfid); - if (GamelogGRFBugReverse(grfid, engine->internal_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) { + if (GamelogGRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) { ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, GBUG_VEH_LENGTH, true); } } @@ -458,9 +458,9 @@ int Train::GetDisplayImageWidth(Point *offset) const int vehicle_pitch = 0; const Engine *e = Engine::Get(this->engine_type); - if (e->grffile != NULL && is_custom_sprite(e->u.rail.image_index)) { - reference_width = e->grffile->traininfo_vehicle_width; - vehicle_pitch = e->grffile->traininfo_vehicle_pitch; + if (e->grf_prop.grffile != NULL && is_custom_sprite(e->u.rail.image_index)) { + reference_width = e->grf_prop.grffile->traininfo_vehicle_width; + vehicle_pitch = e->grf_prop.grffile->traininfo_vehicle_pitch; } if (offset != NULL) { @@ -505,8 +505,8 @@ static SpriteID GetRailIcon(EngineID engine, bool rear_head, int &y) if (is_custom_sprite(spritenum)) { SpriteID sprite = GetCustomVehicleIcon(engine, dir); if (sprite != 0) { - if (e->grffile != NULL) { - y += e->grffile->traininfo_vehicle_pitch; + if (e->grf_prop.grffile != NULL) { + y += e->grf_prop.grffile->traininfo_vehicle_pitch; } return sprite; } @@ -3984,7 +3984,7 @@ Money Train::GetRunningCost() const /* Halve running cost for multiheaded parts */ if (v->IsMultiheaded()) cost_factor /= 2; - cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->grffile); + cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->grf_prop.grffile); } while ((v = v->GetNextVehicle()) != NULL); return cost; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 0fde74128..3a23dfab9 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -200,7 +200,7 @@ uint Vehicle::Crash(bool flooded) void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical) { const Engine *e = Engine::Get(engine); - uint32 grfid = e->grffile->grfid; + uint32 grfid = e->grf_prop.grffile->grfid; GRFConfig *grfconfig = GetGRFConfig(grfid); if (!HasBit(grfconfig->grf_bugs, bug_type)) { diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index eb55996c9..2b8ca00fb 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -281,7 +281,7 @@ static CommandCost GetRefitCost(EngineID engine_type) default: NOT_REACHED(); } - return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->grffile, -10)); + return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->grf_prop.grffile, -10)); } /** |