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 16:35:26 +0000
committerStijn Buys <ingar@osirion.org>2012-10-20 16:35:26 +0000
commit75274ebd6ba90784f5aa837b7e5ea97fc6bfb720 (patch)
treea5d51a87bf3f20833df18bc40a3254b946716afb /src/game/base/game.cc
parentf01629dc14b1ee05b44d2e38b3dffbc1441fd85f (diff)
Item id based inventory, support for weapon dealers.
Diffstat (limited to 'src/game/base/game.cc')
-rw-r--r--src/game/base/game.cc627
1 files changed, 498 insertions, 129 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 738edca..182c856 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -18,6 +18,7 @@
#include "filesystem/inifile.h"
#include "base/game.h"
#include "base/cargo.h"
+#include "base/cargopod.h"
#include "base/faction.h"
#include "base/navpoint.h"
#include "base/jumppoint.h"
@@ -286,6 +287,11 @@ void Game::func_give(core::Player *player, const std::string &args)
return;
}
+ if (!player->control()) {
+ player->send("^WYou need to join the game first!");
+ return;
+ }
+
std::istringstream is(args);
std::string str;
@@ -295,15 +301,11 @@ void Game::func_give(core::Player *player, const std::string &args)
if (str.compare("ship") == 0) {
std::string labelstr;
- if (!player->control()) {
- player->send("^WYou need to join the game first!");
- return;
- }
-
ShipModel *shipmodel = 0;
if (!(is >> labelstr)) {
player->send("Usage: give ship [string]");
} else {
+ aux::to_label(labelstr);
shipmodel = ShipModel::find(labelstr);
}
@@ -319,7 +321,7 @@ void Game::func_give(core::Player *player, const std::string &args)
sys::ConsoleInterface::instance()->rconbuf().pop_front();
}
- player->send("Unkown ship type '" + labelstr + "'");
+ player->send("Unknown ship type '" + labelstr + "'");
return;
}
@@ -353,6 +355,12 @@ void Game::func_give(core::Player *player, const std::string &args)
ship->set_thrust(player->control()->thrust());
ship->set_state(player->control()->state());
+
+ // remove the old ship from the physics simulation
+ oldship->die();
+ oldship->reset();
+
+ // add the new ship to the physics simulation
ship->reset();
//target_thrust is protected
//ship->target_thrust = player->control()->target_thrust());
@@ -382,15 +390,11 @@ void Game::func_give(core::Player *player, const std::string &args)
} else if (str.compare("cargo") == 0) {
std::string labelstr;
- if (!player->control()) {
- player->send("^WYou need to join the game first!");
- return;
- }
-
Cargo *cargo = 0;
if (!(is >> labelstr)) {
player->send("Usage: give cargo [string] [int]");
- } else {
+ } else {
+ aux::to_label(labelstr);
cargo = Cargo::find(labelstr);
}
@@ -406,22 +410,31 @@ void Game::func_give(core::Player *player, const std::string &args)
sys::ConsoleInterface::instance()->rconbuf().pop_front();
}
- player->send("Unkown cargo type '" + labelstr + "'");
+ player->send("Unknown cargo type '" + labelstr + "'");
return;
} else {
int amount = 0;
if (!(is >> amount)) {
- amount = -1;
+ amount = 1;
} else {
if (!amount)
return;
}
+
+ int max = 0;
+ if (cargo->volume()) {
+ max = (int)floorf(player->control()->inventory()->capacity_available() / cargo->volume());
+ } else {
+ max = amount;
+ if (max < 1) {
+ max = 1;
+ }
+ }
- const int max = (int)floorf(player->control()->inventory()->capacity_available() / cargo->volume());
- if (amount < 0 ) {
+ if (amount < 0) {
amount = max;
}
-
+
if ((amount == 0) || (amount > max)) {
player->send("^WNot enough cargo space available!");
return;
@@ -435,21 +448,19 @@ void Game::func_give(core::Player *player, const std::string &args)
assert(item->info() == cargo);
}
item->inc_amount(amount);
+
player->control()->inventory()->set_dirty();
- player->sound("game/buy");
+ player->control()->owner()->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 {
+ } else {
+ aux::to_label(labelstr);
weapon = Weapon::find(labelstr);
}
@@ -465,29 +476,59 @@ void Game::func_give(core::Player *player, const std::string &args)
sys::ConsoleInterface::instance()->rconbuf().pop_front();
}
- player->send("Unkown weapon type '" + labelstr + "'");
+ player->send("Unknown weapon type '" + labelstr + "'");
return;
- } else {
- core::Item *item = 0;
- int amount = 1;
-
- if (player->control()->inventory()->capacity_available() < weapon->volume()) {
+ } else {
+ int amount = 0;
+ if (!(is >> amount)) {
+ amount = 1;
+ } else {
+ if (!amount)
+ return;
+ }
+
+ int max = 0;
+ if (weapon->volume()) {
+ max = (int)floorf(player->control()->inventory()->capacity_available() / weapon->volume());
+ } else {
+ max = amount;
+ if (max < 1) {
+ max = 1;
+ }
+ }
+ if (amount < 0) {
+ if (weapon->stackable()) {
+ amount = max;
+ } else {
+ amount = 1;
+ }
+ }
+
+ if ((amount == 0) || (amount > max)) {
player->send("^WNot enough cargo space available!");
return;
}
+ core::Item *item = 0;
+
if (weapon->stackable()) {
item = player->control()->inventory()->find(weapon);
- }
-
- if (!item) {
- item = new core::Item(weapon);
- player->control()->inventory()->add(item);
+ if (!item) {
+ item = new core::Item(weapon);
+ player->control()->inventory()->add(item);
+ } else {
+ assert(item->info() == weapon);
+ }
+ item->inc_amount(amount);
} else {
- assert(item->info() == weapon);
- }
+ for (int n = 0; n < amount; n++) {
+ item = new core::Item(weapon);
+ item->set_flag(core::Item::Unique);
+ item->set_amount(1);
+ player->control()->inventory()->add(item);
+ }
+ }
- item->inc_amount(amount);
player->control()->inventory()->set_dirty();
player->sound("game/buy");
}
@@ -496,7 +537,7 @@ void Game::func_give(core::Player *player, const std::string &args)
player->send("Usage: give cargo [string] [int]");
player->send(" give credits [int]");
player->send(" give ship [string]");
- player->send(" give weapon [string]");
+ player->send(" give weapon [string] [int]");
return;
}
}
@@ -615,100 +656,302 @@ void Game::func_specs(core::Player *player, const std::string &args)
}
-// sell request from a player
+// sell items on a base
void Game::func_sell(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;
}
- std::istringstream is(args);
- std::string typestr;
- std::string labelstr;
-
- if (!(is >> typestr)) {
- player->send("Usage: sell [string] [string] [int] sell an item: specify type, label and amount");
+ Ship *seller = static_cast<Ship *>(player->control());
+
+ // must be docked to buy items
+ if ((seller->state() != core::Entity::Docked) || (!seller->dock())) {
+ player->send("^WYou need to be docked!");
return;
- } else {
- aux::to_label(typestr);
}
-
- if (!(is >> labelstr)) {
- player->send("Usage: sell [string] [string] [int] sell an item: specify type, label and amount");
+
+ core::Entity *buyer = seller->dock();
+
+ // can only buy at planets and stations
+ if ((buyer->moduletype() != station_enttype) && (buyer->moduletype() != planet_enttype)) {
+ player->send("^WCan not sell here");
+ return;
+ }
+
+ if (!seller->inventory() || !buyer->inventory()) {
+ player->send("^WCan not sell here");
return;
- } else {
- aux::to_label(labelstr);
}
+ core::Item *seller_item = 0;
+ core::Item *buyer_item = 0;
+ unsigned int id = 0;
int amount = 0;
- if (!(is >> amount))
- amount = 0;
-
- if (typestr.compare("cargo") == 0) {
- Cargo *cargo = Cargo::find(labelstr);
- if (cargo) {
- cargo->sell(player->control(), player->view(), amount);
+
+ std::istringstream is(args);
+ if (is >> id >> amount) {
+
+ seller_item = seller->inventory()->find(id);
+ if (!seller_item) {
+ std::stringstream msgstr;
+ msgstr << "^WItem " << id << " not in inventory";
+ player->send(msgstr.str());
+ return;
+ }
+
+ if (amount == 0) {
+ player->send("^WNo amount specified");
+ return;
+ }
+
+ if (seller_item->info()->type() == Cargo::infotype()) {
+ // cargo has to be in demand
+ buyer_item = buyer->inventory()->find(seller_item->info());
+ if (!buyer_item) {
+ player->send("^W" + buyer->name() + " ^Bdoes not buy " + seller_item->info()->name());
+ return;
+ }
+ } else if (seller_item->info()->type() == Weapon::infotype()) {
+ // weapons can be sold anywhere
+ if (!seller_item->unique()) {
+ buyer_item = buyer->inventory()->find(seller_item->info());
+ }
+ if (!buyer_item) {
+ buyer_item = new core::Item(seller_item->info());
+ buyer_item->set_flags(seller_item->flags());
+ buyer->inventory()->add(buyer_item);
+ }
} else {
- player->send("Unkown cargo type '" + labelstr + "'");
+ player->send("^W" + buyer->name() + " ^Bdoes not buy " + seller_item->info()->name());
+ return;
+ }
+
+ if (amount < 0) {
+ amount = seller_item->amount();
+ } else if (amount > seller_item->amount()) {
+ amount = seller_item->amount();
+ }
+
+ int price = buyer_item->price();
+
+ seller_item->dec_amount(amount);
+ seller->owner()->set_credits(seller->owner()->credits() + price * amount);
+ seller->owner()->set_dirty();
+ seller->inventory()->set_dirty();
+
+ if (buyer_item->amount() >= 0) {
+ buyer_item->inc_amount(amount);
+ buyer->inventory()->set_dirty();
+ }
+
+ if (seller_item->amount() == 0) {
+ seller->inventory()->erase(seller_item->id());
+ seller->inventory()->set_dirty();
+ seller_item = 0;
}
+
+ // send a cargo sold message
+ std::stringstream msgstr;
+ if (buyer_item->unique()) {
+ msgstr << "^BSold " << buyer_item->info()->name();
+ } else {
+ msgstr << "^BSold " << amount << " " << aux::plural("unit", amount) << " of " << buyer_item->info()->name() << " for " << price * amount << " credits";
+ }
+ player->send(msgstr.str());
+ player->sound("game/buy");
} else {
- player->send("Unkown item type '" + typestr + "'");
+ player->send("Usage: sell [id] [amount] sell item from inventory");
}
- return;
}
-// buy request from a player
+// buy items on a base
void Game::func_buy(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;
}
- std::istringstream is(args);
- std::string typestr;
- std::string labelstr;
-
- if (!(is >> typestr)) {
- player->send("Usage: buy [string] [string] [int] buy an item: specify type, label and amount");
+ Ship *ship = static_cast<Ship *>(player->control());
+
+ // must be docked to buy items
+ if ((ship->state() != core::Entity::Docked) || (!ship->dock())) {
+ player->send("^WYou need to be docked!");
return;
- } else {
- aux::to_label(typestr);
}
-
- if (!(is >> labelstr)) {
- player->send("Usage: buy [string] [string] [int] buy an item: specify type, label and amount");
+
+ core::Entity *seller = ship->dock();
+
+ // can only buy at planets and stations
+ if ((seller->moduletype() != station_enttype) && (seller->moduletype() != planet_enttype)) {
+ player->send("^WCan not buy here");
+ return;
+ }
+
+ if (!ship->inventory() || !seller->inventory()) {
+ player->send("^WCan not buy here");
return;
- } else {
- aux::to_label(labelstr);
}
+ core::Item *item = 0;
+ unsigned int id = 0;
int amount = 0;
- if (!(is >> amount))
- amount = 0;
+
+ std::istringstream is_int(args);
+ if (is_int >> id >> amount) {
+
+ // item id based buy
+ item = seller->inventory()->find(id);
+ if (!item) {
+ std::stringstream msgstr;
+ msgstr << "^WItem " << id << " not in seller inventory";
+ player->send(msgstr.str());
+ return;
+ }
+
+ if (item->info()->type() == ShipModel::infotype()) {
+ ShipModel *shipmodel = ShipModel::find(item->info()->label());
+ if (shipmodel) {
+ shipmodel->buy(player->control(), player->view());
+ }
+ return;
+
+ } else if ((item->info()->type() == Cargo::infotype()) || (item->info()->type() == Weapon::infotype())) {
+
+ int price = item->price();
+ long cash = player->credits();
+
+ if (item->unique()) {
+ amount = 1;
+ }
+
+ // check if the player has enough cash
+ if (price > 0) {
+
+ // negative amount means 'as much as possible'
+ if (amount < 0) {
+ amount = cash / price;
+ }
+
+ // maximum amount the player can afford
+ if (cash < (amount * price)) {
+ amount = cash / price;
+ }
+
+ if (amount < 1) {
+ player->send("^WCan not afford transaction!");
+ return;
+ }
+ }
+
+ // check cargo size - ignore zero volume cargo
+ if (item->info()->volume() > 0 ) {
+
+ // maximum cargo size
+ if (amount * item->info()->volume() > ship->inventory()->capacity_available()) {
+ amount = (int)floorf(ship->inventory()->capacity_available() / item->info()->volume());
+ }
+
+ if (amount < 1) {
+ player->send("^WNot enough cargo space available!");
+ return;
+ }
+ }
+
+ if (amount <= 0) {
+ // unlimited amount of zero-cost cargo
+ player->send("^WUnlimited amounts of free items are not supported!");
+ return;
+ }
+
+ // if amount is set to -1. the base has an unlimited supply
+ if (item->amount() == 0) {
+ player->send("^W" + item->info()->name() + " not available!");
+ return;
+
+ } else if (item->amount() > 0) {
+
+ if (amount > item->amount()) {
+ amount = item->amount();
+ }
+ }
+
+ // buyer is the player
+ core::Item *buyer_item = 0;
+ if (!item->unique()) {
+ buyer_item = ship->inventory()->find(item->info());
+ }
+ if (!buyer_item) {
+ buyer_item = new core::Item(item->info());
+ buyer_item->set_flags(item->flags());
+ ship->inventory()->add(buyer_item);
+ }
+
+ // update buyer inventory
+ buyer_item->inc_amount(amount);
+ ship->inventory()->set_dirty();
+ player->set_credits(player->credits() - price * amount);
+ player->set_dirty();
+
+ // update seller inventory
+ if (item->amount() >= 0) {
+ item->dec_amount(amount);
+ seller->inventory()->set_dirty();
+ }
+
+ if (item->info()->type() == Weapon::infotype()) {
+ if (item->amount() == 0) {
+ seller->inventory()->erase(item->id());
+ seller->inventory()->set_dirty();
+ }
+ }
+
+ // send a message to the player
+ std::stringstream msgstr;
+ if (buyer_item->unique()) {
+ msgstr << "^BPurchased a " << buyer_item->info()->name();
+ } else {
+ msgstr << "^BPurchased " << amount << " " << aux::plural("unit", amount) << " of " << buyer_item->info()->name() << " for " << price * amount << " credits";
+ }
+ player->send(msgstr.str());
+ player->sound("game/buy");
+ } else {
+ player->send("^WCan not buy " + item->info()->name());
+ }
+
+ } else {
+
+ std::istringstream is(args);
+ std::string typestr;
+ std::string labelstr;
- if (typestr.compare("ship") == 0) {
- ShipModel *shipmodel = ShipModel::find(labelstr);
- if (shipmodel) {
- shipmodel->buy(player->control(), player->view());
+ if (!(is >> typestr >> labelstr)) {
+ player->send("Usage: buy ship [ship label] buy a ship from a base");
+ player->send("Usage: buy [id] [amount] buy from base inventory");
+ return;
} else {
- player->send("Unkown ship type '" + labelstr + "'");
+ aux::to_label(typestr);
+ aux::to_label(labelstr);
}
- } else if (typestr.compare("cargo") == 0) {
- Cargo *cargo = Cargo::find(labelstr);
- if (cargo) {
- cargo->buy(player->control(), player->view(), amount);
+
+ if (typestr.compare("ship") == 0) {
+ ShipModel *shipmodel = ShipModel::find(labelstr);
+ if (shipmodel) {
+ shipmodel->buy(player->control(), player->view());
+ } else {
+ player->send("Unknown ship type '" + labelstr + "'");
+ }
} else {
- player->send("Unkown cargo type '" + labelstr + "'");
+ player->send("Unknown item type '" + typestr + "'");
}
- } else {
- player->send("Unkown item type '" + typestr + "'");
}
- return;
}
-// eject cargo request
+// eject item request
void Game::func_eject(core::Player *player, const std::string &args)
{
if (!player->control()) {
@@ -717,44 +960,103 @@ void Game::func_eject(core::Player *player, const std::string &args)
}
std::istringstream is(args);
- std::string typestr;
- std::string labelstr;
-
- if (!(is >> typestr)) {
- player->send("Usage: eject [string] [string] [int] eject an item: specify type, label and amount");
+ unsigned int id;
+
+ if (!(is >> id)) {
+ player->send("Usage: eject [id] [int] eject inventory item, amount");
return;
- } else {
- aux::to_label(typestr);
}
-
- if (g_devel->value()) {
- if (typestr.compare("mine") == 0) {
- SpaceMine::eject(player->control());
- return;
+
+ int amount = 0;
+ if (!(is >> amount))
+ amount = -1;
+
+ if (!amount) {
+ return;
+ }
+
+ core::EntityControlable *ejector = player->control();
+
+ // cannot eject while jumping
+ if ((ejector->state() == core::Entity::Jump) || (ejector->state() == core::Entity::JumpInitiate)) {
+ if (ejector->owner()) {
+ ejector->owner()->send("^WCan not eject while hyperspace jump drive is active");
}
+ return;
}
-
- if (!(is >> labelstr)) {
- player->send("Usage: eject [string] [string] [int] eject an item: specify type, label and amount");
+
+ // find the item in the inventory
+ core::Item *item = ejector->inventory()->find(id);
+ if (!item) {
+ if (ejector->owner()) {
+ std::stringstream msgstr;
+ msgstr << "^WItem " << id << " not in inventory";
+ ejector->owner()->send(msgstr.str());
+ }
return;
- } else {
- aux::to_label(labelstr);
+ }
+ if (!item->amount()) {
+ if (ejector->owner()) {
+ ejector->owner()->send("^WYou do not own any " + item->info()->name());
+ }
+ return;
+ }
+
+ if ((amount < 0) || (amount > item->amount())) {
+ amount = item->amount();
}
-
- int amount = 0;
- if (!(is >> amount))
- amount = 0;
+ item->dec_amount(amount);
- if (typestr.compare("cargo") == 0) {
- Cargo *cargo = Cargo::find(labelstr);
- if (cargo) {
- cargo->eject(player->control(), amount);
- } else {
- player->send("Unkown cargo type '" + labelstr + "'");
+ if (ejector->state() == core::Entity::Docked) {
+ if (ejector->owner()) {
+ std::stringstream msgstr;
+ msgstr << "^BDestroyed " << amount << " " << aux::plural("unit", amount) << " of " << item->info()->name();
+ ejector->owner()->send(msgstr.str());
+ ejector->owner()->sound("fx/eject");
}
- } else {
- player->send("Unkown item type '" + typestr + "'");
+ } else {
+ // create cargo pod
+ CargoPod *pod = new CargoPod();
+
+ if (item->unique() && item->info()->modelname().size()) {
+ pod->set_modelname(item->info()->modelname());
+ }
+ pod->set_color(ejector->color());
+ pod->set_color_second(ejector->color_second());
+ pod->set_location(ejector->location() + ejector->axis().up() * (ejector->radius() + pod->radius()));
+ pod->set_axis(ejector->axis());
+ pod->set_zone(ejector->zone());
+ pod->set_info(item->info());
+
+ // add loot to inventory
+ pod->add_inventory();
+ pod->inventory()->set_capacity(item->info()->volume() * amount);
+
+ core::Item *loot = new core::Item(item->info());
+ loot->set_amount(amount);
+ loot->set_flags(item->flags());
+
+ pod->inventory()->add(loot);
+ pod->inventory()->set_dirty();
+
+ if (ejector->owner()) {
+ std::stringstream msgstr;
+ if (item->unique()) {
+ msgstr << "^BEjected " << item->info()->name();
+ } else {
+ msgstr << "^BEjected " << amount << " " << aux::plural("unit", amount) << " of " << item->info()->name();
+ }
+ ejector->owner()->send(msgstr.str());
+ ejector->owner()->sound("fx/eject");
+ }
+
+ pod->reset();
+ }
+
+ if (item->amount() == 0) {
+ ejector->inventory()->erase(item->id());
}
+ ejector->inventory()->set_dirty();
}
// beam in nearby cargo pods
@@ -792,12 +1094,14 @@ void Game::func_beam(core::Player *player, const std::string &args)
}
if (negotiated_amount > 0) {
- core::Item *iteminv = inventory->find(item->info());
+ core::Item *iteminv = 0;
+ if (!item->has_flag(core::Item::Unique)) {
+ 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);
@@ -1101,7 +1405,7 @@ Game::~Game()
Cargo::done();
// clear Weapon
- Weapon::clear();
+ Weapon::done();
// clear ShipModel
ShipModel::done();
@@ -1189,6 +1493,7 @@ bool Game::load_zone(core::Zone *zone)
// set zone defaults
zone->set_color(0.5f);
zone->set_ambient_color(0.1f);
+ zone->set_sky("default");
std::string inifilename("ini/zones/");
inifilename.append(zone->label());
@@ -1326,6 +1631,22 @@ bool Game::load_zone(core::Zone *zone)
}
}
+ } else if (zoneini.got_section("weapon")) {
+ // new weapon trading definition for the current base
+ item = 0;
+ inventory = 0;
+
+ if (!entity) {
+ zoneini.unknown_error("weapon definition without entity");
+ } else if ((entity->moduletype() != planet_enttype) && (entity->moduletype() != station_enttype)) {
+ zoneini.unknown_error("weapon definition for invalid entity type");
+ } else {
+ inventory = entity->inventory();
+ if (!inventory) {
+ inventory = entity->add_inventory();
+ }
+ }
+
} else {
zoneini.unknown_section();
}
@@ -1544,7 +1865,7 @@ bool Game::load_zone(core::Zone *zone)
}
} else if (zoneini.in_section("cargo")) {
- // cargo definition for a station or planet
+ // cargo trade definition for a station or planet
if (!entity || !inventory) {
continue;
}
@@ -1574,9 +1895,44 @@ bool Game::load_zone(core::Zone *zone)
} else {
zoneini.unknown_key();
}
+
+ } else if (zoneini.in_section("weapon")) {
+ // weapon trade definition for a station or planet
+ if (!entity || !inventory) {
+ continue;
+ }
+
+ if (zoneini.got_key_label("label", strval)) {
+ Weapon *weapon = Weapon::find(strval);
+ if (weapon) {
+ item = inventory->find(weapon);
+ if (!item) {
+ item = new core::Item(weapon);
+ item->set_amount(-1);
+ item->set_price(weapon->price());
+ if (!weapon->stackable()) {
+ item->set_flag(core::Item::Unique);
+ }
+ inventory->add(item);
+ }
+ } else {
+ zoneini.unknown_error("unknown weapon type '" + strval + "'");
+ }
+
+ } else if (zoneini.got_key_long("price", l)) {
+ if (item) {
+ item->set_price(l);
+ }
+ } else if (zoneini.got_key_long("amount", l)) {
+ if (item) {
+ item->set_amount(l);
+ }
+ } else {
+ zoneini.unknown_key();
+ }
} else if (zoneini.in_section("ship")) {
- // ship definition for a station or planet
+ // ship trade definition for a station or planet
if (!entity || !inventory) {
continue;
}
@@ -1686,7 +2042,8 @@ bool Game::generate_entity_menus(core::Entity *entity)
if (entity->inventory()) {
entity->set_flag(core::Entity::KeepAlive);
size_t nbcargo = 0;
- size_t nbships = 0;
+ size_t nbweapon = 0;
+ size_t nbships = 0;
for (core::Inventory::Items::const_iterator it = entity->inventory()->items().begin(); it != entity->inventory()->items().end(); it++) {
core::Item *item = (*it);
@@ -1694,6 +2051,9 @@ bool Game::generate_entity_menus(core::Entity *entity)
if (item->info()->type() == Cargo::infotype()) {
nbcargo++;
+ } else if (item->info()->type() == Weapon::infotype()) {
+ nbweapon++;
+
} else if (item->info()->type() == ShipModel::infotype()) {
if (!menu_dealer) {
menu_dealer = new MenuDescription();
@@ -1723,6 +2083,15 @@ bool Game::generate_entity_menus(core::Entity *entity)
button->set_alignment(ButtonDescription::Center);
menu_main->add_button(button);
}
+
+ if (nbweapon > 0) {
+ con_debug << " " << entity->label() << " " << nbcargo << " weapon " << aux::plural("type", nbweapon) << std::endl;
+ button = new ButtonDescription();
+ button->set_text("Weapon Dealer");
+ button->set_command("trade weapon", ButtonDescription::CommandMenu);
+ button->set_alignment(ButtonDescription::Center);
+ menu_main->add_button(button);
+ }
if (nbships > 0) {
con_debug << " " << entity->label() << " " << nbships << " ship " << aux::plural("type", nbships) << std::endl;