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