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 g_amodes.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 MAPSTRUCT
, 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
, WM_NEWFILE
);
63 e_WriteLog('Read config file', MSG_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
, MSG_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', MSG_NOTIFY
);
110 e_WriteLog('Releasing SDL', MSG_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', MSG_NOTIFY
);
134 if (e_JoysticksAvailable
> 0) then
135 e_WriteLog('Input: Joysticks available.', MSG_NOTIFY
)
137 e_WriteLog('Input: No Joysticks.', MSG_NOTIFY
);
139 if (not gNoSound
) then
141 e_WriteLog('Initializing sound system', MSG_NOTIFY
);
142 e_InitSoundSystem(NoSound
);
145 e_WriteLog('Init game', MSG_NOTIFY
);
148 for a
:= 0 to 15 do charbuff
[a
] := ' ';
153 e_WriteLog('Releasing engine', MSG_NOTIFY
);
156 e_WriteLog('Releasing Input', MSG_NOTIFY
);
161 e_WriteLog('Releasing FMOD', MSG_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);
256 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
257 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
))
258 or g_Game_IsNet
then Exit
;
260 s
:= 'SOUND_GAME_RADIO';
263 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
265 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
266 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
270 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
272 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
273 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
277 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
279 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
280 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
284 if CheckCheat(I_GAME_CHEAT_DEATH
) then
286 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
287 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
288 s
:= 'SOUND_MONSTER_HAHA';
292 if CheckCheat(I_GAME_CHEAT_DOORS
) then
294 g_Triggers_OpenAll();
298 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
300 if gTriggers
<> nil then
301 for a
:= 0 to High(gTriggers
) do
302 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
304 gExitByTrigger
:= True;
305 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
311 s2
:= Copy(charbuff
, 15, 2);
312 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
314 if g_Map_Exist(MapsDir
+gGameSettings
.WAD
+':\MAP'+s2
) then
324 if CheckCheat(I_GAME_CHEAT_FLY
) then
330 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
332 VEL_JUMP
:= 30-VEL_JUMP
;
336 if CheckCheat(I_GAME_CHEAT_SPEED
) then
338 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
342 if CheckCheat(I_GAME_CHEAT_SUIT
) then
344 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
345 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
349 if CheckCheat(I_GAME_CHEAT_AIR
) then
351 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
352 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
356 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
358 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
359 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
363 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
365 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
366 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
370 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
372 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
373 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
377 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
379 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
380 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
384 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
386 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
387 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
390 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
392 gAimLine
:= not gAimLine
;
395 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
397 gShowMap
:= not gShowMap
;
406 procedure KeyPress(K
: Word);
411 IK_PAUSE
: // <Pause/Break>:
413 if (g_ActiveWindow
= nil) then
414 g_Game_Pause(not gPause
);
417 IK_BACKQUOTE
: // <`/~/¨/¸>:
426 g_Console_Chat_Switch();
433 if g_ActiveWindow
<> nil then
435 Msg
.Msg
:= WM_KEYDOWN
;
436 Msg
.WParam
:= IK_ESCAPE
;
437 g_ActiveWindow
.OnMessage(Msg
);
440 if gState
<> STATE_FOLD
then
442 or (gState
= STATE_INTERSINGLE
)
443 or (gState
= STATE_INTERCUSTOM
)
445 g_Game_InGameMenu(True)
447 if (gExit
= 0) and (gState
<> STATE_SLIST
) then
449 if gState
<> STATE_MENU
then
450 if NetMode
<> NET_NONE
then
452 g_Game_StopAllSounds(True);
454 gState
:= STATE_MENU
;
458 g_GUI_ShowWindow('MainMenu');
459 g_Sound_PlayEx('MENU_OPEN');
463 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
464 begin // <F2> .. <F6> � <F12>
465 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
467 while g_ActiveWindow
<> nil do
468 g_GUI_HideWindow(False);
470 if (not g_Game_IsNet
) then
475 g_Menu_Show_SaveMenu();
477 g_Menu_Show_LoadMenu();
479 g_Menu_Show_GameSetGame();
481 g_Menu_Show_OptionsVideo();
483 g_Menu_Show_OptionsSound();
485 g_Menu_Show_EndGameMenu();
487 g_Menu_Show_QuitGameMenu();
494 gJustChatted
:= False;
495 if gConsoleShow
or gChatShow
then
498 if g_ActiveWindow
<> nil then
500 Msg
.Msg
:= WM_KEYDOWN
;
502 g_ActiveWindow
.OnMessage(Msg
);
506 if (gState
= STATE_MENU
) then
508 g_GUI_ShowWindow('MainMenu');
509 g_Sound_PlayEx('MENU_OPEN');
516 procedure CharPress(C
: Char);
521 if (not gChatShow
) and ((C
= '`') or (C
= '~') or (C
= '¸') or (C
= '¨')) then
524 if gConsoleShow
or gChatShow
then
527 if g_ActiveWindow
<> nil then
530 Msg
.WParam
:= Ord(C
);
531 g_ActiveWindow
.OnMessage(Msg
);
535 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
536 charbuff
[15] := UpCase1251(C
);