Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
61 changes: 18 additions & 43 deletions libs/s25main/ai/aijh/AIPlayerJH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1965,51 +1965,26 @@ bool AIPlayerJH::HuntablesinRange(const MapPoint pt, unsigned min)
// check first if no other hunter(or hunter buildingsite) is nearby
if(aii.isBuildingNearby(BuildingType::Hunter, pt, 14))
return false;
unsigned maxrange = 25;
unsigned short fx, fy, lx, ly;
const unsigned short SQUARE_SIZE = 19;
unsigned huntablecount = 0;
if(pt.x > SQUARE_SIZE)
fx = pt.x - SQUARE_SIZE;
else
fx = 0;
if(pt.y > SQUARE_SIZE)
fy = pt.y - SQUARE_SIZE;
else
fy = 0;
if(pt.x + SQUARE_SIZE < gwb.GetWidth())
lx = pt.x + SQUARE_SIZE;
else
lx = gwb.GetWidth() - 1;
if(pt.y + SQUARE_SIZE < gwb.GetHeight())
ly = pt.y + SQUARE_SIZE;
else
ly = gwb.GetHeight() - 1;
// Durchgehen und nach Tieren suchen
for(MapPoint p2(0, fy); p2.y <= ly; ++p2.y)
{
for(p2.x = fx; p2.x <= lx; ++p2.x)
const unsigned maxrange = 25;

const auto pointToAnimal = [this](const MapPoint pt, unsigned) -> const noAnimal* {
for(const noBase& fig : gwb.GetFigures(pt))
{
// Search for animals
for(const noBase& fig : gwb.GetFigures(p2))
{
if(fig.GetType() == NodalObjectType::Animal)
{
// Ist das Tier überhaupt zum Jagen geeignet?
if(!static_cast<const noAnimal&>(fig).CanHunted())
continue;
// Und komme ich hin?
if(gwb.FindHumanPath(pt, static_cast<const noAnimal&>(fig).GetPos(), maxrange))
// Dann nehmen wir es
{
if(++huntablecount >= min)
return true;
}
}
}
if(fig.GetType() == NodalObjectType::Animal)
return static_cast<const noAnimal*>(&fig);
}
}
return false;
return nullptr;
};

const auto canAnimalBeHunted = [this, pt, maxrange](const noAnimal* const animal) {
Comment thread
morganchristiansson marked this conversation as resolved.
Outdated
return animal && animal->CanHunted()
&& gwb.FindHumanPath(pt, animal->GetPos(), maxrange);
};

const auto available_animals =
gwb.GetPointsInRadius(pt, ANIMAL_RADIUS, pointToAnimal, canAnimalBeHunted, true);

return available_animals.size() >= min;
}

void AIPlayerJH::InitStoreAndMilitarylists()
Expand Down
47 changes: 16 additions & 31 deletions libs/s25main/figures/nofHunter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,39 +131,24 @@ void nofHunter::HandleDerivedEvent(unsigned /*id*/)

void nofHunter::TryStartHunting()
{
// Find animals in a square around building (actually should be circle, but animals are moving anyway)
Comment thread
Flamefire marked this conversation as resolved.
const int SQUARE_SIZE = 19;

// Liste mit den gefundenen Tieren
std::vector<noAnimal*> available_animals;

// Durchgehen und nach Tieren suchen
Position curPos;
for(curPos.y = pos.y - SQUARE_SIZE; curPos.y <= pos.y + SQUARE_SIZE; ++curPos.y)
{
for(curPos.x = pos.x - SQUARE_SIZE; curPos.x <= pos.x + SQUARE_SIZE; ++curPos.x)
// Find animals in a circle around building
const auto pointToAnimal = [world = this->world](const MapPoint pt, unsigned) -> noAnimal* {
for(auto& figure : world->GetFigures(pt))
{
MapPoint curMapPos = world->MakeMapPoint(curPos);

// nach Tieren suchen
for(auto& figure : world->GetFigures(curMapPos))
{
if(figure.GetType() != NodalObjectType::Animal)
continue;
// Ist das Tier überhaupt zum Jagen geeignet?
auto& animal = static_cast<noAnimal&>(figure);
if(!animal.CanHunted())
continue;

// Und komme ich hin?
if(pos == animal.GetPos() || world->FindHumanPath(pos, animal.GetPos(), MAX_HUNTING_DISTANCE))
{
// Dann nehmen wir es
available_animals.push_back(&animal);
}
}
if(figure.GetType() != NodalObjectType::Animal)
continue;
return static_cast<noAnimal*>(&figure);
}
}
return nullptr;
};

const auto canAnimalBeHunted = [pos = this->pos](const noAnimal* const animal) {
return animal && animal->CanHunted()
&& (pos == animal->GetPos() || world->FindHumanPath(pos, animal->GetPos(), MAX_HUNTING_DISTANCE));
};

const auto available_animals =
world->GetPointsInRadius(pos, ANIMAL_RADIUS, pointToAnimal, canAnimalBeHunted, true);

// Gibt es überhaupt ein Tier, das ich jagen kann?
if(!available_animals.empty())
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/figures/nofSkinner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "random/Random.h"
#include "world/GameWorld.h"
#include "nodeObjs/noAnimal.h"
#include "gameData/GameConsts.h"
#include "gameData/JobConsts.h"

using namespace leatheraddon;
Expand Down Expand Up @@ -187,7 +188,6 @@ void nofSkinner::TryStartSkinning()
HandleStateWaiting1();
else
{
const int ANIMAL_RADIUS = 19;
const auto pointToAnimal = [world = this->world](const MapPoint pt, unsigned) -> noAnimal* {
for(auto& figure : world->GetFigures(pt))
{
Expand Down
3 changes: 3 additions & 0 deletions libs/s25main/gameData/GameConsts.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ constexpr auto gfs_to_duration(const unsigned gfs)
/// Reichweite der Bergarbeiter
constexpr unsigned MINER_RADIUS = 2;

/// Suchradius für Tiere (Jäger, Gerber, KI)
Comment thread
morganchristiansson marked this conversation as resolved.
Outdated
constexpr unsigned ANIMAL_RADIUS = 19;

/// Konstante für die Pfadrichtung bei einer Schiffsverbindung
constexpr unsigned char SHIP_DIR = 100;
constexpr unsigned char INVALID_DIR = 0xFF;
Expand Down
Loading