Changeset - r16773:b3301f1d5bbb
[Not reviewed]
master
0 9 0
terkhen - 14 years ago 2010-12-14 21:26:03
terkhen@openttd.org
(svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
9 files changed with 27 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/depot_gui.cpp
Show inline comments
 
@@ -302,13 +302,13 @@ struct DepotWindow : Window {
 
				break;
 
			}
 
			default: NOT_REACHED();
 
		}
 

	
 
		uint diff_x, diff_y;
 
		if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
 
		if (v->IsGroundVehicle()) {
 
			/* Arrange unitnumber and flag horizontally */
 
			diff_x = this->flag_width + WD_FRAMERECT_LEFT;
 
			diff_y = (this->resize.step_height - this->flag_height) / 2 - 2;
 
		} else {
 
			/* Arrange unitnumber and flag vertically */
 
			diff_x = WD_FRAMERECT_LEFT;
src/disaster_cmd.cpp
Show inline comments
 
@@ -503,13 +503,13 @@ static bool DisasterTick_Big_Ufo(Disaste
 
		}
 

	
 
		v->current_order.SetDestination(2);
 

	
 
		Vehicle *target;
 
		FOR_ALL_VEHICLES(target) {
 
			if (target->type == VEH_TRAIN || target->type == VEH_ROAD) {
 
			if (target->IsGroundVehicle()) {
 
				if (Delta(target->x_pos, v->x_pos) + Delta(target->y_pos, v->y_pos) <= 12 * (int)TILE_SIZE) {
 
					target->breakdown_ctr = 5;
 
					target->breakdown_delay = 0xF0;
 
				}
 
			}
 
		}
src/newgrf_engine.cpp
Show inline comments
 
@@ -608,13 +608,13 @@ static uint32 VehicleGetVariable(const R
 
		case 0x45: { // Curvature info
 
			/* Format: xxxTxBxF
 
			 * F - previous wagon to current wagon, 0 if vehicle is first
 
			 * B - current wagon to next wagon, 0 if wagon is last
 
			 * T - previous wagon to next wagon, 0 in an S-bend
 
			 */
 
			if (v->type != VEH_TRAIN && v->type != VEH_ROAD) return 0;
 
			if (!v->IsGroundVehicle()) return 0;
 

	
 
			const Vehicle *u_p = v->Previous();
 
			const Vehicle *u_n = v->Next();
 
			DirDiff f = (u_p == NULL) ?  DIRDIFF_SAME : DirDifference(u_p->direction, v->direction);
 
			DirDiff b = (u_n == NULL) ?  DIRDIFF_SAME : DirDifference(v->direction, u_n->direction);
 
			DirDiff t = ChangeDirDiff(f, b);
src/order_cmd.cpp
Show inline comments
 
@@ -482,14 +482,14 @@ CommandCost CmdInsertOrder(TileIndex til
 

	
 
			if (!CanVehicleUseStation(v, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
 
			for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
 
				if (!CanVehicleUseStation(u, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER_SHARED);
 
			}
 

	
 
			/* Non stop not allowed for non-trains. */
 
			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
 
			/* Non stop only allowed for ground vehicles. */
 
			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
 

	
 
			/* No load and no unload are mutual exclusive. */
 
			if ((new_order.GetLoadType() & OLFB_NO_LOAD) && (new_order.GetUnloadType() & OUFB_NO_UNLOAD)) return CMD_ERROR;
 

	
 
			/* Filter invalid load/unload types. */
 
			switch (new_order.GetLoadType()) {
 
@@ -553,13 +553,13 @@ CommandCost CmdInsertOrder(TileIndex til
 

	
 
						default: return CMD_ERROR;
 
					}
 
				}
 
			}
 

	
 
			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
 
			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
 
			if (new_order.GetDepotOrderType() & ~(ODTFB_PART_OF_ORDERS | ((new_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0 ? ODTFB_SERVICE : 0))) return CMD_ERROR;
 
			if (new_order.GetDepotActionType() & ~(ODATFB_HALT | ODATFB_NEAREST_DEPOT)) return CMD_ERROR;
 
			if ((new_order.GetDepotOrderType() & ODTFB_SERVICE) && (new_order.GetDepotActionType() & ODATFB_HALT)) return CMD_ERROR;
 
			break;
 
		}
 

	
 
@@ -970,13 +970,13 @@ CommandCost CmdModifyOrder(TileIndex til
 
	}
 

	
 
	switch (mof) {
 
		default: NOT_REACHED();
 

	
 
		case MOF_NON_STOP:
 
			if (v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
 
			if (!v->IsGroundVehicle()) return CMD_ERROR;
 
			if (data >= ONSF_END) return CMD_ERROR;
 
			if (data == order->GetNonStopType()) return CMD_ERROR;
 
			break;
 

	
 
		case MOF_STOP_LOCATION:
 
			if (v->type != VEH_TRAIN) return CMD_ERROR;
src/order_gui.cpp
Show inline comments
 
@@ -213,13 +213,13 @@ void DrawOrderString(const Vehicle *v, c
 

	
 
		case OT_GOTO_STATION: {
 
			OrderLoadFlags load = order->GetLoadType();
 
			OrderUnloadFlags unload = order->GetUnloadType();
 

	
 
			SetDParam(0, STR_ORDER_GO_TO_STATION);
 
			SetDParam(1, STR_ORDER_GO_TO + ((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? order->GetNonStopType() : 0));
 
			SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
 
			SetDParam(2, order->GetDestination());
 

	
 
			if (timetable) {
 
				SetDParam(3, STR_EMPTY);
 

	
 
				if (order->wait_time > 0) {
 
@@ -379,13 +379,13 @@ static Order GetOrderCmdFromTile(const V
 
			(facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
 
			(facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
 
			(facil = FACIL_TRUCK_STOP, 1);
 
			if (st->facilities & facil) {
 
				order.MakeGoToStation(st_index);
 
				if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
 
				if (_settings_client.gui.new_nonstop && (v->type == VEH_TRAIN || v->type == VEH_ROAD)) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
 
				if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
 
				order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
 
				return order;
 
			}
 
		}
 
	}
 

	
 
@@ -569,13 +569,13 @@ private:
 
	void OrderClick_NearestDepot(int i)
 
	{
 
		Order order;
 
		order.next = NULL;
 
		order.index = 0;
 
		order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
 
				_settings_client.gui.new_nonstop && (this->vehicle->type == VEH_TRAIN || this->vehicle->type == VEH_ROAD) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
 
				_settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
 
		order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
 

	
 
		DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
 
	}
 

	
 
	/**
 
@@ -644,13 +644,13 @@ private:
 
	/**
 
	 * Handle the click on the nonstop button.
 
	 * @param non_stop what non-stop type to use; -1 to use the 'next' one.
 
	 */
 
	void OrderClick_Nonstop(int non_stop)
 
	{
 
		if (this->vehicle->type != VEH_TRAIN && this->vehicle->type != VEH_ROAD) return;
 
		if (!this->vehicle->IsGroundVehicle()) return;
 

	
 
		VehicleOrderID sel_ord = this->OrderGetSel();
 
		const Order *order = this->vehicle->GetOrder(sel_ord);
 

	
 
		if (order == NULL || order->GetNonStopType() == non_stop) return;
 

	
 
@@ -1602,9 +1602,9 @@ void ShowOrdersWindow(const Vehicle *v)
 
	DeleteWindowById(WC_VEHICLE_TIMETABLE, v->index, false);
 
	if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
 

	
 
	if (v->owner != _local_company) {
 
		new OrdersWindow(&_other_orders_desc, v);
 
	} else {
 
		new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
 
		new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
 
	}
 
}
src/pathfinder/npf/npf.cpp
Show inline comments
 
@@ -1098,13 +1098,13 @@ static void NPFFillWithOrderData(NPFFind
 
	 * save the station id for ships. For roadvehs we don't store it either,
 
	 * because multistop depends on vehicles actually reaching the exact
 
	 * dest_tile, not just any stop of that station.
 
	 * So only for train orders to stations we fill fstd->station_index, for all
 
	 * others only dest_coords */
 
	if (v->type != VEH_SHIP && (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_WAYPOINT))) {
 
		assert(v->type == VEH_TRAIN || v->type == VEH_ROAD);
 
		assert(v->IsGroundVehicle());
 
		fstd->station_index = v->current_order.GetDestination();
 
		fstd->station_type = (v->type == VEH_TRAIN) ? (v->current_order.IsType(OT_GOTO_STATION) ? STATION_RAIL : STATION_WAYPOINT) : (RoadVehicle::From(v)->IsBus() ? STATION_BUS : STATION_TRUCK);
 
		fstd->not_articulated = v->type == VEH_ROAD && !RoadVehicle::From(v)->HasArticulatedPart();
 
		/* Let's take the closest tile of the station as our target for vehicles */
 
		fstd->dest_coords = CalcClosestStationTile(fstd->station_index, v->tile, fstd->station_type);
 
	} else {
src/saveload/afterload.cpp
Show inline comments
 
@@ -1022,13 +1022,13 @@ bool AfterLoadGame()
 
					_m[t].m5 = 1 << 7 | type << 2 | dir;
 
				}
 
			}
 
		}
 

	
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue;
 
			if (!v->IsGroundVehicle()) continue;
 
			if (IsBridgeTile(v->tile)) {
 
				DiagDirection dir = GetTunnelBridgeDirection(v->tile);
 

	
 
				if (dir != DirToDiagDir(v->direction)) continue;
 
				switch (dir) {
 
					default: SlErrorCorrupt("Invalid vehicle direction");
src/vehicle_base.h
Show inline comments
 
@@ -357,12 +357,21 @@ public:
 
		for (Vehicle *u = this; u != NULL; u = u->Next()) {
 
			u->InvalidateNewGRFCache();
 
		}
 
	}
 

	
 
	/**
 
	 * Check if the vehicle is a ground vehicle.
 
	 * @return True iff the vehicle is a train or a road vehicle.
 
	 */
 
	FORCEINLINE bool IsGroundVehicle() const
 
	{
 
		return this->type == VEH_TRAIN || this->type == VEH_ROAD;
 
	}
 

	
 
	/**
 
	 * Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
 
	 * @return the vehicle's speed
 
	 */
 
	virtual int GetDisplaySpeed() const { return 0; }
 

	
 
	/**
src/vehicle_gui.cpp
Show inline comments
 
@@ -432,13 +432,13 @@ struct RefitWindow : public Window {
 
					option.value   = CALLBACK_FAILED;
 
					option.engine  = INVALID_ENGINE;
 
					this->list[current_index].Include(option);
 
				}
 
				current_index++;
 
			}
 
		} while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL);
 
		} while (v->IsGroundVehicle() && (v = v->Next()) != NULL);
 

	
 
		int scroll_size = 0;
 
		for (uint i = 0; i < NUM_CARGO; i++) {
 
			scroll_size += (this->list[i].Length());
 
		}
 
		this->vscroll->SetCount(scroll_size);
 
@@ -2030,13 +2030,13 @@ void StartStopVehicle(const Vehicle *v, 
 
static bool IsVehicleRefitable(const Vehicle *v)
 
{
 
	if (!v->IsStoppedInDepot()) return false;
 

	
 
	do {
 
		if (IsEngineRefittable(v->engine_type)) return true;
 
	} while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL);
 
	} while (v->IsGroundVehicle() && (v = v->Next()) != NULL);
 

	
 
	return false;
 
}
 

	
 
/** Window manager class for viewing a vehicle. */
 
struct VehicleViewWindow : Window {
 
@@ -2308,13 +2308,13 @@ public:
 
			case VVW_WIDGET_CLONE_VEH: // clone vehicle
 
				DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0,
 
										_vehicle_command_translation_table[VCT_CMD_CLONE_VEH][v->type],
 
										CcCloneVehicle);
 
				break;
 
			case VVW_WIDGET_TURN_AROUND: // turn around
 
				assert(v->type == VEH_TRAIN || v->type == VEH_ROAD);
 
				assert(v->IsGroundVehicle());
 
				DoCommandP(v->tile, v->index, 0,
 
										_vehicle_command_translation_table[VCT_CMD_TURN_AROUND][v->type]);
 
				break;
 
			case VVW_WIDGET_FORCE_PROCEED: // force proceed
 
				assert(v->type == VEH_TRAIN);
 
				DoCommandP(v->tile, v->index, 0, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_ERROR_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
 
@@ -2342,13 +2342,13 @@ public:
 
		NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(VVW_WIDGET_SELECT_DEPOT_CLONE); // Selection widget 'send to depot' / 'clone'.
 
		if (nwi->shown_plane + SEL_DC_BASEPLANE != plane) {
 
			this->SelectPlane(plane);
 
			this->SetWidgetDirty(VVW_WIDGET_SELECT_DEPOT_CLONE);
 
		}
 
		/* The same system applies to widget VVW_WIDGET_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/
 
		if (v->type == VEH_ROAD || v->type == VEH_TRAIN) {
 
		if (v->IsGroundVehicle()) {
 
			PlaneSelections plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND;
 
			NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(VVW_WIDGET_SELECT_REFIT_TURN);
 
			if (nwi->shown_plane + SEL_RT_BASEPLANE != plane) {
 
				this->SelectPlane(plane);
 
				this->SetWidgetDirty(VVW_WIDGET_SELECT_REFIT_TURN);
 
			}
0 comments (0 inline, 0 general)