QTfrontend/team.cpp
author unc0rr
Tue, 24 Feb 2009 21:47:17 +0000
changeset 1840 4747f0232b88
parent 1683 af34da5726aa
child 1907 a104432e8301
permissions -rw-r--r--
ttsmj2's random teams patch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 607
diff changeset
     2
 * Hedgewars, a free turn based strategy game
1656
209cf0e2fc36 Finish voicepacks support in engine (not tested though)
unc0rr
parents: 1655
diff changeset
     3
 * Copyright (c) 2005-2007, 2009 Andrey Korotaev <unC0Rr@gmail.com>
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     4
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     8
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    12
 * GNU General Public License for more details.
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    13
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    15
 * along with this program; if not, write to the Free Software
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    17
 */
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    18
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    19
#include <QFile>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    20
#include <QTextStream>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    21
#include <QApplication>
471
e1eb64ba5e9c Small cleanup, faster compilation as a result
unc0rr
parents: 468
diff changeset
    22
#include <QStringList>
e1eb64ba5e9c Small cleanup, faster compilation as a result
unc0rr
parents: 468
diff changeset
    23
#include <QLineEdit>
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    24
#include "team.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    25
#include "hwform.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    26
#include "predefteams.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    27
#include "pages.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    28
#include "hwconsts.h"
1240
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
    29
