changeset 767:45615cacad31

Fog fixed
author Nomad
date Sat, 23 Mar 2013 21:11:15 +0200
parents a464d28566a6
children 67b77b052ef3
files MapInfo.h Outdoor.cpp Outdoor.h Render.cpp Weather.h mm7_2.cpp mm7_3.cpp mm7_4.cpp mm7_data.cpp mm7_data.h
diffstat 10 files changed, 113 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/MapInfo.h	Sat Mar 23 20:22:51 2013 +0200
+++ b/MapInfo.h	Sat Mar 23 21:11:15 2013 +0200
@@ -1,5 +1,25 @@
 #pragma once
 
+enum MAP_TYPE: unsigned __int32
+{
+  MAP_INVALID = 0,
+  MAP_EMERALD_ISLE = 1,
+  MAP_HARMONDALE = 2,
+  MAP_STEADWICK = 3,
+  MAP_PIERPONT = 4,
+  MAP_DEYJA = 5,
+  MAP_BRAKADA_DESERT = 6,
+  MAP_CELESTIA = 7,
+  MAP_THE_PIT = 8,
+  MAP_EVENMORN_ISLE = 9,
+  MAP_MOUNT_NIGHON = 10,
+  MAP_BARROW_DOWNS = 11,
+  MAP_LAND_OF_GIANTS = 12,
+  MAP_TATALIA = 13,
+  MAP_AVLEE = 14,
+  MAP_SHOALS = 15,
+  //...
+};
 
 
 /*  192 */
@@ -53,7 +73,7 @@
 struct MapStats
 {
   void Initialize();
-  unsigned int GetMapInfo(const char *Str2);
+  MAP_TYPE GetMapInfo(const char *Str2);
 
   MapInfo pInfos[77];
   unsigned int uNumMaps;
--- a/Outdoor.cpp	Sat Mar 23 20:22:51 2013 +0200
+++ b/Outdoor.cpp	Sat Mar 23 21:11:15 2013 +0200
@@ -42,6 +42,32 @@
 Edge stru_80C9A4;
 Edge stru_80C9D8;
 
+
+struct FogProbabilityTableEntry
+{
+  unsigned char small_fog_chance;
+  unsigned char average_fog_chance;
+  unsigned char dense_fog_chance;
+  unsigned char __unused;
+} fog_probability_table[15] =
+{
+  { 20,  10,   5,   0}, // MAP_EMERALD_ISLE
+  { 20,  10,   5,   0}, // MAP_HARMONDALE
+  { 20,  10,   5,   0}, // MAP_STEADWICK
+  { 20,  10,   5,   0}, // MAP_PIERPONT
+  { 20,  10,   5,   0}, // MAP_DEYJA
+  { 10,   5,   0,   0}, // MAP_BRAKADA_DESERT
+  {  0,   0,   0,   0}, // MAP_CELESTIA
+  {  0,   0,   0,   0}, // MAP_THE_PIT
+  { 20,  30,  50,   0}, // MAP_EVENMORN_ISLE
+  { 30,  20,  10,   0}, // MAP_MOUNT_NIGHON
+  { 10,   5,   0,   0}, // MAP_BARROW_DOWNS
+  { 20,  10,   5,   0}, // MAP_LAND_OF_GIANTS
+  { 20,  10,   5,   0}, // MAP_TATALIA
+  { 20,  10,   5,   0}, // MAP_AVLEE
+  {  0, 100,   0,   0}  // MAP_SHOALS
+};
+
 //for future sky textures?
 int dword_4EC268[9]={3,3,3,3,3,3,3,3,3}; // weak
 int dword_4EC28C[7]={3,3,3,3,3,3,3}; // weak
@@ -288,9 +314,9 @@
       MessageBoxA(0, "Error!", "Couldn't Load Map!", 0);
       CreateDebugLocation();
     }
