• 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.

Looking for an AI Coder

Status
Not open for further replies.
Level 6
Joined
Feb 5, 2012
Messages
1,685
oK so about your map. Because it is an ALTERED MELEE MAP you need to use the AI Maker of World Editor. I can code AI and MOST OF MY MAPS ARE WITH AI...but as i say in your game it is hard to make an AI for an Altered Melee Map...you must really use the AI Editor..there are some tutorials on this you can read them so you will know...the only thing that i can code an AI are maps that uses Single Heroes like AoS and Hero Arena or RPG..
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
I've been reading a few tutorials, actually, and managed to get the computer to build a base, but that's all it's doing. It's not attacking or expanding, it just follows the list of priorities I set for it and when its done it just sits there :|

Any ideas as to how I can make them start attacking?

Do they have a hero? The default forces require a hero to start an attack.
 
Do they have a hero? The default forces require a hero to start an attack.
They do, but the hero isn't trained - you pick him from the get-go (triggered, you click on a custom spell and it spawns the hero of your choice with Create 1 [Hero] at Temp_Point, etc ). Could that be the problem? My map uses only 1 Hero per race.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
They do, but the hero isn't trained - you pick him from the get-go (triggered, you click on a custom spell and it spawns the hero of your choice with Create 1 [Hero] at Temp_Point, etc ). Could that be the problem? My map uses only 1 Hero per race.

It's probably a problem. It will only work that way if you have "First hero" defined as the same unit that your picked hero - 1 AI per hero
 
If you want an altered melee AI code:
JASS:
//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************

globals
    integer                 attackWave                 = 1
    integer                 nextDelay                  = 0
    integer                 awGold                     = 0
    integer                 awWood                     = 0

    // Conditions
    boolean                 gCond_Attack_Enemy         = false
    boolean                 gCond_Attack_Strong_Creeps = false
    boolean                 gCond_Have_Lumber          = false
    boolean                 gCond_Need_Expansion       = false
endglobals

//***************************************************************************
//*
//*  Utility Functions
//*
//***************************************************************************

//===========================================================================
function CheckLastCommand takes boolean pop returns integer
    local integer cmd = GetLastCommand()
    if (pop) then
        call PopLastCommand(  )
    endif
    return cmd
endfunction

//===========================================================================
function CheckLastCommandData takes boolean pop returns integer
    local integer data = GetLastData()
    if (pop) then
        call PopLastCommand(  )
    endif
    return data
endfunction

//===========================================================================
function TotalFoodProduced takes nothing returns integer
    return GetPlayerState(ai_player,PLAYER_STATE_RESOURCE_FOOD_CAP)
endfunction

//===========================================================================
function ExpansionNeeded takes nothing returns boolean
    return take_exp
endfunction

//===========================================================================
function BuildExpansion takes integer hallID, integer mineID returns nothing
    if (HallsCompleted(hallID)) then
        call SetBuildExpa( TownCount(hallID) + 1, mineID )
    endif
endfunction

//===========================================================================
function CurrentAttackWave takes nothing returns integer
    return attackWave
endfunction

//===========================================================================
function ResetAttackUnits takes nothing returns nothing
    set awGold = 0
    set awWood = 0
    call InitAssaultGroup(  )
endfunction

//===========================================================================
function AddAttackUnit takes integer minQty, integer maxQty, integer unitID returns nothing
    // Track attacking gold workers
    if (unitID == 'n000') then
        set awGold = awGold + minQty
    endif

    // Track attacking wood workers
    if (unitID == 'n000') then
        set awWood = awWood + minQty
    endif

    call SetAssaultGroup( minQty, maxQty, unitID )
endfunction

//***************************************************************************
//*
//*  Basic Options
//*
//***************************************************************************

