Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions libs/s25main/figures/nofMiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,32 @@ helpers::OptionalEnum<GoodType> nofMiner::ProduceWare()

bool nofMiner::AreWaresAvailable() const
{
return nofWorkman::AreWaresAvailable() && FindPointWithResource(GetRequiredResType()).isValid();
return nofWorkman::AreWaresAvailable()
&& (CanMineWithoutResource() || FindPointWithResource(GetRequiredResType()).isValid());
}

bool nofMiner::StartWorking()
{
MapPoint resPt = FindPointWithResource(GetRequiredResType());
if(!resPt.isValid())
return false;
const GlobalGameSettings& settings = world->GetGGS();
bool inexhaustibleRes = settings.isEnabled(AddonId::INEXHAUSTIBLE_MINES)
|| (workplace->GetBuildingType() == BuildingType::GraniteMine
&& settings.isEnabled(AddonId::INEXHAUSTIBLE_GRANITEMINES));
if(!inexhaustibleRes)
world->ReduceResource(resPt);
const bool canMineWithoutResource = CanMineWithoutResource();
const bool inexhaustibleRes = settings.isEnabled(AddonId::INEXHAUSTIBLE_MINES) || canMineWithoutResource;
if(!canMineWithoutResource)
{
MapPoint resPt = FindPointWithResource(GetRequiredResType());
if(!resPt.isValid())
return false;
if(!inexhaustibleRes)
world->ReduceResource(resPt);
Comment thread
DevOpsOfChaos marked this conversation as resolved.
}
return nofWorkman::StartWorking();
}

bool nofMiner::CanMineWithoutResource() const
{
return workplace->GetBuildingType() == BuildingType::GraniteMine
&& world->GetGGS().isEnabled(AddonId::INEXHAUSTIBLE_GRANITEMINES);
}

ResourceType nofMiner::GetRequiredResType() const
{
switch(workplace->GetBuildingType())
Expand Down
1 change: 1 addition & 0 deletions libs/s25main/figures/nofMiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class nofMiner : public nofWorkman
bool AreWaresAvailable() const override;
bool StartWorking() override;
ResourceType GetRequiredResType() const;
bool CanMineWithoutResource() const;

public:
nofMiner(MapPoint pos, unsigned char player, nobUsual* workplace);
Expand Down
42 changes: 42 additions & 0 deletions tests/s25Main/integration/testProduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,46 @@ BOOST_FIXTURE_TEST_CASE(MetalWorkerOrders, WorldWithGCExecution1P)
RTTR_EXEC_TILL(1300, mw->is_working);
}

BOOST_FIXTURE_TEST_CASE(GraniteMineWithoutResourcesNeedsAddon, WorldWithGCExecution1P)
{
GoodsAndPeopleCounts inv;
inv[GoodType::Fish] = 10;
inv[GoodType::PickAxe] = 1;
inv[Job::Miner] = 1;
world.GetSpecObj<nobBaseWarehouse>(hqPos)->AddToInventory(inv, true);

MapPoint minePos = hqPos + MapPoint(2, 0);
const auto* mine = static_cast<nobUsual*>(
BuildingFactory::CreateBuilding(world, BuildingType::GraniteMine, minePos, curPlayer, Nation::Romans));
this->BuildRoad(world.GetNeighbour(minePos, Direction::SouthEast), false,
std::vector<Direction>(2, Direction::West));

const Inventory& curInventory = world.GetPlayer(curPlayer).GetInventory();
const unsigned initialStones = curInventory[GoodType::Stones];
RTTR_EXEC_TILL(500, mine->HasWorker());
RTTR_SKIP_GFS(2000);

BOOST_TEST(curInventory[GoodType::Stones] == initialStones);
}

BOOST_FIXTURE_TEST_CASE(InexhaustibleGraniteMineWorksWithoutResources, WorldWithGCExecution1P)
{
ggs.setSelection(AddonId::INEXHAUSTIBLE_GRANITEMINES, 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 2 tests have the same setup, which I'd like to keep in sync and clearly the same.

I see 2 ways:

  1. Move the common code to a fixture
  2. Change the setting of INEXHAUSTIBLE_GRANITEMINES in the test

I'm concerned by a (purely theoretical though) difference:

-    RTTR_EXEC_TILL(500, mine->HasWorker());
-    RTTR_SKIP_GFS(2000);
+    RTTR_EXEC_TILL(3000, curInventory[GoodType::Stones] > initialStones);

In 2nd case

  • You don't wait for the worker to arrive
  • Time is longer. So it could (theoretically) be possible that after 2501 GFs a stone would arrive making the test wrongly pass

The name GraniteMineWithoutResourcesNeedsAddon would be a great fit for the 2nd approach: Addon disable: No stone, enabling it yields stone being produced.

Currently not sure if the logic of when the worker starts (trying) to work again works with that though in which case the fixture needs to be used.

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

70/30 AI i' use RTTR since 2024. now i'am more familiar with programming due to ai,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will check on that later.


GoodsAndPeopleCounts inv;
inv[GoodType::Fish] = 10;
inv[GoodType::PickAxe] = 1;
inv[Job::Miner] = 1;
world.GetSpecObj<nobBaseWarehouse>(hqPos)->AddToInventory(inv, true);

MapPoint minePos = hqPos + MapPoint(2, 0);
BuildingFactory::CreateBuilding(world, BuildingType::GraniteMine, minePos, curPlayer, Nation::Romans);
this->BuildRoad(world.GetNeighbour(minePos, Direction::SouthEast), false,
std::vector<Direction>(2, Direction::West));

const Inventory& curInventory = world.GetPlayer(curPlayer).GetInventory();
const unsigned initialStones = curInventory[GoodType::Stones];
RTTR_EXEC_TILL(3000, curInventory[GoodType::Stones] > initialStones);
}

BOOST_AUTO_TEST_SUITE_END()
Loading