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 
25 #include "src/common/scopedptr.h"
26 #include "src/common/util.h"
27 #include "src/common/error.h"
28 #include "src/common/maths.h"
29 
30 #include "src/aurora/locstring.h"
31 #include "src/aurora/gff3file.h"
32 
34 
36 
37 namespace Engines {
38 
39 namespace Jade {
40 
42 
43  load(trigger);
44 }
45 
47 }
48 
49 bool Trigger::isOneShot() const {
50  return _isOneShot;
51 }
52 
53 bool Trigger::isTrap() const {
54  return _isTrap;
55 }
56 
57 bool Trigger::isDetectable() const {
58  return _isDetectable;
59 }
60 
61 bool Trigger::isDisarmable() const {
62  return _isDisarmable;
63 }
64 
65 bool Trigger::isFlagged() const {
66  return _isFlagged;
67 }
68 
69 bool Trigger::isAreaTrans() const {
70  return _isAreaTrans;
71 }
72 
74  return _isHenchmenData;
75 }
76 
78  return _transitionText;
79 }
80 
81 void Trigger::load(const Aurora::GFF3Struct &trigger) {
82  Common::UString temp = trigger.getString("ResRef");
83 
84  if (!temp.empty()) {
85  try {
87  trg(new Aurora::GFF3File(temp, Aurora::kFileTypeTRG, MKTAG('T', 'R', 'G', ' ')));
88 
89  loadBlueprint(trg->getTopLevel());
90 
91  } catch (Common::Exception &e) {
92  e.add("Trigger \"%s\" has no blueprint", temp.c_str());
93  throw;
94  }
95  }
96 
97  loadInstance(trigger);
98 }
99 
101  _isOneShot = gff.getBool("IsOneShot");
102  _isTrap = gff.getBool("IsTrap");
103  _isDetectable = gff.getBool("IsDetectable");
104  _isDisarmable = gff.getBool("IsDisarmable");
105  _isFlagged = gff.getBool("IsFlagged");
106  _isAreaTrans = gff.getBool("IsAreaTrans");
107  _isHenchmenData = gff.getBool("IsHenchmenData");
108 
109  _loadScreen = gff.getUint("LoadScreen");
110 
111  _transitionText = gff.getString("TransitionText");
112 
113  // Scripts
114  readScripts(gff);
115 }
116 
118  // Tag
119 
120  _tag = gff.getString("Tag", _tag);
121 
122  loadPositional(gff);
123 
124  const Aurora::GFF3List &geometry = gff.getList("Geometry");
125  float x, y, z;
126 
127  Graphics::VertexDecl vertexDecl;
128 
129  vertexDecl.push_back(Graphics::VertexAttrib(Graphics::VPOSITION, 3, GL_FLOAT));
130 
131  _vertexBuffer.setVertexDeclLinear(geometry.size(), vertexDecl);
132 
133  float *v = reinterpret_cast<float *>(_vertexBuffer.getData());
134  for (uint32 i = 0; i < geometry.size(); i++) {
135  geometry[i]->getVector("Vertex", x, y, z);
136 
137  // Position
138  *v++ = x;
139  *v++ = y;
140  *v++ = z;
141  }
142 }
143 
144 } // End of namespace Jade
145 
146 } // End of namespace Engines
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
bool isAreaTrans() const
Does this trigger represent an area transition?
Definition: trigger.cpp:69
#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
void add(const char *s,...) GCC_PRINTF(2
Definition: error.cpp:58
bool getBool(const Common::UString &field, bool def=false) const
Definition: gff3file.cpp:510
Graphics::VertexBuffer _vertexBuffer
Geometry outline vertex buffer.
Definition: trigger.h:82
A class holding an UTF-8 string.
Definition: ustring.h:48
Vertex position.
Definition: vertexbuffer.h:36
void loadPositional(const Aurora::GFF3Struct &gff)
Load the object&#39;s positional gff struct which contains the position and orientation.
Definition: object.cpp:212
Mathematical helpers.
uint64 getUint(const Common::UString &field, uint64 def=0) const
Definition: gff3file.cpp:436
void readScripts(const Aurora::GFF3Struct &gff)
Definition: container.cpp:91
std::vector< VertexAttrib > VertexDecl
Vertex data layout.
Definition: vertexbuffer.h:63
Exception that provides a stack of explanations.
Definition: error.h:36
bool isDetectable() const
Is this trigger detectable?
Definition: trigger.cpp:57
A simple scoped smart pointer template.
void load(const Aurora::GFF3Struct &trigger)
Load from a trigger instance.
Definition: trigger.cpp:81
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
void loadInstance(const Aurora::GFF3Struct &gff)
Load the trigger instance properties.
Definition: trigger.cpp:117
Utility templates and functions.
A trigger in a Jade Empire area.
A GFF (generic file format) V3.2/V3.3 file, found in all Aurora games except Sonic Chronicles: The Da...
Definition: gff3file.h:85
void setVertexDeclLinear(uint32 vertCount, VertexDecl &decl)
Set the linear vertex declaration for this buffer.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
bool _isFlagged
Is this trigger flagged?
Definition: trigger.h:72
bool isHenchmenData() const
Does this trigger have henchmen data?
Definition: trigger.cpp:73
Trigger, GFF.
Definition: types.h:338
Handling BioWare&#39;s localized strings.
std::vector< const GFF3Struct * > GFF3List
Definition: types.h:449
bool _isHenchmenData
Does this trigger have henchmen data?
Definition: trigger.h:74
Common::UString getTransitionText() const
Return the trigger&#39;s transition text.
Definition: trigger.cpp:77
bool isOneShot() const
Does this trigger only fire once?
Definition: trigger.cpp:49
void loadBlueprint(const Aurora::GFF3Struct &gff)
Load the trigger blueprint properties.
Definition: trigger.cpp:100
An object within a Jade area.
Definition: object.h:53
bool _isDetectable
Is this trigger detectable?
Definition: trigger.h:70
const GFF3List & getList(const Common::UString &field) const
Definition: gff3file.cpp:741
bool isTrap() const
Does this trigger represent a trap?
Definition: trigger.cpp:53
A struct within a GFF3.
Definition: gff3file.h:164
uint32_t uint32
Definition: types.h:204
Common::UString _tag
Definition: object.h:56
GLvoid * getData()
Access buffer data.
bool _isDisarmable
Is this trigger disarmable?
Definition: trigger.h:71
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Definition: gff3file.cpp:527
Generic Aurora engines utility functions.
Common::UString _transitionText
The trigger&#39;s transition text.
Definition: trigger.h:80
bool _isOneShot
Does this trigger only fire once?
Definition: trigger.h:68
Trigger(const Aurora::GFF3Struct &trigger)
Load from a trigger instance.
Definition: trigger.cpp:41
bool _isTrap
Does this trigger represent a trap?
Definition: trigger.h:69
bool isDisarmable() const
Is this trigger disarmable?
Definition: trigger.cpp:61
Generic vertex attribute data.
Definition: vertexbuffer.h:43
bool isFlagged() const
Is this trigger flagged?
Definition: trigger.cpp:65
int _loadScreen
The loading screen used.
Definition: trigger.h:78
bool _isAreaTrans
Does this trigger represent an area transition?
Definition: trigger.h:73