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