summaryrefslogtreecommitdiffstats
path: root/src/control
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/control
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 '')
-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
4 files changed, 126 insertions, 11 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");