QTfrontend/namegen.cpp
author koda
Tue, 19 Apr 2011 00:43:39 +0200
changeset 5159 cb19cb531435
parent 5115 276410cc1178
child 5238 46ddaf14509d
permissions -rw-r--r--
merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
     1
/*
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2009 Martin Minarik <ttsmj@pokec.sk>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 3344
diff changeset
     4
 * Copyright (c) 2009-2011 Andrey Korotaev <unC0Rr@gmail.com>
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
     5
 *
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
     8
 * the Free Software Foundation; version 2 of the License
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
     9
 *
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    13
 * GNU General Public License for more details.
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    14
 *
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    18
 */
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    19
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    20
#include <QFile>
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    21
#include <QTextStream>
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    22
#include <QApplication>
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    23
#include <QStringList>
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    24
#include <QLineEdit>
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    25
#include "namegen.h"
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    26
#include "hwform.h"
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    27
#include "hwconsts.h"
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    28
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    29
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    30
HWNamegen::HWNamegen() :
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    31
    TypesAvliable(false)
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    32
{
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    33
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    34
    TypesLoad();
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    35
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    36
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    37
HWNamegen::~HWNamegen()
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    38
{
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    39
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    40
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    41
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    42
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
    43
void HWNamegen::TeamRandomName(HWTeam*& team, const int HedgehogNumber)
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    44
{
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
    45
    RandomNameByHat(team, HedgehogNumber);
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    46
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    47
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    48
void HWNamegen::TeamRandomNames(HWTeam*& team, const bool changeteamname)
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    49
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    50
    if ((TypesHatnames.size() > 0) && TypesAvliable){
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    51
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    52
        int kind = (rand()%(TypesHatnames.size()));
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    53
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    54
        if (changeteamname){
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    55
            if (TypesTeamnames[kind].size() > 0){
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    56
                team->TeamName = TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    57
            }
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
    58
            team->Grave = GetRandomGrave();
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
    59
            team->Fort = GetRandomFort();
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    60
            team->Voicepack = "Default";
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    61
        }
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    62
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
    63
        //give each hedgehog a random name:
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
    64
        //TODO: load the dictionary only once! (right now it's loaded once for each hedgehog)
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    65
        for(int i = 0; i < 8; i++)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    66
        {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    67
            if ((TypesHatnames[kind].size()) > 0){
3344
b18a166e6ca4 Frontend:
smxx
parents: 2948
diff changeset
    68
                team->Hedgehogs[i].Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    69
            }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    70
            RandomNameByHat(team,i);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    71
        }
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    72
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    73
    }
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    74
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    75
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    76
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    77
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
    78
void HWNamegen::RandomNameByHat(HWTeam*& team, const int HedgehogNumber)
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    79
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    80
    QStringList Dictionaries;
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
    81
    HatCfgLoad(team->Hedgehogs[HedgehogNumber].Hat,Dictionaries);
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    82
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    83
    QStringList Dictionary;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    84
    DictLoad(Dictionaries[rand()%(Dictionaries.size())],Dictionary);
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    85
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
    86
    team->Hedgehogs[HedgehogNumber].Name = Dictionary[rand()%(Dictionary.size())];
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    87
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    88
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    89
void HWNamegen::DictLoad(const QString filename, QStringList &list)
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    90
{
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    91
     list.clear();
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    92
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    93
     QFile file(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename));
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    94
     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    95
     {
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    96
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    97
         QTextStream in(&file);
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    98
         while (!in.atEnd()) {
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    99
             QString line = in.readLine();
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   100
             if(line != QString(""))
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   101
                 {list.append(line);}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   102
         }
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   103
     }
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   104
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   105
     if (list.size()==0)
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   106
         list.append(filename);
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   107
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   108
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   109
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   110
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   111
void HWNamegen::HatCfgLoad(const QString hatname, QStringList &list)
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   112
{
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   113
     list.clear();
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   114
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   115
     QFile file(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname));
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   116
     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   117
     {
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   118
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   119
         QTextStream in(&file);
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   120
         while (!in.atEnd()) {
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   121
             QString line = in.readLine();
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   122
             if(line != QString(""))
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   123
                 {list.append(line);}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   124
         }
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   125
     }
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   126
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   127
     if (list.size()==0)
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   128
         list.append(QString("generic"));
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   129
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   130
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   131
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   132
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   133
void HWNamegen::TypesLoad()
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   134
{
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   135
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   136
     QFile file(QString("%1/Names/types.ini").arg(datadir->absolutePath()));
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   137
     if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   138
         {TypesAvliable = FALSE; return;}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   139
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   140
     int counter = 0; //counter starts with 0 (teamnames mode)
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   141
     TypesTeamnames.append(QStringList());
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   142
     TypesHatnames.append(QStringList());
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   143
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   144
     QTextStream in(&file);
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   145
     while (!in.atEnd()) {
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   146
         QString line = in.readLine();
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   147
         if (line == QString("#####")){
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   148
             counter++; //toggle mode (teamnames || hats)
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   149
             if ((counter%2) == 0){
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   150
                 TypesTeamnames.append(QStringList());
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   151
                 TypesHatnames.append(QStringList());
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   152
             }
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   153
         } else if ((line == QString("*****")) || (line == QString("*END*"))){
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   154
             TypesAvliable = TRUE; return; // bye bye
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   155
         } else {
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   156
             if ((counter%2) == 0){ // even => teamnames mode
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   157
                 TypesTeamnames[(counter/2)].append(line);
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   158
             } else { // odd => hats mode
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   159
                 TypesHatnames[((counter-1)/2)].append(line);
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   160
             }
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   161
         }
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   162
//         Types.append(line);
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   163
     }
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   164
         TypesAvliable = TRUE;
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   165
     return;
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   166
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   167
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   168
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   169
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   170
QString HWNamegen::GetRandomGrave()
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   171
{
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   172
    QStringList Graves;
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   173
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   174
    //list all available Graves
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   175
    QDir tmpdir;
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   176
    tmpdir.cd(datadir->absolutePath());
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   177
    tmpdir.cd("Graphics/Graves");
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   178
    tmpdir.setFilter(QDir::Files);
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   179
    Graves.append(tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1"));
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   180
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   181
    if(Graves.size()==0)
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   182
    {
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   183
        //do some serious error handling
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   184
        return "Error";
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   185
    }
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   186
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   187
    //pick a random grave
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   188
    return Graves[rand()%(Graves.size())];
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   189
}
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   190
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   191
QString HWNamegen::GetRandomFort()
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   192
{
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   193
    QStringList Forts;
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   194
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   195
    //list all available Forts
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   196
    QDir tmpdir;
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   197
    tmpdir.cd(datadir->absolutePath());
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   198
    tmpdir.cd("Forts");
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   199
    tmpdir.setFilter(QDir::Files);
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   200
    Forts.append(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"));
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   201
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   202
    if(Forts.size()==0)
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   203
    {
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   204
        //do some serious error handling
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   205
        return "Error";
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   206
    }
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   207
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   208
    //pick a random fort
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   209
    return Forts[rand()%(Forts.size())];
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   210
}