Subsystem: Players - Adam-Poppenheimer/Civ-Clone GitHub Wiki

Players is a fairly small and simple subsystem whose design was strongly influenced by the desire for extensibility. While it doesn't do much itself, it's designed to make adding AI-controlled opponents much easier (a simple matter of switching out the IPlayerBrain). It is not to be confused with Unity's Player, which can refer to a number of systems unrelated to this one.

Players are the agents that control Civilizations. A player controls one and exactly one civilization. When a player is given the opportunity to take its turn, it becomes the only entity that can issue commands or make decisions. When the player is done with their turn, it should relinquish control to the simulation.

Players are implemented via the IPlayer class and its standard implementation, Player. IPlayers are constructed at IPlayerFactory/PlayerFactory from a civilization (which the player will controlling) and an IPlayerBrain (which determines what that control will look like). A player is given freedom to act via the IPlayerBrain.ExecuteTurn() method. Into that method are passed the player whose turn it is and a C# Action called controlRelinquisher which is supposed to be called when the IPlayerBrain is done with their actions and is ready to end their turn.

There are currently two implementations of IPlayerBrain: HumanPlayerBrain and BarbarianPlayerBrain. HumanPlayerBrain refocuses the camera and subscribes to the PlayerSignals.EndTurnRequested signal, calling controlRelinquisher based on input from the UI.

There are a handful of signals defined in PlayerSignals, some of which handle player creation/destruction, others of which are implementation-agnostic signals made when the program detects certain input events for the purposes of UI. There's a good chance those signals should be moved into a UI subsystem rather than be left in the simulation.