From 4798ff98e23a8f56622b8ca448b997b84ecbd7d5 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 14 Oct 2012 10:25:33 +0000 Subject: Add a stackable flag for weapons, load a default model for spacemines. --- src/game/base/spacemine.cc | 18 +++++++++++++++++- src/game/base/weapon.cc | 4 ++++ src/game/base/weapon.h | 12 ++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src/game') diff --git a/src/game/base/spacemine.cc b/src/game/base/spacemine.cc index 75fe8fa..fbbca51 100644 --- a/src/game/base/spacemine.cc +++ b/src/game/base/spacemine.cc @@ -37,8 +37,11 @@ SpaceMine::SpaceMine() : EntityDynamic() } } */ + // FIXME should be loaded from the Weapon Info set_shape(core::Entity::Sphere); + set_modelname("maps/static/cargopod001"); set_radius(0.10f); + spacemine_detonated_timestamp = 0; // activate physics set_mass(radius()); @@ -80,15 +83,28 @@ void SpaceMine::collision(core::Entity *other) entity->body()->applyCentralImpulse(math::to_btVector3(explosion_direction * force )); entity->body()->applyTorqueImpulse(math::to_btVector3(explosion_torque * force * 0.1f)); + + spacemine_detonated_timestamp = core::game()->time(); } set_state(core::Entity::Destroyed); - die(); + // this method is a bullet callback, we can not reset() here } void SpaceMine::frame(const unsigned long elapsed) { EntityDynamic::frame(elapsed); + + if (state() == core::Entity::Destroyed) { + + if (body()) { + reset(); + } + + if (core::game()->time() - spacemine_detonated_timestamp > 5) { + die(); + } + } } // main 'eject mine' function diff --git a/src/game/base/weapon.cc b/src/game/base/weapon.cc index 8eca691..7f816e2 100644 --- a/src/game/base/weapon.cc +++ b/src/game/base/weapon.cc @@ -152,14 +152,17 @@ bool Weapon::init() if (weaponsini.got_section("mine")) { weapon = new Weapon(); + weapon->set_stackable(true); count++; } else if (weaponsini.got_section("cannon")) { weapon = new Weapon(); + weapon->set_stackable(false); count++; } else if (weaponsini.got_section("turret")) { weapon = new Weapon(); + weapon->set_stackable(false); count++; } else if (weaponsini.got_section()) { @@ -190,6 +193,7 @@ Weapon::Weapon() : core::Info(weapon_infotype) { set_volume(1); set_level(1); + set_stackable(false); } Weapon::~Weapon() diff --git a/src/game/base/weapon.h b/src/game/base/weapon.h index 4e99493..b263266 100644 --- a/src/game/base/weapon.h +++ b/src/game/base/weapon.h @@ -17,16 +17,22 @@ public: Weapon(); ~Weapon(); + inline bool stackable() const { + return weapon_stackable; + } + inline int level() const { return weapon_level; } + inline void set_stackable(bool stackable) { + weapon_stackable = stackable; + } + inline void set_level(const int level) { weapon_level = level; } - - /* --- static registry functions ---------------------------------- */ static Weapon *find(const std::string & label); @@ -45,6 +51,8 @@ private: static core::InfoType *weapon_infotype; int weapon_level; + + bool weapon_stackable; }; } // namespace game -- cgit v1.2.3