--- a/QTfrontend/team.cpp Tue Feb 24 19:39:49 2009 +0000
+++ b/QTfrontend/team.cpp Tue Feb 24 21:47:17 2009 +0000
@@ -33,6 +33,8 @@
numHedgehogs(4),
m_isNetTeam(false)
{
+ TypesLoad();
+
TeamName = teamname;
OldTeamName = TeamName;
for (int i = 0; i < 8; i++)
@@ -54,6 +56,8 @@
numHedgehogs(4),
m_isNetTeam(true)
{
+ TypesLoad();
+
// net teams are configured from QStringList
if(strLst.size() != 22) throw HWTeamConstructException();
TeamName = strLst[0];
@@ -74,7 +78,11 @@
numHedgehogs(4),
m_isNetTeam(false)
{
+ TypesLoad();
+
num %= PREDEFTEAMS_COUNT;
+/*
+ //This is now generated by TeamRandomNames(TRUE);
TeamName = QApplication::translate("teams", pteams[num].TeamName);
HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
@@ -92,7 +100,15 @@
HHHat[5] = pteams[num].hh5hat;
HHHat[6] = pteams[num].hh6hat;
HHHat[7] = pteams[num].hh7hat;
-
+*/
+
+ TeamName = QString("Team");
+ for (int i = 0; i < 8; i++)
+ {
+ HHName[i].sprintf("hedgehog %d", i);
+ HHHat[i] = "NoHat";
+ }
+
Grave = pteams[num].Grave;
Fort = pteams[num].Fort;
for(int i = 0; i < BINDS_NUMBER; i++)
@@ -100,6 +116,8 @@
binds[i].action = cbinds[i].action;
binds[i].strbind = cbinds[i].strbind;
}
+
+ TeamRandomNames(TRUE);
}
@@ -276,6 +294,62 @@
return sl;
}
+void HWTeam::RandomNameByHat(const int &i)
+{
+
+
+
+ QStringList Dictionaries;
+ HatCfgLoad(HHHat[i],Dictionaries);
+
+
+/*
+
+"Dismissed",
+"Dragon",
+"Mindblower",
+*/
+
+ QStringList Dictionary;
+ DictLoad(Dictionaries[rand()%(Dictionaries.size())],Dictionary);
+
+
+ HHName[i] = Dictionary[rand()%(Dictionary.size())];
+
+}
+
+void HWTeam::TeamRandomName(const int &i)
+{
+
+ RandomNameByHat(i);
+
+
+}
+
+void HWTeam::TeamRandomNames(bool changeteamname)
+{
+
+ if ((TypesHatnames.size() > 0) && TypesAvliable){
+
+ int kind = (rand()%(TypesHatnames.size()));
+
+ if (changeteamname){
+ if (TypesTeamnames[kind].size() > 0){
+ TeamName = TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
+ }
+ }
+
+ for(int i = 0; i < 8; i++)
+ {
+ if ((TypesHatnames[kind].size()) > 0){
+ HHHat[i] = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
+ }
+ RandomNameByHat(i);
+ }
+
+ }
+}
+
bool HWTeam::isNetTeam() const
{
return m_isNetTeam;
@@ -289,3 +363,84 @@
bool HWTeam::operator<(const HWTeam& t1) const {
return TeamName<t1.TeamName; // if names are equal - test if it is net team
}
+
+void HWTeam::TypesLoad()
+{
+
+ QFile file(QString("%1/Names/types.ini").arg(datadir->absolutePath()));
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ TypesAvliable = FALSE;
+
+ int counter = 0; //counter starts with 0 (teamnames mode)
+ TypesTeamnames.append(QStringList());
+ TypesHatnames.append(QStringList());
+
+ QTextStream in(&file);
+ while (!in.atEnd()) {
+ QString line = in.readLine();
+ if (line == QString("#####")){
+ counter++; //toggle mode (teamnames || hats)
+ if ((counter%2) == 0){
+ TypesTeamnames.append(QStringList());
+ TypesHatnames.append(QStringList());
+ }
+ } else if ((line == QString("*****")) || (line == QString("*END*"))){
+ TypesAvliable = TRUE; return; // bye bye
+ } else {
+ if ((counter%2) == 0){ // even => teamnames mode
+ TypesTeamnames[(counter/2)].append(line);
+ } else { // odd => hats mode
+ TypesHatnames[((counter-1)/2)].append(line);
+ }
+ }
+// Types.append(line);
+ }
+ TypesAvliable = TRUE;
+ return;
+}
+
+
+void HWTeam::DictLoad(const QString filename, QStringList &list)
+{
+ list.clear();
+
+ QFile file(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename));
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+
+ QTextStream in(&file);
+ while (!in.atEnd()) {
+ QString line = in.readLine();
+ if(line != QString(""))
+ {list.append(line);}
+ }
+ }
+
+ if (list.size()==0)
+ list.append(filename);
+
+}
+
+
+void HWTeam::HatCfgLoad(const QString hatname, QStringList &list)
+{
+ list.clear();
+
+ QFile file(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname));
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+
+ QTextStream in(&file);
+ while (!in.atEnd()) {
+ QString line = in.readLine();
+ if(line != QString(""))
+ {list.append(line);}
+ }
+ }
+
+ if (list.size()==0)
+ list.append(QString("generic"));
+
+}
+
+