--- a/QTfrontend/CMakeLists.txt Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/CMakeLists.txt Sun Aug 27 13:16:40 2006 +0000
@@ -16,8 +16,6 @@
main.cpp
hwform.cpp
team.cpp
- rndstr.cpp
- sha1.cpp
netclient.cpp
teamselect.cpp
teamselhelper.cpp
--- a/QTfrontend/game.cpp Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/game.cpp Sun Aug 27 13:16:40 2006 +0000
@@ -38,6 +38,7 @@
#include <QByteArray>
#include <QFile>
#include <QTextStream>
+#include <QUuid>
#include "game.h"
#include "hwconsts.h"
@@ -86,7 +87,7 @@
void HWGame::SendConfig()
{
SendIPC(QString("eseed %1").arg(seed));
- SendIPC(QString("etheme %1").arg(GetThemeBySeed()));
+ SendIPC(QString("etheme %1").arg(config->GetRandomTheme()));
SENDIPC("TL");
SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()));
SENDIPC("eaddteam");
@@ -256,39 +257,6 @@
TeamCount++;
}
-QString HWGame::GetThemeBySeed()
-{
- QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
- QStringList themes;
- if (themesfile.open(QIODevice::ReadOnly))
- {
- QTextStream stream(&themesfile);
- QString str;
- while (!stream.atEnd())
- {
- themes << stream.readLine();
- }
- themesfile.close();
- }
- quint32 len = themes.size();
- if (len == 0)
- {
- QMessageBox::critical(0, "Error", "Cannot access themes.cfg or bad data", "OK");
- return "avematan";
- }
- if (seed.isEmpty())
- {
- QMessageBox::critical(0, "Error", "seed not defined", "OK");
- return "avematan";
- }
- quint32 k = 0;
- for (int i = 0; i < seed.length(); i++)
- {
- k += seed[i].cell();
- }
- return themes[k % len];
-}
-
void HWGame::SaveDemo(const QString & filename)
{
QFile demofile(filename);
@@ -346,14 +314,14 @@
{
gameType = gtLocal;
if (TeamCount < 2) return;
- seedgen.GenRNDStr(seed, 10);
+ seed = QUuid::createUuid().toString();
Start();
}
void HWGame::StartQuick()
{
gameType = gtLocal;
- seedgen.GenRNDStr(seed, 10);
+ seed = QUuid::createUuid().toString();
Start();
}
--- a/QTfrontend/game.h Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/game.h Sun Aug 27 13:16:40 2006 +0000
@@ -42,7 +42,6 @@
#include <QDir>
#include <QProcess>
#include "team.h"
-#include "rndstr.h"
#define IPC_PORT 46631
#define MAXMSGCHARS 255
@@ -83,7 +82,6 @@
QString teams[5];
QString seed;
int TeamCount;
- RNDStr seedgen;
QByteArray * demo;
QByteArray toSendBuf;
GameUIConfig * config;
@@ -99,7 +97,6 @@
void SendIPC(const QString & buf);
void RawSendIPC(const QByteArray & buf);
void SaveDemo(const QString & filename);
- QString GetThemeBySeed();
private slots:
void NewConnection();
--- a/QTfrontend/gameuiconfig.cpp Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/gameuiconfig.cpp Sun Aug 27 13:16:40 2006 +0000
@@ -77,6 +77,19 @@
}
settings.close();
}
+
+ 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(0, "Error", "Cannot access themes.cfg", "OK");
+ }
}
QStringList GameUIConfig::GetTeamsList()
@@ -120,3 +133,8 @@
{
return Form->ui.pageOptions->CBEnableSound->isChecked();
}
+
+QString GameUIConfig::GetRandomTheme()
+{
+ return (Themes.size() > 0) ? Themes[rand() % Themes.size()] : QString("steel");
+}
--- a/QTfrontend/gameuiconfig.h Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/gameuiconfig.h Sun Aug 27 13:16:40 2006 +0000
@@ -50,6 +50,7 @@
int vid_Resolution();
bool vid_Fullscreen();
bool isSoundEnabled();
+ QString GetRandomTheme();
private slots:
@@ -58,6 +59,7 @@
private:
HWForm * Form;
+ QStringList Themes;
};
#endif
--- a/QTfrontend/hedgewars.pro Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/hedgewars.pro Sun Aug 27 13:16:40 2006 +0000
@@ -15,8 +15,6 @@
hwform.h \
sdlkeys.h \
team.h \
- rndstr.h \
- sha1.h \
netclient.h \
teamselect.h \
teamselhelper.h \
@@ -33,8 +31,6 @@
main.cpp \
hwform.cpp \
team.cpp \
- rndstr.cpp \
- sha1.cpp \
netclient.cpp \
teamselect.cpp \
teamselhelper.cpp \
--- a/QTfrontend/main.cpp Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/main.cpp Sun Aug 27 13:16:40 2006 +0000
@@ -36,6 +36,7 @@
#include <QLocale>
#include <QMessageBox>
#include <QFileInfo>
+#include <QDateTime>
#include "hwform.h"
#include "hwconsts.h"
@@ -47,6 +48,10 @@
{
QApplication app(argc, argv);
+ QDateTime now = QDateTime::currentDateTime();
+ QDateTime zero;
+ srand(now.secsTo(zero));
+
Q_INIT_RESOURCE(hedgewars);
QTranslator Translator;
@@ -55,7 +60,7 @@
QDir mydir(".");
mydir.cd("bin");
-
+
bindir = new QDir(mydir);
cfgdir = new QDir();
--- a/QTfrontend/netclient.cpp Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/netclient.cpp Sun Aug 27 13:16:40 2006 +0000
@@ -1,6 +1,6 @@
/*
* Hedgewars, a worms-like game
- * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
*
* Distributed under the terms of the BSD-modified licence:
*
@@ -32,8 +32,10 @@
*/
#include <QMessageBox>
+#include <QUuid>
#include "netclient.h"
#include "game.h"
+#include "gameuiconfig.h"
HWNet::HWNet(GameUIConfig * config)
: QObject()
@@ -365,7 +367,7 @@
QByteArray cache;
ADD("eseed " + seed);
ADD("e$gmflags 0");
- ADD("etheme steel");
+ ADD(QString("etheme %1").arg(config->GetRandomTheme()));
QString _msg = MAGIC_CHAR MAGIC_CHAR + QString(cache.toBase64());
RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, _msg));
hwp_chanmsg(mynick, _msg);
@@ -494,7 +496,7 @@
playerscnt = players.size();
configasks = 0;
- seedgen.GenRNDStr(seed, 10);
+ seed = QUuid::createUuid().toString();
QString msg = QString(MAGIC_CHAR"Start!");
RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
hwp_chanmsg(mynick, msg);
--- a/QTfrontend/netclient.h Sun Aug 27 12:41:27 2006 +0000
+++ b/QTfrontend/netclient.h Sun Aug 27 13:16:40 2006 +0000
@@ -40,7 +40,6 @@
#include <QStringList>
#include <QTimer>
#include "team.h"
-#include "rndstr.h"
#define MAGIC_CHAR "\x2f"
@@ -102,7 +101,6 @@
quint32 opCount;
netTeam teams[5];
quint8 teamsCount;
- RNDStr seedgen;
int playerscnt;
int configasks;
QByteArray NetBuffer;