By the way, when you say Mechwarrior, do you mean Battletech? Mechwarrior is the roleplaying game, while Battletech is the table top game. If you're replicating the table top game, I assume you have the rulebook with you, so it's kind of surprising that you'd mix the two up...
Anyway, is there a particular reason why you'd be programming in pure C? Even if you don't use the object oriented programming aspects of C++, it still offers many advantages.
Okay, suppose you are programming in C. You'd still want to learn how to use structures. It may seem like a simple idea but they are powerful and will really help your code make sense.
Anyway, enough of that. Onto your problem! You claim to have the grid problem figured out so I'll leave that to you (although your example of the two dimensional array suggests that you don't understand your grid problem but, whatever--listen to Yakk advice!).
You should probably notice that 6 * 12 &ne 146 variables. Anyway, there are two ways you can go about this. The static way (which you seem keen on) and the dynamic way. Lets start with the static way.
You have a structure for each limb. Each limb structure will have an array big enough for the maximum number of items for that limb (I happen to know that not all limbs can have 12 items). If these items have state (they can be destroyed or have ammo) then the elements of this array are, themselves, structures that contain the necessary info, like item type (although this would mean they'd all have to carry this info, even if it doesn't apply--like ammo for your lasers). The static method has the dubious claim of being simpler but, as you have pointed out, allocates a lot of resources (although it's highly unlikely that you don't have these resources). After all, a limb has a static array big enuogh for twelve items, even if it is only equiped with one!
Now, lets look at the dynamic way. Each limb can be a structure that will have a linked list of items. Just like the static way, if the items have state, this will be a linked list of structures that contain state info of each item. Because these are linked lists, they will only allocate resources that are needed. After all, if your mech is fully loaded with 146 (or however many) items, then you really do need 146 slots, right! There's no getting around that... But at least you'll only using the resoures you need and that is the best solution you can get for your concerns of using up too many resources.
If you are intimidated by the use of structures or don't know what a linked list is, then may I kindly suggest that you don't know enough about programming to really implement a game as sophisticated as Battlemech. Practice a little more with simpler projects and this stuff will become second nature to you...
Good luck!
|