• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

AI Attack Move

Status
Not open for further replies.
Level 2
Joined
Jul 3, 2019
Messages
14
Hiya,


I am trying to get my AI to attack-move to a set of X, Y coordinates OR regions within my map.

I want them to “SuicideOnPlayerEX” but follow a specific path to do so.

Does anyone know how to do this?

FYI, my AI is made using JASS, not the World Editor.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Since you already have your "specific path", create waypoints (regions) along this path. Order your units to attack move first waypoint, when they reached nth waypoint order them to attackc (n+1)th waypoint.
 
Level 2
Joined
Jul 3, 2019
Messages
14
Since you already have your "specific path", create waypoints (regions) along this path. Order your units to attack move first waypoint, when they reached nth waypoint order them to attackc (n+1)th waypoint.

I apologize, there is a misunderstanding, I have a "specific path" only in my head. In-game, the units are Attack-Moving to the Town Hall because that is how it works using Jasscraft, I need a function from Jasscraft to get them to attack move to my theoretical locations before attacking the Town Hall because there are dangers for the AI if they attack directly.

There are no unit groups or waves in the World Editor, it is all done by Jasscraft in my map and the AI is just imported as a .ai file.
 
Level 12
Joined
Jun 15, 2016
Messages
472
First of all, there is actually an AI native which tells your attack captain (the group of your attacking units) to attack a location: AttackMoveXY.

Second, you wouldn't want to use it alone because it has no control structure. What you would probably want to use is SuicideOnPointEx, which works just like SuicideOnPlayerEx but with a point. That means the the computer waits until it gathered the attacking units it needs, and returning to base if no Target is found, etc.

Third, you can find all this and more here - the common.ai file contains all of the AI functions and variables, and will make your work much easier once you get a bit more familiar with it.
 
Level 2
Joined
Jul 3, 2019
Messages
14
First of all, there is actually an AI native which tells your attack captain (the group of your attacking units) to attack a location: AttackMoveXY.

Second, you wouldn't want to use it alone because it has no control structure. What you would probably want to use is SuicideOnPointEx, which works just like SuicideOnPlayerEx but with a point. That means the computer waits until it gathered the attacking units it needs, and returning to base if no Target is found, etc.

Third, you can find all this and more here - the common.ai file contains all of the AI functions and variables and will make your work much easier once you get a bit more familiar with it.


Thank you for your reply it was very helpful, especially the JASS Manual, I have one question.

Can I set multiple SuicideOnPointEx within one wave?

For example, the wave suicides on point A, then point B, then point C?

The reason I ask is that the function is formatted like SuicideOnPlayerEx where you define the minutes and the user, so if I use it multiple times would this mess it up?

For example, the wave may go to the first point then wait for x minutes before moving to the next location.
 
Level 12
Joined
Jun 15, 2016
Messages
472
Not exactly. There are a couple of problems, all related to the general purpose attack function that SuicideOnPointEx calls: CommonSuicideOnPlayer.

JASS:
function SuicideOnPoint takes integer seconds, player p, integer x, integer y returns nothing
    call CommonSuicideOnPlayer(false,false,seconds,p,x,y)
endfunction

You can read more about it CommonSuicideOnPlayer itself here, but to keep things short an AI attack is split into three steps:

1. Gathering units (using the FormGroup function)
2. Attacking
3. Waiting for attack termination (using the SuicideOnPlayerWave function)

Each step is done in a loop, your problem is with how attacking a point works in this function:

JASS:
function CommonSuicideOnPlayer takes boolean standard, boolean bldgs, integer seconds, player p, integer x, integer y returns nothing
    local integer save_peons

    if not PrepSuicideOnPlayer(seconds) then
        return
    endif

    set save_peons = campaign_wood_peons
    set campaign_wood_peons = 0

    loop
       //xxx
        if allow_signal_abort and CommandsWaiting() != 0 then
            call Trace("ABORT -- attack wave override\n")
        endif
       //xxx

        exitwhen allow_signal_abort and CommandsWaiting() != 0
//THIS IS THE PART YOU CARE ABOUT=============================================
        loop
            exitwhen allow_signal_abort and CommandsWaiting() != 0

            call FormGroup(5,true)
            exitwhen sleep_seconds <= 0
            call TraceI("waiting %d seconds before suicide\n",sleep_seconds) //xxx
        endloop

        if standard then
            if bldgs then
                exitwhen SuicidePlayer(p,sleep_seconds >= -60)
            else
                exitwhen SuicidePlayerUnits(p,sleep_seconds >= -60)
            endif
        else
            call AttackMoveXYA(x,y)
        endif

        call TraceI("waiting %d seconds before timeout\n",60+sleep_seconds) //xxx
        call SuicideSleep(5)
    endloop
//THIS IS THE PART YOU CARE ABOUT=============================================
    set campaign_wood_peons = save_peons
    set harass_length = 0

    call SuicideOnPlayerWave()
endfunction

You'll notice you're calling AttackMoveXYA inside a loop, and the loop is not stopping. This is an error on Blizzard's side, but since they never used this function no one noticed (UNTIL TODAY!!!). A simple solution to that is copying CommonSuicideOnPlayer, adding a line exitwhen true right after the line call AttackMoveXYA(x,y), and using it instead. This will make your attacks actually finish.

But that still doesn't answer your question!

You can call SuicideOnPointEx a couple of times with different points. It's worth the try, but because of problems in how SuicideOnPlayerWave works (too long to get into), I think your units will go to point A, then back to base, then to point B, and so on.

So your other option is to create a function which works like SuicideOnPointEx, but with more points and better control on your units. Some hints for native functions you'll need:

CaptainAtGoal - check if your unit are near the point.
CaptainInCombat - checks if your units are in combat (call it with true argument).
CaptainIsEmpty - all attacking units are dead.

If you're having trouble/questions about it, you can create a new post here or message me.
 
Level 2
Joined
Jul 3, 2019
Messages
14
I think I will take you up on your offer, please!

I don't have private messaging yet as I am a new HiveWorkshop member so I can't initiate the messaging that way, you would need to message me.

I would like to share my map with you along with the .ai files I'm using so that you can see for yourself what's going on.

What I do know is that I do not currently possess the skills to build the SuicideOnPointEx custom function with more points that you wrote about.

If you wouldn't mind looking at them, that would be extremely helpful. :)
 
Status
Not open for further replies.
Top