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/scopedptr.h"
26 #include "src/common/util.h"
27 #include "src/common/maths.h"
28 
29 #include "src/aurora/gff3file.h"
30 
32 
34 
35 namespace Engines {
36 
37 namespace KotOR {
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 
75 void Waypoint::load(const Aurora::GFF3Struct &instance, const Aurora::GFF3Struct *blueprint) {
76  // General properties
77 
78  if (blueprint)
79  loadProperties(*blueprint); // Blueprint
80  loadProperties(instance); // Instance
81 
82  // Position
83 
84  setPosition(instance.getDouble("XPosition"),
85  instance.getDouble("YPosition"),
86  instance.getDouble("ZPosition"));
87 
88  // Orientation
89 
90  float bearingX = instance.getDouble("XOrientation");
91  float bearingY = instance.getDouble("YOrientation");
92 
93  setOrientation(0.0f, 0.0f, 1.0f, -Common::rad2deg(atan2(bearingX, bearingY)));
94 }
95 
97  // Tag
98  _tag = gff.getString("Tag", _tag);
99 
100  // Map note
101 
102  _hasMapNote = gff.getBool("HasMapNote" , _hasMapNote);
103  _enabledMapNote = gff.getBool("MapNoteEnabled", _enabledMapNote);
104 
105  _mapNote = gff.getString("MapNote", _mapNote);
106 
107  // Scripts
108  readScripts(gff);
109 }
110 
111 } // End of namespace KotOR
112 
113 } // End of namespace Engines
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 hide()
Hide the object&#39;s model(s).
Definition: object.cpp:72
A waypoint in a Star Wars: Knights of the Old Republic area.
bool getBool(const Common::UString &field, bool def=false) const
Definition: gff3file.cpp:510
bool hasMapNote() const
Does this waypoint have a map note?
Definition: waypoint.cpp:59
A class holding an UTF-8 string.
Definition: ustring.h:48
Common::UString _mapNote
The waypoint&#39;s map note text.
Definition: waypoint.h:64
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.
void load(const Aurora::GFF3Struct &waypoint)
Load from a waypoint instance.
Definition: waypoint.cpp:49
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
bool enabledMapNote() const
Is this waypoint&#39;s map note currently enabled?
Definition: waypoint.cpp:63
A simple scoped smart pointer template.
void loadProperties(const Aurora::GFF3Struct &gff)
Load general waypoint properties.
Definition: waypoint.cpp:96
Common::UString getMapNote() const
Return the waypoint&#39;s map note text.
Definition: waypoint.cpp:71
bool _hasMapNote
Does this waypoint have a map note?
Definition: waypoint.h:60
Utility templates and functions.
bool _enabledMapNote
Is this waypoint&#39;s map note enabled?
Definition: waypoint.h:61
double getDouble(const Common::UString &field, double def=0.0) const
Definition: gff3file.cpp:514
virtual void setOrientation(float x, float y, float z, float angle)
Set the object&#39;s orientation.
Definition: object.cpp:158
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void enableMapNote(bool enabled)
Enable/Disable the waypoint&#39;s map note.
Definition: waypoint.cpp:67
Waypoint(const Aurora::GFF3Struct &waypoint)
Load from a waypoint instance.
Definition: waypoint.cpp:39
virtual void setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:152
A struct within a GFF3.
Definition: gff3file.h:164
Common::UString _tag
Definition: object.h:56
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Definition: gff3file.cpp:527
static float rad2deg(float rad)
Definition: maths.h:93
Generic Aurora engines utility functions.
void readScripts(const Aurora::GFF3Struct &gff, bool clear=true)
Definition: container.cpp:134