1 (* Copyright (C) 2016 - The Doom2D.org team & involved community members <http://www.doom2d.org>.
2 * This file is part of Doom2D Forever.
4 * This program is free software: you can redistribute it and/or modify it under the terms of
5 * the GNU General Public License as published by the Free Software Foundation, version 3 of
8 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 * See the GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License along with this program.
13 * If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
29 procedure KeyPress (K
: Word);
30 procedure CharPress (C
: AnsiChar
);
33 {--- Read-only dirs ---}
40 AllMapDirs
: SSArray
; // Maps + Megawads
42 {--- Read-Write dirs ---}
48 ScreenshotDirs
: SSArray
;
50 MapDownloadDirs
: SSArray
;
51 WadDownloadDirs
: SSArray
;
53 GameWADName
: string = 'GAME';
59 {$INCLUDE ../nogl/noGLuses.inc}
60 {$IFDEF ENABLE_HOLMES}
61 g_holmes
, sdlcarcass
, fui_ctls
, fui_wadread
, fui_style
, fui_gfx_gl
,
76 wadreader
, e_log
, g_window
,
77 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
78 g_options
, g_player
, g_basic
,
79 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
, e_res
,
80 g_menu
, g_language
, g_net
, g_touch
, g_system
, g_res_downloader
,
86 LogPrefix
= 'DFSERVER-';
88 LogPrefix
= 'dfclient-';
92 charbuff
: packed array [0..15] of AnsiChar
;
96 UseNativeMusic
: Boolean;
99 function GetBinaryPath (): AnsiString
;
106 result
:= ExtractFilePath(ParamStr(0));
108 // it may be a symlink; do some guesswork here
109 sl
:= fpReadLink(ExtractFileName(ParamStr(0)));
110 if (sl
= ParamStr(0)) then
112 // use current directory, as we don't have anything better
117 result
:= fixSlashes(result
);
118 if (length(result
) > 0) and (result
[length(result
)] <> '/') then result
:= result
+'/';
121 procedure PrintDirs (msg
: AnsiString
; dirs
: SSArray
);
124 e_LogWriteln(msg
+ ':');
126 e_LogWriteln(' ' + dir
);
130 function NSStringToAnsiString (s
: NSString
): AnsiString
;
134 for i
:= 0 to s
.length
- 1 do
135 result
:= result
+ AnsiChar(s
.characterAtIndex(i
));
138 function GetBundlePath (): AnsiString
;
139 var pathRef
: CFURLRef
; pathCFStr
: CFStringRef
; pathStr
: ShortString
;
141 pathRef
:= CFBundleCopyBundleURL(CFBundleGetMainBundle());
142 pathCFStr
:= CFURLCopyFileSystemPath(pathRef
, kCFURLPOSIXPathStyle
);
143 CFStringGetPascalString(pathCFStr
, @pathStr
, 255, CFStringGetSystemEncoding());
145 CFRelease(pathCFStr
);
150 procedure InitPath ();
153 rwdir
, rodir
: AnsiString
;
154 rwdirs
, rodirs
: SSArray
;
156 procedure AddDir (var dirs
: SSArray
; append
: AnsiString
);
158 SetLength(dirs
, Length(dirs
) + 1);
159 dirs
[High(dirs
)] := ExpandFileName(append
)
162 function IsSep (ch
: Char): Boolean;
164 Result
:= (ch
= '/') {$IFDEF WINDOWS} or (ch
= '\') {$ENDIF};
167 function OptimizePath (dir
: AnsiString
): AnsiString
;
176 if IsSep(dir
[i
]) then
178 s
+= DirectorySeparator
;
180 while (i
<= len
) and IsSep(dir
[i
]) do i
+= 1;
181 if (i
<= len
) and (dir
[i
] = '.') then
183 if (i
= len
) or IsSep(dir
[i
+ 1]) then
187 else if (i
+ 1 <= len
) and (dir
[i
+ 1] = '.') then
189 if (i
+ 1 = len
) or IsSep(dir
[i
+ 2]) then
206 procedure OptimizeDirs (var dirs
: SSArray
);
210 for i
:= 0 to High(dirs
) do
211 dirs
[i
] := OptimizePath(dirs
[i
]);
219 if dirs
[j
] = dirs
[i
] then
221 for k
:= j
+ 1 to High(dirs
) do
222 dirs
[k
- 1] := dirs
[k
];
224 SetLength(dirs
, High(dirs
))
235 procedure AddDef (var dirs
: SSArray
; base
: SSArray
; append
: AnsiString
);
239 if Length(dirs
) = 0 then
241 if s
<> '' then // FIXME: hack for improper ConcatPaths(); see commit.
242 AddDir(dirs
, ConcatPaths([s
, append
]));
246 function GetDefaultRODirs (): SSArray
;
247 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
257 bundle
, s
: AnsiString
;
264 bundle
:= GetBundlePath();
265 if ExtractFileExt(bundle
) <> '.app' then
266 AddDir(result
, binpath
);
268 AddDir(result
, binPath
);
270 if not forceBinDir
then
273 AddDir(result
, SDL_GetBasePath());
274 AddDir(result
, SDL_GetPrefPath('', 'doom2df'));
277 appdata
:= GetEnvironmentVariable('APPDATA') + '\doom2df';
278 if appdata
<> '' then
279 AddDir(result
, appdata
);
281 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
282 AddDir(result
, '/usr/share/doom2df');
283 AddDir(result
, '/usr/local/share/doom2df');
284 home
:= GetEnvironmentVariable('HOME');
286 AddDir(result
, ConcatPaths([home
, '.doom2df']));
289 bundle
:= GetBundlePath();
291 AddDir(result
, ConcatPaths([bundle
, 'Contents/Resources']));
292 dirArr
:= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory
, NSUserDomainMask
, true);
293 for i
:= 0 to dirArr
.count
- 1 do
295 s
:= NSStringToAnsiString(dirArr
.objectAtIndex(i
));
296 if s
= '' then s
:= '.'; // FIXME: hack for improper ConcatPaths(); see commit.
297 AddDir(result
, ConcatPaths([s
, 'Doom2D Forever']));
300 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
301 AddDir(result
, SDL_AndroidGetInternalStoragePath());
302 if SDL_AndroidGetExternalStorageState() <> 0 then
303 AddDir(result
, SDL_AndroidGetExternalStoragePath());
308 function GetDefaultRWDirs (): SSArray
;
309 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
319 bundle
, s
: AnsiString
; dirArr
: NSArray
; i
: Integer;
324 bundle
:= GetBundlePath();
325 if ExtractFileExt(bundle
) <> '.app' then
326 AddDir(result
, binPath
);
328 AddDir(result
, binPath
);
330 if not forceBinDir
then
333 AddDir(result
, SDL_GetPrefPath('', 'doom2df'));
336 appdata
:= GetEnvironmentVariable('APPDATA') + '\doom2df';
337 if appdata
<> '' then
338 AddDir(result
, appdata
);
340 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
341 home
:= GetEnvironmentVariable('HOME');
343 AddDir(result
, ConcatPaths([home
, '.doom2df']));
346 dirArr
:= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory
, NSUserDomainMask
, true);
347 for i
:= 0 to dirArr
.count
- 1 do
349 s
:= NSStringToAnsiString(dirArr
.objectAtIndex(i
));
350 if s
= '' then s
:= '.'; // FIXME: hack for improper ConcatPaths(); see commit.
351 AddDir(result
, ConcatPaths([s
, 'Doom2D Forever']));
354 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
355 if SDL_AndroidGetExternalStorageState() <> 0 then
356 AddDir(result
, SDL_AndroidGetExternalStoragePath());
362 binPath
:= GetBinaryPath();
365 while i
< ParamCount
do
368 '--like-windoze': forceBinDir
:= true;
372 rwdir
:= ParamStr(i
);
373 if rwdir
= '' then rwdir
:= '.'; // FIXME: hack for improper ConcatPaths(); see commit.
375 AddDir(LogDirs
, ConcatPaths([rwdir
, 'logs']));
376 AddDir(SaveDirs
, ConcatPaths([rwdir
, 'data/saves']));
377 AddDir(CacheDirs
, ConcatPaths([rwdir
, 'data/cache']));
378 AddDir(ConfigDirs
, ConcatPaths([rwdir
, '']));
379 AddDir(MapDownloadDirs
, ConcatPaths([rwdir
, 'maps/downloads']));
380 AddDir(WadDownloadDirs
, ConcatPaths([rwdir
, 'wads/downloads']));
381 AddDir(ScreenshotDirs
, ConcatPaths([rwdir
, 'screenshots']));
382 AddDir(StatsDirs
, ConcatPaths([rwdir
, 'stats']));
384 AddDir(DataDirs
, ConcatPaths([rwdir
, 'data']));
385 AddDir(ModelDirs
, ConcatPaths([rwdir
, 'data/models']));
386 AddDir(MegawadDirs
, ConcatPaths([rwdir
, 'maps/megawads']));
387 AddDir(MapDirs
, ConcatPaths([rwdir
, 'maps']));
388 AddDir(WadDirs
, ConcatPaths([rwdir
, 'wads']));
393 rodir
:= ParamStr(i
);
394 if rodir
= '' then rodir
:= '.'; // FIXME: hack for improper ConcatPaths(); see commit.
396 AddDir(DataDirs
, ConcatPaths([rodir
, 'data']));
397 AddDir(ModelDirs
, ConcatPaths([rodir
, 'data/models']));
398 AddDir(MegawadDirs
, ConcatPaths([rodir
, 'maps/megawads']));
399 AddDir(MapDirs
, ConcatPaths([rodir
, 'maps']));
400 AddDir(WadDirs
, ConcatPaths([rodir
, 'wads']));
405 GameWADName
:= ParamStr(i
);
410 gConfigScript
:= ParamStr(i
);
416 // prefer bin dir if it writable and contains game.wad
417 if forceBinDir
= false then
419 if findDiskWad(binPath
+ 'data' + '/' + GameWADName
) <> '' then
420 if e_CanCreateFilesAt(binPath
) then
425 rodirs
:= GetDefaultRODirs();
426 AddDef(DataDirs
, rodirs
, 'data');
427 AddDef(ModelDirs
, rodirs
, 'data/models');
428 AddDef(MegawadDirs
, rodirs
, 'maps/megawads');
429 AddDef(MapDirs
, rodirs
, 'maps');
430 AddDef(WadDirs
, rodirs
, 'wads');
433 rwdirs
:= GetDefaultRWDirs();
434 AddDef(LogDirs
, rwdirs
, 'logs');
435 AddDef(SaveDirs
, rwdirs
, 'data/saves');
436 AddDef(CacheDirs
, rwdirs
, 'data/cache');
437 AddDef(ConfigDirs
, rwdirs
, '');
438 AddDef(MapDownloadDirs
, rwdirs
, 'maps/downloads');
439 AddDef(WadDownloadDirs
, rwdirs
, 'wads/downloads');
440 AddDef(ScreenshotDirs
, rwdirs
, 'screenshots');
441 AddDef(StatsDirs
, rwdirs
, 'stats');
443 for i
:= 0 to High(MapDirs
) do
444 AddDir(AllMapDirs
, MapDirs
[i
]);
445 for i
:= 0 to High(MegawadDirs
) do
446 AddDir(AllMapDirs
, MegawadDirs
[i
]);
447 OptimizeDirs(AllMapDirs
);
449 if LogFileName
= '' then
451 rwdir
:= e_GetWriteableDir(LogDirs
, false);
454 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', Now());
455 LogFileName
:= ConcatPaths([rwdir
, LogPrefix
+ date
+ '.log']);
459 // HACK: ensure the screenshots folder also has a stats subfolder in it
460 rwdir
:= e_GetWriteableDir(ScreenshotDirs
, false);
461 if rwdir
<> '' then CreateDir(rwdir
+ '/stats');
464 procedure LogCleanup (const path
, mask
: AnsiString
; limit
: Integer);
465 var R
: TSearchRec
; list
: TStringList
;
467 if FindFirst(ConcatPaths([path
, mask
]), faReadOnly
or faArchive
, R
) = 0 then
469 list
:= TStringList
.Create();
474 until FindNext(R
) <> 0;
477 // Delete old files (errors ignored)
479 while list
.Count
> limit
do
481 DeleteFile(ConcatPaths([path
, list
[0]]));
489 function InitPrep (): Boolean;
497 conbufDumpToStdOut
:= True;
502 while i
< ParamCount
do
505 '--con-stdout': conbufDumpToStdOut
:= True;
506 '--no-fbo': glRenderToFBO
:= False;
510 logLimit
:= StrToIntDef(ParamStr(i
), -1);
516 if LogFileName
<> '' then
517 e_InitLog(LogFileName
, TWriteMode
.WM_NEWFILE
);
518 e_InitWritelnDriver();
520 e_WriteLog('Doom2D Forever version ' + GAME_VERSION
+ ' proto ' + IntToStr(NET_PROTOCOL_VER
), TMsgType
.Notify
);
521 e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType
.Notify
);
522 e_WriteLog('Build date: ' + GAME_BUILDDATE
+ ' ' + GAME_BUILDTIME
, TMsgType
.Notify
);
523 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType
.Notify
);
524 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType
.Notify
);
527 if logLimit
>= 0 then
529 s
:= e_GetWriteableDir(LogDirs
, false);
531 LogCleanup(s
, LogPrefix
+ '*-*-*-*-*-*.log', logLimit
);
534 e_LogWritefln('Force bin dir: %s', [forceBinDir
], TMsgType
.Notify
);
535 e_LogWritefln('BINARY PATH: [%s]', [binPath
], TMsgType
.Notify
);
537 PrintDirs('DataDirs', DataDirs
);
538 PrintDirs('ModelDirs', ModelDirs
);
539 PrintDirs('MegawadDirs', MegawadDirs
);
540 PrintDirs('MapDirs', MapDirs
);
541 PrintDirs('WadDirs', WadDirs
);
543 PrintDirs('LogDirs', LogDirs
);
544 PrintDirs('SaveDirs', SaveDirs
);
545 PrintDirs('CacheDirs', CacheDirs
);
546 PrintDirs('ConfigDirs', ConfigDirs
);
547 PrintDirs('ScreenshotDirs', ScreenshotDirs
);
548 PrintDirs('StatsDirs', StatsDirs
);
549 PrintDirs('MapDownloadDirs', MapDownloadDirs
);
550 PrintDirs('WadDownloadDirs', WadDownloadDirs
);
552 GameWAD
:= e_FindWad(DataDirs
, GameWADName
);
555 e_WriteLog('WAD ' + GameWADName
+ ' not found in data directories.', TMsgType
.Fatal
);
556 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
557 if not forceBinDir
then
558 SDL_ShowSimpleMessageBox(
559 SDL_MESSAGEBOX_ERROR
,
561 PChar('WAD ' + GameWADName
+ ' not found in data directories.'),
566 exit
; // Halt(1) here will cause a memleak of strings GameWAD and "WAD <...> not found <...>"
573 {$IFDEF ENABLE_HOLMES}
579 if not InitPrep() then Halt(1);
583 g_Options_SetDefault();
584 g_Options_SetDefaultVideo();
586 if not sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) then
587 Raise Exception
.Create('Failed to set videomode on startup.');
589 e_WriteLog(gLanguage
, TMsgType
.Notify
);
590 g_Language_Set(gLanguage
);
592 {$IFDEF ENABLE_HOLMES}
594 if not fuiAddWad('flexui.wad') then
595 if not fuiAddWad('./data/flexui.wad') then
596 fuiAddWad('./flexui.wad');
599 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
600 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
601 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
602 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
603 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
605 writeln('ERROR loading FlexUI fonts');
613 e_LogWriteln('FlexUI: loading stylesheet...');
614 uiLoadStyles('flexui/widgets.wgs');
616 on e
: TParserException
do
618 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
630 g_holmes_nonfunctional
:= not flexloaded
;
631 if not g_holmes_nonfunctional
then
633 if @oglInitCB
<> nil then oglInitCB();
635 uiContext
.font
:= 'win14';
639 //g_Res_CreateDatabases(true); // it will be done before connecting to the server for the first time
641 e_WriteLog('Entering PerformExecution', TMsgType
.Notify
);
646 {$IFDEF ENABLE_HOLMES}
647 if not g_holmes_nonfunctional
then
650 if @oglDeinitCB
<> nil then oglDeinitCB();
654 g_Console_WriteGameConfig();
660 {$IFDEF USE_SDLMIXER}
661 timiditycfg
: AnsiString
;
662 oldcwd
, newcwd
: RawByteString
;
669 {$IFDEF USE_SDLMIXER}
670 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
672 NoSound
:= True; // FMOD backend will sort it out
681 if (e_JoysticksAvailable > 0) then
682 e_WriteLog('Input: Joysticks available.', TMsgType.Notify)
684 e_WriteLog('Input: No Joysticks.', TMsgType.Notify);
687 {$IFDEF ENABLE_SOUND}
690 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
691 {$IFDEF USE_SDLMIXER}
693 if UseNativeMusic
then
694 SetEnvVar('SDL_NATIVE_MUSIC', '1');
695 timiditycfg
:= GetEnvironmentVariable('TIMIDITY_CFG');
696 if timiditycfg
= '' then
698 timiditycfg
:= 'timidity.cfg';
699 if e_FindResource(ConfigDirs
, timiditycfg
) OR e_FindResource(DataDirs
, timiditycfg
) then
701 timiditycfg
:= ExpandFileName(timiditycfg
);
702 newcwd
:= ExtractFileDir(timiditycfg
);
703 SetEnvVar('TIMIDITY_CFG', timiditycfg
);
708 e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg
]);
709 e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
711 e_InitSoundSystem(NoSound
);
712 {$IFDEF USE_SDLMIXER}
713 if e_TimidityDecoder
and (newcwd
<> '') then
715 (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
716 (* CWD not restored after sound init because timidity *)
717 (* store relative pathes internally and load patches *)
718 (* later. I hope game never relies on CWD. *)
722 e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd
, newcwd
]);
728 e_WriteLog('Init game', TMsgType
.Notify
);
731 FillChar(charbuff
, SizeOf(charbuff
), ' ');
737 e_WriteLog('Releasing engine', TMsgType
.Notify
);
740 e_WriteLog('Releasing input', TMsgType
.Notify
);
743 {$IFDEF ENABLE_SOUND}
746 e_WriteLog('Releasing sound', TMsgType
.Notify
);
747 e_ReleaseSoundSystem();
755 // remember old mobj positions, prepare for update
757 // server: receive client commands for new frame
758 // client: receive game state changes from server
759 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
760 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
763 // server: send any accumulated outgoing data to clients
764 if NetMode
= NET_SERVER
then g_Net_Flush();
774 function Translit (const S
: AnsiString
): AnsiString
;
779 for i
:= 1 to Length(Result
) do
782 'É': Result
[i
] := 'Q';
783 'Ö': Result
[i
] := 'W';
784 'Ó': Result
[i
] := 'E';
785 'Ê': Result
[i
] := 'R';
786 'Å': Result
[i
] := 'T';
787 'Í': Result
[i
] := 'Y';
788 'Ã': Result
[i
] := 'U';
789 'Ø': Result
[i
] := 'I';
790 'Ù': Result
[i
] := 'O';
791 'Ç': Result
[i
] := 'P';
792 'Õ': Result
[i
] := '['; //Chr(219);
793 'Ú': Result
[i
] := ']'; //Chr(221);
794 'Ô': Result
[i
] := 'A';
795 'Û': Result
[i
] := 'S';
796 'Â': Result
[i
] := 'D';
797 'À': Result
[i
] := 'F';
798 'Ï': Result
[i
] := 'G';
799 'Ð': Result
[i
] := 'H';
800 'Î': Result
[i
] := 'J';
801 'Ë': Result
[i
] := 'K';
802 'Ä': Result
[i
] := 'L';
803 'Æ': Result
[i
] := ';'; //Chr(186);
804 'Ý': Result
[i
] := #39; //Chr(222);
805 'ß': Result
[i
] := 'Z';
806 '×': Result
[i
] := 'X';
807 'Ñ': Result
[i
] := 'C';
808 'Ì': Result
[i
] := 'V';
809 'È': Result
[i
] := 'B';
810 'Ò': Result
[i
] := 'N';
811 'Ü': Result
[i
] := 'M';
812 'Á': Result
[i
] := ','; //Chr(188);
813 'Þ': Result
[i
] := '.'; //Chr(190);
819 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
824 ls2
:= Translit(CheatRus
[ct
]);
825 if length(ls1
) = 0 then ls1
:= '~';
826 if length(ls2
) = 0 then ls2
:= '~';
828 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
829 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
830 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
831 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
833 if ct = I_GAME_CHEAT_JETPACK then
835 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
836 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
837 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
838 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
839 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
840 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
852 {$IFDEF ENABLE_SOUND}
860 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
861 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
862 or g_Game_IsNet then Exit;
864 if not gGameOn
then exit
;
865 if not conIsCheatsEnabled
then exit
;
867 {$IFDEF ENABLE_SOUND}
868 s
:= 'SOUND_GAME_RADIO';
872 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
874 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
875 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
879 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
881 if gPlayer1
<> nil then gPlayer1
.TankRamboCheats(False);
882 if gPlayer2
<> nil then gPlayer2
.TankRamboCheats(False);
886 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
888 if gPlayer1
<> nil then gPlayer1
.TankRamboCheats(True);
889 if gPlayer2
<> nil then gPlayer2
.TankRamboCheats(True);
893 if CheckCheat(I_GAME_CHEAT_DEATH
) then
895 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
896 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
897 {$IFDEF ENABLE_SOUND}
898 s
:= 'SOUND_MONSTER_HAHA';
903 if CheckCheat(I_GAME_CHEAT_DOORS
) then
905 g_Triggers_OpenAll();
909 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
911 if gTriggers
<> nil then
912 for a
:= 0 to High(gTriggers
) do
913 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
915 gExitByTrigger
:= True;
916 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
917 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
923 s2
:= Copy(charbuff
, 15, 2);
924 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
926 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
934 if CheckCheat(I_GAME_CHEAT_FLY
) then
940 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
942 VEL_JUMP
:= 30-VEL_JUMP
;
946 if CheckCheat(I_GAME_CHEAT_SPEED
) then
948 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
952 if CheckCheat(I_GAME_CHEAT_SUIT
) then
954 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
955 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
959 if CheckCheat(I_GAME_CHEAT_AIR
) then
961 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
962 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
966 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
968 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
969 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
973 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
975 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
976 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
980 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
982 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
983 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
987 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
989 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
990 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
994 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
996 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
997 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
1000 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
1002 gAimLine
:= not gAimLine
;
1005 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
1007 gShowMap
:= not gShowMap
;
1013 {$IFDEF ENABLE_SOUND}
1019 procedure KeyPress (K
: Word);
1022 Msg
: g_gui
.TMessage
;
1027 VK_ESCAPE
: // <Esc>:
1029 if (g_ActiveWindow
<> nil) then
1031 Msg
.Msg
:= WM_KEYDOWN
;
1032 Msg
.WParam
:= VK_ESCAPE
;
1033 g_ActiveWindow
.OnMessage(Msg
);
1034 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
1036 else if (gState
<> STATE_FOLD
) then
1038 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
1040 g_Game_InGameMenu(True);
1042 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
1044 if (gState
<> STATE_MENU
) then
1046 if (NetMode
<> NET_NONE
) then
1048 {$IFDEF ENABLE_SOUND}
1049 g_Game_StopAllSounds(True);
1052 gState
:= STATE_MENU
;
1056 g_GUI_ShowWindow('MainMenu');
1057 {$IFDEF ENABLE_SOUND}
1058 g_Sound_PlayEx('MENU_OPEN');
1064 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
1065 begin // <F2> .. <F6> � <F12>
1066 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
1068 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
1069 if (not g_Game_IsNet
) then g_Game_Pause(True);
1071 IK_F2
: g_Menu_Show_SaveMenu();
1072 IK_F3
: g_Menu_Show_LoadMenu();
1073 IK_F4
: g_Menu_Show_GameSetGame();
1074 IK_F5
: g_Menu_Show_OptionsVideo();
1075 IK_F6
: g_Menu_Show_OptionsSound();
1076 IK_F7
: g_Menu_Show_EndGameMenu();
1077 IK_F10
: g_Menu_Show_QuitGameMenu();
1084 gJustChatted
:= False;
1085 if gConsoleShow
or gChatShow
then
1087 g_Console_Control(K
);
1089 else if (g_ActiveWindow
<> nil) then
1091 Msg
.Msg
:= WM_KEYDOWN
;
1093 g_ActiveWindow
.OnMessage(Msg
);
1095 else if (gState
= STATE_MENU
) then
1097 g_GUI_ShowWindow('MainMenu');
1098 {$IFDEF ENABLE_SOUND}
1099 g_Sound_PlayEx('MENU_OPEN');
1108 procedure CharPress (C
: AnsiChar
);
1110 Msg
: g_gui
.TMessage
;
1113 if gConsoleShow
or gChatShow
then
1117 else if (g_ActiveWindow
<> nil) then
1120 Msg
.WParam
:= Ord(C
);
1121 g_ActiveWindow
.OnMessage(Msg
);
1125 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
1126 charbuff
[15] := upcase1251(C
);
1132 {$IFDEF USE_SDLMIXER}
1133 conRegVar('sdl_native_music', @UseNativeMusic
, 'use native midi music output when possible', 'use native midi');
1135 UseNativeMusic
:= true; (* OSX have a good midi support, so why not? *)
1137 UseNativeMusic
:= false;