# 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

• Replies 88
• Created

#### Posted Images

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.

##### Share on other sites

• 2 months later...

aI made a mod that implements my proposals on formations. I think the improvement is stark, here's a preview:

Some detail:

Assignment of units to formation places

This is already very similar to the current algorithm, the only difference is point 3.2. I tried hard to introduce it, but, for simple that it sounds, I can't seem to make it work. Sorting the array doesn't seem to have any effect, I noticed it's always the same units that take the farther positions, those left out by the others. I'm attaching the js file with attemted edits.

Also point 2 has seen an improvememt, similar to the one dealt in the next section.

Rotation movement

This had the greatest impact, in particular the second point. Makes formations a lot more usable I think. First point is dealt as in my last post of June 30.

Column formation

This was easiest. Not much to add about it.

Further considerations and questions

- I did quite some code refactoring, as much as I thought it would be acceptable. External use of some function may break, although it seems unlikely to me.

- I'm not sure I respected coding conventions either.

- Formations now don't get formed anymore in the mean direction of their members.

- Browsing Formation.js history, I was startled noticing that actually my proposals are nothing new and already where in the engine some time ago (rP14292, rP14300). I'm not sure what to do with this information.

- How is LoadFormation supposed to be used?

- The only way to make formation turns more natural than this, is to change how entities turn around obstacles, so that they do not do it on position, but rather sliding around the corner as they turn. The improvement would be evident for formations, but would also be noticeable for rams and cavalry. I'm not sure where's the code for that.

- I can keep making improvements if you like, my goal is to make formations good looking, and also reasonable even for competitive games, and I'd like my edits to go in the main game. (edit/clarification/license: I renounce to all rights on my work on the mod and agree to the legal disclaimer)

Edited by alre
• 7
• 1
##### Share on other sites

1 hour ago, alre said:

I think the improvement is stark,

From a quick test:

I like the movement. A bit less "shifty" than before

##### Share on other sites

9 hours ago, alre said:

Column formation

This was easiest. Not much to add about it.

I wish column followed a more snaking motion.

##### Share on other sites

On 4/7/2021 at 2:44 PM, ChronA said:

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.)

That is an unfortunate aspect of the current gamestate.  In the past there were a few ways the original team though that they could be more useful.  These included making individual target random units in the formation in such a way that ranged units and melee could never focus fire a single unit.  Others included a number of buffs and debuffs.  Phalanx for instance made hoplites generally tougher at the expense of being slower.  Seeing just a few of these ideas in the game could perhaps make the mosh pit battles a less common occurrence.

##### Share on other sites

1 hour ago, Thorfinn the Shallow Minded said:

That is an unfortunate aspect of the current gamestate.  In the past there were a few ways the original team though that they could be more useful.  These included making individual target random units in the formation in such a way that ranged units and melee could never focus fire a single unit.  Others included a number of buffs and debuffs.  Phalanx for instance made hoplites generally tougher at the expense of being slower.  Seeing just a few of these ideas in the game could perhaps make the mosh pit battles a less common occurrence.

It is a bit weird for me to think about a focus on "the basic aspects of ancient warfare" in an RTS. Because RTS games in general are just so immensely unreal. Not just the abstraction but the way you control the units. Total War is perhaps the closest game to any true simulation. Even something like Fields Of Glory which is somewhat closer is turn based.

There's no structural reason that spears or pikes is good against cav for instance just a completely artificial stat bonus.

One major problem I see in general in the development thought process of 0AD is taking generic RTS tropes/mechanics as a given and then subjecting the novel features to a heavy "isolated demand for rigor" as they call it in philosophy. Trying to make formations function at a significantly lower level of abstraction than unit counters or other mechanics doesn't make a lot of sense. And formations are somewhat iffy in RTS in general. There is a reason Total War games put all units in formations at all times. Because single unit micro would be objectively superior if you had the APM in all cases.

You might consider whether 0AD should simply require TW style group based units all the time. Otherwise you'll have to make the kinds of compromises that are already made for "counters".

##### Share on other sites

2 hours ago, MoLAoS said:

There's no structural reason that spears or pikes is good against cav for instance just a completely artificial stat bonus.

The stat bonus is there to focus on a basic aspect of ancient warfare, that cavalry would lose in a head-on fight against massed pole-armed infantry.

2 hours ago, MoLAoS said:

It is a bit weird for me to think about a focus on "the basic aspects of ancient warfare" in an RTS. Because RTS games in general are just so immensely unreal.

Well, if you don't at least make an attempt to simulate ancient warfare, then what is the game simulating?

