Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-01-01 15:20:14 +0000
committerStijn Buys <ingar@osirion.org>2013-01-01 15:20:14 +0000
commit614ce1267772d67825a32fb7495a049cd6498fe5 (patch)
tree20374ef083b62524e831bce2a8a89fcc70a63f42 /src/model
parent18969b1c444597741547598d35e8f0f97acd39dc (diff)
Initial support for turret-style weapons.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/mapfile.cc15
-rw-r--r--src/model/tags.cc23
-rw-r--r--src/model/tags.h34
3 files changed, 53 insertions, 19 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index 3df2659..e06de58 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -1834,7 +1834,7 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.got_classname("location_cannon")) {
// new cannon slot
- tag_weapon = new Weapon();
+ tag_weapon = new Weapon(Weapon::Cannon);
model->add_weapon(tag_weapon);
continue;
@@ -1848,8 +1848,8 @@ Model * MapFile::load(std::string const &name)
tag_weapon->get_location().assign(location * SCALE);
continue;
- } else if (mapfile.got_key_float("radius", r)) {
- tag_weapon->set_radius(r * SCALE);
+ } else if (mapfile.got_key_float("cone", r)) {
+ tag_weapon->set_cone(r);
continue;
} else if (mapfile.got_key()) {
@@ -1858,10 +1858,10 @@ Model * MapFile::load(std::string const &name)
}
continue;
- } else if (mapfile.got_classname("location_turret")) {
+ } else if (mapfile.got_classname("location_turret")) {
// new turret slot
- tag_weapon = new Weapon();
+ tag_weapon = new Weapon(Weapon::Turret);
model->add_weapon(tag_weapon);
continue;
@@ -1875,8 +1875,8 @@ Model * MapFile::load(std::string const &name)
tag_weapon->get_location().assign(location * SCALE);
continue;
- } else if (mapfile.got_key_float("radius", r)) {
- tag_weapon->set_radius(r * SCALE);
+ } else if (mapfile.got_key_float("cone", r)) {
+ tag_weapon->set_cone(r);
continue;
} else if (mapfile.got_key()) {
@@ -2039,7 +2039,6 @@ Model * MapFile::load(std::string const &name)
for (Model::Weapons::const_iterator wit = submodel_model->weapons().begin(); wit != submodel_model->weapons().end(); wit++) {
tag_weapon = new Weapon(*(*wit));
tag_weapon->get_location().assign(tag_submodel->location() + tag_submodel->axis() * (tag_weapon->location() - submodel_model->origin()) * tag_submodel->scale());
- tag_weapon->set_radius(tag_weapon->radius() * tag_submodel->scale());
model->add_weapon(tag_weapon);
}
diff --git a/src/model/tags.cc b/src/model/tags.cc
index 76f18ce..7e5a393 100644
--- a/src/model/tags.cc
+++ b/src/model/tags.cc
@@ -155,14 +155,15 @@ Sound::~Sound()
/* ---- class Dock ------------------------------------------------- */
-Weapon::Weapon() : Tag()
+Weapon::Weapon(const Type type) : Tag()
{
- weapon_radius = 0.01f;
+ set_type(type);
}
Weapon::Weapon(const Weapon& other) : Tag(other)
{
- weapon_radius = other.radius();
+ weapon_type = other.type();
+ weapon_cone = other.cone();
weapon_axis.assign(other.axis());
}
@@ -170,6 +171,22 @@ Weapon::~Weapon()
{
}
+void Weapon::set_type(const Type type)
+{
+ weapon_type = type;
+ switch (weapon_type) {
+ case Unmountable:
+ weapon_cone = 0.0f;
+ break;
+ case Cannon:
+ weapon_cone = 60.0f; // 60 degrees
+ break;
+ case Turret:
+ weapon_cone = 180.0f; // 180 degrees
+ break;
+ }
+}
+
/* ---- class SubModel---------------------------------------------- */
SubModel::SubModel() : Tag()
diff --git a/src/model/tags.h b/src/model/tags.h
index 200c977..7f7d5d7 100644
--- a/src/model/tags.h
+++ b/src/model/tags.h
@@ -702,10 +702,12 @@ private:
class Weapon : public Tag
{
public:
+ enum Type {Unmountable = 0, Cannon = 1, Turret = 2 };
+
/**
* @brief default constructor
* */
- Weapon();
+ Weapon(const Type type = Cannon);
/**
* @brief copy constructor
@@ -724,19 +726,29 @@ public:
}
/**
- * @brief weapon slot radius, default is 0.01f
+ * @brief weapon fire cone, in degrees
* */
- inline float radius() const
+ inline float cone() const
+ {
+ return weapon_cone;
+ }
+
+ /**
+ * @brief weapon slot type
+ * */
+ inline const Type type() const
{
- return weapon_radius;
+ return weapon_type;
}
+
+ /* ---- mutators ------------------------------------------- */
/**
- * @brief set weapon slot radius
+ * @brief set weapon fire cone, in degrees
* */
- inline void set_radius(const float radius)
+ inline void set_cone(const float cone)
{
- weapon_radius = radius;
+ weapon_cone = cone;
}
/**
@@ -746,6 +758,11 @@ public:
{
weapon_axis.assign(axis);
}
+
+ /**
+ * @brief set weapon slot type
+ * */
+; void set_type(const Type type);
/* ---- actors --------------------------------------------- */
@@ -757,8 +774,9 @@ public:
}
private:
- float weapon_radius;
+ Type weapon_type;
math::Axis weapon_axis;
+ float weapon_cone;
};