PDA

View Full Version : Guide: Formations _ai (WIP)



Red Spot
12-11-2007, 01:40
This is my effort in trying to show people some of the characteristics of the formations and how easy it can be to make your own from scratch once you know some of the basic steps.

The topic will start of a bit messy as a true WIP, but hopefully in time I'll slap some structure into it ;)



Formations and formations_ai


First of all I'll have to tell you that there are at least 2 men that have written similair sort of topics as this and even though I may not agree with their findings their work by itself deserves some respect and does a great job on the battlefield, I however believe it can be improved, anyway I do think reading or at least knowing about their work can help you if your new to formation-modding and also will possibly give you an other view on formation-modding;
Darth Vader's work (http://www.twcenter.net/forums/showthread.php?t=64097)
Sinuhet's work (http://www.twcenter.net/forums/forumdisplay.php?f=130)

A generic formation to give you a look at one, if you havent already;

begin_formation ai_family_multi
attack
defend
ai_priority 2.0

;; Family-members, first line
begin_block 0
min_units 2
max_units 3
not_general
unit_type skirmish cavalry 1.0
default_melee_state skirmish
unit_density close
min_unit_width 16
max_unit_width 22
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 2.0
priority 1.0
end_block

;; Family-members, left
begin_block 1
not_general
unit_type skirmish cavalry 1.0
default_melee_state skirmish
unit_density close
min_unit_width 16
max_unit_width 22
block_formation line
block_relative_pos 0 -18.0 -2.0
inter_unit_spacing 2.0
priority 0.8
end_block

;; Family-members, right
begin_block 2
not_general
unit_type skirmish cavalry 1.0
default_melee_state skirmish
unit_density close
min_unit_width 16
max_unit_width 22
block_formation line
block_relative_pos 0 18.0 -2.0
inter_unit_spacing 2.0
priority 0.8
end_block

;; Family-member, General
begin_block 3
min_units 1
max_units 1
unit_type skirmish cavalry 1.0
default_melee_state skirmish
unit_density close
min_unit_width 16
max_unit_width 22
block_formation line
block_relative_pos 0 0.0 -18.0
inter_unit_spacing 2.0
priority 1.0
end_block

;; Siege equipment, left
begin_block 4
unit_type siege 1.0
default_melee_state fire_at_will
unit_density close
min_unit_width 11
max_unit_width 11
block_formation line
block_relative_pos 3 -6.0 -2.0
inter_unit_spacing 6.0
priority 0.4
end_block

;; Siege equipment, right
begin_block 5
unit_type siege 1.0
default_melee_state fire_at_will
unit_density close
min_unit_width 11
max_unit_width 11
block_formation line
block_relative_pos 3 6.0 -2.0
inter_unit_spacing 6.0
priority 0.4
end_block

;; Dummy block
begin_block 6
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 3 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
This formation I use to deploy 3 to unlimited family-members that come without any army except possibly some siege-equipment.
I'll try and explain formations using the above formation as well as it pretty much holds every single command that we can use and has some interesting combinations of commands that need some attention as they can be the cause of some formation-modding-greef, like the "not_general" command can if improperly used.
Even though I dont have a generals blok the general will always deploy in the center of the formation as can be seen here;
https://img131.imageshack.us/img131/6236/nieuwbitmapafbeeldingxu3.th.jpg (https://img131.imageshack.us/my.php?image=nieuwbitmapafbeeldingxu3.jpg)

-The formation label
Each and every formation will start with a name of its own, like each trait or unit or building or city or ... like everything else in the game things need to be assigned some label so the game can refer to it.
Usually when you label things you need to take care not to use a single label twice or more, though it seems the game can handle a label being used more than once, though as there is absolutelly no need to do such a thing I recommend using different labels.

The formation will start with the command; "begin_formation", followed by the label you give the formation.
and the formation at the end is closed using the command; "end_formation"

-The formation purpose
What I'm refering to here is what purpose the game can give to a formation wich are a few fixed purposes, meaning you cant just add new purposes as you go
The game sets certain purposes for armies as it is deployed, enters a battlefield or battles evolve, wich can be;
-attack
-defend
-march
-pursue
-standard_ambush_defender_deployment

-several others for bridge and siege battles (for a later time)

When an army is deployed that army will always deploy in a "defend" formation and will keep the "defend" purpose or immediatelly after start of the battle switch to the "attack" purpose.
Armies that reinforce seem to start on a combination purpose "attack/defend", according to Darth Vader's research you need this formation purpose in your formations_ai file or else a battle with reinforcements will cause CTD's
How exactly reinforcements behave I have no knowledge about ... yet, what I do know is that AI-armies with the "defend" purpose (ones that dont attack you :)) can have their reinforcements join up with them and join a single huge army, wich means you need to make sure your formations are not limited at a max. of 20 units as this is what can cause reinforcements stalling and never joining the battlefield, though I think that that is probably not the only cause.

What you need to run a basic field-battle is basicly only a single formation with the purpose;
attack
defend
(like used in the example formation above)

you do not need individual defend or attack formations, though they allow you to make very big differences between an attacking or defending army (or even a reinforcing army, at least up to some point)

I'm not sure how or when the "march" and "pursue" formations are used as in my current tests I made them into very easy to spot formations and never noticed any being used, wich however doesnt mean they havent been used, I'm just not sure about it.

