Sign in to follow this  

How would you implement this?

This topic is 4492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites

This topic is 4492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this