summaryrefslogtreecommitdiffstats
path: root/src/objects/ObjectData.cpp
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-07-07 13:09:11 +0200
committeraap <aap@papnet.eu>2019-07-07 13:09:11 +0200
commit53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb (patch)
treefc65a6c40fa719f9d43be9e0e15be79c490135e0 /src/objects/ObjectData.cpp
parentfinished CPhysical (diff)
downloadre3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.gz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.bz2
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.lz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.xz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.zst
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.zip
Diffstat (limited to 'src/objects/ObjectData.cpp')
-rw-r--r--src/objects/ObjectData.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/objects/ObjectData.cpp b/src/objects/ObjectData.cpp
new file mode 100644
index 00000000..ef5bcc5e
--- /dev/null
+++ b/src/objects/ObjectData.cpp
@@ -0,0 +1,103 @@
+#include "common.h"
+#include "patcher.h"
+#include "main.h"
+#include "ModelInfo.h"
+#include "Object.h"
+#include "FileMgr.h"
+#include "ObjectData.h"
+
+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, sizeof(work_buff), "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