#include "hats.h"
314
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    30
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    31
HWTeam::HWTeam(const QString & teamname) :
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    32
	difficulty(0),
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    33
	numHedgehogs(4),
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    34
	m_isNetTeam(false)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    35
{
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
    36
	TypesLoad();
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
    37
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    38
	TeamName = teamname;
245
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
    39
	OldTeamName = TeamName;
1240
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
    40
	for (int i = 0; i < 8; i++)
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
    41
	{
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
    42
		HHName[i].sprintf("hedgehog %d", i);
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
    43
		HHHat[i] = "NoHat";
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
    44
	}
1538
8bc56dd2e997 Set default fort to 'Plane' and default grave to 'Statue'
unc0rr
parents: 1325
diff changeset
    45
	Grave = "Statue";
8bc56dd2e997 Set default fort to 'Plane' and default grave to 'Statue'
unc0rr
parents: 1325
diff changeset
    46
	Fort = "Plane";
1659
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
    47
	Voicepack = "Default";
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    48
	for(int i = 0; i < BINDS_NUMBER; i++)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    49
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    50
		binds[i].action = cbinds[i].action;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    51
		binds[i].strbind = cbinds[i].strbind;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    52
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    53
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    54
353
5ec611d702a0 initial hedgehogs num fixed
displacer
parents: 352
diff changeset
    55
HWTeam::HWTeam(const QStringList& strLst) :
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    56
  numHedgehogs(4),
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    57
  m_isNetTeam(true)
314
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    58
{
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
    59
	TypesLoad();
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
    60
1245
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1244
diff changeset
    61
	// net teams are configured from QStringList
1683
af34da5726aa Show team owner in tooltip
unc0rr
parents: 1662
diff changeset
    62
	if(strLst.size() != 22) throw HWTeamConstructException();
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    63
	TeamName = strLst[0];
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    64
	Grave = strLst[1];
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    65
	Fort = strLst[2];
1662
cefb9d0f816f Support voicepack info in net server
unc0rr
parents: 1659
diff changeset
    66
	Voicepack = strLst[3];
1683
af34da5726aa Show team owner in tooltip
unc0rr
parents: 1662
diff changeset
    67
	Owner = strLst[4];
af34da5726aa Show team owner in tooltip
unc0rr
parents: 1662
diff changeset
    68
	difficulty = strLst[5].toUInt();
1245
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1244
diff changeset
    69
	for(int i = 0; i < 8; i++)
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1244
diff changeset
    70
	{
1683
af34da5726aa Show team owner in tooltip
unc0rr
parents: 1662
diff changeset
    71
		HHName[i]=strLst[i * 2 + 6];
af34da5726aa Show team owner in tooltip
unc0rr
parents: 1662
diff changeset
    72
		HHHat[i]=strLst[i * 2 + 7];
1245
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1244
diff changeset
    73
	}
314
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    74
}
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    75
231
c77b16e48273 bots power icons added
displacer
parents: 184
diff changeset
    76
HWTeam::HWTeam(quint8 num) :
339
7535ab6c3820 Run game message added, team and config info provided for net game
displacer
parents: 336
diff changeset
    77
  difficulty(0),
353
5ec611d702a0 initial hedgehogs num fixed
displacer
parents: 352
diff changeset
    78
  numHedgehogs(4),
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
    79
  m_isNetTeam(false)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    80
{
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
    81
	TypesLoad();
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
    82
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    83
	num %= PREDEFTEAMS_COUNT;
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
    84
/*
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
    85
	//This is now generated by TeamRandomNames(TRUE);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    86
	TeamName = QApplication::translate("teams", pteams[num].TeamName);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    87
	HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    88
	HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    89
	HHName[2] = QApplication::translate("teams", pteams[num].hh2name);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    90
	HHName[3] = QApplication::translate("teams", pteams[num].hh3name);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    91
	HHName[4] = QApplication::translate("teams", pteams[num].hh4name);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    92
	HHName[5] = QApplication::translate("teams", pteams[num].hh5name);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    93
	HHName[6] = QApplication::translate("teams", pteams[num].hh6name);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    94
	HHName[7] = QApplication::translate("teams", pteams[num].hh7name);
1293
5943efa67299 Predefined team can have customized hat
unc0rr
parents: 1287
diff changeset
    95
	HHHat[0] = pteams[num].hh0hat;
5943efa67299 Predefined team can have customized hat
unc0rr
parents: 1287
diff changeset
    96
	HHHat[1] = pteams[num].hh1hat;
5943efa67299 Predefined team can have customized hat
unc0rr
parents: 1287
diff changeset
    97
	HHHat[2] = pteams[num].hh2hat;
5943efa67299 Predefined team can have customized hat
unc0rr
parents: 1287
diff changeset
    98
	HHHat[3] = pteams[num].hh3hat;
5943efa67299 Predefined team can have customized hat
unc0rr
parents: 1287
diff changeset
    99
	HHHat[4] = pteams[num].hh4hat;
5943efa67299 Predefined team can have customized hat
unc0rr
parents: 1287
diff changeset
   100
	HHHat[5] = pteams[num].hh5hat;
5943efa67299 Predefined team can have customized hat
unc0rr
parents: 1287
diff changeset
   101
	HHHat[6] = pteams[num].hh6hat;
5943efa67299 Predefined team can have customized hat
unc0rr
parents: 1287
diff changeset
   102
	HHHat[7] = pteams[num].hh7hat;
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   103
*/	
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   104
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   105
	TeamName = QString("Team");
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   106
	for (int i = 0; i < 8; i++)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   107
	{
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   108
		HHName[i].sprintf("hedgehog %d", i);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   109
		HHHat[i] = "NoHat";
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   110
	}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   111
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   112
	Grave = pteams[num].Grave;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   113
	Fort = pteams[num].Fort;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   114
	for(int i = 0; i < BINDS_NUMBER; i++)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   115
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   116
		binds[i].action = cbinds[i].action;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   117
		binds[i].strbind = cbinds[i].strbind;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   118
	}
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   119
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   120
	TeamRandomNames(TRUE);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   121
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   122
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   123
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   124
bool HWTeam::LoadFromFile()
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   125
{
353
5ec611d702a0 initial hedgehogs num fixed
displacer
parents: 352
diff changeset
   126
	numHedgehogs=4;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   127
	QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   128
	if (!cfgfile.open(QIODevice::ReadOnly)) return false;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   129
	QTextStream stream(&cfgfile);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   130
	stream.setCodec("UTF-8");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   131
	QString str;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   132
	QString action;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   133
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   134
	while (!stream.atEnd())
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   135
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   136
		str = stream.readLine();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   137
		if (str.startsWith(";")) continue;
245
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
   138
		/*if (str.startsWith("name team "))
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   139
		{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   140
			str.remove(0, 10);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   141
			TeamName = str;
245
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
   142
		} else*/
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   143
		if (str.startsWith("name hh"))
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   144
		{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   145
			str.remove(0, 7);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   146
			long i = str.left(1).toLong();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   147
			if ((i < 0) || (i > 7)) continue;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   148
			str.remove(0, 2);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   149
			HHName[i] = str;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   150
		} else
1240
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   151
		if (str.startsWith("hat"))
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   152
		{
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   153
			str.remove(0, 3);
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   154
			long i = str.left(1).toLong();
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   155
			if ((i < 0) || (i > 7)) continue;
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   156
			str.remove(0, 2);
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   157
			HHHat[i] = str;
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   158
		} else
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   159
		if (str.startsWith("grave "))
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   160
		{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   161
			str.remove(0, 6);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   162
			Grave = str;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   163
		} else
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   164
		if (str.startsWith("fort "))
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   165
		{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   166
			str.remove(0, 5);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   167
			Fort = str;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   168
		} else
1659
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   169
		if (str.startsWith("voicepack "))
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   170
		{
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   171
			str.remove(0, 10);
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   172
			Voicepack = str;
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   173
		} else
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   174
		if (str.startsWith("bind "))
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   175
		{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   176
			str.remove(0, 5);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   177
			action = str.section(' ', 1);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   178
			str = str.section(' ', 0, 0);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   179
			str.truncate(15);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   180
			for (int i = 0; i < BINDS_NUMBER; i++)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   181
				if (action == binds[i].action)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   182
				{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   183
					binds[i].strbind = str;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   184
					break;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   185
				}
239
f9adf3c73bed 'Proto' class to make things easier
unc0rr
parents: 231
diff changeset
   186
		} else
231
c77b16e48273 bots power icons added
displacer
parents: 184
diff changeset
   187
		if (str.startsWith("difficulty "))
c77b16e48273 bots power icons added
displacer
parents: 184
diff changeset
   188
		{
c77b16e48273 bots power icons added
displacer
parents: 184
diff changeset
   189
		  str.remove(0, 11);
c77b16e48273 bots power icons added
displacer
parents: 184
diff changeset
   190
		  difficulty=str.toUInt();
c77b16e48273 bots power icons added
displacer
parents: 184
diff changeset
   191
		  if (difficulty>5) difficulty=0; // this shouldn't normally happen
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   192
		}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   193
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   194
	cfgfile.close();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   195
	return true;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   196
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   197
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   198
bool HWTeam::SaveToFile()
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   199
{
245
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
   200
	if (OldTeamName != TeamName)
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
   201
	{
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
   202
		QFile cfgfile(cfgdir->absolutePath() + "/" + OldTeamName + ".cfg");
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
   203
		cfgfile.remove();
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
   204
		OldTeamName = TeamName;
4f6b53b7a567 Make teams config file name be team name
unc0rr
parents: 239
diff changeset
   205
	}
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   206
	QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   207
	if (!cfgfile.open(QIODevice::WriteOnly)) return false;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   208
	QTextStream stream(&cfgfile);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   209
	stream.setCodec("UTF-8");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   210
	stream << "; Generated by Hedgewars, do not modify" << endl;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   211
	stream << "name team " << TeamName << endl;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   212
	for (int i = 0; i < 8; i++)
1240
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   213
	{
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   214
		stream << "name hh" << i << " " << HHName[i] << endl;
1240
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   215
		stream << "hat" << i << " " << HHHat[i] << endl;
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   216
	}
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   217
	stream << "grave " << Grave << endl;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   218
	stream << "fort " << Fort << endl;
1659
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   219
	stream << "voicepack " << Voicepack << endl;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   220
	for(int i = 0; i < BINDS_NUMBER; i++)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   221
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   222
		stream << "bind " << binds[i].strbind << " " << binds[i].action << endl;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   223
	}
231
c77b16e48273 bots power icons added
displacer
parents: 184
diff changeset
   224
	stream << "difficulty " << difficulty << endl;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   225
	cfgfile.close();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   226
	return true;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   227
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   228
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   229
void HWTeam::SetToPage(HWForm * hwform)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   230
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   231
	hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName);
336
82d654db133d Team level at new place on team config page
unc0rr
parents: 319
diff changeset
   232
	hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   233
	for(int i = 0; i < 8; i++)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   234
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   235
		hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]);
