author | nemo |
Mon, 12 Oct 2009 13:47:56 +0000 | |
changeset 2425 | a4af95e6382c |
parent 2192 | 4763a778c033 |
child 2948 | 3f21a9dc93d0 |
permissions | -rw-r--r-- |
1907 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2009 Martin Minarik <ttsmj@pokec.sk> |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QFile> |
|
20 |
#include <QTextStream> |
|
21 |
#include <QApplication> |
|
22 |
#include <QStringList> |
|
23 |
#include <QLineEdit> |
|
24 |
#include "namegen.h" |
|
25 |
#include "hwform.h" |
|
26 |
#include "hwconsts.h" |
|
27 |
||
28 |
||
29 |
HWNamegen::HWNamegen() : |
|
30 |
TypesAvliable(false) |
|
31 |
{ |
|
32 |
||
33 |
TypesLoad(); |
|
34 |
} |
|
35 |
||
36 |
HWNamegen::~HWNamegen() |
|
37 |
{ |
|
38 |
} |
|
39 |
||
40 |
||
41 |
||
42 |
void HWNamegen::TeamRandomName(HWTeam*& team, const int &i) |
|
43 |
{ |
|
44 |
RandomNameByHat(team,i); |
|
45 |
} |
|
46 |
||
47 |
void HWNamegen::TeamRandomNames(HWTeam*& team, const bool changeteamname) |
|
48 |
{ |
|
49 |
if ((TypesHatnames.size() > 0) && TypesAvliable){ |
|
50 |
||
51 |
int kind = (rand()%(TypesHatnames.size())); |
|
52 |
||
53 |
if (changeteamname){ |
|
54 |
if (TypesTeamnames[kind].size() > 0){ |
|
55 |
team->TeamName = TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())]; |
|
56 |
} |
|
57 |
team->Grave = "Simple"; // Todo: make it semi-random |
|
58 |
team->Fort = "Island"; // Todo: make it semi-random |
|
2192
4763a778c033
- Fix quickplay sound bug triggered by two faults: ttsmj's (passing voicepack with empty name in team config) and koda's (he changed fallback to default scheme condition)
unc0rr
parents:
1907
diff
changeset
|
59 |
team->Voicepack = "Default"; |
1907 | 60 |
} |
61 |
||
62 |
for(int i = 0; i < 8; i++) |
|
63 |
{ |
|
64 |
if ((TypesHatnames[kind].size()) > 0){ |
|
65 |
team->HHHat[i] = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())]; |
|
66 |
} |
|
67 |
RandomNameByHat(team,i); |
|
68 |
} |
|
69 |
||
70 |
} |
|
71 |
||
72 |
} |
|
73 |
||
74 |
||
75 |
void HWNamegen::RandomNameByHat(HWTeam*& team, const int &i) |
|
76 |
{ |
|
77 |
QStringList Dictionaries; |
|
78 |
HatCfgLoad(team->HHHat[i],Dictionaries); |
|
79 |
||
80 |
QStringList Dictionary; |
|
81 |
DictLoad(Dictionaries[rand()%(Dictionaries.size())],Dictionary); |
|
82 |
||
83 |
team->HHName[i] = Dictionary[rand()%(Dictionary.size())]; |
|
84 |
} |
|
85 |
||
86 |
void HWNamegen::DictLoad(const QString filename, QStringList &list) |
|
87 |
{ |
|
88 |
list.clear(); |
|
89 |
||
90 |
QFile file(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename)); |
|
91 |
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
|
92 |
{ |
|
93 |
||
94 |
QTextStream in(&file); |
|
95 |
while (!in.atEnd()) { |
|
96 |
QString line = in.readLine(); |
|
97 |
if(line != QString("")) |
|
98 |
{list.append(line);} |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
if (list.size()==0) |
|
103 |
list.append(filename); |
|
104 |
||
105 |
} |
|
106 |
||
107 |
||
108 |
void HWNamegen::HatCfgLoad(const QString hatname, QStringList &list) |
|
109 |
{ |
|
110 |
list.clear(); |
|
111 |
||
112 |
QFile file(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname)); |
|
113 |
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
|
114 |
{ |
|
115 |
||
116 |
QTextStream in(&file); |
|
117 |
while (!in.atEnd()) { |
|
118 |
QString line = in.readLine(); |
|
119 |
if(line != QString("")) |
|
120 |
{list.append(line);} |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
if (list.size()==0) |
|
125 |
list.append(QString("generic")); |
|
126 |
||
127 |
} |
|
128 |
||
129 |
||
130 |
void HWNamegen::TypesLoad() |
|
131 |
{ |
|
132 |
||
133 |
QFile file(QString("%1/Names/types.ini").arg(datadir->absolutePath())); |
|
134 |
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) |
|
135 |
{TypesAvliable = FALSE; return;} |
|
136 |
||
137 |
int counter = 0; //counter starts with 0 (teamnames mode) |
|
138 |
TypesTeamnames.append(QStringList()); |
|
139 |
TypesHatnames.append(QStringList()); |
|
140 |
||
141 |
QTextStream in(&file); |
|
142 |
while (!in.atEnd()) { |
|
143 |
QString line = in.readLine(); |
|
144 |
if (line == QString("#####")){ |
|
145 |
counter++; //toggle mode (teamnames || hats) |
|
146 |
if ((counter%2) == 0){ |
|
147 |
TypesTeamnames.append(QStringList()); |
|
148 |
TypesHatnames.append(QStringList()); |
|
149 |
} |
|
150 |
} else if ((line == QString("*****")) || (line == QString("*END*"))){ |
|
151 |
TypesAvliable = TRUE; return; // bye bye |
|
152 |
} else { |
|
153 |
if ((counter%2) == 0){ // even => teamnames mode |
|
154 |
TypesTeamnames[(counter/2)].append(line); |
|
155 |
} else { // odd => hats mode |
|
156 |
TypesHatnames[((counter-1)/2)].append(line); |
|
157 |
} |
|
158 |
} |
|
159 |
// Types.append(line); |
|
160 |
} |
|
161 |
TypesAvliable = TRUE; |
|
162 |
return; |
|
163 |
} |
|
164 |
||
165 |