10 procedure KeyPress(K
: Word);
11 procedure CharPress(C
: Char);
23 SDL2
, GL
, GLExt
, WADEDITOR
, e_log
, g_window
,
24 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
25 e_sound
, g_options
, g_sound
, g_player
,
26 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
,
27 MAPSTRUCT
, g_menu
, g_language
, g_net
;
30 charbuff
: Array [0..15] of Char;
35 MapsDir
:= GameDir
+ '/maps/';
36 DataDir
:= GameDir
+ '/data/';
37 ModelsDir
:= DataDir
+ 'models/';
38 GameWAD
:= DataDir
+ 'Game.wad';
40 e_InitLog(GameDir
+ '/' + LOG_FILENAME
, WM_NEWFILE
);
42 e_WriteLog('Read config file', MSG_NOTIFY
);
43 g_Options_Read(GameDir
+ '/' + CONFIG_FILENAME
);
45 //GetSystemDefaultLCID()
47 //e_WriteLog('Read language file', MSG_NOTIFY);
48 //g_Language_Load(DataDir + gLanguage + '.txt');
49 e_WriteLog(gLanguage
, MSG_NOTIFY
);
50 g_Language_Set(gLanguage
);
52 if SDL_Init(SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
) < 0 then
53 raise Exception
.Create('SDL: Init failed: ' + SDL_GetError());
57 e_WriteLog('Entering SDLMain', MSG_NOTIFY
);
65 e_WriteLog('Releasing SDL', MSG_NOTIFY
);
75 e_WriteLog('Init Input', MSG_NOTIFY
);
78 if (e_JoysticksAvailable
> 0) then
79 e_WriteLog('Input: Joysticks available.', MSG_NOTIFY
)
81 e_WriteLog('Input: No Joysticks.', MSG_NOTIFY
);
85 e_WriteLog('Initializing SDL2 mixer', MSG_NOTIFY
);
89 e_WriteLog('Init game', MSG_NOTIFY
);
92 for a
:= 0 to 15 do charbuff
[a
] := ' ';
97 e_WriteLog('Releasing engine', MSG_NOTIFY
);
100 e_WriteLog('Releasing Input', MSG_NOTIFY
);
105 e_WriteLog('Releasing FMOD', MSG_NOTIFY
);
106 e_ReleaseSoundSystem();
120 function Translit(S
: String): String;
125 for i
:= 1 to Length(Result
) do
127 'É': Result
[i
] := 'Q';
128 'Ö': Result
[i
] := 'W';
129 'Ó': Result
[i
] := 'E';
130 'Ê': Result
[i
] := 'R';
131 'Å': Result
[i
] := 'T';
132 'Í': Result
[i
] := 'Y';
133 'Ã': Result
[i
] := 'U';
134 'Ø': Result
[i
] := 'I';
135 'Ù': Result
[i
] := 'O';
136 'Ç': Result
[i
] := 'P';
137 'Õ': Result
[i
] := Chr(219);
138 'Ú': Result
[i
] := Chr(221);
139 'Ô': Result
[i
] := 'A';
140 'Û': Result
[i
] := 'S';
141 'Â': Result
[i
] := 'D';
142 'À': Result
[i
] := 'F';
143 'Ï': Result
[i
] := 'G';
144 'Ð': Result
[i
] := 'H';
145 'Î': Result
[i
] := 'J';
146 'Ë': Result
[i
] := 'K';
147 'Ä': Result
[i
] := 'L';
148 'Æ': Result
[i
] := Chr(186);
149 'Ý': Result
[i
] := Chr(222);
150 'ß': Result
[i
] := 'Z';
151 '×': Result
[i
] := 'X';
152 'Ñ': Result
[i
] := 'C';
153 'Ì': Result
[i
] := 'V';
154 'È': Result
[i
] := 'B';
155 'Ò': Result
[i
] := 'N';
156 'Ü': Result
[i
] := 'M';
157 'Á': Result
[i
] := Chr(188);
158 'Þ': Result
[i
] := Chr(190);
168 s
, s2
, ls1
, ls2
: string;
172 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
173 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
))
174 or g_Game_IsNet
then Exit
;
176 s
:= 'SOUND_GAME_RADIO';
179 ls1
:= CheatEng
[I_GAME_CHEAT_GODMODE
];
180 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_GODMODE
]);
181 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
182 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
184 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
185 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
189 ls1
:= CheatEng
[I_GAME_CHEAT_WEAPONS
];
190 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_WEAPONS
]);
191 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
192 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
194 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
195 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
199 ls1
:= CheatEng
[I_GAME_CHEAT_HEALTH
];
200 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_HEALTH
]);
201 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
202 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
204 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
205 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
209 ls1
:= CheatEng
[I_GAME_CHEAT_DEATH
];
210 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_DEATH
]);
211 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
212 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
214 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
215 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
216 s
:= 'SOUND_MONSTER_HAHA';
220 ls1
:= CheatEng
[I_GAME_CHEAT_DOORS
];
221 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_DOORS
]);
222 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
223 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
225 g_Triggers_OpenAll();
229 ls1
:= CheatEng
[I_GAME_CHEAT_NEXTMAP
];
230 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_NEXTMAP
]);
231 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
232 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
234 if gTriggers
<> nil then
235 for a
:= 0 to High(gTriggers
) do
236 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
238 gExitByTrigger
:= True;
239 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
245 ls1
:= CheatEng
[I_GAME_CHEAT_CHANGEMAP
];
246 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_CHANGEMAP
]);
247 s2
:= Copy(charbuff
, 15, 2);
248 if ((Copy(charbuff
, 15 - Length(ls1
), Length(ls1
)) = ls1
) or
249 (Copy(charbuff
, 15 - Length(ls2
), Length(ls2
)) = ls2
))
250 and (s2
[1] >= '0') and (s2
[1] <= '9')
251 and (s2
[2] >= '0') and (s2
[2] <= '9') then
253 if g_Map_Exist(MapsDir
+gGameSettings
.WAD
+':\MAP'+s2
) then
263 ls1
:= CheatEng
[I_GAME_CHEAT_FLY
];
264 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_FLY
]);
265 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
266 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
272 ls1
:= CheatEng
[I_GAME_CHEAT_JUMPS
];
273 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_JUMPS
]);
274 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
275 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
277 VEL_JUMP
:= 30-VEL_JUMP
;
281 ls1
:= CheatEng
[I_GAME_CHEAT_SPEED
];
282 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_SPEED
]);
283 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
284 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
286 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
290 ls1
:= CheatEng
[I_GAME_CHEAT_SUIT
];
291 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_SUIT
]);
292 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
293 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
295 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
296 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
300 ls1
:= CheatEng
[I_GAME_CHEAT_AIR
];
301 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_AIR
]);
302 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
303 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
305 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
306 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
310 ls1
:= CheatEng
[I_GAME_CHEAT_BERSERK
];
311 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_BERSERK
]);
312 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
313 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
315 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
316 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
320 ls1
:= CheatEng
[I_GAME_CHEAT_JETPACK
];
321 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_JETPACK
]);
322 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
323 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
325 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
326 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
330 ls1
:= CheatEng
[I_GAME_CHEAT_NOCLIP
];
331 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_NOCLIP
]);
332 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
333 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
335 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
336 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
340 ls1
:= CheatEng
[I_GAME_CHEAT_NOTARGET
];
341 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_NOTARGET
]);
342 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
343 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
345 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
346 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
350 ls1
:= CheatEng
[I_GAME_CHEAT_NORELOAD
];
351 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_NORELOAD
]);
352 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
353 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
355 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
356 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
359 ls1
:= CheatEng
[I_GAME_CHEAT_AIMLINE
];
360 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_AIMLINE
]);
361 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
362 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
364 gAimLine
:= not gAimLine
;
367 ls1
:= CheatEng
[I_GAME_CHEAT_AUTOMAP
];
368 ls2
:= Translit(CheatRus
[I_GAME_CHEAT_AUTOMAP
]);
369 if (Copy(charbuff
, 17 - Length(ls1
), Length(ls1
)) = ls1
) or
370 (Copy(charbuff
, 17 - Length(ls2
), Length(ls2
)) = ls2
) then
372 gShowMap
:= not gShowMap
;
381 procedure KeyPress(K
: Word);
386 IK_PAUSE
: // <Pause/Break>:
388 if (g_ActiveWindow
= nil) then
389 g_Game_Pause(not gPause
);
392 IK_BACKQUOTE
: // <`/~/¨/¸>:
401 g_Console_Chat_Switch();
408 if g_ActiveWindow
<> nil then
410 Msg
.Msg
:= WM_KEYDOWN
;
411 Msg
.WParam
:= IK_ESCAPE
;
412 g_ActiveWindow
.OnMessage(Msg
);
415 if gState
<> STATE_FOLD
then
417 or (gState
= STATE_INTERSINGLE
)
418 or (gState
= STATE_INTERCUSTOM
)
420 g_Game_InGameMenu(True)
422 if (gExit
= 0) and (gState
<> STATE_SLIST
) then
424 if gState
<> STATE_MENU
then
425 if NetMode
<> NET_NONE
then
427 g_Game_StopAllSounds(True);
429 gState
:= STATE_MENU
;
433 g_GUI_ShowWindow('MainMenu');
434 g_Sound_PlayEx('MENU_OPEN');
438 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
439 begin // <F2> .. <F6> � <F12>
440 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
442 while g_ActiveWindow
<> nil do
443 g_GUI_HideWindow(False);
445 if (not g_Game_IsNet
) then
450 g_Menu_Show_SaveMenu();
452 g_Menu_Show_LoadMenu();
454 g_Menu_Show_GameSetGame();
456 g_Menu_Show_OptionsVideo();
458 g_Menu_Show_OptionsSound();
460 g_Menu_Show_EndGameMenu();
462 g_Menu_Show_QuitGameMenu();
469 gJustChatted
:= False;
470 if gConsoleShow
or gChatShow
then
473 if g_ActiveWindow
<> nil then
475 Msg
.Msg
:= WM_KEYDOWN
;
477 g_ActiveWindow
.OnMessage(Msg
);
481 if (gState
= STATE_MENU
) then
483 g_GUI_ShowWindow('MainMenu');
484 g_Sound_PlayEx('MENU_OPEN');
491 procedure CharPress(C
: Char);
496 if (not gChatShow
) and ((C
= '`') or (C
= '~') or (C
= '¸') or (C
= '¨')) then
499 if gConsoleShow
or gChatShow
then
502 if g_ActiveWindow
<> nil then
505 Msg
.WParam
:= Ord(C
);
506 g_ActiveWindow
.OnMessage(Msg
);
511 charbuff
[a
] := charbuff
[a
+1];
512 charbuff
[15] := UpCase(C
);