Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike/addons/settlers iv mining #1501

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion libs/s25main/figures/nofMiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool nofMiner::StartWorking()
}

// depending on remaining resources, roll if this workcycle needs to be altered or not
if(RANDOM_RAND(world->numPointsRadius(MINER_RADIUS_SETTLERSIV, true) * MINER_MAX_QUANTITY)
if(RANDOM_RAND(world->GetNumPointsInRadius(MINER_RADIUS_SETTLERSIV, true) * MINER_MAX_QUANTITY)
Copy link
Member

Choose a reason for hiding this comment

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

TBH: I actually want to push it to the other direction: Types (classes, structs, ...) start with Uppercase, the rest with lowercase. But well, for consistency right now it makes sense

> sumResAmount)
{
isAlteredWorkcycle = true;
Expand Down
6 changes: 0 additions & 6 deletions libs/s25main/world/MapBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,3 @@ MapPoint MapBase::MakeMapPoint(Position pt) const
{
return ::MakeMapPoint(pt, size_);
}

unsigned MapBase::numPointsRadius(unsigned radius, bool includePt) const {
// For every additional radius we get 6 * curRadius more points. Hence we have 6 * sum(1..radius) points + the
// center point if requested This can be reduced via the gauss formula to the following:
return (radius * radius + radius) * 3u + (includePt ? 1u : 0u);
}
12 changes: 10 additions & 2 deletions libs/s25main/world/MapBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ class MapBase
template<class T_IsValidPt>
bool CheckPointsInRadius(MapPoint pt, unsigned radius, T_IsValidPt&& isValid, bool includePt) const;

/// Returns number of points in the given radius
/// If includePt is true, then the point itself is also counted
constexpr unsigned GetNumPointsInRadius(unsigned radius, bool includePt) const
{
// For every additional radius we get 6 * curRadius more points. Hence we have 6 * sum(1..radius) points + the
// center point if requested This can be reduced via the gauss formula to the following:
return (radius * radius + radius) * 3u + (includePt ? 1u : 0u);
}

/// Return the distance between 2 points on the map (includes wrapping around map borders)
unsigned CalcDistance(const Position& p1, const Position& p2) const;
unsigned CalcDistance(const MapPoint p1, const MapPoint p2) const
Expand All @@ -95,7 +104,6 @@ class MapBase
unsigned CalcMaxDistance() const;
/// Return the direction for ships for going from one point to another
ShipDirection GetShipDir(MapPoint fromPt, MapPoint toPt) const;
unsigned numPointsRadius(unsigned radius, bool includePt) const;
};

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -123,7 +131,7 @@ detail::GetPointsResult_t<T_TransformPt> MapBase::GetPointsInRadius(const MapPoi
result.reserve(T_maxResults);
else if(std::is_same<T_IsValidPt, AlwaysTrue>::value)
{
result.reserve(numPointsRadius(radius, includePt));
result.reserve(GetNumPointsInRadius(radius, includePt));
}
if(includePt)
{
Expand Down