xoreos  0.0.5
waypoint.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/locstring.h"
29 #include "src/aurora/gff3file.h"
30 
32 
34 
35 namespace Engines {
36 
37 namespace Witcher {
38 
40  _hasMapNote(false), _enabledMapNote(false) {
41 
42  load(waypoint);
43 }
44 
46  hide();
47 }
48 
49 void Waypoint::load(const Aurora::GFF3Struct &waypoint) {
50  Common::UString temp = waypoint.getString("TemplateResRef");
51 
53  if (!temp.empty())
54  utw.reset(loadOptionalGFF3(temp, Aurora::kFileTypeUTW, MKTAG('U', 'T', 'W', ' ')));
55 
56  load(waypoint, utw ? &utw->getTopLevel() : 0);
57 }
58 
59 bool Waypoint::hasMapNote() const {
60  return _hasMapNote;
61 }
62 
64  return _hasMapNote && _enabledMapNote;
65 }
66 
67 void Waypoint::enableMapNote(bool enabled) {
68  _enabledMapNote = enabled;
69 }
70 
72  return _mapNote;
73 }
74 
77 }
78 
79 void Waypoint::load(const Aurora::GFF3Struct &instance, const Aurora::GFF3Struct *blueprint) {
80  // General properties
81 
82  if (blueprint)
83  loadProperties(*blueprint); // Blueprint
84  loadProperties(instance); // Instance
85 
86  // Position
87 
88  setPosition(instance.getDouble("XPosition"),
89  instance.getDouble("YPosition"),
90  instance.getDouble("ZPosition"));
91 
92  // Orientation
93 
94  float bearingX = instance.getDouble("XOrientation");
95  float bearingY = instance.getDouble("YOrientation");
96 
97  setOrientation(0.0f, 0.0f, 1.0f, -Common::rad2deg(atan2(bearingX, bearingY)));
98 }
99 
101  // Unique ID and tag
102 
103  _uniqueID = gff.getString("UniqueID", _uniqueID);
104  _tag = gff.getString("Tag", _tag);
105 
106  // Map note
107 
108  _hasMapNote = gff.getBool("HasMapNote" , _hasMapNote);
109  _enabledMapNote = gff.getBool("MapNoteEnabled", _enabledMapNote);
110 
111  gff.getLocString("MapNote", _mapNote);
112 
114 
115  // Scripts
116  readScripts(gff);
117 }
118 
119 } // End of namespace Witcher
120 
121 } // End of namespace Engines
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
bool enabledMapNote() const
Is this waypoint&#39;s map note currently enabled?
Definition: waypoint.cpp:63
#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 setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:146
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
A class holding an UTF-8 string.
Definition: ustring.h:48
An object within a Witcher area.
Definition: object.h:51
A localized string.
Definition: locstring.h:43
Waypoint template, GFF.
Definition: types.h:124
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
Mathematical helpers.
virtual void hide()
Hide the object&#39;s model(s).
Definition: object.cpp:74
void readScripts(const Aurora::GFF3Struct &gff)
Definition: container.cpp:129
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 _mapNote
The waypoint&#39;s map note text.
Definition: waypoint.h:67
const Aurora::LocString & getMapNote() const
Return the waypoint&#39;s map note text.
Definition: waypoint.cpp:71
bool _enabledMapNote
Is this waypoint&#39;s map note enabled?
Definition: waypoint.h:64
Utility templates and functions.
bool _hasMapNote
Does this waypoint have a map note?
Definition: waypoint.h:63
double getDouble(const Common::UString &field, double def=0.0) const
Definition: gff3file.cpp:514
void refreshLocalized()
Refresh all localized strings.
Definition: waypoint.cpp:75
Common::UString _uniqueID
A globally unique ID.
Definition: object.h:144
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
A waypoint in a The Witcher area.
Handling BioWare&#39;s localized strings.
virtual void refreshLocalized()
Refresh all localized strings.
Definition: object.cpp:93
void load(const Aurora::GFF3Struct &waypoint)
Load from a waypoint instance.
Definition: waypoint.cpp:49
virtual void setOrientation(float x, float y, float z, float angle)
Set the object&#39;s orientation.
Definition: object.cpp:152
A struct within a GFF3.
Definition: gff3file.h:164
void loadProperties(const Aurora::GFF3Struct &gff)
Load general waypoint properties.
Definition: waypoint.cpp:100
Common::UString _tag
Definition: object.h:56
Waypoint(const Aurora::GFF3Struct &waypoint)
Load from a waypoint instance.
Definition: waypoint.cpp:39
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Definition: gff3file.cpp:527
void enableMapNote(bool enabled)
Enable/Disable the waypoint&#39;s map note.
Definition: waypoint.cpp:67
static float rad2deg(float rad)
Definition: maths.h:93
Generic Aurora engines utility functions.
bool hasMapNote() const
Does this waypoint have a map note?
Definition: waypoint.cpp:59