1240
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   236
		hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole));
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   237
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   238
	hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave));
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   239
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   240
	hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort));
1659
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   241
	hwform->ui.pageEditTeam->CBVoicepack->setCurrentIndex(hwform->ui.pageEditTeam->CBVoicepack->findText(Voicepack));
1287
4a0cbcbe3521 Move preview icons into comboboxes
unc0rr
parents: 1245
diff changeset
   242
	//hwform->ui.pageEditTeam->CBFort_activated(Fort);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   243
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   244
	for(int i = 0; i < BINDS_NUMBER; i++)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   245
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   246
		hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findText(binds[i].strbind));
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   247
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   248
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   249
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   250
void HWTeam::GetFromPage(HWForm * hwform)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   251
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   252
	TeamName  = hwform->ui.pageEditTeam->TeamNameEdit->text();
336
82d654db133d Team level at new place on team config page
unc0rr
parents: 319
diff changeset
   253
	difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex();
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   254
	for(int i = 0; i < 8; i++)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   255
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   256
		HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
1240
16b85f292030 Store selected hats in team config
unc0rr
parents: 1066
diff changeset
   257
		HHHat[i] = hwform->ui.pageEditTeam->HHHats[i]->currentText();
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   258
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   259
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   260
	Grave = hwform->ui.pageEditTeam->CBGrave->currentText();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   261
	Fort = hwform->ui.pageEditTeam->CBFort->currentText();
1659
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   262
	Voicepack = hwform->ui.pageEditTeam->CBVoicepack->currentText();
247
07605d2a2024 - Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents: 245
diff changeset
   263
	for(int i = 0; i < BINDS_NUMBER; i++)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   264
	{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   265
		binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->currentText();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   266
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   267
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   268
341
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   269
QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   270
{
239
f9adf3c73bed 'Proto' class to make things easier
unc0rr
parents: 231
diff changeset
   271
	QStringList sl;
605
2651c3fe4567 - Make hwengine protocol more obvious
unc0rr
parents: 546
diff changeset
   272
	sl.push_back(QString("eaddteam %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName));
606
9d800fdfd3bd Add ammostores in frontend, should help further ammostores implemetation
unc0rr
parents: 605
diff changeset
   273
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
   274
	if (m_isNetTeam)
341
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   275
		sl.push_back("erdriven");
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   276
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   277
	sl.push_back(QString("egrave " + Grave));
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   278
	sl.push_back(QString("efort " + Fort));
1659
fd593a5e71fb Team class now supports voicepacks
unc0rr
parents: 1656
diff changeset
   279
	sl.push_back(QString("evoicepack " + Voicepack));
341
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   280
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
   281
	if (!m_isNetTeam)
341
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   282
		for(int i = 0; i < BINDS_NUMBER; i++)
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   283
			sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   284
184230eb4151 - Store more team specific values in HWTeam
unc0rr
parents: 339
diff changeset
   285
	for (int t = 0; t < numHedgehogs; t++)
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1240
diff changeset
   286
	{
605
2651c3fe4567 - Make hwengine protocol more obvious
unc0rr
parents: 546
diff changeset
   287
	  sl.push_back(QString("eaddhh %1 %2 %3")
319
7f3bd9e31f18 some changes
displacer
parents: 314
diff changeset
   288
		       .arg(QString::number(difficulty),
605
2651c3fe4567 - Make hwengine protocol more obvious
unc0rr
parents: 546
diff changeset
   289
			    QString::number(InitHealth),
2651c3fe4567 - Make hwengine protocol more obvious
unc0rr
parents: 546
diff changeset
   290
			    HHName[t]));
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1240
diff changeset
   291
	  sl.push_back(QString("ehat %1")
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1240
diff changeset
   292
		       .arg(HHHat[t]));
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1240
diff changeset
   293
	}
239
f9adf3c73bed 'Proto' class to make things easier
unc0rr
parents: 231
diff changeset
   294
	return sl;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   295
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   296
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   297
void HWTeam::RandomNameByHat(const int &i)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   298
{
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   299
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   300
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   301
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   302
	QStringList Dictionaries;
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   303
	HatCfgLoad(HHHat[i],Dictionaries);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   304
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   305
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   306
/*
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   307
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   308
"Dismissed",
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   309
"Dragon",
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   310
"Mindblower",
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   311
*/
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   312
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   313
	QStringList Dictionary;
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   314
	DictLoad(Dictionaries[rand()%(Dictionaries.size())],Dictionary);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   315
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   316
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   317
	HHName[i] = Dictionary[rand()%(Dictionary.size())];
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   318
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   319
}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   320
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   321
void HWTeam::TeamRandomName(const int &i)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   322
{
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   323
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   324
	RandomNameByHat(i);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   325
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   326
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   327
}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   328
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   329
void HWTeam::TeamRandomNames(bool changeteamname)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   330
{
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   331
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   332
	if ((TypesHatnames.size() > 0) && TypesAvliable){
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   333
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   334
		int kind = (rand()%(TypesHatnames.size()));
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   335
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   336
		if (changeteamname){
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   337
			if (TypesTeamnames[kind].size() > 0){
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   338
				TeamName = TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())];
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   339
			}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   340
		}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   341
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   342
		for(int i = 0; i < 8; i++)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   343
		{
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   344
			if ((TypesHatnames[kind].size()) > 0){
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   345
				HHHat[i] = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   346
			}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   347
			RandomNameByHat(i);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   348
		}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   349
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   350
	}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   351
}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   352
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   353
bool HWTeam::isNetTeam() const
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   354
{
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
   355
  return m_isNetTeam;
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   356
}
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   357
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
   358
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   359
bool HWTeam::operator==(const HWTeam& t1) const {
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
   360
  return TeamName==t1.TeamName;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   361
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   362
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   363
bool HWTeam::operator<(const HWTeam& t1) const {
1325
c8994d47f41d Adding teams now works
unc0rr
parents: 1293
diff changeset
   364
  return TeamName<t1.TeamName; // if names are equal - test if it is net team
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   365
}
1840
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   366
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   367
void HWTeam::TypesLoad()
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   368
{
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   369
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   370
     QFile file(QString("%1/Names/types.ini").arg(datadir->absolutePath()));
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   371
     if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   372
         TypesAvliable = FALSE;
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   373
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   374
     int counter = 0; //counter starts with 0 (teamnames mode)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   375
     TypesTeamnames.append(QStringList());
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   376
     TypesHatnames.append(QStringList());
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   377
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   378
     QTextStream in(&file);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   379
     while (!in.atEnd()) {
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   380
         QString line = in.readLine();
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   381
         if (line == QString("#####")){
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   382
             counter++; //toggle mode (teamnames || hats)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   383
             if ((counter%2) == 0){
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   384
                 TypesTeamnames.append(QStringList());
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   385
                 TypesHatnames.append(QStringList());
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   386
             }
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   387
         } else if ((line == QString("*****")) || (line == QString("*END*"))){
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   388
             TypesAvliable = TRUE; return; // bye bye
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   389
         } else {
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   390
             if ((counter%2) == 0){ // even => teamnames mode
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   391
                 TypesTeamnames[(counter/2)].append(line);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   392
             } else { // odd => hats mode
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   393
                 TypesHatnames[((counter-1)/2)].append(line);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   394
             }
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   395
         }
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   396
//         Types.append(line);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   397
     }
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   398
         TypesAvliable = TRUE;
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   399
     return;
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   400
}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   401
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   402
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   403
void HWTeam::DictLoad(const QString filename, QStringList &list)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   404
{
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   405
     list.clear();
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   406
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   407
     QFile file(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename));
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   408
     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   409
     {
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   410
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   411
         QTextStream in(&file);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   412
         while (!in.atEnd()) {
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   413
             QString line = in.readLine();
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   414
             if(line != QString(""))
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   415
                 {list.append(line);}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   416
         }
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   417
     }
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   418
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   419
     if (list.size()==0)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   420
         list.append(filename);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   421
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   422
}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   423
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   424
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   425
void HWTeam::HatCfgLoad(const QString hatname, QStringList &list)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   426
{
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   427
     list.clear();
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   428
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   429
     QFile file(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname));
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   430
     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   431
     {
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   432
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   433
         QTextStream in(&file);
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   434
         while (!in.atEnd()) {
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   435
             QString line = in.readLine();
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   436
             if(line != QString(""))
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   437
                 {list.append(line);}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   438
         }
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   439
     }
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   440
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   441
     if (list.size()==0)
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   442
         list.append(QString("generic"));
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   443
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   444
}
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   445
4747f0232b88 ttsmj2's random teams patch
unc0rr
parents: 1683
diff changeset
   446