• 🏆 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!

Chosing path to attack in tug of war

Level 3
Joined
May 7, 2020
Messages
15
I have a tug of war-type map and face a small problem: some units in waves go to different lanes, sometimes even to the furthest away. I want to know if there is a way to fix this so they follow the same path, at least to a certain point, and I don't want to do it by blocking the path with rocks and trees. Here is the JASS script for AI.
JASS:
globals
    integer user = 0

    integer SKELETON_KNIGHT = 'h60T'
    integer DEATH_GUARD = 'u606'
    integer BUTCHER = 'u601'
    integer HIGH_PLAGUER = 'u603'
    integer NECROMANCER = 'u604'
    integer HERO = 'U609' 
endglobals

function main takes nothing returns nothing
    call CampaignAI(BURROW,null)
    
    call PrepFullSuicide()
    loop
        loop
            exitwhen CommandsWaiting() == 0
            set user = GetLastCommand()
            call PopLastCommand()
        endloop
        call SuicideUnitB(DEATH_GUARD,user)        
        call SuicideUnitB(SKELETON_KNIGHT,user)
        call SuicideUnitB(BUTCHER,user)
        call SuicideUnitB(HIGH_PLAGUER,user)
        call SuicideUnitB(NECROMANCER,user)
        call SuicideUnitB(HERO,user)
    endloop        
endfunction
 
Level 25
Joined
Sep 26, 2009
Messages
2,381
I don't have much experience with WC3's AI, but just from this script I would not assume that the AI will always take the shortest route. The AI may decide to for example run around and attack from behind for a pincer-like attack, avoid large amount of enemies, etc.

Perhaps you should leave building units, etc. to the AI, but the attack pattern to triggers? Then you could define a set of locations along the lane and just order units to attack-move the next closest location
 
Level 3
Joined
May 7, 2020
Messages
15
For now, I solved the problem by creating regions between lanes. If a unit enters these regions, I then order it to attack-move to a certain point. It works fairly well, sometimes, some units will slip, probably because when they are ordered to attack-move, they attack some nearby unit, never leave the region, lose the order, and then go to a different lane. However, this rarely happens, so the problem is kind of solved. I tried using attack-move to handle all attacks at the beginning, but units sometimes would lose focus on attack-move after combat, resurrected units were also problem, making it hard to handle them well. Overall, it would probably take a lot of time to get attacks with triggers to work as well as with the JASS script.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,557
What you want to do is track where a unit should be at all times. This can be done with a Unit Indexer or a Hashtable, I prefer the former.

This way at any point in time you can order a "lost" unit to attack-move to where it's supposed to be going next.

This is an example using the Unit Indexer method (note the Custom Value - that's essential to this design):
  • Actions
    • Set Variable Your_Lost_Unit = (Some unit that's lost)
    • Set Variable CV = (Custom value of Your_Lost_Unit)
    • Unit - Order Your_Lost_Unit to Attack-Move To Attack_Point[Next_Destination[CV]]
Variables:
Your_Lost_Unit = Unit
CV = Integer
Next_Destination = Integer (array)
Attack_Point = Point (array)

You would define your different attack positions using the Attack_Point variable at the start of the game:
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set Variable Attack_Point[1] = (Center of Attack Region 1 <gen>)
    • Set Variable Attack_Point[2] = (Center of Attack Region 2 <gen>)
    • Set Variable Attack_Point[3] = (Center of Attack Region 3 <gen>)
    • Set Variable Attack_Point[4] = (Center of Attack Region 4 <gen>)
Then when a unit is created or enters one of these Regions you can track and adjust it's "next destination" so it's always aware of where it needs to go next:
  • Events
    • Time - Every 5.00 seconds
  • Conditions
  • Actions
    • Unit - Create 1 Footman...
    • Set Variable CV = (Custom value of (Last created unit))
    • Set Variable Next_Destination[CV] = 1
    • Unit - Order (Last created unit) to Attack-Move To Attack_Point[Next_Destination[CV]]
  • Events
    • Unit - A unit enters Attack Region 1 <gen>
    • Unit - A unit enters Attack Region 2 <gen>
    • Unit - A unit enters Attack Region 3 <gen>
    • Unit - A unit enters Attack Region 4 <gen>
  • Conditions
    • Next_Destination[(Custom value of (Triggering unit)] Greater than 0
  • Actions
    • Set Variable CV = (Custom value of (Triggering unit))
    • Set Variable Next_Destination[CV] = (Next_Destination[CV] + 1)
    • Unit - Order (Triggering unit) to Attack-Move To Attack_Point[Next_Destination[CV]]
So we're storing a number on all of the units under the variable called Next_Destination. This number starts out at 1 and will increase by 1 as the unit enters each new region. We order the Unit to Attack-move to Attack_Point[1] which happens to be the center of the very first Attack Region. Once it reaches Attack Region 1, we increase it's number to 2 (1 + 1 = 2) and order it to Attack-move to Attack_Point[2], which is the center of Attack Region 2. This pattern continues until it reaches the final region in which case it doesn't really matter anymore since it's probably in the enemies base by now.
 
Last edited:
Top