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