src/order_cmd.cpp
changeset 8848 635cb164edd4
parent 8847 426dd2d582e7
child 8849 26717ff2482e
equal deleted inserted replaced
8847:426dd2d582e7 8848:635cb164edd4
    37 assert_compile(sizeof(DestinationID) >= sizeof(StationID));
    37 assert_compile(sizeof(DestinationID) >= sizeof(StationID));
    38 
    38 
    39 TileIndex _backup_orders_tile;
    39 TileIndex _backup_orders_tile;
    40 BackuppedOrders _backup_orders_data;
    40 BackuppedOrders _backup_orders_data;
    41 
    41 
    42 DEFINE_OLD_POOL_GENERIC(Order, Order)
    42 DEFINE_OLD_POOL_GENERIC(Order, Order);
       
    43 
       
    44 OrderNonStopFlags Order::GetNonStopType() const
       
    45 {
       
    46 	return (this->flags & 0x8) ?
       
    47 			((!_patches.new_nonstop || !this->IsType(OT_GOTO_STATION)) ?
       
    48 					ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS :
       
    49 					ONSF_NO_STOP_AT_DESTINATION_STATION) :
       
    50 			ONSF_STOP_EVERYWHERE;
       
    51 }
    43 
    52 
    44 void Order::Free()
    53 void Order::Free()
    45 {
    54 {
    46 	this->type  = OT_NOTHING;
    55 	this->type  = OT_NOTHING;
    47 	this->flags = 0;
    56 	this->flags = 0;
    57 }
    66 }
    58 
    67 
    59 void Order::MakeGoToDepot(DepotID destination, bool order, CargoID cargo, byte subtype)
    68 void Order::MakeGoToDepot(DepotID destination, bool order, CargoID cargo, byte subtype)
    60 {
    69 {
    61 	this->type = OT_GOTO_DEPOT;
    70 	this->type = OT_GOTO_DEPOT;
    62 	this->flags = order ? OFB_PART_OF_ORDERS : OFB_NON_STOP;
    71 	this->flags = 0;
       
    72 	if (order) {
       
    73 		this->SetDepotOrderType(OFB_PART_OF_ORDERS);
       
    74 	} else {
       
    75 		this->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
       
    76 	}
    63 	this->dest = destination;
    77 	this->dest = destination;
    64 	this->SetRefit(cargo, subtype);
    78 	this->SetRefit(cargo, subtype);
    65 }
    79 }
    66 
    80 
    67 void Order::MakeGoToWaypoint(WaypointID destination)
    81 void Order::MakeGoToWaypoint(WaypointID destination)
   301 					break;
   315 					break;
   302 
   316 
   303 				default: return CMD_ERROR;
   317 				default: return CMD_ERROR;
   304 			}
   318 			}
   305 
   319 
   306 			if (new_order.GetNonStopType() != OFB_NO_NON_STOP && v->type != VEH_TRAIN) return CMD_ERROR;
   320 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   307 
   321 
   308 			/* Order flags can be any of the following for stations:
   322 			/* Order flags can be any of the following for stations:
   309 			 * [full-load | unload] [+ transfer] [+ non-stop]
   323 			 * [full-load | unload] [+ transfer] [+ non-stop]
   310 			 * non-stop orders (if any) are only valid for trains */
   324 			 * non-stop orders (if any) are only valid for trains */
   311 			switch (new_order.GetLoadType() | new_order.GetUnloadType()) {
   325 			switch (new_order.GetLoadType() | new_order.GetUnloadType()) {
   356 
   370 
   357 					default: return CMD_ERROR;
   371 					default: return CMD_ERROR;
   358 				}
   372 				}
   359 			}
   373 			}
   360 
   374 
   361 			if (new_order.GetNonStopType() != OFB_NO_NON_STOP && v->type != VEH_TRAIN) return CMD_ERROR;
   375 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   362 
   376 
   363 			/* Order flags can be any of the following for depots:
   377 			/* Order flags can be any of the following for depots:
   364 			 * order [+ halt] [+ non-stop]
   378 			 * order [+ halt] [+ non-stop]
   365 			 * non-stop orders (if any) are only valid for trains */
   379 			 * non-stop orders (if any) are only valid for trains */
   366 			switch (new_order.GetDepotOrderType() | new_order.GetDepotActionType()) {
   380 			switch (new_order.GetDepotOrderType() | new_order.GetDepotActionType()) {
   383 			if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
   397 			if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
   384 
   398 
   385 			/* Order flags can be any of the following for waypoints:
   399 			/* Order flags can be any of the following for waypoints:
   386 			 * [non-stop]
   400 			 * [non-stop]
   387 			 * non-stop orders (if any) are only valid for trains */
   401 			 * non-stop orders (if any) are only valid for trains */
   388 			switch (new_order.GetNonStopType()) {
   402 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   389 				case OFB_NO_NON_STOP: break;
       
   390 
       
   391 				case OFB_NON_STOP:
       
   392 					if (v->type != VEH_TRAIN) return CMD_ERROR;
       
   393 					break;
       
   394 
       
   395 				default: return CMD_ERROR;
       
   396 			}
       
   397 			break;
       
   398 		}
   403 		}
   399 
   404 
   400 		default: return CMD_ERROR;
   405 		default: return CMD_ERROR;
   401 	}
   406 	}
   402 
   407 
   586 			assert(v->orders == u->orders);
   591 			assert(v->orders == u->orders);
   587 
   592 
   588 			/* NON-stop flag is misused to see if a train is in a station that is
   593 			/* NON-stop flag is misused to see if a train is in a station that is
   589 			 * on his order list or not */
   594 			 * on his order list or not */
   590 			if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING)) {
   595 			if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING)) {
   591 				u->current_order.SetNonStopType(OFB_NO_NON_STOP);
   596 				u->current_order.SetNonStopType(ONSF_STOP_EVERYWHERE);
   592 			}
   597 			}
   593 
   598 
   594 			/* Update any possible open window of the vehicle */
   599 			/* Update any possible open window of the vehicle */
   595 			InvalidateVehicleOrder(u);
   600 			InvalidateVehicleOrder(u);
   596 		}
   601 		}
   770 			case OF_UNLOAD:
   775 			case OF_UNLOAD:
   771 				order->SetUnloadType(order->GetUnloadType() ^ OFB_UNLOAD);
   776 				order->SetUnloadType(order->GetUnloadType() ^ OFB_UNLOAD);
   772 				order->SetLoadType(0);
   777 				order->SetLoadType(0);
   773 				break;
   778 				break;
   774 			case OF_NON_STOP:
   779 			case OF_NON_STOP:
   775 				order->SetNonStopType(order->GetNonStopType() ^ OFB_NON_STOP);
   780 				order->SetNonStopType(order->GetNonStopType() == ONSF_STOP_EVERYWHERE ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_STOP_EVERYWHERE);
   776 				break;
   781 				break;
   777 			case OF_TRANSFER:
   782 			case OF_TRANSFER:
   778 				order->SetUnloadType(order->GetUnloadType() ^ OFB_TRANSFER);
   783 				order->SetUnloadType(order->GetUnloadType() ^ OFB_TRANSFER);
   779 				break;
   784 				break;
   780 			default: NOT_REACHED();
   785 			default: NOT_REACHED();
  1394 	if (v->current_order.IsType(OT_GOTO_WAYPOINT) && v->tile == v->dest_tile) {
  1399 	if (v->current_order.IsType(OT_GOTO_WAYPOINT) && v->tile == v->dest_tile) {
  1395 		UpdateVehicleTimetable(v, true);
  1400 		UpdateVehicleTimetable(v, true);
  1396 		v->cur_order_index++;
  1401 		v->cur_order_index++;
  1397 	}
  1402 	}
  1398 
  1403 
  1399 	/* Check if we've reached a non-stop station while TTDPatch nonstop is enabled.. */
  1404 	/* Check if we've reached a non-stop station.. */
  1400 	if (_patches.new_nonstop &&
  1405 	if ((v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) &&
  1401 			v->current_order.GetNonStopType() & OFB_NON_STOP &&
       
  1402 			IsTileType(v->tile, MP_STATION) &&
  1406 			IsTileType(v->tile, MP_STATION) &&
  1403 			v->current_order.GetDestination() == GetStationIndex(v->tile)) {
  1407 			v->current_order.GetDestination() == GetStationIndex(v->tile)) {
  1404 		v->last_station_visited = v->current_order.GetDestination();
  1408 		v->last_station_visited = v->current_order.GetDestination();
  1405 		UpdateVehicleTimetable(v, true);
  1409 		UpdateVehicleTimetable(v, true);
  1406 		v->cur_order_index++;
  1410 		v->cur_order_index++;
  1480  */
  1484  */
  1481 bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const
  1485 bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const
  1482 {
  1486 {
  1483 	return
  1487 	return
  1484 			v->last_station_visited != station && // Do stop only when we've not just been there
  1488 			v->last_station_visited != station && // Do stop only when we've not just been there
  1485 			type == OT_GOTO_STATION &&            // Do stop only when going to a station
  1489 			/* Finally do stop when there is no non-stop flag set for this type of station. */
  1486 			/* Finally do stop when the non-stop flag is not set, or when we should stop at
  1490 			!(this->GetNonStopType() & ((this->dest == station) ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS));
  1487 			 * this station according to the new_nonstop setting. */
       
  1488 			(!(this->flags & OFB_NON_STOP) || ((this->dest != station) == _patches.new_nonstop));
       
  1489 }
  1491 }
  1490 
  1492 
  1491 void InitializeOrders()
  1493 void InitializeOrders()
  1492 {
  1494 {
  1493 	_Order_pool.CleanPool();
  1495 	_Order_pool.CleanPool();