KlassischeKeplerKriege/game/state/state.hpp

139 lines
4.5 KiB
C++
Raw Normal View History

#pragma once
#include <vector>
#include <list>
#include <queue>
2016-09-28 03:52:23 +00:00
#include <string>
#include <iostream>
#include <glm/vec2.hpp>
#include "missile.hpp"
2016-09-27 20:35:16 +00:00
// TODO:
// give points for equipment / better weapons / more energy when:
// - player discovers the universe
//
// - the shot which made a kill was much longer than the direkt line between
// player and his target
//
// - add wormholes
// - add blackholes
// - shoot through suns which add a fire mantle to the rocket to make it more
// thick and dangerous but it gets destroyed after some time.
namespace game {
// forward declarations
class Command;
class Player;
class Planet;
class Ship;
class Trace;
class Explosion;
class State {
public:
/*************************************************************************/
/* State management */
/*************************************************************************/
// called to setup the state (randomize planets, kill
// traces/missiles/ships etc.)
2016-09-30 12:21:04 +00:00
void init(bool devMode=false);
// main method to advance the simulation by the given timestamp in
// seconds.
void advance(float dt);
/*************************************************************************/
/* 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 03:52:23 +00:00
void clear(int playerId);
void setName(int playerId, std::string name);
void setSpeed(int playerId, double speed);
2016-09-28 01:35:05 +00:00
void quitPlayer(int playerId);
void commandForPlayer(int playerId, Command *cmd);
// lookup. return nullptr on invalid playerId
Player *playerForId(int playerId);
/*************************************************************************/
/* Mixed stuff */
// distance after which missiles get lost in space (and explode)
float maxMissileDistance() const { return m_maxMissileDistance; }
// each ship has the same radius
float shipRadius() const { return m_shipRadius; }
// add a trace to the list of traces.
void addTrace(Trace *trace);
2016-09-27 21:07:11 +00:00
// delete traces with this command
void deleteTrace(Trace *trace); // using a pointer
2016-09-29 06:28:56 +00:00
// get the current time
float timestamp() const { return m_time; }
2016-09-30 12:21:04 +00:00
// check if game is in dev. mode.
// custom commands will then work etc.
bool developerMode() const { return m_developerMode; }
// change the mode.
void setDeveloperMode(bool on)
{
std::cout<<"[state] developer mode is: " << (on ? "on" : "off") << std::endl;
m_developerMode = on;
}
/*************************************************************************/
/* Rendering */
/*************************************************************************/
// Game items which should be rendered are here:
// (access missiles by iterating over player's missiles attribute)
std::vector<Planet*> planets;
std::list<Ship*> ships;
std::list<Player*> players;
std::list<Trace*> traces;
std::list<Explosion*> explosions;
private:
/*************************************************************************/
/* Internal */
/*************************************************************************/
void playerKillsPlayer(Player *killer, Player *victim);
void addExplosionFromHit(const Missile::Event *evt);
2016-09-29 07:32:56 +00:00
void advanceTraceAges(float dt);
void advanceExplosions(float dt);
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-29 06:28:56 +00:00
int m_nextId;
2016-09-27 22:13:03 +00:00
int m_maxNumTraces;
2016-09-29 06:28:56 +00:00
float m_time;
2016-09-30 12:21:04 +00:00
bool m_developerMode;
};
};