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>2010-09-19 22:49:55 +0000
committerStijn Buys <ingar@osirion.org>2010-09-19 22:49:55 +0000
commite8f7c4a06fce9e41fb23ffc42a566501a78210cb (patch)
tree3adf0b1f3eae778e9645450d0e51821142f7983b /src/game/base
parentcc18095cded14f5e7e3f049e47fca2224134b647 (diff)
player can only sell cargo on bases that allow it, trademenu layout updates
Diffstat (limited to 'src/game/base')
-rw-r--r--src/game/base/cargo.cc38
-rw-r--r--src/game/base/game.cc16
2 files changed, 40 insertions, 14 deletions
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) {
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 83d0be8..803657d 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -227,6 +227,10 @@ void Game::func_give(core::Player *player, const std::string &args)
}
Ship * ship = new Ship(player, shipmodel);
+ core::Entity *view = player->view();
+ if (view && (view == player->control())) {
+ view = ship;
+ }
// FIME move this into a method in the Ship class
ship->set_zone(player->control()->zone());
@@ -235,12 +239,12 @@ void Game::func_give(core::Player *player, const std::string &args)
ship->get_axis().assign(player->control()->axis());
ship->set_speed(player->control()->speed());
ship->set_thrust(player->control()->thrust());
+ //target_thrust is protected
+ //ship->target_thrust = player->control()->target_thrust());
- if (player->view() == player->control()) {
- player->set_view(ship);
- }
player->remove_asset(player->control());
player->set_control(ship);
+ player->set_view(view);
player->sound("game/buy-ship");
@@ -983,7 +987,11 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
} else if (inifile.got_key_long("price", l)) {
if (item) {
item->set_price(l);
- }
+ }
+ } else if (inifile.got_key_long("amount", l)) {
+ if (item) {
+ item->set_amount(l);
+ }
} else {
inifile.unkown_key();
}