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}
27 procedure KeyPress (K
: Word);
28 procedure CharPress (C
: AnsiChar
);
31 {--- Read-only dirs ---}
38 AllMapDirs
: SSArray
; // Maps + Megawads
40 {--- Read-Write dirs ---}
46 ScreenshotDirs
: SSArray
;
48 MapDownloadDirs
: SSArray
;
49 WadDownloadDirs
: SSArray
;
51 GameWADName
: string = 'GAME';
57 {$INCLUDE ../nogl/noGLuses.inc}
58 {$IFDEF ENABLE_HOLMES}
59 g_holmes
, sdlcarcass
, fui_ctls
, fui_wadread
, fui_style
, fui_gfx_gl
,
70 wadreader
, e_log
, g_window
,
71 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
72 e_sound
, g_options
, g_sound
, g_player
, g_basic
,
73 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
, e_res
,
74 g_menu
, g_language
, g_net
, g_touch
, g_system
, g_res_downloader
,
80 charbuff
: packed array [0..15] of AnsiChar
;
81 binPath
: AnsiString
= '';
84 UseNativeMusic
: Boolean;
87 function GetBinaryPath (): AnsiString
;
94 result
:= ExtractFilePath(ParamStr(0));
96 // it may be a symlink; do some guesswork here
97 sl
:= fpReadLink(ExtractFileName(ParamStr(0)));
98 if (sl
= ParamStr(0)) then
100 // use current directory, as we don't have anything better
105 result
:= fixSlashes(result
);
106 if (length(result
) > 0) and (result
[length(result
)] <> '/') then result
:= result
+'/';
109 procedure PrintDirs (msg
: AnsiString
; dirs
: SSArray
);
112 e_LogWriteln(msg
+ ':');
114 e_LogWriteln(' ' + dir
);
118 function NSStringToAnsiString (s
: NSString
): AnsiString
;
122 for i
:= 0 to s
.length
- 1 do
123 result
:= result
+ AnsiChar(s
.characterAtIndex(i
));
126 function GetBundlePath (): AnsiString
;
127 var pathRef
: CFURLRef
; pathCFStr
: CFStringRef
; pathStr
: ShortString
;
129 pathRef
:= CFBundleCopyBundleURL(CFBundleGetMainBundle());
130 pathCFStr
:= CFURLCopyFileSystemPath(pathRef
, kCFURLPOSIXPathStyle
);
131 CFStringGetPascalString(pathCFStr
, @pathStr
, 255, CFStringGetSystemEncoding());
133 CFRelease(pathCFStr
);
139 var i
: Integer; rwdir
, rodir
: AnsiString
; rwdirs
, rodirs
: SSArray
;
141 procedure AddDir (var dirs
: SSArray
; append
: AnsiString
);
143 SetLength(dirs
, Length(dirs
) + 1);
144 dirs
[High(dirs
)] := ExpandFileName(append
)
147 function IsSep (ch
: Char): Boolean;
150 result
:= (ch
= '/') or (ch
= '\');
152 result
:= (ch
= '/');
156 function OptimizePath (dir
: AnsiString
): AnsiString
;
157 var i
, len
: Integer; s
: AnsiString
;
159 i
:= 1; len
:= Length(dir
); s
:= '';
162 if IsSep(dir
[i
]) then
164 s
:= s
+ DirectorySeparator
;
166 while (i
<= len
) and IsSep(dir
[i
]) do Inc(i
);
167 if (i
<= len
) and (dir
[i
] = '.') then
169 if (i
= len
) or IsSep(dir
[i
+ 1]) then
173 else if (i
+ 1 <= len
) and (dir
[i
+ 1] = '.') then
175 if (i
+ 1 = len
) or IsSep(dir
[i
+ 2]) then
192 procedure OptimizeDirs (var dirs
: SSArray
);
193 var i
, j
, k
: Integer;
195 for i
:= 0 to High(dirs
) do
196 dirs
[i
] := OptimizePath(dirs
[i
]);
204 if dirs
[j
] = dirs
[i
] then
206 for k
:= j
+ 1 to High(dirs
) do
207 dirs
[k
- 1] := dirs
[k
];
209 SetLength(dirs
, High(dirs
))
220 procedure AddDef (var dirs
: SSArray
; base
: SSArray
; append
: AnsiString
);
223 if Length(dirs
) = 0 then
225 AddDir(dirs
, e_CatPath(s
, append
));
229 function GetDefaultRODirs (): SSArray
;
230 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
231 var home
: AnsiString
;
234 var appdata
: AnsiString
;
237 var bundle
, s
: AnsiString
; dirArr
: NSArray
; i
: Integer;
242 bundle
:= GetBundlePath();
243 if ExtractFileExt(bundle
) <> '.app' then
244 AddDir(result
, binpath
);
246 AddDir(result
, binPath
);
248 if forceBinDir
= false then
251 AddDir(result
, SDL_GetBasePath());
252 AddDir(result
, SDL_GetPrefPath('', 'doom2df'));
255 appdata
:= GetEnvironmentVariable('APPDATA') + '\doom2df';
256 if appdata
<> '' then
257 AddDir(result
, appdata
);
259 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
260 AddDir(result
, '/usr/share/doom2df');
261 AddDir(result
, '/usr/local/share/doom2df');
262 home
:= GetEnvironmentVariable('HOME');
264 AddDir(result
, e_CatPath(home
, '.doom2df'));
267 bundle
:= GetBundlePath();
269 AddDir(result
, e_CatPath(bundle
, 'Contents/Resources'));
270 dirArr
:= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory
, NSUserDomainMask
, true);
271 for i
:= 0 to dirArr
.count
- 1 do
273 s
:= NSStringToAnsiString(dirArr
.objectAtIndex(i
));
274 AddDir(result
, e_CatPath(s
, 'Doom 2D Forever'))
277 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
278 AddDir(result
, SDL_AndroidGetInternalStoragePath());
279 if SDL_AndroidGetExternalStorageState() <> 0 then
280 AddDir(result
, SDL_AndroidGetExternalStoragePath());
285 function GetDefaultRWDirs (): SSArray
;
286 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
287 var home
: AnsiString
;
290 var appdata
: AnsiString
;
293 var bundle
, s
: AnsiString
; dirArr
: NSArray
; i
: Integer;
298 bundle
:= GetBundlePath();
299 if ExtractFileExt(bundle
) <> '.app' then
300 AddDir(result
, binPath
);
302 AddDir(result
, binPath
);
304 if forceBinDir
= false then
307 AddDir(result
, SDL_GetPrefPath('', 'doom2df'));
310 appdata
:= GetEnvironmentVariable('APPDATA') + '\doom2df';
311 if appdata
<> '' then
312 AddDir(result
, appdata
);
314 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
315 home
:= GetEnvironmentVariable('HOME');
317 AddDir(result
, e_CatPath(home
, '.doom2df'));
320 dirArr
:= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory
, NSUserDomainMask
, true);
321 for i
:= 0 to dirArr
.count
- 1 do
323 s
:= NSStringToAnsiString(dirArr
.objectAtIndex(i
));
324 AddDir(result
, e_CatPath(s
, 'Doom 2D Forever'))
327 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
328 if SDL_AndroidGetExternalStorageState() <> 0 then
329 AddDir(result
, SDL_AndroidGetExternalStoragePath());
335 forceBinDir
:= false;
336 binPath
:= GetBinaryPath();
339 while i
< ParamCount
do
342 '--like-windoze': forceBinDir
:= true;
346 rwdir
:= ParamStr(i
);
348 AddDir(LogDirs
, e_CatPath(rwdir
, 'logs'));
349 AddDir(SaveDirs
, e_CatPath(rwdir
, 'data/saves'));
350 AddDir(CacheDirs
, e_CatPath(rwdir
, 'data/cache'));
351 AddDir(ConfigDirs
, e_CatPath(rwdir
, ''));
352 AddDir(MapDownloadDirs
, e_CatPath(rwdir
, 'maps/downloads'));
353 AddDir(WadDownloadDirs
, e_CatPath(rwdir
, 'wads/downloads'));
354 AddDir(ScreenshotDirs
, e_CatPath(rwdir
, 'screenshots'));
355 AddDir(StatsDirs
, e_CatPath(rwdir
, 'stats'));
357 AddDir(DataDirs
, e_CatPath(rwdir
, 'data'));
358 AddDir(ModelDirs
, e_CatPath(rwdir
, 'data/models'));
359 AddDir(MegawadDirs
, e_CatPath(rwdir
, 'maps/megawads'));
360 AddDir(MapDirs
, e_CatPath(rwdir
, 'maps'));
361 AddDir(WadDirs
, e_CatPath(rwdir
, 'wads'));
366 rodir
:= ParamStr(i
);
368 AddDir(DataDirs
, e_CatPath(rodir
, 'data'));
369 AddDir(ModelDirs
, e_CatPath(rodir
, 'data/models'));
370 AddDir(MegawadDirs
, e_CatPath(rodir
, 'maps/megawads'));
371 AddDir(MapDirs
, e_CatPath(rodir
, 'maps'));
372 AddDir(WadDirs
, e_CatPath(rodir
, 'wads'));
377 GameWADName
:= ParamStr(i
);
382 gConfigScript
:= ParamStr(i
);
388 // prefer bin dir if it writable and contains game.wad
389 if forceBinDir
= false then
391 if findDiskWad(binPath
+ 'data' + '/' + GameWADName
) <> '' then
392 if e_CanCreateFilesAt(binPath
) then
397 rodirs
:= GetDefaultRODirs();
398 AddDef(DataDirs
, rodirs
, 'data');
399 AddDef(ModelDirs
, rodirs
, 'data/models');
400 AddDef(MegawadDirs
, rodirs
, 'maps/megawads');
401 AddDef(MapDirs
, rodirs
, 'maps');
402 AddDef(WadDirs
, rodirs
, 'wads');
405 rwdirs
:= GetDefaultRWDirs();
406 AddDef(LogDirs
, rwdirs
, 'logs');
407 AddDef(SaveDirs
, rwdirs
, 'data/saves');
408 AddDef(CacheDirs
, rwdirs
, 'data/cache');
409 AddDef(ConfigDirs
, rwdirs
, '');
410 AddDef(MapDownloadDirs
, rwdirs
, 'maps/downloads');
411 AddDef(WadDownloadDirs
, rwdirs
, 'wads/downloads');
412 AddDef(ScreenshotDirs
, rwdirs
, 'screenshots');
413 AddDef(StatsDirs
, rwdirs
, 'stats');
415 for i
:= 0 to High(MapDirs
) do
416 AddDir(AllMapDirs
, MapDirs
[i
]);
417 for i
:= 0 to High(MegawadDirs
) do
418 AddDir(AllMapDirs
, MegawadDirs
[i
]);
419 OptimizeDirs(AllMapDirs
);
421 if LogFileName
= '' then
423 rwdir
:= e_GetWriteableDir(LogDirs
, false);
426 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', Now());
428 LogFileName
:= e_CatPath(rwdir
, 'dfserver-' + date
+ '.log');
430 LogFileName
:= e_CatPath(rwdir
, 'dfclient-' + date
+ '.log');
435 // HACK: ensure the screenshots folder also has a stats subfolder in it
436 rwdir
:= e_GetWriteableDir(ScreenshotDirs
, false);
437 if rwdir
<> '' then CreateDir(rwdir
+ '/stats');
440 function InitPrep
: Boolean;
445 conbufDumpToStdOut
:= True;
447 for i
:= 1 to ParamCount
do
450 '--con-stdout': conbufDumpToStdOut
:= True;
451 '--no-fbo': glRenderToFBO
:= False;
455 if LogFileName
<> '' then
456 e_InitLog(LogFileName
, TWriteMode
.WM_NEWFILE
);
457 e_InitWritelnDriver();
458 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION
+ ' proto ' + IntToStr(NET_PROTOCOL_VER
), TMsgType
.Notify
);
459 e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType
.Notify
);
460 e_WriteLog('Build date: ' + GAME_BUILDDATE
+ ' ' + GAME_BUILDTIME
, TMsgType
.Notify
);
461 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType
.Notify
);
462 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType
.Notify
);
464 e_LogWritefln('Force bin dir: %s', [forceBinDir
], TMsgType
.Notify
);
465 e_LogWritefln('BINARY PATH: [%s]', [binPath
], TMsgType
.Notify
);
467 PrintDirs('DataDirs', DataDirs
);
468 PrintDirs('ModelDirs', ModelDirs
);
469 PrintDirs('MegawadDirs', MegawadDirs
);
470 PrintDirs('MapDirs', MapDirs
);
471 PrintDirs('WadDirs', WadDirs
);
473 PrintDirs('LogDirs', LogDirs
);
474 PrintDirs('SaveDirs', SaveDirs
);
475 PrintDirs('CacheDirs', CacheDirs
);
476 PrintDirs('ConfigDirs', ConfigDirs
);
477 PrintDirs('ScreenshotDirs', ScreenshotDirs
);
478 PrintDirs('StatsDirs', StatsDirs
);
479 PrintDirs('MapDownloadDirs', MapDownloadDirs
);
480 PrintDirs('WadDownloadDirs', WadDownloadDirs
);
482 GameWAD
:= e_FindWad(DataDirs
, GameWADName
);
485 e_WriteLog('WAD ' + GameWADName
+ ' not found in data directories.', TMsgType
.Fatal
);
486 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
487 if not forceBinDir
then
488 SDL_ShowSimpleMessageBox(
489 SDL_MESSAGEBOX_ERROR
,
491 PChar('WAD ' + GameWADName
+ ' not found in data directories.'),
496 exit
; // Halt(1) here will cause a memleak of strings GameWAD and "WAD <...> not found <...>"
503 {$IFDEF ENABLE_HOLMES}
504 var flexloaded
: Boolean;
508 if not InitPrep
then Halt(1);
512 g_Options_SetDefault
;
513 g_Options_SetDefaultVideo
;
515 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = False then
516 raise Exception
.Create('Failed to set videomode on startup.');
518 e_WriteLog(gLanguage
, TMsgType
.Notify
);
519 g_Language_Set(gLanguage
);
521 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
523 if not fuiAddWad('flexui.wad') then
525 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
528 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
529 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
530 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
531 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
532 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
533 except on e
: Exception
do
535 writeln('ERROR loading FlexUI fonts');
548 e_LogWriteln('FlexUI: loading stylesheet...');
549 uiLoadStyles('flexui/widgets.wgs');
550 except on e
: TParserException
do
552 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
563 g_holmes_imfunctional
:= not flexloaded
;
565 if (not g_holmes_imfunctional
) then
568 uiContext
.font
:= 'win14';
571 if assigned(oglInitCB
) then oglInitCB
;
574 //g_Res_CreateDatabases(true); // it will be done before connecting to the server for the first time
576 e_WriteLog('Entering SDLMain', TMsgType
.Notify
);
582 {$IFDEF ENABLE_HOLMES}
583 if assigned(oglDeinitCB
) then oglDeinitCB
;
586 g_Console_WriteGameConfig
;
591 {$IFDEF USE_SDLMIXER}
592 var timiditycfg
: AnsiString
;
593 var oldcwd
, newcwd
: RawByteString
;
595 var NoSound
: Boolean;
600 {$IFDEF USE_SDLMIXER}
601 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
603 NoSound
:= True; // FMOD backend will sort it out
612 if (e_JoysticksAvailable > 0) then
613 e_WriteLog('Input: Joysticks available.', TMsgType.Notify)
615 e_WriteLog('Input: No Joysticks.', TMsgType.Notify);
618 if gNoSound
= false then
620 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
621 {$IFDEF USE_SDLMIXER}
623 if UseNativeMusic
then
624 SetEnvVar('SDL_NATIVE_MUSIC', '1');
625 timiditycfg
:= GetEnvironmentVariable('TIMIDITY_CFG');
626 if timiditycfg
= '' then
628 timiditycfg
:= 'timidity.cfg';
629 if e_FindResource(ConfigDirs
, timiditycfg
) OR e_FindResource(DataDirs
, timiditycfg
) then
631 timiditycfg
:= ExpandFileName(timiditycfg
);
632 newcwd
:= ExtractFileDir(timiditycfg
);
633 SetEnvVar('TIMIDITY_CFG', timiditycfg
);
638 e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg
]);
639 e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
641 e_InitSoundSystem(NoSound
);
642 {$IFDEF USE_SDLMIXER}
643 if e_TimidityDecoder
and (newcwd
<> '') then
645 (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
646 (* CWD not restored after sound init because timidity *)
647 (* store relative pathes internally and load patches *)
648 (* later. I hope game never relies on CWD. *)
652 e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd
, newcwd
]);
657 e_WriteLog('Init game', TMsgType
.Notify
);
660 FillChar(charbuff
, sizeof(charbuff
), ' ');
666 e_WriteLog('Releasing engine', TMsgType
.Notify
);
669 e_WriteLog('Releasing input', TMsgType
.Notify
);
674 e_WriteLog('Releasing sound', TMsgType
.Notify
);
675 e_ReleaseSoundSystem();
682 // remember old mobj positions, prepare for update
684 // server: receive client commands for new frame
685 // client: receive game state changes from server
686 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
687 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
690 // server: send any accumulated outgoing data to clients
691 if NetMode
= NET_SERVER
then g_Net_Flush();
701 function Translit (const S
: AnsiString
): AnsiString
;
706 for i
:= 1 to Length(Result
) do
709 'É': Result
[i
] := 'Q';
710 'Ö': Result
[i
] := 'W';
711 'Ó': Result
[i
] := 'E';
712 'Ê': Result
[i
] := 'R';
713 'Å': Result
[i
] := 'T';
714 'Í': Result
[i
] := 'Y';
715 'Ã': Result
[i
] := 'U';
716 'Ø': Result
[i
] := 'I';
717 'Ù': Result
[i
] := 'O';
718 'Ç': Result
[i
] := 'P';
719 'Õ': Result
[i
] := '['; //Chr(219);
720 'Ú': Result
[i
] := ']'; //Chr(221);
721 'Ô': Result
[i
] := 'A';
722 'Û': Result
[i
] := 'S';
723 'Â': Result
[i
] := 'D';
724 'À': Result
[i
] := 'F';
725 'Ï': Result
[i
] := 'G';
726 'Ð': Result
[i
] := 'H';
727 'Î': Result
[i
] := 'J';
728 'Ë': Result
[i
] := 'K';
729 'Ä': Result
[i
] := 'L';
730 'Æ': Result
[i
] := ';'; //Chr(186);
731 'Ý': Result
[i
] := #39; //Chr(222);
732 'ß': Result
[i
] := 'Z';
733 '×': Result
[i
] := 'X';
734 'Ñ': Result
[i
] := 'C';
735 'Ì': Result
[i
] := 'V';
736 'È': Result
[i
] := 'B';
737 'Ò': Result
[i
] := 'N';
738 'Ü': Result
[i
] := 'M';
739 'Á': Result
[i
] := ','; //Chr(188);
740 'Þ': Result
[i
] := '.'; //Chr(190);
746 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
751 ls2
:= Translit(CheatRus
[ct
]);
752 if length(ls1
) = 0 then ls1
:= '~';
753 if length(ls2
) = 0 then ls2
:= '~';
755 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
756 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
757 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
758 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
760 if ct = I_GAME_CHEAT_JETPACK then
762 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
763 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
764 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
765 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
766 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
767 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
784 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
785 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
786 or g_Game_IsNet then Exit;
788 if not gGameOn
then exit
;
789 if not conIsCheatsEnabled
then exit
;
791 s
:= 'SOUND_GAME_RADIO';
794 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
796 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
797 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
801 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
803 if gPlayer1
<> nil then gPlayer1
.TankRamboCheats(False);
804 if gPlayer2
<> nil then gPlayer2
.TankRamboCheats(False);
808 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
810 if gPlayer1
<> nil then gPlayer1
.TankRamboCheats(True);
811 if gPlayer2
<> nil then gPlayer2
.TankRamboCheats(True);
815 if CheckCheat(I_GAME_CHEAT_DEATH
) then
817 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
818 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
819 s
:= 'SOUND_MONSTER_HAHA';
823 if CheckCheat(I_GAME_CHEAT_DOORS
) then
825 g_Triggers_OpenAll();
829 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
831 if gTriggers
<> nil then
832 for a
:= 0 to High(gTriggers
) do
833 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
835 gExitByTrigger
:= True;
836 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
837 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
843 s2
:= Copy(charbuff
, 15, 2);
844 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
846 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
854 if CheckCheat(I_GAME_CHEAT_FLY
) then
860 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
862 VEL_JUMP
:= 30-VEL_JUMP
;
866 if CheckCheat(I_GAME_CHEAT_SPEED
) then
868 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
872 if CheckCheat(I_GAME_CHEAT_SUIT
) then
874 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
875 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
879 if CheckCheat(I_GAME_CHEAT_AIR
) then
881 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
882 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
886 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
888 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
889 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
893 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
895 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
896 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
900 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
902 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
903 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
907 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
909 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
910 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
914 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
916 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
917 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
920 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
922 gAimLine
:= not gAimLine
;
925 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
927 gShowMap
:= not gShowMap
;
937 procedure KeyPress (K
: Word);
947 if (g_ActiveWindow
<> nil) then
949 Msg
.Msg
:= WM_KEYDOWN
;
950 Msg
.WParam
:= VK_ESCAPE
;
951 g_ActiveWindow
.OnMessage(Msg
);
952 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
954 else if (gState
<> STATE_FOLD
) then
956 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
958 g_Game_InGameMenu(True);
960 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
962 if (gState
<> STATE_MENU
) then
964 if (NetMode
<> NET_NONE
) then
966 g_Game_StopAllSounds(True);
968 gState
:= STATE_MENU
;
972 g_GUI_ShowWindow('MainMenu');
973 g_Sound_PlayEx('MENU_OPEN');
978 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
979 begin // <F2> .. <F6> � <F12>
980 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
982 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
983 if (not g_Game_IsNet
) then g_Game_Pause(True);
985 IK_F2
: g_Menu_Show_SaveMenu();
986 IK_F3
: g_Menu_Show_LoadMenu();
987 IK_F4
: g_Menu_Show_GameSetGame();
988 IK_F5
: g_Menu_Show_OptionsVideo();
989 IK_F6
: g_Menu_Show_OptionsSound();
990 IK_F7
: g_Menu_Show_EndGameMenu();
991 IK_F10
: g_Menu_Show_QuitGameMenu();
998 gJustChatted
:= False;
999 if gConsoleShow
or gChatShow
then
1001 g_Console_Control(K
);
1003 else if (g_ActiveWindow
<> nil) then
1005 Msg
.Msg
:= WM_KEYDOWN
;
1007 g_ActiveWindow
.OnMessage(Msg
);
1009 else if (gState
= STATE_MENU
) then
1011 g_GUI_ShowWindow('MainMenu');
1012 g_Sound_PlayEx('MENU_OPEN');
1020 procedure CharPress (C
: AnsiChar
);
1022 Msg
: g_gui
.TMessage
;
1025 if gConsoleShow
or gChatShow
then
1029 else if (g_ActiveWindow
<> nil) then
1032 Msg
.WParam
:= Ord(C
);
1033 g_ActiveWindow
.OnMessage(Msg
);
1037 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
1038 charbuff
[15] := upcase1251(C
);
1044 {$IFDEF USE_SDLMIXER}
1045 conRegVar('sdl_native_music', @UseNativeMusic
, 'use native midi music output when possible', 'use native midi');
1047 UseNativeMusic
:= true; (* OSX have a good midi support, so why not? *)
1049 UseNativeMusic
:= false;