kingkingyyk3
Visitor (Welcome to the Jungle, Baby!)
- Reaction score
- 216
JASS:
library AutoMover requires optional Table, optional ABC
/*
___ __ _ ______ _____ _____ _ ___ _ ____ ___
/ | | | |__ __|/ _ \ _ _ \/ _ \ / / ___// /
/ == | | | | || | | | || || || |\| | / / /__ / * /
/ == | |_| | || | |_| || || || |_| |/ / /__ / /\ \
/__/ |_|\___/ || \_____/| || ||\____/_/____//_/ \_\
by kingking ~ v1.0.0 ~
What is AutoMover?
~ AutoMover is an automated creeps ordering system.
~ AutoMove is useful for TD(aka tower defense), AoS style maps.
Functions :
~ AutoMover_Region.create(rect r) -> AutoMover_Region
-> Return an instance.
~ set .enable = true/false
-> Enable/Disable. (Units will be stayed in the region if it is disabled.)
~ .isEnabled() -> boolean
-> Is enabled?
~ .addToPrev(AutoMove_Region)
-> Add region to the previous of current instance.
~ .addToNext(AutoMove_Region)
-> Add region to the next of current instance.
~ .removeNext()
-> Remove all regions after next.
~ .removePrev()
-> Remove all regions at previous.
~ .unlink()
-> Remove all regions at previous and next.
~ .destroy()
-> Destroy the instance.
~ AutoMover_Region.getTriggering() -> AutoMover_Region
-> Returns triggering instance.
function interface ToPrev takes unit whichUnit returns boolean
-> Condition for units to move to previous region.
function interface ToNext takes unit whichUnit returns boolean
-> Condition for units to move to next region.
function interface OnAutoMove takes unit whichUnit returns nothing
-> Callback when a units is ordered.
~ set .toPrevFilter = func
~ set .toNextFilter = func
~ set .endCallback = func
Concept :
this -> this.next -> this.next.next
this.prev.prev <- this.prev <- this
Details :
~ AutoMover is basically a linked list.
~ AutoMover will order units automatically once you have
setup correctly.
Requires :
~ Table/ABC
~ Jasshelper 0.A.2.B or later
How to import :
~ Copy this trigger to your map.
~ Copy ABC/Table to your map if you don't have.
~ Define the regions.
*/
globals
private constant string OnMoveOrder = "move"
/* "move" or "attack" or "smart" */
endglobals
static if LIBRARY_Table then
globals
private HandleTable AutoMoverTable
endglobals
endif
function interface ToPrev takes unit whichUnit returns boolean
function interface ToNext takes unit whichUnit returns boolean
function interface OnAutoMove takes unit whichUnit returns nothing
public struct Region
private static conditionfunc cf
private static thistype array Stack
private static integer StackLevel = 0
private thistype prev
private thistype next
readonly real x
readonly real y
private region reg
private trigger trig
ToPrev toPrevFilter
ToNext toNextFilter
OnAutoMove endCallback
static method getTriggering takes nothing returns thistype
return .Stack[.StackLevel]
endmethod
private static method Cond takes nothing returns boolean
local unit u = GetTriggerUnit()
static if LIBRARY_Table then
local thistype this = AutoMoverTable[GetTriggeringTrigger()]
elseif LIBRARY_ABC then
local thistype this = GetTriggerStructA(GetTriggeringTrigger())
endif
set thistype.StackLevel = thistype.StackLevel + 1
set thistype.Stack[thistype.StackLevel] = this
if .toPrevFilter != 0 and .toPrevFilter.evaluate(u) then
call IssuePointOrder(u,OnMoveOrder,.prev.x,.prev.y)
if .endCallback != 0 then
call .endCallback.execute(u)
endif
endif
if .toNextFilter != 0 and .toNextFilter.evaluate(u) then
call IssuePointOrder(u,OnMoveOrder,.next.x,.next.y)
if .endCallback != 0 then
call .endCallback.execute(u)
endif
endif
set thistype.StackLevel = thistype.StackLevel - 1
set u = null
return false
endmethod
static method create takes rect r returns thistype
local thistype this
if r == null then
return 0
endif
set this = .allocate()
set .prev = this
set .next = this
set .x = GetRectCenterX(r)
set .y = GetRectCenterY(r)
set .trig = CreateTrigger()
set .reg = CreateRegion()
call RegionAddRect(.reg,r)
call TriggerRegisterEnterRegion(.trig,.reg,null)
call TriggerAddCondition(.trig,thistype.cf)
static if LIBRARY_Table then
set AutoMoverTable[.trig] = this
elseif LIBRARY_ABC then
call SetTriggerStructA(.trig,this)
endif
return this
endmethod
method operator enable= takes boolean flag returns nothing
if flag then
call EnableTrigger(.trig)
else
call DisableTrigger(.trig)
endif
endmethod
method operator isEnabled takes nothing returns boolean
return IsTriggerEnabled(.trig)
endmethod
method addToPrev takes thistype this2 returns nothing
set this.prev = this2
set this2.next = this
endmethod
method addToNext takes thistype this2 returns nothing
set this.next = this2
set this2.prev = this
endmethod
method removeNext takes nothing returns nothing
set this.next.prev = this.next
set this.next = this
endmethod
method removePrev takes nothing returns nothing
set this.prev.next = this.prev
set this.prev = this
endmethod
method unlink takes nothing returns nothing
if .prev == this then
set .next.prev = .next
else
set .next.prev = .prev
endif
if .next == this then
set .prev.next = .prev
else
set .prev.next = .next
endif
endmethod
method onDestroy takes nothing returns nothing
call .unlink()
static if LIBRARY_Table then
call AutoMoverTable.flush(.trig)
elseif LIBRARY_ABC then
call ClearTriggerStructA(.trig)
endif
call TriggerClearConditions(.trig)
call DisableTrigger(.trig)
call DestroyTrigger(.trig)
call RemoveRegion(.reg)
set .trig = null
set .reg = null
set .toPrevFilter = 0
set .toNextFilter = 0
set .endCallback = 0
endmethod
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set AutoMoverTable = HandleTable.create()
elseif not LIBRARY_ABC then
call BJDebugMsg("AutoMover Error : Table/ABC is not found in this map!")
endif
set thistype.cf = Condition(function thistype.Cond)
endmethod
endstruct
endlibrary
Table | ABC