- HWMapContainer sets and stores the theme
- Fix indefinite loop when seed has zero length
- Slots to set config options to GameCFGWidget
--- a/QTfrontend/gamecfgwidget.cpp Thu Jan 11 23:29:57 2007 +0000
+++ b/QTfrontend/gamecfgwidget.cpp Fri Jan 12 15:23:16 2007 +0000
@@ -108,13 +108,39 @@
sl.append("eseed " + getCurrentSeed());
sl.append(QString("e$gmflags %1").arg(getGameFlags()));
sl.append(QString("e$turntime %1").arg(getTurnTime() * 1000));
- try {
- QString currentMap = getCurrentMap();
+ QString currentMap = getCurrentMap();
+ if (currentMap.size() > 0)
sl.append("emap " + currentMap);
- sl.append("etheme " + getCurrentTheme());
- }
- catch(const MapFileErrorException& e) {
- sl.append(QString("etheme %1").arg("steel"));
- }
+ sl.append("etheme " + getCurrentTheme());
return sl;
}
+
+void GameCFGWidget::setSeed(const QString & seed)
+{
+ pMapContainer->setSeed(seed);
+}
+
+void GameCFGWidget::setMap(const QString & map)
+{
+ pMapContainer->setMap(map);
+}
+
+void GameCFGWidget::setTheme(const QString & theme)
+{
+ pMapContainer->setTheme(theme);
+}
+
+void GameCFGWidget::setInitHealth(const quint32 health)
+{
+ SB_InitHealth->setValue(health);
+}
+
+void GameCFGWidget::setTurnTime(const quint32 time)
+{
+ SB_TurnTime->setValue(time);
+}
+
+void GameCFGWidget::setFortsMode(const bool value)
+{
+ CB_mode_Forts->setChecked(value);
+}
--- a/QTfrontend/gamecfgwidget.h Thu Jan 11 23:29:57 2007 +0000
+++ b/QTfrontend/gamecfgwidget.h Fri Jan 12 15:23:16 2007 +0000
@@ -43,7 +43,13 @@
quint32 getTurnTime() const;
QStringList getFullConfig() const;
-private slots:
+public slots:
+ void setSeed(const QString & seed);
+ void setMap(const QString & map);
+ void setTheme(const QString & theme);
+ void setInitHealth(const quint32 health);
+ void setTurnTime(const quint32 time);
+ void setFortsMode(const bool value);
private:
QCheckBox * CB_mode_Forts;
--- a/QTfrontend/gameuiconfig.cpp Thu Jan 11 23:29:57 2007 +0000
+++ b/QTfrontend/gameuiconfig.cpp Fri Jan 12 15:23:16 2007 +0000
@@ -38,19 +38,6 @@
Form->ui.pageNet->editIP->setText(value("net/ip", "").toString());
Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool());
Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt());
-
- QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
- if (themesfile.open(QIODevice::ReadOnly)) {
- QTextStream stream(&themesfile);
- QString str;
- while (!stream.atEnd())
- {
- Themes << stream.readLine();
- }
- themesfile.close();
- } else {
- QMessageBox::critical(FormWidgets, "Error", "Cannot access themes.cfg", "OK");
- }
}
QStringList GameUIConfig::GetTeamsList()
@@ -102,8 +89,3 @@
{
return 35 - Form->ui.pageOptions->fpsedit->value();
}
-
-QString GameUIConfig::GetRandomTheme()
-{
- return (Themes.size() > 0) ? Themes[rand() % Themes.size()] : QString("steel");
-}
--- a/QTfrontend/gameuiconfig.h Thu Jan 11 23:29:57 2007 +0000
+++ b/QTfrontend/gameuiconfig.h Fri Jan 12 15:23:16 2007 +0000
@@ -38,7 +38,6 @@
bool isSoundEnabled();
bool isShowFPSEnabled();
quint8 timerInterval();
- QString GetRandomTheme();
private slots:
@@ -47,7 +46,6 @@
private:
HWForm * Form;
- QStringList Themes;
};
#endif
--- a/QTfrontend/mapContainer.cpp Thu Jan 11 23:29:57 2007 +0000
+++ b/QTfrontend/mapContainer.cpp Fri Jan 12 15:23:16 2007 +0000
@@ -33,12 +33,12 @@
QWidget(parent), mainLayout(this)
{
imageButt=new QPushButton(this);
- imageButt->setMaximumSize(256, 128);
+ imageButt->setFixedSize(256, 128);
imageButt->setFlat(true);
imageButt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
mainLayout.addWidget(imageButt);
- connect(imageButt, SIGNAL(clicked()), this, SLOT(changeImage()));
- changeImage();
+ connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed()));
+ setRandomSeed();
chooseMap=new QComboBox(this);
QDir tmpdir;
@@ -82,20 +82,26 @@
}
QPixmap mapImage;
- if(!mapImage.load(datadir->absolutePath()+"/Maps/"+chooseMap->currentText()+"/map.png")) {
+ if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/map.png")) {
changeImage();
chooseMap->setCurrentIndex(0);
return;
}
- imageButt->setIcon(mapImage.scaled(256,128));
+ imageButt->setIcon(mapImage.scaled(256, 128));
+ QFile mapCfgFile(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/map.cfg");
+ if (mapCfgFile.open(QFile::ReadOnly)) {
+ QTextStream input(&mapCfgFile);
+ input >> theme;
+ mapCfgFile.close();
+ }
}
void HWMapContainer::changeImage()
{
- pMap=new HWMap();
+ pMap = new HWMap();
connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage)));
- m_seed = QUuid::createUuid().toString();
pMap->getImage(m_seed.toStdString());
+ theme = (Themes->size() > 0) ? Themes->at(rand() % Themes->size()) : "steel";
}
QString HWMapContainer::getCurrentSeed() const
@@ -105,27 +111,38 @@
QString HWMapContainer::getCurrentMap() const
{
- if(!chooseMap->currentIndex()) throw MapFileErrorException();
+ if(!chooseMap->currentIndex()) return QString();
return chooseMap->currentText();
}
QString HWMapContainer::getCurrentTheme() const
{
- if(!chooseMap->currentIndex()) throw MapFileErrorException();
- QFile mapCfgFile(datadir->absolutePath()+"/Maps/"+chooseMap->currentText()+"/map.cfg");
- if (mapCfgFile.open(QFile::ReadOnly)) {
- QTextStream input(&mapCfgFile);
- QString theme;
- input >> theme;
- mapCfgFile.close();
- if(theme.length()>256) throw MapFileErrorException(); // theme name too long
- return theme;
- } else {
- throw MapFileErrorException();
- }
+ return theme;
}
void HWMapContainer::resizeEvent ( QResizeEvent * event )
{
//imageButt->setIconSize(imageButt->size());
}
+
+void HWMapContainer::setSeed(const QString & seed)
+{
+ m_seed = seed;
+ changeImage();
+}
+
+void HWMapContainer::setMap(const QString & map)
+{
+
+}
+
+void HWMapContainer::setTheme(const QString & theme)
+{
+ this->theme = theme;
+}
+
+void HWMapContainer::setRandomSeed()
+{
+ m_seed = QUuid::createUuid().toString();
+ changeImage();
+}
--- a/QTfrontend/mapContainer.h Thu Jan 11 23:29:57 2007 +0000
+++ b/QTfrontend/mapContainer.h Fri Jan 12 15:23:16 2007 +0000
@@ -34,7 +34,7 @@
class HWMapContainer : public QWidget
{
Q_OBJECT
-
+
public:
HWMapContainer(QWidget * parent=0);
QString getCurrentSeed() const;
@@ -43,10 +43,14 @@
public slots:
void changeImage();
+ void setSeed(const QString & seed);
+ void setMap(const QString & map);
+ void setTheme(const QString & theme);
private slots:
void setImage(const QImage newImage);
void mapChanged(int index);
+ void setRandomSeed();
protected:
virtual void resizeEvent ( QResizeEvent * event );
@@ -57,6 +61,7 @@
QComboBox* chooseMap;
HWMap* pMap;
QString m_seed;
+ QString theme;
};
#endif // _HWMAP_CONTAINER_INCLUDED
--- a/QTfrontend/netclient.cpp Thu Jan 11 23:29:57 2007 +0000
+++ b/QTfrontend/netclient.cpp Fri Jan 12 15:23:16 2007 +0000
@@ -346,7 +346,7 @@
QByteArray cache;
HWProto::addStringToBuffer(cache, "eseed " + seed);
HWProto::addStringToBuffer(cache, "e$gmflags 0");
- HWProto::addStringToBuffer(cache, QString("etheme %1").arg(config->GetRandomTheme()));
+ HWProto::addStringToBuffer(cache, QString("etheme steel"));
QString _msg = MAGIC_CHAR MAGIC_CHAR + QString(cache.toBase64());
RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, _msg));
hwp_chanmsg(mynick, _msg);
--- a/QTfrontend/newnetclient.cpp Thu Jan 11 23:29:57 2007 +0000
+++ b/QTfrontend/newnetclient.cpp Fri Jan 12 15:23:16 2007 +0000
@@ -130,7 +130,7 @@
void HWNewNet::ParseLine(const QByteArray & line)
{
QString msg = QString::fromUtf8 (line.data(), line.size());
-
+
qDebug() << "line " << msg << " received";
QStringList lst = msg.split(delimeter);
@@ -155,14 +155,14 @@
ConfigAsked();
return;
}
-
+
if (lst[0] == "CONFIGURED") {
lst.pop_front();
RunGame();
qDebug() << lst[0];
QByteArray ar=QByteArray::fromBase64(lst[0].toAscii());
emit FromNet(ar);
-
+
lst.pop_front();
QByteArray cache;
emit FromNet(HWProto::addStringListToBuffer(cache, lst));
@@ -181,7 +181,7 @@
HWProto::addStringToBuffer(cache, "eseed " + seed);
HWProto::addStringToBuffer(cache, "TN");
HWProto::addStringToBuffer(cache, "e$gmflags 0");
- HWProto::addStringToBuffer(cache, QString("etheme %1").arg(config->GetRandomTheme()));
+ HWProto::addStringToBuffer(cache, QString("etheme steel"));
QString _msg = QString("CONFIGANSWER") + delimeter + QString(cache.toBase64());
RawSendNet(_msg);
}
--- a/hedgewars/uRandom.pas Thu Jan 11 23:29:57 2007 +0000
+++ b/hedgewars/uRandom.pas Fri Jan 12 15:23:16 2007 +0000
@@ -46,8 +46,8 @@
if Length(Seed) > 54 then Seed:= copy(Seed, 1, 54); // not 55 to ensure we have odd numbers in cirbuf
-for i:= 0 to pred(Length(Seed)) do
- cirbuf[i]:= byte(Seed[i + 1]) * (i + 1);
+for i:= 1 to Length(Seed) do
+ cirbuf[i - 1]:= byte(Seed[i]) * i;
for i:= Length(Seed) to 54 do
cirbuf[i]:= i * 7 + 1;