- Joined
- Feb 2, 2006
- Messages
- 1,631
Hi,
for my save/load system I want to be able to store certain unit, building, item and research types but not ALL of them and I do not want to use the 4 digit raw codes which will become quite big numbers.
Currently, I am registering all types manually with something like this:
As you can see I simply increase the counter and give each type a new unique ID. I could use a separate array for each classification like unit, item, research and even building etc. to keep the numbers lower since in my savecodes I know what to expect.
It works but it is a lot of work to add all unit types, item types etc. manually. Is there some way to iterate through all raw code IDs and check certain properties of the object type (maybe by creating a dummy) and then decide whether to add it or not?
Besides, when adding new items or units I will either have to append them or the IDs will change with the next map release and you will load different stuff.
How do save/load systems usually solve this issue?
for my save/load system I want to be able to store certain unit, building, item and research types but not ALL of them and I do not want to use the 4 digit raw codes which will become quite big numbers.
Currently, I am registering all types manually with something like this:
-
Actions
-
-------- Humans --------
-
Set VariableSet TmpUnitType = Footman
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Knight
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Rifleman
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Mortar Team
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Flying Machine
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Gryphon Rider
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Priest
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Sorceress
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Siege Engine
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Spellbreaker
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Dragonhawk Rider
-
Custom script: call AddSaveObjectUnitType()
-
-------- Orcs --------
-
Set VariableSet TmpUnitType = Grunt
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Raider
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Tauren
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Headhunter
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Demolisher
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Kodo Beast
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Wind Rider
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Batrider
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Witch Doctor
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Shaman
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Spirit Walker
-
Custom script: call AddSaveObjectUnitType()
-
-------- Night Elf --------
-
Set VariableSet TmpUnitType = Archer
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Huntress
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Dryad
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Glaive Thrower
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Hippogryph
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Hippogryph Rider
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Chimaera
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Druid of the Talon (Night Elf Form)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Druid of the Claw (Night Elf Form)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Mountain Giant
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Faerie Dragon
-
Custom script: call AddSaveObjectUnitType()
-
-------- Undead --------
-
Set VariableSet TmpUnitType = Shade
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Ghoul
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Abomination
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Meat Wagon
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Crypt Fiend
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Gargoyle
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Banshee
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Necromancer
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Obsidian Statue
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Frost Wyrm
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Dalaran Mutant
-
Custom script: call AddSaveObjectUnitType()
-
-------- Naga --------
-
Set VariableSet TmpUnitType = Couatl
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Mur'gul Reaver
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Naga Siren
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Snap Dragon
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Naga Myrmidon
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Naga Royal Guard
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Dragon Turtle
-
Custom script: call AddSaveObjectUnitType()
-
-------- Demon --------
-
Set VariableSet TmpUnitType = Overlord (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Fel Stalker (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Infernal Machine (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Greater Voidwalker (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Infernal (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Doom Guard (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Succubus (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Eredar Sorcerer (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Nether Drake (Demons)
-
Custom script: call AddSaveObjectUnitType()
-
-------- Draenei --------
-
Set VariableSet TmpUnitType = Draenei Harbinger (Draenei)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Draenei Seer (Draenei)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Tamed Nether Drake (Draenei)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Salamander (Draenei)
-
Custom script: call AddSaveObjectUnitType()
-
-------- Furbolg --------
-
Set VariableSet TmpUnitType = Furbolg (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Furbolg Shaman (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Furbolg Tracker (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Furbolg Champion (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Furbolg Elder Shaman (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Furbolg Ursa Warrior (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Timber Wolf (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Giant Wolf (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Dire Wolf (Furbolg)
-
Custom script: call AddSaveObjectUnitType()
-
-------- Goblin --------
-
Set VariableSet TmpUnitType = Goblin Flamethrower
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Goblin Sapper (Goblins)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Ogre Goblin Squad (Walking)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Ogre Goblin Squad (Ready)
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Assault Tank (Goblin)
-
Custom script: call AddSaveObjectUnitType()
-
-------- TODO Add them all here --------
-
-------- CREEPS --------
-
-------- Dragons --------
-
Set VariableSet TmpUnitType = Green Dragon Whelp
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Green Drake
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Green Dragon
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Bronze Dragon Whelp
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Bronze Drake
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Bronze Dragon
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Nether Dragon Hatchling
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Nether Drake
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Nether Dragon
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Black Dragon Whelp
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Black Drake
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Black Dragon
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Red Dragon Whelp
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Red Drake
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Red Dragon
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Blue Dragon Whelp
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Blue Drake
-
Custom script: call AddSaveObjectUnitType()
-
Set VariableSet TmpUnitType = Blue Dragon
-
Custom script: call AddSaveObjectUnitType()
-
JASS:
globals
constant integer SAVE_OBJECT_CLASSIFICATION_VALUE = 0
constant integer SAVE_OBJECT_CLASSIFICATION_UNIT = 1
constant integer SAVE_OBJECT_CLASSIFICATION_ITEM = 2
constant integer SAVE_OBJECT_CLASSIFICATION_RESEARCH = 3
string array SaveObjectName
integer array SaveObjectId
integer array SaveCodeObjectClassification
integer SaveObjectTypeCounter = 0
endglobals
function AddSaveObjectType takes string name, integer id, integer classification returns integer
local integer index = SaveObjectTypeCounter
set SaveObjectName[index] = name
set SaveObjectId[index] = id
set SaveCodeObjectClassification[index] = classification
set SaveObjectTypeCounter = SaveObjectTypeCounter + 1
return index
endfunction
function AddSaveObjectUnitType takes nothing returns integer
return AddSaveObjectType(GetObjectName(udg_TmpUnitType), udg_TmpUnitType, SAVE_OBJECT_CLASSIFICATION_UNIT)
endfunction
As you can see I simply increase the counter and give each type a new unique ID. I could use a separate array for each classification like unit, item, research and even building etc. to keep the numbers lower since in my savecodes I know what to expect.
It works but it is a lot of work to add all unit types, item types etc. manually. Is there some way to iterate through all raw code IDs and check certain properties of the object type (maybe by creating a dummy) and then decide whether to add it or not?
Besides, when adding new items or units I will either have to append them or the IDs will change with the next map release and you will load different stuff.
How do save/load systems usually solve this issue?