# HG changeset patch # User unc0rr # Date 1156684600 0 # Node ID ca70467bd0a860075b05d281145771a377bbe84c # Parent 93df479aa1b99363be854193b7c141789f044110 Use QUuid to generate seed, rand() to choose theme diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/CMakeLists.txt --- 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 diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/game.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 #include #include +#include #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(); } diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/game.h --- 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 #include #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(); diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/gameuiconfig.cpp --- 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"); +} diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/gameuiconfig.h --- 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 diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/hedgewars.pro --- 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 \ diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/main.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 #include #include +#include #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(); diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/netclient.cpp --- 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 + * Copyright (c) 2005, 2006 Andrey Korotaev * * Distributed under the terms of the BSD-modified licence: * @@ -32,8 +32,10 @@ */ #include +#include #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); diff -r 93df479aa1b9 -r ca70467bd0a8 QTfrontend/netclient.h --- 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 #include #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;