Mercurial > mm7
annotate Chest.cpp @ 1414:110eac219e5a
ChestUI_WritePointedObjectStatusString
author | Nomad |
---|---|
date | Sat, 27 Jul 2013 16:32:20 +0200 |
parents | 204cce84300b |
children | e11c498c0dc6 a8b1bbac95d4 |
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) -------------------------------------------------------- | |
201 void __cdecl ChestUI_WritePointedObjectStatusString() | |
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); |
528 | 285 sub_40F92A(&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; |
422 v22 = 0; | |
423 if ( v5 > 0 ) | |
424 { | |
526 | 425 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, pChestWindow->par1C) ) |
421 | 426 { |
427 ++v22; | |
428 if ( v22 >= v5 ) | |
429 goto LABEL_8; | |
430 } | |
431 v21 = v22; | |
432 } | |
433 LABEL_8: | |
434 if ( v22 == v5 ) | |
435 { | |
436 if ( uActiveCharacter ) | |
437 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); | |
438 return 0; | |
439 } | |
440 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v4->uItemID].pIconName, TEXTURE_16BIT_PALETTE); | |
441 HIWORD(v8) = 0; | |
945 | 442 v9 = pIcons_LOD->GetTexture(v7); |
443 v10 = v9->uTextureWidth; | |
421 | 444 if ( v10 < 14 ) |
445 v10 = 14; | |
945 | 446 v11 = v9->uTextureHeight; |
421 | 447 v12 = ((v10 - 14) >> 5) + 1; |
448 if ( v11 < 14 ) | |
449 v11 = 14; | |
450 v13 = ((v11 - 14) >> 5) + 1; | |
451 if ( !areWeLoadingTexture ) | |
452 { | |
453 ((Texture *)v9)->Release(); | |
1006 | 454 pIcons_LOD->SyncLoadedFilesCount(); |
421 | 455 } |
456 if ( v13 > 0 ) | |
457 { | |
458 v23 = 0; | |
459 v20 = v13; | |
460 do | |
461 { | |
462 if ( (signed int)v12 > 0 ) | |
463 { | |
526 | 464 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23]; |
421 | 465 LOWORD(v8) = -1 - v21; |
466 v8 <<= 16; | |
467 LOWORD(v8) = -1 - v21; | |
468 memset32(v14, v8, v12 >> 1); | |
469 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); | |
470 for ( i = v12 & 1; i; --i ) | |
471 { | |
472 *(short *)v15 = v8; | |
473 v15 += 2; | |
474 } | |
475 } | |
476 v23 += v19; | |
477 --v20; | |
478 } | |
479 while ( v20 ); | |
480 } | |
526 | 481 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1; |
482 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen)); | |
421 | 483 result = v21 + 1; |
484 } | |
485 else | |
486 { | |
487 result = 1; | |
488 } | |
489 return result; | |
490 } | |
491 // 506128: using guessed type int areWeLoadingTexture; | |
492 | |
493 //----- (0042013E) -------------------------------------------------------- | |
706 | 494 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, signed int uChestID ) |
526 | 495 { |
528 | 496 int uItemID; // edi@1 |
497 int v6; // edx@4 | |
498 unsigned int v7; // eax@5 | |
499 Texture *v8; // ecx@5 | |
500 signed int v9; // eax@5 | |
501 signed int v10; // edi@7 | |
502 unsigned int texture_cell_width; // ebx@7 | |
503 int textute_cell_height; // edi@9 | |
504 int chest_cell_row_pos; // edx@12 | |
505 int chest_cell_width; // [sp+10h] [bp-Ch]@11 | |
421 | 506 |
528 | 507 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID; |
508 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]); | |
509 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges) | |
421 | 510 { |
528 | 511 v6 = rand() % 21 + 10; |
512 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6; | |
513 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6; | |
421 | 514 } |
528 | 515 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 516 v8 = pIcons_LOD->GetTexture(v7); |
517 v9 = v8->uTextureWidth; | |
528 | 518 if ( v9 < 14 ) |
519 v9 = 14; | |
520 v10 = v8->uTextureHeight; | |
521 texture_cell_width = ((v9 - 14) >> 5) + 1; | |
522 if ( v10 < 14 ) | |
523 v10 = 14; | |
524 textute_cell_height = ((v10 - 14) >> 5) + 1; | |
525 if ( !areWeLoadingTexture ) | |
526 { | |
527 v8->Release(); | |
1006 | 528 pIcons_LOD->SyncLoadedFilesCount(); |
528 | 529 } |
530 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; | |
531 chest_cell_row_pos = 0; | |
532 for(int i=0; i<textute_cell_height; ++i) | |
533 { | |
534 for (int j=0; j<texture_cell_width; ++j) | |
535 { | |
536 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1); | |
537 } | |
538 chest_cell_row_pos += chest_cell_width; | |
539 } | |
540 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1; | |
421 | 541 } |
542 // 506128: using guessed type int areWeLoadingTexture; | |
543 | |
544 //----- (00420284) -------------------------------------------------------- | |
706 | 545 void Chest::PlaceItems(signed int uChestID ) |
421 | 546 { |
526 | 547 int uChestArea; // edi@1 |
548 int random_chest_pos; // eax@2 | |
549 int test_position; // ebx@11 | |
550 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 | |
551 int chest_item_id; // [sp+9Ch] [bp-10h]@10 | |
528 | 552 unsigned int items_counter; // [sp+A4h] [bp-8h]@8 |
526 | 553 |
554 pRenderer->ClearZBuffer(0, 479); | |
555 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
556 memset(chest_cells_map, 0, 144); | |
557 //fill cell map at random positions | |
608 | 558 for ( items_counter = 0; items_counter < uChestArea; ++items_counter ) |
559 { | |
526 | 560 //get random position in chest |
561 do | |
562 random_chest_pos = (unsigned __int8)rand(); | |
563 while ( random_chest_pos >= uChestArea ); | |
564 //if this pos occupied move to next | |
565 while ( chest_cells_map[random_chest_pos] ) | |
608 | 566 { |
526 | 567 ++random_chest_pos; |
568 if ( random_chest_pos == uChestArea ) | |
569 random_chest_pos = 0; | |
608 | 570 } |
528 | 571 chest_cells_map[random_chest_pos] = items_counter; |
608 | 572 } |
528 | 573 items_counter = 0; |
526 | 574 |
528 | 575 for (items_counter = 0; items_counter<uChestArea; ++items_counter) |
526 | 576 { |
528 | 577 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID; |
526 | 578 if ( chest_item_id ) |
579 { | |
580 test_position = 0; | |
581 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) | |
582 { | |
583 ++test_position; | |
584 if ( test_position >= uChestArea ) | |
585 break; | |
586 } | |
587 if(test_position<uChestArea) | |
588 { | |
528 | 589 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID); |
592 | 590 if ( pChests[uChestID].uFlags & CHEST_OPENED) |
528 | 591 pChests[uChestID].igChestItems[items_counter].SetIdentified(); |
526 | 592 } |
593 } | |
594 } | |
528 | 595 pChests[uChestID].SetInitialized(true); |
421 | 596 } |
597 // 420284: using guessed type char Dst[144]; | |
598 | |
706 | 599 //----- (00448A17) -------------------------------------------------------- |
600 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle) | |
601 { | |
602 unsigned __int16 *pFlags; // eax@3 | |
603 | |
604 if ( uChestID >= 0 && uChestID <= 19 ) | |
605 { | |
606 pFlags = &pChests[uChestID].uFlags; | |
607 if ( bToggle ) | |
608 *pFlags |= uFlag; | |
609 else | |
610 *pFlags &= ~uFlag; | |
611 } | |
612 } | |
613 | |
0 | 614 //----- (00458B03) -------------------------------------------------------- |
615 void ChestList::ToFile() | |
616 { | |
617 ChestList *v1; // esi@1 | |
618 FILE *v2; // eax@1 | |
619 FILE *v3; // edi@1 | |
620 | |
621 v1 = this; | |
622 v2 = fopen("data\\dchest.bin", "wb"); | |
623 v3 = v2; | |
624 if ( !v2 ) | |
625 Abortf("Unable to save dchest.bin!"); | |
626 fwrite(v1, 4u, 1u, v2); | |
627 fwrite(v1->pChests, 0x24u, v1->uNumChests, v3); | |
628 fclose(v3); | |
629 } | |
630 | |
631 | |
632 //----- (00458B4F) -------------------------------------------------------- | |
633 void ChestList::FromFile(void *pSerialized) | |
634 { | |
635 uNumChests = *(int *)pSerialized; | |
636 pChests = (ChestDesc *)pAllocator->AllocNamedChunk(pChests, 36 * uNumChests, "Chest Descrip"); | |
637 memcpy(pChests, (char *)pSerialized + 4, 36 * uNumChests); | |
638 } | |
639 | |
640 | |
641 //----- (00458B9C) -------------------------------------------------------- | |
642 int ChestList::FromFileTxt(const char *Args) | |
643 { | |
644 ChestList *v2; // ebx@1 | |
645 __int32 v3; // edi@1 | |
646 FILE *v4; // eax@1 | |
647 unsigned int v5; // esi@3 | |
648 const void *v6; // ST18_4@9 | |
649 void *v7; // eax@9 | |
650 FILE *v8; // ST0C_4@11 | |
651 char *i; // eax@11 | |
652 char v10; // al@14 | |
653 const char *v11; // ST14_4@14 | |
654 char v12; // al@14 | |
655 const char *v13; // ST10_4@14 | |
656 char Buf; // [sp+8h] [bp-2F0h]@3 | |
657 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4 | |
658 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4 | |
659 FILE *File; // [sp+2F4h] [bp-4h]@1 | |
660 unsigned int Argsa; // [sp+300h] [bp+8h]@3 | |
661 | |
662 v2 = this; | |
663 pAllocator->FreeChunk(this->pChests); | |
664 v3 = 0; | |
665 v2->pChests = 0; | |
666 v2->uNumChests = 0; | |
667 v4 = fopen(Args, "r"); | |
668 File = v4; | |
669 if ( !v4 ) | |
670 Abortf("ChestDescriptionList::load - Unable to open file: %s."); | |
671 v5 = 0; | |
672 Argsa = 0; | |
673 if ( fgets(&Buf, 490, v4) ) | |
674 { | |
675 do | |
676 { | |
677 *strchr(&Buf, 10) = 0; | |
703 | 678 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 679 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 680 ++Argsa; |
681 } | |
682 while ( fgets(&Buf, 490, File) ); | |
683 v5 = Argsa; | |
684 v3 = 0; | |
685 } | |
686 v6 = v2->pChests; | |
687 v2->uNumChests = v5; | |
688 v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip"); | |
689 v2->pChests = (ChestDesc *)v7; | |
690 if ( v7 == (void *)v3 ) | |
691 Abortf("ChestDescriptionList::load - Out of Memory!"); | |
692 memset(v7, v3, 36 * v2->uNumChests); | |
693 v8 = File; | |
694 v2->uNumChests = v3; | |
695 fseek(v8, v3, v3); | |
696 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
697 { | |
698 *strchr(&Buf, 10) = 0; | |
703 | 699 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 700 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 701 { |
702 strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]); | |
703 v10 = atoi(v17.pProperties[1]); | |
704 v11 = v17.pProperties[2]; | |
705 v2->pChests[v2->uNumChests].uWidth = v10; | |
706 v12 = atoi(v11); | |
707 v13 = v17.pProperties[3]; | |
708 v2->pChests[v2->uNumChests].uHeight = v12; | |
709 v2->pChests[v2->uNumChests++].uTextureID = atoi(v13); | |
710 } | |
711 } | |
712 fclose(File); | |
713 return 1; | |
714 } | |
526 | 715 |
716 //----- (00420B13) -------------------------------------------------------- | |
717 void __fastcall sub_420B13(int a1, int a2) | |
702 | 718 { |
526 | 719 void *v2; // eax@1 |
720 ItemGen *v3; // ebx@1 | |
721 unsigned int v4; // eax@1 | |
722 Texture *v5; // ecx@1 | |
723 signed int v6; // eax@1 | |
724 signed int v7; // edi@3 | |
725 signed int v8; // eax@3 | |
726 int v9; // edi@3 | |
727 int v10; // eax@5 | |
728 int v11; // esi@8 | |
729 unsigned int v12; // ecx@10 | |
730 void *v13; // edi@10 | |
731 unsigned __int8 v14; // cf@10 | |
732 int v15; // edi@10 | |
733 int i; // ecx@10 | |
734 int v17; // [sp+Ch] [bp-14h]@1 | |
735 int v18; // [sp+10h] [bp-10h]@3 | |
736 int v19; // [sp+14h] [bp-Ch]@1 | |
702 | 737 int v20; // [sp+18h] [bp-8h]@1 |
526 | 738 int v21; // [sp+1Ch] [bp-4h]@5 |
739 int v22; // [sp+1Ch] [bp-4h]@8 | |
740 | |
741 v19 = a2; | |
742 v2 = pChestWindow->ptr_1C; | |
702 | 743 v20 = (int)v2; |
526 | 744 v2 = (void *)(5324 * (int)v2); |
702 | 745 //v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4)); |
746 v3 = &pChests[v20].igChestItems[a1]; | |
747 //v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)]; | |
748 v17 = pChestWidthsByType[pChests[v20].uChestBitmapID]; | |
526 | 749 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v3->uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 750 v5 = pIcons_LOD->GetTexture(v4); |
751 v6 = v5->uTextureWidth; | |
526 | 752 if ( v6 < 14 ) |
753 v6 = 14; | |
754 v7 = v6 - 14; | |
755 v8 = v5->uTextureHeight; | |
756 v9 = (v7 >> 5) + 1; | |
757 v18 = v9; | |
758 if ( v8 < 14 ) | |
759 v8 = 14; | |
760 v10 = ((v8 - 14) >> 5) + 1; | |
761 v21 = v10; | |
762 if ( !areWeLoadingTexture ) | |
702 | 763 { |
526 | 764 v5->Release(); |
1006 | 765 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 766 v10 = v21; |
702 | 767 } |
526 | 768 if ( v10 > 0 ) |
702 | 769 { |
526 | 770 v11 = 0; |
771 v22 = v10; | |
772 do | |
702 | 773 { |
526 | 774 if ( v9 > 0 ) |
702 | 775 { |
526 | 776 v12 = v9; |
702 | 777 //v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20]; |
778 v13 = &pChests[v20].pInventoryIndices[v19 + v11]; | |
526 | 779 v14 = v12 & 1; |
780 v12 >>= 1; | |
781 memset(v13, 0, 4 * v12); | |
782 v15 = (int)((char *)v13 + 4 * v12); | |
783 for ( i = v14; i; --i ) | |
702 | 784 { |
526 | 785 *(short *)v15 = 0; |
786 v15 += 2; | |
702 | 787 } |
526 | 788 v9 = v18; |
702 | 789 } |
526 | 790 v11 += v17; |
791 --v22; | |
792 } | |
702 | 793 while ( v22 ); |
526 | 794 } |
702 | 795 v3->Reset(); |
796 } | |
526 | 797 // 506128: using guessed type int areWeLoadingTexture; |
1297 | 798 //----- (00420E01) -------------------------------------------------------- |
799 void __cdecl OnChestLeftClick() | |
800 { | |
801 int chest_id; // edi@1 | |
802 POINT *v1; // esi@2 | |
803 int v2; // eax@2 | |
804 int v3; // ebx@4 | |
805 int v4; // esi@6 | |
806 int v5; // ecx@6 | |
807 //SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
808 POINT v7; // [sp+7Ch] [bp-10h]@2 | |
809 POINT a2; // [sp+84h] [bp-8h]@2 | |
810 | |
811 SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
812 //SpriteObject::SpriteObject(&v6); | |
813 | |
814 chest_id = pGUIWindow_CurrentMenu->par1C; | |
815 if ( pParty->pPickedItem.uItemID ) | |
816 { | |
817 if ( Chest::PutItemInChest(-1, &pParty->pPickedItem, pGUIWindow_CurrentMenu->par1C) ) | |
818 pMouse->RemoveHoldingItem(); | |
819 } | |
820 else | |
821 { | |
822 v1 = pMouse->GetCursorPos(&a2); | |
823 v2 = pRenderer->pActiveZBuffer[v1->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v7)->y]] & 0xFFFF; | |
824 if ( v2 ) | |
825 { | |
826 if ( v2 ) | |
827 v3 = v2 - 1; | |
828 else | |
829 v3 = -1; | |
830 v4 = pChests[chest_id].pInventoryIndices[v3] - 1; | |
831 if ( pItemsTable->pItems[pChests[chest_id].igChestItems[v4].uItemID].uEquipType == EQUIP_GOLD ) | |
832 { | |
833 party_finds_gold(pChests[chest_id].igChestItems[v4].uSpecEnchantmentType, 0); | |
834 viewparams->bRedrawGameUI = 1; | |
835 } | |
836 else | |
837 { | |
838 pParty->SetHoldingItem(&pChests[chest_id].igChestItems[v4]); | |
839 } | |
840 sub_420B13(v4, v3); | |
841 } | |
842 } | |
843 } |