The "standard_ambush_defender_deployment" purpose is set when an army is succesfully ambushed and makes and army deploy sort of in the middle of the ambushers deployment zone.
Note on ambush deployment; make sure that when you play on large or huge that armies can actually deploy in the deployment zone as vanilla clearly cant handle the formation at those sizes.
Vanilla makes the formation strech into a single column, but this makes the army to tall when its a full stack and causes 1/2 the army to deploy in the corner of the map, making the army wider or deploying in 2 or 3 columns depending on gamesettings can prevent the ugly misshap

-The formation priority
After you've given your formation a purpose its needs to be assigned a priority.
Dont let this priority fool you, its not that important when trying to make a difference between formations, meaning a formation based on cavalry wont be used on infantry just cause its given a high priority.

I personally use this priority in 2 different values and pretty much leave it at that, wich are prio. 2.0 for attack or defend formations and prio. 1.0 for anything else.
This makes it so that attack and defend formations will always be picked over the combination formation attack/defend, wich would only be used by reinforcements, and any other formation will only be used if the correct purpose is set by the game so priority has little use there.
(I do use priorities though but in a diff. way, wich later on in the guide will be explained)

-The supported factions
We have the use of a command wich allows formations to be assigned to different factions using the command; "supported_factions" before the actual formation begins.
The command is used as followed;

supported_factions romans_julii, romans_scipii

-So far ....
What you would have by now, and how you could basicly start any formation;

begin_formation ai_my_formation
attack
defend
ai_priority 1.0

supported_factions romans_julii, romans_scipii

{Here the actual formation will come}

end_formation

-In between ....
Formations are simply said basicly a collection of blocks, by using different blocks you make different formations.
Each of these blocks can be given certain settings wich again can make the same formation completelly different, say for instance so one can be used for defence and the other for attack.

When an army is deployed (AI and human) the game runs through the formations file looking for whats seems the best fitting formation for the army using the correct purpose tags, so a fitting formation that is only made as attack formation wont be used for deployment as that requeres a defend formation, or any combination that at least uses the purpose defend

There are several ways to tell or influence the game to pick specific formations, the most brutal of forces are the priority and supported factions command, though both wont make or prevent the game from selecting a formation, what I mean is if you give a formation a high priority and tell it that it needs to be selected by faction X but the formation is without cavalry block and thats what the army is filled with than the game will not select that formation if there is something remotly better fitting, like a formation that does have a cavalry block.
This also shows one of the less direct ways of influencing the priority of the formation, make a fitting formation and the priority can be low as when that army is deployed the AI actually wants to pick it, forcing stuff upon the AI wont improve it!


-The dummy blocks
There are basicly 2 different type of blocks, wich are the dummy and unit blocks.
The dummy-blocks can again be split in 2;
-spacer
-spans

Spacer allows you to create a block without actually placing a unit, say an empty unit-block.
In reality its not of much use as most "gaps" can be created by simply allowing more space in between the units, but it does have it uses.

You should however know that an army will be deployed on a sort of baseline, meaning if you deploy and army it will not cross this baseline nor be behind it.
What I mean is if you put say a spacer in front of an army the army will not be pushed back the size of the spacer, it will deploy at the exact same place as without the spacer.
Spacers are not to "push" armies in any direction they are to create gaps in between men/unit-blocks.

An example of a formation with a usefull spacer.
This formation is for when army of archers together with a general enters the battlefield as reinforcements (untested and probably poor in real battle, but it will give you an impression of how the spacer-command works);

begin_formation ai_archer_small_reinforcements
attack
defend
ai_priority 1.0

begin_dummy_block 0
spacer 0.0 0.0 60 30
end_dummy_block

;; Archers, left
begin_block 1
min_units 1
max_units 3
unit_type ranged_missile_infantry 1.0
default_melee_state fire_at_will_and_defend_and_skirmish
unit_density close
min_unit_width 40
max_unit_width 40
block_formation column
block_relative_pos 0 -2.0 0.0
inter_unit_spacing 3.0
priority 1.0
end_block

;; Archers, right
begin_block 2
min_units 1
max_units 3
unit_type ranged_missile_infantry 1.0
default_melee_state fire_at_will_and_defend_and_skirmish
unit_density close
min_unit_width 40
max_unit_width 40
block_formation column
block_relative_pos 0 2.0 0.0
inter_unit_spacing 3.0
priority 1.0
end_block

;; Generals unit, in center behind
begin_block 3
min_units 1
max_units 1
unit_type general_unit 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 -12.0
inter_unit_spacing 2.0
priority 1.0
end_block

;; Dummy block
begin_block 4
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 3 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block


end_formation
This formation is for an army of 2 to 6 archers together with a general, though it could just as well be used for say a single archer, or even a single general, but that depends on the other formations you have in your formations file.
The archers will deploy in 2 columns and have a gap in between to allow a potential general, possibly heavy cavalry, to freely charge forward.
Because of the last block this formation is enough to prevent any issues with deployment as the game always is allowed to put men somewhere in the formation, wich I will explain a bit better later on in the guide.
In game this will look like so;
https://img252.imageshack.us/img252/7200/nieuwbitmapafbeelding2vd2.th.jpg (https://img252.imageshack.us/my.php?image=nieuwbitmapafbeelding2vd2.jpg)

