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