2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file order_cmd.cpp Handling of orders. */
|
2007-03-21 16:19:33 +01:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
#include "stdafx.h"
|
2009-01-03 14:52:06 +01:00
|
|
|
#include "debug.h"
|
2010-04-17 15:31:41 +02:00
|
|
|
#include "cmd_helper.h"
|
2007-12-21 22:50:46 +01:00
|
|
|
#include "command_func.h"
|
2008-09-30 22:51:04 +02:00
|
|
|
#include "company_func.h"
|
2008-03-28 09:53:36 +01:00
|
|
|
#include "news_func.h"
|
2007-12-21 20:49:27 +01:00
|
|
|
#include "strings_func.h"
|
2008-04-05 12:55:50 +02:00
|
|
|
#include "timetable.h"
|
|
|
|
#include "vehicle_func.h"
|
2008-04-17 21:10:30 +02:00
|
|
|
#include "depot_base.h"
|
2009-05-22 17:13:50 +02:00
|
|
|
#include "core/pool_func.hpp"
|
2013-05-19 16:22:04 +02:00
|
|
|
#include "core/random_func.hpp"
|
2009-05-22 22:03:26 +02:00
|
|
|
#include "aircraft.h"
|
2009-06-06 18:54:22 +02:00
|
|
|
#include "roadveh.h"
|
2009-06-24 19:39:54 +02:00
|
|
|
#include "station_base.h"
|
2009-07-22 12:18:19 +02:00
|
|
|
#include "waypoint_base.h"
|
2010-01-15 17:41:15 +01:00
|
|
|
#include "company_base.h"
|
2011-12-09 21:48:13 +01:00
|
|
|
#include "order_backup.h"
|
2014-05-06 22:50:58 +02:00
|
|
|
#include "cheat_type.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-01-13 02:21:35 +01:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2008-03-28 17:31:26 +01:00
|
|
|
/* DestinationID must be at least as large as every these below, because it can
|
|
|
|
* be any of them
|
|
|
|
*/
|
|
|
|
assert_compile(sizeof(DestinationID) >= sizeof(DepotID));
|
|
|
|
assert_compile(sizeof(DestinationID) >= sizeof(StationID));
|
|
|
|
|
2009-05-22 17:13:50 +02:00
|
|
|
OrderPool _order_pool("Order");
|
|
|
|
INSTANTIATE_POOL_METHODS(Order)
|
|
|
|
OrderListPool _orderlist_pool("OrderList");
|
|
|
|
INSTANTIATE_POOL_METHODS(OrderList)
|
2008-04-07 10:59:04 +02:00
|
|
|
|
2011-11-12 19:06:34 +01:00
|
|
|
/** Clean everything up. */
|
|
|
|
Order::~Order()
|
|
|
|
{
|
|
|
|
if (CleaningPool()) return;
|
|
|
|
|
|
|
|
/* We can visit oil rigs and buoys that are not our own. They will be shown in
|
|
|
|
* the list of stations. So, we need to invalidate that window if needed. */
|
|
|
|
if (this->IsType(OT_GOTO_STATION) || this->IsType(OT_GOTO_WAYPOINT)) {
|
|
|
|
BaseStation *bs = BaseStation::GetIfValid(this->GetDestination());
|
2019-04-10 23:07:06 +02:00
|
|
|
if (bs != nullptr && bs->owner == OWNER_NONE) InvalidateWindowClassesData(WC_STATION_LIST, 0);
|
2011-11-12 19:06:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* 'Free' the order
|
|
|
|
* @note ONLY use on "current_order" vehicle orders!
|
|
|
|
*/
|
2008-04-05 22:57:01 +02:00
|
|
|
void Order::Free()
|
|
|
|
{
|
|
|
|
this->type = OT_NOTHING;
|
|
|
|
this->flags = 0;
|
|
|
|
this->dest = 0;
|
2019-04-10 23:07:06 +02:00
|
|
|
this->next = nullptr;
|
2008-04-05 22:57:01 +02:00
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Makes this order a Go To Station order.
|
|
|
|
* @param destination the station to go to.
|
|
|
|
*/
|
2008-04-06 01:36:54 +02:00
|
|
|
void Order::MakeGoToStation(StationID destination)
|
|
|
|
{
|
|
|
|
this->type = OT_GOTO_STATION;
|
|
|
|
this->flags = 0;
|
|
|
|
this->dest = destination;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Makes this order a Go To Depot order.
|
|
|
|
* @param destination the depot to go to.
|
2013-01-08 23:46:42 +01:00
|
|
|
* @param order is this order a 'default' order, or an overridden vehicle order?
|
2011-01-19 00:09:43 +01:00
|
|
|
* @param non_stop_type how to get to the depot?
|
|
|
|
* @param action what to do in the depot?
|
|
|
|
* @param cargo the cargo type to change to.
|
|
|
|
*/
|
2013-02-24 17:41:51 +01:00
|
|
|
void Order::MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type, OrderDepotActionFlags action, CargoID cargo)
|
2008-04-06 01:36:54 +02:00
|
|
|
{
|
|
|
|
this->type = OT_GOTO_DEPOT;
|
2008-04-07 21:18:56 +02:00
|
|
|
this->SetDepotOrderType(order);
|
2008-11-21 19:16:19 +01:00
|
|
|
this->SetDepotActionType(action);
|
2009-05-02 02:10:24 +02:00
|
|
|
this->SetNonStopType(non_stop_type);
|
2008-04-06 01:36:54 +02:00
|
|
|
this->dest = destination;
|
2013-02-24 17:41:51 +01:00
|
|
|
this->SetRefit(cargo);
|
2008-04-06 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Makes this order a Go To Waypoint order.
|
|
|
|
* @param destination the waypoint to go to.
|
|
|
|
*/
|
2009-07-28 23:06:38 +02:00
|
|
|
void Order::MakeGoToWaypoint(StationID destination)
|
2008-04-06 01:36:54 +02:00
|
|
|
{
|
|
|
|
this->type = OT_GOTO_WAYPOINT;
|
|
|
|
this->flags = 0;
|
|
|
|
this->dest = destination;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Makes this order a Loading order.
|
|
|
|
* @param ordered is this an ordered stop?
|
|
|
|
*/
|
2008-04-06 17:09:45 +02:00
|
|
|
void Order::MakeLoading(bool ordered)
|
2008-04-06 01:36:54 +02:00
|
|
|
{
|
|
|
|
this->type = OT_LOADING;
|
2008-04-06 17:09:45 +02:00
|
|
|
if (!ordered) this->flags = 0;
|
2008-04-06 01:36:54 +02:00
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Makes this order a Leave Station order.
|
|
|
|
*/
|
2008-04-06 01:36:54 +02:00
|
|
|
void Order::MakeLeaveStation()
|
|
|
|
{
|
|
|
|
this->type = OT_LEAVESTATION;
|
|
|
|
this->flags = 0;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Makes this order a Dummy order.
|
|
|
|
*/
|
2008-04-06 01:36:54 +02:00
|
|
|
void Order::MakeDummy()
|
|
|
|
{
|
|
|
|
this->type = OT_DUMMY;
|
|
|
|
this->flags = 0;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Makes this order an conditional order.
|
|
|
|
* @param order the order to jump to.
|
|
|
|
*/
|
2008-04-12 13:58:19 +02:00
|
|
|
void Order::MakeConditional(VehicleOrderID order)
|
|
|
|
{
|
|
|
|
this->type = OT_CONDITIONAL;
|
2008-04-12 14:19:53 +02:00
|
|
|
this->flags = order;
|
|
|
|
this->dest = 0;
|
2008-04-12 13:58:19 +02:00
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
2011-05-18 14:19:58 +02:00
|
|
|
* Makes this order an implicit order.
|
2011-01-19 00:09:43 +01:00
|
|
|
* @param destination the station to go to.
|
|
|
|
*/
|
2011-05-18 14:19:58 +02:00
|
|
|
void Order::MakeImplicit(StationID destination)
|
2010-12-26 10:03:19 +01:00
|
|
|
{
|
2011-05-18 14:19:58 +02:00
|
|
|
this->type = OT_IMPLICIT;
|
2010-12-26 10:03:19 +01:00
|
|
|
this->dest = destination;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
2011-11-04 01:38:51 +01:00
|
|
|
* Make this depot/station order also a refit order.
|
2011-01-19 00:09:43 +01:00
|
|
|
* @param cargo the cargo type to change to.
|
2011-11-04 01:38:51 +01:00
|
|
|
* @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION).
|
2011-01-19 00:09:43 +01:00
|
|
|
*/
|
2013-02-24 17:41:51 +01:00
|
|
|
void Order::SetRefit(CargoID cargo)
|
2008-04-06 09:07:21 +02:00
|
|
|
{
|
|
|
|
this->refit_cargo = cargo;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Does this order have the same type, flags and destination?
|
|
|
|
* @param other the second order to compare to.
|
|
|
|
* @return true if the type, flags and destination match.
|
|
|
|
*/
|
2008-04-05 23:45:05 +02:00
|
|
|
bool Order::Equals(const Order &other) const
|
|
|
|
{
|
2008-11-23 22:46:27 +01:00
|
|
|
/* In case of go to nearest depot orders we need "only" compare the flags
|
|
|
|
* with the other and not the nearest depot order bit or the actual
|
|
|
|
* destination because those get clear/filled in during the order
|
|
|
|
* evaluation. If we do not do this the order will continuously be seen as
|
|
|
|
* a different order and it will try to find a "nearest depot" every tick. */
|
2010-08-15 15:17:04 +02:00
|
|
|
if ((this->IsType(OT_GOTO_DEPOT) && this->type == other.type) &&
|
2008-11-23 22:46:27 +01:00
|
|
|
((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0 ||
|
|
|
|
(other.GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0)) {
|
2010-11-20 16:44:24 +01:00
|
|
|
return this->GetDepotOrderType() == other.GetDepotOrderType() &&
|
|
|
|
(this->GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) == (other.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT);
|
2008-11-23 22:46:27 +01:00
|
|
|
}
|
|
|
|
|
2010-11-20 16:44:24 +01:00
|
|
|
return this->type == other.type && this->flags == other.flags && this->dest == other.dest;
|
2008-04-05 23:45:05 +02:00
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Pack this order into a 32 bits integer, or actually only
|
|
|
|
* the type, flags and destination.
|
|
|
|
* @return the packed representation.
|
|
|
|
* @note unpacking is done in the constructor.
|
|
|
|
*/
|
2008-04-06 09:22:26 +02:00
|
|
|
uint32 Order::Pack() const
|
2008-04-05 22:57:01 +02:00
|
|
|
{
|
2008-04-06 09:22:26 +02:00
|
|
|
return this->dest << 16 | this->flags << 8 | this->type;
|
2008-04-05 22:57:01 +02:00
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Pack this order into a 16 bits integer as close to the TTD
|
|
|
|
* representation as possible.
|
|
|
|
* @return the TTD-like packed representation.
|
|
|
|
*/
|
2009-06-21 12:11:04 +02:00
|
|
|
uint16 Order::MapOldOrder() const
|
|
|
|
{
|
|
|
|
uint16 order = this->GetType();
|
|
|
|
switch (this->type) {
|
|
|
|
case OT_GOTO_STATION:
|
|
|
|
if (this->GetUnloadType() & OUFB_UNLOAD) SetBit(order, 5);
|
|
|
|
if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
|
|
|
|
if (this->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) SetBit(order, 7);
|
|
|
|
order |= GB(this->GetDestination(), 0, 8) << 8;
|
|
|
|
break;
|
|
|
|
case OT_GOTO_DEPOT:
|
|
|
|
if (!(this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) SetBit(order, 6);
|
|
|
|
SetBit(order, 7);
|
|
|
|
order |= GB(this->GetDestination(), 0, 8) << 8;
|
|
|
|
break;
|
|
|
|
case OT_LOADING:
|
|
|
|
if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Create an order based on a packed representation of that order.
|
|
|
|
* @param packed the packed representation.
|
|
|
|
*/
|
2008-04-06 09:22:26 +02:00
|
|
|
Order::Order(uint32 packed)
|
2008-04-05 22:57:01 +02:00
|
|
|
{
|
2008-04-06 09:22:26 +02:00
|
|
|
this->type = (OrderType)GB(packed, 0, 8);
|
|
|
|
this->flags = GB(packed, 8, 8);
|
|
|
|
this->dest = GB(packed, 16, 16);
|
2019-04-10 23:07:06 +02:00
|
|
|
this->next = nullptr;
|
2008-04-06 09:22:26 +02:00
|
|
|
this->refit_cargo = CT_NO_REFIT;
|
|
|
|
this->wait_time = 0;
|
|
|
|
this->travel_time = 0;
|
2012-02-14 18:04:06 +01:00
|
|
|
this->max_speed = UINT16_MAX;
|
2008-04-05 22:57:01 +02:00
|
|
|
}
|
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Updates the widgets of a vehicle which contains the order-data
|
|
|
|
*
|
|
|
|
*/
|
2008-09-24 18:40:06 +02:00
|
|
|
void InvalidateVehicleOrder(const Vehicle *v, int data)
|
2005-01-15 20:06:22 +01:00
|
|
|
{
|
2009-09-13 21:15:59 +02:00
|
|
|
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
|
2008-09-24 18:40:06 +02:00
|
|
|
|
|
|
|
if (data != 0) {
|
|
|
|
/* Calls SetDirty() too */
|
|
|
|
InvalidateWindowData(WC_VEHICLE_ORDERS, v->index, data);
|
|
|
|
InvalidateWindowData(WC_VEHICLE_TIMETABLE, v->index, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-13 21:15:59 +02:00
|
|
|
SetWindowDirty(WC_VEHICLE_ORDERS, v->index);
|
|
|
|
SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2010-01-01 19:45:40 +01:00
|
|
|
* Assign data to an order (from another order)
|
2005-01-15 20:06:22 +01:00
|
|
|
* This function makes sure that the index is maintained correctly
|
2011-01-19 00:09:43 +01:00
|
|
|
* @param other the data to copy (except next pointer).
|
2005-01-15 20:06:22 +01:00
|
|
|
*
|
|
|
|
*/
|
2008-04-05 23:45:05 +02:00
|
|
|
void Order::AssignOrder(const Order &other)
|
2005-01-15 20:06:22 +01:00
|
|
|
{
|
2008-04-05 23:45:05 +02:00
|
|
|
this->type = other.type;
|
|
|
|
this->flags = other.flags;
|
|
|
|
this->dest = other.dest;
|
2006-10-03 16:52:39 +02:00
|
|
|
|
2008-04-05 23:45:05 +02:00
|
|
|
this->refit_cargo = other.refit_cargo;
|
2007-06-20 21:17:22 +02:00
|
|
|
|
2008-04-05 23:45:05 +02:00
|
|
|
this->wait_time = other.wait_time;
|
|
|
|
this->travel_time = other.travel_time;
|
2012-02-14 18:04:06 +01:00
|
|
|
this->max_speed = other.max_speed;
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Recomputes everything.
|
|
|
|
* @param chain first order in the chain
|
|
|
|
* @param v one of vehicle that is using this orderlist
|
|
|
|
*/
|
2009-05-22 17:13:50 +02:00
|
|
|
void OrderList::Initialize(Order *chain, Vehicle *v)
|
2009-01-03 14:52:06 +01:00
|
|
|
{
|
2009-05-22 17:13:50 +02:00
|
|
|
this->first = chain;
|
|
|
|
this->first_shared = v;
|
|
|
|
|
|
|
|
this->num_orders = 0;
|
2010-12-26 14:25:34 +01:00
|
|
|
this->num_manual_orders = 0;
|
2009-05-22 17:13:50 +02:00
|
|
|
this->num_vehicles = 1;
|
|
|
|
this->timetable_duration = 0;
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
for (Order *o = this->first; o != nullptr; o = o->next) {
|
2009-01-03 14:52:06 +01:00
|
|
|
++this->num_orders;
|
2011-05-18 14:19:58 +02:00
|
|
|
if (!o->IsType(OT_IMPLICIT)) ++this->num_manual_orders;
|
2014-05-01 16:49:16 +02:00
|
|
|
this->total_duration += o->GetWaitTime() + o->GetTravelTime();
|
2009-01-03 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
2020-01-03 15:11:33 +01:00
|
|
|
this->RecalculateTimetableDuration();
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
for (Vehicle *u = this->first_shared->PreviousShared(); u != nullptr; u = u->PreviousShared()) {
|
2009-01-03 14:52:06 +01:00
|
|
|
++this->num_vehicles;
|
|
|
|
this->first_shared = u;
|
|
|
|
}
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
for (const Vehicle *u = v->NextShared(); u != nullptr; u = u->NextShared()) ++this->num_vehicles;
|
2009-01-03 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
2020-01-03 15:11:33 +01:00
|
|
|
/**
|
|
|
|
* Recomputes Timetable duration.
|
|
|
|
* Split out into a separate function so it can be used by afterload.
|
|
|
|
*/
|
|
|
|
void OrderList::RecalculateTimetableDuration()
|
|
|
|
{
|
|
|
|
this->timetable_duration = 0;
|
|
|
|
for (Order *o = this->first; o != nullptr; o = o->next) {
|
|
|
|
this->timetable_duration += o->GetTimetabledWait() + o->GetTimetabledTravel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Free a complete order chain.
|
|
|
|
* @param keep_orderlist If this is true only delete the orders, otherwise also delete the OrderList.
|
|
|
|
* @note do not use on "current_order" vehicle orders!
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
void OrderList::FreeChain(bool keep_orderlist)
|
|
|
|
{
|
|
|
|
Order *next;
|
2019-04-10 23:07:06 +02:00
|
|
|
for (Order *o = this->first; o != nullptr; o = next) {
|
2009-01-03 14:52:06 +01:00
|
|
|
next = o->next;
|
|
|
|
delete o;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keep_orderlist) {
|
2019-04-10 23:07:06 +02:00
|
|
|
this->first = nullptr;
|
2009-01-03 14:52:06 +01:00
|
|
|
this->num_orders = 0;
|
2010-12-26 14:25:34 +01:00
|
|
|
this->num_manual_orders = 0;
|
2009-01-03 14:52:06 +01:00
|
|
|
this->timetable_duration = 0;
|
|
|
|
} else {
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Get a certain order of the order chain.
|
|
|
|
* @param index zero-based index of the order within the chain.
|
|
|
|
* @return the order at position index.
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
Order *OrderList::GetOrderAt(int index) const
|
|
|
|
{
|
2019-04-10 23:07:06 +02:00
|
|
|
if (index < 0) return nullptr;
|
2009-01-03 14:52:06 +01:00
|
|
|
|
|
|
|
Order *order = this->first;
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
while (order != nullptr && index-- > 0) {
|
2009-01-03 14:52:06 +01:00
|
|
|
order = order->next;
|
2010-07-24 12:14:39 +02:00
|
|
|
}
|
2009-01-03 14:52:06 +01:00
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
2013-05-19 16:22:04 +02:00
|
|
|
/**
|
|
|
|
* Get the next order which will make the given vehicle stop at a station
|
2013-08-20 23:22:35 +02:00
|
|
|
* or refit at a depot or evaluate a non-trivial condition.
|
2013-05-19 16:22:04 +02:00
|
|
|
* @param next The order to start looking at.
|
|
|
|
* @param hops The number of orders we have already looked at.
|
2013-08-20 23:22:35 +02:00
|
|
|
* @return Either of
|
|
|
|
* \li a station order
|
|
|
|
* \li a refitting depot order
|
|
|
|
* \li a non-trivial conditional order
|
2019-04-10 23:07:06 +02:00
|
|
|
* \li nullptr if the vehicle won't stop anymore.
|
2013-05-19 16:22:04 +02:00
|
|
|
*/
|
2013-08-20 23:22:35 +02:00
|
|
|
const Order *OrderList::GetNextDecisionNode(const Order *next, uint hops) const
|
2013-05-19 16:22:04 +02:00
|
|
|
{
|
2019-04-10 23:07:06 +02:00
|
|
|
if (hops > this->GetNumOrders() || next == nullptr) return nullptr;
|
2013-05-19 16:22:04 +02:00
|
|
|
|
|
|
|
if (next->IsType(OT_CONDITIONAL)) {
|
2013-08-20 23:22:35 +02:00
|
|
|
if (next->GetConditionVariable() != OCV_UNCONDITIONALLY) return next;
|
|
|
|
|
|
|
|
/* We can evaluate trivial conditions right away. They're conceptually
|
|
|
|
* the same as regular order progression. */
|
|
|
|
return this->GetNextDecisionNode(
|
|
|
|
this->GetOrderAt(next->GetConditionSkipToOrder()),
|
|
|
|
hops + 1);
|
2013-05-19 16:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (next->IsType(OT_GOTO_DEPOT)) {
|
2019-04-10 23:07:06 +02:00
|
|
|
if (next->GetDepotActionType() == ODATFB_HALT) return nullptr;
|
2013-05-19 16:22:04 +02:00
|
|
|
if (next->IsRefit()) return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!next->CanLoadOrUnload()) {
|
2013-08-20 23:22:35 +02:00
|
|
|
return this->GetNextDecisionNode(this->GetNext(next), hops + 1);
|
2013-05-19 16:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively determine the next deterministic station to stop at.
|
|
|
|
* @param v The vehicle we're looking at.
|
2019-04-10 23:07:06 +02:00
|
|
|
* @param first Order to start searching at or nullptr to start at cur_implicit_order_index + 1.
|
2014-01-19 10:27:44 +01:00
|
|
|
* @param hops Number of orders we have already looked at.
|
2019-09-29 22:27:32 +02:00
|
|
|
* @return Next stopping station or INVALID_STATION.
|
2013-06-09 15:03:48 +02:00
|
|
|
* @pre The vehicle is currently loading and v->last_station_visited is meaningful.
|
|
|
|
* @note This function may draw a random number. Don't use it from the GUI.
|
2013-05-19 16:22:04 +02:00
|
|
|
*/
|
2014-01-19 10:27:44 +01:00
|
|
|
StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, const Order *first, uint hops) const
|
2013-05-19 16:22:04 +02:00
|
|
|
{
|
|
|
|
|
2013-08-20 23:22:35 +02:00
|
|
|
const Order *next = first;
|
2019-04-10 23:07:06 +02:00
|
|
|
if (first == nullptr) {
|
2013-08-20 23:22:35 +02:00
|
|
|
next = this->GetOrderAt(v->cur_implicit_order_index);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (next == nullptr) {
|
2013-08-20 23:22:35 +02:00
|
|
|
next = this->GetFirstOrder();
|
2019-04-10 23:07:06 +02:00
|
|
|
if (next == nullptr) return INVALID_STATION;
|
2013-08-20 23:22:35 +02:00
|
|
|
} else {
|
2019-04-10 23:07:06 +02:00
|
|
|
/* GetNext never returns nullptr if there is a valid station in the list.
|
2013-08-20 23:22:35 +02:00
|
|
|
* As the given "next" is already valid and a station in the list, we
|
2019-04-10 23:07:06 +02:00
|
|
|
* don't have to check for nullptr here. */
|
2013-08-20 23:22:35 +02:00
|
|
|
next = this->GetNext(next);
|
2019-04-10 23:07:06 +02:00
|
|
|
assert(next != nullptr);
|
2013-08-20 23:22:35 +02:00
|
|
|
}
|
2013-05-19 16:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2013-08-20 23:22:35 +02:00
|
|
|
next = this->GetNextDecisionNode(next, ++hops);
|
|
|
|
|
|
|
|
/* Resolve possibly nested conditionals by estimation. */
|
2019-04-10 23:07:06 +02:00
|
|
|
while (next != nullptr && next->IsType(OT_CONDITIONAL)) {
|
2014-01-19 10:27:44 +01:00
|
|
|
/* We return both options of conditional orders. */
|
|
|
|
const Order *skip_to = this->GetNextDecisionNode(
|
|
|
|
this->GetOrderAt(next->GetConditionSkipToOrder()), hops);
|
|
|
|
const Order *advance = this->GetNextDecisionNode(
|
|
|
|
this->GetNext(next), hops);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (advance == nullptr || advance == first || skip_to == advance) {
|
|
|
|
next = (skip_to == first) ? nullptr : skip_to;
|
|
|
|
} else if (skip_to == nullptr || skip_to == first) {
|
|
|
|
next = (advance == first) ? nullptr : advance;
|
2013-08-20 23:22:35 +02:00
|
|
|
} else {
|
2014-01-19 10:27:44 +01:00
|
|
|
StationIDStack st1 = this->GetNextStoppingStation(v, skip_to, hops);
|
|
|
|
StationIDStack st2 = this->GetNextStoppingStation(v, advance, hops);
|
|
|
|
while (!st2.IsEmpty()) st1.Push(st2.Pop());
|
|
|
|
return st1;
|
2013-08-20 23:22:35 +02:00
|
|
|
}
|
2014-01-19 10:27:44 +01:00
|
|
|
++hops;
|
2013-08-20 23:22:35 +02:00
|
|
|
}
|
|
|
|
|
2013-05-19 16:22:04 +02:00
|
|
|
/* Don't return a next stop if the vehicle has to unload everything. */
|
2019-04-10 23:07:06 +02:00
|
|
|
if (next == nullptr || ((next->IsType(OT_GOTO_STATION) || next->IsType(OT_IMPLICIT)) &&
|
2013-08-11 13:00:09 +02:00
|
|
|
next->GetDestination() == v->last_station_visited &&
|
|
|
|
(next->GetUnloadType() & (OUFB_TRANSFER | OUFB_UNLOAD)) != 0)) {
|
2013-05-19 16:22:04 +02:00
|
|
|
return INVALID_STATION;
|
|
|
|
}
|
|
|
|
} while (next->IsType(OT_GOTO_DEPOT) || next->GetDestination() == v->last_station_visited);
|
|
|
|
|
|
|
|
return next->GetDestination();
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Insert a new order into the order chain.
|
|
|
|
* @param new_order is the order to insert into the chain.
|
|
|
|
* @param index is the position where the order is supposed to be inserted.
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
void OrderList::InsertOrderAt(Order *new_order, int index)
|
|
|
|
{
|
2019-04-10 23:07:06 +02:00
|
|
|
if (this->first == nullptr) {
|
2009-01-03 14:52:06 +01:00
|
|
|
this->first = new_order;
|
|
|
|
} else {
|
|
|
|
if (index == 0) {
|
|
|
|
/* Insert as first or only order */
|
|
|
|
new_order->next = this->first;
|
|
|
|
this->first = new_order;
|
|
|
|
} else if (index >= this->num_orders) {
|
|
|
|
/* index is after the last order, add it to the end */
|
|
|
|
this->GetLastOrder()->next = new_order;
|
|
|
|
} else {
|
|
|
|
/* Put the new order in between */
|
|
|
|
Order *order = this->GetOrderAt(index - 1);
|
|
|
|
new_order->next = order->next;
|
|
|
|
order->next = new_order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++this->num_orders;
|
2011-05-18 14:19:58 +02:00
|
|
|
if (!new_order->IsType(OT_IMPLICIT)) ++this->num_manual_orders;
|
2014-05-01 16:49:16 +02:00
|
|
|
this->timetable_duration += new_order->GetTimetabledWait() + new_order->GetTimetabledTravel();
|
|
|
|
this->total_duration += new_order->GetWaitTime() + new_order->GetTravelTime();
|
2011-11-12 19:06:34 +01:00
|
|
|
|
|
|
|
/* We can visit oil rigs and buoys that are not our own. They will be shown in
|
|
|
|
* the list of stations. So, we need to invalidate that window if needed. */
|
|
|
|
if (new_order->IsType(OT_GOTO_STATION) || new_order->IsType(OT_GOTO_WAYPOINT)) {
|
|
|
|
BaseStation *bs = BaseStation::Get(new_order->GetDestination());
|
|
|
|
if (bs->owner == OWNER_NONE) InvalidateWindowClassesData(WC_STATION_LIST, 0);
|
|
|
|
}
|
|
|
|
|
2009-01-03 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Remove an order from the order list and delete it.
|
|
|
|
* @param index is the position of the order which is to be deleted.
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
void OrderList::DeleteOrderAt(int index)
|
|
|
|
{
|
|
|
|
if (index >= this->num_orders) return;
|
|
|
|
|
|
|
|
Order *to_remove;
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
to_remove = this->first;
|
|
|
|
this->first = to_remove->next;
|
|
|
|
} else {
|
|
|
|
Order *prev = GetOrderAt(index - 1);
|
|
|
|
to_remove = prev->next;
|
|
|
|
prev->next = to_remove->next;
|
|
|
|
}
|
|
|
|
--this->num_orders;
|
2011-05-18 14:19:58 +02:00
|
|
|
if (!to_remove->IsType(OT_IMPLICIT)) --this->num_manual_orders;
|
2014-05-01 16:49:16 +02:00
|
|
|
this->timetable_duration -= (to_remove->GetTimetabledWait() + to_remove->GetTimetabledTravel());
|
|
|
|
this->total_duration -= (to_remove->GetWaitTime() + to_remove->GetTravelTime());
|
2009-01-03 14:52:06 +01:00
|
|
|
delete to_remove;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Move an order to another position within the order list.
|
|
|
|
* @param from is the zero-based position of the order to move.
|
|
|
|
* @param to is the zero-based position where the order is moved to.
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
void OrderList::MoveOrder(int from, int to)
|
|
|
|
{
|
|
|
|
if (from >= this->num_orders || to >= this->num_orders || from == to) return;
|
|
|
|
|
|
|
|
Order *moving_one;
|
|
|
|
|
|
|
|
/* Take the moving order out of the pointer-chain */
|
|
|
|
if (from == 0) {
|
|
|
|
moving_one = this->first;
|
|
|
|
this->first = moving_one->next;
|
|
|
|
} else {
|
|
|
|
Order *one_before = GetOrderAt(from - 1);
|
|
|
|
moving_one = one_before->next;
|
|
|
|
one_before->next = moving_one->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert the moving_order again in the pointer-chain */
|
|
|
|
if (to == 0) {
|
|
|
|
moving_one->next = this->first;
|
|
|
|
this->first = moving_one;
|
|
|
|
} else {
|
|
|
|
Order *one_before = GetOrderAt(to - 1);
|
|
|
|
moving_one->next = one_before->next;
|
|
|
|
one_before->next = moving_one;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Removes the vehicle from the shared order list.
|
|
|
|
* @note This is supposed to be called when the vehicle is still in the chain
|
|
|
|
* @param v vehicle to remove from the list
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
void OrderList::RemoveVehicle(Vehicle *v)
|
|
|
|
{
|
|
|
|
--this->num_vehicles;
|
|
|
|
if (v == this->first_shared) this->first_shared = v->NextShared();
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Checks whether a vehicle is part of the shared vehicle chain.
|
|
|
|
* @param v is the vehicle to search in the shared vehicle chain.
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
bool OrderList::IsVehicleInSharedOrdersList(const Vehicle *v) const
|
|
|
|
{
|
2019-04-10 23:07:06 +02:00
|
|
|
for (const Vehicle *v_shared = this->first_shared; v_shared != nullptr; v_shared = v_shared->NextShared()) {
|
2009-01-03 14:52:06 +01:00
|
|
|
if (v_shared == v) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Gets the position of the given vehicle within the shared order vehicle list.
|
|
|
|
* @param v is the vehicle of which to get the position
|
|
|
|
* @return position of v within the shared vehicle chain.
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
int OrderList::GetPositionInSharedOrderList(const Vehicle *v) const
|
|
|
|
{
|
|
|
|
int count = 0;
|
2019-04-10 23:07:06 +02:00
|
|
|
for (const Vehicle *v_shared = v->PreviousShared(); v_shared != nullptr; v_shared = v_shared->PreviousShared()) count++;
|
2009-01-03 14:52:06 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Checks whether all orders of the list have a filled timetable.
|
|
|
|
* @return whether all orders have a filled timetable.
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
bool OrderList::IsCompleteTimetable() const
|
|
|
|
{
|
2019-04-10 23:07:06 +02:00
|
|
|
for (Order *o = this->first; o != nullptr; o = o->next) {
|
2011-05-18 14:19:58 +02:00
|
|
|
/* Implicit orders are, by definition, not timetabled. */
|
|
|
|
if (o->IsType(OT_IMPLICIT)) continue;
|
2009-01-03 14:52:06 +01:00
|
|
|
if (!o->IsCompletelyTimetabled()) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Checks for internal consistency of order list. Triggers assertion if something is wrong.
|
|
|
|
*/
|
2009-01-03 14:52:06 +01:00
|
|
|
void OrderList::DebugCheckSanity() const
|
|
|
|
{
|
|
|
|
VehicleOrderID check_num_orders = 0;
|
2010-12-26 14:25:34 +01:00
|
|
|
VehicleOrderID check_num_manual_orders = 0;
|
2009-01-03 18:28:22 +01:00
|
|
|
uint check_num_vehicles = 0;
|
2009-11-21 13:43:09 +01:00
|
|
|
Ticks check_timetable_duration = 0;
|
2014-05-01 16:49:16 +02:00
|
|
|
Ticks check_total_duration = 0;
|
2009-01-03 14:52:06 +01:00
|
|
|
|
|
|
|
DEBUG(misc, 6, "Checking OrderList %hu for sanity...", this->index);
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
for (const Order *o = this->first; o != nullptr; o = o->next) {
|
2009-01-03 14:52:06 +01:00
|
|
|
++check_num_orders;
|
2011-05-18 14:19:58 +02:00
|
|
|
if (!o->IsType(OT_IMPLICIT)) ++check_num_manual_orders;
|
2014-05-01 16:49:16 +02:00
|
|
|
check_timetable_duration += o->GetTimetabledWait() + o->GetTimetabledTravel();
|
|
|
|
check_total_duration += o->GetWaitTime() + o->GetTravelTime();
|
2009-01-03 14:52:06 +01:00
|
|
|
}
|
|
|
|
assert(this->num_orders == check_num_orders);
|
2010-12-26 14:25:34 +01:00
|
|
|
assert(this->num_manual_orders == check_num_manual_orders);
|
2009-01-03 14:52:06 +01:00
|
|
|
assert(this->timetable_duration == check_timetable_duration);
|
2014-05-01 16:49:16 +02:00
|
|
|
assert(this->total_duration == check_total_duration);
|
2009-01-03 14:52:06 +01:00
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
for (const Vehicle *v = this->first_shared; v != nullptr; v = v->NextShared()) {
|
2009-01-03 14:52:06 +01:00
|
|
|
++check_num_vehicles;
|
|
|
|
assert(v->orders.list == this);
|
|
|
|
}
|
|
|
|
assert(this->num_vehicles == check_num_vehicles);
|
2014-05-01 16:49:16 +02:00
|
|
|
DEBUG(misc, 6, "... detected %u orders (%u manual), %u vehicles, %i timetabled, %i total",
|
2010-12-26 14:25:34 +01:00
|
|
|
(uint)this->num_orders, (uint)this->num_manual_orders,
|
2014-05-01 16:49:16 +02:00
|
|
|
this->num_vehicles, this->timetable_duration, this->total_duration);
|
2009-01-03 14:52:06 +01:00
|
|
|
}
|
|
|
|
|
2009-01-10 14:00:38 +01:00
|
|
|
/**
|
|
|
|
* Checks whether the order goes to a station or not, i.e. whether the
|
|
|
|
* destination is a station
|
|
|
|
* @param v the vehicle to check for
|
|
|
|
* @param o the order to check
|
|
|
|
* @return true if the destination is a station
|
|
|
|
*/
|
|
|
|
static inline bool OrderGoesToStation(const Vehicle *v, const Order *o)
|
|
|
|
{
|
|
|
|
return o->IsType(OT_GOTO_STATION) ||
|
|
|
|
(v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && !(o->GetDepotActionType() & ODATFB_NEAREST_DEPOT));
|
|
|
|
}
|
|
|
|
|
2006-03-04 12:01:35 +01:00
|
|
|
/**
|
|
|
|
* Delete all news items regarding defective orders about a vehicle
|
|
|
|
* This could kill still valid warnings (for example about void order when just
|
2008-09-30 22:39:50 +02:00
|
|
|
* another order gets added), but assume the company will notice the problems,
|
2006-03-04 12:01:35 +01:00
|
|
|
* when (s)he's changing the orders.
|
|
|
|
*/
|
2009-01-10 01:31:47 +01:00
|
|
|
static void DeleteOrderWarnings(const Vehicle *v)
|
2006-03-04 12:01:35 +01:00
|
|
|
{
|
2009-08-04 20:04:33 +02:00
|
|
|
DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS);
|
|
|
|
DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_VOID_ORDER);
|
|
|
|
DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY);
|
|
|
|
DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_INVALID_ENTRY);
|
2014-05-06 22:50:58 +02:00
|
|
|
DeleteVehicleNews(v->index, STR_NEWS_PLANE_USES_TOO_SHORT_RUNWAY);
|
2006-03-04 12:01:35 +01:00
|
|
|
}
|
|
|
|
|
2010-02-22 21:36:20 +01:00
|
|
|
/**
|
|
|
|
* Returns a tile somewhat representing the order destination (not suitable for pathfinding).
|
|
|
|
* @param v The vehicle to get the location for.
|
2011-12-13 01:43:35 +01:00
|
|
|
* @param airport Get the airport tile and not the station location for aircraft.
|
2010-02-22 21:36:20 +01:00
|
|
|
* @return destination of order, or INVALID_TILE if none.
|
|
|
|
*/
|
2011-12-13 01:43:35 +01:00
|
|
|
TileIndex Order::GetLocation(const Vehicle *v, bool airport) const
|
2007-02-18 17:24:29 +01:00
|
|
|
{
|
2010-02-22 21:36:20 +01:00
|
|
|
switch (this->GetType()) {
|
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
|
case OT_GOTO_STATION:
|
2011-05-18 14:19:58 +02:00
|
|
|
case OT_IMPLICIT:
|
2011-12-13 01:43:35 +01:00
|
|
|
if (airport && v->type == VEH_AIRCRAFT) return Station::Get(this->GetDestination())->airport.tile;
|
2010-02-22 21:36:20 +01:00
|
|
|
return BaseStation::Get(this->GetDestination())->xy;
|
|
|
|
|
2010-02-22 21:08:16 +01:00
|
|
|
case OT_GOTO_DEPOT:
|
2010-02-22 21:36:20 +01:00
|
|
|
if ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE;
|
|
|
|
return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination())->xy : Depot::Get(this->GetDestination())->xy;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return INVALID_TILE;
|
2007-02-18 17:24:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 01:43:48 +01:00
|
|
|
/**
|
|
|
|
* Get the distance between two orders of a vehicle. Conditional orders are resolved
|
|
|
|
* and the bigger distance of the two order branches is returned.
|
|
|
|
* @param prev Origin order.
|
|
|
|
* @param cur Destination order.
|
|
|
|
* @param v The vehicle to get the distance for.
|
|
|
|
* @param conditional_depth Internal param for resolving conditional orders.
|
|
|
|
* @return Maximum distance between the two orders.
|
|
|
|
*/
|
|
|
|
uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
|
2008-06-30 16:49:50 +02:00
|
|
|
{
|
|
|
|
if (cur->IsType(OT_CONDITIONAL)) {
|
2009-01-03 14:20:32 +01:00
|
|
|
if (conditional_depth > v->GetNumOrders()) return 0;
|
2008-06-30 16:49:50 +02:00
|
|
|
|
|
|
|
conditional_depth++;
|
2008-09-14 10:47:18 +02:00
|
|
|
|
2009-05-23 14:27:42 +02:00
|
|
|
int dist1 = GetOrderDistance(prev, v->GetOrder(cur->GetConditionSkipToOrder()), v, conditional_depth);
|
2019-04-10 23:07:06 +02:00
|
|
|
int dist2 = GetOrderDistance(prev, cur->next == nullptr ? v->orders.list->GetFirstOrder() : cur->next, v, conditional_depth);
|
2008-09-14 10:47:18 +02:00
|
|
|
return max(dist1, dist2);
|
2008-06-30 16:49:50 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 01:43:35 +01:00
|
|
|
TileIndex prev_tile = prev->GetLocation(v, true);
|
|
|
|
TileIndex cur_tile = cur->GetLocation(v, true);
|
2010-02-22 21:08:16 +01:00
|
|
|
if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0;
|
2011-12-13 01:43:35 +01:00
|
|
|
return v->type == VEH_AIRCRAFT ? DistanceSquare(prev_tile, cur_tile) : DistanceManhattan(prev_tile, cur_tile);
|
2008-06-30 16:49:50 +02:00
|
|
|
}
|
2007-02-18 17:24:29 +01:00
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Add an order to the orderlist of a vehicle.
|
2006-04-10 09:15:58 +02:00
|
|
|
* @param tile unused
|
2007-04-17 22:23:13 +02:00
|
|
|
* @param flags operation to perform
|
2005-05-11 02:00:27 +02:00
|
|
|
* @param p1 various bitstuffed elements
|
2010-08-19 22:39:12 +02:00
|
|
|
* - p1 = (bit 0 - 19) - ID of the vehicle
|
|
|
|
* - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given,
|
2005-07-20 17:29:28 +02:00
|
|
|
* the order will be inserted before that one
|
2009-02-04 14:52:17 +01:00
|
|
|
* the maximum vehicle order id is 254.
|
2005-05-11 02:00:27 +02:00
|
|
|
* @param p2 packed order to insert
|
2009-09-18 16:23:58 +02:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-01-15 20:06:22 +01:00
|
|
|
*/
|
2009-02-09 22:20:05 +01:00
|
|
|
CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2005-01-15 20:06:22 +01:00
|
|
|
{
|
2010-08-19 22:39:12 +02:00
|
|
|
VehicleID veh = GB(p1, 0, 20);
|
|
|
|
VehicleOrderID sel_ord = GB(p1, 20, 8);
|
2008-04-06 09:22:26 +02:00
|
|
|
Order new_order(p2);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-05-18 18:21:28 +02:00
|
|
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(v->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2005-05-11 02:00:27 +02:00
|
|
|
/* Check if the inserted order is to the correct destination (owner, type),
|
|
|
|
* and has the correct flags if any */
|
2008-04-06 01:36:54 +02:00
|
|
|
switch (new_order.GetType()) {
|
2005-04-22 07:41:09 +02:00
|
|
|
case OT_GOTO_STATION: {
|
2009-05-18 18:21:28 +02:00
|
|
|
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
2019-04-10 23:07:06 +02:00
|
|
|
if (st == nullptr) return CMD_ERROR;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2010-03-13 18:11:28 +01:00
|
|
|
if (st->owner != OWNER_NONE) {
|
|
|
|
CommandCost ret = CheckOwnership(st->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
}
|
2009-01-10 14:00:38 +01:00
|
|
|
|
2009-04-22 01:40:56 +02:00
|
|
|
if (!CanVehicleUseStation(v, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
2019-04-10 23:07:06 +02:00
|
|
|
for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
|
2009-04-22 01:40:56 +02:00
|
|
|
if (!CanVehicleUseStation(u, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER_SHARED);
|
2009-01-10 14:00:38 +01:00
|
|
|
}
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2010-12-14 22:26:03 +01:00
|
|
|
/* Non stop only allowed for ground vehicles. */
|
|
|
|
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
|
2008-04-06 23:54:22 +02:00
|
|
|
|
2008-04-07 22:18:51 +02:00
|
|
|
/* Filter invalid load/unload types. */
|
2008-04-09 20:26:19 +02:00
|
|
|
switch (new_order.GetLoadType()) {
|
2008-05-05 00:57:50 +02:00
|
|
|
case OLF_LOAD_IF_POSSIBLE: case OLFB_FULL_LOAD: case OLF_FULL_LOAD_ANY: case OLFB_NO_LOAD: break;
|
|
|
|
default: return CMD_ERROR;
|
|
|
|
}
|
|
|
|
switch (new_order.GetUnloadType()) {
|
|
|
|
case OUF_UNLOAD_IF_POSSIBLE: case OUFB_UNLOAD: case OUFB_TRANSFER: case OUFB_NO_UNLOAD: break;
|
2008-04-09 20:26:19 +02:00
|
|
|
default: return CMD_ERROR;
|
|
|
|
}
|
2009-04-12 16:11:14 +02:00
|
|
|
|
|
|
|
/* Filter invalid stop locations */
|
|
|
|
switch (new_order.GetStopLocation()) {
|
|
|
|
case OSL_PLATFORM_NEAR_END:
|
|
|
|
case OSL_PLATFORM_MIDDLE:
|
|
|
|
if (v->type != VEH_TRAIN) return CMD_ERROR;
|
2017-08-13 20:38:42 +02:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
2009-04-12 16:11:14 +02:00
|
|
|
case OSL_PLATFORM_FAR_END:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-04-22 07:41:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OT_GOTO_DEPOT: {
|
2010-08-10 18:45:32 +02:00
|
|
|
if ((new_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) == 0) {
|
2008-04-11 17:58:46 +02:00
|
|
|
if (v->type == VEH_AIRCRAFT) {
|
2009-05-18 18:21:28 +02:00
|
|
|
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
if (st == nullptr) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(st->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
|
2010-03-19 10:48:44 +01:00
|
|
|
if (!CanVehicleUseStation(v, st) || !st->airport.HasHangar()) {
|
2008-04-11 17:58:46 +02:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
2009-05-18 18:21:28 +02:00
|
|
|
const Depot *dp = Depot::GetIfValid(new_order.GetDestination());
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
if (dp == nullptr) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(GetTileOwner(dp->xy));
|
|
|
|
if (ret.Failed()) return ret;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2008-04-11 17:58:46 +02:00
|
|
|
switch (v->type) {
|
|
|
|
case VEH_TRAIN:
|
2008-04-17 20:24:45 +02:00
|
|
|
if (!IsRailDepotTile(dp->xy)) return CMD_ERROR;
|
2008-04-11 17:58:46 +02:00
|
|
|
break;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2008-04-11 17:58:46 +02:00
|
|
|
case VEH_ROAD:
|
2008-04-17 20:24:45 +02:00
|
|
|
if (!IsRoadDepotTile(dp->xy)) return CMD_ERROR;
|
2008-04-11 17:58:46 +02:00
|
|
|
break;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2008-04-11 17:58:46 +02:00
|
|
|
case VEH_SHIP:
|
2008-04-17 20:24:45 +02:00
|
|
|
if (!IsShipDepotTile(dp->xy)) return CMD_ERROR;
|
2008-04-11 17:58:46 +02:00
|
|
|
break;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2008-04-11 17:58:46 +02:00
|
|
|
default: return CMD_ERROR;
|
|
|
|
}
|
2005-04-22 07:41:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-14 22:26:03 +01:00
|
|
|
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
|
2008-06-25 21:33:11 +02:00
|
|
|
if (new_order.GetDepotOrderType() & ~(ODTFB_PART_OF_ORDERS | ((new_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0 ? ODTFB_SERVICE : 0))) return CMD_ERROR;
|
2009-04-21 01:49:27 +02:00
|
|
|
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;
|
2005-04-22 07:41:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OT_GOTO_WAYPOINT: {
|
2009-07-22 10:59:57 +02:00
|
|
|
const Waypoint *wp = Waypoint::GetIfValid(new_order.GetDestination());
|
2019-04-10 23:07:06 +02:00
|
|
|
if (wp == nullptr) return CMD_ERROR;
|
2009-07-22 10:59:57 +02:00
|
|
|
|
2009-07-10 20:30:02 +02:00
|
|
|
switch (v->type) {
|
|
|
|
default: return CMD_ERROR;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2010-03-13 18:11:28 +01:00
|
|
|
case VEH_TRAIN: {
|
2009-12-05 20:21:43 +01:00
|
|
|
if (!(wp->facilities & FACIL_TRAIN)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(wp->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2009-07-22 10:59:57 +02:00
|
|
|
break;
|
2010-03-13 18:11:28 +01:00
|
|
|
}
|
2009-07-10 20:30:02 +02:00
|
|
|
|
2009-07-22 10:59:57 +02:00
|
|
|
case VEH_SHIP:
|
2009-12-05 20:21:43 +01:00
|
|
|
if (!(wp->facilities & FACIL_DOCK)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
2010-03-13 18:11:28 +01:00
|
|
|
if (wp->owner != OWNER_NONE) {
|
|
|
|
CommandCost ret = CheckOwnership(wp->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
}
|
2009-07-22 10:59:57 +02:00
|
|
|
break;
|
2009-07-10 20:30:02 +02:00
|
|
|
}
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2005-09-16 18:03:18 +02:00
|
|
|
/* Order flags can be any of the following for waypoints:
|
|
|
|
* [non-stop]
|
|
|
|
* non-stop orders (if any) are only valid for trains */
|
2008-04-10 10:30:15 +02:00
|
|
|
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
|
2008-04-08 18:15:31 +02:00
|
|
|
break;
|
2005-04-22 07:41:09 +02:00
|
|
|
}
|
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
case OT_CONDITIONAL: {
|
|
|
|
VehicleOrderID skip_to = new_order.GetConditionSkipToOrder();
|
2009-01-03 14:20:32 +01:00
|
|
|
if (skip_to != 0 && skip_to >= v->GetNumOrders()) return CMD_ERROR; // Always allow jumping to the first (even when there is no order).
|
2011-08-26 18:39:02 +02:00
|
|
|
if (new_order.GetConditionVariable() >= OCV_END) return CMD_ERROR;
|
2008-07-20 09:41:43 +02:00
|
|
|
|
|
|
|
OrderConditionComparator occ = new_order.GetConditionComparator();
|
2011-08-26 18:39:02 +02:00
|
|
|
if (occ >= OCC_END) return CMD_ERROR;
|
2008-07-20 09:41:43 +02:00
|
|
|
switch (new_order.GetConditionVariable()) {
|
|
|
|
case OCV_REQUIRES_SERVICE:
|
2008-07-20 14:59:27 +02:00
|
|
|
if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) return CMD_ERROR;
|
2008-07-20 09:41:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OCV_UNCONDITIONALLY:
|
2008-07-20 14:59:27 +02:00
|
|
|
if (occ != OCC_EQUALS) return CMD_ERROR;
|
|
|
|
if (new_order.GetConditionValue() != 0) return CMD_ERROR;
|
2008-07-20 09:41:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OCV_LOAD_PERCENTAGE:
|
|
|
|
case OCV_RELIABILITY:
|
2008-07-20 14:59:27 +02:00
|
|
|
if (new_order.GetConditionValue() > 100) return CMD_ERROR;
|
2017-08-13 20:38:42 +02:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
2008-07-20 09:41:43 +02:00
|
|
|
default:
|
2008-07-20 14:59:27 +02:00
|
|
|
if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) return CMD_ERROR;
|
2008-07-20 09:41:43 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-08-01 20:53:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-04-12 13:58:19 +02:00
|
|
|
|
2005-05-11 02:00:27 +02:00
|
|
|
default: return CMD_ERROR;
|
2005-04-22 07:41:09 +02:00
|
|
|
}
|
|
|
|
|
2009-01-03 14:20:32 +01:00
|
|
|
if (sel_ord > v->GetNumOrders()) return CMD_ERROR;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-04-22 01:40:56 +02:00
|
|
|
if (v->GetNumOrders() >= MAX_VEH_ORDER_ID) return_cmd_error(STR_ERROR_TOO_MANY_ORDERS);
|
|
|
|
if (!Order::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v->orders.list == nullptr && !OrderList::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
if (flags & DC_EXEC) {
|
2007-08-03 01:40:19 +02:00
|
|
|
Order *new_o = new Order();
|
2008-04-05 23:45:05 +02:00
|
|
|
new_o->AssignOrder(new_order);
|
2010-12-22 22:16:34 +01:00
|
|
|
InsertOrder(v, new_o, sel_ord);
|
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
return CommandCost();
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
/**
|
|
|
|
* Insert a new order but skip the validation.
|
|
|
|
* @param v The vehicle to insert the order to.
|
|
|
|
* @param new_o The new order.
|
|
|
|
* @param sel_ord The position the order should be inserted at.
|
|
|
|
*/
|
|
|
|
void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
|
|
|
|
{
|
|
|
|
/* Create new order and link in list */
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v->orders.list == nullptr) {
|
2010-12-22 22:16:34 +01:00
|
|
|
v->orders.list = new OrderList(new_o, v);
|
|
|
|
} else {
|
|
|
|
v->orders.list->InsertOrderAt(new_o, sel_ord);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vehicle *u = v->FirstShared();
|
|
|
|
DeleteOrderWarnings(u);
|
2019-04-10 23:07:06 +02:00
|
|
|
for (; u != nullptr; u = u->NextShared()) {
|
2010-12-22 22:16:34 +01:00
|
|
|
assert(v->orders.list == u->orders.list);
|
|
|
|
|
|
|
|
/* If there is added an order before the current one, we need
|
2011-05-18 14:19:58 +02:00
|
|
|
* to update the selected order. We do not change implicit/real order indices though.
|
|
|
|
* If the new order is between the current implicit order and real order, the implicit order will
|
2011-01-31 21:44:15 +01:00
|
|
|
* later skip the inserted order. */
|
|
|
|
if (sel_ord <= u->cur_real_order_index) {
|
|
|
|
uint cur = u->cur_real_order_index + 1;
|
2010-12-22 22:16:34 +01:00
|
|
|
/* Check if we don't go out of bound */
|
|
|
|
if (cur < u->GetNumOrders()) {
|
2011-01-31 21:44:15 +01:00
|
|
|
u->cur_real_order_index = cur;
|
|
|
|
}
|
|
|
|
}
|
2011-05-18 14:19:58 +02:00
|
|
|
if (sel_ord == u->cur_implicit_order_index && u->IsGroundVehicle()) {
|
|
|
|
/* We are inserting an order just before the current implicit order.
|
|
|
|
* We do not know whether we will reach current implicit or the newly inserted order first.
|
|
|
|
* So, disable creation of implicit orders until we are on track again. */
|
2011-04-16 19:06:59 +02:00
|
|
|
uint16 &gv_flags = u->GetGroundVehicleFlags();
|
2011-05-18 14:19:58 +02:00
|
|
|
SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
|
2011-04-16 19:06:59 +02:00
|
|
|
}
|
2011-05-18 14:19:58 +02:00
|
|
|
if (sel_ord <= u->cur_implicit_order_index) {
|
|
|
|
uint cur = u->cur_implicit_order_index + 1;
|
2011-01-31 21:44:15 +01:00
|
|
|
/* Check if we don't go out of bound */
|
|
|
|
if (cur < u->GetNumOrders()) {
|
2011-05-18 14:19:58 +02:00
|
|
|
u->cur_implicit_order_index = cur;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
}
|
2010-12-22 22:16:34 +01:00
|
|
|
/* Update any possible open window of the vehicle */
|
|
|
|
InvalidateVehicleOrder(u, INVALID_VEH_ORDER_ID | (sel_ord << 8));
|
|
|
|
}
|
2004-12-10 19:16:08 +01:00
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
/* As we insert an order, the order to skip to will be 'wrong'. */
|
|
|
|
VehicleOrderID cur_order_id = 0;
|
|
|
|
Order *order;
|
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
if (order->IsType(OT_CONDITIONAL)) {
|
|
|
|
VehicleOrderID order_id = order->GetConditionSkipToOrder();
|
|
|
|
if (order_id >= sel_ord) {
|
|
|
|
order->SetConditionSkipToOrder(order_id + 1);
|
|
|
|
}
|
|
|
|
if (order_id == cur_order_id) {
|
|
|
|
order->SetConditionSkipToOrder((order_id + 1) % v->GetNumOrders());
|
2008-04-12 13:58:19 +02:00
|
|
|
}
|
|
|
|
}
|
2010-12-22 22:16:34 +01:00
|
|
|
cur_order_id++;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
/* Make sure to rebuild the whole list */
|
|
|
|
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Declone an order-list
|
2005-05-11 02:00:27 +02:00
|
|
|
* @param *dst delete the orders of this vehicle
|
|
|
|
* @param flags execution flags
|
2005-01-15 20:06:22 +01:00
|
|
|
*/
|
2009-02-09 22:20:05 +01:00
|
|
|
static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
|
|
|
if (flags & DC_EXEC) {
|
2005-01-15 20:06:22 +01:00
|
|
|
DeleteVehicleOrders(dst);
|
2012-12-20 20:44:02 +01:00
|
|
|
InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
|
2008-05-18 18:51:44 +02:00
|
|
|
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2007-06-18 21:53:50 +02:00
|
|
|
return CommandCost();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Delete an order from the orderlist of a vehicle.
|
2006-04-10 09:15:58 +02:00
|
|
|
* @param tile unused
|
2007-04-17 22:23:13 +02:00
|
|
|
* @param flags operation to perform
|
2005-05-11 02:00:27 +02:00
|
|
|
* @param p1 the ID of the vehicle
|
|
|
|
* @param p2 the order to delete (max 255)
|
2009-09-18 16:23:58 +02:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2004-08-09 19:04:08 +02:00
|
|
|
*/
|
2009-02-09 22:20:05 +01:00
|
|
|
CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2010-08-19 22:39:12 +02:00
|
|
|
VehicleID veh_id = GB(p1, 0, 20);
|
|
|
|
VehicleOrderID sel_ord = GB(p2, 0, 8);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-05-18 18:21:28 +02:00
|
|
|
Vehicle *v = Vehicle::GetIfValid(veh_id);
|
2006-08-22 20:15:17 +02:00
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(v->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* If we did not select an order, we maybe want to de-clone the orders */
|
2010-07-24 12:14:39 +02:00
|
|
|
if (sel_ord >= v->GetNumOrders()) return DecloneOrder(v, flags);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v->GetOrder(sel_ord) == nullptr) return CMD_ERROR;
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
if (flags & DC_EXEC) DeleteOrder(v, sel_ord);
|
|
|
|
return CommandCost();
|
|
|
|
}
|
|
|
|
|
2011-02-09 22:39:22 +01:00
|
|
|
/**
|
|
|
|
* Cancel the current loading order of the vehicle as the order was deleted.
|
|
|
|
* @param v the vehicle
|
|
|
|
*/
|
|
|
|
static void CancelLoadingDueToDeletedOrder(Vehicle *v)
|
|
|
|
{
|
|
|
|
assert(v->current_order.IsType(OT_LOADING));
|
|
|
|
/* NON-stop flag is misused to see if a train is in a station that is
|
|
|
|
* on his order list or not */
|
|
|
|
v->current_order.SetNonStopType(ONSF_STOP_EVERYWHERE);
|
|
|
|
/* When full loading, "cancel" that order so the vehicle doesn't
|
|
|
|
* stay indefinitely at this station anymore. */
|
|
|
|
if (v->current_order.GetLoadType() & OLFB_FULL_LOAD) v->current_order.SetLoadType(OLF_LOAD_IF_POSSIBLE);
|
|
|
|
}
|
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
/**
|
|
|
|
* Delete an order but skip the parameter validation.
|
|
|
|
* @param v The vehicle to delete the order from.
|
|
|
|
* @param sel_ord The id of the order to be deleted.
|
|
|
|
*/
|
|
|
|
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
|
|
|
|
{
|
|
|
|
v->orders.list->DeleteOrderAt(sel_ord);
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
Vehicle *u = v->FirstShared();
|
|
|
|
DeleteOrderWarnings(u);
|
2019-04-10 23:07:06 +02:00
|
|
|
for (; u != nullptr; u = u->NextShared()) {
|
2010-12-22 22:16:34 +01:00
|
|
|
assert(v->orders.list == u->orders.list);
|
|
|
|
|
2011-01-31 21:44:15 +01:00
|
|
|
if (sel_ord == u->cur_real_order_index && u->current_order.IsType(OT_LOADING)) {
|
2011-02-09 22:39:22 +01:00
|
|
|
CancelLoadingDueToDeletedOrder(u);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2004-12-10 19:16:08 +01:00
|
|
|
|
2011-01-31 21:44:15 +01:00
|
|
|
if (sel_ord < u->cur_real_order_index) {
|
|
|
|
u->cur_real_order_index--;
|
|
|
|
} else if (sel_ord == u->cur_real_order_index) {
|
|
|
|
u->UpdateRealOrderIndex();
|
|
|
|
}
|
|
|
|
|
2011-05-18 14:19:58 +02:00
|
|
|
if (sel_ord < u->cur_implicit_order_index) {
|
|
|
|
u->cur_implicit_order_index--;
|
|
|
|
} else if (sel_ord == u->cur_implicit_order_index) {
|
2011-01-31 21:44:15 +01:00
|
|
|
/* Make sure the index is valid */
|
2011-05-18 14:19:58 +02:00
|
|
|
if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0;
|
2011-01-31 21:44:15 +01:00
|
|
|
|
2011-05-18 14:19:58 +02:00
|
|
|
/* Skip non-implicit orders for the implicit-order-index (e.g. if the current implicit order was deleted */
|
|
|
|
while (u->cur_implicit_order_index != u->cur_real_order_index && !u->GetOrder(u->cur_implicit_order_index)->IsType(OT_IMPLICIT)) {
|
|
|
|
u->cur_implicit_order_index++;
|
|
|
|
if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0;
|
2011-01-31 21:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-06 23:24:02 +01:00
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
/* Update any possible open window of the vehicle */
|
|
|
|
InvalidateVehicleOrder(u, sel_ord | (INVALID_VEH_ORDER_ID << 8));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* As we delete an order, the order to skip to will be 'wrong'. */
|
|
|
|
VehicleOrderID cur_order_id = 0;
|
2019-04-10 23:07:06 +02:00
|
|
|
Order *order = nullptr;
|
2010-12-22 22:16:34 +01:00
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
if (order->IsType(OT_CONDITIONAL)) {
|
|
|
|
VehicleOrderID order_id = order->GetConditionSkipToOrder();
|
|
|
|
if (order_id >= sel_ord) {
|
2011-04-16 18:26:08 +02:00
|
|
|
order_id = max(order_id - 1, 0);
|
2010-12-22 22:16:34 +01:00
|
|
|
}
|
|
|
|
if (order_id == cur_order_id) {
|
2011-04-16 18:26:08 +02:00
|
|
|
order_id = (order_id + 1) % v->GetNumOrders();
|
2008-04-12 13:58:19 +02:00
|
|
|
}
|
2011-04-16 18:26:08 +02:00
|
|
|
order->SetConditionSkipToOrder(order_id);
|
2008-04-12 13:58:19 +02:00
|
|
|
}
|
2010-12-22 22:16:34 +01:00
|
|
|
cur_order_id++;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2010-12-22 22:16:34 +01:00
|
|
|
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Goto order of order-list.
|
2006-04-10 09:15:58 +02:00
|
|
|
* @param tile unused
|
2007-04-17 22:23:13 +02:00
|
|
|
* @param flags operation to perform
|
2005-05-11 02:00:27 +02:00
|
|
|
* @param p1 The ID of the vehicle which order is skipped
|
2007-06-04 21:32:45 +02:00
|
|
|
* @param p2 the selected order to which we want to skip
|
2009-09-18 16:23:58 +02:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-01-15 20:06:22 +01:00
|
|
|
*/
|
2009-02-09 22:20:05 +01:00
|
|
|
CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2010-08-19 22:39:12 +02:00
|
|
|
VehicleID veh_id = GB(p1, 0, 20);
|
|
|
|
VehicleOrderID sel_ord = GB(p2, 0, 8);
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2009-05-18 18:21:28 +02:00
|
|
|
Vehicle *v = Vehicle::GetIfValid(veh_id);
|
2006-08-22 20:15:17 +02:00
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v == nullptr || !v->IsPrimaryVehicle() || sel_ord == v->cur_implicit_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(v->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2005-01-15 10:28:08 +01:00
|
|
|
if (flags & DC_EXEC) {
|
2013-05-19 16:22:04 +02:00
|
|
|
if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
|
|
|
|
|
2011-05-18 14:19:58 +02:00
|
|
|
v->cur_implicit_order_index = v->cur_real_order_index = sel_ord;
|
2011-01-31 21:44:15 +01:00
|
|
|
v->UpdateRealOrderIndex();
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2012-12-20 20:44:02 +01:00
|
|
|
InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2005-01-15 10:28:08 +01:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* We have an aircraft/ship, they have a mini-schedule, so update them all */
|
2009-09-13 21:15:59 +02:00
|
|
|
if (v->type == VEH_AIRCRAFT) SetWindowClassesDirty(WC_AIRCRAFT_LIST);
|
|
|
|
if (v->type == VEH_SHIP) SetWindowClassesDirty(WC_SHIPS_LIST);
|
2005-01-15 10:28:08 +01:00
|
|
|
|
2007-06-18 21:53:50 +02:00
|
|
|
return CommandCost();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2007-06-08 20:59:29 +02:00
|
|
|
/**
|
|
|
|
* Move an order inside the orderlist
|
|
|
|
* @param tile unused
|
2009-09-18 16:23:58 +02:00
|
|
|
* @param flags operation to perform
|
2007-06-08 20:59:29 +02:00
|
|
|
* @param p1 the ID of the vehicle
|
|
|
|
* @param p2 order to move and target
|
|
|
|
* bit 0-15 : the order to move
|
|
|
|
* bit 16-31 : the target order
|
2009-09-18 16:23:58 +02:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2007-06-08 20:59:29 +02:00
|
|
|
* @note The target order will move one place down in the orderlist
|
|
|
|
* if you move the order upwards else it'll move it one place down
|
|
|
|
*/
|
2009-02-09 22:20:05 +01:00
|
|
|
CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2007-06-08 20:59:29 +02:00
|
|
|
{
|
2010-08-19 22:39:12 +02:00
|
|
|
VehicleID veh = GB(p1, 0, 20);
|
2007-06-08 20:59:29 +02:00
|
|
|
VehicleOrderID moving_order = GB(p2, 0, 16);
|
|
|
|
VehicleOrderID target_order = GB(p2, 16, 16);
|
|
|
|
|
2009-05-18 18:21:28 +02:00
|
|
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(v->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2007-06-08 20:59:29 +02:00
|
|
|
|
|
|
|
/* Don't make senseless movements */
|
2009-01-03 14:20:32 +01:00
|
|
|
if (moving_order >= v->GetNumOrders() || target_order >= v->GetNumOrders() ||
|
2010-03-20 16:30:57 +01:00
|
|
|
moving_order == target_order || v->GetNumOrders() <= 1) return CMD_ERROR;
|
2007-06-08 20:59:29 +02:00
|
|
|
|
2009-05-23 14:27:42 +02:00
|
|
|
Order *moving_one = v->GetOrder(moving_order);
|
2007-06-08 20:59:29 +02:00
|
|
|
/* Don't move an empty order */
|
2019-04-10 23:07:06 +02:00
|
|
|
if (moving_one == nullptr) return CMD_ERROR;
|
2007-06-08 20:59:29 +02:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2009-01-03 14:52:06 +01:00
|
|
|
v->orders.list->MoveOrder(moving_order, target_order);
|
2007-06-08 20:59:29 +02:00
|
|
|
|
|
|
|
/* Update shared list */
|
2008-08-17 21:56:17 +02:00
|
|
|
Vehicle *u = v->FirstShared();
|
2007-06-08 20:59:29 +02:00
|
|
|
|
|
|
|
DeleteOrderWarnings(u);
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
for (; u != nullptr; u = u->NextShared()) {
|
2011-01-31 21:44:15 +01:00
|
|
|
/* Update the current order.
|
2011-05-18 14:19:58 +02:00
|
|
|
* There are multiple ways to move orders, which result in cur_implicit_order_index
|
2011-01-31 21:44:15 +01:00
|
|
|
* and cur_real_order_index to not longer make any sense. E.g. moving another
|
|
|
|
* real order between them.
|
|
|
|
*
|
|
|
|
* Basically one could choose to preserve either of them, but not both.
|
|
|
|
* While both ways are suitable in this or that case from a human point of view, neither
|
|
|
|
* of them makes really sense.
|
|
|
|
* However, from an AI point of view, preserving cur_real_order_index is the most
|
|
|
|
* predictable and transparent behaviour.
|
|
|
|
*
|
2011-05-18 14:19:58 +02:00
|
|
|
* With that decision it basically does not matter what we do to cur_implicit_order_index.
|
2013-01-08 23:46:42 +01:00
|
|
|
* If we change orders between the implicit- and real-index, the implicit orders are mostly likely
|
2011-05-18 14:19:58 +02:00
|
|
|
* completely out-dated anyway. So, keep it simple and just keep cur_implicit_order_index as well.
|
|
|
|
* The worst which can happen is that a lot of implicit orders are removed when reaching current_order.
|
2011-01-31 21:44:15 +01:00
|
|
|
*/
|
|
|
|
if (u->cur_real_order_index == moving_order) {
|
|
|
|
u->cur_real_order_index = target_order;
|
|
|
|
} else if (u->cur_real_order_index > moving_order && u->cur_real_order_index <= target_order) {
|
|
|
|
u->cur_real_order_index--;
|
|
|
|
} else if (u->cur_real_order_index < moving_order && u->cur_real_order_index >= target_order) {
|
|
|
|
u->cur_real_order_index++;
|
|
|
|
}
|
|
|
|
|
2011-05-18 14:19:58 +02:00
|
|
|
if (u->cur_implicit_order_index == moving_order) {
|
|
|
|
u->cur_implicit_order_index = target_order;
|
|
|
|
} else if (u->cur_implicit_order_index > moving_order && u->cur_implicit_order_index <= target_order) {
|
|
|
|
u->cur_implicit_order_index--;
|
|
|
|
} else if (u->cur_implicit_order_index < moving_order && u->cur_implicit_order_index >= target_order) {
|
|
|
|
u->cur_implicit_order_index++;
|
2007-06-08 20:59:29 +02:00
|
|
|
}
|
|
|
|
|
2009-01-03 14:52:06 +01:00
|
|
|
assert(v->orders.list == u->orders.list);
|
2007-06-08 20:59:29 +02:00
|
|
|
/* Update any possible open window of the vehicle */
|
2008-09-24 18:40:06 +02:00
|
|
|
InvalidateVehicleOrder(u, moving_order | (target_order << 8));
|
2007-06-08 20:59:29 +02:00
|
|
|
}
|
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
/* As we move an order, the order to skip to will be 'wrong'. */
|
|
|
|
Order *order;
|
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
if (order->IsType(OT_CONDITIONAL)) {
|
|
|
|
VehicleOrderID order_id = order->GetConditionSkipToOrder();
|
|
|
|
if (order_id == moving_order) {
|
|
|
|
order_id = target_order;
|
2009-08-14 19:11:59 +02:00
|
|
|
} else if (order_id > moving_order && order_id <= target_order) {
|
2008-04-12 13:58:19 +02:00
|
|
|
order_id--;
|
2009-08-14 19:11:59 +02:00
|
|
|
} else if (order_id < moving_order && order_id >= target_order) {
|
2008-04-12 13:58:19 +02:00
|
|
|
order_id++;
|
|
|
|
}
|
|
|
|
order->SetConditionSkipToOrder(order_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-08 20:59:29 +02:00
|
|
|
/* Make sure to rebuild the whole list */
|
2008-05-18 18:51:44 +02:00
|
|
|
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
|
2007-06-08 20:59:29 +02:00
|
|
|
}
|
|
|
|
|
2007-06-18 21:53:50 +02:00
|
|
|
return CommandCost();
|
2007-06-08 20:59:29 +02:00
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Modify an order in the orderlist of a vehicle.
|
2006-04-10 09:15:58 +02:00
|
|
|
* @param tile unused
|
2007-04-17 22:23:13 +02:00
|
|
|
* @param flags operation to perform
|
2005-05-11 02:00:27 +02:00
|
|
|
* @param p1 various bitstuffed elements
|
2010-08-19 22:39:12 +02:00
|
|
|
* - p1 = (bit 0 - 19) - ID of the vehicle
|
|
|
|
* - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given,
|
2005-07-20 17:29:28 +02:00
|
|
|
* the order will be inserted before that one
|
2010-08-19 22:39:12 +02:00
|
|
|
* the maximum vehicle order id is 254.
|
2008-04-09 14:46:43 +02:00
|
|
|
* @param p2 various bitstuffed elements
|
2008-04-12 13:58:19 +02:00
|
|
|
* - p2 = (bit 0 - 3) - what data to modify (@see ModifyOrderFlags)
|
|
|
|
* - p2 = (bit 4 - 15) - the data to modify
|
2009-09-18 16:23:58 +02:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2004-08-09 19:04:08 +02:00
|
|
|
*/
|
2009-02-09 22:20:05 +01:00
|
|
|
CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2010-08-19 22:39:12 +02:00
|
|
|
VehicleOrderID sel_ord = GB(p1, 20, 8);
|
|
|
|
VehicleID veh = GB(p1, 0, 20);
|
2010-04-17 15:31:41 +02:00
|
|
|
ModifyOrderFlags mof = Extract<ModifyOrderFlags, 0, 4>(p2);
|
2010-08-19 22:39:12 +02:00
|
|
|
uint16 data = GB(p2, 4, 11);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
if (mof >= MOF_END) return CMD_ERROR;
|
2006-08-22 20:15:17 +02:00
|
|
|
|
2009-05-18 18:21:28 +02:00
|
|
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(v->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2005-04-22 07:41:09 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Is it a valid order? */
|
2009-01-03 14:20:32 +01:00
|
|
|
if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-05-23 14:27:42 +02:00
|
|
|
Order *order = v->GetOrder(sel_ord);
|
2008-04-09 14:46:43 +02:00
|
|
|
switch (order->GetType()) {
|
|
|
|
case OT_GOTO_STATION:
|
2014-02-19 21:56:44 +01:00
|
|
|
if (mof != MOF_NON_STOP && mof != MOF_STOP_LOCATION && mof != MOF_UNLOAD && mof != MOF_LOAD) return CMD_ERROR;
|
2008-04-09 14:46:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_GOTO_DEPOT:
|
2008-04-12 13:58:19 +02:00
|
|
|
if (mof != MOF_NON_STOP && mof != MOF_DEPOT_ACTION) return CMD_ERROR;
|
2008-04-09 14:46:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
|
if (mof != MOF_NON_STOP) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
case OT_CONDITIONAL:
|
2009-04-15 19:37:31 +02:00
|
|
|
if (mof != MOF_COND_VARIABLE && mof != MOF_COND_COMPARATOR && mof != MOF_COND_VALUE && mof != MOF_COND_DESTINATION) return CMD_ERROR;
|
2008-04-12 13:58:19 +02:00
|
|
|
break;
|
|
|
|
|
2008-04-09 14:46:43 +02:00
|
|
|
default:
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mof) {
|
2008-04-12 13:58:19 +02:00
|
|
|
default: NOT_REACHED();
|
|
|
|
|
2008-04-09 14:46:43 +02:00
|
|
|
case MOF_NON_STOP:
|
2010-12-14 22:26:03 +01:00
|
|
|
if (!v->IsGroundVehicle()) return CMD_ERROR;
|
2008-04-09 14:46:43 +02:00
|
|
|
if (data >= ONSF_END) return CMD_ERROR;
|
|
|
|
if (data == order->GetNonStopType()) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
2009-04-12 16:11:14 +02:00
|
|
|
case MOF_STOP_LOCATION:
|
|
|
|
if (v->type != VEH_TRAIN) return CMD_ERROR;
|
|
|
|
if (data >= OSL_END) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
2008-04-09 14:46:43 +02:00
|
|
|
case MOF_UNLOAD:
|
2014-02-19 21:56:44 +01:00
|
|
|
if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return CMD_ERROR;
|
2008-04-10 12:18:03 +02:00
|
|
|
if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER | OUFB_NO_UNLOAD)) != 0) return CMD_ERROR;
|
|
|
|
/* Unload and no-unload are mutual exclusive and so are transfer and no unload. */
|
|
|
|
if (data != 0 && ((data & (OUFB_UNLOAD | OUFB_TRANSFER)) != 0) == ((data & OUFB_NO_UNLOAD) != 0)) return CMD_ERROR;
|
2008-04-09 14:46:43 +02:00
|
|
|
if (data == order->GetUnloadType()) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOF_LOAD:
|
2014-02-19 21:56:44 +01:00
|
|
|
if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return CMD_ERROR;
|
2008-04-10 12:18:03 +02:00
|
|
|
if (data > OLFB_NO_LOAD || data == 1) return CMD_ERROR;
|
2008-04-09 14:46:43 +02:00
|
|
|
if (data == order->GetLoadType()) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOF_DEPOT_ACTION:
|
2008-10-24 16:49:45 +02:00
|
|
|
if (data >= DA_END) return CMD_ERROR;
|
2008-04-09 14:46:43 +02:00
|
|
|
break;
|
2008-04-12 13:58:19 +02:00
|
|
|
|
|
|
|
case MOF_COND_VARIABLE:
|
|
|
|
if (data >= OCV_END) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOF_COND_COMPARATOR:
|
|
|
|
if (data >= OCC_END) return CMD_ERROR;
|
|
|
|
switch (order->GetConditionVariable()) {
|
2008-04-12 15:07:25 +02:00
|
|
|
case OCV_UNCONDITIONALLY: return CMD_ERROR;
|
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
case OCV_REQUIRES_SERVICE:
|
|
|
|
if (data != OCC_IS_TRUE && data != OCC_IS_FALSE) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (data == OCC_IS_TRUE || data == OCC_IS_FALSE) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOF_COND_VALUE:
|
|
|
|
switch (order->GetConditionVariable()) {
|
2014-02-19 21:56:44 +01:00
|
|
|
case OCV_UNCONDITIONALLY:
|
|
|
|
case OCV_REQUIRES_SERVICE:
|
|
|
|
return CMD_ERROR;
|
2008-04-12 15:07:25 +02:00
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
case OCV_LOAD_PERCENTAGE:
|
|
|
|
case OCV_RELIABILITY:
|
|
|
|
if (data > 100) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (data > 2047) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-07-20 09:41:43 +02:00
|
|
|
|
|
|
|
case MOF_COND_DESTINATION:
|
2009-01-03 14:20:32 +01:00
|
|
|
if (data >= v->GetNumOrders()) return CMD_ERROR;
|
2008-07-20 09:41:43 +02:00
|
|
|
break;
|
2006-06-27 23:25:53 +02:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2008-04-09 14:46:43 +02:00
|
|
|
switch (mof) {
|
|
|
|
case MOF_NON_STOP:
|
|
|
|
order->SetNonStopType((OrderNonStopFlags)data);
|
2014-02-19 21:56:44 +01:00
|
|
|
if (data & ONSF_NO_STOP_AT_DESTINATION_STATION) {
|
|
|
|
order->SetRefit(CT_NO_REFIT);
|
|
|
|
order->SetLoadType(OLF_LOAD_IF_POSSIBLE);
|
|
|
|
order->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE);
|
|
|
|
}
|
2008-04-06 23:54:22 +02:00
|
|
|
break;
|
2008-04-09 14:46:43 +02:00
|
|
|
|
2009-04-12 16:11:14 +02:00
|
|
|
case MOF_STOP_LOCATION:
|
|
|
|
order->SetStopLocation((OrderStopLocation)data);
|
|
|
|
break;
|
|
|
|
|
2008-04-09 14:46:43 +02:00
|
|
|
case MOF_UNLOAD:
|
|
|
|
order->SetUnloadType((OrderUnloadFlags)data);
|
2008-04-06 23:54:22 +02:00
|
|
|
break;
|
2008-04-09 14:46:43 +02:00
|
|
|
|
|
|
|
case MOF_LOAD:
|
|
|
|
order->SetLoadType((OrderLoadFlags)data);
|
2011-11-04 01:38:51 +01:00
|
|
|
if (data & OLFB_NO_LOAD) order->SetRefit(CT_NO_REFIT);
|
2008-04-06 23:54:22 +02:00
|
|
|
break;
|
2008-04-09 14:46:43 +02:00
|
|
|
|
2008-10-24 16:49:45 +02:00
|
|
|
case MOF_DEPOT_ACTION: {
|
|
|
|
switch (data) {
|
|
|
|
case DA_ALWAYS_GO:
|
|
|
|
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
|
|
|
|
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DA_SERVICE:
|
|
|
|
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() | ODTFB_SERVICE));
|
|
|
|
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
|
2011-07-02 18:45:54 +02:00
|
|
|
order->SetRefit(CT_NO_REFIT);
|
2008-10-24 16:49:45 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DA_STOP:
|
|
|
|
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
|
|
|
|
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() | ODATFB_HALT));
|
2011-07-02 18:45:54 +02:00
|
|
|
order->SetRefit(CT_NO_REFIT);
|
2008-10-24 16:49:45 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
2010-08-01 20:53:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-04-09 14:46:43 +02:00
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
case MOF_COND_VARIABLE: {
|
|
|
|
order->SetConditionVariable((OrderConditionVariable)data);
|
|
|
|
|
|
|
|
OrderConditionComparator occ = order->GetConditionComparator();
|
|
|
|
switch (order->GetConditionVariable()) {
|
2008-04-12 15:07:25 +02:00
|
|
|
case OCV_UNCONDITIONALLY:
|
|
|
|
order->SetConditionComparator(OCC_EQUALS);
|
|
|
|
order->SetConditionValue(0);
|
|
|
|
break;
|
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
case OCV_REQUIRES_SERVICE:
|
|
|
|
if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) order->SetConditionComparator(OCC_IS_TRUE);
|
2014-02-19 21:56:44 +01:00
|
|
|
order->SetConditionValue(0);
|
2008-04-12 13:58:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OCV_LOAD_PERCENTAGE:
|
|
|
|
case OCV_RELIABILITY:
|
|
|
|
if (order->GetConditionValue() > 100) order->SetConditionValue(100);
|
2017-08-13 20:38:42 +02:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
default:
|
|
|
|
if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) order->SetConditionComparator(OCC_EQUALS);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-01 20:53:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-04-12 13:58:19 +02:00
|
|
|
|
|
|
|
case MOF_COND_COMPARATOR:
|
|
|
|
order->SetConditionComparator((OrderConditionComparator)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOF_COND_VALUE:
|
|
|
|
order->SetConditionValue(data);
|
|
|
|
break;
|
|
|
|
|
2008-07-20 09:41:43 +02:00
|
|
|
case MOF_COND_DESTINATION:
|
|
|
|
order->SetConditionSkipToOrder(data);
|
|
|
|
break;
|
|
|
|
|
2008-04-06 23:54:22 +02:00
|
|
|
default: NOT_REACHED();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2005-05-04 00:18:40 +02:00
|
|
|
/* Update the windows and full load flags, also for vehicles that share the same order list */
|
2008-08-17 21:56:17 +02:00
|
|
|
Vehicle *u = v->FirstShared();
|
2008-04-09 14:46:43 +02:00
|
|
|
DeleteOrderWarnings(u);
|
2019-04-10 23:07:06 +02:00
|
|
|
for (; u != nullptr; u = u->NextShared()) {
|
2008-04-09 19:48:22 +02:00
|
|
|
/* Toggle u->current_order "Full load" flag if it changed.
|
|
|
|
* However, as the same flag is used for depot orders, check
|
|
|
|
* whether we are not going to a depot as there are three
|
|
|
|
* cases where the full load flag can be active and only
|
|
|
|
* one case where the flag is used for depot orders. In the
|
2019-04-22 09:16:45 +02:00
|
|
|
* other cases for the OrderType the flags are not used,
|
2008-04-09 19:48:22 +02:00
|
|
|
* so do not care and those orders should not be active
|
|
|
|
* when this function is called.
|
|
|
|
*/
|
2011-01-31 21:44:15 +01:00
|
|
|
if (sel_ord == u->cur_real_order_index &&
|
2008-04-09 19:48:22 +02:00
|
|
|
(u->current_order.IsType(OT_GOTO_STATION) || u->current_order.IsType(OT_LOADING)) &&
|
|
|
|
u->current_order.GetLoadType() != order->GetLoadType()) {
|
|
|
|
u->current_order.SetLoadType(order->GetLoadType());
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
2012-12-20 20:44:02 +01:00
|
|
|
InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2007-06-18 21:53:50 +02:00
|
|
|
return CommandCost();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 01:43:35 +01:00
|
|
|
/**
|
|
|
|
* Check if an aircraft has enough range for an order list.
|
2012-04-01 21:56:08 +02:00
|
|
|
* @param v_new Aircraft to check.
|
|
|
|
* @param v_order Vehicle currently holding the order list.
|
2011-12-13 01:43:35 +01:00
|
|
|
* @param first First order in the source order list.
|
|
|
|
* @return True if the aircraft has enough range for the orders, false otherwise.
|
|
|
|
*/
|
2012-04-01 21:56:08 +02:00
|
|
|
static bool CheckAircraftOrderDistance(const Aircraft *v_new, const Vehicle *v_order, const Order *first)
|
2011-12-13 01:43:35 +01:00
|
|
|
{
|
2019-04-10 23:07:06 +02:00
|
|
|
if (first == nullptr || v_new->acache.cached_max_range == 0) return true;
|
2011-12-13 01:43:35 +01:00
|
|
|
|
|
|
|
/* Iterate over all orders to check the distance between all
|
|
|
|
* 'goto' orders and their respective next order (of any type). */
|
2019-04-10 23:07:06 +02:00
|
|
|
for (const Order *o = first; o != nullptr; o = o->next) {
|
2011-12-13 01:43:35 +01:00
|
|
|
switch (o->GetType()) {
|
|
|
|
case OT_GOTO_STATION:
|
|
|
|
case OT_GOTO_DEPOT:
|
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
|
/* If we don't have a next order, we've reached the end and must check the first order instead. */
|
2019-04-10 23:07:06 +02:00
|
|
|
if (GetOrderDistance(o, o->next != nullptr ? o->next : first, v_order) > v_new->acache.cached_max_range_sqr) return false;
|
2011-12-13 01:43:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Clone/share/copy an order-list of another vehicle.
|
2007-04-17 22:23:13 +02:00
|
|
|
* @param tile unused
|
|
|
|
* @param flags operation to perform
|
2005-05-12 02:11:37 +02:00
|
|
|
* @param p1 various bitstuffed elements
|
2010-08-19 22:39:12 +02:00
|
|
|
* - p1 = (bit 0-19) - destination vehicle to clone orders to
|
|
|
|
* - p1 = (bit 30-31) - action to perform
|
|
|
|
* @param p2 source vehicle to clone orders from, if any (none for CO_UNSHARE)
|
2009-09-18 16:23:58 +02:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-01-15 20:06:22 +01:00
|
|
|
*/
|
2009-02-09 22:20:05 +01:00
|
|
|
CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2005-01-15 20:06:22 +01:00
|
|
|
{
|
2010-08-19 22:39:12 +02:00
|
|
|
VehicleID veh_src = GB(p2, 0, 20);
|
|
|
|
VehicleID veh_dst = GB(p1, 0, 20);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-05-18 18:21:28 +02:00
|
|
|
Vehicle *dst = Vehicle::GetIfValid(veh_dst);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (dst == nullptr || !dst->IsPrimaryVehicle()) return CMD_ERROR;
|
2005-05-12 02:11:37 +02:00
|
|
|
|
2010-03-13 18:11:28 +01:00
|
|
|
CommandCost ret = CheckOwnership(dst->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2005-05-12 02:11:37 +02:00
|
|
|
|
2010-08-19 22:39:12 +02:00
|
|
|
switch (GB(p1, 30, 2)) {
|
2005-01-15 20:06:22 +01:00
|
|
|
case CO_SHARE: {
|
2009-05-18 18:21:28 +02:00
|
|
|
Vehicle *src = Vehicle::GetIfValid(veh_src);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Sanity checks */
|
2019-04-10 23:07:06 +02:00
|
|
|
if (src == nullptr || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(src->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Trucks can't share orders with busses (and visa versa) */
|
2009-12-02 18:37:02 +01:00
|
|
|
if (src->type == VEH_ROAD && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
|
2009-12-02 18:35:54 +01:00
|
|
|
return CMD_ERROR;
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Is the vehicle already in the shared list? */
|
2008-08-17 21:56:17 +02:00
|
|
|
if (src->FirstShared() == dst->FirstShared()) return CMD_ERROR;
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2009-01-10 14:00:38 +01:00
|
|
|
const Order *order;
|
|
|
|
|
|
|
|
FOR_VEHICLE_ORDERS(src, order) {
|
2012-07-09 20:45:35 +02:00
|
|
|
if (!OrderGoesToStation(dst, order)) continue;
|
|
|
|
|
|
|
|
/* Allow copying unreachable destinations if they were already unreachable for the source.
|
|
|
|
* This is basically to allow cloning / autorenewing / autoreplacing vehicles, while the stations
|
|
|
|
* are temporarily invalid due to reconstruction. */
|
|
|
|
const Station *st = Station::Get(order->GetDestination());
|
|
|
|
if (CanVehicleUseStation(src, st) && !CanVehicleUseStation(dst, st)) {
|
2009-04-22 01:40:56 +02:00
|
|
|
return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
|
2009-01-10 14:00:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 01:43:35 +01:00
|
|
|
/* Check for aircraft range limits. */
|
2012-04-01 21:56:08 +02:00
|
|
|
if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src, src->GetFirstOrder())) {
|
2011-12-13 01:43:35 +01:00
|
|
|
return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
|
|
|
|
}
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
if (src->orders.list == nullptr && !OrderList::CanAllocateItem()) {
|
2011-02-08 19:29:30 +01:00
|
|
|
return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
|
|
|
|
}
|
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
if (flags & DC_EXEC) {
|
2011-02-09 22:40:32 +01:00
|
|
|
/* If the destination vehicle had a OrderList, destroy it.
|
|
|
|
* We only reset the order indices, if the new orders are obviously different.
|
|
|
|
* (We mainly do this to keep the order indices valid and in range.) */
|
|
|
|
DeleteVehicleOrders(dst, false, dst->GetNumOrders() != src->GetNumOrders());
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-01-03 14:52:06 +01:00
|
|
|
dst->orders.list = src->orders.list;
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Link this vehicle in the shared-list */
|
2008-08-17 21:56:17 +02:00
|
|
|
dst->AddToShared(src);
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2012-12-20 20:44:02 +01:00
|
|
|
InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
|
|
|
|
InvalidateVehicleOrder(src, VIWD_MODIFY_ORDERS);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 18:51:44 +02:00
|
|
|
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
2010-08-01 20:53:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
case CO_COPY: {
|
2009-05-18 18:21:28 +02:00
|
|
|
Vehicle *src = Vehicle::GetIfValid(veh_src);
|
2005-05-12 02:11:37 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Sanity checks */
|
2019-04-10 23:07:06 +02:00
|
|
|
if (src == nullptr || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(src->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-01-10 14:00:38 +01:00
|
|
|
/* Trucks can't copy all the orders from busses (and visa versa),
|
2013-01-08 23:46:42 +01:00
|
|
|
* and neither can helicopters and aircraft. */
|
2009-01-10 14:00:38 +01:00
|
|
|
const Order *order;
|
|
|
|
FOR_VEHICLE_ORDERS(src, order) {
|
|
|
|
if (OrderGoesToStation(dst, order) &&
|
2009-05-17 01:34:14 +02:00
|
|
|
!CanVehicleUseStation(dst, Station::Get(order->GetDestination()))) {
|
2009-04-22 01:40:56 +02:00
|
|
|
return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
|
2004-08-12 23:29:26 +02:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2011-12-13 01:43:35 +01:00
|
|
|
/* Check for aircraft range limits. */
|
2012-04-01 21:56:08 +02:00
|
|
|
if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src, src->GetFirstOrder())) {
|
2011-12-13 01:43:35 +01:00
|
|
|
return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
|
|
|
|
}
|
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* make sure there are orders available */
|
2012-01-25 19:34:38 +01:00
|
|
|
if (!Order::CanAllocateItem(src->GetNumOrders()) || !OrderList::CanAllocateItem()) {
|
2009-04-22 01:40:56 +02:00
|
|
|
return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
|
2008-10-30 13:32:32 +01:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
const Order *order;
|
2019-04-10 23:07:06 +02:00
|
|
|
Order *first = nullptr;
|
2005-01-15 20:06:22 +01:00
|
|
|
Order **order_dst;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2011-02-09 22:40:32 +01:00
|
|
|
/* If the destination vehicle had an order list, destroy the chain but keep the OrderList.
|
|
|
|
* We only reset the order indices, if the new orders are obviously different.
|
|
|
|
* (We mainly do this to keep the order indices valid and in range.) */
|
|
|
|
DeleteVehicleOrders(dst, true, dst->GetNumOrders() != src->GetNumOrders());
|
2004-12-10 19:16:08 +01:00
|
|
|
|
2009-01-03 14:52:06 +01:00
|
|
|
order_dst = &first;
|
2005-01-15 20:06:22 +01:00
|
|
|
FOR_VEHICLE_ORDERS(src, order) {
|
2007-08-03 01:40:19 +02:00
|
|
|
*order_dst = new Order();
|
2008-04-05 23:45:05 +02:00
|
|
|
(*order_dst)->AssignOrder(*order);
|
2005-01-15 20:06:22 +01:00
|
|
|
order_dst = &(*order_dst)->next;
|
|
|
|
}
|
2019-04-10 23:07:06 +02:00
|
|
|
if (dst->orders.list == nullptr) {
|
2009-05-22 17:13:50 +02:00
|
|
|
dst->orders.list = new OrderList(first, dst);
|
|
|
|
} else {
|
2019-04-10 23:07:06 +02:00
|
|
|
assert(dst->orders.list->GetFirstOrder() == nullptr);
|
2009-05-22 17:13:50 +02:00
|
|
|
assert(!dst->orders.list->IsShared());
|
|
|
|
delete dst->orders.list;
|
2011-02-18 22:46:45 +01:00
|
|
|
assert(OrderList::CanAllocateItem());
|
2009-05-22 17:13:50 +02:00
|
|
|
dst->orders.list = new OrderList(first, dst);
|
2009-01-03 14:52:06 +01:00
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2012-12-20 20:44:02 +01:00
|
|
|
InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-05-18 18:51:44 +02:00
|
|
|
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
2010-08-01 20:53:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2005-05-12 02:11:37 +02:00
|
|
|
case CO_UNSHARE: return DecloneOrder(dst, flags);
|
2005-05-13 01:46:01 +02:00
|
|
|
default: return CMD_ERROR;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2007-06-18 21:53:50 +02:00
|
|
|
return CommandCost();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Add/remove refit orders from an order
|
2006-10-03 16:52:39 +02:00
|
|
|
* @param tile Not used
|
2007-04-17 22:23:13 +02:00
|
|
|
* @param flags operation to perform
|
2006-10-03 16:52:39 +02:00
|
|
|
* @param p1 VehicleIndex of the vehicle having the order
|
|
|
|
* @param p2 bitmask
|
|
|
|
* - bit 0-7 CargoID
|
|
|
|
* - bit 16-23 number of order to modify
|
2009-09-18 16:23:58 +02:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2006-10-03 16:52:39 +02:00
|
|
|
*/
|
2009-02-09 22:20:05 +01:00
|
|
|
CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2006-10-03 16:52:39 +02:00
|
|
|
{
|
2010-08-19 22:39:12 +02:00
|
|
|
VehicleID veh = GB(p1, 0, 20);
|
2006-10-03 16:52:39 +02:00
|
|
|
VehicleOrderID order_number = GB(p2, 16, 8);
|
|
|
|
CargoID cargo = GB(p2, 0, 8);
|
|
|
|
|
2011-11-04 01:38:51 +01:00
|
|
|
if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT && cargo != CT_AUTO_REFIT) return CMD_ERROR;
|
2010-04-17 16:55:49 +02:00
|
|
|
|
2009-05-18 18:21:28 +02:00
|
|
|
const Vehicle *v = Vehicle::GetIfValid(veh);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
2010-03-13 18:11:28 +01:00
|
|
|
|
|
|
|
CommandCost ret = CheckOwnership(v->owner);
|
|
|
|
if (ret.Failed()) return ret;
|
2006-10-03 16:52:39 +02:00
|
|
|
|
2009-05-23 14:27:42 +02:00
|
|
|
Order *order = v->GetOrder(order_number);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (order == nullptr) return CMD_ERROR;
|
2006-10-03 16:52:39 +02:00
|
|
|
|
2011-11-04 01:38:51 +01:00
|
|
|
/* Automatic refit cargo is only supported for goto station orders. */
|
|
|
|
if (cargo == CT_AUTO_REFIT && !order->IsType(OT_GOTO_STATION)) return CMD_ERROR;
|
|
|
|
|
2013-01-23 19:33:28 +01:00
|
|
|
if (order->GetLoadType() & OLFB_NO_LOAD) return CMD_ERROR;
|
|
|
|
|
2006-10-03 16:52:39 +02:00
|
|
|
if (flags & DC_EXEC) {
|
2013-02-24 17:41:51 +01:00
|
|
|
order->SetRefit(cargo);
|
2006-10-03 16:52:39 +02:00
|
|
|
|
2011-07-02 18:45:54 +02:00
|
|
|
/* Make the depot order an 'always go' order. */
|
2012-08-03 16:15:52 +02:00
|
|
|
if (cargo != CT_NO_REFIT && order->IsType(OT_GOTO_DEPOT)) {
|
2011-07-02 18:45:54 +02:00
|
|
|
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
|
|
|
|
order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
|
|
|
|
}
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
|
2006-10-03 16:52:39 +02:00
|
|
|
/* Update any possible open window of the vehicle */
|
2012-12-20 20:44:02 +01:00
|
|
|
InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
|
2006-10-03 16:52:39 +02:00
|
|
|
|
|
|
|
/* If the vehicle already got the current depot set as current order, then update current order as well */
|
2011-01-31 21:44:15 +01:00
|
|
|
if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
|
2013-02-24 17:41:51 +01:00
|
|
|
u->current_order.SetRefit(cargo);
|
2006-10-03 16:52:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-18 21:53:50 +02:00
|
|
|
return CommandCost();
|
2006-10-03 16:52:39 +02:00
|
|
|
}
|
|
|
|
|
2006-07-26 12:00:33 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Check the orders of a vehicle, to see if there are invalid orders and stuff
|
|
|
|
*
|
|
|
|
*/
|
2009-01-10 01:31:47 +01:00
|
|
|
void CheckOrders(const Vehicle *v)
|
2004-08-11 12:15:38 +02:00
|
|
|
{
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Does the user wants us to check things? */
|
2008-05-29 17:13:28 +02:00
|
|
|
if (_settings_client.gui.order_review_system == 0) return;
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Do nothing for crashed vehicles */
|
2006-03-04 12:15:44 +01:00
|
|
|
if (v->vehstatus & VS_CRASHED) return;
|
2004-12-19 10:30:05 +01:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Do nothing for stopped vehicles if setting is '1' */
|
2010-07-24 12:14:39 +02:00
|
|
|
if (_settings_client.gui.order_review_system == 1 && (v->vehstatus & VS_STOPPED)) return;
|
2004-08-11 12:15:38 +02:00
|
|
|
|
2005-01-17 22:54:45 +01:00
|
|
|
/* do nothing we we're not the first vehicle in a share-chain */
|
2008-08-17 21:56:17 +02:00
|
|
|
if (v->FirstShared() != v) return;
|
2005-01-17 22:54:45 +01:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Only check every 20 days, so that we don't flood the message log */
|
2008-09-30 22:39:50 +02:00
|
|
|
if (v->owner == _local_company && v->day_counter % 20 == 0) {
|
2005-01-15 20:06:22 +01:00
|
|
|
const Order *order;
|
2014-05-06 22:53:08 +02:00
|
|
|
StringID message = INVALID_STRING_ID;
|
2005-01-15 20:06:22 +01:00
|
|
|
|
|
|
|
/* Check the order list */
|
2014-05-06 22:53:08 +02:00
|
|
|
int n_st = 0;
|
2004-08-15 15:21:18 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
/* Dummy order? */
|
2008-04-06 01:36:54 +02:00
|
|
|
if (order->IsType(OT_DUMMY)) {
|
2014-05-06 22:53:08 +02:00
|
|
|
message = STR_NEWS_VEHICLE_HAS_VOID_ORDER;
|
2004-08-15 15:21:18 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Does station have a load-bay for this vehicle? */
|
2008-04-06 01:36:54 +02:00
|
|
|
if (order->IsType(OT_GOTO_STATION)) {
|
2009-05-17 01:34:14 +02:00
|
|
|
const Station *st = Station::Get(order->GetDestination());
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2004-08-11 12:15:38 +02:00
|
|
|
n_st++;
|
2014-05-06 22:50:58 +02:00
|
|
|
if (!CanVehicleUseStation(v, st)) {
|
2014-05-06 22:53:08 +02:00
|
|
|
message = STR_NEWS_VEHICLE_HAS_INVALID_ENTRY;
|
2014-05-06 22:50:58 +02:00
|
|
|
} else if (v->type == VEH_AIRCRAFT &&
|
|
|
|
(AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
|
|
|
|
(st->airport.GetFTA()->flags & AirportFTAClass::SHORT_STRIP) &&
|
|
|
|
!_cheats.no_jetcrash.value &&
|
2014-05-06 22:53:08 +02:00
|
|
|
message == INVALID_STRING_ID) {
|
|
|
|
message = STR_NEWS_PLANE_USES_TOO_SHORT_RUNWAY;
|
2014-05-06 22:50:58 +02:00
|
|
|
}
|
2004-08-11 12:15:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Check if the last and the first order are the same */
|
2009-01-03 14:20:32 +01:00
|
|
|
if (v->GetNumOrders() > 1) {
|
2009-05-23 14:27:42 +02:00
|
|
|
const Order *last = v->GetLastOrder();
|
2006-06-27 23:25:53 +02:00
|
|
|
|
2009-01-03 14:52:06 +01:00
|
|
|
if (v->orders.list->GetFirstOrder()->Equals(*last)) {
|
2014-05-06 22:53:08 +02:00
|
|
|
message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY;
|
2006-06-27 23:25:53 +02:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Do we only have 1 station in our order list? */
|
2014-05-06 22:53:08 +02:00
|
|
|
if (n_st < 2 && message == INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS;
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2009-01-03 14:52:06 +01:00
|
|
|
#ifndef NDEBUG
|
2019-04-10 23:07:06 +02:00
|
|
|
if (v->orders.list != nullptr) v->orders.list->DebugCheckSanity();
|
2009-01-03 14:52:06 +01:00
|
|
|
#endif
|
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* We don't have a problem */
|
2014-05-06 22:53:08 +02:00
|
|
|
if (message == INVALID_STRING_ID) return;
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2009-01-04 18:42:46 +01:00
|
|
|
SetDParam(0, v->index);
|
2012-05-26 16:15:52 +02:00
|
|
|
AddVehicleAdviceNewsItem(message, v->index);
|
2004-08-11 12:15:38 +02:00
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-08-22 19:13:49 +02:00
|
|
|
* Removes an order from all vehicles. Triggers when, say, a station is removed.
|
|
|
|
* @param type The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]).
|
|
|
|
* @param destination The destination. Can be a StationID, DepotID or WaypointID.
|
2018-10-01 17:01:28 +02:00
|
|
|
* @param hangar Only used for airports in the destination.
|
|
|
|
* When false, remove airport and hangar orders.
|
|
|
|
* When true, remove either airport or hangar order.
|
2005-01-15 20:06:22 +01:00
|
|
|
*/
|
2018-10-01 17:01:28 +02:00
|
|
|
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
|
2005-01-15 20:06:22 +01:00
|
|
|
{
|
2006-09-03 12:30:38 +02:00
|
|
|
/* Aircraft have StationIDs for depot orders and never use DepotIDs
|
|
|
|
* This fact is handled specially below
|
|
|
|
*/
|
|
|
|
|
2005-01-15 20:06:22 +01:00
|
|
|
/* Go through all vehicles */
|
2019-12-17 03:37:43 +01:00
|
|
|
for (Vehicle *v : Vehicle::Iterate()) {
|
2006-09-03 21:29:31 +02:00
|
|
|
Order *order;
|
|
|
|
|
|
|
|
order = &v->current_order;
|
2018-10-01 17:01:28 +02:00
|
|
|
if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : order->GetType()) == type &&
|
2019-03-20 22:46:02 +01:00
|
|
|
(!hangar || v->type == VEH_AIRCRAFT) && v->current_order.GetDestination() == destination) {
|
2008-04-06 01:36:54 +02:00
|
|
|
order->MakeDummy();
|
2009-09-13 21:15:59 +02:00
|
|
|
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the order from the order-list */
|
2008-09-24 18:40:06 +02:00
|
|
|
int id = -1;
|
2005-01-15 20:06:22 +01:00
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
2008-09-24 18:40:06 +02:00
|
|
|
id++;
|
2011-03-05 14:59:23 +01:00
|
|
|
restart:
|
2010-12-26 10:03:19 +01:00
|
|
|
|
|
|
|
OrderType ot = order->GetType();
|
|
|
|
if (ot == OT_GOTO_DEPOT && (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) continue;
|
2019-03-20 22:46:02 +01:00
|
|
|
if (ot == OT_GOTO_DEPOT && hangar && v->type != VEH_AIRCRAFT) continue; // Not an aircraft? Can't have a hangar order.
|
2018-10-01 17:01:28 +02:00
|
|
|
if (ot == OT_IMPLICIT || (v->type == VEH_AIRCRAFT && ot == OT_GOTO_DEPOT && !hangar)) ot = OT_GOTO_STATION;
|
2010-12-26 10:03:19 +01:00
|
|
|
if (ot == type && order->GetDestination() == destination) {
|
2011-05-18 14:19:58 +02:00
|
|
|
/* We want to clear implicit orders, but we don't want to make them
|
2010-12-26 10:03:19 +01:00
|
|
|
* dummy orders. They should just vanish. Also check the actual order
|
|
|
|
* type as ot is currently OT_GOTO_STATION. */
|
2011-05-18 14:19:58 +02:00
|
|
|
if (order->IsType(OT_IMPLICIT)) {
|
2011-03-05 14:59:23 +01:00
|
|
|
order = order->next; // DeleteOrder() invalidates current order
|
2010-12-26 10:03:19 +01:00
|
|
|
DeleteOrder(v, id);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (order != nullptr) goto restart;
|
2011-03-05 14:59:23 +01:00
|
|
|
break;
|
2010-12-26 10:03:19 +01:00
|
|
|
}
|
|
|
|
|
2014-07-17 00:24:55 +02:00
|
|
|
/* Clear wait time */
|
|
|
|
v->orders.list->UpdateTotalDuration(-order->GetWaitTime());
|
|
|
|
if (order->IsWaitTimetabled()) {
|
|
|
|
v->orders.list->UpdateTimetableDuration(-order->GetTimetabledWait());
|
|
|
|
order->SetWaitTimetabled(false);
|
|
|
|
}
|
|
|
|
order->SetWaitTime(0);
|
|
|
|
|
|
|
|
/* Clear order, preserving travel time */
|
|
|
|
bool travel_timetabled = order->IsTravelTimetabled();
|
2008-04-06 01:36:54 +02:00
|
|
|
order->MakeDummy();
|
2014-07-17 00:24:55 +02:00
|
|
|
order->SetTravelTimetabled(travel_timetabled);
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
for (const Vehicle *w = v->FirstShared(); w != nullptr; w = w->NextShared()) {
|
2008-09-24 18:40:06 +02:00
|
|
|
/* In GUI, simulate by removing the order and adding it back */
|
|
|
|
InvalidateVehicleOrder(w, id | (INVALID_VEH_ORDER_ID << 8));
|
|
|
|
InvalidateVehicleOrder(w, (INVALID_VEH_ORDER_ID << 8) | id);
|
|
|
|
}
|
2008-08-27 21:54:41 +02:00
|
|
|
}
|
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
2011-12-09 21:48:13 +01:00
|
|
|
|
2018-10-01 17:01:28 +02:00
|
|
|
OrderBackup::RemoveOrder(type, destination, hangar);
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-12-11 14:48:30 +01:00
|
|
|
* Checks if a vehicle has a depot in its order list.
|
|
|
|
* @return True iff at least one order is a depot order.
|
2005-01-15 20:06:22 +01:00
|
|
|
*/
|
2010-12-11 14:48:30 +01:00
|
|
|
bool Vehicle::HasDepotOrder() const
|
2005-01-15 20:06:22 +01:00
|
|
|
{
|
|
|
|
const Order *order;
|
|
|
|
|
2010-12-11 14:48:30 +01:00
|
|
|
FOR_VEHICLE_ORDERS(this, order) {
|
2010-07-24 12:14:39 +02:00
|
|
|
if (order->IsType(OT_GOTO_DEPOT)) return true;
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all orders from a vehicle
|
2011-02-09 22:40:32 +01:00
|
|
|
* @param v Vehicle whose orders to reset
|
|
|
|
* @param keep_orderlist If true, do not free the order list, only empty it.
|
2011-05-18 14:19:58 +02:00
|
|
|
* @param reset_order_indices If true, reset cur_implicit_order_index and cur_real_order_index
|
2011-02-09 22:40:32 +01:00
|
|
|
* and cancel the current full load order (if the vehicle is loading).
|
|
|
|
* If false, _you_ have to make sure the order indices are valid after
|
|
|
|
* your messing with them!
|
2005-01-15 20:06:22 +01:00
|
|
|
*/
|
2011-02-09 22:40:32 +01:00
|
|
|
void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indices)
|
2005-01-15 20:06:22 +01:00
|
|
|
{
|
2006-03-04 12:01:35 +01:00
|
|
|
DeleteOrderWarnings(v);
|
|
|
|
|
2008-02-02 03:45:09 +01:00
|
|
|
if (v->IsOrderListShared()) {
|
2008-08-17 21:56:17 +02:00
|
|
|
/* Remove ourself from the shared order list. */
|
|
|
|
v->RemoveFromShared();
|
2019-04-10 23:07:06 +02:00
|
|
|
v->orders.list = nullptr;
|
|
|
|
} else if (v->orders.list != nullptr) {
|
2008-08-17 21:56:17 +02:00
|
|
|
/* Remove the orders */
|
2009-01-03 14:52:06 +01:00
|
|
|
v->orders.list->FreeChain(keep_orderlist);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (!keep_orderlist) v->orders.list = nullptr;
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
2011-02-09 22:40:32 +01:00
|
|
|
|
|
|
|
if (reset_order_indices) {
|
2011-05-18 14:19:58 +02:00
|
|
|
v->cur_implicit_order_index = v->cur_real_order_index = 0;
|
2011-02-09 22:40:32 +01:00
|
|
|
if (v->current_order.IsType(OT_LOADING)) {
|
|
|
|
CancelLoadingDueToDeletedOrder(v);
|
|
|
|
}
|
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
}
|
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Clamp the service interval to the correct min/max. The actual min/max values
|
|
|
|
* depend on whether it's in percent or days.
|
|
|
|
* @param interval proposed service interval
|
|
|
|
* @return Clamped service interval
|
|
|
|
*/
|
2013-02-14 18:06:49 +01:00
|
|
|
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
|
2008-01-07 01:57:19 +01:00
|
|
|
{
|
2013-02-14 18:06:49 +01:00
|
|
|
return ispercent ? Clamp(interval, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(interval, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
|
2008-01-07 01:57:19 +01:00
|
|
|
}
|
|
|
|
|
2008-04-05 14:01:34 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Check if a vehicle has any valid orders
|
|
|
|
*
|
|
|
|
* @return false if there are no valid orders
|
2009-12-23 19:43:38 +01:00
|
|
|
* @note Conditional orders are not considered valid destination orders
|
2008-04-05 14:01:34 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
static bool CheckForValidOrders(const Vehicle *v)
|
|
|
|
{
|
|
|
|
const Order *order;
|
|
|
|
|
2009-12-23 19:43:38 +01:00
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
switch (order->GetType()) {
|
|
|
|
case OT_GOTO_STATION:
|
|
|
|
case OT_GOTO_DEPOT:
|
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-05 14:01:34 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-12 13:58:19 +02:00
|
|
|
/**
|
|
|
|
* Compare the variable and value based on the given comparator.
|
|
|
|
*/
|
|
|
|
static bool OrderConditionCompare(OrderConditionComparator occ, int variable, int value)
|
|
|
|
{
|
|
|
|
switch (occ) {
|
|
|
|
case OCC_EQUALS: return variable == value;
|
|
|
|
case OCC_NOT_EQUALS: return variable != value;
|
|
|
|
case OCC_LESS_THAN: return variable < value;
|
|
|
|
case OCC_LESS_EQUALS: return variable <= value;
|
|
|
|
case OCC_MORE_THAN: return variable > value;
|
|
|
|
case OCC_MORE_EQUALS: return variable >= value;
|
|
|
|
case OCC_IS_TRUE: return variable != 0;
|
|
|
|
case OCC_IS_FALSE: return variable == 0;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 10:33:38 +02:00
|
|
|
/**
|
|
|
|
* Process a conditional order and determine the next order.
|
|
|
|
* @param order the order the vehicle currently has
|
|
|
|
* @param v the vehicle to update
|
|
|
|
* @return index of next order to jump to, or INVALID_VEH_ORDER_ID to use the next order
|
|
|
|
*/
|
2008-08-03 00:53:05 +02:00
|
|
|
VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
|
2008-06-02 10:33:38 +02:00
|
|
|
{
|
|
|
|
if (order->GetType() != OT_CONDITIONAL) return INVALID_VEH_ORDER_ID;
|
|
|
|
|
|
|
|
bool skip_order = false;
|
|
|
|
OrderConditionComparator occ = order->GetConditionComparator();
|
|
|
|
uint16 value = order->GetConditionValue();
|
|
|
|
|
|
|
|
switch (order->GetConditionVariable()) {
|
2019-04-10 23:07:06 +02:00
|
|
|
case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, nullptr), value); break;
|
2011-08-30 22:21:01 +02:00
|
|
|
case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
|
2019-01-05 22:10:37 +01:00
|
|
|
case OCV_MAX_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->GetEngine()->reliability), value); break;
|
2011-08-30 22:21:01 +02:00
|
|
|
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
|
|
|
|
case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
|
|
|
|
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
|
|
|
|
case OCV_UNCONDITIONALLY: skip_order = true; break;
|
|
|
|
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, max(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1, 0) / DAYS_IN_LEAP_YEAR, value); break;
|
2008-06-02 10:33:38 +02:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
return skip_order ? order->GetConditionSkipToOrder() : (VehicleOrderID)INVALID_VEH_ORDER_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the vehicle's destination tile from an order.
|
|
|
|
* @param order the order the vehicle currently has
|
|
|
|
* @param v the vehicle to update
|
2009-09-19 11:51:14 +02:00
|
|
|
* @param conditional_depth the depth (amount of steps) to go with conditional orders. This to prevent infinite loops.
|
2011-06-14 21:19:13 +02:00
|
|
|
* @param pbs_look_ahead Whether we are forecasting orders for pbs reservations in advance. If true, the order indices must not be modified.
|
2008-06-02 10:33:38 +02:00
|
|
|
*/
|
2011-06-14 21:19:13 +02:00
|
|
|
bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead)
|
2008-06-02 10:33:38 +02:00
|
|
|
{
|
2013-07-05 21:09:18 +02:00
|
|
|
if (conditional_depth > v->GetNumOrders()) {
|
|
|
|
v->current_order.Free();
|
2019-01-15 00:33:42 +01:00
|
|
|
v->SetDestTile(0);
|
2013-07-05 21:09:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-13 11:18:07 +02:00
|
|
|
|
2008-06-02 10:33:38 +02:00
|
|
|
switch (order->GetType()) {
|
|
|
|
case OT_GOTO_STATION:
|
2019-01-15 00:33:42 +01:00
|
|
|
v->SetDestTile(v->GetOrderStationLocation(order->GetDestination()));
|
2009-07-13 11:18:07 +02:00
|
|
|
return true;
|
2008-06-02 10:33:38 +02:00
|
|
|
|
|
|
|
case OT_GOTO_DEPOT:
|
2010-07-27 23:46:55 +02:00
|
|
|
if ((order->GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) {
|
2011-06-14 21:19:13 +02:00
|
|
|
assert(!pbs_look_ahead);
|
2010-07-27 23:46:55 +02:00
|
|
|
UpdateVehicleTimetable(v, true);
|
2011-01-31 21:44:15 +01:00
|
|
|
v->IncrementRealOrderIndex();
|
2010-07-27 23:46:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-02 10:33:38 +02:00
|
|
|
if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
|
|
|
|
/* We need to search for the nearest depot (hangar). */
|
|
|
|
TileIndex location;
|
|
|
|
DestinationID destination;
|
|
|
|
bool reverse;
|
|
|
|
|
|
|
|
if (v->FindClosestDepot(&location, &destination, &reverse)) {
|
2011-06-14 21:19:13 +02:00
|
|
|
/* PBS reservations cannot reverse */
|
|
|
|
if (pbs_look_ahead && reverse) return false;
|
|
|
|
|
2019-01-15 00:33:42 +01:00
|
|
|
v->SetDestTile(location);
|
2013-02-24 17:41:51 +01:00
|
|
|
v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo());
|
2008-06-02 10:33:38 +02:00
|
|
|
|
|
|
|
/* If there is no depot in front, reverse automatically (trains only) */
|
|
|
|
if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
|
|
|
|
|
2009-05-22 22:07:26 +02:00
|
|
|
if (v->type == VEH_AIRCRAFT) {
|
2009-06-06 18:54:22 +02:00
|
|
|
Aircraft *a = Aircraft::From(v);
|
2009-05-22 22:07:26 +02:00
|
|
|
if (a->state == FLYING && a->targetairport != destination) {
|
|
|
|
/* The aircraft is now heading for a different hangar than the next in the orders */
|
|
|
|
extern void AircraftNextAirportPos_and_Order(Aircraft *a);
|
|
|
|
AircraftNextAirportPos_and_Order(a);
|
|
|
|
}
|
2008-06-02 10:33:38 +02:00
|
|
|
}
|
2009-07-13 11:18:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-28 23:12:54 +02:00
|
|
|
|
2011-06-14 21:19:13 +02:00
|
|
|
/* If there is no depot, we cannot help PBS either. */
|
|
|
|
if (pbs_look_ahead) return false;
|
|
|
|
|
2009-07-13 11:18:07 +02:00
|
|
|
UpdateVehicleTimetable(v, true);
|
2011-01-31 21:44:15 +01:00
|
|
|
v->IncrementRealOrderIndex();
|
2009-07-13 11:18:07 +02:00
|
|
|
} else {
|
|
|
|
if (v->type != VEH_AIRCRAFT) {
|
2019-01-15 00:33:42 +01:00
|
|
|
v->SetDestTile(Depot::Get(order->GetDestination())->xy);
|
2018-10-02 01:27:07 +02:00
|
|
|
} else {
|
|
|
|
Aircraft *a = Aircraft::From(v);
|
|
|
|
DestinationID destination = a->current_order.GetDestination();
|
|
|
|
if (a->targetairport != destination) {
|
|
|
|
/* The aircraft is now heading for a different hangar than the next in the orders */
|
|
|
|
a->SetDestTile(a->GetOrderStationLocation(destination));
|
|
|
|
}
|
2008-06-02 10:33:38 +02:00
|
|
|
}
|
2009-07-13 11:18:07 +02:00
|
|
|
return true;
|
2008-06-02 10:33:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_GOTO_WAYPOINT:
|
2019-01-15 00:33:42 +01:00
|
|
|
v->SetDestTile(Waypoint::Get(order->GetDestination())->xy);
|
2009-07-13 11:18:07 +02:00
|
|
|
return true;
|
2008-06-02 10:33:38 +02:00
|
|
|
|
|
|
|
case OT_CONDITIONAL: {
|
2011-06-14 21:19:13 +02:00
|
|
|
assert(!pbs_look_ahead);
|
2008-06-02 10:33:38 +02:00
|
|
|
VehicleOrderID next_order = ProcessConditionalOrder(order, v);
|
|
|
|
if (next_order != INVALID_VEH_ORDER_ID) {
|
2011-05-18 14:19:58 +02:00
|
|
|
/* Jump to next_order. cur_implicit_order_index becomes exactly that order,
|
2011-01-31 21:44:15 +01:00
|
|
|
* cur_real_order_index might come after next_order. */
|
2008-07-14 23:01:49 +02:00
|
|
|
UpdateVehicleTimetable(v, false);
|
2011-05-18 14:19:58 +02:00
|
|
|
v->cur_implicit_order_index = v->cur_real_order_index = next_order;
|
2011-01-31 21:44:15 +01:00
|
|
|
v->UpdateRealOrderIndex();
|
2014-05-01 16:49:16 +02:00
|
|
|
v->current_order_time += v->GetOrder(v->cur_real_order_index)->GetTimetabledTravel();
|
2011-04-16 19:02:28 +02:00
|
|
|
|
2011-05-18 14:19:58 +02:00
|
|
|
/* Disable creation of implicit orders.
|
2011-04-16 19:02:28 +02:00
|
|
|
* When inserting them we do not know that we would have to make the conditional orders point to them. */
|
|
|
|
if (v->IsGroundVehicle()) {
|
|
|
|
uint16 &gv_flags = v->GetGroundVehicleFlags();
|
2011-05-18 14:19:58 +02:00
|
|
|
SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
|
2011-04-16 19:02:28 +02:00
|
|
|
}
|
2008-06-02 10:33:38 +02:00
|
|
|
} else {
|
2008-07-14 23:01:49 +02:00
|
|
|
UpdateVehicleTimetable(v, true);
|
2011-01-31 21:44:15 +01:00
|
|
|
v->IncrementRealOrderIndex();
|
2008-06-02 10:33:38 +02:00
|
|
|
}
|
2009-07-13 11:18:07 +02:00
|
|
|
break;
|
2008-06-02 10:33:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2019-01-15 00:33:42 +01:00
|
|
|
v->SetDestTile(0);
|
2008-06-02 10:33:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-13 11:18:07 +02:00
|
|
|
|
2011-05-18 14:19:58 +02:00
|
|
|
assert(v->cur_implicit_order_index < v->GetNumOrders());
|
2011-01-31 21:44:15 +01:00
|
|
|
assert(v->cur_real_order_index < v->GetNumOrders());
|
2009-07-13 11:18:07 +02:00
|
|
|
|
|
|
|
/* Get the current order */
|
2011-01-31 21:44:15 +01:00
|
|
|
order = v->GetOrder(v->cur_real_order_index);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (order != nullptr && order->IsType(OT_IMPLICIT)) {
|
2011-01-31 21:44:15 +01:00
|
|
|
assert(v->GetNumManualOrders() == 0);
|
2019-04-10 23:07:06 +02:00
|
|
|
order = nullptr;
|
2011-01-31 21:44:15 +01:00
|
|
|
}
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
if (order == nullptr) {
|
2011-01-31 21:44:15 +01:00
|
|
|
v->current_order.Free();
|
2019-01-15 00:33:42 +01:00
|
|
|
v->SetDestTile(0);
|
2011-01-31 21:44:15 +01:00
|
|
|
return false;
|
2010-12-26 10:03:19 +01:00
|
|
|
}
|
2011-01-31 21:44:15 +01:00
|
|
|
|
2009-07-13 11:18:07 +02:00
|
|
|
v->current_order = *order;
|
2011-06-14 21:19:13 +02:00
|
|
|
return UpdateOrderDest(v, order, conditional_depth + 1, pbs_look_ahead);
|
2008-06-02 10:33:38 +02:00
|
|
|
}
|
|
|
|
|
2008-04-05 12:55:50 +02:00
|
|
|
/**
|
|
|
|
* Handle the orders of a vehicle and determine the next place
|
|
|
|
* to go to if needed.
|
|
|
|
* @param v the vehicle to do this for.
|
|
|
|
* @return true *if* the vehicle is eligible for reversing
|
|
|
|
* (basically only when leaving a station).
|
|
|
|
*/
|
|
|
|
bool ProcessOrders(Vehicle *v)
|
|
|
|
{
|
2008-04-06 01:36:54 +02:00
|
|
|
switch (v->current_order.GetType()) {
|
2008-04-05 12:55:50 +02:00
|
|
|
case OT_GOTO_DEPOT:
|
|
|
|
/* Let a depot order in the orderlist interrupt. */
|
2008-04-07 21:18:56 +02:00
|
|
|
if (!(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) return false;
|
2008-04-05 12:55:50 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_LOADING:
|
|
|
|
return false;
|
|
|
|
|
2008-04-05 14:01:34 +02:00
|
|
|
case OT_LEAVESTATION:
|
|
|
|
if (v->type != VEH_AIRCRAFT) return false;
|
|
|
|
break;
|
|
|
|
|
2008-04-05 12:55:50 +02:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reversing because of order change is allowed only just after leaving a
|
|
|
|
* station (and the difficulty setting to allowed, of course)
|
|
|
|
* this can be detected because only after OT_LEAVESTATION, current_order
|
|
|
|
* will be reset to nothing. (That also happens if no order, but in that case
|
|
|
|
* it won't hit the point in code where may_reverse is checked)
|
|
|
|
*/
|
2008-04-06 01:36:54 +02:00
|
|
|
bool may_reverse = v->current_order.IsType(OT_NOTHING);
|
2008-04-05 12:55:50 +02:00
|
|
|
|
2010-08-20 17:30:21 +02:00
|
|
|
/* Check if we've reached a 'via' destination. */
|
2009-07-24 17:18:25 +02:00
|
|
|
if (((v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) || v->current_order.IsType(OT_GOTO_WAYPOINT)) &&
|
2008-04-05 12:55:50 +02:00
|
|
|
IsTileType(v->tile, MP_STATION) &&
|
2008-04-06 09:48:51 +02:00
|
|
|
v->current_order.GetDestination() == GetStationIndex(v->tile)) {
|
2011-05-18 14:19:58 +02:00
|
|
|
v->DeleteUnreachedImplicitOrders();
|
2010-08-20 17:30:21 +02:00
|
|
|
/* We set the last visited station here because we do not want
|
|
|
|
* the train to stop at this 'via' station if the next order
|
|
|
|
* is a no-non-stop order; in that case not setting the last
|
|
|
|
* visited station will cause the vehicle to still stop. */
|
|
|
|
v->last_station_visited = v->current_order.GetDestination();
|
2008-04-05 12:55:50 +02:00
|
|
|
UpdateVehicleTimetable(v, true);
|
2011-05-18 14:19:58 +02:00
|
|
|
v->IncrementImplicitOrderIndex();
|
2008-04-05 12:55:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the current order */
|
2011-05-18 14:19:58 +02:00
|
|
|
assert(v->cur_implicit_order_index == 0 || v->cur_implicit_order_index < v->GetNumOrders());
|
2011-01-31 21:44:15 +01:00
|
|
|
v->UpdateRealOrderIndex();
|
2008-04-05 12:55:50 +02:00
|
|
|
|
2011-01-31 21:44:15 +01:00
|
|
|
const Order *order = v->GetOrder(v->cur_real_order_index);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (order != nullptr && order->IsType(OT_IMPLICIT)) {
|
2011-01-31 21:44:15 +01:00
|
|
|
assert(v->GetNumManualOrders() == 0);
|
2019-04-10 23:07:06 +02:00
|
|
|
order = nullptr;
|
2011-01-31 21:44:15 +01:00
|
|
|
}
|
2008-04-05 12:55:50 +02:00
|
|
|
|
|
|
|
/* If no order, do nothing. */
|
2019-04-10 23:07:06 +02:00
|
|
|
if (order == nullptr || (v->type == VEH_AIRCRAFT && !CheckForValidOrders(v))) {
|
2008-04-05 14:01:34 +02:00
|
|
|
if (v->type == VEH_AIRCRAFT) {
|
|
|
|
/* Aircraft do something vastly different here, so handle separately */
|
2009-05-22 22:03:26 +02:00
|
|
|
extern void HandleMissingAircraftOrders(Aircraft *v);
|
2009-06-06 18:54:22 +02:00
|
|
|
HandleMissingAircraftOrders(Aircraft::From(v));
|
2008-04-05 14:01:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-05 12:55:50 +02:00
|
|
|
v->current_order.Free();
|
2019-01-15 00:33:42 +01:00
|
|
|
v->SetDestTile(0);
|
2008-04-05 12:55:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it is unchanged, keep it. */
|
2008-04-13 12:26:39 +02:00
|
|
|
if (order->Equals(v->current_order) && (v->type == VEH_AIRCRAFT || v->dest_tile != 0) &&
|
2019-07-06 14:54:33 +02:00
|
|
|
(v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || Station::Get(order->GetDestination())->ship_station.tile != INVALID_TILE)) {
|
2008-04-05 12:55:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise set it, and determine the destination tile. */
|
|
|
|
v->current_order = *order;
|
|
|
|
|
2012-12-20 20:44:02 +01:00
|
|
|
InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
|
2008-04-05 12:55:50 +02:00
|
|
|
switch (v->type) {
|
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
|
|
|
|
case VEH_ROAD:
|
|
|
|
case VEH_TRAIN:
|
|
|
|
break;
|
|
|
|
|
2008-04-05 14:01:34 +02:00
|
|
|
case VEH_AIRCRAFT:
|
2008-04-05 12:55:50 +02:00
|
|
|
case VEH_SHIP:
|
2009-09-13 21:15:59 +02:00
|
|
|
SetWindowClassesDirty(GetWindowClassForVehicleType(v->type));
|
2008-04-05 12:55:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-02 10:33:38 +02:00
|
|
|
return UpdateOrderDest(v, order) && may_reverse;
|
2008-04-05 12:55:50 +02:00
|
|
|
}
|
2005-01-15 20:06:22 +01:00
|
|
|
|
2008-04-05 17:30:15 +02:00
|
|
|
/**
|
|
|
|
* Check whether the given vehicle should stop at the given station
|
|
|
|
* based on this order and the non-stop settings.
|
|
|
|
* @param v the vehicle that might be stopping.
|
|
|
|
* @param station the station to stop at.
|
|
|
|
* @return true if the vehicle should stop.
|
|
|
|
*/
|
|
|
|
bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const
|
|
|
|
{
|
2008-04-15 14:25:35 +02:00
|
|
|
bool is_dest_station = this->IsType(OT_GOTO_STATION) && this->dest == station;
|
2010-11-20 16:44:24 +01:00
|
|
|
|
|
|
|
return (!this->IsType(OT_GOTO_DEPOT) || (this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0) &&
|
2008-04-05 17:30:15 +02:00
|
|
|
v->last_station_visited != station && // Do stop only when we've not just been there
|
2008-04-07 10:59:04 +02:00
|
|
|
/* Finally do stop when there is no non-stop flag set for this type of station. */
|
2008-04-15 14:25:35 +02:00
|
|
|
!(this->GetNonStopType() & (is_dest_station ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS));
|
2008-04-05 17:30:15 +02:00
|
|
|
}
|
2013-05-19 16:22:04 +02:00
|
|
|
|
|
|
|
bool Order::CanLoadOrUnload() const
|
|
|
|
{
|
|
|
|
return (this->IsType(OT_GOTO_STATION) || this->IsType(OT_IMPLICIT)) &&
|
|
|
|
(this->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0 &&
|
|
|
|
((this->GetLoadType() & OLFB_NO_LOAD) == 0 ||
|
|
|
|
(this->GetUnloadType() & OUFB_NO_UNLOAD) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A vehicle can leave the current station with cargo if:
|
|
|
|
* 1. it can load cargo here OR
|
|
|
|
* 2a. it could leave the last station with cargo AND
|
|
|
|
* 2b. it doesn't have to unload all cargo here.
|
|
|
|
*/
|
|
|
|
bool Order::CanLeaveWithCargo(bool has_cargo) const
|
|
|
|
{
|
|
|
|
return (this->GetLoadType() & OLFB_NO_LOAD) == 0 || (has_cargo &&
|
|
|
|
(this->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == 0);
|
|
|
|
}
|