comparison Engine/Graphics/Outdoor.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
8 #include "stru6.h"
9 #include "Weather.h"
10 #include "Sprites.h"
11 #include "LightmapBuilder.h"
12 #include "Outdoor.h"
13 #include "Party.h"
14 #include "SpriteObject.h"
15 #include "LOD.h"
16 #include "PaletteManager.h"
17 #include "GUIProgressBar.h"
18 #include "AudioPlayer.h"
19 #include "DecorationList.h"
20 #include "OurMath.h"
21 #include "ObjectList.h"
22 #include "Game.h"
23 #include "Actor.h"
24 #include "Chest.h"
25 #include "stru123.h"
26 #include "Timer.h"
27 #include "Viewport.h"
28 #include "Events.h"
29 #include "ParticleEngine.h"
30 #include "TurnEngine.h"
31
32 #include "MM7.h"
33 #include "Lights.h"
34
35 #include "GUIWindow.h"
36 #include "Engine/Graphics/Level/Decoration.h"
37 #include "ZlibWrapper.h"
38 #include "MMT.h"
39
40 MapStartPoint uLevel_StartingPointType; // weak
41
42 OutdoorLocation *pOutdoor = new OutdoorLocation;
43 ODMRenderParams *pODMRenderParams;
44
45
46 stru149 stru_8019C8;
47 std::array<struct Polygon, 2000 + 18000> array_77EC08;
48
49
50 struct FogProbabilityTableEntry
51 {
52 unsigned char small_fog_chance;
53 unsigned char average_fog_chance;
54 unsigned char dense_fog_chance;
55 unsigned char __unused;
56 } fog_probability_table[15] =
57 {
58 { 20, 10, 5, 0}, // MAP_EMERALD_ISLE
59 { 20, 10, 5, 0}, // MAP_HARMONDALE
60 { 20, 10, 5, 0}, // MAP_STEADWICK
61 { 20, 10, 5, 0}, // MAP_PIERPONT
62 { 20, 10, 5, 0}, // MAP_DEYJA
63 { 10, 5, 0, 0}, // MAP_BRAKADA_DESERT
64 { 0, 0, 0, 0}, // MAP_CELESTIA
65 { 0, 0, 0, 0}, // MAP_THE_PIT
66 { 20, 30, 50, 0}, // MAP_EVENMORN_ISLE
67 { 30, 20, 10, 0}, // MAP_MOUNT_NIGHON
68 { 10, 5, 0, 0}, // MAP_BARROW_DOWNS
69 { 20, 10, 5, 0}, // MAP_LAND_OF_GIANTS
70 { 20, 10, 5, 0}, // MAP_TATALIA
71 { 20, 10, 5, 0}, // MAP_AVLEE
72 { 0, 100, 0, 0} // MAP_SHOALS
73 };
74
75 //for future sky textures?
76 std::array<int, 9> dword_4EC268={{3,3,3,3,3,3,3,3,3}}; // weak
77 std::array<int, 7> dword_4EC28C={{3,3,3,3,3,3,3}}; // weak
78 int dword_4EC2A8=9; // weak
79 int dword_4EC2AC=7; // weak
80
81
82
83 //----- (0047A59E) --------------------------------------------------------
84 void OutdoorLocation::ExecDraw(unsigned int bRedraw)
85 {
86
87 pGame->pIndoorCameraD3D->debug_flags = 0;
88 if (viewparams->draw_d3d_outlines)
89 pGame->pIndoorCameraD3D->debug_flags |= ODM_RENDER_DRAW_D3D_OUTLINES;
90
91 if (bRedraw || true/*pRenderer->pRenderD3D*/)
92 {
93 //pODMRenderParams->RotationToInts();
94 sub_481ED9_MessWithODMRenderParams();
95 }
96
97 pODMRenderParams->uMapGridCellX = WorldPosToGridCellX(pParty->vPosition.x);
98 pODMRenderParams->uMapGridCellZ = WorldPosToGridCellZ(pParty->vPosition.y);
99 assert(pODMRenderParams->uMapGridCellX <= 127 && pODMRenderParams->uMapGridCellZ <= 127);
100
101 if (bRedraw)
102 {
103 sub_487DA9();
104 }
105 if ( pParty->uCurrentMinute != pOutdoor->uLastSunlightUpdateMinute )
106 pOutdoor->UpdateSunlightVectors();
107 pOutdoor->UpdateFog();
108 //pGame->pIndoorCameraD3D->sr_Reset_list_0037C();
109
110 //if (pRenderer->pRenderD3D) // d3d - redraw always
111 {
112 pRenderer->DrawOutdoorSkyD3D();
113 pRenderer->DrawBuildingsD3D();
114 pRenderer->RenderTerrainD3D();
115 //pRenderer->DrawBezierTerrain();
116 }
117 /*else
118 {
119 if (!bRedraw)
120 pRenderer->OnOutdoorRedrawSW();
121 else
122 {
123 pRenderer->DrawBuildingsSW();
124 pRenderer->DrawBezierTerrain();
125 sr_sub_486F92_MessWithEdgesAndSpans();
126 pODMRenderParams->ApplyLightmapsSW();
127 }
128 }*/
129
130
131 pMobileLightsStack->uNumLightsActive = 0;
132 pStationaryLightsStack->uNumLightsActive = 0;
133 /*if ( !pRenderer->pRenderD3D )
134 {
135 pRenderer->ExecOutdoorDrawSW();
136 pGame->pIndoorCameraD3D->sr_438240_draw_lits();
137 }*/
138 pGame->PushStationaryLights(-1);
139 pGame->PrepareBloodsplats();
140 if (bRedraw)
141 pOutdoor->UpdateDiscoveredArea(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y), 1);
142 pGame->uFlags2 &= 0xFFFFFFFEu;
143 if (/*pRenderer->pRenderD3D*/true && pRenderer->bUsingSpecular)
144 pGame->pLightmapBuilder->uFlags |= 1;
145 else
146 pGame->pLightmapBuilder->uFlags &= 0xFFFFFFFEu;
147
148 uNumDecorationsDrawnThisFrame = 0;
149 uNumSpritesDrawnThisFrame = 0;
150 uNumBillboardsToDraw = 0;
151
152 PrepareActorsDrawList();
153 if (!pODMRenderParams->bDoNotRenderDecorations)
154 pRenderer->PrepareDecorationsRenderList_ODM();
155
156 pRenderer->DrawSpriteObjects_ODM();
157 pRenderer->TransformBillboardsAndSetPalettesODM();
158 }
159
160
161 //----- (00441CFF) --------------------------------------------------------
162 void OutdoorLocation::Draw()
163 {
164 bool redrawWorld = true;
165 if ( !(pParty->uFlags & 2) && !(pGame->uFlags2 & 1) )
166 redrawWorld = false;
167 pOutdoor->ExecDraw(redrawWorld);
168
169 pGame->DrawParticles();
170 //pWeather->Draw();//если раскомментировать скорость снега быстрее
171 trail_particle_generator.UpdateParticles();
172 }
173
174 //----- (00488E23) --------------------------------------------------------
175 double OutdoorLocation::GetFogDensityByTime()
176 {
177 if ( pParty->uCurrentHour < 5 )//ночь
178 {
179 pWeather->bNight = true;
180 return 60.0 * 0.016666668;
181 }
182 else if ( pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 6 )//рассвет
183 {
184 pWeather->bNight = false;
185 return (60.0 - (double)(60 * pParty->uCurrentHour + pParty->uCurrentMinute - 300)) * 0.016666668;
186 }
187 else if ( pParty->uCurrentHour >= 6 && pParty->uCurrentHour < 20 )//день
188 {
189 pWeather->bNight = false;
190 return 0.0;
191 }
192 else if ( pParty->uCurrentHour >= 20 && pParty->uCurrentHour < 21 )//сумерки
193 {
194 pWeather->bNight = false;
195 return ((double)(pParty->uCurrentHour - 20) * 60.0 + (double)(signed int)pParty->uCurrentMinute) * 0.016666668;
196 }
197 else//ночь
198 {
199 pWeather->bNight = true;
200 return 60.0 * 0.016666668;
201 }
202 }
203
204 //----- (00488EB1) --------------------------------------------------------
205 int OutdoorLocation::GetSomeOtherTileInfo(int sX, int sY)
206 {
207 //OutdoorLocation *v3; // esi@1
208 unsigned int v4; // edi@1
209 unsigned int v5; // eax@1
210 // int result; // eax@5
211
212 /* v3 = this;
213 v4 = WorldPosToGridCellZ(sY);
214 v5 = WorldPosToGridCellX(sX);
215 if ( (v5 & 0x80000000u) != 0 || (signed int)v5 > 127 || (v4 & 0x80000000u) != 0 || (signed int)v4 > 127 )
216 result = 0;
217 else
218 result = ActuallyGetSomeOtherTileInfo(v5, v4);
219 return result;*/
220 v4 = WorldPosToGridCellZ(sY);
221 v5 = WorldPosToGridCellX(sX);
222 if ( v5 < 0 || v5 > 127 || v4 < 0 || v4 > 127 )
223 return 0;
224 return ActuallyGetSomeOtherTileInfo(v5, v4);
225 }
226 // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
227 // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
228
229 //----- (00488EEF) --------------------------------------------------------
230 unsigned int OutdoorLocation::GetTileTexture(signed int sX, signed int sY)
231 {
232 //OutdoorLocation *v3; // esi@1
233 signed int v4; // edi@1
234 signed int v5; // eax@1
235 // unsigned int result; // eax@5
236
237 /*v3 = this;
238 v4 = WorldPosToGridCellZ(sZ);
239 v5 = WorldPosToGridCellX(sX);
240 if ( v5< 0 || (signed int)v5 > 127 || v4 < 0 || (signed int)v4 > 127 )//if ( (v5 & 0x80000000u) != 0 || (signed int)v5 > 127 || (v4 & 0x80000000u) != 0 || (signed int)v4 > 127 )
241 result = -1;
242 else
243 result = DoGetTileTexture(v5, v4);
244 return result;*/
245 v4 = WorldPosToGridCellZ(sY);
246 v5 = WorldPosToGridCellX(sX);
247 if ( v5 < 0 || v5 > 127 || v4 < 0 || v4 > 127 )
248 return -1;
249 return DoGetTileTexture(v5, v4);
250 }
251 // 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
252 // 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
253
254 //----- (00488F2E) --------------------------------------------------------
255 int OutdoorLocation::GetHeightOnTerrain(int sX, int sZ)
256 /* Функция предоставляет возможность перемещать камеру таким образом, чтобы она имитировала ходьбу по ландшафту.
257 То есть нам надо менять высоту камеры (координату Y) в зависимости от того, в каком месте ландшафта мы находимся.
258 Для этого мы сначала должны определить по координатам X и Z камеры квадрат ландшафта в котором мы находимся.
259 Все это делает функция Terrain::getHeight; в своих параметрах она получает координаты X и Z камеры и возвращает высоту,
260 на которой должна быть расположена камера, чтобы она оказалась над ландшафтом.*/
261 {
262 int result; // eax@5
263
264 if ( sX < 0 || sX > 127 || sZ < 0 || sZ > 127 )
265 result = 0;
266 else
267 result = DoGetHeightOnTerrain(sX, sZ);
268 return result;
269 }
270
271 //----- (00488F5C) --------------------------------------------------------
272 bool OutdoorLocation::Initialize(const char *pFilename, int File, size_t uRespawnInterval, int *thisa)
273 {
274 OutdoorLocation *v5; // esi@1
275 bool result; // eax@2
276
277 v5 = this;
278 if ( pFilename )
279 {
280 Release();
281 pBitmaps_LOD->ReleaseAll2();
282 pSprites_LOD->DeleteSomeOtherSprites();
283 pSpriteFrameTable->ResetSomeSpriteFlags();
284 pIcons_LOD->ReleaseAll2();
285
286 if ( !Load(pFilename, (ODMFace *)File, uRespawnInterval, thisa) )
287 {
288 MessageBoxA(0, "Error!", "Couldn't Load Map!", 0);
289 CreateDebugLocation();
290 }
291 ::day_attrib = v5->loc_time.day_attrib;
292 ::day_fogrange_1 = v5->loc_time.day_fogrange_1;
293 ::day_fogrange_2 = v5->loc_time.day_fogrange_2;
294 if ( Is_out15odm_underwater() )
295 SetUnderwaterFog();
296 _6BE134_odm_main_tile_group = v5->pTileTypes[0].tileset;
297 result = 1;
298 }
299 else
300 {
301 result = 0;
302 }
303 return result;
304 }
305
306
307
308 char foot_travel_destinations[15][4] =
309 {
310 // north south east west from
311 {MAP_INVALID, MAP_INVALID, MAP_INVALID, MAP_INVALID}, // MAP_EMERALD_ISLE
312 {MAP_PIERPONT, MAP_BARROW_DOWNS, MAP_PIERPONT, MAP_STEADWICK}, // MAP_HARMONDALE
313 {MAP_DEYJA, MAP_BRAKADA_DESERT, MAP_HARMONDALE, MAP_TATALIA}, // MAP_STEADWICK
314 {MAP_AVLEE, MAP_HARMONDALE, MAP_INVALID, MAP_DEYJA}, // MAP_PIERPONT
315 {MAP_PIERPONT, MAP_STEADWICK, MAP_PIERPONT, MAP_STEADWICK}, // MAP_DEYJA
316 {MAP_STEADWICK, MAP_INVALID, MAP_BARROW_DOWNS, MAP_INVALID}, // MAP_BRAKADA_DESERT
317 {MAP_INVALID, MAP_INVALID, MAP_INVALID, MAP_INVALID}, // MAP_CELESTIA
318 {MAP_INVALID, MAP_INVALID, MAP_INVALID, MAP_INVALID}, // MAP_THE_PIT
319 {MAP_INVALID, MAP_INVALID, MAP_INVALID, MAP_INVALID}, // MAP_EVENMORN_ISLE
320 {MAP_INVALID, MAP_INVALID, MAP_INVALID, MAP_INVALID}, // MAP_MOUNT_NIGHON
321 {MAP_HARMONDALE, MAP_BRAKADA_DESERT, MAP_HARMONDALE, MAP_BRAKADA_DESERT}, // MAP_BARROW_DOWNS
322 {MAP_INVALID, MAP_INVALID, MAP_INVALID, MAP_INVALID}, // MAP_LAND_OF_GIANTS
323 {MAP_INVALID, MAP_INVALID, MAP_STEADWICK, MAP_INVALID}, // MAP_TATALIA
324 {MAP_INVALID, MAP_PIERPONT, MAP_PIERPONT, MAP_INVALID}, // MAP_AVLEE
325 {MAP_INVALID, MAP_INVALID, MAP_INVALID, MAP_INVALID} // MAP_SHOALS
326 };
327 unsigned char foot_travel_times[15][4] =
328 {
329 // north south east west from
330 {0, 0, 0, 0}, // MAP_EMERALD_ISLE
331 {5, 5, 7, 5}, // MAP_HARMONDALE
332 {5, 5, 5, 5}, // MAP_STEADWICK
333 {5, 5, 0, 5}, // MAP_PIERPONT
334 {7, 5, 5, 4}, // MAP_DEYJA
335 {5, 0, 5, 0}, // MAP_BRAKADA_DESERT
336 {0, 0, 0, 0}, // MAP_CELESTIA
337 {0, 0, 0, 0}, // MAP_THE_PIT
338 {0, 0, 0, 0}, // MAP_EVENMORN_ISLE
339 {0, 0, 0, 0}, // MAP_MOUNT_NIGHON
340 {5, 7, 7, 5}, // MAP_BARROW_DOWNS
341 {0, 0, 0, 0}, // MAP_LAND_OF_GIANTS
342 {0, 0, 5, 0}, // MAP_TATALIA
343 {0, 7, 5, 0}, // MAP_AVLEE
344 {0, 0, 0, 0}, // MAP_SHOALS
345 };
346
347
348 MapStartPoint foot_travel_arrival_points[15][4] =
349 {
350 // north south east west from
351 {MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party}, // MAP_EMERALD_ISLE
352 {MapStartPoint_South, MapStartPoint_North, MapStartPoint_South, MapStartPoint_East}, // MAP_HARMONDALE
353 {MapStartPoint_South, MapStartPoint_North, MapStartPoint_West, MapStartPoint_East}, // MAP_STEADWICK
354 {MapStartPoint_East, MapStartPoint_North, MapStartPoint_Party, MapStartPoint_East}, // MAP_PIERPONT
355 {MapStartPoint_West, MapStartPoint_North, MapStartPoint_West, MapStartPoint_North}, // MAP_DEYJA
356 {MapStartPoint_South, MapStartPoint_Party, MapStartPoint_West, MapStartPoint_Party}, // MAP_BRAKADA_DESERT
357 {MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party}, // MAP_CELESTIA
358 {MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party}, // MAP_THE_PIT
359 {MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party}, // MAP_EVENMORN_ISLE
360 {MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party}, // MAP_MOUNT_NIGHON
361 {MapStartPoint_South, MapStartPoint_East, MapStartPoint_South, MapStartPoint_East}, // MAP_BARROW_DOWNS
362 {MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party}, // MAP_LAND_OF_GIANTS
363 {MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_West, MapStartPoint_Party}, // MAP_TATALIA
364 {MapStartPoint_Party, MapStartPoint_North, MapStartPoint_North, MapStartPoint_Party}, // MAP_AVLEE
365 {MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party, MapStartPoint_Party}, // MAP_SHOALS
366 };
367
368
369 //----- (0048902E) --------------------------------------------------------
370 bool OutdoorLocation::GetTravelDestination(signed int sPartyX, signed int sPartyZ, char *pOut, signed int a5)
371 {
372 char *mapNumberAsStr; // eax@3
373 int mapNumberAsInt; // eax@3
374 signed int direction; // esi@7
375 signed int destinationMap; // eax@23
376 char Str[140]; // [sp+8h] [bp-78h]@3
377
378 strcpy(Str, this->pLevelFilename);//настоящая локация
379 _strlwr(Str);
380 mapNumberAsStr = strtok(Str, "out");
381 mapNumberAsStr[2] = 0;
382 mapNumberAsInt = atoi(mapNumberAsStr);
383 if ( a5 < 10 || strlen(this->pLevelFilename) != 9 || mapNumberAsInt < 1 || mapNumberAsInt > 15 ) //длина .odm и количество локаций
384 return 0;
385 if ( sPartyX < -22528 )//граница карты
386 direction = 4;
387 else if ( sPartyX > 22528 )
388 direction = 3;
389 else if ( sPartyZ < -22528 )
390 direction = 2;
391 else if ( sPartyZ > 22528 )
392 direction = 1;
393 else
394 return false;
395
396 if ( mapNumberAsInt == MAP_AVLEE && direction == 4) // to Shoals
397 {
398 if ( pPlayers[1]->HasUnderwaterSuitEquipped() &&
399 pPlayers[2]->HasUnderwaterSuitEquipped() &&
400 pPlayers[3]->HasUnderwaterSuitEquipped() &&
401 pPlayers[4]->HasUnderwaterSuitEquipped())
402 {
403 uDefaultTravelTime_ByFoot = 1;
404 strcpy(pOut, "out15.odm");
405 uLevel_StartingPointType = MapStartPoint_East;
406 LOWORD(pParty->uFlags) &= 0xFD7Bu;
407 return true;
408 }
409 }
410 else if ( mapNumberAsInt == MAP_SHOALS && direction == 3 ) //from Shoals
411 {
412 uDefaultTravelTime_ByFoot = 1;
413 strcpy(pOut, "out14.odm");//Авли
414 uLevel_StartingPointType = MapStartPoint_West;
415 LOWORD(pParty->uFlags) &= 0xFD7Bu;
416 return true;
417 }
418 destinationMap = foot_travel_destinations[mapNumberAsInt - 1][direction - 1];
419 if (destinationMap == MAP_INVALID)
420 return false;
421
422 assert(destinationMap <= MAP_SHOALS);
423
424 uDefaultTravelTime_ByFoot = foot_travel_times[mapNumberAsInt - 1][direction - 1];
425 uLevel_StartingPointType = foot_travel_arrival_points[mapNumberAsInt - 1][direction - 1];
426 sprintf(pOut, "out%02d.odm", destinationMap); //локация направления
427 return true;
428 }
429 // 6BD07C: using guessed type int uDefaultTravelTime_ByFoot;
430 // 6BE35C: using guessed type int uLevel_StartingPointType;
431
432 //----- (0048917E) --------------------------------------------------------
433 void OutdoorLocation::MessWithLUN()
434 {
435 this->pSpriteIDs_LUN[0] = -1;
436 this->pSpriteIDs_LUN[1] = 0;
437 this->pSpriteIDs_LUN[2] = pSpriteFrameTable->FastFindSprite("LUN1-4");
438 this->pSpriteIDs_LUN[3] = 0;
439 this->pSpriteIDs_LUN[4] = pSpriteFrameTable->FastFindSprite("LUN1-2");
440 this->pSpriteIDs_LUN[5] = 0;
441 this->pSpriteIDs_LUN[6] = pSpriteFrameTable->FastFindSprite("LUN3-4");
442 this->pSpriteIDs_LUN[7] = 0;
443 this->uSpriteID_LUNFULL = pSpriteFrameTable->FastFindSprite("LUNFULL");
444 this->uSpriteID_LUN1_2_cp = pSpriteFrameTable->FastFindSprite("LUN1-2");
445 this->uSpriteID_LUN1_4_cp = pSpriteFrameTable->FastFindSprite("LUN1-4");
446 this->uSpriteID_LUN3_4_cp = pSpriteFrameTable->FastFindSprite("LUN3-4");
447 this->field_D60 = -1;
448 this->field_CF0 = 4;
449 this->field_CF8 = 4;
450 this->field_D00 = 4;
451 this->field_CE8 = 0;
452 this->field_D3C = (int)this->pSpriteIDs_LUN;
453 this->field_D40 = 0;
454 this->field_D44 = 0;
455 this->field_D48 = 0;
456 this->field_D4C = 131072;
457 this->field_D5C = 0;
458 this->field_D64 = 0;
459 this->field_D28 = -1;
460 this->field_D08 = 0;
461 this->field_D0C = 0;
462 this->field_D10 = 0;
463 this->field_D24 = 0;
464 this->field_D2C = 0;
465 this->uSpriteID_LUN_SUN = pSpriteFrameTable->FastFindSprite("LUN-SUN");
466 this->field_D14 = -131072;
467 for ( uint i = 0; i < 8; i++ )
468 pSpriteFrameTable->InitializeSprite(this->pSpriteIDs_LUN[i]);//v2 += 2;
469 pSpriteFrameTable->InitializeSprite(this->uSpriteID_LUN_SUN);
470 }
471
472 //----- (004892E6) --------------------------------------------------------
473 void OutdoorLocation::UpdateSunlightVectors()
474 {
475 unsigned int v3; // edi@3
476 double v8; // st7@4
477
478 if ( pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 21 )
479 {
480 v3 = pParty->uCurrentMinute + 60 * (pParty->uCurrentHour - 5);
481 this->inv_sunlight_y = 0;
482 this->inv_sunlight_x = stru_5C6E00->Cos((v3 * stru_5C6E00->uIntegerPi) / 960);
483 this->inv_sunlight_z = stru_5C6E00->Sin((v3 * stru_5C6E00->uIntegerPi) / 960);
484 this->vSunlight.x = -this->inv_sunlight_x;
485 this->vSunlight.y = -this->inv_sunlight_y;
486 this->vSunlight.z = -this->inv_sunlight_z;
487 if ( v3 >= 480 )
488 v8 = 960 - v3;
489 else
490 v8 = v3;
491 this->max_terrain_dimming_level = (int)(20.0 - v8 / 480.0 * 20.0);
492 this->uLastSunlightUpdateMinute = pParty->uCurrentMinute;
493 }
494 }
495
496 //----- (004893C1) --------------------------------------------------------
497 void OutdoorLocation::UpdateFog()
498 {
499 fFogDensity = GetFogDensityByTime();
500 }
501
502 //----- (004893CF) --------------------------------------------------------
503 int OutdoorLocation::GetNumFoodRequiredToRestInCurrentPos(int x, signed int y, int z)
504 {
505 int v7; // eax@4
506 int is_on_water; // [sp+8h] [bp-8h]@2
507 int bmodel_standing_on_pid; // [sp+Ch] [bp-4h]@2
508
509 is_on_water = 0;
510 bmodel_standing_on_pid = 0;
511 ODM_GetFloorLevel(x, y, z, pParty->uDefaultPartyHeight, &is_on_water, &bmodel_standing_on_pid, 0);
512 if ( pParty->uFlags & 8 || bmodel_standing_on_pid || is_on_water )//на bmodel,и или на воде
513 return 2;
514 v7 = _47ED83(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y) - 1);
515 switch ( pTileTable->pTiles[GetTileIdByTileMapId(v7)].tileset )
516 {
517 case Tileset_Grass://на траве
518 return 1;
519 case Tileset_Snow://на снегу
520 return 3;
521 case Tilset_Desert://на песке
522 return 5;
523 case Tileset_3:
524 case Tileset_Dirt:// на грязи
525 return 4;
526 case Tileset_Water:// on water(на воде)
527 return 3;//еденицы еды
528 default:
529 return 2;
530 }
531 }
532
533 //----- (00489487) --------------------------------------------------------
534 void OutdoorLocation::SetFog()
535 {
536 strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
537
538 MAP_TYPE map_id = pMapStats->GetMapInfo(pCurrentMapName);
539 if (map_id == MAP_INVALID || map_id == MAP_CELESTIA || map_id == MAP_THE_PIT || map_id > MAP_SHOALS)
540 return;
541
542 uint chance = rand() % 100;
543
544 if (chance < fog_probability_table[map_id - 1].small_fog_chance)
545 {
546 ::day_fogrange_1 = 4096;
547 ::day_fogrange_2 = 8192;
548 ::day_attrib |= DAY_ATTRIB_FOG;
549 }
550 else if (chance < fog_probability_table[map_id - 1].small_fog_chance +
551 fog_probability_table[map_id - 1].average_fog_chance)
552 {
553 ::day_fogrange_2 = 4096;
554 ::day_fogrange_1 = 0;
555 ::day_attrib |= DAY_ATTRIB_FOG;
556 }
557 else if (fog_probability_table[map_id - 1].dense_fog_chance &&
558 chance < fog_probability_table[map_id - 1].small_fog_chance +
559 fog_probability_table[map_id - 1].average_fog_chance +
560 fog_probability_table[map_id - 1].dense_fog_chance)
561 {
562 ::day_fogrange_2 = 2048;
563 ::day_fogrange_1 = 0;
564 ::day_attrib |= DAY_ATTRIB_FOG;
565 }
566 else
567 ::day_attrib &= ~DAY_ATTRIB_FOG;
568
569 if ( Is_out15odm_underwater() )
570 SetUnderwaterFog();
571 pOutdoor->loc_time.day_fogrange_1 = ::day_fogrange_1;
572 pOutdoor->loc_time.day_fogrange_2 = ::day_fogrange_2;
573 pOutdoor->loc_time.day_attrib = ::day_attrib;
574 }
575
576 //----- (00482170) --------------------------------------------------------
577 bool ODMFace::IsBackfaceNotCulled(RenderVertexSoft *a2, struct Polygon *polygon)
578 {
579 unsigned int numOfVertices; // edx@1
580 RenderVertexSoft *currVertex; // ecx@2
581 double v7; // st7@5
582 double v8; // st6@5
583 double v9; // st5@5
584 float v18; // [sp+8h] [bp-38h]@5
585 float v19; // [sp+10h] [bp-30h]@5
586 float v20; // [sp+14h] [bp-2Ch]@5
587 float v21; // [sp+18h] [bp-28h]@5
588 float v22; // [sp+1Ch] [bp-24h]@5
589 float v23; // [sp+24h] [bp-1Ch]@5
590 float v24; // [sp+28h] [bp-18h]@5
591 float v25; // [sp+30h] [bp-10h]@5
592 float v26; // [sp+34h] [bp-Ch]@5
593 float v27; // [sp+38h] [bp-8h]@5
594 float v28; // [sp+3Ch] [bp-4h]@5
595 float a3a; // [sp+48h] [bp+8h]@5
596 float a3b; // [sp+48h] [bp+8h]@17
597 float a3c; // [sp+48h] [bp+8h]@17
598 float a3d; // [sp+48h] [bp+8h]@17
599 float a3e; // [sp+48h] [bp+8h]@17
600
601 numOfVertices = polygon->uNumVertices;
602 if ( numOfVertices < 3 )
603 return false;
604 currVertex = &a2[numOfVertices - 1];
605 if ( a2->vWorldPosition.z == a2[1].vWorldPosition.z && a2[1].vWorldPosition.z == currVertex->vWorldPosition.z )
606 polygon->flags |= 0x10u;
607
608 v28 = a2[1].vWorldPosition.x - a2->vWorldPosition.x;
609 v27 = a2[1].vWorldPosition.y - a2->vWorldPosition.y;
610 a3a = a2[1].vWorldPosition.z - a2->vWorldPosition.z;
611
612
613 for (int i = 0; i < numOfVertices; i++)
614 {
615 v7 = currVertex->vWorldPosition.x - a2->vWorldPosition.x;
616 v8 = currVertex->vWorldPosition.y - a2->vWorldPosition.y;
617 v9 = currVertex->vWorldPosition.z - a2->vWorldPosition.z;
618 v26 = v27 * v9 - v8 * a3a;
619 v24 = v7 * a3a - v9 * v28;
620 v25 = v8 * v28 - v7 * v27;
621 if ( v24 != 0.0 || v25 != 0.0 || v26 != 0.0 )
622 break;
623 currVertex--;
624 }
625
626 if ( ((double)pGame->pIndoorCameraD3D->vPartyPos.x - a2->vWorldPosition.x) * v26
627 + ((double)pGame->pIndoorCameraD3D->vPartyPos.z - a2->vWorldPosition.z) * v25
628 + ((double)pGame->pIndoorCameraD3D->vPartyPos.y - a2->vWorldPosition.y) * v24 > 0.0 )
629 {
630
631 v19 = a2[1].vWorldViewPosition.x - a2->vWorldViewPosition.x;
632 v18 = a2[1].vWorldViewPosition.y - a2->vWorldViewPosition.y;
633 v20 = a2[1].vWorldViewPosition.z - a2->vWorldViewPosition.z;
634 v21 = currVertex->vWorldViewPosition.x - a2->vWorldViewPosition.x;
635 v22 = currVertex->vWorldViewPosition.y - a2->vWorldViewPosition.y;
636 v23 = currVertex->vWorldViewPosition.z - a2->vWorldViewPosition.z;
637
638 a3b = v23 * v18 - v22 * v20;
639 polygon->v_18.x = bankersRounding(a3b);
640 a3c = v21 * v20 - v23 * v19;
641 polygon->v_18.y = bankersRounding(a3c);
642 a3d = v22 * v19 - v21 * v18;
643 polygon->v_18.z = bankersRounding(a3d);
644 polygon->_normalize_v_18();
645 a3e = -((double)polygon->v_18.x * a2->vWorldViewPosition.x)
646 - (double)polygon->v_18.y * a2->vWorldViewPosition.y
647 - (double)polygon->v_18.z * a2->vWorldViewPosition.z;
648 polygon->field_24 = bankersRounding(a3e);
649 return true;
650 }
651 else
652 return false;
653 }
654
655 //----- (0047C7A9) --------------------------------------------------------
656 void OutdoorLocationTerrain::_47C7A9()
657 {
658 this->field_10 = 0;
659 this->field_12 = 0;
660 this->field_16 = 0;
661 this->field_14 = 0;
662 this->field_1C = 0;
663 this->field_18 = 0;
664 }
665
666 //----- (0047C7C2) --------------------------------------------------------
667 void OutdoorLocationTerrain::Release()//очистить локацию
668 {
669 free(this->pHeightmap);
670 pHeightmap = nullptr;
671 free(pTilemap);
672 pTilemap = nullptr;
673 free(pAttributemap);
674 pAttributemap = nullptr;
675 free(pDmap);
676 pDmap = nullptr;
677
678 _47C7A9();
679 }
680
681 //----- (0047C80A) --------------------------------------------------------
682 void OutdoorLocationTerrain::FillDMap( int X, int Y, int W, int Z )
683 {
684 double v6; // st7@1
685 double v7; // st7@2
686 double v8; // st7@2
687 int result; // eax@3
688 int v10; // eax@4
689 int v11; // ecx@5
690 int v12; // ecx@6
691 int v13; // edi@7
692 int v14; // edx@9
693 // int v15; // eax@15
694 unsigned __int8 *pMapHeight; // ebx@15
695 int v17; // eax@15
696 int v18; // ecx@15
697 int v19; // esi@15
698 int v20; // edi@15
699 int v21; // edx@15
700 int v22; // ecx@15
701 int v23; // ebx@15
702 int v24; // ecx@15
703 int v25; // ST28_4@15
704 double v26; // st7@15
705 double v27; // st6@15
706 double v28; // st5@15
707 double v29; // st7@15
708 double v30; // st7@16
709 double v31; // st7@17
710 int v32; // eax@21
711 double v33; // st7@21
712 double v34; // st6@21
713 double v35; // st5@21
714 double v36; // st7@21
715 double v37; // st7@22
716 double v38; // st7@23
717 int v39; // [sp+14h] [bp-34h]@8
718 int v40; // [sp+18h] [bp-30h]@15
719 int v41; // [sp+1Ch] [bp-2Ch]@15
720 int v42; // [sp+20h] [bp-28h]@15
721 int v44; // [sp+28h] [bp-20h]@21
722 float v45; // [sp+2Ch] [bp-1Ch]@1
723 float v46; // [sp+30h] [bp-18h]@1
724 float v47; // [sp+34h] [bp-14h]@1
725 //int v48; // [sp+38h] [bp-10h]@7
726 int v49; // [sp+3Ch] [bp-Ch]@10
727 int v50; // [sp+40h] [bp-8h]@9
728 float v51; // [sp+44h] [bp-4h]@15
729 float v52; // [sp+44h] [bp-4h]@21
730 float v53; // [sp+50h] [bp+8h]@15
731 float v54; // [sp+50h] [bp+8h]@21
732 // int v55; // [sp+54h] [bp+Ch]@15
733 float v56; // [sp+54h] [bp+Ch]@15
734 float v57; // [sp+54h] [bp+Ch]@21
735
736 v46 = -64.0;
737 v47 = -64.0;
738 v45 = 64.0;
739 v6 = sqrt(12288.0);
740 if ( v6 != 0.0 )
741 {
742 v7 = 1.0 / v6;
743 v45 = 64.0 * v7;
744 v8 = v7 * -64.0;
745 v46 = v8;
746 v47 = v8;
747 }
748 result = Y;
749 if ( Y > Z )
750 {
751 v10 = Z ^ Y;
752 Z ^= Y ^ Z;
753 result = Z ^ v10;
754 }
755 v11 = X;
756 if ( X > W )
757 {
758 v12 = W ^ X;
759 W ^= X ^ W;
760 v11 = W ^ v12;
761 }
762 //v48 = result - 1;
763 if ( result - 1 <= Z )
764 {
765 v39 = v11 - 1;
766 for ( v13 = result - 1; v13 <= Z; v13++ )
767 {
768 v50 = v39;
769 if ( v39 <= W )
770 {
771 result = (v39 - 63) << 9;
772 v49 = (v39 - 63) << 9;
773 for ( v14 = v39; v14 <= W; v14++ )
774 {
775 if ( v13 >= 0 && result >= -32256 && v13 <= 127 && result <= 32768 )
776 {
777 //v15 = pOutLocTerrain->field_10;
778 //v55 = pOutLocTerrain->field_10;
779 pMapHeight = this->pHeightmap;
780 v17 = (int)(&pMapHeight[v13 * this->field_10] + v14);
781 v18 = -v13;
782 v19 = (64 - v13) << 9;
783 v20 = 32 * *(char *)v17;
784 v21 = 32 * *(char *)(v17 + 1);
785
786 v22 = (v18 + 63) << 9;
787 v41 = v22;
788 v23 = (int)(&pMapHeight[this->field_10 * (v13 + 1)] + v14);
789 v24 = v22 - v19;
790 v40 = 32 * *(char *)v23;
791 v42 = 32 * *(char *)(v23 + 1);
792
793 v25 = v49 - 512 - v49;
794 v26 = (double)-((v20 - v21) * v24);
795 v51 = v26;
796 v27 = (double)-(v25 * (v42 - v21));
797 v53 = v27;
798 v28 = (double)(v25 * v24);
799 v56 = v28;
800 v29 = sqrt(v28 * v28 + v27 * v27 + v26 * v26);
801 if ( v29 != 0.0 )
802 {
803 v30 = 1.0 / v29;
804 v51 = v51 * v30;
805 v53 = v53 * v30;
806 v56 = v30 * v56;
807 }
808 v31 = (v56 * v47 + v53 * v46 + v51 * v45) * 31.0;
809 if ( v31 < 0.0 )
810 v31 = 0.0;
811 if ( v31 > 31.0 )
812 v31 = 31.0;
813 v44 = 2 * (v14 + v13 * this->field_10);
814 //pOutLocTerrain = pOutLocTerrain2;
815 *((char *)this->pDmap + v44 + 1) = (signed __int64)v31;
816
817 v32 = v49 - (v49 - 512);
818 v33 = (double)-((v42 - v40) * (v19 - v41));
819 v52 = v33;
820 v34 = (double)-(v32 * (v20 - v40));
821 v54 = v34;
822 v35 = (double)(v32 * (v19 - v41));
823 v57 = v35;
824 v36 = sqrt(v35 * v35 + v34 * v34 + v33 * v33);
825 if ( v36 != 0.0 )
826 {
827 v37 = 1.0 / v36;
828 v52 = v52 * v37;
829 v54 = v54 * v37;
830 v57 = v37 * v57;
831 }
832 v38 = (v57 * v47 + v54 * v46 + v52 * v45) * 31.0;
833 if ( v38 < 0.0 )
834 v38 = 0.0;
835 if ( v38 > 31.0 )
836 v38 = 31.0;
837 //v13 = v48;
838 *((char *)this->pDmap + v44) = (signed __int64)v38;
839 //v14 = v50;
840 result = v49;
841 }
842 //++v14;
843 result += 512;
844 //v50 = v14;
845 v49 = result;
846 }
847 }
848 //++v13;
849 //v48 = v13;
850 }
851 //while ( v13 <= Z );
852 }
853 }
854
855 //----- (0047CB57) --------------------------------------------------------
856 int OutdoorLocationTerrain::_47CB57(int a1, int a2, int a3)
857 {
858 signed int result; // eax@2
859 // unsigned __int16 *v5; // edx@3
860 // double v6; // st7@3
861 // int v8; // eax@3
862 // int v9; // eax@4
863 // int v10; // eax@5
864 // double v11; // st6@7
865 // signed int v12; // edi@7
866 // int v13; // esi@9
867 // char *v14; // esi@10
868 // signed int v15; // ecx@10
869 // char v16[256]; // [sp+4h] [bp-124h]@9
870 // unsigned __int16 *v17; // [sp+104h] [bp-24h]@3
871 // float v22; // [sp+118h] [bp-10h]@3
872 // float v23; // [sp+11Ch] [bp-Ch]@3
873 // int i; // [sp+120h] [bp-8h]@3
874 // unsigned int v25; // [sp+124h] [bp-4h]@5
875 // signed int a2a; // [sp+134h] [bp+Ch]@3
876 // unsigned int a2b; // [sp+134h] [bp+Ch]@7
877 // float a3a; // [sp+138h] [bp+10h]@7
878 // int a3b; // [sp+138h] [bp+10h]@9
879
880 int num_r_bits = 5;
881 int num_g_bits = 6;
882 int num_b_bits = 5;
883
884 int r_mask = 0xF800;
885 int g_mask = 0x7E0;
886 int b_mask = 0x1F;
887
888 //if ( pRenderer->pRenderD3D )
889 result = 0;
890 /*else
891 {
892 __debugbreak();
893 v5 = PaletteManager::Get_Dark_or_Red_LUT(a2, 0, 1);
894 v6 = 0.0;
895 v22 = 0.0;
896 v8 = 0;
897 v17 = v5;
898 v23 = 0.0;
899 a2a = 0;
900 for ( i = 0; i < a3; ++i )
901 {
902 v9 = *(char *)(v8 + a1);
903 if ( v9 )
904 {
905 v10 = v5[v9];
906 v6 = v6 + (double)((signed int)(r_mask & v10) >> (num_b_bits + num_g_bits));
907 ++a2a;
908 v25 = b_mask & v10;
909 v22 = (double)((signed int)(g_mask & v10) >> num_b_bits) + v22;
910 v23 = (double)(signed int)(b_mask & v10) + v23;
911 }
912 v8 = i + 1;
913 }
914 v11 = 1.0 / (double)a2a;
915 a3a = v11;
916 v25 = (signed __int64)(a3a * v22);
917 i = (signed __int64)(a3a * v23);
918 v12 = 0;
919 a2b = num_b_bits + num_g_bits;
920 while ( 1 )
921 {
922 v13 = v17[v12];
923 a3b = abs((__int64)(signed __int64)(v11 * v6) - ((signed int)(r_mask & v17[v12]) >> a2b));
924 BYTE3(a3b) = abs((signed)v25 - ((signed int)(g_mask & v13) >> num_b_bits)) + a3b;
925 v16[v12++] = abs((signed)i - (signed)(b_mask & v13)) + BYTE3(a3b);
926 if ( v12 >= 256 )
927 break;
928 }
929 result = 0;
930 v14 = (char *)&pPaletteManager->field_D1600[42][23][116];
931 v15 = 0;
932 do
933 {
934 if ( (unsigned __int8)v16[v15] < (signed int)v14 )
935 {
936 v14 = (char *)(unsigned __int8)v16[v15];
937 result = v15;
938 }
939 ++v15;
940 }
941 while ( v15 < 256 );
942 }*/
943 return result;
944 }
945
946 //----- (0047CCE2) --------------------------------------------------------
947 bool OutdoorLocationTerrain::ZeroLandscape()
948 {
949 memset(this->pHeightmap, 0, 0x4000u);
950 memset(this->pTilemap, 90, 0x4000u);
951 memset(this->pAttributemap, 0, 0x4000u);
952 memset(this->pDmap, 0, 0x8000u);
953 this->field_12 = 128;
954 this->field_10 = 128;
955 this->field_16 = 7;
956 this->field_14 = 7;
957 this->field_1C = 127;
958 this->field_18 = 127;
959 return true;
960 }
961
962 //----- (0047CD44) --------------------------------------------------------
963 bool OutdoorLocationTerrain::Initialize()
964 {
965 pHeightmap = (unsigned __int8 *)malloc(0x4000u);//height map
966 pTilemap = (unsigned __int8 *)malloc(0x4000u);//tile map
967 pAttributemap = (unsigned __int8 *)malloc(0x4000u);//карта атрибутов
968 pDmap = (struct DMap *)malloc(0x8000u);
969 if (pHeightmap && pTilemap && pAttributemap && pDmap )
970 return true;
971 else
972 return false;
973 }
974
975 //----- (0047CDE2) --------------------------------------------------------
976 void OutdoorLocation::CreateDebugLocation()
977 {
978 //OutdoorLocation *v1; // esi@1
979 void *v2; // eax@1
980 void *v3; // ST14_4@1
981 void *v4; // eax@1
982 void *v5; // ST14_4@1
983 void *v6; // eax@1
984 //unsigned int v7; // eax@1
985 //char v8; // zf@1
986
987 //v1 = this;
988 strcpy(this->pLevelFilename, "blank");
989 strcpy(this->pLocationFileName, "i6.odm");
990 strcpy(this->pLocationFileDescription, "MM6 Outdoor v1.00");
991 this->uNumBModels = 0;
992 this->pTileTypes[0].tileset = Tileset_Grass;
993 this->pTileTypes[1].tileset = Tileset_Water;
994 this->pTileTypes[2].tileset = Tileset_6;
995 this->pTileTypes[3].tileset = Tileset_RoadGrassCobble;
996 this->LoadTileGroupIds();
997 this->LoadRoadTileset();
998 free(this->pBModels);
999 free(this->pSpawnPoints);
1000 this->pBModels = 0;
1001 this->pSpawnPoints = 0;
1002 this->pTerrain.Initialize();
1003 this->pTerrain.ZeroLandscape();
1004 this->pTerrain.FillDMap(0, 0, 128, 128);
1005 free(this->pCmap);
1006 this->pCmap = 0;
1007 v2 = malloc(0x8000u);
1008 v3 = this->pOMAP;
1009 this->pCmap = v2;
1010 free(v3);
1011 this->pOMAP = 0;
1012 v4 = malloc(0x10000u);
1013 this->pOMAP = (unsigned int *)v4;
1014 memset(v4, 0, 0x10000u);
1015 v5 = this->pFaceIDLIST;
1016 this->numFaceIDListElems = 0;
1017 free(v5);
1018 this->pFaceIDLIST = 0;
1019 v6 = malloc(2);
1020 this->pFaceIDLIST = (unsigned __int16 *)v6;
1021 *(short *)v6 = 0;
1022 strcpy(this->pSkyTextureName, pDefaultSkyTexture.data());
1023 this->sSky_TextureID = pBitmaps_LOD->LoadTexture(this->pSkyTextureName);
1024 strcpy(this->pGroundTileset, byte_6BE124_cfg_textures_DefaultGroundTexture.data());
1025 //v7 = pBitmaps_LOD->LoadTexture(this->pGroundTileset);
1026 this->sMainTile_BitmapID = pBitmaps_LOD->LoadTexture(this->pGroundTileset);
1027
1028 if ( this->sSky_TextureID == -1 )
1029 Error("Invalid Sky Tex Handle");
1030
1031 if ( this->sMainTile_BitmapID == -1 )
1032 Error("Invalid Ground Tex Handle");
1033 }
1034
1035 //----- (0047CF9C) --------------------------------------------------------
1036 void OutdoorLocation::Release()
1037 {
1038 strcpy(pLevelFilename, "blank");
1039 strcpy(pLocationFileName, "default.odm");
1040 strcpy(pLocationFileDescription, "MM6 Outdoor v1.00");
1041 strcpy(pSkyTextureName, "sky043");
1042 strcpy(pGroundTileset, "hm005");
1043
1044 if (pBModels)
1045 {
1046 for (uint i = 0; i < uNumBModels; ++i)
1047 pBModels[i].Release();
1048
1049 free(pBModels);
1050 pBModels = nullptr;
1051 uNumBModels = 0;
1052 }
1053
1054 free(pSpawnPoints);
1055 pSpawnPoints = nullptr;
1056 uNumSpawnPoints = 0;
1057
1058 pTerrain.Release();
1059
1060 free(pCmap);
1061 pCmap = nullptr;
1062 free(pOMAP);
1063 pOMAP = nullptr;
1064 free(pFaceIDLIST);
1065 pFaceIDLIST = nullptr;
1066 free(pTerrainNormals);
1067 pTerrainNormals = nullptr;
1068 }
1069
1070 //----- (0047D0A6) --------------------------------------------------------
1071 bool OutdoorLocation::Load(const char *pFilename, ODMFace *File, size_t pNumItems, int *thisa)//загрузка локации
1072 {
1073 //OutdoorLocation *pOutdoorLocation; // esi@1
1074 /*bool result; // eax@9
1075 bool v7; // ebx@9
1076 size_t v8; // eax@10
1077 void *v9; // eax@10
1078 void *v10; // eax@10
1079 void *v11; // eax@10
1080 int v12; // ebx@11
1081 BSPModel *v13; // eax@12
1082 void *v14; // eax@12
1083 BSPModel *v15; // ecx@12
1084 void *v16; // eax@12
1085 BSPModel *v17; // ecx@12
1086 BSPModel *v18; // eax@12
1087 __int16 v19; // ax@15
1088 __int16 v20; // ax@16
1089 int v21; // ecx@16
1090 ODMFace *v22; // ebx@26
1091 SpriteObject *pItems; // ecx@27
1092 unsigned int v24; // eax@28
1093 //unsigned __int8 v25; // zf@28
1094 //unsigned __int8 v26; // sf@28
1095 ODMFace *v27; // eax@28
1096 const char *i; // edx@29
1097 unsigned __int16 v29; // ax@33
1098 unsigned __int16 v30; // ax@37
1099 int v31; // ecx@37
1100 int v32; // eax@38
1101 void *v33; // eax@38
1102 TileDesc *v34; // eax@43
1103 unsigned int v35; // eax@43
1104 unsigned int v36; // edi@43
1105 unsigned int v37; // edi@45*/
1106 //size_t v38; // eax@50
1107 FILE *v39; // eax@50
1108 //unsigned int v40; // edi@56
1109 //void *v41; // eax@56
1110 //void *v42; // ebx@56
1111 //const void *v43; // ebx@59
1112 //const void *v44; // ebx@59
1113 //unsigned int v45; // eax@59
1114 //BSPModel *v46; // eax@59
1115 //unsigned int v47; // ecx@59
1116 //int v48; // ebx@60
1117 //BSPModel *v49; // eax@61
1118 //BSPModel *v50; // eax@61
1119 //BSPModel *v51; // eax@61
1120 //BSPModel *v52; // eax@61
1121 //BSPModel *v53; // eax@61
1122 //BSPModel *v54; // ecx@61
1123 //BSPModel *v55; // ecx@61
1124 //BSPModel *v56; // ecx@61
1125 //void *v57; // ST24_4@61
1126 //BSPModel *v58; // ecx@61
1127 //void *v59; // ST18_4@61
1128 //BSPModel *v60; // eax@61
1129 //__int16 v61; // ax@64
1130 unsigned __int16 v62; // ax@65
1131 //ODMFace *v63; // ecx@65
1132 //unsigned __int16 v64; // ax@80
1133 //const char *v65; // ecx@80
1134 //int v66; // eax@81
1135 //void *v67; // eax@81
1136 //int v68; // ecx@81
1137 //void *v69; // eax@81
1138 //unsigned int v70; // eax@81
1139 //SpawnPointMM7 *v71; // eax@81
1140 //unsigned int v72; // ecx@81
1141 //size_t v73; // eax@81
1142 //int v74; // edi@87
1143 //void *v75; // edi@88
1144 //unsigned int v76; // edx@94
1145 //int v77; // ecx@94
1146 //char *v78; // eax@95
1147 //unsigned int v79; // edx@97
1148 //unsigned int v80; // eax@99
1149 //int v81; // eax@107
1150 //void *v82; // edi@114
1151 //size_t v83; // eax@120
1152 //const void *v84; // edi@120
1153 //const void *v85; // edi@120
1154 //BSPModel *v86; // eax@124
1155 //unsigned int v87; // eax@124
1156 //BSPModel *v88; // eax@126
1157 //BSPModel *v89; // eax@127
1158 //ODMFace *v90; // eax@129
1159 //const void *v91; // edi@138
1160 //const void *v92; // edi@141
1161 //const void *v93; // edi@141
1162 //const void *v94; // edi@144
1163 //const void *v95; // edi@144
1164 //const char *v96; // edi@147
1165 //unsigned int v97; // eax@147
1166 //TileDesc *v98; // eax@147
1167 //unsigned int v99; // eax@147
1168 //int v100; // ecx@150
1169 //unsigned int v101; // eax@157
1170 // int v102; // edi@159
1171 //void *v103; // [sp-14h] [bp-B94h]@55
1172 //void *v104; // [sp-10h] [bp-B90h]@59
1173 //size_t v105; // [sp-Ch] [bp-B8Ch]@59
1174 //char *v106; // [sp-8h] [bp-B88h]@59
1175 // int v107; // [sp-4h] [bp-B84h]@12
1176 int v108; // [sp+0h] [bp-B80h]@10
1177 char Src[968]; // [sp+10h] [bp-B70h]@110
1178 char Dst[968]; // [sp+3D8h] [bp-7A8h]@50
1179 char Str[256]; // [sp+7A0h] [bp-3E0h]@50
1180 /*char DstBuf; // [sp+8A0h] [bp-2E0h]@10
1181 __int32 Offset; // [sp+8A4h] [bp-2DCh]@10
1182 __int32 v114; // [sp+8B0h] [bp-2D0h]@10
1183 __int32 v115; // [sp+8BCh] [bp-2C4h]@10
1184 __int32 v116; // [sp+8C8h] [bp-2B8h]@10
1185 __int32 v117; // [sp+8D4h] [bp-2ACh]@10
1186 __int32 v118; // [sp+8E0h] [bp-2A0h]@10
1187 __int32 v119; // [sp+8ECh] [bp-294h]@10
1188 __int32 v120; // [sp+8F8h] [bp-288h]@10
1189 __int32 v121; // [sp+904h] [bp-27Ch]@10
1190 __int32 v122; // [sp+910h] [bp-270h]@10
1191 __int32 v123; // [sp+91Ch] [bp-264h]@10
1192 __int32 v124; // [sp+928h] [bp-258h]@26
1193 __int32 v125; // [sp+934h] [bp-24Ch]@35
1194 __int32 v126; // [sp+940h] [bp-240h]@38
1195 __int32 v127; // [sp+94Ch] [bp-234h]@38
1196 __int32 v128; // [sp+958h] [bp-228h]@38
1197 __int32 v129; // [sp+964h] [bp-21Ch]@38
1198 __int32 v130; // [sp+970h] [bp-210h]@38
1199 __int32 v131; // [sp+97Ch] [bp-204h]@38
1200 __int32 v132; // [sp+988h] [bp-1F8h]@38
1201 __int32 v133; // [sp+994h] [bp-1ECh]@38
1202 __int32 v134; // [sp+9A0h] [bp-1E0h]@38
1203 __int32 v135; // [sp+9ACh] [bp-1D4h]@38
1204 __int32 v136; // [sp+9D0h] [bp-1B0h]@10*/
1205 //char FileName[8]; // [sp+A20h] [bp-160h]@8
1206 //char v138; // [sp+A28h] [bp-158h]@12
1207 //int v139; // [sp+B1Ch] [bp-64h]@10
1208 //char pContainer[32]; // [sp+B20h] [bp-60h]@1
1209 //int *v141; // [sp+B40h] [bp-40h]@50
1210 //__int64 v142; // [sp+B44h] [bp-3Ch]@55
1211 //size_t pSource; // [sp+B4Ch] [bp-34h]@56
1212 //int v144; // [sp+B50h] [bp-30h]@61
1213 //int v145; // [sp+B54h] [bp-2Ch]@68
1214 ODMHeader header; // [sp+B58h] [bp-28h]@50
1215 //unsigned int pDestLen; // [sp+B68h] [bp-18h]@13
1216 //FILE *ptr; // [sp+B6Ch] [bp-14h]@12
1217 //void *v149; // [sp+B70h] [bp-10h]@19
1218 char *Str2; // [sp+B74h] [bp-Ch]@12
1219 //int v151; // [sp+B78h] [bp-8h]@59
1220 //void *uSourceLen; // [sp+B7Ch] [bp-4h]@59
1221
1222 //pOutdoorLocation = this;
1223 //strcpy(pContainer, pFilename);
1224
1225 if (bUnderwater)
1226 {
1227 pPaletteManager->pPalette_tintColor[0] = 0x10;
1228 pPaletteManager->pPalette_tintColor[1] = 0xC2;
1229 pPaletteManager->pPalette_tintColor[2] = 0x99;
1230 pPaletteManager->SetMistColor(37, 143, 92);
1231 }
1232 else
1233 {
1234 pPaletteManager->pPalette_tintColor[0] = 0;
1235 pPaletteManager->pPalette_tintColor[1] = 0;
1236 pPaletteManager->pPalette_tintColor[2] = 0;
1237 if (pPaletteManager->pPalette_mistColor[0] != 0x80 ||
1238 pPaletteManager->pPalette_mistColor[1] != 0x80 ||
1239 pPaletteManager->pPalette_mistColor[2] != 0x80)
1240 {
1241 pPaletteManager->SetMistColor(128, 128, 128);
1242 pPaletteManager->RecalculateAll();
1243 }
1244 }
1245
1246 _6807E0_num_decorations_with_sounds_6807B8 = 0;
1247 /*sprintf(FileName, "levels\\%s", pContainer);
1248 if ( GetFileAttributesA(FileName) != -1 )
1249 {
1250 result = (bool)fopen(FileName, "rb");
1251 v7 = result;
1252 File = (ODMFace *)result;
1253 if ( !result )
1254 return result;
1255 *(int *)thisa = 1;
1256 v8 = strlen(pContainer);
1257 v108 = 2;
1258 *((char *)&v139 + v8) = 0;
1259 viewparams->uTextureID_LocationMap = pIcons_LOD->LoadTexture(pContainer, (enum TEXTURE_TYPE)v108);
1260 fread(&DstBuf, 0x180u, 1u, (FILE *)v7);
1261 fseek((FILE *)v7, Offset, 0);
1262 fread(this, 0xB0u, 1u, (FILE *)v7);
1263 LoadTileGroupIds();
1264 LoadRoadTileset();
1265 strcpy(pGroundTileset, "grastyl");
1266 fseek((FILE *)v7, v114, 0);
1267 fread(&uNumBModels, 4u, 1u, (FILE *)v7);
1268 fseek((FILE *)v7, v115, 0);
1269 fread(&uNumSpriteObjects, 4u, 1u, (FILE *)v7);
1270 fseek((FILE *)v7, v116, 0);
1271 fread(&uNumLevelDecorations, 4u, 1u, (FILE *)v7);
1272 fseek((FILE *)v7, v117, 0);
1273 fread(&uNumActors, 4u, 1u, (FILE *)v7);
1274 fseek((FILE *)v7, v118, 0);
1275 fread(&uNumChests, 4u, 1u, (FILE *)v7);
1276 pTerrain.Initialize();
1277 fseek((FILE *)v7, v119, 0);
1278 fread(pTerrain.pHeightmap, 1u, 0x4000u, (FILE *)v7);
1279 fseek((FILE *)v7, v120, 0);
1280 fread(pTerrain.pTilemap, 1u, 0x4000u, (FILE *)v7);
1281 fseek((FILE *)v7, v121, 0);
1282 fread(pTerrain.pAttributemap, 1u, 0x4000u, (FILE *)v7);
1283 pTerrain._47C80A(0, 0, 128, 128);
1284 free(ptr_D4);
1285 ptr_D4 = 0;
1286 v9 = malloc(0, 0x8000u, "CMAP");
1287 v108 = (int)pOMAP;
1288 ptr_D4 = v9;
1289 free((void *)v108);
1290 pOMAP = 0;
1291 v10 = malloc(0, 0x10000u, "OMAP");
1292 v108 = 0;
1293 pOMAP = (unsigned int *)v10;
1294 fseek((FILE *)v7, v136, v108);
1295 fread(&uNumTerrainNormals, 4u, 1u, (FILE *)v7);
1296 fread(pTerrainSomeOtherData, 1u, 0x20000u, (FILE *)v7);
1297 fread(pTerrainNormalIndices, 1u, 0x10000u, (FILE *)v7);
1298 pTerrainNormals = (Vec3_float_ *)malloc(pTerrainNormals, 12 * uNumTerrainNormals, "TerNorm");
1299 fread(pTerrainNormals, 1u, 12 * uNumTerrainNormals, (FILE *)v7);
1300 v11 = malloc(pBModels, 188 * uNumBModels, "BDdata");
1301 v108 = 0;
1302 pBModels = (BSPModel *)v11;
1303 fseek((FILE *)v7, v122, v108);
1304 fread(pBModels, 0xBCu, uNumBModels, (FILE *)v7);
1305 fseek((FILE *)v7, v123, 0);
1306 pNumItems = 0;
1307 if ( (signed int)uNumBModels > 0 )
1308 {
1309 v12 = 0;
1310 while ( 1 )
1311 {
1312 pBModels[v12].pVertices.pVertices = 0;
1313 pBModels[v12].pFaces = 0;
1314 pBModels[v12].pFacesOrdering = 0;
1315 pBModels[v12].pNodes = 0;
1316 FileName[0] = 0;
1317 v108 = (int)&pBModels[v12];
1318 sprintfex(FileName, "%s", v108);
1319 v13 = pBModels;
1320 v138 = 0;
1321 pBModels[v12].pVertices.pVertices = (Vec3_int_ *)malloc(v13[v12].pVertices.pVertices, 12 * v13[v12].pVertices.uNumVertices,
1322 FileName);
1323 pBModels[v12].pFaces = (ODMFace *)malloc(pBModels[v12].pFaces, 308 * pBModels[v12].uNumFaces,
1324 FileName);
1325 pBModels[v12].pFacesOrdering = (unsigned __int16 *)malloc(pBModels[v12].pFacesOrdering,
1326 2 * pBModels[v12].uNumFaces, FileName);
1327 v14 = malloc(pBModels[v12].pNodes, 8 * pBModels[v12].uNumNodes, FileName);
1328 v15 = pBModels;
1329 v108 = (int)File;
1330 v15[v12].pNodes = (BSPNode *)v14;
1331 fread(pBModels[v12].pVertices.pVertices, 0xCu, pBModels[v12].pVertices.uNumVertices, (FILE *)v108);
1332 fread(pBModels[v12].pFaces, 0x134u, pBModels[v12].uNumFaces, (FILE *)File);
1333 fread(pBModels[v12].pFacesOrdering, 2u, pBModels[v12].uNumFaces, (FILE *)File);
1334 fread(pBModels[v12].pNodes, 8u, pBModels[v12].uNumNodes, (FILE *)File);
1335 v16 = malloc(10 * pBModels[v12].uNumFaces);
1336 v107 = (int)File;
1337 v17 = pBModels;
1338 ptr = (FILE *)v16;
1339 fread(v16, 0xAu, v17[v12].uNumFaces, (FILE *)File);
1340 v18 = pBModels;
1341 Str2 = 0;
1342 if ( (signed int)v18[v12].uNumFaces > 0 )
1343 break;
1344 LABEL_25:
1345 free(ptr);
1346 ++pNumItems;
1347 ++v12;
1348 if ( (signed int)pNumItems >= (signed int)uNumBModels )
1349 goto LABEL_26;
1350 }
1351 pDestLen = 0;
1352 pFilename = (char *)ptr;
1353 while ( 1 )
1354 {
1355 thisa = (int)((char *)v18[v12].pFaces + pDestLen);
1356 if ( !(*(char *)(thisa + 29) & 0x40) )
1357 break;
1358 v19 = pTextureFrameTable->FindTextureByName(pFilename);
1359 *(short *)(thisa + 272) = v19;
1360 if ( !v19 )
1361 {
1362 v20 = pBitmaps_LOD->LoadTexture(pFilename);
1363 v21 = thisa;
1364 *(char *)(v21 + 29) &= 0xBFu;
1365 LABEL_19:
1366 *(short *)(v21 + 272) = v20;
1367 v149 = (void *)(v20 != -1 ? &pBitmaps_LOD->pTextures[v20] : 0);
1368 auto pTex = (Texture *)v149;
1369 if (pTex)
1370 pTex->palette_id2 = pPaletteManager->LoadPalette(pTex->palette_id1);
1371 goto LABEL_20;
1372 }
1373 pTextureFrameTable->LoadAnimationSequenceAndPalettes(*(unsigned __int16 *)((char *)&pBModels[v12].pFaces->uTextureID + pDestLen));
1374 LABEL_20:
1375 if ( *(short *)(thisa + 292) )
1376 {
1377 if ( ((ODMFace *)thisa)->HasEventHint() )
1378 *(char *)(thisa + 30) |= 0x10u;
1379 else
1380 *(char *)(thisa + 30) &= 0xEFu;
1381 }
1382 ++Str2;
1383 v18 = pBModels;
1384 pDestLen += 308;
1385 pFilename += 10;
1386 if ( (signed int)Str2 >= (signed int)v18[v12].uNumFaces )
1387 goto LABEL_25;
1388 }
1389 v20 = pBitmaps_LOD->LoadTexture(pFilename);
1390 v21 = thisa;
1391 goto LABEL_19;
1392 }
1393 LABEL_26:
1394 v22 = File;
1395 fseek((FILE *)File, v124, 0);
1396 fread(pSpriteObjects, 0x70u, uNumSpriteObjects, (FILE *)v22);
1397 if ( (signed int)uNumSpriteObjects > 0 )
1398 {
1399 pItems = pSpriteObjects;
1400 pNumItems = uNumSpriteObjects;
1401 do
1402 {
1403 v24 = pItems->stru_24.uItemID;
1404 thisa = 0;
1405 v27 = (ODMFace *)(48 * v24);
1406 v25 = pObjectList->uNumObjects == 0;
1407 v26 = (pObjectList->uNumObjects & 0x80000000u) != 0;
1408 LOWORD(v27) = *(short *)((char *)&v27->pFacePlane.vNormal.x + (int)((char *)&pItemsTable + 24));
1409 File = v27;
1410 pItems->uItemType = (unsigned __int16)v27;
1411 if ( v26 | v25 )
1412 {
1413 LABEL_33:
1414 v29 = 0;
1415 }
1416 else
1417 {
1418 for ( i = (const char *)&pObjectList->pObjects->uObjectID; (short)v27 != *(short *)i; i = pFilename )
1419 {
1420 ++thisa;
1421 pFilename = (char *)i + 56;
1422 if ( thisa >= (signed int)pObjectList->uNumObjects )
1423 goto LABEL_33;
1424 LOWORD(v27) = (short)File;
1425 }
1426 v29 = thisa;
1427 }
1428 pItems->uObjectDescID = v29;
1429 ++pItems;
1430 --pNumItems;
1431 }
1432 while ( pNumItems );
1433 }
1434 fseek((FILE *)v22, v125, 0);
1435 fread(pLevelDecorations, 0x20u, uNumLevelDecorations, (FILE *)v22);
1436 pNumItems = 0;
1437 if ( (signed int)uNumLevelDecorations > 0 )
1438 {
1439 thisa = (int)pLevelDecorations;
1440 do
1441 {
1442 fread(FileName, 1u, 0x20u, (FILE *)v22);
1443 v30 = pDecorationList->GetDecorIdByName(FileName);
1444 v31 = thisa;
1445 ++pNumItems;
1446 thisa += 32;
1447 *(short *)v31 = v30;
1448 }
1449 while ( (signed int)pNumItems < (signed int)uNumLevelDecorations );
1450 }
1451 fseek((FILE *)v22, v126, 0);
1452 fread(pActors, 0x344u, uNumActors, (FILE *)v22);
1453 fseek((FILE *)v22, v127, 0);
1454 fread(pChests, 0x14CCu, uNumChests, (FILE *)v22);
1455 fseek((FILE *)v22, v128, 0);
1456 fread(&field_DC, 4u, 1u, (FILE *)v22);
1457 free(pFaceIDLIST);
1458 v32 = field_DC;
1459 pFaceIDLIST = 0;
1460 v33 = malloc(0, 2 * v32, "IDLIST");
1461 v108 = (int)v22;
1462 pFaceIDLIST = (unsigned __int16 *)v33;
1463 fread(v33, 2u, field_DC, (FILE *)v108);
1464 fseek((FILE *)v22, v129, 0);
1465 fread(pOMAP, 4u, 0x4000u, (FILE *)v22);
1466 fseek((FILE *)v22, v130, 0);
1467 fread(&uNumSpawnPoints, 4u, 1u, (FILE *)v22);
1468 pSpawnPoints = (SpawnPointMM7 *)malloc(pSpawnPoints, 24 * uNumSpawnPoints, "Spawn");
1469 fseek((FILE *)v22, v131, 0);
1470 fread(pSpawnPoints, 0x18u, uNumSpawnPoints, (FILE *)v22);
1471 fseek((FILE *)v22, v132, 0);
1472 fread(&ddm, 0x28u, 1u, (FILE *)v22);
1473 fseek((FILE *)v22, v133, 0);
1474 fread(&stru_5E4C90, 1u, 0xC8u, (FILE *)v22);
1475 fseek((FILE *)v22, v134, 0);
1476 fread(&uLastVisitDay, 1u, 0x38u, (FILE *)v22);
1477 fseek((FILE *)v22, v135, 0);
1478 fread(&uLastVisitDay, 1u, 4u, (FILE *)v22);
1479 thisa = (int)pTileTypes;
1480 pTileTable->InitializeTileset(4);
1481 pTileTable->InitializeTileset(pTileTypes[0].uTileGroup);
1482 pTileTable->InitializeTileset(pTileTypes[1].uTileGroup);
1483 pTileTable->InitializeTileset(pTileTypes[2].uTileGroup);
1484 pTileTable->InitializeTileset(pTileTypes[3].uTileGroup);
1485 if ( this != (OutdoorLocation *)-96 && pSkyTextureName[0] )
1486 {
1487 v108 = 0;
1488 v107 = (int)pSkyTextureName;
1489 }
1490 else
1491 {
1492 v108 = 0;
1493 v107 = (int)pDefaultSkyTexture;
1494 }
1495 sSky_TextureID = pBitmaps_LOD->LoadTexture((const char *)v107, (enum TEXTURE_TYPE)v108);
1496 strcpy(pGroundTileset, byte_6BE124_cfg_textures_DefaultGroundTexture);
1497 v34 = pTileTable->GetTileById(pTileTypes[0].uTileID);
1498 v35 = pBitmaps_LOD->LoadTexture(v34->pTileName);
1499 v36 = sSky_TextureID;
1500 sMainTile_BitmapID = v35;
1501 if ( v36 != -1 )
1502 pBitmaps_LOD->pTextures[v36].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v36].palette_id1);
1503
1504 v37 = sMainTile_BitmapID;
1505 if ( v37 != -1 )
1506 pBitmaps_LOD->pTextures[v37].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v37].palette_id1);
1507
1508 _47F0E2();
1509 pGameLoadingUI_ProgressBar->Progress();
1510 fclose((FILE *)v22);
1511 goto LABEL_150;
1512 }*/
1513
1514 assert(sizeof(BSPModel) == 188);
1515
1516 if (!pGames_LOD->DoesContainerExist(pFilename))
1517 Error("Unable to find %s in Games.LOD", pFilename);
1518
1519
1520 char pMinimapTextureFilename[1024];
1521 strcpy(pMinimapTextureFilename, pFilename);
1522 pMinimapTextureFilename[strlen(pMinimapTextureFilename) - 4] = 0;
1523 viewparams->uTextureID_LocationMap = pIcons_LOD->LoadTexture(pMinimapTextureFilename, TEXTURE_16BIT_PALETTE);
1524
1525 //strcpy(FileName, pContainer);
1526 strcpy(Str, pFilename);
1527 strcpy(Str + strlen(Str) - 4, ".odm");
1528 //v141 = &v139;
1529 //v38 = strlen(pFilename);
1530 //strcpy((char *)&v139 + v38, ".odm");
1531 v39 = pGames_LOD->FindContainer(Str, 1);
1532 //Str[strlen(Str) - 4] = 0;
1533
1534 header.uCompressedSize = 0;
1535 header.uDecompressedSize = 0;
1536 //ptr = v39;
1537 header.uVersion = 91969;
1538 header.pMagic[0] = 'm';
1539 header.pMagic[1] = 'v';
1540 header.pMagic[2] = 'i';
1541 header.pMagic[3] = 'i';
1542 fread(&header, 0x10u, 1u, v39);
1543 if (header.uVersion != 91969 ||
1544 header.pMagic[0] != 'm' ||
1545 header.pMagic[1] != 'v' ||
1546 header.pMagic[2] != 'i' ||
1547 header.pMagic[3] != 'i')
1548 {
1549 MessageBoxW(nullptr, L"Can't load file!",
1550 L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:507", 0);
1551 }
1552 //v40 = header.uCompressedSize;
1553 //pSource = header.uDecompressedSize;
1554 //v41 = malloc(header.uDecompressedSize);
1555 uchar* pSrcMem = (unsigned char *)malloc(header.uDecompressedSize);
1556 uchar* pSrc = pSrcMem;
1557 //v42 = v41;
1558 //HIDWORD(v142) = (uint32)pSrc;
1559 if (header.uCompressedSize < header.uDecompressedSize)
1560 {
1561 char* pComressedSrc = (char *)malloc(header.uCompressedSize);
1562 fread(pComressedSrc, header.uCompressedSize, 1, v39);
1563
1564 uint actualDecompressedSize = header.uDecompressedSize;
1565 zlib::MemUnzip(pSrc, &actualDecompressedSize, pComressedSrc, header.uCompressedSize);
1566 free(pComressedSrc);
1567 }
1568 else
1569 {
1570 fread(pSrc, header.uDecompressedSize, 1, v39);
1571 }
1572
1573 memcpy(pLevelFilename, pSrc, 0x20);
1574 memcpy(pLocationFileName, pSrc + 0x20, 0x20);
1575 memcpy(pLocationFileDescription, pSrc + 0x40, 0x20);
1576 memcpy(pSkyTextureName, pSrc + 3 * 32, 32);
1577 memcpy(pGroundTileset, pSrc + 0x80, 0x20);
1578 memcpy(pTileTypes, pSrc + 0xA0, 0x10);
1579 pSrc += 0xB0;
1580
1581 //v43 = (char *)pSrc + 176;
1582 LoadTileGroupIds();
1583 LoadRoadTileset();
1584 strcpy(pGroundTileset, "grastyl");
1585 pGameLoadingUI_ProgressBar->Progress();
1586 pTerrain.Initialize();
1587 //v108 = 16384;
1588 //v107 = (int)v43;
1589 //v106 = (char *)pTerrain.pHeightmap;
1590 memcpy(pTerrain.pHeightmap, pSrc, 0x4000);
1591 pSrc += 0x4000;
1592
1593 //v43 = (char *)v43 + 16384;
1594 //v105 = 16384;
1595 //v104 = (void *)v43;
1596 //v103 = pTerrain.pTilemap;
1597 memcpy(pTerrain.pTilemap, pSrc, 0x4000);
1598 pSrc += 0x4000;
1599
1600 //v43 = (char *)v43 + 16384;
1601 memcpy(pTerrain.pAttributemap, pSrc, 0x4000);
1602 pSrc += 0x4000;
1603
1604 //v43 = (char *)v43 + 16384;
1605 //v108 = (int)ptr_D4;
1606 free(pCmap);
1607 pCmap = malloc(0x8000);
1608 pTerrain.FillDMap(0, 0, 128, 128);
1609
1610 pGameLoadingUI_ProgressBar->Progress();
1611 memcpy(&uNumTerrainNormals, pSrc, 4);
1612 //v43 = (char *)v43 + 4;
1613 memcpy(pTerrainSomeOtherData.data(), pSrc + 4, 0x20000);
1614 pSrc += 4 + 0x20000;
1615 //v43 = (char *)v43 + 131072;
1616 memcpy(pTerrainNormalIndices.data(), pSrc, 0x10000);
1617 pSrc += 0x10000;
1618 //v43 = (char *)v43 + 65536;
1619
1620 //pFilename = (char *)(12 * uNumTerrainNormals);
1621 pTerrainNormals = (Vec3_float_ *)malloc(sizeof(Vec3_float_) * uNumTerrainNormals);
1622 memcpy(pTerrainNormals, pSrc, 12 * uNumTerrainNormals);
1623 pSrc += 12 * uNumTerrainNormals;
1624 //v44 = (char *)v43 + (int)pFilename;
1625 //v44 = (char *)v44 + 4;
1626 //v45 = uNumBModels;
1627 //v108 = (int)"BDdata";
1628
1629 pGameLoadingUI_ProgressBar->Progress();
1630
1631 //v107 = 188 * v45;
1632 //v106 = (char *)pBModels;
1633 //v46 = (BSPModel *)malloc(v106, 188 * v45, "BDdata");
1634 //v47 = uNumBModels;
1635 memcpy(&uNumBModels, pSrc, 4);
1636 pBModels = (BSPModel *)malloc(188 * uNumBModels);
1637 //pFilename = (char *)(188 * v47);
1638 memcpy(pBModels, pSrc + 4, 188 * uNumBModels);
1639 pSrc += 4 + 188 * uNumBModels;
1640
1641 pGameLoadingUI_ProgressBar->Progress();
1642
1643 //uSourceLen = (char *)v44 + (int)pFilename;
1644 //v151 = 0;
1645 for (uint i = 0; i < uNumBModels; ++i)
1646 {
1647 //v48 = 0;
1648 //BSPModel* model = &pBModels[i];
1649
1650 pBModels[i].pVertices.pVertices = nullptr;
1651 pBModels[i].pFaces = nullptr;
1652 pBModels[i].pFacesOrdering = nullptr;
1653 pBModels[i].pNodes = nullptr;
1654 //FileName[0] = 0;
1655 //v108 = (int)&pBModels[i];
1656 //sprintf(FileName, "%s", v108);
1657 //v49 = pBModels;
1658 //v138 = 0;
1659 //v50 = &pBModels[v48];
1660 //v108 = (int)FileName;
1661 //v107 = 12 * v50->pVertices.uNumVertices;
1662 //v106 = (char *)v50->pVertices.pVertices;
1663 assert(sizeof(Vec3_int_) == 12);
1664 uint verticesSize = pBModels[i].pVertices.uNumVertices * sizeof(Vec3_int_);
1665 pBModels[i].pVertices.pVertices = (Vec3_int_ *)malloc(verticesSize);
1666 memcpy(pBModels[i].pVertices.pVertices, pSrc, verticesSize);
1667 pSrc += verticesSize;
1668 //v51 = &pBModels[v48];
1669 //v108 = (int)FileName;
1670 //v107 = 308 * v51->uNumFaces;
1671 //v106 = (char *)v51->pFaces;
1672 assert(sizeof(ODMFace) == 308);
1673 uint facesSize = pBModels[i].uNumFaces * sizeof(ODMFace);
1674 pBModels[i].pFaces = (ODMFace *)malloc(facesSize);
1675 memcpy(pBModels[i].pFaces, pSrc, facesSize);
1676 pSrc += facesSize;
1677 //v52 = &pBModels[v48];
1678 //v108 = (int)FileName;
1679 //v107 = 2 * v52->uNumFaces;
1680 //v106 = (char *)v52->pFacesOrdering;
1681 uint facesOrderingSize = pBModels[i].uNumFaces * sizeof(short);
1682 pBModels[i].pFacesOrdering = (unsigned __int16 *)malloc(facesOrderingSize);
1683 memcpy(pBModels[i].pFacesOrdering, pSrc, facesOrderingSize);
1684 pSrc += facesOrderingSize;
1685 //v53 = &pBModels[v48];
1686 //v108 = (int)FileName;
1687 //v107 = 8 * v53->uNumNodes;
1688 //v106 = (char *)v53->pNodes;
1689 assert(sizeof(BSPNode) == 8);
1690 uint nodesSize = pBModels[i].uNumNodes * sizeof(BSPNode);
1691 pBModels[i].pNodes = (BSPNode *)malloc(nodesSize);
1692 memcpy(pBModels[i].pNodes, pSrc, nodesSize);
1693 pSrc += nodesSize;
1694 //v54 = &pBModels[v48];
1695 //v108 = 12 * v54->pVertices.uNumVertices;
1696 //pFilename = (char *)v108;
1697 //v107 = (int)uSourceLen;
1698 //v106 = (char *)v54->pVertices.pVertices;
1699 //memcpy(v106, uSourceLen, v108);
1700 //uSourceLen = (char *)uSourceLen + (int)pFilename;
1701 //v55 = &pBModels[v48];
1702 //v105 = 308 * v55->uNumFaces;
1703 //v104 = uSourceLen;
1704 //v103 = v55->pFaces;
1705 //pFilename = (char *)v105;
1706 //memcpy(v103, uSourceLen, v105);
1707 //v56 = &pBModels[v48];
1708 //uSourceLen = (char *)uSourceLen + (int)pFilename;
1709 //v57 = v56->pFacesOrdering;
1710 //pFilename = (char *)(2 * v56->uNumFaces);
1711 //memcpy(v57, uSourceLen, (size_t)pFilename);
1712 //v58 = &pBModels[v48];
1713 //uSourceLen = (char *)uSourceLen + (int)pFilename;
1714 //v59 = v58->pNodes;
1715 //pFilename = (char *)(8 * v58->uNumNodes);
1716 //memcpy(v59, uSourceLen, (size_t)pFilename);
1717 //uSourceLen = (char *)uSourceLen + (int)pFilename;
1718 //ptr = (FILE *)malloc(10 * model->uNumFaces);
1719 const char* textureFilenames = (const char *)malloc(10 * pBModels[i].uNumFaces);
1720 //pFilename = (char *)(10 * pBModels[v48].uNumFaces);
1721 memcpy((char *)textureFilenames, pSrc, 10 * pBModels[i].uNumFaces);
1722 pSrc += 10 * pBModels[i].uNumFaces;
1723 //v144 = 0;
1724 //uSourceLen = (char *)uSourceLen + (int)pFilename;
1725 //v60 = pBModels;
1726 for (uint j = 0; j < pBModels[i].uNumFaces; ++j)
1727 {
1728 const char* texFilename = &textureFilenames[j * 10];
1729 //v149 = 0;
1730 //Str2 = (char *)ptr;
1731
1732 //ODMFace* face = &pBModels[i].pFaces[j];
1733 //pFilename = (char *)v149 + (unsigned int)v60[v48].pFaces;
1734 if ( !(pBModels[i].pFaces[j].uAttributes & FACE_DONT_CACHE_TEXTURE))
1735 {
1736 v62 = pBitmaps_LOD->LoadTexture(texFilename);
1737 // v63 = (ODMFace *)pFilename;
1738 pBModels[i].pFaces[j].uTextureID = v62;
1739 //v145 = (signed __int16)v62 != -1 ? &pBitmaps_LOD->pTextures[(signed __int16)v62] : 0;
1740 //v108 = ((signed __int16)v62 != -1 ? pBitmaps_LOD->pTextures[(signed __int16)v62].palette_id1 : 36);
1741 if ((signed __int16)v62 != -1)
1742 pBitmaps_LOD->pTextures[v62].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v62].palette_id1);
1743 //goto LABEL_69;
1744 //goto LABEL_68;
1745 }
1746 else
1747 {
1748 //v61 = pTextureFrameTable->FindTextureByName(texFilename);
1749 pBModels[i].pFaces[j].uTextureID = pTextureFrameTable->FindTextureByName(texFilename);
1750 if (!pBModels[i].pFaces[j].uTextureID)
1751 {
1752 v62 = pBitmaps_LOD->LoadTexture(texFilename);
1753 //v63 = (ODMFace *)pFilename;
1754 pBModels[i].pFaces[j].uAttributes &= ~FACE_DONT_CACHE_TEXTURE;
1755 //LABEL_68:
1756 pBModels[i].pFaces[j].uTextureID = v62;
1757 //v145 = (signed __int16)v62 != -1 ? &pBitmaps_LOD->pTextures[(signed __int16)v62] : 0;
1758 //v108 = ((signed __int16)v62 != -1 ? pBitmaps_LOD->pTextures[(signed __int16)v62].palette_id1 : 36);
1759 if ((signed __int16)v62 != -1)
1760 pBitmaps_LOD->pTextures[v62].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v62].palette_id1);
1761 //goto LABEL_69;
1762 }
1763 else
1764 pTextureFrameTable->LoadAnimationSequenceAndPalettes(pBModels[i].pFaces[j].uTextureID);
1765 }
1766 //LABEL_69:
1767 if (pBModels[i].pFaces[j].sCogTriggeredID)
1768 {
1769 if (pBModels[i].pFaces[j].HasEventHint())
1770 pBModels[i].pFaces[j].uAttributes |= FACE_HAS_EVENT;
1771 else
1772 pBModels[i].pFaces[j].uAttributes &= ~FACE_HAS_EVENT;
1773 }
1774 //++v144;
1775 //v60 = pBModels;
1776 //v149 = (char *)v149 + 308;
1777 //Str2 += 10;
1778 //if ( v144 >= (signed int)v60[v48].uNumFaces )
1779 //goto LABEL_74;
1780 }
1781
1782 //LABEL_74:
1783 free((void *)textureFilenames);
1784 // ++v151;
1785 // ++v48;
1786 // if ( v151 >= (signed int)uNumBModels )
1787 // goto LABEL_75;
1788 }
1789 //LABEL_75:
1790 pGameLoadingUI_ProgressBar->Progress();
1791
1792 memcpy(&uNumLevelDecorations, pSrc, 4);
1793 //uSourceLen = (char *)uSourceLen + 4;
1794 if (uNumLevelDecorations > 3000)
1795 MessageBoxW(nullptr, L"Can't load file!",
1796 L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:678", 0);
1797
1798 assert(sizeof(LevelDecoration) == 32);
1799 //pFilename = (char *)(32 * uNumLevelDecorations);
1800 memcpy(pLevelDecorations.data(), pSrc + 4, uNumLevelDecorations * sizeof(LevelDecoration));
1801 pSrc += 4 + sizeof(LevelDecoration) * uNumLevelDecorations;
1802
1803 pGameLoadingUI_ProgressBar->Progress();
1804
1805 //v151 = 0;
1806 //uSourceLen = (char *)uSourceLen + (int)pFilename;
1807 for (uint i = 0; i < uNumLevelDecorations; ++i)
1808 {
1809 char name[256];
1810 memcpy(name, pSrc, sizeof(LevelDecoration));
1811 pSrc += sizeof(LevelDecoration);
1812
1813 pLevelDecorations[i].uDecorationDescID = pDecorationList->GetDecorIdByName(name);
1814 }
1815
1816 pGameLoadingUI_ProgressBar->Progress();
1817
1818 memcpy(&numFaceIDListElems, pSrc, 4);
1819
1820 //uSourceLen = (char *)uSourceLen + 4;
1821 //v108 = (int)pFaceIDLIST;
1822 free(pFaceIDLIST);
1823 pFaceIDLIST = nullptr;
1824 //v66 = field_DC;
1825 //pFaceIDLIST = 0;
1826 //v67 = malloc(0, 2 * v66, "IDLIST");
1827 uint faceIDListSize = 2 * numFaceIDListElems;
1828 pFaceIDLIST = (unsigned short *)malloc(faceIDListSize);
1829 //v68 = field_DC;
1830 //pFaceIDLIST = (unsigned __int16 *)v67;
1831 //pFilename = (char *)(2 * v68);
1832 memcpy(pFaceIDLIST, pSrc + 4, faceIDListSize);
1833 pSrc += 4 + faceIDListSize;
1834
1835 //uSourceLen = (char *)uSourceLen + (int)pFilename;
1836 pGameLoadingUI_ProgressBar->Progress();
1837
1838 //v108 = (int)pOMAP;
1839 //free((void *)v108);
1840 //pOMAP = 0;
1841 free(pOMAP);
1842 //v69 = malloc(0, 0x10000u, "OMAP");
1843 pOMAP = (unsigned int *)malloc(0x10000);
1844 //v108 = 65536;
1845 //pOMAP = (unsigned int *)v69;
1846 memcpy(pOMAP, pSrc, 65536);
1847 pSrc += 65536;
1848
1849 //uSourceLen = (char *)uSourceLen + 65536;
1850 pGameLoadingUI_ProgressBar->Progress();
1851
1852 memcpy(&uNumSpawnPoints, pSrc, 4);
1853 //uSourceLen = (char *)uSourceLen + 4;
1854 pGameLoadingUI_ProgressBar->Progress();
1855 //v70 = uNumSpawnPoints;
1856 //v108 = (int)"Spawn";
1857 //v107 = 24 * v70;
1858 //v106 = (char *)pSpawnPoints;
1859 assert(sizeof(SpawnPointMM7) == 24);
1860 uint spawnPointsSize = uNumSpawnPoints * sizeof(SpawnPointMM7);
1861 pSpawnPoints = (SpawnPointMM7 *)malloc(spawnPointsSize);
1862 //v72 = uNumSpawnPoints;
1863 //pSpawnPoints = v71;
1864 memcpy(pSpawnPoints, pSrc + 4, spawnPointsSize);
1865 pSrc += 4 + spawnPointsSize;
1866
1867 pGameLoadingUI_ProgressBar->Progress();
1868
1869 free(pSrcMem);
1870
1871 //v108 = (int)".ddm";
1872 //v73 = strlen(pContainer);
1873 strcpy(Str + strlen(Str) - 4, ".ddm");
1874 //strcpy((char *)v141 + v73, (const char *)v108);
1875 v39 = pNew_LOD->FindContainer(Str, 1);//error
1876 fread(&header, 0x10u, 1, v39);
1877 Str2 = 0;
1878 if (header.uVersion != 91969 ||
1879 header.pMagic[0] != 'm' ||
1880 header.pMagic[1] != 'v' ||
1881 header.pMagic[2] != 'i' ||
1882 header.pMagic[3] != 'i' )
1883 {
1884 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:746", 0);
1885 Str2 = (char *)1;
1886 }
1887 //v74 = 0;
1888 //pFilename = (char *)header.uCompressedSize;
1889 //v149 = 0;
1890 //pDestLen = header.uDecompressedSize;
1891 if ( !Str2 )
1892 {
1893 pSrcMem = (unsigned char *)malloc(header.uDecompressedSize);
1894 pSrc = pSrcMem;
1895 //v149 = v75;
1896 if (header.uCompressedSize == header.uDecompressedSize)
1897 fread(pSrc, header.uDecompressedSize, 1u, v39);
1898 else if (header.uCompressedSize < header.uDecompressedSize)
1899 {
1900 void* compressedMem = malloc(header.uCompressedSize);
1901 fread(compressedMem, header.uCompressedSize, 1, v39);
1902
1903 uint actualDecompressedSize = header.uDecompressedSize;
1904 zlib::MemUnzip(pSrc, &actualDecompressedSize, compressedMem, header.uCompressedSize);
1905 free(compressedMem);
1906 }
1907 else
1908 MessageBoxW(nullptr, L"Can't load file!",
1909 L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:765", 0);
1910
1911 assert(sizeof(DDM_DLV_Header) == 0x28);
1912 memcpy(&ddm, pSrc, sizeof(DDM_DLV_Header));
1913 pSrc += sizeof(DDM_DLV_Header);
1914 //v74 = (int)((char *)v75 + 40);
1915 }
1916 uint actualNumFacesInLevel = 0;
1917 for (uint i = 0; i < uNumBModels; ++i)
1918 actualNumFacesInLevel += pBModels[i].uNumFaces;
1919
1920 //v79 = ddm.uNumFacesInBModels;
1921 if (ddm.uNumFacesInBModels)
1922 {
1923 if ( ddm.uNumBModels )
1924 {
1925 //v80 = ddm.uNumDecorations;
1926 if (ddm.uNumDecorations)
1927 {
1928 if (ddm.uNumFacesInBModels != actualNumFacesInLevel ||
1929 ddm.uNumBModels != uNumBModels ||
1930 ddm.uNumDecorations != uNumLevelDecorations )
1931 Str2 = (char *)1;
1932 }
1933 }
1934 }
1935
1936 if (dword_6BE364_game_settings_1 & GAME_SETTINGS_2000)
1937 pNumItems = 0x1BAF800;
1938
1939 if (Str2 || ((unsigned int)((char *)File - ddm.uLastRepawnDay) >= pNumItems || !ddm.uLastRepawnDay))
1940 {
1941
1942 if (Str2)
1943 {
1944 memset(Dst, 0, 0x3C8u);
1945 memset(Src, 0, 0x3C8u);
1946 //goto LABEL_112;
1947 }
1948 //v81 = ddm.uLastRepawnDay;
1949 if ((unsigned int)((char *)File - ddm.uLastRepawnDay) >= pNumItems || !ddm.uLastRepawnDay)
1950 {
1951 memcpy(Dst, pSrc, 0x3C8u);
1952 memcpy(Src, pSrc + 968, 0x3C8u);
1953 }
1954 //LABEL_112:
1955 free(pSrcMem);
1956
1957 ddm.uLastRepawnDay = (int)File;
1958 if (Str2 == 0)
1959 ++ddm.uNumRespawns;
1960 v108 = 0;
1961 *thisa = 1;
1962 v39 = pGames_LOD->FindContainer(Str, 0);
1963 fread(&header, 0x10, 1u, v39);
1964 //pFilename = (char *)header.uCompressedSize;
1965 //pDestLen = header.uDecompressedSize;
1966 //v82 = malloc(header.uDecompressedSize);
1967 pSrcMem = (unsigned char *)malloc(header.uDecompressedSize);
1968 //v149 = v82;
1969 if (header.uCompressedSize == header.uDecompressedSize)
1970 fread(pSrcMem, header.uDecompressedSize, 1, v39);
1971 else if (header.uCompressedSize < header.uDecompressedSize)
1972 {
1973 void* compressedMem = malloc(header.uCompressedSize);
1974 fread(compressedMem, header.uCompressedSize, 1u, v39);
1975
1976 uint actualDecompressedSize = header.uDecompressedSize;
1977 zlib::MemUnzip(pSrcMem, &actualDecompressedSize, compressedMem, header.uCompressedSize);
1978 free(compressedMem);
1979 }
1980 else
1981 MessageBoxW(nullptr, L"Can't load file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:857", 0);
1982
1983 pSrc = pSrcMem + 40;
1984 //goto LABEL_120;
1985 }
1986 else
1987 *thisa = 0;
1988 //LABEL_120:
1989 //v108 = (int)".odm";
1990 //v83 = strlen(pContainer);
1991 //strcpy((char *)v141 + v83, (const char *)v108);
1992 memcpy(uFullyRevealedCellOnMap, pSrc, 0x3C8);
1993 //v84 = (const void *)(v74 + 968);
1994 memcpy(uPartiallyRevealedCellOnMap, pSrc + 0x3C8, 0x3C8);
1995 pSrc += 2 * 0x3C8;
1996 //v85 = (char *)v84 + 968;
1997
1998 pGameLoadingUI_ProgressBar->Progress();
1999
2000 if ( *thisa )
2001 {
2002 memcpy(uFullyRevealedCellOnMap, Dst, 0x3C8u);
2003 memcpy(uPartiallyRevealedCellOnMap, Src, 0x3C8u);
2004 }
2005
2006 for (uint i = 0; i < uNumBModels; ++i)
2007 {
2008 BSPModel model = pBModels[i];
2009 for (uint j = 0; j < model.uNumFaces; ++j)
2010 {
2011 ODMFace face = model.pFaces[j];
2012 memcpy(&face.uAttributes, pSrc, 4);
2013 pSrc += 4;
2014 }
2015
2016 for (uint j = 0; j < model.uNumFaces; ++j)
2017 {
2018 ODMFace face = model.pFaces[j];
2019 if (face.sCogTriggeredID)
2020 {
2021 if (face.HasEventHint())
2022 face.uAttributes |= FACE_HAS_EVENT_HINT;
2023 else
2024 face.uAttributes &= ~FACE_HAS_EVENT_HINT;//~0x00001000
2025 }
2026 }
2027 }
2028
2029 pGameLoadingUI_ProgressBar->Progress();
2030
2031 for (uint i = 0; i < uNumLevelDecorations; ++i)
2032 {
2033 memcpy(&pLevelDecorations[i].uFlags, pSrc, 2);
2034 pSrc += 2;
2035 }
2036
2037 pGameLoadingUI_ProgressBar->Progress();
2038
2039 memcpy(&uNumActors, pSrc, 4);
2040 if (uNumActors > 500)
2041 MessageBoxW(nullptr, L"Can't load file!",
2042 L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:939", 0);
2043
2044 pGameLoadingUI_ProgressBar->Progress();
2045
2046 assert(sizeof(Actor) == 836);
2047 //pFilename = (char *)(836 * uNumActors);
2048 memcpy(pActors.data(), pSrc + 4, uNumActors * sizeof(Actor));
2049 pSrc += 4 + uNumActors * sizeof(Actor);
2050 //v92 = (char *)v91 + (int)pFilename;
2051 pGameLoadingUI_ProgressBar->Progress();
2052
2053 memcpy(&uNumSpriteObjects, pSrc, 4);
2054 assert(uNumSpriteObjects <= 1000 && "Too many objects");
2055 assert(sizeof(SpriteObject) == 112);
2056
2057 pGameLoadingUI_ProgressBar->Progress();
2058
2059 //pFilename = (char *)(112 * uNumSpriteObjects);
2060 memcpy(pSpriteObjects.data(), pSrc + 4, uNumSpriteObjects * sizeof(SpriteObject));
2061 pSrc += 4 + uNumSpriteObjects * sizeof(SpriteObject);
2062
2063 //v94 = (char *)v93 + (int)pFilename;
2064 pGameLoadingUI_ProgressBar->Progress();
2065
2066 memcpy(&uNumChests, pSrc, 4);
2067 //v95 = (char *)v94 + 4;
2068 if (uNumChests > 20)
2069 MessageBoxW(nullptr, L"Can't load file!",
2070 L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odmap.cpp:968", 0);
2071
2072 pGameLoadingUI_ProgressBar->Progress();
2073
2074 assert(sizeof(Chest) == 5324);
2075 //pFilename = (char *)(5324 * uNumChests);
2076 memcpy(pChests.data(), pSrc + 4 , uNumChests * sizeof(Chest));
2077 pSrc += 4 + uNumChests * sizeof(Chest);
2078 //v96 = (char *)v95 + (int)pFilename;
2079 pGameLoadingUI_ProgressBar->Progress();
2080
2081 memcpy(&stru_5E4C90_MapPersistVars, pSrc, 0xC8);
2082 pSrc += 0xC8;
2083
2084 pGameLoadingUI_ProgressBar->Progress();
2085 memcpy(&loc_time, pSrc, 0x38u);
2086
2087 free(pSrcMem);
2088
2089 pTileTable->InitializeTileset(Tileset_Dirt);
2090 pTileTable->InitializeTileset(Tileset_Snow);
2091 pTileTable->InitializeTileset(pTileTypes[0].tileset);
2092 pTileTable->InitializeTileset(pTileTypes[1].tileset);
2093 pTileTable->InitializeTileset(pTileTypes[2].tileset);
2094 pTileTable->InitializeTileset(pTileTypes[3].tileset);
2095 strcpy(pGroundTileset, byte_6BE124_cfg_textures_DefaultGroundTexture.data());
2096 TileDesc* v98 = pTileTable->GetTileById(pTileTypes[0].uTileID);
2097 sMainTile_BitmapID = pBitmaps_LOD->LoadTexture(v98->pTileName, TEXTURE_DEFAULT);
2098 if (sMainTile_BitmapID != -1)
2099 pBitmaps_LOD->pTextures[sMainTile_BitmapID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[sMainTile_BitmapID].palette_id1);
2100
2101 _47F0E2();
2102
2103 //LABEL_150:
2104 if ( pWeather->bRenderSnow ) //Ritor1: it's include for snow
2105 strcpy(loc_time.sky_texture_name, "sky19");
2106 else if (loc_time.uLastVisitDay)
2107 {
2108 if ( (signed int)((signed int)(signed __int64)((double)loc_time.uLastVisitDay * 0.234375) / 60 / 60 / 24) % 28 != pParty->uDaysPlayed )
2109 {
2110 if ( rand() % 100 >= 20 )
2111 v108 = dword_4EC268[rand() % dword_4EC2A8];
2112 else
2113 v108 = dword_4EC28C[rand() % dword_4EC2AC];
2114 sprintf(loc_time.sky_texture_name, "plansky%d", v108);
2115 }
2116 }
2117 else
2118 strcpy(loc_time.sky_texture_name, "plansky3");
2119
2120 //v101 = pBitmaps_LOD->LoadTexture(field_4F8);
2121 sSky_TextureID = pBitmaps_LOD->LoadTexture(loc_time.sky_texture_name);
2122 if (sSky_TextureID != -1)
2123 pBitmaps_LOD->pTextures[sSky_TextureID].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[sSky_TextureID].palette_id1);
2124
2125 pPaletteManager->RecalculateAll();
2126 pSoundList->LoadSound(53, 0);
2127 pSoundList->LoadSound(92, 0);
2128 pSoundList->LoadSound(57, 0);
2129 pSoundList->LoadSound(96, 0);
2130 pSoundList->LoadSound(64, 0);
2131 pSoundList->LoadSound(103, 0);
2132 for (int i=0; i < 3;++i)
2133 {
2134 switch ( pTileTypes[i].tileset )
2135 {
2136 case Tileset_Grass:
2137 pSoundList->LoadSound(54, 0);
2138 pSoundList->LoadSound(93, 0);
2139 break;
2140 case Tileset_Snow:
2141 pSoundList->LoadSound(58, 0);
2142 pSoundList->LoadSound(97, 0);
2143 break;
2144 case Tilset_Desert:
2145 pSoundList->LoadSound(52, 0);
2146 pSoundList->LoadSound(91, 0);
2147 break;
2148 case Tileset_3:
2149 pSoundList->LoadSound(51, 0);
2150 pSoundList->LoadSound(90, 0);
2151 break;
2152 case Tileset_Water:
2153 pSoundList->LoadSound(62, 0);
2154 pSoundList->LoadSound(101, 0);
2155 break;
2156 case Tileset_6:
2157 pSoundList->LoadSound(49, 0);
2158 pSoundList->LoadSound(88, 0);
2159 break;
2160 case Tileset_Swamp:
2161 pSoundList->LoadSound(61, 0);
2162 pSoundList->LoadSound(100, 0);
2163 break;
2164 }
2165 }
2166 return true;
2167 }
2168
2169 //----- (0047ECC1) --------------------------------------------------------
2170 int OutdoorLocation::GetTileIdByTileMapId(signed int a2)
2171 {
2172 signed int result; // eax@2
2173 int v3; // eax@3
2174
2175 if ( a2 >= 90 )
2176 {
2177 v3 = (a2 - 90) / 36;
2178 if ( v3 && v3 != 1 && v3 != 2 )
2179 {
2180 if ( v3 == Tileset_3 )
2181 result = this->pTileTypes[3].uTileID;
2182 else
2183 result = a2;
2184 }
2185 else
2186 result = this->pTileTypes[v3].uTileID;
2187 }
2188 else
2189 result = 0;
2190 return result;
2191 }
2192
2193 //----- (0047ED08) --------------------------------------------------------
2194 unsigned int OutdoorLocation::DoGetTileTexture(signed int sX, signed int sY)
2195 {
2196 int v3; // esi@5
2197 // unsigned int result; // eax@9
2198
2199 assert(sX < 128 && sY < 128);
2200
2201 v3 = this->pTerrain.pTilemap[sY * 128 + sX];
2202 if (v3 < 198) // < Tileset_3
2203 {
2204 if (v3 >= 90)
2205 v3 = v3 + this->pTileTypes[(v3 - 90) / 36].uTileID - 36 * ((v3 - 90) / 36) - 90;
2206 }
2207 else
2208 v3 = v3 + this->pTileTypes[3].uTileID - 198;
2209
2210 #pragma region "New: seasons change"
2211
2212 if (change_seasons)
2213 switch (pParty->uCurrentMonth)
2214 {
2215 case 11: case 0: case 1: // winter
2216 if (v3 >= 90) // Tileset_Grass begins at TileID = 90
2217 {
2218 if (v3 <= 95) // some grastyl entries
2219 v3 = 348;
2220 else if (v3 <= 113) // rest of grastyl & all grdrt*
2221 v3 = 348 + (v3 - 96);
2222 }
2223 /*switch (v3)
2224 {
2225 case 102: v3 = 354; break; // grdrtNE -> SNdrtne
2226 case 104: v3 = 356; break; // grdrtNW -> SNdrtnw
2227 case 108: v3 = 360; break; // grdrtN -> SNdrtn
2228 }*/
2229 break;
2230
2231 case 2: case 3: case 4: // spring
2232 case 8: case 9: case 10: // autumn
2233 if (v3 >= 90 && v3 <= 113) // just convert all Tileset_Grass to dirt
2234 v3 = 1;
2235 break;
2236
2237 case 5: case 6: case 7: // summer
2238 //all tiles are green grass by default
2239 break;
2240
2241 default: assert(pParty->uCurrentMonth >= 0 && pParty->uCurrentMonth < 12);
2242 }
2243 #pragma endregion
2244
2245 return pTileTable->pTiles[v3].uBitmapID;
2246 }
2247
2248 //----- (0047ED83) --------------------------------------------------------
2249 int OutdoorLocation::_47ED83(signed int a2, signed int a3)
2250 {
2251 assert(a2 < 128 && a3 < 128);
2252
2253 return *(&this->pTerrain.pTilemap[128 * a3] + a2);
2254 }
2255
2256 //----- (0047EDB3) --------------------------------------------------------
2257 int OutdoorLocation::ActuallyGetSomeOtherTileInfo(signed int sX, signed int sY)
2258 {
2259 assert(sX < 128 && sY < 128);
2260 int v3; // esi@5
2261
2262 v3 = this->pTerrain.pTilemap[sY * 128 + sX];
2263 if ( v3 >= 90 )
2264 v3 = v3 + this->pTileTypes[(v3 - 90) / 36].uTileID - 36 * ((v3 - 90) / 36) - 90;
2265 return pTileTable->pTiles[v3].uAttributes;
2266 }
2267
2268 //----- (0047EE16) --------------------------------------------------------
2269 int OutdoorLocation::DoGetHeightOnTerrain(signed int sX, signed int sZ)
2270 {
2271 assert(sX < 128 && sZ < 128);
2272
2273 return 32 * pTerrain.pHeightmap[sZ * 128 + sX];
2274 }
2275
2276 //----- (0047EE49) --------------------------------------------------------
2277 int OutdoorLocation::GetSoundIdByPosition( signed int X_pos, signed int Y_pos, int running )
2278 {
2279 signed int v4; // eax@5
2280 signed int v5; // eax@7
2281 // int v6; // eax@8
2282 signed int v8; // eax@9
2283 int modif=0;
2284
2285 if ( X_pos < 0 || X_pos > 127 || Y_pos < 0 || Y_pos > 127 )
2286 v4 = 0;
2287 else
2288 v4 = this->pTerrain.pTilemap[128 * Y_pos + X_pos];
2289 v5 = GetTileIdByTileMapId(v4);
2290 if (running)
2291 modif=-39;
2292 if ( !v5 )
2293 return 92+modif;
2294
2295 switch (pTileTable->pTiles[v5].tileset)
2296 {
2297 case 0: return 93+ modif;
2298 case 1: return 97+ modif;
2299 case 2: return 91+ modif;
2300 case 3: return 90+ modif;
2301 case 4: return 101+ modif;
2302 case 5: return 95+ modif;
2303 case 6: return 88+ modif;
2304 case 7: return 100+ modif;
2305 case 8: return 93+ modif;
2306 default:
2307 v8=pTileTable->pTiles[v5].tileset;
2308 if ( (v8 > 9 && v8 <= 17) || (v8 > 21 && v8 <= 27) )
2309 return 96+ modif;
2310 else
2311 return 95+ modif;
2312 }
2313
2314 }
2315
2316 //----- (0047EF60) --------------------------------------------------------
2317 int OutdoorLocation::UpdateDiscoveredArea(int X_grid_pos, int Y_grid_poa, int a4)
2318 {
2319 for (int i = -10; i < 10; i++)
2320 {
2321 int currYpos = Y_grid_poa + i - 20;
2322 for (int j = -10; j < 10; j++)
2323 {
2324 int currXpos = X_grid_pos + j - 20;
2325 int distanceSquared = i * i + j * j;
2326 if ( distanceSquared <= 100 && currYpos >= 0 && currYpos <= 87 && currXpos >= 0 && currXpos <= 87 )
2327 {
2328 unsigned char v13 = 1 << (7 - currXpos % 8);
2329 this->uPartiallyRevealedCellOnMap[currYpos][currXpos / 8] |= v13;
2330 if ( distanceSquared <= 49 )
2331 this->uFullyRevealedCellOnMap[currYpos][currXpos / 8] |= v13;
2332 }
2333 }
2334 }
2335 return 1;
2336 }
2337
2338
2339 //----- (0047F04C) --------------------------------------------------------
2340 bool OutdoorLocation::IsMapCellFullyRevealed(signed int x_pos, signed int y_pos)
2341 {
2342 if ( x_pos < 0 || x_pos >= 88 || y_pos < 0 || y_pos >= 88 )
2343 return false;
2344 else
2345 return (uFullyRevealedCellOnMap[y_pos][x_pos/8] & (1 << (7 - (x_pos) % 8))) != 0;
2346 }
2347
2348 //----- (0047F097) --------------------------------------------------------
2349 bool OutdoorLocation::IsMapCellPartiallyRevealed(signed int x_pos, signed int y_pos)
2350 {
2351 if ( x_pos < 0 || x_pos >= 88 || y_pos < 0 || y_pos >= 88 )
2352 return false;
2353 else
2354 return (uPartiallyRevealedCellOnMap[y_pos][x_pos/8] & (1 << (7 - (x_pos) % 8))) != 0;
2355 }
2356
2357 //----- (0047F0E2) --------------------------------------------------------
2358 bool OutdoorLocation::_47F0E2()
2359 {
2360 for ( uint i = 0; i < (signed int)pBitmaps_LOD->uNumLoadedFiles; ++i )
2361 {
2362 //if ( i != -1 ? (int)&pBitmaps_LOD->pTextures[i] : 0 )
2363 pBitmaps_LOD->pTextures[i].uDecompressedSize = this->pTerrain._47CB57((int)pBitmaps_LOD->pTextures[i].pLevelOfDetail0_prolly_alpha_mask,
2364 pBitmaps_LOD->pTextures[i].palette_id2,
2365 pBitmaps_LOD->pTextures[i].uTextureWidth * pBitmaps_LOD->pTextures[i].uTextureHeight);
2366 }
2367 return 1;
2368 }
2369
2370 //----- (0047F138) --------------------------------------------------------
2371 bool OutdoorLocation::PrepareDecorations()
2372 {
2373 signed int v1; // ebx@1
2374 signed int v8; // [sp+Ch] [bp-4h]@1
2375
2376 v1 = 0;
2377 v8 = 0;
2378 if ( !_stricmp(pCurrentMapName, "out09.odm") )
2379 v8 = 1;
2380
2381 for (uint i = 0; i < uNumLevelDecorations; ++i)
2382 {
2383 LevelDecoration* decor = &pLevelDecorations[i];
2384
2385 pDecorationList->InitializeDecorationSprite(decor->uDecorationDescID);
2386 if ( pDecorationList->pDecorations[decor->uDecorationDescID].uSoundID && _6807E0_num_decorations_with_sounds_6807B8 < 9 )
2387 {
2388 pSoundList->LoadSound(pDecorationList->pDecorations[decor->uDecorationDescID].uSoundID, 0);
2389 _6807B8_level_decorations_ids[_6807E0_num_decorations_with_sounds_6807B8++] = i;
2390 }
2391 if ( v8 && decor->uCog == 20 )
2392 decor->uFlags |= LEVEL_DECORATION_OBELISK_CHEST;
2393 if ( !decor->uEventID )
2394 {
2395 if ( decor->IsInteractive() )
2396 {
2397 if ( v1 < 124 )
2398 {
2399 decor->_idx_in_stru123 = v1 + 75;
2400 if ( !stru_5E4C90_MapPersistVars._decor_events[v1++] )
2401 decor->uFlags |= LEVEL_DECORATION_INVISIBLE;
2402 }
2403 }
2404 }
2405 }
2406
2407 pGameLoadingUI_ProgressBar->Progress();
2408 return true;
2409 }
2410 // 6807E0: using guessed type int _6807E0_num_decorations_6807B8;
2411
2412 //----- (0047F223) --------------------------------------------------------
2413 void OutdoorLocation::ArrangeSpriteObjects()
2414 {
2415 OutdoorLocation *v5; // [sp+0h] [bp-4h]@1
2416
2417 v5 = this;
2418 if ( (signed int)uNumSpriteObjects > 0 )
2419 {
2420 for ( int i = 0; i < (signed int)uNumSpriteObjects; ++i )
2421 {
2422 if ( pSpriteObjects[i].uObjectDescID )
2423 {
2424 if ( !(pSpriteObjects[i].uAttributes & 8) && !(pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uFlags & 0x10) )
2425 pSpriteObjects[i].vPosition.z = GetTerrainHeightsAroundParty2(pSpriteObjects[i].vPosition.x, pSpriteObjects[i].vPosition.y, (int *)&v5, 0);
2426 if ( pSpriteObjects[i].stru_24.uItemID )
2427 {
2428 if ( pSpriteObjects[i].stru_24.uItemID != 220
2429 && pItemsTable->pItems[pSpriteObjects[i].stru_24.uItemID].uEquipType == EQUIP_POTION
2430 && !pSpriteObjects[i].stru_24.uEnchantmentType )
2431 pSpriteObjects[i].stru_24.uEnchantmentType = rand() % 15 + 5;
2432 pItemsTable->SetSpecialBonus(&pSpriteObjects[i].stru_24);
2433 }
2434 }
2435 }
2436 }
2437 pGameLoadingUI_ProgressBar->Progress();
2438 }
2439
2440 //----- (0047F2D3) --------------------------------------------------------
2441 bool OutdoorLocation::InitalizeActors(int a1)
2442 {
2443 int alert_status; // [sp+348h] [bp-8h]@1
2444 // int v9; // [sp+34Ch] [bp-4h]@1
2445
2446 alert_status = 0;
2447 for( int i = 0; i < uNumActors; ++i )
2448 {
2449 if ( !(pActors[i].uAttributes & ACTOR_UNKNOW7) )
2450 {
2451 if ( alert_status != 1 )
2452 {
2453 pActors[i].uCurrentActionTime = 0;
2454 pActors[i].uCurrentActionLength = 0;
2455 if ( pActors[i].uAttributes & ACTOR_UNKNOW11 )
2456 pActors[i].uAIState = AIState::Disabled;
2457 if ( pActors[i].uAIState != AIState::Removed && pActors[i].uAIState != AIState::Disabled &&
2458 (pActors[i].sCurrentHP == 0 || pActors[i].pMonsterInfo.uHP == 0) )
2459 pActors[i].uAIState = AIState::Dead;
2460 pActors[i].vVelocity.x = 0;
2461 pActors[i].vVelocity.y = 0;
2462 pActors[i].vVelocity.z = 0;
2463 pActors[i].UpdateAnimation();
2464 pActors[i].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
2465 pActors[i].PrepareSprites(0);
2466 }
2467 else
2468 {
2469 pActors[i].uAIState = AIState::Disabled;
2470 pActors[i].uAttributes |= ACTOR_UNKNOW11;
2471 }
2472 }
2473 else if ( a1 == 0 )
2474 {
2475 pActors[i].uAIState = AIState::Disabled;
2476 pActors[i].uAttributes |= ACTOR_UNKNOW11;
2477 }
2478 else if ( alert_status != 0 )
2479 {
2480 pActors[i].uCurrentActionTime = 0;
2481 pActors[i].uCurrentActionLength = 0;
2482 if ( pActors[i].uAttributes & ACTOR_UNKNOW11 )
2483 pActors[i].uAIState = AIState::Disabled;
2484 if ( pActors[i].uAIState != AIState::Removed && pActors[i].uAIState != AIState::Disabled &&
2485 (pActors[i].sCurrentHP == 0 || pActors[i].pMonsterInfo.uHP == 0) )
2486 pActors[i].uAIState = AIState::Dead;
2487 pActors[i].vVelocity.x = 0;
2488 pActors[i].vVelocity.y = 0;
2489 pActors[i].vVelocity.z = 0;
2490 pActors[i].UpdateAnimation();
2491 pActors[i].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
2492 pActors[i].PrepareSprites(0);
2493 }
2494 else
2495 {
2496 pActors[i].uAIState = AIState::Disabled;
2497 pActors[i].uAttributes |= ACTOR_UNKNOW11;
2498 alert_status = GetAlertStatus();
2499 }
2500 }
2501
2502 pGameLoadingUI_ProgressBar->Progress();
2503 //no use for this
2504 // Actor thisa;
2505 // thisa.pMonsterInfo.uID = 45;
2506 // thisa.PrepareSprites(0);
2507 return 1;
2508 }
2509
2510 //----- (0047F3EA) --------------------------------------------------------
2511 bool OutdoorLocation::LoadRoadTileset()
2512 {
2513 pTileTypes[3].uTileID = pTileTable->GetTileForTerrainType(pTileTypes[3].tileset, 1);
2514 pTileTable->InitializeTileset(pTileTypes[3].tileset);
2515 return 1;
2516 }
2517
2518 //----- (0047F420) --------------------------------------------------------
2519 bool OutdoorLocation::LoadTileGroupIds()
2520 {
2521 for (uint i = 0; i < 3; ++i)
2522 pTileTypes[i].uTileID = pTileTable->GetTileForTerrainType(pTileTypes[i].tileset, 1);
2523
2524 return true;
2525 }
2526
2527 //----- (0047B42C) --------------------------------------------------------
2528 void OutdoorLocation::PrepareActorsDrawList()
2529 {
2530 unsigned int result; // eax@1
2531 int z; // esi@5
2532 float v4; // ST48_4@8
2533 unsigned int v8; // eax@11
2534 int v9; // edx@11
2535 signed int v12; // eax@16
2536 SpriteFrame *v14; // eax@24
2537 SpriteFrame *v15; // ebx@25
2538 int v17; // eax@35
2539 int v18; // ST78_4@36
2540 int v19; // eax@36
2541 int v20; // ecx@38
2542 int v21; // eax@38
2543 int v22; // ecx@41
2544 int v23; // ST5C_4@43
2545 int v24; // esi@44
2546 signed __int64 v25; // qtt@45
2547 int v26; // ST54_4@45
2548 int v27; // ecx@45
2549 int v34; // ecx@54
2550 int v41; // [sp+24h] [bp-3Ch]@11
2551 int v42; // [sp+28h] [bp-38h]@38
2552 int v43; // [sp+28h] [bp-38h]@45
2553 int v44; // [sp+2Ch] [bp-34h]@36
2554 int v45; // [sp+2Ch] [bp-34h]@44
2555 int v46; // [sp+2Ch] [bp-34h]@45
2556 int v47; // [sp+30h] [bp-30h]@36
2557 int v48; // [sp+30h] [bp-30h]@41
2558 signed int v49; // [sp+34h] [bp-2Ch]@5
2559 int v50; // [sp+34h] [bp-2Ch]@36
2560 int v51; // [sp+34h] [bp-2Ch]@41
2561 int v53; // [sp+38h] [bp-28h]@36
2562 int y; // [sp+40h] [bp-20h]@5
2563 int x; // [sp+44h] [bp-1Ch]@5
2564 int v57; // [sp+48h] [bp-18h]@45
2565 int v58; // [sp+4Ch] [bp-14h]@45
2566 int X; // [sp+54h] [bp-Ch]@36
2567 signed __int16 v62; // [sp+5Ch] [bp-4h]@25
2568
2569 //result = 0;
2570 //v59 = 0;
2571 for (int i = 0; i < uNumActors; ++i)
2572 {
2573 //v54 = 0;
2574 //v1 = pActors;//[0].vPosition.z;
2575 //do
2576 //{
2577 //Actor* actor = &pActors[i];
2578 //v2 = actor->uAIState;
2579
2580 pActors[i].uAttributes &= 0xFFFFFFF7;//~0x8
2581 if (pActors[i].uAIState == Removed || pActors[i].uAIState == Disabled)
2582 continue;
2583
2584 z = pActors[i].vPosition.z;
2585 v49 = 0;
2586 x = pActors[i].vPosition.x;
2587 y = pActors[i].vPosition.y;
2588 if (pActors[i].uAIState == Summoned)
2589 {
2590 if (PID_TYPE(pActors[i].uSummonerID) != OBJECT_Actor ||
2591 pActors[PID_ID(pActors[i].uSummonerID)].pMonsterInfo.uSpecialAbilityDamageDiceSides != 1 )
2592 {
2593 z += floorf(pActors[i].uActorHeight * 0.5f + 0.5f);
2594 }
2595 else
2596 {
2597 v49 = 1;
2598 pGame->pStru6Instance->_4A7F74(pActors[i].vPosition.x, pActors[i].vPosition.y, z);
2599 v4 = (1.0 - (double)pActors[i].uCurrentActionTime / (double)pActors[i].uCurrentActionLength) *
2600 (double)(2 * pActors[i].uActorHeight);
2601 z -= floorf(v4 + 0.5f);
2602 if ( z > pActors[i].vPosition.z )
2603 z = pActors[i].vPosition.z;
2604 }
2605 }
2606 v8 = stru_5C6E00->Atan2(pActors[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
2607 pActors[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
2608 LOWORD(v9) = pActors[i].uYawAngle;
2609 v41 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v9 - v8) >> 8) & 7;
2610 if ( pParty->bTurnBasedModeOn )
2611 {
2612 v12 = pActors[i].uCurrentActionTime;
2613 if ( pActors[i].uCurrentActionAnimation == 1 )
2614 v12 = 32 * i + pMiscTimer->uTotalGameTimeElapsed;
2615 }
2616 else
2617 {
2618 v12 = pActors[i].uCurrentActionTime;
2619 if ( pActors[i].uCurrentActionAnimation == 1 )
2620 v12 = 32 * i + pEventTimer->uTotalGameTimeElapsed;
2621 }
2622 if ( (signed __int64)pActors[i].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 || (signed __int64)pActors[i].pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0 )
2623 v12 = 0;
2624 if ( pActors[i].uAIState == 17 && !v49 )
2625 v14 = pSpriteFrameTable->GetFrame(uSpriteID_Spell11, v12);
2626 else if ( pActors[i].uAIState == 16 )
2627 v14 = pSpriteFrameTable->GetFrameBy_x(pActors[i].pSpriteIDs[pActors[i].uCurrentActionAnimation], v12);
2628 else
2629 v14 = pSpriteFrameTable->GetFrame(pActors[i].pSpriteIDs[pActors[i].uCurrentActionAnimation], v12);
2630 v62 = 0;
2631 v15 = v14;
2632 //v16 = (int *)v14->uFlags;
2633 if (v14->uFlags & 2)
2634 v62 = 2;
2635 if (v14->uFlags & 0x40000)
2636 v62 |= 0x40;
2637 if (v14->uFlags & 0x20000)
2638 LOBYTE(v62) = v62 | 0x80;
2639 if ((256 << v41) & v14->uFlags)
2640 v62 |= 4;
2641 if ( v15->uGlowRadius )
2642 {
2643 //LOBYTE(v16) = _4E94D3_light_type;
2644 pMobileLightsStack->AddLight(x, y, z, 0, v15->uGlowRadius, 0xFFu, 0xFFu, 0xFFu, _4E94D3_light_type);
2645 }
2646 v17 = (x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
2647 if (pGame->pIndoorCameraD3D->sRotationX)
2648 {
2649 v18 = (y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
2650 v47 = (fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_sine_y));
2651 v50 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_sine_y);
2652 v53 = fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_cosine_y);
2653 v44 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
2654 v19 = (fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_cosine_x));
2655 X = fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_cosine_x);
2656 if ( v19 < 262144 || v19 > pODMRenderParams->shading_dist_mist << 16 )
2657 continue;
2658 v20 = v53 - v50;
2659 v42 = v53 - v50;
2660 v21 = (fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_sine_x));
2661 }
2662 else
2663 {
2664 v48 = (y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
2665 v51 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y);
2666 v22 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_sine_y);
2667 X = v22 + v51;
2668 if ( v22 + v51 < 262144 || v22 + v51 > pODMRenderParams->shading_dist_mist << 16 )
2669 continue;
2670 v23 = fixpoint_mul(((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16), pGame->pIndoorCameraD3D->int_sine_y);
2671 v20 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_cosine_y) - v23;
2672 v42 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_cosine_y) - v23;
2673 v21 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
2674 }
2675 v45 = v21;
2676 v24 = abs(v20);
2677 if ( abs(X) >= v24 )
2678 {
2679 LODWORD(v25) = 0;
2680 HIDWORD(v25) = SLOWORD(pODMRenderParams->int_fov_rad);
2681 v58 = v25 / X;
2682 v26 = v25 / X;
2683 LODWORD(v25) = 0;
2684 HIDWORD(v25) = SLOWORD(pODMRenderParams->int_fov_rad);
2685 v57 = v25 / X;
2686 v27 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v26, v42) + 0x8000) >> 16);
2687 v43 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v26, v42) + 0x8000) >> 16);
2688 v46 = pViewport->uScreenCenterY - ((signed int)(fixpoint_mul(v25 / X, v45) + 0x8000) >> 16);
2689 result = uNumBillboardsToDraw;
2690 //v28 = &pBillboardRenderList[uNumBillboardsToDraw];
2691 if (uNumBillboardsToDraw >= 500)
2692 return;
2693 ++uNumBillboardsToDraw;
2694 ++uNumSpritesDrawnThisFrame;
2695 pActors[i].uAttributes |= ACTOR_UNKNOW2;
2696 pBillboardRenderList[uNumBillboardsToDraw - 1].HwSpriteID = v15->pHwSpriteIDs[v41];
2697 pBillboardRenderList[uNumBillboardsToDraw - 1].uIndoorSectorID = 0;
2698 pBillboardRenderList[uNumBillboardsToDraw - 1].uPalette = v15->uPaletteIndex;
2699 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v15->scale, v58);
2700 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(v15->scale, v57);
2701 if ( pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0 )
2702 {
2703 if ( pActors[i].pActorBuffs[ACTOR_BUFF_MASS_DISTORTION].uExpireTime > 0 )
2704 {
2705 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(pGame->pStru6Instance->_4A806F(&pActors[i]),
2706 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat);
2707 LOWORD(v27) = v43;
2708 }
2709 }
2710 else
2711 {
2712 if ( pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uPower )
2713 {
2714 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(65536 / pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uPower,
2715 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat);
2716 LOWORD(v27) = v43;
2717 }
2718 }
2719 pBillboardRenderList[uNumBillboardsToDraw - 1].uScreenSpaceX = v27;
2720 pBillboardRenderList[uNumBillboardsToDraw - 1].uScreenSpaceY = v46;
2721 pBillboardRenderList[uNumBillboardsToDraw - 1].world_x = x;
2722 pBillboardRenderList[uNumBillboardsToDraw - 1].world_y = y;
2723 pBillboardRenderList[uNumBillboardsToDraw - 1].world_z = z;
2724 HIWORD(v34) = HIWORD(X);
2725 LOWORD(v34) = 0;
2726 pBillboardRenderList[uNumBillboardsToDraw - 1].dimming_level = 0;
2727 pBillboardRenderList[uNumBillboardsToDraw - 1].sZValue = v34 + PID(OBJECT_Actor, i);
2728 pBillboardRenderList[uNumBillboardsToDraw - 1].field_14_actor_id = i;
2729 //v35 = pMonsterList->pMonsters;
2730 //v36 = pActors[i].pMonsterInfo.uID;
2731 pBillboardRenderList[uNumBillboardsToDraw - 1].field_1E = v62 | 0x200;
2732 pBillboardRenderList[uNumBillboardsToDraw - 1].pSpriteFrame = v15;
2733 pBillboardRenderList[uNumBillboardsToDraw - 1].sTintColor = pMonsterList->pMonsters[pActors[i].pMonsterInfo.uID - 1].sTintColor;//*((int *)&v35[v36] - 36);
2734 if (pActors[i].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime)
2735 pBillboardRenderList[uNumBillboardsToDraw - 1].field_1E = v62 | 0x200;
2736 }
2737 //LABEL_58:
2738 //++v59;
2739 //v54 += 32;
2740 //result = v59;
2741 //++v1;
2742 //}
2743 //while ( v59 < (signed int)uNumActors );
2744 }
2745 //return result;
2746 }
2747
2748 //----- (0044C1E8) --------------------------------------------------------
2749 bool ODMFace::HasEventHint()
2750 {
2751 signed int event_index; // eax@1
2752 _evt_raw* start_evt;
2753 _evt_raw* end_evt;
2754
2755 event_index = 0;
2756 if ( (uLevelEVT_NumEvents - 1) <= 0 )
2757 return false;
2758 while ( pLevelEVT_Index[event_index].uEventID != this->sCogTriggeredID )
2759 {
2760 ++event_index;
2761 if ( event_index >= (signed int)(uLevelEVT_NumEvents - 1) )
2762 return false;
2763 }
2764 end_evt=(_evt_raw*)&pLevelEVT[pLevelEVT_Index[event_index+1].uEventOffsetInEVT];
2765 start_evt=(_evt_raw*)&pLevelEVT[pLevelEVT_Index[event_index].uEventOffsetInEVT];
2766 if ( (end_evt->_e_type != EVENT_Exit) || (start_evt->_e_type!= EVENT_MouseOver) )
2767 return false;
2768 else
2769 return true;
2770 }
2771 //----- (0046D49E) --------------------------------------------------------
2772 int ODM_GetFloorLevel(int X, signed int Y, int Z, int __unused, int *pIsOnWater, int *bmodel_pid, int bWaterWalk)
2773 {
2774 BSPModel *pBModel; // esi@4
2775 ODMFace *pFace; // ecx@11
2776 // int v14; // edx@20
2777 signed int v18; // edx@26
2778 int v19; // eax@28
2779 // int v20; // edx@30
2780 // int v21; // ST1C_4@30
2781 signed int v22; // edx@30
2782 signed __int64 v23; // qtt@30
2783 int v24; // eax@36
2784 signed int v25; // ecx@38
2785 // int result; // eax@42
2786 signed int current_floor_level; // ecx@43
2787 // int v28; // edi@44
2788 signed int v29; // edx@44
2789 // int v30; // esi@45
2790 // int v31; // eax@45
2791 // int v33; // ecx@59
2792 // int v36; // [sp+14h] [bp-2Ch]@24
2793 // int v38; // [sp+1Ch] [bp-24h]@2
2794 int v39; // [sp+20h] [bp-20h]@9
2795 signed int pBModelNum; // [sp+28h] [bp-18h]@1
2796 int pFaceNum; // [sp+2Ch] [bp-14h]@8
2797 bool current_vertices_Y; // [sp+30h] [bp-10h]@22
2798 bool next_vertices_Y; // [sp+34h] [bp-Ch]@24
2799 signed int v46; // [sp+3Ch] [bp-4h]@1
2800 signed int number_hits; // [sp+58h] [bp+18h]@22
2801 signed int next_floor_level; // [sp+58h] [bp+18h]@43
2802
2803 v46 = 1;
2804 current_BModel_id[0] = -1;
2805 current_Face_id[0] = -1;
2806 odm_floor_level[0] = GetTerrainHeightsAroundParty2(X, Y, pIsOnWater, bWaterWalk);
2807
2808 for ( pBModelNum = 0; pBModelNum < pOutdoor->uNumBModels; ++pBModelNum )
2809 {
2810 pBModel = &pOutdoor->pBModels[pBModelNum];
2811 if ( X <= pBModel->sMaxX && X >= pBModel->sMinX &&
2812 Y <= pBModel->sMaxY && Y >= pBModel->sMinY )
2813 {
2814 if ( pBModel->uNumFaces > 0 )
2815 {
2816 v39 = 0;
2817 for ( pFaceNum = 0; pFaceNum < pBModel->uNumFaces; ++pFaceNum )
2818 {
2819 pFace = &pBModel->pFaces[pFaceNum];
2820 if ( pFace->Ethereal() )
2821 continue;
2822 if ( (pFace->uPolygonType == POLYGON_Floor || pFace->uPolygonType == POLYGON_InBetweenFloorAndWall)
2823 && X <= pFace->pBoundingBox.x2 && X >= pFace->pBoundingBox.x1
2824 && Y <= pFace->pBoundingBox.y2 && Y >= pFace->pBoundingBox.y1 )
2825 {
2826 for ( uint i = 0; i < pFace->uNumVertices; ++i)
2827 {
2828 odm_floor_face_vert_coord_X[2 * i] = pFace->pXInterceptDisplacements[i] + pBModel->pVertices.pVertices[pFace->pVertexIDs[i]].x;
2829 odm_floor_face_vert_coord_Y[2 * i] = pFace->pYInterceptDisplacements[i] + pBModel->pVertices.pVertices[pFace->pVertexIDs[i]].y;
2830 odm_floor_face_vert_coord_X[2 * i + 1] = pFace->pXInterceptDisplacements[i] + pBModel->pVertices.pVertices[pFace->pVertexIDs[i + 1]].x;
2831 odm_floor_face_vert_coord_Y[2 * i + 1] = pFace->pYInterceptDisplacements[i] + pBModel->pVertices.pVertices[pFace->pVertexIDs[i + 1]].y;
2832 }
2833 odm_floor_face_vert_coord_X[2 * pFace->uNumVertices] = odm_floor_face_vert_coord_X[0];
2834 odm_floor_face_vert_coord_Y[2 * pFace->uNumVertices] = odm_floor_face_vert_coord_Y[0];
2835
2836 current_vertices_Y = odm_floor_face_vert_coord_Y[0] >= Y;
2837 number_hits = 0;
2838 if ( 2 * pFace->uNumVertices > 0 )
2839 {
2840 for ( int i = 0; i < 2 * pFace->uNumVertices; ++i )
2841 {
2842 if ( number_hits >= 2 )
2843 break;
2844 //v36 = odm_floor_face_vert_coord_Y[i + 1];
2845 next_vertices_Y = odm_floor_face_vert_coord_Y[i + 1] >= Y;
2846 if ( current_vertices_Y != next_vertices_Y )//проверка по Y
2847 {
2848 v18 = odm_floor_face_vert_coord_X[i + 1] >= X ? 0 : 2;
2849 v19 = v18 | (odm_floor_face_vert_coord_X[i] < X);
2850 if ( v19 != 3 )
2851 {
2852 if ( !v19 )
2853 ++number_hits;
2854 else
2855 {
2856 LODWORD(v23) = (Y - odm_floor_face_vert_coord_Y[i]) << 16;
2857 HIDWORD(v23) = (Y - odm_floor_face_vert_coord_Y[i]) >> 16;
2858 v22 = ((((odm_floor_face_vert_coord_X[i + 1] - odm_floor_face_vert_coord_X[i]) * v23 / (odm_floor_face_vert_coord_Y[i + 1]
2859 - odm_floor_face_vert_coord_Y[i])) >> 16) + odm_floor_face_vert_coord_X[i]);
2860 if ( v22 >= X)
2861 ++number_hits;
2862 }
2863 }
2864 }
2865 current_vertices_Y = next_vertices_Y;
2866 }
2867 if ( number_hits == 1 )
2868 {
2869 if ( v46 >= 20 )
2870 break;
2871 if ( pFace->uPolygonType == POLYGON_Floor )
2872 v24 = pBModel->pVertices.pVertices[pFace->pVertexIDs[0]].z;
2873 else
2874 {
2875 int a = fixpoint_mul(pFace->zCalc1, X);
2876 int b = fixpoint_mul(pFace->zCalc2, Y);
2877 int c = ((signed __int64)pFace->zCalc3 >> 16);
2878 v24 = a + b + c;
2879 }
2880 v25 = v46++;
2881 odm_floor_level[v25] = v24;
2882 current_BModel_id[v25] = pBModelNum;
2883 current_Face_id[v25] = pFaceNum;
2884 }
2885 }
2886 }
2887
2888 }
2889 }
2890 }
2891 }
2892 if ( v46 == 1 )
2893 {
2894 *bmodel_pid = 0;
2895 return odm_floor_level[0];
2896 }
2897 current_floor_level = 0;
2898 v29 = 0;
2899 if ( v46 <= 1 )
2900 *bmodel_pid = 0;
2901 else
2902 {
2903 current_floor_level = odm_floor_level[0];
2904 for ( uint i = 1; i < v46; ++i )
2905 {
2906 next_floor_level = odm_floor_level[i];
2907 if ( current_floor_level <= Z + 5 )
2908 {
2909 if ( next_floor_level > current_floor_level && next_floor_level <= Z + 5 )
2910 {
2911 current_floor_level = next_floor_level;
2912 v29 = i;
2913 }
2914 }
2915 else if ( next_floor_level < current_floor_level )
2916 {
2917 current_floor_level = next_floor_level;
2918 v29 = i;
2919 }
2920 }
2921 if ( !v29 )
2922 *bmodel_pid = 0;
2923 else
2924 *bmodel_pid = current_Face_id[v29] | (current_BModel_id[v29] << 6);
2925 }
2926 if ( v29 )
2927 {
2928 *pIsOnWater = false;
2929 if ( pOutdoor->pBModels[current_BModel_id[v29]].pFaces[current_Face_id[v29]].Fluid())
2930 *pIsOnWater = true;
2931 }
2932 if ( odm_floor_level[v29] >= odm_floor_level[0] )
2933 odm_floor_level[0] = odm_floor_level[v29];
2934 return odm_floor_level[0];
2935 }
2936
2937 //not sure if right- or left-handed coordinate space assumed, so this could be normal of inverse normal
2938 // for a right-handed system, that would be an inverse normal
2939 //----- (0046DCC8) --------------------------------------------------------
2940 void ODM_GetTerrainNormalAt(int pos_x, int pos_z, Vec3_int_ *out)
2941 {
2942 uint grid_x = WorldPosToGridCellX(pos_x);
2943 uint grid_z = WorldPosToGridCellZ(pos_z) - 1;
2944
2945 int grid_pos_x1 = GridCellToWorldPosX(grid_x);
2946 int grid_pos_x2 = GridCellToWorldPosX(grid_x + 1);
2947 int grid_pos_z1 = GridCellToWorldPosZ(grid_z);
2948 int grid_pos_z2 = GridCellToWorldPosZ(grid_z + 1);
2949
2950 int x1z1_y = pOutdoor->DoGetHeightOnTerrain(grid_x, grid_z);
2951 int x2z1_y = pOutdoor->DoGetHeightOnTerrain(grid_x + 1, grid_z);
2952 int x2z2_y = pOutdoor->DoGetHeightOnTerrain(grid_x + 1, grid_z + 1);
2953 int x1z2_y = pOutdoor->DoGetHeightOnTerrain(grid_x, grid_z + 1);
2954
2955 float side1_dx, side1_dy, side1_dz,
2956 side2_dx, side2_dy, side2_dz;
2957
2958 int dx = abs(pos_x - grid_pos_x1),
2959 dz = abs(grid_pos_z1 - pos_z);
2960 if (dz >= dx)
2961 {
2962 side2_dx = (double)(grid_pos_x2 - grid_pos_x1);
2963 side2_dz = 0.0;//(double)(grid_pos_z2 - grid_pos_z2); // bug? z2 - z2
2964 side2_dy = (double)(x2z2_y - x1z2_y);
2965
2966 side1_dx = 0.0;//(double)(grid_pos_x1 - grid_pos_x1);
2967 side1_dz = (double)(grid_pos_z1 - grid_pos_z2); // z1 - z2 yes
2968 side1_dy = (double)(x1z1_y - x1z2_y);
2969 //Log::Warning(L"%S %S %u\n", __FILE__, __FUNCTION__, __LINE__);
2970 /* |\
2971 side1 | \
2972 |____\
2973 side 2 */
2974 }
2975 else
2976 {
2977 side2_dx = (double)(grid_pos_x1 - grid_pos_x2);
2978 side2_dz = 0.0;//(double)(grid_pos_z1 - grid_pos_z1);
2979 side2_dy = (double)(x1z1_y - x2z1_y);
2980
2981 side1_dx = 0.0;//(double)(grid_pos_x2 - grid_pos_x1);
2982 side1_dz = (double)(grid_pos_z2 - grid_pos_z1);
2983 side1_dy = (double)(x2z2_y - x2z1_y);
2984 /* side 2
2985 _____
2986 \ |
2987 \ | side 1
2988 \| */
2989 }
2990
2991 float nx = side1_dy * side2_dz - side1_dz * side2_dy;
2992 float ny = side1_dx * side2_dy - side1_dy * side2_dx;
2993 float nz = side1_dz * side2_dx - side1_dx * side2_dz;
2994
2995 float mag = sqrt(nx * nx + ny * ny + nz * nz);
2996 if (fabsf(mag) < 1e-6f)
2997 {
2998 out->y = 0;
2999 out->x = 0;
3000 out->z = 65536;
3001 }
3002 else
3003 {
3004 float invmag = 1.0 / mag;
3005 out->x = invmag * nx * 65536.0;
3006 out->y = invmag * ny * 65536.0;
3007 out->z = invmag * nz * 65536.0;
3008 }
3009 }
3010 //----- (0046BE0A) --------------------------------------------------------
3011 void ODM_UpdateUserInputAndOther()
3012 {
3013 bool v0; // eax@5
3014 char pOut[32]; // [sp+8h] [bp-20h]@5
3015
3016 UpdateObjects();
3017 ODM_ProcessPartyActions();
3018 if ( pParty->vPosition.x < -22528
3019 || pParty->vPosition.x > 22528
3020 || pParty->vPosition.y < -22528
3021 || pParty->vPosition.y > 22528 )
3022 {
3023 strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
3024 v0 = pOutdoor->GetTravelDestination(pParty->vPosition.x, pParty->vPosition.y, pOut, 32);
3025 if ( !bUnderwater && (pParty->uFlags & (PARTY_FLAGS_1_STANDING_ON_WATER | PARTY_FLAGS_1_FALLING | 0x04) || pParty->uFlags & 0x0200 || pParty->bFlying) || !v0 )
3026 {
3027 if ( pParty->vPosition.x < -22528 )
3028 pParty->vPosition.x = -22528;
3029 if ( pParty->vPosition.x > 22528 )
3030 pParty->vPosition.x = 22528;
3031 if ( pParty->vPosition.y < -22528 )
3032 pParty->vPosition.y = -22528;
3033 if ( pParty->vPosition.y > 22528 )
3034 pParty->vPosition.y = 22528;
3035 }
3036 else
3037 {
3038 pAudioPlayer->StopChannels(-1, -1);
3039 TravelUI_Load();
3040 }
3041 }
3042 UpdateActors_ODM();
3043 check_event_triggers();
3044 }
3045 //----- (0041F54A) --------------------------------------------------------
3046 void OutdoorLocation::LoadActualSkyFrame()
3047 {
3048 if ( pTexture_RestUI_CurrentSkyFrame )
3049 pTexture_RestUI_CurrentSkyFrame->Release();
3050 if ( pTexture_RestUI_CurrentHourglassFrame )
3051 pTexture_RestUI_CurrentHourglassFrame->Release();
3052 pIcons_LOD->SyncLoadedFilesCount();
3053 sprintf(pTmpBuf.data(), "TERRA%03d", pParty->uCurrentMinute / 6 + 10 * pParty->uCurrentHour);
3054 pTexture_RestUI_CurrentSkyFrame = pIcons_LOD->LoadTexturePtr(pTmpBuf.data(), TEXTURE_16BIT_PALETTE);
3055 }
3056
3057
3058 //----- (004626BA) --------------------------------------------------------
3059 OutdoorLocation::OutdoorLocation()
3060 {
3061 subconstuctor();
3062 uLastSunlightUpdateMinute = 0;
3063
3064 uNumBModels = 0;
3065 pBModels = nullptr;
3066 }
3067
3068 //----- (004626CD) --------------------------------------------------------
3069 void OutdoorLocation::subconstuctor()
3070 {
3071 //OutdoorLocationTerrain::OutdoorLocationTerrain(&this->pTerrain);
3072 field_F0 = 0;
3073 field_F4 = 0x40000000u;
3074 //DLVHeader::DLVHeader(&v1->ddm);
3075 pSpawnPoints = 0;
3076 pBModels = 0;
3077 pCmap = 0;
3078 pFaceIDLIST = 0;
3079 pOMAP = 0;
3080 }
3081
3082 //----- (00481E55) --------------------------------------------------------
3083 void ODM_Project(unsigned int uNumVertices)
3084 {
3085 for ( uint i = 0; i < uNumVertices; i++ )
3086 {
3087 memcpy(&array_50AC10[i], &array_507D30[i], sizeof(array_50AC10[i]));
3088 array_50AC10[i].vWorldViewProjX = (double)pViewport->uScreenCenterX
3089 - ((double)pODMRenderParams->int_fov_rad * array_507D30[i]._rhw) * array_507D30[i].vWorldViewPosition.y;
3090 array_50AC10[i].vWorldViewProjY = (double)pViewport->uScreenCenterY
3091 - ((double)pODMRenderParams->int_fov_rad * array_507D30[i]._rhw) * array_507D30[i].vWorldViewPosition.z;
3092 }
3093 }
3094 //----- (00485F64) --------------------------------------------------------
3095 void ODMRenderParams::Initialize()
3096 {
3097 int v1; // eax@1
3098 int v2; // eax@2
3099 signed __int64 v3; // qtt@4
3100 int v4; // eax@4
3101
3102 this->uCameraFovInDegrees = 75;
3103 v1 = stru_5C6E00->uPiMask & 0xD5;
3104 if ( v1 >= (signed int)stru_5C6E00->uIntegerHalfPi )
3105 v2 = -stru_5C6E00->pTanTable[stru_5C6E00->uIntegerPi - v1];
3106 else
3107 v2 = stru_5C6E00->pTanTable[v1];
3108 LODWORD(v3) = (viewparams->uSomeZ - viewparams->uSomeX) << 31;
3109 HIDWORD(v3) = (viewparams->uSomeZ - viewparams->uSomeX) << 15 >> 16;
3110 v4 = (signed int)(v3 / v2) >> 16;
3111 this->int_fov_rad = v4;
3112 this->field_4C = 360000;
3113 this->int_fov_rad_inv = 65536 / v4;
3114 this->field_50 = 115;
3115 //sr_6BE060[1] = 1;
3116 //RotationToInts();
3117 }
3118 //----- (00473893) --------------------------------------------------------
3119 void ODM_ProcessPartyActions()
3120 {
3121 int v1; // edi@1
3122 int v2; // ebx@1
3123 int floor_level; // eax@14
3124 int v6; // esi@45
3125 ODMFace *face; // ecx@45
3126 //signed int v33; // eax@143
3127 int v34; // esi@143
3128 int v35; // esi@147
3129 int v36; // eax@155
3130 // signed int v37; // esi@159
3131 // signed int v38; // eax@159
3132 // signed int i; // esi@159
3133 int v40; // esi@162
3134 bool v42; // eax@180
3135 signed int v43; // ecx@184
3136 signed int v44; // edx@184
3137 int v45; // ecx@200
3138 BSPModel *pModel; // eax@203
3139 bool pModel_;
3140 ODMFace *pODMFace; // esi@203
3141 int v48; // eax@203
3142 int v54; // eax@215
3143 int v55; // eax@217
3144 unsigned int v66; // esi@263
3145 signed int v68; // ecx@263
3146 int v69; // eax@263
3147 // unsigned int v76; // edi@293
3148 bool v77; // edx@297
3149 bool v78; // ecx@303
3150 int v79; // ecx@314
3151 __int16 v80; // dx@317
3152 //int v81; // ebx@318
3153 //int v82; // ecx@318
3154 int pTerrainHeight; // eax@321
3155 // int v86; // [sp-20h] [bp-B4h]@246
3156 int v87; // [sp-20h] [bp-B4h]@248
3157 int v97; // [sp+Ch] [bp-88h]@180
3158 Vec3_int_ v98;
3159 bool not_high_fall; // [sp+1Ch] [bp-78h]@33
3160 int v102; // [sp+20h] [bp-74h]@1
3161 int trigger_id; // [sp+24h] [bp-70h]@1
3162 bool bFeatherFall; // [sp+28h] [bp-6Ch]@4
3163 int bonus;
3164 int on_ground; // [sp+2Ch] [bp-68h]@24
3165 bool bWaterWalk; // [sp+30h] [bp-64h]@1
3166 int ceiling_height; // [sp+3Ch] [bp-58h]@28
3167 int v110; // [sp+40h] [bp-54h]@180
3168 int v111; // [sp+44h] [bp-50h]@14
3169 bool hovering; // [sp+48h] [bp-4Ch]@1
3170 int v113; // [sp+4Ch] [bp-48h]@1
3171 bool party_running_flag; // [sp+50h] [bp-44h]@1
3172 int _walk_speed; // [sp+54h] [bp-40h]@48
3173 int pX; // [sp+58h] [bp-3Ch]@1
3174 int pY; // [sp+5Ch] [bp-38h]@1
3175 int v118; // [sp+60h] [bp-34h]@1
3176 int _angle_x; // [sp+68h] [bp-2Ch]@48
3177 unsigned int v122; // [sp+70h] [bp-24h]@180
3178 int pZ; // [sp+74h] [bp-20h]@1
3179 bool party_walking_flag; // [sp+78h] [bp-1Ch]@1
3180 int _angle_y; // [sp+7Ch] [bp-18h]@48
3181 int v128; // [sp+88h] [bp-Ch]@1
3182 int v129; // [sp+8Ch] [bp-8h]@92
3183
3184 v1 = 0;
3185 trigger_id = 0;
3186 v2 = 0;
3187 //*(float *)&v128 = 0.0;
3188 int fall_speed = pParty->uFallSpeed;
3189 v128 = 0;
3190 v129 = 0;
3191 pX = pParty->vPosition.x;
3192 pY = pParty->vPosition.y;
3193 pZ = pParty->vPosition.z;
3194 v113 = pParty->field_6F0;
3195 hovering = false;
3196 bool partyAtHighSlope = IsTerrainSlopeTooHigh(pParty->vPosition.x, pParty->vPosition.y);
3197 party_running_flag = false;
3198 party_walking_flag = false;
3199 v102 = 0;
3200 pModel_ = false;
3201 bWaterWalk = false;
3202
3203 if (!pParty->FeatherFallActive())//Проверка падение пера
3204 {
3205 bFeatherFall = false;
3206 for (int i = 0; i < 4; ++i)
3207 if (pParty->pPlayers[i].WearsItemAnyWhere(ITEM_ARTIFACT_LADYS_ESCORT)) // seems like flying boots
3208 {
3209 bFeatherFall = true;
3210 break;
3211 }
3212 }
3213 else
3214 bFeatherFall = true;
3215
3216 pParty->uFlags &= ~PARTY_FLAGS_1_STANDING_ON_WATER;
3217 if (pParty->WaterWalkActive())//Проверка хождения по воде
3218 {
3219 //LOBYTE(pParty->uFlags) &= 0x7Fu;
3220 bWaterWalk = true;
3221 *(short *)&stru_5E4C90_MapPersistVars._decor_events[20 * pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uOverlayID + 119] |= 1u;
3222 if (!(pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uFlags & 1) &&
3223 pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster - 1].sMana <= 0 )
3224 bWaterWalk = false;
3225 }
3226
3227 int bmodel_standing_on_pid;
3228 int is_on_water = false;
3229 floor_level = ODM_GetFloorLevel(pX, pY, pZ, pParty->uPartyHeight, &is_on_water, &bmodel_standing_on_pid, bWaterWalk);
3230 int is_not_on_bmodel = bmodel_standing_on_pid == 0;
3231
3232 v111 = floor_level;
3233 if ( bFeatherFall )
3234 pParty->uFallStartY = floor_level;
3235 else
3236 floor_level = pParty->uFallStartY;
3237
3238 if ( floor_level - pZ > 512 && !bFeatherFall && pZ <= v111 + 1 )//падение на 3D Model
3239 {
3240 if (pParty->uFlags & PARTY_FLAGS_1_LANDING)
3241 pParty->uFlags &= ~PARTY_FLAGS_1_LANDING;
3242 else for (int i = 0; i < 4; ++i) // receive falling damage
3243 {
3244 if ( !pParty->pPlayers[i].HasEnchantedItemEquipped(72) && !pParty->pPlayers[i].WearsItem(ITEM_ARTIFACT_HERMES_SANDALS, EQUIP_BOOTS) )
3245 {
3246 pParty->pPlayers[i].ReceiveDamage(
3247 (signed int)((pParty->uFallStartY - pZ) * (unsigned __int64)(pParty->pPlayers[i].GetMaxHealth() / 10)) / 256, DMGT_PHISYCAL);
3248 bonus = 20 - pParty->pPlayers[i].GetParameterBonus(pParty->pPlayers[i].GetActualEndurance());
3249 pParty->pPlayers[i].SetRecoveryTime((signed __int64)((double)bonus * flt_6BE3A4_debug_recmod1 * 2.133333333333333));
3250 }
3251 }
3252 }
3253
3254 ceiling_height = -1;
3255 if ( pParty->bFlying )
3256 ceiling_height = GetCeilingHeight(pX, pY, pZ + pParty->uPartyHeight, (int)&v102);//высота потолка
3257 //v107 = bmodel_standing_on_pid == 0;
3258 on_ground = v111 + 1;
3259 if ( pZ <= on_ground )//полёт: посадка
3260 {
3261 ceiling_height = -1;
3262 pParty->bFlying = false;
3263 }
3264 else
3265 hovering = true;
3266 not_high_fall = pZ - v111 <= 32;
3267
3268 if ( bWalkSound && pParty->walk_sound_timer)//timer update
3269 {
3270 if (pParty->walk_sound_timer >= pEventTimer->uTimeElapsed)
3271 pParty->walk_sound_timer -= pEventTimer->uTimeElapsed;
3272 else
3273 pParty->walk_sound_timer = 0;
3274 }
3275
3276 if (!bUnderwater && pParty->pPartyBuffs[PARTY_BUFF_FLY].uExpireTime <= 0)// конец действия полёта
3277 pParty->bFlying = false;
3278
3279 if (!hovering)//
3280 {
3281 if ( pParty->floor_face_pid != PID(OBJECT_BModel, bmodel_standing_on_pid) )
3282 {
3283 if (bmodel_standing_on_pid)
3284 {
3285 if ( (bmodel_standing_on_pid >> 6) < pOutdoor->uNumBModels )
3286 {
3287 face = pOutdoor->pBModels[bmodel_standing_on_pid >> 6].pFaces;
3288 v6 = bmodel_standing_on_pid & 0x3F;
3289 /*if ( *(char *)(v7->pFacePlane.vNormal.x + 308 * v6 + 31) & 4 )
3290 {
3291 pParty->field_6F4_packedid = PID(OBJECT_BModel,v108);
3292 v103 = *(short *)(v7->pFacePlane.vNormal.x + 308 * v6 + 292);
3293 }*/
3294 if ( face[v6].uAttributes & FACE_PRESSURE_PLATE )
3295 {
3296 pParty->floor_face_pid = PID(OBJECT_BModel, bmodel_standing_on_pid);
3297 trigger_id = face[v6].sCogTriggeredID; //
3298 }
3299 }
3300 }
3301 }
3302 pParty->floor_face_pid = PID(OBJECT_BModel, bmodel_standing_on_pid);
3303 }
3304
3305 _walk_speed = pParty->uWalkSpeed;
3306 _angle_y = pParty->sRotationY;
3307 _angle_x = pParty->sRotationX;
3308 //v126 = pEventTimer->dt_in_some_format;
3309 /*v119 = (Player **)((unsigned __int64)(pEventTimer->dt_in_some_format
3310 * (signed __int64)((signed int)(pParty->field_20_prolly_turn_speed
3311 * stru_5C6E00->uIntegerPi)
3312 / 180)) >> 16);*/
3313 __int64 dturn = (unsigned __int64)(pEventTimer->dt_in_some_format * (signed __int64)((signed int)(pParty->y_rotation_speed * stru_5C6E00->uIntegerPi) / 180)) >> 16;
3314 while (pPartyActionQueue->uNumActions)
3315 {
3316 switch (pPartyActionQueue->Next())
3317 {
3318 case PARTY_FlyUp://полёт вверх
3319 {
3320 if (!pParty->FlyActive() && !bUnderwater)
3321 break;
3322
3323 pParty->bFlying = false;
3324 if (bUnderwater ||
3325 pParty->pPartyBuffs[PARTY_BUFF_FLY].uFlags & 1 ||
3326 pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster - 1].sMana > 0 )
3327 {
3328 extern int max_flight_height;
3329 if ( pParty->vPosition.z < max_flight_height || hovering )
3330 {
3331 pZ += 30;
3332 v113 += 30;
3333 pParty->bFlying = true;
3334 if ( pZ > max_flight_height )
3335 {
3336 pZ = max_flight_height;
3337 v113 = max_flight_height;
3338 }
3339 v1 = 0;
3340 v2 = 0;
3341 fall_speed = 0;
3342 *(float *)&v128 = 0.0;
3343 if ( v102 && pZ < ceiling_height && (signed int)(pParty->uPartyHeight + pZ) >= ceiling_height )//столкновение с потолком
3344 {
3345 pParty->field_6E0 = 0;
3346 pParty->field_6E4 = 0;
3347 pPartyActionQueue->uNumActions = 0;
3348 pParty->uFlags |= PARTY_FLAGS_1_LANDING;
3349 pParty->vPosition.z = ceiling_height - pParty->uPartyHeight - 31;
3350 pParty->field_6F0 = pZ;
3351 pParty->bFlying = false;
3352 pZ = ceiling_height - pParty->uPartyHeight - 31;
3353 v113 = pParty->field_6F0;
3354 }
3355 pParty->uFallSpeed = 0;
3356 pModel_ = true;
3357 }
3358 }
3359 }
3360 break;
3361
3362 case PARTY_FlyDown://полёт вниз
3363 if (pParty->FlyActive() || bUnderwater)
3364 {
3365 pParty->bFlying = false;
3366 if ( bUnderwater
3367 || pParty->pPartyBuffs[PARTY_BUFF_FLY].uFlags & 1
3368 || pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster - 1].sMana > 0 )//*(int *)&pParty->pArtifactsFound[6972 * pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster + 10] > 0 )
3369 {
3370 pZ -= 30;
3371 v113 -= 30;
3372 pParty->uFallSpeed = 0;
3373 fall_speed = 0;
3374 pParty->bFlying = true;
3375 pModel_ = true;
3376 if ( pZ <= v111 )
3377 {
3378 pParty->bFlying = false;
3379 pPartyActionQueue->uNumActions = 0;
3380 }
3381 }
3382 }
3383 break;
3384
3385 case PARTY_TurnLeft:
3386 if (uTurnSpeed)
3387 _angle_y += uTurnSpeed; //descrete turn
3388 else
3389 _angle_y += dturn * fTurnSpeedMultiplier; // time-based smooth turn
3390
3391 _angle_y &= stru_5C6E00->uDoublePiMask;
3392 break;
3393
3394 case PARTY_TurnRight:
3395 if (uTurnSpeed)
3396 _angle_y -= uTurnSpeed;
3397 else
3398 _angle_y -= dturn * fTurnSpeedMultiplier;
3399
3400 _angle_y &= stru_5C6E00->uDoublePiMask;
3401 break;
3402
3403 case PARTY_FastTurnLeft:
3404 if (uTurnSpeed)
3405 _angle_y += uTurnSpeed;
3406 else
3407 _angle_y += 2.0f * fTurnSpeedMultiplier * (double)dturn;
3408
3409 _angle_y &= stru_5C6E00->uDoublePiMask;
3410 break;
3411
3412 case PARTY_FastTurnRight:
3413 if (!uTurnSpeed)
3414 _angle_y -= 2.0f * fTurnSpeedMultiplier * (double)dturn;
3415 else
3416 _angle_y -= uTurnSpeed;
3417
3418 _angle_y &= stru_5C6E00->uDoublePiMask;
3419 break;
3420
3421 case PARTY_StrafeLeft://хождение боком в влево
3422 {
3423 *(float *)&v128 = pParty->uWalkSpeed;
3424
3425 float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0);
3426 int dx = sin_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
3427 v2 -= 3 * dx / 4;
3428
3429 float cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
3430 int dy = cos_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
3431 v1 += 3 * dy / 4;
3432
3433 v128 = v1;
3434 party_walking_flag = true;
3435 }
3436 break;
3437
3438 case PARTY_StrafeRight://хождение боком в вправо
3439 {
3440 *(float *)&v128 = pParty->uWalkSpeed;
3441
3442 float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0);
3443 int dx = sin_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
3444 v2 += 3 * dx / 4;
3445
3446 float cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
3447 int dy = cos_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
3448 v1 -= 3 * dy / 4;
3449
3450 v128 = v1;
3451 party_walking_flag = true;
3452 }
3453 break;
3454
3455 case PARTY_WalkForward:// идти вперёд
3456 {
3457 *(float *)&v128 = _walk_speed;
3458
3459 float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0),
3460 cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
3461
3462 int dx = cos_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
3463 int dy = sin_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
3464
3465 if ( new_speed )
3466 {
3467 v2 += dx * 12;
3468 v1 += dy * 12;
3469 }
3470 else
3471 {
3472 v2 += dx;
3473 v1 += dy;
3474 }
3475
3476 v128 = v1;
3477 party_walking_flag = true;
3478 }
3479 break;
3480
3481 case PARTY_RunForward://бежать вперёд
3482 {
3483 *(float *)&v128 = _walk_speed;
3484
3485 float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0);
3486 float cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
3487
3488 int dx = cos_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
3489 int dy = sin_y * pParty->uWalkSpeed * fWalkSpeedMultiplier;
3490
3491 if (pParty->bFlying)//лететь вперёд
3492 {
3493 v2 += 4 * dx;
3494 v1 += 4 * dy;
3495
3496 v128 = v1;
3497 }
3498 else if (partyAtHighSlope && !bmodel_standing_on_pid)//сбегание со склона
3499 {
3500 v2 += dx;
3501 v1 += dy;
3502
3503 v128 = v1;
3504 party_walking_flag = true;
3505 }
3506 else
3507 {
3508 /*v2 += (unsigned __int64)(stru_5C6E00->Cos(_angle_y)
3509 * (signed __int64)(signed int)(2 * (unsigned __int64)(signed __int64)((double)_walk_speed * fWalkSpeedMultiplier))) >> 16;
3510 v1 += (unsigned __int64)((signed int)stru_5C6E00->Sin(_angle_y)
3511 * (signed __int64)(signed int)(2 * (unsigned __int64)(signed __int64)((double)_walk_speed * fWalkSpeedMultiplier))) >> 16;*/
3512
3513 v2 += 2 * dx;
3514 v1 += 2 * dy;
3515
3516 v128 = v1;
3517 party_running_flag = true;
3518 }
3519 }
3520 break;
3521
3522
3523 case PARTY_WalkBackward://идти назад
3524 {
3525 *(float *)&v128 = _walk_speed;
3526
3527 float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0),
3528 cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
3529
3530 int dx = cos_y * pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier;
3531 v2 -= dx;
3532
3533 int dy = sin_y * pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier;
3534 v1 -= dy;
3535
3536 v128 = v1;
3537 party_walking_flag = true;
3538 }
3539 break;
3540
3541
3542 case PARTY_RunBackward://бежать назад
3543 {
3544 float sin_y = sinf(2 * 3.141592653589 * _angle_y / 2048.0),
3545 cos_y = cosf(2 * 3.141592653589 * _angle_y / 2048.0);
3546
3547 int dx = cos_y * pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier;
3548 int dy = sin_y * pParty->uWalkSpeed * fBackwardWalkSpeedMultiplier;
3549
3550 if (pParty->bFlying)
3551 {
3552 v2 -= 4 * dx;
3553 v1 -= 4 * dy;
3554 v128 = v1;
3555 }
3556 else
3557 {
3558 v2 -= dx;
3559 v1 -= dy;
3560
3561 v128 = v1;
3562 party_walking_flag = true;
3563 }
3564 }
3565 break;
3566
3567 case PARTY_CenterView://смотреть прямо
3568 _angle_x = 0;
3569 break;
3570
3571 case PARTY_LookUp://смотреть вверх
3572 _angle_x += (signed __int64)(flt_6BE150_look_up_down_dangle * 25.0);
3573 if ( _angle_x > 128 )
3574 _angle_x = 128;
3575 if (uActiveCharacter)
3576 pPlayers[uActiveCharacter]->PlaySound(SPEECH_63, 0);
3577 break;
3578
3579 case PARTY_LookDown://смотреть вниз
3580 _angle_x += (signed __int64)(flt_6BE150_look_up_down_dangle * -25.0);
3581 if ( _angle_x < -128 )
3582 _angle_x = -128;
3583 if (uActiveCharacter)
3584 pPlayers[uActiveCharacter]->PlaySound(SPEECH_64, 0);
3585 break;
3586
3587 case PARTY_Jump://прыжок
3588 if ( (!partyAtHighSlope || bmodel_standing_on_pid) && !hovering && pParty->field_24 && !(pParty->uFlags & 4) && !(pParty->uFlags & 0x200) )
3589 {
3590 //v126 = pParty->field_24 << 6;
3591 hovering = true;
3592 fall_speed = (signed __int64)((double)(pParty->field_24 << 6) * 1.5 + (double)fall_speed);
3593 }
3594 break;
3595
3596 case PARTY_Land://приземление(клавиша Home)
3597 if (pParty->bFlying)
3598 {
3599 pParty->uFlags |= PARTY_FLAGS_1_LANDING;
3600 pParty->uFallSpeed = 0;
3601 }
3602 pParty->bFlying = false;
3603 pPartyActionQueue->uNumActions = 0;
3604 break;
3605
3606 default:
3607 assert(false);
3608
3609
3610 }
3611 }
3612
3613 pParty->sRotationY = _angle_y;
3614 pParty->sRotationX = _angle_x;
3615 //-------------------------------------------
3616 if ( pParty->bFlying )
3617 {
3618 v129 = fixpoint_mul(4, stru_5C6E00->Cos(GetTickCount()));
3619 pZ = v113 + v129;
3620 if ( pModel_ )
3621 pZ = v113;
3622 if (pParty->FlyActive())
3623 stru_5E4C90_MapPersistVars._decor_events[20 * pParty->pPartyBuffs[PARTY_BUFF_FLY].uOverlayID + 119] &= 0xFE;
3624 pParty->uFallStartY = pZ;
3625 }
3626 else if ( pZ < v111 )
3627 {
3628 if ( is_on_water && fall_speed )
3629 SpriteObject::sub_42F960_create_object(pX, pY, v111);
3630 fall_speed = 0;
3631 pZ = v111;
3632 pParty->uFallStartY = v111;
3633 v113 = pZ;
3634 if (pParty->FlyActive())
3635 stru_5E4C90_MapPersistVars._decor_events[20 * pParty->pPartyBuffs[PARTY_BUFF_FLY].uOverlayID + 119] |= 1;
3636 }
3637 else
3638 {
3639 v113 = pZ;
3640 if (pParty->FlyActive())
3641 stru_5E4C90_MapPersistVars._decor_events[20 * pParty->pPartyBuffs[PARTY_BUFF_FLY].uOverlayID + 119] |= 1;
3642 }
3643 //------------------------------------------
3644 if (hovering && !pParty->bFlying)//расчёт скорости падения
3645 {
3646 //v33 = -(pEventTimer->uTimeElapsed * GetGravityStrength());
3647 v34 = fall_speed + (-(pEventTimer->uTimeElapsed * GetGravityStrength()) << 1);
3648 fall_speed += (-(pEventTimer->uTimeElapsed * GetGravityStrength()) << 1 ); //y(t) = 2*gt
3649 }
3650 else if (!partyAtHighSlope)
3651 v34 = fall_speed;
3652 else if (!hovering)
3653 {
3654 if ( !bmodel_standing_on_pid )
3655 {
3656 // rolling down the hill
3657 // how it's done: you get a little bit pushed in the air along terrain normal, getting in the air
3658 // and falling to the gravity, gradually sliding downwards. nice trick
3659 pZ = v111;
3660 ODM_GetTerrainNormalAt(pX, pY, &v98);
3661 v35 = fall_speed + (8 * -(pEventTimer->uTimeElapsed * GetGravityStrength()));
3662 v129 = abs(v2 * v98.x + v1 * v98.y + v35 * v98.z) >> 16;
3663 v2 += fixpoint_mul(v129, v98.x);
3664 v1 += fixpoint_mul(v129, v98.y);
3665 v34 = v35 + fixpoint_mul(v129, v98.z);
3666 v128 = v1;
3667 fall_speed = v34;
3668 }
3669 }
3670 else
3671 v34 = fall_speed;
3672
3673 if ( hovering )//блок для крика падения
3674 {
3675 if ( !bUnderwater && v34 <= 0)
3676 {
3677 if ( v34 < -500 && !pParty->bFlying && pParty->vPosition.z - v111 > 1000 && !pParty->FeatherFallActive())
3678 { // falling scream
3679 for (int i = 0; i < 4; ++i)
3680 {
3681 if (!pParty->pPlayers[i].HasEnchantedItemEquipped(72)
3682 && !pParty->pPlayers[i].WearsItem(ITEM_ARTIFACT_HERMES_SANDALS, EQUIP_BOOTS)
3683 && pParty->pPlayers[i].CanAct())
3684 pParty->pPlayers[i].PlaySound(SPEECH_Falling_scream, 0);//крик падения
3685 }
3686 }
3687 }
3688 }
3689 else
3690 pParty->uFallStartY = pZ;
3691
3692 if ( v2 * v2 + v1 * v1 < 400 && !partyAtHighSlope )
3693 {
3694 *(float *)&v128 = 0.0;
3695 v2 = 0;
3696 }
3697 //--(столкновения)-------------------------------------------------------------------
3698 stru_721530.field_84 = -1;
3699 stru_721530.field_70 = 0;
3700 stru_721530.prolly_normal_d = pParty->field_14_radius;
3701 stru_721530.field_8_radius = pParty->field_14_radius / 2;
3702 stru_721530.field_0 = 1;
3703 stru_721530.height = pParty->uPartyHeight - 32;
3704 for ( uint i = 0; i < 100; i++ )
3705 {
3706 stru_721530.position.x = pX;
3707 stru_721530.position.y = pY;
3708 stru_721530.position.z = stru_721530.height + pZ + 1;
3709
3710 stru_721530.normal.x = pX;
3711 stru_721530.normal.y = pY;
3712 stru_721530.normal.z = stru_721530.prolly_normal_d + pZ + 1;
3713
3714 stru_721530.velocity.x = v2;
3715 stru_721530.velocity.y = v128;
3716 stru_721530.velocity.z = fall_speed;
3717
3718 stru_721530.uSectorID = 0;
3719 v36 = 0;
3720 if ( pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT )
3721 v36 = 13312;
3722 if ( stru_721530._47050A(v36) )
3723 break;
3724 _46E889_collide_against_bmodels(1);
3725 //v37 = WorldPosToGridCellZ(pParty->vPosition.y);
3726 //v38 = WorldPosToGridCellX(pParty->vPosition.x);
3727 _46E26D_collide_against_sprites(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y));
3728 _46ED8A_collide_against_sprite_objects(4);
3729 for ( uint actor_id = 0; actor_id < (signed int)uNumActors; ++actor_id )
3730 Actor::_46DF1A_collide_against_actor(actor_id, 0);
3731 if ( stru_721530.field_7C >= stru_721530.field_6C )
3732 {
3733 _angle_x = stru_721530.normal2.x;
3734 _angle_y = stru_721530.normal2.y;
3735 v40 = stru_721530.normal2.z - stru_721530.prolly_normal_d - 1;
3736 }
3737 else
3738 {
3739 _angle_x = pX + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.x);
3740 _angle_y = pY + fixpoint_mul(stru_721530.field_7C, stru_721530.direction.y);
3741 //pModel = (BSPModel *)fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z);
3742 v40 = fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z) + pZ;
3743 }
3744 v122 = v40;
3745 ODM_GetFloorLevel(_angle_x, _angle_y, v40, pParty->uPartyHeight, &is_on_water, &bmodel_standing_on_pid, 0);
3746 v129 = ODM_GetFloorLevel(_angle_x, pY, v40, pParty->uPartyHeight, &is_on_water, &v97, 0);
3747 int v119 = ODM_GetFloorLevel(pX, _angle_y, v40, pParty->uPartyHeight, &is_on_water, &v110, 0);
3748 bool v42_ = (BSPModel *)IsTerrainSlopeTooHigh(_angle_x, pY);
3749 v42 = IsTerrainSlopeTooHigh(pX, _angle_y);
3750 is_not_on_bmodel = false;
3751 //v118 = v42;
3752 if ( !v97 && !v110 && !bmodel_standing_on_pid )
3753 is_not_on_bmodel = true;
3754 v43 = 1;
3755 v44 = 1;
3756 if ( bUnderwater || !is_not_on_bmodel )
3757 {
3758 pX = _angle_x;
3759 if ( v43 )
3760 pY = _angle_y;
3761 }
3762 else
3763 {
3764 if ( v42_ && v129 > pZ )
3765 v44 = 0;
3766 if ( v42 && v119 > pZ )
3767 v43 = 0;
3768 if ( v44 )
3769 {
3770 pX = _angle_x;
3771 if ( v43 )
3772 pY = _angle_y;
3773 }
3774 else if ( v43 )
3775 pY = _angle_y;
3776 else
3777 {
3778 int new_ = ODM_GetFloorLevel(_angle_x, _angle_y, v40, pParty->uPartyHeight, &is_on_water, &bmodel_standing_on_pid, 0);
3779 if ( IsTerrainSlopeTooHigh(_angle_x, _angle_y) && new_ <= pZ )
3780 {
3781 v43 = 1;
3782 pX = _angle_x;
3783 if ( v43 )
3784 pY = _angle_y;
3785 }
3786 }
3787 }
3788 if ( stru_721530.field_7C >= stru_721530.field_6C )
3789 {
3790 if ( !is_not_on_bmodel )
3791 {
3792 pX = stru_721530.normal2.x;
3793 pY = stru_721530.normal2.y;
3794 }
3795 pZ = stru_721530.normal2.z - stru_721530.prolly_normal_d - 1;
3796 break;
3797 }
3798 stru_721530.field_70 += stru_721530.field_7C;
3799 pX = _angle_x;
3800 pY = _angle_y;
3801 v45 = stru_721530.uFaceID;
3802 pZ = v40;
3803
3804 if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Actor)
3805 {
3806 if (pParty->Invisible())
3807 pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
3808 viewparams->bRedrawGameUI = true;
3809 }
3810
3811 if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_Decoration)
3812 {
3813 v129 = stru_5C6E00->Atan2(_angle_x - pLevelDecorations[(signed int)stru_721530.uFaceID >> 3].vPosition.x,
3814 _angle_y - pLevelDecorations[(signed int)stru_721530.uFaceID >> 3].vPosition.y);
3815 v2 = fixpoint_mul(stru_5C6E00->Cos(v129), integer_sqrt(v2 * v2 + v128 * v128));
3816 v122 = fixpoint_mul(stru_5C6E00->Sin(v129), integer_sqrt(v2 * v2 + v128 * v128));
3817 v128 = fixpoint_mul(stru_5C6E00->Sin(v129), integer_sqrt(v2 * v2 + v128 * v128));
3818 }
3819
3820 if ( PID_TYPE(stru_721530.uFaceID) == OBJECT_BModel)
3821 {
3822 pParty->bFlying = false;
3823 pModel = &pOutdoor->pBModels[(signed int)stru_721530.uFaceID >> 9];
3824 pODMFace = &pModel->pFaces[((signed int)stru_721530.uFaceID >> 3) & 0x3F];
3825 v48 = pODMFace->pBoundingBox.z2 - pODMFace->pBoundingBox.z1;
3826 v129 = v48 <= 32;
3827 v119 = pODMFace->pFacePlane.vNormal.z < 46378;
3828 if ( bUnderwater == 1 )
3829 v119 = 0;
3830 if ( pODMFace->uPolygonType == POLYGON_Floor )
3831 {
3832 if ( fall_speed < 0 )
3833 fall_speed = 0;
3834 pZ = pModel->pVertices.pVertices[pODMFace->pVertexIDs[0]].z + 1;
3835 if ( v2 * v2 + v128 * v128 < 400 )
3836 {
3837 v2 = 0;
3838 *(float *)&v128 = 0.0;
3839 }
3840 if ( pParty->floor_face_pid != v45 && pODMFace->Pressure_Plate() )
3841 {
3842 pParty->floor_face_pid = v45;
3843 trigger_id = pODMFace->sCogTriggeredID;
3844 }
3845 }
3846 if ( !v129 && (pODMFace->uPolygonType != POLYGON_InBetweenFloorAndWall || v119) )// упёрся в столб
3847 {
3848 v118 = abs(v128 * pODMFace->pFacePlane.vNormal.y + fall_speed * pODMFace->pFacePlane.vNormal.z
3849 + v2 * pODMFace->pFacePlane.vNormal.x) >> 16;
3850 if ((stru_721530.speed >> 3) > v118 )
3851 v118 = stru_721530.speed >> 3;
3852 v2 += fixpoint_mul(v118, pODMFace->pFacePlane.vNormal.x);
3853 v128 += fixpoint_mul(v118, pODMFace->pFacePlane.vNormal.y);
3854 v54 = 0;
3855 if ( !v119 )
3856 v54 = fixpoint_mul(v118, pODMFace->pFacePlane.vNormal.z);
3857 pParty->uFallSpeed += v54;
3858 v55 = stru_721530.prolly_normal_d - ((signed int)(pODMFace->pFacePlane.dist + v122 * pODMFace->pFacePlane.vNormal.z
3859 + _angle_y * pODMFace->pFacePlane.vNormal.y + _angle_x * pODMFace->pFacePlane.vNormal.x) >> 16);
3860 if ( v55 > 0 )
3861 {
3862 pX = _angle_x + fixpoint_mul(pODMFace->pFacePlane.vNormal.x, v55);
3863 pY = _angle_y + fixpoint_mul(pODMFace->pFacePlane.vNormal.y, v55);
3864 if ( !v119 )
3865 pZ = v122 + fixpoint_mul(pODMFace->pFacePlane.vNormal.z, v55);
3866 }
3867 if ( pParty->floor_face_pid != stru_721530.uFaceID && pODMFace->Pressure_Plate() )
3868 {
3869 pParty->floor_face_pid = stru_721530.uFaceID;
3870 trigger_id = pODMFace->sCogTriggeredID; //
3871 }
3872 }
3873 if ( pODMFace->uPolygonType == POLYGON_InBetweenFloorAndWall )
3874 {
3875 v118 = abs(v128 * pODMFace->pFacePlane.vNormal.y
3876 + fall_speed * pODMFace->pFacePlane.vNormal.z + v2 * pODMFace->pFacePlane.vNormal.x) >> 16;
3877 if ((stru_721530.speed >> 3) > v118 )
3878 v118 = stru_721530.speed >> 3;
3879 v2 += fixpoint_mul(v118, pODMFace->pFacePlane.vNormal.x);
3880 v128 += fixpoint_mul(v118, pODMFace->pFacePlane.vNormal.y);
3881 fall_speed += fixpoint_mul(v118, pODMFace->pFacePlane.vNormal.z);
3882 if ( v2 * v2 + v128 * v128 >= 400 )
3883 {
3884 if ( pParty->floor_face_pid != stru_721530.uFaceID && pODMFace->Pressure_Plate() )
3885 {
3886 pParty->floor_face_pid = stru_721530.uFaceID;
3887 trigger_id = pODMFace->sCogTriggeredID; //
3888 }
3889 }
3890 else
3891 {
3892 v2 = 0;
3893 fall_speed = 0;
3894 *(float *)&v128 = 0.0;
3895 }
3896 }
3897 }
3898 v2 = fixpoint_mul(58500, v2);
3899 v128 = fixpoint_mul(58500, v128);
3900 v122 = fixpoint_mul(58500, v122);
3901 fall_speed = fixpoint_mul(58500, fall_speed);
3902 }
3903
3904 //Воспроизведение звуков ходьбы/бега------------------------
3905 uint pX_ = abs(pParty->vPosition.x - pX);
3906 uint pY_ = abs(pParty->vPosition.y - pY);
3907 uint pZ_ = abs(pParty->vPosition.z - pZ);
3908 if ( bWalkSound && pParty->walk_sound_timer <= 0 )
3909 {
3910 pAudioPlayer->_4AA258(804);//stop sound
3911 if ( party_running_flag && (!hovering || not_high_fall) )
3912 {
3913 if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) >= 16 )
3914 {
3915 if ( !is_not_on_bmodel && pOutdoor->pBModels[pParty->floor_face_pid >> 9].pFaces[(pParty->floor_face_pid >> 3) & 0x3F].Visible() )
3916 pAudioPlayer->PlaySound(SOUND_RunAlong3DModel, 804, 1, -1, 0, 0, 0, 0);//бег на 3D Modelи
3917 else
3918 {
3919 v87 = pOutdoor->GetSoundIdByPosition(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y) - 1, 1);
3920 pAudioPlayer->PlaySound((SoundID)v87, 804, 1, -1, 0, 0, 0, 0);//бег по земле 56
3921 }
3922 pParty->walk_sound_timer = 96;//таймер для бега
3923 }
3924 }
3925 else if( party_walking_flag && (!hovering || not_high_fall) )
3926 {
3927 if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) >= 8 )
3928 {
3929 if ( !is_not_on_bmodel && pOutdoor->pBModels[pParty->floor_face_pid >> 9].pFaces[(pParty->floor_face_pid >> 3) & 0x3F].Visible() )
3930 pAudioPlayer->PlaySound(SOUND_WalkAlong3DModel, 804, 1, -1, 0, 0, 0, 0);// хождение на 3D Modelи
3931 else
3932 {
3933 v87 = pOutdoor->GetSoundIdByPosition(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y) - 1, 0);
3934 pAudioPlayer->PlaySound((SoundID)v87, 804, 1, -1, 0, 0, 0, 0);// хождение по земле
3935 }
3936 pParty->walk_sound_timer = 144;//таймер для ходьбы
3937 }
3938 }
3939 }
3940 if ( integer_sqrt(pX_ * pX_ + pY_ * pY_ + pZ_ * pZ_) < 8 )//отключить звук ходьбы при остановке
3941 pAudioPlayer->_4AA258(804);
3942 //------------------------------------------------------------------------
3943 if ( !hovering || !not_high_fall )// или не высокое падение
3944 pParty->uFlags &= ~PARTY_FLAGS_1_FALLING;
3945 else
3946 pParty->uFlags |= PARTY_FLAGS_1_FALLING;
3947 int pMap_X = WorldPosToGridCellX(pParty->vPosition.x);
3948 int pMap_Y = WorldPosToGridCellZ(pParty->vPosition.y) - 1;
3949 unsigned int v114_a = WorldPosToGridCellX(pX);
3950 v66 = WorldPosToGridCellZ(pY) - 1;
3951 unsigned int v122_a = (~(unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(pMap_X, pMap_Y) / 2) & 1;
3952 v122 = (~(unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(v114_a, pMap_Y) / 2) & 1;
3953 v69 = (~(unsigned int)pOutdoor->ActuallyGetSomeOtherTileInfo(pMap_X, v66) / 2) & 1;
3954
3955 //-(обновление координат группы)---------------------------------------
3956 v68 = 0;
3957 if ( v114_a == pMap_X && v66 == pMap_Y && v122 && v69 )
3958 v68 = 1;
3959 if ( !is_not_on_bmodel ) // на bmodel,и
3960 v68 = 1;
3961 if ( v68 )
3962 {
3963 pParty->vPosition.x = pX;
3964 pParty->vPosition.y = pY;
3965 pParty->vPosition.z = pZ;
3966 pParty->field_6F0 = v113;
3967 pParty->uFallSpeed = fall_speed;
3968 if ( pZ > 8160 ) //ограничение высоты
3969 {
3970 pZ = 8160;
3971 pParty->uFallStartY = 8160;
3972 pParty->vPosition.z = 8160;
3973 }
3974
3975 if ( !trigger_id //падение на землю
3976 || (EventProcessor(trigger_id, 0, 1),
3977 pParty->vPosition.x == pX)
3978 && pParty->vPosition.y == pY
3979 && pParty->vPosition.z == pZ )
3980 {
3981 if ( pParty->vPosition.z < v111 )
3982 {
3983 pParty->uFallSpeed = 0;
3984 //v73 = v105;
3985 pParty->vPosition.z = on_ground;
3986 if ( pParty->uFallStartY - pZ > 512 && !bFeatherFall && pZ <= on_ground && !bUnderwater )//Fall to the ground(падение на землю с высоты)
3987 {
3988 if ( pParty->uFlags & PARTY_FLAGS_1_LANDING )
3989 pParty->uFlags &= ~PARTY_FLAGS_1_LANDING;
3990 else
3991 {
3992 for ( uint i = 1; i <= 4; ++i )
3993 {
3994 pPlayers[i]->ReceiveDamage((signed int)((pParty->uFallStartY - pZ) * (unsigned __int64)(signed __int64)((double)pPlayers[i]->GetMaxHealth() * 0.1)) / 256,
3995 DMGT_PHISYCAL);
3996 v110 = 20 - pPlayers[i]->GetParameterBonus(pPlayers[i]->GetActualEndurance());
3997 pPlayers[i]->SetRecoveryTime((signed __int64)((double)v110 * flt_6BE3A4_debug_recmod1 * 2.133333333333333));
3998 }
3999 //v73 = pParty->vPosition.z;
4000 }
4001 }
4002 pParty->uFallStartY = pZ;
4003 }
4004 if ( v102 && pParty->vPosition.z < ceiling_height )
4005 {
4006 if ( (signed int)(pParty->uPartyHeight + pParty->vPosition.z) >= ceiling_height )
4007 {
4008 pParty->vPosition.z = ceiling_height - pParty->uPartyHeight - 1;
4009 pParty->field_6F0 = ceiling_height - pParty->uPartyHeight - 1;
4010 }
4011 }
4012 pParty->uFlags &= ~0x204;
4013 }
4014 return;
4015 }
4016 //-----------------------------------------------------------------
4017 //v76 = pParty->bFlying;
4018 if ( pParty->bFlying || !not_high_fall || bWaterWalk || !v122_a )// полёт или высокое падение или хождение по воде или
4019 v77 = 1;
4020 else
4021 v77 = v122 != 0;
4022 bool party_drowning_flag = false;
4023 if ( !pParty->bFlying && not_high_fall && !bWaterWalk ) //не полёт и не высокое падение и не хождение по воде
4024 {
4025 if ( v122_a )
4026 v78 = v69 != 0;
4027 else
4028 {
4029 party_drowning_flag = true;//утопление
4030 v78 = true;
4031 }
4032 }
4033 else
4034 v78 = true;
4035
4036 if ( v77 )
4037 pParty->vPosition.x = pX;
4038 if ( v78 )
4039 pParty->vPosition.y = pY;
4040
4041 if ( v78 || v77)
4042 {
4043 if ( bWaterWalk )
4044 {
4045 pParty->uFlags &= ~PARTY_FLAGS_1_STANDING_ON_WATER;
4046 //v79 = 20 * pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uOverlayID + 6180178;
4047 //*(short *)&stru_5E4C90._decor_events[20 * pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uOverlayID + 119] |= 1u;
4048 v79 = (int)&stru_5E4C90_MapPersistVars._decor_events[20 * pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uOverlayID + 119];
4049 *(short *)v79 |= 1;
4050 if ( !v122 || !v69 )
4051 {
4052 if ( !pParty->bFlying )
4053 {
4054 v80 = *(short *)v79;
4055 pParty->uFlags |= PARTY_FLAGS_1_STANDING_ON_WATER;
4056 *(short *)v79 = v80 & 0xFFFE;
4057 }
4058 }
4059 }
4060 }
4061 else if ( bWalkSound && pParty->walk_sound_timer <= 0 )
4062 {
4063 pAudioPlayer->_4AA258(804);
4064 pParty->walk_sound_timer = 64;
4065 }
4066
4067 //v81 = pZ;
4068 //v82 = pZ;
4069 pParty->vPosition.z = pZ;
4070 if ( pZ > 8160 )//опять ограничение высоты
4071 {
4072 //v82 = 8160;
4073 pParty->uFallStartY = 8160;
4074 pParty->vPosition.z = 8160;
4075 }
4076 LOWORD(pParty->uFlags) &= 0xFDFBu;
4077 pParty->uFallSpeed = fall_speed;
4078 pParty->field_6F0 = v113;
4079 if ( party_drowning_flag )//группа тонет
4080 {
4081 pTerrainHeight = GetTerrainHeightsAroundParty2(pParty->vPosition.x, pParty->vPosition.y, &v110, 1);
4082 if ( pParty->vPosition.z <= pTerrainHeight + 1 )//положение группы всегда +1
4083 pParty->uFlags |= PARTY_FLAGS_1_WATER_DAMAGE;
4084 }
4085
4086 if ( !trigger_id//падение на воду
4087 || (EventProcessor(trigger_id, 0, 1),
4088 pParty->vPosition.x == pX)
4089 && pParty->vPosition.y == pY
4090 && pParty->vPosition.z == pZ )
4091 {
4092 if ( pParty->vPosition.z < v111 )
4093 {
4094 //v82 = on_ground;
4095 pParty->uFallSpeed = 0;
4096 pParty->vPosition.z = on_ground;
4097 if ( pParty->uFallStartY - pZ > 512 && !bFeatherFall && pZ <= on_ground && !bUnderwater )//Fall to the water(падение на воду с высоты)
4098 {
4099 if ( pParty->uFlags & PARTY_FLAGS_1_LANDING )
4100 pParty->uFlags &= ~PARTY_FLAGS_1_LANDING;
4101 else
4102 {
4103 for ( uint i = 1; i <= 4; ++i )
4104 {
4105 v110 = pPlayers[i]->GetMaxHealth();
4106 pPlayers[i]->ReceiveDamage((signed int)((pParty->uFallStartY - pZ) * (unsigned __int64)(signed __int64)((double)v110 * 0.1)) / 256,
4107 DMGT_PHISYCAL);
4108 v110 = 20 - pPlayers[i]->GetParameterBonus(pPlayers[i]->GetActualEndurance());
4109 pPlayers[i]->SetRecoveryTime((signed __int64)((double)v110 * flt_6BE3A4_debug_recmod1 * 2.133333333333333));
4110 }
4111 //v82 = pParty->vPosition.z;
4112 }
4113 }
4114 pParty->uFallStartY = pZ;
4115 }
4116 if ( v102 && pParty->vPosition.z < ceiling_height && (signed int)(pParty->uPartyHeight + pParty->vPosition.z) >= ceiling_height )
4117 {
4118 pParty->vPosition.z = pParty->vPosition.z + pParty->uPartyHeight - ceiling_height + 1;
4119 pParty->field_6F0 = pParty->vPosition.z + pParty->uPartyHeight - ceiling_height + 1;
4120 }
4121 }
4122 }
4123
4124 //----- (0046D8E3) --------------------------------------------------------
4125 int GetCeilingHeight(int Party_X, signed int Party_Y, int Party_ZHeight, int pFaceID)
4126 {
4127 signed int v13; // eax@25
4128 int v14; // edx@27
4129 int v16; // ST18_4@29
4130 signed int v17; // edx@29
4131 signed __int64 v18; // qtt@29
4132 int v19; // eax@35
4133 signed int v20; // ecx@37
4134 signed int v22; // ebx@42
4135 // int v24; // edx@44
4136 // int v25; // eax@44
4137 int v27; // [sp+10h] [bp-34h]@21
4138 bool v34; // [sp+30h] [bp-14h]@21
4139 bool v35; // [sp+34h] [bp-10h]@23
4140 signed int v37; // [sp+38h] [bp-Ch]@21
4141 signed int v38; // [sp+38h] [bp-Ch]@42
4142 signed int v39; // [sp+3Ch] [bp-8h]@1
4143
4144 dword_720ED0[0] = -1;
4145 dword_720E80[0] = -1;
4146 v39 = 1;
4147 ceiling_height_level[0] = 10000;//нет потолка
4148 for ( uint i = 0; i < (signed int)pOutdoor->uNumBModels; ++i )
4149 {
4150 if ( Party_X <= pOutdoor->pBModels[i].sMaxX && Party_X >= pOutdoor->pBModels[i].sMinX
4151 && Party_Y <= pOutdoor->pBModels[i].sMaxY && Party_Y >= pOutdoor->pBModels[i].sMinY )
4152 {
4153 for ( uint j = 0; j < pOutdoor->pBModels[i].uNumFaces; ++j )
4154 {
4155 if ( (pOutdoor->pBModels[i].pFaces[j].uPolygonType == POLYGON_Ceiling
4156 || pOutdoor->pBModels[i].pFaces[j].uPolygonType == POLYGON_InBetweenCeilingAndWall)
4157 && !pOutdoor->pBModels[i].pFaces[j].Ethereal()
4158 && Party_X <= pOutdoor->pBModels[i].pFaces[j].pBoundingBox.x2 && Party_X >= pOutdoor->pBModels[i].pFaces[j].pBoundingBox.x1
4159 && Party_Y <= pOutdoor->pBModels[i].pFaces[j].pBoundingBox.y2 && Party_Y >= pOutdoor->pBModels[i].pFaces[j].pBoundingBox.y1 )
4160 {
4161 for ( uint v = 0; v < pOutdoor->pBModels[i].pFaces[j].uNumVertices; v++ )
4162 {
4163 word_720DB0_xs[2 * v] = pOutdoor->pBModels[i].pFaces[j].pXInterceptDisplacements[v] + LOWORD(pOutdoor->pBModels[i].pVertices.pVertices[pOutdoor->pBModels[i].pFaces[j].pVertexIDs[v]].x);
4164 word_720CE0_ys[2 * v] = pOutdoor->pBModels[i].pFaces[j].pXInterceptDisplacements[v] + LOWORD(pOutdoor->pBModels[i].pVertices.pVertices[pOutdoor->pBModels[i].pFaces[j].pVertexIDs[v]].y);
4165 word_720DB0_xs[2 * v + 1] = pOutdoor->pBModels[i].pFaces[j].pXInterceptDisplacements[v] + LOWORD(pOutdoor->pBModels[i].pVertices.pVertices[pOutdoor->pBModels[i].pFaces[j].pVertexIDs[v + 1]].x);
4166 word_720CE0_ys[2 * v + 1] = pOutdoor->pBModels[i].pFaces[j].pXInterceptDisplacements[v] + LOWORD(pOutdoor->pBModels[i].pVertices.pVertices[pOutdoor->pBModels[i].pFaces[j].pVertexIDs[v + 1]].y);
4167 }
4168 v27 = 2 * pOutdoor->pBModels[i].pFaces[j].uNumVertices;
4169 word_720DB0_xs[2 * pOutdoor->pBModels[i].pFaces[j].uNumVertices] = word_720DB0_xs[0];
4170 word_720CE0_ys[2 * pOutdoor->pBModels[i].pFaces[j].uNumVertices] = word_720CE0_ys[0];
4171 v34 = word_720CE0_ys[0] >= Party_Y;
4172 v37 = 0;
4173 for ( uint v = 0; v < v27; ++v )
4174 {
4175 if ( v37 >= 2 )
4176 break;
4177 v35 = word_720CE0_ys[v + 1] >= Party_Y;
4178 if ( v34 != v35 )
4179 {
4180 v13 = word_720DB0_xs[v + 1] >= Party_X ? 0 : 2;
4181 v14 = v13 | (word_720DB0_xs[v] < Party_X);
4182 if ( v14 != 3 )
4183 {
4184 if ( !v14 || ( v16 = word_720CE0_ys[v + 1] - word_720CE0_ys[v],
4185 v17 = Party_Y - word_720CE0_ys[v],
4186 LODWORD(v18) = v17 << 16,
4187 HIDWORD(v18) = v17 >> 16,
4188 (signed int)(((unsigned __int64)(((signed int)word_720DB0_xs[v + 1]
4189 - (signed int)word_720DB0_xs[v]) * v18 / v16) >> 16) + word_720DB0_xs[v]) >= Party_X) )
4190 ++v37;
4191 }
4192 }
4193 v34 = v35;
4194 }
4195 if ( v37 == 1 )
4196 {
4197 if ( v39 >= 20 )
4198 break;
4199 if ( pOutdoor->pBModels[i].pFaces[j].uPolygonType == POLYGON_Ceiling )
4200 v19 = pOutdoor->pBModels[i].pVertices.pVertices[pOutdoor->pBModels[i].pFaces[j].pVertexIDs[0]].z;
4201 else
4202 v19 = fixpoint_mul(pOutdoor->pBModels[i].pFaces[j].zCalc1, Party_X) + fixpoint_mul(pOutdoor->pBModels[i].pFaces[j].zCalc2, Party_Y)
4203 + HIWORD(pOutdoor->pBModels[i].pFaces[j].zCalc3);
4204 v20 = v39++;
4205 ceiling_height_level[v20] = v19;
4206 dword_720ED0[v20] = i;
4207 dword_720E80[v20] = j;
4208 }
4209 }
4210 }
4211 }
4212 }
4213 if ( !v39 )
4214 {
4215 pFaceID = 0;
4216 return ceiling_height_level[0];
4217 }
4218 v22 = 0;
4219 for ( v38 = 0; v38 < v39; ++v38 )
4220 {
4221 if ( ceiling_height_level[v38] == ceiling_height_level[0] )
4222 v22 = v38;
4223 else if ( ceiling_height_level[v38] < ceiling_height_level[0] && ceiling_height_level[0] > Party_ZHeight + 15 )
4224 v22 = v38;
4225 else if ( ceiling_height_level[v38] > ceiling_height_level[0] && ceiling_height_level[v38] <= Party_ZHeight + 15 )
4226 v22 = v38;
4227 }
4228 if ( v22 )
4229 {
4230 *(int *)pFaceID = dword_720E80[v22] | (dword_720ED0[v22] << 6);
4231 return ceiling_height_level[v22];//если есть преграда
4232 }
4233 pFaceID = 0;
4234 return ceiling_height_level[v22];// нет никакой преграды
4235 }
4236
4237
4238 //----- (00464839) --------------------------------------------------------
4239 char Is_out15odm_underwater()
4240 {
4241 return _stricmp(pCurrentMapName, "out15.odm") == 0;
4242 }
4243
4244 //----- (00464851) --------------------------------------------------------
4245 void SetUnderwaterFog()
4246 {
4247 day_fogrange_1 = 50;
4248 day_fogrange_2 = 5000;
4249 }
4250
4251 //----- (00487DA9) --------------------------------------------------------
4252 void sub_487DA9()
4253 {
4254 for (int i = 0; i < 20000; ++i)
4255 array_77EC08[i].field_108 = 0;
4256 }
4257
4258 //----- (004706C6) --------------------------------------------------------
4259 void UpdateActors_ODM()
4260 {
4261 int v3; // ebx@6
4262 int v5; // eax@10
4263 //int v6; // ecx@10
4264 signed int v8; // ebx@17
4265 // unsigned __int8 v10; // sf@17
4266 // unsigned __int16 v11; // ax@21
4267 __int16 v20; // ax@42
4268 int v25; // eax@45
4269 signed int v26; // ecx@50
4270 int v28; // eax@54
4271 signed int v29; // ebx@57
4272 signed int v30; // eax@57
4273 int v31; // edi@57
4274 signed int i; // ebx@57
4275 unsigned int v33; // ecx@58
4276 int v35; // edi@64
4277 int v36; // eax@64
4278 unsigned int v39; // edi@71
4279 ODMFace *face; // edi@75
4280 int v46; // ecx@82
4281 signed int v47; // ebx@85
4282 int v48; // edi@85
4283 // int v55; // eax@107
4284 // unsigned int v56; // edi@107
4285 // int v57; // ST10_4@107
4286 unsigned int v58; // edi@107
4287 unsigned int v59; // ebx@107
4288 // signed int v60; // eax@107
4289 int v61; // eax@124
4290 Vec3_int_ v62; // [sp+Ch] [bp-44h]@42
4291 int v63; // [sp+18h] [bp-38h]@64
4292 int v64; // [sp+1Ch] [bp-34h]@64
4293 bool v67; // [sp+28h] [bp-28h]@10
4294 unsigned int v69; // [sp+30h] [bp-20h]@6
4295 unsigned int v70; // [sp+34h] [bp-1Ch]@10
4296 int v71; // [sp+38h] [bp-18h]@62
4297 int uIsAboveFloor; // [sp+3Ch] [bp-14h]@10
4298 int v72b;
4299 int uIsFlying; // [sp+44h] [bp-Ch]@8
4300 unsigned int v75; // [sp+48h] [bp-8h]@1
4301 int uIsOnWater; // [sp+4Ch] [bp-4h]@10
4302
4303 for (v75 = 0; v75 < uNumActors; ++v75)
4304 {
4305 if (pActors[v75].uAIState == Removed
4306 || pActors[v75].uAIState == Disabled
4307 || pActors[v75].uAIState == Summoned
4308 || !pActors[v75].uMovementSpeed)
4309 continue;
4310 v3 = 0;
4311 v69 = 0;
4312 if (MonsterStats::BelongsToSupertype(pActors[v75].pMonsterInfo.uID, MONSTER_SUPERTYPE_WATER_ELEMENTAL))
4313 v3 = 1;
4314 pActors[v75].uSectorID = 0;
4315 uIsFlying = pActors[v75].pMonsterInfo.uFlying;
4316 if (!pActors[v75].CanAct())
4317 uIsFlying = 0;
4318 v70 = IsTerrainSlopeTooHigh(pActors[v75].vPosition.x, pActors[v75].vPosition.y);
4319 v5 = ODM_GetFloorLevel(pActors[v75].vPosition.x, pActors[v75].vPosition.y, pActors[v75].vPosition.z,
4320 pActors[v75].uActorHeight, &uIsOnWater, (int *)&v69, v3);
4321 //v6 = pActors[v75].vPosition.z;
4322 uIsAboveFloor = 0;
4323 v67 = v69 == 0;
4324 if (pActors[v75].vPosition.z > v5 + 1)
4325 uIsAboveFloor = 1;
4326 if (pActors[v75].uAIState == Dead && uIsOnWater && !uIsAboveFloor)
4327 {
4328 pActors[v75].uAIState = Removed;
4329 continue;
4330 }
4331 if (pActors[v75].uCurrentActionAnimation == ANIM_Walking)
4332 {
4333 v8 = pActors[v75].uMovementSpeed;
4334 if ((signed __int64)pActors[v75].pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0)
4335 v8 = (signed __int64)((double)v8 * 0.5);
4336 if (pActors[v75].uAIState == Fleeing || pActors[v75].uAIState == Pursuing)
4337 v8 *= 2;
4338 if (pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_WAIT)
4339 v8 *= flt_6BE3AC_debug_recmod1_x_1_6;
4340 if (v8 > 1000)
4341 v8 = 1000;
4342
4343 pActors[v75].vVelocity.x = fixpoint_mul(stru_5C6E00->Cos(pActors[v75].uYawAngle), v8);
4344 pActors[v75].vVelocity.y = fixpoint_mul(stru_5C6E00->Sin(pActors[v75].uYawAngle), v8);
4345 if (uIsFlying)
4346 {
4347 pActors[v75].vVelocity.z = fixpoint_mul(stru_5C6E00->Sin(pActors[v75].uPitchAngle), v8);
4348 }
4349 //v7 = v68;
4350 }
4351 else
4352 {
4353 pActors[v75].vVelocity.x = fixpoint_mul(55000, pActors[v75].vVelocity.x);
4354 pActors[v75].vVelocity.y = fixpoint_mul(55000, pActors[v75].vVelocity.y);
4355 if (uIsFlying)
4356 pActors[v75].vVelocity.z = fixpoint_mul(55000, pActors[v75].vVelocity.z);
4357 }
4358 if (pActors[v75].vPosition.z < v5)
4359 {
4360 pActors[v75].vPosition.z = v5;
4361 pActors[v75].vVelocity.z = uIsFlying != 0 ? 0x14 : 0;
4362 }
4363 //v17 = 0;
4364 if (!uIsAboveFloor || uIsFlying)
4365 {
4366 if (v70 && !uIsAboveFloor && v67)
4367 {
4368 pActors[v75].vPosition.z = v5;
4369 ODM_GetTerrainNormalAt(pActors[v75].vPosition.x, pActors[v75].vPosition.y, &v62);
4370 v20 = GetGravityStrength();
4371 //v21 = v62.y;
4372 //v22 = v62.z;
4373 //v23 = v62.y * v0->vVelocity.y;
4374 pActors[v75].vVelocity.z += -8 * LOWORD(pEventTimer->uTimeElapsed) * v20;
4375 int v73 = abs(v62.x * pActors[v75].vVelocity.x + v62.z * pActors[v75].vVelocity.z + v62.y * pActors[v75].vVelocity.y) >> 16;
4376 //v72b = v21;
4377 pActors[v75].vVelocity.x += fixpoint_mul(v73, v62.x);
4378 pActors[v75].vVelocity.y += fixpoint_mul(v73, v62.y);
4379 pActors[v75].vVelocity.z += fixpoint_mul(v73, v62.z);
4380 //v17 = 0;
4381 }
4382 }
4383 else
4384 {
4385 pActors[v75].vVelocity.z -= LOWORD(pEventTimer->uTimeElapsed) * GetGravityStrength();
4386 }
4387 if (pParty->armageddon_timer != 0 && pActors[v75].CanAct())
4388 {
4389 pActors[v75].vVelocity.x += rand() % 100 - 50;
4390 pActors[v75].vVelocity.y += rand() % 100 - 50;
4391 pActors[v75].vVelocity.z += rand() % 100 - 20;
4392 v25 = rand();
4393 pActors[v75].uAIState = Stunned;
4394 pActors[v75].uYawAngle += v25 % 32 - 16;
4395 pActors[v75].UpdateAnimation();
4396 }
4397 if (pActors[v75].vVelocity.x * pActors[v75].vVelocity.x + pActors[v75].vVelocity.y * pActors[v75].vVelocity.y < 400 && v70 == 0)
4398 {
4399 pActors[v75].vVelocity.y = 0;
4400 pActors[v75].vVelocity.x = 0;
4401 }
4402 stru_721530.field_0 = 1;
4403 if (!uIsFlying)
4404 v26 = 40;
4405 else
4406 v26 = pActors[v75].uActorRadius;
4407
4408 stru_721530.field_84 = -1;
4409 stru_721530.field_8_radius = v26;
4410 stru_721530.prolly_normal_d = v26;
4411 stru_721530.height = pActors[v75].uActorHeight;
4412 stru_721530.field_70 = 0;
4413
4414 for (v69 = 0; v69 < 100; ++v69)
4415 {
4416 stru_721530.position.x = pActors[v75].vPosition.x;
4417 stru_721530.normal.x = stru_721530.position.x;
4418 stru_721530.position.y = pActors[v75].vPosition.y;
4419 stru_721530.normal.y = stru_721530.position.y;
4420 v28 = pActors[v75].vPosition.z;
4421 stru_721530.normal.z = v28 + v26 + 1;
4422 stru_721530.position.z = v28 - v26 + stru_721530.height - 1;
4423 if (stru_721530.position.z < stru_721530.normal.z)
4424 stru_721530.position.z = v28 + v26 + 1;
4425 stru_721530.velocity.x = pActors[v75].vVelocity.x;
4426 stru_721530.uSectorID = 0;
4427 stru_721530.velocity.y = pActors[v75].vVelocity.y;
4428 stru_721530.velocity.z = pActors[v75].vVelocity.z;
4429 if (stru_721530._47050A(0))
4430 break;
4431 _46E889_collide_against_bmodels(1);
4432 v29 = WorldPosToGridCellZ(pActors[v75].vPosition.y);
4433 v30 = WorldPosToGridCellX(pActors[v75].vPosition.x);
4434 _46E26D_collide_against_sprites(v30, v29);
4435 _46EF01_collision_chech_player(0);
4436 _46ED8A_collide_against_sprite_objects(PID(OBJECT_Actor, v75));
4437 v31 = 0;
4438 for (i = 0; v31 < ai_arrays_size; ++v31)
4439 {
4440 v33 = ai_near_actors_ids[v31];
4441 if (v33 != v75 && Actor::_46DF1A_collide_against_actor(v33, 40))
4442 ++i;
4443 }
4444 v71 = i > 1;
4445 if (stru_721530.field_7C < stru_721530.field_6C)
4446 v70 = fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z);
4447 //v34 = 0;
4448 v35 = stru_721530.normal2.z - stru_721530.prolly_normal_d - 1;
4449 v36 = ODM_GetFloorLevel(stru_721530.normal2.x, stru_721530.normal2.y,
4450 stru_721530.normal2.z - stru_721530.prolly_normal_d - 1,
4451 pActors[v75].uActorHeight, (int *)&v63, &v64, 0);
4452 if (uIsOnWater)
4453 {
4454 if (v35 < v36 + 60)
4455 {
4456 if (pActors[v75].uAIState == Dead || pActors[v75].uAIState == Dying || pActors[v75].uAIState == Removed
4457 || pActors[v75].uAIState == Disabled)
4458 {
4459 if (v64)
4460 v61 = v36 + 30;
4461 else
4462 v61 = v5 + 60;
4463 SpriteObject::sub_42F960_create_object(pActors[v75].vPosition.x, pActors[v75].vPosition.y, v61);
4464 pActors[v75].uAIState = Removed;
4465 return;
4466 }
4467 }
4468 }
4469 if (stru_721530.field_7C >= stru_721530.field_6C)
4470 {
4471 pActors[v75].vPosition.x = LOWORD(stru_721530.normal2.x);
4472 pActors[v75].vPosition.y = LOWORD(stru_721530.normal2.y);
4473 pActors[v75].vPosition.z = LOWORD(stru_721530.normal2.z) - LOWORD(stru_721530.prolly_normal_d) - 1;
4474 break;
4475 }
4476 //v72b = fixpoint_mul(stru_721530.field_7C, stru_721530.field_58.x);
4477 pActors[v75].vPosition.x += fixpoint_mul(stru_721530.field_7C, stru_721530.direction.x);
4478 //v72b = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.y) >> 16;
4479 pActors[v75].vPosition.y += fixpoint_mul(stru_721530.field_7C, stru_721530.direction.y);
4480 //v72b = (unsigned __int64)(stru_721530.field_7C * (signed __int64)stru_721530.field_58.z) >> 16;
4481 pActors[v75].vPosition.z += fixpoint_mul(stru_721530.field_7C, stru_721530.direction.z);
4482 stru_721530.field_70 += stru_721530.field_7C;
4483 v39 = PID_ID(stru_721530.uFaceID);
4484 switch (PID_TYPE(stru_721530.uFaceID))
4485 {
4486 case OBJECT_Actor:
4487 if (pTurnEngine->turn_stage != TE_ATTACK && pTurnEngine->turn_stage != TE_MOVEMENT || pParty->bTurnBasedModeOn != TE_WAIT)
4488 {
4489 //if(pParty->bTurnBasedModeOn == 1)
4490 //v34 = 0;
4491 if (pActors[v75].pMonsterInfo.uHostilityType)
4492 {
4493 if (v71 == 0)
4494 Actor::AI_Flee(v75, stru_721530.uFaceID, 0, (AIDirection *)0);
4495 else
4496 Actor::AI_StandOrBored(v75, 4, 0, (AIDirection *)0);
4497 }
4498 else if (v71)
4499 Actor::AI_StandOrBored(v75, 4, 0, (AIDirection *)0);
4500 else if (pActors[v39].pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Friendly)
4501 Actor::AI_Flee(v75, stru_721530.uFaceID, 0, (AIDirection *)0);
4502 else
4503 Actor::AI_FaceObject(v75, stru_721530.uFaceID, 0, (AIDirection *)0);
4504 }
4505 break;
4506 case OBJECT_Player:
4507 if (!pActors[v75].GetActorsRelation(0))
4508 {
4509 Actor::AI_FaceObject(v75, stru_721530.uFaceID, 0, (AIDirection *)0);
4510 break;
4511 }
4512 //v52 = HIDWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime) == 0;
4513 //v53 = SHIDWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime) < 0;
4514 pActors[v75].vVelocity.y = 0;
4515 pActors[v75].vVelocity.x = 0;
4516 //if ( !v53 && (!(v53 | v52) || LODWORD(pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime) > 0) )
4517 if ((signed __int64)pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime < 0)
4518 pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
4519 viewparams->bRedrawGameUI = 1;
4520 break;
4521 case OBJECT_Decoration:
4522 v47 = integer_sqrt(pActors[v75].vVelocity.x * pActors[v75].vVelocity.x + pActors[v75].vVelocity.y * pActors[v75].vVelocity.y);
4523 v48 = stru_5C6E00->Atan2(pActors[v75].vPosition.x - pLevelDecorations[v39].vPosition.x,
4524 pActors[v75].vPosition.y - pLevelDecorations[v39].vPosition.y);
4525 //v49 = v48;
4526 pActors[v75].vVelocity.x = fixpoint_mul(stru_5C6E00->Cos(v48), v47);
4527 pActors[v75].vVelocity.y = fixpoint_mul(stru_5C6E00->Sin(v48), v47);
4528 break;
4529 case OBJECT_BModel:
4530 face = &pOutdoor->pBModels[stru_721530.uFaceID >> 9].pFaces[v39 & 0x3F];
4531 if (!face->Ethereal())
4532 {
4533 if (face->uPolygonType == 3)
4534 {
4535 pActors[v75].vVelocity.z = 0;
4536 pActors[v75].vPosition.z = LOWORD(pOutdoor->pBModels[stru_721530.uFaceID >> 9].pVertices.pVertices[face->pVertexIDs[0]].z) + 1;
4537 if (pActors[v75].vVelocity.x * pActors[v75].vVelocity.x
4538 + pActors[v75].vVelocity.y * pActors[v75].vVelocity.y < 400)
4539 {
4540 pActors[v75].vVelocity.y = 0;
4541 pActors[v75].vVelocity.x = 0;
4542 }
4543 }
4544 else
4545 {
4546 v72b = abs(face->pFacePlane.vNormal.y * pActors[v75].vVelocity.y + face->pFacePlane.vNormal.z * pActors[v75].vVelocity.z
4547 + face->pFacePlane.vNormal.x * pActors[v75].vVelocity.x) >> 16;
4548 if ((stru_721530.speed >> 3) > v72b)
4549 v72b = stru_721530.speed >> 3;
4550
4551 pActors[v75].vVelocity.x += fixpoint_mul(v72b, face->pFacePlane.vNormal.x);
4552 pActors[v75].vVelocity.y += fixpoint_mul(v72b, face->pFacePlane.vNormal.y);
4553 pActors[v75].vVelocity.z += fixpoint_mul(v72b, face->pFacePlane.vNormal.z);
4554 if (face->uPolygonType != 4)
4555 {
4556 v46 = stru_721530.prolly_normal_d
4557 - ((face->pFacePlane.dist
4558 + face->pFacePlane.vNormal.x * pActors[v75].vPosition.x
4559 + face->pFacePlane.vNormal.y * pActors[v75].vPosition.y
4560 + face->pFacePlane.vNormal.z * pActors[v75].vPosition.z) >> 16);
4561 if (v46 > 0)
4562 {
4563 pActors[v75].vPosition.x += fixpoint_mul(v46, face->pFacePlane.vNormal.x);
4564 pActors[v75].vPosition.y += fixpoint_mul(v46, face->pFacePlane.vNormal.y);
4565 pActors[v75].vPosition.z += fixpoint_mul(v46, face->pFacePlane.vNormal.z);
4566 }
4567 pActors[v75].uYawAngle = stru_5C6E00->Atan2(pActors[v75].vVelocity.x, pActors[v75].vVelocity.y);
4568 }
4569 }
4570 }
4571 break;
4572 }
4573
4574 pActors[v75].vVelocity.x = fixpoint_mul(58500, pActors[v75].vVelocity.x);
4575 pActors[v75].vVelocity.y = fixpoint_mul(58500, pActors[v75].vVelocity.y);
4576 pActors[v75].vVelocity.z = fixpoint_mul(58500, pActors[v75].vVelocity.z);
4577
4578 v26 = stru_721530.prolly_normal_d;
4579 }
4580
4581 v58 = ((unsigned int)~pOutdoor->ActuallyGetSomeOtherTileInfo(WorldPosToGridCellX(pActors[v75].vPosition.x), WorldPosToGridCellZ(pActors[v75].vPosition.y) - 1) >> 1) & 1;
4582 v59 = ((unsigned int)~pOutdoor->ActuallyGetSomeOtherTileInfo(WorldPosToGridCellX(pActors[v75].vPosition.x), WorldPosToGridCellZ(pActors[v75].vPosition.y) - 1) >> 1) & 1;
4583 if (WorldPosToGridCellX(pActors[v75].vPosition.x) == WorldPosToGridCellX(pActors[v75].vPosition.x)
4584 && WorldPosToGridCellZ(pActors[v75].vPosition.y) == WorldPosToGridCellZ(pActors[v75].vPosition.y)
4585 && v58 || v67 != 0)
4586 {
4587 if (MonsterStats::BelongsToSupertype(pActors[v75].pMonsterInfo.uID, MONSTER_SUPERTYPE_WATER_ELEMENTAL))
4588 {
4589 v58 = v58 == 0;
4590 v59 = v59 == 0;
4591 }
4592 if (!uIsFlying && v58 && !v59)
4593 {
4594 pActors[v75].vPosition.x = pActors[v75].vPosition.x;
4595 pActors[v75].vPosition.y = pActors[v75].vPosition.y;
4596 if (pActors[v75].CanAct())
4597 {
4598 pActors[v75].uYawAngle -= 32;
4599 pActors[v75].uCurrentActionTime = 0;
4600 pActors[v75].uCurrentActionLength = 128;
4601 pActors[v75].uAIState = Fleeing;
4602 }
4603 }
4604 }
4605 }
4606 }
4607
4608 //----- (0047A384) --------------------------------------------------------
4609 void ODM_LoadAndInitialize(const char *pLevelFilename, ODMRenderParams *thisa)
4610 {
4611 int v2; // ebx@3
4612 unsigned int v3; // eax@3
4613 MapInfo *v4; // edi@4
4614 //int v5; // eax@8
4615 //SpawnPointMM7 *v6; // edx@14
4616 size_t v7; // eax@19
4617 //char *v8; // eax@19
4618 //char *v9; // eax@21
4619 char Source[120]; // [sp+Ch] [bp-84h]@19
4620 const char *pFilename; // [sp+84h] [bp-Ch]@1
4621 //unsigned int v12; // [sp+88h] [bp-8h]@12
4622 //int v13; // [sp+8Ch] [bp-4h]@11
4623 int v;
4624
4625 pFilename = pLevelFilename;
4626 //thisa->AllocSoftwareDrawBuffers();
4627 pODMRenderParams->Initialize();
4628 pWeather->bRenderSnow = false;
4629 pRenderer->ClearZBuffer(0, 479);
4630 //thisa = (ODMRenderParams *)1;
4631 GetAlertStatus();
4632 if (_A750D8_player_speech_timer)
4633 _A750D8_player_speech_timer = 0;
4634 v2 = pMapStats->GetMapInfo(pCurrentMapName);
4635 v3 = 0;
4636 if (v2)
4637 {
4638 v4 = &pMapStats->pInfos[v2];
4639 v3 = v4->uRespawnIntervalDays;
4640 }
4641 else
4642 v4 = (MapInfo *)1;
4643 day_attrib &= ~DAY_ATTRIB_FOG;
4644 dword_6BE13C_uCurrentlyLoadedLocationID = v2;
4645 pOutdoor->Initialize(
4646 pFilename,
4647 (unsigned int)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 0x3C / 0x3C / 0x18 + 1,
4648 v3,
4649 &v);
4650 if (!(dword_6BE364_game_settings_1 & GAME_SETTINGS_2000))
4651 {
4652 Actor::InitializeActors();
4653 SpriteObject::InitializeSpriteObjects();
4654 }
4655 dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_2000;
4656 //v5 = 0;
4657 if (!v2)
4658 v = 0;
4659 if (v == 1)
4660 {
4661 //v13 = 0;
4662 for (uint i = 0; i < pOutdoor->uNumSpawnPoints; ++i)
4663 {
4664 //v12 = 0;
4665 //while ( 1 )
4666 //{
4667 SpawnPointMM7* spawn = pOutdoor->pSpawnPoints + i;
4668 //v6 = &pOutdoor->pSpawnPoints[v12 / 0x18];
4669 if (spawn->uKind == 3)
4670 SpawnEncounter(v4, spawn, 0, 0, 0);
4671 else
4672 v4->SpawnRandomTreasure(spawn);
4673 //++v13;
4674 //v12 += 24;
4675 //if ( v13 >= (signed int)pOutdoor->uNumSpawnPoints )
4676 // break;
4677 //v5 = 0;
4678 //}
4679 }
4680 RespawnGlobalDecorations();
4681 }
4682 pOutdoor->PrepareDecorations();
4683 pOutdoor->ArrangeSpriteObjects();
4684 pOutdoor->InitalizeActors(v2);
4685 pOutdoor->MessWithLUN();
4686 v7 = strlen("levels\\");
4687 strcpy(Source, &pFilename[v7]);
4688 strcpy(pOutdoor->pLevelFilename, Source);
4689 pWeather->Initialize();
4690 pGame->pIndoorCameraD3D->sRotationY = pParty->sRotationY;
4691 pGame->pIndoorCameraD3D->sRotationX = pParty->sRotationX;
4692 //pODMRenderParams->RotationToInts();
4693 pOutdoor->UpdateSunlightVectors();
4694
4695 float fov_rad;
4696 float fov_rad_inv;
4697 //----- (0042394D) --------------------------------------------------------
4698 //void IndoorCamera::Initialize(int degFov, unsigned int uViewportWidth, unsigned int uViewportHeight)
4699 {
4700 //pIndoorCamera->Initialize(65, viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X + 1,
4701 // viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y + 1);
4702
4703 int uViewportWidth = viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X + 1;
4704
4705 extern float _calc_fov(int viewport_width, int angle_degree);
4706 fov_rad = _calc_fov(uViewportWidth, 65);
4707 fov_rad_inv = 65536.0 / fov_rad;
4708 }
4709 pODMRenderParams->int_fov_rad = (signed __int64)fov_rad;
4710 pODMRenderParams->int_fov_rad_inv = (signed __int64)fov_rad_inv;
4711
4712 for (int i = 0; i < 20000; ++i)
4713 {
4714 array_77EC08[i].ptr_38 = &stru_8019C8;
4715
4716 array_77EC08[i].ptr_48 = nullptr;
4717 }
4718
4719 MM7Initialization();
4720 }
4721
4722 //----- (0047C370) --------------------------------------------------------
4723 unsigned int GetLevelFogColor()
4724 {
4725 signed __int64 v1; // qax@5
4726 int v2; // eax@6
4727
4728 if (bUnderwater)
4729 return 0xFF258F5C;
4730
4731 if (day_attrib & DAY_ATTRIB_FOG)
4732 {
4733 if (pWeather->bNight) // night-time fog
4734 {
4735 if (for_refactoring)
4736 {
4737 MessageBoxA(nullptr, "Nomad: decompilation can be inaccurate, please send savegame to Nomad", "", 0);
4738 __debugbreak();
4739 }
4740 v2 = -(pWeather->bNight != 1);
4741 return (v2 & 0xE0E0E1) - 0xE0E0E1;
4742 }
4743 else
4744 {
4745 v1 = (signed __int64)((1.0 - pOutdoor->fFogDensity) * 200.0 + pOutdoor->fFogDensity * 31.0);
4746 return v1 | (((unsigned int)v1 | (((unsigned int)v1 | 0xFFFFFF00) << 8)) << 8);
4747 }
4748 }
4749
4750 return 0;
4751 }
4752
4753 //----- (0047C3D7) --------------------------------------------------------
4754 int __fastcall sub_47C3D7_get_fog_specular(int a1, int a2, float a3)
4755 {
4756 int v3; // ecx@1
4757 signed int v7; // ecx@11
4758
4759 v3 = pWeather->bNight;
4760 if (bUnderwater == 1)
4761 v3 = 0;
4762 if (pParty->armageddon_timer || !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater)
4763 return 0xFF000000;
4764 if (v3)
4765 {
4766 if (a3 < (double)day_fogrange_1)
4767 {
4768 v7 = 0;
4769 if (a3 == 0.0)
4770 v7 = 216;
4771 if (a2)
4772 v7 = 248;
4773 return (-1 - v7) << 24;
4774 }
4775 else
4776 {
4777 if (a3 > (double)day_fogrange_2)
4778 {
4779 v7 = 216;
4780 if (a3 == 0.0)
4781 v7 = 216;
4782 if (a2)
4783 v7 = 248;
4784 return (-1 - v7) << 24;
4785 }
4786 v7 = (signed __int64)((a3 - (double)day_fogrange_1) / ((double)day_fogrange_2 - (double)day_fogrange_1) * 216.0);
4787 }
4788 }
4789 else
4790 {
4791 if (a3 < (double)day_fogrange_1)
4792 {
4793 v7 = 0;
4794 if (a3 == 0.0)
4795 v7 = 216;
4796 if (a2)
4797 v7 = 248;
4798 return (-1 - v7) << 24;
4799 }
4800 else
4801 {
4802 if (a3 > (double)day_fogrange_2)
4803 {
4804 v7 = 216;
4805 if (a3 == 0.0)
4806 v7 = 216;
4807 if (a2)
4808 v7 = 248;
4809 return (-1 - v7) << 24;
4810 }
4811 else
4812 v7 = floorf(((a3 - (double)day_fogrange_1) * 216.0 / ((double)day_fogrange_2 - (double)day_fogrange_1)) + 0.5f);
4813 }
4814 }
4815 if (v7 > 216)
4816 v7 = 216;
4817 else
4818 {
4819 if (a3 == 0.0)
4820 v7 = 216;
4821 }
4822 if (a2)
4823 v7 = 248;
4824 return (-1 - v7) << 24;
4825 }
4826
4827
4828 //----- (0047F44B) --------------------------------------------------------
4829 unsigned int WorldPosToGridCellX(int sWorldPosX)
4830 {
4831 return (sWorldPosX >> 9) + 64; // sar is in original exe, resulting -880 / 512 = -1
4832 // and -880 sar 9 = -2
4833 }
4834
4835 //----- (0047F458) --------------------------------------------------------
4836 unsigned int WorldPosToGridCellZ(int sWorldPosZ)
4837 {
4838 return 64 - (sWorldPosZ >> 9); // sar is in original exe, resulting -880 / 512 = -1
4839 // and -880 sar 9 = -2
4840 }
4841
4842 //----- (0047F469) --------------------------------------------------------
4843 int GridCellToWorldPosX(int a1)
4844 {
4845 return (a1 - 64) << 9;
4846 }
4847
4848 //----- (0047F476) --------------------------------------------------------
4849 int GridCellToWorldPosZ(int a1)
4850 {
4851 return (64 - a1) << 9;
4852 }
4853
4854
4855
4856 //----- (00481ED9) --------------------------------------------------------
4857 void sub_481ED9_MessWithODMRenderParams()
4858 {
4859 stru_8019C8._48616B_frustum_odm(65536, 0, 0, 0, 65536, 0);
4860 pODMRenderParams->uNumPolygons = 0;
4861 //pODMRenderParams->uNumEdges = 0;
4862 //pODMRenderParams->uNumSpans = 0;
4863 //pODMRenderParams->uNumSurfs = 0;
4864 pODMRenderParams->uNumBillboards = 0;
4865 pODMRenderParams->field_44 = 0;
4866 }
4867
4868 //----- (004823F4) --------------------------------------------------------
4869 bool IsTerrainSlopeTooHigh(int pos_x, int pos_z)
4870 {
4871 //unsigned int v2; // ebx@1
4872 //unsigned int v3; // edi@1
4873 //int v4; // eax@1
4874 //int v6; // esi@5
4875 //int v7; // ecx@6
4876 //int v8; // edx@6
4877 //int v9; // eax@6
4878 //int y_min; // esi@10
4879 //int v11; // [sp+14h] [bp-8h]@1
4880 //int v12; // [sp+18h] [bp-4h]@1
4881
4882 //v12 = a1;
4883 //v11 = a2;
4884 unsigned int grid_x = WorldPosToGridCellX(pos_x);
4885 unsigned int grid_z = WorldPosToGridCellZ(pos_z) - 1;
4886
4887 int party_grid_x1 = GridCellToWorldPosX(grid_x);
4888 //dword_76D56C_terrain_cell_world_pos_around_party_x = GridCellToWorldPosX(grid_x + 1);
4889 //dword_76D570_terrain_cell_world_pos_around_party_x = GridCellToWorldPosX(grid_x + 1);
4890 //dword_76D574_terrain_cell_world_pos_around_party_x = GridCellToWorldPosX(grid_x);
4891 int party_grid_z1 = GridCellToWorldPosZ(grid_z);
4892 //dword_76D55C_terrain_cell_world_pos_around_party_z = GridCellToWorldPosZ(grid_z);
4893 //dword_76D560_terrain_cell_world_pos_around_party_z = GridCellToWorldPosZ(grid_z + 1);
4894 //dword_76D564_terrain_cell_world_pos_around_party_z = GridCellToWorldPosZ(grid_z + 1);
4895 int party_x1z1_y = pOutdoor->DoGetHeightOnTerrain(grid_x, grid_z);
4896 int party_x2z1_y = pOutdoor->DoGetHeightOnTerrain(grid_x + 1, grid_z);
4897 int party_x2z2_y = pOutdoor->DoGetHeightOnTerrain(grid_x + 1, grid_z + 1);
4898 int party_x1z2_y = pOutdoor->DoGetHeightOnTerrain(grid_x, grid_z + 1);
4899 //dword_76D554_terrain_cell_world_pos_around_party_y = v4;
4900 if (party_x1z1_y == party_x2z1_y &&
4901 party_x2z1_y == party_x2z2_y &&
4902 party_x2z2_y == party_x1z2_y)
4903 return false;
4904
4905 int dx = abs(pos_x - party_grid_x1),
4906 dz = abs(party_grid_z1 - pos_z);
4907
4908 int y1, y2, y3;
4909 if (dz >= dx)
4910 {
4911 y1 = party_x1z2_y; // lower-left triangle
4912 y2 = party_x2z2_y; // y3 | \
4913 y3 = party_x1z1_y; // | \
4914 /* | \
4915 |______ \
4916 y1 y2 */
4917 }
4918 else
4919 {
4920 y1 = party_x2z1_y; // upper-right
4921 y2 = party_x1z1_y; // y2_______ y1
4922 y3 = party_x2z2_y; // \ |
4923 /* \ |
4924 \ |
4925 y3 */
4926 }
4927
4928 int y_min = min(y1, min(y2, y3));// не верно при подъёме на склон
4929 int y_max = max(y1, max(y2, y3));
4930 return (y_max - y_min) > 512;
4931 }
4932
4933 //----- (0048257A) --------------------------------------------------------
4934 int __fastcall GetTerrainHeightsAroundParty2(int a1, int a2, int *pIsOnWater, int bFloatAboveWater)
4935 {
4936 // int result; // eax@9
4937 int v8; // ebx@11
4938 int v9; // eax@11
4939 int v10; // ecx@11
4940 int v13; // [sp+10h] [bp-8h]@11
4941 signed int v14; // [sp+14h] [bp-4h]@3
4942 int v15; // [sp+24h] [bp+Ch]@11
4943
4944 unsigned int grid_x = WorldPosToGridCellX(a1);
4945 unsigned int grid_z = WorldPosToGridCellZ(a2) - 1;
4946
4947 int grid_x1 = GridCellToWorldPosX(grid_x),
4948 grid_x2 = GridCellToWorldPosX(grid_x + 1);
4949 int grid_z1 = GridCellToWorldPosZ(grid_z),
4950 grid_z2 = GridCellToWorldPosZ(grid_z + 1);
4951
4952 int y_x1z1 = pOutdoor->DoGetHeightOnTerrain(grid_x, grid_z),
4953 y_x2z1 = pOutdoor->DoGetHeightOnTerrain(grid_x + 1, grid_z),
4954 y_x2z2 = pOutdoor->DoGetHeightOnTerrain(grid_x + 1, grid_z + 1),
4955 y_x1z2 = pOutdoor->DoGetHeightOnTerrain(grid_x, grid_z + 1);
4956 //v4 = WorldPosToGridCellX(a1);
4957 //v5 = WorldPosToGridCellZ(v12) - 1;
4958 //dword_76D538_terrain_cell_world_pos_around_party_x = GridCellToWorldPosX(v4);
4959 //dword_76D53C_terrain_cell_world_pos_around_party_x = GridCellToWorldPosX(v4 + 1);
4960 //dword_76D540_terrain_cell_world_pos_around_party_x = GridCellToWorldPosX(v4 + 1);
4961 //dword_76D544_terrain_cell_world_pos_around_party_x = GridCellToWorldPosX(v4);
4962 //dword_76D528_terrain_cell_world_pos_around_party_z = GridCellToWorldPosZ(v5);
4963 //dword_76D52C_terrain_cell_world_pos_around_party_z = GridCellToWorldPosZ(v5);
4964 //dword_76D530_terrain_cell_world_pos_around_party_z = GridCellToWorldPosZ(v5 + 1);
4965 //dword_76D534_terrain_cell_world_pos_around_party_z = GridCellToWorldPosZ(v5 + 1);
4966 //dword_76D518_terrain_cell_world_pos_around_party_y = pOutdoor->DoGetHeightOnTerrain(v4, v5);
4967 //dword_76D51C_terrain_cell_world_pos_around_party_y = pOutdoor->DoGetHeightOnTerrain(v4 + 1, v5);
4968 //dword_76D520_terrain_cell_world_pos_around_party_y = pOutdoor->DoGetHeightOnTerrain(v4 + 1, v5 + 1);
4969 //dword_76D524_terrain_cell_world_pos_around_party_y = pOutdoor->DoGetHeightOnTerrain(v4, v5 + 1);
4970 *pIsOnWater = false;
4971 if (pOutdoor->ActuallyGetSomeOtherTileInfo(grid_x, grid_z) & 2)
4972 *pIsOnWater = true;
4973 v14 = 0;
4974 if (!bFloatAboveWater && *pIsOnWater)
4975 v14 = -60;
4976 if (y_x1z1 != y_x2z1 ||
4977 y_x2z1 != y_x2z2 ||
4978 y_x2z2 != y_x1z2)
4979 {
4980 if (abs(grid_z1 - a2) >= abs(a1 - grid_x1))
4981 {
4982 v8 = y_x1z2;
4983 v9 = y_x2z2;
4984 v10 = y_x1z1;
4985 v15 = a1 - grid_x1;
4986 v13 = a2 - grid_z2;
4987 }
4988 else
4989 {
4990 v8 = y_x2z1;
4991 v9 = y_x1z1;
4992 v10 = y_x2z2;
4993 v15 = grid_x2 - a1;
4994 v13 = grid_z1 - a2;
4995 }
4996 return v14 + v8 + fixpoint_mul(v13, (v10 - v8) * 128) + fixpoint_mul(v15, (v9 - v8) * 128);
4997 }
4998 else
4999 return y_x1z1;
5000 }