Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/Makefile.am2
-rw-r--r--src/game/base/game.h1
-rw-r--r--src/game/base/projectile.cc71
-rw-r--r--src/game/base/projectile.h36
-rw-r--r--src/game/base/ship.cc28
5 files changed, 138 insertions, 0 deletions
diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am
index 544cbb6..9e54b6c 100644
--- a/src/game/base/Makefile.am
+++ b/src/game/base/Makefile.am
@@ -11,6 +11,7 @@ noinst_HEADERS = \
jumppoint.h \
navpoint.h \
planet.h \
+ projectile.h \
racetrack.h \
savegame.h \
ship.h \
@@ -29,6 +30,7 @@ libbase_la_SOURCES = \
jumppoint.cc \
navpoint.cc \
planet.cc \
+ projectile.cc \
racetrack.cc \
savegame.cc \
ship.cc \
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 1bdd5ac..57acf06 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -35,6 +35,7 @@ const unsigned int jumpgate_enttype = 261;
const unsigned int station_enttype = 262;
const unsigned int cargopod_enttype = 263;
const unsigned int spacemine_enttype = 264;
+const unsigned int projectile_enttype = 264;
const unsigned int race_enttype = 280;
// planet docking distance
diff --git a/src/game/base/projectile.cc b/src/game/base/projectile.cc
new file mode 100644
index 0000000..992c55b
--- /dev/null
+++ b/src/game/base/projectile.cc
@@ -0,0 +1,71 @@
+/*
+ base/projectile.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/projectile.h"
+#include "base/game.h"
+#include "core/gameserver.h"
+#include "math/functions.h"
+#include "sys/sys.h"
+
+namespace game
+{
+
+Projectile::Projectile(unsigned long lifespan) : EntityDynamic()
+{
+ entity_moduletypeid = projectile_enttype;
+ //set_name("");
+ //set_label("");
+
+ //set_serverside(true);
+ set_flag(core::Entity::KeepAlive);
+ set_shape(core::Entity::Sphere);
+ set_radius(0.02f);
+ set_mass(radius());
+
+ //reset();
+
+ //const float damp = Game::g_damping->value();
+ //body()->setDamping(0.0f, 0.0f);
+
+ projectile_lifespan = lifespan;
+ projectile_timestamp = core::server()->timestamp();
+}
+
+Projectile::~Projectile()
+{
+
+}
+
+void Projectile::upkeep(const unsigned long timestamp)
+{
+ die();
+}
+
+void Projectile::collision(core::Entity *other)
+{
+ if (state() == core::Entity::Destroyed) {
+ return;
+ }
+
+ set_state(core::Entity::Destroyed);
+ // this method is a bullet callback, we can not reset() here
+}
+
+void Projectile::frame(const unsigned long elapsed)
+{
+ EntityDynamic::frame(elapsed);
+
+ if (projectile_timestamp + projectile_lifespan < core::server()->timestamp()) {
+ set_state(core::Entity::Destroyed);
+ }
+
+ if (state() == core::Entity::Destroyed) {
+ die();
+ }
+}
+
+} // namespace game
+
diff --git a/src/game/base/projectile.h b/src/game/base/projectile.h
new file mode 100644
index 0000000..bbaea99
--- /dev/null
+++ b/src/game/base/projectile.h
@@ -0,0 +1,36 @@
+/*
+ base/spacemine.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_PROJECTILE_H__
+#define __INCLUDED_BASE_PROJECTILE_H__
+
+#include "core/entity.h"
+
+namespace game
+{
+
+class Projectile : public core::EntityDynamic
+{
+public:
+ Projectile(unsigned long lifespan);
+ virtual ~Projectile();
+
+ virtual void upkeep(const unsigned long timestamp);
+
+ virtual void collision(Entity *other);
+
+ virtual void frame(const unsigned long elapsed);
+
+private:
+ unsigned long projectile_timestamp;
+
+ unsigned long projectile_lifespan;
+};
+
+} // namespace game
+
+#endif // __INCLUDED_BASE_PROJECTILE_H__
+
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 22725e0..8be6e6c 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -13,6 +13,7 @@
#include "core/entity.h"
#include "base/game.h"
#include "base/ship.h"
+#include "base/projectile.h"
#include "math/functions.h"
using math::degrees360f;
@@ -77,6 +78,13 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
if (model()) {
add_slots();
slots()->load(model());
+
+ for (core::Slots::iterator it = slots()->begin(); it != slots()->end(); it++) {
+ // default fire rate: 1 projectile / second
+ (*it)->set_interval(1000);
+ (*it)->set_lifespan(5000);
+ (*it)->set_speed(5.0f);
+ }
}
// menus for docked players
@@ -756,6 +764,26 @@ void Ship::frame(const unsigned long elapsed)
*/
EntityControlable::frame(elapsed);
+
+ if (model() && slots() && has_controlflag(core::EntityControlable::ControlFlagFire)) {
+
+ const float modelscale = radius() / model()->radius();
+
+ for (core::Slots::iterator it = slots()->begin(); it != slots()->end(); it++) {
+ // create projectiles
+ if ((*it)->last_fired() + (*it)->interval() <= core::server()->timestamp()) {
+ (*it)->set_last_fired(core::server()->timestamp());
+ Projectile * projectile = new Projectile((*it)->lifespan());
+ projectile->set_zone(zone());
+ projectile->set_axis(axis() * (*it)->axis());
+ projectile->set_location(location() + (axis() * (*it)->location() * modelscale) + projectile->axis().forward() * projectile->radius());
+
+ projectile->reset();
+ projectile->body()->setDamping(0.0f, 0.0f);
+ projectile->body()->setLinearVelocity(math::to_btVector3(projectile->axis().forward() * (*it)->speed()));
+ }
+ }
+ }
}