/* game/game.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include #include "game/game.h" #include "game/ship.h" #include "game/star.h" #include "core/entity.h" #include "sys/sys.h" #include "math/mathlib.h" #include "filesystem/filesystem.h" namespace game { /// a player joins the game void func_join(core::Player *player, std::string const &args) { if (player->control) return; player->control = new Ship(player); std::ostringstream osstream; osstream << player->name() << " joins the game"; core::message_broadcast(osstream.str(), player->id()); } /// a player joins the spectators void func_spectate(core::Player *player, std::string const &args) { if (!player->control) return; std::ostringstream osstream; osstream << player->name() << " spectates"; core::message_broadcast(osstream.str(), player->id()); if (player->control) { // player has only ship for now core::Entity::remove(player->control->id()); player->control = 0; } } Game::Game() : core::GameInterface("Project::OSiRiON") { } Game::~Game() { } bool Game::init() { using math::Vector3f; using math::Color; con_print << "Initializing game..." << std::endl; con_print << " " << name() << std::endl; // set up some stuff in the game world Star *star = new Star(); star->entity_location = Vector3f(256.0f, 0.0f, 256.0f); star->entity_name = "star: Sabishi Hoshi"; core::Entity *cube = new core::Entity(core::Entity::Solid & core::Entity::Static); cube->entity_shape = core::Entity::Cube; cube->entity_color = Color(0.0f, 0.8f, 0.0f); cube->entity_location = Vector3f(24.0f, 0.0f, -24.0f); cube->entity_name ="cube: Borg cube green"; cube->entity_moduletypeid = cube_enttype; cube = new core::Entity(core::Entity::Solid & core::Entity::Static); cube->entity_shape = core::Entity::Cube; cube->entity_color = Color(1.0f, 0.0f, 0.0f); cube->entity_location = Vector3f(16.0f, 0.0f, -16.0f); cube->entity_name ="cube: Borg cube red"; cube->entity_moduletypeid = cube_enttype; core::Entity *sphere = new core::Entity(core::Entity::Solid & core::Entity::Static); sphere->entity_shape = core::Entity::Sphere; sphere->entity_color = Color(0.8f, 0.8f, 0.0f); sphere->entity_location = Vector3f(0.0f, 0.0f, -32.0f); sphere->entity_name ="sphere: The Sphere"; core::Entity *axis = new core::Entity(core::Entity::Static); axis->entity_shape = core::Entity::Diamond; axis->entity_color = Color(1.0f, 1.0f, 0.0f); axis->entity_location = Vector3f(0, 0, 0); axis->entity_name = "axis: Origin"; // add game functions core::Func::add("join", (core::GameFuncPtr) func_join); core::Func::add("spectate", (core::GameFuncPtr) func_spectate); // add game variables core::Cvar::set("g_borgcubes", "2", core::Cvar::Game); core::Cvar::set("g_name", name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly); return true; } void Game::shutdown() { con_print << "Shutting down game..." << std::endl; //core::Func::remove("join"); //core::Func::remove("spectate"); } void Game::frame(float seconds) { } void Game::player_connect(core::Player *player) { std::string args; func_spectate(player, args); } void Game::player_disconnect(core::Player *player) { if (player->control) { // player has only one ship for now core::Entity::remove(player->control->id()); player->control = 0; } } } // namespace game