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
;
54 {$INCLUDE ../nogl/noGLuses.inc}
55 {$IFDEF ENABLE_HOLMES}
56 g_holmes
, sdlcarcass
, fui_ctls
, fui_wadread
, fui_style
, fui_gfx_gl
,
67 wadreader
, e_log
, g_window
,
68 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
69 e_sound
, g_options
, g_sound
, g_player
, g_basic
,
70 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
, e_res
,
71 g_menu
, g_language
, g_net
, g_touch
, g_system
, g_res_downloader
,
77 charbuff
: packed array [0..15] of AnsiChar;
78 binPath
: AnsiString = '';
81 function GetBinaryPath (): AnsiString;
88 result
:= ExtractFilePath(ParamStr(0));
90 // it may be a symlink; do some guesswork here
91 sl
:= fpReadLink(ExtractFileName(ParamStr(0)));
92 if (sl
= ParamStr(0)) then
94 // use current directory, as we don't have anything better
99 result
:= fixSlashes(result
);
100 if (length(result
) > 0) and (result
[length(result
)] <> '/') then result
:= result
+'/';
103 procedure PrintDirs (msg
: AnsiString; dirs
: SSArray
);
106 e_LogWriteln(msg
+ ':');
108 e_LogWriteln(' ' + dir
);
112 function NSStringToAnsiString (s
: NSString
): AnsiString;
116 for i
:= 0 to s
.length
- 1 do
117 result
:= result
+ AnsiChar(s
.characterAtIndex(i
));
120 function GetBundlePath (): AnsiString;
121 var pathRef
: CFURLRef
; pathCFStr
: CFStringRef
; pathStr
: ShortString;
123 pathRef
:= CFBundleCopyBundleURL(CFBundleGetMainBundle());
124 pathCFStr
:= CFURLCopyFileSystemPath(pathRef
, kCFURLPOSIXPathStyle
);
125 CFStringGetPascalString(pathCFStr
, @pathStr
, 255, CFStringGetSystemEncoding());
127 CFRelease(pathCFStr
);
133 var i
: Integer; rwdir
, rodir
: AnsiString; rwdirs
, rodirs
: SSArray
;
135 procedure AddDir (var dirs
: SSArray
; append
: AnsiString);
137 SetLength(dirs
, Length(dirs
) + 1);
138 dirs
[High(dirs
)] := ExpandFileName(append
)
141 function IsSep (ch
: Char): Boolean;
144 result
:= (ch
= '/') or (ch
= '\');
146 result
:= (ch
= '/');
150 function OptimizePath (dir
: AnsiString): AnsiString;
151 var i
, len
: Integer; s
: AnsiString;
153 i
:= 1; len
:= Length(dir
); s
:= '';
156 if IsSep(dir
[i
]) then
158 s
:= s
+ DirectorySeparator
;
160 while (i
<= len
) and IsSep(dir
[i
]) do Inc(i
);
161 if (i
<= len
) and (dir
[i
] = '.') then
163 if (i
= len
) or IsSep(dir
[i
+ 1]) then
167 else if (i
+ 1 <= len
) and (dir
[i
+ 1] = '.') then
169 if (i
+ 1 = len
) or IsSep(dir
[i
+ 2]) then
186 procedure OptimizeDirs (var dirs
: SSArray
);
187 var i
, j
, k
: Integer;
189 for i
:= 0 to High(dirs
) do
190 dirs
[i
] := OptimizePath(dirs
[i
]);
198 if dirs
[j
] = dirs
[i
] then
200 for k
:= j
+ 1 to High(dirs
) do
201 dirs
[k
- 1] := dirs
[k
];
203 SetLength(dirs
, High(dirs
))
214 procedure AddDef (var dirs
: SSArray
; base
: SSArray
; append
: AnsiString);
217 if Length(dirs
) = 0 then
219 AddDir(dirs
, e_CatPath(s
, append
));
223 function GetDefaultRODirs (): SSArray
;
224 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
225 var home
: AnsiString;
228 var appdata
: AnsiString;
231 var bundle
, s
: AnsiString; dirArr
: NSArray
; i
: Integer;
236 bundle
:= GetBundlePath();
237 if ExtractFileExt(bundle
) <> '.app' then
238 AddDir(result
, binpath
);
240 AddDir(result
, binPath
);
242 if forceBinDir
= false then
245 AddDir(result
, SDL_GetBasePath());
246 AddDir(result
, SDL_GetPrefPath('', 'doom2df'));
249 appdata
:= GetEnvironmentVariable('APPDATA') + '\doom2df';
250 if appdata
<> '' then
251 AddDir(result
, appdata
);
253 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
254 AddDir(result
, '/usr/share/doom2df');
255 AddDir(result
, '/usr/local/share/doom2df');
256 home
:= GetEnvironmentVariable('HOME');
258 AddDir(result
, e_CatPath(home
, '.doom2df'));
261 bundle
:= GetBundlePath();
263 AddDir(result
, e_CatPath(bundle
, 'Contents/Resources'));
264 dirArr
:= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory
, NSUserDomainMask
, true);
265 for i
:= 0 to dirArr
.count
- 1 do
267 s
:= NSStringToAnsiString(dirArr
.objectAtIndex(i
));
268 AddDir(result
, e_CatPath(s
, 'Doom 2D Forever'))
271 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
272 AddDir(result
, SDL_AndroidGetInternalStoragePath());
273 if SDL_AndroidGetExternalStorageState() <> 0 then
274 AddDir(result
, SDL_AndroidGetExternalStoragePath());
279 function GetDefaultRWDirs (): SSArray
;
280 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
281 var home
: AnsiString;
284 var appdata
: AnsiString;
287 var bundle
, s
: AnsiString; dirArr
: NSArray
; i
: Integer;
292 bundle
:= GetBundlePath();
293 if ExtractFileExt(bundle
) <> '.app' then
294 AddDir(result
, binPath
);
296 AddDir(result
, binPath
);
298 if forceBinDir
= false then
301 AddDir(result
, SDL_GetPrefPath('', 'doom2df'));
304 appdata
:= GetEnvironmentVariable('APPDATA') + '\doom2df';
305 if appdata
<> '' then
306 AddDir(result
, appdata
);
308 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
309 home
:= GetEnvironmentVariable('HOME');
311 AddDir(result
, e_CatPath(home
, '.doom2df'));
314 dirArr
:= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory
, NSUserDomainMask
, true);
315 for i
:= 0 to dirArr
.count
- 1 do
317 s
:= NSStringToAnsiString(dirArr
.objectAtIndex(i
));
318 AddDir(result
, e_CatPath(s
, 'Doom 2D Forever'))
321 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
322 if SDL_AndroidGetExternalStorageState() <> 0 then
323 AddDir(result
, SDL_AndroidGetExternalStoragePath());
329 forceBinDir
:= false;
330 binPath
:= GetBinaryPath();
333 while i
< ParamCount
do
336 '--like-windoze': forceBinDir
:= true;
340 rwdir
:= ParamStr(i
);
342 AddDir(LogDirs
, e_CatPath(rwdir
, ''));
343 AddDir(SaveDirs
, e_CatPath(rwdir
, 'data'));
344 AddDir(CacheDirs
, e_CatPath(rwdir
, 'data/cache'));
345 AddDir(ConfigDirs
, e_CatPath(rwdir
, ''));
346 AddDir(MapDownloadDirs
, e_CatPath(rwdir
, 'maps/downloads'));
347 AddDir(WadDownloadDirs
, e_CatPath(rwdir
, 'wads/downloads'));
348 AddDir(ScreenshotDirs
, e_CatPath(rwdir
, 'screenshots'));
349 AddDir(StatsDirs
, e_CatPath(rwdir
, 'stats'));
351 AddDir(DataDirs
, e_CatPath(rwdir
, 'data'));
352 AddDir(ModelDirs
, e_CatPath(rwdir
, 'data/models'));
353 AddDir(MegawadDirs
, e_CatPath(rwdir
, 'maps/megawads'));
354 AddDir(MapDirs
, e_CatPath(rwdir
, 'maps'));
355 AddDir(WadDirs
, e_CatPath(rwdir
, 'wads'));
360 rodir
:= ParamStr(i
);
362 AddDir(DataDirs
, e_CatPath(rodir
, 'data'));
363 AddDir(ModelDirs
, e_CatPath(rodir
, 'data/models'));
364 AddDir(MegawadDirs
, e_CatPath(rodir
, 'maps/megawads'));
365 AddDir(MapDirs
, e_CatPath(rodir
, 'maps'));
366 AddDir(WadDirs
, e_CatPath(rodir
, 'wads'));
372 // prefer bin dir if it writable and contains game.wad
373 if forceBinDir
= false then
375 if findDiskWad(binPath
+ 'data' + '/' + 'GAME') <> '' then
376 if e_CanCreateFilesAt(binPath
) then
381 rodirs
:= GetDefaultRODirs();
382 AddDef(DataDirs
, rodirs
, 'data');
383 AddDef(ModelDirs
, rodirs
, 'data/models');
384 AddDef(MegawadDirs
, rodirs
, 'maps/megawads');
385 AddDef(MapDirs
, rodirs
, 'maps');
386 AddDef(WadDirs
, rodirs
, 'wads');
389 rwdirs
:= GetDefaultRWDirs();
390 AddDef(LogDirs
, rwdirs
, '');
391 AddDef(SaveDirs
, rwdirs
, 'data');
392 AddDef(CacheDirs
, rwdirs
, 'data/cache');
393 AddDef(ConfigDirs
, rwdirs
, '');
394 AddDef(MapDownloadDirs
, rwdirs
, 'maps/downloads');
395 AddDef(WadDownloadDirs
, rwdirs
, 'wads/downloads');
396 AddDef(ScreenshotDirs
, rwdirs
, 'screenshots');
397 AddDef(StatsDirs
, rwdirs
, 'stats');
399 for i
:= 0 to High(MapDirs
) do
400 AddDir(AllMapDirs
, MapDirs
[i
]);
401 for i
:= 0 to High(MegawadDirs
) do
402 AddDir(AllMapDirs
, MegawadDirs
[i
]);
403 OptimizeDirs(AllMapDirs
);
405 if LogFileName
= '' then
407 rwdir
:= e_GetWriteableDir(LogDirs
, false);
411 LogFileName
:= e_CatPath(rwdir
, 'Doom2DF_H.log');
413 LogFileName
:= e_CatPath(rwdir
, 'Doom2DF.log');
418 // HACK: ensure the screenshots folder also has a stats subfolder in it
419 rwdir
:= e_GetWriteableDir(ScreenshotDirs
, false);
420 if rwdir
<> '' then CreateDir(rwdir
+ '/stats');
424 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDLMIXER)}
425 var timiditycfg
: AnsiString;
430 conbufDumpToStdOut
:= true;
432 for i
:= 1 to ParamCount
do
434 if (ParamStr(i
) = '--con-stdout') then
436 conbufDumpToStdOut
:= true;
441 if LogFileName
<> '' then
442 e_InitLog(LogFileName
, TWriteMode
.WM_NEWFILE
);
443 e_InitWritelnDriver();
444 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION
+ ' proto ' + IntToStr(NET_PROTOCOL_VER
), TMsgType
.Notify
);
445 e_WriteLog('Build date: ' + GAME_BUILDDATE
+ ' ' + GAME_BUILDTIME
, TMsgType
.Notify
);
446 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType
.Notify
);
447 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType
.Notify
);
449 e_LogWritefln('Force bin dir: %s', [forceBinDir
], TMsgType
.Notify
);
450 e_LogWritefln('BINARY PATH: [%s]', [binPath
], TMsgType
.Notify
);
452 PrintDirs('DataDirs', DataDirs
);
453 PrintDirs('ModelDirs', ModelDirs
);
454 PrintDirs('MegawadDirs', MegawadDirs
);
455 PrintDirs('MapDirs', MapDirs
);
456 PrintDirs('WadDirs', WadDirs
);
458 PrintDirs('LogDirs', LogDirs
);
459 PrintDirs('SaveDirs', SaveDirs
);
460 PrintDirs('CacheDirs', CacheDirs
);
461 PrintDirs('ConfigDirs', ConfigDirs
);
462 PrintDirs('ScreenshotDirs', ScreenshotDirs
);
463 PrintDirs('StatsDirs', StatsDirs
);
464 PrintDirs('MapDownloadDirs', MapDownloadDirs
);
465 PrintDirs('WadDownloadDirs', WadDownloadDirs
);
467 GameWAD
:= e_FindWad(DataDirs
, 'GAME');
470 e_WriteLog('GAME.WAD not installed?', TMsgType
.Fatal
);
471 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
472 if forceBinDir
= false then
473 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR
, 'Doom 2D Forever', 'GAME.WAD not installed?', nil);
479 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDLMIXER)}
480 timiditycfg
:= 'timidity.cfg';
481 if e_FindResource(ConfigDirs
, timiditycfg
) = true then
483 timiditycfg
:= ExpandFileName(timiditycfg
);
484 SetEnvVar('TIMIDITY_CFG', timiditycfg
);
485 e_LogWritefln('Set TIMIDITY_CFG = "%s"', [timiditycfg
]);
491 {$IFDEF ENABLE_HOLMES}
492 var flexloaded
: Boolean;
501 g_Options_SetDefault
;
502 g_Options_SetDefaultVideo
;
503 s
:= CONFIG_FILENAME
;
504 if e_FindResource(ConfigDirs
, s
) = true then
507 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = False then
508 raise Exception
.Create('Failed to set videomode on startup.');
510 e_WriteLog(gLanguage
, TMsgType
.Notify
);
511 g_Language_Set(gLanguage
);
513 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
515 if not fuiAddWad('flexui.wad') then
517 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
520 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
521 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
522 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
523 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
524 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
525 except on e
: Exception
do
527 writeln('ERROR loading FlexUI fonts');
540 e_LogWriteln('FlexUI: loading stylesheet...');
541 uiLoadStyles('flexui/widgets.wgs');
542 except on e
: TParserException
do
544 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
555 g_holmes_imfunctional
:= not flexloaded
;
557 if (not g_holmes_imfunctional
) then
560 uiContext
.font
:= 'win14';
563 if assigned(oglInitCB
) then oglInitCB
;
566 //g_Res_CreateDatabases(true); // it will be done before connecting to the server for the first time
568 e_WriteLog('Entering SDLMain', TMsgType
.Notify
);
574 {$IFDEF ENABLE_HOLMES}
575 if assigned(oglDeinitCB
) then oglDeinitCB
;
578 g_Console_WriteGameConfig
;
589 {$IFDEF USE_SDLMIXER}
590 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
592 NoSound
:= True; // FMOD backend will sort it out
601 if (e_JoysticksAvailable > 0) then
602 e_WriteLog('Input: Joysticks available.', TMsgType.Notify)
604 e_WriteLog('Input: No Joysticks.', TMsgType.Notify);
607 if (not gNoSound
) then
609 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
610 e_InitSoundSystem(NoSound
);
613 e_WriteLog('Init game', TMsgType
.Notify
);
616 FillChar(charbuff
, sizeof(charbuff
), ' ');
622 e_WriteLog('Releasing engine', TMsgType
.Notify
);
625 e_WriteLog('Releasing input', TMsgType
.Notify
);
630 e_WriteLog('Releasing sound', TMsgType
.Notify
);
631 e_ReleaseSoundSystem();
648 function Translit (const S
: AnsiString): AnsiString;
653 for i
:= 1 to Length(Result
) do
656 'É': Result
[i
] := 'Q';
657 'Ö': Result
[i
] := 'W';
658 'Ó': Result
[i
] := 'E';
659 'Ê': Result
[i
] := 'R';
660 'Å': Result
[i
] := 'T';
661 'Í': Result
[i
] := 'Y';
662 'Ã': Result
[i
] := 'U';
663 'Ø': Result
[i
] := 'I';
664 'Ù': Result
[i
] := 'O';
665 'Ç': Result
[i
] := 'P';
666 'Õ': Result
[i
] := '['; //Chr(219);
667 'Ú': Result
[i
] := ']'; //Chr(221);
668 'Ô': Result
[i
] := 'A';
669 'Û': Result
[i
] := 'S';
670 'Â': Result
[i
] := 'D';
671 'À': Result
[i
] := 'F';
672 'Ï': Result
[i
] := 'G';
673 'Ð': Result
[i
] := 'H';
674 'Î': Result
[i
] := 'J';
675 'Ë': Result
[i
] := 'K';
676 'Ä': Result
[i
] := 'L';
677 'Æ': Result
[i
] := ';'; //Chr(186);
678 'Ý': Result
[i
] := #39; //Chr(222);
679 'ß': Result
[i
] := 'Z';
680 '×': Result
[i
] := 'X';
681 'Ñ': Result
[i
] := 'C';
682 'Ì': Result
[i
] := 'V';
683 'È': Result
[i
] := 'B';
684 'Ò': Result
[i
] := 'N';
685 'Ü': Result
[i
] := 'M';
686 'Á': Result
[i
] := ','; //Chr(188);
687 'Þ': Result
[i
] := '.'; //Chr(190);
693 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
698 ls2
:= Translit(CheatRus
[ct
]);
699 if length(ls1
) = 0 then ls1
:= '~';
700 if length(ls2
) = 0 then ls2
:= '~';
702 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
703 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
704 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
705 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
707 if ct = I_GAME_CHEAT_JETPACK then
709 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
710 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
711 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
712 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
713 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
714 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
731 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
732 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
733 or g_Game_IsNet then Exit;
735 if not gGameOn
then exit
;
736 if not conIsCheatsEnabled
then exit
;
738 s
:= 'SOUND_GAME_RADIO';
741 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
743 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
744 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
748 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
750 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
751 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
755 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
757 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
758 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
762 if CheckCheat(I_GAME_CHEAT_DEATH
) then
764 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
765 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
766 s
:= 'SOUND_MONSTER_HAHA';
770 if CheckCheat(I_GAME_CHEAT_DOORS
) then
772 g_Triggers_OpenAll();
776 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
778 if gTriggers
<> nil then
779 for a
:= 0 to High(gTriggers
) do
780 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
782 gExitByTrigger
:= True;
783 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
784 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
790 s2
:= Copy(charbuff
, 15, 2);
791 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
793 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
801 if CheckCheat(I_GAME_CHEAT_FLY
) then
807 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
809 VEL_JUMP
:= 30-VEL_JUMP
;
813 if CheckCheat(I_GAME_CHEAT_SPEED
) then
815 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
819 if CheckCheat(I_GAME_CHEAT_SUIT
) then
821 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
822 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
826 if CheckCheat(I_GAME_CHEAT_AIR
) then
828 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
829 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
833 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
835 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
836 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
840 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
842 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
843 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
847 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
849 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
850 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
854 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
856 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
857 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
861 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
863 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
864 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
867 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
869 gAimLine
:= not gAimLine
;
872 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
874 gShowMap
:= not gShowMap
;
884 procedure KeyPress (K
: Word);
894 if (g_ActiveWindow
<> nil) then
896 Msg
.Msg
:= WM_KEYDOWN
;
897 Msg
.WParam
:= VK_ESCAPE
;
898 g_ActiveWindow
.OnMessage(Msg
);
899 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
901 else if (gState
<> STATE_FOLD
) then
903 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
905 g_Game_InGameMenu(True);
907 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
909 if (gState
<> STATE_MENU
) then
911 if (NetMode
<> NET_NONE
) then
913 g_Game_StopAllSounds(True);
915 gState
:= STATE_MENU
;
919 g_GUI_ShowWindow('MainMenu');
920 g_Sound_PlayEx('MENU_OPEN');
925 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
926 begin // <F2> .. <F6> � <F12>
927 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
929 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
930 if (not g_Game_IsNet
) then g_Game_Pause(True);
932 IK_F2
: g_Menu_Show_SaveMenu();
933 IK_F3
: g_Menu_Show_LoadMenu();
934 IK_F4
: g_Menu_Show_GameSetGame();
935 IK_F5
: g_Menu_Show_OptionsVideo();
936 IK_F6
: g_Menu_Show_OptionsSound();
937 IK_F7
: g_Menu_Show_EndGameMenu();
938 IK_F10
: g_Menu_Show_QuitGameMenu();
945 gJustChatted
:= False;
946 if gConsoleShow
or gChatShow
then
948 g_Console_Control(K
);
950 else if (g_ActiveWindow
<> nil) then
952 Msg
.Msg
:= WM_KEYDOWN
;
954 g_ActiveWindow
.OnMessage(Msg
);
956 else if (gState
= STATE_MENU
) then
958 g_GUI_ShowWindow('MainMenu');
959 g_Sound_PlayEx('MENU_OPEN');
967 procedure CharPress (C
: AnsiChar);
972 if gConsoleShow
or gChatShow
then
976 else if (g_ActiveWindow
<> nil) then
979 Msg
.WParam
:= Ord(C
);
980 g_ActiveWindow
.OnMessage(Msg
);
984 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
985 charbuff
[15] := upcase1251(C
);