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>2015-01-25 11:18:18 +0000
committerStijn Buys <ingar@osirion.org>2015-01-25 11:18:18 +0000
commitcd30cd33b8b78343f0edcc29ac07fa5bd1b844bd (patch)
treed03502f843d8d20045aa8cc9ab1f8d01a0984cdf
parente3986c6d4e898da80bafd21e3861119248a170d8 (diff)
Minor header file cleanup,
add weapons to the player's ship when starting a new game.
-rw-r--r--src/game/base/game.cc140
-rw-r--r--src/game/base/game.h8
-rw-r--r--src/game/base/jumppoint.cc1
-rw-r--r--src/game/base/platform.cc1
-rw-r--r--src/game/base/racetrack.cc2
-rw-r--r--src/game/base/shipmodel.cc1
6 files changed, 124 insertions, 29 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index d7f8435..531d4b1 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -45,6 +45,8 @@ namespace game
core::Zone *Default::zone = 0;
core::Entity *Default::view = 0;
ShipModel *Default::shipmodel = 0;
+Weapon *Default::cannonmodel = 0;
+Weapon *Default::turretmodel = 0;
long Default::credits = 0;
void Default::clear()
@@ -52,6 +54,8 @@ void Default::clear()
zone = 0;
view = 0;
shipmodel = 0;
+ cannonmodel = 0;
+ turretmodel = 0;
credits = 0;
}
@@ -90,8 +94,45 @@ void Game::func_join(core::Player *player, std::string const &args)
ship->set_zone(player->zone());
player->set_control(ship);
+ // load weapons
+ for (core::Slots::iterator it = ship->slots()->begin(); it != ship->slots()->end(); ++it)
+ {
+ core::Slot *slot = (*it);
+ Weapon *weapon = 0;
+
+ if (slot->type() == model::Slot::Cannon)
+ {
+ weapon = Default::cannonmodel;
+ }
+ else if (slot->type() == model::Slot::Turret)
+ {
+ weapon = Default::turretmodel;
+ }
+
+ if (weapon && (weapon->volume() <= ship->inventory()->capacity_available()))
+ {
+ // add weapon to inventory
+ core::Item *item = new core::Item(weapon);
+ item->set_flag(core::Item::Unique);
+ item->set_flag(core::Item::Mountable);
+ item->set_flag(core::Item::Unrestricted);
+ item->set_amount(1);
+
+ ship->inventory()->add(item);
+
+ // mount weapon
+ slot->set_item(item);
+ slot->set_flag(core::Slot::Active);
+ slot->set_flag(core::Slot::Mounted);
+ item->set_flag(core::Item::Mounted);
+ }
+ }
+ ship->inventory()->set_dirty();
+
+ // dock ship at default base
core::Entity *dock = ship->zone()->default_view();
- if (dock) {
+ if (dock)
+ {
ship->set_dock(dock);
player->set_view(dock);
}
@@ -2862,40 +2903,84 @@ bool Game::load_settings()
{
filesystem::IniFile inifile;
inifile.open("ini/game");
- if (!inifile.is_open()) {
+ if (!inifile.is_open())
+ {
con_error << "Could not open " << inifile.name() << "!" << std::endl;
return false;
}
long l;
- std::string str;
-
- while (inifile.getline()) {
-
- if (inifile.got_section()) {
+ std::string strval;
- if (inifile.got_section("player")) {
+ while (inifile.getline())
+ {
+ if (inifile.got_section())
+ {
+ if (inifile.got_section("player"))
+ {
continue;
- } else if (inifile.got_section("cargo")) {
+ }
+ else if (inifile.got_section("cargo"))
+ {
continue;
- } else {
+ }
+ else
+ {
inifile.unknown_section();
}
-
- } else if (inifile.got_key()) {
-
- if (inifile.in_section("player")) {
-
- if (inifile.got_key_long("credits", l)) {
+ }
+ else if (inifile.got_key())
+ {
+ if (inifile.in_section("player"))
+ {
+ if (inifile.got_key_long("credits", l))
+ {
Default::credits = l;
- } else if (inifile.got_key_label("zone", str)) {
- Default::zone = core::Zone::find(str);
-
- } else if (inifile.got_key_label("ship", str)) {
- Default::shipmodel = ShipModel::find(str);
+ }
+ else if (inifile.got_key_label("zone", strval))
+ {
+ Default::zone = core::Zone::find(strval);
- } else {
+ }
+ else if (inifile.got_key_label("ship", strval))
+ {
+ Default::shipmodel = ShipModel::find(strval);
+ }
+ else if (inifile.got_key_label("cannon", strval))
+ {
+ Weapon *cannon = Weapon::find(strval);
+ if (!cannon)
+ {
+ inifile.unknown_error("unknown weapon type '" + strval + "'");
+ }
+ else if (cannon->subtype() != Weapon::Cannon)
+ {
+ inifile.unknown_error("weapon type '" + strval + "' is not a cannon");
+ }
+ else
+ {
+ Default::cannonmodel = cannon;
+ }
+ }
+ else if (inifile.got_key_label("turret", strval))
+ {
+ Weapon *turret = Weapon::find(strval);
+ if (!turret)
+ {
+ inifile.unknown_error("unknown weapon type '" + strval + "'");
+ }
+ else if (turret->subtype() != Weapon::Turret)
+ {
+ inifile.unknown_error("weapon type '" + strval + "' is not a turret");
+ }
+ else
+ {
+ Default::turretmodel = turret;
+ }
+ }
+ else
+ {
inifile.unknown_key();
}
}
@@ -2904,19 +2989,22 @@ bool Game::load_settings()
inifile.close();
- if (!Default::zone) {
- con_error << "No default zone found!\n";
+ if (!Default::zone)
+ {
+ con_error << "No default zone set!\n";
return false;
}
- if (!Default::zone->default_view()) {
+ if (!Default::zone->default_view())
+ {
con_error << "Zone '" << Default::zone->label() << "' has no default view!\n";
return false;
}
Default::view = Default::zone->default_view();
- if (!Default::shipmodel) {
+ if (!Default::shipmodel)
+ {
con_error << "No default ship model found!\n";
return false;
}
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 76d7797..5a93272 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -10,9 +10,6 @@
#include <vector>
#include <string>
-#include "base/ship.h"
-#include "base/faction.h"
-
#include "core/module.h"
#include "core/range.h"
#include "core/application.h"
@@ -52,6 +49,9 @@ const float jump_timer_delay = 5.0f;
const float jump_cooldown_delay = 2.0f;
const float impulse_timer_delay = 3.0f;
+class ShipModel;
+class Weapon;
+
/// default player settings
class Default
{
@@ -59,6 +59,8 @@ public:
static core::Zone *zone;
static core::Entity *view;
static ShipModel *shipmodel;
+ static Weapon *cannonmodel;
+ static Weapon *turretmodel;
static long credits;
static void clear();
diff --git a/src/game/base/jumppoint.cc b/src/game/base/jumppoint.cc
index 7f23fd9..45bf378 100644
--- a/src/game/base/jumppoint.cc
+++ b/src/game/base/jumppoint.cc
@@ -6,6 +6,7 @@
#include "base/game.h"
#include "base/jumppoint.h"
+#include "base/ship.h"
namespace game
{
diff --git a/src/game/base/platform.cc b/src/game/base/platform.cc
index de7f987..b5e92dc 100644
--- a/src/game/base/platform.cc
+++ b/src/game/base/platform.cc
@@ -9,6 +9,7 @@
#include "base/game.h"
#include "base/faction.h"
#include "base/platform.h"
+#include "base/ship.h"
#include "base/weapon.h"
#include "sys/sys.h"
diff --git a/src/game/base/racetrack.cc b/src/game/base/racetrack.cc
index 5191711..b5df4a8 100644
--- a/src/game/base/racetrack.cc
+++ b/src/game/base/racetrack.cc
@@ -9,6 +9,8 @@
#include "base/game.h"
#include "base/racetrack.h"
+#include "base/ship.h"
+
#include "core/gameserver.h"
namespace game
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index cb627c6..275514f 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -10,6 +10,7 @@
#include "auxiliary/functions.h"
#include "base/shipmodel.h"
#include "base/game.h"
+#include "base/ship.h"
#include "base/template.h"
#include "sys/sys.h"