Mercurial > hg > openttd
changeset 18276:72e793b46dee draft
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
author | michi_cc <michi_cc@openttd.org> |
---|---|
date | Fri, 04 Nov 2011 15:04:29 +0000 |
parents | 893113d8052f |
children | 6bf27441026a |
files | src/roadveh.h src/roadveh_cmd.cpp src/train_cmd.cpp src/vehicle.cpp src/vehicle_cmd.cpp src/vehicle_func.h |
diffstat | 6 files changed, 30 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/roadveh.h +++ b/src/roadveh.h @@ -79,7 +79,7 @@ /** The number of ticks a vehicle has for overtaking. */ static const byte RV_OVERTAKE_TIMEOUT = 35; -void RoadVehUpdateCache(RoadVehicle *v); +void RoadVehUpdateCache(RoadVehicle *v, bool same_length = false); /** * Buses, trucks and trams belong to this class.
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -174,9 +174,10 @@ /** * Update the cache of a road vehicle. * @param v Road vehicle needing an update of its cache. + * @param same_length should length of vehicles stay the same? * @pre \a v must be first road vehicle. */ -void RoadVehUpdateCache(RoadVehicle *v) +void RoadVehUpdateCache(RoadVehicle *v, bool same_length) { assert(v->type == VEH_ROAD); assert(v->IsFrontEngine()); @@ -193,7 +194,11 @@ u->gcache.first_engine = (v == u) ? INVALID_ENGINE : v->engine_type; /* Update the length of the vehicle. */ - u->gcache.cached_veh_length = GetRoadVehLength(u); + uint veh_len = GetRoadVehLength(u); + /* Verify length hasn't changed. */ + if (same_length && veh_len != u->gcache.cached_veh_length) VehicleLengthChanged(u); + + u->gcache.cached_veh_length = veh_len; v->gcache.cached_total_length += u->gcache.cached_veh_length; /* Update visual effect */
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -84,22 +84,6 @@ return _settings_game.vehicle.freight_trains; } -/** - * Logs a bug in GRF and shows a warning message if this - * is for the first time this happened. - * @param u first vehicle of chain - */ -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 = u->GetEngine(); - uint32 grfid = engine->grf_prop.grffile->grfid; - GRFConfig *grfconfig = GetGRFConfig(grfid); - 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); - } -} - /** Checks if lengths of all rail vehicles are valid. If not, shows an error message. */ void CheckTrainsLengths() { @@ -244,7 +228,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); + if (same_length && veh_len != u->gcache.cached_veh_length) VehicleLengthChanged(u); /* update vehicle length? */ if (!same_length) u->gcache.cached_veh_length = veh_len;
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -52,6 +52,7 @@ #include "bridge_map.h" #include "tunnel_map.h" #include "depot_map.h" +#include "gamelog.h" #include "table/strings.h" @@ -234,6 +235,22 @@ } /** + * Logs a bug in GRF and shows a warning message if this + * is for the first time this happened. + * @param u first vehicle of chain + */ +void VehicleLengthChanged(const Vehicle *u) +{ + /* show a warning once for each engine in whole game and once for each GRF after each game load */ + const Engine *engine = u->GetEngine(); + uint32 grfid = engine->grf_prop.grffile->grfid; + GRFConfig *grfconfig = GetGRFConfig(grfid); + 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); + } +} + +/** * Vehicle constructor. * @param type Type of the new vehicle. */
--- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -407,10 +407,10 @@ /* Update the cached variables */ switch (v->type) { case VEH_TRAIN: - Train::From(front)->ConsistChanged(false); + Train::From(front)->ConsistChanged(auto_refit); break; case VEH_ROAD: - RoadVehUpdateCache(RoadVehicle::From(front)); + RoadVehUpdateCache(RoadVehicle::From(front), auto_refit); if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) RoadVehicle::From(front)->CargoChanged(); break;