Results 1 to 1 of 1

Thread: Basics of Battle AI and Pathfinding

  1. #1
    z3n's Avatar State of Mind
    Patrician Artifex Modding Staff Director

    Join Date
    Aug 2011
    Posts
    3,697

    Default Basics of Battle AI and Pathfinding

    These are some important points about how the Battle AI and pathfinding actually function, as it is important to get a sense of that before understanding anything else.

    Firstly the pathfinding we have access to is unit based, not army based. Army based pathfinding is independent and functions on the exe level, to confirm this for yourself, simply disable the pathfinding for units by entering a value of 0.


    You will see that rout pathfinding becomes entirely non existent.
    What this means is that units (not armies) rout. Which again is an indication of the above.


    Code:
    multires_pathfinder
    {
        ; Configuration parameters for the scheduler
        scheduler_configuration
        {
            ; low load config
            load low
            {
                max_paths        0        ; maximum paths till shifting to the next loading
                total_nodes        0        ; total nodes allocated across all paths
            }
    
    
            ; medium load config
            load medium
            {
                max_paths        0        ; maximum paths till shifting to the next loading
                total_nodes        0         ; total nodes allocated across all paths
            }
    
    
            ; high load config
            load high
            {
                max_paths        0        ; maximum paths till shifting to the next loading
                total_nodes        0        ; total nodes allocated across all paths
            }
            
            ; low priority config
            priority low
            {
                budget            0        ; percentage of budget for these paths
                max_nodes        0        ; maximum nodes per path
                max_zone_nodes    0        ; maximum zone nodes per path
            }
    
    
            ; medium priority config
            priority medium
            {
                budget            0            ; percentage of budget for these paths
                max_nodes        0        ; maximum nodes per path
                max_zone_nodes    0        ; maximum zone nodes per path
            }
            
            ; high priority config
            priority high
            {
                budget            0        ; percentage of budget for these paths
                max_nodes        0        ; maximum nodes per path
                max_zone_nodes    0        ; maximum zone nodes per path
            }
            
            ; real time priority config
            priority real_time
            {
                budget            0.0            ; percentage of budget for these paths
                max_nodes        0        ; maximum nodes per path
                max_zone_nodes    0        ; maximum zone nodes per path
            }
            
            ; quick test priority config
            priority quick_test
            {
                budget            0.0            ; percentage of budget for these paths
                max_nodes        0        ; maximum nodes per path
                max_zone_nodes    0        ; maximum zone nodes per path
            }
        }
    It is important to note that to regenerate the pathfinding db you have to change this number at the top of the descr_pathfinding text file.
    Code:
    version_info
    {
        63
    }
    We can explore how exactly the army pathfinding (exe level we don't have direct access into) works by using the show_cursorstat command on the battle map. Simply hover your cursor over some ground, open the console using your tilde key (or whichever opens the console on your keyboard) then type show_cursorstat and you will get output that looks something like this. The picture explains quite a few things, first that the battlemap is based on a graph. This is quite sensible, and as it is a graph the graph is what the AI uses when ordering troops to move.

    You can corroborate this via scripting and commanding groups to move to a certain point of the battlefield. Note that the points on the battlefield are listed as x, h, y or x position height and the y position. Anyone who has had to do math at some point probably knows what I am talking about in regards to the x and y axis, if not check out this picture as it may explain what I cannot.


    The next part is connected to this and explains why some may find that formations actually helps the AI at times in a small way, although it can also be a detriment to the AI as well.

    When changing the descr_formations_ai we can see several things,

    1) The existence of 'blocks' (see this picture for what it may look like, while imagining a graph layout under the blocks)
    2) The relative_pos or relative position of a block which is set in a similar x and y format, what this does is offset a block from the other blocks. Once the main formation was ordered to be in or move into an x and y point the blocks will form up sequentially and in their relative position to each of the others
    3) The blocks are likely what are considered 'units' by the AI, further the pathfinding file we can use is used in regards to blocks and their movement on the battlemap itself. Note that the AI does have and recognize basic definitions for the type of unit like cavalry, melee infantry, missile and so on.


    0,0 is the main point on the battlefield, this holds true for both siege and field battles.

    Lastly thanks to Argantonio we can understand how exactly the configuration for the battle AI is used. According to information that is written into our RAM directly from the exe, in the exe there are instructions exist to read strings, are strings are the data inside of the config_ai_battle.
    Code (config_ai_battle) is interpreted by the AI and translated/applied into direction: front, right, left, rear on battlefield. Decisions are made around battle direction as well as a few other factors but this is just explaining the basics. For example as you further explore things you may notice there is threat detection in regards to opposing units and it does work in regards to threat elevation, changing values in the extreme will show this in the way the AI places units on the battlefield in regards to hills and such.
    Last edited by z3n; March 11, 2016 at 12:25 PM. Reason: Clearer explanations
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

Posting Permissions

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