• 🏆 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] Campaign AI Script not starting

Status
Not open for further replies.
Level 3
Joined
May 4, 2012
Messages
25
Hello there, I'm new to JASS and decided to write a bit complex AI script in JASScraft. Unfortunately, JASScraft Syntax Checker doesn't help that much, and the script is not running for my Demon-Undead race. I can't upload my map for the size due to custom contents. Here is the script:

JASS:
globals
    player user = Player(0) 
    player human = Player(1)
    constant integer pyroist            = 'h00J'
    constant integer juggernaught       = 'o005'
    constant integer sane               = 'n00Z'
    constant integer breaker            = 'n00W'
    constant integer harrow             = 'n00V'
    constant integer annih              = 'n00X'
    constant integer hero               = 'U00Q'
    constant integer hero2              = 'U00V'
    
    constant integer array HuUnitID   
    constant integer HuUnitID[0]    = 'h00D'    //strider
    constant integer HuUnitID[1]    = 'e005'    //ballista
    constant integer HuUnitID[2]    = 'h00A'    //templar
    constant integer HuUnitID[3]    = 'h009'    //elite
    constant integer HuUnitID[4]    = 'n009'    //archer
    constant integer HuUnitID[5]    = 'n00E'    //crystal
    constant integer HuUnitID[6]    = 'n00N'    //lancer
    constant integer HuUnitID[7]    = 'n00C'    //hydro
    constant integer HuUnitID[8]    = 'n00D'    //antimage
    
    constant integer array HuUnitWght     
    constant integer HuUnitWght[0]    = 3       //strider
    constant integer HuUnitWght[1]    = 2       //ballista
    constant integer HuUnitWght[2]    = 1       //templar
    constant integer HuUnitWght[3]    = 2       //elite
    constant integer HuUnitWght[4]    = 1       //archer
    constant integer HuUnitWght[5]    = 2       //crystal
    constant integer HuUnitWght[6]    = 3       //lancer
    constant integer HuUnitWght[7]    = 3       //hydro
    constant integer HuUnitWght[8]    = 1       //antimage
        
//    constant integer RAIN     = 'A029'
//    constant integer IMMO     = 'A00U'
//    constant integer INCE     = 'ANic'
//    constant integer DOOM     = 'A02B'
endglobals

//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
function EneTypesCount takes nothing returns integer
    
    local integer count = 0
    local integer i     = 0
    
    loop
        exitwhen i > 7
        set count   = count + GetPlayerUnitTypeCount(human,HuUnitID[i])
        set i = i + 1
    endloop
    return count
endfunction

function EneTypesWeight takes nothing returns integer

    local integer weight    = 0
    local integer i         = 0
    
    loop
        exitwhen i > 7
        if      GetPlayerUnitTypeCount(human,HuUnitID[i]) = 0 then set weight = weight + 0
        elseif  GetPlayerUnitTypeCount(human,HuUnitID[i]) > 0 then set weight = weight + HuUnitWght[i]
        endif
        set i = i + 1
    endloop
    return weight
endfunction

