Mercurial > mm7
annotate Chest.cpp @ 1407:d4f57df4c299
PlayerSpeechID and uSpeakingCharacter
author | Ritor1 |
---|---|
date | Tue, 23 Jul 2013 16:34:00 +0600 |
parents | d071e0e9ba75 |
children | 204cce84300b |
rev | line source |
---|---|
1165
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1110
diff
changeset
|
1 #ifdef _MSC_VER |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1110
diff
changeset
|
2 #define _CRT_SECURE_NO_WARNINGS |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1110
diff
changeset
|
3 #endif |
29a8defbad9e
temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents:
1110
diff
changeset
|
4 |
0 | 5 #include <stdio.h> |
426 | 6 #include <assert.h> |
0 | 7 |
1016 | 8 #include "BSPModel.h" |
9 #include "Items.h" | |
0 | 10 #include "Chest.h" |
11 #include "FrameTableInc.h" | |
12 #include "Allocator.h" | |
421 | 13 #include "LOD.h" |
14 #include "MapInfo.h" | |
15 #include "Actor.h" | |
16 #include "Outdoor.h" | |
17 #include "DecorationList.h" | |
18 #include "Party.h" | |
19 #include "AudioPlayer.h" | |
20 #include "Math.h" | |
21 #include "Texts.h" | |
22 #include "ObjectList.h" | |
23 #include "GUIWindow.h" | |
24 #include "Time.h" | |
0 | 25 |
26 #include "mm7_data.h" | |
848 | 27 #include "MM7.h" |
1016 | 28 #include "SpriteObject.h" |
1297 | 29 #include "Mouse.h" |
30 #include "Viewport.h" | |
0 | 31 |
32 size_t uNumChests; // idb | |
33 struct ChestList *pChestList; | |
1202 | 34 std::array<Chest, 20> pChests; |
0 | 35 |
36 | |
528 | 37 const int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42}; |
38 const int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34}; | |
39 const int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; | |
526 | 40 const int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; |
0 | 41 |
42 | |
421 | 43 //----- (0042041E) -------------------------------------------------------- |
526 | 44 bool Chest::Open( signed int uChestID ) |
822 | 45 { |
1406 | 46 unsigned int pMapID; // eax@8 |
47 int pRandom; // edx@16 | |
421 | 48 int v6; // eax@16 |
1406 | 49 ODMFace *pODMFace; // eax@19 |
50 BLVFace *pBLVFace; // eax@20 | |
51 int pObjectX; // ebx@21 | |
52 int pObjectZ; // edi@21 | |
53 double dir_x; // st7@23 | |
54 double dir_y; // st6@23 | |
1407 | 55 double length_vector; // st7@23 |
1406 | 56 int pDepth; // ecx@26 |
57 Vec3_int_ v; // ST4C_12@28 | |
58 bool flag_shout; // edi@28 | |
59 int pSpriteID[4]; // [sp+84h] [bp-40h]@16 | |
421 | 60 Vec3_int_ pOut; // [sp+A0h] [bp-24h]@28 |
1406 | 61 int pObjectY; // [sp+B0h] [bp-14h]@21 |
421 | 62 int sRotX; // [sp+B4h] [bp-10h]@23 |
1406 | 63 float dir_z; // [sp+BCh] [bp-8h]@23 |
421 | 64 int sRotY; // [sp+C0h] [bp-4h]@8 |
1406 | 65 SpriteObject pSpellObject; // [sp+14h] [bp-B0h]@28 |
421 | 66 |
1406 | 67 assert( uChestID < 20 ); |
68 if ( ( uChestID < 0 ) && ( uChestID >= 20 ) ) | |
69 return false; | |
526 | 70 auto chest = &pChests[uChestID]; |
426 | 71 |
421 | 72 ++pIcons_LOD->uTexturePacksCount; |
426 | 73 if (!pIcons_LOD->uNumPrevLoadedFiles) |
421 | 74 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles; |
426 | 75 |
76 if (!chest->Initialized()) | |
526 | 77 Chest::PlaceItems(uChestID); |
426 | 78 |
421 | 79 if ( !uActiveCharacter ) |
1406 | 80 return false; |
81 flag_shout = false; | |
82 pMapID = pMapStats->GetMapInfo(pCurrentMapName.data()); | |
83 if ( chest->Trapped() && pMapID ) | |
421 | 84 { |
1406 | 85 if ( pPlayers[uActiveCharacter]->GetDisarmTrap() < 2 * pMapStats->pInfos[pMapID].LockX5 ) |
421 | 86 { |
1406 | 87 pSpriteID[0] = 811; |
88 pSpriteID[1] = 812; | |
89 pSpriteID[2] = 813; | |
90 pSpriteID[3] = 814; | |
91 pRandom = rand() % 4; | |
92 v6 = PID_ID(EvtTargetObj); | |
93 if ( PID_TYPE(EvtTargetObj) == OBJECT_Decoration) | |
94 { | |
95 pObjectX = pLevelDecorations[v6].vPosition.x; | |
96 pObjectY = pLevelDecorations[v6].vPosition.y; | |
97 pObjectZ = pLevelDecorations[v6].vPosition.z + ( pDecorationList->pDecorations[pLevelDecorations[v6].uDecorationDescID].uDecorationHeight / 2 ); | |
98 } | |
99 if ( PID_TYPE(EvtTargetObj) == OBJECT_BModel) | |
421 | 100 { |
1406 | 101 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor) |
102 { | |
103 pODMFace = &pOutdoor->pBModels[EvtTargetObj >> 9].pFaces[(EvtTargetObj >> 3) & 0x3F]; | |
104 pObjectX = ( pODMFace->pBoundingBox.x1 + pODMFace->pBoundingBox.x2 ) / 2; | |
105 pObjectY = ( pODMFace->pBoundingBox.y1 + pODMFace->pBoundingBox.y2 ) / 2; | |
106 pObjectZ = ( pODMFace->pBoundingBox.z1 + pODMFace->pBoundingBox.z2 ) / 2; | |
107 } | |
108 else//Indoor | |
109 { | |
110 pBLVFace = &pIndoor->pFaces[v6]; | |
111 pObjectX = ( pBLVFace->pBounding.x1 + pBLVFace->pBounding.x2 ) / 2; | |
112 pObjectY = ( pBLVFace->pBounding.y1 + pBLVFace->pBounding.y2 ) / 2; | |
113 pObjectZ = ( pBLVFace->pBounding.z1 + pBLVFace->pBounding.z2 ) / 2; | |
114 } | |
115 } | |
116 dir_x = (double)pParty->vPosition.x - (double)pObjectX; | |
117 dir_y = (double)pParty->vPosition.y - (double)pObjectY; | |
118 dir_z = ( (double)pParty->sEyelevel + (double)pParty->vPosition.z ) - (double)pObjectZ; | |
1407 | 119 length_vector = sqrt( (dir_x * dir_x) + (dir_y * dir_y) + (dir_z * dir_z) ); |
120 if ( length_vector <= 1.0 ) | |
1406 | 121 { |
122 *(float *)&sRotX = 0.0; | |
123 *(float *)&sRotY = 0.0; | |
421 | 124 } |
125 else | |
126 { | |
1406 | 127 sRotY = (signed __int64)sqrt(dir_x * dir_x + dir_y * dir_y); |
128 sRotX = stru_5C6E00->Atan2((signed __int64)dir_x, (signed __int64)dir_y); | |
129 sRotY = stru_5C6E00->Atan2(dir_y * dir_y, (signed __int64)dir_z); | |
421 | 130 } |
1406 | 131 pDepth = 256; |
1407 | 132 if ( length_vector < 256.0 ) |
133 pDepth = (signed __int64)length_vector / 4; | |
1406 | 134 v.x = pObjectX; |
135 v.y = pObjectY; | |
136 v.z = pObjectZ; | |
137 Vec3_int_::Rotate(pDepth, sRotX, sRotY, v, &pOut.x, &pOut.z, &pOut.y); | |
138 sub_42F7EB_DropItemAt(pSpriteID[pRandom], pOut.x, pOut.z, pOut.y, 0, 1, 0, 48, 0); | |
421 | 139 |
1406 | 140 pSpellObject.stru_24.Reset(); |
141 pSpellObject.spell_skill = 0; | |
142 pSpellObject.spell_level = 0; | |
143 pSpellObject.spell_id = 0; | |
144 pSpellObject.field_54 = 0; | |
145 pSpellObject.uType = pSpriteID[pRandom]; | |
146 pSpellObject.uObjectDescID = 0; | |
147 if ( pObjectList->uNumObjects ) | |
421 | 148 { |
1406 | 149 for ( uint i = 0; i < (signed int)pObjectList->uNumObjects; ++i ) |
150 { | |
151 if ( pSpriteID[pRandom] == pObjectList->pObjects[i].uObjectID ) | |
152 pSpellObject.uObjectDescID = i; | |
153 } | |
421 | 154 } |
1406 | 155 pSpellObject.vPosition.y = pOut.z; |
156 pSpellObject.vPosition.x = pOut.x; | |
157 pSpellObject.vPosition.z = pOut.y; | |
158 pSpellObject.uSoundID = 0; | |
159 pSpellObject.uAttributes = 48; | |
160 pSpellObject.uSectorID = pIndoor->GetSector(pOut.x, pOut.z, pOut.y); | |
161 pSpellObject.uSpriteFrameID = 0; | |
162 pSpellObject.spell_caster_pid = 0; | |
163 pSpellObject.spell_target_pid = 0; | |
164 pSpellObject.uFacing = 0; | |
165 pSpellObject.Create(0, 0, 0, 0); | |
166 pAudioPlayer->PlaySound(SOUND_8, 0, 0, -1, 0, 0, 0, 0); | |
167 pSpellObject.ExplosionTraps(); | |
168 chest->uFlags &= 0xFEu; | |
169 if ( uActiveCharacter && !qword_A750D8 && !dword_507CD8 ) | |
170 { | |
171 qword_A750D8 = 256i64; | |
172 PlayerSpeechID = SPEECH_5; | |
1407 | 173 uSpeakingCharacter = uActiveCharacter; |
1406 | 174 } |
175 pIcons_LOD->RemoveTexturesPackFromTextureList(); | |
176 dword_507CD8 = 0; | |
177 return false; | |
421 | 178 } |
1406 | 179 chest->uFlags &= 0xFEu; |
180 flag_shout = true; | |
421 | 181 } |
182 pAudioPlayer->StopChannels(-1, -1); | |
426 | 183 pAudioPlayer->PlaySound(SOUND_OpenChest, 0, 0, -1, 0, 0, 0, 0); |
1406 | 184 if ( flag_shout == true ) |
421 | 185 { |
186 if ( !dword_507CD8 ) | |
187 pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0); | |
188 } | |
189 dword_507CD8 = 0; | |
948 | 190 pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Chest, uChestID, 0); |
1406 | 191 pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit |
192 pChestWindow->CreateButton( 7, 8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0); | |
421 | 193 pCurrentScreen = SCREEN_CHEST; |
194 pEventTimer->Pause(); | |
1406 | 195 return true; |
421 | 196 } |
197 | |
198 //----- (0042092D) -------------------------------------------------------- | |
706 | 199 void Chest::DrawChestUI(signed int uChestID) |
526 | 200 { |
201 | |
202 int chestBitmapId; // eax@1 | |
203 unsigned int v5; // eax@1 | |
204 int chest_item_index; // ecx@3 | |
205 unsigned int item_texture_id; // eax@4 | |
206 Texture *item_texture; // esi@4 | |
207 signed int itemPixelWidth; // ecx@4 | |
208 signed int itemPixelHeght; // edx@4 | |
209 signed int v11; // eax@4 | |
210 int v12; // eax@6 | |
211 int v13; // eax@6 | |
212 unsigned int itemPixelPosX; // ST34_4@8 | |
213 int itemPixelPosY; // edi@8 | |
214 int *v16; // [sp+Ch] [bp-28h]@1 | |
215 int v17; // [sp+10h] [bp-24h]@4 | |
216 int chest_offs_y; // [sp+14h] [bp-20h]@1 | |
217 signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1 | |
218 int chest_offs_x; // [sp+1Ch] [bp-18h]@1 | |
219 signed int chestWidthCells; // [sp+20h] [bp-14h]@1 | |
528 | 220 signed int item_counter; // [sp+30h] [bp-4h]@1 |
421 | 221 |
526 | 222 v16 = pRenderer->pActiveZBuffer; |
223 pRenderer->ClearZBuffer(0, 479); | |
224 chestBitmapId = pChests[uChestID].uChestBitmapID; | |
225 chest_offs_x = pChestPixelOffsetX[chestBitmapId]; | |
226 chest_offs_y = pChestPixelOffsetY[chestBitmapId]; | |
227 chestWidthCells = pChestWidthsByType[chestBitmapId]; | |
228 chestHeghtCells = pChestHeightsByType[chestBitmapId]; | |
1394 | 229 sprintfex(pTmpBuf.data(), "chest%02d", pChestList->pChests[chestBitmapId].uTextureID); |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
230 v5 = pIcons_LOD->LoadTexture(pTmpBuf.data(), TEXTURE_16BIT_PALETTE); |
945 | 231 pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5)); |
526 | 232 |
1394 | 233 for (item_counter = 0; item_counter < chestWidthCells * chestHeghtCells; ++item_counter) |
526 | 234 { |
528 | 235 chest_item_index = pChests[uChestID].pInventoryIndices[item_counter]; |
526 | 236 if ( chest_item_index > 0 ) |
237 { | |
238 item_texture_id = pIcons_LOD->LoadTexture( | |
239 //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName, | |
1394 | 240 pItemsTable->pItems[pChests[uChestID].igChestItems[chest_item_index - 1].uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 241 item_texture = pIcons_LOD->GetTexture(item_texture_id); |
242 itemPixelWidth = item_texture->uTextureWidth; | |
243 itemPixelHeght = item_texture->uTextureHeight; | |
526 | 244 if ( itemPixelWidth < 14 ) |
245 itemPixelWidth = 14; | |
246 v12 = itemPixelWidth - 14; | |
247 v12 = v12 & 0xFFFFFFE0; | |
248 v13 = v12 + 32; | |
249 if ( itemPixelHeght < 14 ) | |
250 itemPixelHeght = 14; | |
600 | 251 itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth)/2); |
528 | 252 itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) + |
600 | 253 ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32- item_texture->uTextureHeight ) /2); |
526 | 254 pRenderer->DrawTextureTransparent( itemPixelPosX, itemPixelPosY, item_texture); |
528 | 255 sub_40F92A(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1); |
526 | 256 } |
257 } | |
945 | 258 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId)); |
421 | 259 } |
260 | |
261 | |
262 //----- (0041FE71) -------------------------------------------------------- | |
706 | 263 bool Chest::CanPlaceItemAt( signed int test_cell_position, int item_id, signed int uChestID ) |
526 | 264 { |
265 int v3; // eax@1 | |
266 unsigned int item_texture_id; // eax@1 | |
267 Texture *item_texture; // ecx@1 | |
268 signed int v6; // eax@1 | |
269 signed int v7; // edi@3 | |
270 signed int v8; // eax@3 | |
271 int texture_cell_width; // edi@3 | |
272 int texture_cell_height; // ebx@5 | |
273 int _row; // esi@9 | |
274 int _cell_rows; // edx@10 | |
275 int _column; // ecx@11 | |
276 char *v14; // eax@12 | |
277 int chest_cell_heght; // [sp+Ch] [bp-Ch]@1 | |
278 signed int v17; // [sp+10h] [bp-8h]@1 | |
279 signed int chest_cell_width; // [sp+14h] [bp-4h]@1 | |
280 | |
281 chest_cell_heght = pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
282 chest_cell_width = pChestWidthsByType[pChests[uChestID].uChestBitmapID]; | |
283 item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE); | |
945 | 284 item_texture = pIcons_LOD->GetTexture(item_texture_id); |
285 v6 = item_texture->uTextureWidth; | |
526 | 286 if ( v6 < 14 ) |
287 v6 = 14; | |
1110 | 288 texture_cell_width = ((v6 - 14) >> 5) + 1; |
526 | 289 v8 = item_texture->uTextureHeight; |
290 if ( v8 < 14 ) | |
291 v8 = 14; | |
292 texture_cell_height = ((v8 - 14) >> 5) + 1; | |
293 if ( !areWeLoadingTexture ) | |
294 { | |
295 item_texture->Release(); | |
1006 | 296 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 297 } |
298 if ( (texture_cell_width + test_cell_position % chest_cell_width <= chest_cell_width) && | |
299 (texture_cell_height + test_cell_position / chest_cell_width <= chest_cell_heght) ) | |
300 { //we not put over borders | |
301 _row = 0; | |
302 if ( texture_cell_height <= 0 ) | |
303 return true; | |
304 _cell_rows = 0; | |
305 while ( 1 ) | |
306 { | |
307 _column = 0; | |
308 if ( texture_cell_width > 0 ) | |
309 { | |
528 | 310 while ( pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]==0) |
526 | 311 { |
312 ++_column; | |
313 if ( _column >= texture_cell_width ) | |
314 break; | |
315 } | |
528 | 316 if (pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]!=0) |
317 return false; | |
526 | 318 } |
319 _cell_rows += chest_cell_width; | |
320 ++_row; | |
321 if ( _row >= texture_cell_height ) | |
322 return true; | |
323 } | |
324 | |
325 } | |
326 return false; | |
421 | 327 } |
328 // 506128: using guessed type int areWeLoadingTexture; | |
329 | |
330 //----- (0041FF64) -------------------------------------------------------- | |
706 | 331 int Chest::CountChestItems(signed int uChestID) |
421 | 332 { |
526 | 333 signed int item_count; // eax@1 |
334 int max_items; // edx@1 | |
335 item_count = 0; | |
336 max_items = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
337 if ( max_items <= 0 ) | |
421 | 338 { |
526 | 339 item_count = -1; |
421 | 340 } |
341 else | |
342 { | |
526 | 343 while ( pChests[uChestID].igChestItems[item_count].uItemID ) |
421 | 344 { |
526 | 345 ++item_count; |
346 if ( item_count >= max_items ) | |
347 { | |
348 item_count = -1; | |
349 break; | |
350 } | |
421 | 351 } |
352 } | |
526 | 353 return item_count; |
421 | 354 } |
355 | |
356 //----- (0041FFA2) -------------------------------------------------------- | |
706 | 357 int Chest::PutItemInChest(int position, ItemGen *put_item, signed int uChestID) |
421 | 358 { |
359 int v3; // eax@1 | |
360 ItemGen *v4; // edi@1 | |
361 int v5; // esi@1 | |
362 int result; // eax@11 | |
363 unsigned int v7; // eax@12 | |
364 int v8; // edx@12 | |
945 | 365 Texture *v9; // ecx@12 |
421 | 366 signed int v10; // eax@12 |
367 signed int v11; // edi@14 | |
368 unsigned int v12; // esi@14 | |
369 int v13; // edi@16 | |
370 void *v14; // edi@21 | |
371 int v15; // edi@21 | |
372 int i; // ecx@21 | |
373 ItemGen *Src; // [sp+Ch] [bp-18h]@1 | |
526 | 374 signed int item_in_chest_count; // [sp+10h] [bp-14h]@2 |
421 | 375 int v19; // [sp+14h] [bp-10h]@1 |
376 int v20; // [sp+18h] [bp-Ch]@19 | |
377 signed int v21; // [sp+1Ch] [bp-8h]@1 | |
378 signed int v22; // [sp+20h] [bp-4h]@3 | |
379 int v23; // [sp+20h] [bp-4h]@19 | |
380 | |
381 v21 = 0; | |
382 v3 = pChests[uChestID].uChestBitmapID; | |
526 | 383 v4 = put_item; |
421 | 384 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3]; |
526 | 385 Src = put_item; |
421 | 386 v19 = pChestWidthsByType[v3]; |
526 | 387 if ( position == -1 ) |
421 | 388 { |
526 | 389 item_in_chest_count = CountChestItems(uChestID); |
390 if ( item_in_chest_count == -1 ) | |
421 | 391 return 0; |
392 v22 = 0; | |
393 if ( v5 > 0 ) | |
394 { | |
526 | 395 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, pChestWindow->par1C) ) |
421 | 396 { |
397 ++v22; | |
398 if ( v22 >= v5 ) | |
399 goto LABEL_8; | |
400 } | |
401 v21 = v22; | |
402 } | |
403 LABEL_8: | |
404 if ( v22 == v5 ) | |
405 { | |
406 if ( uActiveCharacter ) | |
407 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); | |
408 return 0; | |
409 } | |
410 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v4->uItemID].pIconName, TEXTURE_16BIT_PALETTE); | |
411 HIWORD(v8) = 0; | |
945 | 412 v9 = pIcons_LOD->GetTexture(v7); |
413 v10 = v9->uTextureWidth; | |
421 | 414 if ( v10 < 14 ) |
415 v10 = 14; | |
945 | 416 v11 = v9->uTextureHeight; |
421 | 417 v12 = ((v10 - 14) >> 5) + 1; |
418 if ( v11 < 14 ) | |
419 v11 = 14; | |
420 v13 = ((v11 - 14) >> 5) + 1; | |
421 if ( !areWeLoadingTexture ) | |
422 { | |
423 ((Texture *)v9)->Release(); | |
1006 | 424 pIcons_LOD->SyncLoadedFilesCount(); |
421 | 425 } |
426 if ( v13 > 0 ) | |
427 { | |
428 v23 = 0; | |
429 v20 = v13; | |
430 do | |
431 { | |
432 if ( (signed int)v12 > 0 ) | |
433 { | |
526 | 434 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23]; |
421 | 435 LOWORD(v8) = -1 - v21; |
436 v8 <<= 16; | |
437 LOWORD(v8) = -1 - v21; | |
438 memset32(v14, v8, v12 >> 1); | |
439 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); | |
440 for ( i = v12 & 1; i; --i ) | |
441 { | |
442 *(short *)v15 = v8; | |
443 v15 += 2; | |
444 } | |
445 } | |
446 v23 += v19; | |
447 --v20; | |
448 } | |
449 while ( v20 ); | |
450 } | |
526 | 451 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1; |
452 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen)); | |
421 | 453 result = v21 + 1; |
454 } | |
455 else | |
456 { | |
457 result = 1; | |
458 } | |
459 return result; | |
460 } | |
461 // 506128: using guessed type int areWeLoadingTexture; | |
462 | |
463 //----- (0042013E) -------------------------------------------------------- | |
706 | 464 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, signed int uChestID ) |
526 | 465 { |
528 | 466 int uItemID; // edi@1 |
467 int v6; // edx@4 | |
468 unsigned int v7; // eax@5 | |
469 Texture *v8; // ecx@5 | |
470 signed int v9; // eax@5 | |
471 signed int v10; // edi@7 | |
472 unsigned int texture_cell_width; // ebx@7 | |
473 int textute_cell_height; // edi@9 | |
474 int chest_cell_row_pos; // edx@12 | |
475 int chest_cell_width; // [sp+10h] [bp-Ch]@11 | |
421 | 476 |
528 | 477 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID; |
478 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]); | |
479 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges) | |
421 | 480 { |
528 | 481 v6 = rand() % 21 + 10; |
482 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6; | |
483 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6; | |
421 | 484 } |
528 | 485 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 486 v8 = pIcons_LOD->GetTexture(v7); |
487 v9 = v8->uTextureWidth; | |
528 | 488 if ( v9 < 14 ) |
489 v9 = 14; | |
490 v10 = v8->uTextureHeight; | |
491 texture_cell_width = ((v9 - 14) >> 5) + 1; | |
492 if ( v10 < 14 ) | |
493 v10 = 14; | |
494 textute_cell_height = ((v10 - 14) >> 5) + 1; | |
495 if ( !areWeLoadingTexture ) | |
496 { | |
497 v8->Release(); | |
1006 | 498 pIcons_LOD->SyncLoadedFilesCount(); |
528 | 499 } |
500 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; | |
501 chest_cell_row_pos = 0; | |
502 for(int i=0; i<textute_cell_height; ++i) | |
503 { | |
504 for (int j=0; j<texture_cell_width; ++j) | |
505 { | |
506 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1); | |
507 } | |
508 chest_cell_row_pos += chest_cell_width; | |
509 } | |
510 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1; | |
421 | 511 } |
512 // 506128: using guessed type int areWeLoadingTexture; | |
513 | |
514 //----- (00420284) -------------------------------------------------------- | |
706 | 515 void Chest::PlaceItems(signed int uChestID ) |
421 | 516 { |
526 | 517 int uChestArea; // edi@1 |
518 int random_chest_pos; // eax@2 | |
519 int test_position; // ebx@11 | |
520 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 | |
521 int chest_item_id; // [sp+9Ch] [bp-10h]@10 | |
528 | 522 unsigned int items_counter; // [sp+A4h] [bp-8h]@8 |
526 | 523 |
524 pRenderer->ClearZBuffer(0, 479); | |
525 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
526 memset(chest_cells_map, 0, 144); | |
527 //fill cell map at random positions | |
608 | 528 for ( items_counter = 0; items_counter < uChestArea; ++items_counter ) |
529 { | |
526 | 530 //get random position in chest |
531 do | |
532 random_chest_pos = (unsigned __int8)rand(); | |
533 while ( random_chest_pos >= uChestArea ); | |
534 //if this pos occupied move to next | |
535 while ( chest_cells_map[random_chest_pos] ) | |
608 | 536 { |
526 | 537 ++random_chest_pos; |
538 if ( random_chest_pos == uChestArea ) | |
539 random_chest_pos = 0; | |
608 | 540 } |
528 | 541 chest_cells_map[random_chest_pos] = items_counter; |
608 | 542 } |
528 | 543 items_counter = 0; |
526 | 544 |
528 | 545 for (items_counter = 0; items_counter<uChestArea; ++items_counter) |
526 | 546 { |
528 | 547 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID; |
526 | 548 if ( chest_item_id ) |
549 { | |
550 test_position = 0; | |
551 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) | |
552 { | |
553 ++test_position; | |
554 if ( test_position >= uChestArea ) | |
555 break; | |
556 } | |
557 if(test_position<uChestArea) | |
558 { | |
528 | 559 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID); |
592 | 560 if ( pChests[uChestID].uFlags & CHEST_OPENED) |
528 | 561 pChests[uChestID].igChestItems[items_counter].SetIdentified(); |
526 | 562 } |
563 } | |
564 } | |
528 | 565 pChests[uChestID].SetInitialized(true); |
421 | 566 } |
567 // 420284: using guessed type char Dst[144]; | |
568 | |
706 | 569 //----- (00448A17) -------------------------------------------------------- |
570 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle) | |
571 { | |
572 unsigned __int16 *pFlags; // eax@3 | |
573 | |
574 if ( uChestID >= 0 && uChestID <= 19 ) | |
575 { | |
576 pFlags = &pChests[uChestID].uFlags; | |
577 if ( bToggle ) | |
578 *pFlags |= uFlag; | |
579 else | |
580 *pFlags &= ~uFlag; | |
581 } | |
582 } | |
583 | |
0 | 584 //----- (00458B03) -------------------------------------------------------- |
585 void ChestList::ToFile() | |
586 { | |
587 ChestList *v1; // esi@1 | |
588 FILE *v2; // eax@1 | |
589 FILE *v3; // edi@1 | |
590 | |
591 v1 = this; | |
592 v2 = fopen("data\\dchest.bin", "wb"); | |
593 v3 = v2; | |
594 if ( !v2 ) | |
595 Abortf("Unable to save dchest.bin!"); | |
596 fwrite(v1, 4u, 1u, v2); | |
597 fwrite(v1->pChests, 0x24u, v1->uNumChests, v3); | |
598 fclose(v3); | |
599 } | |
600 | |
601 | |
602 //----- (00458B4F) -------------------------------------------------------- | |
603 void ChestList::FromFile(void *pSerialized) | |
604 { | |
605 uNumChests = *(int *)pSerialized; | |
606 pChests = (ChestDesc *)pAllocator->AllocNamedChunk(pChests, 36 * uNumChests, "Chest Descrip"); | |
607 memcpy(pChests, (char *)pSerialized + 4, 36 * uNumChests); | |
608 } | |
609 | |
610 | |
611 //----- (00458B9C) -------------------------------------------------------- | |
612 int ChestList::FromFileTxt(const char *Args) | |
613 { | |
614 ChestList *v2; // ebx@1 | |
615 __int32 v3; // edi@1 | |
616 FILE *v4; // eax@1 | |
617 unsigned int v5; // esi@3 | |
618 const void *v6; // ST18_4@9 | |
619 void *v7; // eax@9 | |
620 FILE *v8; // ST0C_4@11 | |
621 char *i; // eax@11 | |
622 char v10; // al@14 | |
623 const char *v11; // ST14_4@14 | |
624 char v12; // al@14 | |
625 const char *v13; // ST10_4@14 | |
626 char Buf; // [sp+8h] [bp-2F0h]@3 | |
627 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4 | |
628 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4 | |
629 FILE *File; // [sp+2F4h] [bp-4h]@1 | |
630 unsigned int Argsa; // [sp+300h] [bp+8h]@3 | |
631 | |
632 v2 = this; | |
633 pAllocator->FreeChunk(this->pChests); | |
634 v3 = 0; | |
635 v2->pChests = 0; | |
636 v2->uNumChests = 0; | |
637 v4 = fopen(Args, "r"); | |
638 File = v4; | |
639 if ( !v4 ) | |
640 Abortf("ChestDescriptionList::load - Unable to open file: %s."); | |
641 v5 = 0; | |
642 Argsa = 0; | |
643 if ( fgets(&Buf, 490, v4) ) | |
644 { | |
645 do | |
646 { | |
647 *strchr(&Buf, 10) = 0; | |
703 | 648 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 649 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 650 ++Argsa; |
651 } | |
652 while ( fgets(&Buf, 490, File) ); | |
653 v5 = Argsa; | |
654 v3 = 0; | |
655 } | |
656 v6 = v2->pChests; | |
657 v2->uNumChests = v5; | |
658 v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip"); | |
659 v2->pChests = (ChestDesc *)v7; | |
660 if ( v7 == (void *)v3 ) | |
661 Abortf("ChestDescriptionList::load - Out of Memory!"); | |
662 memset(v7, v3, 36 * v2->uNumChests); | |
663 v8 = File; | |
664 v2->uNumChests = v3; | |
665 fseek(v8, v3, v3); | |
666 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
667 { | |
668 *strchr(&Buf, 10) = 0; | |
703 | 669 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 670 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 671 { |
672 strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]); | |
673 v10 = atoi(v17.pProperties[1]); | |
674 v11 = v17.pProperties[2]; | |
675 v2->pChests[v2->uNumChests].uWidth = v10; | |
676 v12 = atoi(v11); | |
677 v13 = v17.pProperties[3]; | |
678 v2->pChests[v2->uNumChests].uHeight = v12; | |
679 v2->pChests[v2->uNumChests++].uTextureID = atoi(v13); | |
680 } | |
681 } | |
682 fclose(File); | |
683 return 1; | |
684 } | |
526 | 685 |
686 //----- (00420B13) -------------------------------------------------------- | |
687 void __fastcall sub_420B13(int a1, int a2) | |
702 | 688 { |
526 | 689 void *v2; // eax@1 |
690 ItemGen *v3; // ebx@1 | |
691 unsigned int v4; // eax@1 | |
692 Texture *v5; // ecx@1 | |
693 signed int v6; // eax@1 | |
694 signed int v7; // edi@3 | |
695 signed int v8; // eax@3 | |
696 int v9; // edi@3 | |
697 int v10; // eax@5 | |
698 int v11; // esi@8 | |
699 unsigned int v12; // ecx@10 | |
700 void *v13; // edi@10 | |
701 unsigned __int8 v14; // cf@10 | |
702 int v15; // edi@10 | |
703 int i; // ecx@10 | |
704 int v17; // [sp+Ch] [bp-14h]@1 | |
705 int v18; // [sp+10h] [bp-10h]@3 | |
706 int v19; // [sp+14h] [bp-Ch]@1 | |
702 | 707 int v20; // [sp+18h] [bp-8h]@1 |
526 | 708 int v21; // [sp+1Ch] [bp-4h]@5 |
709 int v22; // [sp+1Ch] [bp-4h]@8 | |
710 | |
711 v19 = a2; | |
712 v2 = pChestWindow->ptr_1C; | |
702 | 713 v20 = (int)v2; |
526 | 714 v2 = (void *)(5324 * (int)v2); |
702 | 715 //v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4)); |
716 v3 = &pChests[v20].igChestItems[a1]; | |
717 //v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)]; | |
718 v17 = pChestWidthsByType[pChests[v20].uChestBitmapID]; | |
526 | 719 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v3->uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 720 v5 = pIcons_LOD->GetTexture(v4); |
721 v6 = v5->uTextureWidth; | |
526 | 722 if ( v6 < 14 ) |
723 v6 = 14; | |
724 v7 = v6 - 14; | |
725 v8 = v5->uTextureHeight; | |
726 v9 = (v7 >> 5) + 1; | |
727 v18 = v9; | |
728 if ( v8 < 14 ) | |
729 v8 = 14; | |
730 v10 = ((v8 - 14) >> 5) + 1; | |
731 v21 = v10; | |
732 if ( !areWeLoadingTexture ) | |
702 | 733 { |
526 | 734 v5->Release(); |
1006 | 735 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 736 v10 = v21; |
702 | 737 } |
526 | 738 if ( v10 > 0 ) |
702 | 739 { |
526 | 740 v11 = 0; |
741 v22 = v10; | |
742 do | |
702 | 743 { |
526 | 744 if ( v9 > 0 ) |
702 | 745 { |
526 | 746 v12 = v9; |
702 | 747 //v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20]; |
748 v13 = &pChests[v20].pInventoryIndices[v19 + v11]; | |
526 | 749 v14 = v12 & 1; |
750 v12 >>= 1; | |
751 memset(v13, 0, 4 * v12); | |
752 v15 = (int)((char *)v13 + 4 * v12); | |
753 for ( i = v14; i; --i ) | |
702 | 754 { |
526 | 755 *(short *)v15 = 0; |
756 v15 += 2; | |
702 | 757 } |
526 | 758 v9 = v18; |
702 | 759 } |
526 | 760 v11 += v17; |
761 --v22; | |
762 } | |
702 | 763 while ( v22 ); |
526 | 764 } |
702 | 765 v3->Reset(); |
766 } | |
526 | 767 // 506128: using guessed type int areWeLoadingTexture; |
1297 | 768 //----- (00420E01) -------------------------------------------------------- |
769 void __cdecl OnChestLeftClick() | |
770 { | |
771 int chest_id; // edi@1 | |
772 POINT *v1; // esi@2 | |
773 int v2; // eax@2 | |
774 int v3; // ebx@4 | |
775 int v4; // esi@6 | |
776 int v5; // ecx@6 | |
777 //SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
778 POINT v7; // [sp+7Ch] [bp-10h]@2 | |
779 POINT a2; // [sp+84h] [bp-8h]@2 | |
780 | |
781 SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
782 //SpriteObject::SpriteObject(&v6); | |
783 | |
784 chest_id = pGUIWindow_CurrentMenu->par1C; | |
785 if ( pParty->pPickedItem.uItemID ) | |
786 { | |
787 if ( Chest::PutItemInChest(-1, &pParty->pPickedItem, pGUIWindow_CurrentMenu->par1C) ) | |
788 pMouse->RemoveHoldingItem(); | |
789 } | |
790 else | |
791 { | |
792 v1 = pMouse->GetCursorPos(&a2); | |
793 v2 = pRenderer->pActiveZBuffer[v1->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v7)->y]] & 0xFFFF; | |
794 if ( v2 ) | |
795 { | |
796 if ( v2 ) | |
797 v3 = v2 - 1; | |
798 else | |
799 v3 = -1; | |
800 v4 = pChests[chest_id].pInventoryIndices[v3] - 1; | |
801 if ( pItemsTable->pItems[pChests[chest_id].igChestItems[v4].uItemID].uEquipType == EQUIP_GOLD ) | |
802 { | |
803 party_finds_gold(pChests[chest_id].igChestItems[v4].uSpecEnchantmentType, 0); | |
804 viewparams->bRedrawGameUI = 1; | |
805 } | |
806 else | |
807 { | |
808 pParty->SetHoldingItem(&pChests[chest_id].igChestItems[v4]); | |
809 } | |
810 sub_420B13(v4, v3); | |
811 } | |
812 } | |
813 } |