Mercurial > mm7
annotate Chest.cpp @ 1110:cf6cd674c398
bitwise operator ambiguity reduced
author | Grumpy7 |
---|---|
date | Mon, 27 May 2013 23:05:32 +0200 |
parents | d48c762de563 |
children | 29a8defbad9e |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
426 | 2 #include <assert.h> |
0 | 3 |
1016 | 4 #include "BSPModel.h" |
5 #include "Items.h" | |
0 | 6 #include "Chest.h" |
7 #include "FrameTableInc.h" | |
8 #include "Allocator.h" | |
421 | 9 #include "LOD.h" |
10 #include "MapInfo.h" | |
11 #include "Actor.h" | |
12 #include "Outdoor.h" | |
13 #include "DecorationList.h" | |
14 #include "Party.h" | |
15 #include "AudioPlayer.h" | |
16 #include "Math.h" | |
17 #include "Texts.h" | |
18 #include "ObjectList.h" | |
19 #include "GUIWindow.h" | |
20 #include "Time.h" | |
0 | 21 |
22 #include "mm7_data.h" | |
848 | 23 #include "MM7.h" |
1016 | 24 #include "SpriteObject.h" |
0 | 25 |
26 | |
27 | |
28 size_t uNumChests; // idb | |
29 struct ChestList *pChestList; | |
30 Chest pChests[20]; | |
31 | |
32 | |
528 | 33 const int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42}; |
34 const int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34}; | |
35 const int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; | |
526 | 36 const int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9}; |
0 | 37 |
38 | |
421 | 39 //----- (0042041E) -------------------------------------------------------- |
526 | 40 bool Chest::Open( signed int uChestID ) |
822 | 41 { |
426 | 42 //char *v1; // edi@5 |
421 | 43 unsigned int v2; // eax@8 |
44 GUIWindow *v3; // eax@15 | |
45 int v5; // edx@16 | |
46 int v6; // eax@16 | |
47 ODMFace *v7; // eax@19 | |
48 int v8; // edx@19 | |
49 int v9; // edi@19 | |
50 signed int v10; // ebx@19 | |
51 int v11; // ecx@19 | |
52 int v12; // eax@19 | |
53 BLVFace *v13; // eax@20 | |
54 int v14; // ebx@21 | |
55 int v15; // edi@21 | |
56 int v16; // ecx@22 | |
57 __int64 v17; // qax@22 | |
58 double v18; // st7@23 | |
59 double v19; // st6@23 | |
60 double v20; // st7@23 | |
61 int v21; // ecx@26 | |
62 char v22[12]; // ST4C_12@28 | |
63 unsigned int *v23; // edi@28 | |
64 unsigned __int16 v24; // di@28 | |
65 signed int v25; // ecx@28 | |
66 char *v26; // edx@29 | |
67 unsigned __int16 v27; // ax@32 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
469
diff
changeset
|
68 //SpriteObject a1; // [sp+14h] [bp-B0h]@28 |
1052 | 69 int v29[4]; // [sp+84h] [bp-40h]@16 |
70 //int v30; // [sp+88h] [bp-3Ch]@16 | |
71 //int v31; // [sp+8Ch] [bp-38h]@16 | |
72 //int v32; // [sp+90h] [bp-34h]@16 | |
421 | 73 float v33; // [sp+94h] [bp-30h]@23 |
426 | 74 //char *v34; // [sp+98h] [bp-2Ch]@5 |
421 | 75 int v35; // [sp+9Ch] [bp-28h]@16 |
76 Vec3_int_ pOut; // [sp+A0h] [bp-24h]@28 | |
77 int a4; // [sp+ACh] [bp-18h]@1 | |
78 int v38; // [sp+B0h] [bp-14h]@21 | |
79 int sRotX; // [sp+B4h] [bp-10h]@23 | |
80 float v40; // [sp+B8h] [bp-Ch]@23 | |
81 float v41; // [sp+BCh] [bp-8h]@23 | |
82 int sRotY; // [sp+C0h] [bp-4h]@8 | |
83 | |
426 | 84 //a4 = uChestID; |
85 assert(uChestID < 20); | |
526 | 86 if ((uChestID <0)&&(uChestID >=20) ) |
87 return false; | |
88 auto chest = &pChests[uChestID]; | |
426 | 89 |
421 | 90 ++pIcons_LOD->uTexturePacksCount; |
426 | 91 if (!pIcons_LOD->uNumPrevLoadedFiles) |
421 | 92 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles; |
426 | 93 |
94 | |
95 //v1 = (char *)&pChests[uChestID].uFlags; | |
96 //v34 = v1; | |
97 if (!chest->Initialized()) | |
526 | 98 Chest::PlaceItems(uChestID); |
426 | 99 |
421 | 100 if ( !uActiveCharacter ) |
101 return 0; | |
102 *(float *)&sRotY = 0.0; | |
103 v2 = pMapStats->GetMapInfo(pCurrentMapName); | |
426 | 104 if ( !chest->Trapped() || !v2 ) |
421 | 105 goto LABEL_12; |
106 if ( pPlayers[uActiveCharacter]->GetDisarmTrap() < 2 * pMapStats->pInfos[v2].LockX5 ) | |
107 { | |
1052 | 108 v29[0] = 811; |
109 v29[1] = 812; | |
110 v29[2] = 813; | |
111 v29[3] = 814; | |
421 | 112 v5 = rand() % 4; |
848 | 113 v6 = PID_ID(EvtTargetObj); |
421 | 114 v35 = v5; |
848 | 115 if ( PID_TYPE(EvtTargetObj) == OBJECT_Decoration) |
421 | 116 { |
117 v16 = v6; | |
118 v14 = pLevelDecorations[v6].vPosition.x; | |
119 v38 = pLevelDecorations[v6].vPosition.y; | |
120 v17 = pDecorationList->pDecorations[pLevelDecorations[v6].uDecorationDescID].uDecorationHeight; | |
121 v15 = pLevelDecorations[v16].vPosition.z + (((signed int)v17 - HIDWORD(v17)) >> 1); | |
122 } | |
123 else | |
124 { | |
848 | 125 if ( PID_TYPE(EvtTargetObj) != OBJECT_BModel) |
421 | 126 goto LABEL_12; |
127 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
128 { | |
469 | 129 v7 = &pOutdoor->pBModels[EvtTargetObj >> 9].pFaces[(EvtTargetObj >> 3) & 0x3F]; |
421 | 130 v8 = v7->pBoundingBox.y1; |
131 v9 = v7->pBoundingBox.z2; | |
132 v10 = v7->pBoundingBox.x1 + v7->pBoundingBox.x2; | |
133 v11 = v7->pBoundingBox.y2; | |
134 v12 = v7->pBoundingBox.z1; | |
135 } | |
136 else | |
137 { | |
138 v13 = &pIndoor->pFaces[v6]; | |
139 v8 = v13->pBounding.y1; | |
140 v9 = v13->pBounding.z2; | |
141 v10 = v13->pBounding.x1 + v13->pBounding.x2; | |
142 v11 = v13->pBounding.y2; | |
143 v12 = v13->pBounding.z1; | |
144 } | |
145 v14 = v10 >> 1; | |
146 v38 = (v8 + v11) >> 1; | |
147 v15 = (v12 + v9) >> 1; | |
148 } | |
149 v18 = (double)pParty->vPosition.x - (double)v14; | |
150 *(float *)&a4 = v18; | |
151 v19 = (double)pParty->vPosition.y - (double)v38; | |
152 v33 = v19; | |
153 v41 = (double)pParty->sEyelevel + (double)pParty->vPosition.z - (double)v15; | |
154 *(float *)&sRotY = v19 * v19; | |
155 *(float *)&sRotX = v18 * v18; | |
156 v20 = sqrt(v41 * v41 + *(float *)&sRotX + *(float *)&sRotY); | |
157 v40 = v20; | |
158 if ( v20 <= 1.0 ) | |
159 { | |
160 *(float *)&sRotX = 0.0; | |
161 *(float *)&sRotY = 0.0; | |
162 } | |
163 else | |
164 { | |
165 sRotY = (signed __int64)sqrt(*(float *)&sRotX + *(float *)&sRotY); | |
166 sRotX = stru_5C6E00->Atan2((signed __int64)*(float *)&a4, (signed __int64)v33); | |
167 sRotY = stru_5C6E00->Atan2(sRotY, (signed __int64)v41); | |
168 } | |
169 v21 = 256; | |
170 if ( v40 < 256.0 ) | |
171 v21 = (signed __int64)v40 / 4; | |
172 *(int *)&v22[8] = v15; | |
173 *(_QWORD *)v22 = __PAIR__(v38, v14); | |
174 Vec3_int_::Rotate(v21, sRotX, sRotY, *(Vec3_int_ *)v22, &pOut.x, &pOut.z, &pOut.y); | |
175 v23 = (unsigned int *)(&v29 + v35); | |
176 sub_42F7EB_DropItemAt(*v23, pOut.x, pOut.z, pOut.y, 0, 1, 0, 0x30u, 0); | |
177 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
469
diff
changeset
|
178 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
|
179 //SpriteObject::SpriteObject(&a1); |
421 | 180 |
181 a1.stru_24.Reset(); | |
182 v24 = *(short *)v23; | |
183 v25 = 0; | |
822 | 184 a1.spell_skill = 0; |
185 a1.spell_level = 0; | |
186 a1.spell_id = 0; | |
421 | 187 a1.field_54 = 0; |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
469
diff
changeset
|
188 a1.uType = v24; |
421 | 189 if ( (signed int)pObjectList->uNumObjects <= 0 ) |
190 { | |
191 LABEL_32: | |
192 v27 = 0; | |
193 } | |
194 else | |
195 { | |
196 v26 = (char *)&pObjectList->pObjects->uObjectID; | |
197 while ( v24 != *(short *)v26 ) | |
198 { | |
199 ++v25; | |
200 v26 += 56; | |
201 if ( v25 >= (signed int)pObjectList->uNumObjects ) | |
202 goto LABEL_32; | |
203 } | |
204 v27 = v25; | |
205 } | |
206 a1.uObjectDescID = v27; | |
207 a1.vPosition.y = pOut.z; | |
208 a1.vPosition.x = pOut.x; | |
209 a1.vPosition.z = pOut.y; | |
210 a1.uSoundID = 0; | |
211 a1.uAttributes = 48; | |
212 a1.uSectorID = pIndoor->GetSector(pOut.x, pOut.z, pOut.y); | |
213 a1.uSpriteFrameID = 0; | |
822 | 214 a1.spell_caster_pid = 0; |
823 | 215 a1.spell_target_pid = 0; |
421 | 216 a1.uFacing = 0; |
217 a1.Create(0, 0, 0, 0); | |
218 pAudioPlayer->PlaySound(SOUND_8, 0, 0, -1, 0, 0, 0, 0); | |
219 a1._438E35(); | |
426 | 220 chest->SetInitialized(false);//*v34 &= 0xFEu; |
421 | 221 if ( uActiveCharacter && !qword_A750D8 && !dword_507CD8 ) |
222 { | |
223 qword_A750D8 = 256i64; | |
224 word_A750E0 = 5; | |
225 word_A750E2 = uActiveCharacter; | |
226 } | |
227 pIcons_LOD->_4114F2(); | |
228 dword_507CD8 = 0; | |
229 return 0; | |
230 } | |
426 | 231 chest->SetInitialized(false);//*v1 &= 0xFEu; |
421 | 232 sRotY = 1; |
233 LABEL_12: | |
234 pAudioPlayer->StopChannels(-1, -1); | |
426 | 235 pAudioPlayer->PlaySound(SOUND_OpenChest, 0, 0, -1, 0, 0, 0, 0); |
421 | 236 if ( *(float *)&sRotY != 0.0 ) |
237 { | |
238 if ( !dword_507CD8 ) | |
239 pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0); | |
240 } | |
241 dword_507CD8 = 0; | |
526 | 242 |
948 | 243 pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Chest, uChestID, 0); |
244 | |
245 pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit | |
987 | 246 pChestWindow->CreateButton( 7, 8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0); |
948 | 247 |
421 | 248 pCurrentScreen = SCREEN_CHEST; |
249 pEventTimer->Pause(); | |
250 return 1; | |
251 } | |
252 | |
253 //----- (0042092D) -------------------------------------------------------- | |
706 | 254 void Chest::DrawChestUI(signed int uChestID) |
526 | 255 { |
256 | |
257 int chestBitmapId; // eax@1 | |
258 unsigned int v5; // eax@1 | |
259 int chest_item_index; // ecx@3 | |
260 unsigned int item_texture_id; // eax@4 | |
261 Texture *item_texture; // esi@4 | |
262 signed int itemPixelWidth; // ecx@4 | |
263 signed int itemPixelHeght; // edx@4 | |
264 signed int v11; // eax@4 | |
265 int v12; // eax@6 | |
266 int v13; // eax@6 | |
267 unsigned int itemPixelPosX; // ST34_4@8 | |
268 int itemPixelPosY; // edi@8 | |
269 int *v16; // [sp+Ch] [bp-28h]@1 | |
270 int v17; // [sp+10h] [bp-24h]@4 | |
271 int chest_offs_y; // [sp+14h] [bp-20h]@1 | |
272 signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1 | |
273 int chest_offs_x; // [sp+1Ch] [bp-18h]@1 | |
274 signed int chestWidthCells; // [sp+20h] [bp-14h]@1 | |
528 | 275 signed int item_counter; // [sp+30h] [bp-4h]@1 |
421 | 276 |
526 | 277 v16 = pRenderer->pActiveZBuffer; |
278 pRenderer->ClearZBuffer(0, 479); | |
279 chestBitmapId = pChests[uChestID].uChestBitmapID; | |
280 chest_offs_x = pChestPixelOffsetX[chestBitmapId]; | |
281 chest_offs_y = pChestPixelOffsetY[chestBitmapId]; | |
282 chestWidthCells = pChestWidthsByType[chestBitmapId]; | |
283 chestHeghtCells = pChestHeightsByType[chestBitmapId]; | |
284 sprintf(pTmpBuf, "chest%02d", pChestList->pChests[chestBitmapId].uTextureID); | |
285 v5 = pIcons_LOD->LoadTexture(pTmpBuf, TEXTURE_16BIT_PALETTE); | |
945 | 286 pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5)); |
526 | 287 |
528 | 288 for (item_counter = 0; item_counter< chestWidthCells * chestHeghtCells; ++item_counter) |
526 | 289 { |
528 | 290 chest_item_index = pChests[uChestID].pInventoryIndices[item_counter]; |
526 | 291 if ( chest_item_index > 0 ) |
292 { | |
293 item_texture_id = pIcons_LOD->LoadTexture( | |
294 //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName, | |
295 pItemsTable->pItems[pChests[uChestID].igChestItems[chest_item_index-1].uItemID].pIconName, TEXTURE_16BIT_PALETTE); | |
945 | 296 item_texture = pIcons_LOD->GetTexture(item_texture_id); |
297 itemPixelWidth = item_texture->uTextureWidth; | |
298 itemPixelHeght = item_texture->uTextureHeight; | |
526 | 299 if ( itemPixelWidth < 14 ) |
300 itemPixelWidth = 14; | |
301 v12 = itemPixelWidth - 14; | |
302 v12 = v12 & 0xFFFFFFE0; | |
303 v13 = v12 + 32; | |
304 if ( itemPixelHeght < 14 ) | |
305 itemPixelHeght = 14; | |
600 | 306 itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth)/2); |
528 | 307 itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) + |
600 | 308 ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32- item_texture->uTextureHeight ) /2); |
526 | 309 pRenderer->DrawTextureTransparent( itemPixelPosX, itemPixelPosY, item_texture); |
528 | 310 sub_40F92A(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1); |
526 | 311 } |
312 } | |
945 | 313 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId)); |
421 | 314 } |
315 | |
316 | |
317 //----- (0041FE71) -------------------------------------------------------- | |
706 | 318 bool Chest::CanPlaceItemAt( signed int test_cell_position, int item_id, signed int uChestID ) |
526 | 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); | |
945 | 339 item_texture = pIcons_LOD->GetTexture(item_texture_id); |
340 v6 = item_texture->uTextureWidth; | |
526 | 341 if ( v6 < 14 ) |
342 v6 = 14; | |
1110 | 343 texture_cell_width = ((v6 - 14) >> 5) + 1; |
526 | 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(); | |
1006 | 351 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 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) -------------------------------------------------------- | |
706 | 386 int Chest::CountChestItems(signed 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) -------------------------------------------------------- | |
706 | 412 int Chest::PutItemInChest(int position, ItemGen *put_item, signed 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 | |
945 | 420 Texture *v9; // ecx@12 |
421 | 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; | |
945 | 467 v9 = pIcons_LOD->GetTexture(v7); |
468 v10 = v9->uTextureWidth; | |
421 | 469 if ( v10 < 14 ) |
470 v10 = 14; | |
945 | 471 v11 = v9->uTextureHeight; |
421 | 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(); | |
1006 | 479 pIcons_LOD->SyncLoadedFilesCount(); |
421 | 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) -------------------------------------------------------- | |
706 | 519 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, signed 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); |
945 | 542 v8 = pIcons_LOD->GetTexture(v7); |
543 v9 = v8->uTextureWidth; | |
528 | 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(); | |
1006 | 554 pIcons_LOD->SyncLoadedFilesCount(); |
528 | 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) -------------------------------------------------------- | |
706 | 571 void Chest::PlaceItems(signed 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 | |
608 | 584 for ( items_counter = 0; items_counter < uChestArea; ++items_counter ) |
585 { | |
526 | 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] ) | |
608 | 592 { |
526 | 593 ++random_chest_pos; |
594 if ( random_chest_pos == uChestArea ) | |
595 random_chest_pos = 0; | |
608 | 596 } |
528 | 597 chest_cells_map[random_chest_pos] = items_counter; |
608 | 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); |
592 | 616 if ( pChests[uChestID].uFlags & CHEST_OPENED) |
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 | |
706 | 625 //----- (00448A17) -------------------------------------------------------- |
626 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle) | |
627 { | |
628 unsigned __int16 *pFlags; // eax@3 | |
629 | |
630 if ( uChestID >= 0 && uChestID <= 19 ) | |
631 { | |
632 pFlags = &pChests[uChestID].uFlags; | |
633 if ( bToggle ) | |
634 *pFlags |= uFlag; | |
635 else | |
636 *pFlags &= ~uFlag; | |
637 } | |
638 } | |
639 | |
0 | 640 //----- (00458B03) -------------------------------------------------------- |
641 void ChestList::ToFile() | |
642 { | |
643 ChestList *v1; // esi@1 | |
644 FILE *v2; // eax@1 | |
645 FILE *v3; // edi@1 | |
646 | |
647 v1 = this; | |
648 v2 = fopen("data\\dchest.bin", "wb"); | |
649 v3 = v2; | |
650 if ( !v2 ) | |
651 Abortf("Unable to save dchest.bin!"); | |
652 fwrite(v1, 4u, 1u, v2); | |
653 fwrite(v1->pChests, 0x24u, v1->uNumChests, v3); | |
654 fclose(v3); | |
655 } | |
656 | |
657 | |
658 //----- (00458B4F) -------------------------------------------------------- | |
659 void ChestList::FromFile(void *pSerialized) | |
660 { | |
661 uNumChests = *(int *)pSerialized; | |
662 pChests = (ChestDesc *)pAllocator->AllocNamedChunk(pChests, 36 * uNumChests, "Chest Descrip"); | |
663 memcpy(pChests, (char *)pSerialized + 4, 36 * uNumChests); | |
664 } | |
665 | |
666 | |
667 //----- (00458B9C) -------------------------------------------------------- | |
668 int ChestList::FromFileTxt(const char *Args) | |
669 { | |
670 ChestList *v2; // ebx@1 | |
671 __int32 v3; // edi@1 | |
672 FILE *v4; // eax@1 | |
673 unsigned int v5; // esi@3 | |
674 const void *v6; // ST18_4@9 | |
675 void *v7; // eax@9 | |
676 FILE *v8; // ST0C_4@11 | |
677 char *i; // eax@11 | |
678 char v10; // al@14 | |
679 const char *v11; // ST14_4@14 | |
680 char v12; // al@14 | |
681 const char *v13; // ST10_4@14 | |
682 char Buf; // [sp+8h] [bp-2F0h]@3 | |
683 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4 | |
684 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4 | |
685 FILE *File; // [sp+2F4h] [bp-4h]@1 | |
686 unsigned int Argsa; // [sp+300h] [bp+8h]@3 | |
687 | |
688 v2 = this; | |
689 pAllocator->FreeChunk(this->pChests); | |
690 v3 = 0; | |
691 v2->pChests = 0; | |
692 v2->uNumChests = 0; | |
693 v4 = fopen(Args, "r"); | |
694 File = v4; | |
695 if ( !v4 ) | |
696 Abortf("ChestDescriptionList::load - Unable to open file: %s."); | |
697 v5 = 0; | |
698 Argsa = 0; | |
699 if ( fgets(&Buf, 490, v4) ) | |
700 { | |
701 do | |
702 { | |
703 *strchr(&Buf, 10) = 0; | |
703 | 704 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 705 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 706 ++Argsa; |
707 } | |
708 while ( fgets(&Buf, 490, File) ); | |
709 v5 = Argsa; | |
710 v3 = 0; | |
711 } | |
712 v6 = v2->pChests; | |
713 v2->uNumChests = v5; | |
714 v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip"); | |
715 v2->pChests = (ChestDesc *)v7; | |
716 if ( v7 == (void *)v3 ) | |
717 Abortf("ChestDescriptionList::load - Out of Memory!"); | |
718 memset(v7, v3, 36 * v2->uNumChests); | |
719 v8 = File; | |
720 v2->uNumChests = v3; | |
721 fseek(v8, v3, v3); | |
722 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
723 { | |
724 *strchr(&Buf, 10) = 0; | |
703 | 725 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 726 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 727 { |
728 strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]); | |
729 v10 = atoi(v17.pProperties[1]); | |
730 v11 = v17.pProperties[2]; | |
731 v2->pChests[v2->uNumChests].uWidth = v10; | |
732 v12 = atoi(v11); | |
733 v13 = v17.pProperties[3]; | |
734 v2->pChests[v2->uNumChests].uHeight = v12; | |
735 v2->pChests[v2->uNumChests++].uTextureID = atoi(v13); | |
736 } | |
737 } | |
738 fclose(File); | |
739 return 1; | |
740 } | |
526 | 741 |
742 //----- (00420B13) -------------------------------------------------------- | |
743 void __fastcall sub_420B13(int a1, int a2) | |
702 | 744 { |
526 | 745 void *v2; // eax@1 |
746 ItemGen *v3; // ebx@1 | |
747 unsigned int v4; // eax@1 | |
748 Texture *v5; // ecx@1 | |
749 signed int v6; // eax@1 | |
750 signed int v7; // edi@3 | |
751 signed int v8; // eax@3 | |
752 int v9; // edi@3 | |
753 int v10; // eax@5 | |
754 int v11; // esi@8 | |
755 unsigned int v12; // ecx@10 | |
756 void *v13; // edi@10 | |
757 unsigned __int8 v14; // cf@10 | |
758 int v15; // edi@10 | |
759 int i; // ecx@10 | |
760 int v17; // [sp+Ch] [bp-14h]@1 | |
761 int v18; // [sp+10h] [bp-10h]@3 | |
762 int v19; // [sp+14h] [bp-Ch]@1 | |
702 | 763 int v20; // [sp+18h] [bp-8h]@1 |
526 | 764 int v21; // [sp+1Ch] [bp-4h]@5 |
765 int v22; // [sp+1Ch] [bp-4h]@8 | |
766 | |
767 v19 = a2; | |
768 v2 = pChestWindow->ptr_1C; | |
702 | 769 v20 = (int)v2; |
526 | 770 v2 = (void *)(5324 * (int)v2); |
702 | 771 //v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4)); |
772 v3 = &pChests[v20].igChestItems[a1]; | |
773 //v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)]; | |
774 v17 = pChestWidthsByType[pChests[v20].uChestBitmapID]; | |
526 | 775 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v3->uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 776 v5 = pIcons_LOD->GetTexture(v4); |
777 v6 = v5->uTextureWidth; | |
526 | 778 if ( v6 < 14 ) |
779 v6 = 14; | |
780 v7 = v6 - 14; | |
781 v8 = v5->uTextureHeight; | |
782 v9 = (v7 >> 5) + 1; | |
783 v18 = v9; | |
784 if ( v8 < 14 ) | |
785 v8 = 14; | |
786 v10 = ((v8 - 14) >> 5) + 1; | |
787 v21 = v10; | |
788 if ( !areWeLoadingTexture ) | |
702 | 789 { |
526 | 790 v5->Release(); |
1006 | 791 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 792 v10 = v21; |
702 | 793 } |
526 | 794 if ( v10 > 0 ) |
702 | 795 { |
526 | 796 v11 = 0; |
797 v22 = v10; | |
798 do | |
702 | 799 { |
526 | 800 if ( v9 > 0 ) |
702 | 801 { |
526 | 802 v12 = v9; |
702 | 803 //v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20]; |
804 v13 = &pChests[v20].pInventoryIndices[v19 + v11]; | |
526 | 805 v14 = v12 & 1; |
806 v12 >>= 1; | |
807 memset(v13, 0, 4 * v12); | |
808 v15 = (int)((char *)v13 + 4 * v12); | |
809 for ( i = v14; i; --i ) | |
702 | 810 { |
526 | 811 *(short *)v15 = 0; |
812 v15 += 2; | |
702 | 813 } |
526 | 814 v9 = v18; |
702 | 815 } |
526 | 816 v11 += v17; |
817 --v22; | |
818 } | |
702 | 819 while ( v22 ); |
526 | 820 } |
702 | 821 v3->Reset(); |
822 } | |
526 | 823 // 506128: using guessed type int areWeLoadingTexture; |