2009-08-21 20:21:05 +00: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 15:11:33 +00:00
|
|
|
/** @file order_base.h Base class for orders. */
|
2005-07-28 06:09:15 +00:00
|
|
|
|
2008-03-30 23:24:18 +00:00
|
|
|
#ifndef ORDER_BASE_H
|
|
|
|
#define ORDER_BASE_H
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2008-03-28 16:36:32 +00:00
|
|
|
#include "order_type.h"
|
2009-05-22 15:39:22 +00:00
|
|
|
#include "core/pool_type.hpp"
|
2007-12-21 19:21:21 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "cargo_type.h"
|
2008-04-05 23:36:54 +00:00
|
|
|
#include "depot_type.h"
|
2008-04-05 15:30:15 +00:00
|
|
|
#include "station_type.h"
|
|
|
|
#include "vehicle_type.h"
|
2009-11-21 12:43:09 +00:00
|
|
|
#include "date_type.h"
|
2017-05-29 18:37:08 +00:00
|
|
|
#include "schdispatch.h"
|
2021-11-01 18:33:39 +00:00
|
|
|
#include "saveload/saveload_common.h"
|
2005-02-06 10:24:57 +00:00
|
|
|
|
2016-09-05 00:36:55 +00:00
|
|
|
#include <memory>
|
2016-09-04 11:01:18 +00:00
|
|
|
#include <vector>
|
2019-05-12 03:24:10 +00:00
|
|
|
#include "3rdparty/cpp-btree/btree_map.h"
|
2016-09-04 11:01:18 +00:00
|
|
|
|
2019-02-18 07:37:25 +00:00
|
|
|
typedef Pool<Order, OrderID, 256, 0xFF0000> OrderPool;
|
2009-05-22 15:13:50 +00:00
|
|
|
typedef Pool<OrderList, OrderListID, 128, 64000> OrderListPool;
|
|
|
|
extern OrderPool _order_pool;
|
|
|
|
extern OrderListPool _orderlist_pool;
|
2019-05-12 03:24:10 +00:00
|
|
|
extern btree::btree_map<uint32, uint32> _order_destination_refcount_map;
|
|
|
|
extern bool _order_destination_refcount_map_valid;
|
|
|
|
|
|
|
|
inline uint32 OrderDestinationRefcountMapKey(DestinationID dest, CompanyID cid, OrderType order_type, VehicleType veh_type)
|
|
|
|
{
|
2021-01-30 23:24:40 +00:00
|
|
|
static_assert(sizeof(dest) == 2);
|
|
|
|
static_assert(OT_END <= 16);
|
2019-05-12 03:24:10 +00:00
|
|
|
return (((uint32) dest) << 16) | (((uint32) cid) << 8) | (((uint32) order_type) << 4) | ((uint32) veh_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename F> void IterateOrderRefcountMapForDestinationID(DestinationID dest, F handler)
|
|
|
|
{
|
|
|
|
for (auto lb = _order_destination_refcount_map.lower_bound(OrderDestinationRefcountMapKey(dest, (CompanyID) 0, (OrderType) 0, (VehicleType) 0)); lb != _order_destination_refcount_map.end(); ++lb) {
|
|
|
|
if (GB(lb->first, 16, 16) != dest) return;
|
|
|
|
if (lb->second && !handler((CompanyID) GB(lb->first, 8, 8), (OrderType) GB(lb->first, 4, 4), (VehicleType) GB(lb->first, 0, 4), lb->second)) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntialiseOrderDestinationRefcountMap();
|
|
|
|
void ClearOrderDestinationRefcountMap();
|
2007-08-02 23:40:19 +00:00
|
|
|
|
2016-09-04 19:50:20 +00:00
|
|
|
struct OrderExtraInfo {
|
2016-09-05 00:36:55 +00:00
|
|
|
uint8 cargo_type_flags[NUM_CARGO] = {}; ///< Load/unload types for each cargo type.
|
2018-04-21 17:57:22 +00:00
|
|
|
uint32 xdata = 0; ///< Extra arbitrary data
|
2022-01-13 19:46:43 +00:00
|
|
|
uint16 dispatch_index = 0; ///< Scheduled dispatch index + 1
|
2017-12-18 01:26:27 +00:00
|
|
|
uint8 xflags = 0; ///< Extra flags
|
2016-09-04 19:50:20 +00:00
|
|
|
};
|
|
|
|
|
2021-11-01 18:33:39 +00:00
|
|
|
namespace upstream_sl {
|
|
|
|
SaveLoadTable GetOrderDescription();
|
|
|
|
SaveLoadTable GetOrderListDescription();
|
|
|
|
class SlVehicleCommon;
|
|
|
|
class SlVehicleDisaster;
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* If you change this, keep in mind that it is saved on 3 places:
|
2006-06-27 21:25:53 +00:00
|
|
|
* - Load_ORDR, all the global orders
|
|
|
|
* - Vehicle -> current_order
|
2007-06-20 19:17:22 +00:00
|
|
|
* - REF_ORDER (all REFs are currently limited to 16 bits!!)
|
2006-06-27 21:25:53 +00:00
|
|
|
*/
|
2009-05-22 15:13:50 +00:00
|
|
|
struct Order : OrderPool::PoolItem<&_order_pool> {
|
2008-04-05 23:36:54 +00:00
|
|
|
private:
|
2021-05-31 20:26:44 +00:00
|
|
|
friend SaveLoadTable GetVehicleDescription(VehicleType vt); ///< Saving and loading the current order of vehicles.
|
2008-04-05 23:36:54 +00:00
|
|
|
friend void Load_VEHS(); ///< Loading of ancient vehicles.
|
2021-10-18 17:01:27 +00:00
|
|
|
friend SaveLoadTable GetOrderDescription(); ///< Saving and loading of orders.
|
2021-11-01 18:33:39 +00:00
|
|
|
friend upstream_sl::SaveLoadTable upstream_sl::GetOrderDescription(); ///< Saving and loading of orders.
|
|
|
|
friend upstream_sl::SlVehicleCommon;
|
|
|
|
friend upstream_sl::SlVehicleDisaster;
|
2016-09-04 19:50:20 +00:00
|
|
|
friend void Load_ORDX(); ///< Saving and loading of orders.
|
|
|
|
friend void Save_ORDX(); ///< Saving and loading of orders.
|
2016-10-11 18:01:16 +00:00
|
|
|
friend void Load_VEOX(); ///< Saving and loading of orders.
|
|
|
|
friend void Save_VEOX(); ///< Saving and loading of orders.
|
2007-02-04 13:46:21 +00:00
|
|
|
|
2020-10-17 14:21:38 +00:00
|
|
|
std::unique_ptr<OrderExtraInfo> extra; ///< Extra order info
|
|
|
|
|
|
|
|
uint16 flags; ///< Load/unload types, depot order/action types.
|
2008-04-06 07:48:51 +00:00
|
|
|
DestinationID dest; ///< The destination of the order.
|
2020-10-17 14:21:38 +00:00
|
|
|
uint8 type; ///< The type of order + non-stop flags
|
2008-04-06 07:07:21 +00:00
|
|
|
|
|
|
|
CargoID refit_cargo; ///< Refit CargoID
|
2008-04-05 23:36:54 +00:00
|
|
|
|
2015-08-09 22:39:55 +00:00
|
|
|
uint8 occupancy; ///< Estimate of vehicle occupancy on departure, for the current order, 0 indicates invalid, 1 - 101 indicate 0 - 100%
|
|
|
|
|
2018-10-22 17:21:30 +00:00
|
|
|
TimetableTicks wait_time; ///< How long in ticks to wait at the destination.
|
|
|
|
TimetableTicks travel_time; ///< How long in ticks the journey to this destination should take.
|
|
|
|
uint16 max_speed; ///< How fast the vehicle may go on the way to the destination.
|
2007-06-20 19:17:22 +00:00
|
|
|
|
2016-09-04 19:50:20 +00:00
|
|
|
void AllocExtraInfo();
|
|
|
|
void DeAllocExtraInfo();
|
|
|
|
|
|
|
|
inline void CheckExtraInfoAlloced()
|
|
|
|
{
|
|
|
|
if (!this->extra) this->AllocExtraInfo();
|
|
|
|
}
|
|
|
|
|
2017-12-18 01:26:27 +00:00
|
|
|
inline uint8 GetXFlags() const
|
|
|
|
{
|
|
|
|
return this->extra != nullptr ? this->extra->xflags : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint8 &GetXFlagsRef()
|
|
|
|
{
|
|
|
|
CheckExtraInfoAlloced();
|
|
|
|
return this->extra->xflags;
|
|
|
|
}
|
|
|
|
|
2014-05-01 14:48:44 +00:00
|
|
|
public:
|
2018-04-21 17:57:22 +00:00
|
|
|
inline uint32 GetXData() const
|
|
|
|
{
|
|
|
|
return this->extra != nullptr ? this->extra->xdata : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32 &GetXDataRef()
|
|
|
|
{
|
|
|
|
CheckExtraInfoAlloced();
|
|
|
|
return this->extra->xdata;
|
|
|
|
}
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
Order *next; ///< Pointer to next order. If nullptr, end of list
|
2014-05-01 14:48:44 +00:00
|
|
|
|
2019-03-25 22:45:32 +00:00
|
|
|
Order() : flags(0), refit_cargo(CT_NO_REFIT), max_speed(UINT16_MAX) {}
|
2011-11-12 18:06:34 +00:00
|
|
|
~Order();
|
2007-08-02 23:40:19 +00:00
|
|
|
|
2020-10-17 14:21:38 +00:00
|
|
|
Order(uint64 packed);
|
2008-04-06 07:22:26 +00:00
|
|
|
|
2016-09-05 00:36:55 +00:00
|
|
|
Order(const Order& other)
|
2016-09-04 19:50:20 +00:00
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
2016-09-05 00:36:55 +00:00
|
|
|
Order(Order&& other) = default;
|
|
|
|
|
2016-09-04 19:50:20 +00:00
|
|
|
inline Order& operator=(Order const& other)
|
|
|
|
{
|
|
|
|
AssignOrder(other);
|
|
|
|
this->next = other.next;
|
|
|
|
this->index = other.index;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2008-04-05 23:36:54 +00:00
|
|
|
/**
|
|
|
|
* Check whether this order is of the given type.
|
|
|
|
* @param type the type to check against.
|
|
|
|
* @return true if the order matches.
|
|
|
|
*/
|
2008-04-10 08:30:15 +00:00
|
|
|
inline bool IsType(OrderType type) const { return this->GetType() == type; }
|
2008-04-05 23:36:54 +00:00
|
|
|
|
2018-03-26 19:12:50 +00:00
|
|
|
/**
|
|
|
|
* Check whether this order is either of OT_LOADING or OT_LOADING_ADVANCE.
|
|
|
|
* @return true if the order matches.
|
|
|
|
*/
|
|
|
|
inline bool IsAnyLoadingType() const { return this->GetType() == OT_LOADING || this->GetType() == OT_LOADING_ADVANCE; }
|
|
|
|
|
2008-04-05 23:36:54 +00:00
|
|
|
/**
|
|
|
|
* Get the type of order of this order.
|
|
|
|
* @return the order type.
|
|
|
|
*/
|
2008-04-12 11:58:19 +00:00
|
|
|
inline OrderType GetType() const { return (OrderType)GB(this->type, 0, 4); }
|
2008-04-05 23:36:54 +00:00
|
|
|
|
2007-03-08 21:39:34 +00:00
|
|
|
void Free();
|
2008-04-05 20:57:01 +00:00
|
|
|
|
2008-04-05 23:36:54 +00:00
|
|
|
void MakeGoToStation(StationID destination);
|
2013-02-24 16:41:51 +00:00
|
|
|
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type = ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action = ODATF_SERVICE_ONLY, CargoID cargo = CT_NO_REFIT);
|
2009-07-28 21:06:38 +00:00
|
|
|
void MakeGoToWaypoint(StationID destination);
|
2008-04-06 15:09:45 +00:00
|
|
|
void MakeLoading(bool ordered);
|
2008-04-05 23:36:54 +00:00
|
|
|
void MakeLeaveStation();
|
|
|
|
void MakeDummy();
|
2008-04-12 11:58:19 +00:00
|
|
|
void MakeConditional(VehicleOrderID order);
|
2011-05-18 12:19:58 +00:00
|
|
|
void MakeImplicit(StationID destination);
|
2015-08-03 00:06:05 +00:00
|
|
|
void MakeWaiting();
|
2018-03-26 19:12:50 +00:00
|
|
|
void MakeLoadingAdvance(StationID destination);
|
2021-02-10 22:30:22 +00:00
|
|
|
void MakeReleaseSlot();
|
2022-10-13 19:09:20 +00:00
|
|
|
void MakeChangeCounter();
|
2010-12-26 09:03:19 +00:00
|
|
|
|
2011-12-13 00:43:48 +00:00
|
|
|
/**
|
|
|
|
* Is this a 'goto' order with a real destination?
|
2011-12-13 00:54:13 +00:00
|
|
|
* @return True if the type is either #OT_GOTO_WAYPOINT, #OT_GOTO_DEPOT or #OT_GOTO_STATION.
|
2011-12-13 00:43:48 +00:00
|
|
|
*/
|
|
|
|
inline bool IsGotoOrder() const
|
|
|
|
{
|
|
|
|
return IsType(OT_GOTO_WAYPOINT) || IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION);
|
|
|
|
}
|
|
|
|
|
2021-01-25 02:33:14 +00:00
|
|
|
/**
|
|
|
|
* Is this an order with a BaseStation destination?
|
|
|
|
* @return True if the type is either #OT_IMPLICIT, #OT_GOTO_STATION or #OT_GOTO_WAYPOINT.
|
|
|
|
*/
|
|
|
|
inline bool IsBaseStationOrder() const
|
|
|
|
{
|
|
|
|
return IsType(OT_IMPLICIT) || IsType(OT_GOTO_STATION) || IsType(OT_GOTO_WAYPOINT);
|
|
|
|
}
|
|
|
|
|
2008-04-06 07:48:51 +00:00
|
|
|
/**
|
|
|
|
* Gets the destination of this order.
|
2022-10-13 19:09:20 +00:00
|
|
|
* @pre IsType(OT_GOTO_WAYPOINT) || IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION) || IsType(OT_RELEASE_SLOT) || IsType(OT_COUNTER).
|
2008-04-06 07:48:51 +00:00
|
|
|
* @return the destination of the order.
|
|
|
|
*/
|
|
|
|
inline DestinationID GetDestination() const { return this->dest; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the destination of this order.
|
|
|
|
* @param destination the new destination of the order.
|
2022-10-13 19:09:20 +00:00
|
|
|
* @pre IsType(OT_GOTO_WAYPOINT) || IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION) || IsType(OT_RELEASE_SLOT) || IsType(OT_COUNTER).
|
2008-04-06 07:48:51 +00:00
|
|
|
*/
|
|
|
|
inline void SetDestination(DestinationID destination) { this->dest = destination; }
|
|
|
|
|
2008-04-06 07:07:21 +00:00
|
|
|
/**
|
|
|
|
* Is this order a refit order.
|
2011-11-04 00:38:51 +00:00
|
|
|
* @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
|
2008-04-06 07:07:21 +00:00
|
|
|
* @return true if a refit should happen.
|
|
|
|
*/
|
2011-11-04 00:38:51 +00:00
|
|
|
inline bool IsRefit() const { return this->refit_cargo < NUM_CARGO || this->refit_cargo == CT_AUTO_REFIT; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this order a auto-refit order.
|
|
|
|
* @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
|
|
|
|
* @return true if a auto-refit should happen.
|
|
|
|
*/
|
|
|
|
inline bool IsAutoRefit() const { return this->refit_cargo == CT_AUTO_REFIT; }
|
2008-04-06 07:07:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cargo to to refit to.
|
2011-11-04 00:38:51 +00:00
|
|
|
* @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION)
|
2008-04-06 07:07:21 +00:00
|
|
|
* @return the cargo type.
|
|
|
|
*/
|
|
|
|
inline CargoID GetRefitCargo() const { return this->refit_cargo; }
|
|
|
|
|
2013-02-24 16:41:51 +00:00
|
|
|
void SetRefit(CargoID cargo);
|
2008-04-06 07:07:21 +00:00
|
|
|
|
2015-08-26 21:19:35 +00:00
|
|
|
/**
|
|
|
|
* Update the jump_counter of this order.
|
2020-08-21 16:06:51 +00:00
|
|
|
* @param percent the jump chance in %.
|
|
|
|
* @param dry_run whether this is a dry-run, so do not execute side-effects
|
2015-08-26 21:19:35 +00:00
|
|
|
* @return whether to jump or not.
|
|
|
|
* @pre IsType(OT_CONDITIONAL) && this->GetConditionVariable() == OCV_PERCENT.
|
|
|
|
*/
|
2020-08-21 16:06:51 +00:00
|
|
|
bool UpdateJumpCounter(uint8 percent, bool dry_run);
|
2015-08-26 21:19:35 +00:00
|
|
|
|
2008-04-06 15:09:45 +00:00
|
|
|
/** How must the consist be loaded? */
|
2016-09-07 23:12:27 +00:00
|
|
|
inline OrderLoadFlags GetLoadType() const
|
|
|
|
{
|
|
|
|
OrderLoadFlags type = (OrderLoadFlags)GB(this->flags, 4, 3);
|
|
|
|
if (type == OLFB_CARGO_TYPE_LOAD_ENCODING) type = OLFB_CARGO_TYPE_LOAD;
|
|
|
|
return type;
|
|
|
|
}
|
2016-09-03 21:18:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How must the consist be loaded for this type of cargo?
|
|
|
|
* @pre GetLoadType() == OLFB_CARGO_TYPE_LOAD
|
|
|
|
* @param cargo_id The cargo type index.
|
|
|
|
* @return The load type for this cargo.
|
|
|
|
*/
|
2016-09-03 21:59:19 +00:00
|
|
|
inline OrderLoadFlags GetCargoLoadTypeRaw(CargoID cargo_id) const
|
2016-09-03 21:18:01 +00:00
|
|
|
{
|
|
|
|
assert(cargo_id < NUM_CARGO);
|
2016-09-04 19:50:20 +00:00
|
|
|
if (!this->extra) return OLF_LOAD_IF_POSSIBLE;
|
|
|
|
return (OrderLoadFlags) GB(this->extra->cargo_type_flags[cargo_id], 4, 4);
|
2016-09-03 21:18:01 +00:00
|
|
|
}
|
|
|
|
|
2016-09-03 21:59:19 +00:00
|
|
|
/**
|
|
|
|
* How must the consist be loaded for this type of cargo?
|
|
|
|
* @param cargo_id The cargo type index.
|
|
|
|
* @return The load type for this cargo.
|
|
|
|
*/
|
|
|
|
inline OrderLoadFlags GetCargoLoadType(CargoID cargo_id) const
|
|
|
|
{
|
|
|
|
assert(cargo_id < NUM_CARGO);
|
|
|
|
OrderLoadFlags olf = this->GetLoadType();
|
|
|
|
if (olf == OLFB_CARGO_TYPE_LOAD) olf = this->GetCargoLoadTypeRaw(cargo_id);
|
|
|
|
return olf;
|
|
|
|
}
|
|
|
|
|
2008-04-06 15:09:45 +00:00
|
|
|
/** How must the consist be unloaded? */
|
2016-09-07 23:12:27 +00:00
|
|
|
inline OrderUnloadFlags GetUnloadType() const
|
|
|
|
{
|
|
|
|
OrderUnloadFlags type = (OrderUnloadFlags)GB(this->flags, 0, 3);
|
|
|
|
if (type == OUFB_CARGO_TYPE_UNLOAD_ENCODING) type = OUFB_CARGO_TYPE_UNLOAD;
|
|
|
|
return type;
|
|
|
|
}
|
2016-09-03 21:18:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How must the consist be unloaded for this type of cargo?
|
|
|
|
* @pre GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD
|
|
|
|
* @param cargo_id The cargo type index.
|
|
|
|
* @return The unload type for this cargo.
|
|
|
|
*/
|
2016-09-03 21:59:19 +00:00
|
|
|
inline OrderUnloadFlags GetCargoUnloadTypeRaw(CargoID cargo_id) const
|
2016-09-03 21:18:01 +00:00
|
|
|
{
|
|
|
|
assert(cargo_id < NUM_CARGO);
|
2016-09-04 19:50:20 +00:00
|
|
|
if (!this->extra) return OUF_UNLOAD_IF_POSSIBLE;
|
|
|
|
return (OrderUnloadFlags) GB(this->extra->cargo_type_flags[cargo_id], 0, 4);
|
2016-09-03 21:18:01 +00:00
|
|
|
}
|
|
|
|
|
2016-09-03 21:59:19 +00:00
|
|
|
/**
|
|
|
|
* How must the consist be unloaded for this type of cargo?
|
|
|
|
* @param cargo_id The cargo type index.
|
|
|
|
* @return The unload type for this cargo.
|
|
|
|
*/
|
|
|
|
inline OrderUnloadFlags GetCargoUnloadType(CargoID cargo_id) const
|
|
|
|
{
|
|
|
|
assert(cargo_id < NUM_CARGO);
|
|
|
|
OrderUnloadFlags ouf = this->GetUnloadType();
|
|
|
|
if (ouf == OUFB_CARGO_TYPE_UNLOAD) ouf = this->GetCargoUnloadTypeRaw(cargo_id);
|
|
|
|
return ouf;
|
|
|
|
}
|
|
|
|
|
2018-07-02 18:20:59 +00:00
|
|
|
template <typename F> CargoTypes FilterLoadUnloadTypeCargoMask(F filter_func, CargoTypes cargo_mask = ALL_CARGOTYPES)
|
2016-09-05 19:47:31 +00:00
|
|
|
{
|
|
|
|
if ((this->GetLoadType() == OLFB_CARGO_TYPE_LOAD) || (this->GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD)) {
|
2018-07-02 18:20:59 +00:00
|
|
|
CargoTypes output_mask = cargo_mask;
|
2021-11-01 21:18:24 +00:00
|
|
|
for (CargoID cargo : SetCargoBitIterator(cargo_mask)) {
|
2016-09-05 19:47:31 +00:00
|
|
|
if (!filter_func(this, cargo)) ClrBit(output_mask, cargo);
|
|
|
|
}
|
|
|
|
return output_mask;
|
|
|
|
} else {
|
|
|
|
return filter_func(this, FindFirstBit(cargo_mask)) ? cargo_mask : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-12 14:11:14 +00:00
|
|
|
/** At which stations must we stop? */
|
2008-04-10 08:30:15 +00:00
|
|
|
inline OrderNonStopFlags GetNonStopType() const { return (OrderNonStopFlags)GB(this->type, 6, 2); }
|
2009-04-12 14:11:14 +00:00
|
|
|
/** Where must we stop at the platform? */
|
|
|
|
inline OrderStopLocation GetStopLocation() const { return (OrderStopLocation)GB(this->type, 4, 2); }
|
2008-04-06 15:09:45 +00:00
|
|
|
/** What caused us going to the depot? */
|
2014-05-01 14:49:16 +00:00
|
|
|
inline OrderDepotTypeFlags GetDepotOrderType() const { return (OrderDepotTypeFlags)GB(this->flags, 0, 3); }
|
2008-04-06 15:09:45 +00:00
|
|
|
/** What are we going to do when in the depot. */
|
2014-05-01 14:49:16 +00:00
|
|
|
inline OrderDepotActionFlags GetDepotActionType() const { return (OrderDepotActionFlags)GB(this->flags, 4, 3); }
|
2021-07-23 17:33:24 +00:00
|
|
|
/** Extra depot flags. */
|
|
|
|
inline OrderDepotExtraFlags GetDepotExtraFlags() const { return (OrderDepotExtraFlags)GB(this->flags, 8, 8); }
|
2015-10-28 22:36:21 +00:00
|
|
|
/** What waypoint flags? */
|
2018-08-14 11:35:05 +00:00
|
|
|
inline OrderWaypointFlags GetWaypointFlags() const { return (OrderWaypointFlags)GB(this->flags, 0, 3); }
|
2008-04-12 11:58:19 +00:00
|
|
|
/** What variable do we have to compare? */
|
|
|
|
inline OrderConditionVariable GetConditionVariable() const { return (OrderConditionVariable)GB(this->dest, 11, 5); }
|
|
|
|
/** What is the comparator to use? */
|
|
|
|
inline OrderConditionComparator GetConditionComparator() const { return (OrderConditionComparator)GB(this->type, 5, 3); }
|
|
|
|
/** Get the order to skip to. */
|
|
|
|
inline VehicleOrderID GetConditionSkipToOrder() const { return this->flags; }
|
|
|
|
/** Get the value to base the skip on. */
|
|
|
|
inline uint16 GetConditionValue() const { return GB(this->dest, 0, 11); }
|
2020-10-17 14:10:49 +00:00
|
|
|
/** Get counter for the 'jump xx% of times' option */
|
|
|
|
inline int8 GetJumpCounter() const { return GB(this->GetXData(), 0, 8); }
|
2022-10-13 19:09:20 +00:00
|
|
|
/** Get counter operation */
|
|
|
|
inline uint8 GetCounterOperation() const { return GB(this->flags, 0, 8); }
|
2008-04-06 15:09:45 +00:00
|
|
|
|
|
|
|
/** Set how the consist must be loaded. */
|
2016-09-07 23:12:27 +00:00
|
|
|
inline void SetLoadType(OrderLoadFlags load_type)
|
|
|
|
{
|
|
|
|
if (load_type == OLFB_CARGO_TYPE_LOAD) load_type = OLFB_CARGO_TYPE_LOAD_ENCODING;
|
|
|
|
SB(this->flags, 4, 3, load_type);
|
|
|
|
}
|
2016-09-03 21:18:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set how the consist must be loaded for this type of cargo.
|
|
|
|
* @pre GetLoadType() == OLFB_CARGO_TYPE_LOAD
|
|
|
|
* @param load_type The load type.
|
|
|
|
* @param cargo_id The cargo type index.
|
|
|
|
*/
|
|
|
|
inline void SetLoadType(OrderLoadFlags load_type, CargoID cargo_id)
|
|
|
|
{
|
|
|
|
assert(cargo_id < NUM_CARGO);
|
2016-09-04 19:50:20 +00:00
|
|
|
this->CheckExtraInfoAlloced();
|
|
|
|
SB(this->extra->cargo_type_flags[cargo_id], 4, 4, load_type);
|
2016-09-03 21:18:01 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 15:09:45 +00:00
|
|
|
/** Set how the consist must be unloaded. */
|
2016-09-07 23:12:27 +00:00
|
|
|
inline void SetUnloadType(OrderUnloadFlags unload_type)
|
|
|
|
{
|
|
|
|
if (unload_type == OUFB_CARGO_TYPE_UNLOAD) unload_type = OUFB_CARGO_TYPE_UNLOAD_ENCODING;
|
|
|
|
SB(this->flags, 0, 3, unload_type);
|
|
|
|
}
|
2016-09-03 21:18:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set how the consist must be unloaded for this type of cargo.
|
|
|
|
* @pre GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD
|
|
|
|
* @param unload_type The unload type.
|
|
|
|
* @param cargo_id The cargo type index.
|
|
|
|
*/
|
|
|
|
inline void SetUnloadType(OrderUnloadFlags unload_type, CargoID cargo_id)
|
|
|
|
{
|
|
|
|
assert(cargo_id < NUM_CARGO);
|
2016-09-04 19:50:20 +00:00
|
|
|
this->CheckExtraInfoAlloced();
|
|
|
|
SB(this->extra->cargo_type_flags[cargo_id], 0, 4, unload_type);
|
2016-09-03 21:18:01 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 15:09:45 +00:00
|
|
|
/** Set whether we must stop at stations or not. */
|
2008-04-10 08:30:15 +00:00
|
|
|
inline void SetNonStopType(OrderNonStopFlags non_stop_type) { SB(this->type, 6, 2, non_stop_type); }
|
2009-04-12 14:11:14 +00:00
|
|
|
/** Set where we must stop at the platform. */
|
|
|
|
inline void SetStopLocation(OrderStopLocation stop_location) { SB(this->type, 4, 2, stop_location); }
|
2008-04-06 15:09:45 +00:00
|
|
|
/** Set the cause to go to the depot. */
|
2014-05-01 14:49:16 +00:00
|
|
|
inline void SetDepotOrderType(OrderDepotTypeFlags depot_order_type) { SB(this->flags, 0, 3, depot_order_type); }
|
2008-04-06 15:09:45 +00:00
|
|
|
/** Set what we are going to do in the depot. */
|
2014-05-01 14:49:16 +00:00
|
|
|
inline void SetDepotActionType(OrderDepotActionFlags depot_service_type) { SB(this->flags, 4, 3, depot_service_type); }
|
2021-07-23 17:33:24 +00:00
|
|
|
/** Set what we are going to do in the depot. */
|
|
|
|
inline void SetDepotExtraFlags(OrderDepotExtraFlags depot_extra_flags) { SB(this->flags, 8, 8, depot_extra_flags); }
|
2015-10-28 22:36:21 +00:00
|
|
|
/** Set waypoint flags. */
|
2018-08-14 11:35:05 +00:00
|
|
|
inline void SetWaypointFlags(OrderWaypointFlags waypoint_flags) { SB(this->flags, 0, 3, waypoint_flags); }
|
2008-04-12 11:58:19 +00:00
|
|
|
/** Set variable we have to compare. */
|
|
|
|
inline void SetConditionVariable(OrderConditionVariable condition_variable) { SB(this->dest, 11, 5, condition_variable); }
|
|
|
|
/** Set the comparator to use. */
|
|
|
|
inline void SetConditionComparator(OrderConditionComparator condition_comparator) { SB(this->type, 5, 3, condition_comparator); }
|
|
|
|
/** Get the order to skip to. */
|
|
|
|
inline void SetConditionSkipToOrder(VehicleOrderID order_id) { this->flags = order_id; }
|
|
|
|
/** Set the value to base the skip on. */
|
|
|
|
inline void SetConditionValue(uint16 value) { SB(this->dest, 0, 11, value); }
|
2022-10-13 19:09:20 +00:00
|
|
|
/** Set counter for the 'jump xx% of times' option */
|
2020-10-17 14:10:49 +00:00
|
|
|
inline void SetJumpCounter(int8 jump_counter) { SB(this->GetXDataRef(), 0, 8, jump_counter); }
|
2022-10-13 19:09:20 +00:00
|
|
|
/** Set counter operation */
|
|
|
|
inline void SetCounterOperation(uint8 op) { SB(this->flags, 0, 8, op); }
|
2008-04-06 15:09:45 +00:00
|
|
|
|
2014-05-01 14:49:16 +00:00
|
|
|
/* As conditional orders write their "skip to" order all over the flags, we cannot check the
|
|
|
|
* flags to find out if timetabling is enabled. However, as conditional orders are never
|
|
|
|
* autofilled we can be sure that any non-zero values for their wait_time and travel_time are
|
|
|
|
* explicitly set (but travel_time is actually unused for conditionals). */
|
|
|
|
|
|
|
|
/** Does this order have an explicit wait time set? */
|
2017-12-18 01:26:27 +00:00
|
|
|
inline bool IsWaitTimetabled() const { return this->IsType(OT_CONDITIONAL) ? HasBit(this->GetXFlags(), 0) : HasBit(this->flags, 3); }
|
2014-05-01 14:49:16 +00:00
|
|
|
/** Does this order have an explicit travel time set? */
|
|
|
|
inline bool IsTravelTimetabled() const { return this->IsType(OT_CONDITIONAL) ? this->travel_time > 0 : HasBit(this->flags, 7); }
|
|
|
|
|
|
|
|
/** Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled. */
|
2018-10-22 17:21:30 +00:00
|
|
|
inline TimetableTicks GetTimetabledWait() const { return this->IsWaitTimetabled() ? this->wait_time : 0; }
|
2014-05-01 14:49:16 +00:00
|
|
|
/** Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled. */
|
2018-10-22 17:21:30 +00:00
|
|
|
inline TimetableTicks GetTimetabledTravel() const { return this->IsTravelTimetabled() ? this->travel_time : 0; }
|
2014-05-01 14:49:16 +00:00
|
|
|
/** Get the time in ticks a vehicle will probably wait at the destination (timetabled or not). */
|
2018-10-22 17:21:30 +00:00
|
|
|
inline TimetableTicks GetWaitTime() const { return this->wait_time; }
|
2014-05-01 14:49:16 +00:00
|
|
|
/** Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not). */
|
2018-10-22 17:21:30 +00:00
|
|
|
inline TimetableTicks GetTravelTime() const { return this->travel_time; }
|
2014-05-01 14:48:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the
|
|
|
|
* destination.
|
|
|
|
* @return maximum speed.
|
|
|
|
*/
|
|
|
|
inline uint16 GetMaxSpeed() const { return this->max_speed; }
|
|
|
|
|
2014-05-01 14:49:16 +00:00
|
|
|
/** Set if the wait time is explicitly timetabled (unless the order is conditional). */
|
2017-12-18 01:26:27 +00:00
|
|
|
inline void SetWaitTimetabled(bool timetabled)
|
|
|
|
{
|
|
|
|
if (this->IsType(OT_CONDITIONAL)) {
|
|
|
|
SB(this->GetXFlagsRef(), 0, 1, timetabled ? 1 : 0);
|
|
|
|
} else {
|
|
|
|
SB(this->flags, 3, 1, timetabled ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-01 14:49:16 +00:00
|
|
|
/** Set if the travel time is explicitly timetabled (unless the order is conditional). */
|
|
|
|
inline void SetTravelTimetabled(bool timetabled) { if (!this->IsType(OT_CONDITIONAL)) SB(this->flags, 7, 1, timetabled ? 1 : 0); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time in ticks to wait at the destination.
|
|
|
|
* @param time Time to set as wait time.
|
|
|
|
*/
|
2018-10-22 17:21:30 +00:00
|
|
|
inline void SetWaitTime(TimetableTicks time) { this->wait_time = time; }
|
2014-05-01 14:49:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time in ticks to take for travelling to the destination.
|
|
|
|
* @param time Time to set as travel time.
|
|
|
|
*/
|
2018-10-22 17:21:30 +00:00
|
|
|
inline void SetTravelTime(TimetableTicks time) { this->travel_time = time; }
|
2014-05-01 14:48:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the
|
|
|
|
* destination.
|
|
|
|
* @param speed Speed to be set.
|
|
|
|
*/
|
|
|
|
inline void SetMaxSpeed(uint16 speed) { this->max_speed = speed; }
|
|
|
|
|
2018-07-18 23:32:24 +00:00
|
|
|
/** Does this order have a fixed wait time? */
|
|
|
|
inline bool IsWaitFixed() const { return HasBit(this->GetXFlags(), 1); }
|
|
|
|
|
2018-08-13 00:42:14 +00:00
|
|
|
/** Set if the wait time is fixed */
|
2018-07-18 23:32:24 +00:00
|
|
|
inline void SetWaitFixed(bool fixed)
|
|
|
|
{
|
2022-01-15 15:33:34 +00:00
|
|
|
if (fixed != this->IsWaitFixed()) SB(this->GetXFlagsRef(), 1, 1, fixed ? 1 : 0);
|
2018-08-13 00:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Does this order have a fixed travel time? */
|
|
|
|
inline bool IsTravelFixed() const { return HasBit(this->GetXFlags(), 4); }
|
|
|
|
|
|
|
|
/** Set if the travel time is fixed */
|
|
|
|
inline void SetTravelFixed(bool fixed)
|
|
|
|
{
|
|
|
|
if (!this->IsType(OT_CONDITIONAL) && fixed != IsTravelFixed()) SB(this->GetXFlagsRef(), 4, 1, fixed ? 1 : 0);
|
2018-07-18 23:32:24 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 00:40:17 +00:00
|
|
|
/** Get the leave type */
|
|
|
|
inline OrderLeaveType GetLeaveType() const { return (OrderLeaveType)GB(this->GetXFlags(), 2, 2); }
|
|
|
|
|
|
|
|
/** Set the leave type */
|
|
|
|
inline void SetLeaveType(OrderLeaveType leave_type)
|
|
|
|
{
|
|
|
|
if (leave_type != this->GetLeaveType()) SB(this->GetXFlagsRef(), 2, 2, leave_type);
|
|
|
|
}
|
|
|
|
|
2022-01-27 01:30:22 +00:00
|
|
|
/** Get the road vehicle travel direction */
|
|
|
|
inline DiagDirection GetRoadVehTravelDirection() const { return (DiagDirection)((GB(this->GetXFlags(), 5, 3) - 1) & 0xFF); }
|
|
|
|
|
|
|
|
/** Set the road vehicle travel direction */
|
|
|
|
inline void SetRoadVehTravelDirection(DiagDirection dir)
|
|
|
|
{
|
|
|
|
if (dir != this->GetRoadVehTravelDirection()) SB(this->GetXFlagsRef(), 5, 3, (dir + 1) & 0x7);
|
|
|
|
}
|
|
|
|
|
2015-08-09 22:39:55 +00:00
|
|
|
/**
|
|
|
|
* Get the occupancy value
|
|
|
|
* @return occupancy
|
|
|
|
*/
|
|
|
|
inline uint8 GetOccupancy() const { return this->occupancy; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the occupancy value
|
|
|
|
* @param occupancy The occupancy to set
|
|
|
|
*/
|
|
|
|
inline void SetOccupancy(uint8 occupancy) { this->occupancy = occupancy; }
|
|
|
|
|
2021-03-17 18:00:12 +00:00
|
|
|
bool ShouldStopAtStation(StationID last_station_visited, StationID station, bool waypoint) const;
|
2018-08-14 11:35:05 +00:00
|
|
|
bool ShouldStopAtStation(const Vehicle *v, StationID station, bool waypoint) const;
|
2016-09-04 15:49:27 +00:00
|
|
|
bool CanLeaveWithCargo(bool has_cargo, CargoID cargo) const;
|
2013-05-19 14:22:04 +00:00
|
|
|
|
2011-12-13 00:43:35 +00:00
|
|
|
TileIndex GetLocation(const Vehicle *v, bool airport = false) const;
|
2008-04-05 21:45:05 +00:00
|
|
|
|
2014-05-01 14:49:16 +00:00
|
|
|
/** Checks if travel_time and wait_time apply to this order and if they are timetabled. */
|
2009-01-03 13:52:06 +00:00
|
|
|
inline bool IsCompletelyTimetabled() const
|
|
|
|
{
|
2014-05-01 14:49:16 +00:00
|
|
|
if (!this->IsTravelTimetabled() && !this->IsType(OT_CONDITIONAL)) return false;
|
|
|
|
if (!this->IsWaitTimetabled() && this->IsType(OT_GOTO_STATION) &&
|
|
|
|
!(this->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-03 13:52:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
inline int GetDispatchScheduleIndex() const
|
|
|
|
{
|
|
|
|
return this->extra != nullptr ? (int)this->extra->dispatch_index - 1 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetDispatchScheduleIndex(int schedule_index)
|
|
|
|
{
|
|
|
|
if (schedule_index != this->GetDispatchScheduleIndex()) {
|
|
|
|
this->CheckExtraInfoAlloced();
|
|
|
|
this->extra->dispatch_index = (uint16)(schedule_index + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsScheduledDispatchOrder(bool require_wait_timetabled) const
|
|
|
|
{
|
|
|
|
return this->extra != nullptr && this->extra->dispatch_index > 0 && (!require_wait_timetabled || this->IsWaitTimetabled());
|
|
|
|
}
|
|
|
|
|
2008-04-05 21:45:05 +00:00
|
|
|
void AssignOrder(const Order &other);
|
|
|
|
bool Equals(const Order &other) const;
|
2008-04-06 07:22:26 +00:00
|
|
|
|
2020-10-17 14:21:38 +00:00
|
|
|
uint64 Pack() const;
|
2009-06-21 10:11:04 +00:00
|
|
|
uint16 MapOldOrder() const;
|
2008-04-10 08:30:15 +00:00
|
|
|
void ConvertFromOldSavegame();
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2010-12-22 21:16:34 +00:00
|
|
|
void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord);
|
|
|
|
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord);
|
|
|
|
|
2016-09-04 11:01:18 +00:00
|
|
|
struct CargoMaskedStationIDStack {
|
2018-07-02 18:20:59 +00:00
|
|
|
CargoTypes cargo_mask;
|
2016-09-04 11:01:18 +00:00
|
|
|
StationIDStack station;
|
|
|
|
|
2018-07-02 18:20:59 +00:00
|
|
|
CargoMaskedStationIDStack(CargoTypes cargo_mask, StationIDStack station)
|
2016-09-04 11:01:18 +00:00
|
|
|
: cargo_mask(cargo_mask), station(station) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CargoStationIDStackSet {
|
|
|
|
private:
|
|
|
|
CargoMaskedStationIDStack first;
|
|
|
|
std::vector<CargoMaskedStationIDStack> more;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CargoStationIDStackSet()
|
2018-07-02 18:20:59 +00:00
|
|
|
: first(ALL_CARGOTYPES, INVALID_STATION) {}
|
2016-09-04 11:01:18 +00:00
|
|
|
|
|
|
|
const StationIDStack& Get(CargoID cargo) const
|
|
|
|
{
|
|
|
|
if (HasBit(first.cargo_mask, cargo)) return first.station;
|
|
|
|
for (size_t i = 0; i < more.size(); i++) {
|
|
|
|
if (HasBit(more[i].cargo_mask, cargo)) return more[i].station;
|
|
|
|
}
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
2019-04-11 17:14:13 +00:00
|
|
|
void FillNextStoppingStation(const Vehicle *v, const OrderList *o, const Order *first = nullptr, uint hops = 0);
|
2016-09-04 11:01:18 +00:00
|
|
|
};
|
|
|
|
|
2018-07-02 18:20:59 +00:00
|
|
|
template <typename F> CargoTypes FilterCargoMask(F filter_func, CargoTypes cargo_mask = ALL_CARGOTYPES)
|
2016-09-05 19:47:31 +00:00
|
|
|
{
|
2018-07-02 18:20:59 +00:00
|
|
|
CargoTypes output_mask = cargo_mask;
|
2021-11-01 21:18:24 +00:00
|
|
|
for (CargoID cargo : SetCargoBitIterator(cargo_mask)) {
|
2016-09-05 19:47:31 +00:00
|
|
|
if (!filter_func(cargo)) ClrBit(output_mask, cargo);
|
|
|
|
}
|
|
|
|
return output_mask;
|
|
|
|
}
|
|
|
|
|
2018-07-02 18:20:59 +00:00
|
|
|
template <typename T, typename F> T CargoMaskValueFilter(CargoTypes &cargo_mask, F filter_func)
|
2016-09-04 22:58:17 +00:00
|
|
|
{
|
2021-11-01 23:00:44 +00:00
|
|
|
CargoID first_cargo_id = FindFirstBit(cargo_mask);
|
2016-09-04 22:58:17 +00:00
|
|
|
T value = filter_func(first_cargo_id);
|
2018-07-02 18:20:59 +00:00
|
|
|
CargoTypes other_cargo_mask = cargo_mask;
|
2016-09-04 22:58:17 +00:00
|
|
|
ClrBit(other_cargo_mask, first_cargo_id);
|
2021-11-01 21:18:24 +00:00
|
|
|
for (CargoID cargo : SetCargoBitIterator(other_cargo_mask)) {
|
2016-09-04 22:58:17 +00:00
|
|
|
if (value != filter_func(cargo)) ClrBit(cargo_mask, cargo);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
struct DispatchSchedule {
|
|
|
|
private:
|
|
|
|
friend SaveLoadTable GetDispatchScheduleDescription(); ///< Saving and loading of dispatch schedules
|
|
|
|
|
|
|
|
std::vector<uint32> scheduled_dispatch; ///< Scheduled dispatch time
|
|
|
|
uint32 scheduled_dispatch_duration = 0; ///< Scheduled dispatch duration
|
|
|
|
Date scheduled_dispatch_start_date = -1; ///< Scheduled dispatch start date
|
|
|
|
uint16 scheduled_dispatch_start_full_date_fract = 0; ///< Scheduled dispatch start full date fraction;
|
|
|
|
/// this counts to (DAY_TICK * _settings_game.economy.day_length_factor)
|
|
|
|
int32 scheduled_dispatch_last_dispatch = 0; ///< Last vehicle dispatched offset
|
|
|
|
int32 scheduled_dispatch_max_delay = 0; ///< Maximum allowed delay
|
|
|
|
|
2022-01-14 22:53:55 +00:00
|
|
|
inline void CopyBasicFields(const DispatchSchedule &other)
|
|
|
|
{
|
|
|
|
this->scheduled_dispatch_duration = other.scheduled_dispatch_duration;
|
|
|
|
this->scheduled_dispatch_start_date = other.scheduled_dispatch_start_date;
|
|
|
|
this->scheduled_dispatch_start_full_date_fract = other.scheduled_dispatch_start_full_date_fract;
|
|
|
|
this->scheduled_dispatch_last_dispatch = other.scheduled_dispatch_last_dispatch;
|
|
|
|
this->scheduled_dispatch_max_delay = other.scheduled_dispatch_max_delay;
|
|
|
|
}
|
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the vector of all scheduled dispatch slot
|
|
|
|
* @return first scheduled dispatch
|
|
|
|
*/
|
|
|
|
inline const std::vector<uint32> &GetScheduledDispatch() const { return this->scheduled_dispatch; }
|
|
|
|
|
|
|
|
void SetScheduledDispatch(std::vector<uint32> dispatch_list);
|
|
|
|
void AddScheduledDispatch(uint32 offset);
|
|
|
|
void RemoveScheduledDispatch(uint32 offset);
|
|
|
|
void ClearScheduledDispatch() { this->scheduled_dispatch.clear(); }
|
2022-01-14 22:53:55 +00:00
|
|
|
bool UpdateScheduledDispatchToDate(DateTicksScaled now);
|
2022-01-15 00:21:31 +00:00
|
|
|
void UpdateScheduledDispatch(const Vehicle *v);
|
2022-01-13 19:46:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scheduled dispatch duration, in scaled tick
|
|
|
|
* @param duration New duration
|
|
|
|
*/
|
|
|
|
inline void SetScheduledDispatchDuration(uint32 duration) { this->scheduled_dispatch_duration = duration; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scheduled dispatch duration, in scaled tick
|
|
|
|
* @return scheduled dispatch duration
|
|
|
|
*/
|
|
|
|
inline uint32 GetScheduledDispatchDuration() const { return this->scheduled_dispatch_duration; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scheduled dispatch start
|
|
|
|
* @param start New start date
|
|
|
|
* @param fract New start full date fraction, see \c CmdScheduledDispatchSetStartDate
|
|
|
|
*/
|
|
|
|
inline void SetScheduledDispatchStartDate(Date start_date, uint16 start_full_date_fract)
|
|
|
|
{
|
|
|
|
this->scheduled_dispatch_start_date = start_date;
|
|
|
|
this->scheduled_dispatch_start_full_date_fract = start_full_date_fract;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scheduled dispatch start date part
|
|
|
|
* @return scheduled dispatch start date part
|
|
|
|
*/
|
|
|
|
inline Date GetScheduledDispatchStartDatePart() const { return this->scheduled_dispatch_start_date; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scheduled dispatch start date fract part
|
|
|
|
* @return scheduled dispatch start date fract part
|
|
|
|
*/
|
|
|
|
inline uint16 GetScheduledDispatchStartDateFractPart() const { return this->scheduled_dispatch_start_full_date_fract; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scheduled dispatch start date, in absolute scaled tick
|
|
|
|
* @return scheduled dispatch start date
|
|
|
|
*/
|
|
|
|
inline DateTicksScaled GetScheduledDispatchStartTick() const { return SchdispatchConvertToScaledTick(this->scheduled_dispatch_start_date, this->scheduled_dispatch_start_full_date_fract); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the scheduled dispatch setting is valid
|
|
|
|
* @return scheduled dispatch start date fraction
|
|
|
|
*/
|
|
|
|
inline bool IsScheduledDispatchValid() const { return this->scheduled_dispatch_start_date >= 0 && this->scheduled_dispatch_duration > 0; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scheduled dispatch last dispatch offset, in scaled tick
|
|
|
|
* @param duration New last dispatch offset
|
|
|
|
*/
|
|
|
|
inline void SetScheduledDispatchLastDispatch(int32 offset) { this->scheduled_dispatch_last_dispatch = offset; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scheduled dispatch last dispatch offset, in scaled tick
|
|
|
|
* @return scheduled dispatch last dispatch
|
|
|
|
*/
|
|
|
|
inline int32 GetScheduledDispatchLastDispatch() const { return this->scheduled_dispatch_last_dispatch; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scheduled dispatch maximum allowed delay, in scaled tick
|
|
|
|
* @param delay New maximum allow delay
|
|
|
|
*/
|
|
|
|
inline void SetScheduledDispatchDelay(int32 delay) { this->scheduled_dispatch_max_delay = delay; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scheduled dispatch maximum alowed delay, in scaled tick
|
|
|
|
* @return scheduled dispatch last dispatch
|
|
|
|
*/
|
|
|
|
inline int32 GetScheduledDispatchDelay() const { return this->scheduled_dispatch_max_delay; }
|
2022-01-14 22:53:55 +00:00
|
|
|
|
|
|
|
inline void BorrowSchedule(DispatchSchedule &other)
|
|
|
|
{
|
|
|
|
this->CopyBasicFields(other);
|
|
|
|
this->scheduled_dispatch = std::move(other.scheduled_dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ReturnSchedule(DispatchSchedule &other)
|
|
|
|
{
|
|
|
|
other.scheduled_dispatch = std::move(this->scheduled_dispatch);
|
|
|
|
}
|
2022-01-13 19:46:43 +00:00
|
|
|
};
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Shared order list linking together the linked list of orders and the list
|
2009-01-03 13:52:06 +00:00
|
|
|
* of vehicles sharing this order list.
|
|
|
|
*/
|
2009-05-22 15:13:50 +00:00
|
|
|
struct OrderList : OrderListPool::PoolItem<&_orderlist_pool> {
|
2009-01-03 13:52:06 +00:00
|
|
|
private:
|
|
|
|
friend void AfterLoadVehicles(bool part_of_load); ///< For instantiating the shared vehicle chain
|
2021-05-31 20:26:44 +00:00
|
|
|
friend SaveLoadTable GetOrderListDescription(); ///< Saving and loading of order lists.
|
2021-11-01 18:33:39 +00:00
|
|
|
friend upstream_sl::SaveLoadTable upstream_sl::GetOrderListDescription(); ///< Saving and loading of order lists.
|
2019-01-19 11:21:04 +00:00
|
|
|
friend void Ptrs_ORDL(); ///< Saving and loading of order lists.
|
2009-01-03 13:52:06 +00:00
|
|
|
|
2013-08-20 21:22:35 +00:00
|
|
|
StationID GetBestLoadableNext(const Vehicle *v, const Order *o1, const Order *o2) const;
|
2019-01-19 11:21:04 +00:00
|
|
|
void ReindexOrderList();
|
2019-02-02 23:30:05 +00:00
|
|
|
Order *GetOrderAtFromList(int index) const;
|
2013-06-09 13:03:48 +00:00
|
|
|
|
2010-12-26 13:25:34 +00:00
|
|
|
Order *first; ///< First order of the order list.
|
2019-01-19 11:21:04 +00:00
|
|
|
std::vector<Order *> order_index; ///< NOSAVE: Vector index of order list.
|
2010-12-26 13:25:34 +00:00
|
|
|
VehicleOrderID num_manual_orders; ///< NOSAVE: How many manually added orders are there in the list.
|
|
|
|
uint num_vehicles; ///< NOSAVE: Number of vehicles that share this order list.
|
|
|
|
Vehicle *first_shared; ///< NOSAVE: pointer to the first vehicle in the shared order chain.
|
2009-01-03 13:52:06 +00:00
|
|
|
|
2014-05-01 14:49:16 +00:00
|
|
|
Ticks timetable_duration; ///< NOSAVE: Total timetabled duration of the order list.
|
|
|
|
Ticks total_duration; ///< NOSAVE: Total (timetabled or not) duration of the order list.
|
2017-12-18 01:26:27 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
std::vector<DispatchSchedule> dispatch_schedules; ///< Scheduled dispatch schedules
|
2009-01-03 13:52:06 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** Default constructor producing an invalid order list. */
|
2009-05-17 16:28:29 +00:00
|
|
|
OrderList(VehicleOrderID num_orders = INVALID_VEH_ORDER_ID)
|
2019-04-11 17:14:13 +00:00
|
|
|
: first(nullptr), num_manual_orders(0), num_vehicles(0), first_shared(nullptr),
|
2022-01-13 19:46:43 +00:00
|
|
|
timetable_duration(0), total_duration(0) { }
|
2009-01-03 13:52:06 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Create an order list with the given order chain for the given vehicle.
|
2009-05-22 15:13:50 +00:00
|
|
|
* @param chain pointer to the first order of the order chain
|
|
|
|
* @param v any vehicle using this orderlist
|
2009-01-03 13:52:06 +00:00
|
|
|
*/
|
2009-05-22 15:13:50 +00:00
|
|
|
OrderList(Order *chain, Vehicle *v) { this->Initialize(chain, v); }
|
2009-01-03 13:52:06 +00:00
|
|
|
|
|
|
|
/** Destructor. Invalidates OrderList for re-usage by the pool. */
|
2009-05-22 15:13:50 +00:00
|
|
|
~OrderList() {}
|
2009-01-03 13:52:06 +00:00
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
void Initialize(Order *chain, Vehicle *v);
|
2009-01-03 13:52:06 +00:00
|
|
|
|
2020-01-03 14:11:33 +00:00
|
|
|
void RecalculateTimetableDuration();
|
|
|
|
|
2009-01-03 13:52:06 +00:00
|
|
|
/**
|
|
|
|
* Get the first order of the order chain.
|
|
|
|
* @return the first order of the chain.
|
|
|
|
*/
|
|
|
|
inline Order *GetFirstOrder() const { return this->first; }
|
|
|
|
|
|
|
|
Order *GetOrderAt(int index) const;
|
|
|
|
|
2017-12-18 01:26:27 +00:00
|
|
|
VehicleOrderID GetIndexOfOrder(const Order *order) const;
|
|
|
|
|
2009-01-03 13:52:06 +00:00
|
|
|
/**
|
|
|
|
* Get the last order of the order chain.
|
|
|
|
* @return the last order of the chain.
|
|
|
|
*/
|
2019-01-19 11:21:04 +00:00
|
|
|
inline Order *GetLastOrder() const { return this->GetOrderAt(this->GetNumOrders() - 1); }
|
2009-01-03 13:52:06 +00:00
|
|
|
|
2013-05-19 14:22:04 +00:00
|
|
|
/**
|
|
|
|
* Get the order after the given one or the first one, if the given one is the
|
|
|
|
* last one.
|
|
|
|
* @param curr Order to find the next one for.
|
|
|
|
* @return Next order.
|
|
|
|
*/
|
2019-04-10 21:07:06 +00:00
|
|
|
inline const Order *GetNext(const Order *curr) const { return (curr->next == nullptr) ? this->GetFirstOrder() : curr->next; }
|
2013-05-19 14:22:04 +00:00
|
|
|
|
2009-01-03 13:52:06 +00:00
|
|
|
/**
|
|
|
|
* Get number of orders in the order list.
|
2010-08-01 19:44:49 +00:00
|
|
|
* @return number of orders in the chain.
|
|
|
|
*/
|
2019-12-18 20:38:04 +00:00
|
|
|
inline VehicleOrderID GetNumOrders() const { return static_cast<VehicleOrderID>(this->order_index.size()); }
|
2009-01-03 13:52:06 +00:00
|
|
|
|
2010-12-26 13:25:34 +00:00
|
|
|
/**
|
|
|
|
* Get number of manually added orders in the order list.
|
|
|
|
* @return number of manual orders in the chain.
|
|
|
|
*/
|
|
|
|
inline VehicleOrderID GetNumManualOrders() const { return this->num_manual_orders; }
|
|
|
|
|
2019-04-11 17:14:13 +00:00
|
|
|
CargoMaskedStationIDStack GetNextStoppingStation(const Vehicle *v, CargoTypes cargo_mask, const Order *first = nullptr, uint hops = 0) const;
|
2018-07-02 18:20:59 +00:00
|
|
|
const Order *GetNextDecisionNode(const Order *next, uint hops, CargoTypes &cargo_mask) const;
|
2013-05-19 14:22:04 +00:00
|
|
|
|
2009-01-03 13:52:06 +00:00
|
|
|
void InsertOrderAt(Order *new_order, int index);
|
|
|
|
void DeleteOrderAt(int index);
|
|
|
|
void MoveOrder(int from, int to);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this a shared order list?
|
|
|
|
* @return whether this order list is shared among multiple vehicles
|
|
|
|
*/
|
|
|
|
inline bool IsShared() const { return this->num_vehicles > 1; };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the first vehicle of this vehicle chain.
|
|
|
|
* @return the first vehicle of the chain.
|
|
|
|
*/
|
|
|
|
inline Vehicle *GetFirstSharedVehicle() const { return this->first_shared; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of vehicles that share this orders list
|
|
|
|
* @return the count of vehicles that use this shared orders list
|
|
|
|
*/
|
2009-01-03 17:28:22 +00:00
|
|
|
inline uint GetNumVehicles() const { return this->num_vehicles; }
|
2009-01-03 13:52:06 +00:00
|
|
|
|
|
|
|
bool IsVehicleInSharedOrdersList(const Vehicle *v) const;
|
|
|
|
int GetPositionInSharedOrderList(const Vehicle *v) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the given vehicle to this shared order list.
|
|
|
|
* @note This is supposed to be called after the vehicle has been inserted
|
|
|
|
* into the shared vehicle chain.
|
|
|
|
* @param v vehicle to add to the list
|
|
|
|
*/
|
|
|
|
inline void AddVehicle(Vehicle *v) { ++this->num_vehicles; }
|
|
|
|
|
|
|
|
void RemoveVehicle(Vehicle *v);
|
|
|
|
|
|
|
|
bool IsCompleteTimetable() const;
|
|
|
|
|
|
|
|
/**
|
2009-11-21 12:43:09 +00:00
|
|
|
* Gets the total duration of the vehicles timetable or INVALID_TICKS is the timetable is not complete.
|
|
|
|
* @return total timetable duration or INVALID_TICKS for incomplete timetables
|
2009-01-03 13:52:06 +00:00
|
|
|
*/
|
2009-11-21 12:43:09 +00:00
|
|
|
inline Ticks GetTimetableTotalDuration() const { return this->IsCompleteTimetable() ? this->timetable_duration : INVALID_TICKS; }
|
2009-01-03 13:52:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the known duration of the vehicles timetable even if the timetable is not complete.
|
|
|
|
* @return known timetable duration
|
|
|
|
*/
|
2009-11-21 12:43:09 +00:00
|
|
|
inline Ticks GetTimetableDurationIncomplete() const { return this->timetable_duration; }
|
2009-01-03 13:52:06 +00:00
|
|
|
|
2014-05-01 14:49:16 +00:00
|
|
|
/**
|
|
|
|
* Gets the known duration of the vehicles orders, timetabled or not.
|
|
|
|
* @return known order duration.
|
|
|
|
*/
|
|
|
|
inline Ticks GetTotalDuration() const { return this->total_duration; }
|
|
|
|
|
2009-01-03 13:52:06 +00:00
|
|
|
/**
|
|
|
|
* Must be called if an order's timetable is changed to update internal book keeping.
|
|
|
|
* @param delta By how many ticks has the timetable duration changed
|
|
|
|
*/
|
2014-05-01 14:49:16 +00:00
|
|
|
void UpdateTimetableDuration(Ticks delta) { this->timetable_duration += delta; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Must be called if an order's timetable is changed to update internal book keeping.
|
|
|
|
* @param delta By how many ticks has the total duration changed
|
|
|
|
*/
|
|
|
|
void UpdateTotalDuration(Ticks delta) { this->total_duration += delta; }
|
2009-01-03 13:52:06 +00:00
|
|
|
|
|
|
|
void FreeChain(bool keep_orderlist = false);
|
|
|
|
|
|
|
|
void DebugCheckSanity() const;
|
2019-05-02 02:05:07 +00:00
|
|
|
bool CheckOrderListIndexing() const;
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
inline std::vector<DispatchSchedule> &GetScheduledDispatchScheduleSet() { return this->dispatch_schedules; }
|
|
|
|
inline const std::vector<DispatchSchedule> &GetScheduledDispatchScheduleSet() const { return this->dispatch_schedules; }
|
2017-12-18 01:26:27 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
inline uint GetScheduledDispatchScheduleCount() const { return (uint)this->dispatch_schedules.size(); }
|
2017-05-29 18:37:08 +00:00
|
|
|
|
2022-01-13 19:46:43 +00:00
|
|
|
inline DispatchSchedule &GetDispatchScheduleByIndex(uint index) { return this->dispatch_schedules[index]; }
|
|
|
|
inline const DispatchSchedule &GetDispatchScheduleByIndex(uint index) const { return this->dispatch_schedules[index]; }
|
2009-01-03 13:52:06 +00:00
|
|
|
};
|
|
|
|
|
2020-06-20 20:27:19 +00:00
|
|
|
void ShiftOrderDates(int interval);
|
|
|
|
|
2010-12-22 10:50:32 +00:00
|
|
|
#endif /* ORDER_BASE_H */
|