Mercurial > mm7
comparison Chest.cpp @ 576:1bd8758f50b8
Слияние
author | Ritor1 |
---|---|
date | Mon, 04 Mar 2013 09:22:38 +0600 |
parents | ec3546510fa1 |
children | 96f48cfdd657 653724e9c234 |
comparison
equal
deleted
inserted
replaced
575:cf366ba68de5 | 576:1bd8758f50b8 |
---|---|
27 size_t uNumChests; // idb | 27 size_t uNumChests; // idb |
28 struct ChestList *pChestList; | 28 struct ChestList *pChestList; |
29 Chest pChests[20]; | 29 Chest pChests[20]; |
30 | 30 |
31 | 31 |
32 | 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}; | |
33 | 36 |
34 | 37 |
35 //----- (0042041E) -------------------------------------------------------- | 38 //----- (0042041E) -------------------------------------------------------- |
36 bool Chest::Open(unsigned int uChestID) | 39 bool Chest::Open( signed int uChestID ) |
37 { | 40 { |
38 //char *v1; // edi@5 | 41 //char *v1; // edi@5 |
39 unsigned int v2; // eax@8 | 42 unsigned int v2; // eax@8 |
40 GUIWindow *v3; // eax@15 | 43 GUIWindow *v3; // eax@15 |
41 int v5; // edx@16 | 44 int v5; // edx@16 |
42 int v6; // eax@16 | 45 int v6; // eax@16 |
59 unsigned int *v23; // edi@28 | 62 unsigned int *v23; // edi@28 |
60 unsigned __int16 v24; // di@28 | 63 unsigned __int16 v24; // di@28 |
61 signed int v25; // ecx@28 | 64 signed int v25; // ecx@28 |
62 char *v26; // edx@29 | 65 char *v26; // edx@29 |
63 unsigned __int16 v27; // ax@32 | 66 unsigned __int16 v27; // ax@32 |
64 //LayingItem a1; // [sp+14h] [bp-B0h]@28 | 67 //SpriteObject a1; // [sp+14h] [bp-B0h]@28 |
65 int v29; // [sp+84h] [bp-40h]@16 | 68 int v29; // [sp+84h] [bp-40h]@16 |
66 int v30; // [sp+88h] [bp-3Ch]@16 | 69 int v30; // [sp+88h] [bp-3Ch]@16 |
67 int v31; // [sp+8Ch] [bp-38h]@16 | 70 int v31; // [sp+8Ch] [bp-38h]@16 |
68 int v32; // [sp+90h] [bp-34h]@16 | 71 int v32; // [sp+90h] [bp-34h]@16 |
69 float v33; // [sp+94h] [bp-30h]@23 | 72 float v33; // [sp+94h] [bp-30h]@23 |
77 float v41; // [sp+BCh] [bp-8h]@23 | 80 float v41; // [sp+BCh] [bp-8h]@23 |
78 int sRotY; // [sp+C0h] [bp-4h]@8 | 81 int sRotY; // [sp+C0h] [bp-4h]@8 |
79 | 82 |
80 //a4 = uChestID; | 83 //a4 = uChestID; |
81 assert(uChestID < 20); | 84 assert(uChestID < 20); |
82 auto chest = pChests + uChestID; | 85 if ((uChestID <0)&&(uChestID >=20) ) |
86 return false; | |
87 auto chest = &pChests[uChestID]; | |
83 | 88 |
84 ++pIcons_LOD->uTexturePacksCount; | 89 ++pIcons_LOD->uTexturePacksCount; |
85 if (!pIcons_LOD->uNumPrevLoadedFiles) | 90 if (!pIcons_LOD->uNumPrevLoadedFiles) |
86 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles; | 91 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles; |
87 | 92 |
88 | 93 |
89 //v1 = (char *)&pChests[uChestID].uFlags; | 94 //v1 = (char *)&pChests[uChestID].uFlags; |
90 //v34 = v1; | 95 //v34 = v1; |
91 if (!chest->Initialized()) | 96 if (!chest->Initialized()) |
92 Chest::_420284(uChestID); | 97 Chest::PlaceItems(uChestID); |
93 | 98 |
94 if ( !uActiveCharacter ) | 99 if ( !uActiveCharacter ) |
95 return 0; | 100 return 0; |
96 *(float *)&sRotY = 0.0; | 101 *(float *)&sRotY = 0.0; |
97 v2 = pMapStats->GetMapInfo(pCurrentMapName); | 102 v2 = pMapStats->GetMapInfo(pCurrentMapName); |
167 *(_QWORD *)v22 = __PAIR__(v38, v14); | 172 *(_QWORD *)v22 = __PAIR__(v38, v14); |
168 Vec3_int_::Rotate(v21, sRotX, sRotY, *(Vec3_int_ *)v22, &pOut.x, &pOut.z, &pOut.y); | 173 Vec3_int_::Rotate(v21, sRotX, sRotY, *(Vec3_int_ *)v22, &pOut.x, &pOut.z, &pOut.y); |
169 v23 = (unsigned int *)(&v29 + v35); | 174 v23 = (unsigned int *)(&v29 + v35); |
170 sub_42F7EB_DropItemAt(*v23, pOut.x, pOut.z, pOut.y, 0, 1, 0, 0x30u, 0); | 175 sub_42F7EB_DropItemAt(*v23, pOut.x, pOut.z, pOut.y, 0, 1, 0, 0x30u, 0); |
171 | 176 |
172 LayingItem a1; // [sp+14h] [bp-B0h]@28 | 177 SpriteObject a1; // [sp+14h] [bp-B0h]@28 |
173 //LayingItem::LayingItem(&a1); | 178 //SpriteObject::SpriteObject(&a1); |
174 | 179 |
175 a1.stru_24.Reset(); | 180 a1.stru_24.Reset(); |
176 v24 = *(short *)v23; | 181 v24 = *(short *)v23; |
177 v25 = 0; | 182 v25 = 0; |
178 a1.field_50 = 0; | 183 a1.field_50 = 0; |
179 a1.field_4C = 0; | 184 a1.field_4C = 0; |
180 a1.field_48 = 0; | 185 a1.field_48 = 0; |
181 a1.field_54 = 0; | 186 a1.field_54 = 0; |
182 a1.uItemType = v24; | 187 a1.uType = v24; |
183 if ( (signed int)pObjectList->uNumObjects <= 0 ) | 188 if ( (signed int)pObjectList->uNumObjects <= 0 ) |
184 { | 189 { |
185 LABEL_32: | 190 LABEL_32: |
186 v27 = 0; | 191 v27 = 0; |
187 } | 192 } |
231 { | 236 { |
232 if ( !dword_507CD8 ) | 237 if ( !dword_507CD8 ) |
233 pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0); | 238 pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0); |
234 } | 239 } |
235 dword_507CD8 = 0; | 240 dword_507CD8 = 0; |
236 v3 = GUIWindow::Create(0, 0, 640u, 480u, WINDOW_Chest, a4, 0); | 241 |
237 pGUIWindow_CurrentMenu = v3; | 242 pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640u, 480u, WINDOW_Chest, uChestID, 0); |
238 pChestWindow = v3; | 243 pChestWindow = pGUIWindow_CurrentMenu; |
239 pBtn_ExitCancel = v3->CreateButton( | 244 pBtn_ExitCancel = pChestWindow->CreateButton(0x1D7u, 0x1BDu, 0xA9u, 0x23u, 1, 0, 0x71u, 0, 0, pGlobalTXT_LocalizationStrings[79],// Exit |
240 0x1D7u, | 245 (Texture *)(uExitCancelTextureId != -1 ? (int)&pIcons_LOD->pTextures[uExitCancelTextureId] : 0), 0); |
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); | 246 pChestWindow->CreateButton(7u, 8u, 460u, 343u, 1, 0, 0xCu, 0, 0, "", 0); |
253 pCurrentScreen = SCREEN_CHEST; | 247 pCurrentScreen = SCREEN_CHEST; |
254 pEventTimer->Pause(); | 248 pEventTimer->Pause(); |
255 return 1; | 249 return 1; |
256 } | 250 } |
257 | 251 |
258 //----- (0042092D) -------------------------------------------------------- | 252 //----- (0042092D) -------------------------------------------------------- |
259 void Chest::DrawChestUI(unsigned int uChestID) | 253 void Chest::DrawChestUI(unsigned int uChestID) |
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 item_counter; // [sp+30h] [bp-4h]@1 | |
275 | |
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 (item_counter = 0; item_counter< chestWidthCells * chestHeghtCells; ++item_counter) | |
288 { | |
289 chest_item_index = pChests[uChestID].pInventoryIndices[item_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 * (item_counter % chestWidthCells) + ((v13 - itemPixelWidth) >> 1); | |
306 itemPixelPosY = chest_offs_y + 32 * (item_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, item_counter + 1); | |
310 } | |
311 } | |
312 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, | |
313 (Texture *)(uExitCancelTextureId != -1 ? (int)&pIcons_LOD->pTextures[uExitCancelTextureId] : 0)); | |
314 } | |
315 | |
316 | |
317 //----- (0041FE71) -------------------------------------------------------- | |
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 chest_cell_heght = pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
337 chest_cell_width = pChestWidthsByType[pChests[uChestID].uChestBitmapID]; | |
338 item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE); | |
339 item_texture = (Texture *)(item_texture_id != -1 ? (int)&pIcons_LOD->pTextures[item_texture_id] : 0); | |
340 v6 = (item_texture_id != -1 ? pIcons_LOD->pTextures[item_texture_id].uTextureWidth : 24); | |
341 if ( v6 < 14 ) | |
342 v6 = 14; | |
343 texture_cell_width = (v6 - 14 >> 5) + 1; | |
344 v8 = item_texture->uTextureHeight; | |
345 if ( v8 < 14 ) | |
346 v8 = 14; | |
347 texture_cell_height = ((v8 - 14) >> 5) + 1; | |
348 if ( !areWeLoadingTexture ) | |
349 { | |
350 item_texture->Release(); | |
351 pIcons_LOD->_40F9C5(); | |
352 } | |
353 if ( (texture_cell_width + test_cell_position % chest_cell_width <= chest_cell_width) && | |
354 (texture_cell_height + test_cell_position / chest_cell_width <= chest_cell_heght) ) | |
355 { //we not put over borders | |
356 _row = 0; | |
357 if ( texture_cell_height <= 0 ) | |
358 return true; | |
359 _cell_rows = 0; | |
360 while ( 1 ) | |
361 { | |
362 _column = 0; | |
363 if ( texture_cell_width > 0 ) | |
364 { | |
365 while ( pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]==0) | |
366 { | |
367 ++_column; | |
368 if ( _column >= texture_cell_width ) | |
369 break; | |
370 } | |
371 if (pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]!=0) | |
372 return false; | |
373 } | |
374 _cell_rows += chest_cell_width; | |
375 ++_row; | |
376 if ( _row >= texture_cell_height ) | |
377 return true; | |
378 } | |
379 | |
380 } | |
381 return false; | |
382 } | |
383 // 506128: using guessed type int areWeLoadingTexture; | |
384 | |
385 //----- (0041FF64) -------------------------------------------------------- | |
386 int Chest::CountChestItems(unsigned int uChestID) | |
260 { | 387 { |
261 Render *v1; // edi@1 | 388 signed int item_count; // eax@1 |
262 unsigned int v2; // ebx@1 | 389 int max_items; // edx@1 |
263 unsigned int v3; // ebx@1 | 390 item_count = 0; |
264 int v4; // eax@1 | 391 max_items = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; |
265 unsigned int v5; // eax@1 | 392 if ( max_items <= 0 ) |
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 { | 393 { |
301 v22 = (char *)pChests[v3].pInventoryIndices; | 394 item_count = -1; |
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 } | 395 } |
426 else | 396 else |
427 { | 397 { |
428 pItem = pChests[v1].mm7__vector_pItems; | 398 while ( pChests[uChestID].igChestItems[item_count].uItemID ) |
429 while ( pItem->uItemID ) | 399 { |
430 { | 400 ++item_count; |
431 ++result; | 401 if ( item_count >= max_items ) |
432 ++pItem; | 402 { |
433 if ( result >= v3 ) | 403 item_count = -1; |
434 goto LABEL_5; | 404 break; |
405 } | |
435 } | 406 } |
436 } | 407 } |
437 return result; | 408 return item_count; |
438 } | 409 } |
439 | 410 |
440 //----- (0041FFA2) -------------------------------------------------------- | 411 //----- (0041FFA2) -------------------------------------------------------- |
441 int Chest::_41FFA2(int a1, ItemGen *a2, unsigned int uChestID) | 412 int Chest::PutItemInChest(int position, ItemGen *put_item, unsigned int uChestID) |
442 { | 413 { |
443 int v3; // eax@1 | 414 int v3; // eax@1 |
444 ItemGen *v4; // edi@1 | 415 ItemGen *v4; // edi@1 |
445 int v5; // esi@1 | 416 int v5; // esi@1 |
446 int result; // eax@11 | 417 int result; // eax@11 |
453 int v13; // edi@16 | 424 int v13; // edi@16 |
454 void *v14; // edi@21 | 425 void *v14; // edi@21 |
455 int v15; // edi@21 | 426 int v15; // edi@21 |
456 int i; // ecx@21 | 427 int i; // ecx@21 |
457 ItemGen *Src; // [sp+Ch] [bp-18h]@1 | 428 ItemGen *Src; // [sp+Ch] [bp-18h]@1 |
458 signed int v18; // [sp+10h] [bp-14h]@2 | 429 signed int item_in_chest_count; // [sp+10h] [bp-14h]@2 |
459 int v19; // [sp+14h] [bp-10h]@1 | 430 int v19; // [sp+14h] [bp-10h]@1 |
460 int v20; // [sp+18h] [bp-Ch]@19 | 431 int v20; // [sp+18h] [bp-Ch]@19 |
461 signed int v21; // [sp+1Ch] [bp-8h]@1 | 432 signed int v21; // [sp+1Ch] [bp-8h]@1 |
462 signed int v22; // [sp+20h] [bp-4h]@3 | 433 signed int v22; // [sp+20h] [bp-4h]@3 |
463 int v23; // [sp+20h] [bp-4h]@19 | 434 int v23; // [sp+20h] [bp-4h]@19 |
464 | 435 |
465 v21 = 0; | 436 v21 = 0; |
466 v3 = pChests[uChestID].uChestBitmapID; | 437 v3 = pChests[uChestID].uChestBitmapID; |
467 v4 = a2; | 438 v4 = put_item; |
468 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3]; | 439 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3]; |
469 Src = a2; | 440 Src = put_item; |
470 v19 = pChestWidthsByType[v3]; | 441 v19 = pChestWidthsByType[v3]; |
471 if ( a1 == -1 ) | 442 if ( position == -1 ) |
472 { | 443 { |
473 v18 = _41FF64(uChestID); | 444 item_in_chest_count = CountChestItems(uChestID); |
474 if ( v18 == -1 ) | 445 if ( item_in_chest_count == -1 ) |
475 return 0; | 446 return 0; |
476 v22 = 0; | 447 v22 = 0; |
477 if ( v5 > 0 ) | 448 if ( v5 > 0 ) |
478 { | 449 { |
479 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, (unsigned int)pChestWindow->ptr_1C) ) | 450 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, pChestWindow->par1C) ) |
480 { | 451 { |
481 ++v22; | 452 ++v22; |
482 if ( v22 >= v5 ) | 453 if ( v22 >= v5 ) |
483 goto LABEL_8; | 454 goto LABEL_8; |
484 } | 455 } |
513 v20 = v13; | 484 v20 = v13; |
514 do | 485 do |
515 { | 486 { |
516 if ( (signed int)v12 > 0 ) | 487 if ( (signed int)v12 > 0 ) |
517 { | 488 { |
518 v14 = &pChests[0].pInventoryIndices[v21 + v23 + 2662 * uChestID]; | 489 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23]; |
519 LOWORD(v8) = -1 - v21; | 490 LOWORD(v8) = -1 - v21; |
520 v8 <<= 16; | 491 v8 <<= 16; |
521 LOWORD(v8) = -1 - v21; | 492 LOWORD(v8) = -1 - v21; |
522 memset32(v14, v8, v12 >> 1); | 493 memset32(v14, v8, v12 >> 1); |
523 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); | 494 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); |
530 v23 += v19; | 501 v23 += v19; |
531 --v20; | 502 --v20; |
532 } | 503 } |
533 while ( v20 ); | 504 while ( v20 ); |
534 } | 505 } |
535 pChests[0].pInventoryIndices[v21 + 2662 * uChestID] = v18 + 1; | 506 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1; |
536 memcpy(&pChests[uChestID].mm7__vector_pItems[v18], Src, 0x24u); | 507 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen)); |
537 result = v21 + 1; | 508 result = v21 + 1; |
538 } | 509 } |
539 else | 510 else |
540 { | 511 { |
541 result = 1; | 512 result = 1; |
543 return result; | 514 return result; |
544 } | 515 } |
545 // 506128: using guessed type int areWeLoadingTexture; | 516 // 506128: using guessed type int areWeLoadingTexture; |
546 | 517 |
547 //----- (0042013E) -------------------------------------------------------- | 518 //----- (0042013E) -------------------------------------------------------- |
548 unsigned int Chest::PlaceItemAt(unsigned int a1, unsigned int uItemIdx, unsigned int uChestID) | 519 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, unsigned int uChestID ) |
549 { | 520 { |
550 int v3; // esi@1 | 521 |
551 unsigned int v4; // ebx@1 | 522 int uItemID; // edi@1 |
552 int uItemID; // edi@1 | 523 int v6; // edx@4 |
553 int v6; // edx@4 | 524 unsigned int v7; // eax@5 |
554 unsigned int v7; // eax@5 | 525 Texture *v8; // ecx@5 |
555 Texture *v8; // ecx@5 | 526 signed int v9; // eax@5 |
556 signed int v9; // eax@5 | 527 signed int v10; // edi@7 |
557 signed int v10; // edi@7 | 528 unsigned int texture_cell_width; // ebx@7 |
558 unsigned int v11; // ebx@7 | 529 int textute_cell_height; // edi@9 |
559 int v12; // edi@9 | 530 int chest_cell_row_pos; // edx@12 |
560 int v13; // edx@12 | 531 int chest_cell_width; // [sp+10h] [bp-Ch]@11 |
561 void *v14; // edi@14 | 532 |
562 int v15; // edi@14 | 533 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID; |
563 int i; // ecx@14 | 534 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]); |
564 unsigned int result; // eax@18 | 535 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges) |
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 { | 536 { |
614 *(short *)v15 = v3; | 537 v6 = rand() % 21 + 10; |
615 v15 += 2; | 538 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6; |
616 } | 539 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6; |
617 } | 540 } |
618 v13 += v19; | 541 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
619 --v20; | 542 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0); |
620 } | 543 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); |
621 while ( v20 ); | 544 if ( v9 < 14 ) |
622 } | 545 v9 = 14; |
623 result = v21 + 2662 * uChestID; | 546 v10 = v8->uTextureHeight; |
624 pChests[0].pInventoryIndices[result] = v18 + 1; | 547 texture_cell_width = ((v9 - 14) >> 5) + 1; |
625 return result; | 548 if ( v10 < 14 ) |
626 } | 549 v10 = 14; |
550 textute_cell_height = ((v10 - 14) >> 5) + 1; | |
551 if ( !areWeLoadingTexture ) | |
552 { | |
553 v8->Release(); | |
554 pIcons_LOD->_40F9C5(); | |
555 } | |
556 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; | |
557 chest_cell_row_pos = 0; | |
558 for(int i=0; i<textute_cell_height; ++i) | |
559 { | |
560 for (int j=0; j<texture_cell_width; ++j) | |
561 { | |
562 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1); | |
563 } | |
564 chest_cell_row_pos += chest_cell_width; | |
565 } | |
566 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1; | |
567 } | |
627 // 506128: using guessed type int areWeLoadingTexture; | 568 // 506128: using guessed type int areWeLoadingTexture; |
628 | 569 |
629 //----- (00420284) -------------------------------------------------------- | 570 //----- (00420284) -------------------------------------------------------- |
630 char *Chest::_420284(unsigned int uChestID) | 571 void Chest::PlaceItems( unsigned int uChestID ) |
631 { | 572 { |
632 int v1; // ebx@1 | 573 int uChestArea; // edi@1 |
633 unsigned int v2; // esi@1 | 574 int random_chest_pos; // eax@2 |
634 unsigned int v3; // esi@1 | 575 int test_position; // ebx@11 |
635 int uChestArea; // edi@1 | 576 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 |
636 int v5; // eax@2 | 577 int chest_item_id; // [sp+9Ch] [bp-10h]@10 |
637 int v6; // ebx@11 | 578 unsigned int items_counter; // [sp+A4h] [bp-8h]@8 |
638 char *result; // eax@18 | 579 |
639 char Dst[144]; // [sp+Ch] [bp-A0h]@1 | 580 pRenderer->ClearZBuffer(0, 479); |
640 int v9; // [sp+9Ch] [bp-10h]@10 | 581 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; |
641 unsigned int v10; // [sp+A0h] [bp-Ch]@1 | 582 memset(chest_cells_map, 0, 144); |
642 unsigned int v11; // [sp+A4h] [bp-8h]@8 | 583 //fill cell map at random positions |
643 ItemGen *v12; // [sp+A8h] [bp-4h]@9 | 584 for (items_counter = 0; items_counter<uChestArea; ++items_counter) |
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 { | 585 { |
681 ++v6; | 586 //get random position in chest |
682 if ( v6 >= uChestArea ) | 587 do |
683 break; | 588 random_chest_pos = (unsigned __int8)rand(); |
684 } | 589 while ( random_chest_pos >= uChestArea ); |
685 if(v6<uChestArea) | 590 //if this pos occupied move to next |
686 { | 591 while ( chest_cells_map[random_chest_pos] ) |
687 Chest::PlaceItemAt((unsigned __int8)Dst[v6], v11, v10); | 592 { |
688 if ( pChests[v3].uFlags & 4 ) | 593 ++random_chest_pos; |
689 v12->SetIdentified(); | 594 if ( random_chest_pos == uChestArea ) |
690 } | 595 random_chest_pos = 0; |
691 } | 596 } |
692 ++v11; | 597 chest_cells_map[random_chest_pos] = items_counter; |
693 ++v12; | 598 } |
694 } | 599 items_counter = 0; |
695 while ( (signed int)v11 < uChestArea ); | 600 |
696 } | 601 for (items_counter = 0; items_counter<uChestArea; ++items_counter) |
697 result = (char *)&pChests[v3].uFlags; | 602 { |
698 pChests[v3].uFlags = pChests[v3].uFlags & 0xFFFB | 2; | 603 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID; |
699 return result; | 604 if ( chest_item_id ) |
700 } | 605 { |
606 test_position = 0; | |
607 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) | |
608 { | |
609 ++test_position; | |
610 if ( test_position >= uChestArea ) | |
611 break; | |
612 } | |
613 if(test_position<uChestArea) | |
614 { | |
615 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID); | |
616 if ( pChests[uChestID].uFlags & 4 ) | |
617 pChests[uChestID].igChestItems[items_counter].SetIdentified(); | |
618 } | |
619 } | |
620 } | |
621 pChests[uChestID].SetInitialized(true); | |
622 } | |
701 // 420284: using guessed type char Dst[144]; | 623 // 420284: using guessed type char Dst[144]; |
702 | 624 |
703 //----- (00458B03) -------------------------------------------------------- | 625 //----- (00458B03) -------------------------------------------------------- |
704 void ChestList::ToFile() | 626 void ChestList::ToFile() |
705 { | 627 { |
799 } | 721 } |
800 } | 722 } |
801 fclose(File); | 723 fclose(File); |
802 return 1; | 724 return 1; |
803 } | 725 } |
726 | |
727 //----- (00420B13) -------------------------------------------------------- | |
728 void __fastcall sub_420B13(int a1, int a2) | |
729 { | |
730 void *v2; // eax@1 | |
731 ItemGen *v3; // ebx@1 | |
732 unsigned int v4; // eax@1 | |
733 Texture *v5; // ecx@1 | |
734 signed int v6; // eax@1 | |
735 signed int v7; // edi@3 | |
736 signed int v8; // eax@3 | |
737 int v9; // edi@3 | |
738 int v10; // eax@5 | |
739 int v11; // esi@8 | |
740 unsigned int v12; // ecx@10 | |
741 void *v13; // edi@10 | |
742 unsigned __int8 v14; // cf@10 | |
743 int v15; // edi@10 | |
744 int i; // ecx@10 | |
745 int v17; // [sp+Ch] [bp-14h]@1 | |
746 int v18; // [sp+10h] [bp-10h]@3 | |
747 int v19; // [sp+14h] [bp-Ch]@1 | |
748 void *v20; // [sp+18h] [bp-8h]@1 | |
749 int v21; // [sp+1Ch] [bp-4h]@5 | |
750 int v22; // [sp+1Ch] [bp-4h]@8 | |
751 | |
752 v19 = a2; | |
753 v2 = pChestWindow->ptr_1C; | |
754 v20 = v2; | |
755 v2 = (void *)(5324 * (int)v2); | |
756 v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4)); | |
757 v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)]; | |
758 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v3->uItemID].pIconName, TEXTURE_16BIT_PALETTE); | |
759 v5 = (Texture *)(v4 != -1 ? (int)&pIcons_LOD->pTextures[v4] : 0); | |
760 v6 = (v4 != -1 ? pIcons_LOD->pTextures[v4].uTextureWidth : 24); | |
761 if ( v6 < 14 ) | |
762 v6 = 14; | |
763 v7 = v6 - 14; | |
764 v8 = v5->uTextureHeight; | |
765 v9 = (v7 >> 5) + 1; | |
766 v18 = v9; | |
767 if ( v8 < 14 ) | |
768 v8 = 14; | |
769 v10 = ((v8 - 14) >> 5) + 1; | |
770 v21 = v10; | |
771 if ( !areWeLoadingTexture ) | |
772 { | |
773 v5->Release(); | |
774 pIcons_LOD->_40F9C5(); | |
775 v10 = v21; | |
776 } | |
777 if ( v10 > 0 ) | |
778 { | |
779 v11 = 0; | |
780 v22 = v10; | |
781 do | |
782 { | |
783 if ( v9 > 0 ) | |
784 { | |
785 v12 = v9; | |
786 v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20]; | |
787 v14 = v12 & 1; | |
788 v12 >>= 1; | |
789 memset(v13, 0, 4 * v12); | |
790 v15 = (int)((char *)v13 + 4 * v12); | |
791 for ( i = v14; i; --i ) | |
792 { | |
793 *(short *)v15 = 0; | |
794 v15 += 2; | |
795 } | |
796 v9 = v18; | |
797 } | |
798 v11 += v17; | |
799 --v22; | |
800 } | |
801 while ( v22 ); | |
802 } | |
803 v3->Reset(); | |
804 } | |
805 // 506128: using guessed type int areWeLoadingTexture; |