diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/base/game.cc | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 7cdc066..c6b45ad 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -201,7 +201,7 @@ void Game::func_give(core::Player *player, const std::string &args) std::string labelstr; if (!player->control()) { - player->send("^WNeed a ship to swap!"); + player->send("^WNeed a ship to swap with!"); } if (!(is >> labelstr)) { @@ -263,10 +263,69 @@ void Game::func_give(core::Player *player, const std::string &args) } player->set_dirty(); player->sound("game/buy"); + + } else if (str.compare("cargo") == 0) { + std::string labelstr; + + if (!player->control()) { + player->send("^WNeed a ship to load cargo!"); + } + + if (!(is >> labelstr)) { + player->send("Usage: give cargo [string] [int]"); + return; + } + + Cargo *cargo = Cargo::find(labelstr); + if (!cargo) { + // enable rcon buffering + sys::ConsoleInterface::instance()->set_rcon(true); + Cargo::list(); + // disable rcon buffering + sys::ConsoleInterface::instance()->set_rcon(false); + + while (sys::ConsoleInterface::instance()->rconbuf().size()) { + player->send((*sys::ConsoleInterface::instance()->rconbuf().begin())); + sys::ConsoleInterface::instance()->rconbuf().pop_front(); + } + + player->send("Unkown cargo type '" + labelstr + "'"); + return; + } else { + int amount = 0; + if (!(is >> amount)) { + amount = -1; + } else { + if (!amount) + return; + } + + const int max = player->control()->inventory()->capacity_available() / cargo->volume(); + if (amount < 0 ) { + amount = max; + } + + if ((amount == 0) || (amount > max)) { + player->send("^WNot enough cargo space available!"); + return; + } + + core::Item *item = player->control()->inventory()->find(cargo); + if (!item) { + item = new core::Item(cargo); + player->control()->inventory()->add(item); + } else { + assert(player->control()->info() == cargo); + } + item->inc_amount(amount); + player->control()->inventory()->set_dirty(); + player->sound("game/buy"); + } } else { - player->send("Usage: give ship [string]"); + player->send("Usage: give cargo [string] [int]"); player->send(" give credits [int]"); + player->send(" give ship [string]"); return; } } |