proposals for formations

Recommended Posts

I've looked a bit into binaries/data/mods/public/simulation/components/Formation.js, but I'm not familiar with the code, or with Javascript either, so I'm writing here some suggestions to make formations look better.

Assignment of units to formation places

At now, when soldiers move into formation, they do a lot of switching places, I can't tell if you have implemented already some algorithm to assign positions to men in an effective way, but if you have not, I can propose a simple one:

1. take the 2d point C = the final destination of the current movement, if men are making the formation in place, take C = centroid of the positions of the men (I believe the script already does this)
2. compute the set F of 2d points representing the final position of all men in formation. These points will be placed around C. If different classes of units should take different places, compute an array of sets instead F_1, F_2... each including the positions that will be taken by each class of units
3. for each class of units K:
1.  take the set of points A_K = the current positions of the units of that class
2.  make A_K an ordered array, with the farthest from C first, and the closest last
3.  for each element P of A_K (in order from the fartest to C, to the closest):
1. take the point in F_K that is closest to P (if not already assigned), and assign the unit in P to that point

this should be reasonably fast and effective, often resolving in the best possible assignment of formation slots.

Rotation movement

At now, formations resort a bit too often to a rotation movement that, to bee honest, feels a lot akward to me, not only it can waste a lot of time, but it feels artificial and unrealistic to me. I've been looking around if videos exist of formations and parades making turns, but unfortunatly I didn't find any. In any case, I have a couple of suggestions to smooth this transition:

