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

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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • 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

      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