diff options
Diffstat (limited to 'src/game/base/spacemine.cc')
-rw-r--r-- | src/game/base/spacemine.cc | 133 |
1 files changed, 133 insertions, 0 deletions
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 + |