function AssaultForce takes nothing returns nothing

    local integer array Random
    local integer Slots
    local integer ExtraSlots
    local integer EneCount    = EneTypesCount()
    local integer EneWeight   = EneTypesWeight()

    set ExtraSlots = EneCount - 8
    
    if ExtraSlots < 0 then
        set Slots = 8
        else set Slots = 8 + ExtraSlots
    endif
      
    if      (GetPlayerUnitTypeCount(human,HuUnitID[2]) > 0) or (GetPlayerUnitTypeCount(human,HuUnitID[7]) > 0) or (GetPlayerUnitTypeCount(human,HuUnitID[8]) > 0) then
    set     Random[0] = GetRandomInt(0,2)
        if      Random[0] == 0 and Slots > 2 then
        call CampaignAttackerEx(3,3,3,pyroist)
        set Slots = Slots - 2
        elseif  Random[0] == 1 and Slots > 2 then
        call CampaignAttackerEx(2,2,2,breaker)
        set Slots = Slots - 2
        elseif  Random[0] == 2 and Slots > 3 then
        call CampaignAttackerEx(1,1,1,breaker)
        call CampaignAttackerEx(2,2,2,pyroist)
        set Slots = Slots - 3
        endif
            if  EneWeight > 15 and Slots > 1 then
            call CampaignAttackerEx(1,1,1,breaker)
            set Slots = Slots - 2
            endif
    endif
    
    if      (GetPlayerUnitTypeCount(human,HuUnitID[0]) > 0) or (GetPlayerUnitTypeCount(human,HuUnitID[3]) > 0) or (GetPlayerUnitTypeCount(human,HuUnitID[6]) > 0) then
    set     Random[1] = GetRandomInt(0,2)
        if      Random[1] == 0 and Slots > 2 then
        call CampaignAttackerEx(3,3,3,CRYPT_FIEND)
        set Slots = Slots - 2
        elseif  Random[1] == 1 and Slots > 1 then
        call CampaignAttackerEx(1,1,1,harrow)
        set Slots = Slots - 1
        elseif  Random[1] == 2 and Slots > 2 then
        call CampaignAttackerEx(1,1,1,juggernaught)
        set Slots = Slots - 2
        endif
            if  EneWeight > 12 and Slots > 1 then
            call CampaignAttackerEx(1,1,1,harrow)
            set Slots = Slots - 1
            endif
    endif
    
    if      (GetPlayerUnitTypeCount(human,HuUnitID[4]) > 4) then
    set     Random[2] == GetRandomInt(0,2)
        if      Random[2] == 0 and Slots > 1 then
        call CampaignAttackerEx(1,1,1,annih)
        set Slots = Slots - 1
        elseif  Random[2] == 1 and Slots > 1 then
        call CampaignAttackerEx(1,1,1,ABOMINATION)
        set Slots = Slots - 1
        endif
            if  EneWeight > 14 and Slots > 2 then
            call CampaignAttackerEx(1,1,1,ABOMINATION)
            set Slots = Slots - 1
            endif
    endif

    if      (GetPlayerUnitTypeCount(human,HuUnitID[5]) > 2) then
        if      Slots > 1 then
        call CampaignAttackerEx(2,2,2,GARGOYLE)
        set Slots = Slots - 1
        elseif  Slots > 1 and GetUpgradeLevel(UPG_FIEND_WEB) >= 1 then
        call CampaignAttackerEx(2,2,2,CRYPT_FIEND)
        set Slots = Slots - 1
        endif
            if  EneWeight > 14 and Slots > 1 and GetPlayerUnitTypeCount(human,HuUnitID[5]) > 3 then
            call CampaignAttackerEx(2,2,2,GARGOYLE)
            set Slots = Slots - 1
            endif
    endif
    
    if      (GetUnitCountDone(hero) >= 1) or (GetUnitCountDone(hero2) >= 1) or (GetUnitCountDone(annih) >= 1) then
        if      Slots > 1 then
        call CampaignAttackerEx(1,1,1,OBSIDIAN_STATUE)
        set Slots = Slots - 1
        endif
            if  EneWeight > 12 and Slots > 1 then
            call CampaignAttackerEx(1,1,1,OBSIDIAN_STATUE)
            Slots = Slots - 1
            endif
    endif
endfunction

function main takes nothing returns nothing

    call CampaignAI(ZIGGURAT_1, null)


    call ResetCaptainLocs()

    call SetBuildUpgrEx( 1,1,1, UPG_CANNIBALIZE         )
    call SetBuildUpgrEx( 1,1,1, UPG_GHOUL_FRENZY        )
    call SetBuildUpgrEx( 1,1,1, UPG_FIEND_WEB           )
    call SetBuildUpgrEx( 1,1,1, UPG_BLK_SPHINX          )

    call SetBuildUpgrEx( 1,1,1, UPG_UNHOLY_STR          )
    call SetBuildUpgrEx( 1,1,1, UPG_UNHOLY_ARMOR        )
    call SetBuildUpgrEx( 1,1,1, UPG_CR_ATTACK           )
    call SetBuildUpgrEx( 1,1,1, UPG_CR_ARMOR            )
    
    loop
    InitAssaultGroup()
    call CampaignAttackerEx(1,1,1,hero)
    call CampaignAttackerEx(1,1,1,hero2)
    if GetUnitCountDone(hero) >= 1 or GetUnitCountDone(hero2) >= 1 then
    call AssaultForce()
    call SuicideOnPlayer(M1,human)
        elseif  GetUnitCountDone(hero) <= 0 and GetUnitCountDone(hero2) <= 0 then
        call CampaignAttackerEx(1,1,1,hero)
        call CampaignAttackerEx(1,1,1,hero2)
            loop
            exitwhen GetUnitCountDone(hero) >= 1 and GetUnitCountDone(hero2) >= 1
            call Sleep(1.0)
            endloop
        call AssaultForce()
        call SuicideOnPlayer(M1,human)
    endif
    endloop
