Mercurial > mm7
comparison Player.cpp @ 1365:b691c96d8e06
Player::FindFreeInventorySlot and Player::CreateItemInInventory refactoring
author | Grumpy7 |
---|---|
date | Mon, 15 Jul 2013 02:34:52 +0200 |
parents | fd661c9e7f97 |
children | 8f339c3bbdaf |
comparison
equal
deleted
inserted
replaced
1364:9014784ae84f | 1365:b691c96d8e06 |
---|---|
821 return 1; | 821 return 1; |
822 } | 822 } |
823 if ( (slotWidth + uSlot % INVETORYSLOTSWIDTH) <= INVETORYSLOTSWIDTH && (slotHeight + uSlot / INVETORYSLOTSWIDTH) <= INVETORYSLOTSHEIGHT ) | 823 if ( (slotWidth + uSlot % INVETORYSLOTSWIDTH) <= INVETORYSLOTSWIDTH && (slotHeight + uSlot / INVETORYSLOTSWIDTH) <= INVETORYSLOTSHEIGHT ) |
824 { | 824 { |
825 int startOfInnerLoop = uSlot; | 825 int startOfInnerLoop = uSlot; |
826 for (int y = 0; y < slotHeight; y++) | 826 for (unsigned int y = 0; y < slotHeight; y++) |
827 { | 827 { |
828 int innerLoopPos = startOfInnerLoop; | 828 int innerLoopPos = startOfInnerLoop; |
829 for (int x = 0; x < slotWidth; x++) | 829 for (unsigned int x = 0; x < slotWidth; x++) |
830 { | 830 { |
831 if (pInventoryIndices[innerLoopPos] != 0) | 831 if (pInventoryIndices[innerLoopPos] != 0) |
832 { | 832 { |
833 return false; | 833 return false; |
834 } | 834 } |
841 return false; | 841 return false; |
842 } | 842 } |
843 // 506128: using guessed type int areWeLoadingTexture; | 843 // 506128: using guessed type int areWeLoadingTexture; |
844 | 844 |
845 //----- (004925E6) -------------------------------------------------------- | 845 //----- (004925E6) -------------------------------------------------------- |
846 unsigned int Player::FindFreeInventorySlot() | 846 int Player::FindFreeInventorySlot() |
847 { | 847 { |
848 unsigned int result; // eax@1 | 848 for (int i = 0; i < 126; i++ ) |
849 ItemGen *v2; // ecx@1 | 849 { |
850 | 850 if (pInventoryItems[i].uItemID == 0) |
851 result = 0; | 851 { |
852 v2 = this->pInventoryItems; | 852 return i; |
853 while ( v2->uItemID ) | 853 } |
854 { | 854 } |
855 ++result; | 855 return -1; |
856 ++v2; | |
857 if ( (signed int)result >= 126 ) | |
858 return -1; | |
859 } | |
860 return result; | |
861 } | 856 } |
862 | 857 |
863 //----- (00492600) -------------------------------------------------------- | 858 //----- (00492600) -------------------------------------------------------- |
864 int Player::CreateItemInInventory(unsigned int uSlot, unsigned int uItemID) | 859 int Player::CreateItemInInventory(unsigned int uSlot, unsigned int uItemID) |
865 { | 860 { |
866 signed int v3; // edx@1 | |
867 ItemGen *v4; // eax@1 | |
868 int result; // eax@8 | 861 int result; // eax@8 |
869 unsigned int v6; // ebx@10 | 862 Texture *texturePtr; // esi@10 |
870 //unsigned int v7; // eax@10 | 863 int *v9; // esi@13 |
871 Texture *v8; // esi@10 | 864 unsigned int widthInSlots; // [sp+0h] [bp-Ch]@10 |
872 void *v9; // esi@13 | 865 signed int freeSlot; // [sp+8h] [bp-4h]@4 |
873 unsigned int v10; // [sp+0h] [bp-Ch]@10 | 866 unsigned int heightInSlots; // [sp+18h] [bp+Ch]@10 |
874 Player *v11; // [sp+4h] [bp-8h]@1 | 867 |
875 signed int v12; // [sp+8h] [bp-4h]@4 | 868 freeSlot = FindFreeInventorySlot(); |
876 unsigned int uItemIDa; // [sp+18h] [bp+Ch]@10 | 869 if ( freeSlot == -1 ) |
877 | |
878 v11 = this; | |
879 v3 = 0; | |
880 v4 = this->pInventoryItems; | |
881 while ( v4->uItemID ) | |
882 { | |
883 ++v3; | |
884 ++v4; | |
885 if ( v3 >= 126 ) | |
886 { | |
887 v12 = -1; | |
888 goto LABEL_5; | |
889 } | |
890 } | |
891 v12 = v3; | |
892 LABEL_5: | |
893 if ( v12 == -1 ) | |
894 { | 870 { |
895 if ( uActiveCharacter ) | 871 if ( uActiveCharacter ) |
896 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); | 872 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); |
897 result = 0; | 873 result = -1; |
898 } | 874 } |
899 else | 875 else |
900 { | 876 { |
901 v6 = uItemID; | 877 texturePtr = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
902 v8 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); | 878 widthInSlots = GetSizeInInventorySlots(texturePtr->uTextureWidth); |
903 v10 = GetSizeInInventorySlots(v8->uTextureWidth); | 879 heightInSlots = GetSizeInInventorySlots(texturePtr->uTextureHeight); |
904 uItemIDa = GetSizeInInventorySlots(v8->uTextureHeight); | |
905 if ( !areWeLoadingTexture ) | 880 if ( !areWeLoadingTexture ) |
906 { | 881 { |
907 v8->Release(); | 882 texturePtr->Release(); |
908 pIcons_LOD->SyncLoadedFilesCount(); | 883 pIcons_LOD->SyncLoadedFilesCount(); |
909 } | 884 } |
910 if ( (signed int)uItemIDa > 0 ) | 885 if (widthInSlots > 0) |
911 { | 886 { |
912 v9 = &v11->pInventoryIndices[uSlot]; | 887 v9 = &this->pInventoryIndices[uSlot]; |
913 do | 888 for (unsigned int i = 0; i < heightInSlots; i++) |
914 { | 889 { |
915 if ( (signed int)v10 > 0 ) | 890 memset32(v9, -1 - uSlot, widthInSlots); //TODO: try to come up with a better solution. negative values are used when drawing the inventory - nothing is drawn |
916 memset32(v9, -1 - uSlot, v10); | 891 v9 += INVETORYSLOTSWIDTH; |
917 v9 = (char *)v9 + 56; | 892 } |
918 --uItemIDa; | 893 } |
919 } | 894 result = freeSlot + 1; |
920 while ( uItemIDa ); | 895 this->pInventoryIndices[uSlot] = freeSlot + 1; |
921 } | 896 this->pInventoryItems[freeSlot].uItemID = uItemID; |
922 result = v12 + 1; | |
923 v11->pInventoryIndices[uSlot] = v12 + 1; | |
924 v11->pInventoryItems[v12].uItemID = v6; | |
925 } | 897 } |
926 return result; | 898 return result; |
927 } | 899 } |
928 // 506128: using guessed type int areWeLoadingTexture; | 900 // 506128: using guessed type int areWeLoadingTexture; |
929 | 901 |
8893 int v2; // ebx@1 | 8865 int v2; // ebx@1 |
8894 Player *v3; // eax@1 | 8866 Player *v3; // eax@1 |
8895 int v4; // edx@1 | 8867 int v4; // edx@1 |
8896 int v5; // esi@2 | 8868 int v5; // esi@2 |
8897 //int v6; // eax@2 | 8869 //int v6; // eax@2 |
8898 unsigned int v7; // eax@3 | 8870 int v7; // eax@3 |
8899 ItemGen _this; // [sp+Ch] [bp-30h]@1 | 8871 ItemGen _this; // [sp+Ch] [bp-30h]@1 |
8900 //Player *v9; // [sp+30h] [bp-Ch]@1 | 8872 //Player *v9; // [sp+30h] [bp-Ch]@1 |
8901 int v10; // [sp+34h] [bp-8h]@1 | 8873 int v10; // [sp+34h] [bp-8h]@1 |
8902 int *v11; // [sp+38h] [bp-4h]@1 | 8874 int *v11; // [sp+38h] [bp-4h]@1 |
8903 | 8875 |