HomeWildfire Games

Update range queries to account for entity size.

Description

Update range queries to account for entity size.

CCmpRangeManager queries do not take obstruction size into account, meaning they return fewer entities than they should. This particularly affects buildings with ranged attacks, gates, and a few other templates.

This is, unfortunately, a slight performance decrease.

Discovered following Angen's comment here.

Comments by: Angen

Reviewed By: bb

Refs #3381 (not marking it down as 'fixes' and I'm not entirely sure it was the only moving part here).

Differential Revision: https://code.wildfiregames.com/D2759

Event Timeline

Nescio added a subscriber: Nescio.Nov 19 2020, 3:50 PM

Why the severe <Gate/PassRange> reduction?

wraitii added a comment.EditedNov 19 2020, 3:54 PM

Why the severe <Gate/PassRange> reduction?

Beforehand, this was counting 20 meters from the center of the gate. Now it's counting meters from the obstruction circle around the gate, making it somewhat equivalent.

bb added a subscriber: bb.Nov 19 2020, 3:59 PM

To get to the original situation, one should add the size (== half diagonal length) of the gate to the range. As gates tend to be rather long and thus have a large size, the reduction was done to make gates close in roughly the same situations. Now if you take the brit gate: 37x8, you get half diagonal of (just under )19, so in fact the range got slightly bigger there (similar values are true for the other gates).

Nescio added a comment.EditedNov 19 2020, 4:06 PM

If I understand correctly, this is the distance at which the gate opens or closes when friendly units approach or leave.
The distance parallel to the wall is unimportant, what matters is the distance perpendicular to it. The thickest gate (ptol) has a footprint depth of 12, so the gate range reduction ought to be at most half that.

the obstruction circle

[EDIT] What does that mean exactly?
Also, the palisade gate is much smaller than the other gates.

Does this affect auras? If so, shouldn't their ranges be adjusted too?
And territory influence radius?

/ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
47

Not all centres have the same footprint radius.

Does this affect auras? If so, shouldn't their ranges be adjusted too?

They are -> https://code.wildfiregames.com/D2759#131258
That being said, this might actually be a large change for some buildings with small auras, I'm not sure.

And territory influence radius?

Not affected

/ps/trunk/binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
47

This is based on the obstruction radius. That being said, your comment might still be accurate, in which case we might need to tweak on a per-civ basis.

If it does, then this makes structures with local auras significantly more effective, especially temples.

Nescio added a comment.Dec 3 2020, 2:21 PM

If I understand correctly, for units distances are still calculated from the centre, but for structures from the circle around their obstruction.
Now I wonder whether it wouldn't be better to use the footprint radius instead of the obstruction radius. For rectangular structures, the footprint is typically slightly larger than the obstruction size (usually a structure with obstruction of 2a×2b would have a footprint of (2a+2)×(2b+2)). However, circular structures have circular footprints, but square obstructions; as a consequence their obstruction radii are larger than their footprint radii; some examples:

civ, structure:  footprint ; obstruction
brit, tower:        r =  6 ;  7.5² → r =  5.3
brit, house:        r =  6 ; 10²   → r =  7.1
brit, rotary mill:  r =  9 ; 16²   → r = 11.3
brit, civil centre: r = 15 ; 25²   → r = 17.7
brit, fortress:     r = 17 ; 29²   → r = 20.5
gaia, stonehenge:   r = 30 ; 55²   → r = 38.9
/ps/trunk/binaries/data/mods/public/simulation/templates/structures/iber/monument.xml
10

This reduction is too severe: the iber monument is hardly larger than the maur pillar.

If I understand correctly, for units distances are still calculated from the centre, but for structures from the circle around their obstruction.

Actually no, it's calculated from the circle around the obstruction in both case, it's just units have rather small circular clearances, so the math is "exact" and the approximation is far less bad anyways.

Now I wonder whether it wouldn't be better to use the footprint radius instead of the obstruction radius.

I'm not entirely up to date on footprint bs obstruction, but this mostly reads like the obstruction should be made smaller, no?

Nescio added a comment.Dec 3 2020, 2:54 PM

Actually no, it's calculated from the circle around the obstruction in both case, it's just units have rather small circular clearances, so the math is "exact" and the approximation is far less bad anyways.

Where are unit obstruction sizes hidden? Not in the templates.

I'm not entirely up to date on footprint bs obstruction, but this mostly reads like the obstruction should be made smaller, no?

No: the obstruction size is chosen such that the obstruction area is slighly smaller than the footprint area. If the obstruction radius would be reduced to produce an obstruction radius that is slightly smaller than the footprint radius, then the obstruction area will be much smaller.
For example, a circular structure with a footprint radius of 15 has an obstruction size of 25×25; a square footprint for that obstruction would be 27×27. Those three result in areas of 707, 625, and 729, respectively. To make the obstruction radius a bit smaller than the footprint radius, the obstruction size would have to be reduced to 20×20, which is a much smaller area (400).

Where are unit obstruction sizes hidden? Not in the templates.

It's the pathfinder clearance. So it's slightly less than 1 for most units, rams and elephants are 3 iirc.

No: the obstruction size[...] area (400).

Mh, yeah, guess that makes sense. I suppose we might need to support circular obstruction shapes at some point then. Bit annoying, all this...

As for gate pass range, I believe distance to centre is better, since the doors are in the middle, and only that part of the gate is passable, not the entire structure.

I do somewhat agree that build restrictions might be better served by a center-to-center distance calculation. Needs some thinking for A25.