Mercurial > mm7
annotate Chest.cpp @ 2276:e2433db49428
ActorHasItems
author | Ritor1 |
---|---|
date | Fri, 14 Mar 2014 10:47:22 +0600 |
parents | fd788d2e9585 |
children | 9551756f46c4 |
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 ) |
2268 | 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 ) | |
2268 | 312 { |
313 item_texture->Release(); | |
314 pIcons_LOD->SyncLoadedFilesCount(); | |
315 } | |
526 | 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) ) | |
2268 | 318 { //we not put over borders |
526 | 319 _row = 0; |
320 if ( texture_cell_height <= 0 ) | |
321 return true; | |
322 _cell_rows = 0; | |
323 while ( 1 ) | |
2268 | 324 { |
526 | 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 ) | |
356 item_count = -1; | |
421 | 357 else |
358 { | |
526 | 359 while ( pChests[uChestID].igChestItems[item_count].uItemID ) |
421 | 360 { |
526 | 361 ++item_count; |
362 if ( item_count >= max_items ) | |
2264 | 363 { |
364 item_count = -1; | |
365 break; | |
366 } | |
421 | 367 } |
368 } | |
526 | 369 return item_count; |
421 | 370 } |
371 | |
372 //----- (0041FFA2) -------------------------------------------------------- | |
706 | 373 int Chest::PutItemInChest(int position, ItemGen *put_item, signed int uChestID) |
2268 | 374 {//(rus: положить предмет в ящик) |
421 | 375 ItemGen *v4; // edi@1 |
376 int v5; // esi@1 | |
377 int result; // eax@11 | |
378 unsigned int v7; // eax@12 | |
379 int v8; // edx@12 | |
2264 | 380 Texture *texture; // ecx@12 |
421 | 381 signed int v10; // eax@12 |
382 signed int v11; // edi@14 | |
383 unsigned int v12; // esi@14 | |
384 int v13; // edi@16 | |
385 void *v14; // edi@21 | |
386 int v15; // edi@21 | |
387 int i; // ecx@21 | |
388 ItemGen *Src; // [sp+Ch] [bp-18h]@1 | |
526 | 389 signed int item_in_chest_count; // [sp+10h] [bp-14h]@2 |
421 | 390 int v19; // [sp+14h] [bp-10h]@1 |
391 int v20; // [sp+18h] [bp-Ch]@19 | |
392 signed int v21; // [sp+1Ch] [bp-8h]@1 | |
393 signed int v22; // [sp+20h] [bp-4h]@3 | |
394 int v23; // [sp+20h] [bp-4h]@19 | |
395 | |
396 v21 = 0; | |
526 | 397 v4 = put_item; |
2264 | 398 v5 = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; |
526 | 399 Src = put_item; |
2264 | 400 v19 = pChestWidthsByType[pChests[uChestID].uChestBitmapID]; |
526 | 401 if ( position == -1 ) |
421 | 402 { |
526 | 403 item_in_chest_count = CountChestItems(uChestID); |
404 if ( item_in_chest_count == -1 ) | |
421 | 405 return 0; |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
406 for( int _i = 0; _i < v5; _i++) |
1420 | 407 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
408 if ( Chest::CanPlaceItemAt(_i, v4->uItemID, pChestWindow->par1C) ) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
409 v21 = _i; |
421 | 410 } |
2057 | 411 if ( v21 == v5 ) |
421 | 412 { |
413 if ( uActiveCharacter ) | |
414 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); | |
415 return 0; | |
416 } | |
1709
8251e59fd7c1
ITEM_ENCHANTED to ITEM_HARDENED, created helper functions to get params from itemtable for ItemGens
Grumpy7
parents:
1679
diff
changeset
|
417 v7 = pIcons_LOD->LoadTexture(v4->GetIconName(), TEXTURE_16BIT_PALETTE); |
421 | 418 HIWORD(v8) = 0; |
2264 | 419 texture = pIcons_LOD->GetTexture(v7); |
420 v10 = texture->uTextureWidth; | |
421 if ( texture->uTextureWidth < 14 ) | |
421 | 422 v10 = 14; |
423 v12 = ((v10 - 14) >> 5) + 1; | |
2264 | 424 v11 = texture->uTextureHeight; |
425 if ( texture->uTextureHeight < 14 ) | |
421 | 426 v11 = 14; |
427 v13 = ((v11 - 14) >> 5) + 1; | |
428 if ( !areWeLoadingTexture ) | |
429 { | |
2264 | 430 texture->Release(); |
1006 | 431 pIcons_LOD->SyncLoadedFilesCount(); |
421 | 432 } |
433 if ( v13 > 0 ) | |
434 { | |
435 v23 = 0; | |
436 v20 = v13; | |
437 do | |
438 { | |
439 if ( (signed int)v12 > 0 ) | |
440 { | |
526 | 441 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23]; |
421 | 442 LOWORD(v8) = -1 - v21; |
443 v8 <<= 16; | |
444 LOWORD(v8) = -1 - v21; | |
445 memset32(v14, v8, v12 >> 1); | |
446 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); | |
447 for ( i = v12 & 1; i; --i ) | |
448 { | |
449 *(short *)v15 = v8; | |
450 v15 += 2; | |
451 } | |
452 } | |
453 v23 += v19; | |
454 --v20; | |
455 } | |
456 while ( v20 ); | |
457 } | |
526 | 458 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1; |
459 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen)); | |
421 | 460 result = v21 + 1; |
461 } | |
462 else | |
463 result = 1; | |
464 return result; | |
465 } | |
466 // 506128: using guessed type int areWeLoadingTexture; | |
467 | |
468 //----- (0042013E) -------------------------------------------------------- | |
706 | 469 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, signed int uChestID ) |
2264 | 470 { |
471 int uItemID; // edi@1 | |
472 int v6; // edx@4 | |
473 unsigned int v7; // eax@5 | |
474 Texture *texture; // ecx@5 | |
475 signed int v9; // eax@5 | |
476 signed int v10; // edi@7 | |
477 unsigned int texture_cell_width; // ebx@7 | |
478 int textute_cell_height; // edi@9 | |
479 int chest_cell_row_pos; // edx@12 | |
480 int chest_cell_width; // [sp+10h] [bp-Ch]@11 | |
421 | 481 |
2264 | 482 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID; |
483 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]); | |
484 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges) | |
485 { | |
486 v6 = rand() % 21 + 10; | |
487 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6; | |
488 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6; | |
489 } | |
490 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); | |
491 texture = pIcons_LOD->GetTexture(v7); | |
492 v9 = texture->uTextureWidth; | |
493 if ( texture->uTextureWidth < 14 ) | |
494 v9 = 14; | |
495 texture_cell_width = ((v9 - 14) >> 5) + 1; | |
496 v10 = texture->uTextureHeight; | |
497 if ( texture->uTextureHeight < 14 ) | |
498 v10 = 14; | |
499 textute_cell_height = ((v10 - 14) >> 5) + 1; | |
500 if ( !areWeLoadingTexture ) | |
501 { | |
502 texture->Release(); | |
503 pIcons_LOD->SyncLoadedFilesCount(); | |
504 } | |
505 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; | |
506 chest_cell_row_pos = 0; | |
507 for(int i = 0; i < textute_cell_height; ++i) | |
508 { | |
509 for (int j = 0; j < texture_cell_width; ++j) | |
510 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1); | |
511 chest_cell_row_pos += chest_cell_width; | |
512 } | |
513 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1; | |
514 } | |
421 | 515 // 506128: using guessed type int areWeLoadingTexture; |
516 | |
517 //----- (00420284) -------------------------------------------------------- | |
706 | 518 void Chest::PlaceItems(signed int uChestID ) |
421 | 519 { |
526 | 520 int uChestArea; // edi@1 |
521 int random_chest_pos; // eax@2 | |
522 int test_position; // ebx@11 | |
523 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 | |
524 int chest_item_id; // [sp+9Ch] [bp-10h]@10 | |
528 | 525 unsigned int items_counter; // [sp+A4h] [bp-8h]@8 |
526 | 526 |
527 pRenderer->ClearZBuffer(0, 479); | |
528 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
529 memset(chest_cells_map, 0, 144); | |
530 //fill cell map at random positions | |
608 | 531 for ( items_counter = 0; items_counter < uChestArea; ++items_counter ) |
532 { | |
526 | 533 //get random position in chest |
534 do | |
535 random_chest_pos = (unsigned __int8)rand(); | |
536 while ( random_chest_pos >= uChestArea ); | |
537 //if this pos occupied move to next | |
538 while ( chest_cells_map[random_chest_pos] ) | |
608 | 539 { |
526 | 540 ++random_chest_pos; |
541 if ( random_chest_pos == uChestArea ) | |
542 random_chest_pos = 0; | |
608 | 543 } |
528 | 544 chest_cells_map[random_chest_pos] = items_counter; |
608 | 545 } |
528 | 546 items_counter = 0; |
526 | 547 |
528 | 548 for (items_counter = 0; items_counter<uChestArea; ++items_counter) |
526 | 549 { |
528 | 550 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID; |
526 | 551 if ( chest_item_id ) |
552 { | |
553 test_position = 0; | |
554 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) | |
555 { | |
556 ++test_position; | |
557 if ( test_position >= uChestArea ) | |
558 break; | |
559 } | |
560 if(test_position<uChestArea) | |
561 { | |
528 | 562 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID); |
592 | 563 if ( pChests[uChestID].uFlags & CHEST_OPENED) |
528 | 564 pChests[uChestID].igChestItems[items_counter].SetIdentified(); |
526 | 565 } |
566 } | |
567 } | |
528 | 568 pChests[uChestID].SetInitialized(true); |
421 | 569 } |
570 // 420284: using guessed type char Dst[144]; | |
571 | |
706 | 572 //----- (00448A17) -------------------------------------------------------- |
573 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle) | |
2268 | 574 { |
575 if ( uChestID >= 0 && uChestID <= 19 ) | |
576 { | |
577 if ( bToggle ) | |
578 pChests[uChestID].uFlags |= uFlag; | |
579 else | |
580 pChests[uChestID].uFlags &= ~uFlag; | |
581 } | |
582 } | |
706 | 583 |
0 | 584 //----- (00458B03) -------------------------------------------------------- |
585 void ChestList::ToFile() | |
586 { | |
587 FILE *v2; // eax@1 | |
588 FILE *v3; // edi@1 | |
589 | |
590 v2 = fopen("data\\dchest.bin", "wb"); | |
591 v3 = v2; | |
592 if ( !v2 ) | |
1545 | 593 Error("Unable to save dchest.bin!"); |
594 | |
2264 | 595 fwrite(this, 4, 1, v2); |
596 fwrite(this->pChests, 36, this->uNumChests, v3); | |
0 | 597 fclose(v3); |
598 } | |
599 | |
600 | |
601 //----- (00458B4F) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
602 void ChestList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
0 | 603 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
604 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
|
605 num_mm7_chests = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
606 num_mm8_chests = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
607 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
608 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
|
609 assert(uNumChests); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
610 assert(!num_mm8_chests); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
611 |
1583 | 612 pChests = (ChestDesc *)malloc(uNumChests * sizeof(ChestDesc)); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1458
diff
changeset
|
613 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
|
614 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
|
615 memcpy(pChests + num_mm6_chests + num_mm7_chests, (char *)data_mm8 + 4, num_mm8_chests * sizeof(ChestDesc)); |
0 | 616 } |
617 | |
618 | |
619 //----- (00458B9C) -------------------------------------------------------- | |
620 int ChestList::FromFileTxt(const char *Args) | |
621 { | |
2264 | 622 //ChestList *v2; // ebx@1 |
0 | 623 __int32 v3; // edi@1 |
624 FILE *v4; // eax@1 | |
625 unsigned int v5; // esi@3 | |
626 const void *v6; // ST18_4@9 | |
627 void *v7; // eax@9 | |
628 FILE *v8; // ST0C_4@11 | |
629 char *i; // eax@11 | |
630 char v10; // al@14 | |
631 const char *v11; // ST14_4@14 | |
632 char v12; // al@14 | |
633 const char *v13; // ST10_4@14 | |
634 char Buf; // [sp+8h] [bp-2F0h]@3 | |
635 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4 | |
636 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4 | |
637 FILE *File; // [sp+2F4h] [bp-4h]@1 | |
638 unsigned int Argsa; // [sp+300h] [bp+8h]@3 | |
639 | |
2264 | 640 //v2 = this; |
1583 | 641 free(this->pChests); |
0 | 642 v3 = 0; |
2264 | 643 this->pChests = 0; |
644 this->uNumChests = 0; | |
0 | 645 v4 = fopen(Args, "r"); |
646 File = v4; | |
647 if ( !v4 ) | |
1545 | 648 Error("ChestDescriptionList::load - Unable to open file: %s."); |
649 | |
0 | 650 v5 = 0; |
651 Argsa = 0; | |
652 if ( fgets(&Buf, 490, v4) ) | |
653 { | |
654 do | |
655 { | |
656 *strchr(&Buf, 10) = 0; | |
703 | 657 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 658 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 659 ++Argsa; |
660 } | |
661 while ( fgets(&Buf, 490, File) ); | |
662 v5 = Argsa; | |
663 v3 = 0; | |
664 } | |
2264 | 665 v6 = this->pChests; |
666 this->uNumChests = v5; | |
1583 | 667 v7 = malloc(36 * v5); |
2264 | 668 this->pChests = (ChestDesc *)v7; |
0 | 669 if ( v7 == (void *)v3 ) |
1545 | 670 Error("ChestDescriptionList::load - Out of Memory!"); |
671 | |
2264 | 672 memset(v7, v3, 36 * this->uNumChests); |
0 | 673 v8 = File; |
2264 | 674 this->uNumChests = v3; |
0 | 675 fseek(v8, v3, v3); |
676 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
677 { | |
678 *strchr(&Buf, 10) = 0; | |
703 | 679 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 680 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 681 { |
2264 | 682 strcpy(this->pChests[this->uNumChests].pName, v17.pProperties[0]); |
0 | 683 v10 = atoi(v17.pProperties[1]); |
684 v11 = v17.pProperties[2]; | |
2264 | 685 this->pChests[this->uNumChests].uWidth = v10; |
0 | 686 v12 = atoi(v11); |
687 v13 = v17.pProperties[3]; | |
2264 | 688 this->pChests[this->uNumChests].uHeight = v12; |
689 this->pChests[this->uNumChests++].uTextureID = atoi(v13); | |
0 | 690 } |
691 } | |
692 fclose(File); | |
693 return 1; | |
694 } | |
526 | 695 |
696 //----- (00420B13) -------------------------------------------------------- | |
697 void __fastcall sub_420B13(int a1, int a2) | |
2268 | 698 { //Give item from chest(rus: Взять предмет из ящика) |
526 | 699 void *v2; // eax@1 |
700 unsigned int v4; // eax@1 | |
2264 | 701 Texture *texture; // ecx@1 |
526 | 702 signed int v6; // eax@1 |
703 signed int v7; // edi@3 | |
704 signed int v8; // eax@3 | |
705 int v9; // edi@3 | |
706 int v10; // eax@5 | |
707 int v11; // esi@8 | |
708 unsigned int v12; // ecx@10 | |
709 void *v13; // edi@10 | |
710 unsigned __int8 v14; // cf@10 | |
711 int v15; // edi@10 | |
712 int i; // ecx@10 | |
713 int v17; // [sp+Ch] [bp-14h]@1 | |
714 int v18; // [sp+10h] [bp-10h]@3 | |
715 int v21; // [sp+1Ch] [bp-4h]@5 | |
716 int v22; // [sp+1Ch] [bp-4h]@8 | |
717 | |
2268 | 718 v2 = (void *)(5324 * (int)pChestWindow->ptr_1C); |
719 v17 = pChestWidthsByType[pChests[(int)pChestWindow->ptr_1C].uChestBitmapID]; | |
720 v4 = pIcons_LOD->LoadTexture(pChests[(int)pChestWindow->ptr_1C].igChestItems[a1].GetIconName(), TEXTURE_16BIT_PALETTE); | |
2264 | 721 texture = pIcons_LOD->GetTexture(v4); |
722 | |
723 v6 = texture->uTextureWidth; | |
724 if ( texture->uTextureWidth < 14 ) | |
725 v6 = 14; | |
526 | 726 v7 = v6 - 14; |
727 v9 = (v7 >> 5) + 1; | |
728 v18 = v9; | |
2264 | 729 |
730 v8 = texture->uTextureHeight; | |
731 if ( texture->uTextureHeight < 14 ) | |
732 v8 = 14; | |
526 | 733 v10 = ((v8 - 14) >> 5) + 1; |
734 v21 = v10; | |
2268 | 735 |
526 | 736 if ( !areWeLoadingTexture ) |
702 | 737 { |
2268 | 738 texture->Release(); |
739 pIcons_LOD->SyncLoadedFilesCount(); | |
740 v10 = v21; | |
702 | 741 } |
526 | 742 if ( v10 > 0 ) |
702 | 743 { |
2268 | 744 v11 = 0; |
745 for ( v22 = v10; v22; --v22 ) | |
746 { | |
747 if ( v9 > 0 ) | |
702 | 748 { |
2268 | 749 v12 = v9; |
750 v13 = &pChests[(int)pChestWindow->ptr_1C].pInventoryIndices[a2 + v11]; | |
751 v14 = v12 & 1; | |
752 v12 >>= 1; | |
753 memset(&pChests[(int)pChestWindow->ptr_1C].pInventoryIndices[a2 + v11], 0, 4 * v12); | |
754 v15 = (int)((char *)v13 + 4 * v12); | |
755 for ( i = v14; i; --i ) | |
756 { | |
757 *(short *)v15 = 0; | |
758 v15 += 2; | |
759 } | |
760 v9 = v18; | |
526 | 761 } |
2268 | 762 v11 += v17; |
763 } | |
526 | 764 } |
2268 | 765 pChests[(int)pChestWindow->ptr_1C].igChestItems[a1].Reset(); |
702 | 766 } |
526 | 767 // 506128: using guessed type int areWeLoadingTexture; |
1297 | 768 //----- (00420E01) -------------------------------------------------------- |
1679 | 769 void OnChestLeftClick() |
1297 | 770 { |
771 int v2; // eax@2 | |
772 int v3; // ebx@4 | |
773 int v4; // esi@6 | |
2268 | 774 POINT cursor; // [sp+84h] [bp-8h]@2 |
1297 | 775 |
776 SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
777 if ( pParty->pPickedItem.uItemID ) | |
778 { | |
779 if ( Chest::PutItemInChest(-1, &pParty->pPickedItem, pGUIWindow_CurrentMenu->par1C) ) | |
780 pMouse->RemoveHoldingItem(); | |
781 } | |
782 else | |
783 { | |
2268 | 784 pMouse->GetCursorPos(&cursor); |
785 v2 = pRenderer->pActiveZBuffer[cursor.x + pSRZBufferLineOffsets[cursor.y]] & 0xFFFF; | |
1297 | 786 if ( v2 ) |
787 { | |
788 if ( v2 ) | |
789 v3 = v2 - 1; | |
790 else | |
791 v3 = -1; | |
2268 | 792 v4 = pChests[(int)pGUIWindow_CurrentMenu->par1C].pInventoryIndices[v3] - 1; |
793 if ( pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4].GetItemEquipType() == EQUIP_GOLD ) | |
1297 | 794 { |
2268 | 795 pParty->PartyFindsGold(pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4].uSpecEnchantmentType, 0); |
1297 | 796 viewparams->bRedrawGameUI = 1; |
797 } | |
798 else | |
2268 | 799 pParty->SetHoldingItem(&pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4]); |
1297 | 800 sub_420B13(v4, v3); |
801 } | |
802 } | |
803 } |