Changeset - r18266:8aae3fd9e028
[Not reviewed]
master
0 6 0
michi_cc - 13 years ago 2011-11-04 15:04:29
michi_cc@openttd.org
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
6 files changed with 30 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/roadveh.h
Show inline comments
 
@@ -79,7 +79,7 @@ static const uint RVC_DEPOT_STOP_FRAME  
 
/** 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.
src/roadveh_cmd.cpp
Show inline comments
 
@@ -174,9 +174,10 @@ static uint GetRoadVehLength(const RoadV
 
/**
 
 * 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 @@ void RoadVehUpdateCache(RoadVehicle *v)
 
		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 */
src/train_cmd.cpp
Show inline comments
 
@@ -84,22 +84,6 @@ byte FreightWagonMult(CargoID cargo)
 
	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 @@ void Train::ConsistChanged(bool same_len
 
		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;
src/vehicle.cpp
Show inline comments
 
@@ -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 @@ void ShowNewGrfVehicleError(EngineID eng
 
}
 

	
 
/**
 
 * 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.
 
 */
src/vehicle_cmd.cpp
Show inline comments
 
@@ -407,10 +407,10 @@ CommandCost CmdRefitVehicle(TileIndex ti
 
		/* 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;
 

	
src/vehicle_func.h
Show inline comments
 
@@ -41,6 +41,8 @@ bool HasVehicleOnPosXY(int x, int y, voi
 
void CallVehicleTicks();
 
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
 

	
 
void VehicleLengthChanged(const Vehicle *u);
 

	
 
byte VehicleRandomBits();
 
void ResetVehiclePosHash();
 
void ResetVehicleColourMap();
0 comments (0 inline, 0 general)