comparison Game.cpp @ 0:9c0607679772

init
author Ritor1
date Sat, 12 Jan 2013 09:45:18 +0600
parents
children 8e33efd39355
comparison
equal deleted inserted replaced
-1:000000000000 0:9c0607679772
1 #include "Game.h"
2 #include "Party.h"
3 #include "IndoorCamera.h"
4 #include "Math.h"
5 #include "LightmapBuilder.h"
6 #include "Viewport.h"
7 #include "Time.h"
8 #include "Outdoor.h"
9 #include "Overlays.h"
10 #include "stru279.h"
11 #include "AudioPlayer.h"
12 #include "LOD.h"
13 #include "OSInfo.h"
14 #include "GUIWindow.h"
15 #include "Party.h"
16 #include "TurnEngine.h"
17 #include "stru157.h"
18 #include "VideoPlayer.h"
19 #include "Bink_Smacker.h"
20 #include "Events.h"
21 #include "Arcomage.h"
22
23 //#include "MM7.h"
24
25
26
27
28
29
30 Game *pGame;
31
32
33
34
35
36 //----- (00435694) --------------------------------------------------------
37 void Game::ToggleFlags2(unsigned int uFlag)
38 {
39 unsigned int v2; // eax@1
40
41 v2 = this->uFlags2;
42 if ( v2 & uFlag )
43 this->uFlags2 = v2 & ~uFlag;
44 else
45 this->uFlags2 = uFlag | v2;
46 }
47
48 //----- (0044103C) --------------------------------------------------------
49 void Game::Draw()
50 {
51 float v2; // ST24_4@11
52 //double v3; // ST28_8@11
53 int v4; // edi@26
54 int v5; // eax@35
55
56 uFlags2 &= 0xFFFFFFFDu;
57 if ( pParty->_497FC5_check_party_perception_against_level() )
58 uFlags2 |= 2u;
59 pIndoorCamera->sRotationX = pParty->sRotationX;
60 pIndoorCamera->sRotationY = pParty->sRotationY;
61 pIndoorCamera->pos.x = pParty->vPosition.x - ((unsigned __int64)(stru_5C6E00->SinCos(pParty->sRotationY)
62 * (signed __int64)pParty->field_18) >> 16);
63 pIndoorCamera->pos.y = pParty->vPosition.y - ((unsigned __int64)(stru_5C6E00->SinCos(pParty->sRotationY - stru_5C6E00->uIntegerHalfPi)
64 * (signed __int64)pParty->field_18) >> 16);
65 pIndoorCamera->pos.z = pParty->vPosition.z + pParty->sEyelevel;
66 pIndoorCamera->Initialize2();
67 pIndoorCameraD3D->CreateWorldMatrixAndSomeStuff();
68 pIndoorCameraD3D->_4374E8_ProllyBuildFrustrum();
69
70 if ( pVideoPlayer->AnyMovieLoaded() )
71 {
72 if ( pRenderer->pRenderD3D )
73 goto LABEL_22;
74 pRenderer->BeginSceneD3D();
75 pMouse->DrawCursorToTarget();
76 }
77 else
78 {
79 if ( pParty->vPosition.x != pParty->vPrevPosition.x | pParty->sRotationY != pParty->sPrevRotationY | pParty->vPosition.y != pParty->vPrevPosition.z
80 | pParty->sRotationX != pParty->sPrevRotationX | pParty->vPosition.z != pParty->vPrevPosition.y | pParty->sEyelevel != pParty->sPrevEyelevel )
81 pParty->uFlags |= 2u;
82 pParty->vPrevPosition.x = pParty->vPosition.x;
83 pParty->vPrevPosition.y = pParty->vPosition.z;
84 //v0 = &pRenderer;
85 pParty->sPrevRotationY = pParty->sRotationY;
86 pParty->vPrevPosition.z = pParty->vPosition.y;
87 pParty->sPrevRotationX = pParty->sRotationX;
88 pParty->sPrevEyelevel = pParty->sEyelevel;
89 pRenderer->BeginSceneD3D();
90
91 if ( !pRenderer->pRenderD3D )
92 pMouse->DrawCursorToTarget();
93 if ( !sub_4226C2() || viewparams->field_48 == 1 )
94 {
95 if ( pRenderer->pRenderD3D )
96 {
97 v2 = (double)(((signed int)pMiscTimer->uTotalGameTimeElapsed >> 2) & 0x1F) * 0.032258064 * 6.0;
98 //v3 = v2 + 6.7553994e15;
99 //pRenderer->field_1036A8_bitmapid = LODWORD(v3);
100 pRenderer->field_1036A8_bitmapid = floorf(v2 + 0.5f);
101 }
102
103 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
104 pIndoor->Draw();
105 else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
106 pOutdoor->Draw();
107
108 if (pRenderer->pRenderD3D)
109 {
110 pDecalBuilder->DrawBloodsplats();
111 if (pRenderer->pRenderD3D)
112 pGame->pLightmapBuilder->DrawLightmaps(2);
113 }
114 }
115 }
116 pRenderer->DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
117 LABEL_22:
118 pRenderer->BeginScene();
119 if (pRenderer->pRenderD3D)
120 pMouse->DrawCursorToTarget();
121 if (pOtherOverlayList->field_3EC)
122 viewparams->bRedrawGameUI = 1;
123 v4 = viewparams->bRedrawGameUI;
124 GameUI_DrawStatusBar();
125 if (!viewparams->bRedrawGameUI)
126 {
127 GameUI_DrawRightPanelItems();
128 }
129 else
130 {
131 GameUI_DrawRightPanelFrames();
132 GameUI_DrawStatusBar_2();
133 viewparams->bRedrawGameUI = false;
134 }
135 if (!pVideoPlayer->pSmackerMovie)
136 {
137 GameUI_DrawMinimap(488, 16, 625, 133, viewparams->uMinimapZoom, pParty->uFlags & 2);
138 if (v4)
139 {
140 if ( !sub_4226C2() && pRenderer->pRenderD3D)
141 pRenderer->FillRectFast(pViewport->uViewportX, pViewport->uViewportY, pViewport->uViewportZ - pViewport->uViewportX,
142 pViewport->uViewportW - pViewport->uViewportY + 1, pRenderer->uTargetGMask | pRenderer->uTargetBMask);
143 viewparams->field_48 = 0;
144 }
145 }
146 v5 = pOtherOverlayList->field_3EC;
147 pOtherOverlayList->field_3EC = 0;
148 viewparams->bRedrawGameUI = v5;
149 GameUI_DrawPartySpells();
150 //if (v4 || pParty->pHirelings[0].evtc || pParty->pHirelings[1].evtc )
151 //DrawHiredNPCs();//Ritor1: it's temporarily
152 GameUI_DrawPortraits(v4);
153 GameUI_DrawLifeManaBars();
154 GameUI_DrawCharacterSelectionFrame();
155 if ( sub_44100D() )
156 draw_right_panel();
157 if ( !pVideoPlayer->AnyMovieLoaded() )
158 {
159 pStru6Instance->DrawPlayerBuffAnims();
160 pOtherOverlayList->_441964(v4);
161 GameUI_DrawTorchlightAndWizardEye();
162 }
163 GUI_UpdateWindows();
164 pParty->_4909F4();
165 ++stru_51076C.field_8;
166 dword_5B5924 = 0;
167 if (v4)
168 pMouse->field_14 = 1;
169 pMouse->_469EA4();
170 pMouse->DrawCursor();
171 pMouse->_469E1C();
172 pRenderer->EndScene();
173 pRenderer->Present();
174 pParty->uFlags &= 0xFFFFFFFDu;
175 }
176
177
178 //----- (0047A815) --------------------------------------------------------
179 void Game::DrawParticles()
180 {
181 pParticleEngine->Draw();
182 }
183
184 //----- (00463149) --------------------------------------------------------
185 void Game::Loop()
186 {
187 //signed int v0; // ebp@3
188 //signed int v1; // esi@4
189 //Render *v2; // edi@7
190 //signed int v3; // esi@7
191 signed int pNewNPCsCount; // ecx@58
192 char *pFlags; // eax@59
193 Player *pPlayer; // esi@65
194 OtherOverlay *pOtherOverlay; // esi@67
195 signed int v8; // edi@67
196 int pPlayerNum; // edi@69
197 int *pHealth; // esi@71
198 signed int v11; // esi@78
199 int v12; // eax@83
200 const char *pLocationName; // [sp-4h] [bp-68h]@74
201 bool bLoading; // [sp+10h] [bp-54h]@1
202 signed int bLoadinga; // [sp+10h] [bp-54h]@19
203 signed int v16; // [sp+14h] [bp-50h]@8
204 int v17[4]; // [sp+18h] [bp-4Ch]@80
205 MSG Msg; // [sp+28h] [bp-3Ch]@20
206 char Source[64]; // [sp+44h] [bp-20h]@76
207
208 bLoading = uCurrentMenuID == MENU_LOAD;
209 SetCurrentMenuID((MENU_STATE)-1);
210 if (bLoading)
211 {
212 pParty->Reset();
213 dword_6BE340 = 0;
214 uGameState = 0;
215 LoadGame(uLoadGameUI_SelectedSlot);
216 }
217
218 for (uint i = 1; i < 5; ++i)
219 for (uint j = 1; j < 6; ++j)
220 {
221 sprintf(pTmpBuf, "data\\lloyd%d%d.pcx", i, j);
222 remove(pTmpBuf);
223 }
224
225 LoadPlayerPortraintsAndVoices();
226 pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
227 pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0);
228
229 while ( 2 )
230 {
231 v16 = 1;
232 if (pMessageQueue_50CBD0->uNumMessages)
233 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
234
235 pPartyActionQueue->uNumActions = 0;
236 if (pParty->bTurnBasedModeOn)
237 {
238 pTurnEngine->End(false);
239 pParty->bTurnBasedModeOn = false;
240 }
241 DoPrepareWorld(bLoading, 1);
242 pEventTimer->Resume();
243 dword_6BE364_game_settings_1 |= 0x80;
244 dword_6BE340 = 2;
245 // uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 0;
246 pCurrentScreen = 0;
247 if (pAsyncMouse)
248 pAsyncMouse->Resume();
249 if (pGame->pKeyboardInstance->bUsingAsynKeyboard && pAsyncKeyboard )
250 pAsyncKeyboard->Resume();
251 if ( pRenderer->pRenderD3D )
252 pGame->pVisInstance->_4C1A02();
253 bLoadinga = 0;
254 do
255 {
256 while ( PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE) )
257 {
258 if ( Msg.message == WM_QUIT )
259 Game_DeinitializeAndTerminate(0);
260 TranslateMessage(&Msg);
261 DispatchMessageA(&Msg);
262 }
263 if (dword_6BE364_game_settings_1 & 0x0100 )
264 {
265 WaitMessage();
266 continue;
267 }
268 pGame->_44EEA7();
269 GameUI_WritePointedObjectStatusString();
270 ProcessInputActions();
271 GameUI_MsgProc();
272 if ( pArcomageGame->bGameInProgress )
273 {
274 ArcomageGame::Loop();
275 //LABEL_89:
276 pRenderer->Present();
277 continue;
278 }
279 if (pAsyncMouse)
280 pAsyncMouse->_46B736_consume_click_lists(1);
281 if ( pVideoPlayer->pSmackerMovie && !SmackWait(pVideoPlayer->pSmackerMovie) )
282 {
283 pRenderer->BeginScene();
284 pMouse->DrawCursorToTarget();
285 pVideoPlayer->SmackUpdatePalette(pVideoPlayer->hWindow);
286 pMouse->_469EA4();
287 pRenderer->EndScene();
288 }
289 if ( pVideoPlayer->pBinkMovie && !BinkWait(pVideoPlayer->pBinkMovie) )
290 {
291 pRenderer->BeginScene();
292 pMouse->DrawCursorToTarget();
293 pVideoPlayer->BinkUpdatePalette(pVideoPlayer->hWindow);
294 pMouse->_469EA4();
295 pRenderer->EndScene();
296 }
297 pEventTimer->Update();
298 pMiscTimer->Update();
299 OnTimer(0);
300 GameUI_StatusBar_UpdateTimedString(0);
301 if ( pMiscTimer->bPaused && !pEventTimer->bPaused )
302 pMiscTimer->Resume();
303 if ( pEventTimer->bTackGameTime && !pParty->bTurnBasedModeOn )
304 pEventTimer->bTackGameTime = 0;
305 if ( !pEventTimer->bPaused && !uGameState )
306 {
307 if ( !pEventTimer->bTackGameTime )
308 _494035_timed_effects__water_walking_damage__etc();
309 if ( dword_6BE364_game_settings_1 & 1 )
310 {
311 dword_6BE364_game_settings_1 &= 0xFFFFFFFEu;
312 }
313 else
314 {
315 sub_401A91_AI();
316 sub_46BDC0_UpdateUserInput_and_MapSpecificStuff();
317 }
318 }
319 if ( v16 )
320 {
321 v16 = 0;
322 viewparams->bRedrawGameUI = true;
323 }
324 //pAudioPlayer->_4AAFCF();Ritor1: it's temporarily
325 if (uGameState == 1)
326 //goto LABEL_96;
327 {
328 bLoadinga = 1;
329 continue;
330 }
331 if (uGameState == 2)
332 {
333 pAudioPlayer->StopChannels(-1, -1);
334 PrepareWorld(0);
335 uGameState = 0;
336 continue;
337 }
338 if ( (signed int)uGameState <= 2 )
339 //goto LABEL_85;
340 pGame->Draw();
341 continue;
342 if ( (signed int)uGameState <= 5 || uGameState == 7 )
343 {
344 //LABEL_96:
345 bLoadinga = 1;
346 continue;
347 }
348 if ( uGameState != 8 )
349 {
350 if ( uGameState != 9 )
351 {
352 //LABEL_85:
353 pGame->Draw();
354 continue;
355 }
356 pRenderer->BeginScene();
357 GUI_UpdateWindows();
358 pRenderer->EndScene();
359 //goto LABEL_89;
360 pRenderer->Present();
361 continue;
362 }
363 pAudioPlayer->StopChannels(-1, -1);
364 memset(pParty->pHirelings, 0, 0x4Cu);
365 memset(&pParty->pHirelings[1], 0, 0x4Cu);
366 pNewNPCsCount = 0;
367 if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
368 {
369 pFlags = (char *)&pNPCStats->pNewNPCData[0].uFlags;
370 do
371 {
372 if ( *((int *)pFlags + 6) )
373 *pFlags &= 0x7Fu;
374 ++pNewNPCsCount;
375 pFlags += 76;
376 }
377 while ( pNewNPCsCount < (signed int)pNPCStats->uNumNewNPCs );
378 }
379 pVideoPlayer->PlayDeathMovie();
380 if ( pVideoPlayer->AnyMovieLoaded() )
381 pVideoPlayer->Unload();
382 SaveGame(0, 0);
383 ++pParty->uNumDeaths;
384 pPlayer = pParty->pPlayers;
385 do
386 {
387 pPlayer->SetVariable(VAR_Award, 85);
388 ++pPlayer;
389 }
390 while ( (signed int)pPlayer < (signed int)pParty->pHirelings );
391 pParty->field_764 = 0;
392 pParty->uTimePlayed += 0x276000ui64;
393 LOWORD(pParty->uFlags) &= 0xFDFBu;
394 pParty->SetGold(0);
395 pOtherOverlay = pOtherOverlayList->pOverlays;
396 v8 = 50;
397 do
398 {
399 pOtherOverlay->Reset();
400 ++pOtherOverlay;
401 --v8;
402 }
403 while ( v8 );
404 memset(pParty->pPartyBuffs, 0, 0x140u);
405 pPlayerNum = 1;
406 if ( pParty->bTurnBasedModeOn == 1 )
407 {
408 pTurnEngine->End(1);
409 pParty->bTurnBasedModeOn = 0;
410 }
411 pHealth = &pParty->pPlayers[0].sHealth;//193C
412 do
413 {
414 memset(pHealth - 0x64F, 0, 0xA0u);//(pConditions, 0, 160)
415 memset(pHealth - 0x67, 0, 0x180u);//(pPlayerBuffs[0], 0, 384)
416 *pHealth = 1;
417 pHealth += 1743; //6CF
418 uActiveCharacter = 1;
419 }
420 while ( (signed int)pHealth < (signed int)&pParty->field_871C[567] );
421 if ( (unsigned __int16)_449B57_test_bit(pParty->_award_bits, 136) )
422 {
423 pParty->vPosition.x = -17331; // respawn in harmondale
424 pParty->vPosition.y = 12547;
425 pParty->vPosition.z = 465;
426 pParty->sRotationY = 0;
427 pLocationName = "out02.odm";
428 }
429 else
430 {
431 pParty->vPosition.x = 12552; // respawn on emerald isle
432 pParty->vPosition.y = 1816;
433 pParty->vPosition.z = 0;
434 pParty->sRotationY = 512;
435 pLocationName = "out01.odm";
436 }
437 strcpy(Source, pLocationName);
438 pParty->uFallStartY = pParty->vPosition.z;
439 pParty->sRotationX = 0;
440 pParty->uFallSpeed = 0;
441 pParty->field_6E4 = 0;
442 pParty->field_6E0 = 0;
443 if ( _strcmpi(Source, pCurrentMapName) )
444 {
445 strcpy(pCurrentMapName, Source);
446 _5B65A8_npcdata_uflags_or_other = pParty->vPosition.x;
447 _5B65AC_npcdata_fame_or_other = pParty->vPosition.y;
448 _5B65B0_npcdata_rep_or_other = pParty->vPosition.z;
449 _5B65B4_npcdata_loword_house_or_other = pParty->sRotationY;
450 _5B65B8_npcdata_hiword_house_or_other = pParty->sRotationX;
451 dword_5B65C0 = 1;
452 PrepareWorld(1);
453 }
454 InitializeActors();
455 v11 = 0;
456 do
457 {
458 if ( pPlayers[pPlayerNum]->CanAct() )
459 v17[v11++] = pPlayerNum;
460 ++pPlayerNum;
461 }
462 while ( pPlayerNum <= 4 );
463 if ( v11 )
464 {
465 v12 = rand();
466 pPlayers[v17[v12 % v11]]->PlaySound(99, 0);
467 }
468 ShowStatusBarString(pGlobalTXT_LocalizationStrings[524], 2u);// "Once again you've cheated death!.." "Âû ñíîâà îáõèòðèëè ñìåðòü! …"
469 uGameState = 0;
470 }
471 while ( !bLoadinga );
472 dword_6BE340 = 0;
473 pEventTimer->Pause();
474 ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
475 if ( uGameState == 3 )
476 {
477 sub_491E3A();
478 LoadPlayerPortraintsAndVoices();
479 uGameState = 0;
480 pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
481 bLoading = true;
482 continue;
483 }
484 break;
485 }
486 pCurrentScreen = 16;//îêíî âèäåî ðîëèêà
487 sub_491E3A();
488 }
489
490
491
492 //----- (0044F192) --------------------------------------------------------
493 void Game::PrepareBloodsplats()
494 {
495 for (uint i = 0; i < uNumBloodsplats; ++i)
496 {
497 pBloodsplatContainer->AddBloodsplat(
498 pBloodsplats[i].x,
499 pBloodsplats[i].y,
500 pBloodsplats[i].z,
501 pBloodsplats[i].radius,
502 pBloodsplats[i].r,
503 pBloodsplats[i].g,
504 pBloodsplats[i].b);
505 }
506 }
507
508
509 //----- (0044F120) --------------------------------------------------------
510 void Game::PushStationaryLights(int a2)
511 {
512 signed int v3; // ebx@1
513 char *v4; // esi@2
514
515 auto v2 = this;
516 v3 = 0;
517 if ( (signed int)this->uNumStationaryLights > 0 )
518 {
519 v4 = (char *)&this->pStationaryLights[0].vRGBColor.y;
520 do
521 {
522 pStationaryLightsStack->AddLight(
523 (signed __int64)*((float *)v4 - 4),
524 (signed __int64)*((float *)v4 - 3),
525 (signed __int64)*((float *)v4 - 2),
526 (signed __int64)*((float *)v4 + 2),
527 (signed __int64)*((float *)v4 - 1),
528 (signed __int64)*(float *)v4,
529 (signed __int64)*((float *)v4 + 1),
530 byte_4E94D0);
531 ++v3;
532 v4 += 28;
533 }
534 while ( v3 < (signed int)v2->uNumStationaryLights );
535 }
536 }
537 // 4E94D0: using guessed type char byte_4E94D0;
538
539 //----- (0044F0FD) --------------------------------------------------------
540 void Game::_44F0FD()
541 {
542 ToggleFlags(0x40u);
543
544 if ( !(uFlags & 0x40) )
545 {
546 uNumBloodsplats = 0;
547 field_E0C = 0;
548 }
549 }
550
551 //----- (0044F0D8) --------------------------------------------------------
552 void Game::ToggleFlags(uint uMask)
553 {
554 if (uFlags & uMask)
555 uFlags &= ~uMask;
556 else
557 uFlags |= uMask;
558 }
559
560
561 //----- (0044F07B) --------------------------------------------------------
562 bool Game::_44F07B()
563 {
564 if (!pKeyboardInstance->IsKeyBeingHeld(VK_SHIFT) &&
565 !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) &&
566 !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) ||
567
568 (pKeyboardInstance->WasKeyPressed(VK_F11) == 0 &&
569 pKeyboardInstance->WasKeyPressed(VK_F11)))
570 return true;
571 return false;
572 }
573
574 //----- (0044EEA7) --------------------------------------------------------
575 bool Game::_44EEA7()
576 {
577 //Game *v1; // esi@1
578 double v2; // st7@2
579 float depth; // ST00_4@9
580 bool result; // eax@9
581 unsigned int v5; // eax@14
582 __int64 v6; // kr00_8@21
583 unsigned int y; // [sp+4h] [bp-24h]@2
584 unsigned int x; // [sp+8h] [bp-20h]@2
585 bool v9; // [sp+Ch] [bp-1Ch]@2
586 stru157 *v10; // [sp+10h] [bp-18h]@2
587 stru157 *v11; // [sp+14h] [bp-14h]@2
588 POINT a2; // [sp+20h] [bp-8h]@1
589
590 //v1 = this;
591 ++qword_5C6DF0;
592 pParticleEngine->UpdateParticles();
593 pMouseInstance->GetCursorPos(&a2);
594 if ( sub_4637E0_is_there_popup_onscreen() )
595 {
596 v11 = &a5;
597 v10 = &stru_F93E30;
598 v9 = 0;
599 x = a2.y;
600 y = a2.x;
601 v2 = GetPickDepth();
602 }
603 else
604 {
605 if ( uFlags2 & 0x10 )
606 {
607 v11 = &a5;
608 v10 = &stru_F93E1C;
609 }
610 else
611 {
612 static bool __init_flag = false;
613 static stru157 static_sub_44EEA7_stru157;
614 if (!__init_flag)
615 {
616 __init_flag = true;
617 static_sub_44EEA7_stru157.field_8 = -1;
618 static_sub_44EEA7_stru157.field_0 = 0;
619 static_sub_44EEA7_stru157.field_4 = 2;
620 static_sub_44EEA7_stru157.field_C = 0;
621 static_sub_44EEA7_stru157.field_10 = 0;
622 }
623 v11 = &a5;
624 v10 = &static_sub_44EEA7_stru157;
625 }
626 v2 = 5120.0;
627 v9 = 0;
628 x = a2.y;
629 y = a2.x;
630 }
631 depth = v2;
632
633 PickMouse(depth, y, x, v9, v10, v11);
634 pLightmapBuilder->std__vector_000004_size = 0;
635 pLightmapBuilder->std__vector_183808_size = 0;
636 pDecalBuilder->std__vector_pDecals_size = 0;
637 pDecalBuilder->field_308008 = 0;
638 result = _44F07B();
639 if ( result )
640 {
641 if ( uFlags & 8 )
642 LOBYTE(pStru10Instance->field_4) = 0;
643 if ( pRenderer->pRenderD3D && uCurrentlyLoadedLevelType == LEVEL_Outdoor)
644 {
645 v5 = GetLevelFogColor();
646 pRenderer->uFogColor = v5 & 0xFFFFFF;
647 }
648 if (uFlags & 0x0400)
649 uFlags2 |= 0x01;
650 if ( !pRenderer->pRenderD3D && uCurrentlyLoadedLevelType == LEVEL_Outdoor && pMobileLightsStack->uNumLightsActive )
651 {
652 uFlags2 |= 0x01;
653 field_E10 = qword_5C6DF0;
654 }
655 v6 = qword_5C6DF0 - field_E10;
656 if ( qword_5C6DF0 - field_E10 == 1 )
657 uFlags2 |= v6;
658 if (uNumStationaryLights_in_pStationaryLightsStack != pStationaryLightsStack->uNumLightsActive )
659 {
660 uFlags2 |= 1u;
661 uNumStationaryLights_in_pStationaryLightsStack = pStationaryLightsStack->uNumLightsActive;
662 }
663 _44E904();
664 LOBYTE(result) = 1;
665 }
666 return result;
667 }
668
669
670 //----- (0044EDE4) --------------------------------------------------------
671 bool Game::AlterGamma(BLVFace *pFace, unsigned int *pColor)
672 {
673 if (pGame->uFlags2 & 2 && pFace->uAttributes & 2)
674 {
675 *pColor = ReplaceHSV(*pColor, 1.0, fSaturation, -1.0);
676 return true;
677 }
678 else
679 return false;
680 }
681
682 //----- (0044EE30) --------------------------------------------------------
683 bool Game::_44EE30(ODMFace *a2, int a3)
684 {
685 if (uFlags2 & 0x2 && a2->uAttributes & 0x02)
686 {
687 *(int *)a3 = ReplaceHSV(*(int *)a3, 1.0, fSaturation, -1.0);
688 return true;
689 }
690 else
691 return false;
692 }
693
694
695 //----- (004645FA) --------------------------------------------------------
696 void Game::Deinitialize()
697 {
698 struct tagRECT Rect; // [sp+0h] [bp-10h]@6
699
700 if (pAsyncMouse)
701 pAsyncMouse->Suspend();
702 if (pGame->pKeyboardInstance->bUsingAsynKeyboard && pAsyncKeyboard)
703 pAsyncKeyboard->Suspend();
704 WriteWindowsRegistryInt("startinwindow", pRenderer->bWindowMode);
705 if ( GetWindowRect(hWnd, &Rect) && pRenderer->bWindowMode )
706 {
707 WriteWindowsRegistryInt("window X", Rect.left);
708 WriteWindowsRegistryInt("window Y", Rect.top);
709 }
710 WriteWindowsRegistryInt("debug flags", stru_51076C.registry_debug_flags);
711 WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
712 pItemsTable->Release();
713 pNPCStats->Release();
714 if (pAsyncKeyboard)
715 pAsyncKeyboard->Release();
716 if (pAsyncMouse)
717 pAsyncMouse->Release();
718 if (pMouse)
719 pMouse->Deactivate();
720
721 pAudioPlayer->Release();//error
722 pNew_LOD->FreeSubIndexAndIO();
723 pGames_LOD->FreeSubIndexAndIO();
724 ClipCursor(0);
725 Game::Destroy();
726 }
727
728 //----- (0044EE7C) --------------------------------------------------------
729 bool Game::draw_debug_outlines()
730 {
731 if (uFlags & 0x04)
732 {
733 pLightmapBuilder->DrawDebugOutlines(-1);
734 pDecalBuilder->DrawDecalDebugOutlines();
735 }
736 return true;
737 }
738
739 //----- (0044EC23) --------------------------------------------------------
740 int Game::_44EC23(stru148 *a2, int *a3, signed int a4)
741 {
742 double v4; // st7@4
743 //double v5; // ST00_8@4
744 signed int v6; // eax@5
745 //double v7; // ST00_8@6
746 signed int result; // eax@8
747 //double v9; // ST00_8@9
748 //double v10; // ST00_8@11
749 float a2a; // [sp+14h] [bp+8h]@4
750 float a3a; // [sp+18h] [bp+Ch]@4
751 float a3b; // [sp+18h] [bp+Ch]@6
752 float a4a; // [sp+1Ch] [bp+10h]@9
753 float a4b; // [sp+1Ch] [bp+10h]@11
754
755 if ( this->uFlags2 & 2 && a2->field_59 == 5 && a2->pODMFace->uAttributes & 2 )
756 {
757 v4 = (double)a4;
758 a2a = v4;
759 *a3 |= 2u;
760 a3a = (1.0 - this->fSaturation) * v4;
761 //v5 = a3a + 6.7553994e15;
762 //if ( SLODWORD(v5) >= 0 )
763 if (floorf(a3a + 0.5f) >= 0 )
764 {
765 a3b = (1.0 - this->fSaturation) * a2a;
766 //v7 = a3b + 6.7553994e15;
767 //v6 = LODWORD(v7);
768 v6 = floorf(a3b + 0.5f);
769 }
770 else
771 {
772 v6 = 0;
773 }
774 if ( a4 >= v6 )
775 {
776 a4a = (1.0 - fSaturation) * a2a;
777 //v9 = a4a + 6.7553994e15;
778 //if ( SLODWORD(v9) >= 0 )
779 if (floorf(a4a + 0.5f) >= 0)
780 {
781 a4b = (1.0 - fSaturation) * a2a;
782 //v10 = a4b + 6.7553994e15;
783 //result = LODWORD(v10);
784 result = floorf(a4b + 0.5f);
785 }
786 else
787 {
788 result = 0;
789 }
790 }
791 else
792 {
793 result = a4;
794 }
795 }
796 else
797 {
798 result = -1;
799 }
800 return result;
801 }
802
803
804
805 //----- (00465C8B) --------------------------------------------------------
806 Game *Game::Create()
807 {
808 return new Game;
809 }
810
811 //----- (00465CF3) --------------------------------------------------------
812 void Game::Destroy()
813 {
814 if (pGame)
815 delete pGame;
816 pGame = nullptr;
817 }
818
819 //----- (0044ED0A) --------------------------------------------------------
820 signed int Game::_44ED0A(BLVFace *a2, int *a3, signed int a4)
821 {
822 double v4; // st7@3
823 //double v5; // ST00_8@3
824 signed int v6; // eax@4
825 //double v7; // ST00_8@5
826 signed int result; // eax@7
827 //double v9; // ST00_8@8
828 //double v10; // ST00_8@10
829 float v11; // [sp+14h] [bp+8h]@3
830 float v12; // [sp+18h] [bp+Ch]@3
831 float v13; // [sp+18h] [bp+Ch]@5
832 float v14; // [sp+1Ch] [bp+10h]@8
833 float v15; // [sp+1Ch] [bp+10h]@10
834
835 if ( this->uFlags2 & 2 && a2->uAttributes & 2 )
836 {
837 v4 = (double)a4;
838 v11 = v4;
839 *a3 |= 2u;
840 v12 = (1.0 - this->fSaturation) * v4;
841 //v5 = v12 + 6.7553994e15;
842 if (floorf(v12 + 0.5f)/* SLODWORD(v5)*/ >= 0 )
843 {
844 v13 = (1.0 - this->fSaturation) * v11;
845 //v7 = v13 + 6.7553994e15;
846 //v6 = LODWORD(v7);
847 v6 = floorf(v13 + 0.5f);
848 }
849 else
850 {
851 v6 = 0;
852 }
853 if ( a4 >= v6 )
854 {
855 v14 = (1.0 - fSaturation) * v11;
856 //v9 = v14 + 6.7553994e15;
857 if (floorf(v14 + 0.5f)/* SLODWORD(v9)*/ >= 0 )
858 {
859 v15 = (1.0 - fSaturation) * v11;
860 //v10 = v15 + 6.7553994e15;
861 //result = LODWORD(v10);
862 result = floorf(v15 + 0.5f);
863 }
864 else
865 {
866 result = 0;
867 }
868 }
869 else
870 {
871 result = a4;
872 }
873 }
874 else
875 {
876 result = -1;
877 }
878 return result;
879 }
880
881
882 //----- (0044E4B7) --------------------------------------------------------
883 Game::Game()
884 {
885 uNumStationaryLights = 0;
886 uNumBloodsplats = 0;
887 field_E0C = 0;
888 field_E10 = 0;
889 uNumStationaryLights_in_pStationaryLightsStack = 0;
890 bGammaControlInitialized = false;
891 uFlags = 0;
892 uFlags2 = 0;
893 uSomeGammaStartTime = 0;
894 uSomeGammaDeltaTime = 0;
895
896 pThreadWardInstance = new ThreadWard;
897 pParticleEngine = new ParticleEngine;
898 pMouse = pMouseInstance = new Mouse(pThreadWardInstance);
899 pLightmapBuilder = new LightmapBuilder;
900 pVisInstance = new Vis;
901 pStru6Instance = new stru6;
902 pIndoorCameraD3D = new IndoorCameraD3D;
903 pStru9Instance = new stru9;
904 pStru10Instance = new stru10;
905 pStru11Instance = new stru11;
906 pStru12Instance = new stru12(pStru11Instance);
907 pCShow = new CShow;
908 pKeyboardInstance = new Keyboard;
909 pGammaController = new GammaController;
910
911 uFlags |= 0x0800;
912 uFlags2 |= 0x24;
913
914 _44F0FD();
915
916 bWinNT4_0 = false;
917 if (pVersion->pVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
918 pVersion->pVersionInfo.dwMajorVersion == 4)
919 bWinNT4_0 = true;
920 }
921
922 //----- (0044E7F3) --------------------------------------------------------
923 Game::~Game()
924 {
925 if (pGammaController)
926 delete pGammaController;
927 if (pKeyboardInstance)
928 delete pKeyboardInstance;
929 if (pCShow)
930 delete pCShow;
931 if (pStru12Instance)
932 delete pStru12Instance;
933 if (pStru11Instance)
934 delete pStru11Instance;
935 if (pStru10Instance)
936 delete pStru10Instance;
937 if (pStru9Instance)
938 delete pStru9Instance;
939 if (pIndoorCameraD3D)
940 delete pIndoorCameraD3D;
941 if (pStru6Instance)
942 delete pStru6Instance;
943 if (pVisInstance)
944 delete pVisInstance;
945 if (pLightmapBuilder)
946 delete pLightmapBuilder;
947 if (pMouseInstance)
948 delete pMouseInstance;
949 if (pParticleEngine)
950 delete pParticleEngine;
951 if (pThreadWardInstance)
952 delete pThreadWardInstance;
953 }
954
955 //----- (0044E904) --------------------------------------------------------
956 void Game::_44E904()
957 {
958 //Game *v1; // esi@1
959 unsigned __int64 v2; // qax@1
960 unsigned int v3; // ecx@1
961 int v4; // edi@1
962 unsigned __int8 v5; // cf@7
963 double v6; // st7@13
964 double v7; // st7@15
965 signed __int64 v8; // [sp+Ch] [bp-8h]@1
966
967 //v1 = this;
968 v2 = pEventTimer->Time();
969 v4 = (v2 - uSomeGammaStartTime) >> 32;
970 v3 = v2 - LODWORD(uSomeGammaStartTime);
971 v8 = v2 - uSomeGammaStartTime;
972 if ( v4 < 0
973 || SHIDWORD(v2) < ((unsigned int)v2 < LODWORD(uSomeGammaStartTime)) + HIDWORD(uSomeGammaStartTime) | v4 == 0
974 && v3 <= 0x80 )
975 {
976 if ( v4 > 0 || v4 >= 0 )
977 goto LABEL_12;
978 v3 = 0;
979 v4 = 0;
980 }
981 else
982 {
983 if ( uSomeGammaDeltaTime )
984 {
985 LODWORD(uSomeGammaDeltaTime) = 0;
986 HIDWORD(uSomeGammaDeltaTime) = 0;
987 }
988 else
989 {
990 LODWORD(uSomeGammaDeltaTime) = v3;
991 HIDWORD(uSomeGammaDeltaTime) = v4;
992 }
993 v5 = __CFADD__(v3, -128);
994 v3 -= 128;
995 v4 = v5 + v4 - 1;
996 }
997 uSomeGammaStartTime = v2;
998 v8 = __PAIR__(v4, v3);
999 LABEL_12:
1000 if ( uSomeGammaDeltaTime )
1001 v6 = (double)(signed __int64)(uSomeGammaDeltaTime - __PAIR__(v4, v3));
1002 else
1003 v6 = (double)v8;
1004 v7 = v6 * 0.0078125;
1005 if ( v7 < 0.0 || v7 <= 1.0 )
1006 {
1007 if ( v7 < 0.0 )
1008 v7 = 0.0;
1009 }
1010 else
1011 {
1012 v7 = 1.0;
1013 }
1014 if ( pRenderer->pRenderD3D )
1015 fSaturation = v7;
1016 else
1017 fSaturation = (1.0 - 0.5) * v7 + 0.5;
1018 }
1019
1020 //----- (0044EA17) --------------------------------------------------------
1021 bool Game::InitializeGammaController()
1022 {
1023 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
1024 pVersion->pVersionInfo.dwMajorVersion != 4 )
1025 pGammaController->InitializeFromSurface(pRenderer->pFrontBuffer4);
1026
1027 bGammaControlInitialized = true;
1028 uSomeGammaStartTime = pEventTimer->Time();
1029 return true;
1030 }
1031
1032 //----- (0044EA5E) --------------------------------------------------------
1033 char Game::PickMouse(float fPickDepth, unsigned int uMouseX, unsigned int uMouseY, bool bOutline, stru157 *a5, stru157 *a6)
1034 {
1035 char result; // al@3
1036 std::string v10; // [sp-4h] [bp-24h]@5
1037 float v11; // [sp+4h] [bp-1Ch]@10
1038 float v12; // [sp+8h] [bp-18h]@10
1039 const char *v13; // [sp+Ch] [bp-14h]@5
1040 int v14; // [sp+10h] [bp-10h]@5
1041 std::string *v15; // [sp+18h] [bp-8h]@5
1042 int a3; // [sp+1Fh] [bp-1h]@5
1043
1044 auto v7 = this;
1045 if (!pCurrentScreen && pRenderer->pRenderD3D)
1046 {
1047 if (!pVisInstance)
1048 {
1049 MessageBoxW(nullptr, L"The 'Vis' object pointer has not been instatiated, but CGame::Pick() is trying to call through it.", nullptr, 0);
1050 ExitProcess(0);
1051 }
1052
1053 if ( (signed int)uMouseX >= (signed int)pViewport->uScreenX
1054 && (signed int)uMouseX <= (signed int)pViewport->uScreenZ
1055 && (signed int)uMouseY >= (signed int)pViewport->uScreenY
1056 && (signed int)uMouseY <= (signed int)pViewport->uScreenW )
1057 {
1058 v14 = (int)a6;
1059 v12 = (double)(signed int)uMouseY;
1060 v11 = (double)(signed int)uMouseX;
1061 pVisInstance->PickMouse(fPickDepth, v11, v12, a5, a6);
1062
1063 if (bOutline)
1064 OutlineSelection();
1065 }
1066 return true;
1067 }
1068 return false;
1069 }
1070 // 4E28F8: using guessed type int pCurrentScreen;
1071
1072 //----- (0044EB12) --------------------------------------------------------
1073 bool Game::_44EB12(bool bOutline, stru157 *a3, stru157 *a4)
1074 {
1075 if ( !pCurrentScreen && pVisInstance && pRenderer->pRenderD3D )
1076 {
1077 bool r = pVisInstance->_4C05CC(&pVisInstance->stru1, a3, a4);
1078
1079 if (bOutline)
1080 OutlineSelection();
1081 return r;
1082 }
1083 return false;
1084 }
1085 // 4E28F8: using guessed type int pCurrentScreen;
1086
1087 //----- (0044EB5A) --------------------------------------------------------
1088 void Game::OutlineSelection()
1089 {
1090 Vis *v1; // eax@1
1091 Vis_stru1_stru0 *v2; // eax@3
1092 void *v3; // edx@9
1093 int v4; // eax@10
1094 int v5; // eax@11
1095 int v6; // eax@14
1096 int v7; // eax@15
1097 const char *v9; // [sp-8h] [bp-14h]@8
1098 int v10; // [sp-4h] [bp-10h]@8
1099 char v11; // [sp+0h] [bp-Ch]@18
1100 int a3; // [sp+Ah] [bp-2h]@8
1101
1102 v1 = this->pVisInstance;
1103 if ( v1 )
1104 {
1105 v2 = (Vis_stru1_stru0 *)((signed int)v1->stru1.uNumPointers <= 0 ? 0 : v1->stru1.array_1804[0]);
1106 if ( v2 )
1107 {
1108 if ( v2->uObjectType == 1 )
1109 {
1110 MessageBoxW(nullptr, L"Sprite outline currently Unsupported", nullptr, 0);
1111 ExitProcess(0);
1112 }
1113
1114 if ( v2->uObjectType == 2 )
1115 {
1116 v3 = v2->pObjectInfo; // TODO 2 objects for indoor/outdoor
1117 // some clues in header for Vis_stru1_stru0
1118 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
1119 {
1120 v4 = *((int *)v3 + 11);
1121 if ( v4 & 0x10000 )
1122 v5 = v4 & 0xFFFEFFFF;
1123 else
1124 v5 = v4 | 0x10000;
1125 *((int *)v3 + 11) = v5;
1126 }
1127 else
1128 {
1129 v6 = *((int *)v3 + 7);
1130 if ( v6 & 0x10000 )
1131 v7 = v6 & 0xFFFEFFFF;
1132 else
1133 v7 = v6 | 0x10000;
1134 *((int *)v3 + 7) = v7;
1135 }
1136 }
1137 else
1138 {
1139 MessageBoxW(nullptr, L"Undefined CObjectInfo type requested in CGame::outline_selection()", nullptr, 0);
1140 ExitProcess(0);
1141 }
1142 }
1143 }
1144 }