Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/Makefile.am2
-rw-r--r--src/core/entity.cc39
-rw-r--r--src/core/entity.h28
-rw-r--r--src/core/slot.cc33
-rw-r--r--src/core/slot.h51
-rw-r--r--src/core/slots.cc22
-rw-r--r--src/core/slots.h34
7 files changed, 202 insertions, 7 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 1f1619e..d198cc4 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -31,6 +31,7 @@ noinst_HEADERS = \
player.h \
range.h \
signals.h \
+ slot.h \
slots.h \
stats.h \
uid.h \
@@ -61,6 +62,7 @@ libcore_la_SOURCES = \
physics.cc \
player.cc \
signals.cc \
+ slot.cc \
slots.cc \
stats.cc \
uid.cc \
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 2f23444..3094208 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -168,6 +168,7 @@ Entity::Entity() :
entity_serverside = false;
entity_inventory = 0;
+ entity_slots = 0;
entity_info = 0;
memset(entity_extension, 0, sizeof(entity_extension));
@@ -195,10 +196,9 @@ Entity::Entity(std::istream & is)
entity_destroyed = false;
entity_inventory = 0;
+ entity_slots = 0;
entity_info = 0;
- entity_inventory = 0;
-
memset(entity_extension, 0, sizeof(entity_extension));
}
@@ -218,10 +218,17 @@ Entity::~Entity()
}
menus().clear();
+ // delete equipment slots
+ if (entity_slots) {
+ delete entity_slots;
+ }
+
// delete inventory
- if (entity_inventory)
+ if (entity_inventory) {
delete entity_inventory;
+ }
+ // remove entity from zone
if (entity_zone) {
entity_zone->remove(this);
@@ -230,22 +237,28 @@ Entity::~Entity()
}
}
+ // delete collision shape
if (entity_collision_shape) {
delete entity_collision_shape;
entity_collision_shape = 0;
}
+ // delete child collision shapes
for (CollisionShapes::iterator sit = entity_collision_child_shapes.begin(); sit != entity_collision_child_shapes.end(); sit++) {
delete (*sit);
(*sit) = 0;
}
entity_collision_child_shapes.clear();
- if (entity_body)
+ // delete collision body
+ if (entity_body) {
delete entity_body;
+ }
- if (entity_body_info)
+ // delete collision body construction information
+ if (entity_body_info) {
delete entity_body_info;
+ }
}
void Entity::die()
@@ -279,6 +292,14 @@ Inventory *Entity::add_inventory()
return(entity_inventory);
}
+Slots *Entity::add_slots()
+{
+ if (!entity_slots) {
+ entity_slots = new Slots();
+ }
+ return entity_slots;
+}
+
void Entity::set_zone(Zone *zone)
{
if (entity_zone == zone)
@@ -1100,6 +1121,14 @@ void EntityControlable::set_vstrafe(float vstrafe)
}
}
+void EntityControlable::set_target_aim(const math::Vector3f &aim)
+{
+ if (aim != target_aim) {
+ target_aim.assign(aim);
+ set_dirty();
+ }
+}
+
void EntityControlable::set_afterburner(float afterburner)
{
if (target_afterburner != afterburner) {
diff --git a/src/core/entity.h b/src/core/entity.h
index d071c06..77bc2d8 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -30,6 +30,7 @@ class EntityControlable;
#include "core/label.h"
#include "core/physics.h"
#include "core/player.h"
+#include "core/slots.h"
#include "core/zone.h"
namespace core
@@ -195,6 +196,11 @@ public:
return entity_inventory;
}
+ /// entity weapon slots
+ inline Slots *slots() const {
+ return entity_slots;
+ }
+
/// entity info
inline const Info *info() const {
return entity_info;
@@ -329,12 +335,24 @@ public:
* @brief add an inventory to this entity
* If this entity already has an inventory,
* the current inventory will be return
- */
+ * */
Inventory *add_inventory();
+
+ /**
+ * @brief add equipment slots to this entity
+ * If this entity already has slots,
+ * the current slots will be returned.
+ * */
+ Slots *add_slots();
+ /**
+ * @brief set the information record for this entity
+ * */
void set_info(const Info *info);
- /// set the timestamp when the entity was last alive
+ /**
+ * @brief set the timestamp when the entity was last alive
+ * */
void set_keepalive(unsigned long timestamp) {
entity_keepalive = timestamp;
}
@@ -499,6 +517,7 @@ private:
Menus entity_menus;
Inventory* entity_inventory;
+ Slots* entity_slots;
const Info* entity_info;
Extension* entity_extension[4];
@@ -746,6 +765,9 @@ public:
/// set afterburner/reverse
void set_afterburner(float afterburner);
+
+ /// set aim
+ void set_target_aim(const math::Vector3f &aim);
/**
* @brief runs one game frame for the entity
@@ -793,6 +815,8 @@ protected:
float target_strafe;
float target_vstrafe;
+
+ math::Vector3f target_aim;
int entity_control_flags;
diff --git a/src/core/slot.cc b/src/core/slot.cc
new file mode 100644
index 0000000..1b3e648
--- /dev/null
+++ b/src/core/slot.cc
@@ -0,0 +1,33 @@
+/*
+ core/slot.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2.
+*/
+
+#include "core/slot.h"
+#include "core/item.h"
+
+namespace core
+{
+
+Slot::Slot()
+{
+ slot_item = 0;
+}
+
+Slot::Slot(const math::Vector3f &location)
+{
+ slot_item = 0;
+ slot_location.assign(location);
+}
+
+
+Slot::~Slot()
+{
+ slot_item = 0;
+}
+
+} // namespace core
+
+
+
diff --git a/src/core/slot.h b/src/core/slot.h
new file mode 100644
index 0000000..e99f33c
--- /dev/null
+++ b/src/core/slot.h
@@ -0,0 +1,51 @@
+/*
+ core/slot.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2.
+*/
+
+#ifndef __INCLUDED_CORE_SLOT_H__
+#define __INCLUDED_CORE_SLOT_H__
+
+#include "math/vector3f.h"
+#include "math/axis.h"
+
+#include "core/item.h"
+
+namespace core
+{
+
+/**
+ * @brief A single equipment or weapon slots
+ * */
+class Slot {
+public:
+ Slot();
+ Slot(const math::Vector3f &location);
+
+ ~Slot();
+
+ inline const math::Vector3f &location() {
+ return slot_location;
+ }
+
+
+ inline void set_item(Item *item)
+ {
+ slot_item = item;
+ }
+
+ inline void set_location(const math::Vector3f &location)
+ {
+ slot_location.assign(location);
+ }
+
+private:
+ math::Vector3f slot_location;
+ Item *slot_item;
+};
+
+} // namespace core
+
+#endif // __INCLUDED_CORE_SLOTS_H__
+
diff --git a/src/core/slots.cc b/src/core/slots.cc
index 6ef1d29..afbc29f 100644
--- a/src/core/slots.cc
+++ b/src/core/slots.cc
@@ -4,6 +4,7 @@
the terms of the GNU General Public License version 2.
*/
+#include "sys/sys.h"
#include "core/slots.h"
namespace core
@@ -15,6 +16,27 @@ Slots::Slots()
Slots::~Slots()
{
+ clear();
+}
+
+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());
+ slots_container.push_back(slot);
+ }
+ con_debug << " loaded " << slots_container.size() << " entity slots" << std::endl;
+}
+
+void Slots::clear()
+{
+ for (iterator it = slots_container.begin(); it != slots_container.end(); ++it)
+ {
+ Slot *slot = (*it);
+ delete slot;
+ (*it) = 0;
+ }
+ slots_container.clear();
}
} // namespace core
diff --git a/src/core/slots.h b/src/core/slots.h
index ef1af77..6bb09f1 100644
--- a/src/core/slots.h
+++ b/src/core/slots.h
@@ -7,13 +7,47 @@
#ifndef __INCLUDED_CORE_SLOTS_H__
#define __INCLUDED_CORE_SLOTS_H__
+#include <vector>
+
+#include "model/model.h"
+#include "core/slot.h"
+
namespace core
{
+/**
+ * @brief a collection of entity equipment and weapon slots
+ * */
class Slots {
public:
Slots();
~Slots();
+
+ typedef std::vector<Slot *> Container;
+
+ typedef Container::iterator iterator;
+
+ /**
+ * @brief initialize slots collection from model properties
+ * */
+ void load(model::Model *model);
+
+ /**
+ * @brief remove all slots
+ * */
+ void clear();
+
+ inline iterator begin() {
+ return slots_container.begin();
+ }
+
+ inline iterator end() {
+ return slots_container.end();
+ }
+
+private:
+ Container slots_container;
+
};
} // namespace core