Jump to content

how to write/debug AI routines?


davidlallen

Recommended Posts

on 1:

Ini files are basically stupid texts, they don't carry functionality itself. For an ini file to work, there needs to be a function, a class, somewhere in the .uc files that read out the ini and actually do stuff. All the branches of the AI trees eventually lead to an action or a condition that will need to be handled by a class.

If you want to know more, open up the Default project and make a projectwide search for "IsAbilityAvailable". That will lead you to where in the uc's the ability is defined.

 

on 2:

Yes, this is something that modders should very much worry about. I actually started a big overhaul of my AI file yesterday and i plan on doing exactly what you propose, adding the prefix "ABA_" to many of my behaviours. (My biggest regret with Better ADVENT is not doing that to all of my character and weapon templates as well.)

So what happens if you have two entries in the behaviours with the same name, one from mod A and one from mod B? The debugger will show a redscreen output stating that it is going to ignore one of them. Which one, does indeed depend on whatever passes as a load order for XCOM.

In the case of TryFaceoff, ignoring one of them shouldn't cause much of a problem. Mod A and B are probably doing something very similar there so whichever one wins, stuff will most likely still work when a unit from mod A calls the TryFaceoff line defined from mod B.

You are of course right that it's better to avoid it from the start by using a mod specific prefix.

Link to comment
Share on other sites

  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

Hm. I added a small number of IsAbilityAvailable-xyz, beyond what was in ABA, and they seemed to work without any uc. I will investigate more in 8 hours from now. I wasn't able to get my grenadier to use the launcher yet, he just runs in circles. If you have two behaviors with the same name, in an ini file with the + syntax, doesn't the second one *silently* take precedence over the first one?

Link to comment
Share on other sites

Speaking of AI, one of the more frustrating hurdles we've got with the Escalation classes is the target unit's behavior when Flush is used on them. The behavior for most units is desirable because they tend to run away from the user towards their default range, but melee units specifically will charge the player's units because their default range is 1 or 0.

 

DerBK, do you know if there's a straightforward way to make the unit simply open up distance between them and the enemy rather than moving relative to the default range? I couldn't really find anything along those lines in the weights for move tile selection.

Link to comment
Share on other sites

Speaking of AI, one of the more frustrating hurdles we've got with the Escalation classes is the target unit's behavior when Flush is used on them. The behavior for most units is desirable because they tend to run away from the user towards their default range, but melee units specifically will charge the player's units because their default range is 1 or 0.

 

DerBK, do you know if there's a straightforward way to make the unit simply open up distance between them and the enemy rather than moving relative to the default range? I couldn't really find anything along those lines in the weights for move tile selection.

Flush is supposed to make a target run away for one turn?

 

Not sure on the details, but somewhere in class XComGameState_AIGroup.uc is a retreat function that triggers once you reduce a pod to 1 member.

Maybe try finding out how that works exactly and try to see if you can either manually trigger it or if you can make your own ability from it?

Link to comment
Share on other sites

 

Speaking of AI, one of the more frustrating hurdles we've got with the Escalation classes is the target unit's behavior when Flush is used on them. The behavior for most units is desirable because they tend to run away from the user towards their default range, but melee units specifically will charge the player's units because their default range is 1 or 0.

 

DerBK, do you know if there's a straightforward way to make the unit simply open up distance between them and the enemy rather than moving relative to the default range? I couldn't really find anything along those lines in the weights for move tile selection.

Flush is supposed to make a target run away for one turn?

 

Not sure on the details, but somewhere in class XComGameState_AIGroup.uc is a retreat function that triggers once you reduce a pod to 1 member.

Maybe try finding out how that works exactly and try to see if you can either manually trigger it or if you can make your own ability from it?

 

 

Thank you for the suggestion. I have looked at that one, and it didn't appear like it would be applicable to our purpose. The issue is that it simply weights the AI's behavior for getting allied units in sight. If the unit is still with their own pod, however, then they already have their allies in sight.

Edited by Lucubration
Link to comment
Share on other sites

Can you change the moveweightprofile that is used to weigh tiles for your ability?

 

If so, maybe you can make a new one in XComAI.ini like

m_arrMoveWeightProfile=(Profile=Flush, fCoverWeight=3.0f, fDistanceWeight=0.0f, fFlankingWeight=0.0f, fEnemyVisWeight=0.0f, fEnemyVisWeightPeak1=2.0, fAllyVisWeight=1.0f, fCloseModifier=0.9f, fFarModifier=1.1f)

and start experimenting with the different weights. I think you can actually use negative values here, so setting fEnemyVisWeight to something like "-2.0f" might produce interesting results.

Link to comment
Share on other sites

I wasn't able to get my grenadier to use the launcher yet, he just runs in circles.

 

 

