xoreos  0.0.5
placeable.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/maths.h"
27 
28 #include "src/aurora/gff3file.h"
29 #include "src/aurora/gdafile.h"
30 
32 
35 
38 
39 namespace Engines {
40 
41 namespace DragonAge {
42 
44  _appearanceID(0xFFFFFFFF) {
45 
46  load(placeable);
47 }
48 
50  hide();
51 }
52 
53 void Placeable::setPosition(float x, float y, float z) {
54  Object::setPosition(x, y, z);
55  Object::getPosition(x, y, z);
56 
57  if (_model)
58  _model->setPosition(x, y, z);
59 }
60 
61 void Placeable::setOrientation(float x, float y, float z, float angle) {
62  Object::setOrientation(x, y, z, angle);
63  Object::getOrientation(x, y, z, angle);
64 
65  if (_model)
66  _model->setOrientation(x, y, z, angle);
67 }
68 
70  if (_model)
71  _model->show();
72 }
73 
75  if (_model)
76  _model->hide();
77 }
78 
80  status("Placeable \"%s\" (\"%s\"): \"%s\"",
82 
83  highlight(true);
84 }
85 
87  highlight(false);
88 }
89 
90 void Placeable::highlight(bool enabled) {
91  if (_model)
92  _model->drawBound(enabled);
93 }
94 
95 bool Placeable::click(Object *triggerer) {
96  runScript(kEventTypeClick, this, triggerer);
97  runScript(kEventTypeUse , this, triggerer);
98 
99  return true;
100 }
101 
102 void Placeable::load(const Aurora::GFF3Struct &placeable) {
103  _resRef = placeable.getString("TemplateResRef");
104 
106  if (!_resRef.empty())
107  utp.reset(loadOptionalGFF3(_resRef, Aurora::kFileTypeUTP, MKTAG('U', 'T', 'P', ' ')));
108 
109  load(placeable, utp ? &utp->getTopLevel() : 0);
110 }
111 
112 void Placeable::load(const Aurora::GFF3Struct &instance, const Aurora::GFF3Struct *blueprint = 0) {
113  if (blueprint)
114  loadProperties(*blueprint);
115  loadProperties(instance);
116 
118 
119  _model.reset(loadModelObject(gda.getString(gda.findRow(_appearanceID), "ModelName")));
120 
121  if (_model) {
122  _model->setTag(_tag);
123  _model->setClickable(isClickable());
124 
125  _ids.push_back(_model->getID());
126  }
127 
128  syncPosition();
129  syncOrientation();
130 }
131 
133  // Tag
134  _tag = gff.getString("Tag", _tag);
135 
136  // Name and description
137  gff.getLocString("LocName" , _name);
138  gff.getLocString("LocPopupText", _description);
139 
140  // Conversation
141  _conversation = gff.getString("Conversation", _conversation);
142 
143  // Static and usable
144  _static = !gff.getBool("Active" , !_static);
145  _usable = gff.getBool("Useable", _usable);
146 
147  // Appearance
148  _appearanceID = gff.getUint("Appearance", _appearanceID);
149 
150  // Position
151  if (gff.hasField("XPosition")) {
152  const float position[3] = {
153  (float) gff.getDouble("XPosition"),
154  (float) gff.getDouble("YPosition"),
155  (float) gff.getDouble("ZPosition")
156  };
157 
158  setPosition(position[0], position[1], position[2]);
159  }
160 
161  // Orientation
162  if (gff.hasField("XOrientation")) {
163  const float orientation[4] = {
164  (float) gff.getDouble("XOrientation"),
165  (float) gff.getDouble("YOrientation"),
166  (float) gff.getDouble("ZOrientation"),
167  (float) Common::rad2deg(acos(gff.getDouble("WOrientation")) * 2.0)
168  };
169 
170  setOrientation(orientation[0], orientation[1], orientation[2], orientation[3]);
171  }
172 
173  // Variables and script
174  readVarTable(gff);
175  readScript(gff);
176  enableEvents(true);
177 }
178 
179 } // End of namespace Dragon Age
180 
181 } // End of namespace Engines
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
A placeable object in a Dragon Age: Origins area.
#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
Handling BioWare&#39;s GDAs (2DAs, two-dimensional array, within V4.0 GFFs).
void load(const Aurora::GFF3Struct &placeable)
Definition: placeable.cpp:102
bool getBool(const Common::UString &field, bool def=false) const
Definition: gff3file.cpp:510
bool getLocString(const Common::UString &field, LocString &str) const
Definition: gff3file.cpp:614
bool _static
Is the object static?
Definition: object.h:128
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
Common::ScopedPtr< Graphics::Aurora::Model > _model
The placeable&#39;s model.
Definition: placeable.h:75
bool hasField(const Common::UString &field) const
Does this specific field exist?
Definition: gff3file.cpp:400
Mathematical helpers.
uint64 getUint(const Common::UString &field, uint64 def=0) const
Definition: gff3file.cpp:436
size_t findRow(uint32 id) const
Find a row by its ID value.
Definition: gdafile.cpp:95
Aurora::GFF3File * loadOptionalGFF3(const Common::UString &gff3, Aurora::FileType type, uint32 id, bool repairNWNPremium)
Load a GFF3, but return 0 instead of throwing on error.
Definition: util.cpp:150
Aurora::LocString _description
The object&#39;s description.
Definition: object.h:120
uint32 _appearanceID
The placeable&#39;s appearance; index into the Placeables MGDA.
Definition: placeable.h:73
void highlight(bool enabled)
(Un)Highlight the placeable.
Definition: placeable.cpp:90
void setPosition(float x, float y, float z)
Set the placeable&#39;s position.
Definition: placeable.cpp:53
const Aurora::GDAFile & getMGDA(uint32 id)
Definition: util.cpp:36
const Common::UString & getString(Language language, LanguageGender gender=kLanguageGenderCurrent) const
Get the string of that language.
Definition: locstring.cpp:82
bool click(Object *triggerer=0)
The placeable was clicked.
Definition: placeable.cpp:95
bool _usable
Is the object usable?
Definition: object.h:129
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Utility templates and functions.
double getDouble(const Common::UString &field, double def=0.0) const
Definition: gff3file.cpp:514
Placeable template (user), GFF.
Definition: types.h:109
Dragon Age: Origins utility functions.
A 3D model of an object.
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
Common::UString _resRef
The object&#39;s resource reference.
Definition: object.h:117
void hide()
Hide the placeable&#39;s model.
Definition: placeable.cpp:74
Aurora::LocString _name
The object&#39;s display name.
Definition: object.h:119
void show()
Show the placeable&#39;s model.
Definition: placeable.cpp:69
void readVarTable(const Aurora::GFF3List &varTable)
void leave()
The cursor left the placeable.
Definition: placeable.cpp:86
Common::UString getString(size_t row, uint32 columnHash, const Common::UString &def="") const
Definition: gdafile.cpp:165
std::list< uint32 > _ids
The object&#39;s model IDs.
Definition: object.h:131
Placeable(const Aurora::GFF3Struct &placeable)
Load from a placeable instance.
Definition: placeable.cpp:43
A struct within a GFF3.
Definition: gff3file.h:164
void loadProperties(const Aurora::GFF3Struct &gff)
Definition: placeable.cpp:132
virtual void setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:134
Common::UString _tag
Definition: object.h:56
void status(const char *s,...)
Definition: util.cpp:52
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Definition: gff3file.cpp:527
void readScript(const Aurora::GFF3Struct &gff)
Definition: container.cpp:90
void setOrientation(float x, float y, float z, float angle)
Set the placeable&#39;s orientation.
Definition: placeable.cpp:61
static float rad2deg(float rad)
Definition: maths.h:93
Generic Aurora engines utility functions.
bool isClickable() const
Can the player click the object?
Definition: object.cpp:116
Graphics::Aurora::Model * loadModelObject(const Common::UString &resref, const Common::UString &texture)
Definition: model.cpp:47
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
bool runScript(EventType event, const Aurora::NWScript::ObjectReference owner=Aurora::NWScript::ObjectReference(), const Aurora::NWScript::ObjectReference triggerer=Aurora::NWScript::ObjectReference())
Definition: container.cpp:104
virtual void setOrientation(float x, float y, float z, float angle)
Set the object&#39;s orientation.
Definition: object.cpp:140
void enableEvents(bool enabled)
Enable/Disable the handling of all events.
Definition: container.cpp:76
void enter()
The cursor entered the placeable.
Definition: placeable.cpp:79
Class to hold the GFF&#39;d two-dimensional array of a GDA file.
Definition: gdafile.h:62
Generic Aurora engines model functions.