AI attacking(Whenever the following text says 'seconds', they are ingame seconds. An ingame second is 15 frames regardless of game speed.)
= Attack force =`
attack_add` adds units to the current attack force. In other words, `attack_add 64 zergling` will fill the attack force completely, and additional attack_add commands won't do anything.
While all unit ids can be used for `attack_add`, unit ids of Science Vessel, Queen, Defiler, and High Templar will only move to the grouping region (see below) and do not actually attack the target. (Thanks Nekron)
As was stated earlier, `easy_attack` functions as `attack_add`, but only if the semi-unused difficulty value is 0. In practice it never does anything.
`
harass_factor` calculates the total strength of all enemy units (including buildings), and then multiplies the current attack force by `
((enemy_strength - 1) / parameter) - 1` Division is rounded down, multiplication is limited to range from 1 (no change) to 3.
= Grouping phase =If you've ever watched how the AI does its attacks, you've probably noticed that it sends the attack force somewhere near enemy base to group up before fully attacking. Both opcodes `
attack_prepare` and `
attack_do` initiate an attack, causing the attack force to group up at the
grouping region. If the grouping has already begun, `attack_prepare` does nothing. `attack_do` waits until the grouping has finished and the units start attacking before progressing in the script.
`
wait_finishattack` will wait until the both the grouping phase and the actual attack have finished, but it will not initiate an attack. If there is no attack going on at all, it does nothing.
This means that it is not necessary to use `attack_prepare` if the AI has nothing to do before `attack_do`. It is also fine to use just `attack_prepare` if halting the script for the grouping phase is not desired. `
attack_clear` clears the attack force and aborts any attack that is still in grouping phase, so using `attack_do` to guarantee that the grouping phase has finished is a good idea before attack data is cleared. Also, even if the attack has been done, `attack_clear` is necessary before another attack can be started.
The grouping region chosen is randomly for campaign AIs, while melee AIs use "nearest safe region" out of the possible grouping regions AI has decided. The regions are same regions as ones used in pathfinding, the new SCMDraft versions are able to show how regions are laid out. AI prefers using a region which is roughly 4 regions away from a enemy base.
The AI may decide to do an air-only attack if for some unusual reason it fails to find a grouping region for ground units.
If the AI doesn't have a complete attack force during the grouping phase, it will train the necessary units with priority of 60. But because of the grouping deadline (see below for details) it is a good idea to train most of the units beforehand. Also, Nekron found a bug with attack force training: If the AI needs to train Guardians/Devourers/Lurkers for the attack force, it will train a Mutalisk/Hydralisk as well. Sometimes this intermediate unit will be used for the actually required unit, but if the AI has another Muta/Hydra available, it will morph that and the other unit will end up just hanging around in the attack force even if it wasn't invited there.
Using `attack_add` during the grouping phase should work fine.
= Grouping deadline =The AI has a failsafe if grouping takes too long. After 120 (melee AI) or 180 (campaign AI) seconds, the grouping phase will end and the AI will send any unit that is part of the attack force to the enemy base, whether they had arrived at the grouping region or were still moving there. If the AI didn't get a chance to train all units on the attack force, then the attack will be done with a partial force.
The AI sometimes also just sucks at moving all the units to the (potentially small) grouping region, and will wait for the deadline even if the all units are roughly grouped properly.
`
quick_attack` will initiate the attack and will not wait for it to commence, like `attack_prepare`, but it will also reduce 175 seconds from the grouping deadline, so the AI will skip the grouping phase. I believe that using `quick_attack` in melee scripts is unpredictable, because the AI may realize that deadline is hit before it has even sent any military to group. Using `attack_do` after `quick_attack` to wait is still a good idea to make sure you don't clear attack forces before the AI realizes the deadline has been hit and commences the attack.
The following should work fine in melee scripts as well, using `quick_attack` to separately trigger the deadline after a manual wait. This would also allow shortening the deadline to different values.
`attack_prepare`
`wait 150`
`quick_attack`
Extending the deadline is not possible, other than doing something sketchy like `attack_clear` followed by immediate attack force rebuilding and a new `attack_prepare`, though this will obviously duplicate the attack if it had already commenced. Additionally, the attack deadline is specified in "seconds from game start" - if `quick_attack` is used to reduce the deadline below zero (it wraps
around to 4 billion seconds), the AI will never hit it, which will hang the script if `attack_do` is also used and the AI fails at
grouping as usual.
= eval_harass =`
eval_harass` will initiate attack if it has not been yet (without waiting for grouping), and then it will calculate the strength of the own attack force and enemy units in 32-tile range around the target region. If either the ground or air strength of own units is larger than the respective enemy strength, the script will jump to the label specified as parameter.
`eval_harass` will cause the grouping and attack to commence as usual, but it also can be canceled with `attack_clear` if you just want to use it for control flow instead of causing attacks.
= rush =`
rush` will use the regular attack initiation routines to pick a target, and picks the enemy building nearest to target location to determine which player it is attacking. After that it executes `attack_clear`, so any actual attacks will get reset. If, for some reason, BW fails to find any enemy buildings, it skips the `attack_clear` and commences with the attack... But in the usual case where the enemy player is decided, the script will jump if the enemy player fulfills the following condition:
0x49 - rush
Description: Jump to %2(block) if predifined condition scheme %1(byte) is met.
00 = Barracks OR Spawning Pool OR Gateway (includes incomplete)
01 = At Least 17 Marines + Bunkers, OR at least 16 Sunken Colonies + Hydralisks, OR at least 7
Zealots
02 = At least 25 Marines + Bunkers, OR At least 11 Mutalisks + Spore Colonies + Hydralisks
03 = At least 6 Marines + Bunkers, OR At least 3 Sunken Colonies + Hydralisks, OR Hydralisk Den?, OR
at least 2 Zealots
04 = At least 17 Marines + Bunkers, OR At least 16 Sunken Colonies + Hydralisks, OR at least 9
Zealots
05 = At least 7 Marines + Bunkers, OR at least 7 Sunken Colonies + Hydralisks, OR at least 4 Zealots
06 = At least 13 Marines + Bunkers, OR at least 2 Sunken Colonies, OR at least 2 Dragoons
07 = ?? Siege Tank, OR ?? Queen, OR at most 5 Zealots.
08 = At least 6 Marines + Bunkers, OR at least 3 Sunken Colonies + Hydralisks, OR at least 2 Zealots
09 = At least 10 Marines + Bunkers, OR at least 5 sunken colonies + Hydralisks, OR at least 6
Zealots
10 = At least 5 Marines + Bunkers, OR at least 5 Sunken Colonies + Hydralisks, OR at least 3 Zealots
11 = At least 10 Marines + Bunkers, OR at least 10 Sunken Colonies + Hydralisks, OR at least 6
Zealots
12 = At Least 17 Marines + Bunkers, OR at least 6 Mutalisks + Spore Colonies + Hydralisks, OR at
least 3 Dragoons + Scouts
13 = At least 25 Marines + Bunkers, OR at least 11 Mutalisks + Spore Colonies + Hydralisks, OR at
least 8 Dragoons + Scouts
Credit to Heinermann for figuring these out.
= Expansion attacking (melee only) =The opcodes `
set_attacks` and `
target_expansion` are used to send AI to attack an enemy expansion. The opcodes do nothing if the AI player has ran a campaign script. `target_expansion` sets a flag that allows expansion attacks to occur, and `set_attacks` sets amount of attacks the AI can do. After every attack the `target_expansion` flag is cleared and `set_attacks` count is decreased by one.
The attacks use the same attack force as regular attacks, so mixing them both will have conflicts. If the AI has enough units for the attack force, and the two commands have been used, it will attack the nearest enemy base location that is not set by a start location. I don't think the AI will train the missing units if not explicitly ordered otherwise. These attacks will not be performed if another attack is already in progress.
There is also not grouping phase for these attacks (Or rather, the deadline is 1 second), and while `set_attacks` can be reset to zero, the `target_expansion` will not get cleared if the attack doesn't occur.
Post has been edited 3 time(s), last time on Jul 23 2017, 12:32 am by Neiv.
None.