• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[AI] Need Help!

Status
Not open for further replies.
Level 1
Joined
Apr 23, 2014
Messages
475
Hello, and i'm trying to make a alterned map AI, ut it's totally messed up!

Here's the example: i treied my best... but comp just don't even moved!The main part is the heroes.
JASS:
//============================================================================
//  Human Melee Strategic AI
//============================================================================
globals
    boolean startup     = true

    integer C_footmen   = 0
    integer C_priest    = 0
    integer C_riflemen  = 0
    integer C_gyro      = 0
    integer C_gryphon   = 0
    integer C_vs_air    = 0

    integer max_rifle   = 0
    integer max_gyro    = 0
    integer max_gryphon = 0

    boolean keep        = false
    boolean castle      = false
    boolean mill        = false
    boolean smith       = false
    boolean barracks    = false
    boolean knights     = false
    boolean workshop    = false
    boolean sanctum     = false
    boolean aviary      = false
    boolean priests     = false
    boolean sorcery     = false
endglobals

//============================================================================
//  set_skills
//============================================================================
function set_skills takes nothing returns nothing
    //------------------------------------------------------------------------
    if hero_id == TINKER then
    //------------------------------------------------------------------------
        set skills2[ 1] = CLUSTER_ROCKETS
        set skills2[ 2] = BRILLIANCE_AURA
        set skills2[ 3] = ACID_BOMB
        set skills2[ 4] = BRILLIANCE_AURA
        set skills2[ 5] = CLUSTER_ROCKETS
        set skills2[ 6] = ROBO_GOBLIN
        set skills2[ 7] = ACID_BOMB
        set skills2[ 8] = BRILLIANCE_AURA
        set skills2[ 9] = ACID_BOMB
        set skills2[10] = CLUSTER_ROCKETS
    endif
    //------------------------------------------------------------------------
    if hero_id2 == TINKER then
    //------------------------------------------------------------------------
        set skills2[ 1] = CLUSTER_ROCKETS
        set skills2[ 2] = BRILLIANCE_AURA
        set skills2[ 3] = ACID_BOMB
        set skills2[ 4] = BRILLIANCE_AURA
        set skills2[ 5] = CLUSTER_ROCKETS
        set skills2[ 6] = ROBO_GOBLIN
        set skills2[ 7] = ACID_BOMB
        set skills2[ 8] = BRILLIANCE_AURA
        set skills2[ 9] = ACID_BOMB
        set skills2[10] = CLUSTER_ROCKETS
    endif

    //------------------------------------------------------------------------
    if hero_id == MTN_KING then
    //------------------------------------------------------------------------
        set skills1[ 1] = THUNDER_BOLT
        set skills1[ 2] = BASH
        set skills1[ 3] = THUNDER_BOLT
        set skills1[ 4] = THUNDER_CLAP
        set skills1[ 5] = THUNDER_BOLT
        set skills1[ 6] = EARTHQUAKE
        set skills1[ 7] = BASH
        set skills1[ 8] = BASH
        set skills1[ 9] = THUNDER_CLAP
        set skills1[10] = THUNDER_CLAP
    endif
    //------------------------------------------------------------------------
    if hero_id2 == MTN_KING then
    //------------------------------------------------------------------------
        set skills2[ 1] = THUNDER_BOLT
        set skills2[ 2] = BASH
        set skills2[ 3] = THUNDER_BOLT
        set skills2[ 4] = THUNDER_CLAP
        set skills2[ 5] = THUNDER_BOLT
        set skills2[ 6] = EARTHQUAKE
        set skills2[ 7] = BASH
        set skills2[ 8] = BASH
        set skills2[ 9] = THUNDER_BOLT
        set skills2[10] = THUNDER_BOLT
    endif

    //------------------------------------------------------------------------
    if hero_id == BEASTMASTER then
    //------------------------------------------------------------------------
        set skills2[ 1] = SUMMON_BEAR
        set skills2[ 2] = EVASION
        set skills2[ 3] = SUMMON_BEAR
        set skills2[ 4] = EVASION
        set skills2[ 5] = ATTRIBUTE_BONUS
        set skills2[ 6] = SUMMON_MISHA
        set skills2[ 7] = ATTRIBUTE_BONUS
        set skills2[ 8] = EVASION
        set skills2[ 9] = ATTRIBUTE_BONUS
        set skills2[10] = SUMMON_BEAR
    endif
    //------------------------------------------------------------------------
    if hero_id2 == BEASTMASTER then
    //------------------------------------------------------------------------
        set skills2[ 1] = SUMMON_BEAR
        set skills2[ 2] = EVASION
        set skills2[ 3] = SUMMON_BEAR
        set skills2[ 4] = EVASION
        set skills2[ 5] = ATTRIBUTE_BONUS
        set skills2[ 6] = SUMMON_MISHA
        set skills2[ 7] = ATTRIBUTE_BONUS
        set skills2[ 8] = EVASION
        set skills2[ 9] = ATTRIBUTE_BONUS
        set skills2[10] = SUMMON_BEAR
    endif
endfunction

//============================================================================
//  setup_force
//============================================================================
function setup_force takes nothing returns nothing
    local integer foot
    local integer knight

    call AwaitMeleeHeroes()

    loop
        set foot = GetUnitCountDone(FOOTMAN)
        exitwhen foot >= 5

        set knight = GetUnitCountDone(KNIGHT)
        exitwhen foot + 2*knight >= 6

        call Sleep(2)
    endloop

    call InitAssaultGroup()
    call RemoveInjuries()

    call SetAssaultGroup( 1, 9, hero_id     )
    call SetAssaultGroup( 0, 9, hero_id2    )
    call SetAssaultGroup( 0, 9, FOOTMEN     )
    call SetAssaultGroup( 0, 9, KNIGHT      )
    call SetAssaultGroup( 0, 9, RIFLEMEN    )
    call SetAssaultGroup( 0, 9, PRIEST      )
    call SetAssaultGroup( 0, 9, SORCERESS   )
    call SetAssaultGroup( 0, 9, GRYPHON     )
    call SetAssaultGroup( 0, 9, COPTER      )
    call SetAssaultGroup( 0, 9, MORTAR      )

    call SetInitialWave(10)
endfunction

//============================================================================
//  attack_sequence
//============================================================================
function attack_sequence takes nothing returns nothing
    local boolean needs_exp
    local boolean has_siege
    local boolean major_ok
    local boolean air_units

    loop
        exitwhen GetUnitCountDone(hero_id)>0
        call Sleep(2)
    endloop

    call StaggerSleep(0,2)
    loop
        loop
            exitwhen not CaptainRetreating()
            call Sleep(2)
        endloop

        call setup_force()

        set major_ok         = GetUnitCountDone(RIFLEMAN)>=2
        set needs_exp        = take_exp and major_ok
        set has_siege        = GetUnitCountDone(MORTAR)>0 or GetUnitCountDone(TANK)>0
        set air_units        = GetUnitCountDone(COPTER)>0 or GetUnitCountDone(GRYPHON)>0
        set allow_air_creeps = air_units or major_ok

        call SingleMeleeAttack(needs_exp,has_siege,major_ok,air_units)
    endloop
endfunction

//============================================================================
//  init_booleans
//============================================================================
function init_booleans takes nothing returns nothing
    set C_footmen   = GetUnitCount(FOOTMEN)
    set C_priest    = GetUnitCount(PRIEST)
    set C_riflemen  = GetUnitCount(RIFLEMAN)
    set C_gyro      = GetUnitCount(COPTER)
    set C_gryphon   = GetUnitCount(GRYPHON)

    set keep        = TownCountDone(KEEP)>0
    set castle      = GetUnitCountDone(CASTLE)>0
    set mill        = GetUnitCountDone(LUMBER_MILL)>0
    set smith       = GetUnitCountDone(BLACKSMITH)>0
    set barracks    = GetUnitCountDone(BARRACKS)>0
    set knights     = barracks and mill and smith and castle
    set workshop    = GetUnitCountDone(WORKSHOP)>0
    set sanctum     = GetUnitCountDone(SANCTUM)>0
    set aviary      = GetUnitCountDone(AVIARY)>0
    set priests     = C_priest>0
    set sorcery     = GetUnitCount(SORCERESS)>0

    if workshop and (castle or GetUpgradeLevel(UPG_BOMBS)>0) then
        if aviary then
            set max_rifle   = 0 //  0
            set max_gyro    = 2 //  4
            set max_gryphon = 2 //  8 (=12)
        else
            set max_rifle   = 3 //  9
            set max_gyro    = 1 //  2
            set max_gryphon = 0 //  0 (=11)
        endif
    else
        if aviary then
            set max_rifle   = 1 //  3
            set max_gyro    = 0 //  0
            set max_gryphon = 2 //  8 (=11)
        else
            set max_rifle   = 4 // 12
            set max_gyro    = 0 //  0
            set max_gryphon = 0 //  0 (=12)
        endif
    endif
