mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
This commit is contained in:
parent
ad2fdd8d6f
commit
a3e6e113fe
|
@ -79,7 +79,7 @@ static const uint RVC_DEPOT_STOP_FRAME = 11;
|
||||||
/** The number of ticks a vehicle has for overtaking. */
|
/** The number of ticks a vehicle has for overtaking. */
|
||||||
static const byte RV_OVERTAKE_TIMEOUT = 35;
|
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.
|
* Buses, trucks and trams belong to this class.
|
||||||
|
|
|
@ -174,9 +174,10 @@ static uint GetRoadVehLength(const RoadVehicle *v)
|
||||||
/**
|
/**
|
||||||
* Update the cache of a road vehicle.
|
* Update the cache of a road vehicle.
|
||||||
* @param v Road vehicle needing an update of its cache.
|
* @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.
|
* @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->type == VEH_ROAD);
|
||||||
assert(v->IsFrontEngine());
|
assert(v->IsFrontEngine());
|
||||||
|
@ -193,7 +194,11 @@ void RoadVehUpdateCache(RoadVehicle *v)
|
||||||
u->gcache.first_engine = (v == u) ? INVALID_ENGINE : v->engine_type;
|
u->gcache.first_engine = (v == u) ? INVALID_ENGINE : v->engine_type;
|
||||||
|
|
||||||
/* Update the length of the vehicle. */
|
/* 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;
|
v->gcache.cached_total_length += u->gcache.cached_veh_length;
|
||||||
|
|
||||||
/* Update visual effect */
|
/* Update visual effect */
|
||||||
|
|
|
@ -84,22 +84,6 @@ byte FreightWagonMult(CargoID cargo)
|
||||||
return _settings_game.vehicle.freight_trains;
|
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. */
|
/** Checks if lengths of all rail vehicles are valid. If not, shows an error message. */
|
||||||
void CheckTrainsLengths()
|
void CheckTrainsLengths()
|
||||||
{
|
{
|
||||||
|
@ -244,7 +228,7 @@ void Train::ConsistChanged(bool same_length)
|
||||||
veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1);
|
veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1);
|
||||||
|
|
||||||
/* verify length hasn't changed */
|
/* 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? */
|
/* update vehicle length? */
|
||||||
if (!same_length) u->gcache.cached_veh_length = veh_len;
|
if (!same_length) u->gcache.cached_veh_length = veh_len;
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include "bridge_map.h"
|
#include "bridge_map.h"
|
||||||
#include "tunnel_map.h"
|
#include "tunnel_map.h"
|
||||||
#include "depot_map.h"
|
#include "depot_map.h"
|
||||||
|
#include "gamelog.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
@ -233,6 +234,22 @@ void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRF
|
||||||
DEBUG(grf, 0, "%s", buffer + 3);
|
DEBUG(grf, 0, "%s", buffer + 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Vehicle constructor.
|
||||||
* @param type Type of the new vehicle.
|
* @param type Type of the new vehicle.
|
||||||
|
|
|
@ -407,10 +407,10 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
/* Update the cached variables */
|
/* Update the cached variables */
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
Train::From(front)->ConsistChanged(false);
|
Train::From(front)->ConsistChanged(auto_refit);
|
||||||
break;
|
break;
|
||||||
case VEH_ROAD:
|
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();
|
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) RoadVehicle::From(front)->CargoChanged();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||||
void CallVehicleTicks();
|
void CallVehicleTicks();
|
||||||
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
|
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
|
||||||
|
|
||||||
|
void VehicleLengthChanged(const Vehicle *u);
|
||||||
|
|
||||||
byte VehicleRandomBits();
|
byte VehicleRandomBits();
|
||||||
void ResetVehiclePosHash();
|
void ResetVehiclePosHash();
|
||||||
void ResetVehicleColourMap();
|
void ResetVehicleColourMap();
|
||||||
|
|
Loading…
Reference in New Issue