Skip to content

Commit 9c5a98f

Browse files
committed
Ignore isolated fish resources for fisheries
1 parent 37e4166 commit 9c5a98f

2 files changed

Lines changed: 70 additions & 2 deletions

File tree

libs/s25main/figures/nofFisher.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@
1717
#include "random/Random.h"
1818
#include "world/GameWorld.h"
1919

20+
namespace {
21+
22+
bool IsUsableFishResource(const GameWorld& world, const MapPoint pt)
23+
{
24+
if(!world.GetNode(pt).resources.has(ResourceType::Fish))
25+
return false;
26+
27+
if(!world.IsWaterPoint(pt))
28+
return false;
29+
30+
for(const MapPoint nb : world.GetNeighbours(pt))
31+
{
32+
if(world.IsWaterPoint(nb))
33+
return true;
34+
}
35+
36+
return false;
37+
}
38+
39+
} // namespace
40+
2041
nofFisher::nofFisher(const MapPoint pos, const unsigned char player, nobUsual* workplace)
2142
: nofFarmhand(Job::Fisher, pos, player, workplace), fishing_dir(Direction::West), successful(false)
2243
{}
@@ -96,7 +117,7 @@ void nofFisher::WorkStarted()
96117
for(Direction dir : helpers::enumRange(RANDOM_ENUM(Direction)))
97118
{
98119
const Resource neighbourRes = world->GetNode(world->GetNeighbour(pos, dir)).resources;
99-
if(neighbourRes.has(ResourceType::Fish))
120+
if(IsUsableFishResource(*world, world->GetNeighbour(pos, dir)))
100121
{
101122
fishing_dir = dir;
102123
fishAmount = neighbourRes.getAmount();
@@ -130,7 +151,7 @@ nofFarmhand::PointQuality nofFisher::GetPointQuality(const MapPoint pt, bool /*
130151
// irgendwo drumherum muss es Fisch geben
131152
for(const MapPoint nb : world->GetNeighbours(pt))
132153
{
133-
if(world->GetNode(nb).resources.has(ResourceType::Fish))
154+
if(IsUsableFishResource(*world, nb))
134155
return PointQuality::Class1;
135156
}
136157

tests/s25Main/integration/testBuilding.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
#include "PointOutput.h"
77
#include "RttrForeachPt.h"
88
#include "buildings/nobBaseMilitary.h"
9+
#include "buildings/nobUsual.h"
10+
#include "factories/BuildingFactory.h"
11+
#include "figures/nofFarmhand.h"
12+
#include "figures/nofFisher.h"
13+
#include "gameTypes/Resource.h"
914
#include "desktops/dskGameInterface.h"
1015
#include "helpers/containerUtils.h"
1116
#include "uiHelper/uiHelpers.hpp"
1217
#include "worldFixtures/CreateEmptyWorld.h"
1318
#include "worldFixtures/WorldFixture.h"
19+
#include "worldFixtures/terrainHelpers.h"
1420
#include "world/GameWorldViewer.h"
1521
#include "nodeObjs/noEnvObject.h"
1622
#include "nodeObjs/noStaticObject.h"
@@ -476,4 +482,45 @@ BOOST_FIXTURE_TEST_CASE(RoadRemovesObjs, EmptyWorldFixture1P)
476482
}
477483
}
478484

485+
486+
BOOST_FIXTURE_TEST_CASE(FisherIgnoresIsolatedFishWater, EmptyWorldFixture1PBiggest)
487+
{
488+
const DescIdx<TerrainDesc> tWater = GetWaterTerrain(world.GetDescription());
489+
490+
const MapPoint fisheryPos = world.MakeMapPoint(world.GetPlayer(0).GetHQPos() - Position(6, 6));
491+
auto* fishery = dynamic_cast<nobUsual*>(
492+
BuildingFactory::CreateBuilding(world, BuildingType::Fishery, fisheryPos, 0, Nation::Romans));
493+
BOOST_TEST_REQUIRE(fishery);
494+
495+
nofFisher fisher(fisheryPos, 0, fishery);
496+
const nofFarmhand& farmhand = fisher;
497+
498+
const MapPoint workPt = world.MakeMapPoint(fisheryPos + Position(4, 0));
499+
const MapPoint fishPt = world.GetNeighbour(workPt, Direction::East);
500+
501+
auto makeWaterPoint = [&](const MapPoint pt) {
502+
MapNode& nwNode = world.GetNodeWriteable(world.GetNeighbour(pt, Direction::NorthWest));
503+
MapNode& neNode = world.GetNodeWriteable(world.GetNeighbour(pt, Direction::NorthEast));
504+
MapNode& curNode = world.GetNodeWriteable(pt);
505+
MapNode& wNode = world.GetNodeWriteable(world.GetNeighbour(pt, Direction::West));
506+
507+
nwNode.t1 = tWater;
508+
nwNode.t2 = tWater;
509+
neNode.t1 = tWater;
510+
curNode.t1 = tWater;
511+
curNode.t2 = tWater;
512+
wNode.t2 = tWater;
513+
};
514+
515+
makeWaterPoint(fishPt);
516+
world.SetResource(fishPt, Resource(ResourceType::Fish, 4));
517+
518+
BOOST_TEST_REQUIRE(static_cast<unsigned>(farmhand.GetPointQuality(workPt))
519+
== static_cast<unsigned>(nofFarmhand::PointQuality::NotPossible));
520+
521+
makeWaterPoint(world.GetNeighbour(fishPt, Direction::East));
522+
523+
BOOST_TEST_REQUIRE(static_cast<unsigned>(farmhand.GetPointQuality(workPt))
524+
== static_cast<unsigned>(nofFarmhand::PointQuality::Class1));
525+
}
479526
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)