summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-06-19 18:35:51 +0200
committeraap <aap@papnet.eu>2019-06-19 18:35:51 +0200
commit2ec11b000db3af4cb5cd9a5d70dd050edfbdc99f (patch)
tree4bb63db3c36f43ae63e1560d19d36ccb46ed37ac /src
parentimplemented CPedStats (diff)
downloadre3-2ec11b000db3af4cb5cd9a5d70dd050edfbdc99f.tar
re3-2ec11b000db3af4cb5cd9a5d70dd050edfbdc99f.tar.gz
re3-2ec11b000db3af4cb5cd9a5d70dd050edfbdc99f.tar.bz2
re3-2ec11b000db3af4cb5cd9a5d70dd050edfbdc99f.tar.lz
re3-2ec11b000db3af4cb5cd9a5d70dd050edfbdc99f.tar.xz
re3-2ec11b000db3af4cb5cd9a5d70dd050edfbdc99f.tar.zst
re3-2ec11b000db3af4cb5cd9a5d70dd050edfbdc99f.zip
Diffstat (limited to 'src')
-rw-r--r--src/control/ObjectData.cpp100
-rw-r--r--src/control/ObjectData.h20
-rw-r--r--src/control/PedStats.cpp4
-rw-r--r--src/control/PedStats.h13
-rw-r--r--src/entities/Object.cpp4
-rw-r--r--src/entities/Object.h21
-rw-r--r--src/entities/Ped.h2
-rw-r--r--src/entities/Physical.cpp8
-rw-r--r--src/entities/Physical.h2
-rw-r--r--src/modelinfo/BaseModelInfo.h2
10 files changed, 153 insertions, 23 deletions
diff --git a/src/control/ObjectData.cpp b/src/control/ObjectData.cpp
index 28c34658..a0838007 100644
--- a/src/control/ObjectData.cpp
+++ b/src/control/ObjectData.cpp
@@ -1,5 +1,103 @@
#include "common.h"
#include "patcher.h"
+#include "main.h"
+#include "ModelInfo.h"
+#include "Object.h"
+#include "FileMgr.h"
#include "ObjectData.h"
-WRAPPER void CObjectData::Initialise(const char *filename) { EAXJMP(0x4BC0E0); }
+CObjectInfo CObjectData::ms_aObjectInfo[NUMOBJECTINFO];
+
+// Another ugly file reader
+void
+CObjectData::Initialise(const char *filename)
+{
+ char *p, *lp;
+ char line[1024], name[256];
+ int id;
+ float percentSubmerged;
+ int damageEffect, responseCase, camAvoid;
+ CBaseModelInfo *mi;
+
+ CFileMgr::SetDir("");
+ CFileMgr::LoadFile(filename, work_buff, 55000, "r");
+
+ id = 0;
+ p = (char*)work_buff;
+ while(*p != '*'){
+ // skip over white space and comments
+ while(*p == ' ' || *p == '\n' || *p == '\r' || *p == ';')
+ if(*p == ';')
+ while(*p != '\n' && *p != '*')
+ p++;
+ else
+ p++;
+
+ if(*p == '*')
+ break;
+
+ // read one line
+ lp = line;
+ while(*p != '\n' && *p != '*'){
+ *lp++ = *p == ',' ? ' ' : *p;
+ p++;
+ }
+ if(*p == '\n')
+ p++;
+ *lp = '\0'; // FIX: game wrote '\n' here
+
+ assert(id < NUMOBJECTINFO);
+ sscanf(line, "%s %f %f %f %f %f %f %f %d %d %d", name,
+ &ms_aObjectInfo[id].m_fMass,
+ &ms_aObjectInfo[id].m_fTurnMass,
+ &ms_aObjectInfo[id].m_fAirResistance,
+ &ms_aObjectInfo[id].m_fElasticity,
+ &percentSubmerged,
+ &ms_aObjectInfo[id].m_fUprootLimit,
+ &ms_aObjectInfo[id].m_fCollisionDamageMultiplier,
+ &damageEffect, &responseCase, &camAvoid);
+
+ ms_aObjectInfo[id].m_fBuoyancy = 100.0f/percentSubmerged * 0.008*ms_aObjectInfo[id].m_fMass;
+ ms_aObjectInfo[id].m_nCollisionDamageEffect = damageEffect;
+ ms_aObjectInfo[id].m_nSpecialCollisionResponseCases = responseCase;
+ ms_aObjectInfo[id].m_bCameraToAvoidThisObject = camAvoid;
+
+ mi = CModelInfo::GetModelInfo(name, nil);
+ if(mi)
+ mi->SetObjectID(id++);
+ else
+ debug("CObjectData: Cannot find object %s\n", name);
+ }
+}
+
+void
+CObjectData::SetObjectData(int32 modelId, CObject &object)
+{
+ CObjectInfo *objinfo;
+
+ if(CModelInfo::GetModelInfo(modelId)->GetObjectID() == -1)
+ return;
+
+ objinfo = &ms_aObjectInfo[CModelInfo::GetModelInfo(modelId)->GetObjectID()];
+
+ object.m_fMass = objinfo->m_fMass;
+ object.m_fTurnMass = objinfo->m_fTurnMass;
+ object.m_fAirResistance = objinfo->m_fAirResistance;
+ object.m_fElasticity = objinfo->m_fElasticity;
+ object.m_fBuoyancy = objinfo->m_fBuoyancy;
+ object.m_fUprootLimit = objinfo->m_fUprootLimit;
+ object.m_fCollisionDamageMultiplier = objinfo->m_fCollisionDamageMultiplier;
+ object.m_nCollisionDamageEffect = objinfo->m_nCollisionDamageEffect;
+ object.m_nSpecialCollisionResponseCases = objinfo->m_nSpecialCollisionResponseCases;
+ object.m_bCameraToAvoidThisObject = objinfo->m_bCameraToAvoidThisObject;
+ if(object.m_fMass >= 99998.0){
+ object.bInfiniteMass = true;
+ object.bAffectedByGravity = false;
+ object.m_flagB2 = true;
+ }
+}
+
+STARTPATCHES
+ InjectHook(0x4BC0E0, CObjectData::Initialise, PATCH_JUMP);
+ InjectHook(0x4BC270, CObjectData::SetObjectData, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/control/ObjectData.h b/src/control/ObjectData.h
index 7df1c845..e3a5c1bd 100644
--- a/src/control/ObjectData.h
+++ b/src/control/ObjectData.h
@@ -1,7 +1,27 @@
#pragma once
+class CObject;
+
+class CObjectInfo
+{
+public:
+ float m_fMass;
+ float m_fTurnMass;
+ float m_fAirResistance;
+ float m_fElasticity;
+ float m_fBuoyancy;
+ float m_fUprootLimit;
+ float m_fCollisionDamageMultiplier;
+ uint8 m_nCollisionDamageEffect;
+ uint8 m_nSpecialCollisionResponseCases;
+ bool m_bCameraToAvoidThisObject;
+};
+static_assert(sizeof(CObjectInfo) == 0x20, "CObjectInfo: error");
+
class CObjectData
{
+ static CObjectInfo ms_aObjectInfo[NUMOBJECTINFO];
public:
static void Initialise(const char *filename);
+ static void SetObjectData(int32 modelId, CObject &object);
};
diff --git a/src/control/PedStats.cpp b/src/control/PedStats.cpp
index e669ab43..f6508580 100644
--- a/src/control/PedStats.cpp
+++ b/src/control/PedStats.cpp
@@ -3,7 +3,7 @@
#include "FileMgr.h"
#include "PedStats.h"
-CPedStat *(&CPedStats::ms_apPedStats)[NUM_PEDSTATS] = *(CPedStat *(*)[NUM_PEDSTATS]) *(uintptr*)0x9404D4;
+CPedStats *(&CPedStats::ms_apPedStats)[NUM_PEDSTATS] = *(CPedStats *(*)[NUM_PEDSTATS]) *(uintptr*)0x9404D4;
void
CPedStats::Initialise(void)
@@ -12,7 +12,7 @@ CPedStats::Initialise(void)
debug("Initialising CPedStats...\n");
for(i = 0; i < NUM_PEDSTATS; i++){
- ms_apPedStats[i] = new CPedStat;
+ ms_apPedStats[i] = new CPedStats;
ms_apPedStats[i]->m_type = PEDSTAT_PLAYER;
ms_apPedStats[i]->m_name[8] = 'R'; // WHAT?
ms_apPedStats[i]->m_fleeDistance = 20.0f;
diff --git a/src/control/PedStats.h b/src/control/PedStats.h
index 6b53ea37..78414341 100644
--- a/src/control/PedStats.h
+++ b/src/control/PedStats.h
@@ -54,8 +54,11 @@ enum
STAT_GUN_PANIC = 0x80
};
-struct CPedStat
+class CPedStats
{
+ static CPedStats *(&ms_apPedStats)[NUM_PEDSTATS];
+
+public:
ePedStats m_type;
char m_name[24];
float m_fleeDistance;
@@ -67,16 +70,10 @@ struct CPedStat
float m_attackStrength;
float m_defendWeakness;
int16 m_flags;
-};
-static_assert(sizeof(CPedStat) == 0x34, "CPedStat: error");
-class CPedStats
-{
- static CPedStat *(&ms_apPedStats)[NUM_PEDSTATS];
-
-public:
static void Initialise(void);
static void Shutdown(void);
static void LoadPedStats(void);
static int32 GetPedStatType(char *name);
};
+static_assert(sizeof(CPedStats) == 0x34, "CPedStats: error");
diff --git a/src/entities/Object.cpp b/src/entities/Object.cpp
index 2b068d49..35a64604 100644
--- a/src/entities/Object.cpp
+++ b/src/entities/Object.cpp
@@ -16,8 +16,8 @@ CObject::CObject(void)
m_type = ENTITY_TYPE_OBJECT;
m_fUprootLimit = 0.0f;
m_nCollisionDamageEffect = 0;
- m_bSpecialCollisionResponseCases = 0;
- m_bCameraToAvoidThisObject = 0;
+ m_nSpecialCollisionResponseCases = COLLRESPONSE_NONE;
+ m_bCameraToAvoidThisObject = false;
ObjectCreatedBy = 0;
m_nEndOfLifeTime = 0;
// m_nRefModelIndex = -1; // duplicate
diff --git a/src/entities/Object.h b/src/entities/Object.h
index c9800e20..2079ff0e 100644
--- a/src/entities/Object.h
+++ b/src/entities/Object.h
@@ -9,6 +9,21 @@ enum {
CUTSCENE_OBJECT = 4,
};
+enum {
+ COLLRESPONSE_NONE,
+ COLLRESPONSE_CHANGE_MODEL,
+ COLLRESPONSE_SPLIT_MODEL,
+ COLLRESPONSE_SMASH_COMPLETELY,
+ COLLRESPONSE_CHANGE_THEN_SMASH,
+ COLLRESPONSE_UNKNOWN5,
+
+ COLLRESPONSE_SMASH_CARDBOARD_COMPLETELY = 50,
+ COLLRESPONSE_SMASH_WOODENBOX_COMPLETELY = 60,
+ COLLRESPONSE_SMASH_TRAFFICCONE_COMPLETELY = 70,
+ COLLRESPONSE_SMASH_BARPOST_COMPLETELY = 80,
+
+};
+
class CVehicle;
class CObject : public CPhysical
@@ -28,9 +43,9 @@ public:
int8 field_172;
int8 field_173;
float m_fCollisionDamageMultiplier;
- int8 m_nCollisionDamageEffect;
- int8 m_bSpecialCollisionResponseCases;
- int8 m_bCameraToAvoidThisObject;
+ uint8 m_nCollisionDamageEffect;
+ uint8 m_nSpecialCollisionResponseCases;
+ bool m_bCameraToAvoidThisObject;
int8 field_17B;
int8 field_17C;
int8 field_17D;
diff --git a/src/entities/Ped.h b/src/entities/Ped.h
index 3804236a..fbfa3f57 100644
--- a/src/entities/Ped.h
+++ b/src/entities/Ped.h
@@ -211,7 +211,7 @@ public:
bool bInVehicle;
uint8 stuff4[23];
int32 m_nPedType;
- CPedStat *m_pedStats;
+ CPedStats *m_pedStats;
uint8 stuff5[24];
CEntity *m_pCollidingEntity;
uint8 stuff6[12];
diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp
index 33e2deff..f2693a68 100644
--- a/src/entities/Physical.cpp
+++ b/src/entities/Physical.cpp
@@ -1801,8 +1801,8 @@ CPhysical::ProcessCollision(void)
n = distSq > 0.32f ? NUMSTEPS(0.3f) : NUMSTEPS(0.4f);
step = savedTimeStep / n;
}else if(IsObject()){
- int responsecase = ((CObject*)this)->m_bSpecialCollisionResponseCases;
- if(responsecase == 1){
+ int responsecase = ((CObject*)this)->m_nSpecialCollisionResponseCases;
+ if(responsecase == COLLRESPONSE_CHANGE_MODEL){
CVector speedUp = { 0.0f, 0.0f, 0.0f };
CVector speedDown = { 0.0f, 0.0f, 0.0f };
speedUp.z = GetBoundRadius();
@@ -1816,12 +1816,12 @@ CPhysical::ProcessCollision(void)
n = NUMSTEPS(0.3f);
step = savedTimeStep / n;
}
- }else if(responsecase == 5){
+ }else if(responsecase == COLLRESPONSE_UNKNOWN5){
if(distSq >= 0.009f){
n = NUMSTEPS(0.09f);
step = savedTimeStep / n;
}
- }else if(responsecase == 2 || responsecase == 4){
+ }else if(responsecase == COLLRESPONSE_SPLIT_MODEL || responsecase == COLLRESPONSE_CHANGE_THEN_SMASH){
if(distSq >= sq(0.15f)){
n = NUMSTEPS(0.15f);
step = savedTimeStep / n;
diff --git a/src/entities/Physical.h b/src/entities/Physical.h
index 6b5bd1f6..11d2a1f9 100644
--- a/src/entities/Physical.h
+++ b/src/entities/Physical.h
@@ -30,7 +30,7 @@ public:
float fForceMultiplier;
float m_fAirResistance;
float m_fElasticity;
- float fPercentSubmerged;
+ float m_fBuoyancy;
CVector m_vecCentreOfMass;
CEntryInfoList m_entryInfoList;
CPtrNode *m_movingListNode;
diff --git a/src/modelinfo/BaseModelInfo.h b/src/modelinfo/BaseModelInfo.h
index b6c6c62e..da72990f 100644
--- a/src/modelinfo/BaseModelInfo.h
+++ b/src/modelinfo/BaseModelInfo.h
@@ -52,7 +52,7 @@ public:
void DeleteCollisionModel(void);
void ClearTexDictionary(void) { m_txdSlot = -1; }
short GetObjectID(void) { return m_objectId; }
- void SetObjectID(short id) { m_objectId = id; }
+ void SetObjectID(int16 id) { m_objectId = id; }
short GetTxdSlot(void) { return m_txdSlot; }
void AddRef(void);
void RemoveRef(void);