diff mm7_2.cpp @ 101:8be5293b6b33

odm loading
author Nomad
date Tue, 06 Nov 2012 06:15:25 +0200
parents d7e68aebe0b3
children 3b5267621a5b
line wrap: on
line diff
--- a/mm7_2.cpp	Sun Nov 04 13:58:15 2012 +0200
+++ b/mm7_2.cpp	Tue Nov 06 06:15:25 2012 +0200
@@ -1,5 +1,6 @@
 #include <io.h>
 #include <direct.h>
+#include <assert.h>
 
 #include "MapInfo.h"
 #include "Game.h"
@@ -7501,11 +7502,11 @@
 
 
 //----- (0044F57C) --------------------------------------------------------
-void *__fastcall SpawnEncounter(MapInfo *pMapInfo, SpawnPointMM7 *a2, int a3, int a4, int a5)
-{
-  MapInfo *v5; // esi@1
-  SpawnPointMM7 *v6; // ebx@1
-  void *result; // eax@2
+void SpawnEncounter(MapInfo *pMapInfo, SpawnPointMM7 *spawn, int a3, int a4, int a5)
+{
+  //MapInfo *v5; // esi@1
+  //SpawnPointMM7 *v6; // ebx@1
+  int v7; // eax@2
   char v8; // zf@5
   int v9; // edi@9
   int v10; // eax@9
@@ -7540,123 +7541,139 @@
   int v39; // edi@52
   std::string v40; // [sp-18h] [bp-100h]@60
   void *v41; // [sp-14h] [bp-FCh]@50
-  void *v42; // [sp-10h] [bp-F8h]@50
-  size_t v43; // [sp-Ch] [bp-F4h]@50
+  //void *v42; // [sp-10h] [bp-F8h]@50
+  //size_t v43; // [sp-Ch] [bp-F4h]@50
   const char *v44; // [sp-8h] [bp-F0h]@13
   char *v45; // [sp-4h] [bp-ECh]@9
-  char Str; // [sp+Ch] [bp-DCh]@60
-  char Str2; // [sp+2Ch] [bp-BCh]@29
+  char Str[32]; // [sp+Ch] [bp-DCh]@60
+  char Str2[120]; // [sp+2Ch] [bp-BCh]@29
   unsigned int uFaceID; // [sp+A4h] [bp-44h]@52
-  void *Src; // [sp+A8h] [bp-40h]@50
+  MonsterInfo *Src; // [sp+A8h] [bp-40h]@50
   int v50; // [sp+ACh] [bp-3Ch]@47
-  char Source; // [sp+B0h] [bp-38h]@20
+  char Source[32]; // [sp+B0h] [bp-38h]@20
   int v52; // [sp+D0h] [bp-18h]@34
-  void *v53; // [sp+D4h] [bp-14h]@34
+  int v53; // [sp+D4h] [bp-14h]@34
   int v54; // [sp+D8h] [bp-10h]@32
   int v55; // [sp+DCh] [bp-Ch]@32
   int v56; // [sp+E0h] [bp-8h]@8
   int v57; // [sp+E4h] [bp-4h]@1
 
+  //auto a2 = spawn;
+
   v57 = 0;
-  v5 = pMapInfo;
-  v6 = a2;
+  //v5 = pMapInfo;
+  //v6 = spawn;
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
-    result = (void *)pOutdoor->ddm.field_C_alert;
-  else
-    result = (void *)(uCurrentlyLoadedLevelType == LEVEL_Outdoor ? pIndoor->dlv.field_C_alert : 0);
-  if ( result )
-  {
-    v8 = (a2->uAttributes & 1) == 0;
-  }
-  else
-  {
-    result = (void *)(a2->uAttributes & 1);
-    v8 = (char)result == 1;
-  }
-  if ( !v8 )
-  {
-    result = (void *)(a2->uIndex - 1);
-    v56 = 1;
-    switch ( (int)result )
-    {
-      case 0u:
+    v7 = pOutdoor->ddm.field_C_alert;
+  else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+    v7 = pIndoor->dlv.field_C_alert;
+  else
+    v7 = 0;
+
+  if (v7)
+    v8 = (spawn->uAttributes & 1) == 0;
+  else
+    v8 = (spawn->uAttributes & 1) == 1;
+
+  if (v8)
+    return;
+
+    //result = (void *)(spawn->uIndex - 1);
+  v56 = 1;
+  switch (spawn->uIndex - 1)
+  {
+    case 0u:
         v9 = pMapInfo->uEncounterMonster1AtLeast;
         v10 = rand();
-        v11 = v5->uEncounterMonster1AtMost;
-        v45 = v5->pEncounterMonster1Texture;
-        v12 = v10 % (v11 - v9 + 1);
-        v13 = v5->field_34;
-        goto LABEL_20;
-      case 3u:
+        v11 = pMapInfo->uEncounterMonster1AtMost;
         v45 = pMapInfo->pEncounterMonster1Texture;
-        goto LABEL_13;
-      case 4u:
-        v45 = pMapInfo->pEncounterMonster2Texture;
-        goto LABEL_13;
-      case 5u:
-        v45 = pMapInfo->pEncounterMonster3Texture;
-LABEL_13:
+        v12 = v10 % (v11 - v9 + 1);
+        v13 = pMapInfo->field_34;
+        goto LABEL_20;
+
+    case 3u:
+        v45 = pMapInfo->pEncounterMonster1Texture;
         v44 = "%s A";
         goto LABEL_25;
-      case 1u:
+
+    case 4u:
+        v45 = pMapInfo->pEncounterMonster2Texture;
+        v44 = "%s A";
+        goto LABEL_25;
+
+    case 5u:
+        v45 = pMapInfo->pEncounterMonster3Texture;
+        v44 = "%s A";
+        goto LABEL_25;
+
+    case 1u:
         v9 = pMapInfo->uEncounterMonster2AtLeast;
         v14 = rand();
-        v15 = v5->uEncounterMonster2AtMost;
-        v45 = v5->pEncounterMonster2Texture;
+        v15 = pMapInfo->uEncounterMonster2AtMost;
+        v45 = pMapInfo->pEncounterMonster2Texture;
         v12 = v14 % (v15 - v9 + 1);
-        v13 = v5->field_37;
+        v13 = pMapInfo->field_37;
         goto LABEL_20;
-      case 6u:
+
+    case 6u:
         v45 = pMapInfo->pEncounterMonster1Texture;
-        goto LABEL_18;
-      case 7u:
-        v45 = pMapInfo->pEncounterMonster2Texture;
-        goto LABEL_18;
-      case 8u:
-        v45 = pMapInfo->pEncounterMonster3Texture;
-LABEL_18:
         v44 = "%s B";
         goto LABEL_25;
-      case 2u:
+
+    case 7u:
+        v45 = pMapInfo->pEncounterMonster2Texture;
+        v44 = "%s B";
+        goto LABEL_25;
+
+    case 8u:
+        v45 = pMapInfo->pEncounterMonster3Texture;
+        v44 = "%s B";
+        goto LABEL_25;
+
+    case 2u:
         v9 = pMapInfo->uEncounterMonster3AtLeast;
         v16 = rand();
-        v17 = v5->uEncounterMonster3AtMost;
-        v45 = v5->pEncounterMonster3Texture;
+        v17 = pMapInfo->uEncounterMonster3AtMost;
+        v45 = pMapInfo->pEncounterMonster3Texture;
         v12 = v16 % (v17 - v9 + 1);
-        v13 = v5->field_3A;
+        v13 = pMapInfo->field_3A;
 LABEL_20:
         v57 = v13;
         v56 = v9 + v12;
-        result = strcpy(&Source, v45);
+        strcpy(Source, v45);
         goto LABEL_26;
-      case 9u:
+
+    case 9u:
         v45 = pMapInfo->pEncounterMonster1Texture;
-        goto LABEL_24;
-      case 0xAu:
+        v44 = "%s C";
+        goto LABEL_25;
+
+    case 0xAu:
         v45 = pMapInfo->pEncounterMonster2Texture;
-        goto LABEL_24;
-      case 0xBu:
+        v44 = "%s C";
+        goto LABEL_25;
+
+    case 0xBu:
         v45 = pMapInfo->pEncounterMonster3Texture;
-LABEL_24:
         v44 = "%s C";
 LABEL_25:
-        result = (void *)sprintfex(&Source, v44, v45);
+        sprintf(Source, v44, v45);
 LABEL_26:
-        if ( Source == 48 )
-          return result;
+        if (Source[0] == '0')
+          return;
+
         v57 += a3;
         if ( v57 > 4 )
           v57 = 4;
-        strcpy(&Str2, &Source);
+        strcpy(Str2, Source);
         if ( a4 )
           v56 = a4;
         v18 = v56;
-        result = (void *)(v56 + uNumActors);
         if ( (signed int)(v56 + uNumActors) >= 500 )
-          return result;
-        v19 = v6->vPosition.x;
-        v20 = v6->vPosition.y;
-        v21 = v6->vPosition.z;
+          return;
+        v19 = spawn->vPosition.x;
+        v20 = spawn->vPosition.y;
+        v21 = spawn->vPosition.z;
         v54 = 0;
         v55 = v19;
         a4 = v20;
@@ -7664,16 +7681,16 @@
         if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
           v54 = pIndoor->GetSector(v19, v20, v21);
         v53 = 0;
-        result = (void *)((((uCurrentlyLoadedLevelType != LEVEL_Outdoor) - 1) & 0x40) + 64);
         v52 = (((uCurrentlyLoadedLevelType != LEVEL_Outdoor) - 1) & 0x40) + 64;
         if ( v18 <= 0 )
-          return result;
+          return;
         break;
       default:
-        return result;
-    }
-    do
-    {
+        return;
+  }
+
+  for (uint i = v53; i < v56; ++i)
+  {
       v22 = &pActors[uNumActors];
       pActors[uNumActors].Reset();
       if ( v57 )
@@ -7692,47 +7709,48 @@
         }
         if ( v24 == 1 )
         {
-          v45 = &Source;
+          v45 = Source;
           v44 = "%s A";
         }
         else
         {
           if ( v24 == 2 )
           {
-            v45 = &Source;
+            v45 = Source;
             v44 = "%s B";
           }
           else
           {
             if ( v24 != 3 )
               goto LABEL_58;
-            v45 = &Source;
+            v45 = Source;
             v44 = "%s C";
           }
         }
-        sprintfex(&Str2, v44, v45);
-      }
-      v26 = pMonsterList->GetMonsterByName(&Str2);
+        sprintf(Str2, v44, v45);
+      }
+      v26 = pMonsterList->GetMonsterByName(Str2);
       v50 = (signed __int16)v26;
-      v45 = &Str2;
+      v45 = Str2;
       if ( (signed __int16)v26 == -1 )
       {
-        sprintfex(&Str, "Can't create random monster: '%s'! See MapStats.txt and Monsters.txt!", v45);
-        MessageBoxA(nullptr, &Str, nullptr, 0);
+        sprintfex(Str, "Can't create random monster: '%s'! See MapStats.txt and Monsters.txt!", v45);
+        MessageBoxA(nullptr, Str, nullptr, 0);
         ExitProcess(0);
       }
       v27 = &pMonsterList->pMonsters[(signed __int16)v26];
       v28 = pMonsterStats->_4563FF(v45);
       if ( !v28 )
         v28 = 1;
-      Src = (char *)&pMonsterStats + 88 * v28;
-      strcpy(v22->pActorName, *(const char **)Src);
-      v43 = 88;
-      v42 = Src;
-      v29 = *((short *)Src + 32);
+      Src = &pMonsterStats->pInfos[v28];
+      strcpy(v22->pActorName, Src->pName);
+      //v43 = 88;
+      //v42 = Src;
+      v29 = Src->uHP;
       v41 = &v22->pMonsterInfo;
       v22->sCurrentHP = v29;
-      memcpy(v41, v42, v43);
+      assert(sizeof(MonsterInfo) == 88);
+      memcpy(v41, Src, sizeof(MonsterInfo));
       v22->word_000086_some_monster_id = v50 + 1;
       v22->uActorRadius = v27->uMonsterRadius;
       v22->uActorHeight = v27->uMonsterHeight;
@@ -7748,7 +7766,7 @@
       v22->vInitialPosition.z = a3;
       v22->vPosition.z = a3;
       v22->uSectorID = v54;
-      v22->uGroup = v6->uGroup;
+      v22->uGroup = spawn->uGroup;
       v22->PrepareSprites((char)v45);
       v22->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
       v32 = rand();
@@ -7756,13 +7774,13 @@
       v34 = stru_5C6E00->SinCos(v32 % 2048);
       a4 = v34;
       a3 = (unsigned __int64)(v34 * (signed __int64)v52) >> 16;
-      v55 = a3 + v6->vPosition.x;
+      v55 = a3 + spawn->vPosition.x;
       v35 = stru_5C6E00->SinCos(v33 - stru_5C6E00->uIntegerHalfPi);
       a4 = v35;
       a3 = (unsigned __int64)(v35 * (signed __int64)v52) >> 16;
-      a4 = a3 + v6->vPosition.y;
-      v36 = v6->vPosition.z;
-      a3 = v6->vPosition.z;
+      a4 = a3 + spawn->vPosition.y;
+      v36 = spawn->vPosition.z;
+      a3 = spawn->vPosition.z;
       if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
         goto LABEL_55;
       v37 = pIndoor->GetSector(v55, a4, v36);
@@ -7784,12 +7802,11 @@
         }
       }
 LABEL_58:
