System Creep Camp Manipulator

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
///////////////////////////////////////////////////////////////
//  
//  < Creep Camp Manipulator >  ~ v1.0.1 ~
//
//      by kingking
//
//  ==============
//  What is this ?
//  ==============
//  Creep Camp Manipulator is a simple system for providing
//  efficient creep camp spawning. 
/// It will form a collection of creep types and provides 
//  easy interface to let you to spawn whole camp of creeps.
//
//  -----------
//  Usage :
//  -----------
//  ========================
//  Struct 1 : CreepType
//  ========================
//  CreepType.create()
//  -> Return an instance.
//
//  set .type = <unitType>
//  -> Rawcode of creep.
//
//  set .owner = <unit's owner>
//  -> Owner of creep.
//
//  ========================
//  Struct 2 : CreepTroop
//  ========================
//  CreepTroop.create()
//  -> Return an instance.
//
//  call .addCreepType(CreepType, number)
//  -> Add a certain number of creep type.
//
//  call .removeCreepType(CreepType, number)
//  -> Remove a certain number of creep type.
//
//  ========================
//  Struct 3 : CreepCamp
//  ========================
//  CreepCamp.create()
//  -> Return an instance.
//
//  set .x = x
//  -> X-coordinate for camp.
//
//  set .y = y 
//  -> Y-coordinate for camp.
//
//  set .OnClear = function
//  -> Function that will be fired when the creeps in camp are all died.
//
//  set .OnSpawn = function
//  -> Function that will be fired when creeps are spawned.
//
//  call .enumCreeps(code)
//  -> Enum all creeps in camp.
//
//  call .spawn(CreepTroop)
//  -> Spawn the collection of creeps at the point.
//
//  .active ->
//  -> Is the camp active?
//
//  .amount ->
//  -> Amount of creeps in camp.
//
//  ====================================
//  Example for .OnClear callback :
//  ====================================
//  function OnClear takes CreepCamp whichCreepCamp returns nothing
//
//  ====================================
//  Example for .OnSpawn callback :
//  ====================================
//  function OnSpawnCreep takes unit whichUnit returns nothing
//
//  ******************************************************************
//  * IMPORTANT : NEVER DESTROY ANY CREEP CAMP MANIPULATOR's STRUCT. *
//  *             NEVER USE RemoveUnit() on CREEP.                   *
//  ******************************************************************
//
//  =================
//  Implementation :
//  =================
//  1) Copy this library to your map.
//  2) Copy Table to your map if your map does not have it.
//  3) Setup it correctly.
//  4) Enjoy it!
//
//  ==============
//  Requirement :
//  ==============
//  Table
//  Latest version of Jasshelper.
///////////////////////////////////////////////////////////////////////////
library CCM requires Table
    
    struct CreepType
        integer type
        player owner
        real facing
    endstruct
    
    struct CreepTroop
        public thistype prev
        public thistype next
        public CreepType cd
        
        static method create takes nothing returns thistype
            local thistype this = .allocate()
            set this.prev = this
            set this.next = this
            return this
        endmethod
        
        private method addCreep takes CreepType d returns nothing
            local thistype new
            debug if d == 0 then
                debug call BJDebugMsg("Creep Camp Manipulator Error! <null> CreepData is added into list!")
                debug return
            debug endif
            set new = thistype.allocate()
            set new.next = this
            set new.prev = this.prev
            set this.prev.next = new
            set this.prev = new
            set new.cd = d
        endmethod
        
        private method removeCreep takes CreepType d returns nothing
            local thistype iterator = this.next
            loop
            exitwhen iterator == this
                if iterator.cd == d then
                    set this.prev.next = iterator.next
                    set this.next.prev = iterator.prev
                    call iterator.deallocate()
                    set iterator.prev = 0
                    set iterator.next = 0
                    set iterator.cd = 0
                    set iterator = this
                else
                    set iterator = iterator.next
                endif
            endloop
        endmethod
        
        method addCreepType takes CreepType d, integer number returns nothing
            loop
            exitwhen number == 0
                call .addCreep(d)
                set number = number - 1
            endloop
        endmethod
        
        method removeCreepType takes CreepType d, integer number returns nothing
            loop
            exitwhen number == 0
                call .removeCreep(d)
                set number = number - 1
            endloop
        endmethod
    endstruct
    
    private keyword CreepStruct
    private keyword Data
    
    function interface OnClearCamp takes integer whichData returns nothing
    function interface OnSpawnUnit takes unit whichUnit returns nothing
    
    struct CreepCamp
        real x
        real y
        readonly boolean active
        OnClearCamp OnClear
        OnSpawnUnit OnSpawn
        public group g
        public integer amount
        
        static method create takes nothing returns thistype
            local thistype this = .allocate()
            set .active = false
            set .amount = 0
            set .g = CreateGroup()
            return this
        endmethod
        
        method spawn takes CreepTroop troop returns nothing
            local unit u
            local CreepTroop iterator = troop
            loop
                set iterator = iterator.next
            exitwhen iterator == troop
                set u = CreateUnit(iterator.cd.owner,iterator.cd.type,.x,.y,iterator.cd.facing)
                call CreepStruct.add(u,this)
                call .OnSpawn.execute(u)
            endloop
            set u = null
        endmethod
        
        method enumCreeps takes code c returns nothing
            call ForGroup(.g,c)
        endmethod
        
        method decrement takes nothing returns nothing
            set .amount = .amount - 1
            if .amount == 0 then
                call .OnClear.execute(this)
                set .active = false
            endif
        endmethod
    endstruct
        
    private struct CreepStruct 
        private static HandleTable data
        unit u
        CreepCamp cc
        
        static method add takes unit whichUnit, CreepCamp cc returns nothing
            local thistype this = .allocate()
            set .u = whichUnit
            set .cc = cc
            call GroupAddUnit(.cc.g,u)
            set .cc.amount = .cc.amount + 1
            set thistype.data[whichUnit] = this
        endmethod
        
        method onDestroy takes nothing returns nothing
            call thistype.data.flush(.u)
            call GroupRemoveUnit(.cc.g,.u)
            call .cc.decrement()
            set .cc = 0
            set .u = null
        endmethod
        
        private static method Cond takes nothing returns boolean
            local CreepStruct this = thistype.data[GetTriggerUnit()]
            if this != 0 then
                call .destroy()
            endif
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            local trigger trig = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_DEATH)
            call TriggerAddCondition(trig,Condition(function thistype.Cond))
            set thistype.data = HandleTable.create()
        endmethod
    endstruct
    
    
