diff Player.cpp @ 1620:61ea994a1812

sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped to Player::HasUnderwaterSuitEquipped, sub_43EDB9_get_some_race_sex_relation_2 to ShouldLoadTexturesForRaceAndGender, Player_has_item to Player::HasItem
author Grumpy7
date Sun, 15 Sep 2013 02:20:06 +0200
parents eceabd56f399
children 511cd6dd1048
line wrap: on
line diff
--- a/Player.cpp	Sat Sep 14 19:09:44 2013 +0200
+++ b/Player.cpp	Sun Sep 15 02:20:06 2013 +0200
@@ -7368,98 +7368,49 @@
 //----- (0049387A) --------------------------------------------------------
 int CycleCharacter(bool backwards)
 {
-  signed int result; // eax@1
-  signed int v2; // ecx@2
-  signed int v3; // ecx@8
-
-  result = uActiveCharacter;
-  if ( backwards )
-  {
-    v2 = 0;
-    while ( 1 )
-    {
-      --result;
-      if ( result < 1 )
-        result = 4;
-      if ( !pPlayers[result]->uTimeToRecovery )
-        break;
-      ++v2;
-      if ( v2 >= 4 )
-        return uActiveCharacter;
-    }
-  }
-  else
-  {
-    v3 = 0;
-    while ( 1 )
-    {
-      ++result;
-      if ( result > 4 )
-        result = 1;
-      if ( !pPlayers[result]->uTimeToRecovery )
-        break;
-      ++v3;
-      if ( v3 >= 4 )
-        return uActiveCharacter;
-    }
-  }
-  return result;
-}
+  const int PARTYSIZE = 4;
+  int valToAdd = backwards ? (PARTYSIZE - 2) : 0;
+  int mult = backwards ? -1 : 1;
+
+  for (int i = 0; i < (PARTYSIZE - 1); i++)
+  {
+    int currCharId = ((uActiveCharacter + mult * i + valToAdd) % PARTYSIZE) + 1;
+    if ( pPlayers[currCharId]->uTimeToRecovery == 0 )
+    {
+      return currCharId;
+    }
+  }
+  return uActiveCharacter;
+}
+
 //----- (0043EE77) --------------------------------------------------------
-bool __fastcall sub_43EE77_ProbablyIfUnderwaterSuitIsEquipped(signed int a1)
-{
-  bool result; // eax@0
-  Player *v2; // edx@3
-  int v3; // ecx@3
-  Player **pPlayers; // esi@8
-  //bool item_flag;
-  Player *v6; // edx@9
-
-  //if ( a1 < 1 || a1 > 4 )
-  //{
-    //if ( !a1 )
-    //{
-      //pPlayers = &::pPlayers[1];
-      //v5 = 604;
-      //while ( 1 )
-  Assert ( a1 > 0 && a1 < 5 );
-      for ( uint i = 1; i < 5; ++i )
-      {
-        //item_flag = Player_has_item(604, *pPlayers, 0);
-        if ( !Player_has_item(604, ::pPlayers[i], 0) )
-          return false;
-        //__debugbreak(); // player.cpp(8748): warning C4700: uninitialized local variable 'v6' used
-        //result = ::pPlayers[i]->pEquipment.uArmor;
-        if ( !::pPlayers[i]->pEquipment.uArmor )
-          return false;
-        //result *= 9;
-        if (::pPlayers[i]->pEquippedItems[::pPlayers[i]->pEquipment.uArmor].uItemID != 604 )
-          return false;
-        //++pPlayers;
-        //if ( (signed int)pPlayers >= (signed int)&qword_A750D8 )
-          //return true;
-      }
-      return true;
-    }
+bool Player::HasUnderwaterSuitEquipped() //the original function took the player number as a parameter. if it was 0, the whole party was checked. calls with the parameter 0 have been changed to calls to this for every player
+{
+  if (this->pEquipment.uArmor == 0 || this->pInventoryItemList[this->pEquipment.uArmor].uItemID != 604)
+  {
+    return false;
+  }
+  return true;
+}
 
 //----- (0043EE15) --------------------------------------------------------
