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/error.h"
27 #include "src/common/uuid.h"
28 
29 #include "src/aurora/dlgfile.h"
30 
32 
33 #include "src/sound/sound.h"
34 
36 
38 
39 namespace Engines {
40 
41 namespace Witcher {
42 
43 Object::Object(ObjectType type) : _type(type),
44  _static(false), _usable(true), _area(0) {
46  ObjectMan.registerObject(this);
47 
48  _position [0] = 0.0f;
49  _position [1] = 0.0f;
50  _position [2] = 0.0f;
51  _orientation[0] = 0.0f;
52  _orientation[1] = 0.0f;
53  _orientation[2] = 0.0f;
54  _orientation[3] = 0.0f;
55 }
56 
58  ObjectMan.unregisterObject(this);
59 }
60 
62  return _type;
63 }
64 
66 }
67 
69 }
70 
71 void Object::show() {
72 }
73 
74 void Object::hide() {
75 }
76 
78  return _uniqueID;
79 }
80 
82  return _name;
83 }
84 
86  return _description;
87 }
88 
90  return _conversation;
91 }
92 
94 }
95 
96 bool Object::isStatic() const {
97  return _static;
98 }
99 
100 bool Object::isUsable() const {
101  return _usable;
102 }
103 
104 bool Object::isClickable() const {
105  return !_static && _usable;
106 }
107 
108 const std::list<uint32> &Object::getIDs() const {
109  return _ids;
110 }
111 
113  return _area;
114 }
115 
116 void Object::setArea(Area *area) {
117  _area = area;
118 }
119 
121  // TODO: Object::getLocation(): Facing
122 
123  Location location;
124 
125  location.setArea(_area);
126  location.setPosition(_position[0], _position[1], _position[2]);
127  location.setFacing(0.0f);
128 
129  return location;
130 }
131 
132 void Object::getPosition(float &x, float &y, float &z) const {
133  x = _position[0];
134  y = _position[1];
135  z = _position[2];
136 }
137 
138 void Object::getOrientation(float &x, float &y, float &z, float &angle) const {
139  x = _orientation[0];
140  y = _orientation[1];
141  z = _orientation[2];
142 
143  angle = _orientation[3];
144 }
145 
146 void Object::setPosition(float x, float y, float z) {
147  _position[0] = x;
148  _position[1] = y;
149  _position[2] = z;
150 }
151 
152 void Object::setOrientation(float x, float y, float z, float angle) {
153  _orientation[0] = x;
154  _orientation[1] = y;
155  _orientation[2] = z;
156  _orientation[3] = angle;
157 }
158 
160 }
161 
163 }
164 
165 void Object::highlight(bool UNUSED(enabled)) {
166 }
167 
168 void Object::speakString(const Common::UString &string, uint32 UNUSED(volume)) {
169  // TODO: Object::speakString(): Show the string in a speech bubble
170 
171  status("<%s> \"%s\"", getName().getString().c_str(), string.c_str());
172 }
173 
175  if (conv.empty())
176  conv = _conversation;
177  if (conv.empty())
178  return;
179 
180  Common::UString text;
181  Common::UString sound;
182 
183 
184  try {
185  Aurora::DLGFile dlg(conv, this);
186 
187  const Aurora::DLGFile::Line *line = dlg.getOneLiner();
188  if (line) {
189  text = line->text.getString();
190  sound = line->sound;
191  }
192 
193  } catch (...) {
194  Common::exceptionDispatcherWarning("Failed evaluating one-liner from conversation \"%s\"", conv.c_str());
195  }
196 
197  if (!text.empty())
198  speakString(text, 0);
199  if (!sound.empty())
200  playSound(sound);
201 }
202 
204  SoundMan.stopChannel(_sound);
205 }
206 
207 void Object::playSound(const Common::UString &sound, bool pitchVariance) {
208  stopSound();
209  if (sound.empty())
210  return;
211 
212  _sound = ::Engines::playSound(sound, Sound::kSoundTypeVoice, false, 1.0f, pitchVariance);
213 }
214 
215 bool Object::click(Object *UNUSED(triggerer)) {
216  return true;
217 }
218 
219 } // End of namespace Witcher
220 
221 } // End of namespace Engines
#define ObjectMan
Definition: objectman.h:56
ObjectType getType() const
Return the exact type of the object.
Definition: object.cpp:61
void stopSound()
Stop the current object sound.
Definition: object.cpp:203
Area * getArea() const
Return the area this object is currently in.
Definition: object.cpp:112
An area in The Witcher, holding all objects and area geometry within, as well as general area propert...
Definition: area.h:63
virtual void setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:146
const Common::UString & getConversation() const
Return the object&#39;s default conversation (DLG).
Definition: object.cpp:89
A class holding an UTF-8 string.
Definition: ustring.h:48
void playSound(const Common::UString &sound, bool pitchVariance=false)
Play an object sound.
Definition: object.cpp:207
An object within a Witcher area.
Definition: object.h:51
A localized string.
Definition: locstring.h:43
void setFacing(float facing)
Set the location&#39;s orientation.
Definition: location.cpp:68
void setPosition(float x, float y, float z)
Set the location&#39;s position.
Definition: location.cpp:58
void setArea(Area *)
Set the area this object is currently in.
Definition: object.cpp:116
virtual void hide()
Hide the object&#39;s model(s).
Definition: object.cpp:74
Utility functions for generating unique IDs.
void setArea(Area *area)
Set the location&#39;s area.
Definition: location.cpp:48
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:132
const Common::UString & getString(Language language, LanguageGender gender=kLanguageGenderCurrent) const
Get the string of that language.
Definition: locstring.cpp:82
virtual bool click(Object *triggerer=0)
The object was clicked.
Definition: object.cpp:215
Common::UString sound
ResRef of the sound to play while speaking this entry.
Definition: dlgfile.h:73
bool isClickable() const
Can the player click the object?
Definition: object.cpp:104
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
virtual void unloadModel()
Unload the object&#39;s model(s).
Definition: object.cpp:68
const Line * getOneLiner() const
Return the first active non-branching entry.
Definition: dlgfile.cpp:151
NWScript object manager.
Sound::ChannelHandle _sound
The currently playing object sound.
Definition: object.h:161
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
const std::list< uint32 > & getIDs() const
Return the object&#39;s model IDs.
Definition: object.cpp:108
#define UNUSED(x)
Definition: system.h:170
virtual void getOrientation(float &x, float &y, float &z, float &angle) const
Return the object&#39;s orientation.
Definition: object.cpp:138
Utility templates and functions.
virtual void show()
Show the object&#39;s model(s).
Definition: object.cpp:71
Aurora::LocString _description
The object&#39;s description.
Definition: object.h:147
An object in a The Witcher area.
bool isUsable() const
Can the object be used by the PC?
Definition: object.cpp:100
const Aurora::LocString & getName() const
Return the object&#39;s name.
Definition: object.cpp:81
Common::UString _uniqueID
A globally unique ID.
Definition: object.h:144
virtual void highlight(bool enabled)
(Un)Highlight the object.
Definition: object.cpp:165
The global sound manager, handling all sound output.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
ObjectType _type
The object&#39;s type.
Definition: object.h:142
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
bool _static
Is the object static?
Definition: object.h:151
Voice/Speech.
Definition: types.h:46
virtual void refreshLocalized()
Refresh all localized strings.
Definition: object.cpp:93
bool _usable
Is the object usable?
Definition: object.h:152
Sound::ChannelHandle playSound(const Common::UString &sound, Sound::SoundType soundType, bool loop, float volume, bool pitchVariance)
Play this sound resource.
Definition: util.cpp:81
virtual void enter()
The cursor entered the object.
Definition: object.cpp:159
virtual void setOrientation(float x, float y, float z, float angle)
Set the object&#39;s orientation.
Definition: object.cpp:152
void speakOneLiner(Common::UString conv, Object *tokenTarget=0)
Speak an one-liner from the specified conversation file.
Definition: object.cpp:174
float _position[3]
The object&#39;s position.
Definition: object.h:158
uint32_t uint32
Definition: types.h:204
float _orientation[4]
The object&#39;s orientation.
Definition: object.h:159
Common::UString _conversation
The object&#39;s default conversation.
Definition: object.h:149
void status(const char *s,...)
Definition: util.cpp:52
bool isStatic() const
Is the object static (not manipulable at all)?
Definition: object.cpp:96
Area * _area
The area the object is currently in.
Definition: object.h:156
Aurora::LocString _name
The object&#39;s name.
Definition: object.h:146
Generic Aurora engines utility functions.
Location getLocation() const
Create a Location out of the object&#39;s area, position and orientation.
Definition: object.cpp:120
const Common::UString & getUniqueID() const
Return the object&#39;s globally unique ID.
Definition: object.cpp:77
virtual void leave()
The cursor left the object.
Definition: object.cpp:162
virtual void loadModel()
Load the object&#39;s model(s).
Definition: object.cpp:65
Handling BioWare&#39;s DLGs (dialog / conversation files).
std::list< uint32 > _ids
The object&#39;s model IDs.
Definition: object.h:154
uint32 generateIDNumber()
Definition: uuid.cpp:46
LocString text
The actual text of the entry.
Definition: dlgfile.h:71
const Aurora::LocString & getDescription() const
Return the object&#39;s description.
Definition: object.cpp:85
void speakString(const Common::UString &string, uint32 volume)
Speak the specified string.
Definition: object.cpp:168