From d1931b1ebbe79cbd0f41290acbf9cb6d4c462878 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 22 Apr 2012 19:48:03 +0000 Subject: Load model weapon tags. --- src/model/mapfile.cc | 53 +++++++++++++++++++++++++++++++++++++++++++----- src/model/model.cc | 11 ++++++++++ src/model/model.h | 12 +++++++++++ src/model/tags.cc | 17 ++++++++++++++++ src/model/tags.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 5 deletions(-) (limited to 'src/model') diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index d24a684..fd82036 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -1439,6 +1439,7 @@ Model * MapFile::load(std::string const &name) Light *tag_light = 0; SubModel *tag_submodel = 0; Sound *tag_sound = 0; + Weapon *tag_weapon = 0; std::string modelname; math::Vector3f location; @@ -1828,19 +1829,57 @@ Model * MapFile::load(std::string const &name) } } else if (mapfile.got_classname("location_cannon")) { - // TODO cannon attachment point + + // new cannon slot + tag_weapon = new Weapon(); + model->add_weapon(tag_weapon); continue; } else if (mapfile.classname().compare("location_cannon") == 0) { - // TODO cannon options + + // cannon options + if (mapfile.got_key_axis(tag_weapon->get_axis())) { + continue; + + } else if (mapfile.got_key_vector3f("origin", location)) { + tag_weapon->get_location().assign(location * SCALE); + continue; + + } else if (mapfile.got_key_float("radius", r)) { + tag_weapon->set_radius(r * SCALE); + continue; + + } else if (mapfile.got_key()) { + mapfile.unknown_key(); + + } continue; - } else if (mapfile.got_classname("location_turret")) { - // TODO turret attachment point + } else if (mapfile.got_classname("location_turret")) { + + // new turret slot + tag_weapon = new Weapon(); + model->add_weapon(tag_weapon); continue; } else if (mapfile.classname().compare("location_turret") == 0) { - // TODO turret options + + // turret options + if (mapfile.got_key_axis(tag_weapon->get_axis())) { + continue; + + } else if (mapfile.got_key_vector3f("origin", location)) { + tag_weapon->get_location().assign(location * SCALE); + continue; + + } else if (mapfile.got_key_float("radius", r)) { + tag_weapon->set_radius(r * SCALE); + continue; + + } else if (mapfile.got_key()) { + mapfile.unknown_key(); + + } continue; } else if (mapfile.got_classname("location_cockpit")) { @@ -2031,6 +2070,10 @@ Model * MapFile::load(std::string const &name) for (Model::Docks::iterator dit = model->docks().begin(); dit != model->docks().end(); dit++) { (*dit)->get_location() -= map_center; } + + for (Model::Weapons::iterator wit = model->weapons().begin(); wit != model->weapons().end(); wit++) { + (*wit)->get_location() -= map_center; + } if (mapfile.warning_q2brush) con_warn << mapfile.name() << " quake2 style brushes detected" << std::endl; diff --git a/src/model/model.cc b/src/model/model.cc index 776eba7..f29350f 100644 --- a/src/model/model.cc +++ b/src/model/model.cc @@ -71,6 +71,12 @@ Model::~Model() delete (*sit); } model_sounds.clear(); + + // delete all weapon tags + for (Weapons::iterator wit = model_weapons.begin(); wit != model_weapons.end(); wit++) { + delete (*wit); + } + model_weapons.clear(); } void Model::set_collisionmodel(CollisionModel *collisionmodel) @@ -118,6 +124,11 @@ void Model::add_dock(Dock *dock) model_docks.push_back(dock); } +void Model::add_weapon(Weapon *weapon) +{ + model_weapons.push_back(weapon); +} + Model *Model::find(const std::string & name) { Registry::iterator it = model_registry.find(name); diff --git a/src/model/model.h b/src/model/model.h index c15213c..a33e365 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -51,6 +51,9 @@ public: /// type definition for a list of model sound tags typedef std::list Sounds; + + /// type definition for a list of model weapon tags + typedef std::list Weapons; /// type definition for a list of FragmentGroups typedef std::list Groups; @@ -99,6 +102,11 @@ public: inline Sounds & sounds() { return model_sounds; } + + /// list of model weapon tags + inline Weapons & weapons() { + return model_weapons; + } /// list of model particle system tags inline ParticleSystems & particles() { @@ -140,6 +148,9 @@ public: /// add a docking location tag to the model void add_dock(Dock *dock); + + /// add a weapon slot tag to the model + void add_weapon(Weapon *weapon); /// add a sound tag to the model void add_sound(Sound *sound); @@ -203,6 +214,7 @@ private: Sounds model_sounds; Lights model_lights; ParticleSystems model_particles; + Weapons model_weapons; Groups model_groups; float model_radius; static Registry model_registry; diff --git a/src/model/tags.cc b/src/model/tags.cc index 5993f99..75580e5 100644 --- a/src/model/tags.cc +++ b/src/model/tags.cc @@ -149,6 +149,23 @@ Sound::~Sound() { } +/* ---- class Dock ------------------------------------------------- */ + +Weapon::Weapon() : Tag() +{ + weapon_radius = 0.01f; +} + +Weapon::Weapon(const Weapon& other) : Tag(other) +{ + weapon_radius = other.radius(); + weapon_axis.assign(other.axis()); +} + +Weapon::~Weapon() +{ +} + /* ---- class SubModel---------------------------------------------- */ SubModel::SubModel() : Tag() diff --git a/src/model/tags.h b/src/model/tags.h index 586fd21..ff95954 100644 --- a/src/model/tags.h +++ b/src/model/tags.h @@ -556,6 +556,63 @@ private: math::Axis submodel_axis; }; +/* ---- class Weapon ----------------------------------------------- */ + +/** + * @brief a weapon slot tag + * */ +class Weapon : public Tag +{ +public: + /** + * @brief default constructor + */ + Weapon(); + + /** + * @brief copy constructor + */ + Weapon(const Weapon& other); + + /** + * @brief destructor + */ + ~Weapon(); + + inline const math::Axis &axis() const { + return weapon_axis; + } + + /// weapon slot radius, default is 0.01f + inline float radius() const { + return weapon_radius; + } + + /// set weapon slot radius + inline void set_radius(const float radius) { + weapon_radius = radius; + } + + /// set weapon slot axis + inline void set_axis(const math::Axis& axis) { + weapon_axis.assign(axis); + } + + /* ---- actors --------------------------------------------- */ + + /** + * @brief mutable reference to the axis + */ + inline math::Axis& get_axis() { + return weapon_axis; + } + +private: + float weapon_radius; + math::Axis weapon_axis; +}; + + } #endif // __INCLUDED_MODEL_PARTS_H__ -- cgit v1.2.3