Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-10-20 18:24:35 +0000
committerStijn Buys <ingar@osirion.org>2012-10-20 18:24:35 +0000
commitdb69f96fbf5ac5321bdcb1e86ff07d1e35de9fec (patch)
treebc997c204e36807cc61736d971ec48d9826117b9 /src/game/base/game.cc
parent75274ebd6ba90784f5aa837b7e5ea97fc6bfb720 (diff)
Added func_drop, added spacemine template.
Diffstat (limited to 'src/game/base/game.cc')
-rw-r--r--src/game/base/game.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 182c856..c87c9b6 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -951,6 +951,81 @@ void Game::func_buy(core::Player *player, const std::string &args)
}
}
+// drop item requests
+void Game::func_drop(core::Player *player, const std::string &args)
+{
+ // must be joined to buy items
+ if (!player->control()) {
+ player->send("^WYou need to join the game first!");
+ return;
+ }
+
+ Ship *ship = static_cast<Ship *>(player->control());
+
+ // cannot be docked to drop items
+ if (ship->state() == core::Entity::Docked) {
+ player->send("^WCan't drop items while docked!");
+ return;
+ }
+
+ // cannot drop items while jumping
+ if ((ship->state() == core::Entity::Jump) || (ship->state() == core::Entity::JumpInitiate)) {
+ player->send("^WCan not eject while hyperspace jump drive is active");
+ return;
+ }
+
+ std::istringstream is(args);
+ std::string labelstr;
+
+ if (!(is >> labelstr)) {
+ player->send("Usage: drop [label] drop an item");
+ return;
+ } else {
+ aux::to_label(labelstr);
+ }
+
+ if (labelstr.compare("mine") == 0) {
+ // drop a mine
+
+ // find a mine in inventory
+ core::Item *item = 0;
+ for (core::Inventory::Items::iterator it = ship->inventory()->items().begin(); (!item) && (it != ship->inventory()->items().end()); it++) {
+ if ((*it)->info()->type() == Weapon::infotype()) {
+ const Weapon *weapon = static_cast<const Weapon *>((*it)->info());
+
+ if (weapon->subtype() == Weapon::Mine) {
+ item = (*it);
+ }
+ }
+ }
+
+ if (!item) {
+ player->send("^WNo mines in inventory!");
+ return;
+ }
+
+ // create a spacemine entity
+ SpaceMine *spacemine = new SpaceMine(item->info());
+ spacemine->set_color(ship->color());
+ spacemine->set_color_second(ship->color_second());
+ spacemine->set_location(ship->location() + ship->axis().forward() * -1.0f * (ship->radius() + spacemine->radius()));
+ spacemine->set_axis(ship->axis());
+ spacemine->set_zone(ship->zone());
+ spacemine->set_info(item->info());
+
+ player->send(item->info()->name() + " ejected");
+ player->sound("fx/eject");
+
+ spacemine->reset();
+
+ // remove mine from inventory
+ item->set_amount(1);
+ if (item->amount() == 0) {
+ ship->inventory()->erase(item->id());
+ }
+ }
+}
+
// eject item request
void Game::func_eject(core::Player *player, const std::string &args)
{
@@ -1337,6 +1412,9 @@ Game::Game() : core::Module("Project::OSiRiON", true)
func = core::Func::add("sell", Game::func_sell);
func->set_info("[string] [string] [int] sell an item: specify type, label and amount");
+ func = core::Func::add("drop", Game::func_drop);
+ func->set_info("[label] drop an item and activate it");
+
func = core::Func::add("eject", Game::func_eject);
func->set_info("[string] [string] [int] eject an item from inventory: specify type, label and amount");