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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
26 procedure KeyPress(K
: Word);
27 procedure CharPress(C
: Char);
39 SDL2
, GL
, GLExt
, wadreader
, e_log
, g_window
,
40 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
41 e_sound
, g_options
, g_sound
, g_player
,
42 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
,
43 g_menu
, g_language
, g_net
,
44 utils
, conbuf
, envvars
;
47 charbuff
: Array [0..15] of Char;
53 e_InitWritelnDriver();
56 MapsDir
:= GameDir
+ '/maps/';
57 DataDir
:= GameDir
+ '/data/';
58 ModelsDir
:= DataDir
+ 'models/';
59 GameWAD
:= DataDir
+ 'Game.wad';
61 e_InitLog(GameDir
+ '/' + LOG_FILENAME
, TWriteMode
.WM_NEWFILE
);
63 e_WriteLog('Read config file', TMsgType
.Notify
);
64 g_Options_Read(GameDir
+ '/' + CONFIG_FILENAME
);
67 conbufDumpToStdOut
:= true;
69 e_WriteToStdOut
:= False; //{$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
71 //GetSystemDefaultLCID()
73 //e_WriteLog('Read language file', MSG_NOTIFY);
74 //g_Language_Load(DataDir + gLanguage + '.txt');
75 e_WriteLog(gLanguage
, TMsgType
.Notify
);
76 g_Language_Set(gLanguage
);
80 sdlflags
:= SDL_INIT_TIMER
or SDL_INIT_AUDIO
or $00004000;
81 // HACK: shit this into env and hope for the best
82 SetEnvVar('SDL_AUDIODRIVER', 'dummy');
84 sdlflags
:= SDL_INIT_TIMER
or $00004000;
88 sdlflags
:= SDL_INIT_EVERYTHING
;
90 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
93 if SDL_Init(sdlflags
) < 0 then
94 raise Exception
.Create('SDL: Init failed: ' + SDL_GetError());
100 e_WriteLog('Entering SDLMain', TMsgType
.Notify
);
110 e_WriteLog('Releasing SDL', TMsgType
.Notify
);
122 {$IFDEF USE_SDLMIXER}
123 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
125 NoSound
:= True; // FMOD backend will sort it out
131 e_WriteLog('Init Input', TMsgType
.Notify
);
134 if (e_JoysticksAvailable
> 0) then
135 e_WriteLog('Input: Joysticks available.', TMsgType
.Notify
)
137 e_WriteLog('Input: No Joysticks.', TMsgType
.Notify
);
139 if (not gNoSound
) then
141 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
142 e_InitSoundSystem(NoSound
);
145 e_WriteLog('Init game', TMsgType
.Notify
);
148 for a
:= 0 to 15 do charbuff
[a
] := ' ';
153 e_WriteLog('Releasing engine', TMsgType
.Notify
);
156 e_WriteLog('Releasing Input', TMsgType
.Notify
);
161 e_WriteLog('Releasing FMOD', TMsgType
.Notify
);
162 e_ReleaseSoundSystem();
176 function Translit(S
: String): String;
181 for i
:= 1 to Length(Result
) do
183 'É': Result
[i
] := 'Q';
184 'Ö': Result
[i
] := 'W';
185 'Ó': Result
[i
] := 'E';
186 'Ê': Result
[i
] := 'R';
187 'Å': Result
[i
] := 'T';
188 'Í': Result
[i
] := 'Y';
189 'Ã': Result
[i
] := 'U';
190 'Ø': Result
[i
] := 'I';
191 'Ù': Result
[i
] := 'O';
192 'Ç': Result
[i
] := 'P';
193 'Õ': Result
[i
] := '['; //Chr(219);
194 'Ú': Result
[i
] := ']'; //Chr(221);
195 'Ô': Result
[i
] := 'A';
196 'Û': Result
[i
] := 'S';
197 'Â': Result
[i
] := 'D';
198 'À': Result
[i
] := 'F';
199 'Ï': Result
[i
] := 'G';
200 'Ð': Result
[i
] := 'H';
201 'Î': Result
[i
] := 'J';
202 'Ë': Result
[i
] := 'K';
203 'Ä': Result
[i
] := 'L';
204 'Æ': Result
[i
] := ';'; //Chr(186);
205 'Ý': Result
[i
] := #39; //Chr(222);
206 'ß': Result
[i
] := 'Z';
207 '×': Result
[i
] := 'X';
208 'Ñ': Result
[i
] := 'C';
209 'Ì': Result
[i
] := 'V';
210 'È': Result
[i
] := 'B';
211 'Ò': Result
[i
] := 'N';
212 'Ü': Result
[i
] := 'M';
213 'Á': Result
[i
] := ','; //Chr(188);
214 'Þ': Result
[i
] := '.'; //Chr(190);
219 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
224 ls2
:= Translit(CheatRus
[ct
]);
225 if length(ls1
) = 0 then ls1
:= '~';
226 if length(ls2
) = 0 then ls2
:= '~';
228 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
229 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
230 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
231 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
233 if ct = I_GAME_CHEAT_JETPACK then
235 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
236 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
237 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
238 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
239 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
240 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
257 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
258 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
259 or g_Game_IsNet then Exit;
261 if not gGameOn
then exit
;
262 if not conIsCheatsEnabled
then exit
;
264 s
:= 'SOUND_GAME_RADIO';
267 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
269 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
270 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
274 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
276 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
277 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
281 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
283 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
284 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
288 if CheckCheat(I_GAME_CHEAT_DEATH
) then
290 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
291 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
292 s
:= 'SOUND_MONSTER_HAHA';
296 if CheckCheat(I_GAME_CHEAT_DOORS
) then
298 g_Triggers_OpenAll();
302 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
304 if gTriggers
<> nil then
305 for a
:= 0 to High(gTriggers
) do
306 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
308 gExitByTrigger
:= True;
309 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
310 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
316 s2
:= Copy(charbuff
, 15, 2);
317 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
319 if g_Map_Exist(MapsDir
+gGameSettings
.WAD
+':\MAP'+s2
) then
329 if CheckCheat(I_GAME_CHEAT_FLY
) then
335 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
337 VEL_JUMP
:= 30-VEL_JUMP
;
341 if CheckCheat(I_GAME_CHEAT_SPEED
) then
343 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
347 if CheckCheat(I_GAME_CHEAT_SUIT
) then
349 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
350 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
354 if CheckCheat(I_GAME_CHEAT_AIR
) then
356 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
357 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
361 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
363 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
364 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
368 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
370 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
371 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
375 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
377 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
378 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
382 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
384 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
385 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
389 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
391 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
392 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
395 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
397 gAimLine
:= not gAimLine
;
400 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
402 gShowMap
:= not gShowMap
;
411 procedure KeyPress(K
: Word);
416 IK_PAUSE
: // <Pause/Break>:
418 if (g_ActiveWindow
= nil) then
419 g_Game_Pause(not gPause
);
422 IK_BACKQUOTE
: // <`/~/¨/¸>:
431 g_Console_Chat_Switch();
438 if g_ActiveWindow
<> nil then
440 Msg
.Msg
:= WM_KEYDOWN
;
441 Msg
.WParam
:= IK_ESCAPE
;
442 g_ActiveWindow
.OnMessage(Msg
);
445 if gState
<> STATE_FOLD
then
447 or (gState
= STATE_INTERSINGLE
)
448 or (gState
= STATE_INTERCUSTOM
)
450 g_Game_InGameMenu(True)
452 if (gExit
= 0) and (gState
<> STATE_SLIST
) then
454 if gState
<> STATE_MENU
then
455 if NetMode
<> NET_NONE
then
457 g_Game_StopAllSounds(True);
459 gState
:= STATE_MENU
;
463 g_GUI_ShowWindow('MainMenu');
464 g_Sound_PlayEx('MENU_OPEN');
468 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
469 begin // <F2> .. <F6> � <F12>
470 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
472 while g_ActiveWindow
<> nil do
473 g_GUI_HideWindow(False);
475 if (not g_Game_IsNet
) then
480 g_Menu_Show_SaveMenu();
482 g_Menu_Show_LoadMenu();
484 g_Menu_Show_GameSetGame();
486 g_Menu_Show_OptionsVideo();
488 g_Menu_Show_OptionsSound();
490 g_Menu_Show_EndGameMenu();
492 g_Menu_Show_QuitGameMenu();
499 gJustChatted
:= False;
500 if gConsoleShow
or gChatShow
then
503 if g_ActiveWindow
<> nil then
505 Msg
.Msg
:= WM_KEYDOWN
;
507 g_ActiveWindow
.OnMessage(Msg
);
511 if (gState
= STATE_MENU
) then
513 g_GUI_ShowWindow('MainMenu');
514 g_Sound_PlayEx('MENU_OPEN');
521 procedure CharPress(C
: Char);
526 if (not gChatShow
) and ((C
= '`') or (C
= '~') or (C
= '¸') or (C
= '¨')) then
529 if gConsoleShow
or gChatShow
then
532 if g_ActiveWindow
<> nil then
535 Msg
.WParam
:= Ord(C
);
536 g_ActiveWindow
.OnMessage(Msg
);
540 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
541 charbuff
[15] := UpCase1251(C
);