что здесь не так с этим кодом...кто знает... почему крипы в определённый момент начинают бегать туда-сюда? противоречивые приказы...но где? КАК сделать, чтобы не было глюков и нормально вся игра проходила.... "пиши свой ИИ"..не все являются задротами Вара и умеют разбираться в этих переменных(
//===========================================================================
// 
// Satyr AI
// 
//   Warcraft III AI script
//   Generated by the Warcraft III World Editor
//   Date: Thu Sep 29 20:03:17 2016
// 
//===========================================================================

//***************************************************************************
//*
//*  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 == 'n008') then
        set awGold = awGold + minQty
    endif

    // Track attacking wood workers
    if (unitID == 'n008') 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 == 'O009') then
            set skills1[ 1] = 'ANfb'
            set skills1[ 2] = 'AHfs'
            set skills1[ 3] = 'ANbf'
            set skills1[ 4] = 'ANfb'
            set skills1[ 5] = 'AHfs'
            set skills1[ 6] = 'AUin'
            set skills1[ 7] = 'ANbf'
            set skills1[ 8] = 'ANfb'
            set skills1[ 9] = 'AHfs'
            set skills1[10] = 'ANbf'
        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, 'O009' )
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, 'n008', -1 )
    if (gCond_Need_Expansion) then
        call BuildExpansion( 'o008', 'o008' )
    endif
    call SetBuildAll( BUILD_UNIT, 2, 'n008', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'n008', -1 )
    call SetBuildAll( BUILD_UNIT, 4, 'n008', -1 )
    call SetBuildAll( BUILD_UNIT, 5, 'n008', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'o008', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'O009', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'nsty', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'nsty', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'nsty', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 1, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 1, 'nsat', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'nsat', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'nsat', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'nsts', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'nsts', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 2, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 3, 'nsts', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'nstl', -1 )
    call SetBuildAll( BUILD_UNIT, 2, 'nstl', -1 )
    call SetBuildAll( BUILD_UNIT, 3, 'o008', -1 )
    call SetBuildAll( BUILD_UNIT, 1, 'nsth', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 3, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 3, 'nstl', -1 )
    call SetBuildAll( BUILD_UNIT, 4, 'nstl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 4, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 4, 'nsts', -1 )
    call SetBuildAll( BUILD_UNIT, 5, 'nsts', -1 )
    call SetBuildAll( BUILD_UNIT, 5, 'nstl', -1 )
    call SetBuildAll( BUILD_UNIT, 6, 'nstl', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 5, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 6, 'nsts', -1 )
    call SetBuildAll( BUILD_UNIT, 7, 'nsts', -1 )
    call SetBuildAll( BUILD_UNIT, 8, 'nsts', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 6, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 4, 'nsat', -1 )
    call SetBuildAll( BUILD_UNIT, 5, 'nsat', -1 )
    call SetBuildAll( BUILD_UNIT, 6, 'nsat', -1 )
    if (gCond_Have_Lumber) then
        call SetBuildAll( BUILD_UNIT, 7, 'h000', 0 )
    endif
    call SetBuildAll( BUILD_UNIT, 4, 'nsty', -1 )
    call SetBuildAll( BUILD_UNIT, 5, 'nsty', -1 )
    call SetBuildAll( BUILD_UNIT, 6, 'nsty', -1 )
    if (gCond_Have_Lumber) then
        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('n008')
    local integer allWood = GetUnitCountDone('n008')
    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( 'O009' )
    if (count < 1) then
        return false
    endif
    set count = GetUnitCountDone( 'nsty' )
    if (count < 3) 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( 'O009' )
        call AddAttackUnit( all, all, 'O009' )
        set all = GetUnitCountDone( 'nsty' )
        call AddAttackUnit( all, all, 'nsty' )
        set all = GetUnitCountDone( 'nsat' )
        call AddAttackUnit( all, all, 'nsat' )
        set all = GetUnitCountDone( 'nsts' )
        call AddAttackUnit( all, all, 'nsts' )
        set all = GetUnitCountDone( 'nstl' )
        call AddAttackUnit( all, all, 'nstl' )
        set all = GetUnitCountDone( 'nsth' )
        call AddAttackUnit( all, all, 'nsth' )

        // Attack Group #2: Minimum
    elseif (groupID == 2) then
        call AddAttackUnit( 1,   1,   'O009' )
        call AddAttackUnit( 3,   3,   'nsty' )

    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

Принятый ответ

Отключайте по одной, и смотрите какая глючит.
Возможно, что он пытается атаковать кого-либо, но местная пачка крипов сбивает атаку, сообщая что на базу напали, ну или что-то подобное.
`
ОЖИДАНИЕ РЕКЛАМЫ...
0
18
6 лет назад
0
не стоит ли на карте снова что-то неуязвимое?
0
17
6 лет назад
0
Отключайте по одной, и смотрите какая глючит.
Возможно, что он пытается атаковать кого-либо, но местная пачка крипов сбивает атаку, сообщая что на базу напали, ну или что-то подобное.
Принятый ответ
0
20
6 лет назад
0
Дело скорее всего в их приоритетах. Они вечно отступают пока что-то не случится... Мб привязка к фуд капу или технологиям
Чтобы оставить комментарий, пожалуйста, войдите на сайт.