diff options
author | rubidium <rubidium@openttd.org> | 2011-03-05 21:52:45 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-03-05 21:52:45 +0000 |
commit | e34c42de32a3a7dca800a250747ec41d485f42a3 (patch) | |
tree | d94487a13a4681c0575c894277f8ed45baf22b67 /src | |
parent | 2aa14cc54bc7ab05a84d6f50ee772c6f40fd6099 (diff) | |
download | openttd-e34c42de32a3a7dca800a250747ec41d485f42a3.tar.xz |
(svn r22205) -Codechange: replace magic number with constant
Diffstat (limited to 'src')
-rw-r--r-- | src/articulated_vehicles.cpp | 2 | ||||
-rw-r--r-- | src/ground_vehicle.hpp | 2 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 8 | ||||
-rw-r--r-- | src/train_cmd.cpp | 4 | ||||
-rw-r--r-- | src/vehicle_type.h | 3 |
5 files changed, 11 insertions, 8 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 95ec4871a..0ef4d9bc4 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -328,7 +328,7 @@ void AddArticulatedParts(Vehicle *first) v = rv; rv->subtype = 0; - gcache->cached_veh_length = 8; // Callback is called when the consist is finished + gcache->cached_veh_length = VEHICLE_LENGTH; // Callback is called when the consist is finished rv->state = RVSB_IN_DEPOT; rv->roadtype = front->roadtype; diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp index 6beb4e8fd..941ddca15 100644 --- a/src/ground_vehicle.hpp +++ b/src/ground_vehicle.hpp @@ -42,7 +42,7 @@ struct GroundVehicleCache { /* Cached NewGRF values, recalculated on load and each time a vehicle is added to/removed from the consist. */ uint16 cached_total_length; ///< Length of the whole vehicle (valid only for the first engine). EngineID first_engine; ///< Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself. - uint8 cached_veh_length; ///< Length of this vehicle in units of 1/8 of normal length. It is cached because this can be set by a callback. + uint8 cached_veh_length; ///< Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can be set by a callback. /* Cached UI information. */ uint16 last_speed; ///< The last speed we did display, so we only have to redraw when this changes. diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 29e47bd92..69c1a555d 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -100,7 +100,7 @@ int RoadVehicle::GetDisplayImageWidth(Point *offset) const offset->x = reference_width / 2; offset->y = 0; } - return this->gcache.cached_veh_length * reference_width / 8; + return this->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH; } static SpriteID GetRoadVehIcon(EngineID engine) @@ -161,11 +161,11 @@ void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID eng */ static uint GetRoadVehLength(const RoadVehicle *v) { - uint length = 8; + uint length = VEHICLE_LENGTH; uint16 veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v); if (veh_len != CALLBACK_FAILED) { - length -= Clamp(veh_len, 0, 7); + length -= Clamp(veh_len, 0, VEHICLE_LENGTH - 1); } return length; @@ -262,7 +262,7 @@ CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engin v->roadtype = HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD; v->compatible_roadtypes = RoadTypeToRoadTypes(v->roadtype); - v->gcache.cached_veh_length = 8; + v->gcache.cached_veh_length = VEHICLE_LENGTH; if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 05ce1aaad..853c0ee58 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -240,7 +240,7 @@ void Train::ConsistChanged(bool same_length) veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u); } if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor; - veh_len = 8 - Clamp(veh_len, 0, 7); + veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1); /* verify length hasn't changed */ if (same_length && veh_len != u->gcache.cached_veh_length) RailVehicleLengthChanged(u); @@ -461,7 +461,7 @@ int Train::GetDisplayImageWidth(Point *offset) const offset->x = reference_width / 2; offset->y = vehicle_pitch; } - return this->gcache.cached_veh_length * reference_width / 8; + return this->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH; } static SpriteID GetDefaultTrainSprite(uint8 spritenum, Direction direction) diff --git a/src/vehicle_type.h b/src/vehicle_type.h index 4b4150a63..32c79421d 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -67,6 +67,9 @@ enum DepotCommand { static const uint MAX_LENGTH_VEHICLE_NAME_CHARS = 32; ///< The maximum length of a vehicle name in characters including '\0' static const uint MAX_LENGTH_VEHICLE_NAME_PIXELS = 150; ///< The maximum length of a vehicle name in pixels +/** The length of a vehicle in tile units. */ +static const uint VEHICLE_LENGTH = 8; + /** Vehicle acceleration models. */ enum AccelerationModel { AM_ORIGINAL, |