-    day_attrib = v5->day_attrib;
-    day_fogrange_1 = v5->day_fogrange_1;
-    day_fogrange_2 = v5->day_fogrange_2;
+    ::day_attrib = v5->day_attrib;
+    ::day_fogrange_1 = v5->day_fogrange_1;
+    ::day_fogrange_2 = v5->day_fogrange_2;
     if ( Is_out15odm_underwater() )
       SetUnderwaterFog();
     _6BE134_odm_main_tile_group = v5->pTileTypes[0].tileset;
@@ -545,63 +571,50 @@
   }
   return 1;
 }
-// 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
-// 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
+
 
 //----- (00489487) --------------------------------------------------------
-int OutdoorLocation::SetFog()
+void OutdoorLocation::SetFog()
 {
-  int result; // eax@1
-  int v2; // esi@1
-  int v3; // edx@5
-  unsigned __int8 *v4; // eax@5
-  int v5; // ecx@5
-  int v6; // esi@7
-  unsigned __int8 v7; // al@9
+  strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
 
-  strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
-  result = pMapStats->GetMapInfo(pCurrentMapName);
-  v2 = result;
-  if ( result < 1 || result == 7 || result == 8 || result > 15 )
-    return result;
-  day_attrib &= 0xFFFFFFFEu;
-  v3 = rand() % 100;
-  v4 = (unsigned __int8 *)&byte_4ECB0C[4 * v2];
-  v5 = *v4;
-  if ( v3 < v5 )
+  auto map_id = pMapStats->GetMapInfo(pCurrentMapName);
+  if (map_id == MAP_INVALID || map_id == MAP_CELESTIA || map_id == MAP_THE_PIT || map_id > MAP_SHOALS)
+    return;
+
+  uint chance = rand() % 100;
+
+  if (chance < fog_probability_table[map_id - 1].small_fog_chance)
   {
-    day_fogrange_1 = 4096;
-    day_fogrange_2 = 8192;
-LABEL_13:
-    day_attrib |= 1u;
-    goto LABEL_14;
+    ::day_fogrange_1 = 4096;
+    ::day_fogrange_2 = 8192;
+    ::day_attrib |= DAY_ATTRIB_FOG;
   }
-  v6 = v4[1];
-  if ( v3 < v6 + v5 )
+  else if (chance < fog_probability_table[map_id - 1].small_fog_chance +
+                    fog_probability_table[map_id - 1].average_fog_chance)
   {
-    day_fogrange_2 = 4096;
-LABEL_12:
-    day_fogrange_1 = 0;
-    goto LABEL_13;
+    ::day_fogrange_2 = 4096;
+    ::day_fogrange_1 = 0;
+    ::day_attrib |= DAY_ATTRIB_FOG;
   }
-  v7 = v4[2];
-  if ( v7 && v3 < v5 + v6 + v7 )
+  else if (fog_probability_table[map_id - 1].dense_fog_chance &&
+           chance < fog_probability_table[map_id - 1].small_fog_chance + 
+                    fog_probability_table[map_id - 1].average_fog_chance +
+                    fog_probability_table[map_id - 1].dense_fog_chance)
   {
-    day_fogrange_2 = 2048;
-    goto LABEL_12;
+    ::day_fogrange_2 = 2048;
+    ::day_fogrange_1 = 0;
+    ::day_attrib |= DAY_ATTRIB_FOG;
   }
-LABEL_14:
+  else
+    ::day_attrib &= ~DAY_ATTRIB_FOG;
+
   if ( Is_out15odm_underwater() )
     SetUnderwaterFog();
-  pOutdoor->day_fogrange_1 = day_fogrange_1;
-  pOutdoor->day_fogrange_2 = day_fogrange_2;
-  result = day_attrib;
-  pOutdoor->day_attrib = day_attrib;
-  return result;
+  pOutdoor->day_fogrange_1 = ::day_fogrange_1;
+  pOutdoor->day_fogrange_2 = ::day_fogrange_2;
+  pOutdoor->day_attrib = ::day_attrib;
 }
