Changeset - r13167:424b7af45d3a
[Not reviewed]
master
0 5 0
frosch - 15 years ago 2009-10-03 14:46:48
frosch@openttd.org
(svn r17684) -Fix: tcache.first_engine and rcache.first_engine need to be set before first callback/sprite-resolving. For RV fronts it was missing at all, causing livery selection to fail.
5 files changed with 7 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/articulated_vehicles.cpp
Show inline comments
 
@@ -309,46 +309,46 @@ void AddArticulatedParts(Vehicle *first,
 
		switch (type) {
 
			default: NOT_REACHED();
 

	
 
			case VEH_TRAIN: {
 
				Train *front = Train::From(first);
 
				Train *t = new Train();
 
				v->SetNext(t);
 
				v = t;
 

	
 
				t->subtype = 0;
 
				t->track = front->track;
 
				t->railtype = front->railtype;
 
				t->tcache.first_engine = front->engine_type;
 
				t->tcache.first_engine = front->engine_type; // needs to be set before first callback
 

	
 
				t->spritenum = e_artic->u.rail.image_index;
 
				if (e_artic->CanCarryCargo()) {
 
					t->cargo_type = e_artic->GetDefaultCargoType();
 
					t->cargo_cap = e_artic->u.rail.capacity;  // Callback 36 is called when the consist is finished
 
				} else {
 
					t->cargo_type = front->cargo_type; // Needed for livery selection
 
					t->cargo_cap = 0;
 
				}
 

	
 
				t->SetArticulatedPart();
 
			} break;
 

	
 
			case VEH_ROAD: {
 
				RoadVehicle *front = RoadVehicle::From(first);
 
				RoadVehicle *rv = new RoadVehicle();
 
				v->SetNext(rv);
 
				v = rv;
 

	
 
				rv->subtype = 0;
 
				rv->rcache.first_engine = front->engine_type;
 
				rv->rcache.first_engine = front->engine_type; // needs to be set before first callback
 
				rv->rcache.cached_veh_length = 8; // Callback is called when the consist is finished
 
				rv->state = RVSB_IN_DEPOT;
 

	
 
				rv->roadtype = front->roadtype;
 
				rv->compatible_roadtypes = front->compatible_roadtypes;
 

	
 
				rv->spritenum = e_artic->u.road.image_index;
 
				if (e_artic->CanCarryCargo()) {
 
					rv->cargo_type = e_artic->GetDefaultCargoType();
 
					rv->cargo_cap = e_artic->u.road.capacity;  // Callback 36 is called when the consist is finished
 
				} else {
 
					rv->cargo_type = front->cargo_type; // Needed for livery selection
src/roadveh.h
Show inline comments
 
@@ -80,25 +80,25 @@ enum RoadVehicleSubType {
 
};
 

	
 

	
 
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
 

	
 
byte GetRoadVehLength(const RoadVehicle *v);
 

	
 
void RoadVehUpdateCache(RoadVehicle *v);
 

	
 
/** Cached oftenly queried (NewGRF) values */
 
struct RoadVehicleCache {
 
	byte cached_veh_length;
 
	EngineID first_engine;
 
	EngineID first_engine;   ///< cached EngineID of the front vehicle. INVALID_VEHICLE for the front vehicle itself.
 
};
 

	
 
/**
 
 * Buses, trucks and trams belong to this class.
 
 */
 
struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
 
	RoadVehicleCache rcache; ///< Cache of often used calculated values
 
	byte state;             ///< @see RoadVehicleStates
 
	byte frame;
 
	uint16 blocked_ctr;
 
	byte overtaking;
 
	byte overtaking_ctr;
src/roadveh_cmd.cpp
Show inline comments
 
@@ -246,24 +246,25 @@ CommandCost CmdBuildRoadVeh(TileIndex ti
 
//		v->cargo_count = 0;
 
		v->value = cost.GetCost();
 
//		v->day_counter = 0;
 
//		v->next_order_param = v->next_order = 0;
 
//		v->time_counter = 0;
 
//		v->progress = 0;
 

	
 
//		v->overtaking = 0;
 

	
 
		v->last_station_visited = INVALID_STATION;
 
		v->max_speed = rvi->max_speed;
 
		v->engine_type = (EngineID)p1;
 
		v->rcache.first_engine = INVALID_ENGINE; // needs to be set before first callback
 

	
 
		v->reliability = e->reliability;
 
		v->reliability_spd_dec = e->reliability_spd_dec;
 
		v->max_age = e->GetLifeLengthInDays();
 
		_new_vehicle_id = v->index;
 

	
 
		v->name = NULL;
 

	
 
		v->service_interval = Company::Get(v->owner)->settings.vehicle.servint_roadveh;
 

	
 
		v->date_of_last_service = _date;
 
		v->build_year = _cur_year;
src/train.h
Show inline comments
 
@@ -87,27 +87,25 @@ struct TrainCache {
 
	int cached_max_curve_speed; ///< max consist speed limited by curves
 

	
 
	/**
 
	 * Position/type of visual effect.
 
	 * bit 0 - 3 = position of effect relative to vehicle. (0 = front, 8 = centre, 15 = rear)
 
	 * bit 4 - 5 = type of effect. (0 = default for engine class, 1 = steam, 2 = diesel, 3 = electric)
 
	 * bit     6 = disable visual effect.
 
	 * bit     7 = disable powered wagons.
 
	 */
 
	byte cached_vis_effect;
 
	byte user_def_data;
 

	
 
	/* NOSAVE: for wagon override - id of the first engine in train
 
	 * 0xffff == not in train */
 
	EngineID first_engine;
 
	EngineID first_engine;  ///< cached EngineID of the front vehicle. INVALID_VEHICLE for the front vehicle itself.
 
};
 

	
 
/**
 
 * 'Train' is either a loco or a wagon.
 
 */
 
struct Train : public SpecializedVehicle<Train, VEH_TRAIN> {
 
	TrainCache tcache;
 

	
 
	/* Link between the two ends of a multiheaded engine */
 
	Train *other_multiheaded_part;
 

	
 
	uint16 crash_anim_pos;
src/train_cmd.cpp
Show inline comments
 
@@ -711,24 +711,25 @@ static CommandCost CmdBuildRailWagon(Eng
 
			if (w->tile == tile && w->IsFreeWagon() &&
 
					w->engine_type == engine &&
 
					!(w->vehstatus & VS_CRASHED)) {
 
				u = w->Last();
 
				break;
 
			}
 
		}
 

	
 
		Train *v = new Train();
 
		v->spritenum = rvi->image_index;
 

	
 
		v->engine_type = engine;
 
		v->tcache.first_engine = INVALID_ENGINE; // needs to be set before first callback
 

	
 
		DiagDirection dir = GetRailDepotDirection(tile);
 

	
 
		v->direction = DiagDirToDir(dir);
 
		v->tile = tile;
 

	
 
		int x = TileX(tile) * TILE_SIZE | _vehicle_initial_x_fract[dir];
 
		int y = TileY(tile) * TILE_SIZE | _vehicle_initial_y_fract[dir];
 

	
 
		v->x_pos = x;
 
		v->y_pos = y;
 
		v->z_pos = GetSlopeZ(x, y);
 
@@ -891,24 +892,25 @@ CommandCost CmdBuildRailVehicle(TileInde
 
		v->track = TRACK_BIT_DEPOT;
 
		v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
 
		v->spritenum = rvi->image_index;
 
		v->cargo_type = e->GetDefaultCargoType();
 
//		v->cargo_subtype = 0;
 
		v->cargo_cap = rvi->capacity;
 
		v->max_speed = rvi->max_speed;
 
		v->value = value.GetCost();
 
		v->last_station_visited = INVALID_STATION;
 
//		v->dest_tile = 0;
 

	
 
		v->engine_type = p1;
 
		v->tcache.first_engine = INVALID_ENGINE; // needs to be set before first callback
 

	
 
		v->reliability = e->reliability;
 
		v->reliability_spd_dec = e->reliability_spd_dec;
 
		v->max_age = e->GetLifeLengthInDays();
 

	
 
		v->name = NULL;
 
		v->railtype = rvi->railtype;
 
		_new_vehicle_id = v->index;
 

	
 
		v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_trains;
 
		v->date_of_last_service = _date;
 
		v->build_year = _cur_year;
0 comments (0 inline, 0 general)