summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/newgrf.cpp27
-rw-r--r--src/rail.cpp7
-rw-r--r--src/rail.h11
-rw-r--r--src/table/railtypes.h12
4 files changed, 31 insertions, 26 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index cf3e53a52..1c129d21e 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -3643,15 +3643,15 @@ bool GetGlobalVariable(byte param, uint32 *value)
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 @@ static void ParamSet(byte *buf, size_t len)
_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 @@ static void ResetNewGRFData()
_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;
diff --git a/src/rail.cpp b/src/rail.cpp
index b153788b4..7c508dd8b 100644
--- a/src/rail.cpp
+++ b/src/rail.cpp
@@ -149,13 +149,6 @@ extern const TrackdirBits _uphill_trackdirs[] = {
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)) {
diff --git a/src/rail.h b/src/rail.h
index 8fa3164c2..7e3cd4b75 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -113,6 +113,11 @@ struct RailtypeInfo {
* Bit mask of rail type flags
*/
RailTypeFlags flags;
+
+ /**
+ * Cost multiplier for building this rail type
+ */
+ uint8 cost_multiplier;
};
@@ -154,10 +159,6 @@ static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
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 @@ extern const int _default_railtype_cost_multiplier[RAILTYPE_END];
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;
}
/**
diff --git a/src/table/railtypes.h b/src/table/railtypes.h
index 3a5467cb0..037014541 100644
--- a/src/table/railtypes.h
+++ b/src/table/railtypes.h
@@ -70,6 +70,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* flags */
RTFB_NONE,
+
+ /* cost multiplier */
+ 8,
},
/** Electrified railway */
@@ -136,6 +139,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* flags */
RTFB_CATENARY,
+
+ /* cost multiplier */
+ 12,
},
/** Monorail */
@@ -198,6 +204,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* flags */
RTFB_NONE,
+
+ /* cost multiplier */
+ 16,
},
/** Maglev */
@@ -260,6 +269,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* flags */
RTFB_NONE,
+
+ /* cost multiplier */
+ 24,
},
};