diff options
Diffstat (limited to 'src/game/game.cc')
-rw-r--r-- | src/game/game.cc | 120 |
1 files changed, 106 insertions, 14 deletions
diff --git a/src/game/game.cc b/src/game/game.cc index f0fd190..290b80c 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -17,15 +17,22 @@ namespace game { +ShipModel *default_shipmodel; /*----- engine game functions ------------------------------------- */ -/// a player joins the game +// list the ship model registry +void func_list_ship(std::string const &args) +{ + ShipModel::list(); +} + +// a player joins the game void func_join(core::Player *player, std::string const &args) { if (player->control()) return; - player->player_control = new Ship(player, "vector"); + player->player_control = new Ship(player, default_shipmodel); player->control()->entity_color = player->color(); std::string message(player->name()); @@ -57,25 +64,38 @@ void func_spectate(core::Player *player, std::string const &args) /// a player buys a ship void func_buy(core::Player *player, std::string const &args) { - if (!player->control()) { - return; - } - + std::string shipname; + std::string helpstr; std::istringstream is(args); is >> shipname; - if ((shipname == "vector") || (shipname == "canasta")) { + + ShipModel *shipmodel = 0; + for (std::list<ShipModel *>::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) { + if (shipname == (*smit)->modelname()) { + shipmodel = (*smit); + break; + } + + if (helpstr.size()) + helpstr += '|'; + helpstr.append((*smit)->modelname()); + } + + if (shipmodel) { // player has only ship for now - player->player_control->die(); - player->player_control = 0; - - player->player_control = new Ship(player, shipname); + if (player->control()) { + player->player_control->die(); + player->player_control = 0; + } + + player->player_control = new Ship(player, shipmodel); player->control()->entity_color = player->color(); - core::server()->broadcast(player->name() + " purchased a " + shipname); + core::server()->broadcast(player->name() + " purchased a " + shipmodel->name()); player->player_dirty = true; } else { - core::server()->send(player, "Usage: buy <canasta|vector>"); + core::server()->send(player, "Usage: buy <" + helpstr + ">"); } } /*----- Game ------------------------------------------------------ */ @@ -95,6 +115,8 @@ void Game::init() module_running = false; + ShipModel::clear(); + // setup the game world filesystem::IniFile f; f.open("world"); @@ -242,11 +264,75 @@ void Game::init() alexandria->entity_modelname = "stations/alexandria"; */ + // read ship model specifications + f.open("ships"); + if (!f.is_open()) + return; + + ShipModel *shipmodel = 0; + default_shipmodel = 0; + + while (f.getline()) { + if (f.got_key()) { + if (f.section() == "ship") { + + if (f.got_key_string("name", tmp)) { + shipmodel->shipmodel_name = tmp; + + } else if (f.got_key_string("model", tmp)) { + shipmodel->shipmodel_modelname = tmp; + + } else if (f.got_key_string("default", tmp)) { + + default_shipmodel = shipmodel; + + } else if (f.got_key_string("acceleration", tmp)) { + std::istringstream is(tmp); + float a; + if (is >> a) { + shipmodel->shipmodel_acceleration = a; + } + + } else if (f.got_key_string("maxspeed", tmp)) { + std::istringstream is(tmp); + float ms; + if (is >> ms) { + shipmodel->shipmodel_maxspeed = ms; + } + + } else if (f.got_key_string("turnspeed", tmp)) { + + std::istringstream is(tmp); + float ts; + if (is >> ts) { + shipmodel->shipmodel_turnspeed = ts; + } + + } else + con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl; + } + } else if (f.got_section("ship")) { + shipmodel = new ShipModel(); + + } else if (f.got_section()) { + con_warn << f.name() << " unknown section '" << f.section() << "' at line " << f.line() << std::endl; + } + } + f.close(); + + if (!default_shipmodel) { + con_error << "No default ship model\n"; + return; + } + // add engine game functions core::Func::add("buy", (core::GameFuncPtr) func_buy); core::Func::add("join", (core::GameFuncPtr) func_join); core::Func::add("spectate", (core::GameFuncPtr) func_spectate); - + + // add engine core functions + core::Func::add("list_ship", (core::FuncPtr) func_list_ship); + // add engine 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); @@ -257,6 +343,12 @@ void Game::init() void Game::shutdown() { + // game functions are automaticly removed + + // remove engine core functions + core::Func::remove("list_ship"); + + ShipModel::clear(); module_running = false; } |