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