hedgewars/ArgParsers.pas
changeset 13722 6cdb12449be7
parent 13628 d5e029b84e16
child 13950 48796bef9e69
equal deleted inserted replaced
13721:61095cb5f58a 13722:6cdb12449be7
    70     WriteLn(stdout, '                                                                ');
    70     WriteLn(stdout, '                                                                ');
    71 end;
    71 end;
    72 
    72 
    73 procedure DisplayUsage;
    73 procedure DisplayUsage;
    74 begin
    74 begin
    75     WriteLn(stdout, 'Usage: hwengine <path to replay file> [options]');
    75     WriteLn(stdout, 'This is the Hedgewars Engine (hwengine), used to play Hedgewars games and demos.');
       
    76     WriteLn(stdout, 'Use the command-line arguments to play a demo.');
       
    77     WriteLn(stdout, '');
       
    78     WriteLn(stdout, 'Usage: hwengine <path to demo file> [options]');
    76     WriteLn(stdout, '');
    79     WriteLn(stdout, '');
    77     WriteLn(stdout, 'where [options] can be any of the following:');
    80     WriteLn(stdout, 'where [options] can be any of the following:');
    78     WriteLn(stdout, ' --prefix [path to folder]');
    81     WriteLn(stdout, '');
    79     WriteLn(stdout, ' --user-prefix [path to folder]');
    82     WriteLn(stdout, 'File locations:');
    80     WriteLn(stdout, ' --locale [name of language file]');
    83     WriteLn(stdout, '  --prefix <path to folder>: Set the path to the system game data folder');
    81     WriteLn(stdout, ' --nick [string]');
    84     WriteLn(stdout, '  --user-prefix <path to folder>: Set the path to the custom data folder to find game content');
    82     WriteLn(stdout, ' --fullscreen-width [fullscreen width in pixels]');
    85     WriteLn(stdout, '  --locale <name of file>: Set the game language (en.txt for example)');
    83     WriteLn(stdout, ' --fullscreen-height [fullscreen height in pixels]');
    86     WriteLn(stdout, '');
    84     WriteLn(stdout, ' --width [window width in pixels]');
    87     WriteLn(stdout, 'Graphics:');
    85     WriteLn(stdout, ' --height [window height in pixels]');
    88     WriteLn(stdout, '  --width <width in pixels>: Set game window width');
    86     WriteLn(stdout, ' --volume [sound level]');
    89     WriteLn(stdout, '  --height <height in pixels>: Set game window height');
    87     WriteLn(stdout, ' --frame-interval [milliseconds]');
    90     WriteLn(stdout, '  --fullscreen: Start in fullscreen');
    88     Writeln(stdout, ' --stereo [value]');
    91     WriteLn(stdout, '  --fullscreen-width <width in pixels>: Set fullscreen width');
    89     WriteLn(stdout, ' --raw-quality [flags]');
    92     WriteLn(stdout, '  --fullscreen-height <height in pixels>: Set fullscreen height');
    90     WriteLn(stdout, ' --low-quality');
    93     WriteLn(stdout, '  --low-quality: Lowers the game quality');
    91     WriteLn(stdout, ' --nomusic');
    94     WriteLn(stdout, '');
    92     WriteLn(stdout, ' --nosound');
    95     WriteLn(stdout, 'Audio:');
    93     WriteLn(stdout, ' --nodampen');
    96     WriteLn(stdout, '  --volume <sound level>: Set volume between 0 and 100');
    94     WriteLn(stdout, ' --fullscreen');
    97     WriteLn(stdout, '  --nomusic: Disable music');
    95     WriteLn(stdout, ' --showfps');
    98     WriteLn(stdout, '  --nosound: Disable sound effects');
    96     WriteLn(stdout, ' --altdmg');
    99     WriteLn(stdout, '  --nodampen: Don''t dampen sound volume when game application loses focus');
    97     WriteLn(stdout, ' --no-teamtag');
   100     WriteLn(stdout, '');
    98     WriteLn(stdout, ' --no-hogtag');
   101     WriteLn(stdout, 'HUD:');
    99     WriteLn(stdout, ' --no-healthtag');
   102     WriteLn(stdout, '  --altdmg: Show alternative damage');
   100     WriteLn(stdout, ' --translucent-tags');
   103     WriteLn(stdout, '  --no-teamtag: Disable team name tags');
   101     WriteLn(stdout, ' --stats-only');
   104     WriteLn(stdout, '  --no-hogtag: Disable hedgehog name tags');
   102     WriteLn(stdout, ' --help');
   105     WriteLn(stdout, '  --no-healthtag: Disable hedgehog health tags');
   103     WriteLn(stdout, '');
   106     WriteLn(stdout, '  --translucent-tags: Enable translucent name and health tags');
   104     WriteLn(stdout, 'For more detailed help and examples go to:');
   107     WriteLn(stdout, '  --showfps: Show frames per second');
   105     WriteLn(stdout, 'https://hedgewars.org/kb/CommandLineOptions');
   108     WriteLn(stdout, '');
       
   109     WriteLn(stdout, 'Miscellaneous:');
       
   110     WriteLn(stdout, '  --nick <name>: Set user nickname');
       
   111     WriteLn(stdout, '  --help: Show a list of command-line options and exit');
       
   112     WriteLn(stdout, '');
       
   113     Writeln(stdout, 'Advanced options:');
       
   114     Writeln(stdout, '  --stereo <value>: Set stereoscopic rendering (1 to 14)');
       
   115     WriteLn(stdout, '  --frame-interval <milliseconds>: Set minimum interval (in ms) between each frame. Eg, 40 would make the game run at most 25 fps');
       
   116     WriteLn(stdout, '  --raw-quality <flags>: Manually specify the reduced quality flags');
       
   117     WriteLn(stdout, '  --stats-only: Write the round information to console without launching the game, useful for statistics only');
       
   118     WriteLn(stdout, '  --lua-test <path to script>: Run a Lua test script');
   106     GameType:= gmtSyntaxHelp;
   119     GameType:= gmtSyntaxHelp;
   107     helpCommandUsed:= true;
   120     helpCommandUsed:= true;
   108 end;
   121 end;
   109 
   122 
   110 procedure setDepth(var paramIndex: LongInt);
   123 procedure setDepth(var paramIndex: LongInt);
   111 begin
   124 begin
   112     WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!');
   125     WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!');
   113     WriteLn(stdout, '         This option no longer does anything, please consider removing it');
   126     WriteLn(stdout, '         This option no longer does anything, please consider removing it.');
   114     WriteLn(stdout, '');
   127     WriteLn(stdout, '');
   115    inc(ParamIndex);
   128    inc(ParamIndex);
   116 end;
   129 end;
   117 
   130 
   118 procedure statsOnlyGame;
   131 procedure statsOnlyGame;
   128 begin
   141 begin
   129     if isInternal then
   142     if isInternal then
   130         ipcPort := port
   143         ipcPort := port
   131     else
   144     else
   132         begin
   145         begin
   133         WriteLn(stderr, 'ERROR: use of --port is not allowed');
   146         WriteLn(stderr, 'ERROR: use of --port is not allowed!');
   134         wrongParameter := true;
   147         wrongParameter := true;
   135         end
   148         end
   136 end;
   149 end;
   137 
   150 
   138 function parseNick(nick: shortstring): shortstring;
   151 function parseNick(nick: shortstring): shortstring;
   192     val(str, tmpInt);
   205     val(str, tmpInt);
   193 {$ELSE}
   206 {$ELSE}
   194     val(str, tmpInt, c);
   207     val(str, tmpInt, c);
   195     wrongParameter:= c <> 0;
   208     wrongParameter:= c <> 0;
   196     if wrongParameter then
   209     if wrongParameter then
   197         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
   210         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"!');
   198 {$ENDIF}
   211 {$ENDIF}
   199     getLongIntParameter:= tmpInt;
   212     getLongIntParameter:= tmpInt;
   200 end;
   213 end;
   201 
   214 
   202 function getstringParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): shortstring;
   215 function getstringParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): shortstring;
   203 begin
   216 begin
   204     inc(paramIndex);
   217     inc(paramIndex);
   205     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
   218     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
   206     {$IFNDEF HWLIBRARY}
   219     {$IFNDEF HWLIBRARY}
   207     if wrongParameter then
   220     if wrongParameter then
   208         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
   221         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"!');
   209     {$ENDIF}
   222     {$ENDIF}
   210     getstringParameter:= str;
   223     getstringParameter:= str;
   211 end;
   224 end;
   212 
   225 
   213 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
   226 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
   275         {--no-healthtag}        34 : cTagsMask := cTagsMask and (not htHealth);
   288         {--no-healthtag}        34 : cTagsMask := cTagsMask and (not htHealth);
   276         {--translucent-tags}    35 : cTagsMask := cTagsMask or htTransparent;
   289         {--translucent-tags}    35 : cTagsMask := cTagsMask or htTransparent;
   277         {--lua-test}            36 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   290         {--lua-test}            36 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   278     else
   291     else
   279         begin
   292         begin
   280         //Assume the first "non parameter" is the replay file, anything else is invalid
   293         //Assume the first "non parameter" is the demo file, anything else is invalid
   281         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   294         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   282             recordFileName := cmd
   295             recordFileName := cmd
   283         else
   296         else
   284             begin
   297             begin
   285             WriteLn(stderr, '"'+cmd+'" is not a valid option');
   298             WriteLn(stderr, '"'+cmd+'" is not a valid option.');
   286             parseParameter:= true;
   299             parseParameter:= true;
   287             end;
   300             end;
   288         end;
   301         end;
   289     end;
   302     end;
   290 end;
   303 end;
   292 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt);
   305 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt);
   293 var index, tmpInt: LongInt;
   306 var index, tmpInt: LongInt;
   294     isBool, isValid: Boolean;
   307     isBool, isValid: Boolean;
   295     cmd, arg, newSyntax: string;
   308     cmd, arg, newSyntax: string;
   296 begin
   309 begin
   297     WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!');
   310     WriteLn(stdout, 'WARNING: You are using a deprecated command, which could be removed in a future version!');
   298     WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
   311     WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
   299     WriteLn(stdout, '         Run `hwegine --help` to learn it!');
   312     WriteLn(stdout, '         Run "hwegine --help" to learn it!');
   300     WriteLn(stdout, '');
   313     WriteLn(stdout, '');
   301 
   314 
   302     index:= 0;
   315     index:= 0;
   303     tmpInt:= 1;
   316     tmpInt:= 1;
   304     while (index < size) do
   317     while (index < size) do
   374     recordFileName := '';
   387     recordFileName := '';
   375     parseCommandLine();
   388     parseCommandLine();
   376 
   389 
   377     if (isInternal) and (ParamCount<=1) then
   390     if (isInternal) and (ParamCount<=1) then
   378         begin
   391         begin
   379         WriteLn(stderr, '--internal should not be manually used');
   392         WriteLn(stderr, 'The "--internal" option should not be manually used!');
   380         GameType := gmtBadSyntax;
   393         GameType := gmtBadSyntax;
   381         end;
   394         end;
   382 
   395 
   383     if (not helpCommandUsed) then
   396     if (not helpCommandUsed) then
   384         if (not cTestLua) and (not isInternal) and (recordFileName = '') then
   397         if (not cTestLua) and (not isInternal) and (recordFileName = '') then
   385             begin
   398             begin
   386             WriteLn(stderr, 'You must specify a replay file');
   399             WriteLn(stderr, 'You must specify a demo file.');
   387             GameType := gmtBadSyntax;
   400             GameType := gmtBadSyntax;
   388             end
   401             end
   389         else if (recordFileName <> '') then
   402         else if (recordFileName <> '') then
   390             WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '"');
   403             WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '".');
   391 
   404 
   392     if (GameType = gmtBadSyntax) then
   405     if (GameType = gmtBadSyntax) then
   393         WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
   406         WriteLn(stderr, 'Please use --help to see possible arguments and their usage.');
   394 
   407 
   395     (*
   408     (*
   396     WriteLn(stdout,'PathPrefix:     ' + PathPrefix);
   409     WriteLn(stdout,'PathPrefix:     ' + PathPrefix);
   397     WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);
   410     WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);
   398     *)
   411     *)