Initial implementation of trace restrict slots
This commit is contained in:
@@ -14,12 +14,15 @@
|
||||
#include "core/bitmath_func.hpp"
|
||||
#include "core/enum_type.hpp"
|
||||
#include "core/pool_type.hpp"
|
||||
#include "core/container_func.hpp"
|
||||
#include "command_func.h"
|
||||
#include "rail_map.h"
|
||||
#include "tile_type.h"
|
||||
#include "group_type.h"
|
||||
#include "vehicle_type.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
struct Train;
|
||||
|
||||
@@ -35,6 +38,19 @@ typedef Pool<TraceRestrictProgram, TraceRestrictProgramID, 16, 256000> TraceRest
|
||||
/** The actual pool for trace restrict nodes. */
|
||||
extern TraceRestrictProgramPool _tracerestrictprogram_pool;
|
||||
|
||||
/** Slot pool ID type. */
|
||||
typedef uint16 TraceRestrictSlotID;
|
||||
struct TraceRestrictSlot;
|
||||
|
||||
/** Type of the pool for trace restrict slots. */
|
||||
typedef Pool<TraceRestrictSlot, TraceRestrictSlotID, 16, 0xFFF0> TraceRestrictSlotPool;
|
||||
/** The actual pool for trace restrict nodes. */
|
||||
extern TraceRestrictSlotPool _tracerestrictslot_pool;
|
||||
|
||||
static const TraceRestrictSlotID NEW_TRACE_RESTRICT_SLOT_ID = 0xFFFD; // for GUI use only
|
||||
static const TraceRestrictSlotID ALL_TRAINS_TRACE_RESTRICT_SLOT_ID = 0xFFFE; // for GUI use only
|
||||
static const TraceRestrictSlotID INVALID_TRACE_RESTRICT_SLOT_ID = 0xFFFF;
|
||||
|
||||
extern const uint16 _tracerestrict_pathfinder_penalty_preset_values[];
|
||||
|
||||
#define FOR_ALL_TRACE_RESTRICT_PROGRAMS_FROM(var, start) FOR_ALL_ITEMS_FROM(TraceRestrictProgram, tr_index, var, start)
|
||||
@@ -101,6 +117,7 @@ enum TraceRestrictItemType {
|
||||
TRIT_RESERVE_THROUGH = 3, ///< Reserve through PBS signal
|
||||
TRIT_LONG_RESERVE = 4, ///< Long reserve PBS signal
|
||||
TRIT_WAIT_AT_PBS = 5, ///< Wait at PBS signal
|
||||
TRIT_SLOT = 6, ///< Slot operation
|
||||
|
||||
TRIT_COND_BEGIN = 8, ///< Start of conditional item types, note that this has the same value as TRIT_COND_ENDIF
|
||||
TRIT_COND_ENDIF = 8, ///< This is an endif block or an else block
|
||||
@@ -203,6 +220,16 @@ enum TraceRestrictPathfinderPenaltyAuxField {
|
||||
/* space up to 3 */
|
||||
};
|
||||
|
||||
/**
|
||||
* TraceRestrictItem repurposed condition operator field, for slot operation type actions
|
||||
*/
|
||||
enum TraceRestrictSlotCondOpField {
|
||||
TRSCOF_ACQUIRE_WAIT = 0, ///< acquire a slot, or wait at the current signal
|
||||
TRSCOF_ACQUIRE_TRY = 1, ///< try to acquire a slot, or carry on otherwise
|
||||
TRSCOF_RELEASE = 2, ///< release a slot
|
||||
/* space up to 8 */
|
||||
};
|
||||
|
||||
/**
|
||||
* TraceRestrictItem pathfinder penalty preset index
|
||||
* This may not be shortened, only lengthened, as preset indexes are stored in save games
|
||||
@@ -233,9 +260,20 @@ enum TraceRestrictProgramActionsUsedFlags {
|
||||
TRPAUF_RESERVE_THROUGH = 1 << 1, ///< Reserve through action is present
|
||||
TRPAUF_LONG_RESERVE = 1 << 2, ///< Long reserve action is present
|
||||
TRPAUF_WAIT_AT_PBS = 1 << 3, ///< Wait at PBS signal action is present
|
||||
TRPAUF_SLOT_ACQUIRE = 1 << 4, ///< Slot acquire action is present
|
||||
TRPAUF_SLOT_RELEASE = 1 << 5, ///< Slot release action is present
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(TraceRestrictProgramActionsUsedFlags)
|
||||
|
||||
/**
|
||||
* Enumeration for TraceRestrictProgram::actions_used_flags
|
||||
*/
|
||||
enum TraceRestrictProgramInputSlotPermissions {
|
||||
TRPISP_ACQUIRE = 1 << 0, ///< Slot acquire is permitted
|
||||
TRPISP_RELEASE = 1 << 1, ///< Slot release is permitted
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(TraceRestrictProgramInputSlotPermissions)
|
||||
|
||||
/**
|
||||
* Execution input of a TraceRestrictProgram
|
||||
*/
|
||||
@@ -246,9 +284,11 @@ struct TraceRestrictProgramInput {
|
||||
Trackdir trackdir; ///< Track direction on tile of restrict signal, for direction testing
|
||||
PreviousSignalProc *previous_signal_callback; ///< Callback to retrieve tile and direction of previous signal, may be NULL
|
||||
const void *previous_signal_ptr; ///< Opaque pointer suitable to be passed to previous_signal_callback
|
||||
TraceRestrictProgramInputSlotPermissions permitted_slot_operations; ///< Permitted slot operations
|
||||
|
||||
TraceRestrictProgramInput(TileIndex tile_, Trackdir trackdir_, PreviousSignalProc *previous_signal_callback_, const void *previous_signal_ptr_)
|
||||
: tile(tile_), trackdir(trackdir_), previous_signal_callback(previous_signal_callback_), previous_signal_ptr(previous_signal_ptr_) { }
|
||||
: tile(tile_), trackdir(trackdir_), previous_signal_callback(previous_signal_callback_), previous_signal_ptr(previous_signal_ptr_),
|
||||
permitted_slot_operations(static_cast<TraceRestrictProgramInputSlotPermissions>(0)) { }
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -444,6 +484,7 @@ enum TraceRestrictValueType {
|
||||
TRVT_POWER_WEIGHT_RATIO = 16,///< takes a power / weight ratio, * 100
|
||||
TRVT_FORCE_WEIGHT_RATIO = 17,///< takes a force / weight ratio, * 100
|
||||
TRVT_WAIT_AT_PBS = 18,///< takes a value 0 = wait at PBS signal, 1 = cancel wait at PBS signal
|
||||
TRVT_SLOT_INDEX = 19,///< takes a TraceRestrictSlotID
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -562,6 +603,8 @@ static inline TraceRestrictTypePropertySet GetTraceRestrictTypeProperties(TraceR
|
||||
out.value_type = TRVT_LONG_RESERVE;
|
||||
} else if (GetTraceRestrictType(item) == TRIT_WAIT_AT_PBS) {
|
||||
out.value_type = TRVT_WAIT_AT_PBS;
|
||||
} else if (GetTraceRestrictType(item) == TRIT_SLOT) {
|
||||
out.value_type = TRVT_SLOT_INDEX;
|
||||
} else {
|
||||
out.value_type = TRVT_NONE;
|
||||
}
|
||||
@@ -660,5 +703,54 @@ void ShowTraceRestrictProgramWindow(TileIndex tile, Track track);
|
||||
|
||||
void TraceRestrictRemoveDestinationID(TraceRestrictOrderCondAuxField type, uint16 index);
|
||||
void TraceRestrictRemoveGroupID(GroupID index);
|
||||
void TraceRestrictRemoveSlotID(TraceRestrictSlotID index);
|
||||
|
||||
void TraceRestrictRemoveVehicleFromAllSlots(VehicleID id);
|
||||
void TraceRestrictTransferVehicleOccupantInAllSlots(VehicleID from, VehicleID to);
|
||||
void TraceRestrictGetVehicleSlots(VehicleID id, std::vector<TraceRestrictSlotID> &out);
|
||||
|
||||
static const uint MAX_LENGTH_TRACE_RESTRICT_SLOT_NAME_CHARS = 128; ///< The maximum length of a slot name in characters including '\0'
|
||||
|
||||
/**
|
||||
* Slot type, used for slot operations
|
||||
*/
|
||||
struct TraceRestrictSlot : TraceRestrictSlotPool::PoolItem<&_tracerestrictslot_pool> {
|
||||
std::vector<VehicleID> occupants;
|
||||
uint32 max_occupancy = 1;
|
||||
std::string name;
|
||||
OwnerByte owner;
|
||||
|
||||
static void RebuildVehicleIndex();
|
||||
static void PreCleanPool();
|
||||
|
||||
TraceRestrictSlot(CompanyID owner = INVALID_COMPANY)
|
||||
{
|
||||
this->owner = owner;
|
||||
}
|
||||
|
||||
~TraceRestrictSlot()
|
||||
{
|
||||
if (!CleaningPool()) this->Clear();
|
||||
}
|
||||
|
||||
/** Test whether vehicle ID is already an occupant */
|
||||
bool IsOccupant(VehicleID id) const {
|
||||
for (size_t i = 0; i < occupants.size(); i++) {
|
||||
if (occupants[i] == id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Occupy(VehicleID id, bool force = false);
|
||||
void Vacate(VehicleID id);
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
void DeIndex(VehicleID id);
|
||||
};
|
||||
|
||||
|
||||
#define FOR_ALL_TRACE_RESTRICT_SLOTS_FROM(var, start) FOR_ALL_ITEMS_FROM(TraceRestrictSlot, slot_index, var, start)
|
||||
#define FOR_ALL_TRACE_RESTRICT_SLOTS(var) FOR_ALL_TRACE_RESTRICT_SLOTS_FROM(var, 0)
|
||||
|
||||
#endif /* TRACERESTRICT_H */
|
||||
|
Reference in New Issue
Block a user