- Many improvements to frontend
- Small optimization of generating random data in uRandom.pas
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/QTfrontend.pro Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,15 @@
+######################################################################
+# Automatically generated by qmake (2.00a) ?? 5. ??? 13:58:32 2005
+######################################################################
+
+TEMPLATE = app
+TARGET +=
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QT += network
+
+# Input
+HEADERS += binds.h game.h hwform.h sdlkeys.h team.h rndstr.h sha1.h
+FORMS += hwform.ui
+SOURCES += game.cpp main.cpp hwform.cpp team.cpp rndstr.cpp sha1.cpp
--- a/QTfrontend/game.cpp Wed Nov 09 18:31:11 2005 +0000
+++ b/QTfrontend/game.cpp Sun Nov 13 22:13:58 2005 +0000
@@ -54,6 +54,7 @@
connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
IPCSocket = 0;
TeamCount = 0;
+ seed = "seed";
}
void HWGame::NewConnection()
@@ -162,7 +163,8 @@
readbytes = IPCSocket->read((char *)&msgsize, 1);
} else
{
- msgbufsize += readbytes = IPCSocket->read((char *)&msgbuf[msgbufsize], msgsize - msgbufsize);
+ msgbufsize +=
+ readbytes = IPCSocket->read((char *)&msgbuf[msgbufsize], msgsize - msgbufsize);
if (msgbufsize = msgsize)
{
ParseMessage();
@@ -172,22 +174,23 @@
}
}
-void HWGame::Start(int Resolution)
+void HWGame::Start(int Resolution, bool Fullscreen)
{
if (TeamCount < 2) return;
QProcess * process;
QStringList arguments;
+ seedgen.GenRNDStr(seed, 10);
process = new QProcess;
arguments << resolutions[0][Resolution];
arguments << resolutions[1][Resolution];
arguments << "avematan";
arguments << "46631";
- arguments << "=seed=";
- arguments << "1";
+ arguments << seed;
+ arguments << (Fullscreen ? "1" : "0");
process->start("hw", arguments);
}
-void HWGame::AddTeam(const QString teamname)
+void HWGame::AddTeam(const QString & teamname)
{
if (TeamCount == 5) return;
teams[TeamCount] = teamname;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/game.h Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,80 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GAME_H
+#define GAME_H
+
+#include <QObject>
+#include <QDialog>
+#include <QTcpServer>
+#include <QTcpSocket>
+#include <QByteArray>
+#include "team.h"
+#include "rndstr.h"
+
+#define IPC_PORT 46631
+#define MAXMSGCHARS 255
+#define SENDIPC(a) SendIPC(a, sizeof(a) - 1)
+
+class HWGame : public QDialog
+{
+ Q_OBJECT
+public:
+ HWGame();
+ void Start(int Resolution, bool Fullscreen);
+ void AddTeam(const QString & team);
+
+private:
+ QTcpServer * IPCServer;
+ QTcpSocket * IPCSocket;
+ char msgbuf[MAXMSGCHARS];
+ unsigned char msgbufsize;
+ unsigned char msgsize;
+ QString teams[5];
+ QString seed;
+ int TeamCount;
+ RNDStr seedgen;
+
+ void SendConfig();
+ void SendTeamConfig(int index);
+ void ParseMessage();
+ void SendIPC(const char* msg, unsigned char len);
+ void SendIPC(const QByteArray buf);
+
+private slots:
+ void NewConnection();
+ void ClientDisconnect();
+ void ClientRead();
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/hwconsts.h Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,40 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+const char resolutions[2][4][5] =
+{
+ {"640", "800", "1024", "1280"},
+ {"480", "600", "768", "1024"}
+};
+
+#define DATA_PATH "Data"
--- a/QTfrontend/hwform.cpp Wed Nov 09 18:31:11 2005 +0000
+++ b/QTfrontend/hwform.cpp Sun Nov 13 22:13:58 2005 +0000
@@ -104,6 +104,13 @@
}
cfgdir.cd(".hedgewars");
+ list = cfgdir.entryList(QStringList("*.cfg"));
+ for (QStringList::Iterator it = list.begin(); it != list.end(); ++it )
+ {
+ ui.CBTeamName->addItem((*it).replace(QRegExp("^(.*).cfg"), "\\1"));
+ }
+
+
QFile settings(cfgdir.absolutePath() + "/options");
if (!settings.open(QIODevice::ReadOnly))
{
@@ -161,24 +168,27 @@
void HWForm::NewTeam()
{
- HWTeam tmpTeam(this);
- tmpTeam.ToPage();
+ tmpTeam = new HWTeam();
+ tmpTeam->SetCfgDir(cfgdir.absolutePath());
+ tmpTeam->SetToPage(this);
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
}
void HWForm::EditTeam()
{
- HWTeam tmpTeam(this);
- tmpTeam.LoadFromFile(cfgdir.absolutePath() + "/team.cfg");
- tmpTeam.ToPage();
+ tmpTeam = new HWTeam();
+ tmpTeam->SetCfgDir(cfgdir.absolutePath());
+ tmpTeam->LoadFromFile();
+ tmpTeam->SetToPage(this);
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
}
void HWForm::TeamSave()
{
- HWTeam tmpTeam(this);
- tmpTeam.FromPage();
- tmpTeam.SaveToFile(cfgdir.absolutePath() + "/team.cfg");
+ tmpTeam = new HWTeam();
+ tmpTeam->GetFromPage(this);
+ tmpTeam->SaveToFile();
+ delete tmpTeam;
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
}
@@ -192,7 +202,7 @@
game = new HWGame();
game->AddTeam(cfgdir.absolutePath() + "/team.cfg");
game->AddTeam(cfgdir.absolutePath() + "/team.cfg");
- game->Start(ui.CBResolution->currentIndex());
+ game->Start(ui.CBResolution->currentIndex(), ui.CBFullscreen->isChecked());
}
void HWForm::CBGrave_activated(const QString & gravename)
--- a/QTfrontend/hwform.h Wed Nov 09 18:31:11 2005 +0000
+++ b/QTfrontend/hwform.h Sun Nov 13 22:13:58 2005 +0000
@@ -40,6 +40,7 @@
#include "ui_hwform.h"
#include "binds.h"
#include "game.h"
+#include "team.h"
class HWForm : public QMainWindow
{
@@ -71,6 +72,7 @@
QLabel * LBind[BINDS_NUMBER];
HWGame * game;
QDir cfgdir;
+ HWTeam * tmpTeam;
};
#define ID_PAGE_MAIN 4
--- a/QTfrontend/hwform.ui Wed Nov 09 18:31:11 2005 +0000
+++ b/QTfrontend/hwform.ui Sun Nov 13 22:13:58 2005 +0000
@@ -50,7 +50,7 @@
</size>
</property>
<property name="currentIndex" >
- <number>2</number>
+ <number>1</number>
</property>
<widget class="QWidget" name="page" >
<widget class="QPushButton" name="BtnSPBack" >
@@ -115,19 +115,6 @@
</widget>
</widget>
<widget class="QWidget" name="page" >
- <widget class="QGroupBox" name="GBoxTeam" >
- <property name="geometry" >
- <rect>
- <x>20</x>
- <y>10</y>
- <width>161</width>
- <height>51</height>
- </rect>
- </property>
- <property name="title" >
- <string>Team</string>
- </property>
- </widget>
<widget class="QPushButton" name="BtnTeamSave" >
<property name="geometry" >
<rect>
@@ -307,6 +294,72 @@
</property>
</widget>
</widget>
+ <widget class="QGroupBox" name="GBoxTeam" >
+ <property name="geometry" >
+ <rect>
+ <x>20</x>
+ <y>10</y>
+ <width>161</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="title" >
+ <string>Team</string>
+ </property>
+ </widget>
+ <widget class="QGroupBox" name="GBoxPlayer" >
+ <property name="geometry" >
+ <rect>
+ <x>20</x>
+ <y>340</y>
+ <width>161</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="title" >
+ <string>Player</string>
+ </property>
+ <widget class="QComboBox" name="comboBox" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>20</y>
+ <width>141</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Human</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>CPU level 1</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>CPU level 2</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>CPU level 3</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>CPU level 4</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>CPU level 5</string>
+ </property>
+ </item>
+ </widget>
+ </widget>
</widget>
<widget class="QWidget" name="page" >
<widget class="QGroupBox" name="groupBox" >
@@ -321,16 +374,6 @@
<property name="title" >
<string>Teams</string>
</property>
- <widget class="QComboBox" name="CBTeamName" >
- <property name="geometry" >
- <rect>
- <x>200</x>
- <y>30</y>
- <width>171</width>
- <height>22</height>
- </rect>
- </property>
- </widget>
<widget class="QPushButton" name="BtnNewTeam" >
<property name="geometry" >
<rect>
@@ -379,6 +422,16 @@
<string>Edit team</string>
</property>
</widget>
+ <widget class="QComboBox" name="CBTeamName" >
+ <property name="geometry" >
+ <rect>
+ <x>200</x>
+ <y>30</y>
+ <width>171</width>
+ <height>22</height>
+ </rect>
+ </property>
+ </widget>
</widget>
<widget class="QComboBox" name="CBResolution" >
<property name="geometry" >
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/main.cpp Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,43 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <QApplication>
+#include "hwform.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ HWForm *Form = new HWForm;
+ Form->show();
+ return app.exec();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/rndstr.cpp Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,67 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <QDateTime>
+#include "rndstr.h"
+
+const char * letters = "qwertyuiopasdfghjklzxcvbnm" \
+ "QWERTYUIOPASDFGHJKLZXCVBNM" \
+ "0123456789";
+const quint8 letterscnt = 62;
+
+const char * upd = "/hw!/";
+const quint8 updcnt = 5;
+
+RNDStr::RNDStr()
+{
+ SHA1Init(&ctx);
+ QDateTime now = QDateTime::currentDateTime();
+ QDateTime zero;
+ int secs = now.secsTo(zero);
+ SHA1Update(&ctx, (quint8 *)&secs, sizeof(int));
+}
+
+void RNDStr::GenRNDStr(QString & str, quint32 len)
+{
+ str = "";
+ sha1_ctxt tmpctx;
+ caddr_t digest;
+ for(quint32 i = 0; i < len; i++)
+ {
+ SHA1Update(&ctx, (quint8 *)upd, updcnt);
+ qMemCopy(&tmpctx, &ctx, sizeof(sha1_ctxt));
+ SHA1Final(digest, &tmpctx);
+ int index = (digest[3] + digest[11] + digest[17]) % letterscnt;
+ str += letters[index];
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/rndstr.h Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,50 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RNDGEN_H
+#define RNDGEN_H
+
+#include <QString>
+#include "sha1.h"
+
+class RNDStr
+{
+public:
+ RNDStr();
+
+ void GenRNDStr(QString & str, quint32 len);
+private:
+ sha1_ctxt ctx;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/sdlkeys.h Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,163 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+char sdlkeys[][2][16] =
+{
+ {"mousel", "mousel"},
+ {"mousem", "mousem"},
+ {"mouser", "mouser"},
+ {"backspace", "backspace"},
+ {"tab", "tab"},
+ {"clear", "clear"},
+ {"return", "return"},
+ {"pause", "pause"},
+ {"escape", "escape"},
+ {"space", "space"},
+ {"!", "!"},
+ {"\"", "\""},
+ {"#", "#"},
+ {"$", "$"},
+ {"&", "&"},
+ {"'", "'"},
+ {"(", "("},
+ {")", ")"},
+ {"*", "*"},
+ {"+", "+"},
+ {",", ","},
+ {"-", "-"},
+ {".", "."},
+ {"/", "/"},
+ {"0", "0"},
+ {"1", "1"},
+ {"2", "2"},
+ {"3", "3"},
+ {"4", "4"},
+ {"5", "5"},
+ {"6", "6"},
+ {"7", "7"},
+ {"8", "8"},
+ {"9", "9"},
+ {":", ":"},
+ {";", ";"},
+ {"<", "<"},
+ {"=", "="},
+ {">", ">"},
+ {"?", "?"},
+ {"@", "@"},
+ {"[", "["},
+ {"\\", "\\"},
+ {"]", "]"},
+ {"^", "^"},
+ {"_", "_"},
+ {"`", "`"},
+ {"a", "a"},
+ {"b", "b"},
+ {"c", "c"},
+ {"d", "d"},
+ {"e", "e"},
+ {"f", "f"},
+ {"g", "g"},
+ {"h", "h"},
+ {"i", "i"},
+ {"j", "j"},
+ {"k", "k"},
+ {"l", "l"},
+ {"m", "m"},
+ {"n", "n"},
+ {"o", "o"},
+ {"p", "p"},
+ {"q", "q"},
+ {"r", "r"},
+ {"s", "s"},
+ {"t", "t"},
+ {"u", "u"},
+ {"v", "v"},
+ {"w", "w"},
+ {"x", "x"},
+ {"y", "y"},
+ {"z", "z"},
+ {"delete", "delete"},
+ {"[0]", "[0]"},
+ {"[1]", "[1]"},
+ {"[2]", "[2]"},
+ {"[3]", "[3]"},
+ {"[4]", "[4]"},
+ {"[5]", "[5]"},
+ {"[6]", "[6]"},
+ {"[7]", "[7]"},
+ {"[8]", "[8]"},
+ {"[9]", "[9]"},
+ {"[.]", "[.]"},
+ {"[/]", "[/]"},
+ {"[*]", "[*]"},
+ {"[-]", "[-]"},
+ {"[+]", "[+]"},
+ {"enter", "enter"},
+ {"equals", "equals"},
+ {"up", "up"},
+ {"down", "down"},
+ {"right", "right"},
+ {"left", "left"},
+ {"insert", "insert"},
+ {"home", "home"},
+ {"end", "end"},
+ {"page up", "page up"},
+ {"page down", "page down"},
+ {"f1", "f1"},
+ {"f2", "f2"},
+ {"f3", "f3"},
+ {"f4", "f4"},
+ {"f5", "f5"},
+ {"f6", "f6"},
+ {"f7", "f7"},
+ {"f8", "f8"},
+ {"f9", "f9"},
+ {"f10", "f10"},
+ {"f11", "f11"},
+ {"f12", "f12"},
+ {"f13", "f13"},
+ {"f14", "f14"},
+ {"f15", "f15"},
+ {"numlock", "numlock"},
+ {"caps_lock", "caps_lock"},
+ {"scroll_lock", "scroll_lock"},
+ {"right_shift", "right_shift"},
+ {"left_shift", "left_shift"},
+ {"right_ctrl", "right_ctrl"},
+ {"left_ctrl", "left_ctrl"},
+ {"right_alt", "right_alt"},
+ {"left_alt", "left_alt"},
+ {"right_meta", "right_meta"},
+ {"left_meta", "left_meta"},
+ {"", ""}
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/sha1.cpp Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
+ * based on: http://csrc.nist.gov/fips/fip180-1.txt
+ * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
+ */
+
+#include "sha1.h"
+
+/* constant table */
+static quint32 _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
+#define K(t) _K[(t) / 20]
+
+#define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d)))
+#define F1(b, c, d) (((b) ^ (c)) ^ (d))
+#define F2(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
+#define F3(b, c, d) (((b) ^ (c)) ^ (d))
+
+#define S(n, x) (((x) << (n)) | ((x) >> (32 - n)))
+
+#define H(n) (ctxt->h.b32[(n)])
+#define COUNT (ctxt->count)
+#define BCOUNT (ctxt->c.b64[0] / 8)
+#define W(n) (ctxt->m.b32[(n)])
+
+#define PUTBYTE(x) { \
+ ctxt->m.b8[(COUNT % 64)] = (x); \
+ COUNT++; \
+ COUNT %= 64; \
+ ctxt->c.b64[0] += 8; \
+ if (COUNT % 64 == 0) \
+ sha1_step(ctxt); \
+ }
+
+#define PUTPAD(x) { \
+ ctxt->m.b8[(COUNT % 64)] = (x); \
+ COUNT++; \
+ COUNT %= 64; \
+ if (COUNT % 64 == 0) \
+ sha1_step(ctxt); \
+ }
+
+static void sha1_step(struct sha1_ctxt *);
+
+static void
+sha1_step(struct sha1_ctxt *ctxt)
+{
+ quint32 a, b, c, d, e;
+ size_t t, s;
+ quint32 tmp;
+
+ a = H(0); b = H(1); c = H(2); d = H(3); e = H(4);
+
+ for (t = 0; t < 20; t++) {
+ s = t & 0x0f;
+ if (t >= 16) {
+ W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
+ }
+ tmp = S(5, a) + F0(b, c, d) + e + W(s) + K(t);
+ e = d; d = c; c = S(30, b); b = a; a = tmp;
+ }
+ for (t = 20; t < 40; t++) {
+ s = t & 0x0f;
+ W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
+ tmp = S(5, a) + F1(b, c, d) + e + W(s) + K(t);
+ e = d; d = c; c = S(30, b); b = a; a = tmp;
+ }
+ for (t = 40; t < 60; t++) {
+ s = t & 0x0f;
+ W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
+ tmp = S(5, a) + F2(b, c, d) + e + W(s) + K(t);
+ e = d; d = c; c = S(30, b); b = a; a = tmp;
+ }
+ for (t = 60; t < 80; t++) {
+ s = t & 0x0f;
+ W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
+ tmp = S(5, a) + F3(b, c, d) + e + W(s) + K(t);
+ e = d; d = c; c = S(30, b); b = a; a = tmp;
+ }
+
+ H(0) = H(0) + a;
+ H(1) = H(1) + b;
+ H(2) = H(2) + c;
+ H(3) = H(3) + d;
+ H(4) = H(4) + e;
+
+ qMemSet(&ctxt->m.b8[0], 0, 64);
+}
+
+/*------------------------------------------------------------*/
+
+void sha1_init(struct sha1_ctxt *ctxt)
+{
+ qMemSet(ctxt, 0, sizeof(struct sha1_ctxt));
+ H(0) = 0x67452301;
+ H(1) = 0xefcdab89;
+ H(2) = 0x98badcfe;
+ H(3) = 0x10325476;
+ H(4) = 0xc3d2e1f0;
+}
+
+void sha1_pad(struct sha1_ctxt *ctxt)
+{
+ size_t padlen; /*pad length in bytes*/
+ size_t padstart;
+
+ PUTPAD(0x80);
+
+ padstart = COUNT % 64;
+ padlen = 64 - padstart;
+ if (padlen < 8) {
+ qMemSet(&ctxt->m.b8[padstart], 0, padlen);
+ COUNT += padlen;
+ COUNT %= 64;
+ sha1_step(ctxt);
+ padstart = COUNT % 64; /* should be 0 */
+ padlen = 64 - padstart; /* should be 64 */
+ }
+ qMemSet(&ctxt->m.b8[padstart], 0, padlen - 8);
+ COUNT += (padlen - 8);
+ COUNT %= 64;
+ PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
+ PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
+ PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
+ PUTPAD(ctxt->c.b8[6]); PUTPAD(ctxt->c.b8[7]);
+}
+
+void sha1_loop(struct sha1_ctxt *ctxt, const quint8 *input, size_t len)
+{
+ size_t gaplen;
+ size_t gapstart;
+ size_t off;
+ size_t copysiz;
+
+ off = 0;
+
+ while (off < len) {
+ gapstart = COUNT % 64;
+ gaplen = 64 - gapstart;
+
+ copysiz = (gaplen < len - off) ? gaplen : len - off;
+ qMemCopy(&ctxt->m.b8[gapstart], &input[off], copysiz);
+ COUNT += copysiz;
+ COUNT %= 64;
+ ctxt->c.b64[0] += copysiz * 8;
+ if (COUNT % 64 == 0)
+ sha1_step(ctxt);
+ off += copysiz;
+ }
+}
+
+void sha1_result(struct sha1_ctxt *ctxt, caddr_t digest0)
+{
+ quint8 *digest;
+
+ digest = (quint8 *)digest0;
+ sha1_pad(ctxt);
+ qMemCopy(digest, &ctxt->h.b8[0], 20);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/sha1.h Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
+ * based on: http://csrc.nist.gov/fips/fip180-1.txt
+ * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
+ */
+
+#include <qglobal.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef unsigned char caddr_t[20];
+
+struct sha1_ctxt {
+ union {
+ quint8 b8[20];
+ quint32 b32[5];
+ } h;
+ union {
+ quint8 b8[8];
+ quint64 b64[1];
+ } c;
+ union {
+ quint8 b8[64];
+ quint32 b32[16];
+ } m;
+ quint8 count;
+};
+
+void sha1_init(struct sha1_ctxt *ctxt);
+void sha1_pad(struct sha1_ctxt *ctxt);
+extern void sha1_loop(struct sha1_ctxt *ctxt, const quint8 *input, size_t len);
+extern void sha1_result(struct sha1_ctxt *ctxt, caddr_t digest0);
+#ifdef __cplusplus
+}
+#endif
+
+#define SHA1Init(x) sha1_init((x))
+#define SHA1Update(x, y, z) sha1_loop((x), (y), (z))
+#define SHA1Final(x, y) sha1_result((y), (x))
+
--- a/QTfrontend/team.cpp Wed Nov 09 18:31:11 2005 +0000
+++ b/QTfrontend/team.cpp Sun Nov 13 22:13:58 2005 +0000
@@ -36,24 +36,23 @@
#include "team.h"
#include "hwform.h"
-HWTeam::HWTeam(HWForm * hwform)
+HWTeam::HWTeam()
{
TeamName = "unnamed";
for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
Grave = "Simple";
Fort = "Barrelhouse";
- form = hwform;
for(int i = 0; i < BINDS_NUMBER; i++)
{
binds[i].action = cbinds[i].action;
binds[i].strbind = cbinds[i].strbind;
}
-
+ dir = "";
}
-bool HWTeam::LoadFromFile(const QString & filename)
+bool HWTeam::LoadFromFile()
{
- QFile cfgfile(filename);
+ QFile cfgfile(dir + "/" + TeamName + ".cfg");
if (!cfgfile.open(QIODevice::ReadOnly)) return false;
QTextStream stream(&cfgfile);
stream.setCodec("UTF-8");
@@ -105,9 +104,9 @@
return true;
}
-bool HWTeam::SaveToFile(const QString & filename)
+bool HWTeam::SaveToFile()
{
- QFile cfgfile(filename);
+ QFile cfgfile(dir + "/" + TeamName + ".cfg");
if (!cfgfile.open(QIODevice::WriteOnly)) return false;
QTextStream stream(&cfgfile);
stream.setCodec("UTF-8");
@@ -125,7 +124,7 @@
return true;
}
-void HWTeam::ToPage()
+void HWTeam::SetToPage(HWForm * hwform)
{
form->TeamNameEdit->setText(TeamName);
for(int i = 0; i < 8; i++)
@@ -144,7 +143,7 @@
}
}
-void HWTeam::FromPage()
+void HWTeam::GetFromPage(HWForm * hwform)
{
TeamName = form->TeamNameEdit->text();
for(int i = 0; i < 8; i++)
@@ -159,3 +158,8 @@
binds[i].strbind = form->CBBind[i]->currentText();
}
}
+
+void HWTeam::SetCfgDir(const QString & dir)
+{
+ this->dir = dir;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/team.h Sun Nov 13 22:13:58 2005 +0000
@@ -0,0 +1,62 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * Distributed under the terms of the BSD-modified licence:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * with the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TEAM_H
+#define TEAM_H
+
+#include <QString>
+#include "binds.h"
+
+class HWForm;
+class HWTeam
+{
+ public:
+ HWTeam();
+
+ HWForm * form;
+ QString TeamName;
+ QString HHName[8];
+ QString Grave;
+ QString Fort;
+ QString dir;
+ BindAction binds[BINDS_NUMBER];
+
+ void SetCfgDir(const QString & dir);
+ bool LoadFromFile();
+ bool SaveToFile();
+ void SetToPage(HWForm * hwform);
+ void GetFromPage(HWForm * hwform);
+ private:
+};
+
+#endif
--- a/hedgewars/uRandom.pas Wed Nov 09 18:31:11 2005 +0000
+++ b/hedgewars/uRandom.pas Sun Nov 13 22:13:58 2005 +0000
@@ -55,11 +55,10 @@
begin
SHA1Update(sc1, @Fill[1], Length(Fill));
sc2:= sc1;
-dig:= SHA1Final(sc1);
+dig:= SHA1Final(sc2);
Result:= frac( dig.LongWords[0]*0.0000731563977
+ pi * dig.Words[6]
- + 0.0109070019*dig.Words[9]);
-sc1:= sc2
+ + 0.0109070019*dig.Words[9])
end;
function GetRandom(m: LongWord): LongWord;