diff options
author | Stijn Buys <ingar@osirion.org> | 2008-12-26 12:21:48 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-12-26 12:21:48 +0000 |
commit | b875124824794a7762414db76ed9f953b8ba320f (patch) | |
tree | 86f27d64e4a9e91a93cb4b30752f27eeec6526ac /src/game | |
parent | bfa10f9990a8a045b03474d11af75984c12a856a (diff) |
default player settings in player.ini,
palette text colors,
cleanups
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/base/game.cc | 120 | ||||
-rw-r--r-- | src/game/base/game.h | 16 | ||||
-rw-r--r-- | src/game/intro/intro.cc | 2 |
3 files changed, 104 insertions, 34 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index c591ba4..8a096b2 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -28,7 +28,23 @@ namespace game { -/* -- class Base static members ----------------------------------- */ +/* -- class Default ----------- ----------------------------------- */ + +// default player settings +core::Zone *Default::zone = 0; +core::Entity *Default::view = 0; +ShipModel *Default::shipmodel = 0; +long Default::credits = 0; + +void Default::clear() +{ + zone = 0; + view = 0; + shipmodel = 0; + credits = 0; +} + +/* -- class Game static members ----------------------------------- */ // game variables core::Cvar *Game::g_impulsespeed = 0; @@ -36,9 +52,6 @@ core::Cvar *Game::g_impulseacceleration = 0; core::Cvar *Game::g_jumppointrange = 0; core::Cvar *Game::g_devel = 0; -core::Zone *Game::default_zone = 0; -ShipModel *Game::default_shipmodel = 0; - core::Module *factory() { return new Game(); @@ -61,7 +74,7 @@ void Game::func_join(core::Player *player, std::string const &args) if (player->control()) return; - Ship *ship = new Ship(player, Game::default_shipmodel); + Ship *ship = new Ship(player, Default::shipmodel); ship->set_zone(player->zone()); player->set_control(ship); @@ -78,7 +91,7 @@ void Game::func_join(core::Player *player, std::string const &args) message.append("^B joins the game."); core::server()->broadcast(message); - player->send("^BYou received " + aux::article(Game::default_shipmodel->name())); + player->send("^BYou received " + aux::article(Default::shipmodel->name())); player->sound("game/buy-ship"); player->player_dirty = true; @@ -100,7 +113,7 @@ void Game::func_spectate(core::Player *player, std::string const &args) } if (!player->zone()) - player->set_zone(Game::default_zone); + player->set_zone(Default::zone); player->set_view(0); } @@ -255,9 +268,7 @@ void Game::func_goto(core::Player *player, const std::string &args) Game::Game() : core::Module("Project::OSiRiON", true) { - default_shipmodel = 0; - default_zone = 0; - + Default::clear(); ShipModel::clear(); if (!load_ships()) { @@ -269,12 +280,17 @@ Game::Game() : core::Module("Project::OSiRiON", true) abort(); return; } + + if (!load_player()) { + abort(); + return; + } // add engine functions core::Func *func = 0; func = core::Func::add("list_ship", Game::func_list_ship); - func->set_info("list ship statistics"); + func->set_info("[string] list ship statistics"); func = core::Func::add("join", Game::func_join); func->set_info("join the game"); @@ -391,11 +407,6 @@ bool Game::load_world() } } - if (!default_zone) { - con_error << "No default zone found!" << std::endl; - return false; - } - return true; } @@ -501,9 +512,6 @@ bool Game::load_zone(core::Zone *zone) } else if (zoneini.got_key_string("sky", strval)) { zone->set_sky(strval); continue; - } else if (zoneini.got_key_bool("default", b)) { - if (b) default_zone = zone; - continue; } else { zoneini.unkown_key(); } @@ -733,18 +741,15 @@ bool Game::load_ships() using math::Vector3f; using math::Color; - default_shipmodel = 0; - filesystem::IniFile shipsini; shipsini.open("ships"); if (!shipsini.is_open()) { - con_error << "Could not open ini/ships.ini!" << std::endl; + con_error << "Could not open " << shipsini.name() << "!" << std::endl; return false; } ShipModel *shipmodel = 0; std::string label; - bool b; long l; float f; @@ -760,9 +765,6 @@ bool Game::load_ships() continue; } else if (shipsini.got_key_string("model", shipmodel->shipmodel_modelname)) { continue; - } else if (shipsini.got_key_bool("default", b)) { - if (b) default_shipmodel = shipmodel; - continue; } else if (shipsini.got_key_long("price", l)) { shipmodel->set_price(l); continue; @@ -788,8 +790,8 @@ bool Game::load_ships() } else if (shipsini.got_section("ship")) { if (shipmodel && !ShipModel::find(shipmodel)) delete shipmodel; shipmodel = new ShipModel(); - if (!default_shipmodel) - default_shipmodel = shipmodel; + if (!Default::shipmodel) + Default::shipmodel = shipmodel; } else if (shipsini.got_section()) { shipsini.unknown_section(); @@ -801,7 +803,65 @@ bool Game::load_ships() con_debug << " " << shipsini.name() << " " << ShipModel::registry.size() << " ship models" << std::endl; - if (!default_shipmodel) { + return true; +} + +// load default player settings +bool Game::load_player() +{ + Default::clear(); + + filesystem::IniFile inifile; + inifile.open("player"); + if (!inifile.is_open()) { + con_error << "Could not open " << inifile.name() << "!" << std::endl; + return false; + } + + long l; + std::string str; + + while (inifile.getline()) { + + if (inifile.got_section()) { + + if (inifile.got_section("player")) { + continue; + } else { + inifile.unknown_section(); + } + + } else if (inifile.got_key()) { + + if (inifile.in_section("player")) { + if (inifile.got_key_long("credits", l)) { + Default::credits = l; + } else if (inifile.got_key_string("zone", str)) { + aux::to_label(str); + Default::zone = core::Zone::find(str); + } else if (inifile.got_key_string("ship", str)) { + aux::to_label(str); + Default::shipmodel = ShipModel::find(str); + } + } + } + } + + inifile.close(); + + if (!Default::zone) { + con_error << "No default zone found!\n"; + return false; + } + + if (!Default::zone->default_view()) { + con_error << "Zone '" << Default::zone->label() << "' has no default view!\n"; + return false; + } + + Default::view = Default::zone->default_view(); + + if (!Default::shipmodel) { con_error << "No default ship model found!\n"; return false; } @@ -818,7 +878,7 @@ void Game::frame(float seconds) void Game::player_connect(core::Player *player) { std::string args; - player->set_zone(default_zone); + player->set_zone(Default::zone); player->set_view(0); // not docked func_spectate(player, args); diff --git a/src/game/base/game.h b/src/game/base/game.h index caeb50a..9f31f4f 100644 --- a/src/game/base/game.h +++ b/src/game/base/game.h @@ -32,6 +32,17 @@ const unsigned int jumppoint_enttype = 260; const unsigned int jumpgate_enttype = 261; const unsigned int station_enttype = 262; +/// default player settings +class Default { +public: + static core::Zone *zone; + static core::Entity *view; + static ShipModel *shipmodel; + static long credits; + + static void clear(); +}; + /// the base Project::OSiRiON game model class Game : public core::Module { public: @@ -72,9 +83,8 @@ private: bool load_menus(core::Entity *entity, const std::string &menufilename); bool load_ships(); - - static core::Zone *default_zone; - static ShipModel *default_shipmodel; + + bool load_player(); /* ---- engine functions ----------------------------------- */ diff --git a/src/game/intro/intro.cc b/src/game/intro/intro.cc index edb80d4..3fafa0f 100644 --- a/src/game/intro/intro.cc +++ b/src/game/intro/intro.cc @@ -19,7 +19,7 @@ core::Module *factory() return new Intro(); } -Intro::Intro() : core::Module("Introduction", false) +Intro::Intro() : core::Module("Project::OSiRiON", false) { if (!load_world()) { abort(); |