Changeset - r11986:6596046384a5
[Not reviewed]
master
0 8 0
rubidium - 15 years ago 2009-05-23 12:27:42
rubidium@openttd.org
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
8 files changed with 60 insertions and 51 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_order.cpp
Show inline comments
 
@@ -60,7 +60,7 @@ static const Order *ResolveOrder(Vehicle
 
		order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
 
		if (order_position == AIOrder::ORDER_INVALID) return NULL;
 
	}
 
	return ::GetVehicleOrder(v, order_position);
 
	return v->GetOrder(order_position);
 
}
 

	
 
/* static */ bool AIOrder::IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position)
 
@@ -92,7 +92,7 @@ static const Order *ResolveOrder(Vehicle
 
	if (order_position == ORDER_CURRENT) return false;
 
	if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
 

	
 
	const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
 
	const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
 
	return order->GetType() == OT_CONDITIONAL;
 
}
 

	
 
@@ -236,7 +236,7 @@ static const Order *ResolveOrder(Vehicle
 
	if (!IsValidVehicleOrder(vehicle_id, order_position)) return ORDER_INVALID;
 
	if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return ORDER_INVALID;
 

	
 
	const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
 
	const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
 
	return (OrderPosition)order->GetConditionSkipToOrder();
 
}
 

	
 
@@ -245,7 +245,7 @@ static const Order *ResolveOrder(Vehicle
 
	if (!IsValidVehicleOrder(vehicle_id, order_position)) return OC_INVALID;
 
	if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return OC_INVALID;
 

	
 
	const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
 
	const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
 
	return (OrderCondition)order->GetConditionVariable();
 
}
 

	
 
@@ -254,7 +254,7 @@ static const Order *ResolveOrder(Vehicle
 
	if (!IsValidVehicleOrder(vehicle_id, order_position)) return CF_INVALID;
 
	if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return CF_INVALID;
 

	
 
	const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
 
	const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
 
	return (CompareFunction)order->GetConditionComparator();
 
}
 

	
 
@@ -263,7 +263,7 @@ static const Order *ResolveOrder(Vehicle
 
	if (!IsValidVehicleOrder(vehicle_id, order_position)) return -1;
 
	if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return -1;
 

	
 
	const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
 
	const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
 
	int32 value = order->GetConditionValue();
 
	if (order->GetConditionVariable() == OCV_MAX_SPEED) value = value * 16 / 10;
 
	return value;
 
@@ -432,7 +432,7 @@ static void _DoCommandReturnSetOrderFlag
 
	EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
 
	EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags));
 

	
 
	const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
 
	const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
 

	
 
	AIOrderFlags current = GetOrderFlags(vehicle_id, order_position);
 

	
src/order_cmd.cpp
Show inline comments
 
@@ -398,7 +398,7 @@ static uint GetOrderDistance(const Order
 

	
 
		conditional_depth++;
 

	
 
		int dist1 = GetOrderDistance(prev, GetVehicleOrder(v, cur->GetConditionSkipToOrder()), v, conditional_depth);
 
		int dist1 = GetOrderDistance(prev, v->GetOrder(cur->GetConditionSkipToOrder()), v, conditional_depth);
 
		int dist2 = GetOrderDistance(prev, cur->next == NULL ? v->orders.list->GetFirstOrder() : cur->next, v, conditional_depth);
 
		return max(dist1, dist2);
 
	}
 
