QTfrontend/game.cpp
changeset 14982 575dbd7b5f43
parent 14975 f59b7f5cf6e8
child 14983 da7eb3414e02
equal deleted inserted replaced
14981:372b25c6bdee 14982:575dbd7b5f43
   138     commonConfig();
   138     commonConfig();
   139 }
   139 }
   140 
   140 
   141 void HWGame::SendQuickConfig()
   141 void HWGame::SendQuickConfig()
   142 {
   142 {
       
   143     /* Load and increase Quick Game experience level.
       
   144     Experience increases by 1 for each started game and maxes out
       
   145     at 20. Low experience levels will introduce a "beginner's bias" to make
       
   146     the first quick games easier and simpler. The max. possible difficulty
       
   147     increases progressively the longer you play.
       
   148     If experience is maxed out, the beginner's bias is gone and quick games
       
   149     are completely random. */
       
   150     int exp = config->quickGameExperience();
       
   151     if(exp < 20)
       
   152     {
       
   153        config->setQuickGameExperience(exp + 1);
       
   154     }
       
   155     qDebug("Starting quick game ...");
       
   156     qDebug("Quick Game experience level: %d", exp);
       
   157 
       
   158     // Init stuff
   143     QByteArray teamscfg;
   159     QByteArray teamscfg;
   144     QAbstractItemModel * themeModel = DataManager::instance().themeModel()->withoutHidden();
   160     QAbstractItemModel * themeModel = DataManager::instance().themeModel()->withoutHidden();
   145 
   161 
   146     HWProto::addStringToBuffer(teamscfg, "TL");
   162     HWProto::addStringToBuffer(teamscfg, "TL");
   147 
   163 
   148     // Random seed
   164     // Random seed
   149     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
   165     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
   150 
   166 
   151     int r, minhogs, maxhogs;
   167     int r, minhogs, maxhogs;
   152 
   168 
   153     // Random map
   169     // Random map type
   154     r = rand() % 10000;
   170     r = rand() % 10000;
   155     if(r < 3000) { // 30%
   171     if(r < 3000) { // 30%
       
   172         // Random
   156         r = 0;
   173         r = 0;
   157     } else if(r < 5250) { // 22.5%
   174     } else if(r < 5250) { // 22.5%
   158         r = 1;
   175         // Maze
       
   176         if(exp <= 3)
       
   177             r = 0;
       
   178         else
       
   179             r = 1;
   159     } else if(r < 7500) { // 22.5%
   180     } else if(r < 7500) { // 22.5%
   160         r = 2;
   181         // Perlin
       
   182         if(exp <= 7)
       
   183             r = 1;
       
   184         else
       
   185             r = 2;
   161     } else if(r < 8750) { // 12.5%
   186     } else if(r < 8750) { // 12.5%
       
   187         // Image map
   162         r = 3;
   188         r = 3;
   163     } else { // 12.5%
   189     } else { // 12.5%
       
   190         // Forts
   164         r = 4;
   191         r = 4;
   165     }
   192     }
   166     switch(r)
   193     switch(r)
   167     {
   194     {
   168         // Random
   195         // Random map
   169         default:
   196         default:
   170         case 0: {
   197         case 0: {
   171             r = rand() % 3;
   198             r = rand() % 3;
   172             if(r == 0)
   199             if(r == 0)
   173             {
   200             {
       
   201                 // small island
   174                 HWProto::addStringToBuffer(teamscfg, "e$template_filter 1");
   202                 HWProto::addStringToBuffer(teamscfg, "e$template_filter 1");
   175                 minhogs = 3;
   203                 minhogs = 3;
   176                 maxhogs = 4;
   204                 maxhogs = 4;
   177             }
   205             }
   178             else if(r == 1)
   206             else if(r == 1 || exp <= 6)
   179             {
   207             {
       
   208                 // medium island
   180                 HWProto::addStringToBuffer(teamscfg, "e$template_filter 2");
   209                 HWProto::addStringToBuffer(teamscfg, "e$template_filter 2");
   181                 minhogs = 4;
   210                 minhogs = 4;
   182                 maxhogs = 5;
   211                 maxhogs = 5;
   183             }
   212             }
   184             else
   213             else
   185             {
   214             {
       
   215                 // cave (locked at low experience because these maps can be huge)
   186                 HWProto::addStringToBuffer(teamscfg, "e$template_filter 4");
   216                 HWProto::addStringToBuffer(teamscfg, "e$template_filter 4");
   187                 minhogs = 4;
   217                 minhogs = 4;
   188                 maxhogs = 6;
   218                 maxhogs = 6;
   189             }
   219             }
   190             HWProto::addStringToBuffer(teamscfg, "e$feature_size "+QString::number(rand()%18+4));
   220             HWProto::addStringToBuffer(teamscfg, "e$feature_size "+QString::number(rand()%18+4));
   232     // Theme
   262     // Theme
   233     HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
   263     HWProto::addStringToBuffer(teamscfg, QString("etheme %1")
   234         .arg((themeModel->rowCount() > 0) ? themeModel->index(rand() % themeModel->rowCount(), 0).data(ThemeModel::ActualNameRole).toString() : "Nature"));
   264         .arg((themeModel->rowCount() > 0) ? themeModel->index(rand() % themeModel->rowCount(), 0).data(ThemeModel::ActualNameRole).toString() : "Nature"));
   235 
   265 
   236     int hogs = minhogs + rand() % (maxhogs-minhogs+1);
   266     int hogs = minhogs + rand() % (maxhogs-minhogs+1);
       
   267     // Cap hog count at low experience
       
   268     if((exp <= 8) && (hogs > 5))
       
   269         hogs = 5;
       
   270     else if((exp <= 5) && (hogs > 4))
       
   271         hogs = 4;
   237 
   272 
   238     // Teams
   273     // Teams
   239     // Player team
   274     // Player team
   240     HWTeam team1;
   275     HWTeam team1;
   241     team1.setDifficulty(0);
   276     team1.setDifficulty(0);
   244     HWNamegen::teamRandomEverything(team1);
   279     HWNamegen::teamRandomEverything(team1);
   245     team1.setVoicepack("Default_qau");
   280     team1.setVoicepack("Default_qau");
   246 
   281 
   247     // Computer team
   282     // Computer team
   248     HWTeam team2;
   283     HWTeam team2;
   249     // Random difficulty
   284     // Random difficulty.
   250     // TODO: Select difficulty based on previous player successes/failures.
   285     // Max. possible difficulty is capped at low experience levels.
   251     r = 1 + rand() % 5;
   286     if(exp >= 15) // very easy to very hard (full range)
       
   287         r = 5 - rand() % 5;
       
   288     else if(exp >= 9) // very easy to hard
       
   289         r = 5 - rand() % 4;
       
   290     else if(exp >= 6) // very easy to medium
       
   291         r = 5 - rand() % 3;
       
   292     else if(exp >= 2) // very easy to easy
       
   293         r = 5 - rand() % 2;
       
   294     else // very easy
       
   295         r = 5;
   252     team2.setDifficulty(r);
   296     team2.setDifficulty(r);
   253     team2.setColor(1);
   297     team2.setColor(1);
   254     team2.setNumHedgehogs(hogs);
   298     team2.setNumHedgehogs(hogs);
   255     // Make sure the team names are not equal
   299     // Make sure the team names are not equal
   256     do
   300     do
   257         HWNamegen::teamRandomEverything(team2);
   301         HWNamegen::teamRandomEverything(team2);
   258     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
   302     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
   259     team2.setVoicepack("Default_qau");
   303     team2.setVoicepack("Default_qau");
   260 
   304 
   261     // Random team play order
   305     // Team play order
   262     r = rand() % 2;
   306     r = rand() % 2;
   263     if(r == 0)
   307     if(r == 0 || exp <= 4) // player plays first
   264     {
   308     {
   265         HWProto::addStringListToBuffer(teamscfg, team1.teamGameConfig(100));
   309         HWProto::addStringListToBuffer(teamscfg, team1.teamGameConfig(100));
   266         HWProto::addStringListToBuffer(teamscfg, team2.teamGameConfig(100));
   310         HWProto::addStringListToBuffer(teamscfg, team2.teamGameConfig(100));
   267     }
   311     }
   268     else
   312     else // computer plays first
   269     {
   313     {
   270         HWProto::addStringListToBuffer(teamscfg, team2.teamGameConfig(100));
   314         HWProto::addStringListToBuffer(teamscfg, team2.teamGameConfig(100));
   271         HWProto::addStringListToBuffer(teamscfg, team1.teamGameConfig(100));
   315         HWProto::addStringListToBuffer(teamscfg, team1.teamGameConfig(100));
   272     }
   316     }
   273 
   317