-// 6BE030: using guessed type int day_attrib;
-// 6BE040: using guessed type int day_fogrange_1;
-// 6BE044: using guessed type int day_fogrange_2;
 
 //----- (00482170) --------------------------------------------------------
 bool ODMFace::IsBackfaceCulled(ODMFace *a1, RenderVertexSoft *a2, stru148 *a3)
--- a/Outdoor.h	Sat Mar 23 20:22:51 2013 +0200
+++ b/Outdoor.h	Sat Mar 23 21:11:15 2013 +0200
@@ -5,6 +5,9 @@
 #include "TileFrameTable.h"
 
 
+
+#define DAY_ATTRIB_FOG  1
+
 /*  256 */
 #pragma pack(push, 1)
 struct ODMHeader
@@ -179,7 +182,7 @@
   void UpdateSunlightVectors();
   void UpdateFog();
   int GetNumFoodRequiredToRestInCurrentPos(int x, signed int y, int z);
-  int SetFog();
+  void SetFog();
   void Draw();
 
 
--- a/Render.cpp	Sat Mar 23 20:22:51 2013 +0200
+++ b/Render.cpp	Sat Mar 23 21:11:15 2013 +0200
@@ -634,7 +634,7 @@
   array_77EC08[1999].field_24 = 0x2000000u;
   array_77EC08[1999].sTextureDeltaU = 224 * pMiscTimer->uTotalGameTimeElapsed;
   array_77EC08[1999].sTextureDeltaV = 224 * pMiscTimer->uTotalGameTimeElapsed;
