Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-11-21 20:49:58 +0000
committerStijn Buys <ingar@osirion.org>2012-11-21 20:49:58 +0000
commit5e4ef80dc29a69e1f5f185d1efab323af4a77292 (patch)
tree3f741a160a9f62d392ef0116df9f9925d55da557 /src
parent3dc60689b9327190eeecd42f6920299ef3e7b52c (diff)
Added get/set methods for the weapon-slot API.
Diffstat (limited to 'src')
-rw-r--r--src/core/entity.cc1
-rw-r--r--src/core/slot.cc53
-rw-r--r--src/core/slot.h137
-rw-r--r--src/core/slots.cc4
-rw-r--r--src/game/base/ship.cc40
-rw-r--r--src/game/base/weapon.cc55
-rw-r--r--src/game/base/weapon.h80
7 files changed, 268 insertions, 102 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index a53f8b8..462a46d 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -877,6 +877,7 @@ void EntityDynamic::reset()
}
/* Does not work
+ * Note: does not do what you'd think it does
if (entity_mass) {
diff --git a/src/core/slot.cc b/src/core/slot.cc
index ace3be2..bb7b622 100644
--- a/src/core/slot.cc
+++ b/src/core/slot.cc
@@ -18,36 +18,44 @@ Slot::Slot()
slot_timestamp = 0;
slot_last_fired = 0;
- slot_interval = 0;
- slot_lifespan = 0;
- slot_speed = 0.0f;
+ slot_projectile_interval = 0;;
+ slot_projectile_lifespan = 0;
+ slot_projectile_speed = 0.0f;
+ slot_projectile_damage = 0.0f;
+}
-
+Slot::~Slot()
+{
}
-Slot::Slot(const math::Vector3f & location) :
- slot_location(location)
+void Slot::set_projectile_speed(const float projectile_speed)
{
- slot_item = 0;
- slot_flags = 0;
- slot_timestamp = 0;
- slot_last_fired = 0;
-
- slot_interval = 0;;
- slot_lifespan = 0;
- slot_speed = 0.0f;
+ slot_projectile_speed = projectile_speed;
+ set_timestamp(game() ? game()->timestamp() : 1);
}
-Slot::~Slot()
+void Slot::set_projectile_interval(unsigned long projectile_interval)
{
- slot_item = 0;
- slot_flags = 0;
- slot_timestamp = 0;
- slot_last_fired = 0;
+ slot_projectile_interval = projectile_interval;
+ set_timestamp(game() ? game()->timestamp() : 1);
+}
+
+void Slot::set_projectile_lifespan(unsigned long projectile_lifespan)
+{
+ slot_projectile_lifespan = projectile_lifespan;
+ set_timestamp(game() ? game()->timestamp() : 1);
+}
- slot_interval = 0;
- slot_lifespan = 0;
- slot_speed = 0.0f;
+void Slot::set_projectile_damage(const float projectile_damage)
+{
+ slot_projectile_damage = projectile_damage;
+ set_timestamp(game() ? game()->timestamp() : 1);
+}
+
+void Slot::set_projectile_modelname(const std::string & projectile_modelname)
+{
+ slot_projectile_modelname.assign(projectile_modelname);
+ set_timestamp(game() ? game()->timestamp() : 1);
}
void Slot::set_item(Item *item)
@@ -57,4 +65,3 @@ void Slot::set_item(Item *item)
}
} // namespace core
-
diff --git a/src/core/slot.h b/src/core/slot.h
index 6b6c47b..2d636b3 100644
--- a/src/core/slot.h
+++ b/src/core/slot.h
@@ -29,12 +29,7 @@ public:
* Creates an empty slot
* */
Slot();
-
- /**
- * @brief creates and empty slot at a given location
- * */
- Slot(const math::Vector3f & location);
-
+
/**
* @brief default destructor
* */
@@ -55,32 +50,63 @@ public:
{
return slot_axis;
}
-
- /**
- * @brief the name of the particlesystem used to render
- * projectiles generated by this slot
- * */
/**
+ * @brief timestamp indicating when the slot was last fired,server-side
+ * This is a server-side property
* */
inline unsigned long last_fired() const
{
return slot_last_fired;
}
- inline unsigned long interval() const
+ /**
+ * @brief timestamp indicating when the slot was last fire, client-side
+ * This is a client-side property
+ * */
+ inline unsigned long last_ejected() const
+ {
+ return slot_last_ejected;
+ }
+
+ /**
+ * @brief interval between two consequtive shots by this slot, in milliseconds
+ * */
+ inline unsigned long projectile_interval() const
{
- return slot_interval;
+ return slot_projectile_interval;
}
- inline unsigned long lifespan() const
+ /**
+ * @brief lifespan of a projectile generated by this slot, in milliseconds
+ * */
+ inline unsigned long projectile_lifespan() const
{
- return slot_lifespan;
+ return slot_projectile_lifespan;
}
- inline float speed() const
+ /**
+ * @brief speed of a projectile generated by this slot, in game units per second
+ * */
+ inline float projectile_speed() const
{
- return slot_speed;
+ return slot_projectile_speed;
+ }
+
+ /**
+ * @brief damage done by a projectile generated by this slot
+ * */
+ inline float projectile_damage() const
+ {
+ return slot_projectile_damage;
+ }
+
+ /**
+ * @brief model name used to draw projectiles generated by this slot
+ * */
+ inline const std::string & projectile_modelname() const
+ {
+ return slot_projectile_modelname;
}
/* --- mutators -------------------------------------------- */
@@ -111,27 +137,46 @@ public:
}
/**
- * @brief
+ * @brief set the timestamp when the slot last ejected a projectile, server-side
+ * This is a server-side property, to be set by the game module
* */
inline void set_last_fired(unsigned long last_fired)
{
slot_last_fired = last_fired;
}
- inline void set_interval(unsigned long interval)
+ /**
+ * @brief set the timestamp when the slat last ejected a projectile, client-side
+ * This is a client-side property, to be set by the client
+ * */
+ inline void set_last_ejected(unsigned long last_ejected)
{
- slot_interval = interval;
+ slot_last_ejected = last_ejected;
}
- inline void set_lifespan(unsigned long lifespan)
- {
- slot_lifespan = lifespan;
- }
+ /**
+ * @brief set the interval between two shots, in milliseconds
+ * */
+ void set_projectile_interval(unsigned long projectile_interval);
- inline void set_speed(float speed)
- {
- slot_speed = speed;
- }
+ /**
+ * @brief set the lifespan of ejected projectiles, in milliseconds
+ * */
+ void set_projectile_lifespan(unsigned long projectile_lifespan);
+
+ /**
+ * @brief set the speed of ejected projectiles, in game units per second
+ * */
+ void set_projectile_speed(float projectile_speed);
+
+ /**
+ * @brief set the amount of damage done by a projectile generated by this slot
+ * */
+ void set_projectile_damage(float projectile_damage);
+ /**
+ * @brief set the name of model used to draw projectiles generated by this slot
+ * */
+ void set_projectile_modelname(const std::string & projectile_modelname);
/**
* @brief set the item this slot is holding
@@ -139,33 +184,41 @@ public:
void set_item(Item *item);
private:
- math::Vector3f slot_location;
+ math::Vector3f slot_location;
- math::Axis slot_axis;
+ math::Axis slot_axis;
// slot flags
- unsigned int slot_flags;
+ unsigned int slot_flags;
+
+ // timestamp indicating when the slot configuration was last changed
+ unsigned long slot_timestamp;
- unsigned long slot_timestamp;
+ // timestamp indicating when the slot last generated a projectile, server-side
+ unsigned long slot_last_fired;
- unsigned long slot_last_fired;
+ // timestamp indicating when the slot last generated a projectile, client-side
+ unsigned long slot_last_ejected;
// interval between two shots, in milliseconds
- unsigned long slot_interval;
+ unsigned long slot_projectile_interval;
- // projectile lifespane
- unsigned long slot_lifespan;
+ // projectile lifespan
+ unsigned long slot_projectile_lifespan;
- // projectile speed, in gameunits / second
- float slot_speed;
+ // projectile speed, in game units per second
+ float slot_projectile_speed;
- // item mounted in this slot
- Item *slot_item;
+ // projectile damage
+ float slot_projectile_damage;
+
+ // name of the model used to draw projectiles generated by this slot
+ std::string slot_projectile_modelname;
- std::string slot_particlesystem_name;
+ // item mounted in this slot
+ Item *slot_item;
};
} // namespace core
#endif // __INCLUDED_CORE_SLOTS_H__
-
diff --git a/src/core/slots.cc b/src/core/slots.cc
index 031aba2..9bf557f 100644
--- a/src/core/slots.cc
+++ b/src/core/slots.cc
@@ -22,7 +22,9 @@ Slots::~Slots()
void Slots::load(model::Model *model)
{
for (model::Model::Weapons::iterator it = model->weapons().begin(); it != model->weapons().end(); ++it) {
- Slot *slot = new Slot((*it)->location());
+ Slot *slot = new Slot();
+ slot->set_location((*it)->location());
+ slot->set_axis((*it)->axis());
slots_container.push_back(slot);
}
//con_debug << " loaded " << slots_container.size() << " entity slots" << std::endl;
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index dc039e4..7282fe1 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -88,9 +88,10 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
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);
+ (*it)->set_projectile_interval(1000);
+ (*it)->set_projectile_lifespan(5000);
+ (*it)->set_projectile_speed(5.0f);
+ (*it)->set_projectile_damage(10.0f);
}
}
@@ -442,6 +443,7 @@ void Ship::action (btScalar seconds)
entity_speed = Game::g_impulsespeed->value() * 0.01f;
body()->setLinearVelocity(math::to_btVector3(axis().forward() * entity_speed));
}
+ // FIXME set speed to 0 if below threshold
}
void Ship::collision(core::Entity *other)
@@ -867,27 +869,31 @@ void Ship::frame(const unsigned long elapsed)
EntityControlable::frame(elapsed);
+
+ // TODO move to core::
if (model() && slots() && (state() == core::Entity::Normal) && 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_damage(10.0f);
- projectile->set_color(color());
- if (owner()) {
- projectile->set_ownerid(owner()->id());
+ if ((*it)->projectile_interval() > 0) {
+ if ((*it)->last_fired() + (*it)->projectile_interval() <= core::server()->timestamp()) {
+ (*it)->set_last_fired(core::server()->timestamp());
+ Projectile * projectile = new Projectile((*it)->projectile_lifespan());
+ projectile->set_damage((*it)->projectile_damage());
+ projectile->set_color(color());
+ if (owner()) {
+ projectile->set_ownerid(owner()->id());
+ }
+ 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)->projectile_speed()));
}
- 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()));
}
}
}
diff --git a/src/game/base/weapon.cc b/src/game/base/weapon.cc
index ec87b34..b4d236d 100644
--- a/src/game/base/weapon.cc
+++ b/src/game/base/weapon.cc
@@ -76,17 +76,18 @@ bool Weapon::init()
weapon->set_volume(f);
continue;
- } else if (weaponsini.got_key_float("damage", f)) {
- weapon->set_damage(f);
- continue;
-
} else if (weaponsini.got_key_long("level", l)) {
weapon->set_level(l);
continue;
+
+ } else if (weaponsini.got_key_float("damage", f)) {
+ weapon->set_damage(f);
+ continue;
} else {
weaponsini.unknown_key();
}
+
} else if (weaponsini.section().compare("cannon") == 0) {
if (weaponsini.got_key_label("label", str)) {
weapon->set_label(str);
@@ -112,10 +113,6 @@ bool Weapon::init()
weapon->set_volume(f);
continue;
- } else if (weaponsini.got_key_float("damage", f)) {
- weapon->set_damage(f);
- continue;
-
} else if (weaponsini.got_key_long("level", l)) {
weapon->set_level(l);
continue;
@@ -147,11 +144,7 @@ bool Weapon::init()
} else if (weaponsini.got_key_float("volume", f)) {
weapon->set_volume(f);
continue;
-
- } else if (weaponsini.got_key_float("damage", f)) {
- weapon->set_damage(f);
- continue;
-
+
} else if (weaponsini.got_key_long("level", l)) {
weapon->set_level(l);
continue;
@@ -159,8 +152,35 @@ bool Weapon::init()
} else {
weaponsini.unknown_key();
}
+
+ } else if (weaponsini.section().compare("projectile") == 0) {
+
+ if (weapon) {
+ if (weaponsini.got_key_float("speed", f)) {
+ // speed is in meters / second, one gameunit is 100 meters
+ weapon->set_projectile_speed(f * 0.01f);
+ continue;
+
+ } else if (weaponsini.got_key_long("interval", l)) {
+ weapon->set_projectile_interval((unsigned long) l);
+ continue;
+
+ } else if (weaponsini.got_key_long("lifespan", l)) {
+ weapon->set_projectile_lifespan((unsigned long) l);
+ continue;
+
+ } else if (weaponsini.got_key_float("damage", f)) {
+ weapon->set_damage(f);
+ continue;
+
+ } else if (weaponsini.got_key_string("model", str)) {
+ weapon->set_projectile_modelname(str);
+ continue;
+ }
+ }
}
+
} else if (weaponsini.got_section()) {
if (weaponsini.got_section("mine")) {
@@ -181,6 +201,11 @@ bool Weapon::init()
weapon->set_subtype(Turret);
count++;
+ } else if (weaponsini.got_section("projectile")) {
+ if (!weapon) {
+ weaponsini.unknown_error("projectile section without weapon section");
+ }
+
} else if (weaponsini.got_section()) {
weaponsini.unknown_section();
}
@@ -226,6 +251,10 @@ Weapon::Weapon() : core::Info(weapon_infotype)
set_level(1);
set_stackable(false);
set_subtype(Ammo);
+ set_damage(0);
+ set_projectile_interval(0);
+ set_projectile_lifespan(0);
+ set_projectile_speed(0);
}
Weapon::~Weapon()
diff --git a/src/game/base/weapon.h b/src/game/base/weapon.h
index ba28810..94fdce6 100644
--- a/src/game/base/weapon.h
+++ b/src/game/base/weapon.h
@@ -24,10 +24,14 @@ public:
inline SubType subtype() const {
return weapon_subtype;
}
+
inline bool stackable() const {
return weapon_stackable;
}
+ /**
+ * @brief player level required to buy this weapon
+ * */
inline int level() const {
return weapon_level;
}
@@ -39,23 +43,79 @@ public:
{
return weapon_damage;
}
-
- /* --- mutators -------------------------------------------- */
-
+
/**
- * @brief set the amount of damage this weapon inflicts
+ * @brief speed of projectiles generated by this weapon
* */
- inline void set_damage(const float damage)
+ inline const float projectile_speed() const
{
- weapon_damage = damage;
+ return weapon_projectile_speed;
}
+ /**
+ * @brief interval between consequtive projectils fired by this weapon, in milliseconds
+ * */
+ inline const unsigned long projectile_interval() const
+ {
+ return weapon_projectile_interval;
+ }
+
+ /**
+ * @brief name of the model used for projectiles generated by this weapon
+ * */
+ inline const std::string & projectile_modelname() const
+ {
+ return weapon_projectile_modelname;
+ }
+
+ /* --- mutators -------------------------------------------- */
+
void set_stackable(bool stackable);
void set_level(const int level);
void set_subtype(const SubType subtype);
+ /**
+ * @brief set the projectile lifespan, in milliseconds
+ * */
+ inline void set_projectile_lifespan(const unsigned long projectile_lifespan)
+ {
+ weapon_projectile_lifespan = projectile_lifespan;
+ }
+
+ /**
+ * @brief set the interval between two consecutive shots by this weapon
+ * */
+ inline void set_projectile_interval(const unsigned long projectile_interval)
+ {
+ weapon_projectile_interval = projectile_interval;
+ }
+
+ /**
+ * @brief set_projectile speed, in game units per second
+ * */
+ inline void set_projectile_speed(const float projectile_speed)
+ {
+ weapon_projectile_speed = projectile_speed;
+ }
+
+ /**
+ * @brief set the amount of damage this weapon inflicts
+ * */
+ inline void set_damage(const float damage)
+ {
+ weapon_damage = damage;
+ }
+
+ /**
+ * @brief set_projectile model name
+ * */
+ inline void set_projectile_modelname(const std::string & projectile_modelname)
+ {
+ weapon_projectile_modelname.assign(projectile_modelname);
+ }
+
/* --- static registry functions ---------------------------------- */
static Weapon *find(const std::string & label);
@@ -79,7 +139,15 @@ private:
bool weapon_stackable;
+ unsigned long weapon_projectile_interval;
+
+ unsigned long weapon_projectile_lifespan;
+
+ float weapon_projectile_speed;
+
float weapon_damage;
+
+ std::string weapon_projectile_modelname;
};
} // namespace game