# HG changeset patch # User unc0rr # Date 1353867431 -14400 # Node ID c247346d296f966eab6950b2ba4c9ea458a7bb39 # Parent 0e6fadf81a2cac5280f44a267f19cebc71104f16 Convert HWTeam to be a wrapper to flib_team diff -r 0e6fadf81a2c -r c247346d296f QTfrontend/game.cpp --- a/QTfrontend/game.cpp Sun Nov 25 01:13:51 2012 +0400 +++ b/QTfrontend/game.cpp Sun Nov 25 22:17:11 2012 +0400 @@ -104,8 +104,8 @@ HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber))); HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber))); if(gamecfg->schemeData(15).toBool() || !gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore")); - HWProto::addStringListToBuffer(buf, - team.teamGameConfig(gamecfg->getInitHealth())); +// HWProto::addStringListToBuffer(buf, +// team.teamGameConfig(gamecfg->getInitHealth())); ; } } @@ -133,9 +133,9 @@ team1.setDifficulty(0); team1.setColor(0); team1.setNumHedgehogs(4); - HWNamegen::teamRandomNames(team1,true); - HWProto::addStringListToBuffer(teamscfg, - team1.teamGameConfig(100)); + HWNamegen::teamRandomNames(team1, true); +// HWProto::addStringListToBuffer(teamscfg, +// team1.teamGameConfig(100)); HWTeam team2; team2.setDifficulty(4); @@ -143,9 +143,9 @@ team2.setNumHedgehogs(4); do HWNamegen::teamRandomNames(team2,true); - while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat)); - HWProto::addStringListToBuffer(teamscfg, - team2.teamGameConfig(100)); + while(!team2.name().compare(team1.name()) || !team2.hedgehogHat(0).compare(team1.hedgehogHat(0))); +// HWProto::addStringListToBuffer(teamscfg, +// team2.teamGameConfig(100)); HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber))); HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber))); diff -r 0e6fadf81a2c -r c247346d296f QTfrontend/net/newnetclient.cpp --- a/QTfrontend/net/newnetclient.cpp Sun Nov 25 01:13:51 2012 +0400 +++ b/QTfrontend/net/newnetclient.cpp Sun Nov 25 22:17:11 2012 +0400 @@ -132,9 +132,9 @@ for(int i = 0; i < HEDGEHOGS_PER_TEAM; ++i) { cmd.append(delimeter); - cmd.append(team.hedgehog(i).Name); + cmd.append(team.hedgehogName(i)); cmd.append(delimeter); - cmd.append(team.hedgehog(i).Hat); + cmd.append(team.hedgehogHat(i)); } RawSendNet(cmd); } diff -r 0e6fadf81a2c -r c247346d296f QTfrontend/team.cpp --- a/QTfrontend/team.cpp Sun Nov 25 01:13:51 2012 +0400 +++ b/QTfrontend/team.cpp Sun Nov 25 22:17:11 2012 +0400 @@ -29,119 +29,91 @@ #include "hwform.h" #include "DataManager.h" -HWTeam::HWTeam(const QString & teamname) : - QObject(0) - , m_difficulty(0) - , m_numHedgehogs(4) - , m_isNetTeam(false) - , m_team(NULL) +HWTeam::HWTeam(const QString & teamname, QObject *parent) : + QObject(parent) { - m_name = teamname; - OldTeamName = m_name; + flib_team team; + bzero(&team, sizeof(team)); + team.name = teamname.toUtf8().data(); + team.grave = "Statue"; + team.fort = "Plane"; + team.voicepack = "Default"; + team.flag = "hedgewars"; + for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { - m_hedgehogs.append(HWHog()); - m_hedgehogs[i].Name = (QLineEdit::tr("hedgehog %1").arg(i+1)); - m_hedgehogs[i].Hat = "NoHat"; + team.hogs[i].name = QLineEdit::tr("hedgehog %1").arg(i+1).toUtf8().data(); + team.hogs[i].hat = "NoHat"; } - m_grave = "Statue"; - m_fort = "Plane"; - m_voicepack = "Default"; - m_flag = "hedgewars"; + + m_oldTeamName = teamname; + + QVector binds(BINDS_NUMBER); for(int i = 0; i < BINDS_NUMBER; i++) { - m_binds.append(BindAction()); - m_binds[i].action = cbinds[i].action; - m_binds[i].strbind = cbinds[i].strbind; + binds[i].action = cbinds[i].action.toUtf8().data(); + binds[i].binding = cbinds[i].strbind.toUtf8().data(); } - m_rounds = 0; - m_wins = 0; - m_campaignProgress = 0; - m_color = 0; + team.bindings = binds.data(); + team.bindingCount = binds.size(); + + team.remoteDriven = false; + team.hogsInGame = 4; + + m_team = flib_team_copy(&team); } -HWTeam::HWTeam(const QStringList& strLst) : - QObject(0) - , m_numHedgehogs(4) - , m_isNetTeam(true) - , m_team(NULL) +HWTeam::HWTeam(const QStringList& strLst, QObject *parent) : + QObject(parent) { // net teams are configured from QStringList if(strLst.size() != 23) throw HWTeamConstructException(); - m_name = strLst[0]; - m_grave = strLst[1]; - m_fort = strLst[2]; - m_voicepack = strLst[3]; - m_flag = strLst[4]; - m_owner = strLst[5]; - m_difficulty = strLst[6].toUInt(); - for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) - { - m_hedgehogs.append(HWHog()); - m_hedgehogs[i].Name=strLst[i * 2 + 7]; - m_hedgehogs[i].Hat=strLst[i * 2 + 8]; -// Somehow claymore managed an empty hat. Until we figure out how, this should avoid a repeat -// Checking net teams is probably pointless, but can't hurt. - if (m_hedgehogs[i].Hat.isEmpty()) m_hedgehogs[i].Hat = "NoHat"; - } - m_rounds = 0; - m_wins = 0; - m_campaignProgress = 0; - m_color = 0; -} + flib_team team; + bzero(&team, sizeof(team)); + team.name = strLst[0].toUtf8().data(); + m_oldTeamName = strLst[0]; + team.grave = strLst[1].toUtf8().data(); + team.fort = strLst[2].toUtf8().data(); + team.voicepack = strLst[3].toUtf8().data(); + team.flag = strLst[4].toUtf8().data(); + team.ownerName = strLst[5].toUtf8().data(); + int difficulty = strLst[6].toUInt(); -HWTeam::HWTeam() : - QObject(0) - , m_difficulty(0) - , m_numHedgehogs(4) - , m_isNetTeam(false) - , m_team(NULL) -{ - m_name = QString("Team"); for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { - m_hedgehogs.append(HWHog()); - m_hedgehogs[i].Name.sprintf("hedgehog %d", i); - m_hedgehogs[i].Hat = "NoHat"; + team.hogs[i].name = strLst[i * 2 + 7].toUtf8().data(); + + QString hat = strLst[i * 2 + 8]; + if (hat.isEmpty()) + team.hogs[i].hat = "NoHat"; + else + team.hogs[i].hat = hat.toUtf8().data(); + + team.hogs[i].difficulty = difficulty; } - m_grave = QString("Simple"); // default - m_fort = QString("Island"); // default - m_voicepack = "Default"; - m_flag = "hedgewars"; + m_oldTeamName = strLst[0]; + QVector binds(BINDS_NUMBER); for(int i = 0; i < BINDS_NUMBER; i++) { - m_binds.append(BindAction()); - m_binds[i].action = cbinds[i].action; - m_binds[i].strbind = cbinds[i].strbind; + binds[i].action = cbinds[i].action.toUtf8().data(); + binds[i].binding = cbinds[i].strbind.toUtf8().data(); } - m_rounds = 0; - m_wins = 0; - m_campaignProgress = 0; - m_color = 0; + team.bindings = binds.data(); + team.bindingCount = binds.size(); + + team.remoteDriven = true; + team.hogsInGame = 4; + + m_team = flib_team_copy(&team); } + HWTeam::HWTeam(const HWTeam & other) : - QObject(0) - , OldTeamName(other.OldTeamName) - , m_name(other.m_name) - , m_grave(other.m_grave) - , m_fort(other.m_fort) - , m_flag(other.m_flag) - , m_voicepack(other.m_voicepack) - , m_hedgehogs(other.m_hedgehogs) - , m_difficulty(other.m_difficulty) - , m_binds(other.m_binds) + QObject(other.parent()) + , m_oldTeamName(other.m_oldTeamName) , m_team(flib_team_copy(other.m_team)) - , m_numHedgehogs(other.m_numHedgehogs) - , m_color(other.m_color) - , m_isNetTeam(other.m_isNetTeam) - , m_owner(other.m_owner) - , m_campaignProgress(other.m_campaignProgress) - , m_rounds(other.m_rounds) - , m_wins(other.m_wins) -// , AchievementProgress(other.AchievementProgress) { } @@ -150,23 +122,8 @@ { if(this != &other) { - OldTeamName = other.OldTeamName; - m_name = other.m_name; - m_grave = other.m_grave; - m_fort = other.m_fort; - m_flag = other.m_flag; - m_voicepack = other.m_voicepack; - m_hedgehogs = other.m_hedgehogs; - m_difficulty = other.m_difficulty; - m_binds = other.m_binds; - m_numHedgehogs = other.m_numHedgehogs; - m_color = other.m_color; - m_isNetTeam = other.m_isNetTeam; - m_owner = other.m_owner; - m_campaignProgress = other.m_campaignProgress; - m_rounds = other.m_rounds; - m_wins = other.m_wins; - m_color = other.m_color; + m_oldTeamName = other.m_oldTeamName; + m_team = flib_team_copy(other.m_team); } return *this; @@ -180,143 +137,59 @@ bool HWTeam::loadFromFile() { + QString name = QString::fromUtf8(m_team->name); + if(m_team) flib_team_destroy(m_team); - m_team = flib_team_from_ini(QString("/config/Teams/%1.hwt").arg(m_name).toUtf8().constData()); + m_team = flib_team_from_ini(QString("/config/Teams/%1.hwt").arg(name).toUtf8().data()); - /* - QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0); - teamfile.setIniCodec("UTF-8"); - m_name = teamfile.value("Team/Name", m_name).toString(); - m_grave = teamfile.value("Team/Grave", "Statue").toString(); - m_fort = teamfile.value("Team/Fort", "Plane").toString(); - m_voicepack = teamfile.value("Team/Voicepack", "Default").toString(); - m_flag = teamfile.value("Team/Flag", "hedgewars").toString(); - m_difficulty = teamfile.value("Team/Difficulty", 0).toInt(); - m_rounds = teamfile.value("Team/Rounds", 0).toInt(); - m_wins = teamfile.value("Team/Wins", 0).toInt(); - m_campaignProgress = teamfile.value("Team/CampaignProgress", 0).toInt(); - for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) - { - QString hh = QString("Hedgehog%1/").arg(i); - m_hedgehogs[i].Name = teamfile.value(hh + "Name", QString("hedgehog %1").arg(i+1)).toString(); - m_hedgehogs[i].Hat = teamfile.value(hh + "Hat", "NoHat").toString(); - m_hedgehogs[i].Rounds = teamfile.value(hh + "Rounds", 0).toInt(); - m_hedgehogs[i].Kills = teamfile.value(hh + "Kills", 0).toInt(); - m_hedgehogs[i].Deaths = teamfile.value(hh + "Deaths", 0).toInt(); - m_hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt(); - } - for(int i = 0; i < BINDS_NUMBER; i++) - m_binds[i].strbind = teamfile.value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString(); - for(int i = 0; i < MAX_ACHIEVEMENTS; i++) - if(achievements[i][0][0]) - AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt(); - else - break;*/ return m_team != NULL; } bool HWTeam::fileExists() { - QFile f(QString("physfs://config/Teams/%1.hwt").arg(m_name)); + QFile f(QString("physfs://config/Teams/%1.hwt").arg(name())); return f.exists(); } bool HWTeam::deleteFile() { - if(m_isNetTeam) + if(m_team->remoteDriven) return false; - QFile cfgfile(QString("physfs://config/Teams/%1.hwt").arg(m_name)); + + QFile cfgfile(QString("physfs://config/Teams/%1.hwt").arg(name())); cfgfile.remove(); return true; } bool HWTeam::saveToFile() { - if (OldTeamName != m_name) + if (m_oldTeamName != name()) { - QFile cfgfile(QString("physfs://config/Teams/%1.hwt").arg(OldTeamName)); + QFile cfgfile(QString("physfs://config/Teams/%1.hwt").arg(m_oldTeamName)); cfgfile.remove(); - OldTeamName = m_name; + m_oldTeamName = name(); } - QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0); - teamfile.setIniCodec("UTF-8"); - teamfile.setValue("Team/Name", m_name); - teamfile.setValue("Team/Grave", m_grave); - teamfile.setValue("Team/Fort", m_fort); - teamfile.setValue("Team/Voicepack", m_voicepack); - teamfile.setValue("Team/Flag", m_flag); - teamfile.setValue("Team/Difficulty", m_difficulty); - teamfile.setValue("Team/Rounds", m_rounds); - teamfile.setValue("Team/Wins", m_wins); - teamfile.setValue("Team/CampaignProgress", m_campaignProgress); - for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) - { - QString hh = QString("Hedgehog%1/").arg(i); - teamfile.setValue(hh + "Name", m_hedgehogs[i].Name); - teamfile.setValue(hh + "Hat", m_hedgehogs[i].Hat); - teamfile.setValue(hh + "Rounds", m_hedgehogs[i].Rounds); - teamfile.setValue(hh + "Kills", m_hedgehogs[i].Kills); - teamfile.setValue(hh + "Deaths", m_hedgehogs[i].Deaths); - teamfile.setValue(hh + "Suicides", m_hedgehogs[i].Suicides); - } - for(int i = 0; i < BINDS_NUMBER; i++) - teamfile.setValue(QString("Binds/%1").arg(m_binds[i].action), m_binds[i].strbind); - for(int i = 0; i < MAX_ACHIEVEMENTS; i++) - if(achievements[i][0][0]) - teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]); - else - break; - return true; + + return flib_team_to_ini(QString("physfs://config/Teams/%1.hwt").arg(name()).toUtf8(), m_team) == 0; } -QStringList HWTeam::teamGameConfig(quint32 InitHealth) const -{ - QStringList sl; - if (m_isNetTeam) - { - sl.push_back(QString("eaddteam %3 %1 %2").arg(qcolor().rgb() & 0xffffff).arg(m_name).arg(QString(QCryptographicHash::hash(m_owner.toUtf8(), QCryptographicHash::Md5).toHex()))); - sl.push_back("erdriven"); - } - else sl.push_back(QString("eaddteam %3 %1 %2").arg(qcolor().rgb() & 0xffffff).arg(m_name).arg(playerHash)); - - sl.push_back(QString("egrave " + m_grave)); - sl.push_back(QString("efort " + m_fort)); - sl.push_back(QString("evoicepack " + m_voicepack)); - sl.push_back(QString("eflag " + m_flag)); - - if (!m_isNetTeam) - for(int i = 0; i < BINDS_NUMBER; i++) - if(!m_binds[i].strbind.isEmpty()) - sl.push_back(QString("ebind " + m_binds[i].strbind + " " + m_binds[i].action)); - - for (int t = 0; t < m_numHedgehogs; t++) - { - sl.push_back(QString("eaddhh %1 %2 %3") - .arg(QString::number(m_difficulty), - QString::number(InitHealth), - m_hedgehogs[t].Name)); - sl.push_back(QString("ehat %1") - .arg(m_hedgehogs[t].Hat)); - } - return sl; -} bool HWTeam::isNetTeam() const { - return m_isNetTeam; + return m_team->remoteDriven; } bool HWTeam::operator==(const HWTeam& t1) const { - return m_name==t1.m_name; + return qstrcmp(m_team->name, t1.m_team->name) == 0; } bool HWTeam::operator<(const HWTeam& t1) const { - return m_namename, t1.m_team->name) < 0; // if names are equal - test if it is net team } @@ -326,27 +199,45 @@ // name QString HWTeam::name() const { - return m_name; + return QString::fromUtf8(m_team->name); } + void HWTeam::setName(const QString & name) { - m_name = name; + free(m_team->name); + + m_team->name = qstrdup(name.toUtf8().constData()); +} + +QString HWTeam::hedgehogName(int index) const +{ + return QString::fromUtf8(m_team->hogs[index].name); } -// single hedgehog -const HWHog & HWTeam::hedgehog(unsigned int idx) const +QString HWTeam::hedgehogHat(int index) const { - return m_hedgehogs[idx]; + return QString::fromUtf8(m_team->hogs[index].hat); } -void HWTeam::setHedgehog(unsigned int idx, HWHog hh) + +void HWTeam::setHedgehogName(int index, const QString & name) { - m_hedgehogs[idx] = hh; + free(m_team->hogs[index].name); + + m_team->hogs[index].name = qstrdup(name.toUtf8().constData()); } +void HWTeam::setHedgehogHat(int index, const QString & hat) +{ + free(m_team->hogs[index].hat); + + m_team->hogs[index].hat = qstrdup(hat.toUtf8().constData()); +} + + // owner QString HWTeam::owner() const { - return m_owner; + return QString::fromUtf8(m_team->ownerName); } @@ -354,105 +245,121 @@ // difficulty unsigned int HWTeam::difficulty() const { - return m_difficulty; + return m_team->hogs[0].difficulty; } + void HWTeam::setDifficulty(unsigned int level) { - m_difficulty = level; + for(int i = 0; i < HEDGEHOGS_PER_TEAM; ++i) + m_team->hogs[i].difficulty = level; } // color int HWTeam::color() const { - return m_color; + return m_team->colorIndex; } QColor HWTeam::qcolor() const { - return DataManager::instance().colorsModel()->item(m_color)->data().value(); + return DataManager::instance().colorsModel()->item(m_team->colorIndex)->data().value(); } void HWTeam::setColor(int color) { - m_color = color % DataManager::instance().colorsModel()->rowCount(); + m_team->colorIndex = color % DataManager::instance().colorsModel()->rowCount(); } // binds QString HWTeam::keyBind(unsigned int idx) const { - return m_binds[idx].strbind; + return QString::fromUtf8(m_team->bindings[idx].binding); } + void HWTeam::bindKey(unsigned int idx, const QString & key) { - m_binds[idx].strbind = key; + free(m_team->bindings[idx].binding); + + m_team->bindings[idx].binding = qstrdup(key.toUtf8().constData()); } // flag -void HWTeam::setFlag(const QString & flag) +void HWTeam::setFlag(const QString & flag) { - m_flag = flag; + free(m_team->flag); + + m_team->flag = strdup(flag.toUtf8().constData()); } + QString HWTeam::flag() const { - return m_flag; + return QString::fromUtf8(m_team->flag); } // fort -void HWTeam::setFort(const QString & fort) +void HWTeam::setFort(const QString & fort) { - m_fort = fort; + free(m_team->fort); + + m_team->fort = strdup(fort.toUtf8().constData()); } + QString HWTeam::fort() const { - return m_fort; + return QString::fromUtf8(m_team->fort); } // grave void HWTeam::setGrave(const QString & grave) { - m_grave = grave; + free(m_team->grave); + + m_team->grave = strdup(grave.toUtf8().constData()); } + QString HWTeam::grave() const { - return m_grave; + return QString::fromUtf8(m_team->grave); } // voicepack - getter/setter void HWTeam::setVoicepack(const QString & voicepack) { - m_voicepack = voicepack; + free(m_team->voicepack); + + m_team->voicepack = strdup(voicepack.toUtf8().constData()); } + QString HWTeam::voicepack() const { - return m_voicepack; + return QString::fromUtf8(m_team->voicepack); } // campaignProgress - getter unsigned int HWTeam::campaignProgress() const { - return m_campaignProgress; -}; + return m_team->campaignProgress; +} // amount of hedgehogs unsigned char HWTeam::numHedgehogs() const { - return m_numHedgehogs; + return m_team->hogsInGame; } + void HWTeam::setNumHedgehogs(unsigned char num) { - m_numHedgehogs = num; + m_team->hogsInGame = num; } - - // rounds+wins - incrementors void HWTeam::incRounds() { - m_rounds++; + m_team->rounds++; } void HWTeam::incWins() { - m_wins++; + m_team->wins++; } diff -r 0e6fadf81a2c -r c247346d296f QTfrontend/team.h --- a/QTfrontend/team.h Sun Nov 25 01:13:51 2012 +0400 +++ b/QTfrontend/team.h Sun Nov 25 22:17:11 2012 +0400 @@ -34,14 +34,6 @@ { }; -// structure for customization and statistics of a single hedgehog -struct HWHog -{ - QString Name; - QString Hat; - int Rounds, Kills, Deaths, Suicides; -}; - // class representing a team class HWTeam : public QObject { @@ -50,9 +42,8 @@ public: // constructors - HWTeam(const QString & teamname); - HWTeam(const QStringList& strLst); - HWTeam(); + HWTeam(const QString & teamname = QString(), QObject * parent = 0); + HWTeam(const QStringList& strLst, QObject * parent = 0); HWTeam(const HWTeam & other); ~HWTeam(); @@ -71,7 +62,7 @@ QString flag() const; QString fort() const; QString grave() const; - const HWHog & hedgehog(unsigned int idx) const; + //const HWHog & hedgehog(unsigned int idx) const; bool isNetTeam() const; QString keyBind(unsigned int idx) const; QString name() const; @@ -85,18 +76,19 @@ void setFlag(const QString & flag); void setFort(const QString & fort); void setGrave(const QString & grave); - void setHedgehog(unsigned int idx, HWHog hh); void setName(const QString & name); void setNumHedgehogs(unsigned char num); void setVoicepack(const QString & voicepack); + QString hedgehogName(int index) const; + QString hedgehogHat(int index) const; + void setHedgehogName(int index, const QString & name); + void setHedgehogHat(int index, const QString & hat); + // increments for statistical info void incRounds(); void incWins(); - // convert team info into strings for further computation - QStringList teamGameConfig(quint32 InitHealth) const; - // comparison operators bool operator == (const HWTeam& t1) const; bool operator < (const HWTeam& t1) const; @@ -106,32 +98,10 @@ void setColor(int color); private: - - QString OldTeamName; + QString m_oldTeamName; // class members that contain the general team info and settings - QString m_name; - QString m_grave; - QString m_fort; - QString m_flag; - QString m_voicepack; - QList m_hedgehogs; - quint8 m_difficulty; - QList m_binds; - flib_team * m_team; - - // class members that contain info for the current game setup - quint8 m_numHedgehogs; - int m_color; - bool m_isNetTeam; - QString m_owner; - - // class members that contain statistics, etc. - unsigned int m_campaignProgress; - unsigned int m_rounds; - unsigned int m_wins; - unsigned int AchievementProgress[MAX_ACHIEVEMENTS]; }; #endif diff -r 0e6fadf81a2c -r c247346d296f QTfrontend/ui/page/pageeditteam.cpp --- a/QTfrontend/ui/page/pageeditteam.cpp Sun Nov 25 01:13:51 2012 +0400 +++ b/QTfrontend/ui/page/pageeditteam.cpp Sun Nov 25 22:17:11 2012 +0400 @@ -412,14 +412,13 @@ for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { - HWHog hh = team.hedgehog(i); - - HHNameEdit[i]->setText(hh.Name); + HHNameEdit[i]->setText(team.hedgehogName(i)); - if (hh.Hat.startsWith("Reserved")) - hh.Hat = "Reserved "+hh.Hat.remove(0,40); + QString hat = team.hedgehogHat(i); + if (hat.startsWith("Reserved")) + hat = "Reserved " + hat.mid(40); - HHHats[i]->setCurrentIndex(HHHats[i]->findData(hh.Hat, Qt::DisplayRole)); + HHHats[i]->setCurrentIndex(HHHats[i]->findData(hat, Qt::DisplayRole)); } CBGrave->setCurrentIndex(CBGrave->findText(team.grave())); @@ -447,14 +446,13 @@ for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { - HWHog hh; - hh.Name = HHNameEdit[i]->text(); - hh.Hat = HHHats[i]->currentText(); + QString hat = HHHats[i]->currentText(); - if (hh.Hat.startsWith("Reserved")) - hh.Hat = "Reserved"+m_playerHash+hh.Hat.remove(0,9); + if (hat.startsWith("Reserved")) + hat = "Reserved" + m_playerHash + hat.mid(9); - team.setHedgehog(i,hh); + team.setHedgehogName(i, HHNameEdit[i]->text()); + team.setHedgehogHat(i, hat); } team.setGrave(CBGrave->currentText()); diff -r 0e6fadf81a2c -r c247346d296f QTfrontend/util/namegen.cpp --- a/QTfrontend/util/namegen.cpp Sun Nov 25 01:13:51 2012 +0400 +++ b/QTfrontend/util/namegen.cpp Sun Nov 25 22:17:11 2012 +0400 @@ -64,24 +64,20 @@ if ((TypesHatnames[kind].size()) <= 0) { - dicts = dictsForHat(team.hedgehog(0).Hat); + dicts = dictsForHat(team.hedgehogHat(0)); dict = dictContents(dicts[rand()%(dicts.size())]); } for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { if ((TypesHatnames[kind].size()) > 0) - { - HWHog hh = team.hedgehog(i); - hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())]; - team.setHedgehog(i,hh); - } + team.setHedgehogHat(i, TypesHatnames[kind][rand()%(TypesHatnames[kind].size())]); // there is a chance that this hog has the same hat as the previous one // let's reuse the hat-specific dict in this case - if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat)) + if ((i == 0) || (team.hedgehogHat(i) != team.hedgehogHat(i-1))) { - dicts = dictsForHat(team.hedgehog(i).Hat); + dicts = dictsForHat(team.hedgehogHat(i)); dict = dictContents(dicts[rand()%(dicts.size())]); } @@ -93,7 +89,7 @@ void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber) { - QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat); + QStringList dicts = dictsForHat(team.hedgehogHat(HedgehogNumber)); QStringList dict = dictContents(dicts[rand()%(dicts.size())]); @@ -106,18 +102,14 @@ for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { - namesDict.removeOne(team.hedgehog(i).Name); + namesDict.removeOne(team.hedgehogName(i)); } // if our dict doesn't have any new names we'll have to use duplicates if (namesDict.size() < 1) namesDict = dict; - HWHog hh = team.hedgehog(HedgehogNumber); - - hh.Name = namesDict[rand()%(namesDict.size())]; - - team.setHedgehog(HedgehogNumber, hh); + team.setHedgehogName(HedgehogNumber, namesDict[rand()%(namesDict.size())]); } QStringList HWNamegen::dictContents(const QString filename)