Page 7 of 11 FirstFirst 1234567891011 LastLast
Results 121 to 140 of 204

Thread: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

  1. #121
    GRANTO's Avatar Domesticus
    Join Date
    Dec 2010
    Location
    glastonbury uk
    Posts
    2,207

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Quote Originally Posted by CavalryCmdr View Post
    That makes sense, basically an order of priority. I suspect the 'best' would not be universal at all. After the weekend I will test different orders for different factions, putting what I think would be the best personality first, the second best second etc, to see if I get any noticeable differences.
    yes.

  2. #122

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Thank you for this magnificent guide. I have one small question regarding the retreat analyser part.

    Quote Originally Posted by z3n
    The retreat counter is code that controls how difficult it is to rout units. Higher = more difficult, while lower = easier.
    The retreat counter applies for both enemy and player units, right?
    I'm assuming so, since the original values for it fall with increasing difficulty (200 at easy to 100 at very hard); and unless it affected the player, this would make no sense. Though even as it is, it makes little sense, since it would enable the player to rout AI enemy more easily via flanking. Is this a known & accepted flaw of the original code, or does harder difficulty give the AI an edge via another way?
    Last edited by Santikaye; March 11, 2016 at 03:01 PM.

  3. #123
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    @Granto/CavalryCmdr
    Still running my own tests, unfortunately I've been set back by adjusting several parts of the configuration of my own AI, At present I have to a) adjust some parameters related to rebel invasions and b) set a baseline test.
    Hopefully I'll get it done soon and be able to report my own findings, a little put out I couldn't get it done yesterday but I was doing the above yesterday as well.


    Quote Originally Posted by Santikaye View Post
    Thank you for this magnificent guide. I have one small question regarding the retreat analyser part.



    The retreat counter applies for both enemy and player units, right?
    I'm assuming so, since the original values for it fall with increasing difficulty (200 at easy to 100 at very hard); and unless it affected the player, this would make no sense. Though even as it is, it makes little sense, since it would enable the player to rout AI enemy more easily via flanking. Is this a known & accepted flaw of the original code, or does harder difficulty give the AI an edge via another way?


    I see I glossed over this by only posting this, in any case I can't really update it as I'm already at the character limit for the post.
    The retreat counter is code that controls how difficult it is to rout units. Higher = more difficult, while lower = easier.
    To explain the principle which I believe only applies to the AI, inside the M2TW scripting language we have something called 'counters' currently I use a similar principle in the battle script I'm finishing at the moment called 'command and control'.

    What the code is doing, is increasing a counter every few milliseconds and eventually the counter hits 125 after a couple of seconds at most, at which it is reset to 0. However in between that time frame various commands are fired off and checked at key points in the time frame not all at once, due to the fact that some CPU's probably couldn't process, monitor and execute all those commands at once if it was set to a single value.

    I suspect that the 'retreat_counter' is essentially just that, it tells the AI when it should order a unit to withdraw (subsequently causing a rout) when in a wavering state which in turn can cause a unit to rout, it could apply to the players units as well but I doubt it. It's probably why the AI would 'rout' more often when the retreat counter is lower. It's not routing, it is simply ordering a withdrawal at a sooner time. However, the morale system still works in the sense that units will arbitrarily rout according to the rout state in spite of the counter being a fantastically high value.

    The reason it could order such a thing is due to the units at times being able to 'regroup'. I vaguely recall there being some issues in regards to AI withdrawel of cavalry as well when changing the values higher but that could have been the multipliers or the strength ratio. I can't recall which it was. Be aware of that issue though, it's especially prevalent with heavy cavalry and would be something to avoid as AI cavalry cycle charging is something to encourage in my opinion.


    You can look at an example of what I'm talking about here (I helpfully bolded the important parts ).

    Code:
        ; *********************************************************************************************
        ;	EBII Battle Scripts
        ;	10/3/2015
        ;	z3n
        ; *********************************************************************************************
    
    
        while ! I_BattleStarted
        end_while
    
    
        ; *********************************************************************************************
        ;	EBII Battle Script Counteres/Timers
        ; *********************************************************************************************
    
    
        declare_counter command_and_control
        declare_counter deploy_check
        declare_counter start_battle
        declare_counter FaW_and_S
        declare_counter Release_Labels
        declare_counter AI_GRP
        declare_counter AI_HTC
        declare_counter AI_reinforcements
        declare_counter AI_reinforcements_tc
        declare_counter capture_pike
        declare_counter capture_hoplite
        declare_counter medium_battle
        declare_counter large_battle
        declare_timer AI_reinforcements_timer
    
    
        log always EBII Campaign Based Battle Scripts
        log always Activated
    
    
        ; *********************************************************************************************
        ;	EBII Battle Script Frequency Check 
        ; *********************************************************************************************
    
    
        monitor_conditions I_InBattle
    
    
            inc_counter command_and_control 1
    
            if I_CompareCounter command_and_control = 125
                set_counter command_and_control 0
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;	Game Reloaded
        ; *********************************************************************************************
    
    
        monitor_event GameReloaded
    
    
            log always Game Reloaded
            set_counter deploy_check 0
            set_counter Release_Labels 0
            set_counter command_and_control 0
            set_counter AI_GRP 0
            set_counter AI_reinforcements 0
            set_counter AI_HTC 0
            log always Battle Scripts Reset
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;	Battle Starting
        ; *********************************************************************************************
    
    
        monitor_event ScrollClosed ScrollClosed prebattle_scroll
    
    
            prepare_for_battle
            set_counter command_and_control 0
            set_counter Release_Labels 0
            set_counter AI_GRP 0
            set_counter AI_reinforcements 0
            set_counter AI_HTC 0
            set_counter deploy_check 0
            set_counter capture_pike 0
            set_counter capture_hoplite 0
            set_counter medium_battle 0
            set_counter large_battle 0
            restart_timer AI_reinforcements_timer
    
    
            if I_CompareCounter deploy_check = 0
                log always Battle Loading
            end_if
    
    
        end_monitor
    
    *skipped a large part of the code*
    
        ; *********************************************************************************************
        ;	Initialize Battle Plans & Monitors
        ; *********************************************************************************************
    
    
        ; *********************************************************************************************
        ;	AI Reinforcement Plans
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 10
            and I_BattleStarted
            and I_ConflictType Normal
            and I_CompareCounter AI_reinforcements > 0
    
    
            if I_TimerElapsed AI_reinforcements_timer = 5000
                inc_counter AI_reinforcements_tc 1
            end_if
    
    
            if I_TimerElapsed AI_reinforcements_timer > 5000
                restart_timer AI_reinforcements_timer
            end_if
    
    
            ; *********************************************************************************************
            ;	AI Reinforcements Defend Plan
            ; *********************************************************************************************
    
    
            if I_CompareCounter AI_GRP = 0
            and I_CompareCounter AI_reinforcements_tc < 30
                ;AI Units from Army 1 Battle Objective - Disabled
                ;ai_gta_add_objective 0 DEFEND_LINE 999
                ;AI Army 1 Battle Objective
                ai_gta_plan_set 0 DEFEND_FEATURE
                ;AI Units from Army 2 Battle Objective - Disabled
                ;ai_gta_add_objective 1 DEFEND_LINE 999
                ;AI Army 2 Battle Objective
                ai_gta_plan_set 1 DEFEND_FEATURE
            end_if
    
    
            ; *********************************************************************************************
            ;	AI Reinforcements Reaction Plan
            ; *********************************************************************************************
    
    
            if I_CompareCounter AI_reinforcements > 0
            and I_CompareCounter AI_GRP > 0
                    ;AI Units from Army 1 Battle Objective
                    ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
                    ;AI Army 1 Battle Objective
                    ai_gta_plan_set 0 ATTACK_ALL
                    ;AI Units from Army 2 Battle Objective
                    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
                    ;AI Army 2 Battle Objective
                    ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
            ; *********************************************************************************************
            ;	AI Reinforcements Attack Plan
            ; *********************************************************************************************
    
    
            if I_CompareCounter AI_reinforcements_tc > 30
            and not I_BattlePlayerArmyIsAttacker
                    ;AI Units from Army 1 Battle Objective
                    ai_gta_add_objective 0 ATTACK_ENEMY_BATTLEGROUP 999
                    ;AI Army 1 Battle Objective
                    ai_gta_plan_set 0 ATTACK_ALL
                    ;AI Units from Army 2 Battle Objective
                    ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
                    ;AI Army 2 Battle Objective
                    ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;	Normal Attack Plan
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 20
            and I_BattleStarted
            and I_CompareCounter AI_reinforcements = 0
            and I_ConflictType Normal
            and not I_BattlePlayerArmyIsAttacker
    
    
            ;AI Units Battle Objective
            ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
            ;AI Alliance Battle Objective
            ai_gta_plan_set 1 ATTACK_ALL
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;	Normal Defend Plan
        ;	Recurring counters fire above 0
        ; *********************************************************************************************
    
    
        monitor_conditions I_CompareCounter command_and_control = 30
            and I_BattleStarted
            and I_CompareCounter AI_reinforcements = 0
            and I_ConflictType Normal
            and I_BattlePlayerArmyIsAttacker
    
    
            if I_CompareCounter AI_GRP = 0
                ;AI Units Battle Objective Main Army
                ;ai_gta_add_objective 1 DEFEND_LINE 999
                ;AI Alliance Battle Objective Main Army
                ai_gta_plan_set 1 DEFEND_FEATURE
            end_if
    
    
            if I_CompareCounter AI_GRP > 0
                ;AI Units Battle Objective
                ai_gta_add_objective 1 ATTACK_ENEMY_BATTLEGROUP 999
                ;AI Alliance Battle Objective
                ai_gta_plan_set 1 ATTACK_ALL
            end_if
    
    
        end_monitor
    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)

  4. #124

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Quote Originally Posted by z3n View Post

    I suspect that the 'retreat_counter' is essentially just that, it tells the AI when it should order a unit to withdraw (subsequently causing a rout) when in a wavering state which in turn can cause a unit to rout, it could apply to the players units as well but I doubt it. It's probably why the AI would 'rout' more often when the retreat counter is lower. It's not routing, it is simply ordering a withdrawal at a sooner time. However, the morale system still works in the sense that units will arbitrarily rout according to the rout state in spite of the counter being a fantastically high value.

    The reason it could order such a thing is due to the units at times being able to 'regroup'. I vaguely recall there being some issues in regards to AI withdrawel of cavalry as well when changing the values higher but that could have been the multipliers or the strength ratio. I can't recall which it was. Be aware of that issue though, it's especially prevalent with heavy cavalry and would be something to avoid as AI cavalry cycle charging is something to encourage in my opinion.
    Ah, so it's not determining when to rout, but when to withdraw (but it coincides with routing probably since a lot of men are killed when retreating).

    And the original values are getting lower with increasing difficulty because it is supposed to make the AI more proactive; though since it apparently induces routs instead of actually retreating, you chose to increase the counter with rising difficulty, am I correct? Or do you have other reasons?

    Also, to clarify why I was asking these: I am mainly curious on whatever causes player morale to go from eager to wavering quicker in hard difficulty (After seeing non-flanked knights fighting crossbow militia on enemy walls with "shaken" morale in hard difficulty, I got a bit baffled, and sought what code was responsible for it). Because I'd rather have high morale on enemy units than low morale on mine in harder difficulties. Do you know where this can be edited?

  5. #125
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Also, to clarify why I was asking these: I am mainly curious on whatever causes player morale to go from eager to wavering quicker in hard difficulty (After seeing non-flanked knights fighting crossbow militia on enemy walls with "shaken" morale in hard difficulty, I got a bit baffled, and sought what code was responsible for it). Because I'd rather have high morale on enemy units than low morale on mine in harder difficulties. Do you know where this can be edited?

    You could set this to 0, although it is fairly realistic to give defenders on a wall a bonus.
    Code:
                	<!-- bias towards defenders -->
                	<defender-bias>0.10</defender-bias>
    This is just my opinion but I am fairly certain player units on medium get a bonus, as I once did a few tests with a player phalanx versus an AI and the AI's would always lose. In addition my units in general never seemed to rout easily at all. Hard seems to 'balance' things out for most people, although I personally prefer very hard as it feels the most balanced for me with units routing rather realistically for the AI and the player as well.

    I believe by default units get a morale malus by simply being on the walls (further lowered by the towers firing at them if you have those), in addition to being attacked by an enemy who is receiving the 'wall' bonus which probably gives an additive bonus to their morale/attack.

    And the original values are getting lower with increasing difficulty because it is supposed to make the AI more proactive; though since it apparently induces routs instead of actually retreating, you chose to increase the counter with rising difficulty, am I correct? Or do you have other reasons?


    Yes, I chose to make the AI withdraw/cause a pseudo rout (as far as I understand it) less on a higher difficulty.
    However the AI will still withdraw its entire army once its casualties reach a certain point.
    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)

  6. #126

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Quote Originally Posted by z3n View Post

    This is just my opinion but I am fairly certain player units on medium get a bonus, as I once did a few tests with a player phalanx versus an AI and the AI's would always lose. In addition my units in general never seemed to rout easily at all.
    Might be. To me it felt like the enemy got a morale penalty on medium, which is why I switched to hard in hopes that it'd increase enemy morale. Instead, it seems that it made morale very fragile on both sides. Guess I'll get used to it somehow.

    Thanks for the explanations and tips!

  7. #127

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    After the weekend I will test different orders for different factions, putting what I think would be the best personality first, the second best second etc, to see if I get any noticeable differences.
    Well it's after the weekend and I tested it, and most definitely got noticeable differences. Shockingly bad differences. So on further testing I have come to the conclusion that it is reverse priority so the last personality has the highest priority.
    With the original setup by order of what I thought was best for that faction to worst the average army rating was C or worse (same rating system as before.) Switching it around so the worst was first and best last only 3 factions got C's with most B or B+ and a handful of A's, so it's a pretty significant difference.

    I am going to do some more tests trying alternating personalities (build, army, build, army etc) and with army personality first to see if that gets anything noticeable.

    Update:
    I did both those, I also tried adjusting the number of personalities, so I had 4 build and 4 recruit, as well as all build and only 1 recruit personality. Nothing produced results that could be mis-construed as favorable.

    alternating personalities (build, army, build, army etc) lost all the effects of the all personality, no aggression, no mass recruiting. TBH it was as if it just used the first two personalities. There was one noticeable exception, my Scotland faction produced superb armies with this setting, not sure why.

    Recruit first lost the aggression, but not the mass recruiting, and it's armies were really poor.

    4 build and 4 recruit, nothing, this was probably the worst personality combination in all my personality testing to date.

    All build and only 1 recruit personality did have the aggression and mass recruiting, but their armies were really bad, almost as if the single recruit personality could not keep up with what the build personalities were doing or demanding.

    I have to note that all these tests were done with the AI having limited money (what I call normal, no special AI income) so they are by no means not worth testing. That said, even with these setting the all personalities (operating in reverse priority) produces consistent results comparable to when the AI had unlimited income, just. obviously, on a smaller scale. If anything it was better because the AI was a little more picky in it's recruiting.

    So, unless someone has a suggestion that should produce noticeable results I am done testing. I will be using all personalities in reverse order for my mod. Thanks to GRANTO for prompting me to try it.
    Last edited by CavalryCmdr; March 16, 2016 at 03:21 PM. Reason: Update

  8. #128
    GRANTO's Avatar Domesticus
    Join Date
    Dec 2010
    Location
    glastonbury uk
    Posts
    2,207

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Thanks CC thats really interesting , is it a reverse of the one i posted earlier that you are using ? can you post it up thanks ...the way you are using it.

  9. #129

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    The exact order I used is not really relevant, because it was different for each faction.
    I took all the personalities (build then recruit) and put them in order on a per-faction basis from best-to-worst. Although that's not quite accurate, I took the definitions of the personalities and 'constructed' an order, going on the assumption that first gets the highest priority and last got lowest. I'll use France as an example:
    My France faction has strong heavy cavalry, average archers and light cavalry with slightly below average infantry so I ordered the personalities like so:
    Build personalities was mostly just guess work, and just put in order by what I would choose for that faction, simple as that
    craftsman trader fortified bureaucrat sailor religious comfort balanced
    I put a bit more work into the recruit personalities, the spoiler shows the specifics of my logic.
    henry smith genghis napoleon Caesar stalin mao
    Spoiler Alert, click show to read: 

    First I wanted heavy cavalry the center of the French armies, so 'henry' was the obvious choice. However France has, for the most part, a balanced roster, so I put 'smith' in next. After that it was a little challenging, France has poor light infantry, so the last thing I wanted was them to be mass numbers, so that puts 'stalin' and 'mao' last and put 'genghis' after 'smith' to 'push back' the infantry-centric personalities, then I chose 'napoleon' for archers and then 'Caesar' primarily because it was better then the last two, and France dose have a good heavy infantry in their Voulgier

    Final result being:
    Code:
    faction france, craftsman trader fortified bureaucrat sailor religious comfort balanced henry smith genghis napoleon Caesar stalin mao
    I did this independently for each faction. However, the results were horrendous. Looking the results over, and using knowledge gained from my previous personality tests by seeing patterns in the army builds, I came to the conclusion that the priority was actually on the last personality rather then the first. Luckily for me I set it up on a spreadsheet, so I just had to grab the personalities last-to-first for the next test, using France from above:
    Code:
    faction france, balanced comfort religious sailor bureaucrat fortified trader craftsman mao stalin Caesar napoleon genghis smith henry
    And lo, I got the results I had been hoping for with the first test.

    That's what I mean by 'reverse priority'

  10. #130
    GRANTO's Avatar Domesticus
    Join Date
    Dec 2010
    Location
    glastonbury uk
    Posts
    2,207

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    yes , thanks

  11. #131

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    So I followed your tutorial and made some changes of my own to the BAI to better represent 19th century warfare. Of course it is very different from medieval warfare, but I think I reached a decent point. However, there is on MAJOR thing that i'd like to fix. I need my line infantry to stay cohesively. well, in line. They shoot rather than charge, they behave as intended and even prefer to walk, however as soon as they stop to attack other infantry troops they form into a square, or turn the wrong way. I have seen this last behaviour in later titles so I suspect its something that cannot be fixed, but at least the first problem should be addressed.
    Can I do anything about it?

    PS I should note that I use spearmen as line infantry because they have bayonets to defend themselves against cavalry attacks.

  12. #132
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    other infantry troops they form into a square, or turn the wrong way.
    Are you referring to the way they form into a tighter formation when they commit? If so, the only thing that may help you here is in the descr_formations_ai with the min/max unit width of the block. However it is probably more of an engine/exe thing.

    If you are referring to the army formation these lines should help you.
    Changing them to higher values should help you in regards to that, less units will move around.

    Code:
                <formed-percentage>20</formed-percentage>
                <formed-percentage-finished>66</formed-percentage-finished>
    And there is also this one which can help in regards to units moving together during marching if you refer to that. Although due to the way unit grouping works you may have to increase the other supporting values (merge distance and strength tolerance) to make sure that the AI groups many if not all of its units.

    That may give you better results, although a lot of the marching code and pathfinding is hardcoded. In RTW we did have access to the march flag and formations but in M2TW this is not the case anymore. Hopefully this does help you.

    Code:
            <unit-group-speed-tolerance>0.25</unit-group-speed-tolerance>
    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)

  13. #133

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    If your referring to individual units, not inter-unit behavior, you have the 'formation' line in EDU, also, increased training (highly_trained) will help maintain unit cohesion, while lowering training (untrained) will help the unit perform even when not properly 'in formation' so the 'shifting' into position dose not stop the unit from doing something.

  14. #134

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    I'm referring to this



    and even my own troops if I double click on an enemy unit sometimes



    I tried adding this bit, with your advice and the formation that the team of the Secession mod used

    <attack-battlegroup>
    <tracking-tolerance>30.0</tracking-tolerance>
    <formed-percentage>80</formed-percentage>
    <formed-percentage-finished>90</formed-percentage-finished>
    <shootout-distance-tolerance>10</shootout-distance-tolerance>
    <fight>
    <!-- do not enter fight if the enemy missile strength is greater than this ratio times our missile strength -->
    <missile-ratio>0.6</missile-ratio>
    </fight>
    <formation>
    <easy>ai_triple_missiles_in_front_easy</easy>
    <medium>ai_triple_missiles_in_front</medium>
    <hard>ai_triple_missiles_in_front</hard>
    <very_hard>ai_triple_missiles_in_front</very_hard>
    </formation>
    <unit-group-speed-tolerance>0.25</unit-group-speed-tolerance>
    </attack-battlegroup>
    Overall the behaviour is better, however the lines still cross one another and the cavalry is a bit too passive. Also cavalrymen dont disengage anymore. I think i screwed up somewhere...

  15. #135
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    I'm still not entirely clear on what is wrong. Is it a combination of a more compressed formation (similar to a column) forming when you order an attack against units at times or is the problem a generally disordered AI army formation when marching?

    To clarify, could you perhaps take a video of the issue and upload it to youtube, vid me or some other video sharing site?

    <formed-percentage>80</formed-percentage>
    <formed-percentage-finished>90</formed-percentage-finished>
    Ah, the old cavalryman disengaging bug.

    Try lowering the formed percentage finished to 66 or thereabouts and formed percentage to 50 or 75, that may help.
    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)

  16. #136
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    I've found that this setting in the descr_campaign_db seems to affect the way the LTGD selects a target. It probably changes the way a towns strength is calculated which changes the expansion targets.

    Code:
         <use_new_sett_autoresolve bool = "false"/><!--do we use the new settlement autoresolve -->
    Flipping it from true to false (or false to true) produces different results. Also when set to true it seems the AI has a harder time against the towns, which means it does seem to expand slower as it has to pick 'weaker' targets when set to true. My default setting will likely stay false.
    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)

  17. #137

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Ok I have solved my earlier problem with a lot of trial and error. I have two more questions now:

    - Is there any way I can tell the game to rout automatically any troop that gets over 50-55 percent casualties? Either with morale penalty or pure scripting?

    - Can I force a specific formation until a certain distance from the player is reached? for example, I want the AI in marching columns formation until 200 meters away from the player's troops.

  18. #138
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Quote Originally Posted by Sirlion View Post
    Ok I have solved my earlier problem with a lot of trial and error. I have two more questions now:

    - Is there any way I can tell the game to rout automatically any troop that gets over 50-55 percent casualties? Either with morale penalty or pure scripting?

    - Can I force a specific formation until a certain distance from the player is reached? for example, I want the AI in marching columns formation until 200 meters away from the player's troops.
    Glad to hear that and yes everything takes a lot of trial and error unfortunately.

    Yes both of those things should be possible. It's rather advanced unfortunately so it may take you a lot more trial and error (speaking from experience) including learning how to write a battle script in its entirety, it will only apply during a campaign as well in theory. As background scripts via the advice won't work properly due to their inability to run and execute commands on the campaign map as well. Campaign scripts however can run on the campaign as well as battle map.

    I've only explored the theory and verified that the commands are valid for the 2nd part, I never actually got into executing any particular formation as I wanted to avoid adjusting that sort of thing, as I find formations have significant effects on where the AI moves its troops. The one issue with the 2nd part is that the marching code/formation is heavily tied into the exe now, so I'm not entirely sure whether you'll be able to change the formation like that.

    1) You can do this by monitoring a units casualty rate using I_PercentageUnitKilled and then forcing the unit to rout using the unit_set_morale command.

    2) You'd have to monitor I_UnitGroupDistanceFromGroup (after creating unit groups and labels) then use the unit_group_order_change_group_formation to change to a formation within the formations.txt file, keep in mind you should in theory be able to add in your own custom formations and reference to them there.


    The reason it is advanced is due to the fact that battle scripts (our ones, rather than the historical battle scripts) require continuous monitors which execute over and over to ensure it happens repetitively through your campaign each time you start the campaign and play several battles on the campaign map, what this means is you will need a counter system. You'll have to use inc_counter blah 1 (blah as an example name, and the 1 is the value of your counter, I use 1 or 0 to indicate whether the counter is in an on or off state), and then once the counter fires once it will continue to increase past 1. As you're only looking for the 'on' state of 1 using I_CompareCounter blah = 1 it means your script will only fire the once. You can use the script I designed with these two parts, these two set the value back to 0 upon starting a battle or reloading your game, this means your script is able to 'reset' itself for execution once each battle. You have to do this for two reasons, one a continuously executing monitor often doesn't work exactly how you intended, for example when setting the rout state and two because you don't want the AI to constantly go into the same formation which would be disastrous during a battle.

    Code:
        ; *********************************************************************************************
        ;    Game Reloaded
        ; *********************************************************************************************
    
    
        monitor_event GameReloaded
    
    
            log always Game Reloaded
           set_counter blah 0
            set_counter deploy_check 0
            set_counter Release_Labels 0
            set_counter command_and_control 0
            set_counter AI_GRP 0
            set_counter AI_reinforcements 0
            set_counter AI_HTC 0
            log always Battle Scripts Reset
    
    
        end_monitor
    
    
        ; *********************************************************************************************
        ;    Battle Starting
        ; *********************************************************************************************
    
    
        monitor_event ScrollClosed ScrollClosed prebattle_scroll
    
    
            prepare_for_battle
           set_counter blah 0
            set_counter command_and_control 0
            set_counter Release_Labels 0
            set_counter AI_GRP 0
            set_counter AI_reinforcements 0
            set_counter AI_HTC 0
            set_counter deploy_check 0
            set_counter capture_pike 0
            set_counter capture_hoplite 0
            set_counter medium_battle 0
            set_counter large_battle 0
            restart_timer AI_reinforcements_timer
    
    
            if I_CompareCounter deploy_check = 0
                log always Battle Loading
            end_if
    
    
        end_monitor
    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)

  19. #139

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Mh. So you say this is only possible in the campaign map battles and not historical \ custom battle? Well that's too bad, really. I find extremely silly that "units" with 2 men can still fight. That aspect I really wanted to change.
    However, knowing that everything can be scripted is a greatly reassuring fact, even if "only" for campaign battles, that will grant a far better experience than later titles. Besides, I have fun doing this. I'll try to follow your tutorials. I got to start from the bare bones of this discipline.

  20. #140
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: Understanding MTW2/Kingdoms.exe Pathfinding, XML and the AI

    Well not entirely, what I am saying is while it's possible to design it so that it happens during a custom battle the script will only execute once per game session (game session = from when you start the game until it is closed). I was able to make it work that way but only once while trying to get horse archers to rout after a specific percentage of troops were lost. To test for horse archers I looked for a specific special ability, set of attributes or perhaps class/category. You can test for (in your script) custom attributes as well by adding an attribute of your own name scheme into the EDU for the unit you want to check for in the battle. I then did what I told you (unit_set_morale) for each unit label. You could in theory use a group_set_morale command as well, never tried it though.

    The campaign/campaign script enables repetitive executions of those specific things (routing troops after a certain percentage dead and formations within a certain radius) I was able to get around the problem in regards to repetative executions for specific tasks (like attacking an enemy under certain conditions) in custom battles with a specially designed script so it's not to say you can't, I just couldn't figure out a way to do it for the tasks you asked in custom battles. In campaign battles it should be possible however.
    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
  •