Spans is to create a connector between unit-blocks wich is basicly so you can create a wider range of formation-looks.
Most of the time the spans-blocks wont be needed but sometimes they can be very usefull, for instance when you have 2 lines of infantry and want cavalry to deploy at a certain distance from the tip of a flank, you could make the formation in fixed sizes so you know where to deploy the cavalry, but you can also connect both lines and know for sure the cavalry will deploy at a certain distance of the flank no matter how much men are in first or second line as the spans command creates a rectangulair block around the units it connects and so makes boths lines are the same size for deployment purpose.
In other words, the spans command allows you to create an other point of refrence based upon other blocks.
You can put from 1 to currently I know for sure 10 blocks in each spans, but this may just as well be double that or even more, though I doubt you'll ever need it.

You could use a spans command/block like in the following formation.
Here you have 2 lines of precursor infantry, not one I would use but it illustrates the command well.

begin_formation ai_legion_smallcavalry
attack
defend
ai_priority 1.0

;; Legions, first line
begin_block 0
max_units 8
unit_type light_pilum_infantry 1.0
default_melee_state fire_at_will
unit_density close
min_unit_width 20
max_unit_width 20
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 10.0
priority 1.0
end_block

;; Legions, second line
begin_block 1
max_units 6
unit_type heavy_pilum_infantry 1.0
default_melee_state fire_at_will
unit_density close
min_unit_width 20
max_unit_width 20
block_formation line
block_relative_pos 0 0.0 -12.0
inter_unit_spacing 12.0
priority 1.0
end_block

begin_dummy_block 2
spans 0 1
end_dummy_block

;; Cavalry, right flank .. AI loves cav. on right!
begin_block 3
max_units 2
unit_type heavy cavalry 1.0
unit_type light cavalry 1.0
unit_density close
block_formation line
block_relative_pos 2 24.0 -12.0
inter_unit_spacing 2.0
priority 0.6
end_block

;; Dummy block
begin_block 4
unit_type any 0.1
unit_density close
block_formation line
block_relative_pos 2 0.0 -12.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
As you can see the first block would form a line of only light precursor units, and than a second line of heavy precursor units.
You dont know the exact army-composition when using this formation so if you want to include cavalry you shouldnt deploy it like close to the first line's flank as when the second line is larger you may end up with 2 units crossing each other, deploy it on the flanks of the second line and you may end up deploying it behind the first line.
Using the spans command will make the spans block form a rectangulair block in such size the connected blocks fit in it, like for the above formation this may illustrate it even beter;
https://img512.imageshack.us/img512/2910/nieuwbitmapafbeeldingre1.th.jpg (https://img512.imageshack.us/my.php?image=nieuwbitmapafbeeldingre1.jpg)


-The unit blocks
The unit-blocks are the things that form the actual formation, they are the things that make armies look different from one an other and they are the things you can actually see on the battlefield.
This is where the modding actually starts ....

To start with I'll show you an example of the most basic of unit-blocks, the block I refer to as "any square" or "dummy block", wich I use to close each and every formation;

begin_formation ai_dummy_formation
attack
defend
ai_priority 1.0

;; Dummy block
begin_block 0
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 0 0.0 0.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
This is a perfectly usable formation, beter yet it basicly is the same thing as the "single line" formation you have when using the formation-buttons.
This is also the most basic of formations you must have in your formations_ai file, have this formation tucked away somewhere at the bottom your formations file and any army can deploy, preventing problems where the game isnt able to find an apropriate formation for the army.

The commands ordered as they should be used within a unit-block;
Red -> required
Black -> optional

begin_block #
This command will start/open an inidividual unit-block, it needs to be numbered sequentially starting from 0. (though note that dummy-blocks count here as well, as you see in the above archer-formation)


min_units 1
max_units 2
You can express a prefrence by telling a block it can not hold less or more than a specified number of units, though do note that if no formation is present that can hold less or more numbers than specified the game can "force" when into a block with very unrewarding results. Make sure that when say you limit a formation of infantry at 8 units that you have or an "any square" at the end of the formation or an additional formation that can hold more than 8 units infantry, you may want to than give 9 as minimum if wanted as an army upto 8 is already covered by the previous formation limited at 8.


not_general
This allows you to prevent a generals unit to placed in the unit-block, do note that the general_unit unit type tag means the unit holding the commanding officer, it does not have to be a family-member.

Care should be taken when you use this command as it can cause a formation to not properly deploy if incorrectly used.
A way you should not use the not_general is by using it on each blok but the first, as when an army deploys often the game deploys the general as 2nd or later unit, wich could mean the first block could already be filled. I find it hard to explain properly, so I'll try and illustrate it a bit by using an example.

This formation will most likelly put your general in the "any square" if you use it with 2 or more heavy cavalry, or in the first block if used by itself;

begin_formation ai_small_cavalry
attack
defend
ai_priority 1.0

;; Cavalry, first line
begin_block 0
min_units 1
max_units 1
unit_type heavy cavalry 1.0
unit_density close
min_unit_width 20
max_unit_width 20
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 2.0
priority 1.0
end_block

;; Cavalry, second line
begin_block 1
not_general
unit_type heavy cavalry 1.0
unit_density close
min_unit_width 20
max_unit_width 20
block_formation line
block_relative_pos 0 0.0 -12.0
inter_unit_spacing 2.0
priority 1.0
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 1 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
It will deploy the first unit, not the general in the first block wich than is filled cause of the max_units of 1, than it gets to deploying the general wich it wants to deploy in the 2nd block, but it cant cause of the not_general command, so it gets placed in the last block, the so called "any square".

Same formation, but now it will work;

begin_formation ai_small_cavalry
attack
defend
ai_priority 1.0