• when the turn is narrow enough (let's say less than 45 degrees) formation movements don't look that bad, however, the rotation still eats time, and during a battle you don't want to lose any time at all. For a comparison, I noticed that when you move a group of scattered soldiers towards some destination, into formation, they will be first converging to the center of their position, but will soon start to move towards the destination, before completing the first movement. Would it be possible to have the same thing when the formation makes a turn? That it starts moving onward before completing the rotation?
• Maybe it's me, but I don't like formations making rotations, especially large ones, I don't think they are realistic. And probably you already thought about this, but what if formations were instead re-computed from scratch every time they make a turn sharp enough? It doesn't have to happen for smaller turns, but I think it would feel more natural, especially for homogeneus formations (the most usual), when you command a sharp turn.

Column formation

Sorry if this part won't be as constructive as the others, but I think that column formation, as it is now, should better be removed completely. A column of men is actually better represented in the game by not setting any formation, while the special "column formation", that automatically switches on when you send a formation of men to a distant destination, is rigid, and very akward. The purpose of the column should be saving time by making men move in a flexible shape that follows the road and bends with it, instead, the column in the game even wastes more time than the simple box formation, because its rotations take longer. I don't think there's much to save in current column formation, so I would disable it completely, until a completely new version is possibly introduced.

• 1
• 1
Share on other sites

Looking better, I think that all the swapping places is not really about the algorithm that assingnes places to each unit, but is rather caused by the recurrent routine that updates the formation, often making men abruptly change direction while manouvring. I'm not sure how that could be fixed, but I hope my proposals could be meliorative in that regard too.

Share on other sites

I agree that consistency in a formation will look and play better. I think the unit re-arranging inside formations comes from pathfinding in it's core, calculating if the formation can fit through the path (which gets recalculated quite often if im not mistaken) but i'm not 100% sure. But yeah, the re-arranging is really spammy sometimes.

If you don't know how to mod, you need to find someone who will look into it for you. Or you can try to learn some javascript basics and apply what you learn into your mod. Code Academy is a pretty decent free one, which focusses on quick short sessions a day for routine. Relatively speaking in comparison to other languages, java is easy to learn.

Share on other sites

The way formations work currently is that units are assigned an offset to the 'formation controller', an invisible, large entity (paths like a ram/elephant). Then they try, at all time, to go to that offset. The 'formation controller' itself is moving normally.

This is why turning looks weird: suddenly the formation controller rotates and the offsets change a lot, and it's very un-natural.

Fixing this efficiently would require a rethinking of the system, so it's not that trivial.

Share on other sites

Yes I figured that. And its pathfinder is handled by c++ code, right? How does it read (if it does) the position of the various units? How does it use it? Would it be possible to fix a value to make rotations instantaneous? Would it be possible to make commands given to formations not pass directly to the "formation controller"?

I'm not familiar with either c++ or javascript, but if you'd like to introduce me to the design, and to the nuts and bolts of the formation and pathfinder implementation, I'd like to try my ideas on the code directly.

Share on other sites

10 minutes ago, alre said:

Yes I figured that. And its pathfinder is handled by c++ code, right? How does it read (if it does) the position of the various units? How does it use it? Would it be possible to fix a value to make rotations instantaneous? Would it be possible to make commands given to formations not pass directly to the "formation controller"?

The actual motion of any single unit (including the invisible 'controller') is in C++, however the code that calculates offsets for a given unit is in JS, in formation.js. The problem is that you'd want the offset to adjust each turn, which might be tricky to do at the moment.

10 minutes ago, alre said:

I'm not familiar with either c++ or javascript, but if you'd like to introduce me to the design, and to the nuts and bolts of the formation and pathfinder implementation, I'd like to try my ideas on the code directly.

It's really two pieces of code:

- Formation.js decides where to put the unit in the formation
- CCmpUnitMotion.h in C++ handle the motion.

These are both rather complicated files, but you can take a first look at them and see what you understand.

Share on other sites

A trail of breadcrumbs would be nice, but, as said, is a rework of the system.

@alre You can remove "<!--" and "-->" from template_formation.xml to visualise the formation controller in the game.

Share on other sites

I haven't yet to check the related code entirely, so my opinion here is based solely on my incomplete code checking, observation on in-game behavior, and also my brief experience joining marching competition as high school boyscout. @wraitii and @Freagarach please correct me if I'm wrong.

Formation as currently in 0 A.D. use FormationController to direct the formation. The controller seems to be placed in the center, so when the formation rotated, the units in the center stay put while others move to accommodate this. Also when some of the units are leaving the formation, the entire formation would be rearranged from scratch.

However, it is a bit different in reality. Usually the equivalent of FormationController would be the commander, which is placed not in the center of the formation, but usually on front left. Each formation member on the front row would try to follow the one directly in his left, while others would follow the one directly in front of each. When the formation is rotating, every member would not rotate unless the guy in front of him is turning.

If you want to check how this behavior look in-game, say you have 10 soldiers. Set Soldier 1 to Guard Soldier 2, Soldier 2 to Guard Soldier 3, and so forth until Soldier 9 is set to Guard Soldier 10. Then move Soldier 10 anywhere, and see how the other units behaved. This is how a column formation is supposed to be moving in real life, only they stand closer of course. My suggestion is that we keep the current Formation.js behavior on the front row, while the second and so on rows using this 'guarding' method to follow the first row units.

When some members are leaving the formation, each member that left would first check the front and move forward if his front is empty, and otherwise check the left and move if empty, otherwise stay put. So there would not be too much shifting because the formation is adapted to existing formation members and their positions, not recreated from scratch. MoveMembersIntoFormation function in Formation.js might need to be revised like this.

Hopefully I have time in the weekend to check on this further.

Share on other sites

I tried to raise the turn rate in template_formation, to an'impossibly high value, and I think the turns are (just a slight bit) better. Anyway, for stronger turns I still think that recomputing the whole formation would be better.

I also tried recreating a formation with guard command to back soldiers, but predictabily, it was impossible to make anything passable. I was surprised to find out that guarding units move somehow erratically: sometimes those who are expected to move first, only move after those behind them, sometimes they stop too early, only to make a few more steps after a brief pause.

Share on other sites

To slow down the turn rate you want to set it to smaller numbers. I tried out 0.5 and I think it is a marked improvement.

Share on other sites

On 30/06/2021 at 1:21 AM, ChronA said:

To slow down the turn rate you want to set it to smaller numbers. I tried out 0.5 and I think it is a marked improvement.

yeah, unless you actually want to use formations.

Share on other sites

In terms of historical authenticity, formations should not be maneuverable, durable things. They took tremendous coordination to form and maintain, and that placed strict limitations on the kind of terrains and situations they could be used in, which in turn shaped all the basic tactics and theory of ancient warfare.

When I made my last post, I was actually going to suggest that formations should be programmed to just break any time they try to make a turn of more than 30 degrees or so, just to add more tactical complexity the their use. (But I was feeling lazy, and I don't think it would have added much to the discussion compared to the idea of just slowing the turn rate.)

I do not dispute that reducing the turn rate or persistence of formations would make them unusable in 0 AD as it currently exists. However that's only because 0 AD fails so miserably at simulating some of the basic dynamics of ancient warfare. Without those simulation improvements there is really no point in having formations. They don't meaningfully interact with any other game systems. (Contrast AoE2, where they are at least used for micro against splash damage sources.)

Now that pathfinding is working better, there is no need to keep carrying the crutch of formations just out of habit. Or if you do want to keep it, its time to add new elements to the game that will make it interesting and useful.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.