diff options
Diffstat (limited to 'src/game/game.cc')
-rw-r--r-- | src/game/game.cc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/game/game.cc b/src/game/game.cc index 4aa505d..7dc342a 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -25,7 +25,7 @@ void func_join(core::Player *player, std::string const &args) if (player->control()) return; - player->player_control = new Ship(player); + player->player_control = new Ship(player, "micron_vector"); player->control()->entity_color = player->color(); std::string message(player->name()); @@ -54,6 +54,30 @@ void func_spectate(core::Player *player, std::string const &args) player->player_dirty = true; } +/// a player buys a ship +void func_buy(core::Player *player, std::string const &args) +{ + if (!player->control()) { + return; + } + + std::string shipname; + std::istringstream is(args); + is >> shipname; + if ((shipname == "micron_vector") || (shipname == "canasta")) { + // player has only ship for now + player->player_control->die(); + player->player_control = 0; + + player->player_control = new Ship(player, shipname); + player->control()->entity_color = player->color(); + + core::server()->broadcast(player->name() + " purchased a " + shipname); + } + if (!shipname.size()) { + core::server()->send(player, "Usage: buy <micron_vector|canasta>"); + } +} /*----- Game ------------------------------------------------------ */ Game::Game() : core::Module("Project::OSiRiON") @@ -127,9 +151,10 @@ void Game::init() axis->entity_name = "axis: Origin"; // 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 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); |