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