Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base/game.cc')
-rw-r--r--src/game/base/game.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index b426989..3c84d58 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -478,6 +478,71 @@ void Game::func_eject(core::Player *player, const std::string &args)
}
}
+// beam in nearby cargo pods
+void Game::func_beam(core::Player *player, const std::string &args)
+{
+ const float beam_range_squared = 5.0f * 5.0f;
+
+ if (!player->control())
+ return;
+
+ if (player->control()->state() != core::Entity::Normal)
+ return;
+
+ core::Zone *zone = player->control()->zone();
+ core::Inventory *inventory = player->control()->inventory();
+
+ // entity iterator
+ for (core::Zone::Content::iterator eit = zone->content().begin(); eit != zone->content().end(); eit++) {
+ // if the entity is a cargo pod and within beaming range
+ if (((*eit)->moduletype() == cargopod_enttype) && (math::distancesquared(player->control()->location(), (*eit)->location()) <= beam_range_squared)) {
+ core::Inventory *loot = (*eit)->inventory();
+ if (!inventory || !loot)
+ continue;
+
+ // item iterator
+ int loot_left = 0;
+ for (core::Inventory::Items::iterator iit = loot->items().begin(); iit != loot->items().end(); iit++) {
+ core::Item *item = (*iit);
+ int negotiated_amount = item->amount();
+
+ assert(item->info());
+
+ if (inventory->capacity_available() < negotiated_amount * item->info()->volume()) {
+ negotiated_amount = (int) floorf( inventory->capacity_available() / item->info()->volume());
+ }
+
+ if (negotiated_amount > 0) {
+ core::Item *iteminv = inventory->find(item->info());
+ if (!iteminv) {
+ iteminv = new core::Item(item->info());
+ inventory->add(iteminv);
+ }
+
+ item->dec_amount(negotiated_amount);
+ iteminv->inc_amount(negotiated_amount);
+
+ // this will recalculate inventory capacity
+ inventory->set_dirty();
+ loot->set_dirty();
+
+ std::stringstream msgstr;
+ msgstr << "^BBeamed in " << negotiated_amount << " " << aux::plural("unit", negotiated_amount) << " of " << item->info()->name();
+ player->send(msgstr.str());
+ player->sound("game/beam");
+ }
+
+ loot_left += item->amount();
+ }
+
+ // if there's no loot left, the cargo pod will be destroyed
+ if (!loot_left) {
+ (*eit)->die();
+ }
+ }
+ }
+}
+
// launch request
void Game::func_launch(core::Player *player, std::string const &args)
{
@@ -665,6 +730,9 @@ Game::Game() : core::Module("Project::OSiRiON", true)
func = core::Func::add("eject", Game::func_eject);
func->set_info("[string] [string] [int] eject an item from inventory: specify type, label and amount");
+
+ func = core::Func::add("beam", Game::func_beam);
+ func->set_info("beam nearby cargo pods in");
func = core::Func::add("give", Game::func_give);
func->set_info("cheat functions");