mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-23 02:42:39 +01:00
Remove mHealth, clean up code & hook up character health & armour
This commit is contained in:
parent
e5dc1105b4
commit
8cd50fadf0
@ -21,15 +21,15 @@ struct CharacterState
|
||||
{
|
||||
glm::vec3 position;
|
||||
float rotation;
|
||||
float health;
|
||||
float armour;
|
||||
float health = 100.f;
|
||||
float armour = 0.f;
|
||||
CharacterWeaponSlot weapons[maxInventorySlots];
|
||||
uint16_t currentWeapon;
|
||||
uint32_t lastFireTimeMS;
|
||||
bool primaryActive;
|
||||
bool secondaryActive;
|
||||
uint32_t primaryStartTime;
|
||||
uint32_t primaryEndTime;
|
||||
uint16_t currentWeapon = 0;
|
||||
uint32_t lastFireTimeMS = 0;
|
||||
bool primaryActive = false;
|
||||
bool secondaryActive = false;
|
||||
uint32_t primaryStartTime = 0;
|
||||
uint32_t primaryEndTime = 0;
|
||||
};
|
||||
|
||||
class VehicleObject;
|
||||
@ -94,7 +94,7 @@ private:
|
||||
bool _hasTargetPosition;
|
||||
glm::vec3 _targetPosition;
|
||||
|
||||
bool jumped = false;
|
||||
bool jumped;
|
||||
float jumpSpeed;
|
||||
public:
|
||||
|
||||
@ -144,7 +144,8 @@ public:
|
||||
virtual glm::quat getRotation() const;
|
||||
|
||||
bool isAlive() const;
|
||||
|
||||
bool takeDamage(const DamageInfo& damage) override;
|
||||
|
||||
bool enterVehicle(VehicleObject* vehicle, size_t seat);
|
||||
|
||||
/**
|
||||
@ -157,8 +158,6 @@ public:
|
||||
size_t getCurrentSeat() const;
|
||||
void setCurrentVehicle(VehicleObject *value, size_t seat);
|
||||
|
||||
virtual bool takeDamage(const DamageInfo& damage);
|
||||
|
||||
void jump();
|
||||
void setJumpSpeed(float speed);
|
||||
float getJumpSpeed() const;
|
||||
|
@ -15,7 +15,6 @@ class Skeleton;
|
||||
class CharacterController;
|
||||
class ModelFrame;
|
||||
class Animator;
|
||||
|
||||
class GameWorld;
|
||||
|
||||
/**
|
||||
@ -41,11 +40,6 @@ public:
|
||||
Animator* animator; /// Object's animator.
|
||||
Skeleton* skeleton;
|
||||
|
||||
/**
|
||||
* Health value
|
||||
*/
|
||||
float mHealth;
|
||||
|
||||
bool inWater;
|
||||
|
||||
/**
|
||||
@ -59,10 +53,19 @@ public:
|
||||
bool visible;
|
||||
|
||||
GameObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, ModelRef model)
|
||||
: _lastPosition(pos), _lastRotation(rot), objectID(0), position(pos), rotation(rot),
|
||||
model(model), engine(engine), animator(nullptr), skeleton(nullptr), mHealth(0.f),
|
||||
inWater(false), _lastHeight(std::numeric_limits<float>::max()), visible(true),
|
||||
lifetime(GameObject::UnknownLifetime)
|
||||
: _lastPosition(pos)
|
||||
, _lastRotation(rot)
|
||||
, objectID(0)
|
||||
, position(pos)
|
||||
, rotation(rot)
|
||||
, model(model)
|
||||
, engine(engine)
|
||||
, animator(nullptr)
|
||||
, skeleton(nullptr)
|
||||
, inWater(false)
|
||||
, _lastHeight(std::numeric_limits<float>::max())
|
||||
, visible(true)
|
||||
, lifetime(GameObject::UnknownLifetime)
|
||||
{}
|
||||
|
||||
virtual ~GameObject();
|
||||
|
@ -21,12 +21,10 @@ CharacterObject::CharacterObject(GameWorld* engine, const glm::vec3& pos, const
|
||||
, _hasTargetPosition(false)
|
||||
, ped(data)
|
||||
, physCharacter(nullptr)
|
||||
, controller(nullptr)
|
||||
, jumped(false)
|
||||
, controller(nullptr)
|
||||
, jumpSpeed(DefaultJumpSpeed)
|
||||
{
|
||||
mHealth = 100.f;
|
||||
|
||||
// TODO move AnimationGroup creation somewhere else.
|
||||
animations.idle = engine->data->animations["idle_stance"];
|
||||
animations.walk = engine->data->animations["walk_player"];
|
||||
@ -326,7 +324,7 @@ glm::quat CharacterObject::getRotation() const
|
||||
|
||||
bool CharacterObject::isAlive() const
|
||||
{
|
||||
return mHealth > 0.f;
|
||||
return currentState.health > 0.f;
|
||||
}
|
||||
|
||||
bool CharacterObject::enterVehicle(VehicleObject* vehicle, size_t seat)
|
||||
@ -387,7 +385,15 @@ void CharacterObject::setCurrentVehicle(VehicleObject *value, size_t seat)
|
||||
|
||||
bool CharacterObject::takeDamage(const GameObject::DamageInfo& dmg)
|
||||
{
|
||||
mHealth -= dmg.hitpoints;
|
||||
// Right now there's no state that determines immunity to any kind of damage
|
||||
float dmgPoints = dmg.hitpoints;
|
||||
if (currentState.armour > 0.f) {
|
||||
dmgPoints -= currentState.armour;
|
||||
currentState.armour = std::max(0.f, currentState.armour - dmg.hitpoints);
|
||||
}
|
||||
if (dmgPoints > 0.f) {
|
||||
currentState.health = std::max(0.f, currentState.health - dmgPoints);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -162,6 +162,7 @@ void InstanceObject::setRotation(const glm::quat &r)
|
||||
|
||||
bool InstanceObject::takeDamage(const GameObject::DamageInfo& dmg)
|
||||
{
|
||||
RW_CHECK(dmg.hitpoints == 0, "Instance damange not implemented yet");
|
||||
bool explodeOnHit = (object->flags&ObjectData::EXPLODEONHIT) == ObjectData::EXPLODEONHIT;
|
||||
bool smash = (object->flags&ObjectData::SMASHABLE) == ObjectData::SMASHABLE;
|
||||
if( dynamics ) {
|
||||
@ -175,10 +176,10 @@ bool InstanceObject::takeDamage(const GameObject::DamageInfo& dmg)
|
||||
{
|
||||
if(explodeOnHit) {
|
||||
// explode
|
||||
mHealth = -1.f;
|
||||
//mHealth = -1.f;
|
||||
}
|
||||
else {
|
||||
mHealth -= dmg.hitpoints;
|
||||
//mHealth -= dmg.hitpoints;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ VehicleObject::VehicleObject(GameWorld* engine, const glm::vec3& pos, const glm:
|
||||
vehicle(data), info(info), colourPrimary(prim),
|
||||
colourSecondary(sec), collision(nullptr), physBody(nullptr), physVehicle(nullptr)
|
||||
{
|
||||
mHealth = 1000.f;
|
||||
|
||||
collision = new CollisionInstance;
|
||||
if( collision->createPhysicsBody(this, data->modelName, nullptr, &info->handling) ) {
|
||||
physBody = collision->body;
|
||||
@ -458,7 +456,7 @@ VehicleObject::Part* VehicleObject::getSeatEntryDoor(size_t seat)
|
||||
|
||||
bool VehicleObject::takeDamage(const GameObject::DamageInfo& dmg)
|
||||
{
|
||||
mHealth -= dmg.hitpoints;
|
||||
RW_CHECK(dmg.hitpoints == 0, "Vehicle Damage not implemented yet");
|
||||
|
||||
const float frameDamageThreshold = 1500.f;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user