I can't figure this out. I have added the aoe profile and everything else that I seem to need. But when I "dropunit ht_gren 1" to get this unit, it just runs in circles. When I "dropunit ht_gren 0", I can fire the grenade launcher properly, so that part works.

 

Here's XComAI.ini. Can you spot anything wrong?

 

In case you want to see the full mod files, the zip file is here (ready to play; not the modbuddy directory)

 

http://jendaveallen.com/Temp/WeirdLauncher.zip (17KB)

[XComGame.XGAIBehavior]

+AoEProfiles=( Profile=HT_LaunchProfile, Ability=LaunchGrenade, bUsePrecomputePath=1, bFailOnFriendlyFire=1)
[XComGame.X2AIBTBehaviorTree]
; General sequence

+Behaviors=(BehaviorName=HT_Gren_Root, NodeType=Selector, Child[0]=TryJob, Child[1]=GenericGreenMovement, Child[2]=HT_Gren_RedAlert, Child[3]=GenericAlertHandler)

+Behaviors=(BehaviorName=HT_Gren_RedAlert, NodeType=Sequence, Child[0]=IsRedAlert, Child[1]=HT_Gren_RedAbilitySelector)

+Behaviors=(BehaviorName=HT_Gren_RedAbilitySelector, NodeType=Selector, Child[0]=MimicBeaconBehavior, Child[1]=HT_Gren_RedFirstAction, Child[2]=HT_Gren_RedLastAction)

+Behaviors=(BehaviorName=HT_Gren_RedFirstAction, NodeType=Sequence, Child[0]=NotLastActionPoint, Child[1]=HT_Gren_RedFirstActionSelector)

+Behaviors=(BehaviorName=HT_Gren_RedFirstActionSelector, NodeType=Selector, Child[0]=DoIfFlankedMove, Child[1]=HT_TryMoveThenLaunch, Child[2]=MoveAggressive, Child[3]=HuntEnemyWithCover)

+Behaviors=(BehaviorName=HT_Gren_RedLastAction, NodeType=Sequence, Child[0]=IsLastActionPoint, Child[1]=HT_Gren_RedLastActionSelector)

+Behaviors=(BehaviorName=HT_Gren_RedLastActionSelector, NodeType=Selector, Child[0]=HT_TryLaunch, Child[1]=HuntEnemyWithCover, Child[2]=MoveAggressive)
; My grenade stuff

+Behaviors=(BehaviorName=HT_TryMoveThenLaunch, NodeType=Selector, Child[0]=HT_TryMoveBeforeLaunch, Child[1]=HT_TryLaunch)

+Behaviors=(BehaviorName=HT_TryMoveBeforeLaunch, NodeType=Sequence, Child[0]=SafeToMove, Child[1]=IsAbilityAvailable-LaunchGrenade, Child[2]=FindPotentialAoETargets-HT_LaunchProfile, Child[3]=HT_MoveStandardIfFirstAbilityLaunch)

+Behaviors=(BehaviorName=HT_MoveStandardIfFirstAbilityLaunch, NodeType=Sequence, Child[0]=IsAbilityAvailable-StandardMove, Child[1]=NotLastActionPoint, Child[2]=HT_FindLaunchDestination, Child[3]=SelectAbility-StandardMove)

+Behaviors=(BehaviorName=HT_TryLaunch, NodeType=Sequence, Child[0]=IsAbilityAvailable-LaunchGrenade, Child[1]=FindPotentialAoETargets-HT_LaunchProfile, Child[2]=SelectAoETarget-HT_LaunchProfile, Child[3]=SelectAbility-LaunchGrenade)

+Behaviors=(BehaviorName=HT_FindLaunchDestination, NodeType=Sequence, Child[0]=ResetDestinationSearch, Child[1]=RestrictToAbilityRange-LaunchGrenade, Child[2]=RestrictToEnemyLoS, Child[3]=FindRestrictedDestination-Standard)
; Names automatically split in uc

+Behaviors=(BehaviorName=FindPotentialAoETargets-HT_LaunchProfile, NodeType=Action)

+Behaviors=(BehaviorName=SelectAoETarget-HT_LaunchProfile, NodeType=Action)

+Behaviors=(BehaviorName=IsAbilityAvailable-LaunchGrenade, NodeType=Condition)

+Behaviors=(BehaviorName=RestrictToAbilityRange-LaunchGrenade, NodeType=Action)

+Behaviors=(BehaviorName=SelectAbility-LaunchGrenade, NodeType=Action)
Link to comment
Share on other sites

Regarding a specialist plus gremlin for healing, so far I cannot manage to dropunit a gremlin. I have an enemy whose secondary weapon is a gremlin; but when I dropunit the enemy there is no gremlin. I can use the gremlin heal button, but I get bunch of redscreens saying it couldn't find a gremlin to use. How did you get past this problem?

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...