From 97746cd48fcc68df3c427ab3a0e18b939eb7906f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 28 Jan 2009 21:05:04 +0000 Subject: seed random generator on startup, show loader frame on r_restart, initial collision detection hooks --- src/game/base/Makefile.am | 4 +-- src/game/base/collision.cc | 71 ++++++++++++++++++++++++++++++++++++++++++++++ src/game/base/collision.h | 31 ++++++++++++++++++++ src/game/base/game.cc | 6 ++++ src/game/base/racetrack.cc | 2 +- 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 src/game/base/collision.cc create mode 100644 src/game/base/collision.h (limited to 'src/game/base') 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((*first)), (*second)); + } else if ((*second)->type() == core::Entity::Controlable) { + distance_test(static_cast ((*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"); -- cgit v1.2.3