Mercurial > mm7
comparison Chest.cpp @ 542:8e34868c8069
Слияние
author | Ritor1 |
---|---|
date | Sun, 03 Mar 2013 13:32:04 +0600 |
parents | db4631a484ae 214d9d47cf1f |
children | ec3546510fa1 |
comparison
equal
deleted
inserted
replaced
541:cf5609edbc45 | 542:8e34868c8069 |
---|---|
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); |
85 if ((uChestID <0)&&(uChestID >=20) ) | |
86 return false; | |
82 auto chest = &pChests[uChestID]; | 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::PlacementItems(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); |
218 word_A750E0 = 5; | 223 word_A750E0 = 5; |
219 word_A750E2 = uActiveCharacter; | 224 word_A750E2 = uActiveCharacter; |
220 } | 225 } |
221 pIcons_LOD->_4114F2(); | 226 pIcons_LOD->_4114F2(); |
222 dword_507CD8 = 0; | 227 dword_507CD8 = 0; |
223 return false; | 228 return 0; |
224 } | 229 } |
225 chest->SetInitialized(false);//*v1 &= 0xFEu; | 230 chest->SetInitialized(false);//*v1 &= 0xFEu; |
226 sRotY = 1; | 231 sRotY = 1; |
227 LABEL_12: | 232 LABEL_12: |
228 pAudioPlayer->StopChannels(-1, -1); | 233 pAudioPlayer->StopChannels(-1, -1); |
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, 640, 480, WINDOW_Chest, uChestID, 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(0x1D7u, 0x1BDu, 0xA9u, 0x23u, 1, 0, 0x71u, 0, 0, pGlobalTXT_LocalizationStrings[79],// Exit | 244 pBtn_ExitCancel = pChestWindow->CreateButton(0x1D7u, 0x1BDu, 0xA9u, 0x23u, 1, 0, 0x71u, 0, 0, pGlobalTXT_LocalizationStrings[79],// Exit |
240 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0), 0); | 245 (Texture *)(uExitCancelTextureId != -1 ? (int)&pIcons_LOD->pTextures[uExitCancelTextureId] : 0), 0); |
241 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); |
242 pCurrentScreen = SCREEN_CHEST; | 247 pCurrentScreen = SCREEN_CHEST; |
243 pEventTimer->Pause(); | 248 pEventTimer->Pause(); |
244 return true; | 249 return 1; |
245 } | 250 } |
246 | 251 |
247 //----- (0042092D) -------------------------------------------------------- | 252 //----- (0042092D) -------------------------------------------------------- |
248 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) | |
249 { | 387 { |
250 Render *v1; // edi@1 | 388 signed int item_count; // eax@1 |
251 unsigned int v2; // ebx@1 | 389 int max_items; // edx@1 |
252 unsigned int v3; // ebx@1 | 390 item_count = 0; |
253 int v4; // eax@1 | 391 max_items = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; |
254 unsigned int v5; // eax@1 | 392 if ( max_items <= 0 ) |
255 int v6; // ecx@3 | 393 { |
256 unsigned int v7; // eax@4 | 394 item_count = -1; |
257 Texture *v8; // esi@4 | 395 } |
258 signed int v9; // ecx@4 | 396 else |
259 signed int v10; // edx@4 | 397 { |
260 signed int v11; // eax@4 | 398 while ( pChests[uChestID].igChestItems[item_count].uItemID ) |
261 int v12; // eax@6 | 399 { |
262 int v13; // eax@6 | 400 ++item_count; |
263 unsigned int v14; // ST34_4@8 | 401 if ( item_count >= max_items ) |
264 int v15; // edi@8 | 402 { |
265 int *v16; // [sp+Ch] [bp-28h]@1 | 403 item_count = -1; |
266 int v17; // [sp+10h] [bp-24h]@4 | 404 break; |
267 int v18; // [sp+14h] [bp-20h]@1 | 405 } |
268 signed int v19; // [sp+18h] [bp-1Ch]@1 | 406 } |
269 int v20; // [sp+1Ch] [bp-18h]@1 | 407 } |
270 signed int v21; // [sp+20h] [bp-14h]@1 | 408 return item_count; |
271 char *v22; // [sp+2Ch] [bp-8h]@2 | |
272 signed int v23; // [sp+30h] [bp-4h]@1 | |
273 | |
274 v1 = pRenderer; | |
275 v2 = uChestID; | |
276 v16 = pRenderer->pActiveZBuffer; | |
277 pRenderer->ClearZBuffer(0, 479); | |
278 v3 = v2; | |
279 v4 = pChests[v3].uChestBitmapID; | |
280 v20 = pChestSmthn1ByType[v4]; | |
281 v18 = pChestSmthn2ByType[v4]; | |
282 v21 = pChestWidthsByType[v4]; | |
283 v19 = pChestHeightsByType[v4]; | |
284 sprintf(pTmpBuf, "chest%02d", pChestList->pChests[pChests[v3].uChestBitmapID].uTextureID); | |
285 v5 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE); | |
286 pRenderer->DrawTextureIndexed(8u, 8u, (Texture *)(v5 != -1 ? (int)&pIcons_LOD->pTextures[v5] : 0)); | |
287 v23 = 0; | |
288 if ( v21 * v19 > 0 ) | |
289 { | |
290 v22 = (char *)pChests[v3].pInventoryIndices; | |
291 do | |
292 { | |
293 v6 = *(short *)v22; | |
294 if ( v6 > 0 ) | |
295 { | |
296 v17 = v18 + 32 * v23 / v19; | |
297 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[*(int *)((char *)&pChests[v3].mm7__vector_pItems[v6 - 1].uItemID)].pIconName, | |
298 TEXTURE_16BIT_PALETTE); | |
299 v8 = (Texture *)(v7 != -1 ? &pIcons_LOD->pTextures[v7] : 0); | |
300 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); | |
301 v10 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureHeight : 26); | |
302 v11 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); | |
303 if ( v9 < 14 ) | |
304 v11 = 14; | |
305 v12 = v11 - 14; | |
306 LOBYTE(v12) = v12 & 0xE0; | |
307 v13 = v12 + 32; | |
308 if ( (signed int)v8->uTextureHeight < 14 ) | |
309 v10 = 14; | |
310 v14 = v20 + 32 * v23 % v21 + ((v13 - v9) >> 1); | |
311 v15 = v17 + ((((v10 - 14) & 0xFFFFFFE0) - v8->uTextureHeight + 32) >> 1); | |
312 pRenderer->DrawTextureTransparent( | |
313 v14, | |
314 v17 + ((((v10 - 14) & 0xFFFFFFE0) - v8->uTextureHeight + 32) >> 1), | |
315 v8); | |
316 sub_40F92A(&v16[v14 + pSRZBufferLineOffsets[v15]], v8, v23 + 1); | |
317 v1 = pRenderer; | |
318 } | |
319 ++v23; | |
320 v22 += 2; | |
321 } | |
322 while ( v23 < v21 * v19 ); | |
323 } | |
324 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, | |
325 (Texture *)(uTextureID_506438 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_506438] : 0)); | |
326 } | 409 } |
327 | 410 |
328 | |
329 //----- (0041FE71) -------------------------------------------------------- | |
330 int Chest::CanPlaceItemAt(signed int a1, int a2, unsigned int uChestID) | |
331 { | |
332 int v3; // eax@1 | |
333 unsigned int v4; // eax@1 | |
334 Texture *v5; // ecx@1 | |
335 signed int v6; // eax@1 | |
336 signed int v7; // edi@3 | |
337 signed int v8; // eax@3 | |
338 int v9; // edi@3 | |
339 int v10; // ebx@5 | |
340 int v11; // esi@9 | |
341 int v12; // edx@10 | |
342 int v13; // ecx@11 | |
343 char *v14; // eax@12 | |
344 int v16; // [sp+Ch] [bp-Ch]@1 | |
345 signed int v17; // [sp+10h] [bp-8h]@1 | |
346 signed int v18; // [sp+14h] [bp-4h]@1 | |
347 | |
348 v17 = a1; | |
349 v3 = pChests[uChestID].uChestBitmapID; | |
350 v16 = pChestHeightsByType[v3]; | |
351 v18 = pChestWidthsByType[v3]; | |
352 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[a2].pIconName, TEXTURE_16BIT_PALETTE); | |
353 v5 = (Texture *)(v4 != -1 ? (int)&pIcons_LOD->pTextures[v4] : 0); | |
354 v6 = (v4 != -1 ? pIcons_LOD->pTextures[v4].uTextureWidth : 24); | |
355 if ( v6 < 14 ) | |
356 v6 = 14; | |
357 v7 = v6 - 14; | |
358 v8 = v5->uTextureHeight; | |
359 v9 = (v7 >> 5) + 1; | |
360 if ( v8 < 14 ) | |
361 v8 = 14; | |
362 v10 = ((v8 - 14) >> 5) + 1; | |
363 if ( !areWeLoadingTexture ) | |
364 { | |
365 v5->Release(); | |
366 pIcons_LOD->_40F9C5(); | |
367 } | |
368 if ( v9 + v17 % v18 <= v18 && v10 + v17 / v18 <= v16 ) | |
369 { | |
370 v11 = 0; | |
371 if ( v10 <= 0 ) | |
372 return 1; | |
373 v12 = 0; | |
374 while ( 1 ) | |
375 { | |
376 v13 = 0; | |
377 if ( v9 > 0 ) | |
378 break; | |
379 LABEL_15: | |
380 v12 += v18; | |
381 ++v11; | |
382 if ( v11 >= v10 ) | |
383 return 1; | |
384 } | |
385 v14 = (char *)&pChests[0].pInventoryIndices[v17 + v12 + 2662 * uChestID]; | |
386 while ( !*(short *)v14 ) | |
387 { | |
388 ++v13; | |
389 v14 += 2; | |
390 if ( v13 >= v9 ) | |
391 goto LABEL_15; | |
392 } | |
393 } | |
394 return 0; | |
395 } | |
396 // 506128: using guessed type int areWeLoadingTexture; | |
397 | |
398 //----- (0041FF64) -------------------------------------------------------- | |
399 int Chest::_41FF64(unsigned int uChestID) | |
400 { | |
401 unsigned int v1; // ecx@1 | |
402 signed int result; // eax@1 | |
403 int v3; // edx@1 | |
404 ItemGen *pItem; // ecx@2 | |
405 | |
406 v1 = uChestID; | |
407 result = 0; | |
408 v3 = pChestWidthsByType[pChests[v1].uChestBitmapID] * pChestHeightsByType[pChests[v1].uChestBitmapID]; | |
409 if ( v3 <= 0 ) | |
410 { | |
411 LABEL_5: | |
412 result = -1; | |
413 } | |
414 else | |
415 { | |
416 pItem = pChests[v1].mm7__vector_pItems; | |
417 while ( pItem->uItemID ) | |
418 { | |
419 ++result; | |
420 ++pItem; | |
421 if ( result >= v3 ) | |
422 goto LABEL_5; | |
423 } | |
424 } | |
425 return result; | |
426 } | |
427 | |
428 //----- (0041FFA2) -------------------------------------------------------- | 411 //----- (0041FFA2) -------------------------------------------------------- |
429 int Chest::_41FFA2(int a1, ItemGen *a2, unsigned int uChestID) | 412 int Chest::PutItemInChest(int position, ItemGen *put_item, unsigned int uChestID) |
430 { | 413 { |
431 int v3; // eax@1 | 414 int v3; // eax@1 |
432 ItemGen *v4; // edi@1 | 415 ItemGen *v4; // edi@1 |
433 int v5; // esi@1 | 416 int v5; // esi@1 |
434 int result; // eax@11 | 417 int result; // eax@11 |
441 int v13; // edi@16 | 424 int v13; // edi@16 |
442 void *v14; // edi@21 | 425 void *v14; // edi@21 |
443 int v15; // edi@21 | 426 int v15; // edi@21 |
444 int i; // ecx@21 | 427 int i; // ecx@21 |
445 ItemGen *Src; // [sp+Ch] [bp-18h]@1 | 428 ItemGen *Src; // [sp+Ch] [bp-18h]@1 |
446 signed int v18; // [sp+10h] [bp-14h]@2 | 429 signed int item_in_chest_count; // [sp+10h] [bp-14h]@2 |
447 int v19; // [sp+14h] [bp-10h]@1 | 430 int v19; // [sp+14h] [bp-10h]@1 |
448 int v20; // [sp+18h] [bp-Ch]@19 | 431 int v20; // [sp+18h] [bp-Ch]@19 |
449 signed int v21; // [sp+1Ch] [bp-8h]@1 | 432 signed int v21; // [sp+1Ch] [bp-8h]@1 |
450 signed int v22; // [sp+20h] [bp-4h]@3 | 433 signed int v22; // [sp+20h] [bp-4h]@3 |
451 int v23; // [sp+20h] [bp-4h]@19 | 434 int v23; // [sp+20h] [bp-4h]@19 |
452 | 435 |
453 v21 = 0; | 436 v21 = 0; |
454 v3 = pChests[uChestID].uChestBitmapID; | 437 v3 = pChests[uChestID].uChestBitmapID; |
455 v4 = a2; | 438 v4 = put_item; |
456 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3]; | 439 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3]; |
457 Src = a2; | 440 Src = put_item; |
458 v19 = pChestWidthsByType[v3]; | 441 v19 = pChestWidthsByType[v3]; |
459 if ( a1 == -1 ) | 442 if ( position == -1 ) |
460 { | 443 { |
461 v18 = _41FF64(uChestID); | 444 item_in_chest_count = CountChestItems(uChestID); |
462 if ( v18 == -1 ) | 445 if ( item_in_chest_count == -1 ) |
463 return 0; | 446 return 0; |
464 v22 = 0; | 447 v22 = 0; |
465 if ( v5 > 0 ) | 448 if ( v5 > 0 ) |
466 { | 449 { |
467 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, (unsigned int)pChestWindow->ptr_1C) ) | 450 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, pChestWindow->par1C) ) |
468 { | 451 { |
469 ++v22; | 452 ++v22; |
470 if ( v22 >= v5 ) | 453 if ( v22 >= v5 ) |
471 goto LABEL_8; | 454 goto LABEL_8; |
472 } | 455 } |
501 v20 = v13; | 484 v20 = v13; |
502 do | 485 do |
503 { | 486 { |
504 if ( (signed int)v12 > 0 ) | 487 if ( (signed int)v12 > 0 ) |
505 { | 488 { |
506 v14 = &pChests[0].pInventoryIndices[v21 + v23 + 2662 * uChestID]; | 489 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23]; |
507 LOWORD(v8) = -1 - v21; | 490 LOWORD(v8) = -1 - v21; |
508 v8 <<= 16; | 491 v8 <<= 16; |
509 LOWORD(v8) = -1 - v21; | 492 LOWORD(v8) = -1 - v21; |
510 memset32(v14, v8, v12 >> 1); | 493 memset32(v14, v8, v12 >> 1); |
511 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); | 494 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); |
518 v23 += v19; | 501 v23 += v19; |
519 --v20; | 502 --v20; |
520 } | 503 } |
521 while ( v20 ); | 504 while ( v20 ); |
522 } | 505 } |
523 pChests[0].pInventoryIndices[v21 + 2662 * uChestID] = v18 + 1; | 506 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1; |
524 memcpy(&pChests[uChestID].mm7__vector_pItems[v18], Src, 0x24u); | 507 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen)); |
525 result = v21 + 1; | 508 result = v21 + 1; |
526 } | 509 } |
527 else | 510 else |
528 { | 511 { |
529 result = 1; | 512 result = 1; |
531 return result; | 514 return result; |
532 } | 515 } |
533 // 506128: using guessed type int areWeLoadingTexture; | 516 // 506128: using guessed type int areWeLoadingTexture; |
534 | 517 |
535 //----- (0042013E) -------------------------------------------------------- | 518 //----- (0042013E) -------------------------------------------------------- |
536 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 ) |
537 { | 520 { |
538 int v3; // esi@1 | 521 int v3; // esi@1 |
539 unsigned int v4; // ebx@1 | 522 unsigned int v4; // ebx@1 |
540 int uItemID; // edi@1 | 523 int uItemID; // edi@1 |
541 int v6; // edx@4 | 524 int v6; // edx@4 |
542 unsigned int v7; // eax@5 | 525 unsigned int v7; // eax@5 |
554 int v19; // [sp+10h] [bp-Ch]@11 | 537 int v19; // [sp+10h] [bp-Ch]@11 |
555 int v20; // [sp+14h] [bp-8h]@12 | 538 int v20; // [sp+14h] [bp-8h]@12 |
556 unsigned int v21; // [sp+18h] [bp-4h]@1 | 539 unsigned int v21; // [sp+18h] [bp-4h]@1 |
557 | 540 |
558 v3 = 5324 * uChestID; | 541 v3 = 5324 * uChestID; |
559 v21 = a1; | 542 v21 = put_cell_pos; |
560 v4 = 5324 * uChestID + 36 * uItemIdx; | 543 v4 = 5324 * uChestID + 36 * uItemIdx; |
561 v18 = uItemIdx; | 544 v18 = uItemIdx; |
562 uItemID = *(unsigned int *)((char *)&pChests[0].mm7__vector_pItems[0].uItemID + v4); | 545 uItemID = pChests[ uChestID].igChestItems[uItemIdx].uItemID; |
563 pItemsTable->SetSpecialBonus((ItemGen *)((char *)pChests[0].mm7__vector_pItems + v4)); | 546 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[uItemIdx]); |
564 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) |
565 { | 548 { |
566 v6 = rand() % 21 + 10; | 549 v6 = rand() % 21 + 10; |
567 *(int *)((char *)&pChests[0].mm7__vector_pItems[0].uNumCharges + v4) = v6; | 550 pChests[ uChestID].igChestItems[uItemIdx].uNumCharges = v6; |
568 *(&pChests[0].mm7__vector_pItems[0].uMaxCharges + v4) = v6; | 551 pChests[ uChestID].igChestItems[uItemIdx].uMaxCharges = v6; |
569 } | 552 } |
570 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); | 553 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
571 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0); | 554 v8 = (Texture *)(v7 != -1 ? (int)&pIcons_LOD->pTextures[v7] : 0); |
572 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); | 555 v9 = (v7 != -1 ? pIcons_LOD->pTextures[v7].uTextureWidth : 24); |
573 if ( v9 < 14 ) | 556 if ( v9 < 14 ) |
580 if ( !areWeLoadingTexture ) | 563 if ( !areWeLoadingTexture ) |
581 { | 564 { |
582 v8->Release(); | 565 v8->Release(); |
583 pIcons_LOD->_40F9C5(); | 566 pIcons_LOD->_40F9C5(); |
584 } | 567 } |
585 v19 = pChestWidthsByType[*(unsigned __int16 *)((char *)&pChests[0].uChestBitmapID + v3)]; | 568 v19 = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; |
586 if ( v12 > 0 ) | 569 if ( v12 > 0 ) |
587 { | 570 { |
588 v13 = 0; | 571 v13 = 0; |
589 v20 = v12; | 572 v20 = v12; |
590 do | 573 do |
591 { | 574 { |
592 if ( (signed int)v11 > 0 ) | 575 if ( (signed int)v11 > 0 ) |
593 { | 576 { |
594 v14 = &pChests[0].pInventoryIndices[v21 + v13 + 2662 * uChestID]; | 577 v14 = &pChests[uChestID].pInventoryIndices[v21 + v13]; |
595 LOWORD(v3) = -1 - v21; | 578 LOWORD(v3) = -1 - v21; |
596 v3 <<= 16; | 579 v3 <<= 16; |
597 LOWORD(v3) = -1 - v21; | 580 LOWORD(v3) = -1 - v21; |
598 memset32(v14, v3, v11 >> 1); | 581 memset32(v14, v3, v11 >> 1); |
599 v15 = (int)((char *)v14 + 4 * (v11 >> 1)); | 582 v15 = (int)((char *)v14 + 4 * (v11 >> 1)); |
605 } | 588 } |
606 v13 += v19; | 589 v13 += v19; |
607 --v20; | 590 --v20; |
608 } | 591 } |
609 while ( v20 ); | 592 while ( v20 ); |
610 } | 593 } |
611 result = v21 + 2662 * uChestID; | 594 pChests[uChestID].pInventoryIndices[v21] = v18 + 1; |
612 pChests[0].pInventoryIndices[result] = v18 + 1; | |
613 return result; | |
614 } | 595 } |
615 // 506128: using guessed type int areWeLoadingTexture; | 596 // 506128: using guessed type int areWeLoadingTexture; |
616 | 597 |
617 //----- (00420284) -------------------------------------------------------- | 598 //----- (00420284) -------------------------------------------------------- |
618 char *Chest::PlacementItems(unsigned int uChestID) | 599 void Chest::PlaceItems( unsigned int uChestID ) |
619 { | 600 { |
620 int v1; // ebx@1 | 601 int uChestArea; // edi@1 |
621 unsigned int v2; // esi@1 | 602 int random_chest_pos; // eax@2 |
622 unsigned int v3; // esi@1 | 603 int test_position; // ebx@11 |
623 int uChestArea; // edi@1 | 604 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 |
624 int v5; // eax@2 | 605 int chest_item_id; // [sp+9Ch] [bp-10h]@10 |
625 int v6; // ebx@11 | 606 unsigned int cell_counter; // [sp+A4h] [bp-8h]@8 |
626 char *result; // eax@18 | 607 |
627 char Dst[144]; // [sp+Ch] [bp-A0h]@1 | 608 pRenderer->ClearZBuffer(0, 479); |
628 int v9; // [sp+9Ch] [bp-10h]@10 | 609 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; |
629 unsigned int v10; // [sp+A0h] [bp-Ch]@1 | 610 memset(chest_cells_map, 0, 144); |
630 unsigned int v11; // [sp+A4h] [bp-8h]@8 | 611 //fill cell map at random positions |
631 ItemGen *v12; // [sp+A8h] [bp-4h]@9 | 612 for (cell_counter = 0; cell_counter<uChestArea; ++cell_counter) |
632 | |
633 v1 = 0; | |
634 v2 = uChestID; | |
635 v10 = uChestID; | |
636 pRenderer->ClearZBuffer(0, 479); | |
637 v3 = v2; | |
638 uChestArea = pChestWidthsByType[pChests[v3].uChestBitmapID] * pChestHeightsByType[pChests[v3].uChestBitmapID]; | |
639 memset(Dst, 0, 0x90u); | |
640 if ( uChestArea > 0 ) | |
641 { | |
642 do | |
643 { | |
644 do | |
645 v5 = (unsigned __int8)rand(); | |
646 while ( v5 >= uChestArea ); | |
647 while ( Dst[v5] ) | |
648 { | |
649 ++v5; | |
650 if ( v5 == uChestArea ) | |
651 v5 = 0; | |
652 } | |
653 Dst[v5] = v1++; | |
654 } | |
655 while ( v1 < uChestArea ); | |
656 } | |
657 v11 = 0; | |
658 if ( uChestArea > 0 ) | |
659 { | |
660 v12 = pChests[v3].mm7__vector_pItems;//&pChests[v3].mm7__vector_pItems[0].uAttributes; | |
661 do | |
662 { | |
663 v9 = v12->uItemID; | |
664 if ( v9 ) | |
665 { | |
666 v6 = 0; | |
667 while ( !Chest::CanPlaceItemAt((unsigned __int8)Dst[v6], v9, v10) ) | |
668 { | 613 { |
669 ++v6; | 614 //get random position in chest |
670 if ( v6 >= uChestArea ) | 615 do |
671 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; | |
672 } | 626 } |
673 if(v6 < uChestArea) | 627 cell_counter = 0; |
674 { | 628 |
675 Chest::PlaceItemAt((unsigned __int8)Dst[v6], v11, v10); | 629 for (cell_counter = 0; cell_counter<uChestArea; ++cell_counter) |
676 if ( pChests[v3].uFlags & 4 ) | 630 { |
677 v12->SetIdentified(); | 631 chest_item_id = pChests[uChestID].igChestItems[cell_counter].uItemID; |
678 } | 632 if ( chest_item_id ) |
679 } | 633 { |
680 ++v11; | 634 test_position = 0; |
681 ++v12; | 635 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) |
682 } | 636 { |
683 while ( (signed int)v11 < uChestArea ); | 637 ++test_position; |
684 } | 638 if ( test_position >= uChestArea ) |
685 result = (char *)&pChests[v3].uFlags; | 639 break; |
686 pChests[v3].uFlags = pChests[v3].uFlags & 0xFFFB | 2; | 640 } |
687 return result; | 641 if(test_position<uChestArea) |
688 } | 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 } | |
689 // 420284: using guessed type char Dst[144]; | 651 // 420284: using guessed type char Dst[144]; |
690 | 652 |
691 //----- (00458B03) -------------------------------------------------------- | 653 //----- (00458B03) -------------------------------------------------------- |
692 void ChestList::ToFile() | 654 void ChestList::ToFile() |
693 { | 655 { |
787 } | 749 } |
788 } | 750 } |
789 fclose(File); | 751 fclose(File); |
790 return 1; | 752 return 1; |
791 } | 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; |