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>2008-09-28 21:34:53 +0000
committerStijn Buys <ingar@osirion.org>2008-09-28 21:34:53 +0000
commit9252bfb61fabea1f45afacb19d805eb5fdd01599 (patch)
tree13fdfb005ab0b690766d35572f0eeecca28f6009 /src/game/intro
parent6774f2b5d14c1957d163ef4b7914c2660b59fdfd (diff)
intro module
Diffstat (limited to 'src/game/intro')
-rw-r--r--src/game/intro/Makefile.am4
-rw-r--r--src/game/intro/convoy.cc85
-rw-r--r--src/game/intro/convoy.h51
-rw-r--r--src/game/intro/intro.cc98
-rw-r--r--src/game/intro/intro.h4
5 files changed, 230 insertions, 12 deletions
diff --git a/src/game/intro/Makefile.am b/src/game/intro/Makefile.am
index fc5b019..eeb6f9d 100644
--- a/src/game/intro/Makefile.am
+++ b/src/game/intro/Makefile.am
@@ -2,5 +2,5 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/game
METASOURCES = AUTO
libintro_la_LDFLAGS = -avoid-version
noinst_LTLIBRARIES = libintro.la
-libintro_la_SOURCES = intro.cc
-noinst_HEADERS = intro.h
+libintro_la_SOURCES = convoy.cc intro.cc
+noinst_HEADERS = convoy.h intro.h
diff --git a/src/game/intro/convoy.cc b/src/game/intro/convoy.cc
new file mode 100644
index 0000000..ea71a27
--- /dev/null
+++ b/src/game/intro/convoy.cc
@@ -0,0 +1,85 @@
+/*
+ intro/convoy.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "intro/convoy.h"
+
+namespace intro {
+
+Member::Member(std::string const &model) : core::EntityControlable(0, 1)
+{
+ set_name("Convoy member");
+ set_label(model);
+
+ entity_modelname = "ships/" + model;
+
+ entity_thrust = 1.0f;
+ entity_speed = 1.0f;
+
+ entity_location.x = -16.0f;
+ entity_location.y = -math::randomf(8.0f);
+ entity_location.z = math::randomf(8.0f) - 6.0f;
+
+ entity_axis.change_direction(15.0f);
+}
+
+Member::~Member()
+{
+}
+
+void Member::frame(float seconds)
+{
+ entity_location += entity_axis.forward() * speed() * thrust() * seconds;
+}
+
+Convoy::Convoy(core::Zone *zone)
+{
+ convoy_zone = zone;
+}
+
+Convoy::~Convoy()
+{
+ convoy_members.clear();
+}
+
+void Convoy::set_color(math::Color const &color)
+{
+ convoy_color.assign(color);
+}
+void Convoy::set_color_second(math::Color const &color)
+{
+ convoy_color_second.assign(color);
+}
+
+void Convoy::add(const char *model)
+{
+ add(std::string(model));
+}
+
+void Convoy::add(std::string const &model)
+{
+ Member *member = new Member(model);
+ convoy_members.push_back(member);
+ member->set_zone(convoy_zone);
+ member->entity_color.assign(convoy_color);
+ member->entity_color_second.assign(convoy_color_second);
+}
+
+void Convoy::frame(float seconds)
+{
+ for (Members::iterator it = convoy_members.begin(); it != convoy_members.end(); ) {
+ Member *member = (*it);
+ if (member->location().length() > 64.0f) {
+ std::string model(member->label());
+ member->die();
+ convoy_members.erase(it++);
+ add(model);
+ } else {
+ ++it;
+ }
+ }
+}
+
+} \ No newline at end of file
diff --git a/src/game/intro/convoy.h b/src/game/intro/convoy.h
new file mode 100644
index 0000000..8f8a64d
--- /dev/null
+++ b/src/game/intro/convoy.h
@@ -0,0 +1,51 @@
+/*
+ intro/convoy.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_INTRO_CONVOY_H__
+#define __INCLUDED_INTRO_CONVOY_H__
+
+#include <list>
+
+#include "core/core.h"
+#include "math/color.h"
+
+namespace intro {
+
+class Member : public core::EntityControlable
+{
+public:
+ Member(std::string const &model);
+ ~Member();
+
+ void frame(float seconds);
+};
+
+class Convoy
+{
+public:
+ Convoy(core::Zone *zone);
+ ~Convoy();
+
+ void add(const char *model);
+ void add(std::string const &model);
+
+ void frame(float seconds);
+
+ void set_color(math::Color const &color);
+ void set_color_second(math::Color const &color);
+
+private:
+ typedef std::list<Member *> Members;
+ Members convoy_members;
+ core::Zone *convoy_zone;
+ math::Color convoy_color;
+ math::Color convoy_color_second;
+};
+
+}
+
+#endif // __INCLUDED_INTRO_CONVOY_H__
+
diff --git a/src/game/intro/intro.cc b/src/game/intro/intro.cc
index c0ae6da..f5b4e2f 100644
--- a/src/game/intro/intro.cc
+++ b/src/game/intro/intro.cc
@@ -5,6 +5,11 @@
*/
#include "intro/intro.h"
+#include "core/core.h"
+#include "core/parser.h"
+#include "filesystem/filesystem.h"
+#include "filesystem/inifile.h"
+#include "math/color.h"
#include "sys/sys.h"
namespace intro {
@@ -12,6 +17,7 @@ namespace intro {
Intro::Intro() : core::Module("Introduction")
{
intro_zone = 0;
+ intro_convoy = 0;
}
Intro::~Intro()
@@ -23,21 +29,84 @@ void Intro::init()
/// intialize a single zone for the introduction
intro_zone = new core::Zone("intro");
intro_zone->set_name("Introduction");
+ intro_zone->set_sky("sky");
core::Zone::add(intro_zone);
-
- /// add a planet
- core::EntityGlobe *planet = new core::EntityGlobe();
- planet->set_zone(intro_zone);
- planet->set_name("Planet");
- planet->set_label("planet");
- planet->entity_texture.assign("planets/seymour");
- planet->entity_location.assign(0, -32.0f, 0.0f);
- planet->entity_radius = 64.0f;
- planet->entity_rotationspeed = 1.0f;
+
+ intro_convoy = new Convoy(intro_zone);
+
+ if (!load_world()) {
+ abort();
+ return;
+ }
module_running = true;
}
+bool Intro::load_world()
+{
+ std::string filename("intro");
+
+ filesystem::IniFile ini;
+ ini.open(filename);
+
+ if (!ini.is_open()) {
+ con_error << "Could not open " << ini.name() << std::endl;
+ return false;
+ }
+
+ std::string strval;
+ core::EntityGlobe *globe = 0;
+ math::Color color;
+ bool b;
+
+ while (ini.getline()) {
+ if (ini.got_key()) {
+
+ if (ini.section().compare("intro") == 0) {
+ if (ini.got_key_string("sky", strval)) {
+ intro_zone->set_sky(strval);
+ continue;
+ }
+ } else if (ini.section().compare("convoy") == 0) {
+ if (ini.got_key_color("color", color)) {
+ intro_convoy->set_color(color);
+
+ } else if (ini.got_key_color("colorsecond", color)) {
+ intro_convoy->set_color_second(color);
+
+ } else if (ini.got_key_string("ship", strval)) {
+ intro_convoy->add(strval);
+ }
+
+ } else if (ini.section().compare("globe") == 0) {
+ if (core::Parser::got_entity_key(ini, globe)) {
+ continue;
+ } else if (ini.got_key_string("texture", globe->entity_texture)) {
+ continue;
+ } else if (ini.got_key_float("rotationspeed", globe->entity_rotationspeed)) {
+ continue;
+ } else if (ini.got_key_bool("bright", b)) {
+ if (b) { globe->entity_flags |= core::Entity::Bright; }
+ } else {
+ con_warn << ini.name() << " unknown key '" << ini.key() << "' at line " << ini.line() << std::endl;
+ }
+ }
+
+ } else if (ini.got_section("intro")) {
+ continue;
+
+ } else if (ini.got_section("globe")) {
+ globe = new core::EntityGlobe();
+ globe->set_zone(intro_zone);
+
+ } else if (ini.got_section()) {
+ con_warn << ini.name() << " unknown section '" << ini.section() << "' at line " << ini.line() << std::endl;
+ }
+ }
+
+ return true;
+}
+
void Intro::player_connect(core::Player *player)
{
player->set_zone(intro_zone);
@@ -49,10 +118,19 @@ void Intro::player_disconnect(core::Player *player)
void Intro::frame(float seconds)
{
+ if (intro_convoy) {
+ intro_convoy->frame(seconds);
+ }
}
void Intro::shutdown()
{
+ intro_zone = 0;
+
+ if (intro_convoy) {
+ delete intro_convoy;
+ intro_convoy = 0;
+ }
}
}
diff --git a/src/game/intro/intro.h b/src/game/intro/intro.h
index 21dc604..748432c 100644
--- a/src/game/intro/intro.h
+++ b/src/game/intro/intro.h
@@ -8,6 +8,7 @@
#define __INCLUDED_INTRO_H__
#include "core/core.h"
+#include "intro/convoy.h"
/// introduction game module
namespace intro
@@ -39,6 +40,9 @@ public:
private:
core::Zone *intro_zone;
+ Convoy *intro_convoy;
+
+ bool load_world();
};
}