Results 1 to 16 of 16

Thread: Modifying Formation AI version 2

  1. #1

    Default Modifying Formation AI version 2

    “Modifying Formation AI version 2


    This is the continuation of my tutorial about the manipulation of this valuable and peculiar file of descr_formations_ai.txt” based on the root directory of RTW install folder (…\Activision\Rome - Total War\Data\descr_formations_ai.txt).
    This file is responsible enough to exploit the advantages and disadvantages of the internal hard coded AI programmed by the coders of CA. It defines the system that the AI will use to fulfill the battlefield roles which will be requested to query in the middle of the battle vs a human or AI opponent. This file together with a lot of other techniques that can be used to change some parameters in other files will decisively change the AI behavior to such extent that we can virtually claim that we can manipulate the hard coded AI in a large proportion.(If this is the brain, then we control the eyes, feet, hands, torso so that is exploited correctly). Nevertheless, this file alone can enormously enhance or deteriorate things very much so it needs extra caution when someone tries to “play” with it. I decided to issue this tutorial now because it is very possible that I will retire from modding business for a long time due to some recent events which will drag my attention more in the near future. So you can use this as part of my legacy to my TW modding past. I have to say that the community’s appreciation is that which motivated me more to produce as much more quality work as possible than do it as a frivolous way to fill my time.

    I will not mention the basic knowledge needed to modify the formations since these are mentioned in my first tutorial a long time ago. What I will do is to describe my main thought and perception of programming the formation AI and the most important tricks that contribute to a radical enhancement of AI behavior as stated and appreciated by the majority of the community.

    1st Chapter (Summary of Formation Roles)


    CA hard coded battlefield AI uses a mix of internal commands that are triggered when a certain role is summoned which is based in the formations settings:

    Battlefield Roles

    defend: This role is used by the AI to defend against an opponent during field battles. Also very importantly it is used for the 1st deploy of human/AI player in the battlefield. So if this is messed up, then the human and AI player starts messed up as well. When in campaign you will see it in 1st deploy and when human player attacks AI. Usually this formation role is manipulated statically by the AI. It will place it somewhere on the battlefield with the most desirable ground advantage and wait until opponent is near to interact with hard coded routines.

    attack: This role is used by the AI when it attacks an opponent. It is not seen clearly in the battlefield because AI has 1st deploy with defend role and instantly swaps to this in order to attack. And the destination and orientation of the formation is decided and changed a lot of times during battles. This role is used dynamically by the AI which means you can never really see it statically but rather as a “base” of operations for the units which will interact according to opponent’s movements and ground benefits.

    attack/defend Multi role: This role is also important for the AI because for some reason it is used for reinforcement armies. So when they enter the battle they instantly change to this. If it is not available, there is a CTD. If it is wrongly modded, the reinforcements are idle. And not only this. If the priority is high enough comparing to the previous isolated roles, it will be also used for the respective roles mentioned above . So someone must be really careful how he mods this multi role in order not to surpass the previous roles which then will be seldomly used.

    pursue: This role is used by the AI to exploit its aggressive attack patterns when it self cuts its core formation to small groups. Just like a human player groups his own troops types. It is not used necessarily so it is not causing CTDs even if this role is out of the formation script. In first patches I have claimed that this command was having bugs so my first editions of formations had deleted this role completely. CA uses it as a multi role Attack/pursue. The internal hard coded commands for this role press the AI for very aggressive movements.

    march: This role is used by the AI mostly in town battles and in small groups. It cannot be seen as a whole formation so one must fantasize it how it works in the battlefield. It is usually swapping between attack/march, defend/march when an AI group is marching in the road tracks. It is good to know that this formation is very vital in siege battles and with careful perception there can be achieved envelopment.
    Also if used in mixture with other roles it forces AI for a more mobile strategy.


    Special Siege Roles


    standard_siege_attacker_deployment: This is the starting deployment for AI/Human armies which is used in coordination with the other role I describe below.
    That means this formation is not set alone but internally with the other role. Some troops carry the engines ahead, then some follow and then comes the internal relativity with the following role. The cavalry units mentioned in this code is deployed by default behind (if modded correctly) and will stay idle during the siege procedure.

    wall_assault_force : It usually decides the relativity and proximity of the reserve troops that will follow each siege engine so it is used in small group system. Cavalry must not be used here and by internal hard coded routines AI will never use it unless forced by code. If modded correctly there will be always sufficient troops behind each engine to support the attack and in the correct proximity.(Not too close to receive heavy bow fire, not to far to lose valuable time entering the siege engines)

    Special Bridge Roles

    crossing_assault_force: This is the most bugged CA role that was forgotten to be fixed in their last patch. It is used for the AI to deploy just before it attacks the opponent in the other shore of the bridge. It is not the formation that is buggy but the hard coded routines that correspond with it just after it successfully deploys. In plain words, AI presses all melee troops to cross the bridge except the projectile units mentioned in the following role I will mention. This is a pity because this causes stupid massing in the region of the bridge and boring bridge battles. In Shogun and medieval, bridge battles were my favorite. Now they are a boring nightmare. But…I found ways to enhance it as much as possible and will describe them later.

    crossing_assault_cover: This is used in coordination with the above mentioned role and divides the melee with the projectile units to be used here and in relativity with the first formation role. Hard coded AI will mostly ignore non projectile units to be used here even if coded. It is vital that this formation is modded correctly because then you will witness 2 frequent bugs. AI not firing and AI deploying seriously slow.

    crossing_block: This is used when AI defends a bridge. It is used in coordination with the next last role I will describe and the defend role I described above. Defend role is used firstly to place AI army in a proximity to the bridge. Then it interacts to the attack by grouping AI units with this role and the next. Just like a reserve system.

    crossing_defend: As I predefined above this role supplements the whole AI bridge defense system and is used internally and in coordination with the above role and defend by detaching missile units of the AI and attaching them to this formation and in relativity.


    It has to be clarified that the roles can be used in mixture freely to any formation. That means plainly to understand that you can fix only one formation and attach to it all the roles….the AI will use it!

    2nd Chapter (Darth Internal Formation Swapping System)

    After CA patch 1.3 there was available a powerful tool in the formation code which clearly moved the formation programming to another level. It was now possible to exclude factions from a certain formation and include only the desired. In other words, it was possible to use the command “supported_factions” to add into a formation usage the possibility only the factions mentioned in the code to be utilized. With this possibility we can isolate a faction to use only a certain desired strategy than randomly switch to generic formation roles according to AI internal perception of unit proportion types and roles. So by using this I created unique specialized formations with the following method:

    -Created a certain formation type according to a faction strength

    -I used the command “supported faction” to isolate the formation to be used only for this faction

    -Started to create specific role formations for each specialized occasion and again isolated each formation to be used only by the specific faction

    -Each unique formation role is a variance of the starting defend formation of the faction so that AI will not struggle to revert to very different positions when it needs to.

    -5 formation roles (Battlefield roles) cover all the needs of AI to use them in the middle of a battle and with this method you can witness real like effects such as spearmen infantry to come forwards to defend and then swap positions with axemen to begin their attack, archers to start behind and then move to the wings for flanking shots..etc.

    -Each formation set uses a special strategy according to Faction strengths and weaknesses. For example if a Faction has a strong roster of phalanx units, I create a special thick spear wall formation to utilize it effectively.

    -Also I use a central name for the formation set. That means each internal formation role will not use a different name but the same for each of the 5! I realized that the internal hard coded formation compiler is used more properly and groups each formation than use each one separately with a different name. Of course I cannot prove it but only empirically unless this is a probability conspiracy and my optimization tests were luckily better comparing to the different name system.



    Technical note:

    This is how it will look a whole set of formation code per faction

    begin_formation nameX
    march
    ai_priority xxx(will explain below)
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code)(Faction specific strategy)

    end_formation

    begin_formation nameX
    defend
    ai_priority xxx(will explain below)
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code)(Faction specific strategy)

    end_formation

    begin_formation nameX
    attack
    ai_priority xxx(will explain below)
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code)(Faction specific strategy)

    end_formation

    begin_formation nameX
    attack
    defend
    ai_priority xxx(will explain below)
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code)(Faction specific strategy)

    end_formation

    begin_formation nameX
    pursue
    ai_priority xxx(will explain below)
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code)(Faction specific strategy)

    end_formation
    Of course I use sometimes a variance in role mixture but the above is the core default process.





    The above mentioned summarized rules give roughly but also explanatory, the ideas behind the technique used to create specific characterization of a faction strategy. Of course there are many other techniques which will be mentioned below.

    The formation characterization grouping method mentioned above is also used similarly but not identically for the siege and bridge AI warfare:

    -For the siege battles I created strategies per culture so for example romans will preserve their maniple system when they siege as well, Asians will encircle the fortification more widely etc.
    Technical note:

    This is how a complete set of siege formation code per faction will look like:

    begin_formation nameX1
    standard_siege_attacker_deployment
    ai_priority xxx(will explain below)
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code)(culture based)

    end_formation

    begin_formation nameX2
    wall_assault_force
    ai_priority xxx(will explain below)
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code) (culture based)

    end_formation

    -For the bridge battles I use a hydrid of generic and specialized formation system. First of all I have created special assault code according to unit proportion type per AI army and then maintained the rest of the code generic.

    Technical note:

    This is how a complete set of bridge formation AI code will look like:

    begin_formation nameY
    crossing_assault_force
    ai_priority xxx(will explain below)
    ;supported_factions faction name1, faction name2, ….,faction nameN(Not used)

    …………….(code) (Generic)

    end_formation

    begin_formation nameY
    crossing_assault_force
    ai_priority xxx(will explain below)
    ;supported_factions faction name1, faction name2, ….,faction nameN(Not used)

    …………….(code) (For strong cavalry proportion)

    end_formation

    begin_formation nameY
    crossing_assault_force
    ai_priority xxx(will explain below)
    ;supported_factions faction name1, faction name2, ….,faction nameN(Not used)

    …………….(code) (For strong heavy infantry proportion)

    end_formation

    begin_formation nameZ1
    crossing_assault_cover
    ai_priority xxx(will explain below)
    ;supported_factions faction name1, faction name2, ….,faction nameN(Not used)

    …………….(code) (Generic)

    end_formation

    begin_formation nameZ2
    crossing_block
    ai_priority xxx(will explain below)
    ;supported_factions faction name1, faction name2, ….,faction nameN(Not used)

    …………….(code) (Generic)

    end_formation

    begin_formation nameZ3
    crossing_defend
    ai_priority xxx(will explain below)
    ;supported_factions faction name1, faction name2, ….,faction nameN(Not used)
    …………….(code) (Generic)

    end_formation

    3rd Chapter (Darth Formation Priority System)



    After the above mentioned explanation it will be now easier to describe a very vital secondary technique to create specific characterization of AI armies. I will describe the usage of the line “ai_priority” in the formation code. This gives ratio to the AI of the probability to use the respective formation mentioned. If the number is big, AI will more likely prefer to use it and the opposite. So if you give big numbers to certain roles and disfavoring the rest roles, you create a specific taste for the AI whether it will be “aggressive”, “defensive”, “balanced” etc. In order to do this you must place a “norm” to the internal swapping formation system. In other words there must be placed a specific number which then each specific role will divide it and take a respective piece of it. The role with the biggest piece will be the favored role.
    So what I did was to use as norm the number “1.0”.
    Then each of the 5 roles will use a proportion of it and create the effect of AI ratio strategy. For example, if I want to make AI to be too defensive I give to the ‘defend’ role the biggest proportion, when I want it to be more mobile I give to ‘march’ a good proportion and also include the ‘march’ role to some of the ‘attack’ or ‘defend’ or ‘pursue’ roles as a mixture etc.

    Technical Note:

    Now I will give the swapping code again but will include the priority specification system described in underlined bold.

    begin_formation nameX
    march
    ai_priority p1
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code) (Faction specific strategy)

    end_formation

    begin_formation nameX
    defend
    (march) ;optional

    ai_priority p2
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code) (Faction specific strategy)

    end_formation

    begin_formation nameX
    attack
    (march) ;optional

    ai_priority p3
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code) (Faction specific strategy)

    end_formation

    begin_formation nameX
    attack
    defend
    (march) ;optional

    ai_priority p4
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code) (Faction specific strategy)

    end_formation

    begin_formation nameX
    pursue
    (march) ;optional

    ai_priority p5
    supported_factions faction name1, faction name2, ….,faction nameN

    …………….(code) (Faction specific strategy)

    end_formation
    Where p1+p2+p3+p4+p5 = 1.0 (= norm)

    Important notes:

    -p4 must always be smaller than p1,p2 so as not to override them. But if you want it to override.(The mix mode is sometimes more effective for the AI) then it should be bigger.

    -The optional march mixture must be used with care and after tests since it creates a very undesired endless movement effect for slow heavy moving unit types such as greek_cities.

    -The norm can be any number although very big numbers may cause a more biased AI.

    -I use similar norm system for sieges (2 roles for sieges of 0.5 each)

    -I do not use norm for bridge AI but just a priority increment for desired strategy.(For example Bridge system has a set of 6 formations with 3 internal and 3 generic (described above). The 3 internal have slight difference between them with preference of the cavalry enveloping assault and the generic a more wide difference with preference to the defensive stance of covering.

    -Siege and Bridge formation priorities must be always >0.1 or else a CTD will occur in reinforcement battles.

    -I create also generic formations for all above mentioned roles with very low priorities so that if AI fails to swap into a priority system, it uses the generic and the game never CTDs.

    -Even the slightest mistake in priority numbers can cause undesired effects and a wasted effort of creating a formation that will be seldom or wrongly used.


    Some examples of characterization:
    In my DarthMod greek _cities setting, I force them to be extra defensive and slow moving with the values:

    p1=0.01, p2=0.92, p3=0.01, p4=0.05, p5=0.01 . (Notice their additive power = 1.0 =norm)

    The romans to be very maneuverable and enveloping with:

    p1=0.4, p2(march optional)=0.4, p3(march optional)=0.14, p4=0.05, p5(march optional)=0.01 .
    (Notice the march role added as mixture)

    and many infinite variances can really create a very unique system of AI forcing.


    4th Chapter (Darth Formation Coding Methodology)

    After describing the general and vital rules of the basic structure of a formation AI set it is now the time to describe the most important coding tricks that make the difference from the default and very plain AI coding that was firstly introduced. All the below mentioned are a product of a very hard and long effort of empirical testing and usage of rational thought about programming this internal CA code file. Still there may be some who will have objections of my statements so far and for those that will follow but I believe most of you will agree that it is difficult for me to fully describe a procedure that is accomplished with personal survey and not by usage of any CA tool or manual that would reveal the real truth behind these codes. So if I manage to convince you that the methodology firstly works in the battlefield as I assert, then I can be certain in a large proportion that the methodology I advise is of a rational explanation. So here above I start to describe one by one the most important features:

    -Darth Vertical offset forcing of formation: The AI is manipulating each formation in the vicinity of a “moving” template that has certain width and depth in most cases. That means that a formation has a certain limit as to where it can expand while it is deployed. The moving templates of the interacting AI armies are placed by the AI just like a “hex” system adjacent to each other so that the secondary AI interactions occur. With the offset system I control the proximity of each template so that these internal interactions are manipulated more effectively. By default, as it seems, CA has programmed that the interacting AI templates are placed in a proximity of ‘zero’ between them and so the units involved at each template will stop moving when their respective templates are placed in zero proximity. Also by default, CA has programmed that the template will have as front border, the 1st unit block that has no other in front of it (no matter the 1st unit block of each formation). I would not have touched the offsets if I have not observed occasional idiotic AI approaching of attack in many cases. For instance in many battles AI would maneuver “with a Hollywood Napoleonic manner of suicide”, that means it will ignore the projectile that are targeting them and will continue to move passively until they are in proximity of point blank range and have of course sustained a lot of casualties. This is caused because internal AI clock of swapping of scenario will move to each new waypoint/scenario once it has 100% arrived to the first targeted node. If this node is placed wrongly too close to defensive units, AI will persist to hunt to reach this point in order to change to the next attack programmed node. So what I do here is to give some meters of air between the adjacency of the templates (or sometimes the opposite, to cause intersection of templates) in order to force
    the AI army to arrive sooner to its destination and start interacting. If I want the opposite, that means to provoke AI to move further inside the opponent template it will mostly be done for armies that have heavy phalanx units or barbarian heavy melee units that have to penetrate into a formation in order to exploit their advantages. Or else AI uses them with a “wandering” system of proximity sphere of control which provokes easy isolation of AI units and destruction.


    Technical Note:

    The offset mode is implemented by adjusting the meter relativity of the 1st block of the formation as it is the first that is added in an internal AI deploy script and then all other are placed in a relevant chain proximity with each other.

    begin_formation nameX
    defend
    ai_priority p
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 -10.0
    inter_unit_spacing 5.0
    priority 1.0
    end_block


    …………….(rest of code)

    end_formation
    In the above mentioned example I force the ‘defend’ formation to deploy 10 meters behind that pre-calculated.
    Notice the bizarre effect of the bolded text. I call a relativity internally to the block since the block 0 is itself relative to itself. This works only for the first block and if it is done to other blocks you will witness a lot of intersections between blocks. Another example below:

    begin_formation nameX
    attack
    ai_priority p
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 10.0
    inter_unit_spacing 5.0
    priority 1.0
    end_block


    …………….(rest of code)

    end_formation
    In this example I force the ‘attack’ formation to deploy 10 meters ahead of that internally pre-calculated. I have not used this method to offset the template horizontally since I was afraid that it would cause a lot of problems in a general test. This is a method of a vertical offset. I will mention the horizontal method later.

    Important notes:

    -Too big values (above 25 meters) are not suggested to be used since the template may over leak and the units to exceed the limits of the template and to become uncontrolled.(A common bug).

    -Negative vertical offsets in ‘defend’ formations make the AI to become more cautious in the process since it prefers to maintain a distance from the enemy template. And that because the proximity between rival units is bigger and so are triggered with more probability the skirmish internal AI commands as a preferation.

    -Negative vertical offsets in ‘attack’ formations cause the AI arrive sooner to its pre-calculated position of attack interaction and thus AI starts really attacking sooner but in more distance. So this would be good for armies that have lots of projectiles or maneuverable self strong units (like roman cohorts) but not good for strong melee units or phalanx since they will be deployed in the end in a very far position against the enemy and the secondary AI routines will fail to organize a coherent approach.

    -Positive offset ‘defend’ or ‘attack’ values will cause AI to arrive in a more advanced position and thus create a more aggressive behavior since the AI units are placed intentionally very near to the enemy template so their respective attack arcs trace a lot of rivals to create a simultaneous attack.

    -The offsets are not a general law to be followed but should be created after a formation is designed and then watch the AI how it interacts. Then correct it by giving the appropriate offsets so to create the desired effects, for example if you see AI to arrive too soon and wander then you give positive offsets.

    -Offsets can be given to all roles with the following of procedures and ideas mentioned above.


    -Spacer Command: By reading all the above then I can now speak of the special spacer command available as a code routine. The spacer command is virtually a block that contains no units and can be expanded in size vertically and horizontally. It can also be offset in x-y coordinates from the center of the template. Its size is used as a neutral space from which all the corresponding relative to it units will be in distance. Just like an elliptic /orthogonal shape and around to it the relative blocks. So by inserting it you can create very different forms of formations and also gameplay enhancements. I used to use it in my formations a lot until patch 1.2 so as to create more ‘breathing’ room for the template since the spacer seems to override the template limits and creates extra safe distance without inflicting problems of over leak. But it is causing bizarre effects, for example if it is too big, many units will fail to be positioned correctly in the template and will move to the borders. In later patches the improvement of AI have made me to remove it as a technique. Also because it cannot be seen you can only roughly guess of its true size by watching the relative blocks bordering around it. I use it a lot in the Scythian RTW and my nomad formation in BI which I create a gap in the center of the formation (like a scorpion) to enhance the enveloping of the highly maneuverable nomad units. I also use it to the bridge AI to create attacking offsets. The spacer command can be effectively used to horizontally offset a formation or a group only of the formation units since all the units relative to it will follow its position and size.

    Technical Note:

    The spacer command is:
    begin_dummy_block X
    spacer “x” “y” “width” “depth”
    end_dummy_block

    The explanations in quotes are straightforward so I give the following example:

    begin_formation nameX
    attack
    ai_priority p
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_dummy_block 0
    spacer -50.0 20.0 100 30
    end_dummy_block




    begin_block 1

    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 10.0
    inter_unit_spacing 5.0
    priority 1.0
    end_block

    begin_block 2

    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 -10.0
    inter_unit_spacing 5.0
    priority 1.0
    end_block

    begin_block 3

    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 10.0 0.0
    inter_unit_spacing 5.0
    priority 1.0
    end_block

    begin_block 4

    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 -10.0 0.0
    inter_unit_spacing 5.0
    priority 1.0
    end_block





    …………….(rest of code)

    end_formation

    This simple example creates a gap of width 100 meters, depth 30 meters, horizontal position relative to the center of the template 50 meters to the left, and vertical 20 meters to the front.
    The 4 unit blocks mentioned in the example code are placed in circle around the gap in 10 meters proximity each North, South, East, West of it respectively for blocks 1,2,3,4 .
    The width,depth values can be also set negative with the same effects possible since there is an internal absolute transformation internally.
    The spacer command if used selectively and properly can create very special AI forcing of skirmishing since the formation will try to preserve the space from the enemy template or even create extra skirmishing behaviour of the units involved to this spacer command by preserving always a wide distance around the formation.


    -Darth special unit attack offsets: Doing all this speaking for formation offsets and realizing its importance it has become also more important to force offsets per unit. This can become a reality but needs extensive testing before finalizing the procedure. The extra offset effect can be implemented only to the attack role of formation or any other dynamic role of formation (such as pursue etc.) or else we have over leak due to formation template over extension. The attack role described above is working in a different way that that of ‘defend’. Once the ‘attack’ is triggered the formation moves to a pre-calculated position and then unleashes the units to follow the internal AI commands. The speed and the timing of this attack depends of the flag of percentage of AI units that have arrived to the destination given. It has been observed that AI starts with ‘defend’ deploy and if its mission is to attack it immediately swaps to ‘attack’ role and quickly issues a waypoint to arrive near the opponent formation with as much advantage as possible. I suppose this advantage is internal commands which survey enemy unit type proportion, position, height and type of ground etc. Once the waypoint is reached by the majority of the units they commence the attack either independently or by micro-grouping and following similar routines. So the target was to maximize the effectiveness of unit arrival especially for the wingers and auxiliaries such as cavalry and skirmishers. These units have to arrive sooner to their pre-calculated destination than the core infantry center so that the interaction is timed better. The AI unit moves with more speed if the destination is far and with less if it is near. So by giving an offset of, for example, -60 meters for archers they will use different speed to reach their destination and will arrive far more behind than the melee troops so that will start firing effectively from the proper distance. If they have no offset and only follow the formation relativity then the AI moves the formation all together mostly and archers arrive too near to the enemy to be used correctly or they prefer to melee or they go back again losing time. In other words if I want the units to follow a special attack pattern, I give them offset.
    Giving extra distance relativity and behind from the center of the formation to cavalry makes it to arrive far behind and wait for the center to arrive also than attack too soon. This is vital because of the inter-variance of unit speeds and so if the very quick units arrive in speed and ahead of the center they will start their attack alone, isolated and get massacred. So the offset is forcing them to delay their speed, reach a more rational position in the map to support the attack and generally create a solid and coherent AI formation. Once the units arrive the attack commences but the offset has corrected the difference of unit speeds and given the best interaction spacing. This is not to be created by luck but very careful testing and perception. We can use large number of offset distances with safety because the template of ‘attack’ role is dynamic and moves in the map while the units are ordered to follow it so the over leak is not affecting their position unless you over use it.


    Technical Note:

    Below I will give a simple example of the attack offset method.

    begin_formation nameX
    defend
    ai_priority p1
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type phalanx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 1

    unit_type cavalry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 5.0 -10.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 2

    unit_type cavalry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 -5.0 -10.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 3

    unit_type missile infantry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 -8.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block





    …………….(rest of code)

    end_formation

    begin_formation nameX
    attack
    ai_priority p2
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type phalanx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 1

    unit_type cavalry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 20.0 -40.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 2

    unit_type cavalry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 -20.0 -40.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 3

    unit_type missile infantry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 -50.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block





    …………….(rest of code)

    end_formation
    In this example I want to have phalanx the core unit type to fix the center and cavalry to be the satellites.
    The missile infantry will be behind.
    I start by describing the ‘defend’ role and how different is from the ‘attack’. Here you also get an idea of my swapping method in a very trivial form. Notice the reasonable relativity distances in bold in ‘defend’ role. Then notice how much bigger they become in ‘attack’ role as the AI swaps. If these values where so big also in ‘defend’ role you would see a very bizarre formation with very big distances between the units and with high probability to have over leak. That is, I repeat, the units to fail to be deployed in their ordered positions in the template and so they go off it, get uncontrollable or go all in front. The AI will never use these units correctly.
    But in ‘attack’ role it is different. The formation is not seen clearly in the battlefield, it is dynamic and the bigger relativities order the respective units to have different approach times than that of the core center. With this setting the attack effect would be the following:

    -AI begins with ‘defend’ deploy effectively and rationally
    -AI then swaps to ‘attack’ role and the template is moving to the position of the enemy.
    -The center has much distance to cover since the template moves forward while the large minus distances of the cavalry and missile infantry make them arrive in delayed time but more backwards and in safe distance from enemy projectile fire.
    -Once the phalanx arrives all the units are interacting in coordination and the AI attacks effectively.


    If I have used the same values of ‘defend’ roles then this would happen:

    -AI begins with ‘defend’ deploy effectively and rationally
    -AI then swaps to ‘attack’ role and the template is moving to the position of the enemy.
    -All the formation has approximately the same distances to cover so the faster units will arrive much sooner and in dangerous proximity to enemy projectile fire.
    -While the phalanx moves slowly the cavalry is severely punished by projectile fire, the missile infantry will begin to fire sooner and probably will be unprotected and too far away and in front of the center and not behind as ordered.
    -The phalanx finally arrives and the general attack begins but with heavy losses for the auxiliary troops which will be unable to be of help during the battle due to the pre-mature engagement.


    This method is the core method of clever manipulation of AI through formation according to roles and is surprisingly effective if used correctly.


    -Darth unit width forcing: While playing a lot of battles against the AI a human player can instantly understand that he has a very clear advantage while he is able to change the width of his units to fulfill various roles while the AI can only stick to the pre-defined and move around. I decided to change this and offer to the AI the ability to simulate this. There are 4 available commands:
    min_unit_width, max_unit_width, min_unit_depth, max_unit_depth.
    The last 2 are hidden but can be used eventually as the opposites of the first 2. I decided to work with widths instead of depths. These commands are placed right after the unit type codes and right after the default_melee_state and unit_formation and unit_density commands if they are used in the block.
    Their name calls for their code strength quite straightforwardly. If for example I call max_unit_width 30 then I force the corresponding unit block never to exceed the programmed width of 30 men in the first row.
    If I call min_unit_width 20 I call the unit block to have as a minimum the 20 men in first row.
    If I call them independently they have different effects than if I call them simultaneously and in combination.
    For example if I call only the max_unit_width 30 some units that have been pre-coded by the EDU file to be more stretching will transform to fit the ordered 30 men front row. But some that will be not be too stretching and will be under this limit by default will stick to their pre-defined. So here I also enter the min_unit_width 20 to enter the forcing that the unit will successfully fit my pre-defined 20-30 men width for an homogenous unit width per block. This is very important because through my formations I can override any EDU parameter and create universal formation width types than too much variance according to a mod EDU parameter.
    This kind of modding is very successful but extremely dangerous for the stability of the formation_ai file and can cause freezes or strange unit behavior if modded incorrectly. If it is successfully implemented you get a very satisfying visual result and a human-like AI behavior. For example I have made Romans to expand their maniples when they attack and narrow them if they are to defend just like a rational thoughtful defender would do.


    Technical Note:

    I will give a simple example of how my swapping formation method can co-operate with the unit width forcing to create a unique AI forcing.

    begin_formation nameX
    defend
    ai_priority p1
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type phalanx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    min_unit_width 20
    max_unit_width 20

    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 1

    unit_type cavalry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    min_unit_width 20
    max_unit_width 25

    block_formation line
    block_relative_pos 0 5.0 -10.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 2

    unit_type cavalry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    min_unit_width 20
    max_unit_width 25

    block_formation line
    block_relative_pos 0 -5.0 -10.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 3

    unit_type missile infantry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    min_unit_width 30
    max_unit_width 30

    block_formation line
    block_relative_pos 0 0.0 -8.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block





    …………….(rest of code)

    end_formation


    begin_formation nameX
    attack
    ai_priority p2
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type phalanx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    min_unit_width 30
    max_unit_width 35

    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 1

    unit_type cavalry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    min_unit_width 40
    max_unit_width 40

    block_formation line
    block_relative_pos 0 20.0 -40.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 2

    unit_type cavalry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    min_unit_width 40
    max_unit_width 40

    block_formation line
    block_relative_pos 0 -20.0 -40.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 3

    unit_type missile infantry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    min_unit_width 80
    max_unit_width 120

    block_formation line
    block_relative_pos 0 0.0 -50.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block





    …………….(rest of code)

    end_formation
    Now we see in ‘defend’ role that the widths are narrower than those of ‘attack’. For example the AI phalanx will defend in thicker formation and will be much more difficult to break it. Once they swap to attack, the phalanx will expand its front so to create a more enveloping character and with the coordination of all the other enveloping forces will expand the whole formation to have a wider front, far more difficult and time cost to flank it and more easy for the AI to envelop or benefit from the wider front charge with increased attack ratio.
    Also you see that attacking missile infantry will have minimum 80 men in front (if the men are not enough will make it the wider possible) so as to create an effect of thin line archery with increased attack ratio and better defense against counter fire.

    Important Notes:

    -The force unit width is not working properly for chariots and elephant units so I do not use it and also have to create a special unit block that mentions them with high priority so that they always fit there and not go to the forced width blocks and cause problems.

    -It is trivial to mention that min_unit_width <= max_unit_width or else you get paradox and CTD.



    -Darth force unit stance: The internal AI commands are quite a mystery but still there can be achieved success of how to trigger the correct AI patterns with the formation ai commands. This is accomplished with the help of the commands default_melee_state and unit_formation. These commands go right after the unit type block commands in the order mentioned. The default_melee_state is a command that needs extra attention if it is to be used because it can create untraceable bugs to the AI behavior such as skirmishers being idle or irrelevant human player unit stances, suicidal behavior etc. I use it selectively only to trigger guard mode and also for Romans to create inter-variance of stances between maniples. The default_melee_state is toggling the available stances of units (skirmish, guard mode, special attack etc.) but unfortunately in my opinion cannot cover all the roles that will vary in the battlefield according to unit proportions so it may work in an army full of archers for example but then if this formation script applies to an army with a lot of melee units it will fail to utilize them correctly. And since the internal AI has not the ability to be so selective, there must be caution and balance of the usage of it. This applies also for the unit_formation command which forces the units to follow certain unit formations by default such as phalanx, wedge, horde etc.
    There is a lot of technical advise that has to be mentioned for each available variation of commands but I will not mention them so thoroughly than offer some important examples to understand better the general truth behind these lines.

    Technical Note:

    With the following example I will force the 1st unit block to have as default the guard mode enabled. This will be also used for the human player starting position since as I have mentioned before the ‘defend’ formation role is used also for this reason.

    begin_formation nameX
    defend
    ai_priority p
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    default_melee_state defend
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block


    …………….(rest of code)

    end_formation

    This unit block will be now always in guard mode if controlled by the AI. (Human can toggle it off selectively).
    You can also use a lot of commands here such as skirmish, engage_at_will, attack, etc. and also Sinuhet has found a lot of extra combinations for them but….what he may do not know is that the AI compiler has the ability to override a non existent command, maybe to be confused a little but never produce a show_err report or CTD for a wrong default_melee_state command. What I am telling here is that you can write default_melee_state Sinuhet_attack_and_defend_and_whatever and the AI will not understand it and override it but of course then if it does not CTD, one may think that he found another hidden command…wrong! So unless there is a valid testing that these commands are truly affecting the machine (One can test by applying to ‘defend’ role, then start a battle to see how the human formations start and watch each melee state and if it toggles it is valid. If it does not …it is not existent) he must not exaggerate of his findings.

    Now I give next example with combination of commands:

    begin_formation nameX
    defend
    ai_priority p
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    default_melee_state defend
    unit_formation phalanx

    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block


    …………….(rest of code)

    end_formation

    Now the 1st AI unit block will by default use phalanx and guard mode. A very resilient way to defend against a human army. Unit formations can be as many as those available in the game engine (wedge, shield_wall, square, phalanx etc.) The testudo is CA bugged and when used as primary forced unit formation it will cause CTD instantly in battle. You can also use various options for unit_formation for example unit_formation phalanx, testudo, square, etc.
    This has been only empirically verified by me that it affects the AI by using more than 1 option of unit formation (1 primary=the first and all other secondary). The AI will also accept as stated before irrelevant commands such as ‘whatever’….but in order to understand which are the correct you use them first as primary and if you do not get an error message you use it for secondary and hopefully my tests have shown that affects the internal AI commands to group the units as group of unit capable of respectively phalanx, testudo, square etc. and homogenously treat them.
    Nevertheless if this is not working eventually (the secondary commands), it is surely working the primary command and in a double way. Not only it forces the unit block to have as default a certain formation but affects the grouping of the units so the phalanx related blocks move in coordination, the square blocks also in coordination etc. Like a human grouping.

    Important Notes:

    -As stated above the false default_melee_state commands do not produce error reports so one can easily be tricked that he found ways to manipulate them more

    -The same applies to unit_formation secondary commands

    -These commands need extra caution when trying to implement them because they produce untraceable errors

    -The unit_formation command transforms to a forced formation only the capable units for it. That means if a unit is not phalanx capable it will not phalanx, although if the command is there, AI will most likely make them to behave as phalanx (less maneuverable, penetrating etc.)

    -They must not be used to general units (unless hardly tested) because they cause suicidal behaviors

    -Phalanx unit formation command must not be used to attack roles because it traps the corresponding unit blocks to a very slow movement and so the non-phalanx units start the attack alone. I use phalanx for defend role and then the attack role toggles it off so that the AI army can maneuver freely.



    Darth General Unit protection methodology: One of the most common issues of CA bad AI programming was the occasional suicidal behavior of the general units. This was very important to be corrected since it made extremely easy to win an AI army by knowing that it will lose instantly so much morale and so quickly by the certain death of the general. In later patches this has been improved but certainly not optimized. In order to achieve the optimization I use certain tricks in the formation coding and with combination of other files I create a general almost impossible to catch!(Only in DarthMod 8.1 since I optimize all corresponding files) Still a lot of improvement can be achieved only by modding the formation ai file. I will describe in short the idea behind this:

    -First of all I use a special general block that only the general and no other unit will be placed there. Usually this block is placed behind the army and in some rare special formations it leads the cavalry attack like in my Macedonian Formation.

    -I use the dummy block (will desribe below) a lot and always span all the army in front of the general

    -I also use the not_general command to all blocks I do not want the possibility for the general to be placed.


    Technical Note:

    Now I will give a simple example of how can be a structure of a safe general unit code of formation which includes N blocks:

    begin_formation nameX
    defend
    ai_priority p
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0
    min_units x
    max_units x
    not_general
    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 1
    min_units x
    max_units x
    not_general
    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos 0 0.0 -5.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block
    ……..(rest of code………

    …………………………
    …………………………

    begin_block N-2
    min_units x
    max_units x
    not_general
    unit_type xxx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    block_formation line
    block_relative_pos N-3 0.0 -5.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_dummy_block N-1
    spans 0 1 2 3…..N-2
    end_dummy_block


    begin_block N
    min_units 1
    max_units 1

    unit_type general_unit 1.0
    block_formation line
    block_relative_pos N-1 0.0 -10.0
    inter_unit_spacing 10.0
    priority 1.0
    end_block


    end_formation
    I will describe the important features one by one:

    -Notice that in this form, although it is not essential, the general unit is the last block and behind of all the formation (the N block). There are cases that I force him to be in the center or the right and still be in protection but will not discuss it in this tutorial but will lead you for example to my Byzantine formation in BI where the general is in the center of the formation and in protection of spearmen.

    -You see I have used the not_general command (Placed right up the unit type commands and right below the min, max commands if they exist). This command prohibits the general unit to be placed in any of the blocks used and so he stays to his own special. You must be careful not to use it to all block because you will witness a very suicidal behavior of the general since AI will not know were to put him and will charge him.

    -You must notice the dummy block which spans all the army in front of the general. The usage of this dummy block is very important for formation modding. It is like a relativity connector of the units mentioned in the span. If in the code of the dummy block are mentioned x blocks in the serial form I write above (0 1 2 3 …x) then the next blocks that wish to be relative to the dummy block will be transposed to be relative to all the blocks which connects and with the coordinates ordered just like in any other block.

    -Keep in mind of the special general block N of the example and this form is almost generic to all circumstances. The min_units = max_units =1 safely ensures than only the general unit will be placed there.
    I do not use the min, max to pursue roles because I have a feeling this is causing suicidal behavior of general since it forces the general to be part of the pursue group. Also I do not use it to mix attack/defend roles for the same reasons since the mix role is responsible for AI grouping.

    -Notice the relativity of the general block to the dummy block that spans all the army. This forces the AI general to try to keep his existence always behind the army and make hit and run tactics. I could have done it to be relative to the last block of the formation which still could produce the starting effect of a safe general but not in the whole process of the battle, because in some battles, this block may become obsolete or die and then the general becomes somewhat uncontrolled.

    -You must also see that in unit types only the general_unit is mentioned with high priority of 1.0 to ensure the AI pick.

    -Lastly I use a secondary tactic of inter_unit_spacing of 10 meters which may be somewhat paradox since there is only 1 unit in the block but in my tests it seemed that it enhanced the safe distance between friendly blocks.


    Now this generic form can help someone create his own safe general patterns but I cannot guarantee that all of them will be correct. Each formation has a spirit of each own and since there are other files involved such as EDU and my findings here: http://www.twcenter.net/forums/showthread.php?t=61739
    The best result will be accomplished with the combination of big testing, formation and supplementary balance.
    Also I use for the ‘attack’ roles the offset methods described above for the general unit (Giving large minus values)



    Darth unit densities and spacing:
    Since the whole idea of formation modding is based mostly on the correct system and inter-unit distances that the AI army will follow to exploit its potential I will lastly but not least mention some basic tricks to provide cohesion effects to AI army. The most important and simple is to make the inter_unit spacing smaller as much as possible. If you want to do that (It is very logic for phalanx lines for example) the best value is 0.2 since this covers also the officers that are by the side of the unit blocks. If you place it 0.0 the officers will intersect. If you want to produce maniple effect then you raise the value above 20 meters so that each unit block is having a decent gap between the other unit. In my swapping method I play with this value a lot and can create effects of maniples to become wider and later to form a line, cavalry to skirmish and side protect each other with hex distance or create mass cavalry charge etc. The inter_unit_spacing command is based right below the relativity of block codes and right above the priority of block.

    Also there is another command, the unit_density (to be placed right above the block_formation command). This can take the values of either loose or close and defines the toggle of the respective commands in formation panel of human player which of course can be forced to the AI.
    I use a pseudo-shieldwall system in DarthMod-RTW which replaces the loose unit formation with the “protective formation” which selectively makes the heavy units with good shielding to combine and overlap the shields while it preserves the former loose deploy of the lighter units as they can be better used this way.
    With the combination of the swapping method described above one can create very realistic effects of formations expanding, combining, overlapping, loosing their formations in the middle of the battle and all of that by the AI! I follow the general law of never giving any density command (not loose or close) to skirmisher blocks because this deteriorates their skirmishing attitude. AI will effectively loose them or make them close according to circumstances if there is no forcing code for them. But I toggle the protective mode a lot for heavy units calling for it when necessary and de-activating in other roles during then swapping phase.

    Technical Note:

    Below I will give a very simple example of the implementation of the above mentioned techniques:


    begin_formation nameX
    defend
    ai_priority p
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type phalanx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    unit_density loose, close
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 1

    unit_type missile infantry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    ;unit_density close, loose(not used)
    block_formation line
    block_relative_pos 0 0.0 -10.0
    inter_unit_spacing 5.0
    priority 1.0
    end_block



    …………….(rest of code)

    end_formation


    begin_formation nameX
    attack
    ai_priority p
    supported_factions faction name1, faction name2, ….,faction nameN


    begin_block 0

    unit_type phalanx 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    unit_density close, loose
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.2
    priority 1.0
    end_block

    begin_block 0

    unit_type missile infantry 1.0
    xxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxx
    ;unit_density close, loose (not used)
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 12.0
    priority 1.0
    end_block



    …………….(rest of code)

    end_formation
    In the above mentioned formation code one must notice that :

    ‘defend’ role

    -I picked the 0.2 meters inter unit spacing for the phalanx block since it is more effective when coherent
    -I picked a 5.0 meters inter unit spacing for the missile infantry since they are more AI effective when having space between them and AI fires more rapidly if there are no intersection between units because it pre-calculates friendly fire.
    -Using Darth Pseudo-shieldwall I use the ‘protective’(loose replaced) more combined formation for the phalanx (and secondary the normal close)
    -I do not use unit density code for missile infantry to relief them from bad AI density forcing and melee picking of them.


    Swapping to…

    ‘attack’ role

    -I picked the 0.2 meters inter unit spacing for the phalanx block since it is more effective when coherent
    -I picked a wider 12.0 meters (for attack variance) inter unit spacing for the missile infantry since they are more AI effective when having space between them and AI fires more rapidly if there are no intersection between units because it pre-calculates friendly fire.
    -Using Darth Pseudo-shieldwall I now recall the normal formation of the units and they stop to use overlapping to become more enveloping and cover more space in the battlefield when they attack
    -I do not use unit density code again for missile infantry to relief them from bad AI density forcing and melee picking of them.



    Darth Vader’s Note:

    I decided to end my tutorial at this stage while I think I have mentioned and explained successfully the most important aspects of my formation modding. In order to have the best AI results you must also balance the following gameplay files:
    descr_battle_map_movement_modifiers
    (It decides the speed of all the units and so it determines not only the visual realism but AI decision which has more time to exploit its plan. CA wanted to trick the player by giving insect speeds to units and thus cover the AI faults with compensation the AI ability to give quicker the orders than human and in a lightning speed battle, human is at disadvantage but not in intelligence but reflexes)
    descr_model_battle (DMB)
    (There are hidden the animation parameters of units and so there are hidden the decision of homogenous per faction speeds for the AI if one mods them correctly)
    descr_mount
    (Extremely vital file that decides the mass base of the game. By giving the correct mass to the mount units then the infantry units can take their own respectively mass (through EDU) in relativity and with correct balance you can create the realistic battle tension (Charge penetrations, havoc in unit distribution after melee etc.)
    descr_projectile_new
    (By adjusting correct realistic speeds to the projectiles not only you create realism but better usage of AI skirmishers since the trajectories and the aiming are improved.
    export_descr_unit (EDU)
    (The most important file after the formation AI or maybe slightly better, who knows. This file is hiding so much info to interact with AI that only a new tutorial could explain it.)

    Hope those who read it have actually firstly enjoyed it and secondly why not, try to fix their own formations with the help of my findings. I do not know if I will continue to mod this game anymore.(Even MTW2) because sometimes it is better to take a decision to stop things that offer you more work and finally less compensation in terms of fun and time exploitation.

    Darth Vader

  2. #2

    Default Re: _Episode VI_“Modifying Formation AI version 2”

    Tutorial ended. Hope you like it and help those who are eager to learn about the modding of this file.

  3. #3

    Default Re: _Episode VI_“Modifying Formation AI version 2”

    Bravo Professor Vader
    Thanks for the lecture, something to study in long autumn nights...

    repman

    BareBonesWars 8.1 for RTW 1.5
    Integration Mod which combines unique strategic challenges due to a 4 Season scripted campaign from 280 BC - 180 AD on several big/small maps and with an ruthless AI on the battlefield.
    Deus lo Vult DLV 6.2 for MTW II Kingdoms
    Norway+Ireland+Flanders+Kiev+Lithuania+Teutonic_Order+Armenia+Crusader+Georgia,1y2t script, army field costs, Ultimate AI 1.6, big map, military career, economic system, age simulation, heraldic system, new factions, garrison script, Crowns + Swords, Trait bugfixer, religion dependent recruiting, ancillary enhancements, darth battle mechanics

  4. #4

    Default Re: _Episode VI_“Modifying Formation AI version 2”

    Thanks Repman!

    Also give importance to this:

    This unit block will be now always in guard mode if controlled by the AI. (Human can toggle it off selectively).
    You can also use a lot of commands here such as skirmish, engage_at_will, attack, etc. and also Sinuhet has found a lot of extra combinations for them but….what he may do not know is that the AI compiler has the ability to override a non existent command, maybe to be confused a little but never produce a show_err report or CTD for a wrong default_melee_state command. What I am telling here is that you can write default_melee_state Sinuhet_attack_and_defend_and_whatever and the AI will not understand it and override it but of course then if it does not CTD, one may think that he found another hidden command…wrong! So unless there is a valid testing that these commands are truly affecting the machine (One can test by applying to ‘defend’ role, then start a battle to see how the human formations start and watch each melee state and if it toggles it is valid. If it does not …it is not existent) he must not exaggerate of his findings.
    I believe Sinuhet has to re-check his findings.
    Although I do believe that most of them are valid as I have checked some.

  5. #5

    Default Re: _Episode VI_“Modifying Formation AI version 2”_

    very interesting information Darth Vader!!!

    Macedonia was,is and will always be Hellenic.
    it is nice to be important, but it is more important to be nice.

  6. #6

    Default Re: _Episode VI_“Modifying Formation AI version 2”_

    I only started to learn about this after being suspicious of the formation ai txt, which I believe was controlling the suicidal behavior of my skirmishers,even after reducing charge range to 10! Sheesh. Albeit late,but to know about Modelling I have to learn somewhere,and this is amazing. Appreciated!!!
    RIP Andy aka "Calvin",sorely missed by many.
    Hoping all of your guys and girls out there are OK and your family in RL?

  7. #7
    Athenogoras's Avatar Campidoctor
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    1,784

    Default Re: _Episode VI_“Modifying Formation AI version 2”_

    Thanks for this guide. It is a must-read for anyone meddling with formations. I have used most of it in my own formations. I dont use your priority-system though and I tend to be more careful with the vertical offset-values. I also dont use the "min_units" for general units as it makes your AI-controlled reinforcements to lose its general position(and instead adopt its EDU-classification: heavy cavalry, heavy infantry etc).

    Here is some supplementary information on reinforcements.
    Scenario: Human player(hp) attack, you have 2 full armies, AI-opponent has 2 full armies

    Before battles start

    Both you and AI start with the formation that has the highest "defence"-priority

    Before reinforcements arrive

    Before your reinforcements arrive(inside the square) they will approach using the formation they would have adopted in an attack fieldbattle.

    AI:s reinforcement will approach using the formation the army would have adopted in an defensive fieldbattle

    Reinforcements arrive

    The defensive AI-reinforcements will adopt the formation which has both attack/defend as purpose flags(as you have already mentioned). If possible it will try to merge with the already present army and will then adapt to that armies formation(which uses the defend formation)

    Your own attacking reinforcement will however not arrange itself that way. It is much more buggier.
    Basically the formation is decided by the first soldier that comes into the battlezone.
    If it is a heavy infantry it will lock for the formation where the priority of heavy infantry is biggest. It only searches in formations that have the attack-flag in it.
    In my formations(wip) it will be this formation(priority marked in red):
    begin_formation ai_sparta_reinf1

    ;purpose flags
    attack
    ai_priority 1.0
    supported_factions greek_cities, slave

    ;; Hoplites
    begin_block 0
    not_general
    unit_type heavy infantry 1.01
    unit_type any 0.001
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block
    Also note that not only priority is of importance. It also seems that formations which uses the "min_units" are generally shunned and even if overall priority is higher they will not choose this.

    If the AI fails to find a formation it will show chaotic behaviour and will basically just run to the nearest enemy.
    Last edited by Athenogoras; May 31, 2010 at 03:52 AM.

  8. #8

    Default Re: _Episode VI_“Modifying Formation AI version 2”_

    Thank you Athinagoras for your addition. You reminded me the gold AI modding days of DarthMod.
    I cannot really understand what is the different thing you mention.
    -The first unit block decides the relative positioning of all other unit blocks
    -Unit blocks are line or column arrayed (Horizontal -Vertical)
    -The priority system is applied inside the block and between blocks. The bigger priority of a unit type in a block, the more troops of this kind will fill it. The bigger priority a block has, more troops will fill this block relative to other blocks of the formation.
    -If a formation becomes too wide and a unit gets out of the formation template borders, then it becomes berserk and attacks the nearest unit (AI suicide routine to prevent a total CTD).

  9. #9
    Athenogoras's Avatar Campidoctor
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    1,784

    Default Re: _Episode VI_“Modifying Formation AI version 2”_

    I am sorry for being unclear:
    This is from your guide:

    attack/defend Multi role: This role is also important for the AI because for some reason it is used for reinforcement armies. So when they enter the battle they instantly change to this. If it is not available, there is a CTD. If it is wrongly modded, the reinforcements are idle. And not only this. If the priority is high enough comparing to the previous isolated roles, it will be also used for the respective roles mentioned above . So someone must be really careful how he mods this multi role in order not to surpass the previous roles which then will be seldomly used.
    I say that this is only true for defending armies. You are attacked, you put reinforcing army under Ai control then they will adapt to formation with attack/defend.

    This is not true if you are attacking. Your reinforcements will then not pick the formation of attack/defend(unless the priority is higher than your pure attack formation). It will instead choose formation based on the unit classification that enters first. AI will search in the attack-formationfiles where this unitclass has the highest priority(of course it must also be a supported faction) and choose formation according to this.

    I will update with screenshots to illustrate...

    Here is scenario
    Battle of Plataea
    Spoiler Alert, click show to read: 


    My main army
    Spoiler Alert, click show to read: 


    Reinforcement army approaching
    Spoiler Alert, click show to read: 


    Reinforcement army reformed
    Spoiler Alert, click show to read: 


    Here are my main greek attack formations

    1.
    Spoiler Alert, click show to read: 
    begin_formation ai_sparta_attack

    ;purpose flags
    attack
    pursue
    ai_priority 1.0
    supported_factions greek_cities, slave

    ;; Hoplites
    begin_block 0
    unit_type heavy infantry 1.0
    unit_type any 0.001
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block

    ;; support - right
    begin_block 1
    unit_type light infantry 1.0
    unit_type non_phalanx_spear 1.0
    unit_type any 0.001
    block_formation line
    block_relative_pos 0 0.3 0.0
    inter_unit_spacing 0.3
    priority 0.3
    end_block

    ;; support - left
    begin_block 2
    unit_type light infantry 1.0
    unit_type non_phalanx_spear 1.0
    unit_type any 0.001
    block_formation line
    block_relative_pos 0 -0.3 0.0
    inter_unit_spacing 0.3
    priority 0.3
    end_block

    begin_dummy_block 3
    spans 0 1 2
    end_dummy_block

    ;; True Spartan ; not on the right wing since general-radius would hamper AI-greeks
    begin_block 4
    unit_type general_unit 1.0
    block_formation line
    block_relative_pos 3 0.0 -10.0
    inter_unit_spacing 25.0
    priority 1.0
    end_block

    ;; Hoi polloi

    ;; ranged missile line behind
    begin_block 5
    unit_type ranged_missile_infantry 1.0
    unit_type missile infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 4 0.0 -35.0
    inter_unit_spacing 15.0
    priority 0.4
    end_block

    ;; missile infantry - right
    begin_block 6
    unit_type missile infantry 0.6
    unit_type ranged_missile_infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 5 15.0 0.0
    inter_unit_spacing 15.0
    priority 0.4
    end_block

    ;; missile infantry - left
    begin_block 7
    unit_type missile infantry 0.6
    unit_type ranged_missile_infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 5 -15.0 0.0
    inter_unit_spacing 15.0
    priority 0.4
    end_block

    begin_dummy_block 8
    spans 3 4 5 6 7
    end_dummy_block

    ;; cavalry right
    begin_block 9
    unit_type light cavalry 1.0
    unit_type heavy cavalry 1.0
    block_formation line
    block_relative_pos 8 15.0 -15.0
    inter_unit_spacing 5.0
    priority 0.58
    end_block

    ;; cavalry left
    begin_block 10
    unit_type light cavalry 1.0
    unit_type heavy cavalry 1.0
    block_formation line
    block_relative_pos 8 -15.0 -15.0
    inter_unit_spacing 5.0
    priority 0.58
    end_block

    ;; artillery and handler behind
    begin_block 11
    unit_type handler 1.0
    unit_type siege 1.0
    unit_type any 0.001
    block_formation line
    block_relative_pos 4 0.0 -5.0
    inter_unit_spacing 10.0
    priority 0.1
    end_block

    end_formation


    2.
    Spoiler Alert, click show to read: 
    begin_formation ai_sparta2_attack

    ;purpose flags
    attack
    pursue
    ai_priority 1.0
    supported_factions greek_cities, slave

    ;; Hoplites
    begin_block 0
    unit_type heavy infantry 1.0
    unit_type any 0.001
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.3
    priority 0.5
    end_block

    ;; support behind
    begin_block 1
    unit_type light infantry 1.0
    unit_type non_phalanx_spear 1.0
    unit_type any 0.001
    block_formation line
    block_relative_pos 0 0.0 -5.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block

    begin_dummy_block 2
    spans 0 1
    end_dummy_block

    ;; True Spartan ; not on the right wing since general-radius would hamper AI-greeks
    begin_block 3
    unit_type general_unit 1.0
    block_formation line
    block_relative_pos 2 0.0 -10.0
    inter_unit_spacing 25.0
    priority 1.0
    end_block

    ;; Hoi polloi

    ;; ranged missile line behind
    begin_block 4
    unit_type ranged_missile_infantry 1.0
    unit_type missile infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 3 0.0 -35.0
    inter_unit_spacing 15.0
    priority 0.4
    end_block

    ;; missile infantry - right
    begin_block 5
    unit_type missile infantry 0.6
    unit_type ranged_missile_infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 4 15.0 0.0
    inter_unit_spacing 15.0
    priority 0.4
    end_block

    ;; missile infantry - left
    begin_block 6
    unit_type missile infantry 0.6
    unit_type ranged_missile_infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 4 -15.0 0.0
    inter_unit_spacing 15.0
    priority 0.4
    end_block

    begin_dummy_block 7
    spans 2 3 4 5 6
    end_dummy_block

    ;; cavalry right
    begin_block 8
    unit_type light cavalry 1.0
    unit_type heavy cavalry 1.0
    block_formation line
    block_relative_pos 7 15.0 -15.0
    inter_unit_spacing 5.0
    priority 0.58
    end_block

    ;; cavalry left
    begin_block 9
    unit_type light cavalry 1.0
    unit_type heavy cavalry 1.0
    block_formation line
    block_relative_pos 7 -15.0 -15.0
    inter_unit_spacing 5.0
    priority 0.58
    end_block

    ;; artillery and handler behind
    begin_block 10
    unit_type handler 1.0
    unit_type siege 1.0
    unit_type any 0.001
    block_formation line
    block_relative_pos 3 0.0 -5.0
    inter_unit_spacing 10.0
    priority 0.1
    end_block

    end_formation


    As you can see the reinforcements approach with formation 2(that is logical since the composition of the army supports this formation, much light infantry, less hoplites). Then all of a sudden it changes into formation 1 when entering.
    My conclusion(after much testing) is as I have said before. The first unit(in this case hoplites, heavy infantry) that becomes "self-aware" decides the formation and since the priority is higher for heavy infantry in formation 1 AI chooses this - even if the overall composition of the army says otherwise.
    Last edited by Athenogoras; May 31, 2010 at 04:24 PM.

  10. #10
    Mataputas's Avatar ... llegó el lecherooo!
    Join Date
    Aug 2009
    Posts
    1,252

    Default Re: _Episode VI_“Modifying Formation AI version 2”_

    Quote Originally Posted by DARTH VADER View Post
    This is the continuation of my tutorial about the manipulation of this valuable and peculiar file of descr_formations_ai.txt” based on the root directory of RTW install folder (…\Activision\Rome - Total War\Data\descr_formations_ai.txt).
    Could you tell me where to find the first part of the tutorial? I mean, the basics. Thank you!
    There are none so enslaved as those who falsely believe they are free

  11. #11
    Athenogoras's Avatar Campidoctor
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    1,784

    Default

    I dont think there is one. It is probably merged with this one. And it is not hard. Once you have made one work its pretty routine - although time-consuming since the file is sensitive to errors. And you dont really need to apply all in this guide - it is mostly finetuning.
    But there is one more basic here
    Last edited by Squid; June 02, 2010 at 07:44 AM.

  12. #12

    Default Re: Modifying Formation AI version 2

    Athenogoras, have you come up with any devious plan to overcome this stupidity?


    I also dont use the "min_units" for general units as it makes your AI-controlled reinforcements to lose its general position(and instead adopt its EDU-classification: heavy cavalry, heavy infantry etc).
    The reinforcing army has a 'general' unit of it's own, doesn't it? Or doesn't the AI engine count it as one?
    Last edited by Aradan; July 09, 2010 at 01:20 PM.

  13. #13
    Athenogoras's Avatar Campidoctor
    Join Date
    Apr 2007
    Location
    Sweden
    Posts
    1,784

    Default Re: Modifying Formation AI version 2

    Athenogoras, have you come up with any devious plan to overcome this stupidity?
    Sort of. My main problem with the AI reforming(see above) was that they became tired reforming. So I created pure reinforcing attack formation like this(see spoiler). They reform to one line as before but the line is thicker so they dont have to reform too much. I also made similar formations for when other unitclasses enter first(spearmen, light, missile and cavalry). As you can see heavy infantry has 1.01 priority(the highest in the formation file) all the rest have low priority(so to minimize the risk that the formation is used outside the reinforcement function).

    Spoiler Alert, click show to read: 
    ;****************************************************************************************************************************
    ; Spartan reinforcement(attack) - the formation AI-controlled reinforcement use.
    ; AI chooses formation based on priority of first unit to enter the field.
    ;****************************************************************************************************************************

    begin_formation ai_sparta_reinf1

    ;purpose flags
    attack
    ai_priority 1.0
    supported_factions greek_cities, slave

    ;; Hoplites
    begin_block 0
    not_general
    unit_type heavy infantry 1.01
    unit_type any 0.001
    min_unit_width 10
    max_unit_width 10
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block

    ;; support - left
    begin_block 1
    not_general
    unit_type light infantry 0.1
    unit_type any 0.001
    min_unit_width 8
    max_unit_width 8
    block_formation line
    block_relative_pos 0 -0.3 0.0
    inter_unit_spacing 0.3
    priority 0.1
    end_block

    ;; support - right
    begin_block 2
    not_general
    unit_type light infantry 0.1
    unit_type any 0.001
    min_unit_width 8
    max_unit_width 8
    block_formation line
    block_relative_pos 0 0.3 0.0
    inter_unit_spacing 0.3
    priority 0.1
    end_block

    ;; support - right of right
    begin_block 3
    not_general
    unit_type non_phalanx_spear 0.1
    unit_type any 0.001
    min_unit_width 6
    max_unit_width 6
    block_formation line
    block_relative_pos 2 0.3 0.0
    inter_unit_spacing 0.3
    priority 0.1
    end_block

    ;; support - left of left
    begin_block 4
    not_general
    unit_type non_phalanx_spear 0.1
    unit_type any 0.001
    min_unit_width 6
    max_unit_width 6
    block_formation line
    block_relative_pos 1 -0.3 0.0
    inter_unit_spacing 0.3
    priority 0.1
    end_block

    begin_dummy_block 5
    spans 0 1 2 3 4
    end_dummy_block

    ;; True Spartan ; not on the right wing since general-radius would hamper AI-greeks
    begin_block 6
    unit_type general_unit 0.1
    block_formation line
    block_relative_pos 5 0.0 -15.0
    inter_unit_spacing 25.0
    priority 0.1
    end_block

    ;; Hoi polloi

    ;; ranged missile line behind
    begin_block 7
    not_general
    unit_type ranged_missile_infantry 1.0
    unit_type missile infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 6 0.0 -20.0
    inter_unit_spacing 15.0
    priority 0.1
    end_block

    ;; missile infantry - right
    begin_block 8
    not_general
    unit_type missile infantry 0.6
    unit_type ranged_missile_infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 7 15.0 0.0
    inter_unit_spacing 15.0
    priority 0.1
    end_block

    ;; missile infantry - left
    begin_block 9
    not_general
    unit_type missile infantry 0.6
    unit_type ranged_missile_infantry 0.01
    unit_type any 0.001
    default_melee_state fire_at_will
    unit_density loose
    block_formation line
    block_relative_pos 7 -15.0 0.0
    inter_unit_spacing 15.0
    priority 0.1
    end_block

    begin_dummy_block 10
    spans 5 6 7 8 9
    end_dummy_block

    ;; cavalry right
    begin_block 11
    not_general
    unit_type heavy cavalry 0.1
    unit_type light cavalry 0.1
    unit_type any 0.001
    block_formation line
    block_relative_pos 10 15.0 -15.0
    inter_unit_spacing 5.0
    priority 0.1
    end_block

    ;; cavalry left
    begin_block 12
    not_general
    unit_type heavy cavalry 0.1
    unit_type light cavalry 0.1
    unit_type any 0.001
    block_formation line
    block_relative_pos 10 -15.0 -15.0
    inter_unit_spacing 5.0
    priority 0.1
    end_block

    ;; artillery and handler behind
    begin_block 13
    not_general
    unit_type handler 0.1
    unit_type siege 0.1
    unit_type any 0.001
    block_formation line
    block_relative_pos 10 0.0 -5.0
    inter_unit_spacing 5.0
    priority 0.1
    end_block

    end_formation


    I would however urge you to first test if this is really a problem in your mod(AI general not holding its position). For example XGM uses the min,max units for its generals and there the general holds its position(have tested their greek formation). Perhaps because XGM uses only one attack formation for the greeks.
    If your formations doesnt work as you intend you can send me a PM and I can take a look.

  14. #14
    Foederatus
    Join Date
    Mar 2010
    Location
    Brownsville, TX
    Posts
    47

    Default Re: Modifying Formation AI version 2

    Hello Vader, Aradan, Athenogoras, et al.

    I have a mysterious occurrence with the ai formations in my mod.

    First of all, I considerably simplified and consolidated many of the ai formations from vanilla and used Vader's tutorial to get me started.

    I made my mod to have 4 basic formations: eastern, greco-macedonian (aka, phalanx), roman and barbarian, then used the supported_factions to make it so each ai-faction could only use that one.

    For phalanx I arrnaged it based on historical research and basically made it into a solid wall of phalanx units, with flanks guarded by hoplite units and their flanks guarded by heavy sword units. All cavalry was to the flanks, progressing from near to far flanks heavy cavalry, light cavalry with skirmish and archer cavalry to the sides and ahead and skirmishers to the front corners of the infantry line. It looks great, it is easy for me to set the formation as the human player (as I put it into formations.txt as well).

    Thge only problem (which I only noticed when I play tested human against ai-phalanx) is that, once the battle starts, the defending phalanx formation immediately runs up to my human units, levels their sarrisae and attacks.

    Instead, as defender, they are supposed to simply stay put (on their already high ground) and wait for the enemy charge.

    This happens even though I have done the following:

    - The defending ai-phalanx unit has much less overall power (and retreats from the first attack)
    - I chose its starting position so that it retreats to a high ground facing the enemy (so it is not trying to travel to high ground).
    - The flag = defend and ALL units are default_melee_state = defend OR fire_at_will_and_defend OR fire_at_will_and_skirmish.
    - ai_prioritiy = 0.95 for defend, 0.04 for attack/defend and 0.01 for attack (at first), THEN (when that didnt work)
    - ai_prioritiy = 3.0 for defend, 0.04 for attack/defend and 0.01 for attack (at first), THEN (when that didnt chage it)
    - I removed the attack and attack/defend flagged formations altogether, leaving the only option as the defend flag formation
    - There are no reinforcements.

    Could anyone tell me what I am overlooking or doing wrong. All I want is that the phalanx unit (when ai is defending) to simply stay put.

    I have pasted below the ai-formation "phalanx" with flag=defend for anyone to look at and (hopefully) see what is causing this strange behavior.

    ANY assistance/suggestions would be greatly appreciated.

    Regards,
    Vlad "phalanx_man"

    *********************************************************************************************************
    begin_formation ai_phalanx

    ;;; purpose flags - defending
    defend

    ai_priority 3.0

    supported_factions macedon, greek_cities, pontus, armenia, egypt, seleucid, britons

    ;; Phalanx center
    begin_block 0
    unit_type phalanx 1.0
    default_melee_state defend
    unit_density close
    block_formation line
    block_relative_pos 0 0.0 0.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block


    ;; Hoplites/Spearmen protecting LEFT flank of the Phalanx
    begin_block 1
    min_units 1
    unit_type non_phalanx_spear 1.0
    default_melee_state defend
    block_formation line
    block_relative_pos 0 -0.3 0.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block


    ;; Hoplites/Spearmen protecting RIGHT flank of the Phalanx
    begin_block 2
    min_units 1
    unit_type non_phalanx_spear 1.0
    default_melee_state defend
    block_formation line
    block_relative_pos 0 0.3 0.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block


    ;; Sword Infantry defending LEFT flank of Non-Phx Spearmen
    begin_block 3
    min_units 1
    unit_type heavy infantry 1.0
    unit_type light infantry 0.4
    default_melee_state fire_at_will_and_defend
    block_formation line
    block_relative_pos 1 -0.3 0.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block


    ;; Sword Infantry defending RIGHT flank of Non-Phx Spearmen
    begin_block 4
    min_units 1
    unit_type heavy infantry 1.0
    unit_type light infantry 0.4
    default_melee_state fire_at_will_and_defend
    block_formation line
    block_relative_pos 2 0.3 0.0
    inter_unit_spacing 0.3
    priority 1.0
    end_block


    ; Screen of Skirmishers In Front of Left Flank PHX Defense
    begin_block 5
    max_units 3
    unit_type skirmish infantry 1.0
    unit_type chanting_screeching 0.9
    default_melee_state fire_at_will_and_skirmish
    unit_density close
    max_unit_width 40
    block_formation line
    block_relative_pos 3 0.0 10.0
    inter_unit_spacing 10.0
    priority 1.0
    end_block

    ; Screen of Skirmishers In Front of RIGHT Flank PHX Defense
    begin_block 6
    max_units 3
    unit_type skirmish infantry 1.0
    unit_type chanting_screeching 0.9
    default_melee_state fire_at_will_and_skirmish
    unit_density close
    max_unit_width 40
    block_formation line
    block_relative_pos 4 0.0 10.0
    inter_unit_spacing 10.0
    priority 1.0
    end_block


    ;; Reserve unit protecting LEFT flank of Ranged Missile Units
    begin_block 7
    max_units 1
    unit_type non_phalanx_spear 1.0
    unit_type light infantry 0.9
    unit_type heavy infantry 0.5
    default_melee_state fire_at_will_and_defend
    block_formation line
    block_relative_pos 3 0.0 -18.0
    inter_unit_spacing 10.0
    priority 1.0
    end_block


    ;; Reserve units protecting RIGHT flank of Ranged Missile Units
    begin_block 8
    max_units 1
    unit_type non_phalanx_spear 1.0
    unit_type light infantry 0.9
    unit_type heavy infantry 0.5
    default_melee_state fire_at_will_and_defend
    block_formation line
    block_relative_pos 4 0.0 -18.0
    inter_unit_spacing 10.0
    priority 1.0
    end_block


    ;; Ranged missile anti-elephant corner unit LEFT SIDE behind combined-phalanx
    begin_block 9
    min_units 1
    max_units 1
    unit_type ranged_missile_infantry 1.0
    default_melee_state fire_at_will_and_defend
    max_unit_width 40
    block_formation line
    block_relative_pos 3 10.0 -15.0
    inter_unit_spacing 10.0
    priority 1.0
    end_block


    ;; Ranged missile anti-elephant corner unit RIGHT SIDE behind combined-phalanx
    begin_block 10
    min_units 1
    max_units 1
    unit_type ranged_missile_infantry 1.0
    default_melee_state fire_at_will_and_defend
    max_unit_width 40
    block_formation line
    block_relative_pos 4 -10.0 -15.0
    inter_unit_spacing 10.0
    priority 1.0
    end_block


    ;; Ranged missile fire-suppression units CENTER behind phalanx
    begin_block 11
    unit_type ranged_missile_infantry 1.0
    default_melee_state fire_at_will_and_defend
    max_unit_width 40
    block_formation line
    block_relative_pos 0 0.0 -18.0
    inter_unit_spacing 15.0
    priority 1.0
    end_block


    ;; generals cavalry on the RIGHT flank
    begin_block 12
    unit_type general_unit 1.0
    default_melee_state defend
    unit_formation square
    unit_density close
    block_formation line
    block_relative_pos 4 15.0 0.0
    inter_unit_spacing 15.0
    priority 1.0
    end_block


    ;; heavy cavalry on the LEFT flank
    begin_block 13
    unit_type heavy cavalry 1.0
    default_melee_state fire_at_will_and_defend
    unit_formation square
    unit_density close
    block_formation line
    block_relative_pos 3 -15.0 0.0
    inter_unit_spacing 15.0
    priority 1.0
    end_block


    ;; heavy cavalry on the RIGHT flank
    begin_block 14
    not_general
    unit_type heavy cavalry 1.0
    default_melee_state fire_at_will_and_defend
    unit_formation square
    unit_density close
    block_formation line
    block_relative_pos 12 15.0 0.0
    inter_unit_spacing 15.0
    priority 1.0
    end_block


    ;; light cavalry on the LEFT flank
    begin_block 15
    not_general
    unit_type light cavalry 1.0
    default_melee_state defend
    unit_formation square
    unit_density close
    block_formation line
    block_relative_pos 13 -15.0 0.0
    inter_unit_spacing 15.0
    priority 1.0
    end_block


    ;; light cavalry on the RIGHT flank
    begin_block 16
    not_general
    unit_type light cavalry 1.0
    default_melee_state defend
    unit_formation square
    unit_density close
    block_formation line
    block_relative_pos 14 15.0 0.0
    inter_unit_spacing 15.0
    priority 1.0
    end_block


    ;; missile cavalry on RIGHT flank
    begin_block 17
    not_general
    unit_type missile cavalry 1.0
    default_melee_state fire_at_will_and_skirmish
    unit_formation square
    unit_density close
    block_formation line
    block_relative_pos 16 0.0 15.0
    inter_unit_spacing 15.0
    priority 1.0
    end_block


    ;; missile cavalry on LEFT flank
    begin_block 18
    not_general
    unit_type missile cavalry 1.0
    default_melee_state fire_at_will_and_skirmish
    unit_formation square
    unit_density close
    block_formation line
    block_relative_pos 15 0.0 15.0
    inter_unit_spacing 15.0
    priority 1.0
    end_block


    ;; artillery and spillover behind
    begin_block 19
    unit_type handler 1.0
    unit_type siege 1.0
    unit_type any 0.1
    default_melee_state fire_at_will_and_defend
    block_formation line
    block_relative_pos 0 0.0 -35.0
    inter_unit_spacing 15.0
    priority 0.1
    end_block

    end_formation

    ***********************************************************************************************************
    Last edited by phalanx_man; September 24, 2013 at 08:51 PM. Reason: Spelling.

  15. #15

    Default Re: Modifying Formation AI version 2

    What the formations file does is to tell the AI how to place its units when in a given combat state. It does not however dictate when and how to switch from one combat state to the other. So, while your formations might be awesome, the AI will go from "attack" to "defend" (and vice versa) whenever it feels like, based on variables we do not have access to. So, there's nothing (in the formations file or elsewhere) that can help with your problem.

  16. #16
    Foederatus
    Join Date
    Mar 2010
    Location
    Brownsville, TX
    Posts
    47

    Default Re: Modifying Formation AI version 2

    Too bad...

    I kept wondering why (in my mod) when AI-non-phalanx-army attacks AI-phalanx-army, why the AI-phalanx has such high casualties whereas human(me)-phalanx does not.

    No I see why since, if (on defend mode) it simply moved forward then (when individual unit attacks individual enemy unit) the solid wall of the phalanx becomes a saw-tooth with all their flanks exposed.

    Yet it is still strangs, because in many battles when I am attacking an AI-army, that army will (after START BETTLE) simply stay put and wait for me - and this USUALLY seems to happen when the overall power bar is in my favor (even if only slightly in my favor). And they ALWAYS stay put if the power bar is heavily in my favor. Yet in the play testing I just referred to, even though the power bar is 2-to-1 in my favor, the (supposedly weaker AI) still attacks me rather than waiting.

    And this even happened when I removed all flags except defend.

    So, it seems that even while ONLY DEFENDING, the AI can still decide to attack - which makes no sense.

    Makes you wonder how much (or how in-depth) beta-testing is really done before a game is released.

    Anyway, thanks for the info - at least I know there is nothing I can do about it.

    Regards,
    Vlad "phalanx_man"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •