diff options
author | Stijn Buys <ingar@osirion.org> | 2012-10-10 21:28:24 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-10-10 21:28:24 +0000 |
commit | fe77356f14255d86fe61130d1939243ce7fc59b1 (patch) | |
tree | 080b455b0a8ceb263ed74ccf204581eb6324a145 | |
parent | 05c560e7b9f508997a7c7c5e466329692796dab4 (diff) |
Added space mine proof of concept.
-rw-r--r-- | src/game/base/Makefile.am | 2 | ||||
-rw-r--r-- | src/game/base/cargopod.cc | 1 | ||||
-rw-r--r-- | src/game/base/game.cc | 10 | ||||
-rw-r--r-- | src/game/base/game.h | 3 | ||||
-rw-r--r-- | src/game/base/spacemine.cc | 133 | ||||
-rw-r--r-- | src/game/base/spacemine.h | 38 |
6 files changed, 185 insertions, 2 deletions
diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am index 89c87d3..ddfa5ae 100644 --- a/src/game/base/Makefile.am +++ b/src/game/base/Makefile.am @@ -15,6 +15,7 @@ noinst_HEADERS = \ savegame.h \ ship.h \ shipmodel.h \ + spacemine.h \ star.h \ station.h \ template.h @@ -31,6 +32,7 @@ libbase_la_SOURCES = \ savegame.cc \ ship.cc \ shipmodel.cc \ + spacemine.cc \ star.cc \ station.cc \ template.cc diff --git a/src/game/base/cargopod.cc b/src/game/base/cargopod.cc index 09e5183..67ae51e 100644 --- a/src/game/base/cargopod.cc +++ b/src/game/base/cargopod.cc @@ -20,6 +20,7 @@ CargoPod::CargoPod() : EntityDynamic() set_flag(core::Entity::KeepAlive); + // setting radius to 0 allows it to be set by the template set_radius(0); // use template settings if available diff --git a/src/game/base/game.cc b/src/game/base/game.cc index c4e354c..f542676 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -23,6 +23,7 @@ #include "base/jumppoint.h" #include "base/planet.h" #include "base/savegame.h" +#include "base/spacemine.h" #include "base/station.h" #include "base/racetrack.h" #include "base/ship.h" @@ -667,6 +668,13 @@ void Game::func_eject(core::Player *player, const std::string &args) aux::to_label(typestr); } + if (g_devel->value()) { + if (typestr.compare("mine") == 0) { + SpaceMine::eject(player->control()); + return; + } + } + if (!(is >> labelstr)) { player->send("Usage: eject [string] [string] [int] eject an item: specify type, label and amount"); return; @@ -684,7 +692,7 @@ void Game::func_eject(core::Player *player, const std::string &args) cargo->eject(player->control(), amount); } else { player->send("Unkown cargo type '" + labelstr + "'"); - } + } } else { player->send("Unkown item type '" + typestr + "'"); } diff --git a/src/game/base/game.h b/src/game/base/game.h index fb64798..6a17d16 100644 --- a/src/game/base/game.h +++ b/src/game/base/game.h @@ -34,7 +34,8 @@ const unsigned int jumppoint_enttype = 260; const unsigned int jumpgate_enttype = 261; const unsigned int station_enttype = 262; const unsigned int cargopod_enttype = 263; -const unsigned int race_enttype = 264; +const unsigned int spacemine_enttype = 264; +const unsigned int race_enttype = 280; // planet docking distance const float planet_safe_distance = 50.0f; diff --git a/src/game/base/spacemine.cc b/src/game/base/spacemine.cc new file mode 100644 index 0000000..74ad185 --- /dev/null +++ b/src/game/base/spacemine.cc @@ -0,0 +1,133 @@ +/* + base/spacemine.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/spacemine.h" +#include "base/game.h" +#include "math/functions.h" + +namespace game +{ + + +SpaceMine::SpaceMine() : EntityDynamic() +{ + entity_moduletypeid = spacemine_enttype; + set_name("Space mine"); + set_label("spacemine"); + + set_flag(core::Entity::KeepAlive); +/* + // setting + set_radius(0); + + // use template settings if available + if (cargopod_template) { + cargopod_template->apply(this); + } + + // radius fallback + if (!radius()) { + if (model()->radius()) { + set_radius(model()->radius()); + } else { + set_radius(0.1f); + } + } +*/ + set_shape(core::Entity::Sphere); + set_radius(0.10f); + + // activate physics + set_mass(radius()); + reset(); + + const float damp = Game::g_damping->value(); + body()->setDamping(damp, damp); +} + +SpaceMine::~SpaceMine() +{ + +} + +void SpaceMine::upkeep(const unsigned long timestamp) +{ + // space mines dissapear on upkeep + die(); +} + +void SpaceMine::collision(core::Entity *other) +{ + if (state() == core::Entity::Destroyed) { + return; + } + + // mines explode on impact + + if (other->moduletype() == ship_enttype) { + Ship *ship = static_cast<Ship *>(other); + + math::Vector3f explosion_direction(ship->location() - location()); + explosion_direction.normalize(); + + math::Vector3f explosion_torque(math::randomf(2.0f) - 1.0f, math::randomf(2.0f) - 1.0f, math::randomf(2.0f) - 1.0f); + + // explosion force has the same magnitude as an impulse engine + // note: this has nothing to do with amount of damage + + ship->body()->applyCentralImpulse(math::to_btVector3(explosion_direction * ship->impulse_force() * 5.0f)); + ship->body()->applyTorqueImpulse(math::to_btVector3(explosion_torque * ship->impulse_force() * 0.1f)); + } + + set_state(core::Entity::Destroyed); + die(); +} + +void SpaceMine::frame(const unsigned long elapsed) +{ + EntityDynamic::frame(elapsed); +} + +// main 'eject mine' function +void SpaceMine::eject(core::EntityControlable *ejector) +{ + if (!ejector->inventory()) { + return; + } + + if ((ejector->state() == core::Entity::Jump) || (ejector->state() == core::Entity::JumpInitiate)) { + if (ejector->owner()) { + ejector->owner()->send("^WCan not eject while hyperspace jump drive is active!"); + } + return; + } else if ((ejector->state() == core::Entity::Impulse) || (ejector->state() == core::Entity::ImpulseInitiate)) { + if (ejector->owner()) { + ejector->owner()->send("^WCan not eject at impulse speed!"); + } + return; + } else if (ejector->state() != core::Entity::Normal) { + return; + } + + // create space mine + SpaceMine *spacemine = new SpaceMine(); + + spacemine->set_color(ejector->color()); + spacemine->set_color_second(ejector->color_second()); + spacemine->set_location(ejector->location() - ejector->axis().forward() * (ejector->radius() + spacemine->radius())); + spacemine->set_axis(ejector->axis()); + spacemine->set_zone(ejector->zone()); + + if (ejector->owner()) { + ejector->owner()->send("Spacemine ejected"); + ejector->owner()->sound("fx/eject"); + } + + spacemine->reset(); +} + +} // namespace game + diff --git a/src/game/base/spacemine.h b/src/game/base/spacemine.h new file mode 100644 index 0000000..cdb903c --- /dev/null +++ b/src/game/base/spacemine.h @@ -0,0 +1,38 @@ +/* + 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_SPACEMINE_H__ +#define __INCLUDED_BASE_SPACEMINE_H__ + +#include "core/entity.h" +#include "base/template.h" + +namespace game +{ + +class SpaceMine : public core::EntityDynamic +{ +public: + SpaceMine(); + virtual ~SpaceMine(); + + virtual void upkeep(const unsigned long timestamp); + + virtual void collision(Entity *other); + + virtual void frame(const unsigned long elapsed); + + static void eject(core::EntityControlable *ejector); + +private: + + unsigned long spacemine_detonated_timestamp; +}; + +} // namespace game + +#endif // __INCLUDED_BASE_SPACEMINE_H__ + |