Mercurial > mm7
annotate Chest.cpp @ 2034:cc197a3b6eff
GetScriptFileLocation
author | Ritor1 |
---|---|
date | Wed, 20 Nov 2013 00:25:58 +0600 |
parents | 4c3e8ec07d12 |
children | 7a9477135943 |
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 //----- (0042038D) -------------------------------------------------------- |
2018 | 199 void ChestUI_WritePointedObjectStatusString() |
1414 | 200 { |
201 int v1; // ecx@2 | |
2010 | 202 POINT cursor; // [sp+8h] [bp-8h]@1 |
1414 | 203 |
2010 | 204 pMouse->GetCursorPos(&cursor); |
205 if ( cursor.y < 350 ) | |
1414 | 206 { |
2010 | 207 v1 = pRenderer->pActiveZBuffer[cursor.x + pSRZBufferLineOffsets[cursor.y]]; |
2018 | 208 if ( v1 != 0 && v1 != -65536 ) |
1414 | 209 { |
2018 | 210 if ( v1 ) |
211 { | |
212 ItemGen* item = &pChests[pChestWindow->par1C].igChestItems[pChests[pChestWindow->par1C].pInventoryIndices[(v1 & 0xFFFF) - 1] - 1]; | |
213 GameUI_SetFooterString(item->GetDisplayName()); | |
214 } | |
1414 | 215 } |
216 } | |
217 } | |
218 | |
421 | 219 //----- (0042092D) -------------------------------------------------------- |
706 | 220 void Chest::DrawChestUI(signed int uChestID) |
526 | 221 { |
222 | |
223 int chestBitmapId; // eax@1 | |
224 unsigned int v5; // eax@1 | |
225 int chest_item_index; // ecx@3 | |
226 unsigned int item_texture_id; // eax@4 | |
227 Texture *item_texture; // esi@4 | |
228 signed int itemPixelWidth; // ecx@4 | |
229 signed int itemPixelHeght; // edx@4 | |
230 signed int v11; // eax@4 | |
231 int v12; // eax@6 | |
232 int v13; // eax@6 | |
233 unsigned int itemPixelPosX; // ST34_4@8 | |
234 int itemPixelPosY; // edi@8 | |
235 int *v16; // [sp+Ch] [bp-28h]@1 | |
236 int v17; // [sp+10h] [bp-24h]@4 | |
237 int chest_offs_y; // [sp+14h] [bp-20h]@1 | |
238 signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1 | |
239 int chest_offs_x; // [sp+1Ch] [bp-18h]@1 | |
240 signed int chestWidthCells; // [sp+20h] [bp-14h]@1 | |
528 | 241 signed int item_counter; // [sp+30h] [bp-4h]@1 |
421 | 242 |
526 | 243 v16 = pRenderer->pActiveZBuffer; |
244 pRenderer->ClearZBuffer(0, 479); | |
245 chestBitmapId = pChests[uChestID].uChestBitmapID; | |
246 chest_offs_x = pChestPixelOffsetX[chestBitmapId]; | |
247 chest_offs_y = pChestPixelOffsetY[chestBitmapId]; | |
248 chestWidthCells = pChestWidthsByType[chestBitmapId]; | |
249 chestHeghtCells = pChestHeightsByType[chestBitmapId]; | |
1394 | 250 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
|
251 v5 = pIcons_LOD->LoadTexture(pTmpBuf.data(), TEXTURE_16BIT_PALETTE); |
945 | 252 pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5)); |
526 | 253 |
1394 | 254 for (item_counter = 0; item_counter < chestWidthCells * chestHeghtCells; ++item_counter) |
526 | 255 { |
528 | 256 chest_item_index = pChests[uChestID].pInventoryIndices[item_counter]; |
526 | 257 if ( chest_item_index > 0 ) |
258 { | |
259 item_texture_id = pIcons_LOD->LoadTexture( | |
260 //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
|
261 pChests[uChestID].igChestItems[chest_item_index - 1].GetIconName(), TEXTURE_16BIT_PALETTE); |
945 | 262 item_texture = pIcons_LOD->GetTexture(item_texture_id); |
263 itemPixelWidth = item_texture->uTextureWidth; | |
264 itemPixelHeght = item_texture->uTextureHeight; | |
526 | 265 if ( itemPixelWidth < 14 ) |
266 itemPixelWidth = 14; | |
267 v12 = itemPixelWidth - 14; | |
268 v12 = v12 & 0xFFFFFFE0; | |
269 v13 = v12 + 32; | |
270 if ( itemPixelHeght < 14 ) | |
271 itemPixelHeght = 14; | |
600 | 272 itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth)/2); |
528 | 273 itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) + |
600 | 274 ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32- item_texture->uTextureHeight ) /2); |
526 | 275 pRenderer->DrawTextureTransparent( itemPixelPosX, itemPixelPosY, item_texture); |
1458 | 276 ZBuffer_DoFill2(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1); |
526 | 277 } |
278 } | |
945 | 279 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId)); |
421 | 280 } |
281 | |
282 | |
283 //----- (0041FE71) -------------------------------------------------------- | |
706 | 284 bool Chest::CanPlaceItemAt( signed int test_cell_position, int item_id, signed int uChestID ) |
526 | 285 { |
286 int v3; // eax@1 | |
287 unsigned int item_texture_id; // eax@1 | |
288 Texture *item_texture; // ecx@1 | |
289 signed int v6; // eax@1 | |
290 signed int v7; // edi@3 | |
291 signed int v8; // eax@3 | |
292 int texture_cell_width; // edi@3 | |
293 int texture_cell_height; // ebx@5 | |
294 int _row; // esi@9 | |
295 int _cell_rows; // edx@10 | |
296 int _column; // ecx@11 | |
297 char *v14; // eax@12 | |
298 int chest_cell_heght; // [sp+Ch] [bp-Ch]@1 | |
299 signed int v17; // [sp+10h] [bp-8h]@1 | |
300 signed int chest_cell_width; // [sp+14h] [bp-4h]@1 | |
301 | |
302 chest_cell_heght = pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
303 chest_cell_width = pChestWidthsByType[pChests[uChestID].uChestBitmapID]; | |
304 item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE); | |
945 | 305 item_texture = pIcons_LOD->GetTexture(item_texture_id); |
306 v6 = item_texture->uTextureWidth; | |
526 | 307 if ( v6 < 14 ) |
308 v6 = 14; | |
1110 | 309 texture_cell_width = ((v6 - 14) >> 5) + 1; |
526 | 310 v8 = item_texture->uTextureHeight; |
311 if ( v8 < 14 ) | |
312 v8 = 14; | |
313 texture_cell_height = ((v8 - 14) >> 5) + 1; | |
314 if ( !areWeLoadingTexture ) | |
315 { | |
316 item_texture->Release(); | |
1006 | 317 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 318 } |
319 if ( (texture_cell_width + test_cell_position % chest_cell_width <= chest_cell_width) && | |
320 (texture_cell_height + test_cell_position / chest_cell_width <= chest_cell_heght) ) | |
321 { //we not put over borders | |
322 _row = 0; | |
323 if ( texture_cell_height <= 0 ) | |
324 return true; | |
325 _cell_rows = 0; | |
326 while ( 1 ) | |
327 { | |
328 _column = 0; | |
329 if ( texture_cell_width > 0 ) | |
330 { | |
528 | 331 while ( pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]==0) |
526 | 332 { |
333 ++_column; | |
334 if ( _column >= texture_cell_width ) | |
335 break; | |
336 } | |
528 | 337 if (pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]!=0) |
338 return false; | |
526 | 339 } |
340 _cell_rows += chest_cell_width; | |
341 ++_row; | |
342 if ( _row >= texture_cell_height ) | |
343 return true; | |
344 } | |
345 | |
346 } | |
347 return false; | |
421 | 348 } |
349 // 506128: using guessed type int areWeLoadingTexture; | |
350 | |
351 //----- (0041FF64) -------------------------------------------------------- | |
706 | 352 int Chest::CountChestItems(signed int uChestID) |
421 | 353 { |
526 | 354 signed int item_count; // eax@1 |
355 int max_items; // edx@1 | |
356 item_count = 0; | |
357 max_items = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
358 if ( max_items <= 0 ) | |
421 | 359 { |
526 | 360 item_count = -1; |
421 | 361 } |
362 else | |
363 { | |
526 | 364 while ( pChests[uChestID].igChestItems[item_count].uItemID ) |
421 | 365 { |
526 | 366 ++item_count; |
367 if ( item_count >= max_items ) | |
368 { | |
369 item_count = -1; | |
370 break; | |
371 } | |
421 | 372 } |
373 } | |
526 | 374 return item_count; |
421 | 375 } |
376 | |
377 //----- (0041FFA2) -------------------------------------------------------- | |
706 | 378 int Chest::PutItemInChest(int position, ItemGen *put_item, signed int uChestID) |
421 | 379 { |
380 int v3; // eax@1 | |
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 | |
945 | 386 Texture *v9; // 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 | |
399 signed int v22; // [sp+20h] [bp-4h]@3 | |
400 int v23; // [sp+20h] [bp-4h]@19 | |
401 | |
402 v21 = 0; | |
403 v3 = pChests[uChestID].uChestBitmapID; | |
526 | 404 v4 = put_item; |
421 | 405 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3]; |
526 | 406 Src = put_item; |
421 | 407 v19 = pChestWidthsByType[v3]; |
526 | 408 if ( position == -1 ) |
421 | 409 { |
526 | 410 item_in_chest_count = CountChestItems(uChestID); |
411 if ( item_in_chest_count == -1 ) | |
421 | 412 return 0; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
413 for( int _i = 0; _i < v5; _i++) |
1420 | 414 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
415 if ( Chest::CanPlaceItemAt(_i, v4->uItemID, pChestWindow->par1C) ) |
421 | 416 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
417 v21 = _i; |
421 | 418 } |
419 } | |
420 if ( v22 == v5 ) | |
421 { | |
422 if ( uActiveCharacter ) | |
423 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); | |
424 return 0; | |
425 } | |
1709
8251e59fd7c1
ITEM_ENCHANTED to ITEM_HARDENED, created helper functions to get params from itemtable for ItemGens
Grumpy7
parents:
1679
diff
changeset
|
426 v7 = pIcons_LOD->LoadTexture(v4->GetIconName(), TEXTURE_16BIT_PALETTE); |
421 | 427 HIWORD(v8) = 0; |
945 | 428 v9 = pIcons_LOD->GetTexture(v7); |
429 v10 = v9->uTextureWidth; | |
421 | 430 if ( v10 < 14 ) |
431 v10 = 14; | |
945 | 432 v11 = v9->uTextureHeight; |
421 | 433 v12 = ((v10 - 14) >> 5) + 1; |
434 if ( v11 < 14 ) | |
435 v11 = 14; | |
436 v13 = ((v11 - 14) >> 5) + 1; | |
437 if ( !areWeLoadingTexture ) | |
438 { | |
439 ((Texture *)v9)->Release(); | |
1006 | 440 pIcons_LOD->SyncLoadedFilesCount(); |
421 | 441 } |
442 if ( v13 > 0 ) | |
443 { | |
444 v23 = 0; | |
445 v20 = v13; | |
446 do | |
447 { | |
448 if ( (signed int)v12 > 0 ) | |
449 { | |
526 | 450 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23]; |
421 | 451 LOWORD(v8) = -1 - v21; |
452 v8 <<= 16; | |
453 LOWORD(v8) = -1 - v21; | |
454 memset32(v14, v8, v12 >> 1); | |
455 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); | |
456 for ( i = v12 & 1; i; --i ) | |
457 { | |
458 *(short *)v15 = v8; | |
459 v15 += 2; | |
460 } | |
461 } | |
462 v23 += v19; | |
463 --v20; | |
464 } | |
465 while ( v20 ); | |
466 } | |
526 | 467 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1; |
468 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen)); | |
421 | 469 result = v21 + 1; |
470 } | |
471 else | |
472 { | |
473 result = 1; | |
474 } | |
475 return result; | |
476 } | |
477 // 506128: using guessed type int areWeLoadingTexture; | |
478 | |
479 //----- (0042013E) -------------------------------------------------------- | |
706 | 480 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, signed int uChestID ) |
526 | 481 { |
528 | 482 int uItemID; // edi@1 |
483 int v6; // edx@4 | |
484 unsigned int v7; // eax@5 | |
485 Texture *v8; // ecx@5 | |
486 signed int v9; // eax@5 | |
487 signed int v10; // edi@7 | |
488 unsigned int texture_cell_width; // ebx@7 | |
489 int textute_cell_height; // edi@9 | |
490 int chest_cell_row_pos; // edx@12 | |
491 int chest_cell_width; // [sp+10h] [bp-Ch]@11 | |
421 | 492 |
528 | 493 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID; |
494 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]); | |
495 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges) | |
421 | 496 { |
528 | 497 v6 = rand() % 21 + 10; |
498 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6; | |
499 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6; | |
421 | 500 } |
528 | 501 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 502 v8 = pIcons_LOD->GetTexture(v7); |
503 v9 = v8->uTextureWidth; | |
528 | 504 if ( v9 < 14 ) |
505 v9 = 14; | |
506 v10 = v8->uTextureHeight; | |
507 texture_cell_width = ((v9 - 14) >> 5) + 1; | |
508 if ( v10 < 14 ) | |
509 v10 = 14; | |
510 textute_cell_height = ((v10 - 14) >> 5) + 1; | |
511 if ( !areWeLoadingTexture ) | |
512 { | |
513 v8->Release(); | |
1006 | 514 pIcons_LOD->SyncLoadedFilesCount(); |
528 | 515 } |
516 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; | |
517 chest_cell_row_pos = 0; | |
518 for(int i=0; i<textute_cell_height; ++i) | |
519 { | |
520 for (int j=0; j<texture_cell_width; ++j) | |
521 { | |
522 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1); | |
523 } | |
524 chest_cell_row_pos += chest_cell_width; | |
525 } | |
526 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1; | |
421 | 527 } |
528 // 506128: using guessed type int areWeLoadingTexture; | |
529 | |
530 //----- (00420284) -------------------------------------------------------- | |
706 | 531 void Chest::PlaceItems(signed int uChestID ) |
421 | 532 { |
526 | 533 int uChestArea; // edi@1 |
534 int random_chest_pos; // eax@2 | |
535 int test_position; // ebx@11 | |
536 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 | |
537 int chest_item_id; // [sp+9Ch] [bp-10h]@10 | |
528 | 538 unsigned int items_counter; // [sp+A4h] [bp-8h]@8 |
526 | 539 |
540 pRenderer->ClearZBuffer(0, 479); | |
541 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
542 memset(chest_cells_map, 0, 144); | |
543 //fill cell map at random positions | |
608 | 544 for ( items_counter = 0; items_counter < uChestArea; ++items_counter ) |
545 { | |
526 | 546 //get random position in chest |
547 do | |
548 random_chest_pos = (unsigned __int8)rand(); | |
549 while ( random_chest_pos >= uChestArea ); | |
550 //if this pos occupied move to next | |
551 while ( chest_cells_map[random_chest_pos] ) | |
608 | 552 { |
526 | 553 ++random_chest_pos; |
554 if ( random_chest_pos == uChestArea ) | |
555 random_chest_pos = 0; | |
608 | 556 } |
528 | 557 chest_cells_map[random_chest_pos] = items_counter; |
608 | 558 } |
528 | 559 items_counter = 0; |
526 | 560 |
528 | 561 for (items_counter = 0; items_counter<uChestArea; ++items_counter) |
526 | 562 { |
528 | 563 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID; |
526 | 564 if ( chest_item_id ) |
565 { | |
566 test_position = 0; | |
567 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) | |
568 { | |
569 ++test_position; | |
570 if ( test_position >= uChestArea ) | |
571 break; | |
572 } | |
573 if(test_position<uChestArea) | |
574 { | |
528 | 575 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID); |
592 | 576 if ( pChests[uChestID].uFlags & CHEST_OPENED) |
528 | 577 pChests[uChestID].igChestItems[items_counter].SetIdentified(); |
526 | 578 } |
579 } | |
580 } | |
528 | 581 pChests[uChestID].SetInitialized(true); |
421 | 582 } |
583 // 420284: using guessed type char Dst[144]; | |
584 | |
706 | 585 //----- (00448A17) -------------------------------------------------------- |
586 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle) | |
587 { | |
588 unsigned __int16 *pFlags; // eax@3 | |
589 | |
590 if ( uChestID >= 0 && uChestID <= 19 ) | |
591 { | |
592 pFlags = &pChests[uChestID].uFlags; | |
593 if ( bToggle ) | |
594 *pFlags |= uFlag; | |
595 else | |
596 *pFlags &= ~uFlag; | |
597 } | |
598 } | |
599 | |
0 | 600 //----- (00458B03) -------------------------------------------------------- |
601 void ChestList::ToFile() | |
602 { | |
603 ChestList *v1; // esi@1 | |
604 FILE *v2; // eax@1 | |
605 FILE *v3; // edi@1 | |
606 | |
607 v1 = this; | |
608 v2 = fopen("data\\dchest.bin", "wb"); | |
609 v3 = v2; | |
610 if ( !v2 ) | |
1545 | 611 Error("Unable to save dchest.bin!"); |
612 | |
0 | 613 fwrite(v1, 4u, 1u, v2); |
614 fwrite(v1->pChests, 0x24u, v1->uNumChests, v3); | |
615 fclose(v3); | |
616 } | |
617 | |
618 | |
619 //----- (00458B4F) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
620 void ChestList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
0 | 621 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
622 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
|
623 num_mm7_chests = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
624 num_mm8_chests = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
625 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
626 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
|
627 assert(uNumChests); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
628 assert(!num_mm8_chests); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
629 |
1583 | 630 pChests = (ChestDesc *)malloc(uNumChests * sizeof(ChestDesc)); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
631 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
|
632 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
|
633 memcpy(pChests + num_mm6_chests + num_mm7_chests, (char *)data_mm8 + 4, num_mm8_chests * sizeof(ChestDesc)); |
0 | 634 } |
635 | |
636 | |
637 //----- (00458B9C) -------------------------------------------------------- | |
638 int ChestList::FromFileTxt(const char *Args) | |
639 { | |
640 ChestList *v2; // ebx@1 | |
641 __int32 v3; // edi@1 | |
642 FILE *v4; // eax@1 | |
643 unsigned int v5; // esi@3 | |
644 const void *v6; // ST18_4@9 | |
645 void *v7; // eax@9 | |
646 FILE *v8; // ST0C_4@11 | |
647 char *i; // eax@11 | |
648 char v10; // al@14 | |
649 const char *v11; // ST14_4@14 | |
650 char v12; // al@14 | |
651 const char *v13; // ST10_4@14 | |
652 char Buf; // [sp+8h] [bp-2F0h]@3 | |
653 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4 | |
654 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4 | |
655 FILE *File; // [sp+2F4h] [bp-4h]@1 | |
656 unsigned int Argsa; // [sp+300h] [bp+8h]@3 | |
657 | |
658 v2 = this; | |
1583 | 659 free(this->pChests); |
0 | 660 v3 = 0; |
661 v2->pChests = 0; | |
662 v2->uNumChests = 0; | |
663 v4 = fopen(Args, "r"); | |
664 File = v4; | |
665 if ( !v4 ) | |
1545 | 666 Error("ChestDescriptionList::load - Unable to open file: %s."); |
667 | |
0 | 668 v5 = 0; |
669 Argsa = 0; | |
670 if ( fgets(&Buf, 490, v4) ) | |
671 { | |
672 do | |
673 { | |
674 *strchr(&Buf, 10) = 0; | |
703 | 675 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 676 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 677 ++Argsa; |
678 } | |
679 while ( fgets(&Buf, 490, File) ); | |
680 v5 = Argsa; | |
681 v3 = 0; | |
682 } | |
683 v6 = v2->pChests; | |
684 v2->uNumChests = v5; | |
1583 | 685 v7 = malloc(36 * v5); |
0 | 686 v2->pChests = (ChestDesc *)v7; |
687 if ( v7 == (void *)v3 ) | |
1545 | 688 Error("ChestDescriptionList::load - Out of Memory!"); |
689 | |
0 | 690 memset(v7, v3, 36 * v2->uNumChests); |
691 v8 = File; | |
692 v2->uNumChests = v3; | |
693 fseek(v8, v3, v3); | |
694 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
695 { | |
696 *strchr(&Buf, 10) = 0; | |
703 | 697 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 698 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 699 { |
700 strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]); | |
701 v10 = atoi(v17.pProperties[1]); | |
702 v11 = v17.pProperties[2]; | |
703 v2->pChests[v2->uNumChests].uWidth = v10; | |
704 v12 = atoi(v11); | |
705 v13 = v17.pProperties[3]; | |
706 v2->pChests[v2->uNumChests].uHeight = v12; | |
707 v2->pChests[v2->uNumChests++].uTextureID = atoi(v13); | |
708 } | |
709 } | |
710 fclose(File); | |
711 return 1; | |
712 } | |
526 | 713 |
714 //----- (00420B13) -------------------------------------------------------- | |
715 void __fastcall sub_420B13(int a1, int a2) | |
702 | 716 { |
526 | 717 void *v2; // eax@1 |
718 ItemGen *v3; // ebx@1 | |
719 unsigned int v4; // eax@1 | |
720 Texture *v5; // ecx@1 | |
721 signed int v6; // eax@1 | |
722 signed int v7; // edi@3 | |
723 signed int v8; // eax@3 | |
724 int v9; // edi@3 | |
725 int v10; // eax@5 | |
726 int v11; // esi@8 | |
727 unsigned int v12; // ecx@10 | |
728 void *v13; // edi@10 | |
729 unsigned __int8 v14; // cf@10 | |
730 int v15; // edi@10 | |
731 int i; // ecx@10 | |
732 int v17; // [sp+Ch] [bp-14h]@1 | |
733 int v18; // [sp+10h] [bp-10h]@3 | |
734 int v19; // [sp+14h] [bp-Ch]@1 | |
702 | 735 int v20; // [sp+18h] [bp-8h]@1 |
526 | 736 int v21; // [sp+1Ch] [bp-4h]@5 |
737 int v22; // [sp+1Ch] [bp-4h]@8 | |
738 | |
739 v19 = a2; | |
740 v2 = pChestWindow->ptr_1C; | |
702 | 741 v20 = (int)v2; |
526 | 742 v2 = (void *)(5324 * (int)v2); |
702 | 743 //v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4)); |
744 v3 = &pChests[v20].igChestItems[a1]; | |
745 //v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)]; | |
746 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
|
747 v4 = pIcons_LOD->LoadTexture(v3->GetIconName(), TEXTURE_16BIT_PALETTE); |
945 | 748 v5 = pIcons_LOD->GetTexture(v4); |
749 v6 = v5->uTextureWidth; | |
526 | 750 if ( v6 < 14 ) |
751 v6 = 14; | |
752 v7 = v6 - 14; | |
753 v8 = v5->uTextureHeight; | |
754 v9 = (v7 >> 5) + 1; | |
755 v18 = v9; | |
756 if ( v8 < 14 ) | |
757 v8 = 14; | |
758 v10 = ((v8 - 14) >> 5) + 1; | |
759 v21 = v10; | |
760 if ( !areWeLoadingTexture ) | |
702 | 761 { |
526 | 762 v5->Release(); |
1006 | 763 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 764 v10 = v21; |
702 | 765 } |
526 | 766 if ( v10 > 0 ) |
702 | 767 { |
526 | 768 v11 = 0; |
769 v22 = v10; | |
770 do | |
702 | 771 { |
526 | 772 if ( v9 > 0 ) |
702 | 773 { |
526 | 774 v12 = v9; |
702 | 775 //v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20]; |
776 v13 = &pChests[v20].pInventoryIndices[v19 + v11]; | |
526 | 777 v14 = v12 & 1; |
778 v12 >>= 1; | |
779 memset(v13, 0, 4 * v12); | |
780 v15 = (int)((char *)v13 + 4 * v12); | |
781 for ( i = v14; i; --i ) | |
702 | 782 { |
526 | 783 *(short *)v15 = 0; |
784 v15 += 2; | |
702 | 785 } |
526 | 786 v9 = v18; |
702 | 787 } |
526 | 788 v11 += v17; |
789 --v22; | |
790 } | |
702 | 791 while ( v22 ); |
526 | 792 } |
702 | 793 v3->Reset(); |
794 } | |
526 | 795 // 506128: using guessed type int areWeLoadingTexture; |
1297 | 796 //----- (00420E01) -------------------------------------------------------- |
1679 | 797 void OnChestLeftClick() |
1297 | 798 { |
799 int chest_id; // edi@1 | |
800 POINT *v1; // esi@2 | |
801 int v2; // eax@2 | |
802 int v3; // ebx@4 | |
803 int v4; // esi@6 | |
804 int v5; // ecx@6 | |
805 //SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
806 POINT v7; // [sp+7Ch] [bp-10h]@2 | |
807 POINT a2; // [sp+84h] [bp-8h]@2 | |
808 | |
809 SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
810 //SpriteObject::SpriteObject(&v6); | |
811 | |
812 chest_id = pGUIWindow_CurrentMenu->par1C; | |
813 if ( pParty->pPickedItem.uItemID ) | |
814 { | |
815 if ( Chest::PutItemInChest(-1, &pParty->pPickedItem, pGUIWindow_CurrentMenu->par1C) ) | |
816 pMouse->RemoveHoldingItem(); | |
817 } | |
818 else | |
819 { | |
820 v1 = pMouse->GetCursorPos(&a2); | |
821 v2 = pRenderer->pActiveZBuffer[v1->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v7)->y]] & 0xFFFF; | |
822 if ( v2 ) | |
823 { | |
824 if ( v2 ) | |
825 v3 = v2 - 1; | |
826 else | |
827 v3 = -1; | |
828 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
|
829 if ( pChests[chest_id].igChestItems[v4].GetItemEquipType() == EQUIP_GOLD ) |
1297 | 830 { |
1828
35c1e4ff6ba7
party_finds_gold to Party::PartyFindsGold, cleaned up, moved Level/Decoration.h reference out of Indoor.h
Grumpy7
parents:
1709
diff
changeset
|
831 pParty->PartyFindsGold(pChests[chest_id].igChestItems[v4].uSpecEnchantmentType, 0); |
1297 | 832 viewparams->bRedrawGameUI = 1; |
833 } | |
834 else | |
835 { | |
836 pParty->SetHoldingItem(&pChests[chest_id].igChestItems[v4]); | |
837 } | |
838 sub_420B13(v4, v3); | |
839 } | |
840 } | |
841 } |