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