-  if ( day_attrib & 1
+  if ( day_attrib & DAY_ATTRIB_FOG
     && (LOWORD(v2) = LOWORD(pParty->uCurrentHour), pParty->uCurrentHour >= 5)
     && pParty->uCurrentHour < 0x15
     || bUnderwater )
--- a/Weather.h	Sat Mar 23 20:22:51 2013 +0200
+++ b/Weather.h	Sat Mar 23 21:11:15 2013 +0200
@@ -9,6 +9,10 @@
 #pragma pack(push, 1)
 struct Weather
 {
+  inline Weather():
+    bNight(false), bRenderSnow(false)
+  {}
+
   int DrawSnow();
   int Initialize();
   int Draw();
--- a/mm7_2.cpp	Sat Mar 23 20:22:51 2013 +0200
+++ b/mm7_2.cpp	Sat Mar 23 21:11:15 2013 +0200
@@ -6741,25 +6741,15 @@
 
 
 //----- (004547A3) --------------------------------------------------------
-unsigned int MapStats::GetMapInfo(const char *Str2)
-{
-  MapStats *v2; // esi@1
-  unsigned int v3; // edi@1
-  const char **v4; // ebx@2
-  unsigned int result; // eax@6
-
-  v3 = 1;
-  if ( (signed int)uNumMaps <= 1 )
-     return 0;
-  
-    while ( !*this->pInfos[v3].pFilename || _strcmpi(this->pInfos[v3].pFilename, Str2) )
-    {
-      ++v3;
-      if ( (signed int)v3 >= (signed int)uNumMaps )
-        return 0;
-    }
-    return v3;
-
+MAP_TYPE MapStats::GetMapInfo(const char *Str2)
+{
+  assert(uNumMaps >= 2);
+
+  for (uint i = 1; i < uNumMaps; ++i)
+    if (!strcmpi(pInfos[i].pFilename, Str2))
+      return (MAP_TYPE)i;
+
+  assert(false && "Map not found!");
 }
 
 //----- (004547E4) --------------------------------------------------------
--- a/mm7_3.cpp	Sat Mar 23 20:22:51 2013 +0200
+++ b/mm7_3.cpp	Sat Mar 23 21:11:15 2013 +0200
@@ -6687,7 +6687,7 @@
   {
     v4 = (MapInfo *)thisa;
   }
-  day_attrib &= 0xFFFFFFFEu;
+  day_attrib &= ~DAY_ATTRIB_FOG;
   dword_6BE13C_uCurrentlyLoadedLocationID = v2;
   pOutdoor->Initialize(
     pFilename,
@@ -6826,7 +6826,7 @@
     return PaletteManager::Get(a2);
   if ( !pWeather->bNight )
   {
-    if ( day_attrib & 1 )
+    if (day_attrib & DAY_ATTRIB_FOG)
     {
       v14 = day_fogrange_1 << 16;
       if ( a3 >= day_fogrange_1 << 16 )
@@ -6959,7 +6959,7 @@
     v10 = 0;
   if ( !v10 )
   {
-    if ( !(day_attrib & 1) && !bUnderwater )
+    if ( !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater )
     {
       v14 = a5;
       v15 = a6;
@@ -7234,13 +7234,13 @@
 
   if ( bUnderwater )
   {
-    result = 0xFF258F5Cu;
-  }
-  else
-  {
-    if ( day_attrib & 1 )
-    {
-      if ( pWeather->bNight )
+    result = 0xFF258F5C;
+  }
+  else
+  {
+    if (day_attrib & DAY_ATTRIB_FOG)
+    {
+      if ( pWeather->bNight ) // night-time fog
       {
         __debugbreak(); // decompilation can be inaccurate, please  send savegame to Nomad
         v2 = -(pWeather->bNight != 1);
@@ -7253,9 +7253,7 @@
       }
     }
     else
-    {
-      result = 0;
-    }
+      return 0;
   }
   return result;
 }
@@ -7278,7 +7276,7 @@
   v3 = pWeather->bNight;
   if ( bUnderwater == 1 )
     v3 = 0;
-  if ( pParty->armageddon_timer || !(day_attrib & 1) && !bUnderwater )
+  if ( pParty->armageddon_timer || !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater )
     return 0xFF000000;
   if ( v3 )
   {
--- a/mm7_4.cpp	Sat Mar 23 20:22:51 2013 +0200
+++ b/mm7_4.cpp	Sat Mar 23 21:11:15 2013 +0200
@@ -2525,9 +2525,9 @@
 
           if (!player->Pertified() && !player->Eradicated() && !player->Dead())
           {
-            if (rand() % 100 < 5 * pParty->days_played_without_rest )
+            if (rand() % 100 < 5 * pParty->days_played_without_rest)
               player->SetCondition(Player::Condition_Dead, 0);
-            if (rand() % 100 < 10 * pParty->days_played_without_rest )
+            if (rand() % 100 < 10 * pParty->days_played_without_rest)
               player->SetCondition(Player::Condition_Insane, 0);
           }
         }
--- a/mm7_data.cpp	Sat Mar 23 20:22:51 2013 +0200
+++ b/mm7_data.cpp	Sat Mar 23 21:11:15 2013 +0200
@@ -1107,7 +1107,6 @@
 char aTiletableLoadU[777]; // idb
 char byte_4ECA93[777]; // weak
 char byte_4ECACF[777]; // weak
-char byte_4ECB0C[64]; // idb
 char aError_0[777]; // idb
 char aCouldnTLoadMap[777]; // idb
 char aOut02d_odm[777]; // idb
--- a/mm7_data.h	Sat Mar 23 20:22:51 2013 +0200
+++ b/mm7_data.h	Sat Mar 23 21:11:15 2013 +0200
@@ -953,7 +953,6 @@
 extern char aTiletableLoadU[]; // idb
 extern char byte_4ECA93[]; // weak
 extern char byte_4ECACF[]; // weak
-extern char byte_4ECB0C[64]; // idb
 extern char aError_0[]; // idb
 extern char aCouldnTLoadMap[]; // idb
 extern char aOut02d_odm[]; // idb