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 
35 
36 namespace Engines {
37 
38 namespace DragonAge2 {
39 
41  target.getPosition(xt, yt, zt);
42 }
43 
45  return getDistance(*a) < getDistance(*b);
46 }
47 
49  float x, y, z;
50  a.getPosition(x, y, z);
51 
52  return ABS(x - xt) + ABS(y - yt) + ABS(z - zt);
53 }
54 
55 
56 class SearchType : public ::Aurora::NWScript::SearchRange< std::list<DragonAge2::Object *> > {
57 public:
58  SearchType(const iterator &a, const iterator &b) : ::Aurora::NWScript::SearchRange<type>(std::make_pair(a, b)) { }
59  SearchType(const type &l) : ::Aurora::NWScript::SearchRange<type>(std::make_pair(l.begin(), l.end())) { }
61 
62  ::Aurora::NWScript::Object *getObject(const iterator &t) { return *t; }
63 };
64 
65 
67 }
68 
70 }
71 
73  lock();
74 
75  _objects.clear();
76 
78 
79  unlock();
80 }
81 
83  lock();
84 
86 
87  _objects[object.getType()].push_back(&object);
88 
89  unlock();
90 }
91 
93  lock();
94 
95  _objects[object.getType()].remove(&object);
96 
98 
99  unlock();
100 }
101 
103  ObjectMap::const_iterator l = _objects.find(type);
104  if (l == _objects.end())
105  return 0;
106 
107  SearchType ctx(l->second);
108 
109  return ctx.get();
110 }
111 
113  static const ObjectList kEmptyObjectList;
114 
115  ObjectMap::const_iterator l = _objects.find(type);
116  if (l == _objects.end())
117  return new SearchType(kEmptyObjectList.begin(), kEmptyObjectList.end());
118 
119  return new SearchType(l->second);
120 }
121 
123  return dynamic_cast<DragonAge2::Object *>(object);
124 }
125 
127  return dynamic_cast<Area *>(object);
128 }
129 
131  return dynamic_cast<Waypoint *>(object);
132 }
133 
135  return dynamic_cast<Placeable *>(object);
136 }
137 
139  return dynamic_cast<Creature *>(object);
140 }
141 
143  return dynamic_cast<Event *>(engineType);
144 }
145 
146 } // End of namespace DragonAge2
147 
148 } // End of namespace Engines
::Aurora::NWScript::Object * getFirstObjectByType(ObjectType type) const
Return the first object of this type.
static Creature * toCreature(Aurora::NWScript::Object *object)
A placeable object in a Dragon Age II area.
SearchType(const iterator &a, const iterator &b)
T ABS(T x)
Definition: util.h:69
A container of Dragon Age II objects.
A creature in a Dragon Age II area.
std::list< DragonAge2::Object * > ::const_iterator iterator
The context holding a Dragon Age II area.
An area in Dragon Age II, holding all objects and rooms within, as well as general area properties li...
Definition: area.h:64
void addObject(DragonAge2::Object &object)
Add an object to this container.
static Waypoint * toWaypoint(Aurora::NWScript::Object *object)
STL namespace.
void removeObject(DragonAge2::Object &object)
Remove an object from this container.
An object in a Dragon Age II area.
float getDistance(DragonAge2::Object &a)
Utility templates and functions.
A waypoint in a Dragon Age II area.
::Aurora::NWScript::ObjectSearch * findObjectsByType(ObjectType type) const
Return a search context to iterate over all objects of this type.
static Event * toEvent(Aurora::NWScript::EngineType *engineType)
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.
bool operator()(DragonAge2::Object *a, DragonAge2::Object *b)
static Area * toArea(Aurora::NWScript::Object *object)
ObjectType
Object type, matches the bitfield in script.ldf.
Definition: types.h:60
static DragonAge2::Object * toObject(::Aurora::NWScript::Object *object)
static Placeable * toPlaceable(Aurora::NWScript::Object *object)
A scripting event.
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:120
ObjectDistanceSort(const DragonAge2::Object &target)
::Aurora::NWScript::Object * getObject(const iterator &t)
void addObject(Object &object)
Add an object to this container.