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