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.
Demonstration Objects
Demonstration Spawn Code
Demonstration Base Code
Demonstration Enum Unit Code
Demonstration Enum Item Code
Demonstration Enum Destructable Code
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'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'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'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'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'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 'hpea'
//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'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'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'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 ('hpea'?)
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'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's trigger. Don'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's trigger. Don'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 ('hpea'?)
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'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's trigger. Don'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's trigger. Don'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 ('hpea'?)
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'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 > 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 > 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) && 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) && 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 > 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;hpea039;
mySpawn.spawnOffset = 1000
mySpawn.spawnTime = 4
mySpawn.base = CreateUnit(Player(0), 039;hfoo039;, 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;hfoo039;
Barracks.spawnOffset = 1000
Barracks.spawnTime = 4
barracks = Barracks.create()
barracks.base = CreateUnit(Player(0), 039;Hpal039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea), 100)
barracks = Barracks.create()
barracks.base = CreateUnit(Player(0), 039;Hpal039;, 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;hbar039;
Barracks.spawnType = 039;hfoo039;
Barracks.spawnOffset = 1000
Barracks.spawnCount = 4
Barracks.spawnTime = 6
Barracks.startTimer()
CreateUnit(Player(0), 039;hbar039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea), 0)
CreateUnit(Player(0), 039;hbar039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea)-500, 0)
CreateUnit(Player(0), 039;hbar039;, 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;ratc039;
Claws.spawnType = 039;hfoo039;
Claws.spawnOffset = 1000
Claws.spawnCount = 4
Claws.spawnTime = 6
Claws.startTimer()
CreateItem(039;ratc039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea))
CreateItem(039;ratc039;, GetRectCenterX(bj_mapInitialPlayableArea), GetRectCenterY(bj_mapInitialPlayableArea)-500)
CreateUnit(Player(0), 039;Hpal039;, 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;FTtw039;
Tree.spawnType = 039;hfoo039;
Tree.spawnOffset = 1000
Tree.spawnCount = 4
Tree.spawnTime = 6
Tree.startTimer()
Tree.owner = Player(0)
CreateDestructable(039;FTtw039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea), 0, 1, 1)
CreateDestructable(039;FTtw039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea)-500, 0, 1, 1)
CreateDestructable(039;FTtw039;, GetRectCenterX(bj_mapInitialPlayableArea)-200, GetRectCenterY(bj_mapInitialPlayableArea)+500, 0, 1, 1)
}//Demo
}