Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/game.cc')
-rw-r--r--src/game/game.cc193
1 files changed, 55 insertions, 138 deletions
diff --git a/src/game/game.cc b/src/game/game.cc
index a9d5a6e..fb0d917 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -7,7 +7,6 @@
#include <vector>
#include "game/game.h"
-#include "game/sector.h"
#include "game/ship.h"
#include "game/star.h"
#include "core/entity.h"
@@ -19,36 +18,32 @@ namespace game
{
/// a player joins the game
-void func_join(core::Player &player, std::stringstream &args)
+void func_join(core::Player *player, std::string const &args)
{
- if (player.control)
+ if (player->control)
return;
- Ship *ship = new Ship();
- ship->location = math::Vector3f(0,0,0);
- ship->label = "ship: <" + player.name + "> Micron Vector";
- ship->owner = &player;
- player.control = ship;
-
+ player->control = new Ship(player);
+
std::ostringstream osstream;
- osstream << player.name << " joins the game";
- core::message_broadcast(osstream.str(), player.id);
+ 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::stringstream &args)
+void func_spectate(core::Player *player, std::string const &args)
{
- if (!player.control)
+ if (!player->control)
return;
std::ostringstream osstream;
- osstream << player.name << " spectates";
- core::message_broadcast(osstream.str(), player.id);
+ osstream << player->name() << " spectates";
+ core::message_broadcast(osstream.str(), player->id());
- if (player.control) {
+ if (player->control) {
// player has only ship for now
- core::entity::remove(player.control->id);
- player.control = 0;
+ core::Entity::remove(player->control->id());
+ player->control = 0;
}
}
@@ -64,118 +59,48 @@ bool Game::init()
{
using math::Vector3f;
using math::Color;
- //using filesystem::IniFile;
con_print << "Initializing game..." << std::endl;
con_print << " " << name() << std::endl;
- /*
- // read game.ini
- IniFile f;
- f.open("ini/game.ini");
- while (f) {
- f.getline();
- if (f.got_key()) {
- if (f.section() == "game") {
- // game::name
- if (f.got_key_string("name", name)); else
- // game::label
- if (f.got_key_string("label", label)); else
- // game::author
- if (f.got_key_string("author", author)); else
- // unknown value
- con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
- }
- } else if (f.got_section("game")) {
-
- } else if (f.got_section()) {
- con_warn << f.name() << " unknown section '" << f.section() << "' at line " << f.line() << std::endl;
- }
- }
- f.close();
-
- con_print << name << std::endl;
- con_print << "by " << author << std::endl;
-
- // read world.ini
- std::string tmp;
- Sector *sector =0;
-
- f.open("ini/world.ini");
- while (f) {
- f.getline();
- if (f.got_key()) {
- if (f.section() == "world") {
- // world::name
- if (f.got_key_string("name", tmp)); else
- // world:label
- if (f.got_key_string("label", tmp)); else
- // unknown value
- con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
- } else if (f.section() == "sector") {
- // sector::name
- if (f.got_key_string("name", tmp)) {
- sector->name = tmp;
- } else
- // sector:label
- if (f.got_key_string("label", tmp)) {
- sector->label = tmp;
- } else
- // unknown value
- con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
- }
- } else if (f.got_section("world")) {
- //con_debug << "[world] section" << std::endl;
- } else if (f.got_section("sector")) {
- sector = new Sector();
- sectors.push_back(sector);
- } else if (f.got_section()) {
- con_warn << f.name() << " unknown section '" << f.section() << "' at line " << f.line() << std::endl;
- }
- }
- f.close();
-
-
- con_print << "Loading sectors..." << std::endl;
- for (unsigned n =0; n < sectors.size(); n++)
- con_print << " " << sectors[n]->label << " " << sectors[n]->name << std::endl;
- */
-
// set up some stuff in the game world
Star *star = new Star();
- star->location = Vector3f(256.0f, 0.0f, 256.0f);
- star->label = "star: Sabishi Hoshi";
-
- core::Entity *cube = new core::Entity(core::entity::Solid & core::entity::Static);
- cube->core_shape = core::entity::Cube;
- cube->core_color = Color(0.0f, 0.8f, 0.0f);
- cube->location = Vector3f(24.0f, 0.0f, -24.0f);
- cube->label ="cube: Borg cube green";
- cube->type = cube_enttype;
-
- cube = new core::Entity(core::entity::Solid & core::entity::Static);
- cube->core_shape = core::entity::Cube;
- cube->core_color = Color(1.0f, 0.0f, 0.0f);
- cube->location = Vector3f(16.0f, 0.0f, -16.0f);
- cube->label ="cube: Borg cube red";
- cube->type = cube_enttype;
-
- core::Entity *sphere = new core::Entity(core::entity::Solid & core::entity::Static);
- sphere->core_shape = core::entity::Sphere;
- sphere->core_color = Color(0.8f, 0.8f, 0.0f);
- sphere->location = Vector3f(0.0f, 0.0f, -32.0f);
- sphere->label ="sphere: The Sphere";
-
- core::Entity *axis = new core::Entity(core::entity::Static);
- axis->core_shape = core::entity::Diamond;
- axis->core_color = Color(1.0f, 1.0f, 0.0f);
- axis->location = Vector3f(0, 0, 0);
- axis->label = "axis: Origin";
+ 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", func_join, core::func::Game);
- core::func::add("spectate", func_spectate, core::func::Game);
+ 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;
}
@@ -183,34 +108,26 @@ void Game::shutdown()
{
con_print << "Shutting down game..." << std::endl;
- core::func::remove("join");
- core::func::remove("spectate");
-
- // delete every sector object in the sectors vector
- for (unsigned int n =0; n< sectors.size(); n++) {
- delete sectors[n];
- sectors[n] = 0;
- }
- // clear the sectors vector
- sectors.clear();
+ //core::Func::remove("join");
+ //core::Func::remove("spectate");
}
void Game::frame(float seconds)
{
}
-void Game::player_connect(core::Player &player)
+void Game::player_connect(core::Player *player)
{
- std::stringstream args;
- game::func_spectate(player, args);
+ std::string args;
+ func_spectate(player, args);
}
-void Game::player_disconnect(core::Player &player)
+void Game::player_disconnect(core::Player *player)
{
- if (player.control) {
+ if (player->control) {
// player has only one ship for now
- core::entity::remove(player.control->id);
- player.control = 0;
+ core::Entity::remove(player->control->id());
+ player->control = 0;
}
}