xoreos  0.0.5
functions_object.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 <boost/make_shared.hpp>
26 
27 #include "src/common/scopedptr.h"
28 #include "src/common/util.h"
29 
31 
38 
40 
41 namespace Engines {
42 
43 namespace DragonAge {
44 
50 
52  ctx.getReturn() = getParamObject(ctx, 0) != 0;
53 }
54 
56  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
57  if (object)
58  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeInt).getInt();
59 }
60 
62  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
63  if (object)
64  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeFloat).getFloat();
65 }
66 
68  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
69  if (object)
70  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeString).getString();
71 }
72 
74  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
75  if (object)
76  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeObject).getObject();
77 }
78 
80  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
81  if (object)
82  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeString).getString();
83 }
84 
86  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
87  if (object)
88  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeEngineType).getEngineType();
89 }
90 
92  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
93  if (object)
94  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeEngineType).getEngineType();
95 }
96 
98  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
99  if (object)
100  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeEngineType).getEngineType();
101 }
102 
104  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
105  if (object)
106  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeEngineType).getEngineType();
107 }
108 
110  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
111  if (object)
112  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeEngineType).getEngineType();
113 }
114 
116  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
117  if (object)
118  ctx.getReturn() = object->getVariable(ctx.getParams()[1].getString(), kTypeEngineType).getEngineType();
119 }
120 
122  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
123  if (object)
124  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getInt());
125 }
126 
128  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
129  if (object)
130  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getFloat());
131 }
132 
134  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
135  if (object)
136  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getString());
137 }
138 
140  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
141  if (object)
142  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getObject());
143 }
144 
146  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
147  if (object)
148  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getString());
149 }
150 
152  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
153  if (object)
154  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getEngineType());
155 }
156 
158  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
159  if (object)
160  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getEngineType());
161 }
162 
164  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
165  if (object)
166  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getEngineType());
167 }
168 
170  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
171  if (object)
172  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getEngineType());
173 }
174 
176  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
177  if (object)
178  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getEngineType());
179 }
180 
182  Aurora::NWScript::Object *object = getParamObject(ctx, 0);
183  if (object)
184  object->setVariable(ctx.getParams()[1].getString(), ctx.getParams()[2].getEngineType());
185 }
186 
189 
191  if (!object || ((uint32)object->getType() >= kObjectTypeMAX))
192  return;
193 
194  ctx.getReturn() = (int32) object->getType();
195 }
196 
198  ctx.getReturn().getString().clear();
199 
200  const Aurora::NWScript::Object *object = getParamObject(ctx, 0);
201  if (object)
202  ctx.getReturn() = object->getTag();
203 }
204 
207  ctx.getReturn().getString() = object ? object->getResRef() : "";
208 }
209 
211  ctx.getReturn().getString() = "";
212 
214  if (!object)
215  return;
216 
217  ctx.getReturn().getString() = object->getNonLocalizedName();
218  if (ctx.getReturn().getString().empty())
219  ctx.getReturn().getString() = object->getName().getString();
220 }
221 
224  if (!object)
225  return;
226 
227  object->setNonLocalizedName(ctx.getParams()[1].getString());
228 }
229 
231  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
232 
234  if (!object)
235  return;
236 
238  if (!campaign)
239  return;
240 
241  ctx.getReturn() = (Aurora::NWScript::Object *) campaign->getCurrentArea();
242 }
243 
245  ctx.getReturn().setVector(0.0f, 0.0f, 0.0f);
246 
248  if (!object)
249  return;
250 
251  float x, y, z;
252  object->getPosition(x, y, z);
253 
254  ctx.getReturn().setVector(x, y, z);
255 }
256 
257 #define SQR(x) ((x) * (x))
259  ctx.getReturn() = -1.0f;
260 
263  if (!object1 || !object2)
264  return;
265 
266  float x1, y1, z1;
267  object1->getPosition(x1, y1, z1);
268 
269  float x2, y2, z2;
270  object2->getPosition(x2, y2, z2);
271 
272  ctx.getReturn() = sqrtf(SQR(x1 - x2) + SQR(y1 - y2) + SQR(z1 - z2));
273 }
274 #undef SQR
275 
277  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
278 
280  if (!campaign)
281  return;
282 
283  const Common::UString &tag = ctx.getParams()[0].getString();
284  if (tag.empty())
285  return;
286 
287  int nth = ctx.getParams()[1].getInt();
288 
290  while (nth-- > 0)
291  search->next();
292 
293  ctx.getReturn() = search->get();
294 }
295 
298  if (!campaign)
299  return;
300 
302  if (!target)
303  return;
304 
305  // Bitfield of type(s) to check for
306  const uint32 type = ctx.getParams()[1].getInt();
307  // We want the nth nearest object
308  size_t count = MAX<int32>(ctx.getParams()[2].getInt(), 0);
309 
310  if (count == 0)
311  return;
312 
314 
315  // TODO: nCheckLiving
316  // TODO: nCheckPerceived
317 
318  const bool includeSelf = ctx.getParams()[5].getInt() != 0;
319  if (includeSelf) {
320  result.push_back(boost::make_shared<Aurora::NWScript::Variable>(target));
321  count--;
322  }
323 
324  if (count == 0)
325  return;
326 
328  Aurora::NWScript::Object *object = 0;
329 
330  std::list<Object *> objects;
331  while ((object = search->next())) {
332  // Needs to be a valid object and not the target
334  if (!daObject || (daObject == target))
335  continue;
336 
337  // Ignore invalid object types
338  const uint32 objectType = (uint32) daObject->getType();
339  if (objectType >= kObjectTypeMAX)
340  continue;
341 
342  if (type & objectType)
343  objects.push_back(daObject);
344  }
345 
346  objects.sort(ObjectDistanceSort(*target));
347 
348  for (std::list<Object *>::iterator it = objects.begin(); it != objects.end() && count > 0; ++it, count--)
349  result.push_back(boost::make_shared<Aurora::NWScript::Variable>(*it));
350 }
351 
354  if (!campaign)
355  return;
356 
358  if (!target)
359  return;
360 
361  const Common::UString &tag = ctx.getParams()[1].getString();
362  if (tag.empty())
363  return;
364 
365  // Bitfield of type(s) to check for
366  const uint32 type = ctx.getParams()[2].getInt();
367  // We want the nth nearest object
368  size_t count = MAX<int32>(ctx.getParams()[3].getInt(), 0);
369 
370  if (count == 0)
371  return;
372 
374 
375  // TODO: nCheckLiving
376  // TODO: nCheckPerceived
377 
378  const bool includeSelf = ctx.getParams()[6].getInt() != 0;
379  if (includeSelf) {
380  result.push_back(boost::make_shared<Aurora::NWScript::Variable>(target));
381  count--;
382  }
383 
384  if (count == 0)
385  return;
386 
388  Aurora::NWScript::Object *object = 0;
389 
390  std::list<Object *> objects;
391  while ((object = search->next())) {
392  // Needs to be a valid object and not the target
394  if (!daObject || (daObject == target))
395  continue;
396 
397  // Ignore invalid object types
398  const uint32 objectType = (uint32) daObject->getType();
399  if (objectType >= kObjectTypeMAX)
400  continue;
401 
402  if (type & objectType)
403  objects.push_back(daObject);
404  }
405 
406  objects.sort(ObjectDistanceSort(*target));
407 
408  for (std::list<Object *>::iterator it = objects.begin(); it != objects.end() && count > 0; ++it, count--)
409  result.push_back(boost::make_shared<Aurora::NWScript::Variable>(*it));
410 }
411 
413  ctx.getReturn() = (Aurora::NWScript::Object *) 0;
414 
416  if (!campaign)
417  return;
418 
420  if (!target)
421  return;
422 
423  const Common::UString &tag = ctx.getParams()[1].getString();
424  if (tag.empty())
425  return;
426 
427  const bool includeSelf = ctx.getParams()[2].getInt() != 0;
428  if (includeSelf && (target->getTag() == tag)) {
429  ctx.getReturn() = (Aurora::NWScript::Object *) target;
430  return;
431  }
432 
434  Aurora::NWScript::Object *object = 0;
435 
436  std::list<Object *> objects;
437  while ((object = search->next())) {
438  // Needs to be a valid object and not the target
440  if (!daObject || (daObject == target))
441  continue;
442 
443  objects.push_back(daObject);
444  }
445 
446  objects.sort(ObjectDistanceSort(*target));
447 
448  if (!objects.empty())
449  ctx.getReturn() = (Aurora::NWScript::Object *) *objects.begin();
450 }
451 
452 } // End of namespace DragonAge
453 
454 } // End of namespace Engines
void isObjectValid(Aurora::NWScript::FunctionContext &ctx)
void getLocalFloat(Aurora::NWScript::FunctionContext &ctx)
std::vector< boost::shared_ptr< Variable > > Array
Definition: variable.h:58
void getObjectByTag(Aurora::NWScript::FunctionContext &ctx)
void setName(Aurora::NWScript::FunctionContext &ctx)
A class able to sort objects by distance to a target object.
A class holding an UTF-8 string.
Definition: ustring.h:48
Area * getCurrentArea() const
Return the area the PC is currently in.
Definition: campaign.cpp:291
The context holding a Dragon Age: Origins campaign.
void UT_getNearestObjectByTag(Aurora::NWScript::FunctionContext &ctx)
void getLocalResource(Aurora::NWScript::FunctionContext &ctx)
Context of an NWScript function.
void setLocalFloat(Aurora::NWScript::FunctionContext &ctx)
Campaigns & getCampaigns()
Return the campaigns context.
Definition: game.cpp:57
A container of Dragon Age: Origins objects.
void setLocalItemProperty(Aurora::NWScript::FunctionContext &ctx)
static Aurora::NWScript::Object * getParamObject(const Aurora::NWScript::FunctionContext &ctx, size_t n)
Definition: functions.cpp:101
void setLocalLocation(Aurora::NWScript::FunctionContext &ctx)
void setLocalResource(Aurora::NWScript::FunctionContext &ctx)
A simple scoped smart pointer template.
void setLocalEffect(Aurora::NWScript::FunctionContext &ctx)
const Common::UString & getTag() const
Definition: object.h:49
void getLocalEffect(Aurora::NWScript::FunctionContext &ctx)
void getLocalInt(Aurora::NWScript::FunctionContext &ctx)
ObjectType getType() const
Return the exact type of the object.
Definition: object.cpp:70
void getDistanceBetween(Aurora::NWScript::FunctionContext &ctx)
void getLocalItemProperty(Aurora::NWScript::FunctionContext &ctx)
The context handling the gameplay in Dragon Age: Origins.
void getObjectType(Aurora::NWScript::FunctionContext &ctx)
Utility templates and functions.
void getLocalString(Aurora::NWScript::FunctionContext &ctx)
void setLocalCommand(Aurora::NWScript::FunctionContext &ctx)
void getPosition(Aurora::NWScript::FunctionContext &ctx)
void setVector(float x, float y, float z)
Definition: variable.cpp:335
void setLocalString(Aurora::NWScript::FunctionContext &ctx)
ObjectSearch * findObjectsByTag(const Common::UString &tag) const
Return a search context to iterate over all objects with this tag.
ObjectSearch * findObjects() const
Return a search context to iterate over all objects.
static DragonAge::Object * toObject(::Aurora::NWScript::Object *object)
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
void getLocalObject(Aurora::NWScript::FunctionContext &ctx)
#define SQR(x)
void setLocalObject(Aurora::NWScript::FunctionContext &ctx)
Campaign * getCurrentCampaign() const
Return the currently running campaign.
Definition: campaigns.cpp:311
void getTag(Aurora::NWScript::FunctionContext &ctx)
void getLocalCommand(Aurora::NWScript::FunctionContext &ctx)
An object in a Dragon Age: Origins area.
"effect", "event", "location", "talent"...
Definition: types.h:43
void getLocalPlayer(Aurora::NWScript::FunctionContext &ctx)
void setLocalPlayer(Aurora::NWScript::FunctionContext &ctx)
uint32_t uint32
Definition: types.h:204
const Array & getArray() const
Definition: variable.cpp:353
Common::UString & getString()
Definition: variable.cpp:314
void getName(Aurora::NWScript::FunctionContext &ctx)
Basic Dragon Age: Origins type definitions.
Dragon Age: Origins engine functions.
void getNearestObject(Aurora::NWScript::FunctionContext &ctx)
void getArea(Aurora::NWScript::FunctionContext &ctx)
void getLocalLocation(Aurora::NWScript::FunctionContext &ctx)
The context managing and running the Dragon Age: Origins campaigns.
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:120
void getNearestObjectByTag(Aurora::NWScript::FunctionContext &ctx)
void clear()
Clear the string&#39;s contents.
Definition: ustring.cpp:236
void getLocalEvent(Aurora::NWScript::FunctionContext &ctx)
void setLocalInt(Aurora::NWScript::FunctionContext &ctx)
void getResRef(Aurora::NWScript::FunctionContext &ctx)
void setLocalEvent(Aurora::NWScript::FunctionContext &ctx)
int32_t int32
Definition: types.h:203