comparison Engine/Graphics/Indoor.cpp @ 2496:5abd8fc8f1c6

for ITEM_ARTIFACT_LADYS_ESCORT
author Ritor1
date Thu, 18 Sep 2014 17:38:54 +0600
parents
children 68cdef6879a0
comparison
equal deleted inserted replaced
2495:7b076fe64f23 2496:5abd8fc8f1c6
1 #define _CRTDBG_MAP_ALLOC
2 #include <stdlib.h>
3 #include <crtdbg.h>
4
5 #define _CRT_SECURE_NO_WARNINGS
6 #include "ErrorHandling.h"
7 #include "ZlibWrapper.h"
8
9 #include "LightmapBuilder.h"
10 #include "DecalBuilder.h"
11 #include "stru9.h"
12 #include "stru10.h"
13 #include "stru367.h"
14
15 #include "Outdoor.h"
16 #include "SpriteObject.h"
17 #include "Events.h"
18 #include "Game.h"
19 #include "Viewport.h"
20 #include "Timer.h"
21 #include "Party.h"
22 #include "OurMath.h"
23 #include "LOD.h"
24 #include "DecorationList.h"
25 #include "ObjectList.h"
26 #include "Actor.h"
27 #include "Chest.h"
28 #include "GUIProgressBar.h"
29 #include "stru123.h"
30 #include "AudioPlayer.h"
31 #include "Log.h"
32 #include "TurnEngine.h"
33 #include "PaletteManager.h"
34 #include "Lights.h"
35
36 #include "MM7.h"
37 #include "Sprites.h"
38 #include "stru6.h"
39 #include "ParticleEngine.h"
40 #include "texts.h"
41 #include "GUIWindow.h"
42 #include "Engine/Graphics/Level/Decoration.h"
43 #include "Overlays.h"
44
45
46
47 IndoorLocation *pIndoor = new IndoorLocation;
48 BLVRenderParams *pBLVRenderParams = new BLVRenderParams;
49
50
51 LEVEL_TYPE uCurrentlyLoadedLevelType = LEVEL_null;
52
53 stru320 stru_F8AD28; // idb
54 stru337 stru_F81018;
55 BspRenderer_PortalViewportData stru_F8A590;
56 BspRenderer *pBspRenderer = new BspRenderer; // idb
57 stru141_actor_collision_object stru_721530;
58 std::array<stru352, 480> stru_F83B80;
59
60
61
62 unsigned __int16 pDoorSoundIDsByLocationID[78] =
63 {
64 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300,
65 300, 300, 300, 404, 302, 306, 308, 304, 308, 302, 400, 302, 300,
66 308, 308, 306, 308, 308, 304, 300, 404, 406, 300, 400, 406, 404,
67 306, 302, 408, 304, 300, 300, 300, 300, 300, 300, 300, 300, 300,
68 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 404, 304,
69 400, 300, 300, 404, 304, 400, 300, 300, 404, 304, 400, 300, 300
70 };
71
72
73 std::array<const char *, 11> _4E6BDC_loc_names=
74 {
75 "mdt12.blv",
76 "d18.blv",
77 "mdt14.blv",
78 "d37.blv",
79 "mdk01.blv",
80 "mdt01.blv",
81 "mdr01.blv",
82 "mdt10.blv",
83 "mdt09.blv",
84 "mdt15.blv",
85 "mdt11.blv"
86 };
87
88
89 //----- (0043F39E) --------------------------------------------------------
90 void __fastcall PrepareDrawLists_BLV()
91 {
92 int v5; // eax@4
93 unsigned int v7; // ebx@8
94 BLVSector *v8; // esi@8
95
96 pBLVRenderParams->Reset();
97 pMobileLightsStack->uNumLightsActive = 0;
98 //uNumMobileLightsApplied = 0;
99 uNumDecorationsDrawnThisFrame = 0;
100 uNumSpritesDrawnThisFrame = 0;
101 uNumBillboardsToDraw = 0;
102
103 if ( !byte_4D864C || !(pGame->uFlags & 0x1000) ) // lightspot around party
104 {
105 //v2 = pParty->flt_TorchlightColorB + 6.7553994e15;
106 //v11 = LOBYTE(v2);
107 v5 = 800;
108 if (pParty->TorchlightActive())
109 v5 *= pParty->pPartyBuffs[PARTY_BUFF_TORCHLIGHT].uPower;
110 //LOBYTE(v1) = _4E94D0_light_type;
111 //v4 = pParty->flt_TorchlightColorR + 6.7553994e15;
112 //v3 = pParty->flt_TorchlightColorG + 6.7553994e15;
113 pMobileLightsStack->AddLight(pGame->pIndoorCameraD3D->vPartyPos.x,
114 pGame->pIndoorCameraD3D->vPartyPos.y,
115 pGame->pIndoorCameraD3D->vPartyPos.z,
116 pBLVRenderParams->uPartySectorID,
117 v5,
118 floorf(pParty->flt_TorchlightColorR + 0.5f),
119 floorf(pParty->flt_TorchlightColorG + 0.5f),
120 floorf(pParty->flt_TorchlightColorB + 0.5f),
121 _4E94D0_light_type);
122 }
123 PrepareBspRenderList_BLV();
124 PrepareItemsRenderList_BLV();
125 PrepareActorRenderList_BLV();
126
127 for (uint i = 0; i < pBspRenderer->uNumVisibleNotEmptySectors; ++i)
128 {
129 v7 = pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[i];
130 v8 = &pIndoor->pSectors[pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[i]];
131
132 for (uint j = 0; j < v8->uNumDecorations; ++j)
133 PrepareDecorationsRenderList_BLV(v8->pDecorationIDs[j], v7);
134 }
135 FindBillboardsLightLevels_BLV();
136 pGame->PrepareBloodsplats();
137 }
138
139 //----- (004407D9) --------------------------------------------------------
140 void BLVRenderParams::Reset()
141 {
142 int v7; // eax@1
143
144 this->field_0_timer_ = pEventTimer->uTotalGameTimeElapsed;
145
146 pGame->pIndoorCameraD3D->debug_flags = 0;
147 if (viewparams->draw_sw_outlines)
148 pGame->pIndoorCameraD3D->debug_flags |= BLV_RENDER_DRAW_SW_OUTLINES;
149 if (viewparams->draw_d3d_outlines)
150 pGame->pIndoorCameraD3D->debug_flags |= BLV_RENDER_DRAW_D3D_OUTLINES;
151
152 //v2 = a2;
153 //this->field_0_timer_ = a2->field_0_timer;
154 //this->uFlags = a2->uFlags;
155 //this->vPartyPos.x = a2->vPosition.x;
156 //this->vPartyPos.y = a2->vPosition.y;
157 //this->vPartyPos.z = a2->vPosition.z;
158 //v4 = this->vPartyPos.z;
159 //v5 = this->vPartyPos.y;
160 //this->sPartyRotY = a2->sRotationY;
161 //v6 = this->vPartyPos.x;
162 //this->sPartyRotX = a2->sRotationX;
163 v7 = pIndoor->GetSector(pGame->pIndoorCameraD3D->vPartyPos.x,
164 pGame->pIndoorCameraD3D->vPartyPos.y,
165 pGame->pIndoorCameraD3D->vPartyPos.z);
166 this->uPartySectorID = v7;
167 if ( !v7 )
168 {
169 //__debugbreak(); // shouldnt happen, please provide savegame
170 /*v8 = this->vPartyPos.z;
171 this->vPartyPos.x = pParty->vPosition.x;
172 v9 = pParty->vPosition.y;
173 v10 = this->vPartyPos.x;
174 this->vPartyPos.y = pParty->vPosition.y;*/
175 this->uPartySectorID = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
176 }
177 //if ( pRenderer->pRenderD3D )
178 {
179 //this->sCosineY = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
180 //this->sSineY = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
181 //this->sCosineNegX = stru_5C6E00->Cos(-pGame->pIndoorCameraD3D->sRotationX);
182 //this->sSineNegX = stru_5C6E00->Sin(-pGame->pIndoorCameraD3D->sRotationX);
183 //this->fCosineY = cos((3.141592653589793 + 3.141592653589793) * (double)pGame->pIndoorCameraD3D->sRotationY * 0.00048828125);
184 //this->fSineY = sin((3.141592653589793 + 3.141592653589793) * (double)pGame->pIndoorCameraD3D->sRotationY * 0.00048828125);
185 //this->fCosineNegX = cos((3.141592653589793 + 3.141592653589793) * (double)-pGame->pIndoorCameraD3D->sRotationX * 0.00048828125);
186 //this->fSineNegX = sin((3.141592653589793 + 3.141592653589793) * (double)-pGame->pIndoorCameraD3D->sRotationX * 0.00048828125);
187 this->field_64 = pViewport->field_of_view;
188
189 this->uViewportX = pViewport->uScreen_TL_X;
190 this->uViewportY = pViewport->uScreen_TL_Y;
191 this->uViewportZ = pViewport->uScreen_BR_X;
192 this->uViewportW = pViewport->uScreen_BR_Y;
193
194 this->uViewportWidth = uViewportZ - uViewportX + 1;
195 this->uViewportHeight = uViewportW - uViewportY + 1;
196 this->uViewportCenterX = (uViewportZ + uViewportX) / 2;
197 this->uViewportCenterY = (uViewportY + uViewportW) / 2;
198 }
199 /*else
200 {
201 __debugbreak(); // no sw
202 this->sCosineY = stru_5C6E00->Cos(-this->sPartyRotY);
203 this->sSineY = stru_5C6E00->Sin(-this->sPartyRotY);
204 this->sCosineNegX = stru_5C6E00->Cos(-this->sPartyRotX);
205 this->sSineNegX = stru_5C6E00->Sin(-this->sPartyRotX);
206 v17 = cos((double)-this->sPartyRotY * 0.0030664064);
207 v18 = this->sPartyRotY;
208 this->fCosineY = v17;
209 v19 = sin((double)-v18 * 0.0030664064);
210 v20 = this->sPartyRotX;
211 this->fSineY = v19;
212 v21 = cos((double)-v20 * 0.0030664064);
213 v22 = this->sPartyRotX;
214 this->fCosineNegX = v21;
215 this->fSineNegX = sin((double)-v22 * 0.0030664064);
216 v23 = this->uViewportX;
217 this->field_64 = a2->field_3C;
218 v24 = this->uViewportZ;
219 this->field_70 = this->uViewportZ - v23 + 1;
220 v25 = this->uViewportW - this->uViewportY + 1;
221 this->uViewportHeight = v25;
222 v29 = v25;
223 v26 = this->field_64;
224 this->uViewportCenterX = (signed int)(v24 + v23) >> 1;
225 this->uViewportCenterY = this->uViewportW - ((unsigned __int64)(v26 * (signed __int64)v29) >> 16);
226 }*/
227 //v27 = (unsigned int)(signed __int64)((double)this->uViewportWidth * 0.5
228 // / tan((double)(v2->fov_deg >> 1) * 0.01745329)
229 // + 0.5) << 16;
230 extern float _calc_fov(int viewport_width, int angle_degree);
231 this->fov_rad_fixpoint = fixpoint_from_int(_calc_fov(uViewportWidth, 65), 0);
232 this->fov_rad_inv_fixpoint = 0x100000000i64 / this->fov_rad_fixpoint;
233 this->pRenderTarget = pRenderer->pTargetSurface;
234 this->uTargetWidth = window->GetWidth();
235 this->uTargetHeight = window->GetHeight();
236 this->pTargetZBuffer = pRenderer->pActiveZBuffer;
237 this->field_8C = 0;
238 this->field_84 = 0;
239 this->uNumFacesRenderedThisFrame = 0;
240 this->field_88 = 0;
241 pBLVRenderParams->field_90 = 64;
242 pBLVRenderParams->field_94 = 6;
243 }
244
245 //----- (00440B44) --------------------------------------------------------
246 void IndoorLocation::ExecDraw(bool bD3D)
247 {
248 if (bD3D)
249 {
250 pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
251 for (uint i = 0; i < pBspRenderer->num_faces; ++i)
252 {
253 if (pBspRenderer->nodes[pBspRenderer->faces[i].uNodeID].viewing_portal_id == -1)
254 IndoorLocation::ExecDraw_d3d(pBspRenderer->faces[i].uFaceID, nullptr, 4, nullptr);
255 else
256 IndoorLocation::ExecDraw_d3d(pBspRenderer->faces[i].uFaceID,
257 pBspRenderer->nodes[pBspRenderer->faces[i].uNodeID].std__vector_0007AC, 4,
258 pBspRenderer->nodes[pBspRenderer->faces[i].uNodeID].pPortalBounding);
259 }
260 }
261 else for (uint j = 0; j < pBspRenderer->num_faces; ++j )
262 {
263 __debugbreak(); // no SW
264 //pBLVRenderParams->field_7C = &pBspRenderer->nodes[pBspRenderer->faces[j].uNodeID].PortalScreenData;
265 //IndoorLocation::ExecDraw_sw(pBspRenderer->faces[j].uFaceID);
266 }
267 }
268
269
270 /*
271 //----- (00440BED) --------------------------------------------------------
272 void __fastcall sub_440BED(IndoorLocation_drawstru *_this)
273 {
274 unsigned __int16 *v1; // edi@7
275 BspRenderer_stru0 *v2; // esi@8
276 int v3; // ecx@9
277 unsigned int v4; // edx@9
278 short *v5; // eax@10
279 signed int v6; // [sp+8h] [bp-8h]@7
280 int v7; // [sp+Ch] [bp-4h]@8
281 short *v8;
282
283 PrepareDrawLists_BLV(_this);
284 if (pBLVRenderParams->uPartySectorID)
285 IndoorLocation::ExecDraw(pRenderer->pRenderD3D != 0);
286 pRenderer->DrawBillboardList_BLV();
287
288 if ( !pRenderer->pRenderD3D )
289 {
290 if (pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_D3D_OUTLINES)
291 pBspRenderer->DrawFaceOutlines();
292 if (pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_SW_OUTLINES)
293 {
294 v1 = pBLVRenderParams->pRenderTarget;
295 v7 = 0;
296 for(int i=0; i < pBspRenderer->num_nodes; i++)
297 {
298 BspRenderer_stru0 *pNode = &pBspRenderer->nodes[i];
299 v4 = pRenderer->uTargetSurfacePitch * pNode->PortalScreenData._viewport_space_y;
300 if ( pNode->PortalScreenData._viewport_space_y <= pNode->PortalScreenData._viewport_space_w )
301 {
302 //v5 = (char *)&pBspRenderer->nodes[0].field_C.array_3D8[pNode->field_C._viewport_space_y + v7];
303 v5 = &pNode->PortalScreenData.viewport_right_side[pNode->PortalScreenData._viewport_space_y];
304 v8 = &pNode->PortalScreenData.viewport_left_side[pNode->PortalScreenData._viewport_space_y];
305 do
306 {
307 v1[v4 + *v8] = 255;
308 ++pNode->PortalScreenData._viewport_space_y;
309 v1[v4 + *v5] = 255;
310 v4 += pRenderer->uTargetSurfacePitch;
311 ++v5;
312 ++v8;
313 }
314 while ( pNode->PortalScreenData._viewport_space_y <= pNode->PortalScreenData._viewport_space_w );
315 }
316 }
317 }
318 }
319 }
320 */
321
322 //----- (00441BD4) --------------------------------------------------------
323 void IndoorLocation::Draw()
324 {
325 //int v0; // eax@1
326 //IndoorLocation_drawstru _this; // [sp+0h] [bp-4Ch]@5
327 // int v2; // [sp+44h] [bp-8h]@5
328 // int v3; // [sp+48h] [bp-4h]@5
329
330 /*_this.uFlags = 0;
331 if (viewparams->draw_sw_outlines)
332 _this.uFlags |= BLV_RENDER_DRAW_SW_OUTLINES;
333 if (viewparams->draw_d3d_outlines)
334 _this.uFlags |= BLV_RENDER_DRAW_D3D_OUTLINES;
335
336 _this.uFlags |= BLV_RENDER_DRAW_SW_OUTLINES;
337 _this.uFlags |= BLV_RENDER_DRAW_D3D_OUTLINES;
338
339 _this.field_0_timer = pEventTimer->uTotalGameTimeElapsed;
340 //_this.fov_deg = 65;
341 //_this.vPosition.x = pParty->vPosition.x - fixpoint_mul(stru_5C6E00->Cos(pParty->sRotationY), pParty->y_rotation_granularity);
342 //_this.vPosition.y = pParty->vPosition.y - fixpoint_mul(stru_5C6E00->Sin(pParty->sRotationY), pParty->y_rotation_granularity);
343 //_this.vPosition.z = pParty->vPosition.z + pParty->sEyelevel;
344 //_this.sRotationX = pParty->sRotationX;
345 //_this.sRotationY = pParty->sRotationY;
346 _this.pRenderTarget = pRenderer->pTargetSurface;
347 _this.uViewportX = pViewport->uScreen_TL_X;
348 _this.uViewportY = pViewport->uScreen_TL_Y;
349 _this.uViewportZ = pViewport->uScreen_BR_X;
350 _this.uViewportW = pViewport->uScreen_BR_Y;
351 _this.field_3C = pViewport->field_30;
352
353 _this.uTargetWidth = 640;
354 _this.uTargetHeight = 480;
355 _this.pTargetZ = pRenderer->pActiveZBuffer;*/
356
357 //sub_440BED(&_this); -- inlined
358 //{
359 PrepareDrawLists_BLV();
360 if (pBLVRenderParams->uPartySectorID)
361 IndoorLocation::ExecDraw(true/*pRenderer->pRenderD3D != 0*/);
362 pRenderer->DrawBillboardList_BLV();
363 //}
364
365 pParty->uFlags &= ~2;
366 pGame->DrawParticles();
367 trail_particle_generator.UpdateParticles();
368 }
369
370 //----- (004C0EF2) --------------------------------------------------------
371 void BLVFace::FromODM(ODMFace *face)
372 {
373 this->pFacePlane_old.vNormal.x = face->pFacePlane.vNormal.x;
374 this->pFacePlane_old.vNormal.y = face->pFacePlane.vNormal.y;
375 this->pFacePlane_old.vNormal.z = face->pFacePlane.vNormal.z;
376 this->pFacePlane_old.dist = face->pFacePlane.dist;
377 this->pFacePlane.vNormal.x = (double)(face->pFacePlane.vNormal.x & 0xFFFF) * 0.000015259022
378 + (double)(face->pFacePlane.vNormal.x >> 16);
379 this->pFacePlane.vNormal.y = (double)(face->pFacePlane.vNormal.y & 0xFFFF) * 0.000015259022
380 + (double)(face->pFacePlane.vNormal.y >> 16);
381 this->pFacePlane.vNormal.z = (double)(face->pFacePlane.vNormal.z & 0xFFFF) * 0.000015259022
382 + (double)(face->pFacePlane.vNormal.z >> 16);
383 this->pFacePlane.dist = (double)(face->pFacePlane.dist & 0xFFFF) * 0.000015259022 + (double)(face->pFacePlane.dist >> 16);
384 this->uAttributes = face->uAttributes;
385 this->pBounding.x1 = face->pBoundingBox.x1;
386 this->pBounding.y1 = face->pBoundingBox.y1;
387 this->pBounding.z1 = face->pBoundingBox.z1;
388 this->pBounding.x2 = face->pBoundingBox.x2;
389 this->pBounding.y2 = face->pBoundingBox.y2;
390 this->pBounding.z2 = face->pBoundingBox.z2;
391 this->zCalc1 = face->zCalc1;
392 this->zCalc2 = face->zCalc2;
393 this->zCalc3 = face->zCalc3;
394 this->pXInterceptDisplacements = face->pXInterceptDisplacements;
395 this->pYInterceptDisplacements = face->pYInterceptDisplacements;
396 this->pZInterceptDisplacements = face->pZInterceptDisplacements;
397 this->uPolygonType = (PolygonType)face->uPolygonType;
398 this->uNumVertices = face->uNumVertices;
399 this->uBitmapID = face->uTextureID;
400 this->pVertexIDs = face->pVertexIDs;
401 }
402
403 //----- (004B0A25) --------------------------------------------------------
404 void IndoorLocation::ExecDraw_d3d(unsigned int uFaceID, IndoorCameraD3D_Vec4 *pVertices, unsigned int uNumVertices, RenderVertexSoft *pPortalBounding)
405 {
406 int v17; // ebx@25
407 IDirect3DTexture2 *v27; // eax@42
408 unsigned int uNumVerticesa; // [sp+24h] [bp-4h]@17
409 int a4a; // [sp+34h] [bp+Ch]@25
410
411 if (uFaceID >= pIndoor->uNumFaces)
412 return;
413
414 static RenderVertexSoft static_vertices_F7C228[64];
415 static RenderVertexSoft static_vertices_F7B628[64];
416 static stru154 stru_F7B60C; // idb
417
418 BLVFace* pFace = &pIndoor->pFaces[uFaceID];
419 if (pFace->uNumVertices < 3)
420 return;
421
422
423 if (pFace->Invisible())
424 return;
425
426 ++pBLVRenderParams->uNumFacesRenderedThisFrame;
427 pFace->uAttributes |= FACE_UNKNOW4;
428
429 if (!pFace->GetTexture())
430 return;
431
432 if (!pGame->pIndoorCameraD3D->IsCulled(pFace))
433 {
434 uNumVerticesa = pFace->uNumVertices;
435 for (uint i = 0; i < pFace->uNumVertices; ++i)
436 {
437 static_vertices_F7C228[i].vWorldPosition.x = pIndoor->pVertices[pFace->pVertexIDs[i]].x;
438 static_vertices_F7C228[i].vWorldPosition.y = pIndoor->pVertices[pFace->pVertexIDs[i]].y;
439 static_vertices_F7C228[i].vWorldPosition.z = pIndoor->pVertices[pFace->pVertexIDs[i]].z;
440 static_vertices_F7C228[i].u = (signed short)pFace->pVertexUIDs[i];
441 static_vertices_F7C228[i].v = (signed short)pFace->pVertexVIDs[i];
442 }
443
444 if (!pVertices ||
445 (pGame->pStru9Instance->_498377(pPortalBounding, 4, pVertices, static_vertices_F7C228, &uNumVerticesa), uNumVerticesa) )
446 {
447 if (pGame->pIndoorCameraD3D->CalcPortalShape(static_vertices_F7C228, &uNumVerticesa,
448 static_vertices_F7B628, pGame->pIndoorCameraD3D->std__vector_000034_prolly_frustrum, 4, false, 0) != 1 || uNumVerticesa )
449 {
450 a4a = SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel);
451 v17 = (248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel)) | (((248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel))
452 | ((248 - 8 * SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel)) << 8)) << 8);
453 sub_4B0E07(uFaceID);
454 pGame->pLightmapBuilder->ApplyLights_IndoorFace(uFaceID);
455 pDecalBuilder->ApplyBloodsplatDecals_IndoorFace(uFaceID);
456 pGame->pIndoorCameraD3D->ViewTransfrom_OffsetUV(static_vertices_F7B628, uNumVerticesa, array_507D30, &stru_F8AD28);
457 pGame->pIndoorCameraD3D->Project(array_507D30, uNumVerticesa, 0);
458 pGame->pLightmapBuilder->std__vector_000004_size = 0;
459 if (stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0)
460 {
461 stru_F7B60C.face_plane.vNormal.x = pFace->pFacePlane.vNormal.x;
462 stru_F7B60C.polygonType = pFace->uPolygonType;
463 stru_F7B60C.face_plane.vNormal.y = pFace->pFacePlane.vNormal.y;
464 stru_F7B60C.face_plane.vNormal.z = pFace->pFacePlane.vNormal.z;
465 stru_F7B60C.face_plane.dist = pFace->pFacePlane.dist;
466 }
467
468 if (stru_F8AD28.uNumLightsApplied > 0 && !pFace->Indoor_sky())
469 pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0);
470
471 if (pDecalBuilder->uNumDecals > 0)//отрисовка пятен крови
472 pDecalBuilder->ApplyDecals(a4a, 1, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0, pFace->uSectorID);
473
474 if (pFace->Fluid())
475 {
476 if (pFace->uBitmapID == pRenderer->hd_water_tile_id)
477 v27 = pBitmaps_LOD->pHardwareTextures[pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]];
478 else
479 {
480 //auto v24 = GetTickCount() / 4;
481 //auto v25 = v24 - stru_5C6E00->uIntegerHalfPi;
482 uint eightSeconds = GetTickCount() % 8000;
483 float angle = (eightSeconds / 8000.0f) * 2 * 3.1415f;
484
485 //animte lava back and forth
486 for (uint i = 0; i < uNumVerticesa; ++i)
487 //array_507D30[i].v += (double)(pBitmaps_LOD->pTextures[pFace->uBitmapID].uHeightMinus1 & (unsigned int)(stru_5C6E00->SinCos(v25) >> 8));
488 array_507D30[i].v += pBitmaps_LOD->pTextures[pFace->uBitmapID].uHeightMinus1 * cosf(angle);
489 v27 = pBitmaps_LOD->pHardwareTextures[pFace->uBitmapID];
490 }
491 }
492 else if (pFace->uAttributes & FACE_TEXTURE_FRAME)
493 v27 = pBitmaps_LOD->pHardwareTextures[pTextureFrameTable->GetFrameTexture(pFace->uBitmapID, pBLVRenderParams->field_0_timer_)];
494 else
495 {
496 v17 = 0xFF808080;
497 v27 = pBitmaps_LOD->pHardwareTextures[pFace->uBitmapID];
498 }
499
500 if (pFace->Indoor_sky())
501 pRenderer->DrawIndoorSky(uNumVerticesa, uFaceID);
502 else
503 pRenderer->DrawIndoorPolygon(uNumVerticesa, pFace, v27, pFace->GetTexture(), PID(OBJECT_BModel, uFaceID), v17, 0);
504 return;
505 }
506 }
507 }
508 }
509
510 //----- (004B0E07) --------------------------------------------------------
511 unsigned int __fastcall sub_4B0E07(unsigned int uFaceID)
512 {
513 unsigned int result; // eax@1
514
515 stru_F8AD28.pDeltaUV[0] = pIndoor->pFaceExtras[pIndoor->pFaces[uFaceID].uFaceExtraID].sTextureDeltaU;
516 stru_F8AD28.pDeltaUV[1] = pIndoor->pFaceExtras[pIndoor->pFaces[uFaceID].uFaceExtraID].sTextureDeltaV;
517 result = GetTickCount() >> 3;
518 if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_FLOW_DIAGONAL )
519 stru_F8AD28.pDeltaUV[1] -= result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uHeightMinus1;
520 else
521 {
522 if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_FLOW_VERTICAL )
523 stru_F8AD28.pDeltaUV[1] += result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uHeightMinus1;
524 }
525 if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_FLOW_HORIZONTAL )
526 stru_F8AD28.pDeltaUV[0] -= result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uWidthMinus1;
527 else
528 {
529 if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_DONT_CACHE_TEXTURE )
530 stru_F8AD28.pDeltaUV[0] += result & pBitmaps_LOD->GetTexture(pIndoor->pFaces[uFaceID].uBitmapID)->uWidthMinus1;
531 }
532 return result;
533 }
534
535 //----- (004B0EA8) --------------------------------------------------------
536 void BspRenderer::AddFaceToRenderList_d3d(unsigned int node_id, unsigned int uFaceID)
537 {
538 unsigned __int16 pTransitionSector; // ax@11
539 int v9; // edx@15
540 char v29; // al@48
541
542 nodes[num_nodes].viewing_portal_id = -1;
543 //v39 = &pIndoor->pFaces[uFaceID];
544
545 BLVFace* pFace = &pIndoor->pFaces[uFaceID];
546
547 if (!pFace->Portal())
548 {
549 if (num_faces < 1000)
550 {
551 faces[num_faces].uFaceID = uFaceID;
552 faces[num_faces++].uNodeID = node_id;
553 }
554 return;
555 }
556
557 if (nodes[node_id].uFaceID == uFaceID)
558 return;
559 if (!node_id &&
560 pGame->pIndoorCameraD3D->vPartyPos.x >= pFace->pBounding.x1 - 16 && // we are probably standing at the portal plane
561 pGame->pIndoorCameraD3D->vPartyPos.x <= pFace->pBounding.x2 + 16 &&
562 pGame->pIndoorCameraD3D->vPartyPos.y >= pFace->pBounding.y1 - 16 &&
563 pGame->pIndoorCameraD3D->vPartyPos.y <= pFace->pBounding.y2 + 16 &&
564 pGame->pIndoorCameraD3D->vPartyPos.z >= pFace->pBounding.z1 - 16 &&
565 pGame->pIndoorCameraD3D->vPartyPos.z <= pFace->pBounding.z2 + 16 )
566 {
567 if ( abs(pFace->pFacePlane_old.dist + pGame->pIndoorCameraD3D->vPartyPos.x * pFace->pFacePlane_old.vNormal.x
568 + pGame->pIndoorCameraD3D->vPartyPos.y * pFace->pFacePlane_old.vNormal.y
569 + pGame->pIndoorCameraD3D->vPartyPos.z * pFace->pFacePlane_old.vNormal.z) <= 589824 ) // we sure are standing at the portal plane
570 {
571 pTransitionSector = pFace->uSectorID;
572 if ( nodes[0].uSectorID == pTransitionSector ) // draw back sector
573 pTransitionSector = pFace->uBackSectorID;
574 nodes[num_nodes].uSectorID = pTransitionSector;
575 nodes[num_nodes].uFaceID = uFaceID;
576 nodes[num_nodes].uViewportX = pBLVRenderParams->uViewportX;
577 nodes[num_nodes].uViewportZ = pBLVRenderParams->uViewportZ;
578 nodes[num_nodes].uViewportY = pBLVRenderParams->uViewportY;
579 nodes[num_nodes].uViewportW = pBLVRenderParams->uViewportW;
580 nodes[num_nodes].PortalScreenData.GetViewportData(pBLVRenderParams->uViewportX, pBLVRenderParams->uViewportY,
581 pBLVRenderParams->uViewportZ, pBLVRenderParams->uViewportW);
582 AddBspNodeToRenderList(++num_nodes - 1);
583 return;
584 }
585 }
586
587 v9 = pFace->pFacePlane_old.vNormal.x * (pIndoor->pVertices[pFace->pVertexIDs[0]].x - pGame->pIndoorCameraD3D->vPartyPos.x)
588 + pFace->pFacePlane_old.vNormal.y * (pIndoor->pVertices[pFace->pVertexIDs[0]].y - pGame->pIndoorCameraD3D->vPartyPos.y)
589 + pFace->pFacePlane_old.vNormal.z * (pIndoor->pVertices[pFace->pVertexIDs[0]].z - pGame->pIndoorCameraD3D->vPartyPos.z);
590 if (nodes[node_id].uSectorID != pFace->uSectorID)
591 v9 = -v9;
592 if (v9 >= 0)
593 return;
594
595 int num_vertices = GetPortalScreenCoord(uFaceID);
596 if (num_vertices < 2)
597 return;
598
599 int face_min_screenspace_x = PortalFace._screen_space_x[0],
600 face_max_screenspace_x = PortalFace._screen_space_x[0];
601 int face_min_screenspace_y = PortalFace._screen_space_y[0],
602 face_max_screenspace_y = PortalFace._screen_space_y[0];
603 for (uint i = 1; i < num_vertices; ++i)
604 {
605 if (face_min_screenspace_x > PortalFace._screen_space_x[i])
606 face_min_screenspace_x = PortalFace._screen_space_x[i];
607 if (face_max_screenspace_x < PortalFace._screen_space_x[i])
608 face_max_screenspace_x = PortalFace._screen_space_x[i];
609
610 if (face_min_screenspace_y > PortalFace._screen_space_y[i])
611 face_min_screenspace_y = PortalFace._screen_space_y[i];
612 if (face_max_screenspace_y < PortalFace._screen_space_y[i])
613 face_max_screenspace_y = PortalFace._screen_space_y[i];
614 }
615 //_screen_space_x = 719, 568, 493
616 //savegame: qw , 0Bh and 0x1D4h
617 //problem here when standing near/on portal, condition is false because of face_min_screenspace_x > p->uViewportZ
618 if (face_max_screenspace_x >= nodes[node_id].uViewportX &&
619 face_min_screenspace_x <= nodes[node_id].uViewportZ &&
620 face_max_screenspace_y >= nodes[node_id].uViewportY &&
621 face_min_screenspace_y <= nodes[node_id].uViewportW &&
622 PortalFrustrum(num_vertices, &nodes[num_nodes].PortalScreenData, &nodes[node_id].PortalScreenData, uFaceID))
623 {
624 pTransitionSector = pFace->uSectorID;
625 if (nodes[node_id].uSectorID == pTransitionSector )
626 pTransitionSector = pFace->uBackSectorID;
627 nodes[num_nodes].uSectorID = pTransitionSector;
628 nodes[num_nodes].uFaceID = uFaceID;
629 nodes[num_nodes].uViewportX = pBLVRenderParams->uViewportX;
630 nodes[num_nodes].uViewportZ = pBLVRenderParams->uViewportZ;
631 nodes[num_nodes].uViewportY = pBLVRenderParams->uViewportY;
632 nodes[num_nodes].uViewportW = pBLVRenderParams->uViewportW;
633 v29 = false;
634 if (nodes[node_id].viewing_portal_id == -1)//for first portal
635 v29 = pGame->pStru10Instance->CalcPortalShape(pFace, nodes[num_nodes].std__vector_0007AC, nodes[num_nodes].pPortalBounding);
636 else//for next portals
637 {
638 static RenderVertexSoft static_subAddFaceToRenderList_d3d_stru_F7AA08[64];
639 static RenderVertexSoft static_subAddFaceToRenderList_d3d_stru_F79E08[64];
640
641 for (uint k = 0; k < pFace->uNumVertices; ++k)
642 {
643 static_subAddFaceToRenderList_d3d_stru_F7AA08[k].vWorldPosition.x = pIndoor->pVertices[pFace->pVertexIDs[k]].x;
644 static_subAddFaceToRenderList_d3d_stru_F7AA08[k].vWorldPosition.y = pIndoor->pVertices[pFace->pVertexIDs[k]].y;
645 static_subAddFaceToRenderList_d3d_stru_F7AA08[k].vWorldPosition.z = pIndoor->pVertices[pFace->pVertexIDs[k]].z;
646 }
647
648 unsigned int pNewNumVertices = pFace->uNumVertices;
649 pGame->pIndoorCameraD3D->CalcPortalShape(static_subAddFaceToRenderList_d3d_stru_F7AA08, &pNewNumVertices,
650 static_subAddFaceToRenderList_d3d_stru_F79E08, nodes[node_id].std__vector_0007AC, 4, 0, 0);
651
652 v29 = pGame->pStru10Instance->_49C5DA(pFace, static_subAddFaceToRenderList_d3d_stru_F79E08, &pNewNumVertices,
653 nodes[num_nodes].std__vector_0007AC, nodes[num_nodes].pPortalBounding);
654 }
655 if ( 1 )
656 {
657 assert(num_nodes < 150);
658
659 nodes[num_nodes].viewing_portal_id = uFaceID;
660 AddBspNodeToRenderList(++num_nodes - 1);
661 }
662 if (pGame->pIndoorCameraD3D->debug_flags & BLV_RENDER_DRAW_SW_OUTLINES)
663 pGame->pIndoorCameraD3D->PrepareAndDrawDebugOutline(pFace, 0x1E1EFF);
664 //pGame->pIndoorCameraD3D->DebugDrawPortal(pFace);
665 }
666 }
667
668 //----- (004AE5BA) --------------------------------------------------------
669 Texture *BLVFace::GetTexture()
670 {
671 unsigned int v1; // ecx@2
672
673 if ( uAttributes & FACE_TEXTURE_FRAME )
674 v1 = pTextureFrameTable->GetFrameTexture(this->uBitmapID, pBLVRenderParams->field_0_timer_);
675 else
676 v1 = uBitmapID;
677 return pBitmaps_LOD->GetTexture(v1);
678 }
679
680
681 //----- (00498B15) --------------------------------------------------------
682 void IndoorLocation::Release()
683 {
684 free(this->ptr_0002B4_doors_ddata);
685 this->ptr_0002B4_doors_ddata = NULL;
686
687 free(this->ptr_0002B0_sector_rdata);
688 this->ptr_0002B0_sector_rdata = NULL;
689
690 free(this->ptr_0002B8_sector_lrdata);
691 this->ptr_0002B8_sector_lrdata = NULL;
692
693 free(this->pLFaces);
694 this->pLFaces = NULL;
695
696 free(this->pSpawnPoints);
697 this->pSpawnPoints = NULL;
698
699 this->uNumSectors = 0;
700 this->uNumFaces = 0;
701 this->uNumVertices = 0;
702 this->uNumNodes = 0;
703 this->uNumDoors = 0;
704 this->uNumLights = 0;
705
706 free(this->pVertices);
707 this->pVertices = NULL;
708
709 free(this->pFaces);
710 this->pFaces = NULL;
711
712 free(this->pFaceExtras);
713 this->pFaceExtras = NULL;
714
715 free(this->pSectors);
716 this->pSectors = NULL;
717
718 free(this->pLights);
719 this->pLights = NULL;
720
721 free(this->pDoors);
722 this->pDoors = NULL;
723
724 free(this->pNodes);
725 this->pNodes = NULL;
726
727 free(this->pMapOutlines);
728 this->pMapOutlines = NULL;
729
730 this->bLoaded = 0;
731 }
732
733 //----- (00498C45) --------------------------------------------------------
734 bool IndoorLocation::Alloc()
735 {
736 pVertices = (Vec3_short_ *) malloc(15000 * sizeof(Vec3_short_));//0x15F90u
737 pFaces = (BLVFace *) malloc(10000 * sizeof(BLVFace));//0xEA600u
738 pFaceExtras = (BLVFaceExtra *) malloc(5000 * sizeof(BLVFaceExtra)); //0x2BF20u
739 pSectors = (BLVSector *) malloc(512 * sizeof(BLVSector));//0xE800u
740 pLights = (BLVLightMM7 *) malloc(400 * sizeof(BLVLightMM7));//0x1900u
741 pDoors = (BLVDoor *) malloc(200 * sizeof(BLVDoor));//0x3E80u
742 pNodes = (BSPNode *) malloc(5000 * sizeof(BSPNode));//0x9C40u
743 pMapOutlines =(BLVMapOutlines *)malloc(sizeof(BLVMapOutlines));//0x14824u
744 if (pVertices && pFaces && pFaceExtras && pSectors && pLights && pDoors && pNodes && pMapOutlines )
745 {
746 memset(pVertices, 0, 15000*sizeof(Vec3_short_));
747 memset(pFaces, 0, 10000*sizeof(BLVFace));
748 memset(pFaceExtras,0, 5000*sizeof(BLVFaceExtra));
749 memset(pSectors, 0, 512*sizeof(BLVSector));
750 memset(pLights, 0, 400*sizeof(BLVLightMM7));
751 memset(pDoors, 0, 200*sizeof(BLVDoor));
752 memset(pNodes, 0, 5000*sizeof(BSPNode));
753 memset(pMapOutlines,0, sizeof(BLVMapOutlines));
754 return true;
755 }
756 else
757 return false;
758 }
759
760 //----- (00444810) --------------------------------------------------------
761 unsigned int IndoorLocation::GetLocationIndex(const char *Str1)
762 {
763 for (uint i = 0; i < 11; ++i)
764 if (!_stricmp(Str1, _4E6BDC_loc_names[i]))
765 return i + 1;
766 return 0;
767 }
768
769 //----- (004488F7) --------------------------------------------------------
770 void IndoorLocation::ToggleLight(signed int sLightID, unsigned int bToggle)
771 {
772 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor && (sLightID <= pIndoor->uNumLights - 1) && (sLightID >= 0) )
773 {
774 if ( bToggle )
775 pIndoor->pLights[sLightID].uAtributes &= 0xFFFFFFF7;
776 else
777 pIndoor->pLights[sLightID].uAtributes |= 8;
778 pParty->uFlags |= 2;
779 }
780 }
781
782 //----- (00498E0A) --------------------------------------------------------
783 bool IndoorLocation::Load(char *pFilename, int a3, size_t _i, char *pDest)
784 {
785 /*unsigned int v5; // ebx@1
786 //IndoorLocation *v6; // esi@1
787 FILE *v7; // edi@3
788 bool result; // eax@3
789 char *v9; // ecx@4
790 void *v10; // eax@4
791 //unsigned __int8 v11; // zf@4
792 //unsigned __int8 v12; // sf@4
793 int v13; // eax@5
794 size_t v14; // ecx@6
795 char *v15; // ecx@6
796 int v16; // edx@6
797 size_t v17; // ecx@6
798 char *v18; // ecx@6
799 int v19; // edx@6
800 unsigned __int16 *v20; // edx@6
801 unsigned __int16 *v21; // edx@6
802 unsigned __int16 *v22; // edx@6
803 __int16 v23; // ax@10
804 char *v24; // ecx@10
805 __int16 v25; // cx@10
806 __int16 v26; // ax@11
807 char *v27; // ecx@11
808 unsigned __int16 v28; // ax@17
809 BLVFaceExtra *v29; // ecx@17
810 char *v30; // edx@17
811 int v31; // ecx@20
812 void *v32; // eax@25
813 int v33; // eax@26
814 unsigned __int16 *v34; // edx@27
815 size_t v35; // ecx@27
816 char *v36; // ecx@27
817 int v37; // edx@27
818 size_t v38; // ecx@27
819 char *v39; // ecx@27
820 int v40; // edx@27
821 unsigned __int16 *v41; // edx@27
822 unsigned __int16 *v42; // edx@27
823 unsigned __int16 *v43; // edx@27
824 unsigned __int16 *v44; // edx@27
825 size_t v45; // ecx@27
826 unsigned __int16 *v46; // edx@27
827 void *v47; // eax@28
828 BLVSector *v48; // eax@29
829 size_t v49; // ecx@29
830 unsigned __int16 *v50; // edx@31
831 void *v51; // eax@32
832 int v52; // eax@33
833 unsigned __int16 *v53; // edx@34
834 size_t v54; // ecx@34
835 char *v55; // ecx@34
836 int v56; // edx@34
837 size_t v57; // ecx@34
838 char *v58; // ecx@34
839 int v59; // edx@34
840 unsigned __int16 *v60; // edx@34
841 unsigned __int16 *v61; // edx@34
842 unsigned __int16 *v62; // edx@34
843 unsigned __int16 *v63; // edx@34
844 int v64; // ecx@34
845 BLVDoor *v65; // ecx@36
846 char *v66; // eax@37
847 int v67; // edx@38
848 int v68; // ecx@38
849 BLVFace *v69; // edx@38
850 int v70; // ecx@38
851 int v71; // edx@38
852 int v72; // eax@38
853 unsigned __int16 v73; // ax@42
854 char *v74; // ecx@42
855 SpriteObject *v75; // ecx@44
856 size_t v76; // eax@45
857 int j; // edx@46
858 unsigned __int16 v78; // ax@50
859 void *v79; // eax@52
860 void **v80; // esi@52
861 unsigned int v145; // eax@103
862 void *v146; // eax@103
863 unsigned int v147; // ecx@103
864 int v148; // ebx@103
865 unsigned int *v149; // ecx@103*/
866 //size_t v150; // eax@103
867 //unsigned int v151; // ebx@109
868 //unsigned int v152; // ecx@116
869 //unsigned int v153; // eax@117
870 //size_t v154; // ebx@126
871 //unsigned int v155; // ebx@134
872 //size_t v156; // eax@140
873 //signed int v157; // ebx@142
874 //int v158; // ebx@148
875 //BLVFace *v159; // eax@149
876 // BLVFaceExtra *v160; // ecx@149
877 //BLVFaceExtra *v161; // ecx@149
878 //signed int v162; // ebx@154
879 //unsigned int outz; // ebx@157
880 //unsigned int v164; // ebx@157
881 //unsigned int v165; // edx@158
882 //char *v166; // ecx@158
883 //unsigned __int16 v167; // ax@161
884 //__int16 v168; // ax@165
885 //unsigned int v169; // ebx@168
886 //void *v170; // eax@168
887 //size_t v171; // ebx@168
888 //int v172; // edx@168
889 //BLVDoor *v173; // ecx@169
890 //int k; // eax@169
891 //BLVDoor *v175; // ecx@172
892 //int v176; // edx@172
893 //BLVDoor *v177; // ecx@172
894 //int v178; // edx@172
895 //BLVDoor *v179; // ecx@172
896 //int v180; // edx@172
897 //BLVDoor *v181; // ecx@172
898 //int v182; // edx@172
899 //BLVDoor *v183; // ecx@172
900 //int v184; // edx@172
901 //BLVDoor *v185; // ecx@172
902 //int v186; // edx@172
903 //BLVDoor *v187; // ecx@172
904 //int v188; // edx@172
905 //unsigned __int16 *v189; // ebx@172
906 //char *v190; // edx@173
907 //BLVDoor *v191; // ecx@174
908 //BLVDoor *l; // eax@175
909 //signed int v193; // ebx@176
910 //int v194; // ecx@176
911 //BLVFaceExtra *v195; // ecx@176
912 //BLVFace *v196; // ebx@178
913 //std::string v197; // [sp-18h] [bp-680h]@66
914 //void *v198; // [sp-14h] [bp-67Ch]@72
915 //size_t v199; // [sp-10h] [bp-678h]@72
916 //size_t v200; // [sp-Ch] [bp-674h]@72
917 //const char *v201; // [sp-8h] [bp-670h]@4
918 //int v202; // [sp-4h] [bp-66Ch]@4
919 char v203[875]; // [sp+Ch] [bp-65Ch]@130
920 // char FileName[260]; // [sp+378h] [bp-2F0h]@1
921 //char DstBuf; // [sp+47Ch] [bp-1ECh]@4
922 // __int32 Offset; // [sp+480h] [bp-1E8h]@4
923 // __int32 v207; // [sp+48Ch] [bp-1DCh]@4
924 // __int32 v208; // [sp+498h] [bp-1D0h]@4
925 // __int32 v209; // [sp+4A4h] [bp-1C4h]@4
926 // __int32 v210; // [sp+4B0h] [bp-1B8h]@4
927 // __int32 v211; // [sp+4BCh] [bp-1ACh]@15
928 // __int32 v212; // [sp+4C8h] [bp-1A0h]@15
929 // __int32 v213; // [sp+4D4h] [bp-194h]@25
930 // __int32 v214; // [sp+4E0h] [bp-188h]@25
931 // __int32 v215; // [sp+4ECh] [bp-17Ch]@32
932 // __int32 v216; // [sp+4F8h] [bp-170h]@32
933 // __int32 v217; // [sp+504h] [bp-164h]@40
934 // __int32 v218; // [sp+510h] [bp-158h]@40
935 // __int32 v219; // [sp+51Ch] [bp-14Ch]@43
936 // __int32 v220; // [sp+528h] [bp-140h]@43
937 // __int32 v221; // [sp+534h] [bp-134h]@52
938 // __int32 v222; // [sp+540h] [bp-128h]@52
939 // __int32 v223; // [sp+54Ch] [bp-11Ch]@52
940 // __int32 v224; // [sp+558h] [bp-110h]@52
941 // __int32 v225; // [sp+564h] [bp-104h]@52
942 // __int32 v226; // [sp+570h] [bp-F8h]@52
943 // __int32 v227; // [sp+57Ch] [bp-ECh]@52
944 // __int32 v228; // [sp+588h] [bp-E0h]@52
945 // __int32 v229; // [sp+594h] [bp-D4h]@52
946 // __int32 v230; // [sp+5A0h] [bp-C8h]@52
947 // __int32 v231; // [sp+5ACh] [bp-BCh]@52
948 // __int32 v232; // [sp+5B8h] [bp-B0h]@52
949 // __int32 v233; // [sp+5C4h] [bp-A4h]@52
950 // __int32 v234; // [sp+5D0h] [bp-98h]@52
951 //char pName[40]; // [sp+5FCh] [bp-6Ch]@42
952 //size_t pSource; // [sp+624h] [bp-44h]@67
953 //char Dst[12]; // [sp+628h] [bp-40h]@9
954 //char *v238; // [sp+634h] [bp-34h]@38
955 ODMHeader header; // [sp+638h] [bp-30h]@61
956 //void *ptr; // [sp+648h] [bp-20h]@66
957 //size_t Count; // [sp+64Ch] [bp-1Ch]@109
958 //int uSourceLen; // [sp+653h] [bp-15h]@66
959 FILE *File; // [sp+658h] [bp-10h]@56
960 //BLVSector *v244; // [sp+65Ch] [bp-Ch]@72
961 //int v245; // [sp+660h] [bp-8h]@72
962 //BLVFace *Src; // [sp+664h] [bp-4h]@73
963 // signed int Argsa; // [sp+670h] [bp+8h]@4
964 // signed int Argsb; // [sp+670h] [bp+8h]@7
965 // signed int Argsc; // [sp+670h] [bp+8h]@15
966 // signed int Argsd; // [sp+670h] [bp+8h]@18
967 // int Argse; // [sp+670h] [bp+8h]@25
968 // int Argsf; // [sp+670h] [bp+8h]@28
969 // int Argsg; // [sp+670h] [bp+8h]@32
970 // int Argsh; // [sp+670h] [bp+8h]@35
971 // signed int Argsi; // [sp+670h] [bp+8h]@40
972 // signed int Argsj; // [sp+670h] [bp+8h]@45
973 //int Argsk; // [sp+670h] [bp+8h]@143
974 //void *Argsl; // [sp+670h] [bp+8h]@155
975 //signed int Argsm; // [sp+670h] [bp+8h]@161
976 //signed int Argsn; // [sp+670h] [bp+8h]@175
977
978 //v5 = 0;
979 //v6 = this;
980 _6807E0_num_decorations_with_sounds_6807B8 = 0;
981
982 #pragma region "loading from txt"
983 /*sprintf(FileName, "levels\\%s", pFilename);
984 if ( GetFileAttributesA(FileName) != -1 )
985 {
986 Release();
987 if ( Alloc() )
988 {
989 v7 = fopen(FileName, "rb");
990 result = 1;
991 if ( !v7 )
992 return result;
993 v9 = pDest;
994 bLoaded = 1;
995 v202 = (int)v7;
996 v201 = (const char *)1;
997 *(int *)v9 = 1;
998 fread(&DstBuf, 0x180u, (size_t)v201, (FILE *)v202);
999 fseek(v7, Offset, 0);
1000 fread(&blv, 0x88u, 1u, v7);
1001 fseek(v7, v207, 0);
1002 fread(&uNumVertices, 1u, 4u, v7);
1003 fseek(v7, v208, 0);
1004 fread(pVertices, 6u, uNumVertices, v7);
1005 fseek(v7, v209, 0);
1006 fread(&uNumFaces, 4u, 1u, v7);
1007 fseek(v7, v210, 0);
1008 fread(pFaces, 0x60u, uNumFaces, v7);
1009 v10 = malloc(ptr_2AC, blv.uFaces_fdata_Size, "L.FData");
1010 v202 = (int)v7;
1011 ptr_2AC = (unsigned __int16 *)v10;
1012 fread(v10, 1u, blv.uFaces_fdata_Size, (FILE *)v202);
1013 v11 = uNumFaces == 0;
1014 v12 = (uNumFaces & 0x80000000u) != 0;
1015 pDest = 0;
1016 Argsa = 0;
1017 if ( !(v12 | v11) )
1018 {
1019 v13 = 0;
1020 do
1021 {
1022 pFaces[v13].pVertexIDs = (unsigned __int16 *)&pDest[(unsigned int)ptr_2AC];
1023 v14 = (size_t)&pFaces[v13];
1024 i = v14;
1025 v15 = &pDest[2 * *(char *)(v14 + 93) + 2];
1026 v16 = (int)&v15[(unsigned int)ptr_2AC];
1027 pDest = v15;
1028 *(int *)(i + 52) = v16;
1029 v17 = (size_t)&pFaces[v13];
1030 i = v17;
1031 v18 = &pDest[2 * *(char *)(v17 + 93) + 2];
1032 v19 = (int)&v18[(unsigned int)ptr_2AC];
1033 pDest = v18;
1034 *(int *)(i + 56) = v19;
1035 i = (size_t)&pFaces[v13];
1036 v20 = ptr_2AC;
1037 pDest += 2 * *(char *)(i + 93) + 2;
1038 *(int *)(i + 60) = (int)(char *)v20 + (int)pDest;
1039 i = (size_t)&pFaces[v13];
1040 v21 = ptr_2AC;
1041 pDest += 2 * *(char *)(i + 93) + 2;
1042 *(int *)(i + 64) = (int)(char *)v21 + (int)pDest;
1043 i = (size_t)&pFaces[v13];
1044 ++v13;
1045 v22 = ptr_2AC;
1046 pDest += 2 * *(char *)(i + 93) + 2;
1047 ++Argsa;
1048 *(int *)(i + 68) = (int)(char *)v22 + (int)pDest;
1049 pDest += 2 * *((char *)&pFaces[v13] - 3) + 2;
1050 }
1051 while ( Argsa < (signed int)uNumFaces );
1052 }
1053 Argsb = 0;
1054 if ( (signed int)uNumFaces > 0 )
1055 {
1056 pDest = 0;
1057 do
1058 {
1059 fread(Dst, 1u, 0xAu, v7);
1060 if ( pDest[(unsigned int)pFaces + 45] & 0x40 )
1061 {
1062 v23 = pTextureFrameTable->FindTextureByName(Dst);
1063 v24 = pDest;
1064 *(short *)&pDest[(unsigned int)pFaces + 74] = v23;
1065 v25 = *(short *)&v24[(unsigned int)pFaces + 74];
1066 if ( v25 )
1067 {
1068 pTextureFrameTable->LoadAnimationSequenceAndPalettes(v25);
1069 }
1070 else
1071 {
1072 v26 = pBitmaps_LOD->LoadTexture(Dst);
1073 v27 = pDest;
1074 *(short *)&pDest[(unsigned int)pFaces + 74] = v26;
1075 v27[(unsigned int)pFaces + 45] &= 0xBFu;
1076 }
1077 }
1078 else
1079 {
1080 *(short *)&pDest[(unsigned int)pFaces + 74] = pBitmaps_LOD->LoadTexture(Dst);
1081 }
1082 ++Argsb;
1083 pDest += 96;
1084 }
1085 while ( Argsb < (signed int)uNumFaces );
1086 }
1087 fseek(v7, v211, 0);
1088 fread(&uNumFaceExtras, 4u, 1u, v7);
1089 fseek(v7, v212, 0);
1090 fread(pFaceExtras, 0x24u, uNumFaceExtras, v7);
1091 Argsc = 0;
1092 if ( (signed int)uNumFaceExtras > 0 )
1093 {
1094 pDest = 0;
1095 do
1096 {
1097 fread(Dst, 1u, 0xAu, v7);
1098 v28 = pBitmaps_LOD->LoadTexture(Dst);
1099 v29 = pFaceExtras;
1100 v30 = pDest;
1101 ++Argsc;
1102 pDest += 36;
1103 *(unsigned __int16 *)((char *)&v29->uAdditionalBitmapID + (int)v30) = v28;
1104 }
1105 while ( Argsc < (signed int)uNumFaceExtras );
1106 }
1107 Argsd = 0;
1108 if ( (signed int)uNumFaces > 0 )
1109 {
1110 pDest = 0;
1111 do
1112 {
1113 v31 = (int)&pFaceExtras[*(short *)&pDest[(unsigned int)pFaces + 72]];
1114 if ( *(short *)(v31 + 26) )
1115 {
1116 if ( ((BLVFaceExtra *)v31)->HasEventint() )
1117 pDest[(unsigned int)pFaces + 46] |= 0x10u;
1118 else
1119 pDest[(unsigned int)pFaces + 46] &= 0xEFu;
1120 }
1121 ++Argsd;
1122 pDest += 96;
1123 }
1124 while ( Argsd < (signed int)uNumFaces );
1125 }
1126 fseek(v7, v213, 0);
1127 fread(&uNumSectors, 4u, 1u, v7);
1128 fseek(v7, v214, 0);
1129 fread(pSectors, 0x74u, uNumSectors, v7);
1130 v32 = malloc(ptr_0002B0_sector_rdata, blv.uSector_rdata_Size, "L.RData");
1131 v202 = (int)v7;
1132 ptr_0002B0_sector_rdata = (unsigned __int16 *)v32;
1133 fread(v32, 1u, blv.uSector_rdata_Size, (FILE *)v202);
1134 v11 = uNumSectors == 0;
1135 v12 = uNumSectors < 0;
1136 pDest = 0;
1137 Argse = 0;
1138 if ( !(v12 | v11) )
1139 {
1140 v33 = 0;
1141 do
1142 {
1143 pSectors[v33].pFloors = (unsigned __int16 *)&pDest[(unsigned int)ptr_0002B0_sector_rdata];
1144 i = (size_t)&pSectors[v33];
1145 v34 = ptr_0002B0_sector_rdata;
1146 pDest += 2 * *(short *)(i + 4);
1147 *(int *)(i + 16) = (int)(char *)v34 + (int)pDest;
1148 v35 = (size_t)&pSectors[v33];
1149 i = v35;
1150 v36 = &pDest[2 * *(short *)(v35 + 12)];
1151 v37 = (int)&v36[(unsigned int)ptr_0002B0_sector_rdata];
1152 pDest = v36;
1153 *(int *)(i + 24) = v37;
1154 v38 = (size_t)&pSectors[v33];
1155 i = v38;
1156 v39 = &pDest[2 * *(short *)(v38 + 20)];
1157 v40 = (int)&v39[(unsigned int)ptr_0002B0_sector_rdata];
1158 pDest = v39;
1159 *(int *)(i + 32) = v40;
1160 i = (size_t)&pSectors[v33];
1161 v41 = ptr_0002B0_sector_rdata;
1162 pDest += 2 * *(short *)(i + 28);
1163 *(int *)(i + 40) = (int)(char *)v41 + (int)pDest;
1164 i = (size_t)&pSectors[v33];
1165 v42 = ptr_0002B0_sector_rdata;
1166 pDest += 2 * *(short *)(i + 36);
1167 *(int *)(i + 48) = (int)(char *)v42 + (int)pDest;
1168 i = (size_t)&pSectors[v33];
1169 v43 = ptr_0002B0_sector_rdata;
1170 pDest += 2 * *(short *)(i + 44);
1171 *(int *)(i + 64) = (int)(char *)v43 + (int)pDest;
1172 i = (size_t)&pSectors[v33];
1173 v44 = ptr_0002B0_sector_rdata;
1174 pDest += 2 * *(short *)(i + 60);
1175 *(int *)(i + 72) = (int)(char *)v44 + (int)pDest;
1176 v45 = (size_t)&pSectors[v33];
1177 ++v33;
1178 i = v45;
1179 v46 = ptr_0002B0_sector_rdata;
1180 pDest += 2 * *(short *)(v45 + 68);
1181 ++Argse;
1182 *(int *)(v45 + 80) = (int)(char *)v46 + (int)pDest;
1183 pDest += 2 * *((short *)&pSectors[v33] - 20);
1184 }
1185 while ( Argse < uNumSectors );
1186 }
1187 v47 = malloc(
1188 ptr_0002B8_sector_lrdata,
1189 blv.uSector_lrdata_Size,
1190 "L.RLData");
1191 v202 = (int)v7;
1192 ptr_0002B8_sector_lrdata = (unsigned __int16 *)v47;
1193 fread(v47, 1u, blv.uSector_lrdata_Size, (FILE *)v202);
1194 v11 = uNumSectors == 0;
1195 v12 = uNumSectors < 0;
1196 pDest = 0;
1197 Argsf = 0;
1198 if ( !(v12 | v11) )
1199 {
1200 v48 = pSectors;
1201 v49 = 0;
1202 for ( i = 0; ; v49 = i )
1203 {
1204 v50 = ptr_0002B8_sector_lrdata;
1205 i += 116;
1206 ++Argsf;
1207 *(BLVLightMM7 **)((char *)&v48->pLights + v49) = (BLVLightMM7 *)((char *)v50 + (int)pDest);
1208 v48 = pSectors;
1209 pDest += 2 * *(__int16 *)((char *)&v48->uNumLights + v49);
1210 if ( Argsf >= uNumSectors )
1211 break;
1212 }
1213 }
1214 fseek(v7, v215, 0);
1215 fread(&uNumDoors, 4u, 1u, v7);
1216 fseek(v7, v216, 0);
1217 fread(pDoors, 0x50u, 0xC8u, v7);
1218 v51 = malloc(ptr_0002B4_doors_ddata, blv.uDoors_ddata_Size, "L.DData");
1219 v202 = (int)v7;
1220 ptr_0002B4_doors_ddata = (unsigned __int16 *)v51;
1221 fread(v51, 1u, blv.uDoors_ddata_Size, (FILE *)v202);
1222 v11 = uNumDoors == 0;
1223 v12 = uNumDoors < 0;
1224 pDest = 0;
1225 Argsg = 0;
1226 if ( !(v12 | v11) )
1227 {
1228 v52 = 0;
1229 do
1230 {
1231 pDoors[v52].pVertexIDs = (unsigned __int16 *)&pDest[(unsigned int)ptr_0002B4_doors_ddata];
1232 i = (size_t)&pDoors[v52];
1233 v53 = ptr_0002B4_doors_ddata;
1234 pDest += 2 * *(short *)(i + 68);
1235 *(int *)(i + 40) = (int)(char *)v53 + (int)pDest;
1236 v54 = (size_t)&pDoors[v52];
1237 i = v54;
1238 v55 = &pDest[2 * *(short *)(v54 + 70)];
1239 v56 = (int)&v55[(unsigned int)ptr_0002B4_doors_ddata];
1240 pDest = v55;
1241 *(int *)(i + 44) = v56;
1242 v57 = (size_t)&pDoors[v52];
1243 i = v57;
1244 v58 = &pDest[2 * *(short *)(v57 + 72)];
1245 v59 = (int)&v58[(unsigned int)ptr_0002B4_doors_ddata];
1246 pDest = v58;
1247 *(int *)(i + 48) = v59;
1248 i = (size_t)&pDoors[v52];
1249 v60 = ptr_0002B4_doors_ddata;
1250 pDest += 2 * *(short *)(i + 70);
1251 *(int *)(i + 52) = (int)(char *)v60 + (int)pDest;
1252 i = (size_t)&pDoors[v52];
1253 v61 = ptr_0002B4_doors_ddata;
1254 pDest += 2 * *(short *)(i + 70);
1255 *(int *)(i + 56) = (int)(char *)v61 + (int)pDest;
1256 i = (size_t)&pDoors[v52];
1257 v62 = ptr_0002B4_doors_ddata;
1258 pDest += 2 * *(short *)(i + 74);
1259 *(int *)(i + 60) = (int)(char *)v62 + (int)pDest;
1260 i = (size_t)&pDoors[v52];
1261 v63 = ptr_0002B4_doors_ddata;
1262 pDest += 2 * *(short *)(i + 74);
1263 *(int *)(i + 64) = (int)(char *)v63 + (int)pDest;
1264 ++Argsg;
1265 v64 = pDoors[v52].uNumOffsets;
1266 ++v52;
1267 pDest += 2 * v64;
1268 }
1269 while ( Argsg < uNumDoors );
1270 }
1271 Argsh = 0;
1272 if ( uNumDoors > 0 )
1273 {
1274 v65 = pDoors;
1275 pDest = 0;
1276 do
1277 {
1278 i = 0;
1279 v66 = &pDest[(int)v65];
1280 if ( *(short *)&pDest[(int)v65 + 70] > 0 )
1281 {
1282 do
1283 {
1284 v67 = *((int *)v66 + 10);
1285 a3 = 2 * i;
1286 v68 = *(short *)(v67 + 2 * i);
1287 v69 = pFaces;
1288 ++i;
1289 v70 = (int)&pFaceExtras[v69[v68].uFaceExtraID];
1290 v71 = *((int *)v66 + 12);
1291 v72 = a3;
1292 v238 = (char *)v70;
1293 *(short *)(a3 + v71) = *(short *)(v70 + 20);
1294 *(__int16 *)(*(char **)((char *)&pDoors->pDeltaVs + (unsigned int)pDest) + v72) = *((short *)v238 + 11);
1295 v65 = pDoors;
1296 v66 = &pDest[(int)v65];
1297 }
1298 while ( (signed int)i < *(short *)&pDest[(int)v65 + 70] );
1299 }
1300 ++Argsh;
1301 pDest += 80;
1302 }
1303 while ( Argsh < uNumDoors );
1304 }
1305 fseek(v7, v217, 0);
1306 fread(&uNumLevelDecorations, 4u, 1u, v7);
1307 fseek(v7, v218, 0);
1308 fread(pLevelDecorations, 0x20u, uNumLevelDecorations, v7);
1309 Argsi = 0;
1310 if ( (signed int)uNumLevelDecorations > 0 )
1311 {
1312 pDest = (char *)pLevelDecorations;
1313 do
1314 {
1315 fread(pName, 1u, 0x20u, v7);
1316 v73 = pDecorationList->GetDecorIdByName(pName);
1317 v74 = pDest;
1318 ++Argsi;
1319 pDest += 32;
1320 *(short *)v74 = v73;
1321 }
1322 while ( Argsi < (signed int)uNumLevelDecorations );
1323 }
1324 fseek(v7, v219, 0);
1325 fread(&uNumSpriteObjects, 4u, 1u, v7);
1326 fseek(v7, v220, 0);
1327 fread(pSpriteObjects, 0x70u, uNumSpriteObjects, v7);
1328 if ( (signed int)uNumSpriteObjects > 0 )
1329 {
1330 v75 = pSpriteObjects;
1331 pDest = (char *)uNumSpriteObjects;
1332 do
1333 {
1334 Argsj = 0;
1335 v76 = 48 * v75->stru_24.uItemID;
1336 v11 = pObjectList->uNumObjects == 0;
1337 v12 = (pObjectList->uNumObjects & 0x80000000u) != 0;
1338 LOWORD(v76) = *(unsigned __int16 *)((char *)&pItemsTable->pItems[0].uSpriteID + v76);
1339 i = v76;
1340 v75->uItemType = v76;
1341 if ( v12 | v11 )
1342 {
1343 LABEL_50:
1344 v78 = 0;
1345 }
1346 else
1347 {
1348 for ( j = (int)&pObjectList->pObjects->uObjectID; (short)v76 != *(short *)j; j = a3 )
1349 {
1350 ++Argsj;
1351 a3 = j + 56;
1352 if ( Argsj >= (signed int)pObjectList->uNumObjects )
1353 goto LABEL_50;
1354 LOWORD(v76) = i;
1355 }
1356 v78 = Argsj;
1357 }
1358 v75->uObjectDescID = v78;
1359 ++v75;
1360 --pDest;
1361 }
1362 while ( pDest );
1363 }
1364 fseek(v7, v221, 0);
1365 fread(&uNumActors, 4u, 1u, v7);
1366 fseek(v7, v222, 0);
1367 fread(pActors, 0x344u, uNumActors, v7);
1368 fseek(v7, v228, 0);
1369 fread(&uNumChests, 4u, 1u, v7);
1370 fseek(v7, v229, 0);
1371 fread(pChests, 0x14CCu, uNumChests, v7);
1372 fseek(v7, v224, 0);
1373 fread(&uNumLights, 4u, 1u, v7);
1374 fseek(v7, v225, 0);
1375 fread(pLights, 0x10u, uNumLights, v7);
1376 fseek(v7, v226, 0);
1377 fread(&uNumNodes, 4u, 1u, v7);
1378 fseek(v7, v227, 0);
1379 fread(pNodes, 8u, uNumNodes, v7);
1380 fseek(v7, v230, 0);
1381 fread(&uNumSpawnPoints, 4u, 1u, v7);
1382 v79 = malloc(pSpawnPoints, 24 * uNumSpawnPoints, "Spawn");
1383 v202 = 0;
1384 pSpawnPoints = (SpawnPointMM7 *)v79;
1385 fseek(v7, v231, v202);
1386 fread(pSpawnPoints, 0x18u, uNumSpawnPoints, v7);
1387 fseek(v7, v232, 0);
1388 fread(&dlv, 0x28u, 1u, v7);
1389 fseek(v7, v233, 0);
1390 fread(&stru_5E4C90, 1u, 0xC8u, v7);
1391 fseek(v7, v234, 0);
1392 fread(&uLastVisitDay, 1u, 0x38u, v7);
1393 fseek(v7, v223, 0);
1394 v80 = (void **)&pMapOutlines;
1395 fread(*v80, 4u, 1u, v7);
1396 fread((char *)*v80 + 4, 0xCu, *(int *)*v80, v7);
1397 fclose(v7);
1398 goto LABEL_179;
1399 }
1400 return 4;
1401 }*/
1402 #pragma endregion
1403
1404 if (bLoaded)
1405 {
1406 Log::Warning(L"BLV is already loaded");
1407 return 3;
1408 }
1409
1410 if ( !pGames_LOD->DoesContainerExist(pFilename) )
1411 Error("Unable to find %s in Games.LOD", pFilename);
1412
1413 //v238 = pFilename - 4;
1414 //v81 = strlen(pFilename);
1415 strcpy(this->pFilename, pFilename);
1416 strcpy(&pFilename[strlen(pFilename) - 4], ".blv");
1417 File = pGames_LOD->FindContainer(pFilename, 1);
1418 //File = v82;
1419
1420 Release();
1421 if ( !Alloc() )
1422 return 4;
1423
1424 header.uVersion = 91969;
1425 header.pMagic[0] = 'm';
1426 header.pMagic[1] = 'v';
1427 header.pMagic[2] = 'i';
1428 header.pMagic[3] = 'i';
1429 header.uCompressedSize = 0;
1430 header.uDecompressedSize = 0;
1431 fread(&header, sizeof(ODMHeader), 1, File);
1432 if (header.uVersion != 91969 ||
1433 header.pMagic[0] != 'm' ||
1434 header.pMagic[1] != 'v' ||
1435 header.pMagic[2] != 'i' ||
1436 header.pMagic[3] != 'i' )
1437 {
1438 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:792", 0);
1439 }
1440 //v83 = header.uCompressedSize;
1441 //pSource = header.uDecompressedSize;
1442 //v84 = malloc(header.uDecompressedSize);
1443 //v85 = v84;
1444 //ptr = v84;
1445 void* pRawBLV = malloc(header.uDecompressedSize);
1446 memset(pRawBLV, 0, header.uDecompressedSize);
1447
1448 if (header.uCompressedSize == header.uDecompressedSize)
1449 fread(pRawBLV, header.uDecompressedSize, 1, File);
1450 else if (header.uCompressedSize < header.uDecompressedSize)
1451 {
1452 void* pTmpMem = malloc(header.uCompressedSize);
1453 {
1454 fread(pTmpMem, header.uCompressedSize, 1, File);
1455
1456 uint uDecompressedSize = header.uDecompressedSize;
1457 zlib::MemUnzip(pRawBLV, &uDecompressedSize, pTmpMem, header.uCompressedSize);
1458
1459 if (uDecompressedSize != header.uDecompressedSize)
1460 Log::Warning(L"uDecompressedSize != header.uDecompressedSize in BLV");
1461 }
1462 free(pTmpMem);
1463 }
1464 else
1465 {
1466 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:803", 0);
1467 return 0;
1468 }
1469
1470 bLoaded = true;
1471
1472 char* pData = (char *)pRawBLV;
1473
1474 pGameLoadingUI_ProgressBar->Progress();
1475
1476 memcpy(&blv, pData, 136);
1477 memcpy(&uNumVertices, pData += 136, 4);
1478 memcpy(pVertices, pData += 4, uNumVertices * sizeof(Vec3_short_));
1479
1480 pGameLoadingUI_ProgressBar->Progress();
1481
1482 memcpy(&uNumFaces, pData += uNumVertices * sizeof(Vec3_short_), 4);
1483
1484 pGameLoadingUI_ProgressBar->Progress();
1485
1486 memcpy(pFaces, pData += 4, uNumFaces * sizeof (BLVFace));
1487 pLFaces = (unsigned __int16 *)malloc(blv.uFaces_fdata_Size);
1488
1489 memcpy(pLFaces, pData += uNumFaces * sizeof (BLVFace), blv.uFaces_fdata_Size);
1490
1491 for (uint i = 0, j = 0; i < uNumFaces; ++i)
1492 {
1493 BLVFace* pFace = &pFaces[i];
1494
1495 pFace->pVertexIDs = &pLFaces[j];
1496
1497 j += pFace->uNumVertices + 1;
1498 pFace->pXInterceptDisplacements = (short *)(&pLFaces[j]);
1499
1500 j += pFace->uNumVertices + 1;
1501 pFace->pYInterceptDisplacements = (short *)(&pLFaces[j]);
1502
1503 j += pFace->uNumVertices + 1;
1504 pFace->pZInterceptDisplacements = (short *)(&pLFaces[j]);
1505
1506 j += pFace->uNumVertices + 1;
1507 pFace->pVertexUIDs = (__int16 *)(&pLFaces[j]);
1508
1509 j += pFace->uNumVertices + 1;
1510 pFace->pVertexVIDs = (__int16 *)(&pLFaces[j]);
1511
1512 j += pFace->uNumVertices + 1;
1513 /*v93 = &pFaces[v92];
1514 Src = v93;
1515 v94 = (BLVSector *)((char *)v244 + 2 * v93->uNumVertices + 2);
1516 v95 = (unsigned __int16 *)((char *)v94 + (unsigned int)ptr_2AC);
1517 v244 = v94;
1518 Src->pXInterceptDisplacements = v95;
1519 v96 = (int)&pFaces[v92];
1520 Src = (BLVFace *)v96;
1521 v97 = (BLVSector *)((char *)v244 + 2 * *(char *)(v96 + 93) + 2);
1522 v98 = (unsigned __int16 *)((char *)v97 + (unsigned int)ptr_2AC);
1523 v244 = v97;
1524 Src->pYInterceptDisplacements = v98;
1525 Src = &pFaces[v92];
1526 v99 = ptr_2AC;
1527 v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
1528 Src->pZInterceptDisplacements = (unsigned __int16 *)((char *)v99 + (int)v244);
1529 Src = &pFaces[v92];
1530 v100 = ptr_2AC;
1531 v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
1532 Src->pVertexUIDs = (unsigned __int16 *)((char *)v100 + (int)v244);
1533 Src = &pFaces[v92];
1534 ++v92;
1535 v101 = ptr_2AC;
1536 v244 = (BLVSector *)((char *)v244 + 2 * Src->uNumVertices + 2);
1537 ++v245;
1538 Src->pVertexVIDs = (unsigned __int16 *)((char *)v101 + (int)v244);
1539 v244 = (BLVSector *)((char *)v244 + 2 * *((char *)&pFaces[v92] - 3) + 2);*/
1540 }
1541
1542 pGameLoadingUI_ProgressBar->Progress();
1543
1544 pData += blv.uFaces_fdata_Size;
1545
1546 for (uint i = 0; i < uNumFaces; ++i)
1547 {
1548 BLVFace* pFace = &pFaces[i];
1549
1550 char pTexName[16];
1551 strncpy(pTexName, pData, 10);
1552 pData += 10;
1553
1554 if (pFace->uAttributes & FACE_TEXTURE_FRAME)
1555 {
1556 pFace->uBitmapID = pTextureFrameTable->FindTextureByName(pTexName);
1557 if (pFace->uBitmapID)
1558 pTextureFrameTable->LoadAnimationSequenceAndPalettes(pFace->uBitmapID);
1559 else
1560 {
1561 pFace->uBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
1562 pFace->uAttributes &= ~FACE_TEXTURE_FRAME;
1563 }
1564 }
1565 else
1566 pFace->uBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
1567 }
1568
1569 pGameLoadingUI_ProgressBar->Progress();
1570
1571 memcpy(&uNumFaceExtras, pData, 4);
1572 memcpy(pFaceExtras, pData += 4, uNumFaceExtras * sizeof(BLVFaceExtra));
1573 pData += uNumFaceExtras * sizeof(BLVFaceExtra);
1574
1575 pGameLoadingUI_ProgressBar->Progress();
1576
1577 //v108 = (char *)v107 + 36 * uNumFaceExtras;
1578 //v245 = 0;
1579 //*(int *)((char *)&uSourceLen + 1) = 0;
1580 for (uint i = 0; i < uNumFaceExtras; ++i)
1581 {
1582 char pTexName[32];
1583 strncpy(pTexName, pData, 10);
1584 pData += 10;
1585
1586 if (!strcmp(pTexName, ""))
1587 pFaceExtras[i].uAdditionalBitmapID = -1;
1588 else
1589 pFaceExtras[i].uAdditionalBitmapID = pBitmaps_LOD->LoadTexture(pTexName);
1590 }
1591
1592
1593 for (uint i = 0; i < uNumFaces; ++i)
1594 {
1595 BLVFace* pFace = &pFaces[i];
1596 BLVFaceExtra* pFaceExtra = &pFaceExtras[pFace->uFaceExtraID];
1597
1598 if (pFaceExtra->uEventID)
1599 {
1600 if (pFaceExtra->HasEventint())
1601 pFace->uAttributes |= FACE_HAS_EVENT;
1602 else
1603 pFace->uAttributes &= ~FACE_HAS_EVENT;
1604 }
1605 }
1606
1607 pGameLoadingUI_ProgressBar->Progress();
1608
1609 memcpy(&uNumSectors, pData, 4);
1610 memcpy(pSectors, pData + 4, uNumSectors * sizeof(BLVSector));
1611 pData += 4 + uNumSectors * sizeof(BLVSector);
1612
1613 pGameLoadingUI_ProgressBar->Progress();
1614
1615 ptr_0002B0_sector_rdata = (unsigned short *)malloc(blv.uSector_rdata_Size);//, "L.RData");
1616 memcpy(ptr_0002B0_sector_rdata, pData, blv.uSector_rdata_Size);
1617 pData += blv.uSector_rdata_Size;
1618
1619 for (uint i = 0, j = 0; i < uNumSectors; ++i)
1620 {
1621 BLVSector* pSector = &pSectors[i];
1622
1623 pSector->pFloors = &ptr_0002B0_sector_rdata[j];
1624 j += pSector->uNumFloors;
1625
1626 pSector->pWalls = &ptr_0002B0_sector_rdata[j];
1627 j += pSector->uNumWalls;
1628
1629 pSector->pCeilings = &ptr_0002B0_sector_rdata[j];
1630 j += pSector->uNumCeilings;
1631
1632 pSector->pFluids = &ptr_0002B0_sector_rdata[j];
1633 j += pSector->uNumFluids;
1634
1635 pSector->pPortals = &ptr_0002B0_sector_rdata[j];
1636 j += pSector->uNumPortals;
1637
1638 pSector->pFaceIDs = &ptr_0002B0_sector_rdata[j];
1639 j += pSector->uNumFaces;
1640
1641 pSector->pCogs = &ptr_0002B0_sector_rdata[j];
1642 j += pSector->uNumCogs;
1643
1644 pSector->pDecorationIDs = &ptr_0002B0_sector_rdata[j];
1645 j += pSector->uNumDecorations;
1646
1647 pSector->pMarkers = &ptr_0002B0_sector_rdata[j];
1648 j += pSector->uNumMarkers;
1649
1650
1651 //do
1652 //{
1653 /*pSectors[v118].pFloors = (unsigned __int16 *)((char *)Src + (unsigned int)ptr_0002B0_sector_rdata);
1654 v244 = &pSectors[v118];
1655 v119 = ptr_0002B0_sector_rdata;
1656 Src = (BLVFace *)((char *)Src + 2 * v244->field_4);
1657 v244->pWalls = (unsigned __int16 *)((char *)v119 + (int)Src);
1658 v120 = (int)&pSectors[v118];
1659 v244 = (BLVSector *)v120;
1660 v121 = (BLVFace *)((char *)Src + 2 * *(short *)(v120 + 12));
1661 v122 = (unsigned __int16 *)((char *)v121 + (unsigned int)ptr_0002B0_sector_rdata);
1662 Src = v121;
1663 v244->pCeilings = v122;
1664 v123 = (int)&pSectors[v118];
1665 v244 = (BLVSector *)v123;
1666 v124 = (BLVFace *)((char *)Src + 2 * *(short *)(v123 + 20));
1667 v125 = (unsigned __int16 *)((char *)v124 + (unsigned int)ptr_0002B0_sector_rdata);
1668 Src = v124;
1669 v244->pFluids = v125;
1670 v244 = &pSectors[v118];
1671 v126 = ptr_0002B0_sector_rdata;
1672 Src = (BLVFace *)((char *)Src + 2 * v244->field_1C);
1673 v244->pPortals = (unsigned __int16 *)((char *)v126 + (int)Src);
1674 v244 = &pSectors[v118];
1675 v127 = ptr_0002B0_sector_rdata;
1676 Src = (BLVFace *)((char *)Src + 2 * v244->uNumPortals);
1677 v244->pFaceIDs = (unsigned __int16 *)((char *)v127 + (int)Src);
1678 v244 = &pSectors[v118];
1679 v128 = ptr_0002B0_sector_rdata;
1680 Src = (BLVFace *)((char *)Src + 2 * v244->field_2C);
1681 v244->pCogs = (unsigned __int16 *)((char *)v128 + (int)Src);
1682 v244 = &pSectors[v118];
1683 v129 = ptr_0002B0_sector_rdata;
1684 Src = (BLVFace *)((char *)Src + 2 * v244->field_3C);
1685 v244->pDecorationIDs = (unsigned __int16 *)((char *)v129 + (int)Src);
1686 v130 = (int)&pSectors[v118];
1687 ++v118;
1688 v244 = (BLVSector *)v130;
1689 v131 = ptr_0002B0_sector_rdata;
1690 Src = (BLVFace *)((char *)Src + 2 * *(short *)(v130 + 68));
1691 ++v245;
1692 *(int *)(v130 + 80) = (int)(char *)v131 + (int)Src;
1693 Src = (BLVFace *)((char *)Src + 2 * *((short *)&pSectors[v118] - 20));*/
1694 //}
1695 //while ( v245 < uNumSectors );
1696 }
1697
1698 ptr_0002B8_sector_lrdata = (unsigned __int16 *)malloc(blv.uSector_lrdata_Size);//, "L.RLData");
1699 memcpy(ptr_0002B8_sector_lrdata, pData, blv.uSector_lrdata_Size);
1700 pData += blv.uSector_lrdata_Size;
1701
1702 pGameLoadingUI_ProgressBar->Progress();
1703
1704 for (uint i = 0, j = 0; i < uNumSectors; ++i)
1705 {
1706 pSectors[i].pLights = ptr_0002B8_sector_lrdata + j;
1707 j += pSectors[i].uNumLights;
1708 }
1709
1710 pGameLoadingUI_ProgressBar->Progress();
1711
1712 memcpy(&uNumDoors, pData, 4);
1713 pData += 4;
1714
1715 pGameLoadingUI_ProgressBar->Progress();
1716 pGameLoadingUI_ProgressBar->Progress();
1717
1718 memcpy(&uNumLevelDecorations, pData, 4);
1719 memcpy(pLevelDecorations.data(), pData + 4, uNumLevelDecorations * sizeof(LevelDecoration));
1720 pData += 4 + uNumLevelDecorations * sizeof(LevelDecoration);
1721
1722 for (uint i = 0; i < uNumLevelDecorations; ++i)
1723 {
1724 pLevelDecorations[i].uDecorationDescID = pDecorationList->GetDecorIdByName(pData);
1725
1726 pData += 32;
1727 }
1728
1729 pGameLoadingUI_ProgressBar->Progress();
1730
1731 memcpy(&uNumLights, pData, 4);
1732 memcpy(pLights, pData + 4, uNumLights * sizeof(BLVLightMM7));
1733 pData += 4 + uNumLights * sizeof(BLVLightMM7);
1734
1735 pGameLoadingUI_ProgressBar->Progress();
1736 pGameLoadingUI_ProgressBar->Progress();
1737
1738 memcpy(&uNumNodes, pData, 4);
1739 memcpy(pNodes, pData + 4, uNumNodes * sizeof(BSPNode));
1740 pData += 4 + uNumNodes * sizeof(BSPNode);
1741
1742 pGameLoadingUI_ProgressBar->Progress();
1743 pGameLoadingUI_ProgressBar->Progress();
1744
1745 memcpy(&uNumSpawnPoints, pData, 4);
1746 pSpawnPoints = (SpawnPointMM7 *)malloc(uNumSpawnPoints * sizeof(SpawnPointMM7));
1747 memcpy(pSpawnPoints, pData + 4, uNumSpawnPoints * sizeof(SpawnPointMM7));
1748 pData += 4 + uNumSpawnPoints * sizeof(SpawnPointMM7);
1749
1750 pGameLoadingUI_ProgressBar->Progress();
1751 pGameLoadingUI_ProgressBar->Progress();
1752
1753 //v201 = (const char *)v148;
1754 //v200 = (size_t)pMapOutlines;
1755 memcpy(&pMapOutlines->uNumOutlines, pData, 4);
1756 memcpy(pMapOutlines->pOutlines, pData + 4, pMapOutlines->uNumOutlines * sizeof(BLVMapOutline));
1757 //v149 = pMapOutlines;
1758 //v199 = 12 * *v149;
1759 //memcpy(v149 + 1, (const void *)(v148 + 4), v199);
1760 free(pRawBLV);
1761 pRawBLV = nullptr;
1762
1763 void *pRawDLV = nullptr;
1764 strcpy(&pFilename[strlen(pFilename) - 4], ".dlv");
1765 File = pNew_LOD->FindContainer(pFilename, 1);//error on D28.dlv
1766 fread(&header, 0x10, 1, File);//(FILE *)v245);
1767 bool _v244 = false;
1768 if (header.uVersion != 91969 ||
1769 header.pMagic[0] != 'm' ||
1770 header.pMagic[1] != 'v' ||
1771 header.pMagic[2] != 'i' ||
1772 header.pMagic[3] != 'i' )
1773 {
1774 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1090", 0);
1775 _v244 = true;
1776 }
1777 else
1778 {
1779 pRawDLV = malloc(header.uDecompressedSize);
1780 if (header.uCompressedSize == header.uDecompressedSize)
1781 fread(pRawDLV, 1, header.uCompressedSize, File);
1782 else if (header.uCompressedSize < header.uDecompressedSize)
1783 {
1784 void* pTmpMem = malloc(header.uCompressedSize);
1785 {
1786 fread(pTmpMem, header.uCompressedSize, 1, File);
1787
1788 uint uDecompressedSize = header.uDecompressedSize;
1789 zlib::MemUnzip(pRawDLV, &uDecompressedSize, pTmpMem, header.uCompressedSize);
1790
1791 if (uDecompressedSize != header.uDecompressedSize)
1792 Log::Warning(L"uDecompressedSize != header.uDecompressedSize in DLV");
1793 }
1794 free(pTmpMem);
1795 }
1796 else
1797 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1108", 0);
1798
1799 pData = (char *)pRawDLV;
1800 }
1801
1802 memcpy(&dlv, pData, 40);
1803 pData += 40;
1804
1805 //v152 = dlv.uNumFacesInBModels;
1806 if (dlv.uNumFacesInBModels)
1807 {
1808 //v153 = dlv.uNumDecorations;
1809 if (dlv.uNumDecorations)
1810 {
1811 if (dlv.uNumFacesInBModels != uNumFaces ||
1812 dlv.uNumDecorations != uNumLevelDecorations)
1813 _v244 = true;
1814 }
1815 }
1816
1817 if (dword_6BE364_game_settings_1 & GAME_SETTINGS_2000 )
1818 _i = 0x1BAF800;
1819 bool _a = false;
1820 if ( a3 - dlv.uLastRepawnDay >= _i && _stricmp(pCurrentMapName, "d29.dlv") )
1821 _a = true;
1822
1823 //v154 = 875;
1824 if (_v244 || (_a || !dlv.uLastRepawnDay))
1825 {
1826 if (_v244)
1827 {
1828 memset(v203, 0, 0x36B);
1829 }
1830 else if (_a || !dlv.uLastRepawnDay)
1831 {
1832 memcpy(v203, pData, 0x36B);
1833 }
1834
1835 free(pRawDLV);
1836 dlv.uLastRepawnDay = a3;
1837 if (_v244)
1838 ++dlv.uNumRespawns;
1839 //v201 = pFilename;
1840 *(int *)pDest = 1;
1841 File = pGames_LOD->FindContainer(pFilename, 0);
1842 fread(&header, 0x10u, 1, File);
1843 uint v155 = header.uCompressedSize;
1844 uint Count = header.uDecompressedSize;
1845 BLVFace* Src = (BLVFace *)malloc(header.uDecompressedSize);
1846 pRawDLV = Src;
1847 if (v155 <= Count)
1848 {
1849 if (v155 == Count)
1850 fread(Src, 1, Count, File);
1851 else
1852 {
1853 void* _uSourceLen = malloc(v155);
1854 fread(_uSourceLen, v155, 1, File);
1855 zlib::MemUnzip(Src, &Count, _uSourceLen, v155);
1856 free(_uSourceLen);
1857 }
1858 }
1859 else
1860 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Polydata.cpp:1195", 0);
1861 pData = ((char *)Src + 40);
1862 //v154 = 875;
1863 }
1864 else
1865 {
1866 *(int *)pDest = 0;
1867 }
1868
1869
1870 //LABEL_140:
1871 //v202 = (int)".blv";
1872 //v156 = strlen(pFilename);
1873 strcpy(&pFilename[strlen(pFilename) - 4], ".blv");
1874 memcpy(_visible_outlines, pData, 875);
1875 pData += 875;
1876
1877 if ( *(int *)pDest )
1878 memcpy(_visible_outlines, v203, 875);
1879
1880 for (uint i = 0; i < pMapOutlines->uNumOutlines; ++i)
1881 {
1882 BLVMapOutline* pVertex = &pMapOutlines->pOutlines[i];
1883 if ((unsigned __int8)(1 << (7 - i % 8)) & _visible_outlines[i / 8])
1884 pVertex->uFlags |= 1;
1885 }
1886
1887
1888 for (uint i = 0; i < uNumFaces; ++i)
1889 {
1890 BLVFace* pFace = &pFaces[i];
1891 BLVFaceExtra* pFaceExtra = &pFaceExtras[pFace->uFaceExtraID];
1892
1893 memcpy(&pFace->uAttributes, pData, 4);
1894 pData += 4;
1895
1896 if (pFaceExtra->uEventID)
1897 {
1898 if (pFaceExtra->HasEventint())
1899 pFace->uAttributes |= FACE_HAS_EVENT;
1900 else
1901 pFace->uAttributes &= ~FACE_HAS_EVENT;
1902 }
1903 }
1904
1905 pGameLoadingUI_ProgressBar->Progress();
1906
1907 for (uint i = 0; i < uNumLevelDecorations; ++i)
1908 {
1909 memcpy(&pLevelDecorations[i].uFlags, pData, 2);
1910 pData += 2;
1911 }
1912
1913 pGameLoadingUI_ProgressBar->Progress();
1914
1915 memcpy(&uNumActors, pData, 4);
1916 memcpy(&pActors, pData + 4, uNumActors * sizeof(Actor));
1917 pData += 4 + uNumActors * sizeof(Actor);
1918
1919 pGameLoadingUI_ProgressBar->Progress();
1920 pGameLoadingUI_ProgressBar->Progress();
1921
1922 memcpy(&uNumSpriteObjects, pData, 4);
1923 memcpy(pSpriteObjects.data(), pData + 4, uNumSpriteObjects * sizeof(SpriteObject));
1924 pData += 4 + uNumSpriteObjects * sizeof(SpriteObject);
1925
1926 pGameLoadingUI_ProgressBar->Progress();
1927
1928 for ( uint i = 0; i < uNumSpriteObjects; ++i )
1929 {
1930 if (pSpriteObjects[i].stru_24.uItemID && !(pSpriteObjects[i].uAttributes & 0x0100))
1931 {
1932 pSpriteObjects[i].uType = pItemsTable->pItems[pSpriteObjects[i].stru_24.uItemID].uSpriteID;
1933
1934 //uint uObjectID = 0;
1935 for ( uint j = 0; j < pObjectList->uNumObjects; ++j )
1936 if ( pSpriteObjects[i].uType == pObjectList->pObjects[j].uObjectID )
1937 {
1938 pSpriteObjects[i].uObjectDescID = j;
1939 break;
1940 }
1941 }
1942 }
1943
1944 pGameLoadingUI_ProgressBar->Progress();
1945
1946 memcpy(&uNumChests, pData, 4);
1947 memcpy(pChests.data(), pData + 4, uNumChests * sizeof(Chest));
1948 pData += 4 + uNumChests * sizeof(Chest);
1949
1950 pGameLoadingUI_ProgressBar->Progress();
1951 pGameLoadingUI_ProgressBar->Progress();
1952
1953 memcpy(pDoors, pData, 0x3E80);
1954 pData += 0x3E80;
1955
1956 //v201 = (const char *)blv.uDoors_ddata_Size;
1957 //v200 = (size_t)ptr_0002B4_doors_ddata;
1958 //v170 = malloc(ptr_0002B4_doors_ddata, blv.uDoors_ddata_Size, "L.DData");
1959 //v171 = blv.uDoors_ddata_Size;
1960 ptr_0002B4_doors_ddata = (unsigned __int16 *)malloc(blv.uDoors_ddata_Size);//, "L.DData");
1961 memcpy(ptr_0002B4_doors_ddata, pData, blv.uDoors_ddata_Size);
1962 pData += blv.uDoors_ddata_Size;
1963
1964 //Src = (BLVFace *)((char *)Src + v171);
1965 //v172 = 0;
1966 //v245 = 0;
1967 //if (uNumDoors > 0)
1968 for (uint i = 0, j = 0; i < uNumDoors; ++i)
1969 {
1970 BLVDoor* pDoor = &pDoors[i];
1971
1972 pDoor->pVertexIDs = &ptr_0002B4_doors_ddata[j];
1973 j += pDoor->uNumVertices;
1974
1975 pDoor->pFaceIDs = &ptr_0002B4_doors_ddata[j];
1976 j += pDoor->uNumFaces;
1977
1978 pDoor->pSectorIDs = &ptr_0002B4_doors_ddata[j];
1979 j += pDoor->field_48;
1980
1981 pDoor->pDeltaUs = (short *)(&ptr_0002B4_doors_ddata[j]);
1982 j += pDoor->uNumFaces;
1983
1984 pDoor->pDeltaVs = (short *)(&ptr_0002B4_doors_ddata[j]);
1985 j += pDoor->uNumFaces;
1986
1987 pDoor->pXOffsets = &ptr_0002B4_doors_ddata[j];
1988 j += pDoor->uNumOffsets;
1989
1990 pDoor->pYOffsets = &ptr_0002B4_doors_ddata[j];
1991 j += pDoor->uNumOffsets;
1992
1993 pDoor->pZOffsets = &ptr_0002B4_doors_ddata[j];
1994 j += pDoor->uNumOffsets;
1995 /*v173 = pDoors;
1996 for ( k = 0; ; v172 = v188 + 2 * *((short *)&v173[k] - 3) )
1997 {
1998 v173[k].pVertexIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v172);
1999 v175 = &pDoors[k];
2000 v176 = v172 + 2 * v175->uNumVertices;
2001 v175->pFaceIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v176);
2002 v177 = &pDoors[k];
2003 v178 = v176 + 2 * v177->uNumFaces;
2004 v177->pSectorIDs = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v178);
2005 v179 = &pDoors[k];
2006 v180 = v178 + 2 * v179->field_48;
2007 v179->pDeltaUs = (__int16 *)((char *)ptr_0002B4_doors_ddata + v180);
2008 v181 = &pDoors[k];
2009 v182 = v180 + 2 * v181->uNumFaces;
2010 v181->pDeltaVs = (__int16 *)((char *)ptr_0002B4_doors_ddata + v182);
2011 v183 = &pDoors[k];
2012 v184 = v182 + 2 * v183->uNumFaces;
2013 v183->pXOffsets = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v184);
2014 v185 = &pDoors[k];
2015 v186 = v184 + 2 * v185->uNumOffsets;
2016 v185->pYOffsets = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v186);
2017 v187 = &pDoors[k];
2018 ++k;
2019 v188 = v186 + 2 * v187->uNumOffsets;
2020 v189 = (unsigned __int16 *)((char *)ptr_0002B4_doors_ddata + v188);
2021 ++v245;
2022 v187->pZOffsets = v189;
2023 v173 = pDoors;
2024 if ( v245 >= uNumDoors )
2025 break;
2026 }*/
2027 }
2028 //v190 = 0;
2029 //v245 = 0;
2030 for (uint i = 0; i < uNumDoors; ++i)
2031 {
2032 BLVDoor* pDoor = &pDoors[i];
2033
2034 for (uint j = 0; j < pDoor->uNumFaces; ++j)
2035 {
2036 BLVFace* pFace = &pFaces[pDoor->pFaceIDs[j]];
2037 BLVFaceExtra* pFaceExtra = &pFaceExtras[pFace->uFaceExtraID];
2038
2039 pDoor->pDeltaUs[j] = pFaceExtra->sTextureDeltaU;
2040 pDoor->pDeltaVs[j] = pFaceExtra->sTextureDeltaV;
2041 }
2042 //v191 = pDoors;
2043 //pDest = 0;
2044 //do
2045 // {
2046 /*Argsn = 0;
2047 for ( l = (BLVDoor *)&v190[(int)v191];
2048 Argsn < *(short *)&v190[(int)v191 + 70];
2049 l = (BLVDoor *)&v190[(int)v191] )
2050 {
2051 v193 = Argsn;
2052 v194 = l->pFaceIDs[Argsn++];
2053 v195 = &pFaceExtras[pFaces[v194].uFaceExtraID];
2054 l->pDeltaUs[v193] = v195->sTextureDeltaU;
2055 v190 = pDest;
2056 *(short *)(v193 * 2 + *(int *)&pDest[(unsigned int)pDoors + 52]) = v195->sTextureDeltaV;
2057 v191 = pDoors;
2058 }
2059 ++v245;
2060 v190 += 80;
2061 pDest = v190;*/
2062 //}
2063 //while ( v245 < uNumDoors );
2064 }
2065
2066
2067 pGameLoadingUI_ProgressBar->Progress();
2068
2069 memcpy(&stru_5E4C90_MapPersistVars, pData, 0xC8);
2070 pData += 0xC8;
2071
2072 pGameLoadingUI_ProgressBar->Progress();
2073
2074 memcpy(&stru1, pData, 0x38u);
2075 pData += 0x38;
2076
2077 free(pRawDLV);
2078 //v5 = 0;
2079
2080 pSoundList->LoadSound(64, 0);
2081 pSoundList->LoadSound(103, 0);
2082 pSoundList->LoadSound(63, 0);
2083 pSoundList->LoadSound(102, 0);
2084 pSoundList->LoadSound(50, 0);
2085 pSoundList->LoadSound(89, 0);
2086
2087 return 0;
2088 }
2089
2090
2091 //----- (0049AC17) --------------------------------------------------------
2092 int IndoorLocation::GetSector(int sX, int sY, int sZ)
2093 {
2094 int v4; // esi@1
2095 signed int v25; // edx@21
2096 int v26; // ebx@23
2097 int v37; // edi@38
2098 int pSectorID; // ebx@40
2099 int v39; // eax@41
2100 int v43[50]; // [sp+Ch] [bp-108h]@1
2101 bool v50; // [sp+ECh] [bp-28h]@19
2102 int v51; // [sp+F0h] [bp-24h]@9
2103 int v53; // [sp+F8h] [bp-1Ch]@10
2104 int v54; // [sp+FCh] [bp-18h]@16
2105 int v55; // [sp+100h] [bp-14h]@1
2106 int v59; // [sp+110h] [bp-4h]@16
2107
2108 v4 = 0;
2109 v43[0] = 0;
2110
2111 v55 = 0;
2112
2113 if (uNumSectors < 2)
2114 return 0;
2115
2116 for (uint i = 1; i < uNumSectors; ++i)
2117 {
2118 BLVSector* pSector = &pSectors[i];
2119
2120 if (pSector->pBounding.x1 > sX || pSector->pBounding.x2 < sX ||
2121 pSector->pBounding.y1 > sY || pSector->pBounding.y2 < sY ||
2122 pSector->pBounding.z1 - 64 > sZ || pSector->pBounding.z2 + 64 < sZ)
2123 continue;
2124
2125 //Log::Warning(L"Sector[%u]", i);
2126 v51 = pSector->uNumFloors + pSector->uNumPortals;
2127 if (!v51)
2128 continue;
2129
2130
2131 for (uint j = 0; j < v51; ++j)
2132 {
2133 uint uFaceID;
2134 if (j < pSector->uNumFloors)
2135 uFaceID = pSector->pFloors[j];
2136 else
2137 uFaceID = pSector->pPortals[j - pSector->uNumFloors];
2138
2139 BLVFace* pFace = &pFaces[uFaceID];
2140 if (pFace->uPolygonType != POLYGON_Floor &&
2141 pFace->uPolygonType != POLYGON_InBetweenFloorAndWall)
2142 continue;
2143
2144 v54 = 0;
2145 v50 = pVertices[pFace->pVertexIDs[0]].y >= sY;
2146
2147 for (uint k = 1; k <= pFace->uNumVertices; k++)
2148 {
2149 v59 = v50;
2150
2151 if (v54 >= 2)
2152 break;
2153
2154 Vec3<int16_t>* v2 = &pVertices[pFace->pVertexIDs[k]];
2155 v50 = v2->y >= sY;
2156
2157 if (v59 == v50)
2158 continue;
2159
2160 Vec3<int16_t>* v1 = &pVertices[pFace->pVertexIDs[k - 1]];
2161 v25 = v2->x >= sX ? 0 : 2;
2162 v26 = v25 | (v1->x < sX);
2163
2164 if (v26 == 3)
2165 continue;
2166
2167 if (!v26)
2168 ++v54;
2169 else
2170 {
2171 if (v1->x >= v2->x)
2172 {
2173 /*int _a58;
2174 int _a59;
2175
2176 v32 = v1->x - v2->x;
2177 LODWORD(v33) = v32 << 16;
2178 HIDWORD(v33) = v32 >> 16;*/
2179 //fixpoint_div(v1->x - v2->x, v1->y - v2->y);
2180 //_a58 = v33 / (v1->y - v2->y);
2181 //_a59 = fixpoint_mul(_a58, sY - v2->y);
2182 long long x_div_y = fixpoint_div(v1->x - v2->x, v1->y - v2->y);
2183 long long res = fixpoint_mul(x_div_y, sY - v2->y); // a / b * c - looks like projection
2184 if (res + v2->x > sX)
2185 ++v54;
2186 }
2187 else
2188 {
2189 long long x_div_y = fixpoint_div(v2->x - v1->x, v2->y - v1->y);
2190 long long res = fixpoint_mul(x_div_y, sY - v1->y);
2191
2192 if (res + v1->x > sX)
2193 ++v54;
2194
2195 /*int _a58;
2196 int _a59;
2197 auto v32 = v2->x - v1->x;
2198 LODWORD(v33) = v32 << 16;
2199 HIDWORD(v33) = v32 >> 16;
2200 _a58 = v33 / (v2->y - v1->y);
2201 _a59 = fixpoint_mul(_a58, sY - v1->y);
2202
2203 if (_a59 + pVertices[k].x > sX)
2204 ++v54;*/
2205 }
2206 }
2207 }
2208
2209 if (pFace->uNumVertices && v54 == 1)
2210 v43[v55++] = uFaceID;
2211 }
2212 }
2213
2214 v4 = v43[0];
2215 if ( v55 == 1 )
2216 return this->pFaces[v4].uSectorID;
2217 if ( !v55 )
2218 return 0;
2219 pSectorID = 0;
2220 v53 = 0xFFFFFFu;
2221 if ( v55 > 0 )
2222 {
2223 v39 = sY;
2224 for ( v37 = 0; v37 < v55; ++v37 )
2225 {
2226 if ( this->pFaces[v43[v37]].uPolygonType == POLYGON_Floor )
2227 v39 = sZ - this->pVertices[*this->pFaces[v43[v37]].pVertexIDs].z;
2228 if ( this->pFaces[v43[v37]].uPolygonType == POLYGON_InBetweenFloorAndWall )
2229 {
2230 v39 = sZ - ((fixpoint_mul(this->pFaces[v43[v37]].zCalc1, (sX << 16))
2231 + fixpoint_mul(this->pFaces[v43[v37]].zCalc2, (sY << 16))
2232 + this->pFaces[v43[v37]].zCalc3
2233 + 0x8000) >> 16);
2234 }
2235 if ( v39 >= 0 )
2236 {
2237 if ( v39 < v53 )
2238 {
2239 pSectorID = this->pFaces[v43[v37]].uSectorID;
2240 v53 = v39;
2241 }
2242 }
2243 }
2244 }
2245 return pSectorID;
2246 }
2247 // 49AC17: using guessed type int var_108[50];
2248
2249
2250 //----- (00498A41) --------------------------------------------------------
2251 void BLVFace::_get_normals(Vec3_int_ *a2, Vec3_int_ *a3)
2252 {
2253 Vec3_float_ a1; // [sp+Ch] [bp-Ch]@8
2254
2255 if ( this->uPolygonType == POLYGON_VerticalWall )
2256 {
2257 a2->x = -this->pFacePlane_old.vNormal.y;
2258 a2->y = this->pFacePlane_old.vNormal.x;
2259 a2->z = 0;
2260
2261 a3->x = 0;
2262 a3->y = 0;
2263 a3->z = 0xFFFF0000u;
2264
2265 }
2266 else if ( this->uPolygonType == POLYGON_Floor || this->uPolygonType == POLYGON_Ceiling )
2267 {
2268 a2->x = 0x10000u;
2269 a2->y = 0;
2270 a2->z = 0;
2271
2272 a3->x = 0;
2273 a3->y = 0xFFFF0000u;
2274 a3->z = 0;
2275
2276 }
2277 else if ( this->uPolygonType == POLYGON_InBetweenFloorAndWall || this->uPolygonType == POLYGON_InBetweenCeilingAndWall )
2278 {
2279 if ( abs(this->pFacePlane_old.vNormal.z) < 46441 )
2280 {
2281 a1.x = (double)-this->pFacePlane_old.vNormal.y;
2282 a1.y = (double)this->pFacePlane_old.vNormal.x;
2283 a1.z = 0.0;
2284 a1.Normalize();
2285
2286 a2->x = (signed __int64)(a1.x * 65536.0);
2287 a2->y = (signed __int64)(a1.y * 65536.0);
2288 a2->z = 0;
2289
2290 a3->y = 0;
2291 a3->z = 0xFFFF0000u;
2292 a3->x = 0;
2293
2294 }
2295 else
2296 {
2297 a2->x = 0x10000u;
2298 a2->y = 0;
2299 a2->z = 0;
2300
2301 a3->x = 0;
2302 a3->y = 0xFFFF0000u;
2303 a3->z = 0;
2304 }
2305
2306 }
2307 //LABEL_12:
2308 if ( this->uAttributes & FACE_UNKNOW3 )
2309 {
2310 a2->x = -a2->x;
2311 a2->y = -a2->y;
2312 a2->z = -a2->z;
2313 }
2314 if ( this->uAttributes & FACE_UNKNOW4 )
2315 {
2316 a3->x = -a3->x;
2317 a3->y = -a3->y;
2318 a3->z = -a3->z;
2319 }
2320 return;
2321 }
2322
2323 //----- (0044C23B) --------------------------------------------------------
2324 bool BLVFaceExtra::HasEventint()
2325 {
2326 signed int event_index; // eax@1
2327 _evt_raw* start_evt;
2328 _evt_raw* end_evt;
2329
2330 event_index = 0;
2331 if ( (uLevelEVT_NumEvents - 1) <= 0 )
2332 return false;
2333 while ( pLevelEVT_Index[event_index].uEventID != this->uEventID )
2334 {
2335 ++event_index;
2336 if ( event_index >= (signed int)(uLevelEVT_NumEvents - 1) )
2337 return false;
2338 }
2339 end_evt=(_evt_raw*)&pLevelEVT[pLevelEVT_Index[event_index+1].uEventOffsetInEVT];
2340 start_evt=(_evt_raw*)&pLevelEVT[pLevelEVT_Index[event_index].uEventOffsetInEVT];
2341 if ( (end_evt->_e_type != EVENT_Exit) || (start_evt->_e_type!= EVENT_MouseOver) )
2342 return false;
2343 else
2344 return true;
2345 }
2346
2347 //----- (0046F228) --------------------------------------------------------
2348 void BLV_UpdateDoors()
2349 {
2350 BLVFace *face; // ebx@24
2351 Vec3_short_ *v17; // esi@24
2352 int v18; // eax@24
2353 int v19; // edx@24
2354 signed int v20; // eax@24
2355 int v24; // esi@25
2356 int v25; // eax@25
2357 signed __int64 v27; // qtt@27
2358 BLVFaceExtra *v28; // esi@32
2359 int v32; // eax@34
2360 Vec3_short_ *v34; // eax@35
2361 int v35; // ecx@35
2362 int v36; // edx@35
2363 signed int v37; // eax@35
2364 signed int v38; // edx@35
2365 int v39; // eax@35
2366 int v40; // edx@35
2367 Vec3_short_ *v43; // edi@36
2368 int v57; // eax@58
2369 Vec3_int_ v67;
2370 Vec3_int_ v70;
2371 int v73; // [sp+20h] [bp-44h]@24
2372 int v75; // [sp+28h] [bp-3Ch]@36
2373 int v76; // [sp+2Ch] [bp-38h]@36
2374 int v77; // [sp+30h] [bp-34h]@36
2375 int v82; // [sp+44h] [bp-20h]@35
2376 int v83; // [sp+48h] [bp-1Ch]@34
2377 int v84; // [sp+4Ch] [bp-18h]@34
2378 SoundID eDoorSoundID; // [sp+54h] [bp-10h]@1
2379 int v88; // [sp+5Ch] [bp-8h]@18
2380 int v89; // [sp+60h] [bp-4h]@6
2381
2382 eDoorSoundID = (SoundID)pDoorSoundIDsByLocationID[dword_6BE13C_uCurrentlyLoadedLocationID];
2383 for (uint i = 0; i < pIndoor->uNumDoors; ++i)
2384 {
2385 BLVDoor* door = &pIndoor->pDoors[i];
2386 if (door->uState == BLVDoor::Closed || door->uState == BLVDoor::Open)
2387 {
2388 door->uAttributes &= 0xFFFFFFFDu;//~0x2
2389 continue;
2390 }
2391 door->uTimeSinceTriggered += pEventTimer->uTimeElapsed;
2392 if (door->uState == BLVDoor::Opening)
2393 {
2394 v89 = (signed int)(door->uTimeSinceTriggered * door->uCloseSpeed) / 128;
2395 if ( v89 >= door->uMoveLength )
2396 {
2397 v89 = door->uMoveLength;
2398 door->uState = BLVDoor::Open;
2399 if ( !(door->uAttributes & FACE_UNKNOW5) && door->uNumVertices != 0)
2400 pAudioPlayer->PlaySound((SoundID)((int)eDoorSoundID + 1), PID(OBJECT_BLVDoor,i), 0, -1, 0, 0, 0, 0);
2401 //goto LABEL_18;
2402 }
2403 else if (!(door->uAttributes & FACE_UNKNOW5) && door->uNumVertices)
2404 pAudioPlayer->PlaySound(eDoorSoundID, PID(OBJECT_BLVDoor, i), 1, -1, 0, 0, 0, 0);
2405 }
2406 else
2407 {
2408 signed int v5 = (signed int)(door->uTimeSinceTriggered * door->uOpenSpeed) / 128;
2409 if ( v5 >= door->uMoveLength)
2410 {
2411 v89 = 0;
2412 door->uState = BLVDoor::Closed;
2413 if ( !(door->uAttributes & FACE_UNKNOW5) && door->uNumVertices != 0)
2414 pAudioPlayer->PlaySound((SoundID)((int)eDoorSoundID + 1), PID(OBJECT_BLVDoor,i), 0, -1, 0, 0, 0, 0);
2415 //goto LABEL_18;
2416 }
2417 else
2418 {
2419 v89 = door->uMoveLength - v5;
2420 if (!(door->uAttributes & FACE_UNKNOW5) && door->uNumVertices)
2421 pAudioPlayer->PlaySound(eDoorSoundID, PID(OBJECT_BLVDoor, i), 1, -1, 0, 0, 0, 0);
2422 }
2423 }
2424
2425 //LABEL_18:
2426 for (uint j = 0; j < door->uNumVertices; ++j)
2427 {
2428 pIndoor->pVertices[door->pVertexIDs[j]].x = fixpoint_mul(door->vDirection.x, v89) + door->pXOffsets[j];
2429 pIndoor->pVertices[door->pVertexIDs[j]].y = fixpoint_mul(door->vDirection.y, v89) + door->pYOffsets[j];
2430 pIndoor->pVertices[door->pVertexIDs[j]].z = fixpoint_mul(door->vDirection.z, v89) + door->pZOffsets[j];
2431 }
2432 for ( v88 = 0; v88 < door->uNumFaces; ++v88 )
2433 {
2434 face = &pIndoor->pFaces[door->pFaceIDs[v88]];
2435 v17 = &pIndoor->pVertices[face->pVertexIDs[0]];
2436 v18 = face->pFacePlane_old.vNormal.y;
2437 v73 = *(int *)&v17->x;
2438 v19 = face->pFacePlane_old.vNormal.z;
2439 v20 = -(v19 * (int)v17->z + (signed __int16)v73 * face->pFacePlane_old.vNormal.x + SHIWORD(v73) * v18);
2440 face->pFacePlane_old.dist = v20;
2441 face->pFacePlane.dist = -((double)v17->z * face->pFacePlane.vNormal.z
2442 + (double)v17->y * face->pFacePlane.vNormal.y
2443 + (double)v17->x * face->pFacePlane.vNormal.x);
2444 if ( v19 )
2445 {
2446 v24 = abs(v20 >> 15);
2447 v25 = abs(face->pFacePlane_old.vNormal.z);
2448 if ( v24 > v25 )
2449 Error("Door Error\ndoor id: %i\nfacet no: %i\n\nOverflow dividing facet->d [%i] by facet->nz [%i]",
2450 door->uDoorID, door->pFaceIDs[v88], face->pFacePlane_old.dist, face->pFacePlane_old.vNormal.z);
2451 LODWORD(v27) = face->pFacePlane_old.dist << 16;
2452 HIDWORD(v27) = face->pFacePlane_old.dist >> 16;
2453 face->zCalc3 = -v27 / face->pFacePlane_old.vNormal.z;
2454 }
2455 //if ( face->uAttributes & FACE_TEXTURE_FLOW || pRenderer->pRenderD3D )
2456 face->_get_normals(&v70, &v67);
2457 v28 = &pIndoor->pFaceExtras[face->uFaceExtraID];
2458 /*if ( !pRenderer->pRenderD3D )
2459 {
2460 if ( !(face->uAttributes & FACE_TEXTURE_FLOW) )
2461 continue;
2462 v83 = (unsigned __int64)(door->vDirection.x * (signed __int64)v70.x) >> 16;
2463 v85 = (unsigned __int64)(door->vDirection.y * (signed __int64)v70.y) >> 16;
2464 v84 = (unsigned __int64)(door->vDirection.z * (signed __int64)v70.z) >> 16;
2465 v29 = v89;
2466 v28->sTextureDeltaU = -((v83 + v85 + v84) * (signed __int64)v89) >> 16;
2467 v85 = (unsigned __int64)(door->vDirection.x * (signed __int64)v67.x) >> 16;
2468 v83 = (unsigned __int64)(door->vDirection.y * (signed __int64)v67.y) >> 16;
2469 v84 = (unsigned __int64)(door->vDirection.z * (signed __int64)v67.z) >> 16;
2470 v31 = (v85 + v83 + v84) * (signed __int64)v29;
2471 v32 = v31 >> 16;
2472 v57 = -v32;
2473 v28->sTextureDeltaV = v57;
2474 v28->sTextureDeltaU += door->pDeltaUs[v88];
2475 v28->sTextureDeltaV = v57 + door->pDeltaVs[v88];
2476 continue;
2477 }*/
2478 v28->sTextureDeltaU = 0;
2479 v28->sTextureDeltaV = 0;
2480 v34 = &pIndoor->pVertices[face->pVertexIDs[0]];
2481 v35 = v34->z;
2482 v36 = v34->y;
2483 v82 = v34->x;
2484 v37 = v70.x * v82 + v70.y * v36 + v70.z * v35;
2485 v38 = v67.x * v82 + v67.y * v36 + v67.z * v35;
2486 v39 = v37 >> 16;
2487 *face->pVertexUIDs = v39;
2488 v40 = v38 >> 16;
2489 *face->pVertexVIDs = v40;
2490 v84 = v39;
2491 v82 = v40;
2492 for (uint j = 1; j < face->uNumVertices; ++j)
2493 {
2494 v43 = &pIndoor->pVertices[face->pVertexIDs[j]];
2495 v76 = ((__int64)v70.z * v43->z + (__int64)v70.x * v43->x + (__int64)v70.y * v43->y) >> 16;
2496 v77 = ((__int64)v67.x * v43->x + (__int64)v67.y * v43->y + (__int64)v43->z * v67.z) >> 16;
2497 if ( v76 < v39 )
2498 v39 = v76;
2499 if ( v77 < v40 )
2500 v40 = v77;
2501 if ( v76 > v84 )
2502 v84 = v76;
2503 if ( v77 > v82 )
2504 v82 = v77;
2505 face->pVertexUIDs[j] = v76;
2506 face->pVertexVIDs[j] = v77;
2507 }
2508 if ( face->uAttributes & 0x00001000 )
2509 v28->sTextureDeltaU -= v39;
2510 else
2511 {
2512 if ( SBYTE1(face->uAttributes) < 0 )
2513 {
2514 if ( face->uBitmapID != -1 )
2515 v28->sTextureDeltaU -= v84 + pBitmaps_LOD->pTextures[face->uBitmapID].uTextureWidth;
2516 }
2517 }
2518 if ( face->uAttributes & FACE_UNKNOW6 )
2519 v28->sTextureDeltaV -= v40;
2520 else
2521 {
2522 if ( face->uAttributes & FACE_INDOOR_DOOR )
2523 {
2524 if ( face->uBitmapID != -1 )
2525 v28->sTextureDeltaV -= v82 + pBitmaps_LOD->GetTexture(face->uBitmapID)->uTextureHeight;
2526 }
2527 }
2528 if ( face->uAttributes & FACE_TEXTURE_FLOW )
2529 {
2530 v84 = fixpoint_mul(door->vDirection.x, v70.x);
2531 v82 = fixpoint_mul(door->vDirection.y, v70.y);
2532 v83 = fixpoint_mul(door->vDirection.z, v70.z);
2533 v75 = v84 + v82 + v83;
2534 v82 = fixpoint_mul(v75, v89);
2535 v28->sTextureDeltaU = -v82;
2536 v84 = fixpoint_mul(door->vDirection.x, v67.x);
2537 v82 = fixpoint_mul(door->vDirection.y, v67.y);
2538 v83 = fixpoint_mul(door->vDirection.z, v67.z);
2539 v75 = v84 + v82 + v83;
2540 v32 = fixpoint_mul(v75, v89);
2541 v57 = -v32;
2542 v28->sTextureDeltaV = v57;
2543 v28->sTextureDeltaU += door->pDeltaUs[v88];
2544 v28->sTextureDeltaV = v57 + door->pDeltaVs[v88];
2545 }
2546 }
2547 }
2548 }
2549 // 6BE13C: using guessed type int dword_6BE13C_uCurrentlyLoadedLocationID;
2550
2551 //----- (0046F90C) --------------------------------------------------------
2552 void UpdateActors_BLV()
2553 {
2554 int v2; // edi@6
2555 int v3; // eax@6
2556 int v4; // eax@8
2557 __int16 v5; // ax@11
2558 signed int v6; // ebx@14
2559 signed __int64 v10; // qax@18
2560 int v22; // edi@46
2561 unsigned int v24; // eax@51
2562 int v27; // ST08_4@54
2563 int v28; // edi@54
2564 int v29; // eax@54
2565 int v30; // ecx@62
2566 int v31; // ebx@62
2567 int v32; // eax@62
2568 int v33; // eax@64
2569 signed int v37; // ebx@85
2570 int v44; // ecx@96
2571 int v45; // edi@101
2572 AIDirection v52; // [sp+0h] [bp-60h]@75
2573 AIDirection v53; // [sp+1Ch] [bp-44h]@116
2574 unsigned int uSectorID; // [sp+3Ch] [bp-24h]@6
2575 int v56; // [sp+40h] [bp-20h]@6
2576 unsigned int _this; // [sp+44h] [bp-1Ch]@51
2577 int v58; // [sp+48h] [bp-18h]@51
2578 int v59; // [sp+4Ch] [bp-14h]@8
2579 unsigned int uFaceID; // [sp+50h] [bp-10h]@6
2580 int v61; // [sp+54h] [bp-Ch]@14
2581 int v62; // [sp+58h] [bp-8h]@6
2582 unsigned int actor_id; // [sp+5Ch] [bp-4h]@1
2583
2584 for ( actor_id = 0; actor_id < uNumActors; actor_id++ )
2585 {
2586 if ( pActors[actor_id].uAIState == Removed || pActors[actor_id].uAIState == Disabled
2587 || pActors[actor_id].uAIState == Summoned || !pActors[actor_id].uMovementSpeed )
2588 continue;
2589 uSectorID = pActors[actor_id].uSectorID;
2590 v2 = collide_against_floor(pActors[actor_id].vPosition.x, pActors[actor_id].vPosition.y, pActors[actor_id].vPosition.z, &uSectorID, &uFaceID);
2591 pActors[actor_id].uSectorID = uSectorID;
2592 v3 = pActors[actor_id].pMonsterInfo.uFlying;
2593 v56 = v2;
2594 v62 = v3;
2595 if ( !pActors[actor_id].CanAct() )
2596 v62 = 0;
2597 v4 = pActors[actor_id].vPosition.z;
2598 v59 = 0;
2599 if ( pActors[actor_id].vPosition.z > v2 + 1 )
2600 v59 = 1;
2601 if ( v2 <= -30000 )
2602 {
2603 v5 = pIndoor->GetSector(pActors[actor_id].vPosition.x, pActors[actor_id].vPosition.y, v4);
2604 pActors[actor_id].uSectorID = v5;
2605 v56 = BLV_GetFloorLevel(pActors[actor_id].vPosition.x, pActors[actor_id].vPosition.y, pActors[actor_id].vPosition.z, v5, &uFaceID);
2606 if ( !v5 || v56 == -30000 )
2607 continue;
2608 }
2609 if ( pActors[actor_id].uCurrentActionAnimation == ANIM_Walking)//монстр двигается
2610 {
2611 v6 = pActors[actor_id].uMovementSpeed;
2612 if ( pActors[actor_id].pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0 )
2613 {
2614 if ( pActors[actor_id].pActorBuffs[ACTOR_BUFF_SLOWED].uPower )
2615 LODWORD(v10) = pActors[actor_id].uMovementSpeed / (unsigned __int16)pActors[actor_id].pActorBuffs[ACTOR_BUFF_SLOWED].uPower;
2616 else
2617 v10 = (signed __int64)((double)pActors[actor_id].uMovementSpeed * 0.5);
2618 v6 = v10;
2619 }
2620 if ( pActors[actor_id].uAIState == Pursuing || pActors[actor_id].uAIState == Fleeing )
2621 v6 *= 2;
2622 if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_WAIT )
2623 v6 = (signed __int64)((double)v6 * flt_6BE3AC_debug_recmod1_x_1_6);
2624 if ( v6 > 1000 )
2625 v6 = 1000;
2626 pActors[actor_id].vVelocity.x = fixpoint_mul(stru_5C6E00->Cos(pActors[actor_id].uYawAngle), v6);
2627 pActors[actor_id].vVelocity.y = fixpoint_mul(stru_5C6E00->Sin(pActors[actor_id].uYawAngle), v6);
2628 if ( v62 )
2629 pActors[actor_id].vVelocity.z = fixpoint_mul(stru_5C6E00->Sin(pActors[actor_id].uPitchAngle), v6);
2630 }
2631 else//actor is not moving(актор не двигается)
2632 {
2633 pActors[actor_id].vVelocity.x = fixpoint_mul(55000, pActors[actor_id].vVelocity.x);
2634 pActors[actor_id].vVelocity.y = fixpoint_mul(55000, pActors[actor_id].vVelocity.y);
2635 if ( v62 )
2636 pActors[actor_id].vVelocity.z = fixpoint_mul(55000, pActors[actor_id].vVelocity.z);
2637 }
2638 if ( pActors[actor_id].vPosition.z <= v56 )
2639 {
2640 pActors[actor_id].vPosition.z = v56 + 1;
2641 if ( pIndoor->pFaces[uFaceID].uPolygonType == 3 )
2642 {
2643 if ( pActors[actor_id].vVelocity.z < 0 )
2644 pActors[actor_id].vVelocity.z = 0;
2645 }
2646 else
2647 {
2648 if ( pIndoor->pFaces[uFaceID].pFacePlane_old.vNormal.z < 45000 )
2649 pActors[actor_id].vVelocity.z -= LOWORD(pEventTimer->uTimeElapsed) * GetGravityStrength();
2650 }
2651 }
2652 else
2653 {
2654 if ( v59 && !v62 )
2655 pActors[actor_id].vVelocity.z += -8 * LOWORD(pEventTimer->uTimeElapsed) * GetGravityStrength();
2656 }
2657 if ( pActors[actor_id].vVelocity.x * pActors[actor_id].vVelocity.x
2658 + pActors[actor_id].vVelocity.y * pActors[actor_id].vVelocity.y
2659 + pActors[actor_id].vVelocity.z * pActors[actor_id].vVelocity.z >= 400 )
2660 {
2661 stru_721530.field_84 = -1;
2662 stru_721530.field_70 = 0;
2663 stru_721530.field_0 = 1;
2664 stru_721530.field_8_radius = pActors[actor_id].uActorRadius;
2665 stru_721530.prolly_normal_d = pActors[actor_id].uActorRadius;
2666 stru_721530.height = pActors[actor_id].uActorHeight;
2667 v22 = 0;
2668 for ( uSectorID = 0; uSectorID < 100; uSectorID++ )
2669 {
2670 stru_721530.position.x = pActors[actor_id].vPosition.x;
2671 stru_721530.normal.x = stru_721530.position.x;
2672 stru_721530.position.y = pActors[actor_id].vPosition.y;
2673 stru_721530.normal.y = stru_721530.position.y;
2674 stru_721530.normal.z = pActors[actor_id].vPosition.z + pActors[actor_id].uActorRadius + 1;
2675 stru_721530.position.z = pActors[actor_id].vPosition.z - pActors[actor_id].uActorRadius + stru_721530.height - 1;
2676 if ( stru_721530.position.z < stru_721530.normal.z )
2677 stru_721530.position.z = pActors[actor_id].vPosition.z + pActors[actor_id].uActorRadius + 1;
2678 stru_721530.velocity.x = pActors[actor_id].vVelocity.x;
2679 stru_721530.velocity.y = pActors[actor_id].vVelocity.y;
2680 stru_721530.velocity.z = pActors[actor_id].vVelocity.z;
2681 stru_721530.uSectorID = pActors[actor_id].uSectorID;
2682 if ( !stru_721530._47050A(v22) )
2683 {
2684 v58 = 0;
2685 v24 = 8 * actor_id;
2686 LOBYTE(v24) = PID(OBJECT_Actor,actor_id);
2687 for ( v61 = 0; v61 < 100; ++v61 )
2688 {
2689 _46E44E_collide_against_faces_and_portals(1);
2690 _46E0B2_collide_against_decorations();
2691 _46EF01_collision_chech_player(0);
2692 _46ED8A_collide_against_sprite_objects(v24);
2693 for ( uint j = 0; j < ai_arrays_size; j++ )
2694 {
2695 if ( ai_near_actors_ids[j] != actor_id )
2696 {
2697 v27 = abs(pActors[ai_near_actors_ids[j]].vPosition.z - pActors[actor_id].vPosition.z);
2698 v28 = abs(pActors[ai_near_actors_ids[j]].vPosition.y - pActors[actor_id].vPosition.y);
2699 v29 = abs(pActors[ai_near_actors_ids[j]].vPosition.x - pActors[actor_id].vPosition.x);
2700 if ( int_get_vector_length(v29, v28, v27) >= pActors[actor_id].uActorRadius + (signed int)pActors[ai_near_actors_ids[j]].uActorRadius
2701 && Actor::_46DF1A_collide_against_actor(ai_near_actors_ids[j], 40) )
2702 ++v58;
2703 }
2704 }
2705 if ( _46F04E_collide_against_portals() )
2706 break;
2707 }
2708 v56 = v58 > 1;
2709 if ( stru_721530.field_7C >= stru_721530.field_6C )
2710 {
2711 v30 = stru_721530.normal2.x;
2712 v31 = stru_721530.normal2.y;
2713 v32 = stru_721530.normal2.z - stru_721530.prolly_normal_d - 1;
2714 }
2715 else
2716 {
2717 v30 = pActors[actor_id].vPosition.x + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.x);
2718 v31 = pActors[actor_id].vPosition.y + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.y);
2719 v32 = pActors[actor_id].vPosition.z + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z);
2720 }
2721 v33 = collide_against_floor(v30, v31, v32, &stru_721530.uSectorID, &uFaceID);
2722 if (pIndoor->pFaces[uFaceID].uAttributes & FACE_INDOOR_SKY && pActors[actor_id].uAIState == Dead)
2723 {
2724 pActors[actor_id].uAIState = Removed;
2725 continue;
2726 }
2727 if ( v59 || v62 || !(pIndoor->pFaces[uFaceID].uAttributes & FACE_INDOOR_SKY) )
2728 {
2729 if ( v33 == -30000 )
2730 continue;
2731 if ( pActors[actor_id].uCurrentActionAnimation != 1 || v33 >= pActors[actor_id].vPosition.z - 100 || v59 || v62 )
2732 {
2733 if ( stru_721530.field_7C < stru_721530.field_6C )
2734 {
2735 pActors[actor_id].vPosition.x += fixpoint_mul(stru_721530.field_7C, stru_721530.direction.x);
2736 pActors[actor_id].vPosition.y += fixpoint_mul(stru_721530.field_7C, stru_721530.direction.y);
2737 pActors[actor_id].vPosition.z += fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z);
2738 pActors[actor_id].uSectorID = LOWORD(stru_721530.uSectorID);
2739 stru_721530.field_70 += stru_721530.field_7C;
2740 v37 = PID_ID(stru_721530.uFaceID);
2741 if (PID_TYPE(stru_721530.uFaceID) == OBJECT_Actor)
2742 {
2743 if (pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->turn_stage == TE_MOVEMENT))
2744 {
2745 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2746 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2747 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2748 v22 = 0;
2749 continue;
2750 }
2751 if (pActors[actor_id].pMonsterInfo.uHostilityType)
2752 {
2753 if (!v56)
2754 {
2755 Actor::AI_Flee(actor_id, stru_721530.uFaceID, v22, (AIDirection *)v22);
2756 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2757 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2758 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2759 v22 = 0;
2760 continue;
2761 }
2762 }
2763 else
2764 {
2765 if (!v56)
2766 {
2767 if (!pActors[v37].pMonsterInfo.uHostilityType)
2768 {
2769 Actor::AI_FaceObject(actor_id, stru_721530.uFaceID, v22, (AIDirection *)v22);
2770 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2771 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2772 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2773 v22 = 0;
2774 continue;
2775 }
2776 Actor::AI_Flee(actor_id, stru_721530.uFaceID, v22, (AIDirection *)v22);
2777 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2778 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2779 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2780 v22 = 0;
2781 continue;
2782 }
2783 }
2784 Actor::AI_StandOrBored(actor_id, 4, v22, &v53);
2785 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2786 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2787 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2788 v22 = 0;
2789 continue;
2790 }
2791 if (PID_TYPE(stru_721530.uFaceID) == OBJECT_Player)
2792 {
2793 if (pActors[actor_id].GetActorsRelation(0))
2794 {
2795 //v51 = __OFSUB__(HIDWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime), v22);
2796 //v49 = HIDWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime) == v22;
2797 //v50 = HIDWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime) - v22 < 0;
2798 pActors[actor_id].vVelocity.y = v22;
2799 pActors[actor_id].vVelocity.x = v22;
2800 if (pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime > v22)
2801 pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
2802 viewparams->bRedrawGameUI = 1;
2803 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2804 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2805 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2806 v22 = 0;
2807 continue;
2808 }
2809 Actor::AI_FaceObject(actor_id, stru_721530.uFaceID, v22, (AIDirection *)v22);
2810 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2811 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2812 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2813 v22 = 0;
2814 continue;
2815 }
2816 if (PID_TYPE(stru_721530.uFaceID) == OBJECT_Decoration)
2817 {
2818 _this = integer_sqrt(pActors[actor_id].vVelocity.x * pActors[actor_id].vVelocity.x + pActors[actor_id].vVelocity.y * pActors[actor_id].vVelocity.y);
2819 v45 = stru_5C6E00->Atan2(pActors[actor_id].vPosition.x - pLevelDecorations[v37].vPosition.x,
2820 pActors[actor_id].vPosition.y - pLevelDecorations[v37].vPosition.y);
2821 pActors[actor_id].vVelocity.x = fixpoint_mul(stru_5C6E00->Cos(v45), _this);
2822 pActors[actor_id].vVelocity.y = fixpoint_mul(stru_5C6E00->Sin(v45), _this);
2823 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2824 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2825 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2826 v22 = 0;
2827 continue;
2828 }
2829 if (PID_TYPE(stru_721530.uFaceID) == OBJECT_BModel)
2830 {
2831 stru_721530.field_84 = stru_721530.uFaceID >> 3;
2832 if (pIndoor->pFaces[v37].uPolygonType == 3)
2833 {
2834 pActors[actor_id].vVelocity.z = 0;
2835 pActors[actor_id].vPosition.z = pIndoor->pVertices[*pIndoor->pFaces[v37].pVertexIDs].z + 1;
2836 if (pActors[actor_id].vVelocity.x * pActors[actor_id].vVelocity.x
2837 + pActors[actor_id].vVelocity.y * pActors[actor_id].vVelocity.y < 400)
2838 {
2839 pActors[actor_id].vVelocity.y = 0;
2840 pActors[actor_id].vVelocity.x = 0;
2841 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2842 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2843 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2844 v22 = 0;
2845 continue;
2846 }
2847 }
2848 else
2849 {
2850 v61 = abs(pIndoor->pFaces[v37].pFacePlane_old.vNormal.x * pActors[actor_id].vVelocity.x + pIndoor->pFaces[v37].pFacePlane_old.vNormal.y
2851 * pActors[actor_id].vVelocity.y
2852 + pIndoor->pFaces[v37].pFacePlane_old.vNormal.z
2853 * pActors[actor_id].vVelocity.z) >> 16;
2854 if ((stru_721530.speed >> 3) > v61)
2855 v61 = stru_721530.speed >> 3;
2856 pActors[actor_id].vVelocity.x += fixpoint_mul(v61, pIndoor->pFaces[v37].pFacePlane_old.vNormal.x);
2857 pActors[actor_id].vVelocity.y += fixpoint_mul(v61, pIndoor->pFaces[v37].pFacePlane_old.vNormal.y);
2858 pActors[actor_id].vVelocity.z += fixpoint_mul(v61, pIndoor->pFaces[v37].pFacePlane_old.vNormal.z);
2859 if (pIndoor->pFaces[v37].uPolygonType != 4 && pIndoor->pFaces[v37].uPolygonType != 3)
2860 {
2861 v44 = stru_721530.prolly_normal_d
2862 - ((pIndoor->pFaces[v37].pFacePlane_old.dist
2863 + pIndoor->pFaces[v37].pFacePlane_old.vNormal.z * pActors[actor_id].vPosition.z
2864 + pIndoor->pFaces[v37].pFacePlane_old.vNormal.y * pActors[actor_id].vPosition.y
2865 + pIndoor->pFaces[v37].pFacePlane_old.vNormal.x * pActors[actor_id].vPosition.x) >> 16);
2866 if (v44 > 0)
2867 {
2868 pActors[actor_id].vPosition.x += fixpoint_mul(v44, pIndoor->pFaces[v37].pFacePlane_old.vNormal.x);
2869 pActors[actor_id].vPosition.y += fixpoint_mul(v44, pIndoor->pFaces[v37].pFacePlane_old.vNormal.y);
2870 pActors[actor_id].vPosition.z += fixpoint_mul(v44, pIndoor->pFaces[v37].pFacePlane_old.vNormal.z);
2871 }
2872 pActors[actor_id].uYawAngle = stru_5C6E00->Atan2(pActors[actor_id].vVelocity.x, pActors[actor_id].vVelocity.y);
2873 }
2874 }
2875 if (pIndoor->pFaces[v37].uAttributes & FACE_UNKNOW1)
2876 EventProcessor(pIndoor->pFaceExtras[pIndoor->pFaces[v37].uFaceExtraID].uEventID, 0, 1);
2877 }
2878 pActors[actor_id].vVelocity.x = fixpoint_mul(58500, pActors[actor_id].vVelocity.x);
2879 pActors[actor_id].vVelocity.y = fixpoint_mul(58500, pActors[actor_id].vVelocity.y);
2880 pActors[actor_id].vVelocity.z = fixpoint_mul(58500, pActors[actor_id].vVelocity.z);
2881 v22 = 0;
2882 continue;
2883 }
2884 else
2885 {
2886 pActors[actor_id].vPosition.x = LOWORD(stru_721530.normal2.x);
2887 pActors[actor_id].vPosition.y = LOWORD(stru_721530.normal2.y);
2888 pActors[actor_id].vPosition.z = LOWORD(stru_721530.normal2.z) - LOWORD(stru_721530.prolly_normal_d) - 1;
2889 pActors[actor_id].uSectorID = LOWORD(stru_721530.uSectorID);
2890 //goto LABEL_123;
2891 break;
2892 }
2893
2894 }
2895 else if ( pActors[actor_id].vPosition.x & 1 )
2896 pActors[actor_id].uYawAngle += 100;
2897 else
2898 pActors[actor_id].uYawAngle -= 100;
2899 }
2900 else
2901 {
2902 if (pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->turn_stage == TE_MOVEMENT))
2903 continue;
2904 if ( !pActors[actor_id].pMonsterInfo.uHostilityType || v56 != v22 )
2905 {
2906 Actor::AI_StandOrBored(actor_id, 4, v22, &v52);
2907 continue;
2908 }
2909 }
2910 }
2911 }
2912 }
2913 else
2914 {
2915 pActors[actor_id].vVelocity.z = 0;
2916 pActors[actor_id].vVelocity.y = 0;
2917 pActors[actor_id].vVelocity.x = 0;
2918 if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_INDOOR_SKY )
2919 {
2920 if (pActors[actor_id].uAIState == Dead)
2921 pActors[actor_id].uAIState = Removed;
2922 }
2923 }
2924 //LABEL_123:
2925 ;
2926 }
2927 }
2928
2929
2930 //----- (00460A78) --------------------------------------------------------
2931 void PrepareToLoadBLV(unsigned int bLoading)
2932 {
2933 unsigned int respawn; // ebx@1
2934 unsigned int map_id; // eax@8
2935 MapInfo *map_info; // edi@9
2936 int v4; // eax@11
2937 DecorationDesc *decoration; // eax@54
2938 char v28; // zf@81
2939 signed int v30; // edi@94
2940 int v34[4]; // [sp+3E8h] [bp-2Ch]@96
2941 int v35; // [sp+3F8h] [bp-1Ch]@1
2942 int v38; // [sp+404h] [bp-10h]@1
2943 int pDest; // [sp+40Ch] [bp-8h]@1
2944
2945 respawn = 0;
2946 pGameLoadingUI_ProgressBar->Reset(0x20u);
2947 bUnderwater = false;
2948 bNoNPCHiring = false;
2949 pDest = 1;
2950 uCurrentlyLoadedLevelType = LEVEL_Indoor;
2951 pGame->uFlags2 &= 0xFFFFFFF7u;
2952 if ( Is_out15odm_underwater() )
2953 {
2954 bUnderwater = true;
2955 pGame->uFlags2 |= 8;
2956 }
2957 if ( !_stricmp(pCurrentMapName, "out15.odm") || !_stricmp(pCurrentMapName, "d23.blv") )
2958 bNoNPCHiring = true;
2959 pPaletteManager->pPalette_tintColor[0] = 0;
2960 pPaletteManager->pPalette_tintColor[1] = 0;
2961 pPaletteManager->pPalette_tintColor[2] = 0;
2962 pPaletteManager->RecalculateAll();
2963 if ( _A750D8_player_speech_timer )
2964 _A750D8_player_speech_timer = 0i64;
2965 map_id = pMapStats->GetMapInfo(pCurrentMapName);
2966 if ( map_id )
2967 {
2968 map_info = &pMapStats->pInfos[map_id];
2969 respawn = pMapStats->pInfos[map_id].uRespawnIntervalDays;
2970 v38 = GetAlertStatus();
2971 }
2972 else
2973 map_info = (MapInfo *)bLoading;
2974 dword_6BE13C_uCurrentlyLoadedLocationID = map_id;
2975
2976 pStationaryLightsStack->uNumLightsActive = 0;
2977 v4 = pIndoor->Load(pCurrentMapName, (unsigned int)(signed __int64)((double)pParty->uTimePlayed * 0.234375) / 60 / 60 / 24 + 1, respawn, (char *)&pDest) - 1;
2978 if ( !v4 )
2979 Error("Unable to open %s", pCurrentMapName);
2980
2981 if ( v4 == 1 )
2982 Error("File %s is not a BLV File", pCurrentMapName);
2983
2984 if ( v4 == 2 )
2985 Error("Attempt to open new level before clearing old");
2986 if ( v4 == 3 )
2987 Error("Out of memory loading indoor level");
2988 if ( !(dword_6BE364_game_settings_1 & GAME_SETTINGS_2000) )
2989 {
2990 Actor::InitializeActors();
2991 SpriteObject::InitializeSpriteObjects();
2992 }
2993 dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_2000;
2994 if ( !map_id )
2995 pDest = 0;
2996 if ( pDest == 1 )
2997 {
2998 for (uint i = 0; i < pIndoor->uNumSpawnPoints; ++i )
2999 {
3000 if ( pIndoor->pSpawnPoints[i].uKind == 3 )
3001 SpawnEncounter(map_info, &pIndoor->pSpawnPoints[i], 0, 0, 0);
3002 else
3003 map_info->SpawnRandomTreasure(&pIndoor->pSpawnPoints[i]);
3004 }
3005 RespawnGlobalDecorations();
3006 }
3007
3008 pSoundList->LoadSound(pDoorSoundIDsByLocationID[map_id], 0);
3009 pSoundList->LoadSound(pDoorSoundIDsByLocationID[map_id] + 1, 0);
3010
3011 for (uint i = 0; i < pIndoor->uNumDoors; ++i)
3012 {
3013 if (pIndoor->pDoors[i].uAttributes & 0x01)
3014 {
3015 pIndoor->pDoors[i].uState = BLVDoor::Opening;
3016 pIndoor->pDoors[i].uTimeSinceTriggered = 15360;
3017 pIndoor->pDoors[i].uAttributes = 2;
3018 }
3019
3020 if (pIndoor->pDoors[i].uState == BLVDoor::Closed)
3021 {
3022 pIndoor->pDoors[i].uState = BLVDoor::Closing;
3023 pIndoor->pDoors[i].uTimeSinceTriggered = 15360;
3024 pIndoor->pDoors[i].uAttributes = 2;
3025 }
3026 else if (pIndoor->pDoors[i].uState == BLVDoor::Open)
3027 {
3028 pIndoor->pDoors[i].uState = BLVDoor::Opening;
3029 pIndoor->pDoors[i].uTimeSinceTriggered = 15360;
3030 pIndoor->pDoors[i].uAttributes = 2;
3031 }
3032 }
3033
3034 for (uint i = 0; i < pIndoor->uNumFaces; ++i)
3035 {
3036 if (pIndoor->pFaces[i].uBitmapID != -1)
3037 pBitmaps_LOD->pTextures[pIndoor->pFaces[i].uBitmapID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[pIndoor->pFaces[i].uBitmapID].palette_id1);
3038 }
3039
3040 pGameLoadingUI_ProgressBar->Progress();
3041
3042 v35 = 0;
3043 for (uint i = 0; i < uNumLevelDecorations; ++i)
3044 {
3045 pDecorationList->InitializeDecorationSprite(pLevelDecorations[i].uDecorationDescID);
3046
3047 if (pDecorationList->pDecorations[pLevelDecorations[i].uDecorationDescID].uSoundID && _6807E0_num_decorations_with_sounds_6807B8 < 9)
3048 {
3049 pSoundList->LoadSound(pDecorationList->pDecorations[pLevelDecorations[i].uDecorationDescID].uSoundID, 0);
3050 _6807B8_level_decorations_ids[_6807E0_num_decorations_with_sounds_6807B8++] = i;
3051 }
3052
3053 if (!(pLevelDecorations[i].uFlags & LEVEL_DECORATION_INVISIBLE))
3054 {
3055 decoration = &pDecorationList->pDecorations[pLevelDecorations[i].uDecorationDescID];
3056 if (!decoration->DontDraw())
3057 {
3058 if ( decoration->uLightRadius )
3059 {
3060 unsigned char r = 255,
3061 g = 255,
3062 b = 255;
3063 if (/*pRenderer->pRenderD3D*/true && pRenderer->bUseColoredLights)
3064 {
3065 r = decoration->uColoredLightRed;
3066 g = decoration->uColoredLightGreen;
3067 b = decoration->uColoredLightBlue;
3068 }
3069 pStationaryLightsStack->AddLight(pLevelDecorations[i].vPosition.x,
3070 pLevelDecorations[i].vPosition.y,
3071 pLevelDecorations[i].vPosition.z + decoration->uDecorationHeight, decoration->uLightRadius, r, g, b, _4E94D0_light_type);
3072 }
3073 }
3074 }
3075
3076 if (!pLevelDecorations[i].uEventID)
3077 {
3078 if (pLevelDecorations[i].IsInteractive())
3079 {
3080 if ( v35 < 124 )
3081 {
3082 pLevelDecorations[i]._idx_in_stru123 = v35 + 75;
3083 if ( !stru_5E4C90_MapPersistVars._decor_events[v35] )
3084 pLevelDecorations[i].uFlags |= LEVEL_DECORATION_INVISIBLE;
3085 v35++;
3086 }
3087 }
3088 }
3089 }
3090
3091 pGameLoadingUI_ProgressBar->Progress();
3092
3093 for (uint i = 0; i < uNumSpriteObjects; ++i)
3094 {
3095 if (pSpriteObjects[i].uObjectDescID)
3096 {
3097 if ( pSpriteObjects[i].stru_24.uItemID )
3098 {
3099 if ( pSpriteObjects[i].stru_24.uItemID != 220 && pItemsTable->pItems[ pSpriteObjects[i].stru_24.uItemID].uEquipType == EQUIP_POTION &&
3100 !pSpriteObjects[i].stru_24.uEnchantmentType)
3101 pSpriteObjects[i].stru_24.uEnchantmentType = rand() % 15 + 5;
3102 pItemsTable->SetSpecialBonus(&pSpriteObjects[i].stru_24);
3103 }
3104 }
3105 }
3106
3107 // INDOOR initialize actors
3108 v38 = 0;
3109 for (uint i = 0; i < uNumActors; ++i)
3110 {
3111 if (pActors[i].uAttributes & ACTOR_UNKNOW7)
3112 {
3113 if ( !map_id )
3114 {
3115 pActors[i].pMonsterInfo.field_3E = 19;
3116 pActors[i].uAttributes |= ACTOR_UNKNOW11;
3117 continue;
3118 }
3119 v28 = v38 == 0;
3120 }
3121 else
3122 v28 = v38 == 1;
3123
3124 if ( !v28 )
3125 {
3126 pActors[i].PrepareSprites(0);
3127 pActors[i].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
3128 if ( pActors[i].pMonsterInfo.field_3E != 11 && pActors[i].pMonsterInfo.field_3E != 19 && (!pActors[i].sCurrentHP || !pActors[i].pMonsterInfo.uHP) )
3129 {
3130 pActors[i].pMonsterInfo.field_3E = 5;
3131 pActors[i].UpdateAnimation();
3132 }
3133 }
3134 else
3135 {
3136 pActors[i].pMonsterInfo.field_3E = 19;
3137 pActors[i].uAttributes |= ACTOR_UNKNOW11;
3138 }
3139 }
3140
3141 pGameLoadingUI_ProgressBar->Progress();
3142
3143 //Party to start position
3144 Actor this_;
3145 this_.pMonsterInfo.uID = 45;
3146 this_.PrepareSprites(0);
3147 if ( !bLoading )
3148 {
3149 pParty->sRotationX = 0;
3150 pParty->sRotationY = 0;
3151 pParty->vPosition.z = 0;
3152 pParty->vPosition.y = 0;
3153 pParty->vPosition.x = 0;
3154 pParty->uFallStartY = 0;
3155 pParty->uFallSpeed = 0;
3156 TeleportToStartingPoint(uLevel_StartingPointType);
3157 }
3158 viewparams->_443365();
3159 PlayLevelMusic();
3160 if ( !bLoading )
3161 {
3162 v30 = 0;
3163 for ( uint pl_id = 1; pl_id <= 4; ++pl_id )
3164 {
3165 if ( pPlayers[pl_id]->CanAct() )
3166 v34[v30++] = pl_id;
3167 }
3168 if ( v30 )
3169 {
3170 if ( pDest )
3171 {
3172 _A750D8_player_speech_timer = 256i64;
3173 PlayerSpeechID = SPEECH_46;
3174 uSpeakingCharacter = v34[rand() % v30];
3175 }
3176 }
3177 }
3178 }
3179 //----- (0046CEC3) --------------------------------------------------------
3180 int BLV_GetFloorLevel(int x, int y, int z, unsigned int uSectorID, unsigned int *pFaceID)
3181 {
3182 int v13; // ecx@13
3183 signed int v14; // ebx@14
3184 int v15; // eax@16
3185 int v21; // eax@27
3186 signed int v28; // eax@45
3187 int v29; // ebx@47
3188 int v38; // edx@62
3189 bool v47; // [sp+24h] [bp-1Ch]@43
3190 bool current_vertices_Y; // [sp+28h] [bp-18h]@10
3191 bool v49; // [sp+28h] [bp-18h]@41
3192 bool next_vertices_Y; // [sp+2Ch] [bp-14h]@12
3193 signed int number_hits; // [sp+30h] [bp-10h]@10
3194 signed int v54; // [sp+30h] [bp-10h]@41
3195 signed int v55; // [sp+34h] [bp-Ch]@1
3196
3197 //LOG_DECOMPILATION_WARNING();
3198
3199 static int blv_floor_id[50]; // 00721200
3200 static int blv_floor_level[50]; // 007212C8
3201
3202 static __int16 blv_floor_face_vert_coord_Y[104]; // word_721390_ys
3203 static __int16 blv_floor_face_vert_coord_X[104]; // word_721460_xs
3204
3205 BLVSector* pSector = &pIndoor->pSectors[uSectorID];
3206 v55 = 0;
3207 for (uint i = 0; i < pSector->uNumFloors; ++i)
3208 {
3209 BLVFace* pFloor = &pIndoor->pFaces[pSector->pFloors[i]];
3210 if (pFloor->Ethereal())
3211 continue;
3212
3213 assert(pFloor->uNumVertices);
3214 if (x <= pFloor->pBounding.x2 && x >= pFloor->pBounding.x1 &&
3215 y <= pFloor->pBounding.y2 && y >= pFloor->pBounding.y1)
3216 {
3217 for (uint j = 0; j < pFloor->uNumVertices; ++j)
3218 {
3219 blv_floor_face_vert_coord_X[2 * j] = pFloor->pXInterceptDisplacements[j] + pIndoor->pVertices[pFloor->pVertexIDs[j]].x;
3220 blv_floor_face_vert_coord_X[2 * j + 1] = pFloor->pXInterceptDisplacements[j] + pIndoor->pVertices[pFloor->pVertexIDs[j + 1]].x;
3221 blv_floor_face_vert_coord_Y[2 * j] = pFloor->pYInterceptDisplacements[j] + pIndoor->pVertices[pFloor->pVertexIDs[j]].y;
3222 blv_floor_face_vert_coord_Y[2 * j + 1] = pFloor->pYInterceptDisplacements[j] + pIndoor->pVertices[pFloor->pVertexIDs[j + 1]].y;
3223 }
3224 blv_floor_face_vert_coord_X[2 * pFloor->uNumVertices] = blv_floor_face_vert_coord_X[0];
3225 blv_floor_face_vert_coord_Y[2 * pFloor->uNumVertices] = blv_floor_face_vert_coord_Y[0];
3226
3227 next_vertices_Y = blv_floor_face_vert_coord_Y[0] >= y;
3228 number_hits = 0;
3229
3230 for (uint j = 0; j < 2 * pFloor->uNumVertices; ++j)
3231 {
3232 if (number_hits >= 2)
3233 break;
3234
3235 current_vertices_Y = next_vertices_Y;
3236 next_vertices_Y = blv_floor_face_vert_coord_Y[j + 1] >= y;
3237
3238 v13 = i;
3239 if (current_vertices_Y == next_vertices_Y)
3240 continue;
3241
3242 v14 = blv_floor_face_vert_coord_X[j + 1] >= x ? 0 : 2;
3243 v15 = v14 | (blv_floor_face_vert_coord_X[j] < x);
3244
3245 if (v15 == 3)
3246 continue;
3247 else if (!v15)
3248 ++number_hits;
3249 else
3250 {
3251 long long a_div_b = fixpoint_div(y - blv_floor_face_vert_coord_Y[j], blv_floor_face_vert_coord_Y[j + 1] - blv_floor_face_vert_coord_Y[j]);
3252 long long res = fixpoint_mul((signed int)blv_floor_face_vert_coord_X[j + 1] - (signed int)blv_floor_face_vert_coord_X[j], a_div_b);
3253
3254 if (res + blv_floor_face_vert_coord_X[j] >= x)
3255 ++number_hits;
3256 }
3257 }
3258
3259
3260 if ( number_hits == 1 )
3261 {
3262 if ( v55 >= 50 )
3263 break;
3264 if ( pFloor->uPolygonType == POLYGON_Floor || pFloor->uPolygonType == POLYGON_Ceiling )
3265 v21 = pIndoor->pVertices[pFloor->pVertexIDs[0]].z;
3266 else
3267 v21 = fixpoint_mul(pFloor->zCalc1, x) + fixpoint_mul(pFloor->zCalc2, y) + (short)(pFloor->zCalc3 >> 16);
3268 blv_floor_level[v55] = v21;
3269 blv_floor_id[v55] = pSector->pFloors[i];
3270 v55++;
3271 }
3272 }
3273 }
3274
3275 if ( pSector->field_0 & 8 )
3276 {
3277 for (uint i = 0; i < pSector->uNumPortals; ++i)
3278 {
3279 BLVFace* portal = &pIndoor->pFaces[pSector->pPortals[i]];
3280 if (portal->uPolygonType != POLYGON_Floor)
3281 continue;
3282
3283 if (!portal->uNumVertices)
3284 continue;
3285
3286 if (x <= portal->pBounding.x2 && x >= portal->pBounding.x1 &&
3287 y <= portal->pBounding.y2 && y >= portal->pBounding.y1 )
3288 {
3289 for (uint j = 0; j < portal->uNumVertices; ++j)
3290 {
3291 blv_floor_face_vert_coord_X[2 * j] = portal->pXInterceptDisplacements[j] + pIndoor->pVertices[portal->pVertexIDs[j]].x;
3292 blv_floor_face_vert_coord_X[2 * j + 1] = portal->pXInterceptDisplacements[j + 1] + pIndoor->pVertices[portal->pVertexIDs[j + 1]].x;
3293 blv_floor_face_vert_coord_Y[2 * j] = portal->pYInterceptDisplacements[j] + pIndoor->pVertices[portal->pVertexIDs[j]].y;
3294 blv_floor_face_vert_coord_Y[2 * j + 1] = portal->pYInterceptDisplacements[j + 1] + pIndoor->pVertices[portal->pVertexIDs[j + 1]].y;
3295 }
3296 blv_floor_face_vert_coord_X[2 * portal->uNumVertices] = blv_floor_face_vert_coord_X[0];
3297 blv_floor_face_vert_coord_Y[2 * portal->uNumVertices] = blv_floor_face_vert_coord_Y[0];
3298 v54 = 0;
3299 v47 = blv_floor_face_vert_coord_Y[0] >= y;
3300
3301 for (uint j = 0; j < 2 * portal->uNumVertices; ++j)
3302 {
3303 v49 = v47;
3304 if ( v54 >= 2 )
3305 break;
3306 v47 = blv_floor_face_vert_coord_Y[j + 1] >= y;
3307 if ( v49 != v47 )
3308 {
3309 v28 = blv_floor_face_vert_coord_X[j + 1] >= x ? 0 : 2;
3310 v29 = v28 | (blv_floor_face_vert_coord_X[j] < x);
3311 if ( v29 != 3 )
3312 {
3313 if ( !v29 )
3314 ++v54;
3315 else
3316 {
3317 long long a_div_b = fixpoint_div(y - blv_floor_face_vert_coord_Y[j], blv_floor_face_vert_coord_Y[j + 1] - blv_floor_face_vert_coord_Y[j]);
3318 long long res = fixpoint_mul(blv_floor_face_vert_coord_X[j + 1] - blv_floor_face_vert_coord_X[j], a_div_b);
3319 if (res + blv_floor_face_vert_coord_X[j] >= x)
3320 ++v54;
3321 }
3322 }
3323 }
3324 }
3325 if ( v54 == 1 )
3326 {
3327 if ( v55 >= 50 )
3328 break;
3329 blv_floor_level[v55] = -29000;
3330 blv_floor_id[v55] = pSector->pPortals[i];
3331 v55++;
3332 }
3333 }
3334 }
3335 }
3336 if ( v55 == 1 )
3337 {
3338 *pFaceID = blv_floor_id[0];
3339 if ( blv_floor_level[0] <= -29000 )
3340 __debugbreak();
3341 return blv_floor_level[0];
3342 }
3343 if ( !v55 )
3344 return -30000;
3345 *pFaceID = blv_floor_id[0];
3346 //result = blv_floor_level[0];
3347
3348 /*for ( v35 = 1; v35 < v55; ++v35 )
3349 {
3350 if ( blv_floor_level[0] <= z + 5 )
3351 {
3352 if ( blv_floor_level[v35] >= blv_floor_level[0] || blv_floor_level[v35] > z + 5 )
3353 continue;
3354 blv_floor_level[0] = blv_floor_level[v35];
3355 *pFaceID = blv_floor_id[v35];
3356 continue;
3357 }
3358 if ( blv_floor_level[v35] < blv_floor_level[0] )
3359 {
3360 blv_floor_level[0] = blv_floor_level[v35];
3361 *pFaceID = blv_floor_id[v35];
3362 }
3363 }*/
3364
3365
3366 int result = blv_floor_level[0];
3367 for (uint i = 1; i < v55; ++i)
3368 {
3369 v38 = blv_floor_level[i];
3370 if ( result <= z + 5 )
3371 {
3372 if ( v38 > result && v38 <= z + 5 )
3373 {
3374 result = blv_floor_level[i];
3375 if ( blv_floor_level[i] <= -29000 )
3376 __debugbreak();
3377 *pFaceID = blv_floor_id[i];
3378 }
3379 }
3380 else if ( v38 < result )
3381 {
3382 result = blv_floor_level[i];
3383 if ( blv_floor_level[i] <= -29000 )
3384 __debugbreak();
3385 *pFaceID = blv_floor_id[i];
3386 }
3387 }
3388
3389 return result;
3390 }
3391 //----- (0043FDED) --------------------------------------------------------
3392 void PrepareActorRenderList_BLV()
3393 {
3394 unsigned int v4; // eax@5
3395 int v6; // esi@5
3396 int v8; // eax@10
3397 SpriteFrame *v9; // eax@16
3398 int v12; // ecx@28
3399 signed __int64 v18; // qtt@36
3400 int v25; // edx@44
3401 __int16 v26; // ax@44
3402 int a5a; // [sp+2Ch] [bp-28h]@36
3403 __int16 v41; // [sp+3Ch] [bp-18h]@18
3404 int a6; // [sp+40h] [bp-14h]@34
3405 int v43; // [sp+44h] [bp-10h]@34
3406 int z; // [sp+48h] [bp-Ch]@32
3407 signed int y; // [sp+4Ch] [bp-8h]@32
3408 int x; // [sp+50h] [bp-4h]@32
3409
3410 for (uint i = 0; i < uNumActors; ++i)
3411 {
3412 if (pActors[i].uAIState == Removed || pActors[i].uAIState == Disabled)
3413 continue;
3414
3415 v4 = stru_5C6E00->Atan2(pActors[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x, pActors[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
3416 v6 = ((signed int)(pActors[i].uYawAngle + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v4 + stru_5C6E00->uIntegerPi) >> 8) & 7;
3417 v8 = pActors[i].uCurrentActionTime;
3418 if ( pParty->bTurnBasedModeOn )
3419 {
3420 if ( pActors[i].uCurrentActionAnimation == 1 )
3421 v8 = i * 32 + pMiscTimer->uTotalGameTimeElapsed;
3422 }
3423 else
3424 {
3425 if ( pActors[i].uCurrentActionAnimation == 1 )
3426 v8 = i * 32 + pBLVRenderParams->field_0_timer_;
3427 }
3428 if (pActors[i].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 || pActors[i].pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0 )
3429 v8 = 0;
3430
3431 if (pActors[i].uAIState == Resurrected)
3432 v9 = pSpriteFrameTable->GetFrameBy_x(pActors[i].pSpriteIDs[pActors[i].uCurrentActionAnimation], v8);
3433 else
3434 v9 = pSpriteFrameTable->GetFrame(pActors[i].pSpriteIDs[pActors[i].uCurrentActionAnimation], v8);
3435
3436 v41 = 0;
3437 if (v9->uFlags & 2)
3438 v41 = 2;
3439 if (v9->uFlags & 0x40000)
3440 v41 |= 0x40u;
3441 if (v9->uFlags & 0x20000)
3442 LOBYTE(v41) = v41 | 0x80;
3443 if ( (256 << v6) & v9->uFlags)
3444 v41 |= 4;
3445 if ( v9->uGlowRadius )
3446 {
3447 //LOBYTE(v11) = _4E94D3_light_type;
3448 pMobileLightsStack->AddLight(pActors[i].vPosition.x, pActors[i].vPosition.y, pActors[i].vPosition.z, pActors[i].uSectorID, v9->uGlowRadius, 0xFFu, 0xFFu, 0xFFu, _4E94D3_light_type);
3449 }
3450 for ( v12 = 0; v12 < pBspRenderer->uNumVisibleNotEmptySectors; ++v12 )
3451 {
3452 if ( pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v12] == pActors[i].uSectorID )
3453 {
3454 if ( !pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pActors[i].vPosition.x, pActors[i].vPosition.y, pActors[i].vPosition.z, &x, &y, &z, 1)
3455 || abs(x) < abs(y) )
3456 continue;
3457 pGame->pIndoorCameraD3D->Project(x, y, z, &v43, &a6);
3458 if (uNumBillboardsToDraw >= 500)
3459 break;
3460 ++uNumBillboardsToDraw;
3461 ++uNumSpritesDrawnThisFrame;
3462 pActors[i].uAttributes |= ACTOR_UNKNOW2;
3463 pBillboardRenderList[uNumBillboardsToDraw - 1].HwSpriteID = v9->pHwSpriteIDs[v6];
3464 pBillboardRenderList[uNumBillboardsToDraw - 1].uPalette = v9->uPaletteIndex;
3465 pBillboardRenderList[uNumBillboardsToDraw - 1].uIndoorSectorID = pActors[i].uSectorID;
3466 /*if ( !pRenderer->pRenderD3D )
3467 {
3468 LODWORD(v20) = pBLVRenderParams->fov_rad_fixpoint << 16;
3469 HIDWORD(v20) = pBLVRenderParams->fov_rad_fixpoint >> 16;
3470 v0->_screenspace_x_scaler_packedfloat = fixpoint_mul(v10->scale, v20 / x);
3471 a5a = fixpoint_mul(v10->scale, v20 / x);
3472 }
3473 else
3474 {*/
3475 pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pGame->pIndoorCameraD3D->fov_x;
3476 pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pGame->pIndoorCameraD3D->fov_y;
3477 LODWORD(v18) = 0;
3478 HIDWORD(v18) = floorf(pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x + 0.5f);
3479 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v9->scale, v18 / x);
3480 a5a = fixpoint_mul(v9->scale, v18 / x);
3481 //}
3482 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = a5a;
3483 if ( pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0 )
3484 {
3485 if ( pActors[i].pActorBuffs[ACTOR_BUFF_MASS_DISTORTION].uExpireTime > 0 )
3486 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(pGame->pStru6Instance->_4A806F(&pActors[i]),
3487 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat);
3488 }
3489 else
3490 {
3491 if ( pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uPower > 0 )
3492 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(65536 / pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uPower, pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat);
3493 }
3494 HIWORD(v25) = HIWORD(x);
3495 pBillboardRenderList[uNumBillboardsToDraw - 1].world_x = pActors[i].vPosition.x;
3496 pBillboardRenderList[uNumBillboardsToDraw - 1].world_y = pActors[i].vPosition.y;
3497 pBillboardRenderList[uNumBillboardsToDraw - 1].world_z = pActors[i].vPosition.z;
3498 pBillboardRenderList[uNumBillboardsToDraw - 1].uScreenSpaceX = v43;
3499 pBillboardRenderList[uNumBillboardsToDraw - 1].uScreenSpaceY = a6;
3500 LOWORD(v25) = 0;
3501 LOBYTE(v26) = v41;
3502
3503 //v0->sZValue = v25 + (PID(OBJECT_Actor,i));
3504 pBillboardRenderList[uNumBillboardsToDraw - 1].actual_z = HIWORD(x);
3505 pBillboardRenderList[uNumBillboardsToDraw - 1].object_pid = PID(OBJECT_Actor,i);
3506
3507 //v29 = HIDWORD(p->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime) == 0;
3508 //v30 = HIDWORD(p->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime) < 0;
3509 pBillboardRenderList[uNumBillboardsToDraw - 1].field_1E = v41;
3510 pBillboardRenderList[uNumBillboardsToDraw - 1].pSpriteFrame = v9;
3511 pBillboardRenderList[uNumBillboardsToDraw - 1].sTintColor = pMonsterList->pMonsters[pActors[i].pMonsterInfo.uID - 1].sTintColor;
3512 if ( pActors[i].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 )
3513 {
3514 HIBYTE(v26) = HIBYTE(v41) | 1;
3515 pBillboardRenderList[uNumBillboardsToDraw - 1].field_1E = v26;
3516 }
3517 }
3518 }
3519 }
3520 }
3521 //----- (0044028F) --------------------------------------------------------
3522 void PrepareItemsRenderList_BLV()
3523 {
3524 SpriteFrame *v4; // eax@12
3525 unsigned int v6; // eax@12
3526 int v7; // ecx@12
3527 int v9; // ecx@12
3528 __int64 v18; // ST5C_4@27
3529 int a6; // [sp+2Ch] [bp-30h]@12
3530 int v31; // [sp+38h] [bp-24h]@27
3531 signed __int16 v34; // [sp+44h] [bp-18h]@14
3532 int v35; // [sp+48h] [bp-14h]@25
3533 int v36; // [sp+4Ch] [bp-10h]@25
3534 signed int z; // [sp+50h] [bp-Ch]@24
3535 signed int y; // [sp+54h] [bp-8h]@24
3536 signed int x; // [sp+58h] [bp-4h]@24
3537
3538 for (uint i = 0; i < uNumSpriteObjects; ++i)
3539 {
3540 if (pSpriteObjects[i].uObjectDescID)
3541 {
3542 if ( !(pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uFlags & 1) )
3543 {
3544 if ( ( pSpriteObjects[i].uType < 1000 || pSpriteObjects[i].uType >= 10000)
3545 && (pSpriteObjects[i].uType < 500 || pSpriteObjects[i].uType >= 600)
3546 && (pSpriteObjects[i].uType < 811 || pSpriteObjects[i].uType >= 815)
3547 || pGame->pStru6Instance->_4A81CA(&pSpriteObjects[i]))
3548 {
3549 v4 = pSpriteFrameTable->GetFrame(pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uSpriteID, pSpriteObjects[i].uSpriteFrameID);
3550 a6 = v4->uGlowRadius * pSpriteObjects[i].field_22_glow_radius_multiplier;
3551 v6 = stru_5C6E00->Atan2(pSpriteObjects[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
3552 pSpriteObjects[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
3553 LOWORD(v7) = pSpriteObjects[i].uFacing;
3554 v9 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v7 - v6) >> 8) & 7;
3555 pBillboardRenderList[uNumBillboardsToDraw].HwSpriteID = v4->pHwSpriteIDs[v9];
3556 if ( v4->uFlags & 0x20 )
3557 pSpriteObjects[i].vPosition.z -= (signed int)(fixpoint_mul(v4->scale, pSprites_LOD->pSpriteHeaders[pBillboardRenderList[uNumBillboardsToDraw].HwSpriteID].uHeight) / 2);
3558
3559 v34 = 0;
3560 if ( v4->uFlags & 2 )
3561 v34 = 2;
3562 if ( v4->uFlags & 0x40000 )
3563 v34 |= 0x40u;
3564 if ( v4->uFlags & 0x20000 )
3565 LOBYTE(v34) = v34 | 0x80;
3566 //v11 = (int *)(256 << v9);
3567 if ( (256 << v9) & v4->uFlags )
3568 v34 |= 4;
3569 if ( a6 )
3570 {
3571 //LOBYTE(v11) = _4E94D3_light_type;
3572 pMobileLightsStack->AddLight(pSpriteObjects[i].vPosition.x, pSpriteObjects[i].vPosition.y, pSpriteObjects[i].vPosition.z,
3573 pSpriteObjects[i].uSectorID, a6, pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uParticleTrailColorR,
3574 pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uParticleTrailColorG,
3575 pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uParticleTrailColorB, _4E94D3_light_type);
3576 }
3577 if ( pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pSpriteObjects[i].vPosition.x, pSpriteObjects[i].vPosition.y,
3578 pSpriteObjects[i].vPosition.z, &x, &y, &z, 1) )
3579 {
3580 pGame->pIndoorCameraD3D->Project(x, y, z, &v36, &v35);
3581
3582 assert(uNumBillboardsToDraw < 500);
3583 //if ( (signed int)uNumBillboardsToDraw >= 500 )
3584 // return;
3585 ++uNumBillboardsToDraw;
3586 ++uNumSpritesDrawnThisFrame;
3587 pSpriteObjects[i].uAttributes |= 1;
3588 pBillboardRenderList[uNumBillboardsToDraw - 1].uPalette = v4->uPaletteIndex;
3589 pBillboardRenderList[uNumBillboardsToDraw - 1].uIndoorSectorID = pSpriteObjects[i].uSectorID;
3590 //if ( pRenderer->pRenderD3D )
3591 {
3592 pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pGame->pIndoorCameraD3D->fov_x;
3593 pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pGame->pIndoorCameraD3D->fov_y;
3594 LODWORD(v18) = 0;
3595 HIDWORD(v18) = (int)floorf(pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x + 0.5f);
3596 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v4->scale, v18 / x);
3597 v31 = fixpoint_mul(v4->scale, v18 / x);
3598 }
3599 /*else
3600 {
3601 __debugbreak(); // sw rendering
3602 LODWORD(v19) = pBLVRenderParams->field_40 << 16;
3603 HIDWORD(v19) = pBLVRenderParams->field_40 >> 16;
3604 v20 = v19 / x;
3605 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v24->scale, v19 / x);
3606 v31 = fixpoint_mul(v24->scale, v20);
3607 }*/
3608 //HIWORD(v21) = HIWORD(x);
3609 //LOWORD(v21) = 0;
3610 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = v31;
3611 pBillboardRenderList[uNumBillboardsToDraw - 1].field_1E = v34;
3612 pBillboardRenderList[uNumBillboardsToDraw - 1].world_x = pSpriteObjects[i].vPosition.x;
3613 pBillboardRenderList[uNumBillboardsToDraw - 1].world_y = pSpriteObjects[i].vPosition.y;
3614 pBillboardRenderList[uNumBillboardsToDraw - 1].world_z = pSpriteObjects[i].vPosition.z;
3615 pBillboardRenderList[uNumBillboardsToDraw - 1].uScreenSpaceX = v36;
3616 pBillboardRenderList[uNumBillboardsToDraw - 1].sTintColor = 0;
3617 pBillboardRenderList[uNumBillboardsToDraw - 1].uScreenSpaceY = v35;
3618 //v23 = 8 * i;
3619 //LOBYTE(v23) = PID(OBJECT_Item,i);
3620 pBillboardRenderList[uNumBillboardsToDraw - 1].pSpriteFrame = v4;
3621 //v12 = (p->uAttributes & 0x20) == 0;
3622 //pBillboardRenderList[uNumBillboardsToDraw - 1].sZValue = v21 + v23;
3623 pBillboardRenderList[uNumBillboardsToDraw - 1].actual_z = HIWORD(x);
3624 pBillboardRenderList[uNumBillboardsToDraw - 1].object_pid = PID(OBJECT_Item,i);
3625 /*if (pSpriteObjects[i].uAttributes & 0x20)
3626 {
3627 if ( !pRenderer->pRenderD3D )
3628 pBillboardRenderList[uNumBillboardsToDraw - 1].sZValue = 0;
3629 }*/
3630 }
3631 }
3632 }
3633 }
3634 }
3635 }
3636
3637 //----- (00440639) --------------------------------------------------------
3638 void AddBspNodeToRenderList(unsigned int node_id)
3639 {
3640 BLVSector *pSector; // esi@1
3641
3642 pSector = &pIndoor->pSectors[pBspRenderer->nodes[node_id].uSectorID];
3643 //if ( pRenderer->pRenderD3D )
3644 {
3645 for (uint i = 0; i < pSector->uNumNonBSPFaces; ++i)
3646 //Log::Warning(L"Non-BSP face: %X", v3->pFaceIDs[v2]);
3647 pBspRenderer->AddFaceToRenderList_d3d(node_id, pSector->pFaceIDs[i]);//рекурсия\recursion
3648 }
3649 /*else
3650 {
3651 for (uint i = 0; i < pSector->uNumNonBSPFaces; ++i)
3652 pBspRenderer->AddFaceToRenderList_sw(node_id, pSector->pFaceIDs[i]);
3653 }*/
3654 if ( pSector->field_0 & 0x10 )
3655 sub_4406BC(node_id, pSector->uFirstBSPNode);
3656 }
3657
3658 //----- (004406BC) --------------------------------------------------------
3659 void __fastcall sub_4406BC(unsigned int node_id, unsigned int uFirstNode)
3660 {
3661 BLVSector *pSector; // esi@2
3662 BSPNode *pNode; // edi@2
3663 BLVFace *pFace; // eax@2
3664 int v5; // ecx@2
3665 __int16 v6; // ax@6
3666 int v7; // ebp@10
3667 int v8; // ebx@10
3668 __int16 v9; // di@18
3669 BspRenderer_stru0 *node; // [sp+18h] [bp-4h]@1
3670
3671 //Log::Warning(L"sub_4406BC(%u, %u)", a1, uFirstNode);
3672
3673 //v10 = a1;
3674 node = &pBspRenderer->nodes[node_id];
3675 while ( 1 )
3676 {
3677 pSector = &pIndoor->pSectors[node->uSectorID];
3678 pNode = &pIndoor->pNodes[uFirstNode];
3679 pFace = &pIndoor->pFaces[pSector->pFaceIDs[pNode->uCoplanarOffset]];
3680 v5 = pFace->pFacePlane_old.dist +
3681 pGame->pIndoorCameraD3D->vPartyPos.x * pFace->pFacePlane_old.vNormal.x +
3682 pGame->pIndoorCameraD3D->vPartyPos.y * pFace->pFacePlane_old.vNormal.y +
3683 pGame->pIndoorCameraD3D->vPartyPos.z * pFace->pFacePlane_old.vNormal.z;//plane equation
3684 if (pFace->Portal() && pFace->uSectorID != node->uSectorID )
3685 v5 = -v5;
3686 //v11 = v5 > 0;
3687 if ( v5 <= 0 )
3688 v6 = pNode->uFront;
3689 else
3690 v6 = pNode->uBack;
3691 if ( v6 != -1 )
3692 sub_4406BC(node_id, v6);
3693 v7 = pNode->uCoplanarOffset;
3694 v8 = v7 + pNode->uCoplanarSize;
3695
3696 //Log::Warning(L"Node %u: %X to %X (%hX)", uFirstNode, v7, v8, v2->pFaceIDs[v7]);
3697
3698 //if ( pRenderer->pRenderD3D )
3699 {
3700 while ( v7 < v8 )
3701 pBspRenderer->AddFaceToRenderList_d3d(node_id, pSector->pFaceIDs[v7++]);
3702 }
3703 /*else
3704 {
3705 while ( v7 < v8 )
3706 pBspRenderer->AddFaceToRenderList_sw(node_id, pSector->pFaceIDs[v7++]);
3707 }*/
3708 v9 = v5 > 0 ? pNode->uFront : pNode->uBack;
3709 if ( v9 == -1 )
3710 break;
3711 uFirstNode = v9;
3712 }
3713 }
3714 //----- (0043FA33) --------------------------------------------------------
3715 void PrepareDecorationsRenderList_BLV(unsigned int uDecorationID, unsigned int uSectorID)
3716 {
3717 unsigned int v8; // edi@5
3718 int v9; // edi@5
3719 int v10; // eax@7
3720 SpriteFrame *v11; // eax@7
3721 signed __int64 v20; // qtt@19
3722 Particle_sw particle; // [sp+Ch] [bp-A0h]@3
3723 int v30; // [sp+8Ch] [bp-20h]@7
3724 int a5; // [sp+94h] [bp-18h]@17
3725 int z; // [sp+98h] [bp-14h]@15
3726 int a6; // [sp+9Ch] [bp-10h]@17
3727 int y; // [sp+A0h] [bp-Ch]@15
3728 int x; // [sp+A4h] [bp-8h]@15
3729 int v37; // [sp+A8h] [bp-4h]@5
3730
3731 if (pLevelDecorations[uDecorationID].uFlags & LEVEL_DECORATION_INVISIBLE)
3732 return;
3733
3734 if (pDecorationList->pDecorations[pLevelDecorations[uDecorationID].uDecorationDescID].uFlags & DECORATION_DESC_EMITS_FIRE)
3735 {
3736 memset(&particle, 0, sizeof(particle)); // fire, like at the Pit's tavern
3737 particle.type = ParticleType_Bitmap | ParticleType_Rotating | ParticleType_8;
3738 particle.uDiffuse = 0xFF3C1E;
3739 particle.x = (double)pLevelDecorations[uDecorationID].vPosition.x;
3740 particle.y = (double)pLevelDecorations[uDecorationID].vPosition.y;
3741 particle.z = (double)pLevelDecorations[uDecorationID].vPosition.z;
3742 particle.r = 0.0;
3743 particle.g = 0.0;
3744 particle.b = 0.0;
3745 particle.flt_28 = 1.0;
3746 particle.timeToLive = (rand() & 0x80) + 128;
3747 particle.uTextureID = pBitmaps_LOD->LoadTexture("effpar01");
3748 pGame->pParticleEngine->AddParticle(&particle);
3749 return;
3750 }
3751
3752 if (pDecorationList->pDecorations[pLevelDecorations[uDecorationID].uDecorationDescID].uFlags & DECORATION_DESC_DONT_DRAW)
3753 return;
3754
3755 v8 = pLevelDecorations[uDecorationID].field_10_y_rot + ((signed int)stru_5C6E00->uIntegerPi >> 3)
3756 - stru_5C6E00->Atan2(pLevelDecorations[uDecorationID].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
3757 pLevelDecorations[uDecorationID].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
3758 v9 = ((signed int)(stru_5C6E00->uIntegerPi + v8) >> 8) & 7;
3759 v37 = pBLVRenderParams->field_0_timer_;
3760 if (pParty->bTurnBasedModeOn)
3761 v37 = pMiscTimer->uTotalGameTimeElapsed;
3762 v10 = abs(pLevelDecorations[uDecorationID].vPosition.x + pLevelDecorations[uDecorationID].vPosition.y);
3763 v11 = pSpriteFrameTable->GetFrame(pDecorationList->pDecorations[pLevelDecorations[uDecorationID].uDecorationDescID].uSpriteID, v37 + v10);
3764 v30 = 0;
3765 if ( v11->uFlags & 2 )
3766 v30 = 2;
3767 if ( v11->uFlags & 0x40000 )
3768 v30 |= 0x40u;
3769 if ( v11->uFlags & 0x20000 )
3770 LOBYTE(v30) = v30 | 0x80;
3771 if ( (256 << v9) & v11->uFlags )
3772 v30 |= 4;
3773 if ( pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pLevelDecorations[uDecorationID].vPosition.x,
3774 pLevelDecorations[uDecorationID].vPosition.y,
3775 pLevelDecorations[uDecorationID].vPosition.z, &x, &y, &z, 1) )
3776 {
3777 if ( abs(x) >= abs(y) )
3778 {
3779 pGame->pIndoorCameraD3D->Project(x, y, z, &a5, &a6);
3780
3781 assert(uNumBillboardsToDraw < 500);
3782
3783 ++uNumBillboardsToDraw;
3784 ++uNumDecorationsDrawnThisFrame;
3785 pBillboardRenderList[uNumBillboardsToDraw - 1].HwSpriteID = v11->pHwSpriteIDs[v9];
3786 pBillboardRenderList[uNumBillboardsToDraw - 1].uPalette = v11->uPaletteIndex;
3787 pBillboardRenderList[uNumBillboardsToDraw - 1].uIndoorSectorID = uSectorID;
3788 /*if ( !pRenderer->pRenderD3D )
3789 {
3790 LODWORD(v21) = pBLVRenderParams->fov_rad_fixpoint << 16;
3791 HIDWORD(v21) = pBLVRenderParams->fov_rad_fixpoint >> 16;
3792 //LODWORD(v31) = v12->scale;
3793 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v12->scale, v21 / x);
3794 v37 = fixpoint_mul(v12->scale, v21 / x);
3795 }
3796 else
3797 {*/
3798 pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pGame->pIndoorCameraD3D->fov_x;
3799 pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pGame->pIndoorCameraD3D->fov_y;
3800 LODWORD(v20) = 0;
3801 HIDWORD(v20) = floorf(pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x + 0.5f);
3802 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v11->scale, v20 / x);
3803 LODWORD(v20) = 0;
3804 HIDWORD(v20) = floorf(pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y + 0.5f);
3805 v37 = fixpoint_mul(v11->scale, v20 / x);
3806 //}
3807 //HIWORD(v22) = HIWORD(x);
3808 //LOWORD(v22) = 0;
3809 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = v37;
3810 pBillboardRenderList[uNumBillboardsToDraw - 1].field_1E = v30;
3811 pBillboardRenderList[uNumBillboardsToDraw - 1].world_x = pLevelDecorations[uDecorationID].vPosition.x;
3812 pBillboardRenderList[uNumBillboardsToDraw - 1].world_y = pLevelDecorations[uDecorationID].vPosition.y;
3813 pBillboardRenderList[uNumBillboardsToDraw - 1].world_z = pLevelDecorations[uDecorationID].vPosition.z;
3814 pBillboardRenderList[uNumBillboardsToDraw - 1].uScreenSpaceX = a5;
3815 pBillboardRenderList[uNumBillboardsToDraw - 1].uScreenSpaceY = a6;
3816 //v23 = 8 * uDecorationID;
3817 //LOBYTE(v23) = PID(OBJECT_Decoration,uDecorationID);
3818
3819 //pBillboardRenderList[uNumBillboardsToDraw - 1].sZValue = v22 + v23;
3820 pBillboardRenderList[uNumBillboardsToDraw - 1].actual_z = HIWORD(x);
3821 pBillboardRenderList[uNumBillboardsToDraw - 1].object_pid = PID(OBJECT_Decoration,uDecorationID);
3822
3823 pBillboardRenderList[uNumBillboardsToDraw - 1].sTintColor = 0;
3824 pBillboardRenderList[uNumBillboardsToDraw - 1].pSpriteFrame = v11;
3825 }
3826 }
3827 }
3828 //----- (0043F953) --------------------------------------------------------
3829 void PrepareBspRenderList_BLV()
3830 {
3831 pBspRenderer->num_faces = 0;
3832
3833 if (pBLVRenderParams->uPartySectorID)
3834 {
3835 pBspRenderer->nodes[0].uSectorID = pBLVRenderParams->uPartySectorID;
3836 pBspRenderer->nodes[0].uViewportW = pBLVRenderParams->uViewportW;
3837 pBspRenderer->nodes[0].uViewportZ = pBLVRenderParams->uViewportZ;
3838 pBspRenderer->nodes[0].uViewportY = pBLVRenderParams->uViewportY;
3839 pBspRenderer->nodes[0].uViewportX = pBLVRenderParams->uViewportX;
3840 pBspRenderer->nodes[0].PortalScreenData.GetViewportData(pBLVRenderParams->uViewportX, pBLVRenderParams->uViewportY,
3841 pBLVRenderParams->uViewportZ, pBLVRenderParams->uViewportW);
3842 pBspRenderer->nodes[0].uFaceID = -1;
3843 pBspRenderer->nodes[0].viewing_portal_id = -1;
3844 pBspRenderer->num_nodes = 1;
3845 AddBspNodeToRenderList(0);
3846 }
3847
3848 pBspRenderer->MakeVisibleSectorList();
3849 }
3850
3851 //----- (0043F9E1) --------------------------------------------------------
3852 void BspRenderer_PortalViewportData::GetViewportData(__int16 x, int y, __int16 z, int w)
3853 {
3854 _viewport_space_y = y;
3855 _viewport_space_w = w;
3856
3857 for (uint i = 0; i < window->GetHeight(); ++i)
3858 {
3859 if ( i < y || i > w )
3860 {
3861 viewport_left_side[i] = window->GetWidth();
3862 viewport_right_side[i] = -1;
3863 }
3864 else
3865 {
3866 viewport_left_side[i] = x;
3867 viewport_right_side[i] = z;
3868 }
3869 }
3870 }
3871 //----- (0048653D) --------------------------------------------------------
3872 void stru149::_48653D_frustum_blv(int a2, int a3, int a4, int a5, int a6, int a7)//portal frustum culling
3873 {
3874 int v8; // edi@1
3875 int v9; // eax@1
3876 int v16; // ST14_4@3
3877 int v17; // ST10_4@3
3878 int v19; // ST10_4@6
3879 int v21; // ST10_4@9
3880 int v28; // [sp+1Ch] [bp-Ch]@1
3881 int v29; // [sp+24h] [bp-4h]@1
3882
3883 v8 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
3884 v29 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
3885 v28 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX);
3886 v9 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
3887 //v11 = -pBLVRenderParams->vPartyPos.y;
3888 //v26 = -pBLVRenderParams->vPartyPos.x;
3889 //v27 = v9;
3890 //v12 = -pBLVRenderParams->vPartyPos.z;
3891 if (pGame->pIndoorCameraD3D->sRotationX)
3892 {
3893 v16 = v8 * -pGame->pIndoorCameraD3D->vPartyPos.x + v29 * -pGame->pIndoorCameraD3D->vPartyPos.y;
3894 v17 = -65536 * pGame->pIndoorCameraD3D->vPartyPos.z;
3895 this->field_0_party_dir_x = fixpoint_mul(v16, v28) + fixpoint_mul((-pGame->pIndoorCameraD3D->vPartyPos.z) << 16, v9);
3896 this->field_4_party_dir_y = v8 * -pGame->pIndoorCameraD3D->vPartyPos.y - v29 * -pGame->pIndoorCameraD3D->vPartyPos.x;
3897 this->field_8_party_dir_z = fixpoint_mul(v17, v28) - fixpoint_mul(v16, v9);
3898 }
3899 else
3900 {
3901 this->field_0_party_dir_x = v8 * -pGame->pIndoorCameraD3D->vPartyPos.x + v29 * -pGame->pIndoorCameraD3D->vPartyPos.y;
3902 this->field_4_party_dir_y = v8 * -pGame->pIndoorCameraD3D->vPartyPos.y - v29 * -pGame->pIndoorCameraD3D->vPartyPos.x;
3903 this->field_8_party_dir_z = (-pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
3904 }
3905
3906 if (pGame->pIndoorCameraD3D->sRotationX)
3907 {
3908 v19 = fixpoint_mul(a2, v8) + fixpoint_mul(a3, v29);
3909
3910 this->angle_from_north = fixpoint_mul(v19, v28) + fixpoint_mul(a4, v9);
3911 this->angle_from_west = fixpoint_mul(a3, v8) - fixpoint_mul(a2, v29);
3912 this->viewing_angle_from_west_east = fixpoint_mul(a4, v28) - fixpoint_mul(v19, v9);
3913 }
3914 else
3915 {
3916 this->angle_from_north = fixpoint_mul(a2, v8) + fixpoint_mul(a3, v29);
3917 this->angle_from_west = fixpoint_mul(a3, v8) - fixpoint_mul(a2, v29);
3918 this->viewing_angle_from_west_east = a4;
3919 }
3920
3921 if (pGame->pIndoorCameraD3D->sRotationX)
3922 {
3923 v21 = fixpoint_mul(a5, v8) + fixpoint_mul(a6, v29);
3924
3925 this->angle_from_east = fixpoint_mul(v21, v28) + fixpoint_mul(a7, v9);
3926 this->angle_from_south = fixpoint_mul(a6, v8) - fixpoint_mul(a5, v29);
3927 this->viewing_angle_from_north_south = fixpoint_mul(a7, v28) - fixpoint_mul(v21, v9);
3928 }
3929 else
3930 {
3931 this->angle_from_east = fixpoint_mul(a5, v8) + fixpoint_mul(a6, v29);
3932 this->angle_from_south = fixpoint_mul(a6, v8) - fixpoint_mul(a5, v29);
3933 this->viewing_angle_from_north_south = a7;
3934 }
3935
3936 this->angle_from_east = -this->angle_from_east;
3937 this->angle_from_south = -this->angle_from_south;
3938 this->viewing_angle_from_north_south = -this->viewing_angle_from_north_south;
3939
3940 this->field_24 = fixpoint_dot(this->angle_from_north, this->field_0_party_dir_x,
3941 this->angle_from_west, this->field_4_party_dir_y,
3942 this->viewing_angle_from_west_east, this->field_8_party_dir_z);
3943 this->field_28 = fixpoint_dot(this->angle_from_east, this->field_0_party_dir_x,
3944 this->angle_from_south, this->field_4_party_dir_y,
3945 this->viewing_angle_from_north_south, this->field_8_party_dir_z);
3946 }
3947 //----- (00407A1C) --------------------------------------------------------
3948 bool __fastcall sub_407A1C(int x, int y, int z, Vec3_int_ v)
3949 {
3950 unsigned int v4; // esi@1
3951 int dist_y; // edi@2
3952 int dist_z; // ebx@2
3953 int dist_x; // esi@2
3954 signed int v9; // ecx@2
3955 int v10; // eax@2
3956 int v12; // eax@4
3957 int v17; // ST34_4@25
3958 int v18; // ST38_4@25
3959 int v19; // eax@25
3960 char v20; // zf@25
3961 signed int v21; // ebx@25
3962 signed int v23; // edi@26
3963 int v24; // ST34_4@30
3964 signed int v32; // ecx@37
3965 int v33; // eax@37
3966 int v35; // eax@39
3967 ODMFace *odm_face; // esi@54
3968 signed int v40; // ebx@60
3969 signed int v42; // edi@61
3970 signed int v49; // ecx@73
3971 int v50; // eax@73
3972 int v51; // edx@75
3973 int v52; // ecx@75
3974 int v53; // eax@75
3975 int v59; // eax@90
3976 BLVFace *face; // esi@91
3977 int v63; // ST34_4@98
3978 int v64; // ST30_4@98
3979 int v65; // eax@98
3980 signed int v66; // ebx@98
3981 signed int v68; // edi@99
3982 int v69; // ST2C_4@103
3983 signed int v77; // ecx@111
3984 int v78; // eax@111
3985 int v79; // edx@113
3986 int v80; // ecx@113
3987 int v81; // eax@113
3988 int v87; // ecx@128
3989 signed int v91; // ebx@136
3990 signed int v93; // edi@137
3991 Vec3_int_ v97; // [sp-18h] [bp-94h]@1
3992 int v107; // [sp+10h] [bp-6Ch]@98
3993 int v108; // [sp+10h] [bp-6Ch]@104
3994 int v109; // [sp+18h] [bp-64h]@25
3995 int v110; // [sp+18h] [bp-64h]@31
3996 signed int v113; // [sp+20h] [bp-5Ch]@1
3997 signed int v114; // [sp+24h] [bp-58h]@1
3998 int v119; // [sp+34h] [bp-48h]@75
3999 int v120; // [sp+34h] [bp-48h]@113
4000 int v121; // [sp+38h] [bp-44h]@4
4001 int v122; // [sp+38h] [bp-44h]@39
4002 int v123; // [sp+38h] [bp-44h]@76
4003 int v124; // [sp+38h] [bp-44h]@114
4004 int v125; // [sp+3Ch] [bp-40h]@4
4005 int v126; // [sp+3Ch] [bp-40h]@39
4006 int v127; // [sp+3Ch] [bp-40h]@77
4007 int v128; // [sp+3Ch] [bp-40h]@115
4008 int v129; // [sp+40h] [bp-3Ch]@11
4009 int v130; // [sp+40h] [bp-3Ch]@46
4010 int v131; // [sp+40h] [bp-3Ch]@78
4011 int v132; // [sp+40h] [bp-3Ch]@116
4012 int v133; // [sp+44h] [bp-38h]@10
4013 int v134; // [sp+44h] [bp-38h]@45
4014 int v135; // [sp+44h] [bp-38h]@81
4015 int v136; // [sp+44h] [bp-38h]@119
4016 int v137; // [sp+48h] [bp-34h]@7
4017 int v138; // [sp+48h] [bp-34h]@42
4018 int v139; // [sp+48h] [bp-34h]@82
4019 int v140; // [sp+48h] [bp-34h]@120
4020 int v141; // [sp+4Ch] [bp-30h]@6
4021 int v142; // [sp+4Ch] [bp-30h]@41
4022 int v143; // [sp+4Ch] [bp-30h]@75
4023 int v144; // [sp+4Ch] [bp-30h]@113
4024 int v145; // [sp+50h] [bp-2Ch]@5
4025 int v146; // [sp+50h] [bp-2Ch]@40
4026 int v149; // [sp+54h] [bp-28h]@4
4027 int v150; // [sp+54h] [bp-28h]@39
4028 int sDepthb; // [sp+58h] [bp-24h]@90
4029 signed int a5b; // [sp+5Ch] [bp-20h]@83
4030 signed int a5c; // [sp+5Ch] [bp-20h]@121
4031 int v162; // [sp+60h] [bp-1Ch]@128
4032 int outz; // [sp+64h] [bp-18h]@2
4033 int outx; // [sp+68h] [bp-14h]@2
4034 int outy; // [sp+6Ch] [bp-10h]@2
4035 int sZ; // [sp+70h] [bp-Ch]@2
4036 int sX; // [sp+74h] [bp-8h]@2
4037 int sY; // [sp+78h] [bp-4h]@2
4038 //8bytes unused
4039 int ya; // [sp+84h] [bp+8h]@60
4040 int yb; // [sp+84h] [bp+8h]@136
4041 int ve; // [sp+88h] [bp+Ch]@60
4042 int va; // [sp+88h] [bp+Ch]@60
4043 int vb; // [sp+88h] [bp+Ch]@66
4044 int vf; // [sp+88h] [bp+Ch]@136
4045 int vc; // [sp+88h] [bp+Ch]@136
4046 int vd; // [sp+88h] [bp+Ch]@142
4047 int v_4; // [sp+8Ch] [bp+10h]@60
4048 int v_4a; // [sp+8Ch] [bp+10h]@65
4049 int v_4b; // [sp+8Ch] [bp+10h]@136
4050 int v_4c; // [sp+8Ch] [bp+10h]@141
4051
4052 //__debugbreak();срабатывает при стрельбе огненным шаром
4053
4054 v4 = stru_5C6E00->Atan2(v.x - x, v.y - y);
4055
4056 v113 = 0;
4057 v114 = 0;
4058
4059 v97.z = z;
4060 v97.x = x;
4061 v97.y = y;
4062
4063 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
4064 {
4065 Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v97, &sX, &sY, &sZ);
4066 Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v, &outx, &outy, &outz);
4067 dist_y = outy - sY;
4068 dist_z = outz - sZ;
4069 dist_x = outx - sX;
4070 v49 = integer_sqrt(dist_x * dist_x + dist_y * dist_y + dist_z * dist_z);
4071 v50 = 65536;
4072 if ( v49 )
4073 v50 = 65536 / v49;
4074 v51 = outx;
4075 v143 = dist_x * v50;
4076 v52 = dist_y * v50;
4077 v53 = dist_z * v50;
4078
4079 v123 = max(outx, sX);
4080 v119 = min(outx, sX);
4081
4082 v131 = max(outy, sY);
4083 v127 = min(outy, sY);
4084
4085 v139 = max(outz, sZ);
4086 v135 = min(outz, sZ);
4087
4088 for ( a5b = 0; a5b < 2; a5b++ )
4089 {
4090 if ( a5b )
4091 v59 = pIndoor->GetSector(sX, sY, sZ);
4092 else
4093 v59 = pIndoor->GetSector(outx, outy, outz);
4094 //v60 = pIndoor->pSectors;
4095 //v61 = 116 * v59;
4096 //i = 116 * v59;
4097 //for (sDepthb = 0; *(__int16 *)((char *)&pIndoor->pSectors->uNumWalls + v61)
4098 //+ 2 * *(__int16 *)((char *)&pIndoor->pSectors->uNumFloors + v61); ++sDepthb)
4099 for ( sDepthb = 0; sDepthb < pIndoor->pSectors[v59].uNumFaces; ++sDepthb )
4100 {
4101 face = &pIndoor->pFaces[pIndoor->pSectors[v59].pFaceIDs[sDepthb]];// face = &pIndoor->pFaces[*(__int16 *)((char *)&pIndoor->pSectors->pWalls + v61)[sDepthb]]
4102 v63 = fixpoint_mul(v143, face->pFacePlane_old.vNormal.x);
4103 v64 = fixpoint_mul(v53, face->pFacePlane_old.vNormal.z);
4104 v65 = fixpoint_mul(v52, face->pFacePlane_old.vNormal.y);
4105 v20 = v63 + v64 + v65 == 0;
4106 v66 = v63 + v64 + v65;
4107 v107 = v63 + v64 + v65;
4108 if ( face->Portal()
4109 || v119 > face->pBounding.x2 || v123 < face->pBounding.x1
4110 || v127 > face->pBounding.y2 || v131 < face->pBounding.y1
4111 || v135 > face->pBounding.z2 || v139 < face->pBounding.z1
4112 || v20 )
4113 continue;
4114 v68 = -(face->pFacePlane_old.dist + sX * face->pFacePlane_old.vNormal.x
4115 + sY * face->pFacePlane_old.vNormal.y
4116 + sZ * face->pFacePlane_old.vNormal.z);
4117 if ( v66 <= 0 )
4118 {
4119 if ( face->pFacePlane_old.dist + sX * face->pFacePlane_old.vNormal.x
4120 + sY * face->pFacePlane_old.vNormal.y
4121 + sZ * face->pFacePlane_old.vNormal.z < 0 )
4122 continue;
4123 }
4124 else
4125 {
4126 if ( face->pFacePlane_old.dist + sX * face->pFacePlane_old.vNormal.x
4127 + sY * face->pFacePlane_old.vNormal.y
4128 + sZ * face->pFacePlane_old.vNormal.z > 0 )
4129 continue;
4130 }
4131 v69 = abs(-(face->pFacePlane_old.dist + sX * face->pFacePlane_old.vNormal.x
4132 + sY * face->pFacePlane_old.vNormal.y
4133 + sZ * face->pFacePlane_old.vNormal.z )) >> 14;
4134 if ( v69 <= abs(v66) )
4135 {
4136 //LODWORD(v70) = v68 << 16;
4137 //HIDWORD(v70) = v68 >> 16;
4138 //v71 = v70 / v107;
4139 //v108 = v70 / v107;
4140 v108 = fixpoint_div(v68, v107);
4141 if ( v108 >= 0 )
4142 {
4143 if ( sub_4075DB(sX + ((signed int)(fixpoint_mul(v108, v143) + 0x8000) >> 16),
4144 sY + ((signed int)(fixpoint_mul(v108, v52) + 0x8000) >> 16),
4145 sZ + ((signed int)(fixpoint_mul(v108, v53) + 0x8000) >> 16),
4146 face) )
4147 {
4148 v114 = 1;
4149 break;
4150 }
4151 }
4152 }
4153 }
4154 }
4155
4156 Vec3_int_::Rotate(32, v4 - stru_5C6E00->uIntegerHalfPi, 0, v97, &sX, &sY, &sZ);
4157 Vec3_int_::Rotate(32, v4 - stru_5C6E00->uIntegerHalfPi, 0, v, &outx, &outy, &outz);
4158 dist_y = outy - sY;
4159 dist_z = outz - sZ;
4160 dist_x = outx - sX;
4161 v77 = integer_sqrt(dist_x * dist_x + dist_y * dist_y + dist_z * dist_z);
4162 v78 = 65536;
4163 if ( v77 )
4164 v78 = 65536 / v77;
4165 v79 = outx;
4166 v144 = dist_x * v78;
4167 v80 = dist_y * v78;
4168 v81 = dist_z * v78;
4169
4170 v120 = max(outx, sX);
4171 v124 = min(outx, sX);
4172
4173 v132 = max(outy, sY);
4174 v128 = min(outy, sY);
4175
4176 v140 = max(outz, sZ);
4177 v136 = min(outz, sZ);
4178
4179 for ( a5c = 0; a5c < 2; a5c++ )
4180 {
4181 if ( v113 )
4182 return !v114 || !v113;
4183 if ( a5c )
4184 {
4185 v87 = pIndoor->GetSector(sX, sY, sZ);
4186 }
4187 else
4188 {
4189 v87 = pIndoor->GetSector(outx, outy, outz);
4190 }
4191 for ( v162 = 0; v162 < pIndoor->pSectors[v87].uNumFaces; v162++)
4192 {
4193 face = &pIndoor->pFaces[pIndoor->pSectors[v87].pFaceIDs[v162]];
4194 yb = fixpoint_mul(v144, face->pFacePlane_old.vNormal.x);
4195 v_4b = fixpoint_mul(v80, face->pFacePlane_old.vNormal.y);
4196 vf = fixpoint_mul(v81, face->pFacePlane_old.vNormal.z);
4197 v20 = yb + vf + v_4b == 0;
4198 v91 = yb + vf + v_4b;
4199 vc = yb + vf + v_4b;
4200 if ( face->Portal()
4201 || v120 > face->pBounding.x2 || v124 < face->pBounding.x1
4202 || v128 > face->pBounding.y2 || v132 < face->pBounding.y1
4203 || v136 > face->pBounding.z2 || v140 < face->pBounding.z1
4204 || v20 )
4205 continue;
4206 v93 = -(face->pFacePlane_old.dist + sX * face->pFacePlane_old.vNormal.x
4207 + sY * face->pFacePlane_old.vNormal.y
4208 + sZ * face->pFacePlane_old.vNormal.z);
4209 if ( v91 <= 0 )
4210 {
4211 if ( face->pFacePlane_old.dist + sX * face->pFacePlane_old.vNormal.x
4212 + sY * face->pFacePlane_old.vNormal.y
4213 + sZ * face->pFacePlane_old.vNormal.z < 0 )
4214 continue;
4215 }
4216 else
4217 {
4218 if ( face->pFacePlane_old.dist + sX * face->pFacePlane_old.vNormal.x
4219 + sY * face->pFacePlane_old.vNormal.y
4220 + sZ * face->pFacePlane_old.vNormal.z > 0 )
4221 continue;
4222 }
4223 v_4c = abs(-(face->pFacePlane_old.dist + sX * face->pFacePlane_old.vNormal.x
4224 + sY * face->pFacePlane_old.vNormal.y
4225 + sZ * face->pFacePlane_old.vNormal.z)) >> 14;
4226 if ( v_4c <= abs(v91) )
4227 {
4228 vd = fixpoint_div(v93, vc);
4229 if ( vd >= 0 )
4230 {
4231 if ( sub_4075DB(sX + ((signed int)(fixpoint_mul(vd, v144) + 0x8000) >> 16),
4232 sY + ((signed int)(fixpoint_mul(vd, v80) + 0x8000) >> 16),
4233 sZ + ((signed int)(fixpoint_mul(vd, v81) + 0x8000) >> 16),
4234 face) )
4235 {
4236 v113 = 1;
4237 break;
4238 }
4239 }
4240 }
4241 }
4242 }
4243 }
4244 else if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
4245 {
4246 Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v97, &sX, &sY, &sZ);
4247 Vec3_int_::Rotate(32, stru_5C6E00->uIntegerHalfPi + v4, 0, v, &outx, &outy, &outz);
4248 dist_y = outy - sY;
4249 dist_z = outz - sZ;
4250 dist_x = outx - sX;
4251 v9 = integer_sqrt(dist_x* dist_x+ dist_y* dist_y+ dist_z* dist_z);
4252 v10 = 65536;
4253 if ( v9 )
4254 v10 = 65536 / v9;
4255 v125 = dist_x* v10;
4256 v12 = dist_z* v10;
4257 v121 = dist_y* v10;
4258
4259 v145 = max(outx, sX);
4260 v149 = min(outx, sX);
4261
4262 v137 = max(outy, sY);
4263 v141 = min(outy, sY);
4264
4265 v129 = max(outz, sZ);
4266 v133 = min(outz, sZ);
4267
4268 for ( uint model_id = 0; model_id < pOutdoor->uNumBModels; model_id++)
4269 {
4270 if ( sub_4088E9(sX, sY, outx, outy, pOutdoor->pBModels[model_id].vPosition.x, pOutdoor->pBModels[model_id].vPosition.y)
4271 <= pOutdoor->pBModels[model_id].sBoundingRadius + 128 )
4272 {
4273 for ( uint face_id = 0; face_id < pOutdoor->pBModels[model_id].uNumFaces; ++face_id )
4274 {
4275 odm_face = &pOutdoor->pBModels[model_id].pFaces[face_id];
4276 v17 = fixpoint_mul(v125, odm_face->pFacePlane.vNormal.x);
4277 v18 = fixpoint_mul(v121, odm_face->pFacePlane.vNormal.y);
4278 v19 = fixpoint_mul(v12, odm_face->pFacePlane.vNormal.z);
4279 v20 = v17 + v18 + v19 == 0;
4280 v21 = v17 + v18 + v19;
4281 v109 = v17 + v18 + v19;
4282 if ( v149 > odm_face->pBoundingBox.x2 || v145 < odm_face->pBoundingBox.x1
4283 || v141 > odm_face->pBoundingBox.y2 || v137 < odm_face->pBoundingBox.y1
4284 || v133 > odm_face->pBoundingBox.z2 || v129 < odm_face->pBoundingBox.z1
4285 || v20 )
4286 continue;
4287 v23 = -(odm_face->pFacePlane.dist + sX * odm_face->pFacePlane.vNormal.x
4288 + sY * odm_face->pFacePlane.vNormal.y
4289 + sZ * odm_face->pFacePlane.vNormal.z);
4290 if ( v21 <= 0 )
4291 {
4292 if ( odm_face->pFacePlane.dist + sX * odm_face->pFacePlane.vNormal.x
4293 + sY * odm_face->pFacePlane.vNormal.y
4294 + sZ * odm_face->pFacePlane.vNormal.z < 0 )
4295 continue;
4296 }
4297 else
4298 {
4299 if ( odm_face->pFacePlane.dist + sX * odm_face->pFacePlane.vNormal.x
4300 + sY * odm_face->pFacePlane.vNormal.y
4301 + sZ * odm_face->pFacePlane.vNormal.z > 0 )
4302 continue;
4303 }
4304 v24 = abs(-(odm_face->pFacePlane.dist + sX * odm_face->pFacePlane.vNormal.x
4305 + sY * odm_face->pFacePlane.vNormal.y
4306 + sZ * odm_face->pFacePlane.vNormal.z)) >> 14;
4307 if ( v24 <= abs(v21) )
4308 {
4309 v110 = fixpoint_div(v23, v109);
4310 if ( v110 >= 0 )
4311 {
4312 if ( sub_4077F1(sX + ((signed int)(fixpoint_mul(v110, v125) + 0x8000) >> 16),
4313 sY + ((signed int)(fixpoint_mul(v110, v121) + 0x8000) >> 16),
4314 sZ + ((signed int)(fixpoint_mul(v110, v12) + 0x8000) >> 16),
4315 odm_face,
4316 &pOutdoor->pBModels[model_id].pVertices) )
4317 {
4318 v114 = 1;
4319 break;
4320 }
4321 }
4322 }
4323 }
4324 }
4325 }
4326
4327 Vec3_int_::Rotate(32, v4 - stru_5C6E00->uIntegerHalfPi, 0, v97, &sX, &sY, &sZ);
4328 Vec3_int_::Rotate(32, v4 - stru_5C6E00->uIntegerHalfPi, 0, v, &outx, &outy, &outz);
4329 dist_y = outy - sY;
4330 dist_z = outz - sZ;
4331 dist_x = outx - sX;
4332 v32 = integer_sqrt(dist_x * dist_x + dist_y * dist_y + dist_z * dist_z);
4333 v33 = 65536;
4334 if ( v32 )
4335 v33 = 65536 / v32;
4336 v126 = dist_x * v33;
4337 v35 = dist_z * v33;
4338 v122 = dist_y * v33;
4339
4340 v146 = max(outx, sX);
4341 v150 = min(outx, sX);
4342
4343 v138 = max(outy, sY);
4344 v142 = min(outy, sY);
4345
4346 v130 = max(outz, sZ);
4347 v134 = min(outz, sZ);
4348
4349 for ( uint model_id = 0; model_id < (signed int)pOutdoor->uNumBModels; ++model_id )
4350 {
4351 if ( sub_4088E9(sX, sY, outx, outy, pOutdoor->pBModels[model_id].vPosition.x, pOutdoor->pBModels[model_id].vPosition.y)
4352 <= pOutdoor->pBModels[model_id].sBoundingRadius + 128 )
4353 {
4354 for ( uint face_id = 0; face_id < pOutdoor->pBModels[model_id].uNumFaces; ++face_id )
4355 {
4356 odm_face = &pOutdoor->pBModels[model_id].pFaces[face_id];
4357 ya = fixpoint_mul(v126, odm_face->pFacePlane.vNormal.x);
4358 ve = fixpoint_mul(v122, odm_face->pFacePlane.vNormal.y);
4359 v_4 = fixpoint_mul(v35, odm_face->pFacePlane.vNormal.z);
4360 v20 = ya + ve + v_4 == 0;
4361 v40 = ya + ve + v_4;
4362 va = ya + ve + v_4;
4363 if ( v150 > odm_face->pBoundingBox.x2 || v146 < odm_face->pBoundingBox.x1
4364 || v142 > odm_face->pBoundingBox.y2 || v138 < odm_face->pBoundingBox.y1
4365 || v134 > odm_face->pBoundingBox.z2 || v130 < odm_face->pBoundingBox.z1
4366 || v20 )
4367 continue;
4368 v42 = -(odm_face->pFacePlane.dist + sX * odm_face->pFacePlane.vNormal.x
4369 + sY * odm_face->pFacePlane.vNormal.y
4370 + sZ * odm_face->pFacePlane.vNormal.z);
4371 if ( v40 <= 0 )
4372 {
4373 if ( odm_face->pFacePlane.dist + sX * odm_face->pFacePlane.vNormal.x
4374 + sY * odm_face->pFacePlane.vNormal.y
4375 + sZ * odm_face->pFacePlane.vNormal.z < 0 )
4376 continue;
4377 }
4378 else
4379 {
4380 if ( odm_face->pFacePlane.dist + sX * odm_face->pFacePlane.vNormal.x
4381 + sY * odm_face->pFacePlane.vNormal.y
4382 + sZ * odm_face->pFacePlane.vNormal.z > 0 )
4383 continue;
4384 }
4385 v_4a = abs(-(odm_face->pFacePlane.dist + sX * odm_face->pFacePlane.vNormal.x
4386 + sY * odm_face->pFacePlane.vNormal.y
4387 + sZ * odm_face->pFacePlane.vNormal.z )) >> 14;
4388 if ( v_4a <= abs(v40) )
4389 {
4390 //LODWORD(v43) = v42 << 16;
4391 //HIDWORD(v43) = v42 >> 16;
4392 //vb = v43 / va;
4393 vb = fixpoint_div(v42, va);
4394 if ( vb >= 0 )
4395 {
4396 if ( sub_4077F1(sX + ((signed int)(fixpoint_mul(vb, v126) + 0x8000) >> 16),
4397 sY + ((signed int)(fixpoint_mul(vb, v122) + 0x8000) >> 16),
4398 sZ + ((signed int)(fixpoint_mul(vb, v35) + 0x8000) >> 16),
4399 odm_face,
4400 &pOutdoor->pBModels[model_id].pVertices) )
4401 {
4402 v113 = 1;
4403 break;
4404 }
4405 }
4406 }
4407 }
4408 }
4409 }
4410
4411 }
4412 return !v114 || !v113;
4413 }
4414 //----- (0043F333) --------------------------------------------------------
4415 void BspRenderer::MakeVisibleSectorList()
4416 {
4417 // int v6; // ebx@3
4418
4419 uNumVisibleNotEmptySectors = 0;
4420 for (uint i = 0; i < num_nodes; ++i)
4421 {
4422 //if (!uNumVisibleNotEmptySectors)
4423 //{
4424 //pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
4425 //continue;
4426 //}
4427 //v6 = 0;
4428 //while (pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v6] != nodes[i].uSectorID )
4429 for ( uint j = 0; j < uNumVisibleNotEmptySectors; j++ )
4430 {
4431 //++v6;
4432 if ( pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[j] == nodes[i].uSectorID)
4433 break;
4434 }
4435 pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[uNumVisibleNotEmptySectors++] = nodes[i].uSectorID;
4436 }
4437 }
4438 //----- (0046A334) --------------------------------------------------------
4439 char __fastcall DoInteractionWithTopmostZObject(int a1, int a2)
4440 {
4441 int v17; // edi@36
4442
4443 v17 = PID_ID(a1);
4444 switch ( PID_TYPE(a1) )
4445 {
4446 case OBJECT_Item: // take the item
4447 if ( pObjectList->pObjects[pSpriteObjects[v17].uObjectDescID].uFlags & 0x10 || v17 >= 1000 || !pSpriteObjects[v17].uObjectDescID )
4448 return 1;
4449 if ( pItemsTable->pItems[pSpriteObjects[v17].stru_24.uItemID].uEquipType == EQUIP_GOLD)
4450 {
4451 pParty->PartyFindsGold(pSpriteObjects[v17].stru_24.uSpecEnchantmentType, 0);
4452 viewparams->bRedrawGameUI = 1;
4453 }
4454 else
4455 {
4456 if ( pParty->pPickedItem.uItemID )
4457 return 1;
4458 sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[pSpriteObjects[v17].stru_24.uItemID].pUnidentifiedName);//You found an item (%s)!
4459 ShowStatusBarString(pTmpBuf2.data(), 2);
4460 if ( pSpriteObjects[v17].stru_24.uItemID == 506 )//artefact
4461 _449B7E_toggle_bit(pParty->_quest_bits, 184, 1);
4462 if ( pSpriteObjects[v17].stru_24.uItemID == 455 )
4463 _449B7E_toggle_bit(pParty->_quest_bits, 185, 1);
4464 if ( !pParty->AddItemToParty(&pSpriteObjects[v17].stru_24) )
4465 pParty->SetHoldingItem(&pSpriteObjects[v17].stru_24);
4466 }
4467 SpriteObject::OnInteraction(v17);
4468 break;
4469
4470 case OBJECT_Actor:
4471 if ( pActors[v17].uAIState == Dying || pActors[v17].uAIState == Summoned )
4472 return 1;
4473 if ( pActors[v17].uAIState == Dead )
4474 pActors[v17].LootActor();
4475 else
4476 {
4477 if ( !pActors[v17].GetActorsRelation(0) && pActors[v17].ActorFriend() && pActors[v17].CanAct() )
4478 {
4479 Actor::AI_FaceObject(v17, 4, 0, 0);
4480 if ( pActors[v17].sNPC_ID )
4481 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_StartNPCDialogue, v17, 0);
4482 else
4483 {
4484 if ( pNPCStats->pGroups_copy[pActors[v17].uGroup] )
4485 {
4486 if ( pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[v17].uGroup]] )
4487 {
4488 pParty->uFlags |= 2;
4489 strcpy(byte_5B0938.data(), pNPCStats->pCatchPhrases[pNPCStats->pGroups_copy[pActors[v17].uGroup]]);
4490 sub_4451A8_press_any_key(0, 0, 0);
4491 }
4492 }
4493 }
4494 }
4495 }
4496 break;
4497
4498 case OBJECT_Decoration:
4499 if ( pLevelDecorations[v17].uEventID )
4500 {
4501 EventProcessor(pLevelDecorations[v17].uEventID, a1, 1);
4502 pLevelDecorations[v17].uFlags |= LEVEL_DECORATION_VISIBLE_ON_MAP;
4503 }
4504 else
4505 {
4506 if ( !pLevelDecorations[v17].IsInteractive() )
4507 return 1;
4508 activeLevelDecoration = &pLevelDecorations[v17];
4509 EventProcessor(stru_5E4C90_MapPersistVars._decor_events[pLevelDecorations[v17]._idx_in_stru123 - 75] + 380, 0, 1);
4510 activeLevelDecoration = nullptr;
4511 }
4512 break;
4513
4514 default:
4515 MessageBoxW(nullptr, L"Warning: Invalid ID reached!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Mouse.cpp:2020", 0);
4516 return 1;
4517
4518 case OBJECT_BModel:
4519 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
4520 {
4521 int bmodel_id = a1 >> 9,
4522 face_id = v17 & 0x3F;
4523 if (bmodel_id >= pOutdoor->uNumBModels)
4524 return 1;
4525 if (pOutdoor->pBModels[bmodel_id].pFaces[face_id].uAttributes & FACE_HAS_EVENT
4526 || pOutdoor->pBModels[bmodel_id].pFaces[face_id].sCogTriggeredID == 0 )
4527 return 1;
4528 EventProcessor((signed __int16)pOutdoor->pBModels[bmodel_id].pFaces[face_id].sCogTriggeredID, a1, 1);
4529 }
4530 else
4531 {
4532 if ( !(pIndoor->pFaces[v17].uAttributes & FACE_CLICKABLE) )
4533 {
4534 ShowNothingHereStatus();
4535 return 1;
4536 }
4537 if ( pIndoor->pFaces[v17].uAttributes & FACE_HAS_EVENT || !pIndoor->pFaceExtras[pIndoor->pFaces[v17].uFaceExtraID].uEventID )
4538 return 1;
4539 if ( pCurrentScreen != SCREEN_BRANCHLESS_NPC_DIALOG )
4540 EventProcessor((signed __int16)pIndoor->pFaceExtras[pIndoor->pFaces[v17].uFaceExtraID].uEventID, a1, 1);
4541 }
4542 return 0;
4543 break;
4544 }
4545 return 0;
4546 }
4547 //----- (0046BDF1) --------------------------------------------------------
4548 void BLV_UpdateUserInputAndOther()
4549 {
4550 UpdateObjects();
4551 BLV_ProcessPartyActions();
4552 UpdateActors_BLV();
4553 BLV_UpdateDoors();
4554 check_event_triggers();
4555 }
4556 //----- (00424829) --------------------------------------------------------
4557 // Finds out if current portal can be seen through the previous portal
4558 bool PortalFrustrum(int pNumVertices, BspRenderer_PortalViewportData *far_portal, BspRenderer_PortalViewportData *near_portal, int uFaceID)
4559 {
4560 int min_y; // esi@5
4561 int max_y; // edx@5
4562 int current_ID; // eax@12
4563 int v13; // eax@22
4564 int v15; // ecx@29
4565 int v18; // eax@39
4566 int v19; // eax@44
4567 int v20; // ecx@44
4568 int v22; // edi@46
4569 int v24; // edx@48
4570 int v26; // eax@55
4571 int v29; // edx@57
4572 int v31; // eax@64
4573 __int16 v36; // dx@67
4574 __int16 v38; // dx@67
4575 int v46; // edx@87
4576 int v49; // esi@93
4577 int v53; // [sp+Ch] [bp-34h]@44
4578 int v54; // [sp+10h] [bp-30h]@0
4579 int min_y_ID2; // [sp+14h] [bp-2Ch]@12
4580 int v59; // [sp+14h] [bp-2Ch]@87
4581 int v61; // [sp+1Ch] [bp-24h]@29
4582 int v62; // [sp+20h] [bp-20h]@0
4583 signed int direction1; // [sp+24h] [bp-1Ch]@3
4584 signed int direction2; // [sp+28h] [bp-18h]@3
4585 int min_y_ID; // [sp+2Ch] [bp-14h]@5
4586 int v69; // [sp+34h] [bp-Ch]@29
4587 int v70; // [sp+34h] [bp-Ch]@46
4588
4589 if ( pNumVertices <= 1 )
4590 return false;
4591 min_y = PortalFace._screen_space_y[0];
4592 min_y_ID = 0;
4593 max_y = PortalFace._screen_space_y[0];
4594 //face direction(направление фейса)
4595 if ( !PortalFace.direction )
4596 {
4597 direction1 = 1;
4598 direction2 = -1;
4599 }
4600 else
4601 {
4602 direction1 = -1;
4603 direction2 = 1;
4604 }
4605
4606 //get min and max y for portal(дать минимальное и максимальное значение y для портала)
4607 for ( uint i = 1; i < pNumVertices; ++i )
4608 {
4609 if (PortalFace._screen_space_y[i] < min_y)
4610 {
4611 min_y_ID = i;
4612 min_y = PortalFace._screen_space_y[i];
4613 }
4614 else if (PortalFace._screen_space_y[i] > max_y)
4615 {
4616 max_y = PortalFace._screen_space_y[i];
4617 }
4618 }
4619 if ( max_y == min_y )
4620 return false;
4621
4622 //*****************************************************************************************************************************
4623 far_portal->_viewport_space_y = min_y;
4624 far_portal->_viewport_space_w = max_y;
4625 current_ID = min_y_ID;
4626 min_y_ID2 = min_y_ID;
4627
4628 for ( uint i = 0; i < pNumVertices; ++i )
4629 {
4630 current_ID += direction2;
4631 if ( current_ID < pNumVertices )
4632 {
4633 if ( current_ID < 0 )
4634 current_ID += pNumVertices;
4635 }
4636 else
4637 current_ID -= pNumVertices;
4638 if ( PortalFace._screen_space_y[current_ID] <= PortalFace._screen_space_y[min_y_ID] )//определение минимальной у
4639 {
4640 min_y_ID2 = current_ID;
4641 min_y_ID = current_ID;
4642 }
4643 if ( PortalFace._screen_space_y[current_ID] == max_y )
4644 break;
4645 }
4646
4647 v13 = min_y_ID2 + direction2;
4648 if ( v13 < pNumVertices )
4649 {
4650 if ( v13 < 0 )
4651 v13 += pNumVertices;
4652 }
4653 else
4654 v13 -= pNumVertices;
4655 if ( PortalFace._screen_space_y[v13] != PortalFace._screen_space_y[min_y_ID2] )
4656 {
4657 v62 = PortalFace._screen_space_x[min_y_ID2] << 16;
4658 v54 = ((PortalFace._screen_space_x[v13] - PortalFace._screen_space_x[min_y_ID2]) << 16) /
4659 (PortalFace._screen_space_y[v13] - PortalFace._screen_space_y[min_y_ID2]);
4660 far_portal->viewport_left_side[min_y] = (short)PortalFace._screen_space_x[min_y_ID2];
4661 }
4662 //****************************************************************************************************************************************
4663 //
4664 v15 = min_y_ID;
4665 v61 = min_y_ID;
4666 for ( v69 = 0; v69 < pNumVertices; ++v69 )
4667 {
4668 v15 += direction1;
4669 if ( v15 < pNumVertices )
4670 {
4671 if ( v15 < 0 )
4672 v15 += pNumVertices;
4673 }
4674 else
4675 v15 -= pNumVertices;
4676 if ( PortalFace._screen_space_y[v15] <= PortalFace._screen_space_y[min_y_ID] )
4677 {
4678 v61 = v15;
4679 min_y_ID = v15;
4680 }
4681 if ( PortalFace._screen_space_y[v15] == max_y )
4682 break;
4683 }
4684 v18 = direction1 + v61;
4685 if ( v18 < pNumVertices )
4686 {
4687 if ( v18 < 0 )
4688 v18 += pNumVertices;
4689 }
4690 else
4691 v18 -= pNumVertices;
4692 v19 = v18;
4693 v20 = v61;
4694 if ( PortalFace._screen_space_y[v19] != PortalFace._screen_space_y[v61] )
4695 {
4696 v61 = PortalFace._screen_space_x[v20] << 16;
4697 v53 = ((PortalFace._screen_space_x[v19] - PortalFace._screen_space_x[v20]) << 16) /
4698 (PortalFace._screen_space_y[v19] - PortalFace._screen_space_y[v20]);
4699 far_portal->viewport_right_side[max_y] = (short)PortalFace._screen_space_x[v20];
4700 }
4701 //****************************************************************************************************************************************
4702 v22 = min_y;
4703 if ( min_y <= max_y )
4704 {
4705 for ( v70 = min_y; v70 <= max_y; ++v70 )
4706 {
4707 v24 = v13;
4708 if ( v22 >= PortalFace._screen_space_y[v13] && v22 != max_y )
4709 {
4710 v13 = direction2 + v13;
4711 if ( v13 < pNumVertices )
4712 {
4713 if ( v13 < 0 )
4714 v13 += pNumVertices;
4715 }
4716 else
4717 v13 -= pNumVertices;
4718 v26 = v13;
4719 if ( PortalFace._screen_space_y[v26] - PortalFace._screen_space_y[v24] > 0 )
4720 {
4721 v54 = ((PortalFace._screen_space_x[v26] - PortalFace._screen_space_x[v24]) << 16) / (PortalFace._screen_space_y[v26] - PortalFace._screen_space_y[v24]);
4722 v62 = PortalFace._screen_space_x[v24] << 16;
4723 }
4724 }
4725 v29 = v18;
4726 if ( v70 >= PortalFace._screen_space_y[v18] && v70 != max_y )
4727 {
4728 v18 += direction1;
4729 if ( v18 < pNumVertices )
4730 {
4731 if ( v18 < 0 )
4732 v18 += pNumVertices;
4733 }
4734 else
4735 v18 -= pNumVertices;
4736 v31 = v18;
4737 if ( PortalFace._screen_space_y[v31] - PortalFace._screen_space_y[v29] > 0 )
4738 {
4739 v53 = ((PortalFace._screen_space_x[v31] - PortalFace._screen_space_x[v29]) << 16) / (PortalFace._screen_space_y[v31] - PortalFace._screen_space_y[v29]);
4740 v61 = PortalFace._screen_space_x[v29] << 16;
4741 }
4742 }
4743 far_portal->viewport_left_side[v70] = HIWORD(v62);
4744 far_portal->viewport_right_side[v70] = HIWORD(v61);
4745 if ( far_portal->viewport_left_side[v70] > far_portal->viewport_right_side[v70] )
4746 {
4747 v36 = far_portal->viewport_left_side[v70] ^ far_portal->viewport_right_side[v70];
4748 //v37 = far_portal->viewport_right_side[v70];
4749 far_portal->viewport_left_side[v70] = v36;
4750 v38 = far_portal->viewport_right_side[v70] ^ v36;
4751 far_portal->viewport_left_side[v70] ^= v38;
4752 far_portal->viewport_right_side[v70] = v38;
4753 }
4754 v62 += v54;
4755 v22 = v70 + 1;
4756 v61 += v53;
4757 }
4758 }
4759 //*****************************************************************************************************************************
4760 // check portals coordinates and determine max, min(проверка координат порталов и определение макс, мин-ой у)
4761 if ( max_y < near_portal->_viewport_space_y )
4762 return false;
4763 if ( min_y > near_portal->_viewport_space_w )
4764 return false;
4765 if ( min_y < near_portal->_viewport_space_y )
4766 min_y = near_portal->_viewport_space_y;
4767 if ( max_y > near_portal->_viewport_space_w )
4768 max_y = near_portal->_viewport_space_w;
4769 if ( min_y <= max_y )
4770 {
4771 for ( min_y; min_y <= max_y; ++min_y )
4772 {
4773 if ( far_portal->viewport_right_side[min_y] >= near_portal->viewport_left_side[min_y]
4774 && far_portal->viewport_left_side[min_y] <= near_portal->viewport_right_side[min_y] )
4775 break;
4776 }
4777 }
4778 if ( max_y < min_y )
4779 return false;
4780 for ( max_y; max_y >= min_y; --max_y )
4781 {
4782 if ( far_portal->viewport_right_side[max_y] >= near_portal->viewport_left_side[max_y]
4783 && far_portal->viewport_left_side[max_y] <= near_portal->viewport_right_side[max_y] )
4784 break;
4785 }
4786 if ( min_y >= max_y )
4787 return false;
4788 //*************************************************************************************************************************************
4789 v59 = min_y;
4790 for ( v46 = max_y - min_y + 1; v46; --v46 )
4791 {
4792 if ( far_portal->viewport_left_side[v59] < near_portal->viewport_left_side[v59] )
4793 far_portal->viewport_left_side[v59] = near_portal->viewport_left_side[v59];
4794 if ( far_portal->viewport_right_side[v59] > near_portal->viewport_right_side[v59] )
4795 far_portal->viewport_right_side[v59] = near_portal->viewport_right_side[v59];
4796 ++v59;
4797 }
4798 far_portal->_viewport_space_y = min_y;
4799 far_portal->_viewport_space_w = max_y;
4800 far_portal->_viewport_space_x = far_portal->viewport_left_side[min_y];
4801 far_portal->_viewport_space_z = far_portal->viewport_right_side[min_y];
4802 far_portal->_viewport_x_minID = min_y;
4803 far_portal->_viewport_z_maxID = min_y;
4804 v49 = min_y + 1;
4805 if ( v49 <= max_y )
4806 {
4807 for ( v49; v49 <= max_y; ++v49 )
4808 {
4809 if ( far_portal->viewport_left_side[v49] < far_portal->_viewport_space_x )
4810 {
4811 far_portal->_viewport_space_x = far_portal->viewport_left_side[v49];
4812 far_portal->_viewport_x_minID = v49;
4813 }
4814 if ( far_portal->viewport_right_side[v49] > far_portal->_viewport_space_z )
4815 {
4816 far_portal->_viewport_space_z = far_portal->viewport_right_side[v49];
4817 far_portal->_viewport_z_maxID = v49;
4818 }
4819 }
4820 }
4821 return true;
4822 }
4823 //----- (00423B5D) --------------------------------------------------------
4824 int __fastcall GetPortalScreenCoord(unsigned int uFaceID)
4825 {
4826 BLVFace *pFace; // ebx@1
4827 int pNextVertices; // edx@11
4828 int t; // ST28_4@12
4829 int pScreenX; // eax@22
4830 int pScreenY; // eax@27
4831 signed int left_num_vertices; // edi@31
4832 signed int right_num_vertices; // ebx@41
4833 signed int top_num_vertices; // edi@51
4834 int bottom_num_vertices; // ebx@61
4835 bool current_vertices_flag; // [sp+18h] [bp-10h]@9
4836 signed int depth_num_vertices; // [sp+1Ch] [bp-Ch]@9
4837 bool next_vertices_flag; // [sp+20h] [bp-8h]@10
4838
4839 //Доп инфо "Программирование трёхмерных игр для windows" Ламот стр 910
4840
4841 pFace = &pIndoor->pFaces[uFaceID];
4842 memset(&PortalFace, 0, sizeof(stru367));
4843
4844 //get direction the face(определение направленности фейса)*********************************************************************************
4845 if ( pFace->pFacePlane_old.vNormal.x * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].x - pGame->pIndoorCameraD3D->vPartyPos.x)
4846 + pFace->pFacePlane_old.vNormal.y * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].y - pGame->pIndoorCameraD3D->vPartyPos.y)
4847 + pFace->pFacePlane_old.vNormal.z * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].z - pGame->pIndoorCameraD3D->vPartyPos.z) < 0 )
4848 {
4849 PortalFace.direction = true;
4850 }
4851 else
4852 {
4853 PortalFace.direction = false;
4854 if ( !(pFace->Portal()) )
4855 return 0;
4856 }
4857 //*****************************************************************************************************************************************
4858 //generate/cinvertetion in camera location coordinates(генерация/конвертирование в координаты пространства камеры)
4859
4860 //for new coordinates:
4861 //int x = 0x AAAA BBBB;
4862 //AAAA - integer(целая часть), BBBB - fractional(дробная)
4863 //float v = HIWORD(x) + LOWORD(x) / 65535.0f;
4864 //0x0351A281 это 849(351 в шестнадцатиричной) в целой части и A281 в дробной(хотя как точно BBBB считалась не помню)
4865 //if in HIWORD: FFFF = -1
4866 //FFFE = -2
4867 //FFFD = -3
4868 //....
4869 //8000 = -32767
4870 //7FFF = 32767
4871 //7FFE = 32766
4872 //если в LOWORD например лежит FFFF то не совсем понятно, что это
4873 //потому что если и hiword и loword равны FFFF FFFF то двойное отрицание как бы, нужно тестировать что конкретно получается чтобы понять что это значит
4874 //всё что больше 7FFF для верхнего слова это идёт уже с минусом/Nomad/
4875
4876 if ( (signed int)pFace->uNumVertices > 0 )
4877 {
4878 for (uint i = 0; i < pFace->uNumVertices; ++i)
4879 {
4880 pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pIndoor->pVertices[pFace->pVertexIDs[i]].x,
4881 pIndoor->pVertices[pFace->pVertexIDs[i]].y,
4882 pIndoor->pVertices[pFace->pVertexIDs[i]].z,
4883 &PortalFace._view_transformed_z[i + 3], &PortalFace._view_transformed_x[i + 3], &PortalFace._view_transformed_y[i + 3], 0);
4884 }
4885 }
4886 //*****************************************************************************************************************************************
4887 //check vertices for the nearest plane(проверка вершин есть ли в области за ближайшей плоскостью)
4888 if ( pFace->uNumVertices <= 0 )
4889 return 0;
4890 bool bFound = false;
4891 for (uint i = 0; i < pFace->uNumVertices; ++i)
4892 {
4893 if ( PortalFace._view_transformed_z[i + 3] >= 524288 )// 8.0(0x80000)
4894 {
4895 bFound = true;
4896 break;
4897 }
4898 }
4899 if ( !bFound )
4900 return 0;
4901 //*****************************************************************************************************************************************
4902 //check for near clip plane(проверка по ближней границе)
4903 //
4904 // v0 v1
4905 // ._________________.
4906 // / \
4907 // / \
4908 // v5. . v2
4909 // | |
4910 // | |
4911 // | |
4912 // ---------------------------- 8.0(near_clip)
4913 // | |
4914 // ._______________________.
4915 // v4 v3
4916 depth_num_vertices = 0;
4917 PortalFace._view_transformed_z[pFace->uNumVertices + 3] = PortalFace._view_transformed_z[3];
4918 PortalFace._view_transformed_x[pFace->uNumVertices + 3] = PortalFace._view_transformed_x[3];
4919 PortalFace._view_transformed_y[pFace->uNumVertices + 3] = PortalFace._view_transformed_y[3];
4920 current_vertices_flag = PortalFace._view_transformed_z[3] >= 0x80000; //524288
4921 if ( pFace->uNumVertices >= 1 )
4922 {
4923 for ( uint i = 1; i <= pFace->uNumVertices; ++i)
4924 {
4925 next_vertices_flag = PortalFace._view_transformed_z[i + 3] >= 0x80000; //524288;// 8.0
4926 if ( current_vertices_flag ^ next_vertices_flag )//или текущая или следующая вершина за ближней границей - v5
4927 {
4928 if ( next_vertices_flag )//следующая вершина за ближней границей
4929 {
4930 //t = near_clip - v4.z / v5.z - v4.z
4931 t = fixpoint_div(0x80000 - PortalFace._view_transformed_z[i + 2], PortalFace._view_transformed_z[i + 3] - PortalFace._view_transformed_z[i + 2]);
4932 //New_x = (v5.x - v4.x)*t + v4.x
4933 PortalFace._view_transformed_x[depth_num_vertices] = fixpoint_mul((PortalFace._view_transformed_x[i + 3] - PortalFace._view_transformed_x[i + 2]), t)
4934 + PortalFace._view_transformed_x[i + 2];
4935 //New_y = (v5.y - v4.y)*t + v4.y
4936 PortalFace._view_transformed_y[depth_num_vertices] = fixpoint_mul((PortalFace._view_transformed_y[i + 3] - PortalFace._view_transformed_y[i + 2]), t)
4937 + PortalFace._view_transformed_y[i + 2];
4938 //New_z = 8.0(0x80000)
4939 PortalFace._view_transformed_z[depth_num_vertices] = 0x80000; //524288
4940 }
4941 else// текущая вершина за ближней границей
4942 {
4943 //t = near_clip - v1.z / v0.z - v1.z
4944 t = fixpoint_div(524288 - PortalFace._view_transformed_z[i + 3], PortalFace._view_transformed_z[i + 2] - PortalFace._view_transformed_z[i + 3]);
4945 //New_x = (v0.x - v1.x)*t + v1.x
4946 PortalFace._view_transformed_x[depth_num_vertices] = fixpoint_mul((PortalFace._view_transformed_x[i + 2] - PortalFace._view_transformed_x[i + 3]), t)
4947 + PortalFace._view_transformed_x[i + 3];
4948 //New_y = (v0.x - v1.y)*t + v1.y
4949 PortalFace._view_transformed_y[depth_num_vertices] = fixpoint_mul((PortalFace._view_transformed_y[i + 2] - PortalFace._view_transformed_y[i + 3]), t)
4950 + PortalFace._view_transformed_y[i + 3];
4951 //New_z = 8.0(0x80000)
4952 PortalFace._view_transformed_z[depth_num_vertices] = 0x80000; //524288
4953 }
4954 depth_num_vertices++;
4955 }
4956 if ( next_vertices_flag )//если следующая вершина за ближней границей
4957 {
4958 pNextVertices = depth_num_vertices++;
4959 PortalFace._view_transformed_z[pNextVertices] = PortalFace._view_transformed_z[i + 3];
4960 PortalFace._view_transformed_x[pNextVertices] = PortalFace._view_transformed_x[i + 3];
4961 PortalFace._view_transformed_y[pNextVertices] = PortalFace._view_transformed_y[i + 3];
4962 }
4963 current_vertices_flag = next_vertices_flag;
4964 }
4965 }
4966 //результат: нет моргания на границе портала(когда проходим сквозь портал)
4967 //************************************************************************************************************************************
4968 //convertion in screen coordinates(конвертирование в координаты экрана)
4969 PortalFace._view_transformed_z[depth_num_vertices] = PortalFace._view_transformed_z[0];
4970 PortalFace._view_transformed_x[depth_num_vertices] = PortalFace._view_transformed_x[0];
4971 PortalFace._view_transformed_y[depth_num_vertices] = PortalFace._view_transformed_y[0];
4972 for ( uint i = 0; i < depth_num_vertices; ++i )
4973 {
4974 if ( (abs(PortalFace._view_transformed_x[i]) >> 13) <= abs(PortalFace._view_transformed_z[i]) )
4975 pScreenX = fixpoint_div(PortalFace._view_transformed_x[i], PortalFace._view_transformed_z[i]);
4976 else
4977 {
4978 if ( PortalFace._view_transformed_x[i] >= 0 )
4979 {
4980 if (PortalFace._view_transformed_z[i] >= 0)
4981 pScreenX = 0x400000; // 64.0
4982 else
4983 pScreenX = 0xFFC00000; // -63.0
4984 }
4985 else
4986 {
4987 if (PortalFace._view_transformed_z[i] >= 0)
4988 pScreenX = 0xFFC00000; // -63.0
4989 else
4990 pScreenX = 0x400000; // 64.0
4991 }
4992 }
4993
4994 if ( (abs(PortalFace._view_transformed_y[i]) >> 13) <= abs(PortalFace._view_transformed_z[i]) )
4995 pScreenY = fixpoint_div(PortalFace._view_transformed_y[i], PortalFace._view_transformed_z[i]);
4996 else
4997 {
4998 if ( PortalFace._view_transformed_y[i] >= 0 )
4999 {
5000 if (PortalFace._view_transformed_z[i] >= 0)
5001 pScreenY = 0x400000; // 64.0
5002 else
5003 pScreenY = 0xFFC00000; // -63.0
5004 }
5005 else
5006 {
5007 if (PortalFace._view_transformed_z[i] >= 0)
5008 pScreenY = 0xFFC00000; // -63.0
5009 else
5010 pScreenY = 0x400000; // 64.0
5011 }
5012 }
5013 PortalFace._screen_space_x[i + 12] = pBLVRenderParams->uViewportCenterX - fixpoint_mul(SHIWORD(pBLVRenderParams->fov_rad_fixpoint), pScreenX);
5014 PortalFace._screen_space_y[i + 12] = pBLVRenderParams->uViewportCenterY - fixpoint_mul(SHIWORD(pBLVRenderParams->fov_rad_fixpoint), pScreenY);
5015 }
5016 // результат: при повороте камеры, когда граница портала сдвигается к краю экрана, портал остается прозрачным(видимым)
5017 //******************************************************************************************************************************************
5018 //координаты как в Ида-базе игры так и в данном проекте перевёрнутые,т.е. портал который в правой части экрана имеет экранные координаты
5019 //которые для левой части экрана. Например, x(оригинал) = 8, у нас х = 468(противоположный край экрана), точно также и с у.
5020 //
5021 //check for left_clip plane(порверка по левой границе)
5022 left_num_vertices = 0;
5023 PortalFace._screen_space_x[depth_num_vertices + 12] = PortalFace._screen_space_x[12];
5024 PortalFace._screen_space_y[depth_num_vertices + 12] = PortalFace._screen_space_y[12];
5025 current_vertices_flag = PortalFace._screen_space_x[12] >= (signed int)pBLVRenderParams->uViewportX;//8.0
5026 if ( depth_num_vertices < 1 )
5027 return 0;
5028 for ( uint i = 1; i <= depth_num_vertices; ++i )
5029 {
5030 next_vertices_flag = PortalFace._screen_space_x[i + 12] >= (signed int)pBLVRenderParams->uViewportX;
5031 if ( current_vertices_flag ^ next_vertices_flag )
5032 {
5033 if ( next_vertices_flag )
5034 {
5035 //t = left_clip - v0.x / v1.x - v0.x
5036 t = fixpoint_div(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 11], PortalFace._screen_space_x[i + 12] - PortalFace._screen_space_x[i + 11]);
5037 //New_y = (v1.y - v0.y)*t + v0.y
5038 PortalFace._screen_space_y[left_num_vertices + 9] = fixpoint_mul((PortalFace._screen_space_y[i + 12]- PortalFace._screen_space_y[i + 11]), t)
5039 + PortalFace._screen_space_y[i + 11];
5040 //New_x = left_clip
5041 PortalFace._screen_space_x[left_num_vertices + 9] = pBLVRenderParams->uViewportX;
5042 }
5043 else
5044 {
5045 //t = left_clip - v1.x / v0.x - v1.x
5046 t = fixpoint_div(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 12], PortalFace._screen_space_x[i + 11] - PortalFace._screen_space_x[i + 12]);
5047 //New_y = (v0.y - v1.y)*t + v1.y
5048 PortalFace._screen_space_y[left_num_vertices + 9] = fixpoint_mul((PortalFace._screen_space_y[i + 11] - PortalFace._screen_space_y[i + 12]), t)
5049 + PortalFace._screen_space_y[i + 12];
5050 //New_x = left_clip
5051 PortalFace._screen_space_x[left_num_vertices + 9] = pBLVRenderParams->uViewportX;
5052 }
5053 left_num_vertices++;
5054 }
5055 if ( next_vertices_flag )
5056 {
5057 pNextVertices = left_num_vertices++;
5058 PortalFace._screen_space_x[pNextVertices + 9] = PortalFace._screen_space_x[i + 12];
5059 PortalFace._screen_space_y[pNextVertices + 9] = PortalFace._screen_space_y[i + 12];
5060 }
5061 current_vertices_flag = next_vertices_flag;
5062 }
5063 //*********************************************************************************************************************************
5064 //for right_clip plane(проверка по правой плоскости)
5065 right_num_vertices = 0;
5066 PortalFace._screen_space_x[left_num_vertices + 9] = PortalFace._screen_space_x[9];
5067 PortalFace._screen_space_y[left_num_vertices + 9] = PortalFace._screen_space_y[9];
5068 current_vertices_flag = PortalFace._screen_space_x[9] <= (signed int)pBLVRenderParams->uViewportZ;//468.0
5069 if (left_num_vertices < 1)
5070 return 0;
5071 for ( uint i = 1; i <= left_num_vertices; ++i )
5072 {
5073 next_vertices_flag = PortalFace._screen_space_x[i + 9] <= (signed int)pBLVRenderParams->uViewportZ;
5074 if ( current_vertices_flag ^ next_vertices_flag )
5075 {
5076 if ( next_vertices_flag )
5077 {
5078 //t = right_clip - v1.x / v0.x - v1.x
5079 t = fixpoint_div(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 8], PortalFace._screen_space_x[i + 9] - PortalFace._screen_space_x[i + 8]);
5080 //New_y = (v0.y - v1.y)*t + v1.y
5081 PortalFace._screen_space_y[right_num_vertices + 6] = fixpoint_mul((PortalFace._screen_space_y[i + 9] - PortalFace._screen_space_y[i + 8]), t)
5082 + PortalFace._screen_space_y[i + 8];
5083 //New_x = right_clip
5084 PortalFace._screen_space_x[right_num_vertices + 6] = pBLVRenderParams->uViewportZ;
5085 }
5086 else
5087 {
5088 //t = right_clip - v0.x / v1.x - v0.x
5089 t = fixpoint_div(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 9], PortalFace._screen_space_x[i + 8] - PortalFace._screen_space_x[i + 9]);
5090 //New_y = (v1.y - v0.y)*t + v0.y
5091 PortalFace._screen_space_y[right_num_vertices + 6] = fixpoint_mul((PortalFace._screen_space_y[i + 8] - PortalFace._screen_space_y[i + 9]), t)
5092 + PortalFace._screen_space_y[i + 9];
5093 //New_x = right_clip
5094 PortalFace._screen_space_x[right_num_vertices + 6] = pBLVRenderParams->uViewportZ;
5095 }
5096 right_num_vertices++;
5097 }
5098 if ( next_vertices_flag )
5099 {
5100 pNextVertices = right_num_vertices++;
5101 PortalFace._screen_space_x[pNextVertices + 6] = PortalFace._screen_space_x[i + 9];
5102 PortalFace._screen_space_y[pNextVertices + 6] = PortalFace._screen_space_y[i + 9];
5103 }
5104 current_vertices_flag = next_vertices_flag;
5105 }
5106 //************************************************************************************************************************************
5107 // for top clip plane
5108 top_num_vertices = 0;
5109 PortalFace._screen_space_x[right_num_vertices + 6] = PortalFace._screen_space_x[6];
5110 PortalFace._screen_space_y[right_num_vertices + 6] = PortalFace._screen_space_y[6];
5111
5112 current_vertices_flag = PortalFace._screen_space_y[6] >= (signed int)pBLVRenderParams->uViewportY;//8.0
5113 if ( right_num_vertices < 1 )
5114 return 0;
5115 for ( uint i = 1; i <= right_num_vertices; ++i )
5116 {
5117 next_vertices_flag = PortalFace._screen_space_y[i + 6] >= (signed int)pBLVRenderParams->uViewportY;
5118 if ( current_vertices_flag ^ next_vertices_flag )
5119 {
5120 if ( next_vertices_flag )
5121 {
5122 t = fixpoint_div(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 5], PortalFace._screen_space_y[i + 6] - PortalFace._screen_space_y[i + 5]);
5123 PortalFace._screen_space_x[top_num_vertices + 3] = ((signed int)((PortalFace._screen_space_x[i + 6] - PortalFace._screen_space_x[i + 5])
5124 * t) >> 16) + PortalFace._screen_space_x[i + 5];
5125 PortalFace._screen_space_y[top_num_vertices + 3] = pBLVRenderParams->uViewportY;
5126 }
5127 else
5128 {
5129 t = fixpoint_div(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 6], PortalFace._screen_space_y[i + 5] - PortalFace._screen_space_y[i + 6]);
5130 PortalFace._screen_space_x[top_num_vertices + 3] = fixpoint_mul((PortalFace._screen_space_x[i + 5]- PortalFace._screen_space_x[i + 6]), t)
5131 + PortalFace._screen_space_x[i + 6];
5132 PortalFace._screen_space_y[top_num_vertices + 3] = pBLVRenderParams->uViewportY;
5133 }
5134 top_num_vertices++;
5135 }
5136 current_vertices_flag = next_vertices_flag;
5137 if ( next_vertices_flag )
5138 {
5139 pNextVertices = top_num_vertices++;
5140 PortalFace._screen_space_x[pNextVertices + 3] = PortalFace._screen_space_x[i + 6];
5141 PortalFace._screen_space_y[pNextVertices + 3] = PortalFace._screen_space_y[i + 6];
5142 }
5143 }
5144 //**********************************************************************************************************************************
5145 //for bottom_clip plane(проверка по нижней плоскости)
5146 bottom_num_vertices = 0;
5147 PortalFace._screen_space_x[top_num_vertices + 3] = PortalFace._screen_space_x[3];
5148 PortalFace._screen_space_y[top_num_vertices + 3] = PortalFace._screen_space_y[3];
5149 current_vertices_flag = PortalFace._screen_space_y[3] <= (signed int)pBLVRenderParams->uViewportW;//351.0
5150 if ( top_num_vertices < 1 )
5151 return 0;
5152 for ( uint i =1; i <= top_num_vertices; ++i )
5153 {
5154 next_vertices_flag = PortalFace._screen_space_y[i + 3] <= (signed int)pBLVRenderParams->uViewportW;
5155 if ( current_vertices_flag ^ next_vertices_flag )
5156 {
5157 if ( next_vertices_flag )
5158 {
5159 t = fixpoint_div(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 2], PortalFace._screen_space_y[i + 3] - PortalFace._screen_space_y[i + 2]);
5160 PortalFace._screen_space_x[bottom_num_vertices] = fixpoint_mul((PortalFace._screen_space_x[i + 3] - PortalFace._screen_space_x[i + 2]), t)
5161 + PortalFace._screen_space_x[i + 2];
5162 PortalFace._screen_space_y[bottom_num_vertices] = pBLVRenderParams->uViewportW;
5163 }
5164 else
5165 {
5166 t = fixpoint_div(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 3], PortalFace._screen_space_y[i + 2] - PortalFace._screen_space_y[i + 3]);
5167 PortalFace._screen_space_x[bottom_num_vertices] = fixpoint_mul((PortalFace._screen_space_x[i + 2] - PortalFace._screen_space_x[i + 3]), t)
5168 + PortalFace._screen_space_x[i + 3];
5169 PortalFace._screen_space_y[bottom_num_vertices] = pBLVRenderParams->uViewportW;
5170 }
5171 bottom_num_vertices++;
5172 }
5173 if ( next_vertices_flag )
5174 {
5175 pNextVertices = bottom_num_vertices++;
5176 PortalFace._screen_space_x[pNextVertices] = PortalFace._screen_space_x[i + 3];
5177 PortalFace._screen_space_y[pNextVertices] = PortalFace._screen_space_y[i + 3];
5178 }
5179 current_vertices_flag = next_vertices_flag;
5180 }
5181 //***************************************************************************************************************************************
5182
5183 if ( !bottom_num_vertices )
5184 return 0;
5185 PortalFace._screen_space_x[bottom_num_vertices] = PortalFace._screen_space_x[0];
5186 PortalFace._screen_space_y[bottom_num_vertices] = PortalFace._screen_space_y[0];
5187 //check for software(проверка для софтвар)
5188 /*if ( !pRenderer->pRenderD3D && bottom_num_vertices > 3 )
5189 {
5190 PortalFace._screen_space_x[bottom_num_vertices + 1] = PortalFace._screen_space_x[1];
5191 PortalFace._screen_space_y[bottom_num_vertices + 1] = PortalFace._screen_space_y[1];
5192 thisf = PortalFace.direction == true ? 1 : - 1;
5193 if ( bottom_num_vertices > 0 )
5194 {
5195 v62 = 1;
5196 v71 = 1;
5197 do
5198 {
5199 v63 = v62 - 1;
5200 v64 = v62 + 1;
5201 v80 = v62 + 1;
5202 if ( v62 - 1 >= bottom_num_vertices )
5203 v63 -= bottom_num_vertices;
5204 if ( v62 >= bottom_num_vertices )
5205 v62 -= bottom_num_vertices;
5206 if ( v64 >= bottom_num_vertices )
5207 v64 -= bottom_num_vertices;
5208 if ( thisf * ((PortalFace._screen_space_y[v64] - PortalFace._screen_space_y[v63])
5209 * (PortalFace._screen_space_x[v62] - PortalFace._screen_space_x[v63])
5210 - (PortalFace._screen_space_y[v62] - PortalFace._screen_space_y[v63])
5211 * (PortalFace._screen_space_x[v64] - PortalFace._screen_space_x[v63])) < 0 )
5212 {
5213 v62 = v80;
5214 v71 = v80;
5215 }
5216 else
5217 {
5218 v62 = v71;
5219 v65 = v71;
5220 if ( v71 < bottom_num_vertices || (v65 = v71 - bottom_num_vertices, v71 - bottom_num_vertices < bottom_num_vertices) )
5221 {
5222 memcpy(&PortalFace._screen_space_y[v65], &PortalFace._screen_space_y[v65 + 1],
5223 4 * ((unsigned int)(4 * (bottom_num_vertices - v65)) >> 2));
5224 memcpy(&PortalFace._screen_space_x[v65], &PortalFace._screen_space_x[v65 + 1],
5225 4 * ((unsigned int)(4 * (bottom_num_vertices - v65)) >> 2));
5226 }
5227 --bottom_num_vertices;
5228 }
5229 }
5230 while ( v62 - 1 < bottom_num_vertices );
5231 }
5232 PortalFace._screen_space_x[bottom_num_vertices] = PortalFace._screen_space_x[0];
5233 PortalFace._screen_space_y[bottom_num_vertices] = PortalFace._screen_space_y[0];
5234 }*/
5235 return bottom_num_vertices;
5236 }
5237
5238 //----- (004AAEA6) --------------------------------------------------------
5239 int __fastcall sub_4AAEA6_transform(RenderVertexSoft *a1)
5240 {
5241 double v4; // st5@2
5242 double v5; // st4@3
5243 float v11; // [sp+8h] [bp-8h]@2
5244 float v12; // [sp+8h] [bp-8h]@6
5245 float v13; // [sp+Ch] [bp-4h]@2
5246 float v14; // [sp+Ch] [bp-4h]@6
5247
5248 if (pGame->pIndoorCameraD3D->sRotationX)
5249 {
5250 v13 = a1->vWorldPosition.x - (double)pParty->vPosition.x;
5251 v11 = a1->vWorldPosition.y - (double)pParty->vPosition.y;
5252 v4 = a1->vWorldPosition.z - (double)pParty->vPosition.z;
5253 //if ( pRenderer->pRenderD3D )
5254 //{
5255 v5 = v11 * pGame->pIndoorCameraD3D->fRotationYSine + v13 * pGame->pIndoorCameraD3D->fRotationYCosine;
5256 a1->vWorldViewPosition.y = v13 * pGame->pIndoorCameraD3D->fRotationYSine - v11 * pGame->pIndoorCameraD3D->fRotationYCosine;
5257 /*}
5258 else
5259 {
5260 v5 = v13 * pBLVRenderParams->fCosineY - v11 * pBLVRenderParams->fSineY;
5261 a1->vWorldViewPosition.y = v13 * pBLVRenderParams->fSineY + v11 * pBLVRenderParams->fCosineY;
5262 }*/
5263 a1->vWorldViewPosition.x = v5 * pGame->pIndoorCameraD3D->fRotationXCosine - v4 * pGame->pIndoorCameraD3D->fRotationXSine;
5264 a1->vWorldViewPosition.z = v5 * pGame->pIndoorCameraD3D->fRotationXSine + v4 * pGame->pIndoorCameraD3D->fRotationXCosine;
5265 }
5266 else
5267 {
5268 v14 = a1->vWorldPosition.x - (double)pParty->vPosition.x;
5269 v12 = a1->vWorldPosition.y - (double)pParty->vPosition.y;
5270 a1->vWorldViewPosition.z = a1->vWorldPosition.z - (double)pParty->vPosition.z;
5271 //if ( pRenderer->pRenderD3D )
5272 //{
5273 a1->vWorldViewPosition.x = v12 * pGame->pIndoorCameraD3D->fRotationYSine + v14 * pGame->pIndoorCameraD3D->fRotationYCosine;
5274 a1->vWorldViewPosition.y = v14 * pGame->pIndoorCameraD3D->fRotationYSine - v12 * pGame->pIndoorCameraD3D->fRotationYCosine;
5275 /*}
5276 else
5277 {
5278 a1->vWorldViewPosition.x = v14 * pBLVRenderParams->fCosineY - v12 * pBLVRenderParams->fSineY;
5279 a1->vWorldViewPosition.y = v14 * pBLVRenderParams->fSineY + v12 * pBLVRenderParams->fCosineY;
5280 }*/
5281 }
5282 return 0;
5283 }
5284 //----- (00472866) --------------------------------------------------------
5285 void BLV_ProcessPartyActions()
5286 {
5287 int v1; // ebx@1
5288 int v2; // edi@1
5289 double v10; // st7@27
5290 int new_party_z; // esi@96
5291 int v38; // eax@96
5292 int v39; // ecx@106
5293 int v40; // eax@106
5294 int v42; // eax@120
5295 BLVFace *pFace; // esi@126
5296 int v46; // ecx@133
5297 int v52; // eax@140
5298 int v54; // ebx@146
5299 unsigned int uFaceEvent; // [sp+14h] [bp-4Ch]@1
5300 bool party_running_flag; // [sp+1Ch] [bp-44h]@1
5301 bool bFeatherFall; // [sp+24h] [bp-3Ch]@15
5302 unsigned int uSectorID; // [sp+28h] [bp-38h]@1
5303 bool party_walking_flag; // [sp+2Ch] [bp-34h]@1
5304 unsigned int uFaceID; // [sp+30h] [bp-30h]@1
5305 int v80; // [sp+34h] [bp-2Ch]@1
5306 int v82; // [sp+3Ch] [bp-24h]@47
5307 int _view_angle; // [sp+40h] [bp-20h]@47
5308 bool hovering; // [sp+44h] [bp-1Ch]@1
5309 int new_party_y; // [sp+48h] [bp-18h]@1
5310 int new_party_x; // [sp+4Ch] [bp-14h]@1
5311 int party_z; // [sp+50h] [bp-10h]@1
5312 int angle; // [sp+5Ch] [bp-4h]@47
5313
5314 uFaceEvent = 0;
5315 //v89 = pParty->uFallSpeed;
5316 v1 = 0;
5317 v2 = 0;
5318 new_party_x = pParty->vPosition.x;
5319 new_party_y = pParty->vPosition.y;
5320 party_z = pParty->vPosition.z;
5321 uSectorID = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
5322 party_running_flag = false;
5323 party_walking_flag = false;
5324 hovering = false;
5325
5326 uFaceID = -1;
5327 int floor_level = collide_against_floor(new_party_x, new_party_y, party_z + 40, &uSectorID, &uFaceID);//получить высоту пола
5328
5329 if ( pParty->bFlying )//отключить полёт
5330 {
5331 pParty->bFlying = false;
5332 if (pParty->FlyActive())
5333 pOtherOverlayList->pOverlays[pParty->pPartyBuffs[PARTY_BUFF_FLY].uOverlayID - 1].field_E |= 1;
5334 }
5335
5336 if ( floor_level == -30000 || uFaceID == -1)
5337 {
5338 floor_level = collide_against_floor_approximate(new_party_x, new_party_y, party_z + 40, &uSectorID, &uFaceID);
5339 if ( floor_level == -30000 || uFaceID == -1)
5340 {
5341 __debugbreak(); // level built with errors
5342 pParty->vPosition.x = blv_prev_party_x;
5343 pParty->vPosition.y = blv_prev_party_z;
5344 pParty->vPosition.z = blv_prev_party_y;
5345 pParty->uFallStartY = blv_prev_party_y;
5346 return;
5347 }
5348 }
5349
5350 blv_prev_party_x = pParty->vPosition.x;
5351 blv_prev_party_z = pParty->vPosition.y;
5352 blv_prev_party_y = pParty->vPosition.z;
5353 if (!pParty->bTurnBasedModeOn)
5354 {
5355 static int dword_720CDC = 0;
5356
5357 int v67 = GetTickCount() / 500;
5358 if (dword_720CDC != v67 )
5359 {
5360 dword_4F8580[3 * dword_4F8580[1]] = pParty->vPosition.x;
5361 dword_4F8580[3 * dword_4F8580[2]] = pParty->vPosition.y;
5362 dword_4F8580[3 * dword_4F8580[3]] = pParty->vPosition.z;
5363 if ( dword_4F8580[0] > 60 )
5364 dword_4F8580[0] = 1;
5365
5366 dword_720CDC = v67;
5367 }
5368 }
5369
5370 int fall_start;
5371 /*
5372 if (!pParty->FeatherFallActive())// не активно падение пера
5373 {
5374 bFeatherFall = false;
5375 if (!pParty->pPlayers[0].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT) && // grants feather fall
5376 !pParty->pPlayers[1].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT) &&
5377 !pParty->pPlayers[2].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT) &&
5378 !pParty->pPlayers[3].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT))
5379 {
5380 fall_start = pParty->uFallStartY;
5381 }
5382 else// was missing
5383 {
5384 fall_start = floor_level;
5385 bFeatherFall = true;
5386 pParty->uFallStartY = floor_level;
5387 }
5388 }
5389 else// активно падение пера
5390 {
5391 fall_start = floor_level;
5392 bFeatherFall = true;
5393 pParty->uFallStartY = floor_level;
5394 }
5395
5396 Reworked condition below
5397 */
5398 if (pParty->FeatherFallActive()
5399 || pParty->pPlayers[0].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT)
5400 || pParty->pPlayers[1].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT)
5401 || pParty->pPlayers[2].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT)
5402 || pParty->pPlayers[3].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT))
5403 {
5404 fall_start = floor_level;
5405 bFeatherFall = true;
5406 pParty->uFallStartY = floor_level;
5407 }
5408 else
5409 {
5410 bFeatherFall = false;
5411 fall_start = pParty->uFallStartY;
5412 }
5413
5414 if (fall_start - party_z > 512 && !bFeatherFall && party_z <= floor_level + 1)//повреждение от падения с высоты
5415 {
5416 assert(~pParty->uFlags & PARTY_FLAGS_1_LANDING); // why land in indoor?
5417 if (pParty->uFlags & PARTY_FLAGS_1_LANDING)
5418 pParty->uFlags &= ~PARTY_FLAGS_1_LANDING;
5419 else for (uint i = 0; i < 4; ++i)
5420 { // receive falling damage
5421 if (!pParty->pPlayers[i].HasEnchantedItemEquipped(72) && !pParty->pPlayers[i].WearsItem(ITEM_ARTIFACT_HERMES_SANDALS, EQUIP_BOOTS))
5422 {
5423 pParty->pPlayers[i].ReceiveDamage((pParty->uFallStartY - party_z) * (0.1f * pParty->pPlayers[i].GetMaxHealth()) / 256, DMGT_PHISYCAL);
5424 v10 = (double)(20 - pParty->pPlayers[i].GetParameterBonus(pParty->pPlayers[i].GetActualEndurance())) * flt_6BE3A4_debug_recmod1 * 2.133333333333333;
5425 pParty->pPlayers[i].SetRecoveryTime((signed __int64)v10);
5426 }
5427 }
5428 }
5429
5430 if ( party_z > floor_level + 1 )
5431 hovering = true;
5432
5433 bool not_high_fall = false;
5434
5435 if ( party_z - floor_level <= 32 )
5436 {
5437 pParty->uFallStartY = party_z;
5438 not_high_fall = true;
5439 }
5440
5441 if (bWalkSound && pParty->walk_sound_timer)//таймеры для звуков передвижения
5442 {
5443 if (pParty->walk_sound_timer > pEventTimer->uTimeElapsed)
5444 pParty->walk_sound_timer -= pEventTimer->uTimeElapsed;
5445 else pParty->walk_sound_timer = 0;
5446 }
5447
5448 if (party_z <= floor_level + 1)// группа ниже уровня пола
5449 {
5450 party_z = floor_level + 1;
5451 pParty->uFallStartY = floor_level + 1;
5452
5453 if (!hovering && pParty->floor_face_pid != uFaceID)// не парящие и
5454 {
5455 if (pIndoor->pFaces[uFaceID].uAttributes & FACE_PRESSURE_PLATE)
5456 uFaceEvent = pIndoor->pFaceExtras[pIndoor->pFaces[uFaceID].uFaceExtraID].uEventID;
5457 }
5458 }
5459 if (!hovering)
5460 pParty->floor_face_pid = uFaceID;
5461
5462 bool on_water = false;
5463 if ( pIndoor->pFaces[uFaceID].Fluid())// на воде
5464 on_water = true;
5465
5466 //v81 = pParty->uWalkSpeed;
5467 angle = pParty->sRotationY;
5468 _view_angle = pParty->sRotationX;
5469 v82 = (unsigned __int64)(pEventTimer->dt_in_some_format * (signed __int64)((signed int)(pParty->y_rotation_speed * stru_5C6E00->uIntegerPi)
5470 / 180)) >> 16;
5471 while ( pPartyActionQueue->uNumActions )
5472 {
5473 switch ( pPartyActionQueue->Next() )
5474 {
5475 case PARTY_TurnLeft:
5476 if (uTurnSpeed)
5477 angle = stru_5C6E00->uDoublePiMask & (angle + uTurnSpeed);
5478 else
5479 angle = stru_5C6E00->uDoublePiMask & (angle + (int)(v82 * fTurnSpeedMultiplier));
5480 break;
5481 case PARTY_TurnRight:
5482 if (uTurnSpeed)
5483 angle = stru_5C6E00->uDoublePiMask & (angle - uTurnSpeed);
5484 else
5485 angle = stru_5C6E00->uDoublePiMask & (angle - (int)(v82 * fTurnSpeedMultiplier));
5486 break;
5487
5488 case PARTY_FastTurnLeft:
5489 if (uTurnSpeed)
5490 angle = stru_5C6E00->uDoublePiMask & (angle + uTurnSpeed);
5491 else
5492 angle = stru_5C6E00->uDoublePiMask & (angle + (int)(2.0f * fTurnSpeedMultiplier * (double)v82));
5493 break;
5494
5495 case PARTY_FastTurnRight:
5496 if (uTurnSpeed)
5497 angle = stru_5C6E00->uDoublePiMask & (angle - uTurnSpeed);
5498 else
5499 angle = stru_5C6E00->uDoublePiMask & (angle - (int)(2.0f * fTurnSpeedMultiplier * (double)v82));
5500 break;
5501
5502 case PARTY_StrafeLeft:
5503 v2 -= fixpoint_mul(stru_5C6E00->Sin(angle), pParty->uWalkSpeed * fWalkSpeedMultiplier / 2);
5504 v1 += fixpoint_mul(stru_5C6E00->Cos(angle), pParty->uWalkSpeed * fWalkSpeedMultiplier / 2);
5505 party_walking_flag = true;
5506 break;
5507 case PARTY_StrafeRight:
5508 v2 += fixpoint_mul(stru_5C6E00->Sin(angle), pParty->uWalkSpeed * fWalkSpeedMultiplier / 2);
5509 v1 -= fixpoint_mul(stru_5C6E00->Cos(angle), pParty->uWalkSpeed * fWalkSpeedMultiplier / 2);
5510 party_walking_flag = true;
5511 break;
5512 case PARTY_WalkForward:
5513 v2 += fixpoint_mul(stru_5C6E00->Cos(angle), 5 * pParty->uWalkSpeed * fWalkSpeedMultiplier);
5514 v1 += fixpoint_mul(stru_5C6E00->Sin(angle), 5 * pParty->uWalkSpeed * fWalkSpeedMultiplier);
5515 party_walking_flag = true;
5516 break;
5517 case PARTY_WalkBackward:
5518 v2 -= fixpoint_mul(stru_5C6E00->Cos(angle), pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier);
5519 v1 -= fixpoint_mul(stru_5C6E00->Sin(angle), pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier);
5520 party_walking_flag = true;
5521 break;
5522 case PARTY_RunForward://Бег вперёд
5523 v2 += fixpoint_mul(stru_5C6E00->Cos(angle), 2 * pParty->uWalkSpeed * fWalkSpeedMultiplier);
5524 v1 += fixpoint_mul(stru_5C6E00->Sin(angle), 2 * pParty->uWalkSpeed * fWalkSpeedMultiplier);
5525 party_running_flag = true;
5526 break;
5527 case PARTY_RunBackward:
5528 //v32 = stru_5C6E00->SinCos(angle);
5529 //v33 = (double)v81;
5530 //v88 = (double)v81;
5531 v2 -= fixpoint_mul(stru_5C6E00->Cos(angle), pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier);
5532 //v34 = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
5533 v1 -= fixpoint_mul(stru_5C6E00->Sin(angle), pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier);
5534 party_running_flag = true;
5535 break;
5536 case PARTY_LookUp:
5537 _view_angle += (signed __int64)(flt_6BE150_look_up_down_dangle * 25.0);
5538 if ( _view_angle > 128 )
5539 _view_angle = 128;
5540 if ( uActiveCharacter )
5541 pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)SPEECH_63, 0);
5542 break;
5543 case PARTY_LookDown:
5544 _view_angle += (signed __int64)(flt_6BE150_look_up_down_dangle * -25.0);
5545 if ( _view_angle < -128 )
5546 _view_angle = -128;
5547 if ( uActiveCharacter )
5548 pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)SPEECH_64, 0);
5549 break;
5550 case PARTY_CenterView:
5551 _view_angle = 0;
5552 break;
5553 case PARTY_Jump:
5554 if ( (!hovering || party_z <= floor_level + 6 && pParty->uFallSpeed <= 0) && pParty->field_24 )
5555 {
5556 hovering = true;
5557 pParty->uFallSpeed = (signed __int64)((double)(pParty->field_24 << 6) * 1.5 + (double)pParty->uFallSpeed);
5558 }
5559 break;
5560 default:
5561 break;
5562 }
5563 }
5564 pParty->sRotationY = angle;
5565 pParty->sRotationX = _view_angle;
5566 if ( hovering )//парящие
5567 {
5568 pParty->uFallSpeed += -2 * pEventTimer->uTimeElapsed * GetGravityStrength();// расчёт скорости падения
5569 if ( hovering && pParty->uFallSpeed <= 0 )
5570 {
5571 if ( pParty->uFallSpeed < -500 && !pParty->bFlying )
5572 {
5573 for ( uint pl = 1; pl <= 4; pl++ )
5574 {
5575 if ( !pPlayers[pl]->HasEnchantedItemEquipped(72) && !pPlayers[pl]->WearsItem(ITEM_ARTIFACT_HERMES_SANDALS, EQUIP_BOOTS) ) //was 8
5576 pPlayers[pl]->PlayEmotion(CHARACTER_EXPRESSION_SCARED, 0);
5577 }
5578 }
5579 }
5580 else
5581 pParty->uFallStartY = party_z;
5582 }
5583 else// не парящие
5584 {
5585 if ( pIndoor->pFaces[uFaceID].pFacePlane_old.vNormal.z < 0x8000 )
5586 {
5587 pParty->uFallSpeed -= pEventTimer->uTimeElapsed * GetGravityStrength();
5588 pParty->uFallStartY = party_z;
5589 }
5590 else
5591 {
5592 if (! (pParty->uFlags & PARTY_FLAGS_1_LANDING) )
5593 pParty->uFallSpeed = 0;
5594 pParty->uFallStartY = party_z;
5595 }
5596 }
5597 if ( v2 * v2 + v1 * v1 < 400 )
5598 {
5599 v1 = 0;
5600 v2 = 0;
5601 }
5602
5603 stru_721530.field_84 = -1;
5604 stru_721530.field_70 = 0;
5605 stru_721530.prolly_normal_d = pParty->field_14_radius;
5606 stru_721530.field_8_radius = pParty->field_14_radius / 2;
5607 stru_721530.field_0 = 1;
5608 stru_721530.height = pParty->uPartyHeight - 32;
5609 for ( uint i = 0; i < 100; i++ )
5610 {
5611 new_party_z = party_z;
5612 stru_721530.position.x = new_party_x;
5613 stru_721530.position.y = new_party_y;
5614 stru_721530.position.z = stru_721530.height + party_z + 1;
5615
5616 stru_721530.normal.x = new_party_x;
5617 stru_721530.normal.y = new_party_y;
5618 stru_721530.normal.z = stru_721530.prolly_normal_d + party_z + 1;
5619
5620 stru_721530.velocity.x = v2;
5621 stru_721530.velocity.y = v1;
5622 stru_721530.velocity.z = pParty->uFallSpeed;
5623
5624 stru_721530.uSectorID = uSectorID;
5625 v38 = 0;
5626 if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT )
5627 v38 = 13312;
5628 if ( stru_721530._47050A(v38) )
5629 break;
5630 for ( uint j = 0; j < 100; ++j )
5631 {
5632 _46E44E_collide_against_faces_and_portals(1);
5633 _46E0B2_collide_against_decorations();//столкновения с декором
5634 for ( v80 = 0; v80 < (signed int)uNumActors; ++v80 )
5635 Actor::_46DF1A_collide_against_actor(v80, 0);//столкновения с монстрами
5636 if ( _46F04E_collide_against_portals() )//столкновения с порталами
5637 break;
5638 }
5639 if ( stru_721530.field_7C >= stru_721530.field_6C )
5640 {
5641 v39 = stru_721530.normal2.x;
5642 uSectorID = stru_721530.normal2.y;
5643 v40 = stru_721530.normal2.z - stru_721530.prolly_normal_d - 1;
5644 }
5645 else
5646 {
5647 v39 = new_party_x + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.x);
5648 uSectorID = new_party_y + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.y);
5649 v40 = new_party_z + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z);
5650 }
5651 v42 = collide_against_floor(v39, uSectorID, v40 + 40, &stru_721530.uSectorID, &uFaceID);
5652 if ( v42 == -30000 || v42 - new_party_z > 128 )
5653 return;
5654 if ( stru_721530.field_7C >= stru_721530.field_6C )//???
5655 {
5656 new_party_x = stru_721530.normal2.x;
5657 new_party_y = stru_721530.normal2.y;
5658 new_party_z = stru_721530.normal2.z - stru_721530.prolly_normal_d - 1;
5659 break;
5660 }
5661 new_party_x += fixpoint_mul(stru_721530.field_7C, stru_721530.direction.x);
5662 new_party_y += fixpoint_mul(stru_721530.field_7C, stru_721530.direction.y);
5663 uSectorID = stru_721530.uSectorID;
5664 stru_721530.field_70 += stru_721530.field_7C;
5665 unsigned long long v87 = new_party_z + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z);
5666 if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Actor)//при столкновении с монстром
5667 {
5668 if ( pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime > 0 )
5669 pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
5670 viewparams->bRedrawGameUI = true;
5671 }
5672 else if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Decoration)//при столкновении с декорацией
5673 {
5674 v54 = stru_5C6E00->Atan2(new_party_x - pLevelDecorations[stru_721530.uFaceID >> 3].vPosition.x,
5675 new_party_y - pLevelDecorations[stru_721530.uFaceID >> 3].vPosition.y);
5676 v2 = fixpoint_mul(stru_5C6E00->Cos(v54), integer_sqrt(v2 * v2 + v1 * v1));
5677 v1 = fixpoint_mul(stru_5C6E00->Sin(v54), integer_sqrt(v2 * v2 + v1 * v1));
5678 }
5679 else if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_BModel)//при столкновении с bmodel
5680 {
5681 pFace = &pIndoor->pFaces[(signed int)stru_721530.uFaceID >> 3];
5682 if ( pFace->uPolygonType == POLYGON_Floor )// если bmodel - пол
5683 {
5684 if ( pParty->uFallSpeed < 0 )
5685 pParty->uFallSpeed = 0;
5686 v87 = pIndoor->pVertices[*pFace->pVertexIDs].z + 1;
5687 if ( pParty->uFallStartY - v87 < 512 )
5688 pParty->uFallStartY = v87;
5689 if ( v2 * v2 + v1 * v1 < 400 )
5690 {
5691 v1 = 0;
5692 v2 = 0;
5693 }
5694 if ( pParty->floor_face_pid != PID_ID(stru_721530.uFaceID) && pFace->Pressure_Plate() )
5695 uFaceEvent = pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID;
5696 }
5697 else// если не пол
5698 {
5699 v46 = pParty->uFallSpeed * pFace->pFacePlane_old.vNormal.z;
5700 if ( pFace->uPolygonType != POLYGON_InBetweenFloorAndWall )//полез на холм
5701 {
5702 v80 = abs(v1 * pFace->pFacePlane_old.vNormal.y + v46 + v2 * pFace->pFacePlane_old.vNormal.x) >> 16;
5703 if ((stru_721530.speed >> 3) > v80 )
5704 v80 = stru_721530.speed >> 3;
5705 v2 += fixpoint_mul(v80, pFace->pFacePlane_old.vNormal.x);
5706 v1 += fixpoint_mul(v80, pFace->pFacePlane_old.vNormal.y);
5707 pParty->uFallSpeed += fixpoint_mul(v80, pFace->pFacePlane_old.vNormal.z);
5708 //v80 = pFace->pFacePlane_old.vNormal.y;
5709 v52 = stru_721530.prolly_normal_d - ((pFace->pFacePlane_old.dist
5710 + v87 * pFace->pFacePlane_old.vNormal.z
5711 + new_party_y * pFace->pFacePlane_old.vNormal.y
5712 + new_party_x * pFace->pFacePlane_old.vNormal.x) >> 16);
5713 if ( v52 > 0 )
5714 {
5715 new_party_x += fixpoint_mul(v52, pFace->pFacePlane_old.vNormal.x);
5716 new_party_y += fixpoint_mul(v52, pFace->pFacePlane_old.vNormal.y);
5717 v87 += fixpoint_mul(v52, pFace->pFacePlane_old.vNormal.z);
5718 }
5719 if ( pParty->floor_face_pid != PID_ID(stru_721530.uFaceID) && pFace->Pressure_Plate() )
5720 uFaceEvent = pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID;
5721 }
5722 if ( pFace->uPolygonType == POLYGON_InBetweenFloorAndWall )
5723 {
5724 v80 = abs(v1 * pFace->pFacePlane_old.vNormal.y + v46 + v2 * pFace->pFacePlane_old.vNormal.x) >> 16;
5725 if ((stru_721530.speed >> 3) > v80 )
5726 v80 = stru_721530.speed >> 3;
5727 v2 += fixpoint_mul(v80, pFace->pFacePlane_old.vNormal.x);
5728 v1 += fixpoint_mul(v80, pFace->pFacePlane_old.vNormal.y);
5729 pParty->uFallSpeed += fixpoint_mul(v80, pFace->pFacePlane_old.vNormal.z);
5730 if ( v2 * v2 + v1 * v1 >= 400 )
5731 {
5732 if ( pParty->floor_face_pid != PID_ID(stru_721530.uFaceID) && pFace->Pressure_Plate() )
5733 uFaceEvent = pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID;
5734 }
5735 else
5736 {
5737 v2 = 0;
5738 v1 = 0;
5739 pParty->uFallSpeed = 0;
5740 }
5741 }
5742 }
5743 }
5744 v2 = fixpoint_mul(58500, v2);
5745 v1 = fixpoint_mul(58500, v1);
5746 pParty->uFallSpeed = fixpoint_mul(58500, pParty->uFallSpeed);
5747 }
5748
5749 // //Воспроизведение звуков ходьбы/бега-------------------------
5750 uint pX_ = abs(pParty->vPosition.x - new_party_x);
5751 uint pY_ = abs(pParty->vPosition.y - new_party_y);
5752 uint pZ_ = abs(pParty->vPosition.z - new_party_z);
5753 if ( bWalkSound && pParty->walk_sound_timer <= 0 )
5754 {
5755 pAudioPlayer->_4AA258(804);//stop sound
5756 if ( party_running_flag && (!hovering || not_high_fall) ) //Бег и (не прыжок или не высокое падение )
5757 {
5758 if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) >= 16 )
5759 {
5760 if ( on_water )
5761 pAudioPlayer->PlaySound(SOUND_RunAlongWater, 804, 1, -1, 0, 0, 0, 0);
5762 else if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_INDOOR_CARPET )//по ковру
5763 pAudioPlayer->PlaySound((SoundID)50, 804, 1, -1, 0, 0, 0, 0);
5764 else
5765 pAudioPlayer->PlaySound(SOUND_RunAlong3DModel, 804, 1, -1, 0, 0, 0, 0);
5766 pParty->walk_sound_timer = 96;//64
5767 }
5768 }
5769 else if ( party_walking_flag && (!hovering || not_high_fall) )//Ходьба и (не прыжок или не высокое падение)
5770 {
5771 if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) >= 8 )
5772 {
5773 if ( on_water )
5774 pAudioPlayer->PlaySound(SOUND_WalkAlongWater, 804, 1, -1, 0, 0, 0, 0);
5775 else if ( pIndoor->pFaces[uFaceID].uAttributes & FACE_INDOOR_CARPET )//по ковру
5776 pAudioPlayer->PlaySound((SoundID)89, 804, 1, -1, 0, 0, 0, 0);
5777 else
5778 pAudioPlayer->PlaySound(SOUND_WalkAlong3DModel, 804, 1, -1, 0, 0, 0, 0);
5779 pParty->walk_sound_timer = 144;//64
5780 }
5781 }
5782 }
5783 if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) < 8 )//отключить звук ходьбы при остановке
5784 pAudioPlayer->_4AA258(804);
5785 //-------------------------------------------------------------
5786 if ( !hovering || !not_high_fall )
5787 pParty->uFlags &= ~PARTY_FLAGS_1_FALLING;
5788 else
5789 pParty->uFlags |= PARTY_FLAGS_1_FALLING;
5790 pParty->uFlags &= ~PARTY_FLAGS_1_BURNING;
5791 pParty->vPosition.x = new_party_x;
5792 pParty->vPosition.z = new_party_z;
5793 pParty->vPosition.y = new_party_y;
5794 //pParty->uFallSpeed = v89;
5795 if ( !hovering && pIndoor->pFaces[uFaceID].uAttributes & FACE_INDOOR_LAVA )
5796 pParty->uFlags |= PARTY_FLAGS_1_BURNING;//0x200
5797 if (uFaceEvent)
5798 EventProcessor(uFaceEvent, 0, 1);
5799 }
5800
5801 //----- (00449A49) --------------------------------------------------------
5802 void Door_switch_animation(unsigned int uDoorID, int a2)
5803 {
5804 int old_state; // eax@1
5805 signed int door_id; // esi@2
5806
5807 if ( !pIndoor->pDoors )
5808 return;
5809 for ( door_id = 0; door_id < 200; ++door_id )
5810 {
5811 if ( pIndoor->pDoors[door_id].uDoorID == uDoorID )
5812 break;
5813 }
5814 if ( door_id >= 200 )
5815 {
5816 Error("Unable to find Door ID: %i!", uDoorID);
5817 }
5818 old_state = pIndoor->pDoors[door_id].uState;
5819 //old_state: 0 - в нижнем положении/закрыто
5820 // 2 - в верхнем положении/открыто,
5821 //a2: 1 - открыть
5822 // 2 - опустить/поднять
5823 if ( a2 == 2 )
5824 {
5825 if ( pIndoor->pDoors[door_id].uState == BLVDoor::Closing || pIndoor->pDoors[door_id].uState == BLVDoor::Opening )
5826 return;
5827 if ( pIndoor->pDoors[door_id].uState )
5828 {
5829 if ( pIndoor->pDoors[door_id].uState != BLVDoor::Closed && pIndoor->pDoors[door_id].uState != BLVDoor::Closing )
5830 {
5831 pIndoor->pDoors[door_id].uState = BLVDoor::Closing;
5832 if ( old_state == BLVDoor::Open )
5833 {
5834 pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
5835 return;
5836 }
5837 if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
5838 {
5839 pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uOpenSpeed
5840 - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uCloseSpeed)
5841 / 128 << 7) / pIndoor->pDoors[door_id].uOpenSpeed;
5842 return;
5843 }
5844 pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
5845 }
5846 return;
5847 }
5848 }
5849 else
5850 {
5851 if ( a2 == 0 )
5852 {
5853 if ( pIndoor->pDoors[door_id].uState != BLVDoor::Closed && pIndoor->pDoors[door_id].uState != BLVDoor::Closing )
5854 {
5855 pIndoor->pDoors[door_id].uState = BLVDoor::Closing;
5856 if ( old_state == BLVDoor::Open )
5857 {
5858 pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
5859 return;
5860 }
5861 if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
5862 {
5863 pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uOpenSpeed
5864 - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uCloseSpeed)
5865 / 128 << 7) / pIndoor->pDoors[door_id].uOpenSpeed;
5866 return;
5867 }
5868 pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
5869 }
5870 return;
5871 }
5872 if ( a2 != 1 )
5873 return;
5874 }
5875 if ( old_state != BLVDoor::Open && old_state != BLVDoor::Opening )
5876 {
5877 pIndoor->pDoors[door_id].uState = BLVDoor::Opening;
5878 if ( old_state == BLVDoor::Closed )
5879 {
5880 pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
5881 return;
5882 }
5883 if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
5884 {
5885 pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uCloseSpeed
5886 - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uOpenSpeed)
5887 / 128 << 7) / pIndoor->pDoors[door_id].uCloseSpeed;
5888 return;
5889 }
5890 pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
5891 }
5892 return;
5893 }
5894
5895
5896 //----- (004088E9) --------------------------------------------------------
5897 int __fastcall sub_4088E9(int x1, int y1, int x2, int y2, int x3, int y3)
5898 {
5899 signed int result; // eax@1
5900
5901 result = integer_sqrt(abs(x2 - x1) * abs(x2 - x1) + abs(y2 - y1) * abs(y2 - y1));
5902 if ( result )
5903 result = abs(((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / result);
5904 return result;
5905 }
5906
5907 //----- (00450DA3) --------------------------------------------------------
5908 int GetAlertStatus()
5909 {
5910 int result; // eax@2
5911
5912 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
5913 result = pOutdoor->ddm.field_C_alert;
5914 else
5915 result = uCurrentlyLoadedLevelType == LEVEL_Outdoor ? pIndoor->dlv.field_C_alert : 0;
5916 return result;
5917 }
5918
5919
5920 //----- (0045063B) --------------------------------------------------------
5921 int __fastcall _45063B_spawn_some_monster(MapInfo *a1, int a2)
5922 {
5923 int result; // eax@8
5924 int v6; // edi@11
5925 int v7; // ebx@11
5926 int v8; // edi@11
5927 int v9; // ebx@12
5928 int v10; // eax@12
5929 char v11; // zf@16
5930 int v12; // edi@20
5931 int v13; // eax@20
5932 int v14; // ebx@20
5933 int v15; // eax@20
5934 int v16; // eax@20
5935 int v17; // eax@20
5936 int v18; // eax@21
5937 SpawnPointMM7 v19; // [sp+Ch] [bp-38h]@1
5938 int v22; // [sp+2Ch] [bp-18h]@3
5939 unsigned int uFaceID; // [sp+38h] [bp-Ch]@10
5940 int v26; // [sp+3Ch] [bp-8h]@11
5941 int v27; // [sp+40h] [bp-4h]@11
5942
5943 if (!uNumActors)
5944 return 0;
5945
5946 for ( uint mon_id = 0; mon_id < uNumActors; ++mon_id )
5947 {
5948 if ((pActors[mon_id].pMonsterInfo.uID < 121 || pActors[mon_id].pMonsterInfo.uID > 123) && // Dwarf FemaleC A-C
5949 (pActors[mon_id].pMonsterInfo.uID < 124 || pActors[mon_id].pMonsterInfo.uID > 126) && // Dwarf MaleA A-C
5950 (pActors[mon_id].pMonsterInfo.uID < 133 || pActors[mon_id].pMonsterInfo.uID > 135) && // Peasant Elf FemaleA A-C
5951 pActors[mon_id].CanAct())
5952 {
5953 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
5954 {
5955 v22 = 0;
5956 uint face_id = 0;
5957 for ( face_id; face_id < 100; ++face_id )
5958 {
5959 v6 = rand() % 1024 + 512;
5960 v7 = rand() % (signed int)stru_5C6E00->uIntegerDoublePi;
5961 v19.vPosition.x = pParty->vPosition.x + fixpoint_mul(stru_5C6E00->Cos(v7), v6);
5962 v8 = 0;
5963 v19.uIndex = a2;
5964 v19.vPosition.y = fixpoint_mul(stru_5C6E00->Sin(v7), v6) + pParty->vPosition.y;
5965 v19.vPosition.z = pParty->vPosition.z;
5966 v26 = 0;
5967 v27 = 0;
5968 v19.vPosition.z = ODM_GetFloorLevel(v19.vPosition.x, v19.vPosition.y, pParty->vPosition.z, 0, &v26, &v27, 0);
5969 for( int i = 0; i < pOutdoor->uNumBModels; i++ )
5970 {
5971 v9 = abs(v19.vPosition.y - pOutdoor->pBModels[i].vBoundingCenter.y);
5972 v10 = abs(v19.vPosition.x - pOutdoor->pBModels[i].vBoundingCenter.x);
5973 if ( int_get_vector_length(v10, v9, 0) < pOutdoor->pBModels[i].sBoundingRadius + 256 )
5974 {
5975 v22 = 1;
5976 break;
5977 }
5978 }
5979 if ( v22 )
5980 {
5981 v11 = face_id == 100;
5982 break;
5983 }
5984 }
5985 v11 = face_id == 100;
5986 }
5987 else if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
5988 {
5989 v22 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
5990 for ( uint i = 0; i < 100; ++i )
5991 {
5992 v12 = rand() % 512 + 256;
5993 v13 = rand();
5994 v14 = v13 % (signed int)stru_5C6E00->uIntegerDoublePi;
5995 v15 = stru_5C6E00->Cos(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
5996 v19.vPosition.x = pParty->vPosition.x + fixpoint_mul(v15, v12);
5997 v16 = stru_5C6E00->Sin(v13 % (signed int)stru_5C6E00->uIntegerDoublePi);
5998 v19.vPosition.y = fixpoint_mul(v16, v12) + pParty->vPosition.y;
5999 v19.vPosition.z = pParty->vPosition.z;
6000 v19.uIndex = a2;
6001 v17 = pIndoor->GetSector(v19.vPosition.x, v19.vPosition.y, pParty->vPosition.z);
6002 if ( v17 == v22 )
6003 {
6004 v18 = BLV_GetFloorLevel(v19.vPosition.x, v19.vPosition.y, v19.vPosition.z, v17, &uFaceID);
6005 v19.vPosition.z = v18;
6006 if ( v18 != -30000 )
6007 {
6008 if ( abs(v18 - pParty->vPosition.z) <= 1024 )
6009 break;
6010 }
6011 }
6012 }
6013 v11 = v26 == 100;
6014 }
6015 if ( v11 )
6016 result = 0;
6017 else
6018 {
6019 SpawnEncounter(a1, &v19, 0, 0, 1);
6020 result = a2;
6021 }
6022 }
6023
6024 //break;
6025 //v22 = v3->pMonsterInfo.uID - 1;
6026 //v4 = (signed __int64)((double)v22 * 0.3333333333333333);
6027 //if ( (int)v4 != 40 )
6028 //{
6029 // if ( (int)v4 != 41 && (int)v4 != 44 && v3->CanAct() )
6030 // break;
6031 //}
6032 //++v2;
6033 //++v3;
6034 //if ( v2 >= (signed int)uNumActors )
6035 // goto LABEL_8;
6036 }
6037 return result;
6038 }
6039
6040 //----- (00450521) --------------------------------------------------------
6041 int __fastcall sub_450521_ProllyDropItemAt(int ecx0, signed int a2, int a3, int a4, int a5, unsigned __int16 a6)
6042 {
6043 int v6; // edi@1
6044 int v7; // esi@1
6045 signed int v8; // edi@1
6046 unsigned __int16 v9; // cx@1
6047 // char *v10; // edx@2
6048 unsigned __int16 v11; // ax@5
6049 SpriteObject a1; // [sp+8h] [bp-70h]@1
6050
6051 v6 = ecx0;
6052 v7 = a2;
6053 pItemsTable->GenerateItem(v6, v7, &a1.stru_24);
6054 v8 = 0;
6055 v9 = pItemsTable->pItems[a1.stru_24.uItemID].uSpriteID;
6056 a1.uType = pItemsTable->pItems[a1.stru_24.uItemID].uSpriteID;
6057 v11 = 0;
6058 for( int i = 0; i < pObjectList->uNumObjects; i++ )
6059 {
6060 if( v9 == pObjectList->pObjects[i].uObjectID )
6061 {
6062 v11 = i;
6063 break;
6064 }
6065 }
6066 a1.uObjectDescID = v11;
6067 a1.vPosition.y = a4;
6068 a1.vPosition.x = a3;
6069 a1.vPosition.z = a5;
6070 a1.uFacing = a6;
6071 a1.uAttributes = 0;
6072 a1.uSectorID = pIndoor->GetSector(a3, a4, a5);
6073 a1.uSpriteFrameID = 0;
6074 return a1.Create(0, 0, 0, 0);
6075 }
6076
6077 //----- (004075DB) --------------------------------------------------------
6078 bool __fastcall sub_4075DB(int x, int y, int z, BLVFace *face)
6079 {
6080 int v8; // edi@2
6081 signed int v25; // eax@22
6082 bool result; // eax@25
6083 signed int a3a; // [sp+24h] [bp+8h]@14
6084 int a4a; // [sp+28h] [bp+Ch]@2
6085
6086 std::array<int, 52> dword_4F5CC8_ys; // idb
6087 std::array<int, 52> dword_4F5D98_xs; // idb
6088
6089 //__debugbreak();
6090
6091 if (face->uAttributes & FACE_XY_PLANE)
6092 {
6093 a4a = x;
6094 v8 = y;
6095 for (int i = 0; i < face->uNumVertices; i++)
6096 {
6097 dword_4F5D98_xs[i] = pIndoor->pVertices[face->pVertexIDs[i]].x;
6098 dword_4F5CC8_ys[i] = pIndoor->pVertices[face->pVertexIDs[i]].y;
6099 }
6100 }
6101 else
6102 {
6103 v8 = z;
6104 if (face->uAttributes & FACE_XZ_PLANE)
6105 {
6106 a4a = x;
6107 for (int i = 0; i < face->uNumVertices; i++)
6108 {
6109 dword_4F5D98_xs[i] = pIndoor->pVertices[face->pVertexIDs[i]].x;
6110 dword_4F5CC8_ys[i] = pIndoor->pVertices[face->pVertexIDs[i]].z;
6111 }
6112 }
6113 else
6114 {
6115 a4a = y;
6116 for (int i = 0; i < face->uNumVertices; i++)
6117 {
6118 dword_4F5D98_xs[i] = pIndoor->pVertices[face->pVertexIDs[i]].y;
6119 dword_4F5CC8_ys[i] = pIndoor->pVertices[face->pVertexIDs[i]].z;
6120 }
6121 }
6122 }
6123 a3a = 0;
6124 dword_4F5D98_xs[face->uNumVertices] = dword_4F5D98_xs[0];
6125 dword_4F5CC8_ys[face->uNumVertices] = dword_4F5CC8_ys[0];
6126 for (int i = 0; i < face->uNumVertices && a3a < 2; i++)
6127 {
6128 if (dword_4F5CC8_ys[i] >= v8 ^ (dword_4F5CC8_ys[i + 1] >= v8))
6129 {
6130 //if( dword_4F5D98_xs[i + 1] >= a4a || dword_4F5D98_xs[i] >= a4a)
6131 if (!(dword_4F5D98_xs[i + 1] >= a4a && dword_4F5D98_xs[i] < a4a))
6132 {
6133 if ((dword_4F5D98_xs[i + 1] < a4a && dword_4F5D98_xs[i] >= a4a))
6134 ++a3a;
6135 //|| (v25 = dword_4F5D98_xs[i + 1] - dword_4F5D98_xs[i],LODWORD(v26) = v25 << 16, HIDWORD(v26) = v25 >> 16,
6136 //dword_4F5D98_xs[i] + ((signed int)(((unsigned __int64)(v26 / (dword_4F5CC4_ys[i + 2] - dword_4F5CC4_ys[i + 1])* ((v8 - dword_4F5CC4_ys[i + 1]) << 16)) >> 16)
6137 // + 32768) >> 16) >= a4a) )
6138 else
6139 {
6140 v25 = fixpoint_div(dword_4F5D98_xs[i + 1] - dword_4F5D98_xs[i], dword_4F5CC8_ys[i + 1] - dword_4F5CC8_ys[i]);
6141 if (dword_4F5D98_xs[i] + (fixpoint_mul(v25, (v8 - dword_4F5CC8_ys[i]) << 16) + 0x8000 >> 16) >= a4a)
6142 ++a3a;
6143 }
6144 }
6145 }
6146 }
6147 result = 1;
6148 if (a3a != 1)
6149 result = 0;
6150 return result;
6151 }
6152
6153 //----- (004077F1) --------------------------------------------------------
6154 bool __fastcall sub_4077F1(int a1, int a2, int a3, ODMFace *face, BSPVertexBuffer *a5)
6155 {
6156 int a4a; // [sp+28h] [bp+Ch]@2
6157 signed int a5a; // [sp+2Ch] [bp+10h]@14
6158
6159 std::array<int, 52> dword_4F5B24_ys; // idb
6160 std::array<int, 52> dword_4F5BF4_xs; // idb
6161
6162 //__debugbreak(); //срабатывает при нападении стрекозавров с огнём
6163
6164 if (face->uAttributes & FACE_XY_PLANE)
6165 {
6166 a4a = a1;
6167 a3 = a2;
6168 for (int i = 0; i < face->uNumVertices; i++)
6169 {
6170 dword_4F5BF4_xs[i + 1] = a5->pVertices[face->pVertexIDs[i]].x;
6171 dword_4F5B24_ys[i + 1] = a5->pVertices[face->pVertexIDs[i]].y;
6172 }
6173 }
6174 else
6175 {
6176 if (face->uAttributes & FACE_XY_PLANE)
6177 {
6178 a4a = a1;
6179 for (int i = 0; i < face->uNumVertices; i++)
6180 {
6181 dword_4F5BF4_xs[i + 1] = a5->pVertices[face->pVertexIDs[i]].x;
6182 dword_4F5B24_ys[i + 1] = a5->pVertices[face->pVertexIDs[i]].z;
6183 }
6184 }
6185 else
6186 {
6187 a4a = a2;
6188 for (int i = 0; i < face->uNumVertices; i++)
6189 {
6190 dword_4F5BF4_xs[i + 1] = a5->pVertices[face->pVertexIDs[i]].y;
6191 dword_4F5B24_ys[i + 1] = a5->pVertices[face->pVertexIDs[i]].z;
6192 }
6193 }
6194 }
6195 a5a = 0;
6196 dword_4F5BF4_xs[face->uNumVertices + 1] = dword_4F5BF4_xs[1];
6197 dword_4F5B24_ys[face->uNumVertices + 1] = dword_4F5B24_ys[1];
6198 for (int i = 0; i < face->uNumVertices; i++)
6199 {
6200 if (a5a >= 2)
6201 break;
6202 if (dword_4F5B24_ys[i + 1] >= a3 ^ (dword_4F5B24_ys[i + 2] >= a3))
6203 {
6204 if (dword_4F5BF4_xs[i + 2] >= a4a || dword_4F5BF4_xs[i] >= a4a)
6205 {
6206 if (dword_4F5BF4_xs[i + 2] >= a4a && dword_4F5BF4_xs[i + 1] >= a4a)
6207 ++a5a;
6208 else
6209 {
6210 //v23 = (__int64)(dword_4F5BF4_xs[i + 2] - dword_4F5BF4_xs[i + 1]) << 16;
6211 __int64 _a = dword_4F5B24_ys[i + 2] - dword_4F5B24_ys[i + 1];
6212 __int64 _b = (__int64)(a3 - dword_4F5B24_ys[i + 1]) << 16;
6213
6214 if (dword_4F5BF4_xs[i + 1] + ((((((__int64)(dword_4F5BF4_xs[i + 2] - dword_4F5BF4_xs[i + 1]) << 16) / _a * _b) >> 16) + 0x8000) >> 16) >= a4a)
6215 ++a5a;
6216 }
6217 }
6218 }
6219 }
6220
6221 if (a5a != 1)
6222 return false;
6223 return true;
6224
6225 }
6226
6227 //----- (0049B04D) --------------------------------------------------------
6228 void stru154::GetFacePlaneAndClassify(ODMFace *a2, BSPVertexBuffer *a3)
6229 {
6230 Vec3_float_ v; // [sp+4h] [bp-Ch]@1
6231 float v7;
6232
6233 v.x = 0.0;
6234 v.y = 0.0;
6235 v.z = 0.0;
6236 GetFacePlane(a2, a3, &v, &v7);
6237
6238 if (fabsf(a2->pFacePlane.vNormal.z) < 1e-6f)
6239 polygonType = POLYGON_VerticalWall;
6240 else if (fabsf(a2->pFacePlane.vNormal.x) < 1e-6f &&
6241 fabsf(a2->pFacePlane.vNormal.y) < 1e-6f)
6242 polygonType = POLYGON_Floor;
6243 else
6244 polygonType = POLYGON_InBetweenFloorAndWall;
6245
6246 face_plane.vNormal.x = v.x;
6247 face_plane.vNormal.y = v.y;
6248 face_plane.vNormal.z = v.z;
6249 face_plane.dist = v7;
6250 }
6251
6252 //----- (0049B0C9) --------------------------------------------------------
6253 void stru154::ClassifyPolygon(Vec3_float_ *pNormal, float dist)
6254 {
6255 if (fabsf(pNormal->z) < 1e-6f)
6256 polygonType = POLYGON_VerticalWall;
6257 else if (fabsf(pNormal->x) < 1e-6f &&
6258 fabsf(pNormal->y) < 1e-6f)
6259 polygonType = POLYGON_Floor;
6260 else
6261 polygonType = POLYGON_InBetweenFloorAndWall;
6262
6263 face_plane.vNormal.x = pNormal->x;
6264 face_plane.dist = dist;
6265 face_plane.vNormal.y = pNormal->y;
6266 face_plane.vNormal.z = pNormal->z;
6267 }
6268
6269 //----- (0049B13D) --------------------------------------------------------
6270 void stru154::GetFacePlane(ODMFace *pFace, BSPVertexBuffer *pVertices, Vec3_float_ *pOutNormal, float *pOutDist)
6271 {
6272 Vec3_float_ *v19; // eax@3
6273 Vec3_float_ v2; // [sp+4h] [bp-64h]@3
6274 float v26; // [sp+1Ch] [bp-4Ch]@3
6275 float v27; // [sp+20h] [bp-48h]@3
6276 float v28; // [sp+24h] [bp-44h]@3
6277 Vec3_float_ v1; // [sp+40h] [bp-28h]@1
6278 Vec3_float_ v38; // [sp+58h] [bp-10h]@3
6279
6280 v1.x = 0.0;
6281 v1.y = 0.0;
6282 v1.z = 0.0;
6283
6284 if (pFace->uNumVertices >= 2)
6285 {
6286 for (int i = 0; i < pFace->uNumVertices - 2; i++)
6287 {
6288 v1.x = pVertices->pVertices[pFace->pVertexIDs[i + 1]].x - pVertices->pVertices[pFace->pVertexIDs[i]].x;
6289 v1.y = pVertices->pVertices[pFace->pVertexIDs[i + 1]].y - pVertices->pVertices[pFace->pVertexIDs[i]].y;
6290 v1.z = pVertices->pVertices[pFace->pVertexIDs[i + 1]].z - pVertices->pVertices[pFace->pVertexIDs[i]].z;
6291
6292 v26 = pVertices->pVertices[pFace->pVertexIDs[i + 2]].x - pVertices->pVertices[pFace->pVertexIDs[i + 1]].x;
6293 v27 = pVertices->pVertices[pFace->pVertexIDs[i + 2]].y - pVertices->pVertices[pFace->pVertexIDs[i + 1]].y;
6294 v28 = pVertices->pVertices[pFace->pVertexIDs[i + 2]].z - pVertices->pVertices[pFace->pVertexIDs[i + 1]].z;
6295
6296 v19 = Vec3_float_::Cross(&v1, &v2, v26, v27, v28);
6297 v38.x = v19->x;
6298 v38.y = v19->y;
6299 v38.z = v19->z;
6300 if (v38.x != 0.0 || v38.y != 0.0 || v38.z != 0.0)
6301 {
6302 v38.Normalize();
6303
6304 pOutNormal->x = v38.x;
6305 pOutNormal->y = v38.y;
6306 pOutNormal->z = v38.z;
6307
6308 *pOutDist = -(pVertices->pVertices[pFace->pVertexIDs[i]].x * v38.x
6309 + pVertices->pVertices[pFace->pVertexIDs[i]].y * v38.y
6310 + pVertices->pVertices[pFace->pVertexIDs[i]].z * v38.z);
6311 return;
6312 }
6313 }
6314 }
6315
6316 pOutNormal->x = (double)(pFace->pFacePlane.vNormal.x & 0xFFFF) / 65535.0f + (double)(pFace->pFacePlane.vNormal.x >> 16);
6317 pOutNormal->y = (double)(pFace->pFacePlane.vNormal.y & 0xFFFF) / 65535.0f + (double)(pFace->pFacePlane.vNormal.y >> 16);
6318 pOutNormal->z = (double)(pFace->pFacePlane.vNormal.z & 0xFFFF) / 65535.0f + (double)(pFace->pFacePlane.vNormal.z >> 16);
6319 *pOutDist = (double)(pFace->pFacePlane.dist & 0xFFFF) / 65535.0f + (double)(pFace->pFacePlane.dist >> 16);
6320 }
6321
6322 //----- (0043F515) --------------------------------------------------------
6323 void FindBillboardsLightLevels_BLV()
6324 {
6325 for (uint i = 0; i < uNumBillboardsToDraw; ++i)
6326 {
6327 if (pBillboardRenderList[i].field_1E & 2 || uCurrentlyLoadedLevelType == LEVEL_Indoor && !pBillboardRenderList[i].uIndoorSectorID)
6328 pBillboardRenderList[i].dimming_level = 0;
6329 else
6330 pBillboardRenderList[i].dimming_level = _43F55F_get_billboard_light_level(&pBillboardRenderList[i], -1);
6331 }
6332 }
6333
6334 //----- (0047272C) --------------------------------------------------------
6335 int collide_against_floor_approximate(int x, int y, int z, unsigned int *pSectorID, unsigned int *pFaceID)
6336 {
6337 int result; // eax@1
6338
6339 *pSectorID = pIndoor->GetSector(x - 2, y, z + 40);
6340 result = collide_against_floor(x - 2, y, z + 40, pSectorID, pFaceID);
6341 if (result == -30000 || !*pSectorID)
6342 {
6343 *pSectorID = pIndoor->GetSector(x + 2, y, z + 40);
6344 result = collide_against_floor(x + 2, y, z + 40, pSectorID, pFaceID);
6345 if (result == -30000 || !*pSectorID)
6346 {
6347 *pSectorID = pIndoor->GetSector(x, y - 2, z + 40);
6348 result = collide_against_floor(x, y - 2, z + 40, pSectorID, pFaceID);
6349 if (result == -30000 || !*pSectorID)
6350 {
6351 *pSectorID = pIndoor->GetSector(x, y + 2, z + 40);
6352 result = collide_against_floor(x, y + 2, z + 40, pSectorID, pFaceID);
6353 if (result == -30000 || !*pSectorID)
6354 {
6355 *pSectorID = pIndoor->GetSector(x, y, z + 140);
6356 result = collide_against_floor(x, y, z + 140, pSectorID, pFaceID);
6357 }
6358 }
6359 }
6360 }
6361 return result;
6362 }
6363
6364 //----- (0047050A) --------------------------------------------------------
6365 int stru141_actor_collision_object::_47050A(int dt)
6366 {
6367 int v7; // eax@1
6368 signed int result; // eax@4
6369 int v17; // eax@5
6370 int v18; // eax@7
6371 int v21; // eax@9
6372 int v22; // eax@11
6373
6374 int speed = 1 | integer_sqrt(this->velocity.z * this->velocity.z + this->velocity.y * this->velocity.y + this->velocity.x * this->velocity.x);
6375
6376 this->direction.x = 65536 / speed * this->velocity.x;
6377 this->direction.y = 65536 / speed * this->velocity.y;
6378 this->direction.z = 65536 / speed * this->velocity.z;
6379
6380 this->speed = speed;
6381 this->inv_speed = 65536 / speed;
6382
6383 if (dt)
6384 v7 = dt;
6385 else
6386 v7 = pEventTimer->dt_in_some_format;
6387
6388 //v8 = fixpoint_mul(v7, speed) - this->field_70; // speed * dt - something
6389 this->field_6C = fixpoint_mul(v7, speed) - this->field_70;
6390 if (this->field_6C > 0)
6391 {
6392 //v10 = fixpoint_mul(v8, this->direction.x) + this->normal.x;
6393 this->field_4C = fixpoint_mul(this->field_6C, this->direction.x) + this->normal.x;
6394 this->normal2.x = fixpoint_mul(this->field_6C, this->direction.x) + this->normal.x;
6395 //v11 = fixpoint_mul(this->field_6C, this->direction.y) + this->normal.y;
6396 this->field_50 = fixpoint_mul(this->field_6C, this->direction.y) + this->normal.y;
6397 this->normal2.y = fixpoint_mul(this->field_6C, this->direction.y) + this->normal.y;
6398 this->normal2.z = fixpoint_mul(this->field_6C, this->direction.z) + this->normal.z;
6399 //v12 = this->position.z;
6400 //v13 = this->normal.x;
6401 //v14 = this->normal2.x;
6402 //v15 = this->prolly_normal_d;
6403 //v16 = this->position.z + fixpoint_mul(this->field_6C, this->direction.z);
6404 //v28 = this->position.z + fixpoint_mul(this->field_6C, this->direction.z);
6405 this->field_54 = this->position.z + fixpoint_mul(this->field_6C, this->direction.z);
6406 v17 = this->normal.x;
6407 if (v17 >= this->normal2.x)
6408 v17 = this->normal2.x;
6409 this->sMaxX = v17 - this->prolly_normal_d;
6410 v18 = this->prolly_normal_d + this->normal.x;
6411 if (this->normal.x <= this->normal2.x)
6412 v18 = this->prolly_normal_d + this->normal2.x;
6413 //v19 = this->normal.y;
6414 //v20 = this->normal2.y;
6415 this->sMinX = v18;
6416 v21 = this->normal.y;
6417 if (v21 >= this->normal2.y)
6418 v21 = this->normal2.y;
6419 this->sMaxY = v21 - this->prolly_normal_d;
6420 v22 = this->prolly_normal_d + this->normal.y;
6421 if (this->normal.y <= this->normal2.y)
6422 v22 = this->normal2.y + this->prolly_normal_d;
6423 //v23 = this->normal2.z;
6424 this->sMinY = v22;
6425 //v24 = this->normal.z;
6426 if (this->normal.z >= this->normal2.z)
6427 this->sMaxZ = this->normal2.z - this->prolly_normal_d;
6428 else
6429 this->sMaxZ = this->normal.z - this->prolly_normal_d;
6430 //this->sMaxZ = v25;
6431 //v26 = this->field_8_radius;
6432 if (this->position.z <= this->position.z + fixpoint_mul(this->field_6C, this->direction.z))
6433 this->sMinZ = (this->position.z + fixpoint_mul(this->field_6C, this->direction.z)) + this->field_8_radius;
6434 else
6435 this->sMinZ = this->position.z + this->field_8_radius;
6436 this->uFaceID = 0;
6437 this->field_80 = -1;
6438 this->field_88 = -1;
6439 //this->sMinZ = v27;
6440 this->field_7C = 0xFFFFFFu;
6441 result = 0;
6442 }
6443 else
6444 result = 1;
6445 return result;
6446 }