forked from 1dot13/source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameloop.cpp
670 lines (554 loc) · 19.9 KB
/
gameloop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
#include <stdio.h>
#include <time.h>
#include "sgp.h"
#include "Gameloop.h"
#include "Screens.h"
#include "cursors.h"
#include "init.h"
#include "music control.h"
#include "sys globals.h"
#include "laptop.h"
#include "mapscreen.h"
#include "Game Clock.h"
#include "Timer Control.h"
#include "overhead.h"
#include "LibraryDataBase.h"
#include "Map Screen Interface.h"
#include "Tactical Save.h"
#include "Interface.h"
#include "GameSettings.h"
#include "mapscreen.h"
#include "Interface Control.h"
#include "text.h"
#include "HelpScreen.h"
#include "PreBattle Interface.h"
#include "Tactical Placement GUI.h"//dnl ch45 071009
#include "Map Screen Interface Map Inventory.h"//dnl ch51 081009
#include "World Items.h"//dnl ch77 191113
#include "Overhead.h" // added by Flugente
#include "Ambient Control.h" // sevenfm
#include "SaveLoadScreen.h"
#include "Lua Interpreter.h"
//**ddd direct link libraries
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "gdi32.lib")
#pragma comment (lib, "advapi32.lib")
#pragma comment (lib, "shell32.lib")
#ifdef JA2UB
#include "ub_config.h"
#endif
// rain
#include "Rain.h"
// end rain
// arynn : render mouse regions
#include "line.h"
//network headers
#include "connect.h"
UINT32 guiCurrentScreen;
UINT32 guiPendingScreen = NO_PENDING_SCREEN;
UINT32 guiPreviousScreen = NO_PENDING_SCREEN;
INT32 giStartingMemValue = 0;
#define DONT_CHECK_FOR_FREE_SPACE 255
UINT8 gubCheckForFreeSpaceOnHardDriveCount=DONT_CHECK_FOR_FREE_SPACE;
extern BOOLEAN DoSkiMessageBox( UINT8 ubStyle, STR16 zString, UINT32 uiExitScreen, UINT8 ubFlags, MSGBOX_CALLBACK ReturnCallback );
extern void NotEnoughHardDriveSpaceForQuickSaveMessageBoxCallBack( UINT8 bExitValue );
extern BOOLEAN gfTacticalPlacementGUIActive;
extern BOOLEAN gfTacticalPlacementGUIDirty;
extern BOOLEAN gfValidLocationsChanged;
extern BOOLEAN gfInMsgBox;
extern BOOLEAN gfInChatBox; // OJW - 20090314 - new chatbox
extern void InitSightRange(); //lal
// callback to confirm game is over
void EndGameMessageBoxCallBack( UINT8 bExitValue );
void HandleNewScreenChange( UINT32 uiNewScreen, UINT32 uiOldScreen );
// The InitializeGame function is responsible for setting up all data and Gaming Engine
// tasks which will run the game
#ifdef JA2BETAVERSION
BOOLEAN gubReportMapscreenLock = 0;
void ReportMapscreenErrorLock()
{
switch( gubReportMapscreenLock )
{
case 1:
DoScreenIndependantMessageBox( L"You have just loaded the game which is in a state that you shouldn't be able to. You can still play, but there should be a sector with enemies co-existing with mercs. Please don't report that.", MSG_BOX_FLAG_OK, NULL );
fDisableDueToBattleRoster = FALSE;
fDisableMapInterfaceDueToBattle = FALSE;
gubReportMapscreenLock = 0;
break;
case 2:
DoScreenIndependantMessageBox( L"You have just saved the game which is in a state that you shouldn't be able to. Please report circumstances (ex: merc in other sector pipes up about enemies), etc. Autocorrected, but if you reload the save, don't report the error appearing in load.", MSG_BOX_FLAG_OK, NULL );
fDisableDueToBattleRoster = FALSE;
fDisableMapInterfaceDueToBattle = FALSE;
gubReportMapscreenLock = 0;
break;
}
}
#endif
BOOLEAN InitializeGame(void)
{
UINT32 uiIndex;
giStartingMemValue = MemGetFree( );
//InitializeLua();
is_networked = FALSE;
is_client = FALSE;
is_server = FALSE;
// Set up the debugging topics
//
// Turn off all the flags
ClearAllDebugTopics();
//
// Now turn on the ones we are interested in watching
RegisterJA2DebugTopic( TOPIC_JA2OPPLIST, "Reg" );
RegisterJA2DebugTopic( TOPIC_JA2INTERRUPT, "Reg" );
// Snap: Read options from an INI file in the default of custom Data directory
// Moved this up because some settings are used during other inits
LoadGameAPBPConstants();
LoadGameExternalOptions();
// Load new ini - SANDRO
LoadSkillTraitsExternalSettings();
// HEADROCK HAM 4: Read CTH values
LoadCTHConstants();
//DBrot: load mod settings
LoadModSettings();
// silversurfer: load item settings modifiers
LoadItemSettings();
// Load externalised taunts settings
LoadTauntsSettings();
// Load helicopter repair settings
LoadHelicopterRepairRefuelSettings();
// Load externalised morale settings
LoadMoraleSettings();
// Load externalised reputation settings
LoadReputationSettings();
// Load creatures settings
LoadCreaturesSettings();
// Load rebel command settings
LoadRebelCommandSettings();
#ifdef JA2UB
LoadGameUBOptions(); // JA25 UB
#endif
InitSightRange(); //lal
// Initlaize mouse subsystems
MSYS_Init( );
InitButtonSystem();
InitCursors( );
SetFastForwardPeriod(gGameExternalOptions.iFastForwardPeriod);
SetFastForwardKey(gGameExternalOptions.iFastForwardKey);
SetNotifyFrequencyKey(gGameExternalOptions.iNotifyFrequency);
SetClockSpeedPercent(gGameExternalOptions.fClockSpeedPercent);
// Init Fonts
if ( !InitializeFonts( ) )
{
// Send debug message and quit
DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "COULD NOT INUT FONT SYSTEM...");
return( ERROR_SCREEN );
}
//Deletes all the Temp files in the Maps\Temp directory
InitTacticalSave( TRUE );
// Initialize Game Screens.
for (uiIndex = 0; uiIndex < MAX_SCREENS; uiIndex++)
{
if ((*(GameScreens[uiIndex].InitializeScreen))() == FALSE)
{ // Failed to initialize one of the screens.
return FALSE;
}
}
//Init the help screen system
InitHelpScreenSystem();
//LoadSavegame Slot
LoadSaveGameOldOrNew();
//Loads the saved (if any) general JA2 game settings
LoadGameSettings();
LoadFeatureFlags();
guiCurrentScreen = INIT_SCREEN;
return TRUE;
}
// The ShutdownGame function will free up/undo all things that were started in InitializeGame()
// It will also be responsible to making sure that all Gaming Engine tasks exit properly
void ShutdownGame(void)
{
// handle shutdown of game with respect to preloaded mapscreen graphics
HandleRemovalOfPreLoadedMapGraphics( );
ShutdownJA2( );
//Save the general save game settings to disk
SaveGameSettings();
SaveFeatureFlags();
//shutdown the file database manager
ShutDownFileDatabase( );
if(gGameExternalOptions.fEnableInventoryPoolQ)//dnl ch51 081009
MemFreeInventoryPoolQ();
//Deletes all the Temp files in the Maps\Temp directory
InitTacticalSave( FALSE );
//ShutdownLua( );
FreeGameExternalOptions();
}
// This is the main Gameloop. This should eventually be one big switch statement which represents
// the state of the game (i.e. Main Menu, PC Generation, Combat loop, etc....)
// This function exits constantly and reenters constantly
// rain
static BOOLEAN gfSkipFrame = FALSE;
extern void RefreshBoxes( );
void GameLoop(void)
{
// DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop");
InputAtom InputEvent;
POINT MousePos;
UINT32 uiOldScreen=guiCurrentScreen;
clock_t startTime = clock(); // decrease CPU load patch from defrog
if(_LeftButtonDown | _RightButtonDown)//dnl ch77 191113 to prevent memory corruption during resize
ResizeWorldItems();
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: get mouse position");
GetCursorPos(&MousePos);
ScreenToClient(ghWindow, &MousePos); // In window coords!
// Hook into mouse stuff for MOVEMENT MESSAGES
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: get mouse hook");
MouseSystemHook(MOUSE_POS, (UINT16)MousePos.x ,(UINT16)MousePos.y ,_LeftButtonDown, _RightButtonDown);
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: get music");
MusicPoll( FALSE );
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: check for mouse events");
//*** dddd
//while (DequeueSpecificEvent(&InputEvent, LEFT_BUTTON_REPEAT|RIGHT_BUTTON_REPEAT|LEFT_BUTTON_DOWN|LEFT_BUTTON_UP|RIGHT_BUTTON_DOWN|RIGHT_BUTTON_UP ) == TRUE )
while (DequeueSpecificEvent(&InputEvent,
LEFT_BUTTON_REPEAT|RIGHT_BUTTON_REPEAT|
LEFT_BUTTON_DOWN|LEFT_BUTTON_UP|MIDDLE_BUTTON_UP|X1_BUTTON_UP|X2_BUTTON_UP|
RIGHT_BUTTON_DOWN|RIGHT_BUTTON_UP|MIDDLE_BUTTON_DOWN|X1_BUTTON_DOWN|X2_BUTTON_DOWN|
MOUSE_WHEEL_UP|MOUSE_WHEEL_DOWN) == TRUE )
{
// HOOK INTO MOUSE HOOKS
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("GameLoop: mouse event %d", InputEvent.usEvent ));
MouseSystemHook(InputEvent.usEvent, (UINT16)MousePos.x ,(UINT16)MousePos.y ,_LeftButtonDown, _RightButtonDown);
/* switch(InputEvent.usEvent)
{
case LEFT_BUTTON_DOWN:
MouseSystemHook(LEFT_BUTTON_DOWN, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown);
break;
case LEFT_BUTTON_UP:
MouseSystemHook(LEFT_BUTTON_UP, (INT16)MousePos.x, (INT16)MousePos.y ,_LeftButtonDown, _RightButtonDown);
break;
case RIGHT_BUTTON_DOWN:
MouseSystemHook(RIGHT_BUTTON_DOWN, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown);
break;
case RIGHT_BUTTON_UP:
MouseSystemHook(RIGHT_BUTTON_UP, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown);
break;
case LEFT_BUTTON_REPEAT:
MouseSystemHook(LEFT_BUTTON_REPEAT, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown);
break;
case RIGHT_BUTTON_REPEAT:
MouseSystemHook(RIGHT_BUTTON_REPEAT, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown);
break;
}*/
}
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: check for errors");
if ( gfGlobalError )
{
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: global error");
guiCurrentScreen = ERROR_SCREEN;
}
/*
// Madd: removed check because it kept coming up for me, even on new games, even though I have 12GB free!! I think the "DoesUserHaveEnoughHardDriveSpace" function is busted.
//if we are to check for free space on the hard drive
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: check hard drive");
if( gubCheckForFreeSpaceOnHardDriveCount < DONT_CHECK_FOR_FREE_SPACE )
{
//only if we are in a screen that can get this check
if( guiCurrentScreen == MAP_SCREEN || guiCurrentScreen == GAME_SCREEN || guiCurrentScreen == SAVE_LOAD_SCREEN )
{
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: check for free hard drive space");
if( gubCheckForFreeSpaceOnHardDriveCount < 1 )
{
gubCheckForFreeSpaceOnHardDriveCount++;
}
else
{
// Make sure the user has enough hard drive space
if( !DoesUserHaveEnoughHardDriveSpace() )
{
CHAR16 zText[512];
CHAR16 zSpaceOnDrive[512];
UINT32 uiSpaceOnDrive;
CHAR16 zSizeNeeded[512];
swprintf( zSizeNeeded, L"%d", REQUIRED_FREE_SPACE / BYTESINMEGABYTE );
InsertCommasForDollarFigure( zSizeNeeded );
uiSpaceOnDrive = GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( );
swprintf( zSpaceOnDrive, L"%.2f", uiSpaceOnDrive / (FLOAT)BYTESINMEGABYTE );
swprintf( zText, pMessageStrings[ MSG_LOWDISKSPACE_WARNING ], zSpaceOnDrive, zSizeNeeded );
if( guiPreviousOptionScreen == MAP_SCREEN )
DoMapMessageBox( MSG_BOX_BASIC_STYLE, zText, MAP_SCREEN, MSG_BOX_FLAG_OK, NULL );
else
DoMessageBox( MSG_BOX_BASIC_STYLE, zText, GAME_SCREEN, MSG_BOX_FLAG_OK, NULL, NULL );
}
gubCheckForFreeSpaceOnHardDriveCount = DONT_CHECK_FOR_FREE_SPACE;
}
}
}
*/
// ATE: Force to be in message box screen!
if ( gfInMsgBox )
{
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: message box");
guiPendingScreen = MSG_BOX_SCREEN;
}
// OJW - 20090314 - new chatbox
if (gfInChatBox)
{
guiPendingScreen = MP_CHAT_SCREEN;
}
if ( guiPendingScreen != NO_PENDING_SCREEN )
{
// Based on active screen, deinit!
if( guiPendingScreen != guiCurrentScreen )
{
switch( guiCurrentScreen )
{
case MAP_SCREEN:
if( guiPendingScreen != MSG_BOX_SCREEN && guiPendingScreen != MP_CHAT_SCREEN )
{
EndMapScreen( FALSE );
}
break;
case LAPTOP_SCREEN:
ExitLaptop();
break;
}
}
// if the screen has chnaged
if( uiOldScreen != guiPendingScreen )
{
// Set the fact that the screen has changed
uiOldScreen = guiPendingScreen;
HandleNewScreenChange( guiPendingScreen, guiCurrentScreen );
}
guiCurrentScreen = guiPendingScreen;
guiPendingScreen = NO_PENDING_SCREEN;
}
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: screen changed");
AssertNotNIL (GameScreens[guiCurrentScreen].HandleScreen);
uiOldScreen = (*(GameScreens[guiCurrentScreen].HandleScreen))();
// if the screen has changed
if( uiOldScreen != guiCurrentScreen )
{
HandleNewScreenChange( uiOldScreen, guiCurrentScreen );
guiPreviousScreen = guiCurrentScreen;
guiCurrentScreen = uiOldScreen;
}
// rain
RenderRain();
// sevenfm: update tactical ambients
if (guiCurrentScreen == GAME_SCREEN)
{
UpdateFireAmbient();
}
// Flugente: dynamic opinions: Dialogue Boxes need to be refreshed
if (gGameExternalOptions.fDynamicOpinions)
{
RefreshBoxes();
}
// Flugente:disguised mercs can distract enemies by talking to them. In order to display that, we sometimes display excerpts of their 'chats'
CheckChatPartners();
//DEBUG MODE : DEBUG RENDER ENTRY : point to drop in debugging render code
if( (gGameSettings.fOptions[TOPTION_RETAIN_DEBUG_OPTIONS_IN_RELEASE]) || (JA2BETAVERSION_FLAG))
{
// arynn : render mouse regions
if(gGameSettings.fOptions[TOPTION_RENDER_MOUSE_REGIONS])
{
MOUSE_REGION *curr;
UINT32 uiDestPitchBYTES;
UINT8 *pDestBuf;
curr = get_first_entry_in_MSYS_RegList();
while((curr != NULL) )
{
pDestBuf = LockVideoSurface( FRAME_BUFFER, &uiDestPitchBYTES );
SetClippingRegionAndImageWidth( uiDestPitchBYTES, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
LineDraw( TRUE, curr->RegionTopLeftX, curr->RegionTopLeftY,
curr->RegionBottomRightX, curr->RegionBottomRightY,
Get16BPPColor( FROMRGB( 200, 200, 200 )), pDestBuf);
RectangleDraw( TRUE, curr->RegionTopLeftX, curr->RegionTopLeftY,
curr->RegionBottomRightX, curr->RegionBottomRightY,
Get16BPPColor( FROMRGB( 200, 200, 200 )), pDestBuf);
curr = get_next_entry_in_MSYS_RegList(curr);
UnLockVideoSurface( FRAME_BUFFER );
}
}
}
else
{
//when coming from a recent debug.exe to a rel.exe, and option to carry over debug functions is off, disable debug mode options
gGameSettings.fOptions[TOPTION_RENDER_MOUSE_REGIONS] = FALSE;
}
if( gfSkipFrame )
gfSkipFrame = FALSE;
else
// end rain
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: refresh screen");
RefreshScreen( NULL );
guiGameCycleCounter++;
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop: update clock");
UpdateClock();
#ifdef JA2BETAVERSION
if( gubReportMapscreenLock )
{
ReportMapscreenErrorLock();
}
#endif
// WANNE: Removed Low CPU option
/*
if( gGameSettings.fOptions[ TOPTION_LOW_CPU_USAGE ] == TRUE )
{
// decrease CPU load patch from MTX (http://www.ja-galaxy-forum.com/board/ubbthreads.php/ubb/showflat/Number/102405/page/1#Post102405)
//OK! 12% CPU:
//Sleep(10);
// decrease CPU load patch from defrog
clock_t endTime = clock();
//long sleeptime = 33 - (endTime-startTime)/(CLK_TCK/1000);
long sleeptime = 33 - (endTime-startTime);
if( sleeptime > 0 )
Sleep(sleeptime);
}
*/
if ( is_networked )
{
client_packet();
server_packet();
}
//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"GameLoop done");
}
void SetCurrentScreen( UINT32 uiNewScreen )
{
guiCurrentScreen = uiNewScreen;
(*(GameScreens[guiCurrentScreen].HandleScreen))();
}
void SetPendingNewScreen( UINT32 uiNewScreen )
{
guiPendingScreen = uiNewScreen;
}
// rain
extern UINT32 guiRainLoop;
// end rain
// sevenfm
extern UINT32 guiCurrentSteadyStateSoundHandle;
// Gets called when the screen changes, place any needed in code in here
void HandleNewScreenChange( UINT32 uiNewScreen, UINT32 uiOldScreen )
{
//if we are not going into the message box screen, and we didnt just come from it
if( ( uiNewScreen != MSG_BOX_SCREEN && uiOldScreen != MSG_BOX_SCREEN && uiNewScreen != MP_CHAT_SCREEN && uiOldScreen != MP_CHAT_SCREEN ) )
{
//reset the help screen
NewScreenSoResetHelpScreen( );
}
//rain
if( uiNewScreen == MAP_SCREEN )
{
if ( guiRainLoop != NO_SAMPLE )
{
SoundStop( guiRainLoop );
guiRainLoop = NO_SAMPLE;
}
}
// end rain
// sevenfm: start/stop SSA
if (uiNewScreen == GAME_SCREEN)
{
// check that no sound is playing currently
if (guiCurrentSteadyStateSoundHandle == NO_SAMPLE)
{
SetSSA();
}
}
else if (uiNewScreen != MSG_BOX_SCREEN)
{
// Stop SSA
if (guiCurrentSteadyStateSoundHandle != NO_SAMPLE)
{
SoundStop(guiCurrentSteadyStateSoundHandle);
guiCurrentSteadyStateSoundHandle = NO_SAMPLE;
}
// stop ambients
StopFireAmbient();
}
}
void HandleShortCutExitState( void )
{
// look at the state of fGameIsRunning, if set false, then prompt user for confirmation
// use YES/NO Pop up box, settup for particular screen
SGPRect pCenteringRect= {0 + xResOffset, 0, SCREEN_WIDTH - xResOffset, INV_INTERFACE_START_Y };
if( guiCurrentScreen == ERROR_SCREEN )
{ //an assert failure, don't bring up the box!
gfProgramIsRunning = FALSE;
return;
}
if( guiCurrentScreen == AUTORESOLVE_SCREEN )
{
DoMessageBox( MSG_BOX_BASIC_STYLE, pMessageStrings[ MSG_EXITGAME ], guiCurrentScreen, ( MSG_BOX_FLAG_YESNO | MSG_BOX_FLAG_USE_CENTERING_RECT ), EndGameMessageBoxCallBack, &pCenteringRect );
return;
}
/// which screen are we in?
if ( (guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN ) )
{
// set up for mapscreen
DoMapMessageBox( MSG_BOX_BASIC_STYLE, pMessageStrings[ MSG_EXITGAME ], MAP_SCREEN, MSG_BOX_FLAG_YESNO, EndGameMessageBoxCallBack );
}
else if( guiCurrentScreen == LAPTOP_SCREEN )
{
// set up for laptop
DoLapTopSystemMessageBox( MSG_BOX_LAPTOP_DEFAULT, pMessageStrings[ MSG_EXITGAME ], LAPTOP_SCREEN, MSG_BOX_FLAG_YESNO, EndGameMessageBoxCallBack );
}
else if( guiCurrentScreen == SHOPKEEPER_SCREEN )
{
DoSkiMessageBox( MSG_BOX_BASIC_STYLE, pMessageStrings[ MSG_EXITGAME ], SHOPKEEPER_SCREEN, MSG_BOX_FLAG_YESNO, EndGameMessageBoxCallBack );
}
else
{
// check if error or editor
#ifdef JA2BETAVERSION
if ( guiCurrentScreen == AIVIEWER_SCREEN || guiCurrentScreen == QUEST_DEBUG_SCREEN )
{
// then don't prompt
gfProgramIsRunning = FALSE;
return;
}
#endif
if( ( guiCurrentScreen == ERROR_SCREEN ) || ( guiCurrentScreen == EDIT_SCREEN ) || ( guiCurrentScreen == DEBUG_SCREEN ) )
{
// then don't prompt
gfProgramIsRunning = FALSE;
return;
}
// set up for all otherscreens
DoMessageBox( MSG_BOX_BASIC_STYLE, pMessageStrings[ MSG_EXITGAME ], guiCurrentScreen, ( UINT8 ) ( MSG_BOX_FLAG_YESNO | MSG_BOX_FLAG_USE_CENTERING_RECT ), EndGameMessageBoxCallBack, &pCenteringRect );
}
}
void EndGameMessageBoxCallBack( UINT8 bExitValue )
{
// yes, so start over, else stay here and do nothing for now
if( bExitValue == MSG_BOX_RETURN_YES )
{
gfProgramIsRunning = FALSE;
}
//If we are in the tactical placement gui, we need this flag set so the interface is updated.
if( gfTacticalPlacementGUIActive )
{
gfTacticalPlacementGUIDirty = TRUE;
gfValidLocationsChanged = TRUE;
}
return;
}
void NextLoopCheckForEnoughFreeHardDriveSpace()
{
gubCheckForFreeSpaceOnHardDriveCount = 0;
}
// Called by any game loop after all known events were handled
void HandleDefaultEvent(InputAtom *Event)
{
const int MouseButtonEvents = LEFT_BUTTON_REPEAT|RIGHT_BUTTON_REPEAT|
LEFT_BUTTON_DOWN|LEFT_BUTTON_UP|MIDDLE_BUTTON_UP|X1_BUTTON_UP|X2_BUTTON_UP|
RIGHT_BUTTON_DOWN|RIGHT_BUTTON_UP|MIDDLE_BUTTON_DOWN|X1_BUTTON_DOWN|X2_BUTTON_DOWN|
MOUSE_WHEEL_UP|MOUSE_WHEEL_DOWN;
if (Event != NULL && Event->usEvent & MouseButtonEvents)
{
POINT MousePos;
GetCursorPos(&MousePos);
ScreenToClient(ghWindow, &MousePos); // In window coords!
MouseSystemHook(Event->usEvent, (UINT16)MousePos.x ,(UINT16)MousePos.y ,_LeftButtonDown, _RightButtonDown);
}
}