Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/buymenu.cc13
-rw-r--r--src/game/base/game.cc13
-rw-r--r--src/game/base/shipmodel.cc32
-rw-r--r--src/game/base/shipmodel.h2
4 files changed, 48 insertions, 12 deletions
diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc
index 857e663..c81d80f 100644
--- a/src/client/buymenu.cc
+++ b/src/client/buymenu.cc
@@ -105,13 +105,24 @@ void BuyMenu::set_item(core::Info *info)
menu_buybutton->set_label("buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label());
menu_modelview->show();
-
+
+ /*
+ * NOTE
+ *
+ * client-side is only aware of the price of the item/ship but has no knowledge of any potential refunds
+ * made by the game-side buy function (see game::base::Game::func_buy)
+ * The buy button is always shown, and game-side should send messageboxes where approriate.
+ * */
+ menu_buybutton->show();
+ /*
if (core::localplayer()->credits() < menu_inforecord->price()) {
menu_msgtext->set_text("^1Not enough credits");
menu_msgtext->show();
} else {
menu_buybutton->show();
}
+ */
+
}
menu_infotimestamp = menu_inforecord->timestamp();
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index f802ff2..4703aac 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -1006,7 +1006,7 @@ void Game::func_buy(core::Player *player, const std::string &args)
core::Item *item = 0;
unsigned int id = 0;
- int amount = 0;
+ int amount = 0;
std::istringstream is_int(args);
if (is_int >> id >> amount) {
@@ -1021,9 +1021,18 @@ void Game::func_buy(core::Player *player, const std::string &args)
}
if (item->info()->type() == ShipModel::infotype()) {
+ // buying a ship uses a confirmation messagebox
+ bool confirm = false;
+ std::string strconfirm;
+ if (is_int >> strconfirm) {
+ if (strconfirm.compare("confirm") == 0) {
+ confirm = true;
+ }
+ }
+
ShipModel *shipmodel = ShipModel::find(item->info()->label());
if (shipmodel) {
- shipmodel->buy(player->control(), player->view());
+ shipmodel->buy(player->control(), player->view(), confirm);
}
return;
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index 6fd809b..1edd9d2 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -303,7 +303,7 @@ void ShipModel::list()
}
// a player buys a ship
-void ShipModel::buy(core::EntityControlable *buyer, core::Entity *seller)
+void ShipModel::buy(core::EntityControlable *buyer, core::Entity *seller, bool confirm)
{
if (!buyer || !seller)
return;
@@ -317,7 +317,7 @@ void ShipModel::buy(core::EntityControlable *buyer, core::Entity *seller)
if (!buyer->owner())
return;
- if (!seller->inventory()) {
+ if (!seller->has_flag(core::Entity::Dockable) || !seller->inventory()) {
buyer->owner()->send("^BCan not buy here");
return;
}
@@ -335,25 +335,41 @@ void ShipModel::buy(core::EntityControlable *buyer, core::Entity *seller)
assert(seller_item->info() == this);
}
+ // possible refund
+ const long refund = 0;
+
+ // check price
+ if (price() - refund > player->credits()) {
+ std::ostringstream ostr;
+ ostr << "You need another " << (price() - refund - player->credits()) << " credits to buy a " << name() << "!";
+ player->messagebox(ostr.str().c_str(), "Close");
+ return;
+ }
+
// check if there's enough space available to transfer inventory
if (player->control() && (maxcargo() < player->control()->inventory()->capacity_used())) {
- player->send("^WNot enough cargo space to transfer inventory!");
+ player->messagebox("Not enough cargo space to transfer inventory!", "Close");
return;
}
- // check price
- if (price() > player->credits()) {
- player->send("^WCan not afford transaction!");
+ // needs confirmation
+ if (!confirm) {
+ std::ostringstream ostrtxt;
+ ostrtxt << "Buy a " << name() << " for " << price() -refund << " credits?";
+
+ std::ostringstream ostrcmd;
+ ostrcmd << "buy " << seller_item->id() << " 1 confirm";
+
+ player->messagebox(ostrtxt.str().c_str(), "OK", ostrcmd.str().c_str(), "Cancel", "");
return;
}
-
+
Ship * ship = new Ship(player, this);
ship->set_zone(seller->zone());
ship->get_location().assign(seller->location());
ship->get_axis().assign(seller->axis());
ship->get_axis().change_direction(180.0f);
ship->set_dock(seller);
- //ship->reset(); // reset() is done by set_dock()
// transfer inventory
for (core::Inventory::Items::iterator it = player->control()->inventory()->items().begin(); it != player->control()->inventory()->items().end(); it++) {
diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h
index 9849cd0..64244fc 100644
--- a/src/game/base/shipmodel.h
+++ b/src/game/base/shipmodel.h
@@ -237,7 +237,7 @@ public:
* */
void generate_info();
- void buy(core::EntityControlable *buyer, core::Entity *seller);
+ void buy(core::EntityControlable *buyer, core::Entity *seller, bool confirm = false);
/* --- static registry functions ---------------------------------- */