2019-06-29 20:15:55 +00:00
|
|
|
#include "common.h"
|
2020-04-17 13:31:11 +00:00
|
|
|
|
2019-07-05 20:19:52 +00:00
|
|
|
#include "General.h"
|
2019-07-08 06:46:42 +00:00
|
|
|
#include "Vehicle.h"
|
2019-06-29 20:15:55 +00:00
|
|
|
#include "DamageManager.h"
|
|
|
|
|
2019-07-05 20:19:52 +00:00
|
|
|
|
|
|
|
float G_aComponentDamage[] = { 2.5f, 1.25f, 3.2f, 1.4f, 2.5f, 2.8f, 0.5f };
|
|
|
|
|
2019-07-19 09:57:12 +00:00
|
|
|
CDamageManager::CDamageManager(void)
|
|
|
|
{
|
|
|
|
ResetDamageStatus();
|
|
|
|
m_fWheelDamageEffect = 0.75f;
|
2020-05-27 20:32:57 +00:00
|
|
|
field_18 = 1;
|
2019-07-19 09:57:12 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 20:19:52 +00:00
|
|
|
void
|
|
|
|
CDamageManager::ResetDamageStatus(void)
|
2019-06-29 20:15:55 +00:00
|
|
|
{
|
2019-07-05 20:19:52 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
2019-06-29 20:15:55 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 20:19:52 +00:00
|
|
|
void
|
|
|
|
CDamageManager::FuckCarCompletely(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-07-18 19:41:20 +00:00
|
|
|
m_wheelStatus[0] = WHEEL_STATUS_MISSING;
|
2019-07-05 20:19:52 +00:00
|
|
|
// wheels 1-3 not reset?
|
|
|
|
|
2020-05-27 20:32:57 +00:00
|
|
|
for(i = 0; i < ARRAY_SIZE(m_doorStatus); i++)
|
|
|
|
m_doorStatus[i] = DOOR_STATUS_MISSING;
|
2019-07-05 20:19:52 +00:00
|
|
|
|
|
|
|
for(i = 0; i < 3; i++){
|
|
|
|
#ifdef FIX_BUGS
|
|
|
|
ProgressPanelDamage(VEHBUMPER_FRONT);
|
|
|
|
ProgressPanelDamage(VEHBUMPER_REAR);
|
2019-06-29 20:15:55 +00:00
|
|
|
#else
|
2019-07-05 20:19:52 +00:00
|
|
|
// this can't be right
|
|
|
|
ProgressPanelDamage(COMPONENT_BUMPER_FRONT);
|
|
|
|
ProgressPanelDamage(COMPONENT_BUMPER_REAR);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
// Why set to no damage?
|
2020-09-26 10:30:22 +00:00
|
|
|
#ifndef FIX_BUGS
|
2019-07-05 20:19:52 +00:00
|
|
|
m_lightStatus = 0;
|
|
|
|
m_panelStatus = 0;
|
2020-09-26 10:30:22 +00:00
|
|
|
#endif
|
2019-07-05 20:19:52 +00:00
|
|
|
SetEngineStatus(250);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDamageManager::ApplyDamage(tComponent component, float damage, float unused)
|
|
|
|
{
|
|
|
|
tComponentGroup group;
|
|
|
|
uint8 subComp;
|
|
|
|
|
|
|
|
GetComponentGroup(component, &group, &subComp);
|
|
|
|
damage *= G_aComponentDamage[group];
|
|
|
|
if(damage > 150.0f){
|
|
|
|
switch(group){
|
|
|
|
case COMPGROUP_WHEEL:
|
|
|
|
ProgressWheelDamage(subComp);
|
|
|
|
break;
|
|
|
|
case COMPGROUP_DOOR:
|
|
|
|
case COMPGROUP_BOOT:
|
|
|
|
ProgressDoorDamage(subComp);
|
|
|
|
break;
|
|
|
|
case COMPGROUP_BONNET:
|
|
|
|
if(damage > 220.0f)
|
|
|
|
ProgressEngineDamage();
|
|
|
|
ProgressDoorDamage(subComp);
|
|
|
|
break;
|
|
|
|
case COMPGROUP_PANEL:
|
|
|
|
// so windscreen is a light?
|
|
|
|
SetLightStatus((eLights)subComp, 1);
|
|
|
|
// fall through
|
|
|
|
case COMPGROUP_BUMPER:
|
|
|
|
if(damage > 220.0f &&
|
|
|
|
(component == COMPONENT_PANEL_FRONT_LEFT ||
|
|
|
|
component == COMPONENT_PANEL_FRONT_RIGHT ||
|
|
|
|
component == COMPONENT_PANEL_WINDSCREEN))
|
|
|
|
ProgressEngineDamage();
|
|
|
|
ProgressPanelDamage(subComp);
|
|
|
|
break;
|
2020-05-11 23:24:57 +00:00
|
|
|
default: break;
|
2019-07-05 20:19:52 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDamageManager::GetComponentGroup(tComponent component, tComponentGroup *componentGroup, uint8 *subComp)
|
2019-06-29 20:15:55 +00:00
|
|
|
{
|
2019-07-05 20:19:52 +00:00
|
|
|
*subComp = -2; // ??
|
|
|
|
|
|
|
|
// This is done very strangely in the game, maybe an optimized switch?
|
|
|
|
if(component >= COMPONENT_PANEL_FRONT_LEFT){
|
|
|
|
if(component >= COMPONENT_BUMPER_FRONT)
|
|
|
|
*componentGroup = COMPGROUP_BUMPER;
|
|
|
|
else
|
|
|
|
*componentGroup = COMPGROUP_PANEL;
|
|
|
|
*subComp = component - COMPONENT_PANEL_FRONT_LEFT;
|
|
|
|
return true;
|
|
|
|
}else if(component >= COMPONENT_DOOR_BONNET){
|
|
|
|
if(component == COMPONENT_DOOR_BONNET)
|
|
|
|
*componentGroup = COMPGROUP_BONNET;
|
|
|
|
else if(component == COMPONENT_DOOR_BOOT)
|
|
|
|
*componentGroup = COMPGROUP_BOOT;
|
|
|
|
else
|
|
|
|
*componentGroup = COMPGROUP_DOOR;
|
|
|
|
*subComp = component - COMPONENT_DOOR_BONNET;
|
|
|
|
return true;
|
|
|
|
}else if(component >= COMPONENT_WHEEL_FRONT_LEFT){
|
|
|
|
*componentGroup = COMPGROUP_WHEEL;
|
|
|
|
*subComp = component - COMPONENT_WHEEL_FRONT_LEFT;
|
|
|
|
return true;
|
|
|
|
}else if(component >= COMPONENT_DEFAULT){
|
|
|
|
*componentGroup = COMPGROUP_DEFAULT;
|
2020-02-22 22:42:10 +00:00
|
|
|
*subComp = COMPONENT_DEFAULT;
|
2019-07-05 20:19:52 +00:00
|
|
|
return true;
|
|
|
|
}else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CDamageManager::SetDoorStatus(int32 door, uint32 status)
|
|
|
|
{
|
|
|
|
m_doorStatus[door] = status;
|
2019-06-29 20:15:55 +00:00
|
|
|
}
|
2019-07-05 20:19:52 +00:00
|
|
|
|
|
|
|
int32
|
|
|
|
CDamageManager::GetDoorStatus(int32 door)
|
|
|
|
{
|
|
|
|
return m_doorStatus[door];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDamageManager::ProgressDoorDamage(uint8 door)
|
|
|
|
{
|
|
|
|
int status = GetDoorStatus(door);
|
2020-02-22 22:42:10 +00:00
|
|
|
if(status == PANEL_STATUS_MISSING)
|
2019-07-05 20:19:52 +00:00
|
|
|
return false;
|
|
|
|
SetDoorStatus(door, status+1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CDamageManager::SetPanelStatus(int32 panel, uint32 status)
|
|
|
|
{
|
|
|
|
m_panelStatus = dpb(status, panel*4, 4, m_panelStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
CDamageManager::GetPanelStatus(int32 panel)
|
|
|
|
{
|
|
|
|
return ldb(panel*4, 4, m_panelStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDamageManager::ProgressPanelDamage(uint8 panel)
|
|
|
|
{
|
|
|
|
int status = GetPanelStatus(panel);
|
2020-02-22 22:42:10 +00:00
|
|
|
if(status == DOOR_STATUS_MISSING)
|
2019-07-05 20:19:52 +00:00
|
|
|
return false;
|
|
|
|
SetPanelStatus(panel, status+1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CDamageManager::SetLightStatus(eLights light, uint32 status)
|
|
|
|
{
|
|
|
|
m_lightStatus = dpb(status, light*2, 2, m_lightStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
CDamageManager::GetLightStatus(eLights light)
|
|
|
|
{
|
|
|
|
return ldb(light*2, 2, m_lightStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CDamageManager::SetWheelStatus(int32 wheel, uint32 status)
|
|
|
|
{
|
|
|
|
m_wheelStatus[wheel] = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
CDamageManager::GetWheelStatus(int32 wheel)
|
|
|
|
{
|
|
|
|
return m_wheelStatus[wheel];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDamageManager::ProgressWheelDamage(uint8 wheel)
|
|
|
|
{
|
|
|
|
int status = GetWheelStatus(wheel);
|
2020-02-22 22:42:10 +00:00
|
|
|
if(status == WHEEL_STATUS_MISSING)
|
2019-07-05 20:19:52 +00:00
|
|
|
return false;
|
|
|
|
SetWheelStatus(wheel, status+1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CDamageManager::SetEngineStatus(uint32 status)
|
|
|
|
{
|
|
|
|
if(status > 250)
|
|
|
|
m_engineStatus = 250;
|
|
|
|
else
|
|
|
|
m_engineStatus = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
CDamageManager::GetEngineStatus(void)
|
|
|
|
{
|
|
|
|
return m_engineStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDamageManager::ProgressEngineDamage(void)
|
|
|
|
{
|
|
|
|
int status = GetEngineStatus();
|
|
|
|
int newstatus = status + 32 + (CGeneral::GetRandomNumber() & 0x1F);
|
2019-07-18 19:41:20 +00:00
|
|
|
if(status < ENGINE_STATUS_ON_FIRE && newstatus > ENGINE_STATUS_ON_FIRE-1)
|
|
|
|
newstatus = ENGINE_STATUS_ON_FIRE-1;
|
2019-07-05 20:19:52 +00:00
|
|
|
SetEngineStatus(newstatus);
|
|
|
|
return true;
|
|
|
|
}
|