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