endfunction

Padron my imprudence.
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
Ok i rode a bit your code :
- Indent when using a loop, if, elseif, else blocks.
- I don't think at all you can initialize arrays values in globals blocks.
- For more readability (this word doesn't exist right ?) :
JASS:
if (condition) then
    //Do some stuff
elseif (condition) then
    //Do some stuff
else (condiiton) then
    //Do some stuff
endif


If i find more i'll tell you (but i never made AI as i said so don't wait for the impossible from me ^^).
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
I'm not sure we can use globals blocks without using vJASS...
But as I said I'm not that in AI XD

You can declare global blocks in Pure JASS with JNGP or NewGenPack5d
Like this
JASS:
globals
    unit caster // correct
    private unit target // WRONG! DO NOT USE PRIVATE OR ELSE IT WILL SHOW ERRORS YOU CAN DECLARE THIS IN SCOPES ^^
    public integer i // wrong too ^^
    readonly real r // wrong too ^^ declared in structs.
    hashtable nevermind // correct but no references =,=
endglobals
 
Level 3
Joined
May 4, 2012
Messages
25
Ok i rode a bit your code :
- Indent when using a loop, if, elseif, else blocks.
- I don't think at all you can initialize arrays values in globals blocks.
- For more readability (this word doesn't exist right ?) :
JASS:
if (condition) then
    //Do some stuff
elseif (condition) then
    //Do some stuff
else (condiiton) then
    //Do some stuff
endif


If i find more i'll tell you (but i never made AI as i said so don't wait for the impossible from me ^^).

I created a new function for the matter of initializing arrays values, and I called it from the main function but still to no avail.

JASS:
function ArraysInit takes nothing returns nothing

set    HuUnitID[0]    = 'h00D'    //strider
set    HuUnitID[1]    = 'e005'    //ballista
set    HuUnitID[2]    = 'h00A'    //templar
set    HuUnitID[3]    = 'h009'    //elite
set    HuUnitID[4]    = 'n009'    //archer
set    HuUnitID[5]    = 'n00E'    //crystal
set    HuUnitID[6]    = 'n00N'    //lancer
set    HuUnitID[7]    = 'n00C'    //hydro
set    HuUnitID[8]    = 'n00D'    //antimage

set    HuUnitWght[0]    = 3       //strider
set    HuUnitWght[1]    = 2       //ballista
set    HuUnitWght[2]    = 1       //templar
set    HuUnitWght[3]    = 2       //elite
set    HuUnitWght[4]    = 1       //archer
set    HuUnitWght[5]    = 2       //crystal
set    HuUnitWght[6]    = 3       //lancer
set    HuUnitWght[7]    = 3       //hydro
set    HuUnitWght[8]    = 1       //antimage
endfunction

...

function main takes nothing returns nothing
...
call ArraysInit()
...
endfunction

I also used JassCraft's Indent Text feature as suggested.
 
Level 3
Joined
May 4, 2012
Messages
25
Actually, for jass AI, you don't need JNGP. JASS AI can be done only with Jasscraft.

If you want support, I can give you a hand.

I read this tutorial couple of years ago, and took it as a template for my AI. The problem is the simplicity of the AI, I want an AI that assesses the situation based on enemy's units, as a starter point, to use unit mixing rather than preset attack groups.
 
Status
Not open for further replies.
Top