Changeset - r12295:bb9023f54628
[Not reviewed]
master
0 13 0
rubidium - 15 years ago 2009-07-02 09:06:15
rubidium@openttd.org
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
13 files changed with 26 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_vehicle.cpp
Show inline comments
 
@@ -409,14 +409,14 @@
 
{
 
	if (!IsValidVehicle(vehicle_id)) return false;
 
	if (GetVehicleType(vehicle_id) != VT_ROAD && GetVehicleType(vehicle_id) != VT_RAIL) return false;
 

	
 
	const Vehicle *v = ::Vehicle::Get(vehicle_id);
 
	switch (v->type) {
 
		case VEH_ROAD: return ::RoadVehicle::From(v)->RoadVehHasArticPart();
 
		case VEH_TRAIN: return ::Train::From(v)->EngineHasArticPart();
 
		case VEH_ROAD: return ::RoadVehicle::From(v)->HasArticulatedPart();
 
		case VEH_TRAIN: return ::Train::From(v)->HasArticulatedPart();
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/* static */ bool AIVehicle::HasSharedOrders(VehicleID vehicle_id)
 
{
src/articulated_vehicles.cpp
Show inline comments
 
@@ -204,17 +204,17 @@ bool IsArticulatedVehicleCarryingDiffere
 
				return true;
 
			}
 
		}
 

	
 
		switch (v->type) {
 
			case VEH_TRAIN:
 
				v = Train::From(v)->EngineHasArticPart() ? GetNextArticPart(Train::From(v)) : NULL;
 
				v = Train::From(v)->HasArticulatedPart() ? GetNextArticPart(Train::From(v)) : NULL;
 
				break;
 

	
 
			case VEH_ROAD:
 
				v = RoadVehicle::From(v)->RoadVehHasArticPart() ? v->Next() : NULL;
 
				v = RoadVehicle::From(v)->HasArticulatedPart() ? v->Next() : NULL;
 
				break;
 

	
 
			default:
 
				v = NULL;
 
				break;
 
		}
 
@@ -251,17 +251,17 @@ void CheckConsistencyOfArticulatedVehicl
 

	
 
		assert(v->cargo_type < NUM_CARGO);
 
		real_default_capacity[v->cargo_type] += v->cargo_cap;
 

	
 
		switch (v->type) {
 
			case VEH_TRAIN:
 
				v = Train::From(v)->EngineHasArticPart() ? GetNextArticPart(Train::From(v)) : NULL;
 
				v = Train::From(v)->HasArticulatedPart() ? GetNextArticPart(Train::From(v)) : NULL;
 
				break;
 

	
 
			case VEH_ROAD:
 
				v = RoadVehicle::From(v)->RoadVehHasArticPart() ? v->Next() : NULL;
 
				v = RoadVehicle::From(v)->HasArticulatedPart() ? v->Next() : NULL;
 
				break;
 

	
 
			default:
 
				v = NULL;
 
				break;
 
		}
src/depot_gui.cpp
Show inline comments
 
@@ -857,13 +857,13 @@ struct DepotWindow : Window {
 
			for (const Vehicle *w = v; w != NULL; w = w->Next()) {
 
				if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) {
 
					capacity[w->cargo_type] += w->cargo_cap;
 
					loaded  [w->cargo_type] += w->cargo.Count();
 
				}
 

	
 
				if (w->type == VEH_TRAIN && !Train::From(w)->EngineHasArticPart()) {
 
				if (w->type == VEH_TRAIN && !Train::From(w)->HasArticulatedPart()) {
 
					num++;
 
					if (!whole_chain) break;
 
				}
 
			}
 

	
 
			/* Build tooltipstring */
src/roadstop.cpp
Show inline comments
 
@@ -37,13 +37,13 @@ RoadStop::~RoadStop()
 
RoadStop *RoadStop::GetNextRoadStop(const RoadVehicle *v) const
 
{
 
	for (RoadStop *rs = this->next; rs != NULL; rs = rs->next) {
 
		/* The vehicle cannot go to this roadstop (different roadtype) */
 
		if ((GetRoadTypes(rs->xy) & v->compatible_roadtypes) == ROADTYPES_NONE) continue;
 
		/* The vehicle is articulated and can therefor not go the a standard road stop */
 
		if (IsStandardRoadStopTile(rs->xy) && v->RoadVehHasArticPart()) continue;
 
		if (IsStandardRoadStopTile(rs->xy) && v->HasArticulatedPart()) continue;
 

	
 
		/* The vehicle can actually go to this road stop. So, return it! */
 
		return rs;
 
	}
 

	
 
	return NULL;
src/roadveh.h
Show inline comments
 
@@ -148,12 +148,12 @@ struct RoadVehicle : public SpecializedV
 
	FORCEINLINE void SetArticulatedPart() { this->subtype = RVST_ARTIC_PART; }
 

	
 
	/**
 
	 * Check if an engine has an articulated part.
 
	 * @return True if the engine has an articulated part.
 
	 */
 
	FORCEINLINE bool RoadVehHasArticPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
 
	FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
 
};
 

	
 
#define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)
 

	
 
#endif /* ROADVEH_H */
src/roadveh_cmd.cpp
Show inline comments
 
@@ -913,13 +913,13 @@ static void RoadVehCheckOvertake(RoadVeh
 
	if (v->roadtype == ROADTYPE_TRAM) return;
 

	
 
	/* Don't overtake in stations */
 
	if (IsTileType(v->tile, MP_STATION)) return;
 

	
 
	/* For now, articulated road vehicles can't overtake anything. */
 
	if (v->RoadVehHasArticPart()) return;
 
	if (v->HasArticulatedPart()) return;
 

	
 
	/* Vehicles are not driving in same direction || direction is not a diagonal direction */
 
	if (v->direction != u->direction || !(v->direction & 1)) return;
 

	
 
	/* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */
 
	if (v->state >= RVSB_IN_ROAD_STOP || !IsStraightRoadTrackdir((Trackdir)(v->state & RVSB_TRACKDIR_MASK))) return;
 
@@ -1024,13 +1024,13 @@ static Trackdir RoadFindPathToDest(RoadV
 
			/* Road depot owned by another company or with the wrong orientation */
 
			trackdirs = TRACKDIR_BIT_NONE;
 
		}
 
	} else if (IsTileType(tile, MP_STATION) && IsStandardRoadStopTile(tile)) {
 
		/* Standard road stop (drive-through stops are treated as normal road) */
 

	
 
		if (!IsTileOwner(tile, v->owner) || GetRoadStopDir(tile) == enterdir || v->RoadVehHasArticPart()) {
 
		if (!IsTileOwner(tile, v->owner) || GetRoadStopDir(tile) == enterdir || v->HasArticulatedPart()) {
 
			/* different station owner or wrong orientation or the vehicle has articulated parts */
 
			trackdirs = TRACKDIR_BIT_NONE;
 
		} else {
 
			/* Our station */
 
			RoadStopType rstype = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK;
 

	
src/roadveh_gui.cpp
Show inline comments
 
@@ -23,22 +23,22 @@
 
 * @param y     The y coordinate
 
 */
 
void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
 
{
 
	const RoadVehicle *rv = RoadVehicle::From(v);
 

	
 
	uint y_offset = rv->RoadVehHasArticPart() ? 15 : 0;
 
	uint y_offset = rv->HasArticulatedPart() ? 15 : 0;
 
	StringID str;
 
	Money feeder_share = 0;
 

	
 
	SetDParam(0, v->engine_type);
 
	SetDParam(1, v->build_year);
 
	SetDParam(2, v->value);
 
	DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE);
 

	
 
	if (rv->RoadVehHasArticPart()) {
 
	if (rv->HasArticulatedPart()) {
 
		CargoArray max_cargo;
 
		StringID subtype_text[NUM_CARGO];
 
		char capacity[512];
 

	
 
		memset(subtype_text, 0, sizeof(subtype_text));
 

	
src/saveload/afterload.cpp
Show inline comments
 
@@ -1867,13 +1867,13 @@ bool AfterLoadGame()
 
	if (CheckSavegameVersion(121)) {
 
		/* Delete small ufos heading for non-existing vehicles */
 
		Vehicle *v;
 
		FOR_ALL_DISASTERVEHICLES(v) {
 
			if (v->subtype == 2/*ST_SMALL_UFO*/ && v->current_order.GetDestination() != 0) {
 
				const Vehicle *u = Vehicle::GetIfValid(v->dest_tile);
 
				if (u == NULL || u->type != VEH_ROAD || !IsRoadVehFront(u)) {
 
				if (u == NULL || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsRoadVehFront()) {
 
					delete v;
 
				}
 
			}
 
		}
 

	
 
		/* We didn't store cargo payment yet, so make them for vehicles that are
src/station.cpp
Show inline comments
 
@@ -118,13 +118,13 @@ RoadStop *Station::GetPrimaryRoadStop(co
 
	RoadStop *rs = this->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK);
 

	
 
	for (; rs != NULL; rs = rs->next) {
 
		/* The vehicle cannot go to this roadstop (different roadtype) */
 
		if ((GetRoadTypes(rs->xy) & v->compatible_roadtypes) == ROADTYPES_NONE) continue;
 
		/* The vehicle is articulated and can therefor not go the a standard road stop */
 
		if (IsStandardRoadStopTile(rs->xy) && v->RoadVehHasArticPart()) continue;
 
		if (IsStandardRoadStopTile(rs->xy) && v->HasArticulatedPart()) continue;
 

	
 
		/* The vehicle can actually go to this road stop. So, return it! */
 
		break;
 
	}
 

	
 
	return rs;
src/station_cmd.cpp
Show inline comments
 
@@ -2567,13 +2567,13 @@ static VehicleEnterTileStatus VehicleEnt
 
					SetBit(rv->state, RVS_IN_DT_ROAD_STOP);
 
					return VETSB_CONTINUE;
 
				}
 

	
 
				/* For normal (non drive-through) road stops
 
				 * Check if station is busy or if there are no free bays or whether it is a articulated vehicle. */
 
				if (rs->IsEntranceBusy() || !rs->HasFreeBay() || rv->RoadVehHasArticPart()) return VETSB_CANNOT_ENTER;
 
				if (rs->IsEntranceBusy() || !rs->HasFreeBay() || rv->HasArticulatedPart()) return VETSB_CANNOT_ENTER;
 

	
 
				SetBit(rv->state, RVS_IN_ROAD_STOP);
 

	
 
				/* Allocate a bay and update the road state */
 
				uint bay_nr = rs->AllocateBay();
 
				SB(rv->state, RVS_USING_SECOND_BAY, 1, bay_nr);
src/train.h
Show inline comments
 
@@ -256,46 +256,46 @@ struct Train : public SpecializedVehicle
 
	FORCEINLINE bool IsArticulatedPart() const { return HasBit(this->subtype, TS_ARTICULATED_PART); }
 

	
 
	/**
 
	 * Check if an engine has an articulated part.
 
	 * @return True if the engine has an articulated part.
 
	 */
 
	FORCEINLINE bool EngineHasArticPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
 
	FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
 

	
 
};
 

	
 
#define FOR_ALL_TRAINS(var) FOR_ALL_VEHICLES_OF_TYPE(Train, var)
 

	
 
/**
 
 * Get the next part of a multi-part engine.
 
 * Will only work on a multi-part engine (v->EngineHasArticPart() == true),
 
 * Will only work on a multi-part engine (v->HasArticulatedPart() == true),
 
 * Result is undefined for normal engine.
 
 */
 
static inline Train *GetNextArticPart(const Train *v)
 
{
 
	assert(v->EngineHasArticPart());
 
	assert(v->HasArticulatedPart());
 
	return v->Next();
 
}
 

	
 
/** Get the last part of a multi-part engine.
 
 * @param v Vehicle.
 
 * @return Last part of the engine.
 
 */
 
static inline Train *GetLastEnginePart(Train *v)
 
{
 
	while (v->EngineHasArticPart()) v = GetNextArticPart(v);
 
	while (v->HasArticulatedPart()) v = GetNextArticPart(v);
 
	return v;
 
}
 

	
 
/** Get the next real (non-articulated part) vehicle in the consist.
 
 * @param v Vehicle.
 
 * @return Next vehicle in the consist.
 
 */
 
static inline Train *GetNextVehicle(const Train *v)
 
{
 
	while (v->EngineHasArticPart()) v = GetNextArticPart(v);
 
	while (v->HasArticulatedPart()) v = GetNextArticPart(v);
 

	
 
	/* v now contains the last artic part in the engine */
 
	return v->Next();
 
}
 

	
 
/** Get the previous real (non-articulated part) vehicle in the consist.
src/vehicle_cmd.cpp
Show inline comments
 
@@ -434,15 +434,15 @@ CommandCost CmdCloneVehicle(TileIndex ti
 

	
 
				if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_subtype) {
 
					CommandCost cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v));
 
					if (CmdSucceeded(cost)) total_cost.AddCost(cost);
 
				}
 

	
 
				if (w->type == VEH_TRAIN && Train::From(w)->EngineHasArticPart()) {
 
				if (w->type == VEH_TRAIN && Train::From(w)->HasArticulatedPart()) {
 
					w = GetNextArticPart(Train::From(w));
 
				} else if (w->type == VEH_ROAD && RoadVehicle::From(w)->RoadVehHasArticPart()) {
 
				} else if (w->type == VEH_ROAD && RoadVehicle::From(w)->HasArticulatedPart()) {
 
					w = w->Next();
 
				} else {
 
					break;
 
				}
 
			} else {
 
				const Engine *e = Engine::Get(v->engine_type);
 
@@ -450,15 +450,15 @@ CommandCost CmdCloneVehicle(TileIndex ti
 

	
 
				if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) {
 
					total_cost.AddCost(GetRefitCost(v->engine_type));
 
				}
 
			}
 

	
 
			if (v->type == VEH_TRAIN && Train::From(v)->EngineHasArticPart()) {
 
			if (v->type == VEH_TRAIN && Train::From(v)->HasArticulatedPart()) {
 
				v = GetNextArticPart(Train::From(v));
 
			} else if (v->type == VEH_ROAD && RoadVehicle::From(v)->RoadVehHasArticPart()) {
 
			} else if (v->type == VEH_ROAD && RoadVehicle::From(v)->HasArticulatedPart()) {
 
				v = v->Next();
 
			} else {
 
				break;
 
			}
 
		} while (v != NULL);
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -1352,13 +1352,13 @@ struct VehicleDetailsWindow : Window {
 
				this->widget[VLD_WIDGET_RENAME_VEHICLE].tooltips = STR_VEHICLE_DETAILS_TRAIN_RENAME;
 
				break;
 

	
 
			case VEH_ROAD: {
 
				this->widget[VLD_WIDGET_RENAME_VEHICLE].tooltips = STR_QUERY_RENAME_ROAD_CAPTION;
 

	
 
				if (!RoadVehicle::From(v)->RoadVehHasArticPart()) break;
 
				if (!RoadVehicle::From(v)->HasArticulatedPart()) break;
 

	
 
				/* Draw the text under the vehicle instead of next to it, minus the
 
				 * height already allocated for the cargo of the first vehicle. */
 
				uint height_extension = 15 - 11;
 

	
 
				/* Add space for the cargo amount for each part. */
0 comments (0 inline, 0 general)