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