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