diff options
author | Stijn Buys <ingar@osirion.org> | 2012-10-14 10:11:53 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-10-14 10:11:53 +0000 |
commit | fdd6655f2ce1fa5332c5e23f1a76e25e26733a61 (patch) | |
tree | c4b322e886edd911a63605e0d71162e6b53ad654 /src/game | |
parent | 5227a260a893c0562f93f994f6b94b310ddc4f73 (diff) |
Added "give weapon" function.
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/base/game.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index b19ec52..56719b9 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -438,11 +438,65 @@ void Game::func_give(core::Player *player, const std::string &args) player->control()->inventory()->set_dirty(); player->sound("game/buy"); } + } else if (str.compare("weapon") == 0) { + std::string labelstr; + + if (!player->control()) { + player->send("^WYou need to join the game first!"); + return; + } + + Weapon *weapon = 0; + if (!(is >> labelstr)) { + player->send("Usage: give weapon [string] [int]"); + } else { + weapon = Weapon::find(labelstr); + } + + if (!weapon) { + // enable rcon buffering + sys::ConsoleInterface::instance()->set_rcon(true); + Weapon::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 weapon type '" + labelstr + "'"); + return; + } else { + core::Item *item = 0; + int amount = 1; + + if (player->control()->inventory()->capacity_available() < weapon->volume()) { + player->send("^WNot enough cargo space available!"); + return; + } + + if (weapon->stackable()) { + item = player->control()->inventory()->find(weapon); + } + + if (!item) { + item = new core::Item(weapon); + player->control()->inventory()->add(item); + } else { + assert(item->info() == weapon); + } + + item->inc_amount(amount); + player->control()->inventory()->set_dirty(); + player->sound("game/buy"); + } } else { player->send("Usage: give cargo [string] [int]"); player->send(" give credits [int]"); player->send(" give ship [string]"); + player->send(" give weapon [string]"); return; } } |