Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/client.cc9
-rw-r--r--src/client/entitymenu.cc1
-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
7 files changed, 120 insertions, 4 deletions
diff --git a/src/client/client.cc b/src/client/client.cc
index df56700..24059a5 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -7,8 +7,9 @@
#include <SDL/SDL.h>
#include <iostream>
-#include <cmath>
#include <iomanip>
+#include <cmath>
+#include <cstdlib>
#include "audio/audio.h"
#include "audio/sources.h"
@@ -150,6 +151,10 @@ void Client::run()
{
con_print << "^BRunning client..." << std::endl;
+ // seed random generator
+ unsigned int seed = (unsigned int) SDL_GetTicks();
+ srandom(seed);
+
// default framerate 125fps, 8 milliseconds
Uint32 client_frame_lenght = 8;
@@ -376,6 +381,8 @@ void Client::func_snd_restart(std::string const &args)
void Client::func_r_restart(std::string const &args)
{
video::restart();
+ video::set_loader_message();
+ video::frame_loader();
}
/* ---- func_ui ---------------------------------------------------- */
diff --git a/src/client/entitymenu.cc b/src/client/entitymenu.cc
index c7df7ab..f727ff3 100644
--- a/src/client/entitymenu.cc
+++ b/src/client/entitymenu.cc
@@ -17,6 +17,7 @@ EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ui::Window(pare
set_border(false);
set_background(false);
set_label(label);
+ set_label("entitymenu");
menu_container = new ui::Container(this);
hide();
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");