KlassischeKeplerKriege/game/state/state.hpp

64 lines
1.7 KiB
C++

#pragma once
#include <vector>
#include <queue>
#include <iostream>
#include <glm/vec2.hpp>
namespace game {
class Command;
class Missile;
class Player;
class Planet;
class Ship;
// trace of a missile. exists without a missile at player.
//class Trace {
//public:
// std::vector<glm::vec2> points;
//};
class State {
public:
void init();
void advance(float dt);
// the (network) layer calling these three functions should keep id's
// unique and give one (network) input an id.
void addPlayer(int playerId);
void playerLeft(int playerId);
void commandForPlayer(int playerId, Command *cmd);
// lookup. return nullptr on invalid playerId
Player *playerForId(int playerId);
float maxMissileDistance() const { return m_maxMissileDistance; }
float shipRadius() const { return m_shipRadius; }
std::vector<Planet*> planets;
std::vector<Ship*> ships;
std::vector<Player*> players;
private:
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;
};
};