changeset 1094:c40d40027b77

npc some clean
author Gloval
date Sun, 26 May 2013 18:55:31 +0400
parents 38890b8385e4
children 7c3772c91c7c
files Awards.h Game.cpp NPC.cpp Player.cpp UiGame.cpp mm7_data.cpp mm7_data.h
diffstat 7 files changed, 72 insertions(+), 121 deletions(-) [+]
line wrap: on
line diff
--- a/Awards.h	Sun May 26 14:13:43 2013 +0400
+++ b/Awards.h	Sun May 26 18:55:31 2013 +0400
@@ -9,7 +9,7 @@
   unsigned int  uPriority;
 };
 #pragma pack(pop)
-extern Award pAwards[104];
+extern Award pAwards[105];
 
 
 
--- a/Game.cpp	Sun May 26 14:13:43 2013 +0400
+++ b/Game.cpp	Sun May 26 18:55:31 2013 +0400
@@ -582,30 +582,21 @@
 //----- (0044F120) --------------------------------------------------------
 void Game::PushStationaryLights(int a2)
 {
-  signed int v3; // ebx@1
-  char *v4; // esi@2
-
-  auto v2 = this;
-  v3 = 0;
-  if ( (signed int)this->uNumStationaryLights > 0 )
-  {
-    v4 = (char *)&this->pStationaryLights[0].vRGBColor.y;
-    do
-    {
-      pStationaryLightsStack->AddLight(
-        (signed __int64)*((float *)v4 - 4),
-        (signed __int64)*((float *)v4 - 3),
-        (signed __int64)*((float *)v4 - 2),
-        (signed __int64)*((float *)v4 + 2),
-        (signed __int64)*((float *)v4 - 1),
-        (signed __int64)*(float *)v4,
-        (signed __int64)*((float *)v4 + 1),
-        byte_4E94D0);
-      ++v3;
-      v4 += 28;
-    }
-    while ( v3 < (signed int)v2->uNumStationaryLights );
-  }
+  Game__StationaryLight* pLight;
+ 
+  for( int i=0; i<uNumStationaryLights; ++i ) 
+      {
+       pLight=&pStationaryLights[i];
+       pStationaryLightsStack->AddLight(
+           pLight->vPosition.x, 
+           pLight->vPosition.y,
+           pLight->vPosition.z,
+           pLight->flt_18,
+           pLight->vRGBColor.x,
+           pLight->vRGBColor.y,
+           pLight->vRGBColor.z,
+           byte_4E94D0);
+      }
 }
 // 4E94D0: using guessed type char byte_4E94D0;
 
--- a/NPC.cpp	Sun May 26 14:13:43 2013 +0400
+++ b/NPC.cpp	Sun May 26 18:55:31 2013 +0400
@@ -158,95 +158,70 @@
 }
 
 //----- (00445B2C) --------------------------------------------------------
