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/maths.h"
27 #include "src/common/uuid.h"
28 
30 
32 
33 #include "src/sound/sound.h"
34 
36 
37 namespace Engines {
38 
39 namespace KotOR {
40 
42  : _type(type),
43  _static(false),
44  _usable(true),
45  _currentHitPoints(0),
46  _maxHitPoints(0),
47  _minOneHitPoint(false),
48  _room(0) {
50  ObjectMan.registerObject(this);
51 
52  _position [0] = 0.0f;
53  _position [1] = 0.0f;
54  _position [2] = 0.0f;
55  _orientation[0] = 0.0f;
56  _orientation[1] = 0.0f;
57  _orientation[2] = 0.0f;
58  _orientation[3] = 0.0f;
59 }
60 
62  ObjectMan.unregisterObject(this);
63 }
64 
66  return _type;
67 }
68 
69 void Object::show() {
70 }
71 
72 void Object::hide() {
73 }
74 
76  hide();
77 }
78 
79 bool Object::isVisible() const {
80  return false;
81 }
82 
84  return _name;
85 }
86 
88  return _description;
89 }
90 
92  return _portrait;
93 }
94 
95 void Object::setMaxHitPoints(int maxHP) {
96  _maxHitPoints = maxHP;
97 }
98 
100  return _maxHitPoints;
101 }
102 
103 void Object::setCurrentHitPoints(int hitpoints) {
104  if (_minOneHitPoint)
105  _currentHitPoints = MIN(1, MIN(hitpoints, _maxHitPoints));
106  else
107  _currentHitPoints = MIN(hitpoints, _maxHitPoints);
108 }
109 
111  return _currentHitPoints;
112 }
113 
114 void Object::setMinOneHitPoints(bool enabled) {
115  _minOneHitPoint = enabled;
116 }
117 
119  return _minOneHitPoint;
120 }
121 
122 bool Object::isStatic() const {
123  return _static;
124 }
125 
126 bool Object::isUsable() const {
127  return _usable;
128 }
129 
130 bool Object::isClickable() const {
131  return !_static && _usable;
132 }
133 
134 const std::list<uint32> &Object::getIDs() const {
135  return _ids;
136 }
137 
138 void Object::getPosition(float &x, float &y, float &z) const {
139  x = _position[0];
140  y = _position[1];
141  z = _position[2];
142 }
143 
144 void Object::getOrientation(float &x, float &y, float &z, float &angle) const {
145  x = _orientation[0];
146  y = _orientation[1];
147  z = _orientation[2];
148 
149  angle = _orientation[3];
150 }
151 
152 void Object::setPosition(float x, float y, float z) {
153  _position[0] = x;
154  _position[1] = y;
155  _position[2] = z;
156 }
157 
158 void Object::setOrientation(float x, float y, float z, float angle) {
159  _orientation[0] = x;
160  _orientation[1] = y;
161  _orientation[2] = z;
162  _orientation[3] = angle;
163 }
164 
165 void Object::makeLookAt(float x, float y) {
166  float dx = x - _position[0];
167  float dy = y - _position[1];
168  setOrientation(0.0f, 0.0f, 1.0f, Common::rad2deg(std::atan2(dy, dx)) - 90.0f);
169 }
170 
171 void Object::makeLookAt(Object *target) {
172  makeLookAt(target->_position[0], target->_position[1]);
173 }
174 
176  return _room;
177 }
178 
179 void Object::setRoom(Room *room) {
180  _room = room;
181 }
182 
184 }
185 
187 }
188 
189 void Object::highlight(bool UNUSED(enabled)) {
190 }
191 
192 bool Object::click(Object *UNUSED(triggerer)) {
193  return true;
194 }
195 
197  SoundMan.stopChannel(_sound);
198 }
199 
200 void Object::playSound(const Common::UString &sound, bool pitchVariance) {
201  stopSound();
202  if (sound.empty())
203  return;
204 
205  _sound = ::Engines::playSound(sound, Sound::kSoundTypeVoice, false, 1.0f, pitchVariance);
206 }
207 
208 void Object::playAnimation(const Common::UString &UNUSED(anim), bool UNUSED(restart), float UNUSED(length), float UNUSED(speed)) {
209 }
210 
211 } // End of namespace KotOR
212 
213 } // End of namespace Engines
#define ObjectMan
Definition: objectman.h:56
virtual void hide()
Hide the object&#39;s model(s).
Definition: object.cpp:72
void stopSound()
Stop the current object sound.
Definition: object.cpp:196
Room * _room
Room the object is in.
Definition: object.h:161
bool _static
Is the object static?
Definition: object.h:147
Sound::ChannelHandle _sound
The currently playing object sound.
Definition: object.h:159
A class holding an UTF-8 string.
Definition: ustring.h:48
const Common::UString & getPortrait() const
Return the object&#39;s portrait.
Definition: object.cpp:91
Mathematical helpers.
Utility functions for generating unique IDs.
virtual void playAnimation(const Common::UString &anim, bool restart=true, float length=0.0f, float speed=1.0f)
Definition: object.cpp:208
ObjectType
Object type, matches the bitfield in nwscript.nss.
Definition: types.h:33
Common::UString _description
The object&#39;s description.
Definition: object.h:143
bool isStatic() const
Is the object static (not manipulable at all)?
Definition: object.cpp:122
ObjectType getType() const
Return the exact type of the object.
Definition: object.cpp:65
virtual void hideSoft()
Hide the object&#39;s model(s) if applicable.
Definition: object.cpp:75
virtual void show()
Show the object&#39;s model(s).
Definition: object.cpp:69
void setCurrentHitPoints(int hitpoints)
Set the current hitpoints.
Definition: object.cpp:103
NWScript object manager.
int getCurrentHitPoints()
Return the objects current hitpoints.
Definition: object.cpp:110
Common::UString _portrait
The object&#39;s portrait.
Definition: object.h:145
const Common::UString & getName() const
Return the object&#39;s name.
Definition: object.cpp:83
#define UNUSED(x)
Definition: system.h:170
bool isClickable() const
Can the player click the object?
Definition: object.cpp:130
Utility templates and functions.
Common::UString _name
The object&#39;s display name.
Definition: object.h:142
float _position[3]
The object&#39;s position.
Definition: object.h:156
Room * getRoom()
Get a room the object is in.
Definition: object.cpp:175
virtual bool isVisible() const
Is the object&#39;s model(s) visible?
Definition: object.cpp:79
ObjectType _type
The object&#39;s type.
Definition: object.h:140
virtual void setOrientation(float x, float y, float z, float angle)
Set the object&#39;s orientation.
Definition: object.cpp:158
bool getMinOneHitPoints() const
Get if the object has a minimum of one hp.
Definition: object.cpp:118
T MIN(T a, T b)
Definition: util.h:70
float _orientation[4]
The object&#39;s orientation.
Definition: object.h:157
int getMaxHitPoints()
Get the maximum hit points for the objects.
Definition: object.cpp:99
The global sound manager, handling all sound output.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void setMinOneHitPoints(bool enabled)
Set if the object has a minimum of one hp.
Definition: object.cpp:114
const std::list< uint32 > & getIDs() const
Return the object&#39;s model IDs.
Definition: object.cpp:134
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
int _currentHitPoints
The current hitpoints of the object.
Definition: object.h:150
virtual void getOrientation(float &x, float &y, float &z, float &angle) const
Return the object&#39;s orientation.
Definition: object.cpp:144
bool isUsable() const
Can the object be used by the PC?
Definition: object.cpp:126
Voice/Speech.
Definition: types.h:46
bool _minOneHitPoint
If the object should have at least one hitpoint.
Definition: object.h:152
void playSound(const Common::UString &sound, bool pitchVariance=false)
Play an object sound.
Definition: object.cpp:200
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:183
std::list< uint32 > _ids
The object&#39;s model IDs.
Definition: object.h:154
virtual bool click(Object *triggerer=0)
The object was clicked.
Definition: object.cpp:192
int _maxHitPoints
The maximum hitpoints of the object.
Definition: object.h:151
virtual void setPosition(float x, float y, float z)
Set the object&#39;s position within its area.
Definition: object.cpp:152
void makeLookAt(float x, float y)
Definition: object.cpp:165
virtual void leave()
The cursor left the object.
Definition: object.cpp:186
static float rad2deg(float rad)
Definition: maths.h:93
Generic Aurora engines utility functions.
void setRoom(Room *room)
Set a room the object is in.
Definition: object.cpp:179
An object in a Star Wars: Knights of the Old Republic area.
void setMaxHitPoints(int maxHP)
Set the maximum hit points for the objects.
Definition: object.cpp:95
virtual void getPosition(float &x, float &y, float &z) const
Return the object&#39;s position within its area.
Definition: object.cpp:138
bool _usable
Is the object usable?
Definition: object.h:148
virtual void highlight(bool enabled)
(Un)Highlight the object.
Definition: object.cpp:189
const Common::UString & getDescription() const
Return the object&#39;s description.
Definition: object.cpp:87
uint32 generateIDNumber()
Definition: uuid.cpp:46