;; Cavalry, first line
begin_block 0
max_units 1
unit_type heavy cavalry 1.0
unit_density close
min_unit_width 20
max_unit_width 20
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 2.0
priority 0.1
end_block

;; Cavalry, second line
begin_block 1
not_general
unit_type heavy cavalry 1.0
unit_density close
min_unit_width 20
max_unit_width 20
block_formation line
block_relative_pos 0 0.0 -12.0
inter_unit_spacing 2.0
priority 1.0
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 1 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
If you look at the first block and take notice of the blocks priority you'll see I've lowered it drasticly, also the min_units command is removed so the game isnt so driven on filling the block.
The game will place the first unit in the 2nd block, eventually deploy the general in the first block as it isnt allowed in the 2nd, than fill the 2nd block with the rest of the units.
Do note that this particular formation will potentially start deploying the general in the "any square" if the army growns beyond 10 units as the difference in block-priority will make for a difference of roughly 9 to 10 units.
Though its unlikelly for the general to be deployed late, I've usually noticed it as being deployed as 2nd unit if used in different blocks.

Dont let this command put you down, when an army doesnt deploy the general properly in a formation where you dont want to force the general in a specific block or only if its of a specific unit-type, often a slight tweak in block-priorities can make it work, sometimes changing the order of blocks can.
There is at least no problem with the command itself, it just works a bit difficult. Take a look at the very first formation-example in this guide, wich I use for family in my game, it "guides" the general in the center-block by using a combination of min_units, max_units, block-priority and the not_general commands.


unit_type any 0.1
This tells wich unit type is allowed to be deployed in this specific block and with what priority we want this unit in the block. Do note that if you give a block say first light infantry with prio 0.1 and than heavy infantry with 1.0, ofcourse the heavy infantry would count more but if there is plenty of light infantry the block will first be filled with light infantry, dont want this than start with heavy infantry and end with light infantry, this way the block would only be augmented with light infantry if needed/desired.
The unit types that can be used can be refrenced to by settings within the EDU* file, often by using the "category" tag in EDU (like; infantry or cavalry), or a combination of "category" and "class" (like; light infantry or heavy infantry).
But it can also refer to some abilties the unit has, like a formation (like; phalanx or non_phalanx_spear), or an attribute (like; chanting_screeching)
You can see the tags you can use by looking at the vanilla files, as far as I know they use each type, at least each type I know of.


default_melee_state fire_at_will_and_defend_and_skirmish
Allows you to effectivly press up to 3 of melee buttons for the AI.
When armies are deployed certain units get certain melee states as part of a hardcoded routine, like archers start with fire at will and skirmish enabled. When you use the default_melee_state command within a blok you will override these hardcoded routines, meaning if you tell an archer to fire_at_will it will no longer skirmish, tell it to defend and it will no longer fire_at_will or skirmish. So to get an archer to do the things it usually does but also use a defensive stance you'll need to use the combination fire_at_will_and_defend_and_skirmish, however note that in this particular case it will also enable special ammo if the unit has it. However also note that certain settings will be overriden by the game as battle evolves, like you probably have seen archers start firing normal arrows but later on fire flamming arrows and/or the other way around.

This also means you can disable all hardcoded melee states by using a non-existing flag when an army deploys, like the following used on archers make them hold fire and stand ground;

default_melee_state dummy
or this would do the same;

default_melee_state anyone_home
etc etc ...

You should however be very carefull in using the defend as it can not be disabled, nor does the AI disable it during battle, meaning once set even in an attack units keep their defensive stance. (Yet I can help feel a defensive stance is a good thing on an archer, you dont want it to melee or pursue routers imo.)
An other thing you should note is that the default_melee_state does not seem to work (properly) in the players version of the file. (differences between the 2 will be highlighted later on)

It seems though, but this is pretty much impossible to know for sure, as you cant see it in battle, if the fire_at_will command stays active on the AI or if they may disable it as battle evolves, skirmish on the other stays enabled once set like defend does, but can be disabled by giving an other command.


unit_formation square
unit_formation phalanx
unit_formation wedge
Potentially a usefull command, though I can help ignoring it for my personal formations.
It should allow you to put units in a specific unit-formation, wich in the case of the 3 above mentioned work, but have no use on anything else than phalanx-units or wedge-capable cavalry, I havent used them nor does the vanilla formations file, though I guess we all know the AI uses these unit-formations so you dont need to make a phalanx-unit form into a phalanx, but it could augment its behaviour, than again it may also lock the unit to that unit-formation.
The testudo formation doesnt work, if you try to deploy a unit with the testudo formation you will get an immediate CTD, the AI also rarelly forms it and often at the wrong time as well, be glad it does as units will hardly ever move through a wooden gate when in testudo!
(Though presents you with a great way to research infantry behaviour as it presents you with a very hard result if the testudo is triggered :D)


unit_density close
unit_density loose
Allows you set the density of the units in the block, where the options are;close or loose.
These density settings refer to the "formation" lines in the EDU* file, it seems however that the AI in a battle where it attacks can override this setting if set to loose and make the unit take the close density.
This however is hard to test as in battle the game eventually can form additional smaller formations by picking units from the main-formation, its these smaller formations, often single units, that in late battle can behave rather independend, wich might be cause these formations could deploy in a defend formation instead of an attack formation, but it may just as well be the engine dictating density.


min_unit_width 20
max_unit_width 20
With these 2 commands you can influence the units independend formation by streching it or making it deeper, pretty much needed if you want AI armies to strech out a bit if they sally-out, as the streets narrows the unit-formations wich will stay if not forced wider for the attack.

