• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Ways to manage inventory

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

Is it better to have a virtual inventory and equip items through that (assuming units can have inventories but not be allowed to pick up items, so you just add the item via trigger), or is it better just to use the values in the item objects (e.g. level) to determine whether a unit can equip them?

Better yet, would I lose any performance if I created my own representation of an item (e.g. ItemStruct) and then made a table of these. Then when a hero picks up an item, I search for the appropriate ItemStruct entry and check to see if the hero can equip it. If the hero fails the conditions, then the hero obviously drops it.

Or should I be clever and manipulate the fields in the item object (level, type, etc.) to do this?

I'd like to go for the latter approach because it's more robust and easier to modify. I could even use the level of the item to make the look up time in the ItemStruct array constant (its level corresponds to its position in the array).
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
What kinds of rules do you have for picking up items? The usual stuff like every hero can only use one weapon, one helmet etc. can be done using item classifications.
If your rules are more complicated you might want to trigger them. Then the approach with a hashtable where you look up the itemtypes requirements make sense.

What i do is, i have a struct for both items and itemtypes and each item gets a struct attached when its created. Now the items struct has a reference to its itemtype. The itemtype is a struct where you can store arbitrary information like requirements, etc...
But this is a less "lightweight" approach, if you only need to manage item requirements you should just use the hashtable thingy.
 
Status
Not open for further replies.
Top