3 hours ago, MoLAoS said:

You might consider whether 0AD should simply require TW style group based units all the time. Otherwise you'll have to make the kinds of compromises that are already made for "counters".

##### Share on other sites

32 minutes ago, wowgetoffyourcellphone said:

The stat bonus is there to focus on a basic aspect of ancient warfare, that cavalry would lose in a head-on fight against massed pole-armed infantry.

Well, if you don't at least make an attempt to simulate ancient warfare, then what is the game simulating?

My argument is that you should have a consistent level of abstraction. So if we are willing to use damage bonuses that is a high tier of abstraction. Same should apply to other features. Having battalions actually lowers the abstraction level since it makes more sense. Spear/pike was effective against cav in formation not individually. A single spearman vs a single sword cav the cav should win easy. It is when you have 120 spear boys vs 40 centaur boys that spear boys wreck face.

For formations:

I actually did a legion system as one of my improvements on base GAE for my fork. Had formations, AI stuff. Legion AI didn't get finished though, just move command stuff. Think mixed order combat functioned at the basic formation level though.

I would probably implement formation bonuses with individual auras. So for every unit in formation in position within 2 tiles to unit +1 defense or something. Should be quite fast because you only need to check within formations and between engaged formations.

Edited by MoLAoS
##### Share on other sites

45 minutes ago, MoLAoS said:

I would probably implement formation bonuses with individual auras. So for every unit in formation in position within 2 tiles to unit +1 defense or something. Should be quite fast because you only need to check within formations and between engaged formations.

Formation bonus is already implemented, but only used in one case. See: public/simulation/data/auras/units/heroes/athen_hero_iphicrates_1.json

So probably no need to implement it again if you want to use it.

##### Share on other sites

Do note though, that auras can be slow.

##### Share on other sites

I don't believe to much that has ben said here in the last posts.

- I have read in history sources, that polearms were often weapons of choice of footed soldiers against knights, on 1v1 just as much as in mass, and even if massed soldiers can more easily stop a cavalry charge, I don't really see what difference does the weapon make in that

- positioning your soldiers is a big factor in every RTS, and formation can help in this, regardless of boni or such. Also open formation can help limiting ranged sources of damage

- consider that in 0AD soldiers don't fight in formation (ranged units may do, but not melee) so it doesn't make much sense to me to grant them any bonus. It is true that formations had a role, historically, in combat too, but for that you'd need formations much more flexible than those we have, so that soldiers can stay in formation while fighting

Edited by alre
##### Share on other sites

Well technically we support attacking in formation it's just that the code is broken so it was disabled.

##### Share on other sites

12 hours ago, maroder said:

Formation bonus is already implemented, but only used in one case. See: public/simulation/data/auras/units/heroes/athen_hero_iphicrates_1.json

So probably no need to implement it again if you want to use it.

Yeah I wouldn't do it that way. It is boring. If the game were to move to battalion only combat, which is usually better than a mixed system, it would provide far more verisimilitude to avoid single auras for formations. Or you might avoid auras if they are so slow as Stan claims. Providing aura bonuses based on formation cohesion and stuff like flanking in a sortos pseudo total war style would be way more interesting tactically. You could still employ a "leader/officer" bonus as appears to be the flavor of that json file but that would be in addition.

##### Share on other sites

On 10/9/2021 at 2:21 AM, alre said:

- I have read in history sources, that polearms were often weapons of choice of footed soldiers against knights, on 1v1 just as much as in mass, and even if massed soldiers can more easily stop a cavalry charge, I don't really see what difference does the weapon make in that

The spear/polearm being specifically designed to combat cavalry is a bit of an RTS convention; simply by virtue of much better reach spears were used by and large by all infantry regardless of whether they were facing cavalry or not.  Whether a spearman would outperform a horseman one-on-one is a triviality in which matters of other equipment, training, etc,... complicate the matter.

On 10/9/2021 at 2:21 AM, alre said:

- consider that in 0AD soldiers don't fight in formation (ranged units may do, but not melee) so it doesn't make much sense to me to grant them any bonus. It is true that formations had a role, historically, in combat too, but for that you'd need formations much more flexible than those we have, so that soldiers can stay in formation while fighting

Even if the game does not embrace a battalion system, it would be nice for players to benefit from engaging in orderly formations.  Even making it possible if only suboptimal would be a nice change of pace.  I personally like to see my troops in proper battle lines, but the stand ground stance is annoyingly restrictive while the defensive stance goes too much in the other extreme.

## Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.