QTfrontend/model/gameSchemeModel.cpp
changeset 13197 0bc5f618ca7c
parent 13196 f93658732448
child 13198 ceae8e01af98
equal deleted inserted replaced
13196:f93658732448 13197:0bc5f618ca7c
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    17  */
       
    18 
       
    19 #include <QDebug>
       
    20 #include <QModelIndex>
       
    21 #include <QFile>
       
    22 #include <QTextStream>
       
    23 #include <QHash>
       
    24 
       
    25 #include "gameSchemeModel.h"
       
    26 #include "hwconsts.h"
       
    27 
       
    28 QList<QVariant> defaultScheme = QList<QVariant>()
       
    29                                 << QVariant("Default")     // name           0
       
    30                                 << QVariant(false)         // fortsmode      1
       
    31                                 << QVariant(false)         // team divide    2
       
    32                                 << QVariant(false)         // solid land     3
       
    33                                 << QVariant(false)         // border         4
       
    34                                 << QVariant(false)         // low gravity    5
       
    35                                 << QVariant(false)         // laser sight    6
       
    36                                 << QVariant(false)         // invulnerable   7
       
    37                                 << QVariant(false)         // reset health   8
       
    38                                 << QVariant(false)         // vampiric       9
       
    39                                 << QVariant(false)         // karma          10
       
    40                                 << QVariant(false)         // artillery      11
       
    41                                 << QVariant(true)          // random order   12
       
    42                                 << QVariant(false)         // king           13
       
    43                                 << QVariant(false)         // place hog      14
       
    44                                 << QVariant(false)         // shared ammo    15
       
    45                                 << QVariant(false)         // disable girders 16
       
    46                                 << QVariant(false)         // disable land objects 17
       
    47                                 << QVariant(false)         // AI survival    18
       
    48                                 << QVariant(false)         // inf. attack    19
       
    49                                 << QVariant(false)         // reset weps     20
       
    50                                 << QVariant(false)         // per hog ammo   21
       
    51                                 << QVariant(false)         // no wind        22
       
    52                                 << QVariant(false)         // more wind      23
       
    53                                 << QVariant(false)         // tag team       24
       
    54                                 << QVariant(false)         // bottom border  25
       
    55                                 << QVariant(100)           // damage modfier 26
       
    56                                 << QVariant(45)            // turn time      27
       
    57                                 << QVariant(100)           // init health    28
       
    58                                 << QVariant(15)            // sudden death   29
       
    59                                 << QVariant(5)             // case prob      30
       
    60                                 << QVariant(3)             // mines time     31
       
    61                                 << QVariant(4)             // mines number   32
       
    62                                 << QVariant(0)             // mine dud pct   33
       
    63                                 << QVariant(2)             // explosives     34
       
    64                                 << QVariant(0)             // air mines      35
       
    65                                 << QVariant(35)            // health case pct 36
       
    66                                 << QVariant(25)            // health case amt 37
       
    67                                 << QVariant(47)            // water rise amt 38
       
    68                                 << QVariant(5)             // health dec amt 39
       
    69                                 << QVariant(100)           // rope modfier   40
       
    70                                 << QVariant(100)           // get away time  41
       
    71                                 << QVariant(0)             // world edge     42
       
    72                                 << QVariant()              // scriptparam    43
       
    73                                 ;
       
    74 
       
    75 GameSchemeModel::GameSchemeModel(QObject* parent, const QString & directory) :
       
    76     QAbstractTableModel(parent),
       
    77     fileConfig(cfgdir->absolutePath() + "/schemes.ini", QSettings::IniFormat)
       
    78 {
       
    79     predefSchemesNames = QStringList()
       
    80                          << "Default"
       
    81                          << "Pro Mode"
       
    82                          << "Shoppa"
       
    83                          << "Clean Slate"
       
    84                          << "Minefield"
       
    85                          << "Barrel Mayhem"
       
    86                          << "Tunnel Hogs"
       
    87                          << "Timeless"
       
    88                          << "Thinking with Portals"
       
    89                          << "King Mode"
       
    90                          << "Construction Mode"
       
    91                          << "Space Invasion"
       
    92                          << "HedgeEditor"
       
    93                          ;
       
    94 
       
    95     numberOfDefaultSchemes = predefSchemesNames.size();
       
    96 
       
    97     spNames = QStringList()
       
    98               << "name"                //  0 | Name should be first forever
       
    99               << "fortsmode"           //  1
       
   100               << "divteams"            //  2
       
   101               << "solidland"           //  3
       
   102               << "border"              //  4
       
   103               << "lowgrav"             //  5
       
   104               << "laser"               //  6
       
   105               << "invulnerability"     //  7
       
   106               << "resethealth"         //  8
       
   107               << "vampiric"            //  9
       
   108               << "karma"               // 10
       
   109               << "artillery"           // 11
       
   110               << "randomorder"         // 12
       
   111               << "king"                // 13
       
   112               << "placehog"            // 14
       
   113               << "sharedammo"          // 15
       
   114               << "disablegirders"      // 16
       
   115               << "disablelandobjects"  // 17
       
   116               << "aisurvival"          // 18
       
   117               << "infattack"           // 19
       
   118               << "resetweps"           // 20
       
   119               << "perhogammo"          // 21
       
   120               << "disablewind"         // 22
       
   121               << "morewind"            // 23
       
   122               << "tagteam"             // 24
       
   123               << "bottomborder"        // 25
       
   124               << "damagefactor"        // 26
       
   125               << "turntime"            // 27
       
   126               << "health"              // 28
       
   127               << "suddendeath"         // 29
       
   128               << "caseprobability"     // 30
       
   129               << "minestime"           // 31
       
   130               << "minesnum"            // 32
       
   131               << "minedudpct"          // 33
       
   132               << "explosives"          // 34
       
   133               << "airmines"            // 35
       
   134               << "healthprobability"   // 36
       
   135               << "healthcaseamount"    // 37
       
   136               << "waterrise"           // 38
       
   137               << "healthdecrease"      // 39
       
   138               << "ropepct"             // 40
       
   139               << "getawaytime"         // 41
       
   140               << "worldedge"           // 42
       
   141               << "scriptparam"         // scriptparam    43
       
   142               ;
       
   143 
       
   144     QList<QVariant> proMode;
       
   145     proMode
       
   146             << predefSchemesNames[1]   // name           0
       
   147             << QVariant(false)         // fortsmode      1
       
   148             << QVariant(false)         // team divide    2
       
   149             << QVariant(false)         // solid land     3
       
   150             << QVariant(false)         // border         4
       
   151             << QVariant(false)         // low gravity    5
       
   152             << QVariant(false)         // laser sight    6
       
   153             << QVariant(false)         // invulnerable   7
       
   154             << QVariant(false)         // reset health   8
       
   155             << QVariant(false)         // vampiric       9
       
   156             << QVariant(false)         // karma          10
       
   157             << QVariant(false)         // artillery      11
       
   158             << QVariant(true)          // random order   12
       
   159             << QVariant(false)         // king           13
       
   160             << QVariant(false)         // place hog      14
       
   161             << QVariant(true)          // shared ammo    15
       
   162             << QVariant(false)         // disable girders 16
       
   163             << QVariant(false)         // disable land objects 17
       
   164             << QVariant(false)         // AI survival    18
       
   165             << QVariant(false)         // inf. attack    19
       
   166             << QVariant(false)         // reset weps     20
       
   167             << QVariant(false)         // per hog ammo   21
       
   168             << QVariant(false)         // no wind        22
       
   169             << QVariant(false)         // more wind      23
       
   170             << QVariant(false)         // tag team       24
       
   171             << QVariant(false)         // bottom border  25
       
   172             << QVariant(100)           // damage modfier 26
       
   173             << QVariant(15)            // turn time      27
       
   174             << QVariant(100)           // init health    28
       
   175             << QVariant(15)            // sudden death   29
       
   176             << QVariant(0)             // case prob      30
       
   177             << QVariant(3)             // mines time     31
       
   178             << QVariant(0)             // mines number   32
       
   179             << QVariant(0)             // mine dud pct   33
       
   180             << QVariant(2)             // explosives     34
       
   181             << QVariant(0)             // air mines      35
       
   182             << QVariant(35)            // health case pct 36
       
   183             << QVariant(25)            // health case amt 37
       
   184             << QVariant(47)            // water rise amt 38
       
   185             << QVariant(5)             // health dec amt 39
       
   186             << QVariant(100)           // rope modfier   40
       
   187             << QVariant(100)           // get away time  41
       
   188             << QVariant(0)             // world edge     42
       
   189             << QVariant()              // scriptparam    43
       
   190             ;
       
   191 
       
   192     QList<QVariant> shoppa;
       
   193     shoppa
       
   194             << predefSchemesNames[2]   // name           0
       
   195             << QVariant(false)         // fortsmode      1
       
   196             << QVariant(false)         // team divide    2
       
   197             << QVariant(true)          // solid land     3
       
   198             << QVariant(true)          // border         4
       
   199             << QVariant(false)         // low gravity    5
       
   200             << QVariant(false)         // laser sight    6
       
   201             << QVariant(false)         // invulnerable   7
       
   202             << QVariant(false)         // reset health   8
       
   203             << QVariant(false)         // vampiric       9
       
   204             << QVariant(false)         // karma          10
       
   205             << QVariant(false)         // artillery      11
       
   206             << QVariant(true)          // random order   12
       
   207             << QVariant(false)         // king           13
       
   208             << QVariant(false)         // place hog      14
       
   209             << QVariant(true)          // shared ammo    15
       
   210             << QVariant(true)          // disable girders 16
       
   211             << QVariant(true)         // disable land objects 17
       
   212             << QVariant(false)         // AI survival    18
       
   213             << QVariant(false)         // inf. attack    19
       
   214             << QVariant(true)          // reset weps     20
       
   215             << QVariant(false)         // per hog ammo   21
       
   216             << QVariant(false)         // no wind        22
       
   217             << QVariant(false)         // more wind      23
       
   218             << QVariant(false)         // tag team       24
       
   219             << QVariant(false)         // bottom border  25
       
   220             << QVariant(100)           // damage modfier 26
       
   221             << QVariant(30)            // turn time      27
       
   222             << QVariant(100)           // init health    28
       
   223             << QVariant(50)            // sudden death   29
       
   224             << QVariant(1)             // case prob      30
       
   225             << QVariant(0)             // mines time     31
       
   226             << QVariant(0)             // mines number   32
       
   227             << QVariant(0)             // mine dud pct   33
       
   228             << QVariant(0)             // explosives     34
       
   229             << QVariant(0)             // air mines      35
       
   230             << QVariant(0)             // health case pct 36
       
   231             << QVariant(25)            // health case amt 37
       
   232             << QVariant(0)             // water rise amt 38
       
   233             << QVariant(0)             // health dec amt 39
       
   234             << QVariant(100)           // rope modfier   40
       
   235             << QVariant(100)           // get away time  41
       
   236             << QVariant(0)             // world edge     42
       
   237             << QVariant()              // scriptparam    43
       
   238             ;
       
   239 
       
   240     QList<QVariant> cleanslate;
       
   241     cleanslate
       
   242             << predefSchemesNames[3]   // name           0
       
   243             << QVariant(false)         // fortsmode      1
       
   244             << QVariant(false)         // team divide    2
       
   245             << QVariant(false)         // solid land     3
       
   246             << QVariant(false)         // border         4
       
   247             << QVariant(false)         // low gravity    5
       
   248             << QVariant(false)         // laser sight    6
       
   249             << QVariant(false)         // invulnerable   7
       
   250             << QVariant(true)          // reset health   8
       
   251             << QVariant(false)         // vampiric       9
       
   252             << QVariant(false)         // karma          10
       
   253             << QVariant(false)         // artillery      11
       
   254             << QVariant(true)          // random order   12
       
   255             << QVariant(false)         // king           13
       
   256             << QVariant(false)         // place hog      14
       
   257             << QVariant(false)         // shared ammo    15
       
   258             << QVariant(false)         // disable girders 16
       
   259             << QVariant(false)         // disable land objects 17
       
   260             << QVariant(false)         // AI survival    18
       
   261             << QVariant(true)          // inf. attack    19
       
   262             << QVariant(true)          // reset weps     20
       
   263             << QVariant(false)         // per hog ammo   21
       
   264             << QVariant(false)         // no wind        22
       
   265             << QVariant(false)         // more wind      23
       
   266             << QVariant(false)         // tag team       24
       
   267             << QVariant(false)         // bottom border  25
       
   268             << QVariant(100)           // damage modfier 26
       
   269             << QVariant(45)            // turn time      27
       
   270             << QVariant(100)           // init health    28
       
   271             << QVariant(15)            // sudden death   29
       
   272             << QVariant(5)             // case prob      30
       
   273             << QVariant(3)             // mines time     31
       
   274             << QVariant(4)             // mines number   32
       
   275             << QVariant(0)             // mine dud pct   33
       
   276             << QVariant(2)             // explosives     34
       
   277             << QVariant(0)             // air mines      35
       
   278             << QVariant(35)            // health case pct 36
       
   279             << QVariant(25)            // health case amt 37
       
   280             << QVariant(47)            // water rise amt 38
       
   281             << QVariant(5)             // health dec amt 39
       
   282             << QVariant(100)           // rope modfier   40
       
   283             << QVariant(100)           // get away time  41
       
   284             << QVariant(0)             // world edge     42
       
   285             << QVariant()              // scriptparam    43
       
   286             ;
       
   287 
       
   288     QList<QVariant> minefield;
       
   289     minefield
       
   290             << predefSchemesNames[4]   // name           0
       
   291             << QVariant(false)         // fortsmode      1
       
   292             << QVariant(false)         // team divide    2
       
   293             << QVariant(false)         // solid land     3
       
   294             << QVariant(false)         // border         4
       
   295             << QVariant(false)         // low gravity    5
       
   296             << QVariant(false)         // laser sight    6
       
   297             << QVariant(false)         // invulnerable   7
       
   298             << QVariant(false)         // reset health   8
       
   299             << QVariant(false)         // vampiric       9
       
   300             << QVariant(false)         // karma          10
       
   301             << QVariant(false)         // artillery      11
       
   302             << QVariant(true)          // random order   12
       
   303             << QVariant(false)         // king           13
       
   304             << QVariant(false)         // place hog      14
       
   305             << QVariant(true)          // shared ammo    15
       
   306             << QVariant(true)          // disable girders 16
       
   307             << QVariant(false)         // disable land objects 17
       
   308             << QVariant(false)         // AI survival    18
       
   309             << QVariant(false)         // inf. attack    19
       
   310             << QVariant(false)         // reset weps     20
       
   311             << QVariant(false)         // per hog ammo   21
       
   312             << QVariant(false)         // no wind        22
       
   313             << QVariant(false)         // more wind      23
       
   314             << QVariant(false)         // tag team       24
       
   315             << QVariant(false)         // bottom border  25
       
   316             << QVariant(100)           // damage modfier 26
       
   317             << QVariant(30)            // turn time      27
       
   318             << QVariant(50)            // init health    28
       
   319             << QVariant(15)            // sudden death   29
       
   320             << QVariant(0)             // case prob      30
       
   321             << QVariant(0)             // mines time     31
       
   322             << QVariant(200)           // mines number   32
       
   323             << QVariant(0)             // mine dud pct   33
       
   324             << QVariant(0)             // explosives     34
       
   325             << QVariant(0)             // air mines      35
       
   326             << QVariant(35)            // health case pct 36
       
   327             << QVariant(25)            // health case amt 37
       
   328             << QVariant(47)            // water rise amt 38
       
   329             << QVariant(5)             // health dec amt 39
       
   330             << QVariant(100)           // rope modfier   40
       
   331             << QVariant(100)           // get away time  41
       
   332             << QVariant(0)             // world edge     42
       
   333             << QVariant()              // scriptparam    43
       
   334             ;
       
   335 
       
   336     QList<QVariant> barrelmayhem;
       
   337     barrelmayhem
       
   338             << predefSchemesNames[5]   // name           0
       
   339             << QVariant(false)         // fortsmode      1
       
   340             << QVariant(false)         // team divide    2
       
   341             << QVariant(false)         // solid land     3
       
   342             << QVariant(false)         // border         4
       
   343             << QVariant(false)         // low gravity    5
       
   344             << QVariant(false)         // laser sight    6
       
   345             << QVariant(false)         // invulnerable   7
       
   346             << QVariant(false)         // reset health   8
       
   347             << QVariant(false)         // vampiric       9
       
   348             << QVariant(false)         // karma          10
       
   349             << QVariant(false)         // artillery      11
       
   350             << QVariant(true)          // random order   12
       
   351             << QVariant(false)         // king           13
       
   352             << QVariant(false)         // place hog      14
       
   353             << QVariant(true)          // shared ammo    15
       
   354             << QVariant(false)         // disable girders 16
       
   355             << QVariant(false)         // disable land objects 17
       
   356             << QVariant(false)         // AI survival    18
       
   357             << QVariant(false)         // inf. attack    19
       
   358             << QVariant(false)         // reset weps     20
       
   359             << QVariant(false)         // per hog ammo   21
       
   360             << QVariant(false)         // no wind        22
       
   361             << QVariant(false)         // more wind      23
       
   362             << QVariant(false)         // tag team       24
       
   363             << QVariant(false)         // bottom border  25
       
   364             << QVariant(100)           // damage modfier 26
       
   365             << QVariant(30)            // turn time      27
       
   366             << QVariant(100)           // init health    28
       
   367             << QVariant(15)            // sudden death   29
       
   368             << QVariant(0)             // case prob      30
       
   369             << QVariant(0)             // mines time     31
       
   370             << QVariant(0)             // mines number   32
       
   371             << QVariant(0)             // mine dud pct   33
       
   372             << QVariant(200)           // explosives     34
       
   373             << QVariant(0)             // air mines      35
       
   374             << QVariant(35)            // health case pct 36
       
   375             << QVariant(25)            // health case amt 37
       
   376             << QVariant(47)            // water rise amt 38
       
   377             << QVariant(5)             // health dec amt 39
       
   378             << QVariant(100)           // rope modfier   40
       
   379             << QVariant(100)           // get away time  41
       
   380             << QVariant(0)             // world edge     42
       
   381             << QVariant()              // scriptparam    43
       
   382             ;
       
   383 
       
   384     QList<QVariant> tunnelhogs;
       
   385     tunnelhogs
       
   386             << predefSchemesNames[6]   // name           0
       
   387             << QVariant(false)         // fortsmode      1
       
   388             << QVariant(false)         // team divide    2
       
   389             << QVariant(false)         // solid land     3
       
   390             << QVariant(true)          // border         4
       
   391             << QVariant(false)         // low gravity    5
       
   392             << QVariant(false)         // laser sight    6
       
   393             << QVariant(false)         // invulnerable   7
       
   394             << QVariant(false)         // reset health   8
       
   395             << QVariant(false)         // vampiric       9
       
   396             << QVariant(false)         // karma          10
       
   397             << QVariant(false)         // artillery      11
       
   398             << QVariant(true)          // random order   12
       
   399             << QVariant(false)         // king           13
       
   400             << QVariant(false)         // place hog      14
       
   401             << QVariant(true)          // shared ammo    15
       
   402             << QVariant(true)          // disable girders 16
       
   403             << QVariant(true)          // disable land objects 17
       
   404             << QVariant(false)         // AI survival    18
       
   405             << QVariant(false)         // inf. attack    19
       
   406             << QVariant(false)         // reset weps     20
       
   407             << QVariant(false)         // per hog ammo   21
       
   408             << QVariant(false)         // no wind        22
       
   409             << QVariant(false)         // more wind      23
       
   410             << QVariant(false)         // tag team       24
       
   411             << QVariant(false)         // bottom border  25
       
   412             << QVariant(100)           // damage modfier 26
       
   413             << QVariant(30)            // turn time      27
       
   414             << QVariant(100)           // init health    28
       
   415             << QVariant(15)            // sudden death   29
       
   416             << QVariant(5)             // case prob      30
       
   417             << QVariant(3)             // mines time     31
       
   418             << QVariant(10)            // mines number   32
       
   419             << QVariant(10)            // mine dud pct   33
       
   420             << QVariant(10)            // explosives     34
       
   421             << QVariant(4)             // air mines      35
       
   422             << QVariant(35)            // health case pct 36
       
   423             << QVariant(25)            // health case amt 37
       
   424             << QVariant(47)            // water rise amt 38
       
   425             << QVariant(5)             // health dec amt 39
       
   426             << QVariant(100)           // rope modfier   40
       
   427             << QVariant(100)           // get away time  41
       
   428             << QVariant(0)             // world edge     42
       
   429             << QVariant()              // scriptparam    43
       
   430             ;
       
   431 
       
   432     QList<QVariant> timeless;
       
   433     timeless
       
   434             << predefSchemesNames[7]   // name           0
       
   435             << QVariant(false)         // fortsmode      1
       
   436             << QVariant(false)         // team divide    2
       
   437             << QVariant(false)         // solid land     3
       
   438             << QVariant(false)         // border         4
       
   439             << QVariant(false)         // low gravity    5
       
   440             << QVariant(false)         // laser sight    6
       
   441             << QVariant(false)         // invulnerable   7
       
   442             << QVariant(false)         // reset health   8
       
   443             << QVariant(false)         // vampiric       9
       
   444             << QVariant(false)         // karma          10
       
   445             << QVariant(false)         // artillery      11
       
   446             << QVariant(true)          // random order   12
       
   447             << QVariant(false)         // king           13
       
   448             << QVariant(false)         // place hog      14
       
   449             << QVariant(false)         // shared ammo    15
       
   450             << QVariant(false)         // disable girders 16
       
   451             << QVariant(false)         // disable land objects 17
       
   452             << QVariant(false)         // AI survival    18
       
   453             << QVariant(false)         // inf. attack    19
       
   454             << QVariant(false)         // reset weps     20
       
   455             << QVariant(true)          // per hog ammo   21
       
   456             << QVariant(false)         // no wind        22
       
   457             << QVariant(false)         // more wind      23
       
   458             << QVariant(false)         // tag team       24
       
   459             << QVariant(false)         // bottom border  25
       
   460             << QVariant(100)           // damage modfier 26
       
   461             << QVariant(9999)          // turn time      27
       
   462             << QVariant(100)           // init health    28
       
   463             << QVariant(15)            // sudden death   29
       
   464             << QVariant(5)             // case prob      30
       
   465             << QVariant(3)             // mines time     31
       
   466             << QVariant(5)             // mines number   32
       
   467             << QVariant(10)            // mine dud pct   33
       
   468             << QVariant(2)             // explosives     34
       
   469             << QVariant(0)             // air mines      35
       
   470             << QVariant(35)            // health case pct 36
       
   471             << QVariant(30)            // health case amt 37
       
   472             << QVariant(0)             // water rise amt 38
       
   473             << QVariant(0)             // health dec amt 39
       
   474             << QVariant(100)           // rope modfier   40
       
   475             << QVariant(100)           // get away time  41
       
   476             << QVariant(0)             // world edge     42
       
   477             << QVariant()              // scriptparam    43
       
   478             ;
       
   479 
       
   480     QList<QVariant> thinkingportals;
       
   481     thinkingportals
       
   482             << predefSchemesNames[8]   // name           0
       
   483             << QVariant(false)         // fortsmode      1
       
   484             << QVariant(false)         // team divide    2
       
   485             << QVariant(false)         // solid land     3
       
   486             << QVariant(false)         // border         4
       
   487             << QVariant(false)         // low gravity    5
       
   488             << QVariant(false)         // laser sight    6
       
   489             << QVariant(false)         // invulnerable   7
       
   490             << QVariant(false)         // reset health   8
       
   491             << QVariant(false)         // vampiric       9
       
   492             << QVariant(false)         // karma          10
       
   493             << QVariant(true)          // artillery      11
       
   494             << QVariant(true)          // random order   12
       
   495             << QVariant(false)         // king           13
       
   496             << QVariant(false)         // place hog      14
       
   497             << QVariant(false)         // shared ammo    15
       
   498             << QVariant(false)         // disable girders 16
       
   499             << QVariant(false)         // disable land objects 17
       
   500             << QVariant(false)         // AI survival    18
       
   501             << QVariant(false)         // inf. attack    19
       
   502             << QVariant(false)         // reset weps     20
       
   503             << QVariant(false)         // per hog ammo   21
       
   504             << QVariant(false)         // no wind        22
       
   505             << QVariant(false)         // more wind      23
       
   506             << QVariant(false)         // tag team       24
       
   507             << QVariant(false)         // bottom border  25
       
   508             << QVariant(100)           // damage modfier 26
       
   509             << QVariant(45)            // turn time      27
       
   510             << QVariant(100)           // init health    28
       
   511             << QVariant(15)            // sudden death   29
       
   512             << QVariant(2)             // case prob      30
       
   513             << QVariant(3)             // mines time     31
       
   514             << QVariant(5)             // mines number   32
       
   515             << QVariant(0)             // mine dud pct   33
       
   516             << QVariant(5)             // explosives     34
       
   517             << QVariant(4)             // air mines      35
       
   518             << QVariant(25)            // health case pct 36
       
   519             << QVariant(25)            // health case amt 37
       
   520             << QVariant(47)            // water rise amt 38
       
   521             << QVariant(5)             // health dec amt 39
       
   522             << QVariant(100)           // rope modfier   40
       
   523             << QVariant(100)           // get away time  41
       
   524             << QVariant(0)             // world edge     42
       
   525             << QVariant()              // scriptparam    43
       
   526             ;
       
   527 
       
   528     QList<QVariant> kingmode;
       
   529     kingmode
       
   530             << predefSchemesNames[9]  // name           0
       
   531             << QVariant(false)         // fortsmode      1
       
   532             << QVariant(false)         // team divide    2
       
   533             << QVariant(false)         // solid land     3
       
   534             << QVariant(false)         // border         4
       
   535             << QVariant(false)         // low gravity    5
       
   536             << QVariant(false)         // laser sight    6
       
   537             << QVariant(false)         // invulnerable   7
       
   538             << QVariant(false)         // reset health   8
       
   539             << QVariant(false)         // vampiric       9
       
   540             << QVariant(false)         // karma          10
       
   541             << QVariant(false)         // artillery      11
       
   542             << QVariant(true)          // random order   12
       
   543             << QVariant(true)          // king           13
       
   544             << QVariant(false)         // place hog      14
       
   545             << QVariant(false)         // shared ammo    15
       
   546             << QVariant(false)         // disable girders 16
       
   547             << QVariant(false)         // disable land objects 17
       
   548             << QVariant(false)         // AI survival    18
       
   549             << QVariant(false)         // inf. attack    19
       
   550             << QVariant(false)         // reset weps     20
       
   551             << QVariant(false)         // per hog ammo   21
       
   552             << QVariant(false)         // no wind        22
       
   553             << QVariant(false)         // more wind      23
       
   554             << QVariant(false)         // tag team       24
       
   555             << QVariant(false)         // bottom border  25
       
   556             << QVariant(100)           // damage modfier 26
       
   557             << QVariant(45)            // turn time      27
       
   558             << QVariant(100)           // init health    28
       
   559             << QVariant(15)            // sudden death   29
       
   560             << QVariant(5)             // case prob      30
       
   561             << QVariant(3)             // mines time     31
       
   562             << QVariant(4)             // mines number   32
       
   563             << QVariant(0)             // mine dud pct   33
       
   564             << QVariant(2)             // explosives     34
       
   565             << QVariant(0)             // air mines      35
       
   566             << QVariant(35)            // health case pct 36
       
   567             << QVariant(25)            // health case amt 37
       
   568             << QVariant(47)            // water rise amt 38
       
   569             << QVariant(5)             // health dec amt 39
       
   570             << QVariant(100)           // rope modfier   40
       
   571             << QVariant(100)           // get away time  41
       
   572             << QVariant(0)             // world edge     42
       
   573             << QVariant()              // scriptparam    43
       
   574             ;
       
   575 
       
   576     QList<QVariant> construction;
       
   577     construction
       
   578             << predefSchemesNames[10]  // name           0
       
   579             << QVariant(false)         // fortsmode      1
       
   580             << QVariant(false)         // team divide    2
       
   581             << QVariant(false)         // solid land     3
       
   582             << QVariant(false)         // border         4
       
   583             << QVariant(false)         // low gravity    5
       
   584             << QVariant(false)         // laser sight    6
       
   585             << QVariant(false)         // invulnerable   7
       
   586             << QVariant(false)         // reset health   8
       
   587             << QVariant(false)         // vampiric       9
       
   588             << QVariant(false)         // karma          10
       
   589             << QVariant(false)         // artillery      11
       
   590             << QVariant(true)          // random order   12
       
   591             << QVariant(false)          // king           13
       
   592             << QVariant(false)         // place hog      14
       
   593             << QVariant(false)         // shared ammo    15
       
   594             << QVariant(true)         // disable girders 16
       
   595             << QVariant(true)         // disable land objects 17
       
   596             << QVariant(false)         // AI survival    18
       
   597             << QVariant(true)         // inf. attack    19
       
   598             << QVariant(false)         // reset weps     20
       
   599             << QVariant(true)         // per hog ammo   21
       
   600             << QVariant(false)         // no wind        22
       
   601             << QVariant(false)         // more wind      23
       
   602             << QVariant(false)         // tag team       24
       
   603             << QVariant(false)         // bottom border  25
       
   604             << QVariant(100)           // damage modfier 26
       
   605             << QVariant(45)            // turn time      27
       
   606             << QVariant(100)           // init health    28
       
   607             << QVariant(15)            // sudden death   29
       
   608             << QVariant(5)             // case prob      30
       
   609             << QVariant(3)             // mines time     31
       
   610             << QVariant(0)             // mines number   32
       
   611             << QVariant(0)             // mine dud pct   33
       
   612             << QVariant(0)             // explosives     34
       
   613             << QVariant(0)             // air mines      35
       
   614             << QVariant(35)            // health case pct 36
       
   615             << QVariant(25)            // health case amt 37
       
   616             << QVariant(47)            // water rise amt 38
       
   617             << QVariant(5)             // health dec amt 39
       
   618             << QVariant(100)           // rope modfier   40
       
   619             << QVariant(100)           // get away time  41
       
   620             << QVariant(0)             // world edge     42
       
   621             // NOTE: If you change this, also change the defaults in the Construction Mode script
       
   622             << QVariant("initialenergy=550, energyperround=50, maxenergy=1000, cratesperround=5") // scriptparam    43
       
   623             ;
       
   624 
       
   625     QList<QVariant> spaceinvasion;
       
   626     spaceinvasion
       
   627             << predefSchemesNames[11]  // name           0
       
   628             << QVariant(false)         // fortsmode      1
       
   629             << QVariant(false)         // team divide    2
       
   630             << QVariant(false)         // solid land     3
       
   631             << QVariant(false)         // border         4
       
   632             << QVariant(false)         // low gravity    5
       
   633             << QVariant(false)         // laser sight    6
       
   634             << QVariant(false)         // invulnerable   7
       
   635             << QVariant(false)         // reset health   8
       
   636             << QVariant(false)         // vampiric       9
       
   637             << QVariant(false)         // karma          10
       
   638             << QVariant(false)         // artillery      11
       
   639             << QVariant(true)          // random order   12
       
   640             << QVariant(false)         // king           13
       
   641             << QVariant(false)         // place hog      14
       
   642             << QVariant(false)         // shared ammo    15
       
   643             << QVariant(true)          // disable girders 16
       
   644             << QVariant(false)         // disable land objects 17
       
   645             << QVariant(false)         // AI survival    18
       
   646             << QVariant(false)         // inf. attack    19
       
   647             << QVariant(false)         // reset weps     20
       
   648             << QVariant(false)         // per hog ammo   21
       
   649             << QVariant(false)         // no wind        22
       
   650             << QVariant(false)         // more wind      23
       
   651             << QVariant(false)         // tag team       24
       
   652             << QVariant(false)         // bottom border  25
       
   653             << QVariant(100)           // damage modfier 26
       
   654             << QVariant(45)            // turn time      27
       
   655             << QVariant(100)           // init health    28
       
   656             << QVariant(50)            // sudden death   29
       
   657             << QVariant(0)             // case prob      30
       
   658             << QVariant(3)             // mines time     31
       
   659             << QVariant(0)             // mines number   32
       
   660             << QVariant(0)             // mine dud pct   33
       
   661             << QVariant(0)             // explosives     34
       
   662             << QVariant(0)             // air mines      35
       
   663             << QVariant(0)             // health case pct 36
       
   664             << QVariant(25)            // health case amt 37
       
   665             << QVariant(0)             // water rise amt 38
       
   666             << QVariant(0)             // health dec amt 39
       
   667             << QVariant(100)           // rope modfier   40
       
   668             << QVariant(100)           // get away time  41
       
   669             << QVariant(0)             // world edge     42
       
   670             // NOTE: If you change this, also change the defaults in the Space Invasion script
       
   671             << QVariant("rounds=3, shield=30, barrels=5, pings=2, barrelbonus=3, shieldbonus=30, timebonus=4") // scriptparam    43
       
   672             ;
       
   673 
       
   674     QList<QVariant> hedgeeditor;
       
   675     hedgeeditor
       
   676             << predefSchemesNames[12]  // name           0
       
   677             << QVariant(false)         // fortsmode      1
       
   678             << QVariant(false)         // team divide    2
       
   679             << QVariant(false)         // solid land     3
       
   680             << QVariant(false)         // border         4
       
   681             << QVariant(false)         // low gravity    5
       
   682             << QVariant(false)         // laser sight    6
       
   683             << QVariant(false)         // invulnerable   7
       
   684             << QVariant(false)         // reset health   8
       
   685             << QVariant(false)         // vampiric       9
       
   686             << QVariant(false)         // karma          10
       
   687             << QVariant(false)         // artillery      11
       
   688             << QVariant(false)         // random order   12
       
   689             << QVariant(false)         // king           13
       
   690             << QVariant(false)         // place hog      14
       
   691             << QVariant(false)         // shared ammo    15
       
   692             << QVariant(false)         // disable girders 16
       
   693             << QVariant(false)         // disable land objects 17
       
   694             << QVariant(false)         // AI survival    18
       
   695             << QVariant(false)         // inf. attack    19
       
   696             << QVariant(false)         // reset weps     20
       
   697             << QVariant(true)          // per hog ammo   21
       
   698             << QVariant(false)         // no wind        22
       
   699             << QVariant(false)         // more wind      23
       
   700             << QVariant(false)         // tag team       24
       
   701             << QVariant(false)         // bottom border  25
       
   702             << QVariant(100)           // damage modfier 26
       
   703             << QVariant(9999)          // turn time      27
       
   704             << QVariant(100)           // init health    28
       
   705             << QVariant(50)            // sudden death   29
       
   706             << QVariant(0)             // case prob      30
       
   707             << QVariant(3)             // mines time     31
       
   708             << QVariant(0)             // mines number   32
       
   709             << QVariant(0)             // mine dud pct   33
       
   710             << QVariant(0)             // explosives     34
       
   711             << QVariant(0)             // air mines      35
       
   712             << QVariant(35)            // health case pct 36
       
   713             << QVariant(25)            // health case amt 37
       
   714             << QVariant(0)            // water rise amt 38
       
   715             << QVariant(0)             // health dec amt 39
       
   716             << QVariant(100)           // rope modfier   40
       
   717             << QVariant(100)           // get away time  41
       
   718             << QVariant(0)             // world edge     42
       
   719             << QVariant()              // scriptparam    43
       
   720             ;
       
   721 
       
   722 
       
   723 
       
   724     schemes.append(defaultScheme);
       
   725     schemes.append(proMode);
       
   726     schemes.append(shoppa);
       
   727     schemes.append(cleanslate);
       
   728     schemes.append(minefield);
       
   729     schemes.append(barrelmayhem);
       
   730     schemes.append(tunnelhogs);
       
   731     schemes.append(timeless);
       
   732     schemes.append(thinkingportals);
       
   733     schemes.append(kingmode);
       
   734     schemes.append(construction);
       
   735     schemes.append(spaceinvasion);
       
   736     schemes.append(hedgeeditor);
       
   737 
       
   738     if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
       
   739         QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
       
   740     }
       
   741     if (!QDir(directory).exists()) {
       
   742         QDir().mkdir(directory);
       
   743 
       
   744         qDebug("No /Schemes/Game directory found. Trying to import game schemes from schemes.ini.");
       
   745 
       
   746         int size = fileConfig.beginReadArray("schemes");
       
   747         int imported = 0;
       
   748         for (int i = 0; i < size; ++i)
       
   749         {
       
   750             fileConfig.setArrayIndex(i);
       
   751 
       
   752             QString schemeName = fileConfig.value(spNames[0]).toString();
       
   753             if (!schemeName.isNull() && !predefSchemesNames.contains(schemeName))
       
   754             {
       
   755                 QList<QVariant> scheme;
       
   756                 QFile file(directory + "/" + schemeName + ".hwg");
       
   757 
       
   758                 // Add keys to scheme info and create file
       
   759                 if (file.open(QIODevice::WriteOnly)) {
       
   760                     QTextStream stream(&file);
       
   761 
       
   762                     for (int k = 0; k < spNames.size(); ++k) {
       
   763                         scheme << fileConfig.value(spNames[k], defaultScheme[k]);
       
   764 
       
   765                         // File handling
       
   766                         // We skip the name key (k==0), it is not stored redundantly in file.
       
   767                         // The file name is used for that already.
       
   768                         if(k != 0) {
       
   769                             // The file is just a list of key=value pairs
       
   770                             stream << spNames[k] << "=" << fileConfig.value(spNames[k], defaultScheme[k]).toString();
       
   771                             stream << endl;
       
   772                         }
       
   773                     }
       
   774                     file.close();
       
   775                 }
       
   776                 imported++;
       
   777 
       
   778                 schemes.append(scheme);
       
   779             }
       
   780         }
       
   781         qDebug("%d game scheme(s) imported.", imported);
       
   782         fileConfig.endArray();
       
   783     } else {
       
   784         QStringList scheme_dir = QDir(directory).entryList(QDir::Files);
       
   785 
       
   786         for(int i = 0; i < scheme_dir.size(); i++)
       
   787         {
       
   788             QList<QVariant> scheme;
       
   789             QFile file(directory + "/" + scheme_dir[i]);
       
   790 
       
   791             // Chop off file name suffix
       
   792             QString schemeName = scheme_dir[i];
       
   793             if (schemeName.endsWith(".hwg", Qt::CaseInsensitive)) {
       
   794                 schemeName.chop(4);
       
   795             }
       
   796             // Parse game scheme file
       
   797             if (file.open(QIODevice::ReadOnly)) {
       
   798                 QTextStream stream(&file);
       
   799                 QString line, key, value;
       
   800                 QHash<QString, QString> fileKeyValues;
       
   801                 do {
       
   802                     // Read line and get key and value
       
   803                     line = stream.readLine();
       
   804                     key = line.section(QChar('='), 0, 0);
       
   805                     value = line.section(QChar('='), 1);
       
   806                     if(!key.isNull() && !value.isNull()) {
       
   807                         fileKeyValues[key] = value;
       
   808                     }
       
   809                 } while (!line.isNull());
       
   810 
       
   811                 // Add scheme name manually
       
   812                 scheme << schemeName;
       
   813                 // Add other keys from the QHash.
       
   814                 for (int k = 1; k < spNames.size(); ++k) {
       
   815                     key = spNames[k];
       
   816                     if (fileKeyValues.contains(key)) {
       
   817                         scheme << fileKeyValues.value(key);
       
   818                     } else {
       
   819                         // Use default value in case the key is not set
       
   820                         scheme << defaultScheme[k];
       
   821                     }
       
   822                 }
       
   823                 schemes.append(scheme);
       
   824 
       
   825                 file.close();
       
   826             }
       
   827         }
       
   828     }
       
   829 }
       
   830 
       
   831 QVariant GameSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
       
   832 {
       
   833     Q_UNUSED(section);
       
   834     Q_UNUSED(orientation);
       
   835     Q_UNUSED(role);
       
   836 
       
   837     return QVariant();
       
   838 }
       
   839 
       
   840 int GameSchemeModel::rowCount(const QModelIndex &parent) const
       
   841 {
       
   842     if (parent.isValid())
       
   843         return 0;
       
   844     else
       
   845         return schemes.size();
       
   846 }
       
   847 
       
   848 int GameSchemeModel::columnCount(const QModelIndex & parent) const
       
   849 {
       
   850     if (parent.isValid())
       
   851         return 0;
       
   852     else
       
   853         return defaultScheme.size();
       
   854 }
       
   855 
       
   856 bool GameSchemeModel::hasScheme(QString name)
       
   857 {
       
   858     for(int i=0; i<schemes.size(); i++)
       
   859     {
       
   860         if(schemes[i][0] == name)
       
   861         {
       
   862             return true;
       
   863         }
       
   864     }
       
   865     return false;
       
   866 }
       
   867 
       
   868 Qt::ItemFlags GameSchemeModel::flags(const QModelIndex & index) const
       
   869 {
       
   870     Q_UNUSED(index);
       
   871 
       
   872     return
       
   873         Qt::ItemIsEnabled
       
   874         | Qt::ItemIsSelectable
       
   875         | Qt::ItemIsEditable;
       
   876 }
       
   877 
       
   878 bool GameSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role)
       
   879 {
       
   880     if (!index.isValid() || index.row() < numberOfDefaultSchemes
       
   881             || index.row() >= schemes.size()
       
   882             || index.column() >= defaultScheme.size()
       
   883             || role != Qt::EditRole)
       
   884         return false;
       
   885 
       
   886     schemes[index.row()][index.column()] = value;
       
   887 
       
   888     emit dataChanged(index, index);
       
   889     return true;
       
   890 }
       
   891 
       
   892 bool GameSchemeModel::insertRows(int row, int count, const QModelIndex & parent)
       
   893 {
       
   894     Q_UNUSED(count);
       
   895 
       
   896     beginInsertRows(parent, schemes.size(), schemes.size());
       
   897 
       
   898     if (row == -1)
       
   899     {
       
   900         QList<QVariant> newScheme = defaultScheme;
       
   901 
       
   902         QString newName = tr("New");
       
   903         if(hasScheme(newName))
       
   904         {
       
   905             //name already used -> look for an appropriate name:
       
   906             int i=2;
       
   907             while(hasScheme(newName = tr("New (%1)").arg(i++))) ;
       
   908         }
       
   909         newScheme[0] = QVariant(newName);
       
   910         schemes.insert(schemes.size(), newScheme);
       
   911     }
       
   912     else
       
   913     {
       
   914         QList<QVariant> newScheme = schemes[row];
       
   915         QString oldName = newScheme[0].toString();
       
   916         QString newName = tr("Copy of %1").arg(oldName);
       
   917         if(hasScheme(newName))
       
   918         {
       
   919             //name already used -> look for an appropriate name:
       
   920             int i=2;
       
   921             while(hasScheme(newName = tr("Copy of %1 (%2)").arg(oldName).arg(i++)));
       
   922         }
       
   923         newScheme[0] = QVariant(newName);
       
   924         schemes.insert(schemes.size(), newScheme);
       
   925     }
       
   926 
       
   927     endInsertRows();
       
   928 
       
   929     return true;
       
   930 }
       
   931 
       
   932 bool GameSchemeModel::removeRows(int row, int count, const QModelIndex & parent)
       
   933 {
       
   934     if(count != 1
       
   935             || row < numberOfDefaultSchemes
       
   936             || row >= schemes.size())
       
   937         return false;
       
   938 
       
   939     beginRemoveRows(parent, row, row);
       
   940 
       
   941     QList<QVariant> scheme = schemes[row];
       
   942     int j = spNames.indexOf("name");
       
   943     QFile(cfgdir->absolutePath() + "/Schemes/Game/" + scheme[j].toString() + ".hwg").remove();
       
   944     schemes.removeAt(row);
       
   945 
       
   946     endRemoveRows();
       
   947 
       
   948     return true;
       
   949 }
       
   950 
       
   951 QVariant GameSchemeModel::data(const QModelIndex &index, int role) const
       
   952 {
       
   953     if (!index.isValid() || index.row() < 0
       
   954             || index.row() >= schemes.size()
       
   955             || index.column() >= defaultScheme.size()
       
   956             || (role != Qt::EditRole && role != Qt::DisplayRole)
       
   957        )
       
   958         return QVariant();
       
   959 
       
   960     return schemes[index.row()][index.column()];
       
   961 }
       
   962 
       
   963 void GameSchemeModel::Save()
       
   964 {
       
   965     fileConfig.beginWriteArray("schemes");
       
   966     for (int i = 0; i < schemes.size() - numberOfDefaultSchemes; ++i)
       
   967     {
       
   968         QList<QVariant> scheme = schemes[i + numberOfDefaultSchemes];
       
   969         int j = spNames.indexOf("name");
       
   970 
       
   971         QString schemeName = scheme[j].toString();
       
   972         QFile file(cfgdir->absolutePath() + "/Schemes/Game/" + schemeName + ".hwg");
       
   973 
       
   974         if (file.open(QIODevice::WriteOnly)) {
       
   975             QTextStream stream(&file);
       
   976             for (int k = 0; k < spNames.size(); ++k) {
       
   977                 // We skip the name key
       
   978                 if(k != j) {
       
   979                     // The file is just a list of key=value pairs
       
   980                     stream << spNames[k] << "=" << scheme[k].toString();
       
   981                     stream << endl;
       
   982                 }
       
   983             }
       
   984             file.close();
       
   985         }
       
   986     }
       
   987     fileConfig.endArray();
       
   988 }
       
   989 
       
   990 
       
   991 NetGameSchemeModel::NetGameSchemeModel(QObject * parent) :
       
   992     QAbstractTableModel(parent)
       
   993 {
       
   994     netScheme = defaultScheme;
       
   995 }
       
   996 
       
   997 QVariant NetGameSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
       
   998 {
       
   999     Q_UNUSED(section);
       
  1000     Q_UNUSED(orientation);
       
  1001     Q_UNUSED(role);
       
  1002 
       
  1003     return QVariant();
       
  1004 }
       
  1005 
       
  1006 int NetGameSchemeModel::rowCount(const QModelIndex & parent) const
       
  1007 {
       
  1008     if (parent.isValid())
       
  1009         return 0;
       
  1010     else
       
  1011         return 1;
       
  1012 }
       
  1013 
       
  1014 int NetGameSchemeModel::columnCount(const QModelIndex & parent) const
       
  1015 {
       
  1016     if (parent.isValid())
       
  1017         return 0;
       
  1018     else
       
  1019         return defaultScheme.size();
       
  1020 }
       
  1021 
       
  1022 QVariant NetGameSchemeModel::data(const QModelIndex &index, int role) const
       
  1023 {
       
  1024     if (!index.isValid() || index.row() < 0
       
  1025             || index.row() > 1
       
  1026             || index.column() >= defaultScheme.size()
       
  1027             || (role != Qt::EditRole && role != Qt::DisplayRole)
       
  1028        )
       
  1029         return QVariant();
       
  1030 
       
  1031     return netScheme[index.column()];
       
  1032 }
       
  1033 
       
  1034 void NetGameSchemeModel::setNetSchemeConfig(QStringList cfg)
       
  1035 {
       
  1036     if(cfg.size() != netScheme.size())
       
  1037     {
       
  1038         qWarning("Incorrect scheme cfg size");
       
  1039         return;
       
  1040     }
       
  1041 
       
  1042     beginResetModel();
       
  1043 
       
  1044     cfg[cfg.size()-1] = cfg[cfg.size()-1].mid(1);
       
  1045 
       
  1046     for(int i = 0; i < cfg.size(); ++i)
       
  1047         netScheme[i] = QVariant(cfg[i]);
       
  1048 
       
  1049     endResetModel();
       
  1050 }