Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-08 13:13:37 +0000
committerStijn Buys <ingar@osirion.org>2008-03-08 13:13:37 +0000
commitada8263817ed45e29d4bd63ab0ac635a83eec4f8 (patch)
treebb71900cdb1a4578f1a04632f1c4e0269709cb0a /src/game
parente0e457510bdd59bbbc77a4f80611066285d39193 (diff)
game reads world.ini
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cc132
1 files changed, 109 insertions, 23 deletions
diff --git a/src/game/game.cc b/src/game/game.cc
index 77e534f..f0fd190 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -13,7 +13,7 @@
#include "sys/sys.h"
#include "math/mathlib.h"
#include "filesystem/filesystem.h"
-
+#include "filesystem/inifile.h"
namespace game
{
@@ -25,7 +25,7 @@ void func_join(core::Player *player, std::string const &args)
if (player->control())
return;
- player->player_control = new Ship(player, "micron_vector");
+ player->player_control = new Ship(player, "vector");
player->control()->entity_color = player->color();
std::string message(player->name());
@@ -64,7 +64,7 @@ void func_buy(core::Player *player, std::string const &args)
std::string shipname;
std::istringstream is(args);
is >> shipname;
- if ((shipname == "micron_vector") || (shipname == "canasta")) {
+ if ((shipname == "vector") || (shipname == "canasta")) {
// player has only ship for now
player->player_control->die();
player->player_control = 0;
@@ -75,7 +75,7 @@ void func_buy(core::Player *player, std::string const &args)
core::server()->broadcast(player->name() + " purchased a " + shipname);
player->player_dirty = true;
} else {
- core::server()->send(player, "Usage: buy <canasta|micron_vector>");
+ core::server()->send(player, "Usage: buy <canasta|vector>");
}
}
/*----- Game ------------------------------------------------------ */
@@ -96,11 +96,89 @@ void Game::init()
module_running = false;
// setup the game world
-
- // the star
- Star *star = new Star();
- star->entity_location = Vector3f(256.0f, -256.0f, 0.0f);
- star->entity_name = "star: Sabishi Hoshi";
+ filesystem::IniFile f;
+ f.open("world");
+
+ if (!f.is_open()) {
+ return;
+ }
+
+ Star *star = 0;
+ core::Entity *entity = 0;
+ std::string tmp;
+
+ while (f.getline()) {
+ if (f.got_key()) {
+ if (f.section() == "star") {
+
+ if (f.got_key_string("name", tmp)) {
+ star->entity_name = tmp;
+
+ } else if (f.got_key_string("model", tmp)) {
+ star->entity_modelname = tmp;
+
+ } else if (f.got_key_string("location", tmp)) {
+ std::istringstream is(tmp);
+ float x, y, z;
+ if ((is >> x) && (is >> y) && (is >> z)) {
+ star->entity_location = math::Vector3f(x,y,z);
+ }
+
+ } else if (f.got_key_string("color", tmp)) {
+ std::istringstream is(tmp);
+ float r, g, b;
+ if ((is >> r) && (is >> g) && (is >> b)) {
+ star->entity_color = math::Color(r, g, b);
+ }
+ } else
+ con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
+
+ } else if (f.section() == "entity") {
+
+ if (f.got_key_string("name", tmp)) {
+ entity->entity_name = tmp;
+
+ } else if (f.got_key_string("model", tmp)) {
+ entity->entity_modelname = tmp;
+
+ } else if (f.got_key_string("direction", tmp)) {
+ std::istringstream is(tmp);
+ float a;
+ if (is >> a) {
+ entity->entity_direction = math::degrees360f(a);
+ }
+
+ } else if (f.got_key_string("location", tmp)) {
+ std::istringstream is(tmp);
+ float x, y, z;
+ if ((is >> x) && (is >> y) && (is >> z)) {
+ entity->entity_location = math::Vector3f(x,y,z);
+ }
+
+ } else if (f.got_key_string("color", tmp)) {
+ std::istringstream is(tmp);
+ float r, g, b;
+ if ((is >> r) && (is >> g) && (is >> b)) {
+ entity->entity_color = math::Color(r, g, b);
+ }
+
+ } else {
+ con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
+ }
+ }
+ } else if (f.got_section("star")) {
+ //con_debug << "[star] section" << std::endl;
+ star = new Star();
+
+ } else if (f.got_section("entity")) {
+ //con_debug << "[entity] section" << std::endl;
+ entity = new core::Entity();
+
+ } else if (f.got_section()) {
+ con_warn << f.name() << " unknown section '" << f.section() << "' at line " << f.line() << std::endl;
+ }
+ }
+ f.close();
// the green cube
core::Entity *cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
@@ -120,6 +198,27 @@ void Game::init()
cube->entity_modelname = "cube";
cube->entity_moduletypeid = cube_enttype;
+ // the yellow sphere
+ 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, 32.0f, 0.0f);
+ sphere->entity_name ="sphere: The Sphere";
+
+ // the galactic origin
+ 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";
+
+ /*
+
+ // the star
+ Star *star = new Star();
+ star->entity_location = Vector3f(256.0f, -256.0f, 0.0f);
+ star->entity_name = "star: Sabishi Hoshi";
+
// Canasta
cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
cube->entity_shape = core::Entity::Diamond;
@@ -141,20 +240,7 @@ void Game::init()
alexandria->entity_location = Vector3f(0.0f, -64.0f, 0.0f);
alexandria->entity_name = "station: Alexandria";
alexandria->entity_modelname = "stations/alexandria";
-
- // the yellow sphere
- 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, 32.0f, 0.0f);
- sphere->entity_name ="sphere: The Sphere";
-
- // the galactic origin
- 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 engine game functions
core::Func::add("buy", (core::GameFuncPtr) func_buy);