src/vehicle.cpp
branchnoai
changeset 9869 6404afe43575
parent 9837 c9ec4f82e0d0
child 10142 56ee7da4ad56
--- a/src/vehicle.cpp	Sun Apr 06 14:12:19 2008 +0000
+++ b/src/vehicle.cpp	Sun Apr 06 23:07:42 2008 +0000
@@ -120,10 +120,10 @@
 bool VehicleNeedsService(const Vehicle *v)
 {
 	if (v->vehstatus & (VS_STOPPED | VS_CRASHED))       return false;
-	if (v->current_order.type != OT_GOTO_DEPOT || !(v->current_order.flags & OFB_PART_OF_ORDERS)) { // Don't interfere with a depot visit by the order list
+	if (!v->current_order.IsType(OT_GOTO_DEPOT) || !(v->current_order.GetDepotOrderType() & OFB_PART_OF_ORDERS)) { // Don't interfere with a depot visit by the order list
 		if (_patches.gotodepot && VehicleHasDepotOrders(v)) return false;
-		if (v->current_order.type == OT_LOADING)            return false;
-		if (v->current_order.type == OT_GOTO_DEPOT && v->current_order.flags & OFB_HALT_IN_DEPOT) return false;
+		if (v->current_order.IsType(OT_LOADING))            return false;
+		if (v->current_order.IsType(OT_GOTO_DEPOT) && v->current_order.GetDepotActionType() & OFB_HALT_IN_DEPOT) return false;
 	}
 
 	if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) {
@@ -631,7 +631,7 @@
 {
 	/* We need to set v->leave_depot_instantly as we have no control of it's contents at this time.
 	 * Vehicle should stop in the depot if it was in 'stopping' state - train intered depot while slowing down. */
-	if ((HasBit(v->current_order.flags, OF_HALT_IN_DEPOT) && !HasBit(v->current_order.flags, OF_PART_OF_ORDERS) && v->current_order.type == OT_GOTO_DEPOT) ||
+	if ((HasBit(v->current_order.GetDepotActionType(), OF_HALT_IN_DEPOT) && !HasBit(v->current_order.GetDepotOrderType(), OF_PART_OF_ORDERS) && v->current_order.IsType(OT_GOTO_DEPOT)) ||
 			(v->vehstatus & VS_STOPPED)) {
 		/* we keep the vehicle in the depot since the user ordered it to stay */
 		v->leave_depot_instantly = false;
@@ -767,7 +767,7 @@
 	}
 
 	AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs,
-		v->sprite_width, v->sprite_height, v->z_height, v->z_pos, (v->vehstatus & VS_SHADOW) != 0);
+		v->x_extent, v->y_extent, v->z_extent, v->z_pos, (v->vehstatus & VS_SHADOW) != 0);
 }
 
 void ViewportAddVehicles(DrawPixelInfo *dpi)
@@ -2033,7 +2033,7 @@
 					const Order *order;
 
 					FOR_VEHICLE_ORDERS(v, order) {
-						if (order->type == OT_GOTO_STATION && order->dest == index) {
+						if (order->IsType(OT_GOTO_STATION) && order->GetDestination() == index) {
 							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50);
 							(*sort_list)[n++] = v;
 							break;
@@ -2077,7 +2077,7 @@
 					const Order *order;
 
 					FOR_VEHICLE_ORDERS(v, order) {
-						if (order->type == OT_GOTO_DEPOT && order->dest == index) {
+						if (order->IsType(OT_GOTO_DEPOT) && order->GetDestination() == index) {
 							if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25);
 							(*sort_list)[n++] = v;
 							break;
@@ -2174,7 +2174,7 @@
 		max += v->cargo_cap;
 		if (v->cargo_cap != 0) {
 			unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;
-			loading |= (u->current_order.flags & OFB_UNLOAD) == 0 && st->goods[v->cargo_type].days_since_pickup != 255;
+			loading |= !HasBit(u->current_order.GetUnloadType(), OF_UNLOAD) && st->goods[v->cargo_type].days_since_pickup != 255;
 			cars++;
 		}
 	}
@@ -2235,20 +2235,19 @@
 
 	TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
 
-	if (v->current_order.type == OT_GOTO_DEPOT) {
+	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
 		Order t;
 
 		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 
 		t = v->current_order;
-		v->current_order.type = OT_DUMMY;
-		v->current_order.flags = 0;
-
-		if (t.refit_cargo < NUM_CARGO) {
+		v->current_order.MakeDummy();
+
+		if (t.IsRefit()) {
 			CommandCost cost;
 
 			_current_player = v->owner;
-			cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, GetCmdRefitVeh(v));
+			cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v));
 
 			if (CmdFailed(cost)) {
 				v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot
@@ -2263,11 +2262,11 @@
 			}
 		}
 
-		if (HasBit(t.flags, OF_PART_OF_ORDERS)) {
+		if (HasBit(t.GetDepotOrderType(), OF_PART_OF_ORDERS)) {
 			/* Part of orders */
 			UpdateVehicleTimetable(v, true);
 			v->cur_order_index++;
-		} else if (HasBit(t.flags, OF_HALT_IN_DEPOT)) {
+		} else if (HasBit(t.GetDepotActionType(), OF_HALT_IN_DEPOT)) {
 			/* Force depot visit */
 			v->vehstatus |= VS_STOPPED;
 			if (v->owner == _local_player) {
@@ -3054,7 +3053,7 @@
 }
 
 /** Will be called when vehicles need to be loaded. */
-static void Load_VEHS()
+void Load_VEHS()
 {
 	int index;
 	Vehicle *v;
@@ -3097,7 +3096,7 @@
 		if (CheckSavegameVersion(5)) {
 			/* Convert the current_order.type (which is a mix of type and flags, because
 			 *  in those versions, they both were 4 bits big) to type and flags */
-			v->current_order.flags = (v->current_order.type & 0xF0) >> 4;
+			v->current_order.flags = GB(v->current_order.type, 4, 4);
 			v->current_order.type.m_val &= 0x0F;
 		}
 
@@ -3131,25 +3130,22 @@
 {
 	assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP);
 
-	if (this->current_order.type == OT_GOTO_STATION &&
-			this->current_order.dest == this->last_station_visited) {
-		/* Arriving at the ordered station.
-		 * Keep the load/unload flags, as we (obviously) still need them. */
-		this->current_order.flags &= OFB_FULL_LOAD | OFB_UNLOAD | OFB_TRANSFER;
-
+	if (this->current_order.IsType(OT_GOTO_STATION) &&
+			this->current_order.GetDestination() == this->last_station_visited) {
 		/* Furthermore add the Non Stop flag to mark that this station
 		 * is the actual destination of the vehicle, which is (for example)
 		 * necessary to be known for HandleTrainLoading to determine
 		 * whether the train is lost or not; not marking a train lost
 		 * that arrives at random stations is bad. */
-		this->current_order.flags |= OFB_NON_STOP;
+		this->current_order.SetNonStopType(OFB_NON_STOP);
+
+		current_order.MakeLoading(true);
 		UpdateVehicleTimetable(this, true);
 	} else {
-		/* This is just an unordered intermediate stop */
-		this->current_order.flags = 0;
+		this->current_order.SetNonStopType(OFB_NO_NON_STOP);
+		current_order.MakeLoading(false);
 	}
 
-	current_order.type = OT_LOADING;
 	GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
 
 	VehiclePayment(this);
@@ -3165,13 +3161,12 @@
 
 void Vehicle::LeaveStation()
 {
-	assert(current_order.type == OT_LOADING);
+	assert(current_order.IsType(OT_LOADING));
 
 	/* Only update the timetable if the vehicle was supposed to stop here. */
-	if (current_order.flags & OFB_NON_STOP) UpdateVehicleTimetable(this, false);
-
-	current_order.type = OT_LEAVESTATION;
-	current_order.flags = 0;
+	if (current_order.GetNonStopType() != OFB_NO_NON_STOP) UpdateVehicleTimetable(this, false);
+
+	current_order.MakeLeaveStation();
 	GetStation(this->last_station_visited)->loading_vehicles.remove(this);
 
 	HideFillingPercent(this->fill_percent_te_id);
@@ -3181,7 +3176,7 @@
 
 void Vehicle::HandleLoading(bool mode)
 {
-	switch (this->current_order.type) {
+	switch (this->current_order.GetType()) {
 		case OT_LOADING: {
 			uint wait_time = max(this->current_order.wait_time - this->lateness_counter, 0);
 
@@ -3195,7 +3190,7 @@
 			this->LeaveStation();
 
 			/* If this was not the final order, don't remove it from the list. */
-			if (!(b.flags & OFB_NON_STOP)) return;
+			if (!(b.GetNonStopType() & OFB_NON_STOP)) return;
 			break;
 		}
 
@@ -3234,9 +3229,9 @@
 {
 	this->x_offs        = 0;
 	this->y_offs        = 0;
-	this->sprite_width  = 1;
-	this->sprite_height = 1;
-	this->z_height      = 1;
+	this->x_extent      = 1;
+	this->y_extent      = 1;
+	this->z_extent      = 1;
 }
 
 void StopAllVehicles()