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