xoreos  0.0.5
objectcontainer.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/types.h"
26 #include "src/common/util.h"
27 
31 #include "src/engines/jade/area.h"
36 #include "src/engines/jade/event.h"
37 
38 namespace Engines {
39 
40 namespace Jade {
41 
43  target.getPosition(xt, yt, zt);
44 }
45 
47  return getDistance(*a) < getDistance(*b);
48 }
49 
51  float x, y, z;
52  a.getPosition(x, y, z);
53 
54  return ABS(x - xt) + ABS(y - yt) + ABS(z - zt);
55 }
56 
57 
58 class SearchType : public ::Aurora::NWScript::SearchRange< std::list<Jade::Object *> > {
59 public:
60  SearchType(const iterator &a, const iterator &b) : ::Aurora::NWScript::SearchRange<type>(std::make_pair(a, b)) { }
61  SearchType(const type &l) : ::Aurora::NWScript::SearchRange<type>(std::make_pair(l.begin(), l.end())) { }
63 
64  ::Aurora::NWScript::Object *getObject(const iterator &t) { return *t; }
65 };
66 
67 
69 }
70 
72 }
73 
75  lock();
76 
77  for (size_t i = 0; i < kObjectTypeMAX; i++)
78  _objects[i].clear();
79 
81 
82  unlock();
83 }
84 
86  lock();
87 
89 
90  ObjectType type = object.getType();
91  if (((uint) type) < kObjectTypeMAX)
92  _objects[type].push_back(&object);
93 
94  unlock();
95 }
96 
98  lock();
99 
100  ObjectType type = object.getType();
101  if (((uint) type) < kObjectTypeMAX)
102  _objects[type].remove(&object);
103 
105 
106  unlock();
107 }
108 
110  if (((uint) type) >= kObjectTypeMAX)
111  return 0;
112 
113  SearchType ctx(_objects[type]);
114 
115  return ctx.get();
116 }
117 
119  if (((uint) type) >= kObjectTypeMAX)
120  return new SearchType(_objects[0].end(), _objects[0].end());
121 
122  return new SearchType(_objects[type]);
123 }
124 
126  return dynamic_cast<Jade::Object *>(object);
127 }
128 
130  return dynamic_cast<Area *>(object);
131 }
132 
134  return dynamic_cast<Waypoint *>(object);
135 }
136 
138  return dynamic_cast<Placeable *>(object);
139 }
140 
142  return dynamic_cast<Creature *>(object);
143 }
144 
146  Creature *pc = dynamic_cast<Creature *>(object);
147  if (!pc || !pc->isPC())
148  return 0;
149 
150  return pc;
151 }
152 
154  return dynamic_cast<Location *>(engineType);
155 }
156 
158  return dynamic_cast<Event *>(engineType);
159 }
160 
161 } // End of namespace Jade
162 
163 } // End of namespace Engines
An object within a Jade Empire area.
::Aurora::NWScript::ObjectSearch * findObjectsByType(ObjectType type) const
Return a search context to iterate over all objects of this type.
T ABS(T x)
Definition: util.h:69
A scripting event.
void addObject(Jade::Object &object)
Add an object to this container.
std::list< Jade::Object * > ::const_iterator iterator
A waypoint in a Jade Empire area.
static Creature * toCreature(Aurora::NWScript::Object *object)
A placeable in a Jade Empire area.
void removeObject(Jade::Object &object)
Remove an object from this container.
static Placeable * toPlaceable(Aurora::NWScript::Object *object)
STL namespace.
static Waypoint * toWaypoint(Aurora::NWScript::Object *object)
static Creature * toPC(Aurora::NWScript::Object *object)
static Event * toEvent(Aurora::NWScript::EngineType *engineType)
A container of Jade Empire objects.
bool operator()(Jade::Object *a, Jade::Object *b)
static Jade::Object * toObject(::Aurora::NWScript::Object *object)
Utility templates and functions.
An area in Jade Empire, holding all objects and rooms within, as well as general area properties like...
Definition: area.h:57
::Aurora::NWScript::Object * getObject(const iterator &t)
Low-level type definitions to handle fixed width types portably.
void removeObject(Object &object)
Remove an object from this container.
Object * get()
Return the current object in the search context.
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:142
An area.
An object within a Jade area.
Definition: object.h:53
A location within a Jade Empire area.
::Aurora::NWScript::Object * getFirstObjectByType(ObjectType type) const
Return the first object of this type.
ObjectList _objects[kObjectTypeMAX]
static Area * toArea(Aurora::NWScript::Object *object)
A module.
static Location * toLocation(Aurora::NWScript::EngineType *engineType)
float getDistance(Jade::Object &a)
ObjectDistanceSort(const Jade::Object &target)
bool isPC() const
Is the creature a player character?
Definition: creature.cpp:70
unsigned int uint
Definition: types.h:211
SearchType(const iterator &a, const iterator &b)
void addObject(Object &object)
Add an object to this container.
A creature in a Jade Empire area.