- Joined
- Feb 2, 2006
- Messages
- 1,631
Hey,
I am trying to create an AI script for one hero only. The player should not try to build a base or collect gold. There should be only his/her hero walking around, creeping, leveling, buying items and when the hero dies he/she can be revived at a fixed altar.
Here is my current script for humans:
The current issues are:
I am trying to create an AI script for one hero only. The player should not try to build a base or collect gold. There should be only his/her hero walking around, creeping, leveling, buying items and when the hero dies he/she can be revived at a fixed altar.
Here is my current script for humans:
JASS:
//===========================================================================
// Calculate the modulus/remainder of (dividend) divided by (divisor).
// Examples: 18 mod 5 = 3. 15 mod 5 = 0. -8 mod 5 = 2.
//
function ModuloInteger takes integer dividend, integer divisor returns integer
local integer modulus = dividend - (dividend / divisor) * divisor
// If the dividend was negative, the above modulus calculation will
// be negative, but within (-divisor..0). We can add (divisor) to
// shift this result into the desired range of (0..divisor).
if (modulus < 0) then
set modulus = modulus + divisor
endif
return modulus
endfunction
function ChooseHeroSkill takes nothing returns integer
local integer curHero = GetHeroId()
local integer level = GetHeroLevelAI()
local integer mod = ModuloInteger(level, 4)
local boolean skillUlti = ModuloInteger(level, 6) == 0 and level / 6 <= 9
if (curHero == PALADIN) then
if (skillUlti) then
return RESURRECTION
elseif (mod == 0) then
return HOLY_BOLT
elseif (mod == 1) then
return DIVINE_SHIELD
elseif (mod == 2) then
return DEVOTION_AURA
endif
elseif (curHero == ARCHMAGE) then
if (skillUlti) then
return MASS_TELEPORT
elseif (mod == 0) then
return BLIZZARD
elseif (mod == 1) then
return BRILLIANCE_AURA
elseif (mod == 2) then
return WATER_ELEMENTAL
endif
elseif (curHero == MTN_KING) then
if (skillUlti) then
return AVATAR
elseif (mod == 0) then
return THUNDER_CLAP
elseif (mod == 1) then
return THUNDER_BOLT
elseif (mod == 2) then
return BASH
endif
elseif (curHero == BLOOD_MAGE) then
if (skillUlti) then
return SUMMON_PHOENIX
elseif (mod == 0) then
return FLAME_STRIKE
elseif (mod == 1) then
return BANISH
elseif (mod == 2) then
return SIPHON_MANA
endif
endif
return 'Aamk'
endfunction
function InitHero takes nothing returns nothing
if (GetUnitCountDone(PALADIN) > 0) then
set hero_id = PALADIN
elseif (GetUnitCountDone(ARCHMAGE) > 0) then
set hero_id = ARCHMAGE
elseif (GetUnitCountDone(MTN_KING) > 0) then
set hero_id = MTN_KING
elseif (GetUnitCountDone(BLOOD_MAGE) > 0) then
set hero_id = BLOOD_MAGE
endif
endfunction
function ConfigureAI takes nothing returns nothing
call SetTargetHeroes( true )
call SetUnitsFlee( true )
call SetHeroesFlee( true )
call SetPeonsRepair( true )
call SetHeroesBuyItems( true )
call SetHeroesTakeItems( true )
call SetSlowChopping( false )
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 (target == null) then
set target = GetExpansionFoe()
if (target != null) then
set take_exp = false
endif
endif
// Target Priority #3
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
if (target == null) then
set target = GetCreepCamp( 0, 9, false )
endif
// Target Priority #7
if (target == null) then
set target = GetCreepCamp( 10, 100, true )
endif
// Attack the target and increment attack wave
if (target != null) then
call AttackTarget( target, setAlly )
else
// If no target was found, sleep a bit before trying again
call Sleep( 20 )
endif
endfunction
function AttackWaves takes nothing returns nothing
loop
call InitAssaultGroup()
call CampaignAttackerEx( 1, 1, 1, hero_id )
call Sleep( 10 ) // Waits 10 seconds before attacking
call LaunchAttack()
endloop
endfunction
function main takes nothing returns nothing
call CampaignAI( 0, function ChooseHeroSkill )
call ConfigureAI( )
call InitHero( )
call AttackWaves( )
endfunction
The current issues are:
- The hero stands around and does nothing.
- How can I make sure that the hero will buy items and avoid too strong units.
- How can I let the AI buy Zeppelins and mercenaries?