Darth Vader speaks of "min_unit_depth" and "max_unit_depth" but I cant even get the game to load if even just a single instance of the command is used.


block_formation line
block_formation column
block_formation square
These are the 3 block-formations the game knows, this command allows you to give each block an individual formation of its own.
Yet again its a rather pointless command in general, 90% of the time you'll use the line block-formation wich places units side by side. Sometimes the column can be interesting wich places units behind one an other. But square is rather useless as it has some pretty weird way of deploying units, I do use though for the "any square" as it allows for the most concentrated formation within a single unit-block.


-Normalised positioning
This is a bit of a special part of the guide as these commands work a bit different than the other block-commands, read it than forget it, the following commands are a royal pain in the behind!

When you want to position an army on the battlefield you have 2 methods you can use, you can use the command;

block_relative_pos 0 0.0 0.0
or the combination of commands;

normalised_pos 0.0 0.0
normalised_rot 0.0

The first single command is much easier in its use and the only one I've seen used in any formation I've come across, wich isnt hard to explain as the 2nd method is very hard to use and generally not advised to be used! This is also the reason I'll give you an example of the use of this command but throughout the guide will use the first method.

You should take note of the fact that once you choose a method your entire formation needs to made using this method, meaning you cant give the 1st line a rotation with the normalised_rot command and than position the 2nd line behind it using the block_relative_pos command. The game will not load if you do not respect this, as an show_err error-report will tell you.

The mimimum values of the command are;

normalised_pos 0.0 0.0
normalised_rot 0.0
the maximum values are;

normalised_pos 1.0 1.0
normalised_rot 360.0

I wont even try to explain the command as I hardly understand it myself, but I will show you a few examples of how the command can be used.


begin_formation ai_normalisedstuff_defend
defend
ai_priority 3.0

;; First line of infantry
begin_block 0
max_units 3
unit_type heavy_pilum_infantry 1.0
default_melee_state fire_at_will_and_defend
unit_density close
block_formation line
normalised_pos 0.0 0.0
normalised_rot 0.0
inter_unit_spacing 6.0
priority 1.0
end_block

;; Second line of infantry
begin_block 1
max_units 2
unit_type heavy_pilum_infantry 1.0
default_melee_state fire_at_will_and_defend
unit_density close
block_formation line
normalised_pos 0.0 0.0
normalised_rot 0.0
inter_unit_spacing 6.0
priority 1.0
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
normalised_pos 0.0 0.0
normalised_rot 0.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
Look where the armies are deployed relative to the center of the deployment-square;
https://img262.imageshack.us/img262/5906/nieuwbitmapafbeelding2xi5.th.jpg (https://img262.imageshack.us/my.php?image=nieuwbitmapafbeelding2xi5.jpg)

and;

begin_formation ai_normalisedstuff_defend
defend
ai_priority 3.0

;; First line of infantry
begin_block 0
max_units 3
unit_type heavy_pilum_infantry 1.0
default_melee_state fire_at_will_and_defend
unit_density close
block_formation line
normalised_pos 0.6 0.6
normalised_rot 45.0
inter_unit_spacing 6.0
priority 1.0
end_block

;; Second line of infantry
begin_block 1
max_units 2
unit_type heavy_pilum_infantry 1.0
default_melee_state fire_at_will_and_defend
unit_density close
block_formation line
normalised_pos 0.0 0.0
normalised_rot 45.0
inter_unit_spacing 6.0
priority 1.0
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
normalised_pos 0.0 0.0
normalised_rot 45.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
Again the army is centered in the square, but it does get a rotation;
https://img338.imageshack.us/img338/6765/nieuwbitmapafbeeldingpp2.th.jpg (https://img338.imageshack.us/my.php?image=nieuwbitmapafbeeldingpp2.jpg)

Dont use the same values in the normalised_pos command except for 0.0 0.0, if you do the game seems to freeze if the formation is used.


block_relative_pos 0 0.0 0.0
I'll add this command as a required command and ignore the above mentioned positioning command as 1 of them is required and this one is the most commenly used command.

The command allows you to put a unit in the formation in refrence to an other unit. To take the explaination from the formations_ai file itself; b x z (x,z) position relative to formation block b.

If you dont use one of the two axis the blocks use the same center for those axis, as illustrated by the following 3 formations that all 3 are the same except for how the cavalry is positioned to the infantry;

begin_formation ai_position_defend1
defend
ai_priority 2.0

supported_factions romans_julii

;; Legions
begin_block 0
unit_type heavy_pilum_infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 12.0
priority 1.0
end_block

;; Cavalry
begin_block 1
unit_type heavy cavalry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 -12.0
inter_unit_spacing 2.0
priority 0.9
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 1 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
https://img520.imageshack.us/img520/6738/82868325nr6.th.jpg (https://img520.imageshack.us/my.php?image=82868325nr6.jpg)


begin_formation ai_position_defend2
defend
ai_priority 2.0

supported_factions romans_brutii

;; Legions
begin_block 0
unit_type heavy_pilum_infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 12.0
priority 1.0
end_block

;; Cavalry
begin_block 1
unit_type heavy cavalry 1.0
unit_density close
block_formation line
block_relative_pos 0 -12.0 0.0
inter_unit_spacing 2.0
priority 0.9
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 1 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
https://img260.imageshack.us/img260/3811/49035997oo4.th.jpg (https://img260.imageshack.us/my.php?image=49035997oo4.jpg)


