Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

A friend and I are currently looking at developing a game, with similarities to a certain trademarked francise.

To define the units in the game, we've created an abstract class which denotes the 44 variables, and two methods that need to be instantiated with each instance of a unit. The next step in this game would be to of course, define all the units in the game.

Unfortunately, I have 648 units that need to be defined, with 22 final values for each which must be examined at each individual instantiation in the game. For example, if I encounter this unit in the game, I would pass a method its value, and it would look at some sort of defining table which give all these base, final values. The problem we've encountered with this of course, is finding a method of doing this effectively, and securely.

Currently, for testing of other methods, I have a few units defined through enumeration, and have their values stored in an array. My partner has suggest we create a defining class, which will look at a plaintext lookup table. However, I see the problem with such a solution would either be the length, or quantity of lookup tables would be massive. I have searched around, but most solutions entail the use of a server. Our current goal, however is to just release an offline client with everything already defined.

Anyways, I know this was a lot of possible rambling, but... does anyone have any suggestions on how to store 648 units with 22 different final attributes effectively, so that such an entity could be called later and examined? I don't need a thorough code example, but ideas would be helpful. Thanks

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Read in the data from a file. 648 lines of data, one line per unit type. Store that into an array of 648 unit prototypes. Either write the data by hand, or write a tool for it. You might consider writing the values in Excel and exporting a CSV file. (parsing suggestions here.)

Once you have the data in memory as an array of unit prototypes, making units is easy. Create an uninitialised unit instance, look up the relevant unit prototype in the array, and copy the 22 values across.

share|improve this answer
    
Agreed. Storing the data in a compiled or encrypted data file is fine, and you can just take the time to load it in the background at the start of the program, perhaps while the intro screen is showing. –  DGH May 9 '12 at 17:27
2  
648 lines with 22 values in it will probably load in under 50ms, with most of that time spent searching for the file. –  Kylotan May 9 '12 at 18:04
    
Thanks, already started on learning how to work with CSV's. This is kind of what I was looking at doing. Thanks for the answer. –  Bry6n May 10 '12 at 15:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.