endfunction

//============================================================================
//  upgrade_sequence
//============================================================================
function upgrade_sequence takes nothing returns nothing

    //*** BARRACKS UPGRADES ***
    //
    if barracks then
        call SetBuildUpgr( 1, UPG_DEFEND )
        
        if workshop then
            call SetBuildUpgr( 1, UPG_GUN_RANGE )
        endif

        if knights then
            call SetBuildUpgr( 1, UPG_BREEDING )
        endif
    endif

    //*** BLACKSMITH UPGRADES ***
    //
    if smith then
        call SetBuildUpgr( 1, UPG_MELEE   )
        call SetBuildUpgr( 1, UPG_ARMOR   )
        call SetBuildUpgr( 1, UPG_RANGED  )
        call SetBuildUpgr( 1, UPG_LEATHER )

        if keep then
            call SetBuildUpgr( 2, UPG_MELEE   )
            call SetBuildUpgr( 2, UPG_ARMOR   )
            call SetBuildUpgr( 2, UPG_RANGED  )
            call SetBuildUpgr( 2, UPG_LEATHER )

            if castle then
                call SetBuildUpgr( 3, UPG_MELEE   )
                call SetBuildUpgr( 3, UPG_ARMOR   )
                call SetBuildUpgr( 3, UPG_RANGED  )
                call SetBuildUpgr( 3, UPG_LEATHER )
            endif
        endif
    endif

    //*** SANCTUM UPGRADES ***
    //
    if sanctum and priests then
        call SetBuildUpgr( 1, UPG_PRAYING )

        if sorcery then
            call SetBuildUpgr( 1, UPG_SORCERY )
        endif

        if castle and priests then
            call SetBuildUpgr( 2, UPG_PRAYING  )

            if sorcery then
                call SetBuildUpgr( 2, UPG_SORCERY  )
                call SetBuildUpgr( 1, UPG_SENTINEL )
            endif
        endif
    endif

    //*** LUMBER MILL UPGRADES ***
    //
    if mill and keep then
        call SetBuildUpgr( 1, UPG_WOOD )

        if castle then
            call SetBuildUpgr( 2, UPG_WOOD    )
            call SetBuildUpgr( 2, UPG_MASONRY )
        endif
    endif

    //*** WORKSHOP UPGRADES ***
    //
    if workshop and C_gyro>0 then
        call SetBuildUpgr( 1, UPG_BOMBS )
    endif

    //*** AVIARY UPGRADES ***
    //
    if aviary and C_gryphon>0 then
        call SetBuildUpgr( 1, UPG_HAMMERS )
    endif
endfunction

//============================================================================
//  basic_range
//============================================================================
function basic_ranged takes integer food returns nothing
    local integer C_rifle = GetUnitCount(COPTER)
    local integer rifle
    local integer gyro
    local integer gryphon

    set rifle   = (food - 2*C_gyro  - 4*C_gryphon) / 3
    set gyro    = (food - 3*C_rifle - 4*C_gryphon) / 2
    set gryphon = (food - 3*C_rifle - 2*C_gyro   ) / 4

    if rifle > max_rifle then
        set rifle = max_rifle
    endif
    if gyro > max_gyro then
        set gyro = max_gyro
    endif
    if gryphon > max_gryphon then
        set gryphon = max_gryphon
    endif

    if rifle <= max_rifle then
        call SetBuildUnit( rifle,   RIFLEMAN )
    endif
    if gyro <= max_gyro then
        call SetBuildUnit( gyro,    COPTER   )
    endif
    if gryphon <= max_gryphon then
        call SetBuildUnit( gryphon, GRYPHON  )
    endif
endfunction

//============================================================================
//  forces_sequence
//============================================================================
function forces_sequence takes nothing returns nothing
    local integer farms = GetUnitCountDone(HOUSE) + 2*TownCountDone(TOWN_HALL)

    //*** MELEE FORCES ***
    //
    if farms < 9 then
        return
    endif
    if knights then
        call SetBuildUnit( (8 - GetUnitCount(FOOTMAN)) / 2, KNIGHT )
    endif

    //*** SIEGE FORCES ***
    //
    if farms < 10 then
        return
    endif
    if workshop then
        call SetBuildUnit( 2, MORTAR )
    endif

    //*** CASTER FORCES ***
    //
    if farms < 11 then
        return
    endif
    if sanctum then
        call SetBuildUnit( 3, PRIEST    )
    endif
    if farms < 12 then
        return
    endif
    if sanctum and GetUpgradeLevel(UPG_SORCERY)>=2 then
        call SetBuildUnit( 3, SORCERESS )
    else
        call SetBuildUnit( 1, SORCERESS )
    endif
