Skip to content

Commit

Permalink
KOTOR: Add hitpoints to every object
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius committed Jan 20, 2018
1 parent aa12dd1 commit 8c26839
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/engines/kotor/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* An object in a Star Wars: Knights of the Old Republic area.
*/

#include "src/common/util.h"

#include "src/engines/kotor/object.h"

#include "src/sound/sound.h"
Expand All @@ -32,7 +34,8 @@ namespace Engines {

namespace KotOR {

Object::Object(ObjectType type) : _type(type), _static(false), _usable(true) {
Object::Object(ObjectType type) : _type(type), _static(false), _usable(true), _currentHitPoints(0), _maxHitPoints(0),
_minOneHitPoint(false) {
_position [0] = 0.0f;
_position [1] = 0.0f;
_position [2] = 0.0f;
Expand Down Expand Up @@ -67,6 +70,33 @@ const Common::UString &Object::getPortrait() const {
return _portrait;
}

void Object::setMaxHitPoints(int maxHP) {
_maxHitPoints = maxHP;
}

int Object::getMaxHitPoints() {
return _maxHitPoints;
}

void Object::setCurrentHitPoints(int hitpoints) {
if (_minOneHitPoint)
_currentHitPoints = MIN(1, MIN(hitpoints, _maxHitPoints));
else
_currentHitPoints = MIN(hitpoints, _maxHitPoints);
}

int Object::getCurrentHitPoints() {
return _currentHitPoints;
}

void Object::setMinOneHitPoints(bool enabled) {
_minOneHitPoint = enabled;
}

bool Object::getMinOneHitPoints() const {
return _minOneHitPoint;
}

bool Object::isStatic() const {
return _static;
}
Expand Down
17 changes: 17 additions & 0 deletions src/engines/kotor/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ class Object : public Aurora::NWScript::Object, public KotOR::ScriptContainer {
/** Return the object's portrait. */
const Common::UString &getPortrait() const;

/** Set the maximum hit points for the objects. */
void setMaxHitPoints(int maxHP);
/** Get the maximum hit points for the objects. */
int getMaxHitPoints();
/** Set the current hitpoints. */
void setCurrentHitPoints(int hitpoints);
/** Return the objects current hitpoints. */
int getCurrentHitPoints();
/** Set if the object has a minimum of one hp. */
void setMinOneHitPoints(bool enabled);
/** Get if the object has a minimum of one hp. */
bool getMinOneHitPoints() const;

// Interactive properties

bool isStatic() const; ///< Is the object static (not manipulable at all)?
Expand Down Expand Up @@ -115,6 +128,10 @@ class Object : public Aurora::NWScript::Object, public KotOR::ScriptContainer {
bool _static; ///< Is the object static?
bool _usable; ///< Is the object usable?

int _currentHitPoints; ///< The current hitpoints of the object.
int _maxHitPoints; ///< The maximum hitpoints of the object.
bool _minOneHitPoint; ///< If the object should have at least one hitpoint.

std::list<uint32> _ids; ///< The object's model IDs.

float _position[3]; ///< The object's position.
Expand Down

0 comments on commit 8c26839

Please sign in to comment.