Latest Posts

Topic: Attacking soldiers

xorx
Avatar
Topic Opener
Joined: 2020-12-12, 21:36
Posts: 29
Ranking
Pry about Widelands
Posted at: 2021-01-01, 22:44

Hi,

I've a question about attacking soldiers. Once you chose a military building to attack, a pop-up windows appears where you can chose the soldiers you want to use on that attack (very nice feature, by the way). But many times this pop-up lets me wondering from which military building these soldiers will come from. Is there a smart way to guess that? Is the given list sorted in some way (closest first) or is it completely randomized?

Thanks!


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1954
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2021-01-02, 10:37

This was partly discussed in the merge request (https://code.launchpad.net/~widelands-dev/widelands/choose-attack-soldiers/+merge/367041):

One soldier will always remain in every militarysite. Currently the engine decides which soldier this is, and he will not be shown in the attack box. Ideally, all available soldiers should be shown, grouped by their building, and the player can then choose which soldier(s) remain(s) behind, but this would clutter up the interface too much in my opinion if there are many own militarysites, especially small ones, nearby.

Soldiers from the same building will be shown directly after each other, but there is no way to tell which building which soldier corresponds to, not is this possible without messing up the UI as stated above face-sad.png

I think that the soldiers are searched for by making a hexagonal "circle" with the (fixed) maximum attack radius around the enemy milsite, then iterating every row of the circle left-to-right, all rows being iterated top-to-bottom, and appending the soldiers of every own milsite found in the same order as in the milsite's window to the back of the list of soldiers. Not 100% sure about this though.


Top Quote
xorx
Avatar
Topic Opener
Joined: 2020-12-12, 21:36
Posts: 29
Ranking
Pry about Widelands
Posted at: 2021-01-02, 13:37

Hi Nordfriese,

thanks for the information. Does that mean that if I have a scenario like the following:

    x

 y                  e

          z          k

where x, y, z and k are military building I own and e is an enemy military building, I will get the soldiers from x, then y, then z and finally k?


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1954
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2021-01-02, 14:32

I had another look at the code and actually it's more complicated than I thought because the code also ensures at the same time that the soldiers can actually reach the target building. The algorithm works like this:

  • Create a queue of fields which initially contains only the center of the circle (the enemy site)

  • Create an empty list of own milsites

  • As long as the queue is not empty, do:

    • Append the first field in the queue to the end of the list, if there is an own milsite there

    • For each neighbour of the first queue field, check if we can move from the current field to this neighbour and that the distance from the neighbour to the start field does not exceed the attack radius (hardcoded as 25). If the check succeeds, append the neighbour to the end of the queue (but only if it was not looked at yet). Neighbours are iterated in the order NE, E, SE, SW, W, NW.

    • Remove the first element from the queue

(code: logic/player.cc:1201-1242 and logic/map.cc:1034-1071)

So the exact order is not entirely intuitive (basically from the center outwards in clockwise circles); but if there are obstacles or non-walkable ground it can get almost impossible to predict without following the algorithm with pen and paper…


Top Quote