2020-05-27 09:21:20 +02:00
|
|
|
#include "framework.h"
|
|
|
|
#include "health.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "pickup.h"
|
|
|
|
#include "lara.h"
|
|
|
|
#include "camera.h"
|
|
|
|
#include "level.h"
|
|
|
|
#include "control.h"
|
2020-08-04 20:51:47 +10:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
using namespace T5M::Renderer;
|
2020-05-27 09:21:20 +02:00
|
|
|
short PickupX;
|
|
|
|
short PickupY;
|
|
|
|
short CurrentPickup;
|
|
|
|
DISPLAY_PICKUP Pickups[MAX_COLLECTED_PICKUPS];
|
|
|
|
short PickupVel;
|
|
|
|
int OldHitPoints = 1000;
|
2020-08-04 20:51:47 +10:00
|
|
|
int HealthBarTimer = 40;
|
|
|
|
float HealthBar = OldHitPoints;
|
|
|
|
float MutateAmount = 0;
|
2020-05-27 09:21:20 +02:00
|
|
|
int FlashState = 0;
|
|
|
|
int FlashCount = 0;
|
|
|
|
int PoisonFlag = 0;
|
|
|
|
int DashTimer = 0;
|
|
|
|
extern RendererHUDBar* g_HealthBar;
|
|
|
|
extern RendererHUDBar* g_DashBar;
|
|
|
|
extern RendererHUDBar* g_AirBar;
|
|
|
|
|
2020-08-04 20:51:47 +10:00
|
|
|
bool EnableSmoothHealthBar = true;
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
void DrawHealthBarOverlay(int value)
|
|
|
|
{
|
|
|
|
if (CurrentLevel)
|
|
|
|
{
|
|
|
|
int color2 = 0;
|
|
|
|
if (Lara.poisoned || Lara.gassed)
|
|
|
|
color2 = 0xA0A000;
|
|
|
|
else
|
|
|
|
color2 = 0xA00000;
|
2020-06-27 19:48:50 +02:00
|
|
|
g_Renderer.DrawBar(value, ::g_HealthBar);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawHealthBar(float value)
|
|
|
|
{
|
|
|
|
if (CurrentLevel)
|
|
|
|
{
|
2020-08-04 20:51:47 +10:00
|
|
|
g_Renderer.DrawBar(value, ::g_HealthBar);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-04 20:51:47 +10:00
|
|
|
void UpdateHealthBar(int flash)
|
2020-05-27 09:21:20 +02:00
|
|
|
{
|
|
|
|
int hitPoints = LaraItem->hitPoints;
|
|
|
|
|
|
|
|
if (hitPoints < 0)
|
|
|
|
hitPoints = 0;
|
|
|
|
else if (hitPoints > 1000)
|
|
|
|
hitPoints = 1000;
|
|
|
|
|
2020-08-04 20:51:47 +10:00
|
|
|
// OPT: smoothly transition health bar display.
|
|
|
|
if (EnableSmoothHealthBar)
|
2020-05-27 09:21:20 +02:00
|
|
|
{
|
2020-08-04 20:51:47 +10:00
|
|
|
if (OldHitPoints != hitPoints)
|
|
|
|
{
|
|
|
|
MutateAmount += OldHitPoints - hitPoints;
|
|
|
|
OldHitPoints = hitPoints;
|
|
|
|
HealthBarTimer = 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HealthBar - MutateAmount < 0)
|
|
|
|
MutateAmount = HealthBar;
|
|
|
|
else if (HealthBar - MutateAmount > 1000)
|
|
|
|
MutateAmount = HealthBar - 1000;
|
|
|
|
|
|
|
|
HealthBar -= MutateAmount / 3;
|
|
|
|
MutateAmount -= MutateAmount / 3;
|
|
|
|
|
|
|
|
if (MutateAmount > -0.5f && MutateAmount < 0.5f)
|
|
|
|
{
|
|
|
|
MutateAmount = 0;
|
|
|
|
HealthBar = hitPoints;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OG: discretely transition health bar display.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (OldHitPoints != hitPoints)
|
|
|
|
{
|
|
|
|
OldHitPoints = hitPoints;
|
|
|
|
HealthBar = hitPoints;
|
|
|
|
HealthBarTimer = 40;
|
|
|
|
}
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
|
2020-08-04 20:51:47 +10:00
|
|
|
if (HealthBarTimer < 0)
|
|
|
|
HealthBarTimer = 0;
|
2020-05-27 09:21:20 +02:00
|
|
|
|
2020-08-04 20:51:47 +10:00
|
|
|
// Flash when at 1/4 capacity AND HP bar is not transitioning.
|
|
|
|
if (HealthBar <= 1000 / 4 && MutateAmount == 0)
|
2020-05-27 09:21:20 +02:00
|
|
|
{
|
|
|
|
if (!BinocularRange)
|
|
|
|
{
|
|
|
|
if (flash)
|
2020-08-04 20:51:47 +10:00
|
|
|
DrawHealthBar(HealthBar / 1000.0f);
|
2020-05-27 09:21:20 +02:00
|
|
|
else
|
|
|
|
DrawHealthBar(0);
|
|
|
|
}
|
2020-08-04 20:51:47 +10:00
|
|
|
else
|
2020-05-27 09:21:20 +02:00
|
|
|
{
|
|
|
|
if (flash)
|
2020-08-04 20:51:47 +10:00
|
|
|
DrawHealthBarOverlay(HealthBar / 1000.0f);
|
2020-05-27 09:21:20 +02:00
|
|
|
else
|
|
|
|
DrawHealthBarOverlay(0);
|
|
|
|
}
|
|
|
|
}
|
2020-08-04 20:51:47 +10:00
|
|
|
else if ((HealthBarTimer > 0)
|
|
|
|
|| (HealthBar <= 0)
|
2020-05-27 09:21:20 +02:00
|
|
|
|| (Lara.gunStatus == LG_READY && Lara.gunType != WEAPON_TORCH)
|
|
|
|
|| (Lara.poisoned >= 256))
|
|
|
|
{
|
|
|
|
if (!BinocularRange && !SniperOverlay)
|
|
|
|
{
|
2020-08-04 20:51:47 +10:00
|
|
|
DrawHealthBar(HealthBar / 1000.0f);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-04 20:51:47 +10:00
|
|
|
DrawHealthBarOverlay(HealthBar / 1000.0f);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PoisonFlag)
|
|
|
|
PoisonFlag--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawAirBar(float value)
|
|
|
|
{
|
|
|
|
if (CurrentLevel)
|
|
|
|
{
|
2020-06-27 19:48:50 +02:00
|
|
|
g_Renderer.DrawBar(value, ::g_AirBar);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateAirBar(int flash)
|
|
|
|
{
|
|
|
|
if (Lara.air == 1800 || LaraItem->hitPoints <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((Lara.Vehicle == NO_ITEM)
|
2020-07-21 09:56:47 +02:00
|
|
|
|| (g_Level.Items[Lara.Vehicle].objectNumber != ID_UPV))
|
2020-05-27 09:21:20 +02:00
|
|
|
{
|
|
|
|
if ((Lara.waterStatus != LW_UNDERWATER)
|
|
|
|
&& (Lara.waterStatus != LW_SURFACE)
|
2020-07-21 09:56:47 +02:00
|
|
|
&& (!((g_Level.Rooms[LaraItem->roomNumber].flags & ENV_FLAG_SWAMP)
|
2020-05-27 09:21:20 +02:00
|
|
|
&& (Lara.waterSurfaceDist < -775))))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int air = Lara.air;
|
|
|
|
if (air < 0)
|
|
|
|
air = 0;
|
|
|
|
else if (air > 1800)
|
|
|
|
air = 1800;
|
|
|
|
if (air <= 450)
|
|
|
|
{
|
|
|
|
if (flash)
|
2020-08-04 20:51:47 +10:00
|
|
|
DrawAirBar(air / 1800.0f);
|
2020-05-27 09:21:20 +02:00
|
|
|
else
|
|
|
|
DrawAirBar(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DrawAirBar(air / 1800.0f);
|
|
|
|
|
|
|
|
if (Lara.gassed)
|
|
|
|
{
|
|
|
|
if (Lara.dpoisoned < 2048)
|
|
|
|
Lara.dpoisoned += 2;
|
|
|
|
Lara.gassed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawDashBar(int value)
|
|
|
|
{
|
|
|
|
if (CurrentLevel)
|
|
|
|
{
|
2020-06-27 19:48:50 +02:00
|
|
|
g_Renderer.DrawBar(value, ::g_DashBar);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DrawAllPickups()
|
|
|
|
{
|
|
|
|
if (Pickups[CurrentPickup].life > 0)
|
|
|
|
{
|
|
|
|
if (PickupX > 0)
|
|
|
|
{
|
|
|
|
PickupX += -PickupX >> 5;
|
2020-06-21 14:27:12 +02:00
|
|
|
return g_Renderer.DrawPickup(Pickups[CurrentPickup].objectNumber);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pickups[CurrentPickup].life--;
|
2020-06-21 14:27:12 +02:00
|
|
|
return g_Renderer.DrawPickup(Pickups[CurrentPickup].objectNumber);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Pickups[CurrentPickup].life == 0)
|
|
|
|
{
|
|
|
|
if (PickupX < 128)
|
|
|
|
{
|
|
|
|
if (PickupVel < 16)
|
|
|
|
PickupVel++;
|
|
|
|
PickupX += PickupVel >> 2;
|
2020-06-21 14:27:12 +02:00
|
|
|
return g_Renderer.DrawPickup(Pickups[CurrentPickup].objectNumber);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pickups[CurrentPickup].life = -1;
|
|
|
|
PickupVel = 0;
|
2020-06-21 14:27:12 +02:00
|
|
|
return g_Renderer.DrawPickup(Pickups[CurrentPickup].objectNumber);
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int pickupIndex = CurrentPickup;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_COLLECTED_PICKUPS; ++i)
|
|
|
|
{
|
|
|
|
if (Pickups[pickupIndex].life > 0)
|
|
|
|
break;
|
|
|
|
pickupIndex = pickupIndex + 1 & MAX_COLLECTED_PICKUPS - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentPickup = pickupIndex;
|
|
|
|
if (i != MAX_COLLECTED_PICKUPS)
|
2020-06-21 14:27:12 +02:00
|
|
|
return g_Renderer.DrawPickup(Pickups[CurrentPickup].objectNumber);
|
2020-05-27 09:21:20 +02:00
|
|
|
|
|
|
|
CurrentPickup = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddDisplayPickup(short objectNumber)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MAX_COLLECTED_PICKUPS; i++)
|
|
|
|
{
|
|
|
|
DISPLAY_PICKUP* pickup = &Pickups[i];
|
|
|
|
if (pickup->life < 0)
|
|
|
|
{
|
|
|
|
pickup->life = 45;
|
|
|
|
pickup->objectNumber = objectNumber;
|
|
|
|
PickedUpObject(objectNumber);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No free slot found, so just pickup the object ithout displaying it
|
|
|
|
PickedUpObject(objectNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitialisePickupDisplay()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MAX_COLLECTED_PICKUPS; i++)
|
|
|
|
{
|
|
|
|
DISPLAY_PICKUP* pickup = &Pickups[i];
|
|
|
|
pickup->life = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PickupX = 128;
|
|
|
|
PickupY = 128;
|
|
|
|
PickupVel = 0;
|
|
|
|
CurrentPickup = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FlashIt()
|
|
|
|
{
|
|
|
|
if (FlashCount)
|
|
|
|
FlashCount--;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlashState ^= 1;
|
|
|
|
FlashCount = 5;
|
|
|
|
}
|
|
|
|
return FlashState;
|
|
|
|
}
|