Skip to content

Commit ea2ee5f

Browse files
committed
Fix inexhaustible granite mine production
1 parent 37e4166 commit ea2ee5f

3 files changed

Lines changed: 61 additions & 9 deletions

File tree

libs/s25main/figures/nofMiner.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,32 @@ helpers::OptionalEnum<GoodType> nofMiner::ProduceWare()
7171

7272
bool nofMiner::AreWaresAvailable() const
7373
{
74-
return nofWorkman::AreWaresAvailable() && FindPointWithResource(GetRequiredResType()).isValid();
74+
return nofWorkman::AreWaresAvailable()
75+
&& (CanMineWithoutResource() || FindPointWithResource(GetRequiredResType()).isValid());
7576
}
7677

7778
bool nofMiner::StartWorking()
7879
{
79-
MapPoint resPt = FindPointWithResource(GetRequiredResType());
80-
if(!resPt.isValid())
81-
return false;
8280
const GlobalGameSettings& settings = world->GetGGS();
83-
bool inexhaustibleRes = settings.isEnabled(AddonId::INEXHAUSTIBLE_MINES)
84-
|| (workplace->GetBuildingType() == BuildingType::GraniteMine
85-
&& settings.isEnabled(AddonId::INEXHAUSTIBLE_GRANITEMINES));
86-
if(!inexhaustibleRes)
87-
world->ReduceResource(resPt);
81+
const bool canMineWithoutResource = CanMineWithoutResource();
82+
const bool inexhaustibleRes = settings.isEnabled(AddonId::INEXHAUSTIBLE_MINES) || canMineWithoutResource;
83+
if(!canMineWithoutResource)
84+
{
85+
MapPoint resPt = FindPointWithResource(GetRequiredResType());
86+
if(!resPt.isValid())
87+
return false;
88+
if(!inexhaustibleRes)
89+
world->ReduceResource(resPt);
90+
}
8891
return nofWorkman::StartWorking();
8992
}
9093

94+
bool nofMiner::CanMineWithoutResource() const
95+
{
96+
return workplace->GetBuildingType() == BuildingType::GraniteMine
97+
&& world->GetGGS().isEnabled(AddonId::INEXHAUSTIBLE_GRANITEMINES);
98+
}
99+
91100
ResourceType nofMiner::GetRequiredResType() const
92101
{
93102
switch(workplace->GetBuildingType())

libs/s25main/figures/nofMiner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class nofMiner : public nofWorkman
2323
bool AreWaresAvailable() const override;
2424
bool StartWorking() override;
2525
ResourceType GetRequiredResType() const;
26+
bool CanMineWithoutResource() const;
2627

2728
public:
2829
nofMiner(MapPoint pos, unsigned char player, nobUsual* workplace);

tests/s25Main/integration/testProduction.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,46 @@ BOOST_FIXTURE_TEST_CASE(MetalWorkerOrders, WorldWithGCExecution1P)
102102
RTTR_EXEC_TILL(1300, mw->is_working);
103103
}
104104

105+
BOOST_FIXTURE_TEST_CASE(GraniteMineWithoutResourcesNeedsAddon, WorldWithGCExecution1P)
106+
{
107+
GoodsAndPeopleCounts inv;
108+
inv[GoodType::Fish] = 10;
109+
inv[GoodType::PickAxe] = 1;
110+
inv[Job::Miner] = 1;
111+
world.GetSpecObj<nobBaseWarehouse>(hqPos)->AddToInventory(inv, true);
112+
113+
MapPoint minePos = hqPos + MapPoint(2, 0);
114+
const auto* mine = static_cast<nobUsual*>(
115+
BuildingFactory::CreateBuilding(world, BuildingType::GraniteMine, minePos, curPlayer, Nation::Romans));
116+
this->BuildRoad(world.GetNeighbour(minePos, Direction::SouthEast), false,
117+
std::vector<Direction>(2, Direction::West));
118+
119+
const Inventory& curInventory = world.GetPlayer(curPlayer).GetInventory();
120+
const unsigned initialStones = curInventory[GoodType::Stones];
121+
RTTR_EXEC_TILL(500, mine->HasWorker());
122+
RTTR_SKIP_GFS(2000);
123+
124+
BOOST_TEST(curInventory[GoodType::Stones] == initialStones);
125+
}
126+
127+
BOOST_FIXTURE_TEST_CASE(InexhaustibleGraniteMineWorksWithoutResources, WorldWithGCExecution1P)
128+
{
129+
ggs.setSelection(AddonId::INEXHAUSTIBLE_GRANITEMINES, 1);
130+
131+
GoodsAndPeopleCounts inv;
132+
inv[GoodType::Fish] = 10;
133+
inv[GoodType::PickAxe] = 1;
134+
inv[Job::Miner] = 1;
135+
world.GetSpecObj<nobBaseWarehouse>(hqPos)->AddToInventory(inv, true);
136+
137+
MapPoint minePos = hqPos + MapPoint(2, 0);
138+
BuildingFactory::CreateBuilding(world, BuildingType::GraniteMine, minePos, curPlayer, Nation::Romans);
139+
this->BuildRoad(world.GetNeighbour(minePos, Direction::SouthEast), false,
140+
std::vector<Direction>(2, Direction::West));
141+
142+
const Inventory& curInventory = world.GetPlayer(curPlayer).GetInventory();
143+
const unsigned initialStones = curInventory[GoodType::Stones];
144+
RTTR_EXEC_TILL(3000, curInventory[GoodType::Stones] > initialStones);
145+
}
146+
105147
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)