I'm creating an RTS game where players can click on a missile pod. When selected, an upgrade menu shows to upgrade the missle pod with more missiles and at the same time they can right-click places on the map to shoot the missiles out of the selected missile pod. I'm trying to manage the best way to relate this data.
//base class
class GameState()
{
virtual void Run() = 0;
};
class GameState_Play // High level view of the running game.
class GameState_In_Game// Performs basic things like adding resources over time, performs input for GUI and world (this selects buildings)
class GameState_Upgrade_Menu // Drawing and Input for upgrade menu based on selected object
class GameState_Selected_Object_Actions // Shoot misiles, assign kill orders etc.
So I'm thinking of the best design here because there seem to be a lot of options. Right now all my gamestates can perform sub-tasking GameStates. GameState_Play can be running the GameState_Upgrade_Menu() while also drawing the GameState_Paused() etc.
#1: GameState_Play knows about the selected object and Invokes 2 new game_states: the upgrade menu and the selected objects action. Each of those states receives the selected instance so it knows what actions/menus to display.
#2: Selected object knows it is selected and in it's own update Loop, checks input itself to determine attack orders etc. The GameState_Play invokes the Upgrade Menu.
#3 Selected object knows it is selected and can shoot missiles as well as invoke the upgrade menu itself.
#4... other options.
I personally like #1. The upgrade menu is directy invoked by the game. The selected object knows nothing of the concept of being selected. It is simply given commands from the game.
Secondly though, I have a setup function where you have to place 3 bases before the RTS game starts. So I have GameState_Init and GameState_Play. Both have to render the world, and both have to be able to draw an item where the mouse is located before the player places the purchased item. I'm trying to figure out where to stick this function DrawPurchasedItem() so that either they both have the ability to use it, or figure out how they should interact if GameState_Play is the only one allowed to draw stuff.