Mercurial > mm7
annotate Chest.cpp @ 1009:a32318b557c7
CastSpellInfo::_427E01_cast_spell() more clean 2
author | zipi |
---|---|
date | Sat, 18 May 2013 20:19:38 +0100 |
parents | e865f349aa41 |
children | 9ac94d00012e |
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" | |
848 | 23 #include "MM7.h" |
0 | 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 ) |
822 | 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; | |
848 | 112 v6 = PID_ID(EvtTargetObj); |
421 | 113 v35 = v5; |
848 | 114 if ( PID_TYPE(EvtTargetObj) == 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 { | |
848 | 124 if ( PID_TYPE(EvtTargetObj) != 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; | |
822 | 183 a1.spell_skill = 0; |
184 a1.spell_level = 0; | |
185 a1.spell_id = 0; | |
421 | 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; | |
822 | 213 a1.spell_caster_pid = 0; |
823 | 214 a1.spell_target_pid = 0; |
421 | 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 |
948 | 242 pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Chest, uChestID, 0); |
243 | |
244 pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit | |
987 | 245 pChestWindow->CreateButton( 7, 8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0); |
948 | 246 |
421 | 247 pCurrentScreen = SCREEN_CHEST; |
248 pEventTimer->Pause(); | |
249 return 1; | |
250 } | |
251 | |
252 //----- (0042092D) -------------------------------------------------------- | |
706 | 253 void Chest::DrawChestUI(signed 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); | |
945 | 285 pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5)); |
526 | 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); | |
945 | 295 item_texture = pIcons_LOD->GetTexture(item_texture_id); |
296 itemPixelWidth = item_texture->uTextureWidth; | |
297 itemPixelHeght = item_texture->uTextureHeight; | |
526 | 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; | |
600 | 305 itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth)/2); |
528 | 306 itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) + |
600 | 307 ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32- item_texture->uTextureHeight ) /2); |
526 | 308 pRenderer->DrawTextureTransparent( itemPixelPosX, itemPixelPosY, item_texture); |
528 | 309 sub_40F92A(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1); |
526 | 310 } |
311 } | |
945 | 312 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId)); |
421 | 313 } |
314 | |
315 | |
316 //----- (0041FE71) -------------------------------------------------------- | |
706 | 317 bool Chest::CanPlaceItemAt( signed int test_cell_position, int item_id, signed int uChestID ) |
526 | 318 { |
319 int v3; // eax@1 | |
320 unsigned int item_texture_id; // eax@1 | |
321 Texture *item_texture; // ecx@1 | |
322 signed int v6; // eax@1 | |
323 signed int v7; // edi@3 | |
324 signed int v8; // eax@3 | |
325 int texture_cell_width; // edi@3 | |
326 int texture_cell_height; // ebx@5 | |
327 int _row; // esi@9 | |
328 int _cell_rows; // edx@10 | |
329 int _column; // ecx@11 | |
330 char *v14; // eax@12 | |
331 int chest_cell_heght; // [sp+Ch] [bp-Ch]@1 | |
332 signed int v17; // [sp+10h] [bp-8h]@1 | |
333 signed int chest_cell_width; // [sp+14h] [bp-4h]@1 | |
334 | |
335 chest_cell_heght = pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
336 chest_cell_width = pChestWidthsByType[pChests[uChestID].uChestBitmapID]; | |
337 item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE); | |
945 | 338 item_texture = pIcons_LOD->GetTexture(item_texture_id); |
339 v6 = item_texture->uTextureWidth; | |
526 | 340 if ( v6 < 14 ) |
341 v6 = 14; | |
342 texture_cell_width = (v6 - 14 >> 5) + 1; | |
343 v8 = item_texture->uTextureHeight; | |
344 if ( v8 < 14 ) | |
345 v8 = 14; | |
346 texture_cell_height = ((v8 - 14) >> 5) + 1; | |
347 if ( !areWeLoadingTexture ) | |
348 { | |
349 item_texture->Release(); | |
1006 | 350 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 351 } |
352 if ( (texture_cell_width + test_cell_position % chest_cell_width <= chest_cell_width) && | |
353 (texture_cell_height + test_cell_position / chest_cell_width <= chest_cell_heght) ) | |
354 { //we not put over borders | |
355 _row = 0; | |
356 if ( texture_cell_height <= 0 ) | |
357 return true; | |
358 _cell_rows = 0; | |
359 while ( 1 ) | |
360 { | |
361 _column = 0; | |
362 if ( texture_cell_width > 0 ) | |
363 { | |
528 | 364 while ( pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]==0) |
526 | 365 { |
366 ++_column; | |
367 if ( _column >= texture_cell_width ) | |
368 break; | |
369 } | |
528 | 370 if (pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]!=0) |
371 return false; | |
526 | 372 } |
373 _cell_rows += chest_cell_width; | |
374 ++_row; | |
375 if ( _row >= texture_cell_height ) | |
376 return true; | |
377 } | |
378 | |
379 } | |
380 return false; | |
421 | 381 } |
382 // 506128: using guessed type int areWeLoadingTexture; | |
383 | |
384 //----- (0041FF64) -------------------------------------------------------- | |
706 | 385 int Chest::CountChestItems(signed int uChestID) |
421 | 386 { |
526 | 387 signed int item_count; // eax@1 |
388 int max_items; // edx@1 | |
389 item_count = 0; | |
390 max_items = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
391 if ( max_items <= 0 ) | |
421 | 392 { |
526 | 393 item_count = -1; |
421 | 394 } |
395 else | |
396 { | |
526 | 397 while ( pChests[uChestID].igChestItems[item_count].uItemID ) |
421 | 398 { |
526 | 399 ++item_count; |
400 if ( item_count >= max_items ) | |
401 { | |
402 item_count = -1; | |
403 break; | |
404 } | |
421 | 405 } |
406 } | |
526 | 407 return item_count; |
421 | 408 } |
409 | |
410 //----- (0041FFA2) -------------------------------------------------------- | |
706 | 411 int Chest::PutItemInChest(int position, ItemGen *put_item, signed int uChestID) |
421 | 412 { |
413 int v3; // eax@1 | |
414 ItemGen *v4; // edi@1 | |
415 int v5; // esi@1 | |
416 int result; // eax@11 | |
417 unsigned int v7; // eax@12 | |
418 int v8; // edx@12 | |
945 | 419 Texture *v9; // ecx@12 |
421 | 420 signed int v10; // eax@12 |
421 signed int v11; // edi@14 | |
422 unsigned int v12; // esi@14 | |
423 int v13; // edi@16 | |
424 void *v14; // edi@21 | |
425 int v15; // edi@21 | |
426 int i; // ecx@21 | |
427 ItemGen *Src; // [sp+Ch] [bp-18h]@1 | |
526 | 428 signed int item_in_chest_count; // [sp+10h] [bp-14h]@2 |
421 | 429 int v19; // [sp+14h] [bp-10h]@1 |
430 int v20; // [sp+18h] [bp-Ch]@19 | |
431 signed int v21; // [sp+1Ch] [bp-8h]@1 | |
432 signed int v22; // [sp+20h] [bp-4h]@3 | |
433 int v23; // [sp+20h] [bp-4h]@19 | |
434 | |
435 v21 = 0; | |
436 v3 = pChests[uChestID].uChestBitmapID; | |
526 | 437 v4 = put_item; |
421 | 438 v5 = pChestWidthsByType[v3] * pChestHeightsByType[v3]; |
526 | 439 Src = put_item; |
421 | 440 v19 = pChestWidthsByType[v3]; |
526 | 441 if ( position == -1 ) |
421 | 442 { |
526 | 443 item_in_chest_count = CountChestItems(uChestID); |
444 if ( item_in_chest_count == -1 ) | |
421 | 445 return 0; |
446 v22 = 0; | |
447 if ( v5 > 0 ) | |
448 { | |
526 | 449 while ( !Chest::CanPlaceItemAt(v22, v4->uItemID, pChestWindow->par1C) ) |
421 | 450 { |
451 ++v22; | |
452 if ( v22 >= v5 ) | |
453 goto LABEL_8; | |
454 } | |
455 v21 = v22; | |
456 } | |
457 LABEL_8: | |
458 if ( v22 == v5 ) | |
459 { | |
460 if ( uActiveCharacter ) | |
461 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0); | |
462 return 0; | |
463 } | |
464 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v4->uItemID].pIconName, TEXTURE_16BIT_PALETTE); | |
465 HIWORD(v8) = 0; | |
945 | 466 v9 = pIcons_LOD->GetTexture(v7); |
467 v10 = v9->uTextureWidth; | |
421 | 468 if ( v10 < 14 ) |
469 v10 = 14; | |
945 | 470 v11 = v9->uTextureHeight; |
421 | 471 v12 = ((v10 - 14) >> 5) + 1; |
472 if ( v11 < 14 ) | |
473 v11 = 14; | |
474 v13 = ((v11 - 14) >> 5) + 1; | |
475 if ( !areWeLoadingTexture ) | |
476 { | |
477 ((Texture *)v9)->Release(); | |
1006 | 478 pIcons_LOD->SyncLoadedFilesCount(); |
421 | 479 } |
480 if ( v13 > 0 ) | |
481 { | |
482 v23 = 0; | |
483 v20 = v13; | |
484 do | |
485 { | |
486 if ( (signed int)v12 > 0 ) | |
487 { | |
526 | 488 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23]; |
421 | 489 LOWORD(v8) = -1 - v21; |
490 v8 <<= 16; | |
491 LOWORD(v8) = -1 - v21; | |
492 memset32(v14, v8, v12 >> 1); | |
493 v15 = (int)((char *)v14 + 4 * (v12 >> 1)); | |
494 for ( i = v12 & 1; i; --i ) | |
495 { | |
496 *(short *)v15 = v8; | |
497 v15 += 2; | |
498 } | |
499 } | |
500 v23 += v19; | |
501 --v20; | |
502 } | |
503 while ( v20 ); | |
504 } | |
526 | 505 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1; |
506 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen)); | |
421 | 507 result = v21 + 1; |
508 } | |
509 else | |
510 { | |
511 result = 1; | |
512 } | |
513 return result; | |
514 } | |
515 // 506128: using guessed type int areWeLoadingTexture; | |
516 | |
517 //----- (0042013E) -------------------------------------------------------- | |
706 | 518 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, signed int uChestID ) |
526 | 519 { |
528 | 520 |
521 int uItemID; // edi@1 | |
522 int v6; // edx@4 | |
523 unsigned int v7; // eax@5 | |
524 Texture *v8; // ecx@5 | |
525 signed int v9; // eax@5 | |
526 signed int v10; // edi@7 | |
527 unsigned int texture_cell_width; // ebx@7 | |
528 int textute_cell_height; // edi@9 | |
529 int chest_cell_row_pos; // edx@12 | |
530 int chest_cell_width; // [sp+10h] [bp-Ch]@11 | |
421 | 531 |
528 | 532 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID; |
533 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]); | |
534 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges) | |
421 | 535 { |
528 | 536 v6 = rand() % 21 + 10; |
537 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6; | |
538 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6; | |
421 | 539 } |
528 | 540 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 541 v8 = pIcons_LOD->GetTexture(v7); |
542 v9 = v8->uTextureWidth; | |
528 | 543 if ( v9 < 14 ) |
544 v9 = 14; | |
545 v10 = v8->uTextureHeight; | |
546 texture_cell_width = ((v9 - 14) >> 5) + 1; | |
547 if ( v10 < 14 ) | |
548 v10 = 14; | |
549 textute_cell_height = ((v10 - 14) >> 5) + 1; | |
550 if ( !areWeLoadingTexture ) | |
551 { | |
552 v8->Release(); | |
1006 | 553 pIcons_LOD->SyncLoadedFilesCount(); |
528 | 554 } |
555 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID]; | |
556 chest_cell_row_pos = 0; | |
557 for(int i=0; i<textute_cell_height; ++i) | |
558 { | |
559 for (int j=0; j<texture_cell_width; ++j) | |
560 { | |
561 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1); | |
562 } | |
563 chest_cell_row_pos += chest_cell_width; | |
564 } | |
565 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1; | |
421 | 566 } |
567 // 506128: using guessed type int areWeLoadingTexture; | |
568 | |
569 //----- (00420284) -------------------------------------------------------- | |
706 | 570 void Chest::PlaceItems(signed int uChestID ) |
421 | 571 { |
526 | 572 int uChestArea; // edi@1 |
573 int random_chest_pos; // eax@2 | |
574 int test_position; // ebx@11 | |
575 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1 | |
576 int chest_item_id; // [sp+9Ch] [bp-10h]@10 | |
528 | 577 unsigned int items_counter; // [sp+A4h] [bp-8h]@8 |
526 | 578 |
579 pRenderer->ClearZBuffer(0, 479); | |
580 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID]; | |
581 memset(chest_cells_map, 0, 144); | |
582 //fill cell map at random positions | |
608 | 583 for ( items_counter = 0; items_counter < uChestArea; ++items_counter ) |
584 { | |
526 | 585 //get random position in chest |
586 do | |
587 random_chest_pos = (unsigned __int8)rand(); | |
588 while ( random_chest_pos >= uChestArea ); | |
589 //if this pos occupied move to next | |
590 while ( chest_cells_map[random_chest_pos] ) | |
608 | 591 { |
526 | 592 ++random_chest_pos; |
593 if ( random_chest_pos == uChestArea ) | |
594 random_chest_pos = 0; | |
608 | 595 } |
528 | 596 chest_cells_map[random_chest_pos] = items_counter; |
608 | 597 } |
528 | 598 items_counter = 0; |
526 | 599 |
528 | 600 for (items_counter = 0; items_counter<uChestArea; ++items_counter) |
526 | 601 { |
528 | 602 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID; |
526 | 603 if ( chest_item_id ) |
604 { | |
605 test_position = 0; | |
606 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) ) | |
607 { | |
608 ++test_position; | |
609 if ( test_position >= uChestArea ) | |
610 break; | |
611 } | |
612 if(test_position<uChestArea) | |
613 { | |
528 | 614 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID); |
592 | 615 if ( pChests[uChestID].uFlags & CHEST_OPENED) |
528 | 616 pChests[uChestID].igChestItems[items_counter].SetIdentified(); |
526 | 617 } |
618 } | |
619 } | |
528 | 620 pChests[uChestID].SetInitialized(true); |
421 | 621 } |
622 // 420284: using guessed type char Dst[144]; | |
623 | |
706 | 624 //----- (00448A17) -------------------------------------------------------- |
625 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle) | |
626 { | |
627 unsigned __int16 *pFlags; // eax@3 | |
628 | |
629 if ( uChestID >= 0 && uChestID <= 19 ) | |
630 { | |
631 pFlags = &pChests[uChestID].uFlags; | |
632 if ( bToggle ) | |
633 *pFlags |= uFlag; | |
634 else | |
635 *pFlags &= ~uFlag; | |
636 } | |
637 } | |
638 | |
0 | 639 //----- (00458B03) -------------------------------------------------------- |
640 void ChestList::ToFile() | |
641 { | |
642 ChestList *v1; // esi@1 | |
643 FILE *v2; // eax@1 | |
644 FILE *v3; // edi@1 | |
645 | |
646 v1 = this; | |
647 v2 = fopen("data\\dchest.bin", "wb"); | |
648 v3 = v2; | |
649 if ( !v2 ) | |
650 Abortf("Unable to save dchest.bin!"); | |
651 fwrite(v1, 4u, 1u, v2); | |
652 fwrite(v1->pChests, 0x24u, v1->uNumChests, v3); | |
653 fclose(v3); | |
654 } | |
655 | |
656 | |
657 //----- (00458B4F) -------------------------------------------------------- | |
658 void ChestList::FromFile(void *pSerialized) | |
659 { | |
660 uNumChests = *(int *)pSerialized; | |
661 pChests = (ChestDesc *)pAllocator->AllocNamedChunk(pChests, 36 * uNumChests, "Chest Descrip"); | |
662 memcpy(pChests, (char *)pSerialized + 4, 36 * uNumChests); | |
663 } | |
664 | |
665 | |
666 //----- (00458B9C) -------------------------------------------------------- | |
667 int ChestList::FromFileTxt(const char *Args) | |
668 { | |
669 ChestList *v2; // ebx@1 | |
670 __int32 v3; // edi@1 | |
671 FILE *v4; // eax@1 | |
672 unsigned int v5; // esi@3 | |
673 const void *v6; // ST18_4@9 | |
674 void *v7; // eax@9 | |
675 FILE *v8; // ST0C_4@11 | |
676 char *i; // eax@11 | |
677 char v10; // al@14 | |
678 const char *v11; // ST14_4@14 | |
679 char v12; // al@14 | |
680 const char *v13; // ST10_4@14 | |
681 char Buf; // [sp+8h] [bp-2F0h]@3 | |
682 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4 | |
683 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4 | |
684 FILE *File; // [sp+2F4h] [bp-4h]@1 | |
685 unsigned int Argsa; // [sp+300h] [bp+8h]@3 | |
686 | |
687 v2 = this; | |
688 pAllocator->FreeChunk(this->pChests); | |
689 v3 = 0; | |
690 v2->pChests = 0; | |
691 v2->uNumChests = 0; | |
692 v4 = fopen(Args, "r"); | |
693 File = v4; | |
694 if ( !v4 ) | |
695 Abortf("ChestDescriptionList::load - Unable to open file: %s."); | |
696 v5 = 0; | |
697 Argsa = 0; | |
698 if ( fgets(&Buf, 490, v4) ) | |
699 { | |
700 do | |
701 { | |
702 *strchr(&Buf, 10) = 0; | |
703 | 703 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 704 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 705 ++Argsa; |
706 } | |
707 while ( fgets(&Buf, 490, File) ); | |
708 v5 = Argsa; | |
709 v3 = 0; | |
710 } | |
711 v6 = v2->pChests; | |
712 v2->uNumChests = v5; | |
713 v7 = pAllocator->AllocNamedChunk(v6, 36 * v5, "Chest Descrip"); | |
714 v2->pChests = (ChestDesc *)v7; | |
715 if ( v7 == (void *)v3 ) | |
716 Abortf("ChestDescriptionList::load - Out of Memory!"); | |
717 memset(v7, v3, 36 * v2->uNumChests); | |
718 v8 = File; | |
719 v2->uNumChests = v3; | |
720 fseek(v8, v3, v3); | |
721 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
722 { | |
723 *strchr(&Buf, 10) = 0; | |
703 | 724 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17)); |
702 | 725 if ( v17.uPropCount && *v17.pProperties[0] != 47 ) |
0 | 726 { |
727 strcpy(v2->pChests[v2->uNumChests].pName, v17.pProperties[0]); | |
728 v10 = atoi(v17.pProperties[1]); | |
729 v11 = v17.pProperties[2]; | |
730 v2->pChests[v2->uNumChests].uWidth = v10; | |
731 v12 = atoi(v11); | |
732 v13 = v17.pProperties[3]; | |
733 v2->pChests[v2->uNumChests].uHeight = v12; | |
734 v2->pChests[v2->uNumChests++].uTextureID = atoi(v13); | |
735 } | |
736 } | |
737 fclose(File); | |
738 return 1; | |
739 } | |
526 | 740 |
741 //----- (00420B13) -------------------------------------------------------- | |
742 void __fastcall sub_420B13(int a1, int a2) | |
702 | 743 { |
526 | 744 void *v2; // eax@1 |
745 ItemGen *v3; // ebx@1 | |
746 unsigned int v4; // eax@1 | |
747 Texture *v5; // ecx@1 | |
748 signed int v6; // eax@1 | |
749 signed int v7; // edi@3 | |
750 signed int v8; // eax@3 | |
751 int v9; // edi@3 | |
752 int v10; // eax@5 | |
753 int v11; // esi@8 | |
754 unsigned int v12; // ecx@10 | |
755 void *v13; // edi@10 | |
756 unsigned __int8 v14; // cf@10 | |
757 int v15; // edi@10 | |
758 int i; // ecx@10 | |
759 int v17; // [sp+Ch] [bp-14h]@1 | |
760 int v18; // [sp+10h] [bp-10h]@3 | |
761 int v19; // [sp+14h] [bp-Ch]@1 | |
702 | 762 int v20; // [sp+18h] [bp-8h]@1 |
526 | 763 int v21; // [sp+1Ch] [bp-4h]@5 |
764 int v22; // [sp+1Ch] [bp-4h]@8 | |
765 | |
766 v19 = a2; | |
767 v2 = pChestWindow->ptr_1C; | |
702 | 768 v20 = (int)v2; |
526 | 769 v2 = (void *)(5324 * (int)v2); |
702 | 770 //v3 = (ItemGen *)((char *)v2 + 36 * a1 + (int)((char *)pChests + 4)); |
771 v3 = &pChests[v20].igChestItems[a1]; | |
772 //v17 = pChestWidthsByType[*(short *)((char *)v2 + (int)pChests)]; | |
773 v17 = pChestWidthsByType[pChests[v20].uChestBitmapID]; | |
526 | 774 v4 = pIcons_LOD->LoadTexture(pItemsTable->pItems[v3->uItemID].pIconName, TEXTURE_16BIT_PALETTE); |
945 | 775 v5 = pIcons_LOD->GetTexture(v4); |
776 v6 = v5->uTextureWidth; | |
526 | 777 if ( v6 < 14 ) |
778 v6 = 14; | |
779 v7 = v6 - 14; | |
780 v8 = v5->uTextureHeight; | |
781 v9 = (v7 >> 5) + 1; | |
782 v18 = v9; | |
783 if ( v8 < 14 ) | |
784 v8 = 14; | |
785 v10 = ((v8 - 14) >> 5) + 1; | |
786 v21 = v10; | |
787 if ( !areWeLoadingTexture ) | |
702 | 788 { |
526 | 789 v5->Release(); |
1006 | 790 pIcons_LOD->SyncLoadedFilesCount(); |
526 | 791 v10 = v21; |
702 | 792 } |
526 | 793 if ( v10 > 0 ) |
702 | 794 { |
526 | 795 v11 = 0; |
796 v22 = v10; | |
797 do | |
702 | 798 { |
526 | 799 if ( v9 > 0 ) |
702 | 800 { |
526 | 801 v12 = v9; |
702 | 802 //v13 = &pChests[0].pInventoryIndices[v19 + v11 + 2662 * (int)v20]; |
803 v13 = &pChests[v20].pInventoryIndices[v19 + v11]; | |
526 | 804 v14 = v12 & 1; |
805 v12 >>= 1; | |
806 memset(v13, 0, 4 * v12); | |
807 v15 = (int)((char *)v13 + 4 * v12); | |
808 for ( i = v14; i; --i ) | |
702 | 809 { |
526 | 810 *(short *)v15 = 0; |
811 v15 += 2; | |
702 | 812 } |
526 | 813 v9 = v18; |
702 | 814 } |
526 | 815 v11 += v17; |
816 --v22; | |
817 } | |
702 | 818 while ( v22 ); |
526 | 819 } |
702 | 820 v3->Reset(); |
821 } | |
526 | 822 // 506128: using guessed type int areWeLoadingTexture; |