Mercurial > mm7
comparison Chest.cpp @ 526:214d9d47cf1f
Chest working, but items are not laid correctly
author | Gloval |
---|---|
date | Sun, 03 Mar 2013 01:55:57 +0400 |
parents | cb0ad52d6a26 |
children | b1598f110b07 8e34868c8069 |
comparison
equal
deleted
inserted
replaced
525:e7b3fa10d58d | 526:214d9d47cf1f |
---|---|
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 |
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); |
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 cells_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 (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)); | |
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 v17 = test_cell_position; | |
337 | |
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; | |
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 | 393 { |
267 unsigned int v7; // eax@4 | 394 item_count = -1; |
268 Texture *v8; // esi@4 | 395 } |
269 signed int v9; // ecx@4 | 396 else |
270 signed int v10; // edx@4 | 397 { |
271 signed int v11; // eax@4 | 398 while ( pChests[uChestID].igChestItems[item_count].uItemID ) |
272 int v12; // eax@6 | 399 { |
273 int v13; // eax@6 | 400 ++item_count; |
274 unsigned int v14; // ST34_4@8 | 401 if ( item_count >= max_items ) |
275 int v15; // edi@8 | 402 { |
276 int *v16; // [sp+Ch] [bp-28h]@1 | 403 item_count = -1; |
277 int v17; // [sp+10h] [bp-24h]@4 | 404 break; |
278 int v18; // [sp+14h] [bp-20h]@1 | 405 } |
279 signed int v19; // [sp+18h] [bp-1Ch]@1 | 406 } |
280 int v20; // [sp+1Ch] [bp-18h]@1 | 407 } |
281 signed int v21; // [sp+20h] [bp-14h]@1 | 408 return item_count; |
282 char *v22; // [sp+2Ch] [bp-8h]@2 | |
283 signed int v23; // [sp+30h] [bp-4h]@1 | |
284 | |
285 v1 = pRenderer; | |
286 v2 = uChestID; | |
287 v16 = pRenderer->pActiveZBuffer; | |
288 pRenderer->ClearZBuffer(0, 479); | |
289 v3 = v2; | |
290 v4 = pChests[v3].uChestBitmapID; | |
291 v20 = pChestSmthn1ByType[v4]; | |
292 v18 = pChestSmthn2ByType[v4]; | |
293 v21 = pChestWidthsByType[v4]; | |
294 v19 = pChestHeightsByType[v4]; | |
295 sprintf(pTmpBuf, "chest%02d", pChestList->pChests[pChests[v3].uChestBitmapID].uTextureID); | |
296 v5 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE); | |
297 pRenderer->DrawTextureIndexed(8u, 8u, (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0)); | |
298 v23 = 0; | |
299 if ( v21 * v19 > 0 ) | |
300 { | |
301 v22 = (char *)pChests[v3].pInventoryIndices; | |
302 do | |
303 { | |
304 v6 = *(short *)v22; | |
305 if ( v6 > 0 ) | |
306 { | |
307 v17 = v18 + 32 * v23 / v19; | |
308 v7 = pIcons_LOD->LoadTexture( | |
309 pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName, | |
310 TEXTURE_16BIT_PALETTE); | |
311 v8 = (Texture *)(v7 != -1 ? &pIcons_LOD->pTextures[v7] : 0); | |
312 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); | |
313 v10 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureHeight : 26); | |
314 v11 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); | |
315 if ( v9 < 14 ) | |
316 v11 = 14; | |
317 v12 = v11 - 14; | |
318 LOBYTE(v12) = v12 & 0xE0; | |
319 v13 = v12 + 32; | |
320 if ( (signed int)v8->uTextureHeight < 14 ) | |
321 v10 = 14; | |
322 v14 = v20 + 32 * v23 % v21 + ((v13 - v9) >> 1); | |
323 v15 = v17 + ((((v10 - 14) & 0xFFFFFFE0) - v8->uTextureHeight + 32) >> 1); | |
324 pRenderer->DrawTextureTransparent( | |
325 v14, | |
326 v17 + ((((v10 - 14) & 0xFFFFFFE0) - v8->uTextureHeight + 32) >> 1), | |
327 v8); | |
328 sub_40F92A(&v16[v14 + pSRZBufferLineOffsets[v15]], v8, v23 + 1); | |
329 v1 = pRenderer; | |
330 } | |
331 ++v23; | |
332 v22 += 2; | |
333 } | |
334 while ( v23 < v21 * v19 ); | |
335 } | |
336 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, | |
337 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0)); | |
338 } | 409 } |
339 | 410 |
340 | |
341 //----- (0041FE71) -------------------------------------------------------- | |
342 int Chest::CanPlaceItemAt(signed int a1, int a2, unsigned int uChestID) | |
343 { | |
344 int v3; // eax@1 | |
345 unsigned int v4; // eax@1 | |
346 Texture *v5; // ecx@1 | |
347 signed int v6; // eax@1 | |
348 signed int v7; // edi@3 | |
349 signed int v8; // eax@3 | |
350 int v9; // edi@3 | |
351 int v10; // ebx@5 | |
352 int v11; // esi@9 | |
353 int v12; // edx@10 | |
354 int v13; // ecx@11 | |
355 char *v14; // eax@12 | |
356 int v16; // [sp+Ch] [bp-Ch]@1 | |
357 signed int v17; // [sp+10h] [bp-8h]@1 | |
358 signed int v18; // [sp+14h] [bp-4h]@1 | |
359 | |
360 v17 = a1; | |
361 v3 = pChests[uChestID].uChestBitmapID; | |
362 v16 = pChestHeightsByType[v3]; | |
363 v18 = pChestWidthsByType[v3]; | |
364 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[a2].pIconName, TEXTURE_16BIT_PALETTE); | |
365 v5 = (Texture *)(v4 != -1 ? (int)&pIcons_LOD->pTextures[v4] : 0); | |
366 v6 = (v4 != -1 ? pIcons_LOD->pTextures[v4].uTextureWidth : 24); | |
367 if ( v6 < 14 ) | |
368 v6 = 14; | |
369 v7 = v6 - 14; | |
370 v8 = v5->uTextureHeight; | |
371 v9 = (v7 >> 5) + 1; | |
372 if ( v8 < 14 ) | |
373 v8 = 14; | |
374 v10 = ((v8 - 14) >> 5) + 1; | |
375 if ( !areWeLoadingTexture ) | |
376 { | |
377 v5->Release(); | |
378 pIcons_LOD->_40F9C5(); | |
379 } | |
380 if ( v9 + v17 % v18 <= v18 && v10 + v17 / v18 <= v16 ) | |
381 { | |
382 v11 = 0; | |
383 if ( v10 <= 0 ) | |
384 return 1; | |
385 v12 = 0; | |
386 while ( 1 ) | |
387 { | |
388 v13 = 0; | |
389 if ( v9 > 0 ) | |
390 break; | |
391 LABEL_15: | |
392 v12 += v18; | |
393 ++v11; | |
394 if ( v11 >= v10 ) | |
395 return 1; | |
396 } | |
397 v14 = (char *)&pChests[0].pInventoryIndices[v17 + v12 + 2662 * uChestID]; | |
398 while ( !*(short *)v14 ) | |
399 { | |
400 ++v13; | |
401 v14 += 2; | |
402 if ( v13 >= v9 ) | |
403 goto LABEL_15; | |
404 } | |
405 } | |
406 return 0; | |
407 } | |
408 // 506128: using guessed type int areWeLoadingTexture; | |
409 | |
410 //----- (0041FF64) -------------------------------------------------------- | |
411 int Chest::_41FF64(unsigned int uChestID) | |
412 { | |
413 unsigned int v1; // ecx@1 | |
414 signed int result; // eax@1 | |
415 int v3; // edx@1 | |
416 ItemGen *pItem; // ecx@2 | |
417 | |
418 v1 = uChestID; | |
419 result = 0; | |
420 v3 = pChestWidthsByType[pChests[v1].uChestBitmapID] * pChestHeightsByType[pChests[v1].uChestBitmapID]; | |
421 if ( v3 <= 0 ) | |
422 { | |
423 LABEL_5: | |
424 result = -1; | |
425 } | |
426 else | |
427 { | |
428 pItem = pChests[v1].mm7__vector_pItems; | |
429 while ( pItem->uItemID ) | |
430 { | |
431 ++result; | |
432 ++pItem; | |
433 if ( result >= v3 ) | |
434 goto LABEL_5; | |
435 } | |
436 } | |
437 return result; | |
438 } | |
439 | |
440 //----- (0041FFA2) -------------------------------------------------------- | 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 uItemIdx, unsigned int uChestID ) |
549 { | 520 { |
550 int v3; // esi@1 | 521 int v3; // esi@1 |
551 unsigned int v4; // ebx@1 | 522 unsigned int v4; // ebx@1 |
552 int uItemID; // edi@1 | 523 int uItemID; // edi@1 |
553 int v6; // edx@4 | 524 int v6; // edx@4 |
554 unsigned int v7; // eax@5 | 525 unsigned int v7; // eax@5 |
566 int v19; // [sp+10h] [bp-Ch]@11 | 537 int v19; // [sp+10h] [bp-Ch]@11 |
567 int v20; // [sp+14h] [bp-8h]@12 | 538 int v20; // [sp+14h] [bp-8h]@12 |
568 unsigned int v21; // [sp+18h] [bp-4h]@1 | 539 unsigned int v21; // [sp+18h] [bp-4h]@1 |
569 | 540 |
570 v3 = 5324 * uChestID; | 541 v3 = 5324 * uChestID; |
571 v21 = a1; | 542 v21 = put_cell_pos; |
572 v4 = 5324 * uChestID + 36 * uItemIdx; | 543 v4 = 5324 * uChestID + 36 * uItemIdx; |
573 v18 = uItemIdx; | 544 v18 = uItemIdx; |
574 uItemID = *(unsigned int *)((char *)&pChests[0].mm7__vector_pItems[0].uItemID + v4); | 545 uItemID = pChests[ uChestID].igChestItems[uItemIdx].uItemID; |
575 pItemsTable->SetSpecialBonus((ItemGen *)((char *)pChests[0].mm7__vector_pItems + v4)); | 546 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[uItemIdx]); |
576 if ( uItemID >= 135 && uItemID <= 159 && !*(int *)((char *)&pChests[0].mm7__vector_pItems[0].uNumCharges + v4) ) | 547 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[uItemIdx].uNumCharges) |
577 { | 548 { |
578 v6 = rand() % 21 + 10; | 549 v6 = rand() % 21 + 10; |
579 *(int *)((char *)&pChests[0].mm7__vector_pItems[0].uNumCharges + v4) = v6; | 550 pChests[ uChestID].igChestItems[uItemIdx].uNumCharges = v6; |
580 *(&pChests[0].mm7__vector_pItems[0].uMaxCharges + v4) = v6; | 551 pChests[ uChestID].igChestItems[uItemIdx].uMaxCharges = v6; |
581 } | 552 } |
582 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); | 553 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
583 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0); | 554 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0); |
584 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); | 555 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); |
585 if ( v9 < 14 ) | 556 if ( v9 < 14 ) |
592 if ( !areWeLoadingTexture ) | 563 if ( !areWeLoadingTexture ) |
593 { | 564 { |
594 v8->Release(); | 565 v8->Release(); |
595 pIcons_LOD->_40F9C5(); | 566 pIcons_LOD->_40F9C5(); |
596 } | 567 } |
597 v19 = pChestWidthsByType[*(unsigned __int16 *)((char *)&pChests[0].uChestBitmapID + v3)]; | 568 v19 = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; |
598 if ( v12 > 0 ) | 569 if ( v12 > 0 ) |
599 { | 570 { |
600 v13 = 0; | 571 v13 = 0; |
601 v20 = v12; | 572 v20 = v12; |
602 do | 573 do |
603 { | 574 { |
604 if ( (signed int)v11 > 0 ) | 575 if ( (signed int)v11 > 0 ) |
605 { | 576 { |
606 v14 = &pChests[0].pInventoryIndices[v21 + v13 + 2662 * uChestID]; | 577 v14 = &pChests[uChestID].pInventoryIndices[v21 + v13]; |
607 LOWORD(v3) = -1 - v21; | 578 LOWORD(v3) = -1 - v21; |
608 v3 <<= 16; | 579 v3 <<= 16; |
609 LOWORD(v3) = -1 - v21; | 580 LOWORD(v3) = -1 - v21; |
610 memset32(v14, v3, v11 >> 1); | 581 memset32(v14, v3, v11 >> 1); |
611 v15 = (int)((char *)v14 + 4 * (v11 >> 1)); | 582 v15 = (int)((char *)v14 + 4 * (v11 >> 1)); |
617 } | 588 } |
618 v13 += v19; | 589 v13 += v19; |
619 --v20; | 590 --v20; |
620 } | 591 } |
621 while ( v20 ); | 592 while ( v20 ); |
622 } | 593 } |
623 result = v21 + 2662 * uChestID; | 594 pChests[uChestID].pInventoryIndices[v21] = v18 + 1; |
624 pChests[0].pInventoryIndices[result] = v18 + 1; | |
625 return result; | |
626 } | 595 } |
627 // 506128: using guessed type int areWeLoadingTexture; | 596 // 506128: using guessed type int areWeLoadingTexture; |
628 | 597 |
629 //----- (00420284) -------------------------------------------------------- | 598 //----- (00420284) -------------------------------------------------------- |
630 char *Chest::_420284(unsigned int uChestID) | 599 void Chest::PlaceItems( unsigned int uChestID ) |
631 { | 600 { |
632 int v1; // ebx@1 | 601 int uChestArea; // edi@1 |
633 unsigned int v2; // esi@1 | 602 int random_chest_pos; // eax@2 |
634 unsigned int v3; // esi@1 | 603 int test_position; // ebx@11 |
635 int uChestArea; // edi@1 | 604 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 |
636 int v5; // eax@2 | 605 int chest_item_id; // [sp+9Ch] [bp-10h]@10 |
637 int v6; // ebx@11 | 606 unsigned int cell_counter; // [sp+A4h] [bp-8h]@8 |
638 char *result; // eax@18 | 607 |
639 char Dst[144]; // [sp+Ch] [bp-A0h]@1 | 608 pRenderer->ClearZBuffer(0, 479); |
640 int v9; // [sp+9Ch] [bp-10h]@10 | 609 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; |
641 unsigned int v10; // [sp+A0h] [bp-Ch]@1 | 610 memset(chest_cells_map, 0, 144); |
642 unsigned int v11; // [sp+A4h] [bp-8h]@8 | 611 //fill cell map at random positions |
643 ItemGen *v12; // [sp+A8h] [bp-4h]@9 | 612 for (cell_counter = 0; cell_counter<uChestArea; ++cell_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 { | 613 { |
681 ++v6; | 614 //get random position in chest |
682 if ( v6 >= uChestArea ) | 615 do |
683 break; | 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; | |
684 } | 626 } |
685 if(v6<uChestArea) | 627 cell_counter = 0; |
686 { | 628 |
687 Chest::PlaceItemAt((unsigned __int8)Dst[v6], v11, v10); | 629 for (cell_counter = 0; cell_counter<uChestArea; ++cell_counter) |
688 if ( pChests[v3].uFlags & 4 ) | 630 { |
689 v12->SetIdentified(); | 631 chest_item_id = pChests[uChestID].igChestItems[cell_counter].uItemID; |
690 } | 632 if ( chest_item_id ) |
691 } | 633 { |
692 ++v11; | 634 test_position = 0; |
693 ++v12; | 635 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) |
694 } | 636 { |
695 while ( (signed int)v11 < uChestArea ); | 637 ++test_position; |
696 } | 638 if ( test_position >= uChestArea ) |
697 result = (char *)&pChests[v3].uFlags; | 639 break; |
698 pChests[v3].uFlags = pChests[v3].uFlags & 0xFFFB | 2; | 640 } |
699 return result; | 641 if(test_position<uChestArea) |
700 } | 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; | |
650 } | |
701 // 420284: using guessed type char Dst[144]; | 651 // 420284: using guessed type char Dst[144]; |
702 | 652 |
703 //----- (00458B03) -------------------------------------------------------- | 653 //----- (00458B03) -------------------------------------------------------- |
704 void ChestList::ToFile() | 654 void ChestList::ToFile() |
705 { | 655 { |
799 } | 749 } |
800 } | 750 } |
801 fclose(File); | 751 fclose(File); |
802 return 1; | 752 return 1; |
803 } | 753 } |
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; |