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/cargo.cc')
-rw-r--r--src/game/base/cargo.cc85
1 files changed, 78 insertions, 7 deletions
diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc
index 668c3a4..cc358f6 100644
--- a/src/game/base/cargo.cc
+++ b/src/game/base/cargo.cc
@@ -9,6 +9,7 @@
#include "base/game.h"
#include "base/cargo.h"
+#include "base/cargopod.h"
#include "filesystem/inifile.h"
#include "auxiliary/functions.h"
#include "sys/sys.h"
@@ -121,7 +122,7 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int
// can only sell at planets and stations
if ((buyer->moduletype() != station_enttype) && (buyer->moduletype() != planet_enttype)) {
- seller->owner()->send("^BCan not sell here");
+ seller->owner()->send("^WCan not sell here");
return;
}
@@ -129,7 +130,7 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int
return;
if (!buyer->inventory() || !seller->inventory()) {
- seller->owner()->send("^BCan not sell here");
+ seller->owner()->send("^WCan not sell here");
return;
}
@@ -141,7 +142,7 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int
core::Item *seller_item = seller->inventory()->find(this);
if (!seller_item) {
if (seller->owner()) {
- seller->owner()->send("^BYou do not own any " + name());
+ seller->owner()->send("^WYou do not own any " + name());
}
return;
}
@@ -149,7 +150,7 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int
// buyer is the station or planer
core::Item *buyer_item = buyer->inventory()->find(this);
if (!buyer_item) {
- seller->owner()->send("^B" + buyer->name() + " ^Bdoes not buy " + name());
+ seller->owner()->send("^W" + buyer->name() + " ^Bdoes not buy " + name());
return;
}
@@ -188,7 +189,7 @@ void Cargo::buy(core::EntityControlable *buyer, core::Entity *seller, const int
// can only buy at planets and stations
if ((seller->moduletype() != station_enttype) && (seller->moduletype() != planet_enttype)) {
- buyer->owner()->send("^BCan not buy here");
+ buyer->owner()->send("^WCan not buy here");
return;
}
@@ -196,7 +197,7 @@ void Cargo::buy(core::EntityControlable *buyer, core::Entity *seller, const int
return;
if (!buyer->inventory() || !seller->inventory()) {
- buyer->owner()->send("^BCan not buy here");
+ buyer->owner()->send("^WCan not buy here");
return;
}
@@ -208,7 +209,7 @@ void Cargo::buy(core::EntityControlable *buyer, core::Entity *seller, const int
core::Item *seller_item = seller->inventory()->find(this);
if (!seller_item) {
if (buyer->owner()) {
- buyer->owner()->send("^B" + seller->name() + " ^Bdoes not sell " + name());
+ buyer->owner()->send("^W" + seller->name() + " ^Bdoes not sell " + name());
}
return;
} else {
@@ -294,6 +295,76 @@ void Cargo::buy(core::EntityControlable *buyer, core::Entity *seller, const int
buyer->owner()->sound("game/buy");
}
+// main 'eject cargo' function
+void Cargo::eject(core::EntityControlable *ejector, const int amount)
+{
+ if (!ejector->inventory()) {
+ return;
+ }
+
+ if (!amount) {
+ return;
+ }
+
+ // find the cargo in the inventory
+ core::Item *item = ejector->inventory()->find(this);
+ if (!item || !item->amount()) {
+ if (ejector->owner()) {
+ ejector->owner()->send("^WYou do not own any " + name());
+ }
+ return;
+ } else {
+ assert(item->info() == this);
+ }
+
+ int negotiated_amount = amount;
+ if (negotiated_amount < 0) {
+ negotiated_amount = item->amount();
+ } else if (negotiated_amount > item->amount()) {
+ if (ejector->owner()) {
+ std::stringstream msgstr;
+ msgstr << "^WYou only own " << item->amount() << " " << aux::plural("unit", negotiated_amount) << " of " << name();
+ ejector->owner()->send(msgstr.str());
+ }
+ return;
+ }
+
+ item->dec_amount(negotiated_amount);
+ ejector->owner()->set_dirty();
+
+ if (!ejector->state() == core::Entity::Docked) {
+ std::stringstream msgstr;
+ if (ejector->owner()) {
+ msgstr << "^BDestroyed " << negotiated_amount << " " << aux::plural("unit", negotiated_amount) << " of " << name();
+ ejector->owner()->send(msgstr.str());
+ ejector->owner()->sound("game/eject");
+ }
+ return;
+ }
+
+ // create cargo pod
+
+ CargoPod *pod = new CargoPod();
+
+ pod->set_color(ejector->color());
+ pod->set_color_second(ejector->color_second());
+ pod->set_zone(ejector->zone());
+ pod->set_location(ejector->location() + ejector->axis().up() * ejector->radius());
+ pod->set_axis(ejector->axis());
+
+ pod->set_inventory(new core::Inventory());
+ pod->inventory()->set_capacity(item->info()->volume() * negotiated_amount);
+ pod->inventory()->add(new core::Item(*item));
+ pod->inventory()->set_dirty();
+
+ if (ejector->owner()) {
+ std::stringstream msgstr;
+ msgstr << "^BEjected " << negotiated_amount << " " << aux::plural("unit", negotiated_amount) << " of " << name();
+ ejector->owner()->send(msgstr.str());
+ ejector->owner()->sound("game/eject");
+ }
+}
+
void Cargo::list()
{
core::Info::list(cargo_infotype);