Name | Type | is_array | initial_value |
randomPoint | location | No | |
subStr | string | No | |
tempInt | integer | No | |
tempItemType | itemcode | No | |
tempPlayer | player | No | |
tempString | string | No | |
tempUnitType | unitcode | No | |
unitGroup | group | No | |
urReg | rect | No | |
urUnit | unit | No |
//TESH.scrollpos=219
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=2
//TESH.alwaysfold=0
library Alloc
module Alloc
private static integer array recycler
private static integer instanceCount = 0
debug private static boolean enabled = true
static method allocate takes nothing returns thistype
local thistype this = recycler[0]
debug if (not enabled) then
debug return 1/0
debug endif
if (this == 0) then
debug if (instanceCount == 8191) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"OVERFLOW")
debug set enabled = false
debug set this = 1/0
debug endif
set this = instanceCount + 1
set instanceCount = this
else
set recycler[0] = recycler[this]
endif
debug set recycler[this] = -1
return this
endmethod
method deallocate takes nothing returns nothing
debug if (not enabled) then
debug set this = 1/0
debug endif
debug if (recycler[this] != -1) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"ATTEMPT TO DEALLOCATE NULL STRUCT INSTANCE")
debug set enabled = false
debug set this = 1/0
debug endif
set recycler[this] = recycler[0]
set recycler[0] = this
endmethod
endmodule
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library UnitItemDrops /* by Deathismyfriend version 1.1.0.1
================================ Requirements =================================
Requires JNGP
*/uses Table, /* [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url] by bribe
* Alloc * [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-alloc-alternative-221493/[/url] by nestharus
*************************************************************************************
*
* Used to easily make drop tables for item drops when unit dies.
*
************************************************************************************
*
* Installing
* STEP 1: Install JNGP first if you dont have JNGP.
* STEP 2: Install Table by bribe the link is above.
* STEP 3: Install Alloc by nestharus the link is above. You may be able to use some other alloc systems.
* STEP 4: Copy and paste this library to your map.
*
************************************************************************************
*
* Description
* -----------------------
* This is a very easy item drop system.
* Allows for multi-Chance dropping of items w a simple method call after u call the create method.
*
* Capabilities
* -----------------------
* Allows the user to easily create an item recipe.
* - Easily create item tables for units that drop on percent chance.
* - You can add as many items as wanted for each table for the corresponding unit type id.
*
******************************************************************************************************************************************************************************************************
/ ******************************************************************************************************************************************************************************************************
/ *
/ * This uses a Weighted System for dropping. It does not use a percent chance drop.
/ *
/ * CREATORS / DESTRUCTORS
/ * ----------------------
/ * struct ItemDropSystem extends array
/ *
/ * static method createForType takes integer unitTypeId returns thistype
/ * - this is what you need to start an item drop table.
/ * - Below is how u add the items to the table
/ *
/ * static method createForUnit takes unit u, boolean dropTypeTableAlso returns thistype
/ * - this is used for creating item tables for specific units do not call the create function for these units.
/ * - Below is how u add the items to the table
/ * - If you have a table for the unit type. Made by the createForType method and
/ * - - want both tables to drop an item set this to true.
/ *
/ * method destroy takes nothing returns nothing
/ * - to destroy an item drop table for the unit type id
/ *
/ *
/ * FIELDS
/ * ------
/ * method addItem takes integer itemId, integer weight returns nothing
/ * - this is how u add items to the unit drop table.
/ * - The weight is the chance this item will be dropped.
/ *
/ * method addZeroDropWeight takes integer weight returns nothing
/ * - this is how u add a weight for no item drops.
/ *
/ * static method duplicateDropTable takes integer newUnitID, boolean createForUnitNew, integer oldUnitID, boolean createForUnitOld returns thistype
/ * - this allows you to duplicate an item drop table u previously created.
/ * - You need to tell what the old drop table was.
/ * - If you used the createForUnit method in the old drop table then you set the old one to true.
/ * - As for the new drop table its the same way. If u want to create it for a specific unit you set it to true.
/ * - Note: if you want to create it for a specific unit you need to use GetHandle( ur unit) as the integer.
/ *
/ * method setDropCount takes integer multi returns nothing
/ * - allows you to change the multi drop.
/ * - Set multidrop integer to 2 or higher for multidrop chance
/ *
/ * method getDropCount takes nothing returns integer
/ * - returns the multi drop integer that u have set.
/ *
/ * static method getDataTable takes integer id returns thistype
/ * - this returns the item Table so u can easily add items to the table or destroy it if u want
/ *
/ ********************************************************************************************************************************/
globals
private Table unitTypeTable
private Table unitIdTable
private TableArray itemDropTable
private TableArray itemIdTable
endglobals
struct ItemDropSystem extends array
implement Alloc
private integer index
private integer arrayI
private integer checkPercent
private integer weight
private integer ttlWeight
private integer unitTypeId
private integer multiDrop
private boolean specificUnit
private boolean dropTypeTableAlso
private method setValues takes nothing returns nothing
set this.multiDrop = 1
set this.index = 0
set this.weight = 0
endmethod
static method createForType takes integer unitTypeId returns thistype
local thistype this
if unitTypeTable.has(unitTypeId) then
return unitTypeTable[unitTypeId]
else
set this = thistype.allocate()
set this.unitTypeId = unitTypeId
set unitTypeTable[ this.unitTypeId] = this
set this.specificUnit = false
set this.dropTypeTableAlso = false
call this.setValues()
endif
return this
endmethod
static method createForUnit takes unit u, boolean dropTypeTableAlso returns thistype
local thistype this
local integer id = GetHandleId( u)
if unitIdTable.has(id) then
return unitIdTable[id]
else
set this = thistype.allocate()
set this.unitTypeId = id
set unitIdTable[ this.unitTypeId] = this
set this.specificUnit = true
set this.dropTypeTableAlso = dropTypeTableAlso
call this.setValues()
endif
return this
endmethod
static method duplicateDropTable takes integer newUnitID, boolean createForUnitNew, integer oldUnitID, boolean createForUnitOld returns thistype
local thistype this = thistype.allocate()
local thistype data
local integer L = 1
local integer weight
local integer itemId
if createForUnitOld then
set data = unitIdTable[ this.unitTypeId]
else
set data = unitTypeTable[ this.unitTypeId]
endif
if createForUnitNew then
set unitIdTable[ this.unitTypeId] = this
else
set unitTypeTable[ this.unitTypeId] = this
endif
loop
exitwhen L > data.index
set itemId = itemIdTable[data][L]
set itemIdTable[this][L] = itemId
set weight = itemDropTable[data][itemId]
set this.ttlWeight = this.ttlWeight + weight
set itemDropTable[this][itemId] = this.ttlWeight
set L = L + 1
endloop
set this.specificUnit = createForUnitNew
call this.setValues()
return this
endmethod
method setDropCount takes integer multi returns nothing
set this.multiDrop = multi
endmethod
method getDropCount takes nothing returns integer
return this.multiDrop
endmethod
static method getDataTable takes integer id returns thistype
if unitTypeTable.has( id) then
return unitTypeTable[ id]
endif
return unitIdTable[ id]
endmethod
method addZeroDropWeight takes integer weight returns nothing
set this.index = this.index + 1
set this.ttlWeight = this.ttlWeight + weight
set itemIdTable[this][index] = 100000
set itemDropTable[this][100000] = this.ttlWeight
endmethod
method addItem takes integer itemId, integer weight returns nothing
set this.index = this.index + 1
set this.ttlWeight = this.ttlWeight + weight
set itemIdTable[this][index] = itemId
set itemDropTable[this][itemId] = this.ttlWeight
endmethod
private method dropItem takes real x, real y returns boolean
local integer r
local integer L = 1
local integer L1 = 1
local integer end = 0
local integer array weights
set weights[0] = 0
if this != 0 then
loop
exitwhen L > this.index
set weights[L] = itemDropTable[this][itemIdTable[this][L]]
set end = end + 1
set L = L + 1
endloop
set L = 1
loop
exitwhen L > this.multiDrop
set r = GetRandomInt( 1, this.ttlWeight)
loop
exitwhen L1 > end
if r > weights[L1 - 1] and r <= weights[L1] then
call CreateItem( itemIdTable[this][L1], x, y)
endif
set L1 = L1 + 1
endloop
set L = L + 1
endloop
endif
return this.dropTypeTableAlso
endmethod
method destroy takes nothing returns nothing
local integer L = 0
if this.specificUnit then
call unitIdTable.remove( this.unitTypeId)
else
call unitTypeTable.remove( this.unitTypeId)
endif
call this.deallocate()
endmethod
private static method deathEvent takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer id = GetUnitTypeId( u)
local thistype this
local real x = GetUnitX( u)
local real y = GetUnitY( u)
local boolean b = true
if unitIdTable.has( GetHandleId( u)) then
set this = unitIdTable[ GetHandleId( u)]
set b = this.dropItem( x, y)
call destroy()
endif
if unitTypeTable.has( id) and b then
set this = unitTypeTable[ id]
call this.dropItem( x, y)
endif
set u = null
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
set unitTypeTable = Table.create()
set unitIdTable = Table.create()
set itemIdTable = TableArray[0x2000]
set itemDropTable = TableArray[0x2000]
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition( t, function thistype.deathEvent)
set t = null
endmethod
endstruct
endlibrary
/*
[HIDDEN="Changelog"]
version 1.1.0.0
[INDENT]*Fixed mmajor bug.[/INDENT]
version 1.0.7.5
[INDENT]*Fixed a bad bug were multiple items would be dropped when they shouldn't.[/INDENT]
version 1.0.7.1
[INDENT]*Made some small changes.
*Thanks purge[/INDENT]
version 1.0.7.0
[INDENT]*Now Removes the data stored in the hashtable if it is for a specific unit.
*Fixed some mistakes.[/INDENT]
version 1.0.6.8
[INDENT]*Now if u have a unit with a specific handle and the unit has an item table for its item type it will drop items from both item tables.[/INDENT]
version 1.0.6.7
[INDENT]*Added a method that allows the user to duplicate an item drop table that has previously been created[/INDENT]
version 1.0.6.5
[INDENT]*changed the API
*changed the addItem function to only take one item and the weight of that item
*added a getDropCount which returns the multidrop integer
*changed the create method names to make it easier to understand
*changed it over to a weight taking system instead of percents
*added a method for no item drop w weights[/INDENT]
version 1.0.6.0
[INDENT]*got rid of tsa
*Changed the system to increase speed[/INDENT]
version 1.0.5.3
[INDENT]*Added protection from op limit w TSA. ( opend to better options ?)
*Can now change or add items to an old item Table that was previously made
just call the create function u used for that unit also allows you to change the multichance w same time
*Be careful when using this as the item Table keeps the old items percent that were already stored
if percent of drops added to 100 b4 you will have to destroy then recreate the item Table[/INDENT]
version 1.0.5.2
[INDENT]*fixed a mistype which caused unwanted results[/INDENT]
version 1.0.5.1
[INDENT]*allows for up to 400 item Tables now [/INDENT]
version 1.0.5.0
[INDENT]*allows you to create item drops based on preplaced / specific units[/INDENT]
version 1.0.0.0
[INDENT]*first version released[/INDENT]
[/HIDDEN]
*/
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope ItemTables initializer init
globals
private integer L = 0
endglobals
function addToTable takes nothing returns nothing
local ItemDropSystem data = ItemDropSystem.createForType( 'hpea')
call data.addItem( 'afac', 20)
call data.addItem( 'ratc', 20)
call data.addItem( 'rat6', 20)
call data.addItem( 'rat9', 20)
call data.addItem( 'rst1', 100)
set data = ItemDropSystem.createForType( 'hfoo')
call data.addItem( 'rag1', 100)
endfunction
//===========================================================================
function init takes nothing returns nothing
local trigger t = CreateTrigger()
local timer t1 = CreateTimer()
call TriggerRegisterTimerEvent( t, 0.00, false)
call TriggerAddAction( t, function addToTable)
set t = null
endfunction
endscope