hedgewars/ArgParsers.pas
branchui-scaling
changeset 15288 c4fd2813b127
parent 13394 24b531dcebe7
parent 14682 93429d8f6b3f
--- a/hedgewars/ArgParsers.pas	Wed May 16 18:22:28 2018 +0200
+++ b/hedgewars/ArgParsers.pas	Wed Jul 31 23:14:27 2019 +0200
@@ -34,6 +34,7 @@
 implementation
 uses uVariables, uTypes, uUtils, uSound, uConsts;
 var isInternal: Boolean;
+    helpCommandUsed: Boolean;
 
 {$IFDEF HWLIBRARY}
 
@@ -71,7 +72,10 @@
 
 procedure DisplayUsage;
 begin
-    WriteLn(stdout, 'Usage: hwengine <path to replay file> [options]');
+    WriteLn(stdout, 'This is the Hedgewars Engine (hwengine), used to play Hedgewars games and demos.');
+    WriteLn(stdout, 'Use the command-line arguments to play a demo.');
+    WriteLn(stdout, '');
+    WriteLn(stdout, 'Usage: hwengine <path to demo file> [options]');
     WriteLn(stdout, '');
     WriteLn(stdout, 'where [options] can be any of the following:');
     WriteLn(stdout, ' --prefix [path to folder]');
@@ -96,19 +100,45 @@
     WriteLn(stdout, ' --no-hogtag');
     WriteLn(stdout, ' --no-healthtag');
     WriteLn(stdout, ' --translucent-tags');
+    WriteLn(stdout, ' --stats-only');
     WriteLn(stdout, ' --chat-size [default chat size in percent]');
-    WriteLn(stdout, ' --stats-only');
     WriteLn(stdout, ' --help');
     WriteLn(stdout, '');
-    WriteLn(stdout, 'For more detailed help and examples go to:');
-    WriteLn(stdout, 'http://hedgewars.org/kb/CommandLineOptions');
-    GameType:= gmtSyntax;
+    WriteLn(stdout, 'HUD:');
+    WriteLn(stdout, '  --altdmg: Show alternative damage');
+    WriteLn(stdout, '  --no-teamtag: Disable team name tags');
+    WriteLn(stdout, '  --no-hogtag: Disable hedgehog name tags');
+    WriteLn(stdout, '  --no-healthtag: Disable hedgehog health tags');
+    WriteLn(stdout, '  --translucent-tags: Enable translucent name and health tags');
+    WriteLn(stdout, '  --chat-size [default chat size in percent]');
+    WriteLn(stdout, '  --showfps: Show frames per second');
+    WriteLn(stdout, '');
+    WriteLn(stdout, 'Miscellaneous:');
+    WriteLn(stdout, '  --nick <name>: Set user nickname');
+    WriteLn(stdout, '  --help: Show a list of command-line options and exit');
+    WriteLn(stdout, '  --protocol: Display protocol number and exit');
+    WriteLn(stdout, '');
+    Writeln(stdout, 'Advanced options:');
+    Writeln(stdout, '  --stereo <value>: Set stereoscopic rendering (1 to 14)');
+    WriteLn(stdout, '  --frame-interval <milliseconds>: Set minimum interval (in ms) between each frame. Eg, 40 would make the game run at most 25 fps');
+    WriteLn(stdout, '  --raw-quality <flags>: Manually specify the reduced quality flags');
+    WriteLn(stdout, '  --stats-only: Write the round information to console without launching the game, useful for statistics only');
+    WriteLn(stdout, '  --lua-test <path to script>: Run a Lua test script');
+    GameType:= gmtSyntaxHelp;
+    helpCommandUsed:= true;
+end;
+
+procedure DisplayProtocol;
+begin
+    WriteLn(stdout, IntToStr(cNetProtoVersion));
+    GameType:= gmtSyntaxHelp;
+    helpCommandUsed:= true;
 end;
 
 procedure setDepth(var paramIndex: LongInt);
 begin
     WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!');
-    WriteLn(stdout, '         This option no longer does anything, please consider removing it');
+    WriteLn(stdout, '         This option no longer does anything, please consider removing it.');
     WriteLn(stdout, '');
    inc(ParamIndex);
 end;
@@ -128,7 +158,7 @@
         ipcPort := port
     else
         begin
-        WriteLn(stderr, 'ERROR: use of --port is not allowed');
+        WriteLn(stderr, 'ERROR: use of --port is not allowed!');
         wrongParameter := true;
         end
 end;
@@ -192,7 +222,7 @@
     val(str, tmpInt, c);
     wrongParameter:= c <> 0;
     if wrongParameter then
-        WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
+        WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"!');
 {$ENDIF}
     getLongIntParameter:= tmpInt;
 end;
