Mercurial > hg > openttd
changeset 10002:139ef0c97e94 draft
(svn r14160) -Codechange: Move _railtype_cost_multipliers into the rail type information struct.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Sun, 24 Aug 2008 23:10:23 +0000 |
parents | 5f7a84c30cdf |
children | 225c6c30e9b8 |
files | src/newgrf.cpp src/rail.cpp src/rail.h src/table/railtypes.h |
diffstat | 4 files changed, 31 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3643,15 +3643,15 @@ case 0x0F: // Rail track type cost factors *value = 0; - SB(*value, 0, 8, _railtype_cost_multiplier[0]); // normal rail + SB(*value, 0, 8, GetRailTypeInfo(RAILTYPE_RAIL)->cost_multiplier); // normal rail if (_settings_game.vehicle.disable_elrails) { /* skip elrail multiplier - disabled */ - SB(*value, 8, 8, _railtype_cost_multiplier[2]); // monorail + SB(*value, 8, 8, GetRailTypeInfo(RAILTYPE_MONO)->cost_multiplier); // monorail } else { - SB(*value, 8, 8, _railtype_cost_multiplier[1]); // electified railway + SB(*value, 8, 8, GetRailTypeInfo(RAILTYPE_ELECTRIC)->cost_multiplier); // electified railway /* Skip monorail multiplier - no space in result */ } - SB(*value, 16, 8, _railtype_cost_multiplier[3]); // maglev + SB(*value, 16, 8, GetRailTypeInfo(RAILTYPE_MAGLEV)->cost_multiplier); // maglev return true; case 0x11: // current rail tool type @@ -4651,17 +4651,19 @@ _traininfo_vehicle_pitch = res; break; - case 0x8F: // Rail track type cost factors - _railtype_cost_multiplier[0] = GB(res, 0, 8); + case 0x8F: { // Rail track type cost factors + extern RailtypeInfo _railtypes[RAILTYPE_END]; + _railtypes[RAILTYPE_RAIL].cost_multiplier = GB(res, 0, 8); if (_settings_game.vehicle.disable_elrails) { - _railtype_cost_multiplier[1] = GB(res, 0, 8); - _railtype_cost_multiplier[2] = GB(res, 8, 8); + _railtypes[RAILTYPE_ELECTRIC].cost_multiplier = GB(res, 0, 8); + _railtypes[RAILTYPE_MONO].cost_multiplier = GB(res, 8, 8); } else { - _railtype_cost_multiplier[1] = GB(res, 8, 8); - _railtype_cost_multiplier[2] = GB(res, 16, 8); + _railtypes[RAILTYPE_ELECTRIC].cost_multiplier = GB(res, 8, 8); + _railtypes[RAILTYPE_MONO].cost_multiplier = GB(res, 16, 8); } - _railtype_cost_multiplier[3] = GB(res, 16, 8); + _railtypes[RAILTYPE_MAGLEV].cost_multiplier = GB(res, 16, 8); break; + } /* @todo implement */ case 0x93: // Tile refresh offset to left @@ -5473,9 +5475,6 @@ _traininfo_vehicle_pitch = 0; _traininfo_vehicle_width = 29; - /* Reset track cost multipliers. */ - memcpy(&_railtype_cost_multiplier, &_default_railtype_cost_multiplier, sizeof(_default_railtype_cost_multiplier)); - _loaded_newgrf_features.has_2CC = false; _loaded_newgrf_features.has_newhouses = false; _loaded_newgrf_features.has_newindustries = false;
--- a/src/rail.cpp +++ b/src/rail.cpp @@ -149,13 +149,6 @@ TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE, ///< 30 SLOPE_STEEP_E -> inclined for diagonal track }; -/* The default multiplier for the cost of building different types of railway - * track, which will be divided by 8. Can be changed by newgrf files. */ -const int _default_railtype_cost_multiplier[RAILTYPE_END] = { - 8, 12, 16, 24, -}; -int _railtype_cost_multiplier[RAILTYPE_END]; - RailType GetTileRailType(TileIndex tile) { switch (GetTileType(tile)) {
--- a/src/rail.h +++ b/src/rail.h @@ -113,6 +113,11 @@ * Bit mask of rail type flags */ RailTypeFlags flags; + + /** + * Cost multiplier for building this rail type + */ + uint8 cost_multiplier; }; @@ -154,10 +159,6 @@ return HasBit(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype); } - -extern int _railtype_cost_multiplier[RAILTYPE_END]; -extern const int _default_railtype_cost_multiplier[RAILTYPE_END]; - /** * Returns the cost of building the specified railtype. * @param railtype The railtype being built. @@ -166,7 +167,7 @@ static inline Money RailBuildCost(RailType railtype) { assert(railtype < RAILTYPE_END); - return (_price.build_rail * _railtype_cost_multiplier[railtype]) >> 3; + return (_price.build_rail * GetRailTypeInfo(railtype)->cost_multiplier) >> 3; } /**
--- a/src/table/railtypes.h +++ b/src/table/railtypes.h @@ -70,6 +70,9 @@ /* flags */ RTFB_NONE, + + /* cost multiplier */ + 8, }, /** Electrified railway */ @@ -136,6 +139,9 @@ /* flags */ RTFB_CATENARY, + + /* cost multiplier */ + 12, }, /** Monorail */ @@ -198,6 +204,9 @@ /* flags */ RTFB_NONE, + + /* cost multiplier */ + 16, }, /** Maglev */ @@ -260,6 +269,9 @@ /* flags */ RTFB_NONE, + + /* cost multiplier */ + 24, }, };