hedgewars/uFLSchemes.pas
branchqmlfrontend
changeset 10757 f71275973737
parent 10754 8dd1cf1be5a2
child 10819 57e21f7621b0
--- a/hedgewars/uFLSchemes.pas	Thu Jan 29 23:36:58 2015 +0300
+++ b/hedgewars/uFLSchemes.pas	Mon Feb 02 23:12:56 2015 +0300
@@ -29,16 +29,6 @@
             , placehog
             , sharedammo
             , disablegirders
-            , randomorder
-            , king
-            , placehog
-            , sharedammo
-            , disablegirders
-            , randomorder
-            , king
-            , placehog
-            , sharedammo
-            , disablegirders
             , disablewind
             , morewind
             , tagteam
@@ -68,13 +58,64 @@
     schemesList: PScheme;
     schemesNumber: LongInt;
     listOfSchemeNames: array[0..MAX_SCHEME_NAMES] of PChar;
+    tmpScheme: TScheme;
+
+const ints: array[0 .. 16] of record
+            name: shortstring;
+            param: ^LongInt;
+        end = (
+              (name: 'damagefactor'; param: @tmpScheme.damagefactor)
+            , (name: 'turntime'; param: @tmpScheme.turntime)
+            , (name: 'health'; param: @tmpScheme.health)
+            , (name: 'suddendeath'; param: @tmpScheme.suddendeath)
+            , (name: 'caseprobability'; param: @tmpScheme.caseprobability)
+            , (name: 'minestime'; param: @tmpScheme.minestime)
+            , (name: 'landadds'; param: @tmpScheme.landadds)
+            , (name: 'minedudpct'; param: @tmpScheme.minedudpct)
+            , (name: 'explosives'; param: @tmpScheme.explosives)
+            , (name: 'minesnum'; param: @tmpScheme.minesnum)
+            , (name: 'healthprobability'; param: @tmpScheme.healthprobability)
+            , (name: 'healthcaseamount'; param: @tmpScheme.healthcaseamount)
+            , (name: 'waterrise'; param: @tmpScheme.waterrise)
+            , (name: 'healthdecrease'; param: @tmpScheme.healthdecrease)
+            , (name: 'ropepct'; param: @tmpScheme.ropepct)
+            , (name: 'getawaytime'; param: @tmpScheme.getawaytime)
+            , (name: 'worldedge'; param: @tmpScheme.worldedge)
+              );
+const bools: array[0 .. 19] of record
+            name: shortstring;
+            param: ^boolean;
+        end = (
+              (name: 'fortsmode'; param: @tmpScheme.fortsmode)
+            , (name: 'divteams'; param: @tmpScheme.divteams)
+            , (name: 'solidland'; param: @tmpScheme.solidland)
+            , (name: 'border'; param: @tmpScheme.border)
+            , (name: 'lowgrav'; param: @tmpScheme.lowgrav)
+            , (name: 'laser'; param: @tmpScheme.laser)
+            , (name: 'invulnerability'; param: @tmpScheme.invulnerability)
+            , (name: 'mines'; param: @tmpScheme.mines)
+            , (name: 'vampiric'; param: @tmpScheme.vampiric)
+            , (name: 'karma'; param: @tmpScheme.karma)
+            , (name: 'artillery'; param: @tmpScheme.artillery)
+            , (name: 'randomorder'; param: @tmpScheme.randomorder)
+            , (name: 'king'; param: @tmpScheme.king)
+            , (name: 'placehog'; param: @tmpScheme.placehog)
+            , (name: 'sharedammo'; param: @tmpScheme.sharedammo)
+            , (name: 'disablegirders'; param: @tmpScheme.disablegirders)
+            , (name: 'disablewind'; param: @tmpScheme.disablewind)
+            , (name: 'morewind'; param: @tmpScheme.morewind)
+            , (name: 'tagteam'; param: @tmpScheme.tagteam)
+            , (name: 'bottomborder'; param: @tmpScheme.bottomborder)
+              );
+
 
 procedure loadSchemes;
 var f: PFSFile;
     scheme: PScheme;
     schemes: PSchemeArray;
     s: shortstring;
-    l, i: Longword;
+    l, i, ii: Longword;
+    isFound: boolean;
 begin
     f:= pfsOpenRead('/Config/schemes.ini');
     schemesNumber:= 0;
@@ -104,66 +145,40 @@
             if i < length(s) then
             begin
                 l:= strToInt(copy(s, 1, i - 1));
+                delete(s, 1, i);
 
-                if (l < schemesNumber) and (l > 0) then
+                if (l <= schemesNumber) and (l > 0) then
                 begin
                     scheme:= @schemes^[l - 1];
 
-                    if copy(s, i + 1, 5) = 'name=' then
-                        scheme^. schemeName:= midStr(s, i + 6);
+                    if copy(s, 1, 5) = 'name=' then
+                        tmpScheme. schemeName:= midStr(s, 6)
+                    else if copy(s, 1, 12) = 'scriptparam=' then
+                        tmpScheme. schemeName:= midStr(s, 13) else
+                    begin
+                        ii:= 0;
+                        repeat
+                            isFound:= readInt(ints[ii].name, s, ints[ii].param^);
+                            inc(ii)
+                        until isFound or (ii > High(ints));
+
+                        if not isFound then
+                            begin
+                                ii:= 0;
+                                repeat
+                                    isFound:= readBool(bools[ii].name, s, bools[ii].param^);
+                                    inc(ii)
+                                until isFound or (ii > High(bools));
+                            end;
+                    end;
+
+                    scheme^:= tmpScheme
                 end;
             end;
         end;
 
         pfsClose(f)
     end;
-{
-name=AI TEST
-fortsmode
-divteams
-solidland
-border
-lowgrav
-laser
-invulnerability
-mines
-damagefactor=100
-turntime=40
-health=100
-suddendeath=0
-caseprobability=5
-vampiric
-karma
-artillery
-minestime=0
-landadds=4
-randomorder
-king
-placehog
-sharedammo
-disablegirders
-minedudpct=100
-explosives=40
-disablelandobjects
-aisurvival
-resethealth
-infattack
-resetweps
-perhogammo
-minesnum=0
-healthprobability=100
-healthcaseamount=50
-waterrise=0
-healthdecrease=0
-disablewind
-morewind
-ropepct=100
-tagteam
-getawaytime=100
-bottomborder
-worldedge=1
-scriptparam=@Invalid()
-}
 end;
 
 
@@ -197,7 +212,7 @@
 procedure freeSchemesList;
 begin
     if schemesList <> nil then
-        FreeMem(schemesList, sizeof(schemesList^) * schemesNumber)
+        FreeMem(schemesList, sizeof(schemesList^) * (schemesNumber + 1))
 end;
 
 end.