23 #include <QCryptographicHash> |
23 #include <QCryptographicHash> |
24 #include <QSettings> |
24 #include <QSettings> |
25 |
25 |
26 #include "team.h" |
26 #include "team.h" |
27 #include "hwform.h" |
27 #include "hwform.h" |
28 #include "pageeditteam.h" |
|
29 #include "hwconsts.h" |
|
30 #include "hats.h" |
28 #include "hats.h" |
31 |
29 |
32 HWTeam::HWTeam(const QString & teamname) : |
30 HWTeam::HWTeam(const QString & teamname) : |
33 difficulty(0), |
31 m_difficulty(0), |
34 numHedgehogs(4), |
32 m_numHedgehogs(4), |
35 m_isNetTeam(false) |
33 m_isNetTeam(false) |
36 { |
34 { |
37 TeamName = teamname; |
35 m_name = teamname; |
38 OldTeamName = TeamName; |
36 OldTeamName = m_name; |
39 for (int i = 0; i < 8; i++) |
37 for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
40 { |
38 { |
41 Hedgehogs[i].Name.sprintf("hedgehog %d", i); |
39 m_hedgehogs[i].Name = (QLineEdit::tr("hedgehog %1").arg(i+1)); |
42 Hedgehogs[i].Hat = "NoHat"; |
40 m_hedgehogs[i].Hat = "NoHat"; |
43 } |
41 } |
44 Grave = "Statue"; |
42 m_grave = "Statue"; |
45 Fort = "Plane"; |
43 m_fort = "Plane"; |
46 Voicepack = "Default"; |
44 m_voicepack = "Default"; |
47 Flag = "hedgewars"; |
45 m_flag = "hedgewars"; |
48 for(int i = 0; i < BINDS_NUMBER; i++) |
46 for(int i = 0; i < BINDS_NUMBER; i++) |
49 { |
47 { |
50 binds[i].action = cbinds[i].action; |
48 m_binds[i].action = cbinds[i].action; |
51 binds[i].strbind = cbinds[i].strbind; |
49 m_binds[i].strbind = cbinds[i].strbind; |
52 } |
50 } |
53 Rounds = 0; |
51 m_rounds = 0; |
54 Wins = 0; |
52 m_wins = 0; |
55 CampaignProgress = 0; |
53 m_campaignProgress = 0; |
56 } |
54 } |
57 |
55 |
58 HWTeam::HWTeam(const QStringList& strLst) : |
56 HWTeam::HWTeam(const QStringList& strLst) : |
59 numHedgehogs(4), |
57 m_numHedgehogs(4), |
60 m_isNetTeam(true) |
58 m_isNetTeam(true) |
61 { |
59 { |
62 // net teams are configured from QStringList |
60 // net teams are configured from QStringList |
63 if(strLst.size() != 23) throw HWTeamConstructException(); |
61 if(strLst.size() != 23) throw HWTeamConstructException(); |
64 TeamName = strLst[0]; |
62 m_name = strLst[0]; |
65 Grave = strLst[1]; |
63 m_grave = strLst[1]; |
66 Fort = strLst[2]; |
64 m_fort = strLst[2]; |
67 Voicepack = strLst[3]; |
65 m_voicepack = strLst[3]; |
68 Flag = strLst[4]; |
66 m_flag = strLst[4]; |
69 Owner = strLst[5]; |
67 m_owner = strLst[5]; |
70 difficulty = strLst[6].toUInt(); |
68 m_difficulty = strLst[6].toUInt(); |
71 for(int i = 0; i < 8; i++) |
69 for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
72 { |
70 { |
73 Hedgehogs[i].Name=strLst[i * 2 + 7]; |
71 m_hedgehogs[i].Name=strLst[i * 2 + 7]; |
74 Hedgehogs[i].Hat=strLst[i * 2 + 8]; |
72 m_hedgehogs[i].Hat=strLst[i * 2 + 8]; |
75 // Somehow claymore managed an empty hat. Until we figure out how, this should avoid a repeat |
73 // Somehow claymore managed an empty hat. Until we figure out how, this should avoid a repeat |
76 // Checking net teams is probably pointless, but can't hurt. |
74 // Checking net teams is probably pointless, but can't hurt. |
77 if (Hedgehogs[i].Hat.isEmpty()) Hedgehogs[i].Hat = "NoHat"; |
75 if (m_hedgehogs[i].Hat.isEmpty()) m_hedgehogs[i].Hat = "NoHat"; |
78 } |
76 } |
79 Rounds = 0; |
77 m_rounds = 0; |
80 Wins = 0; |
78 m_wins = 0; |
81 CampaignProgress = 0; |
79 m_campaignProgress = 0; |
82 } |
80 } |
83 |
81 |
84 HWTeam::HWTeam() : |
82 HWTeam::HWTeam() : |
85 difficulty(0), |
83 m_difficulty(0), |
86 numHedgehogs(4), |
84 m_numHedgehogs(4), |
87 m_isNetTeam(false) |
85 m_isNetTeam(false) |
88 { |
86 { |
89 TeamName = QString("Team"); |
87 m_name = QString("Team"); |
90 for (int i = 0; i < 8; i++) |
88 for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
91 { |
89 { |
92 Hedgehogs[i].Name.sprintf("hedgehog %d", i); |
90 m_hedgehogs[i].Name.sprintf("hedgehog %d", i); |
93 Hedgehogs[i].Hat = "NoHat"; |
91 m_hedgehogs[i].Hat = "NoHat"; |
94 } |
92 } |
95 |
93 |
96 Grave = QString("Simple"); // default |
94 m_grave = QString("Simple"); // default |
97 Fort = QString("Island"); // default |
95 m_fort = QString("Island"); // default |
98 Voicepack = "Default"; |
96 m_voicepack = "Default"; |
99 Flag = "hedgewars"; |
97 m_flag = "hedgewars"; |
100 |
98 |
101 for(int i = 0; i < BINDS_NUMBER; i++) |
99 for(int i = 0; i < BINDS_NUMBER; i++) |
102 { |
100 { |
103 binds[i].action = cbinds[i].action; |
101 m_binds[i].action = cbinds[i].action; |
104 binds[i].strbind = cbinds[i].strbind; |
102 m_binds[i].strbind = cbinds[i].strbind; |
105 } |
103 } |
106 Rounds = 0; |
104 m_rounds = 0; |
107 Wins = 0; |
105 m_wins = 0; |
108 CampaignProgress = 0; |
106 m_campaignProgress = 0; |
109 } |
107 } |
110 |
108 |
111 |
109 |
112 bool HWTeam::LoadFromFile() |
110 bool HWTeam::loadFromFile() |
113 { |
111 { |
114 QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".hwt", QSettings::IniFormat, 0); |
112 QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt", QSettings::IniFormat, 0); |
115 teamfile.setIniCodec("UTF-8"); |
113 teamfile.setIniCodec("UTF-8"); |
116 TeamName = teamfile.value("Team/Name", TeamName).toString(); |
114 m_name = teamfile.value("Team/Name", m_name).toString(); |
117 Grave = teamfile.value("Team/Grave", "Statue").toString(); |
115 m_grave = teamfile.value("Team/Grave", "Statue").toString(); |
118 Fort = teamfile.value("Team/Fort", "Plane").toString(); |
116 m_fort = teamfile.value("Team/Fort", "Plane").toString(); |
119 Voicepack = teamfile.value("Team/Voicepack", "Default").toString(); |
117 m_voicepack = teamfile.value("Team/Voicepack", "Default").toString(); |
120 Flag = teamfile.value("Team/Flag", "hedgewars").toString(); |
118 m_flag = teamfile.value("Team/Flag", "hedgewars").toString(); |
121 difficulty = teamfile.value("Team/Difficulty", 0).toInt(); |
119 m_difficulty = teamfile.value("Team/Difficulty", 0).toInt(); |
122 Rounds = teamfile.value("Team/Rounds", 0).toInt(); |
120 m_rounds = teamfile.value("Team/Rounds", 0).toInt(); |
123 Wins = teamfile.value("Team/Wins", 0).toInt(); |
121 m_wins = teamfile.value("Team/Wins", 0).toInt(); |
124 CampaignProgress = teamfile.value("Team/CampaignProgress", 0).toInt(); |
122 m_campaignProgress = teamfile.value("Team/CampaignProgress", 0).toInt(); |
125 for(int i = 0; i < 8; i++) |
123 for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
126 { |
124 { |
127 QString hh = QString("Hedgehog%1/").arg(i); |
125 QString hh = QString("Hedgehog%1/").arg(i); |
128 Hedgehogs[i].Name = teamfile.value(hh + "Name", QString("hedgehog %1").arg(i)).toString(); |
126 m_hedgehogs[i].Name = teamfile.value(hh + "Name", QString("hedgehog %1").arg(i+1)).toString(); |
129 Hedgehogs[i].Hat = teamfile.value(hh + "Hat", "NoHat").toString(); |
127 m_hedgehogs[i].Hat = teamfile.value(hh + "Hat", "NoHat").toString(); |
130 Hedgehogs[i].Rounds = teamfile.value(hh + "Rounds", 0).toInt(); |
128 m_hedgehogs[i].Rounds = teamfile.value(hh + "Rounds", 0).toInt(); |
131 Hedgehogs[i].Kills = teamfile.value(hh + "Kills", 0).toInt(); |
129 m_hedgehogs[i].Kills = teamfile.value(hh + "Kills", 0).toInt(); |
132 Hedgehogs[i].Deaths = teamfile.value(hh + "Deaths", 0).toInt(); |
130 m_hedgehogs[i].Deaths = teamfile.value(hh + "Deaths", 0).toInt(); |
133 Hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt(); |
131 m_hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt(); |
134 } |
132 } |
135 for(int i = 0; i < BINDS_NUMBER; i++) |
133 for(int i = 0; i < BINDS_NUMBER; i++) |
136 binds[i].strbind = teamfile.value(QString("Binds/%1").arg(binds[i].action), cbinds[i].strbind).toString(); |
134 m_binds[i].strbind = teamfile.value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString(); |
137 for(int i = 0; i < MAX_ACHIEVEMENTS; i++) |
135 for(int i = 0; i < MAX_ACHIEVEMENTS; i++) |
138 if(achievements[i][0][0]) |
136 if(achievements[i][0][0]) |
139 AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt(); |
137 AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt(); |
140 else |
138 else |
141 break; |
139 break; |
142 return true; |
140 return true; |
143 } |
141 } |
144 |
142 |
145 bool HWTeam::FileExists() |
143 bool HWTeam::fileExists() |
146 { |
144 { |
147 QFile f(cfgdir->absolutePath() + "/Teams/" + TeamName + ".hwt"); |
145 QFile f(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt"); |
148 return f.exists(); |
146 return f.exists(); |
149 } |
147 } |
150 |
148 |
151 bool HWTeam::DeleteFile() |
149 bool HWTeam::deleteFile() |
152 { |
150 { |
153 if(m_isNetTeam) |
151 if(m_isNetTeam) |
154 return false; |
152 return false; |
155 QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".hwt"); |
153 QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt"); |
156 cfgfile.remove(); |
154 cfgfile.remove(); |
157 return true; |
155 return true; |
158 } |
156 } |
159 |
157 |
160 bool HWTeam::SaveToFile() |
158 bool HWTeam::saveToFile() |
161 { |
159 { |
162 if (OldTeamName != TeamName) |
160 if (OldTeamName != m_name) |
163 { |
161 { |
164 QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + OldTeamName + ".hwt"); |
162 QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + OldTeamName + ".hwt"); |
165 cfgfile.remove(); |
163 cfgfile.remove(); |
166 OldTeamName = TeamName; |
164 OldTeamName = m_name; |
167 } |
165 } |
168 QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".hwt", QSettings::IniFormat, 0); |
166 QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt", QSettings::IniFormat, 0); |
169 teamfile.setIniCodec("UTF-8"); |
167 teamfile.setIniCodec("UTF-8"); |
170 teamfile.setValue("Team/Name", TeamName); |
168 teamfile.setValue("Team/Name", m_name); |
171 teamfile.setValue("Team/Grave", Grave); |
169 teamfile.setValue("Team/Grave", m_grave); |
172 teamfile.setValue("Team/Fort", Fort); |
170 teamfile.setValue("Team/Fort", m_fort); |
173 teamfile.setValue("Team/Voicepack", Voicepack); |
171 teamfile.setValue("Team/Voicepack", m_voicepack); |
174 teamfile.setValue("Team/Flag", Flag); |
172 teamfile.setValue("Team/Flag", m_flag); |
175 teamfile.setValue("Team/Difficulty", difficulty); |
173 teamfile.setValue("Team/Difficulty", m_difficulty); |
176 teamfile.setValue("Team/Rounds", Rounds); |
174 teamfile.setValue("Team/Rounds", m_rounds); |
177 teamfile.setValue("Team/Wins", Wins); |
175 teamfile.setValue("Team/Wins", m_wins); |
178 teamfile.setValue("Team/CampaignProgress", CampaignProgress); |
176 teamfile.setValue("Team/CampaignProgress", m_campaignProgress); |
179 for(int i = 0; i < 8; i++) |
177 for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
180 { |
178 { |
181 QString hh = QString("Hedgehog%1/").arg(i); |
179 QString hh = QString("Hedgehog%1/").arg(i); |
182 teamfile.setValue(hh + "Name", Hedgehogs[i].Name); |
180 teamfile.setValue(hh + "Name", m_hedgehogs[i].Name); |
183 teamfile.setValue(hh + "Hat", Hedgehogs[i].Hat); |
181 teamfile.setValue(hh + "Hat", m_hedgehogs[i].Hat); |
184 teamfile.setValue(hh + "Rounds", Hedgehogs[i].Rounds); |
182 teamfile.setValue(hh + "Rounds", m_hedgehogs[i].Rounds); |
185 teamfile.setValue(hh + "Kills", Hedgehogs[i].Kills); |
183 teamfile.setValue(hh + "Kills", m_hedgehogs[i].Kills); |
186 teamfile.setValue(hh + "Deaths", Hedgehogs[i].Deaths); |
184 teamfile.setValue(hh + "Deaths", m_hedgehogs[i].Deaths); |
187 teamfile.setValue(hh + "Suicides", Hedgehogs[i].Suicides); |
185 teamfile.setValue(hh + "Suicides", m_hedgehogs[i].Suicides); |
188 } |
186 } |
189 for(int i = 0; i < BINDS_NUMBER; i++) |
187 for(int i = 0; i < BINDS_NUMBER; i++) |
190 teamfile.setValue(QString("Binds/%1").arg(binds[i].action), binds[i].strbind); |
188 teamfile.setValue(QString("Binds/%1").arg(m_binds[i].action), m_binds[i].strbind); |
191 for(int i = 0; i < MAX_ACHIEVEMENTS; i++) |
189 for(int i = 0; i < MAX_ACHIEVEMENTS; i++) |
192 if(achievements[i][0][0]) |
190 if(achievements[i][0][0]) |
193 teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]); |
191 teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]); |
194 else |
192 else |
195 break; |
193 break; |
196 return true; |
194 return true; |
197 } |
195 } |
198 |
196 |
199 void HWTeam::SetToPage(HWForm * hwform) |
197 QStringList HWTeam::teamGameConfig(quint32 InitHealth) const |
200 { |
|
201 hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); |
|
202 hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty); |
|
203 for(int i = 0; i < 8; i++) |
|
204 { |
|
205 hwform->ui.pageEditTeam->HHNameEdit[i]->setText(Hedgehogs[i].Name); |
|
206 if (Hedgehogs[i].Hat.startsWith("Reserved")) |
|
207 hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+Hedgehogs[i].Hat.remove(0,40), Qt::DisplayRole)); |
|
208 else |
|
209 hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(Hedgehogs[i].Hat, Qt::DisplayRole)); |
|
210 } |
|
211 hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
|
212 hwform->ui.pageEditTeam->CBFlag->setCurrentIndex(hwform->ui.pageEditTeam->CBFlag->findData(Flag)); |
|
213 |
|
214 hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); |
|
215 hwform->ui.pageEditTeam->CBVoicepack->setCurrentIndex(hwform->ui.pageEditTeam->CBVoicepack->findText(Voicepack)); |
|
216 //hwform->ui.pageEditTeam->CBFort_activated(Fort); |
|
217 |
|
218 for(int i = 0; i < BINDS_NUMBER; i++) |
|
219 { |
|
220 hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findData(binds[i].strbind)); |
|
221 } |
|
222 } |
|
223 |
|
224 void HWTeam::GetFromPage(HWForm * hwform) |
|
225 { |
|
226 TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); |
|
227 difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex(); |
|
228 for(int i = 0; i < 8; i++) |
|
229 { |
|
230 Hedgehogs[i].Name = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); |
|
231 if (hwform->ui.pageEditTeam->HHHats[i]->currentText().startsWith("Reserved")) |
|
232 Hedgehogs[i].Hat = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9); |
|
233 else |
|
234 Hedgehogs[i].Hat = hwform->ui.pageEditTeam->HHHats[i]->currentText(); |
|
235 } |
|
236 |
|
237 Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); |
|
238 Fort = hwform->ui.pageEditTeam->CBFort->currentText(); |
|
239 Voicepack = hwform->ui.pageEditTeam->CBVoicepack->currentText(); |
|
240 Flag = hwform->ui.pageEditTeam->CBFlag->itemData(hwform->ui.pageEditTeam->CBFlag->currentIndex()).toString(); |
|
241 for(int i = 0; i < BINDS_NUMBER; i++) |
|
242 { |
|
243 binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->itemData(hwform->ui.pageEditTeam->CBBind[i]->currentIndex()).toString(); |
|
244 } |
|
245 } |
|
246 |
|
247 QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const |
|
248 { |
198 { |
249 QStringList sl; |
199 QStringList sl; |
250 if (m_isNetTeam) |
200 if (m_isNetTeam) |
251 { |
201 { |
252 sl.push_back(QString("eaddteam %3 %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName).arg(QString(QCryptographicHash::hash(Owner.toLatin1(), QCryptographicHash::Md5).toHex()))); |
202 sl.push_back(QString("eaddteam %3 %1 %2").arg(m_color.rgb() & 0xffffff).arg(m_name).arg(QString(QCryptographicHash::hash(m_owner.toLatin1(), QCryptographicHash::Md5).toHex()))); |
253 sl.push_back("erdriven"); |
203 sl.push_back("erdriven"); |
254 } |
204 } |
255 else sl.push_back(QString("eaddteam %3 %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName).arg(playerHash)); |
205 else sl.push_back(QString("eaddteam %3 %1 %2").arg(m_color.rgb() & 0xffffff).arg(m_name).arg(playerHash)); |
256 |
206 |
257 sl.push_back(QString("egrave " + Grave)); |
207 sl.push_back(QString("egrave " + m_grave)); |
258 sl.push_back(QString("efort " + Fort)); |
208 sl.push_back(QString("efort " + m_fort)); |
259 sl.push_back(QString("evoicepack " + Voicepack)); |
209 sl.push_back(QString("evoicepack " + m_voicepack)); |
260 sl.push_back(QString("eflag " + Flag)); |
210 sl.push_back(QString("eflag " + m_flag)); |
261 |
211 |
262 if (!m_isNetTeam) |
212 if (!m_isNetTeam) |
263 for(int i = 0; i < BINDS_NUMBER; i++) |
213 for(int i = 0; i < BINDS_NUMBER; i++) |
264 if(!binds[i].strbind.isEmpty()) |
214 if(!m_binds[i].strbind.isEmpty()) |
265 sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action)); |
215 sl.push_back(QString("ebind " + m_binds[i].strbind + " " + m_binds[i].action)); |
266 |
216 |
267 for (int t = 0; t < numHedgehogs; t++) |
217 for (int t = 0; t < m_numHedgehogs; t++) |
268 { |
218 { |
269 sl.push_back(QString("eaddhh %1 %2 %3") |
219 sl.push_back(QString("eaddhh %1 %2 %3") |
270 .arg(QString::number(difficulty), |
220 .arg(QString::number(m_difficulty), |
271 QString::number(InitHealth), |
221 QString::number(InitHealth), |
272 Hedgehogs[t].Name)); |
222 m_hedgehogs[t].Name)); |
273 sl.push_back(QString("ehat %1") |
223 sl.push_back(QString("ehat %1") |
274 .arg(Hedgehogs[t].Hat)); |
224 .arg(m_hedgehogs[t].Hat)); |
275 } |
225 } |
276 return sl; |
226 return sl; |
277 } |
227 } |
278 |
228 |
279 bool HWTeam::isNetTeam() const |
229 bool HWTeam::isNetTeam() const |