implement tunnels
This commit is contained in:
@@ -37,6 +37,12 @@ public:
|
||||
// Register a new belt tile. Any items already on this tile are cleared.
|
||||
void placeBelt(QPoint tile, Rotation direction);
|
||||
|
||||
// Register a new tunnel entry tile.
|
||||
void placeTunnelEntry(QPoint tile, Rotation direction, int maxDistance);
|
||||
|
||||
// Register a new tunnel exit tile.
|
||||
void placeTunnelExit(QPoint tile, Rotation direction);
|
||||
|
||||
// Register a new splitter tile. outputA and outputB are the two exit
|
||||
// directions (e.g. West and East for a default-rotation splitter).
|
||||
// Items entering from any adjacent belt whose direction points into this
|
||||
@@ -87,13 +93,20 @@ public:
|
||||
|
||||
private:
|
||||
void advanceProgress();
|
||||
void advanceTunnelProgress();
|
||||
void moveItemsToNextTile();
|
||||
void moveTunnelItems();
|
||||
void routeSplitterItems();
|
||||
|
||||
// Place item into back slot of an existing belt tile at progress 0.
|
||||
// Returns false if tile is not a belt or is full.
|
||||
bool tryPlaceOnBelt(QPoint tile, Item item);
|
||||
|
||||
// Push an item to any tile type (belt, splitter, tunnel entry, tunnel exit).
|
||||
bool tryPushToTile(QPoint dest, Item item, Rotation fromDir);
|
||||
|
||||
void reevaluateTunnelPairing();
|
||||
|
||||
static std::pair<int, int> key(QPoint tile);
|
||||
static QPoint adjacentTile(QPoint tile, Rotation dir);
|
||||
|
||||
@@ -126,9 +139,41 @@ private:
|
||||
std::optional<BeltItemSlot> frontB; // progress [0, 1]; routed to outputB
|
||||
};
|
||||
|
||||
struct TunnelEntryTile
|
||||
{
|
||||
Rotation direction;
|
||||
int maxDistance;
|
||||
std::optional<BeltItemSlot> front;
|
||||
std::optional<BeltItemSlot> back;
|
||||
};
|
||||
|
||||
struct TunnelExitTile
|
||||
{
|
||||
Rotation direction;
|
||||
std::optional<BeltItemSlot> front;
|
||||
std::optional<BeltItemSlot> back;
|
||||
};
|
||||
|
||||
struct TunnelTransitItem
|
||||
{
|
||||
Item item;
|
||||
double progress;
|
||||
};
|
||||
|
||||
struct TunnelLink
|
||||
{
|
||||
QPoint entryTile;
|
||||
QPoint exitTile;
|
||||
double length;
|
||||
std::vector<TunnelTransitItem> items; // front (highest progress) to back
|
||||
};
|
||||
|
||||
double m_progressPerTick; // beltSpeedTilesPerSecond / kTickRateHz
|
||||
|
||||
std::map<std::pair<int, int>, BeltTile> m_belts;
|
||||
std::map<std::pair<int, int>, SplitterTile> m_splitters;
|
||||
std::map<std::pair<int, int>, BeltTile> m_belts;
|
||||
std::map<std::pair<int, int>, SplitterTile> m_splitters;
|
||||
std::map<std::pair<int, int>, TunnelEntryTile> m_tunnelEntries;
|
||||
std::map<std::pair<int, int>, TunnelExitTile> m_tunnelExits;
|
||||
std::vector<TunnelLink> m_tunnelLinks;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user