//===========================================================================
function InitOptions takes nothing returns nothing
    call SetMeleeAI(  )
    call SetDefendPlayer( false )
    call SetRandomPaths( false )
    call SetTargetHeroes( true )
    call SetPeonsRepair( true )
    call SetHeroesFlee( true )
    call SetHeroesBuyItems( false )
    call SetUnitsFlee( true )
    call SetGroupsFlee( true )
    call SetWatchMegaTargets( true )
    call SetIgnoreInjured( true )
    call SetHeroesTakeItems( true )
    call SetSlowChopping( false )
    call SetCaptainChanges( false )
    call SetSmartArtillery( true )
endfunction

//***************************************************************************
//*
//*  Conditions
//*
//***************************************************************************

//===========================================================================
// Updates the values of all preset conditions
//===========================================================================
function UpdateConditions takes nothing returns nothing
    set gCond_Attack_Enemy = ( CheckLastCommand( false ) == 1 )
    set gCond_Attack_Strong_Creeps = ( FoodUsed(  ) >= 40 )
    set gCond_Have_Lumber = ( GetWood(  ) > 0 )
    set gCond_Need_Expansion = ( ( GetGold(  ) < 2000 ) and ( GetGoldOwned(  ) < 2000 ) )
endfunction

//***************************************************************************
//*
//*  Heroes
//*
//***************************************************************************

//===========================================================================
// Stores hero ID and skills
//===========================================================================
function SetHero takes integer order, integer heroid returns nothing
    if (order == 1) then
        set hero_id = heroid
        if (heroid == 'O002') then
            set skills1[ 1] = 'AHtc'
            set skills1[ 2] = 'A001'
            set skills1[ 3] = 'AOcl'
            set skills1[ 4] = 'AHtc'
            set skills1[ 5] = 'A001'
            set skills1[ 6] = 'AOeq'
            set skills1[ 7] = 'AOcl'
            set skills1[ 8] = 'AHtc'
            set skills1[ 9] = 'A001'
            set skills1[10] = 'AOcl'
        endif
    endif
endfunction

//===========================================================================
// Selects hero IDs for three possible heroes
//===========================================================================
function SelectHeroes takes nothing returns nothing
    local integer roll = GetRandomInt(1,100)
    call SetHero( 1, 'O002' )
endfunction

//===========================================================================
// Returns the hero skill for the given hero and level
//===========================================================================
function ChooseHeroSkill takes nothing returns integer
    local integer curHero = GetHeroId()
    local integer level = GetHeroLevelAI()

    if (level > max_hero_level) then
        set max_hero_level = level
    endif

    if (curHero == hero_id) then
        return skills1[level]
    elseif (curHero == hero_id2) then
        return skills2[level]
    elseif (curHero == hero_id3) then
        return skills3[level]
    endif
    return 0
endfunction

//***************************************************************************
//*
//*  Building and Harvesting
//*
//***************************************************************************

