Changeset - r9321:a3548467da58
[Not reviewed]
master
0 4 0
peter1138 - 16 years ago 2008-05-21 12:06:05
peter1138@openttd.org
(svn r13205) -Codechange: Remove unnecessary code-style-buggering-up macro.
4 files changed with 17 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -1944,28 +1944,27 @@ int WhoCanServiceIndustry(Industry* ind)
 
	if (stations.size() == 0) return 0; // No stations found at all => nobody services
 

	
 
	const Vehicle *v;
 
	int result = 0;
 
	FOR_ALL_VEHICLES(v) {
 
		/* Is it worthwhile to try this vehicle? */
 
		if (v->owner != _local_player && result != 0) continue;
 

	
 
		/* Check whether it accepts the right kind of cargo */
 
		bool c_accepts = false;
 
		bool c_produces = false;
 
		if (v->type == VEH_TRAIN && IsFrontEngine(v)) {
 
			const Vehicle *u = v;
 
			BEGIN_ENUM_WAGONS(u)
 
			for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 
				CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces);
 
			END_ENUM_WAGONS(u)
 
			}
 
		} else if (v->type == VEH_ROAD || v->type == VEH_SHIP || v->type == VEH_AIRCRAFT) {
 
			CanCargoServiceIndustry(v->cargo_type, ind, &c_accepts, &c_produces);
 
		} else {
 
			continue;
 
		}
 
		if (!c_accepts && !c_produces) continue; // Wrong cargo
 

	
 
		/* Check orders of the vehicle.
 
		 * We cannot check the first of shared orders only, since the first vehicle in such a chain
 
		 * may have a different cargo type.
 
		 */
 
		const Order *o;
src/train_cmd.cpp
Show inline comments
 
@@ -2798,39 +2798,41 @@ static void SetVehicleCrashed(Vehicle *v
 

	
 
	v->u.rail.crash_anim_pos++;
 

	
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 

	
 
	if (v->u.rail.track == TRACK_BIT_DEPOT) {
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
	}
 

	
 
	InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
 

	
 
	BEGIN_ENUM_WAGONS(v)
 
	for (; v != NULL; v = v->Next()) {
 
		v->vehstatus |= VS_CRASHED;
 
		MarkSingleVehicleDirty(v);
 
	END_ENUM_WAGONS(v)
 
	}
 

	
 
	/* must be updated after the train has been marked crashed */
 
	if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
 
}
 

	
 
static uint CountPassengersInTrain(const Vehicle *v)
 
{
 
	uint num = 0;
 
	BEGIN_ENUM_WAGONS(v)
 

	
 
	for (; v != NULL; v = v->Next()) {
 
		if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) num += v->cargo.Count();
 
	END_ENUM_WAGONS(v)
 
	}
 

	
 
	return num;
 
}
 

	
 
struct TrainCollideChecker {
 
	Vehicle *v;  ///< vehicle we are testing for collision
 
	uint num;    ///< number of dead if train collided
 
};
 

	
 
static void *FindTrainCollideEnum(Vehicle *v, void *data)
 
{
 
	TrainCollideChecker *tcc = (TrainCollideChecker*)data;
 

	
 
@@ -3642,75 +3644,71 @@ void InitializeTrains()
 
void ConnectMultiheadedTrains()
 
{
 
	Vehicle *v;
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_TRAIN) {
 
			v->u.rail.other_multiheaded_part = NULL;
 
		}
 
	}
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_TRAIN && IsFrontEngine(v)) {
 
			Vehicle *u = v;
 

	
 
			BEGIN_ENUM_WAGONS(u) {
 
			for (Vehicle *u = v; u != NULL; u = u->Next()) {
 
				if (u->u.rail.other_multiheaded_part != NULL) continue; // we already linked this one
 

	
 
				if (IsMultiheaded(u)) {
 
					if (!IsTrainEngine(u)) {
 
						/* we got a rear car without a front car. We will convert it to a front one */
 
						SetTrainEngine(u);
 
						u->spritenum--;
 
					}
 

	
 
					Vehicle *w;
 
					for (w = u->Next(); w != NULL && (w->engine_type != u->engine_type || w->u.rail.other_multiheaded_part != NULL); w = GetNextVehicle(w)) {}
 
					if (w != NULL) {
 
						/* we found a car to partner with this engine. Now we will make sure it face the right way */
 
						if (IsTrainEngine(w)) {
 
							ClearTrainEngine(w);
 
							w->spritenum++;
 
						}
 
						w->u.rail.other_multiheaded_part = u;
 
						u->u.rail.other_multiheaded_part = w;
 
					} else {
 
						/* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */
 
						ClearMultiheaded(u);
 
					}
 
				}
 
			} END_ENUM_WAGONS(u)
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 *  Converts all trains to the new subtype format introduced in savegame 16.2
 
 *  It also links multiheaded engines or make them forget they are multiheaded if no suitable partner is found
 
 */
 
void ConvertOldMultiheadToNew()
 
{
 
	Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_TRAIN) {
 
			SetBit(v->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop
 
		}
 
	}
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_TRAIN) {
 
			if (HasBit(v->subtype, 7) && ((v->subtype & ~0x80) == 0 || (v->subtype & ~0x80) == 4)) {
 
				Vehicle *u = v;
 

	
 
				BEGIN_ENUM_WAGONS(u) {
 
				for (Vehicle *u = v; u != NULL; u = u->Next()) {
 
					const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
 

	
 
					ClrBit(u->subtype, 7);
 
					switch (u->subtype) {
 
						case 0: /* TS_Front_Engine */
 
							if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
 
							SetFrontEngine(u);
 
							SetTrainEngine(u);
 
							break;
 

	
 
						case 1: /* TS_Artic_Part */
 
							u->subtype = 0;
 
@@ -3731,17 +3729,17 @@ void ConvertOldMultiheadToNew()
 
							}
 
							if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
 
							SetTrainEngine(u);
 
							break;
 

	
 
						case 4: /* TS_Free_Car */
 
							u->subtype = 0;
 
							SetTrainWagon(u);
 
							SetFreeWagon(u);
 
							break;
 
						default: NOT_REACHED(); break;
 
					}
 
				} END_ENUM_WAGONS(u)
 
				}
 
			}
 
		}
 
	}
 
}
src/vehicle_base.h
Show inline comments
 
