diff options
author | maedhros <maedhros@openttd.org> | 2007-10-14 21:20:12 +0000 |
---|---|---|
committer | maedhros <maedhros@openttd.org> | 2007-10-14 21:20:12 +0000 |
commit | ee4823857ffb85b6fa088f68808ab97aa900ddd0 (patch) | |
tree | e736c50ab51b5772162a0b2e2bdc1fdc07aae36d | |
parent | 85b56a9c156f0983eddd14b63448c71c391852ab (diff) | |
download | openttd-ee4823857ffb85b6fa088f68808ab97aa900ddd0.tar.xz |
(svn r11265) -Feature: Make more advanced rail types more expensive to build.
-rw-r--r-- | src/newgrf.cpp | 20 | ||||
-rw-r--r-- | src/rail.cpp | 6 | ||||
-rw-r--r-- | src/rail.h | 16 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 4 | ||||
-rw-r--r-- | src/road_cmd.cpp | 2 | ||||
-rw-r--r-- | src/station_cmd.cpp | 2 | ||||
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 4 |
7 files changed, 45 insertions, 9 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 8eb545412..769829158 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4192,8 +4192,19 @@ static void ParamSet(byte *buf, int len) _traininfo_vehicle_pitch = res; break; - /* @todo implement */ case 0x8F: // Rail track type cost factors + _railtype_cost_multiplier[0] = GB(res, 0, 8); + if (_patches.disable_elrails) { + _railtype_cost_multiplier[1] = GB(res, 0, 8); + _railtype_cost_multiplier[2] = GB(res, 8, 8); + } else { + _railtype_cost_multiplier[1] = GB(res, 8, 8); + _railtype_cost_multiplier[2] = GB(res, 16, 8); + } + _railtype_cost_multiplier[3] = GB(res, 16, 8); + break; + + /* @todo implement */ case 0x93: // Tile refresh offset to left case 0x94: // Tile refresh offset to right case 0x95: // Tile refresh offset upwards @@ -4696,7 +4707,7 @@ static void InitializeGRFSpecial() | (1 << 0x19) // newships | (1 << 0x1A) // newplanes | ((_patches.signal_side ? 1 : 0) << 0x1B) // signalsontrafficside - | (1 << 0x1C); // electrifiedrailway + | ((_patches.disable_elrails ? 0 : 1) << 0x1C); // electrifiedrailway _ttdpatch_flags[2] = (1 << 0x01) // loadallgraphics - obsolote | (1 << 0x03) // semaphores @@ -4708,7 +4719,7 @@ static void InitializeGRFSpecial() | (0 << 0x10) // moreindustriesperclimate - obsolete | (0 << 0x11) // moretoylandfeatures | (1 << 0x12) // newstations - | (0 << 0x13) // tracktypecostdiff + | (1 << 0x13) // tracktypecostdiff | (1 << 0x14) // manualconvert | ((_patches.build_on_slopes ? 1 : 0) << 0x15) // buildoncoasts | (1 << 0x16) // canals @@ -4968,6 +4979,9 @@ 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 b172ea499..8bf83a36a 100644 --- a/src/rail.cpp +++ b/src/rail.cpp @@ -107,6 +107,12 @@ extern const TrackBits _corner_to_trackbits[] = { TRACK_BIT_LEFT, TRACK_BIT_LOWER, TRACK_BIT_RIGHT, TRACK_BIT_UPPER, }; +/* 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) { diff --git a/src/rail.h b/src/rail.h index c0912d807..36aa83f99 100644 --- a/src/rail.h +++ b/src/rail.h @@ -8,6 +8,7 @@ #include "gfx.h" #include "direction.h" #include "tile.h" +#include "variables.h" /** * Enumeration for all possible railtypes. @@ -791,6 +792,21 @@ static inline bool TracksOverlap(TrackBits bits) return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT; } + +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. + * @return The cost multiplier. + */ +static inline Money RailBuildCost(RailType railtype) +{ + assert(railtype < RAILTYPE_END); + return (_price.build_rail * _railtype_cost_multiplier[railtype]) >> 3; +} + void *UpdateTrainPowerProc(Vehicle *v, void *data); void DrawTrainDepotSprite(int x, int y, int image, RailType railtype); void DrawDefaultWaypointSprite(int x, int y, RailType railtype); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 92753c05c..973737db1 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -394,7 +394,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p YapfNotifyTrackLayoutChange(tile, track); } - return cost.AddCost(_price.build_rail); + return cost.AddCost(RailBuildCost(railtype)); } /** Remove a single piece of track @@ -1092,7 +1092,7 @@ static CommandCost DoConvertRail(TileIndex tile, RailType totype, bool exec) VehicleFromPos(tile, &tile, UpdateTrainPowerProc); } - return CommandCost(_price.build_rail / 2); + return CommandCost(RailBuildCost(totype) / 2); } extern CommandCost DoConvertStationRail(TileIndex tile, RailType totype, bool exec); diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index eaf98c499..c057dfa37 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -605,7 +605,7 @@ CommandCost DoConvertStreetRail(TileIndex tile, RailType totype, bool exec) VehicleFromPos(tile, &tile, UpdateTrainPowerProc); } - return CommandCost(_price.build_rail / 2); + return CommandCost(RailBuildCost(totype) / 2); } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index ef27fc4a6..838e89200 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1245,7 +1245,7 @@ CommandCost DoConvertStationRail(TileIndex tile, RailType totype, bool exec) VehicleFromPos(tile, &tile, UpdateTrainPowerProc); } - return CommandCost(_price.build_rail / 2); + return CommandCost(RailBuildCost(totype) / 2); } /** diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 255def8a9..8a3ea905e 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -773,7 +773,7 @@ CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec VehicleFromPos(endtile, &endtile, UpdateTrainPowerProc); } - return CommandCost((length + 1) * (_price.build_rail >> 1)); + return CommandCost((length + 1) * (RailBuildCost(totype) / 2)); } else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) { TileIndex endtile = GetOtherBridgeEnd(tile); byte bridge_height = GetBridgeHeight(tile); @@ -805,7 +805,7 @@ CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec } } - return CommandCost((DistanceManhattan(tile, endtile) + 1) * (_price.build_rail >> 1)); + return CommandCost((DistanceManhattan(tile, endtile) + 1) * (RailBuildCost(totype) / 2)); } else { return CMD_ERROR; } |