Name | Type | is_array | initial_value |
function Trig_Melee_Initialization_Actions takes nothing returns nothing
call MeleeStartingVisibility( )
call WC1MeleeStartingHeroLimit( )
call MeleeGrantHeroItems( )
call WC1MeleeStartingResources( )
call MeleeClearExcessUnits( )
call WC1MeleeStartingUnits( )
call WC1MeleeStartingAI( )
call MeleeInitVictoryDefeat( )
call SetCreepCampFilterState( true )
endfunction
//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
set gg_trg_Melee_Initialization = CreateTrigger( )
call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions )
endfunction
library WC1Script initializer WC1ScriptInit
globals
private constant integer ID_UA = 'Alsh' // Unholy Armor
private constant integer ID_SS = 'AOss' // Shadowstep
private constant integer ID_PC = 'ntor' // Poison Cloud
private trigger trgSpellCast = CreateTrigger()
private trigger trgUnitSummoned = CreateTrigger()
private trigger trgTimerExpire = CreateTrigger()
private hashtable htb = InitHashtable()
endglobals
//===========================================================================
// MELEE INITIALIZATION
//===========================================================================
// Initialize hero limits
function WC1MeleeStartingHeroLimit takes nothing returns nothing
local integer index
set index = 0
loop
// max heroes per player
call SetPlayerTechMaxAllowed(Player(index), 'HERO', 1)
// each player is restricted to a limit per hero type as well
call ReducePlayerTechMaxAllowed(Player(index), 'Hpal', bj_MELEE_HERO_TYPE_LIMIT)
call ReducePlayerTechMaxAllowed(Player(index), 'Hblm', bj_MELEE_HERO_TYPE_LIMIT)
call ReducePlayerTechMaxAllowed(Player(index), 'Obla', bj_MELEE_HERO_TYPE_LIMIT)
call ReducePlayerTechMaxAllowed(Player(index), 'Otch', bj_MELEE_HERO_TYPE_LIMIT)
set index = index + 1
exitwhen index == bj_MAX_PLAYERS
endloop
endfunction
// Initialize starting resources
function WC1MeleeStartingResources takes nothing returns nothing
local player indexPlayer = null
local integer index = 0
// Set each player's starting resources.
loop
set indexPlayer = Player(index)
if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
call SetPlayerState(indexPlayer, PLAYER_STATE_RESOURCE_GOLD, 450)
call SetPlayerState(indexPlayer, PLAYER_STATE_RESOURCE_LUMBER, 135)
endif
set index = index + 1
exitwhen index == bj_MAX_PLAYERS
endloop
set indexPlayer = null
endfunction
// Initialize units
function WC1MeleeStartingUnits takes nothing returns nothing
local integer index = 0
local integer sheepIndex
local player indexPlayer
local location indexStartLoc
local race indexRace
local string preload
local integer townHall
local integer peon
local real peonX
local real peonY
local integer hero1
local integer hero2
local boolean unknownRace
local unit nearestMine
local location nearMineLoc
local location heroLoc
local real unitSpacing = 64.00
local boolean useRandomHero = IsMapFlagSet(MAP_RANDOM_HERO)
call Preloader( "scripts\\SharedMelee.pld" )
loop
set indexPlayer = Player(index)
if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
set indexStartLoc = GetStartLocationLoc(GetPlayerStartLocation(indexPlayer))
set indexRace = GetPlayerRace(indexPlayer)
set unknownRace = false
// Human
if indexRace == RACE_HUMAN or indexRace == RACE_NIGHTELF then
set preload = "scripts\\HumanMelee.pld"
set townHall = 'htow'
set peon = 'hpea'
set hero1 = 'Hpal'
set hero2 = 'Hblm'
// Orc
elseif indexRace == RACE_ORC or indexRace == RACE_UNDEAD then
set preload = "scripts\\OrcMelee.pld"
set townHall = 'ogre'
set peon = 'opeo'
set hero1 = 'Obla'
set hero2 = 'Otch'
// Unknown
else
set unknownRace = true
set peonX = GetLocationX(indexStartLoc)
set peonY = GetLocationY(indexStartLoc)
set sheepIndex = 0
loop
call CreateUnit(indexPlayer, 'nshe', peonX + GetRandomReal(-256, 256), peonY + GetRandomReal(-256, 256), GetRandomReal(0, 360))
set sheepIndex = sheepIndex + 1
exitwhen sheepIndex == 12
endloop
call SetPlayerState(indexPlayer, PLAYER_STATE_RESOURCE_HERO_TOKENS, bj_MELEE_STARTING_HERO_TOKENS )
endif
// Starting Units
if not unknownRace then
call Preloader(preload)
// Create Hall
call CreateUnitAtLoc(indexPlayer, townHall, indexStartLoc, bj_UNIT_FACING)
// Spawn peasants
set nearestMine = MeleeFindNearestMine(indexStartLoc, bj_MELEE_MINE_SEARCH_RADIUS)
if (nearestMine != null) then
set nearMineLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), indexStartLoc, 320, 0)
// Spawn Peasants near the mine.
set peonX = GetLocationX(nearMineLoc)
set peonY = GetLocationY(nearMineLoc)
call CreateUnit(indexPlayer, peon, peonX + 0.00 * unitSpacing, peonY + 1.00 * unitSpacing, bj_UNIT_FACING)
call CreateUnit(indexPlayer, peon, peonX + 1.00 * unitSpacing, peonY + 0.15 * unitSpacing, bj_UNIT_FACING)
call CreateUnit(indexPlayer, peon, peonX - 1.00 * unitSpacing, peonY + 0.15 * unitSpacing, bj_UNIT_FACING)
call CreateUnit(indexPlayer, peon, peonX + 0.60 * unitSpacing, peonY - 1.00 * unitSpacing, bj_UNIT_FACING)
call CreateUnit(indexPlayer, peon, peonX - 0.60 * unitSpacing, peonY - 1.00 * unitSpacing, bj_UNIT_FACING)
// Set random hero spawn point to be off to the side of the start location.
if useRandomHero then
set heroLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), indexStartLoc, 384, 45)
endif
else
// Spawn Peasants directly south of the town hall.
set peonX = GetLocationX(indexStartLoc)
set peonY = GetLocationY(indexStartLoc) - 224.00
call CreateUnit(indexPlayer, peon, peonX + 2.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
call CreateUnit(indexPlayer, peon, peonX + 1.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
call CreateUnit(indexPlayer, peon, peonX + 0.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
call CreateUnit(indexPlayer, peon, peonX - 1.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
call CreateUnit(indexPlayer, peon, peonX - 2.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
// Set random hero spawn point to be just south of the start location.
if useRandomHero then
set heroLoc = Location(peonX, peonY - 2.00 * unitSpacing)
endif
endif
// If the "Random Hero" option is set, start the player with a random hero.
// Otherwise, give them a "free hero" token.
if useRandomHero then
call MeleeRandomHeroLoc(indexPlayer, hero1, hero1, hero2, hero2, heroLoc)
else
call SetPlayerState(indexPlayer, PLAYER_STATE_RESOURCE_HERO_TOKENS, bj_MELEE_STARTING_HERO_TOKENS)
endif
endif
// Center the camera on the initial Peasants.
call SetCameraPositionForPlayer(indexPlayer, peonX, peonY)
call SetCameraQuickPositionForPlayer(indexPlayer, peonX, peonY)
endif
set index = index + 1
exitwhen index == bj_MAX_PLAYERS
endloop
set indexPlayer = null
set indexStartLoc = null
set indexRace = null
set nearestMine = null
set nearMineLoc = null
set heroLoc = null
endfunction
// Replaces all enumerated units with 'egol' mines
private function ReplaceMinesEnum takes nothing returns boolean
local unit mine = GetFilterUnit()
local real x = GetUnitX(mine)
local real y = GetUnitY(mine)
local integer gold = GetResourceAmount(mine)
call RemoveUnit(mine)
set mine = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'egol', -999999999, -999999999, bj_UNIT_FACING)
call SetResourceAmount(mine, gold)
call ShowUnit(mine, false)
call SetUnitX(mine, x)
call SetUnitY(mine, y)
call ShowUnit(mine, true)
set mine = null
return false
endfunction
// Initialize AI
function WC1MeleeStartingAI takes nothing returns nothing
local integer index = 0
local boolean haveNE_AI = false
local player indexPlayer = null
local race indexRace = null
local group mines = null
loop
set indexPlayer = Player(index)
if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
set indexRace = GetPlayerRace(indexPlayer)
if GetPlayerController(indexPlayer) == MAP_CONTROL_COMPUTER then
if indexRace == RACE_HUMAN or indexRace == RACE_ORC or indexRace == RACE_UNDEAD or indexRace == RACE_NIGHTELF then
set haveNE_AI = haveNE_AI or indexRace == RACE_NIGHTELF
call StartMeleeAI(indexPlayer, "scripts\\wc1.ai")
endif
call ShareEverythingWithTeamAI(indexPlayer)
endif
endif
set index = index + 1
exitwhen index == bj_MAX_PLAYERS
endloop
// Replace 'ngol' goldmines with 'egol' goldmines if we have NE AI players
if haveNE_AI then
set mines = CreateGroup()
call GroupEnumUnitsOfType(mines, UnitId2String('ngol'), function ReplaceMinesEnum)
call DestroyGroup(mines)
set mines = null
endif
set indexPlayer = null
set indexRace = null
endfunction
//===========================================================================
// ABILITY TRIGGERS
//===========================================================================
// Timer Expires
private function TimerExpireCndAcn takes nothing returns boolean
local timer tmr = GetExpiredTimer()
local unit u = null
local integer id = GetHandleId(tmr)
// Unholy Armor: cancel unvulnerability
if HaveSavedHandle(htb, id, ID_UA) then
call SetUnitInvulnerable(LoadUnitHandle(htb, id, ID_UA), false)
// Shadowstep: reset move speed
elseif HaveSavedHandle(htb, id, ID_SS) then
set u = LoadUnitHandle(htb, id, ID_SS)
call SetUnitMoveSpeed(u, GetUnitDefaultMoveSpeed(u))
set u = null
endif
call FlushChildHashtable(htb, id)
call DestroyTimer(tmr)
set tmr = null
return false
endfunction
// Spell is cast
private function SpellCastCndAcn takes nothing returns boolean
local unit target = null
local unit caster = null
local timer tmr = null
local integer spellId = GetSpellAbilityId()
local real hyp
local real deg
local real rad
local real speed
local real dur
if spellId == ID_UA or spellId == ID_SS then
set target = GetSpellTargetUnit()
set caster = GetSpellAbilityUnit()
// Unholy Armor: make invulnerable and take half HP
if spellId == ID_UA then
call SetUnitInvulnerable(target, true)
call SetUnitState(target, UNIT_STATE_LIFE, GetUnitState(target, UNIT_STATE_LIFE) / 2)
set tmr = CreateTimer()
call SaveUnitHandle(htb, GetHandleId(tmr), ID_UA, target)
if IsUnitType(caster, UNIT_TYPE_HERO) then
set dur = BlzGetAbilityRealLevelField(BlzGetUnitAbility(caster, ID_UA), ABILITY_RLF_DURATION_HERO, 0)
else
set dur = BlzGetAbilityRealLevelField(BlzGetUnitAbility(caster, ID_UA), ABILITY_RLF_DURATION_NORMAL, 0)
endif
// Shadowstep: move behind target and increase move speed
else
set hyp = BlzGetUnitCollisionSize(target)/2 + BlzGetUnitCollisionSize(caster)/2 + 20
set deg = GetUnitFacing(target)
set rad = deg*bj_DEGTORAD
call SetUnitPosition(caster, GetUnitX(target) - Cos(rad)*hyp, GetUnitY(target) - Sin(rad)*hyp)
call SetUnitFacing(caster, deg)
set speed = GetUnitDefaultMoveSpeed(caster)*1.7
if speed > GetUnitMoveSpeed(caster) then // make sure speed is actually increased
set tmr = CreateTimer()
set dur = 2
call SaveUnitHandle(htb, GetHandleId(tmr), ID_SS, caster)
call SetUnitMoveSpeed(caster, speed)
endif
call IssueTargetOrder(caster, "attack", target)
endif
// Start the timer
if tmr != null then
call TriggerRegisterTimerExpireEvent(trgTimerExpire, tmr)
call TimerStart(tmr, dur, false, null)
set tmr = null
endif
set target = null
set caster = null
endif
return false
endfunction
// Unit is summoned
private function UnitSummonedCndAcn takes nothing returns boolean
local unit summonedUnit = GetSummonedUnit()
// Poison Cloud: change owner to neutral passive
if GetUnitTypeId(summonedUnit) == ID_PC then
call SetUnitOwner(summonedUnit, Player(PLAYER_NEUTRAL_PASSIVE), false)
endif
set summonedUnit = null
return false
endfunction
//===========================================================================
// LIBRARY INIT
//===========================================================================
private function WC1ScriptInit takes nothing returns nothing
local integer i = 0
loop
call TriggerRegisterPlayerUnitEvent(trgSpellCast, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
call TriggerRegisterPlayerUnitEvent(trgUnitSummoned, Player(i), EVENT_PLAYER_UNIT_SUMMON, null)
set i = i+1
exitwhen i == bj_MAX_PLAYERS
endloop
call TriggerAddCondition(trgSpellCast, function SpellCastCndAcn)
call TriggerAddCondition(trgUnitSummoned, function UnitSummonedCndAcn)
call TriggerAddCondition(trgTimerExpire, function TimerExpireCndAcn)
endfunction
endlibrary