endfunction

//============================================================================
//  basic_melee
//============================================================================
function basic_melee takes integer food returns nothing
    call FoodPool( food,  true,FOOTMAN,2,  knights,KNIGHT,4 )
endfunction

//============================================================================
//  build_sequence
//============================================================================
function build_sequence takes nothing returns nothing
    local integer mines = GetMinesOwned()

    call InitBuildArray()
    call init_booleans()

    call MeleeTownHall( 0, TOWN_HALL )
    call MeleeTownHall( 1, TOWN_HALL )

    call SetBuildUnit( 1, TOWN_HALL     )
    call SetBuildUnit( 6, PEASANT       )
    call BuildFactory(    BARRACKS      )
    call SetBuildUnit( 8, PEASANT       )
    call SetBuildUnit( 1, HOUSE         )
    call SetBuildUnit(10, PEASANT       )

    call basic_melee( 2 )
    call SetBuildUnit( 1, HUMAN_ALTAR   )
    call SetBuildUnit(11, PEASANT       )
    call SetBuildUnit( 2, HOUSE         )

    call basic_melee( 6 )
    call SetBuildUnit( 1, hero_id       )
    call SetBuildUnit( 3, HOUSE         )
    call basic_melee( 10 )

    if startup then
        if GetUnitCountDone(FOOTMAN)<5 then
            return
        endif
        set startup = false
    endif

    call SetBuildUpgr( 1, UPG_DEFEND    )
    call SetBuildUnit( 1, BLACKSMITH    )
    call SetBuildUnit( 1, LUMBER_MILL   )
    call SetBuildUnit( 4, HOUSE         )

    call basic_melee( 12 )
    call basic_ranged( 3 )
    call SetBuildUpgr( 1, UPG_ARMOR     )
    call SetBuildUnit( 5, HOUSE         )

    call basic_ranged( 6 )
    call SetBuildUnit( 1, KEEP          )

    call basic_ranged( 9 )
    call SetBuildUpgr( 1, UPG_MELEE     )

    call basic_ranged( 12 )
    call UpgradeAll( WATCH_TOWER, GUARD_TOWER )

    call SetBuildUnit( 2, WATCH_TOWER   )
    call SetBuildUpgr( 1, UPG_RANGED    )

    call BasicExpansion( mines < 2, TOWN_HALL )

    call SetBuildUnit( 6, HOUSE         )

    call GuardSecondary( 1, 2, WATCH_TOWER )
    call GuardSecondary( 2, 2, WATCH_TOWER )

    call SetBuildUpgr( 1, UPG_LEATHER   )
    call SetBuildUpgr( 1, UPG_WOOD      )
    call SetBuildUnit( 1, hero_id2      )

    if mines > 1 then
        call SetBuildUnit( 14, PEASANT  )
    endif

    call forces_sequence()
    call upgrade_sequence()

    call BuildFactory( WORKSHOP )

    if GetUnitCount(MORTAR)<1 then
        return
    endif

    call BuildFactory( SANCTUM )

    call SetBuildUnit( 1, CASTLE        )
    call SetBuildUnit( 8, HOUSE         )
    call SetBuildUnit( 1, AVIARY        )

    if GetUnitCount(AVIARY)>0 and GetUnitCount(ZEPPELIN)<3 then
        call GetZeppelin()
    endif

    call MeleeTownHall( 2, TOWN_HALL )

    call BasicExpansion( mines < 3, TOWN_HALL )
endfunction

//============================================================================
//  peon_asignment
//============================================================================
function peon_assignment takes nothing returns nothing
    local integer halls = TownCountDone(TOWN_HALL)
    local integer T
    loop
        call ClearHarvestAI()

        set T = TownWithMine()

        call HarvestGold(T,5)
        call HarvestWood(0,2)

        if TownCountDone(TOWN_HALL)>1 then
            call HarvestGold(T+1,4)
        endif

        call HarvestWood(0,15)

        call build_sequence()
        call Sleep(3)
    endloop
endfunction

//============================================================================
//	main
//============================================================================
function main takes nothing returns nothing
    set do_debug_cheats = GetAiPlayer()==1

    call PickMeleeHero(RACE_HUMAN)
    call set_skills()
    call StandardAI(function SkillArrays, function peon_assignment, function attack_sequence)
    call PlayGame()
endfunction
 
Status
Not open for further replies.
Top