System AutoMover

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
 

Attachments

  • AutoMover.w3x
    29.3 KB · Views: 302

Anachron

New Member
Reaction score
53
First of, please make your interfaces private.
Secondly, how is this better than this?
third, since you are not able to create a whole way and add units to it so they automatically move that way, this isn't good in any way. (lol)
Also, some creeps in TDs might cast spells and such, so a reordering system (such as in the provided link) is necessary.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
First of, please make your interfaces private.
:confused:

Secondly, how is this better than this?
This 1 is more efficient and much LIGHTER.

third, since you are not able to create a whole way and add units to it so they automatically move that way, this isn't good in any way. (lol)
Have you looked it carefully? :nuts: I used linked list to achieve it.

Also, some creeps in TDs might cast spells and such, so a reordering system (such as in the provided link) is necessary.
It is easy by porting LastOrder into it. :cool:

Btw, I need more suggestions to improve it. :thup:
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
why do people feel the documentation is not as important as the code itself...
 

Hatebreeder

So many apples
Reaction score
381
This is nice =)

Any way to achieve the Order once a unit "forgets" it?
Ex. You use a stun ability on a creep and move out of sight. That creep usually doesn't start doing it's previously ordered Order. It just stands there.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Ex. You use a stun ability on a creep and move out of sight. That creep usually doesn't start doing it's previously ordered Order. It just stands there.
I will port LastOrder into it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top