|
5 | 5 | #include "nofForester.h" |
6 | 6 |
|
7 | 7 | #include "GameInterface.h" |
| 8 | +#include "buildings/noBaseBuilding.h" |
8 | 9 | #include "GamePlayer.h" |
9 | 10 | #include "Loader.h" |
10 | 11 | #include "SoundManager.h" |
|
15 | 16 | #include "nodeObjs/noTree.h" |
16 | 17 | #include <boost/container/static_vector.hpp> |
17 | 18 |
|
| 19 | +namespace { |
| 20 | +bool IsPotentialNewFieldForOwnFarm(GameWorld& world, const MapPoint pt, const unsigned char player) |
| 21 | +{ |
| 22 | + constexpr unsigned FARM_FIELD_RADIUS = 2; |
| 23 | + |
| 24 | + for(const auto dir : helpers::EnumRange<Direction>{}) |
| 25 | + { |
| 26 | + if(world.GetPointRoad(pt, dir) != PointRoad::None) |
| 27 | + return false; |
| 28 | + } |
| 29 | + |
| 30 | + if(!world.IsOfTerrain(pt, [](const auto& desc) { return desc.IsVital(); })) |
| 31 | + return false; |
| 32 | + |
| 33 | + const NodalObjectType noType = world.GetNO(pt)->GetType(); |
| 34 | + if(noType != NodalObjectType::Environment && noType != NodalObjectType::Nothing) |
| 35 | + return false; |
| 36 | + |
| 37 | + for(const MapPoint nb : world.GetNeighbours(pt)) |
| 38 | + { |
| 39 | + const NodalObjectType nbType = world.GetNO(nb)->GetType(); |
| 40 | + if(nbType == NodalObjectType::Grainfield || nbType == NodalObjectType::Grapefield |
| 41 | + || nbType == NodalObjectType::Building || nbType == NodalObjectType::Buildingsite) |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + return world.CheckPointsInRadius( |
| 46 | + pt, FARM_FIELD_RADIUS, |
| 47 | + [&world, player](const MapPoint farmPt, unsigned) { |
| 48 | + if(world.GetNO(farmPt)->GetType() != NodalObjectType::Building) |
| 49 | + return false; |
| 50 | + |
| 51 | + const auto* building = world.GetSpecObj<noBaseBuilding>(farmPt); |
| 52 | + return building && building->GetPlayer() == player && building->GetBuildingType() == BuildingType::Farm; |
| 53 | + }, |
| 54 | + false); |
| 55 | +} |
| 56 | +} // namespace |
| 57 | + |
18 | 58 | nofForester::nofForester(const MapPoint pos, const unsigned char player, nobUsual* workplace) |
19 | 59 | : nofFarmhand(Job::Forester, pos, player, workplace) |
20 | 60 | {} |
@@ -110,6 +150,10 @@ nofFarmhand::PointQuality nofForester::GetPointQuality(const MapPoint pt, bool / |
110 | 150 | return PointQuality::NotPossible; |
111 | 151 | } |
112 | 152 |
|
| 153 | + // Avoid occupying spots that an own farm could use for a new grain field. |
| 154 | + if(IsPotentialNewFieldForOwnFarm(*world, pt, player)) |
| 155 | + return PointQuality::NotPossible; |
| 156 | + |
113 | 157 | // Terrain untersuchen |
114 | 158 | if(world->IsOfTerrain(pt, [](const auto& desc) { return desc.IsVital(); })) |
115 | 159 | return PointQuality::Class1; |
|
0 commit comments