src/order_cmd.cpp
changeset 8843 45fdf630deaa
parent 8840 332412c2e9c1
child 8845 f9ef3bb70e47
equal deleted inserted replaced
8842:ed3fb21d71c6 8843:45fdf630deaa
    68 	this->type = OT_GOTO_WAYPOINT;
    68 	this->type = OT_GOTO_WAYPOINT;
    69 	this->flags = 0;
    69 	this->flags = 0;
    70 	this->dest = destination;
    70 	this->dest = destination;
    71 }
    71 }
    72 
    72 
    73 void Order::MakeLoading()
    73 void Order::MakeLoading(bool ordered)
    74 {
    74 {
    75 	this->type = OT_LOADING;
    75 	this->type = OT_LOADING;
       
    76 	if (!ordered) this->flags = 0;
    76 }
    77 }
    77 
    78 
    78 void Order::MakeLeaveStation()
    79 void Order::MakeLeaveStation()
    79 {
    80 {
    80 	this->type = OT_LEAVESTATION;
    81 	this->type = OT_LEAVESTATION;
   158 
   159 
   159 	/*
   160 	/*
   160 	 * Sanity check
   161 	 * Sanity check
   161 	 * TTD stores invalid orders as OT_NOTHING with non-zero flags/station
   162 	 * TTD stores invalid orders as OT_NOTHING with non-zero flags/station
   162 	 */
   163 	 */
   163 	if (!order.IsValid() && (order.flags != 0 || order.GetDestination() != 0)) {
   164 	if (!order.IsValid() && (order.GetLoadType() != 0 || order.GetUnloadType() != 0 || order.GetDestination() != 0)) {
   164 		order.MakeDummy();
   165 		order.MakeDummy();
   165 	}
   166 	}
   166 
   167 
   167 	return order;
   168 	return order;
   168 }
   169 }
   391 			if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
   392 			if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
   392 
   393 
   393 			/* Order flags can be any of the following for waypoints:
   394 			/* Order flags can be any of the following for waypoints:
   394 			 * [non-stop]
   395 			 * [non-stop]
   395 			 * non-stop orders (if any) are only valid for trains */
   396 			 * non-stop orders (if any) are only valid for trains */
   396 			switch (new_order.flags) {
   397 			switch (new_order.GetNonStopType()) {
   397 				case 0: break;
   398 				case OFB_NO_NON_STOP: break;
   398 
   399 
   399 				case OFB_NON_STOP:
   400 				case OFB_NON_STOP:
   400 					if (v->type != VEH_TRAIN) return CMD_ERROR;
   401 					if (v->type != VEH_TRAIN) return CMD_ERROR;
   401 					break;
   402 					break;
   402 
   403 
   593 
   594 
   594 			assert(v->orders == u->orders);
   595 			assert(v->orders == u->orders);
   595 
   596 
   596 			/* NON-stop flag is misused to see if a train is in a station that is
   597 			/* NON-stop flag is misused to see if a train is in a station that is
   597 			 * on his order list or not */
   598 			 * on his order list or not */
   598 			if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING) &&
   599 			if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING)) {
   599 					HasBit(u->current_order.flags, OF_NON_STOP)) {
   600 				u->current_order.SetNonStopType(OFB_NO_NON_STOP);
   600 				u->current_order.flags = 0;
       
   601 			}
   601 			}
   602 
   602 
   603 			/* Update any possible open window of the vehicle */
   603 			/* Update any possible open window of the vehicle */
   604 			InvalidateVehicleOrder(u);
   604 			InvalidateVehicleOrder(u);
   605 		}
   605 		}
   632 	if (flags & DC_EXEC) {
   632 	if (flags & DC_EXEC) {
   633 		v->cur_order_index = sel_ord;
   633 		v->cur_order_index = sel_ord;
   634 
   634 
   635 		if (v->type == VEH_ROAD) ClearSlot(v);
   635 		if (v->type == VEH_ROAD) ClearSlot(v);
   636 
   636 
   637 		if (v->current_order.IsType(OT_LOADING)) {
   637 		if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
   638 			v->LeaveStation();
       
   639 			/* NON-stop flag is misused to see if a train is in a station that is
       
   640 			 * on his order list or not */
       
   641 			if (HasBit(v->current_order.flags, OF_NON_STOP)) v->current_order.flags = 0;
       
   642 		}
       
   643 
   638 
   644 		InvalidateVehicleOrder(v);
   639 		InvalidateVehicleOrder(v);
   645 	}
   640 	}
   646 
   641 
   647 	/* We have an aircraft/ship, they have a mini-schedule, so update them all */
   642 	/* We have an aircraft/ship, they have a mini-schedule, so update them all */
   806 				 * so do not care and those orders should not be active
   801 				 * so do not care and those orders should not be active
   807 				 * when this function is called.
   802 				 * when this function is called.
   808 				 */
   803 				 */
   809 				if (sel_ord == u->cur_order_index &&
   804 				if (sel_ord == u->cur_order_index &&
   810 						!u->current_order.IsType(OT_GOTO_DEPOT) &&
   805 						!u->current_order.IsType(OT_GOTO_DEPOT) &&
   811 						HasBit(u->current_order.flags, OF_FULL_LOAD) != HasBit(order->flags, OF_FULL_LOAD)) {
   806 						u->current_order.GetLoadType() != order->GetLoadType()) {
   812 					ToggleBit(u->current_order.flags, OF_FULL_LOAD);
   807 					u->current_order.SetLoadType(order->GetLoadType());
   813 				}
   808 				}
   814 				InvalidateVehicleOrder(u);
   809 				InvalidateVehicleOrder(u);
   815 			}
   810 			}
   816 		}
   811 		}
   817 	}
   812 	}
   988 		for (; u != NULL; u = u->next_shared) {
   983 		for (; u != NULL; u = u->next_shared) {
   989 			/* Update any possible open window of the vehicle */
   984 			/* Update any possible open window of the vehicle */
   990 			InvalidateVehicleOrder(u);
   985 			InvalidateVehicleOrder(u);
   991 
   986 
   992 			/* If the vehicle already got the current depot set as current order, then update current order as well */
   987 			/* If the vehicle already got the current depot set as current order, then update current order as well */
   993 			if (u->cur_order_index == order_number && HasBit(u->current_order.flags, OF_PART_OF_ORDERS)) {
   988 			if (u->cur_order_index == order_number && HasBit(u->current_order.GetDepotOrderType(), OF_PART_OF_ORDERS)) {
   994 				u->current_order.SetRefit(cargo, subtype);
   989 				u->current_order.SetRefit(cargo, subtype);
   995 			}
   990 			}
   996 		}
   991 		}
   997 	}
   992 	}
   998 
   993 
  1371 bool ProcessOrders(Vehicle *v)
  1366 bool ProcessOrders(Vehicle *v)
  1372 {
  1367 {
  1373 	switch (v->current_order.GetType()) {
  1368 	switch (v->current_order.GetType()) {
  1374 		case OT_GOTO_DEPOT:
  1369 		case OT_GOTO_DEPOT:
  1375 			/* Let a depot order in the orderlist interrupt. */
  1370 			/* Let a depot order in the orderlist interrupt. */
  1376 			if (!(v->current_order.flags & OFB_PART_OF_ORDERS)) return false;
  1371 			if (!(v->current_order.GetDepotOrderType() & OFB_PART_OF_ORDERS)) return false;
  1377 
  1372 
  1378 			if ((v->current_order.flags & OFB_SERVICE_IF_NEEDED) && !VehicleNeedsService(v)) {
  1373 			if ((v->current_order.GetDepotOrderType() & OFB_SERVICE_IF_NEEDED) && !VehicleNeedsService(v)) {
  1379 				UpdateVehicleTimetable(v, true);
  1374 				UpdateVehicleTimetable(v, true);
  1380 				v->cur_order_index++;
  1375 				v->cur_order_index++;
  1381 			}
  1376 			}
  1382 			break;
  1377 			break;
  1383 
  1378 
  1406 		v->cur_order_index++;
  1401 		v->cur_order_index++;
  1407 	}
  1402 	}
  1408 
  1403 
  1409 	/* Check if we've reached a non-stop station while TTDPatch nonstop is enabled.. */
  1404 	/* Check if we've reached a non-stop station while TTDPatch nonstop is enabled.. */
  1410 	if (_patches.new_nonstop &&
  1405 	if (_patches.new_nonstop &&
  1411 			v->current_order.flags & OFB_NON_STOP &&
  1406 			v->current_order.GetNonStopType() & OFB_NON_STOP &&
  1412 			IsTileType(v->tile, MP_STATION) &&
  1407 			IsTileType(v->tile, MP_STATION) &&
  1413 			v->current_order.GetDestination() == GetStationIndex(v->tile)) {
  1408 			v->current_order.GetDestination() == GetStationIndex(v->tile)) {
  1414 		v->last_station_visited = v->current_order.GetDestination();
  1409 		v->last_station_visited = v->current_order.GetDestination();
  1415 		UpdateVehicleTimetable(v, true);
  1410 		UpdateVehicleTimetable(v, true);
  1416 		v->cur_order_index++;
  1411 		v->cur_order_index++;