xoreos  0.0.5
trigger.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 
26 #include "src/aurora/resman.h"
27 #include "src/aurora/gff3file.h"
28 
30 
32 
33 namespace Engines {
34 
35 namespace KotOR2 {
36 
38  : ::Engines::Trigger(),
40  load(gff);
41  prepare();
42 }
43 
44 void Trigger::show() {
45  Renderable::show();
46 }
47 
48 void Trigger::hide() {
49  Renderable::hide();
50 }
51 
53 }
54 
55 bool Trigger::isVisible() const {
56  return Renderable::isVisible();
57 }
58 
60  Common::UString temp = gff.getString("TemplateResRef");
61 
63  if (!temp.empty())
64  utt.reset(loadOptionalGFF3(temp, Aurora::kFileTypeUTT, MKTAG('U', 'T', 'T', ' ')));
65 
66  loadBlueprint(utt->getTopLevel());
67 
68  if (!utt)
69  warning("Trigger \"%s\" has no blueprint", temp.c_str());
70 
71  float x, y, z;
72  x = (float)gff.getDouble("XPosition");
73  y = (float)gff.getDouble("YPosition");
74  z = (float)gff.getDouble("ZPosition");
75  glm::vec3 position(x, y, z);
76  setPosition(x, y, z);
77 
78  x = (float)gff.getDouble("XOrientation");
79  y = (float)gff.getDouble("YOrientation");
80  z = (float)gff.getDouble("ZOrientation");
81  glm::vec3 orientation(x, y, z);
82 
83  const Aurora::GFF3List &geometry = gff.getList("Geometry");
84  for (Aurora::GFF3List::const_iterator p = geometry.begin();
85  p != geometry.end();
86  ++p) {
87  x = (float)(*p)->getDouble("PointX");
88  y = (float)(*p)->getDouble("PointY");
89  z = (float)(*p)->getDouble("PointZ");
90  _geometry.push_back(position + glm::vec3(x, y, z));
91  }
92 }
93 
95  Object::_tag = gff.getString("Tag");
96 
97  _name = gff.getString("LocalizedName");
98 
99  readScripts(gff);
100 }
101 
102 } // End of namespace KotOR2
103 
104 } // 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
A class holding an UTF-8 string.
Definition: ustring.h:48
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
void load(const Aurora::GFF3Struct &gff)
Definition: trigger.cpp:59
Trigger in a Star Wars: Knights of the Old Republic II: The Sith Lords area.
Trigger template (user), GFF.
Definition: types.h:97
bool isVisible() const
Is the object&#39;s model(s) visible?
Definition: trigger.cpp:55
virtual void setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:121
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
void loadBlueprint(const Aurora::GFF3Struct &gff)
Definition: trigger.cpp:94
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Common::UString _name
The object&#39;s display name.
Definition: object.h:129
double getDouble(const Common::UString &field, double def=0.0) const
Definition: gff3file.cpp:514
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void hideSoft()
Hide the object&#39;s model(s) if applicable.
Definition: trigger.cpp:52
void warning(const char *s,...)
Definition: util.cpp:33
std::vector< const GFF3Struct * > GFF3List
Definition: types.h:449
const GFF3List & getList(const Common::UString &field) const
Definition: gff3file.cpp:741
A struct within a GFF3.
Definition: gff3file.h:164
Common::UString _tag
Definition: object.h:56
std::vector< glm::vec3 > _geometry
Definition: trigger.h:50
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Definition: gff3file.cpp:527
Generic Aurora engines utility functions.
void readScripts(const Aurora::GFF3Struct &gff)
Definition: container.cpp:134
void show()
Show the object&#39;s model(s).
Definition: trigger.cpp:44
void hide()
Hide the object&#39;s model(s).
Definition: trigger.cpp:48
The global resource manager for Aurora resources.