diff mm7_3.cpp @ 248:37dcbe8f3cca

Dialogue stuff
author Nomad
date Mon, 18 Feb 2013 07:11:43 +0200
parents e9fabaf75628
children e22e2357c8b3 d1af3319bc44 c3bfe1eb3de7
line wrap: on
line diff
--- a/mm7_3.cpp	Mon Feb 18 03:59:31 2013 +0200
+++ b/mm7_3.cpp	Mon Feb 18 07:11:43 2013 +0200
@@ -4704,9 +4704,9 @@
 }
 
 //----- (00476387) --------------------------------------------------------
-bool __cdecl sub_476387()
-{
-  return (pNPCStats->pNewNPCData[57].uFlags & 0x80) != 0;
+bool PartyHasDragon()
+{
+  return pNPCStats->pNewNPCData[57].Hired();
 }
 
 //----- (00476395) --------------------------------------------------------
@@ -16221,7 +16221,7 @@
   unsigned __int16 v2; // di@2
   //unsigned int v3; // eax@2
   char *v4; // esi@3
-  int v5; // eax@11
+  //int v5; // eax@11
   char *v6; // ecx@13
   char *v7; // eax@16
   unsigned int v8; // edi@19
@@ -16279,16 +16279,86 @@
   pRenderer->DrawTextureTransparent(468, 0, (Texture *)(uTextureID_507B04 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_507B04] : 0));
   pRenderer->DrawTextureIndexed(pNPCPortraits_x - 4, pNPCPortraits_y - 4, (Texture *)(uTextureID_50795C != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_50795C] : 0));
   pRenderer->DrawTextureIndexed(pNPCPortraits_x, pNPCPortraits_y, pDialogueNPCPortraits[0]);
-  if ( pNPC->uProfession )
-  {
-    sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[429], pNPC->pName, aNPCProfessionNames[pNPC->uProfession]);//^Pi[%s] %s
-  }
-  else
-  {
+
+  if (pNPC->uProfession)
+  {
+    assert(pNPC->uProfession < sizeof(aNPCProfessionNames) / sizeof(*aNPCProfessionNames)); // sometimes buffer overflows; errors emerge both here and in dialogue text
+    sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[429], pNPC->pName, aNPCProfessionNames[pNPC->uProfession]);//^Pi[%s] %s
+  }
+  else
     strcpy(pTmpBuf, pNPC->pName);
-  }
+
   v51.DrawTitleText(pFontArrus, 483, 112, v2, pTmpBuf, 3);
   pParty->GetPartyFame();
+
+  switch (uDialogueType)
+  {
+    case DIALOGUE_PROFESSION_DETAILS:
+    {
+          if (dialogue_show_profession_details)
+          {
+            v6 = pNPCStats->pProfessions[pNPC->uProfession - 1].pBenefits;
+            v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
+            pInString = v7;
+            pWindow.uFrameWidth = 460;
+            pWindow.uFrameZ = 452;
+            pOutString = pFontArrus;
+            v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
+            if ( 352 - v12 < 8 )
+            {
+              pOutString = pFontCreate;
+              v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
+            }
+            if (uTextureID_Leather != -1)
+              pRenderer->_4A6A68(8, 352 - v12, &pIcons_LOD->pTextures[uTextureID_Leather], pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight - v12);
+            pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+            v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, 0);
+            pDialogueWindow->DrawText(pOutString, 13, 354 - v12, 0, v13, 0, 0, 0);
+          }
+          else if (pNPC->Hired())
+          {
+            v6 = pNPCStats->pProfessions[pNPC->uProfession - 1].pDismissText;
+            v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
+            pInString = v7;
+            pWindow.uFrameWidth = 460;
+            pWindow.uFrameZ = 452;
+            pOutString = pFontArrus;
+            v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
+            if ( 352 - v12 < 8 )
+            {
+              pOutString = pFontCreate;
+              v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
+            }
+            if (uTextureID_Leather != -1)
+              pRenderer->_4A6A68(8, 352 - v12, &pIcons_LOD->pTextures[uTextureID_Leather], pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight - v12);
+            pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+            v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, 0);
+            pDialogueWindow->DrawText(pOutString, 13, 354 - v12, 0, v13, 0, 0, 0);
+          }
+		  else
+		  {
+            v6 = pNPCStats->pProfessions[pNPC->uProfession - 1].pJoinText;
+			v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
+			pInString = v7;
+			pWindow.uFrameWidth = 460;
+			pWindow.uFrameZ = 452;
+			pOutString = pFontArrus;
+			v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
+			if ( 352 - v12 < 8 )
+			{
+			pOutString = pFontCreate;
+			v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
+			}
+            if (uTextureID_Leather != -1)
+              pRenderer->_4A6A68(8, 352 - v12, &pIcons_LOD->pTextures[uTextureID_Leather], pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight - v12);
+			pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
+			v13 = FitTextInAWindow(pInString, pOutString,  &pWindow, 0xDu, 0);
+			pDialogueWindow->DrawText(pOutString, 13, 354 - v12, 0, v13, 0, 0, 0);
+		  }
+    }
+    break;
+  }
+
   if ( (signed int)uDialogueType > DIALOGUE_ARENA_WELCOME )
   {
     if ( uDialogueType == DIALOGUE_ARENA_FIGHT_NOT_OVER_YET )
@@ -16369,8 +16439,7 @@
     }
     else if ( uDialogueType == DIALOGUE_13 )
     {
-      v5 = 5 * pNPC->uProfession;
-      v6 = (char *)*(&pNPCStats->field_13A64 + v5);
+      v6 = pNPCStats->pProfessions[pNPC->uProfession - 1].pJoinText;
       v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
       pInString = v7;
       pWindow.uFrameWidth = 460;
@@ -16382,79 +16451,15 @@
         pOutString = pFontCreate;
         v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
       }
