- Joined
- Dec 12, 2008
- Messages
- 7,385
This system will generate long lists of key map objects.
It will generate 4 seperate lists:
-Items
-Abilities
-Heroes
-Buffs
This can be pretty Useful for Save/Load systems that depend on lists like this
To reduce lag, I'm using a periodic lister
It takes 1 second to generate a list of 1000 objects.
Here's the code:
Give credits if used
It will generate 4 seperate lists:
-Items
-Abilities
-Heroes
-Buffs
This can be pretty Useful for Save/Load systems that depend on lists like this
To reduce lag, I'm using a periodic lister
It takes 1 second to generate a list of 1000 objects.
Here's the code:
JASS:
//*********************************************************************
//
// Object
// Database Generator
// v0.5
// Magtheridon96
//
//*********************************************************************
//
// This is a system that generates lists of the items, buffs,
// abilities and heroes in a map.
//
// It will create a database for the names of the objects and
// another parallel database for the raw codes.
//
// Example:
//
// In a map:
// There are 5 items ('I000' 'I002' 'I%$$' 'I700' and 'I009')
//
// This system will create something like this:
//
// iData[0] = 'I000' ; iObj[0] = Ring
// iData[1] = 'I002' ; iObj[1] = Brace
// iData[2] = 'I009' ; iObj[2] = Belt
// iData[3] = 'I700' ; iObj[3] = Sword
// iData[4] = 'I%$$' ; iObj[4] = Mace
//
// This system can only be useful for maps with HUGE amounts of
// object data (Thousands)
//
// WC3 only supports up to 16777216 items, abilities, buffs, etc...
//
// This system loops through ALL of them ONLY ONCE to generate the
// database. I'm sorry for this inconvinience, but that's the only
// way it could be done (especially since most people command the
// object merger to create objects with raw codes like 'A@@#' or
// 'A!!!'...
//
// This system depends on the NUMBER of objects you have.
// It will NOT affect performance if you have objects like:
//
// 'A009' ; 'A0FF' ; 'A052'
//
// But if you have objects like:
//
// 'A000' ; 'AXXF' ; 'A##2'
//
// It will LAG LIKE HELL!
//
// It's all map dependent. If you don't have huge gaps between raw codes,
// this may be pretty useful. Lists like these are essential especially
// for Save/Load systems :]
//
// Benchmarks:
//
// 3000 objects => 3 seconds ; >57 FPS
// 30000 objects => 16 seconds ; >47 FPS
// 90000 objects => 90 seconds ; <5 FPS
//
// That's actually pretty good :)
// Most maps barely have 1000 objects!
//
//*********************************************************************
//
// Changelog
//
// *** v0.1 ***
// -Released
//
// *** v0.2 ***
// -Made it faster
//
// *** v0.3 ***
// -Fixed Timer Leaks
// -Made it much more efficient
// -Shortened variable names
// -Removed the pesky underscores :P
// -This system is now much safer and doesn't require a dummy unit
//
// *** v0.4 ***
// -Very minor fix
// -Improved readability
//
// *** v0.5 ***
// -Fixed a bug (Thanks Troll-Brain)
// -New Functions used to get the indices given the name.
//
//*********************************************************************
library DatabaseGen initializer Init
globals
// configurable:
// Number of Nightelf based heroes
private constant integer NE = 15
// Number of Human based heroes
private constant integer NH = 3
// Number of Orc based heroes
private constant integer NO = 7
// Number of Undead based heroes
private constant integer NU = 4
// Number of Neutral based heroes
private constant integer NN = 2
// Number of items
private constant integer NI = 234
// Number of abilities
private constant integer NA = 287
// Number of Buffs
private constant integer NB = 323
// end configurables
// Base Ability
private constant integer BA = 'A000'
// Base Buff
private constant integer BB = 'B000'
// Base Item
private constant integer BI = 'I000'
// Base Hero
private integer BH = 'E000'
// Indices
private integer i = 0
private integer j = 0
private constant player P = Player(12)
// Data Storage
integer array iData // item data
integer array aData // ability data
integer array bData // buff data
integer array hData // hero data
string array iObj // item name data
string array aObj // ability name data
string array bObj // buff name data
string array hObj // hero name data
endglobals
private function GenB takes nothing returns nothing
local string s = GetObjectName(BB + i)
if s != "" and s != null then
set bData[j] = BB + i
set bObj[j] = s
set j = j + 1
endif
set i = i + 1
if j > NB then
call DestroyTimer(GetExpiredTimer())
set P = null
endif
set s = ""
endfunction
private function GenH takes nothing returns nothing
local unit u
if j > NE then
set BH = 'H000'
set j = 0
elseif j > NH then
set BH = 'N000'
set j = 0
elseif j > NN then
set BH = 'O000'
set j = 0
elseif j > NO then
set BH = 'U000'
set j = 0
elseif j > NU then
set i = 0
set j = 0
call TimerStart(GetExpiredTimer(),0.001,true,function GenB)
return
endif
set u = CreateUnit(P,BH + i,0,0,0)
if u != null then
set hData[j] = BH + i
set hObj[j] = GetObjectName(BH + i)
set j = j + 1
call RemoveUnit(u)
endif
set i = i + 1
set u = null
endfunction
private function GenA takes nothing returns nothing
local string s = GetObjectName(BA + i)
if s != "" and s != null then
set aData[j] = BA + i
set aObj[j] = s
set j = j + 1
endif
if j > NA then
set i = 0
set j = 0
call TimerStart(GetExpiredTimer(),0.001,true,function GenH)
return
endif
set i = i + 1
set s = ""
endfunction
private function GenI takes nothing returns nothing
local item h = CreateItem(BI + i,0,0)
if h != null then
set iData[j] = BI + i
set iObj[j] = GetObjectName(BI + i)
set j = j + 1
call RemoveItem(h)
endif
if j > NI then
set i = 0
set j = 0
call TimerStart(GetExpiredTimer(),0.001,true,function GenA)
return
endif
set i = i + 1
set h=null
endfunction
private function Init takes nothing returns nothing
call TimerStart(CreateTimer(),0.001,true,function GenI)
endfunction
// These functions are used to retrieve the index
// of the raw codes given the name of the object.
//! textmacro getIndex takes name, char, char2
function Get$name$Index takes string s returns integer
local integer g = 0
loop
exitwhen g>N$char2$
if $char$Obj[g]==s then
return g
endif
set g = g + 1
endloop
return -1
endfunction
//! endtextmacro
//! runtextmacro getIndex("Ability","a","A")
//! runtextmacro getIndex("Item","i","I")
//! runtextmacro getIndex("Buff","b","B")
//! runtextmacro getIndex("Hero","h","H")
endlibrary
Give credits if used
Last edited: