comparison Chest.cpp @ 421:80a5aab68b67

Chest subs moved to Chest.cpp
author Nomad
date Sat, 23 Feb 2013 21:13:50 +0200
parents 9c0607679772
children 94546824edad
comparison
equal deleted inserted replaced
419:ad1e9c0bf6da 421:80a5aab68b67
1 #include <stdio.h> 1 #include <stdio.h>
2 2
3 #include "Chest.h" 3 #include "Chest.h"
4 #include "FrameTableInc.h" 4 #include "FrameTableInc.h"
5 #include "Allocator.h" 5 #include "Allocator.h"
6 #include "LOD.h"
7 #include "MapInfo.h"
8 #include "Actor.h"
9 #include "Indoor.h"
10 #include "Outdoor.h"
11 #include "DecorationList.h"
12 #include "Party.h"
13 #include "AudioPlayer.h"
14 #include "Math.h"
15 #include "Texts.h"
16 #include "ObjectList.h"
17 #include "GUIWindow.h"
18 #include "Time.h"
19 #include "Overlays.h"
6 20
7 #include "mm7_data.h" 21 #include "mm7_data.h"
8 22
9 23
10 24
14 Chest pChests[20]; 28 Chest pChests[20];
15 29
16 30
17 31
18 32
33
34 //----- (0042041E) --------------------------------------------------------
35 bool Chest::Open(unsigned int uChestID)
36 {
37 char *v1; // edi@5
38 unsigned int v2; // eax@8
39 GUIWindow *v3; // eax@15
40 int v5; // edx@16
41 int v6; // eax@16
42 ODMFace *v7; // eax@19
43 int v8; // edx@19
44 int v9; // edi@19
45 signed int v10; // ebx@19
46 int v11; // ecx@19
47 int v12; // eax@19
48 BLVFace *v13; // eax@20
49 int v14; // ebx@21
50 int v15; // edi@21
51 int v16; // ecx@22
52 __int64 v17; // qax@22
53 double v18; // st7@23
54 double v19; // st6@23
55 double v20; // st7@23
56 int v21; // ecx@26
57 char v22[12]; // ST4C_12@28
58 unsigned int *v23; // edi@28
59 unsigned __int16 v24; // di@28
60 signed int v25; // ecx@28
61 char *v26; // edx@29
62 unsigned __int16 v27; // ax@32
63 //LayingItem a1; // [sp+14h] [bp-B0h]@28
64 int v29; // [sp+84h] [bp-40h]@16
65 int v30; // [sp+88h] [bp-3Ch]@16
66 int v31; // [sp+8Ch] [bp-38h]@16
67 int v32; // [sp+90h] [bp-34h]@16
68 float v33; // [sp+94h] [bp-30h]@23
69 char *v34; // [sp+98h] [bp-2Ch]@5
70 int v35; // [sp+9Ch] [bp-28h]@16
71 Vec3_int_ pOut; // [sp+A0h] [bp-24h]@28
72 int a4; // [sp+ACh] [bp-18h]@1
73 int v38; // [sp+B0h] [bp-14h]@21
74 int sRotX; // [sp+B4h] [bp-10h]@23
75 float v40; // [sp+B8h] [bp-Ch]@23
76 float v41; // [sp+BCh] [bp-8h]@23
77 int sRotY; // [sp+C0h] [bp-4h]@8
78
79 a4 = uChestID;
80 if ( (uChestID & 0x80000000u) != 0 || (signed int)uChestID >= 20 )
81 return 0;
82 ++pIcons_LOD->uTexturePacksCount;
83 if ( !pIcons_LOD->uNumPrevLoadedFiles )
84 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
85 v1 = (char *)&pChests[uChestID].uFlags;
86 v34 = v1;
87 if ( !(*v1 & CHEST_ITEMS_PLACED) )
88 Chest::_420284(uChestID);
89 if ( !uActiveCharacter )
90 return 0;
91 *(float *)&sRotY = 0.0;
92 v2 = pMapStats->GetMapInfo(pCurrentMapName);
93 if ( !(*v1 & 1) || !v2 )
94 goto LABEL_12;
95 if ( pPlayers[uActiveCharacter]->GetDisarmTrap() < 2 * pMapStats->pInfos[v2].LockX5 )
96 {
97 v29 = 811;
98 v30 = 812;
99 v31 = 813;
100 v32 = 814;
101 v5 = rand() % 4;
102 v6 = dword_5B5920 >> 3;
103 v35 = v5;
104 if ( (dword_5B5920 & 7) == OBJECT_Decoration)
105 {
106 v16 = v6;
107 v14 = pLevelDecorations[v6].vPosition.x;
108 v38 = pLevelDecorations[v6].vPosition.y;
109 v17 = pDecorationList->pDecorations[pLevelDecorations[v6].uDecorationDescID].uDecorationHeight;
110 v15 = pLevelDecorations[v16].vPosition.z + (((signed int)v17 - HIDWORD(v17)) >> 1);
111 }
112 else
113 {
114 if ( (dword_5B5920 & 7) != OBJECT_BModel)
115 goto LABEL_12;
116 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
117 {
118 v7 = &pOutdoor->pBModels[dword_5B5920 >> 9].pFaces[(dword_5B5920 >> 3) & 0x3F];
119 v8 = v7->pBoundingBox.y1;
120 v9 = v7->pBoundingBox.z2;
121 v10 = v7->pBoundingBox.x1 + v7->pBoundingBox.x2;
122 v11 = v7->pBoundingBox.y2;
123 v12 = v7->pBoundingBox.z1;
124 }
125 else
126 {
127 v13 = &pIndoor->pFaces[v6];
128 v8 = v13->pBounding.y1;
129 v9 = v13->pBounding.z2;
130 v10 = v13->pBounding.x1 + v13->pBounding.x2;
131 v11 = v13->pBounding.y2;
132 v12 = v13->pBounding.z1;
133 }
134 v14 = v10 >> 1;
135 v38 = (v8 + v11) >> 1;
136 v15 = (v12 + v9) >> 1;
137 }
138 v18 = (double)pParty->vPosition.x - (double)v14;
139 *(float *)&a4 = v18;
140 v19 = (double)pParty->vPosition.y - (double)v38;
141 v33 = v19;
142 v41 = (double)pParty->sEyelevel + (double)pParty->vPosition.z - (double)v15;
143 *(float *)&sRotY = v19 * v19;
144 *(float *)&sRotX = v18 * v18;
145 v20 = sqrt(v41 * v41 + *(float *)&sRotX + *(float *)&sRotY);
146 v40 = v20;
147 if ( v20 <= 1.0 )
148 {
149 *(float *)&sRotX = 0.0;
150 *(float *)&sRotY = 0.0;
151 }
152 else
153 {
154 sRotY = (signed __int64)sqrt(*(float *)&sRotX + *(float *)&sRotY);
155 sRotX = stru_5C6E00->Atan2((signed __int64)*(float *)&a4, (signed __int64)v33);
156 sRotY = stru_5C6E00->Atan2(sRotY, (signed __int64)v41);
157 }
158 v21 = 256;
159 if ( v40 < 256.0 )
160 v21 = (signed __int64)v40 / 4;
161 *(int *)&v22[8] = v15;
162 *(_QWORD *)v22 = __PAIR__(v38, v14);
163 Vec3_int_::Rotate(v21, sRotX, sRotY, *(Vec3_int_ *)v22, &pOut.x, &pOut.z, &pOut.y);
164 v23 = (unsigned int *)(&v29 + v35);
165 sub_42F7EB_DropItemAt(*v23, pOut.x, pOut.z, pOut.y, 0, 1, 0, 0x30u, 0);
166
167 LayingItem a1; // [sp+14h] [bp-B0h]@28
168 //LayingItem::LayingItem(&a1);
169
170 a1.stru_24.Reset();
171 v24 = *(short *)v23;
172 v25 = 0;
173 a1.field_50 = 0;
174 a1.field_4C = 0;
175 a1.field_48 = 0;
176 a1.field_54 = 0;
177 a1.uItemType = v24;
178 if ( (signed int)pObjectList->uNumObjects <= 0 )
179 {
180 LABEL_32:
181 v27 = 0;
182 }
183 else
184 {
185 v26 = (char *)&pObjectList->pObjects->uObjectID;
186 while ( v24 != *(short *)v26 )
187 {
188 ++v25;
189 v26 += 56;
190 if ( v25 >= (signed int)pObjectList->uNumObjects )
191 goto LABEL_32;
192 }
193 v27 = v25;
194 }
195 a1.uObjectDescID = v27;
196 a1.vPosition.y = pOut.z;
197 a1.vPosition.x = pOut.x;
198 a1.vPosition.z = pOut.y;
199 a1.uSoundID = 0;
200 a1.uAttributes = 48;
201 a1.uSectorID = pIndoor->GetSector(pOut.x, pOut.z, pOut.y);
202 a1.uSpriteFrameID = 0;
203 a1.field_58_pid = 0;
204 a1.field_5C = 0;
205 a1.uFacing = 0;
206 a1.Create(0, 0, 0, 0);
207 pAudioPlayer->PlaySound(SOUND_8, 0, 0, -1, 0, 0, 0, 0);
208 a1._438E35();
209 *v34 &= 0xFEu;
210 if ( uActiveCharacter && !qword_A750D8 && !dword_507CD8 )
211 {
212 qword_A750D8 = 256i64;
213 word_A750E0 = 5;
214 word_A750E2 = uActiveCharacter;
215 }
216 pIcons_LOD->_4114F2();
217 dword_507CD8 = 0;
218 return 0;
219 }
220 *v1 &= 0xFEu;
221 sRotY = 1;
222 LABEL_12:
223 pAudioPlayer->StopChannels(-1, -1);
224 pAudioPlayer->PlaySound((SoundID)208, 0, 0, -1, 0, 0, 0, 0);
225 if ( *(float *)&sRotY != 0.0 )
226 {
227 if ( !dword_507CD8 )
228 pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0);
229 }
230 dword_507CD8 = 0;
231 v3 = GUIWindow::Create(0, 0, 640u, 480u, WINDOW_Chest, a4, 0);
232 pGUIWindow_CurrentMenu = v3;
233 pChestWindow = v3;
234 pBtn_ExitCancel = v3->CreateButton(
235 0x1D7u,
236 0x1BDu,
237 0xA9u,
238 0x23u,
239 1,
240 0,
241 0x71u,
242 0,
243 0,
244 pGlobalTXT_LocalizationStrings[79],// Exit
245 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0),
246 0);
247 pChestWindow->CreateButton(7u, 8u, 460u, 343u, 1, 0, 0xCu, 0, 0, "", 0);
248 pCurrentScreen = SCREEN_CHEST;
249 pEventTimer->Pause();
250 return 1;
251 }
252
253 //----- (0042092D) --------------------------------------------------------
254 void Chest::DrawChestUI(unsigned int uChestID)
255 {
256 Render *v1; // edi@1
257 unsigned int v2; // ebx@1
258 unsigned int v3; // ebx@1
259 int v4; // eax@1
260 unsigned int v5; // eax@1
261 int v6; // ecx@3
262 unsigned int v7; // eax@4
263 Texture *v8; // esi@4
264 signed int v9; // ecx@4
265 signed int v10; // edx@4
266 signed int v11; // eax@4
267 int v12; // eax@6
268 int v13; // eax@6
269 unsigned int v14; // ST34_4@8
270 int v15; // edi@8
271 int *v16; // [sp+Ch] [bp-28h]@1
272 int v17; // [sp+10h] [bp-24h]@4
273 int v18; // [sp+14h] [bp-20h]@1
274 signed int v19; // [sp+18h] [bp-1Ch]@1
275 int v20; // [sp+1Ch] [bp-18h]@1
276 signed int v21; // [sp+20h] [bp-14h]@1
277 char *v22; // [sp+2Ch] [bp-8h]@2
278 signed int v23; // [sp+30h] [bp-4h]@1
279
280 v1 = pRenderer;
281 v2 = uChestID;
282 v16 = pRenderer->pActiveZBuffer;
283 pRenderer->ClearZBuffer(0, 479);
284 v3 = v2;
285 v4 = pChests[v3].uChestBitmapID;
286 v20 = pChestSmthn1ByType[v4];
287 v18 = pChestSmthn2ByType[v4];
288 v21 = pChestWidthsByType[v4];
289 v19 = pChestHeightsByType[v4];
290 sprintf(pTmpBuf, "chest%02d", pChestList->pChests[pChests[v3].uChestBitmapID].uTextureID);
291 v5 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE);
292 pRenderer->DrawTextureIndexed(8u, 8u, (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0));
293 v23 = 0;
294 if ( v21 * v19 > 0 )
295 {
296 v22 = (char *)pChests[v3].pInventoryIndices;
297 do
298 {
299 v6 = *(short *)v22;
300 if ( v6 > 0 )
301 {
302 v17 = v18 + 32 * v23 / v19;
303 v7 = pIcons_LOD->LoadTexture(
304 pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName,
305 TEXTURE_16BIT_PALETTE);
306 v8 = (Texture *)(v7 != -1 ? &pIcons_LOD->pTextures[v7] : 0);
307 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
308 v10 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureHeight : 26);
309 v11 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
310 if ( v9 < 14 )
311 v11 = 14;
312 v12 = v11 - 14;
313 LOBYTE(v12) = v12 & 0xE0;
314 v13 = v12 + 32;
315 if ( (signed int)v8->uTextureHeight < 14 )
316 v10 = 14;
317 v14 = v20 + 32 * v23 % v21 + ((v13 - v9) >> 1);
318 v15 = v17 + ((((v10 - 14) & 0xFFFFFFE0) - v8->uTextureHeight + 32) >> 1);
319 pRenderer->DrawTextureTransparent(
320 v14,
321 v17 + ((((v10 - 14) & 0xFFFFFFE0) - v8->uTextureHeight + 32) >> 1),
322 v8);
323 sub_40F92A(&v16[v14 + pSRZBufferLineOffsets[v15]], v8, v23 + 1);
324 v1 = pRenderer;
325 }
326 ++v23;
327 v22 += 2;
328 }
329 while ( v23 < v21 * v19 );
330 }
331 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY,
332 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0));
333 }
334
335
336 //----- (0041FE71) --------------------------------------------------------
337 int Chest::CanPlaceItemAt(signed int a1, int a2, unsigned int uChestID)
338 {
339 int v3; // eax@1
340 unsigned int v4; // eax@1
341 Texture *v5; // ecx@1
342 signed int v6; // eax@1
343 signed int v7; // edi@3
344 signed int v8; // eax@3
345 int v9; // edi@3
346 int v10; // ebx@5
347 int v11; // esi@9
348 int v12; // edx@10
349 int v13; // ecx@11
350 char *v14; // eax@12
351 int v16; // [sp+Ch] [bp-Ch]@1
352 signed int v17; // [sp+10h] [bp-8h]@1
353 signed int v18; // [sp+14h] [bp-4h]@1
354
355 v17 = a1;
356 v3 = pChests[uChestID].uChestBitmapID;
357 v16 = pChestHeightsByType[v3];
358 v18 = pChestWidthsByType[v3];
359 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[a2].pIconName, TEXTURE_16BIT_PALETTE);
360 v5 = (Texture *)(v4 != -1 ? (int)&pIcons_LOD->pTextures[v4] : 0);
361 v6 = (v4 != -1 ? pIcons_LOD->pTextures[v4].uTextureWidth : 24);
362 if ( v6 < 14 )
363 v6 = 14;
364 v7 = v6 - 14;
365 v8 = v5->uTextureHeight;
366 v9 = (v7 >> 5) + 1;
367 if ( v8 < 14 )
368 v8 = 14;
369 v10 = ((v8 - 14) >> 5) + 1;
370 if ( !areWeLoadingTexture )
371 {
372 v5->Release();
373 pIcons_LOD->_40F9C5();
374 }
375 if ( v9 + v17 % v18 <= v18 && v10 + v17 / v18 <= v16 )
376 {
377 v11 = 0;
378 if ( v10 <= 0 )
379 return 1;
380 v12 = 0;
381 while ( 1 )
382 {
383 v13 = 0;
384 if ( v9 > 0 )
385 break;
386 LABEL_15:
387 v12 += v18;
388 ++v11;
389 if ( v11 >= v10 )
390 return 1;
391 }
392 v14 = (char *)&pChests[0].pInventoryIndices[v17 + v12 + 2662 * uChestID];
393 while ( !*(short *)v14 )
394 {
395 ++v13;
396 v14 += 2;
397 if ( v13 >= v9 )
398 goto LABEL_15;
399 }
400 }
401 return 0;
402 }
403 // 506128: using guessed type int areWeLoadingTexture;
404
405 //----- (0041FF64) --------------------------------------------------------
406 int Chest::_41FF64(unsigned int uChestID)
407 {
408 unsigned int v1; // ecx@1
409 signed int result; // eax@1
410 int v3; // edx@1
411 ItemGen *pItem; // ecx@2
412
413 v1 = uChestID;
414 result = 0;
415 v3 = pChestWidthsByType[pChests[v1].uChestBitmapID] * pChestHeightsByType[pChests[v1].uChestBitmapID];
416 if ( v3 <= 0 )
417 {
418 LABEL_5:
419 result = -1;
420 }
421 else
422 {
423 pItem = pChests[v1].mm7__vector_pItems;
424 while ( pItem->uItemID )
425 {
426 ++result;
427 ++pItem;
428 if ( result >= v3 )
429 goto LABEL_5;
430 }
431 }
432 return result;
433 }
434
435 //----- (0041FFA2) --------------------------------------------------------
436 int Chest::_41FFA2(int a1, ItemGen *a2, unsigned int uChestID)
437 {
438 int v3; // eax@1
439 ItemGen *v4; // edi@1
440 int v5; // esi@1
441 int result; // eax@11
442 unsigned int v7; // eax@12
443 int v8; // edx@12
444 int v9; // ecx@12
445 signed int v10; // eax@12
446 signed int v11; // edi@14
447 unsigned int v12; // esi@14
448 int v13; // edi@16
449 void *v14; // edi@21
450 int v15; // edi@21
451 int i; // ecx@21
452 ItemGen *Src; // [sp+Ch] [bp-18h]@1
453 signed int v18; // [sp+10h] [bp-14h]@2
454 int v19; // [sp+14h] [bp-10h]@1
455 int v20; // [sp+18h] [bp-Ch]@19
456 signed int v21; // [sp+1Ch] [bp-8h]@1
457 signed int v22; // [sp+20h] [bp-4h]@3
458 int v23; // [sp+20h] [bp-4h]@19
459
460 v21 = 0;
461 v3 = pChests[uChestID].uChestBitmapID;
462 v4 = a2;
463 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3];
464 Src = a2;
465 v19 = pChestWidthsByType[v3];
466 if ( a1 == -1 )
467 {
468 v18 = _41FF64(uChestID);
469 if ( v18 == -1 )
470 return 0;
471 v22 = 0;
472 if ( v5 > 0 )
473 {
474 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, (unsigned int)pChestWindow->ptr_1C) )
475 {
476 ++v22;
477 if ( v22 >= v5 )
478 goto LABEL_8;
479 }
480 v21 = v22;
481 }
482 LABEL_8:
483 if ( v22 == v5 )
484 {
485 if ( uActiveCharacter )
486 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0);
487 return 0;
488 }
489 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v4->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
490 HIWORD(v8) = 0;
491 v9 = v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0;
492 v10 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
493 if ( v10 < 14 )
494 v10 = 14;
495 v11 = *(short *)(v9 + 26);
496 v12 = ((v10 - 14) >> 5) + 1;
497 if ( v11 < 14 )
498 v11 = 14;
499 v13 = ((v11 - 14) >> 5) + 1;
500 if ( !areWeLoadingTexture )
501 {
502 ((Texture *)v9)->Release();
503 pIcons_LOD->_40F9C5();
504 }
505 if ( v13 > 0 )
506 {
507 v23 = 0;
508 v20 = v13;
509 do
510 {
511 if ( (signed int)v12 > 0 )
512 {
513 v14 = &pChests[0].pInventoryIndices[v21 + v23 + 2662 * uChestID];
514 LOWORD(v8) = -1 - v21;
515 v8 <<= 16;
516 LOWORD(v8) = -1 - v21;
517 memset32(v14, v8, v12 >> 1);
518 v15 = (int)((char *)v14 + 4 * (v12 >> 1));
519 for ( i = v12 & 1; i; --i )
520 {
521 *(short *)v15 = v8;
522 v15 += 2;
523 }
524 }
525 v23 += v19;
526 --v20;
527 }
528 while ( v20 );
529 }
530 pChests[0].pInventoryIndices[v21 + 2662 * uChestID] = v18 + 1;
531 memcpy(&pChests[uChestID].mm7__vector_pItems[v18], Src, 0x24u);
532 result = v21 + 1;
533 }
534 else
535 {
536 result = 1;
537 }
538 return result;
539 }
540 // 506128: using guessed type int areWeLoadingTexture;
541
542 //----- (0042013E) --------------------------------------------------------
543 unsigned int Chest::PlaceItemAt(unsigned int a1, unsigned int uItemIdx, unsigned int uChestID)
544 {
545 int v3; // esi@1
546 unsigned int v4; // ebx@1
547 int uItemID; // edi@1
548 int v6; // edx@4
549 unsigned int v7; // eax@5
550 Texture *v8; // ecx@5
551 signed int v9; // eax@5
552 signed int v10; // edi@7
553 unsigned int v11; // ebx@7
554 int v12; // edi@9
555 int v13; // edx@12
556 void *v14; // edi@14
557 int v15; // edi@14
558 int i; // ecx@14
559 unsigned int result; // eax@18
560 __int16 v18; // [sp+Ch] [bp-10h]@1
561 int v19; // [sp+10h] [bp-Ch]@11
562 int v20; // [sp+14h] [bp-8h]@12
563 unsigned int v21; // [sp+18h] [bp-4h]@1
564
565 v3 = 5324 * uChestID;
566 v21 = a1;
567 v4 = 5324 * uChestID + 36 * uItemIdx;
568 v18 = uItemIdx;
569 uItemID = *(unsigned int *)((char *)&pChests[0].mm7__vector_pItems[0].uItemID + v4);
570 pItemsTable->SetSpecialBonus((ItemGen *)((char *)pChests[0].mm7__vector_pItems + v4));
571 if ( uItemID >= 135 && uItemID <= 159 && !*(int *)((char *)&pChests[0].mm7__vector_pItems[0].uNumCharges + v4) )
572 {
573 v6 = rand() % 21 + 10;
574 *(int *)((char *)&pChests[0].mm7__vector_pItems[0].uNumCharges + v4) = v6;
575 *(&pChests[0].mm7__vector_pItems[0].uMaxCharges + v4) = v6;
576 }
577 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
578 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0);
579 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
580 if ( v9 < 14 )
581 v9 = 14;
582 v10 = v8->uTextureHeight;
583 v11 = ((v9 - 14) >> 5) + 1;
584 if ( v10 < 14 )
585 v10 = 14;
586 v12 = ((v10 - 14) >> 5) + 1;
587 if ( !areWeLoadingTexture )
588 {
589 v8->Release();
590 pIcons_LOD->_40F9C5();
591 }
592 v19 = pChestWidthsByType[*(unsigned __int16 *)((char *)&pChests[0].uChestBitmapID + v3)];
593 if ( v12 > 0 )
594 {
595 v13 = 0;
596 v20 = v12;
597 do
598 {
599 if ( (signed int)v11 > 0 )
600 {
601 v14 = &pChests[0].pInventoryIndices[v21 + v13 + 2662 * uChestID];
602 LOWORD(v3) = -1 - v21;
603 v3 <<= 16;
604 LOWORD(v3) = -1 - v21;
605 memset32(v14, v3, v11 >> 1);
606 v15 = (int)((char *)v14 + 4 * (v11 >> 1));
607 for ( i = v11 & 1; i; --i )
608 {
609 *(short *)v15 = v3;
610 v15 += 2;
611 }
612 }
613 v13 += v19;
614 --v20;
615 }
616 while ( v20 );
617 }
618 result = v21 + 2662 * uChestID;
619 pChests[0].pInventoryIndices[result] = v18 + 1;
620 return result;
621 }
622 // 506128: using guessed type int areWeLoadingTexture;
623
624 //----- (00420284) --------------------------------------------------------
625 char *Chest::_420284(unsigned int uChestID)
626 {
627 int v1; // ebx@1
628 unsigned int v2; // esi@1
629 unsigned int v3; // esi@1
630 int uChestArea; // edi@1
631 int v5; // eax@2
632 int v6; // ebx@11
633 char *result; // eax@18
634 char Dst[144]; // [sp+Ch] [bp-A0h]@1
635 int v9; // [sp+9Ch] [bp-10h]@10
636 unsigned int v10; // [sp+A0h] [bp-Ch]@1
637 unsigned int v11; // [sp+A4h] [bp-8h]@8
638 ItemGen *v12; // [sp+A8h] [bp-4h]@9
639
640 v1 = 0;
641 v2 = uChestID;
642 v10 = uChestID;
643 pRenderer->ClearZBuffer(0, 479);
644 v3 = v2;
645 uChestArea = pChestWidthsByType[pChests[v3].uChestBitmapID] * pChestHeightsByType[pChests[v3].uChestBitmapID];
646 memset(Dst, 0, 0x90u);
647 if ( uChestArea > 0 )
648 {
649 do
650 {
651 do
652 v5 = (unsigned __int8)rand();
653 while ( v5 >= uChestArea );
654 while ( Dst[v5] )
655 {
656 ++v5;
657 if ( v5 == uChestArea )
658 v5 = 0;
659 }
660 Dst[v5] = v1++;
661 }
662 while ( v1 < uChestArea );
663 }
664 v11 = 0;
665 if ( uChestArea > 0 )
666 {
667 v12 = pChests[v3].mm7__vector_pItems;//&pChests[v3].mm7__vector_pItems[0].uAttributes;
668 do
669 {
670 v9 = v12->uItemID;
671 if ( v9 )
672 {
673 v6 = 0;
674 while ( !Chest::CanPlaceItemAt((unsigned __int8)Dst[v6], v9, v10) )
675 {
676 ++v6;
677 if ( v6 >= uChestArea )
678 break;
679 }
680 if(v6<uChestArea)
681 {
682 Chest::PlaceItemAt((unsigned __int8)Dst[v6], v11, v10);
683 if ( pChests[v3].uFlags & 4 )
684 v12->SetIdentified();
685 }
686 }
687 ++v11;
688 ++v12;
689 }
690 while ( (signed int)v11 < uChestArea );
691 }
692 result = (char *)&pChests[v3].uFlags;
693 pChests[v3].uFlags = pChests[v3].uFlags & 0xFFFB | 2;
694 return result;
695 }
696 // 420284: using guessed type char Dst[144];
19 697
20 //----- (00458B03) -------------------------------------------------------- 698 //----- (00458B03) --------------------------------------------------------
21 void ChestList::ToFile() 699 void ChestList::ToFile()
22 { 700 {
23 ChestList *v1; // esi@1 701 ChestList *v1; // esi@1