QTfrontend/model/gameSchemeModel.cpp
branchios-develop
changeset 13413 ba39a1d396c0
parent 13272 5984e8c6cbeb
child 13554 a5a8488e2485
equal deleted inserted replaced
13411:6e8b807bda4b 13413:ba39a1d396c0
       
     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 <QSettings>
       
    23 #include <QTextStream>
       
    24 #include <QHash>
       
    25 
       
    26 #include "gameSchemeModel.h"
       
    27 #include "hwconsts.h"
       
    28 
       
    29 QList<QVariant> defaultScheme = QList<QVariant>()
       
    30                                 << QVariant("Default")     // name           0
       
    31                                 << QVariant(false)         // switchhog      1
       
    32                                 << QVariant(false)         // team divide    2
       
    33                                 << QVariant(false)         // solid land     3
       
    34                                 << QVariant(false)         // border         4
       
    35                                 << QVariant(false)         // low gravity    5
       
    36                                 << QVariant(false)         // laser sight    6
       
    37                                 << QVariant(false)         // invulnerable   7
       
    38                                 << QVariant(false)         // reset health   8
       
    39                                 << QVariant(false)         // vampiric       9
       
    40                                 << QVariant(false)         // karma          10
       
    41                                 << QVariant(false)         // artillery      11
       
    42                                 << QVariant(true)          // random order   12
       
    43                                 << QVariant(false)         // king           13
       
    44                                 << QVariant(false)         // place hog      14
       
    45                                 << QVariant(false)         // shared ammo    15
       
    46                                 << QVariant(false)         // disable girders 16
       
    47                                 << QVariant(false)         // disable land objects 17
       
    48                                 << QVariant(false)         // AI survival    18
       
    49                                 << QVariant(false)         // inf. attack    19
       
    50                                 << QVariant(false)         // reset weps     20
       
    51                                 << QVariant(false)         // per hog ammo   21
       
    52                                 << QVariant(false)         // no wind        22
       
    53                                 << QVariant(false)         // more wind      23
       
    54                                 << QVariant(false)         // tag team       24
       
    55                                 << QVariant(false)         // bottom border  25
       
    56                                 << QVariant(100)           // damage modfier 26
       
    57                                 << QVariant(45)            // turn time      27
       
    58                                 << QVariant(100)           // init health    28
       
    59                                 << QVariant(15)            // sudden death   29
       
    60                                 << QVariant(5)             // case prob      30
       
    61                                 << QVariant(3)             // mines time     31
       
    62                                 << QVariant(4)             // mines number   32
       
    63                                 << QVariant(0)             // mine dud pct   33
       
    64                                 << QVariant(2)             // explosives     34
       
    65                                 << QVariant(0)             // air mines      35
       
    66                                 << QVariant(35)            // health case pct 36
       
    67                                 << QVariant(25)            // health case amt 37
       
    68                                 << QVariant(47)            // water rise amt 38
       
    69                                 << QVariant(5)             // health dec amt 39
       
    70                                 << QVariant(100)           // rope modfier   40
       
    71                                 << QVariant(100)           // get away time  41
       
    72                                 << QVariant(0)             // world edge     42
       
    73                                 << QVariant()              // scriptparam    43
       
    74                                 ;
       
    75 
       
    76 GameSchemeModel::GameSchemeModel(QObject* parent, const QString & directory) :
       
    77     QAbstractTableModel(parent)
       
    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               << "switchhog"           //  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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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)         // switchhog      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         QSettings legacyFileConfig(cfgdir->absolutePath() + "/schemes.ini", QSettings::IniFormat);
       
   747         int size = legacyFileConfig.beginReadArray("schemes");
       
   748         int imported = 0;
       
   749         for (int i = 0; i < size; ++i)
       
   750         {
       
   751             legacyFileConfig.setArrayIndex(i);
       
   752 
       
   753             QString schemeName = legacyFileConfig.value(spNames[0]).toString();
       
   754             if (!schemeName.isNull() && !predefSchemesNames.contains(schemeName))
       
   755             {
       
   756                 QList<QVariant> scheme;
       
   757                 QFile file(directory + "/" + schemeName + ".hwg");
       
   758 
       
   759                 // Add keys to scheme info and create file
       
   760                 if (file.open(QIODevice::WriteOnly)) {
       
   761                     QTextStream stream(&file);
       
   762 
       
   763                     for (int k = 0; k < spNames.size(); ++k) {
       
   764                         scheme << legacyFileConfig.value(spNames[k], defaultScheme[k]);
       
   765 
       
   766                         // File handling
       
   767                         // We skip the name key (k==0), it is not stored redundantly in file.
       
   768                         // The file name is used for that already.
       
   769                         if(k != 0) {
       
   770                             // The file is just a list of key=value pairs
       
   771                             stream << spNames[k] << "=" << legacyFileConfig.value(spNames[k], defaultScheme[k]).toString();
       
   772                             stream << endl;
       
   773                         }
       
   774                     }
       
   775                     file.close();
       
   776                 }
       
   777                 imported++;
       
   778 
       
   779                 schemes.append(scheme);
       
   780             }
       
   781         }
       
   782         qDebug("%d game scheme(s) imported.", imported);
       
   783         legacyFileConfig.endArray();
       
   784     } else {
       
   785         QStringList scheme_dir = QDir(directory).entryList(QDir::Files);
       
   786 
       
   787         for(int i = 0; i < scheme_dir.size(); i++)
       
   788         {
       
   789             QList<QVariant> scheme;
       
   790             QFile file(directory + "/" + scheme_dir[i]);
       
   791 
       
   792             // Chop off file name suffix
       
   793             QString schemeName = scheme_dir[i];
       
   794             if (schemeName.endsWith(".hwg", Qt::CaseInsensitive)) {
       
   795                 schemeName.chop(4);
       
   796             }
       
   797             // Parse game scheme file
       
   798             if (file.open(QIODevice::ReadOnly)) {
       
   799                 QTextStream stream(&file);
       
   800                 QString line, key, value;
       
   801                 QHash<QString, QString> fileKeyValues;
       
   802                 do {
       
   803                     // Read line and get key and value
       
   804                     line = stream.readLine();
       
   805                     key = line.section(QChar('='), 0, 0);
       
   806                     value = line.section(QChar('='), 1);
       
   807                     if(!key.isNull() && !value.isNull()) {
       
   808                         fileKeyValues[key] = value;
       
   809                     }
       
   810                 } while (!line.isNull());
       
   811 
       
   812                 // Add scheme name manually
       
   813                 scheme << schemeName;
       
   814                 // Add other keys from the QHash.
       
   815                 for (int k = 1; k < spNames.size(); ++k) {
       
   816                     key = spNames[k];
       
   817                     if (fileKeyValues.contains(key)) {
       
   818                         scheme << fileKeyValues.value(key);
       
   819                     } else {
       
   820                         // Use default value in case the key is not set
       
   821                         scheme << defaultScheme[k];
       
   822                     }
       
   823                 }
       
   824                 schemes.append(scheme);
       
   825 
       
   826                 file.close();
       
   827             }
       
   828         }
       
   829     }
       
   830 }
       
   831 
       
   832 QVariant GameSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
       
   833 {
       
   834     Q_UNUSED(section);
       
   835     Q_UNUSED(orientation);
       
   836     Q_UNUSED(role);
       
   837 
       
   838     return QVariant();
       
   839 }
       
   840 
       
   841 int GameSchemeModel::rowCount(const QModelIndex &parent) const
       
   842 {
       
   843     if (parent.isValid())
       
   844         return 0;
       
   845     else
       
   846         return schemes.size();
       
   847 }
       
   848 
       
   849 int GameSchemeModel::columnCount(const QModelIndex & parent) const
       
   850 {
       
   851     if (parent.isValid())
       
   852         return 0;
       
   853     else
       
   854         return defaultScheme.size();
       
   855 }
       
   856 
       
   857 bool GameSchemeModel::hasScheme(QString name)
       
   858 {
       
   859     for(int i=0; i<schemes.size(); i++)
       
   860     {
       
   861         if(schemes[i][0] == name)
       
   862         {
       
   863             return true;
       
   864         }
       
   865     }
       
   866     return false;
       
   867 }
       
   868 
       
   869 Qt::ItemFlags GameSchemeModel::flags(const QModelIndex & index) const
       
   870 {
       
   871     Q_UNUSED(index);
       
   872 
       
   873     return
       
   874         Qt::ItemIsEnabled
       
   875         | Qt::ItemIsSelectable
       
   876         | Qt::ItemIsEditable;
       
   877 }
       
   878 
       
   879 bool GameSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role)
       
   880 {
       
   881     if (!index.isValid() || index.row() < numberOfDefaultSchemes
       
   882             || index.row() >= schemes.size()
       
   883             || index.column() >= defaultScheme.size()
       
   884             || role != Qt::EditRole)
       
   885         return false;
       
   886 
       
   887     schemes[index.row()][index.column()] = value;
       
   888 
       
   889     emit dataChanged(index, index);
       
   890     return true;
       
   891 }
       
   892 
       
   893 bool GameSchemeModel::insertRows(int row, int count, const QModelIndex & parent)
       
   894 {
       
   895     Q_UNUSED(count);
       
   896 
       
   897     beginInsertRows(parent, schemes.size(), schemes.size());
       
   898 
       
   899     if (row == -1)
       
   900     {
       
   901         QList<QVariant> newScheme = defaultScheme;
       
   902 
       
   903         QString newName = tr("New");
       
   904         if(hasScheme(newName))
       
   905         {
       
   906             //name already used -> look for an appropriate name:
       
   907             int i=2;
       
   908             while(hasScheme(newName = tr("New (%1)").arg(i++))) ;
       
   909         }
       
   910         newScheme[0] = QVariant(newName);
       
   911         schemes.insert(schemes.size(), newScheme);
       
   912     }
       
   913     else
       
   914     {
       
   915         QList<QVariant> newScheme = schemes[row];
       
   916         QString oldName = newScheme[0].toString();
       
   917         QString newName = tr("Copy of %1").arg(oldName);
       
   918         if(hasScheme(newName))
       
   919         {
       
   920             //name already used -> look for an appropriate name:
       
   921             int i=2;
       
   922             while(hasScheme(newName = tr("Copy of %1 (%2)").arg(oldName).arg(i++)));
       
   923         }
       
   924         newScheme[0] = QVariant(newName);
       
   925         schemes.insert(schemes.size(), newScheme);
       
   926     }
       
   927 
       
   928     endInsertRows();
       
   929 
       
   930     return true;
       
   931 }
       
   932 
       
   933 bool GameSchemeModel::removeRows(int row, int count, const QModelIndex & parent)
       
   934 {
       
   935     if(count != 1
       
   936             || row < numberOfDefaultSchemes
       
   937             || row >= schemes.size())
       
   938         return false;
       
   939 
       
   940     beginRemoveRows(parent, row, row);
       
   941 
       
   942     QList<QVariant> scheme = schemes[row];
       
   943     int j = spNames.indexOf("name");
       
   944     QFile(cfgdir->absolutePath() + "/Schemes/Game/" + scheme[j].toString() + ".hwg").remove();
       
   945     schemes.removeAt(row);
       
   946 
       
   947     endRemoveRows();
       
   948 
       
   949     return true;
       
   950 }
       
   951 
       
   952 QVariant GameSchemeModel::data(const QModelIndex &index, int role) const
       
   953 {
       
   954     if (!index.isValid() || index.row() < 0
       
   955             || index.row() >= schemes.size()
       
   956             || index.column() >= defaultScheme.size()
       
   957             || (role != Qt::EditRole && role != Qt::DisplayRole)
       
   958        )
       
   959         return QVariant();
       
   960 
       
   961     return schemes[index.row()][index.column()];
       
   962 }
       
   963 
       
   964 void GameSchemeModel::Save()
       
   965 {
       
   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 }
       
   988 
       
   989 
       
   990 NetGameSchemeModel::NetGameSchemeModel(QObject * parent) :
       
   991     QAbstractTableModel(parent)
       
   992 {
       
   993     netScheme = defaultScheme;
       
   994 }
       
   995 
       
   996 QVariant NetGameSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
       
   997 {
       
   998     Q_UNUSED(section);
       
   999     Q_UNUSED(orientation);
       
  1000     Q_UNUSED(role);
       
  1001 
       
  1002     return QVariant();
       
  1003 }
       
  1004 
       
  1005 int NetGameSchemeModel::rowCount(const QModelIndex & parent) const
       
  1006 {
       
  1007     if (parent.isValid())
       
  1008         return 0;
       
  1009     else
       
  1010         return 1;
       
  1011 }
       
  1012 
       
  1013 int NetGameSchemeModel::columnCount(const QModelIndex & parent) const
       
  1014 {
       
  1015     if (parent.isValid())
       
  1016         return 0;
       
  1017     else
       
  1018         return defaultScheme.size();
       
  1019 }
       
  1020 
       
  1021 QVariant NetGameSchemeModel::data(const QModelIndex &index, int role) const
       
  1022 {
       
  1023     if (!index.isValid() || index.row() < 0
       
  1024             || index.row() > 1
       
  1025             || index.column() >= defaultScheme.size()
       
  1026             || (role != Qt::EditRole && role != Qt::DisplayRole)
       
  1027        )
       
  1028         return QVariant();
       
  1029 
       
  1030     return netScheme[index.column()];
       
  1031 }
       
  1032 
       
  1033 void NetGameSchemeModel::setNetSchemeConfig(QStringList cfg)
       
  1034 {
       
  1035     if(cfg.size() != netScheme.size())
       
  1036     {
       
  1037         qWarning("Incorrect scheme cfg size");
       
  1038         return;
       
  1039     }
       
  1040 
       
  1041     beginResetModel();
       
  1042 
       
  1043     cfg[cfg.size()-1] = cfg[cfg.size()-1].mid(1);
       
  1044 
       
  1045     for(int i = 0; i < cfg.size(); ++i)
       
  1046         netScheme[i] = QVariant(cfg[i]);
       
  1047 
       
  1048     endResetModel();
       
  1049 }