begin_formation ai_position_defend3
defend
ai_priority 2.0

supported_factions romans_scipii

;; Legions
begin_block 0
unit_type heavy_pilum_infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 12.0
priority 1.0
end_block

;; Cavalry
begin_block 1
unit_type heavy cavalry 1.0
unit_density close
block_formation line
block_relative_pos 0 -12.0 -12.0
inter_unit_spacing 2.0
priority 0.9
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 1 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
https://img262.imageshack.us/img262/9753/71989225yj7.th.jpg (https://img262.imageshack.us/my.php?image=71989225yj7.jpg)

As you can see each first block is refrencing itself, this is how you should start the first block or expect weird behaviour. You can also leave the x, y axis values for this first block at 0.0 0.0, there is no difference in army deployment or behaviour if you give it some other values.


inter_unit_spacing 2.0
This command does exactly that what is says, it sets the spacing in between units.
To illustrate the command a bit some examples of a line of units with a different inter_unit_spacing;
6 meters;
https://img260.imageshack.us/img260/3504/nieuwbitmapafbeeldingau2.th.jpg (https://img260.imageshack.us/my.php?image=nieuwbitmapafbeeldingau2.jpg)

12 meters;
https://img340.imageshack.us/img340/712/nieuwbitmapafbeelding2vt4.th.jpg (https://img340.imageshack.us/my.php?image=nieuwbitmapafbeelding2vt4.jpg)

18 meters;
https://img527.imageshack.us/img527/2968/nieuwbitmapafbeelding3qv5.th.jpg (https://img527.imageshack.us/my.php?image=nieuwbitmapafbeelding3qv5.jpg)

When you make your formations I advice to make them for individual scalings, as this allows you to make things relative to one an other. I'll try and explain what I mean using my own game, I know my legions come with 200 men and have a formation setting in the EDU* file of 0.8, 1.2 when in dense formation, this means that if I deploy these men at 25 men width they take up roughly 20 meters (25*0.8) wich will mean they are roughly 9.6 meters deep (8 lines *1.2), knowing that my men will be 20 meters wide with 25 men/line will help me visualise my formation when I build it and dont start making "out of balance" formations, for instance by setting a spacing of 200 meters, nor one of 6 meters with the idea it can allow a unit to charge through it ...


priority 1.0
The last command within any unit-block is the block-priority, this priority is to dictate an importance of the unit-block within the formation.

Like in the following formation the first line will fill up with 10 units before deploying a unit in the 2nd line, the max_units command prevents unit #12 to again be deployed in the first line, take note of the block-priorities;

begin_formation ai_priority_defend
defend
ai_priority 2.0

;; Legions
begin_block 0
max_units 10
unit_type heavy_pilum_infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 12.0
priority 1.0
end_block

;; Legions
begin_block 1
unit_type heavy_pilum_infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 -12.0
inter_unit_spacing 12.0
priority 0.1
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 1 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation

Now there is an other way you can "play" with priorities, let me illustrate with an example.
I will show you 2 formations that both have a line of infantry and a line of cavalry, now I want 1 to be used if the army is mostly infantry and 1 to be used if the army is mostly cavalry, look how I switch the priority of blocks within the formation without changing the priority of the formation itself.

The first formation, the infantry-block has a high priority and the cavalry a bit lower;

begin_formation ai_priority_infantry
defend
ai_priority 2.0

;; Legions
begin_block 0
unit_type heavy_pilum_infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 12.0
priority 1.0
end_block

;; Cavalry
begin_block 1
unit_type heavy cavalry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 -12.0
inter_unit_spacing 2.0
priority 0.6
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 1 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
When I now deploy an army with clearly more infantry than cavalry the formation will be selected by the game;
https://img339.imageshack.us/img339/6214/nieuwbitmapafbeeldingjc8.th.jpg (https://img339.imageshack.us/my.php?image=nieuwbitmapafbeeldingjc8.jpg)

Here I changed the block-priorities so that the cavalry has the high priority and the infantry the low priority;

begin_formation ai_priority_cavalry
defend
ai_priority 2.0

;; Legions
begin_block 0
unit_type heavy_pilum_infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 12.0
priority 0.6
end_block

;; Cavalry
begin_block 1
unit_type heavy cavalry 1.0
unit_density close
block_formation line
block_relative_pos 0 -24.0 -12.0
inter_unit_spacing 2.0
priority 1.0
end_block

;; Dummy block
begin_block 2
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 1 0.0 -18.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
Now deploying an army with clearly more cavalry will select this formation over the previous one, like shown here;
https://img152.imageshack.us/img152/1707/nieuwbitmapafbeelding2ca3.th.jpg (https://img152.imageshack.us/my.php?image=nieuwbitmapafbeelding2ca3.jpg)

You can see that I deployed both armies at the same time, meaning both the above formations where present in my formations_ai file when I deployed these armies and you can see how the game can be influenced towards liking specific formations simply based on the block-priorities.
I suggest you try and guide the game into picking the proper formations for the specific armies by tweaking block-priorities and at first leaving formation-priorities the same for the same purpose of formations, this so you express a clear prefrence towards the game, saying it what formation should be used with say an infantry-rich army.


end_block
The command used to close a unit-block, doesnt take any input from you it just is a tag to tell the game the unit-block is finished and can be closed.



-Formation for a full Roman army
To finish the _ai part of this guide I'd like to show you how a relativly simple formation for a full Roman army could like;

