9a7250f9fc28a21b9933dfaa61123c4587f70fe7
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
: AnsiChar);
45 SDL2
, wadreader
, e_log
, g_window
,
46 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
47 e_sound
, g_options
, g_sound
, g_player
, g_basic
,
48 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
,
49 g_menu
, g_language
, g_net
, g_holmes
,
50 utils
, conbuf
, envvars
, fui_wadread
, fui_style
,
55 charbuff
: packed array [0..15] of AnsiChar;
64 e_InitWritelnDriver();
67 MapsDir
:= GameDir
+ '/maps/';
68 DataDir
:= GameDir
+ '/data/';
69 ModelsDir
:= DataDir
+ 'models/';
70 GameWAD
:= DataDir
+ 'Game.wad';
72 e_InitLog(GameDir
+ '/' + LOG_FILENAME
, TWriteMode
.WM_NEWFILE
);
75 'Doom 2D: Forever version ' + GAME_VERSION
+
76 ' proto ' + IntToStr(NET_PROTOCOL_VER
),
80 'Build date: ' + GAME_BUILDDATE
+ ' ' + GAME_BUILDTIME
,
84 e_WriteLog('Read config file', TMsgType
.Notify
);
85 g_Options_Read(GameDir
+ '/' + CONFIG_FILENAME
);
88 conbufDumpToStdOut
:= true;
90 e_WriteToStdOut
:= False; //{$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
92 //GetSystemDefaultLCID()
94 //e_WriteLog('Read language file', MSG_NOTIFY);
95 //g_Language_Load(DataDir + gLanguage + '.txt');
96 e_WriteLog(gLanguage
, TMsgType
.Notify
);
97 g_Language_Set(gLanguage
);
100 {$IFDEF USE_SDLMIXER}
101 sdlflags
:= SDL_INIT_TIMER
or SDL_INIT_AUDIO
or $00004000;
102 // HACK: shit this into env and hope for the best
103 SetEnvVar('SDL_AUDIODRIVER', 'dummy');
105 sdlflags
:= SDL_INIT_TIMER
or $00004000;
108 {$IFDEF USE_SDLMIXER}
109 {*sdlflags := SDL_INIT_EVERYTHING;*}
110 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
112 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
115 if SDL_Init(sdlflags
) < 0 then
116 raise Exception
.Create('SDL: Init failed: ' + SDL_GetError());
119 SDL_StartTextInput();
124 if not fuiAddWad('flexui.wad') then
126 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
129 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
130 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
131 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
132 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
133 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
134 except on e
: Exception
do
136 writeln('ERROR loading FlexUI fonts');
149 e_LogWriteln('FlexUI: loading stylesheet...');
150 uiLoadStyles('flexui/widgets.wgs');
151 except on e
: TParserException
do
153 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
164 g_holmes_imfunctional
:= not flexloaded
;
167 e_WriteLog('Entering SDLMain', TMsgType
.Notify
);
177 e_WriteLog('Releasing SDL', TMsgType
.Notify
);
188 {$IFDEF USE_SDLMIXER}
189 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
191 NoSound
:= True; // FMOD backend will sort it out
197 e_WriteLog('Init Input', TMsgType
.Notify
);
200 if (e_JoysticksAvailable
> 0) then
201 e_WriteLog('Input: Joysticks available.', TMsgType
.Notify
)
203 e_WriteLog('Input: No Joysticks.', TMsgType
.Notify
);
205 if (not gNoSound
) then
207 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
208 e_InitSoundSystem(NoSound
);
211 e_WriteLog('Init game', TMsgType
.Notify
);
214 FillChar(charbuff
, sizeof(charbuff
), ' ');
220 e_WriteLog('Releasing engine', TMsgType
.Notify
);
223 e_WriteLog('Releasing Input', TMsgType
.Notify
);
228 e_WriteLog('Releasing FMOD', TMsgType
.Notify
);
229 e_ReleaseSoundSystem();
246 function Translit (const S
: AnsiString): AnsiString;
251 for i
:= 1 to Length(Result
) do
254 'É': Result
[i
] := 'Q';
255 'Ö': Result
[i
] := 'W';
256 'Ó': Result
[i
] := 'E';
257 'Ê': Result
[i
] := 'R';
258 'Å': Result
[i
] := 'T';
259 'Í': Result
[i
] := 'Y';
260 'Ã': Result
[i
] := 'U';
261 'Ø': Result
[i
] := 'I';
262 'Ù': Result
[i
] := 'O';
263 'Ç': Result
[i
] := 'P';
264 'Õ': Result
[i
] := '['; //Chr(219);
265 'Ú': Result
[i
] := ']'; //Chr(221);
266 'Ô': Result
[i
] := 'A';
267 'Û': Result
[i
] := 'S';
268 'Â': Result
[i
] := 'D';
269 'À': Result
[i
] := 'F';
270 'Ï': Result
[i
] := 'G';
271 'Ð': Result
[i
] := 'H';
272 'Î': Result
[i
] := 'J';
273 'Ë': Result
[i
] := 'K';
274 'Ä': Result
[i
] := 'L';
275 'Æ': Result
[i
] := ';'; //Chr(186);
276 'Ý': Result
[i
] := #39; //Chr(222);
277 'ß': Result
[i
] := 'Z';
278 '×': Result
[i
] := 'X';
279 'Ñ': Result
[i
] := 'C';
280 'Ì': Result
[i
] := 'V';
281 'È': Result
[i
] := 'B';
282 'Ò': Result
[i
] := 'N';
283 'Ü': Result
[i
] := 'M';
284 'Á': Result
[i
] := ','; //Chr(188);
285 'Þ': Result
[i
] := '.'; //Chr(190);
291 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
296 ls2
:= Translit(CheatRus
[ct
]);
297 if length(ls1
) = 0 then ls1
:= '~';
298 if length(ls2
) = 0 then ls2
:= '~';
300 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
301 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
302 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
303 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
305 if ct = I_GAME_CHEAT_JETPACK then
307 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
308 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
309 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
310 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
311 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
312 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
329 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
330 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
331 or g_Game_IsNet then Exit;
333 if not gGameOn
then exit
;
334 if not conIsCheatsEnabled
then exit
;
336 s
:= 'SOUND_GAME_RADIO';
339 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
341 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
342 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
346 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
348 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
349 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
353 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
355 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
356 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
360 if CheckCheat(I_GAME_CHEAT_DEATH
) then
362 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
363 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
364 s
:= 'SOUND_MONSTER_HAHA';
368 if CheckCheat(I_GAME_CHEAT_DOORS
) then
370 g_Triggers_OpenAll();
374 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
376 if gTriggers
<> nil then
377 for a
:= 0 to High(gTriggers
) do
378 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
380 gExitByTrigger
:= True;
381 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
382 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
388 s2
:= Copy(charbuff
, 15, 2);
389 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
391 if g_Map_Exist(MapsDir
+gGameSettings
.WAD
+':\MAP'+s2
) then
399 if CheckCheat(I_GAME_CHEAT_FLY
) then
405 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
407 VEL_JUMP
:= 30-VEL_JUMP
;
411 if CheckCheat(I_GAME_CHEAT_SPEED
) then
413 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
417 if CheckCheat(I_GAME_CHEAT_SUIT
) then
419 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
420 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
424 if CheckCheat(I_GAME_CHEAT_AIR
) then
426 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
427 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
431 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
433 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
434 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
438 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
440 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
441 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
445 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
447 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
448 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
452 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
454 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
455 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
459 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
461 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
462 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
465 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
467 gAimLine
:= not gAimLine
;
470 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
472 gShowMap
:= not gShowMap
;
482 procedure KeyPress (K
: Word);
487 IK_PAUSE
: // <Pause/Break>:
489 if (g_ActiveWindow
= nil) then g_Game_Pause(not gPause
);
492 IK_BACKQUOTE
: // <`/~/¨/¸>:
501 g_Console_Chat_Switch();
509 else if (g_ActiveWindow
<> nil) then
511 Msg
.Msg
:= WM_KEYDOWN
;
512 Msg
.WParam
:= IK_ESCAPE
;
513 g_ActiveWindow
.OnMessage(Msg
);
514 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
516 else if (gState
<> STATE_FOLD
) then
518 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
520 g_Game_InGameMenu(True);
522 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
524 if (gState
<> STATE_MENU
) then
526 if (NetMode
<> NET_NONE
) then
528 g_Game_StopAllSounds(True);
530 gState
:= STATE_MENU
;
534 g_GUI_ShowWindow('MainMenu');
535 g_Sound_PlayEx('MENU_OPEN');
540 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
541 begin // <F2> .. <F6> � <F12>
542 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
544 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
545 if (not g_Game_IsNet
) then g_Game_Pause(True);
547 IK_F2
: g_Menu_Show_SaveMenu();
548 IK_F3
: g_Menu_Show_LoadMenu();
549 IK_F4
: g_Menu_Show_GameSetGame();
550 IK_F5
: g_Menu_Show_OptionsVideo();
551 IK_F6
: g_Menu_Show_OptionsSound();
552 IK_F7
: g_Menu_Show_EndGameMenu();
553 IK_F10
: g_Menu_Show_QuitGameMenu();
560 gJustChatted
:= False;
561 if gConsoleShow
or gChatShow
then
563 g_Console_Control(K
);
565 else if (g_ActiveWindow
<> nil) then
567 Msg
.Msg
:= WM_KEYDOWN
;
569 g_ActiveWindow
.OnMessage(Msg
);
571 else if (gState
= STATE_MENU
) then
573 g_GUI_ShowWindow('MainMenu');
574 g_Sound_PlayEx('MENU_OPEN');
581 procedure CharPress (C
: AnsiChar);
586 if (not gChatShow
) and ((C
= '`') or (C
= '~') or (C
= '¸') or (C
= '¨')) then Exit
;
588 if gConsoleShow
or gChatShow
then
592 else if (g_ActiveWindow
<> nil) then
595 Msg
.WParam
:= Ord(C
);
596 g_ActiveWindow
.OnMessage(Msg
);
600 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
601 charbuff
[15] := upcase1251(C
);