-bool __fastcall Player_has_item(unsigned int uItemID, Player *pPlayer, char a3)
+bool Player::HasItem( unsigned int uItemID, char a3 )
 {
   if ( !a3 || pParty->pPickedItem.uItemID != uItemID )
   {
     for ( uint i = 0; i < 126; ++i )
     {
-      if ( pPlayer->pInventoryMatrix[i] > 0 )
+      if ( this->pInventoryMatrix[i] > 0 )
       {
-        if ( (unsigned int)pPlayer->pInventoryItemList[pPlayer->pInventoryMatrix[i] - 1].uItemID == uItemID )
+        if ( (unsigned int)this->pInventoryItemList[this->pInventoryMatrix[i] - 1].uItemID == uItemID )
           return true;
       }
     }
     for ( uint i = 0; i < 16; ++i )
     {
-      if ( pPlayer->pEquipment.pIndices[i] )
+      if ( this->pEquipment.pIndices[i] )
       {
-        if ( (unsigned int)pPlayer->pInventoryItemList[pPlayer->pEquipment.pIndices[i] - 1].uItemID == uItemID )
+        if ( (unsigned int)this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID == uItemID )
           return true;
       }
     }
@@ -7467,64 +7418,36 @@
   return false;
 }
 //----- (0043EDB9) --------------------------------------------------------
-bool  sub_43EDB9_get_some_race_sex_relation_2(unsigned int a1)
-{
-  unsigned int pNum; // ebp@1
-  Player **pPlayer; // ebx@1
-  Player *pPlayer2; // esi@2
-  enum CHARACTER_RACE pRace; // edi@2
-  bool pSex; // eax@2
-  char v6; // zf@7
-
-//pPlayer = &pPlayers[1];
-  /*pNum = a1;
-  
-  while ( 1 )
-  {
-    pPlayer2 = *pPlayer;
-    pRace = pPlayer2->GetRace();
-    pSex = pPlayer2->GetSexByVoice();
-    if ( !pRace )
-      break;
-    if ( pRace == 1 || pRace == 2 )
-      break;
-    if ( !pSex && pNum == 2 )//
-      //goto LABEL_15;
-    {
-      pSex = 1;
-      return pSex;
-    }
-    v6 = pNum == 3;//
-LABEL_11:
-    if ( v6 )
-      //goto LABEL_15;
-    {
-      pSex = 1;
-      return pSex;
-    }
-    ++pPlayer;
-    if ( (signed int)pPlayer >= (signed int)&qword_A750D8 )//
-    {
-      pSex = 0;
-      return pSex;
-    }
-  }
-  if ( pSex || pNum )
-  {
-    v6 = pNum == 1;
-    goto LABEL_11;
-  }
-//LABEL_15:
-  pSex = 1;
-  return pSex;*/
-  for (uint i = 1; i <= 4; ++i)
-    {
-      pRace = pPlayers[i]->GetRace();
-      pSex = pPlayers[i]->GetSexByVoice();
-      if (pRace == 0 || pRace == 1 || pRace == 2 || pSex == 0 )
-        return 1;
-    }
- return 0;
+bool ShouldLoadTexturesForRaceAndGender(unsigned int _this)
+{
+  CHARACTER_RACE race; // edi@2
+  PLAYER_SEX sex; // eax@2
+
+  for (int i = 1; i <= 4; i++)
+  {
+    race = pPlayers[i]->GetRace();
+    sex = pPlayers[i]->GetSexByVoice();
+    switch(_this)
+    {
+       case 0:
+         if (( race == CHARACTER_RACE_HUMAN || race == CHARACTER_RACE_ELF || race == CHARACTER_RACE_GOBLIN ) && sex == SEX_MALE )
+           return true;
+         break;
+       case 1:
+         if (( race == CHARACTER_RACE_HUMAN || race == CHARACTER_RACE_ELF || race == CHARACTER_RACE_GOBLIN ) && sex == SEX_FEMALE )
+           return true;
+         break;
+       case 2:
+         if ( race == CHARACTER_RACE_DWARF && sex == SEX_MALE )
+           return true;
+         break;
+       case 3:
+         if ( race == CHARACTER_RACE_DWARF && sex == SEX_FEMALE )
+           return true;
+         break;
+    }
+  }
+  return false;
 }
 //----- (0043ED6F) --------------------------------------------------------
 bool _43ED6F_check_party_races(bool a1)