@@ -668,7 +668,7 @@ CommandCost CmdDeleteOrder(TileIndex til
 
	if (sel_ord >= v->GetNumOrders())
 
		return DecloneOrder(v, flags);
 

	
 
	order = GetVehicleOrder(v, sel_ord);
 
	order = v->GetOrder(sel_ord);
 
	if (order == NULL) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -772,7 +772,7 @@ CommandCost CmdMoveOrder(TileIndex tile,
 
			moving_order == target_order || v->GetNumOrders() <= 1)
 
		return CMD_ERROR;
 

	
 
	Order *moving_one = GetVehicleOrder(v, moving_order);
 
	Order *moving_one = v->GetOrder(moving_order);
 
	/* Don't move an empty order */
 
	if (moving_one == NULL) return CMD_ERROR;
 

	
 
@@ -849,7 +849,7 @@ CommandCost CmdModifyOrder(TileIndex til
 
	/* Is it a valid order? */
 
	if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
 

	
 
	Order *order = GetVehicleOrder(v, sel_ord);
 
	Order *order = v->GetOrder(sel_ord);
 
	switch (order->GetType()) {
 
		case OT_GOTO_STATION:
 
			if (mof == MOF_COND_VARIABLE || mof == MOF_COND_COMPARATOR || mof == MOF_DEPOT_ACTION || mof == MOF_COND_VALUE || Station::Get(order->GetDestination())->IsBuoy()) return CMD_ERROR;
 
@@ -1191,7 +1191,7 @@ CommandCost CmdOrderRefit(TileIndex tile
 
	const Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	Order *order = GetVehicleOrder(v, order_number);
 
	Order *order = v->GetOrder(order_number);
 
	if (order == NULL) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -1412,7 +1412,7 @@ void CheckOrders(const Vehicle *v)
 

	
 
		/* Check if the last and the first order are the same */
 
		if (v->GetNumOrders() > 1) {
 
			const Order *last = GetLastVehicleOrder(v);
 
			const Order *last = v->GetLastOrder();
 

	
 
			if (v->orders.list->GetFirstOrder()->Equals(*last)) {
 
				problem_type = 2;
 
@@ -1648,7 +1648,7 @@ bool UpdateOrderDest(Vehicle *v, const O
 
			if (next_order != INVALID_VEH_ORDER_ID) {
 
				UpdateVehicleTimetable(v, false);
 
				v->cur_order_index = next_order;
 
				v->current_order_time += GetVehicleOrder(v, next_order)->travel_time;
 
				v->current_order_time += v->GetOrder(next_order)->travel_time;
 
			} else {
 
				UpdateVehicleTimetable(v, true);
 
				v->IncrementOrderIndex();
 
@@ -1657,7 +1657,7 @@ bool UpdateOrderDest(Vehicle *v, const O
 
			assert(v->cur_order_index < v->GetNumOrders());
 

	
 
			/* Get the current order */
 
			const Order *order = GetVehicleOrder(v, v->cur_order_index);
 
			const Order *order = v->GetOrder(v->cur_order_index);
 
			v->current_order = *order;
 
			return UpdateOrderDest(v, order, conditional_depth + 1);
 
		}
 
@@ -1726,7 +1726,7 @@ bool ProcessOrders(Vehicle *v)
 
	/* Get the current order */
 
	if (v->cur_order_index >= v->GetNumOrders()) v->cur_order_index = 0;
 

	
 
	const Order *order = GetVehicleOrder(v, v->cur_order_index);
 
	const Order *order = v->GetOrder(v->cur_order_index);
 

	
 
	/* If no order, do nothing. */
 
	if (order == NULL || (v->type == VEH_AIRCRAFT && order->IsType(OT_DUMMY) && !CheckForValidOrders(v))) {
src/order_gui.cpp
Show inline comments
 
@@ -470,7 +470,7 @@ private:
 
	static void OrderClick_FullLoad(OrdersWindow *w, int load_type)
 
	{
 
		VehicleOrderID sel_ord = w->OrderGetSel();
 
		const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
 
		const Order *order = w->vehicle->GetOrder(sel_ord);
 

	
 
		if (order == NULL || order->GetLoadType() == load_type) return;
 

	
 
@@ -490,7 +490,7 @@ private:
 
		VehicleOrderID sel_ord = w->OrderGetSel();
 

	
 
		if (i < 0) {
 
			const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
 
			const Order *order = w->vehicle->GetOrder(sel_ord);
 
			if (order == NULL) return;
 
			i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
 
		}
 
@@ -535,7 +535,7 @@ private:
 
	static void OrderClick_Unload(OrdersWindow *w, int unload_type)
 
	{
 
		VehicleOrderID sel_ord = w->OrderGetSel();
 
		const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
 
		const Order *order = w->vehicle->GetOrder(sel_ord);
 

	
 
		if (order == NULL || order->GetUnloadType() == unload_type) return;
 

	
 
@@ -555,7 +555,7 @@ private:
 
	static void OrderClick_Nonstop(OrdersWindow *w, int non_stop)
 
	{
 
		VehicleOrderID sel_ord = w->OrderGetSel();
 
		const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
 
		const Order *order = w->vehicle->GetOrder(sel_ord);
 

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

	
 
@@ -711,7 +711,7 @@ public:
 
		SetVScrollCount(this, this->vehicle->GetNumOrders() + 1);
 

	
 
		int sel = OrderGetSel();
 
		const Order *order = GetVehicleOrder(this->vehicle, sel);
 
		const Order *order = this->vehicle->GetOrder(sel);
 

	
 
		if (this->vehicle->owner == _local_company) {
 
			/* Set the strings for the dropdown boxes. */
 
@@ -824,7 +824,7 @@ public:
 
		int y = 15;
 

	
 
		int i = this->vscroll.pos;
 
		order = GetVehicleOrder(this->vehicle, i);
 
		order = this->vehicle->GetOrder(i);
 
		StringID str;
 
		while (order != NULL) {
 
			/* Don't draw anything if it extends past the end of the window. */
 
@@ -852,7 +852,7 @@ public:
 
				int sel = this->GetOrderFromPt(pt.y);
 

	
 
				if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
 
					const Order *ord = GetVehicleOrder(this->vehicle, sel);
 
					const Order *ord = this->vehicle->GetOrder(sel);
 
					TileIndex xy = INVALID_TILE;
 

	
 
					switch (ord->GetType()) {
 
@@ -880,7 +880,7 @@ public:
 
				} else if (sel == this->selected_order) {
 
					if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
 
						DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16),
 
								MOF_STOP_LOCATION | ((GetVehicleOrder(this->vehicle, sel)->GetStopLocation() + 1) % OSL_END) << 4,
 
								MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
 
								CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
 
					}
 
				} else {
 
@@ -909,7 +909,7 @@ public:
 
				break;
 

	
 
			case ORDER_WIDGET_NON_STOP_DROPDOWN: {
 
				const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
 
				const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
 
				ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), ORDER_WIDGET_NON_STOP_DROPDOWN, 0, o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
 
			} break;
 

	
 
@@ -926,7 +926,7 @@ public:
 
				break;
 

	
 
			case ORDER_WIDGET_FULL_LOAD_DROPDOWN:
 
				ShowDropDownMenu(this, _order_full_load_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD_DROPDOWN, 0, 2);
 
				ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD_DROPDOWN, 0, 2);
 
				break;
 

	
 
			case ORDER_WIDGET_UNLOAD:
 
@@ -934,7 +934,7 @@ public:
 
				break;
 

	
 
			case ORDER_WIDGET_UNLOAD_DROPDOWN:
 
				ShowDropDownMenu(this, _order_unload_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD_DROPDOWN, 0, 8);
 
				ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD_DROPDOWN, 0, 8);
 
				break;
 

	
 
			case ORDER_WIDGET_REFIT:
 
@@ -946,7 +946,7 @@ public:
 
				break;
 

	
 
			case ORDER_WIDGET_SERVICE_DROPDOWN:
 
				ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(GetVehicleOrder(this->vehicle, this->OrderGetSel())), ORDER_WIDGET_SERVICE_DROPDOWN, 0, 0);
 
				ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), ORDER_WIDGET_SERVICE_DROPDOWN, 0, 0);
 
				break;
 

	
 
			case ORDER_WIDGET_TIMETABLE_VIEW:
 
@@ -954,16 +954,16 @@ public:
 
				break;
 

	
 
			case ORDER_WIDGET_COND_VARIABLE:
 
				ShowDropDownMenu(this, _order_conditional_variable, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
 
				ShowDropDownMenu(this, _order_conditional_variable, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
 
				break;
 

	
 
			case ORDER_WIDGET_COND_COMPARATOR: {
 
				const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
 
				const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
 
				ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
 
			} break;
 

	
 
			case ORDER_WIDGET_COND_VALUE: {
 
				const Order *order = GetVehicleOrder(this->vehicle, this->OrderGetSel());
 
				const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
 
				uint value = order->GetConditionValue();
 
				if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
 
				SetDParam(0, value);
 
@@ -982,7 +982,7 @@ public:
 
			VehicleOrderID sel = this->OrderGetSel();
 
			uint value = atoi(str);
 

	
 
			switch (GetVehicleOrder(this->vehicle, sel)->GetConditionVariable()) {
 
			switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
 
				case OCV_MAX_SPEED:
 
					value = ConvertDisplaySpeedToSpeed(value);
 
					break;
src/timetable_cmd.cpp
Show inline comments
 
@@ -13,7 +13,7 @@
 

	
 
static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 time, bool is_journey)
 
{
 
	Order *order = GetVehicleOrder(v, order_number);
 
	Order *order = v->GetOrder(order_number);
 
	int delta;
 

	
 
	if (is_journey) {
 
@@ -62,7 +62,7 @@ CommandCost CmdChangeTimetable(TileIndex
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	VehicleOrderID order_number = GB(p1, 16, 8);
 
	Order *order = GetVehicleOrder(v, order_number);
 
	Order *order = v->GetOrder(order_number);
 
	if (order == NULL) return CMD_ERROR;
 

	
 
	bool packed_time = HasBit(p1, 25);
src/timetable_gui.cpp
Show inline comments
 
@@ -146,7 +146,7 @@ struct TimetableWindow : Window {
 
		if (v->owner == _local_company) {
 
			bool disable = true;
 
			if (selected != -1) {
 
				const Order *order = GetVehicleOrder(v, ((selected + 1) / 2) % v->GetNumOrders());
 
				const Order *order = v->GetOrder(((selected + 1) / 2) % v->GetNumOrders());
 
				if (selected % 2 == 1) {
 
					disable = order != NULL && order->IsType(OT_CONDITIONAL);
 
				} else {
 
@@ -176,7 +176,7 @@ struct TimetableWindow : Window {
 
		VehicleOrderID order_id = (i + 1) / 2;
 
		bool final_order = false;
 

	
 
		const Order *order = GetVehicleOrder(v, order_id);
 
		const Order *order = v->GetOrder(order_id);
 

	
 
		while (order != NULL) {
 
			/* Don't draw anything if it extends past the end of the window. */
 
@@ -188,7 +188,7 @@ struct TimetableWindow : Window {
 
				order_id++;
 

	
 
				if (order_id >= v->GetNumOrders()) {
 
					order = GetVehicleOrder(v, 0);
 
					order = v->GetOrder(0);
 
					final_order = true;
 
				} else {
 
					order = order->next;
 
@@ -220,7 +220,7 @@ struct TimetableWindow : Window {
 
			uint total_time = 0;
 
			bool complete = true;
 

	
 
			for (const Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) {
 
			for (const Order *order = v->GetOrder(0); order != NULL; order = order->next) {
 
				total_time += order->travel_time + order->wait_time;
 
				if (order->travel_time == 0 && !order->IsType(OT_CONDITIONAL)) complete = false;
 
				if (order->wait_time == 0 && order->IsType(OT_GOTO_STATION) && !(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) complete = false;
 
@@ -273,7 +273,7 @@ struct TimetableWindow : Window {
 

	
 
				if (real >= v->GetNumOrders()) real = 0;
 

	
 
				const Order *order = GetVehicleOrder(v, real);
 
				const Order *order = v->GetOrder(real);
 
				StringID current = STR_EMPTY;
 

	
 
				if (order != NULL) {
src/train_cmd.cpp
Show inline comments
 
@@ -2868,7 +2868,7 @@ public:
 
			/* Wrap around. */
 
			if (this->index >= this->v->GetNumOrders()) this->index = 0;
 

	
 
			Order *order = GetVehicleOrder(this->v, this->index);
 
			Order *order = this->v->GetOrder(this->index);
 
			assert(order != NULL);
 

	
 
			switch (order->GetType()) {
src/vehicle.cpp
Show inline comments
 
@@ -1021,7 +1021,7 @@ void VehicleEnterDepot(Vehicle *v)
 
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 

	
 
		const Order *real_order = GetVehicleOrder(v, v->cur_order_index);
 
		const Order *real_order = v->GetOrder(v->cur_order_index);
 
		Order t = v->current_order;
 
		v->current_order.MakeDummy();
 

	
src/vehicle_base.h
Show inline comments
 
@@ -470,6 +470,25 @@ public:
 
		if (this->cur_order_index >= this->GetNumOrders()) this->cur_order_index = 0;
 
		InvalidateVehicleOrder(this, 0);
 
	}
 

	
 
	/**
 
	 * Returns order 'index' of a vehicle or NULL when it doesn't exists
 
	 * @param index the order to fetch
 
	 * @return the found (or not) order
 
	 */
 
	inline Order *GetOrder(int index) const
 
	{
 
		return (this->orders.list == NULL) ? NULL : this->orders.list->GetOrderAt(index);
 
	}
 

	
 
	/**
 
	 * Returns the last order of a vehicle, or NULL if it doesn't exists
 
	 * @return last order of a vehicle, if available
 
	 */
 
	inline Order *GetLastOrder() const
 
	{
 
		return (this->orders.list == NULL) ? NULL : this->orders.list->GetLastOrder();
 
	}
 
};
 

	
 
/**
 
@@ -520,16 +539,6 @@ struct FreeUnitIDGenerator {
 
	~FreeUnitIDGenerator() { free(this->cache); }
 
};
 

	
 
/* Returns order 'index' of a vehicle or NULL when it doesn't exists */
 
static inline Order *GetVehicleOrder(const Vehicle *v, int index) { return (v->orders.list == NULL) ? NULL : v->orders.list->GetOrderAt(index); }
 

	
 
/**
 
 * Returns the last order of a vehicle, or NULL if it doesn't exists
 
 * @param v Vehicle to query
 
 * @return last order of a vehicle, if available
 
 */
 
static inline Order *GetLastVehicleOrder(const Vehicle *v) { return (v->orders.list == NULL) ? NULL : v->orders.list->GetLastOrder(); }
 

	
 
void CheckVehicle32Day(Vehicle *v);
 

	
 
static const int32 INVALID_COORD = 0x7fffffff;
0 comments (0 inline, 0 general)