@@ -203,11 +233,28 @@
     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
     {$IFNDEF HWLIBRARY}
     if wrongParameter then
-        WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
+        WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"!');
     {$ENDIF}
     getstringParameter:= str;
 end;
 
+procedure setZoom(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean);
+var param: LongInt;
+begin
+    param:= getLongIntParameter(str, paramIndex, wrongParameter);
+
+    if param = 100 then
+        exit;
+    UserZoom:= (param/100.0) * cDefaultZoomLevel;
+
+    if UserZoom < cMaxZoomLevel then
+        UserZoom:= cMaxZoomLevel;
+    if UserZoom > cMinZoomLevel then
+        UserZoom:= cMinZoomLevel;
+    zoom:= UserZoom;
+    ZoomValue:= UserZoom;
+end;
+
 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
 
 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
@@ -215,14 +262,15 @@
       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
       mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
-      allarray: array [0..17] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
-      reallyAll: array[0..36] of shortstring = (
+      allarray: array [0..19] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--nodampen','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags', '--chat-size');
+      reallyAll: array[0..40] of shortstring = (
                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
-                '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
+                '--height', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
+                '--zoom',
   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   {internal}    '--internal', '--port', '--recorder', '--landpreview',
-  {misc}        '--stats-only', '--gci', '--help','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--chat-size');
+  {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness','--chat-size');
 var cmdIndex: byte;
 begin
     parseParameter:= false;
@@ -235,7 +283,7 @@
     case cmdIndex of
         {--prefix}               0 : PathPrefix        := getstringParameter (arg, paramIndex, parseParameter);
         {--user-prefix}          1 : UserPathPrefix    := getstringParameter (arg, paramIndex, parseParameter);
-        {--locale}               2 : cLocaleFName      := getstringParameter (arg, paramIndex, parseParameter);
+        {--locale}               2 : cLanguageFName    := getstringParameter (arg, paramIndex, parseParameter);
         {--fullscreen-width}     3 : cFullscreenWidth  := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
         {--fullscreen-height}    4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
         {--width}                5 : cWindowedWidth    := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
@@ -244,43 +292,47 @@
         {--volume}               8 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
         {--nomusic}              9 : SetMusic           ( false );
         {--nosound}             10 : SetSound           ( false );
-        {--fullscreen}          11 : cFullScreen       := true;
-        {--showfps}             12 : cShowFPS          := true;
-        {--altdmg}              13 : cAltDamage        := true;
-        {--low-quality}         14 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
-        {--raw-quality}         15 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--stereo}              16 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
-        {--nick}                17 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
+        {--nodampen}            11 : SetAudioDampen     ( false );
+        {--fullscreen}          12 : cFullScreen       := true;
+        {--showfps}             13 : cShowFPS          := true;
+        {--altdmg}              14 : cAltDamage        := true;
+        {--low-quality}         15 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
+        {--raw-quality}         16 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--stereo}              17 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
+        {--nick}                18 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
+        {--zoom}                19 : setZoom(arg, paramIndex, parseParameter);
         {deprecated options}
-        {--depth}               18 : setDepth(paramIndex);
-        {--set-video}           19 : parseClassicParameter(videoarray,5,paramIndex);
-        {--set-audio}           20 : parseClassicParameter(audioarray,3,paramIndex);
-        {--set-other}           21 : parseClassicParameter(otherarray,3,paramIndex);
-        {--set-multimedia}      22 : parseClassicParameter(mediaarray,10,paramIndex);
-        {--set-everything}      23 : parseClassicParameter(allarray,14,paramIndex);
+        {--depth}               20 : setDepth(paramIndex);
+        {--set-video}           21 : parseClassicParameter(videoarray,5,paramIndex);
+        {--set-audio}           22 : parseClassicParameter(audioarray,3,paramIndex);
+        {--set-other}           23 : parseClassicParameter(otherarray,3,paramIndex);
+        {--set-multimedia}      24 : parseClassicParameter(mediaarray,10,paramIndex);
+        {--set-everything}      25 : parseClassicParameter(allarray,14,paramIndex);
         {"internal" options}
-        {--internal}            24 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
-        {--port}                25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
-        {--recorder}            26 : startVideoRecording(paramIndex);
-        {--landpreview}         27 : GameType := gmtLandPreview;
+        {--internal}            26 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
+        {--port}                27 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
+        {--recorder}            28 : startVideoRecording(paramIndex);
+        {--landpreview}         29 : GameType := gmtLandPreview;
         {anything else}
