xoreos  0.0.5
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 "src/common/util.h"
26 #include "src/common/error.h"
27 #include "src/common/uuid.h"
28 
29 #include "src/aurora/gff3file.h"
30 #include "src/aurora/gff4file.h"
31 
33 
35 
36 namespace Engines {
37 
38 namespace DragonAge {
39 
40 static const uint32 kVARSID = MKTAG('V', 'A', 'R', 'S');
41 
42 using ::Aurora::GFF3File;
43 using ::Aurora::GFF3Struct;
45 
46 using ::Aurora::GFF4File;
47 using ::Aurora::GFF4Struct;
49 
50 using namespace ::Aurora::GFF4FieldNamesEnum;
51 
52 Object::Object(ObjectType type) : _type(type), _static(true), _usable(false) {
54  ObjectMan.registerObject(this);
55 
56  _position[0] = 0.0f;
57  _position[1] = 0.0f;
58  _position[2] = 0.0f;
59 
60  _orientation[0] = 0.0f;
61  _orientation[1] = 0.0f;
62  _orientation[2] = 0.0f;
63  _orientation[3] = 0.0f;
64 }
65 
67  ObjectMan.unregisterObject(this);
68 }
69 
71  return _type;
72 }
73 
74 void Object::show() {
75 }
76 
77 void Object::hide() {
78 }
79 
80 const std::list<uint32> &Object::getIDs() const {
81  return _ids;
82 }
83 
85  return _resRef;
86 }
87 
89  return _name;
90 }
91 
93  return _description;
94 }
95 
97  return _nonLocalizedName;
98 }
99 
101  _nonLocalizedName = name;
102 }
103 
105  return _conversation;
106 }
107 
108 bool Object::isStatic() const {
109  return _static;
110 }
111 
112 bool Object::isUsable() const {
113  return _usable;
114 }
115 
116 bool Object::isClickable() const {
117  return !_static && _usable;
118 }
119 
120 void Object::getPosition(float &x, float &y, float &z) const {
121  x = _position[0];
122  y = _position[1];
123  z = _position[2];
124 }
125 
126 void Object::getOrientation(float &x, float &y, float &z, float &angle) const {
127  x = _orientation[0];
128  y = _orientation[1];
129  z = _orientation[2];
130 
131  angle = _orientation[3];
132 }
133 
134 void Object::setPosition(float x, float y, float z) {
135  _position[0] = x;
136  _position[1] = y;
137  _position[2] = z;
138 }
139 
140 void Object::setOrientation(float x, float y, float z, float angle) {
141  _orientation[0] = x;
142  _orientation[1] = y;
143  _orientation[2] = z;
144  _orientation[3] = angle;
145 }
146 
148  float x, y, z;
149 
150  getPosition(x, y, z);
151  setPosition(x, y, z);
152 }
153 
155  float x, y, z, angle;
156 
157  getOrientation(x, y, z, angle);
158  setOrientation(x, y, z, angle);
159 }
160 
162 }
163 
165 }
166 
167 void Object::highlight(bool UNUSED(enabled)) {
168 }
169 
170 bool Object::click(Object *UNUSED(triggerer)) {
171  return true;
172 }
173 
174 void Object::readVarTable(const GFF3List &varTable) {
175  for (GFF3List::const_iterator v = varTable.begin(); v != varTable.end(); ++v) {
176  const Common::UString name = (*v)->getString ("Name");
177  const uint8 type = (*v)->getUint ("Type");
178 
179  if (name.empty())
180  continue;
181 
182  switch (type) {
183  case 0:
184  case 4:
186  break;
187 
188  case 1:
189  setVariable(name, (int32) (*v)->getSint("Value"));
190  break;
191 
192  case 2:
193  setVariable(name, (float) (*v)->getDouble("Value"));
194  break;
195 
196  case 3:
197  case 12:
198  setVariable(name, (*v)->getString("Value"));
199  break;
200 
201  default:
202  throw Common::Exception("Unknown variable type %u (\"%s\")", type, name.c_str());
203  }
204  }
205 }
206 
208  if (gff.hasField("VarTable"))
209  readVarTable(gff.getList("VarTable"));
210 }
211 
212 void Object::readVarTable(const GFF4List &varTable) {
213  for (GFF4List::const_iterator v = varTable.begin(); v != varTable.end(); ++v) {
214  if (!*v || ((*v)->getLabel() != kVARSID))
215  continue;
216 
217  const Common::UString name = (*v)->getString (kGFF4ScriptVarTableName);
218  const uint8 type = (*v)->getUint (kGFF4ScriptVarTableType);
219  const GFF4Struct *value = (*v)->getGeneric(kGFF4ScriptVarTableValue);
220 
221  if (name.empty() || (type == 0) || !value || !value->hasField(0))
222  continue;
223 
224  switch (type) {
225  case 4:
227  break;
228 
229  case 1:
230  setVariable(name, (int32) value->getSint(0));
231  break;
232 
233  case 2:
234  setVariable(name, (float) value->getDouble(0));
235  break;
236 
237  case 3:
238  case 12:
239  setVariable(name, value->getString(0));
240  break;
241 
242  default:
243  throw Common::Exception("Unknown variable type %u (\"%s\")", type, name.c_str());
244  }
245  }
246 }
247 
249  if (gff.hasField(kGFF4ScriptVarTable))
251 }
252 
253 } // End of namespace DragonAge
254 
255 } // End of namespace Engines
#define ObjectMan
Definition: objectman.h:56
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like &#39;DATA&#39;, to ensure portability.
Definition: endianness.h:140
virtual void leave()
The cursor left the object.
Definition: object.cpp:164
const std::list< uint32 > & getIDs() const
Return the object&#39;s model IDs.
Definition: object.cpp:80
bool _static
Is the object static?
Definition: object.h:128
A class holding an UTF-8 string.
Definition: ustring.h:48
A localized string.
Definition: locstring.h:43
uint8_t uint8
Definition: types.h:200
virtual void enter()
The cursor entered the object.
Definition: object.cpp:161
bool hasField(const Common::UString &field) const
Does this specific field exist?
Definition: gff3file.cpp:400
const Aurora::LocString & getDescription() const
Return the object&#39;s description.
Definition: object.cpp:92
Utility functions for generating unique IDs.
Aurora::LocString _description
The object&#39;s description.
Definition: object.h:120
const Common::UString & getResRef() const
Return the object&#39;s resource reference.
Definition: object.cpp:84
bool _usable
Is the object usable?
Definition: object.h:129
std::vector< const GFF4Struct * > GFF4List
Definition: types.h:453
float _orientation[4]
The object&#39;s orientation.
Definition: object.h:134
Handling version V4.0/V4.1 of BioWare&#39;s GFFs (generic file format).
ObjectType getType() const
Return the exact type of the object.
Definition: object.cpp:70
NWScript object manager.
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
const Aurora::LocString & getName() const
Return the object&#39;s name.
Definition: object.cpp:88
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
float _position[3]
The object&#39;s position.
Definition: object.h:133
bool hasField(uint32 field) const
Does this specific field exist?
Definition: gff4file.cpp:573
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
virtual void getOrientation(float &x, float &y, float &z, float &angle) const
Return the object&#39;s orientation.
Definition: object.cpp:126
StackException Exception
Definition: error.h:59
Common::UString _nonLocalizedName
The object&#39;s non-localized name.
Definition: object.h:122
Common::UString _resRef
The object&#39;s resource reference.
Definition: object.h:117
virtual bool click(Object *triggerer=0)
The object was clicked.
Definition: object.cpp:170
virtual void highlight(bool enabled)
(Un)Highlight the object.
Definition: object.cpp:167
std::vector< const GFF3Struct * > GFF3List
Definition: types.h:449
Aurora::LocString _name
The object&#39;s display name.
Definition: object.h:119
void readVarTable(const Aurora::GFF3List &varTable)
static const uint32 kVARSID
Definition: object.cpp:40
ObjectType _type
The object&#39;s type.
Definition: object.h:115
virtual void hide()
Hide the object&#39;s model(s).
Definition: object.cpp:77
const GFF3List & getList(const Common::UString &field) const
Definition: gff3file.cpp:741
An object in a Dragon Age: Origins area.
std::list< uint32 > _ids
The object&#39;s model IDs.
Definition: object.h:131
A struct within a GFF3.
Definition: gff3file.h:164
virtual void setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:134
uint32_t uint32
Definition: types.h:204
void setNonLocalizedName(const Common::UString &name)
Set the object&#39;s non-localized name.
Definition: object.cpp:100
const Common::UString & getConversation() const
Return the object&#39;s default conversation (DLG).
Definition: object.cpp:104
bool isStatic() const
Is the object static (not manipulable at all)?
Definition: object.cpp:108
void setVariable(const Common::UString &var, const Variable &value)
bool isClickable() const
Can the player click the object?
Definition: object.cpp:116
const GFF4List & getList(uint32 field) const
Definition: gff4file.cpp:1394
bool isUsable() const
Can the object be used by the PC?
Definition: object.cpp:112
virtual void show()
Show the object&#39;s model(s).
Definition: object.cpp:74
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:120
Common::UString _conversation
The object&#39;s default conversation.
Definition: object.h:124
const Common::UString & getNonLocalizedName() const
Return the object&#39;s non-localized name.
Definition: object.cpp:96
virtual void setOrientation(float x, float y, float z, float angle)
Set the object&#39;s orientation.
Definition: object.cpp:140
uint32 generateIDNumber()
Definition: uuid.cpp:46
int32_t int32
Definition: types.h:203
ObjectType
Object type, matches the bitfield in script.ldf.
Definition: types.h:57