xoreos  0.0.5
object.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/uuid.h"
27 
28 #include "src/aurora/gff3file.h"
29 #include "src/aurora/talkman.h"
30 
32 
34 #include "src/engines/jade/types.h"
35 
36 namespace Engines {
37 
38 namespace Jade {
39 
40 Object::Object(ObjectType type) : _type(type), _conversation(""), _static(false), _usable(true),
41  _active(false), _noCollide(false), _pcSpeaker(0), _area(0), _lastTriggerer(0) {
43  ObjectMan.registerObject(this);
44 
45  _position [0] = 0.0f;
46  _position [1] = 0.0f;
47  _position [2] = 0.0f;
48  _orientation[0] = 0.0f;
49  _orientation[1] = 0.0f;
50  _orientation[2] = 0.0f;
51  _orientation[3] = 0.0f;
52 }
53 
55  ObjectMan.unregisterObject(this);
56 }
57 
59  return _type;
60 }
61 
63 }
64 
66 }
67 
68 void Object::show() {
69 }
70 
71 void Object::hide() {
72 }
73 
75  return _name;
76 }
77 
79  return _description;
80 }
81 
83  return _conversation;
84 }
85 
86 bool Object::isStatic() const {
87  return _static;
88 }
89 
90 bool Object::isUsable() const {
91  return _usable;
92 }
93 
94 bool Object::isActive() const {
95  return _active;
96 }
97 
98 bool Object::isNoCollide() const {
99  return _noCollide;
100 }
101 
102 void Object::setNoCollide(bool noCollide) {
103  _noCollide = noCollide;
104 }
105 
106 bool Object::isClickable() const {
107  return !_static && _usable;
108 }
109 
110 const std::list<uint32> &Object::getIDs() const {
111  return _ids;
112 }
113 
115  return _pcSpeaker;
116 }
117 
119  _pcSpeaker = pc;
120 }
121 
123  return _area;
124 }
125 
126 void Object::setArea(Area *area) {
127  _area = area;
128 }
129 
131  // TODO: Object::getLocation(): Facing
132 
133  Location location;
134 
135  location.setArea(_area);
136  location.setPosition(_position[0], _position[1], _position[2]);
137  location.setFacing(0.0f);
138 
139  return location;
140 }
141 
142 void Object::getPosition(float &x, float &y, float &z) const {
143  x = _position[0];
144  y = _position[1];
145  z = _position[2];
146 }
147 
148 void Object::getOrientation(float &x, float &y, float &z, float &angle) const {
149  x = _orientation[0];
150  y = _orientation[1];
151  z = _orientation[2];
152 
153  angle = _orientation[3];
154 }
155 
156 void Object::setPosition(float x, float y, float z) {
157  _position[0] = x;
158  _position[1] = y;
159  _position[2] = z;
160 }
161 
162 void Object::setOrientation(float x, float y, float z, float angle) {
163  _orientation[0] = x;
164  _orientation[1] = y;
165  _orientation[2] = z;
166  _orientation[3] = angle;
167 }
168 
170 }
171 
173 }
174 
175 void Object::highlight(bool UNUSED(enabled)) {
176 }
177 
178 bool Object::click(Object *triggerer) {
179  bool result = false;
181  result = runScript(kScriptOnClick, this, triggerer);
182  if (hasScript(kScriptOnUse))
183  result = runScript(kScriptOnUse, this, triggerer);
184 
185  if (result)
186  _lastTriggerer = triggerer;
187 
188  return result;
189 }
190 
192  return _lastTriggerer;
193 }
194 
196  // TODO: Object::speakString(): Show the string in a speech bubble
197 
198  status("<%s> \"%s\"", getName().c_str(), TalkMan.getString(strRef).c_str());
199 }
200 
202  bool UNUSED(restart), int32 UNUSED(loopCount)) {
203 
204  warning("TODO: Object::playAnimation(\"%s\")", animation.c_str());
205 }
206 
208  warning("TODO: Object::playAnimation(%d)", (int) animation);
209  // playAnimation(kAnimations[animation]);
210 }
211 
213 
214  const Aurora::GFF3Struct &positional = gff.getStruct("Positional");
215 
216  double x, y, z;
217 
218  // Position
219 
220  positional.getVector("Position", x, y, z);
221  setPosition(x, y, z);
222 
223  // Orientation
224 
225  positional.getVector("Orientation", x, y, z);
226  setOrientation(x, y, z, 0);
227 }
228 
229 } // End of namespace Jade
230 
231 } // End of namespace Engines
#define ObjectMan
Definition: objectman.h:56
An object within a Jade Empire area.
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
float _orientation[4]
The object&#39;s orientation.
Definition: object.h:169
virtual void highlight(bool enabled)
(Un)Highlight the object.
Definition: object.cpp:175
Common::UString _description
The object&#39;s description.
Definition: object.h:150
Common::UString _conversation
The object&#39;s default conversation.
Definition: object.h:152
Location getLocation() const
Create a Location out of the object&#39;s area, position and orientation.
Definition: object.cpp:130
bool isNoCollide() const
Is collision checking disabled?
Definition: object.cpp:98
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
Area * getArea() const
Return the area this object is currently in.
Definition: object.cpp:122
A class holding an UTF-8 string.
Definition: ustring.h:48
virtual void show()
Show the object&#39;s model(s).
Definition: object.cpp:68
void loadPositional(const Aurora::GFF3Struct &gff)
Load the object&#39;s positional gff struct which contains the position and orientation.
Definition: object.cpp:212
virtual void setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:156
void setPosition(float x, float y, float z)
Set the location&#39;s position.
Definition: location.cpp:58
Utility functions for generating unique IDs.
const Common::UString & getDescription() const
Return the object&#39;s description.
Definition: object.cpp:78
virtual void playAnimation(const Common::UString &animation="", bool restart=true, int32 loopCount=0)
Play an object animation.
Definition: object.cpp:201
Area * _area
The area the object is currently in.
Definition: object.h:164
Aurora::NWScript::Object * getPCSpeaker() const
Return the PC currently speaking with this object.
Definition: object.cpp:114
bool hasScript(Script script) const
Definition: container.cpp:82
void setNoCollide(bool noCollide)
Enable or disable collision checking.
Definition: object.cpp:102
bool runScript(Script script, const Aurora::NWScript::ObjectReference owner=Aurora::NWScript::ObjectReference(), const Aurora::NWScript::ObjectReference triggerer=Aurora::NWScript::ObjectReference())
Definition: container.cpp:110
bool isClickable() const
Can the player click the object?
Definition: object.cpp:106
const Common::UString & getConversation() const
Return the object&#39;s default conversation (DLG).
Definition: object.cpp:82
virtual ~Object()
Definition: object.cpp:54
virtual void enter()
The cursor entered the object.
Definition: object.cpp:169
float _position[3]
The object&#39;s position.
Definition: object.h:168
NWScript object manager.
bool _static
Is the object static?
Definition: object.h:154
bool isUsable() const
Can the object be used by the PC?
Definition: object.cpp:90
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
void getVector(const Common::UString &field, float &x, float &y, float &z) const
Definition: gff3file.cpp:660
Basic Jade Empire type definitions.
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
bool _usable
Is the object usable?
Definition: object.h:155
An area in Jade Empire, holding all objects and rooms within, as well as general area properties like...
Definition: area.h:57
virtual void getOrientation(float &x, float &y, float &z, float &angle) const
Return the object&#39;s orientation.
Definition: object.cpp:148
void speakString(int32 resref)
Speak the specified string.
Definition: object.cpp:195
bool _active
Is the object currently active/available/visible?
Definition: object.h:156
virtual bool click(Object *triggerer=0)
The object was clicked.
Definition: object.cpp:178
void setPCSpeaker(Aurora::NWScript::Object *pc)
Set the PC currently speaking with this object.
Definition: object.cpp:118
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:142
bool isStatic() const
Is the object static (not manipulable at all)?
Definition: object.cpp:86
void warning(const char *s,...)
Definition: util.cpp:33
Object * getLastTriggerer() const
Return the object that last triggered this object.
Definition: object.cpp:191
An object within a Jade area.
Definition: object.h:53
std::list< uint32 > _ids
The object&#39;s model IDs.
Definition: object.h:160
A struct within a GFF3.
Definition: gff3file.h:164
bool isActive() const
Is the object currently active/available/visible?
Definition: object.cpp:94
const GFF3Struct & getStruct(const Common::UString &field) const
Definition: gff3file.cpp:728
The global talk manager for Aurora strings.
virtual void hide()
Hide the object&#39;s model(s).
Definition: object.cpp:71
virtual void loadModel()
Load the object&#39;s model(s).
Definition: object.cpp:62
void status(const char *s,...)
Definition: util.cpp:52
bool _noCollide
Is collision checking for the object disabled?
Definition: object.h:158
void setArea(Area *)
Set the area this object is currently in.
Definition: object.cpp:126
virtual void leave()
The cursor left the object.
Definition: object.cpp:172
void setFacing(float facing)
Set the location&#39;s orientation.
Definition: location.cpp:68
virtual void unloadModel()
Unload the object&#39;s model(s).
Definition: object.cpp:65
Common::UString _name
The object&#39;s display name.
Definition: object.h:149
const std::list< uint32 > & getIDs() const
Return the object&#39;s model IDs.
Definition: object.cpp:110
ObjectType getType() const
Return the exact type of the object.
Definition: object.cpp:58
Object * _lastTriggerer
The object that last used this object.
Definition: object.h:166
const Common::UString & getName() const
Return the object&#39;s name.
Definition: object.cpp:74
virtual void setOrientation(float x, float y, float z, float angle)
Set the object&#39;s orientation.
Definition: object.cpp:162
uint32 generateIDNumber()
Definition: uuid.cpp:46
Aurora::NWScript::Object * _pcSpeaker
The current PC speaking with the object.
Definition: object.h:162
ObjectType _type
The object&#39;s type.
Definition: object.h:147
int32_t int32
Definition: types.h:203
void setArea(Area *area)
Set the location&#39;s area.
Definition: location.cpp:48