begin_formation ai_full_legion
attack
defend
ai_priority 1.0

;; First line of infantry
begin_block 0
unit_type light_pilum_infantry 1.0
unit_type heavy_pilum_infantry 0.9
default_melee_state fire_at_will
unit_density close
block_formation line
block_relative_pos 0 0.0 0.0
inter_unit_spacing 12.0
priority 1.0
end_block

;; Second line of infantry left
begin_block 1
max_units 1
unit_type heavy_pilum_infantry 0.9
unit_type light_pilum_infantry 0.1
default_melee_state fire_at_will
unit_density close
block_formation line
block_relative_pos 0 0.0 -12.0
inter_unit_spacing 12.0
priority 1.0
end_block

;; Spearmen
begin_block 2
unit_type spearmen 1.0
unit_density close
block_formation line
block_relative_pos 1 0.0 -12.0
inter_unit_spacing 18.0
priority 1.0
end_block

;; Achers, behind the other infantry
begin_block 3
unit_type ranged_missile_infantry 1.0
default_melee_state fire_at_will_and_defend_and_skirmish
unit_density close
block_formation line
block_relative_pos 2 0.0 -6.0
inter_unit_spacing 3.0
priority 1.0
end_block

;; Elephants
begin_block 4
unit_type elephants 1.0
default_melee_state fire_at_will
unit_density close
block_formation line
block_relative_pos 3 0.0 -6.0
inter_unit_spacing 12.0
priority 0.8
end_block

begin_dummy_block 5
spans 0 1 2 3 4
end_dummy_block

;; Siege equipment
begin_block 6
unit_type siege 1.0
default_melee_state fire_at_will
unit_density close
block_formation line
block_relative_pos 5 0.0 -12.0
inter_unit_spacing 6.0
priority 0.2
end_block

;; Generals unit
begin_block 7
min_units 1
unit_type general_unit 1.0
unit_density close
block_formation line
block_relative_pos 6 0.0 -12.0
inter_unit_spacing 12.0
priority 1.0
end_block

;; Cavalry, left wing
begin_block 8
unit_type heavy cavalry 1.0
unit_type light cavalry 0.9
unit_density close
block_formation line
block_relative_pos 5 -24.0 -6.0
inter_unit_spacing 2.0
priority 0.9
end_block

;; Cavalry, right wing
begin_block 9
unit_type heavy cavalry 1.0
unit_type light cavalry 0.9
unit_density close
block_formation line
block_relative_pos 5 24.0 -6.0
inter_unit_spacing 2.0
priority 0.9
end_block

;; Dummy block
begin_block 10
unit_type any 0.1
unit_density close
block_formation square
block_relative_pos 7 0.0 -12.0
inter_unit_spacing 2.0
priority 0.1
end_block

end_formation
This is enough to get the Romans in vanilla to give you a nice fight, at least better than the current "single line attack", imo.
Make more variations for more specific armies and use more of the optional commands/settings and going to battle might become a nightmare .... :2thumbsup:


*EDU => export_descr_units, check the EDU-Guide (https://forums.totalwar.org/vb/showthread.php?t=88859).

Red Spot
12-11-2007, 01:41
A bit of additional information


-The unit_type
The unit_types that are used in the vanilla formations_ai file.


any

infantry
light infantry
heavy infantry

pilum_infantry
light_pilum_infantry
heavy_pilum_infantry

spearmen
spearmen infantry
non_phalanx_spear
phalanx

missile infantry
skirmish infantry
ranged_missile_infantry

cavalry
spearmen cavalry
heavy cavalry
light cavalry

missile cavalry
skirmish cavalry

elephants
heavy_chariots
handler
siege

general_unit

chanting_screeching
swimming

carrying_siege_engine ram
carrying_siege_engine ladder
carrying_siege_engine tower

Red Spot
12-15-2007, 14:09
The players formations


I'll try to highlight some of the differences between the human and ai version of the formations file here.

First of all in the human version you can not add an unlimited amount of formations, it holds a formation for each of the formation-buttons and 1 additional formation.

-The formation names
As far as I know the formation-buttons are linked to formations with a specific name, where the file uses the following names;


simple_line
ordered_single_line
simple_double_line
ordered_double_line
ordered_triple_line_1
ordered_triple_line_2
ordered_triple_line_3
column

unit_selection
The last formation is used for when you move a selection of units, likelly only when you do so with a selection of ungrouped units.


-Purpose and priority
The purpose and priority are no longer used, wich I guess is rather obvious, you dictate purpose and priority :)

-default_melee_state
I can vaguelly remember that it did work but every test I've latelly run with default_melee_state flags give me as result that the command does not work in the human formations file, or at least not in each of the formations.
I'll be doing a few more tests on the subject just to be sure it doesnt work in any formation and on no unit type.


-Couple of notes on player formation
When you do make custom player/human formations you can use commands like min_units and max_units and if the formation doesnt fit the game may .. er .. stretch your formation, like if you say the first block is the only block that can contain infantry but also limit it at 3 units than use the formation for an infantry army with more than 3 units the game may simply push 4 or more units in that block. Cause of the lack of different formations for the same button based on army-compositions makes it much more of a task to make proper use of the block-priority.

