HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

AI Attack at Specific Target/Locations

10-11-2003, 05:47 PM#1
Tommi
I am not very familiar with JASS, but I'm now trying to use it to make my AI to attack specific buildings on my map. I have managed to extract the AI script and here's how the editor has put it (only the attack part):

Code:
//===========================================================================
// Initiates an attack based on target priorities
//===========================================================================
function LaunchAttack takes nothing returns nothing
    local unit target = null
    local boolean setAlly = true

    // Don't launch any attack while town is threatened
    if (TownThreatened()) then
        call Sleep( 2 )
        return
    endif

    // Target Priority #1
    if (gCond_Attack_condition) then
        if (target == null) then
            set target = GetEnemyExpansion()
            if (target == null) then
                call StartGetEnemyBase(  )
                loop
                    exitwhen (not WaitGetEnemyBase())
                    call SuicideSleep( 1 )
                endloop
                set target = GetEnemyBase()
            endif
        endif

    endif
    // Attack the target and increment attack wave
    if (target != null) then
        call AttackTarget( target, setAlly )
        call AttackWaveUpdate(  )
    else
        // If no target was found, sleep a bit before trying again
        call Sleep( 20 )
    endif
endfunction

I have two targets on my map for the AI. The AI must first destroy the first one (or it may be hidden through a trigger) and when that's done, the AI must seek to destroy another target. Both targets are preplaced on the map and are not generated by triggers (the first one can be hidden through them, though).

Now apparently I need to replace GetEnemyBase() with something else. What function do I have to use to get a preplaced building on a map (to set it as a target)? And how do I check if the target is hidden?

Cheers,

Tommi

P.S. Where do I find source code for GetEnemyBase() and GetEnemyExpansion()? They were not in common.ai nor common.j.
10-11-2003, 09:21 PM#2
AIAndy
They are natives which are not written in JASS but instead in the game engine itself.
You cannot directly access unit variables from the map script. But you can use the GroupEnum... functions to get the units at a certain place. So find out the coordinates of your targets and then enumerate the units in a small radius around that. That way you can get the unit variable of the target and then just set that as target.
10-20-2003, 04:13 PM#3
Tommi
Quote:
Originally posted by AIAndy
You cannot directly access unit variables from the map script. But you can use the GroupEnum... functions to get the units at a certain place. So find out the coordinates of your targets and then enumerate the units in a small radius around that. That way you can get the unit variable of the target and then just set that as target.

Hmm... I tried referencing preplaced units through variables the game creates, such as gg_unit_hcas_0000. It seemed to work rather fine. Is there a problem in doing that I'm not aware of?

Edit: this test was in a map script, not an ai script, if that matters.
10-20-2003, 08:01 PM#4
Tommi
Quote:
Originally posted by Tommi
Edit: this test was in a map script, not an ai script, if that matters.

I had time to test this myself. Indeed, it doesn't work in AI scripts, only map scripts. Now onto what AIAndy suggested...