@@ -555,27 +555,24 @@ struct DisasterVehicle : public Vehicle 
 
 */
 
struct InvalidVehicle : public Vehicle {
 
	/** Initializes the Vehicle to a invalid vehicle */
 
	InvalidVehicle() { this->type = VEH_INVALID; }
 

	
 
	/** We want to 'destruct' the right class. */
 
	virtual ~InvalidVehicle() {}
 

	
 
	const char *GetTypeString() const { return "invalid vehicle"; }
 
	void Tick() {}
 
};
 

	
 
#define BEGIN_ENUM_WAGONS(v) do {
 
#define END_ENUM_WAGONS(v) } while ((v = v->Next()) != NULL);
 

	
 
static inline VehicleID GetMaxVehicleIndex()
 
{
 
	/* TODO - This isn't the real content of the function, but
 
	 *  with the new pool-system this will be replaced with one that
 
	 *  _really_ returns the highest index. Now it just returns
 
	 *  the next safe value we are sure about everything is below.
 
	 */
 
	return GetVehiclePoolSize() - 1;
 
}
 

	
 
static inline uint GetNumVehicles()
 
{
src/water_cmd.cpp
Show inline comments
 
@@ -810,37 +810,33 @@ static void FloodVehicle(Vehicle *v)
 

	
 
		if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_AIRCRAFT) {
 
			if (v->type == VEH_AIRCRAFT) {
 
				/* Crashing aircraft are always at z_pos == 1, never on z_pos == 0,
 
				 * because that's always the shadow. Except for the heliport, because
 
				 * that station has a big z_offset for the aircraft. */
 
				if (!IsTileType(v->tile, MP_STATION) || !IsAirport(v->tile) || GetTileMaxZ(v->tile) != 0) return;
 
				const Station *st = GetStationByTile(v->tile);
 
				const AirportFTAClass *airport = st->Airport();
 

	
 
				if (v->z_pos != airport->delta_z + 1) return;
 
			}
 
			Vehicle *u;
 

	
 
			if (v->type != VEH_AIRCRAFT) v = v->First();
 
			u = v;
 

	
 
			/* crash all wagons, and count passengers */
 
			BEGIN_ENUM_WAGONS(v)
 
				if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count();
 
				v->vehstatus |= VS_CRASHED;
 
				MarkSingleVehicleDirty(v);
 
			END_ENUM_WAGONS(v)
 

	
 
			v = u;
 
			for (Vehicle *u = v; u != NULL; u = u->Next()) {
 
				if (IsCargoInClass(u->cargo_type, CC_PASSENGERS)) pass += u->cargo.Count();
 
				u->vehstatus |= VS_CRASHED;
 
				MarkSingleVehicleDirty(u);
 
			}
 

	
 
			switch (v->type) {
 
				default: NOT_REACHED();
 
				case VEH_TRAIN:
 
					if (IsFrontEngine(v)) pass += 4; // driver
 
					v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
 
					InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
 
					break;
 

	
 
				case VEH_ROAD:
 
					if (IsRoadVehFront(v)) pass += 1; // driver
 
					v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
0 comments (0 inline, 0 general)