You may also want to ask yourself how far you want to go with it. As it is you cant make the formations faction-specific, trust me, I've tried :) What you can do is make different files for different factions so the player just has to swap the file.
Though there are methods that allow a similair setup within a single file.
When you for instance want to make a 3-line formation of;
infantry
archers
cavalry
But you want to do a bit more than vanilla with "infantry" in first line you can for instance split the first line up into 3 blocks, use the center block for say;
heavy infantry
than the outer blocks for;
light infantry
after that use a spans-block to connect the 3 blocks and put the archers behind it and possibly repeat a similair setup for cavalry.
This way Romans keep their heavy precursor units in center and the light on the flanks, the Greek will put Spartans and armoured hoplites in center and the unarmoured phalanxes on the flanks, barbarians ...... hope you get my point, where I advised against "general" formations in the ai version I do advise so in the player version, for ease of use, after all these are the formations you will use yourself.

max_minimod
12-16-2007, 20:50
Hi, I'm doing a RTW/BI Viking mod and I wonder if its possible to put the standardbearer and the officers of an warband or army in front (or first line) of the troops, but retrait them to second (or last) line when battle rages on.

I try to reach a bit more variations of clothes/shields with it.
Its important for our mod, cause the 'clonewarriors' of RTW sux extremly in a darkage mod (there may have been very few 'uniforms' that time, fighter collected often from the fields and there was not much kings that could afford uniforms for their troops anyway.

Can you point me at scripts/files need to edit for it?

Red Spot
12-17-2007, 06:53
you cant really, you can have a specific unit deploy up front to stay there and pushed in 2nd line for an attack, but it will stay on 1st line during the defence and you cant make it switch positions during battle.
Keeping it on 2nd line has the potential that the game has other plans for the unit and keep its back a bit to let it run around the fight and flank the enemy, but this isnt something you can trigger or dictate, at most influence a bit.

Also note that moving entire lines of foot-soldiers isnt something I recommend as variantion between an attacking and defending army, the AI isnt to smart with walking up to an enemy army and large changes in formations leave armies open to be cut up by cavalry and archer-rich armies.


G

max_minimod
12-17-2007, 16:04
Sad to hear that, but thank you anyway!
I will try to put them in the second line then.
What files define the officer position of an army?

Red Spot
12-20-2007, 21:55
Not really sure I understand what you mean ...

Do you mean a unit with the general? Or the officers within a unit??

As the first option is basicly what this guide is (partially) about, and the 2nd option is completelly unrelated to this guide ...

Anyway, generals are positioned within the formation using the unit-type "general_unit", and officers will always be on the left of a unit, nothing you can change about that
(though I still recall, and intend to check it out, that the Senate actually has its officers on the right, possibly only with sieges, "somehow" I've come to recall so though I'm unsure if I'm correct or not)


G

max_minimod
12-30-2007, 09:16
and officers will always be on the left of a unit, nothing you can change about that

Ah, dang, thank you anyway.
Sorry for I'm being not precise, yes I ment the 'officers'.
(or do you see a way to add more than one different models to a unit by "general_unit" ways?)
I even thought about an 'animal-unit' way, but that would have a lot other bad side effects too.

Red Spot
12-30-2007, 20:11
Well it all depends on what you intend on achieving ..
(I guess I dont fully understand the question ...)


the tag "general_unit" doesnt have anything to do with a specific model, it is a tag for the "unit that also has the general in it" wich can be any unit, usually the first unit in an army will be bumped to "general" when there is no family-member in the army ..

you can basicly make each and every unit into a family-member of into an officer, but they will always come on left side of the unit ...

you can make 2 types of identical armies and tell the game 1 is light infantry and the other is heavy infantry, than give only the heavy officers and tell the formation to deploy heavy infantry on the 2nd line, wich will at least keep your officers slightly back, but they will still be on the left of the unit.

you can give no army officers and than create a new unit called "officers" or "commanding unit" or whatever and add all your officer-look-a-likes in that unit to give an impression that the officers are grouped and deployed behind an army ...

you can ... etc etc etc ....


G

max_minimod
01-08-2008, 20:20
Well it all depends on what you intend on achieving

I thought of ways to have something MTW2 has, but on the old RTW/BI engine.
In MTW2 not every soldier looks like the other in the unit.
There are variations of helms, uniforms, outfit.

So I thought to mix the officers (who have different outfit) into the 'clonewarriors' unit, or have them in front.
But thank you told me, its not possible, the officers (and the general/family member) are always on the side. :embarassed:

Red Spot
01-09-2008, 23:48
Ahhh! ... than say so .. :D

you can do such a thing within Rome, though you're effectivly cutting down the number of units in an army ..

what you can do is set the unit-formation (the one in EDU) to be a bit looser (or leave it at "vanilla" settings), than create a formation that deploys 2 units on top of one an other with a small ofset (or not as the game will "push" them in place anyway)

something like;

;;; dummy to use for alligning units
begin_dummy_block 0
spacer 0.0 0.0 1 1
end_dummy_block

begin_block 1
unit_type infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 -0.2 -1.0
inter_unit_spacing 3.0
priority 1.0
end_block

begin_block 2
unit_type infantry 1.0
unit_density close
block_formation line
block_relative_pos 0 0.2 -1.0
inter_unit_spacing 3.0
priority 1.0
end_block

The visual appearance will be the same when an army is deployed or when the AI marches it, though it will break the army up and let units attack individually in the end and it probably doesnt work in siege battles ...
(I've got something like this as a crude test for barbarian formations that I dont want to be looking very organised, more like a mob of very aggressive men)


G

max_minimod
01-15-2008, 15:02
thank you, I will try that :yes: