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>2014-12-13 20:21:10 +0000
committerStijn Buys <ingar@osirion.org>2014-12-13 20:21:10 +0000
commit1876f0f3fda9d0dc4c198416950fa6bf25378626 (patch)
tree3e13c37a839ac7e76c05b820e38b5032f22e9ad3 /src/game/base
parent300db69911bec3a17f9fb695d09be3d9830e3648 (diff)
Added repair engine function and the ability to repair ships at bases.
Diffstat (limited to 'src/game/base')
-rw-r--r--src/game/base/game.cc85
-rw-r--r--src/game/base/game.h1
-rw-r--r--src/game/base/shipmodel.cc2
3 files changed, 87 insertions, 1 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 4703aac..575ba3b 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -1167,6 +1167,76 @@ void Game::func_buy(core::Player *player, const std::string &args)
}
}
+// repair ship
+void Game::func_repair(core::Player *player, const std::string &args)
+{
+ // must be joined to repair
+ if (!player->control()) {
+ player->send("^WYou need to join the game first!");
+ return;
+ }
+
+ // player must be controlling a ship
+ if (player->control()->moduletype() != ship_enttype) {
+ return;
+ }
+
+ Ship *ship = static_cast<Ship *>(player->control());
+
+ // must be docked to repair
+ if ((ship->state() != core::Entity::Docked) || (!ship->dock())) {
+ player->send("^WYou need to be docked!");
+ return;
+ }
+
+ core::Entity *dock = ship->dock();
+
+ // can only buy at planets and stations
+ if ((dock->moduletype() != station_enttype) && (dock->moduletype() != planet_enttype)) {
+ player->send("^WCan not repair here");
+ return;
+ }
+
+ // check if repair is required
+ if (ship->armor() >= ship->maxarmor()) {
+ player->messagebox("Ship armor is already at full strength.");
+ }
+
+ const float base_price = roundf(10.0f + player->reputation(dock->faction()) /-20.0f); // base price per armor unit
+
+ float amount = ship->maxarmor() - ship->armor();
+ float price = base_price * amount;
+
+ if (player->credits() < (long) price) {
+ amount = floorf((float) player->credits() / base_price);
+ price = base_price * amount;
+ }
+
+ std::istringstream is(args);
+ std::string strconfirm;
+ bool confirm = false;
+ if ((is >> strconfirm) && (strconfirm.compare("confirm") == 0)) {
+ confirm = true;
+ }
+
+ if (!confirm) {
+ std::ostringstream strmsg;
+ strmsg << "Repair ship for " << price << " credits?";
+ player->messagebox(strmsg.str().c_str(), "OK", "repair confirm", "Close");
+ return;
+ } else {
+ player->set_credits(player->credits() - (long) price);
+ ship->set_armor(ship->armor() + amount);
+
+ std::ostringstream strmsg;
+ strmsg << "Ship repaired for " << price << " credits.";
+ player->send(strmsg.str());
+ }
+
+ player->set_dirty();
+ player->sound("game/repair");
+}
+
// drop item requests
void Game::func_drop(core::Player *player, const std::string &args)
{
@@ -1176,6 +1246,11 @@ void Game::func_drop(core::Player *player, const std::string &args)
return;
}
+ // player must be controlling a ship
+ if (player->control()->moduletype() != ship_enttype) {
+ return;
+ }
+
Ship *ship = static_cast<Ship *>(player->control());
// cannot be docked to drop items
@@ -1732,6 +1807,9 @@ Game::Game() : core::Module("Project::OSiRiON", true)
func = core::Func::add("sell", Game::func_sell);
func->set_info("[string] [string] [int] sell an item: specify type, label and amount");
+
+ func = core::Func::add("repair", Game::func_repair);
+ func->set_info("repair ship");
func = core::Func::add("drop", Game::func_drop);
func->set_info("[label] drop an item and activate it");
@@ -2698,6 +2776,13 @@ bool Game::generate_entity_menus(core::Entity *entity)
}
}
+ // add repair button
+ button = new ButtonDescription();
+ button->set_text("Repair");
+ button->set_command("repair", ButtonDescription::CommandGame);
+ button->set_alignment(ButtonDescription::Center);
+ menu_main->add_button(button);
+
return true;
}
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 81d5339..444916c 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -145,6 +145,7 @@ private:
static void func_mount(core::Player *player, const std::string &args);
static void func_unmount(core::Player *player, const std::string &args);
static void func_beam(core::Player *player, const std::string &args);
+ static void func_repair(core::Player *player, const std::string &args);
static void func_wingmen(core::Player *player, const std::string &args);
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index 1edd9d2..9489c91 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -355,7 +355,7 @@ void ShipModel::buy(core::EntityControlable *buyer, core::Entity *seller, bool c
// needs confirmation
if (!confirm) {
std::ostringstream ostrtxt;
- ostrtxt << "Buy a " << name() << " for " << price() -refund << " credits?";
+ ostrtxt << "Buy " << aux::article(name()) << " for " << price() - refund << " credits?";
std::ostringstream ostrcmd;
ostrcmd << "buy " << seller_item->id() << " 1 confirm";