changeset 2237:d903816e972e

_4B254D_SkillMasteryTeacher adding case, removing nested ifs, adding some comments
author Grumpy7
date Sun, 23 Feb 2014 14:12:07 +0100
parents 3c802b5e026a
children f66d8be6ad5b
files mm7_4.cpp mm7_unsorted_subs.h
diffstat 2 files changed, 83 insertions(+), 112 deletions(-) [+]
line wrap: on
line diff
--- a/mm7_4.cpp	Sun Feb 23 12:55:01 2014 +0100
+++ b/mm7_4.cpp	Sun Feb 23 14:12:07 2014 +0100
@@ -1823,22 +1823,22 @@
 }
 
 //----- (004B254D) --------------------------------------------------------
-char * _4B254D_SkillMasteryTeacher(int _this)
+const char * _4B254D_SkillMasteryTeacher(int _this)
 {
   //Player *v1; // esi@1
   int v2; // edx@1
   int v3; // ecx@1
   int pClassType; // eax@7
   int v6; // eax@7
-  int v7; // ebx@7
+  int pointsInSkillWOutMastery; // ebx@7
   //int v8; // ebx@8
   signed int v9; // esi@8
-  int v10; // eax@8
+  int classBaseId; // eax@8
   char *v11; // ecx@8
   //int v12; // edi@9
   //char *v13; // edx@9
   signed int v14; // edi@10
-  unsigned int v16; // eax@29
+  unsigned int skillMastery; // eax@29
   //int v17; // eax@36
   char v18; // cl@46
   __int16 v19; // dx@56
@@ -1851,7 +1851,7 @@
   //int v26; // [sp-4h] [bp-30h]@38
   //int v27; // [sp-4h] [bp-30h]@82
   char v28[4]; // [sp+Ch] [bp-20h]@9
-  unsigned __int16 a1[2]; // [sp+1Ch] [bp-10h]@7
+  unsigned __int16 pointsInSkill; // [sp+1Ch] [bp-10h]@7
   //int v33; // [sp+20h] [bp-Ch]@7
   int v34; // [sp+24h] [bp-8h]@7
   char *v35; // [sp+28h] [bp-4h]@1
@@ -1860,119 +1860,90 @@
   v2 = (_this - 200) % 3;
   v3 = (_this - 200) / 3;
   v35 = (char *)pNPCTopics[127].pText;
-  dword_F8B1AC_award_bit_number = v3;
-  if ( v2 )
+    dword_F8B1AC_award_bit_number = v3;
+  switch(v2)
   {
-    if ( v2 == 1 )
-    {
+    case 0: 
+      gold_transaction_amount = 2000;
+      dword_F8B1B0 = 2;
+      break;
+    case 1: 
       gold_transaction_amount = 5000;
       dword_F8B1B0 = 3;
-    }
-    else
-    {
-      if ( v2 == 2 )
-      {
-        gold_transaction_amount = 8000;
-        dword_F8B1B0 = 4;
-      }
-    }
-  }
-  else
-  {
-    gold_transaction_amount = 2000;
-    dword_F8B1B0 = 2;
+      break;
+    case 2: 
+      gold_transaction_amount = 8000;
+      dword_F8B1B0 = 4;
+      break;
   }
   pClassType = pPlayers[uActiveCharacter]->classType;
   //v33 = pClassType;
   v6 = byte_4ED970_skill_learn_ability_by_class_table[pClassType][v3];
-  *(int *)a1 = pPlayers[uActiveCharacter]->pActiveSkills[v3];
-  v7 = a1[0] & 0x3F;
   v34 = v2 + 2;
   if ( v6 < v2 + 2 )
   {
-    //v8 = v33;
-    
-    v10 = pClassType - pClassType % 4;
-    v11 = &byte_4ED970_skill_learn_ability_by_class_table[pClassType - pClassType % 4][v3];
-    for ( v9 = 0; v9 < 4; ++v9 )
-    {
-      v28[v9] = ( (unsigned __int8)*v11 < v34 ) ? 0 : 1;
-      v11 += 37;
-    }
-    if ( v28[1] == 1 )
-    {
-      v25 = pClassNames[v10 + 1];
-    }
+    classBaseId = pClassType - pClassType % 4;
+    if (byte_4ED970_skill_learn_ability_by_class_table[classBaseId + 1][v3] >= v34)
+      sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[633], pClassNames[classBaseId + 1]);//Вы должны достичь звания %s для обучения этому уровню навыка. You have to be promoted to %s to learn this skill level.
+    else if (byte_4ED970_skill_learn_ability_by_class_table[classBaseId + 2][v3] >= v34
+      && byte_4ED970_skill_learn_ability_by_class_table[classBaseId + 3][v3] >= v34)
+      sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[634], pClassNames[classBaseId + 2], pClassNames[classBaseId + 3]);//Вы должны достичь звания %s или %s для обучения этому уровню навыка. You have to be promoted to %s or %s to learn this skill level.
+    else if (byte_4ED970_skill_learn_ability_by_class_table[classBaseId + 2][v3] >= v34)
+      sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[633], pClassNames[classBaseId + 2]);//Вы должны достичь звания %s для обучения этому уровню навыка. You have to be promoted to %s to learn this skill level.
+    else if (byte_4ED970_skill_learn_ability_by_class_table[classBaseId + 3][v3] >= v34)
+      sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[633], pClassNames[classBaseId + 3]);//Вы должны достичь звания %s для обучения этому уровню навыка. You have to be promoted to %s to learn this skill level.
     else
