[AI] campaign ai quirks

Status
Not open for further replies.

zzc

zzc

Level 3
Joined
Apr 25, 2016
Messages
20
JASS:
//============================================================================
//  Night Elf 07 -- light blue player -- AI Script
//============================================================================
globals
    constant integer DEIMOS             = 'H004'
    constant integer LAKCHE             = 'H006'
	constant integer SIEGE             = 'hmtm'
	constant integer FURB1             = 'nhym'
	constant integer FURB2             = 'nhea'
endglobals

function main takes nothing returns nothing
    call CampaignAI(HOUSE,null)

	call SetCaptainHome(BOTH_CAPTAINS,2400,-5568)	
	
    //call SetReplacements(3,3,3)

    call SetGroupsFlee(true)
    call SetHeroesFlee(true)
    call SetUnitsFlee(true)
    call SetPeonsRepair(true)
	call SetSlowChopping(false)

    call SetBuildUnit( 1, PEASANT       )
    call SetBuildUnit( 1, BARRACKS      )
    call SetBuildUnit( 2, PEASANT       )
    call SetBuildUnit( 1, LUMBER_MILL   )
    call SetBuildUnit( 3, PEASANT       )
    call SetBuildUnit( 1, BLACKSMITH    )
    call SetBuildUnit( 1, HUMAN_ALTAR   )
    call SetBuildUnit( 1, WORKSHOP      )
    call SetBuildUnit( 1, SANCTUM       )
    call SetBuildUnit( 8, PEASANT       )

    call CampaignDefenderEx( 1,1,1, JAINA       )
    call CampaignDefenderEx( 1,1,1, DEIMOS      )
    call CampaignDefenderEx( 1,1,1, LAKCHE      )
    call CampaignDefenderEx( 0,2,1, FOOTMEN     )
	call CampaignDefenderEx( 1,2,0, KNIGHT		)
    call CampaignDefenderEx( 1,2,1, RIFLEMEN    )
    call CampaignDefenderEx( 1,2,1, PRIEST      )
    call CampaignDefenderEx( 1,2,1, SORCERESS   )
    call CampaignDefenderEx( 1,2,1, SIEGE   )	
	call CampaignDefenderEx( 1,2,1, FURB1   )	
	call CampaignDefenderEx( 1,2,1, FURB2   )	
	
    loop
        exitwhen GetUnitCount(CASTLE)==0
        call Sleep(5)
    endloop

    call InitBuildArray()
    set do_campaign_farms   = false
    set campaign_gold_peons = 0
    set campaign_wood_peons = 0

    call SleepForever()
endfunction


the ai will build supply structure accordingly despite not being in the build list, how does it do that??

and wats the code to use to get an attack wave moving immediately when its complete - no duration wait
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,243
the ai will build supply structure accordingly despite not being in the build list, how does it do that??

Start by looking at all the complex functions you are calling.
JASS:
function CampaignAI takes integer farms,code heroes returns nothing
    if GetGameDifficulty() == MAP_DIFFICULTY_EASY then
        set difficulty = EASY
        call SetTargetHeroes(false)
        call SetUnitsFlee(false)
    elseif GetGameDifficulty() == MAP_DIFFICULTY_NORMAL then
        set difficulty = NORMAL
        call SetTargetHeroes(false)
        call SetUnitsFlee(false)
    elseif GetGameDifficulty() == MAP_DIFFICULTY_HARD then
        set difficulty = HARD
        call SetPeonsRepair(true)
    else
        set difficulty = INSANE
    endif
    call InitAI()
    call InitBuildArray()
    call InitAssaultGroup()
    call CreateCaptains()
    call SetNewHeroes(false)
    if heroes != null then
        call SetHeroLevels(heroes)
    endif
    call SetHeroesFlee(false)
    call SetGroupsFlee(false)
    call SetSlowChopping(true)
    call GroupTimedLife(false)
    call SetCampaignAI()
    call Sleep(0.1)
    set racial_farm = farms
    call StartThread(function CampaignBasics)
    call StartBuildLoop()
endfunction

This one looks like it might be the right place.
JASS:
function StartBuildLoop takes nothing returns nothing
    call StartThread(function BuildLoop)
endfunction

Wonder what that function does.
JASS:
function BuildLoop takes nothing returns nothing
    call OneBuildLoop()
    call StaggerSleep(1,2)
    loop
        call OneBuildLoop()
        call Sleep(2)
    endloop
endfunction

So this is what builds the units...
JASS:
function OneBuildLoop takes nothing returns nothing
    local integer index = 0
    local integer qty
    local integer id
    local integer tp
    set total_gold = GetGold() - gold_buffer
    set total_wood = GetWood()
    loop
        exitwhen index == build_length
        set qty = build_qty [index]
        set id  = build_item[index]
        set tp  = build_type[index]
        if tp == BUILD_UNIT then
            if not StartUnit(qty,id,build_town[index]) then
                return
            endif
        elseif tp == BUILD_UPGRADE then
            call StartUpgrade(qty,id)
        else // tp == BUILD_EXPAND
            if not StartExpansion(qty,id) then
                return
            endif
        endif
        set index = index + 1
    endloop
endfunction

However that is not what makes the farms. Must be the campaign think thread.
JASS:
function CampaignBasics takes nothing returns nothing
    call Sleep(1)
    call CampaignBasicsA()
    call StaggerSleep(1,5)
    loop
        call CampaignBasicsA()
        call Sleep(campaign_basics_speed)
    endloop
endfunction

This looks like the right place.
JASS:
function CampaignBasicsA takes nothing returns nothing
    local integer food_each = GetFoodMade(racial_farm)
    local integer on_wood
    call ClearHarvestAI()
    if CaptainInCombat(false) then
        set on_wood = 0
    else
        set on_wood = campaign_wood_peons
    endif
    call HarvestGold(0,campaign_gold_peons)
    call HarvestWood(0,on_wood)
    if harvest_town1 then
        call HarvestGold(1,campaign_gold_peons)
        call HarvestWood(1,on_wood)
    endif
    if harvest_town2 then
        call HarvestGold(2,campaign_gold_peons)
        call HarvestWood(2,on_wood)
    endif
    if harvest_town3 then
        call HarvestGold(3,campaign_gold_peons)
        call HarvestWood(3,on_wood)
    endif
    if do_campaign_farms and FoodUsed()+food_each-1 > food_each*(TownCount(racial_farm)+1) then
        call StartUnit(TownCount(racial_farm)+1,racial_farm,-1)
    endif
    if build_campaign_attackers then
        call BuildAttackers()
    endif
    if not CaptainInCombat(false) then
        call BuildDefenders()
    endif
    call FillGuardPosts()
    call ReturnGuardPosts()
endfunction

And here is how they build farms...
JASS:
    if do_campaign_farms and FoodUsed()+food_each-1 > food_each*(TownCount(racial_farm)+1) then
        call StartUnit(TownCount(racial_farm)+1,racial_farm,-1)
    endif

WC3 AI actually looks better than I thought it would. I am surprised so few people have touched it.
 

zzc

zzc

Level 3
Joined
Apr 25, 2016
Messages
20
ah its from common.ai

so whats the purpose of this function?
set do_campaign_farms = false

any script with this still builds supply structures....
 
Status
Not open for further replies.
Top