hedgewars/ArgParsers.pas
author alfadur
Wed, 15 May 2019 18:43:42 +0300
changeset 14977 225839af5272
parent 14698 93429d8f6b3f
child 15304 c4fd2813b127
child 15320 3bf780084c86
permissions -rw-r--r--
free gear textures to avoid log warnings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     1
(*
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10316
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10078
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4004
diff changeset
    17
 *)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9954
diff changeset
    18
9280
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
    19
{$INCLUDE "options.inc"}
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
    20
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
    21
unit ArgParsers;
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
    22
interface
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
    23
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
    24
procedure GetParams;
10175
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    25
{$IFDEF HWLIBRARY}
11789
e2de320aaf69 - More ugly ifdefs for the ifdef god
antonc27 <antonc27@mail.ru>
parents: 11680
diff changeset
    26
var operatingsystem_parameter_argc: LongInt = 0; {$IFNDEF PAS2C}{$IFNDEF IPHONEOS}cdecl;{$ENDIF} export;{$ENDIF}
e2de320aaf69 - More ugly ifdefs for the ifdef god
antonc27 <antonc27@mail.ru>
parents: 11680
diff changeset
    27
    operatingsystem_parameter_argv: pointer = nil; {$IFNDEF PAS2C}{$IFNDEF IPHONEOS}cdecl;{$ENDIF} export;{$ENDIF}
e2de320aaf69 - More ugly ifdefs for the ifdef god
antonc27 <antonc27@mail.ru>
parents: 11680
diff changeset
    28
    operatingsystem_parameter_envp: pointer = nil; {$IFNDEF PAS2C}{$IFNDEF IPHONEOS}cdecl;{$ENDIF} export;{$ENDIF}
10175
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    29
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    30
function ParamCount: LongInt;
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    31
function ParamStr(i: LongInt): shortstring;
9309
7e8f91634f80 engine compiles for ios again, but SDL bindings are outdated. Fix some warnings
koda
parents: 9302
diff changeset
    32
{$ENDIF}
9280
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
    33
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
    34
implementation
9302
1cf37fd7bc47 minor dep order change
koda
parents: 9280
diff changeset
    35
uses uVariables, uTypes, uUtils, uSound, uConsts;
10175
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    36
var isInternal: Boolean;
13488
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
    37
    helpCommandUsed: Boolean;
