-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[WIP] doc on formations #705
Comments
This looks very good! One thing to add maybe: If units types are mixed, each type forms their own little "sub"-formation.
Above would be 40 spearman
This is a formation of 22 Spear + 16 Archers = 38 Units. They form 5 rows instead of the predicted 4.
That's what the 16 archers and 22 spear would look like if they were in separate formations. Seems to be a bit more complex if several different unit types are involved. |
Very nice work here and in the other issues/PRs 👍 |
Oh shit this is gonna be so much fun implementing that in the pathfinder/steerer 🙄 |
Found two articles which are real gold mines. They primarily deal with the formation systems of RTS. Implementing Coordinated Movement both are by Dave Pottinger who worked on the AI for Age of Empires II. He even includes some pseudo-code :) |
@heinezen it seems to be:
NOTE |
@Piruzzolo Great! Unfortunately it gets even more complicated, when cavalry is mixed with infantry. A cavalry line on its own will group normally. However, when infantry is added, they behave a little different. Take an example of 6 cavalry and 9 infantry. The cavalry will form a single line in the front as we would expect but the infantry behind will also form 1 line, making it a 6/9 formation. 6 infantry and 9 archers would form a 6/5/4 formation with a single line of infantry in front. I think this is caused by cavalry being "wider" than infantry and they need more space in between. The infantry behind then adapts to it. At first I thought the width for the infantry line would be Now maybe one could think this happens because cavalry is always in the first group, so it "naturally" influences the units behind it. But when I tested it with infantry + rams, the infantry line also gets wider. In fact, a formation of 6 rams and 16 infantry will put all of the infantry in a single line in front. If you add 10 cavalry to this formation, they also form one single line and not two. The more I think about it, the more I am convinced that the first group doesn't matter and instead the "widest" group dictates the number of units per line. At least in mixed formations. |
For reference, this shows which unit groups are placed in front:
|
Oh gosh! We need a bit of rethink. I agree that the width may be the right thing to look to. If you take a look here, you can see that units are internally arranged in groups and line ids, which determines their type and behaviour. LineIDs may look promising. The archers belong to a certain lineID and group. We can have mixed lines, i.e. formed by units belonging to different groups (as an example, take 11 archers and a scorpion). This suggests that we may create a (symmetric) lookup matrix with 1 if the A-type unit can be in the same line as a B-type unit, 0 otherwise. From the suggested experiment, you can notice that the presence of even a single scorpion in a line of archers does affect the spacing between all the units of the group they belong to. So, if it holds your guess about width determining the arrangement, this would affect all the units in the selection. Your reference list of unit groups will grow 😄 Here's my proposed algorithm:
subroutine (modified from my previous post):
We need to check this against some data |
@Piruzzolo Aah indeed these Group IDs look very promising. However, i don't think we need the affinity matrix. I propose a more radical solution that should compute faster than yours. Every formation would always be divided into 4 "sub"-formations, one for each unit group you see in my previous post. Sub-Formation 1 would take cavalry, Sub-Formation 2 infantry and so on.. Sub-Formations can be empty (with 0 lines and 0 width). The algorithm would look like this:
Then we can continue with the 4th step in your algorithm:
There are several advantages to this method. First of all sorting the units into sub-formations has a run-time of |
Nice work, better and more focused algorithm. So, to do the |
I think we should focus on collecting much more data, before we try to design the
With the bottom-up approach we should discover all variables the formation system depends on in the process rather than just "guessing" how the What do you think about it? |
That's the right approach, I agree. Systematic analysis is definitely better than random guessing. It's going to be a big work, surely I would land you a hand 👍
The following overlap with each other, in single type formation: Trade carts seem to arrange as they were in line formation. My guess is a correlation between (lineIDs and groupIDs) and the actual ordering (like a comparison, greater than or so... why the negative numbers, otherwise?). May worth check |
Just wanted to add that there are 4 types of formations: |
@Yanikore Yes, we know. Since the staggered and flank one are very similar to the line formation, we could easily adapt our findings to those. The staggered formation is just the line one, more spaced; the flank formation is the line one, someway splitted in two. The box formation is a bit different |
Another thought: assuming we had a working pathfinder, how would we add that formation support? And if we have a random bunch of units at some battlefield, if we select those and command them somewhere, they may not have space and time to form their formation. In other words: How do we express the request that units should form the formation? Our coming flow-field-pathfinding-approach can handle each unit independently. Additionally, we have the choice:
The first option will likely be much slower, but the second one requires more logic so that units dont constantly walk into each other. But if we combine the formation forming and the "not walking into each other", we could maybe solve both problems. The formation is just another "not walking into each other" with a certain structure. |
@TheJJ It's going to depend on the actual implementation. Since the game itself won't be using GPU so much, we could even try to implement core pieces of the pathfinder as GPU kernels. There are some implementations of A* on Github and many academic papers on the subject. About formations, we may find some ideas here and here. Also, this overview by one of the game developers may be useful. |
@Piruzzolo Would be awesome if you can figure out if Since it's the weekend now, I will hopefully figure out in which sub-formation every BTW: Do you mean "overlapping" in the sense that their selection circles overlap? @TheJJ I highly recommend you to read this as Piruzzolo already pointed out: because it explains some basic principles that the devs at Ensemble used or the formation system. One interesting thing that Pottinger describes in this article is that a formation should have a leading unit (presumably one in the first line) and other units in the formation will just follow it. This could lead to a great performance increase, since pathfinding would only have to calculate the path for the leading unit. For now we are trying to figure out how the formation is ordering its units, so implementing formation pathfinding still sounds like rocket science 😄. |
Yes, will read that :) |
It seems that
The only exception is the Battle Ship Group. Battle ships use the same 4-sub-formations-system but the deciding factor is the ``LineID`. When land and sea units are mixed (this can be seen in shallow water), the cavalry sub formation will mix with demolition ships, the infantry one with fire ships, the ranged one with galleys, longboats and turtle ships and cannon galeons with the support group.
Looks like putting units into a sub formation just requires a simple switch statement. Note: Units in the 5th sub formation won't form a formation and won't be part of one. The also don't obey the rule that a formation moves as fast as the slowest unit it contains. |
@heinezen Yes, I mean circle overlapping.
I put a pipe to show the pattern on horizontal rows. The |
@Piruzzolo Hmm.. I justed tested this and on my first try I had the same result as you. However after I commanded them around and selected them again I got another result:
Which would be From a quick test I got the idea that it might has to do with the order the units are selected. In this example I selected the units in this order: archers, longbowman, skirmishers, cho ko nu
As you see, it's the selection in reverse order, repeated in every line. Maybe you were just lucky enough to select your units in the right order to support our theory 😄. |
I'd say very lucky, since I've done it 3-4 times without noting! :) I'll do some tests with other configurations |
This (selection order) behavior seems sort of silly; should we really attempt to clone it? (would it harm the user experience not to?) |
@mic-e Well, we don't know until we have figured it out. Right now it could just be a side-effect of the implementation or it could even be the fastest method to order units. When we eventually figure out how it works, we can worry about improvements. @Piruzzolo I did some more testing with units that have the same
If ordering depends solely on
|
@heinezen I just found some interesting hints about
So, "*-line" strings would be just wildcards to group unit types for AI scripting in Lisp, not a "line" meaning a "row" in a formation (or not necessarily). However, the |
So, maybe the point is that units are arranged in a way that they form vertical rows of units of the same type, taking in account the initial selection order.
If we enumerate the types in the list above left-right and the positions in the formation right-left from bottom, we see that the first in the formation is S (as in the order list), the second is P (as in the list), the third is EM (as in list), but then the fourth is M, which is not the fourth in the list. This can be explained by guessing that units already positioned make the turn of their type skip in favour of still non-positioned types. |
@Piruzzolo If thats the case, then we could achieve this ordering by a very simple algorithm
This should seperate all the different unit types that get added to the sub formation. Ordering would be done in the following steps
Example: Archers (A), Shirmishers (S) , Longbowman (L) selected in this order
12 Units should form 2 line á 6 units so the lines should look like this. The arrow points in the direction the formation is oriented.
Which is exactly how it turns out ingame. Can you double check that? 😄 |
The first line |
Ooops I typed the selection order wrong. Should be fixed now and example is working correctly! Same example for my previous "wrong" selection order:
12 Units should form 2 line á 6 units so the lines should look like this. The arrow points in the direction the formation is oriented.
|
Furthermore, @mic-e will be happy because the selection order behavior is only a side-effect of the algorithm. So there's no overhead produced :) |
The resource constraints were very strict at the time 😄 Great job, man! So, we now need to know how the width of a sub-formation is calculated. Units overlap the base circle with each other, seemingly differently depending on the unit. A rough estimate is 30% for cavalry (maybe 33.33%? Maybe) The algorithm of above could maybe be re-used with the box formation, maybe. For a box formation of all Archers, here's the result for 2, 3, 4, 5, 6, 7, 8, 9:
|
From my observation a line of 5 Archers/Infantry is roughly 2 tiles, 5 Cavalry about 3 tiles, and 5 siege units 5 tiles wide. This means cavalry takes usually 50 % more space than infantry and siege 150 %. Maybe @TheJJ can tell us if there is anything in the gamedata that can be used to determine the width or at least the radius of a unit? Should be used for other things such as collision.
Great start! Oh this box formation gives me troubles 😄. With mixed units in a sub formation it seems to order them randomly and changes the order on every movement command. It's also hard to keep track of where the front side is. |
Yes, each unit has a radius, in fact they even have three. For now we thought those are used for the selection circle size and hp bar position. |
@TheJJ Thats awesome, thank you. @Piruzzolo Our |
Maybe the y positioning it's a bit more complicated: take a Ram, its circle is aligned with that of others, but since it has a bigger radius, it has to be positioned a bit behind. It's not the center of the circle to be aligned, it's the front point of the circle, at least for a Ram. So we begin calculating a line through all the circle front points of the other units (the tangent line) and align the Ram accordingly. Need to check if it's true for all the units |
I'm pretty sure it's the center of the unit they align to. In a mixed sub formation of Rams and Kings, the units align to the center points both on the X and on the Y axis. There could be a hidden offset that we don't know about though. Or am I misunderstanding you? |
Ok, I just realized I was wrong, I simply didn't give them enough time to align properly. The Rams seem to align to the center, my mistake |
@Piruzzolo No problem! :) It's better for us to double-check it than doing it wrong. Btw i did test some box formations and the ordering of the sub formations looks like this, with
How far the units in a sub formation (maybe "layer" is more appropiate for this one) stay apart depends on
Take for example a box formation of 2 onagers and 10 archers. The spacing between the archers will be the same as between the onagers. Or to put it simple: Outer layers inherit the Still can't wrap my head around how ordering with mixed units inside sub formations works 😄 |
Hi, I've just updated my gist on formations with a cleaner formula, much simpler than the old one. Please take a look 😄 here |
@Piruzzolo Hey, welcome back :) Looks good to me and should be fast enough for practical use ingame. You totally should create a PR for it now, since it's the last thing about formations that's not in the repository (see #783). |
Hi guys! Sorry, I haven't pinged in a long time :S Anyway, good news! There's a function in the AoK alpha which assigns each unit to their formation group, just like the pseudocode at the end of our nice discussion, here @heinezen Your code looks pretty correct! 😄 |
Hey @Piruzzolo ! Glad to hear back from you. I had to remove some content in your comment because we don't allow reversed code from the original games here for legal reasons. It's not worth the trouble that it could cause 😄 |
Formation Idea: Triangle/Spear formation (example)
|
I've created this gist on units formations. As you can see from the revision log, it is still a work in progress. I'm finding a way to express the last formula in terms of integer functions only (i.e.
Mod
,Ceil
,Floor
and so on). I will make a PR with a recap of the gist as ready.This is for you to know and discuss and (possibly, if you feel to), contribute ideas 👍
The text was updated successfully, but these errors were encountered: