Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/Makefile.am30
-rw-r--r--src/game/base/cargo.cc24
-rw-r--r--src/game/base/cargo.h1
-rw-r--r--src/game/base/game.cc92
-rw-r--r--src/game/base/game.h2
-rw-r--r--src/game/base/shipmodel.cc8
6 files changed, 127 insertions, 30 deletions
diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am
index 2dcea93..6391468 100644
--- a/src/game/base/Makefile.am
+++ b/src/game/base/Makefile.am
@@ -2,7 +2,29 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/game
METASOURCES = AUTO
libbase_la_LDFLAGS = -avoid-version
noinst_LTLIBRARIES = libbase.la
-libbase_la_SOURCES = cargo.cc cargopod.cc game.cc jumppoint.cc navpoint.cc planet.cc \
- racetrack.cc ship.cc shipmodel.cc star.cc station.cc
-noinst_HEADERS = cargo.h cargopod.h game.h jumppoint.h navpoint.h planet.h \
- racetrack.h ship.h shipmodel.h star.h station.h
+libbase_la_SOURCES = \
+ cargo.cc \
+ cargopod.cc \
+ faction.cc \
+ game.cc \
+ jumppoint.cc \
+ navpoint.cc \
+ planet.cc \
+ racetrack.cc \
+ ship.cc \
+ shipmodel.cc \
+ star.cc \
+ station.cc
+noinst_HEADERS = \
+ cargo.h \
+ cargopod.h \
+ game.h \
+ faction.h \
+ jumppoint.h \
+ navpoint.h \
+ planet.h \
+ racetrack.h \
+ ship.h \
+ shipmodel.h \
+ star.h \
+ station.h
diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc
index c7f2492..41cce1b 100644
--- a/src/game/base/cargo.cc
+++ b/src/game/base/cargo.cc
@@ -7,24 +7,30 @@
#include <assert.h>
#include <cmath>
+#include "sys/sys.h"
+#include "filesystem/inifile.h"
+#include "auxiliary/functions.h"
+#include "core/func.h"
#include "base/game.h"
#include "base/cargo.h"
#include "base/cargopod.h"
-#include "filesystem/inifile.h"
-#include "auxiliary/functions.h"
-#include "sys/sys.h"
namespace game
{
core::InfoType *Cargo::cargo_infotype = 0;
+void func_list_cargo(const std::string &args)
+{
+ Cargo::list();
+}
+
// loads cargo types from ini file
bool Cargo::init()
{
- // initialize commodities InfoType
- Cargo::cargo_infotype = new core::InfoType("cargo");
+ // initialize cargo InfoType
+ cargo_infotype = new core::InfoType("cargo");
filesystem::IniFile cargoini;
cargoini.open("ini/cargo");
@@ -47,8 +53,7 @@ bool Cargo::init()
if (cargoini.section().compare("cargo") == 0) {
if (cargoini.got_key_label("label", str)) {
- cargo->set_label(std::string(str));
- count++;
+ cargo->set_label(str);
continue;
} else if (cargoini.got_key_string("name", str)) {
@@ -80,6 +85,7 @@ bool Cargo::init()
if (cargoini.got_section("cargo")) {
cargo = new Cargo();
+ count++;
} else if (cargoini.got_section()) {
cargoini.unknown_section();
@@ -91,6 +97,10 @@ bool Cargo::init()
con_debug << " " << cargoini.name() << " " << count << " cargo types" << std::endl;
cargoini.close();
+
+ core::Func *func = core::Func::add("list_cargo", func_list_cargo);
+ func->set_info("list available cargo types");
+
return true;
}
diff --git a/src/game/base/cargo.h b/src/game/base/cargo.h
index 3a42c74..eb616a5 100644
--- a/src/game/base/cargo.h
+++ b/src/game/base/cargo.h
@@ -24,6 +24,7 @@ public:
void eject(core::EntityControlable *ejector, const int amount);
/* -- static functions -- */
+
static core::InfoType *cargo_infotype;
static Cargo *find(const std::string & label);
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index f110962..295b2f1 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -17,6 +17,7 @@
#include "filesystem/inifile.h"
#include "base/game.h"
#include "base/cargo.h"
+#include "base/faction.h"
#include "base/navpoint.h"
#include "base/jumppoint.h"
#include "base/planet.h"
@@ -848,8 +849,14 @@ void Game::func_goto(core::Player *player, const std::string &args)
Game::Game() : core::Module("Project::OSiRiON", true)
{
- // reset default player values
+ // clear defaults
Default::clear();
+
+ // read factions.ini
+ if (!Faction::init()) {
+ // not fatal
+
+ }
// read cargo.ini
if (!Cargo::init()) {
@@ -951,59 +958,68 @@ Game::~Game()
g_damping = 0;
g_deplete = 0;
+ // clear defaults
Default::clear();
+
+ // clear Factions
+ Faction::clear();
}
bool Game::load_world()
{
std::string inifilename("ini/world");
- filesystem::IniFile worldini;
- worldini.open(inifilename);
+ filesystem::IniFile inifile;
+ inifile.open(inifilename);
- if (!worldini.is_open()) {
- con_error << "Could not open " << worldini.name() << std::endl;
+ if (!inifile.is_open()) {
+ con_error << "Could not open " << inifile.name() << std::endl;
return false;
}
con_print << "^BLoading world..." << std::endl;
+ Faction *faction = 0;
core::Zone *zone = 0;
std::string label;
+ math::Color color;
- while (worldini.getline()) {
+ while (inifile.getline()) {
- if (worldini.got_section()) {
+ if (inifile.got_section()) {
+ zone = 0;
+ faction = 0;
- if (worldini.got_section("world")) {
+ if (inifile.got_section("world")) {
continue;
+
} else {
- worldini.unknown_section();
+ inifile.unknown_section();
}
- } else if (worldini.got_key()) {
+ } else if (inifile.got_key()) {
- if (worldini.in_section("world")) {
+ if (inifile.in_section("world")) {
- if (worldini.got_key_string("zone", label)) {
+ if (inifile.got_key_string("zone", label)) {
aux::to_label(label);
zone = new core::Zone(label);
core::Zone::add(zone);
} else {
- worldini.unkown_key();
- }
+ inifile.unkown_key();
+ }
}
}
}
- worldini.close();
+ inifile.close();
if (!core::Zone::registry().size()) {
con_error << "No zones found!" << std::endl;
return false;
}
- con_debug << " " << worldini.name() << " " << core::Zone::registry().size() << " zones" << std::endl;
+ con_debug << " " << inifile.name() << " " << core::Zone::registry().size() << " zones" << std::endl;
for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
if (!load_zone((*it).second)) {
@@ -1184,9 +1200,27 @@ bool Game::load_zone(core::Zone *zone)
zoneini.unkown_key();
}
- } else if (zoneini.in_section("jumppoint") || zoneini.in_section("jumpgate")) {
+ } else if (zoneini.in_section("jumppoint")) {
+ if (core::Parser::got_entity_key(zoneini, jumppoint)) {
+ continue;
+ } else if (zoneini.got_key_string("target", strval)) {
+ jumppoint->set_targetlabel(strval);
+ continue;
+ } else {
+ zoneini.unkown_key();
+ }
+
+ } else if (zoneini.in_section("jumpgate")) {
if (core::Parser::got_entity_key(zoneini, jumppoint)) {
continue;
+ } else if (zoneini.got_key_label("faction", strval)) {
+ Faction *faction = Faction::find(strval);
+ if (!faction) {
+ zoneini.unknown_error("unkown faction '" + strval + "'");
+ } else {
+ jumppoint->set_color(faction->color());
+ jumppoint->set_color_second(faction->color_second());
+ }
} else if (zoneini.got_key_string("target", strval)) {
jumppoint->set_targetlabel(strval);
continue;
@@ -1212,6 +1246,14 @@ bool Game::load_zone(core::Zone *zone)
zone->set_default_view(planet);
}
continue;
+ } else if (zoneini.got_key_label("faction", strval)) {
+ Faction *faction = Faction::find(strval);
+ if (!faction) {
+ zoneini.unknown_error("unkown faction '" + strval + "'");
+ } else {
+ planet->set_color(faction->color());
+ planet->set_color_second(faction->color_second());
+ }
} else {
zoneini.unkown_key();
}
@@ -1223,6 +1265,14 @@ bool Game::load_zone(core::Zone *zone)
if (b) {
zone->set_default_view(station);
}
+ } else if (zoneini.got_key_label("faction", strval)) {
+ Faction *faction = Faction::find(strval);
+ if (!faction) {
+ zoneini.unknown_error("unkown faction '" + strval + "'");
+ } else {
+ station->set_color(faction->color());
+ station->set_color_second(faction->color_second());
+ }
} else {
zoneini.unkown_key();
}
@@ -1248,6 +1298,14 @@ bool Game::load_zone(core::Zone *zone)
if (b) {
zone->set_default_view(entity);
}
+ } else if (zoneini.got_key_label("faction", strval)) {
+ Faction *faction = Faction::find(strval);
+ if (!faction) {
+ zoneini.unknown_error("unkown faction '" + strval + "'");
+ } else {
+ entity->set_color(faction->color());
+ entity->set_color_second(faction->color_second());
+ }
} else {
zoneini.unkown_key();
}
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 3859122..7e2a384 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -103,8 +103,6 @@ private:
bool load_commodities();
- bool load_ships();
-
bool load_settings();
/* ---- game functions ------------------------------------- */
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index 2b3f9d1..77ddb30 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -17,6 +17,11 @@ namespace game
core::InfoType *ShipModel::shipmodel_infotype = 0;
+void func_list_ship(const std::string &args)
+{
+ ShipModel::list();
+}
+
bool ShipModel::init()
{
// initialize shipmodel InfoType
@@ -121,6 +126,9 @@ bool ShipModel::init()
shipsini.close();
+ core::Func *func = core::Func::add("list_ship", func_list_ship);
+ func->set_info("list available ship types");
+
return true;
}