Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-09-17 23:05:58 +0000
committerStijn Buys <ingar@osirion.org>2010-09-17 23:05:58 +0000
commita85c3ca1ff34775f2fc93013306dec21b34b0359 (patch)
treedc45be555858f53413d2477680247c8758b98d2a /src/game
parent417eeaa34b8374de18358cc64511d7298bc33756 (diff)
Initial inventory loading, ships docking ships
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/Makefile.am4
-rw-r--r--src/game/base/cargo.cc38
-rw-r--r--src/game/base/cargo.h27
-rw-r--r--src/game/base/commodity.cc28
-rw-r--r--src/game/base/commodity.h25
-rw-r--r--src/game/base/game.cc139
-rw-r--r--src/game/base/planet.cc3
-rw-r--r--src/game/base/ship.cc31
-rw-r--r--src/game/base/ship.h2
-rw-r--r--src/game/base/station.cc2
10 files changed, 227 insertions, 72 deletions
diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am
index c3625a0..f7fd52e 100644
--- a/src/game/base/Makefile.am
+++ b/src/game/base/Makefile.am
@@ -2,8 +2,8 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/game
METASOURCES = AUTO
libbase_la_LDFLAGS = -avoid-version
noinst_LTLIBRARIES = libbase.la
-libbase_la_SOURCES = collision.cc commodity.cc game.cc jumppoint.cc navpoint.cc physics.cc \
+libbase_la_SOURCES = collision.cc cargo.cc game.cc jumppoint.cc navpoint.cc physics.cc \
planet.cc racetrack.cc ship.cc shipdealer.cc shipmodel.cc star.cc station.cc
-noinst_HEADERS = game.h collision.h commodity.h jumppoint.h navpoint.h physics.h planet.h \
+noinst_HEADERS = game.h collision.h cargo.h jumppoint.h navpoint.h physics.h planet.h \
racetrack.h ship.h shipdealer.h shipmodel.h star.h station.h
diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc
new file mode 100644
index 0000000..258aecf
--- /dev/null
+++ b/src/game/base/cargo.cc
@@ -0,0 +1,38 @@
+/*
+ base/cargo.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "base/game.h"
+#include "base/cargo.h"
+#include "auxiliary/functions.h"
+#include "sys/sys.h"
+
+namespace game
+{
+
+/* ---- class Cargo -------------------------------------------- */
+
+core::InfoType *Cargo::cargo_infotype = 0;
+
+Cargo::Cargo() : core::Info(cargo_infotype)
+{
+}
+
+Cargo::~Cargo()
+{
+}
+
+Cargo *Cargo::find(const std::string & label)
+{
+ if (!label.size()) {
+ return 0;
+ }
+
+ return (Cargo *) core::Info::find(cargo_infotype, label);
+}
+
+
+} // namespace game
+
diff --git a/src/game/base/cargo.h b/src/game/base/cargo.h
new file mode 100644
index 0000000..808b4c0
--- /dev/null
+++ b/src/game/base/cargo.h
@@ -0,0 +1,27 @@
+/*
+ base/cargo.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_BASE_CARGO_H__
+#define __INCLUDED_BASE_CARGO_H__
+
+#include "core/info.h"
+
+namespace game
+{
+class Cargo : public core::Info {
+
+public:
+ Cargo();
+ ~Cargo();
+
+ static core::InfoType *cargo_infotype;
+
+ static Cargo *find(const std::string & label);
+};
+
+} // namespace game
+
+#endif // __INCLUDED_BASE_CARGO_H__
diff --git a/src/game/base/commodity.cc b/src/game/base/commodity.cc
deleted file mode 100644
index 4f238be..0000000
--- a/src/game/base/commodity.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- base/commodity.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
-*/
-
-#include "base/game.h"
-#include "base/commodity.h"
-#include "auxiliary/functions.h"
-#include "sys/sys.h"
-
-namespace game
-{
-
-/* ---- class Commodity -------------------------------------------- */
-
-core::InfoType *Commodity::commodity_infotype = 0;
-
-Commodity::Commodity() : core::Info(commodity_infotype)
-{
-}
-
-Commodity::~Commodity()
-{
-}
-
-} // namespace game
-
diff --git a/src/game/base/commodity.h b/src/game/base/commodity.h
deleted file mode 100644
index b889749..0000000
--- a/src/game/base/commodity.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- base/commodity.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
-*/
-
-#ifndef __INCLUDED_BASE_COMMODITY_H__
-#define __INCLUDED_BASE_COMMODITY_H__
-
-#include "core/info.h"
-
-namespace game
-{
-class Commodity : public core::Info {
-
-public:
- Commodity();
- ~Commodity();
-
- static core::InfoType *commodity_infotype;
-};
-
-} // namespace game
-
-#endif // __INCLUDED_BASE_COMMODITY_H__
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 128ae7c..667a4c1 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -15,8 +15,8 @@
#include "filesystem/filesystem.h"
#include "filesystem/inifile.h"
#include "base/game.h"
+#include "base/cargo.h"
#include "base/collision.h"
-#include "base/commodity.h"
#include "base/navpoint.h"
#include "base/jumppoint.h"
#include "base/planet.h"
@@ -208,7 +208,7 @@ void Game::func_buy(core::Player *player, const std::string &args)
} else if (typestr.compare("cargo") == 0) {
player->send("Buying cargo is not supported");
} else {
- player->send("unkown item type '" + typestr + "'");
+ player->send("Unkown item type '" + typestr + "'");
}
return;
@@ -228,10 +228,47 @@ void Game::func_launch(core::Player *player, std::string const &args)
assert(player->view()->zone() == player->control()->zone());
- Ship *ship = static_cast<Ship *>(player->control());
- ship->shutdown_physics();
core::Entity *dock = player->view();
+
+ if (dock->moduletype() == ship_enttype) {
+
+ switch(static_cast<Ship *>(dock)->state()) {
+ case core::Entity::Normal:
+ case core::Entity::Docked:
+ break;
+
+ case core::Entity::NoPower:
+ player->send("^BCan not launch while carrier has no power!");
+ return;
+ break;
+
+ case core::Entity::ImpulseInitiate:
+ case core::Entity::Impulse:
+ player->send("^BCan not launch while carrier is using impulse engines!");
+ return;
+ break;
+
+ case core::Entity::JumpInitiate:
+ case core::Entity::Jump:
+ player->send("^BCan not launch while carrier is jumping through hyperspace!");
+ return;
+ break;
+
+ default:
+ if (other_ship->state() != ) {
+ player->send("^BCan not launch from carrier!");
+ return;
+ }
+ break;
+ }
+ }
+
+ assert(player->control()->moduletype() == ship_enttype);
+
+ Ship *ship = static_cast<Ship *>(player->control());
+ ship->shutdown_physics();
+
if (dock->type() == core::Entity::Globe)
ship->get_location().assign(dock->location() + (dock->axis().forward() *(planet_safe_distance + ship->radius() + dock->radius())));
else
@@ -712,12 +749,18 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
return false;
}
+
+
+
filesystem::IniFile inifile;
std::string strval;
MenuDescription *menu_dealer = 0;
ButtonDescription *button = 0;
- ShipDealer *shipdealer = 0;
+ ShipDealer *shipdealer = 0;
+
+ core::Inventory *inventory = 0;
+ core::Item *item = 0;
inifile.open(menufilename);
@@ -725,7 +768,11 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
while (inifile.getline()) {
if (inifile.got_section()) {
+
+ item = 0;
+
if (inifile.got_section("dealer")) {
+ // TODO replace [dealer] section with individual [ship] sections
// dealer menu
if (!menu_dealer) {
menu_dealer = new MenuDescription();
@@ -739,6 +786,11 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
static_cast<Station *>(entity)->set_shipdealer(shipdealer);
}
}
+
+ } else if (inifile.got_section("cargo")) {
+
+ } else if (inifile.got_section("ship")) {
+
} else {
inifile.unknown_section();
}
@@ -759,16 +811,73 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
button->set_info(model);
button->set_alignment(ButtonDescription::Left);
menu_dealer->add_button(button);
+ } else {
+ std::string msg("unknown ship type '");
+ msg.append(strval);
+ msg.append("'");
+ inifile.unknown_error(msg);
}
} else {
inifile.unkown_key();
}
- }
+ } else if (inifile.in_section("cargo")) {
+
+ if (inifile.got_key_label("label", strval)) {
+ Cargo *cargo = Cargo::find(strval);
+ if (cargo) {
+ if (!inventory) {
+ inventory = new core::Inventory();
+ }
+ item = inventory->find(cargo);
+ if (!item) {
+ item = new core::Item(cargo);
+ item->set_amount(-1);
+ inventory->add(item);
+ }
+ } else {
+ std::string msg("unkown cargo type '");
+ msg.append(strval);
+ msg.append("'");
+ inifile.unknown_error(msg);
+ }
+
+ } else {
+ inifile.unkown_key();
+ }
+
+ } else if (inifile.in_section("ship")) {
+
+ if (inifile.got_key_label("label", strval)) {
+ ShipModel *shipmodel = ShipModel::find(strval);
+ if (shipmodel) {
+ if (!inventory) {
+ inventory = new core::Inventory();
+ }
+ item = inventory->find(shipmodel);
+ if (!item) {
+ item = new core::Item(shipmodel);
+ item->set_amount(-1);
+ inventory->add(item);
+ }
+ } else {
+ std::string msg("unknown ship type '");
+ msg.append(strval);
+ msg.append("'");
+ inifile.unknown_error(msg);
+ }
+
+ } else {
+ inifile.unkown_key();
+ }
+ }
}
}
}
+
+ if (inventory)
+ entity->set_inventory(inventory);
MenuDescription *menu_main = new MenuDescription();
menu_main->set_label("main");
@@ -810,7 +919,7 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
bool Game::load_commodities()
{
// initialize commodities InfoType
- Commodity::commodity_infotype = new core::InfoType("cargo");
+ Cargo::cargo_infotype = new core::InfoType("cargo");
filesystem::IniFile cargoini;
cargoini.open("cargo");
@@ -823,28 +932,28 @@ bool Game::load_commodities()
size_t count = 0;
- Commodity *commodity = 0;
+ Cargo *cargo = 0;
std::string str;
while (cargoini.getline()) {
if (cargoini.got_key()) {
if (cargoini.section().compare("cargo") == 0) {
- if (cargoini.got_key_string("label", str)) {
- commodity->set_label(std::string(str));
+ if (cargoini.got_key_label("label", str)) {
+ cargo->set_label(std::string(str));
count++;
continue;
} else if (cargoini.got_key_string("name", str)) {
- commodity->set_name(str);
+ cargo->set_name(str);
continue;
} else if (cargoini.got_key_string("info", str)) {
- commodity->add_text(str);
+ cargo->add_text(str);
continue;
} else if (cargoini.got_key_string("model", str)) {
- commodity->set_modelname(str);
+ cargo->set_modelname(str);
continue;
} else {
@@ -855,7 +964,7 @@ bool Game::load_commodities()
} else if (cargoini.got_section()) {
if (cargoini.got_section("cargo")) {
- commodity = new Commodity();
+ cargo = new Cargo();
} else if (cargoini.got_section()) {
cargoini.unknown_section();
@@ -898,7 +1007,7 @@ bool Game::load_ships()
while (shipsini.getline()) {
if (shipsini.got_key()) {
if (shipsini.section().compare("ship") == 0) {
- if (shipsini.got_key_string("label", str)) {
+ if (shipsini.got_key_label("label", str)) {
shipmodel->set_label(str);
count++;
continue;
diff --git a/src/game/base/planet.cc b/src/game/base/planet.cc
index 380ca02..ca213af 100644
--- a/src/game/base/planet.cc
+++ b/src/game/base/planet.cc
@@ -49,13 +49,14 @@ void Planet::dock(core::Entity *entity)
Ship * ship = static_cast<Ship *>(entity);
+ // fixed 50 km docking radius
if (math::distance(location(), ship->location()) > radius() + ship->radius() + 50.0f) {
if (ship->owner())
ship->owner()->send("Planet out of range");
return;
}
- ship->get_location().assign(entity->location());
+ ship->get_location().assign(location());
ship->set_state(core::Entity::Docked);
if (ship->owner() && ship->owner()->control() == ship) {
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 7edc183..0da57ab 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -82,6 +82,37 @@ void Ship::reset()
current_target_strafe = 0.0f;
current_target_afterburner = 0.0f;
}
+
+// this is called if another shuo wants to dock this ship
+void Ship::dock(Entity *entity)
+{
+ if (!flag_is_set(core::Entity::Dockable))
+ return;
+
+ if (entity->moduletype() != ship_enttype)
+ return;
+
+ Ship *other_ship = static_cast<Ship *>(entity);
+
+ if (math::distance(location(), other_ship->location()) > radius() + other_ship->radius()) {
+ if (other_ship->owner())
+ other_ship->owner()->send("Target out of range");
+ return;
+ }
+
+ other_ship->get_location().assign(location());
+ other_ship->set_state(core::Entity::Docked);
+
+ if (other_ship->owner() && other_ship->owner()->control() == other_ship) {
+ other_ship->owner()->set_view(this);
+ if (owner()) {
+ other_ship->owner()->send("^BDocking at " + owner()->name() + "^B's " + name());
+ } else {
+ other_ship->owner()->send("^BDocking at " + name());
+ }
+ }
+}
+
void Ship::func_impulse()
{
if (entity_state == core::Entity::Impulse) {
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index e1b8b1d..f66bb66 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -51,6 +51,8 @@ public:
/// toggle jump drive activation
void func_jump(std::string const & args);
+
+ virtual void dock(Entity *entity);
private:
JumpPoint *find_closest_jumppoint();
diff --git a/src/game/base/station.cc b/src/game/base/station.cc
index fb548bb..83897cd 100644
--- a/src/game/base/station.cc
+++ b/src/game/base/station.cc
@@ -49,7 +49,7 @@ void Station::dock(core::Entity *entity)
return;
}
- ship->get_location().assign(entity->location());
+ ship->get_location().assign(location());
ship->set_state(core::Entity::Docked);
if (ship->owner() && ship->owner()->control() == ship) {