hedgewars/uFLSchemes.pas
author unc0rr
Sun, 25 Jan 2015 00:08:42 +0300
branchqmlfrontend
changeset 10751 97d00ace1aed
parent 10616 20a2d5e6930a
child 10754 8dd1cf1be5a2
permissions -rw-r--r--
CMake script for qmlFrontend
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10616
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     1
unit uFLSchemes;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     2
interface
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     3
uses uFLTypes;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     4
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     5
function getSchemesList: PPChar; cdecl;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     6
procedure freeSchemesList;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     7
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     8
implementation
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
     9
uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    10
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    11
const MAX_SCHEME_NAMES = 64;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    12
type
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    13
    TScheme = record
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    14
            schemeName: shortstring;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    15
        end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    16
    PScheme = ^TScheme;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    17
    TSchemeArray = array [0..0] of TScheme;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    18
    PSchemeArray = ^TSchemeArray;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    19
var
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    20
    schemesList: PScheme;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    21
    schemesNumber: LongInt;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    22
    listOfSchemeNames: array[0..MAX_SCHEME_NAMES] of PChar;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    23
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    24
procedure loadSchemes;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    25
var f: PFSFile;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    26
    scheme: PScheme;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    27
    schemes: PSchemeArray;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    28
    s: shortstring;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    29
    l, i: Longword;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    30
begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    31
    f:= pfsOpenRead('/Config/schemes.ini');
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    32
    schemesNumber:= 0;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    33
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    34
    if f <> nil then
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    35
    begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    36
        while (not pfsEOF(f)) and (schemesNumber = 0) do
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    37
        begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    38
            pfsReadLn(f, s);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    39
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    40
            if copy(s, 1, 5) = 'size=' then
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    41
                schemesNumber:= strToInt(midStr(s, 6));
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    42
        end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    43
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    44
        //inc(schemesNumber); // add some default schemes
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    45
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    46
        schemesList:= GetMem(sizeof(schemesList^) * (schemesNumber + 1));
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    47
        schemes:= PSchemeArray(schemesList);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    48
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    49
        while (not pfsEOF(f)) do
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    50
        begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    51
            pfsReadLn(f, s);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    52
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    53
            i:= 1;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    54
            while(i <= length(s)) and (s[i] <> '\') do inc(i);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    55
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    56
            if i < length(s) then
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    57
            begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    58
                l:= strToInt(copy(s, 1, i - 1));
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    59
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    60
                if (l < schemesNumber) and (l > 0) then
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    61
                begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    62
                    scheme:= @schemes^[l - 1];
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    63
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    64
                    if copy(s, i + 1, 5) = 'name=' then
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    65
                        scheme^. schemeName:= midStr(s, i + 6);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    66
                end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    67
            end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    68
        end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    69
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    70
        pfsClose(f)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    71
    end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    72
{
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    73
name=AI TEST
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    74
fortsmode=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    75
divteams=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    76
solidland=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    77
border=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    78
lowgrav=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    79
laser=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    80
invulnerability=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    81
mines=true
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    82
damagefactor=100
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    83
turntime=40
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    84
health=100
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    85
suddendeath=0
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    86
caseprobability=5
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    87
vampiric=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    88
karma=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    89
artillery=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    90
minestime=0
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    91
landadds=4
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    92
randomorder=true
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    93
king=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    94
placehog=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    95
sharedammo=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    96
disablegirders=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    97
minedudpct=100
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    98
explosives=40
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
    99
disablelandobjects=true
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   100
aisurvival=true
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   101
resethealth=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   102
infattack=true
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   103
resetweps=true
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   104
perhogammo=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   105
minesnum=0
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   106
healthprobability=100
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   107
healthcaseamount=50
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   108
waterrise=0
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   109
healthdecrease=0
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   110
disablewind=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   111
morewind=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   112
ropepct=100
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   113
tagteam=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   114
getawaytime=100
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   115
bottomborder=false
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   116
worldedge=1
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   117
scriptparam=@Invalid()
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   118
}
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   119
end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   120
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   121
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   122
function getSchemesList: PPChar; cdecl;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   123
var i, t, l: Longword;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   124
    scheme: PScheme;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   125
begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   126
    if schemesList = nil then
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   127
        loadSchemes;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   128
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   129
    t:= schemesNumber;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   130
    if t >= MAX_SCHEME_NAMES then 
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   131
        t:= MAX_SCHEME_NAMES;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   132
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   133
    scheme:= schemesList;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   134
    for i:= 0 to Pred(t) do
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   135
    begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   136
        l:= length(scheme^.schemeName);
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   137
        if l >= 255 then l:= 254;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   138
        scheme^.schemeName[l + 1]:= #0;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   139
        listOfSchemeNames[i]:= @scheme^.schemeName[1];
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   140
        inc(scheme)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   141
    end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   142
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   143
    listOfSchemeNames[t]:= nil;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   144
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   145
    getSchemesList:= listOfSchemeNames
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   146
end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   147
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   148
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   149
procedure freeSchemesList;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   150
begin
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   151
    if schemesList <> nil then
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   152
        FreeMem(schemesList, sizeof(schemesList^) * schemesNumber)
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   153
end;
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   154
20a2d5e6930a Schemes list combobox with their names
unc0rr
parents:
diff changeset
   155
end.