endlibrary


Supports :
-> Form a camp which consists of random creeps on random points.(Clever users will know how to achieve it :) )
-> Dynamic amount of creep types.
-> Automatical camp clearing callback by using O(n) method.

Limitation(I don't think you can go beyond it. If you exceed it, you are doing something mad :p ) :
Max 8191 creep types.
Max 8191 creep types in creep troops.
Max 8191 camps.
Max 8191 creeps on map.

Cons :
-> Requires you to create reviving function by yourself, but I don't think this is a con, because you may add some conditions to control the reviving of creeps. ;)

Requires : Table

Example :
JASS:
library SetupCreeps initializer Init requires CCM, TimerUtils
    
    globals
        CreepTroop ScorpionGroup
    endglobals
    
    private function OnExpire takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local CreepCamp c = GetTimerData(t)
        call c.spawn(ScorpionGroup)
        call ReleaseTimer(t)
        set t = null
    endfunction
    
    private function ReviveCreeps takes CreepCamp camp returns nothing
        local timer t = NewTimer()
        call SetTimerData(t,camp)
        call TimerStart(t,5.,false,function OnExpire)
        set t = null
    endfunction
    
    private function CreateEffects takes unit whichUnit returns nothing
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Avatar\\AvatarCaster.mdl",whichUnit,"origin"))
    endfunction
    
    private function Init takes nothing returns nothing
        local CreepType ScorpionCreeps
        local CreepCamp ScorpionCamp
        
        set ScorpionGroup = CreepTroop.create() //A group of creep types.
        
        set ScorpionCreeps = CreepType.create() //Create a type of creep
        set ScorpionCreeps.type = 'nano'//rawcode of creep
        set ScorpionCreeps.owner = Player(14)//owner of creep
        set ScorpionCreeps.facing = 270. //facing of creep
        
        call ScorpionGroup.addCreepType(ScorpionCreeps,3)//Add 3 same creep type to the group
        
        set ScorpionCamp = CreepCamp.create()//Create a creep camp on the point.
        set ScorpionCamp.x = -1800. //setup position of the camp.
        set ScorpionCamp.y = 4000.
        
        set ScorpionCamp.OnClear = ReviveCreeps//add revive timer for the camp
        set ScorpionCamp.OnSpawn = CreateEffects//add special effect creating callback when the camp of creeps are created.
        
        call ScorpionCamp.spawn(ScorpionGroup)//spawn creeps
    endfunction
    
endlibrary

- You will have 3 scorpion creeps(owned by Neutral Hostile) at -1800,4000.
- When scorpions are spawned, they will have avatar effect
- When the scorpions in map are all died, the new scorpions will be spawned after 5 seconds. :D
 

Attachments

  • Creep Camp Manipulator.w3x
    42.6 KB · Views: 254

Jesus4Lyf

Good Idea™
Reaction score
397
This seems to be a CreateUnit wrapper (it just batch spawns units and counts them?). The fact that this does not handle timed respawning and lacks initialising critical struct members in its constructor tells me this was probably neither well thought through, or written to actually be practical for use.

Furthermore, it is systems like this which fill up the Tutorials and Resources forums - the ones which seem to contain just almost enough content or functionality to warrant being called a snippet or system, but not quite enough functionality to convince people that they're more than just something to submit for the hell of it.

Please, write things which are useful. Write things with clean interfaces (if a creep camp must have an x/y loc, make sure it is set in the constructor). Write things which take less time to learn than to code things yourself. :)

PS.
JASS:
//  *             NEVER USE RemoveUnit() on CREEP.                   *

I would call that a bug. :)

If you wrote this in a way that recycled the creeps for respawning, it would warrant a useful system. Until this does something neat like that, I think it shall remain in the graveyard.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • 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 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