Difference between revisions of "Combat AI"

From Divinity Engine Wiki
Jump to: navigation, search
Line 9: Line 9:
 
The skill conditions panel can be used to set conditions for casting a skill (e.g. prohibit using a skill if the caster is still full health), set flags for the skill, or apply a simple score modifier.
 
The skill conditions panel can be used to set conditions for casting a skill (e.g. prohibit using a skill if the caster is still full health), set flags for the skill, or apply a simple score modifier.
 
<ul>
 
<ul>
<li>AiFlags: AiFlags can be set on a [[#AiFlags|skill on a global level]], but they can also be set in the skill conditions. A list of the flags and what they do can be found [[CombatAi_AiFlags|here]]</li>
+
<li>AiFlags: AiFlags can be set on a [[#AiFlags|skill on a global level]], but they can also be set in the skill conditions. A list of the flags and what they do can be found [[CombatAi_AiFlags|here]]. It is possible to use multiple flags by concatenating them with a semicolon (';')</li>
 
<li>MinimumImpact: The skill should impact at least this amount of characters in a <i>positive</i> way, or else it can not be used. Positive in this case means it's benefitial for the caster: e.g. healing an ally, or damaging an enemy</li>
 
<li>MinimumImpact: The skill should impact at least this amount of characters in a <i>positive</i> way, or else it can not be used. Positive in this case means it's benefitial for the caster: e.g. healing an ally, or damaging an enemy</li>
 
<li>OnlyCastOnSelf: The skill can only be cast on self. Can be used, for example, to force a character to only use the bless skill on itself</li>
 
<li>OnlyCastOnSelf: The skill can only be cast on self. Can be used, for example, to force a character to only use the bless skill on itself</li>
Line 33: Line 33:
  
 
=Overriding Ai=
 
=Overriding Ai=
 +
It's strongly advised to not override the Ai, but we understand that it's needed from time to time. Below are some supported ways to override the Ai and some tips and tricks you might want to use.
 
===Skills===
 
===Skills===
 +
The skills in [[skill_creation|SkillData]] have several properties that affect the Ai in a special way.
 
====Skill overrides====
 
====Skill overrides====
 +
Several skill types have the possibility to be overwritten with the score of a specified <b>Target</b> skill (can not be of any other type) in the AiCalculationSkillOverride column. If a skill has an override it will calculate the score by simulating with the Target skill instead of the original skill. This can be used to make the Ai think a skill will do something that it won't actually do, but some skills actually need to have an override skill:
 +
<ul>
 +
<li>Summon skills: Ai does not know what kind of impact a summon will have. The AiCalculationSkillOverride skill will be used to calculate the impact of the summon.</li>
 +
<li>Projectile skills with a filled in SpawnObject: Just like with Summon skills Ai does not know what kind of impact a summon will have. The AiCalculationSkillOverride skill will be used to calculate the impact of the summon.</li>
 +
</ul>
 +
Next to Summon and Projectile skills it is also supported by Shout and Target skills.
 +
<br />
 +
The override skill can be fairly simple, just like the Target_DummyTargetSkill that we use in a couple of cases. However, it's advised to make the override skill as accurate as possible. E.g.: for a Summon skill that spawns a summon that does only fire damage you shouldn't use an override skill that only does physical damage. Ai might then cast the summon in the middle of a group of enemies that are all immune to fire damage. Use a target skill that represents the actual summon as accurate as you possibly can.
 
====AiFlags====
 
====AiFlags====
 +
The AiFlags column is used to set flags specifically for Ai. A list of the flags and what they do can be found [[CombatAi_AiFlags|here]]. It is possible to use multiple flags by concatenating them with a semicolon (';').
 
===Scripting===
 
===Scripting===
  

Revision as of 15:41, 11 September 2017

Introduction

Ai 2.0 or, as we'd like to call it, Jane (used to be an abbreviation, but we already forgot about it the next day) no longer uses a script for every single skill to reason about its usage. Almost all logic has been moved to code, and all that's left in script is starting the Ai calculation, stopping the Ai calculation, and executing the action that has been selected by Ai. This script logic can be found in DefaultBehaviour.charScript. The Ai now takes into account the properties of a skill, the statuses that are applied, the weapons that are used, the items nearby, etc. It (attempts) to simulate what's going to happen if it will use a certain skill at a certain target and assign a score to it. The action with the highest score will be executed. All this happens automatically, so a new skill or status can be used by Ai without any extra steps. Of course, there are exceptions, and you'd still like to guide or override the Ai from time to time. That's what this page tries to cover in detail.

Guiding Ai

There are multiple ways to guide Ai into certain actions or behaviour. Skill conditions, archetypes and modifiers, and AiHints are all supported by Ai and are used by Ai during the score calculation. Any other way to guide Ai might result in incorrect behaviour (but you're welcome to try).

Skill conditions

CombatAi SkillConditions.PNG

The skill conditions panel you get when adding a skill to a character The skill conditions panel can be used to set conditions for casting a skill (e.g. prohibit using a skill if the caster is still full health), set flags for the skill, or apply a simple score modifier.

  • AiFlags: AiFlags can be set on a skill on a global level, but they can also be set in the skill conditions. A list of the flags and what they do can be found here. It is possible to use multiple flags by concatenating them with a semicolon (';')
  • MinimumImpact: The skill should impact at least this amount of characters in a positive way, or else it can not be used. Positive in this case means it's benefitial for the caster: e.g. healing an ally, or damaging an enemy
  • OnlyCastOnSelf: The skill can only be cast on self. Can be used, for example, to force a character to only use the bless skill on itself
  • StartRound: The skill can only be used from this round. Everything below and including 1 means it can be used from the start
  • HasNoMagicalArmor: The skill can only be used if the source/target has no magical armor
  • HasNoPhysicalArmor: The skill can only be used if the source/target has no physical armor
  • MaximumHealthPercentage: The skill can only be used if the source/target has a health percentage lower or equal to this value
  • MinimumHealthPercentage: The skill can only be used if the source/target has a health percentage higher or equal to this value
  • Tags: The skill can only be used if the source/target has these tags

You may have noticed that the italic conditions in above list are listed twice in the skill conditions. It's possible to set these for both the source (the caster of the skill) and the target of the skill (if the skill has a direct target). Tip: Tags can be used for any skill condition that is not part of the standard skill conditions. You can create a custom tag and a script that assigns/removes a tag based on scripted conditions.
The last skill conditions are the difficulty modes. These are simple checkboxes to enable/disable a skill on a certain difficulty. The very last thing on the list, the score modifier, is exactly what it says it is: a score modifier. If you want the Ai to use a skill more often, even if it's not that good at all, you could increase the score modifier. You could also use to, for example, force Ai to cast a certain skill after an event: set a high score modifier and set a source tag condition for a tag that you apply via script.

Archetypes and modifiers

AiHints

CombatAi AiHints.PNG

The EXTERN script variables AiHints and StayInAiHints You can assign a tag to the EXTERN AiHint parameter in the DefaultBehaviour script for the Ai to use. Ai will find AiHintAreaTriggers with this tag and use these during the calculation. The AiHintAreaTriggers with the specified tag (referred to ai AiHints from now on) are areas where the Ai would prefer to stand when attacking. You could use this when you, for example, want a ranger to prefer standing on some platforms in the back instead of on the lower ground. Keep in mind that it does not force the Ai to stay in the AiHint. For that you also need to enable the StayInAiHints parameter in the same DefaultBehaviour script. This forces the Ai to always stand in the AiHint, even if it blocks it from attacking. There's only 2 exceptions to this rule:

  1. All of the AiHints are filled with dangerous surfaces (all of them full of fire for example)
  2. The character has been moved outside of the AiHint (started outside of it or has been teleported for example) and is not able to attack anyone from any AiHints. In this case it will try to attack anyone without moving.

Overriding Ai

It's strongly advised to not override the Ai, but we understand that it's needed from time to time. Below are some supported ways to override the Ai and some tips and tricks you might want to use.

Skills

The skills in SkillData have several properties that affect the Ai in a special way.

Skill overrides

Several skill types have the possibility to be overwritten with the score of a specified Target skill (can not be of any other type) in the AiCalculationSkillOverride column. If a skill has an override it will calculate the score by simulating with the Target skill instead of the original skill. This can be used to make the Ai think a skill will do something that it won't actually do, but some skills actually need to have an override skill:

  • Summon skills: Ai does not know what kind of impact a summon will have. The AiCalculationSkillOverride skill will be used to calculate the impact of the summon.
  • Projectile skills with a filled in SpawnObject: Just like with Summon skills Ai does not know what kind of impact a summon will have. The AiCalculationSkillOverride skill will be used to calculate the impact of the summon.

Next to Summon and Projectile skills it is also supported by Shout and Target skills.
The override skill can be fairly simple, just like the Target_DummyTargetSkill that we use in a couple of cases. However, it's advised to make the override skill as accurate as possible. E.g.: for a Summon skill that spawns a summon that does only fire damage you shouldn't use an override skill that only does physical damage. Ai might then cast the summon in the middle of a group of enemies that are all immune to fire damage. Use a target skill that represents the actual summon as accurate as you possibly can.

AiFlags

The AiFlags column is used to set flags specifically for Ai. A list of the flags and what they do can be found here. It is possible to use multiple flags by concatenating them with a semicolon (';').

Scripting

Unsupported properties

Skills

Statuses

Debugging Ai