Mercurial > mm7
annotate Chest.cpp @ 1320:2e3deb510de3
Слияние
author | Ritor1 |
---|---|
date | Fri, 28 Jun 2013 11:34:15 +0600 |
parents | 5450af4f57ef |
children | 8ea496564034 |
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 } | |
231 pIcons_LOD->_4114F2(); | |
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]; | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1202
diff
changeset
|
288 sprintf(pTmpBuf.data(), "chest%02d", pChestList->pChests[chestBitmapId].uTextureID); |
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 |
528 | 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, | |
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 |
526 int uItemID; // edi@1 | |
527 int v6; // edx@4 | |
528 unsigned int v7; // eax@5 | |
529 Texture *v8; // ecx@5 | |
530 signed int v9; // eax@5 | |
531 signed int v10; // edi@7 | |
532 unsigned int texture_cell_width; // ebx@7 | |
533 int textute_cell_height; // edi@9 | |
534 int chest_cell_row_pos; // edx@12 | |
535 int chest_cell_width; // [sp+10h] [bp-Ch]@11 | |
421 | 536 |
528 | 537 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID; |
538 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]); | |
539 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges) | |
421 | 540 { |
528 | 541 v6 = rand() % 21 + 10; |
542 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6; | |
543 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6; | |
421 | 544 } |
528 | 545 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 546 v8 = pIcons_LOD->GetTexture(v7); |
547 v9 = v8->uTextureWidth; | |
528 | 548 if ( v9 < 14 ) |
549 v9 = 14; | |
550 v10 = v8->uTextureHeight; | |
551 texture_cell_width = ((v9 - 14) >> 5) + 1; | |
552 if ( v10 < 14 ) | |
553 v10 = 14; | |
554 textute_cell_height = ((v10 - 14) >> 5) + 1; | |
555 if ( !areWeLoadingTexture ) | |
556 { | |
557 v8->Release(); | |
1006 | 558 pIcons_LOD->SyncLoadedFilesCount(); |
528 | 559 } |
560 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; | |
561 chest_cell_row_pos = 0; | |
562 for(int i=0; i<textute_cell_height; ++i) | |
563 { | |
564 for (int j=0; j<texture_cell_width; ++j) | |
565 { | |
566 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1); | |
567 } | |
568 chest_cell_row_pos += chest_cell_width; | |
569 } | |
570 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1; | |
421 | 571 } |
572 // 506128: using guessed type int areWeLoadingTexture; | |
573 | |
574 //----- (00420284) -------------------------------------------------------- | |
706 | 575 void Chest::PlaceItems(signed int uChestID ) |
421 | 576 { |
526 | 577 int uChestArea; // edi@1 |
578 int random_chest_pos; // eax@2 | |
579 int test_position; // ebx@11 | |
580 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 | |
581 int chest_item_id; // [sp+9Ch] [bp-10h]@10 | |
528 | 582 unsigned int items_counter; // [sp+A4h] [bp-8h]@8 |
526 | 583 |
584 pRenderer->ClearZBuffer(0, 479); | |
585 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
586 memset(chest_cells_map, 0, 144); | |
587 //fill cell map at random positions | |
608 | 588 for ( items_counter = 0; items_counter < uChestArea; ++items_counter ) |
589 { | |
526 | 590 //get random position in chest |
591 do | |
592 random_chest_pos = (unsigned __int8)rand(); | |
593 while ( random_chest_pos >= uChestArea ); | |
594 //if this pos occupied move to next | |
595 while ( chest_cells_map[random_chest_pos] ) | |
608 | 596 { |
526 | 597 ++random_chest_pos; |
598 if ( random_chest_pos == uChestArea ) | |
599 random_chest_pos = 0; | |
608 | 600 } |
528 | 601 chest_cells_map[random_chest_pos] = items_counter; |
608 | 602 } |
528 | 603 items_counter = 0; |
526 | 604 |
528 | 605 for (items_counter = 0; items_counter<uChestArea; ++items_counter) |
526 | 606 { |
528 | 607 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID; |
526 | 608 if ( chest_item_id ) |
609 { | |
610 test_position = 0; | |
611 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) | |
612 { | |
613 ++test_position; | |
614 if ( test_position >= uChestArea ) | |
615 break; | |
616 } | |
617 if(test_position<uChestArea) | |
618 { | |
528 | 619 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID); |
592 | 620 if ( pChests[uChestID].uFlags & CHEST_OPENED) |
528 | 621 pChests[uChestID].igChestItems[items_counter].SetIdentified(); |
526 | 622 } |
623 } | |
624 } | |
528 | 625 pChests[uChestID].SetInitialized(true); |
421 | 626 } |
627 // 420284: using guessed type char Dst[144]; | |
628 | |
706 | 629 //----- (00448A17) -------------------------------------------------------- |
630 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle) | |
631 { | |
632 unsigned __int16 *pFlags; // eax@3 | |
633 | |
634 if ( uChestID >= 0 && uChestID <= 19 ) | |
635 { | |
636 pFlags = &pChests[uChestID].uFlags; | |
637 if ( bToggle ) | |
638 *pFlags |= uFlag; | |
639 else | |
640 *pFlags &= ~uFlag; | |
641 } | |
642 } | |
643 | |
0 | 644 //----- (00458B03) -------------------------------------------------------- |
645 void ChestList::ToFile() | |
646 { | |
647 ChestList *v1; // esi@1 | |
648 FILE *v2; // eax@1 | |
649 FILE *v3; // edi@1 | |
650 | |
651 v1 = this; | |
652 v2 = fopen("data\\dchest.bin", "wb"); | |
653 v3 = v2; | |
654 if ( !v2 ) | |
655 Abortf("Unable to save dchest.bin!"); | |
656 fwrite(v1, 4u, 1u, v2); | |
657 fwrite(v1->pChests, 0x24u, v1->uNumChests, v3); | |
658 fclose(v3); | |
659 } | |
660 | |
661 | |
662 //----- (00458B4F) -------------------------------------------------------- | |
663 void ChestList::FromFile(void *pSerialized) | |
664 { | |
665 uNumChests = *(int *)pSerialized; | |
666 pChests = (ChestDesc *)pAllocator->AllocNamedChunk(pChests, 36 * uNumChests, "Chest Descrip"); | |
667 memcpy(pChests, (char *)pSerialized + 4, 36 * uNumChests); | |
668 } | |
669 | |
670 | |
671 //----- (00458B9C) -------------------------------------------------------- | |
672 int ChestList::FromFileTxt(const char *Args) | |
673 { | |
674 ChestList *v2; // ebx@1 | |
675 __int32 v3; // edi@1 | |
676 FILE *v4; // eax@1 | |
677 unsigned int v5; // esi@3 | |
678 const void *v6; // ST18_4@9 | |
679 void *v7; // eax@9 | |
680 FILE *v8; // ST0C_4@11 | |
681 char *i; // eax@11 | |
682 char v10; // al@14 | |
683 const char *v11; // ST14_4@14 | |
684 char v12; // al@14 | |
685 const char *v13; // ST10_4@14 | |
686 char Buf; // [sp+8h] [bp-2F0h]@3 | |
687 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4 | |
688 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4 | |
689 FILE *File; // [sp+2F4h] [bp-4h]@1 | |
690 unsigned int Argsa; // [sp+300h] [bp+8h]@3 | |
691 | |
692 v2 = this; | |
693 pAllocator->FreeChunk(this->pChests); | |
694 v3 = 0; | |
695 v2->pChests = 0; | |
696 v2->uNumChests = 0; | |
697 v4 = fopen(Args, "r"); | |
698 File = v4; | |
699 if ( !v4 ) | |
700 Abortf("ChestDescriptionList::load - Unable to open file: %s."); | |
701 v5 = 0; | |
702 Argsa = 0; | |
703 if ( fgets(&Buf, 490, v4) ) | |
704 { | |
705 do | |
706 { | |
707 *strchr(&Buf, 10) = 0; | |
703 | 708 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 709 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 710 ++Argsa; |
711 } | |
712 while ( fgets(&Buf, 490, File) ); | |
713 v5 = Argsa; | |
714 v3 = 0; | |
715 } | |
716 v6 = v2->pChests; | |
717 v2->uNumChests = v5; | |
718 v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip"); | |
719 v2->pChests = (ChestDesc *)v7; | |
720 if ( v7 == (void *)v3 ) | |
721 Abortf("ChestDescriptionList::load - Out of Memory!"); | |
722 memset(v7, v3, 36 * v2->uNumChests); | |
723 v8 = File; | |
724 v2->uNumChests = v3; | |
725 fseek(v8, v3, v3); | |
726 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
727 { | |
728 *strchr(&Buf, 10) = 0; | |
703 | 729 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 730 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 731 { |
732 strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]); | |
733 v10 = atoi(v17.pProperties[1]); | |
734 v11 = v17.pProperties[2]; | |
735 v2->pChests[v2->uNumChests].uWidth = v10; | |
736 v12 = atoi(v11); | |
737 v13 = v17.pProperties[3]; | |
738 v2->pChests[v2->uNumChests].uHeight = v12; | |
739 v2->pChests[v2->uNumChests++].uTextureID = atoi(v13); | |
740 } | |
741 } | |
742 fclose(File); | |
743 return 1; | |
744 } | |
526 | 745 |
746 //----- (00420B13) -------------------------------------------------------- | |
747 void __fastcall sub_420B13(int a1, int a2) | |
702 | 748 { |
526 | 749 void *v2; // eax@1 |
750 ItemGen *v3; // ebx@1 | |
751 unsigned int v4; // eax@1 | |
752 Texture *v5; // ecx@1 | |
753 signed int v6; // eax@1 | |
754 signed int v7; // edi@3 | |
755 signed int v8; // eax@3 | |
756 int v9; // edi@3 | |
757 int v10; // eax@5 | |
758 int v11; // esi@8 | |
759 unsigned int v12; // ecx@10 | |
760 void *v13; // edi@10 | |
761 unsigned __int8 v14; // cf@10 | |
762 int v15; // edi@10 | |
763 int i; // ecx@10 | |
764 int v17; // [sp+Ch] [bp-14h]@1 | |
765 int v18; // [sp+10h] [bp-10h]@3 | |
766 int v19; // [sp+14h] [bp-Ch]@1 | |
702 | 767 int v20; // [sp+18h] [bp-8h]@1 |
526 | 768 int v21; // [sp+1Ch] [bp-4h]@5 |
769 int v22; // [sp+1Ch] [bp-4h]@8 | |
770 | |
771 v19 = a2; | |
772 v2 = pChestWindow->ptr_1C; | |
702 | 773 v20 = (int)v2; |
526 | 774 v2 = (void *)(5324 * (int)v2); |
702 | 775 //v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4)); |
776 v3 = &pChests[v20].igChestItems[a1]; | |
777 //v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)]; | |
778 v17 = pChestWidthsByType[pChests[v20].uChestBitmapID]; | |
526 | 779 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v3->uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 780 v5 = pIcons_LOD->GetTexture(v4); |
781 v6 = v5->uTextureWidth; | |
526 | 782 if ( v6 < 14 ) |
783 v6 = 14; | |
784 v7 = v6 - 14; | |
785 v8 = v5->uTextureHeight; | |
786 v9 = (v7 >> 5) + 1; | |
787 v18 = v9; | |
788 if ( v8 < 14 ) | |
789 v8 = 14; | |
790 v10 = ((v8 - 14) >> 5) + 1; | |
791 v21 = v10; | |
792 if ( !areWeLoadingTexture ) | |
702 | 793 { |
526 | 794 v5->Release(); |
1006 | 795 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 796 v10 = v21; |
702 | 797 } |
526 | 798 if ( v10 > 0 ) |
702 | 799 { |
526 | 800 v11 = 0; |
801 v22 = v10; | |
802 do | |
702 | 803 { |
526 | 804 if ( v9 > 0 ) |
702 | 805 { |
526 | 806 v12 = v9; |
702 | 807 //v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20]; |
808 v13 = &pChests[v20].pInventoryIndices[v19 + v11]; | |
526 | 809 v14 = v12 & 1; |
810 v12 >>= 1; | |
811 memset(v13, 0, 4 * v12); | |
812 v15 = (int)((char *)v13 + 4 * v12); | |
813 for ( i = v14; i; --i ) | |
702 | 814 { |
526 | 815 *(short *)v15 = 0; |
816 v15 += 2; | |
702 | 817 } |
526 | 818 v9 = v18; |
702 | 819 } |
526 | 820 v11 += v17; |
821 --v22; | |
822 } | |
702 | 823 while ( v22 ); |
526 | 824 } |
702 | 825 v3->Reset(); |
826 } | |
526 | 827 // 506128: using guessed type int areWeLoadingTexture; |
1297 | 828 //----- (00420E01) -------------------------------------------------------- |
829 void __cdecl OnChestLeftClick() | |
830 { | |
831 int chest_id; // edi@1 | |
832 POINT *v1; // esi@2 | |
833 int v2; // eax@2 | |
834 int v3; // ebx@4 | |
835 int v4; // esi@6 | |
836 int v5; // ecx@6 | |
837 //SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
838 POINT v7; // [sp+7Ch] [bp-10h]@2 | |
839 POINT a2; // [sp+84h] [bp-8h]@2 | |
840 | |
841 SpriteObject v6; // [sp+Ch] [bp-80h]@1 | |
842 //SpriteObject::SpriteObject(&v6); | |
843 | |
844 chest_id = pGUIWindow_CurrentMenu->par1C; | |
845 if ( pParty->pPickedItem.uItemID ) | |
846 { | |
847 if ( Chest::PutItemInChest(-1, &pParty->pPickedItem, pGUIWindow_CurrentMenu->par1C) ) | |
848 pMouse->RemoveHoldingItem(); | |
849 } | |
850 else | |
851 { | |
852 v1 = pMouse->GetCursorPos(&a2); | |
853 v2 = pRenderer->pActiveZBuffer[v1->x + pSRZBufferLineOffsets[pMouse->GetCursorPos((POINT *)&v7)->y]] & 0xFFFF; | |
854 if ( v2 ) | |
855 { | |
856 if ( v2 ) | |
857 v3 = v2 - 1; | |
858 else | |
859 v3 = -1; | |
860 v4 = pChests[chest_id].pInventoryIndices[v3] - 1; | |
861 if ( pItemsTable->pItems[pChests[chest_id].igChestItems[v4].uItemID].uEquipType == EQUIP_GOLD ) | |
862 { | |
863 party_finds_gold(pChests[chest_id].igChestItems[v4].uSpecEnchantmentType, 0); | |
864 viewparams->bRedrawGameUI = 1; | |
865 } | |
866 else | |
867 { | |
868 pParty->SetHoldingItem(&pChests[chest_id].igChestItems[v4]); | |
869 } | |
870 sub_420B13(v4, v3); | |
871 } | |
872 } | |
873 } |