How would you implement this?

Started by
4 comments, last by GameDev.net 18 years, 7 months ago
Hi All, I wanted to get some other opinions on the best way to implement the following. . . I have to store the movement orders for a group of ships. There are several groups of ships, and each group can be on the player's side, or the ai's side. Implementation 1 : store the info in a std::map<ShipGroup, MovementOrder> and have 2 maps - 1 for the player's side, and 1 for the Ai's. Implementation 2 : create a data struct with side, shipgroup and movement order and store a vector<DataStruct>. Implementation 3 : I could store all the info in a std::map<ShipGroup, std::map<Side, MovementOrder> > - This seems to be a little more complicated than it should be and i get the feeling there has to be an easier way? Can anyone offer an alternative? AlexS
Advertisement
What are your "movement orders"? Are they coordinates, or an array of values that tell each ship how much to move in which direction?
Well the choice you are facing depends entirely on how you are going to want to acces the ship data. If you are going to constantly want to find a particular ship out of the lot then std::map is your best bet. It is the fasterst for searching. If however this is not the case and yo want to simply iterate through all ships you might as well use the vector.

I wouldn't bother even considering storing a map inside another map.

ace
Sorry guys - i should have said - movement orders are stored in an enum.
Personally, I would store the orders in the group structure [assuming ship groups are the only thing to be ordered]. Orders should be deleted if/when the group is disbanded, and are generally 'owned by' the group.

If the ship group isn't the only thing that can be ordered, I would make a class to handle order addition/storage/handling and then inherit that behavior into stuff that takes orders.
You might consider having only one std::map of all the ship groups / movement orders, and then having a vector of (pointers to?) player ship groups and a vector of (pointers to?) ai ship groups, without any movement info in the vectors. That sounds more natural to me, but you may think differently.

This topic is closed to new replies.

Advertisement