-      v53 = (char *)v53 + 1;
-      result = v53;
-    }
-    while ( (signed int)v53 < v56 );
-  }
-  return result;
+      ;
+      //v53 = (char *)v53 + 1;
+      //result = v53;
+    }
+    //while ( (signed int)v53 < v56 );
 }
 
 
@@ -7955,6 +7972,8 @@
   int v33; // [sp+80h] [bp-8h]@1
   int v34; // [sp+84h] [bp-4h]@1
 
+  __debugbreak();
+
   auto a1 = this;
 
   v2 = a1;
@@ -8619,39 +8638,27 @@
 }
 
 //----- (00450AAA) --------------------------------------------------------
-void *__cdecl RespawnGlobalDecorations()
-{
-  signed int v0; // edi@1
-  void *result; // eax@1
-  signed int v2; // ebx@1
-  LevelDecoration *v3; // esi@2
-
-  v0 = 0;
-  result = memset(stru_5E4C90.field_4B, 0, 0x7Du);
-  v2 = 0;
-  if ( (signed int)uNumLevelDecorations > 0 )
-  {
-    v3 = pLevelDecorations;
-    do
-    {
-      if ( !v3->field_16_event_id )
-      {
-        result = (void *)v3->IsInteractive();
-        if ( result )
-        {
-          if ( v0 < 124 )
-          {
-            v3->field_1C = v0 + 75;
-            stru_5E4C90.field_4B[v0++] = v3->GetGlobalEvent();
-          }
-        }
-      }
-      ++v2;
-      ++v3;
-    }
-    while ( v2 < (signed int)uNumLevelDecorations );
-  }
-  return result;
+void RespawnGlobalDecorations()
+{
+  memset(stru_5E4C90._decor_events, 0, 125);
+
+  uint decorEventIdx = 0;
+  for (uint i = 0; i < uNumLevelDecorations; ++i)
+  {
+    auto decor = pLevelDecorations + i;
+
+    if (!decor->field_16_event_id)
+    {
+      if (decor->IsInteractive())
+      {
+        if (decorEventIdx < 124)
+        {
+          decor->_idx_in_stru123 = decorEventIdx + 75;
+          stru_5E4C90._decor_events[decorEventIdx++] = decor->GetGlobalEvent();
+        }
+      }
+    }
+  }
 }
 
 //----- (00450B0A) --------------------------------------------------------
@@ -15924,9 +15931,9 @@
       {
         if ( !pLevelDecorations[a1 >> 3].IsInteractive() )
           return 1;
-        v10 = v8->field_1C;
+        v10 = v8->_idx_in_stru123;
         v24 = 1;
-        v11 = stru_5E4C90.field_0[v10] + 380;
+        v11 = stru_5E4C90._decor_events[v10 - 75] + 380;
         _5C3420_pDecoration = v8;
         EventProcessor(v11, 0, 1);
         _5C3420_pDecoration = 0;
@@ -16396,7 +16403,7 @@
     goto LABEL_36;
   }
   if ( v25->IsInteractive() )
-    v24 = pNPCTopics[stru_5E4C90.field_0[v26->field_1C] + 379].pTopic;
+    v24 = pNPCTopics[stru_5E4C90._decor_events[v26->_idx_in_stru123 - 75] + 379].pTopic;
   else
     v24 = pDecorationList->pDecorations[v26->uDecorationDescID].field_20;
 LABEL_51: