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: 297

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
380
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.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      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