-        {--stats-only}          28 : statsOnlyGame();
-        {--gci}                 29 : GciEasterEgg();
-        {--help}                30 : DisplayUsage();
-        {--no-teamtag}          31 : cTagsMask := cTagsMask and (not htTeamName);
-        {--no-hogtag}           32 : cTagsMask := cTagsMask and (not htName);
-        {--no-healthtag}        33 : cTagsMask := cTagsMask and (not htHealth);
-        {--translucent-tags}    34 : cTagsMask := cTagsMask or htTransparent;
-        {--lua-test}            35 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
-        {--chat-size}           36 : cDefaultChatScale := 1.0 * getLongIntParameter(arg, paramIndex, parseParameter) / 100;
+        {--stats-only}          30 : statsOnlyGame();
+        {--gci}                 31 : GciEasterEgg();
+        {--help}                32 : DisplayUsage();
+        {--protocol}            33 : DisplayProtocol();
+        {--no-teamtag}          34 : cTagsMask := cTagsMask and (not htTeamName);
+        {--no-hogtag}           35 : cTagsMask := cTagsMask and (not htName);
+        {--no-healthtag}        36 : cTagsMask := cTagsMask and (not htHealth);
+        {--translucent-tags}    37 : cTagsMask := cTagsMask or htTransparent;
+        {--lua-test}            38 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
+        {--no-holiday-silliness} 39 : cHolidaySilliness:= false;
+        {--chat-size}           40 : cDefaultChatScale := 1.0 * getLongIntParameter(arg, paramIndex, parseParameter) / 100;
     else
         begin
-        //Assume the first "non parameter" is the replay file, anything else is invalid
+        //Assume the first "non parameter" is the demo file, anything else is invalid
         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
             recordFileName := cmd
         else
             begin
-            WriteLn(stderr, '"'+cmd+'" is not a valid option');
+            WriteLn(stderr, '"'+cmd+'" is not a valid option.');
             parseParameter:= true;
             end;
         end;
@@ -292,9 +344,9 @@
     isBool, isValid: Boolean;
     cmd, arg, newSyntax: string;
 begin
-    WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!');
+    WriteLn(stdout, 'WARNING: You are using a deprecated command, which could be removed in a future version!');
     WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
-    WriteLn(stdout, '         Run `hwegine --help` to learn it!');
+    WriteLn(stdout, '         Run "hwegine --help" to learn it!');
     WriteLn(stdout, '');
 
     index:= 0;
@@ -308,10 +360,10 @@
         isValid:= (cmd<>'--depth');
 
         // check if the parameter is a boolean one
-        isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg') or (cmd = '--no-teamtag') or (cmd = '--no-hogtag') or (cmd = '--no-healthtag') or (cmd = '--translucent-tags');
+        isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--nodampen') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg') or (cmd = '--no-teamtag') or (cmd = '--no-hogtag') or (cmd = '--no-healthtag') or (cmd = '--translucent-tags');
         if isBool and (arg='0') then
             isValid:= false;
-        if (cmd='--nomusic') or (cmd='--nosound') then
+        if (cmd='--nomusic') or (cmd='--nosound') or (cmd='--nodampen') then
             isValid:= not isValid;
 
         if isValid then
@@ -359,12 +411,13 @@
         inc(paramIndex);
         end;
     if wrongParameter = true then
-        GameType:= gmtSyntax;
+        GameType:= gmtBadSyntax;
 end;
 
 procedure GetParams;
 begin
     isInternal:= (ParamStr(1) = '--internal');
+    helpCommandUsed:= false;
 
     UserPathPrefix := _S'.';
     PathPrefix     := cDefaultPathPrefix;
@@ -373,20 +426,21 @@
 
     if (isInternal) and (ParamCount<=1) then
         begin
-        WriteLn(stderr, '--internal should not be manually used');
-        GameType := gmtSyntax;
+        WriteLn(stderr, 'The "--internal" option should not be manually used!');
+        GameType := gmtBadSyntax;
         end;
 
-    if (not cTestLua) and (not isInternal) and (recordFileName = '') then
-        begin
-        WriteLn(stderr, 'You must specify a replay file');
-        GameType := gmtSyntax;
-        end
-    else if (recordFileName <> '') then
-        WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '"');
+    if (not helpCommandUsed) then
+        if (not cTestLua) and (not isInternal) and (recordFileName = '') then
+            begin
+            WriteLn(stderr, 'You must specify a demo file.');
+            GameType := gmtBadSyntax;
+            end
+        else if (recordFileName <> '') then
+            WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '".');
 
-    if (GameType = gmtSyntax) then
-        WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
+    if (GameType = gmtBadSyntax) then
+        WriteLn(stderr, 'Please use --help to see possible arguments and their usage.');
 
     (*
     WriteLn(stdout,'PathPrefix:     ' + PathPrefix);