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/maths.h"
26 #include "src/common/uuid.h"
27 
29 
31 
32 #include "src/sound/sound.h"
33 
35 
36 namespace Engines {
37 
38 namespace KotOR2 {
39 
41  : _type(type),
42  _static(false),
43  _usable(true),
44  _room(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 
65 void Object::show() {
66 }
67 
68 void Object::hide() {
69 }
70 
72  hide();
73 }
74 
75 bool Object::isVisible() const {
76  return false;
77 }
78 
80  return _name;
81 }
82 
84  return _description;
85 }
86 
88  return _portrait;
89 }
90 
91 bool Object::isStatic() const {
92  return _static;
93 }
94 
95 bool Object::isUsable() const {
96  return _usable;
97 }
98 
99 bool Object::isClickable() const {
100  return !_static && _usable;
101 }
102 
103 const std::list<uint32> &Object::getIDs() const {
104  return _ids;
105 }
106 
107 void Object::getPosition(float &x, float &y, float &z) const {
108  x = _position[0];
109  y = _position[1];
110  z = _position[2];
111 }
112 
113 void Object::getOrientation(float &x, float &y, float &z, float &angle) const {
114  x = _orientation[0];
115  y = _orientation[1];
116  z = _orientation[2];
117 
118  angle = _orientation[3];
119 }
120 
121 void Object::setPosition(float x, float y, float z) {
122  _position[0] = x;
123  _position[1] = y;
124  _position[2] = z;
125 }
126 
127 void Object::setOrientation(float x, float y, float z, float angle) {
128  _orientation[0] = x;
129  _orientation[1] = y;
130  _orientation[2] = z;
131  _orientation[3] = angle;
132 }
133 
134 void Object::makeLookAt(float x, float y) {
135  float dx = x - _position[0];
136  float dy = y - _position[1];
137  setOrientation(0.0f, 0.0f, 1.0f, Common::rad2deg(std::atan2(dy, dx)) - 90.0f);
138 }
139 
140 void Object::makeLookAt(Object *target) {
141  makeLookAt(target->_position[0], target->_position[1]);
142 }
143 
145  return _room;
146 }
147 
148 void Object::setRoom(Room *room) {
149  _room = room;
150 }
151 
153 }
154 
156 }
157 
158 void Object::highlight(bool UNUSED(enabled)) {
159 }
160 
161 bool Object::click(Object *UNUSED(triggerer)) {
162  return true;
163 }
164 
166  SoundMan.stopChannel(_sound);
167 }
168 
169 void Object::playSound(const Common::UString &sound, bool pitchVariance) {
170  stopSound();
171  if (sound.empty())
172  return;
173 
174  _sound = ::Engines::playSound(sound, Sound::kSoundTypeVoice, false, 1.0f, pitchVariance);
175 }
176 
177 void Object::playAnimation(const Common::UString &UNUSED(anim), bool UNUSED(restart), float UNUSED(length), float UNUSED(speed)) {
178 }
179 
180 } // End of namespace KotOR2
181 
182 } // End of namespace Engines
#define ObjectMan
Definition: objectman.h:56
bool isStatic() const
Is the object static (not manipulable at all)?
Definition: object.cpp:91
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:107
Room * getRoom()
Get a room the object is in.
Definition: object.cpp:144
A class holding an UTF-8 string.
Definition: ustring.h:48
void stopSound()
Stop the current object sound.
Definition: object.cpp:165
virtual void playAnimation(const Common::UString &anim, bool restart=true, float length=0.0f, float speed=1.0f)
Definition: object.cpp:177
float _position[3]
The object&#39;s position.
Definition: object.h:139
float _orientation[4]
The object&#39;s orientation.
Definition: object.h:140
virtual void hideSoft()
Hide the object&#39;s model(s) if applicable.
Definition: object.cpp:71
Mathematical helpers.
virtual bool click(Object *triggerer=0)
The object was clicked.
Definition: object.cpp:161
virtual void setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:121
Utility functions for generating unique IDs.
virtual bool isVisible() const
Is the object&#39;s model(s) visible?
Definition: object.cpp:75
bool _usable
Is the object usable?
Definition: object.h:135
virtual void enter()
The cursor entered the object.
Definition: object.cpp:152
virtual void getOrientation(float &x, float &y, float &z, float &angle) const
Return the object&#39;s orientation.
Definition: object.cpp:113
virtual void hide()
Hide the object&#39;s model(s).
Definition: object.cpp:68
NWScript object manager.
virtual void highlight(bool enabled)
(Un)Highlight the object.
Definition: object.cpp:158
bool isClickable() const
Can the player click the object?
Definition: object.cpp:99
An object in a Star Wars: Knights of the Old Republic II - The Sith Lords area.
const Common::UString & getDescription() const
Return the object&#39;s description.
Definition: object.cpp:83
#define UNUSED(x)
Definition: system.h:170
std::list< uint32 > _ids
The object&#39;s model IDs.
Definition: object.h:137
Common::UString _name
The object&#39;s display name.
Definition: object.h:129
Common::UString _portrait
The object&#39;s portrait.
Definition: object.h:132
The global sound manager, handling all sound output.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
void setRoom(Room *room)
Set a room the object is in.
Definition: object.cpp:148
Sound::ChannelHandle _sound
The currently playing object sound.
Definition: object.h:142
ObjectType _type
The object&#39;s type.
Definition: object.h:127
bool isUsable() const
Can the object be used by the PC?
Definition: object.cpp:95
void playSound(const Common::UString &sound, bool pitchVariance=false)
Play an object sound.
Definition: object.cpp:169
Voice/Speech.
Definition: types.h:46
Sound::ChannelHandle playSound(const Common::UString &sound, Sound::SoundType soundType, bool loop, float volume, bool pitchVariance)
Play this sound resource.
Definition: util.cpp:81
ObjectType getType() const
Return the exact type of the object.
Definition: object.cpp:61
ObjectType
Object type, matches the bitfield in nwscript.nss.
Definition: types.h:33
virtual void setOrientation(float x, float y, float z, float angle)
Set the object&#39;s orientation.
Definition: object.cpp:127
bool _static
Is the object static?
Definition: object.h:134
static float rad2deg(float rad)
Definition: maths.h:93
Generic Aurora engines utility functions.
virtual void show()
Show the object&#39;s model(s).
Definition: object.cpp:65
const Common::UString & getPortrait() const
Return the object&#39;s portrait.
Definition: object.cpp:87
virtual void leave()
The cursor left the object.
Definition: object.cpp:155
void makeLookAt(float x, float y)
Definition: object.cpp:134
Room * _room
Room the object is in.
Definition: object.h:144
const std::list< uint32 > & getIDs() const
Return the object&#39;s model IDs.
Definition: object.cpp:103
const Common::UString & getName() const
Return the object&#39;s name.
Definition: object.cpp:79
Common::UString _description
The object&#39;s description.
Definition: object.h:130
uint32 generateIDNumber()
Definition: uuid.cpp:46