10175
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    38
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    39
{$IFDEF HWLIBRARY}
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    40
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    41
type PCharArray = array[0..255] of PChar;
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    42
     PPCharArray = ^PCharArray;
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    43
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    44
function ParamCount: LongInt;
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    45
begin
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    46
    ParamCount:= operatingsystem_parameter_argc - 1
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    47
end;
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    48
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    49
function ParamStr(i: LongInt): shortstring;
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    50
begin
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    51
    ParamStr:= StrPas(PPCharArray(operatingsystem_parameter_argv)^[i])
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    52
end;
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    53
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
    54
{$ENDIF}
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    55
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    56
procedure GciEasterEgg;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    57
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    58
    WriteLn(stdout, '                                                                ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    59
    WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    60
    WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    61
    WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    62
    WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    63
    WriteLn(stdout, '      \/\\\   \/////\\\ \/\\\                 \/\\\             ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    64
    WriteLn(stdout, '       \/\\\       \/\\\ \//\\\                \/\\\            ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    65
    WriteLn(stdout, '        \/\\\       \/\\\  \///\\\              \/\\\           ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    66
    WriteLn(stdout, '         \/\\\\\\\\\\\\\/     \////\\\\\\\\\  /\\\\\\\\\\\      ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    67
    WriteLn(stdout, '          \/////////////          \/////////  \///////////      ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    68
    WriteLn(stdout, '                                                                ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    69
    WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    70
    WriteLn(stdout, '                                                                ');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    71
end;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    72
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    73
procedure DisplayUsage;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
    74
begin
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    75
    WriteLn(stdout, 'This is the Hedgewars Engine (hwengine), used to play Hedgewars games and demos.');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    76
    WriteLn(stdout, 'Use the command-line arguments to play a demo.');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    77
    WriteLn(stdout, '');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    78
    WriteLn(stdout, 'Usage: hwengine <path to demo file> [options]');
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    79
    WriteLn(stdout, '');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    80
    WriteLn(stdout, 'where [options] can be any of the following:');
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    81
    WriteLn(stdout, '');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    82
    WriteLn(stdout, 'File locations:');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    83
    WriteLn(stdout, '  --prefix <path to folder>: Set the path to the system game data folder');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    84
    WriteLn(stdout, '  --user-prefix <path to folder>: Set the path to the custom data folder to find game content');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    85
    WriteLn(stdout, '  --locale <name of file>: Set the game language (en.txt for example)');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    86
    WriteLn(stdout, '');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    87
    WriteLn(stdout, 'Graphics:');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    88
    WriteLn(stdout, '  --width <width in pixels>: Set game window width');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    89
    WriteLn(stdout, '  --height <height in pixels>: Set game window height');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    90
    WriteLn(stdout, '  --fullscreen: Start in fullscreen');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    91
    WriteLn(stdout, '  --fullscreen-width <width in pixels>: Set fullscreen width');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    92
    WriteLn(stdout, '  --fullscreen-height <height in pixels>: Set fullscreen height');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    93
    WriteLn(stdout, '  --low-quality: Lowers the game quality');
14698
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
    94
    WriteLn(stdout, '  --zoom <percent>: Start with custom zoom level');
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
    95
    WriteLn(stdout, '');
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    96
    WriteLn(stdout, 'Audio:');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    97
    WriteLn(stdout, '  --volume <sound level>: Set volume between 0 and 100');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    98
    WriteLn(stdout, '  --nomusic: Disable music');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
    99
    WriteLn(stdout, '  --nosound: Disable sound effects');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   100
    WriteLn(stdout, '  --nodampen: Don''t dampen sound volume when game application loses focus');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   101
    WriteLn(stdout, '');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   102
    WriteLn(stdout, 'HUD:');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   103
    WriteLn(stdout, '  --altdmg: Show alternative damage');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   104
    WriteLn(stdout, '  --no-teamtag: Disable team name tags');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   105
    WriteLn(stdout, '  --no-hogtag: Disable hedgehog name tags');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   106
    WriteLn(stdout, '  --no-healthtag: Disable hedgehog health tags');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   107
    WriteLn(stdout, '  --translucent-tags: Enable translucent name and health tags');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   108
    WriteLn(stdout, '  --showfps: Show frames per second');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   109
    WriteLn(stdout, '');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   110
    WriteLn(stdout, 'Miscellaneous:');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   111
    WriteLn(stdout, '  --nick <name>: Set user nickname');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   112
    WriteLn(stdout, '  --help: Show a list of command-line options and exit');
13971
48796bef9e69 Add --protocol option to engine
unc0rr
parents: 13724
diff changeset
   113
    WriteLn(stdout, '  --protocol: Display protocol number and exit');
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   114
    WriteLn(stdout, '');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   115
    Writeln(stdout, 'Advanced options:');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   116
    Writeln(stdout, '  --stereo <value>: Set stereoscopic rendering (1 to 14)');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   117
    WriteLn(stdout, '  --frame-interval <milliseconds>: Set minimum interval (in ms) between each frame. Eg, 40 would make the game run at most 25 fps');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   118
    WriteLn(stdout, '  --raw-quality <flags>: Manually specify the reduced quality flags');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   119
    WriteLn(stdout, '  --stats-only: Write the round information to console without launching the game, useful for statistics only');
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   120
    WriteLn(stdout, '  --lua-test <path to script>: Run a Lua test script');
13488
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   121
    GameType:= gmtSyntaxHelp;
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   122
    helpCommandUsed:= true;
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   123
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   124
13971
48796bef9e69 Add --protocol option to engine
unc0rr
parents: 13724
diff changeset
   125
procedure DisplayProtocol;
48796bef9e69 Add --protocol option to engine
unc0rr
parents: 13724
diff changeset
   126
begin
48796bef9e69 Add --protocol option to engine
unc0rr
parents: 13724
diff changeset
   127
    WriteLn(stdout, IntToStr(cNetProtoVersion));
48796bef9e69 Add --protocol option to engine
unc0rr
parents: 13724
diff changeset
   128
    GameType:= gmtSyntaxHelp;
48796bef9e69 Add --protocol option to engine
unc0rr
parents: 13724
diff changeset
   129
    helpCommandUsed:= true;
48796bef9e69 Add --protocol option to engine
unc0rr
parents: 13724
diff changeset
   130
end;
48796bef9e69 Add --protocol option to engine
unc0rr
parents: 13724
diff changeset
   131
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   132
procedure setDepth(var paramIndex: LongInt);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   133
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   134
    WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!');
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   135
    WriteLn(stdout, '         This option no longer does anything, please consider removing it.');
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   136
    WriteLn(stdout, '');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   137
   inc(ParamIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   138
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   139
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   140
procedure statsOnlyGame;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   141
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   142
    cOnlyStats:= true;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   143
    cReducedQuality:= $FFFFFFFF xor rqLowRes;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   144
    SetSound(false);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   145
    SetMusic(false);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   146
    SetVolume(0);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   147
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   148
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   149
procedure setIpcPort(port: LongInt; var wrongParameter:Boolean);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   150
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   151
    if isInternal then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   152
        ipcPort := port
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   153
    else
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   154
        begin
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   155
        WriteLn(stderr, 'ERROR: use of --port is not allowed!');
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   156
        wrongParameter := true;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   157
        end
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   158
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   159
8850
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8446
diff changeset
   160
function parseNick(nick: shortstring): shortstring;
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   161
begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   162
    if isInternal then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   163
        parseNick:= DecodeBase64(nick)
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   164
    else
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   165
        parseNick:= nick;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   166
end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   167
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   168
procedure setStereoMode(tmp: LongInt);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   169
begin
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6700
diff changeset
   170
    GrayScale:= false;
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   171
{$IFDEF USE_S3D_RENDERING}
8359
9a7024b2a4d3 Removed wiggle 3D mode, reorder the list of 3D modes.
martin_bede
parents: 8354
diff changeset
   172
    if (tmp > 6) and (tmp < 13) then
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5239
diff changeset
   173
        begin
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   174
        // set the gray anaglyph rendering
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6700
diff changeset
   175
        GrayScale:= true;
8359
9a7024b2a4d3 Removed wiggle 3D mode, reorder the list of 3D modes.
martin_bede
parents: 8354
diff changeset
   176
        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)))
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5239
diff changeset
   177
        end
8359
9a7024b2a4d3 Removed wiggle 3D mode, reorder the list of 3D modes.
martin_bede
parents: 8354
diff changeset
   178
    else if tmp <= 6 then
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   179
        // set the fullcolor anaglyph
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6426
diff changeset
   180
        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   181
    else
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   182
        // any other mode
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6426
diff changeset
   183
        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   184
{$ELSE}
8425
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   185
    tmp:= tmp;
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   186
    cStereoMode:= smNone;
8221
5e2dc5813408 don't set stereomode when stereo is disabled
koda
parents: 8213
diff changeset
   187
{$ENDIF}
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   188
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   189
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   190
procedure startVideoRecording(var paramIndex: LongInt);
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   191
begin
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8359
diff changeset
   192
    // Silence the hint that appears when USE_VIDEO_RECORDING is not defined
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8359
diff changeset
   193
    paramIndex:= paramIndex;
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   194
{$IFDEF USE_VIDEO_RECORDING}
10173
fff5e4b0dfcb Make it build as library
unc0rr
parents: 10108
diff changeset
   195
{$IFNDEF HWLIBRARY}
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   196
    GameType:= gmtRecord;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   197
    inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   198
    cVideoFramerateNum:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   199
    cVideoFramerateDen:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   200
    RecPrefix:= ParamStr(paramIndex);                    inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   201
    cAVFormat:= ParamStr(paramIndex);                    inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   202
    cVideoCodec:= ParamStr(paramIndex);                  inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   203
    cVideoQuality:= StrToInt(ParamStr(paramIndex));      inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   204
    cAudioCodec:= ParamStr(paramIndex);                  inc(paramIndex);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   205
{$ENDIF}
10173
fff5e4b0dfcb Make it build as library
unc0rr
parents: 10108
diff changeset
   206
{$ENDIF}
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   207
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   208
8850
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8446
diff changeset
   209
function getLongIntParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   210
var tmpInt, c: LongInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   211
begin
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   212
    inc(paramIndex);
10173
fff5e4b0dfcb Make it build as library
unc0rr
parents: 10108
diff changeset
   213
{$IFDEF PAS2C OR HWLIBRARY}
8850
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8446
diff changeset
   214
    val(str, tmpInt);
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8446
diff changeset
   215
{$ELSE}
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   216
    val(str, tmpInt, c);
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   217
    wrongParameter:= c <> 0;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   218
    if wrongParameter then
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   219
        WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"!');
8850
ae8a957c69fd engine to c now compiles with some manual intervention (as of bug 596)
koda
parents: 8446
diff changeset
   220
{$ENDIF}
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   221
    getLongIntParameter:= tmpInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   222
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   223
9954
bf51bc7e2808 - Fix build via pas2c
unc0rr
parents: 9521
diff changeset
   224
function getstringParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): shortstring;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   225
begin
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   226
    inc(paramIndex);
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   227
    wrongParameter:= (str='') or (Copy(str,1,2) = '--');
10173
fff5e4b0dfcb Make it build as library
unc0rr
parents: 10108
diff changeset
   228
    {$IFNDEF HWLIBRARY}
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   229
    if wrongParameter then
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   230
        WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"!');
10173
fff5e4b0dfcb Make it build as library
unc0rr
parents: 10108
diff changeset
   231
    {$ENDIF}
9954
bf51bc7e2808 - Fix build via pas2c
unc0rr
parents: 9521
diff changeset
   232
    getstringParameter:= str;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   233
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   234
14698
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   235
procedure setZoom(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   236
var param: LongInt;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   237
begin
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   238
    param:= getLongIntParameter(str, paramIndex, wrongParameter);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   239
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   240
    if param = 100 then
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   241
        exit;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   242
    UserZoom:= (param/100.0) * cDefaultZoomLevel;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   243
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   244
    if UserZoom < cMaxZoomLevel then
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   245
        UserZoom:= cMaxZoomLevel;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   246
    if UserZoom > cMinZoomLevel then
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   247
        UserZoom:= cMinZoomLevel;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   248
    zoom:= UserZoom;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   249
    ZoomValue:= UserZoom;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   250
end;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   251
10078
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10015
diff changeset
   252
procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   253
9954
bf51bc7e2808 - Fix build via pas2c
unc0rr
parents: 9521
diff changeset
   254
function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
10078
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10015
diff changeset
   255
const videoarray: array [0..4] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10015
diff changeset
   256
      audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10015
diff changeset
   257
      otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10015
diff changeset
   258
      mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
13628
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   259
      allarray: array [0..18] 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');
14698
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   260
      reallyAll: array[0..39] of shortstring = (
8924
13ac59499066 update 0.9.19 with dev branch
koda
parents: 8884
diff changeset
   261
                '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
13628
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   262
                '--height', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
8924
13ac59499066 update 0.9.19 with dev branch
koda
parents: 8884
diff changeset
   263
                '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
14698
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   264
                '--zoom',
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   265
  {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   266
  {internal}    '--internal', '--port', '--recorder', '--landpreview',
14691
56831f466d1d Add settings.ini setting and hwengine param to disable holiday silliness (hat changes, etc.)
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
   267
  {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness');
8197
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   268
var cmdIndex: byte;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   269
begin
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   270
    parseParameter:= false;
8197
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   271
    cmdIndex:= 0;
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   272
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   273
    //NOTE: Any update to the list of parameters must be reflected in the case statement below, the reallyAll array above,
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   274
    //      the the DisplayUsage() procedure, the HWForm::getDemoArguments() function, and the online wiki
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   275
8197
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   276
    while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   277
    case cmdIndex of
9954
bf51bc7e2808 - Fix build via pas2c
unc0rr
parents: 9521
diff changeset
   278
        {--prefix}               0 : PathPrefix        := getstringParameter (arg, paramIndex, parseParameter);
bf51bc7e2808 - Fix build via pas2c
unc0rr
parents: 9521
diff changeset
   279
        {--user-prefix}          1 : UserPathPrefix    := getstringParameter (arg, paramIndex, parseParameter);
14619
62dea281e4d5 Refactor hwengine: Rename cLocale to cLanguage
Wuzzy <Wuzzy2@mail.ru>
parents: 13971
diff changeset
   280
        {--locale}               2 : cLanguageFName    := getstringParameter (arg, paramIndex, parseParameter);
8985
fe8d1a476f0b range checking for more engine command line parameters, issue 600
koda
parents: 8924
diff changeset
   281
        {--fullscreen-width}     3 : cFullscreenWidth  := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
fe8d1a476f0b range checking for more engine command line parameters, issue 600
koda
parents: 8924
diff changeset
   282
        {--fullscreen-height}    4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
8884
08fe08651130 set translucency on fruit theme water, clamp size to even number (same sdl window resize) and honouring min size, reduce calls to dmgmod a bit
nemo
parents: 8425
diff changeset
   283
        {--width}                5 : cWindowedWidth    := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
08fe08651130 set translucency on fruit theme water, clamp size to even number (same sdl window resize) and honouring min size, reduce calls to dmgmod a bit
nemo
parents: 8425
diff changeset
   284
        {--height}               6 : cWindowedHeight   := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
8354
c25bee85d6f8 Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents: 8329
diff changeset
   285
        {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
8985
fe8d1a476f0b range checking for more engine command line parameters, issue 600
koda
parents: 8924
diff changeset
   286
        {--volume}               8 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
8354
c25bee85d6f8 Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents: 8329
diff changeset
   287
        {--nomusic}              9 : SetMusic           ( false );
c25bee85d6f8 Separated fullscreen and windowed hwengine resolution parameters.
vitiv <nikita.utiu@gmail.com>
parents: 8329
diff changeset
   288
        {--nosound}             10 : SetSound           ( false );
13628
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   289
        {--nodampen}            11 : SetAudioDampen     ( false );
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   290
        {--fullscreen}          12 : cFullScreen       := true;
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   291
        {--showfps}             13 : cShowFPS          := true;
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   292
        {--altdmg}              14 : cAltDamage        := true;
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   293
        {--low-quality}         15 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   294
        {--raw-quality}         16 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   295
        {--stereo}              17 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   296
        {--nick}                18 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
14698
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   297
        {--zoom}                19 : setZoom(arg, paramIndex, parseParameter);
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   298
        {deprecated options}
14698
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   299
        {--depth}               20 : setDepth(paramIndex);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   300
        {--set-video}           21 : parseClassicParameter(videoarray,5,paramIndex);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   301
        {--set-audio}           22 : parseClassicParameter(audioarray,3,paramIndex);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   302
        {--set-other}           23 : parseClassicParameter(otherarray,3,paramIndex);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   303
        {--set-multimedia}      24 : parseClassicParameter(mediaarray,10,paramIndex);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   304
        {--set-everything}      25 : parseClassicParameter(allarray,14,paramIndex);
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   305
        {"internal" options}
14698
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   306
        {--internal}            26 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   307
        {--port}                27 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   308
        {--recorder}            28 : startVideoRecording(paramIndex);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   309
        {--landpreview}         29 : GameType := gmtLandPreview;
8302
a7934cd12469 improve engine cmd line parsing and its documentation
RowanD
parents: 8221
diff changeset
   310
        {anything else}
14698
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   311
        {--stats-only}          30 : statsOnlyGame();
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   312
        {--gci}                 31 : GciEasterEgg();
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   313
        {--help}                32 : DisplayUsage();
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   314
        {--protocol}            33 : DisplayProtocol();
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   315
        {--no-teamtag}          34 : cTagsMask := cTagsMask and (not htTeamName);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   316
        {--no-hogtag}           35 : cTagsMask := cTagsMask and (not htName);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   317
        {--no-healthtag}        36 : cTagsMask := cTagsMask and (not htHealth);
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   318
        {--translucent-tags}    37 : cTagsMask := cTagsMask or htTransparent;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   319
        {--lua-test}            38 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
93429d8f6b3f Add setting to set default/initial zoom
Wuzzy <Wuzzy2@mail.ru>
parents: 14691
diff changeset
   320
        {--no-holiday-silliness} 39 : cHolidaySilliness:= false;
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   321
    else
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   322
        begin
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   323
        //Assume the first "non parameter" is the demo file, anything else is invalid
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   324
        if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
8307
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   325
            recordFileName := cmd
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   326
        else
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   327
            begin
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   328
            WriteLn(stderr, '"'+cmd+'" is not a valid option.');
8307
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   329
            parseParameter:= true;
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   330
            end;
8d7c52b24e28 GCI2012: Optional Second Argument
RowanD
parents: 8302
diff changeset
   331
        end;
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   332
    end;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   333
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   334
10078
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10015
diff changeset
   335
procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt);
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   336
var index, tmpInt: LongInt;
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   337
    isBool, isValid: Boolean;
9954
bf51bc7e2808 - Fix build via pas2c
unc0rr
parents: 9521
diff changeset
   338
    cmd, arg, newSyntax: string;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   339
begin
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   340
    WriteLn(stdout, 'WARNING: You are using a deprecated command, which could be removed in a future version!');
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   341
    WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   342
    WriteLn(stdout, '         Run "hwegine --help" to learn it!');
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   343
    WriteLn(stdout, '');
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   344
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   345
    index:= 0;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   346
    tmpInt:= 1;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   347
    while (index < size) do
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   348
        begin
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8359
diff changeset
   349
        newSyntax:= '';
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   350
        inc(paramIndex);
10078
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10015
diff changeset
   351
        cmd:= cmdarray[index];
10173
fff5e4b0dfcb Make it build as library
unc0rr
parents: 10108
diff changeset
   352
        arg:= cmdarray[paramIndex];
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   353
        isValid:= (cmd<>'--depth');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   354
8197
6d9371d6d045 Unbreak build with freepascal < 2.6.0
unc0rr
parents: 8150
diff changeset
   355
        // check if the parameter is a boolean one
13628
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   356
        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');
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   357
        if isBool and (arg='0') then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   358
            isValid:= false;
13628
d5e029b84e16 Add setting to disable audio dampening if losing window focus
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
   359
        if (cmd='--nomusic') or (cmd='--nosound') or (cmd='--nodampen') then
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   360
            isValid:= not isValid;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   361
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   362
        if isValid then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   363
            begin
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   364
            parseParameter(cmd, arg, tmpInt);
8332
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   365
            newSyntax:= newSyntax + cmd + ' ';
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   366
            if not isBool then
8332
9333216f2054 fix hwc install and pas2c preprocessing (but not total conversion)
koda
parents: 8330
diff changeset
   367
                newSyntax:= newSyntax + arg + ' ';
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   368
            end;
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   369
        inc(index);
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   370
        end;
8924
13ac59499066 update 0.9.19 with dev branch
koda
parents: 8884
diff changeset
   371
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   372
    WriteLn(stdout, 'Attempted to automatically convert to the new syntax:');
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   373
    WriteLn(stdout, newSyntax);
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   374
    WriteLn(stdout, '');
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   375
end;
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   376
10175
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
   377
procedure parseCommandLine;
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   378
var paramIndex: LongInt;
8327
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   379
    paramTotal: LongInt;
8425
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   380
    index, nextIndex: LongInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   381
    wrongParameter: boolean;
8425
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   382
//var tmpInt: LongInt;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   383
begin
10173
fff5e4b0dfcb Make it build as library
unc0rr
parents: 10108
diff changeset
   384
11099
c51e4c942525 - Fix for wrong start paramIndex in case of Hwlibrary
antonc27 <antonc27@mail.ru>
parents: 10316
diff changeset
   385
    paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
10175
c92668840ea8 Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents: 10173
diff changeset
   386
    paramTotal:= ParamCount; //-1 because pascal enumeration is inclusive
8425
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   387
    (*
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   388
    WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal));
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   389
    tmpInt:= 0;
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   390
    while (tmpInt <= paramTotal) do
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   391
        begin
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   392
        WriteLn(stdout, inttostr(tmpInt) + ': ' + {$IFDEF HWLIBRARY}argv[tmpInt]{$ELSE}paramCount(tmpInt){$ENDIF});
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   393
        inc(tmpInt);
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   394
        end;
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   395
    *)
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   396
    wrongParameter:= false;
8327
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   397
    while (paramIndex <= paramTotal) do
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   398
        begin
8425
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   399
        // avoid going past the number of paramTotal (esp. w/ library)
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   400
        index:= paramIndex;
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   401
        if index = paramTotal then nextIndex:= index
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   402
        else nextIndex:= index+1;
4f226963faef restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
koda
parents: 8370
diff changeset
   403
        wrongParameter:= parseParameter( ParamStr(index), ParamStr(nextIndex), paramIndex);
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   404
        inc(paramIndex);
8150
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   405
        end;
6b30a4cd7c7c GCI2012: Command Line Parsing
Rowan D
parents: 7848
diff changeset
   406
    if wrongParameter = true then
13488
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   407
        GameType:= gmtBadSyntax;
3678
00428183300f patch by lucass (polished by me) - command line parsing is now much more flexible
koda
parents:
diff changeset
   408
end;
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   409
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   410
procedure GetParams;
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   411
begin
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   412
    isInternal:= (ParamStr(1) = '--internal');
13488
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   413
    helpCommandUsed:= false;
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   414
8446
c18ba8726f5a Fix sources so pas2c written in haskell could render them again
unc0rr
parents: 8444
diff changeset
   415
    UserPathPrefix := _S'.';
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   416
    PathPrefix     := cDefaultPathPrefix;
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   417
    recordFileName := '';
8327
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   418
    parseCommandLine();
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   419
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   420
    if (isInternal) and (ParamCount<=1) then
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   421
        begin
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   422
        WriteLn(stderr, 'The "--internal" option should not be manually used!');
13488
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   423
        GameType := gmtBadSyntax;
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   424
        end;
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   425
13488
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   426
    if (not helpCommandUsed) then
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   427
        if (not cTestLua) and (not isInternal) and (recordFileName = '') then
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   428
            begin
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   429
            WriteLn(stderr, 'You must specify a demo file.');
13488
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   430
            GameType := gmtBadSyntax;
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   431
            end
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   432
        else if (recordFileName <> '') then
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   433
            WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '".');
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   434
13488
d23731fe84d4 Fix hwengine --help returning with exit code 51
Wuzzy <Wuzzy2@mail.ru>
parents: 11789
diff changeset
   435
    if (GameType = gmtBadSyntax) then
13724
6cdb12449be7 Add description of hwengine command-line arguments in --help
Wuzzy <Wuzzy2@mail.ru>
parents: 13628
diff changeset
   436
        WriteLn(stderr, 'Please use --help to see possible arguments and their usage.');
8325
ecd51650d5d8 GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents: 8309
diff changeset
   437
8308
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   438
    (*
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   439
    WriteLn(stdout,'PathPrefix:     ' + PathPrefix);
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   440
    WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   441
    *)
cdf83bdf7b27 move GetParams in ArgParser, print a warning when using a deprecated command, pascalisation of +1s
koda
parents: 8307
diff changeset
   442
end;
8327
a6f3452f5f94 convert Game() library call to argc,argv format so that we can use the new parsing functions
koda
parents: 8325
diff changeset
   443
9280
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
   444
end.
c3b11f913145 Refactoring: ArgParsers.inc -> ArgParsers.pas
unc0rr
parents: 9249
diff changeset
   445