Changeset - r15816:67664bff2b7d
[Not reviewed]
master
0 5 0
frosch - 14 years ago 2010-08-15 19:59:48
frosch@openttd.org
(svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype.
5 files changed with 35 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -2463,12 +2463,13 @@ STR_NEWGRF_LIST_NONE                    
 
STR_NEWGRF_LIST_ALL_FOUND                                       :All files present
 
STR_NEWGRF_LIST_COMPATIBLE                                      :{YELLOW}Found compatible files
 
STR_NEWGRF_LIST_MISSING                                         :{RED}Missing files
 

	
 
# NewGRF 'it's broken' warnings
 
STR_NEWGRF_BROKEN                                               :{WHITE}Behaviour of NewGRF '{0:RAW_STRING}' is likely to cause desyncs and/or crashes.
 
STR_NEWGRF_BROKEN_POWERED_WAGON                                 :{WHITE}Wagon '{1:ENGINE}' changed powered-wagon state when not inside a depot.
 
STR_NEWGRF_BROKEN_VEHICLE_LENGTH                                :{WHITE}It changes vehicle length for '{1:ENGINE}' when not inside a depot.
 
STR_BROKEN_VEHICLE_LENGTH                                       :{WHITE}Train '{VEHICLE}' belonging to '{COMPANY}' has invalid length. It is probably caused by problems with NewGRFs. Game may desync or crash.
 

	
 
STR_NEWGRF_BUGGY                                                :{WHITE}NewGRF '{0:RAW_STRING}' provides incorrect information.
 
STR_NEWGRF_BUGGY_ARTICULATED_CARGO                              :{WHITE}Cargo/refit information for '{1:ENGINE}' differs from purchase list after construction. This might cause autorenew/-replace to fail refitting correctly.
 
STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK                    :{WHITE}'{1:STRING}' caused an endless loop in the production callback.
src/newgrf_config.h
Show inline comments
 
@@ -36,14 +36,15 @@ enum GRFStatus {
 
	GCS_INITIALISED,  ///< GRF file has been initialised
 
	GCS_ACTIVATED     ///< GRF file has been activated
 
};
 

	
 
/** Encountered GRF bugs */
 
enum GRFBugs {
 
	GBUG_VEH_LENGTH,  ///< Length of rail vehicle changes when not inside a depot
 
	GBUG_VEH_REFIT,   ///< Articulated vehicles carry different cargos resp. are differently refittable than specified in purchase list
 
	GBUG_VEH_LENGTH,        ///< Length of rail vehicle changes when not inside a depot
 
	GBUG_VEH_REFIT,         ///< Articulated vehicles carry different cargos resp. are differently refittable than specified in purchase list
 
	GBUG_VEH_POWERED_WAGON, ///< Powered wagon changed poweredness state when not inside a depot
 
};
 

	
 
/** Status of post-gameload GRF compatibility check */
 
enum GRFListCompatibility {
 
	GLC_ALL_GOOD,   ///< All GRF needed by game are present
 
	GLC_COMPATIBLE, ///< Compatible (eg. the same ID, but different chacksum) GRF found in at least one case
src/rail_cmd.cpp
Show inline comments
 
@@ -1377,13 +1377,12 @@ CommandCost CmdRemoveSignalTrack(TileInd
 

	
 
/** Update power of train under which is the railtype being converted */
 
static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
 
{
 
	if (v->type != VEH_TRAIN) return NULL;
 

	
 
	/* Similar checks as in Train::PowerChanged() */
 
	TrainList *affected_trains = static_cast<TrainList*>(data);
 
	affected_trains->Include(Train::From(v)->First());
 

	
 
	return NULL;
 
}
 

	
 
@@ -1580,14 +1579,13 @@ CommandCost CmdConvertRail(TileIndex til
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Railtype changed, update trains as when entering different track */
 
		for (Train **v = affected_trains.Begin(); v != affected_trains.End(); v++) {
 
			(*v)->PowerChanged();
 
			(*v)->UpdateAcceleration();
 
			(*v)->RailtypeChanged();
 
		}
 
	}
 

	
 
	return (cost.GetCost() == 0) ? error : cost;
 
}
 

	
src/train.h
Show inline comments
 
@@ -142,12 +142,14 @@ struct Train : public GroundVehicle<Trai
 
	void ReserveTrackUnderConsist() const;
 

	
 
	int GetCurveSpeedLimit() const;
 

	
 
	void ConsistChanged(bool same_length);
 

	
 
	void RailtypeChanged();
 

	
 
	int UpdateSpeed();
 

	
 
	void UpdateAcceleration();
 

	
 
	int GetCurrentMaxSpeed() const;
 

	
 
@@ -369,13 +371,13 @@ struct Train : public GroundVehicle<Trai
 
		return v;
 
	}
 

	
 

	
 
protected: // These functions should not be called outside acceleration code.
 

	
 
	void UpdateVisualEffect();
 
	void UpdateVisualEffect(bool allow_power_change);
 

	
 
	/**
 
	 * Allows to know the power value that this vehicle will use.
 
	 * @return Power value from the engine in HP, or zero if the vehicle is not powered.
 
	 */
 
	FORCEINLINE uint16 GetPower() const
src/train_cmd.cpp
Show inline comments
 
@@ -127,16 +127,33 @@ void CheckTrainsLengths()
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Update the cached visual effect.
 
 * Update visual effect, power and acceleration caches.
 
 * Called when a vehicle in the consist enters a different railtype.
 
 */
 
void Train::UpdateVisualEffect()
 
void Train::RailtypeChanged()
 
{
 
	for (Train *u = this; u != NULL; u = u->Next()) {
 
		/* The wagon-is-powered-state should not change, so the weight does not change. */
 
		u->UpdateVisualEffect(false);
 
	}
 
	this->PowerChanged();
 
	if (this->IsFrontEngine()) this->UpdateAcceleration();
 
}
 

	
 
/**
 
 * Update the cached visual effect.
 
 * @param allow_power_change true if the wagon-is-powered-state may change.
 
 */
 
void Train::UpdateVisualEffect(bool allow_power_change)
 
{
 
	byte powered_before = this->tcache.cached_vis_effect & 0x80;
 

	
 
	const Engine *e = Engine::Get(this->engine_type);
 
	if (e->u.rail.visual_effect != 0) {
 
		this->tcache.cached_vis_effect = e->u.rail.visual_effect;
 
	} else {
 
		if (this->IsWagon() || this->IsArticulatedPart()) {
 
			/* Wagons and articulated parts have no effect by default */
 
@@ -153,12 +170,17 @@ void Train::UpdateVisualEffect()
 
	/* Check powered wagon / visual effect callback */
 
	if (HasBit(e->info.callback_mask, CBM_TRAIN_WAGON_POWER)) {
 
		uint16 callback = GetVehicleCallback(CBID_TRAIN_WAGON_POWER, 0, 0, this->engine_type, this);
 

	
 
		if (callback != CALLBACK_FAILED) this->tcache.cached_vis_effect = GB(callback, 0, 8);
 
	}
 

	
 
	if (!allow_power_change && powered_before != (this->tcache.cached_vis_effect & 0x80)) {
 
		this->tcache.cached_vis_effect ^= 0x80;
 
		ShowNewGrfVehicleError(this->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_POWERED_WAGON, GBUG_VEH_POWERED_WAGON, false);
 
	}
 
}
 

	
 
/**
 
 * Recalculates the cached stuff of a train. Should be called each time a vehicle is added
 
 * to/removed from the chain, and when the game is loaded.
 
 * Note: this needs to be called too for 'wagon chains' (in the depot, without an engine)
 
@@ -212,13 +234,13 @@ void Train::ConsistChanged(bool same_len
 
		u->tcache.cached_override = GetWagonOverrideSpriteSet(u->engine_type, u->cargo_type, u->tcache.first_engine);
 

	
 
		/* Reset colour map */
 
		u->colourmap = PAL_NONE;
 

	
 
		/* Update powered-wagon-status and visual effect */
 
		u->UpdateVisualEffect();
 
		u->UpdateVisualEffect(true);
 

	
 
		if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON &&
 
				UsesWagonOverride(u) && !HasBit(u->tcache.cached_vis_effect, 7)) {
 
			/* wagon is powered */
 
			SetBit(u->flags, VRF_POWEREDWAGON); // cache 'powered' status
 
		} else {
 
@@ -1563,13 +1585,13 @@ static void ReverseTrainSwapVeh(Train *v
 
		a->UpdateViewport(true, true);
 

	
 
		if (a->track != TRACK_BIT_WORMHOLE) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos);
 
	}
 

	
 
	/* Update power of the train in case tiles were different rail type. */
 
	v->PowerChanged();
 
	v->RailtypeChanged();
 
}
 

	
 

	
 
/**
 
 * Check if the vehicle is a train
 
 * @param v vehicle on tile
 
@@ -3364,14 +3386,13 @@ static void TrainController(Train *v, Ve
 
					/* Clear any track reservation when the last vehicle leaves the tile */
 
					if (v->Next() == NULL) ClearPathReservation(v, v->tile, v->GetVehicleTrackdir());
 

	
 
					v->tile = gp.new_tile;
 

	
 
					if (GetTileRailType(gp.new_tile) != GetTileRailType(gp.old_tile)) {
 
						v->First()->PowerChanged();
 
						v->First()->UpdateAcceleration();
 
						v->First()->RailtypeChanged();
 
					}
 

	
 
					v->track = chosen_track;
 
					assert(v->track);
 
				}
 

	
0 comments (0 inline, 0 general)