fix bug where buildings could not output directly on splitters
This commit is contained in:
@@ -199,7 +199,7 @@ void BeltSystem::reevaluateTunnelPairing()
|
|||||||
// Port interface
|
// Port interface
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BeltSystem::tryPutItem(QPoint tile, Item item)
|
bool BeltSystem::tryPutItem(QPoint tile, Item item, Rotation fromDir)
|
||||||
{
|
{
|
||||||
const std::map<std::pair<int, int>, BeltTile>::iterator bIt = m_belts.find(key(tile));
|
const std::map<std::pair<int, int>, BeltTile>::iterator bIt = m_belts.find(key(tile));
|
||||||
if (bIt != m_belts.end())
|
if (bIt != m_belts.end())
|
||||||
@@ -207,6 +207,19 @@ bool BeltSystem::tryPutItem(QPoint tile, Item item)
|
|||||||
return tryPlaceOnBelt(tile, item);
|
return tryPlaceOnBelt(tile, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::map<std::pair<int, int>, SplitterTile>::iterator splIt =
|
||||||
|
m_splitters.find(key(tile));
|
||||||
|
if (splIt != m_splitters.end())
|
||||||
|
{
|
||||||
|
if (!splIt->second.back)
|
||||||
|
{
|
||||||
|
splIt->second.back = BeltItemSlot{item, 0.0};
|
||||||
|
splIt->second.backDir = fromDir;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const std::map<std::pair<int, int>, TunnelEntryTile>::iterator teIt =
|
const std::map<std::pair<int, int>, TunnelEntryTile>::iterator teIt =
|
||||||
m_tunnelEntries.find(key(tile));
|
m_tunnelEntries.find(key(tile));
|
||||||
if (teIt != m_tunnelEntries.end())
|
if (teIt != m_tunnelEntries.end())
|
||||||
|
|||||||
@@ -72,8 +72,9 @@ public:
|
|||||||
// port.direction = direction items flow on that tile
|
// port.direction = direction items flow on that tile
|
||||||
//
|
//
|
||||||
// tryPutItem: place item onto tile.
|
// tryPutItem: place item onto tile.
|
||||||
// Returns false if the tile is not a belt, or tile full.
|
// Returns false if the tile is not a belt/splitter, or tile full.
|
||||||
bool tryPutItem(QPoint tile, Item item);
|
// fromDir: travel direction of the item (used for splitter animation).
|
||||||
|
bool tryPutItem(QPoint tile, Item item, Rotation fromDir = Rotation::West);
|
||||||
|
|
||||||
// tryTakeItem: remove and return the leading item from port.tile.
|
// tryTakeItem: remove and return the leading item from port.tile.
|
||||||
// Returns nullopt if tile is not a belt, direction mismatches, or tile empty.
|
// Returns nullopt if tile is not a belt, direction mismatches, or tile empty.
|
||||||
|
|||||||
@@ -713,7 +713,7 @@ void BuildingSystem::tickBeltPush()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const Item item = building.outputBuffer.items.front();
|
const Item item = building.outputBuffer.items.front();
|
||||||
if (m_belts.tryPutItem(outputPort.tile, item))
|
if (m_belts.tryPutItem(outputPort.tile, item, outputPort.direction))
|
||||||
{
|
{
|
||||||
building.outputBuffer.items.erase(building.outputBuffer.items.begin());
|
building.outputBuffer.items.erase(building.outputBuffer.items.begin());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -629,6 +629,24 @@ TEST_CASE("BeltSystem: splitter accepts new items after building pulls from fron
|
|||||||
REQUIRE(bs.peekItem(Port{tileSpl, Rotation::South}).has_value());
|
REQUIRE(bs.peekItem(Port{tileSpl, Rotation::South}).has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("BeltSystem: tryPutItem succeeds directly on a splitter tile", "[belt]")
|
||||||
|
{
|
||||||
|
// Regression: buildings outputting onto a splitter tile were silently dropped
|
||||||
|
// because tryPutItem had no splitter case and returned false.
|
||||||
|
BeltSystem bs(kFastBeltSpeed);
|
||||||
|
|
||||||
|
const QPoint tileSpl(0, 0);
|
||||||
|
bs.placeSplitter(tileSpl, Rotation::North, Rotation::South);
|
||||||
|
|
||||||
|
REQUIRE(bs.tryPutItem(tileSpl, makeItem("iron_ore"), Rotation::East));
|
||||||
|
|
||||||
|
// Item should arrive at one of the output fronts after the splitter ticks through.
|
||||||
|
bs.tick(); // back advances to 0.5, routes to frontA
|
||||||
|
bs.tick(); // frontA reaches 1.0
|
||||||
|
|
||||||
|
REQUIRE(bs.peekItem(Port{tileSpl, Rotation::North}).has_value());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("BeltSystem: splitter alternates between two unregistered outputs (building inputs)", "[belt]")
|
TEST_CASE("BeltSystem: splitter alternates between two unregistered outputs (building inputs)", "[belt]")
|
||||||
{
|
{
|
||||||
BeltSystem bs(kFastBeltSpeed);
|
BeltSystem bs(kFastBeltSpeed);
|
||||||
|
|||||||
Reference in New Issue
Block a user