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