Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-10-15 14:19:28 +0000
committerStijn Buys <ingar@osirion.org>2010-10-15 14:19:28 +0000
commit2e7da03760895cb8438d53f8ab74bd2b5193ffe2 (patch)
tree135b309ab977328531d496b0d7072fd720b3fdc6 /src/game
parentc3097a768077fa9251a70de10bd29aff3c8553e1 (diff)
beam / eject cargo updates
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/cargo.cc14
-rw-r--r--src/game/base/game.cc68
-rw-r--r--src/game/base/game.h1
-rw-r--r--src/game/base/planet.cc2
4 files changed, 79 insertions, 6 deletions
diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc
index cc358f6..3571b22 100644
--- a/src/game/base/cargo.cc
+++ b/src/game/base/cargo.cc
@@ -330,7 +330,7 @@ void Cargo::eject(core::EntityControlable *ejector, const int amount)
}
item->dec_amount(negotiated_amount);
- ejector->owner()->set_dirty();
+ ejector->inventory()->set_dirty();
if (!ejector->state() == core::Entity::Docked) {
std::stringstream msgstr;
@@ -342,8 +342,7 @@ void Cargo::eject(core::EntityControlable *ejector, const int amount)
return;
}
- // create cargo pod
-
+ // create cargo pod
CargoPod *pod = new CargoPod();
pod->set_color(ejector->color());
@@ -351,10 +350,15 @@ void Cargo::eject(core::EntityControlable *ejector, const int amount)
pod->set_zone(ejector->zone());
pod->set_location(ejector->location() + ejector->axis().up() * ejector->radius());
pod->set_axis(ejector->axis());
-
+
+ // add loot to inventory
pod->set_inventory(new core::Inventory());
pod->inventory()->set_capacity(item->info()->volume() * negotiated_amount);
- pod->inventory()->add(new core::Item(*item));
+
+ core::Item *loot = new core::Item(item->info());
+ loot->set_amount(negotiated_amount);
+
+ pod->inventory()->add(loot);
pod->inventory()->set_dirty();
if (ejector->owner()) {
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");
diff --git a/src/game/base/game.h b/src/game/base/game.h
index f4ce8c0..3f67a25 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -111,6 +111,7 @@ private:
static void func_sell(core::Player *player, const std::string &args);
static void func_give(core::Player *player, const std::string &args);
static void func_eject(core::Player *player, const std::string &args);
+ static void func_beam(core::Player *player, const std::string &args);
};
/// factory function
diff --git a/src/game/base/planet.cc b/src/game/base/planet.cc
index ad1aa47..7a648db 100644
--- a/src/game/base/planet.cc
+++ b/src/game/base/planet.cc
@@ -37,7 +37,7 @@ void Planet::dock(core::Entity *entity)
Ship * ship = static_cast<Ship *>(entity);
- // fixed 50 km docking radius
+ // fixed 5 km docking radius
if (math::distance(location(), ship->location()) > radius() + ship->radius() + 50.0f) {
if (ship->owner())
ship->owner()->send("Planet out of range");