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
|
2566
|
59 SPRITE_OBJECT_TYPE pSpriteID[4]; // [sp+84h] [bp-40h]@16
|
2497
|
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 {
|
2566
|
87 pSpriteID[0] = SPRITE_811;
|
|
88 pSpriteID[1] = SPRITE_812;
|
|
89 pSpriteID[2] = SPRITE_813;
|
|
90 pSpriteID[3] = SPRITE_814;
|
2497
|
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
|
2566
|
140 pSpellObject.containing_item.Reset();
|
2497
|
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
|
2575
|
221 //unsigned int item_texture_id; // eax@1
|
|
222 //Image *item_texture; // ecx@1
|
2497
|
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];
|
2575
|
238
|
|
239 auto item_texture = assets->GetImage_16BitColorKey(pItemsTable->pItems[item_id].pIconName, 0x7FF);
|
|
240 //item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE);
|
|
241 //item_texture = pIcons_LOD->GetTexture(item_texture_id);
|
|
242 v6 = item_texture->GetWidth();
|
2497
|
243 if ( v6 < 14 )
|
|
244 v6 = 14;
|
|
245 texture_cell_width = ((v6 - 14) >> 5) + 1;
|
2575
|
246 v8 = item_texture->GetHeight();
|
2497
|
247 if ( v8 < 14 )
|
|
248 v8 = 14;
|
|
249 texture_cell_height = ((v8 - 14) >> 5) + 1;
|
2575
|
250
|
|
251 if (item_texture)
|
|
252 {
|
|
253 item_texture->Release();
|
|
254 item_texture = nullptr;
|
|
255 }
|
|
256 /*if ( !areWeLoadingTexture )
|
2497
|
257 {
|
|
258 item_texture->Release();
|
|
259 pIcons_LOD->SyncLoadedFilesCount();
|
2575
|
260 }*/
|
|
261
|
2497
|
262 if ( (texture_cell_width + test_cell_position % chest_cell_width <= chest_cell_width) &&
|
|
263 (texture_cell_height + test_cell_position / chest_cell_width <= chest_cell_heght) )
|
|
264 { //we not put over borders
|
|
265 _row = 0;
|
|
266 if ( texture_cell_height <= 0 )
|
|
267 return true;
|
|
268 _cell_rows = 0;
|
|
269 while ( 1 )
|
|
270 {
|
|
271 _column = 0;
|
|
272 if ( texture_cell_width > 0 )
|
|
273 {
|
|
274 while ( pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]==0)
|
|
275 {
|
|
276 ++_column;
|
|
277 if ( _column >= texture_cell_width )
|
|
278 break;
|
|
279 }
|
|
280 if (pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]!=0)
|
|
281 return false;
|
|
282 }
|
|
283 _cell_rows += chest_cell_width;
|
|
284 ++_row;
|
|
285 if ( _row >= texture_cell_height )
|
|
286 return true;
|
|
287 }
|
|
288
|
|
289 }
|
|
290 return false;
|
|
291 }
|
|
292 // 506128: using guessed type int areWeLoadingTexture;
|
|
293
|
|
294 //----- (0041FF64) --------------------------------------------------------
|
|
295 int Chest::CountChestItems(signed int uChestID)
|
|
296 {
|
|
297 signed int item_count; // eax@1
|
|
298 int max_items; // edx@1
|
|
299 item_count = 0;
|
|
300 max_items = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID];
|
|
301 if ( max_items <= 0 )
|
|
302 item_count = -1;
|
|
303 else
|
|
304 {
|
|
305 while ( pChests[uChestID].igChestItems[item_count].uItemID )
|
|
306 {
|
|
307 ++item_count;
|
|
308 if ( item_count >= max_items )
|
|
309 {
|
|
310 item_count = -1;
|
|
311 break;
|
|
312 }
|
|
313 }
|
|
314 }
|
|
315 return item_count;
|
|
316 }
|
|
317
|
|
318 //----- (0041FFA2) --------------------------------------------------------
|
|
319 int Chest::PutItemInChest(int position, ItemGen *put_item, signed int uChestID)
|
|
320 {//(rus: положить предмет в ящик)
|
|
321 ItemGen *v4; // edi@1
|
|
322 int v5; // esi@1
|
|
323 int result; // eax@11
|
2575
|
324 //unsigned int v7; // eax@12
|
2497
|
325 int v8; // edx@12
|
2575
|
326 //Texture_MM7 *texture; // ecx@12
|
2497
|
327 signed int v10; // eax@12
|
|
328 signed int v11; // edi@14
|
|
329 unsigned int v12; // esi@14
|
|
330 int v13; // edi@16
|
|
331 void *v14; // edi@21
|
|
332 int v15; // edi@21
|
|
333 int i; // ecx@21
|
|
334 ItemGen *Src; // [sp+Ch] [bp-18h]@1
|
|
335 signed int item_in_chest_count; // [sp+10h] [bp-14h]@2
|
|
336 int v19; // [sp+14h] [bp-10h]@1
|
|
337 int v20; // [sp+18h] [bp-Ch]@19
|
|
338 signed int v21; // [sp+1Ch] [bp-8h]@1
|
|
339 // signed int v22; // [sp+20h] [bp-4h]@3
|
|
340 int v23; // [sp+20h] [bp-4h]@19
|
|
341
|
|
342 v21 = 0;
|
|
343 v4 = put_item;
|
|
344 v5 = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID];
|
|
345 Src = put_item;
|
|
346 v19 = pChestWidthsByType[pChests[uChestID].uChestBitmapID];
|
|
347 if ( position == -1 )
|
|
348 {
|
|
349 item_in_chest_count = CountChestItems(uChestID);
|
|
350 if ( item_in_chest_count == -1 )
|
|
351 return 0;
|
|
352 for( int _i = 0; _i < v5; _i++)
|
|
353 {
|
|
354 if ( Chest::CanPlaceItemAt(_i, v4->uItemID, pChestWindow->par1C) )
|
|
355 v21 = _i;
|
|
356 }
|
|
357 if ( v21 == v5 )
|
|
358 {
|
|
359 if ( uActiveCharacter )
|
|
360 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0);
|
|
361 return 0;
|
|
362 }
|
|
363 HIWORD(v8) = 0;
|
2575
|
364
|
|
365 auto texture = assets->GetImage_16BitColorKey(v4->GetIconName(), 0x7FF);
|
|
366 //v7 = pIcons_LOD->LoadTexture(v4->GetIconName(), TEXTURE_16BIT_PALETTE);
|
|
367 //texture = pIcons_LOD->GetTexture(v7);
|
|
368
|
|
369 v10 = texture->GetWidth();
|
|
370 if ( texture->GetWidth() < 14 )
|
2497
|
371 v10 = 14;
|
|
372 v12 = ((v10 - 14) >> 5) + 1;
|
2575
|
373 v11 = texture->GetHeight();
|
|
374 if ( texture->GetHeight() < 14 )
|
2497
|
375 v11 = 14;
|
|
376 v13 = ((v11 - 14) >> 5) + 1;
|
|
377 if ( !areWeLoadingTexture )
|
|
378 {
|
|
379 texture->Release();
|
|
380 pIcons_LOD->SyncLoadedFilesCount();
|
|
381 }
|
|
382 if ( v13 > 0 )
|
|
383 {
|
|
384 v23 = 0;
|
|
385 v20 = v13;
|
|
386 do
|
|
387 {
|
|
388 if ( (signed int)v12 > 0 )
|
|
389 {
|
|
390 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23];
|
|
391 LOWORD(v8) = -1 - v21;
|
|
392 v8 <<= 16;
|
|
393 LOWORD(v8) = -1 - v21;
|
|
394 memset32(v14, v8, v12 >> 1);
|
|
395 v15 = (int)((char *)v14 + 4 * (v12 >> 1));
|
|
396 for ( i = v12 & 1; i; --i )
|
|
397 {
|
|
398 *(short *)v15 = v8;
|
|
399 v15 += 2;
|
|
400 }
|
|
401 }
|
|
402 v23 += v19;
|
|
403 --v20;
|
|
404 }
|
|
405 while ( v20 );
|
|
406 }
|
|
407 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1;
|
|
408 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen));
|
|
409 result = v21 + 1;
|
|
410 }
|
|
411 else
|
|
412 result = 1;
|
|
413 return result;
|
|
414 }
|
|
415 // 506128: using guessed type int areWeLoadingTexture;
|
|
416
|
|
417 //----- (0042013E) --------------------------------------------------------
|
|
418 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, signed int uChestID )
|
|
419 {
|
|
420 int uItemID; // edi@1
|
|
421 int v6; // edx@4
|
|
422 unsigned int v7; // eax@5
|
2574
|
423 Texture_MM7 *texture; // ecx@5
|
2497
|
424 signed int v9; // eax@5
|
|
425 signed int v10; // edi@7
|
|
426 unsigned int texture_cell_width; // ebx@7
|
|
427 int textute_cell_height; // edi@9
|
|
428 int chest_cell_row_pos; // edx@12
|
|
429 int chest_cell_width; // [sp+10h] [bp-Ch]@11
|
|
430
|
|
431 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID;
|
|
432 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]);
|
|
433 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges)
|
|
434 {
|
|
435 v6 = rand() % 21 + 10;
|
|
436 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6;
|
|
437 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6;
|
|
438 }
|
|
439 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
|
|
440 texture = pIcons_LOD->GetTexture(v7);
|
|
441 v9 = texture->uTextureWidth;
|
|
442 if ( texture->uTextureWidth < 14 )
|
|
443 v9 = 14;
|
|
444 texture_cell_width = ((v9 - 14) >> 5) + 1;
|
|
445 v10 = texture->uTextureHeight;
|
|
446 if ( texture->uTextureHeight < 14 )
|
|
447 v10 = 14;
|
|
448 textute_cell_height = ((v10 - 14) >> 5) + 1;
|
|
449 if ( !areWeLoadingTexture )
|
|
450 {
|
|
451 texture->Release();
|
|
452 pIcons_LOD->SyncLoadedFilesCount();
|
|
453 }
|
|
454 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID];
|
|
455 chest_cell_row_pos = 0;
|
|
456 for(int i = 0; i < textute_cell_height; ++i)
|
|
457 {
|
|
458 for (int j = 0; j < texture_cell_width; ++j)
|
|
459 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1);
|
|
460 chest_cell_row_pos += chest_cell_width;
|
|
461 }
|
|
462 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1;
|
|
463 }
|
|
464 // 506128: using guessed type int areWeLoadingTexture;
|
|
465
|
|
466 //----- (00420284) --------------------------------------------------------
|
|
467 void Chest::PlaceItems(signed int uChestID )
|
|
468 {
|
|
469 int uChestArea; // edi@1
|
|
470 int random_chest_pos; // eax@2
|
|
471 int test_position; // ebx@11
|
|
472 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1
|
|
473 int chest_item_id; // [sp+9Ch] [bp-10h]@10
|
|
474 unsigned int items_counter; // [sp+A4h] [bp-8h]@8
|
|
475
|
|
476 pRenderer->ClearZBuffer(0, 479);
|
|
477 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID];
|
|
478 memset(chest_cells_map, 0, 144);
|
|
479 //fill cell map at random positions
|
|
480 for ( items_counter = 0; items_counter < uChestArea; ++items_counter )
|
|
481 {
|
|
482 //get random position in chest
|
|
483 do
|
|
484 random_chest_pos = (unsigned __int8)rand();
|
|
485 while ( random_chest_pos >= uChestArea );
|
|
486 //if this pos occupied move to next
|
|
487 while ( chest_cells_map[random_chest_pos] )
|
|
488 {
|
|
489 ++random_chest_pos;
|
|
490 if ( random_chest_pos == uChestArea )
|
|
491 random_chest_pos = 0;
|
|
492 }
|
|
493 chest_cells_map[random_chest_pos] = items_counter;
|
|
494 }
|
|
495 items_counter = 0;
|
|
496
|
|
497 for (items_counter = 0; items_counter<uChestArea; ++items_counter)
|
|
498 {
|
|
499 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID;
|
|
500 if ( chest_item_id )
|
|
501 {
|
|
502 test_position = 0;
|
|
503 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) )
|
|
504 {
|
|
505 ++test_position;
|
|
506 if ( test_position >= uChestArea )
|
|
507 break;
|
|
508 }
|
|
509 if(test_position<uChestArea)
|
|
510 {
|
|
511 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID);
|
|
512 if ( pChests[uChestID].uFlags & CHEST_OPENED)
|
|
513 pChests[uChestID].igChestItems[items_counter].SetIdentified();
|
|
514 }
|
|
515 }
|
|
516 }
|
|
517 pChests[uChestID].SetInitialized(true);
|
|
518 }
|
|
519 // 420284: using guessed type char Dst[144];
|
|
520
|
|
521 //----- (00448A17) --------------------------------------------------------
|
|
522 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle)
|
|
523 {
|
|
524 if ( uChestID >= 0 && uChestID <= 19 )
|
|
525 {
|
|
526 if ( bToggle )
|
|
527 pChests[uChestID].uFlags |= uFlag;
|
|
528 else
|
|
529 pChests[uChestID].uFlags &= ~uFlag;
|
|
530 }
|
|
531 }
|
|
532
|
|
533 //----- (00458B03) --------------------------------------------------------
|
|
534 void ChestList::ToFile()
|
|
535 {
|
|
536 FILE *v2; // eax@1
|
|
537 FILE *v3; // edi@1
|
|
538
|
|
539 v2 = fopen("data\\dchest.bin", "wb");
|
|
540 v3 = v2;
|
|
541 if ( !v2 )
|
|
542 Error("Unable to save dchest.bin!");
|
|
543
|
|
544 fwrite(this, 4, 1, v2);
|
|
545 fwrite(this->pChests, 36, this->uNumChests, v3);
|
|
546 fclose(v3);
|
|
547 }
|
|
548
|
|
549
|
|
550 //----- (00458B4F) --------------------------------------------------------
|
|
551 void ChestList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
|
|
552 {
|
|
553 uint num_mm6_chests = data_mm6 ? *(int *)data_mm6 : 0,
|
|
554 num_mm7_chests = data_mm7 ? *(int *)data_mm7 : 0,
|
|
555 num_mm8_chests = data_mm8 ? *(int *)data_mm8 : 0;
|
|
556
|
|
557 uNumChests = num_mm6_chests + num_mm7_chests + num_mm8_chests;
|
|
558 assert(uNumChests);
|
|
559 assert(!num_mm8_chests);
|
|
560
|
|
561 pChests = (ChestDesc *)malloc(uNumChests * sizeof(ChestDesc));
|
|
562 memcpy(pChests, (char *)data_mm7 + 4, num_mm7_chests * sizeof(ChestDesc));
|
|
563 memcpy(pChests + num_mm7_chests, (char *)data_mm6 + 4, num_mm6_chests * sizeof(ChestDesc));
|
|
564 memcpy(pChests + num_mm6_chests + num_mm7_chests, (char *)data_mm8 + 4, num_mm8_chests * sizeof(ChestDesc));
|
|
565 }
|
|
566
|
|
567
|
|
568 //----- (00458B9C) --------------------------------------------------------
|
|
569 int ChestList::FromFileTxt(const char *Args)
|
|
570 {
|
|
571 //ChestList *v2; // ebx@1
|
|
572 __int32 v3; // edi@1
|
|
573 FILE *v4; // eax@1
|
|
574 unsigned int v5; // esi@3
|
|
575 const void *v6; // ST18_4@9
|
|
576 void *v7; // eax@9
|
|
577 FILE *v8; // ST0C_4@11
|
|
578 char *i; // eax@11
|
|
579 char v10; // al@14
|
|
580 const char *v11; // ST14_4@14
|
|
581 char v12; // al@14
|
|
582 const char *v13; // ST10_4@14
|
|
583 char Buf; // [sp+8h] [bp-2F0h]@3
|
|
584 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4
|
|
585 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4
|
|
586 FILE *File; // [sp+2F4h] [bp-4h]@1
|
|
587 unsigned int Argsa; // [sp+300h] [bp+8h]@3
|
|
588
|
|
589 //v2 = this;
|
|
590 free(this->pChests);
|
|
591 v3 = 0;
|
|
592 this->pChests = 0;
|
|
593 this->uNumChests = 0;
|
|
594 v4 = fopen(Args, "r");
|
|
595 File = v4;
|
|
596 if ( !v4 )
|
|
597 Error("ChestDescriptionList::load - Unable to open file: %s.");
|
|
598
|
|
599 v5 = 0;
|
|
600 Argsa = 0;
|
|
601 if ( fgets(&Buf, 490, v4) )
|
|
602 {
|
|
603 do
|
|
604 {
|
|
605 *strchr(&Buf, 10) = 0;
|
|
606 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17));
|
|
607 if ( v17.uPropCount && *v17.pProperties[0] != 47 )
|
|
608 ++Argsa;
|
|
609 }
|
|
610 while ( fgets(&Buf, 490, File) );
|
|
611 v5 = Argsa;
|
|
612 v3 = 0;
|
|
613 }
|
|
614 v6 = this->pChests;
|
|
615 this->uNumChests = v5;
|
|
616 v7 = malloc(36 * v5);
|
|
617 this->pChests = (ChestDesc *)v7;
|
|
618 if ( v7 == (void *)v3 )
|
|
619 Error("ChestDescriptionList::load - Out of Memory!");
|
|
620
|
|
621 memset(v7, v3, 36 * this->uNumChests);
|
|
622 v8 = File;
|
|
623 this->uNumChests = v3;
|
|
624 fseek(v8, v3, v3);
|
|
625 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
|
|
626 {
|
|
627 *strchr(&Buf, 10) = 0;
|
|
628 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17));
|
|
629 if ( v17.uPropCount && *v17.pProperties[0] != 47 )
|
|
630 {
|
|
631 strcpy(this->pChests[this->uNumChests].pName, v17.pProperties[0]);
|
|
632 v10 = atoi(v17.pProperties[1]);
|
|
633 v11 = v17.pProperties[2];
|
|
634 this->pChests[this->uNumChests].uWidth = v10;
|
|
635 v12 = atoi(v11);
|
|
636 v13 = v17.pProperties[3];
|
|
637 this->pChests[this->uNumChests].uHeight = v12;
|
|
638 this->pChests[this->uNumChests++].uTextureID = atoi(v13);
|
|
639 }
|
|
640 }
|
|
641 fclose(File);
|
|
642 return 1;
|
|
643 }
|
|
644
|
|
645 //----- (00420B13) --------------------------------------------------------
|
|
646 void __fastcall sub_420B13(int a1, int a2)
|
|
647 { //Give item from chest(rus: Взять предмет из ящика)
|
|
648 void *v2; // eax@1
|
|
649 unsigned int v4; // eax@1
|
2574
|
650 Texture_MM7 *texture; // ecx@1
|
2497
|
651 signed int v6; // eax@1
|
|
652 signed int v7; // edi@3
|
|
653 signed int v8; // eax@3
|
|
654 int v9; // edi@3
|
|
655 int v10; // eax@5
|
|
656 int v11; // esi@8
|
|
657 unsigned int v12; // ecx@10
|
|
658 void *v13; // edi@10
|
|
659 unsigned __int8 v14; // cf@10
|
|
660 int v15; // edi@10
|
|
661 int i; // ecx@10
|
|
662 int v17; // [sp+Ch] [bp-14h]@1
|
|
663 int v18; // [sp+10h] [bp-10h]@3
|
|
664 int v21; // [sp+1Ch] [bp-4h]@5
|
|
665 int v22; // [sp+1Ch] [bp-4h]@8
|
|
666
|
|
667 v2 = (void *)(5324 * (int)pChestWindow->ptr_1C);
|
|
668 v17 = pChestWidthsByType[pChests[(int)pChestWindow->ptr_1C].uChestBitmapID];
|
|
669 v4 = pIcons_LOD->LoadTexture(pChests[(int)pChestWindow->ptr_1C].igChestItems[a1].GetIconName(), TEXTURE_16BIT_PALETTE);
|
|
670 texture = pIcons_LOD->GetTexture(v4);
|
|
671
|
|
672 v6 = texture->uTextureWidth;
|
|
673 if ( texture->uTextureWidth < 14 )
|
|
674 v6 = 14;
|
|
675 v7 = v6 - 14;
|
|
676 v9 = (v7 >> 5) + 1;
|
|
677 v18 = v9;
|
|
678
|
|
679 v8 = texture->uTextureHeight;
|
|
680 if ( texture->uTextureHeight < 14 )
|
|
681 v8 = 14;
|
|
682 v10 = ((v8 - 14) >> 5) + 1;
|
|
683 v21 = v10;
|
|
684
|
|
685 if ( !areWeLoadingTexture )
|
|
686 {
|
|
687 texture->Release();
|
|
688 pIcons_LOD->SyncLoadedFilesCount();
|
|
689 v10 = v21;
|
|
690 }
|
|
691 if ( v10 > 0 )
|
|
692 {
|
|
693 v11 = 0;
|
|
694 for ( v22 = v10; v22; --v22 )
|
|
695 {
|
|
696 if ( v9 > 0 )
|
|
697 {
|
|
698 v12 = v9;
|
|
699 v13 = &pChests[(int)pChestWindow->ptr_1C].pInventoryIndices[a2 + v11];
|
|
700 v14 = v12 & 1;
|
|
701 v12 >>= 1;
|
|
702 memset(&pChests[(int)pChestWindow->ptr_1C].pInventoryIndices[a2 + v11], 0, 4 * v12);
|
|
703 v15 = (int)((char *)v13 + 4 * v12);
|
|
704 for ( i = v14; i; --i )
|
|
705 {
|
|
706 *(short *)v15 = 0;
|
|
707 v15 += 2;
|
|
708 }
|
|
709 v9 = v18;
|
|
710 }
|
|
711 v11 += v17;
|
|
712 }
|
|
713 }
|
|
714 pChests[(int)pChestWindow->ptr_1C].igChestItems[a1].Reset();
|
|
715 }
|
|
716 // 506128: using guessed type int areWeLoadingTexture;
|
|
717 //----- (00420E01) --------------------------------------------------------
|
|
718 void Chest::OnChestLeftClick()
|
|
719 {
|
|
720 int v2; // eax@2
|
|
721 int v3; // ebx@4
|
|
722 int v4; // esi@6
|
|
723 POINT cursor; // [sp+84h] [bp-8h]@2
|
|
724
|
|
725 SpriteObject v6; // [sp+Ch] [bp-80h]@1
|
|
726 if ( pParty->pPickedItem.uItemID )
|
|
727 {
|
|
728 if ( Chest::PutItemInChest(-1, &pParty->pPickedItem, pGUIWindow_CurrentMenu->par1C) )
|
|
729 pMouse->RemoveHoldingItem();
|
|
730 }
|
|
731 else
|
|
732 {
|
|
733 pMouse->GetCursorPos(&cursor);
|
|
734 v2 = pRenderer->pActiveZBuffer[cursor.x + pSRZBufferLineOffsets[cursor.y]] & 0xFFFF;
|
|
735 if ( v2 )
|
|
736 {
|
|
737 if ( v2 )
|
|
738 v3 = v2 - 1;
|
|
739 else
|
|
740 v3 = -1;
|
|
741 v4 = pChests[(int)pGUIWindow_CurrentMenu->par1C].pInventoryIndices[v3] - 1;
|
|
742 if ( pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4].GetItemEquipType() == EQUIP_GOLD )
|
|
743 {
|
2567
|
744 pParty->PartyFindsGold(pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4].special_enchantment, 0);
|
2497
|
745 viewparams->bRedrawGameUI = 1;
|
|
746 }
|
|
747 else
|
|
748 pParty->SetHoldingItem(&pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4]);
|
|
749 sub_420B13(v4, v3);
|
|
750 }
|
|
751 }
|
|
752 } |