X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=blobdiff_plain;f=src%2Fgame%2Fg_console.pas;h=64b08642029b320c93a0377ae8a56526b94eb821;hp=21b056f66130f629832193af63b51ed096abd1e5;hb=51998d817120cd3833df7bae3d355642fd4abde5;hpb=7ab0e3623e342566a036b71b847b629e26ee56e1 diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 21b056f..64b0864 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -2,8 +2,7 @@ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, version 3 of the License ONLY. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -31,43 +30,55 @@ uses ACTION_SCORES = 6; ACTION_ACTIVATE = 7; ACTION_STRAFE = 8; - ACTION_WEAPNEXT = 9; - ACTION_WEAPPREV = 10; FIRST_ACTION = ACTION_JUMP; - LAST_ACTION = ACTION_WEAPPREV; + LAST_ACTION = ACTION_STRAFE; -procedure g_Console_Init (); -procedure g_Console_Update (); -procedure g_Console_Draw (); -procedure g_Console_Switch (); +procedure g_Console_Init; +procedure g_Console_SysInit; +procedure g_Console_Update; +procedure g_Console_Draw (MessagesOnly: Boolean = False); procedure g_Console_Char (C: AnsiChar); procedure g_Console_Control (K: Word); procedure g_Console_Process (L: AnsiString; quiet: Boolean=false); procedure g_Console_Add (L: AnsiString; show: Boolean=false); -procedure g_Console_Clear (); +procedure g_Console_Clear; function g_Console_CommandBlacklisted (C: AnsiString): Boolean; procedure g_Console_ReadConfig (filename: String); +procedure g_Console_WriteConfig (filename: String); +procedure g_Console_WriteGameConfig; function g_Console_Interactive: Boolean; function g_Console_Action (action: Integer): Boolean; +function g_Console_MatchBind (key: Integer; down: AnsiString; up: AnsiString = ''): Boolean; +function g_Console_FindBind (n: Integer; down: AnsiString; up: AnsiString = ''): Integer; +procedure g_Console_BindKey (key: Integer; down: AnsiString; up: AnsiString = ''; rep: Boolean = False); procedure g_Console_ProcessBind (key: Integer; down: Boolean); +procedure g_Console_ProcessBindRepeat (key: Integer); +procedure g_Console_ResetBinds; procedure conwriteln (const s: AnsiString; show: Boolean=false); procedure conwritefln (const s: AnsiString; args: array of const; show: Boolean=false); -// <0: no arg; 0/1: true/false -function conGetBoolArg (p: SSArray; idx: Integer): Integer; - -procedure g_Console_Chat_Switch (team: Boolean=false); - procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; procedure conRegVar (const conname: AnsiString; pvar: PInteger; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +procedure conRegVar (const conname: AnsiString; pvar: PWord; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +procedure conRegVar (const conname: AnsiString; pvar: PCardinal; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +procedure conRegVar (const conname: AnsiString; pvar: PAnsiString; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; + +// <0: no arg; 0/1: true/false +function conGetBoolArg (p: SSArray; idx: Integer): Integer; // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks function conParseFloat (var res: Single; const s: AnsiString): Boolean; +const + {$IFDEF HEADLESS} + defaultConfigScript = 'dfserver.cfg'; + {$ELSE} + defaultConfigScript = 'dfconfig.cfg'; + {$ENDIF} var gConsoleShow: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ @@ -75,15 +86,20 @@ var gChatTeam: Boolean = false; gAllowConsoleMessages: Boolean = true; gJustChatted: Boolean = false; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó - gPlayerAction, gDefaultAction: Array [0..1, 0..LAST_ACTION] of Boolean; // [player, action] + gParsingBinds: Boolean = true; // íå ïåðåñîõðàíÿòü êîíôèã âî âðåìÿ ïàðñèíãà + gPlayerAction: Array [0..1, 0..LAST_ACTION] of Boolean; // [player, action] + gConfigScript: string = defaultConfigScript; implementation uses - g_textures, g_main, e_graphics, e_input, g_game, - SysUtils, g_basic, g_options, Math, g_touch, - g_menu, g_language, g_net, g_netmsg, e_log, conbuf; + g_textures, g_main, e_graphics, e_input, g_game, g_gfx, g_player, g_items, + SysUtils, g_basic, g_options, Math, g_touch, e_res, + g_menu, g_gui, g_language, g_net, g_netmsg, e_log, conbuf, g_weapons; +const + autoexecScript = 'autoexec.cfg'; + configComment = 'generated by doom2d, do not modify'; type PCommand = ^TCommand; @@ -111,8 +127,6 @@ type const - Step = 32; - Alpha = 25; MsgTime = 144; MaxScriptRecursion = 16; @@ -123,7 +137,9 @@ var RecursionDepth: Word = 0; RecursionLimitHit: Boolean = False; Cons_Y: SmallInt; - Cons_Shown: Boolean; // Ðèñîâàòü ëè êîíñîëü? + ConsoleHeight: Single; + Cons_Shown: Boolean; // draw console + InputReady: Boolean; // allow text input in console/chat Line: AnsiString; CPos: Word; //ConsoleHistory: SSArray; @@ -138,12 +154,44 @@ var Time: Word; end; - bindDown, bindProcess: Boolean; gInputBinds: Array [0..e_MaxInputKeys - 1] of record - commands: SSArray; + rep: Boolean; + down, up: SSArray; end; + menu_toggled: BOOLEAN; (* hack for menu controls *) + ChatTop: BOOLEAN; + ConsoleStep: Single; + ConsoleTrans: Single; +procedure g_Console_Switch; +begin + Cons_Y := Min(0, Max(Cons_Y, -Floor(gScreenHeight * ConsoleHeight))); + if Cons_Shown = False then + Cons_Y := -Floor(gScreenHeight * ConsoleHeight); + gChatShow := False; + gConsoleShow := not gConsoleShow; + Cons_Shown := True; + InputReady := False; + g_Touch_ShowKeyboard(gConsoleShow or gChatShow); +end; + +procedure g_Console_Chat_Switch (Team: Boolean = False); +begin + if not g_Game_IsNet then Exit; + Cons_Y := Min(0, Max(Cons_Y, -Floor(gScreenHeight * ConsoleHeight))); + if Cons_Shown = False then + Cons_Y := -Floor(gScreenHeight * ConsoleHeight); + gConsoleShow := False; + gChatShow := not gChatShow; + gChatTeam := Team; + Cons_Shown := True; + InputReady := False; + Line := ''; + CPos := 1; + g_Touch_ShowKeyboard(gConsoleShow or gChatShow); +end; + // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks function conParseFloat (var res: Single; const s: AnsiString): Boolean; var @@ -198,6 +246,8 @@ end; procedure boolVarHandler (me: PCommand; p: SSArray); procedure binaryFlag (var flag: Boolean; msg: AnsiString); + var + old: Boolean; begin if (Length(p) > 2) then begin @@ -205,12 +255,15 @@ procedure boolVarHandler (me: PCommand; p: SSArray); end else begin + old := flag; case conGetBoolArg(p, 1) of -1: begin end; 0: if not me.cheat or conIsCheatsEnabled then flag := false else begin conwriteln('not available'); exit; end; 1: if not me.cheat or conIsCheatsEnabled then flag := true else begin conwriteln('not available'); exit; end; 666: if not me.cheat or conIsCheatsEnabled then flag := not flag else begin conwriteln('not available'); exit; end; end; + if flag <> old then + g_Console_WriteGameConfig(); if (Length(msg) = 0) then msg := p[0] else msg += ':'; if flag then conwritefln('%s tan', [msg]) else conwritefln('%s ona', [msg]); end; @@ -221,24 +274,30 @@ end; procedure intVarHandler (me: PCommand; p: SSArray); - procedure binaryFlag (var flag: Boolean; msg: AnsiString); +var + old: Integer; +begin + if (Length(p) <> 2) then begin - if (Length(p) > 2) then - begin - conwritefln('too many arguments to ''%s''', [p[0]]); - end - else - begin - case conGetBoolArg(p, 1) of - -1: begin end; - 0: if not me.cheat or conIsCheatsEnabled then flag := false else begin conwriteln('not available'); exit; end; - 1: if not me.cheat or conIsCheatsEnabled then flag := true else begin conwriteln('not available'); exit; end; - 666: if not me.cheat or conIsCheatsEnabled then flag := not flag else begin conwriteln('not available'); exit; end; - end; - if (Length(msg) = 0) then msg := p[0] else msg += ':'; - if flag then conwritefln('%s tan', [msg]) else conwritefln('%s ona', [msg]); + conwritefln('%s %d', [me.cmd, PInteger(me.ptr)^]); + end + else + begin + try + old := PInteger(me.ptr)^; + PInteger(me.ptr)^ := StrToInt(p[1]); + if PInteger(me.ptr)^ <> old then + g_Console_WriteGameConfig(); + except + conwritefln('invalid integer value: "%s"', [p[1]]); end; end; +end; + + +procedure wordVarHandler (me: PCommand; p: SSArray); +var + old: Integer; begin if (Length(p) <> 2) then begin @@ -247,14 +306,57 @@ begin else begin try - PInteger(me.ptr)^ := StrToInt(p[1]); + old := PWord(me.ptr)^; + PWord(me.ptr)^ := min($FFFF, StrToDWord(p[1])); + if PWord(me.ptr)^ <> old then + g_Console_WriteGameConfig(); except - conwritefln('invalid integer value: "%s"', [p[1]]); + conwritefln('invalid word value: "%s"', [p[1]]); end; end; end; +procedure dwordVarHandler (me: PCommand; p: SSArray); +var + old: Integer; +begin + if (Length(p) <> 2) then + begin + conwritefln('%s %d', [me.cmd, PInteger(me.ptr)^]); + end + else + begin + try + old := PCardinal(me.ptr)^; + PCardinal(me.ptr)^ := StrToDWord(p[1]); + if PCardinal(me.ptr)^ <> old then + g_Console_WriteGameConfig(); + except + conwritefln('invalid dword value: "%s"', [p[1]]); + end; + end; +end; + + +procedure strVarHandler (me: PCommand; p: SSArray); +var + old: AnsiString; +begin + if (Length(p) <> 2) then + begin + conwritefln('%s %s', [me.cmd, QuoteStr(PAnsiString(me.ptr)^)]); + end + else + begin + old := PAnsiString(me.ptr)^; + PAnsiString(me.ptr)^ := p[1]; + if PAnsiString(me.ptr)^ <> old then + g_Console_WriteGameConfig(); + end; +end; + + procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; var f: Integer; @@ -297,6 +399,68 @@ begin end; +procedure conRegVar (const conname: AnsiString; pvar: PWord; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +var + f: Integer; + cp: PCommand; +begin + f := Length(commands); + SetLength(commands, f+1); + cp := @commands[f]; + cp.cmd := LowerCase(conname); + cp.proc := nil; + cp.procEx := wordVarHandler; + cp.help := ahelp; + cp.hidden := ahidden; + cp.ptr := pvar; + cp.msg := amsg; + cp.cheat := acheat; + cp.action := -1; + cp.player := -1; +end; + + +procedure conRegVar (const conname: AnsiString; pvar: PCardinal; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +var + f: Integer; + cp: PCommand; +begin + f := Length(commands); + SetLength(commands, f+1); + cp := @commands[f]; + cp.cmd := LowerCase(conname); + cp.proc := nil; + cp.procEx := dwordVarHandler; + cp.help := ahelp; + cp.hidden := ahidden; + cp.ptr := pvar; + cp.msg := amsg; + cp.cheat := acheat; + cp.action := -1; + cp.player := -1; +end; + + +procedure conRegVar (const conname: AnsiString; pvar: PAnsiString; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +var + f: Integer; + cp: PCommand; +begin + f := Length(commands); + SetLength(commands, f+1); + cp := @commands[f]; + cp.cmd := LowerCase(conname); + cp.proc := nil; + cp.procEx := strVarHandler; + cp.help := ahelp; + cp.hidden := ahidden; + cp.ptr := pvar; + cp.msg := amsg; + cp.cheat := acheat; + cp.action := -1; + cp.player := -1; +end; + // ////////////////////////////////////////////////////////////////////////// // type PVarSingle = ^TVarSingle; @@ -309,7 +473,7 @@ type procedure singleVarHandler (me: PCommand; p: SSArray); var pv: PVarSingle; - nv: Single; + nv, old: Single; msg: AnsiString; begin if (Length(p) > 2) then @@ -318,6 +482,7 @@ begin exit; end; pv := PVarSingle(me.ptr); + old := pv.val^; if (Length(p) = 2) then begin if me.cheat and (not conIsCheatsEnabled) then begin conwriteln('not available'); exit; end; @@ -339,6 +504,8 @@ begin pv.val^ := nv; end; end; + if pv.val^ <> old then + g_Console_WriteGameConfig(); msg := me.msg; if (Length(msg) = 0) then msg := me.cmd else msg += ':'; conwritefln('%s %s', [msg, pv.val^]); @@ -510,13 +677,24 @@ begin if cmd = 'exec' then begin // exec + if Length(p) = 2 then + g_Console_ReadConfig(p[1]) + else + g_Console_Add('exec