hedgewars/uFLSchemes.pas
branchqmlfrontend
changeset 10757 f71275973737
parent 10754 8dd1cf1be5a2
child 10819 57e21f7621b0
equal deleted inserted replaced
10754:8dd1cf1be5a2 10757:f71275973737
    22             , invulnerability
    22             , invulnerability
    23             , mines
    23             , mines
    24             , vampiric
    24             , vampiric
    25             , karma
    25             , karma
    26             , artillery
    26             , artillery
    27             , randomorder
       
    28             , king
       
    29             , placehog
       
    30             , sharedammo
       
    31             , disablegirders
       
    32             , randomorder
       
    33             , king
       
    34             , placehog
       
    35             , sharedammo
       
    36             , disablegirders
       
    37             , randomorder
    27             , randomorder
    38             , king
    28             , king
    39             , placehog
    29             , placehog
    40             , sharedammo
    30             , sharedammo
    41             , disablegirders
    31             , disablegirders
    66     PSchemeArray = ^TSchemeArray;
    56     PSchemeArray = ^TSchemeArray;
    67 var
    57 var
    68     schemesList: PScheme;
    58     schemesList: PScheme;
    69     schemesNumber: LongInt;
    59     schemesNumber: LongInt;
    70     listOfSchemeNames: array[0..MAX_SCHEME_NAMES] of PChar;
    60     listOfSchemeNames: array[0..MAX_SCHEME_NAMES] of PChar;
       
    61     tmpScheme: TScheme;
       
    62 
       
    63 const ints: array[0 .. 16] of record
       
    64             name: shortstring;
       
    65             param: ^LongInt;
       
    66         end = (
       
    67               (name: 'damagefactor'; param: @tmpScheme.damagefactor)
       
    68             , (name: 'turntime'; param: @tmpScheme.turntime)
       
    69             , (name: 'health'; param: @tmpScheme.health)
       
    70             , (name: 'suddendeath'; param: @tmpScheme.suddendeath)
       
    71             , (name: 'caseprobability'; param: @tmpScheme.caseprobability)
       
    72             , (name: 'minestime'; param: @tmpScheme.minestime)
       
    73             , (name: 'landadds'; param: @tmpScheme.landadds)
       
    74             , (name: 'minedudpct'; param: @tmpScheme.minedudpct)
       
    75             , (name: 'explosives'; param: @tmpScheme.explosives)
       
    76             , (name: 'minesnum'; param: @tmpScheme.minesnum)
       
    77             , (name: 'healthprobability'; param: @tmpScheme.healthprobability)
       
    78             , (name: 'healthcaseamount'; param: @tmpScheme.healthcaseamount)
       
    79             , (name: 'waterrise'; param: @tmpScheme.waterrise)
       
    80             , (name: 'healthdecrease'; param: @tmpScheme.healthdecrease)
       
    81             , (name: 'ropepct'; param: @tmpScheme.ropepct)
       
    82             , (name: 'getawaytime'; param: @tmpScheme.getawaytime)
       
    83             , (name: 'worldedge'; param: @tmpScheme.worldedge)
       
    84               );
       
    85 const bools: array[0 .. 19] of record
       
    86             name: shortstring;
       
    87             param: ^boolean;
       
    88         end = (
       
    89               (name: 'fortsmode'; param: @tmpScheme.fortsmode)
       
    90             , (name: 'divteams'; param: @tmpScheme.divteams)
       
    91             , (name: 'solidland'; param: @tmpScheme.solidland)
       
    92             , (name: 'border'; param: @tmpScheme.border)
       
    93             , (name: 'lowgrav'; param: @tmpScheme.lowgrav)
       
    94             , (name: 'laser'; param: @tmpScheme.laser)
       
    95             , (name: 'invulnerability'; param: @tmpScheme.invulnerability)
       
    96             , (name: 'mines'; param: @tmpScheme.mines)
       
    97             , (name: 'vampiric'; param: @tmpScheme.vampiric)
       
    98             , (name: 'karma'; param: @tmpScheme.karma)
       
    99             , (name: 'artillery'; param: @tmpScheme.artillery)
       
   100             , (name: 'randomorder'; param: @tmpScheme.randomorder)
       
   101             , (name: 'king'; param: @tmpScheme.king)
       
   102             , (name: 'placehog'; param: @tmpScheme.placehog)
       
   103             , (name: 'sharedammo'; param: @tmpScheme.sharedammo)
       
   104             , (name: 'disablegirders'; param: @tmpScheme.disablegirders)
       
   105             , (name: 'disablewind'; param: @tmpScheme.disablewind)
       
   106             , (name: 'morewind'; param: @tmpScheme.morewind)
       
   107             , (name: 'tagteam'; param: @tmpScheme.tagteam)
       
   108             , (name: 'bottomborder'; param: @tmpScheme.bottomborder)
       
   109               );
       
   110 
    71 
   111 
    72 procedure loadSchemes;
   112 procedure loadSchemes;
    73 var f: PFSFile;
   113 var f: PFSFile;
    74     scheme: PScheme;
   114     scheme: PScheme;
    75     schemes: PSchemeArray;
   115     schemes: PSchemeArray;
    76     s: shortstring;
   116     s: shortstring;
    77     l, i: Longword;
   117     l, i, ii: Longword;
       
   118     isFound: boolean;
    78 begin
   119 begin
    79     f:= pfsOpenRead('/Config/schemes.ini');
   120     f:= pfsOpenRead('/Config/schemes.ini');
    80     schemesNumber:= 0;
   121     schemesNumber:= 0;
    81 
   122 
    82     if f <> nil then
   123     if f <> nil then
   102             while(i <= length(s)) and (s[i] <> '\') do inc(i);
   143             while(i <= length(s)) and (s[i] <> '\') do inc(i);
   103 
   144 
   104             if i < length(s) then
   145             if i < length(s) then
   105             begin
   146             begin
   106                 l:= strToInt(copy(s, 1, i - 1));
   147                 l:= strToInt(copy(s, 1, i - 1));
   107 
   148                 delete(s, 1, i);
   108                 if (l < schemesNumber) and (l > 0) then
   149 
       
   150                 if (l <= schemesNumber) and (l > 0) then
   109                 begin
   151                 begin
   110                     scheme:= @schemes^[l - 1];
   152                     scheme:= @schemes^[l - 1];
   111 
   153 
   112                     if copy(s, i + 1, 5) = 'name=' then
   154                     if copy(s, 1, 5) = 'name=' then
   113                         scheme^. schemeName:= midStr(s, i + 6);
   155                         tmpScheme. schemeName:= midStr(s, 6)
       
   156                     else if copy(s, 1, 12) = 'scriptparam=' then
       
   157                         tmpScheme. schemeName:= midStr(s, 13) else
       
   158                     begin
       
   159                         ii:= 0;
       
   160                         repeat
       
   161                             isFound:= readInt(ints[ii].name, s, ints[ii].param^);
       
   162                             inc(ii)
       
   163                         until isFound or (ii > High(ints));
       
   164 
       
   165                         if not isFound then
       
   166                             begin
       
   167                                 ii:= 0;
       
   168                                 repeat
       
   169                                     isFound:= readBool(bools[ii].name, s, bools[ii].param^);
       
   170                                     inc(ii)
       
   171                                 until isFound or (ii > High(bools));
       
   172                             end;
       
   173                     end;
       
   174 
       
   175                     scheme^:= tmpScheme
   114                 end;
   176                 end;
   115             end;
   177             end;
   116         end;
   178         end;
   117 
   179 
   118         pfsClose(f)
   180         pfsClose(f)
   119     end;
   181     end;
   120 {
       
   121 name=AI TEST
       
   122 fortsmode
       
   123 divteams
       
   124 solidland
       
   125 border
       
   126 lowgrav
       
   127 laser
       
   128 invulnerability
       
   129 mines
       
   130 damagefactor=100
       
   131 turntime=40
       
   132 health=100
       
   133 suddendeath=0
       
   134 caseprobability=5
       
   135 vampiric
       
   136 karma
       
   137 artillery
       
   138 minestime=0
       
   139 landadds=4
       
   140 randomorder
       
   141 king
       
   142 placehog
       
   143 sharedammo
       
   144 disablegirders
       
   145 minedudpct=100
       
   146 explosives=40
       
   147 disablelandobjects
       
   148 aisurvival
       
   149 resethealth
       
   150 infattack
       
   151 resetweps
       
   152 perhogammo
       
   153 minesnum=0
       
   154 healthprobability=100
       
   155 healthcaseamount=50
       
   156 waterrise=0
       
   157 healthdecrease=0
       
   158 disablewind
       
   159 morewind
       
   160 ropepct=100
       
   161 tagteam
       
   162 getawaytime=100
       
   163 bottomborder
       
   164 worldedge=1
       
   165 scriptparam=@Invalid()
       
   166 }
       
   167 end;
   182 end;
   168 
   183 
   169 
   184 
   170 function getSchemesList: PPChar; cdecl;
   185 function getSchemesList: PPChar; cdecl;
   171 var i, t, l: Longword;
   186 var i, t, l: Longword;
   195 
   210 
   196 
   211 
   197 procedure freeSchemesList;
   212 procedure freeSchemesList;
   198 begin
   213 begin
   199     if schemesList <> nil then
   214     if schemesList <> nil then
   200         FreeMem(schemesList, sizeof(schemesList^) * schemesNumber)
   215         FreeMem(schemesList, sizeof(schemesList^) * (schemesNumber + 1))
   201 end;
   216 end;
   202 
   217 
   203 end.
   218 end.