From e8f7c4a06fce9e41fb23ffc42a566501a78210cb Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 19 Sep 2010 22:49:55 +0000 Subject: player can only sell cargo on bases that allow it, trademenu layout updates --- src/game/base/cargo.cc | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/game/base/cargo.cc') diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc index 536a701..382b03c 100644 --- a/src/game/base/cargo.cc +++ b/src/game/base/cargo.cc @@ -60,7 +60,7 @@ bool Cargo::init() } else if (cargoini.got_key_string("model", str)) { cargo->set_modelname(str); continue; - + } else if (cargoini.got_key_long("price", l)) { cargo->set_price(l); continue; @@ -136,6 +136,7 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int return; } + // seller is the player core::Item *seller_item = seller->inventory()->find(this); if (!seller_item) { if (seller->owner()) { @@ -144,6 +145,13 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int return; } + // 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()); + return; + } + int negotiated_amount = amount; if (negotiated_amount < 0) { negotiated_amount = seller_item->amount(); @@ -151,16 +159,17 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int negotiated_amount = seller_item->amount(); } - int negotiated_price = price(); // base price - core::Item *buyer_item = buyer->inventory()->find(this); - if (buyer_item) { - negotiated_price = buyer_item->price(); - } + int negotiated_price = buyer_item->price(); - seller_item->set_amount(seller_item->amount() - negotiated_amount); + seller_item->dec_amount(negotiated_amount); seller->owner()->set_credits(seller->owner()->credits() + negotiated_price * negotiated_amount); seller->inventory()->set_dirty(); + if (buyer_item->amount() >= 0) { + buyer_item->inc_amount(negotiated_amount); + buyer->inventory()->set_dirty(); + } + // send a cargo purchased message std::stringstream msgstr; msgstr << "^BSold " << negotiated_amount << " " << aux::plural("unit", negotiated_amount) << " of " << name() << " for " << negotiated_price * negotiated_amount << " credits"; @@ -201,7 +210,7 @@ void Cargo::buy(core::EntityControlable *buyer, core::Entity *seller, const int } return; } else { - assert(seller_item->info() == this); + assert(seller_item->info() == this); } int negotiated_amount = amount; @@ -241,13 +250,22 @@ void Cargo::buy(core::EntityControlable *buyer, core::Entity *seller, const int } } - if (negotiated_amount < 0) { + if (negotiated_amount <= 0) { // unlimited amount of zero-cost cargo buyer->owner()->send("^WNo unlimited amounts of zero-cost cargo available!"); return; } - + // if amount is set to -1. the base has a limitless supply + if (seller_item->amount() == 0) { + buyer->owner()->send("^WCargo not available!"); + return; + } else if ((seller_item->amount() > 0) && (negotiated_amount > seller_item->amount())) { + negotiated_amount = seller_item->amount(); + seller_item->dec_amount(negotiated_amount); + seller->inventory()->set_dirty(); + } + // buyer is the player core::Item *buyer_item = buyer->inventory()->find(this); if (!buyer_item) { -- cgit v1.2.3