Skip to content

Radius overlay#1946

Draft
morganchristiansson wants to merge 13 commits into
Return-To-The-Roots:masterfrom
morganchristiansson:radius-overlay
Draft

Radius overlay#1946
morganchristiansson wants to merge 13 commits into
Return-To-The-Roots:masterfrom
morganchristiansson:radius-overlay

Conversation

@morganchristiansson

@morganchristiansson morganchristiansson commented Jun 15, 2026

Copy link
Copy Markdown

Add tooltip and overlay for building ranges

image image image image

@Flamefire Flamefire left a comment

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.

Good idea, makes it a bit S4-like.

@Spikeone Should this be an addon too?

Comment thread libs/s25main/gameData/BuildingConsts.h Outdated
Comment thread libs/s25main/gameData/BuildingConsts.h Outdated
constexpr unsigned HUNTER_SEARCH_RADIUS = 19; ///< Hunter searches for animals in a square of this half-side length
constexpr unsigned FARMER_RADIUS = 2; ///< Farmer plants and harvests crops within this radius
constexpr unsigned CHARBURNER_RADIUS = 3; ///< Charburner places and harvests charcoal piles within this radius
constexpr unsigned CATAPULT_RANGE = 12; ///< Catapult attack range

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.

I see a if(distance < 14) check there. So why 12 here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Google said 12. :-( I started with my own numbers.
This is fixed.
image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Also catapult was not available as constant, I extracted it to constant.

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.

Extracting constants is always good. You just have to make sure you actually use them after defining it.

@Spikeone I guess we should move to actually using radius for all jobs, not rectangles.

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.

Probably yes - can check in the original but pretty sure thats it's circular

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.

I see a if(distance < 14) check there. So why 12 here?

Isn't it the same reason our building range is +1? So the target node is included or something like that?

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.

Which building range? if(distance < 14) means the building on the 13th node away can still be hit, so there are 12 nodes in-between. So maybe that is what is meant by google. And maybe the other part you are referring to has a corner case which required that. But would need to check

Comment thread libs/s25main/ingameWindows/iwAction.h Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment thread libs/s25main/world/GameWorldView.cpp Outdated
Comment on lines +768 to +780
// Draw at all 9 toroidal copies (canonical ± 1 map dimension).
// Using all copies guarantees the ring is continuous across the seam
// regardless of viewport position — the renderer clips off-screen pixels.
for(int dw : {-w, 0, w})
{
for(int dh : {-h, 0, h})
{
const MapPoint copyPt = MakeMapPoint(Position(basePt.x + dw, basePt.y + dh), mapSize);
const auto alt = world.GetNode(copyPt).altitude;
const DrawPoint scr = GetNodePos(copyPt) - DrawPoint(0, HEIGHT_FACTOR * alt) - offset;
Window::DrawRectangle(Rect(scr - DrawPoint(2, 2), Extent(5, 5)), BORDER_COLOR);
}
}

@morganchristiansson morganchristiansson Jun 15, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Noone commented on this yet.
The drawn radius was being clipped where map repeats and this is a workaround. Did not find any cleaner way advice appreciated.

Image

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.

That is indeed hard. You can use the GetNodePos overload taking the height as the base point. Then use const Position mapDrawSize = world->GetSize() * Position(TR_W, TR_H); as the offsets

I don't think it gets better than that: You have to draw possibly all copies when the zoom factor is large which it seems is also not yet taken into account. Possibly even that is not enough.
Maybe rather use a (flat_)set to store the radius points and move drawing to DrawGUI where you can check with contains whether to draw the mark

@@ -132,16 +132,14 @@ void nofHunter::HandleDerivedEvent(unsigned /*id*/)
void nofHunter::TryStartHunting()
{
// Find animals in a square around building (actually should be circle, but animals are moving anyway)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Uhm hunters look for animals in a SQUARE?

Should fix to be circle? Kinda out of scope but can include or do separate PR. Cause right now the range outline doesn't match what game uses.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Created PR #1948 to make Hunters use circle instead of square.

@Flamefire

Flamefire commented Jun 16, 2026

Copy link
Copy Markdown
Member

Given #129 was a request for an addon, can you add one and guard the code changing the tooltip and setting the draw-circle by the addon setting? We usually keep the default behavior to be the same as in S2

BTW: Unless you just applied a suggested code snippet directly please don't resolve conversations as then we miss your reply

@Spikeone

Copy link
Copy Markdown
Member

@Spikeone Should this be an addon too?

Yes, I think so

@morganchristiansson

morganchristiansson commented Jun 16, 2026

Copy link
Copy Markdown
Author

I think it should be player toggleable during game, and per player in multiplayer.
It's just a fancy measuring tool so I think this should be fine.
Also I think the list of addons is getting large.

But most ppl said it should be addon so maybe best to proceed with that.

But should tooltip also be guarded by addon?

BTW: Unless you just applied a suggested code snippet directly please don't resolve conversations as then we miss your reply

Ok I will leave resolving to original commenter from now on. I just did it to track what I resolved.

@stefson

stefson commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

nice idea, but please make it an optional addon.

also, the red isn't very much in the style of S2,

@morganchristiansson

morganchristiansson commented Jun 16, 2026

Copy link
Copy Markdown
Author

nice idea, but please make it an optional addon.

it is now an addon

also, the red isn't very much in the style of S2,

not sure what graphics to use, please provide/suggest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants