[WIP]New Spawn? cJASS

Status
Not open for further replies.

Nestharus

o-o
Reaction score
84
New Spawn 1.0 Alpha! (will stay 1.0 until 1.0 is done aka out of alpha)

Thinking the interface is a lot better and for performance it rocks ^_-. It's not as good as a home brewed system, but it's still very good.

JASS:

library Spawn initializer Initialization {
/*Framework Information
===================================================================
Name: C Spawn
Version: 1.0
Author: Nestharus

Description:
    Spawn is a framework that specializes in producing repeated data using 3 basic parts:
    Algorithm, BaseType, SpawnType
    
    Data can be anything from units to attacks to spells.
    
    The Algorithm refers to how to place the data (2D shapes, 3D shapes, or w/e you like)
    BaseType refers to what has the spawn (coordinates, location, unit, item?)
    SpawnType refers to what the spawn makes (unit, attack, projectile, spell, weapon, item, terrain, damage?)
    
    Everything is set up to be extremely fast and efficient and will be as fast as a home brewed system
    if the SpawnType is a one liner (inlined) <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />.
    
    To give some ideas of what Spawn may be used for-
    Algorithm- relative placement (place at the base)
    BaseType- Unit
    SpawnType- Unit
    
    Now, with those 3 pieces, you could do a Footmen Wars Map.
    Base could be barracks
    
    Algorithm- Line
    BaseType- Unit
    SpawnType- Spell
    
    Let&#039;s say you wanted to do a line of fire pillars. Each spell would actually be
    a set of code to run the spell (each unique instance or w/e).
    
    So in essence, it&#039;s a framework for easy and managable spawn handling.
    
Templates
------------------------------------------------------------------
Algorithm Template-
    Algorithms are used to place the spawns. For example, you might want your spawns to spawn in a line, a circle,
    a sphere, or just plain relative spawning (spawn at origin), or direct spawning (spawn at specified coordinate)
    
    module AlgorithmName {
        private real x
        private real y
        private real z
        private real facing
        private int count
        private real offset
        
        public void setupAlgorithm(real x, real y, real z, real facing, int count, real offset) {
            //This is called whenever a spawn starts to spawn (right before very first spawn is placed)
            
            //x, y, z refer to origin, facing refers to facing of base, count refers to how many spawns, offset
            //refers to how far the spawn is supposed to be from origin
        }//calc
        
        public real getX(int index) {
            //Needs to return a valid x coordinate given a spawn index. If spawning a line of units and
            //it sends in 2 as an index (0..+), need to give it coordinate for third unit in that line
        }//getX
        
        public real getY(int index) {
            //Needs to return a valid y coordinate given a spawn index. If spawning a line of units and
            //it sends in 2 as an index (0..+), need to give it coordinate for third unit in that line
        }//getY
        
        public real getZ(int index) {
            //Needs to return a valid z coordinate given a spawn index. If spawning a line of units and
            //it sends in 2 as an index (0..+), need to give it coordinate for third unit in that line
        }//getZ
        
        public real getFacing(int index) {
            //returns a valid facing for the given spawn (0..+)
        }//getFacing
    }//Algorithm

Base Type Template-
    A Base can be thought of as a Spawn&#039;s origin. The origin has various properties like x, y, z, facing, and an owner.
    
    The origin can be anything like a unit, coordinates, an item, or w/e. The point is that the properties have to be set
    up so that the coordinates can be retrieved no matter the origin.
    
    module BaseType {
        private type spawnBase //origin
        private player spawnOwner //owner of origin
        
        //static values if the origin is static
        private real setX
        private real setY
        private real setZ
        private real setFacing
        private location curLocation
        private static real returnVal
        
        public void operator base=(type newVal) {//sets the origin
            .spawnBase = newVal //set the origin to the new value
            if newVal != null {//if setting origin, set the owner
                //Only mess with code in here
                    //.spawnOwner = GetOwningPlayer(.spawnBase)?
                //Only mess with code in here
            }//if
            else {//otherwise unset the owner
                .spawnOwner = null
            }//else
        }//base=
        
        public type operator base() {//return the origin
            return .base
        }//base
        
        public void operator x=(real newVal) {//set x coordinate of origin
            //SetUnitX(.spawnBase, newVal)?
        }//x=
        
        public void operator y=(real newVal) {//set y coordinate of origin
            //SetUnitY(.spawnBase, newVal)?
        }//y=
        
        public void operator z=(real newVal) {//set z coordinate of origin
            //SetUnitFlyHeight(.spawnBase, newVal, newVal+10000)?
        }//z=
        
        public void operator facing=(real newVal) {//set facing of origin
            //SetUnitFacing(.spawnBase, newVal)?
        }//facing=
        
        public real operator x() {//return x coordinate of origin
            //GetUnitX(.spawnBase)?
        }//x
        
        public real operator y() {//return y coordinate of origin
            //GetUnitY(.spawnBase)?
        }//y
        
        public real operator z() {//return z coordinate of origin
            //for moving points
            //.curLocation = Location(.x, .y)
            //thistype.returnVal = GetLocationZ(.curLocation)
            //RemoveLocation(.curLocation)
            //return thistype.returnVal
            
            //non moving points
            //return GetLocationZ(.curLocation)
        }//z
        
        public real operator facing() {//return facing of origin
        }//facing
        
        public player operator owner() {//return owner of origin
            //shouldn&#039;t have to change this
            return .spawnOwner
        }//owner
    }//BaseType

Spawn Type Template-
    Spawn type contains the method for creating the actual spawns. A very simple one might just be CreateUnit(), but
    there can also be complicated ones like full fledged spells or attacks, for example modify unit hp, create effects,
    etc, and etc.
    
    This can&#039;t be used too well for homing spells, but it can be used for virtually everything
    
    module SpawnType {
        public void createSpawn(player owner, int spawnType, real x, real y, real z, real facing, int current) {
            //owner refers to owner of the spawn
            
            //spawnType refers to type, like &#039;hpea&#039;
            
            //x refers to x coordinate
            
            //y for y coordinate
            
            //z for z coordinate
            
            //facing for the facing
            
            //current for which spawn is currently being spawned, for example if 8 spawns were supposed to spawn,
            //this method would run 8 times where current is equal to 0-7. In this way, you could do effects
            //based on the current spawn, maybe even change the types around. Don&#039;t forget you can inherit off of
            //your Spawn objects through delegates and from there add in different types, but if you are to do this
            //then the spawnType passed in will be useless as the system isn&#039;t designed for that ^_-.
        }//createSpawn
    }//SpawnType
    
Condition Type Template-
    Condition types are just methods that return booleans. All objects except for EnumItem objects can use up to one
    condition type. EnumItem objects can use up to 3.
    
    Regular Condition-
        module EnumCondition {
            public bool isValidEnum(type enumType) {//replace type with the type desired
            }//isValidEnum
        }//EnumCondition
    
    Regular Enum Condition-
        module EnumCondition {
            public static bool isValidEnum(type enumType) {//replace type with the type desired
            }//isValidEnum
        }//EnumCondition
    
    Conditions for EnumItems-
        module ConditionTypeCarrier {
            public static bool checkEnumCarrier(unit carrier) {
            }//checkEnumUnit
        }//ConditionTypeCarrier
        
        module ConditionTypeCarried {
            public static bool checkEnumCarriedItem(unit carrier, item carriedItem) {
            }//checkEnumCarriedItem
        }//ConditionTypeCarried
        
    
API
------------------------------------------------------------------
CreateSpawn(SpawnName, SpawnType, BaseType, Algorithm, ConditionType)
    Creates a Spawn Object (struct)
    
CreateBase(BaseName, SpawnType, BaseType, Algorithm, ConditionType)
    Creates a Base Object (struct)
    
CreateEnumUnitSpawn(EnumName, SpawnType, Algorithm, EnumRegion, EnumPlayer, ConditionTypeEnum)
CreateDestructableSpawn(EnumName, SpawnType, Algorithm, EnumRegion, ConditionTypeEnum)
CreateEnumItemSpawn(EnumName, SpawnType, Algorithm, EnumRegion, EnumPlayer, ConditionTypeEnum, ConditionTypeEnumCarrier, ConditionTypeEnumCarried)
    Enumerates through units/destructables/items on the map and creates spawns for them of a type. This is
    simplest and easiest to use, but it&#039;s not as efficient as CreateBase.
    
    SpawnName refers to the name of the struct
    BaseName refers to the name of the struct
    EnumName refers to the name of the struct
    
    SpawnType refers to SpawnType module name
    BaseType refers to BaseType module name
    Algorithm refers to Algorithm module name
    
    EnumRegion refers to a region that the enumerated base has to be in. If null, not checked
    EnumPlayer refers to a player the enumerated base has to be owned by. If null, not checked
    
    ConditionTypeEnum and ConditionType-
        refer to a custom condition method that takes one argument of a specific type
    
    ConditionTypeEnumCarrier-
        refers to a specific type of condition method that takes a unit that may be carrying an item
    ConditionTypeEnumCarried-
        refers to a specific type of condition method that takes a unit carrying an item and
        the item being carried
    
Spawn-
    public real spawnTime
        How often the spawn
        
    public int spawnType
        What type of spawn (&#039;hpea&#039;?)
        
    public int spawnCount
        How many to spawn
        
    public real spawnOffset
        How far the spawn is from the base (origin)
    
    public static Spawn create()
        Create a new spawn. Each created spawn is permanently associated with a timer to
        keep the speed up.
        
        Example-
            MySpawn mySpawn = MySpawn.create()
            
    public void destroy()
        Destroys spawn.
        
    public void startTimer()
        Start the spawn timer. Make sure you have a spawn time or it could get ugly!!
        
    public void pauseTimer()
        Pause the spawn timer.
        
    public void resumeTimer()
        Resume the spawn timer. Spawn timer will only run once if it&#039;s resumed like this.
        
    public real getRemainingTime()
        Returns remaining time on timer
        
    public real getElapsedTime()
        Returns elapsed time on timer
        
    public void registerTrigger(trigger t)
        Sets up trigger to be the spawn&#039;s trigger. Don&#039;t need to add conditions or actions, just
        register events on it. Can only have one trigger setup at a time.
        
    public void unregisterTrigger()
        Makes trigger not the spawn&#039;s trigger. Don&#039;t need to add conditions or actions, just
        register events on it.
        
Base-
    public bool enabled
        Is the spawn enabled for the base
        
    public static real spawnTime
        How often the spawn
        
    public static int spawnType
        What type of spawn (&#039;hpea&#039;?)
        
    public static int spawnCount
        How many to spawn
        
    public static real spawnOffset
        How far the spawn is from the base (origin)
    
    public static Base create()
        Create a new base.
        
        Example-
            Base base = Base.create()
            
    public void destroy()
        Destroys base.
        
    public static void startTimer()
        Start the spawn timer. Make sure you have a spawn time or it could get ugly!!
        
    public static void pauseTimer()
        Pause the spawn timer.
        
    public static void resumeTimer()
        Resume the spawn timer. Spawn timer will only run once if it&#039;s resumed like this.
        
    public static real getRemainingTime()
        Returns remaining time on timer
        
    public static real getElapsedTime()
        Returns elapsed time on timer
        
    public static void registerTrigger(trigger t)
        Sets up trigger to be the spawn&#039;s trigger. Don&#039;t need to add conditions or actions, just
        register events on it. Can only have one trigger setup at a time.
        
    public static void unregisterTrigger()
        Makes trigger not the spawn&#039;s trigger. Don&#039;t need to add conditions or actions, just
        register events on it.
        
EnumUnitSpawn-
    public static int baseType = 0
        The unit type id for the units to be enumerated. Spawns will only be produced
        at these units.
        
    public static int spawnType = 0
        The type of spawn (&#039;hpea&#039;?)
        
    public static int spawnCount = 1
        How many spawns to place at each unit
        
    public static real spawnOffset = 0
        The offset of the spawn from the origin
        
    public static real spawnTime = 0
        How often will it spawn if a timer is involved

    public static void registerTrigger(trigger t )
        Register trigger to the spawn. Only register events on the trigger. Only one
        trigger can be registered at a time.
        
    public static void unregisterTrigger()
        Unregister trigger from the spawn.
        
    public static void startTimer()
        Start the spawn timer.
        
    public static void pauseTimer()
        Pause the spawn timer.
        
    public static void resumeTimer()
        Resume spawn timer. Spawn timer will only run once if resumed.
        
    public static real getRemainingTime()
        Get remaining time on spawn timer
        
    public static real getElapsedTime()
        Get elapsed time on spawn timer
        
EnumDestructableSpawn
    Standard Enum
    
    public static player owner = Player(15)
        Refers to the owner of the destructable
        
    public static real facing = 0
        Refers to the facing of the destructable
        
EnumItemSpawn
    Standard Enum
    
    public static player defaultOwner = Player(15)
        Refers to the default owner of an item if it&#039;s just on the floor
===================================================================*/
    public hashtable spawnHashing = InitHashtable()
    public group spawnGroup
    public rect world
    
    define CreateSpawn(SpawnName, SpawnType, BaseType, Algorithm, ConditionType) = {
        struct SpawnName extends array {
            private static int spawnStructCount = 0
            private static int spawnStructRecycleCount = 0
            private static int spawnStructRecycle[]
            
            private timer spawnTimer
            public real spawnTime
            public int spawnType
            public int spawnCount
            public real spawnOffset
            private static boolexpr spawnFunction
            private triggercondition spawnCondition
            private trigger spawnTrigger

            private static int curCount
            
            implement BaseType
            implement Algorithm
            implement SpawnType
            #if ConditionType != null
                implement ConditionType
            #endif
            
            public static SpawnName create() {
                if SpawnName.spawnStructRecycleCount &gt; 0 {
                    return SpawnName.spawnStructRecycle[--SpawnName.spawnStructRecycleCount]
                }//if
                SpawnName(SpawnName.spawnStructCount).spawnTimer = CreateTimer()
                SaveInteger(Spawn_spawnHashing, GetHandleId(SpawnName(SpawnName.spawnStructCount).spawnTimer), 0, SpawnName.spawnStructCount)
                SpawnName.spawnStructCount++
                return SpawnName.spawnStructCount-1
            }//create
            
            public void destroy() {
                SpawnName.spawnStructRecycle[SpawnName.spawnStructRecycleCount++] = this
                if .spawnTrigger != null {
                    TriggerRemoveCondition(.spawnTrigger, .spawnCondition)
                    .spawnTrigger = null
                }//if
            }//destroy
            
            private static bool onSpawn() {
                SpawnName this = LoadInteger(Spawn_spawnHashing, GetHandleId(GetExpiredTimer()), 0)
                #if ConditionType != null
                    if .isValidEnum(.base)
                #endif
                    .setupAlgorithm(.x, .y, .z, .facing, .spawnCount, .spawnOffset)
                    SpawnName.curCount = .spawnCount
                    whilenot SpawnName.curCount == 0 {
                        SpawnName.curCount--
                        .createSpawn(.owner, .spawnType, .getX(SpawnName.curCount), .getY(SpawnName.curCount), .getZ(SpawnName.curCount), .getFacing(SpawnName.curCount), SpawnName.curCount)
                    }//whilenot
                #if ConditionType != null
                    endif
                #endif
                return false
            }//onSpawn
            
            public void startTimer() {
                TimerStart(.spawnTimer, .spawnTime, true, function SpawnName.onSpawn)
            }//startTimer
            
            public void pauseTimer() {
                PauseTimer(.spawnTimer)
            }//pauseTimer
            
            public void resumeTimer() {
                ResumeTimer(.spawnTimer)
            }//stopTimer
            
            public real getRemainingTime() {
                return TimerGetRemaining(.spawnTimer)
            }//getRemainingTime
            
            public real getElapsedTime() {
                return TimerGetElapsed(.spawnTimer)
            }//getRemainingTime
            
            public void registerTrigger(trigger t) {//just adds condition to trigger
                .spawnCondition = TriggerAddCondition(t, SpawnName.spawnFunction)
                .spawnTrigger = t
            }//setupTrigger
            
            public void unregisterTrigger() {//unsets the spawn trigger
                TriggerRemoveCondition(.spawnTrigger, .spawnCondition)
                .spawnTrigger = null
            }//unsetSpawnTrigger
            
            private static void onInit() {
                SpawnName.spawnFunction = Condition(function SpawnName.onSpawn)
            }//onInit
        }//Spawn
    }//CreateSpawn
    
    define CreateBase(BaseName, SpawnType, BaseType, Algorithm, ConditionType) = {
        struct BaseName {
            private static int spawnStructCount = 0
            private static int spawnStructRecycleCount = 0
            private static int spawnStructRecycle[]
            
            private static int basesCount = 0
            private static int bases[]
            private int baseId
            
            private static timer spawnTimer
            public static real spawnTime
            public static int spawnType
            public static int spawnCount
            public static real spawnOffset
            private bool isEnabled
            private static boolexpr spawnFunction
            private static triggercondition spawnCondition
            private static trigger spawnTrigger
            
            private static int curCount
            private static int curBaseCount
            
            implement BaseType
            implement Algorithm
            implement SpawnType
            #if ConditionType != null
                implement ConditionType
            #endif
            
            public void operator enabled=(bool doEnable) {
                .isEnabled = !doEnable
            }//enabled=
            
            public bool operator enabled() {
                return !.isEnabled
            }//enabled
            
            public static BaseName create() {
                if BaseName.spawnStructRecycleCount &gt; 0 {
                    BaseName.bases[BaseName.basesCount++] = BaseName.spawnStructRecycle[--BaseName.spawnStructRecycleCount]
                    BaseName(BaseName.bases[BaseName.basesCount-1]).baseId = BaseName.basesCount-1
                    return BaseName.bases[BaseName.basesCount-1]
                }//if
                BaseName.bases[BaseName.basesCount++] = BaseName.spawnStructCount++
                BaseName(BaseName.bases[BaseName.basesCount-1]).baseId = BaseName.basesCount-1
                return BaseName.spawnStructCount-1
            }//create
            
            public void destroy() {
                BaseName.spawnStructRecycle[BaseName.spawnStructRecycleCount++] = this
                BaseName.bases[.baseId] = BaseName.bases[--BaseName.basesCount]
                if .spawnCondition != null {
                    TriggerRemoveCondition(BaseName.spawnTrigger, .spawnCondition)
                    .spawnCondition = null
                }//if
            }//destroy
            
            private static bool onSpawn() {
                BaseName this
                BaseName.curBaseCount = BaseName.basesCount
                whilenot BaseName.curBaseCount == 0 {
                    this = --BaseName.curBaseCount
                    if !.isEnabled {
                        #if ConditionType != null
                            if .isValidEnum(.base)
                        #endif
                            BaseName.curCount = BaseName.spawnCount
                            .setupAlgorithm(.x, .y, .z, .facing, .spawnCount, .spawnOffset)
                            whilenot BaseName.curCount == 0 {
                                BaseName.curCount--
                                .createSpawn(.owner, .spawnType, .getX(BaseName.curCount), .getY(BaseName.curCount), .getZ(BaseName.curCount), .getFacing(BaseName.curCount), BaseName.curCount)
                            }//whilenot
                        #if ConditionType != null
                            endif
                        #endif
                    }//if
                }//whilenot
                return false
            }//onSpawn
            
            public static void startTimer() {
                TimerStart(BaseName.spawnTimer, BaseName.spawnTime, true, function BaseName.onSpawn)
            }//startTimer
            
            public static void pauseTimer() {
                PauseTimer(BaseName.spawnTimer)
            }//pauseTimer
            
            public static void resumeTimer() {
                ResumeTimer(BaseName.spawnTimer)
            }//stopTimer
            
            public static real getRemainingTime() {
                return TimerGetRemaining(BaseName.spawnTimer)
            }//getRemainingTime
            
            public static real getElapsedTime() {
                return TimerGetElapsed(BaseName.spawnTimer)
            }//getRemainingTime
            
            public static void registerTrigger(trigger t) {//just adds condition to trigger
                BaseName.spawnCondition = TriggerAddCondition(t, BaseName.spawnFunction)
                BaseName.spawnTrigger = t
            }//setupTrigger
            
            public static void unregisterTrigger() {//unsets the spawn trigger
                TriggerRemoveCondition(BaseName.spawnTrigger, BaseName.spawnCondition)
                BaseName.spawnCondition = null
            }//unsetSpawnTrigger
            
            private static void onInit() {
                BaseName.spawnFunction = Condition(function BaseName.onSpawn)
                BaseName.spawnTimer = CreateTimer()
            }//onInit
        }//BaseName
    }//CreateBase
    
    define CreateEnumUnitSpawn(EnumName, SpawnType, Algorithm, EnumRegion, EnumPlayer, ConditionTypeEnum) = {
        struct EnumName {
            private static boolexpr enumFilter
            private static boolexpr enumFiring
            public static int baseType = 0
            public static int spawnType = 0
            public static int spawnCount = 1
            public static real spawnOffset = 0
            public static real spawnTime = 0
            private static triggercondition spawnTriggerCond
            private static trigger spawnTrigger
            
            private static unit enumUnit
            private static player curOwner
            private static real curX
            private static real curY
            private static real curFacing
            private static int curCount
            
            private static timer spawnTimer = CreateTimer()
            
            implement SpawnType
            implement Algorithm
            #if ConditionTypeEnum != null
                implement ConditionTypeEnum
            #endif
            
            public static void registerTrigger(trigger t ) {
                EnumName.spawnTrigger = t
                EnumName.spawnTriggerCond = TriggerAddCondition(EnumName.spawnTrigger, EnumName.enumFiring)
            }//registerTrigger
            
            public static void unregisterTrigger() {
                TriggerRemoveCondition(EnumName.spawnTrigger, EnumName.spawnTriggerCond)
            }//unregisterTrigger
            
            private static bool enumSpawn() {
                EnumName.enumUnit = GetFilterUnit()
                if GetUnitTypeId(enumUnit) == baseType {
                    EnumName.curOwner = GetOwningPlayer(EnumName.enumUnit)
                    EnumName.curX = GetUnitX(EnumName.enumUnit)
                    EnumName.curY = GetUnitY(EnumName.enumUnit)
                    #if EnumRegion != null
                        #if EnumPlayer != null
                            if IsPointInRegion(EnumRegion, EnumName.curX, EnumName.curY) &amp;&amp; EnumName.curOwner == EnumPlayer
                        #else
                            if IsPointInRegion(EnumRegion, EnumName.curX, EnumName.curY)
                        #endif   
                    #elseif EnumPlayer != null
                        if EnumName.curOwner == EnumPlayer
                    #endif
                        #if ConditionTypeEnum != null
                            if EnumName.isValidEnum(EnumName.enumUnit)
                        #endif
                            EnumName.curFacing = GetUnitFacing(EnumName.enumUnit)
                            EnumName.curCount = EnumName.spawnCount
                            EnumName(0).setupAlgorithm(EnumName.curX, EnumName.curY, 0, EnumName.curFacing, EnumName.spawnCount, EnumName.spawnOffset)
                            whilenot EnumName.curCount == 0 {
                                EnumName.curCount--
                                EnumName(0).createSpawn(EnumName.curOwner, EnumName.spawnType, EnumName(0).getX(EnumName.curCount), EnumName(0).getY(EnumName.curCount), 0, EnumName(0).getFacing(EnumName.curCount), EnumName.curCount)
                            }//whilenot
                        #if ConditionTypeEnum != null
                            endif
                        #endif
                    #if EnumRegion != null
                        endif
                    #elseif EnumPlayer != null
                        endif
                    #endif
                }//if
                return false
            }//enumSpawn
            
            private static bool enumFire() {
                GroupEnumUnitsInRect(Spawn_spawnGroup, Spawn_world, EnumName.enumFilter)
                return false
            }//enumFire
            
            private static void onInit() {
                EnumName.enumFilter = Condition(function EnumName.enumSpawn)
                EnumName.enumFiring = Condition(function EnumName.enumFire)
            }
            
            public static void startTimer() {
                TimerStart(EnumName.spawnTimer, EnumName.spawnTime, true, function EnumName.enumFire)
            }//startTimer
            
            public static void pauseTimer() {
                PauseTimer(EnumName.spawnTimer)
            }//pauseTimer
            
            public static void resumeTimer() {
                ResumeTimer(EnumName.spawnTimer)
            }//resumeTimer
            
            public static real getRemainingTime() {
                return TimerGetRemaining(EnumName.spawnTimer)
            }//getRemainingTime
            
            public static real getElapsedTime() {
                return TimerGetElapsed(EnumName.spawnTimer)
            }//getElapsedTime
        }//EnumName
    }//CreateEnumSpawn
    
    define CreateEnumDestructableSpawn(EnumName, SpawnType, Algorithm, EnumRegion, ConditionTypeEnum) = {
        struct EnumName {
            private static boolexpr enumFilter
            private static boolexpr enumFiring
            public static int baseType = 0
            public static int spawnType = 0
            public static int spawnCount = 1
            public static real spawnOffset = 0
            public static real spawnTime = 0
            public static player owner = Player(15)
            public static real facing = 0
            
            private static triggercondition spawnTriggerCond
            private static trigger spawnTrigger
            
            private static destructable enumUnit
            
            private static real curX
            private static real curY
            private static real curZ
            
            private static int curCount
            
            private static timer spawnTimer = CreateTimer()
            
            implement SpawnType
            implement Algorithm
            #if ConditionTypeEnum != null
                implement ConditionTypeEnum
            #endif
            
            public static void registerTrigger(trigger t ) {
                EnumName.spawnTrigger = t
                EnumName.spawnTriggerCond = TriggerAddCondition(EnumName.spawnTrigger, EnumName.enumFiring)
            }//registerTrigger
            
            public static void unregisterTrigger() {
                TriggerRemoveCondition(EnumName.spawnTrigger, EnumName.spawnTriggerCond)
            }//unregisterTrigger
            
            private static bool enumSpawn() {
                EnumName.enumUnit = GetFilterDestructable()
                if GetDestructableTypeId(enumUnit) == baseType {
                    EnumName.curX = GetDestructableX(EnumName.enumUnit)
                    EnumName.curY = GetDestructableY(EnumName.enumUnit)
                    #if EnumRegion != null
                        if IsPointInRegion(EnumRegion, EnumName.curX, EnumName.curY)
                    #endif
                        #if ConditionTypeEnum != null
                            if EnumName.isValidEnum(EnumName.enumUnit)
                        #endif
                            EnumName.curZ = GetDestructableOccluderHeight(EnumName.enumUnit)
                            EnumName.curCount = EnumName.spawnCount
                            EnumName(0).setupAlgorithm(EnumName.curX, EnumName.curY, EnumName.curZ, EnumName.facing, EnumName.spawnCount, EnumName.spawnOffset)
                            whilenot EnumName.curCount == 0 {
                                EnumName.curCount--
                                EnumName(0).createSpawn(EnumName.owner, EnumName.spawnType, EnumName(0).getX(EnumName.curCount), EnumName(0).getY(EnumName.curCount), 0, EnumName(0).getFacing(EnumName.curCount), EnumName.curCount)
                            }//whilenot
                        #if ConditionTypeEnum != null
                            endif
                        #endif
                    #if EnumRegion != null
                        endif
                    #endif
                }//if
                return false
            }//enumSpawn
            
            private static bool enumFire() {
                EnumDestructablesInRect(Spawn_world, EnumName.enumFilter, null)
                return false
            }//enumFire
            
            private static void onInit() {
                EnumName.enumFilter = Condition(function EnumName.enumSpawn)
                EnumName.enumFiring = Condition(function EnumName.enumFire)
            }
            
            public static void startTimer() {
                TimerStart(EnumName.spawnTimer, EnumName.spawnTime, true, function EnumName.enumFire)
            }//startTimer
            
            public static void pauseTimer() {
                PauseTimer(EnumName.spawnTimer)
            }//pauseTimer
            
            public static void resumeTimer() {
                ResumeTimer(EnumName.spawnTimer)
            }//resumeTimer
            
            public static real getRemainingTime() {
                return TimerGetRemaining(EnumName.spawnTimer)
            }//getRemainingTime
            
            public static real getElapsedTime() {
                return TimerGetElapsed(EnumName.spawnTimer)
            }//getElapsedTime
        }//EnumName
    }//CreateDestructableSpawn
    
    define CreateEnumItemSpawn(EnumName, SpawnType, Algorithm, EnumRegion, EnumPlayer, ConditionTypeEnum, ConditionTypeEnumCarrier, ConditionTypeEnumCarried) = {
        struct EnumName {
            private static boolexpr enumFilter
            private static boolexpr enumFilterUnit
            private static boolexpr enumFiring
            public static int baseType = 0
            public static int spawnType = 0
            public static int spawnCount = 1
            public static real spawnOffset = 0
            public static real spawnTime = 0
            public static player defaultOwner = Player(15)
            
            private static triggercondition spawnTriggerCond
            private static trigger spawnTrigger
            
            private static item enumUnit
            private static unit enumUnit2
            
            private static real curX
            private static real curY
            private static real curZ
            private static player curOwner
            private static real curFacing
            
            private static int curCount
            private static int spawnsToPlace
            
            private static timer spawnTimer = CreateTimer()
            
            implement SpawnType
            implement Algorithm
            #if ConditionTypeEnum != null
                implement ConditionTypeEnum
            #endif
            #if ConditionTypeEnumCarrier != null
                implement ConditionTypeEnumCarrier
            #endif
            #if ConditionTypeEnumCarried != null
                implement ConditionTypeEnumCarried
            #endif
            
            public static void registerTrigger(trigger t ) {
                EnumName.spawnTrigger = t
                EnumName.spawnTriggerCond = TriggerAddCondition(EnumName.spawnTrigger, EnumName.enumFiring)
            }//registerTrigger
            
            public static void unregisterTrigger() {
                TriggerRemoveCondition(EnumName.spawnTrigger, EnumName.spawnTriggerCond)
            }//unregisterTrigger
            
            private static bool enumSpawnUnit() {
                EnumName.enumUnit2 = GetFilterUnit()
                EnumName.curCount = UnitInventorySize(EnumName.enumUnit2)
                EnumName.spawnsToPlace = 0
                EnumName.curX = GetUnitX(EnumName.enumUnit2)
                EnumName.curY = GetUnitY(EnumName.enumUnit2)
                EnumName.curOwner = GetOwningPlayer(EnumName.enumUnit2)
                #if EnumRegion != null
                    #if EnumPlayer != null
                        if IsPointInRegion(EnumRegion, EnumName.curX, EnumName.curY) &amp;&amp; EnumName.curOwner == EnumPlayer
                    #else
                        if IsPointInRegion(EnumRegion, EnumName.curX, EnumName.curY)
                    #endif   
                #elseif EnumPlayer != null
                    if EnumName.curOwner == EnumPlayer
                #endif
                    #if ConditionTypeEnumCarrier != null
                        if EnumName.checkEnumCarrier(EnumName.enumUnit2)
                    #endif
                        whilenot EnumName.curCount == 0 {
                            EnumName.curCount--
                            EnumName.enumUnit = UnitItemInSlot(EnumName.enumUnit2, EnumName.curCount)
                            if GetItemTypeId(EnumName.enumUnit) == EnumName.baseType {
                                #if ConditionTypeEnumCarried != null
                                    if EnumName.checkEnumCarriedItem(EnumName.enumUnit2, EnumName.enumUnit)
                                #endif
                                    EnumName.spawnsToPlace++
                                #if ConditionTypeEnumCarried != null
                                    endif
                                #endif
                            }//if
                        }//whilenot
                        if EnumName.spawnsToPlace &gt; 0 {
                            EnumName.curZ = GetUnitFlyHeight(EnumName.enumUnit2)
                            EnumName.curFacing = GetUnitFacing(EnumName.enumUnit2)
                            EnumName.curCount = EnumName.spawnCount*EnumName.spawnsToPlace
                            EnumName(0).setupAlgorithm(EnumName.curX, EnumName.curY, EnumName.curZ, EnumName.curFacing, EnumName.curCount, EnumName.spawnOffset)
                            whilenot EnumName.curCount == 0 {
                                EnumName.curCount--
                                EnumName(0).createSpawn(EnumName.curOwner, EnumName.spawnType, EnumName(0).getX(EnumName.curCount), EnumName(0).getY(EnumName.curCount), EnumName(0).getZ(EnumName.curCount), EnumName(0).getFacing(EnumName.curCount), EnumName.curCount)
                            }//whilenot
                        }//if
                    #if ConditionTypeEnumCarrier != null
                        endif
                    #endif
                #if EnumRegion != null
                    endif
                #elseif EnumPlayer != null
                    endif
                #endif
                return false
            }//enumSpawnUnit
            
            private static bool enumSpawn() {
                EnumName.enumUnit = GetFilterItem()
                if GetItemTypeId(EnumName.enumUnit) == EnumName.baseType {
                    EnumName.curX = GetItemX(EnumName.enumUnit)
                    EnumName.curY = GetItemY(EnumName.enumUnit)
                    #if EnumRegion != null
                        if IsPointInRegion(EnumRegion, EnumName.curX, EnumName.curY)
                    #endif
                        #if ConditionTypeEnum != null
                            if EnumName.isValidEnum(EnumName.enumUnit)
                        #endif
                            EnumName.curZ = 0
                            EnumName.curFacing = 0
                            EnumName.curOwner = EnumName.defaultOwner
                            EnumName.curCount = EnumName.spawnCount
                            EnumName(0).setupAlgorithm(EnumName.curX, EnumName.curY, EnumName.curZ, EnumName.curFacing, EnumName.spawnCount, EnumName.spawnOffset)
                            whilenot EnumName.curCount == 0 {
                                EnumName.curCount--
                                EnumName(0).createSpawn(EnumName.curOwner, EnumName.spawnType, EnumName(0).getX(EnumName.curCount), EnumName(0).getY(EnumName.curCount), EnumName(0).getZ(EnumName.curCount), EnumName(0).getFacing(EnumName.curCount), EnumName.curCount)
                            }//whilenot
                        #if ConditionTypeEnum != null
                            endif
                        #endif
                    #if EnumRegion != null
                        endif
                    #endif
                }//if
                return false
            }//enumSpawn
            
            private static bool enumFire() {
                EnumItemsInRect(Spawn_world, EnumName.enumFilter, null)
                GroupEnumUnitsInRect(Spawn_spawnGroup, Spawn_world, EnumName.enumFilterUnit)
                return false
            }//enumFire
            
            private static void onInit() {
                EnumName.enumFilter = Condition(function EnumName.enumSpawn)
                EnumName.enumFiring = Condition(function EnumName.enumFire)
                EnumName.enumFilterUnit = Condition(function EnumName.enumSpawnUnit)
            }
            
            public static void startTimer() {
                TimerStart(EnumName.spawnTimer, EnumName.spawnTime, true, function EnumName.enumFire)
            }//startTimer
            
            public static void pauseTimer() {
                PauseTimer(EnumName.spawnTimer)
            }//pauseTimer
            
            public static void resumeTimer() {
                ResumeTimer(EnumName.spawnTimer)
            }//resumeTimer
            
            public static real getRemainingTime() {
                return TimerGetRemaining(EnumName.spawnTimer)
            }//getRemainingTime
            
            public static real getElapsedTime() {
                return TimerGetElapsed(EnumName.spawnTimer)
            }//getElapsedTime
        }//EnumName
    }//CreateEnumItemSpawn
    
    private void Initialization() {
        Spawn_world = GetWorldBounds()
        Spawn_spawnGroup = CreateGroup()
    }//Initialization
}//Spawn


Demonstration Objects
JASS:

//Algorithm
///////////////////////////////////////////////////////////////////////////////
module AlgorithmLine {
    private real x
    private real y
    private real z
    private real facing
    private int count
    private real offset
    private real splitOffset
    
    public void setupAlgorithm(real x, real y, real z, real facing, int count, real offset) {
        .x = x
        .y = y
        .z = z
        .facing = facing*.01745
        .count = count
        .offset = offset
        .splitOffset = .offset/.count
    }//calc
    
    public real getX(int index) {
        return .x+.splitOffset*(index+1)*Cos(.facing)
    }//getX
    
    public real getY(int index) {
        return .y+.splitOffset*(index+1)*Sin(.facing)
    }//getY
    
    public real getZ(int index) {
        return .z //because default facing is only done in 2D
    }//getZ
    
    public real getFacing(int index) {
        return .facing
    }//getFacing
}//AlgorithmLine

//Base Type
///////////////////////////////////////////////////////////////////////////////
module BaseUnit {
    private unit spawnBase //do a unit
    private player spawnOwner
    //static values if needed
    //public real setX
    //public real setY
    //public real setZ
    //public real setFacing
    private location curLocation
    private static real returnVal
    
    public void operator base=(unit newVal) {
        .spawnBase = newVal
        if newVal != null {
            .spawnOwner = GetOwningPlayer(.spawnBase)
        }//if
        else {
            .spawnOwner = null
        }//else
    }//base=
    
    public unit operator base() {
        return .base
    }//base
    
    public void operator x=(real newVal) {
        SetUnitX(.spawnBase, newVal)
    }//x=
    
    public void operator y=(real newVal) {
        SetUnitY(.spawnBase, newVal)
    }//y=
    
    public void operator z=(real newVal) {
        SetUnitFlyHeight(.spawnBase, newVal, newVal+10000)
    }//z=
    
    public void operator facing=(real newVal) {
        SetUnitFacing(.spawnBase, newVal)
    }//facing=
    
    public real operator x() {
        return GetUnitX(.spawnBase)
    }//x
    
    public real operator y() {
        return GetUnitY(.spawnBase)
    }//y
    
    public real operator z() {
        return GetUnitFlyHeight(.spawnBase)
    }//z
    
    public real operator facing() {
        return GetUnitFacing(.spawnBase)
    }//facing
    
    public player operator owner() {
        return .spawnOwner
    }//owner
}//BaseUnit

//Spawn Type
///////////////////////////////////////////////////////////////////////////////
module SpawnUnit {
    public void createSpawn(player owner, int spawnType, real x, real y, real z, real facing, int current) {
        CreateUnit(owner, spawnType, x, y, facing)
    }//createSpawn
}//SpawnUnit


Demonstration Spawn Code
JASS:

library Demonstration initializer Demo uses Spawn {
    CreateSpawn(MySpawn, SpawnUnit, BaseUnit, AlgorithmLine, null)

    MySpawn mySpawn
    
    void Demo() {
        mySpawn = mySpawn.create()
        mySpawn.spawnCount = 4
        mySpawn.spawnType = &#039;hpea&#039;
        mySpawn.spawnOffset = 1000
        mySpawn.spawnTime = 4
        mySpawn.base = CreateUnit(Player(0), &#039;hfoo&#039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea), 100)
        mySpawn.startTimer()
    }//Demo
}


Demonstration Base Code
JASS:

library Demonstration initializer Demo uses Spawn {
    CreateBase(Barracks, SpawnUnit, BaseUnit, AlgorithmLine, null)
    
    Barracks barracks
    
    void Demo() {   
        Barracks.spawnCount = 4
        Barracks.spawnType = &#039;hfoo&#039;
        Barracks.spawnOffset = 1000
        Barracks.spawnTime = 4
        barracks = Barracks.create()
        barracks.base = CreateUnit(Player(0), &#039;Hpal&#039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea), 100)
        barracks = Barracks.create()
        barracks.base = CreateUnit(Player(0), &#039;Hpal&#039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea), 100)
        Barracks.startTimer()
    }//Demo
}


Demonstration Enum Unit Code
JASS:

library Demonstration initializer Demo uses Spawn {
    CreateEnumUnitSpawn(Barracks, SpawnUnit, AlgorithmLine, null, null, null)
    
    void Demo() {   
        Barracks.baseType = &#039;hbar&#039;
        Barracks.spawnType = &#039;hfoo&#039;
        Barracks.spawnOffset = 1000
        Barracks.spawnCount = 4
        Barracks.spawnTime = 6
        Barracks.startTimer()
        CreateUnit(Player(0), &#039;hbar&#039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea), 0)
        CreateUnit(Player(0), &#039;hbar&#039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea)-500, 0)
        CreateUnit(Player(0), &#039;hbar&#039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea)+500, 0)
    }//Demo
}


Demonstration Enum Item Code
JASS:

library Demonstration initializer Demo uses Spawn {
    CreateEnumItemSpawn(Claws, SpawnUnit, AlgorithmLine, null, null, null, null, null)
    
    void Demo() {   
        Claws.baseType = &#039;ratc&#039;
        Claws.spawnType = &#039;hfoo&#039;
        Claws.spawnOffset = 1000
        Claws.spawnCount = 4
        Claws.spawnTime = 6
        Claws.startTimer()
        CreateItem(&#039;ratc&#039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea))
        CreateItem(&#039;ratc&#039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea)-500)
        CreateUnit(Player(0), &#039;Hpal&#039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea)+200, 270)
    }//Demo
}


Demonstration Enum Destructable Code
JASS:

library Demonstration initializer Demo uses Spawn {
    CreateEnumDestructableSpawn(Tree, SpawnUnit, AlgorithmLine, null, null)
    
    void Demo() {   
        Tree.baseType = &#039;FTtw&#039;
        Tree.spawnType = &#039;hfoo&#039;
        Tree.spawnOffset = 1000
        Tree.spawnCount = 4
        Tree.spawnTime = 6
        Tree.startTimer()
        Tree.owner = Player(0)
        CreateDestructable(&#039;FTtw&#039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea), 0, 1, 1)
        CreateDestructable(&#039;FTtw&#039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea)-500, 0, 1, 1)
        CreateDestructable(&#039;FTtw&#039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea)+500, 0, 1, 1)
    }//Demo
}
 

Nestharus

o-o
Reaction score
84
You'll have to make it of Zinc || vJass if you ever want to submit it.

Not submitting, just asking for feedback on interface design :\

I'm still trying to figure out how to do dynamic text macros with this, lol : D.

I still don't know what it does.

JASS:

library Demonstration initializer Demo uses Spawn {
    CreateSpawn(MySpawn, SpawnUnit, BaseUnit, AlgorithmLine)
    
    MySpawn mySpawn
    
    void Demo() {
        mySpawn = mySpawn.create()
        mySpawn.spawnCount = 4
        mySpawn.spawnType = &#039;hpea&#039;
        mySpawn.spawnOffset = 1000
        mySpawn.spawnTime = 4
        mySpawn.base = CreateUnit(Player(0), &#039;hfoo&#039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea), 100)
        mySpawn.startTimer()
    }//Demo


Ok, so that would create a footmen and set it as the spawn's base. A spawn's base is what the spawn is attached to, aka where it spawns at and how it determines where it is located. The spawn base could be a location, could be coords, could be whatever ^_-, ofc if they were coords you'd have to do some dif coding ;p.

Next, it spawns 4 peasants every 4 seconds over an offset of 1000 using the Line Algorithm and Unit spawn type. Unit spawn type means that the peasants are indeed units, so it uses CreateUnit(). If they were items, the spawn type would be different.

The Line Algorithm I made spawns them in a line over the given offset towards the facing of the footmen. This means every 4 seconds, a line of 4 peasants 1000 pixels long will spawn in front of the footman : D.


Now, I say Spawn spawns things because there is a trigger and a timer, meaning you could just as easily register events ><.

You have an algorithm, a base type, and a spawn type at your disposal to allow you to spawn any sort of thing you want : ). This is a very simple demonstration (was going to do a circle, but that's done so often I thought a line would be more fun, maybe a star next ^^).


Now, what's cool is you can re use your objects. Let's say you wanted another spawn to be in a star algorithm, and in a this algorithm, etc, you could do that. To change a spawn's algorithm, you actually have to move all of the spawn's info from one spawn to the spawn with the algorithm you want. I made it a pain like this to stay away from trigger evaluations. Old Spawn made it really easy, but yea : p.

So that's what it does!! >: O
 

Nestharus

o-o
Reaction score
84
Well, I've made quite a few advances since the last version, but it's not ready to be released yet. The documentation is going to be the biggest pain : ).


Here's a look at some stuff using the new model.

First a Framework Object like CreateSpawn

JASS:

//A Look At Standard Many:1 (Spawn:Base) Spawn Creation
scope SpawnStruct {
    define &lt;Spawn.spawnStruct&gt;(SpawnStruct, SpawnType, BaseType, Algorithm, AlgorithmSetup) = Spawn.createSpawn(SpawnStruct, SpawnType, BaseType, Algorithm, AlgorithmSetup, null)
    define &lt;Spawn.spawnStruct&gt;(SpawnStruct, SpawnType, BaseType, Algorithm, AlgorithmSetup, ConditionType) = {
        struct SpawnStruct extends array {
            implement Spawn.variables
            
            //Put code Here
            //////////////////////////////////////////////////
                //variables
                //////////////////////////////////////////////////
                    //write
                    
                //modules/definitions
                //////////////////////////////////////////////////
                    implement BaseType
                    implement Algorithm
                    
                //code
                //////////////////////////////////////////////////
                    //write     
            //////////////////////////////////////////////////
            
            implement Spawn.fire(Struct.fire(SpawnType, AlgorithmSetup, ConditionType))
            
            implement Spawn.timers(##)
            implement Spawn.triggers(##)
            
            Spawn.Create.start(true)
                //write code here
            Spawn.Create.end
            
            Spawn.Destroy.start
                //write code here
            Spawn.Destroy.end(##)
            
            Spawn.Init.start(true)
                //write code here
            Spawn.Init.end
        }//Spawn.spawnStruct
    }//Spawn.spawnStruct
    
    define private &lt;Struct.fire&gt;(SpawnType, AlgorithmSetup, ConditionType) = {
        #if ConditionType != null
            ConditionType
        #endif
            AlgorithmSetup
            thistype.cur = .spawnCount
            whilenot thistype.cur &lt; 1 {
                thistype.cur--
                SpawnType
            }//whilenot
        #if ConditionType != null
            endif
        #endif
    }//fire
    
    //this is for enum types only, like GroupEnumUnits
    define private &lt;Struct.enum&gt;(SpawnType, AlgorithmSetup, ConditionType) = {
    }//enum
}//SpawnStruct



As you can see, I created a full language for creating Framework Objects ^_^.

But wait, does that mean the insides of the system have gone public? Hell no!

I set it up so that each section of the system and each object is fully encapsulated so that everything has explicit access to what it explicitly needs.

As an example of what I mean, here's the Spawn library-
JASS:

library Spawn initializer Initialization {
    private hashtable spawnHash = InitHashtable()
    private group spawnGroup = CreateGroup()
    private rect spawnWorld
    struct Spawn extends array {
        public static void setHash(int keyId, int id, int val) {
            SaveInteger(spawnHash, keyId, id, val)
        }//setHash
        
        public static int getHash(int keyId, int id) {
            return LoadInteger(spawnHash, keyId, id)
        }//getHash
        
        public static void removeHash(int keyId, int id) {
            RemoveSavedInteger(spawnHash, keyId, id)
        }//removeHash
        
        define &lt;Spawn.forGroup&gt;(c) = Spa##wn.forGroup2(c)
        define &lt;Spawn.forGroup&gt;(r, c) = Spa##wn.forGroup(r, c)

        public static void forGroup(rect r, boolexpr c) {
            GroupEnumUnitsInRect(spawnGroup, r, c)
        }//forGroup
        
        public static void forGroup2(boolexpr c) {
            GroupEnumUnitsInRect(spawnGroup, spawnWorld, c)
        }//forGroup2
    }//Spawn
    
    private void Initialization() {
        spawnWorld = GetWorldBounds()
    }//Initialization
}//Spawn


As can be seen, while you can use the variables in there, you can't modify them : ).

Now I'm not saying everything is readable etc, but I'm saying I'm keeping everything as tight as possible. It's taken me a long time to design the Framework Layer : o.


Furthermore, I've determined that there are 4 Archetypes of spawns, so I'll be including 4 Framework Objects, one of each type, with the system. These should address virtually all needs anyone will ever need. If for some reason you need something more, you just cnp the basic archetype you'll be extending from and then write your code in there. If for some reason you find a new archetype that I haven't thought of (I really think I got them all), then you can write it from scratch using the basic Spawn Framework Object (it's the simplest).



So, what about the old objects like Algorithms and so on? Well, they're still around but redesigned to be better than ever. If you look back at the new layout for Framework Objects, you'll notice I made a few changes to make it much more efficient. I made it virtually as efficient as possible. It'd be the same speed as a home brewed system that did the exact same thing : ). There are no extra operations.


So, since I've only finished designing one object so far in the midst of documentation and other things, I'll go ahead and show it to you. It's the most complicated one, Algorithm.

JASS:

/*
    Variables To Read-
    .x, .y, .z, .facing, .cur, .offset

    Variables To Set-
        private static real algorithmFacing
        private static real algorithmOffset
*/

define &lt;MyAlgorithm.setup&gt; = {
    //write code
}//Algorithm.verticalLine.setup

Algorithm.start(MyAlgorithm)
    Algorithm.X.start
        return 0
    Algorithm.X.end

    Algorithm.Y.start
        return 0
    Algorithm.Y.end

    Algorithm.Z.start
        return 0
    Algorithm.Z.end
    
    Algorithm.Facing.start
        return 0
    Algorithm.Facing.end
Algorithm.end


As you can see, it's very pretty and MUCH simpler than doing a framework object. Keep in mind that this is the most complicated of the regular objects : o.

The Spawn Framework will include basic relative spawning so that you can pretty much use it as a template. It'll also address most needs since many spawns are done at the origin: the base or thing with the spawn.


The documentation is much improved. Here's an excerpt from it-
Spawn Framework specializes in producing repeated data called spawns for origin data called
bases.

When you think of an origin, think of the center of a graph. When you think of a spawn, think of
a dot on that graph.

The origin can be anything so long as it has coordinates to represent the center of that graph.

The spawn can be anything so long as it can be placed as a dot on that graph.

There are three primary pieces to a typical spawn-
The Spawn Type
The Base Type
The Algorithm

The Spawn Type refers to the type of dot, for example maybe a unit or a spell.
The Base Type refers to the type of origin, maybe a unit, an item, or even set coordinates.

The Spawn Framework supports the ability to place more than one spawn at a time, so another key
piece to the puzzle is an Algorithm. The Algorithm determines how the spawns are placed.


It'll also include a guide and an API.


I'll also do nice demo code for each arch type so you can really see what can be done with Spawn.


Now keep in mind that enum spawns will still not be as good as a regular spawn or base spawn. Why? Enum spawns have to enumerate through handles whereas regular spawns are a single array read and base spawns iterate through an array ><. However, enum spawns are much easier to deal with because you never have to worrying about moving bases around or spawns around or changing from one spawn type to another. It's much more manageable.


Finally, to reiterate previous points, the code that the Spawn Framework produces for you is as efficient as possible. It also provides you with flexibilities so that absolutely no extra operations are done with any process. While it allows for triggers, it doesn't do a check when the spawn fires to see if it fired from a trigger or a timer and etc. I really did spend a long time on the framework code to make it pretty, easy to use, and efficient : ).
 

quraji

zap
Reaction score
144
Just like the first version of this, if you give me an example of spawning units I'll just say I can do it better, and faster, myself.

Show me something that this can do that is actually cool, or difficult/tedious to do on my own. Otherwise, it's just a big do-nothing system :(
 

Romek

Super Moderator
Reaction score
963
Although cJass help is allowed in the JASS forum, that does not mean you can start submitting all your cJass resources in this forum instead of the usual T&R Forum, where it's not allowed.

This forum is for help threads and discussion.

Closed.
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.

      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