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>2009-01-28 21:05:04 +0000
committerStijn Buys <ingar@osirion.org>2009-01-28 21:05:04 +0000
commit97746cd48fcc68df3c427ab3a0e18b939eb7906f (patch)
tree16b6e100d96366a459ee1e9f65ed84e10dc26feb /src/game
parent757a712813a0815fc570784ca15676b90a36326a (diff)
seed random generator on startup,
show loader frame on r_restart, initial collision detection hooks
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/Makefile.am4
-rw-r--r--src/game/base/collision.cc71
-rw-r--r--src/game/base/collision.h31
-rw-r--r--src/game/base/game.cc6
-rw-r--r--src/game/base/racetrack.cc2
5 files changed, 111 insertions, 3 deletions
diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am
index 21e1717..74b5d74 100644
--- a/src/game/base/Makefile.am
+++ b/src/game/base/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/game
METASOURCES = AUTO
libbase_la_LDFLAGS = -avoid-version
noinst_LTLIBRARIES = libbase.la
-libbase_la_SOURCES = game.cc jumppoint.cc navpoint.cc planet.cc racetrack.cc \
+libbase_la_SOURCES = game.cc collision.cc jumppoint.cc navpoint.cc planet.cc racetrack.cc \
ship.cc shipdealer.cc shipmodel.cc star.cc station.cc
-noinst_HEADERS = game.h jumppoint.h navpoint.h planet.h racetrack.h ship.h \
+noinst_HEADERS = game.h collision.h jumppoint.h navpoint.h planet.h racetrack.h ship.h \
shipdealer.h shipmodel.h star.h station.h
diff --git a/src/game/base/collision.cc b/src/game/base/collision.cc
new file mode 100644
index 0000000..894ce95
--- /dev/null
+++ b/src/game/base/collision.cc
@@ -0,0 +1,71 @@
+/*
+ base/collision.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2.
+*/
+
+#include "base/collision.h"
+#include "base/game.h"
+#include "core/zone.h"
+#include "math/functions.h"
+#include "math/vector3f.h"
+
+namespace game {
+
+void Collision::distance_test(core::EntityControlable *first, core::Entity *second)
+{
+ if (!first->owner())
+ return;
+
+ if (first->eventstate() == core::Entity::Docked)
+ return;
+
+ // FIXME - use distancesquared
+ const float d = math::distance(first->location(), second->location());
+ const float r = first->radius() + second->radius();
+
+ if (second->type() == core::Entity::Globe) {
+ // collision with a star or a planet
+
+ if ( (d-r) < 0.0f) {
+ // crash zone
+ if (first->owner()->last_warning() + 5.0f < core::application()->time()) {
+ first->owner()->send_warning("^RBOOM!^N");
+ }
+ } else if (first->owner()->last_warning() + 5.0f < core::application()->time()) {
+ // warning zone: star corona or planet atmosphere
+ if ((second->moduletype() == star_enttype) && (d-r < 50.0f)) {
+ first->owner()->send_warning("^3Warning: entering star corona!^N");
+ } else if ((second->moduletype() == planet_enttype) && (d-r < 15.0f)) {
+ first->owner()->send_warning("^3Warning: hard landing imminent!^N");
+ }
+ }
+ }
+}
+
+void Collision::frame_zone(core::Zone *zone)
+{
+ core::Zone::Content::iterator first;
+ core::Zone::Content::iterator second;
+
+ for (first = zone->content().begin(); first != zone->content().end(); first ++) {
+ second = first;
+ for (second++; second != zone->content().end(); second++) {
+ if ( (*first)->type() == core::Entity::Controlable) {
+ distance_test(static_cast<core::EntityControlable *>((*first)), (*second));
+ } else if ((*second)->type() == core::Entity::Controlable) {
+ distance_test(static_cast<core::EntityControlable *> ((*second)), (*first));
+ }
+ }
+ }
+}
+
+void Collision::frame(const float elapsed)
+{
+ for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
+ frame_zone((*it).second);
+ }
+}
+
+} // namespace game
+
diff --git a/src/game/base/collision.h b/src/game/base/collision.h
new file mode 100644
index 0000000..8203669
--- /dev/null
+++ b/src/game/base/collision.h
@@ -0,0 +1,31 @@
+/*
+ base/collision.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_COLLISION_H__
+#define __INCLUDED_BASE_COLLISION_H__
+
+#include "core/zone.h"
+
+namespace game {
+
+/// collision detection functions
+class Collision {
+public:
+ /// do collision detection
+ static void frame(const float elapsed);
+
+private:
+ /// do collision detection for a single zone
+ static void frame_zone(core::Zone *zone);
+
+ /// do a distance test between two entities
+ static void distance_test(core::EntityControlable *first, core::Entity *second);
+};
+
+}
+
+#endif // __INCLUDED_BASE_COLLISION_H__
+
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 07cec0c..23eee3f 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -15,6 +15,7 @@
#include "filesystem/filesystem.h"
#include "filesystem/inifile.h"
#include "base/game.h"
+#include "base/collision.h"
#include "base/navpoint.h"
#include "base/jumppoint.h"
#include "base/planet.h"
@@ -848,6 +849,11 @@ void Game::frame(float seconds)
{
if (!running())
return;
+
+ // TODO check Module::frame() is execute before are Entity::frame()
+
+ // collision
+ Collision::frame(seconds);
}
void Game::player_connect(core::Player *player)
diff --git a/src/game/base/racetrack.cc b/src/game/base/racetrack.cc
index e818414..f36c047 100644
--- a/src/game/base/racetrack.cc
+++ b/src/game/base/racetrack.cc
@@ -200,7 +200,7 @@ void RaceTrack::frame(float seconds)
player->add_credits(the_prize);
msgstr.clear();
msgstr.str("");
- msgstr << "You receive " << the_prize << " credits." << std::endl;
+ msgstr << "You receive " << the_prize << " credits.";
player->send(msgstr.str());
player->sound("game/buy");