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