library Spawn initializer ini requires Mfn
globals
private constant string SYSTEM = "Spawn"
private constant string VERSION = ".01b"
private constant integer CN = 2
private constant string AUTHOR = "Nestharus"
private constant string HELPERS = "None"
private constant string TEXTURE_PATH = "ReplaceableTextures\\CommandButtons\\BTNHumanBarracks.blp"
private constant string NAME = "Spawn"
public hashtable memory
public key DATA
public key SPAWN
public key CONTAINER_BASE
public key CONTAINER_SPAWN
public key OWNERS
public key LENT
public key BORROWED
public key LENT_SPAWN
public key BORROWED_SPAWN
public key BASE
public key STEPS
public key BORROWED_SPAWN_TYPE
public key BORROWED_SPAWN_TYPE_R
public key FIRST_BORROWED_SPAWN
endglobals
public keyword Base
public keyword Spawn
public keyword Handle
public function getBase takes handle u returns integer
return LoadInteger(memory, Mfn_UNIT, GetHandleId(u))
endfunction
public function getHandle takes handle u returns integer
return LoadInteger(memory, Mfn_HANDLE, GetHandleId(u))
endfunction
public function hasBase takes handle u returns boolean
local integer baseOwner = Base(LoadInteger(memory, Mfn_UNIT, GetHandleId(u))).base
local integer h = getHandle(u)
return ((baseOwner == h) and (h > -1))
endfunction
public function hasHandle takes handle u returns boolean
return (Handle(getHandle(u)).h > 0)
endfunction
public function giveBase takes handle u1, handle u2 returns nothing
call Base(getBase(u1)).transfer(Handle(getHandle(u2)))
endfunction
public function takeBase takes handle u1, handle u2 returns nothing
call Base(getBase(u2)).transfer(getHandle(u1))
endfunction
public function tradeBase takes handle u1, handle u2 returns nothing
call Base(getBase(u1)).trade(u2)
endfunction
public function enableHandleSpawns takes handle u, boolean b returns nothing
call Base(getBase(u)).enableSpawns(b)
endfunction
public function enableHandleSpawn takes integer s, handle u, boolean b returns nothing
call Base(getBase(u)).enableSpawn(s, b)
endfunction
public function tradeSpawns takes handle u, handle u2 returns nothing
call Base(getBase(u)).tradeSpawnAll(Base(getBase(u2)))
endfunction
public function borrowBase takes handle u1, handle u2 returns nothing
call Base(getBase(u2)).lend(getHandle(u1))
endfunction
public function lendBase takes handle u1, handle u2 returns nothing
call Base(getBase(u1)).lend(getHandle(u2))
endfunction
public function getBackBase takes handle u returns nothing
call Base(LoadInteger(memory, Spawn_LENT, GetHandleId(u))).original()
endfunction
public function revertBase takes handle u returns nothing
call Base(getBase(u)).revert()
endfunction
public function originalBase takes handle u returns nothing
call Base(getBase(u)).original()
endfunction
public function replace takes handle u, integer typeId returns integer
local integer h = getBase(u)
call Spawn_Handle(Base(h).base).change(typeId)
return h
endfunction
public interface Handle
public integer h
public hashtable memory
public method getX takes nothing returns real defaults 0.0
public method getY takes nothing returns real defaults 0.0
public method getPlayer takes nothing returns player defaults null
public method getTypeId takes nothing returns integer defaults 0
public method getLife takes nothing returns real defaults 0.0
public method getLevel takes nothing returns integer defaults 0
public method getXP takes nothing returns integer defaults 0
public method getFacing takes nothing returns real defaults 0.0
public method setPosition takes real x, real y returns nothing defaults nothing
public method setPlayer takes player p returns nothing defaults nothing
public method setTypeId takes integer t returns nothing defaults nothing
public method setLife takes real x returns nothing defaults nothing
public method setLevel takes integer x returns nothing defaults nothing
public method setXP takes integer x returns nothing defaults nothing
public method setFacing takes real x returns nothing defaults nothing
public static method create takes nothing
public method make takes player p, integer typeId, real x, real y, real facing returns nothing defaults nothing
public method getHandleId takes nothing returns integer defaults 0
public method clean takes nothing returns nothing defaults nothing
public method change takes integer typeId returns nothing defaults nothing
endinterface
public interface SpawnObject
public method make takes player p, integer typeId, real x, real y, real facing returns nothing defaults nothing
public static method create takes nothing
endinterface
public interface SpawnMethod
public method setupEvents takes integer b returns nothing defaults nothing
public method createNew takes nothing returns nothing defaults nothing
public method cloneCustom takes integer s, integer b returns nothing defaults nothing
public method mimicCustom takes integer s returns nothing defaults nothing
public method spawnAction takes player p, real x, real y returns nothing defaults nothing
public method resetCustom takes nothing returns nothing defaults nothing defaults nothing
public method destroyCustom takes nothing returns nothing defaults nothing
endinterface
public interface BaseMethod
public method modify takes integer s, integer addRemove returns nothing defaults nothing
public method resetEventsCustom takes nothing returns nothing defaults nothing
public method dieCustom takes integer b returns nothing defaults nothing
public method mimicEventsCustom takes integer b returns nothing defaults nothing
public method stopMimicEventsCustom takes nothing returns nothing defaults nothing
public method mimicSpawnsCustom takes integer b returns nothing defaults nothing
public method stopMimicSpawnsCustom takes integer b returns nothing defaults nothing
public method mimicCustom takes integer b returns nothing defaults nothing
public method stopMimicCustom takes integer b returns nothing defaults nothing
public method cloneCustom takes integer b, player p, real x, real y, real facing returns nothing defaults nothing
public method createNew takes nothing returns nothing defaults nothing
public method destroyCustom takes nothing returns nothing defaults nothing
public method resetCustom takes nothing returns nothing defaults nothing
public method cloneDataCustom takes integer b returns nothing defaults nothing
public method stopMimicHandleCustom takes nothing returns nothing defaults nothing
public method mimicHandleCustom takes nothing returns nothing defaults nothing
public method startMimicCustom takes integer b returns nothing defaults nothing
endinterface
public interface Base
public Base container
public delegate Handle base
public delegate BaseMethod methodType
public integer spawnIndex
public trigger die
public integer containerID
public integer ownerIndex
public integer lentIndex
public integer borrowedIndex
public integer borrowedSpawnTypeIndex
public integer typeId
public boolean mimicing
public hashtable memory
public hashtable memorySpawnLent
public hashtable memorySpawnBorrowed
public method engraveSpawn takes integer s returns nothing defaults nothing
public method degraveSpawn takes integer s returns nothing defaults nothing
public method createSpawn takes integer ft returns integer defaults 0
public method addSpawn takes integer s returns integer defaults 0
public method removeSpawn takes integer s returns nothing defaults nothing
public method clearSpawns takes nothing returns nothing defaults nothing
public method resetEvents takes nothing returns nothing defaults nothing
public method disableSpawn takes integer s returns nothing defaults nothing
public method enableSpawn takes integer s, boolean restart returns nothing defaults nothing
public method enableSpawns takes boolean restart returns nothing defaults nothing
public method disableSpawns takes nothing returns nothing defaults nothing
public method clone takes player p, real x, real y, real facing returns integer defaults 0
public method create2 takes nothing returns integer defaults 0
public static method create takes nothing
public method reset takes nothing returns nothing defaults nothing
public method degraveSpawns takes nothing returns nothing defaults nothing
public method isAttached takes nothing returns boolean defaults false
public method new takes integer typeid, player p, integer typeId, real x, real y, real facing returns nothing defaults nothing
public method revert takes nothing returns nothing defaults nothing
public method original takes nothing returns nothing defaults nothing
public method cloneData takes nothing returns integer defaults 0
public method cloneSpawns takes integer c returns nothing defaults nothing
public method mimicSpawns takes integer c returns integer defaults 0
public method mimic takes integer b returns integer defaults 0
public method mimicHandle takes integer b returns integer defaults 0
public method stopMimicHandle takes nothing returns nothing defaults nothing
public method stopMimicSpawns takes nothing returns nothing defaults nothing
public method startMimic takes nothing returns integer defaults 0
public method stopMimic takes nothing returns integer defaults 0
public method transfer takes integer u returns nothing defaults nothing
public method remove takes nothing returns nothing defaults nothing
public method attach takes integer u returns nothing defaults nothing
public method giveSpawn takes integer s, integer b returns nothing defaults nothing
public method giveSpawns takes integer b returns nothing defaults nothing
public method takeSpawn takes integer s, integer b returns nothing defaults nothing
public method takeSpawns takes integer b returns nothing defaults nothing
public method lend takes integer u returns nothing defaults nothing
public method lendSpawn takes integer s, integer b returns nothing defaults nothing
public method lendSpawns takes integer b returns nothing defaults nothing
public method borrowSpawn takes integer s, integer b returns nothing defaults nothing
public method borrowSpawns takes integer b returns nothing defaults nothing
public method revertSpawns takes nothing returns nothing defaults nothing
public method revertSpawn takes integer s returns nothing defaults nothing
public method revertSpawnTo takes integer s, integer steps returns nothing defaults nothing
public method revertSpawnsTo takes integer steps returns nothing defaults nothing
public method originalSpawns takes nothing returns nothing defaults nothing
public method originalSpawn takes integer s returns nothing defaults nothing
public method swap takes integer b returns nothing defaults nothing
public method trade takes handle u returns nothing defaults nothing
public method tradeSpawn takes integer s, integer s2, integer b returns nothing defaults nothing
public method tradeSpawnAll takes integer b returns nothing defaults nothing
public method getBackSpawns takes nothing returns nothing defaults nothing
public method getBackSpawn takes integer s returns nothing defaults nothing
public method revertTo takes integer s returns nothing defaults nothing
public method putSpawn takes integer s returns nothing defaults nothing
public method setSpawnOwner takes integer s returns nothing defaults nothing
public method retireSpawn takes integer s returns nothing defaults nothing
public method unsetSpawnOwner takes integer s returns nothing defaults nothing
public method disableSpawn2 takes integer s returns nothing defaults nothing
public method enableSpawn2 takes integer s, boolean restart returns nothing defaults nothing
endinterface
public interface Spawn
public Spawn container
public timer t
public integer base
public real spawnTime
public integer spawnType
public integer spawnCount
public integer id
public integer objectType
public trigger spawnEvent
public delegate SpawnObject spawnHandle
public delegate SpawnMethod methodType
public integer ownerIndex
public hashtable memory
public boolean mimicing
public method transfer takes integer b returns nothing defaults nothing
public method clone takes integer b returns integer defaults 0
public method mimic takes integer s returns integer defaults 0
public method create2 takes nothing returns integer defaults 0
public static method create takes nothing
public method reset takes nothing returns nothing defaults nothing
public method isAttached takes nothing returns boolean defaults false
public method revert takes nothing returns nothing defaults nothing
public method revertTo takes integer steps returns nothing defaults nothing
public method original takes nothing returns nothing defaults nothing
public method startMimic takes nothing returns integer defaults 0
public method stopMimic takes nothing returns integer defaults 0
public method mimicSpawnTime takes integer s returns integer defaults 0
public method mimicSpawnType takes integer s returns integer defaults 0
public method mimicSpawnCount takes integer s returns integer defaults 0
public method mimicSpawnHandle takes integer s returns integer defaults 0
public method mimicMethoType takes integer s returns integer defaults 0
public method stopMimicSpawnTime takes nothing returns nothing defaults nothing
public method stopMimicSpawnType takes nothing returns nothing defaults nothing
public method stopMimicSpawnCount takes nothing returns nothing defaults nothing
public method stopMimicSpawnHandle takes nothing returns nothing defaults nothing
public method stopMimicMethodType takes nothing returns nothing defaults nothing
public method disable takes nothing returns nothing defaults nothing
public method enable takes boolean restart returns nothing defaults nothing
endinterface
public keyword SpawnPrototype
public struct BasePrototype extends Base
public Base container = -1
public delegate Handle base
public delegate BaseMethod methodType
public integer ownerIndex = 0
public integer spawnIndex = 0
public integer lentIndex = 0
public integer borrowedIndex = 0
public integer borrowedSpawnTypeIndex = 0
public trigger die
public boolean mimicing = false
public integer typeId = 0
public hashtable memory
public hashtable memorySpawnLent
public hashtable memorySpawnBorrowed
public method original takes nothing returns nothing
local integer x
if (.ownerIndex > 1) then
set .base = LoadInteger(this.memory, Spawn_OWNERS, 0)
call SaveInteger(memory, Mfn_UNIT, .getHandleId(), this)
loop
exitwhen .ownerIndex <= 1
set .ownerIndex = .ownerIndex - 1
set x = Handle(LoadInteger(this.memory, Spawn_OWNERS, .ownerIndex)).getHandleId()
if HaveSavedInteger(memory, Spawn_LENT, x) then
call RemoveSavedInteger(memory, Spawn_LENT, x)
endif
call RemoveSavedInteger(memory, Spawn_BORROWED, x)
call RemoveSavedInteger(this.memory, Spawn_OWNERS, .ownerIndex)
endloop
elseif (.ownerIndex == 1) then
set .base = LoadInteger(this.memory, Spawn_OWNERS, 0)
endif
if HaveSavedInteger(memory, Spawn_LENT, x) then
call RemoveSavedInteger(memory, Spawn_LENT, x)
endif
endmethod
public method revert takes nothing returns nothing
local integer x = 0
if (.ownerIndex > 1) then
set .ownerIndex = .ownerIndex - 1
call RemoveSavedInteger(memory, Spawn_BORROWED, .getHandleId())
call RemoveSavedInteger(this.memory, Spawn_OWNERS, .ownerIndex)
set .base = LoadInteger(this.memory, Spawn_OWNERS, .ownerIndex-1)
set x = .getHandleId()
call RemoveSavedInteger(memory, Spawn_LENT, x)
call SaveInteger(memory, Mfn_UNIT, x, this)
elseif (.ownerIndex == 1) then
set .base = LoadInteger(this.memory, Spawn_OWNERS, 0)
endif
if HaveSavedInteger(memory, Spawn_LENT, x) then
call RemoveSavedInteger(memory, Spawn_LENT, x)
endif
endmethod
public method revertTo takes integer s returns nothing
local Handle u
local integer x
loop
set .ownerIndex = .ownerIndex - 1
set u = LoadInteger(this.memory, Spawn_OWNERS, .ownerIndex)
exitwhen u == s
call RemoveSavedInteger(memory, Spawn_BORROWED, u)
call RemoveSavedInteger(this.memory, Spawn_OWNERS, .ownerIndex)
call RemoveSavedInteger(memory, Spawn_LENT, u)
endloop
set .base = u
set x = .getHandleId()
call SaveInteger(memory, Mfn_UNIT, x, this)
if HaveSavedInteger(memory, Spawn_LENT, x) then
call RemoveSavedInteger(memory, Spawn_LENT, u)
endif
endmethod
public method lend takes integer u returns nothing
call RemoveSavedInteger(memory, Mfn_UNIT, .getHandleId())
call SaveInteger(memory, Spawn_LENT, .getHandleId(), this)
call SaveInteger(memory, Spawn_BORROWED, Handle(u).getHandleId(), this)
call .attach(u)
endmethod
public method new takes integer typeid, player p, integer typeId, real x, real y, real facing returns nothing
set .base = Handle.create(typeid)
call .make(p, typeId, x, y, facing)
call SaveInteger(memory, Mfn_UNIT, .getHandleId(), this)
set .ownerIndex = .ownerIndex + 1
call SaveInteger(this.memory, Spawn_OWNERS, .ownerIndex-1, .base)
endmethod
public method isAttached takes nothing returns boolean
return (.base > 0)
endmethod
public method putSpawn takes integer s returns nothing
local Spawn spawn = s
local integer index
set index = .spawnIndex
call SaveInteger(this.memory, Spawn_SPAWN, index, s)
set .spawnIndex = .spawnIndex + 1
call .modify(s, 1)
set spawn.id = index
set spawn.base = this
endmethod
public method setSpawnOwner takes integer s returns nothing
local Spawn spawn = s
local Base base = spawn.base
local Base previousBase
call SaveInteger(spawn.memory, Spawn_OWNERS, spawn.ownerIndex, this)
set spawn.ownerIndex = spawn.ownerIndex + 1
if (spawn.ownerIndex > 1) then
set previousBase = LoadInteger(spawn.memory, Spawn_OWNERS, spawn.ownerIndex-2)
if (not HaveSavedInteger(base.memory, Spawn_BORROWED_SPAWN_TYPE_R, spawn)) then
call SaveInteger(base.memory, Spawn_BORROWED_SPAWN_TYPE, base.borrowedSpawnTypeIndex, spawn)
call SaveInteger(base.memory, Spawn_BORROWED_SPAWN_TYPE_R, spawn, base.borrowedSpawnTypeIndex)
call SaveInteger(base.memory, Spawn_FIRST_BORROWED_SPAWN, spawn, spawn.ownerIndex-1)
set base.borrowedSpawnTypeIndex = base.borrowedSpawnTypeIndex + 1
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Base " + I2S(base) + " is now borrowing spawn type " + I2S(spawn) + " in " + I2S(base.borrowedSpawnTypeIndex-1))
endif
call SaveInteger(previousBase.memorySpawnLent, spawn, spawn.ownerIndex-2, previousBase.lentIndex)
call SaveInteger(base.memorySpawnBorrowed, spawn, spawn.ownerIndex-1, base.borrowedIndex)
call SaveInteger(previousBase.memory, Spawn_LENT_SPAWN, previousBase.lentIndex, spawn)
call SaveInteger(base.memory, Spawn_BORROWED_SPAWN, base.borrowedIndex, spawn)
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "--------------------------------------------------")
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Spawn " + I2S(spawn) + " Is now lent by " + I2S(previousBase) + " To " + I2S(base))
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, " With Lent Id " + I2S(previousBase.lentIndex) + " for " + I2S(previousBase))
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, " With Borrowed Id " + I2S(base.borrowedIndex) + " for " + I2S(this))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Spawn " + I2S(spawn) + " no longer has id " + I2S(s) + " for " + I2S(previousBase))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Spawn " + I2S(spawn) + " has id " + I2S(spawn.id) + " for " + I2S(base))
if (HaveSavedInteger(previousBase.memory, Spawn_STEPS, spawn) == false) then
call SaveInteger(previousBase.memory, Spawn_STEPS, spawn, spawn.ownerIndex-2)
endif
set previousBase.lentIndex = previousBase.lentIndex + 1
set base.borrowedIndex = base.borrowedIndex + 1
endif
endmethod
public method engraveSpawn takes integer s returns nothing
call .putSpawn(s)
call .setSpawnOwner(s)
endmethod
public method retireSpawn takes integer s returns nothing
local Spawn spawn = s
set .spawnIndex = .spawnIndex - 1
set spawn = LoadInteger(this.memory, Spawn_SPAWN, .spawnIndex)
set spawn.id = Spawn(s).id
call SaveInteger(this.memory, Spawn_SPAWN, spawn.id, spawn)
set spawn = s
call .modify(spawn, -1)
set spawn.id = -1
set spawn.base = -1
endmethod
public method unsetSpawnOwner takes integer s returns nothing
local Spawn spawn = s
local Base owner
local integer index
local integer spawnIndexing
local boolean doRevert = false
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "-----------------------------------------------------")
if (spawn.ownerIndex == 1 and HaveSavedInteger(this.memory, Spawn_STEPS, spawn)) then
call RemoveSavedInteger(this.memory, Spawn_STEPS, spawn)
elseif (spawn.ownerIndex > 1) then
set doRevert = true
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "----------------REVERTING SPAWN----------------")
if (LoadInteger(this.memory, Spawn_FIRST_BORROWED_SPAWN, spawn) == spawn.ownerIndex-1) then
set .borrowedSpawnTypeIndex = .borrowedSpawnTypeIndex - 1
set index = LoadInteger(this.memory, Spawn_BORROWED_SPAWN_TYPE_R, spawn)
if index < .borrowedSpawnTypeIndex then
set spawnIndexing = LoadInteger(this.memory, Spawn_BORROWED_SPAWN_TYPE, .borrowedSpawnTypeIndex)
call SaveInteger(this.memory, Spawn_BORROWED_SPAWN_TYPE, index, spawnIndexing)
call SaveInteger(this.memory, Spawn_BORROWED_SPAWN_TYPE_R, spawnIndexing, index)
call RemoveSavedInteger(this.memory, Spawn_STEPS, spawn)
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Base " + I2S(this) + " got rid of steps for " + I2S(spawn))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Base " + I2S(this) + " is no longer borrowing spawn type " + I2S(spawn))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Spawn type " +I2S(spawn) + " Was in spawn type borrow slot " + I2S(index))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Spawn type " + I2S(spawnIndexing) + " Is now moved from " + I2S(.borrowedSpawnTypeIndex) + " To " + I2S(index))
endif
endif
endif
set spawn.ownerIndex = spawn.ownerIndex - 1
if (doRevert) then
set owner = LoadInteger(spawn.memory, Spawn_OWNERS, spawn.ownerIndex-1)
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "||||SPAWN " + I2S(spawn) + " BEING REVERTED FROM " + I2S(this) + " TO " + I2S(owner) + "||||")
set .borrowedIndex = .borrowedIndex - 1
set index = LoadInteger(this.memorySpawnBorrowed, spawn, spawn.ownerIndex)
if index < .borrowedIndex then
set spawnIndexing = LoadInteger(this.memory, Spawn_BORROWED_SPAWN, .borrowedIndex)
call SaveInteger(this.memory, Spawn_BORROWED_SPAWN, index, spawnIndexing)
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "-----------------------------------------------------")
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Real spawn " + I2S(spawn) + " Is no longer being borrowed by " + I2S(this))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Real spawn " +I2S(spawn) + " Was in borrow slot " + I2S(index))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Spawn " + I2S(spawnIndexing) + " Is now moved from " + I2S(.borrowedIndex) + " To " + I2S(index))
endif
set owner.lentIndex = owner.lentIndex - 1
set index = LoadInteger(owner.memorySpawnLent, spawn, spawn.ownerIndex-1)
if index < owner.lentIndex then
set spawnIndexing = LoadInteger(owner.memory, Spawn_LENT_SPAWN, owner.lentIndex)
call SaveInteger(owner.memory, Spawn_LENT_SPAWN, index, spawnIndexing)
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "-----------------------------------------------------")
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Real spawn " + I2S(spawn) + " Is no longer being lent by " + I2S(owner))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Real spawn " +I2S(spawn) + " Was in lent slot " + I2S(index))
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 120000, "Spawn " + I2S(spawnIndexing) + " Is now moved from " + I2S(.lentIndex) + " To " + I2S(index))
endif
endif
endmethod
public method degraveSpawn takes integer s returns nothing
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
call spawn.disable()
call .retireSpawn(spawn)
call .unsetSpawnOwner(spawn)
endmethod
public method addSpawn takes integer s returns integer
local Spawn s2 = s
set s2 = s2.clone(this)
return s2
endmethod
public method removeSpawn takes integer s returns nothing
local Spawn s2 = LoadInteger(this.memory, Spawn_SPAWN, s)
call .degraveSpawn(s)
call s2.destroy()
endmethod
public method clearSpawns takes nothing returns nothing
loop
exitwhen .spawnIndex == 0
call .removeSpawn(.spawnIndex-1)
endloop
endmethod
public method degraveSpawns takes nothing returns nothing
loop
exitwhen .spawnIndex == 0
call .degraveSpawn(.spawnIndex-1)
endloop
endmethod
public method takeSpawn takes integer s, integer b returns nothing
call Base(b).giveSpawn(s, this)
endmethod
public method takeSpawns takes integer b returns nothing
call Base(b).giveSpawns(this)
endmethod
public method lendSpawn takes integer s, integer b returns nothing
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
call .retireSpawn(spawn)
call Base(b).putSpawn(spawn)
call Base(b).setSpawnOwner(spawn)
endmethod
public method lendSpawns takes integer b returns nothing
local integer x = .spawnIndex
loop
exitwhen x == 0
call .lendSpawn(x-1, b)
set x = x - 1
endloop
endmethod
public method revertSpawns takes nothing returns nothing
local integer x = .borrowedIndex - .spawnIndex
loop
exitwhen .borrowedIndex == x or .borrowedIndex == 0
call .revertSpawn(Spawn(LoadInteger(this.memory, Spawn_BORROWED_SPAWN, .borrowedIndex-1)).id)
endloop
endmethod
public method revertSpawn takes integer s returns nothing
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
local integer index
local integer spawnIndexing
local Base owner
if (spawn.ownerIndex > 1) then
call .retireSpawn(spawn)
call .unsetSpawnOwner(spawn)
set owner = LoadInteger(spawn.memory, Spawn_OWNERS, spawn.ownerIndex-1)
call owner.putSpawn(spawn)
endif
endmethod
public method originalSpawns takes nothing returns nothing
loop
exitwhen .borrowedIndex == 0
call .originalSpawn(Spawn(LoadInteger(this.memory, Spawn_BORROWED_SPAWN, .borrowedIndex)).id)
endloop
endmethod
public method originalSpawn takes integer s returns nothing
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
local Base owner
loop
exitwhen spawn.ownerIndex == 1
set owner = LoadInteger(spawn.memory, Spawn_OWNERS, spawn.ownerIndex-1)
call owner.revertSpawn(spawn.id)
endloop
endmethod
public method borrowSpawn takes integer s, integer b returns nothing
call Base(b).lendSpawn(s, this)
endmethod
public method revertSpawnTo takes integer s, integer steps returns nothing
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
local integer currentStep = spawn.ownerIndex
local Base owner = LoadInteger(spawn.memory, Spawn_OWNERS, spawn.ownerIndex-1)
local integer x
set spawn = LoadInteger(owner.memory, Spawn_SPAWN, s)
set x = spawn.ownerIndex
loop
exitwhen spawn.ownerIndex == currentStep-steps or spawn.ownerIndex == 1
set owner = LoadInteger(spawn.memory, Spawn_OWNERS, spawn.ownerIndex-1)
call owner.revertSpawn(spawn.id)
if x == spawn.ownerIndex then
return
endif
endloop
endmethod
public method revertSpawnsTo takes integer steps returns nothing
local integer x = .borrowedSpawnTypeIndex
loop
exitwhen x == 0
call .revertSpawnTo(Spawn(LoadInteger(this.memory, Spawn_BORROWED_SPAWN_TYPE, x-1)).id, steps)
set x = x - 1
endloop
endmethod
public method getBackSpawns takes nothing returns nothing
local integer x = .lentIndex
loop
exitwhen .lentIndex == 0
call .getBackSpawn(LoadInteger(this.memory, Spawn_LENT_SPAWN, .lentIndex-1))
if x == .lentIndex then
return
else
set x = .lentIndex
endif
endloop
endmethod
public method getBackSpawn takes integer s returns nothing
local Spawn spawn = s
call Base(Spawn(s).base).revertSpawnTo(Spawn(s).id, spawn.ownerIndex - (LoadInteger(this.memory, Spawn_STEPS, spawn)+1))
endmethod
public method borrowSpawns takes integer b returns nothing
call Base(b).lendSpawns(this)
endmethod
public method tradeSpawn takes integer s, integer s2, integer b returns nothing
local Base base = b
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
local Spawn spawn2 = LoadInteger(base.memory, Spawn_SPAWN, s2)
call .retireSpawn(spawn)
call base.retireSpawn(spawn2)
call .unsetSpawnOwner(spawn)
call base.unsetSpawnOwner(spawn2)
call .putSpawn(spawn2)
call base.putSpawn(spawn)
call .setSpawnOwner(spawn2)
call base.setSpawnOwner(spawn)
endmethod
public method tradeSpawnAll takes integer b returns nothing
local integer array spawn1
local integer array spawn2
local integer spawn1Index = -1
local integer spawn2Index = -1
local integer x = 0
local Spawn spawn
local Base base = b
loop
exitwhen .spawnIndex == 0
set spawn1Index = spawn1Index + 1
set spawn1[spawn1Index] = LoadInteger(this.memory, Spawn_SPAWN, .spawnIndex-1)
call .retireSpawn(spawn1[spawn1Index])
call .unsetSpawnOwner(spawn1[spawn1Index])
endloop
loop
exitwhen base.spawnIndex == 0
set spawn2Index = spawn2Index + 1
set spawn2[spawn2Index] = LoadInteger(base.memory, Spawn_SPAWN, base.spawnIndex-1)
call base.retireSpawn(spawn2[spawn2Index])
call base.unsetSpawnOwner(spawn2[spawn2Index])
endloop
loop
call base.putSpawn(spawn1[x])
call base.setSpawnOwner(spawn1[x])
set x = x + 1
exitwhen x > spawn1Index
endloop
set x = 0
loop
call .putSpawn(spawn2[x])
call .setSpawnOwner(spawn2[x])
set x = x + 1
exitwhen x > spawn2Index
endloop
endmethod
public method mimic takes integer b returns integer
local Base base = b
if not .mimicing then
set this = .startMimic()
endif
set .methodType = base.methodType
call Handle(.base).change(Handle(Base(b).base).getTypeId())
call .mimicSpawns(b)
call .resetEvents()
call .mimicEventsCustom(b)
call .mimicCustom(b)
return this
endmethod
public method startMimic takes nothing returns integer
local thistype b = thistype.create()
set b.methodType = .methodType
call .cloneSpawns(b)
call .cloneDataCustom(b)
set b.base = .base
set b.container = this
set b.mimicing = true
set .typeId = Handle(.base).getTypeId()
call .disableSpawns()
call b.enableSpawns(true)
call .startMimicCustom(b)
return b
endmethod
public method stopMimic takes nothing returns integer
local Base b = this
if b.mimicing == true then
set this = b.container
set b.container = -1
if Handle(b.base).getType() != .typeId then
call Handle(.base).change(.typeId)
endif
call .stopMimicCustom(b)
call b.destroy()
call .enableSpawns(true)
endif
return this
endmethod
public method stopMimicHandle takes nothing returns nothing
call Handle(.base).change(Handle(Base(.container).base).getTypeId())
call .stopMimicHandleCustom()
endmethod
public method mimicHandle takes integer b returns integer
if not .mimicing then
set this = .startMimic()
endif
call Handle(.base).change(Handle(Base(b).base).getTypeId())
call .mimicHandleCustom()
return this
endmethod
public method mimicSpawns takes integer c returns integer
local integer x = 0
local Base b = c
if not .mimicing then
set this = .startMimic()
endif
call .clearSpawns()
loop
exitwhen x >= b.spawnIndex
call .addSpawn(LoadInteger(b.memory, Spawn_SPAWN, x))
set x = x + 1
endloop
call .mimicSpawnsCustom(b)
call .enableSpawns(true)
return this
endmethod
public method stopMimicSpawns takes nothing returns nothing
call .mimicSpawns(.container)
call .stopMimicSpawnsCustom(.container)
endmethod
public method resetEvents takes nothing returns nothing
call TriggerClearActions(.die)
call TriggerAddAction(.die, function thistype.dieA)
call .resetEventsCustom()
endmethod
public static method dieA takes nothing returns nothing
local thistype b = LoadInteger(memory, Mfn_TRIGGER, GetHandleId(GetTriggeringTrigger()))
call b.dieCustom.execute(b)
endmethod
public method giveSpawn takes integer s, integer b returns nothing
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
call .retireSpawn(spawn)
call .unsetSpawnOwner(spawn)
call Base(b).engraveSpawn(spawn)
endmethod
public method giveSpawns takes integer b returns nothing
local integer x = .spawnIndex
loop
exitwhen x == 0
call .giveSpawn(x-1, b)
set x = x - 1
endloop
endmethod
public method disableSpawn takes integer s returns nothing
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
call DisableTrigger(spawn.spawnEvent)
if (spawn.spawnTime > 0) then
call PauseTimer(spawn.t)
endif
endmethod
public method enableSpawn takes integer s, boolean restart returns nothing
local Spawn spawn = LoadInteger(this.memory, Spawn_SPAWN, s)
call EnableTrigger(spawn.spawnEvent)
if (spawn.spawnTime > 0) then
if (restart) then
call TimerStart(spawn.t, spawn.spawnTime, false, null)
else
call ResumeTimer(spawn.t)
endif
endif
endmethod
public method enableSpawns takes boolean restart returns nothing
local integer x = 0
local Spawn s
loop
exitwhen x >= .spawnIndex
set s = LoadInteger(this.memory, Spawn_SPAWN, x)
call EnableTrigger(s.spawnEvent)
if (s.spawnTime > 0) then
if (restart) then
call TimerStart(s.t, s.spawnTime, false, null)
else
call ResumeTimer(s.t)
endif
endif
set x = x + 1
endloop
endmethod
public method disableSpawns takes nothing returns nothing
local integer x = 0
local Spawn s
loop
exitwhen x >= .spawnIndex
set s = LoadInteger(this.memory, Spawn_SPAWN, x)
call DisableTrigger(s.spawnEvent)
if (s.spawnTime > 0) then
call PauseTimer(s.t)
endif
set x = x + 1
endloop
endmethod
public method cloneSpawns takes integer c returns nothing
local integer x = 0
local integer y = .spawnIndex
local Base b = c
loop
exitwhen x >= y
call b.addSpawn(LoadInteger(this.memory, Spawn_SPAWN, x))
set x = x + 1
endloop
endmethod
public method cloneData takes nothing returns integer
local thistype b = thistype.create()
call b.attach(Handle.create(Handle(.base).getType()))
set b.methodType = .methodType
call .cloneSpawns(b)
call .cloneDataCustom(b)
return b
endmethod
public method clone takes player p, real x, real y, real facing returns integer
local thistype b = .cloneData()
call b.make(p, .getTypeId(), x, y, facing)
call .cloneCustom(b, p, x, y, facing)
return b
endmethod
public method attach takes integer u returns nothing
set .base = u
call SaveInteger(memory, Mfn_UNIT, .getHandleId(), this)
set .ownerIndex = .ownerIndex + 1
call SaveInteger(this.memory, Spawn_OWNERS, .ownerIndex-1, u)
endmethod
public method remove takes nothing returns nothing
call .disableSpawns()
call RemoveSavedInteger(memory, Mfn_UNIT, .getHandleId())
set .base = -1
set .ownerIndex = .ownerIndex - 1
call RemoveSavedInteger(this.memory, Spawn_OWNERS, .ownerIndex)
endmethod
public method transfer takes integer u returns nothing
call RemoveSavedInteger(memory, Mfn_UNIT, .getHandleId())
set .ownerIndex = .ownerIndex - 1
call .attach(u)
endmethod
public method swap takes integer b returns nothing
local Base b2 = b
local Handle u1 = .base
local Handle u2 = b2.base
set .ownerIndex = .ownerIndex - 1
set b2.ownerIndex = b2.ownerIndex - 1
call .attach(u2)
call b2.attach(u1)
endmethod
public method trade takes handle u returns nothing
local Base targetBase = getBase(u)
local Handle base = .base
local Handle base2 = targetBase.base
set .ownerIndex = .ownerIndex - 1
set targetBase.ownerIndex = targetBase.ownerIndex - 1
call targetBase.attach(base)
call .attach(base2)
endmethod
public method create2 takes nothing returns integer
return thistype.create()
endmethod
public static method create3 takes integer baseMethod returns thistype
local thistype b = thistype.create()
set b.methodType = baseMethod
call b.createNew()
return b
endmethod
public static method create takes nothing returns thistype
local thistype b = thistype.allocate()
set b.memory = InitHashtable()
set b.memorySpawnLent = InitHashtable()
set b.memorySpawnBorrowed = InitHashtable()
set b.die = CreateTrigger()
call SaveInteger(memory, Mfn_TRIGGER, GetHandleId(b.die), b)
call TriggerAddAction(b.die, function thistype.dieA)
call b.createNew()
return b
endmethod
public method onDestroy takes nothing returns nothing
local integer x = 0
call .clearSpawns()
if .container != -1 then
call .container.destroy()
endif
call .destroyCustom()
call TriggerClearActions(.die)
if (.base > 0) then
call RemoveSavedInteger(memory, Mfn_UNIT, .getHandleId())
endif
call FlushParentHashtable(this.memory)
call FlushParentHashtable(this.memorySpawnLent)
call FlushParentHashtable(this.memorySpawnBorrowed)
set .die = null
endmethod
endstruct
public struct SpawnPrototype extends Spawn
public Spawn container = -1
public timer t
public integer base = -1
public real spawnTime
public integer spawnType
public integer spawnCount
public integer id
public integer ownerIndex = 0
public trigger spawnEvent
public boolean mimicing = false
public delegate SpawnObject spawnHandle
public delegate SpawnMethod methodType
public hashtable memory
public method isAttached takes nothing returns boolean
return (.base > 0)
endmethod
public method transfer takes integer b returns nothing
call Base(.base).degraveSpawn(this)
call Base(b).engraveSpawn(this)
endmethod
public method clone takes integer b returns integer
local thistype s = thistype.create()
local Base b2 = b
set s.spawnTime = .spawnTime
set s.spawnType = .spawnType
set s.spawnCount = .spawnCount
set s.spawnHandle = .spawnHandle
set s.methodType = .methodType
call b2.engraveSpawn(s)
call s.cloneCustom(this, b)
return s
endmethod
public method startMimic takes nothing returns integer
local thistype s = .clone(.base)
set s.mimicing = true
set s.container = this
call .mimicCustom(s)
call .disable()
call s.enable(true)
return s
endmethod
public method stopMimic takes nothing returns integer
local Spawn s = this
if s.mimicing == true then
set this = s.container
set s.container = -1
call s.destroy()
call .enable(true)
endif
return this
endmethod
public method mimic takes integer s returns integer
if .mimicing == false then
set this = .startMimic()
endif
set .spawnTime = Spawn(s).spawnTime
set .spawnType = Spawn(s).spawnType
set .spawnCount = Spawn(s).spawnCount
set .spawnHandle = Spawn(s).spawnHandle
set .methodType = Spawn(s).methodType
call Spawn(s).mimicCustom(this)
return this
endmethod
public method mimicSpawnTime takes integer s returns integer
if .mimicing == false then
set this = .startMimic()
endif
set .spawnTime = Spawn(s).spawnTime
return this
endmethod
public method mimicSpawnType takes integer s returns integer
if .mimicing == false then
set this = .startMimic()
endif
set .spawnType = Spawn(s).spawnType
return this
endmethod
public method mimicSpawnCount takes integer s returns integer
if .mimicing == false then
set this = .startMimic()
endif
set .spawnCount = Spawn(s).spawnCount
return this
endmethod
public method mimicSpawnHandle takes integer s returns integer
if .mimicing == false then
set this = .startMimic()
endif
set .spawnHandle = Spawn(s).spawnHandle
return this
endmethod
public method mimicMethodType takes integer s returns integer
if .mimicing == false then
set this = .startMimic()
endif
set .methodType = Spawn(s).methodType
return this
endmethod
public method stopMimicSpawnTime takes nothing returns nothing
set .spawnTime = Spawn(.container).spawnTime
endmethod
public method stopMimicSpawnType takes nothing returns nothing
set .spawnType = Spawn(.container).spawnType
endmethod
public method stopMimicSpawnCount takes nothing returns nothing
set .spawnCount = Spawn(.container).spawnCount
endmethod
public method stopMimicSpawnHandle takes nothing returns nothing
set .spawnHandle = Spawn(.container).spawnHandle
endmethod
public method stopMimicMethodType takes nothing returns nothing
set .methodType = Spawn(.container).methodType
endmethod
public method revertTo takes integer steps returns nothing
call Base(.base).revertSpawnTo(this.id, steps)
endmethod
public method revert takes nothing returns nothing
call Base(.base).revertSpawn(this.id)
endmethod
public method original takes nothing returns nothing
call Base(.base).originalSpawn(this.id)
endmethod
public method enable takes boolean restart returns nothing
call EnableTrigger(.spawnEvent)
if (.spawnTime > 0) then
if (restart) then
call TimerStart(.t, .spawnTime, false, null)
else
call ResumeTimer(.t)
endif
endif
endmethod
public method disable takes nothing returns nothing
call DisableTrigger(.spawnEvent)
if (.spawnTime > 0) then
call PauseTimer(.t)
endif
endmethod
public static method spawnAction2 takes nothing returns nothing
local thistype s = LoadInteger(memory, Mfn_TRIGGER, GetHandleId(GetTriggeringTrigger()))
local Base b = s.base
local integer x = 0
local real tempCoord
local real xBase = b.getX()
local real yBase = b.getY()
local player p = b.getPlayer()
if (HaveSavedReal(b.memory, Mfn_X, s.id)) then
set xBase = LoadReal(b.memory, Mfn_X, s.id)
endif
if (HaveSavedReal(b.memory, Mfn_Y, s.id)) then
set yBase = LoadReal(b.memory, Mfn_Y, s.id)
endif
loop
call s.make.execute(p, s.spawnType, xBase, yBase, 0)
call s.spawnAction.execute(p, xBase, yBase)
set x = x + 1
exitwhen x >= s.spawnCount
endloop
if (s.spawnTime > 0) then
call TimerStart(s.t, s.spawnTime, false, null)
endif
endmethod
public method create2 takes nothing returns integer
return thistype.create()
endmethod
public static method create3 takes integer spawnMethod returns thistype
local thistype s = thistype.create()
set s.methodType = spawnMethod
call s.createNew()
return s
endmethod
public static method create takes nothing returns thistype
local thistype s = thistype.allocate()
set s.memory = InitHashtable()
set s.spawnEvent = CreateTrigger()
call SaveInteger(memory, Mfn_TRIGGER, GetHandleId(s.spawnEvent), s)
set s.t = CreateTimer()
call TriggerRegisterTimerExpireEvent(s.spawnEvent, s.t)
call TriggerAddAction(s.spawnEvent, function thistype.spawnAction2)
return s
endmethod
public method onDestroy takes nothing returns nothing
local integer x = 0
if .container != -1 then
call .container.destroy()
endif
call TriggerClearActions(.spawnEvent)
set .spawnEvent = null
if (.spawnTime > 0) then
call PauseTimer(.t)
endif
call DestroyTimer(.t)
set .t = null
call RemoveSavedInteger(memory, Mfn_TRIGGER, GetHandleId(.spawnEvent))
if (.base > 0) then
call Base(.base).removeSpawn(.id)
endif
call .destroyCustom()
call FlushParentHashtable(this.memory)
endmethod
endstruct
private function ini takes nothing returns nothing
call Mfn_createCredit1(SYSTEM, VERSION, AUTHOR, HELPERS, TEXTURE_PATH, "The ultimate in spawning.")
set memory = InitHashtable()
endfunction
endlibrary
library RequiresSpawn requires Spawn
endlibrary