- Joined
- Jun 15, 2016
- Messages
- 472
These are my solutions to universal missions 1-3.
Just a note about this mission: Perhaps it should include a note to make sure that the gryphon's target is inside the playable map area. Not that big a deal, but still worth the few extra words.
I also made implemented mission 2 with waits just for fun.
P.S.: Do I need to post a test map of all that? Cause all the missions so far are on the same map...
JASS:
function Trig_Order_Tracking_Actions takes nothing returns nothing
local string order = OrderId2String(GetIssuedOrderId())
local string orunit = GetUnitName(GetOrderedUnit())
local widget target = GetOrderTarget()
local string sr = orunit + " - " + order
if GetOrderTarget() != null then
call PingMinimap(GetWidgetX(target), GetWidgetY(target), 2.0)
endif
call BJDebugMsg(sr)
endfunction
//===========================================================================
function InitTrig_Order_Tracking takes nothing returns nothing
set gg_trg_Order_Tracking = CreateTrigger( )
// Initialize some units for the test
call CreateUnit(Player(0), 'hpea', 100.0, 100.0, 0.0)
call CreateUnit(Player(0), 'Hjai', 110.0, 120.0, 0.0)
call CreateUnit(Player(0), 'Hmbr', 120.0, 110.0, 0.0)
call CreateUnit(Player(1), 'hpea', 1000.0, 1000.0, 0.0)
call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Tracking, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Tracking, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Tracking, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddAction( gg_trg_Order_Tracking, function Trig_Order_Tracking_Actions )
endfunction
JASS:
function GryphonAtGoal takes unit u, integer th returns boolean
local real target_x = LoadReal(udg_Hash,th,1)
local real target_y = LoadReal(udg_Hash,th,2)
local real distance_x = target_x - GetUnitX(u)
local real distance_y = target_y - GetUnitY(u)
local integer terrain_type = LoadInteger(udg_Hash,th,3)
if (distance_x < 50.0 and distance_x > -50.0) and (distance_y < 50.0 and distance_y > -50.0) then
call SetTerrainType(target_x,target_y,terrain_type,-1, 1, 0)
return true
endif
return false
endfunction
function SetNewTarget takes unit u, integer th returns nothing
local location original_loc = GetUnitLoc(u)
local location new_loc
local real new_x
local real new_y
// Check if the new location is inside the playable map bounds
loop
set new_loc = PolarProjectionBJ(original_loc,GetRandomReal(500,1500),GetRandomReal(0,360))
exitwhen RectContainsLoc(bj_mapInitialPlayableArea, new_loc)
endloop
set new_x = GetLocationX(new_loc)
set new_y = GetLocationY(new_loc)
call SaveReal(udg_Hash,th,1,new_x)
call SaveReal(udg_Hash,th,2,new_y)
call SaveInteger(udg_Hash,th,3,GetTerrainType(new_x,new_y))
call IssuePointOrder(u,"smart",new_x,new_y)
call SetTerrainType(new_x,new_y,'Nsnw',-1, 1, 0)
call RemoveLocation(original_loc)
call RemoveLocation(new_loc)
set original_loc = null
set new_loc = null
endfunction
function GryphonTimeout takes nothing returns nothing
local integer timer_handle = GetHandleId(GetExpiredTimer())
local unit gryphon = LoadUnitHandle(udg_Hash,timer_handle,0)
if GryphonAtGoal(gryphon,timer_handle) then
call SetNewTarget(gryphon,timer_handle)
endif
endfunction
function Trig_Wanderer_gryphon_Timer_Actions takes nothing returns nothing
local timer gryphon_timer = CreateTimer()
local unit gryphon = CreateUnit(Player(0),'hgry',0,0,0)
local integer timer_handle = GetHandleId(gryphon_timer)
call SaveUnitHandle(udg_Hash, timer_handle, 0, gryphon)
call SaveReal(udg_Hash, timer_handle,1,0) // save target x
call SaveReal(udg_Hash, timer_handle,2,0) // save target y
call TimerStart(gryphon_timer,0.5,true,function GryphonTimeout)
endfunction
//===========================================================================
function InitTrig_Wanderer_gryphon_timer takes nothing returns nothing
set gg_trg_Wanderer_gryphon_timer = CreateTrigger( )
set udg_Hash = InitHashtable()
call TriggerRegisterPlayerEventEndCinematic( gg_trg_Wanderer_gryphon_timer, Player(0) )
call TriggerAddAction( gg_trg_Wanderer_gryphon_timer, function Trig_Wanderer_gryphon_Timer_Actions )
endfunction
Just a note about this mission: Perhaps it should include a note to make sure that the gryphon's target is inside the playable map area. Not that big a deal, but still worth the few extra words.
I also made implemented mission 2 with waits just for fun.
JASS:
function CheckDistanceWaits takes unit u returns boolean
local real desx = LoadReal(udg_Hash,GetHandleId(u),1)
local real desy = LoadReal(udg_Hash,GetHandleId(u),2)
local integer dest = LoadInteger(udg_Hash,GetHandleId(u),3)
local real dix = desx - GetUnitX(u)
local real diy = desy - GetUnitY(u)
if (dix < 50.0 and dix > -50.0) and (diy < 50.0 and diy > -50.0) then
call SetTerrainType(desx,desy,dest,-1, 1, 0)
return true
endif
return false
endfunction
function UnitWaitDestinationWaits takes unit u returns nothing
//call BJDebugMsg("Starting loop, waiting for unit to arrive at target")
loop
exitwhen CheckDistanceWaits(u)
call TriggerSleepAction(0.25)
endloop
//call BJDebugMsg("unit at target")
endfunction
function SetUnitTargetWaits takes unit u returns nothing
local location ol = GetUnitLoc(u)
local location nl
local real nx
local real ny
// Check if the new location is inside the playable map bounds
loop
set nl = PolarProjectionBJ(ol,GetRandomReal(500,1500),GetRandomReal(0,360))
exitwhen RectContainsLoc(bj_mapInitialPlayableArea, nl)
endloop
set nx = GetLocationX(nl)
set ny = GetLocationY(nl)
call SaveReal(udg_Hash,GetHandleId(u),1,nx)
call SaveReal(udg_Hash,GetHandleId(u),2,ny)
call SaveInteger(udg_Hash,GetHandleId(u),3,GetTerrainType(nx,ny))
call IssuePointOrder(u,"smart",nx,ny)
call SetTerrainType(nx,ny,'Nsnw',-1, 1, 0)
call RemoveLocation(ol)
call RemoveLocation(nl)
set ol = null
set nl = null
endfunction
function Trig_Wanderer_gryphon_Waits_Actions takes nothing returns nothing
local unit gry = CreateUnit(Player(0),'hgry',0,0,0)
loop
exitwhen GetUnitState(gry, UNIT_STATE_LIFE) <= 0
call SetUnitTargetWaits(gry)
call UnitWaitDestinationWaits(gry)
endloop
call BJDebugMsg("Gryphon is dead :<")
set gry = null
endfunction
//===========================================================================
function InitTrig_Wanderer_gryphon_waits takes nothing returns nothing
set gg_trg_Wanderer_gryphon_waits = CreateTrigger( )
set udg_Hash = InitHashtable()
call TriggerRegisterPlayerEventEndCinematic( gg_trg_Wanderer_gryphon_waits, Player(0) )
call TriggerAddAction( gg_trg_Wanderer_gryphon_waits, function Trig_Wanderer_gryphon_Waits_Actions )
endfunction
JASS:
function UnitIsAlive takes nothing returns boolean
return (GetUnitState(GetEnumUnit(),UNIT_STATE_LIFE) <= 0)
endfunction
function BlastOff takes nothing returns nothing
local unit u = GetEnumUnit()
if GetUnitTypeId(u) != 'hbar' then
call ExplodeUnitBJ(u)
endif
endfunction
function ThisIsTheEnd takes nothing returns nothing
local integer index = 0
local group PlayerUnits = CreateGroup()
call BJDebugMsg("YOU WON!!!")
loop
exitwhen index >= 4
call GroupEnumUnitsOfPlayer(PlayerUnits,Player(index),Condition(function UnitIsAlive))
call ForGroup(PlayerUnits, function BlastOff)
set index = index + 1
endloop
endfunction
function CreepIsAlive takes nothing returns nothing
local unit u = GetEnumUnit()
local group g = LoadGroupHandle(udg_Hash,12,1)
if GetUnitState(u,UNIT_STATE_LIFE) <= 0 then
call GroupRemoveUnit(g,u)
endif
endfunction
function GetCreepAmount takes nothing returns integer
local group g = LoadGroupHandle(udg_Hash,12,1)
call ForGroup(g,function CreepIsAlive)
return CountUnitsInGroup(g)
endfunction
function SpawnUnits takes nothing returns nothing
local integer index = 0
local unit barracks
local unit spawn
local real x
local real y
local integer stype
local timer t = GetExpiredTimer()
if GetCreepAmount() < 1 then
call DestroyTimer(t)
set index = 100
call ThisIsTheEnd()
endif
loop
exitwhen index >= 4
set barracks = LoadUnitHandle(udg_Hash,index,1)
set x = GetUnitX(barracks)
set y = GetUnitY(barracks)
set stype = GetRandomInt(1,2)
if stype == 1 then
set spawn = CreateUnit(Player(index),'hfoo',x,y,0)
else
set spawn = CreateUnit(Player(index),'hrif',x,y,0)
endif
call IssuePointOrder(spawn,"attack",0,0)
set index = index + 1
endloop
endfunction
function Trig_Spawn_unit_Actions takes nothing returns nothing
local integer index = 0
local integer level
local location Source = Location(0,0)
local location loc
local timer SpawnTimer = CreateTimer()
local group CreepGroup = CreateGroup()
local unit u
set udg_Hash = InitHashtable()
loop
exitwhen index >= 21
set level = GetRandomInt(1,10)
set u = CreateUnit(Player(12),ChooseRandomCreep(level),0,0,0)
call GroupAddUnit(CreepGroup,u)
set index = index + 1
endloop
call SaveGroupHandle(udg_Hash,12,1,CreepGroup)
set index = 0
loop
exitwhen index >= 4
set loc = PolarProjectionBJ(Source,3000.0,(90.0*index))
set u = CreateUnit(Player(index),'hbar',GetLocationX(loc),GetLocationY(loc),270.0)
call SaveUnitHandle(udg_Hash,index,1,u)
call RemoveLocation(loc)
set index = index + 1
endloop
call RemoveLocation(Source)
call TimerStart(SpawnTimer,2.5,true,function SpawnUnits)
endfunction
//===========================================================================
function InitTrig_Spawn_unit takes nothing returns nothing
set gg_trg_Spawn_unit = CreateTrigger( )
set udg_Hash = InitHashtable()
call TriggerAddAction( gg_trg_Spawn_unit, function Trig_Spawn_unit_Actions )
endfunction
P.S.: Do I need to post a test map of all that? Cause all the missions so far are on the same map...