-      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+      pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0),
         (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
       pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
       v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, 0);
       pDialogueWindow->DrawText(pOutString, 13, 354 - v12, 0, v13, 0, 0, 0);
     }
-    else if ( (signed int)uDialogueType > DIALOGUE_18 && !((signed int)uDialogueType > DIALOGUE_24 && uDialogueType != DIALOGUE_77 || byte_5B0938[0]) )
-    {
-      if ( (signed int)uDialogueType > DIALOGUE_24 && uDialogueType == DIALOGUE_77 )
-      {
-          v5 = 5 * pNPC->uProfession;
-          if ( byte_F8B1EC )
-          {
-            v6 = (char *)*(&pNPCStats->field_13A5C + 5 * pNPC->uProfession);
-            v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
-            pInString = v7;
-            pWindow.uFrameWidth = 460;
-            pWindow.uFrameZ = 452;
-            pOutString = pFontArrus;
-            v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
-            if ( 352 - v12 < 8 )
-            {
-              pOutString = pFontCreate;
-              v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
-            }
-            pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
-                              (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
-            pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
-            v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, 0);
-            pDialogueWindow->DrawText(pOutString, 13, 354 - v12, 0, v13, 0, 0, 0);
-          }
-          else if ( pNPC->uFlags & 0x80 )
-          {
-            v6 = (char *)*(&pNPCStats->field_13A68 + 5 * pNPC->uProfession);
-            v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
-            pInString = v7;
-            pWindow.uFrameWidth = 460;
-            pWindow.uFrameZ = 452;
-            pOutString = pFontArrus;
-            v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
-            if ( 352 - v12 < 8 )
-            {
-              pOutString = pFontCreate;
-              v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
-            }
-            pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
-                               (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
-            pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
-            v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, 0);
-            pDialogueWindow->DrawText(pOutString, 13, 354 - v12, 0, v13, 0, 0, 0);
-          }
-		  else
-		  {
-			v6 = (char *)*(&pNPCStats->field_13A64 + v5);
-			v7 = sub_495461(v6, uActiveCharacter - 1, 0, 0, 0, 0);
-			pInString = v7;
-			pWindow.uFrameWidth = 460;
-			pWindow.uFrameZ = 452;
-			pOutString = pFontArrus;
-			v12 = pFontArrus->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
-			if ( 352 - v12 < 8 )
-			{
-			pOutString = pFontCreate;
-			v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
-			}
-			pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
-										(uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
-			pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
-			v13 = FitTextInAWindow(pInString, pOutString,  &pWindow, 0xDu, 0);
-			pDialogueWindow->DrawText(pOutString, 13, 354 - v12, 0, v13, 0, 0, 0);
-		  }
-      }
-	  else
+    else if ( (signed int)uDialogueType > DIALOGUE_18 && !((signed int)uDialogueType > DIALOGUE_24 && uDialogueType != DIALOGUE_PROFESSION_DETAILS || byte_5B0938[0]) )
+    {
+	  if ((signed int)uDialogueType <= DIALOGUE_23)
 	  {
 		  v7 = (char *)ptr_F8B1E8;
 		  pInString = v7;
@@ -16467,7 +16472,7 @@
 			pOutString = pFontCreate;
 			v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
 		  }
-		  pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
+		  pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? &pIcons_LOD->pTextures[uTextureID_Leather] : 0),
 			(uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
 		  pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
 		  v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, 0);
@@ -16506,10 +16511,10 @@
 		{
 			if ( *(int *)v54 == 2 )
 			{
-				if ( pNPC->uFlags & 0x80 )
-					v9 = (char *)pNPCStats->pProfessions[pNPC->uProfession].pDismissText;
+				if (pNPC->Hired())
+					v9 = pNPCStats->pProfessions[pNPC->uProfession].pDismissText;
 				else
-					v9 = (char *)pNPCStats->pProfessions[pNPC->uProfession].pJoinText; //"Invalid String Passed"
+					v9 = pNPCStats->pProfessions[pNPC->uProfession].pJoinText; //"Invalid String Passed"
 				pInString = sub_495461(v9, uActiveCharacter - 1, 0, 0, 0, 0);
 				if (  pInString != NULL )
 				{
@@ -16522,8 +16527,8 @@
 						pOutString = pFontCreate;
 						v12 = pFontCreate->CalcTextHeight(pInString, &pWindow, 13, 0) + 7;
 					}
-					pRenderer->_4A6A68(8, 352 - v12, (Texture *)(uTextureID_Leather != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_Leather] : 0),
-					(uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v12);
+                    if (uTextureID_Leather != -1)
+                      pRenderer->_4A6A68(8, 352 - v12, &pIcons_LOD->pTextures[uTextureID_Leather], pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight - v12);
 					pRenderer->DrawTextureIndexed(8u, 347 - v12, pTexture_591428);
 					v13 = FitTextInAWindow(pInString, pOutString, &pWindow, 0xDu, 0);
 					pDialogueWindow->DrawText(pOutString, 13, 354 - v12, 0, v13, 0, 0, 0);
@@ -16551,24 +16556,24 @@
         v24 = "";
     }
 	else if ( v16 == 88 )
-		v24 = pGlobalTXT_LocalizationStrings[581];
+		v24 = pGlobalTXT_LocalizationStrings[581]; // Lord
     else if ( v16 == 87 )
-	    v24 = pGlobalTXT_LocalizationStrings[580];
+	    v24 = pGlobalTXT_LocalizationStrings[580]; // Knight
     else if ( v16 == 86 )
-	    v24 = pGlobalTXT_LocalizationStrings[579];
+	    v24 = pGlobalTXT_LocalizationStrings[579]; // Squire
     else if ( v16 == 85 )
-		v24 = pGlobalTXT_LocalizationStrings[578];
+		v24 = pGlobalTXT_LocalizationStrings[578]; // Page
     else if ( v16 == 77 )
-        v24 = pGlobalTXT_LocalizationStrings[407];
+        v24 = pGlobalTXT_LocalizationStrings[407]; // Details
     else if ( v16 == 76 )
     {
-		if ( pNPC->uFlags & 0x80 )
+		if (pNPC->Hired())
 		{
-			sprintf(pTmpBuf, (const char*)pGlobalTXT_LocalizationStrings[408], pNPC->pName);
+			sprintf(pTmpBuf, (const char*)pGlobalTXT_LocalizationStrings[408], pNPC->pName); // Release %s
 			v24 = pTmpBuf;
 		}
 		else
-			v24 = pGlobalTXT_LocalizationStrings[406];
+			v24 = pGlobalTXT_LocalizationStrings[406]; // Hire
     }
 	else if ( v16 == 24 )
     {
@@ -16634,13 +16639,13 @@
 	}
 	else if ( v16 == 13 )
 	{
-		if ( pNPC->uFlags & 0x80 )
+		if (pNPC->Hired())
 		{
-			sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[408], pNPC->pName);
+			sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[408], pNPC->pName); // Release %s
 			v24 = pTmpBuf;
 		}
 		else
-			v24 = pGlobalTXT_LocalizationStrings[122];
+			v24 = pGlobalTXT_LocalizationStrings[122]; // Join
 	}
 	else
 		v24 = "";
@@ -16841,7 +16846,7 @@
     {
       for (i = 0; i < pNPCStats->uNumNewNPCs; ++i)
       {
-        if (pNPCStats->pNewNPCData[i].uFlags & 0x80)
+        if (pNPCStats->pNewNPCData[i].Hired())
         {
           if (!pParty->pHirelings[0].pName || strcmp((char *)pNPCStats->pNewNPCData[i].pName, (char *)pParty->pHirelings[0].pName))
           {
@@ -16927,7 +16932,7 @@
       v16 = &pTmpBuf[v6];
       do
       {
-        if ( v9->uFlags & 0x80
+        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)) )
         {
@@ -16993,7 +16998,7 @@
     v8 = pNPCStats->pNewNPCData;
     do
     {
-      if ( v8->uFlags & 0x80 && (!pParty->pHirelings[0].pName || strcmp(v8->pName, pParty->pHirelings[0].pName)) )
+      if (v8->Hired() && (!pParty->pHirelings[0].pName || strcmp(v8->pName, pParty->pHirelings[0].pName)) )
       {
         if ( !pParty->pHirelings[1].pName || strcmp(v8->pName, pParty->pHirelings[1].pName) )
           *v7++ = v1 + 2;
@@ -20111,7 +20116,7 @@
   for (int i = 0; i < pNPCStats->uNumNewNPCs; ++i)
   {
     auto npc = pNPCStats->pNewNPCData + i;
-    if (npc->uFlags & 0x80 &&
+    if (npc->Hired() &&
         (!pParty->pHirelings[0].pName || strcmp(npc->pName, pParty->pHirelings[0].pName)))
     {
       if (!pParty->pHirelings[1].pName || strcmp(npc->pName, pParty->pHirelings[1].pName))