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);
|
535
|
82 auto chest = &pChests[uChestID];
|
426
|
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;
|
535
|
223 return false;
|
421
|
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;
|
535
|
236 v3 = GUIWindow::Create(0, 0, 640, 480, WINDOW_Chest, uChestID, 0);
|
421
|
237 pGUIWindow_CurrentMenu = v3;
|
|
238 pChestWindow = v3;
|
535
|
239 pBtn_ExitCancel = v3->CreateButton(0x1D7u, 0x1BDu, 0xA9u, 0x23u, 1, 0, 0x71u, 0, 0, pGlobalTXT_LocalizationStrings[79],// Exit
|
|
240 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0), 0);
|
421
|
241 pChestWindow->CreateButton(7u, 8u, 460u, 343u, 1, 0, 0xCu, 0, 0, "", 0);
|
|
242 pCurrentScreen = SCREEN_CHEST;
|
|
243 pEventTimer->Pause();
|
535
|
244 return true;
|
421
|
245 }
|
|
246
|
|
247 //----- (0042092D) --------------------------------------------------------
|
|
248 void Chest::DrawChestUI(unsigned int uChestID)
|
|
249 {
|
|
250 Render *v1; // edi@1
|
|
251 unsigned int v2; // ebx@1
|
|
252 unsigned int v3; // ebx@1
|
|
253 int v4; // eax@1
|
|
254 unsigned int v5; // eax@1
|
|
255 int v6; // ecx@3
|
|
256 unsigned int v7; // eax@4
|
|
257 Texture *v8; // esi@4
|
|
258 signed int v9; // ecx@4
|
|
259 signed int v10; // edx@4
|
|
260 signed int v11; // eax@4
|
|
261 int v12; // eax@6
|
|
262 int v13; // eax@6
|
|
263 unsigned int v14; // ST34_4@8
|
|
264 int v15; // edi@8
|
|
265 int *v16; // [sp+Ch] [bp-28h]@1
|
|
266 int v17; // [sp+10h] [bp-24h]@4
|
|
267 int v18; // [sp+14h] [bp-20h]@1
|
|
268 signed int v19; // [sp+18h] [bp-1Ch]@1
|
|
269 int v20; // [sp+1Ch] [bp-18h]@1
|
|
270 signed int v21; // [sp+20h] [bp-14h]@1
|
|
271 char *v22; // [sp+2Ch] [bp-8h]@2
|
|
272 signed int v23; // [sp+30h] [bp-4h]@1
|
|
273
|
|
274 v1 = pRenderer;
|
|
275 v2 = uChestID;
|
|
276 v16 = pRenderer->pActiveZBuffer;
|
|
277 pRenderer->ClearZBuffer(0, 479);
|
|
278 v3 = v2;
|
|
279 v4 = pChests[v3].uChestBitmapID;
|
|
280 v20 = pChestSmthn1ByType[v4];
|
|
281 v18 = pChestSmthn2ByType[v4];
|
|
282 v21 = pChestWidthsByType[v4];
|
|
283 v19 = pChestHeightsByType[v4];
|
|
284 sprintf(pTmpBuf, "chest%02d", pChestList->pChests[pChests[v3].uChestBitmapID].uTextureID);
|
|
285 v5 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE);
|
|
286 pRenderer->DrawTextureIndexed(8u, 8u, (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0));
|
|
287 v23 = 0;
|
|
288 if ( v21 * v19 > 0 )
|
|
289 {
|
|
290 v22 = (char *)pChests[v3].pInventoryIndices;
|
|
291 do
|
|
292 {
|
|
293 v6 = *(short *)v22;
|
|
294 if ( v6 > 0 )
|
|
295 {
|
|
296 v17 = v18 + 32 * v23 / v19;
|
|
297 v7 = pIcons_LOD->LoadTexture(
|
|
298 pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName,
|
|
299 TEXTURE_16BIT_PALETTE);
|
|
300 v8 = (Texture *)(v7 != -1 ? &pIcons_LOD->pTextures[v7] : 0);
|
|
301 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
|
|
302 v10 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureHeight : 26);
|
|
303 v11 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
|
|
304 if ( v9 < 14 )
|
|
305 v11 = 14;
|
|
306 v12 = v11 - 14;
|
|
307 LOBYTE(v12) = v12 & 0xE0;
|
|
308 v13 = v12 + 32;
|
|
309 if ( (signed int)v8->uTextureHeight < 14 )
|
|
310 v10 = 14;
|
|
311 v14 = v20 + 32 * v23 % v21 + ((v13 - v9) >> 1);
|
|
312 v15 = v17 + ((((v10 - 14) & 0xFFFFFFE0) - v8->uTextureHeight + 32) >> 1);
|
|
313 pRenderer->DrawTextureTransparent(
|
|
314 v14,
|
|
315 v17 + ((((v10 - 14) & 0xFFFFFFE0) - v8->uTextureHeight + 32) >> 1),
|
|
316 v8);
|
|
317 sub_40F92A(&v16[v14 + pSRZBufferLineOffsets[v15]], v8, v23 + 1);
|
|
318 v1 = pRenderer;
|
|
319 }
|
|
320 ++v23;
|
|
321 v22 += 2;
|
|
322 }
|
|
323 while ( v23 < v21 * v19 );
|
|
324 }
|
|
325 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY,
|
|
326 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0));
|
|
327 }
|
|
328
|
|
329
|
|
330 //----- (0041FE71) --------------------------------------------------------
|
|
331 int Chest::CanPlaceItemAt(signed int a1, int a2, unsigned int uChestID)
|
|
332 {
|
|
333 int v3; // eax@1
|
|
334 unsigned int v4; // eax@1
|
|
335 Texture *v5; // ecx@1
|
|
336 signed int v6; // eax@1
|
|
337 signed int v7; // edi@3
|
|
338 signed int v8; // eax@3
|
|
339 int v9; // edi@3
|
|
340 int v10; // ebx@5
|
|
341 int v11; // esi@9
|
|
342 int v12; // edx@10
|
|
343 int v13; // ecx@11
|
|
344 char *v14; // eax@12
|
|
345 int v16; // [sp+Ch] [bp-Ch]@1
|
|
346 signed int v17; // [sp+10h] [bp-8h]@1
|
|
347 signed int v18; // [sp+14h] [bp-4h]@1
|
|
348
|
|
349 v17 = a1;
|
|
350 v3 = pChests[uChestID].uChestBitmapID;
|
|
351 v16 = pChestHeightsByType[v3];
|
|
352 v18 = pChestWidthsByType[v3];
|
|
353 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[a2].pIconName, TEXTURE_16BIT_PALETTE);
|
|
354 v5 = (Texture *)(v4 != -1 ? (int)&pIcons_LOD->pTextures[v4] : 0);
|
|
355 v6 = (v4 != -1 ? pIcons_LOD->pTextures[v4].uTextureWidth : 24);
|
|
356 if ( v6 < 14 )
|
|
357 v6 = 14;
|
|
358 v7 = v6 - 14;
|
|
359 v8 = v5->uTextureHeight;
|
|
360 v9 = (v7 >> 5) + 1;
|
|
361 if ( v8 < 14 )
|
|
362 v8 = 14;
|
|
363 v10 = ((v8 - 14) >> 5) + 1;
|
|
364 if ( !areWeLoadingTexture )
|
|
365 {
|
|
366 v5->Release();
|
|
367 pIcons_LOD->_40F9C5();
|
|
368 }
|
|
369 if ( v9 + v17 % v18 <= v18 && v10 + v17 / v18 <= v16 )
|
|
370 {
|
|
371 v11 = 0;
|
|
372 if ( v10 <= 0 )
|
|
373 return 1;
|
|
374 v12 = 0;
|
|
375 while ( 1 )
|
|
376 {
|
|
377 v13 = 0;
|
|
378 if ( v9 > 0 )
|
|
379 break;
|
|
380 LABEL_15:
|
|
381 v12 += v18;
|
|
382 ++v11;
|
|
383 if ( v11 >= v10 )
|
|
384 return 1;
|
|
385 }
|
|
386 v14 = (char *)&pChests[0].pInventoryIndices[v17 + v12 + 2662 * uChestID];
|
|
387 while ( !*(short *)v14 )
|
|
388 {
|
|
389 ++v13;
|
|
390 v14 += 2;
|
|
391 if ( v13 >= v9 )
|
|
392 goto LABEL_15;
|
|
393 }
|
|
394 }
|
|
395 return 0;
|
|
396 }
|
|
397 // 506128: using guessed type int areWeLoadingTexture;
|
|
398
|
|
399 //----- (0041FF64) --------------------------------------------------------
|
|
400 int Chest::_41FF64(unsigned int uChestID)
|
|
401 {
|
|
402 unsigned int v1; // ecx@1
|
|
403 signed int result; // eax@1
|
|
404 int v3; // edx@1
|
|
405 ItemGen *pItem; // ecx@2
|
|
406
|
|
407 v1 = uChestID;
|
|
408 result = 0;
|
|
409 v3 = pChestWidthsByType[pChests[v1].uChestBitmapID] * pChestHeightsByType[pChests[v1].uChestBitmapID];
|
|
410 if ( v3 <= 0 )
|
|
411 {
|
|
412 LABEL_5:
|
|
413 result = -1;
|
|
414 }
|
|
415 else
|
|
416 {
|
|
417 pItem = pChests[v1].mm7__vector_pItems;
|
|
418 while ( pItem->uItemID )
|
|
419 {
|
|
420 ++result;
|
|
421 ++pItem;
|
|
422 if ( result >= v3 )
|
|
423 goto LABEL_5;
|
|
424 }
|
|
425 }
|
|
426 return result;
|
|
427 }
|
|
428
|
|
429 //----- (0041FFA2) --------------------------------------------------------
|
|
430 int Chest::_41FFA2(int a1, ItemGen *a2, unsigned int uChestID)
|
|
431 {
|
|
432 int v3; // eax@1
|
|
433 ItemGen *v4; // edi@1
|
|
434 int v5; // esi@1
|
|
435 int result; // eax@11
|
|
436 unsigned int v7; // eax@12
|
|
437 int v8; // edx@12
|
|
438 int v9; // ecx@12
|
|
439 signed int v10; // eax@12
|
|
440 signed int v11; // edi@14
|
|
441 unsigned int v12; // esi@14
|
|
442 int v13; // edi@16
|
|
443 void *v14; // edi@21
|
|
444 int v15; // edi@21
|
|
445 int i; // ecx@21
|
|
446 ItemGen *Src; // [sp+Ch] [bp-18h]@1
|
|
447 signed int v18; // [sp+10h] [bp-14h]@2
|
|
448 int v19; // [sp+14h] [bp-10h]@1
|
|
449 int v20; // [sp+18h] [bp-Ch]@19
|
|
450 signed int v21; // [sp+1Ch] [bp-8h]@1
|
|
451 signed int v22; // [sp+20h] [bp-4h]@3
|
|
452 int v23; // [sp+20h] [bp-4h]@19
|
|
453
|
|
454 v21 = 0;
|
|
455 v3 = pChests[uChestID].uChestBitmapID;
|
|
456 v4 = a2;
|
|
457 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3];
|
|
458 Src = a2;
|
|
459 v19 = pChestWidthsByType[v3];
|
|
460 if ( a1 == -1 )
|
|
461 {
|
|
462 v18 = _41FF64(uChestID);
|
|
463 if ( v18 == -1 )
|
|
464 return 0;
|
|
465 v22 = 0;
|
|
466 if ( v5 > 0 )
|
|
467 {
|
|
468 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, (unsigned int)pChestWindow->ptr_1C) )
|
|
469 {
|
|
470 ++v22;
|
|
471 if ( v22 >= v5 )
|
|
472 goto LABEL_8;
|
|
473 }
|
|
474 v21 = v22;
|
|
475 }
|
|
476 LABEL_8:
|
|
477 if ( v22 == v5 )
|
|
478 {
|
|
479 if ( uActiveCharacter )
|
|
480 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0);
|
|
481 return 0;
|
|
482 }
|
|
483 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v4->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
|
|
484 HIWORD(v8) = 0;
|
|
485 v9 = v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0;
|
|
486 v10 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
|
|
487 if ( v10 < 14 )
|
|
488 v10 = 14;
|
|
489 v11 = *(short *)(v9 + 26);
|
|
490 v12 = ((v10 - 14) >> 5) + 1;
|
|
491 if ( v11 < 14 )
|
|
492 v11 = 14;
|
|
493 v13 = ((v11 - 14) >> 5) + 1;
|
|
494 if ( !areWeLoadingTexture )
|
|
495 {
|
|
496 ((Texture *)v9)->Release();
|
|
497 pIcons_LOD->_40F9C5();
|
|
498 }
|
|
499 if ( v13 > 0 )
|
|
500 {
|
|
501 v23 = 0;
|
|
502 v20 = v13;
|
|
503 do
|
|
504 {
|
|
505 if ( (signed int)v12 > 0 )
|
|
506 {
|
|
507 v14 = &pChests[0].pInventoryIndices[v21 + v23 + 2662 * uChestID];
|
|
508 LOWORD(v8) = -1 - v21;
|
|
509 v8 <<= 16;
|
|
510 LOWORD(v8) = -1 - v21;
|
|
511 memset32(v14, v8, v12 >> 1);
|
|
512 v15 = (int)((char *)v14 + 4 * (v12 >> 1));
|
|
513 for ( i = v12 & 1; i; --i )
|
|
514 {
|
|
515 *(short *)v15 = v8;
|
|
516 v15 += 2;
|
|
517 }
|
|
518 }
|
|
519 v23 += v19;
|
|
520 --v20;
|
|
521 }
|
|
522 while ( v20 );
|
|
523 }
|
|
524 pChests[0].pInventoryIndices[v21 + 2662 * uChestID] = v18 + 1;
|
|
525 memcpy(&pChests[uChestID].mm7__vector_pItems[v18], Src, 0x24u);
|
|
526 result = v21 + 1;
|
|
527 }
|
|
528 else
|
|
529 {
|
|
530 result = 1;
|
|
531 }
|
|
532 return result;
|
|
533 }
|
|
534 // 506128: using guessed type int areWeLoadingTexture;
|
|
535
|
|
536 //----- (0042013E) --------------------------------------------------------
|
|
537 unsigned int Chest::PlaceItemAt(unsigned int a1, unsigned int uItemIdx, unsigned int uChestID)
|
|
538 {
|
|
539 int v3; // esi@1
|
|
540 unsigned int v4; // ebx@1
|
|
541 int uItemID; // edi@1
|
|
542 int v6; // edx@4
|
|
543 unsigned int v7; // eax@5
|
|
544 Texture *v8; // ecx@5
|
|
545 signed int v9; // eax@5
|
|
546 signed int v10; // edi@7
|
|
547 unsigned int v11; // ebx@7
|
|
548 int v12; // edi@9
|
|
549 int v13; // edx@12
|
|
550 void *v14; // edi@14
|
|
551 int v15; // edi@14
|
|
552 int i; // ecx@14
|
|
553 unsigned int result; // eax@18
|
|
554 __int16 v18; // [sp+Ch] [bp-10h]@1
|
|
555 int v19; // [sp+10h] [bp-Ch]@11
|
|
556 int v20; // [sp+14h] [bp-8h]@12
|
|
557 unsigned int v21; // [sp+18h] [bp-4h]@1
|
|
558
|
|
559 v3 = 5324 * uChestID;
|
|
560 v21 = a1;
|
|
561 v4 = 5324 * uChestID + 36 * uItemIdx;
|
|
562 v18 = uItemIdx;
|
|
563 uItemID = *(unsigned int *)((char *)&pChests[0].mm7__vector_pItems[0].uItemID + v4);
|
|
564 pItemsTable->SetSpecialBonus((ItemGen *)((char *)pChests[0].mm7__vector_pItems + v4));
|
|
565 if ( uItemID >= 135 && uItemID <= 159 && !*(int *)((char *)&pChests[0].mm7__vector_pItems[0].uNumCharges + v4) )
|
|
566 {
|
|
567 v6 = rand() % 21 + 10;
|
|
568 *(int *)((char *)&pChests[0].mm7__vector_pItems[0].uNumCharges + v4) = v6;
|
|
569 *(&pChests[0].mm7__vector_pItems[0].uMaxCharges + v4) = v6;
|
|
570 }
|
|
571 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
|
|
572 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0);
|
|
573 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24);
|
|
574 if ( v9 < 14 )
|
|
575 v9 = 14;
|
|
576 v10 = v8->uTextureHeight;
|
|
577 v11 = ((v9 - 14) >> 5) + 1;
|
|
578 if ( v10 < 14 )
|
|
579 v10 = 14;
|
|
580 v12 = ((v10 - 14) >> 5) + 1;
|
|
581 if ( !areWeLoadingTexture )
|
|
582 {
|
|
583 v8->Release();
|
|
584 pIcons_LOD->_40F9C5();
|
|
585 }
|
|
586 v19 = pChestWidthsByType[*(unsigned __int16 *)((char *)&pChests[0].uChestBitmapID + v3)];
|
|
587 if ( v12 > 0 )
|
|
588 {
|
|
589 v13 = 0;
|
|
590 v20 = v12;
|
|
591 do
|
|
592 {
|
|
593 if ( (signed int)v11 > 0 )
|
|
594 {
|
|
595 v14 = &pChests[0].pInventoryIndices[v21 + v13 + 2662 * uChestID];
|
|
596 LOWORD(v3) = -1 - v21;
|
|
597 v3 <<= 16;
|
|
598 LOWORD(v3) = -1 - v21;
|
|
599 memset32(v14, v3, v11 >> 1);
|
|
600 v15 = (int)((char *)v14 + 4 * (v11 >> 1));
|
|
601 for ( i = v11 & 1; i; --i )
|
|
602 {
|
|
603 *(short *)v15 = v3;
|
|
604 v15 += 2;
|
|
605 }
|
|
606 }
|
|
607 v13 += v19;
|
|
608 --v20;
|
|
609 }
|
|
610 while ( v20 );
|
|
611 }
|
|
612 result = v21 + 2662 * uChestID;
|
|
613 pChests[0].pInventoryIndices[result] = v18 + 1;
|
|
614 return result;
|
|
615 }
|
|
616 // 506128: using guessed type int areWeLoadingTexture;
|
|
617
|
|
618 //----- (00420284) --------------------------------------------------------
|
|
619 char *Chest::_420284(unsigned int uChestID)
|
|
620 {
|
|
621 int v1; // ebx@1
|
|
622 unsigned int v2; // esi@1
|
|
623 unsigned int v3; // esi@1
|
|
624 int uChestArea; // edi@1
|
|
625 int v5; // eax@2
|
|
626 int v6; // ebx@11
|
|
627 char *result; // eax@18
|
|
628 char Dst[144]; // [sp+Ch] [bp-A0h]@1
|
|
629 int v9; // [sp+9Ch] [bp-10h]@10
|
|
630 unsigned int v10; // [sp+A0h] [bp-Ch]@1
|
|
631 unsigned int v11; // [sp+A4h] [bp-8h]@8
|
|
632 ItemGen *v12; // [sp+A8h] [bp-4h]@9
|
|
633
|
|
634 v1 = 0;
|
|
635 v2 = uChestID;
|
|
636 v10 = uChestID;
|
|
637 pRenderer->ClearZBuffer(0, 479);
|
|
638 v3 = v2;
|
|
639 uChestArea = pChestWidthsByType[pChests[v3].uChestBitmapID] * pChestHeightsByType[pChests[v3].uChestBitmapID];
|
|
640 memset(Dst, 0, 0x90u);
|
|
641 if ( uChestArea > 0 )
|
|
642 {
|
|
643 do
|
|
644 {
|
|
645 do
|
|
646 v5 = (unsigned __int8)rand();
|
|
647 while ( v5 >= uChestArea );
|
|
648 while ( Dst[v5] )
|
|
649 {
|
|
650 ++v5;
|
|
651 if ( v5 == uChestArea )
|
|
652 v5 = 0;
|
|
653 }
|
|
654 Dst[v5] = v1++;
|
|
655 }
|
|
656 while ( v1 < uChestArea );
|
|
657 }
|
|
658 v11 = 0;
|
|
659 if ( uChestArea > 0 )
|
|
660 {
|
|
661 v12 = pChests[v3].mm7__vector_pItems;//&pChests[v3].mm7__vector_pItems[0].uAttributes;
|
|
662 do
|
|
663 {
|
|
664 v9 = v12->uItemID;
|
535
|
665 if ( v9 > 0 )
|
421
|
666 {
|
|
667 v6 = 0;
|
|
668 while ( !Chest::CanPlaceItemAt((unsigned __int8)Dst[v6], v9, v10) )
|
|
669 {
|
|
670 ++v6;
|
|
671 if ( v6 >= uChestArea )
|
|
672 break;
|
|
673 }
|
|
674 if(v6<uChestArea)
|
|
675 {
|
|
676 Chest::PlaceItemAt((unsigned __int8)Dst[v6], v11, v10);
|
|
677 if ( pChests[v3].uFlags & 4 )
|
|
678 v12->SetIdentified();
|
|
679 }
|
|
680 }
|
|
681 ++v11;
|
|
682 ++v12;
|
|
683 }
|
|
684 while ( (signed int)v11 < uChestArea );
|
|
685 }
|
|
686 result = (char *)&pChests[v3].uFlags;
|
|
687 pChests[v3].uFlags = pChests[v3].uFlags & 0xFFFB | 2;
|
|
688 return result;
|
|
689 }
|
|
690 // 420284: using guessed type char Dst[144];
|
|
691
|
0
|
692 //----- (00458B03) --------------------------------------------------------
|
|
693 void ChestList::ToFile()
|
|
694 {
|
|
695 ChestList *v1; // esi@1
|
|
696 FILE *v2; // eax@1
|
|
697 FILE *v3; // edi@1
|
|
698
|
|
699 v1 = this;
|
|
700 v2 = fopen("data\\dchest.bin", "wb");
|
|
701 v3 = v2;
|
|
702 if ( !v2 )
|
|
703 Abortf("Unable to save dchest.bin!");
|
|
704 fwrite(v1, 4u, 1u, v2);
|
|
705 fwrite(v1->pChests, 0x24u, v1->uNumChests, v3);
|
|
706 fclose(v3);
|
|
707 }
|
|
708
|
|
709
|
|
710 //----- (00458B4F) --------------------------------------------------------
|
|
711 void ChestList::FromFile(void *pSerialized)
|
|
712 {
|
|
713 uNumChests = *(int *)pSerialized;
|
|
714 pChests = (ChestDesc *)pAllocator->AllocNamedChunk(pChests, 36 * uNumChests, "Chest Descrip");
|
|
715 memcpy(pChests, (char *)pSerialized + 4, 36 * uNumChests);
|
|
716 }
|
|
717
|
|
718
|
|
719 //----- (00458B9C) --------------------------------------------------------
|
|
720 int ChestList::FromFileTxt(const char *Args)
|
|
721 {
|
|
722 ChestList *v2; // ebx@1
|
|
723 __int32 v3; // edi@1
|
|
724 FILE *v4; // eax@1
|
|
725 unsigned int v5; // esi@3
|
|
726 const void *v6; // ST18_4@9
|
|
727 void *v7; // eax@9
|
|
728 FILE *v8; // ST0C_4@11
|
|
729 char *i; // eax@11
|
|
730 char v10; // al@14
|
|
731 const char *v11; // ST14_4@14
|
|
732 char v12; // al@14
|
|
733 const char *v13; // ST10_4@14
|
|
734 char Buf; // [sp+8h] [bp-2F0h]@3
|
|
735 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4
|
|
736 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4
|
|
737 FILE *File; // [sp+2F4h] [bp-4h]@1
|
|
738 unsigned int Argsa; // [sp+300h] [bp+8h]@3
|
|
739
|
|
740 v2 = this;
|
|
741 pAllocator->FreeChunk(this->pChests);
|
|
742 v3 = 0;
|
|
743 v2->pChests = 0;
|
|
744 v2->uNumChests = 0;
|
|
745 v4 = fopen(Args, "r");
|
|
746 File = v4;
|
|
747 if ( !v4 )
|
|
748 Abortf("ChestDescriptionList::load - Unable to open file: %s.");
|
|
749 v5 = 0;
|
|
750 Argsa = 0;
|
|
751 if ( fgets(&Buf, 490, v4) )
|
|
752 {
|
|
753 do
|
|
754 {
|
|
755 *strchr(&Buf, 10) = 0;
|
|
756 memcpy(&v17, texture_frame_table_txt_parser(&Buf, &v16), sizeof(v17));
|
|
757 if ( v17.field_0 && *v17.pProperties[0] != 47 )
|
|
758 ++Argsa;
|
|
759 }
|
|
760 while ( fgets(&Buf, 490, File) );
|
|
761 v5 = Argsa;
|
|
762 v3 = 0;
|
|
763 }
|
|
764 v6 = v2->pChests;
|
|
765 v2->uNumChests = v5;
|
|
766 v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip");
|
|
767 v2->pChests = (ChestDesc *)v7;
|
|
768 if ( v7 == (void *)v3 )
|
|
769 Abortf("ChestDescriptionList::load - Out of Memory!");
|
|
770 memset(v7, v3, 36 * v2->uNumChests);
|
|
771 v8 = File;
|
|
772 v2->uNumChests = v3;
|
|
773 fseek(v8, v3, v3);
|
|
774 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
|
|
775 {
|
|
776 *strchr(&Buf, 10) = 0;
|
|
777 memcpy(&v17, texture_frame_table_txt_parser(&Buf, &v16), sizeof(v17));
|
|
778 if ( v17.field_0 && *v17.pProperties[0] != 47 )
|
|
779 {
|
|
780 strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]);
|
|
781 v10 = atoi(v17.pProperties[1]);
|
|
782 v11 = v17.pProperties[2];
|
|
783 v2->pChests[v2->uNumChests].uWidth = v10;
|
|
784 v12 = atoi(v11);
|
|
785 v13 = v17.pProperties[3];
|
|
786 v2->pChests[v2->uNumChests].uHeight = v12;
|
|
787 v2->pChests[v2->uNumChests++].uTextureID = atoi(v13);
|
|
788 }
|
|
789 }
|
|
790 fclose(File);
|
|
791 return 1;
|
|
792 }
|