EdgeOfChaos
E
EdgeOfChaos
Patrollers are the easiest obstacles to make in a maze game - or are they?
It's very easy to custom code every single region and every patroller but that is super boring and time consuming. It's also easy to have them use the Patrol command, but that command is bugged (imprecise and stops after some time). It would be much better to have a system that handles all that region manipulation for you.
The issue is that there is no simple way to detect which region was entered by the entering event. You end up having to check every single region to see if the unit is nearby it to determine which region was entered.
Here's a quick hack I threw together to make easy, efficient patrollers, with up to 10 rally points, who don't use the Patrol command. The time calculation would be dangerous for maps where enemy movement speeds change, but it would work for 99% of mazes (and mine, which is what counts). Uses TimerUtils and made with efficiency/ease of use in mind.
Example consumer code to make 5 firelord enemies
It's very easy to custom code every single region and every patroller but that is super boring and time consuming. It's also easy to have them use the Patrol command, but that command is bugged (imprecise and stops after some time). It would be much better to have a system that handles all that region manipulation for you.
The issue is that there is no simple way to detect which region was entered by the entering event. You end up having to check every single region to see if the unit is nearby it to determine which region was entered.
Here's a quick hack I threw together to make easy, efficient patrollers, with up to 10 rally points, who don't use the Patrol command. The time calculation would be dangerous for maps where enemy movement speeds change, but it would work for 99% of mazes (and mine, which is what counts). Uses TimerUtils and made with efficiency/ease of use in mind.
JASS:
struct Patroller
private rect array nodes[10]
private integer index = 0
private integer currentNode = 0
private unit patroller
private integer patrollerType
public static method create takes rect startNode, integer patrollerType returns thistype
local thistype new = thistype.allocate()
set new.patrollerType = patrollerType
call new.addNode(startNode)
return new
endmethod
public method addNode takes rect node returns nothing
if(index < 10)then
set nodes[index] = node
set index = index + 1
endif
endmethod
private static method onReachNode takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype data = GetTimerData(t)
call ReleaseTimer(t)
call data.processNextNodeMovement()
endmethod
private method processNextNodeMovement takes nothing returns nothing
local real distance
local real time
local real x0 = GetRectCenterX(nodes[currentNode])
local real y0 = GetRectCenterY(nodes[currentNode])
local real x1
local real y1
// find next node
set currentNode = currentNode + 1
if(currentNode >= index)then
set currentNode = 0
endif
// calculate distance between this and next node
set x1 = GetRectCenterX(nodes[currentNode])
set y1 = GetRectCenterY(nodes[currentNode])
set distance = DistanceBetweenCoords(x0,y0,x1,y1)
// calculate time to reach point
set time = distance / GetUnitMoveSpeed(patroller)
// issue the move order and start timer to
// determine when it is reached
call IssuePointOrder(patroller,"move",x1,y1)
call TimerStart(NewTimerEx(this),time,false,function thistype.onReachNode)
endmethod
public method start takes nothing returns nothing
// begin at starting node
set patroller = CreateUnit(ENEMY_PLAYER,patrollerType,GetRectCenterX(nodes[0]),GetRectCenterY(nodes[0]),0)
call processNextNodeMovement()
endmethod
endstruct
Example consumer code to make 5 firelord enemies
JASS:
scope FirelordPatrol initializer onInit
private function makeTwoNodeFirelord takes rect r1, rect r2 returns nothing
local Patroller p = Patroller.create(r1,FIRELORD)
call p.addNode(r2)
call p.start()
endfunction
private function onInit takes nothing returns nothing
call makeTwoNodeFirelord(gg_rct_FNode1,gg_rct_FNode2)
call makeTwoNodeFirelord(gg_rct_FNode3,gg_rct_FNode4)
call makeTwoNodeFirelord(gg_rct_FNode5,gg_rct_FNode6)
call makeTwoNodeFirelord(gg_rct_FNode7,gg_rct_FNode8)
call makeTwoNodeFirelord(gg_rct_FNode9,gg_rct_FNode10)
endfunction
endscope
Last edited by a moderator: