Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-03-03 23:15:39 +0000
committerStijn Buys <ingar@osirion.org>2012-03-03 23:15:39 +0000
commit8fbb2425220389ee69749ccd93407a0db73678fd (patch)
tree3ef7b7615711f9dd552760fbf0c26a801421082b
parentf0a4a7d7213b61714542d64a7559648a086df26a (diff)
Added core::Slots class template, replaced Entity::set_inventory() with Entity::add_inventory().
-rw-r--r--src/core/Makefile.am2
-rw-r--r--src/core/entity.cc10
-rw-r--r--src/core/entity.h24
-rw-r--r--src/core/slots.cc23
-rw-r--r--src/core/slots.h22
-rw-r--r--src/game/base/cargo.cc2
-rw-r--r--src/game/base/game.cc8
-rw-r--r--src/game/base/ship.cc2
8 files changed, 72 insertions, 21 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 0c8036e..1f1619e 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -31,6 +31,7 @@ noinst_HEADERS = \
player.h \
range.h \
signals.h \
+ slots.h \
stats.h \
uid.h \
zone.h
@@ -60,6 +61,7 @@ libcore_la_SOURCES = \
physics.cc \
player.cc \
signals.cc \
+ slots.cc \
stats.cc \
uid.cc \
zone.cc
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 4a6528f..2f23444 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -271,12 +271,12 @@ void Entity::set_info(const Info *info)
entity_info = info;
}
-void Entity::set_inventory(Inventory *inventory)
+Inventory *Entity::add_inventory()
{
- if (entity_inventory && (entity_inventory != inventory)) {
- delete entity_inventory;
- }
- entity_inventory = inventory;
+ if (!entity_inventory) {
+ entity_inventory = new Inventory();
+ }
+ return(entity_inventory);
}
void Entity::set_zone(Zone *zone)
diff --git a/src/core/entity.h b/src/core/entity.h
index 94cd09f..d071c06 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -190,7 +190,7 @@ public:
return entity_visible;
}
- ///entity inventory
+ /// entity inventory
inline Inventory *inventory() const {
return entity_inventory;
}
@@ -327,11 +327,12 @@ public:
/**
* @brief add an inventory to this entity
- * Entity takes ownership over the inventory pointer
+ * If this entity already has an inventory,
+ * the current inventory will be return
*/
- void set_inventory(Inventory *inventory);
-
- void set_info(const Info *info);
+ Inventory *add_inventory();
+
+ void set_info(const Info *info);
/// set the timestamp when the entity was last alive
void set_keepalive(unsigned long timestamp) {
@@ -617,7 +618,7 @@ class EntityControlable : public EntityDynamic
public:
/// control flags
- enum ControlFlags {ControlFlagNone = 0, ControlFlagImpulse = 1};
+ enum ControlFlags {ControlFlagNone = 0, ControlFlagFire = 1};
/// bullet action interface class
class ActionInterface: public btActionInterface {
@@ -659,9 +660,14 @@ public:
}
/// control flags
- inline unsigned int control_flags() const {
+ inline int control_flags() const {
return entity_control_flags;
}
+
+ /// returns true if the specified control flag is set
+ inline bool control_flag_is_set(ControlFlags flag) const {
+ return ((flag && entity_control_flags) == flag);
+ }
/// physics action
inline ActionInterface *actioninterface() {
@@ -682,7 +688,7 @@ public:
/*----- mutators -------------------------------------------------- */
/// set all control flags
- inline void set_control_flags(unsigned int control_flags) {
+ inline void set_control_flags(int control_flags) {
entity_control_flags = control_flags;
}
@@ -788,7 +794,7 @@ protected:
float target_vstrafe;
- unsigned int entity_control_flags;
+ int entity_control_flags;
ActionInterface *entity_actioninterface;
diff --git a/src/core/slots.cc b/src/core/slots.cc
new file mode 100644
index 0000000..6ef1d29
--- /dev/null
+++ b/src/core/slots.cc
@@ -0,0 +1,23 @@
+/*
+ core/slots.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/slots.h"
+
+namespace core
+{
+
+Slots::Slots()
+{
+}
+
+Slots::~Slots()
+{
+}
+
+} // namespace core
+
+
+
diff --git a/src/core/slots.h b/src/core/slots.h
new file mode 100644
index 0000000..ef1af77
--- /dev/null
+++ b/src/core/slots.h
@@ -0,0 +1,22 @@
+/*
+ core/slots.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_SLOTS_H__
+#define __INCLUDED_CORE_SLOTS_H__
+
+namespace core
+{
+
+class Slots {
+public:
+ Slots();
+ ~Slots();
+};
+
+} // namespace core
+
+#endif // __INCLUDED_CORE_SLOTS_H__
+
diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc
index 7909e55..706bf84 100644
--- a/src/game/base/cargo.cc
+++ b/src/game/base/cargo.cc
@@ -375,7 +375,7 @@ void Cargo::eject(core::EntityControlable *ejector, const int amount)
pod->set_info(item->info());
// add loot to inventory
- pod->set_inventory(new core::Inventory());
+ pod->add_inventory();
pod->inventory()->set_capacity(item->info()->volume() * negotiated_amount);
core::Item *loot = new core::Item(item->info());
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 0610377..d8af507 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -1224,8 +1224,7 @@ bool Game::load_zone(core::Zone *zone)
} else {
inventory = entity->inventory();
if (!inventory) {
- inventory = new core::Inventory();
- entity->set_inventory(inventory);
+ inventory = entity->add_inventory();
}
}
@@ -1238,11 +1237,10 @@ bool Game::load_zone(core::Zone *zone)
zoneini.unknown_error("ship definition without entity");
} else if ((entity->moduletype() != planet_enttype) && (entity->moduletype() != station_enttype)) {
zoneini.unknown_error("ship definition for invalid entity type");
- } else {
+ } else {
inventory = entity->inventory();
if (!inventory) {
- inventory = new core::Inventory();
- entity->set_inventory(inventory);
+ inventory = entity->add_inventory();
}
}
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index e5ae2fe..9a6d02e 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -72,7 +72,7 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
set_label(str);
// add an inventory
- set_inventory(new core::Inventory());
+ add_inventory();
inventory()->set_capacity(ship_shipmodel->maxcargo());
}