-    {
-      if ( v28[2] == 1 )
-      {
-        if ( v28[3] == 1 )
-        {
-          sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[634], pClassNames[v10 + 2], pClassNames[v10 + 3]);//Вы должны достичь звания %s или %s для обучения этому уровню навыка.
-          return pTmpBuf.data();
-        }
-        v25 = pClassNames[v10 + 2];
-      }
-      else
-      {
-        if ( v28[3] != 1 )
-        {
-          sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[632], pClassNames[pClassType]);//Этот уровень навыка не может быть постигнут классом %s.
-          return pTmpBuf.data();
-        }
-        v25 = pClassNames[v10 + 3];
-      }
-    }
-    sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[633], v25);//Вы должны достичь звания %s для обучения этому уровню навыка.
+      sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[632], pClassNames[pClassType]);//Этот уровень навыка не может быть постигнут классом %s. This skill level can not be learned by the %s class.
     return pTmpBuf.data();
   }
   if ( !pPlayers[uActiveCharacter]->CanAct() )
-    return (char *)pNPCTopics[122].pText;
-  if ( !v7 )
-    return (char *)pNPCTopics[131].pText;
-  v16 = SkillToMastery(a1[0]);
-  if ( (signed int)v16 > v2 + 1 )
-    return (char *)pNPCTopics[v2 + 128].pText;
+    return pNPCTopics[122].pText; //Not in your condition!
+  pointsInSkill = pPlayers[uActiveCharacter]->pActiveSkills[v3];
+  pointsInSkillWOutMastery = pointsInSkill & 0x3F;
+  if ( !pointsInSkillWOutMastery )
+    return pNPCTopics[131].pText; //You must know the skill before you can become an expert in it!
+  skillMastery = SkillToMastery(pointsInSkill);
+  if ( (signed int)skillMastery > v2 + 1 )  // You are already an SKILLLEVEL in this skill.	
+    return pNPCTopics[v2 + 128].pText;
   if ( v34 != 2 )
   {
     if ( v34 == 3 )
     {
-      if ( (signed int)v16 >= 2 && v7 >= 7 )
+      if ( (signed int)skillMastery >= 2 && pointsInSkillWOutMastery >= 7 )
       {
         switch ( dword_F8B1AC_award_bit_number )
         {
-          case 12:
-          case 13:
-          case 14:
-          case 15:
-          case 16:
-          case 17:
-          case 18:
+          case 12:    //Fire magic
+          case 13:    //Air magic
+          case 14:    //Water magic
+          case 15:    //Earth magic
+          case 16:    //Spirit magic
+          case 17:    //Mind magic
+          case 18:    //Body magic
             gold_transaction_amount = 4000;
             goto LABEL_42;
-          case 19:
+          case 19:    //Light magic
             v19 = 114;
             if ( !(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, v19) )
               return v35;
             if ( !gold_transaction_amount )
               goto LABEL_79;
             goto LABEL_42;
-          case 20:
+          case 20:    //Dark magic
             v19 = 110;
             if ( !(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, v19) )
               return v35;
             if ( !gold_transaction_amount )
               goto LABEL_79;
             goto LABEL_42;
-          case 22:
+          case 22:     //Merchant
             v20 = pPlayers[uActiveCharacter]->GetBaseWillpower();
             if ( v20 < 50 )
               return v35;
             if ( !gold_transaction_amount )
               goto LABEL_79;
             goto LABEL_42;
-          case 24:
+          case 24:     //Body Building
             gold_transaction_amount = 2500;
             v20 = pPlayers[uActiveCharacter]->GetBaseEndurance();
             if ( v20 < 50 )
@@ -1980,30 +1951,30 @@
             if ( !gold_transaction_amount )
               goto LABEL_79;
             goto LABEL_42;
-          case 36:
+          case 36:     //Learning
             v20 = pPlayers[uActiveCharacter]->GetBaseIntelligence();
             if ( v20 < 50 )
               return v35;
             if ( !gold_transaction_amount )
               goto LABEL_79;
             goto LABEL_42;
-          case 21:
-          case 23:
-          case 25:
-          case 26:
-          case 29:
-          case 32:
-          case 34:
-          case 35:
+          case 21:     //Identify Item
+          case 23:     //Repait Item
+          case 25:     //Meditation
+          case 26:     //Perception
+          case 29:     //Disarm Trap
+          case 32:     //Identify Monster
+          case 34:     //Stealing
+          case 35:     //Alchemy
             gold_transaction_amount = 2500;
             goto LABEL_42;
-          case 8:
-          case 9:
-          case 10:
-          case 11:
+          case 8:     //Shield
+          case 9:     //Leather
+          case 10:     //Chain
+          case 11:     //Plate
             gold_transaction_amount = 3000;
             goto LABEL_42;
-          case 7:
+          case 7:     //Blaster
             gold_transaction_amount = 0;
             if ( !gold_transaction_amount )
               goto LABEL_79;
@@ -2027,11 +1998,11 @@
           goto LABEL_79;
         goto LABEL_42;
       }
-      if ( (signed int)v16 >= 3 && v7 >= 10 )
+      if ( (signed int)skillMastery >= 3 && pointsInSkillWOutMastery >= 10 )
       {
         switch ( dword_F8B1AC_award_bit_number )
         {
-          case 19:
+        case 19:     //Light Magic
             if ( pPlayers[uActiveCharacter]->ProfessionOrGuildFlagsCorrect(0x22u, 1) == 1 )
             {
               if ( !gold_transaction_amount )
@@ -2045,7 +2016,7 @@
               goto LABEL_42;
             }
             return v35;
-          case 20:
+          case 20:     //Dark Magic
             if ( pPlayers[uActiveCharacter]->ProfessionOrGuildFlagsCorrect(0x23u, 1) == 1 )
             {
               if ( !gold_transaction_amount )
@@ -2059,38 +2030,38 @@
               goto LABEL_42;
             }
             return v35;
-          case 30:
+          case 30:     //Dodging
             v18 = LOBYTE(pPlayers[uActiveCharacter]->pActiveSkills[PLAYER_SKILL_UNARMED]);
             if ( (v18 & 0x3Fu) < 0xA )
               return v35;
             if ( !gold_transaction_amount )
               goto LABEL_79;
             goto LABEL_42;
-          case 31:
+          case 31:     //Unarmed
             v18 = LOBYTE(pPlayers[uActiveCharacter]->pActiveSkills[PLAYER_SKILL_DODGE]);
             if ( (v18 & 0x3Fu) < 0xA )
               return v35;
             if ( !gold_transaction_amount )
               goto LABEL_79;
             goto LABEL_42;
-          case 21:
-          case 23:
-          case 24:
-          case 25:
-          case 26:
-          case 29:
-          case 32:
-          case 34:
-          case 35:
+          case 21:     //Identify Item
+          case 23:     //Repait Item
+          case 24:     //Body Building
+          case 25:     //Meditation
+          case 26:     //Perception
+          case 29:     //Disarm Trap
+          case 32:     //Identify Monster
+          case 34:     //Stealing
+          case 35:     //Alchemy
             gold_transaction_amount = 6000;
             goto LABEL_42;
-          case 8:
-          case 9:
-          case 10:
-          case 11:
+          case 8:     //Shield
+          case 9:     //Leather
+          case 10:     //Chain
+          case 11:     //Plate
             gold_transaction_amount = 7000;
             goto LABEL_42;
-          case 7:
+          case 7:    //Blaster
             break;
           default:
             if ( !gold_transaction_amount )
@@ -2105,7 +2076,7 @@
     }
     return v35;
   }
-  if ( v7 < 4 )
+  if ( pointsInSkillWOutMastery < 4 )
     return v35;
   if ( dword_F8B1AC_award_bit_number > 27 )
   {
--- a/mm7_unsorted_subs.h	Sun Feb 23 12:55:01 2014 +0100
+++ b/mm7_unsorted_subs.h	Sun Feb 23 14:12:07 2014 +0100
@@ -156,7 +156,7 @@
 char __fastcall DoInteractionWithTopmostZObject(int a1, int a2);
 void OracleDialogue();
 void __fastcall ClickNPCTopic(signed int uMessageParam);
-char * _4B254D_SkillMasteryTeacher(int _this);
+const char * _4B254D_SkillMasteryTeacher(int _this);
 const char *ContractSelectText(int pEventCode);
 void SimpleHouseDialog();
 void CreateButtonInColumn(int a1, unsigned int a2);