1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
28 procedure KeyPress (K
: Word);
29 procedure CharPress (C
: AnsiChar
);
32 {--- Read-only dirs ---}
39 AllMapDirs
: SSArray
; // Maps + Megawads
41 {--- Read-Write dirs ---}
47 ScreenshotDirs
: SSArray
;
49 MapDownloadDirs
: SSArray
;
50 WadDownloadDirs
: SSArray
;
52 GameWADName
: string = 'GAME';
58 {$INCLUDE ../nogl/noGLuses.inc}
59 {$IFDEF ENABLE_HOLMES}
60 g_holmes
, sdlcarcass
, fui_ctls
, fui_wadread
, fui_style
, fui_gfx_gl
,
75 wadreader
, e_log
, g_window
,
76 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
77 g_options
, g_player
, g_basic
,
78 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
, e_res
,
79 g_menu
, g_language
, g_net
, g_touch
, g_system
, g_res_downloader
,
85 LogPrefix
= 'DFSERVER-';
87 LogPrefix
= 'dfclient-';
91 charbuff
: packed array [0..15] of AnsiChar
;
95 UseNativeMusic
: Boolean;
98 function GetBinaryPath (): AnsiString
;
105 result
:= ExtractFilePath(ParamStr(0));
107 // it may be a symlink; do some guesswork here
108 sl
:= fpReadLink(ExtractFileName(ParamStr(0)));
109 if (sl
= ParamStr(0)) then
111 // use current directory, as we don't have anything better
116 result
:= fixSlashes(result
);
117 if (length(result
) > 0) and (result
[length(result
)] <> '/') then result
:= result
+'/';
120 procedure PrintDirs (msg
: AnsiString
; dirs
: SSArray
);
123 e_LogWriteln(msg
+ ':');
125 e_LogWriteln(' ' + dir
);
129 function NSStringToAnsiString (s
: NSString
): AnsiString
;
133 for i
:= 0 to s
.length
- 1 do
134 result
:= result
+ AnsiChar(s
.characterAtIndex(i
));
137 function GetBundlePath (): AnsiString
;
138 var pathRef
: CFURLRef
; pathCFStr
: CFStringRef
; pathStr
: ShortString
;
140 pathRef
:= CFBundleCopyBundleURL(CFBundleGetMainBundle());
141 pathCFStr
:= CFURLCopyFileSystemPath(pathRef
, kCFURLPOSIXPathStyle
);
142 CFStringGetPascalString(pathCFStr
, @pathStr
, 255, CFStringGetSystemEncoding());
144 CFRelease(pathCFStr
);
149 procedure InitPath ();
152 rwdir
, rodir
: AnsiString
;
153 rwdirs
, rodirs
: SSArray
;
155 procedure AddDir (var dirs
: SSArray
; append
: AnsiString
);
157 SetLength(dirs
, Length(dirs
) + 1);
158 dirs
[High(dirs
)] := ExpandFileName(append
)
161 function IsSep (ch
: Char): Boolean;
163 Result
:= (ch
= '/') {$IFDEF WINDOWS} or (ch
= '\') {$ENDIF};
166 function OptimizePath (dir
: AnsiString
): AnsiString
;
175 if IsSep(dir
[i
]) then
177 s
+= DirectorySeparator
;
179 while (i
<= len
) and IsSep(dir
[i
]) do i
+= 1;
180 if (i
<= len
) and (dir
[i
] = '.') then
182 if (i
= len
) or IsSep(dir
[i
+ 1]) then
186 else if (i
+ 1 <= len
) and (dir
[i
+ 1] = '.') then
188 if (i
+ 1 = len
) or IsSep(dir
[i
+ 2]) then
205 procedure OptimizeDirs (var dirs
: SSArray
);
209 for i
:= 0 to High(dirs
) do
210 dirs
[i
] := OptimizePath(dirs
[i
]);
218 if dirs
[j
] = dirs
[i
] then
220 for k
:= j
+ 1 to High(dirs
) do
221 dirs
[k
- 1] := dirs
[k
];
223 SetLength(dirs
, High(dirs
))
234 procedure AddDef (var dirs
: SSArray
; base
: SSArray
; append
: AnsiString
);
238 if Length(dirs
) = 0 then
240 if s
<> '' then // FIXME: hack for improper ConcatPaths(); see commit.
241 AddDir(dirs
, ConcatPaths([s
, append
]));
245 function GetDefaultRODirs (): SSArray
;
246 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
256 bundle
, s
: AnsiString
;
263 bundle
:= GetBundlePath();
264 if ExtractFileExt(bundle
) <> '.app' then
265 AddDir(result
, binpath
);
267 AddDir(result
, binPath
);
269 if not forceBinDir
then
272 AddDir(result
, SDL_GetBasePath());
273 AddDir(result
, SDL_GetPrefPath('', 'doom2df'));
276 appdata
:= GetEnvironmentVariable('APPDATA') + '\doom2df';
277 if appdata
<> '' then
278 AddDir(result
, appdata
);
280 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
281 AddDir(result
, '/usr/share/doom2df');
282 AddDir(result
, '/usr/local/share/doom2df');
283 home
:= GetEnvironmentVariable('HOME');
285 AddDir(result
, ConcatPaths([home
, '.doom2df']));
288 bundle
:= GetBundlePath();
290 AddDir(result
, ConcatPaths([bundle
, 'Contents/Resources']));
291 dirArr
:= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory
, NSUserDomainMask
, true);
292 for i
:= 0 to dirArr
.count
- 1 do
294 s
:= NSStringToAnsiString(dirArr
.objectAtIndex(i
));
295 if s
= '' then s
:= '.'; // FIXME: hack for improper ConcatPaths(); see commit.
296 AddDir(result
, ConcatPaths([s
, 'Doom 2D Forever']));
299 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
300 AddDir(result
, SDL_AndroidGetInternalStoragePath());
301 if SDL_AndroidGetExternalStorageState() <> 0 then
302 AddDir(result
, SDL_AndroidGetExternalStoragePath());
307 function GetDefaultRWDirs (): SSArray
;
308 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
318 bundle
, s
: AnsiString
; dirArr
: NSArray
; i
: Integer;
323 bundle
:= GetBundlePath();
324 if ExtractFileExt(bundle
) <> '.app' then
325 AddDir(result
, binPath
);
327 AddDir(result
, binPath
);
329 if not forceBinDir
then
332 AddDir(result
, SDL_GetPrefPath('', 'doom2df'));
335 appdata
:= GetEnvironmentVariable('APPDATA') + '\doom2df';
336 if appdata
<> '' then
337 AddDir(result
, appdata
);
339 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
340 home
:= GetEnvironmentVariable('HOME');
342 AddDir(result
, ConcatPaths([home
, '.doom2df']));
345 dirArr
:= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory
, NSUserDomainMask
, true);
346 for i
:= 0 to dirArr
.count
- 1 do
348 s
:= NSStringToAnsiString(dirArr
.objectAtIndex(i
));
349 if s
= '' then s
:= '.'; // FIXME: hack for improper ConcatPaths(); see commit.
350 AddDir(result
, ConcatPaths([s
, 'Doom 2D Forever']));
353 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
354 if SDL_AndroidGetExternalStorageState() <> 0 then
355 AddDir(result
, SDL_AndroidGetExternalStoragePath());
361 binPath
:= GetBinaryPath();
364 while i
< ParamCount
do
367 '--like-windoze': forceBinDir
:= true;
371 rwdir
:= ParamStr(i
);
372 if rwdir
= '' then rwdir
:= '.'; // FIXME: hack for improper ConcatPaths(); see commit.
374 AddDir(LogDirs
, ConcatPaths([rwdir
, 'logs']));
375 AddDir(SaveDirs
, ConcatPaths([rwdir
, 'data/saves']));
376 AddDir(CacheDirs
, ConcatPaths([rwdir
, 'data/cache']));
377 AddDir(ConfigDirs
, ConcatPaths([rwdir
, '']));
378 AddDir(MapDownloadDirs
, ConcatPaths([rwdir
, 'maps/downloads']));
379 AddDir(WadDownloadDirs
, ConcatPaths([rwdir
, 'wads/downloads']));
380 AddDir(ScreenshotDirs
, ConcatPaths([rwdir
, 'screenshots']));
381 AddDir(StatsDirs
, ConcatPaths([rwdir
, 'stats']));
383 AddDir(DataDirs
, ConcatPaths([rwdir
, 'data']));
384 AddDir(ModelDirs
, ConcatPaths([rwdir
, 'data/models']));
385 AddDir(MegawadDirs
, ConcatPaths([rwdir
, 'maps/megawads']));
386 AddDir(MapDirs
, ConcatPaths([rwdir
, 'maps']));
387 AddDir(WadDirs
, ConcatPaths([rwdir
, 'wads']));
392 rodir
:= ParamStr(i
);
393 if rodir
= '' then rodir
:= '.'; // FIXME: hack for improper ConcatPaths(); see commit.
395 AddDir(DataDirs
, ConcatPaths([rodir
, 'data']));
396 AddDir(ModelDirs
, ConcatPaths([rodir
, 'data/models']));
397 AddDir(MegawadDirs
, ConcatPaths([rodir
, 'maps/megawads']));
398 AddDir(MapDirs
, ConcatPaths([rodir
, 'maps']));
399 AddDir(WadDirs
, ConcatPaths([rodir
, 'wads']));
404 GameWADName
:= ParamStr(i
);
409 gConfigScript
:= ParamStr(i
);
415 // prefer bin dir if it writable and contains game.wad
416 if forceBinDir
= false then
418 if findDiskWad(binPath
+ 'data' + '/' + GameWADName
) <> '' then
419 if e_CanCreateFilesAt(binPath
) then
424 rodirs
:= GetDefaultRODirs();
425 AddDef(DataDirs
, rodirs
, 'data');
426 AddDef(ModelDirs
, rodirs
, 'data/models');
427 AddDef(MegawadDirs
, rodirs
, 'maps/megawads');
428 AddDef(MapDirs
, rodirs
, 'maps');
429 AddDef(WadDirs
, rodirs
, 'wads');
432 rwdirs
:= GetDefaultRWDirs();
433 AddDef(LogDirs
, rwdirs
, 'logs');
434 AddDef(SaveDirs
, rwdirs
, 'data/saves');
435 AddDef(CacheDirs
, rwdirs
, 'data/cache');
436 AddDef(ConfigDirs
, rwdirs
, '');
437 AddDef(MapDownloadDirs
, rwdirs
, 'maps/downloads');
438 AddDef(WadDownloadDirs
, rwdirs
, 'wads/downloads');
439 AddDef(ScreenshotDirs
, rwdirs
, 'screenshots');
440 AddDef(StatsDirs
, rwdirs
, 'stats');
442 for i
:= 0 to High(MapDirs
) do
443 AddDir(AllMapDirs
, MapDirs
[i
]);
444 for i
:= 0 to High(MegawadDirs
) do
445 AddDir(AllMapDirs
, MegawadDirs
[i
]);
446 OptimizeDirs(AllMapDirs
);
448 if LogFileName
= '' then
450 rwdir
:= e_GetWriteableDir(LogDirs
, false);
453 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', Now());
454 LogFileName
:= ConcatPaths([rwdir
, LogPrefix
+ date
+ '.log']);
458 // HACK: ensure the screenshots folder also has a stats subfolder in it
459 rwdir
:= e_GetWriteableDir(ScreenshotDirs
, false);
460 if rwdir
<> '' then CreateDir(rwdir
+ '/stats');
463 procedure LogCleanup (const path
, mask
: AnsiString
; limit
: Integer);
464 var R
: TSearchRec
; list
: TStringList
;
466 if FindFirst(ConcatPaths([path
, mask
]), faReadOnly
or faArchive
, R
) = 0 then
468 list
:= TStringList
.Create();
473 until FindNext(R
) <> 0;
476 // Delete old files (errors ignored)
478 while list
.Count
> limit
do
480 DeleteFile(ConcatPaths([path
, list
[0]]));
488 function InitPrep (): Boolean;
496 conbufDumpToStdOut
:= True;
501 while i
< ParamCount
do
504 '--con-stdout': conbufDumpToStdOut
:= True;
505 '--no-fbo': glRenderToFBO
:= False;
509 logLimit
:= StrToIntDef(ParamStr(i
), -1);
515 if LogFileName
<> '' then
516 e_InitLog(LogFileName
, TWriteMode
.WM_NEWFILE
);
517 e_InitWritelnDriver();
519 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION
+ ' proto ' + IntToStr(NET_PROTOCOL_VER
), TMsgType
.Notify
);
520 e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType
.Notify
);
521 e_WriteLog('Build date: ' + GAME_BUILDDATE
+ ' ' + GAME_BUILDTIME
, TMsgType
.Notify
);
522 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType
.Notify
);
523 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType
.Notify
);
526 if logLimit
>= 0 then
528 s
:= e_GetWriteableDir(LogDirs
, false);
530 LogCleanup(s
, LogPrefix
+ '*-*-*-*-*-*.log', logLimit
);
533 e_LogWritefln('Force bin dir: %s', [forceBinDir
], TMsgType
.Notify
);
534 e_LogWritefln('BINARY PATH: [%s]', [binPath
], TMsgType
.Notify
);
536 PrintDirs('DataDirs', DataDirs
);
537 PrintDirs('ModelDirs', ModelDirs
);
538 PrintDirs('MegawadDirs', MegawadDirs
);
539 PrintDirs('MapDirs', MapDirs
);
540 PrintDirs('WadDirs', WadDirs
);
542 PrintDirs('LogDirs', LogDirs
);
543 PrintDirs('SaveDirs', SaveDirs
);
544 PrintDirs('CacheDirs', CacheDirs
);
545 PrintDirs('ConfigDirs', ConfigDirs
);
546 PrintDirs('ScreenshotDirs', ScreenshotDirs
);
547 PrintDirs('StatsDirs', StatsDirs
);
548 PrintDirs('MapDownloadDirs', MapDownloadDirs
);
549 PrintDirs('WadDownloadDirs', WadDownloadDirs
);
551 GameWAD
:= e_FindWad(DataDirs
, GameWADName
);
554 e_WriteLog('WAD ' + GameWADName
+ ' not found in data directories.', TMsgType
.Fatal
);
555 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
556 if not forceBinDir
then
557 SDL_ShowSimpleMessageBox(
558 SDL_MESSAGEBOX_ERROR
,
560 PChar('WAD ' + GameWADName
+ ' not found in data directories.'),
565 exit
; // Halt(1) here will cause a memleak of strings GameWAD and "WAD <...> not found <...>"
572 {$IFDEF ENABLE_HOLMES}
578 if not InitPrep() then Halt(1);
582 g_Options_SetDefault();
583 g_Options_SetDefaultVideo();
585 if not sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) then
586 Raise Exception
.Create('Failed to set videomode on startup.');
588 e_WriteLog(gLanguage
, TMsgType
.Notify
);
589 g_Language_Set(gLanguage
);
591 {$IFDEF ENABLE_HOLMES}
593 if not fuiAddWad('flexui.wad') then
594 if not fuiAddWad('./data/flexui.wad') then
595 fuiAddWad('./flexui.wad');
598 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
599 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
600 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
601 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
602 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
604 writeln('ERROR loading FlexUI fonts');
612 e_LogWriteln('FlexUI: loading stylesheet...');
613 uiLoadStyles('flexui/widgets.wgs');
615 on e
: TParserException
do
617 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
629 g_holmes_nonfunctional
:= not flexloaded
;
630 if not g_holmes_nonfunctional
then
632 if @oglInitCB
<> nil then oglInitCB();
634 uiContext
.font
:= 'win14';
638 //g_Res_CreateDatabases(true); // it will be done before connecting to the server for the first time
640 e_WriteLog('Entering PerformExecution', TMsgType
.Notify
);
645 {$IFDEF ENABLE_HOLMES}
646 if not g_holmes_nonfunctional
then
649 if @oglDeinitCB
<> nil then oglDeinitCB();
653 g_Console_WriteGameConfig();
659 {$IFDEF USE_SDLMIXER}
660 timiditycfg
: AnsiString
;
661 oldcwd
, newcwd
: RawByteString
;
668 {$IFDEF USE_SDLMIXER}
669 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
671 NoSound
:= True; // FMOD backend will sort it out
680 if (e_JoysticksAvailable > 0) then
681 e_WriteLog('Input: Joysticks available.', TMsgType.Notify)
683 e_WriteLog('Input: No Joysticks.', TMsgType.Notify);
686 {$IFDEF ENABLE_SOUND}
689 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
690 {$IFDEF USE_SDLMIXER}
692 if UseNativeMusic
then
693 SetEnvVar('SDL_NATIVE_MUSIC', '1');
694 timiditycfg
:= GetEnvironmentVariable('TIMIDITY_CFG');
695 if timiditycfg
= '' then
697 timiditycfg
:= 'timidity.cfg';
698 if e_FindResource(ConfigDirs
, timiditycfg
) OR e_FindResource(DataDirs
, timiditycfg
) then
700 timiditycfg
:= ExpandFileName(timiditycfg
);
701 newcwd
:= ExtractFileDir(timiditycfg
);
702 SetEnvVar('TIMIDITY_CFG', timiditycfg
);
707 e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg
]);
708 e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
710 e_InitSoundSystem(NoSound
);
711 {$IFDEF USE_SDLMIXER}
712 if e_TimidityDecoder
and (newcwd
<> '') then
714 (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
715 (* CWD not restored after sound init because timidity *)
716 (* store relative pathes internally and load patches *)
717 (* later. I hope game never relies on CWD. *)
721 e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd
, newcwd
]);
727 e_WriteLog('Init game', TMsgType
.Notify
);
730 FillChar(charbuff
, SizeOf(charbuff
), ' ');
736 e_WriteLog('Releasing engine', TMsgType
.Notify
);
739 e_WriteLog('Releasing input', TMsgType
.Notify
);
742 {$IFDEF ENABLE_SOUND}
745 e_WriteLog('Releasing sound', TMsgType
.Notify
);
746 e_ReleaseSoundSystem();
754 // remember old mobj positions, prepare for update
756 // server: receive client commands for new frame
757 // client: receive game state changes from server
758 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
759 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
762 // server: send any accumulated outgoing data to clients
763 if NetMode
= NET_SERVER
then g_Net_Flush();
773 function Translit (const S
: AnsiString
): AnsiString
;
778 for i
:= 1 to Length(Result
) do
781 'É': Result
[i
] := 'Q';
782 'Ö': Result
[i
] := 'W';
783 'Ó': Result
[i
] := 'E';
784 'Ê': Result
[i
] := 'R';
785 'Å': Result
[i
] := 'T';
786 'Í': Result
[i
] := 'Y';
787 'Ã': Result
[i
] := 'U';
788 'Ø': Result
[i
] := 'I';
789 'Ù': Result
[i
] := 'O';
790 'Ç': Result
[i
] := 'P';
791 'Õ': Result
[i
] := '['; //Chr(219);
792 'Ú': Result
[i
] := ']'; //Chr(221);
793 'Ô': Result
[i
] := 'A';
794 'Û': Result
[i
] := 'S';
795 'Â': Result
[i
] := 'D';
796 'À': Result
[i
] := 'F';
797 'Ï': Result
[i
] := 'G';
798 'Ð': Result
[i
] := 'H';
799 'Î': Result
[i
] := 'J';
800 'Ë': Result
[i
] := 'K';
801 'Ä': Result
[i
] := 'L';
802 'Æ': Result
[i
] := ';'; //Chr(186);
803 'Ý': Result
[i
] := #39; //Chr(222);
804 'ß': Result
[i
] := 'Z';
805 '×': Result
[i
] := 'X';
806 'Ñ': Result
[i
] := 'C';
807 'Ì': Result
[i
] := 'V';
808 'È': Result
[i
] := 'B';
809 'Ò': Result
[i
] := 'N';
810 'Ü': Result
[i
] := 'M';
811 'Á': Result
[i
] := ','; //Chr(188);
812 'Þ': Result
[i
] := '.'; //Chr(190);
818 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
823 ls2
:= Translit(CheatRus
[ct
]);
824 if length(ls1
) = 0 then ls1
:= '~';
825 if length(ls2
) = 0 then ls2
:= '~';
827 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
828 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
829 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
830 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
832 if ct = I_GAME_CHEAT_JETPACK then
834 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
835 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
836 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
837 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
838 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
839 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
851 {$IFDEF ENABLE_SOUND}
859 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
860 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
861 or g_Game_IsNet then Exit;
863 if not gGameOn
then exit
;
864 if not conIsCheatsEnabled
then exit
;
866 {$IFDEF ENABLE_SOUND}
867 s
:= 'SOUND_GAME_RADIO';
871 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
873 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
874 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
878 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
880 if gPlayer1
<> nil then gPlayer1
.TankRamboCheats(False);
881 if gPlayer2
<> nil then gPlayer2
.TankRamboCheats(False);
885 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
887 if gPlayer1
<> nil then gPlayer1
.TankRamboCheats(True);
888 if gPlayer2
<> nil then gPlayer2
.TankRamboCheats(True);
892 if CheckCheat(I_GAME_CHEAT_DEATH
) then
894 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
895 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
896 {$IFDEF ENABLE_SOUND}
897 s
:= 'SOUND_MONSTER_HAHA';
902 if CheckCheat(I_GAME_CHEAT_DOORS
) then
904 g_Triggers_OpenAll();
908 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
910 if gTriggers
<> nil then
911 for a
:= 0 to High(gTriggers
) do
912 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
914 gExitByTrigger
:= True;
915 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
916 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
922 s2
:= Copy(charbuff
, 15, 2);
923 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
925 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
933 if CheckCheat(I_GAME_CHEAT_FLY
) then
939 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
941 VEL_JUMP
:= 30-VEL_JUMP
;
945 if CheckCheat(I_GAME_CHEAT_SPEED
) then
947 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
951 if CheckCheat(I_GAME_CHEAT_SUIT
) then
953 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
954 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
958 if CheckCheat(I_GAME_CHEAT_AIR
) then
960 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
961 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
965 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
967 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
968 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
972 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
974 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
975 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
979 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
981 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
982 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
986 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
988 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
989 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
993 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
995 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
996 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
999 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
1001 gAimLine
:= not gAimLine
;
1004 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
1006 gShowMap
:= not gShowMap
;
1012 {$IFDEF ENABLE_SOUND}
1018 procedure KeyPress (K
: Word);
1021 Msg
: g_gui
.TMessage
;
1026 VK_ESCAPE
: // <Esc>:
1028 if (g_ActiveWindow
<> nil) then
1030 Msg
.Msg
:= WM_KEYDOWN
;
1031 Msg
.WParam
:= VK_ESCAPE
;
1032 g_ActiveWindow
.OnMessage(Msg
);
1033 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
1035 else if (gState
<> STATE_FOLD
) then
1037 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
1039 g_Game_InGameMenu(True);
1041 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
1043 if (gState
<> STATE_MENU
) then
1045 if (NetMode
<> NET_NONE
) then
1047 {$IFDEF ENABLE_SOUND}
1048 g_Game_StopAllSounds(True);
1051 gState
:= STATE_MENU
;
1055 g_GUI_ShowWindow('MainMenu');
1056 {$IFDEF ENABLE_SOUND}
1057 g_Sound_PlayEx('MENU_OPEN');
1063 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
1064 begin // <F2> .. <F6> � <F12>
1065 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
1067 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
1068 if (not g_Game_IsNet
) then g_Game_Pause(True);
1070 IK_F2
: g_Menu_Show_SaveMenu();
1071 IK_F3
: g_Menu_Show_LoadMenu();
1072 IK_F4
: g_Menu_Show_GameSetGame();
1073 IK_F5
: g_Menu_Show_OptionsVideo();
1074 IK_F6
: g_Menu_Show_OptionsSound();
1075 IK_F7
: g_Menu_Show_EndGameMenu();
1076 IK_F10
: g_Menu_Show_QuitGameMenu();
1083 gJustChatted
:= False;
1084 if gConsoleShow
or gChatShow
then
1086 g_Console_Control(K
);
1088 else if (g_ActiveWindow
<> nil) then
1090 Msg
.Msg
:= WM_KEYDOWN
;
1092 g_ActiveWindow
.OnMessage(Msg
);
1094 else if (gState
= STATE_MENU
) then
1096 g_GUI_ShowWindow('MainMenu');
1097 {$IFDEF ENABLE_SOUND}
1098 g_Sound_PlayEx('MENU_OPEN');
1107 procedure CharPress (C
: AnsiChar
);
1109 Msg
: g_gui
.TMessage
;
1112 if gConsoleShow
or gChatShow
then
1116 else if (g_ActiveWindow
<> nil) then
1119 Msg
.WParam
:= Ord(C
);
1120 g_ActiveWindow
.OnMessage(Msg
);
1124 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
1125 charbuff
[15] := upcase1251(C
);
1131 {$IFDEF USE_SDLMIXER}
1132 conRegVar('sdl_native_music', @UseNativeMusic
, 'use native midi music output when possible', 'use native midi');
1134 UseNativeMusic
:= true; (* OSX have a good midi support, so why not? *)
1136 UseNativeMusic
:= false;