2016-09-27 16:23:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <glm/vec2.hpp>
|
|
|
|
|
|
|
|
namespace game {
|
2016-09-27 18:13:09 +00:00
|
|
|
// forward declarations
|
2016-09-27 16:23:58 +00:00
|
|
|
class Command;
|
|
|
|
class Missile;
|
|
|
|
class Player;
|
|
|
|
class Planet;
|
|
|
|
class Ship;
|
2016-09-27 18:13:09 +00:00
|
|
|
class Trace;
|
2016-09-27 16:23:58 +00:00
|
|
|
|
|
|
|
class State {
|
|
|
|
public:
|
2016-09-27 18:13:09 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* State management */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
// called to setup the state (randomize planets, kill
|
|
|
|
// traces/missiles/ships etc.)
|
2016-09-27 16:23:58 +00:00
|
|
|
void init();
|
2016-09-27 18:13:09 +00:00
|
|
|
|
|
|
|
// main method to advance the simulation by the given timestamp in
|
|
|
|
// seconds.
|
2016-09-27 16:23:58 +00:00
|
|
|
void advance(float dt);
|
|
|
|
|
2016-09-27 18:13:09 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* Network / Input */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
// The upper layer (network/renderer) calling these three functions
|
|
|
|
// should keep id's unique and give one (network) input an id.
|
2016-09-27 23:48:34 +00:00
|
|
|
int addPlayer();
|
2016-09-28 01:35:05 +00:00
|
|
|
void quitPlayer(int playerId);
|
2016-09-27 16:23:58 +00:00
|
|
|
void commandForPlayer(int playerId, Command *cmd);
|
|
|
|
|
|
|
|
// lookup. return nullptr on invalid playerId
|
|
|
|
Player *playerForId(int playerId);
|
|
|
|
|
2016-09-27 18:13:09 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* Mixed stuff */
|
|
|
|
|
|
|
|
// distance after which missiles get lost in space (and explode)
|
2016-09-27 16:23:58 +00:00
|
|
|
float maxMissileDistance() const { return m_maxMissileDistance; }
|
2016-09-27 18:13:09 +00:00
|
|
|
|
|
|
|
// each ship has the same radius
|
2016-09-27 16:23:58 +00:00
|
|
|
float shipRadius() const { return m_shipRadius; }
|
|
|
|
|
2016-09-27 18:13:09 +00:00
|
|
|
// add a trace to the list of traces.
|
|
|
|
void addTrace(Trace *trace);
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Rendering */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
// Game items which should be rendered are here:
|
|
|
|
// (access missiles by iterating over player's missiles attribute)
|
2016-09-27 16:23:58 +00:00
|
|
|
std::vector<Planet*> planets;
|
|
|
|
std::vector<Ship*> ships;
|
|
|
|
std::vector<Player*> players;
|
2016-09-27 18:13:09 +00:00
|
|
|
std::vector<Trace*> traces;
|
2016-09-27 16:23:58 +00:00
|
|
|
|
|
|
|
private:
|
2016-09-27 18:13:09 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* Internal */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2016-09-27 16:23:58 +00:00
|
|
|
void playerKillsPlayer(Player *killer, Player *victim);
|
|
|
|
|
|
|
|
void advancePlayerShipSpawns(float dt);
|
|
|
|
void advancePlayerCommands(float dt);
|
|
|
|
void advancePlayerMissiles(float dt);
|
|
|
|
|
|
|
|
// try to spawn a ship for this player.
|
|
|
|
// return true on success, false on failure to find a spot.
|
|
|
|
bool spawnShipForPlayer(Player *player);
|
|
|
|
|
|
|
|
// find some place where nothing is placed nearby (ships/planets).
|
|
|
|
// usefule for spanwing things
|
|
|
|
bool findFreePositionWithRadius(float r, glm::vec2 &pos);
|
|
|
|
|
|
|
|
float m_maxMissileDistance;
|
|
|
|
float m_playerRespawnTime;
|
|
|
|
float m_shipRadius;
|
|
|
|
float m_defaultEnergy;
|
2016-09-27 23:48:34 +00:00
|
|
|
int m_nextId=0;
|
2016-09-27 16:23:58 +00:00
|
|
|
};
|
|
|
|
};
|