-NPCData *__fastcall GetNewNPCData(signed int npcid, int a2)
-{
-  signed int v2; // esi@1
-  int v3; // edi@1
+struct NPCData * GetNewNPCData( signed int npcid, int* npc_indx )
+    {
+
+  int* v3; // edi@1
   NPCData *result; // eax@5
   int v5; // esi@9
   int v6; // ecx@9
-  int v7; // edx@9
-  NPCData *v8; // eax@9
-  NPCData *v9; // edi@14
-  int v10; // ecx@20
   char v11; // al@23
-  std::string v12; // [sp-18h] [bp-34h]@4
-  const char *v13; // [sp-8h] [bp-24h]@4
-  int v14; // [sp-4h] [bp-20h]@4
-  std::string *v15; // [sp+Ch] [bp-10h]@1
-  char *v16; // [sp+10h] [bp-Ch]@14
-  int v17; // [sp+14h] [bp-8h]@13
-  int a3; // [sp+1Bh] [bp-1h]@4
 
-  v2 = npcid;
-  v3 = a2;
-  v15 = (std::string *)a2;
+  v3 = npc_indx;
   if ( npcid >= 0 )
   {
     if ( npcid < 5000 )
     {
       if ( npcid >= 501 )
       {
-    MessageBoxW(nullptr, L"NPC id exceeds MAX_DATA!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Events.cpp:2040", 0);
+        MessageBoxW(nullptr, L"NPC id exceeds MAX_DATA!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Events.cpp:2040", 0);
       }
-      *(int *)v3 = v2;
-      return &pNPCStats->pNewNPCData[v2];
+      *v3 = npcid;
+      return &pNPCStats->pNewNPCData[npcid];
     }
-LABEL_7:
-    *(int *)a2 = npcid - 5000;
+    *npc_indx = npcid - 5000;
     return &pNPCStats->pAdditionalNPC[npcid - 5000];
   }
   if ( npcid >= 5000 )
-    goto LABEL_7;
+      {
+      *npc_indx = npcid - 5000;
+      return &pNPCStats->pAdditionalNPC[npcid - 5000];
+      }
   if ( sDialogue_SpeakingActorNPC_ID >= 0 )
   {
-    *(int *)a2 = 0;
-    result = 0;
+    *npc_indx = 0;
+    result = NULL;
   }
   else
   {
-    v5 = abs((int)sDialogue_SpeakingActorNPC_ID) - 1;
+    v5 = abs(sDialogue_SpeakingActorNPC_ID) - 1;
     v6 = 0;
-    v7 = 0;
-    v8 = pParty->pHirelings;
-    do
-    {
-      if ( v8->pName )
-        pTmpBuf[v6++] = v7;
-      ++v8;
-      ++v7;
-    }
-    while ( (signed int)v8 < (signed int)&pParty->pPickedItem );
-    v17 = 0;
-    if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
+    for (int i=0; i<2; ++i)
     {
-      v9 = pNPCStats->pNewNPCData;
-      v16 = &pTmpBuf[v6];
-      do
-      {
-        if ( v9->Hired()
-          && (!pParty->pHirelings[0].pName || strcmp(v9->pName, pParty->pHirelings[0].pName))
-          && (!pParty->pHirelings[1].pName || strcmp(v9->pName, pParty->pHirelings[1].pName)) )
+      if ( pParty->pHirelings[i].pName )
+        pTmpBuf[v6++] = i;
+     
+    }     
+    for (int i=0; i< pNPCStats->uNumNewNPCs; ++i)
         {
-          v10 = (int)v16++;
-          *(char *)v10 = v17 + 2;
+        if ( pNPCStats->pNewNPCData[i].Hired()
+            && (!pParty->pHirelings[0].pName || strcmp(pNPCStats->pNewNPCData[i].pName, pParty->pHirelings[0].pName))
+            && (!pParty->pHirelings[1].pName || strcmp(pNPCStats->pNewNPCData[i].pName, pParty->pHirelings[1].pName)) )
+            {
+                pTmpBuf[v6++]=i+2;
+            }
         }
-        ++v17;
-        ++v9;
-      }
-      while ( v17 < (signed int)pNPCStats->uNumNewNPCs );
-      v3 = (int)v15;
-    }
     v11 = pTmpBuf[v5];
-    if ( (unsigned __int8)v11 >= 2u )
+
+    if ( v11 >= 2u )
     {
-      *(int *)v3 = (unsigned __int8)v11 - 2;
-      result = &pNPCStats->pNPCData[(unsigned __int8)pTmpBuf[v5] + 499];
+      *v3 = v11 - 2;
+      result = &pNPCStats->pNewNPCData[v11 - 2];
     }
     else
     {
-      *(int *)v3 = (unsigned __int8)v11;
-      result = &pParty->pHirelings[(unsigned __int8)pTmpBuf[v5]];
+      *v3 = v11;
+      result = &pParty->pHirelings[v11];
     }
   }
   return result;
@@ -920,39 +895,24 @@
 //----- (00476395) --------------------------------------------------------
 //0x26 Wizard eye at skill level 2
 bool __thiscall CheckHiredNPCSpeciality(unsigned int uProfession)
-{
-	bool result; // eax@2
-	signed int v2; // esi@3
-	char *v3; // eax@4
+    {
+
+    if ( bNoNPCHiring == 1 )
+        return 0;
 
-	if ( bNoNPCHiring == 1 )
-		return 0;
-	v2 = 0;
-	if ( (signed int)pNPCStats->uNumNewNPCs <= 0 )
-		{
-LABEL_8:
-		result = 0;
-		if ( pParty->pHirelings[0].uProfession != uProfession )
-			{
-			LOBYTE(result) = pParty->pHirelings[1].uProfession == uProfession;
-			return result;
-			}
-		}
-	else
-		{
-		v3 = (char *)&pNPCStats->pNewNPCData[0].uFlags;
-		while ( *((int *)v3 + 4) != uProfession || !(*v3 & 0x80) )
-			{
-			++v2;
-			v3 += 76;
-			if ( v2 >= (signed int)pNPCStats->uNumNewNPCs )
-				goto LABEL_8;
-			}
-		result = 0;
-		}
-	++result;
-	return result;
-	}
+    for (int i=0; i<pNPCStats->uNumNewNPCs; ++i )
+        {
+        if ( pNPCStats->pNewNPCData[i].uProfession == uProfession && 
+            (pNPCStats->pNewNPCData[i].uFlags & 0x80) )
+            return true;
+        }
+    if ( pParty->pHirelings[0].uProfession == uProfession ||
+         pParty->pHirelings[1].uProfession == uProfession)
+        return true;
+    else
+        return false;
+
+    }
 // 6BE3C5: using guessed type char bNoNPCHiring;
 
 //----- (004763E0) --------------------------------------------------------
--- a/Player.cpp	Sun May 26 14:13:43 2013 +0400
+++ b/Player.cpp	Sun May 26 18:55:31 2013 +0400
@@ -8999,7 +8999,7 @@
           {
             case 232:
               VarNum = (VariableType)0;
-              GetNewNPCData(sDialogue_SpeakingActorNPC_ID, (int)&VarNum);
+              GetNewNPCData(sDialogue_SpeakingActorNPC_ID, (int*)&VarNum);
               result = (bool) pValue;
 			  dword_5B65CC = 0;
               if ( (int)VarNum == pValue )
--- a/UiGame.cpp	Sun May 26 14:13:43 2013 +0400
+++ b/UiGame.cpp	Sun May 26 18:55:31 2013 +0400
@@ -262,7 +262,7 @@
     if ( (signed int)((char *)v17 + (unsigned __int8)pParty->field_709) < v1 )
     {
       sDialogue_SpeakingActorNPC_ID = -1 - (unsigned __int8)pParty->field_709 - (int)v17;
-      v5 = GetNewNPCData(sDialogue_SpeakingActorNPC_ID, (int)&a2);
+      v5 = GetNewNPCData(sDialogue_SpeakingActorNPC_ID, &a2);
       v6 = v5;
       if ( v5 )
       {
--- a/mm7_data.cpp	Sun May 26 14:13:43 2013 +0400
+++ b/mm7_data.cpp	Sun May 26 18:55:31 2013 +0400
@@ -52,7 +52,7 @@
 Autonote pAutonoteTxt[195]; // weak
 
 #include "Awards.h"
-Award pAwards[104];
+Award pAwards[105];
 AwardType achieved_awards[1000];
 int num_achieved_awards;
 int num_achieved_awards_2;
@@ -1114,7 +1114,7 @@
 int dword_591084; // weak
 struct Actor *pDialogue_SpeakingActor;
 unsigned int uDialogueType;
-signed int sDialogue_SpeakingActorNPC_ID;
+int sDialogue_SpeakingActorNPC_ID;
 struct LevelDecoration *_591094_decoration;
 char sHouseName[200]; // idb
 int uCurrentHouse_Animation; // weak
--- a/mm7_data.h	Sun May 26 14:13:43 2013 +0400
+++ b/mm7_data.h	Sun May 26 18:55:31 2013 +0400
@@ -1342,7 +1342,7 @@
 void __cdecl sub_4452BB();
 const char *GetProfessionActionText(int a1);
 struct NPCData *__fastcall GetNPCData(signed int npcid);
-struct NPCData *__fastcall GetNewNPCData(signed int npcid, int a2);
+struct NPCData * GetNewNPCData(signed int npcid, int* npc_indx);
 int __fastcall GetGreetType(signed int SpeakingNPC_ID);
 void __cdecl DialogueEnding();
 void PrepareHouse(enum HOUSE_ID house); // idb