//===========================================================================
// Specifies building priorities for workers
//===========================================================================
function BuildPriorities takes nothing returns nothing
    local integer mine = TownWithMine()
    call SetBuildAll( BUILD_UNIT, 1, 'o000', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'n000', -1 )
    if (gCond_Need_Expansion) then
        call BuildExpansion( 'o001', 'o001' )
    endif
    call SetBuildAll( BUILD_UNIT, 2, 'n000', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'n000', -1 )
    call SetBuildAll( BUILD_UNIT, 4, 'n000', -1 )
    call SetBuildAll( BUILD_UNIT, 5, 'n000', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'o001', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'O002', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'nltl', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'nltl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 1, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 1, 'nthl', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'nltl', -1 )
    call SetBuildAll( BUILD_UNIT, 4, 'nltl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 2, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 2, 'nthl', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'o001', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'nstw', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 3, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 5, 'nltl', -1 )
    call SetBuildAll( BUILD_UNIT, 6, 'nltl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 4, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 2, 'nstw', -1 )
    call SetBuildAll( BUILD_UNIT, 7, 'nltl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 5, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 3, 'nthl', -1 )
    call SetBuildAll( BUILD_UNIT, 4, 'nthl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 6, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 8, 'nltl', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'nstw', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 7, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 8, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 9, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 10, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 11, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 12, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 13, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 14, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 15, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 16, 'h000', 0 )
    endif
endfunction

//===========================================================================
// Specifies harvesting priorities for workers
//===========================================================================
function HarvestPriorities takes nothing returns nothing
    local integer mine = TownWithMine()
    local integer allGold = GetUnitCountDone('n000')
    local integer allWood = GetUnitCountDone('n000')
    local integer numWorkers
    set numWorkers = 5
    call HarvestGold( 0, numWorkers )
    set numWorkers = 5
    call HarvestGold( 1, numWorkers )
endfunction

//===========================================================================
// Determines all building and harvesting assignments for workers
//===========================================================================
function WorkerAssignment takes nothing returns nothing
    loop
        call UpdateConditions(  )

        // Harvesting
        call ClearHarvestAI(  )
        call HarvestPriorities(  )

        // Building
        call InitBuildArray(  )
        call BuildPriorities(  )

        call Sleep( 2 )
    endloop
endfunction

//***************************************************************************
//*
//*  Attacking
//*
//***************************************************************************

//===========================================================================
// Returns true if the minimum forces for an attack exist
//===========================================================================
function HaveMinimumAttackers takes nothing returns boolean
    local integer count

    // Check for attack wave limit
    if (attackWave > 1) then
        return false
    endif

    // Attack Group: Minimum
    set count = GetUnitCountDone( 'nltl' )
    if (count < 2) then
        return false
    endif
    return true
endfunction

//===========================================================================
// Assigns units to attack based on the given attack group
//===========================================================================
function PrepareAttackGroup takes integer groupID returns nothing
    local integer all

    // Attack Group #1: All Units
    if (groupID == 1) then
        set all = GetUnitCountDone( 'O002' )
        call AddAttackUnit( all, all, 'O002' )
        set all = GetUnitCountDone( 'nstw' )
        call AddAttackUnit( all, all, 'nstw' )
        set all = GetUnitCountDone( 'nltl' )
        call AddAttackUnit( all, all, 'nltl' )
        set all = GetUnitCountDone( 'nthl' )
        call AddAttackUnit( all, all, 'nthl' )

        // Attack Group #2: Minimum
    elseif (groupID == 2) then
        set all = GetUnitCountDone( 'O002' )
        call AddAttackUnit( all, all, 'O002' )
        call AddAttackUnit( 2,   2,   'nltl' )

    endif
endfunction

//===========================================================================
// Prepares an attack group based on the current attack wave
//===========================================================================
function PrepareForces takes nothing returns nothing
    if (attackWave == 1) then
        call PrepareAttackGroup( 1 )
    endif
endfunction

//===========================================================================
// Sleep delays for each attack wave
//===========================================================================
function AttackWaveDelay takes integer inWave returns nothing
    if (inWave < nextDelay) then
        return
    endif

    set nextDelay = inWave + 1
endfunction

//===========================================================================
// Advances attack wave counter
//===========================================================================
function AttackWaveUpdate takes nothing returns nothing
    call AttackWaveDelay( attackWave )
    set attackWave = attackWave + 1
    if (attackWave > 1) then
        set attackWave = 1
        set nextDelay = attackWave + 1
    endif
endfunction

//===========================================================================
// Basic attack functionality
//===========================================================================
function AttackTarget takes unit target, boolean addAlliance returns nothing
    if (target == null) then
        return
    endif
    if (addAlliance) then
        call SetAllianceTarget( target )
    endif
    call FormGroup( 3, true )
    call AttackMoveKillA( target )
    if (not addAlliance) then
        call SetAllianceTarget( null )
    endif
endfunction

//===========================================================================
// 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 (target == null) then
        set target = GetAllianceTarget()
        if (target != null) then
            set setAlly = false
        endif
    endif

    // Target Priority #2
    if (gCond_Attack_Strong_Creeps) then
        if (target == null) then
            set target = GetExpansionFoe()
            if (target != null) then
                set take_exp = false
            endif
        endif

        // Target Priority #3
    endif
    if (gCond_Attack_Enemy) then
        if (target == null) then
            set target = GetMegaTarget()
        endif

        // Target Priority #4
        if (target == null) then
            set target = GetEnemyExpansion()
        endif

        // Target Priority #5
        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

        // Target Priority #6
    endif
    if (target == null) then
        set target = GetCreepCamp( 0, 6, false )
    endif

    // Target Priority #7
    if (gCond_Attack_Strong_Creeps) then
        if (target == null) then
            set target = GetCreepCamp( 7, 15, true )
        endif

        // Target Priority #8
        if (target == null) then
            set target = GetCreepCamp( 16, 100, true )
        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

//===========================================================================
// Determines all attacking assignments
//===========================================================================
function AttackAssignment takes nothing returns nothing
    call StaggerSleep( 0, 2 )
    if (attackWave == 1) then
        call AttackWaveDelay( 0 )
    endif
    loop
        loop
            call UpdateConditions(  )
            exitwhen (HaveMinimumAttackers() and not CaptainRetreating())
            call Sleep( 2 )
        endloop
        call RemoveInjuries(  )
        call ResetAttackUnits(  )
        call PrepareForces(  )
        call LaunchAttack(  )
    endloop
endfunction

//***************************************************************************
//*
//*  Main Entry Point
//*
//***************************************************************************

//===========================================================================
function main takes nothing returns nothing
    call InitAI(  )
    call InitOptions(  )
    call SelectHeroes(  )
    call CreateCaptains(  )
    call SetHeroLevels( function ChooseHeroSkill )

    call Sleep( 0.1 )
    call StartThread( function WorkerAssignment )
    call StartThread( function AttackAssignment )
    call PlayGame(  )
endfunction
 
If you want an altered melee AI code:
JASS:
//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************

globals
    integer                 attackWave                 = 1
    integer                 nextDelay                  = 0
    integer                 awGold                     = 0
    integer                 awWood                     = 0

    // Conditions
    boolean                 gCond_Attack_Enemy         = false
    boolean                 gCond_Attack_Strong_Creeps = false
    boolean                 gCond_Have_Lumber          = false
    boolean                 gCond_Need_Expansion       = false
endglobals

//***************************************************************************
//*
//*  Utility Functions
//*
//***************************************************************************

//===========================================================================
function CheckLastCommand takes boolean pop returns integer
    local integer cmd = GetLastCommand()
    if (pop) then
        call PopLastCommand(  )
    endif
    return cmd
endfunction

//===========================================================================
function CheckLastCommandData takes boolean pop returns integer
    local integer data = GetLastData()
    if (pop) then
        call PopLastCommand(  )
    endif
    return data
endfunction

//===========================================================================
function TotalFoodProduced takes nothing returns integer
    return GetPlayerState(ai_player,PLAYER_STATE_RESOURCE_FOOD_CAP)
endfunction

//===========================================================================
function ExpansionNeeded takes nothing returns boolean
    return take_exp
endfunction

//===========================================================================
function BuildExpansion takes integer hallID, integer mineID returns nothing
    if (HallsCompleted(hallID)) then
        call SetBuildExpa( TownCount(hallID) + 1, mineID )
    endif
endfunction

//===========================================================================
function CurrentAttackWave takes nothing returns integer
    return attackWave
endfunction

//===========================================================================
function ResetAttackUnits takes nothing returns nothing
    set awGold = 0
    set awWood = 0
    call InitAssaultGroup(  )
endfunction

//===========================================================================
function AddAttackUnit takes integer minQty, integer maxQty, integer unitID returns nothing
    // Track attacking gold workers
    if (unitID == 'n000') then
        set awGold = awGold + minQty
    endif

    // Track attacking wood workers
    if (unitID == 'n000') then
        set awWood = awWood + minQty
    endif

    call SetAssaultGroup( minQty, maxQty, unitID )
endfunction

//***************************************************************************
//*
//*  Basic Options
//*
//***************************************************************************

//===========================================================================
function InitOptions takes nothing returns nothing
    call SetMeleeAI(  )
    call SetDefendPlayer( false )
    call SetRandomPaths( false )
    call SetTargetHeroes( true )
    call SetPeonsRepair( true )
    call SetHeroesFlee( true )
    call SetHeroesBuyItems( false )
    call SetUnitsFlee( true )
    call SetGroupsFlee( true )
    call SetWatchMegaTargets( true )
    call SetIgnoreInjured( true )
    call SetHeroesTakeItems( true )
    call SetSlowChopping( false )
    call SetCaptainChanges( false )
    call SetSmartArtillery( true )
endfunction

//***************************************************************************
//*
//*  Conditions
//*
//***************************************************************************

//===========================================================================
// Updates the values of all preset conditions
//===========================================================================
function UpdateConditions takes nothing returns nothing
    set gCond_Attack_Enemy = ( CheckLastCommand( false ) == 1 )
    set gCond_Attack_Strong_Creeps = ( FoodUsed(  ) >= 40 )
    set gCond_Have_Lumber = ( GetWood(  ) > 0 )
    set gCond_Need_Expansion = ( ( GetGold(  ) < 2000 ) and ( GetGoldOwned(  ) < 2000 ) )
endfunction

//***************************************************************************
//*
//*  Heroes
//*
//***************************************************************************

//===========================================================================
// Stores hero ID and skills
//===========================================================================
function SetHero takes integer order, integer heroid returns nothing
    if (order == 1) then
        set hero_id = heroid
        if (heroid == 'O002') then
            set skills1[ 1] = 'AHtc'
            set skills1[ 2] = 'A001'
            set skills1[ 3] = 'AOcl'
            set skills1[ 4] = 'AHtc'
            set skills1[ 5] = 'A001'
            set skills1[ 6] = 'AOeq'
            set skills1[ 7] = 'AOcl'
            set skills1[ 8] = 'AHtc'
            set skills1[ 9] = 'A001'
            set skills1[10] = 'AOcl'
        endif
    endif
endfunction

//===========================================================================
// Selects hero IDs for three possible heroes
//===========================================================================
function SelectHeroes takes nothing returns nothing
    local integer roll = GetRandomInt(1,100)
    call SetHero( 1, 'O002' )
endfunction

//===========================================================================
// Returns the hero skill for the given hero and level
//===========================================================================
function ChooseHeroSkill takes nothing returns integer
    local integer curHero = GetHeroId()
    local integer level = GetHeroLevelAI()

    if (level > max_hero_level) then
        set max_hero_level = level
    endif

    if (curHero == hero_id) then
        return skills1[level]
    elseif (curHero == hero_id2) then
        return skills2[level]
    elseif (curHero == hero_id3) then
        return skills3[level]
    endif
    return 0
endfunction

//***************************************************************************
//*
//*  Building and Harvesting
//*
//***************************************************************************

//===========================================================================
// Specifies building priorities for workers
//===========================================================================
function BuildPriorities takes nothing returns nothing
    local integer mine = TownWithMine()
    call SetBuildAll( BUILD_UNIT, 1, 'o000', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'n000', -1 )
    if (gCond_Need_Expansion) then
        call BuildExpansion( 'o001', 'o001' )
    endif
    call SetBuildAll( BUILD_UNIT, 2, 'n000', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'n000', -1 )
    call SetBuildAll( BUILD_UNIT, 4, 'n000', -1 )
    call SetBuildAll( BUILD_UNIT, 5, 'n000', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'o001', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'O002', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'nltl', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'nltl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 1, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 1, 'nthl', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'nltl', -1 )
    call SetBuildAll( BUILD_UNIT, 4, 'nltl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 2, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 2, 'nthl', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'o001', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'nstw', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 3, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 5, 'nltl', -1 )
    call SetBuildAll( BUILD_UNIT, 6, 'nltl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 4, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 2, 'nstw', -1 )
    call SetBuildAll( BUILD_UNIT, 7, 'nltl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 5, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 3, 'nthl', -1 )
    call SetBuildAll( BUILD_UNIT, 4, 'nthl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 6, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 8, 'nltl', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'nstw', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 7, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 8, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 9, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 10, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 11, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 12, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 13, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 14, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 15, 'h000', 0 )
        call SetBuildAll( BUILD_UNIT, 16, 'h000', 0 )
    endif
endfunction

//===========================================================================
// Specifies harvesting priorities for workers
//===========================================================================
function HarvestPriorities takes nothing returns nothing
    local integer mine = TownWithMine()
    local integer allGold = GetUnitCountDone('n000')
    local integer allWood = GetUnitCountDone('n000')
    local integer numWorkers
    set numWorkers = 5
    call HarvestGold( 0, numWorkers )
    set numWorkers = 5
    call HarvestGold( 1, numWorkers )
endfunction

//===========================================================================
// Determines all building and harvesting assignments for workers
//===========================================================================
function WorkerAssignment takes nothing returns nothing
    loop
        call UpdateConditions(  )

        // Harvesting
        call ClearHarvestAI(  )
        call HarvestPriorities(  )

        // Building
        call InitBuildArray(  )
        call BuildPriorities(  )

        call Sleep( 2 )
    endloop
endfunction

//***************************************************************************
//*
//*  Attacking
//*
//***************************************************************************

//===========================================================================
// Returns true if the minimum forces for an attack exist
//===========================================================================
function HaveMinimumAttackers takes nothing returns boolean
    local integer count

    // Check for attack wave limit
    if (attackWave > 1) then
        return false
    endif

    // Attack Group: Minimum
    set count = GetUnitCountDone( 'nltl' )
    if (count < 2) then
        return false
    endif
    return true
endfunction

//===========================================================================
// Assigns units to attack based on the given attack group
//===========================================================================
function PrepareAttackGroup takes integer groupID returns nothing
    local integer all

    // Attack Group #1: All Units
    if (groupID == 1) then
        set all = GetUnitCountDone( 'O002' )
        call AddAttackUnit( all, all, 'O002' )
        set all = GetUnitCountDone( 'nstw' )
        call AddAttackUnit( all, all, 'nstw' )
        set all = GetUnitCountDone( 'nltl' )
        call AddAttackUnit( all, all, 'nltl' )
        set all = GetUnitCountDone( 'nthl' )
        call AddAttackUnit( all, all, 'nthl' )

        // Attack Group #2: Minimum
    elseif (groupID == 2) then
        set all = GetUnitCountDone( 'O002' )
        call AddAttackUnit( all, all, 'O002' )
        call AddAttackUnit( 2,   2,   'nltl' )

    endif
endfunction

//===========================================================================
// Prepares an attack group based on the current attack wave
//===========================================================================
function PrepareForces takes nothing returns nothing
    if (attackWave == 1) then
        call PrepareAttackGroup( 1 )
    endif
endfunction

//===========================================================================
// Sleep delays for each attack wave
//===========================================================================
function AttackWaveDelay takes integer inWave returns nothing
    if (inWave < nextDelay) then
        return
    endif

    set nextDelay = inWave + 1
endfunction

//===========================================================================
// Advances attack wave counter
//===========================================================================
function AttackWaveUpdate takes nothing returns nothing
    call AttackWaveDelay( attackWave )
    set attackWave = attackWave + 1
    if (attackWave > 1) then
        set attackWave = 1
        set nextDelay = attackWave + 1
    endif
endfunction

//===========================================================================
// Basic attack functionality
//===========================================================================
function AttackTarget takes unit target, boolean addAlliance returns nothing
    if (target == null) then
        return
    endif
    if (addAlliance) then
        call SetAllianceTarget( target )
    endif
    call FormGroup( 3, true )
    call AttackMoveKillA( target )
    if (not addAlliance) then
        call SetAllianceTarget( null )
    endif
endfunction

//===========================================================================
// 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 (target == null) then
        set target = GetAllianceTarget()
        if (target != null) then
            set setAlly = false
        endif
    endif

    // Target Priority #2
    if (gCond_Attack_Strong_Creeps) then
        if (target == null) then
            set target = GetExpansionFoe()
            if (target != null) then
                set take_exp = false
            endif
        endif

        // Target Priority #3
    endif
    if (gCond_Attack_Enemy) then
        if (target == null) then
            set target = GetMegaTarget()
        endif

        // Target Priority #4
        if (target == null) then
            set target = GetEnemyExpansion()
        endif

        // Target Priority #5
        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

        // Target Priority #6
    endif
    if (target == null) then
        set target = GetCreepCamp( 0, 6, false )
    endif

    // Target Priority #7
    if (gCond_Attack_Strong_Creeps) then
        if (target == null) then
            set target = GetCreepCamp( 7, 15, true )
        endif

        // Target Priority #8
        if (target == null) then
            set target = GetCreepCamp( 16, 100, true )
        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

//===========================================================================
// Determines all attacking assignments
//===========================================================================
function AttackAssignment takes nothing returns nothing
    call StaggerSleep( 0, 2 )
    if (attackWave == 1) then
        call AttackWaveDelay( 0 )
    endif
    loop
        loop
            call UpdateConditions(  )
            exitwhen (HaveMinimumAttackers() and not CaptainRetreating())
            call Sleep( 2 )
        endloop
        call RemoveInjuries(  )
        call ResetAttackUnits(  )
        call PrepareForces(  )
        call LaunchAttack(  )
    endloop
endfunction

//***************************************************************************
//*
//*  Main Entry Point
//*
//***************************************************************************

//===========================================================================
function main takes nothing returns nothing
    call InitAI(  )
    call InitOptions(  )
    call SelectHeroes(  )
    call CreateCaptains(  )
    call SetHeroLevels( function ChooseHeroSkill )

    call Sleep( 0.1 )
    call StartThread( function WorkerAssignment )
    call StartThread( function AttackAssignment )
    call PlayGame(  )
endfunction
Unfortunately I don't quite understand JASS. Does this code just... understand which unit are which or do I have to specify a list of units somewhere? Do I swap BUILD_UNIT for unit codes or??? Sorry but I don't understand any of that :(

Also lumber in my map is converted from gold, and you have only 1 hero to pick per match, so this would add a whole new layer of complexity I would think.

I do appreciate you taking the time though.

Oh thanks, I'll check it out.

By the way, anyone know how to use AMAI? I'm not quite sure if it's compatible anymore but I couldn't even get it to work. Perl 5.8.9 isnt even available anymore unless you buy it, not that I would know what to do with it. This whole tool feels like esoteric computer magic to me so anyone who has a working AMAI and has some free time, care to help?
 
oh btw,that code should be CnP in the notepad,then save it as a .j file.
Then import it unto your map

I'll give it a try, but will it actually work with how my resource collection does? I mean, lumber isn't harvested, it's converted from gold. Like I said, I don't understand this but I'll try and import it.

Will it just fire up on it's own once imported or do I have to make the map run it or...?

Sorry if these questions come off as dumb but I really have no idea what I'm supposed to do here, besides what you told me ofc.
 
You mean in the trigger editor? Because it's not showing up there.

oh and which parts do I need to change for the raw codes? (is where is says unit_id?)

For example:

JASS:
//===========================================================================
function BuildExpansion takes integer hallID, integer mineID returns nothing
    if (HallsCompleted(hallID)) then
        call SetBuildExpa( TownCount(hallID) + 1, mineID )
    endif
endfunction

do I replace hallID with the raw code of a, eg, demon town hall and mineID for its corresponding 'haunted' gold mine?
 
Status
Not open for further replies.
Top