Mercurial > mm7
comparison Player.cpp @ 1383:0a4254e80036
Player::PutItemArInventoryIndex, Player::RemoveItemAtInventoryIndex cleanup, slightly simplified
author | Grumpy7 |
---|---|
date | Tue, 16 Jul 2013 00:40:01 +0200 |
parents | 132a6a0d5cef |
children | b51332ab228f |
comparison
equal
deleted
inserted
replaced
1382:132a6a0d5cef | 1383:0a4254e80036 |
---|---|
893 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); | 893 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); |
894 return 0; | 894 return 0; |
895 } | 895 } |
896 else | 896 else |
897 { | 897 { |
898 texturePtr = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); | 898 PutItemArInventoryIndex(uItemID, freeSlot, uSlot); |
899 widthInSlots = GetSizeInInventorySlots(texturePtr->uTextureWidth); | |
900 heightInSlots = GetSizeInInventorySlots(texturePtr->uTextureHeight); | |
901 if ( !areWeLoadingTexture ) | |
902 { | |
903 texturePtr->Release(); | |
904 pIcons_LOD->SyncLoadedFilesCount(); | |
905 } | |
906 if (widthInSlots > 0) | |
907 { | |
908 v9 = &this->pInventoryIndices[uSlot]; | |
909 for (unsigned int i = 0; i < heightInSlots; i++) | |
910 { | |
911 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 | |
912 v9 += INVETORYSLOTSWIDTH; | |
913 } | |
914 } | |
915 result = freeSlot + 1; | 899 result = freeSlot + 1; |
916 this->pInventoryIndices[uSlot] = freeSlot + 1; | |
917 this->pInventoryItems[freeSlot].uItemID = uItemID; | 900 this->pInventoryItems[freeSlot].uItemID = uItemID; |
918 } | 901 } |
919 return result; | 902 return result; |
920 } | 903 } |
921 // 506128: using guessed type int areWeLoadingTexture; | 904 // 506128: using guessed type int areWeLoadingTexture; |
1023 { | 1006 { |
1024 result = 0; | 1007 result = 0; |
1025 } | 1008 } |
1026 else | 1009 else |
1027 { | 1010 { |
1028 item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[Src->uItemID].pIconName, TEXTURE_16BIT_PALETTE); | 1011 PutItemArInventoryIndex(Src->uItemID, freeSlot, uSlot); |
1029 slot_width = GetSizeInInventorySlots(item_texture->uTextureWidth); | |
1030 slot_height = GetSizeInInventorySlots(item_texture->uTextureHeight); | |
1031 if ( !areWeLoadingTexture ) | |
1032 { | |
1033 item_texture->Release(); | |
1034 pIcons_LOD->SyncLoadedFilesCount(); | |
1035 } | |
1036 | |
1037 if ( slot_width > 0 ) | |
1038 { | |
1039 pInvPos = &pInventoryIndices[uSlot]; | |
1040 for (unsigned int i = 0; i < slot_height; i++) | |
1041 { | |
1042 memset32(pInvPos, -1 - uSlot, slot_width); | |
1043 pInvPos += INVETORYSLOTSWIDTH; | |
1044 } | |
1045 } | |
1046 pInventoryIndices[uSlot] = freeSlot + 1; | |
1047 memcpy(&pInventoryItems[freeSlot], Src, sizeof(ItemGen)); | 1012 memcpy(&pInventoryItems[freeSlot], Src, sizeof(ItemGen)); |
1048 result = freeSlot + 1; | 1013 result = freeSlot + 1; |
1049 } | 1014 } |
1050 return result; | 1015 return result; |
1051 } | 1016 } |
1052 // 506128: using guessed type int areWeLoadingTexture; | 1017 // 506128: using guessed type int areWeLoadingTexture; |
1053 | 1018 |
1054 //----- (0049298B) -------------------------------------------------------- | 1019 //----- (0049298B) -------------------------------------------------------- |
1055 int Player::PutItemArInventoryIndex( ItemGen *item, int item_id, int uSlot ) | 1020 void Player::PutItemArInventoryIndex( int uItemID, int item_id, int uSlot ) |
1056 { | 1021 { |
1057 //Player *v4; // ebx@1 | |
1058 //unsigned int v5; // eax@1 | |
1059 Texture *item_texture; // esi@1 | 1022 Texture *item_texture; // esi@1 |
1060 int *pInvPos; // esi@4 | 1023 int *pInvPos; // esi@4 |
1061 unsigned int slot_width; // [sp+Ch] [bp-4h]@1 | 1024 unsigned int slot_width; // [sp+Ch] [bp-4h]@1 |
1062 unsigned int slot_height; // [sp+18h] [bp+8h]@1 | 1025 unsigned int slot_height; // [sp+18h] [bp+8h]@1 |
1063 | 1026 |
1064 item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[item->uItemID].pIconName, TEXTURE_16BIT_PALETTE); | 1027 item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
1065 slot_width = GetSizeInInventorySlots(item_texture->uTextureWidth); | 1028 slot_width = GetSizeInInventorySlots(item_texture->uTextureWidth); |
1066 slot_height = GetSizeInInventorySlots(item_texture->uTextureHeight); | 1029 slot_height = GetSizeInInventorySlots(item_texture->uTextureHeight); |
1067 if ( !areWeLoadingTexture ) | 1030 if ( !areWeLoadingTexture ) |
1068 { | 1031 { |
1069 item_texture->Release(); | 1032 item_texture->Release(); |
1070 pIcons_LOD->SyncLoadedFilesCount(); | 1033 pIcons_LOD->SyncLoadedFilesCount(); |
1071 } | 1034 } |
1072 if ( (signed int)slot_height > 0 ) | 1035 if ( slot_width > 0 ) |
1073 { | 1036 { |
1074 pInvPos = &pInventoryIndices[uSlot]; //14x9 | 1037 pInvPos = &pInventoryIndices[uSlot]; |
1075 do | 1038 for (unsigned int i = 0; i < slot_height; i++) |
1076 { | 1039 { |
1077 if ( (signed int)slot_width > 0 ) | 1040 memset32(pInvPos, -1 - uSlot, slot_width);//TODO: try to come up with a better solution. negative values are used when drawing the inventory - nothing is drawn |
1078 memset32(pInvPos, -1 - uSlot, slot_width); | 1041 pInvPos += INVETORYSLOTSWIDTH; |
1079 pInvPos +=14; | 1042 } |
1080 --slot_height; | |
1081 } | |
1082 while ( slot_height ); | |
1083 } | 1043 } |
1084 pInventoryIndices[uSlot] = item_id + 1; | 1044 pInventoryIndices[uSlot] = item_id + 1; |
1085 return 1; | |
1086 } | 1045 } |
1087 | 1046 |
1088 // 506128: using guessed type int areWeLoadingTexture; | 1047 // 506128: using guessed type int areWeLoadingTexture; |
1089 | 1048 |
1090 //----- (00492A36) -------------------------------------------------------- | 1049 //----- (00492A36) -------------------------------------------------------- |
1091 void Player::RemoveItemAtInventoryIndex( unsigned int uSlot ) | 1050 void Player::RemoveItemAtInventoryIndex( unsigned int uSlot ) |
1092 { | 1051 { |
1093 | |
1094 ItemGen *item_in_slot; // ecx@1 | 1052 ItemGen *item_in_slot; // ecx@1 |
1095 Texture *item_texture; // esi@1 | 1053 Texture *item_texture; // esi@1 |
1096 unsigned int slot_height; // ebp@1 | 1054 unsigned int slot_height; // ebp@1 |
1097 int *pInvPos; // edx@4 | 1055 int *pInvPos; // edx@4 |
1098 unsigned int slot_width; // [sp+14h] [bp+4h]@1 | 1056 unsigned int slot_width; // [sp+14h] [bp+4h]@1 |
1105 if ( !areWeLoadingTexture ) | 1063 if ( !areWeLoadingTexture ) |
1106 { | 1064 { |
1107 item_texture->Release(); | 1065 item_texture->Release(); |
1108 pIcons_LOD->SyncLoadedFilesCount(); | 1066 pIcons_LOD->SyncLoadedFilesCount(); |
1109 } | 1067 } |
1110 if ( slot_height > 0 ) | 1068 if ( slot_width > 0 ) |
1111 { | 1069 { |
1112 pInvPos = &pInventoryIndices[uSlot]; | 1070 pInvPos = &pInventoryIndices[uSlot]; |
1113 do | 1071 for (unsigned int i = 0; i < slot_height; i++) |
1114 { | 1072 { |
1115 if (slot_width > 0 ) | 1073 memset32(pInvPos, 0, slot_width); |
1116 memset32(pInvPos, 0, slot_width); | 1074 pInvPos += INVETORYSLOTSWIDTH; |
1117 pInvPos += 14; | 1075 } |
1118 --slot_height; | 1076 } |
1119 } | |
1120 while ( slot_height ); | |
1121 } | |
1122 | |
1123 } | 1077 } |
1124 // 506128: using guessed type int areWeLoadingTexture; | 1078 // 506128: using guessed type int areWeLoadingTexture; |
1125 | 1079 |
1126 //identf | 1080 //identf |
1127 //----- (00490EEE) -------------------------------------------------------- | 1081 //----- (00490EEE) -------------------------------------------------------- |
9639 if ( !pX ) | 9593 if ( !pX ) |
9640 { | 9594 { |
9641 pX = v0->AddItem2(0xFFFFFFFFu, &pParty->pPickedItem); | 9595 pX = v0->AddItem2(0xFFFFFFFFu, &pParty->pPickedItem); |
9642 if ( !pX ) | 9596 if ( !pX ) |
9643 { | 9597 { |
9644 v0->PutItemArInventoryIndex(&this_, v13 - 1, a4); | 9598 v0->PutItemArInventoryIndex(this_.uItemID, v13 - 1, a4); |
9645 memcpy((void *)a2.y, &this_, sizeof(ItemGen)); | 9599 memcpy((void *)a2.y, &this_, sizeof(ItemGen)); |
9646 return; | 9600 return; |
9647 } | 9601 } |
9648 } | 9602 } |
9649 v9 = this_.uItemID; | 9603 v9 = this_.uItemID; |