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