QTfrontend/util/namegen.cpp
author nemo
Mon, 10 Apr 2017 12:06:43 -0400
changeset 12218 bb5522e88ab2
parent 11893 618d99523933
child 12249 45c83c88ac4b
permissions -rw-r--r--
bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
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>
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     4
 * Copyright (c) 2004-2015 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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1907
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 <QStringList>
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    23
#include <QLineEdit>
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
    24
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    25
#include "hwform.h"
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6824
diff changeset
    26
#include "DataManager.h"
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    27
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
    28
#include "namegen.h"
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    29
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    30
HWNamegen::HWNamegen() {}
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    31
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    32
QList<QStringList> HWNamegen::TypesTeamnames;
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    33
QList<QStringList> HWNamegen::TypesHatnames;
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    34
bool HWNamegen::typesAvailable = false;
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
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5252
diff changeset
    37
void HWNamegen::teamRandomNames(HWTeam & team, const bool changeteamname)
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    38
{
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    39
    // load types if not already loaded
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    40
    if (!typesAvailable)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    41
        if (!loadTypes())
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    42
            return; // abort if loading failed
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    43
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    44
    // abort if there are no hat types
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    45
    if (TypesHatnames.size() <= 0)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    46
        return;
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    47
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    48
    // the hat will influence which names the hogs get
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    49
    int kind = (rand()%(TypesHatnames.size()));
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    50
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    51
    // pick team name based on hat
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    52
    if (changeteamname)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    53
    {
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    54
        if (TypesTeamnames[kind].size() > 0)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    55
            team.setName(TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())]);
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    56
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    57
        team.setGrave(getRandomGrave());
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    58
        team.setFort(getRandomFort());
