[Spell] Saving a hero unit with his spells efficiently

Level 5
Joined
Jul 31, 2011
Messages
103
Hi hive!.

I created this thread because need help to create a system to save hero unit with his spells.

I want to access to data like this =>

Hero[0] = Arthas
Hero[0]_spells[0] = Heal
Hero[0]_spells[1] = Armor
Hero[0]_spells[2] = DamageX2

Hero[1] = Madthas
Hero[1]_spells[0] = Damage
Hero[1]_spells[1] = Huge Damage
Hero[1]_spells[2] = Suicide

But dont want use a lot of arrays

I triyed this form either

Hero[id] = Hero
Spells[(hero_id*MaximumNumberOfSpells+1)+spell_index] = Spell(s)

Result

Hero[0] = Arthas
Spells[(0*5)+0] = Heal --> 0
Spells[(0*5)+1] = DamageX2 --> 1
Spells[(0*5)+2] = DamageMaster --> 2
Spells[(0*5)+3] = Anotehr --> 3
Spells[(0*5)+4] = Another --> 4

Hero[1] = Mad
Spells[(1*5)+0] = Heal --> 5
Spells[(2*5)+1] = DamageX2 --> 11
Spells[(3*5)+2] = DamageMaster --> 17
Spells[(4*5)+3] = Anotehr --> 23
Spells[(5*5)+4] = Another --> 29

Is there a more efficient way to save hero and his spells?
 

Dr Super Good

Spell Reviewer
Level 60
Joined
Jan 18, 2005
Messages
26,731
You used the wrong variable... It was meant to do this...

Hero[0] = Arthas
Spells[(0*5)+0] = Heal --> 0
Spells[(0*5)+1] = DamageX2 --> 1
Spells[(0*5)+2] = DamageMaster --> 2
Spells[(0*5)+3] = Anotehr --> 3
Spells[(0*5)+4] = Another --> 4

Hero[1] = Mad
Spells[(1*5)+0] = Heal --> 5
Spells[(1*5)+1] = DamageX2 --> 6
Spells[(1*5)+2] = DamageMaster --> 7
Spells[(1*5)+3] = Anotehr --> 8
Spells[(1*5)+4] = Another --> 9


Hero[2] = DrSuperGood
Spells[(2*5)+0] = Awesome --> 10
Spells[(2*5)+1] = Atomic --> 11
Spells[(2*5)+2] = Great Justice--> 12
Spells[(2*5)+3] = Cool --> 13
Spells[(2*5)+4] = Fail --> 14

Is there a more efficient way to save hero and his spells?
If there is a well defined and reasonable maximum number of spells then this approach is highly efficient and recommended. It is basically a 2D array. Be aware of the 8192 array index maximum.

If the number of spells per hero is not well defined then one has to use a dynamic data structure such as a linked list. This has to be manually implemented as there is no standard functionality for that in the game. Use arrays as dynamic memory, allocating an index per linked list node. Fairly simple if one uses vJASS or other extension languages.

Be aware that extension languages are compile time only. They still produce standard JASS on map save, much like what GUI does.
 
Level 5
Joined
Jul 31, 2011
Messages
103
I just realized you don't want to save a hero, but a hero type.

As chaosy said, you want to use some sort of object oriented programming for that.

So, how's your knowledge of programming?

yes im software engineer, the objective of the object, the objective is to handle more easy the hero and the data, to create some like a super smash bros, with selecting the hero, and later charging the spells, because with another system i manage the casting of the spell of every hero to create combos
 
Top