11893
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    59
        team.setFlag(getRandomFlag());
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
    60
        team.setVoicepack(getRandomVoice());
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    61
    }
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    62
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    63
    QStringList dicts;
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    64
    QStringList dict;
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    65
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    66
    if ((TypesHatnames[kind].size()) <= 0)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    67
    {
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    68
        dicts = dictsForHat(team.hedgehog(0).Hat);
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    69
        dict  = dictContents(dicts[rand()%(dicts.size())]);
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    70
    }
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    71
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    72
    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    73
    {
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    74
        if ((TypesHatnames[kind].size()) > 0)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    75
        {
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    76
            HWHog hh = team.hedgehog(i);
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    77
            hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    78
            team.setHedgehog(i,hh);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    79
        }
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    80
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    81
        // there is a chance that this hog has the same hat as the previous one
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    82
        // let's reuse the hat-specific dict in this case
6824
617a861b7750 i didn't even know it was possible (spotted by adam4813)
koda
parents: 6700
diff changeset
    83
        if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    84
        {
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    85
            dicts = dictsForHat(team.hedgehog(i).Hat);
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    86
            dict  = dictContents(dicts[rand()%(dicts.size())]);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    87
        }
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    88
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    89
        // give each hedgehog a random name
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    90
        HWNamegen::teamRandomName(team,i,dict);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2192
diff changeset
    91
    }
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    92
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    93
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    94
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    95
void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    96
{
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    97
    QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
    98
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    99
    QStringList dict = dictContents(dicts[rand()%(dicts.size())]);
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   100
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   101
    teamRandomName(team, HedgehogNumber, dict);
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   102
}
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   103
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   104
void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber, const QStringList & dict)
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   105
{
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   106
    QStringList namesDict = dict;
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   107
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   108
    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   109
    {
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   110
        namesDict.removeOne(team.hedgehog(i).Name);
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   111
    }
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   112
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   113
    // if our dict doesn't have any new names we'll have to use duplicates
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   114
    if (namesDict.size() < 1)
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   115
        namesDict = dict;
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   116
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5252
diff changeset
   117
    HWHog hh = team.hedgehog(HedgehogNumber);
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   118
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   119
    hh.Name = namesDict[rand()%(namesDict.size())];
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   120
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5252
diff changeset
   121
    team.setHedgehog(HedgehogNumber, hh);
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   122
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   123
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   124
QStringList HWNamegen::dictContents(const QString filename)
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   125
{
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   126
    QStringList list;
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   127
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   128
    // find .txt to load the names from
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   129
    QFile file(QString("physfs://Names/%1.txt").arg(filename));
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   130
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   131
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5115
diff changeset
   132
    {
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   133
        QTextStream in(&file);
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   134
        QString line;
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   135
        do
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   136
        {
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   137
            line = in.readLine();
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   138
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   139
            if(!line.isEmpty())
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   140
                list.append(line);
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   141
        } while (!line.isNull());
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5115
diff changeset
   142
    }
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   143
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   144
    if (list.size() == 0)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   145
        list.append(filename);
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   146
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   147
    return list;
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   148
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   149
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   150
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   151
QStringList HWNamegen::dictsForHat(const QString hatname)
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   152
{
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   153
    QStringList list;
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   154
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   155
    // find .cfg to load the dicts from
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   156
    QFile file(QString("physfs://Names/%1.cfg").arg(hatname));
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   157
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   158
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5115
diff changeset
   159
    {
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   160
        QTextStream in(&file);
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   161
        QString line;
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   162
        do
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   163
        {
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   164
            line = in.readLine();
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   165
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   166
            if(!line.isEmpty())
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   167
                list.append(line);
8110
9f5fe3fc9d16 Use alternative way of checking for file end. Also refactor this code a bit.
unc0rr
parents: 8049
diff changeset
   168
        } while (!line.isNull());
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5115
diff changeset
   169
    }
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   170
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   171
    if (list.size() == 0)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   172
        list.append(QString("generic"));
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   173
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   174
    return list;
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   175
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   176
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   177
// loades types from ini files. returns true on success.
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   178
bool HWNamegen::loadTypes()
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   179
{
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   180
    typesAvailable = false;
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   181
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   182
    // find .ini to load the names from
8049
133e22b5c410 Get rid of DataManager::findFileForRead
unc0rr
parents: 6952
diff changeset
   183
    QFile * file = new QFile(QString("physfs://Names/types.ini"));
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   184
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   185
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   186
    if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   187
    {
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   188
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   189
        int counter = 0; //counter starts with 0 (teamnames mode)
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   190
        TypesTeamnames.append(QStringList());
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   191
        TypesHatnames.append(QStringList());
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   192
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   193
        QTextStream in(file);
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   194
        while (!in.atEnd())
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   195
        {
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   196
            QString line = in.readLine();
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   197
            if (line == QString("#####"))
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   198
            {
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   199
                counter++; //toggle mode (teamnames || hats)
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   200
                if ((counter%2) == 0)
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   201
                {
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   202
                    TypesTeamnames.append(QStringList());
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   203
                    TypesHatnames.append(QStringList());
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   204
                }
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5115
diff changeset
   205
            }
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   206
            else if ((line == QString("*****")) || (line == QString("*END*")))
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   207
            {
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   208
                typesAvailable = true;
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   209
                return true; // bye bye
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   210
            }
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   211
            else
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   212
            {
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   213
                if ((counter%2) == 0)
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   214
                {
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   215
                    // even => teamnames mode
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   216
                    TypesTeamnames[(counter/2)].append(line);
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   217
                }
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   218
                else
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   219
                {
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   220
                    // odd => hats mode
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   221
                    TypesHatnames[((counter-1)/2)].append(line);
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   222
                }
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5115
diff changeset
   223
            }
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5115
diff changeset
   224
        }
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   225
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   226
        typesAvailable = true;
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5115
diff changeset
   227
    }
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
   228
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   229
    // this QFile isn't needed any further
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   230
    delete file;
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   231
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   232
    return typesAvailable;
1907
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   233
}
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   234
a104432e8301 Random team generator rework by ttsmj
unc0rr
parents:
diff changeset
   235
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   236
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5252
diff changeset
   237
QString HWNamegen::getRandomGrave()
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   238
{
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   239
    QStringList Graves;
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   240
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   241
    //list all available Graves
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6824
diff changeset
   242
    Graves.append(DataManager::instance().entryList(
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   243
                      "Graphics/Graves",
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   244
                      QDir::Files,
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   245
                      QStringList("*.png")
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   246
                  ).replaceInStrings(QRegExp("\\.png$"), "")
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   247
                 );
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   248
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   249
    if(Graves.size()==0)
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   250
    {
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   251
        // TODO do some serious error handling
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   252
        return "Error";
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   253
    }
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   254
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   255
    //pick a random grave
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   256
    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
   257
}
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   258
11893
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   259
QString HWNamegen::getRandomFlag()
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   260
{
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   261
    QStringList Flags;
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   262
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   263
    //list all available flags
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   264
    Flags.append(DataManager::instance().entryList(
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   265
                      "Graphics/Flags",
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   266
                      QDir::Files,
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   267
                      QStringList("*.png")
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   268
                  ).replaceInStrings(QRegExp("\\.png$"), "")
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   269
                 );
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   270
    //remove internal flags
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   271
    Flags.removeAll("cpu");
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   272
    Flags.removeAll("cpu_plain");
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   273
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   274
    if(Flags.size()==0)
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   275
    {
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   276
        // TODO do some serious error handling
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   277
        return "Error";
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   278
    }
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   279
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   280
    //pick a random flag
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   281
    return Flags[rand()%(Flags.size())];
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   282
}
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   283
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 5252
diff changeset
   284
QString HWNamegen::getRandomFort()
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   285
{
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   286
    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
   287
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   288
    //list all available Forts
6930
d187ea93fc4f renaming HWDataManager -> DataManager
sheepluva
parents: 6824
diff changeset
   289
    Forts.append(DataManager::instance().entryList(
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   290
                     "Forts",
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   291
                     QDir::Files,
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   292
                     QStringList("*L.png")
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6212
diff changeset
   293
                 ).replaceInStrings(QRegExp("L\\.png$"), "")
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   294
                );
5114
a05081bc2769 Improved random name generation (now a random fort and random grave is choosen
Jonathan@Jonathan-PC.fritz.box
parents: 4976
diff changeset
   295
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   296
    if(Forts.size()==0)
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   297
    {
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6060
diff changeset
   298
        // TODO do some serious error handling
5115
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   299
        return "Error";
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   300
    }
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   301
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   302
    //pick a random fort
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   303
    return Forts[rand()%(Forts.size())];
276410cc1178 fix indentation and missing newline at end of file
sheepluva
parents: 5114
diff changeset
   304
}
11893
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   305
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   306
QString HWNamegen::getRandomVoice()
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   307
{
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   308
    QStringList Voices;
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   309
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   310
    //list all available voices 
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   311
    Voices.append(DataManager::instance().entryList(
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   312
                     "Sounds/voices",
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   313
                     QDir::Dirs | QDir::NoDotAndDotDot,
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   314
                     QStringList("*")));
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   315
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   316
    if(Voices.size()==0)
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   317
    {
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   318
        // TODO do some serious error handling
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   319
        return "Error";
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   320
    }
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   321
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   322
    //pick a random voice
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   323
    return Voices[rand()%(Voices.size())];
618d99523933 Set random flags and voice in random teams
Wuzzy <almikes@aol.com>
parents: 11046
diff changeset
   324
}