merge
authorkoda
Tue, 21 Jan 2014 22:53:15 +0100
changeset 10040 4ac87acbaed9
parent 10019 c00db97a668f (diff)
parent 10039 58cf89284115 (current diff)
child 10041 82d062e36e96
merge
CMakeLists.txt
gameServer/EngineInteraction.hs
gameServer/HWProtoInRoomState.hs
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsList.pas
hedgewars/uGearsRender.pas
hedgewars/uLand.pas
hedgewars/uLandGraphics.pas
hedgewars/uLandTexture.pas
hedgewars/uRender.pas
hedgewars/uRenderUtils.pas
hedgewars/uScript.pas
hedgewars/uTextures.pas
hedgewars/uTypes.pas
hedgewars/uWorld.pas
share/hedgewars/Data/Fonts/DroidSansFallback.ttf
--- a/.hgignore	Wed Jan 22 01:11:13 2014 +0400
+++ b/.hgignore	Tue Jan 21 22:53:15 2014 +0100
@@ -40,6 +40,8 @@
 glob:*.orig
 glob:*.bak
 glob:*.rej
+glob:project_files/hwc/*.c
+glob:project_files/hwc/*.h
 glob:project_files/Android-build/SDL-android-project/jni/**
 glob:project_files/Android-build/SDL-android-project/obj
 glob:project_files/Android-build/SDL-android-project/libs/armeabi*
--- a/.travis.yml	Wed Jan 22 01:11:13 2014 +0400
+++ b/.travis.yml	Tue Jan 21 22:53:15 2014 +0100
@@ -16,6 +16,8 @@
   - BUILD_ARGS="-DNOSERVER=1"
   - BUILD_ARGS="-DLUA_SYSTEM=0"
   - BUILD_ARGS="-DPHYSFS_SYSTEM=0"
+  - BUILD_ARGS="-DGL2=1"
+  - BUILD_ARGS="-DBUILD_ENGINE_C=1"
 matrix:
   allow_failures:
     # Failures we expect here
--- a/CMakeLists.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -33,6 +33,9 @@
 option(MINIMAL_FLAGS "Respect system flags as much as possible (off)" OFF)
 option(NOAUTOUPDATE "Disable OS X Sparkle update checking (off)" OFF)
 
+option(BUILD_ENGINE_C "Compile hwengine as native C [default: off]" OFF)
+option(GL2 "Enable OpenGL 2 rendering [default: off]" OFF)
+
 set(GHFLAGS "" CACHE STRING "Additional Haskell flags")
 if(UNIX AND NOT APPLE)
     set(DATA_INSTALL_DIR "share/hedgewars" CACHE STRING "Resource folder path")
@@ -113,6 +116,7 @@
     list(APPEND haskell_flags "-Wall"       # all warnings
                               "-debug"      # debug mode
                               "-dcore-lint" # internal sanity check
+                              "-fno-warn-unused-do-bind"
                               )
 else()
     list(APPEND haskell_flags "-w" # no warnings
@@ -120,6 +124,25 @@
 endif()
 
 
+#build engine without freepascal
+if(BUILD_ENGINE_C)
+    find_package(Clang REQUIRED)
+
+    if(${CLANG_VERSION} VERSION_LESS "3.0")
+        message(FATAL_ERROR "LLVM/Clang compiler required version is 3.0 but version ${CLANG_VERSION} was found!")
+    endif()
+
+    set(CMAKE_C_COMPILER ${CLANG_EXECUTABLE})
+    set(CMAKE_CXX_COMPILER ${CLANG_EXECUTABLE})
+endif()
+
+
+#server
+if(NOT NOSERVER)
+    add_subdirectory(gameServer)
+endif()
+
+
 #lua discovery
 if(LUA_SYSTEM)
     if(NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR)
@@ -184,28 +207,26 @@
 #physfs helper library
 add_subdirectory(misc/libphyslayer)
 
-#server
-if(NOT NOSERVER)
-    add_subdirectory(gameServer)
+#maybe this could be merged inside hedgewars/CMakeLists.txt
+if(BUILD_ENGINE_C)
+    #pascal to c converter
+    add_subdirectory(tools/pas2c)
+    add_subdirectory(project_files/hwc)
+else()
+    #main pascal engine
+    add_subdirectory(hedgewars)
 endif()
 
-#main engine
-add_subdirectory(hedgewars)
-
 #Android related build scripts
+#TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set
 if(ANDROID)
-    #run cmake -DANDROID=1 to enable this
     add_subdirectory(project_files/Android-build)
-endif()
-
-#TODO: when ANDROID, BUILD_ENGINE_LIBRARY should be set
-if(NOT ANDROID)
+else(ANDROID)
     add_subdirectory(bin)
     add_subdirectory(QTfrontend)
     add_subdirectory(share)
     add_subdirectory(tools)
-endif()
-
+endif(ANDROID)
 
 include(${CMAKE_MODULE_PATH}/cpackvars.cmake)
 
--- a/QTfrontend/CMakeLists.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -63,7 +63,7 @@
 include_directories(${SDLMIXER_INCLUDE_DIR})
 include_directories(BEFORE ${PHYSFS_INCLUDE_DIR})
 include_directories(BEFORE ${PHYSLAYER_INCLUDE_DIR})
-
+include_directories(${LUA_INCLUDE_DIR}) #brought by physlayer hwpacksmounter.h
 
 if(UNIX)
     # HACK: in freebsd cannot find iconv.h included via SDL.h
@@ -215,6 +215,10 @@
         )
 endif()
 
+if(CMAKE_CXX_COMPILER MATCHES "clang*")
+    list(APPEND HW_LINK_LIBS stdc++ m)
+endif()
+
 target_link_libraries(hedgewars ${HW_LINK_LIBS})
 
 
--- a/QTfrontend/campaign.cpp	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/campaign.cpp	Tue Jan 21 22:53:15 2014 +0100
@@ -26,31 +26,31 @@
 QList<MissionInfo> getCampMissionList(QString & campaignName, QString & teamName)
 {
     QList<MissionInfo> missionInfoList;
-	QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
+    QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
     teamfile.setIniCodec("UTF-8");
-    
+
     // if entry not found check if there is written without _
     // if then is found rename it to use _
     QString spaceCampName = campaignName;
     spaceCampName = spaceCampName.replace(QString("_"),QString(" "));
-    if (!teamfile.childGroups().contains("Campaign " + campaignName) and 
-			teamfile.childGroups().contains("Campaign " + spaceCampName)){
-		teamfile.beginGroup("Campaign " + spaceCampName);
-		QStringList keys = teamfile.childKeys();
-		teamfile.endGroup();
-		for (int i=0;i<keys.size();i++) {			
-			QVariant value = teamfile.value("Campaign " + spaceCampName + "/" + keys[i]);
-			teamfile.setValue("Campaign " + campaignName + "/" + keys[i], value);
-		}
-		teamfile.remove("Campaign " + spaceCampName);
-	}
-	
+    if (!teamfile.childGroups().contains("Campaign " + campaignName) and
+            teamfile.childGroups().contains("Campaign " + spaceCampName)){
+        teamfile.beginGroup("Campaign " + spaceCampName);
+        QStringList keys = teamfile.childKeys();
+        teamfile.endGroup();
+        for (int i=0;i<keys.size();i++) {
+            QVariant value = teamfile.value("Campaign " + spaceCampName + "/" + keys[i]);
+            teamfile.setValue("Campaign " + campaignName + "/" + keys[i], value);
+        }
+        teamfile.remove("Campaign " + spaceCampName);
+    }
+
     int progress = teamfile.value("Campaign " + campaignName + "/Progress", 0).toInt();
     int unlockedMissions = teamfile.value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
-    
+
     QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
     campfile.setIniCodec("UTF-8");
-    
+
     DataManager & dataMgr = DataManager::instance();
         // get locale
         QSettings settings(dataMgr.settingsFileName(),
@@ -69,42 +69,42 @@
 
         QSettings m_info(campaignDescFile, QSettings::IniFormat, 0);
         m_info.setIniCodec("UTF-8");
-    
+
     if(progress>=0 and unlockedMissions==0)
     {
-		for(unsigned int i=progress+1;i>0;i--)
-		{
-			MissionInfo missionInfo;
-			missionInfo.name = campfile.value(QString("Mission %1/Name").arg(i)).toString();
-			QString script = campfile.value(QString("Mission %1/Script").arg(i)).toString();
+        for(unsigned int i=progress+1;i>0;i--)
+        {
+            MissionInfo missionInfo;
+            missionInfo.name = campfile.value(QString("Mission %1/Name").arg(i)).toString();
+            QString script = campfile.value(QString("Mission %1/Script").arg(i)).toString();
             missionInfo.script = script;
-			missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
+            missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
                                             QObject::tr("No description available")).toString();
             QString image = campfile.value(QString("Mission %1/Script").arg(i)).toString().replace(QString(".lua"),QString(".png"));
             missionInfo.image = ":/res/campaign/"+campaignName+"/"+image;
             if (!QFile::exists(missionInfo.image))
-				missionInfo.image = ":/res/CampaignDefault.png";
-			missionInfoList.append(missionInfo);
-		}
-	} 
-	else if(unlockedMissions>0)
-	{
-		for(int i=1;i<=unlockedMissions;i++)
-		{
-			QString missionNum = QString("%1").arg(i);
-			int missionNumber = teamfile.value("Campaign " + campaignName + "/Mission"+missionNum, -1).toInt();
-			MissionInfo missionInfo;
-			missionInfo.name = campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString();
-			QString script = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString();
+                missionInfo.image = ":/res/CampaignDefault.png";
+            missionInfoList.append(missionInfo);
+        }
+    }
+    else if(unlockedMissions>0)
+    {
+        for(int i=1;i<=unlockedMissions;i++)
+        {
+            QString missionNum = QString("%1").arg(i);
+            int missionNumber = teamfile.value("Campaign " + campaignName + "/Mission"+missionNum, -1).toInt();
+            MissionInfo missionInfo;
+            missionInfo.name = campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString();
+            QString script = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString();
             missionInfo.script = script;
-			missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
+            missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
                                             QObject::tr("No description available")).toString();
             QString image = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString().replace(QString(".lua"),QString(".png"));
             missionInfo.image = ":/res/campaign/"+campaignName+"/"+image;
             if (!QFile::exists(missionInfo.image))
-				missionInfo.image = ":/res/CampaignDefault.png";
-			missionInfoList.append(missionInfo);
-		}
-	}
-	return missionInfoList;
+                missionInfo.image = ":/res/CampaignDefault.png";
+            missionInfoList.append(missionInfo);
+        }
+    }
+    return missionInfoList;
 }
--- a/QTfrontend/campaign.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/campaign.h	Tue Jan 21 22:53:15 2014 +0100
@@ -23,11 +23,11 @@
 
 class MissionInfo
 {
-	public:
-		QString name;
-		QString description;
-		QString script;
-		QString image;
+    public:
+        QString name;
+        QString description;
+        QString script;
+        QString image;
 };
 
 QList<MissionInfo> getCampMissionList(QString & campaignName, QString & teamName);
--- a/QTfrontend/hwform.cpp	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/hwform.cpp	Tue Jan 21 22:53:15 2014 +0100
@@ -1903,15 +1903,15 @@
     Q_UNUSED(index);
     HWTeam team(ui.pageCampaign->CBTeam->currentText());
     QString campaignName = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
-    QString tName = team.name();    
-    
-    campaignMissionInfo = getCampMissionList(campaignName,tName);    
-	ui.pageCampaign->CBMission->clear();
-	
+    QString tName = team.name();
+
+    campaignMissionInfo = getCampMissionList(campaignName,tName);
+    ui.pageCampaign->CBMission->clear();
+
     for(int i=0;i<campaignMissionInfo.size();i++)
     {
         ui.pageCampaign->CBMission->addItem(QString(campaignMissionInfo[i].name), QString(campaignMissionInfo[i].name));
-	}
+    }
 }
 
 void HWForm::UpdateCampaignPageMission(int index)
@@ -1923,7 +1923,7 @@
     if(index > -1 && index < campaignMissionInfo.count()) {
         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
         ui.pageCampaign->lbldescription->setText(campaignMissionInfo[index].description);
-		ui.pageCampaign->btnPreview->setIcon(QIcon(campaignMissionInfo[index].image));
+        ui.pageCampaign->btnPreview->setIcon(QIcon(campaignMissionInfo[index].image));
     }
 }
 
@@ -1935,12 +1935,12 @@
     UpdateCampaignPage(0);
     for(int i=0;i<ui.pageCampaign->CBMission->count();i++)
     {
-		if (ui.pageCampaign->CBMission->itemText(i)==missionTitle)
-		{
-			ui.pageCampaign->CBMission->setCurrentIndex(i);
-			break;
-		}
-	}
+        if (ui.pageCampaign->CBMission->itemText(i)==missionTitle)
+        {
+            ui.pageCampaign->CBMission->setCurrentIndex(i);
+            break;
+        }
+    }
 }
 
 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
--- a/QTfrontend/hwform.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/hwform.h	Tue Jan 21 22:53:15 2014 +0100
@@ -196,7 +196,7 @@
         AmmoSchemeModel * ammoSchemeModel;
         QStack<int> PagesStack;
         QString previousCampaignName;
-        QString previousTeamName;     
+        QString previousTeamName;
         QList<MissionInfo> campaignMissionInfo;
         QTime eggTimer;
         BGWidget * wBackground;
--- a/QTfrontend/ui/page/pagegamestats.cpp	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/ui/page/pagegamestats.cpp	Tue Jan 21 22:53:15 2014 +0100
@@ -40,13 +40,13 @@
 
 QLayout * PageGameStats::bodyLayoutDefinition()
 {
-	kindOfPoints = QString("");
-	defaultGraphTitle = true;	
+    kindOfPoints = QString("");
+    defaultGraphTitle = true;
     QGridLayout * pageLayout = new QGridLayout();
     pageLayout->setSpacing(20);
     pageLayout->setColumnStretch(0, 1);
     pageLayout->setColumnStretch(1, 1);
-    pageLayout->setRowStretch(0, 1);    
+    pageLayout->setRowStretch(0, 1);
     pageLayout->setRowStretch(1, 20);
     //pageLayout->setRowStretch(1, -1); this should work but there is unnecessary empty space betwin lines if used
     pageLayout->setContentsMargins(7, 7, 7, 0);
@@ -106,11 +106,11 @@
 QLayout * PageGameStats::footerLayoutDefinition()
 {
     QHBoxLayout * bottomLayout = new QHBoxLayout();
-    
+
     mainNote = new QLabel(this);
     mainNote->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
     mainNote->setWordWrap(true);
-    
+
     bottomLayout->addWidget(mainNote, 0);
     bottomLayout->setStretch(0,1);
 
@@ -159,41 +159,41 @@
 
 void PageGameStats::renderStats()
 {
-	graphic->show();
-	labelGraphTitle-> show();
-	if(defaultGraphTitle) {
-		labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
-	} else {
-		defaultGraphTitle = true;
-	}
-	// if not health data sent
-	if(healthPoints.size() == 0) {
-		labelGraphTitle->hide();
-		graphic->hide();
-	} else {
-		QGraphicsScene * scene = new QGraphicsScene();
+    graphic->show();
+    labelGraphTitle-> show();
+    if(defaultGraphTitle) {
+        labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
+    } else {
+        defaultGraphTitle = true;
+    }
+    // if not health data sent
+    if(healthPoints.size() == 0) {
+        labelGraphTitle->hide();
+        graphic->hide();
+    } else {
+        QGraphicsScene * scene = new QGraphicsScene();
 
-		QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
-		while (i != healthPoints.constEnd())
-		{
-			quint32 c = i.key();
-			//QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
-			QVector<quint32> hps = i.value();
+        QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
+        while (i != healthPoints.constEnd())
+        {
+            quint32 c = i.key();
+            //QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
+            QVector<quint32> hps = i.value();
 
-			QPainterPath path;
-			if (hps.size())
-				path.moveTo(0, hps[0]);
+            QPainterPath path;
+            if (hps.size())
+                path.moveTo(0, hps[0]);
 
-			for(int t = 1; t < hps.size(); ++t)
-				path.lineTo(t, hps[t]);
+            for(int t = 1; t < hps.size(); ++t)
+                path.lineTo(t, hps[t]);
 
-			scene->addPath(path, QPen(c));
-			++i;
-		}
+            scene->addPath(path, QPen(c));
+            ++i;
+        }
 
-		graphic->setScene(scene);
-		graphic->fitInView(graphic->sceneRect());
-	}
+        graphic->setScene(scene);
+        graphic->fitInView(graphic->sceneRect());
+    }
 }
 
 void PageGameStats::GameStats(char type, const QString & info)
@@ -237,9 +237,9 @@
         }
         case 'g' :
         {
-			// TODO: change default picture or add change pic capability
-			defaultGraphTitle = false;
-			labelGraphTitle->setText("<br><h1><img src=\":/res/StatsR.png\"> " + info + "</h1>");
+            // TODO: change default picture or add change pic capability
+            defaultGraphTitle = false;
+            labelGraphTitle->setText("<br><h1><img src=\":/res/StatsR.png\"> " + info + "</h1>");
             break;
         }
         case 'T':   // local team stats
@@ -257,7 +257,7 @@
             }
             break;
         }
-		case 'p' :
+        case 'p' :
         {
             kindOfPoints = info;
             break;
@@ -300,11 +300,11 @@
             QString message;
             QString killstring;
             if(kindOfPoints.compare("") == 0) {
-				killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills);
-			} else {
-				killstring = PageGameStats::tr("(%1 %2)", "", kills).arg(kills).arg(kindOfPoints);
-				kindOfPoints = QString("");
-			}
+                killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills);
+            } else {
+                killstring = PageGameStats::tr("(%1 %2)", "", kills).arg(kills).arg(kindOfPoints);
+                kindOfPoints = QString("");
+            }
 
             message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "</h2></p>";
 
--- a/QTfrontend/ui/page/pagemain.cpp	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/ui/page/pagemain.cpp	Tue Jan 21 22:53:15 2014 +0100
@@ -209,7 +209,7 @@
 
         file.close();
     }
-    
+
     if(Tips.length())
         return Tips[QTime(0, 0, 0).secsTo(QTime::currentTime()) % Tips.length()];
     else
--- a/QTfrontend/ui/page/pagenetserver.cpp	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/ui/page/pagenetserver.cpp	Tue Jan 21 22:53:15 2014 +0100
@@ -124,7 +124,7 @@
 
 // This function assumes that the user wants to share his server while connected to
 // the Internet and that he/she is using direct access (eg no NATs). To determine the
-// IP we briefly connect to Hedgewars website and fallback to user intervention 
+// IP we briefly connect to Hedgewars website and fallback to user intervention
 // after 4 seconds of timeout.
 void PageNetServer::copyUrl()
 {
--- a/QTfrontend/ui/page/pageoptions.cpp	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/ui/page/pageoptions.cpp	Tue Jan 21 22:53:15 2014 +0100
@@ -397,7 +397,7 @@
             tagsLayout->addWidget(CBHogTag, 0);
             tagsLayout->addWidget(CBHealthTag, 0);
             tagsLayout->addWidget(CBTagOpacity, 0);
-            tagsLayout->addStretch(1); 
+            tagsLayout->addStretch(1);
         }
 
         { // group: frontend
--- a/QTfrontend/util/FileEngine.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/QTfrontend/util/FileEngine.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,93 +1,93 @@
-#ifndef _FileEngine_h
-#define _FileEngine_h
-
-#include <QAbstractFileEngine>
-#include <QAbstractFileEngineHandler>
-#include <QAbstractFileEngineIterator>
-#include <QDateTime>
-
-#include "physfs.h"
-
-
-
-class FileEngine : public QAbstractFileEngine
-{
-    public:
-        FileEngine(const QString& filename);
-
-        virtual ~FileEngine();
-
-        virtual bool open(QIODevice::OpenMode openMode);
-        virtual bool close();
-        virtual bool flush();
-        virtual qint64 size() const;
-        virtual qint64 pos() const;
-        virtual bool setSize(qint64 size);
-        virtual bool seek(qint64 pos);
-        virtual bool isSequential() const;
-        virtual bool remove();
-        virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
-        virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
-        virtual bool caseSensitive() const;
-        virtual bool isRelativePath() const;
-        QAbstractFileEngineIterator *beginEntryList(QDir::Filters filters, const QStringList & filterNames);
-        virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
-        virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
-        virtual QString fileName(FileName file=DefaultName) const;
-        virtual QDateTime fileTime(FileTime time) const;
-        virtual void setFileName(const QString &file);
-        bool atEnd() const;
-
-        virtual qint64 read(char *data, qint64 maxlen);
-        virtual qint64 readLine(char *data, qint64 maxlen);
-        virtual qint64 write(const char *data, qint64 len);
-
-        bool isOpened() const;
-
-        QFile::FileError error() const;
-        QString errorString() const;
-
-        virtual bool supportsExtension(Extension extension) const;
-
-    private:
-        PHYSFS_file *m_handle;
-        qint64 m_size;
-        FileFlags m_flags;
-        QString m_fileName;
-        QDateTime m_date;
-        bool m_bufferSet;
-        bool m_readWrite;
-};
-
-class FileEngineHandler : public QAbstractFileEngineHandler
-{
-    public:
-        FileEngineHandler(char * argv0);
-        ~FileEngineHandler();
-
-        QAbstractFileEngine *create(const QString &filename) const;
-
-        static void mount(const QString & path);
-        static void mount(const QString & path, const QString & mountPoint);
-        static void setWriteDir(const QString & path);
-        static void mountPacks();
-        static QString errorStr();
-
-//    private:
-        static const QString scheme;
-};
-
-class FileEngineIterator : public QAbstractFileEngineIterator
-{
-public:
-        FileEngineIterator(QDir::Filters filters, const QStringList & nameFilters, const QStringList & entries);
-
-        bool hasNext() const;
-        QString next();
-        QString currentFileName() const;
-private:
-        QStringList m_entries;
-        int m_index;
-};
-
-#endif
+#ifndef _FileEngine_h
+#define _FileEngine_h
+
+#include <QAbstractFileEngine>
+#include <QAbstractFileEngineHandler>
+#include <QAbstractFileEngineIterator>
+#include <QDateTime>
+
+#include "physfs.h"
+
+
+
+class FileEngine : public QAbstractFileEngine
+{
+    public:
+        FileEngine(const QString& filename);
+
+        virtual ~FileEngine();
+
+        virtual bool open(QIODevice::OpenMode openMode);
+        virtual bool close();
+        virtual bool flush();
+        virtual qint64 size() const;
+        virtual qint64 pos() const;
+        virtual bool setSize(qint64 size);
+        virtual bool seek(qint64 pos);
+        virtual bool isSequential() const;
+        virtual bool remove();
+        virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
+        virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
+        virtual bool caseSensitive() const;
+        virtual bool isRelativePath() const;
+        QAbstractFileEngineIterator *beginEntryList(QDir::Filters filters, const QStringList & filterNames);
+        virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
+        virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
+        virtual QString fileName(FileName file=DefaultName) const;
+        virtual QDateTime fileTime(FileTime time) const;
+        virtual void setFileName(const QString &file);
+        bool atEnd() const;
+
+        virtual qint64 read(char *data, qint64 maxlen);
+        virtual qint64 readLine(char *data, qint64 maxlen);
+        virtual qint64 write(const char *data, qint64 len);
+
+        bool isOpened() const;
+
+        QFile::FileError error() const;
+        QString errorString() const;
+
+        virtual bool supportsExtension(Extension extension) const;
+
+    private:
+        PHYSFS_file *m_handle;
+        qint64 m_size;
+        FileFlags m_flags;
+        QString m_fileName;
+        QDateTime m_date;
+        bool m_bufferSet;
+        bool m_readWrite;
+};
+
+class FileEngineHandler : public QAbstractFileEngineHandler
+{
+    public:
+        FileEngineHandler(char * argv0);
+        ~FileEngineHandler();
+
+        QAbstractFileEngine *create(const QString &filename) const;
+
+        static void mount(const QString & path);
+        static void mount(const QString & path, const QString & mountPoint);
+        static void setWriteDir(const QString & path);
+        static void mountPacks();
+        static QString errorStr();
+
+//    private:
+        static const QString scheme;
+};
+
+class FileEngineIterator : public QAbstractFileEngineIterator
+{
+public:
+        FileEngineIterator(QDir::Filters filters, const QStringList & nameFilters, const QStringList & entries);
+
+        bool hasNext() const;
+        QString next();
+        QString currentFileName() const;
+private:
+        QStringList m_entries;
+        int m_index;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/FindClang.cmake	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,36 @@
+# - Try to find the Clang/LLVM executable
+# Once done this will define
+#
+#  CLANG_FOUND       - system has Clang
+#  CLANG_VERSION     - Clang version
+#  CLANG_EXECUTABLE  - Clang executable
+#
+# Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+find_program(CLANG_EXECUTABLE
+        NAMES clang-mp-3.3 clang-mp-3.2 clang-mp-3.1 clang-mp-3.0 clang
+        PATHS /opt/local/bin /usr/local/bin /usr/bin)
+
+if (CLANG_EXECUTABLE)
+    execute_process(COMMAND ${CLANG_EXECUTABLE} --version
+                    OUTPUT_VARIABLE CLANG_VERSION_OUTPUT
+                    ERROR_VARIABLE CLANG_VERSION_ERROR
+                    RESULT_VARIABLE CLANG_VERSION_RESULT
+                    OUTPUT_STRIP_TRAILING_WHITESPACE
+                    )
+
+    if(${CLANG_VERSION_RESULT} EQUAL 0)
+        string(REGEX MATCH "[0-9]+\\.[0-9]+" CLANG_VERSION "${CLANG_VERSION_OUTPUT}")
+        string(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" CLANG_VERSION "${CLANG_VERSION}")
+    else()
+        message(SEND_ERROR "Command \"${CLANG_EXECUTABLE} --version\" failed with output: ${CLANG_VERSION_ERROR}")
+    endif()
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Clang DEFAULT_MSG CLANG_EXECUTABLE CLANG_VERSION)
+mark_as_advanced(CLANG_VERSION)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/FindGLEW.cmake	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,39 @@
+# Find GLEW
+#
+# Once done this will define
+#  GLEW_FOUND - system has GLEW
+#  GLEW_INCLUDE_DIR - the GLEW include directory
+#  GLEW_LIBRARY - The library needed to use GLEW
+# Copyright (c) 2013, Vittorio Giovara <vittorio.giovara@gmail.com>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+
+include(FindPackageHandleStandardArgs)
+
+find_path( GLEW_INCLUDE_DIR GL/glew.h
+            /usr/include
+            /usr/local/include
+            /sw/include
+            /opt/local/include
+            $ENV{PROGRAMFILES}/GLEW/include
+            DOC "The directory where GL/glew.h resides")
+find_library( GLEW_LIBRARY
+            NAMES GLEW glew glew32 glew32s
+            PATHS
+            /usr/lib64
+            /usr/lib
+            /usr/local/lib64
+            /usr/local/lib
+            /sw/lib
+            /opt/local/lib
+            $ENV{PROGRAMFILES}/GLEW/lib
+            DOC "The GLEW library")
+
+find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_DIR)
+mark_as_advanced(GLEW_LIBRARY GLEW_INCLUDE_DIR)
+
--- a/cmake_modules/revinfo.cmake	Wed Jan 22 01:11:13 2014 +0400
+++ b/cmake_modules/revinfo.cmake	Tue Jan 21 22:53:15 2014 +0100
@@ -1,7 +1,7 @@
 #detect Mercurial revision and init rev/hash information
 find_program(HGCOMMAND hg)
 find_program(GITCOMMAND git)
-if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND AND NOT NOVERSIONINFOUPDATE)
+if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND)
     execute_process(COMMAND ${HGCOMMAND} identify -in
                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                     OUTPUT_VARIABLE internal_version
@@ -21,7 +21,7 @@
 
     #write down hash and rev for easy picking should hg be missing
     file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
-elseif(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GITCOMMAND AND NOT NOVERSIONINFOUPDATE)
+elseif(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GITCOMMAND)
     execute_process(COMMAND ${GITCOMMAND} rev-parse --short HEAD
                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                     OUTPUT_VARIABLE HEDGEWARS_HASH
--- a/gameServer/Actions.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/Actions.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -327,11 +327,11 @@
     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
     joinedMidGame <- liftM (filter isJoinedMidGame) $ roomClientsS ri
     answerRemovedTeams <- io $
-         room'sM rnc (\r -> let gi = fromJust $ gameInfo r in 
-                        concatMap (\c -> 
+         room'sM rnc (\r -> let gi = fromJust $ gameInfo r in
+                        concatMap (\c ->
                             (answerFullConfigParams c (mapParams r) (params r))
                             ++
-                            (map (\t -> AnswerClients [sendChan c] ["REMOVE_TEAM", t]) $ leftTeams gi) 
+                            (map (\t -> AnswerClients [sendChan c] ["REMOVE_TEAM", t]) $ leftTeams gi)
                         ) joinedMidGame
                      ) ri
 
@@ -357,7 +357,7 @@
         ModifyRoom (\r -> r{
                 gameInfo = liftM (\g -> g{
                     teamsInGameNumber = teamsInGameNumber g - 1
-                    , roundMsgs = (if isJust $ lastFilteredTimedMsg g then (:) (fromJust $ lastFilteredTimedMsg g) else id) 
+                    , roundMsgs = (if isJust $ lastFilteredTimedMsg g then (:) (fromJust $ lastFilteredTimedMsg g) else id)
                       $ rmTeamMsg : roundMsgs g
                 }) $ gameInfo r
             })
@@ -456,11 +456,11 @@
         wp <- client's webPassword
         chan <- client's sendChan
         mapM_ processAction $
-            if wp == p then 
+            if wp == p then
                 [ModifyClient $ \c -> c{logonPassed = True}
                 , AnswerClients [chan] ["LOGONPASSED"]
                 ]
-                else 
+                else
                 [ByeClient $ loc "Authentication failed"]
     playerLogin p a contr = do
         chan <- client's sendChan
@@ -530,7 +530,7 @@
 
 processAction (BanNick n seconds reason) = do
     currentTime <- io getCurrentTime
-    let msg = 
+    let msg =
             if seconds > 60 * 60 * 24 * 365 then
                 B.concat ["Permanent ban (", reason, ")"]
                 else
@@ -775,7 +775,7 @@
 
 processAction Cleanup = do
     jm <- gets joinsMonitor
-    
+
     io $ do
         t <- getCurrentTime
         cleanup jm t
--- a/gameServer/CoreTypes.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/CoreTypes.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -183,7 +183,6 @@
         isRegisteredOnly :: Bool,
         isSpecial :: Bool,
         greeting :: B.ByteString,
-        voting :: Maybe Voting,
         roomBansList :: ![B.ByteString],
         mapParams :: Map.Map B.ByteString B.ByteString,
         params :: Map.Map B.ByteString [B.ByteString]
@@ -205,7 +204,6 @@
         False
         False
         ""
-        Nothing
         []
         (
             Map.fromList $ Prelude.zip
@@ -214,8 +212,8 @@
         )
         (
             Map.fromList $ Prelude.zip
-                ["SCHEME", "SCRIPT", "THEME", "MAZE_SIZE", "DRAWNMAP"]
-                [["Default"], ["Normal"], ["Theme"], ["0"], ["-"]]
+                ["SCHEME", "SCRIPT", "Theme"]
+                [["Default"], ["Normal"], ["Theme"]]
         )
 
 
@@ -266,21 +264,6 @@
         False
         []
 
-data Voting = Voting {
-        voteTTL :: Int,
-        entitledToVote :: [Unique],
-        votes :: [(Unique, Bool)],
-        voteType :: VoteType
-    }
-
-
-data VoteType = VoteKick B.ByteString
-
-
-newVote :: VoteType -> Voting
-newVote = Voting 2 [] []
-
-
 data AccountInfo =
     HasAccount B.ByteString Bool Bool
     | Guest
--- a/gameServer/EngineInteraction.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/EngineInteraction.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -49,7 +49,7 @@
         encode = B.pack . Base64.encode . BW.unpack . B.concat
         isLegal m = (B.length m > 1) && (flip Set.member legalMessages . B.head . B.tail $ m)
         lft = foldr l Nothing
-        l m n = let m' = B.head $ B.tail m; tst = flip Set.member in 
+        l m n = let m' = B.head $ B.tail m; tst = flip Set.member in
                       if not $ tst timedMessages m' then n
                         else if '+' /= m' then Just Nothing else Just . Just . B.pack . Base64.encode . BW.unpack $ m
         isNonEmpty = (/=) '+' . B.head . B.tail
@@ -113,7 +113,7 @@
                         )
 
 drawnMapData :: B.ByteString -> [B.ByteString]
-drawnMapData = 
+drawnMapData =
           L.map (\m -> eml ["edraw ", BW.pack m])
         . L.unfoldr by200
         . BL.unpack
--- a/gameServer/HWProtoCore.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/HWProtoCore.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -33,7 +33,10 @@
         else
         return [ModifyClient (\c -> c{pingsQueue = pingsQueue c - 1})]
 
-handleCmd ["CMD", parameters] = uncurry h $ extractParameters parameters
+handleCmd ["CMD", parameters] = do
+        let (cmd, plist) = B.break (== ' ') parameters
+        let param = B.dropWhile (== ' ') plist
+        h (upperCase cmd) param
     where
         h "DELEGATE" n | not $ B.null n = handleCmd ["DELEGATE", n]
         h "STATS" _ = handleCmd ["STATS"]
@@ -51,15 +54,8 @@
         h "FIX" _ = handleCmd ["FIX"]
         h "UNFIX" _ = handleCmd ["UNFIX"]
         h "GREETING" msg = handleCmd ["GREETING", msg]
-        h "CALLVOTE" msg | B.null msg = handleCmd ["CALLVOTE"]
-                         | otherwise = let (c, p) = extractParameters msg in
-                                           if B.null p then handleCmd ["CALLVOTE", c] else handleCmd ["CALLVOTE", c, p]
-        h "VOTE" msg = handleCmd ["VOTE", upperCase msg]
         h c p = return [Warning $ B.concat ["Unknown cmd: /", c, p]]
 
-        extractParameters p = let (a, b) = B.break (== ' ') p in (upperCase a, B.dropWhile (== ' ') b)
-
-
 handleCmd cmd = do
     (ci, irnc) <- ask
     let cl = irnc `client` ci
--- a/gameServer/HWProtoInRoomState.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/HWProtoInRoomState.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -215,7 +215,7 @@
 
     gs <- if (not $ isReady cl) && (isSpecial rm) && (unreadyClients == [cl]) then startGame else return []
 
-    return $ 
+    return $
         ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady cl then -1 else 1)})
         : ModifyClient (\c -> c{isReady = not $ isReady cl})
         : (AnswerClients chans $ if clientProto cl < 38 then
@@ -236,7 +236,7 @@
 
     if teamsInGame cl > 0 && (isJust $ gameInfo rm) && (not $ B.null legalMsgs) then
         return $ AnswerClients chans ["EM", legalMsgs]
-            : [ModifyRoom (\r -> r{gameInfo = liftM 
+            : [ModifyRoom (\r -> r{gameInfo = liftM
                 (\g -> g{
                     roundMsgs = if B.null nonEmptyMsgs then roundMsgs g else nonEmptyMsgs : roundMsgs g
                     , lastFilteredTimedMsg = fromMaybe (lastFilteredTimedMsg g) lastFTMsg})
@@ -306,7 +306,7 @@
         if not $ isMaster cl then
             [ProtocolError $ loc "Not room master"]
         else
-        if illegalName newName then 
+        if illegalName newName then
             [Warning $ loc "Illegal room name"]
         else
         if isSpecial rm then
--- a/gameServer/OfficialServer/checker.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/OfficialServer/checker.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -28,7 +28,7 @@
 readInt_ str =
   case B.readInt str of
        Just (i, t) | B.null t -> fromIntegral i
-       _                      -> 0 
+       _                      -> 0
 
 data Message = Packet [B.ByteString]
              | CheckFailed B.ByteString
--- a/gameServer/OfficialServer/extdbinterface.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/OfficialServer/extdbinterface.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -18,7 +18,7 @@
 
 
 dbQueryAccount =
-    "SELECT users.pass, \ 
+    "SELECT users.pass, \
     \ (SELECT COUNT(users_roles.rid) FROM users_roles WHERE users.uid = users_roles.uid AND users_roles.rid = 3), \
     \ (SELECT COUNT(users_roles.rid) FROM users_roles WHERE users.uid = users_roles.uid AND users_roles.rid = 13) \
     \ FROM users WHERE users.name = ?"
@@ -71,7 +71,7 @@
         SendStats clients rooms ->
                 run dbConn dbQueryStats [SqlInt32 $ fromIntegral clients, SqlInt32 $ fromIntegral rooms] >> return ()
 --StoreAchievements (B.pack fileName) (map toPair teams) info
-        StoreAchievements p fileName teams info -> 
+        StoreAchievements p fileName teams info ->
             mapM_ (run dbConn dbQueryAchievement) $ (parseStats p fileName teams) info
 
 
--- a/gameServer/ServerCore.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/ServerCore.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -62,8 +62,8 @@
 
         TimerAction tick ->
                 mapM_ processAction $
-                    PingAll 
-                    : [StatsAction | even tick] 
+                    PingAll
+                    : [StatsAction | even tick]
                     ++ [Cleanup | tick `mod` 100 == 0]
 
 
--- a/gameServer/Utils.hs	Wed Jan 22 01:11:13 2014 +0400
+++ b/gameServer/Utils.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -116,7 +116,7 @@
 readInt_ str =
   case B.readInt str of
        Just (i, t) | B.null t -> fromIntegral i
-       _                      -> 0 
+       _                      -> 0
 
 cutHost :: B.ByteString -> B.ByteString
 cutHost = B.intercalate "." .  flip (++) ["*","*"] . List.take 2 . B.split '.'
@@ -128,7 +128,7 @@
 upperCase = UTF8.fromString . map Char.toUpper . UTF8.toString
 
 roomInfo :: Word16 -> B.ByteString -> RoomInfo -> [B.ByteString]
-roomInfo p n r 
+roomInfo p n r
     | p < 46 = [
         showB $ isJust $ gameInfo r,
         name r,
--- a/hedgewars/ArgParsers.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/ArgParsers.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -15,7 +15,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  *)
- 
+
 {$INCLUDE "options.inc"}
 
 unit ArgParsers;
@@ -111,7 +111,7 @@
         end
 end;
 
-function parseNick(nick: String): String;
+function parseNick(nick: shortstring): shortstring;
 begin
     if isInternal then
         parseNick:= DecodeBase64(nick)
@@ -158,35 +158,38 @@
 {$ENDIF}
 end;
 
-function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
+function getLongIntParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
 var tmpInt, c: LongInt;
 begin
     inc(paramIndex);
+{$IFDEF PAS2C}
+    val(str, tmpInt);
+{$ELSE}
     val(str, tmpInt, c);
     wrongParameter:= c <> 0;
     if wrongParameter then
         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
+{$ENDIF}
     getLongIntParameter:= tmpInt;
 end;
 
-function getStringParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): String;
+function getstringParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): shortstring;
 begin
     inc(paramIndex);
     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
     if wrongParameter then
          WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
-    getStringParameter:= str;
+    getstringParameter:= str;
 end;
 
-
-procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); Forward;
+procedure parseClassicParameter(cmdArray: array of string; size:LongInt; var paramIndex:LongInt); forward;
 
-function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
-const videoArray: Array [1..5] of String = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
-      audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
-      otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
-      mediaArray: Array [1..10] of String = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
-      allArray: Array [1..18] of String = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
+function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
+const videoArray: Array [1..5] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
+      audioArray: Array [1..3] of string = ('--volume','--nomusic','--nosound');
+      otherArray: Array [1..3] of string = ('--locale','--fullscreen','--showfps');
+      mediaArray: Array [1..10] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
+      allArray: Array [1..18] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
       reallyAll: array[0..35] of shortstring = (
                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
@@ -204,9 +207,9 @@
 
     while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
     case cmdIndex of
-        {--prefix}               0 : PathPrefix        := getStringParameter (arg, paramIndex, parseParameter);
-        {--user-prefix}          1 : UserPathPrefix    := getStringParameter (arg, paramIndex, parseParameter);
-        {--locale}               2 : cLocaleFName      := getStringParameter (arg, paramIndex, parseParameter);
+        {--prefix}               0 : PathPrefix        := getstringParameter (arg, paramIndex, parseParameter);
+        {--user-prefix}          1 : UserPathPrefix    := getstringParameter (arg, paramIndex, parseParameter);
+        {--locale}               2 : cLocaleFName      := getstringParameter (arg, paramIndex, parseParameter);
         {--fullscreen-width}     3 : cFullscreenWidth  := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
         {--fullscreen-height}    4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
         {--width}                5 : cWindowedWidth    := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
@@ -221,7 +224,7 @@
         {--low-quality}         14 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
         {--raw-quality}         15 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
         {--stereo}              16 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
-        {--nick}                17 : UserNick          := parseNick( getStringParameter(arg, paramIndex, parseParameter) );
+        {--nick}                17 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
         {deprecated options}
         {--depth}               18 : setDepth(paramIndex);
         {--set-video}           19 : parseClassicParameter(videoArray,5,paramIndex);
@@ -242,7 +245,7 @@
         {--no-hogtag}           32 : cTagsMask := cTagsMask and not htName;
         {--no-healthtag}        33 : cTagsMask := cTagsMask and not htHealth;
         {--translucent-tags}    34 : cTagsMask := cTagsMask or htTransparent;
-        {--lua-test}            35 : begin cTestLua := true; cScriptName := getStringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
+        {--lua-test}            35 : begin cTestLua := true; cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
     else
         begin
         //Assume the first "non parameter" is the replay file, anything else is invalid
@@ -257,10 +260,10 @@
     end;
 end;
 
-procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
+procedure parseClassicParameter(cmdArray: array of string; size:LongInt; var paramIndex:LongInt);
 var index, tmpInt: LongInt;
     isBool, isValid: Boolean;
-    cmd, arg, newSyntax: String;
+    cmd, arg, newSyntax: string;
 begin
     WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!');
     WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
@@ -287,9 +290,9 @@
         if isValid then
             begin
             parseParameter(cmd, arg, tmpInt);
-            newSyntax := newSyntax + cmd + ' ';
+            newSyntax:= newSyntax + cmd + ' ';
             if not isBool then
-                newSyntax := newSyntax + arg + ' ';
+                newSyntax:= newSyntax + arg + ' ';
             end;
         inc(index);
         end;
@@ -340,7 +343,7 @@
 begin
     isInternal:= (ParamStr(1) = '--internal');
 
-    UserPathPrefix := '.';
+    UserPathPrefix := _S'.';
     PathPrefix     := cDefaultPathPrefix;
     recordFileName := '';
     parseCommandLine();
--- a/hedgewars/CMakeLists.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -179,6 +179,11 @@
     add_definitions(-dSDL2)
 endif()
 
+#opengl 2
+IF(GL2)
+    add_definitions(-dGL2)
+ENDIF(GL2)
+
 #needs to be last
 add_definitions(-dDEBUGFILE)
 
--- a/hedgewars/LuaPas.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/LuaPas.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -21,7 +21,9 @@
 {$ENDIF}
 
 type
+{$IFNDEF PAS2C}
     size_t   = Cardinal;
+{$ENDIF}
     Psize_t  = ^size_t;
     PPointer = ^Pointer;
 
@@ -55,12 +57,14 @@
 @* of a function in debug information.
 ** CHANGE it if you want a different size.
 *)
+
 const
     LUA_IDSIZE = 60;
 
 (*
 @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
 *)
+
 const
     LUAL_BUFFERSIZE = 1024;
 
@@ -70,6 +74,7 @@
 ** CHANGE them if you want different prompts. (You can also change the
 ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
 *)
+
 const
     LUA_PROMPT  = '> ';
     LUA_PROMPT2 = '>> ';
@@ -113,6 +118,7 @@
 ** See Copyright Notice at the end of this file
 *)
 
+
 const
     LUA_VERSION     = 'Lua 5.1';
     LUA_VERSION_NUM = 501;
@@ -132,8 +138,10 @@
     LUA_ENVIRONINDEX  = -10001;
     LUA_GLOBALSINDEX  = -10002;
 
+
 function lua_upvalueindex(idx : LongInt) : LongInt;   // a marco
 
+
 const
    (* thread status; 0 is OK *)
     LUA_YIELD_    = 1;     // Note: the ending underscore is needed in Pascal
@@ -142,6 +150,7 @@
     LUA_ERRMEM    = 4;
     LUA_ERRERR    = 5;
 
+
 type
    lua_CFunction = function(L : Plua_State) : LongInt; cdecl;
 
@@ -156,6 +165,7 @@
   *)
   lua_Alloc = function (ud, ptr : Pointer; osize, nsize : size_t) : Pointer; cdecl;
 
+
 const
     (*
     ** basic types
@@ -181,12 +191,13 @@
     (* type for integer functions *)
     lua_Integer = LUA_INTEGER_;
 
+
 (*
 ** state manipulation
 *)
 function  lua_newstate(f : lua_Alloc; ud : Pointer) : Plua_State;
     cdecl; external LuaLibName;
-    
+
 procedure lua_close(L: Plua_State);
     cdecl; external LuaLibName;
 function  lua_newthread(L : Plua_State) : Plua_State;
@@ -201,22 +212,22 @@
 *)
 function  lua_gettop(L : Plua_State) : LongInt;
     cdecl; external LuaLibName;
-    
+
 procedure lua_settop(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_pushvalue(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_remove(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_insert(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_replace(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 function  lua_checkstack(L : Plua_State; sz : LongInt) : LongBool;
     cdecl; external LuaLibName;
 
@@ -229,57 +240,55 @@
 *)
 function lua_isnumber(L : Plua_State; idx : LongInt) : LongBool;
     cdecl; external LuaLibName;
-    
+
 function lua_isstring(L : Plua_State; idx : LongInt) : LongBool;
     cdecl; external LuaLibName;
-    
+
 function lua_iscfunction(L : Plua_State; idx : LongInt) : LongBool;
     cdecl; external LuaLibName;
-    
+
 function lua_isuserdata(L : Plua_State; idx : LongInt) : LongBool;
     cdecl; external LuaLibName;
-    
+
 function lua_type(L : Plua_State; idx : LongInt) : LongInt;
     cdecl; external LuaLibName;
-    
+
 function lua_typename(L : Plua_State; tp : LongInt) : PChar;
     cdecl; external LuaLibName;
 
-    
 function lua_equal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
     cdecl; external LuaLibName;
-    
+
 function lua_rawequal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
     cdecl; external LuaLibName;
-    
+
 function lua_lessthan(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
     cdecl; external LuaLibName;
 
 function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number;
     cdecl; external LuaLibName;
-    
+
 function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer;
     cdecl; external LuaLibName;
-    
+
 function lua_toboolean(L : Plua_State; idx : LongInt) : LongBool;
     cdecl; external LuaLibName;
-    
-    
+
 function lua_tolstring(L : Plua_State; idx : LongInt; len : Psize_t) : PChar;
     cdecl; external LuaLibName;
-    
+
 function lua_objlen(L : Plua_State; idx : LongInt) : size_t;
     cdecl; external LuaLibName;
-    
+
 function lua_tocfunction(L : Plua_State; idx : LongInt) : lua_CFunction;
     cdecl; external LuaLibName;
-    
+
 function lua_touserdata(L : Plua_State; idx : LongInt) : Pointer;
     cdecl; external LuaLibName;
-    
+
 function lua_tothread(L : Plua_State; idx : LongInt) : Plua_State;
     cdecl; external LuaLibName;
-    
+
 function lua_topointer(L : Plua_State; idx : LongInt) : Pointer;
     cdecl; external LuaLibName;
 
@@ -289,36 +298,35 @@
 *)
 procedure lua_pushnil(L : Plua_State);
     cdecl; external LuaLibName;
-    
+
 procedure lua_pushnumber(L : Plua_State; n : lua_Number);
     cdecl; external LuaLibName;
-    
+
 procedure lua_pushinteger(L : Plua_State; n : lua_Integer);
     cdecl; external LuaLibName;
-    
+
 procedure lua_pushlstring(L : Plua_State; const s : PChar; ls : size_t);
     cdecl; external LuaLibName;
-    
+
 procedure lua_pushstring(L : Plua_State; const s : PChar);
     cdecl; external LuaLibName;
-    
-    
+
 function  lua_pushvfstring(L : Plua_State;
     const fmt : PChar; argp : Pointer) : PChar;
     cdecl; external LuaLibName;
-    
+
 function  lua_pushfstring(L : Plua_State; const fmt : PChar) : PChar; varargs;
     cdecl; external LuaLibName;
-    
+
 procedure lua_pushcclosure(L : Plua_State; fn : lua_CFunction; n : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_pushboolean(L : Plua_State; b : LongBool);
     cdecl; external LuaLibName;
-    
+
 procedure lua_pushlightuserdata(L : Plua_State; p : Pointer);
     cdecl; external LuaLibName;
-    
+
 function  lua_pushthread(L : Plua_state) : Cardinal;
     cdecl; external LuaLibName;
 
@@ -328,25 +336,25 @@
 *)
 procedure lua_gettable(L : Plua_State ; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_getfield(L : Plua_State; idx : LongInt; k : PChar);
     cdecl; external LuaLibName;
-    
+
 procedure lua_rawget(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_rawgeti(L : Plua_State; idx, n : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_createtable(L : Plua_State; narr, nrec : LongInt);
     cdecl; external LuaLibName;
-    
+
 function  lua_newuserdata(L : Plua_State; sz : size_t) : Pointer;
     cdecl; external LuaLibName;
-    
+
 function  lua_getmetatable(L : Plua_State; objindex : LongInt) : LongBool;
     cdecl; external LuaLibName;
-    
+
 procedure lua_getfenv(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
 
@@ -356,19 +364,19 @@
 *)
 procedure lua_settable(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_setfield(L : Plua_State; idx : LongInt; const k : PChar);
     cdecl; external LuaLibName;
-    
+
 procedure lua_rawset(L : Plua_State; idx : LongInt);
     cdecl; external LuaLibName;
-    
+
 procedure lua_rawseti(L : Plua_State; idx , n: LongInt);
     cdecl; external LuaLibName;
-    
+
 function lua_setmetatable(L : Plua_State; objindex : LongInt): LongBool;
     cdecl; external LuaLibName;
-    
+
 function lua_setfenv(L : Plua_State; idx : LongInt): LongBool;
     cdecl; external LuaLibName;
 
@@ -377,16 +385,16 @@
 *)
 procedure lua_call(L : Plua_State; nargs, nresults : LongInt);
     cdecl; external LuaLibName;
-    
+
 function  lua_pcall(L : Plua_State; nargs, nresults, errfunc : LongInt) : LongInt;
     cdecl; external LuaLibName;
-    
+
 function  lua_cpcall(L : Plua_State; func : lua_CFunction; ud : Pointer) : LongInt;
     cdecl; external LuaLibName;
-    
+
 function  lua_load(L : Plua_State; reader : lua_Reader; dt : Pointer; const chunkname : PChar) : LongInt;
     cdecl; external LuaLibName;
-    
+
 
 function lua_dump(L : Plua_State; writer : lua_Writer; data: Pointer) : LongInt;
     cdecl; external LuaLibName;
@@ -397,16 +405,17 @@
 *)
 function lua_yield(L : Plua_State; nresults : LongInt) : LongInt;
     cdecl; external LuaLibName;
-    
+
 function lua_resume(L : Plua_State; narg : LongInt) : LongInt;
     cdecl; external LuaLibName;
-    
+
 function lua_status(L : Plua_State) : LongInt;
     cdecl; external LuaLibName;
 
 (*
 ** garbage-collection functions and options
 *)
+
 const
     LUA_GCSTOP       = 0;
     LUA_GCRESTART    = 1;
@@ -434,7 +443,7 @@
 
 function  lua_getallocf(L : Plua_State; ud : PPointer) : lua_Alloc;
     cdecl; external LuaLibName;
-    
+
 procedure lua_setallocf(L : Plua_State; f : lua_Alloc; ud : Pointer);
     cdecl; external LuaLibName;
 
@@ -532,25 +541,25 @@
 
 function lua_getstack(L : Plua_State; level : LongInt; ar : Plua_Debug) : LongInt;
     cdecl; external LuaLibName;
-    
+
 function lua_getinfo(L : Plua_State; const what : PChar; ar: Plua_Debug): LongInt;
     cdecl; external LuaLibName;
-    
+
 function lua_getlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar;
     cdecl; external LuaLibName;
-    
+
 function lua_setlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar;
     cdecl; external LuaLibName;
-    
+
 function lua_getupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
     cdecl; external LuaLibName;
-    
+
 function lua_setupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
     cdecl; external LuaLibName;
 
 function lua_sethook(L : Plua_State; func : lua_Hook; mask, count: LongInt): LongInt;
     cdecl; external LuaLibName;
-  
+
 {$IFDEF LUA_GETHOOK}
 function lua_gethook(L : Plua_State) : lua_Hook;
     cdecl; external LuaLibName;
@@ -558,7 +567,7 @@
 
 function lua_gethookmask(L : Plua_State) : LongInt;
     cdecl; external LuaLibName;
-    
+
 function lua_gethookcount(L : Plua_State) : LongInt;
     cdecl; external LuaLibName;
 
--- a/hedgewars/SDLh.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/SDLh.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -404,15 +404,26 @@
         w, h  : LongInt;
         pitch : {$IFDEF SDL2}LongInt{$ELSE}Word{$ENDIF};
         pixels: Pointer;
-{$IFDEF SDL2}
-        userdata: Pointer;
-        locked: LongInt;
-        lock_data: Pointer;
+{$IFDEF PAS2C}
+        hwdata   : Pointer;
         clip_rect: TSDL_Rect;
-        map: Pointer;
-        refcount: LongInt;
+        unsed1   : LongWord;
+        locked   : LongWord;
+        map      : Pointer;
+        format_version: Longword;
+        refcount : LongInt;
+        offset   : LongInt;
 {$ELSE}
-        offset: LongInt;
+{$IFDEF SDL2}
+        userdata  : Pointer;
+        locked    : LongInt;
+        lock_data : Pointer;
+        clip_rect : TSDL_Rect;
+        map       : Pointer;
+        refcount  : LongInt;
+{$ELSE}
+        offset : LongInt;
+{$ENDIF}
 {$ENDIF}
         end;
 
@@ -825,6 +836,7 @@
 
     TByteArray = array[0..65535] of Byte;
     PByteArray = ^TByteArray;
+
     TLongWordArray = array[0..16383] of LongWord;
     PLongWordArray = ^TLongWordArray;
 
--- a/hedgewars/adler32.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/adler32.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -2,7 +2,6 @@
 
 {ZLib - Adler32 checksum function}
 
-
 interface
 
 (*************************************************************************
@@ -66,7 +65,7 @@
 Also, the structure was removed to simplify C conversion
 *)
 
-function Adler32Update ( var adler     :longint; Msg     :pointer; Len     :longint ) : longint;
+function Adler32Update (var adler : longint; Msg     :Pointer; Len     :longint ) : longint;
 
 implementation
 
@@ -124,17 +123,19 @@
 end;
 *)
 
-function Adler32Update(var adler: longint; Msg: pointer; Len :longint) : longint;
+function Adler32Update(var adler:longint; Msg: Pointer; Len :longint) : longint;
     {-update Adler32 with Msg data}
     const
         BASE = 65521; {max. prime < 65536 }
         NMAX = 3854; {max. n with 255n(n+1)/2 + (n+1)(BASE-1) < 2^31}
     var
-        s1, s2: longint;
-        i, n: integer;
+        s1, s2 : longint;
+        i, n   : integer;
+       m       : PByte;
     begin
-        s1 := adler and $FFFF;
-        s2 := adler shr 16;
+        m  := PByte(Msg);
+        s1 := Longword(adler) and $FFFF;
+        s2 := Longword(adler) shr 16;
         while Len>0 do
             begin
             if Len<NMAX then
@@ -144,8 +145,8 @@
 
             for i := 1 to n do
                 begin
-                inc(s1, pByte(Msg)^);
-                inc(Msg);
+                inc(s1, m^);
+                inc(m);
                 inc(s2, s1);
                 end;
             s1 := s1 mod BASE;
--- a/hedgewars/config.inc.in	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/config.inc.in	Tue Jan 21 22:53:15 2014 +0100
@@ -26,4 +26,8 @@
       cRevisionString = '${HEDGEWARS_REVISION}';
       cHashString = '${HEDGEWARS_HASH}';
       cDefaultPathPrefix = '${HEDGEWARS_FULL_DATADIR}/Data';
+{$IFDEF PAS2C}
+      cFontsPaths = '';
+{$ELSE}
       cFontsPaths: ${FONTS_DIRS_ARRAY}
+{$ENDIF}
--- a/hedgewars/hwLibrary.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/hwLibrary.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -106,12 +106,12 @@
 
 procedure JNI_HW_GenLandPreview(env: PJNIEnv; c: JClass; port: JInt); cdecl;
 begin
-	GenLandPreview(port);
+    GenLandPreview(port);
 end;
 
 exports
-    JNI_HW_versionInfoNet name Java_Prefix+'HWversionInfoNetProto', 
-    JNI_HW_versionInfoVersion name Java_Prefix+'HWversionInfoVersion', 
+    JNI_HW_versionInfoNet name Java_Prefix+'HWversionInfoNetProto',
+    JNI_HW_versionInfoVersion name Java_Prefix+'HWversionInfoVersion',
     JNI_HW_GenLandPreview name Java_Prefix + 'HWGenLandPreview',
     HW_getNumberOfweapons name Java_Prefix + 'HWgetNumberOfWeapons',
     HW_getMaxNumberOfHogs name Java_Prefix + 'HWgetMaxNumberOfHogs',
Binary file hedgewars/hwengine.ico has changed
--- a/hedgewars/hwengine.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/hwengine.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -19,7 +19,7 @@
 {$INCLUDE "options.inc"}
 
 {$IFDEF WIN32}
-{$R hwengine.rc}
+{$R res/hwengine.rc}
 {$ENDIF}
 
 {$IFDEF HWLIBRARY}
@@ -92,7 +92,9 @@
             end;
         gsConfirm, gsGame, gsChat:
             begin
-            if not cOnlyStats then DrawWorld(Lag);
+            if not cOnlyStats then
+                // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
+                DrawWorld(Lag);
             DoGameTick(Lag);
             if not cOnlyStats then ProcessVisualGears(Lag);
             end;
@@ -114,7 +116,11 @@
     if flagMakeCapture then
         begin
         flagMakeCapture:= false;
+        {$IFDEF PAS2C}
+        s:= '/Screenshots/hw';
+        {$ELSE}
         s:= '/Screenshots/hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks);
+        {$ENDIF}
 
         // flash
         playSound(sndShutter);
@@ -135,7 +141,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 procedure MainLoop;
 var event: TSDL_Event;
-    PrevTime, CurrTime: Longword;
+    PrevTime, CurrTime: LongWord;
     isTerminated: boolean;
 {$IFDEF SDL2}
     previousGameState: TGameState;
@@ -275,11 +281,12 @@
         CurrTime:= SDL_GetTicks();
         if PrevTime + longword(cTimerInterval) <= CurrTime then
         begin
-            isTerminated := isTerminated or DoTimer(CurrTime - PrevTime);
-            PrevTime:= CurrTime
+            isTerminated:= isTerminated or DoTimer(CurrTime - PrevTime);
+            PrevTime:= CurrTime;
         end
         else SDL_Delay(1);
         IPCCheckSock();
+
     end;
 end;
 
@@ -414,11 +421,14 @@
 
 {$IFDEF USE_VIDEO_RECORDING}
     if GameType = gmtRecord then
-        RecorderMainLoop()
-    else
+    begin
+        RecorderMainLoop();
+        freeEverything(true);
+        exit;
+    end;
 {$ENDIF}
-        MainLoop();
 
+    MainLoop;
     // clean up all the memory allocated
     freeEverything(true);
 end;
@@ -546,6 +556,10 @@
 /////////////////////////////////// m a i n ///////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 begin
+{$IFDEF PAS2C}
+    // workaround for pascal's ParamStr and ParamCount
+    init(argc, argv);
+{$ENDIF}
     preInitEverything();
     cTagsMask:= htTeamName or htName or htHealth; // this one doesn't fit nicely w/ reset of other variables. suggestions welcome
     GetParams();
@@ -556,6 +570,11 @@
         Game();
 
     // return 1 when engine is not called correctly
+    {$IFDEF PAS2C}
+    exit(LongInt(GameType = gmtSyntax));
+    {$ELSE}
     halt(LongInt(GameType = gmtSyntax));
+    {$ENDIF}
+
 {$ENDIF}
 end.
--- a/hedgewars/hwengine.rc	Wed Jan 22 01:11:13 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-MAINICON ICON "hwengine.ico"
\ No newline at end of file
--- a/hedgewars/options.inc	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/options.inc	Tue Jan 21 22:53:15 2014 +0100
@@ -64,12 +64,9 @@
     {$DEFINE SDL2}
 {$ENDIF}
 
-
-//TODO: cruft to be removed
 {$DEFINE _S:=}
 {$DEFINE _P:=}
 
-
 //{$DEFINE TRACEAIACTIONS}
 //{$DEFINE COUNTTICKS}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/pas2cRedo.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,113 @@
+redo;
+{This file contains functions that are re-implemented}
+{pas2c will add prefix fpcrtl_ to all these functions}
+type
+    uinteger = uinteger;
+    Integer = integer;
+    LongInt = integer;
+    LongWord = uinteger;
+    Cardinal = uinteger;
+    PtrInt = integer;
+    Word = uinteger;
+    Byte = integer;
+    SmallInt = integer;
+    ShortInt = integer;
+    Int64 = integer;
+    QWord = uinteger;
+    GLint = integer;
+    GLuint = integer;
+    int = integer;
+    size_t = integer;
+
+    pointer = pointer;
+
+    float = float;
+    single = float;
+    double = float;
+    real = float;
+    extended = float;
+    GLfloat = float;
+
+    boolean = boolean;
+    LongBool = boolean;
+
+    string = string;
+    shortstring = string;
+    ansistring = string;
+    widechar = string;
+
+    char = char;
+    PChar = ^char;
+    PPChar = ^Pchar;
+
+    PByte = ^Byte;
+    PLongInt = ^LongInt;
+    PLongWord = ^LongWord;
+    PInteger = ^Integer;
+
+    Handle = integer;
+
+var
+    write, writeLn, read, readLn, flush, CreateDir: procedure;
+
+    halt:procedure;
+
+    GetEnumName:function:shortstring;
+    TypeInfo:function:Integer;
+
+    lo:function:Integer;
+
+    init:procedure;
+
+    StrLen:function : integer;
+    odd, even : function : boolean;
+
+    Length : function : integer;
+
+    Now : function : integer;
+
+    new, dispose, FillChar, Move : procedure;
+
+    trunc, round : function : integer;
+    abs, sqr : function : integer;
+
+    StrPas, FormatDateTime, copy, delete, str, PosS, trim, LowerCase : function : shortstring;
+    pos : function : integer;
+    StrToInt : function : integer;
+    SetLength, val : procedure;
+    _pchar : function : PChar;
+    pchar2str : function : string;
+    memcpy : procedure;
+
+     min, max:function:integer;
+    assign, rewrite, rewrite_2, reset, reset_2, flush, BlockWrite, BlockRead, close : procedure;
+    FileExists, DirectoryExists, eof : function : boolean;
+    ExtractFileName : function : string;
+
+    ParamCount : function : integer;
+    ParamStr : function : string;
+
+    arctan2, power: function : float;
+
+    //TypeInfo, GetEnumName : function : shortstring;
+
+    UTF8ToUnicode, WrapText: function : shortstring;
+
+    GetMem : function : pointer;
+    FreeMem : procedure;
+
+    BeginThread, ThreadSwitch : procedure;
+    InterlockedIncrement, InterlockedDecrement : procedure;
+
+    random : function : integer;
+    randomize : procedure;
+
+    Assigned : function : boolean;
+
+    //EnumToStr : function : string;
+
+    initParams : procedure;
+
+    Load_GL_VERSION_2_0 : procedure;
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/pas2cSystem.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,134 @@
+system;
+{This file contains functions that are external}
+type
+    uinteger = uinteger;
+    Integer = integer;
+    LongInt = integer;
+    LongWord = uinteger;
+    Cardinal = uinteger;
+    PtrInt = integer;
+    Word = uinteger;
+    Byte = integer;
+    SmallInt = integer;
+    ShortInt = integer;
+    Int64 = integer;
+    QWord = uinteger;
+    GLint = integer;
+    GLuint = integer;
+    GLenum = integer;
+
+    int = integer;
+    size_t = integer;
+
+    pointer = pointer;
+
+    float = float;
+    single = float;
+    double = float;
+    real = float;
+    extended = float;
+    GLfloat = float;
+
+    boolean = boolean;
+    LongBool = boolean;
+
+    string = string;
+    shortstring = string;
+    ansistring = string;
+    widechar = string;
+
+    char = char;
+    PChar = ^char;
+    PPChar = ^Pchar;
+
+    PByte = ^Byte;
+    PWord = ^Word;
+    PLongInt = ^LongInt;
+    PLongWord = ^LongWord;
+    PInteger = ^Integer;
+
+    Handle = integer;
+
+    png_structp = pointer;
+    png_size_t = integer;
+
+var
+    false, true: boolean;
+
+    ord, Succ, Pred : function : integer;
+    inc, dec, Low, High, Lo, Hi : function : integer;
+
+    IOResult : integer;
+    exit, break, halt, continue : procedure;
+
+    TextFile, File : Handle;
+    FileMode : integer;
+    exitcode : integer;
+    stdout, stderr : Handle;
+
+    sqrt, cos, sin: function : float;
+    pi : float;
+
+    sizeof : function : integer;
+
+    glGetString : function : pchar;
+
+    glBegin, glBindTexture, glBlendFunc, glClear, glClearColor,
+    glColor4ub, glColorMask, glColorPointer, glDeleteTextures,
+    glDisable, glDisableClientState, glDrawArrays, glEnable,
+    glEnableClientState, glEnd, glGenTextures, glGetIntegerv,
+    glHint, glLineWidth, glLoadIdentity, glMatrixMode, glPopMatrix,
+    glPushMatrix, glReadPixels, glRotatef, glScalef, glTexCoord2f,
+    glTexCoordPointer, glTexImage2D, glTexParameterf,
+    glTexParameteri, glTranslatef, glVertex2d, glVertexPointer,
+    glViewport, glext_LoadExtension, glDeleteRenderbuffersEXT,
+    glDeleteFramebuffersEXT, glGenFramebuffersEXT,
+    glGenRenderbuffersEXT, glBindFramebufferEXT,
+    glBindRenderbufferEXT, glRenderbufferStorageEXT,
+    glFramebufferRenderbufferEXT, glFramebufferTexture2DEXT,
+    glUniformMatrix4fv, glVertexAttribPointer, glCreateShader,
+    glShaderSource, glCompileShader, glGetShaderiv, glGetShaderInfoLog,
+    glCreateProgram, glAttachShader, glBindAttribLocation, glLinkProgram,
+    glDeleteShader, glGetProgramiv, glGetProgramInfoLog, glUseProgram,
+    glUniform1i, glGetUniformLocation, glEnableVertexAttribArray,
+    glGetError, glDeleteProgram, glDeleteBuffers,
+    glGenBuffers, glBufferData, glBindBuffer, glewInit,
+    glUniform4f, glDisableVertexAttribArray, glTexEnvi : procedure;
+
+    GL_BGRA, GL_BLEND, GL_CLAMP_TO_EDGE, GL_COLOR_ARRAY,
+    GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_DEPTH_COMPONENT,
+    GL_DITHER, GL_EXTENSIONS, GL_FALSE, GL_FASTEST, GL_LINEAR,
+    GL_LINE_LOOP, GL_LINES, GL_LINE_SMOOTH, GL_LINE_STRIP,
+    GL_MAX_TEXTURE_SIZE, GL_MODELVIEW, GL_ONE_MINUS_SRC_ALPHA,
+    GL_PERSPECTIVE_CORRECTION_HINT, GL_PROJECTION, GL_QUADS,
+    GL_RENDERER, GL_RGBA, GL_RGBA8, GL_SRC_ALPHA, GL_TEXTURE_2D,
+    GL_TEXTURE_COORD_ARRAY, GL_TEXTURE_MAG_FILTER,
+    GL_TEXTURE_MIN_FILTER, GL_TEXTURE_PRIORITY, GL_TEXTURE_WRAP_S,
+    GL_TEXTURE_WRAP_T, GL_TRIANGLE_FAN, GL_TRUE, GL_VENDOR,
+    GL_VERSION, GL_VERTEX_ARRAY, GLenum,  GL_FRAMEBUFFER_EXT,
+    GL_RENDERBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
+    GL_COLOR_ATTACHMENT0_EXT, GL_FLOAT, GL_UNSIGNED_BYTE, GL_COMPILE_STATUS,
+    GL_INFO_LOG_LENGTH, GL_LINK_STATUS, GL_VERTEX_SHADER, GL_FRAGMENT_SHADER,
+    GL_NO_ERROR, GL_ARRAY_BUFFER, GL_STATIC_DRAW, GLEW_OK,
+    GL_AUX_BUFFERS, GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE, GL_ADD: integer;
+
+    TThreadId : function : integer;
+
+    _strconcat, _strappend, _strprepend, _chrconcat : function : string;
+    _strcompare, _strncompare, _strcomparec : function : boolean;
+
+    png_structp, png_set_write_fn, png_get_io_ptr,
+    png_get_libpng_ver, png_create_write_struct,
+    png_create_info_struct, png_destroy_write_struct,
+    png_write_row, png_set_ihdr, png_write_info,
+    png_write_end : procedure;
+
+    clear_filelist_hook, add_file_hook, idb_loader_hook, mainloop_hook, drawworld_hook : procedure;
+    SDL_InitPatch : procedure;
+
+    PHYSFS_init, PHYSFS_deinit, PHYSFS_mount, PHYSFS_readBytes : function : LongInt;
+    PHYSFSRWOPS_openRead, PHYSFSRWOPS_openWrite, PHYSFS_openRead : function : pointer;
+    PHYSFS_eof, PHYSFS_close, PHYSFS_exists : function : boolean;
+
+    hedgewarsMountPackages, physfsReaderSetBuffer, hedgewarsMountPackage : procedure;
+    physfsReader : function : pointer;
Binary file hedgewars/res/hwengine.ico has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/res/hwengine.rc	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,2 @@
+MAINICON ICON "res/hwengine.ico"
+
--- a/hedgewars/sdlmain/SDLMain.m	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/sdlmain/SDLMain.m	Tue Jan 21 22:53:15 2014 +0100
@@ -18,21 +18,21 @@
 @end
 
 /* Use this flag to determine whether we use SDLMain.nib or not */
-#define		SDL_USE_NIB_FILE	0
+#define     SDL_USE_NIB_FILE    0
 
 /* Use this flag to determine whether we use CPS (docking) or not */
-#define		SDL_USE_CPS		1
+#define     SDL_USE_CPS     1
 #ifdef SDL_USE_CPS
 /* Portions of CPS.h */
 typedef struct CPSProcessSerNum
 {
-	UInt32		lo;
-	UInt32		hi;
+    UInt32      lo;
+    UInt32      hi;
 } CPSProcessSerNum;
 
-extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
-extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
-extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
+extern OSErr    CPSGetCurrentProcess( CPSProcessSerNum *psn);
+extern OSErr    CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
+extern OSErr    CPSSetFrontProcess( CPSProcessSerNum *psn);
 
 #endif /* SDL_USE_CPS */
 
@@ -198,8 +198,8 @@
 /* Replacement for NSApplicationMain */
 static void CustomApplicationMain (int argc, char **argv)
 {
-    NSAutoreleasePool	*pool = [[NSAutoreleasePool alloc] init];
-    SDLMain				*sdlMain;
+    NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];
+    SDLMain             *sdlMain;
 
     /* Ensure the application object is initialised */
     [SDLApplication sharedApplication];
--- a/hedgewars/uAI.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uAI.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -359,6 +359,10 @@
 
             if GoInfo.FallPix >= FallPixForBranching then
                 Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
+
+            if (StartTicks > GameTicks - 1500) and (not StopThinking) then
+                SDL_Delay(1000);
+
             end {while};
 
         if BestRate > BaseRate then
@@ -370,12 +374,13 @@
 function Think(Me: PGear): LongInt; cdecl; export;
 var BackMe, WalkMe: TGear;
     switchCount: LongInt;
-    StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i: Longword;
+    currHedgehogIndex, itHedgehog, switchesNum, i: Longword;
     switchImmediatelyAvailable: boolean;
     Actions: TActions;
 begin
 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
 StartTicks:= GameTicks;
+
 currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
 itHedgehog:= currHedgehogIndex;
 switchesNum:= 0;
@@ -397,7 +402,7 @@
             Actions.Score:= 0;
             if switchesNum > 0 then
                 begin
-                if not switchImmediatelyAvailable  then
+                if (not switchImmediatelyAvailable)  then
                     begin
                     // when AI has to use switcher, make it cost smth unless they have a lot of switches
                     if (switchCount < 10) then Actions.Score:= (-27+switchCount*3)*4000;
@@ -421,8 +426,8 @@
             or (itHedgehog = currHedgehogIndex)
             or BestActions.isWalkingToABetterPlace;
 
-        if (StartTicks > GameTicks - 1500) and (not StopThinking) then
-            SDL_Delay(1000);
+            if (StartTicks > GameTicks - 1500) and (not StopThinking) then
+                SDL_Delay(1000);
 
         if (BestActions.Score < -1023) and (not BestActions.isWalkingToABetterPlace) then
             begin
@@ -437,11 +442,13 @@
     i:= 12;
     while (not StopThinking) and (BestActions.Count = 0) and (i > 0) do
         begin
+
 (*
         // Maybe this would get a bit of movement out of them? Hopefully not *toward* water. Need to check how often he'd choose that strategy
         if SuddenDeathDmg and ((hwRound(BackMe.Y)+cWaterRise*2) > cWaterLine) then
             AddBonus(hwRound(BackMe.X), hwRound(BackMe.Y), 250, -40);
 *)
+
         FillBonuses(true);
         WalkMe:= BackMe;
         Actions.Count:= 0;
--- a/hedgewars/uAIActions.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uAIActions.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -45,7 +45,7 @@
     aia_Put        = $800A;
     aia_waitAngle  = $800B;
     aia_waitAmmoXY = $800C;
-    
+
     aim_push       = $8000;
     aim_release    = $8001;
     ai_specmask    = $8000;
@@ -55,7 +55,7 @@
         X, Y, Param: LongInt;
         Time: Longword;
         end;
-        
+
     TActions = record
         Count, Pos: Longword;
         actions: array[0..Pred(MAXACTIONS)] of TAction;
@@ -109,7 +109,7 @@
     WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]);
     if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then
         WriteLnToConsole('AI action Wait X = '+IntToStr(Action.Param)+', current X = '+IntToStr(hwRound(Me^.X)))
-        
+
     else if (Action.Action = aia_AwareExpl) then
         WriteLnToConsole('Aware X = ' + IntToStr(Action.X) + ', Y = ' + IntToStr(Action.Y));
     end
@@ -165,10 +165,10 @@
     {$ENDIF}
     if (Action and ai_specmask) <> 0 then
         case Action of
-            aia_Weapon: 
+            aia_Weapon:
                 SetWeapon(TAmmoType(Param));
-            
-            aia_WaitXL: 
+
+            aia_WaitXL:
                 if hwRound(Me^.X) = Param then
                     begin
                     Action:= aia_LookLeft;
@@ -182,12 +182,12 @@
                         exit
                         end
                     else
-                        begin 
+                        begin
                         CheckHang(Me);
                         exit
                         end;
-                            
-            aia_WaitXR: 
+
+            aia_WaitXR:
                 if hwRound(Me^.X) = Param then
                     begin
                     Action:= aia_LookRight;
@@ -201,7 +201,7 @@
                         exit
                         end
                     else
-                        begin 
+                        begin
                         CheckHang(Me);
                         exit
                         end;
@@ -222,24 +222,24 @@
                 else ParseCommand('-right', true);
             aia_AwareExpl:
                 AwareOfExplosion(X, Y, Param);
-            
+
             aia_HJump:
                 ParseCommand('hjump', true);
-            
+
             aia_LJump:
                 ParseCommand('ljump', true);
-            
+
             aia_Skip:
                 ParseCommand('skip', true);
-            
+
             aia_Put:
                 doPut(X, Y, true);
-                
+
             aia_waitAngle:
                 if LongInt(Me^.Angle) <> Abs(Param) then exit;
 
             aia_waitAmmoXY:
-                if (CurAmmoGear <> nil) and ((hwRound(CurAmmoGear^.X) <> X) or (hwRound(CurAmmoGear^.Y) <> Y)) then 
+                if (CurAmmoGear <> nil) and ((hwRound(CurAmmoGear^.X) <> X) or (hwRound(CurAmmoGear^.Y) <> Y)) then
                     exit;
             end
         else
@@ -249,7 +249,7 @@
                 case Param of
                 aim_push:
                 s:= '+' + s;
-                
+
                 aim_release:
                 s:= '-' + s;
             end
--- a/hedgewars/uAIAmmoTests.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uAIAmmoTests.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -247,7 +247,7 @@
                     or (y < 0)
                     or (trunc(x) > LAND_WIDTH)
                     or (trunc(y) > LAND_HEIGHT)
-                    or not TestCollExcludingObjects(trunc(x), trunc(y), 5)
+                    or (not TestCollExcludingObjects(trunc(x), trunc(y), 5))
                     or (timer = 0)
                 end;
             EX:= trunc(x);
@@ -779,7 +779,7 @@
     Targ:= Targ; // avoid compiler hint
 
     if Level < 3 then trackFall:= afTrackFall
-    else trackFall:= 0;
+        else trackFall:= 0;
 
     ap.ExplR:= 0;
     ap.Time:= 0;
@@ -1241,7 +1241,7 @@
     x:= x + dx;
     dy:= dy + cGravityf;
     y:= y + dy;
-    
+
     if TestColl(trunc(x), trunc(y), 3) then
         t:= 0;
 until t = 0;
@@ -1251,7 +1251,7 @@
 
 if Level = 1 then
     valueResult:= RateExplosion(Me, EX, EY, 76, afTrackFall or afErasesLand)
-else 
+else
     valueResult:= RateExplosion(Me, EX, EY, 76);
 
 if (valueResult > 0) then
--- a/hedgewars/uAILandMarks.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uAILandMarks.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -1,7 +1,7 @@
 unit uAILandMarks;
 
 interface
-const 
+const
     markWalkedHere = $01;
     markHJumped    = $02;
     markLJumped    = $04;
@@ -35,13 +35,13 @@
 
 function  checkMark(X, Y: LongInt; mark: byte) : boolean;
 begin
-    checkMark:= ((X and LAND_WIDTH_MASK) = 0) 
-        and ((Y and LAND_HEIGHT_MASK) = 0) 
+    checkMark:= ((X and LAND_WIDTH_MASK) = 0)
+        and ((Y and LAND_HEIGHT_MASK) = 0)
         and ((marks[Y shr gr, X shr gr] and mark) <> 0)
 end;
 
 procedure clearAllMarks;
-var 
+var
     Y, X: Longword;
 begin
     for Y:= 0 to Pred(HEIGHT) do
@@ -50,7 +50,7 @@
 end;
 
 procedure clearMarks(mark: byte);
-var 
+var
     Y, X: Longword;
 begin
     for Y:= 0 to Pred(HEIGHT) do
@@ -62,7 +62,7 @@
 begin
     WIDTH:= LAND_WIDTH shr gr;
     HEIGHT:= LAND_HEIGHT shr gr;
-    
+
     SetLength(marks, HEIGHT, WIDTH);
 end;
 
--- a/hedgewars/uAIMisc.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uAIMisc.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -53,7 +53,17 @@
     X, Y: LongInt;
     Radius: LongInt;
     Score: LongInt;
-    end;
+     end;
+
+Tbonuses = record
+          Count : Longword;
+          ar    : array[0..Pred(MAXBONUS)] of TBonus;
+       end;
+
+Twalkbonuses =  record
+        Count: Longword;
+        ar: array[0..Pred(MAXBONUS div 8)] of TBonus;  // don't use too many
+        end;
 
 procedure initModule;
 procedure freeModule;
@@ -82,22 +92,16 @@
 var ThinkingHH: PGear;
     Targets: TTargets;
 
-    bonuses: record
-        Count: Longword;
-        ar: array[0..Pred(MAXBONUS)] of TBonus;
-        end;
+    bonuses: Tbonuses;
 
-    walkbonuses: record
-        Count: Longword;
-        ar: array[0..Pred(MAXBONUS div 8)] of TBonus;  // don't use too many
-        end;
+    walkbonuses: Twalkbonuses;
 
 const KillScore = 200;
 var friendlyfactor: LongInt = 300;
 var dmgMod: real = 1.0;
 
 implementation
-uses uCollisions, uVariables, uUtils, uLandTexture, uGearsUtils;
+uses uCollisions, uVariables, uUtils, uGearsUtils;
 
 var
     KnownExplosion: record
@@ -127,13 +131,13 @@
     if  (((Gear^.Kind = gtHedgehog) and
             (Gear <> ThinkingHH) and
             (Gear^.Health > Gear^.Damage) and
-            not(Gear^.Hedgehog^.Team^.hasgone)) or
+            (not Gear^.Hedgehog^.Team^.hasgone)) or
         ((Gear^.Kind = gtExplosives) and
             (Gear^.Health > Gear^.Damage)) or
         ((Gear^.Kind = gtMine) and
             (Gear^.Health = 0) and
              (Gear^.Damage < 35))
-             )  and 
+             )  and
         (Targets.Count < 256) then
         begin
         with Targets.ar[Targets.Count] do
@@ -155,7 +159,7 @@
                     Score:= Gear^.Damage - Gear^.Health;
                     inc(f)
                     end
-                else 
+                else
                     begin
                     Score:= Gear^.Health - Gear^.Damage;
                     inc(e)
@@ -163,7 +167,7 @@
                 end
             else if Gear^.Kind = gtExplosives then
                 Score:= Gear^.Health - Gear^.Damage
-            else if Gear^.Kind = gtMine then 
+            else if Gear^.Kind = gtMine then
                 Score:= max(0,35-Gear^.Damage);
             end;
         inc(Targets.Count)
@@ -384,20 +388,20 @@
                     dmg := 1 + trunc((dY - 0.4) * 70);
                     exit(dmg)
                     end
-                else 
+                else
                     begin
                     dxdy:= abs(dX)+abs(dY);
-                    if ((Kind = gtMine) and (dxdy > 0.35)) or 
-                       ((Kind = gtExplosives) and 
+                    if ((Kind = gtMine) and (dxdy > 0.35)) or
+                       ((Kind = gtExplosives) and
                             (((State and gstTmpFlag <> 0) and (dxdy > 0.35)) or
-                             ((State and gstTmpFlag = 0) and 
-                                ((abs(odX) > 0.15) or ((abs(odY) > 0.15) and 
+                             ((State and gstTmpFlag = 0) and
+                                ((abs(odX) > 0.15) or ((abs(odY) > 0.15) and
                                 (abs(odX) > 0.02))) and (dxdy > 0.35)))) then
                         begin
                         dmg := trunc(dxdy * 25);
                         exit(dmg)
                         end
-                    else if (Kind = gtExplosives) and not((abs(odX) > 0.15) or ((abs(odY) > 0.15) and (abs(odX) > 0.02))) and (dY > 0.2) then
+                    else if (Kind = gtExplosives) and (not(abs(odX) > 0.15) or ((abs(odY) > 0.15) and (abs(odX) > 0.02))) and (dY > 0.2) then
                         begin
                         dmg := trunc(dy * 70);
                         exit(dmg)
@@ -436,20 +440,20 @@
                     dmg := trunc((dY - 0.4) * 70);
                     exit(dmg);
                     end
-                else 
+                else
                     begin
                     dxdy:= abs(dX)+abs(dY);
-                    if ((Kind = gtMine) and (dxdy > 0.4)) or 
-                       ((Kind = gtExplosives) and 
+                    if ((Kind = gtMine) and (dxdy > 0.4)) or
+                       ((Kind = gtExplosives) and
                             (((State and gstTmpFlag <> 0) and (dxdy > 0.4)) or
-                             ((State and gstTmpFlag = 0) and 
-                                ((abs(odX) > 0.15) or ((abs(odY) > 0.15) and 
+                             ((State and gstTmpFlag = 0) and
+                                ((abs(odX) > 0.15) or ((abs(odY) > 0.15) and
                                 (abs(odX) > 0.02))) and (dxdy > 0.35)))) then
                         begin
                         dmg := trunc(dxdy * 50);
                         exit(dmg)
                         end
-                    else if (Kind = gtExplosives) and not((abs(odX) > 0.15) or ((abs(odY) > 0.15) and (abs(odX) > 0.02))) and (dY > 0.2) then
+                    else if (Kind = gtExplosives) and (not(abs(odX) > 0.15) or ((abs(odY) > 0.15) and (abs(odX) > 0.02))) and (dY > 0.2) then
                         begin
                         dmg := trunc(dy * 70);
                         exit(dmg)
@@ -520,7 +524,7 @@
                     begin
                     dX:= (0.005 * dmg + 0.01) / Density;
                     dY:= dX;
-                    if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and 
+                    if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and
                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
                         ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then
                         dX:= 0;
@@ -606,8 +610,8 @@
                 pY:= Point.y-2;
                 fallDmg:= 0;
                 if (Flags and afSetSkip <> 0) then skip:= true;
-                if not(dead) and (Flags and afTrackFall <> 0) and (Score > 0) and (power < Score) then
-                    if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and 
+                if (not dead) and (Flags and afTrackFall <> 0) and (Score > 0) and (power < Score) then
+                    if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and
                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
                         ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then
                         fallDmg:= trunc(TraceShoveFall(pX, pY, 0, dY, Targets.ar[i]) * dmgMod)
@@ -701,7 +705,7 @@
                 end;
             if dmg > 0 then
                 begin
-                if not(dead) and (Score > 0) and (dmg < Score) then
+                if (not dead) and (Score > 0) and (dmg < Score) then
                     begin
                     pX:= Point.x;
                     pY:= Point.y;
@@ -709,9 +713,9 @@
                     dY:= gdY * dmg / Density;
                     if dX < 0 then dX:= dX - 0.01
                     else dX:= dX + 0.01;
-                    if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and 
+                    if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and
                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
-                        ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then 
+                        ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then
                        dX:= 0;
                     if (x and LAND_WIDTH_MASK = 0) and ((y+cHHRadius+2) and LAND_HEIGHT_MASK = 0) and
                        (Land[y+cHHRadius+2, x] and lfIndestructible <> 0) then
--- a/hedgewars/uAmmos.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uAmmos.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -50,7 +50,7 @@
 var StoreCnt: Longword;
 
 implementation
-uses uLocale, uVariables, uCommands, uUtils, uCaptions, uDebug;
+uses uVariables, uCommands, uUtils, uCaptions, uDebug;
 
 type TAmmoCounts = array[TAmmoType] of Longword;
      TAmmoArray = array[TAmmoType] of TAmmo;
@@ -132,22 +132,22 @@
             inc(Ammoz[a].SkipTurns,10000);
     if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
         ammos[a]:= AMMO_INFINITE
-        end 
-        
+        end
+
     else
         ammos[a]:= AMMO_INFINITE;
-    if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then 
+    if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
         InitialCounts[Pred(StoreCnt)][a]:= cnt
     else
         InitialCounts[Pred(StoreCnt)][a]:= ammos[a];
     end;
-    
+
     for a:= Low(TAmmoType) to High(TAmmoType) do
         begin
         newAmmos[a]:= Ammoz[a].Ammo;
         newAmmos[a].Count:= ammos[a]
         end;
-        
+
 FillAmmoStore(StoresList[Pred(StoreCnt)], newAmmos)
 end;
 
@@ -272,7 +272,7 @@
             Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1];
             Ammo^[Slot, ami + 1].Count:= 0
             end;
-    until not b;
+    until (not b);
 AmmoMenuInvalidated:= true;
 end;
 
@@ -311,7 +311,7 @@
             if (AmmoType = Ammo) then
                 if Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns then
                     exit(Count)
-                else 
+                else
                     exit(0);
         inc(ami)
     end;
@@ -482,7 +482,7 @@
 
 for a:= Low(TAmmoType) to High(TAmmoType) do
     newAmmos[a]:= Ammoz[a].Ammo;
-    
+
 for i:= 0 to Pred(StoreCnt) do
     begin
     for a:= Low(TAmmoType) to High(TAmmoType) do
@@ -499,8 +499,8 @@
 
 procedure chAddAmmoStore(var descr: shortstring);
 begin
-descr:= ''; // avoid compiler hint
-AddAmmoStore
+    descr:= ''; // avoid compiler hint
+    AddAmmoStore
 end;
 
 procedure initModule;
--- a/hedgewars/uCaptions.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uCaptions.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -15,7 +15,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  *)
- 
+
 {$INCLUDE "options.inc"}
 
 unit uCaptions;
@@ -45,12 +45,14 @@
 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
 begin
     if cOnlyStats then exit;
+    if Length(s) = 0 then
+        exit;
     if Captions[Group].Text <> s then
         begin
         FreeTexture(Captions[Group].Tex);
         Captions[Group].Tex:= nil
         end;
-    
+
     if Captions[Group].Tex = nil then
         begin
         Captions[Group].Color:= Color;
--- a/hedgewars/uChat.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uChat.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -42,7 +42,7 @@
     Width: LongInt;
     s: shortstring;
     end;
-    TChatCmd = (quit, pause, finish, showhistory, fullscreen);
+    TChatCmd = (ccQuit, ccPause, ccFinish, ccShowHistory, ccFullScreen);
 
 var Strs: array[0 .. MaxStrIndex] of TChatLine;
     MStrs: array[0 .. MaxStrIndex] of shortstring;
@@ -228,7 +228,7 @@
 else if (s[1] = '-') and (s[Length(s)] = '-') then
     x:= 3;
 
-if not CurrentTeam^.ExtDriven and (x <> 0) then
+if (not CurrentTeam^.ExtDriven) and (x <> 0) then
     for c:= 0 to Pred(TeamsCount) do
         if (TeamsArray[c] = CurrentTeam) then
             t:= c;
--- a/hedgewars/uCollisions.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uCollisions.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -54,7 +54,7 @@
 
 function  TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
 
-// returns: negative sign if going downhill to left, value is steepness (noslope/error = _0, 45° = _0_5)
+// returns: negative sign if going downhill to left, value is steepness (noslope/error = _0, 45 = _0_5)
 function  CalcSlopeBelowGear(Gear: PGear): hwFloat;
 function  CalcSlopeNearGear(Gear: PGear; dirX, dirY: LongInt): hwFloat;
 function  CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
@@ -92,7 +92,7 @@
 if (Count > (MAXRECTSINDEX-20)) then
     begin
     t:= GearsList;
-    while (t <> nil) and (t^.Kind <> gtMine) do 
+    while (t <> nil) and (t^.Kind <> gtMine) do
         t:= t^.NextGear;
     if (t <> nil) then
         t^.State:= t^.State or gmDelete
@@ -234,7 +234,7 @@
 
     for i:= 0 to Pred(Count) do
         with cinfos[i] do
-            if  (Gear <> cGear) and 
+            if  (Gear <> cGear) and
                 ((mx > x) xor (Dir > 0)) and
                 (
                   ((cGear^.Kind in [gtHedgehog, gtMine, gtKnife]) and ((Gear^.State and gstNotKickable) = 0)) or
@@ -300,7 +300,7 @@
             if (Gear <> cGear) and
                ((myr > y) xor (Dir > 0)) and
                (Gear^.State and gstNotKickable = 0) and
-               (cGear^.Kind in [gtHedgehog, gtMine, gtKnife, gtExplosives]) and 
+               (cGear^.Kind in [gtHedgehog, gtMine, gtKnife, gtExplosives]) and
                (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) then
                     begin
                     with cGear^ do
@@ -327,7 +327,7 @@
 begin
 Gear^.X:= Gear^.X + ShiftX;
 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
-if withGear then 
+if withGear then
     TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir)
 else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir);
 Gear^.X:= Gear^.X - ShiftX;
@@ -394,7 +394,7 @@
   TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir)
 else
   TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir);
-  
+
 Gear^.X:= Gear^.X - int2hwFloat(ShiftX);
 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
 end;
@@ -583,7 +583,7 @@
     isColl, bSucc: Boolean;
 begin
 
-if dirY <> 0 then 
+if dirY <> 0 then
     begin
     y:= hwRound(Gear^.Y) + Gear^.Radius * dirY;
     gx:= hwRound(Gear^.X);
--- a/hedgewars/uCommands.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uCommands.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -106,7 +106,7 @@
         begin
         if TrustedSource or t^.Trusted then
             begin
-            if t^.Rand and (not CheckNoTeamOrHH) then 
+            if t^.Rand and (not CheckNoTeamOrHH) then
                 CheckSum:= CheckSum xor LongWord(SDLNet_Read32(@CmdStr)) xor LongWord(s[0]) xor GameTicks;
             t^.Handler(s);
             end;
@@ -139,7 +139,7 @@
 if (Message and gmLeft) <> 0 then
     ParseCommand('/-left', true)
 else if (Message and gmRight) <> 0 then
-    ParseCommand('/-right', true) 
+    ParseCommand('/-right', true)
 else if (Message and gmUp) <> 0 then
     ParseCommand('/-up', true)
 else if (Message and gmDown) <> 0 then
--- a/hedgewars/uConsole.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uConsole.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -49,11 +49,11 @@
 begin
 {$IFNDEF NOCONSOLE}
     WriteToConsole(s);
-    lastConsoleline:= s;
 {$IFNDEF ANDROID}
     WriteLn(stderr, '');
 {$ENDIF}
 {$ENDIF}
+    lastConsoleline:= s;
 end;
 
 function ShortStringAsPChar(s: shortstring) : PChar;
--- a/hedgewars/uConsts.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uConsts.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -93,18 +93,18 @@
 // lfObject and lfBasic are only to be different *graphically*  in all other ways they should be treated the same
     lfBasic          = $8000;  // white
     lfIndestructible = $4000;  // red
-    lfObject         = $2000;  
+    lfObject         = $2000;
     lfDamaged        = $1000;  //
     lfIce            = $0800;  // blue
     lfBouncy         = $0400;  // green
     lfLandMask       = $FF00;  // upper byte is used for terrain, not objects.
 
-    lfCurrentHog     = $0080;  // CurrentHog.  It is also used to flag crates, for convenience of AI.  Since an active hog would instantly collect the crate, this doesn't impact play
+    lfCurrentHog     = $0080;  // CurrentHog.  It is also used to flag crates, for convenience of AI.  Since an active hog would instantly collect the crate, this does not impact play
     lfNotCurrentMask = $FF7F;  // inverse of above. frequently used
     lfObjMask        = $007F;  // lower 7 bits used for hogs
     lfNotObjMask     = $FF80;  // inverse of above.
-    // lower byte is for objects. 
-    // consists of 0-127 counted for object checkins and $80 as a bit flag for current hog. 
+    // lower byte is for objects.
+    // consists of 0-127 counted for object checkins and $80 as a bit flag for current hog.
     lfAllObjMask     = $00FF;  // lfCurrentHog or lfObjMask
 
 
@@ -115,11 +115,13 @@
     MAXNAMELEN = 192;
     MAXROPEPOINTS = 3840;
 
+    {$IFNDEF PAS2C}
     // some opengl headers do not have these macros
     GL_BGR              = $80E0;
     GL_BGRA             = $80E1;
     GL_CLAMP_TO_EDGE    = $812F;
     GL_TEXTURE_PRIORITY = $8066;
+    {$ENDIF}
 
     cVisibleWater       : LongInt = 128;
     cTeamHealthWidth    : LongInt = 128;
@@ -150,7 +152,7 @@
     cBlowTorchC    = 6;
     cakeDmg =   75;
 
-    cKeyMaxIndex = 1023;
+    cKeyMaxIndex = 1600;
     cKbdMaxIndex = 65536;//need more room for the modifier keys
 
     cFontBorder = 2;
@@ -239,11 +241,11 @@
 
     cMaxSlotIndex       = 9;
     cMaxSlotAmmoIndex   = 5;
-    
+
     // ai hints
     aihUsualProcessing    = $00000000;
     aihDoesntMatter       = $00000001;
-    
+
     // ammo properties
     ammoprop_Timerable    = $00000001;
     ammoprop_Power        = $00000002;
@@ -261,7 +263,7 @@
     ammoprop_Utility      = $00001000;
     ammoprop_Effect       = $00002000;
     ammoprop_SetBounce    = $00004000;
-    ammoprop_NeedUpDown   = $00008000;//Used by TouchInterface to show or hide up/down widgets 
+    ammoprop_NeedUpDown   = $00008000;//Used by TouchInterface to show or hide up/down widgets
     ammoprop_OscAim       = $00010000;
     ammoprop_NoMoveAfter  = $00020000;
     ammoprop_Track        = $00040000;
@@ -296,7 +298,7 @@
     htTransparent = $08;
 
     NoPointX = Low(LongInt);
-    cTargetPointRef : TPoint = (X: NoPointX; Y: 0);
+    cTargetPointRef : TPoint = (x: NoPointX; y: 0);
 
     kSystemSoundID_Vibrate = $00000FFF;
 
--- a/hedgewars/uCursor.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uCursor.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -25,7 +25,7 @@
 var x, y: LongInt;
 begin
     SDL_GetMouseState(@x, @y);
-    
+
     if(x <> cScreenWidth div 2) or (y <> cScreenHeight div 2) then
     begin
         handlePositionUpdate(x - cScreenWidth div 2, y - cScreenHeight div 2);
--- a/hedgewars/uFloat.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uFloat.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -39,7 +39,6 @@
  *)
 interface
 
-{$IFDEF FPC}
 {$IFDEF ENDIAN_LITTLE}
 type hwFloat = record
     isNegative: boolean;
@@ -63,7 +62,9 @@
 // The implemented operators
 
 operator = (const z1, z2: hwFloat) z : boolean; inline;
-
+{$IFDEF PAS2C}
+operator <> (const z1, z2: hwFloat) z : boolean; inline;
+{$ENDIF}
 operator + (const z1, z2: hwFloat) z : hwFloat; inline;
 operator - (const z1, z2: hwFloat) z : hwFloat; inline;
 operator - (const z1: hwFloat) z : hwFloat; inline;
@@ -95,14 +96,9 @@
 function hwSign(r: hwFloat): LongInt; inline; // Returns an integer with value 1 and sign of parameter r.
 function hwSignf(r: real): LongInt; inline; // Returns an integer with value 1 and sign of parameter r.
 function isZero(const z: hwFloat): boolean; inline;
-{$IFDEF FPC}
-{$J-}
-{$ENDIF}
+
 {$WARNINGS OFF}
-
-
 // some hwFloat constants
-
 const  _1div1024: hwFloat = (isNegative: false; QWordValue:     4194304);
       _1div10000: hwFloat = (isNegative: false; QWordValue:      429496);
       _1div50000: hwFloat = (isNegative: false; QWordValue:       85899);
@@ -150,20 +146,20 @@
           _0_999: hwFloat = (isNegative: false; QWordValue:  4290672328);
               _0: hwFloat = (isNegative: false; QWordValue:           0);
               _1: hwFloat = (isNegative: false; QWordValue:  4294967296);
-            _1_2: hwFloat = (isNegative: false; QWordValue:  1288490189*4);
+            _1_2: hwFloat = (isNegative: false; QWordValue:  4294967296 * 6 div 5 + 1);
             _1_5: hwFloat = (isNegative: false; QWordValue:  4294967296 * 3 div 2);
             _1_6: hwFloat = (isNegative: false; QWordValue:  4294967296 * 8 div 5);
             _1_9: hwFloat = (isNegative: false; QWordValue:  8160437862);
               _2: hwFloat = (isNegative: false; QWordValue:  4294967296 * 2);
             _2_4: hwFloat = (isNegative: false; QWordValue:  4294967296 * 12 div 5);
               _3: hwFloat = (isNegative: false; QWordValue:  4294967296 * 3);
-            _3_2: hwFloat = (isNegative: false; QWordValue:  3435973837*4);
+            _3_2: hwFloat = (isNegative: false; QWordValue:  4294967296 * 16 div 5);
              _PI: hwFloat = (isNegative: false; QWordValue: 13493037704);
               _4: hwFloat = (isNegative: false; QWordValue:  4294967296 * 4);
             _4_5: hwFloat = (isNegative: false; QWordValue:  4294967296 * 9 div 2);
               _5: hwFloat = (isNegative: false; QWordValue:  4294967296 * 5);
               _6: hwFloat = (isNegative: false; QWordValue:  4294967296 * 6);
-            _6_4: hwFloat = (isNegative: false; QWordValue:  3435973837 * 8);
+            _6_4: hwFloat = (isNegative: false; QWordValue:  4294967296 * 32 div 5);
               _7: hwFloat = (isNegative: false; QWordValue:  4294967296 * 7);
              _10: hwFloat = (isNegative: false; QWordValue:  4294967296 * 10);
              _12: hwFloat = (isNegative: false; QWordValue:  4294967296 * 12);
@@ -194,18 +190,11 @@
          cLittle: hwFloat = (isNegative: false; QWordValue:           1);
          cHHKick: hwFloat = (isNegative: false; QWordValue:    42949673);  // _0_01
 {$WARNINGS ON}
-{$ENDIF}
-
-{$IFNDEF FPC}
-type hwFloat = Extended;
-{$ENDIF}
 
 implementation
 uses uSinTable;
 
 
-{$IFDEF FPC}
-
 function int2hwFloat (const i: LongInt) : hwFloat; inline;
 begin
 int2hwFloat.isNegative:= i < 0;
@@ -225,6 +214,13 @@
     z:= (z1.isNegative = z2.isNegative) and (z1.QWordValue = z2.QWordValue);
 end;
 
+{$IFDEF PAS2C}
+operator <> (const z1, z2: hwFloat) z : boolean; inline;
+begin
+    z:= (z1.isNegative <> z2.isNegative) or (z1.QWordValue <> z2.QWordValue);
+end;
+{$ENDIF}
+
 operator + (const z1, z2: hwFloat) z : hwFloat; inline;
 begin
 if z1.isNegative = z2.isNegative then
@@ -294,95 +290,95 @@
 
 operator - (const z1: hwFloat) z : hwFloat; inline;
 begin
-z:= z1;
-z.isNegative:= not z.isNegative
+    z:= z1;
+    z.isNegative:= not z.isNegative
 end;
 
 
 operator * (const z1, z2: hwFloat) z : hwFloat; inline;
 begin
-z.isNegative:= z1.isNegative xor z2.isNegative;
-z.QWordValue:= QWord(z1.Round) * z2.Frac + QWord(z1.Frac) * z2.Round + ((QWord(z1.Frac) * z2.Frac) shr 32);
-z.Round:= z.Round + QWord(z1.Round) * z2.Round;
+    z.isNegative:= z1.isNegative xor z2.isNegative;
+    z.QWordValue:= QWord(z1.Round) * z2.Frac + QWord(z1.Frac) * z2.Round + ((QWord(z1.Frac) * z2.Frac) shr 32);
+    z.Round:= z.Round + QWord(z1.Round) * z2.Round;
 end;
 
 operator * (const z1: hwFloat; const z2: LongInt) z : hwFloat; inline;
 begin
-z.isNegative:= z1.isNegative xor (z2 < 0);
-z.QWordValue:= z1.QWordValue * abs(z2)
+    z.isNegative:= z1.isNegative xor (z2 < 0);
+    z.QWordValue:= z1.QWordValue * abs(z2)
 end;
 
 operator / (const z1: hwFloat; z2: hwFloat) z : hwFloat; inline;
 var t: QWord;
 begin
-z.isNegative:= z1.isNegative xor z2.isNegative;
-z.Round:= z1.QWordValue div z2.QWordValue;
-t:= z1.QWordValue - z2.QWordValue * z.Round;
-z.Frac:= 0;
+    z.isNegative:= z1.isNegative xor z2.isNegative;
+    z.Round:= z1.QWordValue div z2.QWordValue;
+    t:= z1.QWordValue - z2.QWordValue * z.Round;
+    z.Frac:= 0;
 
-if t <> 0 then
-    begin
-    while ((t and $FF00000000000000) = 0) and ((z2.QWordValue and $FF00000000000000) = 0) do
+    if t <> 0 then
         begin
-        t:= t shl 8;
-        z2.QWordValue:= z2.QWordValue shl 8
-        end;
+        while ((t and $FF00000000000000) = 0) and ((z2.QWordValue and $FF00000000000000) = 0) do
+            begin
+            t:= t shl 8;
+            z2.QWordValue:= z2.QWordValue shl 8
+            end;
 
-    if z2.Round > 0 then
-        inc(z.QWordValue, t div z2.Round);
-    end
+        if z2.Round > 0 then
+            inc(z.QWordValue, t div z2.Round);
+        end
 end;
 
 operator / (const z1: hwFloat; const z2: LongInt) z : hwFloat; inline;
 begin
-z.isNegative:= z1.isNegative xor (z2 < 0);
-z.QWordValue:= z1.QWordValue div abs(z2)
+    z.isNegative:= z1.isNegative xor (z2 < 0);
+    z.QWordValue:= z1.QWordValue div abs(z2)
 end;
 
 function cstr(const z: hwFloat): shortstring;
 var tmpstr: shortstring;
 begin
-str(z.Round, cstr);
-if z.Frac <> 0 then
-    begin
-    str(z.Frac / $100000000, tmpstr);
-    delete(tmpstr, 1, 2);
-    cstr:= cstr + '.' + copy(tmpstr, 1, 10)
-    end;
-if z.isNegative then
-    cstr:= '-' + cstr
+    str(z.Round, cstr);
+    if z.Frac <> 0 then
+        begin
+        str(z.Frac / $100000000, tmpstr);
+        delete(tmpstr, 1, 2);
+        cstr:= cstr + '.' + copy(tmpstr, 1, 10)
+        end;
+    if z.isNegative then
+        cstr:= '-' + cstr
 end;
 
 function hwRound(const t: hwFloat): LongInt;
 begin
-if t.isNegative then
-    hwRound:= -(t.Round and $7FFFFFFF)
-else
-    hwRound:= t.Round and $7FFFFFFF
+    if t.isNegative then
+        hwRound:= -(t.Round and $7FFFFFFF)
+    else
+        hwRound:= t.Round and $7FFFFFFF
 end;
 
 function hwAbs(const t: hwFloat): hwFloat;
 begin
-hwAbs:= t;
-hwAbs.isNegative:= false
+    hwAbs:= t;
+    hwAbs.isNegative:= false
 end;
 
 function hwSqr(const t: hwFloat): hwFloat; inline;
 begin
-hwSqr.isNegative:= false;
-hwSqr.QWordValue:= ((QWord(t.Round) * t.Round) shl 32) + QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32);
+    hwSqr.isNegative:= false;
+    hwSqr.QWordValue:= ((QWord(t.Round) * t.Round) shl 32) + QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32);
 end;
 
 function hwPow(const t: hwFloat;p: LongWord): hwFloat;
 begin
-hwPow:= t;
-if p mod 2 = 0 then hwPow.isNegative:= false;
+    hwPow:= t;
+    if p mod 2 = 0 then hwPow.isNegative:= false;
 
-while p > 0 do
-    begin
-    hwPow.QWordValue:= QWord(hwPow.Round) * t.Frac + QWord(hwPow.Frac) * t.Round + ((QWord(hwPow.Frac) * t.Frac) shr 32);
-    dec(p)
-    end
+    while p > 0 do
+        begin
+        hwPow.QWordValue:= QWord(hwPow.Round) * t.Frac + QWord(hwPow.Frac) * t.Round + ((QWord(hwPow.Frac) * t.Frac) shr 32);
+        dec(p)
+        end
 end;
 
 function hwSqrt1(const t: hwFloat): hwFloat;
@@ -392,65 +388,67 @@
 var l, r: QWord;
     c: hwFloat;
 begin
-hwSqrt1.isNegative:= false;
+    hwSqrt1.isNegative:= false;
 
-if t.Round = 0 then
-    begin
-    l:= t.QWordValue;
-    r:= $100000000
-    end
-else
-    begin
-    if t.QWordValue > $FFFFFFFFFFFF then // t.Round > 65535.9999
+    if t.Round = 0 then
+        begin
+        l:= t.QWordValue;
+        r:= $100000000
+        end
+    else
         begin
-        l:= $10000000000; // 256
-        r:= $FFFFFFFFFFFF; // 65535.9999
-        end else
-        if t.QWordValue >= rThreshold then
+        if t.QWordValue > $FFFFFFFFFFFF then // t.Round > 65535.9999
             begin
-            l:= lThreshold;
-            r:= $10000000000; // 256
-            end else
-            begin
-            l:= $100000000;
-            r:= lThreshold;
-            end;
+            l:= $10000000000; // 256
+            r:= $FFFFFFFFFFFF; // 65535.9999
+            end
+        else
+            if t.QWordValue >= rThreshold then
+                begin
+                l:= lThreshold;
+                r:= $10000000000; // 256
+                end
+            else
+                begin
+                l:= $100000000;
+                r:= lThreshold;
+                end;
     end;
 
-repeat
-    c.QWordValue:= (l + r) shr 1;
-    if hwSqr(c).QWordValue > t.QWordValue then
-        r:= c.QWordValue
-    else
-        l:= c.QWordValue
-until r - l <= 1;
+    repeat
+        c.QWordValue:= (l + r) shr 1;
+        if hwSqr(c).QWordValue > t.QWordValue then
+            r:= c.QWordValue
+        else
+            l:= c.QWordValue
+    until r - l <= 1;
 
-hwSqrt1.QWordValue:= l
+    hwSqrt1.QWordValue:= l
 end;
 
 function hwSqrt(const x: hwFloat): hwFloat;
 var r, t, s, q: QWord;
     i: integer;
 begin
-hwSqrt.isNegative:= false;
+    hwSqrt.isNegative:= false;
 
-t:= $4000000000000000;
-r:= 0;
-q:= x.QWordValue;
+    t:= $4000000000000000;
+    r:= 0;
+    q:= x.QWordValue;
 
-for i:= 0 to 31 do
-    begin
-    s:= r + t;
-    r:= r shr 1;
-    if s <= q then
+    for i:= 0 to 31 do
         begin
-        dec(q, s);
-        inc(r, t);
+        s:= r + t;
+        r:= r shr 1;
+        if s <= q then
+            begin
+            dec(q, s);
+            inc(r, t);
+            end;
+        t:= t shr 2;
         end;
-    t:= t shr 2;
-    end;
 
-hwSqrt.QWordValue:= r shl 16
+    hwSqrt.QWordValue:= r shl 16
 end;
 
 
@@ -458,25 +456,26 @@
 function Distance(const dx, dy: hwFloat): hwFloat;
 var r: QWord;
 begin
-r:= dx.QWordValue or dy.QWordValue;
+    r:= dx.QWordValue or dy.QWordValue;
 
-if r < $10000 then
-    begin
-    Distance.QWordValue:= r;
-    Distance.isNegative:= false
-    end else
-    Distance:= hwSqrt(hwSqr(dx) + hwSqr(dy))
+    if r < $10000 then
+        begin
+        Distance.QWordValue:= r;
+        Distance.isNegative:= false
+        end
+    else
+        Distance:= hwSqrt(hwSqr(dx) + hwSqr(dy))
 end;
 
 function DistanceI(const dx, dy: LongInt): hwFloat;
 begin
-DistanceI:= hwSqrt(int2hwFloat(sqr(dx) + sqr(dy)))
+    DistanceI:= hwSqrt(int2hwFloat(sqr(dx) + sqr(dy)))
 end;
 
 function SignAs(const num, signum: hwFloat): hwFloat;
 begin
-SignAs.QWordValue:= num.QWordValue;
-SignAs.isNegative:= signum.isNegative
+    SignAs.QWordValue:= num.QWordValue;
+    SignAs.isNegative:= signum.isNegative
 end;
 
 function hwSign(r: hwFloat): LongInt;
@@ -549,6 +548,4 @@
     vector2Angle:= c
 end;
 
-{$ENDIF}
-
 end.
--- a/hedgewars/uGame.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGame.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -116,9 +116,11 @@
                         AddVisualGear(0, 0, vgtTeamHealthSorter);
                         AddVisualGear(0, 0, vgtSmoothWindBar);
                         {$IFDEF IPHONEOS}InitIPC;{$ENDIF}
+                        {$IFNDEF PAS2C}
                         with mobileRecord do
                             if SaveLoadingEnded <> nil then
                                 SaveLoadingEnded();
+                        {$ENDIF}
                         end;
                 end
         else ProcessGears
--- a/hedgewars/uGears.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGears.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -51,7 +51,7 @@
 uses uStore, uSound, uTeams, uRandom, uIO, uLandGraphics,
     {$IFDEF USE_TOUCH_INTERFACE}uTouch,{$ENDIF}
     uLocale, uAmmos, uStats, uVisualGears, uScript, uVariables,
-    uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
+    uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug,
     uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlersRope
     , uVisualGearsList, uGearsHandlersMess, uAI;
 
--- a/hedgewars/uGearsHandlers.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGearsHandlers.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -31,7 +31,10 @@
 
 
 
-const dirs: array[0..3] of TPoint =   ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0));
+const dirs: array[0..3] of TPoint = ((x: 0;  y: -1),
+                                     (x: 1;  y:  0),
+                                     (x: 0;  y:  1),
+                                     (x: -1; y:  0));
 
 procedure PrevAngle(Gear: PGear; dA: LongInt); inline;
 begin
--- a/hedgewars/uGearsHandlersMess.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGearsHandlersMess.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -24,7 +24,7 @@
  *            should NOT occur!
  *            Use safe functions and data types! (e.g. GetRandom() and hwFloat)
  *)
- 
+
  {$INCLUDE "options.inc"}
 
 unit uGearsHandlersMess;
@@ -394,7 +394,7 @@
         if xland <> 0 then collH := -hwSign(Gear^.dX)
         end;
     //if Gear^.AdvBounce and (collV <>0) and (collH <> 0) and (hwSqr(tdX) + hwSqr(tdY) > _0_08) then
-    if (collV <> 0) and (collH <> 0) and 
+    if (collV <> 0) and (collH <> 0) and
        (((Gear^.AdvBounce=1) and ((collV=-1) or ((tdX.QWordValue + tdY.QWordValue) > _0_2.QWordValue)))) then
  //or ((xland or land) and lfBouncy <> 0)) then
         begin
@@ -436,7 +436,7 @@
 
     if ((xland or land) and lfBouncy <> 0) and (Gear^.dX.QWordValue < _0_15.QWordValue) and (Gear^.dY.QWordValue < _0_15.QWordValue) then
         Gear^.State := Gear^.State or gstCollision;
-    
+
     if ((xland or land) and lfBouncy <> 0) and (Gear^.Radius >= 3) and
        ((Gear^.dX.QWordValue > _0_15.QWordValue) or (Gear^.dY.QWordValue > _0_15.QWordValue)) then
         begin
@@ -760,7 +760,7 @@
     yy:= hwRound(Gear^.Y);
     if draw and (WorldEdge = weWrap) and ((xx < LongInt(leftX) + 3) or (xx > LongInt(rightX) - 3)) then
         begin
-        if xx < LongInt(leftX) + 3 then 
+        if xx < LongInt(leftX) + 3 then
              xx:= rightX-3
         else xx:= leftX+3;
         Gear^.X:= int2hwFloat(xx)
@@ -1054,7 +1054,7 @@
             // no need to display remaining time anymore
             Gear^.RenderTimer:= false;
             // bee can drown when timer reached 0
-            Gear^.State:= Gear^.State and not gstSubmersible;
+            Gear^.State:= Gear^.State and (not gstSubmersible);
             end;
         end;
 end;
@@ -1235,7 +1235,7 @@
         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] <> 0) then
             inc(Gear^.Damage);
         // let's interrupt before a collision to give portals a chance to catch the bullet
-        if (Gear^.Damage = 1) and (Gear^.Tag = 0) and not(CheckLandValue(x, y, lfLandMask)) then
+        if (Gear^.Damage = 1) and (Gear^.Tag = 0) and (not CheckLandValue(x, y, lfLandMask)) then
             begin
             Gear^.Tag := 1;
             Gear^.Damage := 0;
@@ -1772,7 +1772,7 @@
                 end
             end
     else // gsttmpFlag = 0
-        if ((GameFlags and gfInfAttack = 0) and ((TurnTimeLeft = 0) or (Gear^.Hedgehog^.Gear = nil))) 
+        if ((GameFlags and gfInfAttack = 0) and ((TurnTimeLeft = 0) or (Gear^.Hedgehog^.Gear = nil)))
         or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) then
             Gear^.State := Gear^.State or gsttmpFlag;
 end;
@@ -1806,7 +1806,7 @@
     if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then
         SetLittle(Gear^.dY);
     Gear^.State := Gear^.State or gstAnimation;
-    if Gear^.Health < cBarrelHealth then Gear^.State:= Gear^.State and not gstFrozen;
+    if Gear^.Health < cBarrelHealth then Gear^.State:= Gear^.State and (not gstFrozen);
 
     if ((Gear^.dX.QWordValue <> 0)
     or (Gear^.dY.QWordValue <> 0))  then
@@ -1892,7 +1892,7 @@
                 Gear^.Message := Gear^.Message and (not (gmLJump or gmHJump));
         exit
         end;
-    if (k = gtExplosives) and (Gear^.Health < cBarrelHealth) then Gear^.State:= Gear^.State and not gstFrozen;
+    if (k = gtExplosives) and (Gear^.Health < cBarrelHealth) then Gear^.State:= Gear^.State and (not gstFrozen);
 
     if ((k <> gtExplosives) and (Gear^.Damage > 0)) or ((k = gtExplosives) and (Gear^.Health<=0)) then
         begin
@@ -2163,7 +2163,7 @@
             exit
             end
         end
-    else 
+    else
         begin
         if (Gear^.Timer = 1) and (GameTicks and $3 = 0) then
             begin
@@ -2471,9 +2471,11 @@
         begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound);
         DeleteGear(Gear);
+        {$IFNDEF PAS2C}
         with mobileRecord do
             if (performRumble <> nil) and (not fastUntilLag) then
                 performRumble(kSystemSoundID_Vibrate);
+        {$ENDIF}
         exit
         end;
     if (GameTicks and $3F) = 0 then
@@ -2502,7 +2504,7 @@
     if Gear^.AmmoType = amRubber then LandFlags:= lfBouncy
     else if cIce then LandFlags:= lfIce;
 
-    if ((Distance(tx - x, ty - y) > _256) and ((WorldEdge <> weWrap) or 
+    if ((Distance(tx - x, ty - y) > _256) and ((WorldEdge <> weWrap) or
             (
             (Distance(tx - int2hwFloat(rightX+(rx-leftX)), ty - y) > _256) and
             (Distance(tx - int2hwFloat(leftX-(rightX-rx)), ty - y) > _256)
@@ -4623,9 +4625,11 @@
     Gear^.dY.isNegative := not Gear^.dY.isNegative;
 
     Gear^.doStep := @doStepSineGunShotWork;
+    {$IFNDEF PAS2C}
     with mobileRecord do
         if (performRumble <> nil) and (not fastUntilLag) then
             performRumble(kSystemSoundID_Vibrate);
+    {$ENDIF}
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -5388,7 +5392,7 @@
         Gear^.SoundChannel:= -1;
         if GameTicks mod 40 = 0 then dec(Gear^.Health)
         end
-    else 
+    else
         begin
         if Gear^.SoundChannel = -1 then
             Gear^.SoundChannel := LoopSound(sndIceBeam);
@@ -5495,14 +5499,15 @@
                     landRect.w := min(2*iceRadius, LAND_WIDTH - landRect.x - 1);
                     landRect.h := min(2*iceRadius, LAND_HEIGHT - landRect.y - 1);
                     UpdateLandTexture(landRect.x, landRect.w, landRect.y, landRect.h, true);
-                    
+
                     // Freeze nearby mines/explosives/cases too
                     iter := GearsList;
                     while iter <> nil do
                         begin
                         if (iter^.State and gstFrozen = 0) and
-                           ((iter^.Kind = gtExplosives) or (iter^.Kind = gtCase) or (iter^.Kind = gtMine)) and 
-                           (abs(iter^.X.Round-target.x)+abs(iter^.Y.Round-target.y)+2<2*iceRadius) and (Distance(iter^.X-int2hwFloat(target.x),iter^.Y-int2hwFloat(target.y))<int2hwFloat(iceRadius*2)) then
+                           ((iter^.Kind = gtExplosives) or (iter^.Kind = gtCase) or (iter^.Kind = gtMine)) and
+                           (abs(LongInt(iter^.X.Round) - target.x) + abs(LongInt(iter^.Y.Round) - target.y) + 2 < 2 * iceRadius)
+                           and (Distance(iter^.X - int2hwFloat(target.x), iter^.Y - int2hwFloat(target.y)) < int2hwFloat(iceRadius * 2)) then
                             begin
                             for t:= 0 to 5 do
                                 begin
@@ -5629,7 +5634,7 @@
         begin
         with gi^ do CheckSum:= CheckSum xor X.round xor X.frac xor dX.round xor dX.frac xor Y.round xor Y.frac xor dY.round xor dY.frac;
         AddRandomness(CheckSum);
-        if gi^.Kind = gtGenericFaller then gi^.State:= gi^.State and not gstTmpFlag;
+        if gi^.Kind = gtGenericFaller then gi^.State:= gi^.State and (not gstTmpFlag);
         gi := gi^.NextGear
         end;
     AddPickup(Gear^.Hedgehog^, a, Gear^.Power, hwRound(Gear^.X), hwRound(Gear^.Y));
--- a/hedgewars/uGearsHandlersRope.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGearsHandlersRope.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -29,13 +29,13 @@
     uAmmos, uDebug, uUtils, uGearsHedgehog, uGearsRender;
 
 procedure doStepRopeAfterAttack(Gear: PGear);
-var 
+var
     HHGear: PGear;
     tX:     hwFloat;
 begin
     HHGear := Gear^.Hedgehog^.Gear;
     tX:= HHGear^.X;
-    if WorldWrap(HHGear) and (WorldEdge = weWrap) and 
+    if WorldWrap(HHGear) and (WorldEdge = weWrap) and
        ((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0))  then
         begin
         HHGear^.X:= tX;
@@ -70,7 +70,7 @@
     HHGear^.X := HHGear^.X + HHGear^.dX;
     HHGear^.Y := HHGear^.Y + HHGear^.dY;
     HHGear^.dY := HHGear^.dY + cGravity;
-    
+
     if (GameFlags and gfMoreWind) <> 0 then
         HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density;
 
@@ -113,7 +113,7 @@
 end;
 
 procedure doStepRopeWork(Gear: PGear);
-var 
+var
     HHGear: PGear;
     len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat;
     lx, ly, cd: LongInt;
@@ -126,7 +126,7 @@
     HHGear := Gear^.Hedgehog^.Gear;
 
     tX:= HHGear^.X;
-    if WorldWrap(HHGear) and (WorldEdge = weWrap) and 
+    if WorldWrap(HHGear) and (WorldEdge = weWrap) and
        ((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0))  then
         begin
         PlaySound(sndRopeRelease);
@@ -405,7 +405,7 @@
 end;
 
 procedure doStepRopeAttach(Gear: PGear);
-var 
+var
     HHGear: PGear;
     tx, ty, tt: hwFloat;
 begin
--- a/hedgewars/uGearsHedgehog.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGearsHedgehog.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -20,7 +20,7 @@
 
 unit uGearsHedgehog;
 interface
-uses uTypes, uGearsHandlersMess; 
+uses uTypes, uGearsHandlersMess;
 
 procedure doStepHedgehog(Gear: PGear);
 procedure AfterAttack;
@@ -126,7 +126,7 @@
             LoadHedgehogHat(HHGear^.Hedgehog^, Hat);
         end;
     // Try again in the next slot
-    if (CurAmmoType = prevAmmo) and (slot < cMaxSlotIndex) then 
+    if (CurAmmoType = prevAmmo) and (slot < cMaxSlotIndex) then
         begin
         inc(slot);
         HHGear^.MsgParam:= slot;
@@ -416,7 +416,7 @@
                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 0);
                        amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
             end;
-            if altUse and (newGear <> nil) and 
+            if altUse and (newGear <> nil) and
                ((CurAmmoGear = nil) or (CurAmmoGear^.AmmoType <> amJetpack) or (Gear^.Message and gmPrecise = 0)) then
                begin
                newGear^.dX:= newDx / newGear^.Density;
@@ -470,15 +470,15 @@
                 begin
                 elastic:=  int2hwfloat(CurWeapon^.Bounciness) / _1000;
 
-                if elastic < _1 then
-                    newGear^.Elasticity:= newGear^.Elasticity * elastic
-                else if elastic > _1 then
-                    newGear^.Elasticity:= _1 - ((_1-newGear^.Elasticity) / elastic);
-    (* Experimented with friction modifier. Didn't seem helpful
-                fric:= int2hwfloat(CurWeapon^.Bounciness) / _250;
-                if fric < _1 then newGear^.Friction:= newGear^.Friction * fric
-                else if fric > _1 then newGear^.Friction:= _1 - ((_1-newGear^.Friction) / fric)*)
-                end;
+            if elastic < _1 then
+                newGear^.Elasticity:= newGear^.Elasticity * elastic
+            else if elastic > _1 then
+                newGear^.Elasticity:= _1 - ((_1-newGear^.Elasticity) / elastic);
+(* Experimented with friction modifier. Didn't seem helpful
+            fric:= int2hwfloat(CurWeapon^.Bounciness) / _250;
+            if fric < _1 then newGear^.Friction:= newGear^.Friction * fric
+            else if fric > _1 then newGear^.Friction:= _1 - ((_1-newGear^.Friction) / fric)*)
+            end;
 
 
             uStats.AmmoUsed(CurAmmoType);
@@ -496,16 +496,15 @@
                 end;
 
             Power:= 0;
-            if (CurAmmoGear <> nil)
-                and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) = 0){check for dropping ammo from rope} then
+            if (CurAmmoGear <> nil) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) = 0){check for dropping ammo from rope} then
                 begin
-                if CurAmmoType in [amRope,amResurrector] then Message:= Message or gmAttack;
+                if CurAmmoType in [amRope,amResurrector] then
+                    Message:= Message or gmAttack;
                 CurAmmoGear^.Message:= Message
                 end
             else
                 begin
-                if not CurrentTeam^.ExtDriven
-                and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then
+                if (not CurrentTeam^.ExtDriven) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then
                     SendIPC(_S'a');
                 AfterAttack;
                 end
@@ -831,7 +830,7 @@
 var da: LongWord;
 begin
 with HHGear^.Hedgehog^ do
-    if (((CurAmmoType = amRope) or ((CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amRope))) and 
+    if (((CurAmmoType = amRope) or ((CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amRope))) and
             ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving))
     or ((CurAmmoType = amPortalGun) and ((HHGear^.State and gstMoving) <> 0)) then
         da:= 2
@@ -878,7 +877,7 @@
             end;
         if (land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0) then
             Gear^.dY:= _0;
-        Gear^.State:= Gear^.State and not gstCollision 
+        Gear^.State:= Gear^.State and (not gstCollision)
         end;
     Gear^.State:= Gear^.State or gstMoving;
     if (Gear^.State and gstHHDriven <> 0) and
@@ -904,8 +903,8 @@
 else
     begin
     land:= TestCollisionYwithGear(Gear, 1);
-    if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0) 
-    and ((land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0)) 
+    if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0)
+    and ((land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0))
     and ((Gear^.State and gstHHJumping) <> 0) then
         SetLittle(Gear^.dX);
 
@@ -933,7 +932,7 @@
             if (land and lfBouncy = 0) or (Gear^.dX.QWordValue < _0_02.QWordValue) then
                 Gear^.dY:= _0
             end;
-        Gear^.State:= Gear^.State and not gstCollision 
+        Gear^.State:= Gear^.State and (not gstCollision)
         end
     else
         Gear^.dY:= Gear^.dY + cGravity;
@@ -1058,7 +1057,7 @@
             Gear^.dY:= _0;
             Gear^.Y:= Gear^.Y + _1
             end;
-        Gear^.State:= Gear^.State and not gstCollision 
+        Gear^.State:= Gear^.State and (not gstCollision)
         end;
 
     // could become nil if ai's hog fails to respawn in ai survival
@@ -1097,6 +1096,11 @@
 else if Hedgehog^.CurAmmoType in [amShotgun, amDEagle, amSniperRifle] then
     HHGear^.Message:= 0;
 
+if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Utility) <> 0) and isInMultiShoot then
+    AllInactive:= true
+else if not isInMultiShoot then
+    AllInactive:= false;
+
 if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then
     begin
     if (Hedgehog^.CurAmmoType = amKnife) then
@@ -1344,7 +1348,7 @@
 tX:= Gear^.X;
 if WorldWrap(Gear) then
     begin
-    if (WorldEdge <> weBounce) and (Gear = CurrentHedgehog^.Gear) and 
+    if (WorldEdge <> weBounce) and (Gear = CurrentHedgehog^.Gear) and
        (CurAmmoGear <> nil) and (CurAmmoGear^.Kind =gtRope) and (CurAmmoGear^.Elasticity <> _0) then
        CurAmmoGear^.PortalCounter:= 1;
     if (WorldEdge = weWrap) and ((TestCollisionXwithGear(Gear, 1) <> 0) or (TestCollisionXwithGear(Gear, -1) <> 0))  then
--- a/hedgewars/uGearsList.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGearsList.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -159,8 +159,10 @@
     c: byte;
 begin
 inc(GCounter);
+
 AddFileLog('AddGear: #' + inttostr(GCounter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
 
+
 New(gear);
 FillChar(gear^, sizeof(TGear), 0);
 gear^.X:= int2hwFloat(X);
@@ -239,14 +241,14 @@
                         gear^.Hedgehog^.Effects[heResurrectable] := 1;
                 // this would presumably be set in the frontend
                 // if we weren't going to do that yet, would need to reinit GetRandom
-                // oh, and, randomising slightly R and B might be nice too. 
+                // oh, and, randomising slightly R and B might be nice too.
                 //gear^.Tint:= $fa00efff or ((random(80)+128) shl 16)
                 //gear^.Tint:= $faa4efff
-                //gear^.Tint:= (($e0+random(32)) shl 24) or 
+                //gear^.Tint:= (($e0+random(32)) shl 24) or
                 //             ((random(80)+128) shl 16) or
                 //             (($d5+random(32)) shl 8) or $ff
                 c:= random(32);
-                gear^.Tint:= (($e0+c) shl 24) or 
+                gear^.Tint:= (($e0+c) shl 24) or
                              ((random(90)+128) shl 16) or
                              (($d5+c) shl 8) or $ff
                 end;
@@ -286,8 +288,8 @@
                     Health:= random(vobFrameTicks);
                     if gear^.Timer = 0 then Timer:= random(vobFramesCount);
                     Damage:= (random(2) * 2 - 1) * (vobVelocity + random(vobVelocity)) * 8;
-                    Tint:= (ExplosionBorderColor and RMask shl RShift) or 
-                           (ExplosionBorderColor and GMask shl GShift) or 
+                    Tint:= (ExplosionBorderColor and RMask shl RShift) or
+                           (ExplosionBorderColor and GMask shl GShift) or
                            (ExplosionBorderColor and BMask shl BShift) or $FF;
                     end
                 end;
@@ -651,7 +653,7 @@
             begin
             t:= max(Gear^.Damage, Gear^.Health);
             Gear^.Damage:= t;
-            if ((not SuddenDeathDmg and (WaterOpacity < $FF)) or (SuddenDeathDmg and (WaterOpacity < $FF)))
+            if (((not SuddenDeathDmg) and (WaterOpacity < $FF)) or (SuddenDeathDmg and (WaterOpacity < $FF)))
             and (hwRound(Gear^.Y) < cWaterLine + 256) then
                 spawnHealthTagForHH(Gear, t);
             end;
--- a/hedgewars/uGearsRender.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGearsRender.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -23,6 +23,18 @@
 interface
 uses uTypes, uConsts, GLunit, uFloat, SDLh;
 
+type
+   Tar = record
+            X, Y: hwFloat;
+            dLen: hwFloat;
+            b : boolean;
+         end;
+   TRopePoints = record
+            Count     : Longword;
+            HookAngle : GLfloat;
+            ar        : array[0..MAXROPEPOINTS] of Tar;
+            rounded   : array[0..MAXROPEPOINTS + 2] of TVertex2f;
+         end;
 procedure RenderGear(Gear: PGear; x, y: LongInt);
 
 var RopePoints: record
@@ -83,6 +95,7 @@
     if (X1 = X2) and (Y1 = Y2) then
         begin
         //OutError('WARNING: zero length rope line!', false);
+        DrawRopeLine:= 0;
         exit
         end;
     eX:= 0;
@@ -143,7 +156,7 @@
                 DrawSprite(sprRopeNode, x - 2, y - 2, 0)
             end
     end;
-DrawRopeLine:= roplen;
+    DrawRopeLine:= roplen;
 end;
 
 procedure DrawRope(Gear: PGear);
@@ -1276,7 +1289,7 @@
                         begin
                         if isInLag and (Gear^.FlightTime < 256) then
                             inc(Gear^.FlightTime, 8)
-                        else if not isInLag and (Gear^.FlightTime > 0) then
+                        else if (not isInLag) and (Gear^.FlightTime > 0) then
                             dec(Gear^.FlightTime, 8);
                         if Gear^.FlightTime > 0 then
                             Tint($FF, $FF, $FF, $FF-min(255,Gear^.FlightTime));
--- a/hedgewars/uGearsUtils.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uGearsUtils.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -23,7 +23,7 @@
 uses uTypes, uFloat;
 
 procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword); inline;
-procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord); 
+procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord);
 
 function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
 procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
@@ -47,8 +47,8 @@
 procedure ShotgunShot(Gear: PGear);
 
 procedure SetAllToActive;
-procedure SetAllHHToActive; inline;
 procedure SetAllHHToActive(Ice: boolean);
+procedure SetAllHHToActive(); inline;
 
 function  GetAmmo(Hedgehog: PHedgehog): TAmmoType;
 function  GetUtility(Hedgehog: PHedgehog): TAmmoType;
@@ -64,7 +64,7 @@
 implementation
 uses uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc,
     uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore,
-    uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug, 
+    uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug,
     uGearsList, Math, uVisualGearsList, uGearsHandlersMess,
     uGearsHedgehog;
 
@@ -199,7 +199,7 @@
 i:= _1;
 if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then
     i:= _1_5;
-if (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog <> nil) and 
+if (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog <> nil) and
    (Gear^.Hedgehog^.King or (Gear^.Hedgehog^.Effects[heFrozen] > 0)) then
     ModifyDamage:= hwRound(cDamageModifier * dmg * i * cDamagePercent * _0_5 * _0_01)
 else
@@ -251,20 +251,20 @@
                         end;
                     end
                 end;
-        if (GameFlags and gfKarma <> 0) and (GameFlags and gfInvulnerable = 0) and 
+        if (GameFlags and gfKarma <> 0) and (GameFlags and gfInvulnerable = 0) and
            (CurrentHedgehog^.Effects[heInvulnerable] = 0) then
             begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid
             inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
             CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog;
             spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
             end;
-        uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);    
+        uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);
         end;
     end else
     //else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure
         Gear^.Hedgehog:= AttackerHog;
     inc(Gear^.Damage, Damage);
-    
+
     ScriptCall('onGearDamage', Gear^.UID, Damage);
 end;
 
@@ -277,7 +277,7 @@
 AllInactive:= false;
 HHGear^.Active:= true;
 end;
-    
+
 procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
 begin
 if Hedgehog^.Effects[heFrozen] <> 0 then exit;
@@ -302,7 +302,7 @@
 end;
 
 procedure CheckHHDamage(Gear: PGear);
-var 
+var
     dmg: LongInt;
     i: LongWord;
     particle: PVisualGear;
@@ -340,7 +340,7 @@
 
 
 procedure CalcRotationDirAngle(Gear: PGear);
-var 
+var
     dAngle: real;
 begin
     // Frac/Round to be kind to JS as of 2012-08-27 where there is yet no int64/uint64
@@ -358,7 +358,7 @@
 end;
 
 function CheckGearDrowning(var Gear: PGear): boolean;
-var 
+var
     skipSpeed, skipAngle, skipDecay: hwFloat;
     i, maxDrops, X, Y: LongInt;
     vdX, vdY: real;
@@ -389,7 +389,7 @@
         vdX:= hwFloat2Float(Gear^.dX);
         vdY:= hwFloat2Float(Gear^.dY);
         // this could perhaps be a tiny bit higher.
-        if  (cWaterLine + 64 + Gear^.Radius > Y) and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) 
+        if  (cWaterLine + 64 + Gear^.Radius > Y) and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed)
         and (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then
             begin
             Gear^.dY.isNegative := true;
@@ -425,9 +425,9 @@
                     else
                         Gear^.doStep := @doStepDrowningGear;
                         if Gear^.Kind = gtFlake then
-                            exit // skip splashes 
+                            exit // skip splashes
                 end
-            else if (Y > cWaterLine + cVisibleWater*4) and 
+            else if (Y > cWaterLine + cVisibleWater*4) and
                     ((Gear <> CurrentHedgehog^.Gear) or (CurAmmoGear = nil) or (CurAmmoGear^.State and gstSubmersible = 0)) then
                 Gear^.doStep:= @doStepDrowningGear;
             if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius))
@@ -435,7 +435,7 @@
             and (CurAmmoGear^.dY < _0_01))) then
                 if Gear^.Density * Gear^.dY > _1 then
                     PlaySound(sndSplash)
-                else if Gear^.Density * Gear^.dY > _0_5 then 
+                else if Gear^.Density * Gear^.dY > _0_5 then
                     PlaySound(sndSkip)
                 else
                     PlaySound(sndDroplet2);
@@ -447,7 +447,7 @@
         and (CurAmmoGear^.dY < _0_01)))) then
             begin
             splash:= AddVisualGear(X, cWaterLine, vgtSplash);
-            if splash <> nil then 
+            if splash <> nil then
                 with splash^ do
                 begin
                 Scale:= hwFloat2Float(Gear^.Density / _3 * Gear^.dY);
@@ -470,12 +470,12 @@
                         dY := dY - vdY / 5;
                         if splash <> nil then
                             begin
-                            if splash^.Scale > 1 then 
+                            if splash^.Scale > 1 then
                                 begin
                                 dX:= dX * power(splash^.Scale,0.3333); // tone down the droplet height further
                                 dY:= dY * power(splash^.Scale, 0.3333)
                                 end
-                            else 
+                            else
                                 begin
                                 dX:= dX * splash^.Scale;
                                 dY:= dY * splash^.Scale
@@ -489,7 +489,8 @@
         end
     else
         begin
-        if not (Gear^.Kind in [gtJetpack, gtBee]) then Gear^.State:= Gear^.State and not gstSubmersible;  // making it temporary for most gears is more attractive I think
+        if (not ((Gear^.Kind = gtJetpack) or (Gear^.Kind = gtBee))) then
+            Gear^.State:= (Gear^.State and (not gstSubmersible));  // making it temporary for most gears is more attractive I think
         CheckGearDrowning := false
         end
 end;
@@ -512,7 +513,7 @@
     gear^.Hedgehog^.Effects[hePoisoned] := 0;
     if (CurrentHedgehog^.Effects[heResurrectable] = 0) or ((CurrentHedgehog^.Effects[heResurrectable] <> 0)
           and (Gear^.Hedgehog^.Team^.Clan <> CurrentHedgehog^.Team^.Clan)) then
-        with CurrentHedgehog^ do 
+        with CurrentHedgehog^ do
             begin
             inc(Team^.stats.AIKills);
             FreeTexture(Team^.AIKillsTex);
@@ -529,7 +530,7 @@
         sparkles^.Tint:= tempTeam^.Clan^.Color shl 8 or $FF;
         //sparkles^.Angle:= random(360);
         end;
-    FindPlace(gear, false, 0, LAND_WIDTH, true); 
+    FindPlace(gear, false, 0, LAND_WIDTH, true);
     if gear <> nil then
         begin
         AddVisualGear(hwRound(gear^.X), hwRound(gear^.Y), vgtExplosion);
@@ -587,6 +588,7 @@
     y, sy: LongInt;
     ar: array[0..1023] of TPoint;
     ar2: array[0..2047] of TPoint;
+    temp: TPoint;
     cnt, cnt2: Longword;
     delta: LongInt;
     ignoreNearObjects, ignoreOverlap, tryAgain: boolean;
@@ -594,7 +596,7 @@
 ignoreNearObjects:= false; // try not skipping proximity at first
 ignoreOverlap:= false; // this not only skips proximity, but allows overlapping objects (barrels, mines, hogs, crates).  Saving it for a 3rd pass.  With this active, winning AI Survival goes back to virtual impossibility
 tryAgain:= true;
-if WorldEdge <> weNone then 
+if WorldEdge <> weNone then
     begin
     Left:= max(Left, LongInt(leftX) + Gear^.Radius);
     Right:= min(Right,rightX-Gear^.Radius)
@@ -614,7 +616,7 @@
                 repeat
                     inc(y, 2);
                 until (y >= cWaterLine) or
-                        (not ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) = 0)) or 
+                        ((not ignoreOverlap) and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) = 0)) or
                         (ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask) = 0));
 
                 sy:= y;
@@ -622,8 +624,8 @@
                 repeat
                     inc(y);
                 until (y >= cWaterLine) or
-                        (not ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) <> 0)) or 
-                        (ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask) <> 0)); 
+                        ((not ignoreOverlap) and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) <> 0)) or
+                        (ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask) <> 0));
 
                 if (y - sy > Gear^.Radius * 2)
                     and (((Gear^.Kind = gtExplosives)
@@ -648,12 +650,15 @@
                 end;
 
             if cnt > 0 then
-                with ar[GetRandom(cnt)] do
+                begin
+                temp := ar[GetRandom(cnt)];
+                with temp do
                     begin
                     ar2[cnt2].x:= x;
                     ar2[cnt2].y:= y;
                     inc(cnt2)
                     end
+                end
         until (x + Delta > Right);
 
         dec(Delta, 60)
@@ -667,12 +672,15 @@
     end;
 
 if cnt2 > 0 then
-    with ar2[GetRandom(cnt2)] do
+    begin
+    temp := ar2[GetRandom(cnt2)];
+    with temp do
         begin
         Gear^.X:= int2hwFloat(x);
         Gear^.Y:= int2hwFloat(y);
         AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
         end
+    end
     else
     begin
     OutError('Can''t find place for Gear', false);
@@ -718,7 +726,7 @@
     if (TestCollisionX(Gear, hwSign(Gear^.dX)) <> 0)
     or (TestCollisionY(Gear, hwSign(Gear^.dY)) <> 0) then
         Gear^.State := Gear^.State or gstCollision
-    else 
+    else
         Gear^.State := Gear^.State and (not gstCollision)
 end;
 
@@ -887,14 +895,14 @@
     begin
     dec(i);
     Gear:= t^.ar[i];
-    if ((Ammo^.Kind = gtFlame) or (Ammo^.Kind = gtBlowTorch)) and 
+    if ((Ammo^.Kind = gtFlame) or (Ammo^.Kind = gtBlowTorch)) and
        (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.Effects[heFrozen] > 255) then
         Gear^.Hedgehog^.Effects[heFrozen]:= max(255,Gear^.Hedgehog^.Effects[heFrozen]-10000);
     tmpDmg:= ModifyDamage(Damage, Gear);
     if (Gear^.State and gstNoDamage) = 0 then
         begin
 
-        if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then 
+        if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then
             begin
             VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit);
             if VGear <> nil then
@@ -945,7 +953,7 @@
                 end
             else
                 Gear^.State:= Gear^.State or gstWinner;
-            if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then 
+            if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then
                 begin
                 if (Ammo^.Hedgehog^.Gear <> nil) then
                     Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable);
@@ -1056,9 +1064,9 @@
     s:= 0;
     SetLength(GearsNearArray, s);
     t := GearsList;
-    while t <> nil do 
+    while t <> nil do
         begin
-        if (t^.Kind = Kind) 
+        if (t^.Kind = Kind)
             and ((X - t^.X)*(X - t^.X) + (Y - t^.Y)*(Y-t^.Y) < int2hwFloat(r)) then
             begin
             inc(s);
@@ -1241,7 +1249,7 @@
             Gear^.dX.isNegative:= false;
             Gear^.X:= int2hwfloat(LongInt(leftX) + Gear^.Radius)
             end
-        else 
+        else
             begin
             RightImpactTimer:= 333;
             Gear^.dX.isNegative:= true;
@@ -1253,7 +1261,7 @@
     else if WorldEdge = weSea then
         begin
         if (hwRound(Gear^.Y) > cWaterLine) and (Gear^.State and gstSubmersible <> 0) then
-            Gear^.State:= Gear^.State and not gstSubmersible
+            Gear^.State:= Gear^.State and (not gstSubmersible)
         else
             begin
             Gear^.State:= Gear^.State or gstSubmersible;
@@ -1269,7 +1277,7 @@
 * Window in the sky (Gear moved high into the sky, Y is used to determine X) [unfortunately, not a safe thing to do. shame, I thought aerial bombardment would be kinda neat
 This one would be really easy to freeze game unless it was flagged unfortunately.
 
-    else 
+    else
         begin
         Gear^.X:= int2hwFloat(PlayWidth)*int2hwFloat(min(max(0,hwRound(Gear^.Y)),PlayHeight))/PlayHeight;
         Gear^.Y:= -_2048-_256-_256;
--- a/hedgewars/uIO.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uIO.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -51,8 +51,7 @@
             loTime: Word;
             case byte of
             1: (len: byte;
-                cmd: Char;
-                X, Y: LongInt);
+                cmd: Char);
             2: (str: shortstring);
             end;
 
@@ -122,6 +121,7 @@
 procedure ParseIPCCommand(s: shortstring);
 var loTicks: Word;
 begin
+
 case s[1] of
      '!': begin AddFileLog('Ping? Pong!'); isPonged:= true; end;
      '?': SendIPC(_S'!');
@@ -177,10 +177,10 @@
 end;
 
 procedure LoadRecordFromFile(fileName: shortstring);
-var f: file;
-    ss: shortstring = '';
-    i: LongInt;
-    s: shortstring;
+var f  : File;
+    ss : shortstring = '';
+    i  : LongInt;
+    s  : shortstring;
 begin
 
 // set RDNLY on file open
@@ -188,7 +188,6 @@
 {$I-}
 assign(f, fileName);
 reset(f, 1);
-
 tryDo(IOResult = 0, 'Error opening file ' + fileName, true);
 
 i:= 0; // avoid compiler hints
@@ -196,13 +195,13 @@
 repeat
     BlockRead(f, s[1], 255 - Length(ss), i);
     if i > 0 then
-        begin
+    begin
         s[0]:= char(i);
         ss:= ss + s;
         while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
             begin
             ParseIPCCommand(copy(ss, 2, byte(ss[1])));
-            Delete(ss, 1, Succ(byte(ss[1])))
+            Delete(ss, 1, Succ(byte(ss[1])));
             end
         end
 until i = 0;
@@ -221,7 +220,11 @@
 
 function isSyncedCommand(c: char): boolean;
 begin
-    isSyncedCommand:= (c in ['+', '#', 'L', 'l', 'R', 'r', 'U', 'u', 'D', 'd', 'Z', 'z', 'A', 'a', 'S', 'j', 'J', ',', 'c', 'N', 'p', 'P', 'w', 't', '1', '2', '3', '4', '5']) or ((c >= #128) and (c <= char(128 + cMaxSlotIndex)))
+    case c of
+        '+', '#', 'L', 'l', 'R', 'r', 'U', 'u', 'D', 'd', 'Z', 'z', 'A', 'a', 'S', 'j', 'J', ',', 'c', 'N', 'p', 'P', 'w', 't', '1', '2', '3', '4', '5': isSyncedCommand:= true;
+    else
+        isSyncedCommand:= ((c >= #128) and (c <= char(128 + cMaxSlotIndex)))
+    end
 end;
 
 procedure flushBuffer();
@@ -240,20 +243,20 @@
     begin
     if s[0] > #251 then
         s[0]:= #251;
-        
+
     SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]);
-    
+
     AddFileLog('[IPC out] '+ sanitizeCharForLog(s[1]));
     inc(s[0], 2);
-    
+
     if isSyncedCommand(s[1]) then
         begin
         if sendBuffer.count + byte(s[0]) >= cSendBufferSize then
             flushBuffer();
-            
+
         Move(s, sendBuffer.buf[sendBuffer.count], byte(s[0]) + 1);
         inc(sendBuffer.count, byte(s[0]) + 1);
-        
+
         if (s[1] = 'N') or (s[1] = '#') then
             flushBuffer();
         end else
@@ -302,8 +305,8 @@
     begin
     if sendBuffer.count = 0 then
         SendIPC(_S'+');
-        
-     flushBuffer()    
+
+     flushBuffer()
     end
 end;
 
@@ -367,8 +370,8 @@
             AddFileLog('got cmd "N": time '+IntToStr(hiTicks shl 16 + headcmd^.loTime))
              end;
         'p': begin
-            x32:= SDLNet_Read32(@(headcmd^.X));
-            y32:= SDLNet_Read32(@(headcmd^.Y));
+            x32:= SDLNet_Read32(@(headcmd^.str[2]));
+            y32:= SDLNet_Read32(@(headcmd^.str[6]));
             doPut(x32, y32, false)
              end;
         'P': begin
@@ -377,8 +380,8 @@
             // SDLNet_Read16(@(headcmd^.Y)) == cScreenHeight - CursorPoint.Y - WorldDy;
             if CurrentTeam^.ExtDriven then
                begin
-               TargetCursorPoint.X:= LongInt(SDLNet_Read32(@(headcmd^.X))) + WorldDx;
-               TargetCursorPoint.Y:= cScreenHeight - LongInt(SDLNet_Read32(@(headcmd^.Y))) - WorldDy;
+               TargetCursorPoint.X:= LongInt(SDLNet_Read32(@(headcmd^.str[2]))) + WorldDx;
+               TargetCursorPoint.Y:= cScreenHeight - LongInt(SDLNet_Read32(@(headcmd^.str[6]))) - WorldDy;
                if not bShowAmmoMenu and autoCameraOn then
                     CursorPoint:= TargetCursorPoint
                end
@@ -388,7 +391,7 @@
         'h': ParseCommand('hogsay ' + copy(headcmd^.str, 2, Pred(headcmd^.len)), true);
         '1'..'5': ParseCommand('timer ' + headcmd^.cmd, true);
         else
-            if (headcmd^.cmd >= #128) and (headcmd^.cmd <= char(128 + cMaxSlotIndex)) then
+            if (byte(headcmd^.cmd) >= 128) and (byte(headcmd^.cmd) <= 128 + cMaxSlotIndex) then
                 ParseCommand('slot ' + char(byte(headcmd^.cmd) - 79), true)
                 else
                 OutError('Unexpected protocol command: ' + headcmd^.cmd, True)
@@ -421,7 +424,7 @@
 if CheckNoTeamOrHH or isPaused then
     exit;
 bShowFinger:= false;
-if not CurrentTeam^.ExtDriven and bShowAmmoMenu then
+if (not CurrentTeam^.ExtDriven) and bShowAmmoMenu then
     begin
     bSelected:= true;
     exit
@@ -471,7 +474,7 @@
     lastcmd:= nil;
     isPonged:= false;
     SocketString:= '';
-    
+
     hiTicks:= 0;
     flushDelayTicks:= 0;
     sendBuffer.count:= 0;
@@ -483,6 +486,7 @@
     SDLNet_FreeSocketSet(fds);
     SDLNet_TCP_Close(IPCSock);
     SDLNet_Quit();
+
 end;
 
 end.
--- a/hedgewars/uInputHandler.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uInputHandler.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -49,7 +49,7 @@
 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
 
 implementation
-uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug, uPhysFSLayer;
+uses uConsole, uCommands, uVariables, uConsts, uUtils, uDebug, uPhysFSLayer;
 
 const
     LSHIFT = $0200;
@@ -57,7 +57,7 @@
     LALT   = $0800;
     RALT   = $1000;
     LCTRL  = $2000;
-    RCTRL  = $4000; 
+    RCTRL  = $4000;
 
 var tkbd: array[0..cKbdMaxIndex] of boolean;
     KeyNames: array [0..cKeyMaxIndex] of string[15];
@@ -91,16 +91,16 @@
 (*
 procedure MaskModifier(var code: LongInt; Modifier: LongWord);
 begin
-    if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT; 
-    if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT; 
-    if(Modifier and KMOD_LALT) <> 0 then code:= code or LALT; 
-    if(Modifier and KMOD_RALT) <> 0 then code:= code or LALT; 
-    if(Modifier and KMOD_LCTRL) <> 0 then code:= code or LCTRL; 
-    if(Modifier and KMOD_RCTRL) <> 0 then code:= code or LCTRL; 
+    if(Modifier and KMOD_LSHIFT) <> 0 then code:= code or LSHIFT;
+    if(Modifier and KMOD_RSHIFT) <> 0 then code:= code or LSHIFT;
+    if(Modifier and KMOD_LALT) <> 0 then code:= code or LALT;
+    if(Modifier and KMOD_RALT) <> 0 then code:= code or LALT;
+    if(Modifier and KMOD_LCTRL) <> 0 then code:= code or LCTRL;
+    if(Modifier and KMOD_RCTRL) <> 0 then code:= code or LCTRL;
 end;
 *)
 procedure MaskModifier(Modifier: shortstring; var code: LongInt);
-var mod_ : shortstring;
+var mod_ : shortstring = '';
     ModifierCount, i: LongInt;
 begin
 if Modifier = '' then exit;
@@ -112,7 +112,7 @@
 SplitByChar(Modifier, mod_, ':');//remove the first mod: part
 Modifier:= mod_;
 for i:= 0 to ModifierCount do
-    begin 
+    begin
     mod_:= '';
     SplitByChar(Modifier, mod_, ':');
     if (Modifier = 'lshift')                    then code:= code or LSHIFT;
@@ -175,7 +175,7 @@
             LocalMessage:= LocalMessage or gmSwitch
         else if CurrentBinds[code] = '+precise' then
             LocalMessage:= LocalMessage or gmPrecise;
-            
+
         ParseCommand(CurrentBinds[code], Trusted);
         if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
             ParseCommand('gencmd R', true)
@@ -183,7 +183,7 @@
     else if (CurrentBinds[code][1] = '+') then
         begin
         if CurrentBinds[code] = '+precise' then
-            LocalMessage:= LocalMessage and not(gmPrecise);
+            LocalMessage:= LocalMessage and (not gmPrecise);
         s:= CurrentBinds[code];
         s[1]:= '-';
         ParseCommand(s, Trusted);
@@ -193,7 +193,7 @@
     else
         begin
         if CurrentBinds[code] = 'switch' then
-            LocalMessage:= LocalMessage and not(gmSwitch)
+            LocalMessage:= LocalMessage and (not gmSwitch)
         end
     end
 end;
@@ -246,7 +246,7 @@
     s:= shortstring(sdl_getkeyname(i));
     //WriteLnToConsole('uInputHandler - ' + IntToStr(i) + ': ' + s + ' ' + IntToStr(cKeyMaxIndex));
     if s = 'unknown key' then KeyNames[i]:= ''
-    else 
+    else
         begin
         for t:= 1 to Length(s) do
             if s[t] = ' ' then
@@ -404,10 +404,10 @@
             if ControllerNumAxes[j] > 20 then
                 ControllerNumAxes[j]:= 20;
             //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20;
-            
+
             if ControllerNumHats[j] > 20 then
                 ControllerNumHats[j]:= 20;
-                
+
             if ControllerNumButtons[j] > 20 then
                 ControllerNumButtons[j]:= 20;
 
@@ -492,7 +492,7 @@
                     val(copy(l, i, 3), b);
                     p:= p + char(b);
                     inc(i, 3)
-                    end 
+                    end
                 else
                     begin
                     p:= p + l[i];
@@ -505,7 +505,7 @@
                 l:= copy(l, i + 1, length(l) - i);
                 if l <> 'default' then
                     begin
-                    if (length(l) = 2) and (l[1] = '\') then 
+                    if (length(l) = 2) and (l[1] = '\') then
                         l:= l[1]
                     else if (l[1] = '"') and (l[length(l)] = '"') then
                         l:= copy(l, 2, length(l) - 2);
@@ -517,7 +517,7 @@
             end;
 
         pfsClose(f)
-        end 
+        end
         else
             AddFileLog('[BINDS] file not found');
 end;
@@ -547,7 +547,7 @@
 if b = 0 then
     OutError(errmsgUnknownVariable + ' "' + id + '"', false)
 else
-    begin 
+    begin
     // add bind: first check if this cmd is already bound, and remove old bind
     i:= cKbdMaxIndex;
     repeat
--- a/hedgewars/uLand.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uLand.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -37,7 +37,7 @@
 
 procedure ResizeLand(width, height: LongWord);
 var potW, potH: LongInt;
-begin 
+begin
 potW:= toPowerOf2(width);
 potH:= toPowerOf2(height);
 if (potW <> LAND_WIDTH) or (potH <> LAND_HEIGHT) then
@@ -127,7 +127,7 @@
 
     // vertical
     s:= LAND_HEIGHT;
-    
+
     for x:= 0 to LAND_WIDTH - 1 do
         for y:= 0 to LAND_HEIGHT - 1 do
             if Land[y, x] = 0 then
@@ -136,7 +136,7 @@
                     for i:= max(s, y - 8) to y - 1 do
                         begin
                         if ((x + i) and 16) = 0 then c:= c1 else c:= c2;
-                        
+
                         if (cReducedQuality and rqBlurryLand) = 0 then
                             LandPixels[i, x]:= c
                         else
@@ -151,17 +151,17 @@
                 if s + 8 > y then
                     begin
                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
-                    
+
                     if (cReducedQuality and rqBlurryLand) = 0 then
                         LandPixels[y, x]:= c
                     else
                         LandPixels[y div 2, x div 2]:= c
-                    end;            
+                    end;
                 end;
-                
+
     // horizontal
     s:= LAND_WIDTH;
-    
+
     for y:= 0 to LAND_HEIGHT - 1 do
         for x:= 0 to LAND_WIDTH - 1 do
             if Land[y, x] = 0 then
@@ -170,7 +170,7 @@
                     for i:= max(s, x - 8) to x - 1 do
                         begin
                         if ((y + i) and 16) = 0 then c:= c1 else c:= c2;
-                        
+
                         if (cReducedQuality and rqBlurryLand) = 0 then
                             LandPixels[y, i]:= c
                         else
@@ -185,12 +185,12 @@
                 if s + 8 > x then
                     begin
                     if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
-                    
+
                     if (cReducedQuality and rqBlurryLand) = 0 then
                         LandPixels[y, x]:= c
                     else
                         LandPixels[y div 2, x div 2]:= c
-                    end;            
+                    end;
                 end
 end;
 
@@ -382,7 +382,7 @@
                 dec(l, TemplateCounts[cTemplateFilter]);
             until l < 0;
             end else getRandom(1);
-        
+
         case cTemplateFilter of
         0: OutError('Ask unC0Rr about what you did wrong', true);
         1: SelectTemplate:= SmallTemplates[getrandom(TemplateCounts[cTemplateFilter])];
@@ -443,12 +443,12 @@
 
     LandSurface2LandPixels(tmpsurf);
     SDL_FreeSurface(tmpsurf);
-    
+
     if gameFlags and gfShoppaBorder <> 0 then DrawShoppaBorder;
-    
+
     for x:= leftX+2 to rightX-2 do
         for y:= topY+2 to LAND_HEIGHT-3 do
-            if (Land[y, x] = 0) and 
+            if (Land[y, x] = 0) and
                (((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or
                ((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then
             begin
@@ -456,16 +456,16 @@
                     begin
                     if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then
                         LandPixels[y, x]:= LandPixels[y, x-1]
-                        
+
                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then
                         LandPixels[y, x]:= LandPixels[y, x+1]
-                        
+
                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then
                         LandPixels[y, x]:= LandPixels[y-1, x]
-                        
+
                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then
                         LandPixels[y, x]:= LandPixels[y+1, x];
-                        
+
                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
                     end;
@@ -480,25 +480,25 @@
                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or
                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then
-                    
+
                 begin
-                
+
                 if (cReducedQuality and rqBlurryLand) = 0 then
-                
+
                     begin
-                    
+
                     if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then
                         LandPixels[y, x]:= LandPixels[y, x-1]
-                        
+
                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then
                         LandPixels[y, x]:= LandPixels[y, x+1]
-                        
+
                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then
                         LandPixels[y, x]:= LandPixels[y+1, x]
-                        
+
                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then
                         LandPixels[y, x]:= LandPixels[y-1, x];
-                        
+
                     if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
                         LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
                     end;
@@ -785,7 +785,7 @@
 
 if (GameFlags and gfForts = 0) and (maskOnly or (cPathz[ptMapCurrent] = '')) then
     AddObjects
-    
+
 else
     AddProgress();
 
@@ -843,7 +843,7 @@
         rw:= rh*2;
         end;
     if rh < rw div 2 then rh:= rw * 2;
-    
+
     ox:= (rw-LAND_WIDTH) div 2;
     oy:= rh-LAND_HEIGHT;
 
@@ -859,7 +859,7 @@
                 cbit:= bit * 8;
                 for yy:= y * lh to y * lh + 7 do
                     for xx:= x * lw + cbit to x * lw + cbit + 7 do
-                        if ((yy-oy) and LAND_HEIGHT_MASK = 0) and ((xx-ox) and LAND_WIDTH_MASK = 0) 
+                        if ((yy-oy) and LAND_HEIGHT_MASK = 0) and ((xx-ox) and LAND_WIDTH_MASK = 0)
                            and (Land[yy-oy, xx-ox] <> 0) then
                             inc(t);
                 if t > 8 then
--- a/hedgewars/uLandGenMaze.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uLandGenMaze.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -16,7 +16,6 @@
     DIR_S: direction = (x: 0; y: 1);
     DIR_W: direction = (x: -1; y: 0);
 
-
 operator = (const a, b: direction) c: Boolean;
 begin
     c := (a.x = b.x) and (a.y = b.y);
@@ -27,28 +26,43 @@
     large_cell_size = 256;
     braidness = 10;
 
-var x, y: LongInt;
-    cellsize: LongInt; //selected by the user in the gui
-    seen_cells_x, seen_cells_y: LongInt; //number of cells that can be visited by the generator, that is every second cell in x and y direction. the cells between there are walls that will be removed when we move from one cell to another
-    num_edges_x, num_edges_y: LongInt; //number of resulting edges that need to be vertexificated
-    num_cells_x, num_cells_y: LongInt; //actual number of cells, depending on cell size
-    seen_list: array of array of LongInt;
-    xwalls: array of array of Boolean;
-    ywalls: array of array of Boolean;
-    x_edge_list: array of array of Boolean;
-    y_edge_list: array of array of Boolean;
-    maze: array of array of Boolean;
-    pa: TPixAr;
-    num_vertices: LongInt;
-    off_y: LongInt;
-    num_steps: LongInt;
-    current_step: LongInt;
-    step_done: array of Boolean;
-    done: Boolean;
-    last_cell: array of record x, y: LongInt; end;
-    came_from: array of array of record x, y: LongInt; end;
+type
+   cell_t = record x,y         : LongInt
+        end;
+
+var x, y               : LongInt;
+    cellsize               : LongInt; //selected by the user in the gui
+    seen_cells_x, seen_cells_y : LongInt; //number of cells that can be visited by the generator, that is every second cell in x and y direction. the cells between there are walls that will be removed when we move from one cell to another
+    num_edges_x, num_edges_y   : LongInt; //number of resulting edges that need to be vertexificated
+    num_cells_x, num_cells_y   : LongInt; //actual number of cells, depending on cell size
+
+
+    seen_list              : array of array of LongInt;
+    xwalls             : array of array of Boolean;
+    ywalls             : array of array of Boolean;
+    x_edge_list            : array of array of Boolean;
+    y_edge_list            : array of array of Boolean;
+    maze               : array of array of Boolean;
+
+    pa                 : TPixAr;
+    num_vertices           : LongInt;
+    off_y              : LongInt;
+    num_steps              : LongInt;
+    current_step           : LongInt;
+
+    step_done              : array of Boolean;
+
+    done               : Boolean;
+
+{   last_cell              : array 0..3 of record x, y :LongInt ; end;
+    came_from              : array of array of record x, y: LongInt; end;
+    came_from_pos          : array of LongInt;
+}
+    last_cell : array of cell_t;
+    came_from : array of array of cell_t;
     came_from_pos: array of LongInt;
-    maze_inverted: Boolean;
+
+    maze_inverted                      : Boolean;
 
 function when_seen(x: LongInt; y: LongInt): LongInt;
 begin
@@ -104,11 +118,11 @@
     begin
         //we have already seen the target cell, decide if we should remove the wall anyway
         //(or put a wall there if maze_inverted, but we are not doing that right now)
-        if not maze_inverted and (GetRandom(braidness) = 0) then
+        if (not maze_inverted) and (GetRandom(braidness) = 0) then
         //or just warn that inverted+braid+indestructible terrain != good idea
         begin
             case dir.x of
-            
+
                 -1:
                 if x > 0 then
                     ywalls[x-1, y] := false;
@@ -178,10 +192,10 @@
     last_cell[current_step].x := came_from[current_step, came_from_pos[current_step]].x;
     last_cell[current_step].y := came_from[current_step, came_from_pos[current_step]].y;
     came_from_pos[current_step] := came_from_pos[current_step] - 1;
-    
+
     if came_from_pos[current_step] >= 0 then
-        see_cell
-        
+        see_cell()
+
     else
         step_done[current_step] := true;
     end;
@@ -208,7 +222,7 @@
         tmp_x := cellsize
     else
         tmp_x := cellsize * 2 div 3;
-        
+
     if maze_inverted or (y mod 2 = 0) then
         tmp_y := cellsize
     else
@@ -318,11 +332,11 @@
 num_cells_x := LAND_WIDTH div cellsize;
 if not odd(num_cells_x) then
     num_cells_x := num_cells_x - 1; //needs to be odd
-    
+
 num_cells_y := LAND_HEIGHT div cellsize;
 if not odd(num_cells_y) then
     num_cells_y := num_cells_y - 1;
-    
+
 num_edges_x := num_cells_x - 1;
 num_edges_y := num_cells_y - 1;
 
@@ -333,19 +347,23 @@
     num_steps := 3 //TODO randomize, between 3 and 5?
 else
     num_steps := 1;
-    
+
 SetLength(step_done, num_steps);
 SetLength(last_cell, num_steps);
 SetLength(came_from_pos, num_steps);
 SetLength(came_from, num_steps, num_cells_x*num_cells_y);
+
 done := false;
 
 for current_step := 0 to num_steps - 1 do
+begin
     step_done[current_step] := false;
     came_from_pos[current_step] := 0;
-    
+end;
+
 current_step := 0;
 
+
 SetLength(seen_list, seen_cells_x, seen_cells_y);
 SetLength(xwalls, seen_cells_x, seen_cells_y - 1);
 SetLength(ywalls, seen_cells_x - 1, seen_cells_y);
@@ -353,6 +371,7 @@
 SetLength(y_edge_list, num_cells_x, num_edges_y);
 SetLength(maze, num_cells_x, num_cells_y);
 
+
 num_vertices := 0;
 
 playHeight := num_cells_y * cellsize;
--- a/hedgewars/uLandGraphics.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uLandGraphics.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -88,21 +88,21 @@
 if ((Land[landY, landX] and lfBasic) <> 0) or ((Land[landY, landX] and lfObject) <> 0) then
     begin
     LandPixels[pixelY, pixelX]:= ExplosionBorderColor;
-    Land[landY, landX]:= (Land[landY, landX] or lfDamaged) and not lfIce;
+    Land[landY, landX]:= (Land[landY, landX] or lfDamaged) and (not lfIce);
     LandDirty[landY div 32, landX div 32]:= 1;
     end;
 end;
 
 function isLandscapeEdge(weight:Longint):boolean; inline;
 begin
-result := (weight < 8) and (weight >= 2);
+isLandscapeEdge := (weight < 8) and (weight >= 2);
 end;
 
 function getPixelWeight(x, y:Longint): Longint;
 var
-    i, j:Longint;
+    i, j, r: Longint;
 begin
-result := 0;
+r := 0;
 for i := x - 1 to x + 1 do
     for j := y - 1 to y + 1 do
     begin
@@ -110,13 +110,13 @@
        (i > LAND_WIDTH - 1) or
        (j < 0) or
        (j > LAND_HEIGHT -1) then
-       begin
-       result := 9;
-       exit;
-       end;
-    if Land[j, i] and lfLandMask and not lfIce = 0 then
-       result := result + 1;
+       exit(9);
+
+    if Land[j, i] and lfLandMask and (not lfIce) = 0 then
+       inc(r)
     end;
+
+    getPixelWeight:= r
 end;
 
 
@@ -144,11 +144,11 @@
         end
     else
         begin
-        LandPixels[pixelY, pixelX]:= IceColor and not AMask or $E8 shl AShift;
+        LandPixels[pixelY, pixelX]:= IceColor and (not AMask) or $E8 shl AShift;
         LandPixels[pixelY, pixelX]:= addBgColor(LandPixels[pixelY, pixelX], icePixels^[iceSurface^.w * (pixelY mod iceSurface^.h) + (pixelX mod iceSurface^.w)]);
         // silly workaround to avoid having to make background erasure a tadb it smarter about sea ice
         if LandPixels[pixelY, pixelX] and AMask shr AShift = 255 then
-            LandPixels[pixelY, pixelX]:= LandPixels[pixelY, pixelX] and not AMask or 254 shl AShift;
+            LandPixels[pixelY, pixelX]:= LandPixels[pixelY, pixelX] and (not AMask) or 254 shl AShift;
         end;
 end;
 
@@ -159,7 +159,7 @@
 if isLandscapeEdge(getPixelWeight(landX, landY)) then
     begin
     if (LandPixels[pixelY, pixelX] and AMask < 255) and (LandPixels[pixelY, pixelX] and AMask > 0) then
-        LandPixels[pixelY, pixelX] := (IceEdgeColor and not AMask) or (LandPixels[pixelY, pixelX] and AMask)
+        LandPixels[pixelY, pixelX] := (IceEdgeColor and (not AMask)) or (LandPixels[pixelY, pixelX] and AMask)
     else if (LandPixels[pixelY, pixelX] and AMask < 255) or (Land[landY, landX] > 255) then
         LandPixels[pixelY, pixelX] := IceEdgeColor
     end
@@ -167,7 +167,7 @@
     begin
         fillPixelFromIceSprite(pixelX, pixelY);
     end;
-if Land[landY, landX] > 255 then Land[landY, landX] := Land[landY, landX] or lfIce and not lfDamaged;
+if Land[landY, landX] > 255 then Land[landY, landX] := Land[landY, landX] or lfIce and (not lfDamaged);
 end;
 
 
@@ -344,11 +344,11 @@
 begin
 if not doSet and isCurrent then
     FillRoundInLandFT(X, Y, Radius, setNotCurrentMask)
-else if not doSet and not IsCurrent then
+else if not doSet and (not IsCurrent) then
     FillRoundInLandFT(X, Y, Radius, changePixelSetNotCurrent)
 else if doSet and IsCurrent then
     FillRoundInLandFT(X, Y, Radius, setCurrentHog)
-else if doSet and not IsCurrent then
+else if doSet and (not IsCurrent) then
     FillRoundInLandFT(X, Y, Radius, changePixelNotSetNotCurrent);
 end;
 
@@ -432,7 +432,7 @@
                 else
                     LandPixels[ty div 2, tx div 2]:= ExplosionBorderColor;
 
-                Land[ty, tx]:= (Land[ty, tx] or lfDamaged) and not lfIce;
+                Land[ty, tx]:= (Land[ty, tx] or lfDamaged) and (not lfIce);
                 LandDirty[ty div 32, tx div 32]:= 1;
                 end;
     inc(y, dY)
@@ -457,7 +457,7 @@
     if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (((Land[ty, tx] and lfBasic) <> 0)
     or ((Land[ty, tx] and lfObject) <> 0)) then
         begin
-        Land[ty, tx]:= (Land[ty, tx] or lfDamaged) and not lfIce;
+        Land[ty, tx]:= (Land[ty, tx] or lfDamaged) and (not lfIce);
         if despeckle then
             LandDirty[ty div 32, tx div 32]:= 1;
         if (cReducedQuality and rqBlurryLand) = 0 then
@@ -501,7 +501,7 @@
     and ((tx and LAND_WIDTH_MASK) = 0)
     and (((Land[ty, tx] and lfBasic) <> 0) or ((Land[ty, tx] and lfObject) <> 0)) then
         begin
-        Land[ty, tx]:= Land[ty, tx] and not lfIce;
+        Land[ty, tx]:= Land[ty, tx] and (not lfIce);
         if despeckle then
             begin
             Land[ty, tx]:= Land[ty, tx] or lfDamaged;
@@ -565,7 +565,7 @@
     if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (((Land[ty, tx] and lfBasic) <> 0)
     or ((Land[ty, tx] and lfObject) <> 0)) then
         begin
-        Land[ty, tx]:= (Land[ty, tx] or lfDamaged) and not lfIce;
+        Land[ty, tx]:= (Land[ty, tx] or lfDamaged) and (not lfIce);
         if despeckle then
             LandDirty[ty div 32, tx div 32]:= 1;
         if (cReducedQuality and rqBlurryLand) = 0 then
--- a/hedgewars/uLandObjects.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uLandObjects.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -94,7 +94,7 @@
 begin
     BlitImageAndGenerateCollisionInfo(cpX, cpY, Width, Image, 0);
 end;
-    
+
 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface; LandFlags: Word);
 var p: PLongwordArray;
     x, y: Longword;
@@ -124,7 +124,7 @@
                     LandPixels[cpY + y, cpX + x]:= p^[x];
                 end
             else
-                if LandPixels[(cpY + y) div 2, (cpX + x) div 2] = 0 then 
+                if LandPixels[(cpY + y) div 2, (cpX + x) div 2] = 0 then
                     LandPixels[(cpY + y) div 2, (cpX + x) div 2]:= p^[x];
 
             if (Land[cpY + y, cpX + x] <= lfAllObjMask) and ((p^[x] and AMask) <> 0) then
@@ -164,7 +164,7 @@
                 LandPixels[cpY + y, cpX + x]:= p^[x];
             end
         else
-            if LandPixels[(cpY + y) div 2, (cpX + x) div 2] = 0 then 
+            if LandPixels[(cpY + y) div 2, (cpX + x) div 2] = 0 then
                 LandPixels[(cpY + y) div 2, (cpX + x) div 2]:= p^[x];
 
         if (Land[cpY + y, cpX + x] <= lfAllObjMask) or (Land[cpY + y, cpX + x] and lfObject <> 0)  then
@@ -261,7 +261,7 @@
         inc(x2, 2);
         k:= CountNonZeroz(x2, y)
         until (x2 >= (rightX-150)) or (k = 0) or (k = 16) or (x2 > i) or (x2 - x1 >= 768);
-        
+
         if (x2 < (rightX - 150)) and (k = 16) and (x2 - x1 > 250) and (x2 - x1 < 768)
         and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then
                 break;
@@ -277,7 +277,7 @@
     rr.x:= x1;
     while rr.x < x2 do
         begin
-        if cIce then 
+        if cIce then
             BlitImageAndGenerateCollisionInfo(rr.x, y, min(x2 - rr.x, tmpsurf^.w), tmpsurf, lfIce)
         else
             BlitImageAndGenerateCollisionInfo(rr.x, y, min(x2 - rr.x, tmpsurf^.w), tmpsurf);
@@ -454,9 +454,9 @@
 
 procedure CheckRect(Width, Height, x, y, w, h: LongWord);
 begin
-    if (x + w > Width) then 
+    if (x + w > Width) then
         OutError('Object''s rectangle exceeds image: x + w (' + inttostr(x) + ' + ' + inttostr(w) + ') > Width (' + inttostr(Width) + ')', true);
-    if (y + h > Height) then 
+    if (y + h > Height) then
         OutError('Object''s rectangle exceeds image: y + h (' + inttostr(y) + ' + ' + inttostr(h) + ') > Height (' + inttostr(Height) + ')', true);
 end;
 
@@ -554,7 +554,7 @@
             c2.g:= t;
             c2.b:= t
             end;
-        ExplosionBorderColor:= (c2.r shl RShift) or (c2.g shl GShift) or (c2.b shl BShift) or AMask; 
+        ExplosionBorderColor:= (c2.r shl RShift) or (c2.g shl GShift) or (c2.b shl BShift) or AMask;
         end
     else if key = 'water-top' then
         begin
--- a/hedgewars/uLandOutline.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uLandOutline.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -27,8 +27,6 @@
                                      end
            end;
 
-const
-    cMaxEdgePoints = 16384;
 
 procedure Push(_xl, _xr, _y, _dir: LongInt);
 begin
@@ -99,9 +97,9 @@
     i:= 0;
     with pa do
         while i < LongInt(Count) - 1 do
-            if (ar[i + 1].X = NTPX) then 
+            if (ar[i + 1].X = NTPX) then
                 inc(i, 2)
-            else 
+            else
                 begin
                 DrawLine(ar[i].x, ar[i].y, ar[i + 1].x, ar[i + 1].y, Color);
                 inc(i)
@@ -130,7 +128,7 @@
         begin
         Vx:= _0;
         Vy:= _0
-        end 
+        end
     else
         begin
         d2:= _1 / d2;
@@ -237,7 +235,7 @@
             CheckIntersect:= false
         else if (c2 < 0) or (c2 > dm) then
             CheckIntersect:= false;
-    end 
+    end
     else
     begin
         if (c1 > 0) or (c1 < dm) then
--- a/hedgewars/uLandPainted.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uLandPainted.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -27,7 +27,7 @@
 procedure freeModule;
 
 implementation
-uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uDebug, uScript;
+uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uScript;
 
 type PointRec = packed record
     X, Y: SmallInt;
--- a/hedgewars/uLocale.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uLocale.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -36,13 +36,14 @@
 {$ENDIF}
 
 implementation
-uses uRandom, uUtils, uVariables, uDebug, uPhysFSLayer, sysutils;
+uses uRandom, uVariables, uDebug, uPhysFSLayer, sysutils;
 
 var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of PChar;
     trevt_n: array[TEventId] of integer;
 
 procedure LoadLocale(FileName: shortstring);
-var s, sc: PChar;
+var s: PChar = nil;
+    sc: PChar;
     f: pfsFile;
     a, b, c: LongInt;
     first: array[TEventId] of boolean;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uMatrix.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,268 @@
+(*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *)
+
+{$INCLUDE "options.inc"}
+
+unit uMatrix;
+
+interface
+
+uses uTypes {$IFNDEF PAS2C}, gl{$ENDIF};
+
+const
+    MATRIX_MODELVIEW:Integer = 0;
+    MATRIX_PROJECTION:Integer = 1;
+
+procedure MatrixLoadIdentity(out Result: TMatrix4x4f);
+procedure MatrixMultiply(out Result: TMatrix4x4f; const lhs, rhs: TMatrix4x4f);
+
+procedure hglMatrixMode(t: Integer);
+procedure hglLoadIdentity();
+procedure hglPushMatrix();
+procedure hglPopMatrix();
+procedure hglMVP(var res : TMatrix4x4f);
+procedure hglScalef(x: GLfloat; y: GLfloat; z: GLfloat);
+procedure hglTranslatef(x: GLfloat; y: GLfloat; z: GLfloat);
+procedure hglRotatef(a:GLfloat; x:GLfloat; y:GLfloat; z:GLfloat);
+procedure initModule();
+procedure freeModule();
+
+implementation
+
+const
+    MATRIX_STACK_SIZE = 10;
+
+type
+    TMatrixStack = record
+        top:Integer;
+        stack: array[0..9] of TMatrix4x4f;
+        end;
+var
+    MatrixStacks : array[0..1] of TMatrixStack;
+    CurMatrix: integer;
+
+procedure MatrixLoadIdentity(out Result: TMatrix4x4f);
+begin
+    Result[0,0]:= 1.0; Result[1,0]:=0.0; Result[2,0]:=0.0; Result[3,0]:=0.0;
+    Result[0,1]:= 0.0; Result[1,1]:=1.0; Result[2,1]:=0.0; Result[3,1]:=0.0;
+    Result[0,2]:= 0.0; Result[1,2]:=0.0; Result[2,2]:=1.0; Result[3,2]:=0.0;
+    Result[0,3]:= 0.0; Result[1,3]:=0.0; Result[2,3]:=0.0; Result[3,3]:=1.0;
+end;
+
+procedure hglMatrixMode(t: Integer);
+begin
+    CurMatrix := t;
+end;
+
+procedure hglLoadIdentity();
+begin
+    MatrixLoadIdentity(MatrixStacks[CurMatrix].stack[MatrixStacks[CurMatrix].top]);
+end;
+
+procedure hglScalef(x: GLfloat; y: GLfloat; z: GLfloat);
+var
+    m:TMatrix4x4f;
+    t:TMatrix4x4f;
+begin
+    m[0,0]:=x;m[1,0]:=0;m[2,0]:=0;m[3,0]:=0;
+    m[0,1]:=0;m[1,1]:=y;m[2,1]:=0;m[3,1]:=0;
+    m[0,2]:=0;m[1,2]:=0;m[2,2]:=z;m[3,2]:=0;
+    m[0,3]:=0;m[1,3]:=0;m[2,3]:=0;m[3,3]:=1;
+
+    MatrixMultiply(t, MatrixStacks[CurMatrix].stack[MatrixStacks[CurMatrix].top], m);
+    MatrixStacks[CurMatrix].stack[MatrixStacks[CurMatrix].top] := t;
+end;
+
+procedure hglTranslatef(x: GLfloat; y: GLfloat; z: GLfloat);
+var
+    m:TMatrix4x4f;
+    t:TMatrix4x4f;
+begin
+    m[0,0]:=1;m[1,0]:=0;m[2,0]:=0;m[3,0]:=x;
+    m[0,1]:=0;m[1,1]:=1;m[2,1]:=0;m[3,1]:=y;
+    m[0,2]:=0;m[1,2]:=0;m[2,2]:=1;m[3,2]:=z;
+    m[0,3]:=0;m[1,3]:=0;m[2,3]:=0;m[3,3]:=1;
+
+    MatrixMultiply(t, MatrixStacks[CurMatrix].stack[MatrixStacks[CurMatrix].top], m);
+    MatrixStacks[CurMatrix].stack[MatrixStacks[CurMatrix].top] := t;
+end;
+
+procedure hglRotatef(a:GLfloat; x:GLfloat; y:GLfloat; z:GLfloat);
+var
+    m:TMatrix4x4f;
+    t:TMatrix4x4f;
+    c:GLfloat;
+    s:GLfloat;
+    xn, yn, zn:GLfloat;
+    l:GLfloat;
+begin
+    a:=a * 3.14159265368 / 180;
+    c:=cos(a);
+    s:=sin(a);
+
+    l := 1.0 / sqrt(x * x + y * y + z * z);
+    xn := x * l;
+    yn := y * l;
+    zn := z * l;
+
+    m[0,0]:=c + xn * xn * (1 - c);
+    m[1,0]:=xn * yn * (1 - c) - zn * s;
+    m[2,0]:=xn * zn * (1 - c) + yn * s;
+    m[3,0]:=0;
+
+
+    m[0,1]:=yn * xn * (1 - c) + zn * s;
+    m[1,1]:=c + yn * yn * (1 - c);
+    m[2,1]:=yn * zn * (1 - c) - xn * s;
+    m[3,1]:=0;
+
+    m[0,2]:=zn * xn * (1 - c) - yn * s;
+    m[1,2]:=zn * yn * (1 - c) + xn * s;
+    m[2,2]:=c + zn * zn * (1 - c);
+    m[3,2]:=0;
+
+    m[0,3]:=0;m[1,3]:=0;m[2,3]:=0;m[3,3]:=1;
+
+    MatrixMultiply(t, MatrixStacks[CurMatrix].stack[MatrixStacks[CurMatrix].top], m);
+    MatrixStacks[CurMatrix].stack[MatrixStacks[CurMatrix].top] := t;
+end;
+
+procedure hglMVP(var res: TMatrix4x4f);
+begin
+    MatrixMultiply(res,
+                   MatrixStacks[MATRIX_PROJECTION].stack[MatrixStacks[MATRIX_PROJECTION].top],
+                   MatrixStacks[MATRIX_MODELVIEW].stack[MatrixStacks[MATRIX_MODELVIEW].top]);
+end;
+
+procedure hglPushMatrix();
+var
+    t: Integer;
+begin
+    t := MatrixStacks[CurMatrix].top;
+    MatrixStacks[CurMatrix].stack[t + 1] := MatrixStacks[CurMatrix].stack[t];
+    inc(t);
+    MatrixStacks[CurMatrix].top := t;
+end;
+
+procedure hglPopMatrix();
+var
+    t: Integer;
+begin
+    t := MatrixStacks[CurMatrix].top;
+    dec(t);
+    MatrixStacks[CurMatrix].top := t;
+end;
+
+procedure initModule();
+begin
+    MatrixStacks[MATRIX_MODELVIEW].top := 0;
+    MatrixStacks[MATRIX_Projection].top := 0;
+    MatrixLoadIdentity(MatrixStacks[MATRIX_MODELVIEW].stack[0]);
+    MatrixLoadIdentity(MatrixStacks[MATRIX_PROJECTION].stack[0]);
+end;
+
+procedure freeModule();
+begin
+end;
+
+procedure MatrixMultiply(out Result: TMatrix4x4f; const lhs, rhs: TMatrix4x4f);
+var
+    test: TMatrix4x4f;
+    i, j: Integer;
+    error: boolean;
+begin
+    Result[0,0]:=lhs[0,0]*rhs[0,0] + lhs[1,0]*rhs[0,1] + lhs[2,0]*rhs[0,2] + lhs[3,0]*rhs[0,3];
+    Result[0,1]:=lhs[0,1]*rhs[0,0] + lhs[1,1]*rhs[0,1] + lhs[2,1]*rhs[0,2] + lhs[3,1]*rhs[0,3];
+    Result[0,2]:=lhs[0,2]*rhs[0,0] + lhs[1,2]*rhs[0,1] + lhs[2,2]*rhs[0,2] + lhs[3,2]*rhs[0,3];
+    Result[0,3]:=lhs[0,3]*rhs[0,0] + lhs[1,3]*rhs[0,1] + lhs[2,3]*rhs[0,2] + lhs[3,3]*rhs[0,3];
+
+    Result[1,0]:=lhs[0,0]*rhs[1,0] + lhs[1,0]*rhs[1,1] + lhs[2,0]*rhs[1,2] + lhs[3,0]*rhs[1,3];
+    Result[1,1]:=lhs[0,1]*rhs[1,0] + lhs[1,1]*rhs[1,1] + lhs[2,1]*rhs[1,2] + lhs[3,1]*rhs[1,3];
+    Result[1,2]:=lhs[0,2]*rhs[1,0] + lhs[1,2]*rhs[1,1] + lhs[2,2]*rhs[1,2] + lhs[3,2]*rhs[1,3];
+    Result[1,3]:=lhs[0,3]*rhs[1,0] + lhs[1,3]*rhs[1,1] + lhs[2,3]*rhs[1,2] + lhs[3,3]*rhs[1,3];
+
+    Result[2,0]:=lhs[0,0]*rhs[2,0] + lhs[1,0]*rhs[2,1] + lhs[2,0]*rhs[2,2] + lhs[3,0]*rhs[2,3];
+    Result[2,1]:=lhs[0,1]*rhs[2,0] + lhs[1,1]*rhs[2,1] + lhs[2,1]*rhs[2,2] + lhs[3,1]*rhs[2,3];
+    Result[2,2]:=lhs[0,2]*rhs[2,0] + lhs[1,2]*rhs[2,1] + lhs[2,2]*rhs[2,2] + lhs[3,2]*rhs[2,3];
+    Result[2,3]:=lhs[0,3]*rhs[2,0] + lhs[1,3]*rhs[2,1] + lhs[2,3]*rhs[2,2] + lhs[3,3]*rhs[2,3];
+
+    Result[3,0]:=lhs[0,0]*rhs[3,0] + lhs[1,0]*rhs[3,1] + lhs[2,0]*rhs[3,2] + lhs[3,0]*rhs[3,3];
+    Result[3,1]:=lhs[0,1]*rhs[3,0] + lhs[1,1]*rhs[3,1] + lhs[2,1]*rhs[3,2] + lhs[3,1]*rhs[3,3];
+    Result[3,2]:=lhs[0,2]*rhs[3,0] + lhs[1,2]*rhs[3,1] + lhs[2,2]*rhs[3,2] + lhs[3,2]*rhs[3,3];
+    Result[3,3]:=lhs[0,3]*rhs[3,0] + lhs[1,3]*rhs[3,1] + lhs[2,3]*rhs[3,2] + lhs[3,3]*rhs[3,3];
+
+{
+    Result[0,0]:=lhs[0,0]*rhs[0,0] + lhs[1,0]*rhs[0,1] + lhs[2,0]*rhs[0,2] + lhs[3,0]*rhs[0,3];
+    Result[0,1]:=lhs[0,0]*rhs[1,0] + lhs[1,0]*rhs[1,1] + lhs[2,0]*rhs[1,2] + lhs[3,0]*rhs[1,3];
+    Result[0,2]:=lhs[0,0]*rhs[2,0] + lhs[1,0]*rhs[2,1] + lhs[2,0]*rhs[2,2] + lhs[3,0]*rhs[2,3];
+    Result[0,3]:=lhs[0,0]*rhs[3,0] + lhs[1,0]*rhs[3,1] + lhs[2,0]*rhs[3,2] + lhs[3,0]*rhs[3,3];
+
+    Result[1,0]:=lhs[0,1]*rhs[0,0] + lhs[1,1]*rhs[0,1] + lhs[2,1]*rhs[0,2] + lhs[3,1]*rhs[0,3];
+    Result[1,1]:=lhs[0,1]*rhs[1,0] + lhs[1,1]*rhs[1,1] + lhs[2,1]*rhs[1,2] + lhs[3,1]*rhs[1,3];
+    Result[1,2]:=lhs[0,1]*rhs[2,0] + lhs[1,1]*rhs[2,1] + lhs[2,1]*rhs[2,2] + lhs[3,1]*rhs[2,3];
+    Result[1,3]:=lhs[0,1]*rhs[3,0] + lhs[1,1]*rhs[3,1] + lhs[2,1]*rhs[3,2] + lhs[3,1]*rhs[3,3];
+
+    Result[2,0]:=lhs[0,2]*rhs[0,0] + lhs[1,2]*rhs[0,1] + lhs[2,2]*rhs[0,2] + lhs[3,2]*rhs[0,3];
+    Result[2,1]:=lhs[0,2]*rhs[1,0] + lhs[1,2]*rhs[1,1] + lhs[2,2]*rhs[1,2] + lhs[3,2]*rhs[1,3];
+    Result[2,2]:=lhs[0,2]*rhs[2,0] + lhs[1,2]*rhs[2,1] + lhs[2,2]*rhs[2,2] + lhs[3,2]*rhs[2,3];
+    Result[2,3]:=lhs[0,2]*rhs[3,0] + lhs[1,2]*rhs[3,1] + lhs[2,2]*rhs[3,2] + lhs[3,2]*rhs[3,3];
+
+    Result[3,0]:=lhs[0,3]*rhs[0,0] + lhs[1,3]*rhs[0,1] + lhs[2,3]*rhs[0,2] + lhs[3,3]*rhs[0,3];
+    Result[3,1]:=lhs[0,3]*rhs[1,0] + lhs[1,3]*rhs[1,1] + lhs[2,3]*rhs[1,2] + lhs[3,3]*rhs[1,3];
+    Result[3,2]:=lhs[0,3]*rhs[2,0] + lhs[1,3]*rhs[2,1] + lhs[2,3]*rhs[2,2] + lhs[3,3]*rhs[2,3];
+    Result[3,3]:=lhs[0,3]*rhs[3,0] + lhs[1,3]*rhs[3,1] + lhs[2,3]*rhs[3,2] + lhs[3,3]*rhs[3,3];
+}
+
+    {$IFNDEF PAS2C}
+    glPushMatrix;
+    glLoadMatrixf(@lhs[0, 0]);
+    glMultMatrixf(@rhs[0, 0]);
+    glGetFloatv(GL_MODELVIEW_MATRIX, @test[0, 0]);
+    glPopMatrix;
+
+    error:=false;
+    for i:=0 to 3 do
+      for j:=0 to 3 do
+        if Abs(test[i, j] - Result[i, j]) > 0.000001 then
+          error:=true;
+
+    if error then
+    begin
+        writeln('shall:');
+        for i:=0 to 3 do
+        begin
+          for j:=0 to 3 do
+            write(test[i, j]);
+          writeln;
+        end;
+
+        writeln('is:');
+        for i:=0 to 3 do
+        begin
+          for j:=0 to 3 do
+            write(Result[i, j]);
+          writeln;
+        end;
+        halt(0);
+    end;
+    {$ENDIF}
+
+end;
+
+
+end.
--- a/hedgewars/uMisc.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uMisc.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -48,7 +48,7 @@
          size: QWord;
          end;
 
-var conversionFormat: PSDL_PixelFormat;
+var conversionFormat : PSDL_PixelFormat;
 
 procedure movecursor(dx, dy: LongInt);
 var x, y: LongInt;
@@ -67,7 +67,7 @@
 var i: LongInt;
     png_ptr: ^png_struct;
     info_ptr: ^png_info;
-    f: file;
+    f: File;
     image: PScreenshot;
 begin
 image:= PScreenshot(screenshot);
@@ -140,6 +140,7 @@
     );
     image: PScreenshot;
     size: QWord;
+    writeResult:LongInt;
 begin
 image:= PScreenshot(screenshot);
 
@@ -167,8 +168,8 @@
 Rewrite(f, 1);
 if IOResult = 0 then
     begin
-    BlockWrite(f, head, sizeof(head));
-    BlockWrite(f, image^.buffer^, size);
+    BlockWrite(f, head, sizeof(head), writeResult);
+    BlockWrite(f, image^.buffer^, size, writeResult);
     Close(f);
     end
 else
@@ -298,7 +299,6 @@
     GetTeamStatString:= s;
 end;
 
-procedure initModule;
 {$IFDEF SDL2}
 const SDL_PIXELFORMAT_ABGR8888 = (1 shl 28) or (6 shl 24) or (7 shl 20) or (6 shl 16) or (32 shl 8) or 4;
 {$ELSE}
@@ -309,6 +309,8 @@
         RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask;
         colorkey: 0; alpha: 255);
 {$ENDIF}
+
+procedure initModule;
 begin
 {$IFDEF SDL2}
     conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888);
--- a/hedgewars/uPhysFSLayer.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uPhysFSLayer.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -40,7 +40,7 @@
 
 function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName;
 function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName;
-function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl ; external PhyslayerLibName;
+function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
 
 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName;
--- a/hedgewars/uRandom.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uRandom.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -31,8 +31,8 @@
 uses uFloat;
 
 procedure SetRandomSeed(Seed: shortstring; dropAdditionalPart: boolean); // Sets the seed that should be used for generating pseudo-random values.
-function  GetRandomf: hwFloat; overload; // Returns a pseudo-random hwFloat.
-function  GetRandom(m: LongWord): LongWord; overload; inline; // Returns a positive pseudo-random integer smaller than m.
+function  GetRandomf: hwFloat; // Returns a pseudo-random hwFloat.
+function  GetRandom(m: LongWord): LongWord; inline; // Returns a positive pseudo-random integer smaller than m.
 procedure AddRandomness(r: LongWord); inline;
 function  rndSign(num: hwFloat): hwFloat; // Returns num with a random chance of having a inverted sign.
 
@@ -45,10 +45,11 @@
 procedure AddRandomness(r: LongWord); inline;
 begin
 n:= (n + 1) and $3F;
-cirbuf[n]:= cirbuf[n] xor r
+   cirbuf[n]:= cirbuf[n] xor r;
 end;
 
 function GetNext: Longword; inline;
+var s : string;
 begin
 n:= (n + 1) and $3F;
 cirbuf[n]:=
@@ -56,7 +57,8 @@
             cirbuf[(n +  9) and $3F])            {n - 55 mod 64}
             and $7FFFFFFF;                       {mod 2^31}
 
-GetNext:= cirbuf[n]
+   GetNext:= cirbuf[n];
+   str(GetNext, s);
 end;
 
 procedure SetRandomSeed(Seed: shortstring; dropAdditionalPart: boolean);
@@ -80,7 +82,7 @@
     cirbuf[i]:= $A98765 + 68; // odd number
 
 for i:= 0 to 1023 do
-    GetNext
+   GetNext;
 end;
 
 function GetRandomf: hwFloat;
--- a/hedgewars/uRender.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uRender.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -17,12 +17,13 @@
  *)
 
 {$INCLUDE "options.inc"}
+{$IF GLunit = GL}{$DEFINE GLunit:=GL,GLext}{$ENDIF}
 
 unit uRender;
 
 interface
 
-uses SDLh, uTypes, GLunit, uConsts;
+uses SDLh, uTypes, GLunit, uConsts, uStore{$IFDEF GL2}, uMatrix{$ENDIF};
 
 procedure DrawSprite            (Sprite: TSprite; X, Y, Frame: LongInt);
 procedure DrawSprite            (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
@@ -56,7 +57,6 @@
 procedure untint(); inline;
 procedure setTintAdd            (f: boolean); inline;
 
-
 implementation
 uses uVariables;
 
@@ -79,6 +79,7 @@
 begin
 DrawTextureFromRectDir(X, Y, r^.w, r^.h, r, SourceTexture, 1)
 end;
+
 procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
 begin
 DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1)
@@ -144,7 +145,7 @@
 
 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
-glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+glDrawArrays(GL_TRIANGLE_FAN, 0, High(VertexBuffer) - Low(VertexBuffer) + 1);
 end;
 
 procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline;
@@ -155,17 +156,30 @@
 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
 begin
 
+{$IFDEF GL2}
+hglPushMatrix;
+hglTranslatef(X, Y, 0);
+hglScalef(Scale, Scale, 1);
+{$ELSE}
 glPushMatrix;
 glTranslatef(X, Y, 0);
 glScalef(Scale, Scale, 1);
+{$ENDIF}
 
 glBindTexture(GL_TEXTURE_2D, Texture^.id);
 
-glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
-glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
+SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
+SetTexCoordPointer(@Texture^.tb, Length(Texture^.vb));
+
+{$IFDEF GL2}
+UpdateModelviewProjection;
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
+hglPopMatrix;
+{$ELSE}
+glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
+glPopMatrix;
+{$ENDIF}
 
-glPopMatrix
 end;
 
 { this contains tweaks in order to avoid land tile borders in blurry land mode }
@@ -211,14 +225,25 @@
 if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
     exit;
 
+{$IFDEF GL2}
+hglPushMatrix;
+hglTranslatef(X, Y, 0);
+{$ELSE}
 glPushMatrix;
 glTranslatef(X, Y, 0);
+{$ENDIF}
+
 if Dir = 0 then Dir:= 1;
 
+{$IFDEF GL2}
+hglRotatef(Angle, 0, 0, Dir);
+hglTranslatef(Dir*OffsetX, OffsetY, 0);
+hglScalef(Scale, Scale, 1);
+{$ELSE}
 glRotatef(Angle, 0, 0, Dir);
-
 glTranslatef(Dir*OffsetX, OffsetY, 0);
 glScalef(Scale, Scale, 1);
+{$ENDIF}
 
 // Any reason for this call? And why only in t direction, not s?
 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -253,11 +278,21 @@
 TextureBuffer[3].X:= fl;
 TextureBuffer[3].Y:= fb;
 
-glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
-glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
+SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
+SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
+
+{$IFDEF GL2}
+UpdateModelviewProjection;
+{$ENDIF}
+
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-glPopMatrix
+{$IFDEF GL2}
+hglPopMatrix;
+{$ELSE}
+glPopMatrix;
+{$ENDIF}
+
 end;
 
 procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
@@ -270,19 +305,42 @@
 
 procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
 begin
+
+{$IFDEF GL2}
+hglPushMatrix;
+hglTranslatef(X, Y, 0);
+{$ELSE}
 glPushMatrix;
 glTranslatef(X, Y, 0);
+{$ENDIF}
 
 if Dir < 0 then
+{$IFDEF GL2}
+    hglRotatef(Angle, 0, 0, -1)
+{$ELSE}
     glRotatef(Angle, 0, 0, -1)
+{$ENDIF}
 else
+{$IFDEF GL2}
+    hglRotatef(Angle, 0, 0,  1);
+{$ELSE}
     glRotatef(Angle, 0, 0,  1);
+{$ENDIF}
 if Dir < 0 then
+{$IFDEF GL2}
+    hglScalef(-1.0, 1.0, 1.0);
+{$ELSE}
     glScalef(-1.0, 1.0, 1.0);
+{$ENDIF}
 
 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
 
-glPopMatrix
+{$IFDEF GL2}
+hglPopMatrix;
+{$ELSE}
+glPopMatrix;
+{$ENDIF}
+
 end;
 
 procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
@@ -294,17 +352,29 @@
 if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
     exit;
 
+{$IFDEF GL2}
+hglPushMatrix;
+hglTranslatef(X, Y, 0);
+{$ELSE}
 glPushMatrix;
 glTranslatef(X, Y, 0);
+{$ENDIF}
 
 if Dir < 0 then
     begin
     hw:= - hw;
+{$IFDEF GL2}
+    hglRotatef(Angle, 0, 0, -1);
+{$ELSE}
     glRotatef(Angle, 0, 0, -1);
+{$ENDIF}
     end
 else
-    glRotatef(Angle, 0, 0,  1);
-
+{$IFDEF GL2}
+    hglRotatef(Angle, 0, 0,  1);
+{$ELSE}
+    glRotatef(Angle, 0, 0, 1);
+{$ENDIF}
 
 glBindTexture(GL_TEXTURE_2D, Texture^.id);
 
@@ -317,11 +387,21 @@
 VertexBuffer[3].X:= -hw;
 VertexBuffer[3].Y:= hh;
 
-glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
-glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
+SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
+SetTexCoordPointer(@Texture^.tb, Length(VertexBuffer));
+
+{$IFDEF GL2}
+UpdateModelviewProjection;
+{$ENDIF}
+
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-glPopMatrix
+{$IFDEF GL2}
+hglPopMatrix;
+{$ELSE}
+glPopMatrix;
+{$ENDIF}
+
 end;
 
 procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
@@ -363,7 +443,7 @@
 if (X + SpritesData[Sprite].Width > RightX) then
     r.w:= RightX - X + 1;
 
-if (r.h < r.y) or (r.w < r.x) then 
+if (r.h < r.y) or (r.w < r.x) then
     exit;
 
 dec(r.h, r.y);
@@ -390,8 +470,9 @@
 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
 var VertexBuffer: array [0..1] of TVertex2f;
 begin
+    glEnable(GL_LINE_SMOOTH);
+{$IFNDEF GL2}
     glDisable(GL_TEXTURE_2D);
-    glEnable(GL_LINE_SMOOTH);
 
     glPushMatrix;
     glTranslatef(WorldDx, WorldDy, 0);
@@ -403,13 +484,37 @@
     VertexBuffer[1].X:= X1;
     VertexBuffer[1].Y:= Y1;
 
-    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
+    SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
     untint;
-    
+
     glPopMatrix;
-    
+
     glEnable(GL_TEXTURE_2D);
+
+{$ELSE}
+    EnableTexture(False);
+
+    hglPushMatrix;
+    hglTranslatef(WorldDx, WorldDy, 0);
+    glLineWidth(Width);
+
+    UpdateModelviewProjection;
+
+    Tint(r, g, b, a);
+    VertexBuffer[0].X:= X0;
+    VertexBuffer[0].Y:= Y0;
+    VertexBuffer[1].X:= X1;
+    VertexBuffer[1].Y:= Y1;
+
+    SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
+    glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
+    Tint($FF, $FF, $FF, $FF);
+
+    hglPopMatrix;
+    EnableTexture(True);
+
+{$ENDIF}
     glDisable(GL_LINE_SMOOTH);
 end;
 
@@ -417,12 +522,17 @@
 var VertexBuffer: array [0..3] of TVertex2f;
 begin
 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+
 if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then
     exit;
 if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then
     exit;
 
+{$IFDEF GL2}
+EnableTexture(False);
+{$ELSE}
 glDisable(GL_TEXTURE_2D);
+{$ENDIF}
 
 Tint($00, $00, $00, $80);
 
@@ -435,21 +545,26 @@
 VertexBuffer[3].X:= r.x;
 VertexBuffer[3].Y:= r.y + r.h;
 
-glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
+SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
 untint;
+{$IFDEF GL2}
+EnableTexture(True);
+{$ELSE}
 glEnable(GL_TEXTURE_2D)
+{$ENDIF}
+
 end;
 
-procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte); 
+procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
 begin
     Tint(r, g, b, a);
-    DrawCircle(X, Y, Radius, Width); 
+    DrawCircle(X, Y, Radius, Width);
     untint;
 end;
 
-procedure DrawCircle(X, Y, Radius, Width: LongInt); 
+procedure DrawCircle(X, Y, Radius, Width: LongInt);
 var
     i: LongInt;
     CircleVertex: array [0..59] of TVertex2f;
@@ -458,6 +573,9 @@
         CircleVertex[i].X := X + Radius*cos(i*pi/30);
         CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
     end;
+
+{$IFNDEF GL2}
+
     glDisable(GL_TEXTURE_2D);
     glEnable(GL_LINE_SMOOTH);
     glPushMatrix;
@@ -467,6 +585,18 @@
     glPopMatrix;
     glEnable(GL_TEXTURE_2D);
     glDisable(GL_LINE_SMOOTH);
+
+{$ELSE}
+    EnableTexture(False);
+    glEnable(GL_LINE_SMOOTH);
+    hglPushMatrix;
+    glLineWidth(Width);
+    SetVertexPointer(@CircleVertex[0], 60);
+    glDrawArrays(GL_LINE_LOOP, 0, 60);
+    hglPopMatrix;
+    EnableTexture(True);
+    glDisable(GL_LINE_SMOOTH);
+{$ENDIF}
 end;
 
 
@@ -499,10 +629,15 @@
         r:= (Step + 1) * 32 / HHTexture^.w
     end;
 
-
+{$IFDEF GL2}
+    hglPushMatrix();
+    hglTranslatef(X, Y, 0);
+    hglRotatef(Angle, 0, 0, 1);
+{$ELSE}
     glPushMatrix();
     glTranslatef(X, Y, 0);
     glRotatef(Angle, 0, 0, 1);
+{$ENDIF}
 
     glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
 
@@ -515,11 +650,20 @@
     TextureBuffer[3].X:= l;
     TextureBuffer[3].Y:= b;
 
-    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
-    glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
+    SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
+    SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
+
+{$IFDEF GL2}
+    UpdateModelviewProjection;
+{$ENDIF}
+
     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-    glPopMatrix
+{$IFDEF GL2}
+    hglPopMatrix;
+{$ELSE}
+    glPopMatrix;
+{$ENDIF}
 end;
 
 procedure DrawScreenWidget(widget: POnScreenWidget);
@@ -533,9 +677,9 @@
         if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
             fadeAnimStart:= 0
         else
-            if show then 
+            if show then
                 alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
-            else 
+            else
                 alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
         end;
 
@@ -570,7 +714,11 @@
 end;
 
 procedure Tint(r, g, b, a: Byte); inline;
-var nc, tw: Longword;
+var
+    nc, tw: Longword;
+    {$IFDEF GL2}
+    scale:Real = 1.0/255.0;
+    {$ENDIF}
 begin
     nc:= (r shl 24) or (g shl 16) or (b shl 8) or a;
 
@@ -587,7 +735,12 @@
         b:= tw
         end;
 
+    {$IFDEF GL2}
+    glUniform4f(uMainTintLocation, r*scale, g*scale, b*scale, a*scale);
+    //glColor4ub(r, g, b, a);
+    {$ELSE}
     glColor4ub(r, g, b, a);
+    {$ENDIF}
     lastTint:= nc;
 end;
 
--- a/hedgewars/uRenderUtils.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uRenderUtils.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -68,7 +68,7 @@
     r.y:= rect^.y + 2;
     r.w:= rect^.w - 2;
     r.h:= rect^.h - 4;
-    SDL_FillRect(Surface, @r, FillColor)
+    SDL_FillRect(Surface, @r, FillColor);
 end;
 (*
 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
@@ -115,6 +115,7 @@
     pixels: PLongWordArray;
 begin
     TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true);
+    SDL_LockSurface(Surface);
     pixels:= Surface^.pixels;
     if Vertical then
     for y := 0 to (Surface^.h div 2) - 1 do
@@ -136,6 +137,7 @@
             pixels^[i]:= pixels^[j];
             pixels^[j]:= tmpPixel;
             end;
+    SDL_UnlockSurface(Surface);
 end;
 
 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline;
@@ -150,6 +152,10 @@
 begin
     maxDest:= (dest^.pitch div 4) * dest^.h;
     maxSrc:= (src^.pitch div 4) * src^.h;
+
+    SDL_LockSurface(src);
+    SDL_LockSurface(dest);
+
     srcPixels:= src^.pixels;
     destPixels:= dest^.pixels;
 
@@ -169,6 +175,9 @@
             destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0);
             end;
         end;
+
+    SDL_UnlockSurface(src);
+    SDL_UnlockSurface(dest);
 end;
 
 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline;
@@ -182,12 +191,12 @@
     numFramesFirstCol:= SpritesData[sprite].imageHeight div SpritesData[sprite].Height;
     row:= Frame mod numFramesFirstCol;
     col:= Frame div numFramesFirstCol;
-    
-    copyToXYFromRect(SpritesData[sprite].Surface, dest, 
-             col*SpritesData[sprite].Width, 
-             row*SpritesData[sprite].Height, 
-             SpritesData[sprite].Width, 
-             spritesData[sprite].Height, 
+
+    copyToXYFromRect(SpritesData[sprite].Surface, dest,
+             col*SpritesData[sprite].Width,
+             row*SpritesData[sprite].Height,
+             SpritesData[sprite].Width,
+             spritesData[sprite].Height,
              x,y);
 end;
 
@@ -199,13 +208,16 @@
 begin
     //max:= (dest^.pitch div 4) * dest^.h;
     yMax:= dest^.pitch div 4;
+
+    SDL_LockSurface(dest);
+
     destPixels:= dest^.pixels;
 
     dx:= abs(x1-x0);
     dy:= abs(y1-y0);
     if x0 < x1 then sx:= 1 else sx:= -1;
     if y0 < y1 then sy:= 1 else sy:= -1;
-    err:= dx-dy; 
+    err:= dx-dy;
 
     while(true) do
         begin
@@ -225,7 +237,8 @@
             err:= err + dx;
             y0:=y0+sy
             end;
-        end; 
+        end;
+    SDL_UnlockSurface(dest);
 end;
 
 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently
@@ -235,6 +248,9 @@
     TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true);
     TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true);
 
+    SDL_LockSurface(src);
+    SDL_LockSurface(dest);
+
     srcPixels:= src^.pixels;
     destPixels:= dest^.pixels;
 
@@ -246,6 +262,10 @@
             destPixels^[j]:= srcPixels^[i];
             inc(j)
             end;
+
+    SDL_UnlockSurface(src);
+    SDL_UnlockSurface(dest);
+
 end;
 
 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
@@ -286,7 +306,7 @@
     substr: shortstring;
     edge, corner, tail: TSPrite;
 begin
-    case SpeechType of
+      case SpeechType of
         1: begin;
         edge:= sprSpeechEdge;
         corner:= sprSpeechCorner;
@@ -463,6 +483,7 @@
 
     SDL_FreeSurface(rotatedEdge);
     SDL_FreeSurface(finalSurface);
+
 end;
 
 end.
--- a/hedgewars/uScript.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uScript.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -85,8 +85,12 @@
     uIO,
     uVisualGearsList,
     uGearsHandlersMess,
-    uPhysFSLayer,
-    typinfo
+    uPhysFSLayer
+{$IFDEF PAS2C}
+    , hwpacksmounter
+{$ELSE}
+    , typinfo
+{$ENDIF}
     ;
 
 var luaState : Plua_State;
@@ -155,7 +159,7 @@
         lua_pushnil(L);
         end
     else
-        lua_pushinteger(L, not lua_tointeger(L, 1));
+        lua_pushinteger(L, (not lua_tointeger(L, 1)));
     lc_bnot := 1;
 end;
 
@@ -1208,7 +1212,7 @@
                 RecountTeamHealth(gear^.Hedgehog^.Team)
                 end;
             // Why did this do a "setalltoactive" ?
-            //SetAllToActive;  
+            //SetAllToActive;
             Gear^.Active:= true;
             AllInactive:= false
             end
@@ -2280,7 +2284,7 @@
 
 procedure ScriptCall(fname : shortstring);
 begin
-if not ScriptLoaded or (not ScriptExists(fname)) then
+if (not ScriptLoaded) or (not ScriptExists(fname)) then
     exit;
 SetGlobals;
 lua_getglobal(luaState, Str2PChar(fname));
@@ -2331,7 +2335,7 @@
 
 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
 begin
-if not ScriptLoaded or (not ScriptExists(fname)) then
+if (not ScriptLoaded) or (not ScriptExists(fname)) then
     exit;
 SetGlobals;
 lua_getglobal(luaState, Str2PChar(fname));
--- a/hedgewars/uSound.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uSound.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -315,7 +315,7 @@
     WriteLnToConsole(msgOK);
 
     Mix_AllocateChannels(Succ(chanTPU));
-    ChangeVolume(cInitVolume);	
+    ChangeVolume(cInitVolume);
 end;
 
 procedure ResetSound;
@@ -452,7 +452,7 @@
     i:= 0;
     while (i<High(VoiceList)) and (VoiceList[i].snd = sndNone) do
         inc(i);
-    
+
     if (VoiceList[i].snd <> sndNone) then
         begin
         LastVoice.snd:= VoiceList[i].snd;
--- a/hedgewars/uStats.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uStats.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -25,7 +25,7 @@
 var TotalRounds: LongInt;
     FinishedTurnsTotal: LongInt;
     SendHealthStatsOn : boolean = true;
-    
+
 procedure initModule;
 procedure freeModule;
 
@@ -111,7 +111,7 @@
     else if CurrentHedgehog^.stats.StepDamageRecv > 0 then
         begin
         AddVoice(sndStupid, PreviousTeam^.voicepack);
-        if CurrentHedgehog^.stats.DamageGiven = CurrentHedgehog^.stats.StepDamageRecv then 
+        if CurrentHedgehog^.stats.DamageGiven = CurrentHedgehog^.stats.StepDamageRecv then
             AddCaption(Format(GetEventString(eidHurtSelf), CurrentHedgehog^.Name), cWhiteColor, capgrpMessage);
         end
 
@@ -164,7 +164,7 @@
                 StepDamageRecv:= 0;
                 StepDamageGiven:= 0
                 end;
-                
+
 if SendHealthStatsOn then
     for t:= 0 to Pred(ClansCount) do
         with ClansArray[t]^ do
@@ -298,7 +298,7 @@
         SendStat(siKilledHHs, IntToStr(KilledHHs));
 
     // now to console
-    if winnersClan <> nil then 
+    if winnersClan <> nil then
         begin
         WriteLnToConsole('WINNERS');
         WriteLnToConsole(inttostr(winnersClan^.TeamsNumber));
@@ -307,12 +307,12 @@
         end
     else
         WriteLnToConsole('DRAW');
-        
+
     ScriptCall('onAchievementsDeclaration');
 end;
 
 procedure declareAchievement(id, teamname, location: shortstring; value: LongInt);
-begin 
+begin
 if (length(id) = 0) or (length(teamname) = 0) or (length(location) = 0) then exit;
     WriteLnToConsole('ACHIEVEMENT');
     WriteLnToConsole(id);
--- a/hedgewars/uStore.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uStore.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -21,7 +21,7 @@
 
 unit uStore;
 interface
-uses StrUtils, SysUtils, uConsts, SDLh, GLunit, uTypes, uLandTexture, uCaptions, uChat;
+uses {$IFNDEF PAS2C} StrUtils, {$ENDIF}SysUtils, uConsts, SDLh, GLunit, uTypes, uLandTexture, uCaptions, uChat;
 
 procedure initModule;
 procedure freeModule;
@@ -59,15 +59,24 @@
 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
 procedure SetSkyColor(r, g, b: real);
 
+{$IFDEF GL2}
+procedure UpdateModelviewProjection;
+procedure EnableTexture(enable:Boolean);
+{$ENDIF}
+
+procedure SetTexCoordPointer(p: Pointer;n: Integer);
+procedure SetVertexPointer(p: Pointer;n: Integer);
+procedure SetColorPointer(p: Pointer;n: Integer);
+procedure BeginWater;
+procedure EndWater;
+
 implementation
-uses uMisc, uConsole, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands
-    , uPhysFSLayer
-    , uDebug
+uses uMisc, uConsole, uVariables, uUtils, uTextures, uRender, uRenderUtils,
+     uCommands, uPhysFSLayer, uDebug
+    {$IFDEF GL2}, uMatrix{$ENDIF}
     {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}
     {$IF NOT DEFINED(SDL2) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
 
-//type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
-
 var MaxTextureSize: LongInt;
 {$IFDEF SDL2}
     SDLwindow: PSDL_Window;
@@ -79,6 +88,13 @@
     numsquares : LongInt;
     ProgrTex: PTexture;
 
+{$IFDEF GL2}
+    shaderMain: GLuint;
+    shaderWater: GLuint;
+
+    // attributes
+{$ENDIF}
+
 const
     cHHFileName = 'Hedgehog';
     cCHFileName = 'Crosshair';
@@ -159,7 +175,13 @@
 r.x:= 0;
 r.y:= 0;
 drY:= - 4;
+{$IFNDEF PAS2C}
 DecodeDate(Date, year, month, md);
+{$ELSE}
+year:= 0;
+month:= 0;
+md:= 0;
+{$ENDIF}
 for t:= 0 to Pred(TeamsCount) do
     with TeamsArray[t]^ do
         begin
@@ -249,7 +271,7 @@
                         else if (month = 10) and (md = 31) then
                             Hat := 'fr_pumpkin'; // Halloween/Hedgewars' birthday
                         end;
-                    
+
                     if Hat <> 'NoHat' then
                         begin
                         if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then
@@ -450,8 +472,10 @@
 if not reload then
     AddProgress;
 IMG_Quit();
+
 end;
 
+{$IFNDEF PAS2C}
 {$IF DEFINED(USE_S3D_RENDERING) OR DEFINED(USE_VIDEO_RECORDING)}
 procedure CreateFramebuffer(var frame, depth, tex: GLuint);
 begin
@@ -476,6 +500,7 @@
     glDeleteFramebuffersEXT(1, @frame);
 end;
 {$ENDIF}
+{$ENDIF}
 
 procedure StoreRelease(reload: boolean);
 var ii: TSprite;
@@ -539,6 +564,7 @@
                 end;
             end;
         end;
+{$IFNDEF PAS2C}
 {$IFDEF USE_VIDEO_RECORDING}
     if defaultFrame <> 0 then
         DeleteFramebuffer(defaultFrame, depthv, texv);
@@ -550,6 +576,7 @@
         DeleteFramebuffer(framer, depthr, texr);
         end
 {$ENDIF}
+{$ENDIF}
 end;
 
 
@@ -667,6 +694,8 @@
 
 function glLoadExtension(extension : shortstring) : boolean;
 begin
+//TODO: pas2c does not handle {$IF (GLunit = gles11) OR DEFINED(PAS2C)}
+{$IFNDEF PAS2C}
 {$IF GLunit = gles11}
     // FreePascal doesnt come with OpenGL ES 1.1 Extension headers
     extension:= extension; // avoid hint
@@ -679,6 +708,7 @@
     else
         AddFileLog('OpenGL - "' + extension + '" failed to load');
 {$ENDIF}
+{$ENDIF}
 end;
 
 procedure SetupOpenGLAttributes;
@@ -701,6 +731,112 @@
     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // prefer hw rendering
 end;
 
+{$IFDEF GL2}
+function CompileShader(shaderFile: string; shaderType: GLenum): GLuint;
+var
+    shader: GLuint;
+    f: Textfile;
+    source, line: AnsiString;
+    sourceA: Pchar;
+    lengthA: GLint;
+    compileResult: GLint;
+    logLength: GLint;
+    log: PChar;
+begin
+    Assign(f, PathPrefix + cPathz[ptShaders] + '/' + shaderFile);
+    filemode:= 0; // readonly
+    Reset(f);
+    if IOResult <> 0 then
+    begin
+        AddFileLog('Unable to load ' + shaderFile);
+        halt(-1);
+    end;
+
+    source:='';
+    while not eof(f) do
+    begin
+        ReadLn(f, line);
+        source:= source + line + #10;
+    end;
+
+    Close(f);
+
+    WriteLnToConsole('Compiling shader: ' + PathPrefix + cPathz[ptShaders] + '/' + shaderFile);
+
+    sourceA:=PChar(source);
+    lengthA:=Length(source);
+
+    shader:=glCreateShader(shaderType);
+    glShaderSource(shader, 1, @sourceA, @lengthA);
+    glCompileShader(shader);
+    glGetShaderiv(shader, GL_COMPILE_STATUS, @compileResult);
+    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, @logLength);
+
+    if logLength > 1 then
+    begin
+        log := GetMem(logLength);
+        glGetShaderInfoLog(shader, logLength, nil, log);
+        WriteLnToConsole('========== Compiler log  ==========');
+        WriteLnToConsole(shortstring(log));
+        WriteLnToConsole('===================================');
+        FreeMem(log, logLength);
+    end;
+
+    if compileResult <> GL_TRUE then
+    begin
+        WriteLnToConsole('Shader compilation failed, halting');
+        halt(-1);
+    end;
+
+    CompileShader:= shader;
+end;
+
+function CompileProgram(shaderName: string): GLuint;
+var
+    program_: GLuint;
+    vs, fs: GLuint;
+    linkResult: GLint;
+    logLength: GLint;
+    log: PChar;
+begin
+    program_:= glCreateProgram();
+    vs:= CompileShader(shaderName + '.vs', GL_VERTEX_SHADER);
+    fs:= CompileShader(shaderName + '.fs', GL_FRAGMENT_SHADER);
+    glAttachShader(program_, vs);
+    glAttachShader(program_, fs);
+
+    glBindAttribLocation(program_, aVertex, PChar('vertex'));
+    glBindAttribLocation(program_, aTexCoord, PChar('texcoord'));
+    glBindAttribLocation(program_, aColor, PChar('color'));
+
+    glLinkProgram(program_);
+    glDeleteShader(vs);
+    glDeleteShader(fs);
+
+    glGetProgramiv(program_, GL_LINK_STATUS, @linkResult);
+    glGetProgramiv(program_, GL_INFO_LOG_LENGTH, @logLength);
+
+    if logLength > 1 then
+    begin
+        log := GetMem(logLength);
+        glGetProgramInfoLog(program_, logLength, nil, log);
+        WriteLnToConsole('========== Compiler log  ==========');
+        WriteLnToConsole(shortstring(log));
+        WriteLnToConsole('===================================');
+        FreeMem(log, logLength);
+    end;
+
+    if linkResult <> GL_TRUE then
+    begin
+        WriteLnToConsole('Linking program failed, halting');
+        halt(-1);
+    end;
+
+    CompileProgram:= program_;
+end;
+
+{$ENDIF}
+
 procedure SetupOpenGL;
 var buf: array[byte] of char;
     AuxBufNum: LongInt = 0;
@@ -708,6 +844,7 @@
     tmpint: LongInt;
     tmpn: LongInt;
 begin
+
 {$IFDEF SDL2}
     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_GetCurrentVideoDriver()) + ')');
 {$ELSE}
@@ -740,8 +877,8 @@
         cReducedQuality := cReducedQuality or rqNoBackground;
         AddFileLog('Texture size too small for backgrounds, disabling.');
         end;
-
     // everyone loves debugging
+    // find out which gpu we are using (for extension compatibility maybe?)
     AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
     AddFileLog('  |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR))));
     AddFileLog('  |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION))));
@@ -750,6 +887,7 @@
     glGetIntegerv(GL_AUX_BUFFERS, @AuxBufNum);
     AddFileLog('  |----- Number of auxiliary buffers: ' + inttostr(AuxBufNum));
 {$ENDIF}
+{$IFNDEF PAS2C}
     AddFileLog('  \----- Extensions: ');
 
     // fetch extentions and store them in string
@@ -769,6 +907,7 @@
         tmpint := tmpint + 3;
     end;
     until (tmpint > tmpn);
+{$ENDIF}
     AddFileLog('');
 
     defaultFrame:= 0;
@@ -796,8 +935,42 @@
     end;
 {$ENDIF}
 
-{$IFDEF USE_S3D_RENDERING}
-    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
+{$IFDEF GL2}
+
+{$IFDEF PAS2C}
+    err := glewInit();
+    if err <> GLEW_OK then
+    begin
+        WriteLnToConsole('Failed to initialize GLEW.');
+        halt;
+    end;
+{$ENDIF}
+
+{$IFNDEF PAS2C}
+    if not Load_GL_VERSION_2_0 then
+        halt;
+{$ENDIF}
+
+    shaderWater:= CompileProgram('water');
+    glUseProgram(shaderWater);
+    glUniform1i(glGetUniformLocation(shaderWater, pchar('tex0')), 0);
+    uWaterMVPLocation:= glGetUniformLocation(shaderWater, pchar('mvp'));
+
+    shaderMain:= CompileProgram('default');
+    glUseProgram(shaderMain);
+    glUniform1i(glGetUniformLocation(shaderMain, pchar('tex0')), 0);
+    uMainMVPLocation:= glGetUniformLocation(shaderMain, pchar('mvp'));
+    uMainTintLocation:= glGetUniformLocation(shaderMain, pchar('tint'));
+
+    uCurrentMVPLocation:= uMainMVPLocation;
+
+    Tint(255, 255, 255, 255);
+    UpdateModelviewProjection;
+{$ENDIF}
+
+{$IFNDEF PAS2C}
+{$IFNDEF USE_S3D_RENDERING}
+    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
     begin
         // prepare left and right frame buffers and associated textures
         if glLoadExtension('GL_EXT_framebuffer_object') then
@@ -812,19 +985,33 @@
             cStereoMode:= smNone;
     end;
 {$ENDIF}
+{$ENDIF}
 
-    // set view port to whole window
-    glViewport(0, 0, cScreenWidth, cScreenHeight);
+// set view port to whole window
+glViewport(0, 0, cScreenWidth, cScreenHeight);
 
+{$IFDEF GL2}
+    uMatrix.initModule;
+    hglMatrixMode(MATRIX_MODELVIEW);
+    // prepare default translation/scaling
+    hglLoadIdentity();
+    hglScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
+    hglTranslatef(0, -cScreenHeight / 2, 0);
+
+    EnableTexture(True);
+
+    glEnableVertexAttribArray(aVertex);
+    glEnableVertexAttribArray(aTexCoord);
+    glGenBuffers(1, @vBuffer);
+    glGenBuffers(1, @tBuffer);
+    glGenBuffers(1, @cBuffer);
+{$ELSE}
     glMatrixMode(GL_MODELVIEW);
     // prepare default translation/scaling
     glLoadIdentity();
     glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
     glTranslatef(0, -cScreenHeight / 2, 0);
 
-    // enable alpha blending
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     // disable/lower perspective correction (will not need it anyway)
     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
     // disable dithering
@@ -833,8 +1020,97 @@
     glEnable(GL_TEXTURE_2D);
     glEnableClientState(GL_VERTEX_ARRAY);
     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+{$ENDIF}
+
+    // enable alpha blending
+    glEnable(GL_BLEND);
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    // disable/lower perspective correction (will not need it anyway)
 end;
 
+{$IFDEF GL2}
+procedure EnableTexture(enable:Boolean);
+begin
+    if enable then
+        glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 1)
+    else
+        glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 0);
+end;
+{$ENDIF}
+
+procedure SetTexCoordPointer(p: Pointer; n: Integer);
+begin
+{$IFDEF GL2}
+    glBindBuffer(GL_ARRAY_BUFFER, tBuffer);
+    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
+    glEnableVertexAttribArray(aTexCoord);
+    glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
+{$ELSE}
+    n:= n;
+    glTexCoordPointer(2, GL_FLOAT, 0, p);
+{$ENDIF}
+end;
+
+procedure SetVertexPointer(p: Pointer; n: Integer);
+begin
+{$IFDEF GL2}
+    glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
+    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
+    glEnableVertexAttribArray(aVertex);
+    glVertexAttribPointer(aVertex, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
+{$ELSE}
+    n:= n;
+    glVertexPointer(2, GL_FLOAT, 0, p);
+{$ENDIF}
+end;
+
+procedure SetColorPointer(p: Pointer; n: Integer);
+begin
+{$IFDEF GL2}
+    glBindBuffer(GL_ARRAY_BUFFER, cBuffer);
+    glBufferData(GL_ARRAY_BUFFER, n * 4, p, GL_STATIC_DRAW);
+    glEnableVertexAttribArray(aColor);
+    glVertexAttribPointer(aColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, pointer(0));
+{$ELSE}
+    n:= n;
+    glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
+{$ENDIF}
+end;
+
+{$IFDEF GL2}
+procedure UpdateModelviewProjection;
+var
+    mvp: TMatrix4x4f;
+begin
+    //MatrixMultiply(mvp, mProjection, mModelview);
+{$HINTS OFF}
+    hglMVP(mvp);
+{$HINTS ON}
+    glUniformMatrix4fv(uCurrentMVPLocation, 1, GL_FALSE, @mvp[0, 0]);
+end;
+{$ENDIF}
+
+(*
+procedure UpdateProjection;
+var
+    s: GLfloat;
+begin
+    s:=cScaleFactor;
+    mProjection[0,0]:= s/cScreenWidth; mProjection[0,1]:=  0.0;             mProjection[0,2]:=0.0; mProjection[0,3]:=  0.0;
+    mProjection[1,0]:= 0.0;            mProjection[1,1]:= -s/cScreenHeight; mProjection[1,2]:=0.0; mProjection[1,3]:=  0.0;
+    mProjection[2,0]:= 0.0;            mProjection[2,1]:=  0.0;             mProjection[2,2]:=1.0; mProjection[2,3]:=  0.0;
+    mProjection[3,0]:= cStereoDepth;   mProjection[3,1]:=  s/2;             mProjection[3,2]:=0.0; mProjection[3,3]:=  1.0;
+
+{$IFDEF GL2}
+    UpdateModelviewProjection;
+{$ELSE}
+    glMatrixMode(GL_PROJECTION);
+    glLoadMatrixf(@mProjection[0, 0]);
+    glMatrixMode(GL_MODELVIEW);
+{$ENDIF}
+end;
+*)
+
 procedure SetScale(f: GLfloat);
 begin
 // leave immediately if scale factor did not change
@@ -842,18 +1118,62 @@
         exit;
 
     if f = cDefaultZoomLevel then
-        glPopMatrix         // return to default scaling
+{$IFDEF GL2}
+        hglPopMatrix         // "return" to default scaling
+{$ELSE}
+        glPopMatrix
+{$ENDIF}
     else                    // other scaling
         begin
+{$IFDEF GL2}
+        hglPushMatrix;       // save default scaling
+        hglLoadIdentity;
+        hglScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
+        hglTranslatef(0, -cScreenHeight / 2, 0);
+{$ELSE}
         glPushMatrix;       // save default scaling
         glLoadIdentity;
         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
         glTranslatef(0, -cScreenHeight / 2, 0);
+{$ENDIF}
         end;
 
     cScaleFactor:= f;
+
+{$IFDEF GL2}
+    UpdateModelviewProjection;
+{$ENDIF}
 end;
 
+procedure BeginWater;
+begin
+{$IFDEF GL2}
+    glUseProgram(shaderWater);
+    uCurrentMVPLocation:=uWaterMVPLocation;
+    UpdateModelviewProjection;
+    glDisableVertexAttribArray(aTexCoord);
+    glEnableVertexAttribArray(aColor);
+{$ELSE}
+    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+    glEnableClientState(GL_COLOR_ARRAY);
+{$ENDIF}
+end;
+
+procedure EndWater;
+begin
+{$IFDEF GL2}
+    glUseProgram(shaderMain);
+    uCurrentMVPLocation:=uMainMVPLocation;
+    UpdateModelviewProjection;
+    glDisableVertexAttribArray(aColor);
+    glEnableVertexAttribArray(aTexCoord);
+{$ELSE}
+    glDisableClientState(GL_COLOR_ARRAY);
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+{$ENDIF}
+end;
+
+
 ////////////////////////////////////////////////////////////////////////////////
 procedure AddProgress;
 var r: TSDL_Rect;
@@ -870,10 +1190,11 @@
         squaresize:= texsurf^.w shr 1;
         numsquares:= texsurf^.h div squaresize;
         SDL_FreeSurface(texsurf);
+        {$IFNDEF PAS2C}
         with mobileRecord do
             if GameLoading <> nil then
                 GameLoading();
-
+        {$ENDIF}
         end;
 
     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
@@ -891,14 +1212,17 @@
     DrawTextureFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
 
     SwapBuffers;
+
     inc(Step);
 end;
 
 procedure FinishProgress;
 begin
+    {$IFNDEF PAS2C}
     with mobileRecord do
         if GameLoaded <> nil then
             GameLoaded();
+    {$ENDIF}
     WriteLnToConsole('Freeing progress surface... ');
     FreeTexture(ProgrTex);
     ProgrTex:= nil;
@@ -1244,6 +1568,7 @@
 {$ENDIF}
 
     SetupOpenGL();
+
     if reinit then
         begin
         // clean the window from any previous content
@@ -1320,6 +1645,13 @@
 
 procedure freeModule;
 begin
+{$IFDEF GL2}
+    glDeleteProgram(shaderMain);
+    glDeleteProgram(shaderWater);
+    glDeleteBuffers(1, @vBuffer);
+    glDeleteBuffers(1, @tBuffer);
+    glDeleteBuffers(1, @cBuffer);
+{$ENDIF}
     StoreRelease(false);
     TTF_Quit();
 {$IFDEF SDL2}
--- a/hedgewars/uTeams.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uTeams.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -20,7 +20,7 @@
 
 unit uTeams;
 interface
-uses uConsts, uInputHandler, uRandom, uFloat, uStats, 
+uses uConsts, uInputHandler, uRandom, uFloat, uStats,
      uCollisions, uSound, uStore, uTypes, uScript
      {$IFDEF USE_TOUCH_INTERFACE}, uWorld{$ENDIF};
 
@@ -567,7 +567,10 @@
 var i: LongInt;
 begin
     for i:= 1 to length(s) do
-        if s[i] in ['\', '/', ':'] then s[i]:= '_';
+        if ((s[i] = '\') or
+            (s[i] = '/') or
+            (s[i] = ':')) then
+            s[i]:= '_';
 
     s:= cPathz[ptTeams] + '/' + s + '.hwt';
 
@@ -593,7 +596,7 @@
     CurrentTeam^.TeamName:= ts;
     CurrentTeam^.PlayerHash:= s;
     loadTeamBinds(ts);
-    
+
     if GameType in [gmtDemo, gmtSave, gmtRecord] then
         CurrentTeam^.ExtDriven:= true;
 
--- a/hedgewars/uTextures.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uTextures.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -109,11 +109,11 @@
 fromP4:= Surf^.pixels;
 for y:= 0 to Pred(Surf^.h) do
     begin
-    for x:= 0 to Pred(Surf^.w) do 
+    for x:= 0 to Pred(Surf^.w) do
         begin
         tw:= fromP4^[x];
-        tw:= round((tw shr RShift and $FF) * RGB_LUMINANCE_RED +  
-              (tw shr GShift and $FF) * RGB_LUMINANCE_GREEN + 
+        tw:= round((tw shr RShift and $FF) * RGB_LUMINANCE_RED +
+              (tw shr GShift and $FF) * RGB_LUMINANCE_GREEN +
               (tw shr BShift and $FF) * RGB_LUMINANCE_BLUE);
         if tw > 255 then tw:= 255;
         tw:= (tw and $FF shl RShift) or (tw and $FF shl BShift) or (tw and $FF shl GShift) or (fromP4^[x] and AMask);
@@ -327,7 +327,7 @@
 begin
 if TextureList <> nil then
     WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem');
-    while TextureList <> nil do 
+    while TextureList <> nil do
         begin
         AddFileLog('Texture not freed: width='+inttostr(LongInt(TextureList^.w))+' height='+inttostr(LongInt(TextureList^.h))+' priority='+inttostr(round(TextureList^.priority*1000)));
         FreeTexture(TextureList);
--- a/hedgewars/uTouch.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uTouch.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -360,8 +360,9 @@
     //Check array sizes
     if length(fingers) < pointerCount then
     begin
-        setLength(fingers, pointerCount * 2);
-        WriteLnToConsole('allocated ' + inttostr(length(fingers)) + ' finger elements');
+        setLength(fingers, length(fingers)*2);
+        for index := length(fingers) div 2 to length(fingers) do
+            fingers[index].id := nilFingerId;
     end;
 
     xCursor := convertToCursorX(x);
--- a/hedgewars/uTypes.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uTypes.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -43,8 +43,9 @@
 
     // Different files are stored in different folders, this enumeration is used to tell which folder to use
     TPathType = (ptNone, ptData, ptGraphics, ptThemes, ptCurrTheme, ptTeams, ptMaps,
-            ptMapCurrent, ptDemos, ptSounds, ptGraves, ptFonts, ptForts,
-            ptLocale, ptAmmoMenu, ptHedgehog, ptVoices, ptHats, ptFlags, ptMissionMaps, ptSuddenDeath, ptButtons);
+            ptMapCurrent, ptDemos, ptSounds, ptGraves, ptFonts, ptForts, ptLocale,
+            ptAmmoMenu, ptHedgehog, ptVoices, ptHats, ptFlags, ptMissionMaps,
+            ptSuddenDeath, ptButtons, ptShaders);
 
     // Available sprites for displaying stuff
     TSprite = (sprWater, sprCloud, sprBomb, sprBigDigit, sprFrame,
@@ -90,7 +91,7 @@
             );
 
     // Gears that interact with other Gears and/or Land
-    TGearType = ({-->}gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives, // <-- these are gears which should be avoided when searching a spawn place
+    TGearType = (gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives, // these gears should be avoided when searching a spawn place
             gtGrenade, gtShell, gtGrave, gtBee, // 8
             gtShotgunShot, gtPickHammer, gtRope,  // 11
             gtDEagleShot, gtDynamite, gtClusterBomb, gtCluster, gtShover, // 16
@@ -138,9 +139,10 @@
             sndHellishImpact1, sndHellishImpact2, sndHellishImpact3, sndHellishImpact4,
             sndMelonImpact, sndDroplet1, sndDroplet2, sndDroplet3, sndEggBreak, sndDrillRocket,
             sndPoisonCough, sndPoisonMoan, sndBirdyLay, sndWhistle, sndBeeWater,
-            sndPiano0, sndPiano1, sndPiano2, sndPiano3, sndPiano4, sndPiano5, sndPiano6, sndPiano7, sndPiano8,
-            sndSkip, sndSineGun, sndOoff1, sndOoff2, sndOoff3, sndWhack,
-            sndComeonthen, sndParachute, sndBump, sndResurrector, sndPlane, sndTardis, sndFrozenHogImpact, sndIceBeam, sndHogFreeze
+            sndPiano0, sndPiano1, sndPiano2, sndPiano3, sndPiano4, sndPiano5, sndPiano6, sndPiano7,
+            sndPiano8, sndSkip, sndSineGun, sndOoff1, sndOoff2, sndOoff3, sndWhack,
+            sndComeonthen, sndParachute, sndBump, sndResurrector, sndPlane, sndTardis, sndFrozenHogImpact,
+            sndIceBeam, sndHogFreeze
             );
 
     // Available ammo types to be used by hedgehogs
@@ -167,7 +169,7 @@
             siMaxTeamKills, siMaxTurnSkips, siCustomAchievement, siGraphTitle,
             siPointType);
 
-    // Various "emote" animations a hedgehog can do
+    // Various 'emote' animations a hedgehog can do
     TWave = (waveRollup, waveSad, waveWave, waveHurrah, waveLemonade, waveShrug, waveJuggle);
 
     TRenderMode = (rmDefault, rmLeftEye, rmRightEye);
@@ -186,8 +188,8 @@
     TAmmo = record
             Propz: LongWord;
             Count: LongWord;
-(* Using for place hedgehogs mode, but for any other situation where the initial count would be needed I guess.
-For example, say, a mode where the weaponset is reset each turn, or on sudden death *)
+// Using for place hedgehogs mode, but for any other situation where the initial count would be needed I guess.
+// For example, say, a mode where the weaponset is reset each turn, or on sudden death
             NumPerTurn: LongWord;
             Timer: LongWord;
             Pos: LongWord;
@@ -204,6 +206,8 @@
             X, Y: GLint;
             end;
 
+    TMatrix4x4f = array[0..3, 0..3] of GLfloat;
+
     PTexture = ^TTexture;
     TTexture = record
             id: GLuint;
@@ -224,10 +228,10 @@
     PClan     = ^TClan;
 
     TGearStepProcedure = procedure (Gear: PGear);
-// So, you're here looking for variables you can (ab)use to store some gear state?
+// So, you are here looking for variables you can (ab)use to store some gear state?
 // Not all members of this structure are created equal. Comments below are my take on what can be used for what in the gear structure.
     TGear = record
-// Don't ever override these.
+// Do *not* ever override these.
             NextGear, PrevGear: PGear;  // Linked list
             Z: Longword;                // Z index. For rendering. Sets order in list
             Active: Boolean;            // Is gear Active (running step code)
@@ -251,7 +255,7 @@
 // Don't use these if you're using generic movement like doStepFallingGear and explosion shoves. Generally recommended not to use.
             Radius: LongInt;     // Radius. If not using uCollisions, is usually used to indicate area of effect
             CollisionMask: Word; // Masking off Land impact  FF7F for example ignores current hog and crates
-            AdvBounce: Longword; // Triggers 45° bounces. Is a counter to avoid edge cases
+            AdvBounce: Longword; // Triggers 45 bounces. Is a counter to avoid edge cases
             Elasticity: hwFloat;
             Friction  : hwFloat;
             Density   : hwFloat; // Density is kind of a mix of size and density. Impacts distance thrown, wind.
@@ -259,7 +263,7 @@
             nImpactSounds: Word; // count of ImpactSounds.
 // Don't use these if you want to take damage normally, otherwise health/damage are commonly used for other purposes
             Health, Damage, Karma: LongInt;
-// DirAngle is a "real" - if you don't need it for rotation of sprite in uGearsRender, you can use it for any visual-only value
+// DirAngle is a 'real' - if you do not need it for rotation of sprite in uGearsRender, you can use it for any visual-only value
             DirAngle: real;
 // These are frequently overridden to serve some other purpose
             Pos: Longword;           // Commonly overridden.  Example use is posCase values in uConsts.
@@ -416,6 +420,7 @@
 
      cdeclPtr = procedure; cdecl;
      cdeclIntPtr = procedure(num: LongInt); cdecl;
+     funcDoublePtr = function: Double;
 
      TMobileRecord = record
                      PerformRumble: cdeclIntPtr;
@@ -455,10 +460,12 @@
             gidRandomMineTimer, gidDamageModifier, gidResetHealth, gidAISurvival,
             gidInfAttack, gidResetWeps, gidPerHogAmmo, gidTagTeam);
 
+
     TLandArray = packed array of array of LongWord;
     TCollisionArray = packed array of array of Word;
+    TDirtyTag = packed array of array of byte;
+
     TPreview  = packed array[0..127, 0..31] of byte;
-    TDirtyTag = packed array of array of byte;
 
     PWidgetMovement = ^TWidgetMovement;
     TWidgetMovement = record
--- a/hedgewars/uUtils.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uUtils.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -25,7 +25,10 @@
 
 procedure SplitBySpace(var a, b: shortstring);
 procedure SplitByChar(var a, b: shortstring; c: char);
+
+{$IFNDEF PAS2C}
 procedure SplitByChar(var a, b: ansistring; c: char);
+{$ENDIF}
 
 function  EnumToStr(const en : TGearType) : shortstring; overload;
 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
@@ -67,8 +70,10 @@
 function  GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt;
 function  GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
 
+{$IFNDEF PAS2C}
 procedure Write(var f: textfile; s: shortstring);
 procedure WriteLn(var f: textfile; s: shortstring);
+{$ENDIF}
 
 function  isPhone: Boolean; inline;
 
@@ -88,7 +93,7 @@
 
 
 implementation
-uses typinfo, Math, uConsts, uVariables, SysUtils;
+uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils;
 
 {$IFDEF DEBUGFILE}
 var f: textfile;
@@ -96,7 +101,7 @@
     logMutex: TRTLCriticalSection; // mutex for debug file
 {$ENDIF}
 {$ENDIF}
-var CharArray: array[byte] of Char;
+var CharArray: array[0..255] of Char;
 
 procedure SplitBySpace(var a,b: shortstring);
 begin
@@ -115,11 +120,15 @@
             Inc(a[t], 32);
     b:= copy(a, i + 1, Length(a) - i);
     a[0]:= char(Pred(i))
+    {$IFDEF PAS2C}
+       a[i] := 0;
+    {$ENDIF}
     end
 else
     b:= '';
 end;
 
+{$IFNDEF PAS2C}
 procedure SplitByChar(var a, b: ansistring; c: char);
 var i: LongInt;
 begin
@@ -129,7 +138,8 @@
     b:= copy(a, i + 1, Length(a) - i);
     setlength(a, Pred(i));
     end else b:= '';
-end;
+end; { SplitByChar }
+{$ENDIF}
 
 function EnumToStr(const en : TGearType) : shortstring; overload;
 begin
@@ -189,14 +199,18 @@
 str(n, IntToStr)
 end;
 
-function  StrToInt(s: shortstring): LongInt;
+function StrToInt(s: shortstring): LongInt;
 var c: LongInt;
 begin
+{$IFDEF PAS2C}
+val(s, StrToInt);
+{$ELSE}
 val(s, StrToInt, c);
 {$IFDEF DEBUGFILE}
 if c <> 0 then
     writeln(f, 'Error at position ' + IntToStr(c) + ' : ' + s[c])
 {$ENDIF}
+{$ENDIF}
 end;
 
 function FloatToStr(n: hwFloat): shortstring;
@@ -290,10 +304,14 @@
 
 
 function Str2PChar(const s: shortstring): PChar;
+var i :Integer ;
 begin
-CharArray:= s;
+   for i:= 1 to Length(s) do
+      begin
+      CharArray[i - 1] := s[i];
+      end;
 CharArray[Length(s)]:= #0;
-Str2PChar:= @CharArray
+   Str2PChar:= @(CharArray[0]);
 end;
 
 
@@ -312,22 +330,26 @@
 
 procedure AddFileLog(s: shortstring);
 begin
-s:= s;
+// s:= s;
 {$IFDEF DEBUGFILE}
+
 {$IFDEF USE_VIDEO_RECORDING}
 EnterCriticalSection(logMutex);
 {$ENDIF}
 writeln(f, inttostr(GameTicks)  + ': ' + s);
 flush(f);
+
 {$IFDEF USE_VIDEO_RECORDING}
 LeaveCriticalSection(logMutex);
 {$ENDIF}
+
 {$ENDIF}
 end;
 
 procedure AddFileLogRaw(s: pchar); cdecl;
 begin
 s:= s;
+{$IFNDEF PAS2C}
 {$IFDEF DEBUGFILE}
 {$IFDEF USE_VIDEO_RECORDING}
 EnterCriticalSection(logMutex);
@@ -338,6 +360,7 @@
 LeaveCriticalSection(logMutex);
 {$ENDIF}
 {$ENDIF}
+{$ENDIF}
 end;
 
 function CheckCJKFont(s: ansistring; font: THWFont): THWFont;
@@ -370,7 +393,7 @@
        ((#$F900  <= u) and (u <= #$FAFF))  or // CJK Compatibility Ideographs
        ((#$FE30  <= u) and (u <= #$FE4F))  or // CJK Compatibility Forms
        ((#$FF66  <= u) and (u <= #$FF9D)))    // halfwidth katakana
-       then 
+       then
         begin
             CheckCJKFont:=  THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) );
             exit;
@@ -408,6 +431,7 @@
 CheckNoTeamOrHH:= (CurrentTeam = nil) or (CurrentHedgehog^.Gear = nil);
 end;
 
+{$IFNDEF PAS2C}
 procedure Write(var f: textfile; s: shortstring);
 begin
 system.write(f, s)
@@ -417,7 +441,7 @@
 begin
 system.writeln(f, s)
 end;
-
+{$ENDIF}
 
 // this function is just to determine whether we are running on a limited screen device
 function isPhone: Boolean; inline;
@@ -444,7 +468,7 @@
             r[i]:= '?'
             else
             r[i]:= s[i];
-            
+
     sanitizeForLog:= r
 end;
 
@@ -454,8 +478,12 @@
     if (c < #32) or (c > #127) then
         r:= '#' + inttostr(byte(c))
         else
-        r:= c;
-            
+        begin
+        // some magic for pas2c
+        r[0]:= #1;
+        r[1]:= c;
+        end;
+
     sanitizeCharForLog:= r
 end;
 
@@ -479,13 +507,16 @@
     InitCriticalSection(logMutex);
 {$ENDIF}
 {$I-}
+{$IFNDEF PAS2C}
     f:= stderr; // if everything fails, write to stderr
+{$ENDIF}
     if (UserPathPrefix <> '') then
         begin
+        {$IFNDEF PAS2C}
         // create directory if it doesn't exist
         if not FileExists(UserPathPrefix + '/Logs/') then
             CreateDir(UserPathPrefix + '/Logs/');
-
+        {$ENDIF}
         // if log is locked, write to the next one
         i:= 0;
         while(i < 7) do
--- a/hedgewars/uVariables.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uVariables.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -21,7 +21,7 @@
 unit uVariables;
 interface
 
-uses SDLh, uTypes, uFloat, GLunit, uConsts, Math;
+uses SDLh, uTypes, uFloat, GLunit, uConsts, Math, uUtils, uMatrix;
 
 var
 /////// init flags ///////
@@ -174,7 +174,7 @@
     cArtillery      : boolean;
     WeaponTooltipTex: PTexture;
     AmmoMenuInvalidated: boolean;
-    AmmoRect		: TSDL_Rect;
+    AmmoRect        : TSDL_Rect;
     HHTexture       : PTexture;
     cMaxZoomLevel   : real;
     cMinZoomLevel   : real;
@@ -234,7 +234,7 @@
     // these consts are here because they would cause circular dependencies in uConsts/uTypes
     cPathz: array[TPathType] of shortstring = (
         '',                              // ptNone
-        '/',                             // ptData
+        '//',                            // ptData
         '/Graphics',                     // ptGraphics
         '/Themes',                       // ptThemes
         '/Themes/Bamboo',                // ptCurrTheme
@@ -254,9 +254,11 @@
         '/Graphics/Flags',               // ptFlags
         '/Missions/Maps',                // ptMissionMaps
         '/Graphics/SuddenDeath',         // ptSuddenDeath
-        '/Graphics/Buttons'              // ptButton
+        '/Graphics/Buttons',             // ptButton
+        '/Shaders'                       // ptShaders
     );
 
+var
     Fontz: array[THWFont] of THHFont = (
             (Handle: nil;
             Height: 12;
@@ -718,7 +720,7 @@
             TimeAfterTurn: Longword;
             minAngle, maxAngle: Longword;
             isDamaging: boolean;
-            SkipTurns: Longword;
+            SkipTurns: LongWord;
             PosCount: Longword;
             PosSprite: TSprite;
             ejectX, ejectY: Longint;
@@ -751,9 +753,9 @@
             NameTex: nil;
             Probability: 0;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Timerable or 
-                          ammoprop_Power or 
-                          ammoprop_AltUse or 
+            Ammo: (Propz: ammoprop_Timerable or
+                          ammoprop_Power or
+                          ammoprop_AltUse or
                           ammoprop_SetBounce or
                           ammoprop_NeedUpDown;
                 Count: AMMO_INFINITE;
@@ -779,9 +781,9 @@
             NameTex: nil;
             Probability: 100;
             NumberInCase: 3;
-            Ammo: (Propz: ammoprop_Timerable or 
-                          ammoprop_Power or 
-                          ammoprop_AltUse or 
+            Ammo: (Propz: ammoprop_Timerable or
+                          ammoprop_Power or
+                          ammoprop_AltUse or
                           ammoprop_SetBounce or
                           ammoprop_NeedUpDown;
                 Count: 5;
@@ -807,7 +809,7 @@
             NameTex: nil;
             Probability: 0;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Power or 
+            Ammo: (Propz: ammoprop_Power or
                           ammoprop_AltUse or
                           ammoprop_NeedUpDown;
                 Count: AMMO_INFINITE;
@@ -833,8 +835,8 @@
             NameTex: nil;
             Probability: 100;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Power or 
-                          ammoprop_NeedTarget or 
+            Ammo: (Propz: ammoprop_Power or
+                          ammoprop_NeedTarget or
                           ammoprop_DontHold or
                           ammoprop_NeedUpDown;
                 Count: 2;
@@ -886,9 +888,9 @@
             NameTex: nil;
             Probability: 0;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_ForwMsgs or 
-                          ammoprop_AttackInMove or 
-                          ammoprop_NoCrosshair or 
+            Ammo: (Propz: ammoprop_ForwMsgs or
+                          ammoprop_AttackInMove or
+                          ammoprop_NoCrosshair or
                           ammoprop_DontHold;
                 Count: 2;
                 NumPerTurn: 0;
@@ -969,10 +971,10 @@
             NameTex: nil;
             Probability: 100;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_NoCrosshair or 
-                          ammoprop_AttackInMove or 
-                          ammoprop_DontHold or 
-                          ammoprop_AltUse or 
+            Ammo: (Propz: ammoprop_NoCrosshair or
+                          ammoprop_AttackInMove or
+                          ammoprop_DontHold or
+                          ammoprop_AltUse or
                           ammoprop_SetBounce;
                 Count: 2;
                 NumPerTurn: 0;
@@ -1021,9 +1023,9 @@
             NameTex: nil;
             Probability: 100;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_NoCrosshair or 
-                          ammoprop_AttackInMove or 
-                          ammoprop_DontHold or 
+            Ammo: (Propz: ammoprop_NoCrosshair or
+                          ammoprop_AttackInMove or
+                          ammoprop_DontHold or
                           ammoprop_AltUse;
                 Count: 1;
                 NumPerTurn: 0;
@@ -1048,8 +1050,8 @@
             NameTex: nil;
             Probability: 0;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_NoCrosshair or 
-                          ammoprop_ForwMsgs or 
+            Ammo: (Propz: ammoprop_NoCrosshair or
+                          ammoprop_ForwMsgs or
                           ammoprop_AttackInMove;
                 Count: AMMO_INFINITE;
                 NumPerTurn: 0;
@@ -1344,8 +1346,8 @@
             NameTex: nil;
             Probability: 100;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_ForwMsgs or 
-                          ammoprop_DontHold or 
+            Ammo: (Propz: ammoprop_ForwMsgs or
+                          ammoprop_DontHold or
                           ammoprop_NeedUpDown or
                           ammoprop_AttackInMove;
                 Count: 1;
@@ -1371,8 +1373,8 @@
             NameTex: nil;
             Probability: 100;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_ForwMsgs or 
-                          ammoprop_NoCrosshair or 
+            Ammo: (Propz: ammoprop_ForwMsgs or
+                          ammoprop_NoCrosshair or
                           ammoprop_DontHold or
                           ammoprop_Track;
                 Count: 1;
@@ -1398,7 +1400,7 @@
             NameTex: nil;
             Probability: 100;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_ForwMsgs or 
+            Ammo: (Propz: ammoprop_ForwMsgs or
                           ammoprop_DontHold or
                           ammoprop_NoCrosshair;
                 Count: 1;
@@ -1424,8 +1426,8 @@
             NameTex: nil;
             Probability: 400;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Timerable or 
-                          ammoprop_Power or 
+            Ammo: (Propz: ammoprop_Timerable or
+                          ammoprop_Power or
                           ammoprop_NeedUpDown or
                           ammoprop_AltUse;
                 Count: 0;
@@ -1451,7 +1453,7 @@
             NameTex: nil;
             Probability: 400;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Power or 
+            Ammo: (Propz: ammoprop_Power or
                           ammoprop_NeedUpDown or
                           ammoprop_AltUse;
                 Count: 0;
@@ -1505,7 +1507,7 @@
             NameTex: nil;
             Probability: 300;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Power or 
+            Ammo: (Propz: ammoprop_Power or
                           ammoprop_NeedUpDown or
                           ammoprop_AltUse;
                 Count: AMMO_INFINITE;
@@ -1531,7 +1533,7 @@
             NameTex: nil;
             Probability: 400;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_ForwMsgs or 
+            Ammo: (Propz: ammoprop_ForwMsgs or
                           ammoprop_NeedUpDown or
                           ammoprop_DontHold;
                 Count: AMMO_INFINITE;
@@ -1816,7 +1818,7 @@
             NameTex: nil;
             Probability: 0;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Power or 
+            Ammo: (Propz: ammoprop_Power or
                           ammoprop_NeedUpDown or
                           ammoprop_AltUse;
                 Count: AMMO_INFINITE;
@@ -1925,9 +1927,9 @@
             NameTex: nil;
             Probability: 0;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Timerable or 
-                          ammoprop_Power or 
-                          ammoprop_AltUse or 
+            Ammo: (Propz: ammoprop_Timerable or
+                          ammoprop_Power or
+                          ammoprop_AltUse or
                           ammoprop_NeedUpDown or
                           ammoprop_SetBounce;
                 Count: AMMO_INFINITE;
@@ -1978,7 +1980,7 @@
             NameTex: nil;
             Probability: 20;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_ForwMsgs or 
+            Ammo: (Propz: ammoprop_ForwMsgs or
                           ammoprop_NeedUpDown or
                           ammoprop_DontHold;
                 Count: 1;
@@ -2109,7 +2111,7 @@
             NameTex: nil;
             Probability: 0;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_Power or 
+            Ammo: (Propz: ammoprop_Power or
                           ammoprop_AltUse or
                           ammoprop_NoRoundEnd;
                 Count: 2;
@@ -2127,7 +2129,7 @@
             SkipTurns: 0;
             PosCount: 1;
             PosSprite: sprWater;
-            ejectX: 0; 
+            ejectX: 0;
             ejectY: 0),
 
 // Tardis
@@ -2157,7 +2159,7 @@
             ejectX: 0;
             ejectY: 0),
 
-// Structure      
+// Structure
 {
             (NameId: sidStructure;
             NameTex: nil;
@@ -2185,7 +2187,7 @@
             ejectX: 0;
             ejectY: 0),
 }
-            
+
 // Land Gun
             (NameId: sidLandGun;
             NameTex: nil;
@@ -2215,7 +2217,7 @@
             NameTex: nil;
             Probability: 20;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_ForwMsgs or 
+            Ammo: (Propz: ammoprop_ForwMsgs or
                           ammoprop_NeedUpDown or
                           ammoprop_DontHold;
                 Count: 1;
@@ -2342,6 +2344,7 @@
     SyncTexture,
     ConfirmTexture: PTexture;
     cScaleFactor: GLfloat;
+    cStereoDepth: GLfloat;
     SupportNPOTT: Boolean;
     Step: LongInt;
     MissionIcons: PSDL_Surface;
@@ -2365,13 +2368,29 @@
 
     lastTurnChecksum : Longword;
 
-    cTestLua : Boolean;
+    mModelview: TMatrix4x4f;
+    mProjection: TMatrix4x4f;
+    vBuffer: GLuint; // vertex buffer
+    tBuffer: GLuint; // texture coords buffer
+    cBuffer: GLuint; // color buffer
+
+    uCurrentMVPLocation: GLint;
+
+    uMainMVPLocation: GLint;
+    uMainTintLocation: GLint;
+
+    uWaterMVPLocation: GLint;
+
+    aVertex: GLint;
+    aTexCoord: GLint;
+    aColor: GLint;
 
 var trammo:  array[TAmmoStrId] of PChar;   // name of the weapon
     trammoc: array[TAmmoStrId] of PChar;   // caption of the weapon
     trammod: array[TAmmoStrId] of PChar;   // description of the weapon
     trmsg:   array[TMsgStrId]  of PChar;   // message of the event
     trgoal:  array[TGoalStrId] of PChar;   // message of the goal
+    cTestLua : Boolean;
 
 procedure preInitModule;
 procedure initModule;
@@ -2437,9 +2456,14 @@
         trmsg[msid]:= nil;
     for gsid:= Low(TGoalStrId) to High(TGoalStrId) do
         trgoal[gsid]:= nil;
-        
+
+// TODO: fixme
+{$IFDEF PAS2C}
+    cLocale:= 'en';
+{$ELSE}
     // TODO: we could just have one cLocale variables and drop strutils
     cLocale:= ExtractDelimited(1, cLocaleFName, StdWordDelims);
+{$ENDIF}
 
     cFlattenFlakes      := false;
     cFlattenClouds      := false;
@@ -2575,7 +2599,7 @@
     cHasFocus       := true;
     cInactDelay     := 100;
     ReadyTimeLeft   := 0;
-    
+
     disableLandBack := false;
     ScreenFade      := sfNone;
 
--- a/hedgewars/uVisualGears.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uVisualGears.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -219,7 +219,7 @@
                               else
                                   DrawSprite(sprDroplet, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, Gear^.Frame);
                   vgtBubble: DrawSprite(sprBubbles, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, Gear^.Frame);//(RealTicks div 64 + Gear^.Frame) mod 8);
-               vgtStraightShot: begin 
+               vgtStraightShot: begin
                                 if Gear^.dX < 0 then
                                     i:= -1
                                 else
@@ -264,9 +264,9 @@
                                     DrawTextureCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex);
                                 end;
                vgtSmallDamageTag: DrawTextureCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex);
-               vgtHealthTag: if Gear^.Tex <> nil then 
+               vgtHealthTag: if Gear^.Tex <> nil then
                                begin
-                               if Gear^.Frame = 0 then 
+                               if Gear^.Frame = 0 then
                                    DrawTextureCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex)
                                else
                                    begin
@@ -274,11 +274,11 @@
                                    if Gear^.Angle = 0 then
                                        DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex)
                                    else
-                                       DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex, Gear^.Angle); 
+                                       DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex, Gear^.Angle);
                                    SetScale(zoom)
                                    end
                                end;
-               vgtStraightShot: begin 
+               vgtStraightShot: begin
                                 if Gear^.dX < 0 then
                                     i:= -1
                                 else
--- a/hedgewars/uVisualGearsHandlers.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uVisualGearsHandlers.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -24,15 +24,15 @@
  * => The usage of safe functions or data types (e.g. GetRandom() or hwFloat)
  * is usually not necessary and therefore undesirable.
  *)
- 
-{$INCLUDE "options.inc"} 
- 
+
+{$INCLUDE "options.inc"}
+
 unit uVisualGearsHandlers;
 
 interface
 uses uTypes;
 
-var doStepHandlers: array[TVisualGearType] of TVGearStepProcedure;
+var doStepVGHandlers: array[TVisualGearType] of TVGearStepProcedure;
 
 procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
 procedure doStepBeeTrace(Gear: PVisualGear; Steps: Longword);
@@ -112,8 +112,8 @@
     else
         if Angle < - 360 then
             Angle:= Angle + 360;
-    
-  
+
+
     if (round(X) >= cLeftScreenBorder)
     and (round(X) <= cRightScreenBorder)
     and (round(Y) - 75 <= LAND_HEIGHT)
@@ -249,7 +249,9 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepLineTrail(Gear: PVisualGear; Steps: Longword);
 begin
+{$IFNDEF PAS2C}
 Steps := Steps;
+{$ENDIF}
 if Gear^.Timer <= Steps then
     DeleteVisualGear(Gear)
 else
@@ -528,7 +530,9 @@
     b: boolean;
     t, h: LongInt;
 begin
+{$IFNDEF PAS2C}
 Steps:= Steps; // avoid compiler hint
+{$ENDIF}
 
 for t:= 0 to Pred(TeamsCount) do
     with thexchar[t] do
@@ -602,7 +606,10 @@
 
 procedure doStepSpeechBubble(Gear: PVisualGear; Steps: Longword);
 begin
+
+{$IFNDEF PAS2C}
 Steps:= Steps; // avoid compiler hint
+{$ENDIF}
 
 with Gear^.Hedgehog^ do
     if SpeechGear <> nil then
@@ -708,10 +715,10 @@
 begin
 gX:= round(Gear^.X);
 gY:= round(Gear^.Y);
-for i:= 0 to 31 do 
+for i:= 0 to 31 do
     begin
     vg:= AddVisualGear(gX, gY, vgtFire);
-    if vg <> nil then 
+    if vg <> nil then
         begin
         vg^.State:= gstTmpFlag;
         inc(vg^.FrameTicks, vg^.FrameTicks)
@@ -752,10 +759,10 @@
 gX:= round(Gear^.X);
 gY:= round(Gear^.Y);
 AddVisualGear(gX, gY, vgtSmokeRing);
-for i:= 0 to 46 do 
+for i:= 0 to 46 do
     begin
     vg:= AddVisualGear(gX, gY, vgtFire);
-    if vg <> nil then 
+    if vg <> nil then
         begin
         vg^.State:= gstTmpFlag;
         inc(vg^.FrameTicks, vg^.FrameTicks)
@@ -768,9 +775,12 @@
 Gear^.doStep:= @doStepBigExplosionWork;
 if Steps > 1 then
     Gear^.doStep(Gear, Steps-1);
+
+{$IFNDEF PAS2C}
 with mobileRecord do
     if (performRumble <> nil) and (not fastUntilLag) then
         performRumble(kSystemSoundID_Vibrate);
+{$ENDIF}
 end;
 
 procedure doStepChunk(Gear: PVisualGear; Steps: Longword);
@@ -832,7 +842,7 @@
 procedure doStepSmoothWindBar(Gear: PVisualGear; Steps: Longword);
 begin
 inc(Gear^.Timer, Steps);
-    
+
 while Gear^.Timer >= 10 do
     begin
     dec(Gear^.Timer, 10);
@@ -851,8 +861,8 @@
     cWindspeedf := cWindspeedf + Gear^.Angle*Steps;
     if cWindspeedf > Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
     end;
-        
-if (WindBarWidth = Gear^.Tag) and (cWindspeedf = Gear^.dAngle)  then 
+
+if (WindBarWidth = Gear^.Tag) and (cWindspeedf = Gear^.dAngle)  then
     DeleteVisualGear(Gear)
 end;
 ////////////////////////////////////////////////////////////////////////////////
@@ -866,7 +876,7 @@
 else
     begin
     dec(Gear^.FrameTicks, Steps);
-    if (Gear^.FrameTicks < 501) and (Gear^.FrameTicks mod 5 = 0) then 
+    if (Gear^.FrameTicks < 501) and (Gear^.FrameTicks mod 5 = 0) then
         Gear^.Tint:= (Gear^.Tint and $FFFFFF00) or (((Gear^.Tint and $000000FF) * Gear^.FrameTicks) div 500)
     end
 end;
@@ -911,7 +921,7 @@
 
 procedure initModule;
 begin
-    doStepHandlers:= handlers
+    doStepVGHandlers:= handlers
 end;
 
 end.
--- a/hedgewars/uVisualGearsList.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uVisualGearsList.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -29,7 +29,7 @@
 procedure DeleteVisualGear(Gear: PVisualGear);
 function  VisualGearByUID(uid : Longword) : PVisualGear;
 
-const 
+const
     cExplFrameTicks = 110;
 
 var VGCounter: LongWord;
@@ -75,7 +75,7 @@
     vgtEvilTrace,
     vgtNote,
     vgtSmoothWindBar])) then
-    
+
         exit;
 
 inc(VGCounter);
@@ -84,7 +84,7 @@
 gear^.X:= real(X);
 gear^.Y:= real(Y);
 gear^.Kind := Kind;
-gear^.doStep:= doStepHandlers[Kind];
+gear^.doStep:= doStepVGHandlers[Kind];
 gear^.State:= 0;
 gear^.Tint:= $FFFFFFFF;
 gear^.uid:= VGCounter;
@@ -289,7 +289,7 @@
                 if random(2) = 0 then
                     dx := -dx;
                 end;
-      vgtNote: 
+      vgtNote:
                 begin
                 dx:= 0.005 * (random(15) + 10);
                 dy:= -0.001 * (random(40) + 20);
@@ -306,7 +306,7 @@
                 Frame:= 7;
                 Angle:= 0;
                 end;
-vgtSmoothWindBar: 
+vgtSmoothWindBar:
                 begin
                 Angle:= hwFloat2Float(cMaxWindSpeed)*2 / 1440; // seems rate below is supposed to change wind bar at 1px per 10ms. Max time, 1440ms. This tries to match the rate of change
                 Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed);
@@ -332,7 +332,7 @@
 case Gear^.Kind of
     vgtFlake: if cFlattenFlakes then
         gear^.Layer:= 0
-              else if random(3) = 0 then 
+              else if random(3) = 0 then
                   begin
                   gear^.Scale:= 0.5;
                   gear^.Layer:= 0   // 33% - far back
--- a/hedgewars/uWorld.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/hedgewars/uWorld.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -64,6 +64,9 @@
 {$IFDEF USE_VIDEO_RECORDING}
     , uVideoRec
 {$ENDIF}
+{$IFDEF GL2}
+    , uMatrix
+{$ENDIF}
     ;
 
 var cWaveWidth, cWaveHeight: LongInt;
@@ -444,14 +447,14 @@
     AmmoRect.w:= (BORDERSIZE*2) + (SlotsNumX * AMSlotSize) + (SlotsNumX-1);
     AmmoRect.h:= (BORDERSIZE*2) + (SlotsNumY * AMSlotSize) + (SlotsNumY-1);
     amSurface := SDL_CreateRGBSurface(SDL_SWSURFACE, AmmoRect.w, AmmoRect.h, 32, RMask, GMask, BMask, AMask);
-    
+
     AMRect.x:= BORDERSIZE;
     AMRect.y:= BORDERSIZE;
     AMRect.w:= AmmoRect.w - (BORDERSIZE*2);
     AMRect.h:= AmmoRect.h - (BORDERSIZE*2);
 
     SDL_FillRect(amSurface, @AMRect, SDL_MapRGB(amSurface^.format, 0,0,0));
-    
+
     x:= AMRect.x;
     y:= AMRect.y;
     for i:= 0 to cMaxSlotIndex do
@@ -485,25 +488,25 @@
                     AMFrame:= LongInt(Ammo^[i,t].AmmoType) - 1;
                     if STurns >= 0 then //weapon not usable yet, draw grayed out with turns remaining
                         begin
-                        DrawSpriteFrame2Surf(sprAMAmmosBW, amSurface, x + AMSlotPadding, 
+                        DrawSpriteFrame2Surf(sprAMAmmosBW, amSurface, x + AMSlotPadding,
                                                                  y + AMSlotPadding, AMFrame);
                         if STurns < 100 then
-                            DrawSpriteFrame2Surf(sprTurnsLeft, amSurface, 
-                                x + AMSlotSize-16, 
+                            DrawSpriteFrame2Surf(sprTurnsLeft, amSurface,
+                                x + AMSlotSize-16,
                                 y + AMSlotSize + 1 - 16, STurns);
                         end
                     else //draw colored version
                         begin
-                        DrawSpriteFrame2Surf(sprAMAmmos, amSurface, x + AMSlotPadding, 
+                        DrawSpriteFrame2Surf(sprAMAmmos, amSurface, x + AMSlotPadding,
                                                                y + AMSlotPadding, AMFrame);
                         end;
 {$IFDEF USE_LANDSCAPE_AMMOMENU}
-	    inc(y, AMSlotSize + 1); //the plus one is for the border
+        inc(y, AMSlotSize + 1); //the plus one is for the border
 {$ELSE}
-	    inc(x, AMSlotSize + 1);
+        inc(x, AMSlotSize + 1);
 {$ENDIF}
-	    end;
-	end;
+        end;
+    end;
 {$IFDEF USE_LANDSCAPE_AMMOMENU}
     inc(x, AMSlotSize + 1);
 {$ELSE}
@@ -512,7 +515,7 @@
     end;
 
 for i:= 1 to SlotsNumX -1 do
-DrawLine2Surf(amSurface, i * (AMSlotSize+1)+1, BORDERSIZE, i * (AMSlotSize+1)+1, AMRect.h + BORDERSIZE - AMSlotSize - 2,160,160,160);            
+DrawLine2Surf(amSurface, i * (AMSlotSize+1)+1, BORDERSIZE, i * (AMSlotSize+1)+1, AMRect.h + BORDERSIZE - AMSlotSize - 2,160,160,160);
 for i:= 1 to SlotsNumY -1 do
 DrawLine2Surf(amSurface, BORDERSIZE, i * (AMSlotSize+1)+1, AMRect.w + BORDERSIZE, i * (AMSlotSize+1)+1,160,160,160);
 
@@ -557,8 +560,8 @@
     exit
     end;
 
-//Init the menu 
-if(AmmoMenuInvalidated) then 
+//Init the menu
+if(AmmoMenuInvalidated) then
     begin
     AmmoMenuInvalidated:= false;
     FreeTexture(AmmoMenuTex);
@@ -614,7 +617,7 @@
             begin
             AMShiftX:= Round(AMShiftTargetX * (1 - AMAnimState));
             AMShiftY:= Round(AMShiftTargetY * (1 - AMAnimState));
-            if (AMAnimType and AMTypeMaskAlpha) <> 0 then 
+            if (AMAnimType and AMTypeMaskAlpha) <> 0 then
                 Tint($FF, $ff, $ff, Round($ff * AMAnimState));
             end
         else
@@ -639,10 +642,10 @@
             begin
             AMShiftX:= Round(AMShiftTargetX * AMAnimState);
             AMShiftY:= Round(AMShiftTargetY * AMAnimState);
-            if (AMAnimType and AMTypeMaskAlpha) <> 0 then 
+            if (AMAnimType and AMTypeMaskAlpha) <> 0 then
                 Tint($FF, $ff, $ff, Round($ff * (1-AMAnimState)));
             end
-         else 
+         else
             begin
             AMShiftX:= AMShiftTargetX;
             AMShiftY:= AMShiftTargetY;
@@ -651,10 +654,10 @@
             AMState:= AMHidden;
             end;
     end;
-    
+
 DrawTexture(AmmoRect.x + AMShiftX, AmmoRect.y + AMShiftY, AmmoMenuTex);
 
-if ((AMState = AMHiding) or (AMState = AMShowingUp)) and ((AMAnimType and AMTypeMaskAlpha) <> 0 )then 
+if ((AMState = AMHiding) or (AMState = AMShowingUp)) and ((AMAnimType and AMTypeMaskAlpha) <> 0 )then
     untint;
 
 Pos:= -1;
@@ -675,15 +678,15 @@
                     begin
                     if (CursorPoint.Y <= (cScreenHeight - AmmoRect.y) - ( g    * (AMSlotSize+1))) and
                        (CursorPoint.Y >  (cScreenHeight - AmmoRect.y) - ((g+1) * (AMSlotSize+1))) and
-                       (CursorPoint.X >  AmmoRect.x                   + ( c    * (AMSlotSize+1))) and 
+                       (CursorPoint.X >  AmmoRect.x                   + ( c    * (AMSlotSize+1))) and
                        (CursorPoint.X <= AmmoRect.x                   + ((c+1) * (AMSlotSize+1))) then
                         begin
                         Slot:= i;
                         Pos:= t;
                         STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
                         if (STurns < 0) and (AMShiftX = 0) and (AMShiftY = 0) then
-                            DrawSprite(sprAMSlot, 
-                                       AmmoRect.x + BORDERSIZE + (c * (AMSlotSize+1)) + AMSlotPadding, 
+                            DrawSprite(sprAMSlot,
+                                       AmmoRect.x + BORDERSIZE + (c * (AMSlotSize+1)) + AMSlotPadding,
                                        AmmoRect.y + BORDERSIZE + (g  * (AMSlotSize+1)) + AMSlotPadding -1, 0);
                         end;
                         inc(g);
@@ -705,15 +708,15 @@
                     begin
                     if (CursorPoint.Y <= (cScreenHeight - AmmoRect.y) - ( c    * (AMSlotSize+1))) and
                        (CursorPoint.Y >  (cScreenHeight - AmmoRect.y) - ((c+1) * (AMSlotSize+1))) and
-                       (CursorPoint.X >  AmmoRect.x                   + ( g    * (AMSlotSize+1))) and 
+                       (CursorPoint.X >  AmmoRect.x                   + ( g    * (AMSlotSize+1))) and
                        (CursorPoint.X <= AmmoRect.x                   + ((g+1) * (AMSlotSize+1))) then
                         begin
                         Slot:= i;
                         Pos:= t;
                         STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
                         if (STurns < 0) and (AMShiftX = 0) and (AMShiftY = 0) then
-                            DrawSprite(sprAMSlot, 
-                                       AmmoRect.x + BORDERSIZE + (g * (AMSlotSize+1)) + AMSlotPadding, 
+                            DrawSprite(sprAMSlot,
+                                       AmmoRect.x + BORDERSIZE + (g * (AMSlotSize+1)) + AMSlotPadding,
                                        AmmoRect.y + BORDERSIZE + (c  * (AMSlotSize+1)) + AMSlotPadding -1, 0);
                         end;
                         inc(g);
@@ -748,7 +751,7 @@
 {$IFDEF USE_TOUCH_INTERFACE}//show the aiming buttons + animation
                 if (Ammo^[Slot, Pos].Propz and ammoprop_NeedUpDown) <> 0 then
                     begin
-                    if not(arrowUp.show) then
+                    if (not arrowUp.show) then
                         begin
                         animateWidget(@arrowUp, true, true);
                         animateWidget(@arrowDown, true, true);
@@ -771,7 +774,7 @@
 
     if (WeaponTooltipTex <> nil) and (AMShiftX = 0) and (AMShiftY = 0) then
 {$IFDEF USE_LANDSCAPE_AMMOMENU}
-        if not isPhone() then
+        if (not isPhone()) then
             ShowWeaponTooltip(-WeaponTooltipTex^.w div 2, AmmoRect.y - WeaponTooltipTex^.h - AMSlotSize);
 {$ELSE}
         ShowWeaponTooltip(AmmoRect.x - WeaponTooltipTex^.w - 3, Min(AmmoRect.y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
@@ -785,9 +788,9 @@
 end;
 
 procedure DrawWater(Alpha: byte; OffsetY: LongInt);
-var VertexBuffer: array [0..3] of TVertex2f;
-    r: TSDL_Rect;
-    lw, lh: GLfloat;
+var VertexBuffer : array [0..3] of TVertex2f;
+    r        : TSDL_Rect;
+    lw, lh   : GLfloat;
 begin
 if SuddenDeathDmg then
     begin
@@ -824,6 +827,7 @@
         VertexBuffer[3].X:= -lw;
         VertexBuffer[3].Y:= lh;
 
+{$IFNDEF GL2}
         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
         glEnableClientState(GL_COLOR_ARRAY);
         if SuddenDeathDmg then
@@ -837,7 +841,27 @@
 
         glDisableClientState(GL_COLOR_ARRAY);
         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-        glColor4ub($FF, $FF, $FF, $FF); // must not be Tint() as color array seems to stay active and color reset is required
+
+{$ELSE}
+        UpdateModelviewProjection;
+
+        BeginWater;
+        if SuddenDeathDmg then
+            SetColorPointer(@SDWaterColorArray[0], 4)
+        else
+            SetColorPointer(@WaterColorArray[0], 4);
+
+        SetVertexPointer(@VertexBuffer[0], 4);
+
+        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+        EndWater;
+{$ENDIF}
+
+{$IFNDEF GL2}
+        // must not be Tint() as color array seems to stay active and color reset is required
+        glColor4ub($FF, $FF, $FF, $FF);
+{$ENDIF}
         glEnable(GL_TEXTURE_2D);
     end;
 end;
@@ -892,8 +916,13 @@
 TextureBuffer[3].Y:= TextureBuffer[2].Y;
 
 
-glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
-glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
+SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
+SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
+
+{$IFDEF GL2}
+UpdateModelviewProjection;
+{$ENDIF}
+
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
 untint;
@@ -1105,12 +1134,19 @@
     else if rm = rmLeftEye then
         d:= -d;
     stereoDepth:= stereoDepth + d;
+
+{$IFDEF GL2}
+    hglMatrixMode(MATRIX_PROJECTION);
+    hglTranslatef(d, 0, 0);
+    hglMatrixMode(MATRIX_MODELVIEW);
+{$ELSE}
     glMatrixMode(GL_PROJECTION);
     glTranslatef(d, 0, 0);
     glMatrixMode(GL_MODELVIEW);
 {$ENDIF}
+{$ENDIF}
 end;
- 
+
 procedure ResetDepth(rm: TRenderMode);
 begin
 {$IFNDEF USE_S3D_RENDERING}
@@ -1119,14 +1155,19 @@
 {$ELSE}
     if rm = rmDefault then
         exit;
+{$IFDEF GL2}
+    hglMatrixMode(MATRIX_PROJECTION);
+    hglTranslatef(-stereoDepth, 0, 0);
+    hglMatrixMode(MATRIX_MODELVIEW);
+{$ELSE}
     glMatrixMode(GL_PROJECTION);
     glTranslatef(-stereoDepth, 0, 0);
     glMatrixMode(GL_MODELVIEW);
-    stereoDepth:= 0;
+{$ENDIF}
+    cStereoDepth:= 0;
 {$ENDIF}
 end;
 
-
 procedure RenderWorldEdge(Lag: Longword);
 var
     VertexBuffer: array [0..3] of TVertex2f;
@@ -1189,7 +1230,7 @@
     glColor4ub($FF, $FF, $FF, $FF); // must not be Tint() as color array seems to stay active and color reset is required
     glEnable(GL_TEXTURE_2D);
 
-    // I'd still like to have things happen to the border when a wrap or bounce just occurred, based on a timer 
+    // I'd still like to have things happen to the border when a wrap or bounce just occurred, based on a timer
     if WorldEdge = weBounce then
         begin
         // could maybe alternate order of these on a bounce, or maybe drop the outer ones.
@@ -1291,7 +1332,7 @@
             for i:= 0 to cMaxHHIndex do
                 begin
                 inc(h, Hedgehogs[i].HealthBarHealth);
-                if (h < TeamHealthBarHealth) and (Hedgehogs[i].HealthBarHealth > 0) then 
+                if (h < TeamHealthBarHealth) and (Hedgehogs[i].HealthBarHealth > 0) then
                     DrawTexture(15 + h * TeamHealthBarWidth div TeamHealthBarHealth, cScreenHeight + DrawHealthY + smallScreenOffset + 1, SpritesData[sprSlider].Texture);
                 end;
 
@@ -1374,7 +1415,7 @@
 if (cReducedQuality and rq2DWater) = 0 then
     begin
         // Waves
-        DrawWater(255, SkyOffset); 
+        DrawWater(255, SkyOffset);
         ChangeDepth(RM, -cStereo_Water_distant);
         DrawWaves( 1,  0 - WorldDx div 32, - cWaveHeight + offsetY div 35, 64);
         ChangeDepth(RM, -cStereo_Water_distant);
@@ -1393,6 +1434,30 @@
 
     DrawWater(255, 0);
 
+(*
+// Attack bar
+    if CurrentTeam <> nil then
+        case AttackBar of
+        //1: begin
+        //r:= StuffPoz[sPowerBar];
+        //{$WARNINGS OFF}
+        //r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
+        //{$WARNINGS ON}
+        //DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
+        //end;
+        2: with CurrentHedgehog^ do
+                begin
+                tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
+                tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
+                for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do
+                    DrawSprite(sprPower,
+                            hwRound(Gear^.X) + GetLaunchX(CurAmmoType, hwSign(Gear^.dX), Gear^.Angle) + LongInt(round(WorldDx + tdx * (24 + i * 2))) - 16,
+                            hwRound(Gear^.Y) + GetLaunchY(CurAmmoType, Gear^.Angle) + LongInt(round(WorldDy + tdy * (24 + i * 2))) - 16,
+                            i)
+                end
+        end;
+*)
+
 DrawVisualGears(1);
 DrawGears;
 DrawVisualGears(6);
@@ -1471,7 +1536,7 @@
             i:= Succ(Pred(ReadyTimeLeft) div 1000)
         else
             i:= Succ(Pred(TurnTimeLeft) div 1000);
-       
+
         if i>99 then
             t:= 112
         else if i>9 then
@@ -1556,14 +1621,14 @@
         AMAnimStartTime:= RealTicks - (AMAnimDuration - (RealTicks - AMAnimStartTime));
     AMState:= AMShowingUp;
     end;
-if not(bShowAmmoMenu) and ((AMstate = AMShowing) or (AMState = AMShowingUp)) then
+if (not bShowAmmoMenu) and ((AMstate = AMShowing) or (AMState = AMShowingUp)) then
     begin
     if (AMState = AMShowing) then
         AMAnimStartTime:= RealTicks
     else
         AMAnimStartTime:= RealTicks - (AMAnimDuration - (RealTicks - AMAnimStartTime));
     AMState:= AMHiding;
-    end; 
+    end;
 
 if bShowAmmoMenu or (AMState = AMHiding) then
     ShowAmmoMenu;
@@ -1575,6 +1640,7 @@
 // Chat
 DrawChat;
 
+
 // various captions
 if fastUntilLag then
     DrawTextureCentered(0, (cScreenHeight shr 1), SyncTexture);
@@ -1618,8 +1684,8 @@
         if t < 10 then
             s:= '0' + s;
         s:= inttostr(i div 60) + ':' + s;
-   
-    
+
+
         tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
         tmpSurface:= doSurfaceConversion(tmpSurface);
         FreeTexture(timeTexture);
@@ -1655,7 +1721,7 @@
 
 if ScreenFade <> sfNone then
     begin
-    if not isFirstFrame then
+    if (not isFirstFrame) then
         case ScreenFade of
             sfToBlack, sfToWhite:     if ScreenFadeValue + Lag * ScreenFadeSpeed < sfMax then
                                           inc(ScreenFadeValue, Lag * ScreenFadeSpeed)
@@ -1685,7 +1751,7 @@
         glDisable(GL_TEXTURE_2D);
 
         glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
-        glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+        glDrawArrays(GL_TRIANGLE_FAN, 0, High(VertexBuffer) - Low(VertexBuffer) + 1);
 
         glEnable(GL_TEXTURE_2D);
         untint;
@@ -1710,7 +1776,7 @@
     DrawTexture( -(cScreenWidth shr 1) + 50, 20, recTexture);
 
     // draw red circle
-    glDisable(GL_TEXTURE_2D); 
+    glDisable(GL_TEXTURE_2D);
     Tint($FF, $00, $00, Byte(Round(127*(1 + sin(SDL_GetTicks()*0.007)))));
     glBegin(GL_POLYGON);
     for i:= 0 to 20 do
@@ -1749,7 +1815,7 @@
 // Cursor
 if isCursorVisible then
     begin
-    if not bShowAmmoMenu then
+    if (not bShowAmmoMenu) then
         begin
         if not CurrentTeam^.ExtDriven then TargetCursorPoint:= CursorPoint;
         with CurrentHedgehog^ do
@@ -1765,7 +1831,8 @@
         DrawSprite(sprArrow, TargetCursorPoint.X, cScreenHeight - TargetCursorPoint.Y, (RealTicks shr 6) mod 8)
         end
     end;
-isFirstFrame:= false;
+
+isFirstFrame:= false
 end;
 
 var PrevSentPointTime: LongWord = 0;
@@ -1780,7 +1847,7 @@
 {$ENDIF}
 z:= round(200/zoom);
 inbtwnTrgtAttks := (CurrentHedgehog <> nil) and ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) <> 0) and ((GameFlags and gfInfAttack) <> 0);
-if autoCameraOn and not PlacingHogs and (FollowGear <> nil) and (not isCursorVisible) and (not bShowAmmoMenu) and (not fastUntilLag) and not inbtwnTrgtAttks then
+if autoCameraOn and (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not bShowAmmoMenu) and (not fastUntilLag) and (not inbtwnTrgtAttks) then
     if ((abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y)) > 4) then
         begin
         FollowGear:= nil;
@@ -1821,7 +1888,7 @@
     {$ENDIF}
 
 {$ENDIF}
-    if CursorPoint.X < AmmoRect.x + amNumOffsetX + 3 then//check left 
+    if CursorPoint.X < AmmoRect.x + amNumOffsetX + 3 then//check left
         CursorPoint.X:= AmmoRect.x + amNumOffsetX + 3;
     if CursorPoint.X > AmmoRect.x + AmmoRect.w - 3 then//check right
         CursorPoint.X:= AmmoRect.x + AmmoRect.w - 3;
@@ -1950,10 +2017,10 @@
 
 {$IFDEF USE_VIDEO_RECORDING}
 // do not change volume during prerecording as it will affect sound in video file
-if not flagPrerecording then
+if (not flagPrerecording) then
 {$ENDIF}
     begin
-    if not cHasFocus then DampenAudio()
+    if (not cHasFocus) then DampenAudio()
     else UndampenAudio();
     end;
 end;
@@ -1969,7 +2036,7 @@
         begin
         utilityWidget.sprite:= sprTimerButton;
         animateWidget(@utilityWidget, true, true);
-        end 
+        end
     else if (Ammoz[ammoType].Ammo.Propz and ammoprop_NeedTarget) <> 0 then
         begin
         utilityWidget.sprite:= sprTargetButton;
@@ -1993,7 +2060,7 @@
     begin
     show:= showWidget;
     if fade then fadeAnimStart:= RealTicks;
-    
+
     with moveAnim do
         begin
         animate:= true;
--- a/misc/OfficialChallenges/racer_#1.hwmap	Wed Jan 22 01:11:13 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-AAAAw3icJc6xDcIwEAXQz+niWBhkiggxAS0djZs0kYVASFmBBWiYw0xAQ5sOV7SZgBpKRvAC+Ezz9PWlfzrd8BHmyzvwiTvoFe7QTf0AAoaIUO9hrwUMpQN56iN5tcT8U6C+dKADuzi7scsHeJuEnCaXJOSkXklAtWaXBBjDbRJKF/7dgtsgyPYcBNm+gwBtaTNqqzyqJ3fj1Oeff4W8JYk=
\ No newline at end of file
--- a/misc/liblua/lapi.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lapi.c	Tue Jan 21 22:53:15 2014 +0100
@@ -38,9 +38,9 @@
 
 
 
-#define api_checknelems(L, n)	api_check(L, (n) <= (L->top - L->base))
+#define api_checknelems(L, n)   api_check(L, (n) <= (L->top - L->base))
 
-#define api_checkvalidindex(L, i)	api_check(L, (i) != luaO_nilobject)
+#define api_checkvalidindex(L, i)   api_check(L, (i) != luaO_nilobject)
 
 #define api_incr_top(L)   {api_check(L, L->top < L->ci->top); L->top++;}
 
--- a/misc/liblua/lauxlib.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lauxlib.c	Tue Jan 21 22:53:15 2014 +0100
@@ -25,12 +25,12 @@
 #include "lauxlib.h"
 
 
-#define FREELIST_REF	0	/* free list of references */
+#define FREELIST_REF    0   /* free list of references */
 
 
 /* convert a stack index to positive */
-#define abs_index(L, i)		((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
-					lua_gettop(L) + (i) + 1)
+#define abs_index(L, i)     ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
+                    lua_gettop(L) + (i) + 1)
 
 
 /*
@@ -389,10 +389,10 @@
 */
 
 
-#define bufflen(B)	((B)->p - (B)->buffer)
-#define bufffree(B)	((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
+#define bufflen(B)  ((B)->p - (B)->buffer)
+#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
 
-#define LIMIT	(LUA_MINSTACK/2)
+#define LIMIT   (LUA_MINSTACK/2)
 
 
 static int emptybuffer (luaL_Buffer *B) {
@@ -574,7 +574,8 @@
     lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
     if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
     /* skip eventual `#!...' */
-   while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
+   while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0])
+       /* do nothing */ ;
     lf.extraline = 0;
   }
   ungetc(c, lf.f);
--- a/misc/liblua/lauxlib.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lauxlib.h	Tue Jan 21 22:53:15 2014 +0100
@@ -24,7 +24,7 @@
 #endif
 
 #if defined(LUA_COMPAT_OPENLIB)
-#define luaI_openlib	luaL_openlib
+#define luaI_openlib    luaL_openlib
 #endif
 
 
@@ -97,26 +97,26 @@
 ** ===============================================================
 */
 
-#define luaL_argcheck(L, cond,numarg,extramsg)	\
-		((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
-#define luaL_checkstring(L,n)	(luaL_checklstring(L, (n), NULL))
-#define luaL_optstring(L,n,d)	(luaL_optlstring(L, (n), (d), NULL))
-#define luaL_checkint(L,n)	((int)luaL_checkinteger(L, (n)))
-#define luaL_optint(L,n,d)	((int)luaL_optinteger(L, (n), (d)))
-#define luaL_checklong(L,n)	((long)luaL_checkinteger(L, (n)))
-#define luaL_optlong(L,n,d)	((long)luaL_optinteger(L, (n), (d)))
+#define luaL_argcheck(L, cond,numarg,extramsg)  \
+        ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
+#define luaL_checkstring(L,n)   (luaL_checklstring(L, (n), NULL))
+#define luaL_optstring(L,n,d)   (luaL_optlstring(L, (n), (d), NULL))
+#define luaL_checkint(L,n)  ((int)luaL_checkinteger(L, (n)))
+#define luaL_optint(L,n,d)  ((int)luaL_optinteger(L, (n), (d)))
+#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
+#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
 
-#define luaL_typename(L,i)	lua_typename(L, lua_type(L,(i)))
+#define luaL_typename(L,i)  lua_typename(L, lua_type(L,(i)))
 
 #define luaL_dofile(L, fn) \
-	(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
+    (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
 
 #define luaL_dostring(L, s) \
-	(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
+    (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
 
-#define luaL_getmetatable(L,n)	(lua_getfield(L, LUA_REGISTRYINDEX, (n)))
+#define luaL_getmetatable(L,n)  (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
 
-#define luaL_opt(L,f,n,d)	(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
+#define luaL_opt(L,f,n,d)   (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
 
 /*
 ** {======================================================
@@ -127,7 +127,7 @@
 
 
 typedef struct luaL_Buffer {
-  char *p;			/* current position in buffer */
+  char *p;          /* current position in buffer */
   int lvl;  /* number of strings in the stack (level) */
   lua_State *L;
   char buffer[LUAL_BUFFERSIZE];
@@ -138,9 +138,9 @@
    (*(B)->p++ = (char)(c)))
 
 /* compatibility only */
-#define luaL_putchar(B,c)	luaL_addchar(B,c)
+#define luaL_putchar(B,c)   luaL_addchar(B,c)
 
-#define luaL_addsize(B,n)	((B)->p += (n))
+#define luaL_addsize(B,n)   ((B)->p += (n))
 
 LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
 LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
@@ -167,7 +167,7 @@
 #define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
 
 
-#define luaL_reg	luaL_Reg
+#define luaL_reg    luaL_Reg
 
 #endif
 
--- a/misc/liblua/lbaselib.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lbaselib.c	Tue Jan 21 22:53:15 2014 +0100
@@ -479,10 +479,10 @@
 ** =======================================================
 */
 
-#define CO_RUN	0	/* running */
-#define CO_SUS	1	/* suspended */
-#define CO_NOR	2	/* 'normal' (it resumed another coroutine) */
-#define CO_DEAD	3
+#define CO_RUN  0   /* running */
+#define CO_SUS  1   /* suspended */
+#define CO_NOR  2   /* 'normal' (it resumed another coroutine) */
+#define CO_DEAD 3
 
 static const char *const statnames[] =
     {"running", "suspended", "normal", "dead"};
--- a/misc/liblua/lcode.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lcode.c	Tue Jan 21 22:53:15 2014 +0100
@@ -24,7 +24,7 @@
 #include "ltable.h"
 
 
-#define hasjumps(e)	((e)->t != (e)->f)
+#define hasjumps(e) ((e)->t != (e)->f)
 
 
 static int isnumeral(expdesc *e) {
--- a/misc/liblua/lcode.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lcode.h	Tue Jan 21 22:53:15 2014 +0100
@@ -36,11 +36,11 @@
 typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
 
 
-#define getcode(fs,e)	((fs)->f->code[(e)->u.s.info])
+#define getcode(fs,e)   ((fs)->f->code[(e)->u.s.info])
 
-#define luaK_codeAsBx(fs,o,A,sBx)	luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
+#define luaK_codeAsBx(fs,o,A,sBx)   luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
 
-#define luaK_setmultret(fs,e)	luaK_setreturns(fs, e, LUA_MULTRET)
+#define luaK_setmultret(fs,e)   luaK_setreturns(fs, e, LUA_MULTRET)
 
 LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
 LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
--- a/misc/liblua/ldblib.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ldblib.c	Tue Jan 21 22:53:15 2014 +0100
@@ -315,8 +315,8 @@
 }
 
 
-#define LEVELS1	12	/* size of the first part of the stack */
-#define LEVELS2	10	/* size of the second part of the stack */
+#define LEVELS1 12  /* size of the first part of the stack */
+#define LEVELS2 10  /* size of the second part of the stack */
 
 static int db_errorfb (lua_State *L) {
   int level;
--- a/misc/liblua/ldebug.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ldebug.c	Tue Jan 21 22:53:15 2014 +0100
@@ -265,11 +265,11 @@
 ** =======================================================
 */
 
-#define check(x)		if (!(x)) return 0;
+#define check(x)        if (!(x)) return 0;
 
-#define checkjump(pt,pc)	check(0 <= pc && pc < pt->sizecode)
+#define checkjump(pt,pc)    check(0 <= pc && pc < pt->sizecode)
 
-#define checkreg(pt,reg)	check((reg) < (pt)->maxstacksize)
+#define checkreg(pt,reg)    check((reg) < (pt)->maxstacksize)
 
 
 
@@ -285,7 +285,7 @@
 }
 
 
-#define checkopenop(pt,pc)	luaG_checkopenop((pt)->code[(pc)+1])
+#define checkopenop(pt,pc)  luaG_checkopenop((pt)->code[(pc)+1])
 
 int luaG_checkopenop (Instruction i) {
   switch (GET_OPCODE(i)) {
--- a/misc/liblua/ldebug.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ldebug.h	Tue Jan 21 22:53:15 2014 +0100
@@ -11,11 +11,11 @@
 #include "lstate.h"
 
 
-#define pcRel(pc, p)	(cast(int, (pc) - (p)->code) - 1)
+#define pcRel(pc, p)    (cast(int, (pc) - (p)->code) - 1)
 
-#define getline(f,pc)	(((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
+#define getline(f,pc)   (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
 
-#define resethookcount(L)	(L->hookcount = L->basehookcount)
+#define resethookcount(L)   (L->hookcount = L->basehookcount)
 
 
 LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
--- a/misc/liblua/ldo.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ldo.h	Tue Jan 21 22:53:15 2014 +0100
@@ -13,7 +13,7 @@
 #include "lzio.h"
 
 
-#define luaD_checkstack(L,n)	\
+#define luaD_checkstack(L,n)    \
   if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \
     luaD_growstack(L, n); \
   else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1));
@@ -21,17 +21,17 @@
 
 #define incr_top(L) {luaD_checkstack(L,1); L->top++;}
 
-#define savestack(L,p)		((char *)(p) - (char *)L->stack)
-#define restorestack(L,n)	((TValue *)((char *)L->stack + (n)))
+#define savestack(L,p)      ((char *)(p) - (char *)L->stack)
+#define restorestack(L,n)   ((TValue *)((char *)L->stack + (n)))
 
-#define saveci(L,p)		((char *)(p) - (char *)L->base_ci)
-#define restoreci(L,n)		((CallInfo *)((char *)L->base_ci + (n)))
+#define saveci(L,p)     ((char *)(p) - (char *)L->base_ci)
+#define restoreci(L,n)      ((CallInfo *)((char *)L->base_ci + (n)))
 
 
 /* results from luaD_precall */
-#define PCRLUA		0	/* initiated a call to a Lua function */
-#define PCRC		1	/* did a call to a C function */
-#define PCRYIELD	2	/* C funtion yielded */
+#define PCRLUA      0   /* initiated a call to a Lua function */
+#define PCRC        1   /* did a call to a C function */
+#define PCRYIELD    2   /* C funtion yielded */
 
 
 /* type of protected functions, to be ran by `runprotected' */
--- a/misc/liblua/ldump.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ldump.c	Tue Jan 21 22:53:15 2014 +0100
@@ -23,8 +23,8 @@
  int status;
 } DumpState;
 
-#define DumpMem(b,n,size,D)	DumpBlock(b,(n)*(size),D)
-#define DumpVar(x,D)	 	DumpMem(&x,1,sizeof(x),D)
+#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
+#define DumpVar(x,D)        DumpMem(&x,1,sizeof(x),D)
 
 static void DumpBlock(const void* b, size_t size, DumpState* D)
 {
@@ -67,13 +67,13 @@
  }
  else
  {
-  size_t size=s->tsv.len+1;		/* include trailing '\0' */
+  size_t size=s->tsv.len+1;     /* include trailing '\0' */
   DumpVar(size,D);
   DumpBlock(getstr(s),size,D);
  }
 }
 
-#define DumpCode(f,D)	 DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
+#define DumpCode(f,D)    DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
 
 static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
 
@@ -88,19 +88,19 @@
   switch (ttype(o))
   {
    case LUA_TNIL:
-	break;
+    break;
    case LUA_TBOOLEAN:
-	DumpChar(bvalue(o),D);
-	break;
+    DumpChar(bvalue(o),D);
+    break;
    case LUA_TNUMBER:
-	DumpNumber(nvalue(o),D);
-	break;
+    DumpNumber(nvalue(o),D);
+    break;
    case LUA_TSTRING:
-	DumpString(rawtsvalue(o),D);
-	break;
+    DumpString(rawtsvalue(o),D);
+    break;
    default:
-	lua_assert(0);			/* cannot happen */
-	break;
+    lua_assert(0);          /* cannot happen */
+    break;
   }
  }
  n=f->sizep;
--- a/misc/liblua/lfunc.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lfunc.h	Tue Jan 21 22:53:15 2014 +0100
@@ -11,10 +11,10 @@
 #include "lobject.h"
 
 
-#define sizeCclosure(n)	(cast(int, sizeof(CClosure)) + \
+#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
                          cast(int, sizeof(TValue)*((n)-1)))
 
-#define sizeLclosure(n)	(cast(int, sizeof(LClosure)) + \
+#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
                          cast(int, sizeof(TValue *)*((n)-1)))
 
 
--- a/misc/liblua/lgc.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lgc.c	Tue Jan 21 22:53:15 2014 +0100
@@ -23,25 +23,25 @@
 #include "ltm.h"
 
 
-#define GCSTEPSIZE	1024u
-#define GCSWEEPMAX	40
-#define GCSWEEPCOST	10
-#define GCFINALIZECOST	100
+#define GCSTEPSIZE  1024u
+#define GCSWEEPMAX  40
+#define GCSWEEPCOST 10
+#define GCFINALIZECOST  100
 
 
-#define maskmarks	cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
+#define maskmarks   cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
 
-#define makewhite(g,x)	\
+#define makewhite(g,x)  \
    ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))
 
-#define white2gray(x)	reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
-#define black2gray(x)	resetbit((x)->gch.marked, BLACKBIT)
+#define white2gray(x)   reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
+#define black2gray(x)   resetbit((x)->gch.marked, BLACKBIT)
 
-#define stringmark(s)	reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)
+#define stringmark(s)   reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)
 
 
-#define isfinalized(u)		testbit((u)->marked, FINALIZEDBIT)
-#define markfinalized(u)	l_setbit((u)->marked, FINALIZEDBIT)
+#define isfinalized(u)      testbit((u)->marked, FINALIZEDBIT)
+#define markfinalized(u)    l_setbit((u)->marked, FINALIZEDBIT)
 
 
 #define KEYWEAK         bitmask(KEYWEAKBIT)
@@ -53,7 +53,7 @@
   if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); }
 
 #define markobject(g,t) { if (iswhite(obj2gco(t))) \
-		reallymarkobject(g, obj2gco(t)); }
+        reallymarkobject(g, obj2gco(t)); }
 
 
 #define setthreshold(g)  (g->GCthreshold = (g->estimate/100) * g->gcpause)
@@ -401,7 +401,7 @@
 
 
 
-#define sweepwholelist(L,p)	sweeplist(L,p,MAX_LUMEM)
+#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM)
 
 
 static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
--- a/misc/liblua/lgc.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lgc.h	Tue Jan 21 22:53:15 2014 +0100
@@ -14,27 +14,27 @@
 /*
 ** Possible states of the Garbage Collector
 */
-#define GCSpause	0
-#define GCSpropagate	1
-#define GCSsweepstring	2
-#define GCSsweep	3
-#define GCSfinalize	4
+#define GCSpause    0
+#define GCSpropagate    1
+#define GCSsweepstring  2
+#define GCSsweep    3
+#define GCSfinalize 4
 
 
 /*
 ** some userful bit tricks
 */
-#define resetbits(x,m)	((x) &= cast(lu_byte, ~(m)))
-#define setbits(x,m)	((x) |= (m))
-#define testbits(x,m)	((x) & (m))
-#define bitmask(b)	(1<<(b))
-#define bit2mask(b1,b2)	(bitmask(b1) | bitmask(b2))
-#define l_setbit(x,b)	setbits(x, bitmask(b))
-#define resetbit(x,b)	resetbits(x, bitmask(b))
-#define testbit(x,b)	testbits(x, bitmask(b))
-#define set2bits(x,b1,b2)	setbits(x, (bit2mask(b1, b2)))
-#define reset2bits(x,b1,b2)	resetbits(x, (bit2mask(b1, b2)))
-#define test2bits(x,b1,b2)	testbits(x, (bit2mask(b1, b2)))
+#define resetbits(x,m)  ((x) &= cast(lu_byte, ~(m)))
+#define setbits(x,m)    ((x) |= (m))
+#define testbits(x,m)   ((x) & (m))
+#define bitmask(b)  (1<<(b))
+#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
+#define l_setbit(x,b)   setbits(x, bitmask(b))
+#define resetbit(x,b)   resetbits(x, bitmask(b))
+#define testbit(x,b)    testbits(x, bitmask(b))
+#define set2bits(x,b1,b2)   setbits(x, (bit2mask(b1, b2)))
+#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2)))
+#define test2bits(x,b1,b2)  testbits(x, (bit2mask(b1, b2)))
 
 
 
@@ -51,47 +51,47 @@
 */
 
 
-#define WHITE0BIT	0
-#define WHITE1BIT	1
-#define BLACKBIT	2
-#define FINALIZEDBIT	3
-#define KEYWEAKBIT	3
-#define VALUEWEAKBIT	4
-#define FIXEDBIT	5
-#define SFIXEDBIT	6
-#define WHITEBITS	bit2mask(WHITE0BIT, WHITE1BIT)
+#define WHITE0BIT   0
+#define WHITE1BIT   1
+#define BLACKBIT    2
+#define FINALIZEDBIT    3
+#define KEYWEAKBIT  3
+#define VALUEWEAKBIT    4
+#define FIXEDBIT    5
+#define SFIXEDBIT   6
+#define WHITEBITS   bit2mask(WHITE0BIT, WHITE1BIT)
 
 
 #define iswhite(x)      test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
 #define isblack(x)      testbit((x)->gch.marked, BLACKBIT)
-#define isgray(x)	(!isblack(x) && !iswhite(x))
+#define isgray(x)   (!isblack(x) && !iswhite(x))
 
-#define otherwhite(g)	(g->currentwhite ^ WHITEBITS)
-#define isdead(g,v)	((v)->gch.marked & otherwhite(g) & WHITEBITS)
+#define otherwhite(g)   (g->currentwhite ^ WHITEBITS)
+#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS)
 
-#define changewhite(x)	((x)->gch.marked ^= WHITEBITS)
-#define gray2black(x)	l_setbit((x)->gch.marked, BLACKBIT)
+#define changewhite(x)  ((x)->gch.marked ^= WHITEBITS)
+#define gray2black(x)   l_setbit((x)->gch.marked, BLACKBIT)
 
-#define valiswhite(x)	(iscollectable(x) && iswhite(gcvalue(x)))
+#define valiswhite(x)   (iscollectable(x) && iswhite(gcvalue(x)))
 
-#define luaC_white(g)	cast(lu_byte, (g)->currentwhite & WHITEBITS)
+#define luaC_white(g)   cast(lu_byte, (g)->currentwhite & WHITEBITS)
 
 
 #define luaC_checkGC(L) { \
   condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
   if (G(L)->totalbytes >= G(L)->GCthreshold) \
-	luaC_step(L); }
+    luaC_step(L); }
 
 
 #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p)))  \
-	luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
+    luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
 
 #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t)))  \
-	luaC_barrierback(L,t); }
+    luaC_barrierback(L,t); }
 
 #define luaC_objbarrier(L,p,o)  \
-	{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
-		luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
+    { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
+        luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
 
 #define luaC_objbarriert(L,t,o)  \
    { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
--- a/misc/liblua/liolib.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/liolib.c	Tue Jan 21 22:53:15 2014 +0100
@@ -20,8 +20,8 @@
 
 
 
-#define IO_INPUT	1
-#define IO_OUTPUT	2
+#define IO_INPUT    1
+#define IO_OUTPUT   2
 
 
 static const char *const fnames[] = {"input", "output"};
@@ -51,7 +51,7 @@
 }
 
 
-#define tofilep(L)	((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
+#define tofilep(L)  ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
 
 
 static int io_type (lua_State *L) {
--- a/misc/liblua/llex.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/llex.c	Tue Jan 21 22:53:15 2014 +0100
@@ -30,7 +30,7 @@
 
 
 
-#define currIsNewline(ls)	(ls->current == '\n' || ls->current == '\r')
+#define currIsNewline(ls)   (ls->current == '\n' || ls->current == '\r')
 
 
 /* ORDER RESERVED */
--- a/misc/liblua/llex.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/llex.h	Tue Jan 21 22:53:15 2014 +0100
@@ -11,10 +11,10 @@
 #include "lzio.h"
 
 
-#define FIRST_RESERVED	257
+#define FIRST_RESERVED  257
 
 /* maximum length of a reserved word */
-#define TOKEN_LEN	(sizeof("function")/sizeof(char))
+#define TOKEN_LEN   (sizeof("function")/sizeof(char))
 
 
 /*
@@ -33,7 +33,7 @@
 };
 
 /* number of reserved words */
-#define NUM_RESERVED	(cast(int, TK_WHILE-FIRST_RESERVED+1))
+#define NUM_RESERVED    (cast(int, TK_WHILE-FIRST_RESERVED+1))
 
 
 /* array with token `names' */
--- a/misc/liblua/llimits.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/llimits.h	Tue Jan 21 22:53:15 2014 +0100
@@ -27,9 +27,9 @@
 typedef unsigned char lu_byte;
 
 
-#define MAX_SIZET	((size_t)(~(size_t)0)-2)
+#define MAX_SIZET   ((size_t)(~(size_t)0)-2)
 
-#define MAX_LUMEM	((lu_mem)(~(lu_mem)0)-2)
+#define MAX_LUMEM   ((lu_mem)(~(lu_mem)0)-2)
 
 
 #define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */
@@ -54,30 +54,30 @@
 /* internal assertions for in-house debugging */
 #ifdef lua_assert
 
-#define check_exp(c,e)		(lua_assert(c), (e))
-#define api_check(l,e)		lua_assert(e)
+#define check_exp(c,e)      (lua_assert(c), (e))
+#define api_check(l,e)      lua_assert(e)
 
 #else
 
-#define lua_assert(c)		((void)0)
-#define check_exp(c,e)		(e)
-#define api_check		luai_apicheck
+#define lua_assert(c)       ((void)0)
+#define check_exp(c,e)      (e)
+#define api_check       luai_apicheck
 
 #endif
 
 
 #ifndef UNUSED
-#define UNUSED(x)	((void)(x))	/* to avoid warnings */
+#define UNUSED(x)   ((void)(x)) /* to avoid warnings */
 #endif
 
 
 #ifndef cast
-#define cast(t, exp)	((t)(exp))
+#define cast(t, exp)    ((t)(exp))
 #endif
 
-#define cast_byte(i)	cast(lu_byte, (i))
-#define cast_num(i)	cast(lua_Number, (i))
-#define cast_int(i)	cast(int, (i))
+#define cast_byte(i)    cast(lu_byte, (i))
+#define cast_num(i) cast(lua_Number, (i))
+#define cast_int(i) cast(int, (i))
 
 
 
@@ -90,19 +90,19 @@
 
 
 /* maximum stack for a Lua function */
-#define MAXSTACK	250
+#define MAXSTACK    250
 
 
 
 /* minimum size for the string table (must be power of 2) */
 #ifndef MINSTRTABSIZE
-#define MINSTRTABSIZE	32
+#define MINSTRTABSIZE   32
 #endif
 
 
 /* minimum size for string buffer */
 #ifndef LUA_MINBUFFER
-#define LUA_MINBUFFER	32
+#define LUA_MINBUFFER   32
 #endif
 
 
@@ -120,9 +120,9 @@
 ** macro to control inclusion of some hard tests on stack reallocation
 */
 #ifndef HARDSTACKTESTS
-#define condhardstacktests(x)	((void)0)
+#define condhardstacktests(x)   ((void)0)
 #else
-#define condhardstacktests(x)	x
+#define condhardstacktests(x)   x
 #endif
 
 #endif
--- a/misc/liblua/lmem.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lmem.c	Tue Jan 21 22:53:15 2014 +0100
@@ -40,7 +40,7 @@
 
 
 
-#define MINSIZEARRAY	4
+#define MINSIZEARRAY    4
 
 
 void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
--- a/misc/liblua/lmem.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lmem.h	Tue Jan 21 22:53:15 2014 +0100
@@ -13,22 +13,22 @@
 #include "llimits.h"
 #include "lua.h"
 
-#define MEMERRMSG	"not enough memory"
+#define MEMERRMSG   "not enough memory"
 
 
 #define luaM_reallocv(L,b,on,n,e) \
-	((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ?  /* +1 to avoid warnings */ \
-		luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
-		luaM_toobig(L))
+    ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ?  /* +1 to avoid warnings */ \
+        luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
+        luaM_toobig(L))
 
-#define luaM_freemem(L, b, s)	luaM_realloc_(L, (b), (s), 0)
-#define luaM_free(L, b)		luaM_realloc_(L, (b), sizeof(*(b)), 0)
+#define luaM_freemem(L, b, s)   luaM_realloc_(L, (b), (s), 0)
+#define luaM_free(L, b)     luaM_realloc_(L, (b), sizeof(*(b)), 0)
 #define luaM_freearray(L, b, n, t)   luaM_reallocv(L, (b), n, 0, sizeof(t))
 
-#define luaM_malloc(L,t)	luaM_realloc_(L, NULL, 0, (t))
-#define luaM_new(L,t)		cast(t *, luaM_malloc(L, sizeof(t)))
+#define luaM_malloc(L,t)    luaM_realloc_(L, NULL, 0, (t))
+#define luaM_new(L,t)       cast(t *, luaM_malloc(L, sizeof(t)))
 #define luaM_newvector(L,n,t) \
-		cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
+        cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
 
 #define luaM_growvector(L,v,nelems,size,t,limit,e) \
           if ((nelems)+1 > (size)) \
--- a/misc/liblua/loadlib.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/loadlib.c	Tue Jan 21 22:53:15 2014 +0100
@@ -23,23 +23,23 @@
 
 
 /* prefix for open functions in C libraries */
-#define LUA_POF		"luaopen_"
+#define LUA_POF     "luaopen_"
 
 /* separator for open functions in C libraries */
-#define LUA_OFSEP	"_"
+#define LUA_OFSEP   "_"
 
 
-#define LIBPREFIX	"LOADLIB: "
+#define LIBPREFIX   "LOADLIB: "
 
-#define POF		LUA_POF
-#define LIB_FAIL	"open"
+#define POF     LUA_POF
+#define LIB_FAIL    "open"
 
 
 /* error codes for ll_loadfunc */
-#define ERRLIB		1
-#define ERRFUNC		2
+#define ERRLIB      1
+#define ERRFUNC     2
 
-#define setprogdir(L)		((void)0)
+#define setprogdir(L)       ((void)0)
 
 
 static void ll_unloadlib (void *lib);
@@ -153,7 +153,7 @@
 
 /* Mac appends a `_' before C function names */
 #undef POF
-#define POF	"_" LUA_POF
+#define POF "_" LUA_POF
 
 
 static void pusherror (lua_State *L) {
@@ -230,10 +230,10 @@
 */
 
 #undef LIB_FAIL
-#define LIB_FAIL	"absent"
+#define LIB_FAIL    "absent"
 
 
-#define DLMSG	"dynamic libraries not enabled; check your Lua installation"
+#define DLMSG   "dynamic libraries not enabled; check your Lua installation"
 
 
 static void ll_unloadlib (void *lib) {
@@ -445,7 +445,7 @@
 
 
 static const int sentinel_ = 0;
-#define sentinel	((void *)&sentinel_)
+#define sentinel    ((void *)&sentinel_)
 
 
 static int ll_require (lua_State *L) {
@@ -587,7 +587,7 @@
 
 
 /* auxiliary mark (for internal use) */
-#define AUXMARK		"\1"
+#define AUXMARK     "\1"
 
 static void setpath (lua_State *L, const char *fieldname, const char *envname,
                                    const char *def) {
--- a/misc/liblua/lobject.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lobject.h	Tue Jan 21 22:53:15 2014 +0100
@@ -17,17 +17,17 @@
 
 
 /* tags for values visible from Lua */
-#define LAST_TAG	LUA_TTHREAD
+#define LAST_TAG    LUA_TTHREAD
 
-#define NUM_TAGS	(LAST_TAG+1)
+#define NUM_TAGS    (LAST_TAG+1)
 
 
 /*
 ** Extra tags for non-values
 */
-#define LUA_TPROTO	(LAST_TAG+1)
-#define LUA_TUPVAL	(LAST_TAG+2)
-#define LUA_TDEADKEY	(LAST_TAG+3)
+#define LUA_TPROTO  (LAST_TAG+1)
+#define LUA_TUPVAL  (LAST_TAG+2)
+#define LUA_TDEADKEY    (LAST_TAG+3)
 
 
 /*
@@ -40,7 +40,7 @@
 ** Common Header for all collectable objects (in macro form, to be
 ** included in other objects)
 */
-#define CommonHeader	GCObject *next; lu_byte tt; lu_byte marked
+#define CommonHeader    GCObject *next; lu_byte tt; lu_byte marked
 
 
 /*
@@ -68,7 +68,7 @@
 ** Tagged Values
 */
 
-#define TValuefields	Value value; int tt
+#define TValuefields    Value value; int tt
 
 typedef struct lua_TValue {
   TValuefields;
@@ -76,31 +76,31 @@
 
 
 /* Macros to test type */
-#define ttisnil(o)	(ttype(o) == LUA_TNIL)
-#define ttisnumber(o)	(ttype(o) == LUA_TNUMBER)
-#define ttisstring(o)	(ttype(o) == LUA_TSTRING)
-#define ttistable(o)	(ttype(o) == LUA_TTABLE)
-#define ttisfunction(o)	(ttype(o) == LUA_TFUNCTION)
-#define ttisboolean(o)	(ttype(o) == LUA_TBOOLEAN)
-#define ttisuserdata(o)	(ttype(o) == LUA_TUSERDATA)
-#define ttisthread(o)	(ttype(o) == LUA_TTHREAD)
-#define ttislightuserdata(o)	(ttype(o) == LUA_TLIGHTUSERDATA)
+#define ttisnil(o)  (ttype(o) == LUA_TNIL)
+#define ttisnumber(o)   (ttype(o) == LUA_TNUMBER)
+#define ttisstring(o)   (ttype(o) == LUA_TSTRING)
+#define ttistable(o)    (ttype(o) == LUA_TTABLE)
+#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION)
+#define ttisboolean(o)  (ttype(o) == LUA_TBOOLEAN)
+#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA)
+#define ttisthread(o)   (ttype(o) == LUA_TTHREAD)
+#define ttislightuserdata(o)    (ttype(o) == LUA_TLIGHTUSERDATA)
 
 /* Macros to access values */
-#define ttype(o)	((o)->tt)
-#define gcvalue(o)	check_exp(iscollectable(o), (o)->value.gc)
-#define pvalue(o)	check_exp(ttislightuserdata(o), (o)->value.p)
-#define nvalue(o)	check_exp(ttisnumber(o), (o)->value.n)
-#define rawtsvalue(o)	check_exp(ttisstring(o), &(o)->value.gc->ts)
-#define tsvalue(o)	(&rawtsvalue(o)->tsv)
-#define rawuvalue(o)	check_exp(ttisuserdata(o), &(o)->value.gc->u)
-#define uvalue(o)	(&rawuvalue(o)->uv)
-#define clvalue(o)	check_exp(ttisfunction(o), &(o)->value.gc->cl)
-#define hvalue(o)	check_exp(ttistable(o), &(o)->value.gc->h)
-#define bvalue(o)	check_exp(ttisboolean(o), (o)->value.b)
-#define thvalue(o)	check_exp(ttisthread(o), &(o)->value.gc->th)
+#define ttype(o)    ((o)->tt)
+#define gcvalue(o)  check_exp(iscollectable(o), (o)->value.gc)
+#define pvalue(o)   check_exp(ttislightuserdata(o), (o)->value.p)
+#define nvalue(o)   check_exp(ttisnumber(o), (o)->value.n)
+#define rawtsvalue(o)   check_exp(ttisstring(o), &(o)->value.gc->ts)
+#define tsvalue(o)  (&rawtsvalue(o)->tsv)
+#define rawuvalue(o)    check_exp(ttisuserdata(o), &(o)->value.gc->u)
+#define uvalue(o)   (&rawuvalue(o)->uv)
+#define clvalue(o)  check_exp(ttisfunction(o), &(o)->value.gc->cl)
+#define hvalue(o)   check_exp(ttistable(o), &(o)->value.gc->h)
+#define bvalue(o)   check_exp(ttisboolean(o), (o)->value.b)
+#define thvalue(o)  check_exp(ttisthread(o), &(o)->value.gc->th)
 
-#define l_isfalse(o)	(ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
+#define l_isfalse(o)    (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
 
 /*
 ** for internal debug only
@@ -169,24 +169,24 @@
 */
 
 /* from stack to (same) stack */
-#define setobjs2s	setobj
+#define setobjs2s   setobj
 /* to stack (not from same stack) */
-#define setobj2s	setobj
-#define setsvalue2s	setsvalue
-#define sethvalue2s	sethvalue
-#define setptvalue2s	setptvalue
+#define setobj2s    setobj
+#define setsvalue2s setsvalue
+#define sethvalue2s sethvalue
+#define setptvalue2s    setptvalue
 /* from table to same table */
-#define setobjt2t	setobj
+#define setobjt2t   setobj
 /* to table */
-#define setobj2t	setobj
+#define setobj2t    setobj
 /* to new object */
-#define setobj2n	setobj
-#define setsvalue2n	setsvalue
+#define setobj2n    setobj
+#define setsvalue2n setsvalue
 
 #define setttype(obj, tt) (ttype(obj) = (tt))
 
 
-#define iscollectable(o)	(ttype(o) >= LUA_TSTRING)
+#define iscollectable(o)    (ttype(o) >= LUA_TSTRING)
 
 
 
@@ -207,7 +207,7 @@
 } TString;
 
 
-#define getstr(ts)	cast(const char *, (ts) + 1)
+#define getstr(ts)  cast(const char *, (ts) + 1)
 #define svalue(o)       getstr(rawtsvalue(o))
 
 
@@ -254,9 +254,9 @@
 
 
 /* masks for new-style vararg */
-#define VARARG_HASARG		1
-#define VARARG_ISVARARG		2
-#define VARARG_NEEDSARG		4
+#define VARARG_HASARG       1
+#define VARARG_ISVARARG     2
+#define VARARG_NEEDSARG     4
 
 
 typedef struct LocVar {
@@ -289,8 +289,8 @@
 */
 
 #define ClosureHeader \
-	CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \
-	struct Table *env
+    CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \
+    struct Table *env
 
 typedef struct CClosure {
   ClosureHeader;
@@ -312,8 +312,8 @@
 } Closure;
 
 
-#define iscfunction(o)	(ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC)
-#define isLfunction(o)	(ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC)
+#define iscfunction(o)  (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC)
+#define isLfunction(o)  (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC)
 
 
 /*
@@ -353,18 +353,18 @@
 ** `module' operation for hashing (size is always a power of 2)
 */
 #define lmod(s,size) \
-	(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
+    (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
 
 
-#define twoto(x)	(1<<(x))
-#define sizenode(t)	(twoto((t)->lsizenode))
+#define twoto(x)    (1<<(x))
+#define sizenode(t) (twoto((t)->lsizenode))
 
 
-#define luaO_nilobject		(&luaO_nilobject_)
+#define luaO_nilobject      (&luaO_nilobject_)
 
 LUAI_DATA const TValue luaO_nilobject_;
 
-#define ceillog2(x)	(luaO_log2((x)-1) + 1)
+#define ceillog2(x) (luaO_log2((x)-1) + 1)
 
 LUAI_FUNC int luaO_log2 (unsigned int x);
 LUAI_FUNC int luaO_int2fb (unsigned int x);
--- a/misc/liblua/lopcodes.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lopcodes.c	Tue Jan 21 22:53:15 2014 +0100
@@ -59,44 +59,44 @@
 #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))
 
 const lu_byte luaP_opmodes[NUM_OPCODES] = {
-/*       T  A    B       C     mode		   opcode	*/
-  opmode(0, 1, OpArgR, OpArgN, iABC) 		/* OP_MOVE */
- ,opmode(0, 1, OpArgK, OpArgN, iABx)		/* OP_LOADK */
- ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_LOADBOOL */
- ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_LOADNIL */
- ,opmode(0, 1, OpArgU, OpArgN, iABC)		/* OP_GETUPVAL */
- ,opmode(0, 1, OpArgK, OpArgN, iABx)		/* OP_GETGLOBAL */
- ,opmode(0, 1, OpArgR, OpArgK, iABC)		/* OP_GETTABLE */
- ,opmode(0, 0, OpArgK, OpArgN, iABx)		/* OP_SETGLOBAL */
- ,opmode(0, 0, OpArgU, OpArgN, iABC)		/* OP_SETUPVAL */
- ,opmode(0, 0, OpArgK, OpArgK, iABC)		/* OP_SETTABLE */
- ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_NEWTABLE */
- ,opmode(0, 1, OpArgR, OpArgK, iABC)		/* OP_SELF */
- ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_ADD */
- ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_SUB */
- ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_MUL */
- ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_DIV */
- ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_MOD */
- ,opmode(0, 1, OpArgK, OpArgK, iABC)		/* OP_POW */
- ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_UNM */
- ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_NOT */
- ,opmode(0, 1, OpArgR, OpArgN, iABC)		/* OP_LEN */
- ,opmode(0, 1, OpArgR, OpArgR, iABC)		/* OP_CONCAT */
- ,opmode(0, 0, OpArgR, OpArgN, iAsBx)		/* OP_JMP */
- ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_EQ */
- ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_LT */
- ,opmode(1, 0, OpArgK, OpArgK, iABC)		/* OP_LE */
- ,opmode(1, 1, OpArgR, OpArgU, iABC)		/* OP_TEST */
- ,opmode(1, 1, OpArgR, OpArgU, iABC)		/* OP_TESTSET */
- ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_CALL */
- ,opmode(0, 1, OpArgU, OpArgU, iABC)		/* OP_TAILCALL */
- ,opmode(0, 0, OpArgU, OpArgN, iABC)		/* OP_RETURN */
- ,opmode(0, 1, OpArgR, OpArgN, iAsBx)		/* OP_FORLOOP */
- ,opmode(0, 1, OpArgR, OpArgN, iAsBx)		/* OP_FORPREP */
- ,opmode(1, 0, OpArgN, OpArgU, iABC)		/* OP_TFORLOOP */
- ,opmode(0, 0, OpArgU, OpArgU, iABC)		/* OP_SETLIST */
- ,opmode(0, 0, OpArgN, OpArgN, iABC)		/* OP_CLOSE */
- ,opmode(0, 1, OpArgU, OpArgN, iABx)		/* OP_CLOSURE */
- ,opmode(0, 1, OpArgU, OpArgN, iABC)		/* OP_VARARG */
+/*       T  A    B       C     mode        opcode   */
+  opmode(0, 1, OpArgR, OpArgN, iABC)        /* OP_MOVE */
+ ,opmode(0, 1, OpArgK, OpArgN, iABx)        /* OP_LOADK */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC)        /* OP_LOADBOOL */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC)        /* OP_LOADNIL */
+ ,opmode(0, 1, OpArgU, OpArgN, iABC)        /* OP_GETUPVAL */
+ ,opmode(0, 1, OpArgK, OpArgN, iABx)        /* OP_GETGLOBAL */
+ ,opmode(0, 1, OpArgR, OpArgK, iABC)        /* OP_GETTABLE */
+ ,opmode(0, 0, OpArgK, OpArgN, iABx)        /* OP_SETGLOBAL */
+ ,opmode(0, 0, OpArgU, OpArgN, iABC)        /* OP_SETUPVAL */
+ ,opmode(0, 0, OpArgK, OpArgK, iABC)        /* OP_SETTABLE */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC)        /* OP_NEWTABLE */
+ ,opmode(0, 1, OpArgR, OpArgK, iABC)        /* OP_SELF */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC)        /* OP_ADD */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC)        /* OP_SUB */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC)        /* OP_MUL */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC)        /* OP_DIV */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC)        /* OP_MOD */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC)        /* OP_POW */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC)        /* OP_UNM */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC)        /* OP_NOT */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC)        /* OP_LEN */
+ ,opmode(0, 1, OpArgR, OpArgR, iABC)        /* OP_CONCAT */
+ ,opmode(0, 0, OpArgR, OpArgN, iAsBx)       /* OP_JMP */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC)        /* OP_EQ */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC)        /* OP_LT */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC)        /* OP_LE */
+ ,opmode(1, 1, OpArgR, OpArgU, iABC)        /* OP_TEST */
+ ,opmode(1, 1, OpArgR, OpArgU, iABC)        /* OP_TESTSET */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC)        /* OP_CALL */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC)        /* OP_TAILCALL */
+ ,opmode(0, 0, OpArgU, OpArgN, iABC)        /* OP_RETURN */
+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx)       /* OP_FORLOOP */
+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx)       /* OP_FORPREP */
+ ,opmode(1, 0, OpArgN, OpArgU, iABC)        /* OP_TFORLOOP */
+ ,opmode(0, 0, OpArgU, OpArgU, iABC)        /* OP_SETLIST */
+ ,opmode(0, 0, OpArgN, OpArgN, iABC)        /* OP_CLOSE */
+ ,opmode(0, 1, OpArgU, OpArgN, iABx)        /* OP_CLOSURE */
+ ,opmode(0, 1, OpArgU, OpArgN, iABC)        /* OP_VARARG */
 };
 
--- a/misc/liblua/lopcodes.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lopcodes.h	Tue Jan 21 22:53:15 2014 +0100
@@ -14,11 +14,11 @@
   We assume that instructions are unsigned numbers.
   All instructions have an opcode in the first 6 bits.
   Instructions can have the following fields:
-	`A' : 8 bits
-	`B' : 9 bits
-	`C' : 9 bits
-	`Bx' : 18 bits (`B' and `C' together)
-	`sBx' : signed Bx
+    `A' : 8 bits
+    `B' : 9 bits
+    `C' : 9 bits
+    `Bx' : 18 bits (`B' and `C' together)
+    `sBx' : signed Bx
 
   A signed argument is represented in excess K; that is, the number
   value is the unsigned value minus K. K is exactly the maximum value
@@ -34,18 +34,18 @@
 /*
 ** size and position of opcode arguments.
 */
-#define SIZE_C		9
-#define SIZE_B		9
-#define SIZE_Bx		(SIZE_C + SIZE_B)
-#define SIZE_A		8
+#define SIZE_C      9
+#define SIZE_B      9
+#define SIZE_Bx     (SIZE_C + SIZE_B)
+#define SIZE_A      8
 
-#define SIZE_OP		6
+#define SIZE_OP     6
 
-#define POS_OP		0
-#define POS_A		(POS_OP + SIZE_OP)
-#define POS_C		(POS_A + SIZE_A)
-#define POS_B		(POS_C + SIZE_C)
-#define POS_Bx		POS_C
+#define POS_OP      0
+#define POS_A       (POS_OP + SIZE_OP)
+#define POS_C       (POS_A + SIZE_A)
+#define POS_B       (POS_C + SIZE_C)
+#define POS_Bx      POS_C
 
 
 /*
@@ -68,47 +68,47 @@
 
 
 /* creates a mask with `n' 1 bits at position `p' */
-#define MASK1(n,p)	((~((~(Instruction)0)<<n))<<p)
+#define MASK1(n,p)  ((~((~(Instruction)0)<<n))<<p)
 
 /* creates a mask with `n' 0 bits at position `p' */
-#define MASK0(n,p)	(~MASK1(n,p))
+#define MASK0(n,p)  (~MASK1(n,p))
 
 /*
 ** the following macros help to manipulate instructions
 */
 
-#define GET_OPCODE(i)	(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
-#define SET_OPCODE(i,o)	((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
-		((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
+#define GET_OPCODE(i)   (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
+#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
+        ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
 
-#define GETARG_A(i)	(cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0)))
-#define SETARG_A(i,u)	((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
-		((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))
+#define GETARG_A(i) (cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0)))
+#define SETARG_A(i,u)   ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
+        ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))
 
-#define GETARG_B(i)	(cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
-#define SETARG_B(i,b)	((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
-		((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
+#define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
+#define SETARG_B(i,b)   ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
+        ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
 
-#define GETARG_C(i)	(cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
-#define SETARG_C(i,b)	((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
-		((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
+#define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
+#define SETARG_C(i,b)   ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
+        ((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
 
-#define GETARG_Bx(i)	(cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))
-#define SETARG_Bx(i,b)	((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \
-		((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))
+#define GETARG_Bx(i)    (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))
+#define SETARG_Bx(i,b)  ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \
+        ((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))
 
-#define GETARG_sBx(i)	(GETARG_Bx(i)-MAXARG_sBx)
-#define SETARG_sBx(i,b)	SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
+#define GETARG_sBx(i)   (GETARG_Bx(i)-MAXARG_sBx)
+#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
 
 
-#define CREATE_ABC(o,a,b,c)	((cast(Instruction, o)<<POS_OP) \
-			| (cast(Instruction, a)<<POS_A) \
-			| (cast(Instruction, b)<<POS_B) \
-			| (cast(Instruction, c)<<POS_C))
+#define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \
+            | (cast(Instruction, a)<<POS_A) \
+            | (cast(Instruction, b)<<POS_B) \
+            | (cast(Instruction, c)<<POS_C))
 
-#define CREATE_ABx(o,a,bc)	((cast(Instruction, o)<<POS_OP) \
-			| (cast(Instruction, a)<<POS_A) \
-			| (cast(Instruction, bc)<<POS_Bx))
+#define CREATE_ABx(o,a,bc)  ((cast(Instruction, o)<<POS_OP) \
+            | (cast(Instruction, a)<<POS_A) \
+            | (cast(Instruction, bc)<<POS_Bx))
 
 
 /*
@@ -116,24 +116,24 @@
 */
 
 /* this bit 1 means constant (0 means register) */
-#define BITRK		(1 << (SIZE_B - 1))
+#define BITRK       (1 << (SIZE_B - 1))
 
 /* test whether value is a constant */
-#define ISK(x)		((x) & BITRK)
+#define ISK(x)      ((x) & BITRK)
 
 /* gets the index of the constant */
-#define INDEXK(r)	((int)(r) & ~BITRK)
+#define INDEXK(r)   ((int)(r) & ~BITRK)
 
-#define MAXINDEXRK	(BITRK - 1)
+#define MAXINDEXRK  (BITRK - 1)
 
 /* code a constant index as a RK value */
-#define RKASK(x)	((x) | BITRK)
+#define RKASK(x)    ((x) | BITRK)
 
 
 /*
 ** invalid register that fits in 8 bits
 */
-#define NO_REG		MAXARG_A
+#define NO_REG      MAXARG_A
 
 
 /*
@@ -149,66 +149,66 @@
 
 typedef enum {
 /*----------------------------------------------------------------------
-name		args	description
+name        args    description
 ------------------------------------------------------------------------*/
-OP_MOVE,/*	A B	R(A) := R(B)					*/
-OP_LOADK,/*	A Bx	R(A) := Kst(Bx)					*/
-OP_LOADBOOL,/*	A B C	R(A) := (Bool)B; if (C) pc++			*/
-OP_LOADNIL,/*	A B	R(A) := ... := R(B) := nil			*/
-OP_GETUPVAL,/*	A B	R(A) := UpValue[B]				*/
+OP_MOVE,/*  A B R(A) := R(B)                    */
+OP_LOADK,/* A Bx    R(A) := Kst(Bx)                 */
+OP_LOADBOOL,/*  A B C   R(A) := (Bool)B; if (C) pc++            */
+OP_LOADNIL,/*   A B R(A) := ... := R(B) := nil          */
+OP_GETUPVAL,/*  A B R(A) := UpValue[B]              */
 
-OP_GETGLOBAL,/*	A Bx	R(A) := Gbl[Kst(Bx)]				*/
-OP_GETTABLE,/*	A B C	R(A) := R(B)[RK(C)]				*/
+OP_GETGLOBAL,/* A Bx    R(A) := Gbl[Kst(Bx)]                */
+OP_GETTABLE,/*  A B C   R(A) := R(B)[RK(C)]             */
 
-OP_SETGLOBAL,/*	A Bx	Gbl[Kst(Bx)] := R(A)				*/
-OP_SETUPVAL,/*	A B	UpValue[B] := R(A)				*/
-OP_SETTABLE,/*	A B C	R(A)[RK(B)] := RK(C)				*/
+OP_SETGLOBAL,/* A Bx    Gbl[Kst(Bx)] := R(A)                */
+OP_SETUPVAL,/*  A B UpValue[B] := R(A)              */
+OP_SETTABLE,/*  A B C   R(A)[RK(B)] := RK(C)                */
 
-OP_NEWTABLE,/*	A B C	R(A) := {} (size = B,C)				*/
+OP_NEWTABLE,/*  A B C   R(A) := {} (size = B,C)             */
 
-OP_SELF,/*	A B C	R(A+1) := R(B); R(A) := R(B)[RK(C)]		*/
+OP_SELF,/*  A B C   R(A+1) := R(B); R(A) := R(B)[RK(C)]     */
 
-OP_ADD,/*	A B C	R(A) := RK(B) + RK(C)				*/
-OP_SUB,/*	A B C	R(A) := RK(B) - RK(C)				*/
-OP_MUL,/*	A B C	R(A) := RK(B) * RK(C)				*/
-OP_DIV,/*	A B C	R(A) := RK(B) / RK(C)				*/
-OP_MOD,/*	A B C	R(A) := RK(B) % RK(C)				*/
-OP_POW,/*	A B C	R(A) := RK(B) ^ RK(C)				*/
-OP_UNM,/*	A B	R(A) := -R(B)					*/
-OP_NOT,/*	A B	R(A) := not R(B)				*/
-OP_LEN,/*	A B	R(A) := length of R(B)				*/
+OP_ADD,/*   A B C   R(A) := RK(B) + RK(C)               */
+OP_SUB,/*   A B C   R(A) := RK(B) - RK(C)               */
+OP_MUL,/*   A B C   R(A) := RK(B) * RK(C)               */
+OP_DIV,/*   A B C   R(A) := RK(B) / RK(C)               */
+OP_MOD,/*   A B C   R(A) := RK(B) % RK(C)               */
+OP_POW,/*   A B C   R(A) := RK(B) ^ RK(C)               */
+OP_UNM,/*   A B R(A) := -R(B)                   */
+OP_NOT,/*   A B R(A) := not R(B)                */
+OP_LEN,/*   A B R(A) := length of R(B)              */
 
-OP_CONCAT,/*	A B C	R(A) := R(B).. ... ..R(C)			*/
+OP_CONCAT,/*    A B C   R(A) := R(B).. ... ..R(C)           */
 
-OP_JMP,/*	sBx	pc+=sBx					*/
+OP_JMP,/*   sBx pc+=sBx                 */
 
-OP_EQ,/*	A B C	if ((RK(B) == RK(C)) ~= A) then pc++		*/
-OP_LT,/*	A B C	if ((RK(B) <  RK(C)) ~= A) then pc++  		*/
-OP_LE,/*	A B C	if ((RK(B) <= RK(C)) ~= A) then pc++  		*/
+OP_EQ,/*    A B C   if ((RK(B) == RK(C)) ~= A) then pc++        */
+OP_LT,/*    A B C   if ((RK(B) <  RK(C)) ~= A) then pc++        */
+OP_LE,/*    A B C   if ((RK(B) <= RK(C)) ~= A) then pc++        */
 
-OP_TEST,/*	A C	if not (R(A) <=> C) then pc++			*/
-OP_TESTSET,/*	A B C	if (R(B) <=> C) then R(A) := R(B) else pc++	*/
+OP_TEST,/*  A C if not (R(A) <=> C) then pc++           */
+OP_TESTSET,/*   A B C   if (R(B) <=> C) then R(A) := R(B) else pc++ */
 
-OP_CALL,/*	A B C	R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
-OP_TAILCALL,/*	A B C	return R(A)(R(A+1), ... ,R(A+B-1))		*/
-OP_RETURN,/*	A B	return R(A), ... ,R(A+B-2)	(see note)	*/
+OP_CALL,/*  A B C   R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
+OP_TAILCALL,/*  A B C   return R(A)(R(A+1), ... ,R(A+B-1))      */
+OP_RETURN,/*    A B return R(A), ... ,R(A+B-2)  (see note)  */
 
-OP_FORLOOP,/*	A sBx	R(A)+=R(A+2);
-			if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
-OP_FORPREP,/*	A sBx	R(A)-=R(A+2); pc+=sBx				*/
+OP_FORLOOP,/*   A sBx   R(A)+=R(A+2);
+            if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
+OP_FORPREP,/*   A sBx   R(A)-=R(A+2); pc+=sBx               */
 
-OP_TFORLOOP,/*	A C	R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
-                        if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++	*/
-OP_SETLIST,/*	A B C	R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B	*/
+OP_TFORLOOP,/*  A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
+                        if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++   */
+OP_SETLIST,/*   A B C   R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B    */
 
-OP_CLOSE,/*	A 	close all variables in the stack up to (>=) R(A)*/
-OP_CLOSURE,/*	A Bx	R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))	*/
+OP_CLOSE,/* A   close all variables in the stack up to (>=) R(A)*/
+OP_CLOSURE,/*   A Bx    R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))  */
 
-OP_VARARG/*	A B	R(A), R(A+1), ..., R(A+B-1) = vararg		*/
+OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg        */
 } OpCode;
 
 
-#define NUM_OPCODES	(cast(int, OP_VARARG) + 1)
+#define NUM_OPCODES (cast(int, OP_VARARG) + 1)
 
 
 
@@ -251,18 +251,18 @@
 
 LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES];
 
-#define getOpMode(m)	(cast(enum OpMode, luaP_opmodes[m] & 3))
-#define getBMode(m)	(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
-#define getCMode(m)	(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
-#define testAMode(m)	(luaP_opmodes[m] & (1 << 6))
-#define testTMode(m)	(luaP_opmodes[m] & (1 << 7))
+#define getOpMode(m)    (cast(enum OpMode, luaP_opmodes[m] & 3))
+#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
+#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
+#define testAMode(m)    (luaP_opmodes[m] & (1 << 6))
+#define testTMode(m)    (luaP_opmodes[m] & (1 << 7))
 
 
 LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */
 
 
 /* number of list items to accumulate before a SETLIST instruction */
-#define LFIELDS_PER_FLUSH	50
+#define LFIELDS_PER_FLUSH   50
 
 
 #endif
--- a/misc/liblua/lparser.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lparser.c	Tue Jan 21 22:53:15 2014 +0100
@@ -27,11 +27,11 @@
 
 
 
-#define hasmultret(k)		((k) == VCALL || (k) == VVARARG)
+#define hasmultret(k)       ((k) == VCALL || (k) == VVARARG)
 
-#define getlocvar(fs, i)	((fs)->f->locvars[(fs)->actvar[i]])
+#define getlocvar(fs, i)    ((fs)->f->locvars[(fs)->actvar[i]])
 
-#define luaY_checklimit(fs,v,l,m)	if ((v)>(l)) errorlimit(fs,l,m)
+#define luaY_checklimit(fs,v,l,m)   if ((v)>(l)) errorlimit(fs,l,m)
 
 
 /*
@@ -97,7 +97,7 @@
 }
 
 
-#define check_condition(ls,c,msg)	{ if (!(c)) luaX_syntaxerror(ls, msg); }
+#define check_condition(ls,c,msg)   { if (!(c)) luaX_syntaxerror(ls, msg); }
 
 
 
@@ -275,11 +275,11 @@
 
 static void enterlevel (LexState *ls) {
   if (++ls->L->nCcalls > LUAI_MAXCCALLS)
-	luaX_lexerror(ls, "chunk has too many syntax levels", 0);
+    luaX_lexerror(ls, "chunk has too many syntax levels", 0);
 }
 
 
-#define leavelevel(ls)	((ls)->L->nCcalls--)
+#define leavelevel(ls)  ((ls)->L->nCcalls--)
 
 
 static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) {
@@ -818,7 +818,7 @@
    {2, 2}, {1, 1}                   /* logical (and/or) */
 };
 
-#define UNARY_PRIORITY	8  /* priority for unary operators */
+#define UNARY_PRIORITY  8  /* priority for unary operators */
 
 
 /*
--- a/misc/liblua/lparser.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lparser.h	Tue Jan 21 22:53:15 2014 +0100
@@ -17,21 +17,21 @@
 */
 
 typedef enum {
-  VVOID,	/* no value */
+  VVOID,    /* no value */
   VNIL,
   VTRUE,
   VFALSE,
-  VK,		/* info = index of constant in `k' */
-  VKNUM,	/* nval = numerical value */
-  VLOCAL,	/* info = local register */
+  VK,       /* info = index of constant in `k' */
+  VKNUM,    /* nval = numerical value */
+  VLOCAL,   /* info = local register */
   VUPVAL,       /* info = index of upvalue in `upvalues' */
-  VGLOBAL,	/* info = index of table; aux = index of global name in `k' */
-  VINDEXED,	/* info = table register; aux = index register (or `k') */
-  VJMP,		/* info = instruction pc */
-  VRELOCABLE,	/* info = instruction pc */
-  VNONRELOC,	/* info = result register */
-  VCALL,	/* info = instruction pc */
-  VVARARG	/* info = instruction pc */
+  VGLOBAL,  /* info = index of table; aux = index of global name in `k' */
+  VINDEXED, /* info = table register; aux = index register (or `k') */
+  VJMP,     /* info = instruction pc */
+  VRELOCABLE,   /* info = instruction pc */
+  VNONRELOC,    /* info = result register */
+  VCALL,    /* info = instruction pc */
+  VVARARG   /* info = instruction pc */
 } expkind;
 
 typedef struct expdesc {
--- a/misc/liblua/lstate.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lstate.c	Tue Jan 21 22:53:15 2014 +0100
@@ -24,8 +24,8 @@
 #include "ltm.h"
 
 
-#define state_size(x)	(sizeof(x) + LUAI_EXTRASPACE)
-#define fromstate(l)	(cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
+#define state_size(x)   (sizeof(x) + LUAI_EXTRASPACE)
+#define fromstate(l)    (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
 #define tostate(l)   (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
 
 
--- a/misc/liblua/lstate.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lstate.h	Tue Jan 21 22:53:15 2014 +0100
@@ -19,10 +19,10 @@
 
 
 /* table of globals */
-#define gt(L)	(&L->l_gt)
+#define gt(L)   (&L->l_gt)
 
 /* registry */
-#define registry(L)	(&G(L)->l_registry)
+#define registry(L) (&G(L)->l_registry)
 
 
 /* extra stack space to handle TM calls and some other extras */
@@ -48,7 +48,7 @@
 typedef struct CallInfo {
   StkId base;  /* base for this function */
   StkId func;  /* function index in the stack */
-  StkId	top;  /* top for this function */
+  StkId top;  /* top for this function */
   const Instruction *savedpc;
   int nresults;  /* expected number of results from this function */
   int tailcalls;  /* number of tail calls lost under this entry */
@@ -56,10 +56,10 @@
 
 
 
-#define curr_func(L)	(clvalue(L->ci->func))
-#define ci_func(ci)	(clvalue((ci)->func))
-#define f_isLua(ci)	(!ci_func(ci)->c.isC)
-#define isLua(ci)	(ttisfunction((ci)->func) && f_isLua(ci))
+#define curr_func(L)    (clvalue(L->ci->func))
+#define ci_func(ci) (clvalue((ci)->func))
+#define f_isLua(ci) (!ci_func(ci)->c.isC)
+#define isLua(ci)   (ttisfunction((ci)->func) && f_isLua(ci))
 
 
 /*
@@ -127,7 +127,7 @@
 };
 
 
-#define G(L)	(L->l_G)
+#define G(L)    (L->l_G)
 
 
 /*
@@ -146,20 +146,20 @@
 
 
 /* macros to convert a GCObject into a specific value */
-#define rawgco2ts(o)	check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
-#define gco2ts(o)	(&rawgco2ts(o)->tsv)
-#define rawgco2u(o)	check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
-#define gco2u(o)	(&rawgco2u(o)->uv)
-#define gco2cl(o)	check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
-#define gco2h(o)	check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
-#define gco2p(o)	check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
-#define gco2uv(o)	check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
+#define rawgco2ts(o)    check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
+#define gco2ts(o)   (&rawgco2ts(o)->tsv)
+#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
+#define gco2u(o)    (&rawgco2u(o)->uv)
+#define gco2cl(o)   check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
+#define gco2h(o)    check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
+#define gco2p(o)    check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
+#define gco2uv(o)   check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
 #define ngcotouv(o) \
-	check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
-#define gco2th(o)	check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
+    check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
+#define gco2th(o)   check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
 
 /* macro to convert any Lua object into a GCObject */
-#define obj2gco(v)	(cast(GCObject *, (v)))
+#define obj2gco(v)  (cast(GCObject *, (v)))
 
 
 LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
--- a/misc/liblua/lstring.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lstring.h	Tue Jan 21 22:53:15 2014 +0100
@@ -13,15 +13,15 @@
 #include "lstate.h"
 
 
-#define sizestring(s)	(sizeof(union TString)+((s)->len+1)*sizeof(char))
+#define sizestring(s)   (sizeof(union TString)+((s)->len+1)*sizeof(char))
 
-#define sizeudata(u)	(sizeof(union Udata)+(u)->len)
+#define sizeudata(u)    (sizeof(union Udata)+(u)->len)
 
-#define luaS_new(L, s)	(luaS_newlstr(L, s, strlen(s)))
-#define luaS_newliteral(L, s)	(luaS_newlstr(L, "" s, \
+#define luaS_new(L, s)  (luaS_newlstr(L, s, strlen(s)))
+#define luaS_newliteral(L, s)   (luaS_newlstr(L, "" s, \
                                  (sizeof(s)/sizeof(char))-1))
 
-#define luaS_fix(s)	l_setbit((s)->tsv.marked, FIXEDBIT)
+#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
 
 LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
 LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
--- a/misc/liblua/lstrlib.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lstrlib.c	Tue Jan 21 22:53:15 2014 +0100
@@ -164,8 +164,8 @@
 */
 
 
-#define CAP_UNFINISHED	(-1)
-#define CAP_POSITION	(-2)
+#define CAP_UNFINISHED  (-1)
+#define CAP_POSITION    (-2)
 
 typedef struct MatchState {
   const char *src_init;  /* init of source string */
@@ -179,8 +179,8 @@
 } MatchState;
 
 
-#define L_ESC		'%'
-#define SPECIALS	"^$*+?.([%-"
+#define L_ESC       '%'
+#define SPECIALS    "^$*+?.([%-"
 
 
 static int check_capture (MatchState *ms, int l) {
@@ -683,14 +683,14 @@
 
 
 /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
-#define MAX_ITEM	512
+#define MAX_ITEM    512
 /* valid flags in a format specification */
-#define FLAGS	"-+ #0"
+#define FLAGS   "-+ #0"
 /*
 ** maximum size of each format specification (such as '%-099.99d')
 ** (+10 accounts for %99.99x plus margin of error)
 */
-#define MAX_FORMAT	(sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
+#define MAX_FORMAT  (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
 
 
 static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
--- a/misc/liblua/ltable.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ltable.c	Tue Jan 21 22:53:15 2014 +0100
@@ -39,12 +39,12 @@
 ** max size of array part is 2^MAXBITS
 */
 #if LUAI_BITSINT > 26
-#define MAXBITS		26
+#define MAXBITS     26
 #else
-#define MAXBITS		(LUAI_BITSINT-2)
+#define MAXBITS     (LUAI_BITSINT-2)
 #endif
 
-#define MAXASIZE	(1 << MAXBITS)
+#define MAXASIZE    (1 << MAXBITS)
 
 
 #define hashpow2(t,n)      (gnode(t, lmod((n), sizenode(t))))
@@ -57,20 +57,20 @@
 ** for some types, it is better to avoid modulus by power of 2, as
 ** they tend to have many 2 factors.
 */
-#define hashmod(t,n)	(gnode(t, ((n) % ((sizenode(t)-1)|1))))
+#define hashmod(t,n)    (gnode(t, ((n) % ((sizenode(t)-1)|1))))
 
 
-#define hashpointer(t,p)	hashmod(t, IntPoint(p))
+#define hashpointer(t,p)    hashmod(t, IntPoint(p))
 
 
 /*
 ** number of ints inside a lua_Number
 */
-#define numints		cast_int(sizeof(lua_Number)/sizeof(int))
+#define numints     cast_int(sizeof(lua_Number)/sizeof(int))
 
 
 
-#define dummynode		(&dummynode_)
+#define dummynode       (&dummynode_)
 
 static const Node dummynode_ = {
   {{NULL}, LUA_TNIL},  /* value */
--- a/misc/liblua/ltable.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ltable.h	Tue Jan 21 22:53:15 2014 +0100
@@ -10,12 +10,12 @@
 #include "lobject.h"
 
 
-#define gnode(t,i)	(&(t)->node[i])
-#define gkey(n)		(&(n)->i_key.nk)
-#define gval(n)		(&(n)->i_val)
-#define gnext(n)	((n)->i_key.nk.next)
+#define gnode(t,i)  (&(t)->node[i])
+#define gkey(n)     (&(n)->i_key.nk)
+#define gval(n)     (&(n)->i_val)
+#define gnext(n)    ((n)->i_key.nk.next)
 
-#define key2tval(n)	(&(n)->i_key.tvk)
+#define key2tval(n) (&(n)->i_key.tvk)
 
 
 LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
--- a/misc/liblua/ltablib.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ltablib.c	Tue Jan 21 22:53:15 2014 +0100
@@ -16,7 +16,7 @@
 #include "lualib.h"
 
 
-#define aux_getn(L,n)	(luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
+#define aux_getn(L,n)   (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
 
 
 static int foreachi (lua_State *L) {
--- a/misc/liblua/ltm.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/ltm.h	Tue Jan 21 22:53:15 2014 +0100
@@ -33,7 +33,7 @@
   TM_LE,
   TM_CONCAT,
   TM_CALL,
-  TM_N		/* number of elements in the enum */
+  TM_N      /* number of elements in the enum */
 } TMS;
 
 
@@ -41,7 +41,7 @@
 #define gfasttm(g,et,e) ((et) == NULL ? NULL : \
   ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
 
-#define fasttm(l,et,e)	gfasttm(G(l), et, e)
+#define fasttm(l,et,e)  gfasttm(G(l), et, e)
 
 LUAI_DATA const char *const luaT_typenames[];
 
--- a/misc/liblua/lua.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lua.h	Tue Jan 21 22:53:15 2014 +0100
@@ -16,35 +16,35 @@
 #include "luaconf.h"
 
 
-#define LUA_VERSION	"Lua 5.1"
-#define LUA_RELEASE	"Lua 5.1.4"
-#define LUA_VERSION_NUM	501
-#define LUA_COPYRIGHT	"Copyright (C) 1994-2008 Lua.org, PUC-Rio"
-#define LUA_AUTHORS 	"R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
+#define LUA_VERSION "Lua 5.1"
+#define LUA_RELEASE "Lua 5.1.4"
+#define LUA_VERSION_NUM 501
+#define LUA_COPYRIGHT   "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
+#define LUA_AUTHORS     "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
 
 
 /* mark for precompiled code (`<esc>Lua') */
-#define	LUA_SIGNATURE	"\033Lua"
+#define LUA_SIGNATURE   "\033Lua"
 
 /* option for multiple returns in `lua_pcall' and `lua_call' */
-#define LUA_MULTRET	(-1)
+#define LUA_MULTRET (-1)
 
 
 /*
 ** pseudo-indices
 */
-#define LUA_REGISTRYINDEX	(-10000)
-#define LUA_ENVIRONINDEX	(-10001)
-#define LUA_GLOBALSINDEX	(-10002)
-#define lua_upvalueindex(i)	(LUA_GLOBALSINDEX-(i))
+#define LUA_REGISTRYINDEX   (-10000)
+#define LUA_ENVIRONINDEX    (-10001)
+#define LUA_GLOBALSINDEX    (-10002)
+#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
 
 
 /* thread status; 0 is OK */
-#define LUA_YIELD	1
-#define LUA_ERRRUN	2
-#define LUA_ERRSYNTAX	3
-#define LUA_ERRMEM	4
-#define LUA_ERRERR	5
+#define LUA_YIELD   1
+#define LUA_ERRRUN  2
+#define LUA_ERRSYNTAX   3
+#define LUA_ERRMEM  4
+#define LUA_ERRERR  5
 
 
 typedef struct lua_State lua_State;
@@ -69,22 +69,22 @@
 /*
 ** basic types
 */
-#define LUA_TNONE		(-1)
+#define LUA_TNONE       (-1)
 
-#define LUA_TNIL		0
-#define LUA_TBOOLEAN		1
-#define LUA_TLIGHTUSERDATA	2
-#define LUA_TNUMBER		3
-#define LUA_TSTRING		4
-#define LUA_TTABLE		5
-#define LUA_TFUNCTION		6
-#define LUA_TUSERDATA		7
-#define LUA_TTHREAD		8
+#define LUA_TNIL        0
+#define LUA_TBOOLEAN        1
+#define LUA_TLIGHTUSERDATA  2
+#define LUA_TNUMBER     3
+#define LUA_TSTRING     4
+#define LUA_TTABLE      5
+#define LUA_TFUNCTION       6
+#define LUA_TUSERDATA       7
+#define LUA_TTHREAD     8
 
 
 
 /* minimum Lua stack available to a C function */
-#define LUA_MINSTACK	20
+#define LUA_MINSTACK    20
 
 
 /*
@@ -149,7 +149,7 @@
 LUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);
 LUA_API size_t          (lua_objlen) (lua_State *L, int idx);
 LUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);
-LUA_API void	       *(lua_touserdata) (lua_State *L, int idx);
+LUA_API void           *(lua_touserdata) (lua_State *L, int idx);
 LUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);
 LUA_API const void     *(lua_topointer) (lua_State *L, int idx);
 
@@ -218,14 +218,14 @@
 ** garbage-collection function and options
 */
 
-#define LUA_GCSTOP		0
-#define LUA_GCRESTART		1
-#define LUA_GCCOLLECT		2
-#define LUA_GCCOUNT		3
-#define LUA_GCCOUNTB		4
-#define LUA_GCSTEP		5
-#define LUA_GCSETPAUSE		6
-#define LUA_GCSETSTEPMUL	7
+#define LUA_GCSTOP      0
+#define LUA_GCRESTART       1
+#define LUA_GCCOLLECT       2
+#define LUA_GCCOUNT     3
+#define LUA_GCCOUNTB        4
+#define LUA_GCSTEP      5
+#define LUA_GCSETPAUSE      6
+#define LUA_GCSETSTEPMUL    7
 
 LUA_API int (lua_gc) (lua_State *L, int what, int data);
 
@@ -251,32 +251,32 @@
 ** ===============================================================
 */
 
-#define lua_pop(L,n)		lua_settop(L, -(n)-1)
+#define lua_pop(L,n)        lua_settop(L, -(n)-1)
 
-#define lua_newtable(L)		lua_createtable(L, 0, 0)
+#define lua_newtable(L)     lua_createtable(L, 0, 0)
 
 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
 
-#define lua_pushcfunction(L,f)	lua_pushcclosure(L, (f), 0)
+#define lua_pushcfunction(L,f)  lua_pushcclosure(L, (f), 0)
 
-#define lua_strlen(L,i)		lua_objlen(L, (i))
+#define lua_strlen(L,i)     lua_objlen(L, (i))
 
-#define lua_isfunction(L,n)	(lua_type(L, (n)) == LUA_TFUNCTION)
-#define lua_istable(L,n)	(lua_type(L, (n)) == LUA_TTABLE)
-#define lua_islightuserdata(L,n)	(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
-#define lua_isnil(L,n)		(lua_type(L, (n)) == LUA_TNIL)
-#define lua_isboolean(L,n)	(lua_type(L, (n)) == LUA_TBOOLEAN)
-#define lua_isthread(L,n)	(lua_type(L, (n)) == LUA_TTHREAD)
-#define lua_isnone(L,n)		(lua_type(L, (n)) == LUA_TNONE)
-#define lua_isnoneornil(L, n)	(lua_type(L, (n)) <= 0)
+#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
+#define lua_istable(L,n)    (lua_type(L, (n)) == LUA_TTABLE)
+#define lua_islightuserdata(L,n)    (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
+#define lua_isnil(L,n)      (lua_type(L, (n)) == LUA_TNIL)
+#define lua_isboolean(L,n)  (lua_type(L, (n)) == LUA_TBOOLEAN)
+#define lua_isthread(L,n)   (lua_type(L, (n)) == LUA_TTHREAD)
+#define lua_isnone(L,n)     (lua_type(L, (n)) == LUA_TNONE)
+#define lua_isnoneornil(L, n)   (lua_type(L, (n)) <= 0)
 
-#define lua_pushliteral(L, s)	\
-	lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
+#define lua_pushliteral(L, s)   \
+    lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
 
-#define lua_setglobal(L,s)	lua_setfield(L, LUA_GLOBALSINDEX, (s))
-#define lua_getglobal(L,s)	lua_getfield(L, LUA_GLOBALSINDEX, (s))
+#define lua_setglobal(L,s)  lua_setfield(L, LUA_GLOBALSINDEX, (s))
+#define lua_getglobal(L,s)  lua_getfield(L, LUA_GLOBALSINDEX, (s))
 
-#define lua_tostring(L,i)	lua_tolstring(L, (i), NULL)
+#define lua_tostring(L,i)   lua_tolstring(L, (i), NULL)
 
 
 
@@ -284,18 +284,18 @@
 ** compatibility macros and functions
 */
 
-#define lua_open()	luaL_newstate()
+#define lua_open()  luaL_newstate()
 
-#define lua_getregistry(L)	lua_pushvalue(L, LUA_REGISTRYINDEX)
+#define lua_getregistry(L)  lua_pushvalue(L, LUA_REGISTRYINDEX)
 
-#define lua_getgccount(L)	lua_gc(L, LUA_GCCOUNT, 0)
+#define lua_getgccount(L)   lua_gc(L, LUA_GCCOUNT, 0)
 
-#define lua_Chunkreader		lua_Reader
-#define lua_Chunkwriter		lua_Writer
+#define lua_Chunkreader     lua_Reader
+#define lua_Chunkwriter     lua_Writer
 
 
 /* hack */
-LUA_API void lua_setlevel	(lua_State *from, lua_State *to);
+LUA_API void lua_setlevel   (lua_State *from, lua_State *to);
 
 
 /*
@@ -308,20 +308,20 @@
 /*
 ** Event codes
 */
-#define LUA_HOOKCALL	0
-#define LUA_HOOKRET	1
-#define LUA_HOOKLINE	2
-#define LUA_HOOKCOUNT	3
+#define LUA_HOOKCALL    0
+#define LUA_HOOKRET 1
+#define LUA_HOOKLINE    2
+#define LUA_HOOKCOUNT   3
 #define LUA_HOOKTAILRET 4
 
 
 /*
 ** Event masks
 */
-#define LUA_MASKCALL	(1 << LUA_HOOKCALL)
-#define LUA_MASKRET	(1 << LUA_HOOKRET)
-#define LUA_MASKLINE	(1 << LUA_HOOKLINE)
-#define LUA_MASKCOUNT	(1 << LUA_HOOKCOUNT)
+#define LUA_MASKCALL    (1 << LUA_HOOKCALL)
+#define LUA_MASKRET (1 << LUA_HOOKRET)
+#define LUA_MASKLINE    (1 << LUA_HOOKLINE)
+#define LUA_MASKCOUNT   (1 << LUA_HOOKCOUNT)
 
 typedef struct lua_Debug lua_Debug;  /* activation record */
 
@@ -345,14 +345,14 @@
 
 struct lua_Debug {
   int event;
-  const char *name;	/* (n) */
-  const char *namewhat;	/* (n) `global', `local', `field', `method' */
-  const char *what;	/* (S) `Lua', `C', `main', `tail' */
-  const char *source;	/* (S) */
-  int currentline;	/* (l) */
-  int nups;		/* (u) number of upvalues */
-  int linedefined;	/* (S) */
-  int lastlinedefined;	/* (S) */
+  const char *name; /* (n) */
+  const char *namewhat; /* (n) `global', `local', `field', `method' */
+  const char *what; /* (S) `Lua', `C', `main', `tail' */
+  const char *source;   /* (S) */
+  int currentline;  /* (l) */
+  int nups;     /* (u) number of upvalues */
+  int linedefined;  /* (S) */
+  int lastlinedefined;  /* (S) */
   char short_src[LUA_IDSIZE]; /* (S) */
   /* private part */
   int i_ci;  /* active function */
--- a/misc/liblua/luaconf.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/luaconf.h	Tue Jan 21 22:53:15 2014 +0100
@@ -35,13 +35,13 @@
 
 #if defined(LUA_USE_LINUX)
 #define LUA_USE_POSIX
-#define LUA_USE_DLOPEN		/* needs an extra library: -ldl */
-#define LUA_USE_READLINE	/* needs some extra libraries */
+#define LUA_USE_DLOPEN      /* needs an extra library: -ldl */
+#define LUA_USE_READLINE    /* needs some extra libraries */
 #endif
 
 #if defined(LUA_USE_MACOSX)
 #define LUA_USE_POSIX
-#define LUA_DL_DYLD		/* does not need extra library */
+#define LUA_DL_DYLD     /* does not need extra library */
 #endif
 
 
@@ -68,7 +68,7 @@
 */
 #define LUA_PATH        "LUA_PATH"
 #define LUA_CPATH       "LUA_CPATH"
-#define LUA_INIT	"LUA_INIT"
+#define LUA_INIT    "LUA_INIT"
 
 
 /*
@@ -85,23 +85,23 @@
 ** In Windows, any exclamation mark ('!') in the path is replaced by the
 ** path of the directory of the executable file of the current process.
 */
-#define LUA_LDIR	"!\\lua\\"
-#define LUA_CDIR	"!\\"
+#define LUA_LDIR    "!\\lua\\"
+#define LUA_CDIR    "!\\"
 #define LUA_PATH_DEFAULT  \
-		".\\?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?\\init.lua;" \
-		             LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua"
+        ".\\?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?\\init.lua;" \
+                     LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua"
 #define LUA_CPATH_DEFAULT \
-	".\\?.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
+    ".\\?.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
 
 #else
-#define LUA_ROOT	"/usr/local/"
-#define LUA_LDIR	LUA_ROOT "share/lua/5.1/"
-#define LUA_CDIR	LUA_ROOT "lib/lua/5.1/"
+#define LUA_ROOT    "/usr/local/"
+#define LUA_LDIR    LUA_ROOT "share/lua/5.1/"
+#define LUA_CDIR    LUA_ROOT "lib/lua/5.1/"
 #define LUA_PATH_DEFAULT  \
-		"./?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \
-		            LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua"
+        "./?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \
+                    LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua"
 #define LUA_CPATH_DEFAULT \
-	"./?.so;"  LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
+    "./?.so;"  LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
 #endif
 
 
@@ -111,9 +111,9 @@
 ** and is not Windows. (On Windows Lua automatically uses "\".)
 */
 #if defined(_WIN32)
-#define LUA_DIRSEP	"\\"
+#define LUA_DIRSEP  "\\"
 #else
-#define LUA_DIRSEP	"/"
+#define LUA_DIRSEP  "/"
 #endif
 
 
@@ -129,10 +129,10 @@
 ** characters. (E.g., if one of those characters is a common character
 ** in file/directory names.) Probably you do not need to change them.
 */
-#define LUA_PATHSEP	";"
-#define LUA_PATH_MARK	"?"
-#define LUA_EXECDIR	"!"
-#define LUA_IGMARK	"-"
+#define LUA_PATHSEP ";"
+#define LUA_PATH_MARK   "?"
+#define LUA_EXECDIR "!"
+#define LUA_IGMARK  "-"
 
 
 /*
@@ -140,7 +140,7 @@
 ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
 ** machines, ptrdiff_t gives a good choice between int or long.)
 */
-#define LUA_INTEGER	ptrdiff_t
+#define LUA_INTEGER ptrdiff_t
 
 
 /*
@@ -161,12 +161,12 @@
 
 #else
 
-#define LUA_API		extern
+#define LUA_API     extern
 
 #endif
 
 /* more often than not the libs go together with the core */
-#define LUALIB_API	LUA_API
+#define LUALIB_API  LUA_API
 
 
 /*
@@ -179,17 +179,17 @@
 ** when Lua is compiled as a shared library.
 */
 #if defined(luaall_c)
-#define LUAI_FUNC	static
-#define LUAI_DATA	/* empty */
+#define LUAI_FUNC   static
+#define LUAI_DATA   /* empty */
 
 #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
       defined(__ELF__)
-#define LUAI_FUNC	__attribute__((visibility("hidden"))) extern
-#define LUAI_DATA	LUAI_FUNC
+#define LUAI_FUNC   __attribute__((visibility("hidden"))) extern
+#define LUAI_DATA   LUAI_FUNC
 
 #else
-#define LUAI_FUNC	extern
-#define LUAI_DATA	extern
+#define LUAI_FUNC   extern
+#define LUAI_DATA   extern
 #endif
 
 
@@ -198,8 +198,8 @@
 @@ LUA_QL describes how error messages quote program elements.
 ** CHANGE it if you want a different appearance.
 */
-#define LUA_QL(x)	"'" x "'"
-#define LUA_QS		LUA_QL("%s")
+#define LUA_QL(x)   "'" x "'"
+#define LUA_QS      LUA_QL("%s")
 
 
 /*
@@ -207,7 +207,7 @@
 @* of a function in debug information.
 ** CHANGE it if you want a different size.
 */
-#define LUA_IDSIZE	60
+#define LUA_IDSIZE  60
 
 
 /*
@@ -226,13 +226,13 @@
 */
 #if defined(LUA_USE_ISATTY)
 #include <unistd.h>
-#define lua_stdin_is_tty()	isatty(0)
+#define lua_stdin_is_tty()  isatty(0)
 #elif defined(LUA_WIN)
 #include <io.h>
 #include <stdio.h>
-#define lua_stdin_is_tty()	_isatty(_fileno(stdin))
+#define lua_stdin_is_tty()  _isatty(_fileno(stdin))
 #else
-#define lua_stdin_is_tty()	1  /* assume stdin is a tty */
+#define lua_stdin_is_tty()  1  /* assume stdin is a tty */
 #endif
 
 
@@ -242,8 +242,8 @@
 ** CHANGE them if you want different prompts. (You can also change the
 ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
 */
-#define LUA_PROMPT		"> "
-#define LUA_PROMPT2		">> "
+#define LUA_PROMPT      "> "
+#define LUA_PROMPT2     ">> "
 
 
 /*
@@ -251,7 +251,7 @@
 ** CHANGE it if your stand-alone interpreter has a different name and
 ** your system is not able to detect that name automatically.
 */
-#define LUA_PROGNAME		"lua"
+#define LUA_PROGNAME        "lua"
 
 
 /*
@@ -259,7 +259,7 @@
 @* stand-alone interpreter.
 ** CHANGE it if you need longer lines.
 */
-#define LUA_MAXINPUT	512
+#define LUA_MAXINPUT    512
 
 
 /*
@@ -274,17 +274,17 @@
 #include <stdio.h>
 #include <readline/readline.h>
 #include <readline/history.h>
-#define lua_readline(L,b,p)	((void)L, ((b)=readline(p)) != NULL)
+#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
 #define lua_saveline(L,idx) \
-	if (lua_strlen(L,idx) > 0)  /* non-empty line? */ \
-	  add_history(lua_tostring(L, idx));  /* add it to history */
-#define lua_freeline(L,b)	((void)L, free(b))
+    if (lua_strlen(L,idx) > 0)  /* non-empty line? */ \
+      add_history(lua_tostring(L, idx));  /* add it to history */
+#define lua_freeline(L,b)   ((void)L, free(b))
 #else
-#define lua_readline(L,b,p)	\
-	((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \
-	fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */
-#define lua_saveline(L,idx)	{ (void)L; (void)idx; }
-#define lua_freeline(L,b)	{ (void)L; (void)b; }
+#define lua_readline(L,b,p) \
+    ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \
+    fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */
+#define lua_saveline(L,idx) { (void)L; (void)idx; }
+#define lua_freeline(L,b)   { (void)L; (void)b; }
 #endif
 
 #endif
@@ -299,7 +299,7 @@
 ** mean larger pauses which mean slower collection.) You can also change
 ** this value dynamically.
 */
-#define LUAI_GCPAUSE	200  /* 200% (wait memory to double before next GC) */
+#define LUAI_GCPAUSE    200  /* 200% (wait memory to double before next GC) */
 
 
 /*
@@ -310,7 +310,7 @@
 ** infinity, where each step performs a full collection.) You can also
 ** change this value dynamically.
 */
-#define LUAI_GCMUL	200 /* GC runs 'twice the speed' of memory allocation */
+#define LUAI_GCMUL  200 /* GC runs 'twice the speed' of memory allocation */
 
 
 
@@ -348,7 +348,7 @@
 ** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
 ** off the advisory error when nesting [[...]].
 */
-#define LUA_COMPAT_LSTR		1
+#define LUA_COMPAT_LSTR     1
 
 /*
 @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
@@ -376,9 +376,9 @@
 */
 #if defined(LUA_USE_APICHECK)
 #include <assert.h>
-#define luai_apicheck(L,o)	{ (void)L; assert(o); }
+#define luai_apicheck(L,o)  { (void)L; assert(o); }
 #else
-#define luai_apicheck(L,o)	{ (void)L; }
+#define luai_apicheck(L,o)  { (void)L; }
 #endif
 
 
@@ -389,10 +389,10 @@
 */
 /* avoid overflows in comparison */
 #if INT_MAX-20 < 32760
-#define LUAI_BITSINT	16
+#define LUAI_BITSINT    16
 #elif INT_MAX > 2147483640L
 /* int has at least 32 bits */
-#define LUAI_BITSINT	32
+#define LUAI_BITSINT    32
 #else
 #error "you must define LUA_BITSINT with number of bits in an integer"
 #endif
@@ -411,18 +411,18 @@
 ** longs.) Probably you do not need to change this.
 */
 #if LUAI_BITSINT >= 32
-#define LUAI_UINT32	unsigned int
-#define LUAI_INT32	int
-#define LUAI_MAXINT32	INT_MAX
-#define LUAI_UMEM	size_t
-#define LUAI_MEM	ptrdiff_t
+#define LUAI_UINT32 unsigned int
+#define LUAI_INT32  int
+#define LUAI_MAXINT32   INT_MAX
+#define LUAI_UMEM   size_t
+#define LUAI_MEM    ptrdiff_t
 #else
 /* 16-bit ints */
-#define LUAI_UINT32	unsigned long
-#define LUAI_INT32	long
-#define LUAI_MAXINT32	LONG_MAX
-#define LUAI_UMEM	unsigned long
-#define LUAI_MEM	long
+#define LUAI_UINT32 unsigned long
+#define LUAI_INT32  long
+#define LUAI_MAXINT32   LONG_MAX
+#define LUAI_UMEM   unsigned long
+#define LUAI_MEM    long
 #endif
 
 
@@ -432,7 +432,7 @@
 ** arbitrary; its only purpose is to stop infinite recursion before
 ** exhausting memory.
 */
-#define LUAI_MAXCALLS	20000
+#define LUAI_MAXCALLS   20000
 
 
 /*
@@ -443,7 +443,7 @@
 ** functions to consume unlimited stack space. (must be smaller than
 ** -LUA_REGISTRYINDEX)
 */
-#define LUAI_MAXCSTACK	8000
+#define LUAI_MAXCSTACK  8000
 
 
 
@@ -465,27 +465,27 @@
 @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
 @* syntactical nested non-terminals in a program.
 */
-#define LUAI_MAXCCALLS		200
+#define LUAI_MAXCCALLS      200
 
 
 /*
 @@ LUAI_MAXVARS is the maximum number of local variables per function
 @* (must be smaller than 250).
 */
-#define LUAI_MAXVARS		200
+#define LUAI_MAXVARS        200
 
 
 /*
 @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
 @* (must be smaller than 250).
 */
-#define LUAI_MAXUPVALUES	60
+#define LUAI_MAXUPVALUES    60
 
 
 /*
 @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
 */
-#define LUAL_BUFFERSIZE		BUFSIZ
+#define LUAL_BUFFERSIZE     BUFSIZ
 
 /* }================================================================== */
 
@@ -502,13 +502,13 @@
 */
 
 #define LUA_NUMBER_DOUBLE
-#define LUA_NUMBER	double
+#define LUA_NUMBER  double
 
 /*
 @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
 @* over a number.
 */
-#define LUAI_UACNUMBER	double
+#define LUAI_UACNUMBER  double
 
 
 /*
@@ -518,11 +518,11 @@
 @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
 @@ lua_str2number converts a string to a number.
 */
-#define LUA_NUMBER_SCAN		"%lf"
-#define LUA_NUMBER_FMT		"%.14g"
-#define lua_number2str(s,n)	sprintf((s), LUA_NUMBER_FMT, (n))
-#define LUAI_MAXNUMBER2STR	32 /* 16 digits, sign, point, and \0 */
-#define lua_str2number(s,p)	strtod((s), (p))
+#define LUA_NUMBER_SCAN     "%lf"
+#define LUA_NUMBER_FMT      "%.14g"
+#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
+#define LUAI_MAXNUMBER2STR  32 /* 16 digits, sign, point, and \0 */
+#define lua_str2number(s,p) strtod((s), (p))
 
 
 /*
@@ -530,17 +530,17 @@
 */
 #if defined(LUA_CORE)
 #include <math.h>
-#define luai_numadd(a,b)	((a)+(b))
-#define luai_numsub(a,b)	((a)-(b))
-#define luai_nummul(a,b)	((a)*(b))
-#define luai_numdiv(a,b)	((a)/(b))
-#define luai_nummod(a,b)	((a) - floor((a)/(b))*(b))
-#define luai_numpow(a,b)	(pow(a,b))
-#define luai_numunm(a)		(-(a))
-#define luai_numeq(a,b)		((a)==(b))
-#define luai_numlt(a,b)		((a)<(b))
-#define luai_numle(a,b)		((a)<=(b))
-#define luai_numisnan(a)	(!luai_numeq((a), (a)))
+#define luai_numadd(a,b)    ((a)+(b))
+#define luai_numsub(a,b)    ((a)-(b))
+#define luai_nummul(a,b)    ((a)*(b))
+#define luai_numdiv(a,b)    ((a)/(b))
+#define luai_nummod(a,b)    ((a) - floor((a)/(b))*(b))
+#define luai_numpow(a,b)    (pow(a,b))
+#define luai_numunm(a)      (-(a))
+#define luai_numeq(a,b)     ((a)==(b))
+#define luai_numlt(a,b)     ((a)<(b))
+#define luai_numle(a,b)     ((a)<=(b))
+#define luai_numisnan(a)    (!luai_numeq((a), (a)))
 #endif
 
 
@@ -561,7 +561,7 @@
 #if defined(_MSC_VER)
 
 #define lua_number2int(i,d)   __asm fld d   __asm fistp i
-#define lua_number2integer(i,n)		lua_number2int(i, n)
+#define lua_number2integer(i,n)     lua_number2int(i, n)
 
 /* the next trick should work on any Pentium, but sometimes clashes
    with a DirectX idiosyncrasy */
@@ -570,15 +570,15 @@
 union luai_Cast { double l_d; long l_l; };
 #define lua_number2int(i,d) \
   { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
-#define lua_number2integer(i,n)		lua_number2int(i, n)
+#define lua_number2integer(i,n)     lua_number2int(i, n)
 
 #endif
 
 
 /* this option always works, but may be slow */
 #else
-#define lua_number2int(i,d)	((i)=(int)(d))
-#define lua_number2integer(i,d)	((i)=(lua_Integer)(d))
+#define lua_number2int(i,d) ((i)=(int)(d))
+#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
 
 #endif
 
@@ -592,7 +592,7 @@
 ** aligned in 16-byte boundaries, then you should add long double in the
 ** union.) Probably you do not need to change this.
 */
-#define LUAI_USER_ALIGNMENT_T	union { double u; void *s; long l; }
+#define LUAI_USER_ALIGNMENT_T   union { double u; void *s; long l; }
 
 
 /*
@@ -605,22 +605,22 @@
 */
 #if defined(__cplusplus)
 /* C++ exceptions */
-#define LUAI_THROW(L,c)	throw(c)
-#define LUAI_TRY(L,c,a)	try { a } catch(...) \
-	{ if ((c)->status == 0) (c)->status = -1; }
-#define luai_jmpbuf	int  /* dummy variable */
+#define LUAI_THROW(L,c) throw(c)
+#define LUAI_TRY(L,c,a) try { a } catch(...) \
+    { if ((c)->status == 0) (c)->status = -1; }
+#define luai_jmpbuf int  /* dummy variable */
 
 #elif defined(LUA_USE_ULONGJMP)
 /* in Unix, try _longjmp/_setjmp (more efficient) */
-#define LUAI_THROW(L,c)	_longjmp((c)->b, 1)
-#define LUAI_TRY(L,c,a)	if (_setjmp((c)->b) == 0) { a }
-#define luai_jmpbuf	jmp_buf
+#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
+#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
+#define luai_jmpbuf jmp_buf
 
 #else
 /* default handling with long jumps */
-#define LUAI_THROW(L,c)	longjmp((c)->b, 1)
-#define LUAI_TRY(L,c,a)	if (setjmp((c)->b) == 0) { a }
-#define luai_jmpbuf	jmp_buf
+#define LUAI_THROW(L,c) longjmp((c)->b, 1)
+#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
+#define luai_jmpbuf jmp_buf
 
 #endif
 
@@ -630,7 +630,7 @@
 @* can do during pattern-matching.
 ** CHANGE it if you need more captures. This limit is arbitrary.
 */
-#define LUA_MAXCAPTURES		32
+#define LUA_MAXCAPTURES     32
 
 
 /*
@@ -645,16 +645,16 @@
 
 #if defined(LUA_USE_MKSTEMP)
 #include <unistd.h>
-#define LUA_TMPNAMBUFSIZE	32
-#define lua_tmpnam(b,e)	{ \
-	strcpy(b, "/tmp/lua_XXXXXX"); \
-	e = mkstemp(b); \
-	if (e != -1) close(e); \
-	e = (e == -1); }
+#define LUA_TMPNAMBUFSIZE   32
+#define lua_tmpnam(b,e) { \
+    strcpy(b, "/tmp/lua_XXXXXX"); \
+    e = mkstemp(b); \
+    if (e != -1) close(e); \
+    e = (e == -1); }
 
 #else
-#define LUA_TMPNAMBUFSIZE	L_tmpnam
-#define lua_tmpnam(b,e)		{ e = (tmpnam(b) == NULL); }
+#define LUA_TMPNAMBUFSIZE   L_tmpnam
+#define lua_tmpnam(b,e)     { e = (tmpnam(b) == NULL); }
 #endif
 
 #endif
@@ -667,19 +667,19 @@
 */
 #if defined(LUA_USE_POPEN)
 
-#define lua_popen(L,c,m)	((void)L, fflush(NULL), popen(c,m))
-#define lua_pclose(L,file)	((void)L, (pclose(file) != -1))
+#define lua_popen(L,c,m)    ((void)L, fflush(NULL), popen(c,m))
+#define lua_pclose(L,file)  ((void)L, (pclose(file) != -1))
 
 #elif defined(LUA_WIN)
 
-#define lua_popen(L,c,m)	((void)L, _popen(c,m))
-#define lua_pclose(L,file)	((void)L, (_pclose(file) != -1))
+#define lua_popen(L,c,m)    ((void)L, _popen(c,m))
+#define lua_pclose(L,file)  ((void)L, (_pclose(file) != -1))
 
 #else
 
-#define lua_popen(L,c,m)	((void)((void)c, m),  \
-		luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
-#define lua_pclose(L,file)		((void)((void)L, file), 0)
+#define lua_popen(L,c,m)    ((void)((void)c, m),  \
+        luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
+#define lua_pclose(L,file)      ((void)((void)L, file), 0)
 
 #endif
 
@@ -712,7 +712,7 @@
 ** CHANGE (define) this if you really need that. This value must be
 ** a multiple of the maximum alignment required for your machine.
 */
-#define LUAI_EXTRASPACE		0
+#define LUAI_EXTRASPACE     0
 
 
 /*
@@ -720,12 +720,12 @@
 ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
 ** extra when a thread is created/deleted/resumed/yielded.
 */
-#define luai_userstateopen(L)		((void)L)
-#define luai_userstateclose(L)		((void)L)
-#define luai_userstatethread(L,L1)	((void)L)
-#define luai_userstatefree(L)		((void)L)
-#define luai_userstateresume(L,n)	((void)L)
-#define luai_userstateyield(L,n)	((void)L)
+#define luai_userstateopen(L)       ((void)L)
+#define luai_userstateclose(L)      ((void)L)
+#define luai_userstatethread(L,L1)  ((void)L)
+#define luai_userstatefree(L)       ((void)L)
+#define luai_userstateresume(L,n)   ((void)L)
+#define luai_userstateyield(L,n)    ((void)L)
 
 
 /*
@@ -738,13 +738,13 @@
 
 #if defined(LUA_USELONGLONG)
 
-#define LUA_INTFRMLEN		"ll"
-#define LUA_INTFRM_T		long long
+#define LUA_INTFRMLEN       "ll"
+#define LUA_INTFRM_T        long long
 
 #else
 
-#define LUA_INTFRMLEN		"l"
-#define LUA_INTFRM_T		long
+#define LUA_INTFRMLEN       "l"
+#define LUA_INTFRM_T        long
 
 #endif
 
--- a/misc/liblua/lualib.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lualib.h	Tue Jan 21 22:53:15 2014 +0100
@@ -12,31 +12,31 @@
 
 
 /* Key to file-handle type */
-#define LUA_FILEHANDLE		"FILE*"
+#define LUA_FILEHANDLE      "FILE*"
 
 
-#define LUA_COLIBNAME	"coroutine"
+#define LUA_COLIBNAME   "coroutine"
 LUALIB_API int (luaopen_base) (lua_State *L);
 
-#define LUA_TABLIBNAME	"table"
+#define LUA_TABLIBNAME  "table"
 LUALIB_API int (luaopen_table) (lua_State *L);
 
-#define LUA_IOLIBNAME	"io"
+#define LUA_IOLIBNAME   "io"
 LUALIB_API int (luaopen_io) (lua_State *L);
 
-#define LUA_OSLIBNAME	"os"
+#define LUA_OSLIBNAME   "os"
 LUALIB_API int (luaopen_os) (lua_State *L);
 
-#define LUA_STRLIBNAME	"string"
+#define LUA_STRLIBNAME  "string"
 LUALIB_API int (luaopen_string) (lua_State *L);
 
-#define LUA_MATHLIBNAME	"math"
+#define LUA_MATHLIBNAME "math"
 LUALIB_API int (luaopen_math) (lua_State *L);
 
-#define LUA_DBLIBNAME	"debug"
+#define LUA_DBLIBNAME   "debug"
 LUALIB_API int (luaopen_debug) (lua_State *L);
 
-#define LUA_LOADLIBNAME	"package"
+#define LUA_LOADLIBNAME "package"
 LUALIB_API int (luaopen_package) (lua_State *L);
 
 
@@ -46,7 +46,7 @@
 
 
 #ifndef lua_assert
-#define lua_assert(x)	((void)0)
+#define lua_assert(x)   ((void)0)
 #endif
 
 
--- a/misc/liblua/lundump.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lundump.c	Tue Jan 21 22:53:15 2014 +0100
@@ -31,7 +31,7 @@
 #define IF(c,s)
 #define error(S,s)
 #else
-#define IF(c,s)		if (c) error(S,s)
+#define IF(c,s)     if (c) error(S,s)
 
 static void error(LoadState* S, const char* why)
 {
@@ -40,10 +40,10 @@
 }
 #endif
 
-#define LoadMem(S,b,n,size)	LoadBlock(S,b,(n)*(size))
-#define	LoadByte(S)		(lu_byte)LoadChar(S)
-#define LoadVar(S,x)		LoadMem(S,&x,1,sizeof(x))
-#define LoadVector(S,b,n,size)	LoadMem(S,b,n,size)
+#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
+#define LoadByte(S)     (lu_byte)LoadChar(S)
+#define LoadVar(S,x)        LoadMem(S,&x,1,sizeof(x))
+#define LoadVector(S,b,n,size)  LoadMem(S,b,n,size)
 
 static void LoadBlock(LoadState* S, void* b, size_t size)
 {
@@ -83,7 +83,7 @@
  {
   char* s=luaZ_openspace(S->L,S->b,size);
   LoadBlock(S,s,size);
-  return luaS_newlstr(S->L,s,size-1);		/* remove trailing '\0' */
+  return luaS_newlstr(S->L,s,size-1);       /* remove trailing '\0' */
  }
 }
 
@@ -111,20 +111,20 @@
   switch (t)
   {
    case LUA_TNIL:
-   	setnilvalue(o);
-	break;
+    setnilvalue(o);
+    break;
    case LUA_TBOOLEAN:
-   	setbvalue(o,LoadChar(S)!=0);
-	break;
+    setbvalue(o,LoadChar(S)!=0);
+    break;
    case LUA_TNUMBER:
-	setnvalue(o,LoadNumber(S));
-	break;
+    setnvalue(o,LoadNumber(S));
+    break;
    case LUA_TSTRING:
-	setsvalue2n(S->L,o,LoadString(S));
-	break;
+    setsvalue2n(S->L,o,LoadString(S));
+    break;
    default:
-	error(S,"bad constant");
-	break;
+    error(S,"bad constant");
+    break;
   }
  }
  n=LoadInt(S);
@@ -218,10 +218,10 @@
  h+=sizeof(LUA_SIGNATURE)-1;
  *h++=(char)LUAC_VERSION;
  *h++=(char)LUAC_FORMAT;
- *h++=(char)*(char*)&x;				/* endianness */
+ *h++=(char)*(char*)&x;             /* endianness */
  *h++=(char)sizeof(int);
  *h++=(char)sizeof(size_t);
  *h++=(char)sizeof(Instruction);
  *h++=(char)sizeof(lua_Number);
- *h++=(char)(((lua_Number)0.5)==0);		/* is lua_Number integral? */
+ *h++=(char)(((lua_Number)0.5)==0);     /* is lua_Number integral? */
 }
--- a/misc/liblua/lundump.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lundump.h	Tue Jan 21 22:53:15 2014 +0100
@@ -25,12 +25,12 @@
 #endif
 
 /* for header of binary files -- this is Lua 5.1 */
-#define LUAC_VERSION		0x51
+#define LUAC_VERSION        0x51
 
 /* for header of binary files -- this is the official format */
-#define LUAC_FORMAT		0
+#define LUAC_FORMAT     0
 
 /* size of header of binary files */
-#define LUAC_HEADERSIZE		12
+#define LUAC_HEADERSIZE     12
 
 #endif
--- a/misc/liblua/lvm.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lvm.c	Tue Jan 21 22:53:15 2014 +0100
@@ -29,7 +29,7 @@
 
 
 /* limit for table tag-method chains (to avoid loops) */
-#define MAXTAGLOOP	100
+#define MAXTAGLOOP  100
 
 
 const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
@@ -338,23 +338,23 @@
 ** some macros for common tasks in `luaV_execute'
 */
 
-#define runtime_check(L, c)	{ if (!(c)) break; }
+#define runtime_check(L, c) { if (!(c)) break; }
 
-#define RA(i)	(base+GETARG_A(i))
+#define RA(i)   (base+GETARG_A(i))
 /* to be used after possible stack reallocation */
-#define RB(i)	check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
-#define RC(i)	check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
-#define RKB(i)	check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
-	ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))
-#define RKC(i)	check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
-	ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))
-#define KBx(i)	check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))
+#define RB(i)   check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
+#define RC(i)   check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
+#define RKB(i)  check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
+    ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))
+#define RKC(i)  check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
+    ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))
+#define KBx(i)  check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))
 
 
-#define dojump(L,pc,i)	{(pc) += (i); luai_threadyield(L);}
+#define dojump(L,pc,i)  {(pc) += (i); luai_threadyield(L);}
 
 
-#define Protect(x)	{ L->savedpc = pc; {x;}; base = L->base; }
+#define Protect(x)  { L->savedpc = pc; {x;}; base = L->base; }
 
 
 #define arith_op(op,tm) { \
--- a/misc/liblua/lvm.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lvm.h	Tue Jan 21 22:53:15 2014 +0100
@@ -15,11 +15,11 @@
 
 #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))
 
-#define tonumber(o,n)	(ttype(o) == LUA_TNUMBER || \
+#define tonumber(o,n)   (ttype(o) == LUA_TNUMBER || \
                          (((o) = luaV_tonumber(o,n)) != NULL))
 
 #define equalobj(L,o1,o2) \
-	(ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
+    (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
 
 
 LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
--- a/misc/liblua/lzio.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/lzio.h	Tue Jan 21 22:53:15 2014 +0100
@@ -13,11 +13,11 @@
 #include "lmem.h"
 
 
-#define EOZ	(-1)			/* end of stream */
+#define EOZ (-1)            /* end of stream */
 
 typedef struct Zio ZIO;
 
-#define char2int(c)	cast(int, cast(unsigned char, (c)))
+#define char2int(c) cast(int, cast(unsigned char, (c)))
 
 #define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))
 
@@ -29,24 +29,24 @@
 
 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
 
-#define luaZ_buffer(buff)	((buff)->buffer)
-#define luaZ_sizebuffer(buff)	((buff)->buffsize)
-#define luaZ_bufflen(buff)	((buff)->n)
+#define luaZ_buffer(buff)   ((buff)->buffer)
+#define luaZ_sizebuffer(buff)   ((buff)->buffsize)
+#define luaZ_bufflen(buff)  ((buff)->n)
 
 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
 
 
 #define luaZ_resizebuffer(L, buff, size) \
-	(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
-	(buff)->buffsize = size)
+    (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
+    (buff)->buffsize = size)
 
-#define luaZ_freebuffer(L, buff)	luaZ_resizebuffer(L, buff, 0)
+#define luaZ_freebuffer(L, buff)    luaZ_resizebuffer(L, buff, 0)
 
 
 LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
                                         void *data);
-LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n);	/* read next n bytes */
+LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
 LUAI_FUNC int luaZ_lookahead (ZIO *z);
 
 
@@ -54,11 +54,11 @@
 /* --------- Private Part ------------------ */
 
 struct Zio {
-  size_t n;			/* bytes still unread */
-  const char *p;		/* current position in buffer */
+  size_t n;         /* bytes still unread */
+  const char *p;        /* current position in buffer */
   lua_Reader reader;
-  void* data;			/* additional data */
-  lua_State *L;			/* Lua state (for reader) */
+  void* data;           /* additional data */
+  lua_State *L;         /* Lua state (for reader) */
 };
 
 
--- a/misc/liblua/print.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/liblua/print.c	Tue Jan 21 22:53:15 2014 +0100
@@ -15,10 +15,10 @@
 #include "lopcodes.h"
 #include "lundump.h"
 
-#define PrintFunction	luaU_print
+#define PrintFunction   luaU_print
 
-#define Sizeof(x)	((int)sizeof(x))
-#define VOID(p)		((const void*)(p))
+#define Sizeof(x)   ((int)sizeof(x))
+#define VOID(p)     ((const void*)(p))
 
 static void PrintString(const TString* ts)
 {
@@ -39,10 +39,10 @@
    case '\r': printf("\\r"); break;
    case '\t': printf("\\t"); break;
    case '\v': printf("\\v"); break;
-   default:	if (isprint((unsigned char)c))
-   			putchar(c);
-		else
-			printf("\\%03u",(unsigned char)c);
+   default: if (isprint((unsigned char)c))
+            putchar(c);
+        else
+            printf("\\%03u",(unsigned char)c);
   }
  }
  putchar('"');
@@ -54,20 +54,20 @@
  switch (ttype(o))
  {
   case LUA_TNIL:
-	printf("nil");
-	break;
+    printf("nil");
+    break;
   case LUA_TBOOLEAN:
-	printf(bvalue(o) ? "true" : "false");
-	break;
+    printf(bvalue(o) ? "true" : "false");
+    break;
   case LUA_TNUMBER:
-	printf(LUA_NUMBER_FMT,nvalue(o));
-	break;
+    printf(LUA_NUMBER_FMT,nvalue(o));
+    break;
   case LUA_TSTRING:
-	PrintString(rawtsvalue(o));
-	break;
-  default:				/* cannot happen */
-	printf("? type=%d",ttype(o));
-	break;
+    PrintString(rawtsvalue(o));
+    break;
+  default:              /* cannot happen */
+    printf("? type=%d",ttype(o));
+    break;
  }
 }
 
@@ -155,8 +155,8 @@
  }
 }
 
-#define SS(x)	(x==1)?"":"s"
-#define S(x)	x,SS(x)
+#define SS(x)   (x==1)?"":"s"
+#define S(x)    x,SS(x)
 
 static void PrintHeader(const Proto* f)
 {
@@ -168,14 +168,14 @@
  else
   s="(string)";
  printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
- 	(f->linedefined==0)?"main":"function",s,
-	f->linedefined,f->lastlinedefined,
-	S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
+    (f->linedefined==0)?"main":"function",s,
+    f->linedefined,f->lastlinedefined,
+    S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
  printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
-	f->numparams,f->is_vararg?"+":"",SS(f->numparams),
-	S(f->maxstacksize),S(f->nups));
+    f->numparams,f->is_vararg?"+":"",SS(f->numparams),
+    S(f->maxstacksize),S(f->nups));
  printf("%d local%s, %d constant%s, %d function%s\n",
-	S(f->sizelocvars),S(f->sizek),S(f->sizep));
+    S(f->sizelocvars),S(f->sizek),S(f->sizep));
 }
 
 static void PrintConstants(const Proto* f)
--- a/misc/libphysfs/archiver_unpacked.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/archiver_unpacked.c	Tue Jan 21 22:53:15 2014 +0100
@@ -200,7 +200,7 @@
                 rc = -1;
             else if (ch > '/')
                 rc = 1;
-            else 
+            else
             {
                 if (stop_on_first_find) /* Just checking dir's existance? */
                     return middle;
@@ -293,7 +293,7 @@
 
 /*
  * This will find the UNPKentry associated with a path in platform-independent
- *  notation. Directories don't have UNPKentries associated with them, but 
+ *  notation. Directories don't have UNPKentries associated with them, but
  *  (*isDir) will be set to non-zero if a dir was hit.
  */
 static UNPKentry *findEntry(const UNPKinfo *info, const char *path, int *isDir)
--- a/misc/libphysfs/archiver_wad.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/archiver_wad.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,7 +1,7 @@
 /*
  * WAD support routines for PhysicsFS.
  *
- * This driver handles DOOM engine archives ("wads"). 
+ * This driver handles DOOM engine archives ("wads").
  * This format (but not this driver) was designed by id Software for use
  *  with the DOOM engine.
  * The specs of the format are from the unofficial doom specs v1.666
@@ -28,7 +28,7 @@
  *    (c) an 8-byte ASCII string, the name of the lump, padded with zeros.
  *        For example, the "DEMO1" entry in hexadecimal would be
  *        (44 45 4D 4F 31 00 00 00)
- * 
+ *
  * Note that there is no way to tell if an opened WAD archive is a
  *  IWAD or PWAD with this archiver.
  * I couldn't think of a way to provide that information, without being too
--- a/misc/libphysfs/archiver_zip.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/archiver_zip.c	Tue Jan 21 22:53:15 2014 +0100
@@ -488,7 +488,7 @@
                 (buf[i + 3] == 0x06) )
             {
                 found = 1;  /* that's the signature! */
-                break;  
+                break;
             } /* if */
         } /* for */
 
@@ -552,7 +552,7 @@
 
 /*
  * This will find the ZIPentry associated with a path in platform-independent
- *  notation. Directories don't have ZIPentries associated with them, but 
+ *  notation. Directories don't have ZIPentries associated with them, but
  *  (*isDir) will be set to non-zero if a dir was hit.
  */
 static ZIPentry *zip_find_entry(const ZIPinfo *info, const char *path,
@@ -724,7 +724,7 @@
 
     path = (char *) __PHYSFS_smallAlloc(size + 1);
     BAIL_IF_MACRO(!path, PHYSFS_ERR_OUT_OF_MEMORY, 0);
-    
+
     if (entry->compression_method == COMPMETH_NONE)
         rc = __PHYSFS_readAll(io, path, size);
 
@@ -1445,7 +1445,7 @@
                 rc = -1;
             else if ('/' > ch)
                 rc = 1;
-            else 
+            else
             {
                 if (stop_on_first_find) /* Just checking dir's existance? */
                     return middle;
--- a/misc/libphysfs/physfs.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/physfs.c	Tue Jan 21 22:53:15 2014 +0100
@@ -486,7 +486,7 @@
     memcpy(retval, io, sizeof (PHYSFS_Io));
     retval->opaque = newfh;
     return retval;
-    
+
 handleIo_dupe_failed:
     if (newfh)
     {
--- a/misc/libphysfs/physfs.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/physfs.h	Tue Jan 21 22:53:15 2014 +0100
@@ -128,9 +128,9 @@
  *
  * PhysicsFS is mostly thread safe. The error messages returned by
  *  PHYSFS_getLastError() are unique by thread, and library-state-setting
- *  functions are mutex'd. For efficiency, individual file accesses are 
- *  not locked, so you can not safely read/write/seek/close/etc the same 
- *  file from two threads at the same time. Other race conditions are bugs 
+ *  functions are mutex'd. For efficiency, individual file accesses are
+ *  not locked, so you can not safely read/write/seek/close/etc the same
+ *  file from two threads at the same time. Other race conditions are bugs
  *  that should be reported/patched.
  *
  * While you CAN use stdio/syscall file access in a program that has PHYSFS_*
@@ -2604,10 +2604,10 @@
  */
 typedef enum PHYSFS_FileType
 {
-	PHYSFS_FILETYPE_REGULAR, /**< a normal file */
-	PHYSFS_FILETYPE_DIRECTORY, /**< a directory */
-	PHYSFS_FILETYPE_SYMLINK, /**< a symlink */
-	PHYSFS_FILETYPE_OTHER /**< something completely different like a device */
+    PHYSFS_FILETYPE_REGULAR, /**< a normal file */
+    PHYSFS_FILETYPE_DIRECTORY, /**< a directory */
+    PHYSFS_FILETYPE_SYMLINK, /**< a symlink */
+    PHYSFS_FILETYPE_OTHER /**< something completely different like a device */
 } PHYSFS_FileType;
 
 /**
@@ -2628,12 +2628,12 @@
  */
 typedef struct PHYSFS_Stat
 {
-	PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */
-	PHYSFS_sint64 modtime;  /**< last modification time */
-	PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
-	PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
-	PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
-	int readonly; /**< non-zero if read only, zero if writable. */
+    PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */
+    PHYSFS_sint64 modtime;  /**< last modification time */
+    PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
+    PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
+    PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
+    int readonly; /**< non-zero if read only, zero if writable. */
 } PHYSFS_Stat;
 
 /**
--- a/misc/libphysfs/physfs_internal.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/physfs_internal.h	Tue Jan 21 22:53:15 2014 +0100
@@ -726,12 +726,12 @@
 /*
  * Grab possession of a platform-specific mutex. Mutexes should be recursive;
  *  that is, the same thread should be able to call this function multiple
- *  times in a row without causing a deadlock. This function should block 
+ *  times in a row without causing a deadlock. This function should block
  *  until a thread can gain possession of the mutex.
  *
- * Return non-zero if the mutex was grabbed, zero if there was an 
- *  unrecoverable problem grabbing it (this should not be a matter of 
- *  timing out! We're talking major system errors; block until the mutex 
+ * Return non-zero if the mutex was grabbed, zero if there was an
+ *  unrecoverable problem grabbing it (this should not be a matter of
+ *  timing out! We're talking major system errors; block until the mutex
  *  is available otherwise.)
  *
  * _DO NOT_ call __PHYSFS_setError() in here! Since setError calls this
@@ -741,7 +741,7 @@
 int __PHYSFS_platformGrabMutex(void *mutex);
 
 /*
- * Relinquish possession of the mutex when this method has been called 
+ * Relinquish possession of the mutex when this method has been called
  *  once for each time that platformGrabMutex was called. Once possession has
  *  been released, the next thread in line to grab the mutex (if any) may
  *  proceed.
--- a/misc/libphysfs/physfs_miniz.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/physfs_miniz.h	Tue Jan 21 22:53:15 2014 +0100
@@ -12,7 +12,7 @@
 typedef PHYSFS_sint16 mz_int16;
 typedef PHYSFS_uint16 mz_uint16;
 typedef PHYSFS_uint32 mz_uint32;
-typedef unsigned int mz_uint; 
+typedef unsigned int mz_uint;
 typedef PHYSFS_uint64 mz_uint64;
 
 /* For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. */
@@ -670,7 +670,7 @@
 
 #endif /* #ifndef TINFL_HEADER_FILE_ONLY */
 
-/* 
+/*
   This is free and unencumbered software released into the public domain.
 
   Anyone is free to copy, modify, publish, use, compile, sell, or
--- a/misc/libphysfs/platform_macosx.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/platform_macosx.c	Tue Jan 21 22:53:15 2014 +0100
@@ -38,7 +38,7 @@
    doesn't work; once a symbol is marked as hidden, it stays that way.  */
 
 void __eprintf (const char *string, const char *expression,
-	        unsigned int line, const char *filename)
+            unsigned int line, const char *filename)
 {
     fprintf(stderr, string, expression, line, filename);
     fflush(stderr);
@@ -144,7 +144,7 @@
 
     if (!IOObjectConformsTo(service, kIOMediaClass))
         return 0;
-        
+
     wholeMedia = IORegistryEntryCreateCFProperty(service,
                                                  CFSTR(kIOMediaWholeKey),
                                                  cfallocator, 0);
@@ -180,7 +180,7 @@
 
     rc = IORegistryEntryCreateIterator(service, kIOServicePlane,
              kIORegistryIterateRecursively | kIORegistryIterateParents, &iter);
-    
+
     if (!iter)
         return 0;
 
@@ -204,7 +204,7 @@
         } /* if */
         IOObjectRelease(service);
     } while ((service = IOIteratorNext(iter)) && (!retval));
-                
+
     IOObjectRelease(iter);
     IOObjectRelease(service);
 
--- a/misc/libphysfs/platform_posix.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/platform_posix.c	Tue Jan 21 22:53:15 2014 +0100
@@ -83,7 +83,7 @@
             } /* if */
         } /* if */
     } /* if */
-    
+
     return retval;
 } /* getUserDirByUID */
 
--- a/misc/libphysfs/platform_windows.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphysfs/platform_windows.c	Tue Jan 21 22:53:15 2014 +0100
@@ -171,7 +171,7 @@
         stem(SEM_FAILCRITICALERRORS, &oldErrorMode);
     else
         oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
-    
+
     /* Do detection. This may block if a disc is spinning up. */
     for (i = 'A'; i <= 'Z'; i++)
     {
@@ -443,7 +443,7 @@
          *  psize. Also note that the second parameter can't be
          *  NULL or the function fails.
          */
-    	rc = pGetDir(accessToken, &dummy, &psize);
+        rc = pGetDir(accessToken, &dummy, &psize);
         assert(!rc);  /* !!! FIXME: handle this gracefully. */
         (void) rc;
 
@@ -481,7 +481,7 @@
 
 static int isSymlinkAttrs(const DWORD attr, const DWORD tag)
 {
-    return ( (attr & FILE_ATTRIBUTE_REPARSE_POINT) && 
+    return ( (attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
              (tag == PHYSFS_IO_REPARSE_TAG_SYMLINK) );
 } /* isSymlinkAttrs */
 
@@ -720,7 +720,7 @@
     {
         BAIL_MACRO(errcodeFromWinApi(), 0);
     } /* if */
-    
+
     return 1;  /* No error occured */
 } /* __PHYSFS_platformSeek */
 
--- a/misc/libphyslayer/CMakeLists.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphyslayer/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -4,8 +4,7 @@
 include_directories(${SDL_INCLUDE_DIR})
 include_directories(${LUA_INCLUDE_DIR})
 
-## extra functions needed by Hedgewars
-## TODO: maybe it's better to have them in a separate library?
+
 set(PHYSLAYER_SRCS
     physfscompat.c
     physfsrwops.c
--- a/misc/libphyslayer/hwpacksmounter.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphyslayer/hwpacksmounter.h	Tue Jan 21 22:53:15 2014 +0100
@@ -2,8 +2,8 @@
 #define HEDGEWARS_PACKAGES_MOUNTER_H
 
 #include "physfs.h"
-
 #include "physfscompat.h"
+#include "lua.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -12,6 +12,9 @@
 PHYSFS_DECL void hedgewarsMountPackages();
 PHYSFS_DECL void hedgewarsMountPackage(char * fileName);
 
+PHYSFS_DECL const char * physfsReader(lua_State *L, PHYSFS_File *f, size_t *size);
+PHYSFS_DECL void physfsReaderSetBuffer(void *buffer);
+
 #ifdef __cplusplus
 }
 #endif
--- a/misc/libphyslayer/physfscompat.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphyslayer/physfscompat.h	Tue Jan 21 22:53:15 2014 +0100
@@ -34,20 +34,20 @@
 
 typedef enum PHYSFS_FileType
 {
-	PHYSFS_FILETYPE_REGULAR,
-	PHYSFS_FILETYPE_DIRECTORY,
-	PHYSFS_FILETYPE_SYMLINK,
-	PHYSFS_FILETYPE_OTHER
+    PHYSFS_FILETYPE_REGULAR,
+    PHYSFS_FILETYPE_DIRECTORY,
+    PHYSFS_FILETYPE_SYMLINK,
+    PHYSFS_FILETYPE_OTHER
 } PHYSFS_FileType;
 
 typedef struct PHYSFS_Stat
 {
-	PHYSFS_sint64 filesize;
-	PHYSFS_sint64 modtime;
-	PHYSFS_sint64 createtime;
-	PHYSFS_sint64 accesstime;
-	PHYSFS_FileType filetype;
-	int readonly;
+    PHYSFS_sint64 filesize;
+    PHYSFS_sint64 modtime;
+    PHYSFS_sint64 createtime;
+    PHYSFS_sint64 accesstime;
+    PHYSFS_FileType filetype;
+    int readonly;
 } PHYSFS_Stat;
 
 PHYSFS_DECL int PHYSFS_stat(const char *fname, PHYSFS_Stat *stat);
--- a/misc/libphyslayer/physfsrwops.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/libphyslayer/physfsrwops.c	Tue Jan 21 22:53:15 2014 +0100
@@ -95,7 +95,7 @@
         SDL_SetError("Attempt to seek past start of file.");
         return -1;
     } /* if */
-    
+
     if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
     {
         SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
--- a/misc/theme_editor.html	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/theme_editor.html	Tue Jan 21 22:53:15 2014 +0100
@@ -7,113 +7,113 @@
             var skyColor, waterTopColor, waterBottomColor;
             var elements = 7;
             var landArray;
-            
+
             function landFunction(x){
                 return 384 - 192 * Math.sin(x * Math.PI/512);
             }
-            
+
             function tryToDraw(){
                 if (--elements <= 0) {
                     draw();
                 }
             }
-        
+
             function load(){
                     var canvas = document.getElementById('preview');
                     if (canvas.getContext){
                         var ctx = canvas.getContext('2d');
-                    
+
                         ctx.fillStyle = '#0b294b';
                         ctx.fillRect(0, 0, 512, 384);
-                        
+
                         ctx.font = "40pt Arial";
                         ctx.fillStyle = '#2b7bd5';
                         ctx.fillText('Loading Images...', 32, 212);
                     }
-                    
+
                     sky = new Image();
                     sky.onload = tryToDraw;
                     sky.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/Sky.png';
-          
+
                     clouds = new Image();
                     clouds.onload = tryToDraw;
                     clouds.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Graphics/Clouds.png';
-          
+
                     horizont = new Image();
                     horizont.onload = tryToDraw;
                     horizont.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/horizont.png';
-          
+
                     land = new Image();
                     land.onload = tryToDraw;
                     land.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/LandTex.png';
-          
+
                     border = new Image();
                     border.onload = tryToDraw;
                     border.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/Border.png';
-          
+
                     water = new Image();
                     water.onload = tryToDraw;
                     water.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Graphics/BlueWater.png';
-                    
+
                     landArray = new Array(512);
                     for (var x = 0; x < landArray.length; x++)
                         landArray[x] = landFunction(x);
-                    
+
                     skyColor = '#131252';
                     document.getElementById('skyColor').value = skyColor;
-                    
+
                     waterTopColor = '#555C9D';
                     document.getElementById('waterTopColor').value = waterTopColor;
-                    
+
                     waterBottomColor = '#343C7D';
                     document.getElementById('waterBottomColor').value = waterBottomColor;
-                    
+
                     tryToDraw();
             }
-            
+
             function draw(){
                 var canvas = document.getElementById('preview');
                 if (canvas.getContext){
                     var ctx = canvas.getContext('2d');
-                    
+
                     ctx.fillStyle = skyColor;
                     ctx.fillRect(0, 0, 512, 384);
-                    
+
                     ctx.drawImage(sky, 0, 64, 512, 256);
-          
+
                     for (var i = 0; i < 4; i++)
                         ctx.drawImage(clouds, 0, i * 128, 256, 128, i * 128, 64, 128, 64);
-          
+
                     ctx.drawImage(horizont, 0, 192, 512, 128);
-                    
+
                     ctx.save();
-                    
+
                     ctx.beginPath();
                     ctx.moveTo(0, 384);
                     for (var x = 0; x < landArray.length; x++)
                         ctx.lineTo(x, landArray[x]);
                     ctx.clip();
-                    
+
                     for (var i = 0; i < 2; i++)
-                    	for (var k = 0; k < 2; k++)
-                    		ctx.drawImage(land, i * 320, k * 240, 320, 240);
-                    
+                        for (var k = 0; k < 2; k++)
+                            ctx.drawImage(land, i * 320, k * 240, 320, 240);
+
                     ctx.restore();
-                    
+
                     var k = 0;
                     for (var x = 0; x < landArray.length; x++) {
                         if (++k == 64)
                             k = 0;
                         ctx.drawImage(border, k, 0, 2, 16, x, landArray[x] - 4, 1, 8);
                     }
-                        
-                    
+
+
                     var gradient = ctx.createLinearGradient(0, 320, 0, 384);
                     gradient.addColorStop(0, waterTopColor);
                     gradient.addColorStop(1, waterBottomColor);
                     ctx.fillStyle = gradient;
                     ctx.fillRect(0, 320, 512, 384);
-          
+
                     for (var i = 0; i < 8; i++)
                         ctx.drawImage(water, i * 64, 308, 64, 24);
                 }
--- a/misc/winutils/include/GL/glut.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/GL/glut.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,716 +1,716 @@
-#ifndef __glut_h__
-#define __glut_h__
-
-/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996, 1998. */
-
-/* This program is freely distributable without licensing fees  and is
-   provided without guarantee or warrantee expressed or  implied. This
-   program is -not- in the public domain. */
-
-#if defined(_WIN32)
-
-/* GLUT 3.7 now tries to avoid including <windows.h>
-   to avoid name space pollution, but Win32's <GL/gl.h> 
-   needs APIENTRY and WINGDIAPI defined properly. */
-# if 0
-   /* This would put tons of macros and crap in our clean name space. */
-#  define  WIN32_LEAN_AND_MEAN
-#  include <windows.h>
-# else
-   /* XXX This is from Win32's <windef.h> */
-#  ifndef APIENTRY
-#   define GLUT_APIENTRY_DEFINED
-#   if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__)
-#    define APIENTRY    __stdcall
-#   else
-#    define APIENTRY
-#   endif
-#  endif
-   /* XXX This is from Win32's <winnt.h> */
-#  ifndef CALLBACK
-#   if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) || defined(__LCC__)
-#    define CALLBACK __stdcall
-#   else
-#    define CALLBACK
-#   endif
-#  endif
-   /* XXX Hack for lcc compiler.  It doesn't support __declspec(dllimport), just __stdcall. */
-#  if defined( __LCC__ )
-#   undef WINGDIAPI
-#   define WINGDIAPI __stdcall
-#  else
-   /* XXX This is from Win32's <wingdi.h> and <winnt.h> */
-#   ifndef WINGDIAPI
-#    define GLUT_WINGDIAPI_DEFINED
-#    define WINGDIAPI __declspec(dllimport)
-#   endif
-#  endif
-   /* XXX This is from Win32's <ctype.h> */
-#  ifndef _WCHAR_T_DEFINED
-typedef unsigned short wchar_t;
-#   define _WCHAR_T_DEFINED
-#  endif
-# endif
-
-/* To disable automatic library usage for GLUT, define GLUT_NO_LIB_PRAGMA
-   in your compile preprocessor options. */
-# if !defined(GLUT_BUILDING_LIB) && !defined(GLUT_NO_LIB_PRAGMA)
-#  pragma comment (lib, "winmm.lib")      /* link with Windows MultiMedia lib */
-/* To enable automatic SGI OpenGL for Windows library usage for GLUT,
-   define GLUT_USE_SGI_OPENGL in your compile preprocessor options.  */
-#  ifdef GLUT_USE_SGI_OPENGL
-#   pragma comment (lib, "opengl.lib")    /* link with SGI OpenGL for Windows lib */
-#   pragma comment (lib, "glu.lib")       /* link with SGI OpenGL Utility lib */
-#   pragma comment (lib, "glut.lib")      /* link with Win32 GLUT for SGI OpenGL lib */
-#  else
-#   pragma comment (lib, "opengl32.lib")  /* link with Microsoft OpenGL lib */
-#   pragma comment (lib, "glu32.lib")     /* link with Microsoft OpenGL Utility lib */
-#   pragma comment (lib, "glut32.lib")    /* link with Win32 GLUT lib */
-#  endif
-# endif
-
-/* To disable supression of annoying warnings about floats being promoted
-   to doubles, define GLUT_NO_WARNING_DISABLE in your compile preprocessor
-   options. */
-# ifndef GLUT_NO_WARNING_DISABLE
-#  pragma warning (disable:4244)  /* Disable bogus VC++ 4.2 conversion warnings. */
-#  pragma warning (disable:4305)  /* VC++ 5.0 version of above warning. */
-# endif
-
-/* Win32 has an annoying issue where there are multiple C run-time
-   libraries (CRTs).  If the executable is linked with a different CRT
-   from the GLUT DLL, the GLUT DLL will not share the same CRT static
-   data seen by the executable.  In particular, atexit callbacks registered
-   in the executable will not be called if GLUT calls its (different)
-   exit routine).  GLUT is typically built with the
-   "/MD" option (the CRT with multithreading DLL support), but the Visual
-   C++ linker default is "/ML" (the single threaded CRT).
-
-   One workaround to this issue is requiring users to always link with
-   the same CRT as GLUT is compiled with.  That requires users supply a
-   non-standard option.  GLUT 3.7 has its own built-in workaround where
-   the executable's "exit" function pointer is covertly passed to GLUT.
-   GLUT then calls the executable's exit function pointer to ensure that
-   any "atexit" calls registered by the application are called if GLUT
-   needs to exit.
-
-   Note that the __glut*WithExit routines should NEVER be called directly.
-   To avoid the atexit workaround, #define GLUT_DISABLE_ATEXIT_HACK. */
-
-/* XXX This is from Win32's <process.h> */
-# if !defined(_MSC_VER) && !defined(__cdecl)
-   /* Define __cdecl for non-Microsoft compilers. */
-#  define __cdecl
-#  define GLUT_DEFINED___CDECL
-# endif
-# ifndef _CRTIMP
-#  ifdef _NTSDK
-    /* Definition compatible with NT SDK */
-#   define _CRTIMP
-#  else
-    /* Current definition */
-#   ifdef _DLL
-#    define _CRTIMP __declspec(dllimport)
-#   else
-#    define _CRTIMP
-#   endif
-#  endif
-#  define GLUT_DEFINED__CRTIMP
-# endif
-
-/* GLUT API entry point declarations for Win32. */
-# ifdef GLUT_BUILDING_LIB
-#  define GLUTAPI __declspec(dllexport)
-# else
-#  ifdef _DLL
-#   define GLUTAPI __declspec(dllimport)
-#  else
-#   define GLUTAPI extern
-#  endif
-# endif
-
-/* GLUT callback calling convention for Win32. */
-# define GLUTCALLBACK __cdecl
-
-#endif  /* _WIN32 */
-
-#include <GL/gl.h>
-#include <GL/glu.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined(_WIN32)
-# ifndef GLUT_BUILDING_LIB
-extern _CRTIMP void __cdecl exit(int);
-# endif
-#else
-/* non-Win32 case. */
-/* Define APIENTRY and CALLBACK to nothing if we aren't on Win32. */
-# define APIENTRY
-# define GLUT_APIENTRY_DEFINED
-# define CALLBACK
-/* Define GLUTAPI and GLUTCALLBACK as below if we aren't on Win32. */
-# define GLUTAPI extern
-# define GLUTCALLBACK
-/* Prototype exit for the non-Win32 case (see above). */
-extern void exit(int);
-#endif
-
-/**
- GLUT API revision history:
- 
- GLUT_API_VERSION is updated to reflect incompatible GLUT
- API changes (interface changes, semantic changes, deletions,
- or additions).
- 
- GLUT_API_VERSION=1  First public release of GLUT.  11/29/94
-
- GLUT_API_VERSION=2  Added support for OpenGL/GLX multisampling,
- extension.  Supports new input devices like tablet, dial and button
- box, and Spaceball.  Easy to query OpenGL extensions.
-
- GLUT_API_VERSION=3  glutMenuStatus added.
-
- GLUT_API_VERSION=4  glutInitDisplayString, glutWarpPointer,
- glutBitmapLength, glutStrokeLength, glutWindowStatusFunc, dynamic
- video resize subAPI, glutPostWindowRedisplay, glutKeyboardUpFunc,
- glutSpecialUpFunc, glutIgnoreKeyRepeat, glutSetKeyRepeat,
- glutJoystickFunc, glutForceJoystickFunc (NOT FINALIZED!).
-**/
-#ifndef GLUT_API_VERSION  /* allow this to be overriden */
-#define GLUT_API_VERSION		3
-#endif
-
-/**
- GLUT implementation revision history:
- 
- GLUT_XLIB_IMPLEMENTATION is updated to reflect both GLUT
- API revisions and implementation revisions (ie, bug fixes).
-
- GLUT_XLIB_IMPLEMENTATION=1  mjk's first public release of
- GLUT Xlib-based implementation.  11/29/94
-
- GLUT_XLIB_IMPLEMENTATION=2  mjk's second public release of
- GLUT Xlib-based implementation providing GLUT version 2 
- interfaces.
-
- GLUT_XLIB_IMPLEMENTATION=3  mjk's GLUT 2.2 images. 4/17/95
-
- GLUT_XLIB_IMPLEMENTATION=4  mjk's GLUT 2.3 images. 6/?/95
-
- GLUT_XLIB_IMPLEMENTATION=5  mjk's GLUT 3.0 images. 10/?/95
-
- GLUT_XLIB_IMPLEMENTATION=7  mjk's GLUT 3.1+ with glutWarpPoitner.  7/24/96
-
- GLUT_XLIB_IMPLEMENTATION=8  mjk's GLUT 3.1+ with glutWarpPoitner
- and video resize.  1/3/97
-
- GLUT_XLIB_IMPLEMENTATION=9 mjk's GLUT 3.4 release with early GLUT 4 routines.
-
- GLUT_XLIB_IMPLEMENTATION=11 Mesa 2.5's GLUT 3.6 release.
-
- GLUT_XLIB_IMPLEMENTATION=12 mjk's GLUT 3.6 release with early GLUT 4 routines + signal handling.
-
- GLUT_XLIB_IMPLEMENTATION=13 mjk's GLUT 3.7 beta with GameGLUT support.
-
- GLUT_XLIB_IMPLEMENTATION=14 mjk's GLUT 3.7 beta with f90gl friend interface.
-
- GLUT_XLIB_IMPLEMENTATION=15 mjk's GLUT 3.7 beta sync'ed with Mesa <GL/glut.h>
-**/
-#ifndef GLUT_XLIB_IMPLEMENTATION  /* Allow this to be overriden. */
-#define GLUT_XLIB_IMPLEMENTATION	15
-#endif
-
-/* Display mode bit masks. */
-#define GLUT_RGB			0
-#define GLUT_RGBA			GLUT_RGB
-#define GLUT_INDEX			1
-#define GLUT_SINGLE			0
-#define GLUT_DOUBLE			2
-#define GLUT_ACCUM			4
-#define GLUT_ALPHA			8
-#define GLUT_DEPTH			16
-#define GLUT_STENCIL			32
-#if (GLUT_API_VERSION >= 2)
-#define GLUT_MULTISAMPLE		128
-#define GLUT_STEREO			256
-#endif
-#if (GLUT_API_VERSION >= 3)
-#define GLUT_LUMINANCE			512
-#endif
-
-/* Mouse buttons. */
-#define GLUT_LEFT_BUTTON		0
-#define GLUT_MIDDLE_BUTTON		1
-#define GLUT_RIGHT_BUTTON		2
-
-/* Mouse button  state. */
-#define GLUT_DOWN			0
-#define GLUT_UP				1
-
-#if (GLUT_API_VERSION >= 2)
-/* function keys */
-#define GLUT_KEY_F1			1
-#define GLUT_KEY_F2			2
-#define GLUT_KEY_F3			3
-#define GLUT_KEY_F4			4
-#define GLUT_KEY_F5			5
-#define GLUT_KEY_F6			6
-#define GLUT_KEY_F7			7
-#define GLUT_KEY_F8			8
-#define GLUT_KEY_F9			9
-#define GLUT_KEY_F10			10
-#define GLUT_KEY_F11			11
-#define GLUT_KEY_F12			12
-/* directional keys */
-#define GLUT_KEY_LEFT			100
-#define GLUT_KEY_UP			101
-#define GLUT_KEY_RIGHT			102
-#define GLUT_KEY_DOWN			103
-#define GLUT_KEY_PAGE_UP		104
-#define GLUT_KEY_PAGE_DOWN		105
-#define GLUT_KEY_HOME			106
-#define GLUT_KEY_END			107
-#define GLUT_KEY_INSERT			108
-#endif
-
-/* Entry/exit  state. */
-#define GLUT_LEFT			0
-#define GLUT_ENTERED			1
-
-/* Menu usage  state. */
-#define GLUT_MENU_NOT_IN_USE		0
-#define GLUT_MENU_IN_USE		1
-
-/* Visibility  state. */
-#define GLUT_NOT_VISIBLE		0
-#define GLUT_VISIBLE			1
-
-/* Window status  state. */
-#define GLUT_HIDDEN			0
-#define GLUT_FULLY_RETAINED		1
-#define GLUT_PARTIALLY_RETAINED		2
-#define GLUT_FULLY_COVERED		3
-
-/* Color index component selection values. */
-#define GLUT_RED			0
-#define GLUT_GREEN			1
-#define GLUT_BLUE			2
-
-#if defined(_WIN32)
-/* Stroke font constants (use these in GLUT program). */
-#define GLUT_STROKE_ROMAN		((void*)0)
-#define GLUT_STROKE_MONO_ROMAN		((void*)1)
-
-/* Bitmap font constants (use these in GLUT program). */
-#define GLUT_BITMAP_9_BY_15		((void*)2)
-#define GLUT_BITMAP_8_BY_13		((void*)3)
-#define GLUT_BITMAP_TIMES_ROMAN_10	((void*)4)
-#define GLUT_BITMAP_TIMES_ROMAN_24	((void*)5)
-#if (GLUT_API_VERSION >= 3)
-#define GLUT_BITMAP_HELVETICA_10	((void*)6)
-#define GLUT_BITMAP_HELVETICA_12	((void*)7)
-#define GLUT_BITMAP_HELVETICA_18	((void*)8)
-#endif
-#else
-/* Stroke font opaque addresses (use constants instead in source code). */
-GLUTAPI void *glutStrokeRoman;
-GLUTAPI void *glutStrokeMonoRoman;
-
-/* Stroke font constants (use these in GLUT program). */
-#define GLUT_STROKE_ROMAN		(&glutStrokeRoman)
-#define GLUT_STROKE_MONO_ROMAN		(&glutStrokeMonoRoman)
-
-/* Bitmap font opaque addresses (use constants instead in source code). */
-GLUTAPI void *glutBitmap9By15;
-GLUTAPI void *glutBitmap8By13;
-GLUTAPI void *glutBitmapTimesRoman10;
-GLUTAPI void *glutBitmapTimesRoman24;
-GLUTAPI void *glutBitmapHelvetica10;
-GLUTAPI void *glutBitmapHelvetica12;
-GLUTAPI void *glutBitmapHelvetica18;
-
-/* Bitmap font constants (use these in GLUT program). */
-#define GLUT_BITMAP_9_BY_15		(&glutBitmap9By15)
-#define GLUT_BITMAP_8_BY_13		(&glutBitmap8By13)
-#define GLUT_BITMAP_TIMES_ROMAN_10	(&glutBitmapTimesRoman10)
-#define GLUT_BITMAP_TIMES_ROMAN_24	(&glutBitmapTimesRoman24)
-#if (GLUT_API_VERSION >= 3)
-#define GLUT_BITMAP_HELVETICA_10	(&glutBitmapHelvetica10)
-#define GLUT_BITMAP_HELVETICA_12	(&glutBitmapHelvetica12)
-#define GLUT_BITMAP_HELVETICA_18	(&glutBitmapHelvetica18)
-#endif
-#endif
-
-/* glutGet parameters. */
-#define GLUT_WINDOW_X			((GLenum) 100)
-#define GLUT_WINDOW_Y			((GLenum) 101)
-#define GLUT_WINDOW_WIDTH		((GLenum) 102)
-#define GLUT_WINDOW_HEIGHT		((GLenum) 103)
-#define GLUT_WINDOW_BUFFER_SIZE		((GLenum) 104)
-#define GLUT_WINDOW_STENCIL_SIZE	((GLenum) 105)
-#define GLUT_WINDOW_DEPTH_SIZE		((GLenum) 106)
-#define GLUT_WINDOW_RED_SIZE		((GLenum) 107)
-#define GLUT_WINDOW_GREEN_SIZE		((GLenum) 108)
-#define GLUT_WINDOW_BLUE_SIZE		((GLenum) 109)
-#define GLUT_WINDOW_ALPHA_SIZE		((GLenum) 110)
-#define GLUT_WINDOW_ACCUM_RED_SIZE	((GLenum) 111)
-#define GLUT_WINDOW_ACCUM_GREEN_SIZE	((GLenum) 112)
-#define GLUT_WINDOW_ACCUM_BLUE_SIZE	((GLenum) 113)
-#define GLUT_WINDOW_ACCUM_ALPHA_SIZE	((GLenum) 114)
-#define GLUT_WINDOW_DOUBLEBUFFER	((GLenum) 115)
-#define GLUT_WINDOW_RGBA		((GLenum) 116)
-#define GLUT_WINDOW_PARENT		((GLenum) 117)
-#define GLUT_WINDOW_NUM_CHILDREN	((GLenum) 118)
-#define GLUT_WINDOW_COLORMAP_SIZE	((GLenum) 119)
-#if (GLUT_API_VERSION >= 2)
-#define GLUT_WINDOW_NUM_SAMPLES		((GLenum) 120)
-#define GLUT_WINDOW_STEREO		((GLenum) 121)
-#endif
-#if (GLUT_API_VERSION >= 3)
-#define GLUT_WINDOW_CURSOR		((GLenum) 122)
-#endif
-#define GLUT_SCREEN_WIDTH		((GLenum) 200)
-#define GLUT_SCREEN_HEIGHT		((GLenum) 201)
-#define GLUT_SCREEN_WIDTH_MM		((GLenum) 202)
-#define GLUT_SCREEN_HEIGHT_MM		((GLenum) 203)
-#define GLUT_MENU_NUM_ITEMS		((GLenum) 300)
-#define GLUT_DISPLAY_MODE_POSSIBLE	((GLenum) 400)
-#define GLUT_INIT_WINDOW_X		((GLenum) 500)
-#define GLUT_INIT_WINDOW_Y		((GLenum) 501)
-#define GLUT_INIT_WINDOW_WIDTH		((GLenum) 502)
-#define GLUT_INIT_WINDOW_HEIGHT		((GLenum) 503)
-#define GLUT_INIT_DISPLAY_MODE		((GLenum) 504)
-#if (GLUT_API_VERSION >= 2)
-#define GLUT_ELAPSED_TIME		((GLenum) 700)
-#endif
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
-#define GLUT_WINDOW_FORMAT_ID		((GLenum) 123)
-#endif
-
-#if (GLUT_API_VERSION >= 2)
-/* glutDeviceGet parameters. */
-#define GLUT_HAS_KEYBOARD		((GLenum) 600)
-#define GLUT_HAS_MOUSE			((GLenum) 601)
-#define GLUT_HAS_SPACEBALL		((GLenum) 602)
-#define GLUT_HAS_DIAL_AND_BUTTON_BOX	((GLenum) 603)
-#define GLUT_HAS_TABLET			((GLenum) 604)
-#define GLUT_NUM_MOUSE_BUTTONS		((GLenum) 605)
-#define GLUT_NUM_SPACEBALL_BUTTONS	((GLenum) 606)
-#define GLUT_NUM_BUTTON_BOX_BUTTONS	((GLenum) 607)
-#define GLUT_NUM_DIALS			((GLenum) 608)
-#define GLUT_NUM_TABLET_BUTTONS		((GLenum) 609)
-#endif
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
-#define GLUT_DEVICE_IGNORE_KEY_REPEAT   ((GLenum) 610)
-#define GLUT_DEVICE_KEY_REPEAT          ((GLenum) 611)
-#define GLUT_HAS_JOYSTICK		((GLenum) 612)
-#define GLUT_OWNS_JOYSTICK		((GLenum) 613)
-#define GLUT_JOYSTICK_BUTTONS		((GLenum) 614)
-#define GLUT_JOYSTICK_AXES		((GLenum) 615)
-#define GLUT_JOYSTICK_POLL_RATE		((GLenum) 616)
-#endif
-
-#if (GLUT_API_VERSION >= 3)
-/* glutLayerGet parameters. */
-#define GLUT_OVERLAY_POSSIBLE           ((GLenum) 800)
-#define GLUT_LAYER_IN_USE		((GLenum) 801)
-#define GLUT_HAS_OVERLAY		((GLenum) 802)
-#define GLUT_TRANSPARENT_INDEX		((GLenum) 803)
-#define GLUT_NORMAL_DAMAGED		((GLenum) 804)
-#define GLUT_OVERLAY_DAMAGED		((GLenum) 805)
-
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
-/* glutVideoResizeGet parameters. */
-#define GLUT_VIDEO_RESIZE_POSSIBLE	((GLenum) 900)
-#define GLUT_VIDEO_RESIZE_IN_USE	((GLenum) 901)
-#define GLUT_VIDEO_RESIZE_X_DELTA	((GLenum) 902)
-#define GLUT_VIDEO_RESIZE_Y_DELTA	((GLenum) 903)
-#define GLUT_VIDEO_RESIZE_WIDTH_DELTA	((GLenum) 904)
-#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA	((GLenum) 905)
-#define GLUT_VIDEO_RESIZE_X		((GLenum) 906)
-#define GLUT_VIDEO_RESIZE_Y		((GLenum) 907)
-#define GLUT_VIDEO_RESIZE_WIDTH		((GLenum) 908)
-#define GLUT_VIDEO_RESIZE_HEIGHT	((GLenum) 909)
-#endif
-
-/* glutUseLayer parameters. */
-#define GLUT_NORMAL			((GLenum) 0)
-#define GLUT_OVERLAY			((GLenum) 1)
-
-/* glutGetModifiers return mask. */
-#define GLUT_ACTIVE_SHIFT               1
-#define GLUT_ACTIVE_CTRL                2
-#define GLUT_ACTIVE_ALT                 4
-
-/* glutSetCursor parameters. */
-/* Basic arrows. */
-#define GLUT_CURSOR_RIGHT_ARROW		0
-#define GLUT_CURSOR_LEFT_ARROW		1
-/* Symbolic cursor shapes. */
-#define GLUT_CURSOR_INFO		2
-#define GLUT_CURSOR_DESTROY		3
-#define GLUT_CURSOR_HELP		4
-#define GLUT_CURSOR_CYCLE		5
-#define GLUT_CURSOR_SPRAY		6
-#define GLUT_CURSOR_WAIT		7
-#define GLUT_CURSOR_TEXT		8
-#define GLUT_CURSOR_CROSSHAIR		9
-/* Directional cursors. */
-#define GLUT_CURSOR_UP_DOWN		10
-#define GLUT_CURSOR_LEFT_RIGHT		11
-/* Sizing cursors. */
-#define GLUT_CURSOR_TOP_SIDE		12
-#define GLUT_CURSOR_BOTTOM_SIDE		13
-#define GLUT_CURSOR_LEFT_SIDE		14
-#define GLUT_CURSOR_RIGHT_SIDE		15
-#define GLUT_CURSOR_TOP_LEFT_CORNER	16
-#define GLUT_CURSOR_TOP_RIGHT_CORNER	17
-#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER	18
-#define GLUT_CURSOR_BOTTOM_LEFT_CORNER	19
-/* Inherit from parent window. */
-#define GLUT_CURSOR_INHERIT		100
-/* Blank cursor. */
-#define GLUT_CURSOR_NONE		101
-/* Fullscreen crosshair (if available). */
-#define GLUT_CURSOR_FULL_CROSSHAIR	102
-#endif
-
-/* GLUT initialization sub-API. */
-GLUTAPI void APIENTRY glutInit(int *argcp, char **argv);
-#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
-GLUTAPI void APIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int));
-#ifndef GLUT_BUILDING_LIB
-static void APIENTRY glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }
-#define glutInit glutInit_ATEXIT_HACK
-#endif
-#endif
-GLUTAPI void APIENTRY glutInitDisplayMode(unsigned int mode);
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
-GLUTAPI void APIENTRY glutInitDisplayString(const char *string);
-#endif
-GLUTAPI void APIENTRY glutInitWindowPosition(int x, int y);
-GLUTAPI void APIENTRY glutInitWindowSize(int width, int height);
-GLUTAPI void APIENTRY glutMainLoop(void);
-
-/* GLUT window sub-API. */
-GLUTAPI int APIENTRY glutCreateWindow(const char *title);
-#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
-GLUTAPI int APIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int));
-#ifndef GLUT_BUILDING_LIB
-static int APIENTRY glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); }
-#define glutCreateWindow glutCreateWindow_ATEXIT_HACK
-#endif
-#endif
-GLUTAPI int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height);
-GLUTAPI void APIENTRY glutDestroyWindow(int win);
-GLUTAPI void APIENTRY glutPostRedisplay(void);
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11)
-GLUTAPI void APIENTRY glutPostWindowRedisplay(int win);
-#endif
-GLUTAPI void APIENTRY glutSwapBuffers(void);
-GLUTAPI int APIENTRY glutGetWindow(void);
-GLUTAPI void APIENTRY glutSetWindow(int win);
-GLUTAPI void APIENTRY glutSetWindowTitle(const char *title);
-GLUTAPI void APIENTRY glutSetIconTitle(const char *title);
-GLUTAPI void APIENTRY glutPositionWindow(int x, int y);
-GLUTAPI void APIENTRY glutReshapeWindow(int width, int height);
-GLUTAPI void APIENTRY glutPopWindow(void);
-GLUTAPI void APIENTRY glutPushWindow(void);
-GLUTAPI void APIENTRY glutIconifyWindow(void);
-GLUTAPI void APIENTRY glutShowWindow(void);
-GLUTAPI void APIENTRY glutHideWindow(void);
-#if (GLUT_API_VERSION >= 3)
-GLUTAPI void APIENTRY glutFullScreen(void);
-GLUTAPI void APIENTRY glutSetCursor(int cursor);
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
-GLUTAPI void APIENTRY glutWarpPointer(int x, int y);
-#endif
-
-/* GLUT overlay sub-API. */
-GLUTAPI void APIENTRY glutEstablishOverlay(void);
-GLUTAPI void APIENTRY glutRemoveOverlay(void);
-GLUTAPI void APIENTRY glutUseLayer(GLenum layer);
-GLUTAPI void APIENTRY glutPostOverlayRedisplay(void);
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11)
-GLUTAPI void APIENTRY glutPostWindowOverlayRedisplay(int win);
-#endif
-GLUTAPI void APIENTRY glutShowOverlay(void);
-GLUTAPI void APIENTRY glutHideOverlay(void);
-#endif
-
-/* GLUT menu sub-API. */
-GLUTAPI int APIENTRY glutCreateMenu(void (GLUTCALLBACK *func)(int));
-#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
-GLUTAPI int APIENTRY __glutCreateMenuWithExit(void (GLUTCALLBACK *func)(int), void (__cdecl *exitfunc)(int));
-#ifndef GLUT_BUILDING_LIB
-static int APIENTRY glutCreateMenu_ATEXIT_HACK(void (GLUTCALLBACK *func)(int)) { return __glutCreateMenuWithExit(func, exit); }
-#define glutCreateMenu glutCreateMenu_ATEXIT_HACK
-#endif
-#endif
-GLUTAPI void APIENTRY glutDestroyMenu(int menu);
-GLUTAPI int APIENTRY glutGetMenu(void);
-GLUTAPI void APIENTRY glutSetMenu(int menu);
-GLUTAPI void APIENTRY glutAddMenuEntry(const char *label, int value);
-GLUTAPI void APIENTRY glutAddSubMenu(const char *label, int submenu);
-GLUTAPI void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value);
-GLUTAPI void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu);
-GLUTAPI void APIENTRY glutRemoveMenuItem(int item);
-GLUTAPI void APIENTRY glutAttachMenu(int button);
-GLUTAPI void APIENTRY glutDetachMenu(int button);
-
-/* GLUT window callback sub-API. */
-GLUTAPI void APIENTRY glutDisplayFunc(void (GLUTCALLBACK *func)(void));
-GLUTAPI void APIENTRY glutReshapeFunc(void (GLUTCALLBACK *func)(int width, int height));
-GLUTAPI void APIENTRY glutKeyboardFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y));
-GLUTAPI void APIENTRY glutMouseFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y));
-GLUTAPI void APIENTRY glutMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
-GLUTAPI void APIENTRY glutPassiveMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
-GLUTAPI void APIENTRY glutEntryFunc(void (GLUTCALLBACK *func)(int state));
-GLUTAPI void APIENTRY glutVisibilityFunc(void (GLUTCALLBACK *func)(int state));
-GLUTAPI void APIENTRY glutIdleFunc(void (GLUTCALLBACK *func)(void));
-GLUTAPI void APIENTRY glutTimerFunc(unsigned int millis, void (GLUTCALLBACK *func)(int value), int value);
-GLUTAPI void APIENTRY glutMenuStateFunc(void (GLUTCALLBACK *func)(int state));
-#if (GLUT_API_VERSION >= 2)
-GLUTAPI void APIENTRY glutSpecialFunc(void (GLUTCALLBACK *func)(int key, int x, int y));
-GLUTAPI void APIENTRY glutSpaceballMotionFunc(void (GLUTCALLBACK *func)(int x, int y, int z));
-GLUTAPI void APIENTRY glutSpaceballRotateFunc(void (GLUTCALLBACK *func)(int x, int y, int z));
-GLUTAPI void APIENTRY glutSpaceballButtonFunc(void (GLUTCALLBACK *func)(int button, int state));
-GLUTAPI void APIENTRY glutButtonBoxFunc(void (GLUTCALLBACK *func)(int button, int state));
-GLUTAPI void APIENTRY glutDialsFunc(void (GLUTCALLBACK *func)(int dial, int value));
-GLUTAPI void APIENTRY glutTabletMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
-GLUTAPI void APIENTRY glutTabletButtonFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y));
-#if (GLUT_API_VERSION >= 3)
-GLUTAPI void APIENTRY glutMenuStatusFunc(void (GLUTCALLBACK *func)(int status, int x, int y));
-GLUTAPI void APIENTRY glutOverlayDisplayFunc(void (GLUTCALLBACK *func)(void));
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
-GLUTAPI void APIENTRY glutWindowStatusFunc(void (GLUTCALLBACK *func)(int state));
-#endif
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
-GLUTAPI void APIENTRY glutKeyboardUpFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y));
-GLUTAPI void APIENTRY glutSpecialUpFunc(void (GLUTCALLBACK *func)(int key, int x, int y));
-GLUTAPI void APIENTRY glutJoystickFunc(void (GLUTCALLBACK *func)(unsigned int buttonMask, int x, int y, int z), int pollInterval);
-#endif
-#endif
-#endif
-
-/* GLUT color index sub-API. */
-GLUTAPI void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
-GLUTAPI GLfloat APIENTRY glutGetColor(int ndx, int component);
-GLUTAPI void APIENTRY glutCopyColormap(int win);
-
-/* GLUT state retrieval sub-API. */
-GLUTAPI int APIENTRY glutGet(GLenum type);
-GLUTAPI int APIENTRY glutDeviceGet(GLenum type);
-#if (GLUT_API_VERSION >= 2)
-/* GLUT extension support sub-API */
-GLUTAPI int APIENTRY glutExtensionSupported(const char *name);
-#endif
-#if (GLUT_API_VERSION >= 3)
-GLUTAPI int APIENTRY glutGetModifiers(void);
-GLUTAPI int APIENTRY glutLayerGet(GLenum type);
-#endif
-
-/* GLUT font sub-API */
-GLUTAPI void APIENTRY glutBitmapCharacter(void *font, int character);
-GLUTAPI int APIENTRY glutBitmapWidth(void *font, int character);
-GLUTAPI void APIENTRY glutStrokeCharacter(void *font, int character);
-GLUTAPI int APIENTRY glutStrokeWidth(void *font, int character);
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
-GLUTAPI int APIENTRY glutBitmapLength(void *font, const unsigned char *string);
-GLUTAPI int APIENTRY glutStrokeLength(void *font, const unsigned char *string);
-#endif
-
-/* GLUT pre-built models sub-API */
-GLUTAPI void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
-GLUTAPI void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
-GLUTAPI void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
-GLUTAPI void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
-GLUTAPI void APIENTRY glutWireCube(GLdouble size);
-GLUTAPI void APIENTRY glutSolidCube(GLdouble size);
-GLUTAPI void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
-GLUTAPI void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
-GLUTAPI void APIENTRY glutWireDodecahedron(void);
-GLUTAPI void APIENTRY glutSolidDodecahedron(void);
-GLUTAPI void APIENTRY glutWireTeapot(GLdouble size);
-GLUTAPI void APIENTRY glutSolidTeapot(GLdouble size);
-GLUTAPI void APIENTRY glutWireOctahedron(void);
-GLUTAPI void APIENTRY glutSolidOctahedron(void);
-GLUTAPI void APIENTRY glutWireTetrahedron(void);
-GLUTAPI void APIENTRY glutSolidTetrahedron(void);
-GLUTAPI void APIENTRY glutWireIcosahedron(void);
-GLUTAPI void APIENTRY glutSolidIcosahedron(void);
-
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
-/* GLUT video resize sub-API. */
-GLUTAPI int APIENTRY glutVideoResizeGet(GLenum param);
-GLUTAPI void APIENTRY glutSetupVideoResizing(void);
-GLUTAPI void APIENTRY glutStopVideoResizing(void);
-GLUTAPI void APIENTRY glutVideoResize(int x, int y, int width, int height);
-GLUTAPI void APIENTRY glutVideoPan(int x, int y, int width, int height);
-
-/* GLUT debugging sub-API. */
-GLUTAPI void APIENTRY glutReportErrors(void);
-#endif
-
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
-/* GLUT device control sub-API. */
-/* glutSetKeyRepeat modes. */
-#define GLUT_KEY_REPEAT_OFF		0
-#define GLUT_KEY_REPEAT_ON		1
-#define GLUT_KEY_REPEAT_DEFAULT		2
-
-/* Joystick button masks. */
-#define GLUT_JOYSTICK_BUTTON_A		1
-#define GLUT_JOYSTICK_BUTTON_B		2
-#define GLUT_JOYSTICK_BUTTON_C		4
-#define GLUT_JOYSTICK_BUTTON_D		8
-
-GLUTAPI void APIENTRY glutIgnoreKeyRepeat(int ignore);
-GLUTAPI void APIENTRY glutSetKeyRepeat(int repeatMode);
-GLUTAPI void APIENTRY glutForceJoystickFunc(void);
-
-/* GLUT game mode sub-API. */
-/* glutGameModeGet. */
-#define GLUT_GAME_MODE_ACTIVE           ((GLenum) 0)
-#define GLUT_GAME_MODE_POSSIBLE         ((GLenum) 1)
-#define GLUT_GAME_MODE_WIDTH            ((GLenum) 2)
-#define GLUT_GAME_MODE_HEIGHT           ((GLenum) 3)
-#define GLUT_GAME_MODE_PIXEL_DEPTH      ((GLenum) 4)
-#define GLUT_GAME_MODE_REFRESH_RATE     ((GLenum) 5)
-#define GLUT_GAME_MODE_DISPLAY_CHANGED  ((GLenum) 6)
-
-GLUTAPI void APIENTRY glutGameModeString(const char *string);
-GLUTAPI int APIENTRY glutEnterGameMode(void);
-GLUTAPI void APIENTRY glutLeaveGameMode(void);
-GLUTAPI int APIENTRY glutGameModeGet(GLenum mode);
-#endif
-
-#ifdef __cplusplus
-}
-
-#endif
-
-#ifdef GLUT_APIENTRY_DEFINED
-# undef GLUT_APIENTRY_DEFINED
-# undef APIENTRY
-#endif
-
-#ifdef GLUT_WINGDIAPI_DEFINED
-# undef GLUT_WINGDIAPI_DEFINED
-# undef WINGDIAPI
-#endif
-
-#ifdef GLUT_DEFINED___CDECL
-# undef GLUT_DEFINED___CDECL
-# undef __cdecl
-#endif
-
-#ifdef GLUT_DEFINED__CRTIMP
-# undef GLUT_DEFINED__CRTIMP
-# undef _CRTIMP
-#endif
-
-#endif                  /* __glut_h__ */
+#ifndef __glut_h__
+#define __glut_h__
+
+/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996, 1998. */
+
+/* This program is freely distributable without licensing fees  and is
+   provided without guarantee or warrantee expressed or  implied. This
+   program is -not- in the public domain. */
+
+#if defined(_WIN32)
+
+/* GLUT 3.7 now tries to avoid including <windows.h>
+   to avoid name space pollution, but Win32's <GL/gl.h>
+   needs APIENTRY and WINGDIAPI defined properly. */
+# if 0
+   /* This would put tons of macros and crap in our clean name space. */
+#  define  WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+# else
+   /* XXX This is from Win32's <windef.h> */
+#  ifndef APIENTRY
+#   define GLUT_APIENTRY_DEFINED
+#   if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__)
+#    define APIENTRY    __stdcall
+#   else
+#    define APIENTRY
+#   endif
+#  endif
+   /* XXX This is from Win32's <winnt.h> */
+#  ifndef CALLBACK
+#   if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) || defined(__LCC__)
+#    define CALLBACK __stdcall
+#   else
+#    define CALLBACK
+#   endif
+#  endif
+   /* XXX Hack for lcc compiler.  It doesn't support __declspec(dllimport), just __stdcall. */
+#  if defined( __LCC__ )
+#   undef WINGDIAPI
+#   define WINGDIAPI __stdcall
+#  else
+   /* XXX This is from Win32's <wingdi.h> and <winnt.h> */
+#   ifndef WINGDIAPI
+#    define GLUT_WINGDIAPI_DEFINED
+#    define WINGDIAPI __declspec(dllimport)
+#   endif
+#  endif
+   /* XXX This is from Win32's <ctype.h> */
+#  ifndef _WCHAR_T_DEFINED
+typedef unsigned short wchar_t;
+#   define _WCHAR_T_DEFINED
+#  endif
+# endif
+
+/* To disable automatic library usage for GLUT, define GLUT_NO_LIB_PRAGMA
+   in your compile preprocessor options. */
+# if !defined(GLUT_BUILDING_LIB) && !defined(GLUT_NO_LIB_PRAGMA)
+#  pragma comment (lib, "winmm.lib")      /* link with Windows MultiMedia lib */
+/* To enable automatic SGI OpenGL for Windows library usage for GLUT,
+   define GLUT_USE_SGI_OPENGL in your compile preprocessor options.  */
+#  ifdef GLUT_USE_SGI_OPENGL
+#   pragma comment (lib, "opengl.lib")    /* link with SGI OpenGL for Windows lib */
+#   pragma comment (lib, "glu.lib")       /* link with SGI OpenGL Utility lib */
+#   pragma comment (lib, "glut.lib")      /* link with Win32 GLUT for SGI OpenGL lib */
+#  else
+#   pragma comment (lib, "opengl32.lib")  /* link with Microsoft OpenGL lib */
+#   pragma comment (lib, "glu32.lib")     /* link with Microsoft OpenGL Utility lib */
+#   pragma comment (lib, "glut32.lib")    /* link with Win32 GLUT lib */
+#  endif
+# endif
+
+/* To disable supression of annoying warnings about floats being promoted
+   to doubles, define GLUT_NO_WARNING_DISABLE in your compile preprocessor
+   options. */
+# ifndef GLUT_NO_WARNING_DISABLE
+#  pragma warning (disable:4244)  /* Disable bogus VC++ 4.2 conversion warnings. */
+#  pragma warning (disable:4305)  /* VC++ 5.0 version of above warning. */
+# endif
+
+/* Win32 has an annoying issue where there are multiple C run-time
+   libraries (CRTs).  If the executable is linked with a different CRT
+   from the GLUT DLL, the GLUT DLL will not share the same CRT static
+   data seen by the executable.  In particular, atexit callbacks registered
+   in the executable will not be called if GLUT calls its (different)
+   exit routine).  GLUT is typically built with the
+   "/MD" option (the CRT with multithreading DLL support), but the Visual
+   C++ linker default is "/ML" (the single threaded CRT).
+
+   One workaround to this issue is requiring users to always link with
+   the same CRT as GLUT is compiled with.  That requires users supply a
+   non-standard option.  GLUT 3.7 has its own built-in workaround where
+   the executable's "exit" function pointer is covertly passed to GLUT.
+   GLUT then calls the executable's exit function pointer to ensure that
+   any "atexit" calls registered by the application are called if GLUT
+   needs to exit.
+
+   Note that the __glut*WithExit routines should NEVER be called directly.
+   To avoid the atexit workaround, #define GLUT_DISABLE_ATEXIT_HACK. */
+
+/* XXX This is from Win32's <process.h> */
+# if !defined(_MSC_VER) && !defined(__cdecl)
+   /* Define __cdecl for non-Microsoft compilers. */
+#  define __cdecl
+#  define GLUT_DEFINED___CDECL
+# endif
+# ifndef _CRTIMP
+#  ifdef _NTSDK
+    /* Definition compatible with NT SDK */
+#   define _CRTIMP
+#  else
+    /* Current definition */
+#   ifdef _DLL
+#    define _CRTIMP __declspec(dllimport)
+#   else
+#    define _CRTIMP
+#   endif
+#  endif
+#  define GLUT_DEFINED__CRTIMP
+# endif
+
+/* GLUT API entry point declarations for Win32. */
+# ifdef GLUT_BUILDING_LIB
+#  define GLUTAPI __declspec(dllexport)
+# else
+#  ifdef _DLL
+#   define GLUTAPI __declspec(dllimport)
+#  else
+#   define GLUTAPI extern
+#  endif
+# endif
+
+/* GLUT callback calling convention for Win32. */
+# define GLUTCALLBACK __cdecl
+
+#endif  /* _WIN32 */
+
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_WIN32)
+# ifndef GLUT_BUILDING_LIB
+extern _CRTIMP void __cdecl exit(int);
+# endif
+#else
+/* non-Win32 case. */
+/* Define APIENTRY and CALLBACK to nothing if we aren't on Win32. */
+# define APIENTRY
+# define GLUT_APIENTRY_DEFINED
+# define CALLBACK
+/* Define GLUTAPI and GLUTCALLBACK as below if we aren't on Win32. */
+# define GLUTAPI extern
+# define GLUTCALLBACK
+/* Prototype exit for the non-Win32 case (see above). */
+extern void exit(int);
+#endif
+
+/**
+ GLUT API revision history:
+
+ GLUT_API_VERSION is updated to reflect incompatible GLUT
+ API changes (interface changes, semantic changes, deletions,
+ or additions).
+
+ GLUT_API_VERSION=1  First public release of GLUT.  11/29/94
+
+ GLUT_API_VERSION=2  Added support for OpenGL/GLX multisampling,
+ extension.  Supports new input devices like tablet, dial and button
+ box, and Spaceball.  Easy to query OpenGL extensions.
+
+ GLUT_API_VERSION=3  glutMenuStatus added.
+
+ GLUT_API_VERSION=4  glutInitDisplayString, glutWarpPointer,
+ glutBitmapLength, glutStrokeLength, glutWindowStatusFunc, dynamic
+ video resize subAPI, glutPostWindowRedisplay, glutKeyboardUpFunc,
+ glutSpecialUpFunc, glutIgnoreKeyRepeat, glutSetKeyRepeat,
+ glutJoystickFunc, glutForceJoystickFunc (NOT FINALIZED!).
+**/
+#ifndef GLUT_API_VERSION  /* allow this to be overriden */
+#define GLUT_API_VERSION        3
+#endif
+
+/**
+ GLUT implementation revision history:
+
+ GLUT_XLIB_IMPLEMENTATION is updated to reflect both GLUT
+ API revisions and implementation revisions (ie, bug fixes).
+
+ GLUT_XLIB_IMPLEMENTATION=1  mjk's first public release of
+ GLUT Xlib-based implementation.  11/29/94
+
+ GLUT_XLIB_IMPLEMENTATION=2  mjk's second public release of
+ GLUT Xlib-based implementation providing GLUT version 2
+ interfaces.
+
+ GLUT_XLIB_IMPLEMENTATION=3  mjk's GLUT 2.2 images. 4/17/95
+
+ GLUT_XLIB_IMPLEMENTATION=4  mjk's GLUT 2.3 images. 6/?/95
+
+ GLUT_XLIB_IMPLEMENTATION=5  mjk's GLUT 3.0 images. 10/?/95
+
+ GLUT_XLIB_IMPLEMENTATION=7  mjk's GLUT 3.1+ with glutWarpPoitner.  7/24/96
+
+ GLUT_XLIB_IMPLEMENTATION=8  mjk's GLUT 3.1+ with glutWarpPoitner
+ and video resize.  1/3/97
+
+ GLUT_XLIB_IMPLEMENTATION=9 mjk's GLUT 3.4 release with early GLUT 4 routines.
+
+ GLUT_XLIB_IMPLEMENTATION=11 Mesa 2.5's GLUT 3.6 release.
+
+ GLUT_XLIB_IMPLEMENTATION=12 mjk's GLUT 3.6 release with early GLUT 4 routines + signal handling.
+
+ GLUT_XLIB_IMPLEMENTATION=13 mjk's GLUT 3.7 beta with GameGLUT support.
+
+ GLUT_XLIB_IMPLEMENTATION=14 mjk's GLUT 3.7 beta with f90gl friend interface.
+
+ GLUT_XLIB_IMPLEMENTATION=15 mjk's GLUT 3.7 beta sync'ed with Mesa <GL/glut.h>
+**/
+#ifndef GLUT_XLIB_IMPLEMENTATION  /* Allow this to be overriden. */
+#define GLUT_XLIB_IMPLEMENTATION    15
+#endif
+
+/* Display mode bit masks. */
+#define GLUT_RGB            0
+#define GLUT_RGBA           GLUT_RGB
+#define GLUT_INDEX          1
+#define GLUT_SINGLE         0
+#define GLUT_DOUBLE         2
+#define GLUT_ACCUM          4
+#define GLUT_ALPHA          8
+#define GLUT_DEPTH          16
+#define GLUT_STENCIL            32
+#if (GLUT_API_VERSION >= 2)
+#define GLUT_MULTISAMPLE        128
+#define GLUT_STEREO         256
+#endif
+#if (GLUT_API_VERSION >= 3)
+#define GLUT_LUMINANCE          512
+#endif
+
+/* Mouse buttons. */
+#define GLUT_LEFT_BUTTON        0
+#define GLUT_MIDDLE_BUTTON      1
+#define GLUT_RIGHT_BUTTON       2
+
+/* Mouse button  state. */
+#define GLUT_DOWN           0
+#define GLUT_UP             1
+
+#if (GLUT_API_VERSION >= 2)
+/* function keys */
+#define GLUT_KEY_F1         1
+#define GLUT_KEY_F2         2
+#define GLUT_KEY_F3         3
+#define GLUT_KEY_F4         4
+#define GLUT_KEY_F5         5
+#define GLUT_KEY_F6         6
+#define GLUT_KEY_F7         7
+#define GLUT_KEY_F8         8
+#define GLUT_KEY_F9         9
+#define GLUT_KEY_F10            10
+#define GLUT_KEY_F11            11
+#define GLUT_KEY_F12            12
+/* directional keys */
+#define GLUT_KEY_LEFT           100
+#define GLUT_KEY_UP         101
+#define GLUT_KEY_RIGHT          102
+#define GLUT_KEY_DOWN           103
+#define GLUT_KEY_PAGE_UP        104
+#define GLUT_KEY_PAGE_DOWN      105
+#define GLUT_KEY_HOME           106
+#define GLUT_KEY_END            107
+#define GLUT_KEY_INSERT         108
+#endif
+
+/* Entry/exit  state. */
+#define GLUT_LEFT           0
+#define GLUT_ENTERED            1
+
+/* Menu usage  state. */
+#define GLUT_MENU_NOT_IN_USE        0
+#define GLUT_MENU_IN_USE        1
+
+/* Visibility  state. */
+#define GLUT_NOT_VISIBLE        0
+#define GLUT_VISIBLE            1
+
+/* Window status  state. */
+#define GLUT_HIDDEN         0
+#define GLUT_FULLY_RETAINED     1
+#define GLUT_PARTIALLY_RETAINED     2
+#define GLUT_FULLY_COVERED      3
+
+/* Color index component selection values. */
+#define GLUT_RED            0
+#define GLUT_GREEN          1
+#define GLUT_BLUE           2
+
+#if defined(_WIN32)
+/* Stroke font constants (use these in GLUT program). */
+#define GLUT_STROKE_ROMAN       ((void*)0)
+#define GLUT_STROKE_MONO_ROMAN      ((void*)1)
+
+/* Bitmap font constants (use these in GLUT program). */
+#define GLUT_BITMAP_9_BY_15     ((void*)2)
+#define GLUT_BITMAP_8_BY_13     ((void*)3)
+#define GLUT_BITMAP_TIMES_ROMAN_10  ((void*)4)
+#define GLUT_BITMAP_TIMES_ROMAN_24  ((void*)5)
+#if (GLUT_API_VERSION >= 3)
+#define GLUT_BITMAP_HELVETICA_10    ((void*)6)
+#define GLUT_BITMAP_HELVETICA_12    ((void*)7)
+#define GLUT_BITMAP_HELVETICA_18    ((void*)8)
+#endif
+#else
+/* Stroke font opaque addresses (use constants instead in source code). */
+GLUTAPI void *glutStrokeRoman;
+GLUTAPI void *glutStrokeMonoRoman;
+
+/* Stroke font constants (use these in GLUT program). */
+#define GLUT_STROKE_ROMAN       (&glutStrokeRoman)
+#define GLUT_STROKE_MONO_ROMAN      (&glutStrokeMonoRoman)
+
+/* Bitmap font opaque addresses (use constants instead in source code). */
+GLUTAPI void *glutBitmap9By15;
+GLUTAPI void *glutBitmap8By13;
+GLUTAPI void *glutBitmapTimesRoman10;
+GLUTAPI void *glutBitmapTimesRoman24;
+GLUTAPI void *glutBitmapHelvetica10;
+GLUTAPI void *glutBitmapHelvetica12;
+GLUTAPI void *glutBitmapHelvetica18;
+
+/* Bitmap font constants (use these in GLUT program). */
+#define GLUT_BITMAP_9_BY_15     (&glutBitmap9By15)
+#define GLUT_BITMAP_8_BY_13     (&glutBitmap8By13)
+#define GLUT_BITMAP_TIMES_ROMAN_10  (&glutBitmapTimesRoman10)
+#define GLUT_BITMAP_TIMES_ROMAN_24  (&glutBitmapTimesRoman24)
+#if (GLUT_API_VERSION >= 3)
+#define GLUT_BITMAP_HELVETICA_10    (&glutBitmapHelvetica10)
+#define GLUT_BITMAP_HELVETICA_12    (&glutBitmapHelvetica12)
+#define GLUT_BITMAP_HELVETICA_18    (&glutBitmapHelvetica18)
+#endif
+#endif
+
+/* glutGet parameters. */
+#define GLUT_WINDOW_X           ((GLenum) 100)
+#define GLUT_WINDOW_Y           ((GLenum) 101)
+#define GLUT_WINDOW_WIDTH       ((GLenum) 102)
+#define GLUT_WINDOW_HEIGHT      ((GLenum) 103)
+#define GLUT_WINDOW_BUFFER_SIZE     ((GLenum) 104)
+#define GLUT_WINDOW_STENCIL_SIZE    ((GLenum) 105)
+#define GLUT_WINDOW_DEPTH_SIZE      ((GLenum) 106)
+#define GLUT_WINDOW_RED_SIZE        ((GLenum) 107)
+#define GLUT_WINDOW_GREEN_SIZE      ((GLenum) 108)
+#define GLUT_WINDOW_BLUE_SIZE       ((GLenum) 109)
+#define GLUT_WINDOW_ALPHA_SIZE      ((GLenum) 110)
+#define GLUT_WINDOW_ACCUM_RED_SIZE  ((GLenum) 111)
+#define GLUT_WINDOW_ACCUM_GREEN_SIZE    ((GLenum) 112)
+#define GLUT_WINDOW_ACCUM_BLUE_SIZE ((GLenum) 113)
+#define GLUT_WINDOW_ACCUM_ALPHA_SIZE    ((GLenum) 114)
+#define GLUT_WINDOW_DOUBLEBUFFER    ((GLenum) 115)
+#define GLUT_WINDOW_RGBA        ((GLenum) 116)
+#define GLUT_WINDOW_PARENT      ((GLenum) 117)
+#define GLUT_WINDOW_NUM_CHILDREN    ((GLenum) 118)
+#define GLUT_WINDOW_COLORMAP_SIZE   ((GLenum) 119)
+#if (GLUT_API_VERSION >= 2)
+#define GLUT_WINDOW_NUM_SAMPLES     ((GLenum) 120)
+#define GLUT_WINDOW_STEREO      ((GLenum) 121)
+#endif
+#if (GLUT_API_VERSION >= 3)
+#define GLUT_WINDOW_CURSOR      ((GLenum) 122)
+#endif
+#define GLUT_SCREEN_WIDTH       ((GLenum) 200)
+#define GLUT_SCREEN_HEIGHT      ((GLenum) 201)
+#define GLUT_SCREEN_WIDTH_MM        ((GLenum) 202)
+#define GLUT_SCREEN_HEIGHT_MM       ((GLenum) 203)
+#define GLUT_MENU_NUM_ITEMS     ((GLenum) 300)
+#define GLUT_DISPLAY_MODE_POSSIBLE  ((GLenum) 400)
+#define GLUT_INIT_WINDOW_X      ((GLenum) 500)
+#define GLUT_INIT_WINDOW_Y      ((GLenum) 501)
+#define GLUT_INIT_WINDOW_WIDTH      ((GLenum) 502)
+#define GLUT_INIT_WINDOW_HEIGHT     ((GLenum) 503)
+#define GLUT_INIT_DISPLAY_MODE      ((GLenum) 504)
+#if (GLUT_API_VERSION >= 2)
+#define GLUT_ELAPSED_TIME       ((GLenum) 700)
+#endif
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
+#define GLUT_WINDOW_FORMAT_ID       ((GLenum) 123)
+#endif
+
+#if (GLUT_API_VERSION >= 2)
+/* glutDeviceGet parameters. */
+#define GLUT_HAS_KEYBOARD       ((GLenum) 600)
+#define GLUT_HAS_MOUSE          ((GLenum) 601)
+#define GLUT_HAS_SPACEBALL      ((GLenum) 602)
+#define GLUT_HAS_DIAL_AND_BUTTON_BOX    ((GLenum) 603)
+#define GLUT_HAS_TABLET         ((GLenum) 604)
+#define GLUT_NUM_MOUSE_BUTTONS      ((GLenum) 605)
+#define GLUT_NUM_SPACEBALL_BUTTONS  ((GLenum) 606)
+#define GLUT_NUM_BUTTON_BOX_BUTTONS ((GLenum) 607)
+#define GLUT_NUM_DIALS          ((GLenum) 608)
+#define GLUT_NUM_TABLET_BUTTONS     ((GLenum) 609)
+#endif
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
+#define GLUT_DEVICE_IGNORE_KEY_REPEAT   ((GLenum) 610)
+#define GLUT_DEVICE_KEY_REPEAT          ((GLenum) 611)
+#define GLUT_HAS_JOYSTICK       ((GLenum) 612)
+#define GLUT_OWNS_JOYSTICK      ((GLenum) 613)
+#define GLUT_JOYSTICK_BUTTONS       ((GLenum) 614)
+#define GLUT_JOYSTICK_AXES      ((GLenum) 615)
+#define GLUT_JOYSTICK_POLL_RATE     ((GLenum) 616)
+#endif
+
+#if (GLUT_API_VERSION >= 3)
+/* glutLayerGet parameters. */
+#define GLUT_OVERLAY_POSSIBLE           ((GLenum) 800)
+#define GLUT_LAYER_IN_USE       ((GLenum) 801)
+#define GLUT_HAS_OVERLAY        ((GLenum) 802)
+#define GLUT_TRANSPARENT_INDEX      ((GLenum) 803)
+#define GLUT_NORMAL_DAMAGED     ((GLenum) 804)
+#define GLUT_OVERLAY_DAMAGED        ((GLenum) 805)
+
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
+/* glutVideoResizeGet parameters. */
+#define GLUT_VIDEO_RESIZE_POSSIBLE  ((GLenum) 900)
+#define GLUT_VIDEO_RESIZE_IN_USE    ((GLenum) 901)
+#define GLUT_VIDEO_RESIZE_X_DELTA   ((GLenum) 902)
+#define GLUT_VIDEO_RESIZE_Y_DELTA   ((GLenum) 903)
+#define GLUT_VIDEO_RESIZE_WIDTH_DELTA   ((GLenum) 904)
+#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA  ((GLenum) 905)
+#define GLUT_VIDEO_RESIZE_X     ((GLenum) 906)
+#define GLUT_VIDEO_RESIZE_Y     ((GLenum) 907)
+#define GLUT_VIDEO_RESIZE_WIDTH     ((GLenum) 908)
+#define GLUT_VIDEO_RESIZE_HEIGHT    ((GLenum) 909)
+#endif
+
+/* glutUseLayer parameters. */
+#define GLUT_NORMAL         ((GLenum) 0)
+#define GLUT_OVERLAY            ((GLenum) 1)
+
+/* glutGetModifiers return mask. */
+#define GLUT_ACTIVE_SHIFT               1
+#define GLUT_ACTIVE_CTRL                2
+#define GLUT_ACTIVE_ALT                 4
+
+/* glutSetCursor parameters. */
+/* Basic arrows. */
+#define GLUT_CURSOR_RIGHT_ARROW     0
+#define GLUT_CURSOR_LEFT_ARROW      1
+/* Symbolic cursor shapes. */
+#define GLUT_CURSOR_INFO        2
+#define GLUT_CURSOR_DESTROY     3
+#define GLUT_CURSOR_HELP        4
+#define GLUT_CURSOR_CYCLE       5
+#define GLUT_CURSOR_SPRAY       6
+#define GLUT_CURSOR_WAIT        7
+#define GLUT_CURSOR_TEXT        8
+#define GLUT_CURSOR_CROSSHAIR       9
+/* Directional cursors. */
+#define GLUT_CURSOR_UP_DOWN     10
+#define GLUT_CURSOR_LEFT_RIGHT      11
+/* Sizing cursors. */
+#define GLUT_CURSOR_TOP_SIDE        12
+#define GLUT_CURSOR_BOTTOM_SIDE     13
+#define GLUT_CURSOR_LEFT_SIDE       14
+#define GLUT_CURSOR_RIGHT_SIDE      15
+#define GLUT_CURSOR_TOP_LEFT_CORNER 16
+#define GLUT_CURSOR_TOP_RIGHT_CORNER    17
+#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 18
+#define GLUT_CURSOR_BOTTOM_LEFT_CORNER  19
+/* Inherit from parent window. */
+#define GLUT_CURSOR_INHERIT     100
+/* Blank cursor. */
+#define GLUT_CURSOR_NONE        101
+/* Fullscreen crosshair (if available). */
+#define GLUT_CURSOR_FULL_CROSSHAIR  102
+#endif
+
+/* GLUT initialization sub-API. */
+GLUTAPI void APIENTRY glutInit(int *argcp, char **argv);
+#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
+GLUTAPI void APIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int));
+#ifndef GLUT_BUILDING_LIB
+static void APIENTRY glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }
+#define glutInit glutInit_ATEXIT_HACK
+#endif
+#endif
+GLUTAPI void APIENTRY glutInitDisplayMode(unsigned int mode);
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
+GLUTAPI void APIENTRY glutInitDisplayString(const char *string);
+#endif
+GLUTAPI void APIENTRY glutInitWindowPosition(int x, int y);
+GLUTAPI void APIENTRY glutInitWindowSize(int width, int height);
+GLUTAPI void APIENTRY glutMainLoop(void);
+
+/* GLUT window sub-API. */
+GLUTAPI int APIENTRY glutCreateWindow(const char *title);
+#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
+GLUTAPI int APIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int));
+#ifndef GLUT_BUILDING_LIB
+static int APIENTRY glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); }
+#define glutCreateWindow glutCreateWindow_ATEXIT_HACK
+#endif
+#endif
+GLUTAPI int APIENTRY glutCreateSubWindow(int win, int x, int y, int width, int height);
+GLUTAPI void APIENTRY glutDestroyWindow(int win);
+GLUTAPI void APIENTRY glutPostRedisplay(void);
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11)
+GLUTAPI void APIENTRY glutPostWindowRedisplay(int win);
+#endif
+GLUTAPI void APIENTRY glutSwapBuffers(void);
+GLUTAPI int APIENTRY glutGetWindow(void);
+GLUTAPI void APIENTRY glutSetWindow(int win);
+GLUTAPI void APIENTRY glutSetWindowTitle(const char *title);
+GLUTAPI void APIENTRY glutSetIconTitle(const char *title);
+GLUTAPI void APIENTRY glutPositionWindow(int x, int y);
+GLUTAPI void APIENTRY glutReshapeWindow(int width, int height);
+GLUTAPI void APIENTRY glutPopWindow(void);
+GLUTAPI void APIENTRY glutPushWindow(void);
+GLUTAPI void APIENTRY glutIconifyWindow(void);
+GLUTAPI void APIENTRY glutShowWindow(void);
+GLUTAPI void APIENTRY glutHideWindow(void);
+#if (GLUT_API_VERSION >= 3)
+GLUTAPI void APIENTRY glutFullScreen(void);
+GLUTAPI void APIENTRY glutSetCursor(int cursor);
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
+GLUTAPI void APIENTRY glutWarpPointer(int x, int y);
+#endif
+
+/* GLUT overlay sub-API. */
+GLUTAPI void APIENTRY glutEstablishOverlay(void);
+GLUTAPI void APIENTRY glutRemoveOverlay(void);
+GLUTAPI void APIENTRY glutUseLayer(GLenum layer);
+GLUTAPI void APIENTRY glutPostOverlayRedisplay(void);
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 11)
+GLUTAPI void APIENTRY glutPostWindowOverlayRedisplay(int win);
+#endif
+GLUTAPI void APIENTRY glutShowOverlay(void);
+GLUTAPI void APIENTRY glutHideOverlay(void);
+#endif
+
+/* GLUT menu sub-API. */
+GLUTAPI int APIENTRY glutCreateMenu(void (GLUTCALLBACK *func)(int));
+#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK)
+GLUTAPI int APIENTRY __glutCreateMenuWithExit(void (GLUTCALLBACK *func)(int), void (__cdecl *exitfunc)(int));
+#ifndef GLUT_BUILDING_LIB
+static int APIENTRY glutCreateMenu_ATEXIT_HACK(void (GLUTCALLBACK *func)(int)) { return __glutCreateMenuWithExit(func, exit); }
+#define glutCreateMenu glutCreateMenu_ATEXIT_HACK
+#endif
+#endif
+GLUTAPI void APIENTRY glutDestroyMenu(int menu);
+GLUTAPI int APIENTRY glutGetMenu(void);
+GLUTAPI void APIENTRY glutSetMenu(int menu);
+GLUTAPI void APIENTRY glutAddMenuEntry(const char *label, int value);
+GLUTAPI void APIENTRY glutAddSubMenu(const char *label, int submenu);
+GLUTAPI void APIENTRY glutChangeToMenuEntry(int item, const char *label, int value);
+GLUTAPI void APIENTRY glutChangeToSubMenu(int item, const char *label, int submenu);
+GLUTAPI void APIENTRY glutRemoveMenuItem(int item);
+GLUTAPI void APIENTRY glutAttachMenu(int button);
+GLUTAPI void APIENTRY glutDetachMenu(int button);
+
+/* GLUT window callback sub-API. */
+GLUTAPI void APIENTRY glutDisplayFunc(void (GLUTCALLBACK *func)(void));
+GLUTAPI void APIENTRY glutReshapeFunc(void (GLUTCALLBACK *func)(int width, int height));
+GLUTAPI void APIENTRY glutKeyboardFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y));
+GLUTAPI void APIENTRY glutMouseFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y));
+GLUTAPI void APIENTRY glutMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
+GLUTAPI void APIENTRY glutPassiveMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
+GLUTAPI void APIENTRY glutEntryFunc(void (GLUTCALLBACK *func)(int state));
+GLUTAPI void APIENTRY glutVisibilityFunc(void (GLUTCALLBACK *func)(int state));
+GLUTAPI void APIENTRY glutIdleFunc(void (GLUTCALLBACK *func)(void));
+GLUTAPI void APIENTRY glutTimerFunc(unsigned int millis, void (GLUTCALLBACK *func)(int value), int value);
+GLUTAPI void APIENTRY glutMenuStateFunc(void (GLUTCALLBACK *func)(int state));
+#if (GLUT_API_VERSION >= 2)
+GLUTAPI void APIENTRY glutSpecialFunc(void (GLUTCALLBACK *func)(int key, int x, int y));
+GLUTAPI void APIENTRY glutSpaceballMotionFunc(void (GLUTCALLBACK *func)(int x, int y, int z));
+GLUTAPI void APIENTRY glutSpaceballRotateFunc(void (GLUTCALLBACK *func)(int x, int y, int z));
+GLUTAPI void APIENTRY glutSpaceballButtonFunc(void (GLUTCALLBACK *func)(int button, int state));
+GLUTAPI void APIENTRY glutButtonBoxFunc(void (GLUTCALLBACK *func)(int button, int state));
+GLUTAPI void APIENTRY glutDialsFunc(void (GLUTCALLBACK *func)(int dial, int value));
+GLUTAPI void APIENTRY glutTabletMotionFunc(void (GLUTCALLBACK *func)(int x, int y));
+GLUTAPI void APIENTRY glutTabletButtonFunc(void (GLUTCALLBACK *func)(int button, int state, int x, int y));
+#if (GLUT_API_VERSION >= 3)
+GLUTAPI void APIENTRY glutMenuStatusFunc(void (GLUTCALLBACK *func)(int status, int x, int y));
+GLUTAPI void APIENTRY glutOverlayDisplayFunc(void (GLUTCALLBACK *func)(void));
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
+GLUTAPI void APIENTRY glutWindowStatusFunc(void (GLUTCALLBACK *func)(int state));
+#endif
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
+GLUTAPI void APIENTRY glutKeyboardUpFunc(void (GLUTCALLBACK *func)(unsigned char key, int x, int y));
+GLUTAPI void APIENTRY glutSpecialUpFunc(void (GLUTCALLBACK *func)(int key, int x, int y));
+GLUTAPI void APIENTRY glutJoystickFunc(void (GLUTCALLBACK *func)(unsigned int buttonMask, int x, int y, int z), int pollInterval);
+#endif
+#endif
+#endif
+
+/* GLUT color index sub-API. */
+GLUTAPI void APIENTRY glutSetColor(int, GLfloat red, GLfloat green, GLfloat blue);
+GLUTAPI GLfloat APIENTRY glutGetColor(int ndx, int component);
+GLUTAPI void APIENTRY glutCopyColormap(int win);
+
+/* GLUT state retrieval sub-API. */
+GLUTAPI int APIENTRY glutGet(GLenum type);
+GLUTAPI int APIENTRY glutDeviceGet(GLenum type);
+#if (GLUT_API_VERSION >= 2)
+/* GLUT extension support sub-API */
+GLUTAPI int APIENTRY glutExtensionSupported(const char *name);
+#endif
+#if (GLUT_API_VERSION >= 3)
+GLUTAPI int APIENTRY glutGetModifiers(void);
+GLUTAPI int APIENTRY glutLayerGet(GLenum type);
+#endif
+
+/* GLUT font sub-API */
+GLUTAPI void APIENTRY glutBitmapCharacter(void *font, int character);
+GLUTAPI int APIENTRY glutBitmapWidth(void *font, int character);
+GLUTAPI void APIENTRY glutStrokeCharacter(void *font, int character);
+GLUTAPI int APIENTRY glutStrokeWidth(void *font, int character);
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
+GLUTAPI int APIENTRY glutBitmapLength(void *font, const unsigned char *string);
+GLUTAPI int APIENTRY glutStrokeLength(void *font, const unsigned char *string);
+#endif
+
+/* GLUT pre-built models sub-API */
+GLUTAPI void APIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks);
+GLUTAPI void APIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
+GLUTAPI void APIENTRY glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
+GLUTAPI void APIENTRY glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
+GLUTAPI void APIENTRY glutWireCube(GLdouble size);
+GLUTAPI void APIENTRY glutSolidCube(GLdouble size);
+GLUTAPI void APIENTRY glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
+GLUTAPI void APIENTRY glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);
+GLUTAPI void APIENTRY glutWireDodecahedron(void);
+GLUTAPI void APIENTRY glutSolidDodecahedron(void);
+GLUTAPI void APIENTRY glutWireTeapot(GLdouble size);
+GLUTAPI void APIENTRY glutSolidTeapot(GLdouble size);
+GLUTAPI void APIENTRY glutWireOctahedron(void);
+GLUTAPI void APIENTRY glutSolidOctahedron(void);
+GLUTAPI void APIENTRY glutWireTetrahedron(void);
+GLUTAPI void APIENTRY glutSolidTetrahedron(void);
+GLUTAPI void APIENTRY glutWireIcosahedron(void);
+GLUTAPI void APIENTRY glutSolidIcosahedron(void);
+
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
+/* GLUT video resize sub-API. */
+GLUTAPI int APIENTRY glutVideoResizeGet(GLenum param);
+GLUTAPI void APIENTRY glutSetupVideoResizing(void);
+GLUTAPI void APIENTRY glutStopVideoResizing(void);
+GLUTAPI void APIENTRY glutVideoResize(int x, int y, int width, int height);
+GLUTAPI void APIENTRY glutVideoPan(int x, int y, int width, int height);
+
+/* GLUT debugging sub-API. */
+GLUTAPI void APIENTRY glutReportErrors(void);
+#endif
+
+#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
+/* GLUT device control sub-API. */
+/* glutSetKeyRepeat modes. */
+#define GLUT_KEY_REPEAT_OFF     0
+#define GLUT_KEY_REPEAT_ON      1
+#define GLUT_KEY_REPEAT_DEFAULT     2
+
+/* Joystick button masks. */
+#define GLUT_JOYSTICK_BUTTON_A      1
+#define GLUT_JOYSTICK_BUTTON_B      2
+#define GLUT_JOYSTICK_BUTTON_C      4
+#define GLUT_JOYSTICK_BUTTON_D      8
+
+GLUTAPI void APIENTRY glutIgnoreKeyRepeat(int ignore);
+GLUTAPI void APIENTRY glutSetKeyRepeat(int repeatMode);
+GLUTAPI void APIENTRY glutForceJoystickFunc(void);
+
+/* GLUT game mode sub-API. */
+/* glutGameModeGet. */
+#define GLUT_GAME_MODE_ACTIVE           ((GLenum) 0)
+#define GLUT_GAME_MODE_POSSIBLE         ((GLenum) 1)
+#define GLUT_GAME_MODE_WIDTH            ((GLenum) 2)
+#define GLUT_GAME_MODE_HEIGHT           ((GLenum) 3)
+#define GLUT_GAME_MODE_PIXEL_DEPTH      ((GLenum) 4)
+#define GLUT_GAME_MODE_REFRESH_RATE     ((GLenum) 5)
+#define GLUT_GAME_MODE_DISPLAY_CHANGED  ((GLenum) 6)
+
+GLUTAPI void APIENTRY glutGameModeString(const char *string);
+GLUTAPI int APIENTRY glutEnterGameMode(void);
+GLUTAPI void APIENTRY glutLeaveGameMode(void);
+GLUTAPI int APIENTRY glutGameModeGet(GLenum mode);
+#endif
+
+#ifdef __cplusplus
+}
+
+#endif
+
+#ifdef GLUT_APIENTRY_DEFINED
+# undef GLUT_APIENTRY_DEFINED
+# undef APIENTRY
+#endif
+
+#ifdef GLUT_WINGDIAPI_DEFINED
+# undef GLUT_WINGDIAPI_DEFINED
+# undef WINGDIAPI
+#endif
+
+#ifdef GLUT_DEFINED___CDECL
+# undef GLUT_DEFINED___CDECL
+# undef __cdecl
+#endif
+
+#ifdef GLUT_DEFINED__CRTIMP
+# undef GLUT_DEFINED__CRTIMP
+# undef _CRTIMP
+#endif
+
+#endif                  /* __glut_h__ */
--- a/misc/winutils/include/SDL.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL.h	Tue Jan 21 22:53:15 2014 +0100
@@ -58,17 +58,17 @@
  *  specify the subsystems which you will be using in your application.
  */
 /*@{*/
-#define	SDL_INIT_TIMER		0x00000001
-#define SDL_INIT_AUDIO		0x00000010
-#define SDL_INIT_VIDEO		0x00000020
-#define SDL_INIT_CDROM		0x00000100
-#define SDL_INIT_JOYSTICK	0x00000200
-#define SDL_INIT_NOPARACHUTE	0x00100000	/**< Don't catch fatal signals */
-#define SDL_INIT_EVENTTHREAD	0x01000000	/**< Not supported on all OS's */
-#define SDL_INIT_EVERYTHING	0x0000FFFF
+#define SDL_INIT_TIMER      0x00000001
+#define SDL_INIT_AUDIO      0x00000010
+#define SDL_INIT_VIDEO      0x00000020
+#define SDL_INIT_CDROM      0x00000100
+#define SDL_INIT_JOYSTICK   0x00000200
+#define SDL_INIT_NOPARACHUTE    0x00100000  /**< Don't catch fatal signals */
+#define SDL_INIT_EVENTTHREAD    0x01000000  /**< Not supported on all OS's */
+#define SDL_INIT_EVERYTHING 0x0000FFFF
 /*@}*/
 
-/** This function loads the SDL dynamically linked library and initializes 
+/** This function loads the SDL dynamically linked library and initializes
  *  the subsystems specified by 'flags' (and those satisfying dependencies)
  *  Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup
  *  signal handlers for some commonly ignored fatal signals (like SIGSEGV)
--- a/misc/winutils/include/SDL_active.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_active.h	Tue Jan 21 22:53:15 2014 +0100
@@ -22,7 +22,7 @@
 
 /**
  *  @file SDL_active.h
- *  Include file for SDL application focus event handling 
+ *  Include file for SDL application focus event handling
  */
 
 #ifndef _SDL_active_h
@@ -39,13 +39,13 @@
 
 /** @name The available application states */
 /*@{*/
-#define SDL_APPMOUSEFOCUS	0x01		/**< The app has mouse coverage */
-#define SDL_APPINPUTFOCUS	0x02		/**< The app has input focus */
-#define SDL_APPACTIVE		0x04		/**< The application is active */
+#define SDL_APPMOUSEFOCUS   0x01        /**< The app has mouse coverage */
+#define SDL_APPINPUTFOCUS   0x02        /**< The app has input focus */
+#define SDL_APPACTIVE       0x04        /**< The application is active */
 /*@}*/
 
 /* Function prototypes */
-/** 
+/**
  * This function returns the current state of the application, which is a
  * bitwise combination of SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, and
  * SDL_APPACTIVE.  If SDL_APPACTIVE is set, then the user is able to
--- a/misc/winutils/include/SDL_audio.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_audio.h	Tue Jan 21 22:53:15 2014 +0100
@@ -72,24 +72,24 @@
  *
  */
 typedef struct SDL_AudioSpec {
-	int freq;		/**< DSP frequency -- samples per second */
-	Uint16 format;		/**< Audio data format */
-	Uint8  channels;	/**< Number of channels: 1 mono, 2 stereo */
-	Uint8  silence;		/**< Audio buffer silence value (calculated) */
-	Uint16 samples;		/**< Audio buffer size in samples (power of 2) */
-	Uint16 padding;		/**< Necessary for some compile environments */
-	Uint32 size;		/**< Audio buffer size in bytes (calculated) */
-	/**
-	 *  This function is called when the audio device needs more data.
-	 *
-	 *  @param[out] stream	A pointer to the audio data buffer
-	 *  @param[in]  len	The length of the audio buffer in bytes.
-	 *
-	 *  Once the callback returns, the buffer will no longer be valid.
-	 *  Stereo samples are stored in a LRLRLR ordering.
-	 */
-	void (SDLCALL *callback)(void *userdata, Uint8 *stream, int len);
-	void  *userdata;
+    int freq;       /**< DSP frequency -- samples per second */
+    Uint16 format;      /**< Audio data format */
+    Uint8  channels;    /**< Number of channels: 1 mono, 2 stereo */
+    Uint8  silence;     /**< Audio buffer silence value (calculated) */
+    Uint16 samples;     /**< Audio buffer size in samples (power of 2) */
+    Uint16 padding;     /**< Necessary for some compile environments */
+    Uint32 size;        /**< Audio buffer size in bytes (calculated) */
+    /**
+     *  This function is called when the audio device needs more data.
+     *
+     *  @param[out] stream  A pointer to the audio data buffer
+     *  @param[in]  len The length of the audio buffer in bytes.
+     *
+     *  Once the callback returns, the buffer will no longer be valid.
+     *  Stereo samples are stored in a LRLRLR ordering.
+     */
+    void (SDLCALL *callback)(void *userdata, Uint8 *stream, int len);
+    void  *userdata;
 } SDL_AudioSpec;
 
 /**
@@ -97,25 +97,25 @@
  *  defaults to LSB byte order
  */
 /*@{*/
-#define AUDIO_U8	0x0008	/**< Unsigned 8-bit samples */
-#define AUDIO_S8	0x8008	/**< Signed 8-bit samples */
-#define AUDIO_U16LSB	0x0010	/**< Unsigned 16-bit samples */
-#define AUDIO_S16LSB	0x8010	/**< Signed 16-bit samples */
-#define AUDIO_U16MSB	0x1010	/**< As above, but big-endian byte order */
-#define AUDIO_S16MSB	0x9010	/**< As above, but big-endian byte order */
-#define AUDIO_U16	AUDIO_U16LSB
-#define AUDIO_S16	AUDIO_S16LSB
+#define AUDIO_U8    0x0008  /**< Unsigned 8-bit samples */
+#define AUDIO_S8    0x8008  /**< Signed 8-bit samples */
+#define AUDIO_U16LSB    0x0010  /**< Unsigned 16-bit samples */
+#define AUDIO_S16LSB    0x8010  /**< Signed 16-bit samples */
+#define AUDIO_U16MSB    0x1010  /**< As above, but big-endian byte order */
+#define AUDIO_S16MSB    0x9010  /**< As above, but big-endian byte order */
+#define AUDIO_U16   AUDIO_U16LSB
+#define AUDIO_S16   AUDIO_S16LSB
 
 /**
  *  @name Native audio byte ordering
  */
 /*@{*/
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
-#define AUDIO_U16SYS	AUDIO_U16LSB
-#define AUDIO_S16SYS	AUDIO_S16LSB
+#define AUDIO_U16SYS    AUDIO_U16LSB
+#define AUDIO_S16SYS    AUDIO_S16LSB
 #else
-#define AUDIO_U16SYS	AUDIO_U16MSB
-#define AUDIO_S16SYS	AUDIO_S16MSB
+#define AUDIO_U16SYS    AUDIO_U16MSB
+#define AUDIO_S16SYS    AUDIO_S16MSB
 #endif
 /*@}*/
 
@@ -124,17 +124,17 @@
 
 /** A structure to hold a set of audio conversion filters and buffers */
 typedef struct SDL_AudioCVT {
-	int needed;			/**< Set to 1 if conversion possible */
-	Uint16 src_format;		/**< Source audio format */
-	Uint16 dst_format;		/**< Target audio format */
-	double rate_incr;		/**< Rate conversion increment */
-	Uint8 *buf;			/**< Buffer to hold entire audio data */
-	int    len;			/**< Length of original audio buffer */
-	int    len_cvt;			/**< Length of converted audio buffer */
-	int    len_mult;		/**< buffer must be len*len_mult big */
-	double len_ratio; 	/**< Given len, final size is len*len_ratio */
-	void (SDLCALL *filters[10])(struct SDL_AudioCVT *cvt, Uint16 format);
-	int filter_index;		/**< Current audio conversion function */
+    int needed;         /**< Set to 1 if conversion possible */
+    Uint16 src_format;      /**< Source audio format */
+    Uint16 dst_format;      /**< Target audio format */
+    double rate_incr;       /**< Rate conversion increment */
+    Uint8 *buf;         /**< Buffer to hold entire audio data */
+    int    len;         /**< Length of original audio buffer */
+    int    len_cvt;         /**< Length of converted audio buffer */
+    int    len_mult;        /**< buffer must be len*len_mult big */
+    double len_ratio;   /**< Given len, final size is len*len_ratio */
+    void (SDLCALL *filters[10])(struct SDL_AudioCVT *cvt, Uint16 format);
+    int filter_index;       /**< Current audio conversion function */
 } SDL_AudioCVT;
 
 
@@ -164,7 +164,7 @@
  * structure pointed to by 'obtained'.  If 'obtained' is NULL, the audio
  * data passed to the callback function will be guaranteed to be in the
  * requested format, and will be automatically converted to the hardware
- * audio format if necessary.  This function returns -1 if it failed 
+ * audio format if necessary.  This function returns -1 if it failed
  * to open the audio device, or couldn't set up the audio thread.
  *
  * The audio device starts out playing silence when it's opened, and should
@@ -178,9 +178,9 @@
 extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained);
 
 typedef enum {
-	SDL_AUDIO_STOPPED = 0,
-	SDL_AUDIO_PLAYING,
-	SDL_AUDIO_PAUSED
+    SDL_AUDIO_STOPPED = 0,
+    SDL_AUDIO_PLAYING,
+    SDL_AUDIO_PAUSED
 } SDL_audiostatus;
 
 /** Get the current audio state */
@@ -199,24 +199,24 @@
  * This function loads a WAVE from the data source, automatically freeing
  * that source if 'freesrc' is non-zero.  For example, to load a WAVE file,
  * you could do:
- *	@code SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...); @endcode
+ *  @code SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...); @endcode
  *
  * If this function succeeds, it returns the given SDL_AudioSpec,
  * filled with the audio data format of the wave data, and sets
  * 'audio_buf' to a malloc()'d buffer containing the audio data,
  * and sets 'audio_len' to the length of that audio buffer, in bytes.
- * You need to free the audio buffer with SDL_FreeWAV() when you are 
+ * You need to free the audio buffer with SDL_FreeWAV() when you are
  * done with it.
  *
- * This function returns NULL and sets the SDL error message if the 
- * wave file cannot be opened, uses an unknown data format, or is 
+ * This function returns NULL and sets the SDL error message if the
+ * wave file cannot be opened, uses an unknown data format, or is
  * corrupt.  Currently raw and MS-ADPCM WAVE files are supported.
  */
 extern DECLSPEC SDL_AudioSpec * SDLCALL SDL_LoadWAV_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);
 
 /** Compatibility convenience function -- loads a WAV from a file */
 #define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
-	SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
+    SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
 
 /**
  * This function frees data previously allocated with SDL_LoadWAV_RW()
@@ -232,8 +232,8 @@
  * @return This function returns 0, or -1 if there was an error.
  */
 extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
-		Uint16 src_format, Uint8 src_channels, int src_rate,
-		Uint16 dst_format, Uint8 dst_channels, int dst_rate);
+        Uint16 src_format, Uint8 src_channels, int src_rate,
+        Uint16 dst_format, Uint8 dst_channels, int dst_rate);
 
 /**
  * Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(),
--- a/misc/winutils/include/SDL_cdrom.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_cdrom.h	Tue Jan 21 22:53:15 2014 +0100
@@ -45,47 +45,47 @@
  */
 
 /** The maximum number of CD-ROM tracks on a disk */
-#define SDL_MAX_TRACKS	99
+#define SDL_MAX_TRACKS  99
 
 /** @name Track Types
  *  The types of CD-ROM track possible
  */
 /*@{*/
-#define SDL_AUDIO_TRACK	0x00
-#define SDL_DATA_TRACK	0x04
+#define SDL_AUDIO_TRACK 0x00
+#define SDL_DATA_TRACK  0x04
 /*@}*/
 
 /** The possible states which a CD-ROM drive can be in. */
 typedef enum {
-	CD_TRAYEMPTY,
-	CD_STOPPED,
-	CD_PLAYING,
-	CD_PAUSED,
-	CD_ERROR = -1
+    CD_TRAYEMPTY,
+    CD_STOPPED,
+    CD_PLAYING,
+    CD_PAUSED,
+    CD_ERROR = -1
 } CDstatus;
 
 /** Given a status, returns true if there's a disk in the drive */
-#define CD_INDRIVE(status)	((int)(status) > 0)
+#define CD_INDRIVE(status)  ((int)(status) > 0)
 
 typedef struct SDL_CDtrack {
-	Uint8 id;		/**< Track number */
-	Uint8 type;		/**< Data or audio track */
-	Uint16 unused;
-	Uint32 length;		/**< Length, in frames, of this track */
-	Uint32 offset;		/**< Offset, in frames, from start of disk */
+    Uint8 id;       /**< Track number */
+    Uint8 type;     /**< Data or audio track */
+    Uint16 unused;
+    Uint32 length;      /**< Length, in frames, of this track */
+    Uint32 offset;      /**< Offset, in frames, from start of disk */
 } SDL_CDtrack;
 
 /** This structure is only current as of the last call to SDL_CDStatus() */
 typedef struct SDL_CD {
-	int id;			/**< Private drive identifier */
-	CDstatus status;	/**< Current drive status */
+    int id;         /**< Private drive identifier */
+    CDstatus status;    /**< Current drive status */
 
-	/** The rest of this structure is only valid if there's a CD in drive */
+    /** The rest of this structure is only valid if there's a CD in drive */
         /*@{*/
-	int numtracks;		/**< Number of tracks on disk */
-	int cur_track;		/**< Current track position */
-	int cur_frame;		/**< Current frame offset within current track */
-	SDL_CDtrack track[SDL_MAX_TRACKS+1];
+    int numtracks;      /**< Number of tracks on disk */
+    int cur_track;      /**< Current track position */
+    int cur_frame;      /**< Current frame offset within current track */
+    SDL_CDtrack track[SDL_MAX_TRACKS+1];
         /*@}*/
 } SDL_CD;
 
@@ -93,16 +93,16 @@
  *  Conversion functions from frames to Minute/Second/Frames and vice versa
  */
 /*@{*/
-#define CD_FPS	75
-#define FRAMES_TO_MSF(f, M,S,F)	{					\
-	int value = f;							\
-	*(F) = value%CD_FPS;						\
-	value /= CD_FPS;						\
-	*(S) = value%60;						\
-	value /= 60;							\
-	*(M) = value;							\
+#define CD_FPS  75
+#define FRAMES_TO_MSF(f, M,S,F) {                   \
+    int value = f;                          \
+    *(F) = value%CD_FPS;                        \
+    value /= CD_FPS;                        \
+    *(S) = value%60;                        \
+    value /= 60;                            \
+    *(M) = value;                           \
 }
-#define MSF_TO_FRAMES(M, S, F)	((M)*60*CD_FPS+(S)*CD_FPS+(F))
+#define MSF_TO_FRAMES(M, S, F)  ((M)*60*CD_FPS+(S)*CD_FPS+(F))
 /*@}*/
 
 /* CD-audio API functions: */
@@ -140,28 +140,28 @@
 
 /**
  *  Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
- *  tracks and 'nframes' frames.  If both 'ntrack' and 'nframe' are 0, play 
+ *  tracks and 'nframes' frames.  If both 'ntrack' and 'nframe' are 0, play
  *  until the end of the CD.  This function will skip data tracks.
- *  This function should only be called after calling SDL_CDStatus() to 
+ *  This function should only be called after calling SDL_CDStatus() to
  *  get track information about the CD.
  *  For example:
  *      @code
- *	// Play entire CD:
- *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
- *		SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
- *	// Play last track:
- *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
- *		SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
- *	}
- *	// Play first and second track and 10 seconds of third track:
- *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
- *		SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
+ *  // Play entire CD:
+ *  if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
+ *      SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
+ *  // Play last track:
+ *  if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
+ *      SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
+ *  }
+ *  // Play first and second track and 10 seconds of third track:
+ *  if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
+ *      SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
  *      @endcode
  *
  *  @return This function returns 0, or -1 if there was an error.
  */
 extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD *cdrom,
-		int start_track, int start_frame, int ntracks, int nframes);
+        int start_track, int start_frame, int ntracks, int nframes);
 
 /**
  *  Play the given CD starting at 'start' frame for 'length' frames.
--- a/misc/winutils/include/SDL_config_win32.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_config_win32.h	Tue Jan 21 22:53:15 2014 +0100
@@ -28,16 +28,16 @@
 /* This is a set of defines to configure the SDL features */
 
 #if defined(__GNUC__) || defined(__DMC__)
-#define HAVE_STDINT_H	1
+#define HAVE_STDINT_H   1
 #elif defined(_MSC_VER)
-typedef signed __int8		int8_t;
-typedef unsigned __int8		uint8_t;
-typedef signed __int16		int16_t;
-typedef unsigned __int16	uint16_t;
-typedef signed __int32		int32_t;
-typedef unsigned __int32	uint32_t;
-typedef signed __int64		int64_t;
-typedef unsigned __int64	uint64_t;
+typedef signed __int8       int8_t;
+typedef unsigned __int8     uint8_t;
+typedef signed __int16      int16_t;
+typedef unsigned __int16    uint16_t;
+typedef signed __int32      int32_t;
+typedef unsigned __int32    uint32_t;
+typedef signed __int64      int64_t;
+typedef unsigned __int64    uint64_t;
 #ifndef _UINTPTR_T_DEFINED
 #ifdef  _WIN64
 typedef unsigned __int64    uintptr_t;
@@ -53,7 +53,7 @@
 #if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
 #define LONG_PTR LONG
 #endif
-#else	/* !__GNUC__ && !_MSC_VER */
+#else   /* !__GNUC__ && !_MSC_VER */
 typedef signed char int8_t;
 typedef unsigned char uint8_t;
 typedef signed short int16_t;
@@ -68,10 +68,10 @@
 #endif
 typedef unsigned int uintptr_t;
 #endif /* __GNUC__ || _MSC_VER */
-#define SDL_HAS_64BIT_TYPE	1
+#define SDL_HAS_64BIT_TYPE  1
 
 /* Enabled for SDL 1.2 (binary compatibility) */
-#define HAVE_LIBC	1
+#define HAVE_LIBC   1
 #ifdef HAVE_LIBC
 /* Useful headers */
 #define HAVE_STDIO_H 1
@@ -117,67 +117,67 @@
 #define HAVE__STRNICMP 1
 #define HAVE_SSCANF 1
 #else
-#define HAVE_STDARG_H	1
-#define HAVE_STDDEF_H	1
+#define HAVE_STDARG_H   1
+#define HAVE_STDDEF_H   1
 #endif
 
 /* Enable various audio drivers */
 #ifndef _WIN32_WCE
-#define SDL_AUDIO_DRIVER_DSOUND	1
+#define SDL_AUDIO_DRIVER_DSOUND 1
 #endif
-#define SDL_AUDIO_DRIVER_WAVEOUT	1
-#define SDL_AUDIO_DRIVER_DISK	1
-#define SDL_AUDIO_DRIVER_DUMMY	1
+#define SDL_AUDIO_DRIVER_WAVEOUT    1
+#define SDL_AUDIO_DRIVER_DISK   1
+#define SDL_AUDIO_DRIVER_DUMMY  1
 
 /* Enable various cdrom drivers */
 #ifdef _WIN32_WCE
 #define SDL_CDROM_DISABLED      1
 #else
-#define SDL_CDROM_WIN32		1
+#define SDL_CDROM_WIN32     1
 #endif
 
 /* Enable various input drivers */
 #ifdef _WIN32_WCE
 #define SDL_JOYSTICK_DISABLED   1
 #else
-#define SDL_JOYSTICK_WINMM	1
+#define SDL_JOYSTICK_WINMM  1
 #endif
 
 /* Enable various shared object loading systems */
-#define SDL_LOADSO_WIN32	1
+#define SDL_LOADSO_WIN32    1
 
 /* Enable various threading systems */
-#define SDL_THREAD_WIN32	1
+#define SDL_THREAD_WIN32    1
 
 /* Enable various timer systems */
 #ifdef _WIN32_WCE
-#define SDL_TIMER_WINCE	1
+#define SDL_TIMER_WINCE 1
 #else
-#define SDL_TIMER_WIN32	1
+#define SDL_TIMER_WIN32 1
 #endif
 
 /* Enable various video drivers */
 #ifdef _WIN32_WCE
-#define SDL_VIDEO_DRIVER_GAPI	1
+#define SDL_VIDEO_DRIVER_GAPI   1
 #endif
 #ifndef _WIN32_WCE
-#define SDL_VIDEO_DRIVER_DDRAW	1
+#define SDL_VIDEO_DRIVER_DDRAW  1
 #endif
-#define SDL_VIDEO_DRIVER_DUMMY	1
-#define SDL_VIDEO_DRIVER_WINDIB	1
+#define SDL_VIDEO_DRIVER_DUMMY  1
+#define SDL_VIDEO_DRIVER_WINDIB 1
 
 /* Enable OpenGL support */
 #ifndef _WIN32_WCE
-#define SDL_VIDEO_OPENGL	1
-#define SDL_VIDEO_OPENGL_WGL	1
+#define SDL_VIDEO_OPENGL    1
+#define SDL_VIDEO_OPENGL_WGL    1
 #endif
 
 /* Disable screensaver */
-#define SDL_VIDEO_DISABLE_SCREENSAVER	1
+#define SDL_VIDEO_DISABLE_SCREENSAVER   1
 
 /* Enable assembly routines (Win64 doesn't have inline asm) */
 #ifndef _WIN64
-#define SDL_ASSEMBLY_ROUTINES	1
+#define SDL_ASSEMBLY_ROUTINES   1
 #endif
 
 #endif /* _SDL_config_win32_h */
--- a/misc/winutils/include/SDL_endian.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_endian.h	Tue Jan 21 22:53:15 2014 +0100
@@ -31,14 +31,14 @@
 #include "SDL_stdinc.h"
 
 /** @name SDL_ENDIANs
- *  The two types of endianness 
+ *  The two types of endianness
  */
 /*@{*/
-#define SDL_LIL_ENDIAN	1234
-#define SDL_BIG_ENDIAN	4321
+#define SDL_LIL_ENDIAN  1234
+#define SDL_BIG_ENDIAN  4321
 /*@}*/
 
-#ifndef SDL_BYTEORDER	/* Not defined in SDL_config.h? */
+#ifndef SDL_BYTEORDER   /* Not defined in SDL_config.h? */
 #ifdef __linux__
 #include <endian.h>
 #define SDL_BYTEORDER  __BYTE_ORDER
@@ -48,9 +48,9 @@
     (defined(__MIPS__) && defined(__MISPEB__)) || \
     defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
     defined(__sparc__)
-#define SDL_BYTEORDER	SDL_BIG_ENDIAN
+#define SDL_BYTEORDER   SDL_BIG_ENDIAN
 #else
-#define SDL_BYTEORDER	SDL_LIL_ENDIAN
+#define SDL_BYTEORDER   SDL_LIL_ENDIAN
 #endif
 #endif /* __linux __ */
 #endif /* !SDL_BYTEORDER */
@@ -74,32 +74,32 @@
    !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
 static __inline__ Uint16 SDL_Swap16(Uint16 x)
 {
-	__asm__("xchgb %b0,%h0" : "=q" (x) :  "0" (x));
-	return x;
+    __asm__("xchgb %b0,%h0" : "=q" (x) :  "0" (x));
+    return x;
 }
 #elif defined(__GNUC__) && defined(__x86_64__)
 static __inline__ Uint16 SDL_Swap16(Uint16 x)
 {
-	__asm__("xchgb %b0,%h0" : "=Q" (x) :  "0" (x));
-	return x;
+    __asm__("xchgb %b0,%h0" : "=Q" (x) :  "0" (x));
+    return x;
 }
 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
 static __inline__ Uint16 SDL_Swap16(Uint16 x)
 {
-	Uint16 result;
+    Uint16 result;
 
-	__asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x));
-	return result;
+    __asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x));
+    return result;
 }
 #elif defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__))
 static __inline__ Uint16 SDL_Swap16(Uint16 x)
 {
-	__asm__("rorw #8,%0" : "=d" (x) :  "0" (x) : "cc");
-	return x;
+    __asm__("rorw #8,%0" : "=d" (x) :  "0" (x) : "cc");
+    return x;
 }
 #else
 static __inline__ Uint16 SDL_Swap16(Uint16 x) {
-	return SDL_static_cast(Uint16, ((x<<8)|(x>>8)));
+    return SDL_static_cast(Uint16, ((x<<8)|(x>>8)));
 }
 #endif
 
@@ -107,34 +107,34 @@
    !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
 static __inline__ Uint32 SDL_Swap32(Uint32 x)
 {
-	__asm__("bswap %0" : "=r" (x) : "0" (x));
-	return x;
+    __asm__("bswap %0" : "=r" (x) : "0" (x));
+    return x;
 }
 #elif defined(__GNUC__) && defined(__x86_64__)
 static __inline__ Uint32 SDL_Swap32(Uint32 x)
 {
-	__asm__("bswapl %0" : "=r" (x) : "0" (x));
-	return x;
+    __asm__("bswapl %0" : "=r" (x) : "0" (x));
+    return x;
 }
 #elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
 static __inline__ Uint32 SDL_Swap32(Uint32 x)
 {
-	Uint32 result;
+    Uint32 result;
 
-	__asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x));
-	__asm__("rlwimi %0,%2,8,8,15"   : "=&r" (result) : "0" (result),    "r" (x));
-	__asm__("rlwimi %0,%2,24,0,7"   : "=&r" (result) : "0" (result),    "r" (x));
-	return result;
+    __asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x));
+    __asm__("rlwimi %0,%2,8,8,15"   : "=&r" (result) : "0" (result),    "r" (x));
+    __asm__("rlwimi %0,%2,24,0,7"   : "=&r" (result) : "0" (result),    "r" (x));
+    return result;
 }
 #elif defined(__GNUC__) && (defined(__m68k__) && !defined(__mcoldfire__))
 static __inline__ Uint32 SDL_Swap32(Uint32 x)
 {
-	__asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) :  "0" (x) : "cc");
-	return x;
+    __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0" : "=d" (x) :  "0" (x) : "cc");
+    return x;
 }
 #else
 static __inline__ Uint32 SDL_Swap32(Uint32 x) {
-	return SDL_static_cast(Uint32, ((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24)));
+    return SDL_static_cast(Uint32, ((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24)));
 }
 #endif
 
@@ -143,35 +143,35 @@
    !(__GNUC__ == 2 && __GNUC_MINOR__ <= 95 /* broken gcc version */)
 static __inline__ Uint64 SDL_Swap64(Uint64 x)
 {
-	union { 
-		struct { Uint32 a,b; } s;
-		Uint64 u;
-	} v;
-	v.u = x;
-	__asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1" 
-	        : "=r" (v.s.a), "=r" (v.s.b) 
-	        : "0" (v.s.a), "1" (v.s.b)); 
-	return v.u;
+    union {
+        struct { Uint32 a,b; } s;
+        Uint64 u;
+    } v;
+    v.u = x;
+    __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1"
+            : "=r" (v.s.a), "=r" (v.s.b)
+            : "0" (v.s.a), "1" (v.s.b));
+    return v.u;
 }
 #elif defined(__GNUC__) && defined(__x86_64__)
 static __inline__ Uint64 SDL_Swap64(Uint64 x)
 {
-	__asm__("bswapq %0" : "=r" (x) : "0" (x));
-	return x;
+    __asm__("bswapq %0" : "=r" (x) : "0" (x));
+    return x;
 }
 #else
 static __inline__ Uint64 SDL_Swap64(Uint64 x)
 {
-	Uint32 hi, lo;
+    Uint32 hi, lo;
 
-	/* Separate into high and low 32-bit values and swap them */
-	lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
-	x >>= 32;
-	hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
-	x = SDL_Swap32(lo);
-	x <<= 32;
-	x |= SDL_Swap32(hi);
-	return (x);
+    /* Separate into high and low 32-bit values and swap them */
+    lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
+    x >>= 32;
+    hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
+    x = SDL_Swap32(lo);
+    x <<= 32;
+    x |= SDL_Swap32(hi);
+    return (x);
 }
 #endif
 #else
@@ -179,7 +179,7 @@
  * If there is no real 64-bit datatype, then compilers will complain about
  * the fake 64-bit datatype that SDL provides when it compiles user code.
  */
-#define SDL_Swap64(X)	(X)
+#define SDL_Swap64(X)   (X)
 #endif /* SDL_HAS_64BIT_TYPE */
 /*@}*/
 
@@ -189,19 +189,19 @@
  */
 /*@{*/
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
-#define SDL_SwapLE16(X)	(X)
-#define SDL_SwapLE32(X)	(X)
-#define SDL_SwapLE64(X)	(X)
-#define SDL_SwapBE16(X)	SDL_Swap16(X)
-#define SDL_SwapBE32(X)	SDL_Swap32(X)
-#define SDL_SwapBE64(X)	SDL_Swap64(X)
+#define SDL_SwapLE16(X) (X)
+#define SDL_SwapLE32(X) (X)
+#define SDL_SwapLE64(X) (X)
+#define SDL_SwapBE16(X) SDL_Swap16(X)
+#define SDL_SwapBE32(X) SDL_Swap32(X)
+#define SDL_SwapBE64(X) SDL_Swap64(X)
 #else
-#define SDL_SwapLE16(X)	SDL_Swap16(X)
-#define SDL_SwapLE32(X)	SDL_Swap32(X)
-#define SDL_SwapLE64(X)	SDL_Swap64(X)
-#define SDL_SwapBE16(X)	(X)
-#define SDL_SwapBE32(X)	(X)
-#define SDL_SwapBE64(X)	(X)
+#define SDL_SwapLE16(X) SDL_Swap16(X)
+#define SDL_SwapLE32(X) SDL_Swap32(X)
+#define SDL_SwapLE64(X) SDL_Swap64(X)
+#define SDL_SwapBE16(X) (X)
+#define SDL_SwapBE32(X) (X)
+#define SDL_SwapBE64(X) (X)
 #endif
 /*@}*/
 
--- a/misc/winutils/include/SDL_error.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_error.h	Tue Jan 21 22:53:15 2014 +0100
@@ -36,7 +36,7 @@
 extern "C" {
 #endif
 
-/** 
+/**
  *  @name Public functions
  */
 /*@{*/
@@ -50,15 +50,15 @@
  *  @internal Private error message function - used internally
  */
 /*@{*/
-#define SDL_OutOfMemory()	SDL_Error(SDL_ENOMEM)
-#define SDL_Unsupported()	SDL_Error(SDL_UNSUPPORTED)
+#define SDL_OutOfMemory()   SDL_Error(SDL_ENOMEM)
+#define SDL_Unsupported()   SDL_Error(SDL_UNSUPPORTED)
 typedef enum {
-	SDL_ENOMEM,
-	SDL_EFREAD,
-	SDL_EFWRITE,
-	SDL_EFSEEK,
-	SDL_UNSUPPORTED,
-	SDL_LASTERROR
+    SDL_ENOMEM,
+    SDL_EFREAD,
+    SDL_EFWRITE,
+    SDL_EFSEEK,
+    SDL_UNSUPPORTED,
+    SDL_LASTERROR
 } SDL_errorcode;
 extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code);
 /*@}*/
--- a/misc/winutils/include/SDL_events.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_events.h	Tue Jan 21 22:53:15 2014 +0100
@@ -44,147 +44,147 @@
 
 /** @name General keyboard/mouse state definitions */
 /*@{*/
-#define SDL_RELEASED	0
-#define SDL_PRESSED	1
+#define SDL_RELEASED    0
+#define SDL_PRESSED 1
 /*@}*/
 
 /** Event enumerations */
 typedef enum {
-       SDL_NOEVENT = 0,			/**< Unused (do not remove) */
-       SDL_ACTIVEEVENT,			/**< Application loses/gains visibility */
-       SDL_KEYDOWN,			/**< Keys pressed */
-       SDL_KEYUP,			/**< Keys released */
-       SDL_MOUSEMOTION,			/**< Mouse moved */
-       SDL_MOUSEBUTTONDOWN,		/**< Mouse button pressed */
-       SDL_MOUSEBUTTONUP,		/**< Mouse button released */
-       SDL_JOYAXISMOTION,		/**< Joystick axis motion */
-       SDL_JOYBALLMOTION,		/**< Joystick trackball motion */
-       SDL_JOYHATMOTION,		/**< Joystick hat position change */
-       SDL_JOYBUTTONDOWN,		/**< Joystick button pressed */
-       SDL_JOYBUTTONUP,			/**< Joystick button released */
-       SDL_QUIT,			/**< User-requested quit */
-       SDL_SYSWMEVENT,			/**< System specific event */
-       SDL_EVENT_RESERVEDA,		/**< Reserved for future use.. */
-       SDL_EVENT_RESERVEDB,		/**< Reserved for future use.. */
-       SDL_VIDEORESIZE,			/**< User resized video mode */
-       SDL_VIDEOEXPOSE,			/**< Screen needs to be redrawn */
-       SDL_EVENT_RESERVED2,		/**< Reserved for future use.. */
-       SDL_EVENT_RESERVED3,		/**< Reserved for future use.. */
-       SDL_EVENT_RESERVED4,		/**< Reserved for future use.. */
-       SDL_EVENT_RESERVED5,		/**< Reserved for future use.. */
-       SDL_EVENT_RESERVED6,		/**< Reserved for future use.. */
-       SDL_EVENT_RESERVED7,		/**< Reserved for future use.. */
+       SDL_NOEVENT = 0,         /**< Unused (do not remove) */
+       SDL_ACTIVEEVENT,         /**< Application loses/gains visibility */
+       SDL_KEYDOWN,         /**< Keys pressed */
+       SDL_KEYUP,           /**< Keys released */
+       SDL_MOUSEMOTION,         /**< Mouse moved */
+       SDL_MOUSEBUTTONDOWN,     /**< Mouse button pressed */
+       SDL_MOUSEBUTTONUP,       /**< Mouse button released */
+       SDL_JOYAXISMOTION,       /**< Joystick axis motion */
+       SDL_JOYBALLMOTION,       /**< Joystick trackball motion */
+       SDL_JOYHATMOTION,        /**< Joystick hat position change */
+       SDL_JOYBUTTONDOWN,       /**< Joystick button pressed */
+       SDL_JOYBUTTONUP,         /**< Joystick button released */
+       SDL_QUIT,            /**< User-requested quit */
+       SDL_SYSWMEVENT,          /**< System specific event */
+       SDL_EVENT_RESERVEDA,     /**< Reserved for future use.. */
+       SDL_EVENT_RESERVEDB,     /**< Reserved for future use.. */
+       SDL_VIDEORESIZE,         /**< User resized video mode */
+       SDL_VIDEOEXPOSE,         /**< Screen needs to be redrawn */
+       SDL_EVENT_RESERVED2,     /**< Reserved for future use.. */
+       SDL_EVENT_RESERVED3,     /**< Reserved for future use.. */
+       SDL_EVENT_RESERVED4,     /**< Reserved for future use.. */
+       SDL_EVENT_RESERVED5,     /**< Reserved for future use.. */
+       SDL_EVENT_RESERVED6,     /**< Reserved for future use.. */
+       SDL_EVENT_RESERVED7,     /**< Reserved for future use.. */
        /** Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
        SDL_USEREVENT = 24,
        /** This last event is only for bounding internal arrays
-	*  It is the number of bits in the event mask datatype -- Uint32
+    *  It is the number of bits in the event mask datatype -- Uint32
         */
        SDL_NUMEVENTS = 32
 } SDL_EventType;
 
 /** @name Predefined event masks */
 /*@{*/
-#define SDL_EVENTMASK(X)	(1<<(X))
+#define SDL_EVENTMASK(X)    (1<<(X))
 typedef enum {
-	SDL_ACTIVEEVENTMASK	= SDL_EVENTMASK(SDL_ACTIVEEVENT),
-	SDL_KEYDOWNMASK		= SDL_EVENTMASK(SDL_KEYDOWN),
-	SDL_KEYUPMASK		= SDL_EVENTMASK(SDL_KEYUP),
-	SDL_KEYEVENTMASK	= SDL_EVENTMASK(SDL_KEYDOWN)|
-	                          SDL_EVENTMASK(SDL_KEYUP),
-	SDL_MOUSEMOTIONMASK	= SDL_EVENTMASK(SDL_MOUSEMOTION),
-	SDL_MOUSEBUTTONDOWNMASK	= SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
-	SDL_MOUSEBUTTONUPMASK	= SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
-	SDL_MOUSEEVENTMASK	= SDL_EVENTMASK(SDL_MOUSEMOTION)|
-	                          SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|
-	                          SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
-	SDL_JOYAXISMOTIONMASK	= SDL_EVENTMASK(SDL_JOYAXISMOTION),
-	SDL_JOYBALLMOTIONMASK	= SDL_EVENTMASK(SDL_JOYBALLMOTION),
-	SDL_JOYHATMOTIONMASK	= SDL_EVENTMASK(SDL_JOYHATMOTION),
-	SDL_JOYBUTTONDOWNMASK	= SDL_EVENTMASK(SDL_JOYBUTTONDOWN),
-	SDL_JOYBUTTONUPMASK	= SDL_EVENTMASK(SDL_JOYBUTTONUP),
-	SDL_JOYEVENTMASK	= SDL_EVENTMASK(SDL_JOYAXISMOTION)|
-	                          SDL_EVENTMASK(SDL_JOYBALLMOTION)|
-	                          SDL_EVENTMASK(SDL_JOYHATMOTION)|
-	                          SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|
-	                          SDL_EVENTMASK(SDL_JOYBUTTONUP),
-	SDL_VIDEORESIZEMASK	= SDL_EVENTMASK(SDL_VIDEORESIZE),
-	SDL_VIDEOEXPOSEMASK	= SDL_EVENTMASK(SDL_VIDEOEXPOSE),
-	SDL_QUITMASK		= SDL_EVENTMASK(SDL_QUIT),
-	SDL_SYSWMEVENTMASK	= SDL_EVENTMASK(SDL_SYSWMEVENT)
+    SDL_ACTIVEEVENTMASK = SDL_EVENTMASK(SDL_ACTIVEEVENT),
+    SDL_KEYDOWNMASK     = SDL_EVENTMASK(SDL_KEYDOWN),
+    SDL_KEYUPMASK       = SDL_EVENTMASK(SDL_KEYUP),
+    SDL_KEYEVENTMASK    = SDL_EVENTMASK(SDL_KEYDOWN)|
+                              SDL_EVENTMASK(SDL_KEYUP),
+    SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION),
+    SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
+    SDL_MOUSEBUTTONUPMASK   = SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
+    SDL_MOUSEEVENTMASK  = SDL_EVENTMASK(SDL_MOUSEMOTION)|
+                              SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|
+                              SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
+    SDL_JOYAXISMOTIONMASK   = SDL_EVENTMASK(SDL_JOYAXISMOTION),
+    SDL_JOYBALLMOTIONMASK   = SDL_EVENTMASK(SDL_JOYBALLMOTION),
+    SDL_JOYHATMOTIONMASK    = SDL_EVENTMASK(SDL_JOYHATMOTION),
+    SDL_JOYBUTTONDOWNMASK   = SDL_EVENTMASK(SDL_JOYBUTTONDOWN),
+    SDL_JOYBUTTONUPMASK = SDL_EVENTMASK(SDL_JOYBUTTONUP),
+    SDL_JOYEVENTMASK    = SDL_EVENTMASK(SDL_JOYAXISMOTION)|
+                              SDL_EVENTMASK(SDL_JOYBALLMOTION)|
+                              SDL_EVENTMASK(SDL_JOYHATMOTION)|
+                              SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|
+                              SDL_EVENTMASK(SDL_JOYBUTTONUP),
+    SDL_VIDEORESIZEMASK = SDL_EVENTMASK(SDL_VIDEORESIZE),
+    SDL_VIDEOEXPOSEMASK = SDL_EVENTMASK(SDL_VIDEOEXPOSE),
+    SDL_QUITMASK        = SDL_EVENTMASK(SDL_QUIT),
+    SDL_SYSWMEVENTMASK  = SDL_EVENTMASK(SDL_SYSWMEVENT)
 } SDL_EventMask ;
-#define SDL_ALLEVENTS		0xFFFFFFFF
+#define SDL_ALLEVENTS       0xFFFFFFFF
 /*@}*/
 
 /** Application visibility event structure */
 typedef struct SDL_ActiveEvent {
-	Uint8 type;	/**< SDL_ACTIVEEVENT */
-	Uint8 gain;	/**< Whether given states were gained or lost (1/0) */
-	Uint8 state;	/**< A mask of the focus states */
+    Uint8 type; /**< SDL_ACTIVEEVENT */
+    Uint8 gain; /**< Whether given states were gained or lost (1/0) */
+    Uint8 state;    /**< A mask of the focus states */
 } SDL_ActiveEvent;
 
 /** Keyboard event structure */
 typedef struct SDL_KeyboardEvent {
-	Uint8 type;	/**< SDL_KEYDOWN or SDL_KEYUP */
-	Uint8 which;	/**< The keyboard device index */
-	Uint8 state;	/**< SDL_PRESSED or SDL_RELEASED */
-	SDL_keysym keysym;
+    Uint8 type; /**< SDL_KEYDOWN or SDL_KEYUP */
+    Uint8 which;    /**< The keyboard device index */
+    Uint8 state;    /**< SDL_PRESSED or SDL_RELEASED */
+    SDL_keysym keysym;
 } SDL_KeyboardEvent;
 
 /** Mouse motion event structure */
 typedef struct SDL_MouseMotionEvent {
-	Uint8 type;	/**< SDL_MOUSEMOTION */
-	Uint8 which;	/**< The mouse device index */
-	Uint8 state;	/**< The current button state */
-	Uint16 x, y;	/**< The X/Y coordinates of the mouse */
-	Sint16 xrel;	/**< The relative motion in the X direction */
-	Sint16 yrel;	/**< The relative motion in the Y direction */
+    Uint8 type; /**< SDL_MOUSEMOTION */
+    Uint8 which;    /**< The mouse device index */
+    Uint8 state;    /**< The current button state */
+    Uint16 x, y;    /**< The X/Y coordinates of the mouse */
+    Sint16 xrel;    /**< The relative motion in the X direction */
+    Sint16 yrel;    /**< The relative motion in the Y direction */
 } SDL_MouseMotionEvent;
 
 /** Mouse button event structure */
 typedef struct SDL_MouseButtonEvent {
-	Uint8 type;	/**< SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
-	Uint8 which;	/**< The mouse device index */
-	Uint8 button;	/**< The mouse button index */
-	Uint8 state;	/**< SDL_PRESSED or SDL_RELEASED */
-	Uint16 x, y;	/**< The X/Y coordinates of the mouse at press time */
+    Uint8 type; /**< SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
+    Uint8 which;    /**< The mouse device index */
+    Uint8 button;   /**< The mouse button index */
+    Uint8 state;    /**< SDL_PRESSED or SDL_RELEASED */
+    Uint16 x, y;    /**< The X/Y coordinates of the mouse at press time */
 } SDL_MouseButtonEvent;
 
 /** Joystick axis motion event structure */
 typedef struct SDL_JoyAxisEvent {
-	Uint8 type;	/**< SDL_JOYAXISMOTION */
-	Uint8 which;	/**< The joystick device index */
-	Uint8 axis;	/**< The joystick axis index */
-	Sint16 value;	/**< The axis value (range: -32768 to 32767) */
+    Uint8 type; /**< SDL_JOYAXISMOTION */
+    Uint8 which;    /**< The joystick device index */
+    Uint8 axis; /**< The joystick axis index */
+    Sint16 value;   /**< The axis value (range: -32768 to 32767) */
 } SDL_JoyAxisEvent;
 
 /** Joystick trackball motion event structure */
 typedef struct SDL_JoyBallEvent {
-	Uint8 type;	/**< SDL_JOYBALLMOTION */
-	Uint8 which;	/**< The joystick device index */
-	Uint8 ball;	/**< The joystick trackball index */
-	Sint16 xrel;	/**< The relative motion in the X direction */
-	Sint16 yrel;	/**< The relative motion in the Y direction */
+    Uint8 type; /**< SDL_JOYBALLMOTION */
+    Uint8 which;    /**< The joystick device index */
+    Uint8 ball; /**< The joystick trackball index */
+    Sint16 xrel;    /**< The relative motion in the X direction */
+    Sint16 yrel;    /**< The relative motion in the Y direction */
 } SDL_JoyBallEvent;
 
 /** Joystick hat position change event structure */
 typedef struct SDL_JoyHatEvent {
-	Uint8 type;	/**< SDL_JOYHATMOTION */
-	Uint8 which;	/**< The joystick device index */
-	Uint8 hat;	/**< The joystick hat index */
-	Uint8 value;	/**< The hat position value:
-			 *   SDL_HAT_LEFTUP   SDL_HAT_UP       SDL_HAT_RIGHTUP
-			 *   SDL_HAT_LEFT     SDL_HAT_CENTERED SDL_HAT_RIGHT
-			 *   SDL_HAT_LEFTDOWN SDL_HAT_DOWN     SDL_HAT_RIGHTDOWN
-			 *  Note that zero means the POV is centered.
-			 */
+    Uint8 type; /**< SDL_JOYHATMOTION */
+    Uint8 which;    /**< The joystick device index */
+    Uint8 hat;  /**< The joystick hat index */
+    Uint8 value;    /**< The hat position value:
+             *   SDL_HAT_LEFTUP   SDL_HAT_UP       SDL_HAT_RIGHTUP
+             *   SDL_HAT_LEFT     SDL_HAT_CENTERED SDL_HAT_RIGHT
+             *   SDL_HAT_LEFTDOWN SDL_HAT_DOWN     SDL_HAT_RIGHTDOWN
+             *  Note that zero means the POV is centered.
+             */
 } SDL_JoyHatEvent;
 
 /** Joystick button event structure */
 typedef struct SDL_JoyButtonEvent {
-	Uint8 type;	/**< SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
-	Uint8 which;	/**< The joystick device index */
-	Uint8 button;	/**< The joystick button index */
-	Uint8 state;	/**< SDL_PRESSED or SDL_RELEASED */
+    Uint8 type; /**< SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
+    Uint8 which;    /**< The joystick device index */
+    Uint8 button;   /**< The joystick button index */
+    Uint8 state;    /**< SDL_PRESSED or SDL_RELEASED */
 } SDL_JoyButtonEvent;
 
 /** The "window resized" event
@@ -192,53 +192,53 @@
  *  mode with the new width and height.
  */
 typedef struct SDL_ResizeEvent {
-	Uint8 type;	/**< SDL_VIDEORESIZE */
-	int w;		/**< New width */
-	int h;		/**< New height */
+    Uint8 type; /**< SDL_VIDEORESIZE */
+    int w;      /**< New width */
+    int h;      /**< New height */
 } SDL_ResizeEvent;
 
 /** The "screen redraw" event */
 typedef struct SDL_ExposeEvent {
-	Uint8 type;	/**< SDL_VIDEOEXPOSE */
+    Uint8 type; /**< SDL_VIDEOEXPOSE */
 } SDL_ExposeEvent;
 
 /** The "quit requested" event */
 typedef struct SDL_QuitEvent {
-	Uint8 type;	/**< SDL_QUIT */
+    Uint8 type; /**< SDL_QUIT */
 } SDL_QuitEvent;
 
 /** A user-defined event type */
 typedef struct SDL_UserEvent {
-	Uint8 type;	/**< SDL_USEREVENT through SDL_NUMEVENTS-1 */
-	int code;	/**< User defined event code */
-	void *data1;	/**< User defined data pointer */
-	void *data2;	/**< User defined data pointer */
+    Uint8 type; /**< SDL_USEREVENT through SDL_NUMEVENTS-1 */
+    int code;   /**< User defined event code */
+    void *data1;    /**< User defined data pointer */
+    void *data2;    /**< User defined data pointer */
 } SDL_UserEvent;
 
 /** If you want to use this event, you should include SDL_syswm.h */
 struct SDL_SysWMmsg;
 typedef struct SDL_SysWMmsg SDL_SysWMmsg;
 typedef struct SDL_SysWMEvent {
-	Uint8 type;
-	SDL_SysWMmsg *msg;
+    Uint8 type;
+    SDL_SysWMmsg *msg;
 } SDL_SysWMEvent;
 
 /** General event structure */
 typedef union SDL_Event {
-	Uint8 type;
-	SDL_ActiveEvent active;
-	SDL_KeyboardEvent key;
-	SDL_MouseMotionEvent motion;
-	SDL_MouseButtonEvent button;
-	SDL_JoyAxisEvent jaxis;
-	SDL_JoyBallEvent jball;
-	SDL_JoyHatEvent jhat;
-	SDL_JoyButtonEvent jbutton;
-	SDL_ResizeEvent resize;
-	SDL_ExposeEvent expose;
-	SDL_QuitEvent quit;
-	SDL_UserEvent user;
-	SDL_SysWMEvent syswm;
+    Uint8 type;
+    SDL_ActiveEvent active;
+    SDL_KeyboardEvent key;
+    SDL_MouseMotionEvent motion;
+    SDL_MouseButtonEvent button;
+    SDL_JoyAxisEvent jaxis;
+    SDL_JoyBallEvent jball;
+    SDL_JoyHatEvent jhat;
+    SDL_JoyButtonEvent jbutton;
+    SDL_ResizeEvent resize;
+    SDL_ExposeEvent expose;
+    SDL_QuitEvent quit;
+    SDL_UserEvent user;
+    SDL_SysWMEvent syswm;
 } SDL_Event;
 
 
@@ -251,9 +251,9 @@
 extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
 
 typedef enum {
-	SDL_ADDEVENT,
-	SDL_PEEKEVENT,
-	SDL_GETEVENT
+    SDL_ADDEVENT,
+    SDL_PEEKEVENT,
+    SDL_GETEVENT
 } SDL_eventaction;
 
 /**
@@ -264,7 +264,7 @@
  *  If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front
  *  of the event queue, matching 'mask', will be returned and will not
  *  be removed from the queue.
- *  If 'action' is SDL_GETEVENT, up to 'numevents' events at the front 
+ *  If 'action' is SDL_GETEVENT, up to 'numevents' events at the front
  *  of the event queue, matching 'mask', will be returned and will be
  *  removed from the queue.
  *
@@ -275,7 +275,7 @@
  *  This function is thread-safe.
  */
 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event *events, int numevents,
-				SDL_eventaction action, Uint32 mask);
+                SDL_eventaction action, Uint32 mask);
 
 /** Polls for currently pending events, and returns 1 if there are any pending
  *  events, or 0 if there are none available.  If 'event' is not NULL, the next
@@ -306,11 +306,11 @@
  *      @code typedef int (SDLCALL *SDL_EventFilter)(const SDL_Event *event); @endcode
  *
  * If the filter returns 1, then the event will be added to the internal queue.
- * If it returns 0, then the event will be dropped from the queue, but the 
+ * If it returns 0, then the event will be dropped from the queue, but the
  * internal state will still be updated.  This allows selective filtering of
  * dynamically arriving events.
  *
- * @warning  Be very careful of what you do in the event filter function, as 
+ * @warning  Be very careful of what you do in the event filter function, as
  *           it may run in a different thread!
  *
  * There is one caveat when dealing with the SDL_QUITEVENT event type.  The
@@ -331,10 +331,10 @@
 
 /** @name Event State */
 /*@{*/
-#define SDL_QUERY	-1
-#define SDL_IGNORE	 0
-#define SDL_DISABLE	 0
-#define SDL_ENABLE	 1
+#define SDL_QUERY   -1
+#define SDL_IGNORE   0
+#define SDL_DISABLE  0
+#define SDL_ENABLE   1
 /*@}*/
 
 /**
@@ -342,7 +342,7 @@
 * If 'state' is set to SDL_IGNORE, that event will be automatically dropped
 * from the event queue and will not event be filtered.
 * If 'state' is set to SDL_ENABLE, that event will be processed normally.
-* If 'state' is set to SDL_QUERY, SDL_EventState() will return the 
+* If 'state' is set to SDL_QUERY, SDL_EventState() will return the
 * current processing state of the specified event.
 */
 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint8 type, int state);
--- a/misc/winutils/include/SDL_joystick.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_joystick.h	Tue Jan 21 22:53:15 2014 +0100
@@ -138,18 +138,18 @@
  *  The return value of SDL_JoystickGetHat() is one of the following positions:
  */
 /*@{*/
-#define SDL_HAT_CENTERED	0x00
-#define SDL_HAT_UP		0x01
-#define SDL_HAT_RIGHT		0x02
-#define SDL_HAT_DOWN		0x04
-#define SDL_HAT_LEFT		0x08
-#define SDL_HAT_RIGHTUP		(SDL_HAT_RIGHT|SDL_HAT_UP)
-#define SDL_HAT_RIGHTDOWN	(SDL_HAT_RIGHT|SDL_HAT_DOWN)
-#define SDL_HAT_LEFTUP		(SDL_HAT_LEFT|SDL_HAT_UP)
-#define SDL_HAT_LEFTDOWN	(SDL_HAT_LEFT|SDL_HAT_DOWN)
+#define SDL_HAT_CENTERED    0x00
+#define SDL_HAT_UP      0x01
+#define SDL_HAT_RIGHT       0x02
+#define SDL_HAT_DOWN        0x04
+#define SDL_HAT_LEFT        0x08
+#define SDL_HAT_RIGHTUP     (SDL_HAT_RIGHT|SDL_HAT_UP)
+#define SDL_HAT_RIGHTDOWN   (SDL_HAT_RIGHT|SDL_HAT_DOWN)
+#define SDL_HAT_LEFTUP      (SDL_HAT_LEFT|SDL_HAT_UP)
+#define SDL_HAT_LEFTDOWN    (SDL_HAT_LEFT|SDL_HAT_DOWN)
 /*@}*/
 
-/** 
+/**
  *  Get the current state of a POV hat on a joystick
  *
  *  @param[in] hat The hat indices start at index 0.
--- a/misc/winutils/include/SDL_keyboard.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_keyboard.h	Tue Jan 21 22:53:15 2014 +0100
@@ -48,23 +48,23 @@
  *    high 9 bits of the character are 0, then this maps to the equivalent
  *    ASCII character:
  *      @code
- *	char ch;
- *	if ( (keysym.unicode & 0xFF80) == 0 ) {
- *		ch = keysym.unicode & 0x7F;
- *	} else {
- *		An international character..
- *	}
+ *  char ch;
+ *  if ( (keysym.unicode & 0xFF80) == 0 ) {
+ *      ch = keysym.unicode & 0x7F;
+ *  } else {
+ *      An international character..
+ *  }
  *      @endcode
  */
 typedef struct SDL_keysym {
-	Uint8 scancode;			/**< hardware specific scancode */
-	SDLKey sym;			/**< SDL virtual keysym */
-	SDLMod mod;			/**< current key modifiers */
-	Uint16 unicode;			/**< translated character */
+    Uint8 scancode;         /**< hardware specific scancode */
+    SDLKey sym;         /**< SDL virtual keysym */
+    SDLMod mod;         /**< current key modifiers */
+    Uint16 unicode;         /**< translated character */
 } SDL_keysym;
 
 /** This is the mask which refers to all hotkey bindings */
-#define SDL_ALL_HOTKEYS		0xFFFFFFFF
+#define SDL_ALL_HOTKEYS     0xFFFFFFFF
 
 /* Function prototypes */
 /**
@@ -81,8 +81,8 @@
  */
 extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
 
-#define SDL_DEFAULT_REPEAT_DELAY	500
-#define SDL_DEFAULT_REPEAT_INTERVAL	30
+#define SDL_DEFAULT_REPEAT_DELAY    500
+#define SDL_DEFAULT_REPEAT_INTERVAL 30
 /**
  * Enable/Disable keyboard repeat.  Keyboard repeat defaults to off.
  *
@@ -102,10 +102,10 @@
  * Get a snapshot of the current state of the keyboard.
  * Returns an array of keystates, indexed by the SDLK_* syms.
  * Usage:
- *	@code
- * 	Uint8 *keystate = SDL_GetKeyState(NULL);
- *	if ( keystate[SDLK_RETURN] ) //... \<RETURN> is pressed.
- *	@endcode
+ *  @code
+ *  Uint8 *keystate = SDL_GetKeyState(NULL);
+ *  if ( keystate[SDLK_RETURN] ) //... \<RETURN> is pressed.
+ *  @endcode
  */
 extern DECLSPEC Uint8 * SDLCALL SDL_GetKeyState(int *numkeys);
 
--- a/misc/winutils/include/SDL_keysym.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_keysym.h	Tue Jan 21 22:53:15 2014 +0100
@@ -33,294 +33,294 @@
          *  The keyboard syms have been cleverly chosen to map to ASCII
          */
         /*@{*/
-	SDLK_UNKNOWN		= 0,
-	SDLK_FIRST		= 0,
-	SDLK_BACKSPACE		= 8,
-	SDLK_TAB		= 9,
-	SDLK_CLEAR		= 12,
-	SDLK_RETURN		= 13,
-	SDLK_PAUSE		= 19,
-	SDLK_ESCAPE		= 27,
-	SDLK_SPACE		= 32,
-	SDLK_EXCLAIM		= 33,
-	SDLK_QUOTEDBL		= 34,
-	SDLK_HASH		= 35,
-	SDLK_DOLLAR		= 36,
-	SDLK_AMPERSAND		= 38,
-	SDLK_QUOTE		= 39,
-	SDLK_LEFTPAREN		= 40,
-	SDLK_RIGHTPAREN		= 41,
-	SDLK_ASTERISK		= 42,
-	SDLK_PLUS		= 43,
-	SDLK_COMMA		= 44,
-	SDLK_MINUS		= 45,
-	SDLK_PERIOD		= 46,
-	SDLK_SLASH		= 47,
-	SDLK_0			= 48,
-	SDLK_1			= 49,
-	SDLK_2			= 50,
-	SDLK_3			= 51,
-	SDLK_4			= 52,
-	SDLK_5			= 53,
-	SDLK_6			= 54,
-	SDLK_7			= 55,
-	SDLK_8			= 56,
-	SDLK_9			= 57,
-	SDLK_COLON		= 58,
-	SDLK_SEMICOLON		= 59,
-	SDLK_LESS		= 60,
-	SDLK_EQUALS		= 61,
-	SDLK_GREATER		= 62,
-	SDLK_QUESTION		= 63,
-	SDLK_AT			= 64,
-	/* 
-	   Skip uppercase letters
-	 */
-	SDLK_LEFTBRACKET	= 91,
-	SDLK_BACKSLASH		= 92,
-	SDLK_RIGHTBRACKET	= 93,
-	SDLK_CARET		= 94,
-	SDLK_UNDERSCORE		= 95,
-	SDLK_BACKQUOTE		= 96,
-	SDLK_a			= 97,
-	SDLK_b			= 98,
-	SDLK_c			= 99,
-	SDLK_d			= 100,
-	SDLK_e			= 101,
-	SDLK_f			= 102,
-	SDLK_g			= 103,
-	SDLK_h			= 104,
-	SDLK_i			= 105,
-	SDLK_j			= 106,
-	SDLK_k			= 107,
-	SDLK_l			= 108,
-	SDLK_m			= 109,
-	SDLK_n			= 110,
-	SDLK_o			= 111,
-	SDLK_p			= 112,
-	SDLK_q			= 113,
-	SDLK_r			= 114,
-	SDLK_s			= 115,
-	SDLK_t			= 116,
-	SDLK_u			= 117,
-	SDLK_v			= 118,
-	SDLK_w			= 119,
-	SDLK_x			= 120,
-	SDLK_y			= 121,
-	SDLK_z			= 122,
-	SDLK_DELETE		= 127,
-	/* End of ASCII mapped keysyms */
+    SDLK_UNKNOWN        = 0,
+    SDLK_FIRST      = 0,
+    SDLK_BACKSPACE      = 8,
+    SDLK_TAB        = 9,
+    SDLK_CLEAR      = 12,
+    SDLK_RETURN     = 13,
+    SDLK_PAUSE      = 19,
+    SDLK_ESCAPE     = 27,
+    SDLK_SPACE      = 32,
+    SDLK_EXCLAIM        = 33,
+    SDLK_QUOTEDBL       = 34,
+    SDLK_HASH       = 35,
+    SDLK_DOLLAR     = 36,
+    SDLK_AMPERSAND      = 38,
+    SDLK_QUOTE      = 39,
+    SDLK_LEFTPAREN      = 40,
+    SDLK_RIGHTPAREN     = 41,
+    SDLK_ASTERISK       = 42,
+    SDLK_PLUS       = 43,
+    SDLK_COMMA      = 44,
+    SDLK_MINUS      = 45,
+    SDLK_PERIOD     = 46,
+    SDLK_SLASH      = 47,
+    SDLK_0          = 48,
+    SDLK_1          = 49,
+    SDLK_2          = 50,
+    SDLK_3          = 51,
+    SDLK_4          = 52,
+    SDLK_5          = 53,
+    SDLK_6          = 54,
+    SDLK_7          = 55,
+    SDLK_8          = 56,
+    SDLK_9          = 57,
+    SDLK_COLON      = 58,
+    SDLK_SEMICOLON      = 59,
+    SDLK_LESS       = 60,
+    SDLK_EQUALS     = 61,
+    SDLK_GREATER        = 62,
+    SDLK_QUESTION       = 63,
+    SDLK_AT         = 64,
+    /*
+       Skip uppercase letters
+     */
+    SDLK_LEFTBRACKET    = 91,
+    SDLK_BACKSLASH      = 92,
+    SDLK_RIGHTBRACKET   = 93,
+    SDLK_CARET      = 94,
+    SDLK_UNDERSCORE     = 95,
+    SDLK_BACKQUOTE      = 96,
+    SDLK_a          = 97,
+    SDLK_b          = 98,
+    SDLK_c          = 99,
+    SDLK_d          = 100,
+    SDLK_e          = 101,
+    SDLK_f          = 102,
+    SDLK_g          = 103,
+    SDLK_h          = 104,
+    SDLK_i          = 105,
+    SDLK_j          = 106,
+    SDLK_k          = 107,
+    SDLK_l          = 108,
+    SDLK_m          = 109,
+    SDLK_n          = 110,
+    SDLK_o          = 111,
+    SDLK_p          = 112,
+    SDLK_q          = 113,
+    SDLK_r          = 114,
+    SDLK_s          = 115,
+    SDLK_t          = 116,
+    SDLK_u          = 117,
+    SDLK_v          = 118,
+    SDLK_w          = 119,
+    SDLK_x          = 120,
+    SDLK_y          = 121,
+    SDLK_z          = 122,
+    SDLK_DELETE     = 127,
+    /* End of ASCII mapped keysyms */
         /*@}*/
 
-	/** @name International keyboard syms */
+    /** @name International keyboard syms */
         /*@{*/
-	SDLK_WORLD_0		= 160,		/* 0xA0 */
-	SDLK_WORLD_1		= 161,
-	SDLK_WORLD_2		= 162,
-	SDLK_WORLD_3		= 163,
-	SDLK_WORLD_4		= 164,
-	SDLK_WORLD_5		= 165,
-	SDLK_WORLD_6		= 166,
-	SDLK_WORLD_7		= 167,
-	SDLK_WORLD_8		= 168,
-	SDLK_WORLD_9		= 169,
-	SDLK_WORLD_10		= 170,
-	SDLK_WORLD_11		= 171,
-	SDLK_WORLD_12		= 172,
-	SDLK_WORLD_13		= 173,
-	SDLK_WORLD_14		= 174,
-	SDLK_WORLD_15		= 175,
-	SDLK_WORLD_16		= 176,
-	SDLK_WORLD_17		= 177,
-	SDLK_WORLD_18		= 178,
-	SDLK_WORLD_19		= 179,
-	SDLK_WORLD_20		= 180,
-	SDLK_WORLD_21		= 181,
-	SDLK_WORLD_22		= 182,
-	SDLK_WORLD_23		= 183,
-	SDLK_WORLD_24		= 184,
-	SDLK_WORLD_25		= 185,
-	SDLK_WORLD_26		= 186,
-	SDLK_WORLD_27		= 187,
-	SDLK_WORLD_28		= 188,
-	SDLK_WORLD_29		= 189,
-	SDLK_WORLD_30		= 190,
-	SDLK_WORLD_31		= 191,
-	SDLK_WORLD_32		= 192,
-	SDLK_WORLD_33		= 193,
-	SDLK_WORLD_34		= 194,
-	SDLK_WORLD_35		= 195,
-	SDLK_WORLD_36		= 196,
-	SDLK_WORLD_37		= 197,
-	SDLK_WORLD_38		= 198,
-	SDLK_WORLD_39		= 199,
-	SDLK_WORLD_40		= 200,
-	SDLK_WORLD_41		= 201,
-	SDLK_WORLD_42		= 202,
-	SDLK_WORLD_43		= 203,
-	SDLK_WORLD_44		= 204,
-	SDLK_WORLD_45		= 205,
-	SDLK_WORLD_46		= 206,
-	SDLK_WORLD_47		= 207,
-	SDLK_WORLD_48		= 208,
-	SDLK_WORLD_49		= 209,
-	SDLK_WORLD_50		= 210,
-	SDLK_WORLD_51		= 211,
-	SDLK_WORLD_52		= 212,
-	SDLK_WORLD_53		= 213,
-	SDLK_WORLD_54		= 214,
-	SDLK_WORLD_55		= 215,
-	SDLK_WORLD_56		= 216,
-	SDLK_WORLD_57		= 217,
-	SDLK_WORLD_58		= 218,
-	SDLK_WORLD_59		= 219,
-	SDLK_WORLD_60		= 220,
-	SDLK_WORLD_61		= 221,
-	SDLK_WORLD_62		= 222,
-	SDLK_WORLD_63		= 223,
-	SDLK_WORLD_64		= 224,
-	SDLK_WORLD_65		= 225,
-	SDLK_WORLD_66		= 226,
-	SDLK_WORLD_67		= 227,
-	SDLK_WORLD_68		= 228,
-	SDLK_WORLD_69		= 229,
-	SDLK_WORLD_70		= 230,
-	SDLK_WORLD_71		= 231,
-	SDLK_WORLD_72		= 232,
-	SDLK_WORLD_73		= 233,
-	SDLK_WORLD_74		= 234,
-	SDLK_WORLD_75		= 235,
-	SDLK_WORLD_76		= 236,
-	SDLK_WORLD_77		= 237,
-	SDLK_WORLD_78		= 238,
-	SDLK_WORLD_79		= 239,
-	SDLK_WORLD_80		= 240,
-	SDLK_WORLD_81		= 241,
-	SDLK_WORLD_82		= 242,
-	SDLK_WORLD_83		= 243,
-	SDLK_WORLD_84		= 244,
-	SDLK_WORLD_85		= 245,
-	SDLK_WORLD_86		= 246,
-	SDLK_WORLD_87		= 247,
-	SDLK_WORLD_88		= 248,
-	SDLK_WORLD_89		= 249,
-	SDLK_WORLD_90		= 250,
-	SDLK_WORLD_91		= 251,
-	SDLK_WORLD_92		= 252,
-	SDLK_WORLD_93		= 253,
-	SDLK_WORLD_94		= 254,
-	SDLK_WORLD_95		= 255,		/* 0xFF */
+    SDLK_WORLD_0        = 160,      /* 0xA0 */
+    SDLK_WORLD_1        = 161,
+    SDLK_WORLD_2        = 162,
+    SDLK_WORLD_3        = 163,
+    SDLK_WORLD_4        = 164,
+    SDLK_WORLD_5        = 165,
+    SDLK_WORLD_6        = 166,
+    SDLK_WORLD_7        = 167,
+    SDLK_WORLD_8        = 168,
+    SDLK_WORLD_9        = 169,
+    SDLK_WORLD_10       = 170,
+    SDLK_WORLD_11       = 171,
+    SDLK_WORLD_12       = 172,
+    SDLK_WORLD_13       = 173,
+    SDLK_WORLD_14       = 174,
+    SDLK_WORLD_15       = 175,
+    SDLK_WORLD_16       = 176,
+    SDLK_WORLD_17       = 177,
+    SDLK_WORLD_18       = 178,
+    SDLK_WORLD_19       = 179,
+    SDLK_WORLD_20       = 180,
+    SDLK_WORLD_21       = 181,
+    SDLK_WORLD_22       = 182,
+    SDLK_WORLD_23       = 183,
+    SDLK_WORLD_24       = 184,
+    SDLK_WORLD_25       = 185,
+    SDLK_WORLD_26       = 186,
+    SDLK_WORLD_27       = 187,
+    SDLK_WORLD_28       = 188,
+    SDLK_WORLD_29       = 189,
+    SDLK_WORLD_30       = 190,
+    SDLK_WORLD_31       = 191,
+    SDLK_WORLD_32       = 192,
+    SDLK_WORLD_33       = 193,
+    SDLK_WORLD_34       = 194,
+    SDLK_WORLD_35       = 195,
+    SDLK_WORLD_36       = 196,
+    SDLK_WORLD_37       = 197,
+    SDLK_WORLD_38       = 198,
+    SDLK_WORLD_39       = 199,
+    SDLK_WORLD_40       = 200,
+    SDLK_WORLD_41       = 201,
+    SDLK_WORLD_42       = 202,
+    SDLK_WORLD_43       = 203,
+    SDLK_WORLD_44       = 204,
+    SDLK_WORLD_45       = 205,
+    SDLK_WORLD_46       = 206,
+    SDLK_WORLD_47       = 207,
+    SDLK_WORLD_48       = 208,
+    SDLK_WORLD_49       = 209,
+    SDLK_WORLD_50       = 210,
+    SDLK_WORLD_51       = 211,
+    SDLK_WORLD_52       = 212,
+    SDLK_WORLD_53       = 213,
+    SDLK_WORLD_54       = 214,
+    SDLK_WORLD_55       = 215,
+    SDLK_WORLD_56       = 216,
+    SDLK_WORLD_57       = 217,
+    SDLK_WORLD_58       = 218,
+    SDLK_WORLD_59       = 219,
+    SDLK_WORLD_60       = 220,
+    SDLK_WORLD_61       = 221,
+    SDLK_WORLD_62       = 222,
+    SDLK_WORLD_63       = 223,
+    SDLK_WORLD_64       = 224,
+    SDLK_WORLD_65       = 225,
+    SDLK_WORLD_66       = 226,
+    SDLK_WORLD_67       = 227,
+    SDLK_WORLD_68       = 228,
+    SDLK_WORLD_69       = 229,
+    SDLK_WORLD_70       = 230,
+    SDLK_WORLD_71       = 231,
+    SDLK_WORLD_72       = 232,
+    SDLK_WORLD_73       = 233,
+    SDLK_WORLD_74       = 234,
+    SDLK_WORLD_75       = 235,
+    SDLK_WORLD_76       = 236,
+    SDLK_WORLD_77       = 237,
+    SDLK_WORLD_78       = 238,
+    SDLK_WORLD_79       = 239,
+    SDLK_WORLD_80       = 240,
+    SDLK_WORLD_81       = 241,
+    SDLK_WORLD_82       = 242,
+    SDLK_WORLD_83       = 243,
+    SDLK_WORLD_84       = 244,
+    SDLK_WORLD_85       = 245,
+    SDLK_WORLD_86       = 246,
+    SDLK_WORLD_87       = 247,
+    SDLK_WORLD_88       = 248,
+    SDLK_WORLD_89       = 249,
+    SDLK_WORLD_90       = 250,
+    SDLK_WORLD_91       = 251,
+    SDLK_WORLD_92       = 252,
+    SDLK_WORLD_93       = 253,
+    SDLK_WORLD_94       = 254,
+    SDLK_WORLD_95       = 255,      /* 0xFF */
         /*@}*/
 
-	/** @name Numeric keypad */
+    /** @name Numeric keypad */
         /*@{*/
-	SDLK_KP0		= 256,
-	SDLK_KP1		= 257,
-	SDLK_KP2		= 258,
-	SDLK_KP3		= 259,
-	SDLK_KP4		= 260,
-	SDLK_KP5		= 261,
-	SDLK_KP6		= 262,
-	SDLK_KP7		= 263,
-	SDLK_KP8		= 264,
-	SDLK_KP9		= 265,
-	SDLK_KP_PERIOD		= 266,
-	SDLK_KP_DIVIDE		= 267,
-	SDLK_KP_MULTIPLY	= 268,
-	SDLK_KP_MINUS		= 269,
-	SDLK_KP_PLUS		= 270,
-	SDLK_KP_ENTER		= 271,
-	SDLK_KP_EQUALS		= 272,
+    SDLK_KP0        = 256,
+    SDLK_KP1        = 257,
+    SDLK_KP2        = 258,
+    SDLK_KP3        = 259,
+    SDLK_KP4        = 260,
+    SDLK_KP5        = 261,
+    SDLK_KP6        = 262,
+    SDLK_KP7        = 263,
+    SDLK_KP8        = 264,
+    SDLK_KP9        = 265,
+    SDLK_KP_PERIOD      = 266,
+    SDLK_KP_DIVIDE      = 267,
+    SDLK_KP_MULTIPLY    = 268,
+    SDLK_KP_MINUS       = 269,
+    SDLK_KP_PLUS        = 270,
+    SDLK_KP_ENTER       = 271,
+    SDLK_KP_EQUALS      = 272,
         /*@}*/
 
-	/** @name Arrows + Home/End pad */
+    /** @name Arrows + Home/End pad */
         /*@{*/
-	SDLK_UP			= 273,
-	SDLK_DOWN		= 274,
-	SDLK_RIGHT		= 275,
-	SDLK_LEFT		= 276,
-	SDLK_INSERT		= 277,
-	SDLK_HOME		= 278,
-	SDLK_END		= 279,
-	SDLK_PAGEUP		= 280,
-	SDLK_PAGEDOWN		= 281,
+    SDLK_UP         = 273,
+    SDLK_DOWN       = 274,
+    SDLK_RIGHT      = 275,
+    SDLK_LEFT       = 276,
+    SDLK_INSERT     = 277,
+    SDLK_HOME       = 278,
+    SDLK_END        = 279,
+    SDLK_PAGEUP     = 280,
+    SDLK_PAGEDOWN       = 281,
         /*@}*/
 
-	/** @name Function keys */
+    /** @name Function keys */
         /*@{*/
-	SDLK_F1			= 282,
-	SDLK_F2			= 283,
-	SDLK_F3			= 284,
-	SDLK_F4			= 285,
-	SDLK_F5			= 286,
-	SDLK_F6			= 287,
-	SDLK_F7			= 288,
-	SDLK_F8			= 289,
-	SDLK_F9			= 290,
-	SDLK_F10		= 291,
-	SDLK_F11		= 292,
-	SDLK_F12		= 293,
-	SDLK_F13		= 294,
-	SDLK_F14		= 295,
-	SDLK_F15		= 296,
+    SDLK_F1         = 282,
+    SDLK_F2         = 283,
+    SDLK_F3         = 284,
+    SDLK_F4         = 285,
+    SDLK_F5         = 286,
+    SDLK_F6         = 287,
+    SDLK_F7         = 288,
+    SDLK_F8         = 289,
+    SDLK_F9         = 290,
+    SDLK_F10        = 291,
+    SDLK_F11        = 292,
+    SDLK_F12        = 293,
+    SDLK_F13        = 294,
+    SDLK_F14        = 295,
+    SDLK_F15        = 296,
         /*@}*/
 
-	/** @name Key state modifier keys */
+    /** @name Key state modifier keys */
         /*@{*/
-	SDLK_NUMLOCK		= 300,
-	SDLK_CAPSLOCK		= 301,
-	SDLK_SCROLLOCK		= 302,
-	SDLK_RSHIFT		= 303,
-	SDLK_LSHIFT		= 304,
-	SDLK_RCTRL		= 305,
-	SDLK_LCTRL		= 306,
-	SDLK_RALT		= 307,
-	SDLK_LALT		= 308,
-	SDLK_RMETA		= 309,
-	SDLK_LMETA		= 310,
-	SDLK_LSUPER		= 311,		/**< Left "Windows" key */
-	SDLK_RSUPER		= 312,		/**< Right "Windows" key */
-	SDLK_MODE		= 313,		/**< "Alt Gr" key */
-	SDLK_COMPOSE		= 314,		/**< Multi-key compose key */
+    SDLK_NUMLOCK        = 300,
+    SDLK_CAPSLOCK       = 301,
+    SDLK_SCROLLOCK      = 302,
+    SDLK_RSHIFT     = 303,
+    SDLK_LSHIFT     = 304,
+    SDLK_RCTRL      = 305,
+    SDLK_LCTRL      = 306,
+    SDLK_RALT       = 307,
+    SDLK_LALT       = 308,
+    SDLK_RMETA      = 309,
+    SDLK_LMETA      = 310,
+    SDLK_LSUPER     = 311,      /**< Left "Windows" key */
+    SDLK_RSUPER     = 312,      /**< Right "Windows" key */
+    SDLK_MODE       = 313,      /**< "Alt Gr" key */
+    SDLK_COMPOSE        = 314,      /**< Multi-key compose key */
         /*@}*/
 
-	/** @name Miscellaneous function keys */
+    /** @name Miscellaneous function keys */
         /*@{*/
-	SDLK_HELP		= 315,
-	SDLK_PRINT		= 316,
-	SDLK_SYSREQ		= 317,
-	SDLK_BREAK		= 318,
-	SDLK_MENU		= 319,
-	SDLK_POWER		= 320,		/**< Power Macintosh power key */
-	SDLK_EURO		= 321,		/**< Some european keyboards */
-	SDLK_UNDO		= 322,		/**< Atari keyboard has Undo */
+    SDLK_HELP       = 315,
+    SDLK_PRINT      = 316,
+    SDLK_SYSREQ     = 317,
+    SDLK_BREAK      = 318,
+    SDLK_MENU       = 319,
+    SDLK_POWER      = 320,      /**< Power Macintosh power key */
+    SDLK_EURO       = 321,      /**< Some european keyboards */
+    SDLK_UNDO       = 322,      /**< Atari keyboard has Undo */
         /*@}*/
 
-	/* Add any other keys here */
+    /* Add any other keys here */
 
-	SDLK_LAST
+    SDLK_LAST
 } SDLKey;
 
 /** Enumeration of valid key mods (possibly OR'd together) */
 typedef enum {
-	KMOD_NONE  = 0x0000,
-	KMOD_LSHIFT= 0x0001,
-	KMOD_RSHIFT= 0x0002,
-	KMOD_LCTRL = 0x0040,
-	KMOD_RCTRL = 0x0080,
-	KMOD_LALT  = 0x0100,
-	KMOD_RALT  = 0x0200,
-	KMOD_LMETA = 0x0400,
-	KMOD_RMETA = 0x0800,
-	KMOD_NUM   = 0x1000,
-	KMOD_CAPS  = 0x2000,
-	KMOD_MODE  = 0x4000,
-	KMOD_RESERVED = 0x8000
+    KMOD_NONE  = 0x0000,
+    KMOD_LSHIFT= 0x0001,
+    KMOD_RSHIFT= 0x0002,
+    KMOD_LCTRL = 0x0040,
+    KMOD_RCTRL = 0x0080,
+    KMOD_LALT  = 0x0100,
+    KMOD_RALT  = 0x0200,
+    KMOD_LMETA = 0x0400,
+    KMOD_RMETA = 0x0800,
+    KMOD_NUM   = 0x1000,
+    KMOD_CAPS  = 0x2000,
+    KMOD_MODE  = 0x4000,
+    KMOD_RESERVED = 0x8000
 } SDLMod;
 
-#define KMOD_CTRL	(KMOD_LCTRL|KMOD_RCTRL)
-#define KMOD_SHIFT	(KMOD_LSHIFT|KMOD_RSHIFT)
-#define KMOD_ALT	(KMOD_LALT|KMOD_RALT)
-#define KMOD_META	(KMOD_LMETA|KMOD_RMETA)
+#define KMOD_CTRL   (KMOD_LCTRL|KMOD_RCTRL)
+#define KMOD_SHIFT  (KMOD_LSHIFT|KMOD_RSHIFT)
+#define KMOD_ALT    (KMOD_LALT|KMOD_RALT)
+#define KMOD_META   (KMOD_LMETA|KMOD_RMETA)
 
 #endif /* _SDL_keysym_h */
--- a/misc/winutils/include/SDL_loadso.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_loadso.h	Tue Jan 21 22:53:15 2014 +0100
@@ -25,7 +25,7 @@
  */
 
 /** @file SDL_loadso.h
- *  Some things to keep in mind:                                        
+ *  Some things to keep in mind:
  *  - These functions only work on C function names.  Other languages may
  *    have name mangling and intrinsic language support that varies from
  *    compiler to compiler.
--- a/misc/winutils/include/SDL_main.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_main.h	Tue Jan 21 22:53:15 2014 +0100
@@ -35,7 +35,7 @@
     defined(__SYMBIAN32__) || defined(QWS)
 
 #ifdef __cplusplus
-#define C_LINKAGE	"C"
+#define C_LINKAGE   "C"
 #else
 #define C_LINKAGE
 #endif /* __cplusplus */
@@ -46,12 +46,12 @@
  *      #ifdef __cplusplus
  *      extern "C"
  *      #endif
- *	int main(int argc, char *argv[])
- *	{
- *	}
+ *  int main(int argc, char *argv[])
+ *  {
+ *  }
  *      @endcode
  */
-#define main	SDL_main
+#define main    SDL_main
 
 /** The prototype for the application's main() function */
 extern C_LINKAGE int SDL_main(int argc, char *argv[]);
--- a/misc/winutils/include/SDL_mixer.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_mixer.h	Tue Jan 21 22:53:15 2014 +0100
@@ -38,25 +38,25 @@
 
 /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
 */
-#define SDL_MIXER_MAJOR_VERSION	1
-#define SDL_MIXER_MINOR_VERSION	2
+#define SDL_MIXER_MAJOR_VERSION 1
+#define SDL_MIXER_MINOR_VERSION 2
 #define SDL_MIXER_PATCHLEVEL    12
 
 /* This macro can be used to fill a version structure with the compile-time
  * version of the SDL_mixer library.
  */
-#define SDL_MIXER_VERSION(X)						\
-{									\
-	(X)->major = SDL_MIXER_MAJOR_VERSION;				\
-	(X)->minor = SDL_MIXER_MINOR_VERSION;				\
-	(X)->patch = SDL_MIXER_PATCHLEVEL;				\
+#define SDL_MIXER_VERSION(X)                        \
+{                                   \
+    (X)->major = SDL_MIXER_MAJOR_VERSION;               \
+    (X)->minor = SDL_MIXER_MINOR_VERSION;               \
+    (X)->patch = SDL_MIXER_PATCHLEVEL;              \
 }
 
 /* Backwards compatibility */
-#define MIX_MAJOR_VERSION	SDL_MIXER_MAJOR_VERSION
-#define MIX_MINOR_VERSION	SDL_MIXER_MINOR_VERSION
-#define MIX_PATCHLEVEL		SDL_MIXER_PATCHLEVEL
-#define MIX_VERSION(X)		SDL_MIXER_VERSION(X)
+#define MIX_MAJOR_VERSION   SDL_MIXER_MAJOR_VERSION
+#define MIX_MINOR_VERSION   SDL_MIXER_MINOR_VERSION
+#define MIX_PATCHLEVEL      SDL_MIXER_PATCHLEVEL
+#define MIX_VERSION(X)      SDL_MIXER_VERSION(X)
 
 /* This function gets the version of the dynamically linked SDL_mixer library.
    it should NOT be used to fill a version structure, instead you should
@@ -85,45 +85,45 @@
 
 /* The default mixer has 8 simultaneous mixing channels */
 #ifndef MIX_CHANNELS
-#define MIX_CHANNELS	8
+#define MIX_CHANNELS    8
 #endif
 
 /* Good default values for a PC soundcard */
-#define MIX_DEFAULT_FREQUENCY	22050
+#define MIX_DEFAULT_FREQUENCY   22050
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
-#define MIX_DEFAULT_FORMAT	AUDIO_S16LSB
+#define MIX_DEFAULT_FORMAT  AUDIO_S16LSB
 #else
-#define MIX_DEFAULT_FORMAT	AUDIO_S16MSB
+#define MIX_DEFAULT_FORMAT  AUDIO_S16MSB
 #endif
-#define MIX_DEFAULT_CHANNELS	2
-#define MIX_MAX_VOLUME		128	/* Volume of a chunk */
+#define MIX_DEFAULT_CHANNELS    2
+#define MIX_MAX_VOLUME      128 /* Volume of a chunk */
 
 /* The internal format for an audio chunk */
 typedef struct Mix_Chunk {
-	int allocated;
-	Uint8 *abuf;
-	Uint32 alen;
-	Uint8 volume;		/* Per-sample volume, 0-128 */
+    int allocated;
+    Uint8 *abuf;
+    Uint32 alen;
+    Uint8 volume;       /* Per-sample volume, 0-128 */
 } Mix_Chunk;
 
 /* The different fading types supported */
 typedef enum {
-	MIX_NO_FADING,
-	MIX_FADING_OUT,
-	MIX_FADING_IN
+    MIX_NO_FADING,
+    MIX_FADING_OUT,
+    MIX_FADING_IN
 } Mix_Fading;
 
 typedef enum {
-	MUS_NONE,
-	MUS_CMD,
-	MUS_WAV,
-	MUS_MOD,
-	MUS_MID,
-	MUS_OGG,
-	MUS_MP3,
-	MUS_MP3_MAD,
-	MUS_FLAC,
-	MUS_MODPLUG
+    MUS_NONE,
+    MUS_CMD,
+    MUS_WAV,
+    MUS_MOD,
+    MUS_MID,
+    MUS_OGG,
+    MUS_MP3,
+    MUS_MP3_MAD,
+    MUS_FLAC,
+    MUS_MODPLUG
 } Mix_MusicType;
 
 /* The internal format for a music chunk interpreted via mikmod */
@@ -131,7 +131,7 @@
 
 /* Open the mixer with a certain audio format */
 extern DECLSPEC int SDLCALL Mix_OpenAudio(int frequency, Uint16 format, int channels,
-							int chunksize);
+                            int chunksize);
 
 /* Dynamically change the number of channels managed by the mixer.
    If decreasing the number of channels, the upper channels are
@@ -147,7 +147,7 @@
 
 /* Load a wave file or a music (.mod .s3m .it .xm) file */
 extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
-#define Mix_LoadWAV(file)	Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1)
+#define Mix_LoadWAV(file)   Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1)
 extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file);
 
 /* Load a music file from an SDL_RWop object (Ogg and MikMod specific currently)
@@ -219,9 +219,9 @@
 
 /*
  * Add your own callback when a channel has finished playing. NULL
- *  to disable callback. The callback may be called from the mixer's audio 
+ *  to disable callback. The callback may be called from the mixer's audio
  *  callback or it could be called as a result of Mix_HaltChannel(), etc.
- *  do not call SDL_LockAudio() from this callback; you will either be 
+ *  do not call SDL_LockAudio() from this callback; you will either be
  *  inside the audio callback, or SDL_mixer will explicitly lock the audio
  *  before calling your callback.
  */
@@ -302,7 +302,7 @@
  *
  * After all these effects have finished processing, the callback registered
  *  through Mix_SetPostMix() runs, and then the stream goes to the audio
- *  device. 
+ *  device.
  *
  * DO NOT EVER call SDL_LockAudio() from your callback function!
  *
@@ -310,7 +310,7 @@
  *  Error messages can be retrieved from Mix_GetError().
  */
 extern DECLSPEC int SDLCALL Mix_RegisterEffect(int chan, Mix_EffectFunc_t f,
-					Mix_EffectDone_t d, void *arg);
+                    Mix_EffectDone_t d, void *arg);
 
 
 /* You may not need to call this explicitly, unless you need to stop an
@@ -590,7 +590,7 @@
 /* Set the current position in the music stream.
    This returns 0 if successful, or -1 if it failed or isn't implemented.
    This function is only implemented for MOD music formats (set pattern
-   order number) and for OGG, FLAC, MP3_MAD, and MODPLUG music (set 
+   order number) and for OGG, FLAC, MP3_MAD, and MODPLUG music (set
    position in seconds), at the moment.
 */
 extern DECLSPEC int SDLCALL Mix_SetMusicPosition(double position);
@@ -622,8 +622,8 @@
 extern DECLSPEC void SDLCALL Mix_CloseAudio(void);
 
 /* We'll use SDL for reporting errors */
-#define Mix_SetError	SDL_SetError
-#define Mix_GetError	SDL_GetError
+#define Mix_SetError    SDL_SetError
+#define Mix_GetError    SDL_GetError
 
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
--- a/misc/winutils/include/SDL_mouse.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_mouse.h	Tue Jan 21 22:53:15 2014 +0100
@@ -37,14 +37,14 @@
 extern "C" {
 #endif
 
-typedef struct WMcursor WMcursor;	/**< Implementation dependent */
+typedef struct WMcursor WMcursor;   /**< Implementation dependent */
 typedef struct SDL_Cursor {
-	SDL_Rect area;			/**< The area of the mouse cursor */
-	Sint16 hot_x, hot_y;		/**< The "tip" of the cursor */
-	Uint8 *data;			/**< B/W cursor data */
-	Uint8 *mask;			/**< B/W cursor mask */
-	Uint8 *save[2];			/**< Place to save cursor area */
-	WMcursor *wm_cursor;		/**< Window-manager cursor */
+    SDL_Rect area;          /**< The area of the mouse cursor */
+    Sint16 hot_x, hot_y;        /**< The "tip" of the cursor */
+    Uint8 *data;            /**< B/W cursor data */
+    Uint8 *mask;            /**< B/W cursor mask */
+    Uint8 *save[2];         /**< Place to save cursor area */
+    WMcursor *wm_cursor;        /**< Window-manager cursor */
 } SDL_Cursor;
 
 /* Function prototypes */
@@ -83,11 +83,11 @@
  * Cursors created with this function must be freed with SDL_FreeCursor().
  */
 extern DECLSPEC SDL_Cursor * SDLCALL SDL_CreateCursor
-		(Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
+        (Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
 
 /**
  * Set the currently active cursor to the specified one.
- * If the cursor is currently visible, the change will be immediately 
+ * If the cursor is currently visible, the change will be immediately
  * represented on the display.
  */
 extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor *cursor);
@@ -113,25 +113,25 @@
 
 /*@{*/
 /** Used as a mask when testing buttons in buttonstate
- *  Button 1:	Left mouse button
- *  Button 2:	Middle mouse button
- *  Button 3:	Right mouse button
- *  Button 4:	Mouse wheel up	 (may also be a real button)
- *  Button 5:	Mouse wheel down (may also be a real button)
+ *  Button 1:   Left mouse button
+ *  Button 2:   Middle mouse button
+ *  Button 3:   Right mouse button
+ *  Button 4:   Mouse wheel up   (may also be a real button)
+ *  Button 5:   Mouse wheel down (may also be a real button)
  */
-#define SDL_BUTTON(X)		(1 << ((X)-1))
-#define SDL_BUTTON_LEFT		1
-#define SDL_BUTTON_MIDDLE	2
-#define SDL_BUTTON_RIGHT	3
-#define SDL_BUTTON_WHEELUP	4
-#define SDL_BUTTON_WHEELDOWN	5
-#define SDL_BUTTON_X1		6
-#define SDL_BUTTON_X2		7
-#define SDL_BUTTON_LMASK	SDL_BUTTON(SDL_BUTTON_LEFT)
-#define SDL_BUTTON_MMASK	SDL_BUTTON(SDL_BUTTON_MIDDLE)
-#define SDL_BUTTON_RMASK	SDL_BUTTON(SDL_BUTTON_RIGHT)
-#define SDL_BUTTON_X1MASK	SDL_BUTTON(SDL_BUTTON_X1)
-#define SDL_BUTTON_X2MASK	SDL_BUTTON(SDL_BUTTON_X2)
+#define SDL_BUTTON(X)       (1 << ((X)-1))
+#define SDL_BUTTON_LEFT     1
+#define SDL_BUTTON_MIDDLE   2
+#define SDL_BUTTON_RIGHT    3
+#define SDL_BUTTON_WHEELUP  4
+#define SDL_BUTTON_WHEELDOWN    5
+#define SDL_BUTTON_X1       6
+#define SDL_BUTTON_X2       7
+#define SDL_BUTTON_LMASK    SDL_BUTTON(SDL_BUTTON_LEFT)
+#define SDL_BUTTON_MMASK    SDL_BUTTON(SDL_BUTTON_MIDDLE)
+#define SDL_BUTTON_RMASK    SDL_BUTTON(SDL_BUTTON_RIGHT)
+#define SDL_BUTTON_X1MASK   SDL_BUTTON(SDL_BUTTON_X1)
+#define SDL_BUTTON_X2MASK   SDL_BUTTON(SDL_BUTTON_X2)
 /*@}*/
 
 /* Ends C function definitions when using C++ */
--- a/misc/winutils/include/SDL_mutex.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_mutex.h	Tue Jan 21 22:53:15 2014 +0100
@@ -41,10 +41,10 @@
 /** Synchronization functions which can time out return this value
  *  if they time out.
  */
-#define SDL_MUTEX_TIMEDOUT	1
+#define SDL_MUTEX_TIMEDOUT  1
 
 /** This is the timeout value which corresponds to never time out */
-#define SDL_MUTEX_MAXWAIT	(~(Uint32)0)
+#define SDL_MUTEX_MAXWAIT   (~(Uint32)0)
 
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -58,13 +58,13 @@
 /** Create a mutex, initialized unlocked */
 extern DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void);
 
-#define SDL_LockMutex(m)	SDL_mutexP(m)
+#define SDL_LockMutex(m)    SDL_mutexP(m)
 /** Lock the mutex
  *  @return 0, or -1 on error
  */
 extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex);
 
-#define SDL_UnlockMutex(m)	SDL_mutexV(m)
+#define SDL_UnlockMutex(m)  SDL_mutexV(m)
 /** Unlock the mutex
  *  @return 0, or -1 on error
  *
@@ -93,7 +93,7 @@
 extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem);
 
 /**
- * This function suspends the calling thread until the semaphore pointed 
+ * This function suspends the calling thread until the semaphore pointed
  * to by sem has a positive count. It then atomically decreases the semaphore
  * count.
  */
--- a/misc/winutils/include/SDL_name.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_name.h	Tue Jan 21 22:53:15 2014 +0100
@@ -6,6 +6,6 @@
 #define NeedFunctionPrototypes 1
 #endif
 
-#define SDL_NAME(X)	SDL_##X
+#define SDL_NAME(X) SDL_##X
 
 #endif /* _SDLname_h_ */
--- a/misc/winutils/include/SDL_net.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_net.h	Tue Jan 21 22:53:15 2014 +0100
@@ -38,18 +38,18 @@
 
 /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
 */
-#define SDL_NET_MAJOR_VERSION	1
-#define SDL_NET_MINOR_VERSION	2
-#define SDL_NET_PATCHLEVEL	8
+#define SDL_NET_MAJOR_VERSION   1
+#define SDL_NET_MINOR_VERSION   2
+#define SDL_NET_PATCHLEVEL  8
 
 /* This macro can be used to fill a version structure with the compile-time
  * version of the SDL_net library.
  */
-#define SDL_NET_VERSION(X)						\
-{									\
-	(X)->major = SDL_NET_MAJOR_VERSION;				\
-	(X)->minor = SDL_NET_MINOR_VERSION;				\
-	(X)->patch = SDL_NET_PATCHLEVEL;				\
+#define SDL_NET_VERSION(X)                      \
+{                                   \
+    (X)->major = SDL_NET_MAJOR_VERSION;             \
+    (X)->minor = SDL_NET_MINOR_VERSION;             \
+    (X)->patch = SDL_NET_PATCHLEVEL;                \
 }
 
 /* This function gets the version of the dynamically linked SDL_net library.
@@ -70,8 +70,8 @@
 /***********************************************************************/
 
 typedef struct {
-	Uint32 host;			/* 32-bit IPv4 host address */
-	Uint16 port;			/* 16-bit protocol port */
+    Uint32 host;            /* 32-bit IPv4 host address */
+    Uint16 port;            /* 16-bit protocol port */
 } IPaddress;
 
 /* Resolve a host name and port to an IP address in network form.
@@ -81,13 +81,13 @@
    If 'host' is NULL, the resolved host will be set to INADDR_ANY.
  */
 #ifndef INADDR_ANY
-#define INADDR_ANY		0x00000000
+#define INADDR_ANY      0x00000000
 #endif
 #ifndef INADDR_NONE
-#define INADDR_NONE		0xFFFFFFFF
+#define INADDR_NONE     0xFFFFFFFF
 #endif
 #ifndef INADDR_BROADCAST
-#define INADDR_BROADCAST	0xFFFFFFFF
+#define INADDR_BROADCAST    0xFFFFFFFF
 #endif
 extern DECLSPEC int SDLCALL SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port);
 
@@ -113,7 +113,7 @@
    If ip.host is INADDR_NONE or INADDR_ANY, this creates a local server
    socket on the given port, otherwise a TCP connection to the remote
    host and port is attempted. The address passed in should already be
-   swapped to network byte order (addresses returned from 
+   swapped to network byte order (addresses returned from
    SDLNet_ResolveHost() are already in the correct form).
    The newly created socket is returned, or NULL if there was an error.
 */
@@ -135,7 +135,7 @@
    closed, or an unknown socket error occurred.
 */
 extern DECLSPEC int SDLCALL SDLNet_TCP_Send(TCPsocket sock, const void *data,
-		int len);
+        int len);
 
 /* Receive up to 'maxlen' bytes of data over the non-server socket 'sock',
    and store them in the buffer pointed to by 'data'.
@@ -154,18 +154,18 @@
 /***********************************************************************/
 
 /* The maximum channels on a a UDP socket */
-#define SDLNET_MAX_UDPCHANNELS	32
+#define SDLNET_MAX_UDPCHANNELS  32
 /* The maximum addresses bound to a single UDP socket channel */
-#define SDLNET_MAX_UDPADDRESSES	4
+#define SDLNET_MAX_UDPADDRESSES 4
 
 typedef struct _UDPsocket *UDPsocket;
 typedef struct {
-	int channel;		/* The src/dst channel of the packet */
-	Uint8 *data;		/* The packet data */
-	int len;		/* The length of the packet data */
-	int maxlen;		/* The size of the data buffer */
-	int status;		/* packet status after sending */
-	IPaddress address;		/* The source/dest address of an incoming/outgoing packet */
+    int channel;        /* The src/dst channel of the packet */
+    Uint8 *data;        /* The packet data */
+    int len;        /* The length of the packet data */
+    int maxlen;     /* The size of the data buffer */
+    int status;     /* packet status after sending */
+    IPaddress address;      /* The source/dest address of an incoming/outgoing packet */
 } UDPpacket;
 
 /* Allocate/resize/free a single UDP packet 'size' bytes long.
@@ -210,7 +210,7 @@
 /* Unbind all addresses from the given channel */
 extern DECLSPEC void SDLCALL SDLNet_UDP_Unbind(UDPsocket sock, int channel);
 
-/* Get the primary IP address of the remote system associated with the 
+/* Get the primary IP address of the remote system associated with the
    socket and channel.  If the channel is -1, then the primary IP port
    of the UDP socket is returned -- this is only meaningful for sockets
    opened with a specific port.
@@ -221,7 +221,7 @@
 /* Send a vector of packets to the the channels specified within the packet.
    If the channel specified in the packet is -1, the packet will be sent to
    the address in the 'src' member of the packet.
-   Each packet will be updated with the status of the packet after it has 
+   Each packet will be updated with the status of the packet after it has
    been sent, -1 if the packet send failed.
    This function returns the number of packets sent.
 */
@@ -277,7 +277,7 @@
 
 /* Any network socket can be safely cast to this socket type */
 typedef struct _SDLNet_GenericSocket {
-	int ready;
+    int ready;
 } *SDLNet_GenericSocket;
 
 /* Allocate a socket set for use with SDLNet_CheckSockets()
@@ -288,23 +288,23 @@
 
 /* Add a socket to a set of sockets to be checked for available data */
 #define SDLNet_TCP_AddSocket(set, sock) \
-			SDLNet_AddSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
+            SDLNet_AddSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
 #define SDLNet_UDP_AddSocket(set, sock) \
-			SDLNet_AddSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
+            SDLNet_AddSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
 extern DECLSPEC int SDLCALL SDLNet_AddSocket(SDLNet_SocketSet set, SDLNet_GenericSocket sock);
 
 /* Remove a socket from a set of sockets to be checked for available data */
 #define SDLNet_TCP_DelSocket(set, sock) \
-			SDLNet_DelSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
+            SDLNet_DelSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
 #define SDLNet_UDP_DelSocket(set, sock) \
-			SDLNet_DelSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
+            SDLNet_DelSocket(set, SDL_reinterpret_cast(SDLNet_GenericSocket, sock))
 extern DECLSPEC int SDLCALL SDLNet_DelSocket(SDLNet_SocketSet set, SDLNet_GenericSocket sock);
 
 /* This function checks to see if data is available for reading on the
    given set of sockets.  If 'timeout' is 0, it performs a quick poll,
    otherwise the function returns when either data is available for
    reading, or the timeout in milliseconds has elapsed, which ever occurs
-   first.  This function returns the number of sockets ready for reading, 
+   first.  This function returns the number of sockets ready for reading,
    or -1 if there was an error with the select() system call.
 */
 extern DECLSPEC int SDLCALL SDLNet_CheckSockets(SDLNet_SocketSet set, Uint32 timeout);
@@ -314,7 +314,7 @@
    for reading.
 */
 #define SDLNet_SocketReady(sock) \
-		((sock != NULL) && SDL_reinterpret_cast(SDLNet_GenericSocket, sock)->ready)
+        ((sock != NULL) && SDL_reinterpret_cast(SDLNet_GenericSocket, sock)->ready)
 
 /* Free a set of sockets allocated by SDL_NetAllocSocketSet() */
 extern DECLSPEC void SDLCALL SDLNet_FreeSocketSet(SDLNet_SocketSet set);
@@ -337,8 +337,8 @@
 /***********************************************************************/
 
 /* We'll use SDL's functions for error reporting */
-#define SDLNet_SetError	SDL_SetError
-#define SDLNet_GetError	SDL_GetError
+#define SDLNet_SetError SDL_SetError
+#define SDLNet_GetError SDL_GetError
 
 /* I'm eventually going to try to disentangle SDL_net from SDL, thus making
    SDL_net an independent X-platform networking toolkit.  Not today though....
@@ -352,91 +352,91 @@
 
 /* Warning, some systems have data access alignment restrictions */
 #if defined(sparc) || defined(mips)
-#define SDL_DATA_ALIGNED	1
+#define SDL_DATA_ALIGNED    1
 #endif
 #ifndef SDL_DATA_ALIGNED
-#define SDL_DATA_ALIGNED	0
+#define SDL_DATA_ALIGNED    0
 #endif
 
 /* Write a 16 bit value to network packet buffer */
 #if !SDL_DATA_ALIGNED
-#define SDLNet_Write16(value, areap)	\
-	(*SDL_reinterpret_cast(Uint16 *, areap) = SDL_SwapBE16(value))
+#define SDLNet_Write16(value, areap)    \
+    (*SDL_reinterpret_cast(Uint16 *, areap) = SDL_SwapBE16(value))
 #else
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define SDLNet_Write16(value, areap)	\
-do 					\
-{					\
-	Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap);	\
-	area[0] = (value >>  8) & 0xFF;	\
-	area[1] =  value        & 0xFF;	\
+#define SDLNet_Write16(value, areap)    \
+do                  \
+{                   \
+    Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
+    area[0] = (value >>  8) & 0xFF; \
+    area[1] =  value        & 0xFF; \
 } while ( 0 )
 #else
-#define SDLNet_Write16(value, areap)	\
-do 					\
-{					\
-	Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap);	\
-	area[1] = (value >>  8) & 0xFF;	\
-	area[0] =  value        & 0xFF;	\
+#define SDLNet_Write16(value, areap)    \
+do                  \
+{                   \
+    Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
+    area[1] = (value >>  8) & 0xFF; \
+    area[0] =  value        & 0xFF; \
 } while ( 0 )
 #endif
 #endif /* !SDL_DATA_ALIGNED */
 
 /* Write a 32 bit value to network packet buffer */
 #if !SDL_DATA_ALIGNED
-#define SDLNet_Write32(value, areap) 	\
-	*SDL_reinterpret_cast(Uint32 *, areap) = SDL_SwapBE32(value);
+#define SDLNet_Write32(value, areap)    \
+    *SDL_reinterpret_cast(Uint32 *, areap) = SDL_SwapBE32(value);
 #else
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define SDLNet_Write32(value, areap) 	\
-do					\
-{					\
-	Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap);	\
-	area[0] = (value >> 24) & 0xFF;	\
-	area[1] = (value >> 16) & 0xFF;	\
-	area[2] = (value >>  8) & 0xFF;	\
-	area[3] =  value       & 0xFF;	\
+#define SDLNet_Write32(value, areap)    \
+do                  \
+{                   \
+    Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
+    area[0] = (value >> 24) & 0xFF; \
+    area[1] = (value >> 16) & 0xFF; \
+    area[2] = (value >>  8) & 0xFF; \
+    area[3] =  value       & 0xFF;  \
 } while ( 0 )
 #else
-#define SDLNet_Write32(value, areap) 	\
-do					\
-{					\
-	Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap);	\
-	area[3] = (value >> 24) & 0xFF;	\
-	area[2] = (value >> 16) & 0xFF;	\
-	area[1] = (value >>  8) & 0xFF;	\
-	area[0] =  value       & 0xFF;	\
+#define SDLNet_Write32(value, areap)    \
+do                  \
+{                   \
+    Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
+    area[3] = (value >> 24) & 0xFF; \
+    area[2] = (value >> 16) & 0xFF; \
+    area[1] = (value >>  8) & 0xFF; \
+    area[0] =  value       & 0xFF;  \
 } while ( 0 )
 #endif
 #endif /* !SDL_DATA_ALIGNED */
 
 /* Read a 16 bit value from network packet buffer */
 #if !SDL_DATA_ALIGNED
-#define SDLNet_Read16(areap) 		\
-	(SDL_SwapBE16(*SDL_reinterpret_cast(Uint16 *, areap)))
+#define SDLNet_Read16(areap)        \
+    (SDL_SwapBE16(*SDL_reinterpret_cast(Uint16 *, areap)))
 #else
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define SDLNet_Read16(areap) 		\
-	(((SDL_reinterpret_cast(Uint8 *, areap))[0] <<  8) | (SDL_reinterpret_cast(Uint8 *, areap))[1] <<  0)
+#define SDLNet_Read16(areap)        \
+    (((SDL_reinterpret_cast(Uint8 *, areap))[0] <<  8) | (SDL_reinterpret_cast(Uint8 *, areap))[1] <<  0)
 #else
-#define SDLNet_Read16(areap) 		\
-	(((SDL_reinterpret_cast(Uint8 *, areap))[1] <<  8) | (SDL_reinterpret_cast(Uint8 *, areap))[0] <<  0)
+#define SDLNet_Read16(areap)        \
+    (((SDL_reinterpret_cast(Uint8 *, areap))[1] <<  8) | (SDL_reinterpret_cast(Uint8 *, areap))[0] <<  0)
 #endif
 #endif /* !SDL_DATA_ALIGNED */
 
 /* Read a 32 bit value from network packet buffer */
 #if !SDL_DATA_ALIGNED
-#define SDLNet_Read32(areap) 		\
-	(SDL_SwapBE32(*SDL_reinterpret_cast(Uint32 *, areap)))
+#define SDLNet_Read32(areap)        \
+    (SDL_SwapBE32(*SDL_reinterpret_cast(Uint32 *, areap)))
 #else
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define SDLNet_Read32(areap) 		\
-	(((SDL_reinterpret_cast(Uint8 *, areap))[0] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[1] << 16) | \
-	 ((SDL_reinterpret_cast(Uint8 *, areap))[2] <<  8) |  (SDL_reinterpret_cast(Uint8 *, areap))[3] <<  0)
+#define SDLNet_Read32(areap)        \
+    (((SDL_reinterpret_cast(Uint8 *, areap))[0] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[1] << 16) | \
+     ((SDL_reinterpret_cast(Uint8 *, areap))[2] <<  8) |  (SDL_reinterpret_cast(Uint8 *, areap))[3] <<  0)
 #else
-#define SDLNet_Read32(areap) 		\
-	(((SDL_reinterpret_cast(Uint8 *, areap))[3] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[2] << 16) | \
-	 ((SDL_reinterpret_cast(Uint8 *, areap))[1] <<  8) |  (SDL_reinterpret_cast(Uint8 *, areap))[0] <<  0)
+#define SDLNet_Read32(areap)        \
+    (((SDL_reinterpret_cast(Uint8 *, areap))[3] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[2] << 16) | \
+     ((SDL_reinterpret_cast(Uint8 *, areap))[1] <<  8) |  (SDL_reinterpret_cast(Uint8 *, areap))[0] <<  0)
 #endif
 #endif /* !SDL_DATA_ALIGNED */
 
--- a/misc/winutils/include/SDL_opengl.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_opengl.h	Tue Jan 21 22:53:15 2014 +0100
@@ -29,7 +29,7 @@
 #ifdef __WIN32__
 #define WIN32_LEAN_AND_MEAN
 #ifndef NOMINMAX
-#define NOMINMAX	/* Don't defined min() and max() */
+#define NOMINMAX    /* Don't defined min() and max() */
 #endif
 #include <windows.h>
 #endif
@@ -37,14 +37,14 @@
 #define __glext_h_  /* Don't let gl.h include glext.h */
 #endif
 #if defined(__MACOSX__)
-#include <OpenGL/gl.h>	/* Header File For The OpenGL Library */
-#include <OpenGL/glu.h>	/* Header File For The GLU Library */
+#include <OpenGL/gl.h>  /* Header File For The OpenGL Library */
+#include <OpenGL/glu.h> /* Header File For The GLU Library */
 #elif defined(__MACOS__)
-#include <gl.h>		/* Header File For The OpenGL Library */
-#include <glu.h>	/* Header File For The GLU Library */
+#include <gl.h>     /* Header File For The OpenGL Library */
+#include <glu.h>    /* Header File For The GLU Library */
 #else
-#include <GL/gl.h>	/* Header File For The OpenGL Library */
-#include <GL/glu.h>	/* Header File For The GLU Library */
+#include <GL/gl.h>  /* Header File For The OpenGL Library */
+#include <GL/glu.h> /* Header File For The GLU Library */
 #endif
 #ifndef NO_SDL_GLEXT
 #undef __glext_h_
@@ -72,21 +72,21 @@
 ** this file except in compliance with the License. You may obtain a copy
 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
-** 
+**
 ** http://oss.sgi.com/projects/FreeB
-** 
+**
 ** Note that, as provided in the License, the Software is distributed on an
 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
-** 
+**
 ** Original Code. The Original Code is: OpenGL Sample Implementation,
 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
 ** Inc. The Original Code is Copyright (c) 1991-2004 Silicon Graphics, Inc.
 ** Copyright in any portions created by third parties is as indicated
 ** elsewhere herein. All Rights Reserved.
-** 
+**
 ** Additional Notice Provisions: This software was created using the
 ** OpenGL(R) version 1.2.1 Sample Implementation published by SGI, but has
 ** not been independently verified as being compliant with the OpenGL(R)
@@ -3103,7 +3103,7 @@
 #include <stddef.h>
 #ifndef GL_VERSION_2_0
 /* GL type for program/shader text */
-typedef char GLchar;			/* native character */
+typedef char GLchar;            /* native character */
 #endif
 
 #ifndef GL_VERSION_1_5
@@ -3130,11 +3130,11 @@
 
 #ifndef GL_ARB_shader_objects
 /* GL types for handling shader object handles and program/shader text */
-typedef char GLcharARB;		/* native character */
+typedef char GLcharARB;     /* native character */
 #if defined(__APPLE__)
-typedef void *GLhandleARB;	/* shader object handle */
+typedef void *GLhandleARB;  /* shader object handle */
 #else
-typedef unsigned int GLhandleARB;	/* shader object handle */
+typedef unsigned int GLhandleARB;   /* shader object handle */
 #endif
 #endif
 
--- a/misc/winutils/include/SDL_platform.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_platform.h	Tue Jan 21 22:53:15 2014 +0100
@@ -29,11 +29,11 @@
 
 #if defined(_AIX)
 #undef __AIX__
-#define __AIX__		1
+#define __AIX__     1
 #endif
 #if defined(__BEOS__)
 #undef __BEOS__
-#define __BEOS__	1
+#define __BEOS__    1
 #endif
 #if defined(__HAIKU__)
 #undef __HAIKU__
@@ -41,70 +41,70 @@
 #endif
 #if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
 #undef __BSDI__
-#define __BSDI__	1
+#define __BSDI__    1
 #endif
 #if defined(_arch_dreamcast)
 #undef __DREAMCAST__
-#define __DREAMCAST__	1
+#define __DREAMCAST__   1
 #endif
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 #undef __FREEBSD__
-#define __FREEBSD__	1
+#define __FREEBSD__ 1
 #endif
 #if defined(__HAIKU__)
 #undef __HAIKU__
-#define __HAIKU__	1
+#define __HAIKU__   1
 #endif
 #if defined(hpux) || defined(__hpux) || defined(__hpux__)
 #undef __HPUX__
-#define __HPUX__	1
+#define __HPUX__    1
 #endif
 #if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
 #undef __IRIX__
-#define __IRIX__	1
+#define __IRIX__    1
 #endif
 #if defined(linux) || defined(__linux) || defined(__linux__)
 #undef __LINUX__
-#define __LINUX__	1
+#define __LINUX__   1
 #endif
 #if defined(__APPLE__)
 #undef __MACOSX__
-#define __MACOSX__	1
+#define __MACOSX__  1
 #elif defined(macintosh)
 #undef __MACOS__
-#define __MACOS__	1
+#define __MACOS__   1
 #endif
 #if defined(__NetBSD__)
 #undef __NETBSD__
-#define __NETBSD__	1
+#define __NETBSD__  1
 #endif
 #if defined(__OpenBSD__)
 #undef __OPENBSD__
-#define __OPENBSD__	1
+#define __OPENBSD__ 1
 #endif
 #if defined(__OS2__)
 #undef __OS2__
-#define __OS2__		1
+#define __OS2__     1
 #endif
 #if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
 #undef __OSF__
-#define __OSF__		1
+#define __OSF__     1
 #endif
 #if defined(__QNXNTO__)
 #undef __QNXNTO__
-#define __QNXNTO__	1
+#define __QNXNTO__  1
 #endif
 #if defined(riscos) || defined(__riscos) || defined(__riscos__)
 #undef __RISCOS__
-#define __RISCOS__	1
+#define __RISCOS__  1
 #endif
 #if defined(__SVR4)
 #undef __SOLARIS__
-#define __SOLARIS__	1
+#define __SOLARIS__ 1
 #endif
 #if defined(WIN32) || defined(_WIN32)
 #undef __WIN32__
-#define __WIN32__	1
+#define __WIN32__   1
 #endif
 
 #endif /* _SDL_platform_h */
--- a/misc/winutils/include/SDL_quit.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_quit.h	Tue Jan 21 22:53:15 2014 +0100
@@ -34,7 +34,7 @@
  *  An SDL_QUITEVENT is generated when the user tries to close the application
  *  window.  If it is ignored or filtered out, the window will remain open.
  *  If it is not ignored or filtered, it is queued normally and the window
- *  is allowed to close.  When the window is closed, screen updates will 
+ *  is allowed to close.  When the window is closed, screen updates will
  *  complete, but have no effect.
  *
  *  SDL_Init() installs signal handlers for SIGINT (keyboard interrupt)
@@ -46,7 +46,7 @@
  */
 
 /** @file SDL_quit.h
- *  There are no functions directly affecting the quit event 
+ *  There are no functions directly affecting the quit event
  */
 
 #define SDL_QuitRequested() \
--- a/misc/winutils/include/SDL_rwops.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_rwops.h	Tue Jan 21 22:53:15 2014 +0100
@@ -40,55 +40,55 @@
 /** This is the read/write operation structure -- very basic */
 
 typedef struct SDL_RWops {
-	/** Seek to 'offset' relative to whence, one of stdio's whence values:
-	 *	SEEK_SET, SEEK_CUR, SEEK_END
-	 *  Returns the final offset in the data source.
-	 */
-	int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence);
+    /** Seek to 'offset' relative to whence, one of stdio's whence values:
+     *  SEEK_SET, SEEK_CUR, SEEK_END
+     *  Returns the final offset in the data source.
+     */
+    int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence);
 
-	/** Read up to 'maxnum' objects each of size 'size' from the data
-	 *  source to the area pointed at by 'ptr'.
-	 *  Returns the number of objects read, or -1 if the read failed.
-	 */
-	int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
+    /** Read up to 'maxnum' objects each of size 'size' from the data
+     *  source to the area pointed at by 'ptr'.
+     *  Returns the number of objects read, or -1 if the read failed.
+     */
+    int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
 
-	/** Write exactly 'num' objects each of size 'objsize' from the area
-	 *  pointed at by 'ptr' to data source.
-	 *  Returns 'num', or -1 if the write failed.
-	 */
-	int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num);
+    /** Write exactly 'num' objects each of size 'objsize' from the area
+     *  pointed at by 'ptr' to data source.
+     *  Returns 'num', or -1 if the write failed.
+     */
+    int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num);
 
-	/** Close and free an allocated SDL_FSops structure */
-	int (SDLCALL *close)(struct SDL_RWops *context);
+    /** Close and free an allocated SDL_FSops structure */
+    int (SDLCALL *close)(struct SDL_RWops *context);
 
-	Uint32 type;
-	union {
+    Uint32 type;
+    union {
 #if defined(__WIN32__) && !defined(__SYMBIAN32__)
-	    struct {
-		int   append;
-		void *h;
-		struct {
-		    void *data;
-		    int size;
-		    int left;
-		} buffer;
-	    } win32io;
+        struct {
+        int   append;
+        void *h;
+        struct {
+            void *data;
+            int size;
+            int left;
+        } buffer;
+        } win32io;
 #endif
-#ifdef HAVE_STDIO_H 
-	    struct {
-		int autoclose;
-	 	FILE *fp;
-	    } stdio;
+#ifdef HAVE_STDIO_H
+        struct {
+        int autoclose;
+        FILE *fp;
+        } stdio;
 #endif
-	    struct {
-		Uint8 *base;
-	 	Uint8 *here;
-		Uint8 *stop;
-	    } mem;
-	    struct {
-		void *data1;
-	    } unknown;
-	} hidden;
+        struct {
+        Uint8 *base;
+        Uint8 *here;
+        Uint8 *stop;
+        } mem;
+        struct {
+        void *data1;
+        } unknown;
+    } hidden;
 
 } SDL_RWops;
 
@@ -112,18 +112,18 @@
 
 /** @name Seek Reference Points */
 /*@{*/
-#define RW_SEEK_SET	0	/**< Seek from the beginning of data */
-#define RW_SEEK_CUR	1	/**< Seek relative to current read point */
-#define RW_SEEK_END	2	/**< Seek relative to the end of data */
+#define RW_SEEK_SET 0   /**< Seek from the beginning of data */
+#define RW_SEEK_CUR 1   /**< Seek relative to current read point */
+#define RW_SEEK_END 2   /**< Seek relative to the end of data */
 /*@}*/
 
 /** @name Macros to easily read and write from an SDL_RWops structure */
 /*@{*/
-#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
-#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, RW_SEEK_CUR)
-#define SDL_RWread(ctx, ptr, size, n)	(ctx)->read(ctx, ptr, size, n)
-#define SDL_RWwrite(ctx, ptr, size, n)	(ctx)->write(ctx, ptr, size, n)
-#define SDL_RWclose(ctx)		(ctx)->close(ctx)
+#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
+#define SDL_RWtell(ctx)         (ctx)->seek(ctx, 0, RW_SEEK_CUR)
+#define SDL_RWread(ctx, ptr, size, n)   (ctx)->read(ctx, ptr, size, n)
+#define SDL_RWwrite(ctx, ptr, size, n)  (ctx)->write(ctx, ptr, size, n)
+#define SDL_RWclose(ctx)        (ctx)->close(ctx)
 /*@}*/
 
 /** @name Read an item of the specified endianness and return in native format */
--- a/misc/winutils/include/SDL_stdinc.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_stdinc.h	Tue Jan 21 22:53:15 2014 +0100
@@ -75,8 +75,8 @@
 #endif
 
 /** The number of elements in an array */
-#define SDL_arraysize(array)	(sizeof(array)/sizeof(array[0]))
-#define SDL_TABLESIZE(table)	SDL_arraysize(table)
+#define SDL_arraysize(array)    (sizeof(array)/sizeof(array[0]))
+#define SDL_TABLESIZE(table)    SDL_arraysize(table)
 
 /* Use proper C++ casts when compiled as C++ to be compatible with the option
  -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above. */
@@ -91,27 +91,27 @@
 /** @name Basic data types */
 /*@{*/
 typedef enum {
-	SDL_FALSE = 0,
-	SDL_TRUE  = 1
+    SDL_FALSE = 0,
+    SDL_TRUE  = 1
 } SDL_bool;
 
-typedef int8_t		Sint8;
-typedef uint8_t		Uint8;
-typedef int16_t		Sint16;
-typedef uint16_t	Uint16;
-typedef int32_t		Sint32;
-typedef uint32_t	Uint32;
+typedef int8_t      Sint8;
+typedef uint8_t     Uint8;
+typedef int16_t     Sint16;
+typedef uint16_t    Uint16;
+typedef int32_t     Sint32;
+typedef uint32_t    Uint32;
 
 #ifdef SDL_HAS_64BIT_TYPE
-typedef int64_t		Sint64;
+typedef int64_t     Sint64;
 #ifndef SYMBIAN32_GCCE
-typedef uint64_t	Uint64;
+typedef uint64_t    Uint64;
 #endif
 #else
 /* This is really just a hack to prevent the compiler from complaining */
 typedef struct {
-	Uint32 hi;
-	Uint32 lo;
+    Uint32 hi;
+    Uint32 lo;
 } Uint64, Sint64;
 #endif
 
@@ -144,7 +144,7 @@
 #endif
 
 typedef enum {
-	DUMMY_ENUM_VALUE
+    DUMMY_ENUM_VALUE
 } SDL_DUMMY_ENUM;
 
 #ifndef __NDS__
@@ -159,25 +159,25 @@
 #endif
 
 #ifdef HAVE_MALLOC
-#define SDL_malloc	malloc
+#define SDL_malloc  malloc
 #else
 extern DECLSPEC void * SDLCALL SDL_malloc(size_t size);
 #endif
 
 #ifdef HAVE_CALLOC
-#define SDL_calloc	calloc
+#define SDL_calloc  calloc
 #else
 extern DECLSPEC void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
 #endif
 
 #ifdef HAVE_REALLOC
-#define SDL_realloc	realloc
+#define SDL_realloc realloc
 #else
 extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size);
 #endif
 
 #ifdef HAVE_FREE
-#define SDL_free	free
+#define SDL_free    free
 #else
 extern DECLSPEC void SDLCALL SDL_free(void *mem);
 #endif
@@ -213,32 +213,32 @@
 #endif
 
 #ifdef HAVE_GETENV
-#define SDL_getenv	getenv
+#define SDL_getenv  getenv
 #else
 extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
 #endif
 
 #ifdef HAVE_PUTENV
-#define SDL_putenv	putenv
+#define SDL_putenv  putenv
 #else
 extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
 #endif
 
 #ifdef HAVE_QSORT
-#define SDL_qsort	qsort
+#define SDL_qsort   qsort
 #else
 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
            int (*compare)(const void *, const void *));
 #endif
 
 #ifdef HAVE_ABS
-#define SDL_abs		abs
+#define SDL_abs     abs
 #else
-#define SDL_abs(X)	((X) < 0 ? -(X) : (X))
+#define SDL_abs(X)  ((X) < 0 ? -(X) : (X))
 #endif
 
-#define SDL_min(x, y)	(((x) < (y)) ? (x) : (y))
-#define SDL_max(x, y)	(((x) > (y)) ? (x) : (y))
+#define SDL_min(x, y)   (((x) < (y)) ? (x) : (y))
+#define SDL_max(x, y)   (((x) > (y)) ? (x) : (y))
 
 #ifdef HAVE_CTYPE_H
 #define SDL_isdigit(X)  isdigit(X)
@@ -259,32 +259,32 @@
 #endif
 
 #if defined(__GNUC__) && defined(i386)
-#define SDL_memset4(dst, val, len)				\
-do {								\
-	int u0, u1, u2;						\
-	__asm__ __volatile__ (					\
-		"cld\n\t"					\
-		"rep ; stosl\n\t"				\
-		: "=&D" (u0), "=&a" (u1), "=&c" (u2)		\
-		: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))	\
-		: "memory" );					\
+#define SDL_memset4(dst, val, len)              \
+do {                                \
+    int u0, u1, u2;                     \
+    __asm__ __volatile__ (                  \
+        "cld\n\t"                   \
+        "rep ; stosl\n\t"               \
+        : "=&D" (u0), "=&a" (u1), "=&c" (u2)        \
+        : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))  \
+        : "memory" );                   \
 } while(0)
 #endif
 #ifndef SDL_memset4
-#define SDL_memset4(dst, val, len)		\
-do {						\
-	unsigned _count = (len);		\
-	unsigned _n = (_count + 3) / 4;		\
-	Uint32 *_p = SDL_static_cast(Uint32 *, dst);	\
-	Uint32 _val = (val);			\
-	if (len == 0) break;			\
-        switch (_count % 4) {			\
-        case 0: do {    *_p++ = _val;		\
-        case 3:         *_p++ = _val;		\
-        case 2:         *_p++ = _val;		\
-        case 1:         *_p++ = _val;		\
-		} while ( --_n );		\
-	}					\
+#define SDL_memset4(dst, val, len)      \
+do {                        \
+    unsigned _count = (len);        \
+    unsigned _n = (_count + 3) / 4;     \
+    Uint32 *_p = SDL_static_cast(Uint32 *, dst);    \
+    Uint32 _val = (val);            \
+    if (len == 0) break;            \
+        switch (_count % 4) {           \
+        case 0: do {    *_p++ = _val;       \
+        case 3:         *_p++ = _val;       \
+        case 2:         *_p++ = _val;       \
+        case 1:         *_p++ = _val;       \
+        } while ( --_n );       \
+    }                   \
 } while(0)
 #endif
 
@@ -292,29 +292,29 @@
 #if defined(__MACH__) && defined(__APPLE__)
 #define SDL_memcpy(dst, src, len) memcpy(dst, src, len)
 #elif defined(__GNUC__) && defined(i386)
-#define SDL_memcpy(dst, src, len)					  \
-do {									  \
-	int u0, u1, u2;						  	  \
-	__asm__ __volatile__ (						  \
-		"cld\n\t"						  \
-		"rep ; movsl\n\t"					  \
-		"testb $2,%b4\n\t"					  \
-		"je 1f\n\t"						  \
-		"movsw\n"						  \
-		"1:\ttestb $1,%b4\n\t"					  \
-		"je 2f\n\t"						  \
-		"movsb\n"						  \
-		"2:"							  \
-		: "=&c" (u0), "=&D" (u1), "=&S" (u2)			  \
-		: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
-		: "memory" );						  \
+#define SDL_memcpy(dst, src, len)                     \
+do {                                      \
+    int u0, u1, u2;                           \
+    __asm__ __volatile__ (                        \
+        "cld\n\t"                         \
+        "rep ; movsl\n\t"                     \
+        "testb $2,%b4\n\t"                    \
+        "je 1f\n\t"                       \
+        "movsw\n"                         \
+        "1:\ttestb $1,%b4\n\t"                    \
+        "je 2f\n\t"                       \
+        "movsb\n"                         \
+        "2:"                              \
+        : "=&c" (u0), "=&D" (u1), "=&S" (u2)              \
+        : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
+        : "memory" );                         \
 } while(0)
 #endif
 #ifndef SDL_memcpy
 #ifdef HAVE_MEMCPY
 #define SDL_memcpy      memcpy
 #elif defined(HAVE_BCOPY)
-#define SDL_memcpy(d, s, n)	bcopy((s), (d), (n))
+#define SDL_memcpy(d, s, n) bcopy((s), (d), (n))
 #else
 extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
 #endif
@@ -324,46 +324,46 @@
 #if defined(__MACH__) && defined(__APPLE__)
 #define SDL_memcpy4(dst, src, len) memcpy(dst, src, (len)*4)
 #elif defined(__GNUC__) && defined(i386)
-#define SDL_memcpy4(dst, src, len)				\
-do {								\
-	int ecx, edi, esi;					\
-	__asm__ __volatile__ (					\
-		"cld\n\t"					\
-		"rep ; movsl"					\
-		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
-		: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)	\
-		: "memory" );					\
+#define SDL_memcpy4(dst, src, len)              \
+do {                                \
+    int ecx, edi, esi;                  \
+    __asm__ __volatile__ (                  \
+        "cld\n\t"                   \
+        "rep ; movsl"                   \
+        : "=&c" (ecx), "=&D" (edi), "=&S" (esi)     \
+        : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)    \
+        : "memory" );                   \
 } while(0)
 #endif
 #ifndef SDL_memcpy4
-#define SDL_memcpy4(dst, src, len)	SDL_memcpy(dst, src, (len) << 2)
+#define SDL_memcpy4(dst, src, len)  SDL_memcpy(dst, src, (len) << 2)
 #endif
 
 #if defined(__GNUC__) && defined(i386)
-#define SDL_revcpy(dst, src, len)			\
-do {							\
-	int u0, u1, u2;					\
-	char *dstp = SDL_static_cast(char *, dst);	\
-	char *srcp = SDL_static_cast(char *, src);	\
-	int n = (len);					\
-	if ( n >= 4 ) {					\
-	__asm__ __volatile__ (				\
-		"std\n\t"				\
-		"rep ; movsl\n\t"			\
-		"cld\n\t"				\
-		: "=&c" (u0), "=&D" (u1), "=&S" (u2)	\
-		: "0" (n >> 2),				\
-		  "1" (dstp+(n-4)), "2" (srcp+(n-4))	\
-		: "memory" );				\
-	}						\
-	switch (n & 3) {				\
-		case 3: dstp[2] = srcp[2];		\
-		case 2: dstp[1] = srcp[1];		\
-		case 1: dstp[0] = srcp[0];		\
-			break;				\
-		default:				\
-			break;				\
-	}						\
+#define SDL_revcpy(dst, src, len)           \
+do {                            \
+    int u0, u1, u2;                 \
+    char *dstp = SDL_static_cast(char *, dst);  \
+    char *srcp = SDL_static_cast(char *, src);  \
+    int n = (len);                  \
+    if ( n >= 4 ) {                 \
+    __asm__ __volatile__ (              \
+        "std\n\t"               \
+        "rep ; movsl\n\t"           \
+        "cld\n\t"               \
+        : "=&c" (u0), "=&D" (u1), "=&S" (u2)    \
+        : "0" (n >> 2),             \
+          "1" (dstp+(n-4)), "2" (srcp+(n-4))    \
+        : "memory" );               \
+    }                       \
+    switch (n & 3) {                \
+        case 3: dstp[2] = srcp[2];      \
+        case 2: dstp[1] = srcp[1];      \
+        case 1: dstp[0] = srcp[0];      \
+            break;              \
+        default:                \
+            break;              \
+    }                       \
 } while(0)
 #endif
 #ifndef SDL_revcpy
@@ -373,15 +373,15 @@
 #ifdef HAVE_MEMMOVE
 #define SDL_memmove     memmove
 #elif defined(HAVE_BCOPY)
-#define SDL_memmove(d, s, n)	bcopy((s), (d), (n))
+#define SDL_memmove(d, s, n)    bcopy((s), (d), (n))
 #else
-#define SDL_memmove(dst, src, len)			\
-do {							\
-	if ( dst < src ) {				\
-		SDL_memcpy(dst, src, len);		\
-	} else {					\
-		SDL_revcpy(dst, src, len);		\
-	}						\
+#define SDL_memmove(dst, src, len)          \
+do {                            \
+    if ( dst < src ) {              \
+        SDL_memcpy(dst, src, len);      \
+    } else {                    \
+        SDL_revcpy(dst, src, len);      \
+    }                       \
 } while(0)
 #endif
 
@@ -458,7 +458,7 @@
 #ifdef HAVE_ITOA
 #define SDL_itoa        itoa
 #else
-#define SDL_itoa(value, string, radix)	SDL_ltoa((long)value, string, radix)
+#define SDL_itoa(value, string, radix)  SDL_ltoa((long)value, string, radix)
 #endif
 
 #ifdef HAVE__LTOA
@@ -470,7 +470,7 @@
 #ifdef HAVE__UITOA
 #define SDL_uitoa       _uitoa
 #else
-#define SDL_uitoa(value, string, radix)	SDL_ultoa((long)value, string, radix)
+#define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix)
 #endif
 
 #ifdef HAVE__ULTOA
@@ -584,13 +584,13 @@
 #endif
 
 /** @name SDL_ICONV Error Codes
- *  The SDL implementation of iconv() returns these error codes 
+ *  The SDL implementation of iconv() returns these error codes
  */
 /*@{*/
-#define SDL_ICONV_ERROR		(size_t)-1
-#define SDL_ICONV_E2BIG		(size_t)-2
-#define SDL_ICONV_EILSEQ	(size_t)-3
-#define SDL_ICONV_EINVAL	(size_t)-4
+#define SDL_ICONV_ERROR     (size_t)-1
+#define SDL_ICONV_E2BIG     (size_t)-2
+#define SDL_ICONV_EILSEQ    (size_t)-3
+#define SDL_ICONV_EINVAL    (size_t)-4
 /*@}*/
 
 #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
@@ -607,9 +607,9 @@
  *  string that must be freed with SDL_free() or NULL on error.
  */
 extern DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft);
-#define SDL_iconv_utf8_locale(S)	SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
-#define SDL_iconv_utf8_ucs2(S)		(Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
-#define SDL_iconv_utf8_ucs4(S)		(Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
+#define SDL_iconv_utf8_locale(S)    SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
+#define SDL_iconv_utf8_ucs2(S)      (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
+#define SDL_iconv_utf8_ucs4(S)      (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
 
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
--- a/misc/winutils/include/SDL_syswm.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_syswm.h	Tue Jan 21 22:53:15 2014 +0100
@@ -65,16 +65,16 @@
 
 /** These are the various supported subsystems under UNIX */
 typedef enum {
-	SDL_SYSWM_X11
+    SDL_SYSWM_X11
 } SDL_SYSWM_TYPE;
 
 /** The UNIX custom event structure */
 struct SDL_SysWMmsg {
-	SDL_version version;
-	SDL_SYSWM_TYPE subsystem;
-	union {
-	    XEvent xevent;
-	} event;
+    SDL_version version;
+    SDL_SYSWM_TYPE subsystem;
+    union {
+        XEvent xevent;
+    } event;
 };
 
 /** The UNIX custom window manager information structure.
@@ -82,35 +82,35 @@
  *  low level system it is using, and will be one of SDL_SYSWM_TYPE.
  */
 typedef struct SDL_SysWMinfo {
-	SDL_version version;
-	SDL_SYSWM_TYPE subsystem;
-	union {
-	    struct {
-	    	Display *display;	/**< The X11 display */
-	    	Window window;		/**< The X11 display window */
-		/** These locking functions should be called around
-                 *  any X11 functions using the display variable, 
+    SDL_version version;
+    SDL_SYSWM_TYPE subsystem;
+    union {
+        struct {
+            Display *display;   /**< The X11 display */
+            Window window;      /**< The X11 display window */
+        /** These locking functions should be called around
+                 *  any X11 functions using the display variable,
                  *  but not the gfxdisplay variable.
                  *  They lock the event thread, so should not be
-		 *  called around event functions or from event filters.
-		 */
+         *  called around event functions or from event filters.
+         */
                 /*@{*/
-		void (*lock_func)(void);
-		void (*unlock_func)(void);
+        void (*lock_func)(void);
+        void (*unlock_func)(void);
                 /*@}*/
 
-		/** @name Introduced in SDL 1.0.2 */
+        /** @name Introduced in SDL 1.0.2 */
                 /*@{*/
-	    	Window fswindow;	/**< The X11 fullscreen window */
-	    	Window wmwindow;	/**< The X11 managed input window */
+            Window fswindow;    /**< The X11 fullscreen window */
+            Window wmwindow;    /**< The X11 managed input window */
                 /*@}*/
 
-		/** @name Introduced in SDL 1.2.12 */
+        /** @name Introduced in SDL 1.2.12 */
                 /*@{*/
-		Display *gfxdisplay;	/**< The X11 display to which rendering is done */
+        Display *gfxdisplay;    /**< The X11 display to which rendering is done */
                 /*@}*/
-	    } x11;
-	} info;
+        } x11;
+    } info;
 } SDL_SysWMinfo;
 
 #elif defined(SDL_VIDEO_DRIVER_NANOX)
@@ -118,14 +118,14 @@
 
 /** The generic custom event structure */
 struct SDL_SysWMmsg {
-	SDL_version version;
-	int data;
+    SDL_version version;
+    int data;
 };
 
 /** The windows custom window manager information structure */
 typedef struct SDL_SysWMinfo {
-	SDL_version version ;
-	GR_WINDOW_ID window ;	/* The display window */
+    SDL_version version ;
+    GR_WINDOW_ID window ;   /* The display window */
 } SDL_SysWMinfo;
 
 #elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
@@ -134,35 +134,35 @@
 
 /** The windows custom event structure */
 struct SDL_SysWMmsg {
-	SDL_version version;
-	HWND hwnd;			/**< The window for the message */
-	UINT msg;			/**< The type of message */
-	WPARAM wParam;			/**< WORD message parameter */
-	LPARAM lParam;			/**< LONG message parameter */
+    SDL_version version;
+    HWND hwnd;          /**< The window for the message */
+    UINT msg;           /**< The type of message */
+    WPARAM wParam;          /**< WORD message parameter */
+    LPARAM lParam;          /**< LONG message parameter */
 };
 
 /** The windows custom window manager information structure */
 typedef struct SDL_SysWMinfo {
-	SDL_version version;
-	HWND window;			/**< The Win32 display window */
-	HGLRC hglrc;			/**< The OpenGL context, if any */
+    SDL_version version;
+    HWND window;            /**< The Win32 display window */
+    HGLRC hglrc;            /**< The OpenGL context, if any */
 } SDL_SysWMinfo;
 
 #elif defined(SDL_VIDEO_DRIVER_RISCOS)
 
 /** RISC OS custom event structure */
 struct SDL_SysWMmsg {
-	SDL_version version;
-	int eventCode;		/**< The window for the message */
-	int pollBlock[64];
+    SDL_version version;
+    int eventCode;      /**< The window for the message */
+    int pollBlock[64];
 };
 
 /** The RISC OS custom window manager information structure */
 typedef struct SDL_SysWMinfo {
-	SDL_version version;
-	int wimpVersion;    /**< Wimp version running under */
-	int taskHandle;     /**< The RISC OS task handle */
-	int window;		/**< The RISC OS display window */
+    SDL_version version;
+    int wimpVersion;    /**< Wimp version running under */
+    int taskHandle;     /**< The RISC OS task handle */
+    int window;     /**< The RISC OS display window */
 } SDL_SysWMinfo;
 
 #elif defined(SDL_VIDEO_DRIVER_PHOTON)
@@ -171,28 +171,28 @@
 
 /** The QNX custom event structure */
 struct SDL_SysWMmsg {
-	SDL_version version;
-	int data;
+    SDL_version version;
+    int data;
 };
 
 /** The QNX custom window manager information structure */
 typedef struct SDL_SysWMinfo {
-	SDL_version version;
-	int data;
+    SDL_version version;
+    int data;
 } SDL_SysWMinfo;
 
 #else
 
 /** The generic custom event structure */
 struct SDL_SysWMmsg {
-	SDL_version version;
-	int data;
+    SDL_version version;
+    int data;
 };
 
 /** The generic custom window manager information structure */
 typedef struct SDL_SysWMinfo {
-	SDL_version version;
-	int data;
+    SDL_version version;
+    int data;
 } SDL_SysWMinfo;
 
 #endif /* video driver type */
@@ -203,7 +203,7 @@
 /**
  * This function gives you custom hooks into the window manager information.
  * It fills the structure pointed to by 'info' with custom information and
- * returns 0 if the function is not implemented, 1 if the function is 
+ * returns 0 if the function is not implemented, 1 if the function is
  * implemented and no error occurred, and -1 if the version member of
  * the 'info' structure is not filled in or not supported.
  *
--- a/misc/winutils/include/SDL_thread.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_thread.h	Tue Jan 21 22:53:15 2014 +0100
@@ -24,7 +24,7 @@
 #define _SDL_thread_h
 
 /** @file SDL_thread.h
- *  Header for the SDL thread management routines 
+ *  Header for the SDL thread management routines
  *
  *  @note These are independent of the other SDL routines.
  */
@@ -66,11 +66,11 @@
 #endif
 
 #ifdef __OS2__
-typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg); 
+typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg);
 typedef void (*pfnSDL_CurrentEndThread)(void);
 #else
 typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
-        unsigned (__stdcall *func)(void *), void *arg, 
+        unsigned (__stdcall *func)(void *), void *arg,
         unsigned, unsigned *threadID);
 typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
 #endif
--- a/misc/winutils/include/SDL_timer.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_timer.h	Tue Jan 21 22:53:15 2014 +0100
@@ -37,15 +37,15 @@
 #endif
 
 /** This is the OS scheduler timeslice, in milliseconds */
-#define SDL_TIMESLICE		10
+#define SDL_TIMESLICE       10
 
 /** This is the maximum resolution of the SDL timer on all platforms */
-#define TIMER_RESOLUTION	10	/**< Experimentally determined */
+#define TIMER_RESOLUTION    10  /**< Experimentally determined */
 
 /**
  * Get the number of milliseconds since the SDL library initialization.
  * Note that this value wraps if the program runs for more than ~49 days.
- */ 
+ */
 extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
 
 /** Wait a specified number of milliseconds before returning */
@@ -57,7 +57,7 @@
 /**
  * Set a callback to run after the specified number of milliseconds has
  * elapsed. The callback function is passed the current timer interval
- * and returns the next timer interval.  If the returned value is the 
+ * and returns the next timer interval.  If the returned value is the
  * same as the one passed in, the periodic alarm continues, otherwise a
  * new alarm is scheduled.  If the callback returns 0, the periodic alarm
  * is cancelled.
@@ -70,7 +70,7 @@
  * The maximum resolution of this timer is 10 ms, which means that if
  * you request a 16 ms timer, your callback will run approximately 20 ms
  * later on an unloaded system.  If you wanted to set a flag signaling
- * a frame update at 30 frames per second (every 33 ms), you might set a 
+ * a frame update at 30 frames per second (every 33 ms), you might set a
  * timer for 30 ms:
  *   @code SDL_SetTimer((33/10)*10, flag_update); @endcode
  *
--- a/misc/winutils/include/SDL_version.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_version.h	Tue Jan 21 22:53:15 2014 +0100
@@ -39,42 +39,42 @@
  *  Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
  */
 /*@{*/
-#define SDL_MAJOR_VERSION	1
-#define SDL_MINOR_VERSION	2
-#define SDL_PATCHLEVEL		15
+#define SDL_MAJOR_VERSION   1
+#define SDL_MINOR_VERSION   2
+#define SDL_PATCHLEVEL      15
 /*@}*/
 
 typedef struct SDL_version {
-	Uint8 major;
-	Uint8 minor;
-	Uint8 patch;
+    Uint8 major;
+    Uint8 minor;
+    Uint8 patch;
 } SDL_version;
 
 /**
  * This macro can be used to fill a version structure with the compile-time
  * version of the SDL library.
  */
-#define SDL_VERSION(X)							\
-{									\
-	(X)->major = SDL_MAJOR_VERSION;					\
-	(X)->minor = SDL_MINOR_VERSION;					\
-	(X)->patch = SDL_PATCHLEVEL;					\
+#define SDL_VERSION(X)                          \
+{                                   \
+    (X)->major = SDL_MAJOR_VERSION;                 \
+    (X)->minor = SDL_MINOR_VERSION;                 \
+    (X)->patch = SDL_PATCHLEVEL;                    \
 }
 
 /** This macro turns the version numbers into a numeric value:
  *  (1,2,3) -> (1203)
  *  This assumes that there will never be more than 100 patchlevels
  */
-#define SDL_VERSIONNUM(X, Y, Z)						\
-	((X)*1000 + (Y)*100 + (Z))
+#define SDL_VERSIONNUM(X, Y, Z)                     \
+    ((X)*1000 + (Y)*100 + (Z))
 
 /** This is the version number macro for the current SDL version */
 #define SDL_COMPILEDVERSION \
-	SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
+    SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
 
 /** This macro will evaluate to true if compiled with SDL at least X.Y.Z */
 #define SDL_VERSION_ATLEAST(X, Y, Z) \
-	(SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
+    (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
 
 /** This function gets the version of the dynamically linked SDL library.
  *  it should NOT be used to fill a version structure, instead you should
--- a/misc/winutils/include/SDL_video.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/SDL_video.h	Tue Jan 21 22:53:15 2014 +0100
@@ -48,77 +48,77 @@
 /** @name Useful data types */
 /*@{*/
 typedef struct SDL_Rect {
-	Sint16 x, y;
-	Uint16 w, h;
+    Sint16 x, y;
+    Uint16 w, h;
 } SDL_Rect;
 
 typedef struct SDL_Color {
-	Uint8 r;
-	Uint8 g;
-	Uint8 b;
-	Uint8 unused;
+    Uint8 r;
+    Uint8 g;
+    Uint8 b;
+    Uint8 unused;
 } SDL_Color;
 #define SDL_Colour SDL_Color
 
 typedef struct SDL_Palette {
-	int       ncolors;
-	SDL_Color *colors;
+    int       ncolors;
+    SDL_Color *colors;
 } SDL_Palette;
 /*@}*/
 
 /** Everything in the pixel format structure is read-only */
 typedef struct SDL_PixelFormat {
-	SDL_Palette *palette;
-	Uint8  BitsPerPixel;
-	Uint8  BytesPerPixel;
-	Uint8  Rloss;
-	Uint8  Gloss;
-	Uint8  Bloss;
-	Uint8  Aloss;
-	Uint8  Rshift;
-	Uint8  Gshift;
-	Uint8  Bshift;
-	Uint8  Ashift;
-	Uint32 Rmask;
-	Uint32 Gmask;
-	Uint32 Bmask;
-	Uint32 Amask;
+    SDL_Palette *palette;
+    Uint8  BitsPerPixel;
+    Uint8  BytesPerPixel;
+    Uint8  Rloss;
+    Uint8  Gloss;
+    Uint8  Bloss;
+    Uint8  Aloss;
+    Uint8  Rshift;
+    Uint8  Gshift;
+    Uint8  Bshift;
+    Uint8  Ashift;
+    Uint32 Rmask;
+    Uint32 Gmask;
+    Uint32 Bmask;
+    Uint32 Amask;
 
-	/** RGB color key information */
-	Uint32 colorkey;
-	/** Alpha value information (per-surface alpha) */
-	Uint8  alpha;
+    /** RGB color key information */
+    Uint32 colorkey;
+    /** Alpha value information (per-surface alpha) */
+    Uint8  alpha;
 } SDL_PixelFormat;
 
 /** This structure should be treated as read-only, except for 'pixels',
  *  which, if not NULL, contains the raw pixel data for the surface.
  */
 typedef struct SDL_Surface {
-	Uint32 flags;				/**< Read-only */
-	SDL_PixelFormat *format;		/**< Read-only */
-	int w, h;				/**< Read-only */
-	Uint16 pitch;				/**< Read-only */
-	void *pixels;				/**< Read-write */
-	int offset;				/**< Private */
+    Uint32 flags;               /**< Read-only */
+    SDL_PixelFormat *format;        /**< Read-only */
+    int w, h;               /**< Read-only */
+    Uint16 pitch;               /**< Read-only */
+    void *pixels;               /**< Read-write */
+    int offset;             /**< Private */
 
-	/** Hardware-specific surface info */
-	struct private_hwdata *hwdata;
+    /** Hardware-specific surface info */
+    struct private_hwdata *hwdata;
 
-	/** clipping information */
-	SDL_Rect clip_rect;			/**< Read-only */
-	Uint32 unused1;				/**< for binary compatibility */
+    /** clipping information */
+    SDL_Rect clip_rect;         /**< Read-only */
+    Uint32 unused1;             /**< for binary compatibility */
 
-	/** Allow recursive locks */
-	Uint32 locked;				/**< Private */
+    /** Allow recursive locks */
+    Uint32 locked;              /**< Private */
 
-	/** info for fast blit mapping to other surfaces */
-	struct SDL_BlitMap *map;		/**< Private */
+    /** info for fast blit mapping to other surfaces */
+    struct SDL_BlitMap *map;        /**< Private */
 
-	/** format version, bumped at every change to invalidate blit maps */
-	unsigned int format_version;		/**< Private */
+    /** format version, bumped at every change to invalidate blit maps */
+    unsigned int format_version;        /**< Private */
 
-	/** Reference count -- used when freeing surface */
-	int refcount;				/**< Read-mostly */
+    /** Reference count -- used when freeing surface */
+    int refcount;               /**< Read-mostly */
 } SDL_Surface;
 
 /** @name SDL_Surface Flags
@@ -128,100 +128,100 @@
 
 /** Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() */
 /*@{*/
-#define SDL_SWSURFACE	0x00000000	/**< Surface is in system memory */
-#define SDL_HWSURFACE	0x00000001	/**< Surface is in video memory */
-#define SDL_ASYNCBLIT	0x00000004	/**< Use asynchronous blits if possible */
+#define SDL_SWSURFACE   0x00000000  /**< Surface is in system memory */
+#define SDL_HWSURFACE   0x00000001  /**< Surface is in video memory */
+#define SDL_ASYNCBLIT   0x00000004  /**< Use asynchronous blits if possible */
 /*@}*/
 
 /** Available for SDL_SetVideoMode() */
 /*@{*/
-#define SDL_ANYFORMAT	0x10000000	/**< Allow any video depth/pixel-format */
-#define SDL_HWPALETTE	0x20000000	/**< Surface has exclusive palette */
-#define SDL_DOUBLEBUF	0x40000000	/**< Set up double-buffered video mode */
-#define SDL_FULLSCREEN	0x80000000	/**< Surface is a full screen display */
+#define SDL_ANYFORMAT   0x10000000  /**< Allow any video depth/pixel-format */
+#define SDL_HWPALETTE   0x20000000  /**< Surface has exclusive palette */
+#define SDL_DOUBLEBUF   0x40000000  /**< Set up double-buffered video mode */
+#define SDL_FULLSCREEN  0x80000000  /**< Surface is a full screen display */
 #define SDL_OPENGL      0x00000002      /**< Create an OpenGL rendering context */
-#define SDL_OPENGLBLIT	0x0000000A	/**< Create an OpenGL rendering context and use it for blitting */
-#define SDL_RESIZABLE	0x00000010	/**< This video mode may be resized */
-#define SDL_NOFRAME	0x00000020	/**< No window caption or edge frame */
+#define SDL_OPENGLBLIT  0x0000000A  /**< Create an OpenGL rendering context and use it for blitting */
+#define SDL_RESIZABLE   0x00000010  /**< This video mode may be resized */
+#define SDL_NOFRAME 0x00000020  /**< No window caption or edge frame */
 /*@}*/
 
 /** Used internally (read-only) */
 /*@{*/
-#define SDL_HWACCEL	0x00000100	/**< Blit uses hardware acceleration */
-#define SDL_SRCCOLORKEY	0x00001000	/**< Blit uses a source color key */
-#define SDL_RLEACCELOK	0x00002000	/**< Private flag */
-#define SDL_RLEACCEL	0x00004000	/**< Surface is RLE encoded */
-#define SDL_SRCALPHA	0x00010000	/**< Blit uses source alpha blending */
-#define SDL_PREALLOC	0x01000000	/**< Surface uses preallocated memory */
+#define SDL_HWACCEL 0x00000100  /**< Blit uses hardware acceleration */
+#define SDL_SRCCOLORKEY 0x00001000  /**< Blit uses a source color key */
+#define SDL_RLEACCELOK  0x00002000  /**< Private flag */
+#define SDL_RLEACCEL    0x00004000  /**< Surface is RLE encoded */
+#define SDL_SRCALPHA    0x00010000  /**< Blit uses source alpha blending */
+#define SDL_PREALLOC    0x01000000  /**< Surface uses preallocated memory */
 /*@}*/
 
 /*@}*/
 
 /** Evaluates to true if the surface needs to be locked before access */
-#define SDL_MUSTLOCK(surface)	\
-  (surface->offset ||		\
+#define SDL_MUSTLOCK(surface)   \
+  (surface->offset ||       \
   ((surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_RLEACCEL)) != 0))
 
 /** typedef for private surface blitting functions */
 typedef int (*SDL_blit)(struct SDL_Surface *src, SDL_Rect *srcrect,
-			struct SDL_Surface *dst, SDL_Rect *dstrect);
+            struct SDL_Surface *dst, SDL_Rect *dstrect);
 
 
 /** Useful for determining the video hardware capabilities */
 typedef struct SDL_VideoInfo {
-	Uint32 hw_available :1;	/**< Flag: Can you create hardware surfaces? */
-	Uint32 wm_available :1;	/**< Flag: Can you talk to a window manager? */
-	Uint32 UnusedBits1  :6;
-	Uint32 UnusedBits2  :1;
-	Uint32 blit_hw      :1;	/**< Flag: Accelerated blits HW --> HW */
-	Uint32 blit_hw_CC   :1;	/**< Flag: Accelerated blits with Colorkey */
-	Uint32 blit_hw_A    :1;	/**< Flag: Accelerated blits with Alpha */
-	Uint32 blit_sw      :1;	/**< Flag: Accelerated blits SW --> HW */
-	Uint32 blit_sw_CC   :1;	/**< Flag: Accelerated blits with Colorkey */
-	Uint32 blit_sw_A    :1;	/**< Flag: Accelerated blits with Alpha */
-	Uint32 blit_fill    :1;	/**< Flag: Accelerated color fill */
-	Uint32 UnusedBits3  :16;
-	Uint32 video_mem;	/**< The total amount of video memory (in K) */
-	SDL_PixelFormat *vfmt;	/**< Value: The format of the video surface */
-	int    current_w;	/**< Value: The current video mode width */
-	int    current_h;	/**< Value: The current video mode height */
+    Uint32 hw_available :1; /**< Flag: Can you create hardware surfaces? */
+    Uint32 wm_available :1; /**< Flag: Can you talk to a window manager? */
+    Uint32 UnusedBits1  :6;
+    Uint32 UnusedBits2  :1;
+    Uint32 blit_hw      :1; /**< Flag: Accelerated blits HW --> HW */
+    Uint32 blit_hw_CC   :1; /**< Flag: Accelerated blits with Colorkey */
+    Uint32 blit_hw_A    :1; /**< Flag: Accelerated blits with Alpha */
+    Uint32 blit_sw      :1; /**< Flag: Accelerated blits SW --> HW */
+    Uint32 blit_sw_CC   :1; /**< Flag: Accelerated blits with Colorkey */
+    Uint32 blit_sw_A    :1; /**< Flag: Accelerated blits with Alpha */
+    Uint32 blit_fill    :1; /**< Flag: Accelerated color fill */
+    Uint32 UnusedBits3  :16;
+    Uint32 video_mem;   /**< The total amount of video memory (in K) */
+    SDL_PixelFormat *vfmt;  /**< Value: The format of the video surface */
+    int    current_w;   /**< Value: The current video mode width */
+    int    current_h;   /**< Value: The current video mode height */
 } SDL_VideoInfo;
 
 
 /** @name Overlay Formats
  *  The most common video overlay formats.
  *  For an explanation of these pixel formats, see:
- *	http://www.webartz.com/fourcc/indexyuv.htm
+ *  http://www.webartz.com/fourcc/indexyuv.htm
  *
  *  For information on the relationship between color spaces, see:
  *  http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
  */
 /*@{*/
-#define SDL_YV12_OVERLAY  0x32315659	/**< Planar mode: Y + V + U  (3 planes) */
-#define SDL_IYUV_OVERLAY  0x56555949	/**< Planar mode: Y + U + V  (3 planes) */
-#define SDL_YUY2_OVERLAY  0x32595559	/**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
-#define SDL_UYVY_OVERLAY  0x59565955	/**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
-#define SDL_YVYU_OVERLAY  0x55595659	/**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
+#define SDL_YV12_OVERLAY  0x32315659    /**< Planar mode: Y + V + U  (3 planes) */
+#define SDL_IYUV_OVERLAY  0x56555949    /**< Planar mode: Y + U + V  (3 planes) */
+#define SDL_YUY2_OVERLAY  0x32595559    /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
+#define SDL_UYVY_OVERLAY  0x59565955    /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
+#define SDL_YVYU_OVERLAY  0x55595659    /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
 /*@}*/
 
 /** The YUV hardware video overlay */
 typedef struct SDL_Overlay {
-	Uint32 format;				/**< Read-only */
-	int w, h;				/**< Read-only */
-	int planes;				/**< Read-only */
-	Uint16 *pitches;			/**< Read-only */
-	Uint8 **pixels;				/**< Read-write */
+    Uint32 format;              /**< Read-only */
+    int w, h;               /**< Read-only */
+    int planes;             /**< Read-only */
+    Uint16 *pitches;            /**< Read-only */
+    Uint8 **pixels;             /**< Read-write */
 
-	/** @name Hardware-specific surface info */
+    /** @name Hardware-specific surface info */
         /*@{*/
-	struct private_yuvhwfuncs *hwfuncs;
-	struct private_yuvhwdata *hwdata;
+    struct private_yuvhwfuncs *hwfuncs;
+    struct private_yuvhwdata *hwdata;
         /*@{*/
 
-	/** @name Special flags */
+    /** @name Special flags */
         /*@{*/
-	Uint32 hw_overlay :1;	/**< Flag: This overlay hardware accelerated? */
-	Uint32 UnusedBits :31;
+    Uint32 hw_overlay :1;   /**< Flag: This overlay hardware accelerated? */
+    Uint32 UnusedBits :31;
         /*@}*/
 } SDL_Overlay;
 
@@ -314,11 +314,11 @@
 
 /**
  * Return a pointer to an array of available screen dimensions for the
- * given format and video flags, sorted largest to smallest.  Returns 
- * NULL if there are no dimensions available for a particular format, 
+ * given format and video flags, sorted largest to smallest.  Returns
+ * NULL if there are no dimensions available for a particular format,
  * or (SDL_Rect **)-1 if any dimension is okay for the given format.
  *
- * If 'format' is NULL, the mode list will be for the format given 
+ * If 'format' is NULL, the mode list will be for the format given
  * by SDL_GetVideoInfo()->vfmt
  */
 extern DECLSPEC SDL_Rect ** SDLCALL SDL_ListModes(SDL_PixelFormat *format, Uint32 flags);
@@ -347,21 +347,21 @@
  * Otherwise, in 8-bit mode, SDL_SetColors() may not be able to set all
  * of the colors exactly the way they are requested, and you should look
  * at the video surface structure to determine the actual palette.
- * If SDL cannot guarantee that the colors you request can be set, 
+ * If SDL cannot guarantee that the colors you request can be set,
  * i.e. if the colormap is shared, then the video surface may be created
  * under emulation in system memory, overriding the SDL_HWSURFACE flag.
  *
  * If SDL_FULLSCREEN is set in 'flags', the SDL library will try to set
  * a fullscreen video mode.  The default is to create a windowed mode
  * if the current graphics system has a window manager.
- * If the SDL library is able to set a fullscreen video mode, this flag 
+ * If the SDL library is able to set a fullscreen video mode, this flag
  * will be set in the surface that is returned.
  *
  * If SDL_DOUBLEBUF is set in 'flags', the SDL library will try to set up
- * two surfaces in video memory and swap between them when you call 
+ * two surfaces in video memory and swap between them when you call
  * SDL_Flip().  This is usually slower than the normal single-buffering
- * scheme, but prevents "tearing" artifacts caused by modifying video 
- * memory while the monitor is refreshing.  It should only be used by 
+ * scheme, but prevents "tearing" artifacts caused by modifying video
+ * memory while the monitor is refreshing.  It should only be used by
  * applications that redraw the entire screen on every update.
  *
  * If SDL_RESIZABLE is set in 'flags', the SDL library will allow the
@@ -382,7 +382,7 @@
  * are not available.
  */
 extern DECLSPEC SDL_Surface * SDLCALL SDL_SetVideoMode
-			(int width, int height, int bpp, Uint32 flags);
+            (int width, int height, int bpp, Uint32 flags);
 
 /** @name SDL_Update Functions
  * These functions should not be called while 'screen' is locked.
@@ -392,13 +392,13 @@
  * Makes sure the given list of rectangles is updated on the given screen.
  */
 extern DECLSPEC void SDLCALL SDL_UpdateRects
-		(SDL_Surface *screen, int numrects, SDL_Rect *rects);
+        (SDL_Surface *screen, int numrects, SDL_Rect *rects);
 /**
  * If 'x', 'y', 'w' and 'h' are all 0, SDL_UpdateRect will update the entire
  * screen.
  */
 extern DECLSPEC void SDLCALL SDL_UpdateRect
-		(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h);
+        (SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h);
 /*@}*/
 
 /**
@@ -416,7 +416,7 @@
 /**
  * Set the gamma correction for each of the color channels.
  * The gamma values range (approximately) between 0.1 and 10.0
- * 
+ *
  * If this function isn't supported directly by the hardware, it will
  * be emulated using gamma ramps, if available.  If successful, this
  * function returns 0, otherwise it returns -1.
@@ -429,7 +429,7 @@
  * representing a mapping between the input and output for that channel.
  * The input is the index into the array, and the output is the 16-bit
  * gamma value at that index, scaled to the output color precision.
- * 
+ *
  * You may pass NULL for any of the channels to leave it unchanged.
  * If the call succeeds, it will return 0.  If the display driver or
  * hardware does not support gamma translation, or otherwise fails,
@@ -439,7 +439,7 @@
 
 /**
  * Retrieve the current values of the gamma translation tables.
- * 
+ *
  * You must pass in valid pointers to arrays of 256 16-bit quantities.
  * Any of the pointers may be NULL to ignore that channel.
  * If the call succeeds, it will return 0.  If the display driver or
@@ -457,14 +457,14 @@
  * determine the actual color palette.
  *
  * When 'surface' is the surface associated with the current display, the
- * display colormap will be updated with the requested colors.  If 
+ * display colormap will be updated with the requested colors.  If
  * SDL_HWPALETTE was set in SDL_SetVideoMode() flags, SDL_SetColors()
  * will always return 1, and the palette is guaranteed to be set the way
  * you desire, even if the window colormap has to be warped or run under
  * emulation.
  */
-extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface *surface, 
-			SDL_Color *colors, int firstcolor, int ncolors);
+extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface *surface,
+            SDL_Color *colors, int firstcolor, int ncolors);
 
 /**
  * Sets a portion of the colormap for a given 8-bit surface.
@@ -483,8 +483,8 @@
  *     flags = (SDL_LOGPAL|SDL_PHYSPAL).
  */
 extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface *surface, int flags,
-				   SDL_Color *colors, int firstcolor,
-				   int ncolors);
+                   SDL_Color *colors, int firstcolor,
+                   int ncolors);
 
 /**
  * Maps an RGB triple to an opaque pixel value for a given pixel format
@@ -504,15 +504,15 @@
  * Maps a pixel value into the RGB components for a given pixel format
  */
 extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
-				const SDL_PixelFormat * const fmt,
-				Uint8 *r, Uint8 *g, Uint8 *b);
+                const SDL_PixelFormat * const fmt,
+                Uint8 *r, Uint8 *g, Uint8 *b);
 
 /**
  * Maps a pixel value into the RGBA components for a given pixel format
  */
 extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
-				const SDL_PixelFormat * const fmt,
-				Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
+                const SDL_PixelFormat * const fmt,
+                Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
 
 /** @sa SDL_CreateRGBSurface */
 #define SDL_AllocSurface    SDL_CreateRGBSurface
@@ -537,7 +537,7 @@
  * two surfaces in video memory, SDL will try to place the surface in
  * video memory. If this isn't possible or if there is no hardware
  * acceleration available, the surface will be placed in system memory.
- * SDL_SRCALPHA means that the surface will be used for alpha blits and 
+ * SDL_SRCALPHA means that the surface will be used for alpha blits and
  * if the hardware supports hardware acceleration of alpha blits between
  * two surfaces in video memory, to place the surface in video memory
  * if possible, otherwise it will be placed in system memory.
@@ -551,19 +551,19 @@
  * the SDL_HWSURFACE flag set, and will be created in system memory instead.
  */
 extern DECLSPEC SDL_Surface * SDLCALL SDL_CreateRGBSurface
-			(Uint32 flags, int width, int height, int depth, 
-			Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
+            (Uint32 flags, int width, int height, int depth,
+            Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
 /** @sa SDL_CreateRGBSurface */
 extern DECLSPEC SDL_Surface * SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
-			int width, int height, int depth, int pitch,
-			Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
+            int width, int height, int depth, int pitch,
+            Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
 extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface);
 
 /**
  * SDL_LockSurface() sets up a surface for directly accessing the pixels.
  * Between calls to SDL_LockSurface()/SDL_UnlockSurface(), you can write
- * to and read from 'surface->pixels', using the pixel format stored in 
- * 'surface->format'.  Once you are done accessing the surface, you should 
+ * to and read from 'surface->pixels', using the pixel format stored in
+ * 'surface->format'.  Once you are done accessing the surface, you should
  * use SDL_UnlockSurface() to release it.
  *
  * Not all surfaces require locking.  If SDL_MUSTLOCK(surface) evaluates
@@ -571,7 +571,7 @@
  * pixel format of the surface will not change.  In particular, if the
  * SDL_HWSURFACE flag is not given when calling SDL_SetVideoMode(), you
  * will not need to lock the display surface before accessing it.
- * 
+ *
  * No operating system or library calls should be made between lock/unlock
  * pairs, as critical system locks may be held during this time.
  *
@@ -589,7 +589,7 @@
 extern DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP_RW(SDL_RWops *src, int freesrc);
 
 /** Convenience macro -- load a surface from a file */
-#define SDL_LoadBMP(file)	SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
+#define SDL_LoadBMP(file)   SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
 
 /**
  * Save a surface to a seekable SDL data source (memory or file.)
@@ -597,15 +597,15 @@
  * Returns 0 if successful or -1 if there was an error.
  */
 extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
-		(SDL_Surface *surface, SDL_RWops *dst, int freedst);
+        (SDL_Surface *surface, SDL_RWops *dst, int freedst);
 
 /** Convenience macro -- save a surface to a file */
 #define SDL_SaveBMP(surface, file) \
-		SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
+        SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
 
 /**
  * Sets the color key (transparent pixel) in a blittable surface.
- * If 'flag' is SDL_SRCCOLORKEY (optionally OR'd with SDL_RLEACCEL), 
+ * If 'flag' is SDL_SRCCOLORKEY (optionally OR'd with SDL_RLEACCEL),
  * 'key' will be the transparent pixel in the source image of a blit.
  * SDL_RLEACCEL requests RLE acceleration for the surface if present,
  * and removes RLE acceleration if absent.
@@ -613,7 +613,7 @@
  * This function returns 0, or -1 if there was an error.
  */
 extern DECLSPEC int SDLCALL SDL_SetColorKey
-			(SDL_Surface *surface, Uint32 flag, Uint32 key);
+            (SDL_Surface *surface, Uint32 flag, Uint32 key);
 
 /**
  * This function sets the alpha value for the entire surface, as opposed to
@@ -654,11 +654,11 @@
 extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface *surface, SDL_Rect *rect);
 
 /**
- * Creates a new surface of the specified format, and then copies and maps 
- * the given surface to it so the blit of the converted surface will be as 
+ * Creates a new surface of the specified format, and then copies and maps
+ * the given surface to it so the blit of the converted surface will be as
  * fast as possible.  If this function fails, it returns NULL.
  *
- * The 'flags' parameter is passed to SDL_CreateRGBSurface() and has those 
+ * The 'flags' parameter is passed to SDL_CreateRGBSurface() and has those
  * semantics.  You can also pass SDL_RLEACCEL in the flags parameter and
  * SDL will try to RLE accelerate colorkey and alpha blits in the resulting
  * surface.
@@ -666,7 +666,7 @@
  * This function is used internally by SDL_DisplayFormat().
  */
 extern DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurface
-			(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags);
+            (SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags);
 
 /**
  * This performs a fast blit from the source surface to the destination
@@ -683,54 +683,54 @@
  *
  * RGBA->RGB:
  *     SDL_SRCALPHA set:
- * 	alpha-blend (using alpha-channel).
- * 	SDL_SRCCOLORKEY ignored.
+ *  alpha-blend (using alpha-channel).
+ *  SDL_SRCCOLORKEY ignored.
  *     SDL_SRCALPHA not set:
- * 	copy RGB.
- * 	if SDL_SRCCOLORKEY set, only copy the pixels matching the
- * 	RGB values of the source colour key, ignoring alpha in the
- * 	comparison.
- * 
+ *  copy RGB.
+ *  if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ *  RGB values of the source colour key, ignoring alpha in the
+ *  comparison.
+ *
  * RGB->RGBA:
  *     SDL_SRCALPHA set:
- * 	alpha-blend (using the source per-surface alpha value);
- * 	set destination alpha to opaque.
+ *  alpha-blend (using the source per-surface alpha value);
+ *  set destination alpha to opaque.
  *     SDL_SRCALPHA not set:
- * 	copy RGB, set destination alpha to source per-surface alpha value.
+ *  copy RGB, set destination alpha to source per-surface alpha value.
  *     both:
- * 	if SDL_SRCCOLORKEY set, only copy the pixels matching the
- * 	source colour key.
- * 
+ *  if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ *  source colour key.
+ *
  * RGBA->RGBA:
  *     SDL_SRCALPHA set:
- * 	alpha-blend (using the source alpha channel) the RGB values;
- * 	leave destination alpha untouched. [Note: is this correct?]
- * 	SDL_SRCCOLORKEY ignored.
+ *  alpha-blend (using the source alpha channel) the RGB values;
+ *  leave destination alpha untouched. [Note: is this correct?]
+ *  SDL_SRCCOLORKEY ignored.
  *     SDL_SRCALPHA not set:
- * 	copy all of RGBA to the destination.
- * 	if SDL_SRCCOLORKEY set, only copy the pixels matching the
- * 	RGB values of the source colour key, ignoring alpha in the
- * 	comparison.
- * 
- * RGB->RGB: 
+ *  copy all of RGBA to the destination.
+ *  if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ *  RGB values of the source colour key, ignoring alpha in the
+ *  comparison.
+ *
+ * RGB->RGB:
  *     SDL_SRCALPHA set:
- * 	alpha-blend (using the source per-surface alpha value).
+ *  alpha-blend (using the source per-surface alpha value).
  *     SDL_SRCALPHA not set:
- * 	copy RGB.
+ *  copy RGB.
  *     both:
- * 	if SDL_SRCCOLORKEY set, only copy the pixels matching the
- * 	source colour key.
+ *  if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ *  source colour key.
  *
  * If either of the surfaces were in video memory, and the blit returns -2,
- * the video memory was lost, so it should be reloaded with artwork and 
+ * the video memory was lost, so it should be reloaded with artwork and
  * re-blitted:
  * @code
- *	while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) {
- *		while ( SDL_LockSurface(image) < 0 )
- *			Sleep(10);
- *		-- Write image pixels to image->pixels --
- *		SDL_UnlockSurface(image);
- *	}
+ *  while ( SDL_BlitSurface(image, imgrect, screen, dstrect) == -2 ) {
+ *      while ( SDL_LockSurface(image) < 0 )
+ *          Sleep(10);
+ *      -- Write image pixels to image->pixels --
+ *      SDL_UnlockSurface(image);
+ *  }
  * @endcode
  *
  * This happens under DirectX 5.0 when the system switches away from your
@@ -746,26 +746,26 @@
  *  rectangle validation and clipping before passing it to SDL_LowerBlit()
  */
 extern DECLSPEC int SDLCALL SDL_UpperBlit
-			(SDL_Surface *src, SDL_Rect *srcrect,
-			 SDL_Surface *dst, SDL_Rect *dstrect);
+            (SDL_Surface *src, SDL_Rect *srcrect,
+             SDL_Surface *dst, SDL_Rect *dstrect);
 /** This is a semi-private blit function and it performs low-level surface
  *  blitting only.
  */
 extern DECLSPEC int SDLCALL SDL_LowerBlit
-			(SDL_Surface *src, SDL_Rect *srcrect,
-			 SDL_Surface *dst, SDL_Rect *dstrect);
+            (SDL_Surface *src, SDL_Rect *srcrect,
+             SDL_Surface *dst, SDL_Rect *dstrect);
 
 /**
  * This function performs a fast fill of the given rectangle with 'color'
  * The given rectangle is clipped to the destination surface clip area
  * and the final fill rectangle is saved in the passed in pointer.
  * If 'dstrect' is NULL, the whole surface will be filled with 'color'
- * The color should be a pixel of the format used by the surface, and 
+ * The color should be a pixel of the format used by the surface, and
  * can be generated by the SDL_MapRGB() function.
  * This function returns 0 on success, or -1 on error.
  */
 extern DECLSPEC int SDLCALL SDL_FillRect
-		(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
+        (SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
 
 /**
  * This function takes a surface and copies it to a new surface of the
@@ -805,7 +805,7 @@
  *  is shown is undefined - it may be overwritten with the converted YUV data.
  */
 extern DECLSPEC SDL_Overlay * SDLCALL SDL_CreateYUVOverlay(int width, int height,
-				Uint32 format, SDL_Surface *display);
+                Uint32 format, SDL_Surface *display);
 
 /** Lock an overlay for direct access, and unlock it when you are done */
 extern DECLSPEC int SDLCALL SDL_LockYUVOverlay(SDL_Overlay *overlay);
@@ -813,7 +813,7 @@
 
 /** Blit a video overlay to the display surface.
  *  The contents of the video surface underneath the blit destination are
- *  not defined.  
+ *  not defined.
  *  The width and height of the destination rectangle may be different from
  *  that of the overlay, but currently only 2x scaling is supported.
  */
@@ -908,7 +908,7 @@
  * If the display surface does not require locking before accessing
  * the pixel information, then the memory pointers will not change.
  *
- * If this function was able to toggle fullscreen mode (change from 
+ * If this function was able to toggle fullscreen mode (change from
  * running in a window to fullscreen, or vice-versa), it will return 1.
  * If it is not implemented, or fails, it returns 0.
  *
@@ -921,10 +921,10 @@
 extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface *surface);
 
 typedef enum {
-	SDL_GRAB_QUERY = -1,
-	SDL_GRAB_OFF = 0,
-	SDL_GRAB_ON = 1,
-	SDL_GRAB_FULLSCREEN	/**< Used internally */
+    SDL_GRAB_QUERY = -1,
+    SDL_GRAB_OFF = 0,
+    SDL_GRAB_ON = 1,
+    SDL_GRAB_FULLSCREEN /**< Used internally */
 } SDL_GrabMode;
 /**
  * This function allows you to set and query the input grab state of
@@ -941,7 +941,7 @@
 /** @internal Not in public API at the moment - do not use! */
 extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
                                     SDL_Surface *dst, SDL_Rect *dstrect);
-                    
+
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
 }
--- a/misc/winutils/include/begin_code.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/misc/winutils/include/begin_code.h	Tue Jan 21 22:53:15 2014 +0100
@@ -20,14 +20,14 @@
     slouken@libsdl.org
 */
 
-/** 
+/**
  *  @file begin_code.h
  *  This file sets things up for C dynamic library function definitions,
  *  static inlined functions, and structures aligned at 4-byte alignment.
  *  If you don't like ugly C preprocessor code, don't look at this file. :)
  */
 
-/** 
+/**
  *  @file begin_code.h
  *  This shouldn't be nested -- included it around code only.
  */
@@ -36,7 +36,7 @@
 #endif
 #define _begin_code_h
 
-/** 
+/**
  *  @def DECLSPEC
  *  Some compilers use a special export keyword
  */
@@ -45,22 +45,22 @@
 #  if defined(__GNUC__)
 #   define DECLSPEC
 #  else
-#   define DECLSPEC	__declspec(export)
+#   define DECLSPEC __declspec(export)
 #  endif
 # elif defined(__WIN32__)
 #  ifdef __BORLANDC__
 #   ifdef BUILD_SDL
-#    define DECLSPEC 
+#    define DECLSPEC
 #   else
-#    define DECLSPEC	__declspec(dllimport)
+#    define DECLSPEC    __declspec(dllimport)
 #   endif
 #  else
-#   define DECLSPEC	__declspec(dllexport)
+#   define DECLSPEC __declspec(dllexport)
 #  endif
 # elif defined(__OS2__)
 #  ifdef __WATCOMC__
 #   ifdef BUILD_SDL
-#    define DECLSPEC	__declspec(dllexport)
+#    define DECLSPEC    __declspec(dllexport)
 #   else
 #    define DECLSPEC
 #   endif
@@ -78,14 +78,14 @@
 #  endif
 # else
 #  if defined(__GNUC__) && __GNUC__ >= 4
-#   define DECLSPEC	__attribute__ ((visibility("default")))
+#   define DECLSPEC __attribute__ ((visibility("default")))
 #  else
 #   define DECLSPEC
 #  endif
 # endif
 #endif
 
-/** 
+/**
  *  @def SDLCALL
  *  By default SDL uses the C calling convention
  */
@@ -108,8 +108,8 @@
 # endif
 #endif /* SDLCALL */
 
-#ifdef __SYMBIAN32__ 
-#ifndef EKA2 
+#ifdef __SYMBIAN32__
+#ifndef EKA2
 #undef DECLSPEC
 #define DECLSPEC
 #elif !defined(__WINS__)
@@ -123,7 +123,7 @@
  *  Force structure packing at 4 byte alignment.
  *  This is necessary if the header is included in code which has structure
  *  packing set to an alternate value, say for loading structures from disk.
- *  The packing is reset to the previous value in close_code.h 
+ *  The packing is reset to the previous value in close_code.h
  */
 #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
 #ifdef _MSC_VER
@@ -157,7 +157,7 @@
     defined(__WATCOMC__) || defined(__LCC__) || \
     defined(__DECC) || defined(__EABI__)
 #ifndef __inline__
-#define __inline__	__inline
+#define __inline__  __inline
 #endif
 #define SDL_INLINE_OKAY
 #else
--- a/project_files/Android-build/SDL-android-project/AndroidManifest.xml	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/AndroidManifest.xml	Tue Jan 21 22:53:15 2014 +0100
@@ -46,7 +46,7 @@
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
 
         <service android:name=".Downloader.DownloadService" />
-		
+
         <activity
             android:name=".LocalRoomActivity"
             android:label="@string/app_name"
--- a/project_files/Android-build/SDL-android-project/assets/Data/Locale/en.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/assets/Data/Locale/en.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -507,7 +507,7 @@
 04:51=Get in a free shot by hurling a ball of mud.|Stings a bit, and knocks hogs back.
 04:52=UNUSED
 04:53=Take a trip through time and space,|while leaving your comrades to fight on alone.|Be prepared to return at any time,|or for Sudden Death or if they are all defeated.|Disclaimer. Does not function in Sudden Death,|if you are alone, or if you are a King.
-04:54=INCOMPLETE                                                                                                                                     
+04:54=INCOMPLETE
 04:55=Spray a stream of sticky flakes.|Build bridges, bury enemies, seal off tunnels.|Be careful you don't get any on you!
 
 ; Game goal strings
--- a/project_files/Android-build/SDL-android-project/jni/SDL/src/core/android/SDL_android.cpp	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/jni/SDL/src/core/android/SDL_android.cpp	Tue Jan 21 22:53:15 2014 +0100
@@ -102,7 +102,7 @@
                                 "createGLContext","(II)Z");
     midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass,
                                 "flipBuffers","()V");
-    midAudioInit = mEnv->GetStaticMethodID(mActivityClass, 
+    midAudioInit = mEnv->GetStaticMethodID(mActivityClass,
                                 "audioInit", "(IZZI)Ljava/lang/Object;");
     midAudioWriteShortBuffer = mEnv->GetStaticMethodID(mActivityClass,
                                 "audioWriteShortBuffer", "([S)V");
@@ -165,7 +165,7 @@
 // Quit
 extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeQuit(
                                     JNIEnv* env, jclass cls)
-{    
+{
     // Inject a SDL_QUIT event
     SDL_SendQuit();
 }
@@ -214,7 +214,7 @@
 
 extern "C" void Android_JNI_SwapWindow()
 {
-    mEnv->CallStaticVoidMethod(mActivityClass, midFlipBuffers); 
+    mEnv->CallStaticVoidMethod(mActivityClass, midFlipBuffers);
 }
 
 extern "C" void Android_JNI_SetActivityTitle(const char *title)
@@ -257,7 +257,7 @@
 
     int status;
     JNIEnv *env;
-    static bool isAttached = false;    
+    static bool isAttached = false;
     status = mJavaVM->GetEnv((void **) &env, JNI_VERSION_1_4);
     if(status < 0) {
         LOGE("callback_handler: failed to get JNI environment, assuming native thread");
@@ -269,7 +269,7 @@
         isAttached = true;
     }
 
-    
+
     __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device");
     audioBuffer16Bit = is16Bit;
     audioBufferStereo = channelCount > 1;
@@ -293,7 +293,7 @@
     if (audioBufferStereo) {
         audioBufferFrames /= 2;
     }
- 
+
     if (isAttached) {
         mJavaVM->DetachCurrentThread();
     }
@@ -323,7 +323,7 @@
 {
     int status;
     JNIEnv *env;
-    static bool isAttached = false;    
+    static bool isAttached = false;
     status = mJavaVM->GetEnv((void **) &env, JNI_VERSION_1_4);
     if(status < 0) {
         LOGE("callback_handler: failed to get JNI environment, assuming native thread");
@@ -335,7 +335,7 @@
         isAttached = true;
     }
 
-    env->CallStaticVoidMethod(mActivityClass, midAudioQuit); 
+    env->CallStaticVoidMethod(mActivityClass, midAudioQuit);
 
     if (audioBuffer) {
         env->DeleteGlobalRef(audioBuffer);
--- a/project_files/Android-build/SDL-android-project/jni/SDL/src/file/SDL_rwops.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/jni/SDL/src/file/SDL_rwops.c	Tue Jan 21 22:53:15 2014 +0100
@@ -45,7 +45,7 @@
 
 /* Functions to read/write Win32 API file pointers */
 /* Will not use it on WinCE because stdio is buffered, it means
-   faster, and all stdio functions anyway are embedded in coredll.dll - 
+   faster, and all stdio functions anyway are embedded in coredll.dll -
    the main wince dll*/
 
 #include "../core/windows/SDL_windows.h"
@@ -54,7 +54,7 @@
 #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
 #endif
 
-#define READAHEAD_BUFFER_SIZE	1024
+#define READAHEAD_BUFFER_SIZE   1024
 
 static int SDLCALL
 windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
@@ -473,12 +473,12 @@
     rwops->close = windows_file_close;
 
 #elif HAVE_STDIO_H
-	#ifdef __APPLE__
-	fp = SDL_OpenFPFromBundleOrFallback(file, mode);
+    #ifdef __APPLE__
+    fp = SDL_OpenFPFromBundleOrFallback(file, mode);
     #else
-	fp = fopen(file, mode);
-	#endif
-	if (fp == NULL) {
+    fp = fopen(file, mode);
+    #endif
+    if (fp == NULL) {
         SDL_SetError("Couldn't open %s", file);
     } else {
         rwops = SDL_RWFromFP(fp, 1);
--- a/project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp	Tue Jan 21 22:53:15 2014 +0100
@@ -27,19 +27,19 @@
     char *argv[argc];
     jstring jstringArgv[argc];
     for(int i = 0; i < argc; i++){
-		jstringArgv[i] = (jstring)env->GetObjectArrayElement(strArray, i);  //get the element
-		argv[i] = (char*)malloc(env->GetStringUTFLength(jstringArgv[i]) + 1);
-		const char *str = env->GetStringUTFChars(jstringArgv[i], NULL);
-		strcpy(argv[i], str); //copy it to a mutable location
-        env->ReleaseStringUTFChars(jstringArgv[i], str);           
+        jstringArgv[i] = (jstring)env->GetObjectArrayElement(strArray, i);  //get the element
+        argv[i] = (char*)malloc(env->GetStringUTFLength(jstringArgv[i]) + 1);
+        const char *str = env->GetStringUTFChars(jstringArgv[i], NULL);
+        strcpy(argv[i], str); //copy it to a mutable location
+        env->ReleaseStringUTFChars(jstringArgv[i], str);
     }
-    
+
     /* Run the application code! */
     int status = SDL_main(argc, argv);
 
     //Clean up argv
     for(int i = 0; i < argc; i++){
-		free(argv[i]);
+        free(argv[i]);
     }
 }
 
--- a/project_files/Android-build/SDL-android-project/jni/SDL_mixer/Android.mk	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/jni/SDL_mixer/Android.mk	Tue Jan 21 22:53:15 2014 +0100
@@ -5,9 +5,9 @@
 LOCAL_MODULE := SDL_mixer
 
 LOCAL_C_INCLUDES := \
-	$(LOCAL_PATH)/.. \
-	$(LOCAL_PATH)/../SDL/include \
-	$(LOCAL_PATH)/../mikmod/include \
+    $(LOCAL_PATH)/.. \
+    $(LOCAL_PATH)/../SDL/include \
+    $(LOCAL_PATH)/../mikmod/include \
 
 LOCAL_CFLAGS := -DWAV_MUSIC -DOGG_MUSIC -DOGG_USE_TREMOR -DMOD_MUSIC
 
--- a/project_files/Android-build/SDL-android-project/jni/jnidispatch/Android.mk	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/jni/jnidispatch/Android.mk	Tue Jan 21 22:53:15 2014 +0100
@@ -1,6 +1,6 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libjnidispatch
-LOCAL_SRC_FILES := libjnidispatch.so
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libjnidispatch
+LOCAL_SRC_FILES := libjnidispatch.so
 include $(PREBUILT_SHARED_LIBRARY)
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/jni/src/Android.mk	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/jni/src/Android.mk	Tue Jan 21 22:53:15 2014 +0100
@@ -7,7 +7,7 @@
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/../SDL/include
 
 # Add your application source files here...
-LOCAL_SRC_FILES := ../SDL/src/main/android/SDL_android_main.cpp hedgewars_main.c 
+LOCAL_SRC_FILES := ../SDL/src/main/android/SDL_android_main.cpp hedgewars_main.c
 
 LOCAL_SHARED_LIBRARIES := SDL
 
--- a/project_files/Android-build/SDL-android-project/jni/src/hedgewars_main.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/jni/src/hedgewars_main.c	Tue Jan 21 22:53:15 2014 +0100
@@ -10,32 +10,32 @@
 typedef  (*HWEngine_Game)(int32_t argc, char** argv);
 
 main(int argc, char *argv[]){
-	void *handle;
-	char *error;
-	HWEngine_Game Game;
-	
+    void *handle;
+    char *error;
+    HWEngine_Game Game;
+
 
         __android_log_print(ANDROID_LOG_INFO, TAG, "HWEngine being loaded");
-	handle = dlopen("libhwengine.so", RTLD_NOW|RTLD_GLOBAL);
-	if(!handle){
-		__android_log_print(ANDROID_LOG_INFO, TAG, dlerror());
-		__android_log_print(ANDROID_LOG_INFO, TAG, "error dlopen");
-		exit(EXIT_FAILURE);
-	}
-	dlerror();
+    handle = dlopen("libhwengine.so", RTLD_NOW|RTLD_GLOBAL);
+    if(!handle){
+        __android_log_print(ANDROID_LOG_INFO, TAG, dlerror());
+        __android_log_print(ANDROID_LOG_INFO, TAG, "error dlopen");
+        exit(EXIT_FAILURE);
+    }
+    dlerror();
 
         __android_log_print(ANDROID_LOG_INFO, TAG, "HWEngine successfully loaded..");
 
 
-	Game = (HWEngine_Game) dlsym(handle,"Game");
-	if((error = dlerror()) != NULL){
-		__android_log_print(ANDROID_LOG_INFO, TAG, error);
-		__android_log_print(ANDROID_LOG_INFO, TAG, "error dlsym");
-		exit(EXIT_FAILURE);
-	}
-	__android_log_print(ANDROID_LOG_INFO, TAG, "dlsym succeeded");
-	Game(argc, argv);
-	__android_log_print(ANDROID_LOG_INFO, TAG, "Game() ended");
+    Game = (HWEngine_Game) dlsym(handle,"Game");
+    if((error = dlerror()) != NULL){
+        __android_log_print(ANDROID_LOG_INFO, TAG, error);
+        __android_log_print(ANDROID_LOG_INFO, TAG, "error dlsym");
+        exit(EXIT_FAILURE);
+    }
+    __android_log_print(ANDROID_LOG_INFO, TAG, "dlsym succeeded");
+    Game(argc, argv);
+    __android_log_print(ANDROID_LOG_INFO, TAG, "Game() ended");
 
-	dlclose(handle);
+    dlclose(handle);
 }
--- a/project_files/Android-build/SDL-android-project/res/raw/team_one.hwt	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/res/raw/team_one.hwt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,74 +1,74 @@
-[Team]
-Name=Team 1
-Grave=Bone
-Fort=Lego
-Voicepack=Classic
-Flag=hedgewars
-Difficulty=0
-Rounds=0
-Wins=0
-CampaignProgress=0
-
-[Hedgehog0]
-Name=Leonidas
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog1]
-Name=Pipo
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog2]
-Name=Sonic
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog3]
-Name=Xin
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog4]
-Name=Arnold
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog5]
-Name=Jack
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog6]
-Name=Tom
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog7]
-Name=Goldie
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
+[Team]
+Name=Team 1
+Grave=Bone
+Fort=Lego
+Voicepack=Classic
+Flag=hedgewars
+Difficulty=0
+Rounds=0
+Wins=0
+CampaignProgress=0
+
+[Hedgehog0]
+Name=Leonidas
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog1]
+Name=Pipo
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog2]
+Name=Sonic
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog3]
+Name=Xin
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog4]
+Name=Arnold
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog5]
+Name=Jack
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog6]
+Name=Tom
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog7]
+Name=Goldie
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
--- a/project_files/Android-build/SDL-android-project/res/raw/team_two.hwt	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/res/raw/team_two.hwt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,74 +1,74 @@
-[Team]
-Name=Team 2
-Grave=Bone
-Fort=Lego
-Voicepack=Classic
-Flag=cm_binary
-Difficulty=2
-Rounds=0
-Wins=0
-CampaignProgress=0
-
-[Hedgehog0]
-Name=Paris
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog1]
-Name=Knut
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog2]
-Name=Ash
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog3]
-Name=Woad
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog4]
-Name=Bob
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog5]
-Name=Corky
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog6]
-Name=Bea
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
-
-[Hedgehog7]
-Name=Silvia
-Hat=NoHat
-Rounds=0
-Kills=0
-Deaths=0
-Suicides=0
+[Team]
+Name=Team 2
+Grave=Bone
+Fort=Lego
+Voicepack=Classic
+Flag=cm_binary
+Difficulty=2
+Rounds=0
+Wins=0
+CampaignProgress=0
+
+[Hedgehog0]
+Name=Paris
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog1]
+Name=Knut
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog2]
+Name=Ash
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog3]
+Name=Woad
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog4]
+Name=Bob
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog5]
+Name=Corky
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog6]
+Name=Bea
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
+
+[Hedgehog7]
+Name=Silvia
+Hat=NoHat
+Rounds=0
+Kills=0
+Deaths=0
+Suicides=0
--- a/project_files/Android-build/SDL-android-project/res/raw/weapons_builtin.ini	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/res/raw/weapons_builtin.ini	Tue Jan 21 22:53:15 2014 +0100
@@ -1,8 +1,8 @@
-[General]
-%44efault=9391929422199121032235111001201000000211110101011111011040504054160065554655446477657666666615551010111541101100000000000002055000000400070040000000002200000006000001311110312111111123114111111111111111211111101111111010
-%43razy=9999999999999999992999999999999999299999999909999992099111111011111111111111111111111111111111111110111111101100000000000000000000000000000000000000000000000000000001311110312111111123114111111111111111211110101111111011
-%50ro%20%4dode=9090009000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002055000000400070040000000002000000000000001111111111111111111111111111111111111111100101111111011
-%53hoppa=0000009900000000000000000000000000000000000000000000000444441004424440221011212122242200000000200040001001100000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111101101111111001
-%43lean%20%53late=1010009000010000011000000000000000000000000000001000000040504054160065554655446477657666666615551010111541101100000000000000000000000000000000000000000000000000000001311110312111111123114111111111111111211111101111111011
-%4dinefield=0000009900090000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002055000000400070040000000002000000006000001111111111111111111111111111111111111111111101111111011
-%54hinking%20with%20%50ortals=9000009002000000002100000000000000110000090000000000000040504054160065554655446477657666666615551010111541101100000000000002055000000400070040000000002000000006000001311110312111111123114111111111111111211111101111111011
+[General]
+%44efault=9391929422199121032235111001201000000211110101011111011040504054160065554655446477657666666615551010111541101100000000000002055000000400070040000000002200000006000001311110312111111123114111111111111111211111101111111010
+%43razy=9999999999999999992999999999999999299999999909999992099111111011111111111111111111111111111111111110111111101100000000000000000000000000000000000000000000000000000001311110312111111123114111111111111111211110101111111011
+%50ro%20%4dode=9090009000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002055000000400070040000000002000000000000001111111111111111111111111111111111111111100101111111011
+%53hoppa=0000009900000000000000000000000000000000000000000000000444441004424440221011212122242200000000200040001001100000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111101101111111001
+%43lean%20%53late=1010009000010000011000000000000000000000000000001000000040504054160065554655446477657666666615551010111541101100000000000000000000000000000000000000000000000000000001311110312111111123114111111111111111211111101111111011
+%4dinefield=0000009900090000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002055000000400070040000000002000000006000001111111111111111111111111111111111111111111101111111011
+%54hinking%20with%20%50ortals=9000009002000000002100000000000000110000090000000000000040504054160065554655446477657666666615551010111541101100000000000002055000000400070040000000002000000006000001311110312111111123114111111111111111211111101111111011
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/BasicRoomState.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/BasicRoomState.java	Tue Jan 21 22:53:15 2014 +0100
@@ -37,125 +37,125 @@
  * Common base implementation for a roomstate that will call listeners on every
  * change. The derived classes have to coordinate how state is changed to
  * complete the implementation of the RoomStateManager interface.
- * 
+ *
  * See {@link RoomStateManager} for a description of what this is for.
  */
 public abstract class BasicRoomState implements RoomStateManager {
-	private final List<RoomStateManager.Listener> observers = new LinkedList<RoomStateManager.Listener>();
-	
-	private boolean chief;
-	private String gameStyle;
-	private Scheme scheme;
-	private MapRecipe map;
-	private Weaponset weaponset;
-	private Map<String, TeamInGame> teams = Collections.emptyMap();
-	
-	public final MapRecipe getMapRecipe() {
-		return map;
-	}
+    private final List<RoomStateManager.Listener> observers = new LinkedList<RoomStateManager.Listener>();
+
+    private boolean chief;
+    private String gameStyle;
+    private Scheme scheme;
+    private MapRecipe map;
+    private Weaponset weaponset;
+    private Map<String, TeamInGame> teams = Collections.emptyMap();
+
+    public final MapRecipe getMapRecipe() {
+        return map;
+    }
+
+    public final boolean getChiefStatus() {
+        return chief;
+    }
+
+    public final Scheme getScheme() {
+        return scheme;
+    }
+
+    public final String getGameStyle() {
+        return gameStyle;
+    }
 
-	public final boolean getChiefStatus() {
-		return chief;
-	}
+    public final Weaponset getWeaponset() {
+        return weaponset;
+    }
+
+    public final Map<String, TeamInGame> getTeams() {
+        return teams;
+    }
 
-	public final Scheme getScheme() {
-		return scheme;
-	}
+    public final void setWeaponset(Weaponset weaponset) {
+        if(!equal(weaponset, this.weaponset)) {
+            this.weaponset = weaponset;
+            for(RoomStateManager.Listener observer : observers) {
+                observer.onWeaponsetChanged(weaponset);
+            }
+        }
+    }
 
-	public final String getGameStyle() {
-		return gameStyle;
-	}
+    public final void setMapRecipe(MapRecipe map) {
+        if(!equal(map, this.map)) {
+            this.map = map;
+            for(RoomStateManager.Listener observer : observers) {
+                observer.onMapChanged(map);
+            }
+        }
+    }
 
-	public final Weaponset getWeaponset() {
-		return weaponset;
-	}
-	
-	public final Map<String, TeamInGame> getTeams() {
-		return teams;
-	}
-	
-	public final void setWeaponset(Weaponset weaponset) {
-		if(!equal(weaponset, this.weaponset)) {
-			this.weaponset = weaponset;
-			for(RoomStateManager.Listener observer : observers) {
-				observer.onWeaponsetChanged(weaponset);
-			}
-		}
-	}
-	
-	public final void setMapRecipe(MapRecipe map) {
-		if(!equal(map, this.map)) { 
-			this.map = map;
-			for(RoomStateManager.Listener observer : observers) {
-				observer.onMapChanged(map);
-			}
-		}
-	}
-	
-	public final void setGameStyle(String gameStyle) {
-		if(!equal(gameStyle, this.gameStyle)) {
-			this.gameStyle = gameStyle;
-			for(RoomStateManager.Listener observer : observers) {
-				observer.onGameStyleChanged(gameStyle);
-			}
-		}
-	}
-	
-	public final void setScheme(Scheme scheme) {
-		if(!equal(scheme, this.scheme)) {
-			this.scheme = scheme;
-			for(RoomStateManager.Listener observer : observers) {
-				observer.onSchemeChanged(scheme);
-			}
-		}
-	}
-	
-	public final void setChief(boolean chief) {
-		if(chief != this.chief) {
-			this.chief = chief;
-			for(RoomStateManager.Listener observer : observers) {
-				observer.onChiefStatusChanged(chief);
-			}
-		}
-	}
-	
-	public final void putTeam(TeamInGame team) {
-		TeamInGame oldEntry = teams.get(team.team.name);
-		if(!equal(team, oldEntry)) {
-			Map<String, TeamInGame> changedMap = new TreeMap<String, TeamInGame>(teams);
-			changedMap.put(team.team.name, team);
-			teams = Collections.unmodifiableMap(changedMap);
-			for(RoomStateManager.Listener observer : observers) {
-				observer.onTeamsChanged(teams);
-			}
-		}
-	}
-	
-	public final void removeTeam(String teamname) {
-		if(teams.containsKey(teamname)) {
-			Map<String, TeamInGame> changedMap = new TreeMap<String, TeamInGame>(teams);
-			changedMap.remove(teamname);
-			teams = Collections.unmodifiableMap(changedMap);
-			for(RoomStateManager.Listener observer : observers) {
-				observer.onTeamsChanged(teams);
-			}
-		}
-	}
-	
-	public final void setTeams(Map<String, TeamInGame> newTeams) {
-		if(!newTeams.equals(teams)) {
-			teams = Collections.unmodifiableMap(new TreeMap<String, TeamInGame>(newTeams));
-			for(RoomStateManager.Listener observer : observers) {
-				observer.onTeamsChanged(teams);
-			}
-		}
-	}
-	
-	public final void addListener(Listener observer) {
-		observers.add(observer);
-	}
+    public final void setGameStyle(String gameStyle) {
+        if(!equal(gameStyle, this.gameStyle)) {
+            this.gameStyle = gameStyle;
+            for(RoomStateManager.Listener observer : observers) {
+                observer.onGameStyleChanged(gameStyle);
+            }
+        }
+    }
+
+    public final void setScheme(Scheme scheme) {
+        if(!equal(scheme, this.scheme)) {
+            this.scheme = scheme;
+            for(RoomStateManager.Listener observer : observers) {
+                observer.onSchemeChanged(scheme);
+            }
+        }
+    }
+
+    public final void setChief(boolean chief) {
+        if(chief != this.chief) {
+            this.chief = chief;
+            for(RoomStateManager.Listener observer : observers) {
+                observer.onChiefStatusChanged(chief);
+            }
+        }
+    }
 
-	public final void removeListener(Listener observer) {
-		observers.remove(observer);
-	}
+    public final void putTeam(TeamInGame team) {
+        TeamInGame oldEntry = teams.get(team.team.name);
+        if(!equal(team, oldEntry)) {
+            Map<String, TeamInGame> changedMap = new TreeMap<String, TeamInGame>(teams);
+            changedMap.put(team.team.name, team);
+            teams = Collections.unmodifiableMap(changedMap);
+            for(RoomStateManager.Listener observer : observers) {
+                observer.onTeamsChanged(teams);
+            }
+        }
+    }
+
+    public final void removeTeam(String teamname) {
+        if(teams.containsKey(teamname)) {
+            Map<String, TeamInGame> changedMap = new TreeMap<String, TeamInGame>(teams);
+            changedMap.remove(teamname);
+            teams = Collections.unmodifiableMap(changedMap);
+            for(RoomStateManager.Listener observer : observers) {
+                observer.onTeamsChanged(teams);
+            }
+        }
+    }
+
+    public final void setTeams(Map<String, TeamInGame> newTeams) {
+        if(!newTeams.equals(teams)) {
+            teams = Collections.unmodifiableMap(new TreeMap<String, TeamInGame>(newTeams));
+            for(RoomStateManager.Listener observer : observers) {
+                observer.onTeamsChanged(teams);
+            }
+        }
+    }
+
+    public final void addListener(Listener observer) {
+        observers.add(observer);
+    }
+
+    public final void removeListener(Listener observer) {
+        observers.remove(observer);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ChatFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ChatFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -39,61 +39,61 @@
  * the lobby or a room.
  */
 public class ChatFragment extends Fragment {
-	private ChatlogAdapter adapter;
-	private Netplay netplay;
-	private MessageLog messageLog;
-	private boolean inRoom;
-	
-	public void setInRoom(boolean inRoom) {
-		this.inRoom = inRoom;
-	}
-	
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
-		adapter = new ChatlogAdapter(getActivity());
-	}
-	
-	@Override
-	public void onStart() {
-		super.onStart();
-		messageLog = inRoom ? netplay.roomChatlog : netplay.lobbyChatlog;
-    	adapter.setLog(messageLog.getLog());
-    	messageLog.addListener(adapter);
-	}
-	
-	@Override
-	public void onStop() {
-		super.onStop();
-		messageLog.removeListener(adapter);
-	}
-	
-	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container,
-			Bundle savedInstanceState) {
-		View view = inflater.inflate(R.layout.fragment_chat, container, false);
-		
-		ListView listView = (ListView) view.findViewById(R.id.chatConsole);
-		listView.setAdapter(adapter);
-		listView.setDivider(null);
-		listView.setDividerHeight(0);
-		listView.setVerticalFadingEdgeEnabled(true);
-		
-		EditText editText = (EditText) view.findViewById(R.id.chatInput);
+    private ChatlogAdapter adapter;
+    private Netplay netplay;
+    private MessageLog messageLog;
+    private boolean inRoom;
+
+    public void setInRoom(boolean inRoom) {
+        this.inRoom = inRoom;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
+        adapter = new ChatlogAdapter(getActivity());
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        messageLog = inRoom ? netplay.roomChatlog : netplay.lobbyChatlog;
+        adapter.setLog(messageLog.getLog());
+        messageLog.addListener(adapter);
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+        messageLog.removeListener(adapter);
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        View view = inflater.inflate(R.layout.fragment_chat, container, false);
+
+        ListView listView = (ListView) view.findViewById(R.id.chatConsole);
+        listView.setAdapter(adapter);
+        listView.setDivider(null);
+        listView.setDividerHeight(0);
+        listView.setVerticalFadingEdgeEnabled(true);
+
+        EditText editText = (EditText) view.findViewById(R.id.chatInput);
         editText.setOnEditorActionListener(new ChatSendListener());
-        
-		return view;
-	}
-	
-	private final class ChatSendListener implements OnEditorActionListener {
-		public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
-			String text = v.getText().toString();
-			if(text.length()>0) {
-				v.setText("");
-				netplay.sendChat(text);
-			}
-			return true;
-		}
-	}
+
+        return view;
+    }
+
+    private final class ChatSendListener implements OnEditorActionListener {
+        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+            String text = v.getText().toString();
+            if(text.length()>0) {
+                v.setText("");
+                netplay.sendChat(text);
+            }
+            return true;
+        }
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ChatlogAdapter.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ChatlogAdapter.java	Tue Jan 21 22:53:15 2014 +0100
@@ -39,14 +39,14 @@
  * Since lines with a given ID never change in our chatlog, we can avoid the effort
  * of TextView.setText in many cases by checking if the view is already set up for the
  * line with the right ID - but to do that, the view needs to remember the ID it's
- * holding the text for. That's what the LoglineView does. 
+ * holding the text for. That's what the LoglineView does.
  */
 class LoglineView extends TextView {
-	long chatlogId = -1;
-	
-	public LoglineView(Context context) {
-		super(context);
-	}
+    long chatlogId = -1;
+
+    public LoglineView(Context context) {
+        super(context);
+    }
 }
 
 /**
@@ -57,65 +57,65 @@
  * the textviews from a messagelog in an efficient way.
  */
 public class ChatlogAdapter extends BaseAdapter implements MessageLog.Listener {
-	long idOffset = 0;
-	private List<CharSequence> log = new ArrayList<CharSequence>();
-	private Context context;
-	
-	public ChatlogAdapter(Context context) {
-		this.context = context;
-	}
-	
-	public int getCount() {
-		return log.size();
-	}
+    long idOffset = 0;
+    private List<CharSequence> log = new ArrayList<CharSequence>();
+    private Context context;
+
+    public ChatlogAdapter(Context context) {
+        this.context = context;
+    }
+
+    public int getCount() {
+        return log.size();
+    }
 
-	public Object getItem(int position) {
-		return log.get(position);
-	}
+    public Object getItem(int position) {
+        return log.get(position);
+    }
+
+    public long getItemId(int position) {
+        return position+idOffset;
+    }
 
-	public long getItemId(int position) {
-		return position+idOffset;
-	}
+    public boolean hasStableIds() {
+        return true;
+    }
 
-	public boolean hasStableIds() {
-		return true;
-	}
+    public void clear() {
+        idOffset += log.size();
+        log.clear();
+        notifyDataSetChanged();
+    }
 
-	public void clear() {
-		idOffset += log.size();
-		log.clear();
-		notifyDataSetChanged();
-	}
-	
-	public void lineAdded(CharSequence text) {
-		log.add(text);
-		notifyDataSetChanged();
-	}
-	
-	public void lineRemoved() {
-		log.remove(0);
-		idOffset += 1;
-		notifyDataSetChanged();
-	}
-	
-	public void setLog(Collection<CharSequence> log) {
-		idOffset += log.size();
-		this.log = new ArrayList<CharSequence>(log);
-		notifyDataSetChanged();
-	}
-	
-	public View getView(int position, View convertView, ViewGroup parent) {
-		LoglineView v = (LoglineView)convertView;
-		if (v == null) {
-			v = new LoglineView(context);
-			v.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
-			v.setMovementMethod(LinkMovementMethod.getInstance());
-		}
-		long id = getItemId(position);
-		if(id != v.chatlogId) {
-			v.setText(log.get(position));
-			v.chatlogId = id;
-		}
-		return v;
-	}
+    public void lineAdded(CharSequence text) {
+        log.add(text);
+        notifyDataSetChanged();
+    }
+
+    public void lineRemoved() {
+        log.remove(0);
+        idOffset += 1;
+        notifyDataSetChanged();
+    }
+
+    public void setLog(Collection<CharSequence> log) {
+        idOffset += log.size();
+        this.log = new ArrayList<CharSequence>(log);
+        notifyDataSetChanged();
+    }
+
+    public View getView(int position, View convertView, ViewGroup parent) {
+        LoglineView v = (LoglineView)convertView;
+        if (v == null) {
+            v = new LoglineView(context);
+            v.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
+            v.setMovementMethod(LinkMovementMethod.getInstance());
+        }
+        long id = getItemId(position);
+        if(id != v.chatlogId) {
+            v.setText(log.get(position));
+            v.chatlogId = id;
+        }
+        return v;
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ConnectingDialog.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ConnectingDialog.java	Tue Jan 21 22:53:15 2014 +0100
@@ -37,58 +37,58 @@
  * Indeterminate progress dialog that is shown in the MainActivity while trying
  * to connect to the server. If the connection fails (disconnect before we reach
  * lobby state), an error toast with the disconnect message is shown.
- * 
+ *
  */
 public class ConnectingDialog extends ConnectionDependendDialogFragment {
-	@Override
-	public void onStart() {
-		super.onStart();
-		LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
-		LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(disconnectedReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
-		
-		if(Netplay.getAppInstance(getActivity().getApplicationContext()).getState() != State.CONNECTING) {
-			dismiss();
-		}
-	}
-	
-	@Override
-	public void onStop() {
-		super.onStop();
-		LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(connectedReceiver);
-		LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(disconnectedReceiver);
-	}
-	
-	@Override
-	public Dialog onCreateDialog(Bundle savedInstanceState) {
-		ProgressDialog dialog = new ProgressDialog(getActivity());
-		dialog.setIndeterminate(true);
-		dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
-		dialog.setTitle(R.string.dialog_connecting_title);
-		dialog.setMessage(getString(R.string.dialog_connecting_message));
-		return dialog;
-	}
-	
-	private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			Dialog dialog = getDialog();
-			if(dialog != null) {
-				dialog.dismiss();
-			} else {
-				dismiss();
-			}
-		}
-	};
-	
-	private BroadcastReceiver disconnectedReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			Toast.makeText(getActivity(), intent.getExtras().getString(Netplay.EXTRA_MESSAGE), Toast.LENGTH_LONG).show();
-		}
-	};
-	
-	public void onCancel(DialogInterface dialog) {
-		super.onCancel(dialog);
-		Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
-	};
+    @Override
+    public void onStart() {
+        super.onStart();
+        LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
+        LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(disconnectedReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
+
+        if(Netplay.getAppInstance(getActivity().getApplicationContext()).getState() != State.CONNECTING) {
+            dismiss();
+        }
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+        LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(connectedReceiver);
+        LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(disconnectedReceiver);
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        ProgressDialog dialog = new ProgressDialog(getActivity());
+        dialog.setIndeterminate(true);
+        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+        dialog.setTitle(R.string.dialog_connecting_title);
+        dialog.setMessage(getString(R.string.dialog_connecting_message));
+        return dialog;
+    }
+
+    private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            Dialog dialog = getDialog();
+            if(dialog != null) {
+                dialog.dismiss();
+            } else {
+                dismiss();
+            }
+        }
+    };
+
+    private BroadcastReceiver disconnectedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            Toast.makeText(getActivity(), intent.getExtras().getString(Netplay.EXTRA_MESSAGE), Toast.LENGTH_LONG).show();
+        }
+    };
+
+    public void onCancel(DialogInterface dialog) {
+        super.onCancel(dialog);
+        Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ConnectionDependendDialogFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/ConnectionDependendDialogFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -36,30 +36,30 @@
  * appear during connecting (e.g. username input)
  */
 public class ConnectionDependendDialogFragment extends DialogFragment {
-	@Override
-	public void onStart() {
-		super.onStart();
-		LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(dismissReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
-		if(Netplay.getAppInstance(getActivity().getApplicationContext()).getState() == State.NOT_CONNECTED) {
-			dismiss();
-		}
-	}
-	
-	@Override
-	public void onStop() {
-		super.onStop();
-		LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(dismissReceiver);
-	}
-	
-	private BroadcastReceiver dismissReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			Dialog dialog = getDialog();
-			if(dialog != null) {
-				dialog.dismiss();
-			} else {
-				dismiss();
-			}
-		}
-	};
+    @Override
+    public void onStart() {
+        super.onStart();
+        LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(dismissReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
+        if(Netplay.getAppInstance(getActivity().getApplicationContext()).getState() == State.NOT_CONNECTED) {
+            dismiss();
+        }
+    }
+
+    @Override
+    public void onStop() {
+        super.onStop();
+        LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(dismissReceiver);
+    }
+
+    private BroadcastReceiver dismissReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            Dialog dialog = getDialog();
+            if(dialog != null) {
+                dialog.dismiss();
+            } else {
+                dismiss();
+            }
+        }
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAssets.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAssets.java	Tue Jan 21 22:53:15 2014 +0100
@@ -36,48 +36,48 @@
 import android.util.Log;
 
 public class DownloadAssets extends AsyncTask<Object, Long, Boolean> {
-	private static final String VERSION_FILENAME = "assetsversion.txt";
-	private final MainActivity act;
-	
-	public DownloadAssets(MainActivity act){
-		this.act = act;
-	}
-	
-	private void copyFileOrDir(AssetManager assetManager, File target, String assetPath) throws IOException {
-		try {
-			FileUtils.writeStreamToFile(assetManager.open(assetPath), target);
-		} catch(FileNotFoundException e) {
-			/*
-			 * I can't find a better way to figure out whether an asset entry is
-			 * a file or a directory. Checking if assetManager.list(assetPath)
-			 * is empty is a bit cleaner, but SLOW.
-			 */
-			if (!target.isDirectory() && !target.mkdir()) {
-				throw new IOException("Unable to create directory "+target);
-			}
-			for (String asset : assetManager.list(assetPath)) {
-				copyFileOrDir(assetManager, new File(target, asset), assetPath + "/" + asset);
-			}
-		}
-	}
-	
-	@Override
-	protected Boolean doInBackground(Object... params) {
-		try {
-			FileUtils.writeStreamToFile(act.getResources().openRawResource(R.raw.schemes_builtin), Schemes.getBuiltinSchemesFile(act));
-			FileUtils.writeStreamToFile(act.getResources().openRawResource(R.raw.weapons_builtin), Weaponsets.getBuiltinWeaponsetsFile(act));
-			FileUtils.resRawToFilesDir(act, R.array.teams, R.array.teamFilenames, Team.DIRECTORY_TEAMS);
-			copyFileOrDir(act.getAssets(), FileUtils.getDataPathFile(act), "Data");
-			copyFileOrDir(act.getAssets(), new File(FileUtils.getCachePath(act), VERSION_FILENAME), VERSION_FILENAME);
-			return Boolean.TRUE;
-		} catch(IOException e) {
-			Log.e("DownloadAssets", e.getMessage(), e);
-			return Boolean.FALSE;
-		}
-	}
-	
-	@Override
-	protected void onPostExecute(Boolean result){
-		act.onAssetsDownloaded(result);
-	}
+    private static final String VERSION_FILENAME = "assetsversion.txt";
+    private final MainActivity act;
+
+    public DownloadAssets(MainActivity act){
+        this.act = act;
+    }
+
+    private void copyFileOrDir(AssetManager assetManager, File target, String assetPath) throws IOException {
+        try {
+            FileUtils.writeStreamToFile(assetManager.open(assetPath), target);
+        } catch(FileNotFoundException e) {
+            /*
+             * I can't find a better way to figure out whether an asset entry is
+             * a file or a directory. Checking if assetManager.list(assetPath)
+             * is empty is a bit cleaner, but SLOW.
+             */
+            if (!target.isDirectory() && !target.mkdir()) {
+                throw new IOException("Unable to create directory "+target);
+            }
+            for (String asset : assetManager.list(assetPath)) {
+                copyFileOrDir(assetManager, new File(target, asset), assetPath + "/" + asset);
+            }
+        }
+    }
+
+    @Override
+    protected Boolean doInBackground(Object... params) {
+        try {
+            FileUtils.writeStreamToFile(act.getResources().openRawResource(R.raw.schemes_builtin), Schemes.getBuiltinSchemesFile(act));
+            FileUtils.writeStreamToFile(act.getResources().openRawResource(R.raw.weapons_builtin), Weaponsets.getBuiltinWeaponsetsFile(act));
+            FileUtils.resRawToFilesDir(act, R.array.teams, R.array.teamFilenames, Team.DIRECTORY_TEAMS);
+            copyFileOrDir(act.getAssets(), FileUtils.getDataPathFile(act), "Data");
+            copyFileOrDir(act.getAssets(), new File(FileUtils.getCachePath(act), VERSION_FILENAME), VERSION_FILENAME);
+            return Boolean.TRUE;
+        } catch(IOException e) {
+            Log.e("DownloadAssets", e.getMessage(), e);
+            return Boolean.FALSE;
+        }
+    }
+
+    @Override
+    protected void onPostExecute(Boolean result){
+        act.onAssetsDownloaded(result);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java	Tue Jan 21 22:53:15 2014 +0100
@@ -37,188 +37,188 @@
 import android.os.AsyncTask;
 /**
  * This is an AsyncTask which will download a zip from an URL and unzip it to a specified path
- * 
+ *
  *  a typical call to start the task would be new DownloadAsyncTask().execute(getExternalStorage(), "www.hedgewars.org/data.zip");
  * @author Xeli
  *
  */
 public class DownloadAsyncTask extends AsyncTask<DownloadPackage, Object, Integer> {
 
-	//private final static String URL_WITHOUT_SUFFIX = "http://www.xelification.com/tmp/firebutton.";
-	private final static String URL_ZIP_SUFFIX = ".zip";
-	private final static String URL_HASH_SUFFIX = ".hash";
+    //private final static String URL_WITHOUT_SUFFIX = "http://www.xelification.com/tmp/firebutton.";
+    private final static String URL_ZIP_SUFFIX = ".zip";
+    private final static String URL_HASH_SUFFIX = ".hash";
 
-	public static final int EXIT_SUCCESS = 0;
-	public static final int EXIT_URLFAIL = 1;
-	public static final int EXIT_CONNERROR = 2;
-	public static final int EXIT_FNF = 3;
-	public static final int EXIT_MD5 = 4;
-	public static final int EXIT_CANCELLED = 5;
+    public static final int EXIT_SUCCESS = 0;
+    public static final int EXIT_URLFAIL = 1;
+    public static final int EXIT_CONNERROR = 2;
+    public static final int EXIT_FNF = 3;
+    public static final int EXIT_MD5 = 4;
+    public static final int EXIT_CANCELLED = 5;
 
-	private DownloadTask task;
-	private long lastUpdateMillis = 0;
+    private DownloadTask task;
+    private long lastUpdateMillis = 0;
 
-	public DownloadAsyncTask(DownloadTask _task){
-		task = _task;
-	}
+    public DownloadAsyncTask(DownloadTask _task){
+        task = _task;
+    }
 
-	/**
-	 * 
-	 * @param params - A {@link}DownloadTask which gives information about where to download from and store the files to 
-	 */
-	protected Integer doInBackground(DownloadPackage...packages) {
-		DownloadPackage pack = packages[0];//just use one task per execute call for now
+    /**
+     *
+     * @param params - A {@link}DownloadTask which gives information about where to download from and store the files to
+     */
+    protected Integer doInBackground(DownloadPackage...packages) {
+        DownloadPackage pack = packages[0];//just use one task per execute call for now
 
-		HttpURLConnection conn = null;
-		MessageDigest digester = null;
-		String rootZipDest = pack.getPathToStore();
+        HttpURLConnection conn = null;
+        MessageDigest digester = null;
+        String rootZipDest = pack.getPathToStore();
 
-		File rootDest = new File(rootZipDest);//TODO check for nullpointer, it hints to the absence of an sdcard
-		rootDest.mkdirs();
+        File rootDest = new File(rootZipDest);//TODO check for nullpointer, it hints to the absence of an sdcard
+        rootDest.mkdirs();
 
-		try {
-			URL url = new URL(pack.getURL() + URL_ZIP_SUFFIX);
-			conn = (HttpURLConnection)url.openConnection();
-		} catch (IOException e) {
-			e.printStackTrace();
-			return EXIT_URLFAIL;
-		}
+        try {
+            URL url = new URL(pack.getURL() + URL_ZIP_SUFFIX);
+            conn = (HttpURLConnection)url.openConnection();
+        } catch (IOException e) {
+            e.printStackTrace();
+            return EXIT_URLFAIL;
+        }
 
-		String contentType = conn.getContentType();
+        String contentType = conn.getContentType();
 
-		if(contentType == null || contentType.contains("zip")){ //Seeing as we provide the url if the contentType is unknown lets assume zips
-			int bytesDecompressed = 0;
-			ZipEntry entry = null;
-			ZipInputStream input = null;
-			FileOutputStream output = null;
-			int kbytesToProcess = conn.getContentLength()/1024;
+        if(contentType == null || contentType.contains("zip")){ //Seeing as we provide the url if the contentType is unknown lets assume zips
+            int bytesDecompressed = 0;
+            ZipEntry entry = null;
+            ZipInputStream input = null;
+            FileOutputStream output = null;
+            int kbytesToProcess = conn.getContentLength()/1024;
 
-			byte[] buffer = new byte[1024];
-			task.start(kbytesToProcess);
+            byte[] buffer = new byte[1024];
+            task.start(kbytesToProcess);
 
-			try {
-				digester = MessageDigest.getInstance("MD5");
+            try {
+                digester = MessageDigest.getInstance("MD5");
 
-			} catch (NoSuchAlgorithmException e1) {
-				e1.printStackTrace();
-			}
+            } catch (NoSuchAlgorithmException e1) {
+                e1.printStackTrace();
+            }
 
-			try{
-				input = new ZipInputStream(conn.getInputStream());
-				entry = input.getNextEntry();	
-			}catch(IOException e){
-				e.printStackTrace();
-				conn.disconnect();
-				return EXIT_CONNERROR;
-			}
+            try{
+                input = new ZipInputStream(conn.getInputStream());
+                entry = input.getNextEntry();
+            }catch(IOException e){
+                e.printStackTrace();
+                conn.disconnect();
+                return EXIT_CONNERROR;
+            }
 
 
 
-			while(entry != null){
+            while(entry != null){
 
-				if(isCancelled()) break;
+                if(isCancelled()) break;
 
-				try {
-					String fileName = entry.getName();
-					File f = new File(rootZipDest + fileName);
-					bytesDecompressed += entry.getCompressedSize();
+                try {
+                    String fileName = entry.getName();
+                    File f = new File(rootZipDest + fileName);
+                    bytesDecompressed += entry.getCompressedSize();
 
-					if(entry.isDirectory()){
-						f.mkdir();
-					}else{
-						if(f.exists()){
-							f.delete();
-						}
-						f.createNewFile();
-						output = new FileOutputStream(f);
+                    if(entry.isDirectory()){
+                        f.mkdir();
+                    }else{
+                        if(f.exists()){
+                            f.delete();
+                        }
+                        f.createNewFile();
+                        output = new FileOutputStream(f);
 
-						int count = 0;
-						while((count = input.read(buffer)) != -1){
-							output.write(buffer, 0, count);
-							digester.update(buffer, 0, count);
-							if(System.currentTimeMillis() - lastUpdateMillis > 1000){
-								lastUpdateMillis = System.currentTimeMillis();
-								publishProgress(bytesDecompressed, kbytesToProcess, fileName);
-							}
-						}
-						output.flush();
-						input.closeEntry();
-					}//if isDir 
-					entry = input.getNextEntry();
-				} catch (FileNotFoundException e) {
-					e.printStackTrace();
-					if(conn != null) conn.disconnect();
-					return EXIT_FNF;
-				} catch (IOException e) {
-					e.printStackTrace();
-					if(conn != null) conn.disconnect();
-					return EXIT_CONNERROR;
-				}finally{
-					try {
-						if( output != null) output.close();
+                        int count = 0;
+                        while((count = input.read(buffer)) != -1){
+                            output.write(buffer, 0, count);
+                            digester.update(buffer, 0, count);
+                            if(System.currentTimeMillis() - lastUpdateMillis > 1000){
+                                lastUpdateMillis = System.currentTimeMillis();
+                                publishProgress(bytesDecompressed, kbytesToProcess, fileName);
+                            }
+                        }
+                        output.flush();
+                        input.closeEntry();
+                    }//if isDir
+                    entry = input.getNextEntry();
+                } catch (FileNotFoundException e) {
+                    e.printStackTrace();
+                    if(conn != null) conn.disconnect();
+                    return EXIT_FNF;
+                } catch (IOException e) {
+                    e.printStackTrace();
+                    if(conn != null) conn.disconnect();
+                    return EXIT_CONNERROR;
+                }finally{
+                    try {
+                        if( output != null) output.close();
 
-					} catch (IOException e) {}
-				}
-			}//end while(entry != null)
-			if( input != null)
-				try {
-					input.close();
-				} catch (IOException e) {}
-		}else{//end if contentType == "zip"
-			return EXIT_URLFAIL;
-		}
-		if(conn != null) conn.disconnect();
+                    } catch (IOException e) {}
+                }
+            }//end while(entry != null)
+            if( input != null)
+                try {
+                    input.close();
+                } catch (IOException e) {}
+        }else{//end if contentType == "zip"
+            return EXIT_URLFAIL;
+        }
+        if(conn != null) conn.disconnect();
 
-		if(checkMD5(digester, pack))return EXIT_SUCCESS;
-		else return EXIT_MD5;
-	}
+        if(checkMD5(digester, pack))return EXIT_SUCCESS;
+        else return EXIT_MD5;
+    }
 
-	//TODO proper result handling
-	protected void onPostExecute(Integer result){
-		task.done(result);
-	}
+    //TODO proper result handling
+    protected void onPostExecute(Integer result){
+        task.done(result);
+    }
 
-	protected void onProgressUpdate(Object...objects){
-		task.update((Integer)objects[0], (Integer)objects[1], (String)objects[2]);
-	}
+    protected void onProgressUpdate(Object...objects){
+        task.update((Integer)objects[0], (Integer)objects[1], (String)objects[2]);
+    }
 
-	protected void onCancelled(){
-		onPostExecute(EXIT_CANCELLED);
-	}
+    protected void onCancelled(){
+        onPostExecute(EXIT_CANCELLED);
+    }
 
-	private boolean checkMD5(MessageDigest digester, DownloadPackage task){
-		if(digester != null) {
-			byte[] messageDigest = digester.digest();
+    private boolean checkMD5(MessageDigest digester, DownloadPackage task){
+        if(digester != null) {
+            byte[] messageDigest = digester.digest();
 
-			try {
-				URL url = new URL(task.getURL() + URL_HASH_SUFFIX);
-				HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+            try {
+                URL url = new URL(task.getURL() + URL_HASH_SUFFIX);
+                HttpURLConnection conn = (HttpURLConnection)url.openConnection();
 
-				byte[] buffer = new byte[1024];//size is large enough to hold the entire hash
-				BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
-				int bytesRead = bis.read(buffer);
-				String hash = null;
-				if(bytesRead > -1){
-					hash = new String(buffer, 0, bytesRead);
-				}
-				StringBuffer sb = new StringBuffer();
-				Integer tmp = 0;
-				for(int i = 0; i < messageDigest.length; i++){
-					tmp = 0xFF & messageDigest[i];
-					if(tmp < 0xF) sb.append('0');
-					sb.append(Integer.toHexString(tmp));
-				}
-				sb.append('\n');//add newline to become identical with the hash file
+                byte[] buffer = new byte[1024];//size is large enough to hold the entire hash
+                BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
+                int bytesRead = bis.read(buffer);
+                String hash = null;
+                if(bytesRead > -1){
+                    hash = new String(buffer, 0, bytesRead);
+                }
+                StringBuffer sb = new StringBuffer();
+                Integer tmp = 0;
+                for(int i = 0; i < messageDigest.length; i++){
+                    tmp = 0xFF & messageDigest[i];
+                    if(tmp < 0xF) sb.append('0');
+                    sb.append(Integer.toHexString(tmp));
+                }
+                sb.append('\n');//add newline to become identical with the hash file
 
-				return hash.equals(sb.toString());
-			} catch (IOException e) {
-				e.printStackTrace();
-				return true;
-			}
-		}else{
-			return true;	
-		}
+                return hash.equals(sb.toString());
+            } catch (IOException e) {
+                e.printStackTrace();
+                return true;
+            }
+        }else{
+            return true;
+        }
 
-	}
+    }
 
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadDialogFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadDialogFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -32,57 +32,57 @@
 
 public class DownloadDialogFragment extends DialogFragment {
 
-	public static final int NUM_ALREADYDOWNLOADED = 0;
-	public static final int NUM_AREYOUSURE = 1;
+    public static final int NUM_ALREADYDOWNLOADED = 0;
+    public static final int NUM_AREYOUSURE = 1;
 
-	private final static String BUNDLE_TASK = "task";
+    private final static String BUNDLE_TASK = "task";
 
-	static DownloadDialogFragment newInstance(DownloadPackage task){
-		DownloadDialogFragment dialog = new DownloadDialogFragment();
+    static DownloadDialogFragment newInstance(DownloadPackage task){
+        DownloadDialogFragment dialog = new DownloadDialogFragment();
 
-		Bundle args = new Bundle();
-		args.putParcelable(DownloadDialogFragment.BUNDLE_TASK, task);
-		dialog.setArguments(args);
+        Bundle args = new Bundle();
+        args.putParcelable(DownloadDialogFragment.BUNDLE_TASK, task);
+        dialog.setArguments(args);
 
-		return dialog;
-	}
+        return dialog;
+    }
 
-	public Dialog onCreateDialog(Bundle savedInstanceState){
-		DownloadPackage task = (DownloadPackage)getArguments().getParcelable(DownloadDialogFragment.BUNDLE_TASK);
+    public Dialog onCreateDialog(Bundle savedInstanceState){
+        DownloadPackage task = (DownloadPackage)getArguments().getParcelable(DownloadDialogFragment.BUNDLE_TASK);
 
-		Builder builder = new AlertDialog.Builder(getActivity());
+        Builder builder = new AlertDialog.Builder(getActivity());
 
-		switch(task.getStatus()){
-		case CURRENTVERSION:
-		case NEWERVERSION:
-			builder.setMessage(R.string.download_areyousure);
-			break;
-		case OLDERVERSION:
-			builder.setMessage(R.string.download_alreadydownloaded);
-			break;
-		}
+        switch(task.getStatus()){
+        case CURRENTVERSION:
+        case NEWERVERSION:
+            builder.setMessage(R.string.download_areyousure);
+            break;
+        case OLDERVERSION:
+            builder.setMessage(R.string.download_alreadydownloaded);
+            break;
+        }
 
-		DownloadClicker clicker = new DownloadClicker(task);
-		builder.setPositiveButton(android.R.string.yes, clicker);
-		builder.setNegativeButton(android.R.string.no, clicker);
+        DownloadClicker clicker = new DownloadClicker(task);
+        builder.setPositiveButton(android.R.string.yes, clicker);
+        builder.setNegativeButton(android.R.string.no, clicker);
 
-		return builder.create();
-	}
+        return builder.create();
+    }
 
-	class DownloadClicker implements OnClickListener{
+    class DownloadClicker implements OnClickListener{
 
-		DownloadPackage task = null;
+        DownloadPackage task = null;
 
-		public DownloadClicker(DownloadPackage _task){
-			task = _task;
-		}
+        public DownloadClicker(DownloadPackage _task){
+            task = _task;
+        }
 
-		public void onClick(DialogInterface dialog, int which) {
-			if(which == Dialog.BUTTON_POSITIVE){
-				Intent i = new Intent(getActivity(), DownloadListActivity.class);
-				i.putExtra(DownloadFragment.EXTRA_TASK, task);
-				getActivity().startActivity(i);
-			}
-		}
-	}
+        public void onClick(DialogInterface dialog, int which) {
+            if(which == Dialog.BUTTON_POSITIVE){
+                Intent i = new Intent(getActivity(), DownloadListActivity.class);
+                i.putExtra(DownloadFragment.EXTRA_TASK, task);
+                getActivity().startActivity(i);
+            }
+        }
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -41,177 +41,177 @@
 import android.widget.TextView;
 
 public class DownloadFragment extends Fragment{
-	public static final String EXTRA_TASK = "task";
+    public static final String EXTRA_TASK = "task";
 
-	public static final int MSG_START = 0;
-	public static final int MSG_UPDATE = 1;
-	public static final int MSG_DONE = 2;
-	public static final int MSG_FAILED = 3;
+    public static final int MSG_START = 0;
+    public static final int MSG_UPDATE = 1;
+    public static final int MSG_DONE = 2;
+    public static final int MSG_FAILED = 3;
 
-	private boolean boundToService = false;
+    private boolean boundToService = false;
 
-	private TextView progress_sub;
-	private ProgressBar progress;
-	private Button /*positive,*/ negative;
+    private TextView progress_sub;
+    private ProgressBar progress;
+    private Button /*positive,*/ negative;
 
-	private DownloadPackage pack;
+    private DownloadPackage pack;
 
-	private Handler messageHandler;
-	private Messenger messenger, messengerService;
+    private Handler messageHandler;
+    private Messenger messenger, messengerService;
 
-	public static DownloadFragment getInstance(DownloadPackage task){
-		DownloadFragment df = new DownloadFragment();
-		Bundle args = new Bundle();
-		args.putParcelable(DownloadFragment.EXTRA_TASK, task);
+    public static DownloadFragment getInstance(DownloadPackage task){
+        DownloadFragment df = new DownloadFragment();
+        Bundle args = new Bundle();
+        args.putParcelable(DownloadFragment.EXTRA_TASK, task);
 
-		df.setArguments(args);
+        df.setArguments(args);
 
-		return df;
-	}
+        return df;
+    }
 
-	public void onActivityCreated(Bundle savedInstanceState){
-		super.onActivityCreated(savedInstanceState);
+    public void onActivityCreated(Bundle savedInstanceState){
+        super.onActivityCreated(savedInstanceState);
 
-		messageHandler = new Handler(messageCallback);
-		messenger = new Messenger(messageHandler);
-		Intent i = new Intent(getActivity().getApplicationContext(), DownloadService.class);
-		getActivity().startService(i);
-		getActivity().bindService(new Intent(getActivity().getApplicationContext(), DownloadService.class), connection, Context.BIND_AUTO_CREATE);
-	}
+        messageHandler = new Handler(messageCallback);
+        messenger = new Messenger(messageHandler);
+        Intent i = new Intent(getActivity().getApplicationContext(), DownloadService.class);
+        getActivity().startService(i);
+        getActivity().bindService(new Intent(getActivity().getApplicationContext(), DownloadService.class), connection, Context.BIND_AUTO_CREATE);
+    }
 
-	public View onCreateView(LayoutInflater inflater, ViewGroup viewgroup, Bundle savedInstanceState){
-		View v = inflater.inflate(R.layout.download_progress, viewgroup, false);
-		progress_sub = (TextView)v.findViewById(R.id.progressbar_sub);
-		progress = (ProgressBar)v.findViewById(R.id.progressbar);
+    public View onCreateView(LayoutInflater inflater, ViewGroup viewgroup, Bundle savedInstanceState){
+        View v = inflater.inflate(R.layout.download_progress, viewgroup, false);
+        progress_sub = (TextView)v.findViewById(R.id.progressbar_sub);
+        progress = (ProgressBar)v.findViewById(R.id.progressbar);
 
-		//positive = (Button) v.findViewById(R.id.background);
-		negative = (Button) v.findViewById(R.id.cancelDownload);
-		//positive.setOnClickListener(backgroundClicker);
-		negative.setOnClickListener(cancelClicker);
+        //positive = (Button) v.findViewById(R.id.background);
+        negative = (Button) v.findViewById(R.id.cancelDownload);
+        //positive.setOnClickListener(backgroundClicker);
+        negative.setOnClickListener(cancelClicker);
 
-		pack = getArguments().getParcelable(DownloadFragment.EXTRA_TASK);
+        pack = getArguments().getParcelable(DownloadFragment.EXTRA_TASK);
 
-		return v;
-	}
+        return v;
+    }
 
-	private OnClickListener backgroundClicker = new OnClickListener(){
-		public void onClick(View v){
-			getActivity().finish();
-		}
-	};
-	private OnClickListener cancelClicker = new OnClickListener(){
-		public void onClick(View v){
-			if(messengerService != null){
-				Message message = Message.obtain(messageHandler, DownloadService.MSG_CANCEL, pack);
-				try {
-					messengerService.send(message);
-				} catch (RemoteException e) {}
-			}
-			//getActivity().finish();
-		}
-	};
-	private OnClickListener doneClicker = new OnClickListener(){
-		public void onClick(View v){
-			getActivity().finish();
-		}
-	};
+    private OnClickListener backgroundClicker = new OnClickListener(){
+        public void onClick(View v){
+            getActivity().finish();
+        }
+    };
+    private OnClickListener cancelClicker = new OnClickListener(){
+        public void onClick(View v){
+            if(messengerService != null){
+                Message message = Message.obtain(messageHandler, DownloadService.MSG_CANCEL, pack);
+                try {
+                    messengerService.send(message);
+                } catch (RemoteException e) {}
+            }
+            //getActivity().finish();
+        }
+    };
+    private OnClickListener doneClicker = new OnClickListener(){
+        public void onClick(View v){
+            getActivity().finish();
+        }
+    };
 
-	private OnClickListener tryAgainClicker = new OnClickListener(){
-		public void onClick(View v){
-			if(messengerService != null){
-				Message message = Message.obtain(messageHandler, DownloadService.MSG_ADDTASK, pack);
-				message.replyTo = messenger;
-				try {
-					messengerService.send(message);
-				} catch (RemoteException e) {
-					e.printStackTrace();
-				}
-			}
-		}
-	};
+    private OnClickListener tryAgainClicker = new OnClickListener(){
+        public void onClick(View v){
+            if(messengerService != null){
+                Message message = Message.obtain(messageHandler, DownloadService.MSG_ADDTASK, pack);
+                message.replyTo = messenger;
+                try {
+                    messengerService.send(message);
+                } catch (RemoteException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    };
 
-	public void onDestroy(){
-		unBindFromService();
-		super.onDestroy();
-	}
+    public void onDestroy(){
+        unBindFromService();
+        super.onDestroy();
+    }
 
-	private ServiceConnection connection = new ServiceConnection(){
+    private ServiceConnection connection = new ServiceConnection(){
 
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			messengerService = new Messenger(service);
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            messengerService = new Messenger(service);
 
-			try{
-				//give the service a task
-				if(messengerService != null){
-					Message message = Message.obtain(messageHandler, DownloadService.MSG_ADDTASK, pack);
-					message.replyTo = messenger;
-					messengerService.send(message);
-				}
+            try{
+                //give the service a task
+                if(messengerService != null){
+                    Message message = Message.obtain(messageHandler, DownloadService.MSG_ADDTASK, pack);
+                    message.replyTo = messenger;
+                    messengerService.send(message);
+                }
 
-			}catch (RemoteException e){}
-		}
+            }catch (RemoteException e){}
+        }
 
-		public void onServiceDisconnected(ComponentName name) {
-			messengerService = null;
-		}
+        public void onServiceDisconnected(ComponentName name) {
+            messengerService = null;
+        }
 
-	};
+    };
 
-	public void unBindFromService(){
-		if(messengerService != null){
-			try {
-				Message message = Message.obtain(messageHandler, DownloadService.MSG_UNREGISTER_CLIENT, pack);
-				message.replyTo = messenger;
-				messengerService.send(message);
-			} catch (RemoteException e) {
-				e.printStackTrace();
-			}
-		}
+    public void unBindFromService(){
+        if(messengerService != null){
+            try {
+                Message message = Message.obtain(messageHandler, DownloadService.MSG_UNREGISTER_CLIENT, pack);
+                message.replyTo = messenger;
+                messengerService.send(message);
+            } catch (RemoteException e) {
+                e.printStackTrace();
+            }
+        }
 
-		getActivity().unbindService(connection);
-	}
+        getActivity().unbindService(connection);
+    }
 
-	private Handler.Callback messageCallback = new Handler.Callback() {
+    private Handler.Callback messageCallback = new Handler.Callback() {
 
-		public boolean handleMessage(Message msg) {
-			switch(msg.what){
-			case MSG_START:
-				progress.setMax(msg.arg1);
-				progress_sub.setText(String.format("%dkb/%dkb\n%s", 0, msg.arg1, ""));
-				//positive.setText(R.string.download_background);
-				//positive.setOnClickListener(backgroundClicker);
-				negative.setText(R.string.download_cancel);
-				negative.setOnClickListener(cancelClicker);
-				break;
-			case MSG_UPDATE:
-				progress_sub.setText(String.format("%d%% - %dkb/%dkb\n%s",(msg.arg1*100)/msg.arg2, msg.arg1, msg.arg2, msg.obj));
-				progress.setProgress(msg.arg1);
-				break;
-			case MSG_DONE:
-				progress.setProgress(progress.getMax());
-				progress_sub.setText(R.string.download_done);
+        public boolean handleMessage(Message msg) {
+            switch(msg.what){
+            case MSG_START:
+                progress.setMax(msg.arg1);
+                progress_sub.setText(String.format("%dkb/%dkb\n%s", 0, msg.arg1, ""));
+                //positive.setText(R.string.download_background);
+                //positive.setOnClickListener(backgroundClicker);
+                negative.setText(R.string.download_cancel);
+                negative.setOnClickListener(cancelClicker);
+                break;
+            case MSG_UPDATE:
+                progress_sub.setText(String.format("%d%% - %dkb/%dkb\n%s",(msg.arg1*100)/msg.arg2, msg.arg1, msg.arg2, msg.obj));
+                progress.setProgress(msg.arg1);
+                break;
+            case MSG_DONE:
+                progress.setProgress(progress.getMax());
+                progress_sub.setText(R.string.download_done);
 
-				//	positive.setText(R.string.download_back);
-				//	positive.setOnClickListener(doneClicker);
+                //  positive.setText(R.string.download_back);
+                //  positive.setOnClickListener(doneClicker);
+
+                negative.setVisibility(View.INVISIBLE);
+                break;
+            case MSG_FAILED:
+                progress.setProgress(progress.getMax());
 
-				negative.setVisibility(View.INVISIBLE);
-				break;
-			case MSG_FAILED:
-				progress.setProgress(progress.getMax());
-				
-				String errorMsg = getString(R.string.download_failed);
-				switch(msg.arg1){
-				case DownloadAsyncTask.EXIT_CONNERROR: progress_sub.setText(errorMsg + " " + "Connection error"); break;
-				case DownloadAsyncTask.EXIT_FNF: progress_sub.setText(errorMsg + " " + "File not found"); break;
-				case DownloadAsyncTask.EXIT_MD5: progress_sub.setText(errorMsg + " " + "MD5 check failed"); break;
-				case DownloadAsyncTask.EXIT_URLFAIL: progress_sub.setText(errorMsg + " " + "Invalid url"); break;
-				}
-				negative.setText(R.string.download_tryagain);
-				negative.setOnClickListener(tryAgainClicker);
-				break;
-			}
-			return false;
-		}
-	};
+                String errorMsg = getString(R.string.download_failed);
+                switch(msg.arg1){
+                case DownloadAsyncTask.EXIT_CONNERROR: progress_sub.setText(errorMsg + " " + "Connection error"); break;
+                case DownloadAsyncTask.EXIT_FNF: progress_sub.setText(errorMsg + " " + "File not found"); break;
+                case DownloadAsyncTask.EXIT_MD5: progress_sub.setText(errorMsg + " " + "MD5 check failed"); break;
+                case DownloadAsyncTask.EXIT_URLFAIL: progress_sub.setText(errorMsg + " " + "Invalid url"); break;
+                }
+                negative.setText(R.string.download_tryagain);
+                negative.setOnClickListener(tryAgainClicker);
+                break;
+            }
+            return false;
+        }
+    };
 
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -35,99 +35,99 @@
 
 public class DownloadListActivity extends FragmentActivity implements OnItemMovementListener{
 
-	private FrameLayout layout = null;
-	private LinearLayout downloadQueueContainer = null;
-	private View infoView = null;
-	private ImageView arrow = null;
-	private int halfSize = 0;
-	private DownloadPackage task = null;
+    private FrameLayout layout = null;
+    private LinearLayout downloadQueueContainer = null;
+    private View infoView = null;
+    private ImageView arrow = null;
+    private int halfSize = 0;
+    private DownloadPackage task = null;
+
+    public void onCreate(Bundle savedInstanceState){
+        super.onCreate(savedInstanceState);
 
-	public void onCreate(Bundle savedInstanceState){
-		super.onCreate(savedInstanceState);
+        setContentView(R.layout.download_listactivity);
+        //FragmentManager fm = this.getSupportFragmentManager();
+        //if(fm.findFragmentById(android.R.id.content) == null){
+        //  DownloadListFragment listfrag = new DownloadListFragment();
+        //  fm.beginTransaction().add(android.R.id.content, listfrag).commit();
+        //}
 
-		setContentView(R.layout.download_listactivity);
-		//FragmentManager fm = this.getSupportFragmentManager();
-		//if(fm.findFragmentById(android.R.id.content) == null){
-		//	DownloadListFragment listfrag = new DownloadListFragment();
-		//	fm.beginTransaction().add(android.R.id.content, listfrag).commit();
-		//}
+        layout = (FrameLayout)findViewById(R.id.downloadFrameLayout);
+        downloadQueueContainer = (LinearLayout) findViewById(R.id.downloadQueueContainer);
+    }
 
-		layout = (FrameLayout)findViewById(R.id.downloadFrameLayout);
-		downloadQueueContainer = (LinearLayout) findViewById(R.id.downloadQueueContainer);
-	}
-	
-	public void onNewItemSelected(DownloadPackage _task, int x, int minX, int maxX, int size) {
-		if(layout != null){
-			if(!_task.equals(task)){//if it's a new task refresh the whole thing
-				task = _task;
-				layout.removeView(infoView);
-				infoView = null;
-			}
-			
-			if(infoView == null){//build iv if it hasn't been created yet
-				infoView = this.getLayoutInflater().inflate(R.layout.download_info, layout, false);
-				FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) infoView.getLayoutParams();
-				params.gravity = Gravity.NO_GRAVITY;
-				params.height = size;
-				arrow = (ImageView)infoView.findViewById(R.id.arrow);
-				arrow.setVisibility(View.INVISIBLE);
-				halfSize = size/2;
-				
-				Button yes = (Button)infoView.findViewById(R.id.download);
-				Button no = (Button)infoView.findViewById(R.id.cancel);
-				yes.setOnClickListener(yesClicker);
-				no.setOnClickListener(noClicker);
-				
-				layout.addView(infoView, params);
-			}
-		}
-	}
+    public void onNewItemSelected(DownloadPackage _task, int x, int minX, int maxX, int size) {
+        if(layout != null){
+            if(!_task.equals(task)){//if it's a new task refresh the whole thing
+                task = _task;
+                layout.removeView(infoView);
+                infoView = null;
+            }
+
+            if(infoView == null){//build iv if it hasn't been created yet
+                infoView = this.getLayoutInflater().inflate(R.layout.download_info, layout, false);
+                FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) infoView.getLayoutParams();
+                params.gravity = Gravity.NO_GRAVITY;
+                params.height = size;
+                arrow = (ImageView)infoView.findViewById(R.id.arrow);
+                arrow.setVisibility(View.INVISIBLE);
+                halfSize = size/2;
+
+                Button yes = (Button)infoView.findViewById(R.id.download);
+                Button no = (Button)infoView.findViewById(R.id.cancel);
+                yes.setOnClickListener(yesClicker);
+                no.setOnClickListener(noClicker);
+
+                layout.addView(infoView, params);
+            }
+        }
+    }
 
-	public void onViewMoved(int x, int minX, int maxX) {
-		if(halfSize == -1){
-			if(infoView.getHeight() != 0){
-				halfSize = infoView.getHeight()/2;
-			}
-		}
-		if(layout != null && infoView != null){
-			FrameLayout.LayoutParams params = ((FrameLayout.LayoutParams)infoView.getLayoutParams());
-			if(x - halfSize < minX){
-				params.topMargin = 0;
-				arrow.setVisibility(View.INVISIBLE);
-				params.gravity = Gravity.TOP;
-			}else if (x + halfSize >= maxX){
-				params.topMargin = 0;
-				arrow.setVisibility(View.INVISIBLE);
-				params.gravity = Gravity.BOTTOM;
-			}else{
-				params.topMargin = x - halfSize;
-				params.gravity = Gravity.NO_GRAVITY;
-				arrow.setVisibility(View.VISIBLE);
-			}
-			
-			infoView.requestLayout();
-			
-		}
-	}
-	
-	private OnClickListener yesClicker = new OnClickListener(){
-		public void onClick(View v){
-			FragmentManager fm = getSupportFragmentManager();
-			FragmentTransaction ft= fm.beginTransaction();
-			DownloadFragment df = DownloadFragment.getInstance(task);
-			
-			ft.add(R.id.downloadQueueContainer, df).commit();
-			//ft.show(new DownloadFragment());
-			
-			task = null;
-			layout.removeView(infoView);
-		}
-	};
-	
-	private OnClickListener noClicker = new OnClickListener(){
-		public void onClick(View v){
-			task = null;
-			layout.removeView(infoView);
-		}
-	};
+    public void onViewMoved(int x, int minX, int maxX) {
+        if(halfSize == -1){
+            if(infoView.getHeight() != 0){
+                halfSize = infoView.getHeight()/2;
+            }
+        }
+        if(layout != null && infoView != null){
+            FrameLayout.LayoutParams params = ((FrameLayout.LayoutParams)infoView.getLayoutParams());
+            if(x - halfSize < minX){
+                params.topMargin = 0;
+                arrow.setVisibility(View.INVISIBLE);
+                params.gravity = Gravity.TOP;
+            }else if (x + halfSize >= maxX){
+                params.topMargin = 0;
+                arrow.setVisibility(View.INVISIBLE);
+                params.gravity = Gravity.BOTTOM;
+            }else{
+                params.topMargin = x - halfSize;
+                params.gravity = Gravity.NO_GRAVITY;
+                arrow.setVisibility(View.VISIBLE);
+            }
+
+            infoView.requestLayout();
+
+        }
+    }
+
+    private OnClickListener yesClicker = new OnClickListener(){
+        public void onClick(View v){
+            FragmentManager fm = getSupportFragmentManager();
+            FragmentTransaction ft= fm.beginTransaction();
+            DownloadFragment df = DownloadFragment.getInstance(task);
+
+            ft.add(R.id.downloadQueueContainer, df).commit();
+            //ft.show(new DownloadFragment());
+
+            task = null;
+            layout.removeView(infoView);
+        }
+    };
+
+    private OnClickListener noClicker = new OnClickListener(){
+        public void onClick(View v){
+            task = null;
+            layout.removeView(infoView);
+        }
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -43,172 +43,172 @@
 
 public class DownloadListFragment extends ListFragment implements OnItemClickListener, OnScrollListener, Runnable{
 
-	private View targetView = null;
-	private ArrayList<OnItemMovementListener> listeners = new ArrayList<OnItemMovementListener>(); 
+    private View targetView = null;
+    private ArrayList<OnItemMovementListener> listeners = new ArrayList<OnItemMovementListener>();
 
-	public void onActivityCreated(Bundle savedInstanceState){
-		super.onActivityCreated(savedInstanceState);
+    public void onActivityCreated(Bundle savedInstanceState){
+        super.onActivityCreated(savedInstanceState);
 
-		ArrayList<DownloadPackage> tasks = new ArrayList<DownloadPackage>();
+        ArrayList<DownloadPackage> tasks = new ArrayList<DownloadPackage>();
 
-		ArrayAdapter<DownloadPackage> adapter = new ArrayAdapter<DownloadPackage>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, tasks);
-		setListAdapter(adapter);
-		getListView().setOnItemClickListener(this);
-		getListView().setOnScrollListener(this);
+        ArrayAdapter<DownloadPackage> adapter = new ArrayAdapter<DownloadPackage>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, tasks);
+        setListAdapter(adapter);
+        getListView().setOnItemClickListener(this);
+        getListView().setOnScrollListener(this);
 
-		if(getActivity() instanceof OnItemMovementListener){
-			listeners.add((OnItemMovementListener)getActivity());
-		}
+        if(getActivity() instanceof OnItemMovementListener){
+            listeners.add((OnItemMovementListener)getActivity());
+        }
+
+        getListView().setCacheColorHint(Color.TRANSPARENT);//To prevent a blackish background while scrolling
+
 
-		getListView().setCacheColorHint(Color.TRANSPARENT);//To prevent a blackish background while scrolling
-		
-		
-		Thread t = new Thread(this, "DownloadListParser");
-		t.start();
-	}
+        Thread t = new Thread(this, "DownloadListParser");
+        t.start();
+    }
 
-	public void run(){
-		XmlPullParserFactory xmlPullFactory;
-		try {
-			xmlPullFactory = XmlPullParserFactory.newInstance();
-			XmlPullParser xmlPuller = xmlPullFactory.newPullParser();
+    public void run(){
+        XmlPullParserFactory xmlPullFactory;
+        try {
+            xmlPullFactory = XmlPullParserFactory.newInstance();
+            XmlPullParser xmlPuller = xmlPullFactory.newPullParser();
 
-			URL url = new URL("http://www.xelification.com/tmp/downloads.xml");
-			HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+            URL url = new URL("http://www.xelification.com/tmp/downloads.xml");
+            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+
+            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()), 1024);
+            xmlPuller.setInput(br);
 
-			BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()), 1024);
-			xmlPuller.setInput(br);
+            final ArrayAdapter<DownloadPackage> adapter = (ArrayAdapter<DownloadPackage>) getListAdapter();
+
+            int eventType = xmlPuller.getEventType();
+            while(eventType != XmlPullParser.END_DOCUMENT){
+
+                if(eventType == XmlPullParser.START_TAG){
+                    if(xmlPuller.getName().toLowerCase().equals("task")){
+                        final DownloadPackage task = DownloadPackage.getTaskFromXML(getActivity(), xmlPuller);
 
-			final ArrayAdapter<DownloadPackage> adapter = (ArrayAdapter<DownloadPackage>) getListAdapter();
-			
-			int eventType = xmlPuller.getEventType();
-			while(eventType != XmlPullParser.END_DOCUMENT){
-			
-				if(eventType == XmlPullParser.START_TAG){
-					if(xmlPuller.getName().toLowerCase().equals("task")){
-						final DownloadPackage task = DownloadPackage.getTaskFromXML(getActivity(), xmlPuller);
-						
-						getActivity().runOnUiThread(new Runnable(){
-							public void run() {
-								adapter.add(task);								
-							}
-						});
-					}
-				}
-				eventType = getEventType(xmlPuller);
-			}
-			
-			
-		} catch (XmlPullParserException e) {
-			e.printStackTrace();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-	
+                        getActivity().runOnUiThread(new Runnable(){
+                            public void run() {
+                                adapter.add(task);
+                            }
+                        });
+                    }
+                }
+                eventType = getEventType(xmlPuller);
+            }
+
+
+        } catch (XmlPullParserException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
 
-	/**
-	 * Skips whitespaces..
-	 */
-	private static int getEventType(XmlPullParser xmlPuller)throws XmlPullParserException, IOException{
-		int eventType = xmlPuller.next();
-		while(eventType == XmlPullParser.TEXT && xmlPuller.isWhitespace()){
-			eventType = xmlPuller.next();
-		}
-		return eventType;
-	}
+    /**
+     * Skips whitespaces..
+     */
+    private static int getEventType(XmlPullParser xmlPuller)throws XmlPullParserException, IOException{
+        int eventType = xmlPuller.next();
+        while(eventType == XmlPullParser.TEXT && xmlPuller.isWhitespace()){
+            eventType = xmlPuller.next();
+        }
+        return eventType;
+    }
 
-	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
-		DownloadPackage task = (DownloadPackage)arg0.getAdapter().getItem(position);
-		/*
-		FragmentTransaction ft = getFragmentManager().beginTransaction();
-		Fragment prev = getFragmentManager().findFragmentByTag("dialog");
+    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
+        DownloadPackage task = (DownloadPackage)arg0.getAdapter().getItem(position);
+        /*
+        FragmentTransaction ft = getFragmentManager().beginTransaction();
+        Fragment prev = getFragmentManager().findFragmentByTag("dialog");
 
-		//remove any old dialogs
-		if(prev != null) ft.remove(prev);
-		ft.addToBackStack(null);
+        //remove any old dialogs
+        if(prev != null) ft.remove(prev);
+        ft.addToBackStack(null);
 
-		//create a new dialog based on this task
-		
-		DialogFragment newFragment = DownloadDialogFragment.newInstance(task);
+        //create a new dialog based on this task
+
+        DialogFragment newFragment = DownloadDialogFragment.newInstance(task);
 
-		//show it
-		newFragment.show(ft, "dialog");
-		 */
-		targetView = arg1;
+        //show it
+        newFragment.show(ft, "dialog");
+         */
+        targetView = arg1;
 
-		//determine state
-		int min = arg0.getTop();
-		int max = arg0.getBottom();
-		int top = targetView.getTop();
+        //determine state
+        int min = arg0.getTop();
+        int max = arg0.getBottom();
+        int top = targetView.getTop();
 
-		previousXCoord = top;
-		for(OnItemMovementListener listener : listeners){
-			listener.onNewItemSelected(task, top, min, max, targetView.getHeight()*2);
-		}
-	}
+        previousXCoord = top;
+        for(OnItemMovementListener listener : listeners){
+            listener.onNewItemSelected(task, top, min, max, targetView.getHeight()*2);
+        }
+    }
 
-	private int previousXCoord = 0;
+    private int previousXCoord = 0;
 
-	/*
-	 * (non-Javadoc)
-	 * @see android.widget.AbsListView.OnScrollListener#onScroll(android.widget.AbsListView, int, int, int)
-	 * 
-	 * Android renews the Items used in the view, so when a user scroll down the list, 
-	 * as soon as the item has dissapeard from the list it gets reused at the bottom.
-	 * 
-	 * For this reason we cannot just keep sending the targetView.getTop() but we must
-	 *  remember if the view is supposed to be at the top or bottom of the list. We 
-	 *  remember this with int state, 
-	 *     - 0 means we've got accurate reading from getTop()
-	 *     - -1 means it's somewhere at the top of the list
-	 *     - 1 means it's at the bottom somewhere
-	 */
-	public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
-		if(targetView != null){
-			int top = targetView.getTop() + (targetView.getHeight()/2);
-			int min = view.getTop();
-			int max = view.getBottom();
+    /*
+     * (non-Javadoc)
+     * @see android.widget.AbsListView.OnScrollListener#onScroll(android.widget.AbsListView, int, int, int)
+     *
+     * Android renews the Items used in the view, so when a user scroll down the list,
+     * as soon as the item has dissapeard from the list it gets reused at the bottom.
+     *
+     * For this reason we cannot just keep sending the targetView.getTop() but we must
+     *  remember if the view is supposed to be at the top or bottom of the list. We
+     *  remember this with int state,
+     *     - 0 means we've got accurate reading from getTop()
+     *     - -1 means it's somewhere at the top of the list
+     *     - 1 means it's at the bottom somewhere
+     */
+    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
+        if(targetView != null){
+            int top = targetView.getTop() + (targetView.getHeight()/2);
+            int min = view.getTop();
+            int max = view.getBottom();
 
-			if(Math.abs(previousXCoord - top) > targetView.getHeight()*2 ){
-				top = previousXCoord;
-			}
+            if(Math.abs(previousXCoord - top) > targetView.getHeight()*2 ){
+                top = previousXCoord;
+            }
 
-			for(OnItemMovementListener listener : listeners){
-				listener.onViewMoved(top, min, max);
-			}
+            for(OnItemMovementListener listener : listeners){
+                listener.onViewMoved(top, min, max);
+            }
 
-			previousXCoord = top;
-		}
-	}
+            previousXCoord = top;
+        }
+    }
 
-	public void onScrollStateChanged(AbsListView view, int scrollState) {
-		switch(scrollState){
-		case OnScrollListener.SCROLL_STATE_FLING: Log.d("tag", "fling"); break;
-		case OnScrollListener.SCROLL_STATE_IDLE:Log.d("tag", "idle"); break;
-		case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:Log.d("tag", "scroll"); break;
+    public void onScrollStateChanged(AbsListView view, int scrollState) {
+        switch(scrollState){
+        case OnScrollListener.SCROLL_STATE_FLING: Log.d("tag", "fling"); break;
+        case OnScrollListener.SCROLL_STATE_IDLE:Log.d("tag", "idle"); break;
+        case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:Log.d("tag", "scroll"); break;
 
-		}
+        }
 
-	}
+    }
 }
 
 interface OnItemMovementListener{
-	/**
-	 * When I new item has been selected this method will be called
-	 * @param task The task which goes with this item
-	 * @param x The middle of this item
-	 * @param minX The top of the parent of this item
-	 * @param maxX The bottom of the parent of this item
-	 */
-	void onNewItemSelected(DownloadPackage task, int x, int minX, int maxX, int size);
+    /**
+     * When I new item has been selected this method will be called
+     * @param task The task which goes with this item
+     * @param x The middle of this item
+     * @param minX The top of the parent of this item
+     * @param maxX The bottom of the parent of this item
+     */
+    void onNewItemSelected(DownloadPackage task, int x, int minX, int maxX, int size);
 
-	/**
-	 * When the item has been moved this method is called
-	 * @param x The middle of this item
-	 * @param minX The top of the parent of this item
-	 * @param maxX The bottom of the parent of this item
-	 */
-	void onViewMoved(int x, int minX, int maxX);
+    /**
+     * When the item has been moved this method is called
+     * @param x The middle of this item
+     * @param minX The top of the parent of this item
+     * @param maxX The bottom of the parent of this item
+     */
+    void onViewMoved(int x, int minX, int maxX);
 }
 
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadPackage.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadPackage.java	Tue Jan 21 22:53:15 2014 +0100
@@ -32,155 +32,155 @@
 import android.preference.PreferenceManager;
 
 public class DownloadPackage implements Parcelable{
-	private String url_without_suffix;
-	private String pathToStore;
-	private String representation;
-	private String description;
-	private int versionNumber;
-	private final Status status;
-	private int uniqueId;
+    private String url_without_suffix;
+    private String pathToStore;
+    private String representation;
+    private String description;
+    private int versionNumber;
+    private final Status status;
+    private int uniqueId;
 
 
-	public DownloadPackage(Parcel src){
-		url_without_suffix = src.readString();
-		pathToStore = src.readString();
-		representation = src.readString();
-		versionNumber = src.readInt();
-		status = Status.values()[src.readInt()];
-		description = src.readString();
-		uniqueId = src.readInt();
-	}
+    public DownloadPackage(Parcel src){
+        url_without_suffix = src.readString();
+        pathToStore = src.readString();
+        representation = src.readString();
+        versionNumber = src.readInt();
+        status = Status.values()[src.readInt()];
+        description = src.readString();
+        uniqueId = src.readInt();
+    }
 
-	public DownloadPackage(Context c, String _url_without_suffix, String path, int version, String _representation, String _description, int _uniqueId){
-		url_without_suffix = _url_without_suffix;
-		pathToStore = path;
-		representation = _representation;
-		versionNumber = version;
-		description = _description;
-		uniqueId = _uniqueId;
+    public DownloadPackage(Context c, String _url_without_suffix, String path, int version, String _representation, String _description, int _uniqueId){
+        url_without_suffix = _url_without_suffix;
+        pathToStore = path;
+        representation = _representation;
+        versionNumber = version;
+        description = _description;
+        uniqueId = _uniqueId;
 
 
-		//determine if the user has already downloaded this version
-		SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
-		int currentVersion = sharedPref.getInt(representation, -1);
-		if(currentVersion == versionNumber) status = Status.CURRENTVERSION;
-		else if (currentVersion < versionNumber) status = Status.NEWERVERSION;
-		else status = Status.OLDERVERSION;
-	}
+        //determine if the user has already downloaded this version
+        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
+        int currentVersion = sharedPref.getInt(representation, -1);
+        if(currentVersion == versionNumber) status = Status.CURRENTVERSION;
+        else if (currentVersion < versionNumber) status = Status.NEWERVERSION;
+        else status = Status.OLDERVERSION;
+    }
 
-	public Status getStatus(){
-		return status;
-	}
+    public Status getStatus(){
+        return status;
+    }
 
-	public String getURL(){
-		return url_without_suffix;
-	}
+    public String getURL(){
+        return url_without_suffix;
+    }
 
-	public String getPathToStore(){
-		return pathToStore;
-	}
+    public String getPathToStore(){
+        return pathToStore;
+    }
 
-	public String toString(){
-		return representation;
-	}
+    public String toString(){
+        return representation;
+    }
 
-	public int describeContents() {
-		return 0;
-	}
-	public int getId(){
-		return uniqueId;
-	}
+    public int describeContents() {
+        return 0;
+    }
+    public int getId(){
+        return uniqueId;
+    }
 
-	public void writeToParcel(Parcel dest, int flags) {
-		dest.writeString(url_without_suffix);
-		dest.writeString(pathToStore);
-		dest.writeString(representation);
-		dest.writeInt(versionNumber);
-		dest.writeInt(status.ordinal());
-		dest.writeString(description);
-	}
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeString(url_without_suffix);
+        dest.writeString(pathToStore);
+        dest.writeString(representation);
+        dest.writeInt(versionNumber);
+        dest.writeInt(status.ordinal());
+        dest.writeString(description);
+    }
 
-	public static final Parcelable.Creator<DownloadPackage> CREATOR = new Parcelable.Creator<DownloadPackage>() {
-		public DownloadPackage createFromParcel(Parcel source) {
-			return new DownloadPackage(source);
-		}
-		public DownloadPackage[] newArray(int size) {
-			return new DownloadPackage[size];
-		}
-	};
+    public static final Parcelable.Creator<DownloadPackage> CREATOR = new Parcelable.Creator<DownloadPackage>() {
+        public DownloadPackage createFromParcel(Parcel source) {
+            return new DownloadPackage(source);
+        }
+        public DownloadPackage[] newArray(int size) {
+            return new DownloadPackage[size];
+        }
+    };
 
-	/*
-	 * We enter with a XmlPullParser.Start_tag with name "task"
-	 */
-	public static DownloadPackage getTaskFromXML(Context c, XmlPullParser xmlPuller) throws XmlPullParserException, IOException{
-		String url = null;
-		String path = null;
-		String representation = null;
-		String description = null;
-		int uniqueId = -1;
-		int version = -1;
+    /*
+     * We enter with a XmlPullParser.Start_tag with name "task"
+     */
+    public static DownloadPackage getTaskFromXML(Context c, XmlPullParser xmlPuller) throws XmlPullParserException, IOException{
+        String url = null;
+        String path = null;
+        String representation = null;
+        String description = null;
+        int uniqueId = -1;
+        int version = -1;
 
-		int eventType = DownloadPackage.getEventType(xmlPuller);//get the next token, should be a start tag
-		while(eventType != XmlPullParser.END_DOCUMENT){
-			switch(eventType){
-			case XmlPullParser.START_TAG:
-				String name = xmlPuller.getName().toLowerCase();
-				if(DownloadPackage.getEventType(xmlPuller) == XmlPullParser.TEXT){
-					String text = xmlPuller.getText().trim();
-					if(name.equals("url")){
-						url = text;
-					}else if(name.equals("version")){
-						try{
-						version = Integer.parseInt(text);
-						}catch (NumberFormatException e){
-							e.printStackTrace();
-							version = -1;
-						}
-					}else if(name.equals("path")){
-						path = FileUtils.getDataPathFile(c, text).getAbsolutePath();
-					}else if(name.equals("representation")){
-						representation = text;
-					}else if(name.equals("description")){
-						description = text;
-					}else if(name.equals("uniqueid")){
-						try{
-							uniqueId = Integer.parseInt(text);
-							}catch (NumberFormatException e){
-								e.printStackTrace();
-								version = -1;
-							}
-					}
-				}				
-				DownloadPackage.getEventType(xmlPuller);//endtag
-				break;
-			case XmlPullParser.END_TAG:
-				if(xmlPuller.getName().toLowerCase().equals("task") && url != null && path != null && version != -1 && representation != null){
-					return new DownloadPackage(c, url, path, version, representation, description, uniqueId);
-				}else{
-					throw new XmlPullParserException("XML download parsing: missing tags");
-				}
-			case XmlPullParser.TEXT:
-				throw new XmlPullParserException("Wrong tag recieved got TEXT : " + xmlPuller.getText());
-			default:
-				throw new XmlPullParserException("Wrong tag recieved got: " + eventType);
-			}
-			eventType = DownloadPackage.getEventType(xmlPuller);
-		}
-		throw new XmlPullParserException("Xml: unexpected endofdocument tag");
-	}
+        int eventType = DownloadPackage.getEventType(xmlPuller);//get the next token, should be a start tag
+        while(eventType != XmlPullParser.END_DOCUMENT){
+            switch(eventType){
+            case XmlPullParser.START_TAG:
+                String name = xmlPuller.getName().toLowerCase();
+                if(DownloadPackage.getEventType(xmlPuller) == XmlPullParser.TEXT){
+                    String text = xmlPuller.getText().trim();
+                    if(name.equals("url")){
+                        url = text;
+                    }else if(name.equals("version")){
+                        try{
+                        version = Integer.parseInt(text);
+                        }catch (NumberFormatException e){
+                            e.printStackTrace();
+                            version = -1;
+                        }
+                    }else if(name.equals("path")){
+                        path = FileUtils.getDataPathFile(c, text).getAbsolutePath();
+                    }else if(name.equals("representation")){
+                        representation = text;
+                    }else if(name.equals("description")){
+                        description = text;
+                    }else if(name.equals("uniqueid")){
+                        try{
+                            uniqueId = Integer.parseInt(text);
+                            }catch (NumberFormatException e){
+                                e.printStackTrace();
+                                version = -1;
+                            }
+                    }
+                }
+                DownloadPackage.getEventType(xmlPuller);//endtag
+                break;
+            case XmlPullParser.END_TAG:
+                if(xmlPuller.getName().toLowerCase().equals("task") && url != null && path != null && version != -1 && representation != null){
+                    return new DownloadPackage(c, url, path, version, representation, description, uniqueId);
+                }else{
+                    throw new XmlPullParserException("XML download parsing: missing tags");
+                }
+            case XmlPullParser.TEXT:
+                throw new XmlPullParserException("Wrong tag recieved got TEXT : " + xmlPuller.getText());
+            default:
+                throw new XmlPullParserException("Wrong tag recieved got: " + eventType);
+            }
+            eventType = DownloadPackage.getEventType(xmlPuller);
+        }
+        throw new XmlPullParserException("Xml: unexpected endofdocument tag");
+    }
 
-	/**
-	 * Skips whitespaces..
-	 */
-	private static int getEventType(XmlPullParser xmlPuller)throws XmlPullParserException, IOException{
-		int eventType = xmlPuller.next();
-		while(eventType == XmlPullParser.TEXT && xmlPuller.isWhitespace()){
-			eventType = xmlPuller.next();
-		}
-		return eventType;
-	}
+    /**
+     * Skips whitespaces..
+     */
+    private static int getEventType(XmlPullParser xmlPuller)throws XmlPullParserException, IOException{
+        int eventType = xmlPuller.next();
+        while(eventType == XmlPullParser.TEXT && xmlPuller.isWhitespace()){
+            eventType = xmlPuller.next();
+        }
+        return eventType;
+    }
 }
 
 enum Status{
-	CURRENTVERSION, NEWERVERSION, OLDERVERSION;
+    CURRENTVERSION, NEWERVERSION, OLDERVERSION;
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadService.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadService.java	Tue Jan 21 22:53:15 2014 +0100
@@ -37,194 +37,194 @@
 import android.widget.RemoteViews;
 
 public class DownloadService extends Service {
-	public final static String INTENT_TASKID = "taskId";
-	public final static String INTENT_TASK = "task";
+    public final static String INTENT_TASKID = "taskId";
+    public final static String INTENT_TASK = "task";
 
-	public static final String PREF_DOWNLOADED = "downloaded";
-	public static final int MSG_CANCEL = 0;
-	public static final int MSG_UNREGISTER_CLIENT = 2;
-	public final static int MSG_ADDTASK = 4;
+    public static final String PREF_DOWNLOADED = "downloaded";
+    public static final int MSG_CANCEL = 0;
+    public static final int MSG_UNREGISTER_CLIENT = 2;
+    public final static int MSG_ADDTASK = 4;
 
-	public static final int NOTIFICATION_PROCESSING = 0;
-	public static final int NOTIFICATION_DONE = 1;
+    public static final int NOTIFICATION_PROCESSING = 0;
+    public static final int NOTIFICATION_DONE = 1;
 
-	private DownloadAsyncTask asyncExecutor;
+    private DownloadAsyncTask asyncExecutor;
 
-	private DownloadHandler handler = new DownloadHandler();
-	private final Messenger messenger = new Messenger(handler);
+    private DownloadHandler handler = new DownloadHandler();
+    private final Messenger messenger = new Messenger(handler);
 
-	private NotificationManager nM;
-	private RemoteViews contentView;
+    private NotificationManager nM;
+    private RemoteViews contentView;
 
-	private LinkedList<DownloadTask> downloadTasks = new LinkedList<DownloadTask>();
-	private DownloadTask currentTask = null;
+    private LinkedList<DownloadTask> downloadTasks = new LinkedList<DownloadTask>();
+    private DownloadTask currentTask = null;
 
-	public class DownloadHandler extends Handler{
+    public class DownloadHandler extends Handler{
 
-		public void handleMessage(Message msg){
-			if(msg.obj != null){
-				DownloadPackage pack = (DownloadPackage) msg.obj;
-				DownloadTask task = null;
-				Messenger replyToMessenger = msg.replyTo;
-				for(DownloadTask _task : downloadTasks){
-					if(_task.getPackage().equals(pack)){
-						task = _task;
-						break;
-					}
-				}
+        public void handleMessage(Message msg){
+            if(msg.obj != null){
+                DownloadPackage pack = (DownloadPackage) msg.obj;
+                DownloadTask task = null;
+                Messenger replyToMessenger = msg.replyTo;
+                for(DownloadTask _task : downloadTasks){
+                    if(_task.getPackage().equals(pack)){
+                        task = _task;
+                        break;
+                    }
+                }
 
-				switch(msg.what){
-				case MSG_ADDTASK:
-					if(task == null){
-						task = new DownloadTask(pack);
-						downloadTasks.add(task);
-					}
+                switch(msg.what){
+                case MSG_ADDTASK:
+                    if(task == null){
+                        task = new DownloadTask(pack);
+                        downloadTasks.add(task);
+                    }
 
-					task.addClient(replyToMessenger);
-					runNextTask();
-					return;
-				case MSG_CANCEL:
-					if(task != null && task.getPackage().equals(pack) && task.getStatus() == TASK_STATE.PENDING){
-						downloadTasks.remove(task);
-					}
-					if(currentTask != null && currentTask.getPackage().equals(pack)){//TODO synchronization problem?
-						asyncExecutor.cancel(false);
-					}
-					return;
-				case MSG_UNREGISTER_CLIENT:
-					if(task != null){
-						task.removeClient(replyToMessenger);
-					}
-					return;
-				}
-			}
-		}
-	}
+                    task.addClient(replyToMessenger);
+                    runNextTask();
+                    return;
+                case MSG_CANCEL:
+                    if(task != null && task.getPackage().equals(pack) && task.getStatus() == TASK_STATE.PENDING){
+                        downloadTasks.remove(task);
+                    }
+                    if(currentTask != null && currentTask.getPackage().equals(pack)){//TODO synchronization problem?
+                        asyncExecutor.cancel(false);
+                    }
+                    return;
+                case MSG_UNREGISTER_CLIENT:
+                    if(task != null){
+                        task.removeClient(replyToMessenger);
+                    }
+                    return;
+                }
+            }
+        }
+    }
 
-	public void onCreate(){
-		super.onCreate();
-		nM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-	}
-	public IBinder onBind(Intent intent) {
-		return messenger.getBinder();
-	}
+    public void onCreate(){
+        super.onCreate();
+        nM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+    }
+    public IBinder onBind(Intent intent) {
+        return messenger.getBinder();
+    }
 
-	private void runNextTask(){
-		if(asyncExecutor == null){//if (task isnt running right now) ...
-			currentTask = downloadTasks.poll();
-			if(currentTask != null){
-				asyncExecutor = new DownloadAsyncTask(currentTask);
-				asyncExecutor.execute(currentTask.getPackage());
-			}
-		}
-	}
+    private void runNextTask(){
+        if(asyncExecutor == null){//if (task isnt running right now) ...
+            currentTask = downloadTasks.poll();
+            if(currentTask != null){
+                asyncExecutor = new DownloadAsyncTask(currentTask);
+                asyncExecutor.execute(currentTask.getPackage());
+            }
+        }
+    }
 
-	public void onDestroy(){
-		super.onDestroy();
-		asyncExecutor.cancel(false);	
-	}
+    public void onDestroy(){
+        super.onDestroy();
+        asyncExecutor.cancel(false);
+    }
 
-	class DownloadTask {
-		private final DownloadPackage pack;
-		private TASK_STATE status = TASK_STATE.PENDING;
-		private Notification progressNotification, doneNotification;
+    class DownloadTask {
+        private final DownloadPackage pack;
+        private TASK_STATE status = TASK_STATE.PENDING;
+        private Notification progressNotification, doneNotification;
 
-		//I expect little to no removeClient calls that's why we go for a list rather than a map
-		private final List<Messenger> clients;
+        //I expect little to no removeClient calls that's why we go for a list rather than a map
+        private final List<Messenger> clients;
 
-		public DownloadTask(DownloadPackage _pack){
-			pack = _pack;
-			clients = new LinkedList<Messenger>();
-		}
+        public DownloadTask(DownloadPackage _pack){
+            pack = _pack;
+            clients = new LinkedList<Messenger>();
+        }
 
-		public void addClient(Messenger messenger){
-			clients.add(messenger);
-		}
-		public void removeClient(Messenger messenger){
-			clients.remove(messenger);
-		}
+        public void addClient(Messenger messenger){
+            clients.add(messenger);
+        }
+        public void removeClient(Messenger messenger){
+            clients.remove(messenger);
+        }
 
-		public DownloadPackage getPackage(){
-			return pack;
-		}
+        public DownloadPackage getPackage(){
+            return pack;
+        }
 
-		public TASK_STATE getStatus(){
-			return status;
-		}
+        public TASK_STATE getStatus(){
+            return status;
+        }
 
-		public void sendMessageToClients(Message msg){
-			for(Messenger messenger : clients){
-				try {
-					messenger.send(msg);		
-				} catch (RemoteException e) {
-					e.printStackTrace();
-				}
-			}
-		}
+        public void sendMessageToClients(Message msg){
+            for(Messenger messenger : clients){
+                try {
+                    messenger.send(msg);
+                } catch (RemoteException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
 
-		/*
-		 * Callbacks called from the async tasks
-		 */
+        /*
+         * Callbacks called from the async tasks
+         */
 
-		//Thread safe method to let clients know the processing is starting and will process int max kbytes
-		public void start(int max){
-			progressNotification = new Notification(R.drawable.statusbar, getString(R.string.notification_title), System.currentTimeMillis());
-			progressNotification.flags |= Notification.FLAG_ONGOING_EVENT;
+        //Thread safe method to let clients know the processing is starting and will process int max kbytes
+        public void start(int max){
+            progressNotification = new Notification(R.drawable.statusbar, getString(R.string.notification_title), System.currentTimeMillis());
+            progressNotification.flags |= Notification.FLAG_ONGOING_EVENT;
 
-			contentView = new RemoteViews(getPackageName(), R.layout.notification);
-			contentView.setProgressBar(R.id.notification_progress, 100, 34, false);
-			progressNotification.contentView = contentView;
+            contentView = new RemoteViews(getPackageName(), R.layout.notification);
+            contentView.setProgressBar(R.id.notification_progress, 100, 34, false);
+            progressNotification.contentView = contentView;
 
-			PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, new Intent(DownloadService.this, DownloadListActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
-			progressNotification.contentIntent = contentIntent;
+            PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, new Intent(DownloadService.this, DownloadListActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
+            progressNotification.contentIntent = contentIntent;
 
-			startForeground(NOTIFICATION_PROCESSING, progressNotification);
+            startForeground(NOTIFICATION_PROCESSING, progressNotification);
 
-			Message msg = Message.obtain(null, DownloadFragment.MSG_START, max, 0);
-			sendMessageToClients(msg);
-		}
+            Message msg = Message.obtain(null, DownloadFragment.MSG_START, max, 0);
+            sendMessageToClients(msg);
+        }
 
-		//periodically gets called by the ASyncTask, we can't tell for sure when it's called
-		public void update(int progress, int max, String fileName){
-			progress = (progress/1024);
+        //periodically gets called by the ASyncTask, we can't tell for sure when it's called
+        public void update(int progress, int max, String fileName){
+            progress = (progress/1024);
 
-			contentView.setProgressBar(R.id.notification_progress, max, progress, false);
-			contentView.setTextViewText(R.id.progressbar_sub, String.format("%dkb/%dkb (Compressed sizes)", progress, max));
-			nM.notify(NOTIFICATION_PROCESSING, progressNotification);
+            contentView.setProgressBar(R.id.notification_progress, max, progress, false);
+            contentView.setTextViewText(R.id.progressbar_sub, String.format("%dkb/%dkb (Compressed sizes)", progress, max));
+            nM.notify(NOTIFICATION_PROCESSING, progressNotification);
 
-			sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_UPDATE, progress, max, fileName));
-		}
+            sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_UPDATE, progress, max, fileName));
+        }
 
-		//Call back from the ASync task when the task has either run into an error or finished otherwise
-		public void done(int result){
-			switch(result){
-			case DownloadAsyncTask.EXIT_SUCCESS: 	sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break;
-			case DownloadAsyncTask.EXIT_CONNERROR:  sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_CONNERROR, 0)); break;
-			case DownloadAsyncTask.EXIT_FNF:		sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_FNF, 0)); break;
-			case DownloadAsyncTask.EXIT_MD5:		sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_MD5, 0)); break;
-			case DownloadAsyncTask.EXIT_URLFAIL:	sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_URLFAIL, 0)); break;
-			case DownloadAsyncTask.EXIT_CANCELLED:	sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break;
-			}
-			
-			stopForeground(true);
-			nM.cancel(NOTIFICATION_PROCESSING);
+        //Call back from the ASync task when the task has either run into an error or finished otherwise
+        public void done(int result){
+            switch(result){
+            case DownloadAsyncTask.EXIT_SUCCESS:    sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break;
+            case DownloadAsyncTask.EXIT_CONNERROR:  sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_CONNERROR, 0)); break;
+            case DownloadAsyncTask.EXIT_FNF:        sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_FNF, 0)); break;
+            case DownloadAsyncTask.EXIT_MD5:        sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_MD5, 0)); break;
+            case DownloadAsyncTask.EXIT_URLFAIL:    sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_URLFAIL, 0)); break;
+            case DownloadAsyncTask.EXIT_CANCELLED:  sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break;
+            }
 
-			String title = getString(R.string.notification_title);
+            stopForeground(true);
+            nM.cancel(NOTIFICATION_PROCESSING);
+
+            String title = getString(R.string.notification_title);
 
-			doneNotification = new Notification(R.drawable.icon, title, System.currentTimeMillis());
-			doneNotification.flags |= Notification.FLAG_AUTO_CANCEL;
-			PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, new Intent(DownloadService.this, DownloadListActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
-			doneNotification.setLatestEventInfo(DownloadService.this, title, getString(R.string.notification_done) + pack, contentIntent);
-			nM.notify(pack.getId(), doneNotification);
+            doneNotification = new Notification(R.drawable.icon, title, System.currentTimeMillis());
+            doneNotification.flags |= Notification.FLAG_AUTO_CANCEL;
+            PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, new Intent(DownloadService.this, DownloadListActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
+            doneNotification.setLatestEventInfo(DownloadService.this, title, getString(R.string.notification_done) + pack, contentIntent);
+            nM.notify(pack.getId(), doneNotification);
 
-			asyncExecutor = null;
-			runNextTask();//see if there are more tasks
-		}
+            asyncExecutor = null;
+            runNextTask();//see if there are more tasks
+        }
 
-	}
+    }
 
-	enum TASK_STATE{
-		RUNNING, FINISHED, PENDING;
-	}
+    enum TASK_STATE{
+        RUNNING, FINISHED, PENDING;
+    }
 
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/PascalExports.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/PascalExports.java	Tue Jan 21 22:53:15 2014 +0100
@@ -21,28 +21,28 @@
 package org.hedgewars.hedgeroid.EngineProtocol;
 
 public class PascalExports {
-	public static Object engineMutex = new Object();
+    public static Object engineMutex = new Object();
 
-	static{
-		System.loadLibrary("SDL");
-		System.loadLibrary("SDL_image");
-		System.loadLibrary("mikmod");
-		System.loadLibrary("SDL_net");
-		System.loadLibrary("SDL_mixer");
-		System.loadLibrary("SDL_ttf");
-		System.loadLibrary("lua5.1");
-		System.loadLibrary("physfs");
-		System.loadLibrary("physlayer");
-		System.loadLibrary("hwengine");
-	}
-	
-	public static native int HWgetMaxNumberOfTeams();
+    static{
+        System.loadLibrary("SDL");
+        System.loadLibrary("SDL_image");
+        System.loadLibrary("mikmod");
+        System.loadLibrary("SDL_net");
+        System.loadLibrary("SDL_mixer");
+        System.loadLibrary("SDL_ttf");
+        System.loadLibrary("lua5.1");
+        System.loadLibrary("physfs");
+        System.loadLibrary("physlayer");
+        System.loadLibrary("hwengine");
+    }
+
+    public static native int HWgetMaxNumberOfTeams();
     private static native void HWGenLandPreview(int port);
 
     public static void synchronizedGenLandPreview(int port) {
-    	synchronized(engineMutex) {
-    		HWGenLandPreview(port);
-    	}
+        synchronized(engineMutex) {
+            HWGenLandPreview(port);
+        }
     }
-    
+
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/GameConnection.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/GameConnection.java	Tue Jan 21 22:53:15 2014 +0100
@@ -48,175 +48,175 @@
  * This class handles both talking to the engine (IPC) for running a game, and
  * coordinating with the netconn if it is a netgame, using the frontlib for the
  * actual IPC networking communication.
- * 
+ *
  * After creating the GameConnection object, it will communicate with the engine
  * on its own thread. It shuts itself down as soon as the connection to the engine
  * is lost.
  */
 public final class GameConnection {
-	private static final Handler mainHandler = new Handler(Looper.getMainLooper());
-	
-	public final int port;
-	private final HandlerThread thread;
-	private final Handler handler;
-	private TickHandler tickHandler;
-	private final Netplay netplay; // ==null if not a netgame
-	private GameconnPtr conn;
-	
-	private GameConnection(GameconnPtr conn, Netplay netplay) {
-		this.conn = conn;
-		this.port = Flib.INSTANCE.flib_gameconn_getport(conn);
-		this.netplay = netplay;
-		this.thread = new HandlerThread("IPCThread");
-		thread.start();
-		this.handler = new Handler(thread.getLooper());
-	}
-	
-	private void setupConnection() {
-		tickHandler = new TickHandler(thread.getLooper(), 50, tickCb);
-		tickHandler.start();
-		
-		if(netplay != null) {
-			mainHandler.post(new Runnable() {
-				public void run() { 
-					netplay.registerGameMessageListener(gameMessageListener);
-				}
-			});
-			Flib.INSTANCE.flib_gameconn_onChat(conn, chatCb, null);
-			Flib.INSTANCE.flib_gameconn_onEngineMessage(conn, engineMessageCb, null);
-		}
-		Flib.INSTANCE.flib_gameconn_onConnect(conn, connectCb, null);
-		Flib.INSTANCE.flib_gameconn_onDisconnect(conn, disconnectCb, null);
-		Flib.INSTANCE.flib_gameconn_onErrorMessage(conn, errorMessageCb, null);
-	}
-	
-	/**
-	 * Start a new IPC server to communicate with the engine.
-	 * Performs networking operations, don't run on the UI thread.
-	 * @throws ConnectException if we can't set up the IPC server
-	 */
-	public static GameConnection forNetgame(final GameConfig config, Netplay netplay) throws ConnectException {
-		final String playerName = netplay.getPlayerName();
-		GameconnPtr conn = Flib.INSTANCE.flib_gameconn_create(playerName, GameSetupPtr.createJavaOwned(config), true);
-		if(conn == null) {
-			throw new ConnectException();
-		}
-		GameConnection result = new GameConnection(conn, netplay);
-		result.setupConnection();
-		return result;
-	}
-	
-	/**
-	 * Start a new IPC server to communicate with the engine.
-	 * Performs networking operations, don't run on the UI thread.
-	 * @throws ConnectException if we can't set up the IPC server
-	 */
-	public static GameConnection forLocalGame(final GameConfig config) throws ConnectException {
-		GameconnPtr conn = Flib.INSTANCE.flib_gameconn_create("Player", GameSetupPtr.createJavaOwned(config), false);
-		if(conn == null) {
-			throw new ConnectException();
-		}
-		GameConnection result = new GameConnection(conn, null);
-		result.setupConnection();
-		return result;
-	}
-	
-	private final Runnable tickCb = new Runnable() {
-		public void run() {
-			Flib.INSTANCE.flib_gameconn_tick(conn);
-		}
-	};
-	
-	// runs on the IPCThread
-	private void shutdown() {
-		tickHandler.stop();
-		thread.quit();
-		Flib.INSTANCE.flib_gameconn_destroy(conn);
-		conn = null;
-		if(netplay != null) {
-			mainHandler.post(new Runnable() {
-				public void run() {
-					netplay.unregisterGameMessageListener(gameMessageListener);
-				}
-			});
-		}
-	}
-	
-	// runs on the IPCThread
-	private final StrBoolCallback chatCb = new StrBoolCallback() {
-		public void callback(Pointer context, String message, boolean teamChat) {
-			if(teamChat) {
-				netplay.sendTeamChat(message);
-			} else {
-				netplay.sendChat(message);
-			}
-		}
-	};
-	
-	// runs on the IPCThread
-	private final VoidCallback connectCb = new VoidCallback() {
-		public void callback(Pointer context) {
-			Log.i("GameConnection", "Connected");
-		}
-	};
-	
-	// runs on the IPCThread
-	private final IntCallback disconnectCb = new IntCallback() {
-		public void callback(Pointer context, int reason) {
-			if(netplay != null) {
-				netplay.sendRoundFinished(reason==Frontlib.GAME_END_FINISHED);
-			}
-			shutdown();
-		}
-	};
-	
-	// runs on the IPCThread
-	private final BytesCallback engineMessageCb = new BytesCallback() {
-		public void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size) {
-			netplay.sendEngineMessage(buffer.deref(size.intValue()));
-		}
-	};
-	
-	// runs on the IPCThread
-	private final StrCallback errorMessageCb = new StrCallback() {
-		public void callback(Pointer context, String message) {
-			Log.e("GameConnection", message);
-		}
-	};
-	
-	// runs on any thread
-	private final GameMessageListener gameMessageListener = new GameMessageListener() {
-		public void onNetDisconnected() {
-			handler.post(new Runnable() {
-				public void run() {
-					Flib.INSTANCE.flib_gameconn_send_quit(conn);
-				}
-			});
-		}
-		
-		public void onMessage(final int type, final String message) {
-			handler.post(new Runnable() {
-				public void run() {
-					Flib.INSTANCE.flib_gameconn_send_textmsg(conn, type, message);
-				}
-			});
-		}
-		
-		public void onEngineMessage(final byte[] em) {
-			handler.post(new Runnable() {
-				public void run() {
-					ByteArrayPtr ptr = ByteArrayPtr.createJavaOwned(em);
-					Flib.INSTANCE.flib_gameconn_send_enginemsg(conn, ptr, NativeSizeT.valueOf(em.length));
-				}
-			});
-		}
-		
-		public void onChatMessage(final String nick, final String message) {
-			handler.post(new Runnable() {
-				public void run() {
-					Flib.INSTANCE.flib_gameconn_send_chatmsg(conn, nick, message);
-				}
-			});
-		}
-	};
+    private static final Handler mainHandler = new Handler(Looper.getMainLooper());
+
+    public final int port;
+    private final HandlerThread thread;
+    private final Handler handler;
+    private TickHandler tickHandler;
+    private final Netplay netplay; // ==null if not a netgame
+    private GameconnPtr conn;
+
+    private GameConnection(GameconnPtr conn, Netplay netplay) {
+        this.conn = conn;
+        this.port = Flib.INSTANCE.flib_gameconn_getport(conn);
+        this.netplay = netplay;
+        this.thread = new HandlerThread("IPCThread");
+        thread.start();
+        this.handler = new Handler(thread.getLooper());
+    }
+
+    private void setupConnection() {
+        tickHandler = new TickHandler(thread.getLooper(), 50, tickCb);
+        tickHandler.start();
+
+        if(netplay != null) {
+            mainHandler.post(new Runnable() {
+                public void run() {
+                    netplay.registerGameMessageListener(gameMessageListener);
+                }
+            });
+            Flib.INSTANCE.flib_gameconn_onChat(conn, chatCb, null);
+            Flib.INSTANCE.flib_gameconn_onEngineMessage(conn, engineMessageCb, null);
+        }
+        Flib.INSTANCE.flib_gameconn_onConnect(conn, connectCb, null);
+        Flib.INSTANCE.flib_gameconn_onDisconnect(conn, disconnectCb, null);
+        Flib.INSTANCE.flib_gameconn_onErrorMessage(conn, errorMessageCb, null);
+    }
+
+    /**
+     * Start a new IPC server to communicate with the engine.
+     * Performs networking operations, don't run on the UI thread.
+     * @throws ConnectException if we can't set up the IPC server
+     */
+    public static GameConnection forNetgame(final GameConfig config, Netplay netplay) throws ConnectException {
+        final String playerName = netplay.getPlayerName();
+        GameconnPtr conn = Flib.INSTANCE.flib_gameconn_create(playerName, GameSetupPtr.createJavaOwned(config), true);
+        if(conn == null) {
+            throw new ConnectException();
+        }
+        GameConnection result = new GameConnection(conn, netplay);
+        result.setupConnection();
+        return result;
+    }
+
+    /**
+     * Start a new IPC server to communicate with the engine.
+     * Performs networking operations, don't run on the UI thread.
+     * @throws ConnectException if we can't set up the IPC server
+     */
+    public static GameConnection forLocalGame(final GameConfig config) throws ConnectException {
+        GameconnPtr conn = Flib.INSTANCE.flib_gameconn_create("Player", GameSetupPtr.createJavaOwned(config), false);
+        if(conn == null) {
+            throw new ConnectException();
+        }
+        GameConnection result = new GameConnection(conn, null);
+        result.setupConnection();
+        return result;
+    }
+
+    private final Runnable tickCb = new Runnable() {
+        public void run() {
+            Flib.INSTANCE.flib_gameconn_tick(conn);
+        }
+    };
+
+    // runs on the IPCThread
+    private void shutdown() {
+        tickHandler.stop();
+        thread.quit();
+        Flib.INSTANCE.flib_gameconn_destroy(conn);
+        conn = null;
+        if(netplay != null) {
+            mainHandler.post(new Runnable() {
+                public void run() {
+                    netplay.unregisterGameMessageListener(gameMessageListener);
+                }
+            });
+        }
+    }
+
+    // runs on the IPCThread
+    private final StrBoolCallback chatCb = new StrBoolCallback() {
+        public void callback(Pointer context, String message, boolean teamChat) {
+            if(teamChat) {
+                netplay.sendTeamChat(message);
+            } else {
+                netplay.sendChat(message);
+            }
+        }
+    };
+
+    // runs on the IPCThread
+    private final VoidCallback connectCb = new VoidCallback() {
+        public void callback(Pointer context) {
+            Log.i("GameConnection", "Connected");
+        }
+    };
+
+    // runs on the IPCThread
+    private final IntCallback disconnectCb = new IntCallback() {
+        public void callback(Pointer context, int reason) {
+            if(netplay != null) {
+                netplay.sendRoundFinished(reason==Frontlib.GAME_END_FINISHED);
+            }
+            shutdown();
+        }
+    };
+
+    // runs on the IPCThread
+    private final BytesCallback engineMessageCb = new BytesCallback() {
+        public void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size) {
+            netplay.sendEngineMessage(buffer.deref(size.intValue()));
+        }
+    };
+
+    // runs on the IPCThread
+    private final StrCallback errorMessageCb = new StrCallback() {
+        public void callback(Pointer context, String message) {
+            Log.e("GameConnection", message);
+        }
+    };
+
+    // runs on any thread
+    private final GameMessageListener gameMessageListener = new GameMessageListener() {
+        public void onNetDisconnected() {
+            handler.post(new Runnable() {
+                public void run() {
+                    Flib.INSTANCE.flib_gameconn_send_quit(conn);
+                }
+            });
+        }
+
+        public void onMessage(final int type, final String message) {
+            handler.post(new Runnable() {
+                public void run() {
+                    Flib.INSTANCE.flib_gameconn_send_textmsg(conn, type, message);
+                }
+            });
+        }
+
+        public void onEngineMessage(final byte[] em) {
+            handler.post(new Runnable() {
+                public void run() {
+                    ByteArrayPtr ptr = ByteArrayPtr.createJavaOwned(em);
+                    Flib.INSTANCE.flib_gameconn_send_enginemsg(conn, ptr, NativeSizeT.valueOf(em.length));
+                }
+            });
+        }
+
+        public void onChatMessage(final String nick, final String message) {
+            handler.post(new Runnable() {
+                public void run() {
+                    Flib.INSTANCE.flib_gameconn_send_chatmsg(conn, nick, message);
+                }
+            });
+        }
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -38,103 +38,103 @@
 /**
  * Activity for the server lobby of a hedgewars server. Allows you to chat, join
  * and create rooms and interact with a list of players.
- * 
+ *
  * Most of the functionality is handled by various fragments.
  */
 public class LobbyActivity extends FragmentActivity implements TextInputDialogListener, NetplayStateListener {
-	private static final int DIALOG_CREATE_ROOM = 0;
-	
+    private static final int DIALOG_CREATE_ROOM = 0;
+
     private TabHost tabHost;
     private Netplay netplay;
-    
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
-        
+
         setContentView(R.layout.activity_lobby);
         ChatFragment chatFragment = (ChatFragment)getSupportFragmentManager().findFragmentById(R.id.chatFragment);
         chatFragment.setInRoom(false);
-        
+
         FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
         trans.add(new NetplayStateFragment(), "netplayFragment");
         trans.commit();
-        
+
         netplay = Netplay.getAppInstance(getApplicationContext());
-        
+
         // Set up a tabbed UI for medium and small screens
         tabHost = (TabHost)findViewById(android.R.id.tabhost);
         if(tabHost != null) {
-	        tabHost.setup();
-	        tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
+            tabHost.setup();
+            tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
 
-	        tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_rooms, R.drawable.roomlist_ingame)).setContent(R.id.roomListFragment));
-	        tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_chat, R.drawable.edit)).setContent(R.id.chatFragment));
-	        tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_players, R.drawable.human)).setContent(R.id.playerListFragment));
-	
-	        if (icicle != null) {
-	            tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
-	        }
+            tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_rooms, R.drawable.roomlist_ingame)).setContent(R.id.roomListFragment));
+            tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_chat, R.drawable.edit)).setContent(R.id.chatFragment));
+            tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_players, R.drawable.human)).setContent(R.id.playerListFragment));
+
+            if (icicle != null) {
+                tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
+            }
         }
     }
-    
-	@Override
-	public boolean onCreateOptionsMenu(Menu menu) {
-		super.onCreateOptionsMenu(menu);
-		getMenuInflater().inflate(R.menu.lobby_options, menu);
-		return true;
-	}
-	
-	@Override
-	public boolean onOptionsItemSelected(MenuItem item) {
-		switch(item.getItemId()) {
-		case R.id.room_create:
-	        TextInputDialog dialog = new TextInputDialog(DIALOG_CREATE_ROOM, R.string.dialog_create_room_title, 0, R.string.dialog_create_room_hint);
-	        dialog.show(getSupportFragmentManager(), "create_room_dialog");
-			return true;
-		case R.id.disconnect:
-			netplay.disconnect();
-			return true;
-		default:
-			return super.onOptionsItemSelected(item);
-		}
-	}
-	
-	@Override
-	public void onBackPressed() {
-		netplay.disconnect();
-	}
-	
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        super.onCreateOptionsMenu(menu);
+        getMenuInflater().inflate(R.menu.lobby_options, menu);
+        return true;
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch(item.getItemId()) {
+        case R.id.room_create:
+            TextInputDialog dialog = new TextInputDialog(DIALOG_CREATE_ROOM, R.string.dialog_create_room_title, 0, R.string.dialog_create_room_hint);
+            dialog.show(getSupportFragmentManager(), "create_room_dialog");
+            return true;
+        case R.id.disconnect:
+            netplay.disconnect();
+            return true;
+        default:
+            return super.onOptionsItemSelected(item);
+        }
+    }
+
+    @Override
+    public void onBackPressed() {
+        netplay.disconnect();
+    }
+
     @Override
     protected void onSaveInstanceState(Bundle icicle) {
         super.onSaveInstanceState(icicle);
         if(tabHost != null) {
-        	icicle.putString("currentTab", tabHost.getCurrentTabTag());
+            icicle.putString("currentTab", tabHost.getCurrentTabTag());
         }
     }
-    
+
     public void onTextInputDialogSubmitted(int dialogId, String text) {
-    	if(text != null && text.length()>0) {
-    		netplay.sendCreateRoom(text);
-    	}
+        if(text != null && text.length()>0) {
+            netplay.sendCreateRoom(text);
+        }
     }
-    
+
     public void onTextInputDialogCancelled(int dialogId) {
     }
-    
+
     public void onNetplayStateChanged(State newState) {
-    	switch(newState) {
-    	case CONNECTING:
-    	case NOT_CONNECTED:
-    		finish();
-    		break;
-    	case ROOM:
-    		startActivity(new Intent(getApplicationContext(), NetRoomActivity.class));
-    		break;
-    	case LOBBY:
-    		// Do nothing
-    		break;
-		default:
-			throw new IllegalStateException("Unknown connection state: "+newState);
-    	}
+        switch(newState) {
+        case CONNECTING:
+        case NOT_CONNECTED:
+            finish();
+            break;
+        case ROOM:
+            startActivity(new Intent(getApplicationContext(), NetRoomActivity.class));
+            break;
+        case LOBBY:
+            // Do nothing
+            break;
+        default:
+            throw new IllegalStateException("Unknown connection state: "+newState);
+        }
     }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyPlayerlistAdapter.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyPlayerlistAdapter.java	Tue Jan 21 22:53:15 2014 +0100
@@ -41,28 +41,28 @@
  * Simple adapter for displaying the list of players in the lobby.
  */
 public class LobbyPlayerlistAdapter extends ObservableTreeMapAdapter<String, Player> {
-	@Override
-	protected Comparator<Player> getEntryOrder() {
-		return Player.ADMIN_NAME_ORDER;
-	}
+    @Override
+    protected Comparator<Player> getEntryOrder() {
+        return Player.ADMIN_NAME_ORDER;
+    }
 
-	public View getView(int position, View convertView, ViewGroup parent) {
-		View v = convertView;
-		if (v == null) {
-			LayoutInflater vi = LayoutInflater.from(parent.getContext());
-			v = vi.inflate(R.layout.listview_player, null);
-		}
+    public View getView(int position, View convertView, ViewGroup parent) {
+        View v = convertView;
+        if (v == null) {
+            LayoutInflater vi = LayoutInflater.from(parent.getContext());
+            v = vi.inflate(R.layout.listview_player, null);
+        }
 
-		Player player = getItem(position);
-		TextView username = (TextView) v.findViewById(android.R.id.text1);
-		Spannable spannable = new SpannableString(player.name);
-		if(player.registered) {
-			spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-		}
-		if(player.admin) {
-			spannable.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-		}
-		username.setText(spannable);
-		return v;
-	}
+        Player player = getItem(position);
+        TextView username = (TextView) v.findViewById(android.R.id.text1);
+        Spannable spannable = new SpannableString(player.name);
+        if(player.registered) {
+            spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        }
+        if(player.admin) {
+            spannable.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        }
+        username.setText(spannable);
+        return v;
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyPlayerlistFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LobbyPlayerlistFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -39,60 +39,60 @@
  * over the context menu.
  */
 public class LobbyPlayerlistFragment extends ListFragment {
-	private Netplay netplay;
-	private LobbyPlayerlistAdapter adapter;
-	
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
-		adapter = new LobbyPlayerlistAdapter();
-		adapter.setSource(netplay.lobbyPlayerlist);
-		setListAdapter(adapter);
-	}
+    private Netplay netplay;
+    private LobbyPlayerlistAdapter adapter;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
+        adapter = new LobbyPlayerlistAdapter();
+        adapter.setSource(netplay.lobbyPlayerlist);
+        setListAdapter(adapter);
+    }
 
-	@Override
-	public void onDestroy() {
-		super.onDestroy();
-		adapter.invalidate();
-	}
-	
-	@Override
-	public void onActivityCreated(Bundle savedInstanceState) {
-		super.onActivityCreated(savedInstanceState);
-		registerForContextMenu(getListView());
-	}
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        adapter.invalidate();
+    }
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+        registerForContextMenu(getListView());
+    }
 
-	@Override
-	public void onCreateContextMenu(ContextMenu menu, View v,
-			ContextMenuInfo menuInfo) {
-		super.onCreateContextMenu(menu, v, menuInfo);
-		AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
-		MenuInflater inflater = getActivity().getMenuInflater();
-		inflater.inflate(R.menu.lobby_playerlist_context, menu);
-		menu.setHeaderIcon(R.drawable.human);
-		menu.setHeaderTitle(adapter.getItem(info.position).name);
-	}
-	
-	@Override
-	public boolean onContextItemSelected(MenuItem item) {
-		AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
-		Player player = adapter.getItem(info.position);
-		switch(item.getItemId()) {
-		case R.id.player_info:
-			netplay.sendPlayerInfoQuery(player.name);
-			return true;
-		case R.id.player_follow:
-			netplay.sendFollowPlayer(player.name);
-			return true;
-		default:
-			return super.onContextItemSelected(item);
-		}
-	}
-	
-	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container,
-			Bundle savedInstanceState) {
-		return inflater.inflate(R.layout.fragment_playerlist, container, false);
-	}
+    @Override
+    public void onCreateContextMenu(ContextMenu menu, View v,
+            ContextMenuInfo menuInfo) {
+        super.onCreateContextMenu(menu, v, menuInfo);
+        AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
+        MenuInflater inflater = getActivity().getMenuInflater();
+        inflater.inflate(R.menu.lobby_playerlist_context, menu);
+        menu.setHeaderIcon(R.drawable.human);
+        menu.setHeaderTitle(adapter.getItem(info.position).name);
+    }
+
+    @Override
+    public boolean onContextItemSelected(MenuItem item) {
+        AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
+        Player player = adapter.getItem(info.position);
+        switch(item.getItemId()) {
+        case R.id.player_info:
+            netplay.sendPlayerInfoQuery(player.name);
+            return true;
+        case R.id.player_follow:
+            netplay.sendFollowPlayer(player.name);
+            return true;
+        default:
+            return super.onContextItemSelected(item);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.fragment_playerlist, container, false);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -44,78 +44,78 @@
  * This activity is used to set up and start a local game.
  */
 public class LocalRoomActivity extends FragmentActivity implements RoomStateManager.Provider, TeamAddDialog.Listener {
-	private TabHost tabHost;
-	private RoomStateManager stateManager;
-	private Button startButton;
-	
+    private TabHost tabHost;
+    private RoomStateManager stateManager;
+    private Button startButton;
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         // TODO find a better central location / way to set up the default scheme and weaponset
         Netplay netplay = Netplay.getAppInstance(getApplicationContext());
         stateManager = new LocalRoomStateManager(netplay.defaultScheme, netplay.defaultWeaponset);
-        
+
         setContentView(R.layout.activity_localroom);
         startButton = (Button)findViewById(R.id.startGame);
-        
+
         startButton.setOnClickListener(startButtonClickListener);
-        
+
         // Set up a tabbed UI for medium and small screens
         tabHost = (TabHost)findViewById(android.R.id.tabhost);
         if(tabHost != null) {
-	        tabHost.setup();
-	        tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
+            tabHost.setup();
+            tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
 
-	        tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
-	        tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
-	        tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistContainer));
-	        
-	        if (icicle != null) {
-	            tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
-	        }
+            tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
+            tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
+            tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistContainer));
+
+            if (icicle != null) {
+                tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
+            }
         }
     }
-    
+
     @Override
     protected void onSaveInstanceState(Bundle icicle) {
         super.onSaveInstanceState(icicle);
         if(tabHost != null) {
-        	icicle.putString("currentTab", tabHost.getCurrentTabTag());
+            icicle.putString("currentTab", tabHost.getCurrentTabTag());
         }
     }
-    
-	public void onTeamAddDialogSubmitted(Team newTeam) {
-		stateManager.requestAddTeam(newTeam, TeamInGame.getUnusedOrRandomColorIndex(stateManager.getTeams().values()));
-	}
-	
-	public RoomStateManager getRoomStateManager() {
-		return stateManager;
-	}
+
+    public void onTeamAddDialogSubmitted(Team newTeam) {
+        stateManager.requestAddTeam(newTeam, TeamInGame.getUnusedOrRandomColorIndex(stateManager.getTeams().values()));
+    }
+
+    public RoomStateManager getRoomStateManager() {
+        return stateManager;
+    }
 
-	private final OnClickListener startButtonClickListener = new OnClickListener() {
-		public void onClick(View v) {
-			Map<String, TeamInGame> teams = stateManager.getTeams();
-			Set<Integer> clanColors = new TreeSet<Integer>();
-			for(TeamInGame t : teams.values()) {
-				clanColors.add(t.ingameAttribs.colorIndex);
-			}
-			if(clanColors.size()<2) {
-				if(tabHost != null) {
-					tabHost.setCurrentTabByTag("teams");
-				}
-				int errortext = teams.size()<2 ? R.string.not_enough_teams : R.string.not_enough_clans;
-				Toast.makeText(getApplicationContext(), errortext, Toast.LENGTH_SHORT).show();
-				return;
-			}
-			
-			SDLActivity.startNetgame = false;
-			SDLActivity.startConfig = new GameConfig(
-					stateManager.getGameStyle(),
-					stateManager.getScheme(),
-					stateManager.getMapRecipe(),
-					new ArrayList<TeamInGame>(stateManager.getTeams().values()),
-					stateManager.getWeaponset());
-			startActivity(new Intent(LocalRoomActivity.this, SDLActivity.class));
-		}
-	};
+    private final OnClickListener startButtonClickListener = new OnClickListener() {
+        public void onClick(View v) {
+            Map<String, TeamInGame> teams = stateManager.getTeams();
+            Set<Integer> clanColors = new TreeSet<Integer>();
+            for(TeamInGame t : teams.values()) {
+                clanColors.add(t.ingameAttribs.colorIndex);
+            }
+            if(clanColors.size()<2) {
+                if(tabHost != null) {
+                    tabHost.setCurrentTabByTag("teams");
+                }
+                int errortext = teams.size()<2 ? R.string.not_enough_teams : R.string.not_enough_clans;
+                Toast.makeText(getApplicationContext(), errortext, Toast.LENGTH_SHORT).show();
+                return;
+            }
+
+            SDLActivity.startNetgame = false;
+            SDLActivity.startConfig = new GameConfig(
+                    stateManager.getGameStyle(),
+                    stateManager.getScheme(),
+                    stateManager.getMapRecipe(),
+                    new ArrayList<TeamInGame>(stateManager.getTeams().values()),
+                    stateManager.getWeaponset());
+            startActivity(new Intent(LocalRoomActivity.this, SDLActivity.class));
+        }
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomStateManager.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomStateManager.java	Tue Jan 21 22:53:15 2014 +0100
@@ -35,80 +35,80 @@
  * state.
  */
 public class LocalRoomStateManager extends BasicRoomState {
-	private static final String TAG = LocalRoomStateManager.class.getSimpleName(); 
+    private static final String TAG = LocalRoomStateManager.class.getSimpleName();
 
-	public LocalRoomStateManager(Scheme defaultScheme, Weaponset defaultWeaponset) {
-		setChief(true);
-		setGameStyle(GameConfig.DEFAULT_STYLE);
-		setMapRecipe(MapRecipe.makeRandomMap(0, MapRecipe.makeRandomSeed(), GameConfig.DEFAULT_THEME));
-		setScheme(defaultScheme);
-		setWeaponset(defaultWeaponset);
-	}
-	
-	public void changeMapRecipe(MapRecipe map) {
-		setMapRecipe(map);
-	}
+    public LocalRoomStateManager(Scheme defaultScheme, Weaponset defaultWeaponset) {
+        setChief(true);
+        setGameStyle(GameConfig.DEFAULT_STYLE);
+        setMapRecipe(MapRecipe.makeRandomMap(0, MapRecipe.makeRandomSeed(), GameConfig.DEFAULT_THEME));
+        setScheme(defaultScheme);
+        setWeaponset(defaultWeaponset);
+    }
 
-	public void changeMapTheme(String theme) {
-		setMapRecipe(getMapRecipe().withTheme(theme));
-	}
+    public void changeMapRecipe(MapRecipe map) {
+        setMapRecipe(map);
+    }
+
+    public void changeMapTheme(String theme) {
+        setMapRecipe(getMapRecipe().withTheme(theme));
+    }
 
-	public void changeMapNameAndGenerator(String mapName) {
-		int newGenerator = MapRecipe.generatorForMapname(mapName);
-		setMapRecipe(getMapRecipe().withName(mapName).withMapgen(newGenerator));
-	}
+    public void changeMapNameAndGenerator(String mapName) {
+        int newGenerator = MapRecipe.generatorForMapname(mapName);
+        setMapRecipe(getMapRecipe().withName(mapName).withMapgen(newGenerator));
+    }
 
-	public void changeMapTemplate(int template) {
-		setMapRecipe(getMapRecipe().withTemplateFilter(template));
-	}
+    public void changeMapTemplate(int template) {
+        setMapRecipe(getMapRecipe().withTemplateFilter(template));
+    }
 
-	public void changeMazeSize(int mazeSize) {
-		setMapRecipe(getMapRecipe().withMazeSize(mazeSize));
-	}
+    public void changeMazeSize(int mazeSize) {
+        setMapRecipe(getMapRecipe().withMazeSize(mazeSize));
+    }
 
-	public void changeMapSeed(String seed) {
-		setMapRecipe(getMapRecipe().withSeed(seed));
-	}
+    public void changeMapSeed(String seed) {
+        setMapRecipe(getMapRecipe().withSeed(seed));
+    }
 
-	public void changeMapDrawdata(byte[] drawdata) {
-		setMapRecipe(getMapRecipe().withDrawData(drawdata));
-	}
+    public void changeMapDrawdata(byte[] drawdata) {
+        setMapRecipe(getMapRecipe().withDrawData(drawdata));
+    }
 
-	public void changeScheme(Scheme scheme) {
-		setScheme(scheme);
-	}
+    public void changeScheme(Scheme scheme) {
+        setScheme(scheme);
+    }
 
-	public void changeGameStyle(String style) {
-		setGameStyle(style);
-	}
+    public void changeGameStyle(String style) {
+        setGameStyle(style);
+    }
 
-	public void changeWeaponset(Weaponset weaponset) {
-		setWeaponset(weaponset);
-	}
+    public void changeWeaponset(Weaponset weaponset) {
+        setWeaponset(weaponset);
+    }
 
-	public void requestAddTeam(Team team, int colorIndex) {
-		putTeam(new TeamInGame(team, new TeamIngameAttributes("Player", colorIndex, TeamIngameAttributes.DEFAULT_HOG_COUNT, false)));
-	}
+    public void requestAddTeam(Team team, int colorIndex) {
+        putTeam(new TeamInGame(team, new TeamIngameAttributes("Player", colorIndex, TeamIngameAttributes.DEFAULT_HOG_COUNT, false)));
+    }
 
-	public void requestRemoveTeam(String teamname) {
-		removeTeam(teamname);
-	}
+    public void requestRemoveTeam(String teamname) {
+        removeTeam(teamname);
+    }
 
-	public void changeTeamColorIndex(String teamname, int colorIndex) {
-		TeamInGame oldTeam = getTeams().get(teamname);
-		if(oldTeam != null) {
-			putTeam(oldTeam.withAttribs(oldTeam.ingameAttribs.withColorIndex(colorIndex)));
-		} else {
-			Log.e(TAG, "Requested color change for unknown team "+ teamname);
-		}
-	}
+    public void changeTeamColorIndex(String teamname, int colorIndex) {
+        TeamInGame oldTeam = getTeams().get(teamname);
+        if(oldTeam != null) {
+            putTeam(oldTeam.withAttribs(oldTeam.ingameAttribs.withColorIndex(colorIndex)));
+        } else {
+            Log.e(TAG, "Requested color change for unknown team "+ teamname);
+        }
+    }
 
-	public void changeTeamHogCount(String teamname, int hogcount) {
-		TeamInGame oldTeam = getTeams().get(teamname);
-		if(oldTeam != null) {
-			putTeam(oldTeam.withAttribs(oldTeam.ingameAttribs.withHogCount(hogcount)));
-		} else {
-			Log.e(TAG, "Requested hog count change for unknown team "+ teamname);
-		}
-	}
+    public void changeTeamHogCount(String teamname, int hogcount) {
+        TeamInGame oldTeam = getTeams().get(teamname);
+        if(oldTeam != null) {
+            putTeam(oldTeam.withAttribs(oldTeam.ingameAttribs.withHogCount(hogcount)));
+        } else {
+            Log.e(TAG, "Requested hog count change for unknown team "+ teamname);
+        }
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -49,175 +49,175 @@
 import android.widget.Toast;
 
 public class MainActivity extends FragmentActivity {
-	private static final int DIALOG_NO_SDCARD = 0;
-	
-	private LocalBroadcastManager broadcastManager;
-	private ProgressDialog assetsDialog;
+    private static final int DIALOG_NO_SDCARD = 0;
+
+    private LocalBroadcastManager broadcastManager;
+    private ProgressDialog assetsDialog;
+
+    public void onCreate(Bundle sis){
+        super.onCreate(sis);
+        setContentView(R.layout.activity_main);
+
+        broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
+        Button startLocalGame = (Button)findViewById(R.id.startGame);
+        Button startNetGame = (Button)findViewById(R.id.joinLobby);
+
+        startLocalGame.setOnClickListener(startGameListener);
+        startNetGame.setOnClickListener(startNetGameListener);
 
-	public void onCreate(Bundle sis){
-		super.onCreate(sis);
-		setContentView(R.layout.activity_main);
+        if(!FileUtils.isDataPathAvailable()){
+            showDialog(DIALOG_NO_SDCARD);
+        } else {
+            String existingVersion = "";
+            try {
+                File versionFile = new File(FileUtils.getCachePath(this), "assetsversion.txt");
+                existingVersion = FileUtils.readToString(new FileInputStream(versionFile));
+            } catch(IOException e) {
+            }
 
-		broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
-		Button startLocalGame = (Button)findViewById(R.id.startGame);
-		Button startNetGame = (Button)findViewById(R.id.joinLobby);
-
-		startLocalGame.setOnClickListener(startGameListener);
-		startNetGame.setOnClickListener(startNetGameListener);
+            String newVersion = "";
+            try {
+                newVersion = FileUtils.readToString(getAssets().open("assetsversion.txt"));
+            } catch(IOException e) {
+            }
 
-		if(!FileUtils.isDataPathAvailable()){
-			showDialog(DIALOG_NO_SDCARD);
-		} else {
-			String existingVersion = "";
-			try {
-				File versionFile = new File(FileUtils.getCachePath(this), "assetsversion.txt");
-				existingVersion = FileUtils.readToString(new FileInputStream(versionFile));
-			} catch(IOException e) {
-			}
-			
-			String newVersion = "";
-			try {
-				newVersion = FileUtils.readToString(getAssets().open("assetsversion.txt"));
-			} catch(IOException e) {
-			}
-			
-			if(!existingVersion.equals(newVersion)) {
-				DownloadAssets assetsAsyncTask = new DownloadAssets(this);
-				assetsDialog = ProgressDialog.show(this, "Please wait a moment", "Moving assets to SD card...");
-				assetsAsyncTask.execute();
-			}
-		}
-	}
+            if(!existingVersion.equals(newVersion)) {
+                DownloadAssets assetsAsyncTask = new DownloadAssets(this);
+                assetsDialog = ProgressDialog.show(this, "Please wait a moment", "Moving assets to SD card...");
+                assetsAsyncTask.execute();
+            }
+        }
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        broadcastManager.registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
+        broadcastManager.registerReceiver(connectionFailedReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
+        broadcastManager.registerReceiver(passwordRequestedReceiver, new IntentFilter(Netplay.ACTION_PASSWORD_REQUESTED));
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        broadcastManager.unregisterReceiver(connectedReceiver);
+        broadcastManager.unregisterReceiver(connectionFailedReceiver);
+        broadcastManager.unregisterReceiver(passwordRequestedReceiver);
+        Netplay netplay = Netplay.getAppInstance(getApplicationContext());
+        if(netplay.getState() == State.CONNECTING) {
+            netplay.disconnect();
+        }
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        super.onCreateOptionsMenu(menu);
+        getMenuInflater().inflate(R.menu.main_options, menu);
+        return true;
+    }
 
-	@Override
-	protected void onResume() {
-		super.onResume();
-		broadcastManager.registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
-		broadcastManager.registerReceiver(connectionFailedReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
-		broadcastManager.registerReceiver(passwordRequestedReceiver, new IntentFilter(Netplay.ACTION_PASSWORD_REQUESTED));
-	}
-	
-	@Override
-	protected void onPause() {
-		super.onPause();
-		broadcastManager.unregisterReceiver(connectedReceiver);
-		broadcastManager.unregisterReceiver(connectionFailedReceiver);
-		broadcastManager.unregisterReceiver(passwordRequestedReceiver);
-		Netplay netplay = Netplay.getAppInstance(getApplicationContext());
-		if(netplay.getState() == State.CONNECTING) {
-			netplay.disconnect();
-		}
-	}
-	
-	@Override
-	public boolean onCreateOptionsMenu(Menu menu) {
-		super.onCreateOptionsMenu(menu);
-		getMenuInflater().inflate(R.menu.main_options, menu);
-		return true;
-	}
-	
-	@Override
-	public boolean onOptionsItemSelected(MenuItem item) {
-		switch(item.getItemId()) {
-		case R.id.download:
-			startActivityForResult(new Intent(this, DownloadListActivity.class), 0);
-			return true;
-		case R.id.preferences:
-			Toast.makeText(this, R.string.not_implemented_yet, Toast.LENGTH_SHORT).show();
-			return true;
-		case R.id.edit_weaponsets:
-			startActivity(new Intent(this, WeaponsetListActivity.class));
-			return true;
-		case R.id.edit_teams:
-			startActivity(new Intent(this, TeamListActivity.class));
-			return true;
-		default:
-			return super.onOptionsItemSelected(item);
-		}
-	}
-	
-	public Dialog onCreateDialog(int id, Bundle args){
-		switch(id) {
-		case DIALOG_NO_SDCARD:
-			return createNoSdcardDialog();
-		default:
-			throw new IndexOutOfBoundsException();
-		}
-	}
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch(item.getItemId()) {
+        case R.id.download:
+            startActivityForResult(new Intent(this, DownloadListActivity.class), 0);
+            return true;
+        case R.id.preferences:
+            Toast.makeText(this, R.string.not_implemented_yet, Toast.LENGTH_SHORT).show();
+            return true;
+        case R.id.edit_weaponsets:
+            startActivity(new Intent(this, WeaponsetListActivity.class));
+            return true;
+        case R.id.edit_teams:
+            startActivity(new Intent(this, TeamListActivity.class));
+            return true;
+        default:
+            return super.onOptionsItemSelected(item);
+        }
+    }
+
+    public Dialog onCreateDialog(int id, Bundle args){
+        switch(id) {
+        case DIALOG_NO_SDCARD:
+            return createNoSdcardDialog();
+        default:
+            throw new IndexOutOfBoundsException();
+        }
+    }
+
+    private Dialog createNoSdcardDialog() {
+        AlertDialog.Builder builder = new AlertDialog.Builder(this);
+        builder.setTitle(R.string.sdcard_not_mounted_title);
+        builder.setMessage(R.string.sdcard_not_mounted);
+        builder.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener(){
+            public void onClick(DialogInterface dialog, int which) {
+                finish();
+            }
+        });
+
+        return builder.create();
+    }
+
+    public void onAssetsDownloaded(boolean result){
+        if(!result){
+            Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG).show();
+        }
+        assetsDialog.dismiss();
+    }
 
-	private Dialog createNoSdcardDialog() {
-		AlertDialog.Builder builder = new AlertDialog.Builder(this);
-		builder.setTitle(R.string.sdcard_not_mounted_title);
-		builder.setMessage(R.string.sdcard_not_mounted);
-		builder.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener(){
-			public void onClick(DialogInterface dialog, int which) {
-				finish();				
-			}
-		});
+    private final OnClickListener startGameListener = new OnClickListener(){
+        public void onClick(View v){
+            startActivity(new Intent(getApplicationContext(), LocalRoomActivity.class));
+        }
+    };
 
-		return builder.create();
-	}
-	
-	public void onAssetsDownloaded(boolean result){
-		if(!result){
-			Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG).show();
-		}
-		assetsDialog.dismiss();
-	}
+    private final OnClickListener startNetGameListener = new OnClickListener() {
+        public void onClick(View v) {
+            State state = Netplay.getAppInstance(getApplicationContext()).getState();
+            switch(state) {
+            case NOT_CONNECTED:
+                FragmentManager fm = getSupportFragmentManager();
+                StartNetgameDialog startNetgameDialog = new StartNetgameDialog();
+                startNetgameDialog.show(fm, "start_netgame_dialog");
+                break;
+            case CONNECTING:
+                onNetConnectingStarted();
+                break;
+            default:
+                startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
+                break;
+            }
+        }
+    };
 
-	private final OnClickListener startGameListener = new OnClickListener(){
-		public void onClick(View v){
-			startActivity(new Intent(getApplicationContext(), LocalRoomActivity.class));
-		}
-	};
-	
-	private final OnClickListener startNetGameListener = new OnClickListener() {
-		public void onClick(View v) {
-			State state = Netplay.getAppInstance(getApplicationContext()).getState();
-			switch(state) {
-			case NOT_CONNECTED:
-		        FragmentManager fm = getSupportFragmentManager();
-		        StartNetgameDialog startNetgameDialog = new StartNetgameDialog();
-		        startNetgameDialog.show(fm, "start_netgame_dialog");
-				break;
-			case CONNECTING:
-				onNetConnectingStarted();
-				break;
-			default:
-				startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
-				break;
-			}
-		}
-	};
-	
-	private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
-		}
-	};
-	
-	private BroadcastReceiver connectionFailedReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) {
-				Toast.makeText(getApplicationContext(), intent.getStringExtra(Netplay.EXTRA_MESSAGE), Toast.LENGTH_LONG).show();
-			}
-		}
-	};
-	
-	private BroadcastReceiver passwordRequestedReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-	        FragmentManager fm = getSupportFragmentManager();
-	        PasswordDialog passwordDialog = new PasswordDialog(intent.getStringExtra(Netplay.EXTRA_PLAYERNAME));
-	        passwordDialog.show(fm, "fragment_password_dialog");
-		}
-	};
+    private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
+        }
+    };
 
-	public void onNetConnectingStarted() {
+    private BroadcastReceiver connectionFailedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) {
+                Toast.makeText(getApplicationContext(), intent.getStringExtra(Netplay.EXTRA_MESSAGE), Toast.LENGTH_LONG).show();
+            }
+        }
+    };
+
+    private BroadcastReceiver passwordRequestedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            FragmentManager fm = getSupportFragmentManager();
+            PasswordDialog passwordDialog = new PasswordDialog(intent.getStringExtra(Netplay.EXTRA_PLAYERNAME));
+            passwordDialog.show(fm, "fragment_password_dialog");
+        }
+    };
+
+    public void onNetConnectingStarted() {
         FragmentManager fm = getSupportFragmentManager();
         ConnectingDialog connectingDialog = new ConnectingDialog();
         connectingDialog.show(fm, "fragment_connecting_dialog");
-	}
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MapFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MapFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -50,225 +50,225 @@
 
 /**
  * Display a map preview, and configuration options for the map.
- * 
+ *
  * Mostly for layout reasons, this does not include the theme setting, which
  * (arguably) is more a map setting than a general game setting.
  */
 public class MapFragment extends Fragment {
-	private Spinner mapTypeSpinner, mapNameSpinner, templateSpinner, mazeSizeSpinner;
-	private TableRow nameRow, templateRow, mazeSizeRow;
-	private ImageView mapPreview;
-	
-	private List<MapFile> mapFiles;
-	private RoomStateManager stateManager;
-	private Random random = new Random();
-	private CalmDownHandler mapPreviewHandler;
-	
-	/*
-	 * Rendering the preview can take a few seconds on Android, so we want to prevent preview
-	 * requests from queueing up if maps are changed quickly. So if there is already a preview
-	 * being generated, we store our latest request in the newPreviewRequest variable instead.
-	 * Once the current preview is finished generating it will start on that one.
-	 */
-	private boolean previewGenerationInProgress;
-	private MapRecipe newPreviewRequest;
-	private MapRecipe currentMap; // kept for reference on every change to find out what changed
-	
-	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-		View v = inflater.inflate(R.layout.fragment_map, container, false);
-		final Context appContext = getActivity().getApplicationContext();
+    private Spinner mapTypeSpinner, mapNameSpinner, templateSpinner, mazeSizeSpinner;
+    private TableRow nameRow, templateRow, mazeSizeRow;
+    private ImageView mapPreview;
+
+    private List<MapFile> mapFiles;
+    private RoomStateManager stateManager;
+    private Random random = new Random();
+    private CalmDownHandler mapPreviewHandler;
+
+    /*
+     * Rendering the preview can take a few seconds on Android, so we want to prevent preview
+     * requests from queueing up if maps are changed quickly. So if there is already a preview
+     * being generated, we store our latest request in the newPreviewRequest variable instead.
+     * Once the current preview is finished generating it will start on that one.
+     */
+    private boolean previewGenerationInProgress;
+    private MapRecipe newPreviewRequest;
+    private MapRecipe currentMap; // kept for reference on every change to find out what changed
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        View v = inflater.inflate(R.layout.fragment_map, container, false);
+        final Context appContext = getActivity().getApplicationContext();
+
+        /*
+         * This handler will start the map preview after none of the map settings
+         * have been updated for a short time.
+         */
+        mapPreviewHandler = new CalmDownHandler(getActivity().getMainLooper(), new Runnable() {
+            public void run() {
+                if(!previewGenerationInProgress) {
+                    mapPreview.setImageResource(R.drawable.roomlist_preparing);
+                    MapPreviewGenerator.startPreviewGeneration(appContext, stateManager.getMapRecipe(), mapPreviewListener);
+                    previewGenerationInProgress = true;
+                } else {
+                    newPreviewRequest = stateManager.getMapRecipe();
+                }
+            }
+        }, 250);
+
+        nameRow = (TableRow) v.findViewById(R.id.rowMapName);
+        templateRow = (TableRow) v.findViewById(R.id.rowTemplateFilter);
+        mazeSizeRow = (TableRow) v.findViewById(R.id.rowMazeSize);
+        mapPreview = (ImageView) v.findViewById(R.id.mapPreview);
+        mapPreview.setImageDrawable(null);;
+        mapPreview.setOnClickListener(mapClickListener);
 
-		/*
-		 * This handler will start the map preview after none of the map settings
-		 * have been updated for a short time.
-		 */
-		mapPreviewHandler = new CalmDownHandler(getActivity().getMainLooper(), new Runnable() {
-			public void run() {
-				if(!previewGenerationInProgress) {
-					mapPreview.setImageResource(R.drawable.roomlist_preparing);
-					MapPreviewGenerator.startPreviewGeneration(appContext, stateManager.getMapRecipe(), mapPreviewListener);
-					previewGenerationInProgress = true;
-				} else {
-					newPreviewRequest = stateManager.getMapRecipe();
-				}
-			}
-		}, 250);
-		
-		nameRow = (TableRow) v.findViewById(R.id.rowMapName);
-		templateRow = (TableRow) v.findViewById(R.id.rowTemplateFilter);
-		mazeSizeRow = (TableRow) v.findViewById(R.id.rowMazeSize);
-		mapPreview = (ImageView) v.findViewById(R.id.mapPreview);
-		mapPreview.setImageDrawable(null);;
-		mapPreview.setOnClickListener(mapClickListener);
-		
-		try {
-			mapFiles = FrontendDataUtils.getMaps(getActivity());
-		} catch (IOException e) {
-			Toast.makeText(getActivity().getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
-			getActivity().finish();
-			return null;
-		}
-		Collections.sort(mapFiles, MapFile.MISSIONS_FIRST_NAME_ORDER);
-		
-		List<String> mapNames = MapFile.toDisplayNameList(mapFiles, getResources());
-		mapTypeSpinner = prepareSpinner(v, R.id.spinMapType, Arrays.asList(getResources().getStringArray(R.array.map_types)), mapTypeSelectedListener);
-		mapNameSpinner = prepareSpinner(v, R.id.spinMapName, mapNames, mapNameSelectedListener);
-		templateSpinner = prepareSpinner(v, R.id.spinTemplateFilter, Arrays.asList(getResources().getStringArray(R.array.map_templates)), mapTemplateSelectedListener);
-		mazeSizeSpinner = prepareSpinner(v, R.id.spinMazeSize, Arrays.asList(getResources().getStringArray(R.array.map_maze_sizes)), mazeSizeSelectedListener);
+        try {
+            mapFiles = FrontendDataUtils.getMaps(getActivity());
+        } catch (IOException e) {
+            Toast.makeText(getActivity().getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
+            getActivity().finish();
+            return null;
+        }
+        Collections.sort(mapFiles, MapFile.MISSIONS_FIRST_NAME_ORDER);
+
+        List<String> mapNames = MapFile.toDisplayNameList(mapFiles, getResources());
+        mapTypeSpinner = prepareSpinner(v, R.id.spinMapType, Arrays.asList(getResources().getStringArray(R.array.map_types)), mapTypeSelectedListener);
+        mapNameSpinner = prepareSpinner(v, R.id.spinMapName, mapNames, mapNameSelectedListener);
+        templateSpinner = prepareSpinner(v, R.id.spinTemplateFilter, Arrays.asList(getResources().getStringArray(R.array.map_templates)), mapTemplateSelectedListener);
+        mazeSizeSpinner = prepareSpinner(v, R.id.spinMazeSize, Arrays.asList(getResources().getStringArray(R.array.map_maze_sizes)), mazeSizeSelectedListener);
+
+        stateManager.addListener(roomStateChangeListener);
+        currentMap = stateManager.getMapRecipe();
+        if(currentMap != null) {
+            updateDisplay(currentMap);
+        }
+        setChiefState(stateManager.getChiefStatus());
+        mapPreviewHandler.activity();
+        return v;
+    }
+
+    private static Spinner prepareSpinner(View v, int id, List<String> items, OnItemSelectedListener itemSelectedListener) {
+        Spinner spinner = (Spinner)v.findViewById(id);
+        ArrayAdapter<String> adapter = new ArrayAdapter<String>(v.getContext(), R.layout.listview_item, items);
+        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        spinner.setAdapter(adapter);
+        spinner.setOnItemSelectedListener(itemSelectedListener);
+        return spinner;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        try {
+            stateManager = ((RoomStateManager.Provider)getActivity()).getRoomStateManager();
+        } catch(ClassCastException e) {
+            throw new RuntimeException("Hosting activity must implement RoomStateManager.Provider.", e);
+        }
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        mapPreviewHandler.stop();
+        newPreviewRequest = null;
+
+        stateManager.removeListener(roomStateChangeListener);
+    }
+
+    private void setChiefState(boolean chiefState) {
+        mapTypeSpinner.setEnabled(chiefState);
+        mapNameSpinner.setEnabled(chiefState);
+        templateSpinner.setEnabled(chiefState);
+        mazeSizeSpinner.setEnabled(chiefState);
+        mapPreview.setEnabled(chiefState);
 
-		stateManager.addListener(roomStateChangeListener);
-		currentMap = stateManager.getMapRecipe();
-		if(currentMap != null) {
-			updateDisplay(currentMap);
-		}
-		setChiefState(stateManager.getChiefStatus());
-		mapPreviewHandler.activity();
-		return v;
-	}
-	
-	private static Spinner prepareSpinner(View v, int id, List<String> items, OnItemSelectedListener itemSelectedListener) {
-		Spinner spinner = (Spinner)v.findViewById(id);
-		ArrayAdapter<String> adapter = new ArrayAdapter<String>(v.getContext(), R.layout.listview_item, items);
-		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-		spinner.setAdapter(adapter);
-		spinner.setOnItemSelectedListener(itemSelectedListener);
-		return spinner;
-	}
-	
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		try {
-			stateManager = ((RoomStateManager.Provider)getActivity()).getRoomStateManager();
-		} catch(ClassCastException e) {
-			throw new RuntimeException("Hosting activity must implement RoomStateManager.Provider.", e);
-		}
-	}
-	
-	@Override
-	public void onDestroy() {
-		super.onDestroy();
-		mapPreviewHandler.stop();
-		newPreviewRequest = null;
-		
-		stateManager.removeListener(roomStateChangeListener);
-	}
-	
-	private void setChiefState(boolean chiefState) {
-		mapTypeSpinner.setEnabled(chiefState);
-		mapNameSpinner.setEnabled(chiefState);
-		templateSpinner.setEnabled(chiefState);
-		mazeSizeSpinner.setEnabled(chiefState);
-		mapPreview.setEnabled(chiefState);
-		
-		if(chiefState) {
-			sendMapnameAndGenerator();
-			stateManager.changeMapTemplate(templateSpinner.getSelectedItemPosition());
-			stateManager.changeMazeSize(mazeSizeSpinner.getSelectedItemPosition());
-		}
-	}
-	
-	private void updateDisplay(MapRecipe map) {
-		nameRow.setVisibility(map.mapgen == Frontlib.MAPGEN_NAMED ? View.VISIBLE : View.GONE);
-		templateRow.setVisibility(map.mapgen == Frontlib.MAPGEN_REGULAR ? View.VISIBLE : View.GONE);
-		mazeSizeRow.setVisibility(map.mapgen == Frontlib.MAPGEN_MAZE ? View.VISIBLE : View.GONE);
-		
-		mapTypeSpinner.setSelection(map.mapgen);
-		int mapPosition = findMapPosition(mapFiles, map.name);
-		if(mapPosition >= 0) {
-			mapNameSpinner.setSelection(mapPosition);
-		}
-		templateSpinner.setSelection(map.templateFilter);
-		mazeSizeSpinner.setSelection(map.mazeSize);
-	}
-	
-	private static int findMapPosition(List<MapFile> mapFiles, String mapName) {
-		for(int i=0; i<mapFiles.size(); i++) {
-			if(mapName.equals(mapFiles.get(i).name)) {
-				return i;
-			}
-		}
-		return -1;
-	}
-	
-	private void sendMapnameAndGenerator() {
-		int mapType = mapTypeSpinner.getSelectedItemPosition();
-		String mapName = mapFiles.get(mapNameSpinner.getSelectedItemPosition()).name;
-		stateManager.changeMapNameAndGenerator(MapRecipe.mapnameForGenerator(mapType, mapName));
-	}
-	
-	private final OnItemSelectedListener mapTypeSelectedListener = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
-			sendMapnameAndGenerator();
-		}
-		public void onNothingSelected(AdapterView<?> arg0) {}
-	};
-	
-	private final OnItemSelectedListener mapNameSelectedListener = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
-			sendMapnameAndGenerator();
-		}
-		public void onNothingSelected(AdapterView<?> arg0) {}
-	};
-	
-	private final OnItemSelectedListener mapTemplateSelectedListener = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
-			stateManager.changeMapTemplate(position);
-		}
-		public void onNothingSelected(AdapterView<?> arg0) {}
-	};
-	
-	private final OnItemSelectedListener mazeSizeSelectedListener = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
-			stateManager.changeMazeSize(position);
-		}
-		public void onNothingSelected(AdapterView<?> arg0) {}
-	};
-	
-	private final OnClickListener mapClickListener = new OnClickListener() {
-		public void onClick(View v) {
-			stateManager.changeMapSeed(MapRecipe.makeRandomSeed());
-			if(mapTypeSpinner.getSelectedItemPosition() == Frontlib.MAPGEN_NAMED) {
-				mapNameSpinner.setSelection(random.nextInt(mapNameSpinner.getCount()));
-			}
-		}
-	};
-	
-	private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.ListenerAdapter() {
-		@Override
-		public void onChiefStatusChanged(boolean isChief) {
-			setChiefState(isChief);
-		};
-		
-		@Override
-		public void onMapChanged(MapRecipe recipe) {
-			// Only trigger a preview update if a relevant field changed (not theme)
-			if(currentMap==null
-					|| currentMap.mapgen != recipe.mapgen
-					|| currentMap.mazeSize != recipe.mazeSize
-					|| !currentMap.name.equals(recipe.name)
-					|| !currentMap.seed.equals(recipe.seed)
-					|| currentMap.templateFilter != recipe.templateFilter
-					|| !Arrays.equals(currentMap.getDrawData(), recipe.getDrawData())) {
-				mapPreviewHandler.activity();
-			}
-			updateDisplay(recipe);
-			currentMap = recipe;
-		};
-	};
-	
-	private MapPreviewGenerator.Listener mapPreviewListener = new MapPreviewGenerator.Listener() {
-		public void onMapPreviewResult(Drawable preview) {
-			if(newPreviewRequest != null) {
-				MapPreviewGenerator.startPreviewGeneration(getActivity().getApplicationContext(), newPreviewRequest, mapPreviewListener);
-				newPreviewRequest = null;
-			} else {
-				if(mapPreview != null) {
-					mapPreview.setImageDrawable(preview);
-				}
-				previewGenerationInProgress = false;
-			}
-		}
-	};
+        if(chiefState) {
+            sendMapnameAndGenerator();
+            stateManager.changeMapTemplate(templateSpinner.getSelectedItemPosition());
+            stateManager.changeMazeSize(mazeSizeSpinner.getSelectedItemPosition());
+        }
+    }
+
+    private void updateDisplay(MapRecipe map) {
+        nameRow.setVisibility(map.mapgen == Frontlib.MAPGEN_NAMED ? View.VISIBLE : View.GONE);
+        templateRow.setVisibility(map.mapgen == Frontlib.MAPGEN_REGULAR ? View.VISIBLE : View.GONE);
+        mazeSizeRow.setVisibility(map.mapgen == Frontlib.MAPGEN_MAZE ? View.VISIBLE : View.GONE);
+
+        mapTypeSpinner.setSelection(map.mapgen);
+        int mapPosition = findMapPosition(mapFiles, map.name);
+        if(mapPosition >= 0) {
+            mapNameSpinner.setSelection(mapPosition);
+        }
+        templateSpinner.setSelection(map.templateFilter);
+        mazeSizeSpinner.setSelection(map.mazeSize);
+    }
+
+    private static int findMapPosition(List<MapFile> mapFiles, String mapName) {
+        for(int i=0; i<mapFiles.size(); i++) {
+            if(mapName.equals(mapFiles.get(i).name)) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    private void sendMapnameAndGenerator() {
+        int mapType = mapTypeSpinner.getSelectedItemPosition();
+        String mapName = mapFiles.get(mapNameSpinner.getSelectedItemPosition()).name;
+        stateManager.changeMapNameAndGenerator(MapRecipe.mapnameForGenerator(mapType, mapName));
+    }
+
+    private final OnItemSelectedListener mapTypeSelectedListener = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
+            sendMapnameAndGenerator();
+        }
+        public void onNothingSelected(AdapterView<?> arg0) {}
+    };
+
+    private final OnItemSelectedListener mapNameSelectedListener = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
+            sendMapnameAndGenerator();
+        }
+        public void onNothingSelected(AdapterView<?> arg0) {}
+    };
+
+    private final OnItemSelectedListener mapTemplateSelectedListener = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
+            stateManager.changeMapTemplate(position);
+        }
+        public void onNothingSelected(AdapterView<?> arg0) {}
+    };
+
+    private final OnItemSelectedListener mazeSizeSelectedListener = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
+            stateManager.changeMazeSize(position);
+        }
+        public void onNothingSelected(AdapterView<?> arg0) {}
+    };
+
+    private final OnClickListener mapClickListener = new OnClickListener() {
+        public void onClick(View v) {
+            stateManager.changeMapSeed(MapRecipe.makeRandomSeed());
+            if(mapTypeSpinner.getSelectedItemPosition() == Frontlib.MAPGEN_NAMED) {
+                mapNameSpinner.setSelection(random.nextInt(mapNameSpinner.getCount()));
+            }
+        }
+    };
+
+    private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.ListenerAdapter() {
+        @Override
+        public void onChiefStatusChanged(boolean isChief) {
+            setChiefState(isChief);
+        };
+
+        @Override
+        public void onMapChanged(MapRecipe recipe) {
+            // Only trigger a preview update if a relevant field changed (not theme)
+            if(currentMap==null
+                    || currentMap.mapgen != recipe.mapgen
+                    || currentMap.mazeSize != recipe.mazeSize
+                    || !currentMap.name.equals(recipe.name)
+                    || !currentMap.seed.equals(recipe.seed)
+                    || currentMap.templateFilter != recipe.templateFilter
+                    || !Arrays.equals(currentMap.getDrawData(), recipe.getDrawData())) {
+                mapPreviewHandler.activity();
+            }
+            updateDisplay(recipe);
+            currentMap = recipe;
+        };
+    };
+
+    private MapPreviewGenerator.Listener mapPreviewListener = new MapPreviewGenerator.Listener() {
+        public void onMapPreviewResult(Drawable preview) {
+            if(newPreviewRequest != null) {
+                MapPreviewGenerator.startPreviewGeneration(getActivity().getApplicationContext(), newPreviewRequest, mapPreviewListener);
+                newPreviewRequest = null;
+            } else {
+                if(mapPreview != null) {
+                    mapPreview.setImageDrawable(preview);
+                }
+                previewGenerationInProgress = false;
+            }
+        }
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MapPreviewGenerator.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MapPreviewGenerator.java	Tue Jan 21 22:53:15 2014 +0100
@@ -48,176 +48,176 @@
 
 /**
  * A class that asynchronously generates a map preview from a MapRecipe.
- * 
+ *
  * For named maps, this will load the preview image from the filesystem. For others,
  * it will call the Hedgewars engine to generate a preview image. The result is sent
  * back to a listener on the UI thread.
  */
 public final class MapPreviewGenerator implements Runnable {
-	private static final String TAG = MapPreviewGenerator.class.getSimpleName();
-	private static final Handler mainHandler = new Handler(Looper.getMainLooper());
-	private static final long TIMEOUT_NS = 20l * 1000 * 1000 * 1000;
+    private static final String TAG = MapPreviewGenerator.class.getSimpleName();
+    private static final Handler mainHandler = new Handler(Looper.getMainLooper());
+    private static final long TIMEOUT_NS = 20l * 1000 * 1000 * 1000;
+
+    private final Context appContext;
+    private final MapRecipe map;
+    private final Listener listener;
+
+    private boolean resultAvailable;
+    private Drawable result;
+
+    public static interface Listener {
+        /**
+         * This is called on the UI thread once the preview is ready or failed.
+         * In case of failure, null is passed.
+         */
+        void onMapPreviewResult(Drawable preview);
+    }
+
+    private MapPreviewGenerator(Context appContext, MapRecipe map, Listener listener) {
+        this.appContext = appContext;
+        this.map = map;
+        this.listener = listener;
+    }
 
-	private final Context appContext;
-	private final MapRecipe map;
-	private final Listener listener;
-	
-	private boolean resultAvailable;
-	private Drawable result;
-	
-	public static interface Listener {
-		/**
-		 * This is called on the UI thread once the preview is ready or failed.
-		 * In case of failure, null is passed.
-		 */
-		void onMapPreviewResult(Drawable preview);
-	}
+    public void run() {
+        if (map.mapgen == Frontlib.MAPGEN_NAMED) {
+            postToListener(loadPreviewFromFile(appContext, map.name));
+        } else {
+            resultAvailable = false;
+            result = null;
+            MapconnPtr conn = Flib.INSTANCE.flib_mapconn_create(MapRecipePtr.createJavaOwned(map));
+            if (conn == null) {
+                postToListener(null);
+                return;
+            }
+            try {
+                int port = Flib.INSTANCE.flib_mapconn_getport(conn);
+                Flib.INSTANCE.flib_mapconn_onSuccess(conn, successCb, null);
+                Flib.INSTANCE.flib_mapconn_onFailure(conn, failureCb, null);
+
+                String configPath;
+                try {
+                    configPath = FileUtils.getCachePath(appContext).getAbsolutePath();
+                } catch(FileNotFoundException e) {
+                    return;
+                }
+
+                startEngine(configPath, port);
+                long startTime = System.nanoTime();
+                do {
+                    Flib.INSTANCE.flib_mapconn_tick(conn);
+                    try {
+                        Thread.sleep(50);
+                    } catch (InterruptedException e) {
+                        // ignore
+                    }
+                    if(System.nanoTime()-startTime > TIMEOUT_NS) {
+                        Log.w(TAG, "Error generating map preview: timeout");
+                        resultAvailable = true;
+                    }
+                } while(!resultAvailable);
+            } finally {
+                Flib.INSTANCE.flib_mapconn_destroy(conn);
+                postToListener(result);
+            }
+        }
+    }
+
+    public static void startPreviewGeneration(Context appContext, MapRecipe map, Listener listener) {
+        new Thread(new MapPreviewGenerator(appContext, map, listener)).start();
+    }
 
-	private MapPreviewGenerator(Context appContext, MapRecipe map, Listener listener) {
-		this.appContext = appContext;
-		this.map = map;
-		this.listener = listener;
-	}
-	
-	public void run() {
-		if (map.mapgen == Frontlib.MAPGEN_NAMED) {
-			postToListener(loadPreviewFromFile(appContext, map.name));
-		} else {
-			resultAvailable = false;
-			result = null;
-			MapconnPtr conn = Flib.INSTANCE.flib_mapconn_create(MapRecipePtr.createJavaOwned(map));
-			if (conn == null) {
-				postToListener(null);
-				return;
-			}
-			try {
-				int port = Flib.INSTANCE.flib_mapconn_getport(conn);
-				Flib.INSTANCE.flib_mapconn_onSuccess(conn, successCb, null);
-				Flib.INSTANCE.flib_mapconn_onFailure(conn, failureCb, null);
-	
-				String configPath;
-				try {
-					configPath = FileUtils.getCachePath(appContext).getAbsolutePath();
-				} catch(FileNotFoundException e) {
-					return;
-				}
-				
-				startEngine(configPath, port);
-				long startTime = System.nanoTime();
-				do {
-					Flib.INSTANCE.flib_mapconn_tick(conn);
-					try {
-						Thread.sleep(50);
-					} catch (InterruptedException e) {
-						// ignore
-					}
-					if(System.nanoTime()-startTime > TIMEOUT_NS) {
-						Log.w(TAG, "Error generating map preview: timeout");
-						resultAvailable = true;
-					}
-				} while(!resultAvailable); 
-			} finally {
-				Flib.INSTANCE.flib_mapconn_destroy(conn);
-				postToListener(result);
-			}
-		}
-	}
-	
-	public static void startPreviewGeneration(Context appContext, MapRecipe map, Listener listener) {
-		new Thread(new MapPreviewGenerator(appContext, map, listener)).start();
-	}
-	
-	private static Drawable loadPreviewFromFile(Context appContext, String mapName) {
-		if(!mapName.startsWith("+")) {
-			try {
-				File previewFile = MapFile.getPreviewFile(appContext, mapName);
-				return Drawable.createFromPath(previewFile.getAbsolutePath());
-			} catch (FileNotFoundException e) {
-				Log.w("MapPreviewGenerator", "Preview for map "+mapName+" not found.");
-			}
-		}
-		return null;
-	}
-	
-	private static void startEngine(final String configPath, final int port) {
-		new Thread(new Runnable() {
-			public void run() {
-				Log.d(TAG, "Starting engine "+port);
-				PascalExports.synchronizedGenLandPreview(port);
-				Log.d(TAG, "Engine finished");
-			}
-		}).start();
-	}
-	
-	private void postToListener(final Drawable result) {
-		mainHandler.post(new Runnable() {
-			public void run() {
-				listener.onMapPreviewResult(result);
-			}
-		});
-	}
-	
-	/**
-	 * Let's be extra nice here and clip off the left and right sides, so the preview is centered...
-	 * Since the image is present in bytes, we can save some effort by checking entire byte-columns first.
-	 */
-	private final MapimageCallback successCb = new MapimageCallback() {
-		public void callback(Pointer context, ByteArrayPtr buffer, int hedgehogCount) {
-			byte[] mapdata = buffer.deref(Frontlib.MAPIMAGE_BYTES);
-			
-			int leftmostPixel = Frontlib.MAPIMAGE_WIDTH;
-			int rightmostPixel = -1;
-			int bytesPerLine = Frontlib.MAPIMAGE_WIDTH/8;
-			
-			// Find the leftmost pixel
-			for(int xbyte=0; xbyte<bytesPerLine; xbyte++) {
-				for(int y=0; y<Frontlib.MAPIMAGE_HEIGHT; y++) {
-					int b = 0xff&mapdata[xbyte+y*bytesPerLine];
-					if(b != 0) {
-						leftmostPixel = Math.min(leftmostPixel, Integer.numberOfLeadingZeros(b)-24+xbyte*8);
-					}
-				}
-				if(leftmostPixel!=Frontlib.MAPIMAGE_WIDTH) break;
-			}
-			
-			// Find the rightmost pixel
-			for(int xbyte=bytesPerLine-1; xbyte>=0; xbyte--) {
-				for(int y=0; y<Frontlib.MAPIMAGE_HEIGHT; y++) {
-					int b = mapdata[xbyte+y*bytesPerLine];
-					if(b != 0) {
-						rightmostPixel = Math.max(rightmostPixel, xbyte*8+7-Integer.numberOfTrailingZeros(b));
-					}
-				}
-				if(rightmostPixel!=-1) break;
-			}
-		
-			// No pixel was set at all -> use default width
-			if(rightmostPixel==-1) {
-				leftmostPixel = 0;
-				rightmostPixel = Frontlib.MAPIMAGE_WIDTH-1;
-			}
-			
-			Bitmap bitmap = Bitmap.createBitmap(rightmostPixel-leftmostPixel+1, Frontlib.MAPIMAGE_HEIGHT, Config.ARGB_8888);
-			for(int y=0; y<Frontlib.MAPIMAGE_HEIGHT; y++) {
-				for(int x=0; x<bitmap.getWidth(); x++) {
-					bitmap.setPixel(x, y, isPixelSet(mapdata, x+leftmostPixel, y) ? Color.YELLOW : Color.TRANSPARENT);
-				}
-			}
-			result = new BitmapDrawable(bitmap);
-			resultAvailable = true;
-		}
-	};
-	
-	private static boolean isPixelSet(byte[] imgdata, int x, int y) {
-		int pixelnum = x+Frontlib.MAPIMAGE_WIDTH*y;
-		return (imgdata[pixelnum>>3] & (128>>(pixelnum&7))) != 0;
-	}
-	
-	private final StrCallback failureCb = new StrCallback() {
-		public void callback(Pointer context, String reason) {
-			Log.w(TAG, "Error generating map preview: "+reason);
-			result = null;
-			resultAvailable = true;
-		}
-	};
+    private static Drawable loadPreviewFromFile(Context appContext, String mapName) {
+        if(!mapName.startsWith("+")) {
+            try {
+                File previewFile = MapFile.getPreviewFile(appContext, mapName);
+                return Drawable.createFromPath(previewFile.getAbsolutePath());
+            } catch (FileNotFoundException e) {
+                Log.w("MapPreviewGenerator", "Preview for map "+mapName+" not found.");
+            }
+        }
+        return null;
+    }
+
+    private static void startEngine(final String configPath, final int port) {
+        new Thread(new Runnable() {
+            public void run() {
+                Log.d(TAG, "Starting engine "+port);
+                PascalExports.synchronizedGenLandPreview(port);
+                Log.d(TAG, "Engine finished");
+            }
+        }).start();
+    }
+
+    private void postToListener(final Drawable result) {
+        mainHandler.post(new Runnable() {
+            public void run() {
+                listener.onMapPreviewResult(result);
+            }
+        });
+    }
+
+    /**
+     * Let's be extra nice here and clip off the left and right sides, so the preview is centered...
+     * Since the image is present in bytes, we can save some effort by checking entire byte-columns first.
+     */
+    private final MapimageCallback successCb = new MapimageCallback() {
+        public void callback(Pointer context, ByteArrayPtr buffer, int hedgehogCount) {
+            byte[] mapdata = buffer.deref(Frontlib.MAPIMAGE_BYTES);
+
+            int leftmostPixel = Frontlib.MAPIMAGE_WIDTH;
+            int rightmostPixel = -1;
+            int bytesPerLine = Frontlib.MAPIMAGE_WIDTH/8;
+
+            // Find the leftmost pixel
+            for(int xbyte=0; xbyte<bytesPerLine; xbyte++) {
+                for(int y=0; y<Frontlib.MAPIMAGE_HEIGHT; y++) {
+                    int b = 0xff&mapdata[xbyte+y*bytesPerLine];
+                    if(b != 0) {
+                        leftmostPixel = Math.min(leftmostPixel, Integer.numberOfLeadingZeros(b)-24+xbyte*8);
+                    }
+                }
+                if(leftmostPixel!=Frontlib.MAPIMAGE_WIDTH) break;
+            }
+
+            // Find the rightmost pixel
+            for(int xbyte=bytesPerLine-1; xbyte>=0; xbyte--) {
+                for(int y=0; y<Frontlib.MAPIMAGE_HEIGHT; y++) {
+                    int b = mapdata[xbyte+y*bytesPerLine];
+                    if(b != 0) {
+                        rightmostPixel = Math.max(rightmostPixel, xbyte*8+7-Integer.numberOfTrailingZeros(b));
+                    }
+                }
+                if(rightmostPixel!=-1) break;
+            }
+
+            // No pixel was set at all -> use default width
+            if(rightmostPixel==-1) {
+                leftmostPixel = 0;
+                rightmostPixel = Frontlib.MAPIMAGE_WIDTH-1;
+            }
+
+            Bitmap bitmap = Bitmap.createBitmap(rightmostPixel-leftmostPixel+1, Frontlib.MAPIMAGE_HEIGHT, Config.ARGB_8888);
+            for(int y=0; y<Frontlib.MAPIMAGE_HEIGHT; y++) {
+                for(int x=0; x<bitmap.getWidth(); x++) {
+                    bitmap.setPixel(x, y, isPixelSet(mapdata, x+leftmostPixel, y) ? Color.YELLOW : Color.TRANSPARENT);
+                }
+            }
+            result = new BitmapDrawable(bitmap);
+            resultAvailable = true;
+        }
+    };
+
+    private static boolean isPixelSet(byte[] imgdata, int x, int y) {
+        int pixelnum = x+Frontlib.MAPIMAGE_WIDTH*y;
+        return (imgdata[pixelnum>>3] & (128>>(pixelnum&7))) != 0;
+    }
+
+    private final StrCallback failureCb = new StrCallback() {
+        public void callback(Pointer context, String reason) {
+            Log.w(TAG, "Error generating map preview: "+reason);
+            result = null;
+            resultAvailable = true;
+        }
+    };
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetRoomActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetRoomActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -43,11 +43,11 @@
  * This activity is used to set up and start a game on the server.
  */
 public class NetRoomActivity extends FragmentActivity implements NetplayStateListener, TeamAddDialog.Listener, RoomStateManager.Provider, RunGameListener {
-	private TabHost tabHost;
-	private Netplay netplay;
-	private RoomStateManager stateManager;
-	private Button startButton;
-	
+    private TabHost tabHost;
+    private Netplay netplay;
+    private RoomStateManager stateManager;
+    private Button startButton;
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -55,97 +55,97 @@
         netplay.registerRunGameListener(this);
         stateManager = netplay.getRoomStateManager();
         stateManager.addListener(roomStateChangeListener);
-        
+
         setContentView(R.layout.activity_netroom);
         startButton = (Button)findViewById(R.id.startGame);
-        
+
         ChatFragment chatFragment = (ChatFragment)getSupportFragmentManager().findFragmentById(R.id.chatFragment);
         chatFragment.setInRoom(true);
-        
+
         FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
         trans.add(new NetplayStateFragment(), "netplayFragment");
         trans.commit();
-        
+
         startButton.setVisibility(netplay.isChief() ? View.VISIBLE : View.GONE);
         startButton.setOnClickListener(startButtonClickListener);
-        
+
         // Set up a tabbed UI for medium and small screens
         tabHost = (TabHost)findViewById(android.R.id.tabhost);
         if(tabHost != null) {
-	        tabHost.setup();
-	        tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
+            tabHost.setup();
+            tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
 
-	        tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
-	        tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
-	        tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistFragment));
-	        tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_chat, 0)).setContent(R.id.chatFragment));
-	        tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_players, 0)).setContent(R.id.playerListContainer));
-	        
-	        if (icicle != null) {
-	            tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
-	        }
+            tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
+            tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
+            tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistFragment));
+            tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_chat, 0)).setContent(R.id.chatFragment));
+            tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_players, 0)).setContent(R.id.playerListContainer));
+
+            if (icicle != null) {
+                tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
+            }
         }
     }
 
     @Override
     protected void onDestroy() {
-    	super.onDestroy();
-    	stateManager.removeListener(roomStateChangeListener);
-    	netplay.unregisterRunGameListener(this);
+        super.onDestroy();
+        stateManager.removeListener(roomStateChangeListener);
+        netplay.unregisterRunGameListener(this);
     }
-    
-	@Override
-	public void onBackPressed() {
-		netplay.sendLeaveRoom(null);
-	}
-    
+
+    @Override
+    public void onBackPressed() {
+        netplay.sendLeaveRoom(null);
+    }
+
     @Override
     protected void onSaveInstanceState(Bundle icicle) {
         super.onSaveInstanceState(icicle);
         if(tabHost != null) {
-        	icicle.putString("currentTab", tabHost.getCurrentTabTag());
+            icicle.putString("currentTab", tabHost.getCurrentTabTag());
+        }
+    }
+
+    public void onNetplayStateChanged(State newState) {
+        switch(newState) {
+        case NOT_CONNECTED:
+        case CONNECTING:
+        case LOBBY:
+            finish();
+            break;
+        case ROOM:
+            // Do nothing
+            break;
+        default:
+            throw new IllegalStateException("Unknown connection state: "+newState);
         }
     }
-    
-    public void onNetplayStateChanged(State newState) {
-    	switch(newState) {
-    	case NOT_CONNECTED:
-    	case CONNECTING:
-    	case LOBBY:
-    		finish();
-    		break;
-    	case ROOM:
-    		// Do nothing
-    		break;
-		default:
-			throw new IllegalStateException("Unknown connection state: "+newState);
-    	}
+
+    public void onTeamAddDialogSubmitted(Team newTeam) {
+        stateManager.requestAddTeam(newTeam, TeamInGame.getUnusedOrRandomColorIndex(stateManager.getTeams().values()));
+    }
+
+    public RoomStateManager getRoomStateManager() {
+        return stateManager;
     }
-    
-	public void onTeamAddDialogSubmitted(Team newTeam) {
-		stateManager.requestAddTeam(newTeam, TeamInGame.getUnusedOrRandomColorIndex(stateManager.getTeams().values()));
-	}
-	
-	public RoomStateManager getRoomStateManager() {
-		return stateManager;
-	}
+
+    private final OnClickListener startButtonClickListener = new OnClickListener() {
+        public void onClick(View v) {
+            netplay.sendStartGame();
+        }
+    };
 
-	private final OnClickListener startButtonClickListener = new OnClickListener() {
-		public void onClick(View v) {
-			netplay.sendStartGame();
-		}
-	};
-	
-	private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.ListenerAdapter() {
-		@Override
-		public void onChiefStatusChanged(boolean isChief) {
-			startButton.setVisibility(isChief ? View.VISIBLE : View.GONE);
-		}
-	};
-	
-	public void runGame(GameConfig config) {
-		SDLActivity.startConfig = config;
-		SDLActivity.startNetgame = true;
-		startActivity(new Intent(this, SDLActivity.class));
-	}
+    private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.ListenerAdapter() {
+        @Override
+        public void onChiefStatusChanged(boolean isChief) {
+            startButton.setVisibility(isChief ? View.VISIBLE : View.GONE);
+        }
+    };
+
+    public void runGame(GameConfig config) {
+        SDLActivity.startConfig = config;
+        SDLActivity.startNetgame = true;
+        startActivity(new Intent(this, SDLActivity.class));
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetplayStateFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/NetplayStateFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -37,7 +37,7 @@
 /**
  * Fragment for use by an activity that depends on the state of the network
  * connection. The activity must implement the NetplayStateListener interface.
- * 
+ *
  * This fragment manages reacting to changes in the networking state by calling
  * a callback method on the activity.
  */
@@ -47,91 +47,91 @@
     private LocalBroadcastManager broadcastManager;
     private NetplayStateListener listener;
     private State knownState;
-    
+
     interface NetplayStateListener {
-    	/**
-    	 * This is called while the activity is running, and every time during resume, if
-    	 * a change in the networking state is detected. It is also called once
-    	 * with the initial state (which could be called a change from the "unknown" state).
-    	 */
-    	void onNetplayStateChanged(State newState);
-    } 
-    
+        /**
+         * This is called while the activity is running, and every time during resume, if
+         * a change in the networking state is detected. It is also called once
+         * with the initial state (which could be called a change from the "unknown" state).
+         */
+        void onNetplayStateChanged(State newState);
+    }
+
     @Override
-	public void onAttach(Activity activity) {
-		super.onAttach(activity);
-		try {
-			listener = (NetplayStateListener) activity;
-		} catch(ClassCastException e) {
-			throw new ClassCastException("Activity " + activity + " must implement NetplayStateListener to use NetplayStateFragment.");
-		}
-	}
-	
-	@Override
-	public void onDetach() {
-		super.onDetach();
-		listener = null;
-	}
-	
+    public void onAttach(Activity activity) {
+        super.onAttach(activity);
+        try {
+            listener = (NetplayStateListener) activity;
+        } catch(ClassCastException e) {
+            throw new ClassCastException("Activity " + activity + " must implement NetplayStateListener to use NetplayStateFragment.");
+        }
+    }
+
+    @Override
+    public void onDetach() {
+        super.onDetach();
+        listener = null;
+    }
+
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         appContext = getActivity().getApplicationContext();
         broadcastManager = LocalBroadcastManager.getInstance(appContext);
         netplay = Netplay.getAppInstance(appContext);
-    }    
+    }
 
     @Override
     public void onResume() {
-    	super.onResume();
-    	broadcastManager.registerReceiver(disconnectReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
-    	broadcastManager.registerReceiver(leaveRoomReceiver, new IntentFilter(Netplay.ACTION_LEFT_ROOM));
-    	broadcastManager.registerReceiver(stateChangeReceiver, new IntentFilter(Netplay.ACTION_STATE_CHANGED));
-    	
-    	State newState = netplay.getState();
-		if(knownState != newState) {
-    		listener.onNetplayStateChanged(newState);
-    		knownState = newState;
-    	}
+        super.onResume();
+        broadcastManager.registerReceiver(disconnectReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
+        broadcastManager.registerReceiver(leaveRoomReceiver, new IntentFilter(Netplay.ACTION_LEFT_ROOM));
+        broadcastManager.registerReceiver(stateChangeReceiver, new IntentFilter(Netplay.ACTION_STATE_CHANGED));
+
+        State newState = netplay.getState();
+        if(knownState != newState) {
+            listener.onNetplayStateChanged(newState);
+            knownState = newState;
+        }
     }
-    
+
     @Override
     public void onPause() {
-    	super.onPause();
-    	broadcastManager.unregisterReceiver(disconnectReceiver);
-    	broadcastManager.unregisterReceiver(leaveRoomReceiver);
-    	broadcastManager.unregisterReceiver(stateChangeReceiver);
+        super.onPause();
+        broadcastManager.unregisterReceiver(disconnectReceiver);
+        broadcastManager.unregisterReceiver(leaveRoomReceiver);
+        broadcastManager.unregisterReceiver(stateChangeReceiver);
     }
 
-	private final BroadcastReceiver disconnectReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) {
-				String message = intent.getStringExtra(Netplay.EXTRA_MESSAGE);
-				String toastText = getString(R.string.toast_disconnected, message);
-				Toast.makeText(appContext, toastText, Toast.LENGTH_LONG).show();
-			}
-		}
-	};
-	
-	private final BroadcastReceiver leaveRoomReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			int reason = intent.getIntExtra(Netplay.EXTRA_REASON, -1);
-			if(reason == Frontlib.NETCONN_ROOMLEAVE_ABANDONED) {
-				Toast.makeText(appContext, R.string.toast_room_abandoned, Toast.LENGTH_LONG).show();
-			} else if(reason == Frontlib.NETCONN_ROOMLEAVE_KICKED) {
-				Toast.makeText(appContext, R.string.toast_kicked, Toast.LENGTH_LONG).show();
-			}
-		}
-	};
-	
-	private final BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() {
-		@Override
-		public void onReceive(Context context, Intent intent) {
-			State newState = netplay.getState();
-			listener.onNetplayStateChanged(newState);
-			knownState = newState;
-		}
-	};
+    private final BroadcastReceiver disconnectReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) {
+                String message = intent.getStringExtra(Netplay.EXTRA_MESSAGE);
+                String toastText = getString(R.string.toast_disconnected, message);
+                Toast.makeText(appContext, toastText, Toast.LENGTH_LONG).show();
+            }
+        }
+    };
+
+    private final BroadcastReceiver leaveRoomReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            int reason = intent.getIntExtra(Netplay.EXTRA_REASON, -1);
+            if(reason == Frontlib.NETCONN_ROOMLEAVE_ABANDONED) {
+                Toast.makeText(appContext, R.string.toast_room_abandoned, Toast.LENGTH_LONG).show();
+            } else if(reason == Frontlib.NETCONN_ROOMLEAVE_KICKED) {
+                Toast.makeText(appContext, R.string.toast_kicked, Toast.LENGTH_LONG).show();
+            }
+        }
+    };
+
+    private final BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            State newState = netplay.getState();
+            listener.onNetplayStateChanged(newState);
+            knownState = newState;
+        }
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/PasswordDialog.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/PasswordDialog.java	Tue Jan 21 22:53:15 2014 +0100
@@ -33,50 +33,50 @@
  * Shown when connecting to the server, and the server requests a password.
  */
 public class PasswordDialog extends ConnectionDependendDialogFragment {
-	String username;
-	
-	public PasswordDialog() {
-	}
-	
-	public PasswordDialog(String username) {
-		this.username = username;
-	}
-	
-	@Override
-	public void onSaveInstanceState(Bundle icicle) {
-		super.onSaveInstanceState(icicle);
-		icicle.putString("username", username);
-	}
-	
-	@Override
-	public Dialog onCreateDialog(Bundle savedInstanceState) {
-		if(savedInstanceState != null) {
-			username = savedInstanceState.getString("username");
-		}
-		final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-		final EditText editText = new EditText(getActivity());
-		final Netplay netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
-		
-		editText.setHint(R.string.dialog_password_hint);
-		editText.setId(android.R.id.text1);
-		editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
-		editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
-		builder.setView(editText);
-		builder.setTitle(R.string.dialog_password_title);
-		builder.setMessage(getString(R.string.dialog_password_message, username));
-		builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-			public void onClick(DialogInterface dialog, int which) {
-				String password = editText.getText().toString();
-				editText.setText("");
-				netplay.sendPassword(password);
-			}
-		});
-		return builder.create();
-	}
-	
-	@Override
-	public void onCancel(DialogInterface dialog) {
-		super.onCancel(dialog);
-		Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
-	}
+    String username;
+
+    public PasswordDialog() {
+    }
+
+    public PasswordDialog(String username) {
+        this.username = username;
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle icicle) {
+        super.onSaveInstanceState(icicle);
+        icicle.putString("username", username);
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        if(savedInstanceState != null) {
+            username = savedInstanceState.getString("username");
+        }
+        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+        final EditText editText = new EditText(getActivity());
+        final Netplay netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
+
+        editText.setHint(R.string.dialog_password_hint);
+        editText.setId(android.R.id.text1);
+        editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
+        editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
+        builder.setView(editText);
+        builder.setTitle(R.string.dialog_password_title);
+        builder.setMessage(getString(R.string.dialog_password_message, username));
+        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+            public void onClick(DialogInterface dialog, int which) {
+                String password = editText.getText().toString();
+                editText.setText("");
+                netplay.sendPassword(password);
+            }
+        });
+        return builder.create();
+    }
+
+    @Override
+    public void onCancel(DialogInterface dialog) {
+        super.onCancel(dialog);
+        Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomPlayerlistAdapter.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomPlayerlistAdapter.java	Tue Jan 21 22:53:15 2014 +0100
@@ -31,30 +31,30 @@
 import android.widget.TextView;
 
 public class RoomPlayerlistAdapter extends ObservableTreeMapAdapter<String, PlayerInRoom> {
-	@Override
-	protected Comparator<PlayerInRoom> getEntryOrder() {
-		return AlphabeticalOrderComparator.INSTANCE;
-	}
+    @Override
+    protected Comparator<PlayerInRoom> getEntryOrder() {
+        return AlphabeticalOrderComparator.INSTANCE;
+    }
 
-	public View getView(int position, View convertView, ViewGroup parent) {
-		View v = convertView;
-		if (v == null) {
-			LayoutInflater vi = LayoutInflater.from(parent.getContext());
-			v = vi.inflate(R.layout.listview_player, null);
-		}
+    public View getView(int position, View convertView, ViewGroup parent) {
+        View v = convertView;
+        if (v == null) {
+            LayoutInflater vi = LayoutInflater.from(parent.getContext());
+            v = vi.inflate(R.layout.listview_player, null);
+        }
 
-		PlayerInRoom player = getItem(position);
-		TextView username = (TextView) v.findViewById(android.R.id.text1);
-		username.setText(player.player.name);
-		int readyDrawable = player.ready ? R.drawable.lightbulb_on : R.drawable.lightbulb_off;
-		username.setCompoundDrawablesWithIntrinsicBounds(readyDrawable, 0, 0, 0);
-		return v;
-	}
-	
-	private static final class AlphabeticalOrderComparator implements Comparator<PlayerInRoom> {
-		public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator();
-		public int compare(PlayerInRoom lhs, PlayerInRoom rhs) {
-			return lhs.player.name.compareToIgnoreCase(rhs.player.name);
-		};
-	}
+        PlayerInRoom player = getItem(position);
+        TextView username = (TextView) v.findViewById(android.R.id.text1);
+        username.setText(player.player.name);
+        int readyDrawable = player.ready ? R.drawable.lightbulb_on : R.drawable.lightbulb_off;
+        username.setCompoundDrawablesWithIntrinsicBounds(readyDrawable, 0, 0, 0);
+        return v;
+    }
+
+    private static final class AlphabeticalOrderComparator implements Comparator<PlayerInRoom> {
+        public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator();
+        public int compare(PlayerInRoom lhs, PlayerInRoom rhs) {
+            return lhs.player.name.compareToIgnoreCase(rhs.player.name);
+        };
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomPlayerlistFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomPlayerlistFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -38,73 +38,73 @@
 import android.widget.AdapterView.OnItemClickListener;
 
 public class RoomPlayerlistFragment extends ListFragment implements OnItemClickListener {
-	private Netplay netplay;
-	private RoomPlayerlistAdapter adapter;
-	
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
-		adapter = new RoomPlayerlistAdapter();
-		adapter.setSource(netplay.roomPlayerlist);
-		setListAdapter(adapter);
-	}
+    private Netplay netplay;
+    private RoomPlayerlistAdapter adapter;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
+        adapter = new RoomPlayerlistAdapter();
+        adapter.setSource(netplay.roomPlayerlist);
+        setListAdapter(adapter);
+    }
 
-	@Override
-	public void onDestroy() {
-		super.onDestroy();
-		adapter.invalidate();
-	}
-	
-	@Override
-	public void onActivityCreated(Bundle savedInstanceState) {
-		super.onActivityCreated(savedInstanceState);
-		registerForContextMenu(getListView());
-		getListView().setOnItemClickListener(this);
-	}
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        adapter.invalidate();
+    }
+
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+        registerForContextMenu(getListView());
+        getListView().setOnItemClickListener(this);
+    }
+
+    @Override
+    public void onCreateContextMenu(ContextMenu menu, View v,
+            ContextMenuInfo menuInfo) {
+        super.onCreateContextMenu(menu, v, menuInfo);
+        AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
+        String playerName = adapter.getItem(info.position).player.name;
 
-	@Override
-	public void onCreateContextMenu(ContextMenu menu, View v,
-			ContextMenuInfo menuInfo) {
-		super.onCreateContextMenu(menu, v, menuInfo);
-		AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
-		String playerName = adapter.getItem(info.position).player.name;
-		
-		MenuInflater inflater = getActivity().getMenuInflater();
-		inflater.inflate(R.menu.room_playerlist_context, menu);
-		if(netplay.isChief() && !playerName.equals(netplay.getPlayerName())) {
-			inflater.inflate(R.menu.room_playerlist_chief_context, menu);
-		}
-		menu.setHeaderIcon(R.drawable.human);
-		menu.setHeaderTitle(playerName);
-	}
-	
-	@Override
-	public boolean onContextItemSelected(MenuItem item) {
-		AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
-		PlayerInRoom player = adapter.getItem(info.position);
-		switch(item.getItemId()) {
-		case R.id.player_info:
-			netplay.sendPlayerInfoQuery(player.player.name);
-			return true;
-		case R.id.player_kick:
-			netplay.sendKick(player.player.name);
-			return true;
-		default:
-			return super.onContextItemSelected(item);
-		}
-	}
-	
-	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container,
-			Bundle savedInstanceState) {
-		return inflater.inflate(R.layout.fragment_playerlist, container, false);
-	}
-	
-	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-		Player player = adapter.getItem(position).player;
-		if(player.name.equals(netplay.getPlayerName())) {
-			netplay.sendToggleReady();
-		}
-	}
+        MenuInflater inflater = getActivity().getMenuInflater();
+        inflater.inflate(R.menu.room_playerlist_context, menu);
+        if(netplay.isChief() && !playerName.equals(netplay.getPlayerName())) {
+            inflater.inflate(R.menu.room_playerlist_chief_context, menu);
+        }
+        menu.setHeaderIcon(R.drawable.human);
+        menu.setHeaderTitle(playerName);
+    }
+
+    @Override
+    public boolean onContextItemSelected(MenuItem item) {
+        AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
+        PlayerInRoom player = adapter.getItem(info.position);
+        switch(item.getItemId()) {
+        case R.id.player_info:
+            netplay.sendPlayerInfoQuery(player.player.name);
+            return true;
+        case R.id.player_kick:
+            netplay.sendKick(player.player.name);
+            return true;
+        default:
+            return super.onContextItemSelected(item);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.fragment_playerlist, container, false);
+    }
+
+    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+        Player player = adapter.getItem(position).player;
+        if(player.name.equals(netplay.getPlayerName())) {
+            netplay.sendToggleReady();
+        }
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomStateManager.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomStateManager.java	Tue Jan 21 22:53:15 2014 +0100
@@ -33,78 +33,78 @@
  * using these fragments both for setting up networked and local games, despite
  * the fact that for local games the settings can be changed immediately in
  * memory, while they have to be sent out to the server for networked games.
- * 
+ *
  * If/when the state changes as result of calling one of the "changeX" or
  * "requestX" functions, that will also trigger the corresponding change
  * listener method. There is no guarantee that calling a changeX method will
  * actually change the setting (e.g. if you're not room chief).
- * 
+ *
  * For local games, getChiefStatus is always true.
- * 
+ *
  * Implementations of this interface are probably not thread safe and should
  * only be used on the UI thread.
  */
 public interface RoomStateManager {
-	// Query current state
-	MapRecipe getMapRecipe();
-	boolean getChiefStatus();
-	Scheme getScheme();
-	String getGameStyle();
-	Weaponset getWeaponset();
-	Map<String, TeamInGame> getTeams();
-	
-	// Manipulate state
-	void changeMapRecipe(MapRecipe map);
-	void changeMapTheme(String theme);
+    // Query current state
+    MapRecipe getMapRecipe();
+    boolean getChiefStatus();
+    Scheme getScheme();
+    String getGameStyle();
+    Weaponset getWeaponset();
+    Map<String, TeamInGame> getTeams();
+
+    // Manipulate state
+    void changeMapRecipe(MapRecipe map);
+    void changeMapTheme(String theme);
+
+    /**
+     * This function sets both the map's name and generator. There is no function
+     * to change them independendly since e.g. the QtFrontend relies on them being
+     * consistent.
+     *
+     * If the name parameter is equal to one of the MapRecipe.MAPNAME_REGULAR, MAPNAME_MAZE
+     * or MAPNAME_DRAWN constants, the map generator is set accordingly. Otherwise, the
+     * map generator is set to represent a mapfile. The map's name is always set to
+     * the parameter.
+     */
+    void changeMapNameAndGenerator(String mapName);
+    void changeMapTemplate(int template);
+    void changeMazeSize(int mazeSize);
+    void changeMapSeed(String seed);
+    void changeMapDrawdata(byte[] drawdata);
+
+    void changeScheme(Scheme scheme);
+    void changeGameStyle(String style);
+    void changeWeaponset(Weaponset weaponset);
 
-	/**
-	 * This function sets both the map's name and generator. There is no function
-	 * to change them independendly since e.g. the QtFrontend relies on them being
-	 * consistent.
-	 * 
-	 * If the name parameter is equal to one of the MapRecipe.MAPNAME_REGULAR, MAPNAME_MAZE
-	 * or MAPNAME_DRAWN constants, the map generator is set accordingly. Otherwise, the
-	 * map generator is set to represent a mapfile. The map's name is always set to
-	 * the parameter.
-	 */
-	void changeMapNameAndGenerator(String mapName);
-	void changeMapTemplate(int template);
-	void changeMazeSize(int mazeSize);
-	void changeMapSeed(String seed);
-	void changeMapDrawdata(byte[] drawdata);
-	
-	void changeScheme(Scheme scheme);
-	void changeGameStyle(String style);
-	void changeWeaponset(Weaponset weaponset);
-	
-	void requestAddTeam(Team team, int colorIndex);
-	void requestRemoveTeam(String teamname);
-	void changeTeamColorIndex(String teamname, int colorIndex);
-	void changeTeamHogCount(String teamname, int hogcount);
-	
-	// Observe changes
-	void addListener(Listener observer);
-	void removeListener(Listener observer);
-	
-	public interface Listener {
-		void onMapChanged(MapRecipe recipe);
-		void onChiefStatusChanged(boolean isChief);
-		void onSchemeChanged(Scheme scheme);
-		void onGameStyleChanged(String gameStyle);
-		void onWeaponsetChanged(Weaponset weaponset);
-		void onTeamsChanged(Map<String, TeamInGame> teams);
-	}
-	
-	public static class ListenerAdapter implements Listener {
-		public void onMapChanged(MapRecipe recipe) {}
-		public void onChiefStatusChanged(boolean isChief) {}
-		public void onSchemeChanged(Scheme scheme) {}
-		public void onGameStyleChanged(String gameStyle) {}
-		public void onWeaponsetChanged(Weaponset weaponset) {}
-		public void onTeamsChanged(Map<String, TeamInGame> teams) {}
-	}
-	
-	public interface Provider {
-		RoomStateManager getRoomStateManager();
-	}
+    void requestAddTeam(Team team, int colorIndex);
+    void requestRemoveTeam(String teamname);
+    void changeTeamColorIndex(String teamname, int colorIndex);
+    void changeTeamHogCount(String teamname, int hogcount);
+
+    // Observe changes
+    void addListener(Listener observer);
+    void removeListener(Listener observer);
+
+    public interface Listener {
+        void onMapChanged(MapRecipe recipe);
+        void onChiefStatusChanged(boolean isChief);
+        void onSchemeChanged(Scheme scheme);
+        void onGameStyleChanged(String gameStyle);
+        void onWeaponsetChanged(Weaponset weaponset);
+        void onTeamsChanged(Map<String, TeamInGame> teams);
+    }
+
+    public static class ListenerAdapter implements Listener {
+        public void onMapChanged(MapRecipe recipe) {}
+        public void onChiefStatusChanged(boolean isChief) {}
+        public void onSchemeChanged(Scheme scheme) {}
+        public void onGameStyleChanged(String gameStyle) {}
+        public void onWeaponsetChanged(Weaponset weaponset) {}
+        public void onTeamsChanged(Map<String, TeamInGame> teams) {}
+    }
+
+    public interface Provider {
+        RoomStateManager getRoomStateManager();
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomlistAdapter.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomlistAdapter.java	Tue Jan 21 22:53:15 2014 +0100
@@ -37,77 +37,77 @@
  * Displays the list of all rooms in the lobby
  */
 public class RoomlistAdapter extends ObservableTreeMapAdapter<String, RoomWithId> {
-	private Context context;
-	
-	public RoomlistAdapter(Context context) {
-		this.context = context;
-	}
-	
-	@Override
-	protected Comparator<RoomWithId> getEntryOrder() {
-		return RoomWithId.NEWEST_FIRST_ORDER;
-	}
-	
-	@Override
-	public long getItemId(int position) {
-		return getItem(position).id;
-	}
-	
-	@Override
-	public boolean hasStableIds() {
-		return true;
-	}
-	
-	private static CharSequence formatExtra(Resources res, Room room) {
-		String ownermsg = res.getString(R.string.roomlist_owner, room.owner);
-		String mapmsg = res.getString(R.string.roomlist_map, room.formatMapName(res));
-		String scheme = room.scheme.equals(room.weapons) ? room.scheme : room.scheme + " / " + room.weapons;
-		String schememsg = res.getString(R.string.roomlist_scheme, scheme);
-		return ownermsg + ". " + mapmsg + ", " + schememsg;
-	}
-	
-	public View getView(int position, View convertView, ViewGroup parent) {
-		View v = convertView;
-		if (v == null) {
-			LayoutInflater vi = LayoutInflater.from(context);
-			v = vi.inflate(R.layout.listview_room, null);
-		}
-		
-		Room room = getItem(position).room;
-		int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing;
-		
-		if(v.findViewById(android.R.id.text1) == null) {
-			// Tabular room list
-			TextView roomnameView = (TextView)v.findViewById(R.id.roomname);
-			TextView playerCountView = (TextView)v.findViewById(R.id.playercount);
-			TextView teamCountView = (TextView)v.findViewById(R.id.teamcount);
-			TextView ownerView = (TextView)v.findViewById(R.id.owner);
-			TextView mapView = (TextView)v.findViewById(R.id.map);
-			TextView schemeView = (TextView)v.findViewById(R.id.scheme);
-			TextView weaponView = (TextView)v.findViewById(R.id.weapons);
-			
-			roomnameView.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
-			roomnameView.setText(room.name);
-			if(playerCountView != null) {
-				playerCountView.setText(String.valueOf(room.playerCount));
-			}
-			if(teamCountView != null) {
-				teamCountView.setText(String.valueOf(room.teamCount));
-			}
-			ownerView.setText(room.owner);
-			mapView.setText(room.formatMapName(context.getResources()));
-			schemeView.setText(room.scheme);
-			weaponView.setText(room.weapons);
-		} else {
-			// Small room list
-			TextView v1 = (TextView)v.findViewById(android.R.id.text1);
-			TextView v2 = (TextView)v.findViewById(android.R.id.text2);
-			
-			v1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
-			v1.setText(room.name);
-			v2.setText(formatExtra(context.getResources(), room));
-		}
-		
-		return v;
-	}
+    private Context context;
+
+    public RoomlistAdapter(Context context) {
+        this.context = context;
+    }
+
+    @Override
+    protected Comparator<RoomWithId> getEntryOrder() {
+        return RoomWithId.NEWEST_FIRST_ORDER;
+    }
+
+    @Override
+    public long getItemId(int position) {
+        return getItem(position).id;
+    }
+
+    @Override
+    public boolean hasStableIds() {
+        return true;
+    }
+
+    private static CharSequence formatExtra(Resources res, Room room) {
+        String ownermsg = res.getString(R.string.roomlist_owner, room.owner);
+        String mapmsg = res.getString(R.string.roomlist_map, room.formatMapName(res));
+        String scheme = room.scheme.equals(room.weapons) ? room.scheme : room.scheme + " / " + room.weapons;
+        String schememsg = res.getString(R.string.roomlist_scheme, scheme);
+        return ownermsg + ". " + mapmsg + ", " + schememsg;
+    }
+
+    public View getView(int position, View convertView, ViewGroup parent) {
+        View v = convertView;
+        if (v == null) {
+            LayoutInflater vi = LayoutInflater.from(context);
+            v = vi.inflate(R.layout.listview_room, null);
+        }
+
+        Room room = getItem(position).room;
+        int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing;
+
+        if(v.findViewById(android.R.id.text1) == null) {
+            // Tabular room list
+            TextView roomnameView = (TextView)v.findViewById(R.id.roomname);
+            TextView playerCountView = (TextView)v.findViewById(R.id.playercount);
+            TextView teamCountView = (TextView)v.findViewById(R.id.teamcount);
+            TextView ownerView = (TextView)v.findViewById(R.id.owner);
+            TextView mapView = (TextView)v.findViewById(R.id.map);
+            TextView schemeView = (TextView)v.findViewById(R.id.scheme);
+            TextView weaponView = (TextView)v.findViewById(R.id.weapons);
+
+            roomnameView.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
+            roomnameView.setText(room.name);
+            if(playerCountView != null) {
+                playerCountView.setText(String.valueOf(room.playerCount));
+            }
+            if(teamCountView != null) {
+                teamCountView.setText(String.valueOf(room.teamCount));
+            }
+            ownerView.setText(room.owner);
+            mapView.setText(room.formatMapName(context.getResources()));
+            schemeView.setText(room.scheme);
+            weaponView.setText(room.weapons);
+        } else {
+            // Small room list
+            TextView v1 = (TextView)v.findViewById(android.R.id.text1);
+            TextView v2 = (TextView)v.findViewById(android.R.id.text2);
+
+            v1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
+            v1.setText(room.name);
+            v2.setText(formatExtra(context.getResources(), room));
+        }
+
+        return v;
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomlistFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomlistFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -35,60 +35,60 @@
  * Displays the list of all rooms in the lobby
  */
 public class RoomlistFragment extends ListFragment implements OnItemClickListener {
-	private static final int AUTO_REFRESH_INTERVAL_MS = 15000;
-	
-	private Netplay netplay;
-	private RoomlistAdapter adapter;
-	private CountDownTimer autoRefreshTimer = new CountDownTimer(Long.MAX_VALUE, AUTO_REFRESH_INTERVAL_MS) {
-		@Override
-		public void onTick(long millisUntilFinished) {
-			netplay.sendRoomlistRequest();
-		}
-		
-		@Override
-		public void onFinish() { }
-	};
+    private static final int AUTO_REFRESH_INTERVAL_MS = 15000;
+
+    private Netplay netplay;
+    private RoomlistAdapter adapter;
+    private CountDownTimer autoRefreshTimer = new CountDownTimer(Long.MAX_VALUE, AUTO_REFRESH_INTERVAL_MS) {
+        @Override
+        public void onTick(long millisUntilFinished) {
+            netplay.sendRoomlistRequest();
+        }
+
+        @Override
+        public void onFinish() { }
+    };
 
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
-		adapter = new RoomlistAdapter(getActivity());
-		adapter.setSource(netplay.roomList);
-		setListAdapter(adapter);
-	}
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
+        adapter = new RoomlistAdapter(getActivity());
+        adapter.setSource(netplay.roomList);
+        setListAdapter(adapter);
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.fragment_roomlist, container, false);
+    }
 
-	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container,
-			Bundle savedInstanceState) {
-		return inflater.inflate(R.layout.fragment_roomlist, container, false);
-	}
-	
-	@Override
-	public void onActivityCreated(Bundle savedInstanceState) {
-		super.onActivityCreated(savedInstanceState);
-		getListView().setOnItemClickListener(this);
-	}
-	
-	@Override
-	public void onResume() {
-		super.onResume();
-		autoRefreshTimer.start();
-	}
-	
-	@Override
-	public void onPause() {
-		super.onPause();
-		autoRefreshTimer.cancel();
-	}
-	
-	@Override
-	public void onDestroy() {
-		super.onDestroy();
-		adapter.invalidate();
-	}
-	
-	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-		netplay.sendJoinRoom(adapter.getItem(position).room.name);
-	}
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+        getListView().setOnItemClickListener(this);
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        autoRefreshTimer.start();
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+        autoRefreshTimer.cancel();
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        adapter.invalidate();
+    }
+
+    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+        netplay.sendJoinRoom(adapter.getItem(position).room.name);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SDLActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SDLActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -62,358 +62,358 @@
     SDL Activity
  */
 public class SDLActivity extends Activity {
-	/**
-	 * Set startConfig to the desired config when starting this activity. This avoids having to parcel all
-	 * the config objects into the Intent. Not particularly elegant, but it's actually a recommended
-	 * way to do this (http://developer.android.com/guide/faq/framework.html#3)
-	 */
-	public static volatile GameConfig startConfig;
-	public static volatile boolean startNetgame;
-	
-	// Main components
-	public static SDLActivity mSingleton;
-	private static SDLSurface mSurface;
-	private static Thread mSDLThread;
+    /**
+     * Set startConfig to the desired config when starting this activity. This avoids having to parcel all
+     * the config objects into the Intent. Not particularly elegant, but it's actually a recommended
+     * way to do this (http://developer.android.com/guide/faq/framework.html#3)
+     */
+    public static volatile GameConfig startConfig;
+    public static volatile boolean startNetgame;
 
-	// Audio
-	private static Thread mAudioThread;
-	private static AudioTrack mAudioTrack;
+    // Main components
+    public static SDLActivity mSingleton;
+    private static SDLSurface mSurface;
+    private static Thread mSDLThread;
 
-	// EGL private objects
-	private static EGLContext  mEGLContext;
-	private static EGLSurface  mEGLSurface;
-	private static EGLDisplay  mEGLDisplay;
-	private static EGLConfig   mEGLConfig;
-	private static int mGLMajor, mGLMinor;
+    // Audio
+    private static Thread mAudioThread;
+    private static AudioTrack mAudioTrack;
+
+    // EGL private objects
+    private static EGLContext  mEGLContext;
+    private static EGLSurface  mEGLSurface;
+    private static EGLDisplay  mEGLDisplay;
+    private static EGLConfig   mEGLConfig;
+    private static int mGLMajor, mGLMinor;
 
-	// Load the .so
-	static {
-		System.loadLibrary("SDL");
-		System.loadLibrary("main");
-	}
+    // Load the .so
+    static {
+        System.loadLibrary("SDL");
+        System.loadLibrary("main");
+    }
 
-	// Setup
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
+    // Setup
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
 
-		// So we can call stuff from static callbacks
-		mSingleton = this;
+        // So we can call stuff from static callbacks
+        mSingleton = this;
 
-		// Set up the surface
-		mSurface = new SDLSurface(getApplication(), startConfig, startNetgame);
-		startConfig = null;
-		setContentView(mSurface);
-	}
+        // Set up the surface
+        mSurface = new SDLSurface(getApplication(), startConfig, startNetgame);
+        startConfig = null;
+        setContentView(mSurface);
+    }
 
-	// Events
-	protected void onPause() {
-		Log.v("SDL", "onPause()");
-		super.onPause();
+    // Events
+    protected void onPause() {
+        Log.v("SDL", "onPause()");
+        super.onPause();
 
-		if(mEGLDisplay != null && mEGLContext != null){
-			EGL10 egl = (EGL10)EGLContext.getEGL();
-			egl.eglDestroyContext(mEGLDisplay, mEGLContext);
-			mEGLDisplay = null;
-			mEGLContext = null;
-		}
+        if(mEGLDisplay != null && mEGLContext != null){
+            EGL10 egl = (EGL10)EGLContext.getEGL();
+            egl.eglDestroyContext(mEGLDisplay, mEGLContext);
+            mEGLDisplay = null;
+            mEGLContext = null;
+        }
 
-		SDLActivity.nativePause();
-	}
+        SDLActivity.nativePause();
+    }
 
-	protected void onResume() {
-		Log.v("SDL", "onResume()");
-		super.onResume();
-	}
+    protected void onResume() {
+        Log.v("SDL", "onResume()");
+        super.onResume();
+    }
 
-	protected void onDestroy() {
-		super.onDestroy();
-		Log.v("SDL", "onDestroy()");
-		// Send a quit message to the application
-		SDLActivity.nativeQuit();
-		// Now wait for the SDL thread to quit
-		if (mSDLThread != null) {
-			try {
-				mSDLThread.join();
-			} catch(Exception e) {
-				Log.w("SDL", "Problem stopping thread: " + e);
-			}
-			mSDLThread = null;
-		}
-		mSingleton = null;
-	}
-	
-	public static void synchronizedNativeInit(String...args) {
-		synchronized(PascalExports.engineMutex) {
-			nativeInit(args);
-		}
-	}
-	
-	// C functions we call
-	private static native void nativeInit(String...args);
-	public static native void nativeQuit();
-	public static native void nativePause();
-	public static native void nativeResume();
-	public static native void onNativeResize(int x, int y, int format);
-	public static native void onNativeKeyDown(int keycode);
-	public static native void onNativeKeyUp(int keycode);
-	public static native void onNativeTouch(int touchDevId, int pointerFingerId,
-			int action, float x, 
-			float y, float p);
-	public static native void onNativeAccel(float x, float y, float z);
-	public static native void nativeRunAudioThread();
+    protected void onDestroy() {
+        super.onDestroy();
+        Log.v("SDL", "onDestroy()");
+        // Send a quit message to the application
+        SDLActivity.nativeQuit();
+        // Now wait for the SDL thread to quit
+        if (mSDLThread != null) {
+            try {
+                mSDLThread.join();
+            } catch(Exception e) {
+                Log.w("SDL", "Problem stopping thread: " + e);
+            }
+            mSDLThread = null;
+        }
+        mSingleton = null;
+    }
+
+    public static void synchronizedNativeInit(String...args) {
+        synchronized(PascalExports.engineMutex) {
+            nativeInit(args);
+        }
+    }
+
+    // C functions we call
+    private static native void nativeInit(String...args);
+    public static native void nativeQuit();
+    public static native void nativePause();
+    public static native void nativeResume();
+    public static native void onNativeResize(int x, int y, int format);
+    public static native void onNativeKeyDown(int keycode);
+    public static native void onNativeKeyUp(int keycode);
+    public static native void onNativeTouch(int touchDevId, int pointerFingerId,
+            int action, float x,
+            float y, float p);
+    public static native void onNativeAccel(float x, float y, float z);
+    public static native void nativeRunAudioThread();
 
 
-	// Java functions called from C
+    // Java functions called from C
 
-	public static boolean createGLContext(int majorVersion, int minorVersion) {
-		return initEGL(majorVersion, minorVersion);
-	}
+    public static boolean createGLContext(int majorVersion, int minorVersion) {
+        return initEGL(majorVersion, minorVersion);
+    }
 
-	public static void flipBuffers() {
-		flipEGL();
-	}
+    public static void flipBuffers() {
+        flipEGL();
+    }
 
-	public static void setActivityTitle(final String title) {
-		// Called from SDLMain() thread and can't directly affect the view
-		mSingleton.runOnUiThread(new Runnable() {
-			public void run() {
-				mSingleton.setTitle(title);
-			}
-		});
-	}
+    public static void setActivityTitle(final String title) {
+        // Called from SDLMain() thread and can't directly affect the view
+        mSingleton.runOnUiThread(new Runnable() {
+            public void run() {
+                mSingleton.setTitle(title);
+            }
+        });
+    }
 
-	public static Context getContext() {
-		return mSingleton;
-	}
+    public static Context getContext() {
+        return mSingleton;
+    }
 
-	public static void startApp(final int width, final int height, GameConfig config, boolean netgame) {
-		// Start up the C app thread
-		if (mSDLThread == null) {
-			mSDLThread = new Thread(new SDLMain(width, height, config, netgame));
-			mSDLThread.start();
-		} else {
-			SDLActivity.nativeResume();
-		}
-	}
+    public static void startApp(final int width, final int height, GameConfig config, boolean netgame) {
+        // Start up the C app thread
+        if (mSDLThread == null) {
+            mSDLThread = new Thread(new SDLMain(width, height, config, netgame));
+            mSDLThread.start();
+        } else {
+            SDLActivity.nativeResume();
+        }
+    }
 
-	// EGL functions
-	public static boolean initEGL(int majorVersion, int minorVersion) {
-		if (SDLActivity.mEGLDisplay == null) {
-			try {
-				EGL10 egl = (EGL10)EGLContext.getEGL();
+    // EGL functions
+    public static boolean initEGL(int majorVersion, int minorVersion) {
+        if (SDLActivity.mEGLDisplay == null) {
+            try {
+                EGL10 egl = (EGL10)EGLContext.getEGL();
 
-				EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+                EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
 
-				int[] version = new int[2];
-				egl.eglInitialize(dpy, version);
+                int[] version = new int[2];
+                egl.eglInitialize(dpy, version);
 
-				int EGL_OPENGL_ES_BIT = 1;
-				int EGL_OPENGL_ES2_BIT = 4;
-				int renderableType = 0;
-				if (majorVersion == 2) {
-					renderableType = EGL_OPENGL_ES2_BIT;
-				} else if (majorVersion == 1) {
-					renderableType = EGL_OPENGL_ES_BIT;
-				}
-				int[] configSpec = {
-						EGL10.EGL_RENDERABLE_TYPE, renderableType,
-						EGL10.EGL_NONE
-				};
-				EGLConfig[] configs = new EGLConfig[1];
-				int[] num_config = new int[1];
-				if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) {
-					Log.e("SDL", "No EGL config available");
-					return false;
-				}
-				EGLConfig config = configs[0];
+                int EGL_OPENGL_ES_BIT = 1;
+                int EGL_OPENGL_ES2_BIT = 4;
+                int renderableType = 0;
+                if (majorVersion == 2) {
+                    renderableType = EGL_OPENGL_ES2_BIT;
+                } else if (majorVersion == 1) {
+                    renderableType = EGL_OPENGL_ES_BIT;
+                }
+                int[] configSpec = {
+                        EGL10.EGL_RENDERABLE_TYPE, renderableType,
+                        EGL10.EGL_NONE
+                };
+                EGLConfig[] configs = new EGLConfig[1];
+                int[] num_config = new int[1];
+                if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) {
+                    Log.e("SDL", "No EGL config available");
+                    return false;
+                }
+                EGLConfig config = configs[0];
 
-				SDLActivity.mEGLDisplay = dpy;
-				SDLActivity.mEGLConfig = config;
-				SDLActivity.mGLMajor = majorVersion;
-				SDLActivity.mGLMinor = minorVersion;
+                SDLActivity.mEGLDisplay = dpy;
+                SDLActivity.mEGLConfig = config;
+                SDLActivity.mGLMajor = majorVersion;
+                SDLActivity.mGLMinor = minorVersion;
 
-				SDLActivity.createEGLSurface();
-			} catch(Exception e) {
-				Log.v("SDL", e + "");
-				for (StackTraceElement s : e.getStackTrace()) {
-					Log.v("SDL", s.toString());
-				}
-			}
-		}
-		else SDLActivity.createEGLSurface();
+                SDLActivity.createEGLSurface();
+            } catch(Exception e) {
+                Log.v("SDL", e + "");
+                for (StackTraceElement s : e.getStackTrace()) {
+                    Log.v("SDL", s.toString());
+                }
+            }
+        }
+        else SDLActivity.createEGLSurface();
 
-		return true;
-	}
+        return true;
+    }
 
-	public static boolean createEGLContext() {
-		EGL10 egl = (EGL10)EGLContext.getEGL();
-		int EGL_CONTEXT_CLIENT_VERSION=0x3098;
-		int contextAttrs[] = new int[] { EGL_CONTEXT_CLIENT_VERSION, SDLActivity.mGLMajor, EGL10.EGL_NONE };
-		SDLActivity.mEGLContext = egl.eglCreateContext(SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, EGL10.EGL_NO_CONTEXT, contextAttrs);
-		if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) {
-			Log.e("SDL", "Couldn't create context");
-			return false;
-		}
-		return true;
-	}
+    public static boolean createEGLContext() {
+        EGL10 egl = (EGL10)EGLContext.getEGL();
+        int EGL_CONTEXT_CLIENT_VERSION=0x3098;
+        int contextAttrs[] = new int[] { EGL_CONTEXT_CLIENT_VERSION, SDLActivity.mGLMajor, EGL10.EGL_NONE };
+        SDLActivity.mEGLContext = egl.eglCreateContext(SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, EGL10.EGL_NO_CONTEXT, contextAttrs);
+        if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) {
+            Log.e("SDL", "Couldn't create context");
+            return false;
+        }
+        return true;
+    }
 
-	public static boolean createEGLSurface() {
-		if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) {
-			EGL10 egl = (EGL10)EGLContext.getEGL();
-			if (SDLActivity.mEGLContext == null) createEGLContext();
+    public static boolean createEGLSurface() {
+        if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) {
+            EGL10 egl = (EGL10)EGLContext.getEGL();
+            if (SDLActivity.mEGLContext == null) createEGLContext();
 
-			Log.v("SDL", "Creating new EGL Surface");
-			EGLSurface surface = egl.eglCreateWindowSurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, SDLActivity.mSurface, null);
-			if (surface == EGL10.EGL_NO_SURFACE) {
-				Log.e("SDL", "Couldn't create surface");
-				return false;
-			}
+            Log.v("SDL", "Creating new EGL Surface");
+            EGLSurface surface = egl.eglCreateWindowSurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, SDLActivity.mSurface, null);
+            if (surface == EGL10.EGL_NO_SURFACE) {
+                Log.e("SDL", "Couldn't create surface");
+                return false;
+            }
 
-			if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) {
-				Log.e("SDL", "Old EGL Context doesnt work, trying with a new one");
-				createEGLContext();
-				if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) {
-					Log.e("SDL", "Failed making EGL Context current");
-					return false;
-				}
-			}
-			SDLActivity.mEGLSurface = surface;
-			return true;
-		}
-		return false;
-	}
+            if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) {
+                Log.e("SDL", "Old EGL Context doesnt work, trying with a new one");
+                createEGLContext();
+                if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) {
+                    Log.e("SDL", "Failed making EGL Context current");
+                    return false;
+                }
+            }
+            SDLActivity.mEGLSurface = surface;
+            return true;
+        }
+        return false;
+    }
 
-	// EGL buffer flip
-	public static void flipEGL() {
-		try {
-			EGL10 egl = (EGL10)EGLContext.getEGL();
+    // EGL buffer flip
+    public static void flipEGL() {
+        try {
+            EGL10 egl = (EGL10)EGLContext.getEGL();
 
-			egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, null);
+            egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, null);
 
-			// drawing here
+            // drawing here
 
-			egl.eglWaitGL();
+            egl.eglWaitGL();
 
-			egl.eglSwapBuffers(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface);
+            egl.eglSwapBuffers(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface);
 
 
-		} catch(Exception e) {
-			Log.v("SDL", "flipEGL(): " + e);
-			for (StackTraceElement s : e.getStackTrace()) {
-				Log.v("SDL", s.toString());
-			}
-		}
-	}
+        } catch(Exception e) {
+            Log.v("SDL", "flipEGL(): " + e);
+            for (StackTraceElement s : e.getStackTrace()) {
+                Log.v("SDL", s.toString());
+            }
+        }
+    }
 
-	// Audio
-	private static Object buf;
+    // Audio
+    private static Object buf;
 
-	public static Object audioInit(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) {
-		int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO;
-		int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT;
-		int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1);
+    public static Object audioInit(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) {
+        int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO;
+        int audioFormat = is16Bit ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT;
+        int frameSize = (isStereo ? 2 : 1) * (is16Bit ? 2 : 1);
 
-		Log.v("SDL", "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer");
+        Log.v("SDL", "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer");
 
-		// Let the user pick a larger buffer if they really want -- but ye
-		// gods they probably shouldn't, the minimums are horrifyingly high
-		// latency already
-		desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize);
+        // Let the user pick a larger buffer if they really want -- but ye
+        // gods they probably shouldn't, the minimums are horrifyingly high
+        // latency already
+        desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize);
 
-		mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate,
-				channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM);
+        mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate,
+                channelConfig, audioFormat, desiredFrames * frameSize, AudioTrack.MODE_STREAM);
 
-		audioStartThread();
+        audioStartThread();
 
-		Log.v("SDL", "SDL audio: got " + ((mAudioTrack.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioTrack.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + ((float)mAudioTrack.getSampleRate() / 1000f) + "kHz, " + desiredFrames + " frames buffer");
+        Log.v("SDL", "SDL audio: got " + ((mAudioTrack.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioTrack.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + ((float)mAudioTrack.getSampleRate() / 1000f) + "kHz, " + desiredFrames + " frames buffer");
 
-		if (is16Bit) {
-			buf = new short[desiredFrames * (isStereo ? 2 : 1)];
-		} else {
-			buf = new byte[desiredFrames * (isStereo ? 2 : 1)]; 
-		}
-		return buf;
-	}
+        if (is16Bit) {
+            buf = new short[desiredFrames * (isStereo ? 2 : 1)];
+        } else {
+            buf = new byte[desiredFrames * (isStereo ? 2 : 1)];
+        }
+        return buf;
+    }
 
-	public static void audioStartThread() {
-		mAudioThread = new Thread(new Runnable() {
-			public void run() {
-				mAudioTrack.play();
-				nativeRunAudioThread();
-			}
-		});
+    public static void audioStartThread() {
+        mAudioThread = new Thread(new Runnable() {
+            public void run() {
+                mAudioTrack.play();
+                nativeRunAudioThread();
+            }
+        });
 
-		// I'd take REALTIME if I could get it!
-		mAudioThread.setPriority(Thread.MAX_PRIORITY);
-		mAudioThread.start();
-	}
+        // I'd take REALTIME if I could get it!
+        mAudioThread.setPriority(Thread.MAX_PRIORITY);
+        mAudioThread.start();
+    }
 
-	public static void audioWriteShortBuffer(short[] buffer) {
-		for (int i = 0; i < buffer.length; ) {
-			int result = mAudioTrack.write(buffer, i, buffer.length - i);
-			if (result > 0) {
-				i += result;
-			} else if (result == 0) {
-				try {
-					Thread.sleep(1);
-				} catch(InterruptedException e) {
-					// Nom nom
-				}
-			} else {
-				Log.w("SDL", "SDL audio: error return from write(short)");
-				return;
-			}
-		}
-	}
+    public static void audioWriteShortBuffer(short[] buffer) {
+        for (int i = 0; i < buffer.length; ) {
+            int result = mAudioTrack.write(buffer, i, buffer.length - i);
+            if (result > 0) {
+                i += result;
+            } else if (result == 0) {
+                try {
+                    Thread.sleep(1);
+                } catch(InterruptedException e) {
+                    // Nom nom
+                }
+            } else {
+                Log.w("SDL", "SDL audio: error return from write(short)");
+                return;
+            }
+        }
+    }
 
-	public static void audioWriteByteBuffer(byte[] buffer) {
-		for (int i = 0; i < buffer.length; ) {
-			int result = mAudioTrack.write(buffer, i, buffer.length - i);
-			if (result > 0) {
-				i += result;
-			} else if (result == 0) {
-				try {
-					Thread.sleep(1);
-				} catch(InterruptedException e) {
-					// Nom nom
-				}
-			} else {
-				Log.w("SDL", "SDL audio: error return from write(short)");
-				return;
-			}
-		}
-	}
+    public static void audioWriteByteBuffer(byte[] buffer) {
+        for (int i = 0; i < buffer.length; ) {
+            int result = mAudioTrack.write(buffer, i, buffer.length - i);
+            if (result > 0) {
+                i += result;
+            } else if (result == 0) {
+                try {
+                    Thread.sleep(1);
+                } catch(InterruptedException e) {
+                    // Nom nom
+                }
+            } else {
+                Log.w("SDL", "SDL audio: error return from write(short)");
+                return;
+            }
+        }
+    }
 
-	public static void audioQuit() {
-		if (mAudioThread != null) {
-			try {
-				mAudioThread.join();
-			} catch(Exception e) {
-				Log.v("SDL", "Problem stopping audio thread: " + e);
-			}
-			mAudioThread = null;
+    public static void audioQuit() {
+        if (mAudioThread != null) {
+            try {
+                mAudioThread.join();
+            } catch(Exception e) {
+                Log.v("SDL", "Problem stopping audio thread: " + e);
+            }
+            mAudioThread = null;
 
-			//Log.v("SDL", "Finished waiting for audio thread");
-		}
+            //Log.v("SDL", "Finished waiting for audio thread");
+        }
 
-		if (mAudioTrack != null) {
-			mAudioTrack.stop();
-			mAudioTrack = null;
-		}
-	}
-	
-	public static int getDensity(){
-		DisplayMetrics dm = SDLActivity.getContext().getResources().getDisplayMetrics();
-		return dm.densityDpi;
-	}
+        if (mAudioTrack != null) {
+            mAudioTrack.stop();
+            mAudioTrack = null;
+        }
+    }
+
+    public static int getDensity(){
+        DisplayMetrics dm = SDLActivity.getContext().getResources().getDisplayMetrics();
+        return dm.densityDpi;
+    }
 }
 
 /**
     Simple nativeInit() runnable
  */
 class SDLMain implements Runnable {
-	public static final String TAG = "SDLMain";
-	
+    public static final String TAG = "SDLMain";
+
     public static final int RQ_LOWRES            = 0x00000001; // use half land array
     public static final int RQ_BLURRY_LAND       = 0x00000002; // downscaled terrain
     public static final int RQ_NO_BACKGROUND     = 0x00000004; // don't draw background
@@ -426,246 +426,246 @@
     public static final int RQ_NO_CLAMPING       = 0x00000200; // don't clamp textures
     public static final int RQ_NO_TOOLTIPS       = 0x00000400; // tooltips are not drawn
     public static final int RQ_NO_VSYNC          = 0x00000800; // don't sync on vblank
-	
-	private final int surfaceWidth, surfaceHeight;
-	private final String playerName;
-	private final GameConfig config;
-	private final boolean netgame;
-	
-	public SDLMain(int width, int height, GameConfig config, boolean netgame) {
-		surfaceWidth = width;
-		surfaceHeight = height;
-		if(netgame) {
-			playerName = Netplay.getAppInstance(SDLActivity.getContext().getApplicationContext()).getPlayerName();
-		} else {
-			playerName = "Player";
-		}
-		this.config = config;
-		this.netgame = netgame;
-	}
+
+    private final int surfaceWidth, surfaceHeight;
+    private final String playerName;
+    private final GameConfig config;
+    private final boolean netgame;
+
+    public SDLMain(int width, int height, GameConfig config, boolean netgame) {
+        surfaceWidth = width;
+        surfaceHeight = height;
+        if(netgame) {
+            playerName = Netplay.getAppInstance(SDLActivity.getContext().getApplicationContext()).getPlayerName();
+        } else {
+            playerName = "Player";
+        }
+        this.config = config;
+        this.netgame = netgame;
+    }
 
-	public void run() {
-		//Set up the IPC socket server to communicate with the engine
-		GameConnection gameConn;
-		String path;
-		try {
-			if(netgame) {
-				Netplay netplay = Netplay.getAppInstance(SDLActivity.mSingleton.getApplicationContext());
-				gameConn = GameConnection.forNetgame(config, netplay);
-			} else {
-				gameConn = GameConnection.forLocalGame(config);
-			}
-			
-			path = FileUtils.getDataPathFile(SDLActivity.mSingleton).getAbsolutePath();
-			Log.d(TAG, "Starting engine");
-			// Runs SDL_main() with added parameters
-			try {
-				String pPort = String.valueOf(gameConn.port);
-				String pWidth = String.valueOf(surfaceWidth);
-				String pHeight = String.valueOf(surfaceHeight);
-				String pQuality = Integer.toString(RQ_NO_FLAKES|RQ_NO_DROPLETS|RQ_SIMPLE_EXPLOSIONS);
-				String pPlayerName = Base64.encodeToString(playerName.getBytes("UTF-8"), 0);
-				SDLActivity.synchronizedNativeInit(new String[] { pPort, pWidth, pHeight, pQuality, "en.txt", pPlayerName, "1", "1", "1", path, ""  });
-			} catch (UnsupportedEncodingException e) {
-				throw new AssertionError(e); // never happens
-			}
-			Log.d(TAG, "Engine stopped");
-		} catch(ConnectException e) {
-			Log.e(TAG, "Error starting IPC connection");
-		} catch (IOException e) {
-			Log.e(TAG, "Missing SDCard");
-		}
-		SDLActivity.mSingleton.runOnUiThread(new Runnable() { public void run() {
-			if(SDLActivity.mSingleton != null) {
-				SDLActivity.mSingleton.finish();
-			}
-		}});
-	}
+    public void run() {
+        //Set up the IPC socket server to communicate with the engine
+        GameConnection gameConn;
+        String path;
+        try {
+            if(netgame) {
+                Netplay netplay = Netplay.getAppInstance(SDLActivity.mSingleton.getApplicationContext());
+                gameConn = GameConnection.forNetgame(config, netplay);
+            } else {
+                gameConn = GameConnection.forLocalGame(config);
+            }
+
+            path = FileUtils.getDataPathFile(SDLActivity.mSingleton).getAbsolutePath();
+            Log.d(TAG, "Starting engine");
+            // Runs SDL_main() with added parameters
+            try {
+                String pPort = String.valueOf(gameConn.port);
+                String pWidth = String.valueOf(surfaceWidth);
+                String pHeight = String.valueOf(surfaceHeight);
+                String pQuality = Integer.toString(RQ_NO_FLAKES|RQ_NO_DROPLETS|RQ_SIMPLE_EXPLOSIONS);
+                String pPlayerName = Base64.encodeToString(playerName.getBytes("UTF-8"), 0);
+                SDLActivity.synchronizedNativeInit(new String[] { pPort, pWidth, pHeight, pQuality, "en.txt", pPlayerName, "1", "1", "1", path, ""  });
+            } catch (UnsupportedEncodingException e) {
+                throw new AssertionError(e); // never happens
+            }
+            Log.d(TAG, "Engine stopped");
+        } catch(ConnectException e) {
+            Log.e(TAG, "Error starting IPC connection");
+        } catch (IOException e) {
+            Log.e(TAG, "Missing SDCard");
+        }
+        SDLActivity.mSingleton.runOnUiThread(new Runnable() { public void run() {
+            if(SDLActivity.mSingleton != null) {
+                SDLActivity.mSingleton.finish();
+            }
+        }});
+    }
 }
 
 
 /**
     SDLSurface. This is what we draw on, so we need to know when it's created
-    in order to do anything useful. 
+    in order to do anything useful.
 
     Because of this, that's where we set up the SDL thread
  */
-class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, 
+class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
 View.OnKeyListener, View.OnTouchListener, SensorEventListener  {
 
-	private GameConfig config;
-	private boolean netgame;
-	
-	// Sensors
-	private static SensorManager mSensorManager;
+    private GameConfig config;
+    private boolean netgame;
+
+    // Sensors
+    private static SensorManager mSensorManager;
 
-	// Startup    
-	public SDLSurface(Context context, GameConfig _config, boolean netgame) {
-		super(context);
-		getHolder().addCallback(this); 
+    // Startup
+    public SDLSurface(Context context, GameConfig _config, boolean netgame) {
+        super(context);
+        getHolder().addCallback(this);
 
-		setFocusable(true);
-		setFocusableInTouchMode(true);
-		requestFocus();
-		setOnKeyListener(this); 
-		setOnTouchListener(this);   
+        setFocusable(true);
+        setFocusableInTouchMode(true);
+        requestFocus();
+        setOnKeyListener(this);
+        setOnTouchListener(this);
 
-		mSensorManager = (SensorManager)context.getSystemService("sensor");
-		config = _config;
-		this.netgame = netgame;
-	}
+        mSensorManager = (SensorManager)context.getSystemService("sensor");
+        config = _config;
+        this.netgame = netgame;
+    }
 
-	// Called when we have a valid drawing surface
-	public void surfaceCreated(SurfaceHolder holder) {
-		Log.v("SDL", "surfaceCreated()");
-		holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
-		SDLActivity.createEGLSurface();
-		//		enableSensor(Sensor.TYPE_ACCELEROMETER, true);
-	}
+    // Called when we have a valid drawing surface
+    public void surfaceCreated(SurfaceHolder holder) {
+        Log.v("SDL", "surfaceCreated()");
+        holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
+        SDLActivity.createEGLSurface();
+        //      enableSensor(Sensor.TYPE_ACCELEROMETER, true);
+    }
 
-	// Called when we lose the surface
-	public void surfaceDestroyed(SurfaceHolder holder) {
-		Log.v("SDL", "surfaceDestroyed()");
-		SDLActivity.nativePause();
-		//		enableSensor(Sensor.TYPE_ACCELEROMETER, false);
-	}
+    // Called when we lose the surface
+    public void surfaceDestroyed(SurfaceHolder holder) {
+        Log.v("SDL", "surfaceDestroyed()");
+        SDLActivity.nativePause();
+        //      enableSensor(Sensor.TYPE_ACCELEROMETER, false);
+    }
 
-	// Called when the surface is resized
-	public void surfaceChanged(SurfaceHolder holder,
-			int format, int width, int height) {
-		Log.v("SDL", "surfaceChanged()");
+    // Called when the surface is resized
+    public void surfaceChanged(SurfaceHolder holder,
+            int format, int width, int height) {
+        Log.v("SDL", "surfaceChanged()");
 
-		int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default
-		switch (format) {
-		case PixelFormat.A_8:
-			Log.v("SDL", "pixel format A_8");
-			break;
-		case PixelFormat.LA_88:
-			Log.v("SDL", "pixel format LA_88");
-			break;
-		case PixelFormat.L_8:
-			Log.v("SDL", "pixel format L_8");
-			break;
-		case PixelFormat.RGBA_4444:
-			Log.v("SDL", "pixel format RGBA_4444");
-			sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444
-			break;
-		case PixelFormat.RGBA_5551:
-			Log.v("SDL", "pixel format RGBA_5551");
-			sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551
-			break;
-		case PixelFormat.RGBA_8888:
-			Log.v("SDL", "pixel format RGBA_8888");
-			sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888
-			break;
-		case PixelFormat.RGBX_8888:
-			Log.v("SDL", "pixel format RGBX_8888");
-			sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888
-			break;
-		case PixelFormat.RGB_332:
-			Log.v("SDL", "pixel format RGB_332");
-			sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332
-			break;
-		case PixelFormat.RGB_565:
-			Log.v("SDL", "pixel format RGB_565");
-			sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565
-			break;
-		case PixelFormat.RGB_888:
-			Log.v("SDL", "pixel format RGB_888");
-			// Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
-			sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888
-			break;
-		default:
-			Log.v("SDL", "pixel format unknown " + format);
-			break;
-		}
-		SDLActivity.onNativeResize(width, height, sdlFormat);
-		Log.v("SDL", "Window size:" + width + "x"+height);
+        int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default
+        switch (format) {
+        case PixelFormat.A_8:
+            Log.v("SDL", "pixel format A_8");
+            break;
+        case PixelFormat.LA_88:
+            Log.v("SDL", "pixel format LA_88");
+            break;
+        case PixelFormat.L_8:
+            Log.v("SDL", "pixel format L_8");
+            break;
+        case PixelFormat.RGBA_4444:
+            Log.v("SDL", "pixel format RGBA_4444");
+            sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444
+            break;
+        case PixelFormat.RGBA_5551:
+            Log.v("SDL", "pixel format RGBA_5551");
+            sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551
+            break;
+        case PixelFormat.RGBA_8888:
+            Log.v("SDL", "pixel format RGBA_8888");
+            sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888
+            break;
+        case PixelFormat.RGBX_8888:
+            Log.v("SDL", "pixel format RGBX_8888");
+            sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888
+            break;
+        case PixelFormat.RGB_332:
+            Log.v("SDL", "pixel format RGB_332");
+            sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332
+            break;
+        case PixelFormat.RGB_565:
+            Log.v("SDL", "pixel format RGB_565");
+            sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565
+            break;
+        case PixelFormat.RGB_888:
+            Log.v("SDL", "pixel format RGB_888");
+            // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
+            sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888
+            break;
+        default:
+            Log.v("SDL", "pixel format unknown " + format);
+            break;
+        }
+        SDLActivity.onNativeResize(width, height, sdlFormat);
+        Log.v("SDL", "Window size:" + width + "x"+height);
 
-		SDLActivity.startApp(width, height, config, netgame);
-	}
+        SDLActivity.startApp(width, height, config, netgame);
+    }
 
-	// unused
-	public void onDraw(Canvas canvas) {}
+    // unused
+    public void onDraw(Canvas canvas) {}
 
 
 
 
-	// Key events
-	public boolean onKey(View  v, int keyCode, KeyEvent event) {
-		switch(keyCode){
-		case KeyEvent.KEYCODE_BACK:
-			Log.d("SDL", "KEYCODE_BACK");
-			SDLActivity.nativeQuit();
+    // Key events
+    public boolean onKey(View  v, int keyCode, KeyEvent event) {
+        switch(keyCode){
+        case KeyEvent.KEYCODE_BACK:
+            Log.d("SDL", "KEYCODE_BACK");
+            SDLActivity.nativeQuit();
             return true;
-		case KeyEvent.KEYCODE_VOLUME_DOWN:
-		case KeyEvent.KEYCODE_VOLUME_UP:
-		case KeyEvent.KEYCODE_VOLUME_MUTE:
-			return false;
-		}
-		if (event.getAction() == KeyEvent.ACTION_DOWN) {
-			//Log.v("SDL", "key down: " + keyCode);
-			SDLActivity.onNativeKeyDown(keyCode);
-			return true;
-		}
-		else if (event.getAction() == KeyEvent.ACTION_UP) {
-			//Log.v("SDL", "key up: " + keyCode);
-			SDLActivity.onNativeKeyUp(keyCode);
-			return true;
-		}
+        case KeyEvent.KEYCODE_VOLUME_DOWN:
+        case KeyEvent.KEYCODE_VOLUME_UP:
+        case KeyEvent.KEYCODE_VOLUME_MUTE:
+            return false;
+        }
+        if (event.getAction() == KeyEvent.ACTION_DOWN) {
+            //Log.v("SDL", "key down: " + keyCode);
+            SDLActivity.onNativeKeyDown(keyCode);
+            return true;
+        }
+        else if (event.getAction() == KeyEvent.ACTION_UP) {
+            //Log.v("SDL", "key up: " + keyCode);
+            SDLActivity.onNativeKeyUp(keyCode);
+            return true;
+        }
 
-		return false;
-	}
+        return false;
+    }
 
-	// Touch events
-	public boolean onTouch(View v, MotionEvent event) {
-		final int action = event.getAction() & MotionEvent.ACTION_MASK;
-		final int actionPointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;		
+    // Touch events
+    public boolean onTouch(View v, MotionEvent event) {
+        final int action = event.getAction() & MotionEvent.ACTION_MASK;
+        final int actionPointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
 
-		if (action == MotionEvent.ACTION_MOVE) {
-			// TODO send motion to every pointer if its position has
-			// changed since prev event.
-			for (int i = 0; i < event.getPointerCount(); i++) {
-				sendNativeTouch(event, action, i);
-			}
-		} else {
-			sendNativeTouch(event, action, actionPointerIndex);
-		}
-		return true;
-	} 
-	
-	private static void sendNativeTouch(MotionEvent event, int action, int pointerIndex) {
-		int touchDevId = event.getDeviceId();
-		int pointerFingerId = event.getPointerId(pointerIndex);
-		float x = event.getX(pointerIndex);
-		float y = event.getY(pointerIndex);
-		float pressure = event.getPressure(pointerIndex);
-		SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, pressure);
-	}
+        if (action == MotionEvent.ACTION_MOVE) {
+            // TODO send motion to every pointer if its position has
+            // changed since prev event.
+            for (int i = 0; i < event.getPointerCount(); i++) {
+                sendNativeTouch(event, action, i);
+            }
+        } else {
+            sendNativeTouch(event, action, actionPointerIndex);
+        }
+        return true;
+    }
+
+    private static void sendNativeTouch(MotionEvent event, int action, int pointerIndex) {
+        int touchDevId = event.getDeviceId();
+        int pointerFingerId = event.getPointerId(pointerIndex);
+        float x = event.getX(pointerIndex);
+        float y = event.getY(pointerIndex);
+        float pressure = event.getPressure(pointerIndex);
+        SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, pressure);
+    }
 
-	// Sensor events
-	public void enableSensor(int sensortype, boolean enabled) {
-		// TODO: This uses getDefaultSensor - what if we have >1 accels?
-		if (enabled) {
-			mSensorManager.registerListener(this, 
-					mSensorManager.getDefaultSensor(sensortype), 
-					SensorManager.SENSOR_DELAY_GAME, null);
-		} else {
-			mSensorManager.unregisterListener(this, 
-					mSensorManager.getDefaultSensor(sensortype));
-		}
-	}
+    // Sensor events
+    public void enableSensor(int sensortype, boolean enabled) {
+        // TODO: This uses getDefaultSensor - what if we have >1 accels?
+        if (enabled) {
+            mSensorManager.registerListener(this,
+                    mSensorManager.getDefaultSensor(sensortype),
+                    SensorManager.SENSOR_DELAY_GAME, null);
+        } else {
+            mSensorManager.unregisterListener(this,
+                    mSensorManager.getDefaultSensor(sensortype));
+        }
+    }
 
-	public void onAccuracyChanged(Sensor sensor, int accuracy) {
-		// TODO
-	}
+    public void onAccuracyChanged(Sensor sensor, int accuracy) {
+        // TODO
+    }
 
-	public void onSensorChanged(SensorEvent event) {
-		if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
-			SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH,
-					event.values[1] / SensorManager.GRAVITY_EARTH,
-					event.values[2] / SensorManager.GRAVITY_EARTH);
-		}
-	}
+    public void onSensorChanged(SensorEvent event) {
+        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
+            SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH,
+                    event.values[1] / SensorManager.GRAVITY_EARTH,
+                    event.values[2] / SensorManager.GRAVITY_EARTH);
+        }
+    }
 }
 
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SettingsFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SettingsFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -51,177 +51,177 @@
 import android.widget.Toast;
 
 public class SettingsFragment extends Fragment {
-	private Spinner styleSpinner, schemeSpinner, weaponsetSpinner, themeSpinner;
-	private ImageView themeIcon;
-	
-	private List<String> styles;
-	private List<Scheme> schemes;
-	private List<Weaponset> weaponsets;
-	private List<String> themes;
-	
-	private RoomStateManager stateManager;
+    private Spinner styleSpinner, schemeSpinner, weaponsetSpinner, themeSpinner;
+    private ImageView themeIcon;
+
+    private List<String> styles;
+    private List<Scheme> schemes;
+    private List<Weaponset> weaponsets;
+    private List<String> themes;
+
+    private RoomStateManager stateManager;
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        View v = inflater.inflate(R.layout.fragment_settings, container, false);
+        themeIcon = (ImageView)v.findViewById(R.id.imgTheme);
+
+        try {
+            styles = FrontendDataUtils.getGameStyles(getActivity());
+            schemes = Schemes.loadAllSchemes(getActivity());
+            weaponsets = Weaponsets.loadAllWeaponsets(getActivity());
+            themes = FrontendDataUtils.getThemes(getActivity());
+        } catch (IOException e) {
+            Toast.makeText(getActivity().getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
+            getActivity().finish();
+            return null;
+        }
+
+        Collections.sort(styles, String.CASE_INSENSITIVE_ORDER);
+        Collections.sort(schemes, Scheme.NAME_ORDER);
+        Collections.sort(weaponsets, Weaponset.NAME_ORDER);
+        Collections.sort(themes, String.CASE_INSENSITIVE_ORDER);
+
+        styleSpinner = prepareSpinner(v, R.id.spinGameplay, styles, styleSelectedListener);
+        schemeSpinner = prepareSpinner(v, R.id.spinGamescheme, Schemes.toNameList(schemes), schemeSelectedListener);
+        weaponsetSpinner = prepareSpinner(v, R.id.spinweapons, Weaponsets.toNameList(weaponsets), weaponsetSelectedListener);
+        themeSpinner = prepareSpinner(v, R.id.spinTheme, themes, themeSelectedListener);
+
+        stateManager.addListener(roomStateChangeListener);
 
-	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container,
-			Bundle savedInstanceState) {
-		View v = inflater.inflate(R.layout.fragment_settings, container, false);
-		themeIcon = (ImageView)v.findViewById(R.id.imgTheme);
-		
-		try {
-			styles = FrontendDataUtils.getGameStyles(getActivity());
-			schemes = Schemes.loadAllSchemes(getActivity());
-			weaponsets = Weaponsets.loadAllWeaponsets(getActivity());
-			themes = FrontendDataUtils.getThemes(getActivity());
-		} catch (IOException e) {
-			Toast.makeText(getActivity().getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
-			getActivity().finish();
-			return null;
-		}
-		
-		Collections.sort(styles, String.CASE_INSENSITIVE_ORDER);
-		Collections.sort(schemes, Scheme.NAME_ORDER);
-		Collections.sort(weaponsets, Weaponset.NAME_ORDER);
-		Collections.sort(themes, String.CASE_INSENSITIVE_ORDER);
-		
-		styleSpinner = prepareSpinner(v, R.id.spinGameplay, styles, styleSelectedListener);
-		schemeSpinner = prepareSpinner(v, R.id.spinGamescheme, Schemes.toNameList(schemes), schemeSelectedListener);
-		weaponsetSpinner = prepareSpinner(v, R.id.spinweapons, Weaponsets.toNameList(weaponsets), weaponsetSelectedListener);
-		themeSpinner = prepareSpinner(v, R.id.spinTheme, themes, themeSelectedListener);
-		
-		stateManager.addListener(roomStateChangeListener);
+        if(stateManager.getGameStyle() != null) {
+            styleSpinner.setSelection(styles.indexOf(stateManager.getGameStyle()), false);
+        }
+        if(stateManager.getScheme() != null) {
+            schemeSpinner.setSelection(getSchemePosition(schemes, stateManager.getScheme().name), false);
+        }
+        if(stateManager.getWeaponset() != null) {
+            weaponsetSpinner.setSelection(getWeaponsetPosition(weaponsets, stateManager.getWeaponset().name), false);
+        }
+        if(stateManager.getMapRecipe() != null) {
+            themeSpinner.setSelection(themes.indexOf(stateManager.getMapRecipe().theme), false);
+        }
+
+        setChiefState(stateManager.getChiefStatus());
+
+        return v;
+    }
+
+    private static Spinner prepareSpinner(View v, int id, List<String> items, OnItemSelectedListener itemSelectedListener) {
+        Spinner spinner = (Spinner)v.findViewById(id);
+        ArrayAdapter<String> adapter = new ArrayAdapter<String>(v.getContext(), R.layout.listview_item, items);
+        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        spinner.setAdapter(adapter);
+        spinner.setOnItemSelectedListener(itemSelectedListener);
+        return spinner;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        try {
+            stateManager = ((RoomStateManager.Provider)getActivity()).getRoomStateManager();
+        } catch(ClassCastException e) {
+            throw new RuntimeException("Hosting activity must implement RoomStateManager.Provider.", e);
+        }
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        stateManager.removeListener(roomStateChangeListener);
+    }
 
-		if(stateManager.getGameStyle() != null) {
-			styleSpinner.setSelection(styles.indexOf(stateManager.getGameStyle()), false);
-		}
-		if(stateManager.getScheme() != null) {
-			schemeSpinner.setSelection(getSchemePosition(schemes, stateManager.getScheme().name), false);
-		}
-		if(stateManager.getWeaponset() != null) {
-			weaponsetSpinner.setSelection(getWeaponsetPosition(weaponsets, stateManager.getWeaponset().name), false);
-		}
-		if(stateManager.getMapRecipe() != null) {
-			themeSpinner.setSelection(themes.indexOf(stateManager.getMapRecipe().theme), false);
-		}
-		
-		setChiefState(stateManager.getChiefStatus());
-		
-		return v;
-	}
-	
-	private static Spinner prepareSpinner(View v, int id, List<String> items, OnItemSelectedListener itemSelectedListener) {
-		Spinner spinner = (Spinner)v.findViewById(id);
-		ArrayAdapter<String> adapter = new ArrayAdapter<String>(v.getContext(), R.layout.listview_item, items);
-		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-		spinner.setAdapter(adapter);
-		spinner.setOnItemSelectedListener(itemSelectedListener);
-		return spinner;
-	}
-	
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		try {
-			stateManager = ((RoomStateManager.Provider)getActivity()).getRoomStateManager();
-		} catch(ClassCastException e) {
-			throw new RuntimeException("Hosting activity must implement RoomStateManager.Provider.", e);
-		}
-	}
-	
-	@Override
-	public void onDestroy() {
-		super.onDestroy();
-		stateManager.removeListener(roomStateChangeListener);
-	}
-	
-	private static int getSchemePosition(List<Scheme> schemes, String scheme) {
-		for(int i=0; i<schemes.size(); i++) {
-			if(schemes.get(i).name.equals(scheme)) {
-				return i;
-			}
-		}
-		return -1;
-	}
-	
-	private static int getWeaponsetPosition(List<Weaponset> weaponsets, String weaponset) {
-		for(int i=0; i<weaponsets.size(); i++) {
-			if(weaponsets.get(i).name.equals(weaponset)) {
-				return i;
-			}
-		}
-		return -1;
-	}
-	
-	private void setChiefState(boolean chiefState) {
-		styleSpinner.setEnabled(chiefState);
-		schemeSpinner.setEnabled(chiefState);
-		weaponsetSpinner.setEnabled(chiefState);
-		themeSpinner.setEnabled(chiefState);
-		
-		if(chiefState) {
-			stateManager.changeGameStyle(styles.get(styleSpinner.getSelectedItemPosition()));
-			stateManager.changeScheme(schemes.get(schemeSpinner.getSelectedItemPosition()));
-			stateManager.changeWeaponset(weaponsets.get(weaponsetSpinner.getSelectedItemPosition()));
-			stateManager.changeMapTheme(themes.get(themeSpinner.getSelectedItemPosition()));
-		}
-	}
-	
-	private final OnItemSelectedListener styleSelectedListener = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
-			stateManager.changeGameStyle(styles.get(position));
-		}
-		public void onNothingSelected(AdapterView<?> arg0) {}
-	};
-	
-	private final OnItemSelectedListener schemeSelectedListener = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
-			stateManager.changeScheme(schemes.get(position));
-		}
-		public void onNothingSelected(AdapterView<?> arg0) {}
-	};
-	
-	private final OnItemSelectedListener weaponsetSelectedListener = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
-			stateManager.changeWeaponset(weaponsets.get(position));
-		}
-		public void onNothingSelected(AdapterView<?> arg0) {}
-	};
-	
-	private final OnItemSelectedListener themeSelectedListener = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
-			stateManager.changeMapTheme(themes.get(position));
-			String theme = themes.get(position);
-			try {
-				File iconFile = FileUtils.getDataPathFile(getActivity(), "Themes", theme, "icon@2X.png");
-				Drawable themeIconDrawable = Drawable.createFromPath(iconFile.getAbsolutePath());
-				themeIcon.setImageDrawable(themeIconDrawable);
-			} catch (FileNotFoundException e) {
-				Log.e("SettingsFragment", "Unable to find preview for theme "+theme, e);
-			}
-		};
-		public void onNothingSelected(AdapterView<?> arg0) {};
-	};
-	
-	private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.Listener() {
-		public void onWeaponsetChanged(Weaponset weaponset) {
-			weaponsetSpinner.setSelection(getWeaponsetPosition(weaponsets, weaponset.name));
-		}
-		
-		public void onTeamsChanged(Map<String, TeamInGame> teams) {}
-		
-		public void onSchemeChanged(Scheme scheme) {
-			schemeSpinner.setSelection(getSchemePosition(schemes, scheme.name));
-		}
-		
-		public void onMapChanged(MapRecipe recipe) {
-			themeSpinner.setSelection(themes.indexOf(recipe.theme));
-		}
-		
-		public void onGameStyleChanged(String gameStyle) {
-			styleSpinner.setSelection(styles.indexOf(gameStyle));
-		}
-		
-		public void onChiefStatusChanged(boolean isChief) {
-			setChiefState(isChief);
-		}
-	};
+    private static int getSchemePosition(List<Scheme> schemes, String scheme) {
+        for(int i=0; i<schemes.size(); i++) {
+            if(schemes.get(i).name.equals(scheme)) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    private static int getWeaponsetPosition(List<Weaponset> weaponsets, String weaponset) {
+        for(int i=0; i<weaponsets.size(); i++) {
+            if(weaponsets.get(i).name.equals(weaponset)) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    private void setChiefState(boolean chiefState) {
+        styleSpinner.setEnabled(chiefState);
+        schemeSpinner.setEnabled(chiefState);
+        weaponsetSpinner.setEnabled(chiefState);
+        themeSpinner.setEnabled(chiefState);
+
+        if(chiefState) {
+            stateManager.changeGameStyle(styles.get(styleSpinner.getSelectedItemPosition()));
+            stateManager.changeScheme(schemes.get(schemeSpinner.getSelectedItemPosition()));
+            stateManager.changeWeaponset(weaponsets.get(weaponsetSpinner.getSelectedItemPosition()));
+            stateManager.changeMapTheme(themes.get(themeSpinner.getSelectedItemPosition()));
+        }
+    }
+
+    private final OnItemSelectedListener styleSelectedListener = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
+            stateManager.changeGameStyle(styles.get(position));
+        }
+        public void onNothingSelected(AdapterView<?> arg0) {}
+    };
+
+    private final OnItemSelectedListener schemeSelectedListener = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
+            stateManager.changeScheme(schemes.get(position));
+        }
+        public void onNothingSelected(AdapterView<?> arg0) {}
+    };
+
+    private final OnItemSelectedListener weaponsetSelectedListener = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
+            stateManager.changeWeaponset(weaponsets.get(position));
+        }
+        public void onNothingSelected(AdapterView<?> arg0) {}
+    };
+
+    private final OnItemSelectedListener themeSelectedListener = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
+            stateManager.changeMapTheme(themes.get(position));
+            String theme = themes.get(position);
+            try {
+                File iconFile = FileUtils.getDataPathFile(getActivity(), "Themes", theme, "icon@2X.png");
+                Drawable themeIconDrawable = Drawable.createFromPath(iconFile.getAbsolutePath());
+                themeIcon.setImageDrawable(themeIconDrawable);
+            } catch (FileNotFoundException e) {
+                Log.e("SettingsFragment", "Unable to find preview for theme "+theme, e);
+            }
+        };
+        public void onNothingSelected(AdapterView<?> arg0) {};
+    };
+
+    private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.Listener() {
+        public void onWeaponsetChanged(Weaponset weaponset) {
+            weaponsetSpinner.setSelection(getWeaponsetPosition(weaponsets, weaponset.name));
+        }
+
+        public void onTeamsChanged(Map<String, TeamInGame> teams) {}
+
+        public void onSchemeChanged(Scheme scheme) {
+            schemeSpinner.setSelection(getSchemePosition(schemes, scheme.name));
+        }
+
+        public void onMapChanged(MapRecipe recipe) {
+            themeSpinner.setSelection(themes.indexOf(recipe.theme));
+        }
+
+        public void onGameStyleChanged(String gameStyle) {
+            styleSpinner.setSelection(styles.indexOf(gameStyle));
+        }
+
+        public void onChiefStatusChanged(boolean isChief) {
+            setChiefState(isChief);
+        }
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/StartNetgameDialog.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/StartNetgameDialog.java	Tue Jan 21 22:53:15 2014 +0100
@@ -36,60 +36,60 @@
 import android.widget.TextView.OnEditorActionListener;
 
 public class StartNetgameDialog extends DialogFragment {
-	private static final String PREF_PLAYERNAME = "playerName";
-	
-	@Override
-	public Dialog onCreateDialog(Bundle savedInstanceState) {
-		SharedPreferences prefs = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
-		final String playerName = prefs.getString(PREF_PLAYERNAME, "Player");
-		final EditText editText = new EditText(getActivity());
-		final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-		
-		editText.setText(playerName);
-		editText.setHint(R.string.start_netgame_dialog_playername_hint);
-		editText.setId(android.R.id.text1);
-		editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
-		editText.setSingleLine();
+    private static final String PREF_PLAYERNAME = "playerName";
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        SharedPreferences prefs = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
+        final String playerName = prefs.getString(PREF_PLAYERNAME, "Player");
+        final EditText editText = new EditText(getActivity());
+        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+
+        editText.setText(playerName);
+        editText.setHint(R.string.start_netgame_dialog_playername_hint);
+        editText.setId(android.R.id.text1);
+        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
+        editText.setSingleLine();
+
+        builder.setTitle(R.string.start_netgame_dialog_title);
+        builder.setMessage(R.string.start_netgame_dialog_message);
+        builder.setView(editText);
+        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+            public void onClick(DialogInterface dialog, int which) {
+                editText.setText(playerName);
+            }
+        });
 
-		builder.setTitle(R.string.start_netgame_dialog_title);
-		builder.setMessage(R.string.start_netgame_dialog_message);
-		builder.setView(editText);
-		builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
-			public void onClick(DialogInterface dialog, int which) {
-				editText.setText(playerName);
-			}
-		});
-		
-		editText.setOnEditorActionListener(new OnEditorActionListener() {
-			public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
-				boolean handled = false;
-				if(actionId == EditorInfo.IME_ACTION_DONE) {
-					startConnection(v.getText().toString());
-					handled = true;
-				}
-				return handled;
-			}
-		});
-		
-		builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-			public void onClick(DialogInterface dialog, int which) {
-				startConnection(editText.getText().toString());
-			}
-		});
+        editText.setOnEditorActionListener(new OnEditorActionListener() {
+            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+                boolean handled = false;
+                if(actionId == EditorInfo.IME_ACTION_DONE) {
+                    startConnection(v.getText().toString());
+                    handled = true;
+                }
+                return handled;
+            }
+        });
+
+        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+            public void onClick(DialogInterface dialog, int which) {
+                startConnection(editText.getText().toString());
+            }
+        });
 
-		return builder.create();
-	}
-	
-	private void startConnection(String username) {
-		if(username.length() > 0) {
-			SharedPreferences prefs = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
-			Editor edit = prefs.edit();
-			edit.putString(PREF_PLAYERNAME, username);
-			edit.commit();
-			
-			Netplay.getAppInstance(getActivity().getApplicationContext()).connectToDefaultServer(username);
-			getDialog().dismiss();
-			((MainActivity)getActivity()).onNetConnectingStarted();
-		}
-	}
+        return builder.create();
+    }
+
+    private void startConnection(String username) {
+        if(username.length() > 0) {
+            SharedPreferences prefs = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
+            Editor edit = prefs.edit();
+            edit.putString(PREF_PLAYERNAME, username);
+            edit.commit();
+
+            Netplay.getAppInstance(getActivity().getApplicationContext()).connectToDefaultServer(username);
+            getDialog().dismiss();
+            ((MainActivity)getActivity()).onNetConnectingStarted();
+        }
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamAddDialog.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamAddDialog.java	Tue Jan 21 22:53:15 2014 +0100
@@ -37,76 +37,76 @@
 import android.support.v4.app.DialogFragment;
 
 public class TeamAddDialog extends DialogFragment {
-	private static final String STATE_TEAMS_ALREADY_IN_GAME = "teamAlreadyInGame";
-	private ArrayList<String> teamsAlreadyInGame;
-	private List<Team> availableTeams;
-	private Listener listener;
-	
-	public static interface Listener {
-		void onTeamAddDialogSubmitted(Team newTeam);
-	}
-	
-	public TeamAddDialog() {
-		// Only for reflection-based instantiation by the framework
-	}
-	
-	TeamAddDialog(Collection<String> teamsAlreadyInGame) {
-		this.teamsAlreadyInGame = new ArrayList<String>(teamsAlreadyInGame);
-	}
-	
-	@Override
-	public void onAttach(Activity activity) {
-		super.onAttach(activity);
-		try {
-			listener = (Listener) activity;
-		} catch(ClassCastException e) {
-			throw new ClassCastException("Activity " + activity + " must implement TeamAddDialog.Listener to use TeamAddDialog.");
-		}
-	}
-	
-	@Override
-	public void onDetach() {
-		super.onDetach();
-		listener = null;
-	}
-	
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		if(savedInstanceState != null) {
-			teamsAlreadyInGame = savedInstanceState.getStringArrayList(STATE_TEAMS_ALREADY_IN_GAME);
-		}
-		availableTeams = new ArrayList<Team>();
-		List<Team> teams = FrontendDataUtils.getTeams(getActivity());
-		for(Team team : teams) {
-			if(!teamsAlreadyInGame.contains(team.name)) {
-				availableTeams.add(team);
-			}
-		}
-		Collections.sort(availableTeams, Team.NAME_ORDER);
-	}
-	
-	// TODO use icons for the teams (corresponding to botlevel) 
-	@Override
-	public Dialog onCreateDialog(Bundle savedInstanceState) {
-		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-		builder.setTitle(R.string.dialog_addteam_title);
-		builder.setIcon(R.drawable.human);
-		String[] teamNames = new String[availableTeams.size()];
-		for(int i=0; i<availableTeams.size(); i++) {
-			teamNames[i] = availableTeams.get(i).name;
-		}
-		builder.setItems(teamNames, new OnClickListener() {
-			public void onClick(DialogInterface dialog, int which) {
-				listener.onTeamAddDialogSubmitted(availableTeams.get(which));
-			}
-		});
-		return builder.create();
-	}
-	
-	@Override
-	public void onSaveInstanceState(Bundle outState) {
-		super.onSaveInstanceState(outState);
-		outState.putStringArrayList(STATE_TEAMS_ALREADY_IN_GAME, teamsAlreadyInGame);
-	}
+    private static final String STATE_TEAMS_ALREADY_IN_GAME = "teamAlreadyInGame";
+    private ArrayList<String> teamsAlreadyInGame;
+    private List<Team> availableTeams;
+    private Listener listener;
+
+    public static interface Listener {
+        void onTeamAddDialogSubmitted(Team newTeam);
+    }
+
+    public TeamAddDialog() {
+        // Only for reflection-based instantiation by the framework
+    }
+
+    TeamAddDialog(Collection<String> teamsAlreadyInGame) {
+        this.teamsAlreadyInGame = new ArrayList<String>(teamsAlreadyInGame);
+    }
+
+    @Override
+    public void onAttach(Activity activity) {
+        super.onAttach(activity);
+        try {
+            listener = (Listener) activity;
+        } catch(ClassCastException e) {
+            throw new ClassCastException("Activity " + activity + " must implement TeamAddDialog.Listener to use TeamAddDialog.");
+        }
+    }
+
+    @Override
+    public void onDetach() {
+        super.onDetach();
+        listener = null;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if(savedInstanceState != null) {
+            teamsAlreadyInGame = savedInstanceState.getStringArrayList(STATE_TEAMS_ALREADY_IN_GAME);
+        }
+        availableTeams = new ArrayList<Team>();
+        List<Team> teams = FrontendDataUtils.getTeams(getActivity());
+        for(Team team : teams) {
+            if(!teamsAlreadyInGame.contains(team.name)) {
+                availableTeams.add(team);
+            }
+        }
+        Collections.sort(availableTeams, Team.NAME_ORDER);
+    }
+
+    // TODO use icons for the teams (corresponding to botlevel)
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+        builder.setTitle(R.string.dialog_addteam_title);
+        builder.setIcon(R.drawable.human);
+        String[] teamNames = new String[availableTeams.size()];
+        for(int i=0; i<availableTeams.size(); i++) {
+            teamNames[i] = availableTeams.get(i).name;
+        }
+        builder.setItems(teamNames, new OnClickListener() {
+            public void onClick(DialogInterface dialog, int which) {
+                listener.onTeamAddDialogSubmitted(availableTeams.get(which));
+            }
+        });
+        return builder.create();
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putStringArrayList(STATE_TEAMS_ALREADY_IN_GAME, teamsAlreadyInGame);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamCreatorActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamCreatorActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -61,341 +61,341 @@
  * as parameter oldTeamName.
  */
 public class TeamCreatorActivity extends Activity implements Runnable {
-	public static final String PARAMETER_EXISTING_TEAMNAME = "existingTeamName";
-	private static final String TAG = TeamCreatorActivity.class.getSimpleName();
-	
-	private TextView name;
-	private Spinner difficulty, grave, flag, voice, fort;
-	private ImageView imgFort;
-	private ArrayList<ImageButton> hogDice = new ArrayList<ImageButton>();
-	private ArrayList<Spinner> hogHat = new ArrayList<Spinner>();
-	private ArrayList<EditText> hogName = new ArrayList<EditText>();
-	private ImageButton voiceButton;
-	private ScrollView scroller;
-	private MediaPlayer mp = null;
-	private boolean initComplete = false;
-	
-	private String existingTeamName = null;
+    public static final String PARAMETER_EXISTING_TEAMNAME = "existingTeamName";
+    private static final String TAG = TeamCreatorActivity.class.getSimpleName();
+
+    private TextView name;
+    private Spinner difficulty, grave, flag, voice, fort;
+    private ImageView imgFort;
+    private ArrayList<ImageButton> hogDice = new ArrayList<ImageButton>();
+    private ArrayList<Spinner> hogHat = new ArrayList<Spinner>();
+    private ArrayList<EditText> hogName = new ArrayList<EditText>();
+    private ImageButton voiceButton;
+    private ScrollView scroller;
+    private MediaPlayer mp = null;
+    private boolean initComplete = false;
+
+    private String existingTeamName = null;
 
-	private final List<Map<String, ?>> flagsData = new ArrayList<Map<String, ?>>();
-	private final List<Map<String, ?>> typesData = new ArrayList<Map<String, ?>>();
-	private final List<Map<String, ?>> gravesData = new ArrayList<Map<String, ?>>();
-	private final List<Map<String, ?>> hatsData = new ArrayList<Map<String, ?>>();
-	private final List<String> voicesData = new ArrayList<String>();
-	private final List<String> fortsData = new ArrayList<String>();
+    private final List<Map<String, ?>> flagsData = new ArrayList<Map<String, ?>>();
+    private final List<Map<String, ?>> typesData = new ArrayList<Map<String, ?>>();
+    private final List<Map<String, ?>> gravesData = new ArrayList<Map<String, ?>>();
+    private final List<Map<String, ?>> hatsData = new ArrayList<Map<String, ?>>();
+    private final List<String> voicesData = new ArrayList<String>();
+    private final List<String> fortsData = new ArrayList<String>();
+
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        initComplete = false;
+
+        // Restore state and read parameters
+        if(savedInstanceState != null) {
+            existingTeamName = savedInstanceState.getString(PARAMETER_EXISTING_TEAMNAME);
+        } else {
+            existingTeamName = getIntent().getStringExtra(PARAMETER_EXISTING_TEAMNAME);
+        }
 
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		initComplete = false;
-		
-		// Restore state and read parameters 
-		if(savedInstanceState != null) {
-			existingTeamName = savedInstanceState.getString(PARAMETER_EXISTING_TEAMNAME);
-		} else {
-			existingTeamName = getIntent().getStringExtra(PARAMETER_EXISTING_TEAMNAME);
-		}
-		
-		// Set up view
-		setContentView(R.layout.team_creation);
+        // Set up view
+        setContentView(R.layout.team_creation);
 
-		name = (TextView) findViewById(R.id.txtName);
-		difficulty = (Spinner) findViewById(R.id.spinType);
-		grave = (Spinner) findViewById(R.id.spinGrave);
-		flag = (Spinner) findViewById(R.id.spinFlag);
-		voice = (Spinner) findViewById(R.id.spinVoice);
-		fort = (Spinner) findViewById(R.id.spinFort);
+        name = (TextView) findViewById(R.id.txtName);
+        difficulty = (Spinner) findViewById(R.id.spinType);
+        grave = (Spinner) findViewById(R.id.spinGrave);
+        flag = (Spinner) findViewById(R.id.spinFlag);
+        voice = (Spinner) findViewById(R.id.spinVoice);
+        fort = (Spinner) findViewById(R.id.spinFort);
 
-		imgFort = (ImageView) findViewById(R.id.imgFort);
+        imgFort = (ImageView) findViewById(R.id.imgFort);
+
+        voiceButton = (ImageButton) findViewById(R.id.btnPlay);
+
+        scroller = (ScrollView) findViewById(R.id.scroller);
 
-		voiceButton = (ImageButton) findViewById(R.id.btnPlay);
-
-		scroller = (ScrollView) findViewById(R.id.scroller);
-
-		// Wire view elements
-		LinearLayout ll = (LinearLayout) findViewById(R.id.HogsContainer);
-		for (int i = 0; i < ll.getChildCount(); i++) {
-			RelativeLayout team_creation_entry = (RelativeLayout) ll.getChildAt(i);
+        // Wire view elements
+        LinearLayout ll = (LinearLayout) findViewById(R.id.HogsContainer);
+        for (int i = 0; i < ll.getChildCount(); i++) {
+            RelativeLayout team_creation_entry = (RelativeLayout) ll.getChildAt(i);
 
-			hogHat.add((Spinner) team_creation_entry
-					.findViewById(R.id.spinTeam1));
-			hogDice.add((ImageButton) team_creation_entry
-					.findViewById(R.id.btnTeam1));
-			hogName.add((EditText) team_creation_entry
-					.findViewById(R.id.txtTeam1));
-		}
+            hogHat.add((Spinner) team_creation_entry
+                    .findViewById(R.id.spinTeam1));
+            hogDice.add((ImageButton) team_creation_entry
+                    .findViewById(R.id.btnTeam1));
+            hogName.add((EditText) team_creation_entry
+                    .findViewById(R.id.txtTeam1));
+        }
 
-		grave.setAdapter(createMapSpinnerAdapter(gravesData));
-		flag.setAdapter(createMapSpinnerAdapter(flagsData));
-		difficulty.setAdapter(createMapSpinnerAdapter(typesData));
-		SpinnerAdapter hatAdapter = createMapSpinnerAdapter(hatsData);
-		for (Spinner spin : hogHat) {
-			spin.setAdapter(hatAdapter);
-		}
+        grave.setAdapter(createMapSpinnerAdapter(gravesData));
+        flag.setAdapter(createMapSpinnerAdapter(flagsData));
+        difficulty.setAdapter(createMapSpinnerAdapter(typesData));
+        SpinnerAdapter hatAdapter = createMapSpinnerAdapter(hatsData);
+        for (Spinner spin : hogHat) {
+            spin.setAdapter(hatAdapter);
+        }
 
 
-		voice.setAdapter(createListSpinnerAdapter(voicesData));
-		voiceButton.setOnClickListener(voiceClicker);
+        voice.setAdapter(createListSpinnerAdapter(voicesData));
+        voiceButton.setOnClickListener(voiceClicker);
+
+        fort.setAdapter(createListSpinnerAdapter(fortsData));
+        fort.setOnItemSelectedListener(fortSelector);
+
+        new Thread(this).start();
+    }
+
+    private SpinnerAdapter createMapSpinnerAdapter(List<? extends Map<String, ?>> data) {
+        SimpleAdapter sa = new SimpleAdapter(this, data,
+                R.layout.spinner_textimg_entry, new String[] { "txt", "img" },
+                new int[] { R.id.spinner_txt, R.id.spinner_img });
+        sa.setDropDownViewResource(R.layout.spinner_textimg_dropdown_entry);
+        sa.setViewBinder(viewBinder);
+        return sa;
+    }
+
+    private SpinnerAdapter createListSpinnerAdapter(List<String> data) {
+        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listview_item, data);
+        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        return adapter;
+    }
 
-		fort.setAdapter(createListSpinnerAdapter(fortsData));
-		fort.setOnItemSelectedListener(fortSelector);
+    public void run(){
+        try {
+            final List<Map<String, ?>> gravesDataNew = FrontendDataUtils.getGraves(this);
+            runOnUiThread(new Runnable(){
+                public void run() {
+                    gravesData.addAll(gravesDataNew);
+                    ((SimpleAdapter)grave.getAdapter()).notifyDataSetChanged();
+                }
+            });
 
-		new Thread(this).start();
-	}
+            final List<Map<String, ?>> flagsDataNew = FrontendDataUtils.getFlags(this);
+            runOnUiThread(new Runnable(){
+                public void run() {
+                    flagsData.addAll(flagsDataNew);
+                    ((SimpleAdapter)flag.getAdapter()).notifyDataSetChanged();
+                }
+            });
+
+            final List<Map<String, ?>> typesDataNew = FrontendDataUtils.getTypes(this);
+            runOnUiThread(new Runnable(){
+                public void run() {
+                    typesData.addAll(typesDataNew);
+                    ((SimpleAdapter)difficulty.getAdapter()).notifyDataSetChanged();
+                }
+            });
+
+            final List<Map<String, ?>> hatsDataNew = FrontendDataUtils.getHats(this);
+            runOnUiThread(new Runnable(){
+                public void run() {
+                    hatsData.addAll(hatsDataNew);
+                    ((SimpleAdapter)hogHat.get(0).getAdapter()).notifyDataSetChanged();
+                }
+            });
 
-	private SpinnerAdapter createMapSpinnerAdapter(List<? extends Map<String, ?>> data) {
-		SimpleAdapter sa = new SimpleAdapter(this, data,
-				R.layout.spinner_textimg_entry, new String[] { "txt", "img" },
-				new int[] { R.id.spinner_txt, R.id.spinner_img });
-		sa.setDropDownViewResource(R.layout.spinner_textimg_dropdown_entry);
-		sa.setViewBinder(viewBinder);
-		return sa;
-	}
-	
-	private SpinnerAdapter createListSpinnerAdapter(List<String> data) {
-		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listview_item, data);
-		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-		return adapter;
-	}
-	
-	public void run(){
-		try {
-			final List<Map<String, ?>> gravesDataNew = FrontendDataUtils.getGraves(this);
-			runOnUiThread(new Runnable(){
-				public void run() {
-					gravesData.addAll(gravesDataNew);
-					((SimpleAdapter)grave.getAdapter()).notifyDataSetChanged();
-				}
-			});
-			
-			final List<Map<String, ?>> flagsDataNew = FrontendDataUtils.getFlags(this);
-			runOnUiThread(new Runnable(){
-				public void run() {
-					flagsData.addAll(flagsDataNew);
-					((SimpleAdapter)flag.getAdapter()).notifyDataSetChanged();
-				}
-			});
-			
-			final List<Map<String, ?>> typesDataNew = FrontendDataUtils.getTypes(this);
-			runOnUiThread(new Runnable(){
-				public void run() {
-					typesData.addAll(typesDataNew);
-					((SimpleAdapter)difficulty.getAdapter()).notifyDataSetChanged();
-				}
-			});
-			
-			final List<Map<String, ?>> hatsDataNew = FrontendDataUtils.getHats(this);
-			runOnUiThread(new Runnable(){
-				public void run() {
-					hatsData.addAll(hatsDataNew);
-					((SimpleAdapter)hogHat.get(0).getAdapter()).notifyDataSetChanged();
-				}
-			});
-			
-			final List<String> voicesDataNew = FrontendDataUtils.getVoices(this);
-			runOnUiThread(new Runnable(){
-				public void run() {
-					voicesData.addAll(voicesDataNew);
-					((ArrayAdapter<?>)voice.getAdapter()).notifyDataSetChanged();
-				}
-			});
-			
-			final List<String> fortsDataNew = FrontendDataUtils.getForts(this);
-			runOnUiThread(new Runnable(){
-				public void run() {
-					fortsData.addAll(fortsDataNew);
-					((ArrayAdapter<?>)fort.getAdapter()).notifyDataSetChanged();
-				}
-			});
-			
-			if(existingTeamName!=null) {
-				final Team loadedTeam = Team.load(Team.getTeamfileByName(getApplicationContext(), existingTeamName));
-				if(loadedTeam==null) {
-					existingTeamName = null;
-				} else {
-					runOnUiThread(new Runnable(){
-						public void run() {
-							setTeamValues(loadedTeam);
-						}
-					});
-				}
-			}
-			runOnUiThread(new Runnable(){
-				public void run() {
-					initComplete = true;
-				}
-			});
-		} catch(FileNotFoundException e) {
-			this.runOnUiThread(new Runnable(){
-				public void run() {
-					Toast.makeText(getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
-					finish();
-				}
-			});
-		}
-	}
-	
-	public void onDestroy() {
-		super.onDestroy();
-		if (mp != null) {
-			mp.release();
-			mp = null;
-		}
-	}
+            final List<String> voicesDataNew = FrontendDataUtils.getVoices(this);
+            runOnUiThread(new Runnable(){
+                public void run() {
+                    voicesData.addAll(voicesDataNew);
+                    ((ArrayAdapter<?>)voice.getAdapter()).notifyDataSetChanged();
+                }
+            });
+
+            final List<String> fortsDataNew = FrontendDataUtils.getForts(this);
+            runOnUiThread(new Runnable(){
+                public void run() {
+                    fortsData.addAll(fortsDataNew);
+                    ((ArrayAdapter<?>)fort.getAdapter()).notifyDataSetChanged();
+                }
+            });
 
-	@Override
-	protected void onSaveInstanceState(Bundle outState) {
-		super.onSaveInstanceState(outState);
-		outState.putString(PARAMETER_EXISTING_TEAMNAME, existingTeamName);
-	}
+            if(existingTeamName!=null) {
+                final Team loadedTeam = Team.load(Team.getTeamfileByName(getApplicationContext(), existingTeamName));
+                if(loadedTeam==null) {
+                    existingTeamName = null;
+                } else {
+                    runOnUiThread(new Runnable(){
+                        public void run() {
+                            setTeamValues(loadedTeam);
+                        }
+                    });
+                }
+            }
+            runOnUiThread(new Runnable(){
+                public void run() {
+                    initComplete = true;
+                }
+            });
+        } catch(FileNotFoundException e) {
+            this.runOnUiThread(new Runnable(){
+                public void run() {
+                    Toast.makeText(getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
+                    finish();
+                }
+            });
+        }
+    }
 
-	public void onBackPressed() {
-		if(initComplete) {
-			saveTeam();
-		}
-		setResult(RESULT_OK);
-		super.onBackPressed();
-	}
+    public void onDestroy() {
+        super.onDestroy();
+        if (mp != null) {
+            mp.release();
+            mp = null;
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putString(PARAMETER_EXISTING_TEAMNAME, existingTeamName);
+    }
+
+    public void onBackPressed() {
+        if(initComplete) {
+            saveTeam();
+        }
+        setResult(RESULT_OK);
+        super.onBackPressed();
+    }
+
+    private void saveTeam() {
+        String teamName = name.getText().toString();
+        String teamFlag = (String)((Map<String, Object>) flag.getSelectedItem()).get("txt");
+        String teamFort = fort.getSelectedItem().toString();
+        String teamGrave = (String)((Map<String, Object>) grave.getSelectedItem()).get("txt");
+        String teamVoice = voice.getSelectedItem().toString();
+        int levelInt = (Integer)((Map<String, Object>) difficulty.getSelectedItem()).get("level");
 
-	private void saveTeam() {
-		String teamName = name.getText().toString();
-		String teamFlag = (String)((Map<String, Object>) flag.getSelectedItem()).get("txt");
-		String teamFort = fort.getSelectedItem().toString();
-		String teamGrave = (String)((Map<String, Object>) grave.getSelectedItem()).get("txt");
-		String teamVoice = voice.getSelectedItem().toString();
-		int levelInt = (Integer)((Map<String, Object>) difficulty.getSelectedItem()).get("level");
-		
-		List<Hog> hogs = new ArrayList<Hog>();
-		for (int i = 0; i < hogName.size(); i++) {
-			String name = hogName.get(i).getText().toString();
-			String hat = ((Map<String, Object>) hogHat.get(i).getSelectedItem()).get("txt").toString();
-			hogs.add(new Hog(name, hat, levelInt));
-		}
-		
-		Team team = new Team(teamName, teamGrave, teamFlag, teamVoice, teamFort, hogs);
-		File teamsDir = new File(getFilesDir(), Team.DIRECTORY_TEAMS);
-		if (!teamsDir.exists()) teamsDir.mkdir();
-		
-		File newFile = Team.getTeamfileByName(this, teamName);
-		File oldFile = null;
-		if(existingTeamName != null) {
-			oldFile = Team.getTeamfileByName(this, existingTeamName);
-		}
-		try {
-			team.save(newFile);
-			// If the team was renamed, delete the old file.
-			if(oldFile != null && oldFile.isFile() && !oldFile.equals(newFile)) {
-				oldFile.delete();
-			}
-			existingTeamName = teamName;
-		} catch(IOException e) {
-			Toast.makeText(getApplicationContext(), R.string.error_save_failed, Toast.LENGTH_SHORT).show();
-		}
-	};
+        List<Hog> hogs = new ArrayList<Hog>();
+        for (int i = 0; i < hogName.size(); i++) {
+            String name = hogName.get(i).getText().toString();
+            String hat = ((Map<String, Object>) hogHat.get(i).getSelectedItem()).get("txt").toString();
+            hogs.add(new Hog(name, hat, levelInt));
+        }
+
+        Team team = new Team(teamName, teamGrave, teamFlag, teamVoice, teamFort, hogs);
+        File teamsDir = new File(getFilesDir(), Team.DIRECTORY_TEAMS);
+        if (!teamsDir.exists()) teamsDir.mkdir();
+
+        File newFile = Team.getTeamfileByName(this, teamName);
+        File oldFile = null;
+        if(existingTeamName != null) {
+            oldFile = Team.getTeamfileByName(this, existingTeamName);
+        }
+        try {
+            team.save(newFile);
+            // If the team was renamed, delete the old file.
+            if(oldFile != null && oldFile.isFile() && !oldFile.equals(newFile)) {
+                oldFile.delete();
+            }
+            existingTeamName = teamName;
+        } catch(IOException e) {
+            Toast.makeText(getApplicationContext(), R.string.error_save_failed, Toast.LENGTH_SHORT).show();
+        }
+    };
 
-	private OnItemSelectedListener fortSelector = new OnItemSelectedListener() {
-		public void onItemSelected(AdapterView<?> arg0, View arg1,
-				int position, long arg3) {
-			String fortName = (String) arg0.getAdapter().getItem(position);
-			try {
-				File fortImage = FileUtils.getDataPathFile(TeamCreatorActivity.this, "Forts", fortName, "L.png");
-				Drawable fortIconDrawable = Drawable.createFromPath(fortImage.getAbsolutePath());
-				imgFort.setImageDrawable(fortIconDrawable);
-			} catch(IOException e) {
-				Log.e(TAG, "Unable to show fort image", e);
-			}
-			scroller.fullScroll(ScrollView.FOCUS_DOWN);// Scroll the scrollview
-			// to the bottom, work
-			// around for scrollview
-			// invalidation (scrolls
-			// back to top)
-		}
+    private OnItemSelectedListener fortSelector = new OnItemSelectedListener() {
+        public void onItemSelected(AdapterView<?> arg0, View arg1,
+                int position, long arg3) {
+            String fortName = (String) arg0.getAdapter().getItem(position);
+            try {
+                File fortImage = FileUtils.getDataPathFile(TeamCreatorActivity.this, "Forts", fortName, "L.png");
+                Drawable fortIconDrawable = Drawable.createFromPath(fortImage.getAbsolutePath());
+                imgFort.setImageDrawable(fortIconDrawable);
+            } catch(IOException e) {
+                Log.e(TAG, "Unable to show fort image", e);
+            }
+            scroller.fullScroll(ScrollView.FOCUS_DOWN);// Scroll the scrollview
+            // to the bottom, work
+            // around for scrollview
+            // invalidation (scrolls
+            // back to top)
+        }
 
-		public void onNothingSelected(AdapterView<?> arg0) {
-		}
+        public void onNothingSelected(AdapterView<?> arg0) {
+        }
 
-	};
+    };
 
-	private OnClickListener voiceClicker = new OnClickListener() {
-		public void onClick(View v) {
-			try {
-				File dir = FileUtils.getDataPathFile(TeamCreatorActivity.this, "Sounds", "voices", (String)voice.getSelectedItem());
-				String file = "";
-				File[] dirs = dir.listFiles();
-				File f = dirs[(int) Math.round(Math.random() * dirs.length)];
-				if (f.getName().endsWith(".ogg"))
-					file = f.getAbsolutePath();
+    private OnClickListener voiceClicker = new OnClickListener() {
+        public void onClick(View v) {
+            try {
+                File dir = FileUtils.getDataPathFile(TeamCreatorActivity.this, "Sounds", "voices", (String)voice.getSelectedItem());
+                String file = "";
+                File[] dirs = dir.listFiles();
+                File f = dirs[(int) Math.round(Math.random() * dirs.length)];
+                if (f.getName().endsWith(".ogg"))
+                    file = f.getAbsolutePath();
 
-				if (mp == null)
-					mp = new MediaPlayer();
-				else
-					mp.reset();
-				mp.setDataSource(file);
-				mp.prepare();
-				mp.start();
-			} catch (IllegalArgumentException e) {
-				Log.e(TAG, "Unable to play voice sample", e);
-			} catch (IllegalStateException e) {
-				Log.e(TAG, "Unable to play voice sample", e);
-			} catch (IOException e) {
-				Log.e(TAG, "Unable to play voice sample", e);
-			}
-		}
-	};
+                if (mp == null)
+                    mp = new MediaPlayer();
+                else
+                    mp.reset();
+                mp.setDataSource(file);
+                mp.prepare();
+                mp.start();
+            } catch (IllegalArgumentException e) {
+                Log.e(TAG, "Unable to play voice sample", e);
+            } catch (IllegalStateException e) {
+                Log.e(TAG, "Unable to play voice sample", e);
+            } catch (IOException e) {
+                Log.e(TAG, "Unable to play voice sample", e);
+            }
+        }
+    };
+
+    @SuppressWarnings("unchecked")
+    private void setTeamValues(Team t){
+        if (t == null) {
+            return;
+        }
+
+        try {
+            name.setText(t.name);
+            voice.setSelection(findPosition((ArrayAdapter<String>) voice.getAdapter(), t.voice));
+            fort.setSelection(findPosition((ArrayAdapter<String>) fort.getAdapter(), t.fort));
+            difficulty.setSelection(findPosition(typesData, "level", Integer.valueOf(t.hogs.get(0).level)));
+            grave.setSelection(findPosition(gravesData, "txt", t.grave));
+            flag.setSelection(findPosition(flagsData, "txt", t.flag));
 
-	@SuppressWarnings("unchecked")
-	private void setTeamValues(Team t){
-		if (t == null) {
-			return;
-		}
-		
-		try {
-			name.setText(t.name);
-			voice.setSelection(findPosition((ArrayAdapter<String>) voice.getAdapter(), t.voice));
-			fort.setSelection(findPosition((ArrayAdapter<String>) fort.getAdapter(), t.fort));
-			difficulty.setSelection(findPosition(typesData, "level", Integer.valueOf(t.hogs.get(0).level)));
-			grave.setSelection(findPosition(gravesData, "txt", t.grave));
-			flag.setSelection(findPosition(flagsData, "txt", t.flag));
-	
-			for (int i = 0; i < Team.HEDGEHOGS_PER_TEAM; i++) {
-				hogHat.get(i).setSelection(findPosition(hatsData, "txt", t.hogs.get(i).hat));
-				hogName.get(i).setText(t.hogs.get(i).name);
-			}
-		} catch(NoSuchElementException e) {
-			Toast.makeText(getApplicationContext(), R.string.error_team_attribute_not_found, Toast.LENGTH_LONG).show();
-			finish();
-		}
-	}
+            for (int i = 0; i < Team.HEDGEHOGS_PER_TEAM; i++) {
+                hogHat.get(i).setSelection(findPosition(hatsData, "txt", t.hogs.get(i).hat));
+                hogName.get(i).setText(t.hogs.get(i).name);
+            }
+        } catch(NoSuchElementException e) {
+            Toast.makeText(getApplicationContext(), R.string.error_team_attribute_not_found, Toast.LENGTH_LONG).show();
+            finish();
+        }
+    }
+
+    int findPosition(ArrayAdapter<String> adapter, String value) throws NoSuchElementException {
+        int position = adapter.getPosition(value);
+        if(position<0) {
+            throw new NoSuchElementException();
+        }
+        return position;
+    }
 
-	int findPosition(ArrayAdapter<String> adapter, String value) throws NoSuchElementException {
-		int position = adapter.getPosition(value);
-		if(position<0) {
-			throw new NoSuchElementException();
-		}
-		return position;
-	}
-	
-	int findPosition(List<? extends Map<String, ?>> data, String key, Object value) throws NoSuchElementException {
-		int position = 0;
-		for (Map<String, ?> map : data) {
-			if (map.get(key).equals(value)) {
-				return position;
-			}
-			position++;
-		}
-		throw new NoSuchElementException();
-	}
+    int findPosition(List<? extends Map<String, ?>> data, String key, Object value) throws NoSuchElementException {
+        int position = 0;
+        for (Map<String, ?> map : data) {
+            if (map.get(key).equals(value)) {
+                return position;
+            }
+            position++;
+        }
+        throw new NoSuchElementException();
+    }
+
+    private SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
 
-	private SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
-
-		public boolean setViewValue(View view, Object data,
-				String textRepresentation) {
-			if (view instanceof ImageView && data instanceof Bitmap) {
-				ImageView v = (ImageView) view;
-				v.setImageBitmap((Bitmap) data);
-				return true;
-			} else {
-				return false;
-			}
-		}
-	};
+        public boolean setViewValue(View view, Object data,
+                String textRepresentation) {
+            if (view instanceof ImageView && data instanceof Bitmap) {
+                ImageView v = (ImageView) view;
+                v.setImageBitmap((Bitmap) data);
+                return true;
+            } else {
+                return false;
+            }
+        }
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamListActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamListActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -43,87 +43,87 @@
 import android.widget.SimpleAdapter;
 
 public class TeamListActivity extends ListActivity implements OnItemClickListener {
-	private List<Team> teams;
-	private ImageButton addButton;
+    private List<Team> teams;
+    private ImageButton addButton;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_teamlist);
+        addButton = (ImageButton)findViewById(R.id.btnAdd);
+        addButton.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                editTeam(null);
+            }
+        });
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        updateList();
+        getListView().setOnItemClickListener(this);
+        registerForContextMenu(getListView());
+    }
+
+    public void onItemClick(AdapterView<?> adapterView, View v, int position, long arg3) {
+        editTeam(teams.get(position).name);
+    }
+
+    @Override
+    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuinfo){
+        menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, R.string.edit);
+        menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete);
+    }
 
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.activity_teamlist);
-		addButton = (ImageButton)findViewById(R.id.btnAdd);
-		addButton.setOnClickListener(new OnClickListener() {
-			public void onClick(View v) {
-				editTeam(null);
-			}
-		});
-	}
-	
-	@Override
-	public void onResume() {
-		super.onResume();
-		updateList();
-		getListView().setOnItemClickListener(this);
-		registerForContextMenu(getListView());
-	}
-	
-	public void onItemClick(AdapterView<?> adapterView, View v, int position, long arg3) {
-		editTeam(teams.get(position).name);
-	}
-	
-	@Override
-	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuinfo){
-		menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, R.string.edit);
-		menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete);
-	}
-	
-	@Override
-	public boolean onContextItemSelected(MenuItem item){
-		AdapterView.AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
-		int position = menuInfo.position;
-		Team team = teams.get(position);
-		switch(item.getItemId()){
-		case 0:
-			editTeam(team.name);
-			return true;
-		case 1:
-			Team.getTeamfileByName(getApplicationContext(), team.name).delete();
-			updateList();
-			return true;
-		}
-		return false;
-	}
-	
-	private void updateList() {
-		teams = FrontendDataUtils.getTeams(getApplicationContext());
-		Collections.sort(teams, Team.NAME_ORDER);
-		SimpleAdapter adapter = new SimpleAdapter(this, teamsToMaps(teams), R.layout.team_selection_entry_simple, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty});
-		setListAdapter(adapter);
-	}
-	
-	private void editTeam(String teamName) {
-		Intent i = new Intent(this, TeamCreatorActivity.class);
-		i.putExtra(TeamCreatorActivity.PARAMETER_EXISTING_TEAMNAME, teamName);
-		startActivity(i);
-	}
+    @Override
+    public boolean onContextItemSelected(MenuItem item){
+        AdapterView.AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
+        int position = menuInfo.position;
+        Team team = teams.get(position);
+        switch(item.getItemId()){
+        case 0:
+            editTeam(team.name);
+            return true;
+        case 1:
+            Team.getTeamfileByName(getApplicationContext(), team.name).delete();
+            updateList();
+            return true;
+        }
+        return false;
+    }
+
+    private void updateList() {
+        teams = FrontendDataUtils.getTeams(getApplicationContext());
+        Collections.sort(teams, Team.NAME_ORDER);
+        SimpleAdapter adapter = new SimpleAdapter(this, teamsToMaps(teams), R.layout.team_selection_entry_simple, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty});
+        setListAdapter(adapter);
+    }
 
-	private static final int[] botlevelDrawables = new int[] {
-		R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1
-	};
-	
-	private List<Map<String, ?>> teamsToMaps(List<Team> teams) {
-		List<Map<String, ?>> result = new ArrayList<Map<String,?>>();
-		for(Team t : teams) {
-			HashMap<String, Object> map = new HashMap<String, Object>();
-			map.put("team", t);
-			map.put("txt", t.name);
-			int botlevel = t.hogs.get(0).level;
-			if(botlevel<0 || botlevel>=botlevelDrawables.length) {
-				map.put("img", R.drawable.bot1);
-			} else {
-				map.put("img", botlevelDrawables[botlevel]);
-			}
-			result.add(map);
-		}
-		return result;
-	}
+    private void editTeam(String teamName) {
+        Intent i = new Intent(this, TeamCreatorActivity.class);
+        i.putExtra(TeamCreatorActivity.PARAMETER_EXISTING_TEAMNAME, teamName);
+        startActivity(i);
+    }
+
+    private static final int[] botlevelDrawables = new int[] {
+        R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1
+    };
+
+    private List<Map<String, ?>> teamsToMaps(List<Team> teams) {
+        List<Map<String, ?>> result = new ArrayList<Map<String,?>>();
+        for(Team t : teams) {
+            HashMap<String, Object> map = new HashMap<String, Object>();
+            map.put("team", t);
+            map.put("txt", t.name);
+            int botlevel = t.hogs.get(0).level;
+            if(botlevel<0 || botlevel>=botlevelDrawables.length) {
+                map.put("img", R.drawable.bot1);
+            } else {
+                map.put("img", botlevelDrawables[botlevel]);
+            }
+            result.add(map);
+        }
+        return result;
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamlistAdapter.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamlistAdapter.java	Tue Jan 21 22:53:15 2014 +0100
@@ -39,116 +39,116 @@
 import android.widget.TextView;
 
 public class TeamlistAdapter extends BaseAdapter {
-	private boolean colorHogcountEnabled = false;
-	private Listener listener;
-	private List<TeamInGame> teams = new ArrayList<TeamInGame>();
-	
-	public void setColorHogcountEnabled(boolean colorHogcountEnabled) {
-		this.colorHogcountEnabled = colorHogcountEnabled;
-		notifyDataSetChanged();
-	}
-	
-	public void setListener(Listener listener) {
-		this.listener = listener;
-	}
-	
-	public int getCount() {
-		return teams.size();
-	}
-	
-	public TeamInGame getItem(int position) {
-		return teams.get(position);
-	}
-	
-	public long getItemId(int position) {
-		return position;
-	}
-	
-	@Override
-	public boolean hasStableIds() {
-		return false;
-	}
-	
-	public void updateTeamlist(Collection<TeamInGame> newTeams) {
-		teams.clear();
-		teams.addAll(newTeams);
-		Collections.sort(teams, TeamInGame.NAME_ORDER);
-		notifyDataSetChanged();
-	}
-	
-	public View getView(int position, View convertView, ViewGroup parent) {
-		View v = convertView;
-		if (v == null) {
-			LayoutInflater vi = LayoutInflater.from(parent.getContext());
-			v = vi.inflate(R.layout.listview_team, null);
-		}
+    private boolean colorHogcountEnabled = false;
+    private Listener listener;
+    private List<TeamInGame> teams = new ArrayList<TeamInGame>();
+
+    public void setColorHogcountEnabled(boolean colorHogcountEnabled) {
+        this.colorHogcountEnabled = colorHogcountEnabled;
+        notifyDataSetChanged();
+    }
+
+    public void setListener(Listener listener) {
+        this.listener = listener;
+    }
+
+    public int getCount() {
+        return teams.size();
+    }
+
+    public TeamInGame getItem(int position) {
+        return teams.get(position);
+    }
+
+    public long getItemId(int position) {
+        return position;
+    }
+
+    @Override
+    public boolean hasStableIds() {
+        return false;
+    }
+
+    public void updateTeamlist(Collection<TeamInGame> newTeams) {
+        teams.clear();
+        teams.addAll(newTeams);
+        Collections.sort(teams, TeamInGame.NAME_ORDER);
+        notifyDataSetChanged();
+    }
+
+    public View getView(int position, View convertView, ViewGroup parent) {
+        View v = convertView;
+        if (v == null) {
+            LayoutInflater vi = LayoutInflater.from(parent.getContext());
+            v = vi.inflate(R.layout.listview_team, null);
+        }
+
+        TeamInGame team = getItem(position);
+        TextView teamNameView = (TextView) v.findViewById(android.R.id.text1);
+        ImageButton colorButton = (ImageButton) v.findViewById(R.id.colorButton);
+        ImageButton hogCountButton = (ImageButton) v.findViewById(R.id.hogCountButton);
+
+        teamNameView.setText(team.team.name);
+        int teamImage;
+        if(team.ingameAttribs.remoteDriven) {
+            teamImage = R.drawable.team_net_by_level;
+        } else {
+            teamImage = R.drawable.team_local_by_level;
+        }
 
-		TeamInGame team = getItem(position);
-		TextView teamNameView = (TextView) v.findViewById(android.R.id.text1);
-		ImageButton colorButton = (ImageButton) v.findViewById(R.id.colorButton);
-		ImageButton hogCountButton = (ImageButton) v.findViewById(R.id.hogCountButton);
-		
-		teamNameView.setText(team.team.name);
-		int teamImage;
-		if(team.ingameAttribs.remoteDriven) {
-			teamImage = R.drawable.team_net_by_level;
-		} else {
-			teamImage = R.drawable.team_local_by_level;
-		}
-		
-		Drawable d = parent.getContext().getResources().getDrawable(teamImage).mutate();
-		d.setLevel(team.team.hogs.get(0).level);
-		teamNameView.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
-		hogCountButton.getDrawable().setLevel(team.ingameAttribs.hogCount);
-		colorButton.setImageDrawable(new ColorDrawable(TeamIngameAttributes.TEAM_COLORS[team.ingameAttribs.colorIndex]));
-		
-		colorButton.setEnabled(colorHogcountEnabled);
-		hogCountButton.setEnabled(colorHogcountEnabled);
-		
-		colorButton.setOnClickListener(new ButtonClickListener(team, Type.COLOR_BUTTON));
-		hogCountButton.setOnClickListener(new ButtonClickListener(team, Type.HOGCOUNT_BUTTON));
-		
-		if(team.ingameAttribs.remoteDriven) {
-			teamNameView.setClickable(false);
-		} else {
-			teamNameView.setOnClickListener(new ButtonClickListener(team, Type.TEAM_VIEW));
-		}
-		
-		return v;
-	}
-	
-	private static enum Type {COLOR_BUTTON, HOGCOUNT_BUTTON, TEAM_VIEW}
-	private final class ButtonClickListener implements OnClickListener {
-		private final TeamInGame team;
-		private final Type type;
-		
-		public ButtonClickListener(TeamInGame team, Type type) {
-			this.team = team;
-			this.type = type;
-		}
-		
-		public void onClick(View v) {
-			if(listener != null) {
-				switch(type) {
-				case COLOR_BUTTON:
-					listener.onColorClicked(team);
-					break;
-				case HOGCOUNT_BUTTON:
-					listener.onHogcountClicked(team);
-					break;
-				case TEAM_VIEW:
-					listener.onTeamClicked(team);
-					break;
-				default:
-					throw new IllegalStateException();	
-				}
-			}
-		}
-	}
-	
-	public interface Listener {
-		void onTeamClicked(TeamInGame team);
-		void onColorClicked(TeamInGame team);
-		void onHogcountClicked(TeamInGame team);
-	}
+        Drawable d = parent.getContext().getResources().getDrawable(teamImage).mutate();
+        d.setLevel(team.team.hogs.get(0).level);
+        teamNameView.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
+        hogCountButton.getDrawable().setLevel(team.ingameAttribs.hogCount);
+        colorButton.setImageDrawable(new ColorDrawable(TeamIngameAttributes.TEAM_COLORS[team.ingameAttribs.colorIndex]));
+
+        colorButton.setEnabled(colorHogcountEnabled);
+        hogCountButton.setEnabled(colorHogcountEnabled);
+
+        colorButton.setOnClickListener(new ButtonClickListener(team, Type.COLOR_BUTTON));
+        hogCountButton.setOnClickListener(new ButtonClickListener(team, Type.HOGCOUNT_BUTTON));
+
+        if(team.ingameAttribs.remoteDriven) {
+            teamNameView.setClickable(false);
+        } else {
+            teamNameView.setOnClickListener(new ButtonClickListener(team, Type.TEAM_VIEW));
+        }
+
+        return v;
+    }
+
+    private static enum Type {COLOR_BUTTON, HOGCOUNT_BUTTON, TEAM_VIEW}
+    private final class ButtonClickListener implements OnClickListener {
+        private final TeamInGame team;
+        private final Type type;
+
+        public ButtonClickListener(TeamInGame team, Type type) {
+            this.team = team;
+            this.type = type;
+        }
+
+        public void onClick(View v) {
+            if(listener != null) {
+                switch(type) {
+                case COLOR_BUTTON:
+                    listener.onColorClicked(team);
+                    break;
+                case HOGCOUNT_BUTTON:
+                    listener.onHogcountClicked(team);
+                    break;
+                case TEAM_VIEW:
+                    listener.onTeamClicked(team);
+                    break;
+                default:
+                    throw new IllegalStateException();
+                }
+            }
+        }
+    }
+
+    public interface Listener {
+        void onTeamClicked(TeamInGame team);
+        void onColorClicked(TeamInGame team);
+        void onHogcountClicked(TeamInGame team);
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamlistFragment.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TeamlistFragment.java	Tue Jan 21 22:53:15 2014 +0100
@@ -37,83 +37,83 @@
 import android.widget.Button;
 
 public class TeamlistFragment extends ListFragment implements TeamlistAdapter.Listener {
-	private TeamlistAdapter adapter;
-	private Button addTeamButton;
-	private RoomStateManager stateManager;
-	
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		try {
-			stateManager = ((RoomStateManager.Provider)getActivity()).getRoomStateManager();
-		} catch(ClassCastException e) {
-			throw new RuntimeException("Hosting activity must implement RoomStateManager.Provider.", e);
-		}
-		adapter = new TeamlistAdapter();
-		adapter.updateTeamlist(stateManager.getTeams().values());
-		adapter.setColorHogcountEnabled(stateManager.getChiefStatus());
-		adapter.setListener(this);
-		setListAdapter(adapter);
-		stateManager.addListener(roomStateChangeListener);
-	}
+    private TeamlistAdapter adapter;
+    private Button addTeamButton;
+    private RoomStateManager stateManager;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        try {
+            stateManager = ((RoomStateManager.Provider)getActivity()).getRoomStateManager();
+        } catch(ClassCastException e) {
+            throw new RuntimeException("Hosting activity must implement RoomStateManager.Provider.", e);
+        }
+        adapter = new TeamlistAdapter();
+        adapter.updateTeamlist(stateManager.getTeams().values());
+        adapter.setColorHogcountEnabled(stateManager.getChiefStatus());
+        adapter.setListener(this);
+        setListAdapter(adapter);
+        stateManager.addListener(roomStateChangeListener);
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        View v = inflater.inflate(R.layout.fragment_teamlist, container, false);
+        addTeamButton = (Button)v.findViewById(R.id.addTeamButton);
+        addTeamButton.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                new TeamAddDialog(getCurrentTeamNames()).show(getFragmentManager(), "team_add_dialog");
+            }
+        });
+
+        addTeamButton.setEnabled(stateManager.getTeams().size() < Team.maxNumberOfTeams);
+
+        return v;
+    }
 
-	@Override
-	public View onCreateView(LayoutInflater inflater, ViewGroup container,
-			Bundle savedInstanceState) {
-		View v = inflater.inflate(R.layout.fragment_teamlist, container, false);
-		addTeamButton = (Button)v.findViewById(R.id.addTeamButton);
-		addTeamButton.setOnClickListener(new OnClickListener() {
-			public void onClick(View v) {
-				new TeamAddDialog(getCurrentTeamNames()).show(getFragmentManager(), "team_add_dialog");
-			}
-		});
-		
-		addTeamButton.setEnabled(stateManager.getTeams().size() < Team.maxNumberOfTeams);
-		
-		return v;
-	}
-	
-	@Override
-	public void onDestroy() {
-		super.onDestroy();
-		adapter.setListener(null);
-		stateManager.removeListener(roomStateChangeListener);
-	}
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        adapter.setListener(null);
+        stateManager.removeListener(roomStateChangeListener);
+    }
+
+    private Collection<String> getCurrentTeamNames() {
+        List<String> names = new ArrayList<String>();
+        for(TeamInGame team : stateManager.getTeams().values()) {
+            names.add(team.team.name);
+        }
+        return names;
+    }
+
+    public void onColorClicked(TeamInGame team) {
+        stateManager.changeTeamColorIndex(team.team.name, (team.ingameAttribs.colorIndex+1)%TeamIngameAttributes.TEAM_COLORS.length);
+    }
 
-	private Collection<String> getCurrentTeamNames() {
-		List<String> names = new ArrayList<String>();
-		for(TeamInGame team : stateManager.getTeams().values()) {
-			names.add(team.team.name);
-		}
-		return names;
-	}
-	
-	public void onColorClicked(TeamInGame team) {
-		stateManager.changeTeamColorIndex(team.team.name, (team.ingameAttribs.colorIndex+1)%TeamIngameAttributes.TEAM_COLORS.length);
-	}
-	
-	public void onHogcountClicked(TeamInGame team) {
-		int newHogCount = team.ingameAttribs.hogCount+1;
-		if(newHogCount>Team.HEDGEHOGS_PER_TEAM) {
-			newHogCount = 1;
-		}
-		stateManager.changeTeamHogCount(team.team.name, newHogCount);
-	}
-	
-	public void onTeamClicked(TeamInGame team) {
-		stateManager.requestRemoveTeam(team.team.name);
-	}
-	
-	private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.ListenerAdapter() {
-		@Override
-		public void onChiefStatusChanged(boolean isChief) {
-			adapter.setColorHogcountEnabled(isChief);
-		};
-		
-		@Override
-		public void onTeamsChanged(Map<String, TeamInGame> teams) {
-			adapter.updateTeamlist(teams.values());
-			addTeamButton.setEnabled(teams.size() < Team.maxNumberOfTeams);
-		};
-	};
+    public void onHogcountClicked(TeamInGame team) {
+        int newHogCount = team.ingameAttribs.hogCount+1;
+        if(newHogCount>Team.HEDGEHOGS_PER_TEAM) {
+            newHogCount = 1;
+        }
+        stateManager.changeTeamHogCount(team.team.name, newHogCount);
+    }
+
+    public void onTeamClicked(TeamInGame team) {
+        stateManager.requestRemoveTeam(team.team.name);
+    }
+
+    private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.ListenerAdapter() {
+        @Override
+        public void onChiefStatusChanged(boolean isChief) {
+            adapter.setColorHogcountEnabled(isChief);
+        };
+
+        @Override
+        public void onTeamsChanged(Map<String, TeamInGame> teams) {
+            adapter.updateTeamlist(teams.values());
+            addTeamButton.setEnabled(teams.size() < Team.maxNumberOfTeams);
+        };
+    };
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TextImageAdapter.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/TextImageAdapter.java	Tue Jan 21 22:53:15 2014 +0100
@@ -35,40 +35,40 @@
 
 public class TextImageAdapter extends SimpleAdapter {
 
-	private Context context;
-	private ArrayList<Map<String, ?>> data;
-	
-	public TextImageAdapter(Context _context, ArrayList<Map<String, ?>> _data, int resource, String[] from, int[] to) {
-		super(_context, _data, resource, from, to);
-		context = _context;
-		data = _data;
-	}
-	
-	public static TextImageAdapter createAdapter(Context c, String[] txt, String[] img, String[] from, int[] to){
-		if(txt.length != img.length) throw new IllegalArgumentException("txt and img parameters not equal");
-		
-		ArrayList<Map<String, ?>> data = new ArrayList<Map<String, ?>>(txt.length);
-		
-		for(int i = 0; i < txt.length; i++){
-			HashMap<String, Object> map = new HashMap<String, Object>();
-			map.put("txt", txt[i]);
-			map.put("img", BitmapFactory.decodeFile(img[i]));
-			data.add(map);
-		}
-		return new TextImageAdapter(c, data, R.layout.spinner_textimg_entry, from, to);
-	}
+    private Context context;
+    private ArrayList<Map<String, ?>> data;
+
+    public TextImageAdapter(Context _context, ArrayList<Map<String, ?>> _data, int resource, String[] from, int[] to) {
+        super(_context, _data, resource, from, to);
+        context = _context;
+        data = _data;
+    }
+
+    public static TextImageAdapter createAdapter(Context c, String[] txt, String[] img, String[] from, int[] to){
+        if(txt.length != img.length) throw new IllegalArgumentException("txt and img parameters not equal");
+
+        ArrayList<Map<String, ?>> data = new ArrayList<Map<String, ?>>(txt.length);
 
-	public View getView(int position, View convertView, ViewGroup parent){
-		if(convertView == null){
-			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-			convertView = inflater.inflate(R.layout.spinner_textimg_entry, parent);
-		}
-		TextView tv = (TextView) convertView.findViewById(R.id.spinner_txt);
-		ImageView img = (ImageView) convertView.findViewById(R.id.spinner_img);
-		
-		tv.setText((String)data.get(position).get("txt"));
-		img.setImageBitmap((Bitmap)data.get(position).get("img"));
-		
-		return convertView;
-	}
+        for(int i = 0; i < txt.length; i++){
+            HashMap<String, Object> map = new HashMap<String, Object>();
+            map.put("txt", txt[i]);
+            map.put("img", BitmapFactory.decodeFile(img[i]));
+            data.add(map);
+        }
+        return new TextImageAdapter(c, data, R.layout.spinner_textimg_entry, from, to);
+    }
+
+    public View getView(int position, View convertView, ViewGroup parent){
+        if(convertView == null){
+            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+            convertView = inflater.inflate(R.layout.spinner_textimg_entry, parent);
+        }
+        TextView tv = (TextView) convertView.findViewById(R.id.spinner_txt);
+        ImageView img = (ImageView) convertView.findViewById(R.id.spinner_img);
+
+        tv.setText((String)data.get(position).get("txt"));
+        img.setImageBitmap((Bitmap)data.get(position).get("img"));
+
+        return convertView;
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/UserInput/TouchInterface.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/UserInput/TouchInterface.java	Tue Jan 21 22:53:15 2014 +0100
@@ -28,63 +28,63 @@
 
 public class TouchInterface{
 
-	public static OnTouchListener getTouchInterface(){
-		OnTouchListener toucher;
-		if(Build.VERSION.SDK_INT < 5){//8 == Build.VERSION_CODES.FROYO
-			toucher = new TouchInterfaceST();
-		}else{
-			toucher = new TouchInterfaceMT();
-		}
+    public static OnTouchListener getTouchInterface(){
+        OnTouchListener toucher;
+        if(Build.VERSION.SDK_INT < 5){//8 == Build.VERSION_CODES.FROYO
+            toucher = new TouchInterfaceST();
+        }else{
+            toucher = new TouchInterfaceMT();
+        }
 
-		return toucher;
-	}
+        return toucher;
+    }
 }
 /**
  * Touch interface with multitouch
  */
 class TouchInterfaceMT implements OnTouchListener {
-	
-	private boolean firstEvent = true;
-	
-	public boolean onTouch(View v, MotionEvent event) {
-		//dumpEvent(event);
-		
-		int action = event.getAction();
-		int actionCode = action & MotionEvent.ACTION_MASK;
-		
-		for (int i = 0; i < event.getPointerCount(); i++) {
-			SDLActivity.onNativeTouch(event.getDeviceId(),  event.getPointerId(i), actionCode, (int)event.getX(i), (int)event.getY(i), event.getPressure(i));
-//			Log.d("Android", String.format("x=%f, y=%f, pntr=%d", event.getX(i), event.getY(i), event.getPointerId(i)));
-		   }
-		return true;
-	}
+
+    private boolean firstEvent = true;
+
+    public boolean onTouch(View v, MotionEvent event) {
+        //dumpEvent(event);
+
+        int action = event.getAction();
+        int actionCode = action & MotionEvent.ACTION_MASK;
+
+        for (int i = 0; i < event.getPointerCount(); i++) {
+            SDLActivity.onNativeTouch(event.getDeviceId(),  event.getPointerId(i), actionCode, (int)event.getX(i), (int)event.getY(i), event.getPressure(i));
+//          Log.d("Android", String.format("x=%f, y=%f, pntr=%d", event.getX(i), event.getY(i), event.getPointerId(i)));
+           }
+        return true;
+    }
 
-	/** Show an event in the LogCat view, for debugging */
-	private void dumpEvent(MotionEvent event) {
-	   String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
-	      "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
-	   StringBuilder sb = new StringBuilder();
-	   int action = event.getAction();
-	   int actionCode = action & MotionEvent.ACTION_MASK;
-	   sb.append("event ACTION_" ).append(names[actionCode]);
-	   if (actionCode == MotionEvent.ACTION_POINTER_DOWN
-	         || actionCode == MotionEvent.ACTION_POINTER_UP) {
-	      sb.append("(pid " ).append(
-	      action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
-	      sb.append(")" );
-	   }
-	   sb.append("[" );
-	   for (int i = 0; i < event.getPointerCount(); i++) {
-	      sb.append("#" ).append(i);
-	      sb.append("(pid " ).append(event.getPointerId(i));
-	      sb.append(")=" ).append((int) event.getX(i));
-	      sb.append("," ).append((int) event.getY(i));
-	      if (i + 1 < event.getPointerCount())
-	         sb.append(";" );
-	   }
-	   sb.append("]" );
-	   Log.d("HW_APP_TOUCH", sb.toString());
-	}
+    /** Show an event in the LogCat view, for debugging */
+    private void dumpEvent(MotionEvent event) {
+       String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
+          "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
+       StringBuilder sb = new StringBuilder();
+       int action = event.getAction();
+       int actionCode = action & MotionEvent.ACTION_MASK;
+       sb.append("event ACTION_" ).append(names[actionCode]);
+       if (actionCode == MotionEvent.ACTION_POINTER_DOWN
+             || actionCode == MotionEvent.ACTION_POINTER_UP) {
+          sb.append("(pid " ).append(
+          action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
+          sb.append(")" );
+       }
+       sb.append("[" );
+       for (int i = 0; i < event.getPointerCount(); i++) {
+          sb.append("#" ).append(i);
+          sb.append("(pid " ).append(event.getPointerId(i));
+          sb.append(")=" ).append((int) event.getX(i));
+          sb.append("," ).append((int) event.getY(i));
+          if (i + 1 < event.getPointerCount())
+             sb.append(";" );
+       }
+       sb.append("]" );
+       Log.d("HW_APP_TOUCH", sb.toString());
+    }
 
 }
 
@@ -93,9 +93,9 @@
  */
 class TouchInterfaceST implements OnTouchListener {
 
-	public boolean onTouch(View v, MotionEvent event) {
-		return false;
-	}
+    public boolean onTouch(View v, MotionEvent event) {
+        return false;
+    }
 
 
 
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/WeaponsetCreatorActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/WeaponsetCreatorActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -4,5 +4,5 @@
 
 // TODO
 public class WeaponsetCreatorActivity extends FragmentActivity {
-	public static final String PARAMETER_EXISTING_WEAPONSETNAME="existingWeaponsetName";
+    public static final String PARAMETER_EXISTING_WEAPONSETNAME="existingWeaponsetName";
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/WeaponsetListActivity.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/WeaponsetListActivity.java	Tue Jan 21 22:53:15 2014 +0100
@@ -44,83 +44,83 @@
 import android.widget.Toast;
 
 public class WeaponsetListActivity extends ListActivity implements OnItemClickListener {
-	private List<Weaponset> userWeaponsets;
-	private Button addButton;
-	
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.activity_weaponsetlist);
-		addButton = (Button)findViewById(R.id.addButton);
-		addButton.setOnClickListener(new OnClickListener() {
-			public void onClick(View v) {
-				editWeaponset(null);
-			}
-		});
-	}
-	
-	@Override
-	public void onResume() {
-		super.onResume();
-		updateList();
-		getListView().setOnItemClickListener(this);
-		registerForContextMenu(getListView());
-	}
-	
-	private List<Map<String, ?>> weaponsetsToMap(List<Weaponset> weaponsets) {
-		List<Map<String, ?>> result = new ArrayList<Map<String, ?>>();
-		for(Weaponset weaponset : weaponsets) {
-			result.add(Collections.singletonMap("txt", weaponset.name));
-		}
-		return result;
-	}
-	
-	public void onItemClick(AdapterView<?> adapterView, View v, int position, long arg3) {
-		editWeaponset(userWeaponsets.get(position).name);
-	}
-	
-	@Override
-	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuinfo){
-		menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, R.string.edit);
-		menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete);
-	}
-	
-	@Override
-	public boolean onContextItemSelected(MenuItem item){
-		AdapterView.AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
-		int position = menuInfo.position;
-		Weaponset weaponset = userWeaponsets.get(position);
-		switch(item.getItemId()){
-		case 0:
-			editWeaponset(weaponset.name);
-			return true;
-		case 1:
-			try {
-				Weaponsets.deleteUserWeaponset(this, weaponset.name);
-			} catch (IOException e) {
-				Toast.makeText(this.getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_SHORT).show();
-			}
-			updateList();
-			return true;
-		}
-		return false;
-	}
-	
-	private void updateList() {
-		try {
-			userWeaponsets = Weaponsets.loadUserWeaponsets(this);
-		} catch (IOException e) {
-			Toast.makeText(this, R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
-			finish();
-		}
-		Collections.sort(userWeaponsets, Weaponset.NAME_ORDER);
-		ListAdapter adapter = new SimpleAdapter(this, weaponsetsToMap(userWeaponsets), android.R.layout.simple_list_item_1, new String[]{"txt"}, new int[]{android.R.id.text1});
-		setListAdapter(adapter);
-	}
-	
-	private void editWeaponset(String weaponsetName) {
-		Intent i = new Intent(this, WeaponsetCreatorActivity.class);
-		i.putExtra(WeaponsetCreatorActivity.PARAMETER_EXISTING_WEAPONSETNAME, weaponsetName);
-		startActivity(i);
-	}
+    private List<Weaponset> userWeaponsets;
+    private Button addButton;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_weaponsetlist);
+        addButton = (Button)findViewById(R.id.addButton);
+        addButton.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                editWeaponset(null);
+            }
+        });
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        updateList();
+        getListView().setOnItemClickListener(this);
+        registerForContextMenu(getListView());
+    }
+
+    private List<Map<String, ?>> weaponsetsToMap(List<Weaponset> weaponsets) {
+        List<Map<String, ?>> result = new ArrayList<Map<String, ?>>();
+        for(Weaponset weaponset : weaponsets) {
+            result.add(Collections.singletonMap("txt", weaponset.name));
+        }
+        return result;
+    }
+
+    public void onItemClick(AdapterView<?> adapterView, View v, int position, long arg3) {
+        editWeaponset(userWeaponsets.get(position).name);
+    }
+
+    @Override
+    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuinfo){
+        menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, R.string.edit);
+        menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete);
+    }
+
+    @Override
+    public boolean onContextItemSelected(MenuItem item){
+        AdapterView.AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
+        int position = menuInfo.position;
+        Weaponset weaponset = userWeaponsets.get(position);
+        switch(item.getItemId()){
+        case 0:
+            editWeaponset(weaponset.name);
+            return true;
+        case 1:
+            try {
+                Weaponsets.deleteUserWeaponset(this, weaponset.name);
+            } catch (IOException e) {
+                Toast.makeText(this.getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_SHORT).show();
+            }
+            updateList();
+            return true;
+        }
+        return false;
+    }
+
+    private void updateList() {
+        try {
+            userWeaponsets = Weaponsets.loadUserWeaponsets(this);
+        } catch (IOException e) {
+            Toast.makeText(this, R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
+            finish();
+        }
+        Collections.sort(userWeaponsets, Weaponset.NAME_ORDER);
+        ListAdapter adapter = new SimpleAdapter(this, weaponsetsToMap(userWeaponsets), android.R.layout.simple_list_item_1, new String[]{"txt"}, new int[]{android.R.id.text1});
+        setListAdapter(adapter);
+    }
+
+    private void editWeaponset(String weaponsetName) {
+        Intent i = new Intent(this, WeaponsetCreatorActivity.class);
+        i.putExtra(WeaponsetCreatorActivity.PARAMETER_EXISTING_WEAPONSETNAME, weaponsetName);
+        startActivity(i);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/AndroidTypeMapper.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/AndroidTypeMapper.java	Tue Jan 21 22:53:15 2014 +0100
@@ -1,63 +1,63 @@
-/*
- * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.hedgewars.hedgeroid.frontlib;
-
-import com.sun.jna.DefaultTypeMapper;
-import com.sun.jna.FromNativeContext;
-import com.sun.jna.ToNativeContext;
-import com.sun.jna.TypeConverter;
-import com.sun.jna.TypeMapper;
-
-class AndroidTypeMapper extends DefaultTypeMapper {
-	static final int NATIVE_INT_SIZE = 4;
-	static final int NATIVE_SIZE_T_SIZE = 4;
-	static final int NATIVE_BOOL_SIZE = 1;
-    public static final TypeMapper INSTANCE = new AndroidTypeMapper();
-    
-    protected AndroidTypeMapper() {
-        addTypeConverter(Boolean.class, new BooleanConverter());
-        addTypeConverter(NativeSizeT.class, new SizeTConverter());
-    }
-
-    private static final class BooleanConverter implements TypeConverter {
-    	public Class<Byte> nativeType() {
-    		return Byte.class;
-    	}
-    	public Object fromNative(Object value, FromNativeContext context) {
-    		return ((Byte)value).intValue() != 0 ? Boolean.TRUE : Boolean.FALSE;
-    	}
-    	public Object toNative(Object value, ToNativeContext context) {
-    		return Byte.valueOf((byte)(Boolean.TRUE.equals(value) ? 1 : 0));
-    	}
-    }
-    
-    private static final class SizeTConverter implements TypeConverter {
-    	public Class<Integer> nativeType() {
-    		return Integer.class;
-    	}
-    	public Object fromNative(Object value, FromNativeContext context) {
-    		return NativeSizeT.valueOf((Integer)value);
-    	}
-    	public Object toNative(Object value, ToNativeContext context) {
-    		return Integer.valueOf(value==null ? 0 : ((NativeSizeT)value).intValue());
-    	}
-    }
-}
-
+/*
+ * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.hedgewars.hedgeroid.frontlib;
+
+import com.sun.jna.DefaultTypeMapper;
+import com.sun.jna.FromNativeContext;
+import com.sun.jna.ToNativeContext;
+import com.sun.jna.TypeConverter;
+import com.sun.jna.TypeMapper;
+
+class AndroidTypeMapper extends DefaultTypeMapper {
+    static final int NATIVE_INT_SIZE = 4;
+    static final int NATIVE_SIZE_T_SIZE = 4;
+    static final int NATIVE_BOOL_SIZE = 1;
+    public static final TypeMapper INSTANCE = new AndroidTypeMapper();
+
+    protected AndroidTypeMapper() {
+        addTypeConverter(Boolean.class, new BooleanConverter());
+        addTypeConverter(NativeSizeT.class, new SizeTConverter());
+    }
+
+    private static final class BooleanConverter implements TypeConverter {
+        public Class<Byte> nativeType() {
+            return Byte.class;
+        }
+        public Object fromNative(Object value, FromNativeContext context) {
+            return ((Byte)value).intValue() != 0 ? Boolean.TRUE : Boolean.FALSE;
+        }
+        public Object toNative(Object value, ToNativeContext context) {
+            return Byte.valueOf((byte)(Boolean.TRUE.equals(value) ? 1 : 0));
+        }
+    }
+
+    private static final class SizeTConverter implements TypeConverter {
+        public Class<Integer> nativeType() {
+            return Integer.class;
+        }
+        public Object fromNative(Object value, FromNativeContext context) {
+            return NativeSizeT.valueOf((Integer)value);
+        }
+        public Object toNative(Object value, ToNativeContext context) {
+            return Integer.valueOf(value==null ? 0 : ((NativeSizeT)value).intValue());
+        }
+    }
+}
+
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Flib.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Flib.java	Tue Jan 21 22:53:15 2014 +0100
@@ -27,36 +27,36 @@
 import com.sun.jna.Native;
 
 public class Flib {
-	static {
-		System.loadLibrary("SDL");
-		System.loadLibrary("SDL_net");
-		System.setProperty("jna.encoding", "UTF8"); // Ugly global setting, but it seems JNA doesn't allow setting this per-library... 
-	}
-	public static final Frontlib INSTANCE = (Frontlib)Native.loadLibrary("frontlib", Frontlib.class, Collections.singletonMap(Library.OPTION_TYPE_MAPPER, AndroidTypeMapper.INSTANCE));
-	
-	static {
-		// We'll just do it here and never quit it again...
-		if(Flib.INSTANCE.flib_init() != 0) {
-			throw new RuntimeException("Unable to initialize frontlib");
-		}
-	}
-	
-	// Hook frontlib logging into Android logging
-	private static final Frontlib.LogCallback logCb = new Frontlib.LogCallback() {
-		public void callback(int level, String message) {
-			if(level >= Frontlib.FLIB_LOGLEVEL_ERROR) {
-				Log.e("Frontlib", message);
-			} else if(level == Frontlib.FLIB_LOGLEVEL_WARNING){
-				Log.w("Frontlib", message);
-			} else if(level == Frontlib.FLIB_LOGLEVEL_INFO){
-				Log.i("Frontlib", message);
-			} else if(level <= Frontlib.FLIB_LOGLEVEL_DEBUG){
-				Log.d("Frontlib", message);
-			}
-		}
-	};
-	static {
-		INSTANCE.flib_log_setLevel(Frontlib.FLIB_LOGLEVEL_INFO);
-		INSTANCE.flib_log_setCallback(logCb);
-	}
+    static {
+        System.loadLibrary("SDL");
+        System.loadLibrary("SDL_net");
+        System.setProperty("jna.encoding", "UTF8"); // Ugly global setting, but it seems JNA doesn't allow setting this per-library...
+    }
+    public static final Frontlib INSTANCE = (Frontlib)Native.loadLibrary("frontlib", Frontlib.class, Collections.singletonMap(Library.OPTION_TYPE_MAPPER, AndroidTypeMapper.INSTANCE));
+
+    static {
+        // We'll just do it here and never quit it again...
+        if(Flib.INSTANCE.flib_init() != 0) {
+            throw new RuntimeException("Unable to initialize frontlib");
+        }
+    }
+
+    // Hook frontlib logging into Android logging
+    private static final Frontlib.LogCallback logCb = new Frontlib.LogCallback() {
+        public void callback(int level, String message) {
+            if(level >= Frontlib.FLIB_LOGLEVEL_ERROR) {
+                Log.e("Frontlib", message);
+            } else if(level == Frontlib.FLIB_LOGLEVEL_WARNING){
+                Log.w("Frontlib", message);
+            } else if(level == Frontlib.FLIB_LOGLEVEL_INFO){
+                Log.i("Frontlib", message);
+            } else if(level <= Frontlib.FLIB_LOGLEVEL_DEBUG){
+                Log.d("Frontlib", message);
+            }
+        }
+    };
+    static {
+        INSTANCE.flib_log_setLevel(Frontlib.FLIB_LOGLEVEL_INFO);
+        INSTANCE.flib_log_setCallback(logCb);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Frontlib.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Frontlib.java	Tue Jan 21 22:53:15 2014 +0100
@@ -1,1263 +1,1263 @@
-/*
- * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-
-package org.hedgewars.hedgeroid.frontlib;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.hedgewars.hedgeroid.Datastructures.Hog;
-import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
-import org.hedgewars.hedgeroid.Datastructures.MetaScheme;
-import org.hedgewars.hedgeroid.Datastructures.MetaScheme.Mod;
-import org.hedgewars.hedgeroid.Datastructures.MetaScheme.Setting;
-import org.hedgewars.hedgeroid.Datastructures.GameConfig;
-import org.hedgewars.hedgeroid.Datastructures.Room;
-import org.hedgewars.hedgeroid.Datastructures.Scheme;
-import org.hedgewars.hedgeroid.Datastructures.Team;
-import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
-import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
-import org.hedgewars.hedgeroid.Datastructures.Weaponset;
-
-import com.sun.jna.Callback;
-import com.sun.jna.Library;
-import com.sun.jna.Memory;
-import com.sun.jna.Pointer;
-import com.sun.jna.PointerType;
-import com.sun.jna.Structure;
-
-/**
- * Here is an introduction to the most important aspects of the JNA code.
- * 
- * This interface permits access to the Hedgewars frontend library (frontlib)
- * from Java. Each function directly contained in the Frontlib interface
- * represents a mapped C function. The Structure classes (ending in -Struct) are
- * mappings of C structs, and the PointerType classes (ending in -Ptr) represent
- * pointers to structs.
- * 
- * Quick notes for USING these classes from outside this package:
- * 
- * Usage should be fairly straightforward, but there are a few surprising
- * gotchas. First, when you implement callbacks, YOU are responsible for
- * ensuring that the callback objects are not garbage-collected while they might
- * still be called! So make sure you keep them in member variables or similar,
- * because Java will not know if there are still native references to them.
- * 
- * When using Frontlib from outside its package, you only interact with structs
- * via the PointerType classes. They allow you to get at the data of the struct
- * with a function called deref(), which creates a plain normal Java object
- * representing the data (e.g. SchemePtr.deref() will give you a Scheme object).
- * 
- * Remember that you usually have to destroy structs that you receive from the
- * library, because they are owned by the native code, not Java. The recommended
- * pattern for most cases is to call deref() on the pointer to get a Java object
- * (that you can keep as long as you like), and then immediately destroy the
- * struct if it needs destroying. To find out whether and how the struct needs
- * to be destroyed, see the library's documentation of the function that you got
- * the struct from.
- * 
- * To pass new structs to the library, you can use the static createJavaOwned()
- * function in each PointerType, which creates a new struct from the Java object
- * you provide, and returns a pointer to that struct that you can pass to
- * library functions. This new structure's memory is owned and managed by Java
- * code, so do not destroy it with frontlib functions!
- * 
- * There is a slight mismatch between the data model for the game setup. The
- * frontlib supports setting initial health and weaponset per-hog, because the
- * engine allows for that, but currently neither the networking protocol nor the
- * PC frontend support this feature, so the Android version does not take
- * advantage of it either and treats both as per-game settings. The initial
- * health is contained in the game scheme, the weaponset is explicitly part of
- * the GameConfig. When converting GameConfig to a native flib_gamesetup, both
- * are automatically copied to all hogs in the game, and for the reverse
- * conversion the weaponset of the first hog of the first team is used as the
- * GameConfig weaponset. This means that GameConfig.weaponset will be null if
- * there are no teams in the game.
- * 
- * When starting a network game, you only need to query the GameSetupPtr from
- * the netconn and use it to create the gameconn - this is preferable to using
- * your own recreation of the game setup, because that way the same piece of
- * code is used to determine the game setup on all platforms.
- * 
- * The "context" parameter of the callbacks is never needed here because JNA
- * generates function code for each callback object. Don't worry about it, just
- * pass null for context and ignore the context parameter in the callbacks.
- * 
- * Finally, the library functions are documented in the actual library, not
- * here, so check the docs there to find out what exactly each function does!
- * 
- * Notes about the structure of this class (for the next one who has to touch
- * this...):
- * 
- * Java/C interop is quite fiddly and error-prone, so as long as things work,
- * try to stick to the established patterns.
- * 
- * Structure types should always be hidden from the outside world, because they
- * can be misused too easily. For example, if you get a Structure from the
- * library, change a String value in there and pass it back, JNA will re-write
- * that string using Java-owned memory without freeing the old native-owned
- * string, which causes a memory leak and possibly a double-free or other Bad
- * Things (tm). To avoid problems like this, Structure types are only used
- * internally, to map existing structures to Java types (without modifying them)
- * or to create brand-new, Java-owned structures. Both operations are exposed to
- * the outside through the PointerType classes corresponding to the structures
- * in question.
- * 
- * Since all of the struct mapping happens in Java, it is never checked against
- * the actual struct declarations in the library. That means strange things can
- * start happening at runtime if the frontlib structs are modified without
- * changing the mappings here to match. This also applies to the function
- * signatures: JNA checks whether the functions actually exist when loading the
- * library, but it has no way of knowing whether the signatures are correct. If
- * the signatures here deviate from those in the frontlib, you might get stack
- * corruption.
- * 
- * In order to check at least the function signatures, take a look at the file
- * extra/jnacontrol.c in the frontlib sources. You can validate whether the
- * function signatures are still correct by copy-pasting them into jnaControl.c
- * and compiling it against the frontlib headers. The typedefs and #defines in
- * that file will make the compiler see the Java method signatures as C function
- * declarations. Since the same functions are already declared in the frontlib
- * headers, the compiler will give you errors if the signatures don't match.
- */
-public interface Frontlib extends Library {
-	public static class NetconnPtr extends PointerType { }
-	public static class MapconnPtr extends PointerType { }
-	public static class GameconnPtr extends PointerType { }
-	
-	public static class MetaschemePtr extends PointerType {
-		public MetaScheme deref() {
-			return deref(getPointer());
-		}
-		
-		public static MetaScheme deref(Pointer p) {
-			MetaschemeStruct struct = new MetaschemeStruct(p);
-			struct.read();
-			return struct.toMetaScheme();
-		}
-	}
-	
-	public static class RoomArrayPtr extends PointerType { 
-		public Room[] getRooms(int count) {
-			Pointer ptr = getPointer();
-			if(ptr == null) {
-				return new Room[0];
-			}
-			Pointer[] untypedPtrs = ptr.getPointerArray(0, count);
-			Room[] result = new Room[count];
-			for(int i=0; i<count; i++) {
-				result[i] = RoomPtr.deref(untypedPtrs[i]);
-			}
-			return result;
-		}
-	}
-	
-	public static class RoomPtr extends PointerType {
-		public Room deref() {
-			return deref(getPointer());
-		}
-		
-		public static Room deref(Pointer p) {
-			RoomStruct struct = new RoomStruct(p);
-			struct.read();
-			return struct.toRoomlistRoom();
-		}
-	}
-	
-	public static class TeamPtr extends PointerType {
-		private TeamStruct javaOwnedInstance; 
-		
-		public TeamInGame deref() {
-			TeamStruct struct = new TeamStruct(getPointer());
-			struct.read();
-			return struct.toTeamInGame();
-		}
-		
-		public static TeamPtr createJavaOwned(Team t) {
-			return createJavaOwned(new TeamInGame(t, null));
-		}
-		
-		public static TeamPtr createJavaOwned(TeamInGame ingameTeam) {
-			TeamPtr result = new TeamPtr();
-			result.javaOwnedInstance = new TeamStruct();
-			result.javaOwnedInstance.fillFrom(ingameTeam.team, ingameTeam.ingameAttribs);
-			result.javaOwnedInstance.autoWrite();
-			result.setPointer(result.javaOwnedInstance.getPointer());
-			return result;
-		}
-	}
-	
-	public static class WeaponsetPtr extends PointerType {
-		private WeaponsetStruct javaOwnedInstance; 
-		
-		public Weaponset deref() {
-			WeaponsetStruct struct = new WeaponsetStruct(getPointer());
-			struct.read();
-			return struct.toWeaponset();
-		}
-		
-		public static WeaponsetPtr createJavaOwned(Weaponset weaponset) {
-			WeaponsetPtr result = new WeaponsetPtr();
-			result.javaOwnedInstance = new WeaponsetStruct();
-			result.javaOwnedInstance.fillFrom(weaponset);
-			result.javaOwnedInstance.autoWrite();
-			result.setPointer(result.javaOwnedInstance.getPointer());
-			return result;
-		}
-	}
-	
-	public static class WeaponsetListPtr extends PointerType {
-		private WeaponsetListStruct javaOwnedInstance;
-		
-		public List<Weaponset> deref() {
-			WeaponsetListStruct struct = new WeaponsetListStruct(getPointer());
-			struct.read();
-			return struct.toWeaponsetList();
-		}
-		
-		public static WeaponsetListPtr createJavaOwned(List<Weaponset> list) {
-			WeaponsetListPtr result = new WeaponsetListPtr();
-			result.javaOwnedInstance = new WeaponsetListStruct();
-			result.javaOwnedInstance.fillFrom(list);
-			result.javaOwnedInstance.autoWrite();
-			result.setPointer(result.javaOwnedInstance.getPointer());
-			return result;
-		}
-	}
-	
-	public static class MapRecipePtr extends PointerType {
-		private MapRecipeStruct javaOwnedInstance;
-		
-		public MapRecipe deref() {
-			MapRecipeStruct struct = new MapRecipeStruct(getPointer());
-			struct.read();
-			return struct.toMapRecipe();
-		}
-		
-		public static MapRecipePtr createJavaOwned(MapRecipe recipe) {
-			MapRecipePtr result = new MapRecipePtr();
-			result.javaOwnedInstance = new MapRecipeStruct();
-			result.javaOwnedInstance.fillFrom(recipe);
-			result.javaOwnedInstance.autoWrite();
-			result.setPointer(result.javaOwnedInstance.getPointer());
-			return result;
-		}
-	}
-	
-	public static class SchemePtr extends PointerType {
-		private SchemeStruct javaOwnedInstance;
-		
-		public Scheme deref() {
-			SchemeStruct struct = new SchemeStruct(getPointer());
-			struct.read();
-			return struct.toScheme();
-		}
-		
-		public static SchemePtr createJavaOwned(Scheme scheme) {
-			SchemePtr result = new SchemePtr();
-			result.javaOwnedInstance = new SchemeStruct();
-			result.javaOwnedInstance.fillFrom(scheme);
-			result.javaOwnedInstance.autoWrite();
-			result.setPointer(result.javaOwnedInstance.getPointer());
-			return result;
-		}
-	}
-	
-	public static class SchemelistPtr extends PointerType {
-		private SchemelistStruct javaOwnedInstance;
-		
-		public List<Scheme> deref() {
-			SchemelistStruct struct = new SchemelistStruct(getPointer());
-			struct.read();
-			return struct.toSchemeList();
-		}
-		
-		public static SchemelistPtr createJavaOwned(List<Scheme> schemes) {
-			SchemelistPtr result = new SchemelistPtr();
-			result.javaOwnedInstance = new SchemelistStruct();
-			result.javaOwnedInstance.fillFrom(schemes);
-			result.javaOwnedInstance.autoWrite();
-			result.setPointer(result.javaOwnedInstance.getPointer());
-			return result;
-		}
-	}
-	
-	public static class GameSetupPtr extends PointerType {
-		private GameSetupStruct javaOwnedInstance;
-		
-		public GameConfig deref() {
-			GameSetupStruct struct = new GameSetupStruct(getPointer());
-			struct.read();
-			return struct.toGameConfig();
-		}
-		
-		public static GameSetupPtr createJavaOwned(GameConfig conf) {
-			GameSetupPtr result = new GameSetupPtr();
-			result.javaOwnedInstance = new GameSetupStruct();
-			result.javaOwnedInstance.fillFrom(conf);
-			result.javaOwnedInstance.autoWrite();
-			result.setPointer(result.javaOwnedInstance.getPointer());
-			return result;
-		}
-	}
-	
-	public static class ByteArrayPtr extends PointerType {
-		public byte[] deref(int size) {
-			return getPointer().getByteArray(0, size);
-		}
-		
-		public static byte[] deref(ByteArrayPtr ptr, int size) {
-			if(ptr==null && size==0) {
-				return null;
-			} else {
-				return ptr.deref(size);
-			}
-		}
-		
-		public static ByteArrayPtr createJavaOwned(byte[] buffer) {
-			if(buffer == null || buffer.length == 0) {
-				return null;
-			}
-			// no need for javaOwnedInstance here because PointerType
-			// remembers the memory as its Pointer
-			Pointer ptr = new Memory(buffer.length);
-			ptr.write(0, buffer, 0, buffer.length);
-			ByteArrayPtr result = new ByteArrayPtr();
-			result.setPointer(ptr);
-			return result;
-		}
-	}
-	
-	static class HogStruct extends Structure {
-		public static class ByVal extends HogStruct implements Structure.ByValue {}
-		public static class ByRef extends HogStruct implements Structure.ByReference {}
-
-		public HogStruct() { super(); }
-		public HogStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("name", "hat", "rounds", "kills", "deaths", "suicides", "difficulty", "initialHealth", "weaponset");
-		}
-		
-		public void fillFrom(Hog hog) {
-			difficulty = hog.level;
-			hat = hog.hat;
-			name = hog.name;
-		}
-		
-		public Hog toHog() {
-			return new Hog(name, hat, difficulty);
-		}
-		
-		public String name;
-		public String hat;
-		
-		public int rounds;
-		public int kills;
-		public int deaths;
-		public int suicides;
-	
-		public int difficulty;
-		
-		public int initialHealth;
-		public WeaponsetStruct.ByRef weaponset;
-	}
-	
-	static class TeamStruct extends Structure {
-		public static class ByVal extends TeamStruct implements Structure.ByValue {}
-		public static class ByRef extends TeamStruct implements Structure.ByReference {}
-
-		public TeamStruct() { super(); }
-		public TeamStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("hogs", "name", "grave", "fort", "voicepack", "flag", "bindings", "bindingCount", "rounds", "wins", "campaignProgress", "colorIndex", "hogsInGame", "remoteDriven", "ownerName");
-		}
-		
-		public void fillFrom(Team team, TeamIngameAttributes attrs) {
-			if(team != null) {
-				name = team.name;
-				grave = team.grave;
-				flag = team.flag;
-				voicepack = team.voice;
-				fort = team.fort;
-				if(team.hogs.size() != Team.HEDGEHOGS_PER_TEAM) {
-					throw new IllegalArgumentException();
-				}
-				for(int i=0; i<hogs.length; i++) {
-					hogs[i] = new HogStruct();
-					hogs[i].fillFrom(team.hogs.get(i));
-				}
-			}
-			
-			if(attrs != null) {
-				hogsInGame = attrs.hogCount;
-				ownerName = attrs.ownerName;
-				colorIndex = attrs.colorIndex;
-				remoteDriven = attrs.remoteDriven;
-			}
-		}
-		
-		public void fillFrom(TeamInGame team, WeaponsetStruct.ByRef weaponset, int initialHealth) {
-			fillFrom(team.team, team.ingameAttribs);
-			for(int i=0; i<hogs.length; i++) {
-				hogs[i].initialHealth = initialHealth;
-				hogs[i].weaponset = weaponset;
-			}
-		}
-		
-		public Team toTeam() {
-			List<Hog> hogList = new ArrayList<Hog>();
-			for(int i=0; i<hogs.length; i++) {
-				hogList.add(hogs[i].toHog());
-			}
-			return new Team(name, grave, flag, voicepack, fort, hogList);
-		}
-		
-		public TeamIngameAttributes toTeamIngameAttributes() {
-			return new TeamIngameAttributes(ownerName, colorIndex, hogsInGame, remoteDriven);
-		}
-		
-		public TeamInGame toTeamInGame() {
-			return new TeamInGame(toTeam(), toTeamIngameAttributes());
-		}
-		
-		public HogStruct[] hogs = new HogStruct[Team.HEDGEHOGS_PER_TEAM];
-		public String name;
-		public String grave;
-		public String fort;
-		public String voicepack;
-		public String flag;
-		
-		public Pointer bindings;
-		public int bindingCount;
-		
-		public int rounds;
-		public int wins;
-		public int campaignProgress;
-		
-		public int colorIndex;
-		public int hogsInGame;
-		public boolean remoteDriven;
-		public String ownerName;
-	}
-	
-	static class WeaponsetStruct extends Structure {
-		public static class ByVal extends WeaponsetStruct implements Structure.ByValue {}
-		public static class ByRef extends WeaponsetStruct implements Structure.ByReference {}
-		
-		public WeaponsetStruct() { super(); }
-		public WeaponsetStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("loadout", "crateprob", "crateammo", "delay", "name");
-		}
-		
-		public void fillFrom(Weaponset weaponset) {
-			fillWeaponInfo(loadout, weaponset.loadout);
-			fillWeaponInfo(crateprob, weaponset.crateProb);
-			fillWeaponInfo(crateammo, weaponset.crateAmmo);
-			fillWeaponInfo(delay, weaponset.delay);
-			name = weaponset.name;
-		}
-		
-		private static void fillWeaponInfo(byte[] array, String str) {
-			for(int i=0; i<array.length-1; i++) {
-				array[i] = (byte) (i<str.length() ? str.charAt(i) : '0');
-			}
-			array[array.length-1] = (byte)0;
-		}
-		
-		public Weaponset toWeaponset() {
-			return new Weaponset(name, weaponInfoToString(loadout), weaponInfoToString(crateprob), weaponInfoToString(crateammo), weaponInfoToString(delay));
-		}
-		
-		private static String weaponInfoToString(byte[] array) {
-			try {
-				return new String(array, 0, array.length-1, "ASCII");
-			} catch (UnsupportedEncodingException e) {
-				throw new AssertionError();
-			}
-		}
-		
-		public byte[] loadout = new byte[Weaponset.WEAPONS_COUNT+1];
-		public byte[] crateprob = new byte[Weaponset.WEAPONS_COUNT+1];
-		public byte[] crateammo = new byte[Weaponset.WEAPONS_COUNT+1];
-		public byte[] delay = new byte[Weaponset.WEAPONS_COUNT+1];
-		public String name;
-	}
-	
-	/**
-	 * Represents a flib_weaponset*, for use as part of a flib_weaponset**
-	 */
-	static class WeaponsetPointerByReference extends Structure implements Structure.ByReference {
-		public WeaponsetPointerByReference() { super(); }
-		public WeaponsetPointerByReference(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("weaponset");
-		}
-		
-		public WeaponsetStruct.ByRef weaponset;
-	}
-	
-	static class WeaponsetListStruct extends Structure {
-		public static class ByVal extends WeaponsetListStruct implements Structure.ByValue {}
-		public static class ByRef extends WeaponsetListStruct implements Structure.ByReference {}
-		
-		public WeaponsetListStruct() { super(); }
-		public WeaponsetListStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("weaponsetCount", "weaponsets");
-		}
-		
-		public void fillFrom(List<Weaponset> list) {
-			weaponsetCount = list.size();
-			if(weaponsetCount<=0) {
-				weaponsets = null;
-			} else {
-				weaponsets = new WeaponsetPointerByReference();
-				Structure[] structs = weaponsets.toArray(weaponsetCount);
-				
-				for(int i=0; i<weaponsetCount; i++) {
-					WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i];
-					pstruct.weaponset = new WeaponsetStruct.ByRef();
-					pstruct.weaponset.fillFrom(list.get(i));
-				}
-			}
-		}
-		
-		/**
-		 * Only use on native-owned structs!
-		 * Calling this method on a Java-owned struct could cause garbage collection of referenced
-		 * structures.
-		 */
-		public List<Weaponset> toWeaponsetList() {
-			if(weaponsetCount<=0) {
-				return new ArrayList<Weaponset>();
-			} else {
-				List<Weaponset> list = new ArrayList<Weaponset>(weaponsetCount);
-				Structure[] structs = weaponsets.toArray(weaponsetCount);
-				
-				for(int i=0; i<weaponsetCount; i++) {
-					WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i];
-					list.add(pstruct.weaponset.toWeaponset());
-				}
-				return list;
-			}
-		}
-		
-		public int weaponsetCount;
-		public WeaponsetPointerByReference weaponsets;
-	}
-	
-	static class RoomStruct extends Structure {
-		public static class ByVal extends RoomStruct implements Structure.ByValue {}
-		public static class ByRef extends RoomStruct implements Structure.ByReference {}
-		
-		public RoomStruct() { super(); }
-		public RoomStruct(Pointer ptr) { super(ptr); }
-
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("inProgress", "name", "playerCount", "teamCount", "owner", "map", "scheme", "weapons");
-		}
-		
-		public Room toRoomlistRoom() {
-			return new Room(name, map, scheme, weapons, owner, playerCount, teamCount, inProgress);
-		}
-		
-	    public boolean inProgress;
-	    public String name;
-	    public int playerCount;
-	    public int teamCount;
-	    public String owner;
-	    public String map;
-	    public String scheme;
-	    public String weapons;
-	}
-	
-	static class MapRecipeStruct extends Structure {
-		public static class ByVal extends MapRecipeStruct implements Structure.ByValue {}
-		public static class ByRef extends MapRecipeStruct implements Structure.ByReference {}
-		
-		public MapRecipeStruct() { super(); }
-		public MapRecipeStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("mapgen", "name", "seed", "theme", "drawData", "drawDataSize", "templateFilter", "mazeSize");
-		}
-		
-		public void fillFrom(MapRecipe map) {
-			mapgen = map.mapgen;
-			name = map.name;
-			seed = map.seed;
-			theme = map.theme;
-			byte[] buf = map.getDrawData();
-			drawData = ByteArrayPtr.createJavaOwned(buf);
-			drawDataSize = NativeSizeT.valueOf(buf==null ? 0 : buf.length);
-			templateFilter = map.templateFilter;
-			mazeSize = map.mazeSize;
-		}
-		
-		public MapRecipe toMapRecipe() {
-			byte[] buf = ByteArrayPtr.deref(drawData, drawDataSize.intValue());
-			return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, buf);
-		}
-		
-		public int mapgen;
-		public String name;
-		public String seed;
-		public String theme;
-		public ByteArrayPtr drawData;
-		public NativeSizeT drawDataSize;
-		public int templateFilter;
-		public int mazeSize;
-	}
-	
-	static class MetaschemeSettingStruct extends Structure {
-		public static class ByVal extends MetaschemeSettingStruct implements Structure.ByValue {}
-		public static class ByRef extends MetaschemeSettingStruct implements Structure.ByReference {}
-		
-		public MetaschemeSettingStruct() { super(); }
-		public MetaschemeSettingStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("name", "engineCommand", "maxMeansInfinity", "times1000", "min", "max", "def");
-		}
-		
-		public void fillFrom(Setting setting) {
-			name = setting.name;
-			engineCommand = setting.engineCommand;
-			maxMeansInfinity = setting.maxMeansInfinity;
-			times1000 = setting.times1000;
-			min = setting.min;
-			max = setting.max;
-			def = setting.def;
-		}
-		
-		public MetaScheme.Setting toMetaSchemeSetting() {
-			return new MetaScheme.Setting(name, engineCommand, maxMeansInfinity, times1000, min, max, def);
-		}
-		
-		public String name;
-		public String engineCommand;
-		public boolean maxMeansInfinity;
-		public boolean times1000;
-		public int min;
-		public int max;
-		public int def;
-	}
-	
-	static class MetaschemeModStruct extends Structure {
-		public static class ByVal extends MetaschemeModStruct implements Structure.ByValue {}
-		public static class ByRef extends MetaschemeModStruct implements Structure.ByReference {}
-		
-		public MetaschemeModStruct() { super(); }
-		public MetaschemeModStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("name", "bitmaskIndex");
-		}
-		
-		public void fillFrom(Mod mod) {
-			name = mod.name;
-			bitmaskIndex = mod.bitmaskIndex;
-		}
-		
-		public MetaScheme.Mod toMetaSchemeMod() {
-			return new MetaScheme.Mod(name, bitmaskIndex);
-		}
-
-		public String name;
-		public int bitmaskIndex;
-
-	}
-	
-	static class MetaschemeStruct extends Structure {
-		public static class ByVal extends MetaschemeStruct implements Structure.ByValue {}
-		public static class ByRef extends MetaschemeStruct implements Structure.ByReference {}
-
-		public MetaschemeStruct() { super(); }
-		public MetaschemeStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("settingCount", "modCount", "settings", "mods");
-		}
-		
-		/**
-		 * Only use on native-owned structs!
-		 * Calling this method on a Java-owned struct could cause garbage collection of referenced
-		 * structures.
-		 */
-		public MetaScheme toMetaScheme() {
-			List<MetaScheme.Setting> settingList = new ArrayList<MetaScheme.Setting>(settingCount);
-			List<MetaScheme.Mod> modList = new ArrayList<MetaScheme.Mod>(modCount);
-			
-			Structure[] settingStructs = settings.toArray(settingCount);
-			Structure[] modStructs = mods.toArray(modCount);
-			
-			for(int i=0; i<settingCount; i++) {
-				MetaschemeSettingStruct mss = (MetaschemeSettingStruct)settingStructs[i];
-				settingList.add(mss.toMetaSchemeSetting());
-			}
-			
-			for(int i=0; i<modCount; i++) {
-				MetaschemeModStruct mms = (MetaschemeModStruct)modStructs[i];
-				modList.add(mms.toMetaSchemeMod());
-			}
-			
-			return new MetaScheme(modList, settingList);
-		}
-		
-		public int settingCount;
-		public int modCount;
-		public MetaschemeSettingStruct.ByRef settings;
-		public MetaschemeModStruct.ByRef mods;
-	}
-	
-	static class SchemeStruct extends Structure {
-		public static class ByVal extends SchemeStruct implements Structure.ByValue {}
-		public static class ByRef extends SchemeStruct implements Structure.ByReference {}
-		
-		public SchemeStruct() { super(); }
-		public SchemeStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("name", "settings", "mods");
-		}
-		
-		public void fillFrom(Scheme scheme) {
-			MetaScheme meta = MetaScheme.INSTANCE;
-			name = scheme.name;
-			settings = new Memory(AndroidTypeMapper.NATIVE_INT_SIZE * meta.settings.size());
-			for(int i=0; i<meta.settings.size(); i++) {
-				Integer value = scheme.settings.get(meta.settings.get(i).name);
-				settings.setInt(AndroidTypeMapper.NATIVE_INT_SIZE*i, value);
-			}
-			mods = new Memory(AndroidTypeMapper.NATIVE_BOOL_SIZE * meta.mods.size());
-			for(int i=0; i<meta.mods.size(); i++) {
-				Boolean value = scheme.mods.get(meta.mods.get(i).name);
-				mods.setByte(AndroidTypeMapper.NATIVE_BOOL_SIZE*i, (byte)(value ? 1 : 0));
-			}
-		}
-
-		public Scheme toScheme() {
-			Map<String, Integer> settingsMap = new HashMap<String, Integer>();
-			MetaScheme meta = MetaScheme.INSTANCE;
-			for(int i=0; i<meta.settings.size(); i++) {
-				settingsMap.put(meta.settings.get(i).name, settings.getInt(AndroidTypeMapper.NATIVE_INT_SIZE*i));
-			}
-			Map<String, Boolean> modsMap = new HashMap<String, Boolean>();
-			for(int i=0; i<meta.mods.size(); i++) {
-				modsMap.put(meta.mods.get(i).name, mods.getByte(i) != 0 ? Boolean.TRUE : Boolean.FALSE);
-			}
-			return new Scheme(name, settingsMap, modsMap);
-		}
-		
-		public String name;
-		public Pointer settings;
-		public Pointer mods;
-	}
-	
-	/**
-	 * Represents a flib_scheme*, for use as part of a flib_scheme**
-	 */
-	static class SchemePointerByReference extends Structure implements Structure.ByReference {
-		public SchemePointerByReference() { super(); }
-		public SchemePointerByReference(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("scheme");
-		}
-		
-		public SchemeStruct.ByRef scheme;
-	}
-	
-	static class SchemelistStruct extends Structure {
-		public static class ByVal extends SchemelistStruct implements Structure.ByValue {}
-		public static class ByRef extends SchemelistStruct implements Structure.ByReference {}
-		
-		public SchemelistStruct() { super(); }
-		public SchemelistStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("schemeCount", "schemes");
-		}
-		
-		public void fillFrom(List<Scheme> schemeList) {
-			schemeCount = schemeList.size();
-			if(schemeCount<=0) {
-				schemes = null;
-			} else {
-				schemes = new SchemePointerByReference();
-				Structure[] schemePtrStructs = schemes.toArray(schemeCount);
-				
-				for(int i=0; i<this.schemeCount; i++) {
-					SchemePointerByReference spbr = (SchemePointerByReference)schemePtrStructs[i];
-					spbr.scheme = new SchemeStruct.ByRef();
-					spbr.scheme.fillFrom(schemeList.get(i));
-				}
-			}
-		}
-
-		/**
-		 * Only use on native-owned structs!
-		 * Calling this method on a Java-owned struct could cause garbage collection of referenced
-		 * structures.
-		 */
-		public List<Scheme> toSchemeList() {
-			if(schemeCount<=0) {
-				return new ArrayList<Scheme>();
-			} else {
-				List<Scheme> schemeList = new ArrayList<Scheme>(schemeCount);
-				
-				Structure[] schemePtrStructs = schemes.toArray(schemeCount);
-				
-				for(int i=0; i<schemeCount; i++) {
-					SchemePointerByReference spbr2 = (SchemePointerByReference)schemePtrStructs[i];
-					schemeList.add(spbr2.scheme.toScheme());
-				}
-				return schemeList;
-			}
-		}
-		
-		public int schemeCount;
-		public SchemePointerByReference schemes;
-	}
-	
-	/**
-	 * Represents a flib_team*, for use as part of a flib_team**
-	 */
-	static class TeamPointerByReference extends Structure implements Structure.ByReference {
-		public TeamPointerByReference() { super(); }
-		public TeamPointerByReference(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("team");
-		}
-		
-		public TeamStruct.ByRef team;
-	}
-	
-	static class TeamlistStruct extends Structure {
-		public static class ByVal extends TeamlistStruct implements Structure.ByValue {}
-		public static class ByRef extends TeamlistStruct implements Structure.ByReference {}
-
-		public TeamlistStruct() { super(); }
-		public TeamlistStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("teamCount", "teams");
-		}
-		
-		public void fillFrom(List<TeamInGame> teamList, WeaponsetStruct.ByRef weaponset, int initialHealth) {
-			teamCount = teamList.size();
-			if(teamCount <= 0) {
-				teams = null;
-			} else {
-				teams = new TeamPointerByReference();
-				Structure[] teamPtrStructs = teams.toArray(teamCount);
-				
-				for(int i=0; i<this.teamCount; i++) {
-					TeamPointerByReference tpbr = (TeamPointerByReference)teamPtrStructs[i];
-					tpbr.team = new TeamStruct.ByRef();
-					tpbr.team.fillFrom(teamList.get(i), weaponset, initialHealth);
-				}
-			}
-		}
-
-		public List<TeamInGame> toTeamInGameList() {
-			if(teamCount<=0) {
-				return new ArrayList<TeamInGame>();
-			} else {
-				List<TeamInGame> result = new ArrayList<TeamInGame>(teamCount);
-				Structure[] structs = teams.toArray(teamCount);
-				
-				for(int i=0; i<teamCount; i++) {
-					TeamPointerByReference struct = (TeamPointerByReference)structs[i];
-					result.add(struct.team.toTeamInGame());
-				}
-				return result;
-			}
-		}
-		
-		public int teamCount;
-		public TeamPointerByReference teams;
-	}
-	
-	static class GameSetupStruct extends Structure {
-		public static class ByVal extends GameSetupStruct implements Structure.ByValue {}
-		public static class ByRef extends GameSetupStruct implements Structure.ByReference {}
-		
-		public GameSetupStruct() { super(); }
-		public GameSetupStruct(Pointer ptr) { super(ptr); }
-		
-		@Override
-		protected List<String> getFieldOrder() {
-			return Arrays.asList("script", "gamescheme", "map", "teamlist");
-		}
-		
-		public void fillFrom(GameConfig conf) {
-			script = conf.style;
-			gamescheme = new SchemeStruct.ByRef();
-			gamescheme.fillFrom(conf.scheme);
-			map = new MapRecipeStruct.ByRef();
-			map.fillFrom(conf.map);
-			
-			/*
-			 * At this point we deviate from the usual copying pattern because the frontlib
-			 * expects per-hog weapons and initial health, but the UI models them as per-
-			 * game, so we extract them from the config here and pass them on to be included
-			 * in each hog.
-			 */
-			WeaponsetStruct.ByRef wss = new WeaponsetStruct.ByRef();
-			wss.fillFrom(conf.weaponset);
-			int initialHealth = conf.scheme.getHealth();
-			
-			teamlist = new TeamlistStruct.ByRef();
-			teamlist.fillFrom(conf.teams, wss, initialHealth);
-		}
-		
-		public GameConfig toGameConfig() {
-			Scheme scheme = gamescheme != null ? gamescheme.toScheme() : null;
-			MapRecipe mapRecipe = map != null ? map.toMapRecipe() : null;
-			List<TeamInGame> teams = teamlist != null ? teamlist.toTeamInGameList() : null;
-			
-			WeaponsetStruct weaponsetStruct = teamlist != null && teamlist.teamCount>0 ? teamlist.teams.team.hogs[0].weaponset : null;
-			Weaponset weaponset = weaponsetStruct != null ? weaponsetStruct.toWeaponset() : null;
-			return new GameConfig(script, scheme, mapRecipe, teams, weaponset);
-		}
-
-		public String script;
-		public SchemeStruct.ByRef gamescheme;
-		public MapRecipeStruct.ByRef map;
-		public TeamlistStruct.ByRef teamlist;
-	}
-	
-	/*
-	 * Callback interfaces. The context parameter is never needed here and
-	 * should always be ignored. Be sure to keep a reference to each callback
-	 * for as long as they might be called by native code, to avoid premature
-	 * garbage collection.
-	 */
-	public static interface VoidCallback extends Callback {
-		void callback(Pointer context);
-	}
-	
-	public static interface StrCallback extends Callback {
-		void callback(Pointer context, String arg1);
-	}
-	
-	public static interface IntCallback extends Callback {
-		void callback(Pointer context, int arg1);
-	}
-	
-	public static interface IntStrCallback extends Callback {
-		void callback(Pointer context, int arg1, String arg2);
-	}
-	
-	public static interface StrIntCallback extends Callback {
-		void callback(Pointer context, String arg1, int arg2);
-	}
-	
-	public static interface StrStrCallback extends Callback {
-		void callback(Pointer context, String arg1, String arg2);
-	}
-	
-	public static interface StrStrBoolCallback extends Callback {
-		void callback(Pointer context, String arg1, String arg2, boolean arg3);
-	}
-	
-	public static interface RoomCallback extends Callback {
-		void callback(Pointer context, RoomPtr arg1);
-	}
-	
-	public static interface RoomListCallback extends Callback {
-		void callback(Pointer context, RoomArrayPtr arg1, int count);
-	}
-	
-	public static interface StrRoomCallback extends Callback {
-		void callback(Pointer context, String arg1, RoomPtr arg2);
-	}
-	
-	public static interface BoolCallback extends Callback {
-		void callback(Pointer context, boolean arg1);
-	}
-	
-	public static interface StrBoolCallback extends Callback {
-		void callback(Pointer context, String arg1, boolean arg2);
-	}
-	
-	public static interface TeamCallback extends Callback {
-		void callback(Pointer context, TeamPtr arg1);
-	}
-	
-	public static interface BytesCallback extends Callback {
-		void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size);
-	}
-	
-	public static interface BytesBoolCallback extends Callback {
-		void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size, boolean arg3);
-	}
-	
-	public static interface SchemeCallback extends Callback {
-		void callback(Pointer context, SchemePtr arg1);
-	}
-	
-	public static interface MapIntCallback extends Callback {
-		void callback(Pointer context, MapRecipePtr arg1, int arg2);
-	}
-	
-	public static interface WeaponsetCallback extends Callback {
-		void callback(Pointer context, WeaponsetPtr arg1);
-	}
-	
-	public static interface MapimageCallback extends Callback {
-		void callback(Pointer context, ByteArrayPtr buffer, int hedgehogCount);
-	}
-	
-	public static interface LogCallback extends Callback {
-		void callback(int level, String logMessage);
-	}
-	
-	// frontlib.h
-    int flib_init();
-    void flib_quit();
-	
-    // hwconsts.h
-    int flib_get_teamcolor(int colorIndex);
-    int flib_get_teamcolor_count();
-    int flib_get_hedgehogs_per_team();
-    int flib_get_weapons_count();
-	MetaschemePtr flib_get_metascheme();
-	
-    // net/netconn.h
-	static final int NETCONN_STATE_CONNECTING = 0;
-	static final int NETCONN_STATE_LOBBY = 1;
-	static final int NETCONN_STATE_ROOM = 2;
-	static final int NETCONN_STATE_DISCONNECTED = 10;
-	
-	static final int NETCONN_DISCONNECT_NORMAL = 0;
-	static final int NETCONN_DISCONNECT_SERVER_TOO_OLD = 1;
-	static final int NETCONN_DISCONNECT_AUTH_FAILED = 2;
-	static final int NETCONN_DISCONNECT_CONNLOST = 3;
-	static final int NETCONN_DISCONNECT_INTERNAL_ERROR = 100;
-	
-	static final int NETCONN_ROOMLEAVE_ABANDONED = 0;
-	static final int NETCONN_ROOMLEAVE_KICKED = 1;
-	
-	static final int NETCONN_MSG_TYPE_PLAYERINFO = 0;
-	static final int NETCONN_MSG_TYPE_SERVERMESSAGE = 1;
-	static final int NETCONN_MSG_TYPE_WARNING = 2;
-	static final int NETCONN_MSG_TYPE_ERROR = 3;
-	
-	static final int NETCONN_MAPCHANGE_FULL = 0;
-	static final int NETCONN_MAPCHANGE_MAP = 1;
-	static final int NETCONN_MAPCHANGE_MAPGEN = 2;
-	static final int NETCONN_MAPCHANGE_DRAWNMAP = 3;
-	static final int NETCONN_MAPCHANGE_MAZE_SIZE = 4;
-	static final int NETCONN_MAPCHANGE_TEMPLATE = 5;
-	static final int NETCONN_MAPCHANGE_THEME = 6;
-	static final int NETCONN_MAPCHANGE_SEED = 7;
-    
-	NetconnPtr flib_netconn_create(String playerName, String dataDirPath, String host, int port);
-	void flib_netconn_destroy(NetconnPtr conn);
-
-	void flib_netconn_tick(NetconnPtr conn);
-	boolean flib_netconn_is_chief(NetconnPtr conn);
-	String flib_netconn_get_playername(NetconnPtr conn);
-	GameSetupPtr flib_netconn_create_gamesetup(NetconnPtr conn);
-	int flib_netconn_send_quit(NetconnPtr conn, String quitmsg);
-	int flib_netconn_send_chat(NetconnPtr conn, String chat);
-	int flib_netconn_send_teamchat(NetconnPtr conn, String msg);
-	int flib_netconn_send_password(NetconnPtr conn, String passwd);
-	int flib_netconn_send_nick(NetconnPtr conn, String nick);
-	int flib_netconn_send_request_roomlist(NetconnPtr conn);
-	int flib_netconn_send_joinRoom(NetconnPtr conn, String room);
-	int flib_netconn_send_createRoom(NetconnPtr conn, String room);
-	int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName);
-	int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg);
-	int flib_netconn_send_toggleReady(NetconnPtr conn);
-	int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team);
-	int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname);
-	int flib_netconn_send_engineMessage(NetconnPtr conn, ByteArrayPtr message, NativeSizeT size);
-	int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount);
-	int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex);
-	int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset);
-	int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map);
-	int flib_netconn_send_mapName(NetconnPtr conn, String mapName);
-	int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen);
-	int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter);
-	int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize);
-	int flib_netconn_send_mapSeed(NetconnPtr conn, String seed);
-	int flib_netconn_send_mapTheme(NetconnPtr conn, String theme);
-	int flib_netconn_send_mapDrawdata(NetconnPtr conn, ByteArrayPtr drawData, NativeSizeT size);
-	int flib_netconn_send_script(NetconnPtr conn, String scriptName);
-	int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme);
-	int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError);
-	int flib_netconn_send_ban(NetconnPtr conn, String playerName);
-	int flib_netconn_send_kick(NetconnPtr conn, String playerName);
-	int flib_netconn_send_playerInfo(NetconnPtr conn, String playerName);
-	int flib_netconn_send_playerFollow(NetconnPtr conn, String playerName);
-	int flib_netconn_send_startGame(NetconnPtr conn);
-	int flib_netconn_send_toggleRestrictJoins(NetconnPtr conn);
-	int flib_netconn_send_toggleRestrictTeams(NetconnPtr conn);
-	int flib_netconn_send_clearAccountsCache(NetconnPtr conn);
-	int flib_netconn_send_setServerVar(NetconnPtr conn, String name, String value);
-	int flib_netconn_send_getServerVars(NetconnPtr conn);
-	
-	void flib_netconn_onMessage(NetconnPtr conn, IntStrCallback callback, Pointer context);
-	void flib_netconn_onClientFlags(NetconnPtr conn, StrStrBoolCallback callback, Pointer context);
-	void flib_netconn_onChat(NetconnPtr conn, StrStrCallback callback, Pointer context);
-	void flib_netconn_onConnected(NetconnPtr conn, VoidCallback callback, Pointer context);
-	void flib_netconn_onDisconnected(NetconnPtr conn, IntStrCallback callback, Pointer context);
-	void flib_netconn_onRoomlist(NetconnPtr conn, RoomListCallback callback, Pointer context);
-	void flib_netconn_onRoomAdd(NetconnPtr conn, RoomCallback callback, Pointer context);
-	void flib_netconn_onRoomDelete(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onRoomUpdate(NetconnPtr conn, StrRoomCallback callback, Pointer context);
-	void flib_netconn_onLobbyJoin(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onLobbyLeave(NetconnPtr conn, StrStrCallback callback, Pointer context);
-	void flib_netconn_onNickTaken(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onPasswordRequest(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onEnterRoom(NetconnPtr conn, BoolCallback callback, Pointer context);
-	void flib_netconn_onLeaveRoom(NetconnPtr conn, IntStrCallback callback, Pointer context);
-	void flib_netconn_onTeamAdd(NetconnPtr conn, TeamCallback callback, Pointer context);
-	void flib_netconn_onTeamDelete(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onRoomJoin(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onRoomLeave(NetconnPtr conn, StrStrCallback callback, Pointer context);
-	void flib_netconn_onRunGame(NetconnPtr conn, VoidCallback callback, Pointer context);
-	void flib_netconn_onTeamAccepted(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onHogCountChanged(NetconnPtr conn, StrIntCallback callback, Pointer context);
-	void flib_netconn_onTeamColorChanged(NetconnPtr conn, StrIntCallback callback, Pointer context);
-	void flib_netconn_onEngineMessage(NetconnPtr conn, BytesCallback callback, Pointer context);
-	void flib_netconn_onSchemeChanged(NetconnPtr conn, SchemeCallback callback, Pointer context);
-	void flib_netconn_onMapChanged(NetconnPtr conn, MapIntCallback callback, Pointer context);
-	void flib_netconn_onScriptChanged(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onWeaponsetChanged(NetconnPtr conn, WeaponsetCallback callback, Pointer context);
-	void flib_netconn_onServerVar(NetconnPtr conn, StrStrCallback callback, Pointer context);
-
-	// ipc/gameconn.h
-	static final int GAME_END_FINISHED = 0;
-	static final int GAME_END_INTERRUPTED = 1;
-	static final int GAME_END_HALTED = 2;
-	static final int GAME_END_ERROR = 3;
-	
-	GameconnPtr flib_gameconn_create(String playerName, GameSetupPtr setup, boolean netgame);
-	GameconnPtr flib_gameconn_create_playdemo(ByteArrayPtr demo, NativeSizeT size);
-	GameconnPtr flib_gameconn_create_loadgame(String playerName, ByteArrayPtr save, NativeSizeT size);
-	GameconnPtr flib_gameconn_create_campaign(String playerName, String seed, String script);
-
-	void flib_gameconn_destroy(GameconnPtr conn);
-	int flib_gameconn_getport(GameconnPtr conn);
-	void flib_gameconn_tick(GameconnPtr conn);
-
-	int flib_gameconn_send_enginemsg(GameconnPtr conn, ByteArrayPtr data, NativeSizeT len);
-	int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg);
-	int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg);
-	int flib_gameconn_send_quit(GameconnPtr conn);
-	int flib_gameconn_send_cmd(GameconnPtr conn, String cmdString);
-	
-	void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context);
-	void flib_gameconn_onDisconnect(GameconnPtr conn, IntCallback callback, Pointer context);
-	void flib_gameconn_onErrorMessage(GameconnPtr conn, StrCallback callback, Pointer context);
-	void flib_gameconn_onChat(GameconnPtr conn, StrBoolCallback callback, Pointer context);
-	void flib_gameconn_onGameRecorded(GameconnPtr conn, BytesBoolCallback callback, Pointer context);
-	void flib_gameconn_onEngineMessage(GameconnPtr conn, BytesCallback callback, Pointer context);
-	
-	// ipc/mapconn.h
-	public static final int MAPIMAGE_WIDTH = 256;
-	public static final int MAPIMAGE_HEIGHT = 128;
-	public static final int MAPIMAGE_BYTES = (MAPIMAGE_WIDTH/8*MAPIMAGE_HEIGHT);
-	
-	MapconnPtr flib_mapconn_create(MapRecipePtr mapdesc);
-	void flib_mapconn_destroy(MapconnPtr conn);
-	int flib_mapconn_getport(MapconnPtr conn);
-	void flib_mapconn_onSuccess(MapconnPtr conn, MapimageCallback callback, Pointer context);
-	void flib_mapconn_onFailure(MapconnPtr conn, StrCallback callback, Pointer context);
-	void flib_mapconn_tick(MapconnPtr conn);
-	
-	// model/map.h
-	public static final int MAPGEN_REGULAR = 0;
-	public static final int MAPGEN_MAZE = 1;
-	public static final int MAPGEN_DRAWN = 2;
-	public static final int MAPGEN_NAMED = 3;
-
-	public static final int TEMPLATEFILTER_ALL = 0;
-	public static final int TEMPLATEFILTER_SMALL = 1;
-	public static final int TEMPLATEFILTER_MEDIUM = 2;
-	public static final int TEMPLATEFILTER_LARGE = 3;
-	public static final int TEMPLATEFILTER_CAVERN = 4;
-	public static final int TEMPLATEFILTER_WACKY = 5;
-
-	public static final int MAZE_SIZE_SMALL_TUNNELS = 0;
-	public static final int MAZE_SIZE_MEDIUM_TUNNELS = 1;
-	public static final int MAZE_SIZE_LARGE_TUNNELS = 2;
-	public static final int MAZE_SIZE_SMALL_ISLANDS = 3;
-	public static final int MAZE_SIZE_MEDIUM_ISLANDS = 4;
-	public static final int MAZE_SIZE_LARGE_ISLANDS = 5;
-		
-	// model/schemelist.h
-	SchemelistPtr flib_schemelist_from_ini(String filename);
-	int flib_schemelist_to_ini(String filename, SchemelistPtr list);
-	void flib_schemelist_destroy(SchemelistPtr list);
-	
-	// model/team.h
-	TeamPtr flib_team_from_ini(String filename);
-	int flib_team_to_ini(String filename, TeamPtr team);
-	void flib_team_destroy(TeamPtr team);
-	
-	// model/weapon.h
-	WeaponsetListPtr flib_weaponsetlist_from_ini(String filename);
-	int flib_weaponsetlist_to_ini(String filename, WeaponsetListPtr weaponsets);
-	void flib_weaponsetlist_destroy(WeaponsetListPtr list);
-	
-	// model/gamesetup.h
-	void flib_gamesetup_destroy(GameSetupPtr gamesetup);
-	
-	// util/logging.h
-	public static final int FLIB_LOGLEVEL_ALL = -100;
-	public static final int FLIB_LOGLEVEL_DEBUG = -1;
-	public static final int FLIB_LOGLEVEL_INFO = 0;
-	public static final int FLIB_LOGLEVEL_WARNING = 1;
-	public static final int FLIB_LOGLEVEL_ERROR = 2;
-	public static final int FLIB_LOGLEVEL_NONE = 100;
-	
-    void flib_log_setLevel(int level);
-    void flib_log_setCallback(LogCallback callback);
+/*
+ * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+
+package org.hedgewars.hedgeroid.frontlib;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hedgewars.hedgeroid.Datastructures.Hog;
+import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
+import org.hedgewars.hedgeroid.Datastructures.MetaScheme;
+import org.hedgewars.hedgeroid.Datastructures.MetaScheme.Mod;
+import org.hedgewars.hedgeroid.Datastructures.MetaScheme.Setting;
+import org.hedgewars.hedgeroid.Datastructures.GameConfig;
+import org.hedgewars.hedgeroid.Datastructures.Room;
+import org.hedgewars.hedgeroid.Datastructures.Scheme;
+import org.hedgewars.hedgeroid.Datastructures.Team;
+import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
+import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
+import org.hedgewars.hedgeroid.Datastructures.Weaponset;
+
+import com.sun.jna.Callback;
+import com.sun.jna.Library;
+import com.sun.jna.Memory;
+import com.sun.jna.Pointer;
+import com.sun.jna.PointerType;
+import com.sun.jna.Structure;
+
+/**
+ * Here is an introduction to the most important aspects of the JNA code.
+ *
+ * This interface permits access to the Hedgewars frontend library (frontlib)
+ * from Java. Each function directly contained in the Frontlib interface
+ * represents a mapped C function. The Structure classes (ending in -Struct) are
+ * mappings of C structs, and the PointerType classes (ending in -Ptr) represent
+ * pointers to structs.
+ *
+ * Quick notes for USING these classes from outside this package:
+ *
+ * Usage should be fairly straightforward, but there are a few surprising
+ * gotchas. First, when you implement callbacks, YOU are responsible for
+ * ensuring that the callback objects are not garbage-collected while they might
+ * still be called! So make sure you keep them in member variables or similar,
+ * because Java will not know if there are still native references to them.
+ *
+ * When using Frontlib from outside its package, you only interact with structs
+ * via the PointerType classes. They allow you to get at the data of the struct
+ * with a function called deref(), which creates a plain normal Java object
+ * representing the data (e.g. SchemePtr.deref() will give you a Scheme object).
+ *
+ * Remember that you usually have to destroy structs that you receive from the
+ * library, because they are owned by the native code, not Java. The recommended
+ * pattern for most cases is to call deref() on the pointer to get a Java object
+ * (that you can keep as long as you like), and then immediately destroy the
+ * struct if it needs destroying. To find out whether and how the struct needs
+ * to be destroyed, see the library's documentation of the function that you got
+ * the struct from.
+ *
+ * To pass new structs to the library, you can use the static createJavaOwned()
+ * function in each PointerType, which creates a new struct from the Java object
+ * you provide, and returns a pointer to that struct that you can pass to
+ * library functions. This new structure's memory is owned and managed by Java
+ * code, so do not destroy it with frontlib functions!
+ *
+ * There is a slight mismatch between the data model for the game setup. The
+ * frontlib supports setting initial health and weaponset per-hog, because the
+ * engine allows for that, but currently neither the networking protocol nor the
+ * PC frontend support this feature, so the Android version does not take
+ * advantage of it either and treats both as per-game settings. The initial
+ * health is contained in the game scheme, the weaponset is explicitly part of
+ * the GameConfig. When converting GameConfig to a native flib_gamesetup, both
+ * are automatically copied to all hogs in the game, and for the reverse
+ * conversion the weaponset of the first hog of the first team is used as the
+ * GameConfig weaponset. This means that GameConfig.weaponset will be null if
+ * there are no teams in the game.
+ *
+ * When starting a network game, you only need to query the GameSetupPtr from
+ * the netconn and use it to create the gameconn - this is preferable to using
+ * your own recreation of the game setup, because that way the same piece of
+ * code is used to determine the game setup on all platforms.
+ *
+ * The "context" parameter of the callbacks is never needed here because JNA
+ * generates function code for each callback object. Don't worry about it, just
+ * pass null for context and ignore the context parameter in the callbacks.
+ *
+ * Finally, the library functions are documented in the actual library, not
+ * here, so check the docs there to find out what exactly each function does!
+ *
+ * Notes about the structure of this class (for the next one who has to touch
+ * this...):
+ *
+ * Java/C interop is quite fiddly and error-prone, so as long as things work,
+ * try to stick to the established patterns.
+ *
+ * Structure types should always be hidden from the outside world, because they
+ * can be misused too easily. For example, if you get a Structure from the
+ * library, change a String value in there and pass it back, JNA will re-write
+ * that string using Java-owned memory without freeing the old native-owned
+ * string, which causes a memory leak and possibly a double-free or other Bad
+ * Things (tm). To avoid problems like this, Structure types are only used
+ * internally, to map existing structures to Java types (without modifying them)
+ * or to create brand-new, Java-owned structures. Both operations are exposed to
+ * the outside through the PointerType classes corresponding to the structures
+ * in question.
+ *
+ * Since all of the struct mapping happens in Java, it is never checked against
+ * the actual struct declarations in the library. That means strange things can
+ * start happening at runtime if the frontlib structs are modified without
+ * changing the mappings here to match. This also applies to the function
+ * signatures: JNA checks whether the functions actually exist when loading the
+ * library, but it has no way of knowing whether the signatures are correct. If
+ * the signatures here deviate from those in the frontlib, you might get stack
+ * corruption.
+ *
+ * In order to check at least the function signatures, take a look at the file
+ * extra/jnacontrol.c in the frontlib sources. You can validate whether the
+ * function signatures are still correct by copy-pasting them into jnaControl.c
+ * and compiling it against the frontlib headers. The typedefs and #defines in
+ * that file will make the compiler see the Java method signatures as C function
+ * declarations. Since the same functions are already declared in the frontlib
+ * headers, the compiler will give you errors if the signatures don't match.
+ */
+public interface Frontlib extends Library {
+    public static class NetconnPtr extends PointerType { }
+    public static class MapconnPtr extends PointerType { }
+    public static class GameconnPtr extends PointerType { }
+
+    public static class MetaschemePtr extends PointerType {
+        public MetaScheme deref() {
+            return deref(getPointer());
+        }
+
+        public static MetaScheme deref(Pointer p) {
+            MetaschemeStruct struct = new MetaschemeStruct(p);
+            struct.read();
+            return struct.toMetaScheme();
+        }
+    }
+
+    public static class RoomArrayPtr extends PointerType {
+        public Room[] getRooms(int count) {
+            Pointer ptr = getPointer();
+            if(ptr == null) {
+                return new Room[0];
+            }
+            Pointer[] untypedPtrs = ptr.getPointerArray(0, count);
+            Room[] result = new Room[count];
+            for(int i=0; i<count; i++) {
+                result[i] = RoomPtr.deref(untypedPtrs[i]);
+            }
+            return result;
+        }
+    }
+
+    public static class RoomPtr extends PointerType {
+        public Room deref() {
+            return deref(getPointer());
+        }
+
+        public static Room deref(Pointer p) {
+            RoomStruct struct = new RoomStruct(p);
+            struct.read();
+            return struct.toRoomlistRoom();
+        }
+    }
+
+    public static class TeamPtr extends PointerType {
+        private TeamStruct javaOwnedInstance;
+
+        public TeamInGame deref() {
+            TeamStruct struct = new TeamStruct(getPointer());
+            struct.read();
+            return struct.toTeamInGame();
+        }
+
+        public static TeamPtr createJavaOwned(Team t) {
+            return createJavaOwned(new TeamInGame(t, null));
+        }
+
+        public static TeamPtr createJavaOwned(TeamInGame ingameTeam) {
+            TeamPtr result = new TeamPtr();
+            result.javaOwnedInstance = new TeamStruct();
+            result.javaOwnedInstance.fillFrom(ingameTeam.team, ingameTeam.ingameAttribs);
+            result.javaOwnedInstance.autoWrite();
+            result.setPointer(result.javaOwnedInstance.getPointer());
+            return result;
+        }
+    }
+
+    public static class WeaponsetPtr extends PointerType {
+        private WeaponsetStruct javaOwnedInstance;
+
+        public Weaponset deref() {
+            WeaponsetStruct struct = new WeaponsetStruct(getPointer());
+            struct.read();
+            return struct.toWeaponset();
+        }
+
+        public static WeaponsetPtr createJavaOwned(Weaponset weaponset) {
+            WeaponsetPtr result = new WeaponsetPtr();
+            result.javaOwnedInstance = new WeaponsetStruct();
+            result.javaOwnedInstance.fillFrom(weaponset);
+            result.javaOwnedInstance.autoWrite();
+            result.setPointer(result.javaOwnedInstance.getPointer());
+            return result;
+        }
+    }
+
+    public static class WeaponsetListPtr extends PointerType {
+        private WeaponsetListStruct javaOwnedInstance;
+
+        public List<Weaponset> deref() {
+            WeaponsetListStruct struct = new WeaponsetListStruct(getPointer());
+            struct.read();
+            return struct.toWeaponsetList();
+        }
+
+        public static WeaponsetListPtr createJavaOwned(List<Weaponset> list) {
+            WeaponsetListPtr result = new WeaponsetListPtr();
+            result.javaOwnedInstance = new WeaponsetListStruct();
+            result.javaOwnedInstance.fillFrom(list);
+            result.javaOwnedInstance.autoWrite();
+            result.setPointer(result.javaOwnedInstance.getPointer());
+            return result;
+        }
+    }
+
+    public static class MapRecipePtr extends PointerType {
+        private MapRecipeStruct javaOwnedInstance;
+
+        public MapRecipe deref() {
+            MapRecipeStruct struct = new MapRecipeStruct(getPointer());
+            struct.read();
+            return struct.toMapRecipe();
+        }
+
+        public static MapRecipePtr createJavaOwned(MapRecipe recipe) {
+            MapRecipePtr result = new MapRecipePtr();
+            result.javaOwnedInstance = new MapRecipeStruct();
+            result.javaOwnedInstance.fillFrom(recipe);
+            result.javaOwnedInstance.autoWrite();
+            result.setPointer(result.javaOwnedInstance.getPointer());
+            return result;
+        }
+    }
+
+    public static class SchemePtr extends PointerType {
+        private SchemeStruct javaOwnedInstance;
+
+        public Scheme deref() {
+            SchemeStruct struct = new SchemeStruct(getPointer());
+            struct.read();
+            return struct.toScheme();
+        }
+
+        public static SchemePtr createJavaOwned(Scheme scheme) {
+            SchemePtr result = new SchemePtr();
+            result.javaOwnedInstance = new SchemeStruct();
+            result.javaOwnedInstance.fillFrom(scheme);
+            result.javaOwnedInstance.autoWrite();
+            result.setPointer(result.javaOwnedInstance.getPointer());
+            return result;
+        }
+    }
+
+    public static class SchemelistPtr extends PointerType {
+        private SchemelistStruct javaOwnedInstance;
+
+        public List<Scheme> deref() {
+            SchemelistStruct struct = new SchemelistStruct(getPointer());
+            struct.read();
+            return struct.toSchemeList();
+        }
+
+        public static SchemelistPtr createJavaOwned(List<Scheme> schemes) {
+            SchemelistPtr result = new SchemelistPtr();
+            result.javaOwnedInstance = new SchemelistStruct();
+            result.javaOwnedInstance.fillFrom(schemes);
+            result.javaOwnedInstance.autoWrite();
+            result.setPointer(result.javaOwnedInstance.getPointer());
+            return result;
+        }
+    }
+
+    public static class GameSetupPtr extends PointerType {
+        private GameSetupStruct javaOwnedInstance;
+
+        public GameConfig deref() {
+            GameSetupStruct struct = new GameSetupStruct(getPointer());
+            struct.read();
+            return struct.toGameConfig();
+        }
+
+        public static GameSetupPtr createJavaOwned(GameConfig conf) {
+            GameSetupPtr result = new GameSetupPtr();
+            result.javaOwnedInstance = new GameSetupStruct();
+            result.javaOwnedInstance.fillFrom(conf);
+            result.javaOwnedInstance.autoWrite();
+            result.setPointer(result.javaOwnedInstance.getPointer());
+            return result;
+        }
+    }
+
+    public static class ByteArrayPtr extends PointerType {
+        public byte[] deref(int size) {
+            return getPointer().getByteArray(0, size);
+        }
+
+        public static byte[] deref(ByteArrayPtr ptr, int size) {
+            if(ptr==null && size==0) {
+                return null;
+            } else {
+                return ptr.deref(size);
+            }
+        }
+
+        public static ByteArrayPtr createJavaOwned(byte[] buffer) {
+            if(buffer == null || buffer.length == 0) {
+                return null;
+            }
+            // no need for javaOwnedInstance here because PointerType
+            // remembers the memory as its Pointer
+            Pointer ptr = new Memory(buffer.length);
+            ptr.write(0, buffer, 0, buffer.length);
+            ByteArrayPtr result = new ByteArrayPtr();
+            result.setPointer(ptr);
+            return result;
+        }
+    }
+
+    static class HogStruct extends Structure {
+        public static class ByVal extends HogStruct implements Structure.ByValue {}
+        public static class ByRef extends HogStruct implements Structure.ByReference {}
+
+        public HogStruct() { super(); }
+        public HogStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("name", "hat", "rounds", "kills", "deaths", "suicides", "difficulty", "initialHealth", "weaponset");
+        }
+
+        public void fillFrom(Hog hog) {
+            difficulty = hog.level;
+            hat = hog.hat;
+            name = hog.name;
+        }
+
+        public Hog toHog() {
+            return new Hog(name, hat, difficulty);
+        }
+
+        public String name;
+        public String hat;
+
+        public int rounds;
+        public int kills;
+        public int deaths;
+        public int suicides;
+
+        public int difficulty;
+
+        public int initialHealth;
+        public WeaponsetStruct.ByRef weaponset;
+    }
+
+    static class TeamStruct extends Structure {
+        public static class ByVal extends TeamStruct implements Structure.ByValue {}
+        public static class ByRef extends TeamStruct implements Structure.ByReference {}
+
+        public TeamStruct() { super(); }
+        public TeamStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("hogs", "name", "grave", "fort", "voicepack", "flag", "bindings", "bindingCount", "rounds", "wins", "campaignProgress", "colorIndex", "hogsInGame", "remoteDriven", "ownerName");
+        }
+
+        public void fillFrom(Team team, TeamIngameAttributes attrs) {
+            if(team != null) {
+                name = team.name;
+                grave = team.grave;
+                flag = team.flag;
+                voicepack = team.voice;
+                fort = team.fort;
+                if(team.hogs.size() != Team.HEDGEHOGS_PER_TEAM) {
+                    throw new IllegalArgumentException();
+                }
+                for(int i=0; i<hogs.length; i++) {
+                    hogs[i] = new HogStruct();
+                    hogs[i].fillFrom(team.hogs.get(i));
+                }
+            }
+
+            if(attrs != null) {
+                hogsInGame = attrs.hogCount;
+                ownerName = attrs.ownerName;
+                colorIndex = attrs.colorIndex;
+                remoteDriven = attrs.remoteDriven;
+            }
+        }
+
+        public void fillFrom(TeamInGame team, WeaponsetStruct.ByRef weaponset, int initialHealth) {
+            fillFrom(team.team, team.ingameAttribs);
+            for(int i=0; i<hogs.length; i++) {
+                hogs[i].initialHealth = initialHealth;
+                hogs[i].weaponset = weaponset;
+            }
+        }
+
+        public Team toTeam() {
+            List<Hog> hogList = new ArrayList<Hog>();
+            for(int i=0; i<hogs.length; i++) {
+                hogList.add(hogs[i].toHog());
+            }
+            return new Team(name, grave, flag, voicepack, fort, hogList);
+        }
+
+        public TeamIngameAttributes toTeamIngameAttributes() {
+            return new TeamIngameAttributes(ownerName, colorIndex, hogsInGame, remoteDriven);
+        }
+
+        public TeamInGame toTeamInGame() {
+            return new TeamInGame(toTeam(), toTeamIngameAttributes());
+        }
+
+        public HogStruct[] hogs = new HogStruct[Team.HEDGEHOGS_PER_TEAM];
+        public String name;
+        public String grave;
+        public String fort;
+        public String voicepack;
+        public String flag;
+
+        public Pointer bindings;
+        public int bindingCount;
+
+        public int rounds;
+        public int wins;
+        public int campaignProgress;
+
+        public int colorIndex;
+        public int hogsInGame;
+        public boolean remoteDriven;
+        public String ownerName;
+    }
+
+    static class WeaponsetStruct extends Structure {
+        public static class ByVal extends WeaponsetStruct implements Structure.ByValue {}
+        public static class ByRef extends WeaponsetStruct implements Structure.ByReference {}
+
+        public WeaponsetStruct() { super(); }
+        public WeaponsetStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("loadout", "crateprob", "crateammo", "delay", "name");
+        }
+
+        public void fillFrom(Weaponset weaponset) {
+            fillWeaponInfo(loadout, weaponset.loadout);
+            fillWeaponInfo(crateprob, weaponset.crateProb);
+            fillWeaponInfo(crateammo, weaponset.crateAmmo);
+            fillWeaponInfo(delay, weaponset.delay);
+            name = weaponset.name;
+        }
+
+        private static void fillWeaponInfo(byte[] array, String str) {
+            for(int i=0; i<array.length-1; i++) {
+                array[i] = (byte) (i<str.length() ? str.charAt(i) : '0');
+            }
+            array[array.length-1] = (byte)0;
+        }
+
+        public Weaponset toWeaponset() {
+            return new Weaponset(name, weaponInfoToString(loadout), weaponInfoToString(crateprob), weaponInfoToString(crateammo), weaponInfoToString(delay));
+        }
+
+        private static String weaponInfoToString(byte[] array) {
+            try {
+                return new String(array, 0, array.length-1, "ASCII");
+            } catch (UnsupportedEncodingException e) {
+                throw new AssertionError();
+            }
+        }
+
+        public byte[] loadout = new byte[Weaponset.WEAPONS_COUNT+1];
+        public byte[] crateprob = new byte[Weaponset.WEAPONS_COUNT+1];
+        public byte[] crateammo = new byte[Weaponset.WEAPONS_COUNT+1];
+        public byte[] delay = new byte[Weaponset.WEAPONS_COUNT+1];
+        public String name;
+    }
+
+    /**
+     * Represents a flib_weaponset*, for use as part of a flib_weaponset**
+     */
+    static class WeaponsetPointerByReference extends Structure implements Structure.ByReference {
+        public WeaponsetPointerByReference() { super(); }
+        public WeaponsetPointerByReference(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("weaponset");
+        }
+
+        public WeaponsetStruct.ByRef weaponset;
+    }
+
+    static class WeaponsetListStruct extends Structure {
+        public static class ByVal extends WeaponsetListStruct implements Structure.ByValue {}
+        public static class ByRef extends WeaponsetListStruct implements Structure.ByReference {}
+
+        public WeaponsetListStruct() { super(); }
+        public WeaponsetListStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("weaponsetCount", "weaponsets");
+        }
+
+        public void fillFrom(List<Weaponset> list) {
+            weaponsetCount = list.size();
+            if(weaponsetCount<=0) {
+                weaponsets = null;
+            } else {
+                weaponsets = new WeaponsetPointerByReference();
+                Structure[] structs = weaponsets.toArray(weaponsetCount);
+
+                for(int i=0; i<weaponsetCount; i++) {
+                    WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i];
+                    pstruct.weaponset = new WeaponsetStruct.ByRef();
+                    pstruct.weaponset.fillFrom(list.get(i));
+                }
+            }
+        }
+
+        /**
+         * Only use on native-owned structs!
+         * Calling this method on a Java-owned struct could cause garbage collection of referenced
+         * structures.
+         */
+        public List<Weaponset> toWeaponsetList() {
+            if(weaponsetCount<=0) {
+                return new ArrayList<Weaponset>();
+            } else {
+                List<Weaponset> list = new ArrayList<Weaponset>(weaponsetCount);
+                Structure[] structs = weaponsets.toArray(weaponsetCount);
+
+                for(int i=0; i<weaponsetCount; i++) {
+                    WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i];
+                    list.add(pstruct.weaponset.toWeaponset());
+                }
+                return list;
+            }
+        }
+
+        public int weaponsetCount;
+        public WeaponsetPointerByReference weaponsets;
+    }
+
+    static class RoomStruct extends Structure {
+        public static class ByVal extends RoomStruct implements Structure.ByValue {}
+        public static class ByRef extends RoomStruct implements Structure.ByReference {}
+
+        public RoomStruct() { super(); }
+        public RoomStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("inProgress", "name", "playerCount", "teamCount", "owner", "map", "scheme", "weapons");
+        }
+
+        public Room toRoomlistRoom() {
+            return new Room(name, map, scheme, weapons, owner, playerCount, teamCount, inProgress);
+        }
+
+        public boolean inProgress;
+        public String name;
+        public int playerCount;
+        public int teamCount;
+        public String owner;
+        public String map;
+        public String scheme;
+        public String weapons;
+    }
+
+    static class MapRecipeStruct extends Structure {
+        public static class ByVal extends MapRecipeStruct implements Structure.ByValue {}
+        public static class ByRef extends MapRecipeStruct implements Structure.ByReference {}
+
+        public MapRecipeStruct() { super(); }
+        public MapRecipeStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("mapgen", "name", "seed", "theme", "drawData", "drawDataSize", "templateFilter", "mazeSize");
+        }
+
+        public void fillFrom(MapRecipe map) {
+            mapgen = map.mapgen;
+            name = map.name;
+            seed = map.seed;
+            theme = map.theme;
+            byte[] buf = map.getDrawData();
+            drawData = ByteArrayPtr.createJavaOwned(buf);
+            drawDataSize = NativeSizeT.valueOf(buf==null ? 0 : buf.length);
+            templateFilter = map.templateFilter;
+            mazeSize = map.mazeSize;
+        }
+
+        public MapRecipe toMapRecipe() {
+            byte[] buf = ByteArrayPtr.deref(drawData, drawDataSize.intValue());
+            return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, buf);
+        }
+
+        public int mapgen;
+        public String name;
+        public String seed;
+        public String theme;
+        public ByteArrayPtr drawData;
+        public NativeSizeT drawDataSize;
+        public int templateFilter;
+        public int mazeSize;
+    }
+
+    static class MetaschemeSettingStruct extends Structure {
+        public static class ByVal extends MetaschemeSettingStruct implements Structure.ByValue {}
+        public static class ByRef extends MetaschemeSettingStruct implements Structure.ByReference {}
+
+        public MetaschemeSettingStruct() { super(); }
+        public MetaschemeSettingStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("name", "engineCommand", "maxMeansInfinity", "times1000", "min", "max", "def");
+        }
+
+        public void fillFrom(Setting setting) {
+            name = setting.name;
+            engineCommand = setting.engineCommand;
+            maxMeansInfinity = setting.maxMeansInfinity;
+            times1000 = setting.times1000;
+            min = setting.min;
+            max = setting.max;
+            def = setting.def;
+        }
+
+        public MetaScheme.Setting toMetaSchemeSetting() {
+            return new MetaScheme.Setting(name, engineCommand, maxMeansInfinity, times1000, min, max, def);
+        }
+
+        public String name;
+        public String engineCommand;
+        public boolean maxMeansInfinity;
+        public boolean times1000;
+        public int min;
+        public int max;
+        public int def;
+    }
+
+    static class MetaschemeModStruct extends Structure {
+        public static class ByVal extends MetaschemeModStruct implements Structure.ByValue {}
+        public static class ByRef extends MetaschemeModStruct implements Structure.ByReference {}
+
+        public MetaschemeModStruct() { super(); }
+        public MetaschemeModStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("name", "bitmaskIndex");
+        }
+
+        public void fillFrom(Mod mod) {
+            name = mod.name;
+            bitmaskIndex = mod.bitmaskIndex;
+        }
+
+        public MetaScheme.Mod toMetaSchemeMod() {
+            return new MetaScheme.Mod(name, bitmaskIndex);
+        }
+
+        public String name;
+        public int bitmaskIndex;
+
+    }
+
+    static class MetaschemeStruct extends Structure {
+        public static class ByVal extends MetaschemeStruct implements Structure.ByValue {}
+        public static class ByRef extends MetaschemeStruct implements Structure.ByReference {}
+
+        public MetaschemeStruct() { super(); }
+        public MetaschemeStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("settingCount", "modCount", "settings", "mods");
+        }
+
+        /**
+         * Only use on native-owned structs!
+         * Calling this method on a Java-owned struct could cause garbage collection of referenced
+         * structures.
+         */
+        public MetaScheme toMetaScheme() {
+            List<MetaScheme.Setting> settingList = new ArrayList<MetaScheme.Setting>(settingCount);
+            List<MetaScheme.Mod> modList = new ArrayList<MetaScheme.Mod>(modCount);
+
+            Structure[] settingStructs = settings.toArray(settingCount);
+            Structure[] modStructs = mods.toArray(modCount);
+
+            for(int i=0; i<settingCount; i++) {
+                MetaschemeSettingStruct mss = (MetaschemeSettingStruct)settingStructs[i];
+                settingList.add(mss.toMetaSchemeSetting());
+            }
+
+            for(int i=0; i<modCount; i++) {
+                MetaschemeModStruct mms = (MetaschemeModStruct)modStructs[i];
+                modList.add(mms.toMetaSchemeMod());
+            }
+
+            return new MetaScheme(modList, settingList);
+        }
+
+        public int settingCount;
+        public int modCount;
+        public MetaschemeSettingStruct.ByRef settings;
+        public MetaschemeModStruct.ByRef mods;
+    }
+
+    static class SchemeStruct extends Structure {
+        public static class ByVal extends SchemeStruct implements Structure.ByValue {}
+        public static class ByRef extends SchemeStruct implements Structure.ByReference {}
+
+        public SchemeStruct() { super(); }
+        public SchemeStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("name", "settings", "mods");
+        }
+
+        public void fillFrom(Scheme scheme) {
+            MetaScheme meta = MetaScheme.INSTANCE;
+            name = scheme.name;
+            settings = new Memory(AndroidTypeMapper.NATIVE_INT_SIZE * meta.settings.size());
+            for(int i=0; i<meta.settings.size(); i++) {
+                Integer value = scheme.settings.get(meta.settings.get(i).name);
+                settings.setInt(AndroidTypeMapper.NATIVE_INT_SIZE*i, value);
+            }
+            mods = new Memory(AndroidTypeMapper.NATIVE_BOOL_SIZE * meta.mods.size());
+            for(int i=0; i<meta.mods.size(); i++) {
+                Boolean value = scheme.mods.get(meta.mods.get(i).name);
+                mods.setByte(AndroidTypeMapper.NATIVE_BOOL_SIZE*i, (byte)(value ? 1 : 0));
+            }
+        }
+
+        public Scheme toScheme() {
+            Map<String, Integer> settingsMap = new HashMap<String, Integer>();
+            MetaScheme meta = MetaScheme.INSTANCE;
+            for(int i=0; i<meta.settings.size(); i++) {
+                settingsMap.put(meta.settings.get(i).name, settings.getInt(AndroidTypeMapper.NATIVE_INT_SIZE*i));
+            }
+            Map<String, Boolean> modsMap = new HashMap<String, Boolean>();
+            for(int i=0; i<meta.mods.size(); i++) {
+                modsMap.put(meta.mods.get(i).name, mods.getByte(i) != 0 ? Boolean.TRUE : Boolean.FALSE);
+            }
+            return new Scheme(name, settingsMap, modsMap);
+        }
+
+        public String name;
+        public Pointer settings;
+        public Pointer mods;
+    }
+
+    /**
+     * Represents a flib_scheme*, for use as part of a flib_scheme**
+     */
+    static class SchemePointerByReference extends Structure implements Structure.ByReference {
+        public SchemePointerByReference() { super(); }
+        public SchemePointerByReference(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("scheme");
+        }
+
+        public SchemeStruct.ByRef scheme;
+    }
+
+    static class SchemelistStruct extends Structure {
+        public static class ByVal extends SchemelistStruct implements Structure.ByValue {}
+        public static class ByRef extends SchemelistStruct implements Structure.ByReference {}
+
+        public SchemelistStruct() { super(); }
+        public SchemelistStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("schemeCount", "schemes");
+        }
+
+        public void fillFrom(List<Scheme> schemeList) {
+            schemeCount = schemeList.size();
+            if(schemeCount<=0) {
+                schemes = null;
+            } else {
+                schemes = new SchemePointerByReference();
+                Structure[] schemePtrStructs = schemes.toArray(schemeCount);
+
+                for(int i=0; i<this.schemeCount; i++) {
+                    SchemePointerByReference spbr = (SchemePointerByReference)schemePtrStructs[i];
+                    spbr.scheme = new SchemeStruct.ByRef();
+                    spbr.scheme.fillFrom(schemeList.get(i));
+                }
+            }
+        }
+
+        /**
+         * Only use on native-owned structs!
+         * Calling this method on a Java-owned struct could cause garbage collection of referenced
+         * structures.
+         */
+        public List<Scheme> toSchemeList() {
+            if(schemeCount<=0) {
+                return new ArrayList<Scheme>();
+            } else {
+                List<Scheme> schemeList = new ArrayList<Scheme>(schemeCount);
+
+                Structure[] schemePtrStructs = schemes.toArray(schemeCount);
+
+                for(int i=0; i<schemeCount; i++) {
+                    SchemePointerByReference spbr2 = (SchemePointerByReference)schemePtrStructs[i];
+                    schemeList.add(spbr2.scheme.toScheme());
+                }
+                return schemeList;
+            }
+        }
+
+        public int schemeCount;
+        public SchemePointerByReference schemes;
+    }
+
+    /**
+     * Represents a flib_team*, for use as part of a flib_team**
+     */
+    static class TeamPointerByReference extends Structure implements Structure.ByReference {
+        public TeamPointerByReference() { super(); }
+        public TeamPointerByReference(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("team");
+        }
+
+        public TeamStruct.ByRef team;
+    }
+
+    static class TeamlistStruct extends Structure {
+        public static class ByVal extends TeamlistStruct implements Structure.ByValue {}
+        public static class ByRef extends TeamlistStruct implements Structure.ByReference {}
+
+        public TeamlistStruct() { super(); }
+        public TeamlistStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("teamCount", "teams");
+        }
+
+        public void fillFrom(List<TeamInGame> teamList, WeaponsetStruct.ByRef weaponset, int initialHealth) {
+            teamCount = teamList.size();
+            if(teamCount <= 0) {
+                teams = null;
+            } else {
+                teams = new TeamPointerByReference();
+                Structure[] teamPtrStructs = teams.toArray(teamCount);
+
+                for(int i=0; i<this.teamCount; i++) {
+                    TeamPointerByReference tpbr = (TeamPointerByReference)teamPtrStructs[i];
+                    tpbr.team = new TeamStruct.ByRef();
+                    tpbr.team.fillFrom(teamList.get(i), weaponset, initialHealth);
+                }
+            }
+        }
+
+        public List<TeamInGame> toTeamInGameList() {
+            if(teamCount<=0) {
+                return new ArrayList<TeamInGame>();
+            } else {
+                List<TeamInGame> result = new ArrayList<TeamInGame>(teamCount);
+                Structure[] structs = teams.toArray(teamCount);
+
+                for(int i=0; i<teamCount; i++) {
+                    TeamPointerByReference struct = (TeamPointerByReference)structs[i];
+                    result.add(struct.team.toTeamInGame());
+                }
+                return result;
+            }
+        }
+
+        public int teamCount;
+        public TeamPointerByReference teams;
+    }
+
+    static class GameSetupStruct extends Structure {
+        public static class ByVal extends GameSetupStruct implements Structure.ByValue {}
+        public static class ByRef extends GameSetupStruct implements Structure.ByReference {}
+
+        public GameSetupStruct() { super(); }
+        public GameSetupStruct(Pointer ptr) { super(ptr); }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList("script", "gamescheme", "map", "teamlist");
+        }
+
+        public void fillFrom(GameConfig conf) {
+            script = conf.style;
+            gamescheme = new SchemeStruct.ByRef();
+            gamescheme.fillFrom(conf.scheme);
+            map = new MapRecipeStruct.ByRef();
+            map.fillFrom(conf.map);
+
+            /*
+             * At this point we deviate from the usual copying pattern because the frontlib
+             * expects per-hog weapons and initial health, but the UI models them as per-
+             * game, so we extract them from the config here and pass them on to be included
+             * in each hog.
+             */
+            WeaponsetStruct.ByRef wss = new WeaponsetStruct.ByRef();
+            wss.fillFrom(conf.weaponset);
+            int initialHealth = conf.scheme.getHealth();
+
+            teamlist = new TeamlistStruct.ByRef();
+            teamlist.fillFrom(conf.teams, wss, initialHealth);
+        }
+
+        public GameConfig toGameConfig() {
+            Scheme scheme = gamescheme != null ? gamescheme.toScheme() : null;
+            MapRecipe mapRecipe = map != null ? map.toMapRecipe() : null;
+            List<TeamInGame> teams = teamlist != null ? teamlist.toTeamInGameList() : null;
+
+            WeaponsetStruct weaponsetStruct = teamlist != null && teamlist.teamCount>0 ? teamlist.teams.team.hogs[0].weaponset : null;
+            Weaponset weaponset = weaponsetStruct != null ? weaponsetStruct.toWeaponset() : null;
+            return new GameConfig(script, scheme, mapRecipe, teams, weaponset);
+        }
+
+        public String script;
+        public SchemeStruct.ByRef gamescheme;
+        public MapRecipeStruct.ByRef map;
+        public TeamlistStruct.ByRef teamlist;
+    }
+
+    /*
+     * Callback interfaces. The context parameter is never needed here and
+     * should always be ignored. Be sure to keep a reference to each callback
+     * for as long as they might be called by native code, to avoid premature
+     * garbage collection.
+     */
+    public static interface VoidCallback extends Callback {
+        void callback(Pointer context);
+    }
+
+    public static interface StrCallback extends Callback {
+        void callback(Pointer context, String arg1);
+    }
+
+    public static interface IntCallback extends Callback {
+        void callback(Pointer context, int arg1);
+    }
+
+    public static interface IntStrCallback extends Callback {
+        void callback(Pointer context, int arg1, String arg2);
+    }
+
+    public static interface StrIntCallback extends Callback {
+        void callback(Pointer context, String arg1, int arg2);
+    }
+
+    public static interface StrStrCallback extends Callback {
+        void callback(Pointer context, String arg1, String arg2);
+    }
+
+    public static interface StrStrBoolCallback extends Callback {
+        void callback(Pointer context, String arg1, String arg2, boolean arg3);
+    }
+
+    public static interface RoomCallback extends Callback {
+        void callback(Pointer context, RoomPtr arg1);
+    }
+
+    public static interface RoomListCallback extends Callback {
+        void callback(Pointer context, RoomArrayPtr arg1, int count);
+    }
+
+    public static interface StrRoomCallback extends Callback {
+        void callback(Pointer context, String arg1, RoomPtr arg2);
+    }
+
+    public static interface BoolCallback extends Callback {
+        void callback(Pointer context, boolean arg1);
+    }
+
+    public static interface StrBoolCallback extends Callback {
+        void callback(Pointer context, String arg1, boolean arg2);
+    }
+
+    public static interface TeamCallback extends Callback {
+        void callback(Pointer context, TeamPtr arg1);
+    }
+
+    public static interface BytesCallback extends Callback {
+        void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size);
+    }
+
+    public static interface BytesBoolCallback extends Callback {
+        void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size, boolean arg3);
+    }
+
+    public static interface SchemeCallback extends Callback {
+        void callback(Pointer context, SchemePtr arg1);
+    }
+
+    public static interface MapIntCallback extends Callback {
+        void callback(Pointer context, MapRecipePtr arg1, int arg2);
+    }
+
+    public static interface WeaponsetCallback extends Callback {
+        void callback(Pointer context, WeaponsetPtr arg1);
+    }
+
+    public static interface MapimageCallback extends Callback {
+        void callback(Pointer context, ByteArrayPtr buffer, int hedgehogCount);
+    }
+
+    public static interface LogCallback extends Callback {
+        void callback(int level, String logMessage);
+    }
+
+    // frontlib.h
+    int flib_init();
+    void flib_quit();
+
+    // hwconsts.h
+    int flib_get_teamcolor(int colorIndex);
+    int flib_get_teamcolor_count();
+    int flib_get_hedgehogs_per_team();
+    int flib_get_weapons_count();
+    MetaschemePtr flib_get_metascheme();
+
+    // net/netconn.h
+    static final int NETCONN_STATE_CONNECTING = 0;
+    static final int NETCONN_STATE_LOBBY = 1;
+    static final int NETCONN_STATE_ROOM = 2;
+    static final int NETCONN_STATE_DISCONNECTED = 10;
+
+    static final int NETCONN_DISCONNECT_NORMAL = 0;
+    static final int NETCONN_DISCONNECT_SERVER_TOO_OLD = 1;
+    static final int NETCONN_DISCONNECT_AUTH_FAILED = 2;
+    static final int NETCONN_DISCONNECT_CONNLOST = 3;
+    static final int NETCONN_DISCONNECT_INTERNAL_ERROR = 100;
+
+    static final int NETCONN_ROOMLEAVE_ABANDONED = 0;
+    static final int NETCONN_ROOMLEAVE_KICKED = 1;
+
+    static final int NETCONN_MSG_TYPE_PLAYERINFO = 0;
+    static final int NETCONN_MSG_TYPE_SERVERMESSAGE = 1;
+    static final int NETCONN_MSG_TYPE_WARNING = 2;
+    static final int NETCONN_MSG_TYPE_ERROR = 3;
+
+    static final int NETCONN_MAPCHANGE_FULL = 0;
+    static final int NETCONN_MAPCHANGE_MAP = 1;
+    static final int NETCONN_MAPCHANGE_MAPGEN = 2;
+    static final int NETCONN_MAPCHANGE_DRAWNMAP = 3;
+    static final int NETCONN_MAPCHANGE_MAZE_SIZE = 4;
+    static final int NETCONN_MAPCHANGE_TEMPLATE = 5;
+    static final int NETCONN_MAPCHANGE_THEME = 6;
+    static final int NETCONN_MAPCHANGE_SEED = 7;
+
+    NetconnPtr flib_netconn_create(String playerName, String dataDirPath, String host, int port);
+    void flib_netconn_destroy(NetconnPtr conn);
+
+    void flib_netconn_tick(NetconnPtr conn);
+    boolean flib_netconn_is_chief(NetconnPtr conn);
+    String flib_netconn_get_playername(NetconnPtr conn);
+    GameSetupPtr flib_netconn_create_gamesetup(NetconnPtr conn);
+    int flib_netconn_send_quit(NetconnPtr conn, String quitmsg);
+    int flib_netconn_send_chat(NetconnPtr conn, String chat);
+    int flib_netconn_send_teamchat(NetconnPtr conn, String msg);
+    int flib_netconn_send_password(NetconnPtr conn, String passwd);
+    int flib_netconn_send_nick(NetconnPtr conn, String nick);
+    int flib_netconn_send_request_roomlist(NetconnPtr conn);
+    int flib_netconn_send_joinRoom(NetconnPtr conn, String room);
+    int flib_netconn_send_createRoom(NetconnPtr conn, String room);
+    int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName);
+    int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg);
+    int flib_netconn_send_toggleReady(NetconnPtr conn);
+    int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team);
+    int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname);
+    int flib_netconn_send_engineMessage(NetconnPtr conn, ByteArrayPtr message, NativeSizeT size);
+    int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount);
+    int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex);
+    int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset);
+    int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map);
+    int flib_netconn_send_mapName(NetconnPtr conn, String mapName);
+    int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen);
+    int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter);
+    int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize);
+    int flib_netconn_send_mapSeed(NetconnPtr conn, String seed);
+    int flib_netconn_send_mapTheme(NetconnPtr conn, String theme);
+    int flib_netconn_send_mapDrawdata(NetconnPtr conn, ByteArrayPtr drawData, NativeSizeT size);
+    int flib_netconn_send_script(NetconnPtr conn, String scriptName);
+    int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme);
+    int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError);
+    int flib_netconn_send_ban(NetconnPtr conn, String playerName);
+    int flib_netconn_send_kick(NetconnPtr conn, String playerName);
+    int flib_netconn_send_playerInfo(NetconnPtr conn, String playerName);
+    int flib_netconn_send_playerFollow(NetconnPtr conn, String playerName);
+    int flib_netconn_send_startGame(NetconnPtr conn);
+    int flib_netconn_send_toggleRestrictJoins(NetconnPtr conn);
+    int flib_netconn_send_toggleRestrictTeams(NetconnPtr conn);
+    int flib_netconn_send_clearAccountsCache(NetconnPtr conn);
+    int flib_netconn_send_setServerVar(NetconnPtr conn, String name, String value);
+    int flib_netconn_send_getServerVars(NetconnPtr conn);
+
+    void flib_netconn_onMessage(NetconnPtr conn, IntStrCallback callback, Pointer context);
+    void flib_netconn_onClientFlags(NetconnPtr conn, StrStrBoolCallback callback, Pointer context);
+    void flib_netconn_onChat(NetconnPtr conn, StrStrCallback callback, Pointer context);
+    void flib_netconn_onConnected(NetconnPtr conn, VoidCallback callback, Pointer context);
+    void flib_netconn_onDisconnected(NetconnPtr conn, IntStrCallback callback, Pointer context);
+    void flib_netconn_onRoomlist(NetconnPtr conn, RoomListCallback callback, Pointer context);
+    void flib_netconn_onRoomAdd(NetconnPtr conn, RoomCallback callback, Pointer context);
+    void flib_netconn_onRoomDelete(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onRoomUpdate(NetconnPtr conn, StrRoomCallback callback, Pointer context);
+    void flib_netconn_onLobbyJoin(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onLobbyLeave(NetconnPtr conn, StrStrCallback callback, Pointer context);
+    void flib_netconn_onNickTaken(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onPasswordRequest(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onEnterRoom(NetconnPtr conn, BoolCallback callback, Pointer context);
+    void flib_netconn_onLeaveRoom(NetconnPtr conn, IntStrCallback callback, Pointer context);
+    void flib_netconn_onTeamAdd(NetconnPtr conn, TeamCallback callback, Pointer context);
+    void flib_netconn_onTeamDelete(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onRoomJoin(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onRoomLeave(NetconnPtr conn, StrStrCallback callback, Pointer context);
+    void flib_netconn_onRunGame(NetconnPtr conn, VoidCallback callback, Pointer context);
+    void flib_netconn_onTeamAccepted(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onHogCountChanged(NetconnPtr conn, StrIntCallback callback, Pointer context);
+    void flib_netconn_onTeamColorChanged(NetconnPtr conn, StrIntCallback callback, Pointer context);
+    void flib_netconn_onEngineMessage(NetconnPtr conn, BytesCallback callback, Pointer context);
+    void flib_netconn_onSchemeChanged(NetconnPtr conn, SchemeCallback callback, Pointer context);
+    void flib_netconn_onMapChanged(NetconnPtr conn, MapIntCallback callback, Pointer context);
+    void flib_netconn_onScriptChanged(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onWeaponsetChanged(NetconnPtr conn, WeaponsetCallback callback, Pointer context);
+    void flib_netconn_onServerVar(NetconnPtr conn, StrStrCallback callback, Pointer context);
+
+    // ipc/gameconn.h
+    static final int GAME_END_FINISHED = 0;
+    static final int GAME_END_INTERRUPTED = 1;
+    static final int GAME_END_HALTED = 2;
+    static final int GAME_END_ERROR = 3;
+
+    GameconnPtr flib_gameconn_create(String playerName, GameSetupPtr setup, boolean netgame);
+    GameconnPtr flib_gameconn_create_playdemo(ByteArrayPtr demo, NativeSizeT size);
+    GameconnPtr flib_gameconn_create_loadgame(String playerName, ByteArrayPtr save, NativeSizeT size);
+    GameconnPtr flib_gameconn_create_campaign(String playerName, String seed, String script);
+
+    void flib_gameconn_destroy(GameconnPtr conn);
+    int flib_gameconn_getport(GameconnPtr conn);
+    void flib_gameconn_tick(GameconnPtr conn);
+
+    int flib_gameconn_send_enginemsg(GameconnPtr conn, ByteArrayPtr data, NativeSizeT len);
+    int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg);
+    int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg);
+    int flib_gameconn_send_quit(GameconnPtr conn);
+    int flib_gameconn_send_cmd(GameconnPtr conn, String cmdString);
+
+    void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context);
+    void flib_gameconn_onDisconnect(GameconnPtr conn, IntCallback callback, Pointer context);
+    void flib_gameconn_onErrorMessage(GameconnPtr conn, StrCallback callback, Pointer context);
+    void flib_gameconn_onChat(GameconnPtr conn, StrBoolCallback callback, Pointer context);
+    void flib_gameconn_onGameRecorded(GameconnPtr conn, BytesBoolCallback callback, Pointer context);
+    void flib_gameconn_onEngineMessage(GameconnPtr conn, BytesCallback callback, Pointer context);
+
+    // ipc/mapconn.h
+    public static final int MAPIMAGE_WIDTH = 256;
+    public static final int MAPIMAGE_HEIGHT = 128;
+    public static final int MAPIMAGE_BYTES = (MAPIMAGE_WIDTH/8*MAPIMAGE_HEIGHT);
+
+    MapconnPtr flib_mapconn_create(MapRecipePtr mapdesc);
+    void flib_mapconn_destroy(MapconnPtr conn);
+    int flib_mapconn_getport(MapconnPtr conn);
+    void flib_mapconn_onSuccess(MapconnPtr conn, MapimageCallback callback, Pointer context);
+    void flib_mapconn_onFailure(MapconnPtr conn, StrCallback callback, Pointer context);
+    void flib_mapconn_tick(MapconnPtr conn);
+
+    // model/map.h
+    public static final int MAPGEN_REGULAR = 0;
+    public static final int MAPGEN_MAZE = 1;
+    public static final int MAPGEN_DRAWN = 2;
+    public static final int MAPGEN_NAMED = 3;
+
+    public static final int TEMPLATEFILTER_ALL = 0;
+    public static final int TEMPLATEFILTER_SMALL = 1;
+    public static final int TEMPLATEFILTER_MEDIUM = 2;
+    public static final int TEMPLATEFILTER_LARGE = 3;
+    public static final int TEMPLATEFILTER_CAVERN = 4;
+    public static final int TEMPLATEFILTER_WACKY = 5;
+
+    public static final int MAZE_SIZE_SMALL_TUNNELS = 0;
+    public static final int MAZE_SIZE_MEDIUM_TUNNELS = 1;
+    public static final int MAZE_SIZE_LARGE_TUNNELS = 2;
+    public static final int MAZE_SIZE_SMALL_ISLANDS = 3;
+    public static final int MAZE_SIZE_MEDIUM_ISLANDS = 4;
+    public static final int MAZE_SIZE_LARGE_ISLANDS = 5;
+
+    // model/schemelist.h
+    SchemelistPtr flib_schemelist_from_ini(String filename);
+    int flib_schemelist_to_ini(String filename, SchemelistPtr list);
+    void flib_schemelist_destroy(SchemelistPtr list);
+
+    // model/team.h
+    TeamPtr flib_team_from_ini(String filename);
+    int flib_team_to_ini(String filename, TeamPtr team);
+    void flib_team_destroy(TeamPtr team);
+
+    // model/weapon.h
+    WeaponsetListPtr flib_weaponsetlist_from_ini(String filename);
+    int flib_weaponsetlist_to_ini(String filename, WeaponsetListPtr weaponsets);
+    void flib_weaponsetlist_destroy(WeaponsetListPtr list);
+
+    // model/gamesetup.h
+    void flib_gamesetup_destroy(GameSetupPtr gamesetup);
+
+    // util/logging.h
+    public static final int FLIB_LOGLEVEL_ALL = -100;
+    public static final int FLIB_LOGLEVEL_DEBUG = -1;
+    public static final int FLIB_LOGLEVEL_INFO = 0;
+    public static final int FLIB_LOGLEVEL_WARNING = 1;
+    public static final int FLIB_LOGLEVEL_ERROR = 2;
+    public static final int FLIB_LOGLEVEL_NONE = 100;
+
+    void flib_log_setLevel(int level);
+    void flib_log_setCallback(LogCallback callback);
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/NativeSizeT.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/NativeSizeT.java	Tue Jan 21 22:53:15 2014 +0100
@@ -22,37 +22,37 @@
 /**
  * This class represents the native C type size_t. On Android, this type could be mapped with int,
  * but we use a separate type to make it easier to adapt for other platforms if anyone wants to use
- * the mappings elsewhere. 
+ * the mappings elsewhere.
  */
 public final class NativeSizeT extends Number {
-	private static final long serialVersionUID = 1L;
-	private final long value;
-	
-	private NativeSizeT(long value) {
-		this.value = value;
-	}
-	
-	public static NativeSizeT valueOf(long l) {
-		return new NativeSizeT(l);
-	}
-	
-	@Override
-	public int intValue() {
-		return (int)value;
-	}
-	
-	@Override
-	public long longValue() {
-		return value;
-	}
+    private static final long serialVersionUID = 1L;
+    private final long value;
+
+    private NativeSizeT(long value) {
+        this.value = value;
+    }
+
+    public static NativeSizeT valueOf(long l) {
+        return new NativeSizeT(l);
+    }
+
+    @Override
+    public int intValue() {
+        return (int)value;
+    }
 
-	@Override
-	public double doubleValue() {
-		return value;
-	}
+    @Override
+    public long longValue() {
+        return value;
+    }
 
-	@Override
-	public float floatValue() {
-		return value;
-	}
+    @Override
+    public double doubleValue() {
+        return value;
+    }
+
+    @Override
+    public float floatValue() {
+        return value;
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ClientFlagsUpdate.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ClientFlagsUpdate.java	Tue Jan 21 22:53:15 2014 +0100
@@ -4,45 +4,45 @@
 import org.hedgewars.hedgeroid.Datastructures.PlayerInRoom;
 
 final class ClientFlagsUpdate {
-	public static final char FLAG_ADMIN = 'a';
-	public static final char FLAG_CHIEF = 'h';
-	public static final char FLAG_READY = 'r';
-	public static final char FLAG_REGISTERED = 'u';
-	
-	public final String nick, flags;
-	public final boolean newFlagState;
-	
-	public ClientFlagsUpdate(String nick, String flags, boolean newFlagState) {
-		this.nick = nick;
-		this.flags = flags;
-		this.newFlagState = newFlagState;
-	}
+    public static final char FLAG_ADMIN = 'a';
+    public static final char FLAG_CHIEF = 'h';
+    public static final char FLAG_READY = 'r';
+    public static final char FLAG_REGISTERED = 'u';
+
+    public final String nick, flags;
+    public final boolean newFlagState;
+
+    public ClientFlagsUpdate(String nick, String flags, boolean newFlagState) {
+        this.nick = nick;
+        this.flags = flags;
+        this.newFlagState = newFlagState;
+    }
+
+    public Player applyTo(Player p) {
+        return new Player(
+                p.name,
+                updatedFlag(FLAG_REGISTERED, p.registered),
+                updatedFlag(FLAG_ADMIN, p.admin));
+    }
 
-	public Player applyTo(Player p) {
-		return new Player(
-				p.name,
-				updatedFlag(FLAG_REGISTERED, p.registered),
-				updatedFlag(FLAG_ADMIN, p.admin));
-	}
-	
-	public PlayerInRoom applyTo(PlayerInRoom p) {
-		return new PlayerInRoom(
-				this.applyTo(p.player),
-				updatedFlag(FLAG_READY, p.ready),
-				updatedFlag(FLAG_CHIEF, p.roomChief));
-	}
-	
-	public boolean appliesTo(char flag) {
-		return flags.indexOf(flag) != -1;
-	}
-	
-	private boolean updatedFlag(char flag, boolean oldValue) {
-		return appliesTo(flag) ? newFlagState : oldValue;
-	}
-	
-	@Override
-	public String toString() {
-		return "ClientFlagsUpdate [nick=" + nick + ", flags=" + flags
-				+ ", newFlagState=" + newFlagState + "]";
-	}
+    public PlayerInRoom applyTo(PlayerInRoom p) {
+        return new PlayerInRoom(
+                this.applyTo(p.player),
+                updatedFlag(FLAG_READY, p.ready),
+                updatedFlag(FLAG_CHIEF, p.roomChief));
+    }
+
+    public boolean appliesTo(char flag) {
+        return flags.indexOf(flag) != -1;
+    }
+
+    private boolean updatedFlag(char flag, boolean oldValue) {
+        return appliesTo(flag) ? newFlagState : oldValue;
+    }
+
+    @Override
+    public String toString() {
+        return "ClientFlagsUpdate [nick=" + nick + ", flags=" + flags
+                + ", newFlagState=" + newFlagState + "]";
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/GameMessageListener.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/GameMessageListener.java	Tue Jan 21 22:53:15 2014 +0100
@@ -23,12 +23,12 @@
  * Interface with several event callbacks that represent network messages which are interesting
  * for a running game, e.g. because they concern the lifecycle of the game or because they contain
  * data that needs to be passed on.
- * 
+ *
  * These functions might be called on any thread.
  */
 public interface GameMessageListener {
-	void onChatMessage(String nick, String message);
-	void onEngineMessage(byte[] em);
-	void onMessage(int type, String message);
-	void onNetDisconnected();
+    void onChatMessage(String nick, String message);
+    void onEngineMessage(byte[] em);
+    void onMessage(int type, String message);
+    void onNetDisconnected();
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/MessageLog.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/MessageLog.java	Tue Jan 21 22:53:15 2014 +0100
@@ -44,126 +44,126 @@
 import android.util.Log;
 
 public class MessageLog {
-	private static final int BACKLOG_LINES = 200;
-	
-	private static final int INFO_COLOR = Color.GRAY;
-	private static final int PLAYERINFO_COLOR = Color.GREEN;
-	private static final int CHAT_COLOR = Color.GREEN;
-	private static final int MECHAT_COLOR = Color.CYAN;
-	private static final int WARN_COLOR = Color.RED;
-	private static final int ERROR_COLOR = Color.RED;
-	
-	private final Context context;
-	private List<Listener> observers = new LinkedList<Listener>();
-	private List<CharSequence> log = new LinkedList<CharSequence>();
-	
-	public MessageLog(Context context) {
-		this.context = context;
-	}
-	
-	private Spanned makeLogTime() {
-		String time = DateFormat.getTimeFormat(context).format(new Date());
-		return withColor("[" + time + "] ", INFO_COLOR);
-	}
-	
-	private static Spanned span(CharSequence s, Object o) {
-		Spannable spannable = new SpannableString(s);
-		spannable.setSpan(o, 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-		return spannable;
-	}
-	
-	private static Spanned withColor(CharSequence s, int color) {
-		return span(s, new ForegroundColorSpan(color));
-	}
-	
-	private static Spanned bold(CharSequence s) {
-		return span(s, new StyleSpan(Typeface.BOLD));
-	}
-	
-	private void append(CharSequence msg) {
-		SpannableStringBuilder ssb = new SpannableStringBuilder();
-		ssb.append(makeLogTime()).append(msg);
-		appendRaw(ssb);
-	}
-	
-	private void appendRaw(CharSequence msg) {
-		if(log.size() > BACKLOG_LINES) {
-			log.remove(0);
-			for(Listener o : observers) {
-				o.lineRemoved();
-			}
-		}
-		log.add(msg);
-		for(Listener o : observers) {
-			o.lineAdded(msg);
-		}
-	}
-	
-	void appendPlayerJoin(String playername) {
-		append(withColor("***" + context.getResources().getString(R.string.log_player_join, playername), INFO_COLOR));
-	}
-	
-	void appendPlayerLeave(String playername, String partMsg) {
-		String msg = "***";
-		if(partMsg != null) {
-			msg += context.getResources().getString(R.string.log_player_leave_with_msg, playername, partMsg);
-		} else {
-			msg += context.getResources().getString(R.string.log_player_leave, playername);
-		}
-		append(withColor(msg, INFO_COLOR));
-	}
-	
-	void appendChat(String playerName, String msg) {
-		if(msg.startsWith("/me ")) {
-			append(withColor("*"+playerName+" "+msg.substring(4), MECHAT_COLOR));
-		} else {
-			Spanned name = bold(playerName+": ");
-			Spanned fullMessage = withColor(TextUtils.concat(name, msg), CHAT_COLOR);
-			append(fullMessage);			
-		}
-	}
-	
-	void appendMessage(int type, String msg) {
-		switch(type) {
-		case Frontlib.NETCONN_MSG_TYPE_ERROR:
-			append(withColor("***"+msg, ERROR_COLOR));
-			break;
-		case Frontlib.NETCONN_MSG_TYPE_WARNING:
-			append(withColor("***"+msg, WARN_COLOR));
-			break;
-		case Frontlib.NETCONN_MSG_TYPE_PLAYERINFO:
-			append(withColor(msg.replace("\n", " "), PLAYERINFO_COLOR));
-			break;
-		case Frontlib.NETCONN_MSG_TYPE_SERVERMESSAGE:
-			appendRaw(span(TextUtils.concat("\n", Html.fromHtml(msg), "\n"), new RelativeSizeSpan(1.5f)));
-			break;
-		default:
-			Log.e("MessageLog", "Unknown messagetype "+type);
-		}
-	}
-	
-	void clear() {
-		for(Listener o : observers) {
-			o.clear();
-		}
-		log.clear();
-	}
-	
-	public void addListener(Listener o) {
-		observers.add(o);
-	}
-	
-	public void removeListener(Listener o) {
-		observers.remove(o);
-	}
-	
-	public static interface Listener {
-		void lineAdded(CharSequence text);
-		void lineRemoved();
-		void clear();
-	}
+    private static final int BACKLOG_LINES = 200;
+
+    private static final int INFO_COLOR = Color.GRAY;
+    private static final int PLAYERINFO_COLOR = Color.GREEN;
+    private static final int CHAT_COLOR = Color.GREEN;
+    private static final int MECHAT_COLOR = Color.CYAN;
+    private static final int WARN_COLOR = Color.RED;
+    private static final int ERROR_COLOR = Color.RED;
+
+    private final Context context;
+    private List<Listener> observers = new LinkedList<Listener>();
+    private List<CharSequence> log = new LinkedList<CharSequence>();
+
+    public MessageLog(Context context) {
+        this.context = context;
+    }
+
+    private Spanned makeLogTime() {
+        String time = DateFormat.getTimeFormat(context).format(new Date());
+        return withColor("[" + time + "] ", INFO_COLOR);
+    }
+
+    private static Spanned span(CharSequence s, Object o) {
+        Spannable spannable = new SpannableString(s);
+        spannable.setSpan(o, 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+        return spannable;
+    }
+
+    private static Spanned withColor(CharSequence s, int color) {
+        return span(s, new ForegroundColorSpan(color));
+    }
+
+    private static Spanned bold(CharSequence s) {
+        return span(s, new StyleSpan(Typeface.BOLD));
+    }
+
+    private void append(CharSequence msg) {
+        SpannableStringBuilder ssb = new SpannableStringBuilder();
+        ssb.append(makeLogTime()).append(msg);
+        appendRaw(ssb);
+    }
+
+    private void appendRaw(CharSequence msg) {
+        if(log.size() > BACKLOG_LINES) {
+            log.remove(0);
+            for(Listener o : observers) {
+                o.lineRemoved();
+            }
+        }
+        log.add(msg);
+        for(Listener o : observers) {
+            o.lineAdded(msg);
+        }
+    }
+
+    void appendPlayerJoin(String playername) {
+        append(withColor("***" + context.getResources().getString(R.string.log_player_join, playername), INFO_COLOR));
+    }
 
-	public Collection<CharSequence> getLog() {
-		return Collections.unmodifiableList(log);
-	}
+    void appendPlayerLeave(String playername, String partMsg) {
+        String msg = "***";
+        if(partMsg != null) {
+            msg += context.getResources().getString(R.string.log_player_leave_with_msg, playername, partMsg);
+        } else {
+            msg += context.getResources().getString(R.string.log_player_leave, playername);
+        }
+        append(withColor(msg, INFO_COLOR));
+    }
+
+    void appendChat(String playerName, String msg) {
+        if(msg.startsWith("/me ")) {
+            append(withColor("*"+playerName+" "+msg.substring(4), MECHAT_COLOR));
+        } else {
+            Spanned name = bold(playerName+": ");
+            Spanned fullMessage = withColor(TextUtils.concat(name, msg), CHAT_COLOR);
+            append(fullMessage);
+        }
+    }
+
+    void appendMessage(int type, String msg) {
+        switch(type) {
+        case Frontlib.NETCONN_MSG_TYPE_ERROR:
+            append(withColor("***"+msg, ERROR_COLOR));
+            break;
+        case Frontlib.NETCONN_MSG_TYPE_WARNING:
+            append(withColor("***"+msg, WARN_COLOR));
+            break;
+        case Frontlib.NETCONN_MSG_TYPE_PLAYERINFO:
+            append(withColor(msg.replace("\n", " "), PLAYERINFO_COLOR));
+            break;
+        case Frontlib.NETCONN_MSG_TYPE_SERVERMESSAGE:
+            appendRaw(span(TextUtils.concat("\n", Html.fromHtml(msg), "\n"), new RelativeSizeSpan(1.5f)));
+            break;
+        default:
+            Log.e("MessageLog", "Unknown messagetype "+type);
+        }
+    }
+
+    void clear() {
+        for(Listener o : observers) {
+            o.clear();
+        }
+        log.clear();
+    }
+
+    public void addListener(Listener o) {
+        observers.add(o);
+    }
+
+    public void removeListener(Listener o) {
+        observers.remove(o);
+    }
+
+    public static interface Listener {
+        void lineAdded(CharSequence text);
+        void lineRemoved();
+        void clear();
+    }
+
+    public Collection<CharSequence> getLog() {
+        return Collections.unmodifiableList(log);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/NetRoomState.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/NetRoomState.java	Tue Jan 21 22:53:15 2014 +0100
@@ -41,145 +41,145 @@
  * This class manages the room state in a network game.
  */
 class NetRoomState extends BasicRoomState {
-	final Map<String, TeamInGame> requestedTeams = new TreeMap<String, TeamInGame>();
-	private Netplay netplay;
-	
-	public NetRoomState(Netplay netplay) {
-		this.netplay = netplay;
-		initRoomState(false);
-	}
+    final Map<String, TeamInGame> requestedTeams = new TreeMap<String, TeamInGame>();
+    private Netplay netplay;
+
+    public NetRoomState(Netplay netplay) {
+        this.netplay = netplay;
+        initRoomState(false);
+    }
+
+    public void changeWeaponset(Weaponset weaponset) {
+        if(getChiefStatus() && !equal(weaponset, getWeaponset())) {
+            sendToNet(MSG_SEND_WEAPONSET, weaponset);
+            setWeaponset(weaponset);
+        }
+    }
+
+    public void changeMapRecipe(MapRecipe mapRecipe) {
+        if(getChiefStatus() && !equal(mapRecipe, getMapRecipe())) {
+            sendToNet(MSG_SEND_MAP, mapRecipe);
+            setMapRecipe(mapRecipe);
+        }
+    }
+
+    public void changeMapNameAndGenerator(String mapName) {
+        if(getChiefStatus() && !equal(mapName, getMapRecipe().name)) {
+            int newGenerator = MapRecipe.generatorForMapname(mapName);
+            if(newGenerator != getMapRecipe().mapgen) {
+                sendToNet(MSG_SEND_MAP_GENERATOR, newGenerator, null);
+            }
+            sendToNet(MSG_SEND_MAP_NAME, mapName);
+            setMapRecipe(getMapRecipe().withName(mapName).withMapgen(newGenerator));
+        }
+    }
+
+    public void changeMapTemplate(int template) {
+        if(getChiefStatus() && template != getMapRecipe().templateFilter) {
+            sendToNet(MSG_SEND_MAP_TEMPLATE, template, null);
+            setMapRecipe(getMapRecipe().withTemplateFilter(template));
+        }
+    }
+
+    public void changeMazeSize(int mazeSize) {
+        if(getChiefStatus() && mazeSize != getMapRecipe().mazeSize) {
+            sendToNet(MSG_SEND_MAZE_SIZE, mazeSize, 0);
+            setMapRecipe(getMapRecipe().withMazeSize(mazeSize));
+        }
+    }
+
+    public void changeMapSeed(String seed) {
+        if(getChiefStatus() && !equal(seed, getMapRecipe().seed)) {
+            sendToNet(MSG_SEND_MAP_SEED, seed);
+            setMapRecipe(getMapRecipe().withSeed(seed));
+        }
+    }
+
+    public void changeMapTheme(String theme) {
+        if(getChiefStatus() && !equal(theme, getMapRecipe().theme)) {
+            sendToNet(MSG_SEND_MAP_THEME, theme);
+            setMapRecipe(getMapRecipe().withTheme(theme));
+        }
+    }
+
+    public void changeMapDrawdata(byte[] drawdata) {
+        if(getChiefStatus() && !Arrays.equals(drawdata, getMapRecipe().getDrawData())) {
+            sendToNet(MSG_SEND_MAP_DRAWDATA, drawdata);
+            setMapRecipe(getMapRecipe().withDrawData(drawdata));
+        }
+    }
 
-	public void changeWeaponset(Weaponset weaponset) {
-		if(getChiefStatus() && !equal(weaponset, getWeaponset())) {
-			sendToNet(MSG_SEND_WEAPONSET, weaponset);
-			setWeaponset(weaponset);
-		}
-	}
-	
-	public void changeMapRecipe(MapRecipe mapRecipe) {
-		if(getChiefStatus() && !equal(mapRecipe, getMapRecipe())) {
-			sendToNet(MSG_SEND_MAP, mapRecipe);
-			setMapRecipe(mapRecipe);
-		}
-	}
-	
-	public void changeMapNameAndGenerator(String mapName) {
-		if(getChiefStatus() && !equal(mapName, getMapRecipe().name)) {
-			int newGenerator = MapRecipe.generatorForMapname(mapName);
-			if(newGenerator != getMapRecipe().mapgen) {
-				sendToNet(MSG_SEND_MAP_GENERATOR, newGenerator, null);
-			}
-			sendToNet(MSG_SEND_MAP_NAME, mapName);
-			setMapRecipe(getMapRecipe().withName(mapName).withMapgen(newGenerator));
-		}
-	}
-	
-	public void changeMapTemplate(int template) {
-		if(getChiefStatus() && template != getMapRecipe().templateFilter) {
-			sendToNet(MSG_SEND_MAP_TEMPLATE, template, null);
-			setMapRecipe(getMapRecipe().withTemplateFilter(template));
-		}
-	}
-	
-	public void changeMazeSize(int mazeSize) {
-		if(getChiefStatus() && mazeSize != getMapRecipe().mazeSize) {
-			sendToNet(MSG_SEND_MAZE_SIZE, mazeSize, 0);
-			setMapRecipe(getMapRecipe().withMazeSize(mazeSize));
-		}
-	}
-	
-	public void changeMapSeed(String seed) {
-		if(getChiefStatus() && !equal(seed, getMapRecipe().seed)) {
-			sendToNet(MSG_SEND_MAP_SEED, seed);
-			setMapRecipe(getMapRecipe().withSeed(seed));
-		}
-	}
-	
-	public void changeMapTheme(String theme) {
-		if(getChiefStatus() && !equal(theme, getMapRecipe().theme)) {
-			sendToNet(MSG_SEND_MAP_THEME, theme);
-			setMapRecipe(getMapRecipe().withTheme(theme));
-		}
-	}
-	
-	public void changeMapDrawdata(byte[] drawdata) {
-		if(getChiefStatus() && !Arrays.equals(drawdata, getMapRecipe().getDrawData())) {
-			sendToNet(MSG_SEND_MAP_DRAWDATA, drawdata);
-			setMapRecipe(getMapRecipe().withDrawData(drawdata));
-		}
-	}
-	
-	public void changeGameStyle(String gameStyle) {
-		if(getChiefStatus() && !equal(gameStyle, getGameStyle())) {
-			sendToNet(MSG_SEND_GAMESTYLE, gameStyle);
-			setGameStyle(gameStyle);
-		}
-	}
-	
-	public void changeScheme(Scheme scheme) {
-		if(getChiefStatus() && !equal(scheme, getScheme())) {
-			sendToNet(MSG_SEND_SCHEME, scheme);
-			setScheme(scheme);
-		}
-	}
-	
-	void initRoomState(boolean chief) {
-		setTeams(Collections.<String, TeamInGame>emptyMap());
-		requestedTeams.clear();
-		
-		setChief(chief);
-		setGameStyle(GameConfig.DEFAULT_STYLE);
-		setMapRecipe(MapRecipe.makeRandomMap(0, "seed", GameConfig.DEFAULT_THEME));
-		setScheme(netplay.defaultScheme);
-		setWeaponset(netplay.defaultWeaponset);
-		sendFullConfig();
-	}
-	
-	void sendFullConfig() {
-		if(getChiefStatus()) {
-			sendToNet(MSG_SEND_GAMESTYLE, getGameStyle());
-			sendToNet(MSG_SEND_SCHEME, getScheme());
-			sendToNet(MSG_SEND_WEAPONSET, getWeaponset());
-			sendToNet(MSG_SEND_MAP, getMapRecipe());
-		}
-	}
-	
-	private boolean sendToNet(ToNetMsgType what, Object obj) {
-		return netplay.sendToNet(what, 0, obj);
-	}
-	
-	private boolean sendToNet(ToNetMsgType what, int arg1, Object obj) {
-		return netplay.sendToNet(what, arg1, obj);
-	}
+    public void changeGameStyle(String gameStyle) {
+        if(getChiefStatus() && !equal(gameStyle, getGameStyle())) {
+            sendToNet(MSG_SEND_GAMESTYLE, gameStyle);
+            setGameStyle(gameStyle);
+        }
+    }
+
+    public void changeScheme(Scheme scheme) {
+        if(getChiefStatus() && !equal(scheme, getScheme())) {
+            sendToNet(MSG_SEND_SCHEME, scheme);
+            setScheme(scheme);
+        }
+    }
+
+    void initRoomState(boolean chief) {
+        setTeams(Collections.<String, TeamInGame>emptyMap());
+        requestedTeams.clear();
+
+        setChief(chief);
+        setGameStyle(GameConfig.DEFAULT_STYLE);
+        setMapRecipe(MapRecipe.makeRandomMap(0, "seed", GameConfig.DEFAULT_THEME));
+        setScheme(netplay.defaultScheme);
+        setWeaponset(netplay.defaultWeaponset);
+        sendFullConfig();
+    }
+
+    void sendFullConfig() {
+        if(getChiefStatus()) {
+            sendToNet(MSG_SEND_GAMESTYLE, getGameStyle());
+            sendToNet(MSG_SEND_SCHEME, getScheme());
+            sendToNet(MSG_SEND_WEAPONSET, getWeaponset());
+            sendToNet(MSG_SEND_MAP, getMapRecipe());
+        }
+    }
 
-	public void requestAddTeam(Team team, int colorIndex) {
-		TeamIngameAttributes tia = new TeamIngameAttributes(netplay.getPlayerName(), colorIndex, TeamIngameAttributes.DEFAULT_HOG_COUNT, false);
-		TeamInGame newTeamInGame = new TeamInGame(team, tia);
-		requestedTeams.put(team.name, newTeamInGame);
-		sendToNet(MSG_SEND_ADD_TEAM, newTeamInGame);
-	}
+    private boolean sendToNet(ToNetMsgType what, Object obj) {
+        return netplay.sendToNet(what, 0, obj);
+    }
+
+    private boolean sendToNet(ToNetMsgType what, int arg1, Object obj) {
+        return netplay.sendToNet(what, arg1, obj);
+    }
 
-	public void requestRemoveTeam(String teamname) {
-		sendToNet(MSG_SEND_REMOVE_TEAM, teamname);
-	}
+    public void requestAddTeam(Team team, int colorIndex) {
+        TeamIngameAttributes tia = new TeamIngameAttributes(netplay.getPlayerName(), colorIndex, TeamIngameAttributes.DEFAULT_HOG_COUNT, false);
+        TeamInGame newTeamInGame = new TeamInGame(team, tia);
+        requestedTeams.put(team.name, newTeamInGame);
+        sendToNet(MSG_SEND_ADD_TEAM, newTeamInGame);
+    }
+
+    public void requestRemoveTeam(String teamname) {
+        sendToNet(MSG_SEND_REMOVE_TEAM, teamname);
+    }
 
-	public void changeTeamColorIndex(String teamname, int colorIndex) {
-		if(getChiefStatus()) {
-			TeamInGame team = getTeams().get(teamname);
-			if(team.ingameAttribs.colorIndex != colorIndex) {
-				sendToNet(MSG_SEND_TEAM_COLOR_INDEX, colorIndex, teamname);
-				putTeam(team.withAttribs(team.ingameAttribs.withColorIndex(colorIndex)));
-			}
-		}
-	}
+    public void changeTeamColorIndex(String teamname, int colorIndex) {
+        if(getChiefStatus()) {
+            TeamInGame team = getTeams().get(teamname);
+            if(team.ingameAttribs.colorIndex != colorIndex) {
+                sendToNet(MSG_SEND_TEAM_COLOR_INDEX, colorIndex, teamname);
+                putTeam(team.withAttribs(team.ingameAttribs.withColorIndex(colorIndex)));
+            }
+        }
+    }
 
-	public void changeTeamHogCount(String teamname, int hogcount) {
-		if(getChiefStatus()) {
-			TeamInGame team = getTeams().get(teamname);
-			if(team.ingameAttribs.hogCount != hogcount) {
-				sendToNet(MSG_SEND_TEAM_HOG_COUNT, hogcount, teamname);
-				putTeam(team.withAttribs(team.ingameAttribs.withHogCount(hogcount)));
-			}
-		}
-	}
+    public void changeTeamHogCount(String teamname, int hogcount) {
+        if(getChiefStatus()) {
+            TeamInGame team = getTeams().get(teamname);
+            if(team.ingameAttribs.hogCount != hogcount) {
+                sendToNet(MSG_SEND_TEAM_HOG_COUNT, hogcount, teamname);
+                putTeam(team.withAttribs(team.ingameAttribs.withHogCount(hogcount)));
+            }
+        }
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netplay.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Netplay.java	Tue Jan 21 22:53:15 2014 +0100
@@ -1,535 +1,535 @@
-/*
- * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.hedgewars.hedgeroid.netplay;
-
-import static org.hedgewars.hedgeroid.netplay.ThreadedNetConnection.ToNetMsgType.*;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.hedgewars.hedgeroid.RoomStateManager;
-import org.hedgewars.hedgeroid.Datastructures.GameConfig;
-import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
-import org.hedgewars.hedgeroid.Datastructures.Player;
-import org.hedgewars.hedgeroid.Datastructures.PlayerInRoom;
-import org.hedgewars.hedgeroid.Datastructures.Room;
-import org.hedgewars.hedgeroid.Datastructures.Scheme;
-import org.hedgewars.hedgeroid.Datastructures.Schemes;
-import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
-import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
-import org.hedgewars.hedgeroid.Datastructures.Weaponset;
-import org.hedgewars.hedgeroid.Datastructures.Weaponsets;
-import org.hedgewars.hedgeroid.netplay.ThreadedNetConnection.ToNetMsgType;
-import org.hedgewars.hedgeroid.util.ObservableTreeMap;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.support.v4.content.LocalBroadcastManager;
-import android.util.Log;
-import android.util.Pair;
-
-
-/**
- * This class manages the application's networking state.
- */
-public class Netplay {
-	public static enum State { NOT_CONNECTED, CONNECTING, LOBBY, ROOM }
-	
-	// Extras in broadcasts
-	public static final String EXTRA_PLAYERNAME = "playerName";
-	public static final String EXTRA_MESSAGE = "message";
-	public static final String EXTRA_HAS_ERROR = "hasError";
-	public static final String EXTRA_REASON = "reason";
-	
-	private static final String ACTIONPREFIX = "org.hedgewars.hedgeroid.netconn.";
-	public static final String ACTION_DISCONNECTED = ACTIONPREFIX+"DISCONNECTED";
-	public static final String ACTION_CONNECTED = ACTIONPREFIX+"CONNECTED";
-	public static final String ACTION_PASSWORD_REQUESTED = ACTIONPREFIX+"PASSWORD_REQUESTED";
-	public static final String ACTION_ENTERED_ROOM_FROM_LOBBY = ACTIONPREFIX+"ENTERED_ROOM";
-	public static final String ACTION_LEFT_ROOM = ACTIONPREFIX+"LEFT_ROOM";
-	public static final String ACTION_STATE_CHANGED = ACTIONPREFIX+"STATE_CHANGED";
-	
-	public static final String DEFAULT_SERVER = "netserver.hedgewars.org";
-	public static final int DEFAULT_PORT = 46631;
-		
-	private final Context appContext;
-	private final LocalBroadcastManager broadcastManager;
-	private final FromNetHandler fromNetHandler = new FromNetHandler();
-	public final Scheme defaultScheme;
-	public final Weaponset defaultWeaponset;
-	
-	private State state = State.NOT_CONNECTED;
-	private String playerName;
-	
-	// null or stale if not in room state
-	private final NetRoomState netRoomState = new NetRoomState(this);
-	
-	// null if there is no running connection (==state is NOT_CONNECTED)
-	private ThreadedNetConnection connection;
-	
-	public final ObservableTreeMap<String, Player> lobbyPlayerlist = new ObservableTreeMap<String, Player>();
-	public final ObservableTreeMap<String, PlayerInRoom> roomPlayerlist = new ObservableTreeMap<String, PlayerInRoom>();
-	public final Roomlist roomList = new Roomlist();
-	public final MessageLog lobbyChatlog;
-	public final MessageLog roomChatlog;
-	
-	private final List<GameMessageListener> gameMessageListeners = new LinkedList<GameMessageListener>();
-	private final List<RunGameListener> runGameListeners = new LinkedList<RunGameListener>();
-	
-	public Netplay(Context appContext, Scheme defaultScheme, Weaponset defaultWeaponset) {
-		this.appContext = appContext;
-		broadcastManager = LocalBroadcastManager.getInstance(appContext);
-		lobbyChatlog = new MessageLog(appContext);
-		roomChatlog = new MessageLog(appContext);
-		this.defaultScheme = defaultScheme;
-		this.defaultWeaponset = defaultWeaponset;
-	}
-	
-	public RoomStateManager getRoomStateManager() {
-		return netRoomState;
-	}
-	
-	private void clearLobbyState() {
-		lobbyPlayerlist.clear();
-		roomList.clear();
-		lobbyChatlog.clear();
-	}
-	
-	private void initRoomState(boolean chief) {
-		roomChatlog.clear();
-		roomPlayerlist.clear();
-		netRoomState.initRoomState(chief);
-	}
-	
-	public void registerGameMessageListener(GameMessageListener listener) {
-		gameMessageListeners.add(listener);
-	}
-	
-	public void unregisterGameMessageListener(GameMessageListener listener) {
-		gameMessageListeners.remove(listener);
-	}
-	
-	public void registerRunGameListener(RunGameListener listener) {
-		runGameListeners.add(listener);
-	}
-	
-	public void unregisterRunGameListener(RunGameListener listener) {
-		runGameListeners.remove(listener);
-	}
-	
-	public void connectToDefaultServer(String playerName) {
-		connect(playerName, DEFAULT_SERVER, DEFAULT_PORT);
-	}
-	
-	/**
-	 * Establish a new connection. Only call if the current state is NOT_CONNECTED.
-	 * 
-	 * The state will switch to CONNECTING immediately. After that, it can asynchronously change to any other state.
-	 * State changes are indicated by broadcasts. In particular, if an error occurs while trying to connect, the state
-	 * will change back to NOT_CONNECTED and an ACTION_DISCONNECTED broadcast is sent.
-	 */
-	public void connect(String name, String host, int port) {
-		playerName = name;
-		if(state != State.NOT_CONNECTED) {
-			throw new IllegalStateException("Attempt to start a new connection while the old one was still running.");
-		}
-		
-		clearLobbyState();
-		changeState(State.CONNECTING);
-		connection = ThreadedNetConnection.startConnection(appContext, fromNetHandler, name, host, port);
-		connection.setFastTickRate(true);
-	}
-	
-	public void sendNick(String nick) {
-		playerName = nick;
-		sendToNet(MSG_SEND_NICK, nick);
-	}
-	public void sendPassword(String password) { sendToNet(MSG_SEND_PASSWORD, password); }
-	public void sendQuit(String message) { sendToNet(MSG_SEND_QUIT, message); }
-	public void sendRoomlistRequest() { sendToNet(MSG_SEND_ROOMLIST_REQUEST); }
-	public void sendPlayerInfoQuery(String name) { sendToNet(MSG_SEND_PLAYER_INFO_REQUEST, name); }
-	public void sendChat(String s) { sendToNet(MSG_SEND_CHAT, s); }
-	public void sendTeamChat(String s) { sendToNet(MSG_SEND_TEAMCHAT, s); }
-	public void sendFollowPlayer(String nick) { sendToNet(MSG_SEND_FOLLOW_PLAYER, nick); }
-	public void sendJoinRoom(String name) { sendToNet(MSG_SEND_JOIN_ROOM, name); }
-	public void sendCreateRoom(String name) { sendToNet(MSG_SEND_CREATE_ROOM, name); }
-	public void sendLeaveRoom(String message) { sendToNet(MSG_SEND_LEAVE_ROOM, message); }
-	public void sendKick(String player) { sendToNet(MSG_SEND_KICK, player); }
-	public void sendEngineMessage(byte[] engineMessage) { sendToNet(MSG_SEND_ENGINE_MESSAGE, engineMessage); }
-	public void sendRoundFinished(boolean withoutError) { sendToNet(MSG_SEND_ROUND_FINISHED, Boolean.valueOf(withoutError)); }
-	public void sendToggleReady() { sendToNet(MSG_SEND_TOGGLE_READY); }
-	public void sendStartGame() { sendToNet(MSG_SEND_START_GAME); }
-	
-	public void disconnect() { sendToNet(MSG_DISCONNECT, "User Quit"); }
-	
-	private static Netplay instance;
-	
-	/**
-	 * Retrieve the single app-wide instance of the netplay interface, creating it if it
-	 * does not exist yet.
-	 * 
-	 * @param applicationContext
-	 * @return
-	 */
-	public static Netplay getAppInstance(Context applicationContext) {
-		if(instance == null) {
-			// We will need some default values for rooms, best load them here
-			Scheme defaultScheme = null;
-			Weaponset defaultWeaponset = null;
-			try {
-				List<Scheme> schemes = Schemes.loadBuiltinSchemes(applicationContext);
-				for(Scheme scheme : schemes) {
-					if(scheme.name.equals(GameConfig.DEFAULT_SCHEME)) {
-						defaultScheme = scheme;
-					}
-				}
-				List<Weaponset> weaponsets = Weaponsets.loadBuiltinWeaponsets(applicationContext);
-				for(Weaponset weaponset : weaponsets) {
-					if(weaponset.name.equals(GameConfig.DEFAULT_WEAPONSET)) {
-						defaultWeaponset = weaponset;
-					}
-				}
-			} catch(IOException e) {
-				throw new RuntimeException(e);
-			}
-			
-			if(defaultScheme==null || defaultWeaponset==null) {
-				throw new RuntimeException("Unable to load default scheme or weaponset");
-			}
-			
-			instance = new Netplay(applicationContext, defaultScheme, defaultWeaponset);
-		}
-		return instance;
-	}
-
-	public State getState() {
-		return state;
-	}
-	
-	private void changeState(State newState) {
-		if(newState != state) {
-			state = newState;
-			broadcastManager.sendBroadcastSync(new Intent(ACTION_STATE_CHANGED));
-		}
-	}
-	
-	public boolean isChief() {
-		if(netRoomState != null) {
-			return netRoomState.getChiefStatus();
-		} else {
-			return false;
-		}
-	}
-	
-	public String getPlayerName() {
-		return playerName;
-	}
-	
-	boolean sendToNet(ToNetMsgType what) {
-		return sendToNet(what, 0, null);
-	}
-	
-	boolean sendToNet(ToNetMsgType what, Object obj) {
-		return sendToNet(what, 0, obj);
-	}
-	
-	boolean sendToNet(ToNetMsgType what, int arg1, Object obj) {
-		if(connection != null) {
-			Handler handler = connection.toNetHandler;
-			return handler.sendMessage(handler.obtainMessage(what.ordinal(), arg1, 0, obj));
-		} else {
-			return false;
-		}
-	}
-	
-	private MessageLog getCurrentLog() {
-		if(state == State.ROOM) {
-			return roomChatlog;
-		} else {
-			return lobbyChatlog;
-		}
-	}
-	
-	public static enum FromNetMsgType {
-		MSG_LOBBY_JOIN,
-		MSG_LOBBY_LEAVE,
-		MSG_ROOM_JOIN,
-		MSG_ROOM_LEAVE,
-		MSG_CLIENT_FLAGS,
-		MSG_CHAT,
-		MSG_MESSAGE,
-		MSG_ROOM_ADD,
-		MSG_ROOM_UPDATE,
-		MSG_ROOM_DELETE,
-		MSG_ROOMLIST,
-		MSG_CONNECTED,
-		MSG_DISCONNECTED,
-		MSG_PASSWORD_REQUEST,
-		MSG_ENTER_ROOM_FROM_LOBBY,
-		MSG_LEAVE_ROOM,
-		MSG_TEAM_ADDED,
-		MSG_TEAM_DELETED,
-		MSG_TEAM_ACCEPTED,
-		MSG_TEAM_COLOR_CHANGED,
-		MSG_HOG_COUNT_CHANGED,
-		MSG_ENGINE_MESSAGE,
-		MSG_RUN_GAME,
-		MSG_SCHEME_CHANGED,
-		MSG_MAP_CHANGED,
-		MSG_SCRIPT_CHANGED,
-		MSG_WEAPONSET_CHANGED;
-		
-		static final List<FromNetMsgType> values = Collections.unmodifiableList(Arrays.asList(FromNetMsgType.values()));
-	}
-	
-	/**
-	 * Processes messages from the networking system. Always runs on the main thread.
-	 */
-	@SuppressLint("HandlerLeak")
-	final class FromNetHandler extends Handler {
-		public FromNetHandler() {
-			super(Looper.getMainLooper());
-		}
-		
-		@SuppressWarnings("unchecked")
-		@Override
-		public void handleMessage(Message msg) {
-			switch(FromNetMsgType.values.get(msg.what)) {
-			case MSG_LOBBY_JOIN: {
-				String name = (String)msg.obj;
-				lobbyPlayerlist.put(name, new Player(name, false, false));
-				lobbyChatlog.appendPlayerJoin(name);
-				break;
-			}
-			case MSG_LOBBY_LEAVE: {
-				Pair<String, String> args = (Pair<String, String>)msg.obj;
-				lobbyPlayerlist.remove(args.first);
-				lobbyChatlog.appendPlayerLeave(args.first, args.second);
-				break;
-			}
-			case MSG_ROOM_JOIN: {
-				String name = (String)msg.obj;
-				Player p = lobbyPlayerlist.get(name);
-				if(p==null) {
-					Log.w("Netplay", "Unknown player joined room: "+name);
-					p = new Player(name, false, false);
-				}
-				roomPlayerlist.put(name, new PlayerInRoom(p, false, false));
-				roomChatlog.appendPlayerJoin(name);
-				break;
-			}
-			case MSG_ROOM_LEAVE: {
-				Pair<String, String> args = (Pair<String, String>)msg.obj;
-				roomPlayerlist.remove(args.first);
-				roomChatlog.appendPlayerLeave(args.first, args.second);
-				break;
-			}
-			case MSG_CLIENT_FLAGS: {
-				ClientFlagsUpdate upd = (ClientFlagsUpdate)msg.obj;
-				PlayerInRoom pir = roomPlayerlist.get(upd.nick);
-				if(pir != null) {
-					roomPlayerlist.put(upd.nick, upd.applyTo(pir));
-				}
-				Player p = lobbyPlayerlist.get(upd.nick);
-				if(p != null) {
-					lobbyPlayerlist.put(upd.nick, upd.applyTo(p));
-				} else {
-					Log.w("Netplay", "Received client flags for unknown player "+upd.nick);
-				}
-				if(playerName.equals(upd.nick) && upd.appliesTo(ClientFlagsUpdate.FLAG_CHIEF)) {
-					netRoomState.setChief(upd.newFlagState);
-				}
-				break;
-			}
-			case MSG_CHAT: {
-				Pair<String, String> args = (Pair<String, String>)msg.obj;
-				getCurrentLog().appendChat(args.first, args.second);
-				for(GameMessageListener listener : gameMessageListeners) {
-					listener.onChatMessage(args.first, args.second);
-				}
-				break;
-			}
-			case MSG_MESSAGE: {
-				getCurrentLog().appendMessage(msg.arg1, (String)msg.obj);
-				for(GameMessageListener listener : gameMessageListeners) {
-					listener.onMessage(1, (String)msg.obj);
-				}
-				break;
-			}
-			case MSG_ROOM_ADD: {
-				Room room = (Room)msg.obj;
-				roomList.addRoomWithNewId(room);
-				break;
-			}
-			case MSG_ROOM_UPDATE: {
-				Pair<String, Room> args = (Pair<String, Room>)msg.obj;
-				roomList.updateRoom(args.first, args.second);
-				break;
-			}
-			case MSG_ROOM_DELETE: {
-				roomList.remove((String)msg.obj);
-				break;
-			}
-			case MSG_ROOMLIST: {
-				Room[] rooms = (Room[])msg.obj;
-				roomList.updateList(rooms);
-				break;
-			}
-			case MSG_CONNECTED: {
-				playerName = (String)msg.obj;
-				changeState(State.LOBBY);
-				broadcastManager.sendBroadcast(new Intent(ACTION_CONNECTED));
-				break;
-			}
-			case MSG_DISCONNECTED: {
-				Pair<Boolean, String> args = (Pair<Boolean, String>)msg.obj;
-				for(GameMessageListener listener : gameMessageListeners) {
-					listener.onNetDisconnected();
-				}
-				changeState(State.NOT_CONNECTED);
-				connection = null;
-				Intent intent = new Intent(ACTION_DISCONNECTED);
-				intent.putExtra(EXTRA_HAS_ERROR, args.first);
-				intent.putExtra(EXTRA_MESSAGE, args.second);
-				broadcastManager.sendBroadcastSync(intent);
-				break;
-			}
-			case MSG_PASSWORD_REQUEST: {
-				Intent intent = new Intent(ACTION_PASSWORD_REQUESTED);
-				intent.putExtra(EXTRA_PLAYERNAME, (String)msg.obj);
-				broadcastManager.sendBroadcast(intent);
-				break;
-			}
-			case MSG_ENTER_ROOM_FROM_LOBBY: {
-				initRoomState((Boolean)msg.obj);
-				changeState(State.ROOM);
-				Intent intent = new Intent(ACTION_ENTERED_ROOM_FROM_LOBBY);
-				broadcastManager.sendBroadcastSync(intent);
-				break;
-			}
-			case MSG_LEAVE_ROOM: {
-				changeState(State.LOBBY);
-				Intent intent = new Intent(ACTION_LEFT_ROOM);
-				intent.putExtra(EXTRA_MESSAGE, (String)msg.obj);
-				intent.putExtra(EXTRA_REASON, msg.arg1);
-				broadcastManager.sendBroadcastSync(intent);
-				break;
-			}
-			case MSG_TEAM_ADDED: {
-				TeamInGame newTeam = (TeamInGame)msg.obj;
-				if(isChief()) {
-					int freeColor = TeamInGame.getUnusedOrRandomColorIndex(netRoomState.getTeams().values());
-					sendToNet(MSG_SEND_TEAM_HOG_COUNT, newTeam.ingameAttribs.hogCount, newTeam.team.name);
-					sendToNet(MSG_SEND_TEAM_COLOR_INDEX, freeColor, newTeam.team.name);
-					newTeam = newTeam.withAttribs(newTeam.ingameAttribs.withColorIndex(freeColor));
-				}
-				netRoomState.putTeam(newTeam);
-				break;
-			}
-			case MSG_TEAM_DELETED: {
-				netRoomState.removeTeam((String)msg.obj);
-				break;
-			}
-			case MSG_TEAM_ACCEPTED: {
-				TeamInGame requestedTeam = netRoomState.requestedTeams.remove(msg.obj);
-				if(requestedTeam!=null) {
-					netRoomState.putTeam(requestedTeam);
-					if(isChief()) {
-						// Not strictly necessary, but QtFrontend does it...
-						sendToNet(MSG_SEND_TEAM_HOG_COUNT, requestedTeam.ingameAttribs.hogCount, requestedTeam.team.name);
-					}
-				} else {
-					Log.e("Netplay", "Got accepted message for team that was never requested.");
-				}
-				break;
-			}
-			case MSG_TEAM_COLOR_CHANGED: {
-				TeamInGame oldEntry = netRoomState.getTeams().get((String)msg.obj);
-				if(oldEntry != null) {
-					/*
-					 * If we are chief, we ignore colors from the outside. They only come from the server
-					 * when someone adds a team then, and we override that choice anyway.
-					 * Worse, that color message arrives *after* we have overridden the color, so it would
-					 * re-override it right back.
-					 */
-					if(!isChief()) {
-						TeamIngameAttributes newAttribs = oldEntry.ingameAttribs.withColorIndex(msg.arg1);
-						netRoomState.putTeam(oldEntry.withAttribs(newAttribs));
-					}
-				} else {
-					Log.e("Netplay", "Color update for unknown team "+msg.obj);
-				}
-				break;
-			}
-			case MSG_HOG_COUNT_CHANGED: {
-				TeamInGame oldEntry = netRoomState.getTeams().get((String)msg.obj);
-				if(oldEntry != null) {
-					TeamIngameAttributes newAttribs = oldEntry.ingameAttribs.withHogCount(msg.arg1);
-					netRoomState.putTeam(oldEntry.withAttribs(newAttribs));
-				} else {
-					Log.e("Netplay", "Hog count update for unknown team "+msg.obj);
-				}
-				break;
-			}
-			case MSG_ENGINE_MESSAGE: {
-				byte[] em = (byte[])msg.obj;
-				for(GameMessageListener listener : gameMessageListeners) {
-					listener.onEngineMessage(em);
-				}
-				break;
-			}
-			case MSG_RUN_GAME: {
-				GameConfig config = (GameConfig)msg.obj;
-				for(RunGameListener listener : runGameListeners) {
-					listener.runGame(config);
-				}
-				break;
-			}
-			case MSG_MAP_CHANGED: {
-				netRoomState.setMapRecipe((MapRecipe)msg.obj);
-				break;
-			}
-			case MSG_SCHEME_CHANGED: {
-				netRoomState.setScheme((Scheme)msg.obj);
-				break;
-			}
-			case MSG_SCRIPT_CHANGED: {
-				netRoomState.setGameStyle((String)msg.obj);
-				break;
-			}
-			case MSG_WEAPONSET_CHANGED: {
-				netRoomState.setWeaponset((Weaponset)msg.obj);
-				break;
-			}
-			default: {
-				Log.e("FromNetHandler", "Unknown message type: "+msg.what);
-				break;
-			}
-			}
-		}
-	}
-}
+/*
+ * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.hedgewars.hedgeroid.netplay;
+
+import static org.hedgewars.hedgeroid.netplay.ThreadedNetConnection.ToNetMsgType.*;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.hedgewars.hedgeroid.RoomStateManager;
+import org.hedgewars.hedgeroid.Datastructures.GameConfig;
+import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
+import org.hedgewars.hedgeroid.Datastructures.Player;
+import org.hedgewars.hedgeroid.Datastructures.PlayerInRoom;
+import org.hedgewars.hedgeroid.Datastructures.Room;
+import org.hedgewars.hedgeroid.Datastructures.Scheme;
+import org.hedgewars.hedgeroid.Datastructures.Schemes;
+import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
+import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
+import org.hedgewars.hedgeroid.Datastructures.Weaponset;
+import org.hedgewars.hedgeroid.Datastructures.Weaponsets;
+import org.hedgewars.hedgeroid.netplay.ThreadedNetConnection.ToNetMsgType;
+import org.hedgewars.hedgeroid.util.ObservableTreeMap;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.support.v4.content.LocalBroadcastManager;
+import android.util.Log;
+import android.util.Pair;
+
+
+/**
+ * This class manages the application's networking state.
+ */
+public class Netplay {
+    public static enum State { NOT_CONNECTED, CONNECTING, LOBBY, ROOM }
+
+    // Extras in broadcasts
+    public static final String EXTRA_PLAYERNAME = "playerName";
+    public static final String EXTRA_MESSAGE = "message";
+    public static final String EXTRA_HAS_ERROR = "hasError";
+    public static final String EXTRA_REASON = "reason";
+
+    private static final String ACTIONPREFIX = "org.hedgewars.hedgeroid.netconn.";
+    public static final String ACTION_DISCONNECTED = ACTIONPREFIX+"DISCONNECTED";
+    public static final String ACTION_CONNECTED = ACTIONPREFIX+"CONNECTED";
+    public static final String ACTION_PASSWORD_REQUESTED = ACTIONPREFIX+"PASSWORD_REQUESTED";
+    public static final String ACTION_ENTERED_ROOM_FROM_LOBBY = ACTIONPREFIX+"ENTERED_ROOM";
+    public static final String ACTION_LEFT_ROOM = ACTIONPREFIX+"LEFT_ROOM";
+    public static final String ACTION_STATE_CHANGED = ACTIONPREFIX+"STATE_CHANGED";
+
+    public static final String DEFAULT_SERVER = "netserver.hedgewars.org";
+    public static final int DEFAULT_PORT = 46631;
+
+    private final Context appContext;
+    private final LocalBroadcastManager broadcastManager;
+    private final FromNetHandler fromNetHandler = new FromNetHandler();
+    public final Scheme defaultScheme;
+    public final Weaponset defaultWeaponset;
+
+    private State state = State.NOT_CONNECTED;
+    private String playerName;
+
+    // null or stale if not in room state
+    private final NetRoomState netRoomState = new NetRoomState(this);
+
+    // null if there is no running connection (==state is NOT_CONNECTED)
+    private ThreadedNetConnection connection;
+
+    public final ObservableTreeMap<String, Player> lobbyPlayerlist = new ObservableTreeMap<String, Player>();
+    public final ObservableTreeMap<String, PlayerInRoom> roomPlayerlist = new ObservableTreeMap<String, PlayerInRoom>();
+    public final Roomlist roomList = new Roomlist();
+    public final MessageLog lobbyChatlog;
+    public final MessageLog roomChatlog;
+
+    private final List<GameMessageListener> gameMessageListeners = new LinkedList<GameMessageListener>();
+    private final List<RunGameListener> runGameListeners = new LinkedList<RunGameListener>();
+
+    public Netplay(Context appContext, Scheme defaultScheme, Weaponset defaultWeaponset) {
+        this.appContext = appContext;
+        broadcastManager = LocalBroadcastManager.getInstance(appContext);
+        lobbyChatlog = new MessageLog(appContext);
+        roomChatlog = new MessageLog(appContext);
+        this.defaultScheme = defaultScheme;
+        this.defaultWeaponset = defaultWeaponset;
+    }
+
+    public RoomStateManager getRoomStateManager() {
+        return netRoomState;
+    }
+
+    private void clearLobbyState() {
+        lobbyPlayerlist.clear();
+        roomList.clear();
+        lobbyChatlog.clear();
+    }
+
+    private void initRoomState(boolean chief) {
+        roomChatlog.clear();
+        roomPlayerlist.clear();
+        netRoomState.initRoomState(chief);
+    }
+
+    public void registerGameMessageListener(GameMessageListener listener) {
+        gameMessageListeners.add(listener);
+    }
+
+    public void unregisterGameMessageListener(GameMessageListener listener) {
+        gameMessageListeners.remove(listener);
+    }
+
+    public void registerRunGameListener(RunGameListener listener) {
+        runGameListeners.add(listener);
+    }
+
+    public void unregisterRunGameListener(RunGameListener listener) {
+        runGameListeners.remove(listener);
+    }
+
+    public void connectToDefaultServer(String playerName) {
+        connect(playerName, DEFAULT_SERVER, DEFAULT_PORT);
+    }
+
+    /**
+     * Establish a new connection. Only call if the current state is NOT_CONNECTED.
+     *
+     * The state will switch to CONNECTING immediately. After that, it can asynchronously change to any other state.
+     * State changes are indicated by broadcasts. In particular, if an error occurs while trying to connect, the state
+     * will change back to NOT_CONNECTED and an ACTION_DISCONNECTED broadcast is sent.
+     */
+    public void connect(String name, String host, int port) {
+        playerName = name;
+        if(state != State.NOT_CONNECTED) {
+            throw new IllegalStateException("Attempt to start a new connection while the old one was still running.");
+        }
+
+        clearLobbyState();
+        changeState(State.CONNECTING);
+        connection = ThreadedNetConnection.startConnection(appContext, fromNetHandler, name, host, port);
+        connection.setFastTickRate(true);
+    }
+
+    public void sendNick(String nick) {
+        playerName = nick;
+        sendToNet(MSG_SEND_NICK, nick);
+    }
+    public void sendPassword(String password) { sendToNet(MSG_SEND_PASSWORD, password); }
+    public void sendQuit(String message) { sendToNet(MSG_SEND_QUIT, message); }
+    public void sendRoomlistRequest() { sendToNet(MSG_SEND_ROOMLIST_REQUEST); }
+    public void sendPlayerInfoQuery(String name) { sendToNet(MSG_SEND_PLAYER_INFO_REQUEST, name); }
+    public void sendChat(String s) { sendToNet(MSG_SEND_CHAT, s); }
+    public void sendTeamChat(String s) { sendToNet(MSG_SEND_TEAMCHAT, s); }
+    public void sendFollowPlayer(String nick) { sendToNet(MSG_SEND_FOLLOW_PLAYER, nick); }
+    public void sendJoinRoom(String name) { sendToNet(MSG_SEND_JOIN_ROOM, name); }
+    public void sendCreateRoom(String name) { sendToNet(MSG_SEND_CREATE_ROOM, name); }
+    public void sendLeaveRoom(String message) { sendToNet(MSG_SEND_LEAVE_ROOM, message); }
+    public void sendKick(String player) { sendToNet(MSG_SEND_KICK, player); }
+    public void sendEngineMessage(byte[] engineMessage) { sendToNet(MSG_SEND_ENGINE_MESSAGE, engineMessage); }
+    public void sendRoundFinished(boolean withoutError) { sendToNet(MSG_SEND_ROUND_FINISHED, Boolean.valueOf(withoutError)); }
+    public void sendToggleReady() { sendToNet(MSG_SEND_TOGGLE_READY); }
+    public void sendStartGame() { sendToNet(MSG_SEND_START_GAME); }
+
+    public void disconnect() { sendToNet(MSG_DISCONNECT, "User Quit"); }
+
+    private static Netplay instance;
+
+    /**
+     * Retrieve the single app-wide instance of the netplay interface, creating it if it
+     * does not exist yet.
+     *
+     * @param applicationContext
+     * @return
+     */
+    public static Netplay getAppInstance(Context applicationContext) {
+        if(instance == null) {
+            // We will need some default values for rooms, best load them here
+            Scheme defaultScheme = null;
+            Weaponset defaultWeaponset = null;
+            try {
+                List<Scheme> schemes = Schemes.loadBuiltinSchemes(applicationContext);
+                for(Scheme scheme : schemes) {
+                    if(scheme.name.equals(GameConfig.DEFAULT_SCHEME)) {
+                        defaultScheme = scheme;
+                    }
+                }
+                List<Weaponset> weaponsets = Weaponsets.loadBuiltinWeaponsets(applicationContext);
+                for(Weaponset weaponset : weaponsets) {
+                    if(weaponset.name.equals(GameConfig.DEFAULT_WEAPONSET)) {
+                        defaultWeaponset = weaponset;
+                    }
+                }
+            } catch(IOException e) {
+                throw new RuntimeException(e);
+            }
+
+            if(defaultScheme==null || defaultWeaponset==null) {
+                throw new RuntimeException("Unable to load default scheme or weaponset");
+            }
+
+            instance = new Netplay(applicationContext, defaultScheme, defaultWeaponset);
+        }
+        return instance;
+    }
+
+    public State getState() {
+        return state;
+    }
+
+    private void changeState(State newState) {
+        if(newState != state) {
+            state = newState;
+            broadcastManager.sendBroadcastSync(new Intent(ACTION_STATE_CHANGED));
+        }
+    }
+
+    public boolean isChief() {
+        if(netRoomState != null) {
+            return netRoomState.getChiefStatus();
+        } else {
+            return false;
+        }
+    }
+
+    public String getPlayerName() {
+        return playerName;
+    }
+
+    boolean sendToNet(ToNetMsgType what) {
+        return sendToNet(what, 0, null);
+    }
+
+    boolean sendToNet(ToNetMsgType what, Object obj) {
+        return sendToNet(what, 0, obj);
+    }
+
+    boolean sendToNet(ToNetMsgType what, int arg1, Object obj) {
+        if(connection != null) {
+            Handler handler = connection.toNetHandler;
+            return handler.sendMessage(handler.obtainMessage(what.ordinal(), arg1, 0, obj));
+        } else {
+            return false;
+        }
+    }
+
+    private MessageLog getCurrentLog() {
+        if(state == State.ROOM) {
+            return roomChatlog;
+        } else {
+            return lobbyChatlog;
+        }
+    }
+
+    public static enum FromNetMsgType {
+        MSG_LOBBY_JOIN,
+        MSG_LOBBY_LEAVE,
+        MSG_ROOM_JOIN,
+        MSG_ROOM_LEAVE,
+        MSG_CLIENT_FLAGS,
+        MSG_CHAT,
+        MSG_MESSAGE,
+        MSG_ROOM_ADD,
+        MSG_ROOM_UPDATE,
+        MSG_ROOM_DELETE,
+        MSG_ROOMLIST,
+        MSG_CONNECTED,
+        MSG_DISCONNECTED,
+        MSG_PASSWORD_REQUEST,
+        MSG_ENTER_ROOM_FROM_LOBBY,
+        MSG_LEAVE_ROOM,
+        MSG_TEAM_ADDED,
+        MSG_TEAM_DELETED,
+        MSG_TEAM_ACCEPTED,
+        MSG_TEAM_COLOR_CHANGED,
+        MSG_HOG_COUNT_CHANGED,
+        MSG_ENGINE_MESSAGE,
+        MSG_RUN_GAME,
+        MSG_SCHEME_CHANGED,
+        MSG_MAP_CHANGED,
+        MSG_SCRIPT_CHANGED,
+        MSG_WEAPONSET_CHANGED;
+
+        static final List<FromNetMsgType> values = Collections.unmodifiableList(Arrays.asList(FromNetMsgType.values()));
+    }
+
+    /**
+     * Processes messages from the networking system. Always runs on the main thread.
+     */
+    @SuppressLint("HandlerLeak")
+    final class FromNetHandler extends Handler {
+        public FromNetHandler() {
+            super(Looper.getMainLooper());
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public void handleMessage(Message msg) {
+            switch(FromNetMsgType.values.get(msg.what)) {
+            case MSG_LOBBY_JOIN: {
+                String name = (String)msg.obj;
+                lobbyPlayerlist.put(name, new Player(name, false, false));
+                lobbyChatlog.appendPlayerJoin(name);
+                break;
+            }
+            case MSG_LOBBY_LEAVE: {
+                Pair<String, String> args = (Pair<String, String>)msg.obj;
+                lobbyPlayerlist.remove(args.first);
+                lobbyChatlog.appendPlayerLeave(args.first, args.second);
+                break;
+            }
+            case MSG_ROOM_JOIN: {
+                String name = (String)msg.obj;
+                Player p = lobbyPlayerlist.get(name);
+                if(p==null) {
+                    Log.w("Netplay", "Unknown player joined room: "+name);
+                    p = new Player(name, false, false);
+                }
+                roomPlayerlist.put(name, new PlayerInRoom(p, false, false));
+                roomChatlog.appendPlayerJoin(name);
+                break;
+            }
+            case MSG_ROOM_LEAVE: {
+                Pair<String, String> args = (Pair<String, String>)msg.obj;
+                roomPlayerlist.remove(args.first);
+                roomChatlog.appendPlayerLeave(args.first, args.second);
+                break;
+            }
+            case MSG_CLIENT_FLAGS: {
+                ClientFlagsUpdate upd = (ClientFlagsUpdate)msg.obj;
+                PlayerInRoom pir = roomPlayerlist.get(upd.nick);
+                if(pir != null) {
+                    roomPlayerlist.put(upd.nick, upd.applyTo(pir));
+                }
+                Player p = lobbyPlayerlist.get(upd.nick);
+                if(p != null) {
+                    lobbyPlayerlist.put(upd.nick, upd.applyTo(p));
+                } else {
+                    Log.w("Netplay", "Received client flags for unknown player "+upd.nick);
+                }
+                if(playerName.equals(upd.nick) && upd.appliesTo(ClientFlagsUpdate.FLAG_CHIEF)) {
+                    netRoomState.setChief(upd.newFlagState);
+                }
+                break;
+            }
+            case MSG_CHAT: {
+                Pair<String, String> args = (Pair<String, String>)msg.obj;
+                getCurrentLog().appendChat(args.first, args.second);
+                for(GameMessageListener listener : gameMessageListeners) {
+                    listener.onChatMessage(args.first, args.second);
+                }
+                break;
+            }
+            case MSG_MESSAGE: {
+                getCurrentLog().appendMessage(msg.arg1, (String)msg.obj);
+                for(GameMessageListener listener : gameMessageListeners) {
+                    listener.onMessage(1, (String)msg.obj);
+                }
+                break;
+            }
+            case MSG_ROOM_ADD: {
+                Room room = (Room)msg.obj;
+                roomList.addRoomWithNewId(room);
+                break;
+            }
+            case MSG_ROOM_UPDATE: {
+                Pair<String, Room> args = (Pair<String, Room>)msg.obj;
+                roomList.updateRoom(args.first, args.second);
+                break;
+            }
+            case MSG_ROOM_DELETE: {
+                roomList.remove((String)msg.obj);
+                break;
+            }
+            case MSG_ROOMLIST: {
+                Room[] rooms = (Room[])msg.obj;
+                roomList.updateList(rooms);
+                break;
+            }
+            case MSG_CONNECTED: {
+                playerName = (String)msg.obj;
+                changeState(State.LOBBY);
+                broadcastManager.sendBroadcast(new Intent(ACTION_CONNECTED));
+                break;
+            }
+            case MSG_DISCONNECTED: {
+                Pair<Boolean, String> args = (Pair<Boolean, String>)msg.obj;
+                for(GameMessageListener listener : gameMessageListeners) {
+                    listener.onNetDisconnected();
+                }
+                changeState(State.NOT_CONNECTED);
+                connection = null;
+                Intent intent = new Intent(ACTION_DISCONNECTED);
+                intent.putExtra(EXTRA_HAS_ERROR, args.first);
+                intent.putExtra(EXTRA_MESSAGE, args.second);
+                broadcastManager.sendBroadcastSync(intent);
+                break;
+            }
+            case MSG_PASSWORD_REQUEST: {
+                Intent intent = new Intent(ACTION_PASSWORD_REQUESTED);
+                intent.putExtra(EXTRA_PLAYERNAME, (String)msg.obj);
+                broadcastManager.sendBroadcast(intent);
+                break;
+            }
+            case MSG_ENTER_ROOM_FROM_LOBBY: {
+                initRoomState((Boolean)msg.obj);
+                changeState(State.ROOM);
+                Intent intent = new Intent(ACTION_ENTERED_ROOM_FROM_LOBBY);
+                broadcastManager.sendBroadcastSync(intent);
+                break;
+            }
+            case MSG_LEAVE_ROOM: {
+                changeState(State.LOBBY);
+                Intent intent = new Intent(ACTION_LEFT_ROOM);
+                intent.putExtra(EXTRA_MESSAGE, (String)msg.obj);
+                intent.putExtra(EXTRA_REASON, msg.arg1);
+                broadcastManager.sendBroadcastSync(intent);
+                break;
+            }
+            case MSG_TEAM_ADDED: {
+                TeamInGame newTeam = (TeamInGame)msg.obj;
+                if(isChief()) {
+                    int freeColor = TeamInGame.getUnusedOrRandomColorIndex(netRoomState.getTeams().values());
+                    sendToNet(MSG_SEND_TEAM_HOG_COUNT, newTeam.ingameAttribs.hogCount, newTeam.team.name);
+                    sendToNet(MSG_SEND_TEAM_COLOR_INDEX, freeColor, newTeam.team.name);
+                    newTeam = newTeam.withAttribs(newTeam.ingameAttribs.withColorIndex(freeColor));
+                }
+                netRoomState.putTeam(newTeam);
+                break;
+            }
+            case MSG_TEAM_DELETED: {
+                netRoomState.removeTeam((String)msg.obj);
+                break;
+            }
+            case MSG_TEAM_ACCEPTED: {
+                TeamInGame requestedTeam = netRoomState.requestedTeams.remove(msg.obj);
+                if(requestedTeam!=null) {
+                    netRoomState.putTeam(requestedTeam);
+                    if(isChief()) {
+                        // Not strictly necessary, but QtFrontend does it...
+                        sendToNet(MSG_SEND_TEAM_HOG_COUNT, requestedTeam.ingameAttribs.hogCount, requestedTeam.team.name);
+                    }
+                } else {
+                    Log.e("Netplay", "Got accepted message for team that was never requested.");
+                }
+                break;
+            }
+            case MSG_TEAM_COLOR_CHANGED: {
+                TeamInGame oldEntry = netRoomState.getTeams().get((String)msg.obj);
+                if(oldEntry != null) {
+                    /*
+                     * If we are chief, we ignore colors from the outside. They only come from the server
+                     * when someone adds a team then, and we override that choice anyway.
+                     * Worse, that color message arrives *after* we have overridden the color, so it would
+                     * re-override it right back.
+                     */
+                    if(!isChief()) {
+                        TeamIngameAttributes newAttribs = oldEntry.ingameAttribs.withColorIndex(msg.arg1);
+                        netRoomState.putTeam(oldEntry.withAttribs(newAttribs));
+                    }
+                } else {
+                    Log.e("Netplay", "Color update for unknown team "+msg.obj);
+                }
+                break;
+            }
+            case MSG_HOG_COUNT_CHANGED: {
+                TeamInGame oldEntry = netRoomState.getTeams().get((String)msg.obj);
+                if(oldEntry != null) {
+                    TeamIngameAttributes newAttribs = oldEntry.ingameAttribs.withHogCount(msg.arg1);
+                    netRoomState.putTeam(oldEntry.withAttribs(newAttribs));
+                } else {
+                    Log.e("Netplay", "Hog count update for unknown team "+msg.obj);
+                }
+                break;
+            }
+            case MSG_ENGINE_MESSAGE: {
+                byte[] em = (byte[])msg.obj;
+                for(GameMessageListener listener : gameMessageListeners) {
+                    listener.onEngineMessage(em);
+                }
+                break;
+            }
+            case MSG_RUN_GAME: {
+                GameConfig config = (GameConfig)msg.obj;
+                for(RunGameListener listener : runGameListeners) {
+                    listener.runGame(config);
+                }
+                break;
+            }
+            case MSG_MAP_CHANGED: {
+                netRoomState.setMapRecipe((MapRecipe)msg.obj);
+                break;
+            }
+            case MSG_SCHEME_CHANGED: {
+                netRoomState.setScheme((Scheme)msg.obj);
+                break;
+            }
+            case MSG_SCRIPT_CHANGED: {
+                netRoomState.setGameStyle((String)msg.obj);
+                break;
+            }
+            case MSG_WEAPONSET_CHANGED: {
+                netRoomState.setWeaponset((Weaponset)msg.obj);
+                break;
+            }
+            default: {
+                Log.e("FromNetHandler", "Unknown message type: "+msg.what);
+                break;
+            }
+            }
+        }
+    }
+}
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Roomlist.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Roomlist.java	Tue Jan 21 22:53:15 2014 +0100
@@ -27,32 +27,32 @@
 import org.hedgewars.hedgeroid.util.ObservableTreeMap;
 
 public class Roomlist extends ObservableTreeMap<String, RoomWithId> {
-	private long nextId = 1;
-	
-	public void updateList(Room[] newRooms) {
-		Map<String, RoomWithId> newMap = new TreeMap<String, RoomWithId>();
-		for(Room room : newRooms) {
-			RoomWithId oldEntry = get(room.name);
-			if(oldEntry == null) {
-				newMap.put(room.name, new RoomWithId(room, nextId++));
-			} else {
-				newMap.put(room.name, new RoomWithId(room, oldEntry.id));
-			}
-		}
-		replaceContent(newMap);
-	}
-	
-	public void addRoomWithNewId(Room room) {
-		put(room.name, new RoomWithId(room, nextId++));
-	}
-	
-	public void updateRoom(String name, Room room) {
-		RoomWithId oldEntry = get(name);
-		if(oldEntry == null) {
-			addRoomWithNewId(room);
-		} else {
-			remove(name);
-			put(room.name, new RoomWithId(room, oldEntry.id));
-		}
-	}
+    private long nextId = 1;
+
+    public void updateList(Room[] newRooms) {
+        Map<String, RoomWithId> newMap = new TreeMap<String, RoomWithId>();
+        for(Room room : newRooms) {
+            RoomWithId oldEntry = get(room.name);
+            if(oldEntry == null) {
+                newMap.put(room.name, new RoomWithId(room, nextId++));
+            } else {
+                newMap.put(room.name, new RoomWithId(room, oldEntry.id));
+            }
+        }
+        replaceContent(newMap);
+    }
+
+    public void addRoomWithNewId(Room room) {
+        put(room.name, new RoomWithId(room, nextId++));
+    }
+
+    public void updateRoom(String name, Room room) {
+        RoomWithId oldEntry = get(name);
+        if(oldEntry == null) {
+            addRoomWithNewId(room);
+        } else {
+            remove(name);
+            put(room.name, new RoomWithId(room, oldEntry.id));
+        }
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RunGameListener.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RunGameListener.java	Tue Jan 21 22:53:15 2014 +0100
@@ -22,5 +22,5 @@
 import org.hedgewars.hedgeroid.Datastructures.GameConfig;
 
 public interface RunGameListener {
-	void runGame(GameConfig config);
+    void runGame(GameConfig config);
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ThreadedNetConnection.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/ThreadedNetConnection.java	Tue Jan 21 22:53:15 2014 +0100
@@ -78,501 +78,501 @@
 
 /**
  * This class handles the actual communication with the networking library, running on a separate thread.
- * 
+ *
  * In order to process net messages, this class regularly runs a tick() function on the frontlib. This
  * usually happens several times per second, but it can be slowed down a lot if no fast reaction to
  * events is required (e.g. to conserve battery if the application is in the background).
  */
 class ThreadedNetConnection {
-	private static final long TICK_INTERVAL_FAST = 100;
-	private static final long TICK_INTERVAL_SLOW = 5000;
-	private static final Frontlib FLIB = Flib.INSTANCE;
-	
-	public final ToNetHandler toNetHandler;
-	
-	private final Context appContext;
-	private final FromNetHandler fromNetHandler;
-	private final TickHandler tickHandler;
+    private static final long TICK_INTERVAL_FAST = 100;
+    private static final long TICK_INTERVAL_SLOW = 5000;
+    private static final Frontlib FLIB = Flib.INSTANCE;
+
+    public final ToNetHandler toNetHandler;
+
+    private final Context appContext;
+    private final FromNetHandler fromNetHandler;
+    private final TickHandler tickHandler;
+
+    /**
+     * conn can only be null while connecting (the first thing in the thread), and directly after disconnecting,
+     * in the same message (the looper is shut down on disconnect, so there will be no messages after that).
+     */
+    private NetconnPtr conn;
+    private String playerName;
+
+    private ThreadedNetConnection(Context appContext, FromNetHandler fromNetHandler) {
+        this.appContext = appContext;
+        this.fromNetHandler = fromNetHandler;
+
+        HandlerThread thread = new HandlerThread("NetThread");
+        thread.start();
+        toNetHandler = new ToNetHandler(thread.getLooper());
+        tickHandler = new TickHandler(thread.getLooper(), TICK_INTERVAL_FAST, tickCb);
+    }
+
+    private void connect(final String name, final String host, final int port) {
+        toNetHandler.post(new Runnable() {
+            public void run() {
+                playerName = name == null ? "Player" : name;
+                File dataPath;
+                try {
+                    dataPath = FileUtils.getDataPathFile(appContext);
+                } catch (FileNotFoundException e) {
+                    shutdown(true, appContext.getString(R.string.sdcard_not_mounted));
+                    return;
+                }
+                conn = FLIB.flib_netconn_create(playerName, dataPath.getAbsolutePath()+"/", host, port);
+                if(conn == null) {
+                    shutdown(true, appContext.getString(R.string.error_connection_failed));
+                    return;
+                }
+
+                FLIB.flib_netconn_onSchemeChanged(conn, cfgSchemeCb, null);
+                FLIB.flib_netconn_onClientFlags(conn, clientFlagsCb, null);
+                FLIB.flib_netconn_onChat(conn, chatCb, null);
+                FLIB.flib_netconn_onConnected(conn, connectedCb, null);
+                FLIB.flib_netconn_onDisconnected(conn, disconnectCb, null);
+                FLIB.flib_netconn_onEngineMessage(conn, engineMessageCb, null);
+                FLIB.flib_netconn_onEnterRoom(conn, enterRoomCb, null);
+                FLIB.flib_netconn_onHogCountChanged(conn, hogCountChangedCb, null);
+                FLIB.flib_netconn_onLeaveRoom(conn, leaveRoomCb, null);
+                FLIB.flib_netconn_onLobbyJoin(conn, lobbyJoinCb, null);
+                FLIB.flib_netconn_onLobbyLeave(conn, lobbyLeaveCb, null);
+                FLIB.flib_netconn_onMapChanged(conn, mapChangedCb, null);
+                FLIB.flib_netconn_onMessage(conn, messageCb, null);
+                FLIB.flib_netconn_onPasswordRequest(conn, passwordRequestCb, null);
+                FLIB.flib_netconn_onRoomAdd(conn, roomAddCb, null);
+                FLIB.flib_netconn_onRoomDelete(conn, roomDeleteCb, null);
+                FLIB.flib_netconn_onRoomJoin(conn, roomJoinCb, null);
+                FLIB.flib_netconn_onRoomLeave(conn, roomLeaveCb, null);
+                FLIB.flib_netconn_onRoomlist(conn, roomlistCb, null);
+                FLIB.flib_netconn_onRoomUpdate(conn, roomUpdateCb, null);
+                FLIB.flib_netconn_onRunGame(conn, runGameCb, null);
+                FLIB.flib_netconn_onScriptChanged(conn, scriptChangedCb, null);
+                // FLIB.flib_netconn_onServerVar(conn, serverVarCb, null);
+                FLIB.flib_netconn_onTeamAccepted(conn, teamAcceptedCb, null);
+                FLIB.flib_netconn_onTeamAdd(conn, teamAddedCb, null);
+                FLIB.flib_netconn_onTeamColorChanged(conn, teamColorChangedCb, null);
+                FLIB.flib_netconn_onTeamDelete(conn, teamDeletedCb, null);
+                FLIB.flib_netconn_onWeaponsetChanged(conn, weaponsetChangedCb, null);
+
+                tickHandler.start();
+            }
+        });
+    }
+
+    public static ThreadedNetConnection startConnection(Context appContext, FromNetHandler fromNetHandler, String playerName, String host, int port) {
+        ThreadedNetConnection result = new ThreadedNetConnection(appContext, fromNetHandler);
+        result.connect(playerName, host, port);
+        return result;
+    }
+
+    public void setFastTickRate(boolean fastTickRate) {
+        tickHandler.setInterval(fastTickRate ? TICK_INTERVAL_FAST : TICK_INTERVAL_SLOW);
+    }
+
+    private final Runnable tickCb = new Runnable() {
+        public void run() {
+            FLIB.flib_netconn_tick(conn);
+        }
+    };
+
+    private final SchemeCallback cfgSchemeCb = new SchemeCallback() {
+        public void callback(Pointer context, SchemePtr schemePtr) {
+            sendFromNet(MSG_SCHEME_CHANGED, schemePtr.deref());
+        }
+    };
+
+    private final MapIntCallback mapChangedCb = new MapIntCallback() {
+        public void callback(Pointer context, MapRecipePtr mapPtr, int updateType) {
+            sendFromNet(MSG_MAP_CHANGED, updateType, mapPtr.deref());
+        }
+    };
+
+    private final StrCallback scriptChangedCb = new StrCallback() {
+        public void callback(Pointer context, String script) {
+            sendFromNet(MSG_SCRIPT_CHANGED, script);
+        }
+    };
+
+    private final WeaponsetCallback weaponsetChangedCb = new WeaponsetCallback() {
+        public void callback(Pointer context, WeaponsetPtr weaponsetPtr) {
+            sendFromNet(MSG_WEAPONSET_CHANGED, weaponsetPtr.deref());
+        }
+    };
 
-	/**
-	 * conn can only be null while connecting (the first thing in the thread), and directly after disconnecting,
-	 * in the same message (the looper is shut down on disconnect, so there will be no messages after that).
-	 */
-	private NetconnPtr conn;
-	private String playerName;
-	
-	private ThreadedNetConnection(Context appContext, FromNetHandler fromNetHandler) {
-		this.appContext = appContext;
-		this.fromNetHandler = fromNetHandler;
-		
-		HandlerThread thread = new HandlerThread("NetThread");
-		thread.start();
-		toNetHandler = new ToNetHandler(thread.getLooper());
-		tickHandler = new TickHandler(thread.getLooper(), TICK_INTERVAL_FAST, tickCb);
-	}
-	
-	private void connect(final String name, final String host, final int port) {
-		toNetHandler.post(new Runnable() {
-			public void run() {
-				playerName = name == null ? "Player" : name;
-				File dataPath;
-				try {
-					dataPath = FileUtils.getDataPathFile(appContext);
-				} catch (FileNotFoundException e) {
-					shutdown(true, appContext.getString(R.string.sdcard_not_mounted));
-					return;
-				}
-				conn = FLIB.flib_netconn_create(playerName, dataPath.getAbsolutePath()+"/", host, port);
-				if(conn == null) {
-					shutdown(true, appContext.getString(R.string.error_connection_failed));
-					return;
-				}
+    private final StrCallback lobbyJoinCb = new StrCallback() {
+        public void callback(Pointer context, String name) {
+            sendFromNet(MSG_LOBBY_JOIN, name);
+        }
+    };
+
+    private final StrStrCallback lobbyLeaveCb = new StrStrCallback() {
+        public void callback(Pointer context, String name, String msg) {
+            sendFromNet(MSG_LOBBY_LEAVE, Pair.create(name, msg));
+        }
+    };
+
+    private final StrCallback roomJoinCb = new StrCallback() {
+        public void callback(Pointer context, String name) {
+            sendFromNet(MSG_ROOM_JOIN, name);
+        }
+    };
+
+    private final StrStrCallback roomLeaveCb = new StrStrCallback() {
+        public void callback(Pointer context, String name, String message) {
+            sendFromNet(MSG_ROOM_LEAVE, Pair.create(name, message));
+        }
+    };
+
+    private final StrStrBoolCallback clientFlagsCb = new StrStrBoolCallback() {
+        public void callback(Pointer context, String nick, String flags, boolean newFlagsState) {
+            sendFromNet(MSG_CLIENT_FLAGS, new ClientFlagsUpdate(nick, flags, newFlagsState));
+        }
+    };
+
+    private final StrStrCallback chatCb = new StrStrCallback() {
+        public void callback(Pointer context, String name, String msg) {
+            sendFromNet(MSG_CHAT, Pair.create(name, msg));
+        }
+    };
+
+    private final IntStrCallback messageCb = new IntStrCallback() {
+        public void callback(Pointer context, int type, String msg) {
+            sendFromNet(MSG_MESSAGE, type, msg);
+        }
+    };
+
+    private final RoomCallback roomAddCb = new RoomCallback() {
+        public void callback(Pointer context, RoomPtr roomPtr) {
+            sendFromNet(MSG_ROOM_ADD, roomPtr.deref());
+        }
+    };
+
+    private final StrRoomCallback roomUpdateCb = new StrRoomCallback() {
+        public void callback(Pointer context, String name, RoomPtr roomPtr) {
+            sendFromNet(MSG_ROOM_UPDATE, Pair.create(name, roomPtr.deref()));
+        }
+    };
+
+    private final StrCallback roomDeleteCb = new StrCallback() {
+        public void callback(Pointer context, final String name) {
+            sendFromNet(MSG_ROOM_DELETE, name);
+        }
+    };
+
+    private final RoomListCallback roomlistCb = new RoomListCallback() {
+        public void callback(Pointer context, RoomArrayPtr arg1, int count) {
+            sendFromNet(MSG_ROOMLIST, arg1.getRooms(count));
+        }
+    };
+
+    private final VoidCallback connectedCb = new VoidCallback() {
+        public void callback(Pointer context) {
+            FLIB.flib_netconn_send_request_roomlist(conn);
+            playerName = FLIB.flib_netconn_get_playername(conn);
+            sendFromNet(MSG_CONNECTED, playerName);
+        }
+    };
+
+    private final StrCallback passwordRequestCb = new StrCallback() {
+        public void callback(Pointer context, String nickname) {
+            sendFromNet(MSG_PASSWORD_REQUEST, playerName);
+        }
+    };
+
+    private final BoolCallback enterRoomCb = new BoolCallback() {
+        public void callback(Pointer context, boolean isChief) {
+            sendFromNet(MSG_ENTER_ROOM_FROM_LOBBY, isChief);
+        }
+    };
+
+    private final IntStrCallback leaveRoomCb = new IntStrCallback() {
+        public void callback(Pointer context, int reason, String message) {
+            sendFromNet(MSG_LEAVE_ROOM, reason, message);
+        }
+    };
+
+    private final TeamCallback teamAddedCb = new TeamCallback() {
+        public void callback(Pointer context, TeamPtr team) {
+            sendFromNet(MSG_TEAM_ADDED, team.deref());
+        }
+    };
+
+    private final StrCallback teamDeletedCb = new StrCallback() {
+        public void callback(Pointer context, String teamName) {
+            sendFromNet(MSG_TEAM_DELETED, teamName);
+        }
+    };
+
+    private final StrCallback teamAcceptedCb = new StrCallback() {
+        public void callback(Pointer context, String teamName) {
+            sendFromNet(MSG_TEAM_ACCEPTED, teamName);
+        }
+    };
+
+    private final StrIntCallback teamColorChangedCb = new StrIntCallback() {
+        public void callback(Pointer context, String teamName, int colorIndex) {
+            sendFromNet(MSG_TEAM_COLOR_CHANGED, colorIndex, teamName);
+        }
+    };
+
+    private final StrIntCallback hogCountChangedCb = new StrIntCallback() {
+        public void callback(Pointer context, String teamName, int hogCount) {
+            sendFromNet(MSG_HOG_COUNT_CHANGED, hogCount, teamName);
+        }
+    };
+
+    private final BytesCallback engineMessageCb = new BytesCallback() {
+        public void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size) {
+            sendFromNet(MSG_ENGINE_MESSAGE, buffer.deref(size.intValue()));
+        }
+    };
 
-				FLIB.flib_netconn_onSchemeChanged(conn, cfgSchemeCb, null);
-				FLIB.flib_netconn_onClientFlags(conn, clientFlagsCb, null);
-				FLIB.flib_netconn_onChat(conn, chatCb, null);
-				FLIB.flib_netconn_onConnected(conn, connectedCb, null);
-				FLIB.flib_netconn_onDisconnected(conn, disconnectCb, null);
-				FLIB.flib_netconn_onEngineMessage(conn, engineMessageCb, null);
-				FLIB.flib_netconn_onEnterRoom(conn, enterRoomCb, null);
-				FLIB.flib_netconn_onHogCountChanged(conn, hogCountChangedCb, null);
-				FLIB.flib_netconn_onLeaveRoom(conn, leaveRoomCb, null);
-				FLIB.flib_netconn_onLobbyJoin(conn, lobbyJoinCb, null);
-				FLIB.flib_netconn_onLobbyLeave(conn, lobbyLeaveCb, null);
-				FLIB.flib_netconn_onMapChanged(conn, mapChangedCb, null);
-				FLIB.flib_netconn_onMessage(conn, messageCb, null);
-				FLIB.flib_netconn_onPasswordRequest(conn, passwordRequestCb, null);
-				FLIB.flib_netconn_onRoomAdd(conn, roomAddCb, null);
-				FLIB.flib_netconn_onRoomDelete(conn, roomDeleteCb, null);
-				FLIB.flib_netconn_onRoomJoin(conn, roomJoinCb, null);
-				FLIB.flib_netconn_onRoomLeave(conn, roomLeaveCb, null);
-				FLIB.flib_netconn_onRoomlist(conn, roomlistCb, null);
-				FLIB.flib_netconn_onRoomUpdate(conn, roomUpdateCb, null);
-				FLIB.flib_netconn_onRunGame(conn, runGameCb, null);
-				FLIB.flib_netconn_onScriptChanged(conn, scriptChangedCb, null);
-				// FLIB.flib_netconn_onServerVar(conn, serverVarCb, null);
-				FLIB.flib_netconn_onTeamAccepted(conn, teamAcceptedCb, null);
-				FLIB.flib_netconn_onTeamAdd(conn, teamAddedCb, null);
-				FLIB.flib_netconn_onTeamColorChanged(conn, teamColorChangedCb, null);
-				FLIB.flib_netconn_onTeamDelete(conn, teamDeletedCb, null);
-				FLIB.flib_netconn_onWeaponsetChanged(conn, weaponsetChangedCb, null);
-				
-				tickHandler.start();
-			}
-		});
-	}
-	
-	public static ThreadedNetConnection startConnection(Context appContext, FromNetHandler fromNetHandler, String playerName, String host, int port) {
-		ThreadedNetConnection result = new ThreadedNetConnection(appContext, fromNetHandler);
-		result.connect(playerName, host, port);
-		return result;
-	}
-	
-	public void setFastTickRate(boolean fastTickRate) {
-		tickHandler.setInterval(fastTickRate ? TICK_INTERVAL_FAST : TICK_INTERVAL_SLOW);
-	}
-	
-	private final Runnable tickCb = new Runnable() {
-		public void run() {
-			FLIB.flib_netconn_tick(conn);
-		}
-	};
-	
-	private final SchemeCallback cfgSchemeCb = new SchemeCallback() {
-		public void callback(Pointer context, SchemePtr schemePtr) {
-			sendFromNet(MSG_SCHEME_CHANGED, schemePtr.deref());
-		}
-	};
-	
-	private final MapIntCallback mapChangedCb = new MapIntCallback() {
-		public void callback(Pointer context, MapRecipePtr mapPtr, int updateType) {
-			sendFromNet(MSG_MAP_CHANGED, updateType, mapPtr.deref());
-		}
-	};
-	
-	private final StrCallback scriptChangedCb = new StrCallback() {
-		public void callback(Pointer context, String script) {
-			sendFromNet(MSG_SCRIPT_CHANGED, script);
-		}
-	};
-	
-	private final WeaponsetCallback weaponsetChangedCb = new WeaponsetCallback() {
-		public void callback(Pointer context, WeaponsetPtr weaponsetPtr) {
-			sendFromNet(MSG_WEAPONSET_CHANGED, weaponsetPtr.deref());				
-		}
-	};
-	
-	private final StrCallback lobbyJoinCb = new StrCallback() {
-		public void callback(Pointer context, String name) {
-			sendFromNet(MSG_LOBBY_JOIN, name);
-		}
-	};
-	
-	private final StrStrCallback lobbyLeaveCb = new StrStrCallback() {
-		public void callback(Pointer context, String name, String msg) {
-			sendFromNet(MSG_LOBBY_LEAVE, Pair.create(name, msg));
-		}
-	};
-	
-	private final StrCallback roomJoinCb = new StrCallback() {
-		public void callback(Pointer context, String name) {
-			sendFromNet(MSG_ROOM_JOIN, name);
-		}
-	};
-	
-	private final StrStrCallback roomLeaveCb = new StrStrCallback() {
-		public void callback(Pointer context, String name, String message) {
-			sendFromNet(MSG_ROOM_LEAVE, Pair.create(name, message));
-		}
-	};
-	
-	private final StrStrBoolCallback clientFlagsCb = new StrStrBoolCallback() {
-		public void callback(Pointer context, String nick, String flags, boolean newFlagsState) {
-			sendFromNet(MSG_CLIENT_FLAGS, new ClientFlagsUpdate(nick, flags, newFlagsState));
-		}
-	};
-	
-	private final StrStrCallback chatCb = new StrStrCallback() {
-		public void callback(Pointer context, String name, String msg) {
-			sendFromNet(MSG_CHAT, Pair.create(name, msg));
-		}
-	};
-	
-	private final IntStrCallback messageCb = new IntStrCallback() {
-		public void callback(Pointer context, int type, String msg) {
-			sendFromNet(MSG_MESSAGE, type, msg);
-		}
-	};
-	
-	private final RoomCallback roomAddCb = new RoomCallback() {
-		public void callback(Pointer context, RoomPtr roomPtr) {
-			sendFromNet(MSG_ROOM_ADD, roomPtr.deref());
-		}
-	};
-	
-	private final StrRoomCallback roomUpdateCb = new StrRoomCallback() {
-		public void callback(Pointer context, String name, RoomPtr roomPtr) {
-			sendFromNet(MSG_ROOM_UPDATE, Pair.create(name, roomPtr.deref()));
-		}
-	};
-	
-	private final StrCallback roomDeleteCb = new StrCallback() {
-		public void callback(Pointer context, final String name) {
-			sendFromNet(MSG_ROOM_DELETE, name);
-		}
-	};
-	
-	private final RoomListCallback roomlistCb = new RoomListCallback() {
-		public void callback(Pointer context, RoomArrayPtr arg1, int count) {
-			sendFromNet(MSG_ROOMLIST, arg1.getRooms(count));
-		}
-	};
-	
-	private final VoidCallback connectedCb = new VoidCallback() {
-		public void callback(Pointer context) {
-			FLIB.flib_netconn_send_request_roomlist(conn);
-			playerName = FLIB.flib_netconn_get_playername(conn);
-			sendFromNet(MSG_CONNECTED, playerName);
-		}
-	};
-	
-	private final StrCallback passwordRequestCb = new StrCallback() {
-		public void callback(Pointer context, String nickname) {
-			sendFromNet(MSG_PASSWORD_REQUEST, playerName);
-		}
-	};
-	
-	private final BoolCallback enterRoomCb = new BoolCallback() {
-		public void callback(Pointer context, boolean isChief) {
-			sendFromNet(MSG_ENTER_ROOM_FROM_LOBBY, isChief);
-		}
-	};
-	
-	private final IntStrCallback leaveRoomCb = new IntStrCallback() {
-		public void callback(Pointer context, int reason, String message) {
-			sendFromNet(MSG_LEAVE_ROOM, reason, message);
-		}
-	};
-	
-	private final TeamCallback teamAddedCb = new TeamCallback() {
-		public void callback(Pointer context, TeamPtr team) {
-			sendFromNet(MSG_TEAM_ADDED, team.deref());
-		}
-	};
-	
-	private final StrCallback teamDeletedCb = new StrCallback() {
-		public void callback(Pointer context, String teamName) {
-			sendFromNet(MSG_TEAM_DELETED, teamName);
-		}
-	};
-	
-	private final StrCallback teamAcceptedCb = new StrCallback() {
-		public void callback(Pointer context, String teamName) {
-			sendFromNet(MSG_TEAM_ACCEPTED, teamName);
-		}
-	};
-	
-	private final StrIntCallback teamColorChangedCb = new StrIntCallback() {
-		public void callback(Pointer context, String teamName, int colorIndex) {
-			sendFromNet(MSG_TEAM_COLOR_CHANGED, colorIndex, teamName);
-		}
-	};
-	
-	private final StrIntCallback hogCountChangedCb = new StrIntCallback() {
-		public void callback(Pointer context, String teamName, int hogCount) {
-			sendFromNet(MSG_HOG_COUNT_CHANGED, hogCount, teamName);
-		}
-	};
-	
-	private final BytesCallback engineMessageCb = new BytesCallback() {
-		public void callback(Pointer context, ByteArrayPtr buffer, NativeSizeT size) {
-			sendFromNet(MSG_ENGINE_MESSAGE, buffer.deref(size.intValue()));
-		}
-	};
-	
-	private final VoidCallback runGameCb = new VoidCallback() {
-		public void callback(Pointer context) {
-			GameSetupPtr configPtr = FLIB.flib_netconn_create_gamesetup(conn);
-			sendFromNet(MSG_RUN_GAME, configPtr.deref());
-			FLIB.flib_gamesetup_destroy(configPtr);
-		}
-	};
-	
-	private void shutdown(boolean error, String message) {
-		if(conn != null) {
-			FLIB.flib_netconn_destroy(conn);
-			conn = null;
-		}
-		tickHandler.stop();
-		toNetHandler.getLooper().quit();
-		sendFromNet(MSG_DISCONNECTED, Pair.create(error, message));
-	}
-	
-	private final IntStrCallback disconnectCb = new IntStrCallback() {
-		public void callback(Pointer context, int reason, String message) {
-			Boolean error = reason != Frontlib.NETCONN_DISCONNECT_NORMAL;
-			String messageForUser = createDisconnectUserMessage(appContext.getResources(), reason, message);
-			shutdown(error, messageForUser);
-		}
-	};
-	
-	private static String createDisconnectUserMessage(Resources res, int reason, String message) {
-		switch(reason) {
-		case Frontlib.NETCONN_DISCONNECT_AUTH_FAILED:
-			return res.getString(R.string.error_auth_failed);
-		case Frontlib.NETCONN_DISCONNECT_CONNLOST:
-			return res.getString(R.string.error_connection_lost);
-		case Frontlib.NETCONN_DISCONNECT_INTERNAL_ERROR:
-			return res.getString(R.string.error_unexpected, message);
-		case Frontlib.NETCONN_DISCONNECT_SERVER_TOO_OLD:
-			return res.getString(R.string.error_server_too_old);
-		default:
-			return message;
-		}
-	}
-	
-	private boolean sendFromNet(FromNetMsgType what, Object obj) {
-		return fromNetHandler.sendMessage(fromNetHandler.obtainMessage(what.ordinal(), obj));
-	}
-	
-	private boolean sendFromNet(FromNetMsgType what, int arg1, Object obj) {
-		return fromNetHandler.sendMessage(fromNetHandler.obtainMessage(what.ordinal(), arg1, 0, obj));
-	}
-	
-	static enum ToNetMsgType {
-		MSG_SEND_NICK,
-		MSG_SEND_PASSWORD,
-		MSG_SEND_QUIT,
-		MSG_SEND_ROOMLIST_REQUEST,
-		MSG_SEND_PLAYER_INFO_REQUEST,
-		MSG_SEND_CHAT,
-		MSG_SEND_TEAMCHAT,
-		MSG_SEND_FOLLOW_PLAYER,
-		MSG_SEND_JOIN_ROOM,
-		MSG_SEND_CREATE_ROOM,
-		MSG_SEND_LEAVE_ROOM,
-		MSG_SEND_KICK,
-		MSG_SEND_ADD_TEAM,
-		MSG_SEND_REMOVE_TEAM,
-		MSG_DISCONNECT,
-		MSG_SEND_TEAM_COLOR_INDEX,
-		MSG_SEND_TEAM_HOG_COUNT,
-		MSG_SEND_ENGINE_MESSAGE,
-		MSG_SEND_ROUND_FINISHED,
-		MSG_SEND_TOGGLE_READY,
-		MSG_SEND_START_GAME,
-		MSG_SEND_WEAPONSET,
-		MSG_SEND_MAP,
-		MSG_SEND_MAP_NAME,
-		MSG_SEND_MAP_GENERATOR,
-		MSG_SEND_MAP_TEMPLATE,
-		MSG_SEND_MAZE_SIZE,
-		MSG_SEND_MAP_SEED,
-		MSG_SEND_MAP_THEME,
-		MSG_SEND_MAP_DRAWDATA,
-		MSG_SEND_GAMESTYLE,
-		MSG_SEND_SCHEME;
-		
-		static final List<ThreadedNetConnection.ToNetMsgType> values = Collections.unmodifiableList(Arrays.asList(ToNetMsgType.values()));
-	}
-	
-	/**
-	 * Processes messages to the networking system. Runs on a non-main thread.
-	 */
-	@SuppressLint("HandlerLeak")
-	public final class ToNetHandler extends Handler {
-		
-		public ToNetHandler(Looper looper) {
-			super(looper);
-		}
-		
-		@Override
-		public void handleMessage(Message msg) {
-			switch(ToNetMsgType.values.get(msg.what)) {
-			case MSG_SEND_NICK: {
-				FLIB.flib_netconn_send_nick(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_PASSWORD: {
-				FLIB.flib_netconn_send_password(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_QUIT: {
-				FLIB.flib_netconn_send_quit(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_ROOMLIST_REQUEST: {
-				FLIB.flib_netconn_send_request_roomlist(conn);
-				break;
-			}
-			case MSG_SEND_PLAYER_INFO_REQUEST: {
-				FLIB.flib_netconn_send_playerInfo(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_CHAT: {
-				if(FLIB.flib_netconn_send_chat(conn, (String)msg.obj) == 0) {
-					sendFromNet(MSG_CHAT, Pair.create(playerName, (String)msg.obj));
-				}
-				break;
-			}
-			case MSG_SEND_TEAMCHAT: {
-				FLIB.flib_netconn_send_teamchat(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_FOLLOW_PLAYER: {
-				FLIB.flib_netconn_send_playerFollow(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_JOIN_ROOM: {
-				FLIB.flib_netconn_send_joinRoom(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_CREATE_ROOM: {
-				FLIB.flib_netconn_send_createRoom(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_LEAVE_ROOM: {
-				if(FLIB.flib_netconn_send_leaveRoom(conn, (String)msg.obj) == 0) {
-					sendFromNet(MSG_LEAVE_ROOM, -1, "");
-				}
-				break;
-			}
-			case MSG_SEND_KICK: {
-				FLIB.flib_netconn_send_kick(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_ADD_TEAM: {
-				FLIB.flib_netconn_send_addTeam(conn, TeamPtr.createJavaOwned((TeamInGame)msg.obj));
-				break;
-			}
-			case MSG_SEND_REMOVE_TEAM: {
-				if(FLIB.flib_netconn_send_removeTeam(conn, (String)msg.obj)==0) {
-					sendFromNet(MSG_TEAM_DELETED, msg.obj);
-				}
-				break;
-			}
-			case MSG_DISCONNECT: {
-				FLIB.flib_netconn_send_quit(conn, (String)msg.obj);
-				shutdown(false, "User quit");
-				break;
-			}
-			case MSG_SEND_TEAM_COLOR_INDEX: {
-				FLIB.flib_netconn_send_teamColor(conn, (String)msg.obj, msg.arg1);
-				break;
-			}
-			case MSG_SEND_TEAM_HOG_COUNT: {
-				FLIB.flib_netconn_send_teamHogCount(conn, (String)msg.obj, msg.arg1);
-				break;
-			}
-			case MSG_SEND_ENGINE_MESSAGE: {
-				byte[] message = (byte[])msg.obj;
-				ByteArrayPtr ptr = ByteArrayPtr.createJavaOwned(message);
-				FLIB.flib_netconn_send_engineMessage(conn, ptr, NativeSizeT.valueOf(message.length));
-				break;
-			}
-			case MSG_SEND_ROUND_FINISHED: {
-				FLIB.flib_netconn_send_roundfinished(conn, (Boolean)msg.obj);
-				break;
-			}
-			case MSG_SEND_TOGGLE_READY: {
-				FLIB.flib_netconn_send_toggleReady(conn);
-				break;
-			}
-			case MSG_SEND_START_GAME: {
-				FLIB.flib_netconn_send_startGame(conn);
-				break;
-			}
-			case MSG_SEND_WEAPONSET: {
-				FLIB.flib_netconn_send_weaponset(conn, WeaponsetPtr.createJavaOwned((Weaponset)msg.obj));
-				break;
-			}
-			case MSG_SEND_MAP: {
-				FLIB.flib_netconn_send_map(conn, MapRecipePtr.createJavaOwned((MapRecipe)msg.obj));
-				break;
-			}
-			case MSG_SEND_MAP_NAME: {
-				FLIB.flib_netconn_send_mapName(conn, (String)msg.obj);
-				break;
-			}
-			case MSG_SEND_MAP_GENERATOR: {
-				FLIB.flib_netconn_send_mapGen(conn, msg.arg1);
-				break;
-			}
-			case MSG_SEND_MAP_TEMPLATE: {
-				FLIB.flib_netconn_send_mapTemplate(conn, msg.arg1);
-				break;
-			}
-			case MSG_SEND_MAZE_SIZE: {
-				FLIB.flib_netconn_send_mapMazeSize(conn, msg.arg1);
-				break;
-			}
-			case MSG_SEND_MAP_SEED: {
-				FLIB.flib_netconn_send_mapSeed(conn, (String) msg.obj);
-				break;
-			}
-			case MSG_SEND_MAP_THEME: {
-				FLIB.flib_netconn_send_mapTheme(conn, (String) msg.obj);
-				break;
-			}
-			case MSG_SEND_MAP_DRAWDATA: {
-				byte[] message = (byte[])msg.obj;
-				ByteArrayPtr ptr = ByteArrayPtr.createJavaOwned(message);
-				FLIB.flib_netconn_send_mapDrawdata(conn, ptr, NativeSizeT.valueOf(message.length));
-				break;
-			}
-			case MSG_SEND_GAMESTYLE: {
-				FLIB.flib_netconn_send_script(conn, (String) msg.obj);
-				break;
-			}
-			case MSG_SEND_SCHEME: {
-				FLIB.flib_netconn_send_scheme(conn, SchemePtr.createJavaOwned((Scheme) msg.obj));
-				break;
-			}
-			default: {
-				Log.e("ToNetHandler", "Unknown message type: "+msg.what);
-				break;
-			}
-			}
-		}
-	}
+    private final VoidCallback runGameCb = new VoidCallback() {
+        public void callback(Pointer context) {
+            GameSetupPtr configPtr = FLIB.flib_netconn_create_gamesetup(conn);
+            sendFromNet(MSG_RUN_GAME, configPtr.deref());
+            FLIB.flib_gamesetup_destroy(configPtr);
+        }
+    };
+
+    private void shutdown(boolean error, String message) {
+        if(conn != null) {
+            FLIB.flib_netconn_destroy(conn);
+            conn = null;
+        }
+        tickHandler.stop();
+        toNetHandler.getLooper().quit();
+        sendFromNet(MSG_DISCONNECTED, Pair.create(error, message));
+    }
+
+    private final IntStrCallback disconnectCb = new IntStrCallback() {
+        public void callback(Pointer context, int reason, String message) {
+            Boolean error = reason != Frontlib.NETCONN_DISCONNECT_NORMAL;
+            String messageForUser = createDisconnectUserMessage(appContext.getResources(), reason, message);
+            shutdown(error, messageForUser);
+        }
+    };
+
+    private static String createDisconnectUserMessage(Resources res, int reason, String message) {
+        switch(reason) {
+        case Frontlib.NETCONN_DISCONNECT_AUTH_FAILED:
+            return res.getString(R.string.error_auth_failed);
+        case Frontlib.NETCONN_DISCONNECT_CONNLOST:
+            return res.getString(R.string.error_connection_lost);
+        case Frontlib.NETCONN_DISCONNECT_INTERNAL_ERROR:
+            return res.getString(R.string.error_unexpected, message);
+        case Frontlib.NETCONN_DISCONNECT_SERVER_TOO_OLD:
+            return res.getString(R.string.error_server_too_old);
+        default:
+            return message;
+        }
+    }
+
+    private boolean sendFromNet(FromNetMsgType what, Object obj) {
+        return fromNetHandler.sendMessage(fromNetHandler.obtainMessage(what.ordinal(), obj));
+    }
+
+    private boolean sendFromNet(FromNetMsgType what, int arg1, Object obj) {
+        return fromNetHandler.sendMessage(fromNetHandler.obtainMessage(what.ordinal(), arg1, 0, obj));
+    }
+
+    static enum ToNetMsgType {
+        MSG_SEND_NICK,
+        MSG_SEND_PASSWORD,
+        MSG_SEND_QUIT,
+        MSG_SEND_ROOMLIST_REQUEST,
+        MSG_SEND_PLAYER_INFO_REQUEST,
+        MSG_SEND_CHAT,
+        MSG_SEND_TEAMCHAT,
+        MSG_SEND_FOLLOW_PLAYER,
+        MSG_SEND_JOIN_ROOM,
+        MSG_SEND_CREATE_ROOM,
+        MSG_SEND_LEAVE_ROOM,
+        MSG_SEND_KICK,
+        MSG_SEND_ADD_TEAM,
+        MSG_SEND_REMOVE_TEAM,
+        MSG_DISCONNECT,
+        MSG_SEND_TEAM_COLOR_INDEX,
+        MSG_SEND_TEAM_HOG_COUNT,
+        MSG_SEND_ENGINE_MESSAGE,
+        MSG_SEND_ROUND_FINISHED,
+        MSG_SEND_TOGGLE_READY,
+        MSG_SEND_START_GAME,
+        MSG_SEND_WEAPONSET,
+        MSG_SEND_MAP,
+        MSG_SEND_MAP_NAME,
+        MSG_SEND_MAP_GENERATOR,
+        MSG_SEND_MAP_TEMPLATE,
+        MSG_SEND_MAZE_SIZE,
+        MSG_SEND_MAP_SEED,
+        MSG_SEND_MAP_THEME,
+        MSG_SEND_MAP_DRAWDATA,
+        MSG_SEND_GAMESTYLE,
+        MSG_SEND_SCHEME;
+
+        static final List<ThreadedNetConnection.ToNetMsgType> values = Collections.unmodifiableList(Arrays.asList(ToNetMsgType.values()));
+    }
+
+    /**
+     * Processes messages to the networking system. Runs on a non-main thread.
+     */
+    @SuppressLint("HandlerLeak")
+    public final class ToNetHandler extends Handler {
+
+        public ToNetHandler(Looper looper) {
+            super(looper);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch(ToNetMsgType.values.get(msg.what)) {
+            case MSG_SEND_NICK: {
+                FLIB.flib_netconn_send_nick(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_PASSWORD: {
+                FLIB.flib_netconn_send_password(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_QUIT: {
+                FLIB.flib_netconn_send_quit(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_ROOMLIST_REQUEST: {
+                FLIB.flib_netconn_send_request_roomlist(conn);
+                break;
+            }
+            case MSG_SEND_PLAYER_INFO_REQUEST: {
+                FLIB.flib_netconn_send_playerInfo(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_CHAT: {
+                if(FLIB.flib_netconn_send_chat(conn, (String)msg.obj) == 0) {
+                    sendFromNet(MSG_CHAT, Pair.create(playerName, (String)msg.obj));
+                }
+                break;
+            }
+            case MSG_SEND_TEAMCHAT: {
+                FLIB.flib_netconn_send_teamchat(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_FOLLOW_PLAYER: {
+                FLIB.flib_netconn_send_playerFollow(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_JOIN_ROOM: {
+                FLIB.flib_netconn_send_joinRoom(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_CREATE_ROOM: {
+                FLIB.flib_netconn_send_createRoom(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_LEAVE_ROOM: {
+                if(FLIB.flib_netconn_send_leaveRoom(conn, (String)msg.obj) == 0) {
+                    sendFromNet(MSG_LEAVE_ROOM, -1, "");
+                }
+                break;
+            }
+            case MSG_SEND_KICK: {
+                FLIB.flib_netconn_send_kick(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_ADD_TEAM: {
+                FLIB.flib_netconn_send_addTeam(conn, TeamPtr.createJavaOwned((TeamInGame)msg.obj));
+                break;
+            }
+            case MSG_SEND_REMOVE_TEAM: {
+                if(FLIB.flib_netconn_send_removeTeam(conn, (String)msg.obj)==0) {
+                    sendFromNet(MSG_TEAM_DELETED, msg.obj);
+                }
+                break;
+            }
+            case MSG_DISCONNECT: {
+                FLIB.flib_netconn_send_quit(conn, (String)msg.obj);
+                shutdown(false, "User quit");
+                break;
+            }
+            case MSG_SEND_TEAM_COLOR_INDEX: {
+                FLIB.flib_netconn_send_teamColor(conn, (String)msg.obj, msg.arg1);
+                break;
+            }
+            case MSG_SEND_TEAM_HOG_COUNT: {
+                FLIB.flib_netconn_send_teamHogCount(conn, (String)msg.obj, msg.arg1);
+                break;
+            }
+            case MSG_SEND_ENGINE_MESSAGE: {
+                byte[] message = (byte[])msg.obj;
+                ByteArrayPtr ptr = ByteArrayPtr.createJavaOwned(message);
+                FLIB.flib_netconn_send_engineMessage(conn, ptr, NativeSizeT.valueOf(message.length));
+                break;
+            }
+            case MSG_SEND_ROUND_FINISHED: {
+                FLIB.flib_netconn_send_roundfinished(conn, (Boolean)msg.obj);
+                break;
+            }
+            case MSG_SEND_TOGGLE_READY: {
+                FLIB.flib_netconn_send_toggleReady(conn);
+                break;
+            }
+            case MSG_SEND_START_GAME: {
+                FLIB.flib_netconn_send_startGame(conn);
+                break;
+            }
+            case MSG_SEND_WEAPONSET: {
+                FLIB.flib_netconn_send_weaponset(conn, WeaponsetPtr.createJavaOwned((Weaponset)msg.obj));
+                break;
+            }
+            case MSG_SEND_MAP: {
+                FLIB.flib_netconn_send_map(conn, MapRecipePtr.createJavaOwned((MapRecipe)msg.obj));
+                break;
+            }
+            case MSG_SEND_MAP_NAME: {
+                FLIB.flib_netconn_send_mapName(conn, (String)msg.obj);
+                break;
+            }
+            case MSG_SEND_MAP_GENERATOR: {
+                FLIB.flib_netconn_send_mapGen(conn, msg.arg1);
+                break;
+            }
+            case MSG_SEND_MAP_TEMPLATE: {
+                FLIB.flib_netconn_send_mapTemplate(conn, msg.arg1);
+                break;
+            }
+            case MSG_SEND_MAZE_SIZE: {
+                FLIB.flib_netconn_send_mapMazeSize(conn, msg.arg1);
+                break;
+            }
+            case MSG_SEND_MAP_SEED: {
+                FLIB.flib_netconn_send_mapSeed(conn, (String) msg.obj);
+                break;
+            }
+            case MSG_SEND_MAP_THEME: {
+                FLIB.flib_netconn_send_mapTheme(conn, (String) msg.obj);
+                break;
+            }
+            case MSG_SEND_MAP_DRAWDATA: {
+                byte[] message = (byte[])msg.obj;
+                ByteArrayPtr ptr = ByteArrayPtr.createJavaOwned(message);
+                FLIB.flib_netconn_send_mapDrawdata(conn, ptr, NativeSizeT.valueOf(message.length));
+                break;
+            }
+            case MSG_SEND_GAMESTYLE: {
+                FLIB.flib_netconn_send_script(conn, (String) msg.obj);
+                break;
+            }
+            case MSG_SEND_SCHEME: {
+                FLIB.flib_netconn_send_scheme(conn, SchemePtr.createJavaOwned((Scheme) msg.obj));
+                break;
+            }
+            default: {
+                Log.e("ToNetHandler", "Unknown message type: "+msg.what);
+                break;
+            }
+            }
+        }
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/CalmDownHandler.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/CalmDownHandler.java	Tue Jan 21 22:53:15 2014 +0100
@@ -32,31 +32,31 @@
  * information change.
  */
 public final class CalmDownHandler extends Handler {
-	int runningMessagesCounter = 0;
-	final Runnable inactivityRunnable;
-	final long inactivityMs;
-	boolean stopped;
+    int runningMessagesCounter = 0;
+    final Runnable inactivityRunnable;
+    final long inactivityMs;
+    boolean stopped;
+
+    public CalmDownHandler(Looper looper, Runnable runnable, long inactivityMs) {
+        super(looper);
+        this.inactivityRunnable = runnable;
+        this.inactivityMs = inactivityMs;
+    }
 
-	public CalmDownHandler(Looper looper, Runnable runnable, long inactivityMs) {
-		super(looper);
-		this.inactivityRunnable = runnable;
-		this.inactivityMs = inactivityMs;
-	}
-	
-	public void activity() {
-		runningMessagesCounter++;
-		sendMessageDelayed(obtainMessage(), inactivityMs);
-	}
-	
-	@Override
-	public void handleMessage(Message msg) {
-		runningMessagesCounter--;
-		if(runningMessagesCounter==0 && !stopped) {
-			inactivityRunnable.run();
-		}
-	}
-	
-	public void stop() {
-		stopped = true;
-	}
+    public void activity() {
+        runningMessagesCounter++;
+        sendMessageDelayed(obtainMessage(), inactivityMs);
+    }
+
+    @Override
+    public void handleMessage(Message msg) {
+        runningMessagesCounter--;
+        if(runningMessagesCounter==0 && !stopped) {
+            inactivityRunnable.run();
+        }
+    }
+
+    public void stop() {
+        stopped = true;
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/FileUtils.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/FileUtils.java	Tue Jan 21 22:53:15 2014 +0100
@@ -40,220 +40,220 @@
 import android.util.Log;
 
 public class FileUtils {
-	private static final String ROOT_DIR = "Data";
-	private static final String TAG = FileUtils.class.getSimpleName();
+    private static final String ROOT_DIR = "Data";
+    private static final String TAG = FileUtils.class.getSimpleName();
+
+    /**
+     * @return true if the data path is currently available. However, it can vanish at any time so
+     * normally you should just try to use it and rely on the exceptions.
+     */
+    public static boolean isDataPathAvailable() {
+        return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
+    }
 
-	/**
-	 * @return true if the data path is currently available. However, it can vanish at any time so
-	 * normally you should just try to use it and rely on the exceptions.
-	 */
-	public static boolean isDataPathAvailable() {
-		return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
-	}
-	
-	/**
-	 * get the path to which we should download all the data files
-	 * @param c context 
-	 * @return The directory
-	 * @throws FileNotFoundException if external storage is not available at the moment
-	 */
-	public static File getCachePath(Context c) throws FileNotFoundException {
-		File cachePath = null;
-		if(Build.VERSION.SDK_INT < 8){//8 == Build.VERSION_CODES.FROYO
-			cachePath = PreFroyoSDCardDir.getDownloadPath(c);
-		} else {
-			cachePath = FroyoSDCardDir.getDownloadPath(c);
-		}
-		if(cachePath==null) {
-			throw new FileNotFoundException("External storage is currently unavailable");
-		} else {
-			return cachePath;
-		}
-	}
+    /**
+     * get the path to which we should download all the data files
+     * @param c context
+     * @return The directory
+     * @throws FileNotFoundException if external storage is not available at the moment
+     */
+    public static File getCachePath(Context c) throws FileNotFoundException {
+        File cachePath = null;
+        if(Build.VERSION.SDK_INT < 8){//8 == Build.VERSION_CODES.FROYO
+            cachePath = PreFroyoSDCardDir.getDownloadPath(c);
+        } else {
+            cachePath = FroyoSDCardDir.getDownloadPath(c);
+        }
+        if(cachePath==null) {
+            throw new FileNotFoundException("External storage is currently unavailable");
+        } else {
+            return cachePath;
+        }
+    }
 
-	public static File getDataPathFile(Context c, String...subpath) throws FileNotFoundException {
-		File file = new File(getCachePath(c), ROOT_DIR);
-		for(String pathcomponent : subpath) {
-			file = new File(file, pathcomponent);
-		}
-		return file;
-	}
-	
-	@TargetApi(8)
-	private static class FroyoSDCardDir{
-		public static File getDownloadPath(Context c){
-			return c.getExternalCacheDir();
-		}
-	}
+    public static File getDataPathFile(Context c, String...subpath) throws FileNotFoundException {
+        File file = new File(getCachePath(c), ROOT_DIR);
+        for(String pathcomponent : subpath) {
+            file = new File(file, pathcomponent);
+        }
+        return file;
+    }
+
+    @TargetApi(8)
+    private static class FroyoSDCardDir{
+        public static File getDownloadPath(Context c){
+            return c.getExternalCacheDir();
+        }
+    }
 
-	private static class PreFroyoSDCardDir{
-		public static File getDownloadPath(Context c){
-			if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
-				File extStorageDir = Environment.getExternalStorageDirectory();
-				if(extStorageDir != null) {
-					return new File(extStorageDir, "Hedgewars");
-				}
-			}
-			return null;
-		}
-	}
+    private static class PreFroyoSDCardDir{
+        public static File getDownloadPath(Context c){
+            if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
+                File extStorageDir = Environment.getExternalStorageDirectory();
+                if(extStorageDir != null) {
+                    return new File(extStorageDir, "Hedgewars");
+                }
+            }
+            return null;
+        }
+    }
 
-	/**
-	 * Return a File array with all the files from dirName
-	 * @param c
-	 * @param dirName
-	 * @return
-	 * @throws FileNotFoundException If the sdcard is not available or the subdirectory "dirName" does not exist
-	 */
-	public static File[] getFilesFromRelativeDir(Context c, String dirName) throws FileNotFoundException {
-		File f = getDataPathFile(c, dirName);
+    /**
+     * Return a File array with all the files from dirName
+     * @param c
+     * @param dirName
+     * @return
+     * @throws FileNotFoundException If the sdcard is not available or the subdirectory "dirName" does not exist
+     */
+    public static File[] getFilesFromRelativeDir(Context c, String dirName) throws FileNotFoundException {
+        File f = getDataPathFile(c, dirName);
 
-		if(f.isDirectory()) {
-			return f.listFiles();
-		} else {
-			throw new FileNotFoundException("Directory "+dirName+" does not exist.");
-		}
-	}
+        if(f.isDirectory()) {
+            return f.listFiles();
+        } else {
+            throw new FileNotFoundException("Directory "+dirName+" does not exist.");
+        }
+    }
 
-	/**
-	 * Checks if this directory has a file with suffix suffix
-	 * @param f - directory
-	 * @return
-	 */
-	public static boolean hasFileWithSuffix(File f, String suffix){
-		if(f.isDirectory()){
-			for(String s : f.list()){
-				if(s.endsWith(suffix)) return true;
-			}
-			return false;
-		}else{
-			return false;
-		}
-	}
+    /**
+     * Checks if this directory has a file with suffix suffix
+     * @param f - directory
+     * @return
+     */
+    public static boolean hasFileWithSuffix(File f, String suffix){
+        if(f.isDirectory()){
+            for(String s : f.list()){
+                if(s.endsWith(suffix)) return true;
+            }
+            return false;
+        }else{
+            return false;
+        }
+    }
 
-	/**
-	 * Gives back all dirs which contain a file with suffix fileSuffix
-	 * @param c
-	 * @param path
-	 * @param fileSuffix
-	 * @return
-	 * @throws FileNotFoundException If the sdcard is not available or the subdirectory "path" does not exist
-	 */
-	public static List<String> getDirsWithFileSuffix(Context c, String path, String fileSuffix) throws FileNotFoundException{
-		File[] files = getFilesFromRelativeDir(c,path);
-		ArrayList<String> ret = new ArrayList<String>();
+    /**
+     * Gives back all dirs which contain a file with suffix fileSuffix
+     * @param c
+     * @param path
+     * @param fileSuffix
+     * @return
+     * @throws FileNotFoundException If the sdcard is not available or the subdirectory "path" does not exist
+     */
+    public static List<String> getDirsWithFileSuffix(Context c, String path, String fileSuffix) throws FileNotFoundException{
+        File[] files = getFilesFromRelativeDir(c,path);
+        ArrayList<String> ret = new ArrayList<String>();
 
-		for(File f : files){
-			if(hasFileWithSuffix(f, fileSuffix)) ret.add(f.getName());
-		}
-		return ret;
-	}
+        for(File f : files){
+            if(hasFileWithSuffix(f, fileSuffix)) ret.add(f.getName());
+        }
+        return ret;
+    }
 
-	/**
-	 * Get all files from directory dir which have the given suffix
-	 * @throws FileNotFoundException If the sdcard is not available or the subdirectory "dir" does not exist
-	 */
-	public static List<String> getFileNamesFromDirWithSuffix(Context c, String dir, String suffix, boolean removeSuffix) throws FileNotFoundException{
-		File[] files = FileUtils.getFilesFromRelativeDir(c, dir);
-		List<String> ret = new ArrayList<String>();
-		for(File file : files){
-			String s = file.getName();
-			if(s.endsWith(suffix)){
-				if(removeSuffix) ret.add(s.substring(0, s.length()-suffix.length()));
-				else ret.add(s);
-			}
-		}
-		return ret;
-	}
+    /**
+     * Get all files from directory dir which have the given suffix
+     * @throws FileNotFoundException If the sdcard is not available or the subdirectory "dir" does not exist
+     */
+    public static List<String> getFileNamesFromDirWithSuffix(Context c, String dir, String suffix, boolean removeSuffix) throws FileNotFoundException{
+        File[] files = FileUtils.getFilesFromRelativeDir(c, dir);
+        List<String> ret = new ArrayList<String>();
+        for(File file : files){
+            String s = file.getName();
+            if(s.endsWith(suffix)){
+                if(removeSuffix) ret.add(s.substring(0, s.length()-suffix.length()));
+                else ret.add(s);
+            }
+        }
+        return ret;
+    }
+
+    /**
+     * Close a resource (possibly null), ignoring any IOException.
+     */
+    public static void closeQuietly(Closeable c) {
+        if(c!=null) {
+            try {
+                c.close();
+            } catch(IOException e) {
+                Log.w(TAG, e);
+            }
+        }
+    }
+
+    /**
+     * Write all data from the input stream to the file, creating or overwriting it.
+     * The input stream will be closed.
+     *
+     * @throws IOException
+     */
+    public static void writeStreamToFile(InputStream is, File file) throws IOException {
+        OutputStream os = null;
+        byte[] buffer = new byte[8192];
+        try {
+            os = new FileOutputStream(file);
+            int size;
+            while((size=is.read(buffer)) != -1) {
+                os.write(buffer, 0, size);
+            }
+            os.close(); // Important to close this non-quietly, in case of exceptions when flushing
+        } finally {
+            FileUtils.closeQuietly(is);
+            FileUtils.closeQuietly(os);
+        }
+    }
 
-	/**
-	 * Close a resource (possibly null), ignoring any IOException.
-	 */
-	public static void closeQuietly(Closeable c) {
-		if(c!=null) {
-			try {
-				c.close();
-			} catch(IOException e) {
-				Log.w(TAG, e);
-			}
-		}
-	}
-	
-	/**
-	 * Write all data from the input stream to the file, creating or overwriting it.
-	 * The input stream will be closed.
-	 * 
-	 * @throws IOException
-	 */
-	public static void writeStreamToFile(InputStream is, File file) throws IOException {
-		OutputStream os = null;
-		byte[] buffer = new byte[8192];
-		try {
-			os = new FileOutputStream(file);
-			int size;
-			while((size=is.read(buffer)) != -1) {
-				os.write(buffer, 0, size);
-			}
-			os.close(); // Important to close this non-quietly, in case of exceptions when flushing
-		} finally {
-			FileUtils.closeQuietly(is);
-			FileUtils.closeQuietly(os);
-		}
-	}
-	
-	/**
-	 * Moves resources pointed to by sourceResId (from @res/raw/) to the app's private data directory
-	 * @param c
-	 * @param sourceResId
-	 * @param directory
-	 */
-	public static void resRawToFilesDir(Context c, int sourceResId, int targetFilenames, String directory) throws IOException {
-		File targetDir = new File(c.getFilesDir(), directory);
-		targetDir.mkdirs();
+    /**
+     * Moves resources pointed to by sourceResId (from @res/raw/) to the app's private data directory
+     * @param c
+     * @param sourceResId
+     * @param directory
+     */
+    public static void resRawToFilesDir(Context c, int sourceResId, int targetFilenames, String directory) throws IOException {
+        File targetDir = new File(c.getFilesDir(), directory);
+        targetDir.mkdirs();
+
+        //Get an array with the resource files ID
+        Resources resources = c.getResources();
+        TypedArray ta = resources.obtainTypedArray(sourceResId);
+        TypedArray filenames = resources.obtainTypedArray(targetFilenames);
+        for(int i = 0; i < ta.length(); i++){
+            int resId =  ta.getResourceId(i, 0);
+            String fileName = filenames.getString(i);
+            File f = new File(targetDir, fileName);
+            writeStreamToFile(resources.openRawResource(resId), f);
+        }
+    }
 
-		//Get an array with the resource files ID
-		Resources resources = c.getResources();
-		TypedArray ta = resources.obtainTypedArray(sourceResId);
-		TypedArray filenames = resources.obtainTypedArray(targetFilenames);
-		for(int i = 0; i < ta.length(); i++){
-			int resId =  ta.getResourceId(i, 0);
-			String fileName = filenames.getString(i);
-			File f = new File(targetDir, fileName);
-			writeStreamToFile(resources.openRawResource(resId), f);
-		}
-	}
+    public static String readToString(InputStream is) throws IOException {
+        try {
+            ByteArrayOutputStream os = new ByteArrayOutputStream();
+            byte[] buffer = new byte[8192];
+            int size;
+            while((size=is.read(buffer)) != -1) {
+                os.write(buffer, 0, size);
+            }
+            return new String(os.toByteArray());
+        } finally {
+            closeQuietly(is);
+        }
+    }
+
+    private static final char[] badFilenameChars = new char[] { '/', '\\', ':', '*', '?', '\"', '<', '>', '|', '.', '\0' };
 
-	public static String readToString(InputStream is) throws IOException {
-		try {
-			ByteArrayOutputStream os = new ByteArrayOutputStream();
-			byte[] buffer = new byte[8192];
-			int size;
-			while((size=is.read(buffer)) != -1) {
-				os.write(buffer, 0, size);
-			}
-			return new String(os.toByteArray());
-		} finally {
-			closeQuietly(is);
-		}
-	}
-	
-	private static final char[] badFilenameChars = new char[] { '/', '\\', ':', '*', '?', '\"', '<', '>', '|', '.', '\0' };
-	
-	/**
-	 * Modify the given String so that it can be used as part of a filename
-	 * without causing problems from illegal/special characters.
-	 * 
-	 * The result should be similar to the input, but isn't necessarily
-	 * reversible.
-	 */
-	public static String replaceBadChars(String name) {
-		if (name == null || name.trim().length()==0) {
-			return "_";
-		}
-		name = name.trim();
-		for (char badChar : badFilenameChars) {
-			name = name.replace(badChar, '_');
-		}
-		return name;
-	}
+    /**
+     * Modify the given String so that it can be used as part of a filename
+     * without causing problems from illegal/special characters.
+     *
+     * The result should be similar to the input, but isn't necessarily
+     * reversible.
+     */
+    public static String replaceBadChars(String name) {
+        if (name == null || name.trim().length()==0) {
+            return "_";
+        }
+        name = name.trim();
+        for (char badChar : badFilenameChars) {
+            name = name.replace(badChar, '_');
+        }
+        return name;
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/ObjectUtils.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/ObjectUtils.java	Tue Jan 21 22:53:15 2014 +0100
@@ -20,13 +20,13 @@
 package org.hedgewars.hedgeroid.util;
 
 public final class ObjectUtils {
-	public static boolean equal(Object o1, Object o2) {
-		if(o1==o2) {
-			return true;
-		} else if(o1==null || o2 == null) {
-			return false;
-		} else {
-			return o1.equals(o2);
-		}
-	}
+    public static boolean equal(Object o1, Object o2) {
+        if(o1==o2) {
+            return true;
+        } else if(o1==null || o2 == null) {
+            return false;
+        } else {
+            return o1.equals(o2);
+        }
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/ObservableTreeMap.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/ObservableTreeMap.java	Tue Jan 21 22:53:15 2014 +0100
@@ -26,37 +26,37 @@
 import android.database.DataSetObservable;
 
 public class ObservableTreeMap<K,V> extends DataSetObservable {
-	private final Map<K, V> map = new TreeMap<K, V>();
-	
-	public void replaceContent(Map<? extends K, ? extends V> newMap) {
-		map.clear();
-		map.putAll(newMap);
-		notifyChanged();
-	}
-	
-	public void put(K key, V value) {
-		map.put(key, value);
-		notifyChanged();
-	}
-	
-	public V get(K key) {
-		return map.get(key);
-	}
-	
-	public void remove(K key) {
-		if(map.remove(key) != null) {
-			notifyChanged();
-		}
-	}
-	
-	public void clear() {
-		if(!map.isEmpty()) {
-			map.clear();
-			notifyChanged();
-		}
-	}
-	
-	public Map<K, V> getMap() {
-		return Collections.unmodifiableMap(map);
-	}
+    private final Map<K, V> map = new TreeMap<K, V>();
+
+    public void replaceContent(Map<? extends K, ? extends V> newMap) {
+        map.clear();
+        map.putAll(newMap);
+        notifyChanged();
+    }
+
+    public void put(K key, V value) {
+        map.put(key, value);
+        notifyChanged();
+    }
+
+    public V get(K key) {
+        return map.get(key);
+    }
+
+    public void remove(K key) {
+        if(map.remove(key) != null) {
+            notifyChanged();
+        }
+    }
+
+    public void clear() {
+        if(!map.isEmpty()) {
+            map.clear();
+            notifyChanged();
+        }
+    }
+
+    public Map<K, V> getMap() {
+        return Collections.unmodifiableMap(map);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/ObservableTreeMapAdapter.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/ObservableTreeMapAdapter.java	Tue Jan 21 22:53:15 2014 +0100
@@ -28,67 +28,67 @@
 import android.widget.BaseAdapter;
 
 public abstract class ObservableTreeMapAdapter<K,V> extends BaseAdapter {
-	private boolean sourceChanged = true;
-	private List<V> entries = new ArrayList<V>();
-	private ObservableTreeMap<K, V> source;
-	
-	private DataSetObserver observer = new DataSetObserver() {
-		@Override
-		public void onChanged() {
-			sourceChanged = true;
-			notifyDataSetChanged();
-		}
-		
-		@Override
-		public void onInvalidated() {
-			invalidate();
-		}
-	};
-	
-	abstract protected Comparator<V> getEntryOrder();
-	
-	protected List<V> getEntries() {
-		if(sourceChanged) {
-			entries.clear();
-			entries.addAll(source.getMap().values());
-			Collections.sort(entries, getEntryOrder());
-			sourceChanged = false;
-		}
-		return entries;
-	}
-	
-	public int getCount() {
-		return getEntries().size();
-	}
+    private boolean sourceChanged = true;
+    private List<V> entries = new ArrayList<V>();
+    private ObservableTreeMap<K, V> source;
+
+    private DataSetObserver observer = new DataSetObserver() {
+        @Override
+        public void onChanged() {
+            sourceChanged = true;
+            notifyDataSetChanged();
+        }
+
+        @Override
+        public void onInvalidated() {
+            invalidate();
+        }
+    };
+
+    abstract protected Comparator<V> getEntryOrder();
+
+    protected List<V> getEntries() {
+        if(sourceChanged) {
+            entries.clear();
+            entries.addAll(source.getMap().values());
+            Collections.sort(entries, getEntryOrder());
+            sourceChanged = false;
+        }
+        return entries;
+    }
 
-	public V getItem(int position) {
-		return getEntries().get(position);
-	}
-	
-	public long getItemId(int position) {
-		return position;
-	}
-	
-	@Override
-	public boolean hasStableIds() {
-		return false;
-	}
-	
-	public void setSource(ObservableTreeMap<K,V> source) {
-		if(this.source != null) {
-			this.source.unregisterObserver(observer);
-		}
-		this.source = source;
-		this.source.registerObserver(observer);
-		sourceChanged = true;
-		notifyDataSetChanged();
-	}
-	
-	public void invalidate() {
-		if(source != null) {
-			source.unregisterObserver(observer);
-		}
-		source = null;
-		notifyDataSetInvalidated();
-	}
+    public int getCount() {
+        return getEntries().size();
+    }
+
+    public V getItem(int position) {
+        return getEntries().get(position);
+    }
+
+    public long getItemId(int position) {
+        return position;
+    }
+
+    @Override
+    public boolean hasStableIds() {
+        return false;
+    }
+
+    public void setSource(ObservableTreeMap<K,V> source) {
+        if(this.source != null) {
+            this.source.unregisterObserver(observer);
+        }
+        this.source = source;
+        this.source.registerObserver(observer);
+        sourceChanged = true;
+        notifyDataSetChanged();
+    }
+
+    public void invalidate() {
+        if(source != null) {
+            source.unregisterObserver(observer);
+        }
+        source = null;
+        notifyDataSetInvalidated();
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/TextInputDialog.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/TextInputDialog.java	Tue Jan 21 22:53:15 2014 +0100
@@ -36,113 +36,113 @@
  * interface TextInputDialogListener, which will be called by the dialog if it is submitted or cancelled.
  */
 public class TextInputDialog extends DialogFragment {
-	private static final String BUNDLE_DIALOG_ID = "dialogId";
-	private static final String BUNDLE_TITLE_TEXT = "title";
-	private static final String BUNDLE_MESSAGE_TEXT = "message";
-	private static final String BUNDLE_HINT_TEXT = "hint";
-	
-	private int dialogId, titleText, messageText, hintText;
-	private TextInputDialogListener listener;
-	
-	public interface TextInputDialogListener {
-		void onTextInputDialogSubmitted(int dialogId, String text);
-		void onTextInputDialogCancelled(int dialogId);
-	}
-	
-	/**
-	 * The dialogId is only used for passing back to the callback on the activity, the
-	 * other parameters are text resource IDs. Pass 0 for any of them to not use this
-	 * text.
-	 */
-	public TextInputDialog(int dialogId, int titleText, int messageText, int hintText) {
-		this.dialogId = dialogId;
-		this.titleText = titleText;
-		this.messageText = messageText;
-		this.hintText = hintText;
-	}
-	
-	public TextInputDialog() {
-		// Only for reflection-based instantiation by the framework
-	}
-	
-	@Override
-	public void onAttach(Activity activity) {
-		super.onAttach(activity);
-		try {
-			listener = (TextInputDialogListener) activity;
-		} catch(ClassCastException e) {
-			throw new ClassCastException("Activity " + activity + " must implement TextInputDialogListener to use TextInputDialog.");
-		}
-	}
-	
-	@Override
-	public void onDetach() {
-		super.onDetach();
-		listener = null;
-	}
-	
-	@Override
-	public Dialog onCreateDialog(Bundle savedInstanceState) {
-		if(savedInstanceState != null) {
-			dialogId = savedInstanceState.getInt(BUNDLE_DIALOG_ID, dialogId);
-			titleText = savedInstanceState.getInt(BUNDLE_TITLE_TEXT, titleText);
-			messageText = savedInstanceState.getInt(BUNDLE_MESSAGE_TEXT, messageText);
-			hintText = savedInstanceState.getInt(BUNDLE_HINT_TEXT, hintText);
-		}
-		
-		final EditText editText = new EditText(getActivity());
-		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
-		
-		if(titleText != 0) {
-			builder.setTitle(titleText);
-		}
-		if(messageText != 0) {
-			builder.setTitle(messageText);
-		}
-		if(hintText != 0) {
-			editText.setHint(hintText);
-		}
-		
-		editText.setId(android.R.id.text1);
-		editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
-		editText.setSingleLine();
+    private static final String BUNDLE_DIALOG_ID = "dialogId";
+    private static final String BUNDLE_TITLE_TEXT = "title";
+    private static final String BUNDLE_MESSAGE_TEXT = "message";
+    private static final String BUNDLE_HINT_TEXT = "hint";
+
+    private int dialogId, titleText, messageText, hintText;
+    private TextInputDialogListener listener;
+
+    public interface TextInputDialogListener {
+        void onTextInputDialogSubmitted(int dialogId, String text);
+        void onTextInputDialogCancelled(int dialogId);
+    }
+
+    /**
+     * The dialogId is only used for passing back to the callback on the activity, the
+     * other parameters are text resource IDs. Pass 0 for any of them to not use this
+     * text.
+     */
+    public TextInputDialog(int dialogId, int titleText, int messageText, int hintText) {
+        this.dialogId = dialogId;
+        this.titleText = titleText;
+        this.messageText = messageText;
+        this.hintText = hintText;
+    }
+
+    public TextInputDialog() {
+        // Only for reflection-based instantiation by the framework
+    }
+
+    @Override
+    public void onAttach(Activity activity) {
+        super.onAttach(activity);
+        try {
+            listener = (TextInputDialogListener) activity;
+        } catch(ClassCastException e) {
+            throw new ClassCastException("Activity " + activity + " must implement TextInputDialogListener to use TextInputDialog.");
+        }
+    }
+
+    @Override
+    public void onDetach() {
+        super.onDetach();
+        listener = null;
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        if(savedInstanceState != null) {
+            dialogId = savedInstanceState.getInt(BUNDLE_DIALOG_ID, dialogId);
+            titleText = savedInstanceState.getInt(BUNDLE_TITLE_TEXT, titleText);
+            messageText = savedInstanceState.getInt(BUNDLE_MESSAGE_TEXT, messageText);
+            hintText = savedInstanceState.getInt(BUNDLE_HINT_TEXT, hintText);
+        }
 
-		builder.setView(editText);
-		builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
-			public void onClick(DialogInterface dialog, int which) {
-				dialog.cancel();
-			}
-		});
-		
-		editText.setOnEditorActionListener(new OnEditorActionListener() {
-			public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
-				listener.onTextInputDialogSubmitted(dialogId, v.getText().toString());
-				dismiss();
-				return true;
-			}
-		});
-		
-		builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-			public void onClick(DialogInterface dialog, int which) {
-				listener.onTextInputDialogSubmitted(dialogId, editText.getText().toString());
-			}
-		});
+        final EditText editText = new EditText(getActivity());
+        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+
+        if(titleText != 0) {
+            builder.setTitle(titleText);
+        }
+        if(messageText != 0) {
+            builder.setTitle(messageText);
+        }
+        if(hintText != 0) {
+            editText.setHint(hintText);
+        }
+
+        editText.setId(android.R.id.text1);
+        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
+        editText.setSingleLine();
+
+        builder.setView(editText);
+        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+            public void onClick(DialogInterface dialog, int which) {
+                dialog.cancel();
+            }
+        });
 
-		return builder.create();
-	}
-	
-	@Override
-	public void onSaveInstanceState(Bundle icicle) {
-		super.onSaveInstanceState(icicle);
-		icicle.putInt(BUNDLE_DIALOG_ID, dialogId);
-		icicle.putInt(BUNDLE_TITLE_TEXT, titleText);
-		icicle.putInt(BUNDLE_MESSAGE_TEXT, messageText);
-		icicle.putInt(BUNDLE_HINT_TEXT, hintText);
-	}
-	
-	@Override
-	public void onCancel(DialogInterface dialog) {
-		super.onCancel(dialog);
-		listener.onTextInputDialogCancelled(dialogId);
-	}
+        editText.setOnEditorActionListener(new OnEditorActionListener() {
+            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+                listener.onTextInputDialogSubmitted(dialogId, v.getText().toString());
+                dismiss();
+                return true;
+            }
+        });
+
+        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+            public void onClick(DialogInterface dialog, int which) {
+                listener.onTextInputDialogSubmitted(dialogId, editText.getText().toString());
+            }
+        });
+
+        return builder.create();
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle icicle) {
+        super.onSaveInstanceState(icicle);
+        icicle.putInt(BUNDLE_DIALOG_ID, dialogId);
+        icicle.putInt(BUNDLE_TITLE_TEXT, titleText);
+        icicle.putInt(BUNDLE_MESSAGE_TEXT, messageText);
+        icicle.putInt(BUNDLE_HINT_TEXT, hintText);
+    }
+
+    @Override
+    public void onCancel(DialogInterface dialog) {
+        super.onCancel(dialog);
+        listener.onTextInputDialogCancelled(dialogId);
+    }
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/TickHandler.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/TickHandler.java	Tue Jan 21 22:53:15 2014 +0100
@@ -32,42 +32,42 @@
  * an immediate execution of the runnable again.
  */
 public class TickHandler extends Handler {
-	private final Runnable callback;
-	private int messageId;
-	private long interval;
-	private boolean running;
-	
-	public TickHandler(Looper looper, long interval, Runnable callback) {
-		super(looper);
-		this.callback = callback;
-		this.interval = interval;
-	}
-	
-	public synchronized void stop() {
-		messageId++;
-		running = false;
-	}
-	
-	public synchronized void start() {
-		messageId++;
-		sendMessage(obtainMessage(messageId));
-		running = true;
-	}
-	
-	public synchronized void setInterval(long interval) {
-		this.interval = interval;
-		if(running) {
-			start();
-		}
-	}
-	
-	@Override
-	public synchronized void handleMessage(Message msg) {
-		if(msg.what == messageId) {
-			callback.run();
-		}
-		if(msg.what == messageId) {
-			sendMessageDelayed(obtainMessage(messageId), interval);
-		}
-	}
+    private final Runnable callback;
+    private int messageId;
+    private long interval;
+    private boolean running;
+
+    public TickHandler(Looper looper, long interval, Runnable callback) {
+        super(looper);
+        this.callback = callback;
+        this.interval = interval;
+    }
+
+    public synchronized void stop() {
+        messageId++;
+        running = false;
+    }
+
+    public synchronized void start() {
+        messageId++;
+        sendMessage(obtainMessage(messageId));
+        running = true;
+    }
+
+    public synchronized void setInterval(long interval) {
+        this.interval = interval;
+        if(running) {
+            start();
+        }
+    }
+
+    @Override
+    public synchronized void handleMessage(Message msg) {
+        if(msg.what == messageId) {
+            callback.run();
+        }
+        if(msg.what == messageId) {
+            sendMessageDelayed(obtainMessage(messageId), interval);
+        }
+    }
 }
\ No newline at end of file
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/UiUtils.java	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/UiUtils.java	Tue Jan 21 22:53:15 2014 +0100
@@ -29,25 +29,25 @@
 import android.widget.TextView;
 
 public final class UiUtils {
-	private UiUtils() {
-		throw new AssertionError("This class is not meant to be instantiated");
-	}
+    private UiUtils() {
+        throw new AssertionError("This class is not meant to be instantiated");
+    }
 
-	public static View createVerticalTabIndicator(TabHost tabHost, int label, int icon) {
-		LayoutInflater inflater = (LayoutInflater) tabHost.getContext()
-				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+    public static View createVerticalTabIndicator(TabHost tabHost, int label, int icon) {
+        LayoutInflater inflater = (LayoutInflater) tabHost.getContext()
+                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
-		View view = inflater.inflate(R.layout.tab_indicator_vertical,
-				tabHost.getTabWidget(), false);
+        View view = inflater.inflate(R.layout.tab_indicator_vertical,
+                tabHost.getTabWidget(), false);
 
-		final TextView tv = (TextView) view.findViewById(R.id.title);
-		tv.setText(label);
+        final TextView tv = (TextView) view.findViewById(R.id.title);
+        tv.setText(label);
 
-		if (icon != 0) {
-			ImageView iconView = (ImageView) view.findViewById(R.id.icon);
-			iconView.setImageResource(icon);
-		}
+        if (icon != 0) {
+            ImageView iconView = (ImageView) view.findViewById(R.id.icon);
+            iconView.setImageResource(icon);
+        }
 
-		return view;
-	}
+        return view;
+    }
 }
--- a/project_files/Android-build/jni.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/jni.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -513,7 +513,7 @@
 
 const curVM:PJavaVM=nil;
       curEnv:PJNIEnv=nil;
-      
+
 (*
 function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
 procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer);{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
--- a/project_files/Android-build/log.pas	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/Android-build/log.pas	Tue Jan 21 22:53:15 2014 +0100
@@ -22,7 +22,7 @@
 function __android_log_write(prio:longint;tag,text:pchar):longint; cdecl; external libname name '__android_log_write';
 
 //function __android_log_print(prio:longint;tag,print:pchar;params:array of pchar):longint; cdecl; external libname name '__android_log_print';
-  
+
 implementation
 
 end.
--- a/project_files/HedgewarsMobile/Locale/Japanese.lproj/About.strings	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/HedgewarsMobile/Locale/Japanese.lproj/About.strings	Tue Jan 21 22:53:15 2014 +0100
@@ -1,44 +1,44 @@
-/* code credit */
-"Engine, frontend, net server" = "エンジン、フロントエンド、ネットサーバー";
-"Many desktop frontend improvements" = "多くのデスクトップフロントエンドの改善";
-"Many engine and desktop frontend improvements" = "多くのエンジンとデスクトップフロントエンドの改善";
-"Drillrocket, Ballgun, RC Plane weapons" = "ドリルロケット、ボールガン、ラジコン武器";
-"Mine number and time game settings" = "地雷番号とタイムゲーム設定";
-"Desktop frontend improvements" = "デスクトップフロントエンドの改善";
-"Desktop frontend improvements" = "デスクトップフロントエンドの改善";
-"Mac OS X and iPhone version" = "Mac OS X と iPhone バージョン";
-"Many engine and desktop frontend improvements" = "多くのエンジンとデスクトップフロントエンドの改善";
-"Gamepad and Lua integration" = "ゲームパッドとLuaの統合化";
-"Many engine improvements and graphics" = "多くのエンジン改善とグラフィック";
-"Maze maps" = "迷路地図";
-"Engine and desktop frontend improvements" = "エンジンとデスクトップフロントエンドの改善";
-"Lua game modes and missions" = "Lua ゲームモードとミッション";
-"Desktop frontend improvements" = "デスクトップフロントエンドの改善";
-"Android port" = "アンドロイドポート";
-
-/* art credit */
-"Main graphics" = "メイングラフィック";
-"Some hats" = "帽子";
-"Hedgehogs voice" = "ハリネズミの声";
-
-/* translation credit */
-"Brazilian Portuguese" = "ポルトガル語(ブラジル)";
-"Bulgarian" = "ブルガリア語";
-"Czech" = "チェコ語";
-"Chinese" = "中国語";
-"English" = "英語";
-"Finnish" = "フィンランド語";
-"French" = "フランス語";
-"German" = "ドイツ語";
-"Greek" = "ギリシャ語";
-"Italian" = "イタリア語";
-"Japanese" = "日本語";
-"Korean" = "韓国語";
-"Lithuanian" = "リトアニア語";
-"Polish" = "ポーランド語";
-"Portuguese" = "ポルトガル語";
-"Russian" = "ロシア語";
-"Slovak" = "スロバキア語";
-"Spanish" = "スペイン語";
-"Swedish" = "スウェーデン語";
-"Ukrainian" = "ウクライナ語";
+/* code credit */
+"Engine, frontend, net server" = "エンジン、フロントエンド、ネットサーバー";
+"Many desktop frontend improvements" = "多くのデスクトップフロントエンドの改善";
+"Many engine and desktop frontend improvements" = "多くのエンジンとデスクトップフロントエンドの改善";
+"Drillrocket, Ballgun, RC Plane weapons" = "ドリルロケット、ボールガン、ラジコン武器";
+"Mine number and time game settings" = "地雷番号とタイムゲーム設定";
+"Desktop frontend improvements" = "デスクトップフロントエンドの改善";
+"Desktop frontend improvements" = "デスクトップフロントエンドの改善";
+"Mac OS X and iPhone version" = "Mac OS X と iPhone バージョン";
+"Many engine and desktop frontend improvements" = "多くのエンジンとデスクトップフロントエンドの改善";
+"Gamepad and Lua integration" = "ゲームパッドとLuaの統合化";
+"Many engine improvements and graphics" = "多くのエンジン改善とグラフィック";
+"Maze maps" = "迷路地図";
+"Engine and desktop frontend improvements" = "エンジンとデスクトップフロントエンドの改善";
+"Lua game modes and missions" = "Lua ゲームモードとミッション";
+"Desktop frontend improvements" = "デスクトップフロントエンドの改善";
+"Android port" = "アンドロイドポート";
+
+/* art credit */
+"Main graphics" = "メイングラフィック";
+"Some hats" = "帽子";
+"Hedgehogs voice" = "ハリネズミの声";
+
+/* translation credit */
+"Brazilian Portuguese" = "ポルトガル語(ブラジル)";
+"Bulgarian" = "ブルガリア語";
+"Czech" = "チェコ語";
+"Chinese" = "中国語";
+"English" = "英語";
+"Finnish" = "フィンランド語";
+"French" = "フランス語";
+"German" = "ドイツ語";
+"Greek" = "ギリシャ語";
+"Italian" = "イタリア語";
+"Japanese" = "日本語";
+"Korean" = "韓国語";
+"Lithuanian" = "リトアニア語";
+"Polish" = "ポーランド語";
+"Portuguese" = "ポルトガル語";
+"Russian" = "ロシア語";
+"Slovak" = "スロバキア語";
+"Spanish" = "スペイン語";
+"Swedish" = "スウェーデン語";
+"Ukrainian" = "ウクライナ語";
--- a/project_files/HedgewarsMobile/Locale/Japanese.lproj/Localizable.strings	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/HedgewarsMobile/Locale/Japanese.lproj/Localizable.strings	Tue Jan 21 22:53:15 2014 +0100
@@ -1,380 +1,380 @@
-/* No comment provided by engineer. */
-"A monitor has been disconnected while playing and this has ended the match! You need to restart the game if you wish to use the second display again." = "モニターの接続が切断され、マッチを終了してしまいました!二番目のディスプレーをまた使用したい場合はゲームをリスタートしなければいけません。";
-
-/* from the scheme panel
-   from the team panel */
-"Add" = "追加";
-
-/* No comment provided by engineer. */
-"Aggressive" = "積極的";
-
-/* No comment provided by engineer. */
-"All" = "全て";
-
-/* from the settings table */
-"Alternate Damage" = "代わりのダメージ";
-
-/* No comment provided by engineer. */
-"Are you reeeeeally sure?" = "本当にいいですか?";
-
-/* from the settings table */
-"Audio Preferences" = "オーディオ設定";
-
-/* No comment provided by engineer. */
-"Available Teams" = "利用可能なチーム";
-
-/* No comment provided by engineer. */
-"Average" = "平均";
-
-/* No comment provided by engineer. */
-"Backup" = "バックアップ";
-
-/* No comment provided by engineer. */
-"Before playing the preview needs to be generated" = "プレーする前にプレビューを生成する必要があります";
-
-/* No comment provided by engineer. */
-"Before returning the preview needs to be generated" = "戻る前にプレビューを生成する必要があります";
-
-/* No comment provided by engineer. */
-"Brutal" = "残忍";
-
-/* No comment provided by engineer. */
-"Bully" = "いじめっ子";
-
-/* No comment provided by engineer. */
-"Cancel" = "キャンセル";
-
-/* No comment provided by engineer. */
-"Cavern" = "洞窟";
-
-/* No comment provided by engineer. */
-"Change hedgehogs' hat" = "ハリネズミの帽子を変える";
-
-/* No comment provided by engineer. */
-"Chat with the devs in IRC" = "IRC でデベロッパ達とチャットする";
-
-/* No comment provided by engineer. */
-"Choose a charismatic symbol for your team" = "チームのためのカリスマ的なシンボルを選択する";
-
-/* No comment provided by engineer. */
-"Choose hedgehog graves" = "ハリネズミの墓を選択する";
-
-/* No comment provided by engineer. */
-"Choose team fort" = "チームの砦を選択する";
-
-/* from the settings table */
-"Choosing a Scheme will select its associated Weapon" = "スキームを選択すると関連した武器を選択します。";
-
-/* No comment provided by engineer. */
-"Classic Ammo Menu" = "クラシックな弾薬メニュー";
-
-/* No comment provided by engineer. */
-"Community" = "コミュニティー";
-
-/* from the settings table */
-"Damage popups will notify you on every single hit" = "ダメージポップアップはすべてのヒットを通知してくれます。";
-
-/* from the scheme panel
-   from the team panel */
-"Done" = "終了";
-
-/* from the scheme panel
-   from the team panel */
-"Edit" = "編集";
-
-/* No comment provided by engineer. */
-"Edit scheme preferences" = "スキーム設定を編集";
-
-/* No comment provided by engineer. */
-"Edit team settings" = "チーム設定を編集";
-
-/* No comment provided by engineer. */
-"Edit weapons preferences" = "武器設定を編集";
-
-/* No comment provided by engineer. */
-"End Game" = "ゲームを終了する";
-
-/* No comment provided by engineer. */
-"Flag" = "フラグ";
-
-/* No comment provided by engineer. */
-"Follow us on Twitter" = "ツイッターでフォローする";
-
-/* No comment provided by engineer. */
-"Fort" = "砦";
-
-/* No comment provided by engineer. */
-"Game Modifiers" = "ゲームの変更";
-
-/* No comment provided by engineer. */
-"Game Settings" = "ゲームの設定";
-
-/* No comment provided by engineer. */
-"General" = "一般";
-
-/* No comment provided by engineer. */
-"Grave" = "墓";
-
-/* No comment provided by engineer. */
-"Hedgewars supports multi-monitor configurations, but the screen has to be connected before launching the game." = "Hedgewarsはマルチモニター設定をサポートしていますが、スクリーンはゲームをスタートする前に接続されていなければいけません。";
-
-/* No comment provided by engineer. */
-"Hogs controlled by AI" = "AIにコントロールされたハリネズミ";
-
-/* No comment provided by engineer. */
-"Hold your finger on a weapon to see what it does.\nTap anywhere to dismiss." = "武器の上でホールドして何をするか見る。\nほかの部分をタップして閉じる。";
-
-/* No comment provided by engineer. */
-"Hold your finger on a weapon to see what it does.\nYou can move this window anywhere on the screen." = "武器の上でホールドして何をするか見る。\nこのウィンドウはスクリーンのどこにでも動かすことができます。";
-
-/* ammo selection */
-"Initial quantity " = "初期量";
-
-/* from the settings table */
-"Insert your password" = "パスワードを入力";
-
-/* from the settings table */
-"Insert your username (if you have one)" = "ユーザーネームを入力 (持っていた場合)";
-
-/* No comment provided by engineer. */
-"Join us on Facebook" = "Facebookで参加する";
-
-/* No comment provided by engineer. */
-"Large" = "大きな";
-
-/* No comment provided by engineer. */
-"Large Floating Islands" = "大きな浮き島";
-
-/* No comment provided by engineer. */
-"Large Tunnels" = "大きなトンネル";
-
-/* No comment provided by engineer. */
-"Leave a positive review on iTunes!" = "iTunesでポジティブなレビューを残す!";
-
-/* No comment provided by engineer. */
-"Level" = "レベル";
-
-/* No comment provided by engineer. */
-"Loading..." = "ロード中...";
-
-/* from the settings table */
-"Main Configuration" = "メイン設定";
-
-/* No comment provided by engineer. */
-"Mark the death of your fallen warriors" = "あなたの倒れた戦士の死をマーク";
-
-/* No comment provided by engineer. */
-"Max Hogs:" = "ハリネズミの最大数:";
-
-/* No comment provided by engineer. */
-"Medium" = "中くらい";
-
-/* No comment provided by engineer. */
-"Medium Floating Islands" = "中くらいの浮き島";
-
-/* No comment provided by engineer. */
-"Medium Tunnels" = "中くらいのトンネル";
-
-/* No comment provided by engineer. */
-"Missing detail" = "詳細が抜けています";
-
-/* No comment provided by engineer. */
-"Missions don't need further configuration" = "ミッションはこれ以上の設定を必要としません";
-
-/* from the settings table */
-"Music" = "音楽";
-
-/* No comment provided by engineer. */
-"Names and Hats" = "ネームと帽子";
-
-/* from the settings table */
-"Nickname" = "ニックネーム";
-
-/* No comment provided by engineer. */
-"No filter" = "フィルターなし";
-
-/* No comment provided by engineer. */
-"No thanks" = "遠慮します";
-
-/* ammo selection */
-"Number of turns before you can use this weapon " = "この武器を使えるようになるまでのターン数";
-
-/* Short for 'Never' */
-"Nvr" = "絶対にない";
-
-/* No comment provided by engineer. */
-"Of course!" = "もちろん!";
-
-/* No comment provided by engineer. */
-"Ok, got it" = "Ok, わかった";
-
-/* No comment provided by engineer. */
-"Opt for controlling the team or let the AI lead" = "チームをコントロールするかAIをリードさせる";
-
-/* from the settings table */
-"Other Settings" = "ほかの設定";
-
-/* from the settings table */
-"Password" = "パスワード";
-
-/* No comment provided by engineer. */
-"Pick a slang your hogs will speak" = "あなたのハリネズミが話すスラングを選択";
-
-/* No comment provided by engineer. */
-"Playing Teams" = "プレー中のチーム";
-
-/* ammo selection */
-"Presence probability in crates " = "クレートの中の存在確率";
-
-/* No comment provided by engineer. */
-"Press to resume playing or swipe to delete the save file." = "押してプレーを再開するか、スワイプしてセーブファイルを削除。";
-
-/* No comment provided by engineer. */
-"Preview not available" = "プレビューが利用できません";
-
-/* ammo selection */
-"Quantity that you will find in a crate " = "クレーとの中で見つかる量";
-
-/* No comment provided by engineer. */
-"Remind me later" = "後で連絡";
-
-/* Short for 'Random' */
-"Rnd" = "ランダム";
-
-/* No comment provided by engineer. */
-"Save" = "保存";
-
-/* No comment provided by engineer. */
-"Scheme" = "スキーム";
-
-/* No comment provided by engineer. */
-"Scheme mismatch" = "スキームミスマッチ";
-
-/* No comment provided by engineer. */
-"Scheme Name" = "スキーム名";
-
-/* No comment provided by engineer. */
-"Schemes" = "スキーム";
-
-/* No comment provided by engineer. */
-"Select at least two teams to play a game" = "ゲームをプレーするには最低二チーム選択してください。";
-
-/* No comment provided by engineer. */
-"Select one Scheme and one Weapon for this game" = "このゲームのためにスキームと武器を一つずつ選択してください。";
-
-/* No comment provided by engineer. */
-"Select the team invincible fortress (only valid for fort games)" = "無敵砦のチームを選択する (砦ゲームのみ有効)";
-
-/* from the settings table */
-"Select which style of ammo menu you prefer" = "弾薬メニューのスタイルを選択してください";
-
-/* No comment provided by engineer. */
-"Set difficulty level" = "難易度レベルをセットする";
-
-/* No comment provided by engineer. */
-"Set hedgehog voices" = "ハリネズミの声をセットする";
-
-/* No comment provided by engineer. */
-"Set team flag" = "チームフラグをセットする";
-
-/* on the overlay */
-"Set!" = "セット!";
-
-/* No comment provided by engineer. */
-"Show Help" = "ヘルプを表示する";
-
-/* No comment provided by engineer. */
-"Small" = "小さい";
-
-/* No comment provided by engineer. */
-"Small Floating Islands" = "小さな浮き島";
-
-/* No comment provided by engineer. */
-"Small Tunnels" = "小さなトンネル";
-
-/* from the settings table */
-"Sound" = "サウンド";
-
-/* No comment provided by engineer. */
-"Style" = "スタイル";
-
-/* No comment provided by engineer. */
-"Support" = "サポート";
-
-/* No comment provided by engineer. */
-"Sync Schemes and Weapons" = "スキームと武器を同期する";
-
-/* No comment provided by engineer. */
-"Tag" = "タグ";
-
-/* No comment provided by engineer. */
-"Tap to add hogs or change color, touch and hold to remove a team." = "ハリネズミを追加するか色を変更するにはタップ、チームを取り除くにはタッチしてホールドしてください。";
-
-/* No comment provided by engineer. */
-"Team Name" = "チーム名";
-
-/* No comment provided by engineer. */
-"Team Preferences" = "チーム設定";
-
-/* No comment provided by engineer. */
-"Teams" = "チーム";
-
-/* No comment provided by engineer. */
-"The map is too small for that many hogs" = "このマップはこれだけのハリネズミには小さすぎます。";
-
-/* No comment provided by engineer. */
-"The robot badge indicates an AI-controlled team." = "ロボットバッジはAIがコントロールするチームを指します。";
-
-/* No comment provided by engineer. */
-"The scheme you selected allows only for two teams" = "選択したスキームは二チーム用です。";
-
-/* No comment provided by engineer. */
-"This weapon is locked" = "この武器はロックされています";
-
-/* No comment provided by engineer. */
-"Too few teams playing" = "プレーしているチームが少なすぎます";
-
-/* No comment provided by engineer. */
-"Too many hogs" = "ハリネズミが多すぎます";
-
-/* No comment provided by engineer. */
-"Too many teams" = "チームが多すぎます";
-
-/* No comment provided by engineer. */
-"Visit our website" = "ウェブサイトを見る";
-
-/* No comment provided by engineer. */
-"Voice" = "音量";
-
-/* No comment provided by engineer. */
-"Wacky" = "奇抜";
-
-/* No comment provided by engineer. */
-"Wait for the Preview" = "プレビューを待つ";
-
-/* No comment provided by engineer. */
-"Weaky" = "弱い者";
-
-/* No comment provided by engineer. */
-"Weapon" = "武器";
-
-/* No comment provided by engineer. */
-"Weapon Ammuntions" = "武器弾薬";
-
-/* No comment provided by engineer. */
-"Weapons" = "武器";
-
-/* No comment provided by engineer. */
-"Weaponset Name" = "武器セット名";
-
-/* No comment provided by engineer. */
-"Well, maybe not..." = "まあ、そうでないかもしれません...";
-
-/* No comment provided by engineer. */
-"Worldwide" = "ワールドワイド";
-
-/* No comment provided by engineer. */
-"You can add a description if you wish" = "お望みなら説明を追加することができます。";
-
-/* No comment provided by engineer. */
+/* No comment provided by engineer. */
+"A monitor has been disconnected while playing and this has ended the match! You need to restart the game if you wish to use the second display again." = "モニターの接続が切断され、マッチを終了してしまいました!二番目のディスプレーをまた使用したい場合はゲームをリスタートしなければいけません。";
+
+/* from the scheme panel
+   from the team panel */
+"Add" = "追加";
+
+/* No comment provided by engineer. */
+"Aggressive" = "積極的";
+
+/* No comment provided by engineer. */
+"All" = "全て";
+
+/* from the settings table */
+"Alternate Damage" = "代わりのダメージ";
+
+/* No comment provided by engineer. */
+"Are you reeeeeally sure?" = "本当にいいですか?";
+
+/* from the settings table */
+"Audio Preferences" = "オーディオ設定";
+
+/* No comment provided by engineer. */
+"Available Teams" = "利用可能なチーム";
+
+/* No comment provided by engineer. */
+"Average" = "平均";
+
+/* No comment provided by engineer. */
+"Backup" = "バックアップ";
+
+/* No comment provided by engineer. */
+"Before playing the preview needs to be generated" = "プレーする前にプレビューを生成する必要があります";
+
+/* No comment provided by engineer. */
+"Before returning the preview needs to be generated" = "戻る前にプレビューを生成する必要があります";
+
+/* No comment provided by engineer. */
+"Brutal" = "残忍";
+
+/* No comment provided by engineer. */
+"Bully" = "いじめっ子";
+
+/* No comment provided by engineer. */
+"Cancel" = "キャンセル";
+
+/* No comment provided by engineer. */
+"Cavern" = "洞窟";
+
+/* No comment provided by engineer. */
+"Change hedgehogs' hat" = "ハリネズミの帽子を変える";
+
+/* No comment provided by engineer. */
+"Chat with the devs in IRC" = "IRC でデベロッパ達とチャットする";
+
+/* No comment provided by engineer. */
+"Choose a charismatic symbol for your team" = "チームのためのカリスマ的なシンボルを選択する";
+
+/* No comment provided by engineer. */
+"Choose hedgehog graves" = "ハリネズミの墓を選択する";
+
+/* No comment provided by engineer. */
+"Choose team fort" = "チームの砦を選択する";
+
+/* from the settings table */
+"Choosing a Scheme will select its associated Weapon" = "スキームを選択すると関連した武器を選択します。";
+
+/* No comment provided by engineer. */
+"Classic Ammo Menu" = "クラシックな弾薬メニュー";
+
+/* No comment provided by engineer. */
+"Community" = "コミュニティー";
+
+/* from the settings table */
+"Damage popups will notify you on every single hit" = "ダメージポップアップはすべてのヒットを通知してくれます。";
+
+/* from the scheme panel
+   from the team panel */
+"Done" = "終了";
+
+/* from the scheme panel
+   from the team panel */
+"Edit" = "編集";
+
+/* No comment provided by engineer. */
+"Edit scheme preferences" = "スキーム設定を編集";
+
+/* No comment provided by engineer. */
+"Edit team settings" = "チーム設定を編集";
+
+/* No comment provided by engineer. */
+"Edit weapons preferences" = "武器設定を編集";
+
+/* No comment provided by engineer. */
+"End Game" = "ゲームを終了する";
+
+/* No comment provided by engineer. */
+"Flag" = "フラグ";
+
+/* No comment provided by engineer. */
+"Follow us on Twitter" = "ツイッターでフォローする";
+
+/* No comment provided by engineer. */
+"Fort" = "砦";
+
+/* No comment provided by engineer. */
+"Game Modifiers" = "ゲームの変更";
+
+/* No comment provided by engineer. */
+"Game Settings" = "ゲームの設定";
+
+/* No comment provided by engineer. */
+"General" = "一般";
+
+/* No comment provided by engineer. */
+"Grave" = "墓";
+
+/* No comment provided by engineer. */
+"Hedgewars supports multi-monitor configurations, but the screen has to be connected before launching the game." = "Hedgewarsはマルチモニター設定をサポートしていますが、スクリーンはゲームをスタートする前に接続されていなければいけません。";
+
+/* No comment provided by engineer. */
+"Hogs controlled by AI" = "AIにコントロールされたハリネズミ";
+
+/* No comment provided by engineer. */
+"Hold your finger on a weapon to see what it does.\nTap anywhere to dismiss." = "武器の上でホールドして何をするか見る。\nほかの部分をタップして閉じる。";
+
+/* No comment provided by engineer. */
+"Hold your finger on a weapon to see what it does.\nYou can move this window anywhere on the screen." = "武器の上でホールドして何をするか見る。\nこのウィンドウはスクリーンのどこにでも動かすことができます。";
+
+/* ammo selection */
+"Initial quantity " = "初期量";
+
+/* from the settings table */
+"Insert your password" = "パスワードを入力";
+
+/* from the settings table */
+"Insert your username (if you have one)" = "ユーザーネームを入力 (持っていた場合)";
+
+/* No comment provided by engineer. */
+"Join us on Facebook" = "Facebookで参加する";
+
+/* No comment provided by engineer. */
+"Large" = "大きな";
+
+/* No comment provided by engineer. */
+"Large Floating Islands" = "大きな浮き島";
+
+/* No comment provided by engineer. */
+"Large Tunnels" = "大きなトンネル";
+
+/* No comment provided by engineer. */
+"Leave a positive review on iTunes!" = "iTunesでポジティブなレビューを残す!";
+
+/* No comment provided by engineer. */
+"Level" = "レベル";
+
+/* No comment provided by engineer. */
+"Loading..." = "ロード中...";
+
+/* from the settings table */
+"Main Configuration" = "メイン設定";
+
+/* No comment provided by engineer. */
+"Mark the death of your fallen warriors" = "あなたの倒れた戦士の死をマーク";
+
+/* No comment provided by engineer. */
+"Max Hogs:" = "ハリネズミの最大数:";
+
+/* No comment provided by engineer. */
+"Medium" = "中くらい";
+
+/* No comment provided by engineer. */
+"Medium Floating Islands" = "中くらいの浮き島";
+
+/* No comment provided by engineer. */
+"Medium Tunnels" = "中くらいのトンネル";
+
+/* No comment provided by engineer. */
+"Missing detail" = "詳細が抜けています";
+
+/* No comment provided by engineer. */
+"Missions don't need further configuration" = "ミッションはこれ以上の設定を必要としません";
+
+/* from the settings table */
+"Music" = "音楽";
+
+/* No comment provided by engineer. */
+"Names and Hats" = "ネームと帽子";
+
+/* from the settings table */
+"Nickname" = "ニックネーム";
+
+/* No comment provided by engineer. */
+"No filter" = "フィルターなし";
+
+/* No comment provided by engineer. */
+"No thanks" = "遠慮します";
+
+/* ammo selection */
+"Number of turns before you can use this weapon " = "この武器を使えるようになるまでのターン数";
+
+/* Short for 'Never' */
+"Nvr" = "絶対にない";
+
+/* No comment provided by engineer. */
+"Of course!" = "もちろん!";
+
+/* No comment provided by engineer. */
+"Ok, got it" = "Ok, わかった";
+
+/* No comment provided by engineer. */
+"Opt for controlling the team or let the AI lead" = "チームをコントロールするかAIをリードさせる";
+
+/* from the settings table */
+"Other Settings" = "ほかの設定";
+
+/* from the settings table */
+"Password" = "パスワード";
+
+/* No comment provided by engineer. */
+"Pick a slang your hogs will speak" = "あなたのハリネズミが話すスラングを選択";
+
+/* No comment provided by engineer. */
+"Playing Teams" = "プレー中のチーム";
+
+/* ammo selection */
+"Presence probability in crates " = "クレートの中の存在確率";
+
+/* No comment provided by engineer. */
+"Press to resume playing or swipe to delete the save file." = "押してプレーを再開するか、スワイプしてセーブファイルを削除。";
+
+/* No comment provided by engineer. */
+"Preview not available" = "プレビューが利用できません";
+
+/* ammo selection */
+"Quantity that you will find in a crate " = "クレーとの中で見つかる量";
+
+/* No comment provided by engineer. */
+"Remind me later" = "後で連絡";
+
+/* Short for 'Random' */
+"Rnd" = "ランダム";
+
+/* No comment provided by engineer. */
+"Save" = "保存";
+
+/* No comment provided by engineer. */
+"Scheme" = "スキーム";
+
+/* No comment provided by engineer. */
+"Scheme mismatch" = "スキームミスマッチ";
+
+/* No comment provided by engineer. */
+"Scheme Name" = "スキーム名";
+
+/* No comment provided by engineer. */
+"Schemes" = "スキーム";
+
+/* No comment provided by engineer. */
+"Select at least two teams to play a game" = "ゲームをプレーするには最低二チーム選択してください。";
+
+/* No comment provided by engineer. */
+"Select one Scheme and one Weapon for this game" = "このゲームのためにスキームと武器を一つずつ選択してください。";
+
+/* No comment provided by engineer. */
+"Select the team invincible fortress (only valid for fort games)" = "無敵砦のチームを選択する (砦ゲームのみ有効)";
+
+/* from the settings table */
+"Select which style of ammo menu you prefer" = "弾薬メニューのスタイルを選択してください";
+
+/* No comment provided by engineer. */
+"Set difficulty level" = "難易度レベルをセットする";
+
+/* No comment provided by engineer. */
+"Set hedgehog voices" = "ハリネズミの声をセットする";
+
+/* No comment provided by engineer. */
+"Set team flag" = "チームフラグをセットする";
+
+/* on the overlay */
+"Set!" = "セット!";
+
+/* No comment provided by engineer. */
+"Show Help" = "ヘルプを表示する";
+
+/* No comment provided by engineer. */
+"Small" = "小さい";
+
+/* No comment provided by engineer. */
+"Small Floating Islands" = "小さな浮き島";
+
+/* No comment provided by engineer. */
+"Small Tunnels" = "小さなトンネル";
+
+/* from the settings table */
+"Sound" = "サウンド";
+
+/* No comment provided by engineer. */
+"Style" = "スタイル";
+
+/* No comment provided by engineer. */
+"Support" = "サポート";
+
+/* No comment provided by engineer. */
+"Sync Schemes and Weapons" = "スキームと武器を同期する";
+
+/* No comment provided by engineer. */
+"Tag" = "タグ";
+
+/* No comment provided by engineer. */
+"Tap to add hogs or change color, touch and hold to remove a team." = "ハリネズミを追加するか色を変更するにはタップ、チームを取り除くにはタッチしてホールドしてください。";
+
+/* No comment provided by engineer. */
+"Team Name" = "チーム名";
+
+/* No comment provided by engineer. */
+"Team Preferences" = "チーム設定";
+
+/* No comment provided by engineer. */
+"Teams" = "チーム";
+
+/* No comment provided by engineer. */
+"The map is too small for that many hogs" = "このマップはこれだけのハリネズミには小さすぎます。";
+
+/* No comment provided by engineer. */
+"The robot badge indicates an AI-controlled team." = "ロボットバッジはAIがコントロールするチームを指します。";
+
+/* No comment provided by engineer. */
+"The scheme you selected allows only for two teams" = "選択したスキームは二チーム用です。";
+
+/* No comment provided by engineer. */
+"This weapon is locked" = "この武器はロックされています";
+
+/* No comment provided by engineer. */
+"Too few teams playing" = "プレーしているチームが少なすぎます";
+
+/* No comment provided by engineer. */
+"Too many hogs" = "ハリネズミが多すぎます";
+
+/* No comment provided by engineer. */
+"Too many teams" = "チームが多すぎます";
+
+/* No comment provided by engineer. */
+"Visit our website" = "ウェブサイトを見る";
+
+/* No comment provided by engineer. */
+"Voice" = "音量";
+
+/* No comment provided by engineer. */
+"Wacky" = "奇抜";
+
+/* No comment provided by engineer. */
+"Wait for the Preview" = "プレビューを待つ";
+
+/* No comment provided by engineer. */
+"Weaky" = "弱い者";
+
+/* No comment provided by engineer. */
+"Weapon" = "武器";
+
+/* No comment provided by engineer. */
+"Weapon Ammuntions" = "武器弾薬";
+
+/* No comment provided by engineer. */
+"Weapons" = "武器";
+
+/* No comment provided by engineer. */
+"Weaponset Name" = "武器セット名";
+
+/* No comment provided by engineer. */
+"Well, maybe not..." = "まあ、そうでないかもしれません...";
+
+/* No comment provided by engineer. */
+"Worldwide" = "ワールドワイド";
+
+/* No comment provided by engineer. */
+"You can add a description if you wish" = "お望みなら説明を追加することができます。";
+
+/* No comment provided by engineer. */
 "You exceeded the maximum number of tems allowed in a game" = "ゲームで許可されているチームの最大数を超しました。";
\ No newline at end of file
--- a/project_files/HedgewarsMobile/Locale/Japanese.lproj/Scheme.strings	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/HedgewarsMobile/Locale/Japanese.lproj/Scheme.strings	Tue Jan 21 22:53:15 2014 +0100
@@ -1,194 +1,194 @@
-/* game mod description */
-"Land can not be destroyed" = "土地は破壊することができません";
-
-/* game mod title */
-"Solid Land" = "固形の土地";
-
-/* game mod description */
-"Add an indestructable border around the terrain" = "地形の周りに破壊できないボーダーを追加する";
-
-/* game mod title */
-"Add Border" = "ボーダーを追加する";
-
-/* game mod description */
-"Teams will start on opposite sides of the terrain" = "チームは地形の反対側からスタート思案す";
-
-/* game mod title */
-"Divide Team (max 2 teams)" = "チームを分ける (最大二チーム)";
-
-/* game mod description */
-"Lower gravity" = "低い重力";
-
-/* game mod title */
-"Low Gravity" = "低重力";
-
-/* game mod description */
-"Assisted aiming with laser sight" = "レーザーサイトで狙いの補助";
-
-/* game mod title */
-"Laser Sight" = "レーザーサイト";
-
-/* game mod description */
-"All hogs have a personal forcefield" = "全てのハリネズミは自分の力場を持っています";
-
-/* game mod title */
-"Invulnerable" = "無敵";
-
-/* game mod description */
-"All (living) hedgehogs are fully restored at the end of turn" = "全ての (生きている) ハリネズミの体力はターン終了時に完全に復元されます";
-
-/* game mod title */
-"Reset Health" = "体力をリセット";
-
-/* game mod description */
-"Gain 80% of the damage you do back in health" = "ダメージの80% を体力としてもらう";
-
-/* game mod title */
-"Vampirism Mode" = "吸血モード";
-
-/* game mod description */
-"Share your opponents pain, share their damage" = "相手の痛みを共有し、 ダメージを共有する";
-
-/* game mod title */
-"Karma Mode" = "カルマモード";
-
-/* game mod description */
-"Your hogs are unable to move, test your aim" = "あなたのハリネズミは動けない, 狙いを試せ";
-
-/* game mod title */
-"Artillery Mode" = "砲兵モード";
-
-/* game mod description */
-"Defend your fort and destroy the opponents" = "砦を守って相手を潰せ";
-
-/* game mod title */
-"Fort Mode" = "砦モード";
-
-/* game mod description */
-"Order of play is random instead of in room order" = "プレー順はルーム順ではなくランダムです";
-
-/* game mod title */
-"Random Order" = "ランダムオーダー";
-
-/* game mod description */
-"Play with a King; when he dies, your side loses" = "キングとプレーする; キングが死ぬと、あなたの負けです";
-
-/* game mod title */
-"King Mode" = "キングモード";
-
-/* game mod description */
-"Take turns placing your hedgehogs pre-game" = "ゲームの前にターンを取ってハリネズミを置く";
-
-/* game mod title */
-"Place Hedgehogs" = "ハリネズミを置く";
-
-/* game mod description */
-"Ammo is shared between all clan teams" = "弾薬は全ての一族チームの間で共有されます";
-
-/* game mod title */
-"Clan Shares Ammo" = "一族は弾薬を共有します";
-
-/* game mod description */
-"Disable girders when generating random maps" = "ランダムマップを作成するときはガードを無効にする";
-
-/* game mod title */
-"Disable Girders" = "ガードを無効にする";
-
-/* game mod description */
-"Disable land objects when generating maps" = "マップ作成中は土地のオブジェクトを無効にする";
-
-/* game mod title */
-"Disable Land Objects" = "土地のオブジェクトを無効にする";
-
-/* game mod description */
-"AI-controlled hogs respawn on death" = "AIがコントロールするハリネズミは死ぬと再出現します";
-
-/* game mod title */
-"AI Survival Mode" = "AI サバイバルモード";
-
-/* game mod description */
-"Attacking does not end your turn" = "攻撃してもターンは終了しません";
-
-/* game mod title */
-"Unlimited Attacks" = "無限攻撃";
-
-/* game mod description */
-"Weapons are reset to starting values each turn" = "武器は毎ターン初期値にリセットされます";
-
-/* game mod title */
-"Reset Weapons" = "武器をリセット";
-
-/* game mod description */
-"Each hedgehog has its own ammo" = "各ハリネズミが自分の弾薬を持っています";
-
-/* game mod title */
-"Per Hedgehog Ammo" = "ハリネズミあたりの弾薬";
-
-/* game mod description */
-"You will not have to worry about wind any more" = "風のことは気にせずに良くなります";
-
-/* game mod title */
-"Disable Wind" = "風を無効にする";
-
-/* game mod description */
-"Wind will affect almost everything" = "風はほとんどのものに影響します";
-
-/* game mod title */
-"More Wind" = "より強い風";
-
-/* game mod description */
-"Clan teams take turns sharing their time" = "一族のチームはタイムを共有してターンを取ります";
-
-/* game mod title */
-"Tag Team" = "タッグチーム";
-
-/* game mod description */
-"Add an indestructible border along the bottom" = "破壊できないボーダーを下に追加する";
-
-/* game mod title */
-"Bottom Border" = "ボトムボーダー";
-
-
-/* flag description */
-"Initial Health" = "初期体力";
-
-/* flag description */
-"Damage Modifier" = "ダメージ変更";
-
-/* flag description */
-"Turn Time" = "ターンタイム";
-/* flag description */
-"Sudden Death Timeout" = "サデン・デス タイムアウト";
-
-/* flag description */
-"Water Rise Amount" = "水位上昇量";
-
-/* flag description */
-"Health Decrease" = "体力の減少";
-
-/* flag description */
-"Rope Length (%)" = "ロープの長さ (%)";
-
-/* flag description */
-"Crate Drop Turns" = "クレートドロップターン";
-
-/* flag description */
-"Health Kit Probability (%)" = "体力キットの確率 (%)";
-
-/* flag description */
-"Health Amount in Kit" = "キットの体力量";
-
-/* flag description */
-"Mines Time" = "地雷タイム";
-
-/* flag description */
-"Mines Number" = "地雷ナンバー";
-
-/* flag description */
-"Dud Mines Probability (%)" = "不発地雷の確率(%)";
-
-/* flag description */
-"Explosives" = "爆発物";
-
-/* flag description */
+/* game mod description */
+"Land can not be destroyed" = "土地は破壊することができません";
+
+/* game mod title */
+"Solid Land" = "固形の土地";
+
+/* game mod description */
+"Add an indestructable border around the terrain" = "地形の周りに破壊できないボーダーを追加する";
+
+/* game mod title */
+"Add Border" = "ボーダーを追加する";
+
+/* game mod description */
+"Teams will start on opposite sides of the terrain" = "チームは地形の反対側からスタート思案す";
+
+/* game mod title */
+"Divide Team (max 2 teams)" = "チームを分ける (最大二チーム)";
+
+/* game mod description */
+"Lower gravity" = "低い重力";
+
+/* game mod title */
+"Low Gravity" = "低重力";
+
+/* game mod description */
+"Assisted aiming with laser sight" = "レーザーサイトで狙いの補助";
+
+/* game mod title */
+"Laser Sight" = "レーザーサイト";
+
+/* game mod description */
+"All hogs have a personal forcefield" = "全てのハリネズミは自分の力場を持っています";
+
+/* game mod title */
+"Invulnerable" = "無敵";
+
+/* game mod description */
+"All (living) hedgehogs are fully restored at the end of turn" = "全ての (生きている) ハリネズミの体力はターン終了時に完全に復元されます";
+
+/* game mod title */
+"Reset Health" = "体力をリセット";
+
+/* game mod description */
+"Gain 80% of the damage you do back in health" = "ダメージの80% を体力としてもらう";
+
+/* game mod title */
+"Vampirism Mode" = "吸血モード";
+
+/* game mod description */
+"Share your opponents pain, share their damage" = "相手の痛みを共有し、 ダメージを共有する";
+
+/* game mod title */
+"Karma Mode" = "カルマモード";
+
+/* game mod description */
+"Your hogs are unable to move, test your aim" = "あなたのハリネズミは動けない, 狙いを試せ";
+
+/* game mod title */
+"Artillery Mode" = "砲兵モード";
+
+/* game mod description */
+"Defend your fort and destroy the opponents" = "砦を守って相手を潰せ";
+
+/* game mod title */
+"Fort Mode" = "砦モード";
+
+/* game mod description */
+"Order of play is random instead of in room order" = "プレー順はルーム順ではなくランダムです";
+
+/* game mod title */
+"Random Order" = "ランダムオーダー";
+
+/* game mod description */
+"Play with a King; when he dies, your side loses" = "キングとプレーする; キングが死ぬと、あなたの負けです";
+
+/* game mod title */
+"King Mode" = "キングモード";
+
+/* game mod description */
+"Take turns placing your hedgehogs pre-game" = "ゲームの前にターンを取ってハリネズミを置く";
+
+/* game mod title */
+"Place Hedgehogs" = "ハリネズミを置く";
+
+/* game mod description */
+"Ammo is shared between all clan teams" = "弾薬は全ての一族チームの間で共有されます";
+
+/* game mod title */
+"Clan Shares Ammo" = "一族は弾薬を共有します";
+
+/* game mod description */
+"Disable girders when generating random maps" = "ランダムマップを作成するときはガードを無効にする";
+
+/* game mod title */
+"Disable Girders" = "ガードを無効にする";
+
+/* game mod description */
+"Disable land objects when generating maps" = "マップ作成中は土地のオブジェクトを無効にする";
+
+/* game mod title */
+"Disable Land Objects" = "土地のオブジェクトを無効にする";
+
+/* game mod description */
+"AI-controlled hogs respawn on death" = "AIがコントロールするハリネズミは死ぬと再出現します";
+
+/* game mod title */
+"AI Survival Mode" = "AI サバイバルモード";
+
+/* game mod description */
+"Attacking does not end your turn" = "攻撃してもターンは終了しません";
+
+/* game mod title */
+"Unlimited Attacks" = "無限攻撃";
+
+/* game mod description */
+"Weapons are reset to starting values each turn" = "武器は毎ターン初期値にリセットされます";
+
+/* game mod title */
+"Reset Weapons" = "武器をリセット";
+
+/* game mod description */
+"Each hedgehog has its own ammo" = "各ハリネズミが自分の弾薬を持っています";
+
+/* game mod title */
+"Per Hedgehog Ammo" = "ハリネズミあたりの弾薬";
+
+/* game mod description */
+"You will not have to worry about wind any more" = "風のことは気にせずに良くなります";
+
+/* game mod title */
+"Disable Wind" = "風を無効にする";
+
+/* game mod description */
+"Wind will affect almost everything" = "風はほとんどのものに影響します";
+
+/* game mod title */
+"More Wind" = "より強い風";
+
+/* game mod description */
+"Clan teams take turns sharing their time" = "一族のチームはタイムを共有してターンを取ります";
+
+/* game mod title */
+"Tag Team" = "タッグチーム";
+
+/* game mod description */
+"Add an indestructible border along the bottom" = "破壊できないボーダーを下に追加する";
+
+/* game mod title */
+"Bottom Border" = "ボトムボーダー";
+
+
+/* flag description */
+"Initial Health" = "初期体力";
+
+/* flag description */
+"Damage Modifier" = "ダメージ変更";
+
+/* flag description */
+"Turn Time" = "ターンタイム";
+/* flag description */
+"Sudden Death Timeout" = "サデン・デス タイムアウト";
+
+/* flag description */
+"Water Rise Amount" = "水位上昇量";
+
+/* flag description */
+"Health Decrease" = "体力の減少";
+
+/* flag description */
+"Rope Length (%)" = "ロープの長さ (%)";
+
+/* flag description */
+"Crate Drop Turns" = "クレートドロップターン";
+
+/* flag description */
+"Health Kit Probability (%)" = "体力キットの確率 (%)";
+
+/* flag description */
+"Health Amount in Kit" = "キットの体力量";
+
+/* flag description */
+"Mines Time" = "地雷タイム";
+
+/* flag description */
+"Mines Number" = "地雷ナンバー";
+
+/* flag description */
+"Dud Mines Probability (%)" = "不発地雷の確率(%)";
+
+/* flag description */
+"Explosives" = "爆発物";
+
+/* flag description */
 "Get Away Time (%)" = "脱出タイム (%)";
\ No newline at end of file
--- a/project_files/HedgewarsMobile/Locale/hw-desc_ja.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/HedgewarsMobile/Locale/hw-desc_ja.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,28 +1,28 @@
-
-Hedgewars, ブラストだ!
-
-Hedgewars が Mac アップストアに登場! Mac で Hedgewars を検索して無料コピーを今すぐダウンロードしよう!
-
-iOS ポートはいくつかの限定フィーチャーがあります。例えば:
-* iPad VGA アウト: 外部ディスプレイを接続してフル解像度でプレー
-* Retina ディスrプレイサポート: ゲームの全てを高い解像度でプレー;
-* マルチタスキング: いつでもゲームをポーズ;
-* ゲームリストア: あなたは何が何でもマッチを完成させることができます。
-
-説明:
-これはあなたが遊ぶ一番面白くて依存症のあるゲームです - いつでも、どこでも楽しめる陽気な楽しみ。 Hedgewars はターン制ストラテジーゲームですが、本当の楽しみはあの厄介なハリネズミがすばらしい武器を使って起こす破壊を見ることです - 悪い態度の小さな厄介者!
-
-言い換えれば、 Hedgewars はターン製ストラテジー、砲兵、アクションとコメディゲームで、地獄から宇宙まで 悪ふざけをするピンクのハリネズミが特色です。
-
-司令官としてのあなたの役目はハリネズミ兵のチームを編成し、敵に戦争を持ってゆくことです。
-
-プレイヤーはそれぞれ複数のハリネズミをコントロールします。ゲーム中は、ハリネズミの一つを使って交代します。利用可能な武器や道具を使って敵のハリネズミを攻撃して殺し、勝利を取ります。
-Hedgehogs は地形をさまざまな方法で動き回ります。普段は歩いたりジャンプしたりしますが、"ロープ"や"パラシュート"などの特定の道具を使って本来なら届かないエリアに移動することができます。ターンはプレイヤーが動いたいり考えたりする時間をとり過ぎないようにタイムリミットがかかっています。ゲーム中はさまざまな道具や武器が使えます:手榴弾、クラスター爆弾、UFO、ショットガン、デザートイーグル、ファイアーパンチ、野球バット、ダイナマイト、地雷、ロープ、ニューマチックピックやパラシュートです。ほとんどの武器は、使用時に、地形を変える爆発を起こします。地形は水の上に浮かんでいる島か、下に水がある洞窟です。ハリネズミは水の中に入るか(島から落ちるか、穴を通って)、アリーナの横から落とされるか、爆発などで体力がゼロに減ると(プレーヤーやCPUのターンのダメージは全ての動きが止まった後表示されます)死んでしまいます。
-
-* 六人までの陽気と壊滅的なターン制コンバット
-* AIも追加可能なローカルとネットワーク上のマルチプレーヤー
-* ランダムで作成された無限のマップと二十以上の環境の中で戦おう
-* 48(上昇中)の圧倒的な武器を使おう!ピアノストライクと爆発的なロボットケーキも含みます。
-* 二十種類以上のゲーム修飾法で戦いのほとんどの部分を微調整して自分のやり方でプレーしよう
-* 120以上のコスチューム、30以上の墓、12以上の砦、100以上のフラグやユニークなボイスパックでチームをカスタマイズ
+
+Hedgewars, ブラストだ!
+
+Hedgewars が Mac アップストアに登場! Mac で Hedgewars を検索して無料コピーを今すぐダウンロードしよう!
+
+iOS ポートはいくつかの限定フィーチャーがあります。例えば:
+* iPad VGA アウト: 外部ディスプレイを接続してフル解像度でプレー
+* Retina ディスrプレイサポート: ゲームの全てを高い解像度でプレー;
+* マルチタスキング: いつでもゲームをポーズ;
+* ゲームリストア: あなたは何が何でもマッチを完成させることができます。
+
+説明:
+これはあなたが遊ぶ一番面白くて依存症のあるゲームです - いつでも、どこでも楽しめる陽気な楽しみ。 Hedgewars はターン制ストラテジーゲームですが、本当の楽しみはあの厄介なハリネズミがすばらしい武器を使って起こす破壊を見ることです - 悪い態度の小さな厄介者!
+
+言い換えれば、 Hedgewars はターン製ストラテジー、砲兵、アクションとコメディゲームで、地獄から宇宙まで 悪ふざけをするピンクのハリネズミが特色です。
+
+司令官としてのあなたの役目はハリネズミ兵のチームを編成し、敵に戦争を持ってゆくことです。
+
+プレイヤーはそれぞれ複数のハリネズミをコントロールします。ゲーム中は、ハリネズミの一つを使って交代します。利用可能な武器や道具を使って敵のハリネズミを攻撃して殺し、勝利を取ります。
+Hedgehogs は地形をさまざまな方法で動き回ります。普段は歩いたりジャンプしたりしますが、"ロープ"や"パラシュート"などの特定の道具を使って本来なら届かないエリアに移動することができます。ターンはプレイヤーが動いたいり考えたりする時間をとり過ぎないようにタイムリミットがかかっています。ゲーム中はさまざまな道具や武器が使えます:手榴弾、クラスター爆弾、UFO、ショットガン、デザートイーグル、ファイアーパンチ、野球バット、ダイナマイト、地雷、ロープ、ニューマチックピックやパラシュートです。ほとんどの武器は、使用時に、地形を変える爆発を起こします。地形は水の上に浮かんでいる島か、下に水がある洞窟です。ハリネズミは水の中に入るか(島から落ちるか、穴を通って)、アリーナの横から落とされるか、爆発などで体力がゼロに減ると(プレーヤーやCPUのターンのダメージは全ての動きが止まった後表示されます)死んでしまいます。
+
+* 六人までの陽気と壊滅的なターン制コンバット
+* AIも追加可能なローカルとネットワーク上のマルチプレーヤー
+* ランダムで作成された無限のマップと二十以上の環境の中で戦おう
+* 48(上昇中)の圧倒的な武器を使おう!ピアノストライクと爆発的なロボットケーキも含みます。
+* 二十種類以上のゲーム修飾法で戦いのほとんどの部分を微調整して自分のやり方でプレーしよう
+* 120以上のコスチューム、30以上の墓、12以上の砦、100以上のフラグやユニークなボイスパックでチームをカスタマイズ
 * 64体までの広大な戦い
\ No newline at end of file
--- a/project_files/cmdlineClient/cmdlineClient.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/cmdlineClient/cmdlineClient.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,475 +1,475 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include <frontlib.h>
-#include <util/logging.h>
-#include <util/util.h>
-#include <base64/base64.h>
-#include <model/schemelist.h>
-
-#include <stdlib.h>
-#include <stdbool.h>
-#include <assert.h>
-#include <string.h>
-#include <conio.h>
-#include <windows.h>
-
-#define ENGINE_DIR ".\\"
-#define CONFIG_DIR "..\\share\\hedgewars"
-#define DATA_DIR CONFIG_DIR"\\Data"
-
-static flib_netconn *netconn;
-static flib_gameconn *gameconn;
-static flib_mapconn *mapconn;
-static char nickname[128];
-static flib_metascheme *metacfg;
-static bool netConnected = false;
-
-// Callback function that will be called when the map is rendered
-static void handleMapGenerated(void *context, const uint8_t *bitmap, int numHedgehogs) {
-	printf("Drawing map for %i brave little hogs...", numHedgehogs);
-
-	// Draw the map as ASCII art
-	for(int y=0; y<MAPIMAGE_HEIGHT; y+=8) {
-		for(int x=0; x<MAPIMAGE_WIDTH; x+=6) {
-			int pixelnum = x + y*MAPIMAGE_WIDTH;
-			bool pixel = bitmap[pixelnum>>3] & (1<<(7-(pixelnum&7)));
-			printf(pixel ? "#" : " ");
-		}
-		printf("\n");
-	}
-
-	flib_mapconn_destroy(mapconn);
-	mapconn = NULL;
-}
-
-static void onGameDisconnect(void *context, int reason) {
-	flib_log_i("Connection closed. Reason: %i", reason);
-	flib_gameconn_destroy(gameconn);
-	gameconn = NULL;
-	if(netconn) {
-		flib_netconn_send_roundfinished(netconn, reason==GAME_END_FINISHED);
-	}
-}
-
-// Callback function that will be called on error
-static void handleMapFailure(void *context, const char *errormessage) {
-	flib_log_e("Map rendering failed: %s", errormessage);
-	flib_mapconn_destroy(mapconn);
-	mapconn = NULL;
-}
-
-static void startEngineMap(int port) {
-	char cmdbuffer[255];
-	char argbuffer[255];
-	snprintf(cmdbuffer, 255, "%shwengine.exe", ENGINE_DIR);
-	snprintf(argbuffer, 255, "%s %i landpreview", CONFIG_DIR, port);
-	ShellExecute(NULL, NULL, cmdbuffer, argbuffer, NULL, SW_HIDE);
-}
-
-static void startEngineGame(int port) {
-	char cmdbuffer[255];
-	char argbuffer[255];
-	char base64PlayerName[255];
-	base64_encode(nickname, strlen(nickname), base64PlayerName, sizeof(base64PlayerName));
-	snprintf(cmdbuffer, 255, "%shwengine.exe", ENGINE_DIR);
-	snprintf(argbuffer, 255, "%s 1024 768 32 %i 0 0 0 10 10 %s 0 0 %s 0 0 en.txt", CONFIG_DIR, port, DATA_DIR, base64PlayerName);
-	ShellExecute(NULL, NULL, cmdbuffer, argbuffer, NULL, SW_HIDE);
-}
-
-void handleNetDisconnect(void *context, int reason, const char *message) {
-	printf("Disconnected: %s", message);
-	flib_netconn_destroy(netconn);
-	netconn = NULL;
-}
-
-/*void printRoomList() {
-	const flib_roomlist *roomlist = flib_netconn_get_roomlist(netconn);
-	if(roomlist) {
-		if(roomlist->roomCount>0) {
-			for(int i=0; i<roomlist->roomCount; i++) {
-				if(i>0) {
-					printf(", ");
-				}
-				flib_room *room = roomlist->rooms[i];
-				printf("%s", room->name);
-			}
-		} else {
-			puts("Unfortunately, there are no rooms at the moment.");
-		}
-	} else {
-		puts("Sorry, due to an error the room list is not available.");
-	}
-	puts("\n");
-}*/
-
-void printTeamList() {
-	flib_gamesetup *setup = flib_netconn_create_gamesetup(netconn);
-	if(setup) {
-		puts("The following teams are in this room:");
-		for(int i=0; i<setup->teamlist->teamCount; i++) {
-			if(i>0) {
-				printf(", ");
-			}
-			printf("%s", setup->teamlist->teams[i]->name);
-		}
-		puts("\n");
-	} else {
-		puts("Sorry, due to an error the team list is not available.");
-	}
-	flib_gamesetup_destroy(setup);
-}
-
-void handleNetConnected(void *context) {
-	printf("You enter the lobby of a strange house inhabited by hedgehogs. Looking around, you see hallways branching off to these rooms:\n");
-	//printRoomList();
-	printf("\n\nNow, you can chat by just entering text, or join a room with /join <roomname>.");
-	printf(" You can also /quit or let me /describe <roomname>. Once in a room, you can /add <teamname> and set yourself /ready. You can also /list the available rooms (in the lobby) or the teams (in a room).\n");
-	netConnected = true;
-}
-
-void handleChat(void *context, const char *nick, const char *msg) {
-	if(gameconn) {
-		flib_gameconn_send_chatmsg(gameconn, nick, msg);
-	}
-	printf("%s: %s\n", nick, msg);
-}
-
-void handleEnterRoom(void *context, bool isChief) {
-	puts("You have entered the room.");
-}
-
-void handleRoomJoin(void *context, const char *nick) {
-	if(strcmp(nick, nickname)) {
-		printf("%s is here.\n", nick);
-	}
-}
-
-void handleRoomLeave(void *context, const char *nick, const char *partmsg) {
-	if(strcmp(nick, nickname)) {
-		printf("%s leaves.\n", nick);
-	}
-}
-
-void handleReady(void *context, const char *nick, bool ready) {
-	if(strcmp(nick, nickname)) {
-		if(ready) {
-			printf("%s is ready to go.\n", nick);
-		} else {
-			printf("%s is not ready.\n", nick);
-		}
-	} else {
-		if(ready) {
-			printf("You are ready to go.\n");
-		} else {
-			printf("You are not ready.\n");
-		}
-	}
-}
-
-void handleEmFromNet(void *context, const uint8_t *em, size_t size) {
-	if(gameconn) {
-		flib_gameconn_send_enginemsg(gameconn, em, size);
-	}
-}
-
-void handleEmFromEngine(void *context, const uint8_t *em, size_t size) {
-	if(netconn) {
-		flib_netconn_send_engineMessage(netconn, em, size);
-	}
-}
-
-void handleChatFromGame(void *context, const char *message, bool teamchat) {
-	if(netconn) {
-		if(teamchat) {
-			flib_netconn_send_teamchat(netconn, message);
-		} else {
-			flib_netconn_send_chat(netconn, message);
-		}
-	}
-}
-
-void handleRunGame(void *context) {
-	flib_gamesetup *gamesetup = flib_netconn_create_gamesetup(netconn);
-	if(gameconn) {
-		flib_log_e("Request to start game, but a game is already running.");
-	} else if(gamesetup) {
-		gameconn = flib_gameconn_create(nickname, gamesetup, true);
-		flib_gameconn_onEngineMessage(gameconn, handleEmFromEngine, NULL);
-		flib_gameconn_onDisconnect(gameconn, onGameDisconnect, NULL);
-		flib_gameconn_onChat(gameconn, handleChatFromGame, NULL);
-		startEngineGame(flib_gameconn_getport(gameconn));
-	}
-	flib_gamesetup_destroy(gamesetup);
-}
-
-void handleNickTaken(void *context, const char *nick) {
-	printf("The nickname %s is already in use, please choose a different one:\n", nick);
-	flib_gets(nickname, sizeof(nickname));
-	flib_netconn_send_nick(netconn, nickname);
-}
-
-void handlePwRequest(void *context, const char *nick) {
-	printf("A password is required to log in as %s, please enter (warning: shown in cleartext):\n", nick);
-	char password[256];
-	flib_gets(password, sizeof(password));
-	flib_netconn_send_password(netconn, password);
-}
-
-void handleMessage(void *context, int type, const char *msg) {
-	if(gameconn) {
-		flib_gameconn_send_textmsg(gameconn, 1, msg);
-	}
-	printf("*** %s\n", msg);
-}
-
-void handleTeamAccepted(void *context, const char *teamname) {
-	printf("The team %s has been accepted.\n", teamname);
-}
-
-void handleMapChanged(void *context, const flib_map *map, int changetype) {
-	if(map->mapgen != MAPGEN_NAMED && changetype != NETCONN_MAPCHANGE_THEME) {
-		if(mapconn) {
-			flib_mapconn_destroy(mapconn);
-			mapconn = NULL;
-		}
-		mapconn = flib_mapconn_create(map);
-		if(mapconn) {
-			flib_mapconn_onSuccess(mapconn, handleMapGenerated, NULL);
-			flib_mapconn_onFailure(mapconn, handleMapFailure, NULL);
-			startEngineMap(flib_mapconn_getport(mapconn));
-		}
-	} else if(map->mapgen == MAPGEN_NAMED) {
-		printf("The map %s has been selected.\n", map->name);
-	}
-}
-
-void handleLeaveRoom(void *context, int reason, const char *msg) {
-	if(reason == NETCONN_ROOMLEAVE_ABANDONED) {
-		printf("The chief has abandoned the room.");
-	} else if(reason == NETCONN_ROOMLEAVE_KICKED) {
-		printf("You have been kicked from the room.");
-	}
-	if(msg) {
-		printf(" (%s)", msg);
-	}
-	puts(" You are back in the lobby.");
-}
-
-void handleSchemeChanged(void *context, const flib_scheme *scheme) {
-	printf("Game scheme: %s.\n", scheme->name);
-}
-
-void handleWeaponsetChanged(void *context, const flib_weaponset *weaponset) {
-	printf("Weaponset: %s.\n", weaponset->name);
-}
-
-void handleHogcountChanged(void *context, const char *team, int count) {
-	printf("Team %s will send %i hogs into the fight.\n", team, count);
-}
-
-void handleRoomAdd(void *context, const flib_room *room) {
-	printf("%s created a new room called %s.\n", room->owner, room->name);
-}
-
-void handleRoomDelete(void *context, const char *roomName) {
-	printf("The room %s has collapsed.\n", roomName);
-}
-
-void handleScriptChanged(void *context, const char *script) {
-	printf("Game Type: %s\n", script);
-}
-
-void handleTeamAdd(void *context, const flib_team *team) {
-	printf("%s puts the team %s to the planning board.\n", team->ownerName, team->name);
-}
-
-void handleTeamDelete(void *context, const char *teamName) {
-	printf("The team %s decided not to fight this battle after all.\n", teamName);
-}
-
-void handleTeamColorChanged(void *context, const char *name, int colorIndex) {
-	static const char* colorNames[] = {"red", "blue", "teal", "purple", "pink", "green", "orange", "brown", "yellow"};
-	const char *colorName = "strange";
-	if(colorIndex>=0 && colorIndex < 9) {
-		colorName = colorNames[colorIndex];
-	}
-	printf("The team %s will wear %s uniforms today.\n", name, colorName);
-}
-
-void tick() {
-	if(gameconn) {
-		flib_gameconn_tick(gameconn);
-	}
-	if(netconn) {
-		flib_netconn_tick(netconn);
-	}
-	if(mapconn) {
-		flib_mapconn_tick(mapconn);
-	}
-}
-
-static HANDLE hStdin;
-
-static int init() {
-	hStdin = GetStdHandle(STD_INPUT_HANDLE);
-	if(hStdin == INVALID_HANDLE_VALUE) {
-		flib_log_e("Unable to get stdin handle");
-		return 1;
-	}
-	if(!flib_init(0)) {
-		flib_log_setLevel(FLIB_LOGLEVEL_WARNING);
-		freopen( "CON", "w", stdout );
-		freopen( "CON", "w", stderr );
-		metacfg = flib_metascheme_from_ini("metasettings.ini");
-		if(!metacfg) {
-			flib_quit();
-			return -1;
-		} else {
-			return 0;
-		}
-	}
-	return -1;
-}
-
-int main(int argc, char *argv[]) {
-	if(init()) {
-		return -1;
-	}
-
-	puts("Please enter a nickname:");
-	flib_gets(nickname, sizeof(nickname));
-
-	netconn = flib_netconn_create(nickname, metacfg, DATA_DIR"\\", "140.247.62.101", 46631);
-	if(!netconn) {
-		flib_quit();
-		return -1;
-	}
-
-	flib_netconn_onConnected(netconn, handleNetConnected, NULL);
-	flib_netconn_onDisconnected(netconn, handleNetDisconnect, NULL);
-	flib_netconn_onChat(netconn, handleChat, NULL);
-	flib_netconn_onEnterRoom(netconn, handleEnterRoom, NULL);
-	flib_netconn_onRunGame(netconn, handleRunGame, NULL);
-	flib_netconn_onEngineMessage(netconn, handleEmFromNet, NULL);
-	flib_netconn_onRoomJoin(netconn, handleRoomJoin, NULL);
-	flib_netconn_onRoomLeave(netconn, handleRoomLeave, NULL);
-	flib_netconn_onReadyState(netconn, handleReady, NULL);
-	flib_netconn_onNickTaken(netconn, handleNickTaken, NULL);
-	flib_netconn_onPasswordRequest(netconn, handlePwRequest, NULL);
-	flib_netconn_onMessage(netconn, handleMessage, NULL);
-	flib_netconn_onTeamAccepted(netconn, handleTeamAccepted, NULL);
-	flib_netconn_onMapChanged(netconn, handleMapChanged, NULL);
-	flib_netconn_onLeaveRoom(netconn, handleLeaveRoom, NULL);
-	flib_netconn_onCfgScheme(netconn, handleSchemeChanged, NULL);
-	flib_netconn_onWeaponsetChanged(netconn, handleWeaponsetChanged, NULL);
-	flib_netconn_onHogCountChanged(netconn, handleHogcountChanged, NULL);
-	flib_netconn_onRoomAdd(netconn, handleRoomAdd, NULL);
-	flib_netconn_onRoomDelete(netconn, handleRoomDelete, NULL);
-	flib_netconn_onScriptChanged(netconn, handleScriptChanged, NULL);
-	flib_netconn_onTeamAdd(netconn, handleTeamAdd, NULL);
-	flib_netconn_onTeamDelete(netconn, handleTeamDelete, NULL);
-	flib_netconn_onTeamColorChanged(netconn, handleTeamColorChanged, NULL);
-
-	INPUT_RECORD inputRecord;
-	DWORD eventCount = 0;
-
-	while(netconn || gameconn) {
-		tick();
-		if(netconn && netConnected) {
-			while(PeekConsoleInput(hStdin, &inputRecord, 1, &eventCount) && eventCount>0) {
-				if(inputRecord.EventType != KEY_EVENT) {
-					ReadConsoleInput(hStdin, &inputRecord, 1, &eventCount);
-				} else {
-					printf("%s: ", nickname);
-					char input[256];
-					if(!flib_gets(input, sizeof(input))) {
-						if(!memcmp("/quit", input, strlen("/quit"))) {
-							flib_netconn_send_quit(netconn, "Player quit.");
-						} else if(!memcmp("/describe ", input, strlen("/describe "))) {
-							const char *roomname = input+strlen("/describe ");
-							/*const flib_roomlist *roomlist = flib_netconn_get_roomlist(netconn);
-							flib_room *room = flib_roomlist_find(roomlist, roomname);
-							if(!room) {
-								puts("Unknown room.");
-							} else {
-								char *text = flib_asprintf(
-										"%s is a room created by %s, where %i players (%i teams) are %s on %s%s, using the %s scheme and %s weaponset.",
-										room->name,
-										room->owner,
-										room->playerCount,
-										room->teamCount,
-										room->inProgress ? "fighting" : "preparing to fight",
-										room->map[0]=='+' ? "" : "the map ",
-										!strcmp("+rnd+", room->map) ? "a random map" :
-												!strcmp("+maze+", room->map) ? "a random maze" :
-												!strcmp("+drawn+", room->map) ? "a hand-drawn map" :
-												room->map,
-										room->scheme,
-										room->weapons);
-								if(text) {
-									puts(text);
-								}
-								free(text);
-							}*/
-						} else if(!memcmp("/join ", input, strlen("/join "))) {
-							const char *roomname = input+strlen("/join ");
-							flib_netconn_send_joinRoom(netconn, roomname);
-						} else if(!memcmp("/ready", input, strlen("/ready"))) {
-							flib_netconn_send_toggleReady(netconn);
-						} else if(!memcmp("/loglevel ", input, strlen("/loglevel "))) {
-							int loglevel = atoi(input+strlen("/loglevel "));
-							flib_log_setLevel(loglevel);
-						} else if(!memcmp("/list", input, strlen("/list"))) {
-							if(flib_netconn_is_in_room_context(netconn)) {
-								printTeamList();
-							} else {
-								puts("From this big and expansive lobby, hallways branch off to these rooms:");
-								//printRoomList();
-							}
-						} else if(!memcmp("/addteam ", input, strlen("/addteam "))) {
-							const char *teamname = input+strlen("/addteam ");
-							if(!flib_contains_dir_separator(teamname)) {
-								char *teamfilename = flib_asprintf("%s.hwt", teamname);
-								if(teamfilename) {
-									flib_team *team = flib_team_from_ini(teamfilename);
-									if(team) {
-										flib_netconn_send_addTeam(netconn, team);
-									} else {
-										printf("Teamfile %s not found.\n", teamfilename);
-									}
-									flib_team_destroy(team);
-								}
-								free(teamfilename);
-							}
-						} else if(strlen(input)>0) {
-							flib_netconn_send_chat(netconn, input);
-						}
-					}
-				}
-			}
-		}
-		fflush(stdout);
-		Sleep(10);
-	}
-
-
-	flib_metascheme_release(metacfg);
-	return 0;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include <frontlib.h>
+#include <util/logging.h>
+#include <util/util.h>
+#include <base64/base64.h>
+#include <model/schemelist.h>
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <string.h>
+#include <conio.h>
+#include <windows.h>
+
+#define ENGINE_DIR ".\\"
+#define CONFIG_DIR "..\\share\\hedgewars"
+#define DATA_DIR CONFIG_DIR"\\Data"
+
+static flib_netconn *netconn;
+static flib_gameconn *gameconn;
+static flib_mapconn *mapconn;
+static char nickname[128];
+static flib_metascheme *metacfg;
+static bool netConnected = false;
+
+// Callback function that will be called when the map is rendered
+static void handleMapGenerated(void *context, const uint8_t *bitmap, int numHedgehogs) {
+    printf("Drawing map for %i brave little hogs...", numHedgehogs);
+
+    // Draw the map as ASCII art
+    for(int y=0; y<MAPIMAGE_HEIGHT; y+=8) {
+        for(int x=0; x<MAPIMAGE_WIDTH; x+=6) {
+            int pixelnum = x + y*MAPIMAGE_WIDTH;
+            bool pixel = bitmap[pixelnum>>3] & (1<<(7-(pixelnum&7)));
+            printf(pixel ? "#" : " ");
+        }
+        printf("\n");
+    }
+
+    flib_mapconn_destroy(mapconn);
+    mapconn = NULL;
+}
+
+static void onGameDisconnect(void *context, int reason) {
+    flib_log_i("Connection closed. Reason: %i", reason);
+    flib_gameconn_destroy(gameconn);
+    gameconn = NULL;
+    if(netconn) {
+        flib_netconn_send_roundfinished(netconn, reason==GAME_END_FINISHED);
+    }
+}
+
+// Callback function that will be called on error
+static void handleMapFailure(void *context, const char *errormessage) {
+    flib_log_e("Map rendering failed: %s", errormessage);
+    flib_mapconn_destroy(mapconn);
+    mapconn = NULL;
+}
+
+static void startEngineMap(int port) {
+    char cmdbuffer[255];
+    char argbuffer[255];
+    snprintf(cmdbuffer, 255, "%shwengine.exe", ENGINE_DIR);
+    snprintf(argbuffer, 255, "%s %i landpreview", CONFIG_DIR, port);
+    ShellExecute(NULL, NULL, cmdbuffer, argbuffer, NULL, SW_HIDE);
+}
+
+static void startEngineGame(int port) {
+    char cmdbuffer[255];
+    char argbuffer[255];
+    char base64PlayerName[255];
+    base64_encode(nickname, strlen(nickname), base64PlayerName, sizeof(base64PlayerName));
+    snprintf(cmdbuffer, 255, "%shwengine.exe", ENGINE_DIR);
+    snprintf(argbuffer, 255, "%s 1024 768 32 %i 0 0 0 10 10 %s 0 0 %s 0 0 en.txt", CONFIG_DIR, port, DATA_DIR, base64PlayerName);
+    ShellExecute(NULL, NULL, cmdbuffer, argbuffer, NULL, SW_HIDE);
+}
+
+void handleNetDisconnect(void *context, int reason, const char *message) {
+    printf("Disconnected: %s", message);
+    flib_netconn_destroy(netconn);
+    netconn = NULL;
+}
+
+/*void printRoomList() {
+    const flib_roomlist *roomlist = flib_netconn_get_roomlist(netconn);
+    if(roomlist) {
+        if(roomlist->roomCount>0) {
+            for(int i=0; i<roomlist->roomCount; i++) {
+                if(i>0) {
+                    printf(", ");
+                }
+                flib_room *room = roomlist->rooms[i];
+                printf("%s", room->name);
+            }
+        } else {
+            puts("Unfortunately, there are no rooms at the moment.");
+        }
+    } else {
+        puts("Sorry, due to an error the room list is not available.");
+    }
+    puts("\n");
+}*/
+
+void printTeamList() {
+    flib_gamesetup *setup = flib_netconn_create_gamesetup(netconn);
+    if(setup) {
+        puts("The following teams are in this room:");
+        for(int i=0; i<setup->teamlist->teamCount; i++) {
+            if(i>0) {
+                printf(", ");
+            }
+            printf("%s", setup->teamlist->teams[i]->name);
+        }
+        puts("\n");
+    } else {
+        puts("Sorry, due to an error the team list is not available.");
+    }
+    flib_gamesetup_destroy(setup);
+}
+
+void handleNetConnected(void *context) {
+    printf("You enter the lobby of a strange house inhabited by hedgehogs. Looking around, you see hallways branching off to these rooms:\n");
+    //printRoomList();
+    printf("\n\nNow, you can chat by just entering text, or join a room with /join <roomname>.");
+    printf(" You can also /quit or let me /describe <roomname>. Once in a room, you can /add <teamname> and set yourself /ready. You can also /list the available rooms (in the lobby) or the teams (in a room).\n");
+    netConnected = true;
+}
+
+void handleChat(void *context, const char *nick, const char *msg) {
+    if(gameconn) {
+        flib_gameconn_send_chatmsg(gameconn, nick, msg);
+    }
+    printf("%s: %s\n", nick, msg);
+}
+
+void handleEnterRoom(void *context, bool isChief) {
+    puts("You have entered the room.");
+}
+
+void handleRoomJoin(void *context, const char *nick) {
+    if(strcmp(nick, nickname)) {
+        printf("%s is here.\n", nick);
+    }
+}
+
+void handleRoomLeave(void *context, const char *nick, const char *partmsg) {
+    if(strcmp(nick, nickname)) {
+        printf("%s leaves.\n", nick);
+    }
+}
+
+void handleReady(void *context, const char *nick, bool ready) {
+    if(strcmp(nick, nickname)) {
+        if(ready) {
+            printf("%s is ready to go.\n", nick);
+        } else {
+            printf("%s is not ready.\n", nick);
+        }
+    } else {
+        if(ready) {
+            printf("You are ready to go.\n");
+        } else {
+            printf("You are not ready.\n");
+        }
+    }
+}
+
+void handleEmFromNet(void *context, const uint8_t *em, size_t size) {
+    if(gameconn) {
+        flib_gameconn_send_enginemsg(gameconn, em, size);
+    }
+}
+
+void handleEmFromEngine(void *context, const uint8_t *em, size_t size) {
+    if(netconn) {
+        flib_netconn_send_engineMessage(netconn, em, size);
+    }
+}
+
+void handleChatFromGame(void *context, const char *message, bool teamchat) {
+    if(netconn) {
+        if(teamchat) {
+            flib_netconn_send_teamchat(netconn, message);
+        } else {
+            flib_netconn_send_chat(netconn, message);
+        }
+    }
+}
+
+void handleRunGame(void *context) {
+    flib_gamesetup *gamesetup = flib_netconn_create_gamesetup(netconn);
+    if(gameconn) {
+        flib_log_e("Request to start game, but a game is already running.");
+    } else if(gamesetup) {
+        gameconn = flib_gameconn_create(nickname, gamesetup, true);
+        flib_gameconn_onEngineMessage(gameconn, handleEmFromEngine, NULL);
+        flib_gameconn_onDisconnect(gameconn, onGameDisconnect, NULL);
+        flib_gameconn_onChat(gameconn, handleChatFromGame, NULL);
+        startEngineGame(flib_gameconn_getport(gameconn));
+    }
+    flib_gamesetup_destroy(gamesetup);
+}
+
+void handleNickTaken(void *context, const char *nick) {
+    printf("The nickname %s is already in use, please choose a different one:\n", nick);
+    flib_gets(nickname, sizeof(nickname));
+    flib_netconn_send_nick(netconn, nickname);
+}
+
+void handlePwRequest(void *context, const char *nick) {
+    printf("A password is required to log in as %s, please enter (warning: shown in cleartext):\n", nick);
+    char password[256];
+    flib_gets(password, sizeof(password));
+    flib_netconn_send_password(netconn, password);
+}
+
+void handleMessage(void *context, int type, const char *msg) {
+    if(gameconn) {
+        flib_gameconn_send_textmsg(gameconn, 1, msg);
+    }
+    printf("*** %s\n", msg);
+}
+
+void handleTeamAccepted(void *context, const char *teamname) {
+    printf("The team %s has been accepted.\n", teamname);
+}
+
+void handleMapChanged(void *context, const flib_map *map, int changetype) {
+    if(map->mapgen != MAPGEN_NAMED && changetype != NETCONN_MAPCHANGE_THEME) {
+        if(mapconn) {
+            flib_mapconn_destroy(mapconn);
+            mapconn = NULL;
+        }
+        mapconn = flib_mapconn_create(map);
+        if(mapconn) {
+            flib_mapconn_onSuccess(mapconn, handleMapGenerated, NULL);
+            flib_mapconn_onFailure(mapconn, handleMapFailure, NULL);
+            startEngineMap(flib_mapconn_getport(mapconn));
+        }
+    } else if(map->mapgen == MAPGEN_NAMED) {
+        printf("The map %s has been selected.\n", map->name);
+    }
+}
+
+void handleLeaveRoom(void *context, int reason, const char *msg) {
+    if(reason == NETCONN_ROOMLEAVE_ABANDONED) {
+        printf("The chief has abandoned the room.");
+    } else if(reason == NETCONN_ROOMLEAVE_KICKED) {
+        printf("You have been kicked from the room.");
+    }
+    if(msg) {
+        printf(" (%s)", msg);
+    }
+    puts(" You are back in the lobby.");
+}
+
+void handleSchemeChanged(void *context, const flib_scheme *scheme) {
+    printf("Game scheme: %s.\n", scheme->name);
+}
+
+void handleWeaponsetChanged(void *context, const flib_weaponset *weaponset) {
+    printf("Weaponset: %s.\n", weaponset->name);
+}
+
+void handleHogcountChanged(void *context, const char *team, int count) {
+    printf("Team %s will send %i hogs into the fight.\n", team, count);
+}
+
+void handleRoomAdd(void *context, const flib_room *room) {
+    printf("%s created a new room called %s.\n", room->owner, room->name);
+}
+
+void handleRoomDelete(void *context, const char *roomName) {
+    printf("The room %s has collapsed.\n", roomName);
+}
+
+void handleScriptChanged(void *context, const char *script) {
+    printf("Game Type: %s\n", script);
+}
+
+void handleTeamAdd(void *context, const flib_team *team) {
+    printf("%s puts the team %s to the planning board.\n", team->ownerName, team->name);
+}
+
+void handleTeamDelete(void *context, const char *teamName) {
+    printf("The team %s decided not to fight this battle after all.\n", teamName);
+}
+
+void handleTeamColorChanged(void *context, const char *name, int colorIndex) {
+    static const char* colorNames[] = {"red", "blue", "teal", "purple", "pink", "green", "orange", "brown", "yellow"};
+    const char *colorName = "strange";
+    if(colorIndex>=0 && colorIndex < 9) {
+        colorName = colorNames[colorIndex];
+    }
+    printf("The team %s will wear %s uniforms today.\n", name, colorName);
+}
+
+void tick() {
+    if(gameconn) {
+        flib_gameconn_tick(gameconn);
+    }
+    if(netconn) {
+        flib_netconn_tick(netconn);
+    }
+    if(mapconn) {
+        flib_mapconn_tick(mapconn);
+    }
+}
+
+static HANDLE hStdin;
+
+static int init() {
+    hStdin = GetStdHandle(STD_INPUT_HANDLE);
+    if(hStdin == INVALID_HANDLE_VALUE) {
+        flib_log_e("Unable to get stdin handle");
+        return 1;
+    }
+    if(!flib_init(0)) {
+        flib_log_setLevel(FLIB_LOGLEVEL_WARNING);
+        freopen( "CON", "w", stdout );
+        freopen( "CON", "w", stderr );
+        metacfg = flib_metascheme_from_ini("metasettings.ini");
+        if(!metacfg) {
+            flib_quit();
+            return -1;
+        } else {
+            return 0;
+        }
+    }
+    return -1;
+}
+
+int main(int argc, char *argv[]) {
+    if(init()) {
+        return -1;
+    }
+
+    puts("Please enter a nickname:");
+    flib_gets(nickname, sizeof(nickname));
+
+    netconn = flib_netconn_create(nickname, metacfg, DATA_DIR"\\", "140.247.62.101", 46631);
+    if(!netconn) {
+        flib_quit();
+        return -1;
+    }
+
+    flib_netconn_onConnected(netconn, handleNetConnected, NULL);
+    flib_netconn_onDisconnected(netconn, handleNetDisconnect, NULL);
+    flib_netconn_onChat(netconn, handleChat, NULL);
+    flib_netconn_onEnterRoom(netconn, handleEnterRoom, NULL);
+    flib_netconn_onRunGame(netconn, handleRunGame, NULL);
+    flib_netconn_onEngineMessage(netconn, handleEmFromNet, NULL);
+    flib_netconn_onRoomJoin(netconn, handleRoomJoin, NULL);
+    flib_netconn_onRoomLeave(netconn, handleRoomLeave, NULL);
+    flib_netconn_onReadyState(netconn, handleReady, NULL);
+    flib_netconn_onNickTaken(netconn, handleNickTaken, NULL);
+    flib_netconn_onPasswordRequest(netconn, handlePwRequest, NULL);
+    flib_netconn_onMessage(netconn, handleMessage, NULL);
+    flib_netconn_onTeamAccepted(netconn, handleTeamAccepted, NULL);
+    flib_netconn_onMapChanged(netconn, handleMapChanged, NULL);
+    flib_netconn_onLeaveRoom(netconn, handleLeaveRoom, NULL);
+    flib_netconn_onCfgScheme(netconn, handleSchemeChanged, NULL);
+    flib_netconn_onWeaponsetChanged(netconn, handleWeaponsetChanged, NULL);
+    flib_netconn_onHogCountChanged(netconn, handleHogcountChanged, NULL);
+    flib_netconn_onRoomAdd(netconn, handleRoomAdd, NULL);
+    flib_netconn_onRoomDelete(netconn, handleRoomDelete, NULL);
+    flib_netconn_onScriptChanged(netconn, handleScriptChanged, NULL);
+    flib_netconn_onTeamAdd(netconn, handleTeamAdd, NULL);
+    flib_netconn_onTeamDelete(netconn, handleTeamDelete, NULL);
+    flib_netconn_onTeamColorChanged(netconn, handleTeamColorChanged, NULL);
+
+    INPUT_RECORD inputRecord;
+    DWORD eventCount = 0;
+
+    while(netconn || gameconn) {
+        tick();
+        if(netconn && netConnected) {
+            while(PeekConsoleInput(hStdin, &inputRecord, 1, &eventCount) && eventCount>0) {
+                if(inputRecord.EventType != KEY_EVENT) {
+                    ReadConsoleInput(hStdin, &inputRecord, 1, &eventCount);
+                } else {
+                    printf("%s: ", nickname);
+                    char input[256];
+                    if(!flib_gets(input, sizeof(input))) {
+                        if(!memcmp("/quit", input, strlen("/quit"))) {
+                            flib_netconn_send_quit(netconn, "Player quit.");
+                        } else if(!memcmp("/describe ", input, strlen("/describe "))) {
+                            const char *roomname = input+strlen("/describe ");
+                            /*const flib_roomlist *roomlist = flib_netconn_get_roomlist(netconn);
+                            flib_room *room = flib_roomlist_find(roomlist, roomname);
+                            if(!room) {
+                                puts("Unknown room.");
+                            } else {
+                                char *text = flib_asprintf(
+                                        "%s is a room created by %s, where %i players (%i teams) are %s on %s%s, using the %s scheme and %s weaponset.",
+                                        room->name,
+                                        room->owner,
+                                        room->playerCount,
+                                        room->teamCount,
+                                        room->inProgress ? "fighting" : "preparing to fight",
+                                        room->map[0]=='+' ? "" : "the map ",
+                                        !strcmp("+rnd+", room->map) ? "a random map" :
+                                                !strcmp("+maze+", room->map) ? "a random maze" :
+                                                !strcmp("+drawn+", room->map) ? "a hand-drawn map" :
+                                                room->map,
+                                        room->scheme,
+                                        room->weapons);
+                                if(text) {
+                                    puts(text);
+                                }
+                                free(text);
+                            }*/
+                        } else if(!memcmp("/join ", input, strlen("/join "))) {
+                            const char *roomname = input+strlen("/join ");
+                            flib_netconn_send_joinRoom(netconn, roomname);
+                        } else if(!memcmp("/ready", input, strlen("/ready"))) {
+                            flib_netconn_send_toggleReady(netconn);
+                        } else if(!memcmp("/loglevel ", input, strlen("/loglevel "))) {
+                            int loglevel = atoi(input+strlen("/loglevel "));
+                            flib_log_setLevel(loglevel);
+                        } else if(!memcmp("/list", input, strlen("/list"))) {
+                            if(flib_netconn_is_in_room_context(netconn)) {
+                                printTeamList();
+                            } else {
+                                puts("From this big and expansive lobby, hallways branch off to these rooms:");
+                                //printRoomList();
+                            }
+                        } else if(!memcmp("/addteam ", input, strlen("/addteam "))) {
+                            const char *teamname = input+strlen("/addteam ");
+                            if(!flib_contains_dir_separator(teamname)) {
+                                char *teamfilename = flib_asprintf("%s.hwt", teamname);
+                                if(teamfilename) {
+                                    flib_team *team = flib_team_from_ini(teamfilename);
+                                    if(team) {
+                                        flib_netconn_send_addTeam(netconn, team);
+                                    } else {
+                                        printf("Teamfile %s not found.\n", teamfilename);
+                                    }
+                                    flib_team_destroy(team);
+                                }
+                                free(teamfilename);
+                            }
+                        } else if(strlen(input)>0) {
+                            flib_netconn_send_chat(netconn, input);
+                        }
+                    }
+                }
+            }
+        }
+        fflush(stdout);
+        Sleep(10);
+    }
+
+
+    flib_metascheme_release(metacfg);
+    return 0;
+}
--- a/project_files/frontlib/Android.mk	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/Android.mk	Tue Jan 21 22:53:15 2014 +0100
@@ -4,17 +4,17 @@
 
 LOCAL_MODULE := frontlib
 
-LOCAL_CFLAGS := -I$(LOCAL_PATH)/../Android-build/SDL-android-project/jni/SDL_net -std=c99 -I$(LOCAL_PATH)/../Android-build/SDL-android-project/jni/SDL/include  
+LOCAL_CFLAGS := -I$(LOCAL_PATH)/../Android-build/SDL-android-project/jni/SDL_net -std=c99 -I$(LOCAL_PATH)/../Android-build/SDL-android-project/jni/SDL/include
 
 LOCAL_SRC_FILES := base64/base64.c iniparser/iniparser.c \
-	iniparser/dictionary.c ipc/gameconn.c ipc/ipcbase.c \
-	ipc/ipcprotocol.c ipc/mapconn.c md5/md5.c model/scheme.c \
-	model/gamesetup.c model/map.c model/mapcfg.c model/room.c \
-	model/schemelist.c model/team.c model/teamlist.c model/weapon.c \
-	net/netbase.c net/netconn_callbacks.c net/netconn_send.c \
-	net/netconn.c net/netprotocol.c util/buffer.c util/inihelper.c \
-	util/logging.c util/util.c frontlib.c hwconsts.c socket.c \
-	extra/jnacontrol.c
+    iniparser/dictionary.c ipc/gameconn.c ipc/ipcbase.c \
+    ipc/ipcprotocol.c ipc/mapconn.c md5/md5.c model/scheme.c \
+    model/gamesetup.c model/map.c model/mapcfg.c model/room.c \
+    model/schemelist.c model/team.c model/teamlist.c model/weapon.c \
+    net/netbase.c net/netconn_callbacks.c net/netconn_send.c \
+    net/netconn.c net/netprotocol.c util/buffer.c util/inihelper.c \
+    util/logging.c util/util.c frontlib.c hwconsts.c socket.c \
+    extra/jnacontrol.c
 
 LOCAL_SHARED_LIBRARIES += SDL SDL_net
 LOCAL_LDLIBS += -lz
--- a/project_files/frontlib/extra/jnacontrol.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/extra/jnacontrol.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,240 +1,240 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/*
- * This file is not directly part of the frontlib and is not required to build it.
- * However, it is recommended to include it in compilation when building for Android. The purpose of this file
- * is to ensure consistency between the function signatures of the JNA Java bindings of the Android port and the
- * frontlib functions.
- *
- * This file, in essence, consists only of function declarations. They are duplicates of function declarations
- * from the frontlib headers that are referenced from JNA bindings. If the signature of one of these functions
- * changes in the frontlib, it will no longer match the signature in this file, and the compiler will show an error.
- * If that happens, you need to update the JNA bindings in Hedgeroid to match the new function signature, and then
- * update this file.
- *
- * The reason for all this is that JNA does not actually know the function signatures of the functions it binds,
- * it derives them from Java method declarations. If those do not match the actual function signatures, you will
- * only notice when you suddenly get strange (and possibly hard to track down) problems at runtime. This file is
- * an attempt to detect these problems at compile time instead. Notice that it will NOT detect changes to structs
- * or constants though, which also require updates to the JNA bindings.
- */
-
-/*
- * Before we include the frontlib headers, we define away the const keyword. This is necessary because there is no
- * distinction between const and non-const types on the JNA side, and we don't want the compiler to complain because
- * of bad constness.
- *
- * This is so evil, but it works...
- */
-#define const
-
-#include "../frontlib.h"
-
-/*
- * Now we map the Java types to the corresponding C types...
- */
-typedef flib_netconn *NetconnPtr;
-typedef flib_gameconn *GameconnPtr;
-typedef flib_mapconn *MapconnPtr;
-typedef flib_metascheme *MetaschemePtr;
-typedef flib_room **RoomArrayPtr;
-typedef flib_weaponset *WeaponsetPtr;
-typedef flib_weaponsetlist *WeaponsetListPtr;
-typedef flib_map *MapRecipePtr;
-typedef flib_scheme *SchemePtr;
-typedef flib_schemelist *SchemelistPtr;
-
-typedef flib_room *RoomPtr;
-typedef flib_team *TeamPtr;
-typedef flib_gamesetup *GameSetupPtr;
-typedef bool boolean;
-typedef size_t NativeSizeT;
-typedef void *Pointer;
-typedef uint8_t *ByteArrayPtr;
-typedef char *String;
-
-/*
- * Mapping callback types
- */
-typedef void (*VoidCallback)(Pointer context);
-typedef void (*StrCallback)(Pointer context, String arg1);
-typedef void (*IntCallback)(Pointer context, int arg1);
-typedef void (*IntStrCallback)(Pointer context, int arg1, String arg2);
-typedef void (*StrIntCallback)(Pointer context, String arg1, int arg2);
-typedef void (*StrStrCallback)(Pointer context, String arg1, String arg2);
-typedef void (*StrStrBoolCallback)(Pointer context, String arg1, String arg2, boolean arg3);
-typedef void (*RoomCallback)(Pointer context, RoomPtr arg1);
-typedef void (*RoomListCallback)(Pointer context, RoomArrayPtr arg1, int arg2);
-typedef void (*StrRoomCallback)(Pointer context, String arg1, RoomPtr arg2);
-typedef void (*BoolCallback)(Pointer context, boolean arg1);
-typedef void (*StrBoolCallback)(Pointer context, String arg1, boolean arg2);
-typedef void (*TeamCallback)(Pointer context, TeamPtr arg1);
-typedef void (*BytesCallback)(Pointer context, const uint8_t *buffer, NativeSizeT size);
-typedef void (*BytesBoolCallback)(Pointer context, const uint8_t *buffer, NativeSizeT size, boolean arg3);
-typedef void (*SchemeCallback)(Pointer context, SchemePtr arg1);
-typedef void (*MapIntCallback)(Pointer context, MapRecipePtr arg1, int arg2);
-typedef void (*WeaponsetCallback)(Pointer context, WeaponsetPtr arg1);
-typedef void (*MapimageCallback)(Pointer context, const uint8_t *mapimage, int hogs);
-typedef void (*LogCallback)(int arg1, String arg2);
-
-/*
- * Below here are the copypasted method declarations from the JNA bindings
- */
-
-	// frontlib.h
-    int flib_init();
-    void flib_quit();
-
-    // hwconsts.h
-    int flib_get_teamcolor_count();
-    int flib_get_hedgehogs_per_team();
-    int flib_get_weapons_count();
-	MetaschemePtr flib_get_metascheme();
-
-    // net/netconn.h
-	NetconnPtr flib_netconn_create(String playerName, String dataDirPath, String host, int port);
-	void flib_netconn_destroy(NetconnPtr conn);
-
-	void flib_netconn_tick(NetconnPtr conn);
-	boolean flib_netconn_is_chief(NetconnPtr conn);
-	String flib_netconn_get_playername(NetconnPtr conn);
-	GameSetupPtr flib_netconn_create_gamesetup(NetconnPtr conn);
-	int flib_netconn_send_quit(NetconnPtr conn, String quitmsg);
-	int flib_netconn_send_chat(NetconnPtr conn, String chat);
-	int flib_netconn_send_teamchat(NetconnPtr conn, String msg);
-	int flib_netconn_send_password(NetconnPtr conn, String passwd);
-	int flib_netconn_send_nick(NetconnPtr conn, String nick);
-	int flib_netconn_send_request_roomlist(NetconnPtr conn);
-	int flib_netconn_send_joinRoom(NetconnPtr conn, String room);
-	int flib_netconn_send_createRoom(NetconnPtr conn, String room);
-	int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName);
-	int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg);
-	int flib_netconn_send_toggleReady(NetconnPtr conn);
-	int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team);
-	int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname);
-	int flib_netconn_send_engineMessage(NetconnPtr conn, ByteArrayPtr message, NativeSizeT size);
-	int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount);
-	int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex);
-	int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset);
-	int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map);
-	int flib_netconn_send_mapName(NetconnPtr conn, String mapName);
-	int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen);
-	int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter);
-	int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize);
-	int flib_netconn_send_mapSeed(NetconnPtr conn, String seed);
-	int flib_netconn_send_mapTheme(NetconnPtr conn, String theme);
-	int flib_netconn_send_mapDrawdata(NetconnPtr conn, ByteArrayPtr drawData, NativeSizeT size);
-	int flib_netconn_send_script(NetconnPtr conn, String scriptName);
-	int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme);
-	int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError);
-	int flib_netconn_send_ban(NetconnPtr conn, String playerName);
-	int flib_netconn_send_kick(NetconnPtr conn, String playerName);
-	int flib_netconn_send_playerInfo(NetconnPtr conn, String playerName);
-	int flib_netconn_send_playerFollow(NetconnPtr conn, String playerName);
-	int flib_netconn_send_startGame(NetconnPtr conn);
-	int flib_netconn_send_toggleRestrictJoins(NetconnPtr conn);
-	int flib_netconn_send_toggleRestrictTeams(NetconnPtr conn);
-	int flib_netconn_send_clearAccountsCache(NetconnPtr conn);
-	int flib_netconn_send_setServerVar(NetconnPtr conn, String name, String value);
-	int flib_netconn_send_getServerVars(NetconnPtr conn);
-
-	void flib_netconn_onMessage(NetconnPtr conn, IntStrCallback callback, Pointer context);
-	void flib_netconn_onClientFlags(NetconnPtr conn, StrStrBoolCallback callback, Pointer context);
-	void flib_netconn_onChat(NetconnPtr conn, StrStrCallback callback, Pointer context);
-	void flib_netconn_onConnected(NetconnPtr conn, VoidCallback callback, Pointer context);
-	void flib_netconn_onDisconnected(NetconnPtr conn, IntStrCallback callback, Pointer context);
-	void flib_netconn_onRoomlist(NetconnPtr conn, RoomListCallback callback, Pointer context);
-	void flib_netconn_onRoomAdd(NetconnPtr conn, RoomCallback callback, Pointer context);
-	void flib_netconn_onRoomDelete(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onRoomUpdate(NetconnPtr conn, StrRoomCallback callback, Pointer context);
-	void flib_netconn_onLobbyJoin(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onLobbyLeave(NetconnPtr conn, StrStrCallback callback, Pointer context);
-	void flib_netconn_onNickTaken(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onPasswordRequest(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onEnterRoom(NetconnPtr conn, BoolCallback callback, Pointer context);
-	void flib_netconn_onLeaveRoom(NetconnPtr conn, IntStrCallback callback, Pointer context);
-	void flib_netconn_onTeamAdd(NetconnPtr conn, TeamCallback callback, Pointer context);
-	void flib_netconn_onTeamDelete(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onRoomJoin(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onRoomLeave(NetconnPtr conn, StrStrCallback callback, Pointer context);
-	void flib_netconn_onRunGame(NetconnPtr conn, VoidCallback callback, Pointer context);
-	void flib_netconn_onTeamAccepted(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onHogCountChanged(NetconnPtr conn, StrIntCallback callback, Pointer context);
-	void flib_netconn_onTeamColorChanged(NetconnPtr conn, StrIntCallback callback, Pointer context);
-	void flib_netconn_onEngineMessage(NetconnPtr conn, BytesCallback callback, Pointer context);
-	void flib_netconn_onSchemeChanged(NetconnPtr conn, SchemeCallback callback, Pointer context);
-	void flib_netconn_onMapChanged(NetconnPtr conn, MapIntCallback callback, Pointer context);
-	void flib_netconn_onScriptChanged(NetconnPtr conn, StrCallback callback, Pointer context);
-	void flib_netconn_onWeaponsetChanged(NetconnPtr conn, WeaponsetCallback callback, Pointer context);
-	void flib_netconn_onServerVar(NetconnPtr conn, StrStrCallback callback, Pointer context);
-
-	// ipc/gameconn.h
-
-	GameconnPtr flib_gameconn_create(String playerName, GameSetupPtr setup, boolean netgame);
-	GameconnPtr flib_gameconn_create_playdemo(ByteArrayPtr demo, NativeSizeT size);
-	GameconnPtr flib_gameconn_create_loadgame(String playerName, ByteArrayPtr save, NativeSizeT size);
-	GameconnPtr flib_gameconn_create_campaign(String playerName, String seed, String script);
-
-	void flib_gameconn_destroy(GameconnPtr conn);
-	int flib_gameconn_getport(GameconnPtr conn);
-	void flib_gameconn_tick(GameconnPtr conn);
-
-	int flib_gameconn_send_enginemsg(GameconnPtr conn, ByteArrayPtr data, NativeSizeT len);
-	int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg);
-	int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg);
-	int flib_gameconn_send_quit(GameconnPtr conn);
-	int flib_gameconn_send_cmd(GameconnPtr conn, String cmdString);
-
-	void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context);
-	void flib_gameconn_onDisconnect(GameconnPtr conn, IntCallback callback, Pointer context);
-	void flib_gameconn_onErrorMessage(GameconnPtr conn, StrCallback callback, Pointer context);
-	void flib_gameconn_onChat(GameconnPtr conn, StrBoolCallback callback, Pointer context);
-	void flib_gameconn_onGameRecorded(GameconnPtr conn, BytesBoolCallback callback, Pointer context);
-	void flib_gameconn_onEngineMessage(GameconnPtr conn, BytesCallback callback, Pointer context);
-
-	// ipc/mapconn.h
-	MapconnPtr flib_mapconn_create(MapRecipePtr mapdesc);
-	void flib_mapconn_destroy(MapconnPtr conn);
-	int flib_mapconn_getport(MapconnPtr conn);
-	void flib_mapconn_onSuccess(MapconnPtr conn, MapimageCallback callback, Pointer context);
-	void flib_mapconn_onFailure(MapconnPtr conn, StrCallback callback, Pointer context);
-	void flib_mapconn_tick(MapconnPtr conn);
-
-	// model/schemelist.h
-	SchemelistPtr flib_schemelist_from_ini(String filename);
-	int flib_schemelist_to_ini(String filename, SchemelistPtr list);
-	void flib_schemelist_destroy(SchemelistPtr list);
-
-	// model/team.h
-	TeamPtr flib_team_from_ini(String filename);
-	int flib_team_to_ini(String filename, TeamPtr team);
-	void flib_team_destroy(TeamPtr team);
-
-	// model/weapon.h
-	WeaponsetListPtr flib_weaponsetlist_from_ini(String filename);
-	int flib_weaponsetlist_to_ini(String filename, WeaponsetListPtr weaponsets);
-	void flib_weaponsetlist_destroy(WeaponsetListPtr list);
-
-	// model/gamesetup.h
-	void flib_gamesetup_destroy(GameSetupPtr gamesetup);
-
-	// util/logging.h
-    void flib_log_setLevel(int level);
-    void flib_log_setCallback(LogCallback callback);
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/*
+ * This file is not directly part of the frontlib and is not required to build it.
+ * However, it is recommended to include it in compilation when building for Android. The purpose of this file
+ * is to ensure consistency between the function signatures of the JNA Java bindings of the Android port and the
+ * frontlib functions.
+ *
+ * This file, in essence, consists only of function declarations. They are duplicates of function declarations
+ * from the frontlib headers that are referenced from JNA bindings. If the signature of one of these functions
+ * changes in the frontlib, it will no longer match the signature in this file, and the compiler will show an error.
+ * If that happens, you need to update the JNA bindings in Hedgeroid to match the new function signature, and then
+ * update this file.
+ *
+ * The reason for all this is that JNA does not actually know the function signatures of the functions it binds,
+ * it derives them from Java method declarations. If those do not match the actual function signatures, you will
+ * only notice when you suddenly get strange (and possibly hard to track down) problems at runtime. This file is
+ * an attempt to detect these problems at compile time instead. Notice that it will NOT detect changes to structs
+ * or constants though, which also require updates to the JNA bindings.
+ */
+
+/*
+ * Before we include the frontlib headers, we define away the const keyword. This is necessary because there is no
+ * distinction between const and non-const types on the JNA side, and we don't want the compiler to complain because
+ * of bad constness.
+ *
+ * This is so evil, but it works...
+ */
+#define const
+
+#include "../frontlib.h"
+
+/*
+ * Now we map the Java types to the corresponding C types...
+ */
+typedef flib_netconn *NetconnPtr;
+typedef flib_gameconn *GameconnPtr;
+typedef flib_mapconn *MapconnPtr;
+typedef flib_metascheme *MetaschemePtr;
+typedef flib_room **RoomArrayPtr;
+typedef flib_weaponset *WeaponsetPtr;
+typedef flib_weaponsetlist *WeaponsetListPtr;
+typedef flib_map *MapRecipePtr;
+typedef flib_scheme *SchemePtr;
+typedef flib_schemelist *SchemelistPtr;
+
+typedef flib_room *RoomPtr;
+typedef flib_team *TeamPtr;
+typedef flib_gamesetup *GameSetupPtr;
+typedef bool boolean;
+typedef size_t NativeSizeT;
+typedef void *Pointer;
+typedef uint8_t *ByteArrayPtr;
+typedef char *String;
+
+/*
+ * Mapping callback types
+ */
+typedef void (*VoidCallback)(Pointer context);
+typedef void (*StrCallback)(Pointer context, String arg1);
+typedef void (*IntCallback)(Pointer context, int arg1);
+typedef void (*IntStrCallback)(Pointer context, int arg1, String arg2);
+typedef void (*StrIntCallback)(Pointer context, String arg1, int arg2);
+typedef void (*StrStrCallback)(Pointer context, String arg1, String arg2);
+typedef void (*StrStrBoolCallback)(Pointer context, String arg1, String arg2, boolean arg3);
+typedef void (*RoomCallback)(Pointer context, RoomPtr arg1);
+typedef void (*RoomListCallback)(Pointer context, RoomArrayPtr arg1, int arg2);
+typedef void (*StrRoomCallback)(Pointer context, String arg1, RoomPtr arg2);
+typedef void (*BoolCallback)(Pointer context, boolean arg1);
+typedef void (*StrBoolCallback)(Pointer context, String arg1, boolean arg2);
+typedef void (*TeamCallback)(Pointer context, TeamPtr arg1);
+typedef void (*BytesCallback)(Pointer context, const uint8_t *buffer, NativeSizeT size);
+typedef void (*BytesBoolCallback)(Pointer context, const uint8_t *buffer, NativeSizeT size, boolean arg3);
+typedef void (*SchemeCallback)(Pointer context, SchemePtr arg1);
+typedef void (*MapIntCallback)(Pointer context, MapRecipePtr arg1, int arg2);
+typedef void (*WeaponsetCallback)(Pointer context, WeaponsetPtr arg1);
+typedef void (*MapimageCallback)(Pointer context, const uint8_t *mapimage, int hogs);
+typedef void (*LogCallback)(int arg1, String arg2);
+
+/*
+ * Below here are the copypasted method declarations from the JNA bindings
+ */
+
+    // frontlib.h
+    int flib_init();
+    void flib_quit();
+
+    // hwconsts.h
+    int flib_get_teamcolor_count();
+    int flib_get_hedgehogs_per_team();
+    int flib_get_weapons_count();
+    MetaschemePtr flib_get_metascheme();
+
+    // net/netconn.h
+    NetconnPtr flib_netconn_create(String playerName, String dataDirPath, String host, int port);
+    void flib_netconn_destroy(NetconnPtr conn);
+
+    void flib_netconn_tick(NetconnPtr conn);
+    boolean flib_netconn_is_chief(NetconnPtr conn);
+    String flib_netconn_get_playername(NetconnPtr conn);
+    GameSetupPtr flib_netconn_create_gamesetup(NetconnPtr conn);
+    int flib_netconn_send_quit(NetconnPtr conn, String quitmsg);
+    int flib_netconn_send_chat(NetconnPtr conn, String chat);
+    int flib_netconn_send_teamchat(NetconnPtr conn, String msg);
+    int flib_netconn_send_password(NetconnPtr conn, String passwd);
+    int flib_netconn_send_nick(NetconnPtr conn, String nick);
+    int flib_netconn_send_request_roomlist(NetconnPtr conn);
+    int flib_netconn_send_joinRoom(NetconnPtr conn, String room);
+    int flib_netconn_send_createRoom(NetconnPtr conn, String room);
+    int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName);
+    int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg);
+    int flib_netconn_send_toggleReady(NetconnPtr conn);
+    int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team);
+    int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname);
+    int flib_netconn_send_engineMessage(NetconnPtr conn, ByteArrayPtr message, NativeSizeT size);
+    int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount);
+    int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex);
+    int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset);
+    int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map);
+    int flib_netconn_send_mapName(NetconnPtr conn, String mapName);
+    int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen);
+    int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter);
+    int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize);
+    int flib_netconn_send_mapSeed(NetconnPtr conn, String seed);
+    int flib_netconn_send_mapTheme(NetconnPtr conn, String theme);
+    int flib_netconn_send_mapDrawdata(NetconnPtr conn, ByteArrayPtr drawData, NativeSizeT size);
+    int flib_netconn_send_script(NetconnPtr conn, String scriptName);
+    int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme);
+    int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError);
+    int flib_netconn_send_ban(NetconnPtr conn, String playerName);
+    int flib_netconn_send_kick(NetconnPtr conn, String playerName);
+    int flib_netconn_send_playerInfo(NetconnPtr conn, String playerName);
+    int flib_netconn_send_playerFollow(NetconnPtr conn, String playerName);
+    int flib_netconn_send_startGame(NetconnPtr conn);
+    int flib_netconn_send_toggleRestrictJoins(NetconnPtr conn);
+    int flib_netconn_send_toggleRestrictTeams(NetconnPtr conn);
+    int flib_netconn_send_clearAccountsCache(NetconnPtr conn);
+    int flib_netconn_send_setServerVar(NetconnPtr conn, String name, String value);
+    int flib_netconn_send_getServerVars(NetconnPtr conn);
+
+    void flib_netconn_onMessage(NetconnPtr conn, IntStrCallback callback, Pointer context);
+    void flib_netconn_onClientFlags(NetconnPtr conn, StrStrBoolCallback callback, Pointer context);
+    void flib_netconn_onChat(NetconnPtr conn, StrStrCallback callback, Pointer context);
+    void flib_netconn_onConnected(NetconnPtr conn, VoidCallback callback, Pointer context);
+    void flib_netconn_onDisconnected(NetconnPtr conn, IntStrCallback callback, Pointer context);
+    void flib_netconn_onRoomlist(NetconnPtr conn, RoomListCallback callback, Pointer context);
+    void flib_netconn_onRoomAdd(NetconnPtr conn, RoomCallback callback, Pointer context);
+    void flib_netconn_onRoomDelete(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onRoomUpdate(NetconnPtr conn, StrRoomCallback callback, Pointer context);
+    void flib_netconn_onLobbyJoin(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onLobbyLeave(NetconnPtr conn, StrStrCallback callback, Pointer context);
+    void flib_netconn_onNickTaken(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onPasswordRequest(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onEnterRoom(NetconnPtr conn, BoolCallback callback, Pointer context);
+    void flib_netconn_onLeaveRoom(NetconnPtr conn, IntStrCallback callback, Pointer context);
+    void flib_netconn_onTeamAdd(NetconnPtr conn, TeamCallback callback, Pointer context);
+    void flib_netconn_onTeamDelete(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onRoomJoin(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onRoomLeave(NetconnPtr conn, StrStrCallback callback, Pointer context);
+    void flib_netconn_onRunGame(NetconnPtr conn, VoidCallback callback, Pointer context);
+    void flib_netconn_onTeamAccepted(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onHogCountChanged(NetconnPtr conn, StrIntCallback callback, Pointer context);
+    void flib_netconn_onTeamColorChanged(NetconnPtr conn, StrIntCallback callback, Pointer context);
+    void flib_netconn_onEngineMessage(NetconnPtr conn, BytesCallback callback, Pointer context);
+    void flib_netconn_onSchemeChanged(NetconnPtr conn, SchemeCallback callback, Pointer context);
+    void flib_netconn_onMapChanged(NetconnPtr conn, MapIntCallback callback, Pointer context);
+    void flib_netconn_onScriptChanged(NetconnPtr conn, StrCallback callback, Pointer context);
+    void flib_netconn_onWeaponsetChanged(NetconnPtr conn, WeaponsetCallback callback, Pointer context);
+    void flib_netconn_onServerVar(NetconnPtr conn, StrStrCallback callback, Pointer context);
+
+    // ipc/gameconn.h
+
+    GameconnPtr flib_gameconn_create(String playerName, GameSetupPtr setup, boolean netgame);
+    GameconnPtr flib_gameconn_create_playdemo(ByteArrayPtr demo, NativeSizeT size);
+    GameconnPtr flib_gameconn_create_loadgame(String playerName, ByteArrayPtr save, NativeSizeT size);
+    GameconnPtr flib_gameconn_create_campaign(String playerName, String seed, String script);
+
+    void flib_gameconn_destroy(GameconnPtr conn);
+    int flib_gameconn_getport(GameconnPtr conn);
+    void flib_gameconn_tick(GameconnPtr conn);
+
+    int flib_gameconn_send_enginemsg(GameconnPtr conn, ByteArrayPtr data, NativeSizeT len);
+    int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg);
+    int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg);
+    int flib_gameconn_send_quit(GameconnPtr conn);
+    int flib_gameconn_send_cmd(GameconnPtr conn, String cmdString);
+
+    void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context);
+    void flib_gameconn_onDisconnect(GameconnPtr conn, IntCallback callback, Pointer context);
+    void flib_gameconn_onErrorMessage(GameconnPtr conn, StrCallback callback, Pointer context);
+    void flib_gameconn_onChat(GameconnPtr conn, StrBoolCallback callback, Pointer context);
+    void flib_gameconn_onGameRecorded(GameconnPtr conn, BytesBoolCallback callback, Pointer context);
+    void flib_gameconn_onEngineMessage(GameconnPtr conn, BytesCallback callback, Pointer context);
+
+    // ipc/mapconn.h
+    MapconnPtr flib_mapconn_create(MapRecipePtr mapdesc);
+    void flib_mapconn_destroy(MapconnPtr conn);
+    int flib_mapconn_getport(MapconnPtr conn);
+    void flib_mapconn_onSuccess(MapconnPtr conn, MapimageCallback callback, Pointer context);
+    void flib_mapconn_onFailure(MapconnPtr conn, StrCallback callback, Pointer context);
+    void flib_mapconn_tick(MapconnPtr conn);
+
+    // model/schemelist.h
+    SchemelistPtr flib_schemelist_from_ini(String filename);
+    int flib_schemelist_to_ini(String filename, SchemelistPtr list);
+    void flib_schemelist_destroy(SchemelistPtr list);
+
+    // model/team.h
+    TeamPtr flib_team_from_ini(String filename);
+    int flib_team_to_ini(String filename, TeamPtr team);
+    void flib_team_destroy(TeamPtr team);
+
+    // model/weapon.h
+    WeaponsetListPtr flib_weaponsetlist_from_ini(String filename);
+    int flib_weaponsetlist_to_ini(String filename, WeaponsetListPtr weaponsets);
+    void flib_weaponsetlist_destroy(WeaponsetListPtr list);
+
+    // model/gamesetup.h
+    void flib_gamesetup_destroy(GameSetupPtr gamesetup);
+
+    // util/logging.h
+    void flib_log_setLevel(int level);
+    void flib_log_setCallback(LogCallback callback);
--- a/project_files/frontlib/frontlib.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/frontlib.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,37 +1,37 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "frontlib.h"
-#include "util/logging.h"
-#include <SDL_net.h>
-
-int flib_init() {
-	flib_log_d("Initializing frontlib");
-	if(SDLNet_Init()==-1) {
-		flib_log_e("Error in SDLNet_Init: %s", SDLNet_GetError());
-		return -1;
-	}
-
-	return 0;
-}
-
-void flib_quit() {
-	flib_log_d("Shutting down frontlib");
-	SDLNet_Quit();
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "frontlib.h"
+#include "util/logging.h"
+#include <SDL_net.h>
+
+int flib_init() {
+    flib_log_d("Initializing frontlib");
+    if(SDLNet_Init()==-1) {
+        flib_log_e("Error in SDLNet_Init: %s", SDLNet_GetError());
+        return -1;
+    }
+
+    return 0;
+}
+
+void flib_quit() {
+    flib_log_d("Shutting down frontlib");
+    SDLNet_Quit();
+}
--- a/project_files/frontlib/frontlib.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/frontlib.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,48 +1,48 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/*
- * Public header file for the hedgewars frontent networking library.
- *
- * This is the only header you should need to include from frontend code.
- */
-
-#ifndef FRONTLIB_H_
-#define FRONTLIB_H_
-
-#include "ipc/gameconn.h"
-#include "ipc/mapconn.h"
-#include "net/netconn.h"
-#include "util/logging.h"
-#include "model/schemelist.h"
-
-/**
- * Call this function before anything else in this library.
- * Returns 0 on success, -1 on error.
- */
-int flib_init();
-
-/**
- * Free resources associated with the library. Call this function once
- * the library is no longer needed. You can re-initialize the library by calling
- * flib_init again.
- */
-void flib_quit();
-
-#endif /* FRONTLIB_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/*
+ * Public header file for the hedgewars frontent networking library.
+ *
+ * This is the only header you should need to include from frontend code.
+ */
+
+#ifndef FRONTLIB_H_
+#define FRONTLIB_H_
+
+#include "ipc/gameconn.h"
+#include "ipc/mapconn.h"
+#include "net/netconn.h"
+#include "util/logging.h"
+#include "model/schemelist.h"
+
+/**
+ * Call this function before anything else in this library.
+ * Returns 0 on success, -1 on error.
+ */
+int flib_init();
+
+/**
+ * Free resources associated with the library. Call this function once
+ * the library is no longer needed. You can re-initialize the library by calling
+ * flib_init again.
+ */
+void flib_quit();
+
+#endif /* FRONTLIB_H_ */
--- a/project_files/frontlib/hwconsts.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/hwconsts.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,100 +1,100 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "hwconsts.h"
-
-const uint32_t flib_teamcolors[] = HW_TEAMCOLOR_ARRAY;
-const size_t flib_teamcolor_count = sizeof(flib_teamcolors)/sizeof(uint32_t)-1;
-
-static const flib_metascheme_setting metaSchemeSettings[] = {
-	{ .name = "damagefactor",      .times1000 = false, .engineCommand = "e$damagepct",   .maxMeansInfinity = false, .min = 10, .max = 300,  .def = 100 },
-	{ .name = "turntime",          .times1000 = true,  .engineCommand = "e$turntime",    .maxMeansInfinity = true,  .min = 1,  .max = 9999, .def = 45  },
-	{ .name = "health",            .times1000 = false, .engineCommand = NULL,            .maxMeansInfinity = false, .min = 50, .max = 200,  .def = 100 },
-	{ .name = "suddendeath",       .times1000 = false, .engineCommand = "e$sd_turns",    .maxMeansInfinity = true,  .min = 0,  .max = 50,   .def = 15  },
-	{ .name = "caseprobability",   .times1000 = false, .engineCommand = "e$casefreq",    .maxMeansInfinity = false, .min = 0,  .max = 9,    .def = 5   },
-	{ .name = "minestime",         .times1000 = true,  .engineCommand = "e$minestime",   .maxMeansInfinity = false, .min = -1, .max = 5,    .def = 3   },
-	{ .name = "minesnum",          .times1000 = false, .engineCommand = "e$minesnum",    .maxMeansInfinity = false, .min = 0,  .max = 80,   .def = 4   },
-	{ .name = "minedudpct",        .times1000 = false, .engineCommand = "e$minedudpct",  .maxMeansInfinity = false, .min = 0,  .max = 100,  .def = 0   },
-	{ .name = "explosives",        .times1000 = false, .engineCommand = "e$explosives",  .maxMeansInfinity = false, .min = 0,  .max = 40,   .def = 2   },
-	{ .name = "healthprobability", .times1000 = false, .engineCommand = "e$healthprob",  .maxMeansInfinity = false, .min = 0,  .max = 100,  .def = 35  },
-	{ .name = "healthcaseamount",  .times1000 = false, .engineCommand = "e$hcaseamount", .maxMeansInfinity = false, .min = 0,  .max = 200,  .def = 25  },
-	{ .name = "waterrise",         .times1000 = false, .engineCommand = "e$waterrise",   .maxMeansInfinity = false, .min = 0,  .max = 100,  .def = 47  },
-	{ .name = "healthdecrease",    .times1000 = false, .engineCommand = "e$healthdec",   .maxMeansInfinity = false, .min = 0,  .max = 100,  .def = 5   },
-	{ .name = "ropepct",           .times1000 = false, .engineCommand = "e$ropepct",     .maxMeansInfinity = false, .min = 25, .max = 999,  .def = 100 },
-	{ .name = "getawaytime",       .times1000 = false, .engineCommand = "e$getawaytime", .maxMeansInfinity = false, .min = 0,  .max = 999,  .def = 100 }
-};
-
-static const flib_metascheme_mod metaSchemeMods[] = {
-	{ .name = "fortsmode",          .bitmaskIndex = 12 },
-	{ .name = "divteams",           .bitmaskIndex = 4  },
-	{ .name = "solidland",          .bitmaskIndex = 2  },
-	{ .name = "border",             .bitmaskIndex = 3  },
-	{ .name = "lowgrav",            .bitmaskIndex = 5  },
-	{ .name = "laser",              .bitmaskIndex = 6  },
-	{ .name = "invulnerability",    .bitmaskIndex = 7  },
-	{ .name = "resethealth",        .bitmaskIndex = 8  },
-	{ .name = "vampiric",           .bitmaskIndex = 9  },
-	{ .name = "karma",              .bitmaskIndex = 10 },
-	{ .name = "artillery",          .bitmaskIndex = 11 },
-	{ .name = "randomorder",        .bitmaskIndex = 13 },
-	{ .name = "king",               .bitmaskIndex = 14 },
-	{ .name = "placehog",           .bitmaskIndex = 15 },
-	{ .name = "sharedammo",         .bitmaskIndex = 16 },
-	{ .name = "disablegirders",     .bitmaskIndex = 17 },
-	{ .name = "disablelandobjects", .bitmaskIndex = 18 },
-	{ .name = "aisurvival",         .bitmaskIndex = 19 },
-	{ .name = "infattack",          .bitmaskIndex = 20 },
-	{ .name = "resetweps",          .bitmaskIndex = 21 },
-	{ .name = "perhogammo",         .bitmaskIndex = 22 },
-	{ .name = "disablewind",        .bitmaskIndex = 23 },
-	{ .name = "morewind",           .bitmaskIndex = 24 },
-	{ .name = "tagteam",            .bitmaskIndex = 25 },
-	{ .name = "bottomborder",       .bitmaskIndex = 26 }
-};
-
-const flib_metascheme flib_meta = {
-	.settingCount = sizeof(metaSchemeSettings)/sizeof(flib_metascheme_setting),
-	.modCount = sizeof(metaSchemeMods)/sizeof(flib_metascheme_mod),
-	.settings = metaSchemeSettings,
-	.mods = metaSchemeMods
-};
-
-uint32_t flib_get_teamcolor(int colorIndex) {
-	if(colorIndex>=0 && colorIndex < flib_teamcolor_count) {
-		return flib_teamcolors[colorIndex];
-	} else {
-		return 0;
-	}
-}
-
-int flib_get_teamcolor_count() {
-	return flib_teamcolor_count;
-}
-
-int flib_get_hedgehogs_per_team() {
-	return HEDGEHOGS_PER_TEAM;
-}
-
-int flib_get_weapons_count() {
-	return WEAPONS_COUNT;
-}
-
-const flib_metascheme *flib_get_metascheme() {
-	return &flib_meta;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "hwconsts.h"
+
+const uint32_t flib_teamcolors[] = HW_TEAMCOLOR_ARRAY;
+const size_t flib_teamcolor_count = sizeof(flib_teamcolors)/sizeof(uint32_t)-1;
+
+static const flib_metascheme_setting metaSchemeSettings[] = {
+    { .name = "damagefactor",      .times1000 = false, .engineCommand = "e$damagepct",   .maxMeansInfinity = false, .min = 10, .max = 300,  .def = 100 },
+    { .name = "turntime",          .times1000 = true,  .engineCommand = "e$turntime",    .maxMeansInfinity = true,  .min = 1,  .max = 9999, .def = 45  },
+    { .name = "health",            .times1000 = false, .engineCommand = NULL,            .maxMeansInfinity = false, .min = 50, .max = 200,  .def = 100 },
+    { .name = "suddendeath",       .times1000 = false, .engineCommand = "e$sd_turns",    .maxMeansInfinity = true,  .min = 0,  .max = 50,   .def = 15  },
+    { .name = "caseprobability",   .times1000 = false, .engineCommand = "e$casefreq",    .maxMeansInfinity = false, .min = 0,  .max = 9,    .def = 5   },
+    { .name = "minestime",         .times1000 = true,  .engineCommand = "e$minestime",   .maxMeansInfinity = false, .min = -1, .max = 5,    .def = 3   },
+    { .name = "minesnum",          .times1000 = false, .engineCommand = "e$minesnum",    .maxMeansInfinity = false, .min = 0,  .max = 80,   .def = 4   },
+    { .name = "minedudpct",        .times1000 = false, .engineCommand = "e$minedudpct",  .maxMeansInfinity = false, .min = 0,  .max = 100,  .def = 0   },
+    { .name = "explosives",        .times1000 = false, .engineCommand = "e$explosives",  .maxMeansInfinity = false, .min = 0,  .max = 40,   .def = 2   },
+    { .name = "healthprobability", .times1000 = false, .engineCommand = "e$healthprob",  .maxMeansInfinity = false, .min = 0,  .max = 100,  .def = 35  },
+    { .name = "healthcaseamount",  .times1000 = false, .engineCommand = "e$hcaseamount", .maxMeansInfinity = false, .min = 0,  .max = 200,  .def = 25  },
+    { .name = "waterrise",         .times1000 = false, .engineCommand = "e$waterrise",   .maxMeansInfinity = false, .min = 0,  .max = 100,  .def = 47  },
+    { .name = "healthdecrease",    .times1000 = false, .engineCommand = "e$healthdec",   .maxMeansInfinity = false, .min = 0,  .max = 100,  .def = 5   },
+    { .name = "ropepct",           .times1000 = false, .engineCommand = "e$ropepct",     .maxMeansInfinity = false, .min = 25, .max = 999,  .def = 100 },
+    { .name = "getawaytime",       .times1000 = false, .engineCommand = "e$getawaytime", .maxMeansInfinity = false, .min = 0,  .max = 999,  .def = 100 }
+};
+
+static const flib_metascheme_mod metaSchemeMods[] = {
+    { .name = "fortsmode",          .bitmaskIndex = 12 },
+    { .name = "divteams",           .bitmaskIndex = 4  },
+    { .name = "solidland",          .bitmaskIndex = 2  },
+    { .name = "border",             .bitmaskIndex = 3  },
+    { .name = "lowgrav",            .bitmaskIndex = 5  },
+    { .name = "laser",              .bitmaskIndex = 6  },
+    { .name = "invulnerability",    .bitmaskIndex = 7  },
+    { .name = "resethealth",        .bitmaskIndex = 8  },
+    { .name = "vampiric",           .bitmaskIndex = 9  },
+    { .name = "karma",              .bitmaskIndex = 10 },
+    { .name = "artillery",          .bitmaskIndex = 11 },
+    { .name = "randomorder",        .bitmaskIndex = 13 },
+    { .name = "king",               .bitmaskIndex = 14 },
+    { .name = "placehog",           .bitmaskIndex = 15 },
+    { .name = "sharedammo",         .bitmaskIndex = 16 },
+    { .name = "disablegirders",     .bitmaskIndex = 17 },
+    { .name = "disablelandobjects", .bitmaskIndex = 18 },
+    { .name = "aisurvival",         .bitmaskIndex = 19 },
+    { .name = "infattack",          .bitmaskIndex = 20 },
+    { .name = "resetweps",          .bitmaskIndex = 21 },
+    { .name = "perhogammo",         .bitmaskIndex = 22 },
+    { .name = "disablewind",        .bitmaskIndex = 23 },
+    { .name = "morewind",           .bitmaskIndex = 24 },
+    { .name = "tagteam",            .bitmaskIndex = 25 },
+    { .name = "bottomborder",       .bitmaskIndex = 26 }
+};
+
+const flib_metascheme flib_meta = {
+    .settingCount = sizeof(metaSchemeSettings)/sizeof(flib_metascheme_setting),
+    .modCount = sizeof(metaSchemeMods)/sizeof(flib_metascheme_mod),
+    .settings = metaSchemeSettings,
+    .mods = metaSchemeMods
+};
+
+uint32_t flib_get_teamcolor(int colorIndex) {
+    if(colorIndex>=0 && colorIndex < flib_teamcolor_count) {
+        return flib_teamcolors[colorIndex];
+    } else {
+        return 0;
+    }
+}
+
+int flib_get_teamcolor_count() {
+    return flib_teamcolor_count;
+}
+
+int flib_get_hedgehogs_per_team() {
+    return HEDGEHOGS_PER_TEAM;
+}
+
+int flib_get_weapons_count() {
+    return WEAPONS_COUNT;
+}
+
+const flib_metascheme *flib_get_metascheme() {
+    return &flib_meta;
+}
--- a/project_files/frontlib/hwconsts.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/hwconsts.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,118 +1,118 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
- * Copyright (c) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-/**
- * This file contains important constants which might need to be changed to adapt to
- * changes in the engine or protocols.
- *
- * It also contains getter functions for some constants (in particular for constants
- * that are important for the layout of data structures), so that client code can
- * query the constants that the library was built with.
- */
-
-#ifndef HWCONSTS_H_
-#define HWCONSTS_H_
-
-#include <inttypes.h>
-#include <stddef.h>
-#include <stdbool.h>
-
-#define HEDGEHOGS_PER_TEAM 8
-#define DEFAULT_HEDGEHOG_COUNT 4
-#define DEFAULT_COLOR_INDEX 0
-
-#define NETGAME_DEFAULT_PORT 46631
-#define PROTOCOL_VERSION 42
-#define MIN_SERVER_VERSION 1
-
-//! Used for sending scripts to the engine
-#define MULTIPLAYER_SCRIPT_PATH "Scripts/Multiplayer/"
-
-#define WEAPONS_COUNT 56
-
-// TODO allow frontend to override these?
-/*! A merge of mikade/bugq colours w/ a bit of channel feedback */
-#define HW_TEAMCOLOR_ARRAY  { UINT32_C(0xffff0204), /*! red    */ \
-                              UINT32_C(0xff4980c1), /*! blue   */ \
-                              UINT32_C(0xff1de6ba), /*! teal   */ \
-                              UINT32_C(0xffb541ef), /*! purple */ \
-                              UINT32_C(0xffe55bb0), /*! pink   */ \
-                              UINT32_C(0xff20bf00), /*! green  */ \
-                              UINT32_C(0xfffe8b0e), /*! orange */ \
-                              UINT32_C(0xff5f3605), /*! brown  */ \
-                              UINT32_C(0xffffff01), /*! yellow */ \
-                              /*! add new colors here */ \
-                              0 } /*! Keep this 0 at the end */
-
-extern const size_t flib_teamcolor_count;
-extern const uint32_t flib_teamcolors[];
-
-/**
- * Returns the team color (ARGB) corresponding to the color index (0 if index out of bounds)
- */
-uint32_t flib_get_teamcolor(int colorIndex);
-
-/**
- * Returns the number of team colors (i.e. the length of the flib_teamcolors array)
- */
-int flib_get_teamcolor_count();
-
-/**
- * Returns the HEDGEHOGS_PER_TEAM constant
- */
-int flib_get_hedgehogs_per_team();
-
-/**
- * Returns the WEAPONS_COUNT constant
- */
-int flib_get_weapons_count();
-
-/*!
- * These structs define the meaning of values in the flib_scheme struct, i.e. their correspondence to
- * ini settings, engine commands and positions in the network protocol (the last is encoded in the
- * order of settings/mods).
- */
-typedef struct {
-    const char *name;				//!< A name identifying this setting (used as key in the schemes file)
-    const char *engineCommand;		//!< The command needed to send the setting to the engine. May be null if the setting is not sent to the engine (for the "health" setting)
-    const bool maxMeansInfinity;	//!< If true, send a very high number to the engine if the setting is equal to its maximum
-    const bool times1000;			//!< If true (for time-based settings), multiply the setting by 1000 before sending it to the engine.
-    const int min;					//!< The smallest allowed value
-    const int max;					//!< The highest allowed value
-    const int def;					//!< The default value
-} flib_metascheme_setting;
-
-typedef struct {
-    const char *name;				//!< A name identifying this mod (used as key in the schemes file)
-    const int bitmaskIndex;			//!< Mods are sent to the engine in a single integer, this field describes which bit of that integer is used
-    								//! for this particular mod.
-} flib_metascheme_mod;
-
-typedef struct {
-	const int settingCount;
-	const int modCount;
-	const flib_metascheme_setting *settings;
-	const flib_metascheme_mod *mods;
-} flib_metascheme;
-
-extern const flib_metascheme flib_meta;
-
-const flib_metascheme *flib_get_metascheme();
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/**
+ * This file contains important constants which might need to be changed to adapt to
+ * changes in the engine or protocols.
+ *
+ * It also contains getter functions for some constants (in particular for constants
+ * that are important for the layout of data structures), so that client code can
+ * query the constants that the library was built with.
+ */
+
+#ifndef HWCONSTS_H_
+#define HWCONSTS_H_
+
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#define HEDGEHOGS_PER_TEAM 8
+#define DEFAULT_HEDGEHOG_COUNT 4
+#define DEFAULT_COLOR_INDEX 0
+
+#define NETGAME_DEFAULT_PORT 46631
+#define PROTOCOL_VERSION 42
+#define MIN_SERVER_VERSION 1
+
+//! Used for sending scripts to the engine
+#define MULTIPLAYER_SCRIPT_PATH "Scripts/Multiplayer/"
+
+#define WEAPONS_COUNT 56
+
+// TODO allow frontend to override these?
+/*! A merge of mikade/bugq colours w/ a bit of channel feedback */
+#define HW_TEAMCOLOR_ARRAY  { UINT32_C(0xffff0204), /*! red    */ \
+                              UINT32_C(0xff4980c1), /*! blue   */ \
+                              UINT32_C(0xff1de6ba), /*! teal   */ \
+                              UINT32_C(0xffb541ef), /*! purple */ \
+                              UINT32_C(0xffe55bb0), /*! pink   */ \
+                              UINT32_C(0xff20bf00), /*! green  */ \
+                              UINT32_C(0xfffe8b0e), /*! orange */ \
+                              UINT32_C(0xff5f3605), /*! brown  */ \
+                              UINT32_C(0xffffff01), /*! yellow */ \
+                              /*! add new colors here */ \
+                              0 } /*! Keep this 0 at the end */
+
+extern const size_t flib_teamcolor_count;
+extern const uint32_t flib_teamcolors[];
+
+/**
+ * Returns the team color (ARGB) corresponding to the color index (0 if index out of bounds)
+ */
+uint32_t flib_get_teamcolor(int colorIndex);
+
+/**
+ * Returns the number of team colors (i.e. the length of the flib_teamcolors array)
+ */
+int flib_get_teamcolor_count();
+
+/**
+ * Returns the HEDGEHOGS_PER_TEAM constant
+ */
+int flib_get_hedgehogs_per_team();
+
+/**
+ * Returns the WEAPONS_COUNT constant
+ */
+int flib_get_weapons_count();
+
+/*!
+ * These structs define the meaning of values in the flib_scheme struct, i.e. their correspondence to
+ * ini settings, engine commands and positions in the network protocol (the last is encoded in the
+ * order of settings/mods).
+ */
+typedef struct {
+    const char *name;               //!< A name identifying this setting (used as key in the schemes file)
+    const char *engineCommand;      //!< The command needed to send the setting to the engine. May be null if the setting is not sent to the engine (for the "health" setting)
+    const bool maxMeansInfinity;    //!< If true, send a very high number to the engine if the setting is equal to its maximum
+    const bool times1000;           //!< If true (for time-based settings), multiply the setting by 1000 before sending it to the engine.
+    const int min;                  //!< The smallest allowed value
+    const int max;                  //!< The highest allowed value
+    const int def;                  //!< The default value
+} flib_metascheme_setting;
+
+typedef struct {
+    const char *name;               //!< A name identifying this mod (used as key in the schemes file)
+    const int bitmaskIndex;         //!< Mods are sent to the engine in a single integer, this field describes which bit of that integer is used
+                                    //! for this particular mod.
+} flib_metascheme_mod;
+
+typedef struct {
+    const int settingCount;
+    const int modCount;
+    const flib_metascheme_setting *settings;
+    const flib_metascheme_mod *mods;
+} flib_metascheme;
+
+extern const flib_metascheme flib_meta;
+
+const flib_metascheme *flib_get_metascheme();
+
+#endif
--- a/project_files/frontlib/iniparser/LICENSE	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/iniparser/LICENSE	Tue Jan 21 22:53:15 2014 +0100
@@ -1,23 +1,23 @@
-Copyright (c) 2000-2012 by Nicolas Devillard.
-MIT License
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in 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:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+Copyright (c) 2000-2012 by Nicolas Devillard.
+MIT License
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in 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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- a/project_files/frontlib/iniparser/VERSION	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/iniparser/VERSION	Tue Jan 21 22:53:15 2014 +0100
@@ -1,2 +1,2 @@
-This is version 3.1 of the iniparser library developed by N. Devillard.
+This is version 3.1 of the iniparser library developed by N. Devillard.
 See http://ndevilla.free.fr/iniparser/ for details and new versions.
\ No newline at end of file
--- a/project_files/frontlib/iniparser/dictionary.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/iniparser/dictionary.c	Tue Jan 21 22:53:15 2014 +0100
@@ -38,7 +38,7 @@
 static void * mem_double(void * ptr, int size)
 {
     void * newptr ;
- 
+
     newptr = calloc(2*size, 1);
     if (newptr==NULL) {
         return NULL ;
@@ -224,7 +224,7 @@
     unsigned    hash ;
 
     if (d==NULL || key==NULL) return -1 ;
-    
+
     /* Compute hash for this key */
     hash = dictionary_hash(key) ;
     /* Find if value is already in dictionary */
@@ -367,7 +367,7 @@
     /* Allocate dictionary */
     printf("allocating...\n");
     d = dictionary_new(0);
-    
+
     /* Set values in dictionary */
     printf("setting %d values...\n", NVALS);
     for (i=0 ; i<NVALS ; i++) {
--- a/project_files/frontlib/iniparser/iniparser.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/iniparser/iniparser.c	Tue Jan 21 22:53:15 2014 +0100
@@ -75,9 +75,9 @@
 {
     static char l[ASCIILINESZ+1];
     char * last ;
-    
+
     if (s==NULL) return NULL ;
-    
+
     while (isspace((int)*s) && *s) s++;
     memset(l, 0, ASCIILINESZ+1);
     strcpy(l, s);
@@ -292,7 +292,7 @@
     for (j=0 ; j<d->size ; j++) {
         if (d->key[j]==NULL)
             continue ;
-        if (!strncmp(d->key[j], keym, seclen+1)) 
+        if (!strncmp(d->key[j], keym, seclen+1))
             nkeys++;
     }
 
@@ -310,7 +310,7 @@
   This function queries a dictionary and finds all keys in a given section.
   Each pointer in the returned char pointer-to-pointer is pointing to
   a string allocated in the dictionary; do not free or modify them.
-  
+
   This function returns NULL in case of error.
  */
 /*--------------------------------------------------------------------------*/
@@ -334,7 +334,7 @@
 
     seclen  = (int)strlen(s);
     sprintf(keym, "%s:", s);
-    
+
     i = 0;
 
     for (j=0 ; j<d->size ; j++) {
@@ -557,7 +557,7 @@
     char * section,
     char * key,
     char * value)
-{   
+{
     line_status sta ;
     char        line[ASCIILINESZ+1];
     int         len ;
@@ -571,7 +571,7 @@
         sta = LINE_EMPTY ;
     } else if (line[0]=='#' || line[0]==';') {
         /* Comment line */
-        sta = LINE_COMMENT ; 
+        sta = LINE_COMMENT ;
     } else if (line[0]=='[' && line[len-1]==']') {
         /* Section name */
         sscanf(line, "[%[^]]", section);
--- a/project_files/frontlib/ipc/gameconn.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/ipc/gameconn.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,452 +1,452 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "gameconn.h"
-#include "ipcbase.h"
-#include "ipcprotocol.h"
-#include "../util/logging.h"
-#include "../util/util.h"
-#include "../hwconsts.h"
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-
-typedef enum {
-	AWAIT_CONNECTION,
-	CONNECTED,
-	FINISHED
-} gameconn_state;
-
-struct _flib_gameconn {
-	flib_ipcbase *ipcBase;
-	flib_vector *configBuffer;
-	flib_vector *demoBuffer;
-	char *playerName;
-
-	gameconn_state state;
-	bool netgame;
-	int disconnectReason;
-
-	void (*onConnectCb)(void* context);
-	void *onConnectCtx;
-
-	void (*onDisconnectCb)(void* context, int reason);
-	void *onDisconnectCtx;
-
-	void (*onErrorMessageCb)(void* context, const char *msg);
-	void *onErrorMessageCtx;
-
-	void (*onChatCb)(void* context, const char *msg, bool teamchat);
-	void *onChatCtx;
-
-	void (*onGameRecordedCb)(void *context, const uint8_t *record, size_t size, bool isSavegame);
-	void *onGameRecordedCtx;
-
-	void (*onEngineMessageCb)(void *context, const uint8_t *em, size_t size);
-	void *onEngineMessageCtx;
-
-	bool running;
-	bool destroyRequested;
-};
-
-static void defaultCallback_onErrorMessage(void* context, const char *msg) {
-	flib_log_w("Error from engine (no callback set): %s", msg);
-}
-
-static void clearCallbacks(flib_gameconn *conn) {
-	flib_gameconn_onConnect(conn, NULL, NULL);
-	flib_gameconn_onDisconnect(conn, NULL, NULL);
-	flib_gameconn_onErrorMessage(conn, NULL, NULL);
-	flib_gameconn_onChat(conn, NULL, NULL);
-	flib_gameconn_onGameRecorded(conn, NULL, NULL);
-	flib_gameconn_onEngineMessage(conn, NULL, NULL);
-}
-
-static flib_gameconn *flib_gameconn_create_partial(bool record, const char *playerName, bool netGame) {
-	flib_gameconn *result = NULL;
-	flib_gameconn *tempConn = flib_calloc(1, sizeof(flib_gameconn));
-	if(tempConn) {
-		tempConn->ipcBase = flib_ipcbase_create();
-		tempConn->configBuffer = flib_vector_create();
-		tempConn->playerName = flib_strdupnull(playerName);
-		if(tempConn->ipcBase && tempConn->configBuffer && tempConn->playerName) {
-			if(record) {
-				tempConn->demoBuffer = flib_vector_create();
-			}
-			tempConn->state = AWAIT_CONNECTION;
-			tempConn->netgame = netGame;
-			tempConn->disconnectReason = GAME_END_ERROR;
-			clearCallbacks(tempConn);
-			result = tempConn;
-			tempConn = NULL;
-		}
-	}
-	flib_gameconn_destroy(tempConn);
-	return result;
-}
-
-flib_gameconn *flib_gameconn_create(const char *playerName, const flib_gamesetup *setup, bool netgame) {
-	if(log_badargs_if2(playerName==NULL, setup==NULL)) {
-		return NULL;
-	}
-	flib_gameconn *result = NULL;
-	flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, netgame);
-	if(tempConn) {
-		if(flib_ipc_append_fullconfig(tempConn->configBuffer, setup, netgame)) {
-			flib_log_e("Error generating full game configuration for the engine.");
-		} else {
-			result = tempConn;
-			tempConn = NULL;
-		}
-	}
-	flib_gameconn_destroy(tempConn);
-	return result;
-}
-
-flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demoFileContent, size_t size) {
-	if(log_badargs_if(demoFileContent==NULL && size>0)) {
-		return NULL;
-	}
-	flib_gameconn *result = NULL;
-	flib_gameconn *tempConn = flib_gameconn_create_partial(false, "Player", false);
-	if(tempConn) {
-		if(!flib_vector_append(tempConn->configBuffer, demoFileContent, size)) {
-			result = tempConn;
-			tempConn = NULL;
-		}
-	}
-	flib_gameconn_destroy(tempConn);
-	return result;
-}
-
-flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *saveFileContent, size_t size) {
-	if(log_badargs_if(saveFileContent==NULL && size>0)) {
-		return NULL;
-	}
-	flib_gameconn *result = NULL;
-	flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, false);
-	if(tempConn) {
-		if(!flib_vector_append(tempConn->configBuffer, saveFileContent, size)) {
-			result = tempConn;
-			tempConn = NULL;
-		}
-	}
-	flib_gameconn_destroy(tempConn);
-	return result;
-}
-
-flib_gameconn *flib_gameconn_create_campaign(const char *playerName, const char *seed, const char *script) {
-	if(log_badargs_if3(playerName==NULL, seed==NULL, script==NULL)) {
-		return NULL;
-	}
-	flib_gameconn *result = NULL;
-	flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, false);
-	if(tempConn) {
-		if(!flib_ipc_append_message(tempConn->configBuffer, "TL")
-				&& !flib_ipc_append_seed(tempConn->configBuffer, seed)
-				&& !flib_ipc_append_script(tempConn->configBuffer, script)
-				&& !flib_ipc_append_message(tempConn->configBuffer, "!")) {
-			result = tempConn;
-			tempConn = NULL;
-		}
-	}
-	flib_gameconn_destroy(tempConn);
-	return result;
-}
-
-void flib_gameconn_destroy(flib_gameconn *conn) {
-	if(conn) {
-		if(conn->running) {
-			/*
-			 * The function was called from a callback, so the tick function is still running
-			 * and we delay the actual destruction. We ensure no further callbacks will be
-			 * sent to prevent surprises.
-			 */
-			clearCallbacks(conn);
-			conn->destroyRequested = true;
-		} else {
-			flib_ipcbase_destroy(conn->ipcBase);
-			flib_vector_destroy(conn->configBuffer);
-			flib_vector_destroy(conn->demoBuffer);
-			free(conn->playerName);
-			free(conn);
-		}
-	}
-}
-
-int flib_gameconn_getport(flib_gameconn *conn) {
-	if(log_badargs_if(conn==NULL)) {
-		return 0;
-	}
-	return flib_ipcbase_port(conn->ipcBase);
-}
-
-static void demo_append(flib_gameconn *conn, const void *data, size_t len) {
-	if(conn->demoBuffer) {
-		if(flib_vector_append(conn->demoBuffer, data, len)) {
-			flib_log_e("Error recording demo: Out of memory.");
-			flib_vector_destroy(conn->demoBuffer);
-			conn->demoBuffer = NULL;
-		}
-	}
-}
-
-static int format_chatmessage(uint8_t buffer[257], const char *playerName, const char *message) {
-	size_t msglen = strlen(message);
-
-	// If the message starts with /me, it will be displayed differently.
-	bool meMessage = msglen >= 4 && !memcmp(message, "/me ", 4);
-	const char *template = meMessage ? "s\x02* %s %s  " : "s\x01%s: %s  ";
-	int size = snprintf((char*)buffer+1, 256, template, playerName, meMessage ? message+4 : message);
-	if(log_e_if(size<=0, "printf error")) {
-		return -1;
-	} else {
-		buffer[0] = size>255 ? 255 : size;
-		return 0;
-	}
-}
-
-static void demo_append_chatmessage(flib_gameconn *conn, const char *message) {
-	// Chat messages are reformatted to make them look as if they were received, not sent.
-	uint8_t converted[257];
-	if(!format_chatmessage(converted, conn->playerName, message)) {
-		demo_append(conn, converted, converted[0]+1);
-	}
-}
-
-static void demo_replace_gamemode(flib_buffer buf, char gamemode) {
-	size_t msgStart = 0;
-	uint8_t *data = (uint8_t*)buf.data;
-	while(msgStart+2 < buf.size) {
-		if(!memcmp(data+msgStart, "\x02T", 2)) {
-			data[msgStart+2] = gamemode;
-		}
-		msgStart += (uint8_t)data[msgStart]+1;
-	}
-}
-
-int flib_gameconn_send_enginemsg(flib_gameconn *conn, const uint8_t *data, size_t len) {
-	if(log_badargs_if2(conn==NULL, data==NULL && len>0)) {
-		return -1;
-	}
-	int result = flib_ipcbase_send_raw(conn->ipcBase, data, len);
-	if(!result) {
-		demo_append(conn, data, len);
-	}
-	return result;
-}
-
-int flib_gameconn_send_textmsg(flib_gameconn *conn, int msgtype, const char *msg) {
-	if(log_badargs_if2(conn==NULL, msg==NULL)) {
-		return -1;
-	}
-	int result = -1;
-	uint8_t converted[257];
-	int size = snprintf((char*)converted+1, 256, "s%c%s", (char)msgtype, msg);
-	if(size>0) {
-		converted[0] = size>255 ? 255 : size;
-		if(!flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) {
-			demo_append(conn, converted, converted[0]+1);
-			result = 0;
-		}
-	}
-	return result;
-}
-
-int flib_gameconn_send_chatmsg(flib_gameconn *conn, const char *playername, const char *msg) {
-	if(log_badargs_if3(conn==NULL, playername==NULL, msg==NULL)) {
-		return -1;
-	}
-	uint8_t converted[257];
-	if(!format_chatmessage(converted, playername, msg)
-			&& !flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) {
-		demo_append(conn, converted, converted[0]+1);
-		return 0;
-	}
-	return -1;
-}
-
-int flib_gameconn_send_quit(flib_gameconn *conn) {
-	return flib_gameconn_send_cmd(conn, "efinish");
-}
-
-int flib_gameconn_send_cmd(flib_gameconn *conn, const char *cmdString) {
-	if(log_badargs_if2(conn==NULL, cmdString==NULL)) {
-		return -1;
-	}
-	int result = -1;
-	uint8_t converted[256];
-	size_t msglen = strlen(cmdString);
-	if(!log_e_if(msglen>255, "Message too long: %s", cmdString)) {
-		strcpy((char*)converted+1, cmdString);
-		converted[0] = msglen;
-		if(!flib_ipcbase_send_raw(conn->ipcBase, converted, msglen+1)) {
-			demo_append(conn, converted, msglen+1);
-			result = 0;
-		}
-	}
-	return result;
-}
-
-/**
- * This macro generates a callback setter function. It uses the name of the callback to
- * automatically generate the function name and the fields to set, so a consistent naming
- * convention needs to be enforced (not that that is a bad thing). If null is passed as
- * callback to the generated function, the defaultCb will be set instead (with conn
- * as the context).
- */
-#define GENERATE_CB_SETTER(cbName, cbParameterTypes, defaultCb) \
-	void flib_gameconn_##cbName(flib_gameconn *conn, void (*callback)cbParameterTypes, void *context) { \
-		if(!log_badargs_if(conn==NULL)) { \
-			conn->cbName##Cb = callback ? callback : &defaultCb; \
-			conn->cbName##Ctx = callback ? context : conn; \
-		} \
-	}
-
-/**
- * Generate a callback setter function like GENERATE_CB_SETTER, and automatically generate a
- * no-op callback function as well that is used as default.
- */
-#define GENERATE_CB_SETTER_AND_DEFAULT(cbName, cbParameterTypes) \
-	static void _noop_callback_##cbName cbParameterTypes {} \
-	GENERATE_CB_SETTER(cbName, cbParameterTypes, _noop_callback_##cbName)
-
-GENERATE_CB_SETTER_AND_DEFAULT(onConnect, (void *context));
-GENERATE_CB_SETTER_AND_DEFAULT(onDisconnect, (void* context, int reason));
-GENERATE_CB_SETTER(onErrorMessage, (void* context, const char *msg), defaultCallback_onErrorMessage);
-GENERATE_CB_SETTER_AND_DEFAULT(onChat, (void* context, const char *msg, bool teamchat));
-GENERATE_CB_SETTER_AND_DEFAULT(onGameRecorded, (void *context, const uint8_t *record, size_t size, bool isSavegame));
-GENERATE_CB_SETTER_AND_DEFAULT(onEngineMessage, (void *context, const uint8_t *em, size_t size));
-
-#undef GENERATE_CB_SETTER_AND_DEFAULT
-#undef GENERATE_CB_SETTER
-
-static void flib_gameconn_wrappedtick(flib_gameconn *conn) {
-	if(conn->state == AWAIT_CONNECTION) {
-		flib_ipcbase_accept(conn->ipcBase);
-		switch(flib_ipcbase_state(conn->ipcBase)) {
-		case IPC_CONNECTED:
-			{
-				flib_constbuffer configBuffer = flib_vector_as_constbuffer(conn->configBuffer);
-				if(flib_ipcbase_send_raw(conn->ipcBase, configBuffer.data, configBuffer.size)) {
-					conn->state = FINISHED;
-					conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR);
-					return;
-				} else {
-					demo_append(conn, configBuffer.data, configBuffer.size);
-					conn->state = CONNECTED;
-					conn->onConnectCb(conn->onConnectCtx);
-					if(conn->destroyRequested) {
-						return;
-					}
-				}
-			}
-			break;
-		case IPC_NOT_CONNECTED:
-			conn->state = FINISHED;
-			conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR);
-			return;
-		default:
-			break;
-		}
-	}
-
-	if(conn->state == CONNECTED) {
-		uint8_t msgbuffer[257];
-		int len;
-		while(!conn->destroyRequested && (len = flib_ipcbase_recv_message(conn->ipcBase, msgbuffer))>=0) {
-			if(len<2) {
-				flib_log_w("Received short message from IPC (<2 bytes)");
-				continue;
-			}
-			switch(msgbuffer[1]) {
-			case '?':	// Ping
-				// The pong is already part of the config message
-				break;
-			case 'C':	// Config query
-				// And we already send the config message on connecting.
-				break;
-			case 'E':	// Error message
-				if(len>=3) {
-					msgbuffer[len-2] = 0;
-					conn->onErrorMessageCb(conn->onErrorMessageCtx, (char*)msgbuffer+2);
-				}
-				break;
-			case 'i':	// Statistics
-				// TODO stats
-				break;
-			case 'Q':	// Game interrupted
-			case 'H':	// Game halted
-			case 'q':	// game finished
-				{
-					int reason = msgbuffer[1]=='Q' ? GAME_END_INTERRUPTED : msgbuffer[1]=='H' ? GAME_END_HALTED : GAME_END_FINISHED;
-					conn->disconnectReason = reason;
-					bool savegame = (reason != GAME_END_FINISHED) && !conn->netgame;
-					if(conn->demoBuffer) {
-						flib_buffer demoBuffer = flib_vector_as_buffer(conn->demoBuffer);
-						demo_replace_gamemode(demoBuffer, savegame ? 'S' : 'D');
-						conn->onGameRecordedCb(conn->onGameRecordedCtx, demoBuffer.data, demoBuffer.size, savegame);
-						if(conn->destroyRequested) {
-							return;
-						}
-					}
-					return;
-				}
-			case 's':	// Chat message
-				if(len>=3) {
-					msgbuffer[len-2] = 0;
-					demo_append_chatmessage(conn, (char*)msgbuffer+2);
-
-					conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, false);
-				}
-				break;
-			case 'b':	// Teamchat message
-				if(len>=3) {
-					msgbuffer[len-2] = 0;
-					conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, true);
-				}
-				break;
-			default:	// Engine message
-				demo_append(conn, msgbuffer, len);
-
-				conn->onEngineMessageCb(conn->onEngineMessageCtx, msgbuffer, len);
-				break;
-			}
-		}
-	}
-
-	if(flib_ipcbase_state(conn->ipcBase) == IPC_NOT_CONNECTED) {
-		conn->state = FINISHED;
-		conn->onDisconnectCb(conn->onDisconnectCtx, conn->disconnectReason);
-	}
-}
-
-void flib_gameconn_tick(flib_gameconn *conn) {
-	if(!log_badargs_if(conn == NULL)
-			&& !log_w_if(conn->running, "Call to flib_gameconn_tick from a callback")
-			&& !log_w_if(conn->state == FINISHED, "We are already done.")) {
-		conn->running = true;
-		flib_gameconn_wrappedtick(conn);
-		conn->running = false;
-
-		if(conn->destroyRequested) {
-			flib_gameconn_destroy(conn);
-		}
-	}
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "gameconn.h"
+#include "ipcbase.h"
+#include "ipcprotocol.h"
+#include "../util/logging.h"
+#include "../util/util.h"
+#include "../hwconsts.h"
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef enum {
+    AWAIT_CONNECTION,
+    CONNECTED,
+    FINISHED
+} gameconn_state;
+
+struct _flib_gameconn {
+    flib_ipcbase *ipcBase;
+    flib_vector *configBuffer;
+    flib_vector *demoBuffer;
+    char *playerName;
+
+    gameconn_state state;
+    bool netgame;
+    int disconnectReason;
+
+    void (*onConnectCb)(void* context);
+    void *onConnectCtx;
+
+    void (*onDisconnectCb)(void* context, int reason);
+    void *onDisconnectCtx;
+
+    void (*onErrorMessageCb)(void* context, const char *msg);
+    void *onErrorMessageCtx;
+
+    void (*onChatCb)(void* context, const char *msg, bool teamchat);
+    void *onChatCtx;
+
+    void (*onGameRecordedCb)(void *context, const uint8_t *record, size_t size, bool isSavegame);
+    void *onGameRecordedCtx;
+
+    void (*onEngineMessageCb)(void *context, const uint8_t *em, size_t size);
+    void *onEngineMessageCtx;
+
+    bool running;
+    bool destroyRequested;
+};
+
+static void defaultCallback_onErrorMessage(void* context, const char *msg) {
+    flib_log_w("Error from engine (no callback set): %s", msg);
+}
+
+static void clearCallbacks(flib_gameconn *conn) {
+    flib_gameconn_onConnect(conn, NULL, NULL);
+    flib_gameconn_onDisconnect(conn, NULL, NULL);
+    flib_gameconn_onErrorMessage(conn, NULL, NULL);
+    flib_gameconn_onChat(conn, NULL, NULL);
+    flib_gameconn_onGameRecorded(conn, NULL, NULL);
+    flib_gameconn_onEngineMessage(conn, NULL, NULL);
+}
+
+static flib_gameconn *flib_gameconn_create_partial(bool record, const char *playerName, bool netGame) {
+    flib_gameconn *result = NULL;
+    flib_gameconn *tempConn = flib_calloc(1, sizeof(flib_gameconn));
+    if(tempConn) {
+        tempConn->ipcBase = flib_ipcbase_create();
+        tempConn->configBuffer = flib_vector_create();
+        tempConn->playerName = flib_strdupnull(playerName);
+        if(tempConn->ipcBase && tempConn->configBuffer && tempConn->playerName) {
+            if(record) {
+                tempConn->demoBuffer = flib_vector_create();
+            }
+            tempConn->state = AWAIT_CONNECTION;
+            tempConn->netgame = netGame;
+            tempConn->disconnectReason = GAME_END_ERROR;
+            clearCallbacks(tempConn);
+            result = tempConn;
+            tempConn = NULL;
+        }
+    }
+    flib_gameconn_destroy(tempConn);
+    return result;
+}
+
+flib_gameconn *flib_gameconn_create(const char *playerName, const flib_gamesetup *setup, bool netgame) {
+    if(log_badargs_if2(playerName==NULL, setup==NULL)) {
+        return NULL;
+    }
+    flib_gameconn *result = NULL;
+    flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, netgame);
+    if(tempConn) {
+        if(flib_ipc_append_fullconfig(tempConn->configBuffer, setup, netgame)) {
+            flib_log_e("Error generating full game configuration for the engine.");
+        } else {
+            result = tempConn;
+            tempConn = NULL;
+        }
+    }
+    flib_gameconn_destroy(tempConn);
+    return result;
+}
+
+flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demoFileContent, size_t size) {
+    if(log_badargs_if(demoFileContent==NULL && size>0)) {
+        return NULL;
+    }
+    flib_gameconn *result = NULL;
+    flib_gameconn *tempConn = flib_gameconn_create_partial(false, "Player", false);
+    if(tempConn) {
+        if(!flib_vector_append(tempConn->configBuffer, demoFileContent, size)) {
+            result = tempConn;
+            tempConn = NULL;
+        }
+    }
+    flib_gameconn_destroy(tempConn);
+    return result;
+}
+
+flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *saveFileContent, size_t size) {
+    if(log_badargs_if(saveFileContent==NULL && size>0)) {
+        return NULL;
+    }
+    flib_gameconn *result = NULL;
+    flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, false);
+    if(tempConn) {
+        if(!flib_vector_append(tempConn->configBuffer, saveFileContent, size)) {
+            result = tempConn;
+            tempConn = NULL;
+        }
+    }
+    flib_gameconn_destroy(tempConn);
+    return result;
+}
+
+flib_gameconn *flib_gameconn_create_campaign(const char *playerName, const char *seed, const char *script) {
+    if(log_badargs_if3(playerName==NULL, seed==NULL, script==NULL)) {
+        return NULL;
+    }
+    flib_gameconn *result = NULL;
+    flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, false);
+    if(tempConn) {
+        if(!flib_ipc_append_message(tempConn->configBuffer, "TL")
+                && !flib_ipc_append_seed(tempConn->configBuffer, seed)
+                && !flib_ipc_append_script(tempConn->configBuffer, script)
+                && !flib_ipc_append_message(tempConn->configBuffer, "!")) {
+            result = tempConn;
+            tempConn = NULL;
+        }
+    }
+    flib_gameconn_destroy(tempConn);
+    return result;
+}
+
+void flib_gameconn_destroy(flib_gameconn *conn) {
+    if(conn) {
+        if(conn->running) {
+            /*
+             * The function was called from a callback, so the tick function is still running
+             * and we delay the actual destruction. We ensure no further callbacks will be
+             * sent to prevent surprises.
+             */
+            clearCallbacks(conn);
+            conn->destroyRequested = true;
+        } else {
+            flib_ipcbase_destroy(conn->ipcBase);
+            flib_vector_destroy(conn->configBuffer);
+            flib_vector_destroy(conn->demoBuffer);
+            free(conn->playerName);
+            free(conn);
+        }
+    }
+}
+
+int flib_gameconn_getport(flib_gameconn *conn) {
+    if(log_badargs_if(conn==NULL)) {
+        return 0;
+    }
+    return flib_ipcbase_port(conn->ipcBase);
+}
+
+static void demo_append(flib_gameconn *conn, const void *data, size_t len) {
+    if(conn->demoBuffer) {
+        if(flib_vector_append(conn->demoBuffer, data, len)) {
+            flib_log_e("Error recording demo: Out of memory.");
+            flib_vector_destroy(conn->demoBuffer);
+            conn->demoBuffer = NULL;
+        }
+    }
+}
+
+static int format_chatmessage(uint8_t buffer[257], const char *playerName, const char *message) {
+    size_t msglen = strlen(message);
+
+    // If the message starts with /me, it will be displayed differently.
+    bool meMessage = msglen >= 4 && !memcmp(message, "/me ", 4);
+    const char *template = meMessage ? "s\x02* %s %s  " : "s\x01%s: %s  ";
+    int size = snprintf((char*)buffer+1, 256, template, playerName, meMessage ? message+4 : message);
+    if(log_e_if(size<=0, "printf error")) {
+        return -1;
+    } else {
+        buffer[0] = size>255 ? 255 : size;
+        return 0;
+    }
+}
+
+static void demo_append_chatmessage(flib_gameconn *conn, const char *message) {
+    // Chat messages are reformatted to make them look as if they were received, not sent.
+    uint8_t converted[257];
+    if(!format_chatmessage(converted, conn->playerName, message)) {
+        demo_append(conn, converted, converted[0]+1);
+    }
+}
+
+static void demo_replace_gamemode(flib_buffer buf, char gamemode) {
+    size_t msgStart = 0;
+    uint8_t *data = (uint8_t*)buf.data;
+    while(msgStart+2 < buf.size) {
+        if(!memcmp(data+msgStart, "\x02T", 2)) {
+            data[msgStart+2] = gamemode;
+        }
+        msgStart += (uint8_t)data[msgStart]+1;
+    }
+}
+
+int flib_gameconn_send_enginemsg(flib_gameconn *conn, const uint8_t *data, size_t len) {
+    if(log_badargs_if2(conn==NULL, data==NULL && len>0)) {
+        return -1;
+    }
+    int result = flib_ipcbase_send_raw(conn->ipcBase, data, len);
+    if(!result) {
+        demo_append(conn, data, len);
+    }
+    return result;
+}
+
+int flib_gameconn_send_textmsg(flib_gameconn *conn, int msgtype, const char *msg) {
+    if(log_badargs_if2(conn==NULL, msg==NULL)) {
+        return -1;
+    }
+    int result = -1;
+    uint8_t converted[257];
+    int size = snprintf((char*)converted+1, 256, "s%c%s", (char)msgtype, msg);
+    if(size>0) {
+        converted[0] = size>255 ? 255 : size;
+        if(!flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) {
+            demo_append(conn, converted, converted[0]+1);
+            result = 0;
+        }
+    }
+    return result;
+}
+
+int flib_gameconn_send_chatmsg(flib_gameconn *conn, const char *playername, const char *msg) {
+    if(log_badargs_if3(conn==NULL, playername==NULL, msg==NULL)) {
+        return -1;
+    }
+    uint8_t converted[257];
+    if(!format_chatmessage(converted, playername, msg)
+            && !flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) {
+        demo_append(conn, converted, converted[0]+1);
+        return 0;
+    }
+    return -1;
+}
+
+int flib_gameconn_send_quit(flib_gameconn *conn) {
+    return flib_gameconn_send_cmd(conn, "efinish");
+}
+
+int flib_gameconn_send_cmd(flib_gameconn *conn, const char *cmdString) {
+    if(log_badargs_if2(conn==NULL, cmdString==NULL)) {
+        return -1;
+    }
+    int result = -1;
+    uint8_t converted[256];
+    size_t msglen = strlen(cmdString);
+    if(!log_e_if(msglen>255, "Message too long: %s", cmdString)) {
+        strcpy((char*)converted+1, cmdString);
+        converted[0] = msglen;
+        if(!flib_ipcbase_send_raw(conn->ipcBase, converted, msglen+1)) {
+            demo_append(conn, converted, msglen+1);
+            result = 0;
+        }
+    }
+    return result;
+}
+
+/**
+ * This macro generates a callback setter function. It uses the name of the callback to
+ * automatically generate the function name and the fields to set, so a consistent naming
+ * convention needs to be enforced (not that that is a bad thing). If null is passed as
+ * callback to the generated function, the defaultCb will be set instead (with conn
+ * as the context).
+ */
+#define GENERATE_CB_SETTER(cbName, cbParameterTypes, defaultCb) \
+    void flib_gameconn_##cbName(flib_gameconn *conn, void (*callback)cbParameterTypes, void *context) { \
+        if(!log_badargs_if(conn==NULL)) { \
+            conn->cbName##Cb = callback ? callback : &defaultCb; \
+            conn->cbName##Ctx = callback ? context : conn; \
+        } \
+    }
+
+/**
+ * Generate a callback setter function like GENERATE_CB_SETTER, and automatically generate a
+ * no-op callback function as well that is used as default.
+ */
+#define GENERATE_CB_SETTER_AND_DEFAULT(cbName, cbParameterTypes) \
+    static void _noop_callback_##cbName cbParameterTypes {} \
+    GENERATE_CB_SETTER(cbName, cbParameterTypes, _noop_callback_##cbName)
+
+GENERATE_CB_SETTER_AND_DEFAULT(onConnect, (void *context));
+GENERATE_CB_SETTER_AND_DEFAULT(onDisconnect, (void* context, int reason));
+GENERATE_CB_SETTER(onErrorMessage, (void* context, const char *msg), defaultCallback_onErrorMessage);
+GENERATE_CB_SETTER_AND_DEFAULT(onChat, (void* context, const char *msg, bool teamchat));
+GENERATE_CB_SETTER_AND_DEFAULT(onGameRecorded, (void *context, const uint8_t *record, size_t size, bool isSavegame));
+GENERATE_CB_SETTER_AND_DEFAULT(onEngineMessage, (void *context, const uint8_t *em, size_t size));
+
+#undef GENERATE_CB_SETTER_AND_DEFAULT
+#undef GENERATE_CB_SETTER
+
+static void flib_gameconn_wrappedtick(flib_gameconn *conn) {
+    if(conn->state == AWAIT_CONNECTION) {
+        flib_ipcbase_accept(conn->ipcBase);
+        switch(flib_ipcbase_state(conn->ipcBase)) {
+        case IPC_CONNECTED:
+            {
+                flib_constbuffer configBuffer = flib_vector_as_constbuffer(conn->configBuffer);
+                if(flib_ipcbase_send_raw(conn->ipcBase, configBuffer.data, configBuffer.size)) {
+                    conn->state = FINISHED;
+                    conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR);
+                    return;
+                } else {
+                    demo_append(conn, configBuffer.data, configBuffer.size);
+                    conn->state = CONNECTED;
+                    conn->onConnectCb(conn->onConnectCtx);
+                    if(conn->destroyRequested) {
+                        return;
+                    }
+                }
+            }
+            break;
+        case IPC_NOT_CONNECTED:
+            conn->state = FINISHED;
+            conn->onDisconnectCb(conn->onDisconnectCtx, GAME_END_ERROR);
+            return;
+        default:
+            break;
+        }
+    }
+
+    if(conn->state == CONNECTED) {
+        uint8_t msgbuffer[257];
+        int len;
+        while(!conn->destroyRequested && (len = flib_ipcbase_recv_message(conn->ipcBase, msgbuffer))>=0) {
+            if(len<2) {
+                flib_log_w("Received short message from IPC (<2 bytes)");
+                continue;
+            }
+            switch(msgbuffer[1]) {
+            case '?':   // Ping
+                // The pong is already part of the config message
+                break;
+            case 'C':   // Config query
+                // And we already send the config message on connecting.
+                break;
+            case 'E':   // Error message
+                if(len>=3) {
+                    msgbuffer[len-2] = 0;
+                    conn->onErrorMessageCb(conn->onErrorMessageCtx, (char*)msgbuffer+2);
+                }
+                break;
+            case 'i':   // Statistics
+                // TODO stats
+                break;
+            case 'Q':   // Game interrupted
+            case 'H':   // Game halted
+            case 'q':   // game finished
+                {
+                    int reason = msgbuffer[1]=='Q' ? GAME_END_INTERRUPTED : msgbuffer[1]=='H' ? GAME_END_HALTED : GAME_END_FINISHED;
+                    conn->disconnectReason = reason;
+                    bool savegame = (reason != GAME_END_FINISHED) && !conn->netgame;
+                    if(conn->demoBuffer) {
+                        flib_buffer demoBuffer = flib_vector_as_buffer(conn->demoBuffer);
+                        demo_replace_gamemode(demoBuffer, savegame ? 'S' : 'D');
+                        conn->onGameRecordedCb(conn->onGameRecordedCtx, demoBuffer.data, demoBuffer.size, savegame);
+                        if(conn->destroyRequested) {
+                            return;
+                        }
+                    }
+                    return;
+                }
+            case 's':   // Chat message
+                if(len>=3) {
+                    msgbuffer[len-2] = 0;
+                    demo_append_chatmessage(conn, (char*)msgbuffer+2);
+
+                    conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, false);
+                }
+                break;
+            case 'b':   // Teamchat message
+                if(len>=3) {
+                    msgbuffer[len-2] = 0;
+                    conn->onChatCb(conn->onChatCtx, (char*)msgbuffer+2, true);
+                }
+                break;
+            default:    // Engine message
+                demo_append(conn, msgbuffer, len);
+
+                conn->onEngineMessageCb(conn->onEngineMessageCtx, msgbuffer, len);
+                break;
+            }
+        }
+    }
+
+    if(flib_ipcbase_state(conn->ipcBase) == IPC_NOT_CONNECTED) {
+        conn->state = FINISHED;
+        conn->onDisconnectCb(conn->onDisconnectCtx, conn->disconnectReason);
+    }
+}
+
+void flib_gameconn_tick(flib_gameconn *conn) {
+    if(!log_badargs_if(conn == NULL)
+            && !log_w_if(conn->running, "Call to flib_gameconn_tick from a callback")
+            && !log_w_if(conn->state == FINISHED, "We are already done.")) {
+        conn->running = true;
+        flib_gameconn_wrappedtick(conn);
+        conn->running = false;
+
+        if(conn->destroyRequested) {
+            flib_gameconn_destroy(conn);
+        }
+    }
+}
--- a/project_files/frontlib/ipc/gameconn.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/ipc/gameconn.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,179 +1,179 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * This file contains functions for starting and interacting with a game run by the engine.
- * The general usage is to first create a gameconn object by calling one of the flib_gameconn_create
- * functions. That will cause the frontlib to listen on a random port which can be queried using
- * flib_gameconn_getport(). You should also register your callback functions right at the start
- * to ensure you don't miss any callbacks.
- *
- * Next, start the engine (that part is up to you) with the appropriate command line arguments
- * for starting a game.
- *
- * In order to allow the gameconn to run, you should regularly call flib_gameconn_tick(), which
- * performs network I/O and calls your callbacks on interesting events.
- *
- * Once the engine connects, the gameconn will send it the required commands for starting the
- * game you requested in your flib_gameconn_create call.
- *
- * When the game is finished (or the connection is lost), you will receive the onDisconnect
- * message. This is the signal to destroy the gameconn and stop calling tick().
- */
-
-#ifndef GAMECONN_H_
-#define GAMECONN_H_
-
-#include "../model/gamesetup.h"
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-/*
- * Different reasons for a disconnect. Only GAME_END_FINISHED signals a correctly completed game.
- */
-#define GAME_END_FINISHED 0
-#define GAME_END_INTERRUPTED 1
-#define GAME_END_HALTED 2
-#define GAME_END_ERROR 3
-
-typedef struct _flib_gameconn flib_gameconn;
-
-/**
- * Create a gameconn that will start a local or network game with the indicated configuration.
- */
-flib_gameconn *flib_gameconn_create(const char *playerName, const flib_gamesetup *setup, bool netgame);
-
-/**
- * Create a gameconn that will play back a demo.
- */
-flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demoFileContent, size_t size);
-
-/**
- * Create a gameconn that will continue from a saved game.
- */
-flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *saveFileContent, size_t size);
-
-/**
- * Create a gameconn that will start a campaign or training mission with the indicated script.
- * seed is the random seed to use as entropy source (any string).
- * script is the path and filename of a Campaign or Training script, relative to the Data directory
- * (e.g. "Missions/Training/Basic_Training_-_Bazooka.lua")
- */
-flib_gameconn *flib_gameconn_create_campaign(const char *playerName, const char *seed, const char *script);
-
-/**
- * Release all resources of this gameconn, including the network connection, and free its memory.
- * It is safe to call this function from a callback.
- */
-void flib_gameconn_destroy(flib_gameconn *conn);
-
-/**
- * Returns the port on which the gameconn is listening. Only fails if you
- * pass NULL (not allowed), in that case 0 is returned.
- */
-int flib_gameconn_getport(flib_gameconn *conn);
-
-/**
- * Perform I/O operations and call callbacks if something interesting happens.
- * Should be called regularly.
- */
-void flib_gameconn_tick(flib_gameconn *conn);
-
-/**
- * Send an engine message to the engine. Only needed in net games, where you receive engine
- * messages from the server and have to pass them here.
- */
-int flib_gameconn_send_enginemsg(flib_gameconn *conn, const uint8_t *data, size_t len);
-
-/**
- * Send an info message to the engine that will be displayed in the game's chatlog.
- * The msgtype determines the color of the message;  in the QTFrontend, info messages and
- * normal chat messages use 1, emote-messages (those starting with /me) use 2, and
- * join/leave messages use 3. You should use flib_gameconn_send_chatmsg for chat messages
- * though because it automatically formats /me messages.
- *
- * Generally only needed in net games.
- */
-int flib_gameconn_send_textmsg(flib_gameconn *conn, int msgtype, const char *msg);
-
-/**
- * Send a chat message to be displayed in the game's chatlog. Messages starting with /me are
- * automatically formatted correctly.
- *
- * Generally only needed in net games.
- */
-int flib_gameconn_send_chatmsg(flib_gameconn *conn, const char *playername, const char *msg);
-
-/**
- * Request the engine to stop the game (efinish).
- * You can use this to shut down a game early without directly killing the engine process.
- */
-int flib_gameconn_send_quit(flib_gameconn *conn);
-
-/**
- * Send an arbitrary command to the engine, e.g. "eforcequit" to shut down the engine
- * quickly. Commands prefixed with "e" will be processed by the engine's ProcessCommand
- * method (with the e removed, so e.g. efinish will be parsed as finish).
- */
-int flib_gameconn_send_cmd(flib_gameconn *conn, const char *cmdString);
-
-/**
- * Expected callback signature: void handleConnect(void *context)
- * The engine has successfully connected. You don't have to react to this in any way.
- */
-void flib_gameconn_onConnect(flib_gameconn *conn, void (*callback)(void* context), void* context);
-
-/**
- * Expected callback signature: void handleDisconnect(void *context, int reason)
- * The connection to the engine was closed, either because the game has ended normally, or
- * because it was interrupted/halted, or because of an error. The reason is provided as one
- * of the GAME_END_xxx constants.
- *
- * You should destroy the gameconn and - in a netgame - notify the server that the game has ended.
- */
-void flib_gameconn_onDisconnect(flib_gameconn *conn, void (*callback)(void* context, int reason), void* context);
-
-/**
- * Expected callback signature: void handleErrorMessage(void* context, const char *msg)
- * The engine sent an error message, you should probably display it to the user or at least log it.
- */
-void flib_gameconn_onErrorMessage(flib_gameconn *conn, void (*callback)(void* context, const char *msg), void* context);
-
-/**
- * Expected callback signature: void handleChat(void* context, const char *msg, bool teamchat)
- * The player entered a chat or teamchat message. In a netgame, you should send it on to the server.
- */
-void flib_gameconn_onChat(flib_gameconn *conn, void (*callback)(void* context, const char *msg, bool teamchat), void* context);
-
-/**
- * Expected callback signature: void handleGameRecorded(void *context, const uint8_t *record, size_t size, bool isSavegame)
- * The game has stopped, and a demo or savegame is available. You can store it in a file and later pass it back
- * to the engine to either watch a replay (if it's a demo) or to continue playing (if it's a savegame).
- */
-void flib_gameconn_onGameRecorded(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *record, size_t size, bool isSavegame), void* context);
-
-/**
- * Expected callback signature: void handleEngineMessage(void *context, const uint8_t *em, size_t size)
- * The engine has generated a message with player input. In a netgame, you should send it on to the server.
- */
-void flib_gameconn_onEngineMessage(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *em, size_t size), void* context);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * This file contains functions for starting and interacting with a game run by the engine.
+ * The general usage is to first create a gameconn object by calling one of the flib_gameconn_create
+ * functions. That will cause the frontlib to listen on a random port which can be queried using
+ * flib_gameconn_getport(). You should also register your callback functions right at the start
+ * to ensure you don't miss any callbacks.
+ *
+ * Next, start the engine (that part is up to you) with the appropriate command line arguments
+ * for starting a game.
+ *
+ * In order to allow the gameconn to run, you should regularly call flib_gameconn_tick(), which
+ * performs network I/O and calls your callbacks on interesting events.
+ *
+ * Once the engine connects, the gameconn will send it the required commands for starting the
+ * game you requested in your flib_gameconn_create call.
+ *
+ * When the game is finished (or the connection is lost), you will receive the onDisconnect
+ * message. This is the signal to destroy the gameconn and stop calling tick().
+ */
+
+#ifndef GAMECONN_H_
+#define GAMECONN_H_
+
+#include "../model/gamesetup.h"
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+/*
+ * Different reasons for a disconnect. Only GAME_END_FINISHED signals a correctly completed game.
+ */
+#define GAME_END_FINISHED 0
+#define GAME_END_INTERRUPTED 1
+#define GAME_END_HALTED 2
+#define GAME_END_ERROR 3
+
+typedef struct _flib_gameconn flib_gameconn;
+
+/**
+ * Create a gameconn that will start a local or network game with the indicated configuration.
+ */
+flib_gameconn *flib_gameconn_create(const char *playerName, const flib_gamesetup *setup, bool netgame);
+
+/**
+ * Create a gameconn that will play back a demo.
+ */
+flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demoFileContent, size_t size);
+
+/**
+ * Create a gameconn that will continue from a saved game.
+ */
+flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *saveFileContent, size_t size);
+
+/**
+ * Create a gameconn that will start a campaign or training mission with the indicated script.
+ * seed is the random seed to use as entropy source (any string).
+ * script is the path and filename of a Campaign or Training script, relative to the Data directory
+ * (e.g. "Missions/Training/Basic_Training_-_Bazooka.lua")
+ */
+flib_gameconn *flib_gameconn_create_campaign(const char *playerName, const char *seed, const char *script);
+
+/**
+ * Release all resources of this gameconn, including the network connection, and free its memory.
+ * It is safe to call this function from a callback.
+ */
+void flib_gameconn_destroy(flib_gameconn *conn);
+
+/**
+ * Returns the port on which the gameconn is listening. Only fails if you
+ * pass NULL (not allowed), in that case 0 is returned.
+ */
+int flib_gameconn_getport(flib_gameconn *conn);
+
+/**
+ * Perform I/O operations and call callbacks if something interesting happens.
+ * Should be called regularly.
+ */
+void flib_gameconn_tick(flib_gameconn *conn);
+
+/**
+ * Send an engine message to the engine. Only needed in net games, where you receive engine
+ * messages from the server and have to pass them here.
+ */
+int flib_gameconn_send_enginemsg(flib_gameconn *conn, const uint8_t *data, size_t len);
+
+/**
+ * Send an info message to the engine that will be displayed in the game's chatlog.
+ * The msgtype determines the color of the message;  in the QTFrontend, info messages and
+ * normal chat messages use 1, emote-messages (those starting with /me) use 2, and
+ * join/leave messages use 3. You should use flib_gameconn_send_chatmsg for chat messages
+ * though because it automatically formats /me messages.
+ *
+ * Generally only needed in net games.
+ */
+int flib_gameconn_send_textmsg(flib_gameconn *conn, int msgtype, const char *msg);
+
+/**
+ * Send a chat message to be displayed in the game's chatlog. Messages starting with /me are
+ * automatically formatted correctly.
+ *
+ * Generally only needed in net games.
+ */
+int flib_gameconn_send_chatmsg(flib_gameconn *conn, const char *playername, const char *msg);
+
+/**
+ * Request the engine to stop the game (efinish).
+ * You can use this to shut down a game early without directly killing the engine process.
+ */
+int flib_gameconn_send_quit(flib_gameconn *conn);
+
+/**
+ * Send an arbitrary command to the engine, e.g. "eforcequit" to shut down the engine
+ * quickly. Commands prefixed with "e" will be processed by the engine's ProcessCommand
+ * method (with the e removed, so e.g. efinish will be parsed as finish).
+ */
+int flib_gameconn_send_cmd(flib_gameconn *conn, const char *cmdString);
+
+/**
+ * Expected callback signature: void handleConnect(void *context)
+ * The engine has successfully connected. You don't have to react to this in any way.
+ */
+void flib_gameconn_onConnect(flib_gameconn *conn, void (*callback)(void* context), void* context);
+
+/**
+ * Expected callback signature: void handleDisconnect(void *context, int reason)
+ * The connection to the engine was closed, either because the game has ended normally, or
+ * because it was interrupted/halted, or because of an error. The reason is provided as one
+ * of the GAME_END_xxx constants.
+ *
+ * You should destroy the gameconn and - in a netgame - notify the server that the game has ended.
+ */
+void flib_gameconn_onDisconnect(flib_gameconn *conn, void (*callback)(void* context, int reason), void* context);
+
+/**
+ * Expected callback signature: void handleErrorMessage(void* context, const char *msg)
+ * The engine sent an error message, you should probably display it to the user or at least log it.
+ */
+void flib_gameconn_onErrorMessage(flib_gameconn *conn, void (*callback)(void* context, const char *msg), void* context);
+
+/**
+ * Expected callback signature: void handleChat(void* context, const char *msg, bool teamchat)
+ * The player entered a chat or teamchat message. In a netgame, you should send it on to the server.
+ */
+void flib_gameconn_onChat(flib_gameconn *conn, void (*callback)(void* context, const char *msg, bool teamchat), void* context);
+
+/**
+ * Expected callback signature: void handleGameRecorded(void *context, const uint8_t *record, size_t size, bool isSavegame)
+ * The game has stopped, and a demo or savegame is available. You can store it in a file and later pass it back
+ * to the engine to either watch a replay (if it's a demo) or to continue playing (if it's a savegame).
+ */
+void flib_gameconn_onGameRecorded(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *record, size_t size, bool isSavegame), void* context);
+
+/**
+ * Expected callback signature: void handleEngineMessage(void *context, const uint8_t *em, size_t size)
+ * The engine has generated a message with player input. In a netgame, you should send it on to the server.
+ */
+void flib_gameconn_onEngineMessage(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *em, size_t size), void* context);
+
+#endif
--- a/project_files/frontlib/ipc/ipcbase.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/ipc/ipcbase.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,216 +1,216 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "ipcbase.h"
-#include "../util/logging.h"
-#include "../util/util.h"
-#include "../socket.h"
-
-#include <string.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-/*
- * The receive buffer has to be able to hold any message that might be received. Normally
- * the messages are at most 256 bytes, but the map preview contains 4097 bytes (4096 for a
- * bitmap, 1 for the number of hogs which fit on the map).
- *
- * We don't need to worry about wasting a few kb though, and I like powers of two...
- */
-struct _flib_ipcbase {
-	uint8_t readBuffer[8192];
-	int readBufferSize;
-
-	flib_acceptor *acceptor;
-	uint16_t port;
-
-	flib_tcpsocket *sock;
-};
-
-flib_ipcbase *flib_ipcbase_create() {
-	flib_ipcbase *result = flib_calloc(1, sizeof(flib_ipcbase));
-	flib_acceptor *acceptor = flib_acceptor_create(0);
-
-	if(!result || !acceptor) {
-		free(result);
-		flib_acceptor_close(acceptor);
-		return NULL;
-	}
-
-	result->acceptor = acceptor;
-	result->sock = NULL;
-	result->readBufferSize = 0;
-	result->port = flib_acceptor_listenport(acceptor);
-
-	flib_log_i("Started listening for IPC connections on port %u", (unsigned)result->port);
-	return result;
-}
-
-uint16_t flib_ipcbase_port(flib_ipcbase *ipc) {
-	if(log_badargs_if(ipc==NULL)) {
-		return 0;
-	}
-	return ipc->port;
-}
-
-void flib_ipcbase_destroy(flib_ipcbase *ipc) {
-	if(ipc) {
-		flib_acceptor_close(ipc->acceptor);
-		flib_socket_close(ipc->sock);
-		if(ipc->sock) {
-			flib_log_d("IPC connection closed.");
-		}
-		free(ipc);
-	}
-}
-
-IpcState flib_ipcbase_state(flib_ipcbase *ipc) {
-	if(log_badargs_if(ipc==NULL)) {
-		return IPC_NOT_CONNECTED;
-	} else if(ipc->sock) {
-		return IPC_CONNECTED;
-	} else if(ipc->acceptor) {
-		return IPC_LISTENING;
-	} else {
-		return IPC_NOT_CONNECTED;
-	}
-}
-
-static void receiveToBuffer(flib_ipcbase *ipc) {
-	if(ipc->sock) {
-		int size = flib_socket_nbrecv(ipc->sock, ipc->readBuffer+ipc->readBufferSize, sizeof(ipc->readBuffer)-ipc->readBufferSize);
-		if(size>=0) {
-			ipc->readBufferSize += size;
-		} else {
-			flib_log_d("IPC connection lost.");
-			flib_socket_close(ipc->sock);
-			ipc->sock = NULL;
-		}
-	}
-}
-
-static bool isMessageReady(flib_ipcbase *ipc) {
-	return ipc->readBufferSize >= ipc->readBuffer[0]+1;
-}
-
-static void logSentMsg(const uint8_t *data, size_t len) {
-	if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) {
-		size_t msgStart = 0;
-		while(msgStart < len) {
-			uint8_t msglen = data[msgStart];
-			if(msgStart+msglen < len) {
-				flib_log_d("[IPC OUT][%03u]%*.*s",(unsigned)msglen, (unsigned)msglen, (unsigned)msglen, data+msgStart+1);
-			} else {
-				uint8_t msglen2 = len-msgStart-1;
-				flib_log_d("[IPC OUT][%03u/%03u]%*.*s",(unsigned)msglen2, (unsigned)msglen, (unsigned)msglen2, (unsigned)msglen2, data+msgStart+1);
-			}
-			msgStart += (uint8_t)data[msgStart]+1;
-		}
-	}
-}
-
-static void logRecvMsg(const uint8_t *data) {
-	if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) {
-		uint8_t msglen = data[0];
-		flib_log_d("[IPC IN][%03u]%*.*s",(unsigned)msglen, (unsigned)msglen, (unsigned)msglen, data+1);
-	}
-}
-
-static void popFromReadBuffer(flib_ipcbase *ipc, uint8_t *outbuf, size_t size) {
-	memcpy(outbuf, ipc->readBuffer, size);
-	memmove(ipc->readBuffer, ipc->readBuffer+size, ipc->readBufferSize-size);
-	ipc->readBufferSize -= size;
-}
-
-int flib_ipcbase_recv_message(flib_ipcbase *ipc, void *data) {
-	if(log_badargs_if2(ipc==NULL, data==NULL)) {
-		return -1;
-	}
-
-	if(!isMessageReady(ipc)) {
-		receiveToBuffer(ipc);
-	}
-
-	if(isMessageReady(ipc)) {
-		int msgsize = ipc->readBuffer[0]+1;
-		popFromReadBuffer(ipc, data, msgsize);
-		logRecvMsg(data);
-		return msgsize;
-	} else if(!ipc->sock && ipc->readBufferSize>0) {
-		flib_log_w("Last message from engine data stream is incomplete (received %u of %u bytes)", (unsigned)ipc->readBufferSize, (unsigned)(ipc->readBuffer[0])+1);
-		ipc->readBufferSize = 0;
-		return -1;
-	} else {
-		return -1;
-	}
-}
-
-int flib_ipcbase_recv_map(flib_ipcbase *ipc, void *data) {
-	if(log_badargs_if2(ipc==NULL, data==NULL)) {
-		return -1;
-	}
-
-	receiveToBuffer(ipc);
-
-	if(ipc->readBufferSize >= IPCBASE_MAPMSG_BYTES) {
-		popFromReadBuffer(ipc, data, IPCBASE_MAPMSG_BYTES);
-		return IPCBASE_MAPMSG_BYTES;
-	} else {
-		return -1;
-	}
-}
-
-int flib_ipcbase_send_raw(flib_ipcbase *ipc, const void *data, size_t len) {
-	if(log_badargs_if2(ipc==NULL, data==NULL && len>0)
-			|| log_w_if(!ipc->sock, "flib_ipcbase_send_raw: Not connected.")) {
-		return -1;
-	}
-	if(flib_socket_send(ipc->sock, data, len) == len) {
-		logSentMsg(data, len);
-		return 0;
-	} else {
-		flib_log_w("Failed or incomplete IPC write: engine connection lost.");
-		flib_socket_close(ipc->sock);
-		ipc->sock = NULL;
-		return -1;
-	}
-}
-
-int flib_ipcbase_send_message(flib_ipcbase *ipc, void *data, size_t len) {
-	if(log_badargs_if3(ipc==NULL, data==NULL && len>0, len>255)) {
-		return -1;
-	}
-
-	uint8_t sendbuf[256];
-	sendbuf[0] = len;
-	memcpy(sendbuf+1, data, len);
-	return flib_ipcbase_send_raw(ipc, sendbuf, len+1);
-}
-
-void flib_ipcbase_accept(flib_ipcbase *ipc) {
-	if(!log_badargs_if(ipc==NULL) && !ipc->sock && ipc->acceptor) {
-		ipc->sock = flib_socket_accept(ipc->acceptor, true);
-		if(ipc->sock) {
-			flib_log_d("IPC connection accepted.");
-			flib_acceptor_close(ipc->acceptor);
-			ipc->acceptor = NULL;
-		}
-	}
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "ipcbase.h"
+#include "../util/logging.h"
+#include "../util/util.h"
+#include "../socket.h"
+
+#include <string.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/*
+ * The receive buffer has to be able to hold any message that might be received. Normally
+ * the messages are at most 256 bytes, but the map preview contains 4097 bytes (4096 for a
+ * bitmap, 1 for the number of hogs which fit on the map).
+ *
+ * We don't need to worry about wasting a few kb though, and I like powers of two...
+ */
+struct _flib_ipcbase {
+    uint8_t readBuffer[8192];
+    int readBufferSize;
+
+    flib_acceptor *acceptor;
+    uint16_t port;
+
+    flib_tcpsocket *sock;
+};
+
+flib_ipcbase *flib_ipcbase_create() {
+    flib_ipcbase *result = flib_calloc(1, sizeof(flib_ipcbase));
+    flib_acceptor *acceptor = flib_acceptor_create(0);
+
+    if(!result || !acceptor) {
+        free(result);
+        flib_acceptor_close(acceptor);
+        return NULL;
+    }
+
+    result->acceptor = acceptor;
+    result->sock = NULL;
+    result->readBufferSize = 0;
+    result->port = flib_acceptor_listenport(acceptor);
+
+    flib_log_i("Started listening for IPC connections on port %u", (unsigned)result->port);
+    return result;
+}
+
+uint16_t flib_ipcbase_port(flib_ipcbase *ipc) {
+    if(log_badargs_if(ipc==NULL)) {
+        return 0;
+    }
+    return ipc->port;
+}
+
+void flib_ipcbase_destroy(flib_ipcbase *ipc) {
+    if(ipc) {
+        flib_acceptor_close(ipc->acceptor);
+        flib_socket_close(ipc->sock);
+        if(ipc->sock) {
+            flib_log_d("IPC connection closed.");
+        }
+        free(ipc);
+    }
+}
+
+IpcState flib_ipcbase_state(flib_ipcbase *ipc) {
+    if(log_badargs_if(ipc==NULL)) {
+        return IPC_NOT_CONNECTED;
+    } else if(ipc->sock) {
+        return IPC_CONNECTED;
+    } else if(ipc->acceptor) {
+        return IPC_LISTENING;
+    } else {
+        return IPC_NOT_CONNECTED;
+    }
+}
+
+static void receiveToBuffer(flib_ipcbase *ipc) {
+    if(ipc->sock) {
+        int size = flib_socket_nbrecv(ipc->sock, ipc->readBuffer+ipc->readBufferSize, sizeof(ipc->readBuffer)-ipc->readBufferSize);
+        if(size>=0) {
+            ipc->readBufferSize += size;
+        } else {
+            flib_log_d("IPC connection lost.");
+            flib_socket_close(ipc->sock);
+            ipc->sock = NULL;
+        }
+    }
+}
+
+static bool isMessageReady(flib_ipcbase *ipc) {
+    return ipc->readBufferSize >= ipc->readBuffer[0]+1;
+}
+
+static void logSentMsg(const uint8_t *data, size_t len) {
+    if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) {
+        size_t msgStart = 0;
+        while(msgStart < len) {
+            uint8_t msglen = data[msgStart];
+            if(msgStart+msglen < len) {
+                flib_log_d("[IPC OUT][%03u]%*.*s",(unsigned)msglen, (unsigned)msglen, (unsigned)msglen, data+msgStart+1);
+            } else {
+                uint8_t msglen2 = len-msgStart-1;
+                flib_log_d("[IPC OUT][%03u/%03u]%*.*s",(unsigned)msglen2, (unsigned)msglen, (unsigned)msglen2, (unsigned)msglen2, data+msgStart+1);
+            }
+            msgStart += (uint8_t)data[msgStart]+1;
+        }
+    }
+}
+
+static void logRecvMsg(const uint8_t *data) {
+    if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) {
+        uint8_t msglen = data[0];
+        flib_log_d("[IPC IN][%03u]%*.*s",(unsigned)msglen, (unsigned)msglen, (unsigned)msglen, data+1);
+    }
+}
+
+static void popFromReadBuffer(flib_ipcbase *ipc, uint8_t *outbuf, size_t size) {
+    memcpy(outbuf, ipc->readBuffer, size);
+    memmove(ipc->readBuffer, ipc->readBuffer+size, ipc->readBufferSize-size);
+    ipc->readBufferSize -= size;
+}
+
+int flib_ipcbase_recv_message(flib_ipcbase *ipc, void *data) {
+    if(log_badargs_if2(ipc==NULL, data==NULL)) {
+        return -1;
+    }
+
+    if(!isMessageReady(ipc)) {
+        receiveToBuffer(ipc);
+    }
+
+    if(isMessageReady(ipc)) {
+        int msgsize = ipc->readBuffer[0]+1;
+        popFromReadBuffer(ipc, data, msgsize);
+        logRecvMsg(data);
+        return msgsize;
+    } else if(!ipc->sock && ipc->readBufferSize>0) {
+        flib_log_w("Last message from engine data stream is incomplete (received %u of %u bytes)", (unsigned)ipc->readBufferSize, (unsigned)(ipc->readBuffer[0])+1);
+        ipc->readBufferSize = 0;
+        return -1;
+    } else {
+        return -1;
+    }
+}
+
+int flib_ipcbase_recv_map(flib_ipcbase *ipc, void *data) {
+    if(log_badargs_if2(ipc==NULL, data==NULL)) {
+        return -1;
+    }
+
+    receiveToBuffer(ipc);
+
+    if(ipc->readBufferSize >= IPCBASE_MAPMSG_BYTES) {
+        popFromReadBuffer(ipc, data, IPCBASE_MAPMSG_BYTES);
+        return IPCBASE_MAPMSG_BYTES;
+    } else {
+        return -1;
+    }
+}
+
+int flib_ipcbase_send_raw(flib_ipcbase *ipc, const void *data, size_t len) {
+    if(log_badargs_if2(ipc==NULL, data==NULL && len>0)
+            || log_w_if(!ipc->sock, "flib_ipcbase_send_raw: Not connected.")) {
+        return -1;
+    }
+    if(flib_socket_send(ipc->sock, data, len) == len) {
+        logSentMsg(data, len);
+        return 0;
+    } else {
+        flib_log_w("Failed or incomplete IPC write: engine connection lost.");
+        flib_socket_close(ipc->sock);
+        ipc->sock = NULL;
+        return -1;
+    }
+}
+
+int flib_ipcbase_send_message(flib_ipcbase *ipc, void *data, size_t len) {
+    if(log_badargs_if3(ipc==NULL, data==NULL && len>0, len>255)) {
+        return -1;
+    }
+
+    uint8_t sendbuf[256];
+    sendbuf[0] = len;
+    memcpy(sendbuf+1, data, len);
+    return flib_ipcbase_send_raw(ipc, sendbuf, len+1);
+}
+
+void flib_ipcbase_accept(flib_ipcbase *ipc) {
+    if(!log_badargs_if(ipc==NULL) && !ipc->sock && ipc->acceptor) {
+        ipc->sock = flib_socket_accept(ipc->acceptor, true);
+        if(ipc->sock) {
+            flib_log_d("IPC connection accepted.");
+            flib_acceptor_close(ipc->acceptor);
+            ipc->acceptor = NULL;
+        }
+    }
+}
--- a/project_files/frontlib/ipc/ipcbase.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/ipc/ipcbase.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,105 +1,105 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/*
- * Low-level protocol support for the IPC connection to the engine.
- */
-#ifndef IPCBASE_H_
-#define IPCBASE_H_
-
-#include <stddef.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#define IPCBASE_MAPMSG_BYTES 4097
-
-typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcState;
-
-typedef struct _flib_ipcbase flib_ipcbase;
-
-/**
- * Start an engine connection by listening on a random port. The selected port can
- * be queried with flib_ipcbase_port and has to be passed to the engine.
- *
- * Returns NULL on error. Destroy the created object with flib_ipcbase_destroy.
- *
- * We stop accepting new connections once a connection has been established, so you
- * need to create a new ipcbase in order to start a new connection.
- */
-flib_ipcbase *flib_ipcbase_create();
-
-/**
- * Return the listening port
- */
-uint16_t flib_ipcbase_port(flib_ipcbase *ipc);
-
-/**
- * Free resources and close sockets. NULL safe.
- */
-void flib_ipcbase_destroy(flib_ipcbase *ipc);
-
-/**
- * Determine the current connection state
- */
-IpcState flib_ipcbase_state(flib_ipcbase *ipc);
-
-/**
- * Receive a single message (up to 256 bytes) and copy it into the data buffer.
- * Returns the length of the received message, a negative value if no message could
- * be read.
- *
- * The first byte of a message is its content length, which is one less than the returned
- * value.
- *
- * Note: When a connection is closed, you probably want to call this function until
- * no further message is returned, to ensure you see all messages that were sent
- * before the connection closed.
- */
-int flib_ipcbase_recv_message(flib_ipcbase *ipc, void *data);
-
-/**
- * Try to receive 4097 bytes. This is the size of the reply the engine sends
- * when successfully queried for map data. The first 4096 bytes are a bit-packed
- * twocolor image of the map (256x128), the last byte is the number of hogs that
- * fit on the map.
- */
-int flib_ipcbase_recv_map(flib_ipcbase *ipc, void *data);
-
-/**
- * Blocking send bytes over the socket. No message framing will be added.
- * Returns 0 on success.
- */
-int flib_ipcbase_send_raw(flib_ipcbase *ipc, const void *data, size_t len);
-
-/**
- * Write a single message (up to 255 bytes) to the engine. This call blocks until the
- * message is completely written or the connection is closed or an error occurs.
- *
- * Calling this function in a state other than IPC_CONNECTED will fail immediately.
- * Returns 0 on success.
- */
-int flib_ipcbase_send_message(flib_ipcbase *ipc, void *data, size_t len);
-
-/**
- * Try to accept a connection. Only has an effect in state IPC_LISTENING.
- */
-void flib_ipcbase_accept(flib_ipcbase *ipc);
-
-#endif /* IPCBASE_H_ */
-
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/*
+ * Low-level protocol support for the IPC connection to the engine.
+ */
+#ifndef IPCBASE_H_
+#define IPCBASE_H_
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#define IPCBASE_MAPMSG_BYTES 4097
+
+typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcState;
+
+typedef struct _flib_ipcbase flib_ipcbase;
+
+/**
+ * Start an engine connection by listening on a random port. The selected port can
+ * be queried with flib_ipcbase_port and has to be passed to the engine.
+ *
+ * Returns NULL on error. Destroy the created object with flib_ipcbase_destroy.
+ *
+ * We stop accepting new connections once a connection has been established, so you
+ * need to create a new ipcbase in order to start a new connection.
+ */
+flib_ipcbase *flib_ipcbase_create();
+
+/**
+ * Return the listening port
+ */
+uint16_t flib_ipcbase_port(flib_ipcbase *ipc);
+
+/**
+ * Free resources and close sockets. NULL safe.
+ */
+void flib_ipcbase_destroy(flib_ipcbase *ipc);
+
+/**
+ * Determine the current connection state
+ */
+IpcState flib_ipcbase_state(flib_ipcbase *ipc);
+
+/**
+ * Receive a single message (up to 256 bytes) and copy it into the data buffer.
+ * Returns the length of the received message, a negative value if no message could
+ * be read.
+ *
+ * The first byte of a message is its content length, which is one less than the returned
+ * value.
+ *
+ * Note: When a connection is closed, you probably want to call this function until
+ * no further message is returned, to ensure you see all messages that were sent
+ * before the connection closed.
+ */
+int flib_ipcbase_recv_message(flib_ipcbase *ipc, void *data);
+
+/**
+ * Try to receive 4097 bytes. This is the size of the reply the engine sends
+ * when successfully queried for map data. The first 4096 bytes are a bit-packed
+ * twocolor image of the map (256x128), the last byte is the number of hogs that
+ * fit on the map.
+ */
+int flib_ipcbase_recv_map(flib_ipcbase *ipc, void *data);
+
+/**
+ * Blocking send bytes over the socket. No message framing will be added.
+ * Returns 0 on success.
+ */
+int flib_ipcbase_send_raw(flib_ipcbase *ipc, const void *data, size_t len);
+
+/**
+ * Write a single message (up to 255 bytes) to the engine. This call blocks until the
+ * message is completely written or the connection is closed or an error occurs.
+ *
+ * Calling this function in a state other than IPC_CONNECTED will fail immediately.
+ * Returns 0 on success.
+ */
+int flib_ipcbase_send_message(flib_ipcbase *ipc, void *data, size_t len);
+
+/**
+ * Try to accept a connection. Only has an effect in state IPC_LISTENING.
+ */
+void flib_ipcbase_accept(flib_ipcbase *ipc);
+
+#endif /* IPCBASE_H_ */
+
--- a/project_files/frontlib/ipc/ipcprotocol.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/ipc/ipcprotocol.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,316 +1,316 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "ipcprotocol.h"
-#include "../util/util.h"
-#include "../util/logging.h"
-#include "../md5/md5.h"
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdlib.h>
-
-int flib_ipc_append_message(flib_vector *vec, const char *fmt, ...) {
-	int result = -1;
-	if(!log_badargs_if2(vec==NULL, fmt==NULL)) {
-		// 1 byte size prefix, 255 bytes max message length, 1 0-byte for vsnprintf
-		char msgbuffer[257];
-
-		// Format the message, leaving one byte at the start for the length
-		va_list argp;
-		va_start(argp, fmt);
-		int msgSize = vsnprintf(msgbuffer+1, 256, fmt, argp);
-		va_end(argp);
-
-		if(!log_e_if(msgSize > 255, "Message too long (%u bytes)", (unsigned)msgSize)
-				&& !log_e_if(msgSize < 0, "printf error")) {
-			// Add the length prefix
-			((uint8_t*)msgbuffer)[0] = msgSize;
-
-			// Append it to the vector
-			result = flib_vector_append(vec, msgbuffer, msgSize+1);
-		}
-	}
-	return result;
-}
-
-int flib_ipc_append_mapconf(flib_vector *vec, const flib_map *map, bool mappreview) {
-	int result = -1;
-	flib_vector *tempvector = flib_vector_create();
-	if(!log_badargs_if2(vec==NULL, map==NULL)) {
-		bool error = false;
-
-		if(map->mapgen == MAPGEN_NAMED) {
-			error |= log_e_if(!map->name, "Missing map name")
-					|| flib_ipc_append_message(tempvector, "emap %s", map->name);
-		}
-		if(!mappreview) {
-			error |= log_e_if(!map->theme, "Missing map theme")
-					|| flib_ipc_append_message(tempvector, "etheme %s", map->theme);
-		}
-		error |= flib_ipc_append_seed(tempvector, map->seed);
-		error |= flib_ipc_append_message(tempvector, "e$template_filter %i", map->templateFilter);
-		error |= flib_ipc_append_message(tempvector, "e$mapgen %i", map->mapgen);
-
-		if(map->mapgen == MAPGEN_MAZE) {
-			error |= flib_ipc_append_message(tempvector, "e$maze_size %i", map->mazeSize);
-		}
-		if(map->mapgen == MAPGEN_DRAWN) {
-			/*
-			 * We have to split the drawn map data into several edraw messages here because
-			 * it can be longer than the maximum message size.
-			 */
-			const char *edraw = "edraw ";
-			int edrawlen = strlen(edraw);
-			for(size_t offset=0; offset<map->drawDataSize; offset+=200) {
-				size_t bytesRemaining = map->drawDataSize-offset;
-				int fragmentsize = bytesRemaining < 200 ? bytesRemaining : 200;
-				uint8_t messagesize = edrawlen + fragmentsize;
-				error |= flib_vector_append(tempvector, &messagesize, 1);
-				error |= flib_vector_append(tempvector, edraw, edrawlen);
-				error |= flib_vector_append(tempvector, map->drawData+offset, fragmentsize);
-			}
-		}
-
-		if(!log_e_if(error, "Error generating map config")) {
-			// Message created, now we can copy everything.
-			flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
-			if(!flib_vector_append(vec, constbuf.data, constbuf.size)) {
-				result = 0;
-			}
-		}
-	}
-	flib_vector_destroy(tempvector);
-	return result;
-}
-
-int flib_ipc_append_seed(flib_vector *vec, const char *seed) {
-	if(log_badargs_if2(vec==NULL, seed==NULL)) {
-		return -1;
-	}
-	return flib_ipc_append_message(vec, "eseed %s", seed);
-}
-
-int flib_ipc_append_script(flib_vector *vec, const char *script) {
-	int result = -1;
-	if(!log_badargs_if2(vec==NULL, script==NULL)) {
-		result = flib_ipc_append_message(vec, "escript %s", script);
-	}
-	return result;
-}
-
-int flib_ipc_append_style(flib_vector *vec, const char *style) {
-	int result = -1;
-	char *copy = flib_strdupnull(style);
-	if(!log_badargs_if(vec==NULL) && copy) {
-		if(!strcmp("Normal", copy)) {
-			// "Normal" means no gametype script
-			// TODO if an empty script called "Normal" is added to the scripts directory this can be removed
-			result = 0;
-		} else {
-			size_t len = strlen(copy);
-			for(size_t i=0; i<len; i++) {
-				if(copy[i] == ' ') {
-					copy[i] = '_';
-				}
-			}
-
-			result = flib_ipc_append_message(vec, "escript %s%s.lua", MULTIPLAYER_SCRIPT_PATH, copy);
-		}
-	}
-	free(copy);
-	return result;
-}
-
-static uint32_t buildModFlags(const flib_scheme *scheme) {
-	uint32_t result = 0;
-	for(int i=0; i<flib_meta.modCount; i++) {
-		if(scheme->mods[i]) {
-			int bitmaskIndex = flib_meta.mods[i].bitmaskIndex;
-			result |= (UINT32_C(1) << bitmaskIndex);
-		}
-	}
-	return result;
-}
-
-int flib_ipc_append_gamescheme(flib_vector *vec, const flib_scheme *scheme) {
-	int result = -1;
-	flib_vector *tempvector = flib_vector_create();
-	if(!log_badargs_if2(vec==NULL, scheme==NULL) && tempvector) {
-		bool error = false;
-		error |= flib_ipc_append_message(tempvector, "e$gmflags %"PRIu32, buildModFlags(scheme));
-		for(int i=0; i<flib_meta.settingCount; i++) {
-			if(flib_meta.settings[i].engineCommand) {
-				int value = scheme->settings[i];
-				if(flib_meta.settings[i].maxMeansInfinity) {
-					value = value>=flib_meta.settings[i].max ? 9999 : value;
-				}
-				if(flib_meta.settings[i].times1000) {
-					value *= 1000;
-				}
-				error |= flib_ipc_append_message(tempvector, "%s %i", flib_meta.settings[i].engineCommand, value);
-			}
-		}
-
-		if(!error) {
-			// Message created, now we can copy everything.
-			flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
-			if(!flib_vector_append(vec, constbuf.data, constbuf.size)) {
-				result = 0;
-			}
-		}
-	}
-	flib_vector_destroy(tempvector);
-	return result;
-}
-
-static int appendWeaponSet(flib_vector *vec, flib_weaponset *set) {
-	return flib_ipc_append_message(vec, "eammloadt %s", set->loadout)
-		|| flib_ipc_append_message(vec, "eammprob %s", set->crateprob)
-		|| flib_ipc_append_message(vec, "eammdelay %s", set->delay)
-		|| flib_ipc_append_message(vec, "eammreinf %s", set->crateammo);
-}
-
-static void calculateMd5Hex(const char *in, char out[33]) {
-	md5_state_t md5state;
-	uint8_t md5bytes[16];
-	md5_init(&md5state);
-	md5_append(&md5state, (unsigned char*)in, strlen(in));
-	md5_finish(&md5state, md5bytes);
-	for(int i=0;i<sizeof(md5bytes); i++) {
-		snprintf(out+i*2, 3, "%02x", (unsigned)md5bytes[i]);
-	}
-}
-
-static int flib_ipc_append_addteam(flib_vector *vec, const flib_team *team, bool perHogAmmo, bool noAmmoStore) {
-	int result = -1;
-	flib_vector *tempvector = flib_vector_create();
-	if(!log_badargs_if2(vec==NULL, team==NULL) && tempvector) {
-		bool error = false;
-
-		if(!perHogAmmo && !noAmmoStore) {
-			error = error
-					|| appendWeaponSet(tempvector, team->hogs[0].weaponset)
-					|| flib_ipc_append_message(tempvector, "eammstore");
-		}
-
-		char md5Hex[33];
-		calculateMd5Hex(team->ownerName ? team->ownerName : "", md5Hex);
-		if(team->colorIndex<0 || team->colorIndex>=flib_teamcolor_count) {
-			flib_log_e("Color index out of bounds for team %s: %i", team->name, team->colorIndex);
-			error = true;
-		} else {
-			error |= flib_ipc_append_message(tempvector, "eaddteam %s %"PRIu32" %s", md5Hex, flib_teamcolors[team->colorIndex], team->name);
-		}
-
-		if(team->remoteDriven) {
-			error |= flib_ipc_append_message(tempvector, "erdriven");
-		}
-
-		error |= flib_ipc_append_message(tempvector, "egrave %s", team->grave);
-		error |= flib_ipc_append_message(tempvector, "efort %s", team->fort);
-		error |= flib_ipc_append_message(tempvector, "evoicepack %s", team->voicepack);
-		error |= flib_ipc_append_message(tempvector, "eflag %s", team->flag);
-
-		for(int i=0; i<team->bindingCount; i++) {
-			error |= flib_ipc_append_message(tempvector, "ebind %s %s", team->bindings[i].binding, team->bindings[i].action);
-		}
-
-		for(int i=0; i<team->hogsInGame; i++) {
-			if(perHogAmmo && !noAmmoStore) {
-				error |= appendWeaponSet(tempvector, team->hogs[i].weaponset);
-			}
-			error |= flib_ipc_append_message(tempvector, "eaddhh %i %i %s", team->hogs[i].difficulty, team->hogs[i].initialHealth, team->hogs[i].name);
-			error |= flib_ipc_append_message(tempvector, "ehat %s", team->hogs[i].hat);
-		}
-
-		if(!error) {
-			// Message created, now we can copy everything.
-			flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
-			if(!flib_vector_append(vec, constbuf.data, constbuf.size)) {
-				result = 0;
-			}
-		}
-	}
-	flib_vector_destroy(tempvector);
-	return result;
-}
-
-int flib_ipc_append_fullconfig(flib_vector *vec, const flib_gamesetup *setup, bool netgame) {
-	int result = -1;
-	flib_vector *tempvector = flib_vector_create();
-	if(!log_badargs_if2(vec==NULL, setup==NULL) && tempvector) {
-		bool error = false;
-		bool perHogAmmo = false;
-		bool sharedAmmo = false;
-
-		error |= flib_ipc_append_message(vec, netgame ? "TN" : "TL");
-		if(setup->map) {
-			error |= flib_ipc_append_mapconf(tempvector, setup->map, false);
-		}
-		if(setup->style) {
-			error |= flib_ipc_append_style(tempvector, setup->style);
-		}
-		if(setup->gamescheme) {
-			error |= flib_ipc_append_gamescheme(tempvector, setup->gamescheme);
-			sharedAmmo = flib_scheme_get_mod(setup->gamescheme, "sharedammo");
-			// Shared ammo has priority over per-hog ammo
-			perHogAmmo = !sharedAmmo && flib_scheme_get_mod(setup->gamescheme, "perhogammo");
-		}
-		if(setup->teamlist->teams && setup->teamlist->teamCount>0) {
-			int *clanColors = flib_calloc(setup->teamlist->teamCount, sizeof(int));
-			if(!clanColors) {
-				error = true;
-			} else {
-				int clanCount = 0;
-				for(int i=0; !error && i<setup->teamlist->teamCount; i++) {
-					flib_team *team = setup->teamlist->teams[i];
-					// Find the clan index of this team (clans are identified by color).
-					bool newClan = false;
-					int clan = 0;
-					while(clan<clanCount && clanColors[clan] != team->colorIndex) {
-						clan++;
-					}
-					if(clan==clanCount) {
-						newClan = true;
-						clanCount++;
-						clanColors[clan] = team->colorIndex;
-					}
-
-					// If shared ammo is active, only add an ammo store for the first team in each clan.
-					bool noAmmoStore = sharedAmmo&&!newClan;
-					error |= flib_ipc_append_addteam(tempvector, setup->teamlist->teams[i], perHogAmmo, noAmmoStore);
-				}
-			}
-			free(clanColors);
-		}
-		error |= flib_ipc_append_message(tempvector, "!");
-
-		if(!error) {
-			// Message created, now we can copy everything.
-			flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
-			if(!flib_vector_append(vec, constbuf.data, constbuf.size)) {
-				result = 0;
-			}
-		}
-	}
-	return result;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "ipcprotocol.h"
+#include "../util/util.h"
+#include "../util/logging.h"
+#include "../md5/md5.h"
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <inttypes.h>
+#include <stdlib.h>
+
+int flib_ipc_append_message(flib_vector *vec, const char *fmt, ...) {
+    int result = -1;
+    if(!log_badargs_if2(vec==NULL, fmt==NULL)) {
+        // 1 byte size prefix, 255 bytes max message length, 1 0-byte for vsnprintf
+        char msgbuffer[257];
+
+        // Format the message, leaving one byte at the start for the length
+        va_list argp;
+        va_start(argp, fmt);
+        int msgSize = vsnprintf(msgbuffer+1, 256, fmt, argp);
+        va_end(argp);
+
+        if(!log_e_if(msgSize > 255, "Message too long (%u bytes)", (unsigned)msgSize)
+                && !log_e_if(msgSize < 0, "printf error")) {
+            // Add the length prefix
+            ((uint8_t*)msgbuffer)[0] = msgSize;
+
+            // Append it to the vector
+            result = flib_vector_append(vec, msgbuffer, msgSize+1);
+        }
+    }
+    return result;
+}
+
+int flib_ipc_append_mapconf(flib_vector *vec, const flib_map *map, bool mappreview) {
+    int result = -1;
+    flib_vector *tempvector = flib_vector_create();
+    if(!log_badargs_if2(vec==NULL, map==NULL)) {
+        bool error = false;
+
+        if(map->mapgen == MAPGEN_NAMED) {
+            error |= log_e_if(!map->name, "Missing map name")
+                    || flib_ipc_append_message(tempvector, "emap %s", map->name);
+        }
+        if(!mappreview) {
+            error |= log_e_if(!map->theme, "Missing map theme")
+                    || flib_ipc_append_message(tempvector, "etheme %s", map->theme);
+        }
+        error |= flib_ipc_append_seed(tempvector, map->seed);
+        error |= flib_ipc_append_message(tempvector, "e$template_filter %i", map->templateFilter);
+        error |= flib_ipc_append_message(tempvector, "e$mapgen %i", map->mapgen);
+
+        if(map->mapgen == MAPGEN_MAZE) {
+            error |= flib_ipc_append_message(tempvector, "e$maze_size %i", map->mazeSize);
+        }
+        if(map->mapgen == MAPGEN_DRAWN) {
+            /*
+             * We have to split the drawn map data into several edraw messages here because
+             * it can be longer than the maximum message size.
+             */
+            const char *edraw = "edraw ";
+            int edrawlen = strlen(edraw);
+            for(size_t offset=0; offset<map->drawDataSize; offset+=200) {
+                size_t bytesRemaining = map->drawDataSize-offset;
+                int fragmentsize = bytesRemaining < 200 ? bytesRemaining : 200;
+                uint8_t messagesize = edrawlen + fragmentsize;
+                error |= flib_vector_append(tempvector, &messagesize, 1);
+                error |= flib_vector_append(tempvector, edraw, edrawlen);
+                error |= flib_vector_append(tempvector, map->drawData+offset, fragmentsize);
+            }
+        }
+
+        if(!log_e_if(error, "Error generating map config")) {
+            // Message created, now we can copy everything.
+            flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
+            if(!flib_vector_append(vec, constbuf.data, constbuf.size)) {
+                result = 0;
+            }
+        }
+    }
+    flib_vector_destroy(tempvector);
+    return result;
+}
+
+int flib_ipc_append_seed(flib_vector *vec, const char *seed) {
+    if(log_badargs_if2(vec==NULL, seed==NULL)) {
+        return -1;
+    }
+    return flib_ipc_append_message(vec, "eseed %s", seed);
+}
+
+int flib_ipc_append_script(flib_vector *vec, const char *script) {
+    int result = -1;
+    if(!log_badargs_if2(vec==NULL, script==NULL)) {
+        result = flib_ipc_append_message(vec, "escript %s", script);
+    }
+    return result;
+}
+
+int flib_ipc_append_style(flib_vector *vec, const char *style) {
+    int result = -1;
+    char *copy = flib_strdupnull(style);
+    if(!log_badargs_if(vec==NULL) && copy) {
+        if(!strcmp("Normal", copy)) {
+            // "Normal" means no gametype script
+            // TODO if an empty script called "Normal" is added to the scripts directory this can be removed
+            result = 0;
+        } else {
+            size_t len = strlen(copy);
+            for(size_t i=0; i<len; i++) {
+                if(copy[i] == ' ') {
+                    copy[i] = '_';
+                }
+            }
+
+            result = flib_ipc_append_message(vec, "escript %s%s.lua", MULTIPLAYER_SCRIPT_PATH, copy);
+        }
+    }
+    free(copy);
+    return result;
+}
+
+static uint32_t buildModFlags(const flib_scheme *scheme) {
+    uint32_t result = 0;
+    for(int i=0; i<flib_meta.modCount; i++) {
+        if(scheme->mods[i]) {
+            int bitmaskIndex = flib_meta.mods[i].bitmaskIndex;
+            result |= (UINT32_C(1) << bitmaskIndex);
+        }
+    }
+    return result;
+}
+
+int flib_ipc_append_gamescheme(flib_vector *vec, const flib_scheme *scheme) {
+    int result = -1;
+    flib_vector *tempvector = flib_vector_create();
+    if(!log_badargs_if2(vec==NULL, scheme==NULL) && tempvector) {
+        bool error = false;
+        error |= flib_ipc_append_message(tempvector, "e$gmflags %"PRIu32, buildModFlags(scheme));
+        for(int i=0; i<flib_meta.settingCount; i++) {
+            if(flib_meta.settings[i].engineCommand) {
+                int value = scheme->settings[i];
+                if(flib_meta.settings[i].maxMeansInfinity) {
+                    value = value>=flib_meta.settings[i].max ? 9999 : value;
+                }
+                if(flib_meta.settings[i].times1000) {
+                    value *= 1000;
+                }
+                error |= flib_ipc_append_message(tempvector, "%s %i", flib_meta.settings[i].engineCommand, value);
+            }
+        }
+
+        if(!error) {
+            // Message created, now we can copy everything.
+            flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
+            if(!flib_vector_append(vec, constbuf.data, constbuf.size)) {
+                result = 0;
+            }
+        }
+    }
+    flib_vector_destroy(tempvector);
+    return result;
+}
+
+static int appendWeaponSet(flib_vector *vec, flib_weaponset *set) {
+    return flib_ipc_append_message(vec, "eammloadt %s", set->loadout)
+        || flib_ipc_append_message(vec, "eammprob %s", set->crateprob)
+        || flib_ipc_append_message(vec, "eammdelay %s", set->delay)
+        || flib_ipc_append_message(vec, "eammreinf %s", set->crateammo);
+}
+
+static void calculateMd5Hex(const char *in, char out[33]) {
+    md5_state_t md5state;
+    uint8_t md5bytes[16];
+    md5_init(&md5state);
+    md5_append(&md5state, (unsigned char*)in, strlen(in));
+    md5_finish(&md5state, md5bytes);
+    for(int i=0;i<sizeof(md5bytes); i++) {
+        snprintf(out+i*2, 3, "%02x", (unsigned)md5bytes[i]);
+    }
+}
+
+static int flib_ipc_append_addteam(flib_vector *vec, const flib_team *team, bool perHogAmmo, bool noAmmoStore) {
+    int result = -1;
+    flib_vector *tempvector = flib_vector_create();
+    if(!log_badargs_if2(vec==NULL, team==NULL) && tempvector) {
+        bool error = false;
+
+        if(!perHogAmmo && !noAmmoStore) {
+            error = error
+                    || appendWeaponSet(tempvector, team->hogs[0].weaponset)
+                    || flib_ipc_append_message(tempvector, "eammstore");
+        }
+
+        char md5Hex[33];
+        calculateMd5Hex(team->ownerName ? team->ownerName : "", md5Hex);
+        if(team->colorIndex<0 || team->colorIndex>=flib_teamcolor_count) {
+            flib_log_e("Color index out of bounds for team %s: %i", team->name, team->colorIndex);
+            error = true;
+        } else {
+            error |= flib_ipc_append_message(tempvector, "eaddteam %s %"PRIu32" %s", md5Hex, flib_teamcolors[team->colorIndex], team->name);
+        }
+
+        if(team->remoteDriven) {
+            error |= flib_ipc_append_message(tempvector, "erdriven");
+        }
+
+        error |= flib_ipc_append_message(tempvector, "egrave %s", team->grave);
+        error |= flib_ipc_append_message(tempvector, "efort %s", team->fort);
+        error |= flib_ipc_append_message(tempvector, "evoicepack %s", team->voicepack);
+        error |= flib_ipc_append_message(tempvector, "eflag %s", team->flag);
+
+        for(int i=0; i<team->bindingCount; i++) {
+            error |= flib_ipc_append_message(tempvector, "ebind %s %s", team->bindings[i].binding, team->bindings[i].action);
+        }
+
+        for(int i=0; i<team->hogsInGame; i++) {
+            if(perHogAmmo && !noAmmoStore) {
+                error |= appendWeaponSet(tempvector, team->hogs[i].weaponset);
+            }
+            error |= flib_ipc_append_message(tempvector, "eaddhh %i %i %s", team->hogs[i].difficulty, team->hogs[i].initialHealth, team->hogs[i].name);
+            error |= flib_ipc_append_message(tempvector, "ehat %s", team->hogs[i].hat);
+        }
+
+        if(!error) {
+            // Message created, now we can copy everything.
+            flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
+            if(!flib_vector_append(vec, constbuf.data, constbuf.size)) {
+                result = 0;
+            }
+        }
+    }
+    flib_vector_destroy(tempvector);
+    return result;
+}
+
+int flib_ipc_append_fullconfig(flib_vector *vec, const flib_gamesetup *setup, bool netgame) {
+    int result = -1;
+    flib_vector *tempvector = flib_vector_create();
+    if(!log_badargs_if2(vec==NULL, setup==NULL) && tempvector) {
+        bool error = false;
+        bool perHogAmmo = false;
+        bool sharedAmmo = false;
+
+        error |= flib_ipc_append_message(vec, netgame ? "TN" : "TL");
+        if(setup->map) {
+            error |= flib_ipc_append_mapconf(tempvector, setup->map, false);
+        }
+        if(setup->style) {
+            error |= flib_ipc_append_style(tempvector, setup->style);
+        }
+        if(setup->gamescheme) {
+            error |= flib_ipc_append_gamescheme(tempvector, setup->gamescheme);
+            sharedAmmo = flib_scheme_get_mod(setup->gamescheme, "sharedammo");
+            // Shared ammo has priority over per-hog ammo
+            perHogAmmo = !sharedAmmo && flib_scheme_get_mod(setup->gamescheme, "perhogammo");
+        }
+        if(setup->teamlist->teams && setup->teamlist->teamCount>0) {
+            int *clanColors = flib_calloc(setup->teamlist->teamCount, sizeof(int));
+            if(!clanColors) {
+                error = true;
+            } else {
+                int clanCount = 0;
+                for(int i=0; !error && i<setup->teamlist->teamCount; i++) {
+                    flib_team *team = setup->teamlist->teams[i];
+                    // Find the clan index of this team (clans are identified by color).
+                    bool newClan = false;
+                    int clan = 0;
+                    while(clan<clanCount && clanColors[clan] != team->colorIndex) {
+                        clan++;
+                    }
+                    if(clan==clanCount) {
+                        newClan = true;
+                        clanCount++;
+                        clanColors[clan] = team->colorIndex;
+                    }
+
+                    // If shared ammo is active, only add an ammo store for the first team in each clan.
+                    bool noAmmoStore = sharedAmmo&&!newClan;
+                    error |= flib_ipc_append_addteam(tempvector, setup->teamlist->teams[i], perHogAmmo, noAmmoStore);
+                }
+            }
+            free(clanColors);
+        }
+        error |= flib_ipc_append_message(tempvector, "!");
+
+        if(!error) {
+            // Message created, now we can copy everything.
+            flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
+            if(!flib_vector_append(vec, constbuf.data, constbuf.size)) {
+                result = 0;
+            }
+        }
+    }
+    return result;
+}
--- a/project_files/frontlib/ipc/ipcprotocol.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/ipc/ipcprotocol.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,93 +1,93 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef IPCPROTOCOL_H_
-#define IPCPROTOCOL_H_
-
-#include "../util/buffer.h"
-#include "../model/map.h"
-#include "../model/team.h"
-#include "../model/scheme.h"
-#include "../model/gamesetup.h"
-
-#include <stdbool.h>
-
-/**
- * Create a message in the IPC protocol format and add it to
- * the vector. Use a format string and extra parameters as with printf.
- *
- * Returns nonzero if something goes wrong. In that case the buffer
- * contents are unaffected.
- */
-int flib_ipc_append_message(flib_vector *vec, const char *fmt, ...);
-
-/**
- * Append IPC messages to the buffer that configure the engine for
- * this map.
- *
- * Unfortunately the engine needs a slightly different configuration
- * for generating a map preview.
- *
- * Returns nonzero if something goes wrong. In that case the buffer
- * contents are unaffected.
- */
-int flib_ipc_append_mapconf(flib_vector *vec, const flib_map *map, bool mappreview);
-
-/**
- * Append a seed message to the buffer.
- *
- * Returns nonzero if something goes wrong. In that case the buffer
- * contents are unaffected.
- */
-int flib_ipc_append_seed(flib_vector *vec, const char *seed);
-
-/**
- * Append a script to the buffer (e.g. "Missions/Training/Basic_Training_-_Bazooka.lua")
- *
- * Returns nonzero if something goes wrong. In that case the buffer
- * contents are unaffected.
- */
-int flib_ipc_append_script(flib_vector *vec, const char *script);
-
-/**
- * Append a game style to the buffer. (e.g. "Capture the Flag")
- *
- * Returns nonzero if something goes wrong. In that case the buffer
- * contents are unaffected.
- */
-int flib_ipc_append_style(flib_vector *vec, const char *style);
-
-/**
- * Append the game scheme to the buffer.
- *
- * Returns nonzero if something goes wrong. In that case the buffer
- * contents are unaffected.
- */
-int flib_ipc_append_gamescheme(flib_vector *vec, const flib_scheme *scheme);
-
-/**
- * Append the entire game config to the buffer (including the final "!" that marks the
- * end of configuration data for the engine)
- *
- * Returns nonzero if something goes wrong. In that case the buffer
- * contents are unaffected.
- */
-int flib_ipc_append_fullconfig(flib_vector *vec, const flib_gamesetup *setup, bool netgame);
-
-#endif /* IPCPROTOCOL_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef IPCPROTOCOL_H_
+#define IPCPROTOCOL_H_
+
+#include "../util/buffer.h"
+#include "../model/map.h"
+#include "../model/team.h"
+#include "../model/scheme.h"
+#include "../model/gamesetup.h"
+
+#include <stdbool.h>
+
+/**
+ * Create a message in the IPC protocol format and add it to
+ * the vector. Use a format string and extra parameters as with printf.
+ *
+ * Returns nonzero if something goes wrong. In that case the buffer
+ * contents are unaffected.
+ */
+int flib_ipc_append_message(flib_vector *vec, const char *fmt, ...);
+
+/**
+ * Append IPC messages to the buffer that configure the engine for
+ * this map.
+ *
+ * Unfortunately the engine needs a slightly different configuration
+ * for generating a map preview.
+ *
+ * Returns nonzero if something goes wrong. In that case the buffer
+ * contents are unaffected.
+ */
+int flib_ipc_append_mapconf(flib_vector *vec, const flib_map *map, bool mappreview);
+
+/**
+ * Append a seed message to the buffer.
+ *
+ * Returns nonzero if something goes wrong. In that case the buffer
+ * contents are unaffected.
+ */
+int flib_ipc_append_seed(flib_vector *vec, const char *seed);
+
+/**
+ * Append a script to the buffer (e.g. "Missions/Training/Basic_Training_-_Bazooka.lua")
+ *
+ * Returns nonzero if something goes wrong. In that case the buffer
+ * contents are unaffected.
+ */
+int flib_ipc_append_script(flib_vector *vec, const char *script);
+
+/**
+ * Append a game style to the buffer. (e.g. "Capture the Flag")
+ *
+ * Returns nonzero if something goes wrong. In that case the buffer
+ * contents are unaffected.
+ */
+int flib_ipc_append_style(flib_vector *vec, const char *style);
+
+/**
+ * Append the game scheme to the buffer.
+ *
+ * Returns nonzero if something goes wrong. In that case the buffer
+ * contents are unaffected.
+ */
+int flib_ipc_append_gamescheme(flib_vector *vec, const flib_scheme *scheme);
+
+/**
+ * Append the entire game config to the buffer (including the final "!" that marks the
+ * end of configuration data for the engine)
+ *
+ * Returns nonzero if something goes wrong. In that case the buffer
+ * contents are unaffected.
+ */
+int flib_ipc_append_fullconfig(flib_vector *vec, const flib_gamesetup *setup, bool netgame);
+
+#endif /* IPCPROTOCOL_H_ */
--- a/project_files/frontlib/ipc/mapconn.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/ipc/mapconn.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,196 +1,196 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "mapconn.h"
-#include "ipcbase.h"
-#include "ipcprotocol.h"
-
-#include "../util/logging.h"
-#include "../util/buffer.h"
-#include "../util/util.h"
-
-#include <stdlib.h>
-
-typedef enum {
-	AWAIT_CONNECTION,
-	AWAIT_REPLY,
-	AWAIT_CLOSE,
-	FINISHED
-} mapconn_state;
-
-struct _flib_mapconn {
-	uint8_t mapBuffer[IPCBASE_MAPMSG_BYTES];
-	flib_ipcbase *ipcBase;
-	flib_vector *configBuffer;
-
-	mapconn_state progress;
-
-	void (*onSuccessCb)(void*, const uint8_t*, int);
-	void *onSuccessCtx;
-
-	void (*onFailureCb)(void*, const char*);
-	void *onFailureCtx;
-
-	bool running;
-	bool destroyRequested;
-};
-
-static void noop_handleSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) {}
-static void noop_handleFailure(void *context, const char *errormessage) {}
-
-static void clearCallbacks(flib_mapconn *conn) {
-	conn->onSuccessCb = &noop_handleSuccess;
-	conn->onFailureCb = &noop_handleFailure;
-}
-
-static flib_vector *createConfigBuffer(const flib_map *mapdesc) {
-	flib_vector *result = NULL;
-	flib_vector *tempbuffer = flib_vector_create();
-	if(tempbuffer) {
-		bool error = false;
-		error |= flib_ipc_append_mapconf(tempbuffer, mapdesc, true);
-		error |= flib_ipc_append_message(tempbuffer, "!");
-		if(!error) {
-			result = tempbuffer;
-			tempbuffer = NULL;
-		}
-	}
-	flib_vector_destroy(tempbuffer);
-	return result;
-}
-
-flib_mapconn *flib_mapconn_create(const flib_map *mapdesc) {
-	if(log_badargs_if(mapdesc==NULL)) {
-		return NULL;
-	}
-	flib_mapconn *result = NULL;
-	flib_mapconn *tempConn = flib_calloc(1, sizeof(flib_mapconn));
-	if(tempConn) {
-		tempConn->ipcBase = flib_ipcbase_create();
-		tempConn->configBuffer = createConfigBuffer(mapdesc);
-		if(tempConn->ipcBase && tempConn->configBuffer) {
-			tempConn->progress = AWAIT_CONNECTION;
-			clearCallbacks(tempConn);
-			result = tempConn;
-			tempConn = NULL;
-		}
-	}
-	flib_mapconn_destroy(tempConn);
-	return result;
-}
-
-void flib_mapconn_destroy(flib_mapconn *conn) {
-	if(conn) {
-		if(conn->running) {
-			/*
-			 * The function was called from a callback, so the tick function is still running
-			 * and we delay the actual destruction. We ensure no further callbacks will be
-			 * sent to prevent surprises.
-			 */
-			clearCallbacks(conn);
-			conn->destroyRequested = true;
-		} else {
-			flib_ipcbase_destroy(conn->ipcBase);
-			flib_vector_destroy(conn->configBuffer);
-			free(conn);
-		}
-	}
-}
-
-int flib_mapconn_getport(flib_mapconn *conn) {
-	if(log_badargs_if(conn==NULL)) {
-		return 0;
-	}
-	return flib_ipcbase_port(conn->ipcBase);
-}
-
-void flib_mapconn_onSuccess(flib_mapconn *conn, void (*callback)(void* context, const uint8_t *bitmap, int numHedgehogs), void *context) {
-	if(!log_badargs_if(conn==NULL)) {
-		conn->onSuccessCb = callback ? callback : &noop_handleSuccess;
-		conn->onSuccessCtx = context;
-	}
-}
-
-void flib_mapconn_onFailure(flib_mapconn *conn, void (*callback)(void* context, const char *errormessage), void *context) {
-	if(!log_badargs_if(conn==NULL)) {
-		conn->onFailureCb = callback ? callback : &noop_handleFailure;
-		conn->onFailureCtx = context;
-	}
-}
-
-static void flib_mapconn_wrappedtick(flib_mapconn *conn) {
-	if(conn->progress == AWAIT_CONNECTION) {
-		flib_ipcbase_accept(conn->ipcBase);
-		switch(flib_ipcbase_state(conn->ipcBase)) {
-		case IPC_CONNECTED:
-			{
-				flib_constbuffer configBuffer = flib_vector_as_constbuffer(conn->configBuffer);
-				if(flib_ipcbase_send_raw(conn->ipcBase, configBuffer.data, configBuffer.size)) {
-					conn->progress = FINISHED;
-					conn->onFailureCb(conn->onFailureCtx, "Error sending map information to the engine.");
-					return;
-				} else {
-					conn->progress = AWAIT_REPLY;
-				}
-			}
-			break;
-		case IPC_NOT_CONNECTED:
-			conn->progress = FINISHED;
-			conn->onFailureCb(conn->onFailureCtx, "Engine connection closed unexpectedly.");
-			return;
-		default:
-			break;
-		}
-	}
-
-	if(conn->progress == AWAIT_REPLY) {
-		if(flib_ipcbase_recv_map(conn->ipcBase, conn->mapBuffer) >= 0) {
-			conn->progress = AWAIT_CLOSE;
-		} else if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
-			conn->progress = FINISHED;
-			conn->onFailureCb(conn->onSuccessCtx, "Engine connection closed unexpectedly.");
-			return;
-		}
-	}
-
-	if(conn->progress == AWAIT_CLOSE) {
-		// Just do throwaway reads so we find out when the engine disconnects
-		uint8_t buf[256];
-		flib_ipcbase_recv_message(conn->ipcBase, buf);
-		if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
-			conn->progress = FINISHED;
-			conn->onSuccessCb(conn->onSuccessCtx, conn->mapBuffer, conn->mapBuffer[IPCBASE_MAPMSG_BYTES-1]);
-			return;
-		}
-	}
-}
-
-void flib_mapconn_tick(flib_mapconn *conn) {
-	if(!log_badargs_if(conn==NULL)
-			&& !log_w_if(conn->running, "Call to flib_mapconn_tick from a callback")
-			&& !log_w_if(conn->progress == FINISHED, "We are already done.")) {
-		conn->running = true;
-		flib_mapconn_wrappedtick(conn);
-		conn->running = false;
-
-		if(conn->destroyRequested) {
-			flib_mapconn_destroy(conn);
-		}
-	}
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "mapconn.h"
+#include "ipcbase.h"
+#include "ipcprotocol.h"
+
+#include "../util/logging.h"
+#include "../util/buffer.h"
+#include "../util/util.h"
+
+#include <stdlib.h>
+
+typedef enum {
+    AWAIT_CONNECTION,
+    AWAIT_REPLY,
+    AWAIT_CLOSE,
+    FINISHED
+} mapconn_state;
+
+struct _flib_mapconn {
+    uint8_t mapBuffer[IPCBASE_MAPMSG_BYTES];
+    flib_ipcbase *ipcBase;
+    flib_vector *configBuffer;
+
+    mapconn_state progress;
+
+    void (*onSuccessCb)(void*, const uint8_t*, int);
+    void *onSuccessCtx;
+
+    void (*onFailureCb)(void*, const char*);
+    void *onFailureCtx;
+
+    bool running;
+    bool destroyRequested;
+};
+
+static void noop_handleSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) {}
+static void noop_handleFailure(void *context, const char *errormessage) {}
+
+static void clearCallbacks(flib_mapconn *conn) {
+    conn->onSuccessCb = &noop_handleSuccess;
+    conn->onFailureCb = &noop_handleFailure;
+}
+
+static flib_vector *createConfigBuffer(const flib_map *mapdesc) {
+    flib_vector *result = NULL;
+    flib_vector *tempbuffer = flib_vector_create();
+    if(tempbuffer) {
+        bool error = false;
+        error |= flib_ipc_append_mapconf(tempbuffer, mapdesc, true);
+        error |= flib_ipc_append_message(tempbuffer, "!");
+        if(!error) {
+            result = tempbuffer;
+            tempbuffer = NULL;
+        }
+    }
+    flib_vector_destroy(tempbuffer);
+    return result;
+}
+
+flib_mapconn *flib_mapconn_create(const flib_map *mapdesc) {
+    if(log_badargs_if(mapdesc==NULL)) {
+        return NULL;
+    }
+    flib_mapconn *result = NULL;
+    flib_mapconn *tempConn = flib_calloc(1, sizeof(flib_mapconn));
+    if(tempConn) {
+        tempConn->ipcBase = flib_ipcbase_create();
+        tempConn->configBuffer = createConfigBuffer(mapdesc);
+        if(tempConn->ipcBase && tempConn->configBuffer) {
+            tempConn->progress = AWAIT_CONNECTION;
+            clearCallbacks(tempConn);
+            result = tempConn;
+            tempConn = NULL;
+        }
+    }
+    flib_mapconn_destroy(tempConn);
+    return result;
+}
+
+void flib_mapconn_destroy(flib_mapconn *conn) {
+    if(conn) {
+        if(conn->running) {
+            /*
+             * The function was called from a callback, so the tick function is still running
+             * and we delay the actual destruction. We ensure no further callbacks will be
+             * sent to prevent surprises.
+             */
+            clearCallbacks(conn);
+            conn->destroyRequested = true;
+        } else {
+            flib_ipcbase_destroy(conn->ipcBase);
+            flib_vector_destroy(conn->configBuffer);
+            free(conn);
+        }
+    }
+}
+
+int flib_mapconn_getport(flib_mapconn *conn) {
+    if(log_badargs_if(conn==NULL)) {
+        return 0;
+    }
+    return flib_ipcbase_port(conn->ipcBase);
+}
+
+void flib_mapconn_onSuccess(flib_mapconn *conn, void (*callback)(void* context, const uint8_t *bitmap, int numHedgehogs), void *context) {
+    if(!log_badargs_if(conn==NULL)) {
+        conn->onSuccessCb = callback ? callback : &noop_handleSuccess;
+        conn->onSuccessCtx = context;
+    }
+}
+
+void flib_mapconn_onFailure(flib_mapconn *conn, void (*callback)(void* context, const char *errormessage), void *context) {
+    if(!log_badargs_if(conn==NULL)) {
+        conn->onFailureCb = callback ? callback : &noop_handleFailure;
+        conn->onFailureCtx = context;
+    }
+}
+
+static void flib_mapconn_wrappedtick(flib_mapconn *conn) {
+    if(conn->progress == AWAIT_CONNECTION) {
+        flib_ipcbase_accept(conn->ipcBase);
+        switch(flib_ipcbase_state(conn->ipcBase)) {
+        case IPC_CONNECTED:
+            {
+                flib_constbuffer configBuffer = flib_vector_as_constbuffer(conn->configBuffer);
+                if(flib_ipcbase_send_raw(conn->ipcBase, configBuffer.data, configBuffer.size)) {
+                    conn->progress = FINISHED;
+                    conn->onFailureCb(conn->onFailureCtx, "Error sending map information to the engine.");
+                    return;
+                } else {
+                    conn->progress = AWAIT_REPLY;
+                }
+            }
+            break;
+        case IPC_NOT_CONNECTED:
+            conn->progress = FINISHED;
+            conn->onFailureCb(conn->onFailureCtx, "Engine connection closed unexpectedly.");
+            return;
+        default:
+            break;
+        }
+    }
+
+    if(conn->progress == AWAIT_REPLY) {
+        if(flib_ipcbase_recv_map(conn->ipcBase, conn->mapBuffer) >= 0) {
+            conn->progress = AWAIT_CLOSE;
+        } else if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
+            conn->progress = FINISHED;
+            conn->onFailureCb(conn->onSuccessCtx, "Engine connection closed unexpectedly.");
+            return;
+        }
+    }
+
+    if(conn->progress == AWAIT_CLOSE) {
+        // Just do throwaway reads so we find out when the engine disconnects
+        uint8_t buf[256];
+        flib_ipcbase_recv_message(conn->ipcBase, buf);
+        if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
+            conn->progress = FINISHED;
+            conn->onSuccessCb(conn->onSuccessCtx, conn->mapBuffer, conn->mapBuffer[IPCBASE_MAPMSG_BYTES-1]);
+            return;
+        }
+    }
+}
+
+void flib_mapconn_tick(flib_mapconn *conn) {
+    if(!log_badargs_if(conn==NULL)
+            && !log_w_if(conn->running, "Call to flib_mapconn_tick from a callback")
+            && !log_w_if(conn->progress == FINISHED, "We are already done.")) {
+        conn->running = true;
+        flib_mapconn_wrappedtick(conn);
+        conn->running = false;
+
+        if(conn->destroyRequested) {
+            flib_mapconn_destroy(conn);
+        }
+    }
+}
--- a/project_files/frontlib/ipc/mapconn.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/ipc/mapconn.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,116 +1,116 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * Functions for querying a map preview from the engine, which includes both a two-color image
- * and the number of hogs this map is suitable for.
- *
- * The general usage is to first create a mapconn object by calling flib_mapconn_create.
- * That will cause the frontlib to listen on a random port which can be queried using
- * flib_mapconn_getport(). You should also register your callback functions right at the start
- * to ensure you don't miss any callbacks.
- *
- * Next, start the engine (that part is up to you) with the appropriate command line arguments
- * for a map preview request.
- *
- * In order to allow the mapconn to run, you should regularly call flib_mapconn_tick(), which
- * performs network I/O and calls your callbacks if the map has been generated or an error
- * has occurred. Once either the onSuccess or onFailure callback is called, you should destroy
- * the mapconn and stop calling tick().
- */
-
-#ifndef IPC_MAPCONN_H_
-#define IPC_MAPCONN_H_
-
-#include "../model/map.h"
-
-#include <stdint.h>
-
-#define MAPIMAGE_WIDTH 256
-#define MAPIMAGE_HEIGHT 128
-#define MAPIMAGE_BYTES (MAPIMAGE_WIDTH/8*MAPIMAGE_HEIGHT)
-
-typedef struct _flib_mapconn flib_mapconn;
-
-/**
- * Start a new map rendering connection (mapconn). This means a listening socket
- * will be started on a random unused port, waiting for a connection from the
- * engine process. Once this connection is established, the required information
- * will be sent to the engine, and the reply is read.
- *
- * The map must be a regular, maze or drawn map - for a preview of a named map,
- * use the preview images in the map's directory, and for the hog count read the
- * map information (e.g. using flib_mapcfg_read).
- *
- * No NULL parameters allowed, returns NULL on failure.
- * Use flib_mapconn_destroy to free the returned object.
- */
-flib_mapconn *flib_mapconn_create(const flib_map *mapdesc);
-
-/**
- * Destroy the mapconn object. Passing NULL is allowed and does nothing.
- * flib_mapconn_destroy may be called from inside a callback function.
- */
-void flib_mapconn_destroy(flib_mapconn *conn);
-
-/**
- * Returns the port on which the mapconn is listening. Only fails if you
- * pass NULL (not allowed), in that case 0 is returned.
- */
-int flib_mapconn_getport(flib_mapconn *conn);
-
-/**
- * Set a callback which will receive the rendered map if the rendering succeeds.
- *
- * Expected callback signature:
- * void handleSuccess(void *context, const uint8_t *bitmap, int numHedgehogs)
- *
- * The context passed to the callback is the same pointer you provided when
- * registering the callback. bitmap is a pointer to a buffer of size MAPIMAGE_BYTES
- * containing a bit-packed image of size MAPIMAGE_WIDTH * MAPIMAGE_HEIGHT.
- * numHedgehogs is the number of hogs that fit on this map.
- *
- * The bitmap pointer passed to the callback belongs to the caller,
- * so it should not be stored elsewhere. Note that it remains valid
- * inside the callback method even if flib_mapconn_destroy is called.
- */
-void flib_mapconn_onSuccess(flib_mapconn *conn, void (*callback)(void* context, const uint8_t *bitmap, int numHedgehogs), void *context);
-
-/**
- * Set a callback which will receive an error message if rendering fails.
- *
- * Expected callback signature:
- * void handleFailure(void *context, const char *errormessage)
- *
- * The context passed to the callback is the same pointer you provided when
- * registering the callback.
- *
- * The error message passed to the callback belongs to the caller,
- * so it should not be stored elsewhere. Note that it remains valid
- * inside the callback method even if flib_mapconn_destroy is called.
- */
-void flib_mapconn_onFailure(flib_mapconn *conn, void (*callback)(void* context, const char *errormessage), void *context);
-
-/**
- * Perform I/O operations and call callbacks if something interesting happens.
- * Should be called regularly.
- */
-void flib_mapconn_tick(flib_mapconn *conn);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * Functions for querying a map preview from the engine, which includes both a two-color image
+ * and the number of hogs this map is suitable for.
+ *
+ * The general usage is to first create a mapconn object by calling flib_mapconn_create.
+ * That will cause the frontlib to listen on a random port which can be queried using
+ * flib_mapconn_getport(). You should also register your callback functions right at the start
+ * to ensure you don't miss any callbacks.
+ *
+ * Next, start the engine (that part is up to you) with the appropriate command line arguments
+ * for a map preview request.
+ *
+ * In order to allow the mapconn to run, you should regularly call flib_mapconn_tick(), which
+ * performs network I/O and calls your callbacks if the map has been generated or an error
+ * has occurred. Once either the onSuccess or onFailure callback is called, you should destroy
+ * the mapconn and stop calling tick().
+ */
+
+#ifndef IPC_MAPCONN_H_
+#define IPC_MAPCONN_H_
+
+#include "../model/map.h"
+
+#include <stdint.h>
+
+#define MAPIMAGE_WIDTH 256
+#define MAPIMAGE_HEIGHT 128
+#define MAPIMAGE_BYTES (MAPIMAGE_WIDTH/8*MAPIMAGE_HEIGHT)
+
+typedef struct _flib_mapconn flib_mapconn;
+
+/**
+ * Start a new map rendering connection (mapconn). This means a listening socket
+ * will be started on a random unused port, waiting for a connection from the
+ * engine process. Once this connection is established, the required information
+ * will be sent to the engine, and the reply is read.
+ *
+ * The map must be a regular, maze or drawn map - for a preview of a named map,
+ * use the preview images in the map's directory, and for the hog count read the
+ * map information (e.g. using flib_mapcfg_read).
+ *
+ * No NULL parameters allowed, returns NULL on failure.
+ * Use flib_mapconn_destroy to free the returned object.
+ */
+flib_mapconn *flib_mapconn_create(const flib_map *mapdesc);
+
+/**
+ * Destroy the mapconn object. Passing NULL is allowed and does nothing.
+ * flib_mapconn_destroy may be called from inside a callback function.
+ */
+void flib_mapconn_destroy(flib_mapconn *conn);
+
+/**
+ * Returns the port on which the mapconn is listening. Only fails if you
+ * pass NULL (not allowed), in that case 0 is returned.
+ */
+int flib_mapconn_getport(flib_mapconn *conn);
+
+/**
+ * Set a callback which will receive the rendered map if the rendering succeeds.
+ *
+ * Expected callback signature:
+ * void handleSuccess(void *context, const uint8_t *bitmap, int numHedgehogs)
+ *
+ * The context passed to the callback is the same pointer you provided when
+ * registering the callback. bitmap is a pointer to a buffer of size MAPIMAGE_BYTES
+ * containing a bit-packed image of size MAPIMAGE_WIDTH * MAPIMAGE_HEIGHT.
+ * numHedgehogs is the number of hogs that fit on this map.
+ *
+ * The bitmap pointer passed to the callback belongs to the caller,
+ * so it should not be stored elsewhere. Note that it remains valid
+ * inside the callback method even if flib_mapconn_destroy is called.
+ */
+void flib_mapconn_onSuccess(flib_mapconn *conn, void (*callback)(void* context, const uint8_t *bitmap, int numHedgehogs), void *context);
+
+/**
+ * Set a callback which will receive an error message if rendering fails.
+ *
+ * Expected callback signature:
+ * void handleFailure(void *context, const char *errormessage)
+ *
+ * The context passed to the callback is the same pointer you provided when
+ * registering the callback.
+ *
+ * The error message passed to the callback belongs to the caller,
+ * so it should not be stored elsewhere. Note that it remains valid
+ * inside the callback method even if flib_mapconn_destroy is called.
+ */
+void flib_mapconn_onFailure(flib_mapconn *conn, void (*callback)(void* context, const char *errormessage), void *context);
+
+/**
+ * Perform I/O operations and call callbacks if something interesting happens.
+ * Should be called regularly.
+ */
+void flib_mapconn_tick(flib_mapconn *conn);
+
+#endif
--- a/project_files/frontlib/md5/md5.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/md5/md5.c	Tue Jan 21 22:53:15 2014 +0100
@@ -27,7 +27,7 @@
 
   This code implements the MD5 Algorithm defined in RFC 1321, whose
   text is available at
-	http://www.ietf.org/rfc/rfc1321.txt
+    http://www.ietf.org/rfc/rfc1321.txt
   The code is derived from the text of the RFC, including the test suite
   (section A.5) but excluding the rest of Appendix A.  It does not include
   any code or documentation that is identified in the RFC as being
@@ -38,14 +38,14 @@
   that follows (in reverse chronological order):
 
   2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
-	either statically or dynamically; added missing #include <string.h>
-	in library.
+    either statically or dynamically; added missing #include <string.h>
+    in library.
   2002-03-11 lpd Corrected argument list for main(), and added int return
-	type, in test program and T value program.
+    type, in test program and T value program.
   2002-02-21 lpd Added missing #include <stdio.h> in test program.
   2000-07-03 lpd Patched to eliminate warnings about "constant is
-	unsigned in ANSI C, signed in traditional"; made test program
-	self-checking.
+    unsigned in ANSI C, signed in traditional"; made test program
+    self-checking.
   1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
   1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
   1999-05-03 lpd Original version.
@@ -54,7 +54,7 @@
 #include "md5.h"
 #include <string.h>
 
-#undef BYTE_ORDER	/* 1 = big-endian, -1 = little-endian, 0 = unknown */
+#undef BYTE_ORDER   /* 1 = big-endian, -1 = little-endian, 0 = unknown */
 #ifdef ARCH_IS_BIG_ENDIAN
 #  define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
 #else
@@ -132,8 +132,8 @@
 md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
 {
     md5_word_t
-	a = pms->abcd[0], b = pms->abcd[1],
-	c = pms->abcd[2], d = pms->abcd[3];
+    a = pms->abcd[0], b = pms->abcd[1],
+    c = pms->abcd[2], d = pms->abcd[3];
     md5_word_t t;
 #if BYTE_ORDER > 0
     /* Define storage only for big-endian CPUs. */
@@ -146,51 +146,51 @@
 
     {
 #if BYTE_ORDER == 0
-	/*
-	 * Determine dynamically whether this is a big-endian or
-	 * little-endian machine, since we can use a more efficient
-	 * algorithm on the latter.
-	 */
-	static const int w = 1;
+    /*
+     * Determine dynamically whether this is a big-endian or
+     * little-endian machine, since we can use a more efficient
+     * algorithm on the latter.
+     */
+    static const int w = 1;
 
-	if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
+    if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
 #endif
-#if BYTE_ORDER <= 0		/* little-endian */
-	{
-	    /*
-	     * On little-endian machines, we can process properly aligned
-	     * data without copying it.
-	     */
-	    if (!((data - (const md5_byte_t *)0) & 3)) {
-		/* data are properly aligned */
-		X = (const md5_word_t *)data;
-	    } else {
-		/* not aligned */
-		memcpy(xbuf, data, 64);
-		X = xbuf;
-	    }
-	}
+#if BYTE_ORDER <= 0     /* little-endian */
+    {
+        /*
+         * On little-endian machines, we can process properly aligned
+         * data without copying it.
+         */
+        if (!((data - (const md5_byte_t *)0) & 3)) {
+        /* data are properly aligned */
+        X = (const md5_word_t *)data;
+        } else {
+        /* not aligned */
+        memcpy(xbuf, data, 64);
+        X = xbuf;
+        }
+    }
 #endif
 #if BYTE_ORDER == 0
-	else			/* dynamic big-endian */
+    else            /* dynamic big-endian */
 #endif
-#if BYTE_ORDER >= 0		/* big-endian */
-	{
-	    /*
-	     * On big-endian machines, we must arrange the bytes in the
-	     * right order.
-	     */
-	    const md5_byte_t *xp = data;
-	    int i;
+#if BYTE_ORDER >= 0     /* big-endian */
+    {
+        /*
+         * On big-endian machines, we must arrange the bytes in the
+         * right order.
+         */
+        const md5_byte_t *xp = data;
+        int i;
 
 #  if BYTE_ORDER == 0
-	    X = xbuf;		/* (dynamic only) */
+        X = xbuf;       /* (dynamic only) */
 #  else
-#    define xbuf X		/* (static only) */
+#    define xbuf X      /* (static only) */
 #  endif
-	    for (i = 0; i < 16; ++i, xp += 4)
-		xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
-	}
+        for (i = 0; i < 16; ++i, xp += 4)
+        xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
+    }
 #endif
     }
 
@@ -328,54 +328,54 @@
     md5_word_t nbits = (md5_word_t)(nbytes << 3);
 
     if (nbytes <= 0)
-	return;
+    return;
 
     /* Update the message length. */
     pms->count[1] += nbytes >> 29;
     pms->count[0] += nbits;
     if (pms->count[0] < nbits)
-	pms->count[1]++;
+    pms->count[1]++;
 
     /* Process an initial partial block. */
     if (offset) {
-	int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
+    int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 
-	memcpy(pms->buf + offset, p, copy);
-	if (offset + copy < 64)
-	    return;
-	p += copy;
-	left -= copy;
-	md5_process(pms, pms->buf);
+    memcpy(pms->buf + offset, p, copy);
+    if (offset + copy < 64)
+        return;
+    p += copy;
+    left -= copy;
+    md5_process(pms, pms->buf);
     }
 
     /* Process full blocks. */
     for (; left >= 64; p += 64, left -= 64)
-	md5_process(pms, p);
+    md5_process(pms, p);
 
     /* Process a final partial block. */
     if (left)
-	memcpy(pms->buf, p, left);
+    memcpy(pms->buf, p, left);
 }
 
 void
 md5_finish(md5_state_t *pms, md5_byte_t digest[16])
 {
     static const md5_byte_t pad[64] = {
-	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+    0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
     };
     md5_byte_t data[8];
     int i;
 
     /* Save the length before padding. */
     for (i = 0; i < 8; ++i)
-	data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
+    data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
     /* Pad to 56 bytes mod 64. */
     md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
     /* Append the length. */
     md5_append(pms, data, 8);
     for (i = 0; i < 16; ++i)
-	digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
+    digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
 }
--- a/project_files/frontlib/md5/md5.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/md5/md5.h	Tue Jan 21 22:53:15 2014 +0100
@@ -27,7 +27,7 @@
 
   This code implements the MD5 Algorithm defined in RFC 1321, whose
   text is available at
-	http://www.ietf.org/rfc/rfc1321.txt
+    http://www.ietf.org/rfc/rfc1321.txt
   The code is derived from the text of the RFC, including the test suite
   (section A.5) but excluding the rest of Appendix A.  It does not include
   any code or documentation that is identified in the RFC as being
@@ -38,12 +38,12 @@
   that follows (in reverse chronological order):
 
   2002-04-13 lpd Removed support for non-ANSI compilers; removed
-	references to Ghostscript; clarified derivation from RFC 1321;
-	now handles byte order either statically or dynamically.
+    references to Ghostscript; clarified derivation from RFC 1321;
+    now handles byte order either statically or dynamically.
   1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
   1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
-	added conditionalization for C++ compilation from Martin
-	Purschke <purschke@bnl.gov>.
+    added conditionalization for C++ compilation from Martin
+    Purschke <purschke@bnl.gov>.
   1999-05-03 lpd Original version.
  */
 
@@ -65,13 +65,13 @@
 
 /*! Define the state of the MD5 Algorithm. */
 typedef struct md5_state_s {
-    md5_word_t count[2];	/*! message length in bits, lsw first */
-    md5_word_t abcd[4];		/*! digest buffer */
-    md5_byte_t buf[64];		/*! accumulate block */
+    md5_word_t count[2];    /*! message length in bits, lsw first */
+    md5_word_t abcd[4];     /*! digest buffer */
+    md5_byte_t buf[64];     /*! accumulate block */
 } md5_state_t;
 
 #ifdef __cplusplus
-extern "C" 
+extern "C"
 {
 #endif
 
--- a/project_files/frontlib/model/gamesetup.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/gamesetup.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,55 +1,55 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "gamesetup.h"
-#include "../util/util.h"
-
-#include <stdlib.h>
-
-void flib_gamesetup_destroy(flib_gamesetup *gamesetup) {
-	if(gamesetup) {
-		free(gamesetup->style);
-		flib_scheme_destroy(gamesetup->gamescheme);
-		flib_map_destroy(gamesetup->map);
-		flib_teamlist_destroy(gamesetup->teamlist);
-		free(gamesetup);
-	}
-}
-
-flib_gamesetup *flib_gamesetup_copy(const flib_gamesetup *setup) {
-	if(!setup) {
-		return NULL;
-	}
-
-	flib_gamesetup *result = flib_calloc(1, sizeof(flib_gamesetup));
-	if(result) {
-		result->style = flib_strdupnull(setup->style);
-		result->gamescheme = flib_scheme_copy(setup->gamescheme);
-		result->map = flib_map_copy(setup->map);
-		result->teamlist = flib_teamlist_copy(setup->teamlist);
-		if((setup->style && !result->style)
-				|| (setup->gamescheme && !result->gamescheme)
-				|| (setup->map && !result->map)
-				|| (setup->teamlist && !result->teamlist)) {
-			flib_gamesetup_destroy(result);
-			result = NULL;
-		}
-	}
-	return result;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "gamesetup.h"
+#include "../util/util.h"
+
+#include <stdlib.h>
+
+void flib_gamesetup_destroy(flib_gamesetup *gamesetup) {
+    if(gamesetup) {
+        free(gamesetup->style);
+        flib_scheme_destroy(gamesetup->gamescheme);
+        flib_map_destroy(gamesetup->map);
+        flib_teamlist_destroy(gamesetup->teamlist);
+        free(gamesetup);
+    }
+}
+
+flib_gamesetup *flib_gamesetup_copy(const flib_gamesetup *setup) {
+    if(!setup) {
+        return NULL;
+    }
+
+    flib_gamesetup *result = flib_calloc(1, sizeof(flib_gamesetup));
+    if(result) {
+        result->style = flib_strdupnull(setup->style);
+        result->gamescheme = flib_scheme_copy(setup->gamescheme);
+        result->map = flib_map_copy(setup->map);
+        result->teamlist = flib_teamlist_copy(setup->teamlist);
+        if((setup->style && !result->style)
+                || (setup->gamescheme && !result->gamescheme)
+                || (setup->map && !result->map)
+                || (setup->teamlist && !result->teamlist)) {
+            flib_gamesetup_destroy(result);
+            result = NULL;
+        }
+    }
+    return result;
+}
--- a/project_files/frontlib/model/gamesetup.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/gamesetup.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,47 +1,47 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * A complete game configuration that contains all settings the engine needs to start a
- * local or networked game.
- */
-
-#ifndef MODEL_GAMESETUP_H_
-#define MODEL_GAMESETUP_H_
-
-#include "scheme.h"
-#include "weapon.h"
-#include "map.h"
-#include "teamlist.h"
-
-typedef struct {
-    char *style;				//!< e.g. "Capture the Flag"
-    flib_scheme *gamescheme;
-    flib_map *map;
-	flib_teamlist *teamlist;
-} flib_gamesetup;
-
-void flib_gamesetup_destroy(flib_gamesetup *gamesetup);
-
-/**
- * Deep-copy of the flib_gamesetup.
- */
-flib_gamesetup *flib_gamesetup_copy(const flib_gamesetup *gamesetup);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * A complete game configuration that contains all settings the engine needs to start a
+ * local or networked game.
+ */
+
+#ifndef MODEL_GAMESETUP_H_
+#define MODEL_GAMESETUP_H_
+
+#include "scheme.h"
+#include "weapon.h"
+#include "map.h"
+#include "teamlist.h"
+
+typedef struct {
+    char *style;                //!< e.g. "Capture the Flag"
+    flib_scheme *gamescheme;
+    flib_map *map;
+    flib_teamlist *teamlist;
+} flib_gamesetup;
+
+void flib_gamesetup_destroy(flib_gamesetup *gamesetup);
+
+/**
+ * Deep-copy of the flib_gamesetup.
+ */
+flib_gamesetup *flib_gamesetup_copy(const flib_gamesetup *gamesetup);
+
+#endif
--- a/project_files/frontlib/model/map.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/map.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,110 +1,110 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "map.h"
-
-#include "../util/inihelper.h"
-#include "../util/util.h"
-#include "../util/logging.h"
-
-#include <stdlib.h>
-
-flib_map *flib_map_create_regular(const char *seed, const char *theme, int templateFilter) {
-	if(log_badargs_if2(seed==NULL, theme==NULL)) {
-		return NULL;
-	}
-	flib_map newmap = {0};
-	newmap.mapgen = MAPGEN_REGULAR;
-	newmap.name = "+rnd+";
-	newmap.seed = (char*)seed;
-	newmap.theme = (char*)theme;
-	newmap.templateFilter = templateFilter;
-	return flib_map_copy(&newmap);
-}
-
-flib_map *flib_map_create_maze(const char *seed, const char *theme, int mazeSize) {
-	if(log_badargs_if2(seed==NULL, theme==NULL)) {
-		return NULL;
-	}
-	flib_map newmap = {0};
-	newmap.mapgen = MAPGEN_MAZE;
-	newmap.name = "+maze+";
-	newmap.seed = (char*)seed;
-	newmap.theme = (char*)theme;
-	newmap.mazeSize = mazeSize;
-	return flib_map_copy(&newmap);
-}
-
-flib_map *flib_map_create_named(const char *seed, const char *name) {
-	if(log_badargs_if2(seed==NULL, name==NULL)) {
-		return NULL;
-	}
-	flib_map newmap = {0};
-	newmap.mapgen = MAPGEN_NAMED;
-	newmap.name = (char*)name;
-	newmap.seed = (char*)seed;
-	return flib_map_copy(&newmap);
-}
-
-flib_map *flib_map_create_drawn(const char *seed, const char *theme, const uint8_t *drawData, size_t drawDataSize) {
-	if(log_badargs_if3(seed==NULL, theme==NULL, drawData==NULL)) {
-		return NULL;
-	}
-	flib_map newmap = {0};
-	newmap.mapgen = MAPGEN_DRAWN;
-	newmap.name = "+drawn+";
-	newmap.seed = (char*)seed;
-	newmap.theme = (char*)theme;
-	newmap.drawData = (uint8_t*) drawData;
-	newmap.drawDataSize = drawDataSize;
-	return flib_map_copy(&newmap);
-}
-
-flib_map *flib_map_copy(const flib_map *map) {
-	flib_map *result = NULL;
-	if(map) {
-		flib_map *newmap = flib_calloc(1, sizeof(flib_map));
-		if(newmap) {
-			newmap->mapgen = map->mapgen;
-			newmap->drawDataSize = map->drawDataSize;
-			newmap->drawData = flib_bufdupnull(map->drawData, map->drawDataSize);
-			newmap->mazeSize = map->mazeSize;
-			newmap->name = flib_strdupnull(map->name);
-			newmap->seed = flib_strdupnull(map->seed);
-			newmap->templateFilter = map->templateFilter;
-			newmap->theme = flib_strdupnull(map->theme);
-			if((newmap->drawData || !map->drawData) && (newmap->name || !map->name) && (newmap->seed || !map->seed) && (newmap->theme || !map->theme)) {
-				result = newmap;
-				newmap = NULL;
-			}
-		}
-		flib_map_destroy(newmap);
-	}
-	return result;
-}
-
-void flib_map_destroy(flib_map *map) {
-	if(map) {
-		free(map->seed);
-		free(map->drawData);
-		free(map->name);
-		free(map->theme);
-		free(map);
-	}
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "map.h"
+
+#include "../util/inihelper.h"
+#include "../util/util.h"
+#include "../util/logging.h"
+
+#include <stdlib.h>
+
+flib_map *flib_map_create_regular(const char *seed, const char *theme, int templateFilter) {
+    if(log_badargs_if2(seed==NULL, theme==NULL)) {
+        return NULL;
+    }
+    flib_map newmap = {0};
+    newmap.mapgen = MAPGEN_REGULAR;
+    newmap.name = "+rnd+";
+    newmap.seed = (char*)seed;
+    newmap.theme = (char*)theme;
+    newmap.templateFilter = templateFilter;
+    return flib_map_copy(&newmap);
+}
+
+flib_map *flib_map_create_maze(const char *seed, const char *theme, int mazeSize) {
+    if(log_badargs_if2(seed==NULL, theme==NULL)) {
+        return NULL;
+    }
+    flib_map newmap = {0};
+    newmap.mapgen = MAPGEN_MAZE;
+    newmap.name = "+maze+";
+    newmap.seed = (char*)seed;
+    newmap.theme = (char*)theme;
+    newmap.mazeSize = mazeSize;
+    return flib_map_copy(&newmap);
+}
+
+flib_map *flib_map_create_named(const char *seed, const char *name) {
+    if(log_badargs_if2(seed==NULL, name==NULL)) {
+        return NULL;
+    }
+    flib_map newmap = {0};
+    newmap.mapgen = MAPGEN_NAMED;
+    newmap.name = (char*)name;
+    newmap.seed = (char*)seed;
+    return flib_map_copy(&newmap);
+}
+
+flib_map *flib_map_create_drawn(const char *seed, const char *theme, const uint8_t *drawData, size_t drawDataSize) {
+    if(log_badargs_if3(seed==NULL, theme==NULL, drawData==NULL)) {
+        return NULL;
+    }
+    flib_map newmap = {0};
+    newmap.mapgen = MAPGEN_DRAWN;
+    newmap.name = "+drawn+";
+    newmap.seed = (char*)seed;
+    newmap.theme = (char*)theme;
+    newmap.drawData = (uint8_t*) drawData;
+    newmap.drawDataSize = drawDataSize;
+    return flib_map_copy(&newmap);
+}
+
+flib_map *flib_map_copy(const flib_map *map) {
+    flib_map *result = NULL;
+    if(map) {
+        flib_map *newmap = flib_calloc(1, sizeof(flib_map));
+        if(newmap) {
+            newmap->mapgen = map->mapgen;
+            newmap->drawDataSize = map->drawDataSize;
+            newmap->drawData = flib_bufdupnull(map->drawData, map->drawDataSize);
+            newmap->mazeSize = map->mazeSize;
+            newmap->name = flib_strdupnull(map->name);
+            newmap->seed = flib_strdupnull(map->seed);
+            newmap->templateFilter = map->templateFilter;
+            newmap->theme = flib_strdupnull(map->theme);
+            if((newmap->drawData || !map->drawData) && (newmap->name || !map->name) && (newmap->seed || !map->seed) && (newmap->theme || !map->theme)) {
+                result = newmap;
+                newmap = NULL;
+            }
+        }
+        flib_map_destroy(newmap);
+    }
+    return result;
+}
+
+void flib_map_destroy(flib_map *map) {
+    if(map) {
+        free(map->seed);
+        free(map->drawData);
+        free(map->name);
+        free(map->theme);
+        free(map);
+    }
+}
--- a/project_files/frontlib/model/map.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/map.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,114 +1,114 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef MODEL_MAP_H_
-#define MODEL_MAP_H_
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#define MAPGEN_REGULAR 0
-#define MAPGEN_MAZE 1
-#define MAPGEN_DRAWN 2
-#define MAPGEN_NAMED 3
-
-#define TEMPLATEFILTER_ALL 0
-#define TEMPLATEFILTER_SMALL 1
-#define TEMPLATEFILTER_MEDIUM 2
-#define TEMPLATEFILTER_LARGE 3
-#define TEMPLATEFILTER_CAVERN 4
-#define TEMPLATEFILTER_WACKY 5
-
-#define MAZE_SIZE_SMALL_TUNNELS 0
-#define MAZE_SIZE_MEDIUM_TUNNELS 1
-#define MAZE_SIZE_LARGE_TUNNELS 2
-#define MAZE_SIZE_SMALL_ISLANDS 3
-#define MAZE_SIZE_MEDIUM_ISLANDS 4
-#define MAZE_SIZE_LARGE_ISLANDS 5
-
-/**
- * Data structure for defining a map. This contains the whole recipe to
- * exactly recreate a particular map.
- *
- * The required fields depend on the map generator, see the comments
- * at the struct for details.
- */
-typedef struct {
-	int mapgen;				//!< Always one of the MAPGEN_ constants
-	char *name;				//!< The name of the map for MAPGEN_NAMED (e.g. "Cogs"), otherwise one of "+rnd+", "+maze+" or "+drawn+".
-	char *seed;				//!< Used for all maps. This is a random seed for all (non-AI) entropy in the round. Typically a random UUID, but can be any string.
-	char *theme;			//!< Used for all maps. This is the name of a directory in Data/Themes (e.g. "Beach")
-	uint8_t *drawData;		//!< Used for MAPGEN_DRAWN
-	size_t drawDataSize;	//!< Used for MAPGEN_DRAWN
-	int templateFilter;		//!< Used for MAPGEN_REGULAR. One of the TEMPLATEFILTER_xxx constants.
-	int mazeSize;			//!< Used for MAPGEN_MAZE. One of the MAZE_SIZE_xxx constants.
-} flib_map;
-
-/**
- * Create a generated map. theme should be the name of a
- * directory in "Themes" and templateFilter should be one of the
- * TEMPLATEFILTER_* constants, but this is not checked before
- * passing it to the engine.
- *
- * Use flib_map_destroy to free the returned object.
- * No NULL parameters allowed, returns NULL on failure.
- */
-flib_map *flib_map_create_regular(const char *seed, const char *theme, int templateFilter);
-
-/**
- * Create a generated maze-type map. theme should be the name of a
- * directory in "Themes" and mazeSize should be one of the
- * MAZE_SIZE_* constants, but this is not checked before
- * passing it to the engine.
- *
- * Use flib_map_destroy to free the returned object.
- * No NULL parameters allowed, returns NULL on failure.
- */
-flib_map *flib_map_create_maze(const char *seed, const char *theme, int mazeSize);
-
-/**
- * Create a map from the Maps-Directory. name should be the name of a
- * directory in "Maps", but this is not checked before
- * passing it to the engine. If this is a mission, the corresponding
- * script is used automatically.
- *
- * Use flib_map_destroy to free the returned object.
- * No NULL parameters allowed, returns NULL on failure.
- */
-flib_map *flib_map_create_named(const char *seed, const char *name);
-
-/**
- * Create a hand-drawn map. Use flib_map_destroy to free the returned object.
- * No NULL parameters allowed, returns NULL on failure.
- */
-flib_map *flib_map_create_drawn(const char *seed, const char *theme, const uint8_t *drawData, size_t drawDataSize);
-
-/**
- * Create a deep copy of the map. Returns NULL on failure or if NULL was passed.
- */
-flib_map *flib_map_copy(const flib_map *map);
-
-/**
- * Decrease the reference count of the object and free it if this was the last reference.
- */
-void flib_map_destroy(flib_map *map);
-
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef MODEL_MAP_H_
+#define MODEL_MAP_H_
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#define MAPGEN_REGULAR 0
+#define MAPGEN_MAZE 1
+#define MAPGEN_DRAWN 2
+#define MAPGEN_NAMED 3
+
+#define TEMPLATEFILTER_ALL 0
+#define TEMPLATEFILTER_SMALL 1
+#define TEMPLATEFILTER_MEDIUM 2
+#define TEMPLATEFILTER_LARGE 3
+#define TEMPLATEFILTER_CAVERN 4
+#define TEMPLATEFILTER_WACKY 5
+
+#define MAZE_SIZE_SMALL_TUNNELS 0
+#define MAZE_SIZE_MEDIUM_TUNNELS 1
+#define MAZE_SIZE_LARGE_TUNNELS 2
+#define MAZE_SIZE_SMALL_ISLANDS 3
+#define MAZE_SIZE_MEDIUM_ISLANDS 4
+#define MAZE_SIZE_LARGE_ISLANDS 5
+
+/**
+ * Data structure for defining a map. This contains the whole recipe to
+ * exactly recreate a particular map.
+ *
+ * The required fields depend on the map generator, see the comments
+ * at the struct for details.
+ */
+typedef struct {
+    int mapgen;             //!< Always one of the MAPGEN_ constants
+    char *name;             //!< The name of the map for MAPGEN_NAMED (e.g. "Cogs"), otherwise one of "+rnd+", "+maze+" or "+drawn+".
+    char *seed;             //!< Used for all maps. This is a random seed for all (non-AI) entropy in the round. Typically a random UUID, but can be any string.
+    char *theme;            //!< Used for all maps. This is the name of a directory in Data/Themes (e.g. "Beach")
+    uint8_t *drawData;      //!< Used for MAPGEN_DRAWN
+    size_t drawDataSize;    //!< Used for MAPGEN_DRAWN
+    int templateFilter;     //!< Used for MAPGEN_REGULAR. One of the TEMPLATEFILTER_xxx constants.
+    int mazeSize;           //!< Used for MAPGEN_MAZE. One of the MAZE_SIZE_xxx constants.
+} flib_map;
+
+/**
+ * Create a generated map. theme should be the name of a
+ * directory in "Themes" and templateFilter should be one of the
+ * TEMPLATEFILTER_* constants, but this is not checked before
+ * passing it to the engine.
+ *
+ * Use flib_map_destroy to free the returned object.
+ * No NULL parameters allowed, returns NULL on failure.
+ */
+flib_map *flib_map_create_regular(const char *seed, const char *theme, int templateFilter);
+
+/**
+ * Create a generated maze-type map. theme should be the name of a
+ * directory in "Themes" and mazeSize should be one of the
+ * MAZE_SIZE_* constants, but this is not checked before
+ * passing it to the engine.
+ *
+ * Use flib_map_destroy to free the returned object.
+ * No NULL parameters allowed, returns NULL on failure.
+ */
+flib_map *flib_map_create_maze(const char *seed, const char *theme, int mazeSize);
+
+/**
+ * Create a map from the Maps-Directory. name should be the name of a
+ * directory in "Maps", but this is not checked before
+ * passing it to the engine. If this is a mission, the corresponding
+ * script is used automatically.
+ *
+ * Use flib_map_destroy to free the returned object.
+ * No NULL parameters allowed, returns NULL on failure.
+ */
+flib_map *flib_map_create_named(const char *seed, const char *name);
+
+/**
+ * Create a hand-drawn map. Use flib_map_destroy to free the returned object.
+ * No NULL parameters allowed, returns NULL on failure.
+ */
+flib_map *flib_map_create_drawn(const char *seed, const char *theme, const uint8_t *drawData, size_t drawDataSize);
+
+/**
+ * Create a deep copy of the map. Returns NULL on failure or if NULL was passed.
+ */
+flib_map *flib_map_copy(const flib_map *map);
+
+/**
+ * Decrease the reference count of the object and free it if this was the last reference.
+ */
+void flib_map_destroy(flib_map *map);
+
+
+#endif
--- a/project_files/frontlib/model/mapcfg.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/mapcfg.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,64 +1,64 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "mapcfg.h"
-
-#include "../util/util.h"
-#include "../util/logging.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-void removeNewline(char *str) {
-	for(;*str;str++) {
-		if(*str=='\n' || *str=='\r') {
-			*str = 0;
-			return;
-		}
-	}
-}
-
-int flib_mapcfg_read(const char *dataDirPath, const char *mapname, flib_mapcfg *out) {
-	int result = -1;
-	if(!log_badargs_if4(dataDirPath==NULL, mapname==NULL, out==NULL, flib_contains_dir_separator(mapname))) {
-		char *path = flib_asprintf("%sMaps/%s/map.cfg", dataDirPath, mapname);
-		if(path) {
-			FILE *file = fopen(path, "rb");
-			if(!log_e_if(!file, "Unable to open map config file %s", path)) {
-				if(!log_e_if(!fgets(out->theme, sizeof(out->theme), file), "Error reading theme from %s", path)) {
-					removeNewline(out->theme);
-					char buf[64];
-					if(fgets(buf, sizeof(buf), file)) {
-						removeNewline(buf);
-						errno = 0;
-						out->hogLimit = strtol(buf, NULL, 10);
-						result = !log_e_if(errno, "Invalid hoglimit in %s: %i", path, buf);
-					} else {
-						result = 0;
-					}
-				}
-				fclose(file);
-			}
-		}
-		free(path);
-	}
-	return result;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "mapcfg.h"
+
+#include "../util/util.h"
+#include "../util/logging.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+void removeNewline(char *str) {
+    for(;*str;str++) {
+        if(*str=='\n' || *str=='\r') {
+            *str = 0;
+            return;
+        }
+    }
+}
+
+int flib_mapcfg_read(const char *dataDirPath, const char *mapname, flib_mapcfg *out) {
+    int result = -1;
+    if(!log_badargs_if4(dataDirPath==NULL, mapname==NULL, out==NULL, flib_contains_dir_separator(mapname))) {
+        char *path = flib_asprintf("%sMaps/%s/map.cfg", dataDirPath, mapname);
+        if(path) {
+            FILE *file = fopen(path, "rb");
+            if(!log_e_if(!file, "Unable to open map config file %s", path)) {
+                if(!log_e_if(!fgets(out->theme, sizeof(out->theme), file), "Error reading theme from %s", path)) {
+                    removeNewline(out->theme);
+                    char buf[64];
+                    if(fgets(buf, sizeof(buf), file)) {
+                        removeNewline(buf);
+                        errno = 0;
+                        out->hogLimit = strtol(buf, NULL, 10);
+                        result = !log_e_if(errno, "Invalid hoglimit in %s: %i", path, buf);
+                    } else {
+                        result = 0;
+                    }
+                }
+                fclose(file);
+            }
+        }
+        free(path);
+    }
+    return result;
+}
--- a/project_files/frontlib/model/mapcfg.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/mapcfg.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,38 +1,38 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/*!
- * Data structure and functions for accessing the map.cfg of named maps.
- */
-
-#ifndef MAPCFG_H_
-#define MAPCFG_H_
-
-typedef struct {
-	char theme[256];
-	int hogLimit;
-} flib_mapcfg;
-
-/**
- * Read the map configuration for the map with this name.
- * The dataDirPath must end in a path separator.
- */
-int flib_mapcfg_read(const char *dataDirPath, const char *mapname, flib_mapcfg *out);
-
-#endif /* MAPCFG_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/*!
+ * Data structure and functions for accessing the map.cfg of named maps.
+ */
+
+#ifndef MAPCFG_H_
+#define MAPCFG_H_
+
+typedef struct {
+    char theme[256];
+    int hogLimit;
+} flib_mapcfg;
+
+/**
+ * Read the map configuration for the map with this name.
+ * The dataDirPath must end in a path separator.
+ */
+int flib_mapcfg_read(const char *dataDirPath, const char *mapname, flib_mapcfg *out);
+
+#endif /* MAPCFG_H_ */
--- a/project_files/frontlib/model/room.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/room.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,34 +1,34 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "room.h"
-#include "../util/logging.h"
-
-#include <stdlib.h>
-
-void flib_room_destroy(flib_room *room) {
-	if(room) {
-		free(room->map);
-		free(room->name);
-		free(room->owner);
-		free(room->scheme);
-		free(room->weapons);
-		free(room);
-	}
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "room.h"
+#include "../util/logging.h"
+
+#include <stdlib.h>
+
+void flib_room_destroy(flib_room *room) {
+    if(room) {
+        free(room->map);
+        free(room->name);
+        free(room->owner);
+        free(room->scheme);
+        free(room->weapons);
+        free(room);
+    }
+}
--- a/project_files/frontlib/model/room.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/room.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,42 +1,42 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * Models the room information for the lobby roomlist.
- */
-
-#ifndef ROOM_H_
-#define ROOM_H_
-
-#include <stdbool.h>
-
-typedef struct {
-    bool inProgress;	//!< true if the game is running
-    char *name;
-    int playerCount;
-    int teamCount;
-    char *owner;
-    char *map;			//!< This is either a map name, or one of +rnd+, +maze+ or +drawn+.
-    char *scheme;
-    char *weapons;
-} flib_room;
-
-void flib_room_destroy();
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * Models the room information for the lobby roomlist.
+ */
+
+#ifndef ROOM_H_
+#define ROOM_H_
+
+#include <stdbool.h>
+
+typedef struct {
+    bool inProgress;    //!< true if the game is running
+    char *name;
+    int playerCount;
+    int teamCount;
+    char *owner;
+    char *map;          //!< This is either a map name, or one of +rnd+, +maze+ or +drawn+.
+    char *scheme;
+    char *weapons;
+} flib_room;
+
+void flib_room_destroy();
+
+#endif
--- a/project_files/frontlib/model/scheme.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/scheme.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,95 +1,95 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "scheme.h"
-
-#include "../util/inihelper.h"
-#include "../util/logging.h"
-#include "../util/util.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-
-flib_scheme *flib_scheme_create(const char *schemeName) {
-	flib_scheme *result = flib_calloc(1, sizeof(flib_scheme));
-	if(log_badargs_if(schemeName==NULL) || result==NULL) {
-		return NULL;
-	}
-
-	result->name = flib_strdupnull(schemeName);
-	result->mods = flib_calloc(flib_meta.modCount, sizeof(*result->mods));
-	result->settings = flib_calloc(flib_meta.settingCount, sizeof(*result->settings));
-
-	if(!result->mods || !result->settings || !result->name) {
-		flib_scheme_destroy(result);
-		return NULL;
-	}
-
-	for(int i=0; i<flib_meta.settingCount; i++) {
-		result->settings[i] = flib_meta.settings[i].def;
-	}
-	return result;
-}
-
-flib_scheme *flib_scheme_copy(const flib_scheme *scheme) {
-	flib_scheme *result = NULL;
-	if(scheme) {
-		result = flib_scheme_create(scheme->name);
-		if(result) {
-			memcpy(result->mods, scheme->mods, flib_meta.modCount * sizeof(*scheme->mods));
-			memcpy(result->settings, scheme->settings, flib_meta.settingCount * sizeof(*scheme->settings));
-		}
-	}
-	return result;
-}
-
-void flib_scheme_destroy(flib_scheme* scheme) {
-	if(scheme) {
-		free(scheme->mods);
-		free(scheme->settings);
-		free(scheme->name);
-		free(scheme);
-	}
-}
-
-bool flib_scheme_get_mod(const flib_scheme *scheme, const char *name) {
-	if(!log_badargs_if2(scheme==NULL, name==NULL)) {
-		for(int i=0; i<flib_meta.modCount; i++) {
-			if(!strcmp(flib_meta.mods[i].name, name)) {
-				return scheme->mods[i];
-			}
-		}
-		flib_log_e("Unable to find game mod %s", name);
-	}
-	return false;
-}
-
-int flib_scheme_get_setting(const flib_scheme *scheme, const char *name, int def) {
-	if(!log_badargs_if2(scheme==NULL, name==NULL)) {
-		for(int i=0; i<flib_meta.settingCount; i++) {
-			if(!strcmp(flib_meta.settings[i].name, name)) {
-				return scheme->settings[i];
-			}
-		}
-		flib_log_e("Unable to find game setting %s", name);
-	}
-	return def;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "scheme.h"
+
+#include "../util/inihelper.h"
+#include "../util/logging.h"
+#include "../util/util.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+
+flib_scheme *flib_scheme_create(const char *schemeName) {
+    flib_scheme *result = flib_calloc(1, sizeof(flib_scheme));
+    if(log_badargs_if(schemeName==NULL) || result==NULL) {
+        return NULL;
+    }
+
+    result->name = flib_strdupnull(schemeName);
+    result->mods = flib_calloc(flib_meta.modCount, sizeof(*result->mods));
+    result->settings = flib_calloc(flib_meta.settingCount, sizeof(*result->settings));
+
+    if(!result->mods || !result->settings || !result->name) {
+        flib_scheme_destroy(result);
+        return NULL;
+    }
+
+    for(int i=0; i<flib_meta.settingCount; i++) {
+        result->settings[i] = flib_meta.settings[i].def;
+    }
+    return result;
+}
+
+flib_scheme *flib_scheme_copy(const flib_scheme *scheme) {
+    flib_scheme *result = NULL;
+    if(scheme) {
+        result = flib_scheme_create(scheme->name);
+        if(result) {
+            memcpy(result->mods, scheme->mods, flib_meta.modCount * sizeof(*scheme->mods));
+            memcpy(result->settings, scheme->settings, flib_meta.settingCount * sizeof(*scheme->settings));
+        }
+    }
+    return result;
+}
+
+void flib_scheme_destroy(flib_scheme* scheme) {
+    if(scheme) {
+        free(scheme->mods);
+        free(scheme->settings);
+        free(scheme->name);
+        free(scheme);
+    }
+}
+
+bool flib_scheme_get_mod(const flib_scheme *scheme, const char *name) {
+    if(!log_badargs_if2(scheme==NULL, name==NULL)) {
+        for(int i=0; i<flib_meta.modCount; i++) {
+            if(!strcmp(flib_meta.mods[i].name, name)) {
+                return scheme->mods[i];
+            }
+        }
+        flib_log_e("Unable to find game mod %s", name);
+    }
+    return false;
+}
+
+int flib_scheme_get_setting(const flib_scheme *scheme, const char *name, int def) {
+    if(!log_badargs_if2(scheme==NULL, name==NULL)) {
+        for(int i=0; i<flib_meta.settingCount; i++) {
+            if(!strcmp(flib_meta.settings[i].name, name)) {
+                return scheme->settings[i];
+            }
+        }
+        flib_log_e("Unable to find game setting %s", name);
+    }
+    return def;
+}
--- a/project_files/frontlib/model/scheme.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/scheme.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,72 +1,72 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * Data structures for game scheme information.
- *
- * The scheme consists of settings (integers) and mods (booleans). These are not fixed, but
- * described in a "metascheme", which describes how each setting and mod is sent to the
- * engine, and in which order they appear in the network protocol. The metascheme is defined
- * in hwconsts.h
- */
-
-#ifndef SCHEME_H_
-#define SCHEME_H_
-
-#include <stdbool.h>
-#include <stddef.h>
-#include "../hwconsts.h"
-
-/**
- * The settings and mods arrays have the same number and order of elements
- * as the corresponding arrays in the metascheme.
- */
-typedef struct {
-    char *name;
-    int *settings;
-    bool *mods;
-} flib_scheme;
-
-/**
- * Create a new configuration with everything set to default or false
- * Returns NULL on error.
- */
-flib_scheme *flib_scheme_create(const char *schemeName);
-
-/**
- * Create a copy of the scheme. Returns NULL on error or if NULL was passed.
- */
-flib_scheme *flib_scheme_copy(const flib_scheme *scheme);
-
-/**
- * Decrease the reference count of the object and free it if this was the last reference.
- */
-void flib_scheme_destroy(flib_scheme* scheme);
-
-/**
- * Retrieve a mod setting by its name. If the mod is not found, logs an error and returns false.
- */
-bool flib_scheme_get_mod(const flib_scheme *scheme, const char *name);
-
-/**
- * Retrieve a game setting by its name. If the setting is not found, logs an error and returns def.
- */
-int flib_scheme_get_setting(const flib_scheme *scheme, const char *name, int def);
-
-#endif /* SCHEME_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * Data structures for game scheme information.
+ *
+ * The scheme consists of settings (integers) and mods (booleans). These are not fixed, but
+ * described in a "metascheme", which describes how each setting and mod is sent to the
+ * engine, and in which order they appear in the network protocol. The metascheme is defined
+ * in hwconsts.h
+ */
+
+#ifndef SCHEME_H_
+#define SCHEME_H_
+
+#include <stdbool.h>
+#include <stddef.h>
+#include "../hwconsts.h"
+
+/**
+ * The settings and mods arrays have the same number and order of elements
+ * as the corresponding arrays in the metascheme.
+ */
+typedef struct {
+    char *name;
+    int *settings;
+    bool *mods;
+} flib_scheme;
+
+/**
+ * Create a new configuration with everything set to default or false
+ * Returns NULL on error.
+ */
+flib_scheme *flib_scheme_create(const char *schemeName);
+
+/**
+ * Create a copy of the scheme. Returns NULL on error or if NULL was passed.
+ */
+flib_scheme *flib_scheme_copy(const flib_scheme *scheme);
+
+/**
+ * Decrease the reference count of the object and free it if this was the last reference.
+ */
+void flib_scheme_destroy(flib_scheme* scheme);
+
+/**
+ * Retrieve a mod setting by its name. If the mod is not found, logs an error and returns false.
+ */
+bool flib_scheme_get_mod(const flib_scheme *scheme, const char *name);
+
+/**
+ * Retrieve a game setting by its name. If the setting is not found, logs an error and returns def.
+ */
+int flib_scheme_get_setting(const flib_scheme *scheme, const char *name, int def);
+
+#endif /* SCHEME_H_ */
--- a/project_files/frontlib/model/schemelist.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/schemelist.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,216 +1,216 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "schemelist.h"
-
-#include "../util/inihelper.h"
-#include "../util/logging.h"
-#include "../util/util.h"
-#include "../util/list.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-
-static char *makePrefixedName(int schemeIndex, const char *settingName) {
-	return flib_asprintf("%i\\%s", schemeIndex, settingName);
-}
-
-static int readSettingsFromIni(flib_ini *ini, flib_scheme *scheme, int index) {
-	bool error = false;
-	for(int i=0; i<flib_meta.settingCount && !error; i++) {
-		char *key = makePrefixedName(index, flib_meta.settings[i].name);
-		if(!key) {
-			error = true;
-		} else if(flib_ini_get_int_opt(ini, &scheme->settings[i], key, flib_meta.settings[i].def)) {
-			flib_log_e("Error reading setting %s in schemes file.", key);
-			error = true;
-		}
-		free(key);
-	}
-	return error;
-}
-
-static int readModsFromIni(flib_ini *ini, flib_scheme *scheme, int index) {
-	bool error = false;
-	for(int i=0; i<flib_meta.modCount && !error; i++) {
-		char *key = makePrefixedName(index, flib_meta.mods[i].name);
-		if(!key) {
-			error = true;
-		} else if(flib_ini_get_bool_opt(ini, &scheme->mods[i], key, false)) {
-			flib_log_e("Error reading mod %s in schemes file.", key);
-			error = true;
-		}
-		free(key);
-	}
-	return error;
-}
-
-static flib_scheme *readSchemeFromIni(flib_ini *ini, int index) {
-	flib_scheme *result = NULL;
-	char *schemeNameKey = makePrefixedName(index+1, "name");
-	if(schemeNameKey) {
-		char *schemeName = NULL;
-		if(!flib_ini_get_str_opt(ini, &schemeName, schemeNameKey, "Unnamed")) {
-			flib_scheme *tmpScheme = flib_scheme_create(schemeName);
-			if(tmpScheme) {
-				if(!readSettingsFromIni(ini, tmpScheme, index) && !readModsFromIni(ini, tmpScheme, index)) {
-					result = tmpScheme;
-					tmpScheme = NULL;
-				}
-			}
-			flib_scheme_destroy(tmpScheme);
-		}
-		free(schemeName);
-	}
-	free(schemeNameKey);
-	return result;
-}
-
-static flib_schemelist *fromIniHandleError(flib_schemelist *result, flib_ini *ini) {
-	flib_ini_destroy(ini);
-	flib_schemelist_destroy(result);
-	return NULL;
-}
-
-flib_schemelist *flib_schemelist_from_ini(const char *filename) {
-	if(log_badargs_if(filename==NULL)) {
-		return NULL;
-	}
-
-	flib_schemelist *list = NULL;
-	flib_ini *ini = flib_ini_load(filename);
-	if(!ini || flib_ini_enter_section(ini, "schemes")) {
-		flib_log_e("Missing file or missing section \"schemes\" in file %s.", filename);
-		return fromIniHandleError(list, ini);
-	}
-
-	list = flib_schemelist_create();
-	if(!list) {
-		return fromIniHandleError(list, ini);
-	}
-
-	int schemeCount = 0;
-	if(flib_ini_get_int(ini, &schemeCount, "size")) {
-		flib_log_e("Missing or malformed scheme count in config file %s.", filename);
-		return fromIniHandleError(list, ini);
-	}
-
-	for(int i=0; i<schemeCount; i++) {
-		flib_scheme *scheme = readSchemeFromIni(ini, i);
-		if(!scheme || flib_schemelist_insert(list, scheme, i)) {
-			flib_scheme_destroy(scheme);
-			flib_log_e("Error reading scheme %i from config file %s.", i, filename);
-			return fromIniHandleError(list, ini);
-		}
-	}
-
-
-	flib_ini_destroy(ini);
-	return list;
-}
-
-static int writeSchemeToIni(const flib_scheme *scheme, flib_ini *ini, int index) {
-	bool error = false;
-
-	char *key = makePrefixedName(index+1, "name");
-	error |= !key || flib_ini_set_str(ini, key, scheme->name);
-	free(key);
-
-	for(int i=0; i<flib_meta.modCount && !error; i++) {
-		char *key = makePrefixedName(index+1, flib_meta.mods[i].name);
-		error |= !key || flib_ini_set_bool(ini, key, scheme->mods[i]);
-		free(key);
-	}
-
-	for(int i=0; i<flib_meta.settingCount && !error; i++) {
-		char *key = makePrefixedName(index+1, flib_meta.settings[i].name);
-		error |= !key || flib_ini_set_int(ini, key, scheme->settings[i]);
-		free(key);
-	}
-	return error;
-}
-
-int flib_schemelist_to_ini(const char *filename, const flib_schemelist *schemes) {
-	int result = -1;
-	if(!log_badargs_if2(filename==NULL, schemes==NULL)) {
-		flib_ini *ini = flib_ini_create(NULL);
-		if(ini && !flib_ini_create_section(ini, "schemes")) {
-			bool error = false;
-			error |= flib_ini_set_int(ini, "size", schemes->schemeCount);
-			for(int i=0; i<schemes->schemeCount && !error; i++) {
-				error |= writeSchemeToIni(schemes->schemes[i], ini, i);
-			}
-
-			if(!error) {
-				result = flib_ini_save(ini, filename);
-			}
-		}
-		flib_ini_destroy(ini);
-	}
-	return result;
-}
-
-flib_schemelist *flib_schemelist_create() {
-	return flib_calloc(1, sizeof(flib_schemelist));
-}
-
-void flib_schemelist_destroy(flib_schemelist *list) {
-	if(list) {
-		for(int i=0; i<list->schemeCount; i++) {
-			flib_scheme_destroy(list->schemes[i]);
-		}
-		free(list->schemes);
-		free(list);
-	}
-}
-
-flib_scheme *flib_schemelist_find(flib_schemelist *list, const char *name) {
-	if(!log_badargs_if2(list==NULL, name==NULL)) {
-		for(int i=0; i<list->schemeCount; i++) {
-			if(!strcmp(name, list->schemes[i]->name)) {
-				return list->schemes[i];
-			}
-		}
-	}
-	return NULL;
-}
-
-GENERATE_STATIC_LIST_INSERT(insertScheme, flib_scheme*)
-GENERATE_STATIC_LIST_DELETE(deleteScheme, flib_scheme*)
-
-int flib_schemelist_insert(flib_schemelist *list, flib_scheme *cfg, int pos) {
-	if(!log_badargs_if2(list==NULL, cfg==NULL)
-			&& !insertScheme(&list->schemes, &list->schemeCount, cfg, pos)) {
-		return 0;
-	}
-	return -1;
-}
-
-int flib_schemelist_delete(flib_schemelist *list, int pos) {
-	if(!log_badargs_if(list==NULL)) {
-		flib_scheme *elem = list->schemes[pos];
-		if(!deleteScheme(&list->schemes, &list->schemeCount, pos)) {
-			flib_scheme_destroy(elem);
-			return 0;
-		}
-	}
-	return -1;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "schemelist.h"
+
+#include "../util/inihelper.h"
+#include "../util/logging.h"
+#include "../util/util.h"
+#include "../util/list.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+
+static char *makePrefixedName(int schemeIndex, const char *settingName) {
+    return flib_asprintf("%i\\%s", schemeIndex, settingName);
+}
+
+static int readSettingsFromIni(flib_ini *ini, flib_scheme *scheme, int index) {
+    bool error = false;
+    for(int i=0; i<flib_meta.settingCount && !error; i++) {
+        char *key = makePrefixedName(index, flib_meta.settings[i].name);
+        if(!key) {
+            error = true;
+        } else if(flib_ini_get_int_opt(ini, &scheme->settings[i], key, flib_meta.settings[i].def)) {
+            flib_log_e("Error reading setting %s in schemes file.", key);
+            error = true;
+        }
+        free(key);
+    }
+    return error;
+}
+
+static int readModsFromIni(flib_ini *ini, flib_scheme *scheme, int index) {
+    bool error = false;
+    for(int i=0; i<flib_meta.modCount && !error; i++) {
+        char *key = makePrefixedName(index, flib_meta.mods[i].name);
+        if(!key) {
+            error = true;
+        } else if(flib_ini_get_bool_opt(ini, &scheme->mods[i], key, false)) {
+            flib_log_e("Error reading mod %s in schemes file.", key);
+            error = true;
+        }
+        free(key);
+    }
+    return error;
+}
+
+static flib_scheme *readSchemeFromIni(flib_ini *ini, int index) {
+    flib_scheme *result = NULL;
+    char *schemeNameKey = makePrefixedName(index+1, "name");
+    if(schemeNameKey) {
+        char *schemeName = NULL;
+        if(!flib_ini_get_str_opt(ini, &schemeName, schemeNameKey, "Unnamed")) {
+            flib_scheme *tmpScheme = flib_scheme_create(schemeName);
+            if(tmpScheme) {
+                if(!readSettingsFromIni(ini, tmpScheme, index) && !readModsFromIni(ini, tmpScheme, index)) {
+                    result = tmpScheme;
+                    tmpScheme = NULL;
+                }
+            }
+            flib_scheme_destroy(tmpScheme);
+        }
+        free(schemeName);
+    }
+    free(schemeNameKey);
+    return result;
+}
+
+static flib_schemelist *fromIniHandleError(flib_schemelist *result, flib_ini *ini) {
+    flib_ini_destroy(ini);
+    flib_schemelist_destroy(result);
+    return NULL;
+}
+
+flib_schemelist *flib_schemelist_from_ini(const char *filename) {
+    if(log_badargs_if(filename==NULL)) {
+        return NULL;
+    }
+
+    flib_schemelist *list = NULL;
+    flib_ini *ini = flib_ini_load(filename);
+    if(!ini || flib_ini_enter_section(ini, "schemes")) {
+        flib_log_e("Missing file or missing section \"schemes\" in file %s.", filename);
+        return fromIniHandleError(list, ini);
+    }
+
+    list = flib_schemelist_create();
+    if(!list) {
+        return fromIniHandleError(list, ini);
+    }
+
+    int schemeCount = 0;
+    if(flib_ini_get_int(ini, &schemeCount, "size")) {
+        flib_log_e("Missing or malformed scheme count in config file %s.", filename);
+        return fromIniHandleError(list, ini);
+    }
+
+    for(int i=0; i<schemeCount; i++) {
+        flib_scheme *scheme = readSchemeFromIni(ini, i);
+        if(!scheme || flib_schemelist_insert(list, scheme, i)) {
+            flib_scheme_destroy(scheme);
+            flib_log_e("Error reading scheme %i from config file %s.", i, filename);
+            return fromIniHandleError(list, ini);
+        }
+    }
+
+
+    flib_ini_destroy(ini);
+    return list;
+}
+
+static int writeSchemeToIni(const flib_scheme *scheme, flib_ini *ini, int index) {
+    bool error = false;
+
+    char *key = makePrefixedName(index+1, "name");
+    error |= !key || flib_ini_set_str(ini, key, scheme->name);
+    free(key);
+
+    for(int i=0; i<flib_meta.modCount && !error; i++) {
+        char *key = makePrefixedName(index+1, flib_meta.mods[i].name);
+        error |= !key || flib_ini_set_bool(ini, key, scheme->mods[i]);
+        free(key);
+    }
+
+    for(int i=0; i<flib_meta.settingCount && !error; i++) {
+        char *key = makePrefixedName(index+1, flib_meta.settings[i].name);
+        error |= !key || flib_ini_set_int(ini, key, scheme->settings[i]);
+        free(key);
+    }
+    return error;
+}
+
+int flib_schemelist_to_ini(const char *filename, const flib_schemelist *schemes) {
+    int result = -1;
+    if(!log_badargs_if2(filename==NULL, schemes==NULL)) {
+        flib_ini *ini = flib_ini_create(NULL);
+        if(ini && !flib_ini_create_section(ini, "schemes")) {
+            bool error = false;
+            error |= flib_ini_set_int(ini, "size", schemes->schemeCount);
+            for(int i=0; i<schemes->schemeCount && !error; i++) {
+                error |= writeSchemeToIni(schemes->schemes[i], ini, i);
+            }
+
+            if(!error) {
+                result = flib_ini_save(ini, filename);
+            }
+        }
+        flib_ini_destroy(ini);
+    }
+    return result;
+}
+
+flib_schemelist *flib_schemelist_create() {
+    return flib_calloc(1, sizeof(flib_schemelist));
+}
+
+void flib_schemelist_destroy(flib_schemelist *list) {
+    if(list) {
+        for(int i=0; i<list->schemeCount; i++) {
+            flib_scheme_destroy(list->schemes[i]);
+        }
+        free(list->schemes);
+        free(list);
+    }
+}
+
+flib_scheme *flib_schemelist_find(flib_schemelist *list, const char *name) {
+    if(!log_badargs_if2(list==NULL, name==NULL)) {
+        for(int i=0; i<list->schemeCount; i++) {
+            if(!strcmp(name, list->schemes[i]->name)) {
+                return list->schemes[i];
+            }
+        }
+    }
+    return NULL;
+}
+
+GENERATE_STATIC_LIST_INSERT(insertScheme, flib_scheme*)
+GENERATE_STATIC_LIST_DELETE(deleteScheme, flib_scheme*)
+
+int flib_schemelist_insert(flib_schemelist *list, flib_scheme *cfg, int pos) {
+    if(!log_badargs_if2(list==NULL, cfg==NULL)
+            && !insertScheme(&list->schemes, &list->schemeCount, cfg, pos)) {
+        return 0;
+    }
+    return -1;
+}
+
+int flib_schemelist_delete(flib_schemelist *list, int pos) {
+    if(!log_badargs_if(list==NULL)) {
+        flib_scheme *elem = list->schemes[pos];
+        if(!deleteScheme(&list->schemes, &list->schemeCount, pos)) {
+            flib_scheme_destroy(elem);
+            return 0;
+        }
+    }
+    return -1;
+}
--- a/project_files/frontlib/model/schemelist.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/schemelist.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,79 +1,79 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * Functions for managing a list of schemes.
- * This is in here because the scheme config file of the QtFrontend (which we are staying compatible with) contains
- * all the schemes at once, so we need functions to work with a list like that.
- */
-
-#ifndef SCHEMELIST_H_
-#define SCHEMELIST_H_
-
-#include "scheme.h"
-
-typedef struct {
-	int schemeCount;
-	flib_scheme **schemes;
-} flib_schemelist;
-
-/**
- * Load a list of configurations from the ini file.
- * Returns NULL on error.
- */
-flib_schemelist *flib_schemelist_from_ini(const char *filename);
-
-/**
- * Store the list of configurations to an ini file.
- * Returns NULL on error.
- */
-int flib_schemelist_to_ini(const char *filename, const flib_schemelist *config);
-
-/**
- * Create an empty scheme list. Returns NULL on error.
- */
-flib_schemelist *flib_schemelist_create();
-
-/**
- * Insert a new scheme into the list at position pos, moving all higher schemes to make place.
- * pos must be at least 0 (insert at the start) and at most list->schemeCount (insert at the end).
- * Ownership of the scheme is transferred to the list.
- * Returns 0 on success.
- */
-int flib_schemelist_insert(flib_schemelist *list, flib_scheme *cfg, int pos);
-
-/**
- * Delete a scheme from the list at position pos, moving down all higher schemes.
- * The scheme is destroyed.
- * Returns 0 on success.
- */
-int flib_schemelist_delete(flib_schemelist *list, int pos);
-
-/**
- * Find the scheme with a specific name
- */
-flib_scheme *flib_schemelist_find(flib_schemelist *list, const char *name);
-
-/**
- * Free this schemelist and all contained schemes
- */
-void flib_schemelist_destroy(flib_schemelist *list);
-
-
-#endif /* SCHEMELIST_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * Functions for managing a list of schemes.
+ * This is in here because the scheme config file of the QtFrontend (which we are staying compatible with) contains
+ * all the schemes at once, so we need functions to work with a list like that.
+ */
+
+#ifndef SCHEMELIST_H_
+#define SCHEMELIST_H_
+
+#include "scheme.h"
+
+typedef struct {
+    int schemeCount;
+    flib_scheme **schemes;
+} flib_schemelist;
+
+/**
+ * Load a list of configurations from the ini file.
+ * Returns NULL on error.
+ */
+flib_schemelist *flib_schemelist_from_ini(const char *filename);
+
+/**
+ * Store the list of configurations to an ini file.
+ * Returns NULL on error.
+ */
+int flib_schemelist_to_ini(const char *filename, const flib_schemelist *config);
+
+/**
+ * Create an empty scheme list. Returns NULL on error.
+ */
+flib_schemelist *flib_schemelist_create();
+
+/**
+ * Insert a new scheme into the list at position pos, moving all higher schemes to make place.
+ * pos must be at least 0 (insert at the start) and at most list->schemeCount (insert at the end).
+ * Ownership of the scheme is transferred to the list.
+ * Returns 0 on success.
+ */
+int flib_schemelist_insert(flib_schemelist *list, flib_scheme *cfg, int pos);
+
+/**
+ * Delete a scheme from the list at position pos, moving down all higher schemes.
+ * The scheme is destroyed.
+ * Returns 0 on success.
+ */
+int flib_schemelist_delete(flib_schemelist *list, int pos);
+
+/**
+ * Find the scheme with a specific name
+ */
+flib_scheme *flib_schemelist_find(flib_schemelist *list, const char *name);
+
+/**
+ * Free this schemelist and all contained schemes
+ */
+void flib_schemelist_destroy(flib_schemelist *list);
+
+
+#endif /* SCHEMELIST_H_ */
--- a/project_files/frontlib/model/team.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/team.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,323 +1,323 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "team.h"
-
-#include "../util/inihelper.h"
-#include "../util/util.h"
-#include "../util/logging.h"
-
-#include <string.h>
-#include <stdlib.h>
-
-static flib_team *from_ini_handleError(flib_team *result, flib_ini *settingfile) {
-	flib_ini_destroy(settingfile);
-	flib_team_destroy(result);
-	return NULL;
-}
-
-flib_team *flib_team_from_ini(const char *filename) {
-	if(log_badargs_if(filename==NULL)) {
-		return NULL;
-	}
-
-	flib_team *result = flib_calloc(1, sizeof(flib_team));
-	flib_ini *ini = NULL;
-
-	if(!result) {
-		return from_ini_handleError(result, ini);
-	}
-
-	ini = flib_ini_load(filename);
-	if(!ini) {
-		flib_log_e("Error loading team file %s", filename);
-		return from_ini_handleError(result, ini);
-	}
-
-	if(flib_ini_enter_section(ini, "team")) {
-		flib_log_e("Missing section \"Team\" in team file %s", filename);
-		return from_ini_handleError(result, ini);
-	}
-	bool error = false;
-	error |= flib_ini_get_str(ini, &result->name, "name");
-	error |= flib_ini_get_str(ini, &result->grave, "grave");
-	error |= flib_ini_get_str(ini, &result->fort, "fort");
-	error |= flib_ini_get_str(ini, &result->voicepack, "voicepack");
-	error |= flib_ini_get_str(ini, &result->flag, "flag");
-	error |= flib_ini_get_int(ini, &result->rounds, "rounds");
-	error |= flib_ini_get_int(ini, &result->wins, "wins");
-	error |= flib_ini_get_int(ini, &result->campaignProgress, "campaignprogress");
-
-	int difficulty = 0;
-	error |= flib_ini_get_int(ini, &difficulty, "difficulty");
-
-	if(error) {
-		flib_log_e("Missing or malformed entry in section \"Team\" in file %s", filename);
-		return from_ini_handleError(result, ini);
-	}
-
-	for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-		char sectionName[32];
-		if(snprintf(sectionName, sizeof(sectionName), "hedgehog%i", i) <= 0) {
-			return from_ini_handleError(result, ini);
-		}
-		if(flib_ini_enter_section(ini, sectionName)) {
-			flib_log_e("Missing section \"%s\" in team file %s", sectionName, filename);
-			return from_ini_handleError(result, ini);
-		}
-		flib_hog *hog = &result->hogs[i];
-		error |= flib_ini_get_str(ini, &hog->name, "name");
-		error |= flib_ini_get_str(ini, &hog->hat, "hat");
-		error |= flib_ini_get_int(ini, &hog->rounds, "rounds");
-		error |= flib_ini_get_int(ini, &hog->kills, "kills");
-		error |= flib_ini_get_int(ini, &hog->deaths, "deaths");
-		error |= flib_ini_get_int(ini, &hog->suicides, "suicides");
-		result->hogs[i].difficulty = difficulty;
-		result->hogs[i].initialHealth = TEAM_DEFAULT_HEALTH;
-
-		if(error) {
-			flib_log_e("Missing or malformed entry in section \"%s\" in file %s", sectionName, filename);
-			return from_ini_handleError(result, ini);
-		}
-	}
-
-	if(!flib_ini_enter_section(ini, "binds")) {
-		result->bindingCount = flib_ini_get_keycount(ini);
-		if(result->bindingCount<0) {
-			flib_log_e("Error reading bindings from file %s", filename);
-			result->bindingCount = 0;
-		}
-		result->bindings = flib_calloc(result->bindingCount, sizeof(flib_binding));
-		if(!result->bindings) {
-			return from_ini_handleError(result, ini);
-		}
-		for(int i=0; i<result->bindingCount; i++) {
-			char *keyname = flib_ini_get_keyname(ini, i);
-			if(!keyname) {
-				error = true;
-			} else {
-				result->bindings[i].action = flib_urldecode(keyname);
-				error |= !result->bindings[i].action;
-				error |= flib_ini_get_str(ini, &result->bindings[i].binding, keyname);
-			}
-			free(keyname);
-		}
-	}
-
-	if(error) {
-		flib_log_e("Error reading team file %s", filename);
-		return from_ini_handleError(result, ini);
-	}
-
-	flib_ini_destroy(ini);
-	return result;
-}
-
-void flib_team_destroy(flib_team *team) {
-	if(team) {
-		for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-			free(team->hogs[i].name);
-			free(team->hogs[i].hat);
-			flib_weaponset_destroy(team->hogs[i].weaponset);
-		}
-		free(team->name);
-		free(team->grave);
-		free(team->fort);
-		free(team->voicepack);
-		free(team->flag);
-		if(team->bindings) {
-			for(int i=0; i<team->bindingCount; i++) {
-				free(team->bindings[i].action);
-				free(team->bindings[i].binding);
-			}
-		}
-		free(team->bindings);
-		free(team->ownerName);
-		free(team);
-	}
-}
-
-static int writeTeamSection(const flib_team *team, flib_ini *ini) {
-	if(flib_ini_create_section(ini, "team")) {
-		return -1;
-	}
-	bool error = false;
-	error |= flib_ini_set_str(ini, "name",  team->name);
-	error |= flib_ini_set_str(ini, "grave", team->grave);
-	error |= flib_ini_set_str(ini, "fort", team->fort);
-	error |= flib_ini_set_str(ini, "voicepack", team->voicepack);
-	error |= flib_ini_set_str(ini, "flag", team->flag);
-	error |= flib_ini_set_int(ini, "rounds", team->rounds);
-	error |= flib_ini_set_int(ini, "wins", team->wins);
-	error |= flib_ini_set_int(ini, "campaignprogress", team->campaignProgress);
-	error |= flib_ini_set_int(ini, "difficulty", team->hogs[0].difficulty);
-	return error;
-}
-
-static int writeHogSections(const flib_team *team, flib_ini *ini) {
-	for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-		const flib_hog *hog = &team->hogs[i];
-		char sectionName[32];
-		if(snprintf(sectionName, sizeof(sectionName), "hedgehog%i", i) <= 0) {
-			return -1;
-		}
-		if(flib_ini_create_section(ini, sectionName)) {
-			return -1;
-		}
-		bool error = false;
-		error |= flib_ini_set_str(ini, "name", hog->name);
-		error |= flib_ini_set_str(ini, "hat", hog->hat);
-		error |= flib_ini_set_int(ini, "rounds", hog->rounds);
-		error |= flib_ini_set_int(ini, "kills", hog->kills);
-		error |= flib_ini_set_int(ini, "deaths", hog->deaths);
-		error |= flib_ini_set_int(ini, "suicides", hog->suicides);
-		if(error) {
-			return error;
-		}
-	}
-	return 0;
-}
-
-static int writeBindingSection(const flib_team *team, flib_ini *ini) {
-	if(team->bindingCount == 0) {
-		return 0;
-	}
-	if(flib_ini_create_section(ini, "binds")) {
-		return -1;
-	}
-	for(int i=0; i<team->bindingCount; i++) {
-		bool error = false;
-		char *action = flib_urlencode(team->bindings[i].action);
-		if(action) {
-			error |= flib_ini_set_str(ini, action, team->bindings[i].binding);
-			free(action);
-		} else {
-			error = true;
-		}
-		if(error) {
-			return error;
-		}
-	}
-	return 0;
-}
-
-int flib_team_to_ini(const char *filename, const flib_team *team) {
-	int result = -1;
-	if(!log_badargs_if2(filename==NULL, team==NULL)) {
-		flib_ini *ini = flib_ini_create(filename);
-		bool error = false;
-		error |= writeTeamSection(team, ini);
-		error |= writeHogSections(team, ini);
-		error |= writeBindingSection(team, ini);
-		if(!error) {
-			result = flib_ini_save(ini, filename);
-		}
-		flib_ini_destroy(ini);
-	}
-	return result;
-}
-
-int flib_team_set_weaponset(flib_team *team, const flib_weaponset *set) {
-	if(team) {
-		for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-			flib_weaponset_destroy(team->hogs[i].weaponset);
-			team->hogs[i].weaponset = flib_weaponset_copy(set);
-			if(set && !team->hogs[i].weaponset) {
-				return -1;
-			}
-		}
-	}
-	return 0;
-}
-
-void flib_team_set_health(flib_team *team, int health) {
-	if(team) {
-		for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-			team->hogs[i].initialHealth = health;
-		}
-	}
-}
-
-static char *strdupWithError(const char *in, bool *error) {
-	char *out = flib_strdupnull(in);
-	if(in && !out) {
-		*error = true;
-	}
-	return out;
-}
-
-flib_team *flib_team_copy(const flib_team *team) {
-	flib_team *result = NULL;
-	if(team) {
-		flib_team *tmpTeam = flib_calloc(1, sizeof(flib_team));
-		if(tmpTeam) {
-			bool error = false;
-
-			for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-				tmpTeam->hogs[i].name = strdupWithError(team->hogs[i].name, &error);
-				tmpTeam->hogs[i].hat = strdupWithError(team->hogs[i].hat, &error);
-				tmpTeam->hogs[i].rounds = team->hogs[i].rounds;
-				tmpTeam->hogs[i].kills = team->hogs[i].kills;
-				tmpTeam->hogs[i].deaths = team->hogs[i].deaths;
-				tmpTeam->hogs[i].suicides = team->hogs[i].suicides;
-				tmpTeam->hogs[i].difficulty = team->hogs[i].difficulty;
-				tmpTeam->hogs[i].initialHealth = team->hogs[i].initialHealth;
-				tmpTeam->hogs[i].weaponset = flib_weaponset_copy(team->hogs[i].weaponset);
-				if(team->hogs[i].weaponset && !tmpTeam->hogs[i].weaponset) {
-					error = true;
-				}
-			}
-
-			tmpTeam->name = strdupWithError(team->name, &error);
-			tmpTeam->grave = strdupWithError(team->grave, &error);
-			tmpTeam->fort = strdupWithError(team->fort, &error);
-			tmpTeam->voicepack = strdupWithError(team->voicepack, &error);
-			tmpTeam->flag = strdupWithError(team->flag, &error);
-			tmpTeam->ownerName = strdupWithError(team->ownerName, &error);
-
-			tmpTeam->bindingCount = team->bindingCount;
-			if(team->bindings) {
-				tmpTeam->bindings = flib_calloc(team->bindingCount, sizeof(flib_binding));
-				if(tmpTeam->bindings) {
-					for(int i=0; i<tmpTeam->bindingCount; i++) {
-						tmpTeam->bindings[i].action = strdupWithError(team->bindings[i].action, &error);
-						tmpTeam->bindings[i].binding = strdupWithError(team->bindings[i].binding, &error);
-					}
-				} else {
-					error = true;
-				}
-			}
-
-			tmpTeam->rounds = team->rounds;
-			tmpTeam->wins = team->wins;
-			tmpTeam->campaignProgress = team->campaignProgress;
-
-			tmpTeam->colorIndex = team->colorIndex;
-			tmpTeam->hogsInGame = team->hogsInGame;
-			tmpTeam->remoteDriven = team->remoteDriven;
-
-			if(!error) {
-				result = tmpTeam;
-				tmpTeam = 0;
-			}
-		}
-		flib_team_destroy(tmpTeam);
-	}
-	return result;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "team.h"
+
+#include "../util/inihelper.h"
+#include "../util/util.h"
+#include "../util/logging.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+static flib_team *from_ini_handleError(flib_team *result, flib_ini *settingfile) {
+    flib_ini_destroy(settingfile);
+    flib_team_destroy(result);
+    return NULL;
+}
+
+flib_team *flib_team_from_ini(const char *filename) {
+    if(log_badargs_if(filename==NULL)) {
+        return NULL;
+    }
+
+    flib_team *result = flib_calloc(1, sizeof(flib_team));
+    flib_ini *ini = NULL;
+
+    if(!result) {
+        return from_ini_handleError(result, ini);
+    }
+
+    ini = flib_ini_load(filename);
+    if(!ini) {
+        flib_log_e("Error loading team file %s", filename);
+        return from_ini_handleError(result, ini);
+    }
+
+    if(flib_ini_enter_section(ini, "team")) {
+        flib_log_e("Missing section \"Team\" in team file %s", filename);
+        return from_ini_handleError(result, ini);
+    }
+    bool error = false;
+    error |= flib_ini_get_str(ini, &result->name, "name");
+    error |= flib_ini_get_str(ini, &result->grave, "grave");
+    error |= flib_ini_get_str(ini, &result->fort, "fort");
+    error |= flib_ini_get_str(ini, &result->voicepack, "voicepack");
+    error |= flib_ini_get_str(ini, &result->flag, "flag");
+    error |= flib_ini_get_int(ini, &result->rounds, "rounds");
+    error |= flib_ini_get_int(ini, &result->wins, "wins");
+    error |= flib_ini_get_int(ini, &result->campaignProgress, "campaignprogress");
+
+    int difficulty = 0;
+    error |= flib_ini_get_int(ini, &difficulty, "difficulty");
+
+    if(error) {
+        flib_log_e("Missing or malformed entry in section \"Team\" in file %s", filename);
+        return from_ini_handleError(result, ini);
+    }
+
+    for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+        char sectionName[32];
+        if(snprintf(sectionName, sizeof(sectionName), "hedgehog%i", i) <= 0) {
+            return from_ini_handleError(result, ini);
+        }
+        if(flib_ini_enter_section(ini, sectionName)) {
+            flib_log_e("Missing section \"%s\" in team file %s", sectionName, filename);
+            return from_ini_handleError(result, ini);
+        }
+        flib_hog *hog = &result->hogs[i];
+        error |= flib_ini_get_str(ini, &hog->name, "name");
+        error |= flib_ini_get_str(ini, &hog->hat, "hat");
+        error |= flib_ini_get_int(ini, &hog->rounds, "rounds");
+        error |= flib_ini_get_int(ini, &hog->kills, "kills");
+        error |= flib_ini_get_int(ini, &hog->deaths, "deaths");
+        error |= flib_ini_get_int(ini, &hog->suicides, "suicides");
+        result->hogs[i].difficulty = difficulty;
+        result->hogs[i].initialHealth = TEAM_DEFAULT_HEALTH;
+
+        if(error) {
+            flib_log_e("Missing or malformed entry in section \"%s\" in file %s", sectionName, filename);
+            return from_ini_handleError(result, ini);
+        }
+    }
+
+    if(!flib_ini_enter_section(ini, "binds")) {
+        result->bindingCount = flib_ini_get_keycount(ini);
+        if(result->bindingCount<0) {
+            flib_log_e("Error reading bindings from file %s", filename);
+            result->bindingCount = 0;
+        }
+        result->bindings = flib_calloc(result->bindingCount, sizeof(flib_binding));
+        if(!result->bindings) {
+            return from_ini_handleError(result, ini);
+        }
+        for(int i=0; i<result->bindingCount; i++) {
+            char *keyname = flib_ini_get_keyname(ini, i);
+            if(!keyname) {
+                error = true;
+            } else {
+                result->bindings[i].action = flib_urldecode(keyname);
+                error |= !result->bindings[i].action;
+                error |= flib_ini_get_str(ini, &result->bindings[i].binding, keyname);
+            }
+            free(keyname);
+        }
+    }
+
+    if(error) {
+        flib_log_e("Error reading team file %s", filename);
+        return from_ini_handleError(result, ini);
+    }
+
+    flib_ini_destroy(ini);
+    return result;
+}
+
+void flib_team_destroy(flib_team *team) {
+    if(team) {
+        for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+            free(team->hogs[i].name);
+            free(team->hogs[i].hat);
+            flib_weaponset_destroy(team->hogs[i].weaponset);
+        }
+        free(team->name);
+        free(team->grave);
+        free(team->fort);
+        free(team->voicepack);
+        free(team->flag);
+        if(team->bindings) {
+            for(int i=0; i<team->bindingCount; i++) {
+                free(team->bindings[i].action);
+                free(team->bindings[i].binding);
+            }
+        }
+        free(team->bindings);
+        free(team->ownerName);
+        free(team);
+    }
+}
+
+static int writeTeamSection(const flib_team *team, flib_ini *ini) {
+    if(flib_ini_create_section(ini, "team")) {
+        return -1;
+    }
+    bool error = false;
+    error |= flib_ini_set_str(ini, "name",  team->name);
+    error |= flib_ini_set_str(ini, "grave", team->grave);
+    error |= flib_ini_set_str(ini, "fort", team->fort);
+    error |= flib_ini_set_str(ini, "voicepack", team->voicepack);
+    error |= flib_ini_set_str(ini, "flag", team->flag);
+    error |= flib_ini_set_int(ini, "rounds", team->rounds);
+    error |= flib_ini_set_int(ini, "wins", team->wins);
+    error |= flib_ini_set_int(ini, "campaignprogress", team->campaignProgress);
+    error |= flib_ini_set_int(ini, "difficulty", team->hogs[0].difficulty);
+    return error;
+}
+
+static int writeHogSections(const flib_team *team, flib_ini *ini) {
+    for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+        const flib_hog *hog = &team->hogs[i];
+        char sectionName[32];
+        if(snprintf(sectionName, sizeof(sectionName), "hedgehog%i", i) <= 0) {
+            return -1;
+        }
+        if(flib_ini_create_section(ini, sectionName)) {
+            return -1;
+        }
+        bool error = false;
+        error |= flib_ini_set_str(ini, "name", hog->name);
+        error |= flib_ini_set_str(ini, "hat", hog->hat);
+        error |= flib_ini_set_int(ini, "rounds", hog->rounds);
+        error |= flib_ini_set_int(ini, "kills", hog->kills);
+        error |= flib_ini_set_int(ini, "deaths", hog->deaths);
+        error |= flib_ini_set_int(ini, "suicides", hog->suicides);
+        if(error) {
+            return error;
+        }
+    }
+    return 0;
+}
+
+static int writeBindingSection(const flib_team *team, flib_ini *ini) {
+    if(team->bindingCount == 0) {
+        return 0;
+    }
+    if(flib_ini_create_section(ini, "binds")) {
+        return -1;
+    }
+    for(int i=0; i<team->bindingCount; i++) {
+        bool error = false;
+        char *action = flib_urlencode(team->bindings[i].action);
+        if(action) {
+            error |= flib_ini_set_str(ini, action, team->bindings[i].binding);
+            free(action);
+        } else {
+            error = true;
+        }
+        if(error) {
+            return error;
+        }
+    }
+    return 0;
+}
+
+int flib_team_to_ini(const char *filename, const flib_team *team) {
+    int result = -1;
+    if(!log_badargs_if2(filename==NULL, team==NULL)) {
+        flib_ini *ini = flib_ini_create(filename);
+        bool error = false;
+        error |= writeTeamSection(team, ini);
+        error |= writeHogSections(team, ini);
+        error |= writeBindingSection(team, ini);
+        if(!error) {
+            result = flib_ini_save(ini, filename);
+        }
+        flib_ini_destroy(ini);
+    }
+    return result;
+}
+
+int flib_team_set_weaponset(flib_team *team, const flib_weaponset *set) {
+    if(team) {
+        for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+            flib_weaponset_destroy(team->hogs[i].weaponset);
+            team->hogs[i].weaponset = flib_weaponset_copy(set);
+            if(set && !team->hogs[i].weaponset) {
+                return -1;
+            }
+        }
+    }
+    return 0;
+}
+
+void flib_team_set_health(flib_team *team, int health) {
+    if(team) {
+        for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+            team->hogs[i].initialHealth = health;
+        }
+    }
+}
+
+static char *strdupWithError(const char *in, bool *error) {
+    char *out = flib_strdupnull(in);
+    if(in && !out) {
+        *error = true;
+    }
+    return out;
+}
+
+flib_team *flib_team_copy(const flib_team *team) {
+    flib_team *result = NULL;
+    if(team) {
+        flib_team *tmpTeam = flib_calloc(1, sizeof(flib_team));
+        if(tmpTeam) {
+            bool error = false;
+
+            for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+                tmpTeam->hogs[i].name = strdupWithError(team->hogs[i].name, &error);
+                tmpTeam->hogs[i].hat = strdupWithError(team->hogs[i].hat, &error);
+                tmpTeam->hogs[i].rounds = team->hogs[i].rounds;
+                tmpTeam->hogs[i].kills = team->hogs[i].kills;
+                tmpTeam->hogs[i].deaths = team->hogs[i].deaths;
+                tmpTeam->hogs[i].suicides = team->hogs[i].suicides;
+                tmpTeam->hogs[i].difficulty = team->hogs[i].difficulty;
+                tmpTeam->hogs[i].initialHealth = team->hogs[i].initialHealth;
+                tmpTeam->hogs[i].weaponset = flib_weaponset_copy(team->hogs[i].weaponset);
+                if(team->hogs[i].weaponset && !tmpTeam->hogs[i].weaponset) {
+                    error = true;
+                }
+            }
+
+            tmpTeam->name = strdupWithError(team->name, &error);
+            tmpTeam->grave = strdupWithError(team->grave, &error);
+            tmpTeam->fort = strdupWithError(team->fort, &error);
+            tmpTeam->voicepack = strdupWithError(team->voicepack, &error);
+            tmpTeam->flag = strdupWithError(team->flag, &error);
+            tmpTeam->ownerName = strdupWithError(team->ownerName, &error);
+
+            tmpTeam->bindingCount = team->bindingCount;
+            if(team->bindings) {
+                tmpTeam->bindings = flib_calloc(team->bindingCount, sizeof(flib_binding));
+                if(tmpTeam->bindings) {
+                    for(int i=0; i<tmpTeam->bindingCount; i++) {
+                        tmpTeam->bindings[i].action = strdupWithError(team->bindings[i].action, &error);
+                        tmpTeam->bindings[i].binding = strdupWithError(team->bindings[i].binding, &error);
+                    }
+                } else {
+                    error = true;
+                }
+            }
+
+            tmpTeam->rounds = team->rounds;
+            tmpTeam->wins = team->wins;
+            tmpTeam->campaignProgress = team->campaignProgress;
+
+            tmpTeam->colorIndex = team->colorIndex;
+            tmpTeam->hogsInGame = team->hogsInGame;
+            tmpTeam->remoteDriven = team->remoteDriven;
+
+            if(!error) {
+                result = tmpTeam;
+                tmpTeam = 0;
+            }
+        }
+        flib_team_destroy(tmpTeam);
+    }
+    return result;
+}
--- a/project_files/frontlib/model/team.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/team.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,130 +1,130 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * This file defines a data structure for a hedgewars team.
- *
- * Teams are used in several different contexts in Hedgewars, and some of these require
- * extra information about teams. For example, the weaponset is important
- * to the engine, but not for ini reading/writing, and with the team statistics it is the
- * other way around. To keep things simple, the data structure can hold all information
- * used in any context. On the downside, that means we can't use static typing to ensure
- * that team information is "complete" for a particular purpose.
- */
-#ifndef TEAM_H_
-#define TEAM_H_
-
-
-#include "weapon.h"
-#include "../hwconsts.h"
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#define TEAM_DEFAULT_HEALTH 100
-
-/**
- * Struct representing a single keybinding.
- */
-typedef struct {
-	char *action;
-	char *binding;
-} flib_binding;
-
-typedef struct {
-	char *name;
-	char *hat;			//!< e.g. hair_yellow; References a .png file in Data/Graphics/Hats
-
-	//! Statistics. They are irrelevant for the engine or server,
-	//! but provided for ini reading/writing by the frontend.
-	int rounds;
-	int kills;
-	int deaths;
-	int suicides;
-
-	int difficulty;		//!< 0 = human, 1 = most difficult bot ... 5 = least difficult bot (somewhat counterintuitive)
-
-	//! Transient setting used in game setup
-	int initialHealth;
-	flib_weaponset *weaponset;
-} flib_hog;
-
-typedef struct {
-	flib_hog hogs[HEDGEHOGS_PER_TEAM];
-	char *name;
-	char *grave;		//!< e.g. "Bone"; References a .png file in Data/Graphics/Graves
-	char *fort;			//!< e.g. "Castle"; References a series of files in Data/Forts
-	char *voicepack;	//!< e.g. "Classic"; References a directory in Data/Sounds/voices
-	char *flag;			//!< e.g. "hedgewars"; References a .png file in Data/Graphics/Flags
-
-	flib_binding *bindings;
-	int bindingCount;
-
-	//! Statistics. They are irrelevant for the engine or server,
-	//! but provided for ini reading/writing by the frontend.
-	int rounds;
-	int wins;
-	int campaignProgress;
-
-	//! Transient settings used in game setup
-	int colorIndex;		//!< Index into a color table
-	int hogsInGame;		//!< The number of hogs that will actually play
-	bool remoteDriven;	//!< true for non-local teams in a network game
-	char *ownerName;	//!< Username of the owner of a team in a network game
-} flib_team;
-
-/**
- * Free all memory associated with the team
- */
-void flib_team_destroy(flib_team *team);
-
-/**
- * Loads a team, returns NULL on error. Destroy this team using flib_team_destroy.
- * This will not fill in the fields marked as "transient" in the structs above.
- */
-flib_team *flib_team_from_ini(const char *filename);
-
-/**
- * Write the team to an ini file. Attempts to retain extra ini settings
- * that were already present. Note that not all fields of a team struct
- * are stored in the ini, some are only used intermittently to store
- * information about a team in the context of a game.
- *
- * The flib_team can handle "difficulty" on a per-hog basis, but it
- * is only written per-team in the team file. The difficulty of the
- * first hog is used for the entire team when writing.
- */
-int flib_team_to_ini(const char *filename, const flib_team *team);
-
-/**
- * Set the same weaponset for every hog in the team
- */
-int flib_team_set_weaponset(flib_team *team, const flib_weaponset *set);
-
-/**
- * Set the same initial health for every hog.
- */
-void flib_team_set_health(flib_team *team, int health);
-
-/**
- * Create a deep copy of a team. Returns NULL on failure.
- */
-flib_team *flib_team_copy(const flib_team *team);
-
-#endif /* TEAM_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * This file defines a data structure for a hedgewars team.
+ *
+ * Teams are used in several different contexts in Hedgewars, and some of these require
+ * extra information about teams. For example, the weaponset is important
+ * to the engine, but not for ini reading/writing, and with the team statistics it is the
+ * other way around. To keep things simple, the data structure can hold all information
+ * used in any context. On the downside, that means we can't use static typing to ensure
+ * that team information is "complete" for a particular purpose.
+ */
+#ifndef TEAM_H_
+#define TEAM_H_
+
+
+#include "weapon.h"
+#include "../hwconsts.h"
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#define TEAM_DEFAULT_HEALTH 100
+
+/**
+ * Struct representing a single keybinding.
+ */
+typedef struct {
+    char *action;
+    char *binding;
+} flib_binding;
+
+typedef struct {
+    char *name;
+    char *hat;          //!< e.g. hair_yellow; References a .png file in Data/Graphics/Hats
+
+    //! Statistics. They are irrelevant for the engine or server,
+    //! but provided for ini reading/writing by the frontend.
+    int rounds;
+    int kills;
+    int deaths;
+    int suicides;
+
+    int difficulty;     //!< 0 = human, 1 = most difficult bot ... 5 = least difficult bot (somewhat counterintuitive)
+
+    //! Transient setting used in game setup
+    int initialHealth;
+    flib_weaponset *weaponset;
+} flib_hog;
+
+typedef struct {
+    flib_hog hogs[HEDGEHOGS_PER_TEAM];
+    char *name;
+    char *grave;        //!< e.g. "Bone"; References a .png file in Data/Graphics/Graves
+    char *fort;         //!< e.g. "Castle"; References a series of files in Data/Forts
+    char *voicepack;    //!< e.g. "Classic"; References a directory in Data/Sounds/voices
+    char *flag;         //!< e.g. "hedgewars"; References a .png file in Data/Graphics/Flags
+
+    flib_binding *bindings;
+    int bindingCount;
+
+    //! Statistics. They are irrelevant for the engine or server,
+    //! but provided for ini reading/writing by the frontend.
+    int rounds;
+    int wins;
+    int campaignProgress;
+
+    //! Transient settings used in game setup
+    int colorIndex;     //!< Index into a color table
+    int hogsInGame;     //!< The number of hogs that will actually play
+    bool remoteDriven;  //!< true for non-local teams in a network game
+    char *ownerName;    //!< Username of the owner of a team in a network game
+} flib_team;
+
+/**
+ * Free all memory associated with the team
+ */
+void flib_team_destroy(flib_team *team);
+
+/**
+ * Loads a team, returns NULL on error. Destroy this team using flib_team_destroy.
+ * This will not fill in the fields marked as "transient" in the structs above.
+ */
+flib_team *flib_team_from_ini(const char *filename);
+
+/**
+ * Write the team to an ini file. Attempts to retain extra ini settings
+ * that were already present. Note that not all fields of a team struct
+ * are stored in the ini, some are only used intermittently to store
+ * information about a team in the context of a game.
+ *
+ * The flib_team can handle "difficulty" on a per-hog basis, but it
+ * is only written per-team in the team file. The difficulty of the
+ * first hog is used for the entire team when writing.
+ */
+int flib_team_to_ini(const char *filename, const flib_team *team);
+
+/**
+ * Set the same weaponset for every hog in the team
+ */
+int flib_team_set_weaponset(flib_team *team, const flib_weaponset *set);
+
+/**
+ * Set the same initial health for every hog.
+ */
+void flib_team_set_health(flib_team *team, int health);
+
+/**
+ * Create a deep copy of a team. Returns NULL on failure.
+ */
+flib_team *flib_team_copy(const flib_team *team);
+
+#endif /* TEAM_H_ */
--- a/project_files/frontlib/model/teamlist.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/teamlist.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,120 +1,120 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "teamlist.h"
-
-#include "../util/util.h"
-#include "../util/list.h"
-#include "../util/logging.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-flib_teamlist *flib_teamlist_create() {
-	return flib_calloc(1, sizeof(flib_teamlist));
-}
-
-void flib_teamlist_destroy(flib_teamlist *list) {
-	if(list) {
-		for(int i=0; i<list->teamCount; i++) {
-			flib_team_destroy(list->teams[i]);
-		}
-		free(list->teams);
-		free(list);
-	}
-}
-
-GENERATE_STATIC_LIST_INSERT(insertTeam, flib_team*)
-GENERATE_STATIC_LIST_DELETE(deleteTeam, flib_team*)
-
-static int findTeam(const flib_teamlist *list, const char *name) {
-	for(int i=0; i<list->teamCount; i++) {
-		if(!strcmp(name, list->teams[i]->name)) {
-			return i;
-		}
-	}
-	return -1;
-}
-
-int flib_teamlist_insert(flib_teamlist *list, flib_team *team, int pos) {
-	if(!log_badargs_if2(list==NULL, team==NULL)
-			&& !insertTeam(&list->teams, &list->teamCount, team, pos)) {
-		return 0;
-	}
-	return -1;
-}
-
-int flib_teamlist_delete(flib_teamlist *list, const char *name) {
-	int result = -1;
-	if(!log_badargs_if2(list==NULL, name==NULL)) {
-		int itemid = findTeam(list, name);
-		if(itemid>=0) {
-			flib_team *team = list->teams[itemid];
-			if(!deleteTeam(&list->teams, &list->teamCount, itemid)) {
-				flib_team_destroy(team);
-				result = 0;
-			}
-		}
-	}
-	return result;
-}
-
-flib_team *flib_teamlist_find(const flib_teamlist *list, const char *name) {
-	flib_team *result = NULL;
-	if(!log_badargs_if2(list==NULL, name==NULL)) {
-		int itemid = findTeam(list, name);
-		if(itemid>=0) {
-			result = list->teams[itemid];
-		}
-	}
-	return result;
-}
-
-void flib_teamlist_clear(flib_teamlist *list) {
-	if(!log_badargs_if(list==NULL)) {
-		for(int i=0; i<list->teamCount; i++) {
-			flib_team_destroy(list->teams[i]);
-		}
-		free(list->teams);
-		list->teams = NULL;
-		list->teamCount = 0;
-	}
-}
-
-flib_teamlist *flib_teamlist_copy(flib_teamlist *list) {
-	if(!list) {
-		return NULL;
-	}
-	flib_teamlist *result = flib_teamlist_create();
-	if(result) {
-		bool error = false;
-		for(int i=0; !error && i<list->teamCount; i++) {
-			flib_team *teamcopy = flib_team_copy(list->teams[i]);
-			if(!teamcopy || flib_teamlist_insert(result, teamcopy, i)) {
-				flib_team_destroy(teamcopy);
-				error = true;
-			}
-		}
-		if(error) {
-			flib_teamlist_destroy(result);
-			result = NULL;
-		}
-	}
-	return result;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "teamlist.h"
+
+#include "../util/util.h"
+#include "../util/list.h"
+#include "../util/logging.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+flib_teamlist *flib_teamlist_create() {
+    return flib_calloc(1, sizeof(flib_teamlist));
+}
+
+void flib_teamlist_destroy(flib_teamlist *list) {
+    if(list) {
+        for(int i=0; i<list->teamCount; i++) {
+            flib_team_destroy(list->teams[i]);
+        }
+        free(list->teams);
+        free(list);
+    }
+}
+
+GENERATE_STATIC_LIST_INSERT(insertTeam, flib_team*)
+GENERATE_STATIC_LIST_DELETE(deleteTeam, flib_team*)
+
+static int findTeam(const flib_teamlist *list, const char *name) {
+    for(int i=0; i<list->teamCount; i++) {
+        if(!strcmp(name, list->teams[i]->name)) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+int flib_teamlist_insert(flib_teamlist *list, flib_team *team, int pos) {
+    if(!log_badargs_if2(list==NULL, team==NULL)
+            && !insertTeam(&list->teams, &list->teamCount, team, pos)) {
+        return 0;
+    }
+    return -1;
+}
+
+int flib_teamlist_delete(flib_teamlist *list, const char *name) {
+    int result = -1;
+    if(!log_badargs_if2(list==NULL, name==NULL)) {
+        int itemid = findTeam(list, name);
+        if(itemid>=0) {
+            flib_team *team = list->teams[itemid];
+            if(!deleteTeam(&list->teams, &list->teamCount, itemid)) {
+                flib_team_destroy(team);
+                result = 0;
+            }
+        }
+    }
+    return result;
+}
+
+flib_team *flib_teamlist_find(const flib_teamlist *list, const char *name) {
+    flib_team *result = NULL;
+    if(!log_badargs_if2(list==NULL, name==NULL)) {
+        int itemid = findTeam(list, name);
+        if(itemid>=0) {
+            result = list->teams[itemid];
+        }
+    }
+    return result;
+}
+
+void flib_teamlist_clear(flib_teamlist *list) {
+    if(!log_badargs_if(list==NULL)) {
+        for(int i=0; i<list->teamCount; i++) {
+            flib_team_destroy(list->teams[i]);
+        }
+        free(list->teams);
+        list->teams = NULL;
+        list->teamCount = 0;
+    }
+}
+
+flib_teamlist *flib_teamlist_copy(flib_teamlist *list) {
+    if(!list) {
+        return NULL;
+    }
+    flib_teamlist *result = flib_teamlist_create();
+    if(result) {
+        bool error = false;
+        for(int i=0; !error && i<list->teamCount; i++) {
+            flib_team *teamcopy = flib_team_copy(list->teams[i]);
+            if(!teamcopy || flib_teamlist_insert(result, teamcopy, i)) {
+                flib_team_destroy(teamcopy);
+                error = true;
+            }
+        }
+        if(error) {
+            flib_teamlist_destroy(result);
+            result = NULL;
+        }
+    }
+    return result;
+}
--- a/project_files/frontlib/model/teamlist.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/teamlist.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,61 +1,61 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef TEAMLIST_H_
-#define TEAMLIST_H_
-
-#include "team.h"
-
-typedef struct {
-	int teamCount;
-	flib_team **teams;
-} flib_teamlist;
-
-flib_teamlist *flib_teamlist_create();
-
-void flib_teamlist_destroy(flib_teamlist *list);
-
-/**
- * Insert a team into the list. The list takes ownership of the team. Returns 0 on success.
- */
-int flib_teamlist_insert(flib_teamlist *list, flib_team *team, int pos);
-
-/**
- * Delete the team with the name [name] from the list and destroys it.
- * Returns 0 on success.
- */
-int flib_teamlist_delete(flib_teamlist *list, const char *name);
-
-/**
- * Returns the team with the name [name] from the list if it exists, NULL otherwise
- */
-flib_team *flib_teamlist_find(const flib_teamlist *list, const char *name);
-
-/**
- * Removes all items from the list and destroys them.
- */
-void flib_teamlist_clear(flib_teamlist *list);
-
-/**
- * Create a copy of the list and all the teams it contains. Weaponsets are not copied, but
- * kept as references
- */
-flib_teamlist *flib_teamlist_copy(flib_teamlist *list);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef TEAMLIST_H_
+#define TEAMLIST_H_
+
+#include "team.h"
+
+typedef struct {
+    int teamCount;
+    flib_team **teams;
+} flib_teamlist;
+
+flib_teamlist *flib_teamlist_create();
+
+void flib_teamlist_destroy(flib_teamlist *list);
+
+/**
+ * Insert a team into the list. The list takes ownership of the team. Returns 0 on success.
+ */
+int flib_teamlist_insert(flib_teamlist *list, flib_team *team, int pos);
+
+/**
+ * Delete the team with the name [name] from the list and destroys it.
+ * Returns 0 on success.
+ */
+int flib_teamlist_delete(flib_teamlist *list, const char *name);
+
+/**
+ * Returns the team with the name [name] from the list if it exists, NULL otherwise
+ */
+flib_team *flib_teamlist_find(const flib_teamlist *list, const char *name);
+
+/**
+ * Removes all items from the list and destroys them.
+ */
+void flib_teamlist_clear(flib_teamlist *list);
+
+/**
+ * Create a copy of the list and all the teams it contains. Weaponsets are not copied, but
+ * kept as references
+ */
+flib_teamlist *flib_teamlist_copy(flib_teamlist *list);
+
+#endif
--- a/project_files/frontlib/model/weapon.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/weapon.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,234 +1,234 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "weapon.h"
-
-#include "../util/inihelper.h"
-#include "../util/logging.h"
-#include "../util/util.h"
-#include "../util/list.h"
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-static void setField(char field[WEAPONS_COUNT+1], const char *line, int lineLen, bool no9) {
-	if(lineLen>WEAPONS_COUNT) {
-		lineLen = WEAPONS_COUNT;
-	}
-
-	char min = '0';
-	char max = no9 ? '8' : '9';
-	for(int i=0; i<lineLen; i++) {
-		if(line[i] >= min && line[i] <= max) {
-			field[i] = line[i];
-		} else {
-			flib_log_w("Invalid character in weapon config string \"%.*s\", position %i", lineLen, line, i);
-			field[i] = '0';
-		}
-	}
-	for(int i=lineLen; i<WEAPONS_COUNT; i++) {
-		field[i] = '0';
-	}
-	field[WEAPONS_COUNT] = 0;
-}
-
-flib_weaponset *flib_weaponset_create(const char *name) {
-	flib_weaponset *result = NULL;
-	if(!log_badargs_if(name==NULL)) {
-		flib_weaponset *newSet = flib_calloc(1, sizeof(flib_weaponset));
-		if(newSet) {
-			newSet->name = flib_strdupnull(name);
-			if(newSet->name) {
-				setField(newSet->loadout, "", 0, false);
-				setField(newSet->crateprob, "", 0, false);
-				setField(newSet->crateammo, "", 0, false);
-				setField(newSet->delay, "", 0, false);
-				result = newSet;
-				newSet = NULL;
-			}
-		}
-		flib_weaponset_destroy(newSet);
-	}
-	return result;
-}
-
-void flib_weaponset_destroy(flib_weaponset *cfg) {
-	if(cfg) {
-		free(cfg->name);
-		free(cfg);
-	}
-}
-
-flib_weaponset *flib_weaponset_copy(const flib_weaponset *weaponset) {
-	if(!weaponset) {
-		return NULL;
-	}
-
-	flib_weaponset *result = flib_weaponset_create(weaponset->name);
-	if(result) {
-		memcpy(result->loadout, weaponset->loadout, WEAPONS_COUNT+1);
-		memcpy(result->crateprob, weaponset->crateprob, WEAPONS_COUNT+1);
-		memcpy(result->delay, weaponset->delay, WEAPONS_COUNT+1);
-		memcpy(result->crateammo, weaponset->crateammo, WEAPONS_COUNT+1);
-	}
-
-	return result;
-}
-
-void flib_weaponsetlist_destroy(flib_weaponsetlist *list) {
-	if(list) {
-		for(int i=0; i<list->weaponsetCount; i++) {
-			flib_weaponset_destroy(list->weaponsets[i]);
-		}
-		free(list->weaponsets);
-		free(list);
-	}
-}
-
-flib_weaponset *flib_weaponset_from_ammostring(const char *name, const char *ammostring) {
-	flib_weaponset *result = NULL;
-	if(!log_badargs_if2(name==NULL, ammostring==NULL)) {
-		result = flib_weaponset_create(name);
-		if(result) {
-			int fieldlen = strlen(ammostring)/4;
-			setField(result->loadout, ammostring, fieldlen, false);
-			setField(result->crateprob, ammostring + fieldlen, fieldlen, true);
-			setField(result->delay, ammostring + 2*fieldlen, fieldlen, true);
-			setField(result->crateammo, ammostring + 3*fieldlen, fieldlen, true);
-		}
-	}
-	return result;
-}
-
-static int fillWeaponsetFromIni(flib_weaponsetlist *list, flib_ini *ini, int index) {
-	int result = -1;
-	char *keyname = flib_ini_get_keyname(ini, index);
-	char *decodedKeyname = flib_urldecode(keyname);
-	char *ammostring = NULL;
-	if(decodedKeyname && !flib_ini_get_str(ini, &ammostring, keyname)) {
-		flib_weaponset *set = flib_weaponset_from_ammostring(decodedKeyname, ammostring);
-		if(set) {
-			result = flib_weaponsetlist_insert(list, set, list->weaponsetCount);
-			if(result) {
-				flib_weaponset_destroy(set);
-			}
-		}
-	}
-	free(ammostring);
-	free(decodedKeyname);
-	free(keyname);
-	return result;
-}
-
-static int fillWeaponsetsFromIni(flib_weaponsetlist *list, flib_ini *ini) {
-	bool error = false;
-	int weaponsets = flib_ini_get_keycount(ini);
-
-	for(int i=0; i<weaponsets && !error; i++) {
-		error |= fillWeaponsetFromIni(list, ini, i);
-	}
-	return error;
-}
-
-flib_weaponsetlist *flib_weaponsetlist_from_ini(const char *filename) {
-	flib_weaponsetlist *result = NULL;
-	if(!log_badargs_if(filename==NULL)) {
-		flib_ini *ini = flib_ini_load(filename);
-		if(!ini) {
-			flib_log_e("Missing file %s.", filename);
-		} else if(flib_ini_enter_section(ini, "General")) {
-			flib_log_e("Missing section \"General\" in file %s.", filename);
-		} else {
-			flib_weaponsetlist *tmpList = flib_weaponsetlist_create();
-			if(tmpList && !fillWeaponsetsFromIni(tmpList, ini)) {
-				result = tmpList;
-				tmpList = NULL;
-			}
-			flib_weaponsetlist_destroy(tmpList);
-		}
-		flib_ini_destroy(ini);
-	}
-	return result;
-}
-
-static bool needsEscape(char c) {
-	return !((c>='0' && c<='9') || (c>='a' && c <='z'));
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "weapon.h"
+
+#include "../util/inihelper.h"
+#include "../util/logging.h"
+#include "../util/util.h"
+#include "../util/list.h"
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+static void setField(char field[WEAPONS_COUNT+1], const char *line, int lineLen, bool no9) {
+    if(lineLen>WEAPONS_COUNT) {
+        lineLen = WEAPONS_COUNT;
+    }
+
+    char min = '0';
+    char max = no9 ? '8' : '9';
+    for(int i=0; i<lineLen; i++) {
+        if(line[i] >= min && line[i] <= max) {
+            field[i] = line[i];
+        } else {
+            flib_log_w("Invalid character in weapon config string \"%.*s\", position %i", lineLen, line, i);
+            field[i] = '0';
+        }
+    }
+    for(int i=lineLen; i<WEAPONS_COUNT; i++) {
+        field[i] = '0';
+    }
+    field[WEAPONS_COUNT] = 0;
+}
+
+flib_weaponset *flib_weaponset_create(const char *name) {
+    flib_weaponset *result = NULL;
+    if(!log_badargs_if(name==NULL)) {
+        flib_weaponset *newSet = flib_calloc(1, sizeof(flib_weaponset));
+        if(newSet) {
+            newSet->name = flib_strdupnull(name);
+            if(newSet->name) {
+                setField(newSet->loadout, "", 0, false);
+                setField(newSet->crateprob, "", 0, false);
+                setField(newSet->crateammo, "", 0, false);
+                setField(newSet->delay, "", 0, false);
+                result = newSet;
+                newSet = NULL;
+            }
+        }
+        flib_weaponset_destroy(newSet);
+    }
+    return result;
+}
+
+void flib_weaponset_destroy(flib_weaponset *cfg) {
+    if(cfg) {
+        free(cfg->name);
+        free(cfg);
+    }
+}
+
+flib_weaponset *flib_weaponset_copy(const flib_weaponset *weaponset) {
+    if(!weaponset) {
+        return NULL;
+    }
+
+    flib_weaponset *result = flib_weaponset_create(weaponset->name);
+    if(result) {
+        memcpy(result->loadout, weaponset->loadout, WEAPONS_COUNT+1);
+        memcpy(result->crateprob, weaponset->crateprob, WEAPONS_COUNT+1);
+        memcpy(result->delay, weaponset->delay, WEAPONS_COUNT+1);
+        memcpy(result->crateammo, weaponset->crateammo, WEAPONS_COUNT+1);
+    }
+
+    return result;
+}
+
+void flib_weaponsetlist_destroy(flib_weaponsetlist *list) {
+    if(list) {
+        for(int i=0; i<list->weaponsetCount; i++) {
+            flib_weaponset_destroy(list->weaponsets[i]);
+        }
+        free(list->weaponsets);
+        free(list);
+    }
+}
 
-static int writeWeaponsetToIni(flib_ini *ini, flib_weaponset *set) {
-	int result = -1;
-	char weaponstring[WEAPONS_COUNT*4+1];
-	strcpy(weaponstring, set->loadout);
-	strcat(weaponstring, set->crateprob);
-	strcat(weaponstring, set->delay);
-	strcat(weaponstring, set->crateammo);
-
-	char *escapedname = flib_urlencode_pred(set->name, needsEscape);
-	if(escapedname) {
-		result = flib_ini_set_str(ini, escapedname, weaponstring);
-	}
-	free(escapedname);
-	return result;
-}
-
-int flib_weaponsetlist_to_ini(const char *filename, const flib_weaponsetlist *list) {
-	int result = -1;
-	if(!log_badargs_if2(filename==NULL, list==NULL)) {
-		flib_ini *ini = flib_ini_create(NULL);
-		if(ini && !flib_ini_create_section(ini, "General")) {
-			bool error = false;
-			for(int i=0; i<list->weaponsetCount && !error; i++) {
-				error |= writeWeaponsetToIni(ini, list->weaponsets[i]);
-			}
-
-			if(!error) {
-				result = flib_ini_save(ini, filename);
-			}
-		}
-		flib_ini_destroy(ini);
-	}
-	return result;
-}
-
-flib_weaponsetlist *flib_weaponsetlist_create() {
-	return flib_calloc(1, sizeof(flib_weaponsetlist));
-}
-
-GENERATE_STATIC_LIST_INSERT(insertWeaponset, flib_weaponset*)
-GENERATE_STATIC_LIST_DELETE(deleteWeaponset, flib_weaponset*)
-
-int flib_weaponsetlist_insert(flib_weaponsetlist *list, flib_weaponset *set, int pos) {
-	if(!log_badargs_if2(list==NULL, set==NULL)
-			&& !insertWeaponset(&list->weaponsets, &list->weaponsetCount, set, pos)) {
-		return 0;
-	}
-	return -1;
-}
-
-int flib_weaponsetlist_delete(flib_weaponsetlist *list, int pos) {
-	if(!log_badargs_if(list==NULL)) {
-		flib_weaponset *elem = list->weaponsets[pos];
-		if(!deleteWeaponset(&list->weaponsets, &list->weaponsetCount, pos)) {
-			flib_weaponset_destroy(elem);
-			return 0;
-		}
-	}
-	return -1;
-}
+flib_weaponset *flib_weaponset_from_ammostring(const char *name, const char *ammostring) {
+    flib_weaponset *result = NULL;
+    if(!log_badargs_if2(name==NULL, ammostring==NULL)) {
+        result = flib_weaponset_create(name);
+        if(result) {
+            int fieldlen = strlen(ammostring)/4;
+            setField(result->loadout, ammostring, fieldlen, false);
+            setField(result->crateprob, ammostring + fieldlen, fieldlen, true);
+            setField(result->delay, ammostring + 2*fieldlen, fieldlen, true);
+            setField(result->crateammo, ammostring + 3*fieldlen, fieldlen, true);
+        }
+    }
+    return result;
+}
+
+static int fillWeaponsetFromIni(flib_weaponsetlist *list, flib_ini *ini, int index) {
+    int result = -1;
+    char *keyname = flib_ini_get_keyname(ini, index);
+    char *decodedKeyname = flib_urldecode(keyname);
+    char *ammostring = NULL;
+    if(decodedKeyname && !flib_ini_get_str(ini, &ammostring, keyname)) {
+        flib_weaponset *set = flib_weaponset_from_ammostring(decodedKeyname, ammostring);
+        if(set) {
+            result = flib_weaponsetlist_insert(list, set, list->weaponsetCount);
+            if(result) {
+                flib_weaponset_destroy(set);
+            }
+        }
+    }
+    free(ammostring);
+    free(decodedKeyname);
+    free(keyname);
+    return result;
+}
+
+static int fillWeaponsetsFromIni(flib_weaponsetlist *list, flib_ini *ini) {
+    bool error = false;
+    int weaponsets = flib_ini_get_keycount(ini);
+
+    for(int i=0; i<weaponsets && !error; i++) {
+        error |= fillWeaponsetFromIni(list, ini, i);
+    }
+    return error;
+}
+
+flib_weaponsetlist *flib_weaponsetlist_from_ini(const char *filename) {
+    flib_weaponsetlist *result = NULL;
+    if(!log_badargs_if(filename==NULL)) {
+        flib_ini *ini = flib_ini_load(filename);
+        if(!ini) {
+            flib_log_e("Missing file %s.", filename);
+        } else if(flib_ini_enter_section(ini, "General")) {
+            flib_log_e("Missing section \"General\" in file %s.", filename);
+        } else {
+            flib_weaponsetlist *tmpList = flib_weaponsetlist_create();
+            if(tmpList && !fillWeaponsetsFromIni(tmpList, ini)) {
+                result = tmpList;
+                tmpList = NULL;
+            }
+            flib_weaponsetlist_destroy(tmpList);
+        }
+        flib_ini_destroy(ini);
+    }
+    return result;
+}
+
+static bool needsEscape(char c) {
+    return !((c>='0' && c<='9') || (c>='a' && c <='z'));
+}
+
+static int writeWeaponsetToIni(flib_ini *ini, flib_weaponset *set) {
+    int result = -1;
+    char weaponstring[WEAPONS_COUNT*4+1];
+    strcpy(weaponstring, set->loadout);
+    strcat(weaponstring, set->crateprob);
+    strcat(weaponstring, set->delay);
+    strcat(weaponstring, set->crateammo);
+
+    char *escapedname = flib_urlencode_pred(set->name, needsEscape);
+    if(escapedname) {
+        result = flib_ini_set_str(ini, escapedname, weaponstring);
+    }
+    free(escapedname);
+    return result;
+}
+
+int flib_weaponsetlist_to_ini(const char *filename, const flib_weaponsetlist *list) {
+    int result = -1;
+    if(!log_badargs_if2(filename==NULL, list==NULL)) {
+        flib_ini *ini = flib_ini_create(NULL);
+        if(ini && !flib_ini_create_section(ini, "General")) {
+            bool error = false;
+            for(int i=0; i<list->weaponsetCount && !error; i++) {
+                error |= writeWeaponsetToIni(ini, list->weaponsets[i]);
+            }
+
+            if(!error) {
+                result = flib_ini_save(ini, filename);
+            }
+        }
+        flib_ini_destroy(ini);
+    }
+    return result;
+}
+
+flib_weaponsetlist *flib_weaponsetlist_create() {
+    return flib_calloc(1, sizeof(flib_weaponsetlist));
+}
+
+GENERATE_STATIC_LIST_INSERT(insertWeaponset, flib_weaponset*)
+GENERATE_STATIC_LIST_DELETE(deleteWeaponset, flib_weaponset*)
+
+int flib_weaponsetlist_insert(flib_weaponsetlist *list, flib_weaponset *set, int pos) {
+    if(!log_badargs_if2(list==NULL, set==NULL)
+            && !insertWeaponset(&list->weaponsets, &list->weaponsetCount, set, pos)) {
+        return 0;
+    }
+    return -1;
+}
+
+int flib_weaponsetlist_delete(flib_weaponsetlist *list, int pos) {
+    if(!log_badargs_if(list==NULL)) {
+        flib_weaponset *elem = list->weaponsets[pos];
+        if(!deleteWeaponset(&list->weaponsets, &list->weaponsetCount, pos)) {
+            flib_weaponset_destroy(elem);
+            return 0;
+        }
+    }
+    return -1;
+}
--- a/project_files/frontlib/model/weapon.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/model/weapon.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,104 +1,104 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef MODEL_WEAPON_H_
-#define MODEL_WEAPON_H_
-
-#include "../hwconsts.h"
-
-/**
- * These values are all ASCII characters in the range '0'..'9'
- * The fields are zero-terminated so they can easily be used as strings.
- *
- * For loadout, 9 means inifinite ammo.
- * For the other setting, 9 is invalid.
- */
-typedef struct {
-	char loadout[WEAPONS_COUNT+1];
-	char crateprob[WEAPONS_COUNT+1];
-	char crateammo[WEAPONS_COUNT+1];
-	char delay[WEAPONS_COUNT+1];
-	char *name;
-} flib_weaponset;
-
-typedef struct {
-	int weaponsetCount;
-	flib_weaponset **weaponsets;
-} flib_weaponsetlist;
-
-/**
- * Returns a new weapon set, or NULL on error.
- * name must not be NULL.
- *
- * The new weapon set is pre-filled with default
- * settings (see hwconsts.h)
- */
-flib_weaponset *flib_weaponset_create(const char *name);
-
-/**
- * Free the memory used by this weaponset
- */
-void flib_weaponset_destroy(flib_weaponset *weaponset);
-
-flib_weaponset *flib_weaponset_copy(const flib_weaponset *weaponset);
-
-/**
- * Create a weaponset from an ammostring. This format is used both in the ini files
- * and in the net protocol.
- */
-flib_weaponset *flib_weaponset_from_ammostring(const char *name, const char *ammostring);
-
-/**
- * Load a list of weaponsets from the ini file.
- * Returns NULL on error.
- */
-flib_weaponsetlist *flib_weaponsetlist_from_ini(const char *filename);
-
-/**
- * Store the list of weaponsets to an ini file.
- * Returns NULL on error.
- */
-int flib_weaponsetlist_to_ini(const char *filename, const flib_weaponsetlist *weaponsets);
-
-/**
- * Create an empty weaponset list. Returns NULL on error.
- */
-flib_weaponsetlist *flib_weaponsetlist_create();
-
-/**
- * Release all memory associated with the weaponsetlist and release all contained weaponsets
- */
-void flib_weaponsetlist_destroy(flib_weaponsetlist *list);
-
-/**
- * Insert a new weaponset into the list at position pos, moving all higher weaponsets to make place.
- * pos must be at least 0 (insert at the start) and at most list->weaponsetCount (insert at the end).
- * Ownership of the weaponset is transferred to the list.
- * Returns 0 on success.
- */
-int flib_weaponsetlist_insert(flib_weaponsetlist *list, flib_weaponset *weaponset, int pos);
-
-/**
- * Delete a weaponset from the list at position pos, moving down all higher weaponsets.
- * The weaponset is destroyed.
- * Returns 0 on success.
- */
-int flib_weaponsetlist_delete(flib_weaponsetlist *list, int pos);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef MODEL_WEAPON_H_
+#define MODEL_WEAPON_H_
+
+#include "../hwconsts.h"
+
+/**
+ * These values are all ASCII characters in the range '0'..'9'
+ * The fields are zero-terminated so they can easily be used as strings.
+ *
+ * For loadout, 9 means inifinite ammo.
+ * For the other setting, 9 is invalid.
+ */
+typedef struct {
+    char loadout[WEAPONS_COUNT+1];
+    char crateprob[WEAPONS_COUNT+1];
+    char crateammo[WEAPONS_COUNT+1];
+    char delay[WEAPONS_COUNT+1];
+    char *name;
+} flib_weaponset;
+
+typedef struct {
+    int weaponsetCount;
+    flib_weaponset **weaponsets;
+} flib_weaponsetlist;
+
+/**
+ * Returns a new weapon set, or NULL on error.
+ * name must not be NULL.
+ *
+ * The new weapon set is pre-filled with default
+ * settings (see hwconsts.h)
+ */
+flib_weaponset *flib_weaponset_create(const char *name);
+
+/**
+ * Free the memory used by this weaponset
+ */
+void flib_weaponset_destroy(flib_weaponset *weaponset);
+
+flib_weaponset *flib_weaponset_copy(const flib_weaponset *weaponset);
+
+/**
+ * Create a weaponset from an ammostring. This format is used both in the ini files
+ * and in the net protocol.
+ */
+flib_weaponset *flib_weaponset_from_ammostring(const char *name, const char *ammostring);
+
+/**
+ * Load a list of weaponsets from the ini file.
+ * Returns NULL on error.
+ */
+flib_weaponsetlist *flib_weaponsetlist_from_ini(const char *filename);
+
+/**
+ * Store the list of weaponsets to an ini file.
+ * Returns NULL on error.
+ */
+int flib_weaponsetlist_to_ini(const char *filename, const flib_weaponsetlist *weaponsets);
+
+/**
+ * Create an empty weaponset list. Returns NULL on error.
+ */
+flib_weaponsetlist *flib_weaponsetlist_create();
+
+/**
+ * Release all memory associated with the weaponsetlist and release all contained weaponsets
+ */
+void flib_weaponsetlist_destroy(flib_weaponsetlist *list);
+
+/**
+ * Insert a new weaponset into the list at position pos, moving all higher weaponsets to make place.
+ * pos must be at least 0 (insert at the start) and at most list->weaponsetCount (insert at the end).
+ * Ownership of the weaponset is transferred to the list.
+ * Returns 0 on success.
+ */
+int flib_weaponsetlist_insert(flib_weaponsetlist *list, flib_weaponset *weaponset, int pos);
+
+/**
+ * Delete a weaponset from the list at position pos, moving down all higher weaponsets.
+ * The weaponset is destroyed.
+ * Returns 0 on success.
+ */
+int flib_weaponsetlist_delete(flib_weaponsetlist *list, int pos);
+
+#endif
--- a/project_files/frontlib/net/netbase.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netbase.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,259 +1,259 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "netbase.h"
-#include "../util/buffer.h"
-#include "../util/logging.h"
-#include "../util/util.h"
-#include "../socket.h"
-
-#include <string.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#define NET_READBUFFER_LIMIT (1024*1024)
-
-struct _flib_netbase {
-	flib_vector *readBuffer;
-	flib_tcpsocket *sock;
-};
-
-flib_netbase *flib_netbase_create(const char *server, uint16_t port) {
-	if(log_badargs_if2(server==NULL, port==0)) {
-		return NULL;
-	}
-
-	flib_netbase *result = NULL;
-	flib_netbase *newNet =  flib_calloc(1, sizeof(flib_netbase));
-
-	if(newNet) {
-		newNet->readBuffer = flib_vector_create();
-		newNet->sock = flib_socket_connect(server, port);
-		if(newNet->readBuffer && newNet->sock) {
-			flib_log_i("Connected to server %s:%u", server, (unsigned)port);
-			result = newNet;
-			newNet = NULL;
-		}
-	}
-	flib_netbase_destroy(newNet);
-
-	return result;
-}
-
-void flib_netbase_destroy(flib_netbase *net) {
-	if(net) {
-		flib_socket_close(net->sock);
-		flib_vector_destroy(net->readBuffer);
-		free(net);
-	}
-}
-
-bool flib_netbase_connected(flib_netbase *net) {
-	if(!log_badargs_if(net==NULL) && net->sock) {
-		return true;
-	}
-	return false;
-}
-
-/**
- * Parses and returns a message, and removes it from the vector.
- */
-static flib_netmsg *parseMessage(flib_vector *vec) {
-	const uint8_t *partStart = flib_vector_data(vec);
-	const uint8_t *end = partStart+flib_vector_size(vec);
-	flib_netmsg *result = flib_netmsg_create();
-	if(!result) {
-		return NULL;
-	}
-
-	while(1) {
-		const uint8_t *partEnd = memchr(partStart, '\n', end-partStart);
-		if(!partEnd) {
-			// message incomplete
-			flib_netmsg_destroy(result);
-			return NULL;
-		} else if(partEnd-partStart == 0) {
-			// Zero-length part, message end marker. Remove the message from the vector.
-			uint8_t *vectorStart = flib_vector_data(vec);
-			size_t msgLen = partEnd+1-vectorStart;
-			memmove(vectorStart, partEnd+1, flib_vector_size(vec)-msgLen);
-			flib_vector_resize(vec, flib_vector_size(vec)-msgLen);
-			return result;
-		} else {
-			if(flib_netmsg_append_part(result, partStart, partEnd-partStart)) {
-				flib_netmsg_destroy(result);
-				return NULL;
-			}
-			partStart = partEnd+1; // Skip the '\n'
-		}
-	}
-	return NULL; // Never reached
-}
-
-/**
- * Receive some bytes and add them to the buffer.
- * Returns the number of bytes received.
- * Automatically closes the socket if an error occurs
- * and sets sock=NULL.
- */
-static int receiveToBuffer(flib_netbase *net) {
-	uint8_t buffer[256];
-	if(!net->sock) {
-		return 0;
-	} else if(flib_vector_size(net->readBuffer) > NET_READBUFFER_LIMIT) {
-		flib_log_e("Net connection closed: Net message too big");
-		flib_socket_close(net->sock);
-		net->sock = NULL;
-		return 0;
-	} else {
-		int size = flib_socket_nbrecv(net->sock, buffer, sizeof(buffer));
-		if(size>=0 && !flib_vector_append(net->readBuffer, buffer, size)) {
-			return size;
-		} else {
-			flib_socket_close(net->sock);
-			net->sock = NULL;
-			return 0;
-		}
-	}
-}
-
-flib_netmsg *flib_netbase_recv_message(flib_netbase *net) {
-	if(log_badargs_if(net==NULL)) {
-		return NULL;
-	}
-
-	flib_netmsg *msg;
-	while(!(msg=parseMessage(net->readBuffer))
-			&& receiveToBuffer(net)) {}
-
-	if(msg) {
-		return msg;
-	} else if(!net->sock && flib_vector_size(net->readBuffer)>0) {
-		// Connection is down and we didn't get a complete message, just flush the rest.
-		flib_vector_resize(net->readBuffer, 0);
-	}
-	return NULL;
-}
-
-static void logSentMsg(const uint8_t *data, size_t len) {
-	if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) {
-		flib_log_d("[NET OUT][%03u]%*.*s",(unsigned)len, (unsigned)len, (unsigned)len, data);
-	}
-}
-
-int flib_netbase_send_raw(flib_netbase *net, const void *data, size_t len) {
-	if(log_badargs_if2(net==NULL, data==NULL && len>0)) {
-		return -1;
-	}
-	if(!net->sock) {
-		flib_log_w("flib_netbase_send_raw: Not connected.");
-		return -1;
-	}
-
-	if(flib_socket_send(net->sock, data, len) == len) {
-		logSentMsg(data, len);
-		return 0;
-	} else {
-		flib_log_w("Failed or incomplete write: net connection lost.");
-		flib_socket_close(net->sock);
-		net->sock = NULL;
-		return -1;
-	}
-}
-
-int flib_netbase_send_message(flib_netbase *net, const flib_netmsg *msg) {
-	if(log_badargs_if2(net==NULL, msg==NULL)) {
-		return -1;
-	}
-
-	size_t totalSize = 0;
-	for(int i=0; i<msg->partCount; i++) {
-		totalSize += strlen(msg->parts[i]) + 1;
-	}
-	totalSize++; // Last part ends in two '\n' instead of one
-
-	uint8_t *buffer = flib_malloc(totalSize);
-	if(!buffer) {
-		return -1;
-	}
-	size_t pos = 0;
-	for(int i=0; i<msg->partCount; i++) {
-		size_t partsize = strlen(msg->parts[i]);
-		memcpy(buffer+pos, msg->parts[i], partsize);
-		pos += partsize;
-		buffer[pos++] = '\n';
-	}
-	buffer[pos++] = '\n';
-	return flib_netbase_send_raw(net, buffer, pos);
-}
-
-int flib_netbase_sendf(flib_netbase *net, const char *format, ...) {
-	int result = -1;
-	if(!log_badargs_if2(net==NULL, format==NULL)) {
-		va_list argp;
-		va_start(argp, format);
-		char *buffer = flib_vasprintf(format, argp);
-		if(buffer) {
-			result = flib_netbase_send_raw(net, buffer, strlen(buffer));
-		}
-		free(buffer);
-		va_end(argp);
-	}
-	return result;
-}
-
-flib_netmsg *flib_netmsg_create() {
-	flib_netmsg *result = flib_calloc(1, sizeof(flib_netmsg));
-	if(result) {
-		result->partCount = 0;
-		result->parts = NULL;
-		return result;
-	} else {
-		return NULL;
-	}
-}
-
-void flib_netmsg_destroy(flib_netmsg *msg) {
-	if(msg) {
-		for(int i=0; i<msg->partCount; i++) {
-			free(msg->parts[i]);
-		}
-		free(msg->parts);
-		free(msg);
-	}
-}
-
-int flib_netmsg_append_part(flib_netmsg *msg, const void *part, size_t partlen) {
-	int result = -1;
-	if(!log_badargs_if2(msg==NULL, part==NULL && partlen>0)) {
-		char **newParts = realloc(msg->parts, (msg->partCount+1)*sizeof(*msg->parts));
-		if(newParts) {
-			msg->parts = newParts;
-			msg->parts[msg->partCount] = flib_malloc(partlen+1);
-			if(msg->parts[msg->partCount]) {
-				memcpy(msg->parts[msg->partCount], part, partlen);
-				msg->parts[msg->partCount][partlen] = 0;
-				msg->partCount++;
-				result = 0;
-			}
-		}
-	}
-	return result;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "netbase.h"
+#include "../util/buffer.h"
+#include "../util/logging.h"
+#include "../util/util.h"
+#include "../socket.h"
+
+#include <string.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NET_READBUFFER_LIMIT (1024*1024)
+
+struct _flib_netbase {
+    flib_vector *readBuffer;
+    flib_tcpsocket *sock;
+};
+
+flib_netbase *flib_netbase_create(const char *server, uint16_t port) {
+    if(log_badargs_if2(server==NULL, port==0)) {
+        return NULL;
+    }
+
+    flib_netbase *result = NULL;
+    flib_netbase *newNet =  flib_calloc(1, sizeof(flib_netbase));
+
+    if(newNet) {
+        newNet->readBuffer = flib_vector_create();
+        newNet->sock = flib_socket_connect(server, port);
+        if(newNet->readBuffer && newNet->sock) {
+            flib_log_i("Connected to server %s:%u", server, (unsigned)port);
+            result = newNet;
+            newNet = NULL;
+        }
+    }
+    flib_netbase_destroy(newNet);
+
+    return result;
+}
+
+void flib_netbase_destroy(flib_netbase *net) {
+    if(net) {
+        flib_socket_close(net->sock);
+        flib_vector_destroy(net->readBuffer);
+        free(net);
+    }
+}
+
+bool flib_netbase_connected(flib_netbase *net) {
+    if(!log_badargs_if(net==NULL) && net->sock) {
+        return true;
+    }
+    return false;
+}
+
+/**
+ * Parses and returns a message, and removes it from the vector.
+ */
+static flib_netmsg *parseMessage(flib_vector *vec) {
+    const uint8_t *partStart = flib_vector_data(vec);
+    const uint8_t *end = partStart+flib_vector_size(vec);
+    flib_netmsg *result = flib_netmsg_create();
+    if(!result) {
+        return NULL;
+    }
+
+    while(1) {
+        const uint8_t *partEnd = memchr(partStart, '\n', end-partStart);
+        if(!partEnd) {
+            // message incomplete
+            flib_netmsg_destroy(result);
+            return NULL;
+        } else if(partEnd-partStart == 0) {
+            // Zero-length part, message end marker. Remove the message from the vector.
+            uint8_t *vectorStart = flib_vector_data(vec);
+            size_t msgLen = partEnd+1-vectorStart;
+            memmove(vectorStart, partEnd+1, flib_vector_size(vec)-msgLen);
+            flib_vector_resize(vec, flib_vector_size(vec)-msgLen);
+            return result;
+        } else {
+            if(flib_netmsg_append_part(result, partStart, partEnd-partStart)) {
+                flib_netmsg_destroy(result);
+                return NULL;
+            }
+            partStart = partEnd+1; // Skip the '\n'
+        }
+    }
+    return NULL; // Never reached
+}
+
+/**
+ * Receive some bytes and add them to the buffer.
+ * Returns the number of bytes received.
+ * Automatically closes the socket if an error occurs
+ * and sets sock=NULL.
+ */
+static int receiveToBuffer(flib_netbase *net) {
+    uint8_t buffer[256];
+    if(!net->sock) {
+        return 0;
+    } else if(flib_vector_size(net->readBuffer) > NET_READBUFFER_LIMIT) {
+        flib_log_e("Net connection closed: Net message too big");
+        flib_socket_close(net->sock);
+        net->sock = NULL;
+        return 0;
+    } else {
+        int size = flib_socket_nbrecv(net->sock, buffer, sizeof(buffer));
+        if(size>=0 && !flib_vector_append(net->readBuffer, buffer, size)) {
+            return size;
+        } else {
+            flib_socket_close(net->sock);
+            net->sock = NULL;
+            return 0;
+        }
+    }
+}
+
+flib_netmsg *flib_netbase_recv_message(flib_netbase *net) {
+    if(log_badargs_if(net==NULL)) {
+        return NULL;
+    }
+
+    flib_netmsg *msg;
+    while(!(msg=parseMessage(net->readBuffer))
+            && receiveToBuffer(net)) {}
+
+    if(msg) {
+        return msg;
+    } else if(!net->sock && flib_vector_size(net->readBuffer)>0) {
+        // Connection is down and we didn't get a complete message, just flush the rest.
+        flib_vector_resize(net->readBuffer, 0);
+    }
+    return NULL;
+}
+
+static void logSentMsg(const uint8_t *data, size_t len) {
+    if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) {
+        flib_log_d("[NET OUT][%03u]%*.*s",(unsigned)len, (unsigned)len, (unsigned)len, data);
+    }
+}
+
+int flib_netbase_send_raw(flib_netbase *net, const void *data, size_t len) {
+    if(log_badargs_if2(net==NULL, data==NULL && len>0)) {
+        return -1;
+    }
+    if(!net->sock) {
+        flib_log_w("flib_netbase_send_raw: Not connected.");
+        return -1;
+    }
+
+    if(flib_socket_send(net->sock, data, len) == len) {
+        logSentMsg(data, len);
+        return 0;
+    } else {
+        flib_log_w("Failed or incomplete write: net connection lost.");
+        flib_socket_close(net->sock);
+        net->sock = NULL;
+        return -1;
+    }
+}
+
+int flib_netbase_send_message(flib_netbase *net, const flib_netmsg *msg) {
+    if(log_badargs_if2(net==NULL, msg==NULL)) {
+        return -1;
+    }
+
+    size_t totalSize = 0;
+    for(int i=0; i<msg->partCount; i++) {
+        totalSize += strlen(msg->parts[i]) + 1;
+    }
+    totalSize++; // Last part ends in two '\n' instead of one
+
+    uint8_t *buffer = flib_malloc(totalSize);
+    if(!buffer) {
+        return -1;
+    }
+    size_t pos = 0;
+    for(int i=0; i<msg->partCount; i++) {
+        size_t partsize = strlen(msg->parts[i]);
+        memcpy(buffer+pos, msg->parts[i], partsize);
+        pos += partsize;
+        buffer[pos++] = '\n';
+    }
+    buffer[pos++] = '\n';
+    return flib_netbase_send_raw(net, buffer, pos);
+}
+
+int flib_netbase_sendf(flib_netbase *net, const char *format, ...) {
+    int result = -1;
+    if(!log_badargs_if2(net==NULL, format==NULL)) {
+        va_list argp;
+        va_start(argp, format);
+        char *buffer = flib_vasprintf(format, argp);
+        if(buffer) {
+            result = flib_netbase_send_raw(net, buffer, strlen(buffer));
+        }
+        free(buffer);
+        va_end(argp);
+    }
+    return result;
+}
+
+flib_netmsg *flib_netmsg_create() {
+    flib_netmsg *result = flib_calloc(1, sizeof(flib_netmsg));
+    if(result) {
+        result->partCount = 0;
+        result->parts = NULL;
+        return result;
+    } else {
+        return NULL;
+    }
+}
+
+void flib_netmsg_destroy(flib_netmsg *msg) {
+    if(msg) {
+        for(int i=0; i<msg->partCount; i++) {
+            free(msg->parts[i]);
+        }
+        free(msg->parts);
+        free(msg);
+    }
+}
+
+int flib_netmsg_append_part(flib_netmsg *msg, const void *part, size_t partlen) {
+    int result = -1;
+    if(!log_badargs_if2(msg==NULL, part==NULL && partlen>0)) {
+        char **newParts = realloc(msg->parts, (msg->partCount+1)*sizeof(*msg->parts));
+        if(newParts) {
+            msg->parts = newParts;
+            msg->parts[msg->partCount] = flib_malloc(partlen+1);
+            if(msg->parts[msg->partCount]) {
+                memcpy(msg->parts[msg->partCount], part, partlen);
+                msg->parts[msg->partCount][partlen] = 0;
+                msg->partCount++;
+                result = 0;
+            }
+        }
+    }
+    return result;
+}
--- a/project_files/frontlib/net/netbase.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netbase.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,91 +1,91 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/*
- * Low-level protocol support for the network connection
- */
-
-#ifndef NETBASE_H_
-#define NETBASE_H_
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-struct _flib_netbase;
-typedef struct _flib_netbase flib_netbase;
-
-typedef struct {
-	int partCount;
-	char **parts;
-} flib_netmsg;
-
-/**
- * Start a connection to the specified Hedgewars server.
- *
- * Returns NULL on error. Destroy the created object with flib_netconn_destroy.
- */
-flib_netbase *flib_netbase_create(const char *server, uint16_t port);
-
-/**
- * Free resources and close sockets.
- */
-void flib_netbase_destroy(flib_netbase *net);
-
-/**
- * Determine the current connection state. Starts out true, and turns to
- * false when we are disconnected from the server.
- */
-bool flib_netbase_connected(flib_netbase *net);
-
-/**
- * Receive a new message and return it as a flib_netmsg. The netmsg has to be
- * destroyed with flib_netmsg_destroy after use.
- * Returns NULL if no message is available.
- *
- * Note: When a connection is closed, you probably want to call this function until
- * no further message is returned, to ensure you see all messages that were sent
- * before the connection closed.
- */
-flib_netmsg *flib_netbase_recv_message(flib_netbase *net);
-
-int flib_netbase_send_raw(flib_netbase *net, const void *data, size_t len);
-
-/**
- * Write a single message to the server. This call blocks until the
- * message is completely written or the connection is closed or an error occurs.
- *
- * Returns a negative value on failure.
- */
-int flib_netbase_send_message(flib_netbase *net, const flib_netmsg *msg);
-
-/**
- * Send a message printf-style.
- *
- * flib_netbase_sendf(net, "%s\n\n", "TOGGLE_READY");
- * flib_netbase_sendf(net, "%s\n%s\n%i\n\n", "CFG", "MAPGEN", MAPGEN_MAZE);
- */
-int flib_netbase_sendf(flib_netbase *net, const char *format, ...);
-
-flib_netmsg *flib_netmsg_create();
-void flib_netmsg_destroy(flib_netmsg *msg);
-int flib_netmsg_append_part(flib_netmsg *msg, const void *param, size_t len);
-
-#endif /* NETBASE_H_ */
-
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/*
+ * Low-level protocol support for the network connection
+ */
+
+#ifndef NETBASE_H_
+#define NETBASE_H_
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+struct _flib_netbase;
+typedef struct _flib_netbase flib_netbase;
+
+typedef struct {
+    int partCount;
+    char **parts;
+} flib_netmsg;
+
+/**
+ * Start a connection to the specified Hedgewars server.
+ *
+ * Returns NULL on error. Destroy the created object with flib_netconn_destroy.
+ */
+flib_netbase *flib_netbase_create(const char *server, uint16_t port);
+
+/**
+ * Free resources and close sockets.
+ */
+void flib_netbase_destroy(flib_netbase *net);
+
+/**
+ * Determine the current connection state. Starts out true, and turns to
+ * false when we are disconnected from the server.
+ */
+bool flib_netbase_connected(flib_netbase *net);
+
+/**
+ * Receive a new message and return it as a flib_netmsg. The netmsg has to be
+ * destroyed with flib_netmsg_destroy after use.
+ * Returns NULL if no message is available.
+ *
+ * Note: When a connection is closed, you probably want to call this function until
+ * no further message is returned, to ensure you see all messages that were sent
+ * before the connection closed.
+ */
+flib_netmsg *flib_netbase_recv_message(flib_netbase *net);
+
+int flib_netbase_send_raw(flib_netbase *net, const void *data, size_t len);
+
+/**
+ * Write a single message to the server. This call blocks until the
+ * message is completely written or the connection is closed or an error occurs.
+ *
+ * Returns a negative value on failure.
+ */
+int flib_netbase_send_message(flib_netbase *net, const flib_netmsg *msg);
+
+/**
+ * Send a message printf-style.
+ *
+ * flib_netbase_sendf(net, "%s\n\n", "TOGGLE_READY");
+ * flib_netbase_sendf(net, "%s\n%s\n%i\n\n", "CFG", "MAPGEN", MAPGEN_MAZE);
+ */
+int flib_netbase_sendf(flib_netbase *net, const char *format, ...);
+
+flib_netmsg *flib_netmsg_create();
+void flib_netmsg_destroy(flib_netmsg *msg);
+int flib_netmsg_append_part(flib_netmsg *msg, const void *param, size_t len);
+
+#endif /* NETBASE_H_ */
+
--- a/project_files/frontlib/net/netconn.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netconn.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,613 +1,613 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com>
- * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
- * Copyright (c) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include "netconn_internal.h"
-#include "netprotocol.h"
-#include "../util/logging.h"
-#include "../util/util.h"
-#include "../md5/md5.h"
-#include "../base64/base64.h"
-#include "../model/mapcfg.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-
-flib_netconn *flib_netconn_create(const char *playerName, const char *dataDirPath, const char *host, int port) {
-	flib_netconn *result = NULL;
-	if(!log_badargs_if4(playerName==NULL, host==NULL, port<1, port>65535)) {
-		flib_netconn *newConn = flib_calloc(1, sizeof(flib_netconn));
-		if(newConn) {
-			newConn->netBase = flib_netbase_create(host, port);
-			newConn->playerName = flib_strdupnull(playerName);
-			newConn->dataDirPath = flib_strdupnull(dataDirPath);
-
-			newConn->netconnState = NETCONN_STATE_CONNECTING;
-
-			newConn->isChief = false;
-			newConn->map = flib_map_create_named("", "NoSuchMap");
-			newConn->pendingTeamlist.teamCount = 0;
-			newConn->pendingTeamlist.teams = NULL;
-			newConn->teamlist.teamCount = 0;
-			newConn->teamlist.teams = NULL;
-			newConn->scheme = NULL;
-			newConn->style = NULL;
-			newConn->weaponset = NULL;
-
-			newConn->running = false;
-			newConn->destroyRequested = false;
-			netconn_clearCallbacks(newConn);
-			if(newConn->netBase && newConn->playerName && newConn->dataDirPath && newConn->map) {
-				result = newConn;
-				newConn = NULL;
-			}
-		}
-		flib_netconn_destroy(newConn);
-	}
-	return result;
-}
-
-void flib_netconn_destroy(flib_netconn *conn) {
-	if(conn) {
-		if(conn->running) {
-			/*
-			 * The function was called from a callback, so the tick function is still running
-			 * and we delay the actual destruction. We ensure no further callbacks will be
-			 * sent to prevent surprises.
-			 */
-			netconn_clearCallbacks(conn);
-			conn->destroyRequested = true;
-		} else {
-			flib_netbase_destroy(conn->netBase);
-			free(conn->playerName);
-			free(conn->dataDirPath);
-
-			flib_map_destroy(conn->map);
-			flib_teamlist_clear(&conn->pendingTeamlist);
-			flib_teamlist_clear(&conn->teamlist);
-			flib_scheme_destroy(conn->scheme);
-			free(conn->style);
-			flib_weaponset_destroy(conn->weaponset);
-
-			free(conn);
-		}
-	}
-}
-
-bool flib_netconn_is_chief(flib_netconn *conn) {
-	if(!log_badargs_if(conn==NULL) && conn->netconnState==NETCONN_STATE_ROOM) {
-		return conn->isChief;
-	}
-	return false;
-}
-
-const char *flib_netconn_get_playername(flib_netconn *conn) {
-	if(!log_badargs_if(conn==NULL)) {
-		return conn->playerName;
-	}
-	return NULL;
-}
-
-void netconn_leaveRoom(flib_netconn *conn) {
-	conn->netconnState = NETCONN_STATE_LOBBY;
-	conn->isChief = false;
-	flib_map_destroy(conn->map);
-	conn->map = flib_map_create_named("", "NoSuchMap");
-	flib_teamlist_clear(&conn->pendingTeamlist);
-	flib_teamlist_clear(&conn->teamlist);
-	flib_scheme_destroy(conn->scheme);
-	conn->scheme = NULL;
-	free(conn->style);
-	conn->style = NULL;
-	flib_weaponset_destroy(conn->weaponset);
-	conn->weaponset = NULL;
-}
-
-void netconn_setMap(flib_netconn *conn, const flib_map *map) {
-	flib_map *copy = flib_map_copy(map);
-	if(copy) {
-		flib_map_destroy(conn->map);
-		conn->map = copy;
-	}
-}
-
-void netconn_setWeaponset(flib_netconn *conn, const flib_weaponset *weaponset) {
-	flib_weaponset *copy = flib_weaponset_copy(weaponset);
-	if(copy) {
-		flib_weaponset_destroy(conn->weaponset);
-		conn->weaponset = copy;
-	}
-}
-
-void netconn_setScript(flib_netconn *conn, const char *script) {
-	char *copy = flib_strdupnull(script);
-	if(copy) {
-		free(conn->style);
-		conn->style = copy;
-	}
-}
-
-void netconn_setScheme(flib_netconn *conn, const flib_scheme *scheme) {
-	flib_scheme *copy = flib_scheme_copy(scheme);
-	if(copy) {
-		flib_scheme_destroy(conn->scheme);
-		conn->scheme = copy;
-	}
-}
-
-flib_gamesetup *flib_netconn_create_gamesetup(flib_netconn *conn) {
-	flib_gamesetup *result = NULL;
-	if(!log_badargs_if(conn==NULL)) {
-		if(conn->teamlist.teamCount==0 || !conn->scheme || !conn->weaponset) {
-			flib_log_e("Incomplete room state");
-		} else {
-			flib_gamesetup stackSetup = {0};
-			stackSetup.gamescheme = conn->scheme;
-			stackSetup.map = conn->map;
-			stackSetup.style = conn->style;
-			stackSetup.teamlist = &conn->teamlist;
-			result = flib_gamesetup_copy(&stackSetup);
-			if(result) {
-				bool error = false;
-				for(int i=0; i<result->teamlist->teamCount; i++) {
-					if(flib_team_set_weaponset(result->teamlist->teams[i], conn->weaponset)) {
-						error = true;
-					}
-					flib_team_set_health(result->teamlist->teams[i], flib_scheme_get_setting(conn->scheme, "health", 100));
-				}
-				if(result->map->mapgen == MAPGEN_NAMED && result->map->name) {
-					flib_mapcfg mapcfg;
-					if(!flib_mapcfg_read(conn->dataDirPath, result->map->name, &mapcfg)) {
-						free(result->map->theme);
-						result->map->theme = flib_strdupnull(mapcfg.theme);
-						if(!result->map->theme) {
-							error = true;
-						}
-					} else {
-						flib_log_e("Unable to read map config for map %s", result->map->name);
-					}
-				}
-				if(error) {
-					flib_gamesetup_destroy(result);
-					result = NULL;
-				}
-			}
-		}
-	}
-	return result;
-}
-
-static void flib_netconn_wrappedtick(flib_netconn *conn) {
-	flib_netmsg *netmsg;
-	flib_netbase *net = conn->netBase;
-	bool exit = false;
-
-	while(!exit && !conn->destroyRequested && (netmsg=flib_netbase_recv_message(conn->netBase))) {
-		if(netmsg->partCount==0) {
-			flib_log_w("Empty server message");
-			continue;
-		}
-
-		if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) {
-			char *buf = flib_join(netmsg->parts, netmsg->partCount, "|");
-			if(buf) {
-				flib_log_d("[Net In]%s", buf);
-			}
-			free(buf);
-		}
-
-		const char *cmd = netmsg->parts[0];
-
-	    if (!strcmp(cmd, "NICK") && netmsg->partCount>=2) {
-	    	if(netmsg->partCount<2) {
-	    		flib_log_w("Net: Malformed NICK message");
-	    	} else {
-	    		char *nick = flib_strdupnull(netmsg->parts[1]);
-	    		if(nick) {
-					free(conn->playerName);
-					conn->playerName = nick;
-	    		} else {
-					conn->netconnState = NETCONN_STATE_DISCONNECTED;
-					conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_INTERNAL_ERROR, "Out of memory");
-					exit = true;
-				}
-	    	}
-	    } else if (!strcmp(cmd, "PROTO")) {
-	        // The server just echoes this back apparently
-		} else if (!strcmp(cmd, "ERROR")) {
-			if (netmsg->partCount >= 2) {
-				conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_ERROR, netmsg->parts[1]);
-			} else {
-				conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_ERROR, "Unknown Error");
-			}
-		} else if(!strcmp(cmd, "WARNING")) {
-			if (netmsg->partCount >= 2) {
-				conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_WARNING, netmsg->parts[1]);
-			} else {
-				conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_WARNING, "Unknown Warning");
-			}
-	    } else if(!strcmp(cmd, "CONNECTED")) {
-			if(netmsg->partCount<3 || atol(netmsg->parts[2])<MIN_SERVER_VERSION) {
-				flib_log_w("Net: Server too old");
-				flib_netbase_sendf(net, "%s\n%s\n\n", "QUIT", "Server too old");
-				conn->netconnState = NETCONN_STATE_DISCONNECTED;
-				conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_SERVER_TOO_OLD, "Server too old");
-				exit = true;
-			} else {
-				flib_netbase_sendf(net, "%s\n%s\n\n", "NICK", conn->playerName);
-				flib_netbase_sendf(net, "%s\n%i\n\n", "PROTO", (int)PROTOCOL_VERSION);
-			}
-		} else if(!strcmp(cmd, "PING")) {
-	        if (netmsg->partCount > 1) {
-	        	flib_netbase_sendf(net, "%s\n%s\n\n", "PONG", netmsg->parts[1]);
-	        } else {
-	        	flib_netbase_sendf(net, "%s\n\n", "PONG");
-	        }
-	    } else if(!strcmp(cmd, "ROOMS")) {
-	        if(netmsg->partCount % 8 != 1) {
-	        	flib_log_w("Net: Malformed ROOMS message");
-	        } else {
-	        	int roomCount = netmsg->partCount/8;
-	        	flib_room **rooms = flib_room_array_from_netmsg(netmsg->parts+1, roomCount);
-	        	if(rooms) {
-	        		conn->onRoomlistCb(conn->onRoomlistCtx, (const flib_room**)rooms, roomCount);
-	        		for(int i=0; i<roomCount; i++) {
-	        			flib_room_destroy(rooms[i]);
-	        		}
-	        		free(rooms);
-	        	}
-	        }
-	    } else if (!strcmp(cmd, "SERVER_MESSAGE")) {
-	        if(netmsg->partCount < 2) {
-	        	flib_log_w("Net: Empty SERVERMESSAGE message");
-	        } else {
-	        	conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_SERVERMESSAGE, netmsg->parts[1]);
-	        }
-	    } else if (!strcmp(cmd, "CHAT")) {
-	        if(netmsg->partCount < 3) {
-	        	flib_log_w("Net: Empty CHAT message");
-	        } else {
-	        	conn->onChatCb(conn->onChatCtx, netmsg->parts[1], netmsg->parts[2]);
-	        }
-	    } else if (!strcmp(cmd, "INFO")) {
-	        if(netmsg->partCount < 5) {
-	        	flib_log_w("Net: Malformed INFO message");
-	        } else {
-	        	char *joined = flib_join(netmsg->parts+1, netmsg->partCount-1, "\n");
-	        	if(joined) {
-	        		conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_PLAYERINFO, joined);
-	        	}
-	        	free(joined);
-	        }
-	    } else if(!strcmp(cmd, "SERVER_VARS")) {
-	    	for(int offset=1; offset+2<netmsg->partCount; offset+=2) {
-	    		conn->onServerVarCb(conn->onServerVarCtx, netmsg->parts[offset], netmsg->parts[offset+1]);
-	    	}
-	    } else if (!strcmp(cmd, "CLIENT_FLAGS")) {
-	        if(netmsg->partCount < 3 || strlen(netmsg->parts[1]) < 2) {
-	        	flib_log_w("Net: Malformed CLIENT_FLAGS message");
-	        } else {
-				const char *flags = netmsg->parts[1];
-				bool setFlag = flags[0] == '+';
-
-				for(int j = 2; j < netmsg->partCount; ++j) {
-					bool isSelf = !strcmp(conn->playerName, netmsg->parts[j]);
-					if(isSelf && strchr(flags, 'h')) {
-						conn->isChief = setFlag;
-					}
-					conn->onClientFlagsCb(conn->onClientFlagsCtx, netmsg->parts[j], flags+1, setFlag);
-				}
-	        }
-	    } else if (!strcmp(cmd, "ADD_TEAM")) {
-	        if(netmsg->partCount != 24 || conn->netconnState!=NETCONN_STATE_ROOM) {
-	            flib_log_w("Net: Bad ADD_TEAM message");
-	        } else {
-	        	flib_team *team = flib_team_from_netmsg(netmsg->parts+1);
-	        	if(!team || flib_teamlist_insert(&conn->teamlist, team, conn->teamlist.teamCount)) {
-					flib_team_destroy(team);
-					conn->netconnState = NETCONN_STATE_DISCONNECTED;
-					conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_INTERNAL_ERROR, "Internal error");
-					exit = true;
-	        	} else {
-	        		conn->onTeamAddCb(conn->onTeamAddCtx, team);
-	        	}
-	        }
-	    } else if (!strcmp(cmd, "REMOVE_TEAM")) {
-	        if(netmsg->partCount != 2 || conn->netconnState!=NETCONN_STATE_ROOM) {
-	            flib_log_w("Net: Bad REMOVETEAM message");
-	        } else {
-	        	flib_teamlist_delete(&conn->teamlist, netmsg->parts[1]);
-	        	conn->onTeamDeleteCb(conn->onTeamDeleteCtx, netmsg->parts[1]);
-	        }
-	    } else if(!strcmp(cmd, "ROOMABANDONED")) {
-	    	netconn_leaveRoom(conn);
-	        conn->onLeaveRoomCb(conn->onLeaveRoomCtx, NETCONN_ROOMLEAVE_ABANDONED, "Room destroyed");
-	    } else if(!strcmp(cmd, "KICKED")) {
-	    	netconn_leaveRoom(conn);
-	    	conn->onLeaveRoomCb(conn->onLeaveRoomCtx, NETCONN_ROOMLEAVE_KICKED, "You got kicked");
-	    } else if(!strcmp(cmd, "JOINED")) {
-	        if(netmsg->partCount < 2) {
-	            flib_log_w("Net: Bad JOINED message");
-	        } else {
-				for(int i = 1; i < netmsg->partCount; ++i)
-				{
-					bool isMe = !strcmp(conn->playerName, netmsg->parts[i]);
-					if (isMe) {
-						conn->netconnState = NETCONN_STATE_ROOM;
-						conn->onEnterRoomCb(conn->onEnterRoomCtx, conn->isChief);
-					}
-
-					conn->onRoomJoinCb(conn->onRoomJoinCtx, netmsg->parts[i]);
-				}
-	        }
-	    } else if(!strcmp(cmd, "LOBBY:JOINED")) {
-	        if(netmsg->partCount < 2) {
-	            flib_log_w("Net: Bad JOINED message");
-	        } else {
-				for(int i = 1; i < netmsg->partCount; ++i)
-				{
-					bool isMe = !strcmp(conn->playerName, netmsg->parts[i]);
-					if (isMe && conn->netconnState == NETCONN_STATE_CONNECTING) {
-						conn->onConnectedCb(conn->onConnectedCtx);
-						conn->netconnState = NETCONN_STATE_LOBBY;
-					}
-					conn->onLobbyJoinCb(conn->onLobbyJoinCtx, netmsg->parts[i]);
-				}
-	        }
-	    } else if(!strcmp(cmd, "LEFT")) {
-	        if(netmsg->partCount < 2) {
-	            flib_log_w("Net: Bad LEFT message");
-	        } else {
-	        	conn->onRoomLeaveCb(conn->onRoomLeaveCtx, netmsg->parts[1], netmsg->partCount>2 ? netmsg->parts[2] : NULL);
-	        }
-	    } else if(!strcmp(cmd, "ROOM") && netmsg->partCount >= 2) {
-	    	const char *subcmd = netmsg->parts[1];
-	    	if(!strcmp(subcmd, "ADD") && netmsg->partCount == 10) {
-	    		flib_room *room = flib_room_from_netmsg(netmsg->parts+2);
-	    		if(room) {
-	    			conn->onRoomAddCb(conn->onRoomAddCtx, room);
-	    		}
-	    		flib_room_destroy(room);
-			} else if(!strcmp(subcmd, "UPD") && netmsg->partCount == 11) {
-				flib_room *room = flib_room_from_netmsg(netmsg->parts+3);
-				if(room) {
-	    			conn->onRoomUpdateCb(conn->onRoomUpdateCtx, netmsg->parts[2], room);
-	    		}
-				flib_room_destroy(room);
-			} else if(!strcmp(subcmd, "DEL") && netmsg->partCount == 3) {
-				conn->onRoomDeleteCb(conn->onRoomDeleteCtx, netmsg->parts[2]);
-			} else {
-				flib_log_w("Net: Unknown or malformed ROOM subcommand: %s", subcmd);
-			}
-	    } else if(!strcmp(cmd, "LOBBY:LEFT")) {
-	        if(netmsg->partCount < 2) {
-	            flib_log_w("Net: Bad LOBBY:LEFT message");
-	        } else {
-	        	conn->onLobbyLeaveCb(conn->onLobbyLeaveCtx, netmsg->parts[1], netmsg->partCount>2 ? netmsg->parts[2] : NULL);
-	        }
-	    } else if (!strcmp(cmd, "RUN_GAME")) {
-	        conn->onRunGameCb(conn->onRunGameCtx);
-	    } else if (!strcmp(cmd, "ASKPASSWORD")) {
-	    	conn->onPasswordRequestCb(conn->onPasswordRequestCtx, conn->playerName);
-	    } else if (!strcmp(cmd, "NOTICE")) {
-	        if(netmsg->partCount < 2) {
-	            flib_log_w("Net: Bad NOTICE message");
-	        } else {
-				errno = 0;
-				long n = strtol(netmsg->parts[1], NULL, 10);
-				if(errno) {
-					flib_log_w("Net: Bad NOTICE message");
-				} else if(n==0) {
-					conn->onNickTakenCb(conn->onNickTakenCtx, conn->playerName);
-				} else {
-					flib_log_w("Net: Unknown NOTICE message: %l", n);
-				}
-	        }
-	    } else if (!strcmp(cmd, "TEAM_ACCEPTED")) {
-	        if (netmsg->partCount != 2 || conn->netconnState!=NETCONN_STATE_ROOM) {
-	            flib_log_w("Net: Bad TEAM_ACCEPTED message");
-	        } else {
-	        	flib_team *team = flib_team_copy(flib_teamlist_find(&conn->pendingTeamlist, netmsg->parts[1]));
-	        	if(team) {
-	        		flib_teamlist_insert(&conn->teamlist, team, conn->teamlist.teamCount);
-	        		flib_teamlist_delete(&conn->pendingTeamlist, netmsg->parts[1]);
-	        	} else {
-	        		flib_log_e("Team accepted that was not requested: %s", netmsg->parts[1]);
-	        	}
-	        	conn->onTeamAcceptedCb(conn->onTeamAcceptedCtx, netmsg->parts[1]);
-	        }
-	    } else if (!strcmp(cmd, "CFG")) {
-	        if(netmsg->partCount < 3 || conn->netconnState!=NETCONN_STATE_ROOM) {
-	            flib_log_w("Net: Bad CFG message");
-	        } else {
-	        	const char *subcmd = netmsg->parts[1];
-				if(!strcmp(subcmd, "SCHEME") && netmsg->partCount == flib_meta.modCount + flib_meta.settingCount + 3) {
-					flib_scheme *cfg = flib_scheme_from_netmsg(netmsg->parts+2);
-					if(cfg) {
-						flib_scheme_destroy(conn->scheme);
-						conn->scheme = cfg;
-						conn->onSchemeChangedCb(conn->onSchemeChangedCtx, cfg);
-					} else {
-						flib_log_e("Error processing CFG SCHEME message");
-					}
-				} else if(!strcmp(subcmd, "FULLMAPCONFIG") && netmsg->partCount == 7) {
-					flib_map *map = flib_map_from_netmsg(netmsg->parts+2);
-					if(map) {
-						flib_map_destroy(conn->map);
-						conn->map = map;
-						conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_FULL);
-					} else {
-						flib_log_e("Error processing CFG FULLMAPCONFIG message");
-					}
-				} else if(!strcmp(subcmd, "MAP") && netmsg->partCount == 3) {
-					char *mapname = flib_strdupnull(netmsg->parts[2]);
-					if(mapname) {
-						free(conn->map->name);
-						conn->map->name = mapname;
-						conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_MAP);
-					} else {
-						flib_log_e("Error processing CFG MAP message");
-					}
-				} else if(!strcmp(subcmd, "THEME") && netmsg->partCount == 3) {
-					char *themename = flib_strdupnull(netmsg->parts[2]);
-					if(themename) {
-						free(conn->map->theme);
-						conn->map->theme = themename;
-						conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_THEME);
-					} else {
-						flib_log_e("Error processing CFG THEME message");
-					}
-				} else if(!strcmp(subcmd, "SEED") && netmsg->partCount == 3) {
-					char *seed = flib_strdupnull(netmsg->parts[2]);
-					if(seed) {
-						free(conn->map->seed);
-						conn->map->seed = seed;
-						conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_SEED);
-					} else {
-						flib_log_e("Error processing CFG SEED message");
-					}
-				} else if(!strcmp(subcmd, "TEMPLATE") && netmsg->partCount == 3) {
-					conn->map->templateFilter = atoi(netmsg->parts[2]);
-					conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_TEMPLATE);
-				} else if(!strcmp(subcmd, "MAPGEN") && netmsg->partCount == 3) {
-					conn->map->mapgen = atoi(netmsg->parts[2]);
-					conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_MAPGEN);
-				} else if(!strcmp(subcmd, "MAZE_SIZE") && netmsg->partCount == 3) {
-					conn->map->mazeSize = atoi(netmsg->parts[2]);
-					conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_MAZE_SIZE);
-				} else if(!strcmp(subcmd, "DRAWNMAP") && netmsg->partCount == 3) {
-					size_t drawnMapSize = 0;
-					uint8_t *drawnMapData = NULL;
-					if(!flib_drawnmapdata_from_netmsg(netmsg->parts[2], &drawnMapData, &drawnMapSize)) {
-						free(conn->map->drawData);
-						conn->map->drawData = drawnMapData;
-						conn->map->drawDataSize = drawnMapSize;
-						conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_DRAWNMAP);
-					} else {
-						flib_log_e("Error processing CFG DRAWNMAP message");
-					}
-				} else if(!strcmp(subcmd, "SCRIPT") && netmsg->partCount == 3) {
-					netconn_setScript(conn, netmsg->parts[2]);
-					conn->onScriptChangedCb(conn->onScriptChangedCtx, netmsg->parts[2]);
-				} else if(!strcmp(subcmd, "AMMO") && netmsg->partCount == 4) {
-					flib_weaponset *weapons = flib_weaponset_from_ammostring(netmsg->parts[2], netmsg->parts[3]);
-					if(weapons) {
-						flib_weaponset_destroy(conn->weaponset);
-						conn->weaponset = weapons;
-						conn->onWeaponsetChangedCb(conn->onWeaponsetChangedCtx, weapons);
-					} else {
-						flib_log_e("Error processing CFG AMMO message");
-					}
-				} else {
-					flib_log_w("Net: Unknown or malformed CFG subcommand: %s", subcmd);
-				}
-	        }
-	    } else if (!strcmp(cmd, "HH_NUM")) {
-	        if (netmsg->partCount != 3 || conn->netconnState!=NETCONN_STATE_ROOM) {
-	            flib_log_w("Net: Bad HH_NUM message");
-	        } else {
-	        	int hogs = atoi(netmsg->parts[2]);
-	        	if(hogs<=0 || hogs>HEDGEHOGS_PER_TEAM) {
-	        		flib_log_w("Net: Bad HH_NUM message: %s hogs", netmsg->parts[2]);
-	        	} else {
-	        		flib_team *team = flib_teamlist_find(&conn->teamlist, netmsg->parts[1]);
-	        		if(team) {
-	        			team->hogsInGame = hogs;
-	        		} else {
-	        			flib_log_e("HH_NUM message for unknown team %s", netmsg->parts[1]);
-	        		}
-	        		conn->onHogCountChangedCb(conn->onHogCountChangedCtx, netmsg->parts[1], hogs);
-	        	}
-	        }
-	    } else if (!strcmp(cmd, "TEAM_COLOR")) {
-	        if (netmsg->partCount != 3 || conn->netconnState!=NETCONN_STATE_ROOM) {
-	            flib_log_w("Net: Bad TEAM_COLOR message");
-	        } else {
-	        	long color;
-	        	if(sscanf(netmsg->parts[2], "%lu", &color) && color>=0 && color<flib_teamcolor_count) {
-	        		flib_team *team = flib_teamlist_find(&conn->teamlist, netmsg->parts[1]);
-	        		if(team) {
-	        			team->colorIndex = color;
-	        		} else {
-	        			flib_log_e("TEAM_COLOR message for unknown team %s", netmsg->parts[1]);
-	        		}
-	        		conn->onTeamColorChangedCb(conn->onTeamColorChangedCtx, netmsg->parts[1], color);
-	        	} else {
-	        		flib_log_w("Net: Bad TEAM_COLOR message: Color %s", netmsg->parts[2]);
-	        	}
-	        }
-	    } else if (!strcmp(cmd, "EM")) {
-	        if(netmsg->partCount < 2) {
-	            flib_log_w("Net: Bad EM message");
-	        } else {
-	        	for(int i = 1; i < netmsg->partCount; ++i) {
-					char *out = NULL;
-					size_t outlen;
-					bool ok = base64_decode_alloc(netmsg->parts[i], strlen(netmsg->parts[i]), &out, &outlen);
-					if(ok && outlen) {
-						conn->onEngineMessageCb(conn->onEngineMessageCtx, (uint8_t*)out, outlen);
-					} else {
-						flib_log_e("Net: Malformed engine message: %s", netmsg->parts[i]);
-					}
-					free(out);
-	        	}
-	        }
-	    } else if (!strcmp(cmd, "BYE")) {
-	        if (netmsg->partCount < 2) {
-	            flib_log_w("Net: Bad BYE message");
-	        } else {
-				conn->netconnState = NETCONN_STATE_DISCONNECTED;
-				if (!strcmp(netmsg->parts[1], "Authentication failed")) {
-					conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_AUTH_FAILED, netmsg->parts[1]);
-				} else {
-					conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_NORMAL, netmsg->parts[1]);
-				}
-				exit = true;
-	        }
-	    } else if (!strcmp(cmd, "ADMIN_ACCESS")) {
-	    	// deprecated
-	    } else if (!strcmp(cmd, "ROOM_CONTROL_ACCESS")) {
-	    	// deprecated
-	    } else {
-	    	flib_log_w("Unknown server command: %s", cmd);
-	    }
-		flib_netmsg_destroy(netmsg);
-	}
-
-	if(!exit && !conn->destroyRequested && !flib_netbase_connected(net)) {
-		conn->netconnState = NETCONN_STATE_DISCONNECTED;
-		conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_CONNLOST, "Connection lost");
-	}
-}
-
-void flib_netconn_tick(flib_netconn *conn) {
-	if(!log_badargs_if(conn==NULL)
-			&& !log_w_if(conn->running, "Call to flib_netconn_tick from a callback")
-			&& !log_w_if(conn->netconnState == NETCONN_STATE_DISCONNECTED, "We are already done.")) {
-		conn->running = true;
-		flib_netconn_wrappedtick(conn);
-		conn->running = false;
-
-		if(conn->destroyRequested) {
-			flib_netconn_destroy(conn);
-		}
-	}
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com>
+ * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "netconn_internal.h"
+#include "netprotocol.h"
+#include "../util/logging.h"
+#include "../util/util.h"
+#include "../md5/md5.h"
+#include "../base64/base64.h"
+#include "../model/mapcfg.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+
+flib_netconn *flib_netconn_create(const char *playerName, const char *dataDirPath, const char *host, int port) {
+    flib_netconn *result = NULL;
+    if(!log_badargs_if4(playerName==NULL, host==NULL, port<1, port>65535)) {
+        flib_netconn *newConn = flib_calloc(1, sizeof(flib_netconn));
+        if(newConn) {
+            newConn->netBase = flib_netbase_create(host, port);
+            newConn->playerName = flib_strdupnull(playerName);
+            newConn->dataDirPath = flib_strdupnull(dataDirPath);
+
+            newConn->netconnState = NETCONN_STATE_CONNECTING;
+
+            newConn->isChief = false;
+            newConn->map = flib_map_create_named("", "NoSuchMap");
+            newConn->pendingTeamlist.teamCount = 0;
+            newConn->pendingTeamlist.teams = NULL;
+            newConn->teamlist.teamCount = 0;
+            newConn->teamlist.teams = NULL;
+            newConn->scheme = NULL;
+            newConn->style = NULL;
+            newConn->weaponset = NULL;
+
+            newConn->running = false;
+            newConn->destroyRequested = false;
+            netconn_clearCallbacks(newConn);
+            if(newConn->netBase && newConn->playerName && newConn->dataDirPath && newConn->map) {
+                result = newConn;
+                newConn = NULL;
+            }
+        }
+        flib_netconn_destroy(newConn);
+    }
+    return result;
+}
+
+void flib_netconn_destroy(flib_netconn *conn) {
+    if(conn) {
+        if(conn->running) {
+            /*
+             * The function was called from a callback, so the tick function is still running
+             * and we delay the actual destruction. We ensure no further callbacks will be
+             * sent to prevent surprises.
+             */
+            netconn_clearCallbacks(conn);
+            conn->destroyRequested = true;
+        } else {
+            flib_netbase_destroy(conn->netBase);
+            free(conn->playerName);
+            free(conn->dataDirPath);
+
+            flib_map_destroy(conn->map);
+            flib_teamlist_clear(&conn->pendingTeamlist);
+            flib_teamlist_clear(&conn->teamlist);
+            flib_scheme_destroy(conn->scheme);
+            free(conn->style);
+            flib_weaponset_destroy(conn->weaponset);
+
+            free(conn);
+        }
+    }
+}
+
+bool flib_netconn_is_chief(flib_netconn *conn) {
+    if(!log_badargs_if(conn==NULL) && conn->netconnState==NETCONN_STATE_ROOM) {
+        return conn->isChief;
+    }
+    return false;
+}
+
+const char *flib_netconn_get_playername(flib_netconn *conn) {
+    if(!log_badargs_if(conn==NULL)) {
+        return conn->playerName;
+    }
+    return NULL;
+}
+
+void netconn_leaveRoom(flib_netconn *conn) {
+    conn->netconnState = NETCONN_STATE_LOBBY;
+    conn->isChief = false;
+    flib_map_destroy(conn->map);
+    conn->map = flib_map_create_named("", "NoSuchMap");
+    flib_teamlist_clear(&conn->pendingTeamlist);
+    flib_teamlist_clear(&conn->teamlist);
+    flib_scheme_destroy(conn->scheme);
+    conn->scheme = NULL;
+    free(conn->style);
+    conn->style = NULL;
+    flib_weaponset_destroy(conn->weaponset);
+    conn->weaponset = NULL;
+}
+
+void netconn_setMap(flib_netconn *conn, const flib_map *map) {
+    flib_map *copy = flib_map_copy(map);
+    if(copy) {
+        flib_map_destroy(conn->map);
+        conn->map = copy;
+    }
+}
+
+void netconn_setWeaponset(flib_netconn *conn, const flib_weaponset *weaponset) {
+    flib_weaponset *copy = flib_weaponset_copy(weaponset);
+    if(copy) {
+        flib_weaponset_destroy(conn->weaponset);
+        conn->weaponset = copy;
+    }
+}
+
+void netconn_setScript(flib_netconn *conn, const char *script) {
+    char *copy = flib_strdupnull(script);
+    if(copy) {
+        free(conn->style);
+        conn->style = copy;
+    }
+}
+
+void netconn_setScheme(flib_netconn *conn, const flib_scheme *scheme) {
+    flib_scheme *copy = flib_scheme_copy(scheme);
+    if(copy) {
+        flib_scheme_destroy(conn->scheme);
+        conn->scheme = copy;
+    }
+}
+
+flib_gamesetup *flib_netconn_create_gamesetup(flib_netconn *conn) {
+    flib_gamesetup *result = NULL;
+    if(!log_badargs_if(conn==NULL)) {
+        if(conn->teamlist.teamCount==0 || !conn->scheme || !conn->weaponset) {
+            flib_log_e("Incomplete room state");
+        } else {
+            flib_gamesetup stackSetup = {0};
+            stackSetup.gamescheme = conn->scheme;
+            stackSetup.map = conn->map;
+            stackSetup.style = conn->style;
+            stackSetup.teamlist = &conn->teamlist;
+            result = flib_gamesetup_copy(&stackSetup);
+            if(result) {
+                bool error = false;
+                for(int i=0; i<result->teamlist->teamCount; i++) {
+                    if(flib_team_set_weaponset(result->teamlist->teams[i], conn->weaponset)) {
+                        error = true;
+                    }
+                    flib_team_set_health(result->teamlist->teams[i], flib_scheme_get_setting(conn->scheme, "health", 100));
+                }
+                if(result->map->mapgen == MAPGEN_NAMED && result->map->name) {
+                    flib_mapcfg mapcfg;
+                    if(!flib_mapcfg_read(conn->dataDirPath, result->map->name, &mapcfg)) {
+                        free(result->map->theme);
+                        result->map->theme = flib_strdupnull(mapcfg.theme);
+                        if(!result->map->theme) {
+                            error = true;
+                        }
+                    } else {
+                        flib_log_e("Unable to read map config for map %s", result->map->name);
+                    }
+                }
+                if(error) {
+                    flib_gamesetup_destroy(result);
+                    result = NULL;
+                }
+            }
+        }
+    }
+    return result;
+}
+
+static void flib_netconn_wrappedtick(flib_netconn *conn) {
+    flib_netmsg *netmsg;
+    flib_netbase *net = conn->netBase;
+    bool exit = false;
+
+    while(!exit && !conn->destroyRequested && (netmsg=flib_netbase_recv_message(conn->netBase))) {
+        if(netmsg->partCount==0) {
+            flib_log_w("Empty server message");
+            continue;
+        }
+
+        if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) {
+            char *buf = flib_join(netmsg->parts, netmsg->partCount, "|");
+            if(buf) {
+                flib_log_d("[Net In]%s", buf);
+            }
+            free(buf);
+        }
+
+        const char *cmd = netmsg->parts[0];
+
+        if (!strcmp(cmd, "NICK") && netmsg->partCount>=2) {
+            if(netmsg->partCount<2) {
+                flib_log_w("Net: Malformed NICK message");
+            } else {
+                char *nick = flib_strdupnull(netmsg->parts[1]);
+                if(nick) {
+                    free(conn->playerName);
+                    conn->playerName = nick;
+                } else {
+                    conn->netconnState = NETCONN_STATE_DISCONNECTED;
+                    conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_INTERNAL_ERROR, "Out of memory");
+                    exit = true;
+                }
+            }
+        } else if (!strcmp(cmd, "PROTO")) {
+            // The server just echoes this back apparently
+        } else if (!strcmp(cmd, "ERROR")) {
+            if (netmsg->partCount >= 2) {
+                conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_ERROR, netmsg->parts[1]);
+            } else {
+                conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_ERROR, "Unknown Error");
+            }
+        } else if(!strcmp(cmd, "WARNING")) {
+            if (netmsg->partCount >= 2) {
+                conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_WARNING, netmsg->parts[1]);
+            } else {
+                conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_WARNING, "Unknown Warning");
+            }
+        } else if(!strcmp(cmd, "CONNECTED")) {
+            if(netmsg->partCount<3 || atol(netmsg->parts[2])<MIN_SERVER_VERSION) {
+                flib_log_w("Net: Server too old");
+                flib_netbase_sendf(net, "%s\n%s\n\n", "QUIT", "Server too old");
+                conn->netconnState = NETCONN_STATE_DISCONNECTED;
+                conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_SERVER_TOO_OLD, "Server too old");
+                exit = true;
+            } else {
+                flib_netbase_sendf(net, "%s\n%s\n\n", "NICK", conn->playerName);
+                flib_netbase_sendf(net, "%s\n%i\n\n", "PROTO", (int)PROTOCOL_VERSION);
+            }
+        } else if(!strcmp(cmd, "PING")) {
+            if (netmsg->partCount > 1) {
+                flib_netbase_sendf(net, "%s\n%s\n\n", "PONG", netmsg->parts[1]);
+            } else {
+                flib_netbase_sendf(net, "%s\n\n", "PONG");
+            }
+        } else if(!strcmp(cmd, "ROOMS")) {
+            if(netmsg->partCount % 8 != 1) {
+                flib_log_w("Net: Malformed ROOMS message");
+            } else {
+                int roomCount = netmsg->partCount/8;
+                flib_room **rooms = flib_room_array_from_netmsg(netmsg->parts+1, roomCount);
+                if(rooms) {
+                    conn->onRoomlistCb(conn->onRoomlistCtx, (const flib_room**)rooms, roomCount);
+                    for(int i=0; i<roomCount; i++) {
+                        flib_room_destroy(rooms[i]);
+                    }
+                    free(rooms);
+                }
+            }
+        } else if (!strcmp(cmd, "SERVER_MESSAGE")) {
+            if(netmsg->partCount < 2) {
+                flib_log_w("Net: Empty SERVERMESSAGE message");
+            } else {
+                conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_SERVERMESSAGE, netmsg->parts[1]);
+            }
+        } else if (!strcmp(cmd, "CHAT")) {
+            if(netmsg->partCount < 3) {
+                flib_log_w("Net: Empty CHAT message");
+            } else {
+                conn->onChatCb(conn->onChatCtx, netmsg->parts[1], netmsg->parts[2]);
+            }
+        } else if (!strcmp(cmd, "INFO")) {
+            if(netmsg->partCount < 5) {
+                flib_log_w("Net: Malformed INFO message");
+            } else {
+                char *joined = flib_join(netmsg->parts+1, netmsg->partCount-1, "\n");
+                if(joined) {
+                    conn->onMessageCb(conn->onMessageCtx, NETCONN_MSG_TYPE_PLAYERINFO, joined);
+                }
+                free(joined);
+            }
+        } else if(!strcmp(cmd, "SERVER_VARS")) {
+            for(int offset=1; offset+2<netmsg->partCount; offset+=2) {
+                conn->onServerVarCb(conn->onServerVarCtx, netmsg->parts[offset], netmsg->parts[offset+1]);
+            }
+        } else if (!strcmp(cmd, "CLIENT_FLAGS")) {
+            if(netmsg->partCount < 3 || strlen(netmsg->parts[1]) < 2) {
+                flib_log_w("Net: Malformed CLIENT_FLAGS message");
+            } else {
+                const char *flags = netmsg->parts[1];
+                bool setFlag = flags[0] == '+';
+
+                for(int j = 2; j < netmsg->partCount; ++j) {
+                    bool isSelf = !strcmp(conn->playerName, netmsg->parts[j]);
+                    if(isSelf && strchr(flags, 'h')) {
+                        conn->isChief = setFlag;
+                    }
+                    conn->onClientFlagsCb(conn->onClientFlagsCtx, netmsg->parts[j], flags+1, setFlag);
+                }
+            }
+        } else if (!strcmp(cmd, "ADD_TEAM")) {
+            if(netmsg->partCount != 24 || conn->netconnState!=NETCONN_STATE_ROOM) {
+                flib_log_w("Net: Bad ADD_TEAM message");
+            } else {
+                flib_team *team = flib_team_from_netmsg(netmsg->parts+1);
+                if(!team || flib_teamlist_insert(&conn->teamlist, team, conn->teamlist.teamCount)) {
+                    flib_team_destroy(team);
+                    conn->netconnState = NETCONN_STATE_DISCONNECTED;
+                    conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_INTERNAL_ERROR, "Internal error");
+                    exit = true;
+                } else {
+                    conn->onTeamAddCb(conn->onTeamAddCtx, team);
+                }
+            }
+        } else if (!strcmp(cmd, "REMOVE_TEAM")) {
+            if(netmsg->partCount != 2 || conn->netconnState!=NETCONN_STATE_ROOM) {
+                flib_log_w("Net: Bad REMOVETEAM message");
+            } else {
+                flib_teamlist_delete(&conn->teamlist, netmsg->parts[1]);
+                conn->onTeamDeleteCb(conn->onTeamDeleteCtx, netmsg->parts[1]);
+            }
+        } else if(!strcmp(cmd, "ROOMABANDONED")) {
+            netconn_leaveRoom(conn);
+            conn->onLeaveRoomCb(conn->onLeaveRoomCtx, NETCONN_ROOMLEAVE_ABANDONED, "Room destroyed");
+        } else if(!strcmp(cmd, "KICKED")) {
+            netconn_leaveRoom(conn);
+            conn->onLeaveRoomCb(conn->onLeaveRoomCtx, NETCONN_ROOMLEAVE_KICKED, "You got kicked");
+        } else if(!strcmp(cmd, "JOINED")) {
+            if(netmsg->partCount < 2) {
+                flib_log_w("Net: Bad JOINED message");
+            } else {
+                for(int i = 1; i < netmsg->partCount; ++i)
+                {
+                    bool isMe = !strcmp(conn->playerName, netmsg->parts[i]);
+                    if (isMe) {
+                        conn->netconnState = NETCONN_STATE_ROOM;
+                        conn->onEnterRoomCb(conn->onEnterRoomCtx, conn->isChief);
+                    }
+
+                    conn->onRoomJoinCb(conn->onRoomJoinCtx, netmsg->parts[i]);
+                }
+            }
+        } else if(!strcmp(cmd, "LOBBY:JOINED")) {
+            if(netmsg->partCount < 2) {
+                flib_log_w("Net: Bad JOINED message");
+            } else {
+                for(int i = 1; i < netmsg->partCount; ++i)
+                {
+                    bool isMe = !strcmp(conn->playerName, netmsg->parts[i]);
+                    if (isMe && conn->netconnState == NETCONN_STATE_CONNECTING) {
+                        conn->onConnectedCb(conn->onConnectedCtx);
+                        conn->netconnState = NETCONN_STATE_LOBBY;
+                    }
+                    conn->onLobbyJoinCb(conn->onLobbyJoinCtx, netmsg->parts[i]);
+                }
+            }
+        } else if(!strcmp(cmd, "LEFT")) {
+            if(netmsg->partCount < 2) {
+                flib_log_w("Net: Bad LEFT message");
+            } else {
+                conn->onRoomLeaveCb(conn->onRoomLeaveCtx, netmsg->parts[1], netmsg->partCount>2 ? netmsg->parts[2] : NULL);
+            }
+        } else if(!strcmp(cmd, "ROOM") && netmsg->partCount >= 2) {
+            const char *subcmd = netmsg->parts[1];
+            if(!strcmp(subcmd, "ADD") && netmsg->partCount == 10) {
+                flib_room *room = flib_room_from_netmsg(netmsg->parts+2);
+                if(room) {
+                    conn->onRoomAddCb(conn->onRoomAddCtx, room);
+                }
+                flib_room_destroy(room);
+            } else if(!strcmp(subcmd, "UPD") && netmsg->partCount == 11) {
+                flib_room *room = flib_room_from_netmsg(netmsg->parts+3);
+                if(room) {
+                    conn->onRoomUpdateCb(conn->onRoomUpdateCtx, netmsg->parts[2], room);
+                }
+                flib_room_destroy(room);
+            } else if(!strcmp(subcmd, "DEL") && netmsg->partCount == 3) {
+                conn->onRoomDeleteCb(conn->onRoomDeleteCtx, netmsg->parts[2]);
+            } else {
+                flib_log_w("Net: Unknown or malformed ROOM subcommand: %s", subcmd);
+            }
+        } else if(!strcmp(cmd, "LOBBY:LEFT")) {
+            if(netmsg->partCount < 2) {
+                flib_log_w("Net: Bad LOBBY:LEFT message");
+            } else {
+                conn->onLobbyLeaveCb(conn->onLobbyLeaveCtx, netmsg->parts[1], netmsg->partCount>2 ? netmsg->parts[2] : NULL);
+            }
+        } else if (!strcmp(cmd, "RUN_GAME")) {
+            conn->onRunGameCb(conn->onRunGameCtx);
+        } else if (!strcmp(cmd, "ASKPASSWORD")) {
+            conn->onPasswordRequestCb(conn->onPasswordRequestCtx, conn->playerName);
+        } else if (!strcmp(cmd, "NOTICE")) {
+            if(netmsg->partCount < 2) {
+                flib_log_w("Net: Bad NOTICE message");
+            } else {
+                errno = 0;
+                long n = strtol(netmsg->parts[1], NULL, 10);
+                if(errno) {
+                    flib_log_w("Net: Bad NOTICE message");
+                } else if(n==0) {
+                    conn->onNickTakenCb(conn->onNickTakenCtx, conn->playerName);
+                } else {
+                    flib_log_w("Net: Unknown NOTICE message: %l", n);
+                }
+            }
+        } else if (!strcmp(cmd, "TEAM_ACCEPTED")) {
+            if (netmsg->partCount != 2 || conn->netconnState!=NETCONN_STATE_ROOM) {
+                flib_log_w("Net: Bad TEAM_ACCEPTED message");
+            } else {
+                flib_team *team = flib_team_copy(flib_teamlist_find(&conn->pendingTeamlist, netmsg->parts[1]));
+                if(team) {
+                    flib_teamlist_insert(&conn->teamlist, team, conn->teamlist.teamCount);
+                    flib_teamlist_delete(&conn->pendingTeamlist, netmsg->parts[1]);
+                } else {
+                    flib_log_e("Team accepted that was not requested: %s", netmsg->parts[1]);
+                }
+                conn->onTeamAcceptedCb(conn->onTeamAcceptedCtx, netmsg->parts[1]);
+            }
+        } else if (!strcmp(cmd, "CFG")) {
+            if(netmsg->partCount < 3 || conn->netconnState!=NETCONN_STATE_ROOM) {
+                flib_log_w("Net: Bad CFG message");
+            } else {
+                const char *subcmd = netmsg->parts[1];
+                if(!strcmp(subcmd, "SCHEME") && netmsg->partCount == flib_meta.modCount + flib_meta.settingCount + 3) {
+                    flib_scheme *cfg = flib_scheme_from_netmsg(netmsg->parts+2);
+                    if(cfg) {
+                        flib_scheme_destroy(conn->scheme);
+                        conn->scheme = cfg;
+                        conn->onSchemeChangedCb(conn->onSchemeChangedCtx, cfg);
+                    } else {
+                        flib_log_e("Error processing CFG SCHEME message");
+                    }
+                } else if(!strcmp(subcmd, "FULLMAPCONFIG") && netmsg->partCount == 7) {
+                    flib_map *map = flib_map_from_netmsg(netmsg->parts+2);
+                    if(map) {
+                        flib_map_destroy(conn->map);
+                        conn->map = map;
+                        conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_FULL);
+                    } else {
+                        flib_log_e("Error processing CFG FULLMAPCONFIG message");
+                    }
+                } else if(!strcmp(subcmd, "MAP") && netmsg->partCount == 3) {
+                    char *mapname = flib_strdupnull(netmsg->parts[2]);
+                    if(mapname) {
+                        free(conn->map->name);
+                        conn->map->name = mapname;
+                        conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_MAP);
+                    } else {
+                        flib_log_e("Error processing CFG MAP message");
+                    }
+                } else if(!strcmp(subcmd, "THEME") && netmsg->partCount == 3) {
+                    char *themename = flib_strdupnull(netmsg->parts[2]);
+                    if(themename) {
+                        free(conn->map->theme);
+                        conn->map->theme = themename;
+                        conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_THEME);
+                    } else {
+                        flib_log_e("Error processing CFG THEME message");
+                    }
+                } else if(!strcmp(subcmd, "SEED") && netmsg->partCount == 3) {
+                    char *seed = flib_strdupnull(netmsg->parts[2]);
+                    if(seed) {
+                        free(conn->map->seed);
+                        conn->map->seed = seed;
+                        conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_SEED);
+                    } else {
+                        flib_log_e("Error processing CFG SEED message");
+                    }
+                } else if(!strcmp(subcmd, "TEMPLATE") && netmsg->partCount == 3) {
+                    conn->map->templateFilter = atoi(netmsg->parts[2]);
+                    conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_TEMPLATE);
+                } else if(!strcmp(subcmd, "MAPGEN") && netmsg->partCount == 3) {
+                    conn->map->mapgen = atoi(netmsg->parts[2]);
+                    conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_MAPGEN);
+                } else if(!strcmp(subcmd, "MAZE_SIZE") && netmsg->partCount == 3) {
+                    conn->map->mazeSize = atoi(netmsg->parts[2]);
+                    conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_MAZE_SIZE);
+                } else if(!strcmp(subcmd, "DRAWNMAP") && netmsg->partCount == 3) {
+                    size_t drawnMapSize = 0;
+                    uint8_t *drawnMapData = NULL;
+                    if(!flib_drawnmapdata_from_netmsg(netmsg->parts[2], &drawnMapData, &drawnMapSize)) {
+                        free(conn->map->drawData);
+                        conn->map->drawData = drawnMapData;
+                        conn->map->drawDataSize = drawnMapSize;
+                        conn->onMapChangedCb(conn->onMapChangedCtx, conn->map, NETCONN_MAPCHANGE_DRAWNMAP);
+                    } else {
+                        flib_log_e("Error processing CFG DRAWNMAP message");
+                    }
+                } else if(!strcmp(subcmd, "SCRIPT") && netmsg->partCount == 3) {
+                    netconn_setScript(conn, netmsg->parts[2]);
+                    conn->onScriptChangedCb(conn->onScriptChangedCtx, netmsg->parts[2]);
+                } else if(!strcmp(subcmd, "AMMO") && netmsg->partCount == 4) {
+                    flib_weaponset *weapons = flib_weaponset_from_ammostring(netmsg->parts[2], netmsg->parts[3]);
+                    if(weapons) {
+                        flib_weaponset_destroy(conn->weaponset);
+                        conn->weaponset = weapons;
+                        conn->onWeaponsetChangedCb(conn->onWeaponsetChangedCtx, weapons);
+                    } else {
+                        flib_log_e("Error processing CFG AMMO message");
+                    }
+                } else {
+                    flib_log_w("Net: Unknown or malformed CFG subcommand: %s", subcmd);
+                }
+            }
+        } else if (!strcmp(cmd, "HH_NUM")) {
+            if (netmsg->partCount != 3 || conn->netconnState!=NETCONN_STATE_ROOM) {
+                flib_log_w("Net: Bad HH_NUM message");
+            } else {
+                int hogs = atoi(netmsg->parts[2]);
+                if(hogs<=0 || hogs>HEDGEHOGS_PER_TEAM) {
+                    flib_log_w("Net: Bad HH_NUM message: %s hogs", netmsg->parts[2]);
+                } else {
+                    flib_team *team = flib_teamlist_find(&conn->teamlist, netmsg->parts[1]);
+                    if(team) {
+                        team->hogsInGame = hogs;
+                    } else {
+                        flib_log_e("HH_NUM message for unknown team %s", netmsg->parts[1]);
+                    }
+                    conn->onHogCountChangedCb(conn->onHogCountChangedCtx, netmsg->parts[1], hogs);
+                }
+            }
+        } else if (!strcmp(cmd, "TEAM_COLOR")) {
+            if (netmsg->partCount != 3 || conn->netconnState!=NETCONN_STATE_ROOM) {
+                flib_log_w("Net: Bad TEAM_COLOR message");
+            } else {
+                long color;
+                if(sscanf(netmsg->parts[2], "%lu", &color) && color>=0 && color<flib_teamcolor_count) {
+                    flib_team *team = flib_teamlist_find(&conn->teamlist, netmsg->parts[1]);
+                    if(team) {
+                        team->colorIndex = color;
+                    } else {
+                        flib_log_e("TEAM_COLOR message for unknown team %s", netmsg->parts[1]);
+                    }
+                    conn->onTeamColorChangedCb(conn->onTeamColorChangedCtx, netmsg->parts[1], color);
+                } else {
+                    flib_log_w("Net: Bad TEAM_COLOR message: Color %s", netmsg->parts[2]);
+                }
+            }
+        } else if (!strcmp(cmd, "EM")) {
+            if(netmsg->partCount < 2) {
+                flib_log_w("Net: Bad EM message");
+            } else {
+                for(int i = 1; i < netmsg->partCount; ++i) {
+                    char *out = NULL;
+                    size_t outlen;
+                    bool ok = base64_decode_alloc(netmsg->parts[i], strlen(netmsg->parts[i]), &out, &outlen);
+                    if(ok && outlen) {
+                        conn->onEngineMessageCb(conn->onEngineMessageCtx, (uint8_t*)out, outlen);
+                    } else {
+                        flib_log_e("Net: Malformed engine message: %s", netmsg->parts[i]);
+                    }
+                    free(out);
+                }
+            }
+        } else if (!strcmp(cmd, "BYE")) {
+            if (netmsg->partCount < 2) {
+                flib_log_w("Net: Bad BYE message");
+            } else {
+                conn->netconnState = NETCONN_STATE_DISCONNECTED;
+                if (!strcmp(netmsg->parts[1], "Authentication failed")) {
+                    conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_AUTH_FAILED, netmsg->parts[1]);
+                } else {
+                    conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_NORMAL, netmsg->parts[1]);
+                }
+                exit = true;
+            }
+        } else if (!strcmp(cmd, "ADMIN_ACCESS")) {
+            // deprecated
+        } else if (!strcmp(cmd, "ROOM_CONTROL_ACCESS")) {
+            // deprecated
+        } else {
+            flib_log_w("Unknown server command: %s", cmd);
+        }
+        flib_netmsg_destroy(netmsg);
+    }
+
+    if(!exit && !conn->destroyRequested && !flib_netbase_connected(net)) {
+        conn->netconnState = NETCONN_STATE_DISCONNECTED;
+        conn->onDisconnectedCb(conn->onDisconnectedCtx, NETCONN_DISCONNECT_CONNLOST, "Connection lost");
+    }
+}
+
+void flib_netconn_tick(flib_netconn *conn) {
+    if(!log_badargs_if(conn==NULL)
+            && !log_w_if(conn->running, "Call to flib_netconn_tick from a callback")
+            && !log_w_if(conn->netconnState == NETCONN_STATE_DISCONNECTED, "We are already done.")) {
+        conn->running = true;
+        flib_netconn_wrappedtick(conn);
+        conn->running = false;
+
+        if(conn->destroyRequested) {
+            flib_netconn_destroy(conn);
+        }
+    }
+}
--- a/project_files/frontlib/net/netconn.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netconn.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,654 +1,654 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * This file contains functions for communicating with a Hedgewars server to chat, prepare and play
- * rounds of Hedgewars.
- *
- * To use this, first create a netconn object by calling flib_netconn_create. This will start the
- * connection to the game server (which might fail right away, the function returns null then). You
- * should also register your callback functions right at the start to ensure you don't miss any
- * callbacks.
- *
- * In order to allow the netconn to run, you should regularly call flib_netconn_tick(), which
- * performs network I/O and calls your callbacks on interesting events.
- *
- * When the connection is closed, you will receive the onDisconnect callback. This is the signal to
- * destroy the netconn and stop calling tick().
- *
- * The connection process lasts from the time you create the netconn until you receive the
- * onConnected callback (or onDisconnected in case something goes wrong). During that time, you
- * might receive the onNickTaken and onPasswordRequest callbacks; see their description for more
- * information on how to handle them. You could also receive other callbacks during connecting (e.g.
- * about the room list), but it should be safe to ignore them.
- *
- * Once you are connected, you are in the lobby, and you can enter rooms and leave them again. The
- * room and lobby states have different protocols, so many commands only work in either one or the
- * other. If you are in a room you might also be in a game, but most of the functions behave the
- * same ingame as in a room.
- *
- * The state changes from lobby to room when the server tells you that you just entered one, which
- * will also trigger the onEnterRoom callback. This usually happens in reply to either a joinRoom,
- * createRoom or playerFollow command.
- *
- * The state changes back to lobby when the room is dissolved, when you are kicked from the room, or
- * when you actively leave the room using flib_netconn_send_leaveRoom. The first two events will
- * trigger the onLeaveRoom callback.
- */
-
-#ifndef NETCONN_H_
-#define NETCONN_H_
-
-#include "../model/gamesetup.h"
-#include "../model/scheme.h"
-#include "../model/room.h"
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#define NETCONN_STATE_CONNECTING 0
-#define NETCONN_STATE_LOBBY 1
-#define NETCONN_STATE_ROOM 2
-#define NETCONN_STATE_DISCONNECTED 10
-
-#define NETCONN_DISCONNECT_NORMAL 0				//!< The connection was closed normally
-#define NETCONN_DISCONNECT_SERVER_TOO_OLD 1		//!< The server has a lower protocol version than we do
-#define NETCONN_DISCONNECT_AUTH_FAILED 2		//!< You sent a password with flib_netconn_send_password that was not accepted
-#define NETCONN_DISCONNECT_CONNLOST 3			//!< The network connection was lost
-#define NETCONN_DISCONNECT_INTERNAL_ERROR 100	//!< Something went wrong in frontlib itself
-
-#define NETCONN_ROOMLEAVE_ABANDONED 0			//!< The room was closed because the chief left
-#define NETCONN_ROOMLEAVE_KICKED 1				//!< You have been kicked from the room
-
-#define NETCONN_MSG_TYPE_PLAYERINFO 0			//!< A response to flib_netconn_send_playerInfo
-#define NETCONN_MSG_TYPE_SERVERMESSAGE 1		//!< The welcome message when connecting to the lobby
-#define NETCONN_MSG_TYPE_WARNING 2				//!< A general warning message
-#define NETCONN_MSG_TYPE_ERROR 3				//!< A general error message
-
-#define NETCONN_MAPCHANGE_FULL 0
-#define NETCONN_MAPCHANGE_MAP 1
-#define NETCONN_MAPCHANGE_MAPGEN 2
-#define NETCONN_MAPCHANGE_DRAWNMAP 3
-#define NETCONN_MAPCHANGE_MAZE_SIZE 4
-#define NETCONN_MAPCHANGE_TEMPLATE 5
-#define NETCONN_MAPCHANGE_THEME 6
-#define NETCONN_MAPCHANGE_SEED 7
-
-typedef struct _flib_netconn flib_netconn;
-
-/**
- * Create a new netplay connection with these parameters.
- * The path to the data directory must end with a path delimiter (e.g. C:\Games\Hedgewars\Data\)
- */
-flib_netconn *flib_netconn_create(const char *playerName, const char *dataDirPath, const char *host, int port);
-void flib_netconn_destroy(flib_netconn *conn);
-
-/**
- * Perform I/O operations and call callbacks if something interesting happens.
- * Should be called regularly.
- */
-void flib_netconn_tick(flib_netconn *conn);
-
-/**
- * Are you currently the owner of this room? The return value only makes sense in
- * NETCONN_STATE_ROOM and NETCONN_STATE_INGAME states.
- */
-bool flib_netconn_is_chief(flib_netconn *conn);
-
-/**
- * Returns the playername. This is *probably* the one provided on creation, but if that name was
- * already taken, a different one could have been set by the onNickTaken callback or its default
- * implementation.
- */
-const char *flib_netconn_get_playername(flib_netconn *conn);
-
-/**
- * Generate a game setup from the current room state.
- * Returns NULL if the room state does not contain enough information for a complete game setup,
- * or if an error occurs.
- *
- * The new gamesetup must be destroyed with flib_gamesetup_destroy().
- */
-flib_gamesetup *flib_netconn_create_gamesetup(flib_netconn *conn);
-
-
-
-
-// Send functions needed when connecting and disconnecting
-
-	/**
-	 * Request a different nickname.
-	 * This function only makes sense in reaction to an onNickTaken callback, because the netconn
-	 * automatically requests the nickname you provide on creation, and once the server accepts the
-	 * nickname it can no longer be changed.
-	 */
-	int flib_netconn_send_nick(flib_netconn *conn, const char *nick);
-
-	/**
-	 * Send the password in reply to a password request.
-	 * If the server does not accept the password, you will be disconnected
-	 * (NETCONN_DISCONNECT_AUTH_FAILED)
-	 */
-	int flib_netconn_send_password(flib_netconn *conn, const char *passwd);
-
-	/**
-	 * Tell the server that you want to leave. If successful, the server will disconnect you.
-	 */
-	int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg);
-
-
-// Send functions that make sense both in the lobby and in rooms
-
-	/**
-	 * Send a chat message. This message is either sent to the lobby or the room, depending on
-	 * whether you are in a room at the moment. The message is not echoed back to you.
-	 */
-	int flib_netconn_send_chat(flib_netconn *conn, const char *chat);
-
-	/**
-	 * Kick a player. This has different meanings in the lobby and in a room;
-	 * In the lobby, it will kick the player from the server, and you need to be a server admin to
-	 * do it. In a room, it will kick the player from the room, and you need to be room chief.
-	 */
-	int flib_netconn_send_kick(flib_netconn *conn, const char *playerName);
-
-	/**
-	 * Request information about a player (e.g. current room, version, partial IP). If the action
-	 * succeeds, you will receive an onMessage callback with NETCONN_MSG_TYPE_PLAYERINFO containing
-	 * the requested information.
-	 */
-	int flib_netconn_send_playerInfo(flib_netconn *conn, const char *playerName);
-
-
-// Send functions that only make sense in the lobby
-
-	/**
-	 * Request an update of the room list. Only makes sense when in lobby state.
-	 * If the action succeeds, you will receive an onRoomlist callback containing the current room
-	 * data.
-	 */
-	int flib_netconn_send_request_roomlist(flib_netconn *conn);
-
-	/**
-	 * Join a room as guest (not chief). Only makes sense when in lobby state. If the action
-	 * succeeds, you will receive an onEnterRoom callback with chief=false followed by other
-	 * callbacks with current room information.
-	 */
-	int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room);
-
-	/**
-	 * Follow a player. Only valid in the lobby. If the player is in a room (or in a game), this
-	 * command is analogous to calling flib_netconn_send_joinRoom with that room.
-	 */
-	int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName);
-
-	/**
-	 * Create and join a new room. Only makes sense when in lobby state. If the action succeeds,
-	 * you will receive an onEnterRoom callback with chief=true.
-	 */
-	int flib_netconn_send_createRoom(flib_netconn *conn, const char *room);
-
-	/**
-	 * Ban a player. The scope of this ban depends on whether you are in a room or in the lobby.
-	 * In a room, you need to be the room chief, and the ban will apply to the room only. In the
-	 * lobby, you need to be server admin to ban someone, and the ban applies to the entire server.
-	 */
-	int flib_netconn_send_ban(flib_netconn *conn, const char *playerName);
-
-	/**
-	 * Does something administrator-y. At any rate you need to be an administrator and in the lobby
-	 * to use this command.
-	 */
-	int flib_netconn_send_clearAccountsCache(flib_netconn *conn);
-
-	/**
-	 * Sets a server variable to the indicated value. Only makes sense if you are server admin and
-	 * in the lobby. Known variables are MOTD_NEW, MOTD_OLD and LATEST_PROTO. MOTD_OLD is shown to
-	 * players with older protocol versions, to inform them that they might want to update.
-	 */
-	int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value);
-
-	/**
-	 * Queries all server variables. Only makes sense if you are server admin and in the lobby.
-	 * If the action succeeds, you will receive several onServerVar callbacks with the
-	 * current values of all server variables.
-	 */
-	int flib_netconn_send_getServerVars(flib_netconn *conn);
-
-
-// Send functions that only make sense in a room
-
-	/**
-	 * Leave the room for the lobby. Only makes sense in room state. msg can be NULL if you don't
-	 * want to send a message. The server always accepts a part command, so once you send it off,
-	 * you can just assume that you are back in the lobby.
-	 */
-	int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *msg);
-
-	/**
-	 * Change your "ready" status in the room. Only makes sense when in room state. If the action
-	 * succeeds, you will receive an onClientFlags callback containing the change.
-	 */
-	int flib_netconn_send_toggleReady(flib_netconn *conn);
-
-	/**
-	 * Add a team to the current room. Apart from the "fixed" team information, this also includes
-	 * the color, but not the number of hogs. Only makes sense when in room state. If the action
-	 * succeeds, you will receive an onTeamAccepted callback with the name of the team.
-	 *
-	 * Notes: Technically, sending a color here is the only way for a non-chief to set the color of
-	 * her own team. The server remembers this color and even generates a separate teamColor message
-	 * to inform everyone of it. However, at the moment the frontends generally override this color
-	 * with one they choose themselves in order to deal with unfortunate behavior of the QtFrontend,
-	 * which always sends color index 0 when adding a team but thinks that the team has a random
-	 * color. The chief always sends a new color in order to bring the QtFrontend back into sync.
-	 */
-	int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team);
-
-	/**
-	 * Remove the team with the name teamname. Only makes sense when in room state.
-	 * The server does not send a reply on success.
-	 */
-	int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname);
-
-
-// Send functions that only make sense in a room and if you are room chief
-
-	/**
-	 * Rename the current room. Only makes sense in room state and if you are chief. If the action
-	 * succeeds, you (and everyone else on the server) will receive an onRoomUpdate message
-	 * containing the change.
-	 */
-	int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName);
-
-	/**
-	 * Set the number of hogs for a team. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount);
-
-	/**
-	 * Set the teamcolor of a team. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex);
-
-	/**
-	 * Set the weaponset for the room. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset);
-
-	/**
-	 * Set the map for the room. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_map(flib_netconn *conn, const flib_map *map);
-
-	/**
-	 * Set the mapname. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName);
-
-	/**
-	 * Set the map generator (regular, maze, drawn, named). Only makes sense in room state and if
-	 * you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen);
-
-	/**
-	 * Set the map template for regular maps. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter);
-
-	/**
-	 * Set the maze template (maze size) for mazes. Only makes sense in room state and if you are
-	 * chief. The server does not send a reply.
-	 */
-	int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize);
-
-	/**
-	 * Set the seed for the map. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed);
-
-	/**
-	 * Set the theme for the map. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme);
-
-	/**
-	 * Set the draw data for the drawn map. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size);
-
-	/**
-	 * Set the script (game style). Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_script(flib_netconn *conn, const char *scriptName);
-
-	/**
-	 * Set the scheme. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme);
-
-	/**
-	 * Signal that you want to start the game. Only makes sense in room state and if you are chief.
-	 * The server will check whether all players are ready and whether it believes the setup makes
-	 * sense (e.g. more than one clan). If the server is satisfied, you will receive an onRunGame
-	 * callback (all other clients in the room are notified the same way). Otherwise the server
-	 * might answer with a warning, or might not answer at all.
-	 */
-	int flib_netconn_send_startGame(flib_netconn *conn);
-
-	/**
-	 * Allow/forbid players to join the room. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_toggleRestrictJoins(flib_netconn *conn);
-
-	/**
-	 * Allow/forbid adding teams to the room. Only makes sense in room state and if you are chief.
-	 * The server does not send a reply.
-	 */
-	int flib_netconn_send_toggleRestrictTeams(flib_netconn *conn);
-
-
-// Send functions that are only needed for running a game
-
-	/**
-	 * Send a teamchat message, forwarded from the engine. Only makes sense ingame.
-	 * The server does not send a reply. In contrast to a Chat message, the server
-	 * automatically converts this into an engine message and passes it on to the other
-	 * clients.
-	 */
-	int flib_netconn_send_teamchat(flib_netconn *conn, const char *msg);
-
-	/**
-	 * Send an engine message. Only makes sense when ingame. In a networked game, you have to pass
-	 * all the engine messages from the engine here, and they will be spread to all other clients
-	 * in the game to keep the game in sync.
-	 */
-	int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size);
-
-	/**
-	 * Inform the server that the round has ended. Call this when the engine has disconnected,
-	 * passing 1 if the round ended normally, 0 otherwise.
-	 */
-	int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError);
-
-
-
-
-
-// Callbacks that are important for connecting/disconnecting
-
-	/**
-	 * onNickTaken is called when connecting to the server, if it turns out that there is already a
-	 * player with the same nick.
-	 * In order to proceed, a new nickname needs to be sent to the server using
-	 * flib_netconn_send_nick() (or of course you can bail out and send a QUIT).
-	 * If you don't set a callback, the netconn will automatically react by generating a new name.
-	 */
-	void flib_netconn_onNickTaken(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
-
-	/**
-	 * When connecting with a registered nickname, the server will ask for a password before
-	 * admitting you in. This callback is called when that happens. As a reaction, you can send the
-	 * password using flib_netconn_send_password. If you don't register a callback, the default
-	 * behavior is to just quit in a way that will cause a disconnect with
-	 * NETCONN_DISCONNECT_AUTH_FAILED.
-	 *
-	 * You can't just choose a new nickname when you receive this callback, because at that point
-	 * the server has already accepted your nick.
-	 */
-	void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
-
-	/**
-	 * This is called when the server has accepted our nickname (and possibly password) and we have
-	 * entered the lobby.
-	 */
-	void flib_netconn_onConnected(flib_netconn *conn, void (*callback)(void *context), void* context);
-
-	/**
-	 * This is always the last callback (unless the netconn is destroyed early), and the netconn
-	 * should be destroyed when it is received. The reason for the disconnect is passed as one of
-	 * the NETCONN_DISCONNECT_ constants. Sometimes a message is included as well, but that
-	 * parameter might also be NULL.
-	 */
-	void flib_netconn_onDisconnected(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void* context);
-
-
-// Callbacks that make sense in most situations
-
-	/**
-	 * Callback for several informational messages that should be displayed to the user
-	 * (e.g. in the chat window), but do not require a reaction. If a game is running, you might
-	 * want to redirect some of these messages to the engine as well so the user will see them.
-	 */
-	void flib_netconn_onMessage(flib_netconn *conn, void (*callback)(void *context, int msgtype, const char *msg), void* context);
-
-	/**
-	 * We received a chat message. Where this message belongs depends on the current state
-	 * (lobby/room). If a game is running the message should be passed to the engine.
-	 */
-	void flib_netconn_onChat(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *msg), void* context);
-
-	/**
-	 * Callbacks for incremental room list updates. They will fire whenever these events occur,
-	 * even before you first query the actual roomlist - so be sure not to blindly reference your
-	 * room list in these callbacks. The server currently only sends updates when a room changes
-	 * its name, so in order to update other room information you need to query the roomlist again
-	 * (see send_request_roomlist / onRoomlist).
-	 */
-	void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_room *room), void* context);
-	void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context);
-	void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_room *room), void* context);
-
-	/**
-	 * Callbacks for players joining or leaving the lobby. In contrast to the roomlist updates, you
-	 * will get a JOIN callback for every player already on the server when you join (and there is
-	 * no direct way to query the current playerlist)
-	 *
-	 * NOTE: partMessage may be NULL.
-	 */
-	void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
-	void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context);
-
-	/**
-	 * This is called when the server informs us that one or more flags associated with a
-	 * player/client have changed.
-	 *
-	 * nick is the name of the player, flags is a string containing one character for each modified
-	 * flag (see below), and newFlagState signals whether the flags should be set to true or false.
-	 *
-	 * Some of these flags are important for protocol purposes (especially if they are set for you)
-	 * while others are just informational. Also, some flags are only relevant for players who are
-	 * in the same room as you, and the server will not inform you if they change for others.
-	 *
-	 * These are the currently known/used flags:
-	 * a: Server admin. Always updated.
-	 * h: Room chief. Updated when in the same room.
-	 * r: Ready to play. Updated when in the same room.
-	 * u: Registered user. Always updated.
-	 *
-	 * The server tells us the 'a' and 'u' flags for all players when we first join the lobby, and
-	 * also tells us the 'r' and 'h' flags when we join or create a room. It assumes that all flags
-	 * are initially false, so it will typically only tell you to set certain flags to true when
-	 * transmitting the initial states. Reset the 'h' and 'r' flags to false when leaving a room,
-	 * or when entering room state, to arrive at the right state for each player.
-	 *
-	 * The room chief state of yourself is particularly important because it determines whether you
-	 * can modify settings of the current room. Generally, when you create a room you start out
-	 * being room chief, and when you join an existing room you are not. However, if the original
-	 * chief leaves a room, the server can choose a new chief, and if that happens the chief flag
-	 * will be transferred to someone else.
-	 */
-	void flib_netconn_onClientFlags(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *flags, bool newFlagState), void *context);
-
-// Callbacks that happen only in response to specific requests
-
-	/**
-	 * Response to flib_netconn_send_request_roomlist().
-	 * The rooms array contains the current state of all rooms on the server.
-	 */
-	void flib_netconn_onRoomlist(flib_netconn *conn, void (*callback)(void *context, const flib_room **rooms, int roomCount), void* context);
-
-	/**
-	 * Response to flib_netconn_send_joinRoom, flib_netconn_send_playerFollow or
-	 * flib_netconn_send_createRoom.
-	 *
-	 * You just left the lobby and entered a room.
-	 * If chief is true, you can and should send a full configuration for the room now. This
-	 * consists of ammo, scheme, script and map, where map apparently has to come last.
-	 */
-	void flib_netconn_onEnterRoom(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context);
-
-	/**
-	 * Response to flib_netconn_send_addTeam.
-	 * The server might reject your team for several reasons, e.g. because it has the same name as
-	 * an existing team, or because the room chief restricted adding new teams. If the team is
-	 * accepted by the server, this callback is fired.
-	 *
-	 * If you are the room chief, you are expected to provide the hog count for your own team now
-	 * using flib_netconn_send_teamHogCount. The color of the team is already set to the one you
-	 * provided in addTeam.
-	 */
-	void flib_netconn_onTeamAccepted(flib_netconn *conn, void (*callback)(void *context, const char *team), void *context);
-
-	/**
-	 * When you query the server vars with flib_netconn_send_getServerVars (only works as admin),
-	 * the server replies with a list of them. This callback is called for each entry in that list.
-	 */
-	void flib_netconn_onServerVar(flib_netconn *conn, void (*callback)(void *context, const char *name, const char *value), void *context);
-
-
-// Callbacks that are only relevant in a room
-
-	/**
-	 * You just left a room and entered the lobby again.
-	 * reason is one of the NETCONN_ROOMLEAVE_ constants (usually a kick).
-	 * This will not be called when you actively leave a room using PART.
-	 * Don't confuse with onRoomLeave, which indicates that *someone else* left the room.
-	 */
-	void flib_netconn_onLeaveRoom(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void *context);
-
-	/**
-	 * Someone joined or left the room you are currently in.
-	 * Analogous to onLobbyJoin/leave, you will receive the join callback for all players that are
-	 * already in the room when you join, including for yourself (this is actually how it is
-	 * determined that you joined a room).
-	 *
-	 * However, you will *not* receive onRoomLeave messages for everyone when you leave the room.
-	 */
-	void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
-	void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context);
-
-	/**
-	 * A new team was added to the room. The person who adds a team does NOT receive this callback
-	 * (he gets onTeamAccepted instead).
-	 *
-	 * The team does not contain bindings, stats, weaponset, color or the number of hogs (but it is
-	 * assumed to be the default of 4).
-	 *
-	 * If you receive this message and you are the room chief, you may want to send a color and hog
-	 * count for this team using flib_netconn_send_teamHogCount / teamColor for QtFrontend
-	 * compatibility.
-	 *
-	 * The server currently sends another message with the color of the team to the same recipients
-	 * as this teamAdd message, which will trigger an onTeamColorChanged callback. See the
-	 * description of flib_netconn_send_addTeam for more information.
-	 */
-	void flib_netconn_onTeamAdd(flib_netconn *conn, void (*callback)(void *context, const flib_team *team), void *context);
-
-	/**
-	 * A team was removed from the room. The person who removed the team will not receive this
-	 * callback.
-	 */
-	void flib_netconn_onTeamDelete(flib_netconn *conn, void (*callback)(void *context, const char *teamname), void *context);
-
-	/**
-	 * The number of hogs in a team has been changed by the room chief. If you are the chief and
-	 * change the number of hogs yourself, you will not receive this callback.
-	 */
-	void flib_netconn_onHogCountChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int hogs), void *context);
-
-	/**
-	 * The color of a team has been set or changed. The client who set or changed the color will
-	 * not receive this callback.
-	 *
-	 * Normally, only the chief can change the color of a team. However, this message is also
-	 * generated when a team is added, so you can receive it even as chief.
-	 */
-	void flib_netconn_onTeamColorChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int colorIndex), void *context);
-
-	/**
-	 * The room chief has changed the game scheme (or you just joined a room).
-	 * You will not receive this callback if you changed the scheme yourself.
-	 */
-	void flib_netconn_onSchemeChanged(flib_netconn *conn, void (*callback)(void *context, const flib_scheme *scheme), void *context);
-
-	/**
-	 * The room chief has changed the map (or you just joined a room). Only non-chiefs receive these
-	 * messages.
-	 *
-	 * To reduce the number of callback functions, the netconn keeps track of the current map
-	 * settings and always passes the entire current map config, but informs the callee about what
-	 * has changed (see the NETCONN_MAPCHANGE_ constants).
-	 *
-	 * Caution: Due to the way the protocol works, the map might not be complete at this point if it
-	 * is a hand-drawn map, because the "full" map config does not include the drawn map data.
-	 */
-	void flib_netconn_onMapChanged(flib_netconn *conn, void (*callback)(void *context, const flib_map *map, int changetype), void *context);
-
-	/**
-	 * The room chief has changed the game style (or you just joined a room). If you are the chief
-	 * and change the style yourself, you will not receive this callback.
-	 */
-	void flib_netconn_onScriptChanged(flib_netconn *conn, void (*callback)(void *context, const char *script), void *context);
-
-	/**
-	 * The room chief has changed the weaponset (or you just joined a room). If you are the chief
-	 * and change the weaponset yourself, you will not receive this callback.
-	 */
-	void flib_netconn_onWeaponsetChanged(flib_netconn *conn, void (*callback)(void *context, const flib_weaponset *weaponset), void *context);
-
-	/**
-	 * The game is starting. Fire up the engine and join in!
-	 * You can let the netconn generate the right game setup using flib_netconn_create_gamesetup
-	 */
-	void flib_netconn_onRunGame(flib_netconn *conn, void (*callback)(void *context), void *context);
-
-	/**
-	 * You are in a room, a game is in progress, and the server is sending you the new input for the
-	 * engine to keep up to date with the current happenings. Pass it on to the engine using
-	 * flib_gameconn_send_enginemsg.
-	 */
-	void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const uint8_t *message, size_t size), void *context);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * This file contains functions for communicating with a Hedgewars server to chat, prepare and play
+ * rounds of Hedgewars.
+ *
+ * To use this, first create a netconn object by calling flib_netconn_create. This will start the
+ * connection to the game server (which might fail right away, the function returns null then). You
+ * should also register your callback functions right at the start to ensure you don't miss any
+ * callbacks.
+ *
+ * In order to allow the netconn to run, you should regularly call flib_netconn_tick(), which
+ * performs network I/O and calls your callbacks on interesting events.
+ *
+ * When the connection is closed, you will receive the onDisconnect callback. This is the signal to
+ * destroy the netconn and stop calling tick().
+ *
+ * The connection process lasts from the time you create the netconn until you receive the
+ * onConnected callback (or onDisconnected in case something goes wrong). During that time, you
+ * might receive the onNickTaken and onPasswordRequest callbacks; see their description for more
+ * information on how to handle them. You could also receive other callbacks during connecting (e.g.
+ * about the room list), but it should be safe to ignore them.
+ *
+ * Once you are connected, you are in the lobby, and you can enter rooms and leave them again. The
+ * room and lobby states have different protocols, so many commands only work in either one or the
+ * other. If you are in a room you might also be in a game, but most of the functions behave the
+ * same ingame as in a room.
+ *
+ * The state changes from lobby to room when the server tells you that you just entered one, which
+ * will also trigger the onEnterRoom callback. This usually happens in reply to either a joinRoom,
+ * createRoom or playerFollow command.
+ *
+ * The state changes back to lobby when the room is dissolved, when you are kicked from the room, or
+ * when you actively leave the room using flib_netconn_send_leaveRoom. The first two events will
+ * trigger the onLeaveRoom callback.
+ */
+
+#ifndef NETCONN_H_
+#define NETCONN_H_
+
+#include "../model/gamesetup.h"
+#include "../model/scheme.h"
+#include "../model/room.h"
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#define NETCONN_STATE_CONNECTING 0
+#define NETCONN_STATE_LOBBY 1
+#define NETCONN_STATE_ROOM 2
+#define NETCONN_STATE_DISCONNECTED 10
+
+#define NETCONN_DISCONNECT_NORMAL 0             //!< The connection was closed normally
+#define NETCONN_DISCONNECT_SERVER_TOO_OLD 1     //!< The server has a lower protocol version than we do
+#define NETCONN_DISCONNECT_AUTH_FAILED 2        //!< You sent a password with flib_netconn_send_password that was not accepted
+#define NETCONN_DISCONNECT_CONNLOST 3           //!< The network connection was lost
+#define NETCONN_DISCONNECT_INTERNAL_ERROR 100   //!< Something went wrong in frontlib itself
+
+#define NETCONN_ROOMLEAVE_ABANDONED 0           //!< The room was closed because the chief left
+#define NETCONN_ROOMLEAVE_KICKED 1              //!< You have been kicked from the room
+
+#define NETCONN_MSG_TYPE_PLAYERINFO 0           //!< A response to flib_netconn_send_playerInfo
+#define NETCONN_MSG_TYPE_SERVERMESSAGE 1        //!< The welcome message when connecting to the lobby
+#define NETCONN_MSG_TYPE_WARNING 2              //!< A general warning message
+#define NETCONN_MSG_TYPE_ERROR 3                //!< A general error message
+
+#define NETCONN_MAPCHANGE_FULL 0
+#define NETCONN_MAPCHANGE_MAP 1
+#define NETCONN_MAPCHANGE_MAPGEN 2
+#define NETCONN_MAPCHANGE_DRAWNMAP 3
+#define NETCONN_MAPCHANGE_MAZE_SIZE 4
+#define NETCONN_MAPCHANGE_TEMPLATE 5
+#define NETCONN_MAPCHANGE_THEME 6
+#define NETCONN_MAPCHANGE_SEED 7
+
+typedef struct _flib_netconn flib_netconn;
+
+/**
+ * Create a new netplay connection with these parameters.
+ * The path to the data directory must end with a path delimiter (e.g. C:\Games\Hedgewars\Data\)
+ */
+flib_netconn *flib_netconn_create(const char *playerName, const char *dataDirPath, const char *host, int port);
+void flib_netconn_destroy(flib_netconn *conn);
+
+/**
+ * Perform I/O operations and call callbacks if something interesting happens.
+ * Should be called regularly.
+ */
+void flib_netconn_tick(flib_netconn *conn);
+
+/**
+ * Are you currently the owner of this room? The return value only makes sense in
+ * NETCONN_STATE_ROOM and NETCONN_STATE_INGAME states.
+ */
+bool flib_netconn_is_chief(flib_netconn *conn);
+
+/**
+ * Returns the playername. This is *probably* the one provided on creation, but if that name was
+ * already taken, a different one could have been set by the onNickTaken callback or its default
+ * implementation.
+ */
+const char *flib_netconn_get_playername(flib_netconn *conn);
+
+/**
+ * Generate a game setup from the current room state.
+ * Returns NULL if the room state does not contain enough information for a complete game setup,
+ * or if an error occurs.
+ *
+ * The new gamesetup must be destroyed with flib_gamesetup_destroy().
+ */
+flib_gamesetup *flib_netconn_create_gamesetup(flib_netconn *conn);
+
+
+
+
+// Send functions needed when connecting and disconnecting
+
+    /**
+     * Request a different nickname.
+     * This function only makes sense in reaction to an onNickTaken callback, because the netconn
+     * automatically requests the nickname you provide on creation, and once the server accepts the
+     * nickname it can no longer be changed.
+     */
+    int flib_netconn_send_nick(flib_netconn *conn, const char *nick);
+
+    /**
+     * Send the password in reply to a password request.
+     * If the server does not accept the password, you will be disconnected
+     * (NETCONN_DISCONNECT_AUTH_FAILED)
+     */
+    int flib_netconn_send_password(flib_netconn *conn, const char *passwd);
+
+    /**
+     * Tell the server that you want to leave. If successful, the server will disconnect you.
+     */
+    int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg);
+
+
+// Send functions that make sense both in the lobby and in rooms
+
+    /**
+     * Send a chat message. This message is either sent to the lobby or the room, depending on
+     * whether you are in a room at the moment. The message is not echoed back to you.
+     */
+    int flib_netconn_send_chat(flib_netconn *conn, const char *chat);
+
+    /**
+     * Kick a player. This has different meanings in the lobby and in a room;
+     * In the lobby, it will kick the player from the server, and you need to be a server admin to
+     * do it. In a room, it will kick the player from the room, and you need to be room chief.
+     */
+    int flib_netconn_send_kick(flib_netconn *conn, const char *playerName);
+
+    /**
+     * Request information about a player (e.g. current room, version, partial IP). If the action
+     * succeeds, you will receive an onMessage callback with NETCONN_MSG_TYPE_PLAYERINFO containing
+     * the requested information.
+     */
+    int flib_netconn_send_playerInfo(flib_netconn *conn, const char *playerName);
+
+
+// Send functions that only make sense in the lobby
+
+    /**
+     * Request an update of the room list. Only makes sense when in lobby state.
+     * If the action succeeds, you will receive an onRoomlist callback containing the current room
+     * data.
+     */
+    int flib_netconn_send_request_roomlist(flib_netconn *conn);
+
+    /**
+     * Join a room as guest (not chief). Only makes sense when in lobby state. If the action
+     * succeeds, you will receive an onEnterRoom callback with chief=false followed by other
+     * callbacks with current room information.
+     */
+    int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room);
+
+    /**
+     * Follow a player. Only valid in the lobby. If the player is in a room (or in a game), this
+     * command is analogous to calling flib_netconn_send_joinRoom with that room.
+     */
+    int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName);
+
+    /**
+     * Create and join a new room. Only makes sense when in lobby state. If the action succeeds,
+     * you will receive an onEnterRoom callback with chief=true.
+     */
+    int flib_netconn_send_createRoom(flib_netconn *conn, const char *room);
+
+    /**
+     * Ban a player. The scope of this ban depends on whether you are in a room or in the lobby.
+     * In a room, you need to be the room chief, and the ban will apply to the room only. In the
+     * lobby, you need to be server admin to ban someone, and the ban applies to the entire server.
+     */
+    int flib_netconn_send_ban(flib_netconn *conn, const char *playerName);
+
+    /**
+     * Does something administrator-y. At any rate you need to be an administrator and in the lobby
+     * to use this command.
+     */
+    int flib_netconn_send_clearAccountsCache(flib_netconn *conn);
+
+    /**
+     * Sets a server variable to the indicated value. Only makes sense if you are server admin and
+     * in the lobby. Known variables are MOTD_NEW, MOTD_OLD and LATEST_PROTO. MOTD_OLD is shown to
+     * players with older protocol versions, to inform them that they might want to update.
+     */
+    int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value);
+
+    /**
+     * Queries all server variables. Only makes sense if you are server admin and in the lobby.
+     * If the action succeeds, you will receive several onServerVar callbacks with the
+     * current values of all server variables.
+     */
+    int flib_netconn_send_getServerVars(flib_netconn *conn);
+
+
+// Send functions that only make sense in a room
+
+    /**
+     * Leave the room for the lobby. Only makes sense in room state. msg can be NULL if you don't
+     * want to send a message. The server always accepts a part command, so once you send it off,
+     * you can just assume that you are back in the lobby.
+     */
+    int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *msg);
+
+    /**
+     * Change your "ready" status in the room. Only makes sense when in room state. If the action
+     * succeeds, you will receive an onClientFlags callback containing the change.
+     */
+    int flib_netconn_send_toggleReady(flib_netconn *conn);
+
+    /**
+     * Add a team to the current room. Apart from the "fixed" team information, this also includes
+     * the color, but not the number of hogs. Only makes sense when in room state. If the action
+     * succeeds, you will receive an onTeamAccepted callback with the name of the team.
+     *
+     * Notes: Technically, sending a color here is the only way for a non-chief to set the color of
+     * her own team. The server remembers this color and even generates a separate teamColor message
+     * to inform everyone of it. However, at the moment the frontends generally override this color
+     * with one they choose themselves in order to deal with unfortunate behavior of the QtFrontend,
+     * which always sends color index 0 when adding a team but thinks that the team has a random
+     * color. The chief always sends a new color in order to bring the QtFrontend back into sync.
+     */
+    int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team);
+
+    /**
+     * Remove the team with the name teamname. Only makes sense when in room state.
+     * The server does not send a reply on success.
+     */
+    int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname);
+
+
+// Send functions that only make sense in a room and if you are room chief
+
+    /**
+     * Rename the current room. Only makes sense in room state and if you are chief. If the action
+     * succeeds, you (and everyone else on the server) will receive an onRoomUpdate message
+     * containing the change.
+     */
+    int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName);
+
+    /**
+     * Set the number of hogs for a team. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount);
+
+    /**
+     * Set the teamcolor of a team. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex);
+
+    /**
+     * Set the weaponset for the room. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset);
+
+    /**
+     * Set the map for the room. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_map(flib_netconn *conn, const flib_map *map);
+
+    /**
+     * Set the mapname. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName);
+
+    /**
+     * Set the map generator (regular, maze, drawn, named). Only makes sense in room state and if
+     * you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen);
+
+    /**
+     * Set the map template for regular maps. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter);
+
+    /**
+     * Set the maze template (maze size) for mazes. Only makes sense in room state and if you are
+     * chief. The server does not send a reply.
+     */
+    int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize);
+
+    /**
+     * Set the seed for the map. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed);
+
+    /**
+     * Set the theme for the map. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme);
+
+    /**
+     * Set the draw data for the drawn map. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size);
+
+    /**
+     * Set the script (game style). Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_script(flib_netconn *conn, const char *scriptName);
+
+    /**
+     * Set the scheme. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme);
+
+    /**
+     * Signal that you want to start the game. Only makes sense in room state and if you are chief.
+     * The server will check whether all players are ready and whether it believes the setup makes
+     * sense (e.g. more than one clan). If the server is satisfied, you will receive an onRunGame
+     * callback (all other clients in the room are notified the same way). Otherwise the server
+     * might answer with a warning, or might not answer at all.
+     */
+    int flib_netconn_send_startGame(flib_netconn *conn);
+
+    /**
+     * Allow/forbid players to join the room. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_toggleRestrictJoins(flib_netconn *conn);
+
+    /**
+     * Allow/forbid adding teams to the room. Only makes sense in room state and if you are chief.
+     * The server does not send a reply.
+     */
+    int flib_netconn_send_toggleRestrictTeams(flib_netconn *conn);
+
+
+// Send functions that are only needed for running a game
+
+    /**
+     * Send a teamchat message, forwarded from the engine. Only makes sense ingame.
+     * The server does not send a reply. In contrast to a Chat message, the server
+     * automatically converts this into an engine message and passes it on to the other
+     * clients.
+     */
+    int flib_netconn_send_teamchat(flib_netconn *conn, const char *msg);
+
+    /**
+     * Send an engine message. Only makes sense when ingame. In a networked game, you have to pass
+     * all the engine messages from the engine here, and they will be spread to all other clients
+     * in the game to keep the game in sync.
+     */
+    int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size);
+
+    /**
+     * Inform the server that the round has ended. Call this when the engine has disconnected,
+     * passing 1 if the round ended normally, 0 otherwise.
+     */
+    int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError);
+
+
+
+
+
+// Callbacks that are important for connecting/disconnecting
+
+    /**
+     * onNickTaken is called when connecting to the server, if it turns out that there is already a
+     * player with the same nick.
+     * In order to proceed, a new nickname needs to be sent to the server using
+     * flib_netconn_send_nick() (or of course you can bail out and send a QUIT).
+     * If you don't set a callback, the netconn will automatically react by generating a new name.
+     */
+    void flib_netconn_onNickTaken(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
+
+    /**
+     * When connecting with a registered nickname, the server will ask for a password before
+     * admitting you in. This callback is called when that happens. As a reaction, you can send the
+     * password using flib_netconn_send_password. If you don't register a callback, the default
+     * behavior is to just quit in a way that will cause a disconnect with
+     * NETCONN_DISCONNECT_AUTH_FAILED.
+     *
+     * You can't just choose a new nickname when you receive this callback, because at that point
+     * the server has already accepted your nick.
+     */
+    void flib_netconn_onPasswordRequest(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
+
+    /**
+     * This is called when the server has accepted our nickname (and possibly password) and we have
+     * entered the lobby.
+     */
+    void flib_netconn_onConnected(flib_netconn *conn, void (*callback)(void *context), void* context);
+
+    /**
+     * This is always the last callback (unless the netconn is destroyed early), and the netconn
+     * should be destroyed when it is received. The reason for the disconnect is passed as one of
+     * the NETCONN_DISCONNECT_ constants. Sometimes a message is included as well, but that
+     * parameter might also be NULL.
+     */
+    void flib_netconn_onDisconnected(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void* context);
+
+
+// Callbacks that make sense in most situations
+
+    /**
+     * Callback for several informational messages that should be displayed to the user
+     * (e.g. in the chat window), but do not require a reaction. If a game is running, you might
+     * want to redirect some of these messages to the engine as well so the user will see them.
+     */
+    void flib_netconn_onMessage(flib_netconn *conn, void (*callback)(void *context, int msgtype, const char *msg), void* context);
+
+    /**
+     * We received a chat message. Where this message belongs depends on the current state
+     * (lobby/room). If a game is running the message should be passed to the engine.
+     */
+    void flib_netconn_onChat(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *msg), void* context);
+
+    /**
+     * Callbacks for incremental room list updates. They will fire whenever these events occur,
+     * even before you first query the actual roomlist - so be sure not to blindly reference your
+     * room list in these callbacks. The server currently only sends updates when a room changes
+     * its name, so in order to update other room information you need to query the roomlist again
+     * (see send_request_roomlist / onRoomlist).
+     */
+    void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_room *room), void* context);
+    void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context);
+    void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_room *room), void* context);
+
+    /**
+     * Callbacks for players joining or leaving the lobby. In contrast to the roomlist updates, you
+     * will get a JOIN callback for every player already on the server when you join (and there is
+     * no direct way to query the current playerlist)
+     *
+     * NOTE: partMessage may be NULL.
+     */
+    void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
+    void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context);
+
+    /**
+     * This is called when the server informs us that one or more flags associated with a
+     * player/client have changed.
+     *
+     * nick is the name of the player, flags is a string containing one character for each modified
+     * flag (see below), and newFlagState signals whether the flags should be set to true or false.
+     *
+     * Some of these flags are important for protocol purposes (especially if they are set for you)
+     * while others are just informational. Also, some flags are only relevant for players who are
+     * in the same room as you, and the server will not inform you if they change for others.
+     *
+     * These are the currently known/used flags:
+     * a: Server admin. Always updated.
+     * h: Room chief. Updated when in the same room.
+     * r: Ready to play. Updated when in the same room.
+     * u: Registered user. Always updated.
+     *
+     * The server tells us the 'a' and 'u' flags for all players when we first join the lobby, and
+     * also tells us the 'r' and 'h' flags when we join or create a room. It assumes that all flags
+     * are initially false, so it will typically only tell you to set certain flags to true when
+     * transmitting the initial states. Reset the 'h' and 'r' flags to false when leaving a room,
+     * or when entering room state, to arrive at the right state for each player.
+     *
+     * The room chief state of yourself is particularly important because it determines whether you
+     * can modify settings of the current room. Generally, when you create a room you start out
+     * being room chief, and when you join an existing room you are not. However, if the original
+     * chief leaves a room, the server can choose a new chief, and if that happens the chief flag
+     * will be transferred to someone else.
+     */
+    void flib_netconn_onClientFlags(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *flags, bool newFlagState), void *context);
+
+// Callbacks that happen only in response to specific requests
+
+    /**
+     * Response to flib_netconn_send_request_roomlist().
+     * The rooms array contains the current state of all rooms on the server.
+     */
+    void flib_netconn_onRoomlist(flib_netconn *conn, void (*callback)(void *context, const flib_room **rooms, int roomCount), void* context);
+
+    /**
+     * Response to flib_netconn_send_joinRoom, flib_netconn_send_playerFollow or
+     * flib_netconn_send_createRoom.
+     *
+     * You just left the lobby and entered a room.
+     * If chief is true, you can and should send a full configuration for the room now. This
+     * consists of ammo, scheme, script and map, where map apparently has to come last.
+     */
+    void flib_netconn_onEnterRoom(flib_netconn *conn, void (*callback)(void *context, bool chief), void *context);
+
+    /**
+     * Response to flib_netconn_send_addTeam.
+     * The server might reject your team for several reasons, e.g. because it has the same name as
+     * an existing team, or because the room chief restricted adding new teams. If the team is
+     * accepted by the server, this callback is fired.
+     *
+     * If you are the room chief, you are expected to provide the hog count for your own team now
+     * using flib_netconn_send_teamHogCount. The color of the team is already set to the one you
+     * provided in addTeam.
+     */
+    void flib_netconn_onTeamAccepted(flib_netconn *conn, void (*callback)(void *context, const char *team), void *context);
+
+    /**
+     * When you query the server vars with flib_netconn_send_getServerVars (only works as admin),
+     * the server replies with a list of them. This callback is called for each entry in that list.
+     */
+    void flib_netconn_onServerVar(flib_netconn *conn, void (*callback)(void *context, const char *name, const char *value), void *context);
+
+
+// Callbacks that are only relevant in a room
+
+    /**
+     * You just left a room and entered the lobby again.
+     * reason is one of the NETCONN_ROOMLEAVE_ constants (usually a kick).
+     * This will not be called when you actively leave a room using PART.
+     * Don't confuse with onRoomLeave, which indicates that *someone else* left the room.
+     */
+    void flib_netconn_onLeaveRoom(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void *context);
+
+    /**
+     * Someone joined or left the room you are currently in.
+     * Analogous to onLobbyJoin/leave, you will receive the join callback for all players that are
+     * already in the room when you join, including for yourself (this is actually how it is
+     * determined that you joined a room).
+     *
+     * However, you will *not* receive onRoomLeave messages for everyone when you leave the room.
+     */
+    void flib_netconn_onRoomJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
+    void flib_netconn_onRoomLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context);
+
+    /**
+     * A new team was added to the room. The person who adds a team does NOT receive this callback
+     * (he gets onTeamAccepted instead).
+     *
+     * The team does not contain bindings, stats, weaponset, color or the number of hogs (but it is
+     * assumed to be the default of 4).
+     *
+     * If you receive this message and you are the room chief, you may want to send a color and hog
+     * count for this team using flib_netconn_send_teamHogCount / teamColor for QtFrontend
+     * compatibility.
+     *
+     * The server currently sends another message with the color of the team to the same recipients
+     * as this teamAdd message, which will trigger an onTeamColorChanged callback. See the
+     * description of flib_netconn_send_addTeam for more information.
+     */
+    void flib_netconn_onTeamAdd(flib_netconn *conn, void (*callback)(void *context, const flib_team *team), void *context);
+
+    /**
+     * A team was removed from the room. The person who removed the team will not receive this
+     * callback.
+     */
+    void flib_netconn_onTeamDelete(flib_netconn *conn, void (*callback)(void *context, const char *teamname), void *context);
+
+    /**
+     * The number of hogs in a team has been changed by the room chief. If you are the chief and
+     * change the number of hogs yourself, you will not receive this callback.
+     */
+    void flib_netconn_onHogCountChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int hogs), void *context);
+
+    /**
+     * The color of a team has been set or changed. The client who set or changed the color will
+     * not receive this callback.
+     *
+     * Normally, only the chief can change the color of a team. However, this message is also
+     * generated when a team is added, so you can receive it even as chief.
+     */
+    void flib_netconn_onTeamColorChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int colorIndex), void *context);
+
+    /**
+     * The room chief has changed the game scheme (or you just joined a room).
+     * You will not receive this callback if you changed the scheme yourself.
+     */
+    void flib_netconn_onSchemeChanged(flib_netconn *conn, void (*callback)(void *context, const flib_scheme *scheme), void *context);
+
+    /**
+     * The room chief has changed the map (or you just joined a room). Only non-chiefs receive these
+     * messages.
+     *
+     * To reduce the number of callback functions, the netconn keeps track of the current map
+     * settings and always passes the entire current map config, but informs the callee about what
+     * has changed (see the NETCONN_MAPCHANGE_ constants).
+     *
+     * Caution: Due to the way the protocol works, the map might not be complete at this point if it
+     * is a hand-drawn map, because the "full" map config does not include the drawn map data.
+     */
+    void flib_netconn_onMapChanged(flib_netconn *conn, void (*callback)(void *context, const flib_map *map, int changetype), void *context);
+
+    /**
+     * The room chief has changed the game style (or you just joined a room). If you are the chief
+     * and change the style yourself, you will not receive this callback.
+     */
+    void flib_netconn_onScriptChanged(flib_netconn *conn, void (*callback)(void *context, const char *script), void *context);
+
+    /**
+     * The room chief has changed the weaponset (or you just joined a room). If you are the chief
+     * and change the weaponset yourself, you will not receive this callback.
+     */
+    void flib_netconn_onWeaponsetChanged(flib_netconn *conn, void (*callback)(void *context, const flib_weaponset *weaponset), void *context);
+
+    /**
+     * The game is starting. Fire up the engine and join in!
+     * You can let the netconn generate the right game setup using flib_netconn_create_gamesetup
+     */
+    void flib_netconn_onRunGame(flib_netconn *conn, void (*callback)(void *context), void *context);
+
+    /**
+     * You are in a room, a game is in progress, and the server is sending you the new input for the
+     * engine to keep up to date with the current happenings. Pass it on to the engine using
+     * flib_gameconn_send_enginemsg.
+     */
+    void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const uint8_t *message, size_t size), void *context);
+
+#endif
--- a/project_files/frontlib/net/netconn_callbacks.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netconn_callbacks.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,149 +1,149 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "netconn_internal.h"
-
-#include "../util/logging.h"
-#include "../util/util.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-static void defaultCallback_onMessage(void *context, int msgtype, const char *msg) {
-	flib_log_i("Net: [%i] %s", msgtype, msg);
-}
-
-static void defaultCallback_onChat(void *context, const char *nick, const char *msg) {
-	flib_log_i("%s: %s", nick, msg);
-}
-
-// Change the name by suffixing it with a number. If it already ends in a number, increase that number by 1.
-static void defaultCallback_onNickTaken(void *context, const char *requestedNick) {
-	flib_netconn *conn = context;
-	size_t namelen = strlen(requestedNick);
-	int digits = 0;
-	while(digits<namelen && isdigit(requestedNick[namelen-1-digits])) {
-		digits++;
-	}
-	long suffix = 0;
-	if(digits>0) {
-		suffix = atol(requestedNick+namelen-digits)+1;
-	}
-	char *newPlayerName = flib_asprintf("%.*s%li", namelen-digits, requestedNick, suffix);
-	if(newPlayerName) {
-		flib_netconn_send_nick(conn, newPlayerName);
-	} else {
-		flib_netconn_send_quit(conn, "Nick already taken.");
-	}
-	free(newPlayerName);
-}
-
-// Default behavior: Quit
-static void defaultCallback_onPasswordRequest(void *context, const char *requestedNick) {
-	flib_netconn_send_quit((flib_netconn*)context, "Authentication failed");
-}
-
-void netconn_clearCallbacks(flib_netconn *conn) {
-	flib_netconn_onMessage(conn, NULL, NULL);
-	flib_netconn_onConnected(conn, NULL, NULL);
-	flib_netconn_onDisconnected(conn, NULL, NULL);
-	flib_netconn_onRoomlist(conn, NULL, NULL);
-	flib_netconn_onRoomAdd(conn, NULL, NULL);
-	flib_netconn_onRoomDelete(conn, NULL, NULL);
-	flib_netconn_onRoomUpdate(conn, NULL, NULL);
-	flib_netconn_onClientFlags(conn, NULL, NULL);
-	flib_netconn_onChat(conn, NULL, NULL);
-	flib_netconn_onLobbyJoin(conn, NULL, NULL);
-	flib_netconn_onLobbyLeave(conn, NULL, NULL);
-	flib_netconn_onRoomJoin(conn, NULL, NULL);
-	flib_netconn_onRoomLeave(conn, NULL, NULL);
-	flib_netconn_onNickTaken(conn, NULL, NULL);
-	flib_netconn_onPasswordRequest(conn, NULL, NULL);
-	flib_netconn_onEnterRoom(conn, NULL, NULL);
-	flib_netconn_onLeaveRoom(conn, NULL, NULL);
-	flib_netconn_onTeamAdd(conn, NULL, NULL);
-	flib_netconn_onTeamDelete(conn, NULL, NULL);
-	flib_netconn_onRunGame(conn, NULL, NULL);
-	flib_netconn_onTeamAccepted(conn, NULL, NULL);
-	flib_netconn_onHogCountChanged(conn, NULL, NULL);
-	flib_netconn_onTeamColorChanged(conn, NULL, NULL);
-	flib_netconn_onEngineMessage(conn, NULL, NULL);
-	flib_netconn_onSchemeChanged(conn, NULL, NULL);
-	flib_netconn_onMapChanged(conn, NULL, NULL);
-	flib_netconn_onScriptChanged(conn, NULL, NULL);
-	flib_netconn_onWeaponsetChanged(conn, NULL, NULL);
-	flib_netconn_onServerVar(conn, NULL, NULL);
-}
-
-/**
- * This macro generates a callback setter function. It uses the name of the callback to
- * automatically generate the function name and the fields to set, so a consistent naming
- * convention needs to be enforced (not that that is a bad thing). If null is passed as
- * callback to the generated function, the defaultCb will be set instead (with conn
- * as the context).
- */
-#define GENERATE_CB_SETTER(cbName, cbParameterTypes, defaultCb) \
-	void flib_netconn_##cbName(flib_netconn *conn, void (*callback)cbParameterTypes, void *context) { \
-		if(!log_badargs_if(conn==NULL)) { \
-			conn->cbName##Cb = callback ? callback : &defaultCb; \
-			conn->cbName##Ctx = callback ? context : conn; \
-		} \
-	}
-
-/**
- * Generate a callback setter function like GENERATE_CB_SETTER, and automatically generate a
- * no-op callback function as well that is used as default.
- */
-#define GENERATE_CB_SETTER_AND_DEFAULT(cbName, cbParameterTypes) \
-	static void _noop_callback_##cbName cbParameterTypes {} \
-	GENERATE_CB_SETTER(cbName, cbParameterTypes, _noop_callback_##cbName)
-
-GENERATE_CB_SETTER(onMessage, (void *context, int msgtype, const char *msg), defaultCallback_onMessage);
-GENERATE_CB_SETTER_AND_DEFAULT(onConnected, (void *context));
-GENERATE_CB_SETTER_AND_DEFAULT(onDisconnected, (void *context, int reason, const char *message));
-GENERATE_CB_SETTER_AND_DEFAULT(onRoomlist, (void *context, const flib_room **rooms, int roomCount));
-GENERATE_CB_SETTER_AND_DEFAULT(onRoomAdd, (void *context, const flib_room *room));
-GENERATE_CB_SETTER_AND_DEFAULT(onRoomDelete, (void *context, const char *name));
-GENERATE_CB_SETTER_AND_DEFAULT(onRoomUpdate, (void *context, const char *oldName, const flib_room *room));
-GENERATE_CB_SETTER_AND_DEFAULT(onClientFlags, (void *context, const char *nick, const char *flags, bool newFlagState));
-GENERATE_CB_SETTER(onChat, (void *context, const char *nick, const char *msg), defaultCallback_onChat);
-GENERATE_CB_SETTER_AND_DEFAULT(onLobbyJoin, (void *context, const char *nick));
-GENERATE_CB_SETTER_AND_DEFAULT(onLobbyLeave, (void *context, const char *nick, const char *partMsg));
-GENERATE_CB_SETTER_AND_DEFAULT(onRoomJoin, (void *context, const char *nick));
-GENERATE_CB_SETTER_AND_DEFAULT(onRoomLeave, (void *context, const char *nick, const char *partMessage));
-GENERATE_CB_SETTER(onNickTaken, (void *context, const char *nick), defaultCallback_onNickTaken);
-GENERATE_CB_SETTER(onPasswordRequest, (void *context, const char *nick), defaultCallback_onPasswordRequest);
-GENERATE_CB_SETTER_AND_DEFAULT(onEnterRoom, (void *context, bool chief));
-GENERATE_CB_SETTER_AND_DEFAULT(onLeaveRoom, (void *context, int reason, const char *message));
-GENERATE_CB_SETTER_AND_DEFAULT(onTeamAdd, (void *context, const flib_team *team));
-GENERATE_CB_SETTER_AND_DEFAULT(onTeamDelete, (void *context, const char *teamname));
-GENERATE_CB_SETTER_AND_DEFAULT(onRunGame, (void *context));
-GENERATE_CB_SETTER_AND_DEFAULT(onTeamAccepted, (void *context, const char *teamName));
-GENERATE_CB_SETTER_AND_DEFAULT(onHogCountChanged, (void *context, const char *teamName, int hogs));
-GENERATE_CB_SETTER_AND_DEFAULT(onTeamColorChanged, (void *context, const char *teamName, int colorIndex));
-GENERATE_CB_SETTER_AND_DEFAULT(onEngineMessage, (void *context, const uint8_t *message, size_t size));
-GENERATE_CB_SETTER_AND_DEFAULT(onSchemeChanged, (void *context, const flib_scheme *scheme));
-GENERATE_CB_SETTER_AND_DEFAULT(onMapChanged, (void *context, const flib_map *map, int changetype));
-GENERATE_CB_SETTER_AND_DEFAULT(onScriptChanged, (void *context, const char *script));
-GENERATE_CB_SETTER_AND_DEFAULT(onWeaponsetChanged, (void *context, const flib_weaponset *weaponset));
-GENERATE_CB_SETTER_AND_DEFAULT(onServerVar, (void *context, const char *name, const char *value));
-
-#undef GENERATE_CB_SETTER_AND_DEFAULT
-#undef GENERATE_CB_SETTER
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "netconn_internal.h"
+
+#include "../util/logging.h"
+#include "../util/util.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+static void defaultCallback_onMessage(void *context, int msgtype, const char *msg) {
+    flib_log_i("Net: [%i] %s", msgtype, msg);
+}
+
+static void defaultCallback_onChat(void *context, const char *nick, const char *msg) {
+    flib_log_i("%s: %s", nick, msg);
+}
+
+// Change the name by suffixing it with a number. If it already ends in a number, increase that number by 1.
+static void defaultCallback_onNickTaken(void *context, const char *requestedNick) {
+    flib_netconn *conn = context;
+    size_t namelen = strlen(requestedNick);
+    int digits = 0;
+    while(digits<namelen && isdigit(requestedNick[namelen-1-digits])) {
+        digits++;
+    }
+    long suffix = 0;
+    if(digits>0) {
+        suffix = atol(requestedNick+namelen-digits)+1;
+    }
+    char *newPlayerName = flib_asprintf("%.*s%li", namelen-digits, requestedNick, suffix);
+    if(newPlayerName) {
+        flib_netconn_send_nick(conn, newPlayerName);
+    } else {
+        flib_netconn_send_quit(conn, "Nick already taken.");
+    }
+    free(newPlayerName);
+}
+
+// Default behavior: Quit
+static void defaultCallback_onPasswordRequest(void *context, const char *requestedNick) {
+    flib_netconn_send_quit((flib_netconn*)context, "Authentication failed");
+}
+
+void netconn_clearCallbacks(flib_netconn *conn) {
+    flib_netconn_onMessage(conn, NULL, NULL);
+    flib_netconn_onConnected(conn, NULL, NULL);
+    flib_netconn_onDisconnected(conn, NULL, NULL);
+    flib_netconn_onRoomlist(conn, NULL, NULL);
+    flib_netconn_onRoomAdd(conn, NULL, NULL);
+    flib_netconn_onRoomDelete(conn, NULL, NULL);
+    flib_netconn_onRoomUpdate(conn, NULL, NULL);
+    flib_netconn_onClientFlags(conn, NULL, NULL);
+    flib_netconn_onChat(conn, NULL, NULL);
+    flib_netconn_onLobbyJoin(conn, NULL, NULL);
+    flib_netconn_onLobbyLeave(conn, NULL, NULL);
+    flib_netconn_onRoomJoin(conn, NULL, NULL);
+    flib_netconn_onRoomLeave(conn, NULL, NULL);
+    flib_netconn_onNickTaken(conn, NULL, NULL);
+    flib_netconn_onPasswordRequest(conn, NULL, NULL);
+    flib_netconn_onEnterRoom(conn, NULL, NULL);
+    flib_netconn_onLeaveRoom(conn, NULL, NULL);
+    flib_netconn_onTeamAdd(conn, NULL, NULL);
+    flib_netconn_onTeamDelete(conn, NULL, NULL);
+    flib_netconn_onRunGame(conn, NULL, NULL);
+    flib_netconn_onTeamAccepted(conn, NULL, NULL);
+    flib_netconn_onHogCountChanged(conn, NULL, NULL);
+    flib_netconn_onTeamColorChanged(conn, NULL, NULL);
+    flib_netconn_onEngineMessage(conn, NULL, NULL);
+    flib_netconn_onSchemeChanged(conn, NULL, NULL);
+    flib_netconn_onMapChanged(conn, NULL, NULL);
+    flib_netconn_onScriptChanged(conn, NULL, NULL);
+    flib_netconn_onWeaponsetChanged(conn, NULL, NULL);
+    flib_netconn_onServerVar(conn, NULL, NULL);
+}
+
+/**
+ * This macro generates a callback setter function. It uses the name of the callback to
+ * automatically generate the function name and the fields to set, so a consistent naming
+ * convention needs to be enforced (not that that is a bad thing). If null is passed as
+ * callback to the generated function, the defaultCb will be set instead (with conn
+ * as the context).
+ */
+#define GENERATE_CB_SETTER(cbName, cbParameterTypes, defaultCb) \
+    void flib_netconn_##cbName(flib_netconn *conn, void (*callback)cbParameterTypes, void *context) { \
+        if(!log_badargs_if(conn==NULL)) { \
+            conn->cbName##Cb = callback ? callback : &defaultCb; \
+            conn->cbName##Ctx = callback ? context : conn; \
+        } \
+    }
+
+/**
+ * Generate a callback setter function like GENERATE_CB_SETTER, and automatically generate a
+ * no-op callback function as well that is used as default.
+ */
+#define GENERATE_CB_SETTER_AND_DEFAULT(cbName, cbParameterTypes) \
+    static void _noop_callback_##cbName cbParameterTypes {} \
+    GENERATE_CB_SETTER(cbName, cbParameterTypes, _noop_callback_##cbName)
+
+GENERATE_CB_SETTER(onMessage, (void *context, int msgtype, const char *msg), defaultCallback_onMessage);
+GENERATE_CB_SETTER_AND_DEFAULT(onConnected, (void *context));
+GENERATE_CB_SETTER_AND_DEFAULT(onDisconnected, (void *context, int reason, const char *message));
+GENERATE_CB_SETTER_AND_DEFAULT(onRoomlist, (void *context, const flib_room **rooms, int roomCount));
+GENERATE_CB_SETTER_AND_DEFAULT(onRoomAdd, (void *context, const flib_room *room));
+GENERATE_CB_SETTER_AND_DEFAULT(onRoomDelete, (void *context, const char *name));
+GENERATE_CB_SETTER_AND_DEFAULT(onRoomUpdate, (void *context, const char *oldName, const flib_room *room));
+GENERATE_CB_SETTER_AND_DEFAULT(onClientFlags, (void *context, const char *nick, const char *flags, bool newFlagState));
+GENERATE_CB_SETTER(onChat, (void *context, const char *nick, const char *msg), defaultCallback_onChat);
+GENERATE_CB_SETTER_AND_DEFAULT(onLobbyJoin, (void *context, const char *nick));
+GENERATE_CB_SETTER_AND_DEFAULT(onLobbyLeave, (void *context, const char *nick, const char *partMsg));
+GENERATE_CB_SETTER_AND_DEFAULT(onRoomJoin, (void *context, const char *nick));
+GENERATE_CB_SETTER_AND_DEFAULT(onRoomLeave, (void *context, const char *nick, const char *partMessage));
+GENERATE_CB_SETTER(onNickTaken, (void *context, const char *nick), defaultCallback_onNickTaken);
+GENERATE_CB_SETTER(onPasswordRequest, (void *context, const char *nick), defaultCallback_onPasswordRequest);
+GENERATE_CB_SETTER_AND_DEFAULT(onEnterRoom, (void *context, bool chief));
+GENERATE_CB_SETTER_AND_DEFAULT(onLeaveRoom, (void *context, int reason, const char *message));
+GENERATE_CB_SETTER_AND_DEFAULT(onTeamAdd, (void *context, const flib_team *team));
+GENERATE_CB_SETTER_AND_DEFAULT(onTeamDelete, (void *context, const char *teamname));
+GENERATE_CB_SETTER_AND_DEFAULT(onRunGame, (void *context));
+GENERATE_CB_SETTER_AND_DEFAULT(onTeamAccepted, (void *context, const char *teamName));
+GENERATE_CB_SETTER_AND_DEFAULT(onHogCountChanged, (void *context, const char *teamName, int hogs));
+GENERATE_CB_SETTER_AND_DEFAULT(onTeamColorChanged, (void *context, const char *teamName, int colorIndex));
+GENERATE_CB_SETTER_AND_DEFAULT(onEngineMessage, (void *context, const uint8_t *message, size_t size));
+GENERATE_CB_SETTER_AND_DEFAULT(onSchemeChanged, (void *context, const flib_scheme *scheme));
+GENERATE_CB_SETTER_AND_DEFAULT(onMapChanged, (void *context, const flib_map *map, int changetype));
+GENERATE_CB_SETTER_AND_DEFAULT(onScriptChanged, (void *context, const char *script));
+GENERATE_CB_SETTER_AND_DEFAULT(onWeaponsetChanged, (void *context, const flib_weaponset *weaponset));
+GENERATE_CB_SETTER_AND_DEFAULT(onServerVar, (void *context, const char *name, const char *value));
+
+#undef GENERATE_CB_SETTER_AND_DEFAULT
+#undef GENERATE_CB_SETTER
--- a/project_files/frontlib/net/netconn_internal.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netconn_internal.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,151 +1,151 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * Common definitions needed by netconn functions, to allow splitting them into several files.
- */
-
-#ifndef NETCONN_INTERNAL_H_
-#define NETCONN_INTERNAL_H_
-
-#include "netconn.h"
-#include "netbase.h"
-#include "../model/map.h"
-#include "../model/team.h"
-#include "../model/weapon.h"
-#include "../model/room.h"
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <stddef.h>
-
-struct _flib_netconn {
-	flib_netbase *netBase;
-	char *playerName;
-	char *dataDirPath;
-
-	int netconnState;			//!< One of the NETCONN_STATE constants
-
-	bool isChief;				//!< Player can modify the current room
-	flib_map *map;
-	flib_teamlist pendingTeamlist;
-	flib_teamlist teamlist;
-	flib_scheme *scheme;
-	char *style;
-	flib_weaponset *weaponset;
-
-	void (*onMessageCb)(void *context, int msgtype, const char *msg);
-	void *onMessageCtx;
-
-	void (*onConnectedCb)(void *context);
-	void *onConnectedCtx;
-
-	void (*onDisconnectedCb)(void *context, int reason, const char *message);
-	void *onDisconnectedCtx;
-
-	void (*onRoomlistCb)(void *context, const flib_room **rooms, int roomCount);
-	void *onRoomlistCtx;
-
-	void (*onRoomAddCb)(void *context, const flib_room *room);
-	void *onRoomAddCtx;
-
-	void (*onRoomDeleteCb)(void *context, const char *name);
-	void *onRoomDeleteCtx;
-
-	void (*onRoomUpdateCb)(void *context, const char *oldName, const flib_room *room);
-	void *onRoomUpdateCtx;
-
-	void (*onClientFlagsCb)(void *context, const char *nick, const char *flags, bool newFlagState);
-	void *onClientFlagsCtx;
-
-	void (*onChatCb)(void *context, const char *nick, const char *msg);
-	void *onChatCtx;
-
-	void (*onLobbyJoinCb)(void *context, const char *nick);
-	void *onLobbyJoinCtx;
-
-	void (*onLobbyLeaveCb)(void *context, const char *nick, const char *partMessage);
-	void *onLobbyLeaveCtx;
-
-	void (*onRoomJoinCb)(void *context, const char *nick);
-	void *onRoomJoinCtx;
-
-	void (*onRoomLeaveCb)(void *context, const char *nick, const char *partMessage);
-	void *onRoomLeaveCtx;
-
-	void (*onNickTakenCb)(void *context, const char *nick);
-	void *onNickTakenCtx;
-
-	void (*onPasswordRequestCb)(void *context, const char *nick);
-	void *onPasswordRequestCtx;
-
-	void (*onEnterRoomCb)(void *context, bool chief);
-	void *onEnterRoomCtx;
-
-	void (*onLeaveRoomCb)(void *context, int reason, const char *message);
-	void *onLeaveRoomCtx;
-
-	void (*onTeamAddCb)(void *context, const flib_team *team);
-	void *onTeamAddCtx;
-
-	void (*onTeamDeleteCb)(void *context, const char *teamname);
-	void *onTeamDeleteCtx;
-
-	void (*onRunGameCb)(void *context);
-	void *onRunGameCtx;
-
-	void (*onTeamAcceptedCb)(void *context, const char *teamName);
-	void *onTeamAcceptedCtx;
-
-	void (*onHogCountChangedCb)(void *context, const char *teamName, int hogs);
-	void *onHogCountChangedCtx;
-
-	void (*onTeamColorChangedCb)(void *context, const char *teamName, int colorIndex);
-	void *onTeamColorChangedCtx;
-
-	void (*onEngineMessageCb)(void *context, const uint8_t *message, size_t size);
-	void *onEngineMessageCtx;
-
-	void (*onSchemeChangedCb)(void *context, const flib_scheme *scheme);
-	void *onSchemeChangedCtx;
-
-	void (*onMapChangedCb)(void *context, const flib_map *map, int changetype);
-	void *onMapChangedCtx;
-
-	void (*onScriptChangedCb)(void *context, const char *script);
-	void *onScriptChangedCtx;
-
-	void (*onWeaponsetChangedCb)(void *context, const flib_weaponset *weaponset);
-	void *onWeaponsetChangedCtx;
-
-	void (*onServerVarCb)(void *context, const char *name, const char *value);
-	void *onServerVarCtx;
-
-	bool running;
-	bool destroyRequested;
-};
-
-void netconn_clearCallbacks(flib_netconn *conn);
-void netconn_leaveRoom(flib_netconn *conn);
-void netconn_setMap(flib_netconn *conn, const flib_map *map);
-void netconn_setWeaponset(flib_netconn *conn, const flib_weaponset *weaponset);
-void netconn_setScript(flib_netconn *conn, const char *script);
-void netconn_setScheme(flib_netconn *conn, const flib_scheme *scheme);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * Common definitions needed by netconn functions, to allow splitting them into several files.
+ */
+
+#ifndef NETCONN_INTERNAL_H_
+#define NETCONN_INTERNAL_H_
+
+#include "netconn.h"
+#include "netbase.h"
+#include "../model/map.h"
+#include "../model/team.h"
+#include "../model/weapon.h"
+#include "../model/room.h"
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stddef.h>
+
+struct _flib_netconn {
+    flib_netbase *netBase;
+    char *playerName;
+    char *dataDirPath;
+
+    int netconnState;           //!< One of the NETCONN_STATE constants
+
+    bool isChief;               //!< Player can modify the current room
+    flib_map *map;
+    flib_teamlist pendingTeamlist;
+    flib_teamlist teamlist;
+    flib_scheme *scheme;
+    char *style;
+    flib_weaponset *weaponset;
+
+    void (*onMessageCb)(void *context, int msgtype, const char *msg);
+    void *onMessageCtx;
+
+    void (*onConnectedCb)(void *context);
+    void *onConnectedCtx;
+
+    void (*onDisconnectedCb)(void *context, int reason, const char *message);
+    void *onDisconnectedCtx;
+
+    void (*onRoomlistCb)(void *context, const flib_room **rooms, int roomCount);
+    void *onRoomlistCtx;
+
+    void (*onRoomAddCb)(void *context, const flib_room *room);
+    void *onRoomAddCtx;
+
+    void (*onRoomDeleteCb)(void *context, const char *name);
+    void *onRoomDeleteCtx;
+
+    void (*onRoomUpdateCb)(void *context, const char *oldName, const flib_room *room);
+    void *onRoomUpdateCtx;
+
+    void (*onClientFlagsCb)(void *context, const char *nick, const char *flags, bool newFlagState);
+    void *onClientFlagsCtx;
+
+    void (*onChatCb)(void *context, const char *nick, const char *msg);
+    void *onChatCtx;
+
+    void (*onLobbyJoinCb)(void *context, const char *nick);
+    void *onLobbyJoinCtx;
+
+    void (*onLobbyLeaveCb)(void *context, const char *nick, const char *partMessage);
+    void *onLobbyLeaveCtx;
+
+    void (*onRoomJoinCb)(void *context, const char *nick);
+    void *onRoomJoinCtx;
+
+    void (*onRoomLeaveCb)(void *context, const char *nick, const char *partMessage);
+    void *onRoomLeaveCtx;
+
+    void (*onNickTakenCb)(void *context, const char *nick);
+    void *onNickTakenCtx;
+
+    void (*onPasswordRequestCb)(void *context, const char *nick);
+    void *onPasswordRequestCtx;
+
+    void (*onEnterRoomCb)(void *context, bool chief);
+    void *onEnterRoomCtx;
+
+    void (*onLeaveRoomCb)(void *context, int reason, const char *message);
+    void *onLeaveRoomCtx;
+
+    void (*onTeamAddCb)(void *context, const flib_team *team);
+    void *onTeamAddCtx;
+
+    void (*onTeamDeleteCb)(void *context, const char *teamname);
+    void *onTeamDeleteCtx;
+
+    void (*onRunGameCb)(void *context);
+    void *onRunGameCtx;
+
+    void (*onTeamAcceptedCb)(void *context, const char *teamName);
+    void *onTeamAcceptedCtx;
+
+    void (*onHogCountChangedCb)(void *context, const char *teamName, int hogs);
+    void *onHogCountChangedCtx;
+
+    void (*onTeamColorChangedCb)(void *context, const char *teamName, int colorIndex);
+    void *onTeamColorChangedCtx;
+
+    void (*onEngineMessageCb)(void *context, const uint8_t *message, size_t size);
+    void *onEngineMessageCtx;
+
+    void (*onSchemeChangedCb)(void *context, const flib_scheme *scheme);
+    void *onSchemeChangedCtx;
+
+    void (*onMapChangedCb)(void *context, const flib_map *map, int changetype);
+    void *onMapChangedCtx;
+
+    void (*onScriptChangedCb)(void *context, const char *script);
+    void *onScriptChangedCtx;
+
+    void (*onWeaponsetChangedCb)(void *context, const flib_weaponset *weaponset);
+    void *onWeaponsetChangedCtx;
+
+    void (*onServerVarCb)(void *context, const char *name, const char *value);
+    void *onServerVarCtx;
+
+    bool running;
+    bool destroyRequested;
+};
+
+void netconn_clearCallbacks(flib_netconn *conn);
+void netconn_leaveRoom(flib_netconn *conn);
+void netconn_setMap(flib_netconn *conn, const flib_map *map);
+void netconn_setWeaponset(flib_netconn *conn, const flib_weaponset *weaponset);
+void netconn_setScript(flib_netconn *conn, const char *script);
+void netconn_setScheme(flib_netconn *conn, const flib_scheme *scheme);
+
+#endif
--- a/project_files/frontlib/net/netconn_send.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netconn_send.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,495 +1,495 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "netconn_internal.h"
-
-#include "../util/logging.h"
-#include "../util/util.h"
-#include "../util/buffer.h"
-#include "../md5/md5.h"
-#include "../base64/base64.h"
-
-#include <zlib.h>
-
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
-// cmdname is always given as literal from functions in this file, so it is never null.
-static int sendVoid(flib_netconn *conn, const char *cmdname) {
-	if(log_e_if(!conn, "Invalid parameter sending %s command", cmdname)) {
-		return -1;
-	}
-	return flib_netbase_sendf(conn->netBase, "%s\n\n", cmdname);
-}
-
-// Testing for !*str prevents sending 0-length parameters (they trip up the protocol)
-static int sendStr(flib_netconn *conn, const char *cmdname, const char *str) {
-	if(log_e_if(!conn || flib_strempty(str), "Invalid parameter sending %s command", cmdname)) {
-		return -1;
-	}
-	return flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", cmdname, str);
-}
-
-static int sendInt(flib_netconn *conn, const char *cmdname, int param) {
-	if(log_e_if(!conn, "Invalid parameter sending %s command", cmdname)) {
-		return -1;
-	}
-	return flib_netbase_sendf(conn->netBase, "%s\n%i\n\n", cmdname, param);
-}
-
-int flib_netconn_send_nick(flib_netconn *conn, const char *nick) {
-	int result = -1;
-	if(!log_badargs_if2(conn==NULL, flib_strempty(nick))) {
-		char *tmpName = flib_strdupnull(nick);
-		if(tmpName) {
-			if(!flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "NICK", nick)) {
-				free(conn->playerName);
-				conn->playerName = tmpName;
-				tmpName = NULL;
-				result = 0;
-			}
-		}
-		free(tmpName);
-	}
-	return result;
-}
-
-int flib_netconn_send_password(flib_netconn *conn, const char *passwd) {
-	int result = -1;
-	if(!log_badargs_if2(conn==NULL, passwd==NULL)) {
-		md5_state_t md5state;
-		uint8_t md5bytes[16];
-		char md5hex[33];
-		md5_init(&md5state);
-		md5_append(&md5state, (unsigned char*)passwd, strlen(passwd));
-		md5_finish(&md5state, md5bytes);
-		for(int i=0;i<sizeof(md5bytes); i++) {
-			// Needs to be lowercase - server checks case sensitive
-			snprintf(md5hex+i*2, 3, "%02x", (unsigned)md5bytes[i]);
-		}
-		result = flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "PASSWORD", md5hex);
-	}
-	return result;
-}
-
-int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg) {
-	return sendStr(conn, "QUIT", (quitmsg && *quitmsg) ? quitmsg : "User quit");
-}
-
-int flib_netconn_send_chat(flib_netconn *conn, const char *chat) {
-	if(!flib_strempty(chat)) {
-		return sendStr(conn, "CHAT", chat);
-	}
-	return 0;
-}
-
-int flib_netconn_send_kick(flib_netconn *conn, const char *playerName) {
-	return sendStr(conn, "KICK", playerName);
-}
-
-int flib_netconn_send_playerInfo(flib_netconn *conn, const char *playerName) {
-	return sendStr(conn, "INFO", playerName);
-}
-
-int flib_netconn_send_request_roomlist(flib_netconn *conn) {
-	return sendVoid(conn, "LIST");
-}
-
-int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room) {
-	if(!sendStr(conn, "JOIN_ROOM", room)) {
-		conn->isChief = false;
-		return 0;
-	}
-	return -1;
-}
-
-int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName) {
-	return sendStr(conn, "FOLLOW", playerName);
-}
-
-int flib_netconn_send_createRoom(flib_netconn *conn, const char *room) {
-	if(!sendStr(conn, "CREATE_ROOM", room)) {
-		conn->isChief = true;
-		return 0;
-	}
-	return -1;
-}
-
-int flib_netconn_send_ban(flib_netconn *conn, const char *playerName) {
-	return sendStr(conn, "BAN", playerName);
-}
-
-int flib_netconn_send_clearAccountsCache(flib_netconn *conn) {
-	return sendVoid(conn, "CLEAR_ACCOUNTS_CACHE");
-}
-
-int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value) {
-	if(log_badargs_if3(conn==NULL, flib_strempty(name), flib_strempty(value))) {
-		return -1;
-	}
-	return flib_netbase_sendf(conn->netBase, "%s\n%s\n%s\n\n", "SET_SERVER_VAR", name, value);
-}
-
-int flib_netconn_send_getServerVars(flib_netconn *conn) {
-	return sendVoid(conn, "GET_SERVER_VAR");
-}
-int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *str) {
-	int result = -1;
-	if(conn->netconnState==NETCONN_STATE_ROOM) {
-		result = (str && *str) ? sendStr(conn, "PART", str) : sendVoid(conn, "PART");
-		if(!result) {
-			netconn_leaveRoom(conn);
-		}
-	}
-	return result;
-}
-
-int flib_netconn_send_toggleReady(flib_netconn *conn) {
-	return sendVoid(conn, "TOGGLE_READY");
-}
-
-static void addTeamToPendingList(flib_netconn *conn, const flib_team *team) {
-	flib_team *teamcopy = flib_team_copy(team);
-	if(teamcopy) {
-		teamcopy->remoteDriven = false;
-		free(teamcopy->ownerName);
-		teamcopy->ownerName = flib_strdupnull(conn->playerName);
-		if(teamcopy->ownerName) {
-			flib_teamlist_delete(&conn->pendingTeamlist, team->name);
-			if(!flib_teamlist_insert(&conn->pendingTeamlist, teamcopy, 0)) {
-				teamcopy = NULL;
-			}
-		}
-	}
-	flib_team_destroy(teamcopy);
-}
-
-int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team) {
-	int result = -1;
-	if(!log_badargs_if2(conn==NULL, team==NULL)) {
-		bool missingInfo = flib_strempty(team->name) || flib_strempty(team->grave) || flib_strempty(team->fort) || flib_strempty(team->voicepack) || flib_strempty(team->flag);
-		for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-			missingInfo |= flib_strempty(team->hogs[i].name) || flib_strempty(team->hogs[i].hat);
-		}
-		if(!log_e_if(missingInfo, "Incomplete team definition")) {
-			flib_vector *vec = flib_vector_create();
-			if(vec) {
-				bool error = false;
-				error |= flib_vector_appendf(vec, "ADD_TEAM\n%s\n%i\n%s\n%s\n%s\n%s\n%i\n", team->name, team->colorIndex, team->grave, team->fort, team->voicepack, team->flag, team->hogs[0].difficulty);
-				for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-					error |= flib_vector_appendf(vec, "%s\n%s\n", team->hogs[i].name, team->hogs[i].hat);
-				}
-				error |= flib_vector_appendf(vec, "\n");
-				if(!error && !flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec))) {
-					addTeamToPendingList(conn, team);
-					result = 0;
-				}
-			}
-			flib_vector_destroy(vec);
-		}
-	}
-	return result;
-}
-
-int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname) {
-	flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
-	if(team && !team->remoteDriven && !sendStr(conn, "REMOVE_TEAM", teamname)) {
-		flib_teamlist_delete(&conn->teamlist, teamname);
-		return 0;
-	}
-	return -1;
-}
-
-int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName) {
-	return sendStr(conn, "ROOM_NAME", roomName);
-}
-
-int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount) {
-	if(!log_badargs_if5(conn==NULL, flib_strempty(teamname), hogcount<1, hogcount>HEDGEHOGS_PER_TEAM, !conn->isChief)
-			&& !flib_netbase_sendf(conn->netBase, "HH_NUM\n%s\n%i\n\n", teamname, hogcount)) {
-		flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
-		if(team) {
-			team->hogsInGame = hogcount;
-		}
-		return 0;
-	}
-	return -1;
-}
-
-int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex) {
-	if(!log_badargs_if3(conn==NULL, flib_strempty(teamname), !conn->isChief)
-			&& !flib_netbase_sendf(conn->netBase, "TEAM_COLOR\n%s\n%i\n\n", teamname, colorIndex)) {
-		flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
-		if(team) {
-			team->colorIndex = colorIndex;
-		}
-		return 0;
-	}
-	return -1;
-}
-
-int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset) {
-	if(!log_badargs_if3(conn==NULL, weaponset==NULL, flib_strempty(weaponset->name))) {
-		char ammostring[WEAPONS_COUNT*4+1];
-		strcpy(ammostring, weaponset->loadout);
-		strcat(ammostring, weaponset->crateprob);
-		strcat(ammostring, weaponset->delay);
-		strcat(ammostring, weaponset->crateammo);
-		if(conn->isChief) {
-			if(!flib_netbase_sendf(conn->netBase, "CFG\nAMMO\n%s\n%s\n\n", weaponset->name, ammostring)) {
-				netconn_setWeaponset(conn, weaponset);
-				return 0;
-			}
-		}
-	}
-	return -1;
-}
-
-int flib_netconn_send_map(flib_netconn *conn, const flib_map *map) {
-	if(log_badargs_if2(conn==NULL, map==NULL)) {
-		return -1;
-	}
-	bool error = false;
-
-	if(map->seed) {
-		error |= flib_netconn_send_mapSeed(conn, map->seed);
-	}
-	error |= flib_netconn_send_mapTemplate(conn, map->templateFilter);
-	if(map->theme) {
-		error |= flib_netconn_send_mapTheme(conn, map->theme);
-	}
-	error |= flib_netconn_send_mapGen(conn, map->mapgen);
-	error |= flib_netconn_send_mapMazeSize(conn, map->mazeSize);
-	if(map->drawData && map->drawDataSize>0) {
-		error |= flib_netconn_send_mapDrawdata(conn, map->drawData, map->drawDataSize);
-	}
-	// Name is sent last, because the QtFrontend uses this to update its preview, and to show/hide
-	// certain fields
-	if(map->name) {
-		error |= flib_netconn_send_mapName(conn, map->name);
-	}
-	return error;
-}
-
-int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName) {
-	if(log_badargs_if2(conn==NULL, mapName==NULL)) {
-		return -1;
-	}
-	if(conn->isChief) {
-		if(!sendStr(conn, "CFG\nMAP", mapName)) {
-			char *copy = flib_strdupnull(mapName);
-			if(copy) {
-				free(conn->map->name);
-				conn->map->name = copy;
-				return 0;
-			}
-		}
-	}
-	return -1;
-}
-
-int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen) {
-	if(log_badargs_if(conn==NULL)) {
-		return -1;
-	}
-	if(conn->isChief) {
-		if(!sendInt(conn, "CFG\nMAPGEN", mapGen)) {
-			conn->map->mapgen = mapGen;
-			return 0;
-		}
-	}
-	return -1;
-}
-
-int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter) {
-	if(log_badargs_if(conn==NULL)) {
-		return -1;
-	}
-	if(conn->isChief) {
-		if(!sendInt(conn, "CFG\nTEMPLATE", templateFilter)) {
-			conn->map->templateFilter = templateFilter;
-			return 0;
-		}
-	}
-	return -1;
-}
-
-int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize) {
-	if(log_badargs_if(conn==NULL)) {
-		return -1;
-	}
-	if(conn->isChief) {
-		if(!sendInt(conn, "CFG\nMAZE_SIZE", mazeSize)) {
-			conn->map->mazeSize = mazeSize;
-			return 0;
-		}
-	}
-	return -1;
-}
-
-int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed) {
-	if(log_badargs_if2(conn==NULL, seed==NULL)) {
-		return -1;
-	}
-	if(conn->isChief) {
-		if(!sendStr(conn, "CFG\nSEED", seed)) {
-			char *copy = flib_strdupnull(seed);
-			if(copy) {
-				free(conn->map->seed);
-				conn->map->seed = copy;
-				return 0;
-			}
-		}
-	}
-	return -1;
-}
-
-int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme) {
-	if(log_badargs_if2(conn==NULL, theme==NULL)) {
-		return -1;
-	}
-	if(conn->isChief) {
-		if(!sendStr(conn, "CFG\nTHEME", theme)) {
-			char *copy = flib_strdupnull(theme);
-			if(copy) {
-				free(conn->map->theme);
-				conn->map->theme = copy;
-				return 0;
-			}
-		}
-	}
-	return -1;
-}
-
-int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size) {
-	int result = -1;
-	if(!log_badargs_if3(conn==NULL, drawData==NULL && size>0, size>SIZE_MAX/2) && conn->isChief) {
-		uLongf zippedSize = compressBound(size);
-		uint8_t *zipped = flib_malloc(zippedSize+4); // 4 extra bytes for header
-		if(zipped) {
-			// Create the QCompress size header (uint32 big endian)
-			zipped[0] = (size>>24) & 0xff;
-			zipped[1] = (size>>16) & 0xff;
-			zipped[2] = (size>>8) & 0xff;
-			zipped[3] = (size) & 0xff;
-
-			if(compress(zipped+4, &zippedSize, drawData, size) != Z_OK) {
-				flib_log_e("Error compressing drawn map data.");
-			} else {
-				char *base64encout = NULL;
-				base64_encode_alloc((const char*)zipped, zippedSize+4, &base64encout);
-				if(!base64encout) {
-					flib_log_e("Error base64-encoding drawn map data.");
-				} else {
-					result = flib_netbase_sendf(conn->netBase, "CFG\nDRAWNMAP\n%s\n\n", base64encout);
-				}
-				free(base64encout);
-			}
-		}
-		free(zipped);
-	}
-
-	if(!result) {
-		uint8_t *copy = flib_bufdupnull(drawData, size);
-		if(copy) {
-			free(conn->map->drawData);
-			conn->map->drawData = copy;
-			conn->map->drawDataSize = size;
-		}
-	}
-	return result;
-}
-
-int flib_netconn_send_script(flib_netconn *conn, const char *scriptName) {
-	if(log_badargs_if2(conn==NULL, scriptName==NULL)) {
-		return -1;
-	}
-	if(conn->isChief) {
-		if(!sendStr(conn, "CFG\nSCRIPT", scriptName)) {
-			netconn_setScript(conn, scriptName);
-			return 0;
-		}
-	}
-	return -1;
-}
-
-int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme) {
-	int result = -1;
-	if(!log_badargs_if3(conn==NULL, scheme==NULL, flib_strempty(scheme->name)) && conn->isChief) {
-		flib_vector *vec = flib_vector_create();
-		if(vec) {
-			bool error = false;
-			error |= flib_vector_appendf(vec, "CFG\nSCHEME\n%s\n", scheme->name);
-			for(int i=0; i<flib_meta.modCount; i++) {
-				error |= flib_vector_appendf(vec, "%s\n", scheme->mods[i] ? "true" : "false");
-			}
-			for(int i=0; i<flib_meta.settingCount; i++) {
-				error |= flib_vector_appendf(vec, "%i\n", scheme->settings[i]);
-			}
-			error |= flib_vector_appendf(vec, "\n");
-			if(!error) {
-				result = flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec));
-			}
-		}
-		flib_vector_destroy(vec);
-	}
-
-	if(!result) {
-		netconn_setScheme(conn, scheme);
-	}
-	return result;
-}
-
-int flib_netconn_send_startGame(flib_netconn *conn) {
-	return sendVoid(conn, "START_GAME");
-}
-
-int flib_netconn_send_toggleRestrictJoins(flib_netconn *conn) {
-	return sendVoid(conn, "TOGGLE_RESTRICT_JOINS");
-}
-
-int flib_netconn_send_toggleRestrictTeams(flib_netconn *conn) {
-	return sendVoid(conn, "TOGGLE_RESTRICT_TEAMS");
-}
-
-int flib_netconn_send_teamchat(flib_netconn *conn, const char *chat) {
-	if(!flib_strempty(chat)) {
-		return sendStr(conn, "TEAMCHAT", chat);
-	}
-	return 0;
-}
-
-int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size) {
-	int result = -1;
-	if(!log_badargs_if2(conn==NULL, message==NULL && size>0)) {
-		char *base64encout = NULL;
-		base64_encode_alloc((const char*)message, size, &base64encout);
-		if(base64encout) {
-			result = flib_netbase_sendf(conn->netBase, "EM\n%s\n\n", base64encout);
-		}
-		free(base64encout);
-	}
-	return result;
-}
-
-int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError) {
-	return sendInt(conn, "ROUNDFINISHED", withoutError ? 1 : 0);
-}
-
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "netconn_internal.h"
+
+#include "../util/logging.h"
+#include "../util/util.h"
+#include "../util/buffer.h"
+#include "../md5/md5.h"
+#include "../base64/base64.h"
+
+#include <zlib.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+// cmdname is always given as literal from functions in this file, so it is never null.
+static int sendVoid(flib_netconn *conn, const char *cmdname) {
+    if(log_e_if(!conn, "Invalid parameter sending %s command", cmdname)) {
+        return -1;
+    }
+    return flib_netbase_sendf(conn->netBase, "%s\n\n", cmdname);
+}
+
+// Testing for !*str prevents sending 0-length parameters (they trip up the protocol)
+static int sendStr(flib_netconn *conn, const char *cmdname, const char *str) {
+    if(log_e_if(!conn || flib_strempty(str), "Invalid parameter sending %s command", cmdname)) {
+        return -1;
+    }
+    return flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", cmdname, str);
+}
+
+static int sendInt(flib_netconn *conn, const char *cmdname, int param) {
+    if(log_e_if(!conn, "Invalid parameter sending %s command", cmdname)) {
+        return -1;
+    }
+    return flib_netbase_sendf(conn->netBase, "%s\n%i\n\n", cmdname, param);
+}
+
+int flib_netconn_send_nick(flib_netconn *conn, const char *nick) {
+    int result = -1;
+    if(!log_badargs_if2(conn==NULL, flib_strempty(nick))) {
+        char *tmpName = flib_strdupnull(nick);
+        if(tmpName) {
+            if(!flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "NICK", nick)) {
+                free(conn->playerName);
+                conn->playerName = tmpName;
+                tmpName = NULL;
+                result = 0;
+            }
+        }
+        free(tmpName);
+    }
+    return result;
+}
+
+int flib_netconn_send_password(flib_netconn *conn, const char *passwd) {
+    int result = -1;
+    if(!log_badargs_if2(conn==NULL, passwd==NULL)) {
+        md5_state_t md5state;
+        uint8_t md5bytes[16];
+        char md5hex[33];
+        md5_init(&md5state);
+        md5_append(&md5state, (unsigned char*)passwd, strlen(passwd));
+        md5_finish(&md5state, md5bytes);
+        for(int i=0;i<sizeof(md5bytes); i++) {
+            // Needs to be lowercase - server checks case sensitive
+            snprintf(md5hex+i*2, 3, "%02x", (unsigned)md5bytes[i]);
+        }
+        result = flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "PASSWORD", md5hex);
+    }
+    return result;
+}
+
+int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg) {
+    return sendStr(conn, "QUIT", (quitmsg && *quitmsg) ? quitmsg : "User quit");
+}
+
+int flib_netconn_send_chat(flib_netconn *conn, const char *chat) {
+    if(!flib_strempty(chat)) {
+        return sendStr(conn, "CHAT", chat);
+    }
+    return 0;
+}
+
+int flib_netconn_send_kick(flib_netconn *conn, const char *playerName) {
+    return sendStr(conn, "KICK", playerName);
+}
+
+int flib_netconn_send_playerInfo(flib_netconn *conn, const char *playerName) {
+    return sendStr(conn, "INFO", playerName);
+}
+
+int flib_netconn_send_request_roomlist(flib_netconn *conn) {
+    return sendVoid(conn, "LIST");
+}
+
+int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room) {
+    if(!sendStr(conn, "JOIN_ROOM", room)) {
+        conn->isChief = false;
+        return 0;
+    }
+    return -1;
+}
+
+int flib_netconn_send_playerFollow(flib_netconn *conn, const char *playerName) {
+    return sendStr(conn, "FOLLOW", playerName);
+}
+
+int flib_netconn_send_createRoom(flib_netconn *conn, const char *room) {
+    if(!sendStr(conn, "CREATE_ROOM", room)) {
+        conn->isChief = true;
+        return 0;
+    }
+    return -1;
+}
+
+int flib_netconn_send_ban(flib_netconn *conn, const char *playerName) {
+    return sendStr(conn, "BAN", playerName);
+}
+
+int flib_netconn_send_clearAccountsCache(flib_netconn *conn) {
+    return sendVoid(conn, "CLEAR_ACCOUNTS_CACHE");
+}
+
+int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value) {
+    if(log_badargs_if3(conn==NULL, flib_strempty(name), flib_strempty(value))) {
+        return -1;
+    }
+    return flib_netbase_sendf(conn->netBase, "%s\n%s\n%s\n\n", "SET_SERVER_VAR", name, value);
+}
+
+int flib_netconn_send_getServerVars(flib_netconn *conn) {
+    return sendVoid(conn, "GET_SERVER_VAR");
+}
+int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *str) {
+    int result = -1;
+    if(conn->netconnState==NETCONN_STATE_ROOM) {
+        result = (str && *str) ? sendStr(conn, "PART", str) : sendVoid(conn, "PART");
+        if(!result) {
+            netconn_leaveRoom(conn);
+        }
+    }
+    return result;
+}
+
+int flib_netconn_send_toggleReady(flib_netconn *conn) {
+    return sendVoid(conn, "TOGGLE_READY");
+}
+
+static void addTeamToPendingList(flib_netconn *conn, const flib_team *team) {
+    flib_team *teamcopy = flib_team_copy(team);
+    if(teamcopy) {
+        teamcopy->remoteDriven = false;
+        free(teamcopy->ownerName);
+        teamcopy->ownerName = flib_strdupnull(conn->playerName);
+        if(teamcopy->ownerName) {
+            flib_teamlist_delete(&conn->pendingTeamlist, team->name);
+            if(!flib_teamlist_insert(&conn->pendingTeamlist, teamcopy, 0)) {
+                teamcopy = NULL;
+            }
+        }
+    }
+    flib_team_destroy(teamcopy);
+}
+
+int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team) {
+    int result = -1;
+    if(!log_badargs_if2(conn==NULL, team==NULL)) {
+        bool missingInfo = flib_strempty(team->name) || flib_strempty(team->grave) || flib_strempty(team->fort) || flib_strempty(team->voicepack) || flib_strempty(team->flag);
+        for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+            missingInfo |= flib_strempty(team->hogs[i].name) || flib_strempty(team->hogs[i].hat);
+        }
+        if(!log_e_if(missingInfo, "Incomplete team definition")) {
+            flib_vector *vec = flib_vector_create();
+            if(vec) {
+                bool error = false;
+                error |= flib_vector_appendf(vec, "ADD_TEAM\n%s\n%i\n%s\n%s\n%s\n%s\n%i\n", team->name, team->colorIndex, team->grave, team->fort, team->voicepack, team->flag, team->hogs[0].difficulty);
+                for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+                    error |= flib_vector_appendf(vec, "%s\n%s\n", team->hogs[i].name, team->hogs[i].hat);
+                }
+                error |= flib_vector_appendf(vec, "\n");
+                if(!error && !flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec))) {
+                    addTeamToPendingList(conn, team);
+                    result = 0;
+                }
+            }
+            flib_vector_destroy(vec);
+        }
+    }
+    return result;
+}
+
+int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname) {
+    flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
+    if(team && !team->remoteDriven && !sendStr(conn, "REMOVE_TEAM", teamname)) {
+        flib_teamlist_delete(&conn->teamlist, teamname);
+        return 0;
+    }
+    return -1;
+}
+
+int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName) {
+    return sendStr(conn, "ROOM_NAME", roomName);
+}
+
+int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount) {
+    if(!log_badargs_if5(conn==NULL, flib_strempty(teamname), hogcount<1, hogcount>HEDGEHOGS_PER_TEAM, !conn->isChief)
+            && !flib_netbase_sendf(conn->netBase, "HH_NUM\n%s\n%i\n\n", teamname, hogcount)) {
+        flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
+        if(team) {
+            team->hogsInGame = hogcount;
+        }
+        return 0;
+    }
+    return -1;
+}
+
+int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex) {
+    if(!log_badargs_if3(conn==NULL, flib_strempty(teamname), !conn->isChief)
+            && !flib_netbase_sendf(conn->netBase, "TEAM_COLOR\n%s\n%i\n\n", teamname, colorIndex)) {
+        flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
+        if(team) {
+            team->colorIndex = colorIndex;
+        }
+        return 0;
+    }
+    return -1;
+}
+
+int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset) {
+    if(!log_badargs_if3(conn==NULL, weaponset==NULL, flib_strempty(weaponset->name))) {
+        char ammostring[WEAPONS_COUNT*4+1];
+        strcpy(ammostring, weaponset->loadout);
+        strcat(ammostring, weaponset->crateprob);
+        strcat(ammostring, weaponset->delay);
+        strcat(ammostring, weaponset->crateammo);
+        if(conn->isChief) {
+            if(!flib_netbase_sendf(conn->netBase, "CFG\nAMMO\n%s\n%s\n\n", weaponset->name, ammostring)) {
+                netconn_setWeaponset(conn, weaponset);
+                return 0;
+            }
+        }
+    }
+    return -1;
+}
+
+int flib_netconn_send_map(flib_netconn *conn, const flib_map *map) {
+    if(log_badargs_if2(conn==NULL, map==NULL)) {
+        return -1;
+    }
+    bool error = false;
+
+    if(map->seed) {
+        error |= flib_netconn_send_mapSeed(conn, map->seed);
+    }
+    error |= flib_netconn_send_mapTemplate(conn, map->templateFilter);
+    if(map->theme) {
+        error |= flib_netconn_send_mapTheme(conn, map->theme);
+    }
+    error |= flib_netconn_send_mapGen(conn, map->mapgen);
+    error |= flib_netconn_send_mapMazeSize(conn, map->mazeSize);
+    if(map->drawData && map->drawDataSize>0) {
+        error |= flib_netconn_send_mapDrawdata(conn, map->drawData, map->drawDataSize);
+    }
+    // Name is sent last, because the QtFrontend uses this to update its preview, and to show/hide
+    // certain fields
+    if(map->name) {
+        error |= flib_netconn_send_mapName(conn, map->name);
+    }
+    return error;
+}
+
+int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName) {
+    if(log_badargs_if2(conn==NULL, mapName==NULL)) {
+        return -1;
+    }
+    if(conn->isChief) {
+        if(!sendStr(conn, "CFG\nMAP", mapName)) {
+            char *copy = flib_strdupnull(mapName);
+            if(copy) {
+                free(conn->map->name);
+                conn->map->name = copy;
+                return 0;
+            }
+        }
+    }
+    return -1;
+}
+
+int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen) {
+    if(log_badargs_if(conn==NULL)) {
+        return -1;
+    }
+    if(conn->isChief) {
+        if(!sendInt(conn, "CFG\nMAPGEN", mapGen)) {
+            conn->map->mapgen = mapGen;
+            return 0;
+        }
+    }
+    return -1;
+}
+
+int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter) {
+    if(log_badargs_if(conn==NULL)) {
+        return -1;
+    }
+    if(conn->isChief) {
+        if(!sendInt(conn, "CFG\nTEMPLATE", templateFilter)) {
+            conn->map->templateFilter = templateFilter;
+            return 0;
+        }
+    }
+    return -1;
+}
+
+int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize) {
+    if(log_badargs_if(conn==NULL)) {
+        return -1;
+    }
+    if(conn->isChief) {
+        if(!sendInt(conn, "CFG\nMAZE_SIZE", mazeSize)) {
+            conn->map->mazeSize = mazeSize;
+            return 0;
+        }
+    }
+    return -1;
+}
+
+int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed) {
+    if(log_badargs_if2(conn==NULL, seed==NULL)) {
+        return -1;
+    }
+    if(conn->isChief) {
+        if(!sendStr(conn, "CFG\nSEED", seed)) {
+            char *copy = flib_strdupnull(seed);
+            if(copy) {
+                free(conn->map->seed);
+                conn->map->seed = copy;
+                return 0;
+            }
+        }
+    }
+    return -1;
+}
+
+int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme) {
+    if(log_badargs_if2(conn==NULL, theme==NULL)) {
+        return -1;
+    }
+    if(conn->isChief) {
+        if(!sendStr(conn, "CFG\nTHEME", theme)) {
+            char *copy = flib_strdupnull(theme);
+            if(copy) {
+                free(conn->map->theme);
+                conn->map->theme = copy;
+                return 0;
+            }
+        }
+    }
+    return -1;
+}
+
+int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size) {
+    int result = -1;
+    if(!log_badargs_if3(conn==NULL, drawData==NULL && size>0, size>SIZE_MAX/2) && conn->isChief) {
+        uLongf zippedSize = compressBound(size);
+        uint8_t *zipped = flib_malloc(zippedSize+4); // 4 extra bytes for header
+        if(zipped) {
+            // Create the QCompress size header (uint32 big endian)
+            zipped[0] = (size>>24) & 0xff;
+            zipped[1] = (size>>16) & 0xff;
+            zipped[2] = (size>>8) & 0xff;
+            zipped[3] = (size) & 0xff;
+
+            if(compress(zipped+4, &zippedSize, drawData, size) != Z_OK) {
+                flib_log_e("Error compressing drawn map data.");
+            } else {
+                char *base64encout = NULL;
+                base64_encode_alloc((const char*)zipped, zippedSize+4, &base64encout);
+                if(!base64encout) {
+                    flib_log_e("Error base64-encoding drawn map data.");
+                } else {
+                    result = flib_netbase_sendf(conn->netBase, "CFG\nDRAWNMAP\n%s\n\n", base64encout);
+                }
+                free(base64encout);
+            }
+        }
+        free(zipped);
+    }
+
+    if(!result) {
+        uint8_t *copy = flib_bufdupnull(drawData, size);
+        if(copy) {
+            free(conn->map->drawData);
+            conn->map->drawData = copy;
+            conn->map->drawDataSize = size;
+        }
+    }
+    return result;
+}
+
+int flib_netconn_send_script(flib_netconn *conn, const char *scriptName) {
+    if(log_badargs_if2(conn==NULL, scriptName==NULL)) {
+        return -1;
+    }
+    if(conn->isChief) {
+        if(!sendStr(conn, "CFG\nSCRIPT", scriptName)) {
+            netconn_setScript(conn, scriptName);
+            return 0;
+        }
+    }
+    return -1;
+}
+
+int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme) {
+    int result = -1;
+    if(!log_badargs_if3(conn==NULL, scheme==NULL, flib_strempty(scheme->name)) && conn->isChief) {
+        flib_vector *vec = flib_vector_create();
+        if(vec) {
+            bool error = false;
+            error |= flib_vector_appendf(vec, "CFG\nSCHEME\n%s\n", scheme->name);
+            for(int i=0; i<flib_meta.modCount; i++) {
+                error |= flib_vector_appendf(vec, "%s\n", scheme->mods[i] ? "true" : "false");
+            }
+            for(int i=0; i<flib_meta.settingCount; i++) {
+                error |= flib_vector_appendf(vec, "%i\n", scheme->settings[i]);
+            }
+            error |= flib_vector_appendf(vec, "\n");
+            if(!error) {
+                result = flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec));
+            }
+        }
+        flib_vector_destroy(vec);
+    }
+
+    if(!result) {
+        netconn_setScheme(conn, scheme);
+    }
+    return result;
+}
+
+int flib_netconn_send_startGame(flib_netconn *conn) {
+    return sendVoid(conn, "START_GAME");
+}
+
+int flib_netconn_send_toggleRestrictJoins(flib_netconn *conn) {
+    return sendVoid(conn, "TOGGLE_RESTRICT_JOINS");
+}
+
+int flib_netconn_send_toggleRestrictTeams(flib_netconn *conn) {
+    return sendVoid(conn, "TOGGLE_RESTRICT_TEAMS");
+}
+
+int flib_netconn_send_teamchat(flib_netconn *conn, const char *chat) {
+    if(!flib_strempty(chat)) {
+        return sendStr(conn, "TEAMCHAT", chat);
+    }
+    return 0;
+}
+
+int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size) {
+    int result = -1;
+    if(!log_badargs_if2(conn==NULL, message==NULL && size>0)) {
+        char *base64encout = NULL;
+        base64_encode_alloc((const char*)message, size, &base64encout);
+        if(base64encout) {
+            result = flib_netbase_sendf(conn->netBase, "EM\n%s\n\n", base64encout);
+        }
+        free(base64encout);
+    }
+    return result;
+}
+
+int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError) {
+    return sendInt(conn, "ROUNDFINISHED", withoutError ? 1 : 0);
+}
+
--- a/project_files/frontlib/net/netprotocol.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netprotocol.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,192 +1,192 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "netprotocol.h"
-
-#include "../util/util.h"
-#include "../util/logging.h"
-
-#include "../base64/base64.h"
-
-#include <zlib.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-
-static int fillTeamFromMsg(flib_team *team, char **parts) {
-	team->name = flib_strdupnull(parts[0]);
-	team->grave = flib_strdupnull(parts[1]);
-	team->fort = flib_strdupnull(parts[2]);
-	team->voicepack = flib_strdupnull(parts[3]);
-	team->flag = flib_strdupnull(parts[4]);
-	team->ownerName = flib_strdupnull(parts[5]);
-	if(!team->name || !team->grave || !team->fort || !team->voicepack || !team->flag || !team->ownerName) {
-		return -1;
-	}
-
-	errno = 0;
-	long difficulty = strtol(parts[6], NULL, 10);
-	if(errno) {
-		return -1;
-	}
-
-	for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
-		flib_hog *hog = &team->hogs[i];
-		hog->difficulty = difficulty;
-		hog->name = flib_strdupnull(parts[7+2*i]);
-		hog->hat = flib_strdupnull(parts[8+2*i]);
-		if(!hog->name || !hog->hat) {
-			return -1;
-		}
-	}
-
-	// Set some default assumptions as well
-	team->colorIndex = DEFAULT_COLOR_INDEX;
-	team->hogsInGame = DEFAULT_HEDGEHOG_COUNT;
-	team->remoteDriven = true;
-	return 0;
-}
-
-flib_team *flib_team_from_netmsg(char **parts) {
-	flib_team *result = NULL;
-	flib_team *tmpTeam = flib_calloc(1, sizeof(flib_team));
-	if(tmpTeam) {
-		if(!fillTeamFromMsg(tmpTeam, parts)) {
-			result = tmpTeam;
-			tmpTeam = NULL;
-		} else {
-			flib_log_e("Error parsing team from net.");
-		}
-	}
-	flib_team_destroy(tmpTeam);
-	return result;
-}
-
-flib_scheme *flib_scheme_from_netmsg(char **parts) {
-	flib_scheme *result = flib_scheme_create(parts[0]);
-	if(result) {
-		for(int i=0; i<flib_meta.modCount; i++) {
-			result->mods[i] = !strcmp(parts[i+1], "true");
-		}
-		for(int i=0; i<flib_meta.settingCount; i++) {
-			result->settings[i] = atoi(parts[i+flib_meta.modCount+1]);
-		}
-	}
-	return result;
-}
-
-flib_map *flib_map_from_netmsg(char **parts) {
-	flib_map *result = flib_map_create_named(parts[3], parts[0]);
-	if(result) {
-		result->mapgen = atoi(parts[1]);
-		result->mazeSize = atoi(parts[2]);
-		result->templateFilter = atoi(parts[4]);
-	}
-	return result;
-}
-
-int flib_drawnmapdata_from_netmsg(char *netmsg, uint8_t** outbuf, size_t *outlen) {
-	int result = -1;
-
-	// First step: base64 decoding
-	char *base64decout = NULL;
-	size_t base64declen;
-	bool ok = base64_decode_alloc(netmsg, strlen(netmsg), &base64decout, &base64declen);
-	if(ok && base64declen>3) {
-		// Second step: unzip with the QCompress header. That header is just a big-endian
-		// uint32 indicating the length of the uncompressed data.
-		uint8_t *ubyteBuf = (uint8_t*)base64decout;
-		uint32_t unzipLen =
-				(((uint32_t)ubyteBuf[0])<<24)
-				+ (((uint32_t)ubyteBuf[1])<<16)
-				+ (((uint32_t)ubyteBuf[2])<<8)
-				+ ubyteBuf[3];
-		if(unzipLen==0) {
-			*outbuf = NULL;
-			*outlen = 0;
-			result = 0;
-		} else {
-			uint8_t *out = flib_malloc(unzipLen);
-			if(out) {
-				uLongf actualUnzipLen = unzipLen;
-				int resultcode = uncompress(out, &actualUnzipLen, (Bytef*)(base64decout+4), base64declen-4);
-				if(resultcode == Z_OK) {
-					*outbuf = out;
-					*outlen = actualUnzipLen;
-					out = NULL;
-					result = 0;
-				} else {
-					flib_log_e("Uncompressing drawn map failed. Code: %i", resultcode);
-				}
-			}
-			free(out);
-		}
-	} else {
-		flib_log_e("base64 decoding of drawn map failed.");
-	}
-	free(base64decout);
-	return result;
-}
-
-flib_room *flib_room_from_netmsg(char **params) {
-	flib_room *result = NULL;
-	flib_room *tmpRoom = flib_calloc(1, sizeof(flib_room));
-	if(tmpRoom) {
-		tmpRoom->inProgress = !strcmp(params[0], "True");
-		tmpRoom->name = flib_strdupnull(params[1]);
-		tmpRoom->playerCount = atoi(params[2]);
-		tmpRoom->teamCount = atoi(params[3]);
-		tmpRoom->owner = flib_strdupnull(params[4]);
-		tmpRoom->map = flib_strdupnull(params[5]);
-		tmpRoom->scheme = flib_strdupnull(params[6]);
-		tmpRoom->weapons = flib_strdupnull(params[7]);
-		if(tmpRoom->name && tmpRoom->owner && tmpRoom->map && tmpRoom->scheme && tmpRoom->weapons) {
-			result = tmpRoom;
-			tmpRoom = NULL;
-		}
-	}
-	flib_room_destroy(tmpRoom);
-	return result;
-}
-
-int fillRoomArray(flib_room **array, char **params, int count) {
-	for(int i=0; i<count; i++) {
-		array[i] = flib_room_from_netmsg(params + 8*i);
-		if(!array[i]) {
-			return -1;
-		}
-	}
-	return 0;
-}
-
-flib_room **flib_room_array_from_netmsg(char **params, int count) {
-	flib_room **result = flib_calloc(count, sizeof(flib_room*));
-	if(result) {
-		if(fillRoomArray(result, params, count)) {
-			for(int i=0; i<count; i++) {
-				flib_room_destroy(result[i]);
-			}
-			free(result);
-			result = NULL;
-		}
-	}
-	return result;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "netprotocol.h"
+
+#include "../util/util.h"
+#include "../util/logging.h"
+
+#include "../base64/base64.h"
+
+#include <zlib.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+
+static int fillTeamFromMsg(flib_team *team, char **parts) {
+    team->name = flib_strdupnull(parts[0]);
+    team->grave = flib_strdupnull(parts[1]);
+    team->fort = flib_strdupnull(parts[2]);
+    team->voicepack = flib_strdupnull(parts[3]);
+    team->flag = flib_strdupnull(parts[4]);
+    team->ownerName = flib_strdupnull(parts[5]);
+    if(!team->name || !team->grave || !team->fort || !team->voicepack || !team->flag || !team->ownerName) {
+        return -1;
+    }
+
+    errno = 0;
+    long difficulty = strtol(parts[6], NULL, 10);
+    if(errno) {
+        return -1;
+    }
+
+    for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
+        flib_hog *hog = &team->hogs[i];
+        hog->difficulty = difficulty;
+        hog->name = flib_strdupnull(parts[7+2*i]);
+        hog->hat = flib_strdupnull(parts[8+2*i]);
+        if(!hog->name || !hog->hat) {
+            return -1;
+        }
+    }
+
+    // Set some default assumptions as well
+    team->colorIndex = DEFAULT_COLOR_INDEX;
+    team->hogsInGame = DEFAULT_HEDGEHOG_COUNT;
+    team->remoteDriven = true;
+    return 0;
+}
+
+flib_team *flib_team_from_netmsg(char **parts) {
+    flib_team *result = NULL;
+    flib_team *tmpTeam = flib_calloc(1, sizeof(flib_team));
+    if(tmpTeam) {
+        if(!fillTeamFromMsg(tmpTeam, parts)) {
+            result = tmpTeam;
+            tmpTeam = NULL;
+        } else {
+            flib_log_e("Error parsing team from net.");
+        }
+    }
+    flib_team_destroy(tmpTeam);
+    return result;
+}
+
+flib_scheme *flib_scheme_from_netmsg(char **parts) {
+    flib_scheme *result = flib_scheme_create(parts[0]);
+    if(result) {
+        for(int i=0; i<flib_meta.modCount; i++) {
+            result->mods[i] = !strcmp(parts[i+1], "true");
+        }
+        for(int i=0; i<flib_meta.settingCount; i++) {
+            result->settings[i] = atoi(parts[i+flib_meta.modCount+1]);
+        }
+    }
+    return result;
+}
+
+flib_map *flib_map_from_netmsg(char **parts) {
+    flib_map *result = flib_map_create_named(parts[3], parts[0]);
+    if(result) {
+        result->mapgen = atoi(parts[1]);
+        result->mazeSize = atoi(parts[2]);
+        result->templateFilter = atoi(parts[4]);
+    }
+    return result;
+}
+
+int flib_drawnmapdata_from_netmsg(char *netmsg, uint8_t** outbuf, size_t *outlen) {
+    int result = -1;
+
+    // First step: base64 decoding
+    char *base64decout = NULL;
+    size_t base64declen;
+    bool ok = base64_decode_alloc(netmsg, strlen(netmsg), &base64decout, &base64declen);
+    if(ok && base64declen>3) {
+        // Second step: unzip with the QCompress header. That header is just a big-endian
+        // uint32 indicating the length of the uncompressed data.
+        uint8_t *ubyteBuf = (uint8_t*)base64decout;
+        uint32_t unzipLen =
+                (((uint32_t)ubyteBuf[0])<<24)
+                + (((uint32_t)ubyteBuf[1])<<16)
+                + (((uint32_t)ubyteBuf[2])<<8)
+                + ubyteBuf[3];
+        if(unzipLen==0) {
+            *outbuf = NULL;
+            *outlen = 0;
+            result = 0;
+        } else {
+            uint8_t *out = flib_malloc(unzipLen);
+            if(out) {
+                uLongf actualUnzipLen = unzipLen;
+                int resultcode = uncompress(out, &actualUnzipLen, (Bytef*)(base64decout+4), base64declen-4);
+                if(resultcode == Z_OK) {
+                    *outbuf = out;
+                    *outlen = actualUnzipLen;
+                    out = NULL;
+                    result = 0;
+                } else {
+                    flib_log_e("Uncompressing drawn map failed. Code: %i", resultcode);
+                }
+            }
+            free(out);
+        }
+    } else {
+        flib_log_e("base64 decoding of drawn map failed.");
+    }
+    free(base64decout);
+    return result;
+}
+
+flib_room *flib_room_from_netmsg(char **params) {
+    flib_room *result = NULL;
+    flib_room *tmpRoom = flib_calloc(1, sizeof(flib_room));
+    if(tmpRoom) {
+        tmpRoom->inProgress = !strcmp(params[0], "True");
+        tmpRoom->name = flib_strdupnull(params[1]);
+        tmpRoom->playerCount = atoi(params[2]);
+        tmpRoom->teamCount = atoi(params[3]);
+        tmpRoom->owner = flib_strdupnull(params[4]);
+        tmpRoom->map = flib_strdupnull(params[5]);
+        tmpRoom->scheme = flib_strdupnull(params[6]);
+        tmpRoom->weapons = flib_strdupnull(params[7]);
+        if(tmpRoom->name && tmpRoom->owner && tmpRoom->map && tmpRoom->scheme && tmpRoom->weapons) {
+            result = tmpRoom;
+            tmpRoom = NULL;
+        }
+    }
+    flib_room_destroy(tmpRoom);
+    return result;
+}
+
+int fillRoomArray(flib_room **array, char **params, int count) {
+    for(int i=0; i<count; i++) {
+        array[i] = flib_room_from_netmsg(params + 8*i);
+        if(!array[i]) {
+            return -1;
+        }
+    }
+    return 0;
+}
+
+flib_room **flib_room_array_from_netmsg(char **params, int count) {
+    flib_room **result = flib_calloc(count, sizeof(flib_room*));
+    if(result) {
+        if(fillRoomArray(result, params, count)) {
+            for(int i=0; i<count; i++) {
+                flib_room_destroy(result[i]);
+            }
+            free(result);
+            result = NULL;
+        }
+    }
+    return result;
+}
--- a/project_files/frontlib/net/netprotocol.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/net/netprotocol.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,66 +1,66 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef NETPROTOCOL_H_
-#define NETPROTOCOL_H_
-
-#include "../model/team.h"
-#include "../model/scheme.h"
-#include "../model/map.h"
-#include "../model/room.h"
-
-#include <stddef.h>
-
-/**
- * Create a new team from this 23-part net message
- */
-flib_team *flib_team_from_netmsg(char **parts);
-
-/**
- * Create a new scheme from this net message, which must have
- * meta->modCount+meta->settingCount+1 parts.
- */
-flib_scheme *flib_scheme_from_netmsg(char **parts);
-
-/**
- * Create a new map from this five-part netmsg
- */
-flib_map *flib_map_from_netmsg(char **parts);
-
-/**
- * Decode the drawn map data from this netmessage line.
- *
- * The data is first base64 decoded and then quncompress()ed.
- * The return value is a newly allocated byte buffer, the length
- * is written to the variable pointed to by outlen.
- * Returns NULL on error.
- */
-int flib_drawnmapdata_from_netmsg(char *netmsg, uint8_t **outbuf, size_t *outlen);
-
-/**
- * Create a new room from this 8-part net message
- */
-flib_room *flib_room_from_netmsg(char **params);
-
-/**
- * Create an array of count rooms from count*8 netmessage parts
- */
-flib_room **flib_room_array_from_netmsg(char **params, int count);
-
-#endif /* NETPROTOCOL_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef NETPROTOCOL_H_
+#define NETPROTOCOL_H_
+
+#include "../model/team.h"
+#include "../model/scheme.h"
+#include "../model/map.h"
+#include "../model/room.h"
+
+#include <stddef.h>
+
+/**
+ * Create a new team from this 23-part net message
+ */
+flib_team *flib_team_from_netmsg(char **parts);
+
+/**
+ * Create a new scheme from this net message, which must have
+ * meta->modCount+meta->settingCount+1 parts.
+ */
+flib_scheme *flib_scheme_from_netmsg(char **parts);
+
+/**
+ * Create a new map from this five-part netmsg
+ */
+flib_map *flib_map_from_netmsg(char **parts);
+
+/**
+ * Decode the drawn map data from this netmessage line.
+ *
+ * The data is first base64 decoded and then quncompress()ed.
+ * The return value is a newly allocated byte buffer, the length
+ * is written to the variable pointed to by outlen.
+ * Returns NULL on error.
+ */
+int flib_drawnmapdata_from_netmsg(char *netmsg, uint8_t **outbuf, size_t *outlen);
+
+/**
+ * Create a new room from this 8-part net message
+ */
+flib_room *flib_room_from_netmsg(char **params);
+
+/**
+ * Create an array of count rooms from count*8 netmessage parts
+ */
+flib_room **flib_room_array_from_netmsg(char **params, int count);
+
+#endif /* NETPROTOCOL_H_ */
--- a/project_files/frontlib/socket.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/socket.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,191 +1,191 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "socket.h"
-#include "util/logging.h"
-#include "util/util.h"
-#include <stdlib.h>
-#include <SDL_net.h>
-#include <time.h>
-
-struct _flib_tcpsocket {
-	TCPsocket sock;
-	SDLNet_SocketSet sockset;
-};
-
-struct _flib_acceptor {
-	TCPsocket sock;
-	uint16_t port;
-};
-
-static uint32_t getPeerIp(TCPsocket sock) {
-	IPaddress *addr = SDLNet_TCP_GetPeerAddress(sock);
-	return SDLNet_Read32(&addr->host);
-}
-
-static bool connectionIsLocal(TCPsocket sock) {
-	return getPeerIp(sock) == (uint32_t)((127UL<<24)+1); // 127.0.0.1
-}
-
-static flib_tcpsocket *createSocket(TCPsocket sdlsock) {
-	flib_tcpsocket *result = flib_calloc(1, sizeof(flib_tcpsocket));
-	if(result) {
-		result->sock = sdlsock;
-		result->sockset = SDLNet_AllocSocketSet(1);
-
-		if(!result->sockset) {
-			flib_log_e("Can't allocate socket: Out of memory!");
-			SDLNet_FreeSocketSet(result->sockset);
-			free(result);
-			result = NULL;
-		} else {
-			SDLNet_AddSocket(result->sockset, (SDLNet_GenericSocket)result->sock);
-		}
-	}
-	return result;
-}
-
-TCPsocket listen(uint16_t port) {
-	IPaddress addr;
-	addr.host = INADDR_ANY;
-	SDLNet_Write16(port, &addr.port);
-	TCPsocket sock = SDLNet_TCP_Open(&addr);
-	if(!sock) {
-		flib_log_w("Unable to listen on port %u: %s", (unsigned)port, SDLNet_GetError());
-	}
-	return sock;
-}
-
-flib_acceptor *flib_acceptor_create(uint16_t port) {
-	flib_acceptor *result = flib_calloc(1, sizeof(flib_acceptor));
-	if(result) {
-		if(port > 0) {
-			result->port = port;
-			result->sock = listen(result->port);
-		} else {
-			/* SDL_net does not seem to have a way to listen on a random unused port
-			   and find out which port that is, so let's try to find one ourselves. */
-			srand(time(NULL));
-			for(int i=0; !result->sock && i<1000; i++) {
-				// IANA suggests using ports in the range 49152-65535 for things like this
-				result->port = 49152+(rand()%(65536-49152));
-				result->sock = listen(result->port);
-			}
-		}
-		if(!result->sock) {
-			flib_log_e("Failed to create acceptor.");
-			free(result);
-			result = NULL;
-		}
-	}
-	return result;
-}
-
-uint16_t flib_acceptor_listenport(flib_acceptor *acceptor) {
-	if(!acceptor) {
-		flib_log_e("Call to flib_acceptor_listenport with acceptor==null");
-		return 0;
-	}
-	return acceptor->port;
-}
-
-void flib_acceptor_close(flib_acceptor *acceptor) {
-	if(acceptor) {
-		SDLNet_TCP_Close(acceptor->sock);
-		free(acceptor);
-	}
-}
-
-flib_tcpsocket *flib_socket_accept(flib_acceptor *acceptor, bool localOnly) {
-	flib_tcpsocket *result = NULL;
-	if(!acceptor) {
-		flib_log_e("Call to flib_socket_accept with acceptor==null");
-	} else {
-		TCPsocket sock = NULL;
-		while(!result && (sock = SDLNet_TCP_Accept(acceptor->sock))) {
-			if(localOnly && !connectionIsLocal(sock)) {
-				flib_log_i("Rejected nonlocal connection attempt from %s", flib_format_ip(getPeerIp(sock)));
-			} else {
-				result = createSocket(sock);
-			}
-			if(!result) {
-				SDLNet_TCP_Close(sock);
-			}
-		}
-	}
-	return result;
-}
-
-flib_tcpsocket *flib_socket_connect(const char *host, uint16_t port) {
-	flib_tcpsocket *result = NULL;
-	if(!host || port==0) {
-		flib_log_e("Invalid parameter in flib_socket_connect");
-	} else {
-		IPaddress ip;
-		if(SDLNet_ResolveHost(&ip,host,port)==-1) {
-		   flib_log_e("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
-		} else {
-			TCPsocket sock=SDLNet_TCP_Open(&ip);
-			if(!sock) {
-				flib_log_e("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
-			} else {
-				result = createSocket(sock);
-				if(result) {
-					sock = NULL;
-				}
-			}
-			SDLNet_TCP_Close(sock);
-		}
-	}
-	return result;
-}
-
-void flib_socket_close(flib_tcpsocket *sock) {
-	if(sock) {
-		SDLNet_DelSocket(sock->sockset, (SDLNet_GenericSocket)sock->sock);
-		SDLNet_TCP_Close(sock->sock);
-		SDLNet_FreeSocketSet(sock->sockset);
-		free(sock);
-	}
-}
-
-int flib_socket_nbrecv(flib_tcpsocket *sock, void *data, int maxlen) {
-	if(!sock || (maxlen>0 && !data)) {
-		flib_log_e("Call to flib_socket_nbrecv with sock==null or data==null");
-		return -1;
-	}
-	int readySockets = SDLNet_CheckSockets(sock->sockset, 0);
-	if(readySockets>0) {
-		int size = SDLNet_TCP_Recv(sock->sock, data, maxlen);
-		return size>0 ? size : -1;
-	} else if(readySockets==0) {
-		return 0;
-	} else {
-		flib_log_e("Error in select system call: %s", SDLNet_GetError());
-		return -1;
-	}
-}
-
-int flib_socket_send(flib_tcpsocket *sock, const void *data, int len) {
-	if(!sock || (len>0 && !data)) {
-		flib_log_e("Call to flib_socket_send with sock==null or data==null");
-		return -1;
-	}
-	return SDLNet_TCP_Send(sock->sock, data, len);
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "socket.h"
+#include "util/logging.h"
+#include "util/util.h"
+#include <stdlib.h>
+#include <SDL_net.h>
+#include <time.h>
+
+struct _flib_tcpsocket {
+    TCPsocket sock;
+    SDLNet_SocketSet sockset;
+};
+
+struct _flib_acceptor {
+    TCPsocket sock;
+    uint16_t port;
+};
+
+static uint32_t getPeerIp(TCPsocket sock) {
+    IPaddress *addr = SDLNet_TCP_GetPeerAddress(sock);
+    return SDLNet_Read32(&addr->host);
+}
+
+static bool connectionIsLocal(TCPsocket sock) {
+    return getPeerIp(sock) == (uint32_t)((127UL<<24)+1); // 127.0.0.1
+}
+
+static flib_tcpsocket *createSocket(TCPsocket sdlsock) {
+    flib_tcpsocket *result = flib_calloc(1, sizeof(flib_tcpsocket));
+    if(result) {
+        result->sock = sdlsock;
+        result->sockset = SDLNet_AllocSocketSet(1);
+
+        if(!result->sockset) {
+            flib_log_e("Can't allocate socket: Out of memory!");
+            SDLNet_FreeSocketSet(result->sockset);
+            free(result);
+            result = NULL;
+        } else {
+            SDLNet_AddSocket(result->sockset, (SDLNet_GenericSocket)result->sock);
+        }
+    }
+    return result;
+}
+
+TCPsocket listen(uint16_t port) {
+    IPaddress addr;
+    addr.host = INADDR_ANY;
+    SDLNet_Write16(port, &addr.port);
+    TCPsocket sock = SDLNet_TCP_Open(&addr);
+    if(!sock) {
+        flib_log_w("Unable to listen on port %u: %s", (unsigned)port, SDLNet_GetError());
+    }
+    return sock;
+}
+
+flib_acceptor *flib_acceptor_create(uint16_t port) {
+    flib_acceptor *result = flib_calloc(1, sizeof(flib_acceptor));
+    if(result) {
+        if(port > 0) {
+            result->port = port;
+            result->sock = listen(result->port);
+        } else {
+            /* SDL_net does not seem to have a way to listen on a random unused port
+               and find out which port that is, so let's try to find one ourselves. */
+            srand(time(NULL));
+            for(int i=0; !result->sock && i<1000; i++) {
+                // IANA suggests using ports in the range 49152-65535 for things like this
+                result->port = 49152+(rand()%(65536-49152));
+                result->sock = listen(result->port);
+            }
+        }
+        if(!result->sock) {
+            flib_log_e("Failed to create acceptor.");
+            free(result);
+            result = NULL;
+        }
+    }
+    return result;
+}
+
+uint16_t flib_acceptor_listenport(flib_acceptor *acceptor) {
+    if(!acceptor) {
+        flib_log_e("Call to flib_acceptor_listenport with acceptor==null");
+        return 0;
+    }
+    return acceptor->port;
+}
+
+void flib_acceptor_close(flib_acceptor *acceptor) {
+    if(acceptor) {
+        SDLNet_TCP_Close(acceptor->sock);
+        free(acceptor);
+    }
+}
+
+flib_tcpsocket *flib_socket_accept(flib_acceptor *acceptor, bool localOnly) {
+    flib_tcpsocket *result = NULL;
+    if(!acceptor) {
+        flib_log_e("Call to flib_socket_accept with acceptor==null");
+    } else {
+        TCPsocket sock = NULL;
+        while(!result && (sock = SDLNet_TCP_Accept(acceptor->sock))) {
+            if(localOnly && !connectionIsLocal(sock)) {
+                flib_log_i("Rejected nonlocal connection attempt from %s", flib_format_ip(getPeerIp(sock)));
+            } else {
+                result = createSocket(sock);
+            }
+            if(!result) {
+                SDLNet_TCP_Close(sock);
+            }
+        }
+    }
+    return result;
+}
+
+flib_tcpsocket *flib_socket_connect(const char *host, uint16_t port) {
+    flib_tcpsocket *result = NULL;
+    if(!host || port==0) {
+        flib_log_e("Invalid parameter in flib_socket_connect");
+    } else {
+        IPaddress ip;
+        if(SDLNet_ResolveHost(&ip,host,port)==-1) {
+           flib_log_e("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
+        } else {
+            TCPsocket sock=SDLNet_TCP_Open(&ip);
+            if(!sock) {
+                flib_log_e("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
+            } else {
+                result = createSocket(sock);
+                if(result) {
+                    sock = NULL;
+                }
+            }
+            SDLNet_TCP_Close(sock);
+        }
+    }
+    return result;
+}
+
+void flib_socket_close(flib_tcpsocket *sock) {
+    if(sock) {
+        SDLNet_DelSocket(sock->sockset, (SDLNet_GenericSocket)sock->sock);
+        SDLNet_TCP_Close(sock->sock);
+        SDLNet_FreeSocketSet(sock->sockset);
+        free(sock);
+    }
+}
+
+int flib_socket_nbrecv(flib_tcpsocket *sock, void *data, int maxlen) {
+    if(!sock || (maxlen>0 && !data)) {
+        flib_log_e("Call to flib_socket_nbrecv with sock==null or data==null");
+        return -1;
+    }
+    int readySockets = SDLNet_CheckSockets(sock->sockset, 0);
+    if(readySockets>0) {
+        int size = SDLNet_TCP_Recv(sock->sock, data, maxlen);
+        return size>0 ? size : -1;
+    } else if(readySockets==0) {
+        return 0;
+    } else {
+        flib_log_e("Error in select system call: %s", SDLNet_GetError());
+        return -1;
+    }
+}
+
+int flib_socket_send(flib_tcpsocket *sock, const void *data, int len) {
+    if(!sock || (len>0 && !data)) {
+        flib_log_e("Call to flib_socket_send with sock==null or data==null");
+        return -1;
+    }
+    return SDLNet_TCP_Send(sock->sock, data, len);
+}
--- a/project_files/frontlib/socket.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/socket.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,91 +1,91 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/*
- * Sockets for TCP networking.
- *
- * This layer offers some functionality over what SDL_net offers directly: listening
- * sockets (called acceptors here) can be bound to port 0, which will make them listen
- * on a random unused port, if one can be found. To support this feature, you can also
- * query the local port that an acceptor is listening on.
- *
- * Further, we support nonblocking reads here.
- */
-
-#ifndef SOCKET_H_
-#define SOCKET_H_
-
-#include <stdbool.h>
-#include <stdint.h>
-
-typedef struct _flib_tcpsocket flib_tcpsocket;
-typedef struct _flib_acceptor flib_acceptor;
-
-/**
- * Create a new acceptor which will listen for incoming TCP connections
- * on the given port. If port is 0, this will listen on a random
- * unused port which can then be queried with flib_acceptor_listenport.
- *
- * Returns NULL on error.
- */
-flib_acceptor *flib_acceptor_create(uint16_t port);
-
-/**
- * Return the port on which the acceptor is listening.
- */
-uint16_t flib_acceptor_listenport(flib_acceptor *acceptor);
-
-/**
- * Close the acceptor and free its memory. NULL-safe.
- */
-void flib_acceptor_close(flib_acceptor *acceptor);
-
-/**
- * Try to accept a connection from an acceptor (listening socket).
- * if localOnly is true, this will only accept connections which came from 127.0.0.1
- * Returns NULL if nothing can be accepted.
- */
-flib_tcpsocket *flib_socket_accept(flib_acceptor *acceptor, bool localOnly);
-
-/**
- * Try to connect to the server at the given address.
- */
-flib_tcpsocket *flib_socket_connect(const char *host, uint16_t port);
-
-/**
- * Close the socket and free its memory. NULL-safe.
- */
-void flib_socket_close(flib_tcpsocket *socket);
-
-/**
- * Attempt to receive up to maxlen bytes from the socket, but does not
- * block if nothing is available.
- * Returns the ammount of data received, 0 if there was nothing to receive,
- * or a negative number if the connection was closed or an error occurred.
- */
-int flib_socket_nbrecv(flib_tcpsocket *sock, void *data, int maxlen);
-
-/**
- * Blocking send all the data in the data buffer. Returns the actual ammount
- * of data sent, or a negative value on error. If the value returned here
- * is less than len, either the connection closed or an error occurred.
- */
-int flib_socket_send(flib_tcpsocket *sock, const void *data, int len);
-
-#endif /* SOCKET_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/*
+ * Sockets for TCP networking.
+ *
+ * This layer offers some functionality over what SDL_net offers directly: listening
+ * sockets (called acceptors here) can be bound to port 0, which will make them listen
+ * on a random unused port, if one can be found. To support this feature, you can also
+ * query the local port that an acceptor is listening on.
+ *
+ * Further, we support nonblocking reads here.
+ */
+
+#ifndef SOCKET_H_
+#define SOCKET_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+typedef struct _flib_tcpsocket flib_tcpsocket;
+typedef struct _flib_acceptor flib_acceptor;
+
+/**
+ * Create a new acceptor which will listen for incoming TCP connections
+ * on the given port. If port is 0, this will listen on a random
+ * unused port which can then be queried with flib_acceptor_listenport.
+ *
+ * Returns NULL on error.
+ */
+flib_acceptor *flib_acceptor_create(uint16_t port);
+
+/**
+ * Return the port on which the acceptor is listening.
+ */
+uint16_t flib_acceptor_listenport(flib_acceptor *acceptor);
+
+/**
+ * Close the acceptor and free its memory. NULL-safe.
+ */
+void flib_acceptor_close(flib_acceptor *acceptor);
+
+/**
+ * Try to accept a connection from an acceptor (listening socket).
+ * if localOnly is true, this will only accept connections which came from 127.0.0.1
+ * Returns NULL if nothing can be accepted.
+ */
+flib_tcpsocket *flib_socket_accept(flib_acceptor *acceptor, bool localOnly);
+
+/**
+ * Try to connect to the server at the given address.
+ */
+flib_tcpsocket *flib_socket_connect(const char *host, uint16_t port);
+
+/**
+ * Close the socket and free its memory. NULL-safe.
+ */
+void flib_socket_close(flib_tcpsocket *socket);
+
+/**
+ * Attempt to receive up to maxlen bytes from the socket, but does not
+ * block if nothing is available.
+ * Returns the ammount of data received, 0 if there was nothing to receive,
+ * or a negative number if the connection was closed or an error occurred.
+ */
+int flib_socket_nbrecv(flib_tcpsocket *sock, void *data, int maxlen);
+
+/**
+ * Blocking send all the data in the data buffer. Returns the actual ammount
+ * of data sent, or a negative value on error. If the value returned here
+ * is less than len, either the connection closed or an error occurred.
+ */
+int flib_socket_send(flib_tcpsocket *sock, const void *data, int len);
+
+#endif /* SOCKET_H_ */
--- a/project_files/frontlib/util/buffer.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/buffer.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,177 +1,177 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "buffer.h"
-#include "logging.h"
-#include "util.h"
-
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-
-#define MIN_VECTOR_CAPACITY 16
-
-struct _flib_vector {
-	void *data;
-	size_t size;
-	size_t capacity;
-};
-
-flib_vector *flib_vector_create() {
-	flib_vector *result = NULL;
-	flib_vector *tmpVector = flib_calloc(1, sizeof(flib_vector));
-	if(tmpVector) {
-		tmpVector->data = flib_malloc(MIN_VECTOR_CAPACITY);
-		if(tmpVector->data) {
-			tmpVector->size = 0;
-			tmpVector->capacity = MIN_VECTOR_CAPACITY;
-			result = tmpVector;
-			tmpVector = NULL;
-		}
-	}
-	flib_vector_destroy(tmpVector);
-	return result;
-}
-
-void flib_vector_destroy(flib_vector *vec) {
-	if(vec) {
-		free(vec->data);
-		free(vec);
-	}
-}
-
-static int setCapacity(flib_vector *vec, size_t newCapacity) {
-	if(newCapacity == vec->capacity) {
-		return 0;
-	}
-	void *newData = realloc(vec->data, newCapacity);
-	if(newData) {
-		vec->data = newData;
-		vec->capacity = newCapacity;
-		return 0;
-	} else {
-		return -1;
-	}
-}
-
-static int allocateExtraCapacity(flib_vector *vec, size_t extraCapacity) {
-	if(extraCapacity <= SIZE_MAX - vec->capacity) {
-		return setCapacity(vec, vec->capacity + extraCapacity);
-	} else {
-		return -1;
-	}
-}
-
-int flib_vector_resize(flib_vector *vec, size_t newSize) {
-	if(log_badargs_if(vec==NULL)) {
-		return -1;
-	}
-
-	if(vec->capacity < newSize) {
-		// Resize exponentially for constant amortized time,
-		// But at least by as much as we need of course
-		size_t extraCapacity = (vec->capacity)/2;
-		size_t minExtraCapacity = newSize - vec->capacity;
-		if(extraCapacity < minExtraCapacity) {
-			extraCapacity = minExtraCapacity;
-		}
-
-		if(allocateExtraCapacity(vec, extraCapacity)) {
-			allocateExtraCapacity(vec, minExtraCapacity);
-		}
-	} else if(vec->capacity/2 > newSize) {
-		size_t newCapacity = newSize+newSize/4;
-		if(newCapacity < MIN_VECTOR_CAPACITY) {
-			newCapacity = MIN_VECTOR_CAPACITY;
-		}
-		setCapacity(vec, newCapacity);
-	}
-
-	if(vec->capacity >= newSize) {
-		vec->size = newSize;
-		return 0;
-	} else {
-		return -1;
-	}
-}
-
-int flib_vector_append(flib_vector *vec, const void *data, size_t len) {
-	if(!log_badargs_if2(vec==NULL, data==NULL && len>0)
-			&& !log_oom_if(len > SIZE_MAX-vec->size)) {
-		size_t oldSize = vec->size;
-		if(!log_oom_if(flib_vector_resize(vec, vec->size+len))) {
-			memmove(((uint8_t*)vec->data) + oldSize, data, len);
-			return 0;
-		}
-	}
-	return -1;
-}
-
-int flib_vector_appendf(flib_vector *vec, const char *fmt, ...) {
-	int result = -1;
-	if(!log_badargs_if2(vec==NULL, fmt==NULL)) {
-		va_list argp;
-		va_start(argp, fmt);
-		char *formatted = flib_vasprintf(fmt, argp);
-		va_end(argp);
-
-
-		if(formatted) {
-			size_t len = strlen(formatted);
-			result = flib_vector_append(vec, formatted, len);
-		}
-	}
-	return result;
-}
-
-flib_buffer flib_vector_as_buffer(flib_vector *vec) {
-	if(log_badargs_if(vec==NULL)) {
-		flib_buffer result = {NULL, 0};
-		return result;
-	} else {
-		flib_buffer result = {vec->data, vec->size};
-		return result;
-	}
-}
-
-flib_constbuffer flib_vector_as_constbuffer(flib_vector *vec) {
-	if(log_badargs_if(vec==NULL)) {
-		flib_constbuffer result = {NULL, 0};
-		return result;
-	} else {
-		flib_constbuffer result = {vec->data, vec->size};
-		return result;
-	}
-}
-
-void *flib_vector_data(flib_vector *vec) {
-	if(log_badargs_if(vec==NULL)) {
-		return NULL;
-	} else {
-		return vec->data;
-	}
-}
-
-size_t flib_vector_size(flib_vector *vec) {
-	if(log_badargs_if(vec==NULL)) {
-		return 0;
-	} else {
-		return vec->size;
-	}
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "buffer.h"
+#include "logging.h"
+#include "util.h"
+
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+
+#define MIN_VECTOR_CAPACITY 16
+
+struct _flib_vector {
+    void *data;
+    size_t size;
+    size_t capacity;
+};
+
+flib_vector *flib_vector_create() {
+    flib_vector *result = NULL;
+    flib_vector *tmpVector = flib_calloc(1, sizeof(flib_vector));
+    if(tmpVector) {
+        tmpVector->data = flib_malloc(MIN_VECTOR_CAPACITY);
+        if(tmpVector->data) {
+            tmpVector->size = 0;
+            tmpVector->capacity = MIN_VECTOR_CAPACITY;
+            result = tmpVector;
+            tmpVector = NULL;
+        }
+    }
+    flib_vector_destroy(tmpVector);
+    return result;
+}
+
+void flib_vector_destroy(flib_vector *vec) {
+    if(vec) {
+        free(vec->data);
+        free(vec);
+    }
+}
+
+static int setCapacity(flib_vector *vec, size_t newCapacity) {
+    if(newCapacity == vec->capacity) {
+        return 0;
+    }
+    void *newData = realloc(vec->data, newCapacity);
+    if(newData) {
+        vec->data = newData;
+        vec->capacity = newCapacity;
+        return 0;
+    } else {
+        return -1;
+    }
+}
+
+static int allocateExtraCapacity(flib_vector *vec, size_t extraCapacity) {
+    if(extraCapacity <= SIZE_MAX - vec->capacity) {
+        return setCapacity(vec, vec->capacity + extraCapacity);
+    } else {
+        return -1;
+    }
+}
+
+int flib_vector_resize(flib_vector *vec, size_t newSize) {
+    if(log_badargs_if(vec==NULL)) {
+        return -1;
+    }
+
+    if(vec->capacity < newSize) {
+        // Resize exponentially for constant amortized time,
+        // But at least by as much as we need of course
+        size_t extraCapacity = (vec->capacity)/2;
+        size_t minExtraCapacity = newSize - vec->capacity;
+        if(extraCapacity < minExtraCapacity) {
+            extraCapacity = minExtraCapacity;
+        }
+
+        if(allocateExtraCapacity(vec, extraCapacity)) {
+            allocateExtraCapacity(vec, minExtraCapacity);
+        }
+    } else if(vec->capacity/2 > newSize) {
+        size_t newCapacity = newSize+newSize/4;
+        if(newCapacity < MIN_VECTOR_CAPACITY) {
+            newCapacity = MIN_VECTOR_CAPACITY;
+        }
+        setCapacity(vec, newCapacity);
+    }
+
+    if(vec->capacity >= newSize) {
+        vec->size = newSize;
+        return 0;
+    } else {
+        return -1;
+    }
+}
+
+int flib_vector_append(flib_vector *vec, const void *data, size_t len) {
+    if(!log_badargs_if2(vec==NULL, data==NULL && len>0)
+            && !log_oom_if(len > SIZE_MAX-vec->size)) {
+        size_t oldSize = vec->size;
+        if(!log_oom_if(flib_vector_resize(vec, vec->size+len))) {
+            memmove(((uint8_t*)vec->data) + oldSize, data, len);
+            return 0;
+        }
+    }
+    return -1;
+}
+
+int flib_vector_appendf(flib_vector *vec, const char *fmt, ...) {
+    int result = -1;
+    if(!log_badargs_if2(vec==NULL, fmt==NULL)) {
+        va_list argp;
+        va_start(argp, fmt);
+        char *formatted = flib_vasprintf(fmt, argp);
+        va_end(argp);
+
+
+        if(formatted) {
+            size_t len = strlen(formatted);
+            result = flib_vector_append(vec, formatted, len);
+        }
+    }
+    return result;
+}
+
+flib_buffer flib_vector_as_buffer(flib_vector *vec) {
+    if(log_badargs_if(vec==NULL)) {
+        flib_buffer result = {NULL, 0};
+        return result;
+    } else {
+        flib_buffer result = {vec->data, vec->size};
+        return result;
+    }
+}
+
+flib_constbuffer flib_vector_as_constbuffer(flib_vector *vec) {
+    if(log_badargs_if(vec==NULL)) {
+        flib_constbuffer result = {NULL, 0};
+        return result;
+    } else {
+        flib_constbuffer result = {vec->data, vec->size};
+        return result;
+    }
+}
+
+void *flib_vector_data(flib_vector *vec) {
+    if(log_badargs_if(vec==NULL)) {
+        return NULL;
+    } else {
+        return vec->data;
+    }
+}
+
+size_t flib_vector_size(flib_vector *vec) {
+    if(log_badargs_if(vec==NULL)) {
+        return 0;
+    } else {
+        return vec->size;
+    }
+}
--- a/project_files/frontlib/util/buffer.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/buffer.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,104 +1,104 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef BUFFER_H_
-#define BUFFER_H_
-
-#include <stdint.h>
-#include <stddef.h>
-
-/**
- * A simple struct to hold both the pointer to an array and its size,
- * for e.g. conveniently returning it from a function.
- *
- * Convention: Size is zero iff data is a NULL pointer.
- */
-typedef struct {
-	void *data;
-	size_t size;
-} flib_buffer;
-
-/**
- * Just like flib_buffer, but the contents are not supposed to be modified.
- */
-typedef struct {
-	const void *data;
-	size_t size;
-} flib_constbuffer;
-
-/**
- * Simple variable-capacity data structure that can be efficiently appended to.
- */
-typedef struct _flib_vector flib_vector;
-
-/**
- * Create a new vector. Needs to be destroyed again later with flib_vector_destroy.
- * May return NULL if memory runs out.
- */
-flib_vector *flib_vector_create();
-
-/**
- * Free the memory of this vector
- */
-void flib_vector_destroy(flib_vector *vec);
-
-/**
- * Resize the vector. This changes the size, and ensures the capacity is large enough to
- * for the new size. Can also free memory if the new size is smaller. There is no guarantee
- * about the contents of extra memory.
- */
-int flib_vector_resize(flib_vector *vec, size_t newSize);
-
-/**
- * Append the provided data to the end of the vector, enlarging it as required.
- * The vector remains unchanged if appending fails.
- * Returns 0 on success.
- */
-int flib_vector_append(flib_vector *vec, const void *data, size_t len);
-
-/**
- * Append data from a format string to the buffer (without trailing 0)
- * Returns 0 on success.
- */
-int flib_vector_appendf(flib_vector *vec, const char *template, ...);
-
-/**
- * Return a pointer to the current data buffer of the vector. This pointer can
- * become invalid if the vector size or capacity is changed.
- */
-void *flib_vector_data(flib_vector *vec);
-
-/**
- * Return the current size of the vector.
- */
-size_t flib_vector_size(flib_vector *vec);
-
-/**
- * Return a buffer pointing to the current contents of the vector.
- * These will become invalid if the vector size or capacity is changed.
- */
-flib_buffer flib_vector_as_buffer(flib_vector *vec);
-
-/**
- * Return a constbuffer pointing to the current contents of the vector.
- * These will become invalid if the vector size or capacity is changed.
- */
-flib_constbuffer flib_vector_as_constbuffer(flib_vector *vec);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef BUFFER_H_
+#define BUFFER_H_
+
+#include <stdint.h>
+#include <stddef.h>
+
+/**
+ * A simple struct to hold both the pointer to an array and its size,
+ * for e.g. conveniently returning it from a function.
+ *
+ * Convention: Size is zero iff data is a NULL pointer.
+ */
+typedef struct {
+    void *data;
+    size_t size;
+} flib_buffer;
+
+/**
+ * Just like flib_buffer, but the contents are not supposed to be modified.
+ */
+typedef struct {
+    const void *data;
+    size_t size;
+} flib_constbuffer;
+
+/**
+ * Simple variable-capacity data structure that can be efficiently appended to.
+ */
+typedef struct _flib_vector flib_vector;
+
+/**
+ * Create a new vector. Needs to be destroyed again later with flib_vector_destroy.
+ * May return NULL if memory runs out.
+ */
+flib_vector *flib_vector_create();
+
+/**
+ * Free the memory of this vector
+ */
+void flib_vector_destroy(flib_vector *vec);
+
+/**
+ * Resize the vector. This changes the size, and ensures the capacity is large enough to
+ * for the new size. Can also free memory if the new size is smaller. There is no guarantee
+ * about the contents of extra memory.
+ */
+int flib_vector_resize(flib_vector *vec, size_t newSize);
+
+/**
+ * Append the provided data to the end of the vector, enlarging it as required.
+ * The vector remains unchanged if appending fails.
+ * Returns 0 on success.
+ */
+int flib_vector_append(flib_vector *vec, const void *data, size_t len);
+
+/**
+ * Append data from a format string to the buffer (without trailing 0)
+ * Returns 0 on success.
+ */
+int flib_vector_appendf(flib_vector *vec, const char *template, ...);
+
+/**
+ * Return a pointer to the current data buffer of the vector. This pointer can
+ * become invalid if the vector size or capacity is changed.
+ */
+void *flib_vector_data(flib_vector *vec);
+
+/**
+ * Return the current size of the vector.
+ */
+size_t flib_vector_size(flib_vector *vec);
+
+/**
+ * Return a buffer pointing to the current contents of the vector.
+ * These will become invalid if the vector size or capacity is changed.
+ */
+flib_buffer flib_vector_as_buffer(flib_vector *vec);
+
+/**
+ * Return a constbuffer pointing to the current contents of the vector.
+ * These will become invalid if the vector size or capacity is changed.
+ */
+flib_constbuffer flib_vector_as_constbuffer(flib_vector *vec);
+
+#endif
--- a/project_files/frontlib/util/inihelper.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/inihelper.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,321 +1,321 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "inihelper.h"
-#include "../iniparser/dictionary.h"
-#include "../iniparser/iniparser.h"
-
-#include "logging.h"
-#include "util.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdarg.h>
-
-struct _flib_ini {
-	dictionary *inidict;
-	char *currentSection;
-};
-
-static char *createDictKey(const char *sectionName, const char *keyName) {
-	return flib_asprintf("%s:%s", sectionName, keyName);
-}
-
-/**
- * Turns a string into a lowercase string, in-place.
- */
-static void strToLower(char *str) {
-	if(str) {
-		while(*str) {
-			*str = tolower(*str);
-			str++;
-		}
-	}
-}
-
-flib_ini *flib_ini_create(const char *filename) {
-	flib_ini *result = NULL;
-	flib_ini *tmpIni = flib_calloc(1, sizeof(flib_ini));
-	if(tmpIni) {
-		if(filename) {
-			tmpIni->inidict = iniparser_load(filename);
-		}
-		if(!tmpIni->inidict) {
-			tmpIni->inidict = dictionary_new(0);
-		}
-		if(tmpIni->inidict) {
-			result = tmpIni;
-			tmpIni = NULL;
-		}
-	}
-	flib_ini_destroy(tmpIni);
-	return result;
-}
-
-flib_ini *flib_ini_load(const char *filename) {
-	flib_ini *result = NULL;
-	if(!log_badargs_if(filename==NULL)) {
-		flib_ini *tmpIni = flib_calloc(1, sizeof(flib_ini));
-		if(tmpIni) {
-			tmpIni->inidict = iniparser_load(filename);
-			if(tmpIni->inidict) {
-				result = tmpIni;
-				tmpIni = NULL;
-			}
-		}
-		flib_ini_destroy(tmpIni);
-	}
-	return result;
-}
-
-int flib_ini_save(flib_ini *ini, const char *filename) {
-	int result = INI_ERROR_OTHER;
-	if(!log_badargs_if2(ini==NULL, filename==NULL)) {
-		FILE *file = fopen(filename, "wb");
-		if(!file) {
-			flib_log_e("Error opening file \"%s\" for writing.", filename);
-		} else {
-			iniparser_dump_ini(ini->inidict, file);
-			if(fclose(file)) {
-				flib_log_e("Write error on ini file \"%s\"", filename);
-			} else {
-				result = 0;
-			}
-		}
-	}
-	return result;
-}
-
-void flib_ini_destroy(flib_ini *ini) {
-	if(ini) {
-		if(ini->inidict) {
-			iniparser_freedict(ini->inidict);
-		}
-		free(ini->currentSection);
-		free(ini);
-	}
-}
-
-int flib_ini_enter_section(flib_ini *ini, const char *section) {
-	int result = INI_ERROR_OTHER;
-	if(ini) {
-		free(ini->currentSection);
-		ini->currentSection = NULL;
-	}
-	if(!log_badargs_if2(ini==NULL, section==NULL)) {
-		if(!iniparser_find_entry(ini->inidict, section)) {
-			flib_log_d("Ini section %s not found", section);
-			result = INI_ERROR_NOTFOUND;
-		} else {
-			ini->currentSection = flib_strdupnull(section);
-			if(ini->currentSection) {
-				// Usually iniparser ignores case, but some section-handling functions don't,
-				// so we set it to lowercase manually
-				strToLower(ini->currentSection);
-				result = 0;
-			}
-		}
-	}
-	return result;
-}
-
-int flib_ini_create_section(flib_ini *ini, const char *section) {
-	int result = INI_ERROR_OTHER;
-	if(!log_badargs_if2(ini==NULL, section==NULL)) {
-		result = flib_ini_enter_section(ini, section);
-		if(result == INI_ERROR_NOTFOUND) {
-			if(iniparser_set(ini->inidict, section, NULL)) {
-				flib_log_e("Error creating ini section %s", section);
-				result = INI_ERROR_OTHER;
-			} else {
-				result = flib_ini_enter_section(ini, section);
-			}
-		}
-	}
-	return result;
-}
-
-/**
- * The result is an internal string of the iniparser, don't free it.
- */
-static char *findValue(dictionary *dict, const char *section, const char *key) {
-	char *result = NULL;
-	char *dictKey = createDictKey(section, key);
-	if(dictKey) {
-		result = iniparser_getstring(dict, dictKey, NULL);
-	}
-	free(dictKey);
-	return result;
-}
-
-int flib_ini_get_str(flib_ini *ini, char **outVar, const char *key) {
-	char *tmpValue = NULL;
-	int result = flib_ini_get_str_opt(ini, &tmpValue, key, NULL);
-	if(result==0) {
-		if(tmpValue == NULL) {
-			result = INI_ERROR_NOTFOUND;
-		} else {
-			*outVar = tmpValue;
-			tmpValue = NULL;
-		}
-	}
-	free(tmpValue);
-	return result;
-}
-
-int flib_ini_get_str_opt(flib_ini *ini, char **outVar, const char *key, const char *def) {
-	int result = INI_ERROR_OTHER;
-	if(!log_badargs_if4(ini==NULL, ini->currentSection==NULL, outVar==NULL, key==NULL)) {
-		const char *value = findValue(ini->inidict, ini->currentSection, key);
-		if(!value) {
-			value = def;
-		}
-		char *valueDup = flib_strdupnull(value);
-		if(valueDup || !def) {
-			*outVar = valueDup;
-			result = 0;
-		}
-	}
-	return result;
-}
-
-int flib_ini_get_int(flib_ini *ini, int *outVar, const char *key) {
-	char *tmpValue = NULL;
-	int result = flib_ini_get_str(ini, &tmpValue, key);
-	if(result==0) {
-		errno = 0;
-		long val = strtol(tmpValue, NULL, 10);
-		if(errno!=0 || val<INT_MIN || val>INT_MAX) {
-			flib_log_w("Cannot parse ini setting %s/%s = \"%s\" as integer.", ini->currentSection, key, tmpValue);
-			result = INI_ERROR_FORMAT;
-		} else {
-			*outVar = val;
-		}
-	}
-	free(tmpValue);
-	return result;
-}
-
-int flib_ini_get_int_opt(flib_ini *ini, int *outVar, const char *key, int def) {
-	int tmpValue;
-	int result = flib_ini_get_int(ini, &tmpValue, key);
-	if(result == 0) {
-		*outVar = tmpValue;
-	} else if(result == INI_ERROR_NOTFOUND || result == INI_ERROR_FORMAT) {
-		*outVar = def;
-		result = 0;
-	}
-	return result;
-}
-
-int flib_ini_get_bool(flib_ini *ini, bool *outVar, const char *key) {
-	char *tmpValue = NULL;
-	int result = flib_ini_get_str(ini, &tmpValue, key);
-	if(result==0) {
-		bool trueval = strchr("1tTyY", tmpValue[0]);
-		bool falseval = strchr("0fFnN", tmpValue[0]);
-		if(!trueval && !falseval) {
-			flib_log_w("ini setting %s/%s = \"%s\" is not a recognized truth value.", ini->currentSection, key, tmpValue);
-			result = INI_ERROR_FORMAT;
-		} else {
-			*outVar = trueval;
-		}
-	}
-	free(tmpValue);
-	return result;
-}
-
-int flib_ini_get_bool_opt(flib_ini *ini, bool *outVar, const char *key, bool def) {
-	bool tmpValue;
-	int result = flib_ini_get_bool(ini, &tmpValue, key);
-	if(result == 0) {
-		*outVar = tmpValue;
-	} else if(result == INI_ERROR_NOTFOUND || result == INI_ERROR_FORMAT) {
-		*outVar = def;
-		result = 0;
-	}
-	return result;
-}
-
-int flib_ini_set_str(flib_ini *ini, const char *key, const char *value) {
-	int result = INI_ERROR_OTHER;
-	if(!log_badargs_if4(ini==NULL, ini->currentSection==NULL, key==NULL, value==NULL)) {
-		char *dictKey = createDictKey(ini->currentSection, key);
-		if(dictKey) {
-			result = iniparser_set(ini->inidict, dictKey, value);
-			if(result) {
-				flib_log_e("Error setting ini entry %s to %s", dictKey, value);
-			}
-		}
-		free(dictKey);
-	}
-	return result;
-}
-
-int flib_ini_set_int(flib_ini *ini, const char *key, int value) {
-	int result = INI_ERROR_OTHER;
-	char *strvalue = flib_asprintf("%i", value);
-	if(strvalue) {
-		result = flib_ini_set_str(ini, key, strvalue);
-	}
-	free(strvalue);
-	return result;
-}
-
-int flib_ini_set_bool(flib_ini *ini, const char *key, bool value) {
-	return flib_ini_set_str(ini, key, value ? "true" : "false");
-}
-
-int flib_ini_get_sectioncount(flib_ini *ini) {
-	if(!log_badargs_if(ini==NULL)) {
-		return iniparser_getnsec(ini->inidict);
-	}
-	return INI_ERROR_OTHER;
-}
-
-char *flib_ini_get_sectionname(flib_ini *ini, int number) {
-	if(!log_badargs_if2(ini==NULL, number<0)) {
-		return flib_strdupnull(iniparser_getsecname(ini->inidict, number));
-	}
-	return NULL;
-}
-
-int flib_ini_get_keycount(flib_ini *ini) {
-	if(!log_badargs_if2(ini==NULL, ini->currentSection==NULL)) {
-		return iniparser_getsecnkeys(ini->inidict, ini->currentSection);
-	}
-	return INI_ERROR_OTHER;
-}
-
-char *flib_ini_get_keyname(flib_ini *ini, int number) {
-	char *result = NULL;
-	if(!log_badargs_if3(ini==NULL, ini->currentSection==NULL, number<0)) {
-		int keyCount = iniparser_getsecnkeys(ini->inidict, ini->currentSection);
-		char **keys = iniparser_getseckeys(ini->inidict, ini->currentSection);
-		if(keys && keyCount>number) {
-			// The keys are in the format section:key, so we have to skip the section and colon.
-			result = flib_strdupnull(keys[number]+strlen(ini->currentSection)+1);
-		}
-		free(keys);
-	}
-	return result;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "inihelper.h"
+#include "../iniparser/dictionary.h"
+#include "../iniparser/iniparser.h"
+
+#include "logging.h"
+#include "util.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdarg.h>
+
+struct _flib_ini {
+    dictionary *inidict;
+    char *currentSection;
+};
+
+static char *createDictKey(const char *sectionName, const char *keyName) {
+    return flib_asprintf("%s:%s", sectionName, keyName);
+}
+
+/**
+ * Turns a string into a lowercase string, in-place.
+ */
+static void strToLower(char *str) {
+    if(str) {
+        while(*str) {
+            *str = tolower(*str);
+            str++;
+        }
+    }
+}
+
+flib_ini *flib_ini_create(const char *filename) {
+    flib_ini *result = NULL;
+    flib_ini *tmpIni = flib_calloc(1, sizeof(flib_ini));
+    if(tmpIni) {
+        if(filename) {
+            tmpIni->inidict = iniparser_load(filename);
+        }
+        if(!tmpIni->inidict) {
+            tmpIni->inidict = dictionary_new(0);
+        }
+        if(tmpIni->inidict) {
+            result = tmpIni;
+            tmpIni = NULL;
+        }
+    }
+    flib_ini_destroy(tmpIni);
+    return result;
+}
+
+flib_ini *flib_ini_load(const char *filename) {
+    flib_ini *result = NULL;
+    if(!log_badargs_if(filename==NULL)) {
+        flib_ini *tmpIni = flib_calloc(1, sizeof(flib_ini));
+        if(tmpIni) {
+            tmpIni->inidict = iniparser_load(filename);
+            if(tmpIni->inidict) {
+                result = tmpIni;
+                tmpIni = NULL;
+            }
+        }
+        flib_ini_destroy(tmpIni);
+    }
+    return result;
+}
+
+int flib_ini_save(flib_ini *ini, const char *filename) {
+    int result = INI_ERROR_OTHER;
+    if(!log_badargs_if2(ini==NULL, filename==NULL)) {
+        FILE *file = fopen(filename, "wb");
+        if(!file) {
+            flib_log_e("Error opening file \"%s\" for writing.", filename);
+        } else {
+            iniparser_dump_ini(ini->inidict, file);
+            if(fclose(file)) {
+                flib_log_e("Write error on ini file \"%s\"", filename);
+            } else {
+                result = 0;
+            }
+        }
+    }
+    return result;
+}
+
+void flib_ini_destroy(flib_ini *ini) {
+    if(ini) {
+        if(ini->inidict) {
+            iniparser_freedict(ini->inidict);
+        }
+        free(ini->currentSection);
+        free(ini);
+    }
+}
+
+int flib_ini_enter_section(flib_ini *ini, const char *section) {
+    int result = INI_ERROR_OTHER;
+    if(ini) {
+        free(ini->currentSection);
+        ini->currentSection = NULL;
+    }
+    if(!log_badargs_if2(ini==NULL, section==NULL)) {
+        if(!iniparser_find_entry(ini->inidict, section)) {
+            flib_log_d("Ini section %s not found", section);
+            result = INI_ERROR_NOTFOUND;
+        } else {
+            ini->currentSection = flib_strdupnull(section);
+            if(ini->currentSection) {
+                // Usually iniparser ignores case, but some section-handling functions don't,
+                // so we set it to lowercase manually
+                strToLower(ini->currentSection);
+                result = 0;
+            }
+        }
+    }
+    return result;
+}
+
+int flib_ini_create_section(flib_ini *ini, const char *section) {
+    int result = INI_ERROR_OTHER;
+    if(!log_badargs_if2(ini==NULL, section==NULL)) {
+        result = flib_ini_enter_section(ini, section);
+        if(result == INI_ERROR_NOTFOUND) {
+            if(iniparser_set(ini->inidict, section, NULL)) {
+                flib_log_e("Error creating ini section %s", section);
+                result = INI_ERROR_OTHER;
+            } else {
+                result = flib_ini_enter_section(ini, section);
+            }
+        }
+    }
+    return result;
+}
+
+/**
+ * The result is an internal string of the iniparser, don't free it.
+ */
+static char *findValue(dictionary *dict, const char *section, const char *key) {
+    char *result = NULL;
+    char *dictKey = createDictKey(section, key);
+    if(dictKey) {
+        result = iniparser_getstring(dict, dictKey, NULL);
+    }
+    free(dictKey);
+    return result;
+}
+
+int flib_ini_get_str(flib_ini *ini, char **outVar, const char *key) {
+    char *tmpValue = NULL;
+    int result = flib_ini_get_str_opt(ini, &tmpValue, key, NULL);
+    if(result==0) {
+        if(tmpValue == NULL) {
+            result = INI_ERROR_NOTFOUND;
+        } else {
+            *outVar = tmpValue;
+            tmpValue = NULL;
+        }
+    }
+    free(tmpValue);
+    return result;
+}
+
+int flib_ini_get_str_opt(flib_ini *ini, char **outVar, const char *key, const char *def) {
+    int result = INI_ERROR_OTHER;
+    if(!log_badargs_if4(ini==NULL, ini->currentSection==NULL, outVar==NULL, key==NULL)) {
+        const char *value = findValue(ini->inidict, ini->currentSection, key);
+        if(!value) {
+            value = def;
+        }
+        char *valueDup = flib_strdupnull(value);
+        if(valueDup || !def) {
+            *outVar = valueDup;
+            result = 0;
+        }
+    }
+    return result;
+}
+
+int flib_ini_get_int(flib_ini *ini, int *outVar, const char *key) {
+    char *tmpValue = NULL;
+    int result = flib_ini_get_str(ini, &tmpValue, key);
+    if(result==0) {
+        errno = 0;
+        long val = strtol(tmpValue, NULL, 10);
+        if(errno!=0 || val<INT_MIN || val>INT_MAX) {
+            flib_log_w("Cannot parse ini setting %s/%s = \"%s\" as integer.", ini->currentSection, key, tmpValue);
+            result = INI_ERROR_FORMAT;
+        } else {
+            *outVar = val;
+        }
+    }
+    free(tmpValue);
+    return result;
+}
+
+int flib_ini_get_int_opt(flib_ini *ini, int *outVar, const char *key, int def) {
+    int tmpValue;
+    int result = flib_ini_get_int(ini, &tmpValue, key);
+    if(result == 0) {
+        *outVar = tmpValue;
+    } else if(result == INI_ERROR_NOTFOUND || result == INI_ERROR_FORMAT) {
+        *outVar = def;
+        result = 0;
+    }
+    return result;
+}
+
+int flib_ini_get_bool(flib_ini *ini, bool *outVar, const char *key) {
+    char *tmpValue = NULL;
+    int result = flib_ini_get_str(ini, &tmpValue, key);
+    if(result==0) {
+        bool trueval = strchr("1tTyY", tmpValue[0]);
+        bool falseval = strchr("0fFnN", tmpValue[0]);
+        if(!trueval && !falseval) {
+            flib_log_w("ini setting %s/%s = \"%s\" is not a recognized truth value.", ini->currentSection, key, tmpValue);
+            result = INI_ERROR_FORMAT;
+        } else {
+            *outVar = trueval;
+        }
+    }
+    free(tmpValue);
+    return result;
+}
+
+int flib_ini_get_bool_opt(flib_ini *ini, bool *outVar, const char *key, bool def) {
+    bool tmpValue;
+    int result = flib_ini_get_bool(ini, &tmpValue, key);
+    if(result == 0) {
+        *outVar = tmpValue;
+    } else if(result == INI_ERROR_NOTFOUND || result == INI_ERROR_FORMAT) {
+        *outVar = def;
+        result = 0;
+    }
+    return result;
+}
+
+int flib_ini_set_str(flib_ini *ini, const char *key, const char *value) {
+    int result = INI_ERROR_OTHER;
+    if(!log_badargs_if4(ini==NULL, ini->currentSection==NULL, key==NULL, value==NULL)) {
+        char *dictKey = createDictKey(ini->currentSection, key);
+        if(dictKey) {
+            result = iniparser_set(ini->inidict, dictKey, value);
+            if(result) {
+                flib_log_e("Error setting ini entry %s to %s", dictKey, value);
+            }
+        }
+        free(dictKey);
+    }
+    return result;
+}
+
+int flib_ini_set_int(flib_ini *ini, const char *key, int value) {
+    int result = INI_ERROR_OTHER;
+    char *strvalue = flib_asprintf("%i", value);
+    if(strvalue) {
+        result = flib_ini_set_str(ini, key, strvalue);
+    }
+    free(strvalue);
+    return result;
+}
+
+int flib_ini_set_bool(flib_ini *ini, const char *key, bool value) {
+    return flib_ini_set_str(ini, key, value ? "true" : "false");
+}
+
+int flib_ini_get_sectioncount(flib_ini *ini) {
+    if(!log_badargs_if(ini==NULL)) {
+        return iniparser_getnsec(ini->inidict);
+    }
+    return INI_ERROR_OTHER;
+}
+
+char *flib_ini_get_sectionname(flib_ini *ini, int number) {
+    if(!log_badargs_if2(ini==NULL, number<0)) {
+        return flib_strdupnull(iniparser_getsecname(ini->inidict, number));
+    }
+    return NULL;
+}
+
+int flib_ini_get_keycount(flib_ini *ini) {
+    if(!log_badargs_if2(ini==NULL, ini->currentSection==NULL)) {
+        return iniparser_getsecnkeys(ini->inidict, ini->currentSection);
+    }
+    return INI_ERROR_OTHER;
+}
+
+char *flib_ini_get_keyname(flib_ini *ini, int number) {
+    char *result = NULL;
+    if(!log_badargs_if3(ini==NULL, ini->currentSection==NULL, number<0)) {
+        int keyCount = iniparser_getsecnkeys(ini->inidict, ini->currentSection);
+        char **keys = iniparser_getseckeys(ini->inidict, ini->currentSection);
+        if(keys && keyCount>number) {
+            // The keys are in the format section:key, so we have to skip the section and colon.
+            result = flib_strdupnull(keys[number]+strlen(ini->currentSection)+1);
+        }
+        free(keys);
+    }
+    return result;
+}
--- a/project_files/frontlib/util/inihelper.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/inihelper.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,178 +1,178 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * Convenience interface for ini reading/writing.
- *
- * We currently use iniparser in the background, but using its interface directly is a bit verbose.
- * This module is supposed to 1. make ini reading and writing a bit more convenient, and 2. hide
- * the iniparser dependency so it can at need be easily replaced.
- */
-
-#ifndef INIHELPER_H_
-#define INIHELPER_H_
-
-#include <stdbool.h>
-
-#define INI_ERROR_NOTFOUND -1
-#define INI_ERROR_FORMAT -2
-#define INI_ERROR_OTHER -100
-
-typedef struct _flib_ini flib_ini;
-
-/**
- * Create a new ini data structure, pre-filled with the contents of
- * the file "filename" if it exists. If filename is null, or the file
- * is not found, an empty ini will be created. However, if an error
- * occurs while reading the ini file (or any other error), null
- * is returned.
- *
- * This behavior is useful for modifying an existing ini file without
- * discarding unknown keys.
- */
-flib_ini *flib_ini_create(const char *filename);
-
-/**
- * Similar to flib_ini_create, but fails if the file is not found
- * or if filename is null.
- */
-flib_ini *flib_ini_load(const char *filename);
-
-/**
- * Store the ini to the file "filename", overwriting
- * the previous contents. Returns 0 on success.
- */
-int flib_ini_save(flib_ini *ini, const char *filename);
-
-void flib_ini_destroy(flib_ini *ini);
-
-/**
- * Enter the section with the specified name. Returns 0 on
- * success, INI_ERROR_NOTFOUND if the section does not exist
- * and a different value if another error occurs.
- * If an error occurs, there is no current section.
- *
- * The section name should only consist of letters and
- * numbers.
- */
-int flib_ini_enter_section(flib_ini *ini, const char *section);
-
-/**
- * Creates and enters the section with the specified name. Simply
- * enters the section if it exists already. Returns 0 on success
- * and a different value if another error occurs.
- * If an error occurs, there is no current section.
- */
-int flib_ini_create_section(flib_ini *ini, const char *section);
-
-/**
- * Find a key in the current section and store the value in outVar
- * as a newly allocated string. Returns 0 on success, INI_ERROR_NOTFOUND
- * if the key was not found and a different value for other errors,
- * e.g. if there is no current section.
- */
-int flib_ini_get_str(flib_ini *ini, char **outVar, const char *key);
-
-/**
- * Find a key in the current section and store the value in outVar
- * as a newly allocated string. If the key is not found, the default
- * value will be used instead. Returns 0 on success.
- */
-int flib_ini_get_str_opt(flib_ini *ini, char **outVar, const char *key, const char *def);
-
-/**
- * Find a key in the current section and store the value in outVar
- * as an int. Returns 0 on success, INI_ERROR_NOTFOUND
- * if the key was not found, INI_ERROR_FORMAT if it was found but
- * could not be converted to an int, and a different value for other
- * errors, e.g. if there is no current section.
- */
-int flib_ini_get_int(flib_ini *ini, int *outVar, const char *key);
-
-/**
- * Find a key in the current section and store the value in outVar
- * as an int. If the key is not found, the default value will be used instead.
- * Returns 0 on success, INI_ERROR_FORMAT if the value was found but
- * could not be converted to int, and another value otherwise.
- */
-int flib_ini_get_int_opt(flib_ini *ini, int *outVar, const char *key, int def);
-
-/**
- * Find a key in the current section and store the value in outVar
- * as a bool. Treats everything beginning with "Y", "T" or "1" as true,
- * everything starting with "N", "F" or "1" as false.
- *
- * Returns 0 on success, INI_ERROR_NOTFOUND if the key was not found,
- * INI_ERROR_FORMAT if the value could not be interpreted as boolean,
- * and another value otherwise.
- */
-int flib_ini_get_bool(flib_ini *ini, bool *outVar, const char *key);
-
-/**
- * Find a key in the current section and store the value in outVar
- * as a bool. If the key is not found, the default value will be
- * used instead. Returns 0 on success, INI_ERROR_FORMAT if the
- * value could not be interpreted as boolean, and another value otherwise.
- */
-int flib_ini_get_bool_opt(flib_ini *ini, bool *outVar, const char *key, bool def);
-
-/**
- * In the current section, associate key with value. Returns 0 on success.
- */
-int flib_ini_set_str(flib_ini *ini, const char *key, const char *value);
-
-/**
- * In the current section, associate key with value. Returns 0 on success.
- */
-int flib_ini_set_int(flib_ini *ini, const char *key, int value);
-
-/**
- * In the current section, associate key with value. Returns 0 on success.
- */
-int flib_ini_set_bool(flib_ini *ini, const char *key, bool value);
-
-/**
- * Returns the number of sections in the ini file, or a negative value on error.
- */
-int flib_ini_get_sectioncount(flib_ini *ini);
-
-/**
- * Returns the name of the section, or NULL on error. The returned string must
- * be free()d.
- *
- * Note: There is no guarantee that the order of the sections
- * will remain stable if the ini is modified.
- */
-char *flib_ini_get_sectionname(flib_ini *ini, int number);
-
-/**
- * Returns the number of keys in the current section, or -1 on error.
- */
-int flib_ini_get_keycount(flib_ini *ini);
-
-/**
- * Returns the name of the key in the current section, or NULL on error.
- * The returned string must be free()d.
- *
- * Note: There is no guarantee that the order of the keys in a section
- * will remain stable if the ini is modified.
- */
-char *flib_ini_get_keyname(flib_ini *ini, int number);
-
-#endif /* INIHELPER_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * Convenience interface for ini reading/writing.
+ *
+ * We currently use iniparser in the background, but using its interface directly is a bit verbose.
+ * This module is supposed to 1. make ini reading and writing a bit more convenient, and 2. hide
+ * the iniparser dependency so it can at need be easily replaced.
+ */
+
+#ifndef INIHELPER_H_
+#define INIHELPER_H_
+
+#include <stdbool.h>
+
+#define INI_ERROR_NOTFOUND -1
+#define INI_ERROR_FORMAT -2
+#define INI_ERROR_OTHER -100
+
+typedef struct _flib_ini flib_ini;
+
+/**
+ * Create a new ini data structure, pre-filled with the contents of
+ * the file "filename" if it exists. If filename is null, or the file
+ * is not found, an empty ini will be created. However, if an error
+ * occurs while reading the ini file (or any other error), null
+ * is returned.
+ *
+ * This behavior is useful for modifying an existing ini file without
+ * discarding unknown keys.
+ */
+flib_ini *flib_ini_create(const char *filename);
+
+/**
+ * Similar to flib_ini_create, but fails if the file is not found
+ * or if filename is null.
+ */
+flib_ini *flib_ini_load(const char *filename);
+
+/**
+ * Store the ini to the file "filename", overwriting
+ * the previous contents. Returns 0 on success.
+ */
+int flib_ini_save(flib_ini *ini, const char *filename);
+
+void flib_ini_destroy(flib_ini *ini);
+
+/**
+ * Enter the section with the specified name. Returns 0 on
+ * success, INI_ERROR_NOTFOUND if the section does not exist
+ * and a different value if another error occurs.
+ * If an error occurs, there is no current section.
+ *
+ * The section name should only consist of letters and
+ * numbers.
+ */
+int flib_ini_enter_section(flib_ini *ini, const char *section);
+
+/**
+ * Creates and enters the section with the specified name. Simply
+ * enters the section if it exists already. Returns 0 on success
+ * and a different value if another error occurs.
+ * If an error occurs, there is no current section.
+ */
+int flib_ini_create_section(flib_ini *ini, const char *section);
+
+/**
+ * Find a key in the current section and store the value in outVar
+ * as a newly allocated string. Returns 0 on success, INI_ERROR_NOTFOUND
+ * if the key was not found and a different value for other errors,
+ * e.g. if there is no current section.
+ */
+int flib_ini_get_str(flib_ini *ini, char **outVar, const char *key);
+
+/**
+ * Find a key in the current section and store the value in outVar
+ * as a newly allocated string. If the key is not found, the default
+ * value will be used instead. Returns 0 on success.
+ */
+int flib_ini_get_str_opt(flib_ini *ini, char **outVar, const char *key, const char *def);
+
+/**
+ * Find a key in the current section and store the value in outVar
+ * as an int. Returns 0 on success, INI_ERROR_NOTFOUND
+ * if the key was not found, INI_ERROR_FORMAT if it was found but
+ * could not be converted to an int, and a different value for other
+ * errors, e.g. if there is no current section.
+ */
+int flib_ini_get_int(flib_ini *ini, int *outVar, const char *key);
+
+/**
+ * Find a key in the current section and store the value in outVar
+ * as an int. If the key is not found, the default value will be used instead.
+ * Returns 0 on success, INI_ERROR_FORMAT if the value was found but
+ * could not be converted to int, and another value otherwise.
+ */
+int flib_ini_get_int_opt(flib_ini *ini, int *outVar, const char *key, int def);
+
+/**
+ * Find a key in the current section and store the value in outVar
+ * as a bool. Treats everything beginning with "Y", "T" or "1" as true,
+ * everything starting with "N", "F" or "1" as false.
+ *
+ * Returns 0 on success, INI_ERROR_NOTFOUND if the key was not found,
+ * INI_ERROR_FORMAT if the value could not be interpreted as boolean,
+ * and another value otherwise.
+ */
+int flib_ini_get_bool(flib_ini *ini, bool *outVar, const char *key);
+
+/**
+ * Find a key in the current section and store the value in outVar
+ * as a bool. If the key is not found, the default value will be
+ * used instead. Returns 0 on success, INI_ERROR_FORMAT if the
+ * value could not be interpreted as boolean, and another value otherwise.
+ */
+int flib_ini_get_bool_opt(flib_ini *ini, bool *outVar, const char *key, bool def);
+
+/**
+ * In the current section, associate key with value. Returns 0 on success.
+ */
+int flib_ini_set_str(flib_ini *ini, const char *key, const char *value);
+
+/**
+ * In the current section, associate key with value. Returns 0 on success.
+ */
+int flib_ini_set_int(flib_ini *ini, const char *key, int value);
+
+/**
+ * In the current section, associate key with value. Returns 0 on success.
+ */
+int flib_ini_set_bool(flib_ini *ini, const char *key, bool value);
+
+/**
+ * Returns the number of sections in the ini file, or a negative value on error.
+ */
+int flib_ini_get_sectioncount(flib_ini *ini);
+
+/**
+ * Returns the name of the section, or NULL on error. The returned string must
+ * be free()d.
+ *
+ * Note: There is no guarantee that the order of the sections
+ * will remain stable if the ini is modified.
+ */
+char *flib_ini_get_sectionname(flib_ini *ini, int number);
+
+/**
+ * Returns the number of keys in the current section, or -1 on error.
+ */
+int flib_ini_get_keycount(flib_ini *ini);
+
+/**
+ * Returns the name of the key in the current section, or NULL on error.
+ * The returned string must be free()d.
+ *
+ * Note: There is no guarantee that the order of the keys in a section
+ * will remain stable if the ini is modified.
+ */
+char *flib_ini_get_keyname(flib_ini *ini, int number);
+
+#endif /* INIHELPER_H_ */
--- a/project_files/frontlib/util/list.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/list.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,80 +1,80 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-/**
- * Simple dynamic array manipulation functions.
- */
-
-#ifndef LIST_H_
-#define LIST_H_
-
-#include <stddef.h>
-#include <string.h>
-#include <stdlib.h>
-#include "util.h"
-#include "logging.h"
-
-/**
- * Generate a static function that inserts a new value into a heap array of the given type,
- * using realloc and memmove to increase the capacity and shift existing values.
- * The function takes a pointer to the array variable and a pointer to the size variable
- * because both can be changed by this operation (realloc / increment).
- * The function returns 0 on success and leaves the array unchanged on error.
- */
-#define GENERATE_STATIC_LIST_INSERT(fname, type) \
-	static int fname(type **listptr, int *listSizePtr, type element, int pos) { \
-		int result = -1; \
-		if(!log_badargs_if4(listptr==NULL, listSizePtr==NULL, pos < 0, pos > *listSizePtr)) { \
-			type *newList = flib_realloc(*listptr, ((*listSizePtr)+1)*sizeof(type)); \
-			if(newList) { \
-				memmove(newList + (pos+1), newList + pos, ((*listSizePtr)-pos)*sizeof(type)); \
-				newList[pos] = element; \
-				(*listSizePtr)++; \
-				*listptr = newList; \
-				result = 0; \
-			} \
-		} \
-		return result; \
-	}
-
-/**
- * Generate a static function that deletes a value from a heap array of the given type,
- * using realloc and memmove to decrease the capacity and shift existing values.
- * The function takes a pointer to the array variable and a pointer to the size variable
- * because both can be changed by this operation (realloc / decrement).
- * The function returns 0 on success and leaves the array unchanged on error.
- */
-#define GENERATE_STATIC_LIST_DELETE(fname, type) \
-	static int fname(type **listPtr, int *listSizePtr, int pos) { \
-		int result = -1; \
-		if(!log_badargs_if4(listPtr==NULL, listSizePtr==NULL, pos < 0, pos >= *listSizePtr)) { \
-			memmove((*listPtr) + pos, (*listPtr) + (pos+1), ((*listSizePtr)-(pos+1))*sizeof(type)); \
-			(*listSizePtr)--; \
-			\
-			size_t newCharSize = (*listSizePtr)*sizeof(type); \
-			type *newList = flib_realloc((*listPtr), newCharSize); \
-			if(newList || newCharSize==0) { \
-				(*listPtr) = newList; \
-			} /* If the realloc fails, just keep using the old buffer...*/ \
-			result = 0; \
-		} \
-		return result; \
-	}
-
-#endif /* LIST_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * Simple dynamic array manipulation functions.
+ */
+
+#ifndef LIST_H_
+#define LIST_H_
+
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include "util.h"
+#include "logging.h"
+
+/**
+ * Generate a static function that inserts a new value into a heap array of the given type,
+ * using realloc and memmove to increase the capacity and shift existing values.
+ * The function takes a pointer to the array variable and a pointer to the size variable
+ * because both can be changed by this operation (realloc / increment).
+ * The function returns 0 on success and leaves the array unchanged on error.
+ */
+#define GENERATE_STATIC_LIST_INSERT(fname, type) \
+    static int fname(type **listptr, int *listSizePtr, type element, int pos) { \
+        int result = -1; \
+        if(!log_badargs_if4(listptr==NULL, listSizePtr==NULL, pos < 0, pos > *listSizePtr)) { \
+            type *newList = flib_realloc(*listptr, ((*listSizePtr)+1)*sizeof(type)); \
+            if(newList) { \
+                memmove(newList + (pos+1), newList + pos, ((*listSizePtr)-pos)*sizeof(type)); \
+                newList[pos] = element; \
+                (*listSizePtr)++; \
+                *listptr = newList; \
+                result = 0; \
+            } \
+        } \
+        return result; \
+    }
+
+/**
+ * Generate a static function that deletes a value from a heap array of the given type,
+ * using realloc and memmove to decrease the capacity and shift existing values.
+ * The function takes a pointer to the array variable and a pointer to the size variable
+ * because both can be changed by this operation (realloc / decrement).
+ * The function returns 0 on success and leaves the array unchanged on error.
+ */
+#define GENERATE_STATIC_LIST_DELETE(fname, type) \
+    static int fname(type **listPtr, int *listSizePtr, int pos) { \
+        int result = -1; \
+        if(!log_badargs_if4(listPtr==NULL, listSizePtr==NULL, pos < 0, pos >= *listSizePtr)) { \
+            memmove((*listPtr) + pos, (*listPtr) + (pos+1), ((*listSizePtr)-(pos+1))*sizeof(type)); \
+            (*listSizePtr)--; \
+            \
+            size_t newCharSize = (*listSizePtr)*sizeof(type); \
+            type *newList = flib_realloc((*listPtr), newCharSize); \
+            if(newList || newCharSize==0) { \
+                (*listPtr) = newList; \
+            } /* If the realloc fails, just keep using the old buffer...*/ \
+            result = 0; \
+        } \
+        return result; \
+    }
+
+#endif /* LIST_H_ */
--- a/project_files/frontlib/util/logging.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/logging.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,145 +1,145 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "logging.h"
-
-#include <time.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-
-static int flib_loglevel = FLIB_LOGLEVEL_INFO;
-static FILE *flib_logfile = NULL;
-void (*flib_logCallback)(int level, const char *msg) = NULL;
-
-char* flib_format_ip(uint32_t numip) {
-	static char ip[16];
-	snprintf(ip, 16, "%u.%u.%u.%u", (unsigned)(numip>>24), (unsigned)((numip>>16)&0xff), (unsigned)((numip>>8)&0xff), (unsigned)(numip&0xff));
-	return ip;
-}
-
-static inline FILE *flib_log_getfile() {
-	if(flib_logfile==NULL) {
-		return stdout;
-	} else {
-		return flib_logfile;
-	}
-}
-
-static int log_time(char *buffer) {
-    time_t timer;
-    struct tm* tm_info;
-
-    time(&timer);
-    tm_info = localtime(&timer);
-
-    return strftime(buffer, 25, "%Y-%m-%d %H:%M:%S", tm_info);
-}
-
-static char getPrefix(int level) {
-	switch(level) {
-	case FLIB_LOGLEVEL_ERROR: return 'E';
-	case FLIB_LOGLEVEL_WARNING: return 'W';
-	case FLIB_LOGLEVEL_INFO: return 'I';
-	case FLIB_LOGLEVEL_DEBUG: return 'D';
-	default: return '?';
-	}
-}
-
-static void _flib_vflog(const char *func, int level, const char *fmt, va_list args) {
-	if(level >= flib_loglevel) {
-		char logbuffer[1024];
-		logbuffer[0] = getPrefix(level);
-		logbuffer[1] = ' ';
-
-		int pos = 2;
-
-		int len = log_time(logbuffer+pos);
-		if(len>=0) {
-			pos += len;
-			if(pos>sizeof(logbuffer)-1) pos = sizeof(logbuffer)-1;
-		} else {
-			return;
-		}
-
-		len = snprintf(logbuffer+pos, sizeof(logbuffer)-pos, " [%-30s] ", func);
-		if(len>=0) {
-			pos += len;
-			if(pos>sizeof(logbuffer)-1) pos = sizeof(logbuffer)-1;
-		} else {
-			return;
-		}
-
-		len = vsnprintf(logbuffer+pos, sizeof(logbuffer)-pos, fmt, args);
-		if(len>=0) {
-			pos += len;
-			if(pos>sizeof(logbuffer)-1) pos = sizeof(logbuffer)-1;
-		} else {
-			return;
-		}
-
-		if(flib_logCallback != NULL) {
-			flib_logCallback(level, logbuffer);
-		} else {
-			FILE *logfile = flib_log_getfile();
-			fputs(logbuffer, logfile);
-			fputc('\n', logfile);
-			fflush(logfile);
-		}
-	}
-}
-
-void _flib_flog(const char *func, int level, const char *fmt, ...) {
-	va_list argp;
-	va_start(argp, fmt);
-	_flib_vflog(func, level, fmt, argp);
-	va_end(argp);
-}
-
-bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...) {
-	if(!cond) {
-		va_list argp;
-		va_start(argp, fmt);
-		_flib_vflog(func, level, fmt, argp);
-		va_end(argp);
-	}
-	return !cond;
-}
-
-int flib_log_getLevel() {
-	return flib_loglevel;
-}
-
-void flib_log_setLevel(int level) {
-	flib_loglevel = level;
-}
-
-void flib_log_setFile(FILE *file) {
-	flib_logfile = file;
-	flib_logCallback = NULL;
-}
-
-bool flib_log_isActive(int level) {
-	return level >= flib_log_getLevel();
-}
-
-void flib_log_setCallback(void (*logCallback)(int level, const char *msg)) {
-	flib_logCallback = logCallback;
-	flib_logfile = NULL;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "logging.h"
+
+#include <time.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+static int flib_loglevel = FLIB_LOGLEVEL_INFO;
+static FILE *flib_logfile = NULL;
+void (*flib_logCallback)(int level, const char *msg) = NULL;
+
+char* flib_format_ip(uint32_t numip) {
+    static char ip[16];
+    snprintf(ip, 16, "%u.%u.%u.%u", (unsigned)(numip>>24), (unsigned)((numip>>16)&0xff), (unsigned)((numip>>8)&0xff), (unsigned)(numip&0xff));
+    return ip;
+}
+
+static inline FILE *flib_log_getfile() {
+    if(flib_logfile==NULL) {
+        return stdout;
+    } else {
+        return flib_logfile;
+    }
+}
+
+static int log_time(char *buffer) {
+    time_t timer;
+    struct tm* tm_info;
+
+    time(&timer);
+    tm_info = localtime(&timer);
+
+    return strftime(buffer, 25, "%Y-%m-%d %H:%M:%S", tm_info);
+}
+
+static char getPrefix(int level) {
+    switch(level) {
+    case FLIB_LOGLEVEL_ERROR: return 'E';
+    case FLIB_LOGLEVEL_WARNING: return 'W';
+    case FLIB_LOGLEVEL_INFO: return 'I';
+    case FLIB_LOGLEVEL_DEBUG: return 'D';
+    default: return '?';
+    }
+}
+
+static void _flib_vflog(const char *func, int level, const char *fmt, va_list args) {
+    if(level >= flib_loglevel) {
+        char logbuffer[1024];
+        logbuffer[0] = getPrefix(level);
+        logbuffer[1] = ' ';
+
+        int pos = 2;
+
+        int len = log_time(logbuffer+pos);
+        if(len>=0) {
+            pos += len;
+            if(pos>sizeof(logbuffer)-1) pos = sizeof(logbuffer)-1;
+        } else {
+            return;
+        }
+
+        len = snprintf(logbuffer+pos, sizeof(logbuffer)-pos, " [%-30s] ", func);
+        if(len>=0) {
+            pos += len;
+            if(pos>sizeof(logbuffer)-1) pos = sizeof(logbuffer)-1;
+        } else {
+            return;
+        }
+
+        len = vsnprintf(logbuffer+pos, sizeof(logbuffer)-pos, fmt, args);
+        if(len>=0) {
+            pos += len;
+            if(pos>sizeof(logbuffer)-1) pos = sizeof(logbuffer)-1;
+        } else {
+            return;
+        }
+
+        if(flib_logCallback != NULL) {
+            flib_logCallback(level, logbuffer);
+        } else {
+            FILE *logfile = flib_log_getfile();
+            fputs(logbuffer, logfile);
+            fputc('\n', logfile);
+            fflush(logfile);
+        }
+    }
+}
+
+void _flib_flog(const char *func, int level, const char *fmt, ...) {
+    va_list argp;
+    va_start(argp, fmt);
+    _flib_vflog(func, level, fmt, argp);
+    va_end(argp);
+}
+
+bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...) {
+    if(!cond) {
+        va_list argp;
+        va_start(argp, fmt);
+        _flib_vflog(func, level, fmt, argp);
+        va_end(argp);
+    }
+    return !cond;
+}
+
+int flib_log_getLevel() {
+    return flib_loglevel;
+}
+
+void flib_log_setLevel(int level) {
+    flib_loglevel = level;
+}
+
+void flib_log_setFile(FILE *file) {
+    flib_logfile = file;
+    flib_logCallback = NULL;
+}
+
+bool flib_log_isActive(int level) {
+    return level >= flib_log_getLevel();
+}
+
+void flib_log_setCallback(void (*logCallback)(int level, const char *msg)) {
+    flib_logCallback = logCallback;
+    flib_logfile = NULL;
+}
--- a/project_files/frontlib/util/logging.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/logging.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,106 +1,106 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef LOGGING_H_
-#define LOGGING_H_
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdbool.h>
-
-#define FLIB_LOGLEVEL_ALL -100
-#define FLIB_LOGLEVEL_DEBUG -1
-#define FLIB_LOGLEVEL_INFO 0
-#define FLIB_LOGLEVEL_WARNING 1
-#define FLIB_LOGLEVEL_ERROR 2
-#define FLIB_LOGLEVEL_NONE 100
-
-/**
- * Returns a pointer to a static buffer, don't free or store.
- */
-char* flib_format_ip(uint32_t numip);
-
-/**
- * Evaluates the expression cond. If it is true, a formatted error will be logged.
- * Returns true if an error is logged, false otherwise (i.e. the boolean value of the argument)
- * Usage: log_e_if(errorHasHappened, "Format string", formatArg, ...);
- */
-#define log_e_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_ERROR, !(bool)(cond), __VA_ARGS__)
-#define log_w_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_WARNING, !(bool)(cond), __VA_ARGS__)
-
-/**
- * Helper macros for log_badargs_if
- * The t parameters are the textual representation of the c parameters. They need to be passed
- * explicitly, to prevent them from being expanded in prescan.
- */
-#define _flib_lbi(c1,t1) log_e_if(c1, "Invalid Argument (%s)", t1)
-#define _flib_lbi2(c1,t1,c2,t2) (_flib_lbi(c1,t1) || _flib_lbi(c2,t2))
-#define _flib_lbi3(c1,t1,c2,t2,c3,t3) (_flib_lbi(c1,t1) || _flib_lbi2(c2,t2,c3,t3))
-#define _flib_lbi4(c1,t1,c2,t2,c3,t3,c4,t4) (_flib_lbi(c1,t1) || _flib_lbi3(c2,t2,c3,t3,c4,t4))
-#define _flib_lbi5(c1,t1,c2,t2,c3,t3,c4,t4,c5,t5) (_flib_lbi(c1,t1) || _flib_lbi4(c2,t2,c3,t3,c4,t4,c5,t5))
-#define _flib_lbi6(c1,t1,c2,t2,c3,t3,c4,t4,c5,t5,c6,t6) (_flib_lbi(c1,t1) || _flib_lbi5(c2,t2,c3,t3,c4,t4,c5,t5,c6,t6))
-
-/**
- * These macros log an "Invalid Argument" error for the first of their arguments that evaluates to true.
- * The text of the argument is included in the log message.
- * The expression returns true if any of its arguments is true (i.e. if an argument error was logged).
- *
- * For example, log_badargs_if(x==NULL) will log "Invalid Argument (x==NULL)" and return true if x is NULL.
- */
-#define log_badargs_if(c1) _flib_lbi(c1,#c1)
-#define log_badargs_if2(c1, c2) _flib_lbi2(c1,#c1,c2,#c2)
-#define log_badargs_if3(c1, c2, c3) _flib_lbi3(c1,#c1,c2,#c2,c3,#c3)
-#define log_badargs_if4(c1, c2, c3, c4) _flib_lbi4(c1,#c1,c2,#c2,c3,#c3,c4,#c4)
-#define log_badargs_if5(c1, c2, c3, c4, c5) _flib_lbi5(c1,#c1,c2,#c2,c3,#c3,c4,#c4,c5,#c5)
-#define log_badargs_if6(c1, c2, c3, c4, c5, c6) _flib_lbi6(c1,#c1,c2,#c2,c3,#c3,c4,#c4,c5,#c5,c6,#c6)
-
-#define log_oom_if(cond) log_e_if(cond, "Out of Memory")
-
-#define flib_log_e(...) _flib_flog(__func__, FLIB_LOGLEVEL_ERROR, __VA_ARGS__)
-#define flib_log_w(...) _flib_flog(__func__, FLIB_LOGLEVEL_WARNING, __VA_ARGS__)
-#define flib_log_i(...) _flib_flog(__func__, FLIB_LOGLEVEL_INFO, __VA_ARGS__)
-#define flib_log_d(...) _flib_flog(__func__, FLIB_LOGLEVEL_DEBUG, __VA_ARGS__)
-
-bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...);
-void _flib_flog(const char *func, int level, const char *fmt, ...);
-
-/**
- * Only log messages that are at least the indicated level
- */
-void flib_log_setLevel(int level);
-int flib_log_getLevel();
-
-/**
- * Log to the indicated file. You can pass NULL to log to stdout.
- * This overrides setCallback and vice versa.
- */
-void flib_log_setFile(FILE *logfile);
-
-/**
- * Returns whether messages of this level are logged at the moment.
- */
-bool flib_log_isActive(int level);
-
-/**
- * Allows logging through an arbitrary callback function. Useful for integrating into an
- * existing logging system. This overrides setFile and vice versa.
- */
-void flib_log_setCallback(void (*logCallback)(int level, const char *msg));
-
-#endif /* LOGGING_H_ */
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef LOGGING_H_
+#define LOGGING_H_
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#define FLIB_LOGLEVEL_ALL -100
+#define FLIB_LOGLEVEL_DEBUG -1
+#define FLIB_LOGLEVEL_INFO 0
+#define FLIB_LOGLEVEL_WARNING 1
+#define FLIB_LOGLEVEL_ERROR 2
+#define FLIB_LOGLEVEL_NONE 100
+
+/**
+ * Returns a pointer to a static buffer, don't free or store.
+ */
+char* flib_format_ip(uint32_t numip);
+
+/**
+ * Evaluates the expression cond. If it is true, a formatted error will be logged.
+ * Returns true if an error is logged, false otherwise (i.e. the boolean value of the argument)
+ * Usage: log_e_if(errorHasHappened, "Format string", formatArg, ...);
+ */
+#define log_e_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_ERROR, !(bool)(cond), __VA_ARGS__)
+#define log_w_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_WARNING, !(bool)(cond), __VA_ARGS__)
+
+/**
+ * Helper macros for log_badargs_if
+ * The t parameters are the textual representation of the c parameters. They need to be passed
+ * explicitly, to prevent them from being expanded in prescan.
+ */
+#define _flib_lbi(c1,t1) log_e_if(c1, "Invalid Argument (%s)", t1)
+#define _flib_lbi2(c1,t1,c2,t2) (_flib_lbi(c1,t1) || _flib_lbi(c2,t2))
+#define _flib_lbi3(c1,t1,c2,t2,c3,t3) (_flib_lbi(c1,t1) || _flib_lbi2(c2,t2,c3,t3))
+#define _flib_lbi4(c1,t1,c2,t2,c3,t3,c4,t4) (_flib_lbi(c1,t1) || _flib_lbi3(c2,t2,c3,t3,c4,t4))
+#define _flib_lbi5(c1,t1,c2,t2,c3,t3,c4,t4,c5,t5) (_flib_lbi(c1,t1) || _flib_lbi4(c2,t2,c3,t3,c4,t4,c5,t5))
+#define _flib_lbi6(c1,t1,c2,t2,c3,t3,c4,t4,c5,t5,c6,t6) (_flib_lbi(c1,t1) || _flib_lbi5(c2,t2,c3,t3,c4,t4,c5,t5,c6,t6))
+
+/**
+ * These macros log an "Invalid Argument" error for the first of their arguments that evaluates to true.
+ * The text of the argument is included in the log message.
+ * The expression returns true if any of its arguments is true (i.e. if an argument error was logged).
+ *
+ * For example, log_badargs_if(x==NULL) will log "Invalid Argument (x==NULL)" and return true if x is NULL.
+ */
+#define log_badargs_if(c1) _flib_lbi(c1,#c1)
+#define log_badargs_if2(c1, c2) _flib_lbi2(c1,#c1,c2,#c2)
+#define log_badargs_if3(c1, c2, c3) _flib_lbi3(c1,#c1,c2,#c2,c3,#c3)
+#define log_badargs_if4(c1, c2, c3, c4) _flib_lbi4(c1,#c1,c2,#c2,c3,#c3,c4,#c4)
+#define log_badargs_if5(c1, c2, c3, c4, c5) _flib_lbi5(c1,#c1,c2,#c2,c3,#c3,c4,#c4,c5,#c5)
+#define log_badargs_if6(c1, c2, c3, c4, c5, c6) _flib_lbi6(c1,#c1,c2,#c2,c3,#c3,c4,#c4,c5,#c5,c6,#c6)
+
+#define log_oom_if(cond) log_e_if(cond, "Out of Memory")
+
+#define flib_log_e(...) _flib_flog(__func__, FLIB_LOGLEVEL_ERROR, __VA_ARGS__)
+#define flib_log_w(...) _flib_flog(__func__, FLIB_LOGLEVEL_WARNING, __VA_ARGS__)
+#define flib_log_i(...) _flib_flog(__func__, FLIB_LOGLEVEL_INFO, __VA_ARGS__)
+#define flib_log_d(...) _flib_flog(__func__, FLIB_LOGLEVEL_DEBUG, __VA_ARGS__)
+
+bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...);
+void _flib_flog(const char *func, int level, const char *fmt, ...);
+
+/**
+ * Only log messages that are at least the indicated level
+ */
+void flib_log_setLevel(int level);
+int flib_log_getLevel();
+
+/**
+ * Log to the indicated file. You can pass NULL to log to stdout.
+ * This overrides setCallback and vice versa.
+ */
+void flib_log_setFile(FILE *logfile);
+
+/**
+ * Returns whether messages of this level are logged at the moment.
+ */
+bool flib_log_isActive(int level);
+
+/**
+ * Allows logging through an arbitrary callback function. Useful for integrating into an
+ * existing logging system. This overrides setFile and vice versa.
+ */
+void flib_log_setCallback(void (*logCallback)(int level, const char *msg));
+
+#endif /* LOGGING_H_ */
--- a/project_files/frontlib/util/util.c	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/util.c	Tue Jan 21 22:53:15 2014 +0100
@@ -1,212 +1,212 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#include "util.h"
-#include "logging.h"
-
-#include <stddef.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <limits.h>
-
-char *flib_asprintf(const char *fmt, ...) {
-	va_list argp;
-	va_start(argp, fmt);
-	char *result = flib_vasprintf(fmt, argp);
-	va_end(argp);
-	return result;
-}
-
-char *flib_vasprintf(const char *fmt, va_list args) {
-	char *result = NULL;
-	if(!log_badargs_if(fmt==NULL)) {
-		int requiredSize = vsnprintf(NULL, 0, fmt, args)+1;					// Figure out how much memory we need,
-		if(!log_e_if(requiredSize<0, "Error formatting string with template \"%s\"", fmt)) {
-			char *tmpbuf = flib_malloc(requiredSize);						// allocate it
-			if(tmpbuf && vsnprintf(tmpbuf, requiredSize, fmt, args)>=0) {	// and then do the actual formatting.
-				result = tmpbuf;
-				tmpbuf = NULL;
-			}
-			free(tmpbuf);
-		}
-	}
-	return result;
-}
-
-char *flib_join(char **parts, int partCount, const char *delimiter) {
-	char *result = NULL;
-	if(!log_badargs_if2(parts==NULL, delimiter==NULL)) {
-		size_t totalSize = 1;
-		size_t delimLen = strlen(delimiter);
-		for(int i=0; i<partCount; i++) {
-			totalSize += strlen(parts[i]) + delimLen;
-		}
-		result = flib_malloc(totalSize);
-
-		if(result) {
-			size_t outpos = 0;
-			for(int i=0; i<partCount; i++) {
-				if(i>0) {
-					strcpy(result+outpos, delimiter);
-					outpos += delimLen;
-				}
-				strcpy(result+outpos, parts[i]);
-				outpos += strlen(parts[i]);
-			}
-		}
-	}
-	return result;
-}
-
-char *flib_strdupnull(const char *str) {
-	return str==NULL ? NULL : flib_asprintf("%s", str);
-}
-
-void *flib_bufdupnull(const void *buf, size_t size) {
-	void *result = NULL;
-	if(!log_badargs_if(buf==NULL && size>0)) {
-		result = flib_malloc(size);
-		if(result) {
-			memcpy(result, buf, size);
-		}
-	}
-	return result;
-}
-
-void *flib_malloc(size_t size) {
-	void *result = malloc(size);
-	if(!result && size>0) {
-		flib_log_e("Out of memory trying to malloc %zu bytes.", size);
-	}
-	return result;
-}
-
-void *flib_calloc(size_t count, size_t elementsize) {
-	void *result = calloc(count, elementsize);
-	if(!result && count>0 && elementsize>0) {
-		flib_log_e("Out of memory trying to calloc %zu objects of %zu bytes each.", count, elementsize);
-	}
-	return result;
-}
-
-void *flib_realloc(void *ptr, size_t size) {
-	void *result = realloc(ptr, size);
-	if(!result && size>0) {
-		flib_log_e("Out of memory trying to realloc %zu bytes.", size);
-	}
-	return result;
-}
-
-static bool isAsciiAlnum(char c) {
-	return (c>='0' && c<='9') || (c>='a' && c <='z') || (c>='A' && c <='Z');
-}
-
-char *flib_urlencode(const char *inbuf) {
-	return flib_urlencode_pred(inbuf, isAsciiAlnum);
-}
-
-static size_t countCharsToEscape(const char *inbuf, bool (*needsEscaping)(char c)) {
-	size_t result = 0;
-	for(const char *c=inbuf; *c; c++) {
-		if(needsEscaping(*c)) {
-			result++;
-		}
-	}
-	return result;
-}
-
-char *flib_urlencode_pred(const char *inbuf, bool (*needsEscaping)(char c)) {
-	char *result = NULL;
-	if(inbuf && !log_badargs_if(needsEscaping == NULL)) {
-		size_t insize = strlen(inbuf);
-		if(!log_e_if(insize > SIZE_MAX/4, "String too long: %zu bytes.", insize)) {
-			size_t escapeCount = countCharsToEscape(inbuf, needsEscaping);
-			result = flib_malloc(insize + escapeCount*2 + 1);
-		}
-		if(result) {
-			char *out = result;
-			for(const char *in = inbuf; *in; in++) {
-				if(!needsEscaping(*in)) {
-					*out = *in;
-					out++;
-				} else {
-					snprintf(out, 4, "%%%02x", (unsigned)(*(uint8_t*)in));
-					out += 3;
-				}
-			}
-			*out = 0;
-		}
-	}
-	return result;
-}
-
-char *flib_urldecode(const char *inbuf) {
-	if(!inbuf) {
-		return NULL;
-	}
-	char *outbuf = flib_malloc(strlen(inbuf)+1);
-	if(!outbuf) {
-		return NULL;
-	}
-
-    size_t inpos = 0, outpos = 0;
-    while(inbuf[inpos]) {
-        if(inbuf[inpos] == '%' && isxdigit(inbuf[inpos+1]) && isxdigit(inbuf[inpos+2])) {
-            char temp[3] = {inbuf[inpos+1],inbuf[inpos+2],0};
-            outbuf[outpos++] = strtol(temp, NULL, 16);
-            inpos += 3;
-        } else {
-        	outbuf[outpos++] = inbuf[inpos++];
-        }
-    }
-    outbuf[outpos] = 0;
-    char *shrunk = realloc(outbuf, outpos+1);
-    return shrunk ? shrunk : outbuf;
-}
-
-bool flib_contains_dir_separator(const char *str) {
-	if(!log_badargs_if(!str)) {
-		for(;*str;str++) {
-			if(*str=='\\' || *str=='/') {
-				return true;
-			}
-		}
-	}
-	return false;
-}
-
-bool flib_strempty(const char *str) {
-	return !str || !*str;
-}
-
-int flib_gets(char *str, size_t strlen) {
-	if(fgets(str, strlen, stdin)) {
-		for(char *s=str; *s; s++) {
-			if(*s=='\r' || *s=='\n') {
-				*s = 0;
-				break;
-			}
-		}
-		return 0;
-	}
-	return -1;
-}
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "util.h"
+#include "logging.h"
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <limits.h>
+
+char *flib_asprintf(const char *fmt, ...) {
+    va_list argp;
+    va_start(argp, fmt);
+    char *result = flib_vasprintf(fmt, argp);
+    va_end(argp);
+    return result;
+}
+
+char *flib_vasprintf(const char *fmt, va_list args) {
+    char *result = NULL;
+    if(!log_badargs_if(fmt==NULL)) {
+        int requiredSize = vsnprintf(NULL, 0, fmt, args)+1;                 // Figure out how much memory we need,
+        if(!log_e_if(requiredSize<0, "Error formatting string with template \"%s\"", fmt)) {
+            char *tmpbuf = flib_malloc(requiredSize);                       // allocate it
+            if(tmpbuf && vsnprintf(tmpbuf, requiredSize, fmt, args)>=0) {   // and then do the actual formatting.
+                result = tmpbuf;
+                tmpbuf = NULL;
+            }
+            free(tmpbuf);
+        }
+    }
+    return result;
+}
+
+char *flib_join(char **parts, int partCount, const char *delimiter) {
+    char *result = NULL;
+    if(!log_badargs_if2(parts==NULL, delimiter==NULL)) {
+        size_t totalSize = 1;
+        size_t delimLen = strlen(delimiter);
+        for(int i=0; i<partCount; i++) {
+            totalSize += strlen(parts[i]) + delimLen;
+        }
+        result = flib_malloc(totalSize);
+
+        if(result) {
+            size_t outpos = 0;
+            for(int i=0; i<partCount; i++) {
+                if(i>0) {
+                    strcpy(result+outpos, delimiter);
+                    outpos += delimLen;
+                }
+                strcpy(result+outpos, parts[i]);
+                outpos += strlen(parts[i]);
+            }
+        }
+    }
+    return result;
+}
+
+char *flib_strdupnull(const char *str) {
+    return str==NULL ? NULL : flib_asprintf("%s", str);
+}
+
+void *flib_bufdupnull(const void *buf, size_t size) {
+    void *result = NULL;
+    if(!log_badargs_if(buf==NULL && size>0)) {
+        result = flib_malloc(size);
+        if(result) {
+            memcpy(result, buf, size);
+        }
+    }
+    return result;
+}
+
+void *flib_malloc(size_t size) {
+    void *result = malloc(size);
+    if(!result && size>0) {
+        flib_log_e("Out of memory trying to malloc %zu bytes.", size);
+    }
+    return result;
+}
+
+void *flib_calloc(size_t count, size_t elementsize) {
+    void *result = calloc(count, elementsize);
+    if(!result && count>0 && elementsize>0) {
+        flib_log_e("Out of memory trying to calloc %zu objects of %zu bytes each.", count, elementsize);
+    }
+    return result;
+}
+
+void *flib_realloc(void *ptr, size_t size) {
+    void *result = realloc(ptr, size);
+    if(!result && size>0) {
+        flib_log_e("Out of memory trying to realloc %zu bytes.", size);
+    }
+    return result;
+}
+
+static bool isAsciiAlnum(char c) {
+    return (c>='0' && c<='9') || (c>='a' && c <='z') || (c>='A' && c <='Z');
+}
+
+char *flib_urlencode(const char *inbuf) {
+    return flib_urlencode_pred(inbuf, isAsciiAlnum);
+}
+
+static size_t countCharsToEscape(const char *inbuf, bool (*needsEscaping)(char c)) {
+    size_t result = 0;
+    for(const char *c=inbuf; *c; c++) {
+        if(needsEscaping(*c)) {
+            result++;
+        }
+    }
+    return result;
+}
+
+char *flib_urlencode_pred(const char *inbuf, bool (*needsEscaping)(char c)) {
+    char *result = NULL;
+    if(inbuf && !log_badargs_if(needsEscaping == NULL)) {
+        size_t insize = strlen(inbuf);
+        if(!log_e_if(insize > SIZE_MAX/4, "String too long: %zu bytes.", insize)) {
+            size_t escapeCount = countCharsToEscape(inbuf, needsEscaping);
+            result = flib_malloc(insize + escapeCount*2 + 1);
+        }
+        if(result) {
+            char *out = result;
+            for(const char *in = inbuf; *in; in++) {
+                if(!needsEscaping(*in)) {
+                    *out = *in;
+                    out++;
+                } else {
+                    snprintf(out, 4, "%%%02x", (unsigned)(*(uint8_t*)in));
+                    out += 3;
+                }
+            }
+            *out = 0;
+        }
+    }
+    return result;
+}
+
+char *flib_urldecode(const char *inbuf) {
+    if(!inbuf) {
+        return NULL;
+    }
+    char *outbuf = flib_malloc(strlen(inbuf)+1);
+    if(!outbuf) {
+        return NULL;
+    }
+
+    size_t inpos = 0, outpos = 0;
+    while(inbuf[inpos]) {
+        if(inbuf[inpos] == '%' && isxdigit(inbuf[inpos+1]) && isxdigit(inbuf[inpos+2])) {
+            char temp[3] = {inbuf[inpos+1],inbuf[inpos+2],0};
+            outbuf[outpos++] = strtol(temp, NULL, 16);
+            inpos += 3;
+        } else {
+            outbuf[outpos++] = inbuf[inpos++];
+        }
+    }
+    outbuf[outpos] = 0;
+    char *shrunk = realloc(outbuf, outpos+1);
+    return shrunk ? shrunk : outbuf;
+}
+
+bool flib_contains_dir_separator(const char *str) {
+    if(!log_badargs_if(!str)) {
+        for(;*str;str++) {
+            if(*str=='\\' || *str=='/') {
+                return true;
+            }
+        }
+    }
+    return false;
+}
+
+bool flib_strempty(const char *str) {
+    return !str || !*str;
+}
+
+int flib_gets(char *str, size_t strlen) {
+    if(fgets(str, strlen, stdin)) {
+        for(char *s=str; *s; s++) {
+            if(*s=='\r' || *s=='\n') {
+                *s = 0;
+                break;
+            }
+        }
+        return 0;
+    }
+    return -1;
+}
--- a/project_files/frontlib/util/util.h	Wed Jan 22 01:11:13 2014 +0400
+++ b/project_files/frontlib/util/util.h	Tue Jan 21 22:53:15 2014 +0100
@@ -1,122 +1,122 @@
-/*
- * Hedgewars, a free turn based strategy game
- * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-#ifndef FLIB_UTIL_H_
-#define FLIB_UTIL_H_
-
-#include <stddef.h>
-#include <stdarg.h>
-#include <stdbool.h>
-
-/**
- * Prints a format string to a newly allocated buffer of the required size.
- * Parameters are like those for printf. Returns NULL on error.
- *
- * Returned buffer must be free()d
- */
-char *flib_asprintf(const char *fmt, ...);
-
-/**
- * Exactly as flib_asprintf, but accepts a va_list.
- */
-char *flib_vasprintf(const char *fmt, va_list args);
-
-/**
- * Creates a new string (that must be freed) containing all parts
- * joined together, with the specified delimiter between each.
- */
-char *flib_join(char **parts, int partCount, const char *delimiter);
-
-/**
- * Return a duplicate of the provided string, or NULL if an error
- * occurs or if str is already NULL.
- *
- * Returned buffer must be free()d
- */
-char *flib_strdupnull(const char *str);
-
-/**
- * Return a duplicate of the provided buffer, or NULL if an error
- * occurs or if buf is already NULL or if size is 0.
- *
- * Returned buffer must be free()d
- */
-void *flib_bufdupnull(const void *buf, size_t size);
-
-/**
- * Simple malloc wrapper that automatically logs an error if no memory
- * is available. Otherwise behaves exactly like malloc.
- */
-void *flib_malloc(size_t size);
-
-/**
- * Simple calloc wrapper that automatically logs an error if no memory
- * is available. Otherwise behaves exactly like calloc.
- */
-void *flib_calloc(size_t count, size_t elementsize);
-
-/**
- * Simple realloc wrapper that automatically logs an error if no memory
- * is available. Otherwise behaves exactly like realloc.
- */
-void *flib_realloc(void *ptr, size_t size);
-
-/**
- * Replace all non-alphanumeric and non-ascii bytes with escape
- * sequences in the form %XX. Does not modify the original string,
- * but returns a newly allocated one that must be free()d. Returns
- * null on failure or if null was passed as argument.
- *
- * This should work fine with all ASCII-based charsets including UTF-8.
- */
-char *flib_urlencode(const char *str);
-
-/**
- * Replace some bytes with escape sequences in the form %XX.
- * Does not modify the original string, but returns a newly allocated
- * one that must be free()d.
- *
- * All bytes for which the predicate function returns true are escaped.
- *
- * Returns null on failure or if null was passed as argument.
- */
-char *flib_urlencode_pred(const char *str, bool (*needsEscaping)(char c));
-
-/**
- * Replace escape sequences of the form %XX with their byte values.
- * Does not modify the original string, but returns a newly allocated
- * one that must be free()d. Returns null on failure or if null was
- * passed as argument.
- */
-char *flib_urldecode(const char *str);
-
-/**
- * Figure out if the string contains / or \. Useful in routines that
- * construct filenames.
- */
-bool flib_contains_dir_separator(const char *str);
-
-/**
- * Returns true if str is either NULL or points to a 0-length string
- */
-bool flib_strempty(const char *str);
-
-int flib_gets(char *str, size_t strlen);
-
-#endif
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef FLIB_UTIL_H_
+#define FLIB_UTIL_H_
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <stdbool.h>
+
+/**
+ * Prints a format string to a newly allocated buffer of the required size.
+ * Parameters are like those for printf. Returns NULL on error.
+ *
+ * Returned buffer must be free()d
+ */
+char *flib_asprintf(const char *fmt, ...);
+
+/**
+ * Exactly as flib_asprintf, but accepts a va_list.
+ */
+char *flib_vasprintf(const char *fmt, va_list args);
+
+/**
+ * Creates a new string (that must be freed) containing all parts
+ * joined together, with the specified delimiter between each.
+ */
+char *flib_join(char **parts, int partCount, const char *delimiter);
+
+/**
+ * Return a duplicate of the provided string, or NULL if an error
+ * occurs or if str is already NULL.
+ *
+ * Returned buffer must be free()d
+ */
+char *flib_strdupnull(const char *str);
+
+/**
+ * Return a duplicate of the provided buffer, or NULL if an error
+ * occurs or if buf is already NULL or if size is 0.
+ *
+ * Returned buffer must be free()d
+ */
+void *flib_bufdupnull(const void *buf, size_t size);
+
+/**
+ * Simple malloc wrapper that automatically logs an error if no memory
+ * is available. Otherwise behaves exactly like malloc.
+ */
+void *flib_malloc(size_t size);
+
+/**
+ * Simple calloc wrapper that automatically logs an error if no memory
+ * is available. Otherwise behaves exactly like calloc.
+ */
+void *flib_calloc(size_t count, size_t elementsize);
+
+/**
+ * Simple realloc wrapper that automatically logs an error if no memory
+ * is available. Otherwise behaves exactly like realloc.
+ */
+void *flib_realloc(void *ptr, size_t size);
+
+/**
+ * Replace all non-alphanumeric and non-ascii bytes with escape
+ * sequences in the form %XX. Does not modify the original string,
+ * but returns a newly allocated one that must be free()d. Returns
+ * null on failure or if null was passed as argument.
+ *
+ * This should work fine with all ASCII-based charsets including UTF-8.
+ */
+char *flib_urlencode(const char *str);
+
+/**
+ * Replace some bytes with escape sequences in the form %XX.
+ * Does not modify the original string, but returns a newly allocated
+ * one that must be free()d.
+ *
+ * All bytes for which the predicate function returns true are escaped.
+ *
+ * Returns null on failure or if null was passed as argument.
+ */
+char *flib_urlencode_pred(const char *str, bool (*needsEscaping)(char c));
+
+/**
+ * Replace escape sequences of the form %XX with their byte values.
+ * Does not modify the original string, but returns a newly allocated
+ * one that must be free()d. Returns null on failure or if null was
+ * passed as argument.
+ */
+char *flib_urldecode(const char *str);
+
+/**
+ * Figure out if the string contains / or \. Useful in routines that
+ * construct filenames.
+ */
+bool flib_contains_dir_separator(const char *str);
+
+/**
+ * Returns true if str is either NULL or points to a 0-length string
+ */
+bool flib_strempty(const char *str);
+
+int flib_gets(char *str, size_t strlen);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,84 @@
+#the usual set of dependencies
+find_package(OpenGL REQUIRED)
+find_package(GLEW REQUIRED)
+find_package(SDL REQUIRED)
+find_package(SDL_mixer REQUIRED)
+find_package(SDL_net REQUIRED)
+find_package(SDL_image REQUIRED)
+find_package(SDL_ttf REQUIRED)
+
+#compile our rtl implementation
+include_directories(${GLEW_INCLUDE_DIR})
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/rtl)
+include_directories(${PHYSFS_INCLUDE_DIR})
+include_directories(${PHYSLAYER_INCLUDE_DIR})
+add_subdirectory(rtl)
+
+configure_file(${CMAKE_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
+
+#get the list of pas files that are going to be converted and compiled
+file(GLOB engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/*.pas")
+#TODO: temporary until cmake can configure itself accordingly
+list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uWeb.pas")
+list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uVideoRec.pas")
+list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/uTouch.pas")
+list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/PNGh.pas")
+list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/pas2cSystem.pas")
+list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/pas2cRedo.pas")
+list(REMOVE_ITEM engine_sources_pas "${CMAKE_SOURCE_DIR}/hedgewars/hwLibrary.pas")
+
+#remove and readd hwengine so that it is compiled first, compiling every other file in the process
+list(REMOVE_ITEM engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas)
+list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas)
+
+#process files .pas -> .c
+foreach(sourcefile ${engine_sources_pas})
+    get_filename_component(sourcename ${sourcefile} NAME_WE) #drops .pas
+    list(APPEND engine_sources "${CMAKE_CURRENT_BINARY_DIR}/${sourcename}.c")
+endforeach()
+
+#add again files for external functions and for fpcrtl_ functions
+list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/pas2cSystem.pas)
+list(APPEND engine_sources_pas ${CMAKE_SOURCE_DIR}/hedgewars/pas2cRedo.pas)
+
+
+#invoke pas2c on main module, it will call all the others
+add_custom_command(OUTPUT ${engine_sources}
+                   COMMAND "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}"
+                   ARGS -n "hwengine"
+                        -i "${CMAKE_SOURCE_DIR}/hedgewars"
+                        -o "${CMAKE_CURRENT_BINARY_DIR}"
+                        -a "${CMAKE_CURRENT_BINARY_DIR}"
+                        -d "ENDIAN_LITTLE"
+                        -d "DEBUGFILE"
+                   DEPENDS pas2c                     #converter tool
+                           ${engine_sources_pas}     #original pascal file
+                  )
+
+#wrap conversion for all source in this command
+add_custom_target(engine_c DEPENDS ${engine_sources})
+
+
+#compile the c files
+add_executable(hwengine WIN32 ${engine_sources})
+
+target_link_libraries(hwengine  fpcrtl
+                                ${LUA_LIBRARY}
+                                ${OPENGL_LIBRARY}
+                                ${SDL_LIBRARY}
+                                ${SDLMIXER_LIBRARY}
+                                ${SDLNET_LIBRARY}
+                                ${SDLIMAGE_LIBRARY}
+                                ${SDLTTF_LIBRARY}
+                                ${GLEW_LIBRARY}
+                                physfs
+                                physlayer
+                                m
+                                #TODO: add other libraries
+                            )
+if(APPLE)
+    target_link_libraries(hwengine IOKit SDLmain)
+endif()
+
+install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_binary_install_dir})
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,16 @@
+
+include_directories(${GLEW_INCLUDE_DIR})
+
+file(GLOB fpcrtl_src *.c)
+
+add_library(fpcrtl STATIC ${fpcrtl_src})
+
+#if(WEBGL)
+#    set_target_properties(fpcrtl PROPERTIES PREFIX "em")
+#    set_target_properties(fpcrtl PROPERTIES SUFFIX ".bc")
+#endif(WEBGL)
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/GL.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,8 @@
+#pragma once
+
+#ifdef __APPLE__
+#include <OpenGL/gl.h>
+#else
+#include "GL/gl.h"
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/Math.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,4 @@
+#pragma once
+
+#include <math.h>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/SysUtils.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,41 @@
+#ifndef _FPCRTL_SYSUTILS_H_
+#define _FPCRTL_SYSUTILS_H_
+
+#include "Types.h"
+
+// EFFECTS: return the current date time in pascal notation
+//          http://www.merlyn.demon.co.uk/del-prgg.htm#TDT
+TDateTime   fpcrtl_now();
+#define     now                     fpcrtl_now
+#define     Now                     fpcrtl_now
+
+// EFFECTS: return the current time
+//          http://www.merlyn.demon.co.uk/del-prgg.htm#TDT
+TDateTime   fpcrtl_time();
+
+
+// EFFECTS: return the current date
+//          http://www.merlyn.demon.co.uk/del-prgg.htm#TDT
+TDateTime   fpcrtl_date();
+#define     date                    fpcrtl_date
+#define     Date                    fpcrtl_date
+
+// EFFECTS: Trim strips blank characters (spaces) at the beginning and end of S
+// and returns the resulting string. Only #32 characters are stripped.
+// If the string contains only spaces, an empty string is returned.
+string255   fpcrtl_trim(string255 s);
+#define     trim                    fpcrtl_trim
+#define     Trim                    fpcrtl_trim
+
+Integer     fpcrtl_strToInt(string255 s);
+#define     StrToInt                fpcrtl_strToInt
+#define     strToInt                fpcrtl_strToInt
+
+string255   fpcrtl_extractFileName(string255 f);
+#define     fpcrtl_ExtractFileName  fpcrtl_extractFileName
+
+string255   fpcrtl_strPas(PChar);
+#define     fpcrtl_StrPas           fpcrtl_strPas
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/Types.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,39 @@
+#ifndef _TYPES_H_
+#define _TYPES_H_
+
+#include "pas2c.h"
+
+/*
+ * Not very useful currently
+ */
+
+typedef double TDate;
+typedef double TTime;
+typedef double TDateTime;
+typedef string255 TMonthNameArray[13];
+typedef string255 TWeekNameArray[8];
+
+typedef struct {
+    Byte CurrencyFormat;
+    Byte NegCurrFormat;
+    Char ThousandSeparator;
+    Char DecimalSeparator;
+    Byte CurrencyDecimals;
+    Char DateSeparator;
+    Char TimeSeparator;
+    Char ListSeparator;
+    string255 CurrencyString;
+    string255 ShortDateFormat;
+    string255 LongDateFormat;
+    string255 TimeAMString;
+    string255 TimePMString;
+    string255 ShortTimeFormat;
+    string255 LongTimeFormat;
+    TMonthNameArray ShortMonthNames;
+    TMonthNameArray LongMonthNames;
+    TWeekNameArray ShortDayNames;
+    TWeekNameArray LongDayNames;
+    Word TwoDigitYearCenturyWindow;
+}TFormatSettings;
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/fileio.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,225 @@
+/*
+ * XXX: assume all files are text files
+ */
+
+#include "misc.h"
+#include "fileio.h"
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <sys/stat.h>
+
+io_result_t IOResult;
+int FileMode;
+
+static void init(File f) {
+    f->fp = NULL;
+    f->eof = 0;
+    f->mode = NULL;
+    f->record_len = 0;
+}
+
+void fpcrtl_assign__vars(File *f, string255 name) {
+    FIX_STRING(name);
+    *f = (File) malloc(sizeof(file_wrapper_t));
+    strcpy((*f)->file_name, name.str);
+    init(*f);
+}
+
+void fpcrtl_reset1(File f) {
+    f->fp = fopen(f->file_name, "r");
+    if (!f->fp) {
+        IOResult = IO_ERROR_DUMMY;
+        printf("Failed to open %s\n", f->file_name);
+        return;
+    } else {
+#ifdef FPCRTL_DEBUG
+        printf("Opened %s\n", f->file_name);
+#endif
+    }
+    IOResult = IO_NO_ERROR;
+    f->mode = "r";
+}
+
+void fpcrtl_reset2(File f, int l) {
+    f->eof = 0;
+    f->fp = fopen(f->file_name, "rb");
+    if (!f->fp) {
+        IOResult = IO_ERROR_DUMMY;
+        printf("Failed to open %s\n", f->file_name);
+        return;
+    }
+    IOResult = IO_NO_ERROR;
+    f->mode = "rb";
+    f->record_len = l;
+}
+
+void __attribute__((overloadable)) fpcrtl_rewrite(File f) {
+    f->fp = fopen(f->file_name, "w+");
+    if (!f->fp) {
+        IOResult = IO_ERROR_DUMMY;
+        return;
+    }
+    IOResult = IO_NO_ERROR;
+    f->mode = "w+";
+}
+
+void __attribute__((overloadable)) fpcrtl_rewrite(File f, Integer l) {
+    IOResult = IO_NO_ERROR;
+    fpcrtl_rewrite(f);
+    if (f->fp) {
+        f->record_len = l;
+    }
+}
+
+void fpcrtl_close(File f) {
+    IOResult = IO_NO_ERROR;
+    fclose(f->fp);
+    free(f);
+}
+
+boolean fpcrtl_eof(File f) {
+    IOResult = IO_NO_ERROR;
+    if (f->eof || f->fp == NULL || feof(f->fp)) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
+void __attribute__((overloadable)) fpcrtl_readLn(File f) {
+    IOResult = IO_NO_ERROR;
+    char line[256];
+    if (fgets(line, sizeof(line), f->fp) == NULL) {
+        f->eof = 1;
+    }
+    if (feof(f->fp)) {
+        f->eof = 1;
+    }
+}
+
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, Integer *i) {
+    string255 s;
+
+    if (feof(f->fp)) {
+        f->eof = 1;
+        return;
+    }
+
+    fpcrtl_readLn__vars(f, &s);
+
+    *i = atoi(s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, LongWord *i) {
+    string255 s;
+
+    if (feof(f->fp)) {
+        f->eof = 1;
+        return;
+    }
+
+    fpcrtl_readLn__vars(f, &s);
+
+    *i = atoi(s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, string255 *s) {
+
+    if (fgets(s->str, 255, f->fp) == NULL) {
+
+        s->len = 0;
+        s->str[0] = 0;
+
+        f->eof = 1;
+        return;
+    }
+
+    if (feof(f->fp)) {
+        s->len = 0;
+        f->eof = 1;
+        return;
+    }
+
+    IOResult = IO_NO_ERROR;
+
+    s->len = strlen(s->str);
+    if ((s->len > 0) && (s->str[s->len - 1] == '\n')) {
+        s->str[s->len - 1] = 0;
+        s->len--;
+    }
+}
+
+void __attribute__((overloadable)) fpcrtl_write(File f, string255 s) {
+    FIX_STRING(s);
+    fprintf(f->fp, "%s", s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_write(FILE *f, string255 s) {
+    FIX_STRING(s);
+    fprintf(f, "%s", s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_writeLn(File f, string255 s) {
+    FIX_STRING(s);
+    fprintf(f->fp, "%s\n", s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_writeLn(FILE *f, string255 s) {
+    FIX_STRING(s);
+    fprintf(f, "%s\n", s.str);
+}
+
+void fpcrtl_blockRead__vars(File f, void *buf, Integer count, Integer *result) {
+    assert(f->record_len > 0);
+    *result = fread(buf, f->record_len, count, f->fp);
+}
+
+/*
+ * XXX: dummy blockWrite
+ */
+void fpcrtl_blockWrite__vars(File f, const void *buf, Integer count,
+        Integer *result) {
+    assert(0);
+}
+
+bool fpcrtl_directoryExists(string255 dir) {
+
+    struct stat st;
+    FIX_STRING(dir);
+
+    IOResult = IO_NO_ERROR;
+
+#ifdef FPCRTL_DEBUG
+    printf("Warning: directoryExists is called. This may not work when compiled to js.\n");
+#endif
+
+    if (stat(dir.str, &st) == 0) {
+        return true;
+    }
+
+    return false;
+}
+
+bool fpcrtl_fileExists(string255 filename) {
+
+    FIX_STRING(filename);
+
+    IOResult = IO_NO_ERROR;
+
+    FILE *fp = fopen(filename.str, "r");
+    if (fp) {
+        fclose(fp);
+        return true;
+    }
+    return false;
+}
+
+void __attribute__((overloadable)) fpcrtl_flush(Text f) {
+    fflush(f->fp);
+}
+
+void __attribute__((overloadable)) fpcrtl_flush(FILE *f) {
+    fflush(f);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/fileio.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,78 @@
+#ifndef FILEIO_H_
+#define FILEIO_H_
+
+#include <stdio.h>
+#include "Types.h"
+#include "misc.h"
+
+extern        int                                       FileMode;
+
+typedef enum{
+    IO_NO_ERROR = 0,
+    IO_ERROR_DUMMY = 1
+}io_result_t;
+
+extern        io_result_t                               IOResult;
+
+typedef struct{
+    FILE        *fp;
+    const char* mode;
+    char        file_name[256];
+    int         eof;
+    int            record_len;
+}file_wrapper_t;
+
+typedef     file_wrapper_t*                             File;
+typedef     File                                        Text;
+typedef     Text                                        TextFile;
+
+void        __attribute__((overloadable))               fpcrtl_readLn(File f);
+#define     fpcrtl_readLn1(f)                           fpcrtl_readLn(f)
+
+void        __attribute__((overloadable))               fpcrtl_readLn__vars(File f, Integer *i);
+void        __attribute__((overloadable))               fpcrtl_readLn__vars(File f, LongWord *i);
+void        __attribute__((overloadable))               fpcrtl_readLn__vars(File f, string255 *s);
+#define     fpcrtl_readLn2(f, t)                        fpcrtl_readLn__vars(f, &(t))
+
+#define     fpcrtl_readLn(...)                          macro_dispatcher(fpcrtl_readLn, __VA_ARGS__)(__VA_ARGS__)
+
+
+void        fpcrtl_blockRead__vars(File f, void *buf, Integer count, Integer *result);
+#define     fpcrtl_blockRead(f, buf, count, result)     fpcrtl_blockRead__vars(f, &(buf), count, &(result))
+#define     fpcrtl_BlockRead                            fpcrtl_blockRead
+
+#define     fpcrtl_assign(f, name)                      fpcrtl_assign__vars(&f, name)
+void        fpcrtl_assign__vars(File *f, string255 name);
+
+boolean     fpcrtl_eof(File f);
+
+void        fpcrtl_reset1(File f);
+void        fpcrtl_reset2(File f, Integer l);
+#define     fpcrtl_reset1(f)                            fpcrtl_reset1(f)
+#define     fpcrtl_reset2(f, l)                         fpcrtl_reset2(f, l)
+#define     fpcrtl_reset(...)                           macro_dispatcher(fpcrtl_reset, __VA_ARGS__)(__VA_ARGS__)
+
+void        fpcrtl_close(File f);
+
+void        __attribute__((overloadable))               fpcrtl_rewrite(File f);
+void        __attribute__((overloadable))               fpcrtl_rewrite(File f, Integer l);
+
+void        __attribute__((overloadable))               fpcrtl_flush(Text f);
+void        __attribute__((overloadable))               fpcrtl_flush(FILE *f);
+
+void        __attribute__((overloadable))               fpcrtl_write(File f, string255 s);
+void        __attribute__((overloadable))               fpcrtl_write(FILE *f, string255 s);
+void        __attribute__((overloadable))               fpcrtl_writeLn(File f, string255 s);
+void        __attribute__((overloadable))               fpcrtl_writeLn(FILE *f, string255 s);
+
+void        fpcrtl_blockWrite__vars(File f, const void *buf, Integer count, Integer *result);
+#define     fpcrtl_blockWrite(f, buf, count, result)    fpcrtl_blockWrite__vars(f, &(buf), count, &(result))
+#define     fpcrtl_BlockWrite                           fpcrtl_blockWrite
+
+bool        fpcrtl_directoryExists(string255 dir);
+#define     fpcrtl_DirectoryExists                      fpcrtl_directoryExists
+
+bool        fpcrtl_fileExists(string255 filename);
+#define     fpcrtl_FileExists                           fpcrtl_fileExists
+
+#endif /* FILEIO_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/fpcrtl.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,202 @@
+#ifndef _FPCRTL_H_
+#define _FPCRTL_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <math.h>
+
+#include "SysUtils.h"
+#include "system.h"
+#include "misc.h"
+#include "fileio.h"
+#include "pmath.h"
+
+#ifndef EMSCRIPTEN
+#if __APPLE__
+#define main SDL_main
+#endif
+#include "GL/glew.h"
+#endif
+
+#define fpcrtl_memcpy                       memcpy
+
+#define luapas_lua_gettop                   lua_gettop
+#define luapas_lua_close                    lua_close
+#define luapas_lua_createtable              lua_createtable
+#define luapas_lua_error                    lua_error
+#define luapas_lua_gc                       lua_gc
+#define luapas_lua_getfield                 lua_getfield
+#define luapas_lua_objlen                   lua_objlen
+#define luapas_lua_call                     lua_call
+#define luapas_lua_pcall                    lua_pcall
+#define luapas_lua_pushboolean              lua_pushboolean
+#define luapas_lua_pushcclosure             lua_pushcclosure
+#define luapas_lua_pushinteger              lua_pushinteger
+#define luapas_lua_pushnil                  lua_pushnil
+#define luapas_lua_pushnumber               lua_pushnumber
+#define luapas_lua_pushlstring              lua_pushlstring
+#define luapas_lua_pushstring               lua_pushstring
+#define luapas_lua_pushvalue                lua_pushvalue
+#define luapas_lua_rawgeti                  lua_rawgeti
+#define luapas_lua_setfield                 lua_setfield
+#define luapas_lua_settop                   lua_settop
+#define luapas_lua_toboolean                lua_toboolean
+#define luapas_lua_tointeger                lua_tointeger
+#define luapas_lua_tolstring                lua_tolstring
+#define luapas_lua_tonumber                 lua_tonumber
+#define luapas_lua_type                     lua_type
+#define luapas_lua_typename                 lua_typename
+#define luapas_luaL_argerror                luaL_argerror
+#define luapas_luaL_checkinteger            luaL_checkinteger
+#define luapas_luaL_checklstring            luaL_checklstring
+#define luapas_luaL_loadfile                luaL_loadfile
+#define luapas_luaL_loadstring              luaL_loadstring
+#define luapas_luaL_newstate                luaL_newstate
+#define luapas_luaL_optinteger              luaL_optinteger
+#define luapas_luaL_optlstring              luaL_optlstring
+#define luapas_luaL_prepbuffer              luaL_prepbuffer
+#define luapas_luaL_ref                     luaL_ref
+#define luapas_luaL_unref                   luaL_unref
+#define luapas_luaopen_base                 luaopen_base
+#define luapas_luaopen_math                 luaopen_math
+#define luapas_luaopen_string               luaopen_string
+#define luapas_luaopen_table                luaopen_table
+#define luapas_lua_load                     lua_load
+
+#define sdlh_IMG_Load                       IMG_Load
+#define sdlh_IMG_Load_RW                    IMG_Load_RW
+
+#ifndef EMSCRIPTEN
+#define sdlh_Mix_AllocateChannels           Mix_AllocateChannels
+#define sdlh_Mix_CloseAudio                 Mix_CloseAudio
+#define sdlh_Mix_FadeInChannelTimed         Mix_FadeInChannelTimed
+#define sdlh_Mix_FadeInMusic                Mix_FadeInMusic
+#define sdlh_Mix_FadeOutChannel             Mix_FadeOutChannel
+#define sdlh_Mix_FreeChunk                  Mix_FreeChunk
+#define sdlh_Mix_FreeMusic                  Mix_FreeMusic
+#define sdlh_Mix_HaltChannel                Mix_HaltChannel
+#define sdlh_Mix_HaltMusic                  Mix_HaltMusic
+#define sdlh_Mix_LoadMUS                    Mix_LoadMUS
+#define sdlh_Mix_LoadMUS_RW                 Mix_LoadMUS_RW
+#define sdlh_Mix_LoadWAV_RW                 Mix_LoadWAV_RW
+#define sdlh_Mix_OpenAudio                  Mix_OpenAudio
+#define sdlh_Mix_PauseMusic                 Mix_PauseMusic
+#define sdlh_Mix_PlayChannelTimed           Mix_PlayChannelTimed
+#define sdlh_Mix_Playing                    Mix_Playing
+#define sdlh_Mix_ResumeMusic                Mix_ResumeMusic
+#define sdlh_Mix_Volume                     Mix_Volume
+#define sdlh_Mix_VolumeMusic                Mix_VolumeMusic
+#else
+#define sdlh_Mix_AllocateChannels           stub_Mix_AllocateChannels
+#define sdlh_Mix_CloseAudio                 stub_Mix_CloseAudio
+#define sdlh_Mix_FadeInChannelTimed         stub_Mix_FadeInChannelTimed
+#define sdlh_Mix_FadeInMusic                stub_Mix_FadeInMusic
+#define sdlh_Mix_FadeOutChannel             stub_Mix_FadeOutChannel
+#define sdlh_Mix_FreeChunk                  stub_Mix_FreeChunk
+#define sdlh_Mix_FreeMusic                  stub_Mix_FreeMusic
+#define sdlh_Mix_HaltChannel                stub_Mix_HaltChannel
+#define sdlh_Mix_HaltMusic                  stub_Mix_HaltMusic
+#define sdlh_Mix_LoadMUS                    stub_Mix_LoadMUS
+#define sdlh_Mix_LoadMUS_RW                 stub_Mix_LoadMUS_RW
+#define sdlh_Mix_LoadWAV_RW                 stub_Mix_LoadWAV_RW
+#define sdlh_Mix_OpenAudio                  stub_Mix_OpenAudio
+#define sdlh_Mix_PauseMusic                 stub_Mix_PauseMusic
+#define sdlh_Mix_PlayChannelTimed           stub_Mix_PlayChannelTimed
+#define sdlh_Mix_Playing                    stub_Mix_Playing
+#define sdlh_Mix_ResumeMusic                stub_Mix_ResumeMusic
+#define sdlh_Mix_Volume                     stub_Mix_Volume
+#define sdlh_Mix_VolumeMusic                stub_Mix_VolumeMusic
+#endif
+
+#define sdlh_SDL_ConvertSurface             SDL_ConvertSurface
+#define sdlh_SDL_CreateRGBSurface           SDL_CreateRGBSurface
+#define sdlh_SDL_CreateThread               SDL_CreateThread
+#define sdlh_SDL_Delay                      SDL_Delay
+#define sdlh_SDL_EnableKeyRepeat            SDL_EnableKeyRepeat
+#define sdlh_SDL_EnableUNICODE              SDL_EnableUNICODE
+#define sdlh_SDL_FillRect                   SDL_FillRect
+#define sdlh_SDL_FreeSurface                SDL_FreeSurface
+#define sdlh_SDL_GetError                   SDL_GetError
+#define sdlh_SDL_GetKeyName                 SDL_GetKeyName
+#define sdlh_SDL_GetKeyState                SDL_GetKeyState
+#define sdlh_SDL_GetMouseState              SDL_GetMouseState
+#define sdlh_SDL_GetRGBA                    SDL_GetRGBA
+#define sdlh_SDL_GetTicks                   SDL_GetTicks
+#define sdlh_SDL_GL_SetAttribute            SDL_GL_SetAttribute
+#define sdlh_SDL_GL_SwapBuffers             SDL_GL_SwapBuffers
+#define sdlh_SDL_Init                       SDL_Init
+#define sdlh_SDL_InitSubSystem              SDL_InitSubSystem
+#define sdlh_SDL_JoystickClose              SDL_JoystickClose
+#define sdlh_SDL_JoystickEventState         SDL_JoystickEventState
+#define sdlh_SDL_JoystickName               SDL_JoystickName
+#define sdlh_SDL_JoystickNumAxes            SDL_JoystickNumAxes
+#define sdlh_SDL_JoystickNumButtons         SDL_JoystickNumButtons
+#define sdlh_SDL_JoystickNumHats            SDL_JoystickNumHats
+#define sdlh_SDL_JoystickOpen               SDL_JoystickOpen
+#define sdlh_SDL_LockSurface                SDL_LockSurface
+#define sdlh_SDL_MapRGB                     SDL_MapRGB
+#define sdlh_SDL_MapRGBA                    SDL_MapRGBA
+#define sdlh_SDL_NumJoysticks               SDL_NumJoysticks
+#define sdlh_SDL_PeepEvents                 SDL_PeepEvents
+#define sdlh_SDL_PumpEvents                 SDL_PumpEvents
+#define sdlh_SDL_Quit                       SDL_Quit
+#define sdlh_SDL_RWFromFile                 SDL_RWFromFile
+#define sdlh_SDL_SetColorKey                SDL_SetColorKey
+#define sdlh_SDL_SetVideoMode               SDL_SetVideoMode
+#define sdlh_SDL_WaitThread                 SDL_WaitThread
+#define sdlh_SDL_CreateMutex                SDL_CreateMutex
+#define sdlh_SDL_DestroyMutex               SDL_DestroyMutex
+#define sdlh_SDL_LockMutex                  SDL_mutexP
+#define sdlh_SDL_UnlockMutex                SDL_mutexV
+#ifndef EMSCRIPTEN
+#define sdlh_SDL_ShowCursor                 SDL_ShowCursor
+#else
+#define sdlh_SDL_ShowCursor                 SDL_ShowCursor_patch
+#endif
+#define sdlh_SDL_UnlockSurface              SDL_UnlockSurface
+#define sdlh_SDL_UpperBlit                  SDL_UpperBlit
+#define sdlh_SDL_VideoDriverName            SDL_VideoDriverName
+#define sdlh_SDL_WarpMouse                  SDL_WarpMouse
+#define sdlh_SDL_WM_SetCaption              SDL_WM_SetCaption
+#define sdlh_SDL_WM_SetIcon                 SDL_WM_SetIcon
+#define sdlh_SDLNet_AddSocket               SDLNet_AddSocket
+#define sdlh_SDLNet_AllocSocketSet          SDLNet_AllocSocketSet
+#define sdlh_SDLNet_CheckSockets            SDLNet_CheckSockets
+#define sdlh_SDLNet_FreeSocketSet           SDLNet_FreeSocketSet
+#define sdlh_SDLNet_Init                    SDLNet_Init
+#define sdlh_SDLNet_Quit                    SDLNet_Quit
+#define sdlh_SDLNet_ResolveHost             SDLNet_ResolveHost
+#define sdlh_SDLNet_TCP_Close               SDLNet_TCP_Close
+#define sdlh_SDLNet_TCP_Open                SDLNet_TCP_Open
+#define sdlh_SDLNet_TCP_Recv                SDLNet_TCP_Recv
+#define sdlh_SDLNet_TCP_Send                SDLNet_TCP_Send
+#define sdlh_TTF_Init                       TTF_Init
+#define sdlh_TTF_OpenFont                   TTF_OpenFont
+#define sdlh_TTF_OpenFontRW                 TTF_OpenFontRW
+#define sdlh_TTF_Quit                       TTF_Quit
+#define sdlh_TTF_RenderUTF8_Blended         TTF_RenderUTF8_Blended
+#define sdlh_TTF_RenderUTF8_Solid           TTF_RenderUTF8_Solid
+#define sdlh_TTF_SetFontStyle               TTF_SetFontStyle
+#define sdlh_TTF_SizeUTF8                   TTF_SizeUTF8
+
+#define _strconcat                          fpcrtl_strconcat
+#define _strappend                          fpcrtl_strappend
+#define _strprepend                         fpcrtl_strprepend
+#define _strcompare                         fpcrtl_strcompare
+#define _strncompare                        fpcrtl_strncompare
+#define _strcomparec                        fpcrtl_strcomparec
+#define _chrconcat                          fpcrtl_chrconcat
+#define _pchar                              fpcrtl_pchar
+
+// hooks are implemented in javascript
+void start_hook(void);
+void mainloop_hook(void);
+void clear_filelist_hook(void);
+void add_file_hook(const char* ptr);
+void idb_loader_hook();
+void showcursor_hook();
+void hidecursor_hook();
+void drawworld_init_hook();
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/misc.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,168 @@
+#include "misc.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+
+char strbuf[512];
+
+void fpcrtl_assert(int i)
+{
+    if(!i){
+        assert(0);
+    }
+}
+
+// EFFECTS: return the nearest integer of the given number
+int fpcrtl_round(double number)
+{
+    return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5);
+}
+
+void fpcrtl_printf(const char* format, ...)
+{
+#ifdef FPCRTL_DEBUG
+    va_list args;
+    va_start (args, format);
+    vprintf (format, args);
+    va_end (args);
+#endif
+}
+
+//
+//void fpcrtl_check_string(string255 str)
+//{
+//#ifdef FPCRTL_DEBUG
+//    int len = strlen(str.str);
+//    if(len != str.len){
+//        printf("String %s internal inconsistency error. Length should be %d but actually is %d.\n", str.str, len, str.len);
+//    }
+//    //assert(len == str.len);
+//#endif
+//}
+
+string255 fpcrtl_strconcat(string255 str1, string255 str2)
+{
+    //printf("str1 = %d, %d\n", str1.len, strlen(str1.str));
+    //printf("str2 = %d, %d\n", str2.len, strlen(str2.str));
+
+#ifdef FPCRTL_DEBUG
+    if(str1.len + (int)(str2.len) > 255){
+        printf("String overflow\n");
+        printf("str1(%d): %s\nstr2(%d): %s\n", str1.len, str1.str, str2.len, str2.str);
+        printf("String will be truncated.\n");
+
+        strbuf[0] = 0;
+        strcpy(strbuf, str1.str);
+        strcat(strbuf, str2.str);
+        memcpy(str1.str, strbuf, 255);
+        str1.str[254] = 0;
+
+        return str1;
+    }
+#endif
+
+    memcpy(&(str1.str[str1.len]), str2.str, str2.len);
+    str1.str[str1.len + str2.len] = 0;
+    str1.len += str2.len;
+
+    return str1;
+}
+
+string255 fpcrtl_strappend(string255 s, char c)
+{
+    s.str[s.len] = c;
+    s.str[s.len + 1] = 0;
+    s.len ++;
+
+    return s;
+}
+
+string255 fpcrtl_strprepend(char c, string255 s)
+{
+    FIX_STRING(s);
+
+    memmove(s.str + 1, s.str, s.len + 1); // also move '/0'
+    s.str[0] = c;
+    s.len++;
+
+    return s;
+}
+
+string255 fpcrtl_chrconcat(char a, char b)
+{
+    string255 result;
+
+    result.len = 2;
+    result.str[0] = a;
+    result.str[1] = b;
+    result.str[2] = 0;
+
+    return result;
+}
+
+bool fpcrtl_strcompare(string255 str1, string255 str2)
+{
+    //printf("str1 = %d, %d\n", str1.len, strlen(str1.str));
+    //printf("str2 = %d, %d\n", str2.len, strlen(str2.str));
+    FIX_STRING(str1);
+    FIX_STRING(str2);
+
+    if(strcmp(str1.str, str2.str) == 0){
+        return true;
+    }
+
+    return false;
+}
+
+bool fpcrtl_strcomparec(string255 a, char b)
+{
+    FIX_STRING(a);
+
+    if(a.len == 1 && a.str[0] == b){
+        return true;
+    }
+
+    return false;
+}
+
+bool fpcrtl_strncompare(string255 a, string255 b)
+{
+    return !fpcrtl_strcompare(a, b);
+}
+
+//char* fpcrtl_pchar(string255 s)
+//{
+//    return s.str;
+//}
+
+string255 fpcrtl_pchar2str(char *s)
+{
+    string255 result;
+    int t = strlen(s);
+
+    if(t > 255){
+        printf("pchar2str, length > 255\n");
+        assert(0);
+    }
+
+    result.len = t;
+    memcpy(result.str, s, t);
+    result.str[t] = 0;
+
+    return result;
+}
+
+string255 fpcrtl_make_string(const char* s) {
+    string255 result;
+    strcpy(result.str, s);
+    result.len = strlen(s);
+    return result;
+}
+
+#ifdef EMSCRIPTEN
+GLenum glewInit()
+{
+    return GLEW_OK;
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/misc.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,58 @@
+#ifndef _FPCRTL_MISC_H_
+#define _FPCRTL_MISC_H_
+
+#include "pas2c.h"
+#include <assert.h>
+#include <stdbool.h>
+
+#ifdef EMSCRIPTEN
+#include <GL/gl.h>
+#else
+#include <GL/glew.h>
+#endif
+
+#define     VA_NUM_ARGS(...)                        VA_NUM_ARGS_IMPL(__VA_ARGS__, 5,4,3,2,1)
+#define     VA_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,N,...)  N
+
+#define     macro_dispatcher(func, ...)             macro_dispatcher_(func, VA_NUM_ARGS(__VA_ARGS__))
+#define     macro_dispatcher_(func, nargs)          macro_dispatcher__(func, nargs)
+#define     macro_dispatcher__(func, nargs)         func ## nargs
+
+#define     FPCRTL_DEBUG
+
+#define     FIX_STRING(s)                           (s.str[s.len] = 0)
+
+//#define fpcrtl_check_string(s)     do{ if(strlen((s).str) != (s).len){ \
+//                                        printf("String %s internal inconsistency error. Length should be %d but actually is %d.\n", (s).str, strlen((s).str), (s).len); \
+//                                        assert(0);\
+//                                    }}while(0)
+
+void        fpcrtl_assert(int);
+void        fpcrtl_print_trace (void);
+
+int         fpcrtl_round(double number);
+void        fpcrtl_printf(const char* format, ...);
+
+string255   fpcrtl_make_string(const char* s);
+
+string255   fpcrtl_strconcat(string255 str1, string255 str2);
+string255   fpcrtl_strappend(string255 s, char c);
+string255   fpcrtl_strprepend(char c, string255 s);
+string255   fpcrtl_chrconcat(char a, char b);
+
+// return true if str1 == str2
+bool        fpcrtl_strcompare(string255 str1, string255 str2);
+bool        fpcrtl_strcomparec(string255 a, char b);
+bool        fpcrtl_strncompare(string255 a, string255 b);
+
+#define     fpcrtl__pchar(s)                        ((s).str)
+string255   fpcrtl_pchar2str(char *s);
+
+#define     fpcrtl_TypeInfo                         sizeof // dummy
+
+#ifdef EMSCRIPTEN
+#define     GLEW_OK                                 1
+GLenum      glewInit();
+#endif
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/pas2c.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,80 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <wchar.h>
+#include <math.h>
+
+#define MAX_PARAMS 64
+
+typedef union string255_
+    {
+        struct {
+            unsigned char s[257];
+        };
+        struct {
+            unsigned char len;
+            unsigned char str[256];
+        };
+    } string255;
+typedef struct string192_
+    {
+        unsigned char s[193];
+    } string192;
+typedef struct string31_
+    {
+        unsigned char s[32];
+    } string31;
+typedef struct string15_
+    {
+        unsigned char s[16];
+    } string15;
+
+typedef string255 shortstring;
+typedef string255 ansistring;
+
+typedef uint8_t Byte;
+typedef int8_t ShortInt;
+typedef uint16_t Word;
+typedef int16_t SmallInt;
+typedef uint32_t LongWord;
+typedef int32_t LongInt;
+typedef uint64_t QWord;
+typedef int64_t Int64;
+typedef LongWord Cardinal;
+
+typedef LongInt Integer;
+typedef float extended;
+typedef float real;
+typedef float single;
+
+typedef bool boolean;
+typedef int LongBool;
+
+typedef void * pointer;
+typedef Byte * PByte;
+typedef char * PChar;
+typedef LongInt * PLongInt;
+typedef LongWord * PLongWord;
+typedef Integer * PInteger;
+typedef int PtrInt;
+typedef wchar_t widechar;
+typedef wchar_t* PWideChar;
+typedef char Char;
+typedef LongInt SizeInt;
+typedef char ** PPChar;
+typedef Word* PWord;
+
+string255 _strconcat(string255 a, string255 b);
+string255 _strappend(string255 s, unsigned char c);
+string255 _strprepend(unsigned char c, string255 s);
+string255 _chrconcat(unsigned char a, unsigned char b);
+bool _strcompare(string255 a, string255 b);
+bool _strcomparec(string255 a, unsigned char b);
+bool _strncompare(string255 a, string255 b);
+
+
+#define STRINIT(a) {.len = sizeof(a) - 1, .str = a}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/pmath.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,49 @@
+#include "pmath.h"
+#include <stdlib.h>
+#include <math.h>
+
+/*
+ * power raises base to the power power.
+ * This is equivalent to exp(power*ln(base)). Therefore base should be non-negative.
+ */
+float fpcrtl_power(float base, float exponent)
+{
+    return exp(exponent * log(base));
+}
+
+/* Currently the games only uses sign of an integer */
+int fpcrtl_signi(int x)
+{
+    if(x > 0){
+        return 1;
+    }
+    else if(x < 0){
+        return -1;
+    }
+    else{
+        return 0;
+    }
+}
+
+float fpcrtl_csc(float x)
+{
+    return 1 / sin(x);
+}
+
+float __attribute__((overloadable)) fpcrtl_abs(float x)
+{
+    return fabs(x);
+}
+double __attribute__((overloadable)) fpcrtl_abs(double x)
+{
+    return fabs(x);
+}
+int __attribute__((overloadable)) fpcrtl_abs(int x)
+{
+    return abs(x);
+}
+
+int64_t __attribute__((overloadable)) fpcrtl_abs(int64_t x)
+{
+    return x < 0 ? -x : x;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/pmath.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,24 @@
+#ifndef PMATH_H_
+#define PMATH_H_
+
+#include <stdint.h>
+#include <math.h>
+
+#define     fpcrtl_min(a, b)                ((a) < (b) ? (a) : (b))
+#define     fpcrtl_max(a, b)                ((a) > (b) ? (a) : (b))
+
+float       fpcrtl_power(float base, float exponent);
+
+/* Currently the games only uses sign of an integer */
+int         fpcrtl_signi(int x);
+
+float       fpcrtl_csc(float x);
+
+#define     fpcrtl_arctan2(y, x)            atan2(y, x)
+
+float       __attribute__((overloadable))   fpcrtl_abs(float x);
+double      __attribute__((overloadable))   fpcrtl_abs(double x);
+int         __attribute__((overloadable))   fpcrtl_abs(int x);
+int64_t     __attribute__((overloadable))   fpcrtl_abs(int64_t x);
+
+#endif /* PMATH_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/system.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,282 @@
+#include "system.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+
+#ifndef M_PI
+// some math.h do not have M_PI macros
+# define M_PI    3.14159265358979323846  /* pi */
+# define M_PI_2  1.57079632679489661923  /* pi/2 */
+# define M_PI_4  0.78539816339744830962  /* pi/4 */
+# define M_PIl   3.1415926535897932384626433832795029L  /* pi */
+# define M_PI_2l 1.5707963267948966192313216916397514L  /* pi/2 */
+# define M_PI_4l 0.7853981633974483096156608458198757L  /* pi/4 */
+#endif
+
+double pi = M_PI;
+
+int paramCount;
+string255 params[MAX_PARAMS];
+
+string255 fpcrtl_copy(string255 s, Integer index, Integer count) {
+    string255 result = STRINIT("");
+
+    if (count < 1) {
+        return result;
+    }
+
+    if (index < 1) {
+        index = 1;
+    }
+
+    if (index > s.len) {
+        return result;
+    }
+
+    if (index + count > s.len + 1) {
+        count = s.len + 1 - index;
+    }
+
+    memcpy(result.str, s.str + index - 1, count);
+
+    result.str[count] = 0;
+    result.len = count;
+
+    return result;
+}
+
+void fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count) {
+    // number of chars to be move
+    int num_move;
+    int new_length;
+
+    string255 temp = *s;
+
+    if (index < 1) {
+        // in fpc, if index < 1, the string won't be modified
+        return;
+    }
+
+    if(index > s->len){
+        return;
+    }
+
+    if (count > s->len - index + 1) {
+        s->str[index - 1] = 0;
+        s->len = index - 1;
+        return;
+    }
+
+    num_move = s->len - index + 1 - count;
+    new_length = s->len - count;
+
+    memmove(s->str + index - 1, temp.str + index - 1 + count, num_move);
+    s->str[new_length] = 0;
+
+    s->len = new_length;
+
+}
+
+string255 fpcrtl_floatToStr(double n) {
+    string255 t;
+    sprintf(t.str, "%f", n);
+    t.len = strlen(t.str);
+
+    return t;
+}
+
+void fpcrtl_move__vars(void *src, void *dst, SizeInt count) {
+    memmove(dst, src, count);
+}
+
+Integer __attribute__((overloadable)) fpcrtl_pos(Char c, string255 str) {
+    string255 t;
+    t.len = 1;
+    t.str[0] = c;
+    t.str[1] = 0;
+    return fpcrtl_pos(t, str);
+}
+
+Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str) {
+
+    char* p;
+
+    FIX_STRING(substr);
+    FIX_STRING(str);
+
+    if (str.len == 0) {
+        return 0;
+    }
+
+    if (substr.len == 0) {
+        return 0;
+    }
+
+    str.str[str.len] = 0;
+    substr.str[substr.len] = 0;
+
+    p = strstr(str.str, substr.str);
+
+    if (p == NULL) {
+        return 0;
+    }
+
+    return strlen(str.str) - strlen(p) + 1;
+}
+
+Integer fpcrtl_length(string255 s) {
+    return s.len;
+}
+
+string255 fpcrtl_lowerCase(string255 s) {
+    int i;
+
+    for (i = 0; i < s.len; i++) {
+        if (s.str[i] >= 'A' && s.str[i] <= 'Z') {
+            s.str[i] += 'a' - 'A';
+        }
+    }
+
+    return s;
+}
+
+void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value) {
+    memset(x, value, count);
+}
+
+void fpcrtl_new__vars(void **p, int size) {
+    *p = malloc(size);
+}
+
+Integer fpcrtl_trunc(extended n) {
+    return (int) n;
+}
+
+LongInt str_to_int(char *src)
+{
+    int i;
+    int len = strlen(src);
+    char *end;
+    for(i = 0; i < len; i++)
+    {
+        if(src[i] == '$'){
+            // hex
+            return strtol(src + i + 1, &end, 16);
+        }
+    }
+
+    // decimal
+    return atoi(src);
+}
+
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongInt *a)
+{
+    FIX_STRING(s);
+    *a = str_to_int(s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, Byte *a)
+{
+    FIX_STRING(s);
+    *a = str_to_int(s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongWord *a)
+{
+    FIX_STRING(s);
+    *a = str_to_int(s.str);
+}
+
+LongInt fpcrtl_random(LongInt l) {
+    return (LongInt) (rand() / (double) RAND_MAX * l);
+}
+
+void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) {
+    sprintf(s->str, "%f", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) {
+    sprintf(s->str, "%f", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) {
+    sprintf(s->str, "%u", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) {
+    sprintf(s->str, "%d", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) {
+    sprintf(s->str, "%u", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) {
+    sprintf(s->str, "%d", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) {
+    sprintf(s->str, "%u", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) {
+    sprintf(s->str, "%d", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) {
+    sprintf(s->str, "%llu", x);
+    s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) {
+    sprintf(s->str, "%lld", x);
+    s->len = strlen(s->str);
+}
+
+/*
+ * XXX No protection currently!
+ */
+void fpcrtl_interlockedIncrement__vars(int *i) {
+    (*i)++;
+}
+
+void fpcrtl_interlockedDecrement__vars(int *i) {
+    (*i)--;
+}
+
+/*
+ * This function should be called when entering main
+ */
+void fpcrtl_init(int argc, char** argv) {
+    int i;
+    paramCount = argc;
+
+    printf("ARGC = %d\n", paramCount);
+
+    for (i = 0; i < argc; i++) {
+        if (strlen(argv[i]) > 255) {
+            assert(0);
+        }
+        strcpy(params[i].str, argv[i]);
+        params[i].len = strlen(params[i].str);
+    }
+
+}
+
+int fpcrtl_paramCount() {
+    return paramCount - 1; // ignore the first one
+}
+
+string255 fpcrtl_paramStr(int i) {
+    return params[i];
+}
+
+int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen) {
+    //return swprintf(dest, maxLen, L"%hs", "src"); //doesn't work in emscripten
+    return 0;
+}
+
+uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t i) {
+    return (i & 0xFFFFFFFF);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/system.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,169 @@
+#ifndef SYSTEM_H_
+#define SYSTEM_H_
+
+#include <time.h>
+#include "Types.h"
+#include "misc.h"
+
+extern double pi;
+
+typedef TDate* PDate;
+
+// dimension info for dynamic arrays
+typedef struct {
+    int dim;
+    int a[4]; // at most 4
+} fpcrtl_dimension_t;
+
+/*
+ * Copy returns a string which is a copy if the Count characters in S, starting at position Index.
+ * If Count is larger than the length of the string S, the result is truncated.
+ * If Index is larger than the length of the string S, then an empty string is returned.
+ * Index is 1-based.
+ */
+string255   fpcrtl_copy(string255 s, Integer Index, Integer Count);
+
+/*
+ * Delete removes Count characters from string S, starting at position Index.
+ * All characters after the deleted characters are shifted Count positions to the left,
+ * and the length of the string is adjusted.
+ */
+#define     fpcrtl_delete(s, index, count)                  fpcrtl_delete__vars(&(s), index, count)
+void        fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count);
+
+string255   fpcrtl_floatToStr(double n);
+
+/*
+ * Move data from one location in memory to another
+ */
+void        fpcrtl_move__vars(void *src, void *dst, SizeInt count);
+#define     fpcrtl_move(src, dst, count)                    fpcrtl_move__vars(&(src), &(dst), count);
+#define     fpcrtl_Move                                     fpcrtl_move
+
+Integer     __attribute__((overloadable))                   fpcrtl_pos(Char c, string255 str);
+Integer     __attribute__((overloadable))                   fpcrtl_pos(string255 substr, string255 str);
+
+Integer     fpcrtl_length(string255 s);
+#define     fpcrtl_Length                                   fpcrtl_length
+
+#define     fpcrtl_sqr(x)                                   ((x) * (x))
+
+#define     fpcrtl_odd(x)                                   ((x) % 2 != 0 ? true : false)
+
+#define     fpcrtl_StrLen                                   strlen
+
+#define     SizeOf                                          sizeof
+
+string255   fpcrtl_lowerCase(string255 s);
+#define     fpcrtl_LowerCase                                fpcrtl_lowerCase
+
+void        fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value);
+#define     fpcrtl_fillChar(x, count, value)                fpcrtl_fillChar__vars(&(x), count, value)
+#define     fpcrtl_FillChar                                 fpcrtl_fillChar
+
+void        fpcrtl_new__vars(void **p, int size);
+#define     fpcrtl_new(a)                                   fpcrtl_new__vars((void **)&(a), sizeof(*(a)))
+
+#define     fpcrtl_dispose                                  free
+
+#define     fpcrtl_freeMem(p, size)                         free(p)
+#define     fpcrtl_FreeMem(p, size)                         free(p)
+
+#define     fpcrtl_getMem(size)                             malloc(size)
+#define     fpcrtl_GetMem                                   fpcrtl_getMem
+
+#define     fpcrtl_assigned(p)                              ((p) != NULL)
+#define     fpcrtl_Assigned                                 fpcrtl_assigned
+
+Integer     fpcrtl_trunc(extended n);
+
+#define     fpcrtl_val(s, a)                                fpcrtl_val__vars(s, &(a))
+void        __attribute__((overloadable))                   fpcrtl_val__vars(string255 s, LongInt *a);
+void        __attribute__((overloadable))                   fpcrtl_val__vars(string255 s, Byte *a);
+void        __attribute__((overloadable))                   fpcrtl_val__vars(string255 s, LongWord *a);
+
+#define     fpcrtl_randomize()                              srand(time(NULL))
+
+/*
+ * Random returns a random number larger or equal to 0 and strictly less than L
+ */
+LongInt     fpcrtl_random(LongInt l);
+
+string255   fpcrtl_paramStr(LongInt);
+#define     fpcrtl_ParamStr                                 fpcrtl_paramStr
+
+/*
+ * Str returns a string which represents the value of X. X can be any numerical type.
+ */
+#define     fpcrtl_str(x, s)                                fpcrtl_str__vars(x, &(s))
+void        __attribute__((overloadable))                   fpcrtl_str__vars(float x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(double x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(uint8_t x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(int8_t x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(uint16_t x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(int16_t x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(uint32_t x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(int32_t x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(uint64_t x, string255 *s);
+void        __attribute__((overloadable))                   fpcrtl_str__vars(int64_t x, string255 *s);
+
+void        fpcrtl_interlockedIncrement__vars(int *i);
+void        fpcrtl_interlockedDecrement__vars(int *i);
+
+#define     fpcrtl_interlockedIncrement(i)                  fpcrtl_interlockedIncrement__vars(&(i))
+#define     fpcrtl_interlockedDecrement(i)                  fpcrtl_interlockedDecrement__vars(&(i))
+
+#define     fpcrtl_InterlockedIncrement                     fpcrtl_interlockedIncrement
+#define     fpcrtl_InterlockedDecrement                     fpcrtl_interlockedDecrement
+
+void        fpcrtl_init(int argc, char** argv);
+
+int         fpcrtl_paramCount();
+#define     fpcrtl_ParamCount                               fpcrtl_paramCount
+
+string255   fpcrtl_paramStr(int i);
+#define     fpcrtl_ParamStr                                 fpcrtl_paramStr
+
+int         fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen);
+
+#define     fpcrtl_halt(t)                                  assert(0)
+
+#define     fpcrtl_Load_GL_VERSION_2_0()                    1
+
+uint32_t    __attribute__((overloadable))                   fpcrtl_lo(uint64_t);
+#define     fpcrtl_Lo                                       fpcrtl_lo
+
+#define     __SET_LENGTH2(arr, d, b) do{\
+                d.dim = 1;\
+                arr = realloc(arr, b * sizeof(typeof(*arr)));\
+                d.a[0] = b;\
+            }while(0)
+
+#define     SET_LENGTH2(arr, b)                             __SET_LENGTH2(arr, arr##_dimension_info, (b))
+
+#define     __SET_LENGTH3(arr, d, b, c) do{\
+                d.dim = 2;\
+                for (int i = 0; i < d.a[0]; i++) {\
+                    arr[i] = realloc(arr[i], c * sizeof(typeof(**arr)));\
+                }\
+                if (d.a[0] > b) {\
+                    for (int i = b; i < d.a[0]; i++) {\
+                        free(arr[i]);\
+                    }\
+                    arr = realloc(arr, b * sizeof(typeof(*arr)));\
+                } else if (d.a[0] < b) {\
+                    arr = realloc(arr, b * sizeof(typeof(*arr)));\
+                    for (int i = d.a[0]; i < b; i++) {\
+                        arr[i] = malloc(c * sizeof(typeof(**arr)));\
+                        memset(arr[i], 0, c * sizeof(typeof(**arr)));\
+                    }\
+                }\
+                d.a[0] = b;\
+                d.a[1] = c;\
+            }while(0)
+
+#define     SET_LENGTH3(arr, b, c)                          __SET_LENGTH3(arr, arr##_dimension_info, (b), (c))
+
+#define     fpcrtl_SetLength(...)                           macro_dispatcher(SET_LENGTH, __VA_ARGS__)(__VA_ARGS__)
+
+#endif /* SYSTEM_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/sysutils.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,178 @@
+#include "SysUtils.h"
+
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "system.h"
+#include "misc.h"
+
+TDateTime fpcrtl_date()
+{
+    const int num_days_between_1900_1980 = 29220;
+
+    struct tm ref_date;
+    struct tm cur_date;
+    time_t local_time;
+    time_t ref_time, cur_time;
+
+    double timeDiff;
+    double day_time_frac; //fraction that represents the time in one day
+    int num_seconds;
+    int numDays;
+
+    // unix epoch doesn't work, choose Jan 1st 1980 instead
+    ref_date.tm_year = 80;
+    ref_date.tm_mon = 0;
+    ref_date.tm_mday = 1;
+    ref_date.tm_hour = 0;
+    ref_date.tm_min = 0;
+    ref_date.tm_sec = 0;
+    ref_date.tm_isdst = 0;
+    ref_date.tm_wday = 0; // ignored
+    ref_date.tm_yday = 0; // ignored
+
+    local_time = time(NULL);
+    cur_date = *localtime(&local_time);
+
+    cur_date.tm_hour = 0;
+    cur_date.tm_min = 0;
+    cur_date.tm_sec = 0;
+
+    ref_time = mktime(&ref_date);
+    cur_time = mktime(&cur_date);
+
+    timeDiff = difftime(cur_time, ref_time);
+    numDays = fpcrtl_round(timeDiff / 3600 / 24) + num_days_between_1900_1980 + 1;
+
+    fpcrtl_printf("[date] tim diff: %f\n", timeDiff);
+    fpcrtl_printf("[date] num days between 1980 and today:  %d\n", fpcrtl_round(timeDiff/3600/24));
+    fpcrtl_printf("[date] current date: %s\n", asctime(&cur_date));
+    fpcrtl_printf("[date] reference date: %s\n", asctime(&ref_date));
+    fpcrtl_printf("[date] num days: %d\n", numDays);
+
+    return numDays;
+}
+
+TDateTime fpcrtl_time()
+{
+    struct tm cur_date;
+    time_t local_time;
+    time_t cur_time;
+
+    double day_time_frac; //fraction that represents the time in one day
+    int num_seconds;
+
+    local_time = time(NULL);
+    cur_date = *localtime(&local_time);
+
+    num_seconds = cur_date.tm_hour * 3600 + cur_date.tm_min * 60 + cur_date.tm_sec;
+    day_time_frac = num_seconds / 3600.0 / 24.0;
+
+    fpcrtl_printf("%f\n", day_time_frac);
+
+    return day_time_frac;
+}
+
+TDateTime fpcrtl_now()
+{
+    return fpcrtl_date() + fpcrtl_time();
+}
+
+/*
+ * XXX: dummy
+ */
+string255 fpcrtl_formatDateTime(string255 FormatStr, TDateTime DateTime)
+{
+    string255 result = STRINIT("2012 01-01");
+    return result;
+}
+
+string255 fpcrtl_trim(string255 s)
+{
+    int left, right;
+
+    if(s.len == 0){
+        return s;
+    }
+
+    for(left = 0; left < s.len; left++)
+    {
+        if(s.str[left] != ' '){
+            break;
+        }
+    }
+
+    for(right = s.len - 1; right >= 0; right--)
+    {
+        if(s.str[right] != ' '){
+            break;
+        }
+    }
+
+    if(left > right){
+        s.len = 0;
+        s.str[0] = 0;
+        return s;
+    }
+
+    s.len = right - left + 1;
+    memmove(s.str, s.str + left, s.len);
+
+    s.str[s.len] = 0;
+
+    return s;
+}
+
+Integer fpcrtl_strToInt(string255 s)
+{
+    s.str[s.len] = 0;
+    return atoi(s.str);
+}
+
+//function ExtractFileName(const FileName: string): string;
+//var
+//  i : longint;
+//  EndSep : Set of Char;
+//begin
+//  I := Length(FileName);
+//  EndSep:=AllowDirectorySeparators+AllowDriveSeparators;
+//  while (I > 0) and not (FileName[I] in EndSep) do
+//    Dec(I);
+//  Result := Copy(FileName, I + 1, MaxInt);
+//end;
+
+string255 fpcrtl_extractFileName(string255 f)
+{
+    const char sep[] = {'\\', '/', ':'};
+    LongInt i,j;
+
+    i = f.len - 1;
+    while(i >= 0){
+        for(j = 0; j < sizeof(sep); j++){
+            if(f.str[i] == sep[j]){
+                goto FPCRTL_EXTRACTFILENAME_END;
+            }
+        }
+        i--;
+    }
+FPCRTL_EXTRACTFILENAME_END:
+    return fpcrtl_copy(f, i + 2, 256);
+}
+
+string255 fpcrtl_strPas(PChar p)
+{
+    string255 s;
+    int l = strlen(p);
+
+    if(l > 255){
+        printf("strPas: source string length > 255\n");
+        assert(0);
+    }
+
+    s.len = l;
+    strcpy(s.str, p);
+
+    return s;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_check.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,23 @@
+#include <check.h>
+#include <stdlib.h>
+#include "check_check.h"
+
+int main(void)
+{
+    int number_failed;
+
+    Suite *s1 = system_suite();
+    Suite *s2 = misc_suite();
+    Suite *s3 = sysutils_suite();
+    Suite *s4 = fileio_suite();
+
+    SRunner *sr = srunner_create(s1);
+    srunner_add_suite(sr, s2);
+    srunner_add_suite(sr, s3);
+    srunner_add_suite(sr, s4);
+
+    srunner_run_all(sr, CK_NORMAL);
+    number_failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
+    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_check.h	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,9 @@
+#ifndef _CHECK_CHECK_H_
+#define _CHECK_CHECK_H_
+
+Suite *system_suite();
+Suite *misc_suite();
+Suite *sysutils_suite();
+Suite *fileio_suite();
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_fileio.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,103 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "check_check.h"
+#include "../src/fpcrtl.h"
+
+typedef struct __TResourceList
+{
+    Integer count;
+    string255 files[500 + 1];
+} TResourceList;
+
+string255 t = STRINIT("test");
+string255 Pathz[1] =
+{ STRINIT("../../") };
+int ptCurrTheme = 0;
+string255 cThemeCFGFilename = STRINIT("theme.cfg");
+const string255 __str79 = STRINIT("object");
+string255 c1 = STRINIT("=");
+string255 c2 = STRINIT("\x2c");
+string255 c3 = STRINIT("\x2f");
+
+static string255 make_string(const char* str)
+{
+    string255 s;
+    s.len = strlen(str);
+    memcpy(s.str, str, s.len + 1);
+    return s;
+}
+
+TResourceList readThemeCfg_0()
+{
+    TResourceList readthemecfg_result;
+    string255 s;
+    string255 key;
+    TextFile f;
+    Integer i;
+    TResourceList res;
+
+    s = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), cThemeCFGFilename);
+    //umisc_log(s);
+
+    fpcrtl_assign(f, s);
+
+    FileMode = 0;
+    fpcrtl_reset(f);
+
+    res.count = 0;
+    while (!(fpcrtl_eof(f)))
+    {
+        fpcrtl_readLnS(f, s);
+        if ((fpcrtl_Length(s)) == (0))
+        {
+            continue;
+        }
+        if ((s.s[1]) == ('\x3b'))
+        {
+            continue;
+        }
+        i = fpcrtl_pos('\x3d', s);
+        key = fpcrtl_trim(fpcrtl_copy(s, 1, i - 1));
+        fpcrtl_delete(s, 1, i);
+        if (_strcompare(key, __str79))
+        {
+            i = fpcrtl_pos('\x2c', s);
+            res.files[res.count] = _strconcat(
+                    _strappend(Pathz[ptCurrTheme], '\x2f'),
+                    fpcrtl_trim(fpcrtl_copy(s, 1, i - 1)));
+            ++res.count;
+            //umisc_log(fpcrtl_trim(fpcrtl_copy(s, 1, i - 1)));
+        }
+    }
+    fpcrtl_close(f);
+    readthemecfg_result = res;
+    return readthemecfg_result;
+}
+
+START_TEST(test_readthemecfg)
+    {
+        int i;
+        TResourceList result;
+
+        printf("-----Entering test readthemecfg-----\n");
+        result = readThemeCfg_0();
+        for (i = 0; i < result.count; i++)
+        {
+            printf("%s\n", result.files[i].str);
+        }
+        printf("-----Leaving test readthemecfg-----\n");
+    }END_TEST
+
+Suite* fileio_suite(void)
+{
+    Suite *s = suite_create("fileio");
+
+    TCase *tc_core = tcase_create("Core");
+
+    tcase_add_test(tc_core, test_readthemecfg);
+
+    suite_add_tcase(s, tc_core);
+
+    return s;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_misc.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,88 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "check_check.h"
+#include "../src/misc.h"
+
+static string255 make_string(const char* str)
+{
+    string255 s;
+    s.len = strlen(str);
+    memcpy(s.str, str, s.len + 1);
+    return s;
+}
+
+START_TEST(test_strconcat)
+{
+    string255 t;
+    t = fpcrtl_strconcat(make_string(""), make_string(""));
+    fail_if(strcmp(t.str, ""), "strconcat(\"\", \"\")");
+
+    t = fpcrtl_strconcat(make_string(""), make_string("a"));
+    fail_if(strcmp(t.str, "a"), "strconcat(\"\", \"a\")");
+
+    t = fpcrtl_strconcat(make_string("a"), make_string(""));
+    fail_if(strcmp(t.str, "a"), "strconcat(\"a\", \"\")");
+
+    t = fpcrtl_strconcat(make_string("ab"), make_string(""));
+    fail_if(strcmp(t.str, "ab"), "strconcat(\"ab\", \"\")");
+
+    t = fpcrtl_strconcat(make_string("ab"), make_string("cd"));
+    fail_if(strcmp(t.str, "abcd"), "strconcat(\"ab\", \"cd\")");
+}
+END_TEST
+
+START_TEST (test_strappend)
+{
+    string255 t;
+
+    t = fpcrtl_strappend(make_string(""), 'c');
+    fail_if(strcmp(t.str, "c"), "strappend(\"\", 'c')");
+
+    t = fpcrtl_strappend(make_string("ab"), 'c');
+    fail_if(strcmp(t.str, "abc"), "strappend(\"ab\", 'c')");
+}
+END_TEST
+
+START_TEST (test_strprepend)
+{
+    string255 t;
+
+    t = fpcrtl_strprepend('c', make_string(""));
+    fail_if(strcmp(t.str, "c"), "strprepend('c', \"\")");
+
+    t = fpcrtl_strprepend('c', make_string("ab"));
+    fail_if(strcmp(t.str, "cab"), "strprepend('c', \"ab\")");
+}
+END_TEST
+
+START_TEST (test_strcompare)
+{
+    fail_unless(fpcrtl_strcompare(make_string(""), make_string("")), "strcompare(\"\", \"\")");
+    fail_unless(fpcrtl_strcompare(make_string("a"), make_string("a")), "strcompare(\"a\", \"a\"");
+    fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("b")), "strcompare(\"a\", \"b\")");
+    fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("ab")), "strcompare(\"a\", \"ab\")");
+
+    fail_unless(fpcrtl_strcomparec(make_string(" "), ' '), "strcomparec(\" \", ' ')");
+    fail_unless(fpcrtl_strcomparec(make_string("a"), 'a'), "strcomparec(\"a\", 'a')");
+    fail_unless(!fpcrtl_strcomparec(make_string("  "), ' '), "strcomparec(\"  \", ' '");
+    fail_unless(!fpcrtl_strcomparec(make_string(""), ' '), "strcomparec(\"\", ' ')");
+
+}
+END_TEST
+
+Suite* misc_suite(void)
+{
+    Suite *s = suite_create("misc");
+
+    TCase *tc_core = tcase_create("Core");
+
+    tcase_add_test(tc_core, test_strconcat);
+    tcase_add_test(tc_core, test_strappend);
+    tcase_add_test(tc_core, test_strprepend);
+    tcase_add_test(tc_core, test_strcompare);
+
+    suite_add_tcase(s, tc_core);
+
+    return s;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_system.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,251 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "check_check.h"
+#include "../src/system.h"
+
+void check_string(string255 str)
+{
+    fail_unless(strlen(str.str) == str.len, "String internal inconsistency error");
+}
+
+static string255 make_string(const char* str)
+{
+    string255 s;
+    s.len = strlen(str);
+    memcpy(s.str, str, s.len + 1);
+    return s;
+}
+
+START_TEST (test_copy)
+    {
+        string255 s = STRINIT("1234567");
+        string255 t;
+
+        t = fpcrtl_copy(s, 1, 1);
+        fail_if(strcmp(t.str, "1"), "Test copy fail 1");
+
+        t = fpcrtl_copy(s, 7, 1);
+        fail_if(strcmp(t.str, "7"), "Test copy fail 2");
+
+        t = fpcrtl_copy(s, 8, 1);
+        fail_if(t.len != 0, "Test copy fail 3");
+
+        t = fpcrtl_copy(s, 8, 100);
+        fail_if(t.len != 0, "Test copy fail 4");
+        check_string(t);
+
+        t = fpcrtl_copy(s, 0, 100);
+        fail_if(strcmp(t.str, "1234567"), "Test copy fail 5");
+
+        t = fpcrtl_copy(s, 0, 5);
+        fail_if(strcmp(t.str, "12345"), "Test copy fail 6");
+
+        t = fpcrtl_copy(s, 4, 100);
+        fail_if(strcmp(t.str, "4567"), "Test copy fail 7");
+
+        t = fpcrtl_copy(s, 4, 2);
+        fail_if(strcmp(t.str, "45"), "Test copy fail 8");
+    }END_TEST
+
+START_TEST (test_delete)
+    {
+        string255 s = STRINIT("1234567");
+        string255 s2 = STRINIT("1234567");
+        string255 s3 = STRINIT("1234567");
+
+        fpcrtl_delete(s, 0, 10);
+        fail_if(strcmp(s.str, "1234567"), "delete(\"1234567\", 0, 10)");
+        check_string(s);
+
+        fpcrtl_delete(s, 1, 1);
+        fail_if(strcmp(s.str, "234567"), "delete(\"1234567\", 1, 1)");
+        check_string(s);
+
+        fpcrtl_delete(s, 1, 100);
+        fail_if(strcmp(s.str, ""), "delete(\"234567\", 1, 100)");
+        check_string(s);
+
+        fpcrtl_delete(s2, 3, 2);
+        fail_if(strcmp(s2.str, "12567"), "delete(\"1234567\", 3, 2)");
+        check_string(s2);
+
+        fpcrtl_delete(s3, 3, 100);
+        fail_if(strcmp(s3.str, "12"), "delete(\"1234567\", 3, 100)");
+        check_string(s3);
+
+    }
+END_TEST
+
+START_TEST (test_FloatToStr)
+    {
+        double s = 1.2345;
+        string255 t = fpcrtl_floatToStr(s);
+        printf("-----Entering test floatToStr-----\n");
+        printf("FloatToStr(%f) = %s\n", s, t.str);
+        printf("-----Leaving test floatToStr-----\n");
+    }
+END_TEST
+
+START_TEST (test_random)
+    {
+        fpcrtl_randomize();
+        printf("-----Entering test random-----\n");
+        printf("random(5000) = %d\n", fpcrtl_random(5000));
+        printf("random(1) = %d\n", fpcrtl_random(1));
+        printf("random(2) = %d\n", fpcrtl_random(2));
+        printf("-----Leaving test random-----\n");
+
+    }
+END_TEST
+
+START_TEST (test_posS)
+    {
+        string255 substr1 = STRINIT("123");
+        string255 str1 = STRINIT("12345");
+
+        string255 substr2 = STRINIT("45");
+        string255 str2 = STRINIT("12345");
+
+        string255 substr3 = STRINIT("");
+        string255 str3 = STRINIT("12345");
+
+        string255 substr4 = STRINIT("123");
+        string255 str4 = STRINIT("");
+
+        string255 substr5 = STRINIT("123");
+        string255 str5 = STRINIT("456");
+
+        fail_unless(fpcrtl_posS(substr1, str1) == 1, "pos(123, 12345)");
+        fail_unless(fpcrtl_posS(substr2, str2) == 4, "pos(45, 12345)");
+        fail_unless(fpcrtl_posS(substr3, str3) == 0, "pos(, 12345)");
+        fail_unless(fpcrtl_posS(substr4, str4) == 0, "pos(123, )");
+        fail_unless(fpcrtl_posS(substr5, str5) == 0, "pos(123, 456)");
+    }
+END_TEST
+
+START_TEST (test_trunc)
+    {
+          fail_unless(fpcrtl_trunc(123.456) == 123, "trunc(123.456)");
+          fail_unless(fpcrtl_trunc(-123.456) == -123, "trunc(-123.456)");
+          fail_unless(fpcrtl_trunc(12.3456) == 12, "trunc(12.3456)");
+          fail_unless(fpcrtl_trunc(-12.3456) == -12, "trunc(-12.3456)");
+    }
+END_TEST
+
+START_TEST (test_odd)
+{
+    fail_unless(fpcrtl_odd(123) != 0, "odd(123)");
+    fail_unless(fpcrtl_odd(124) == 0, "odd(124)");
+    fail_unless(fpcrtl_odd(0) == 0, "odd(0)");
+    fail_unless(fpcrtl_odd(-1) != 0, "odd(-1)");
+    fail_unless(fpcrtl_odd(-2) == 0, "odd(-2)");
+}
+END_TEST
+
+START_TEST (test_sqr)
+{
+    fail_unless(fpcrtl_sqr(0) == 0, "sqr(0)");
+    fail_unless(fpcrtl_sqr(5) == 25, "sqr(5)");
+    fail_unless(fpcrtl_sqr(-5) == 25, "sqr(-5)");
+}
+END_TEST
+
+START_TEST (test_lowercase)
+{
+    string255 s1 = STRINIT("");
+    string255 s2 = STRINIT("a");
+    string255 s3 = STRINIT("abc");
+    string255 t;
+
+    t = fpcrtl_lowerCase(make_string(""));
+    fail_if(strcmp(t.str, s1.str), "lowerCase(\"\")");
+
+    t = fpcrtl_lowerCase(make_string("a"));
+    fail_if(strcmp(t.str, s2.str), "lowerCase(\"a\")");
+
+    t = fpcrtl_lowerCase(make_string("A"));
+    fail_if(strcmp(t.str, s2.str), "lowerCase(\"A\")");
+
+    t = fpcrtl_lowerCase(make_string("AbC"));
+    fail_if(strcmp(t.str, s3.str), "lowerCase(\"AbC\")");
+
+    t = fpcrtl_lowerCase(make_string("abc"));
+    fail_if(strcmp(t.str, s3.str), "lowerCase(\"abc\")");
+}
+END_TEST
+
+START_TEST (test_str)
+{
+    int8_t a1 = -8;
+    uint8_t a2 = 8;
+    int16_t a3 = -13;
+    uint16_t a4 = 13;
+    int32_t a5 = -19;
+    uint32_t a6 = 22;
+    int64_t a7 = -199999999999999;
+    uint64_t a8 = 200000000000000;
+
+    float a9 = 12345.6789;
+    double a10 = -9876.54321;
+
+    string255 s;
+
+    printf("-----Entering test str-----\n");
+
+    fpcrtl_str(a1, s);
+    printf("%d == %s\n", a1, s.str);
+
+    fpcrtl_str(a2, s);
+    printf("%u == %s\n", a2, s.str);
+
+    fpcrtl_str(a3, s);
+    printf("%d == %s\n", a3, s.str);
+
+    fpcrtl_str(a4, s);
+    printf("%u == %s\n", a4, s.str);
+
+    fpcrtl_str(a5, s);
+    printf("%d == %s\n", a5, s.str);
+
+    fpcrtl_str(a6, s);
+    printf("%u == %s\n", a6, s.str);
+
+    fpcrtl_str(a7, s);
+    printf("%lld == %s\n", a7, s.str);
+
+    fpcrtl_str(a8, s);
+    printf("%llu == %s\n", a8, s.str);
+
+    fpcrtl_str(a9, s);
+    printf("%f == %s\n", a9, s.str);
+
+    fpcrtl_str(a10, s);
+    printf("%f == %s\n", a10, s.str);
+
+    printf("-----Leaving test str------\n");
+}
+END_TEST
+
+Suite* system_suite(void)
+{
+    Suite *s = suite_create("system");
+
+    TCase *tc_core = tcase_create("Core");
+
+    tcase_add_test(tc_core, test_copy);
+    tcase_add_test(tc_core, test_FloatToStr);
+    tcase_add_test(tc_core, test_random);
+    tcase_add_test(tc_core, test_posS);
+    tcase_add_test(tc_core, test_trunc);
+    tcase_add_test(tc_core, test_delete);
+    tcase_add_test(tc_core, test_odd);
+    tcase_add_test(tc_core, test_sqr);
+    tcase_add_test(tc_core, test_lowercase);
+    tcase_add_test(tc_core, test_str);
+
+    suite_add_tcase(s, tc_core);
+
+    return s;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_sysutils.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,80 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "check_check.h"
+#include "../src/sysutils.h"
+
+static string255 make_string(const char* str)
+{
+    string255 s;
+    s.len = strlen(str);
+    memcpy(s.str, str, s.len + 1);
+    return s;
+}
+
+static int is_string_equal(string255 s1, string255 s2)
+{
+    return (s1.len == s2.len) && (strcmp(s1.str, s2.str) == 0);
+}
+
+START_TEST (test_trim)
+{
+    string255 t;
+
+    t = fpcrtl_trim(make_string(""));
+    fail_if(strcmp(t.str, ""), "trim(\"\")");
+
+    t = fpcrtl_trim(make_string("ab"));
+    fail_if(strcmp(t.str, "ab"), "trim(\"ab\")");
+
+    t = fpcrtl_trim(make_string(" "));
+    fail_if(strcmp(t.str, ""), "trim(\" \")");
+
+    t = fpcrtl_trim(make_string("   "));
+    fail_if(strcmp(t.str, ""), "trim(\"   \")");
+
+    t = fpcrtl_trim(make_string(" ab"));
+    fail_if(strcmp(t.str, "ab"), "trim(\" ab\")");
+
+    t = fpcrtl_trim(make_string("ab  "));
+    fail_if(strcmp(t.str, "ab"), "trim(\"ab  \")");
+
+    t = fpcrtl_trim(make_string("  ab  "));
+    fail_if(strcmp(t.str, "ab"), "trim(\"  ab  \")");
+
+}
+END_TEST
+
+START_TEST (test_strToInt)
+{
+    fail_unless(fpcrtl_strToInt(make_string("123")) == 123, "strToInt(\"123\")");
+    fail_unless(fpcrtl_strToInt(make_string("0")) == 0, "strToInt(\"0\")");
+    fail_unless(fpcrtl_strToInt(make_string("-123")) == -123, "strToInt(\"-123\")");
+}
+END_TEST
+
+START_TEST (test_extractFileName)
+{
+    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("abc")), make_string("abc")), "extractFileName(\"abc\")");
+    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("a:abc")), make_string("abc")), "extractFileName(\"a:abc\")");
+    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/abc")), make_string("abc")), "extractFileName(\"/abc\")");
+    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("\\abc")), make_string("abc")), "extractFileName(\"\\abc\")");
+    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/usr/bin/abc")), make_string("abc")), "extractFileName(\"/usr/bin/abc\")");
+    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("c:\\def\\abc")), make_string("abc")), "extractFileName(\"c:\\def\\abc\")");
+}
+END_TEST
+
+Suite* sysutils_suite(void)
+{
+    Suite *s = suite_create("sysutils");
+
+    TCase *tc_core = tcase_create("Core");
+
+    tcase_add_test(tc_core, test_trim);
+    tcase_add_test(tc_core, test_strToInt);
+    tcase_add_test(tc_core, test_extractFileName);
+
+    suite_add_tcase(s, tc_core);
+
+    return s;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/fileio_test.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,59 @@
+
+#include "pas2c.h"
+
+#include "fpcrtl.h"
+
+char Pathz[1][128] = {"./"};
+int ptCurrTheme = 0;
+cThemeCFGFilename = "theme.cfg";
+const string255 __str79 = STRINIT("object");
+
+typedef struct __TResourceList {
+            Integer count;
+            string255 files[500 + 1];
+} TResourceList;
+
+TResourceList readThemeCfg_0()
+{
+    TResourceList readthemecfg_result;
+    string255 s;
+    string255 key;
+    TextFile f;
+    Integer i;
+    TResourceList result;
+    s = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), cThemeCFGFilename);
+
+    assign(f, s);
+    FileMode = 0;
+    reset(f);
+    result.count = 0;
+    while(!eof(f))
+    {
+        readLnS(f, s);
+        if((Length(s)) == (0))
+        {
+            continue;
+        }
+        if((s.s[1]) == ('\x3b'))
+        {
+            continue;
+        }
+        i = pos('\x3d', s);
+        key = trim(copy(s, 1, i - 1));
+        delete(s, 1, i);
+        if(_strcompare(key, __str79))
+        {
+            i = pos('\x2c', s);
+            result.files[result.count] = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), trim(copy(s, 1, i - 1)));
+            ++result.count;
+        }
+    }
+    close(f);
+    readthemecfg_result = result;
+    return readthemecfg_result;
+};
+
+int main(int argc, char** argv)
+{
+    readThemeCfg_0();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/main.c	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,80 @@
+#if 0
+#include <stdio.h>
+#include "fpcrtl.h"
+#include "fileio.h"
+
+string255 t = STRINIT("test");
+string255 Pathz[1] = {STRINIT(".")};
+//int ptCurrTheme = 0;
+string255 cThemeCFGFilename = STRINIT("theme.cfg");
+const string255 __str79 = STRINIT("object");
+string255 c1 = STRINIT("=");
+string255 c2 = STRINIT("\x2c");
+string255 c3 = STRINIT("\x2f");
+
+typedef struct __TResourceList {
+            Integer count;
+            string255 files[500 + 1];
+} TResourceList;
+
+TResourceList readThemeCfg_0()
+{
+    TResourceList readthemecfg_result;
+    string255 s;
+    string255 key;
+    TextFile f;
+    Integer i;
+    TResourceList result;
+
+    int t = 0;
+
+    s = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), cThemeCFGFilename);
+
+    assign(&f, s);
+
+    reset(&f);
+
+    if (f.fp == NULL) {
+      readthemecfg_result.count = 0;
+      return readthemecfg_result;
+    }
+
+    result.count = 0;
+    while (!eof(&f)) {
+        readLnS(&f, &s);
+
+        if ((Length(s)) == (0)) {
+            continue;
+        }
+        if ((s.s[1]) == ('\x3b')) {
+            continue;
+        }
+
+        i = pos(c1, s);
+
+        key = fpcrtl_trim(fpcrtl_copy(s, 1, i - 1));
+
+        fpcrtl_delete(&s, 1, i);
+
+        if (_strcompare(key, __str79)) {
+            i = pos(c2, s);
+            result.files[result.count] = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), trim(copy(s, 1, i - 1)));
+            ++result.count;
+        }
+    }
+
+    close(&f);
+    readthemecfg_result = result;
+    return readthemecfg_result;
+}
+
+int main(int argc, char** argv)
+{
+    int i;
+
+    TResourceList result = readThemeCfg_0();
+    for(i = 0; i < result.count; i++) {
+        printf("%s\n", result.files[i].str);
+    }
+}
+#endif
--- a/share/hedgewars/Data/CMakeLists.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,3 +1,7 @@
 foreach(dir "Fonts" "Forts" "Graphics" "Locale" "Maps" "Music" "Sounds" "Themes" "Missions" "Names" "misc" "Scripts")
-  add_subdirectory(${dir})
+    add_subdirectory(${dir})
 endforeach(dir)
+
+if(${GL2})
+    add_subdirectory(Shaders)
+endif(${GL2})
Binary file share/hedgewars/Data/Graphics/Hedgehog/Idle.png has changed
--- a/share/hedgewars/Data/Locale/fr.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Locale/fr.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -136,7 +136,7 @@
 02:01=%1 fait splish splash splosh !
 02:01=%1 va dormir avec les poissons !
 02:01=%1 pense que la physique de l'eau est nulle dans ce jeu !
-02:01=%1 a l'air assoiffé ! 
+02:01=%1 a l'air assoiffé !
 02:01=La mer réclame %1 !
 02:01=Un hérisson à la mer !
 02:01=%1 aurait dû prendre son masque et son tuba !
@@ -256,7 +256,7 @@
 02:06=Prends-la ou explose-la, le choix est tien !
 02:06=Mmmmh, Munitions !
 02:06=Une boîte de pouvoir destructif !
-02:06=Courrier aérien ! 
+02:06=Courrier aérien !
 02:06=Quelque soit ce qu'il y a dans cette boîte, ce n'est pas une pizza !
 02:06=Prends-la !
 02:06=Lâcher d'armes en approche !
@@ -270,7 +270,7 @@
 ; New utility crate
 02:07=Boite à outils !
 02:07=Ça peut être pratique...
-02:07=Utilisez cette boîte ! 
+02:07=Utilisez cette boîte !
 02:07=Regardez en-dessous !
 02:07=Des outils pour toi !
 02:07=Ça devrait être bien !
--- a/share/hedgewars/Data/Locale/missions_el.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Locale/missions_el.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,7 +1,7 @@
 Basic_Training_-_Bazooka.name=Βασική Εκπαίδευση Μπαζούκα
 Basic_Training_-_Bazooka.desc="Το κλειδί είναι να χρησιμοποιήσεις τον άνεμο προς όφελός σου!"
 
-Basic_Training_-_Grenade.name=Βασική Εκπαίδευση Χειροβομβίδας	
+Basic_Training_-_Grenade.name=Βασική Εκπαίδευση Χειροβομβίδας
 Basic_Training_-_Grenade.desc="Θυμίσου, τραβάς την περόνη ΚΑΙ πετάς!"
 
 Basic_Training_-_Cluster_Bomb.name=Βασική Εκπαίδευση Βόμβας Θραυσμάτων
--- a/share/hedgewars/Data/Locale/tips_en.xml	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Locale/tips_en.xml	Tue Jan 21 22:53:15 2014 +0100
@@ -49,7 +49,7 @@
     <tip>Heads or tails? Type '/rnd' in lobby and you'll find out. Also '/rnd rock paper scissors' works!</tip>
     <tip>You're able to associate Hedgewars related files (savegames and demo recordings) with the game to launch them right from your favorite file or internet browser.</tip>
     <windows-only>
-	    <tip>The version of Hedgewars supports <a href="http://www.xfire.com">Xfire</a>. Make sure to add Hedgewars to its game list so your friends can see you playing.</tip>
+        <tip>The version of Hedgewars supports <a href="http://www.xfire.com">Xfire</a>. Make sure to add Hedgewars to its game list so your friends can see you playing.</tip>
         <tip>You can find your Hedgewars configuration files under "My Documents\Hedgewars". Create backups or take the files with you, but don't edit them by hand.</tip>
     </windows-only>
     <mac-only>
--- a/share/hedgewars/Data/Maps/Basketball/desc.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Maps/Basketball/desc.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,1 +1,1 @@
-en_US=Who said hedgehogs can't play basketball?
+en_US=Who said hedgehogs can't play basketball?
--- a/share/hedgewars/Data/Maps/CTF_Blizzard/desc.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Maps/CTF_Blizzard/desc.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,1 +1,1 @@
-en_US=Capture the Flag\, blizzard style!
+en_US=Capture the Flag\, blizzard style!
--- a/share/hedgewars/Data/Maps/Control/desc.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Maps/Control/desc.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,1 +1,1 @@
-en_US=Islands scattered everywhere\, full set of weapons.
+en_US=Islands scattered everywhere\, full set of weapons.
--- a/share/hedgewars/Data/Maps/Knockball/desc.txt	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Maps/Knockball/desc.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -1,1 +1,1 @@
-en_US=Knock your opponents off the platforms using only a bat!
+en_US=Knock your opponents off the platforms using only a bat!
--- a/share/hedgewars/Data/Missions/Training/User_Mission_-_Nobody_Laugh.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Missions/Training/User_Mission_-_Nobody_Laugh.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -1,130 +1,130 @@
---------------------------------------
--- NOBODY LAUGH
--- a hilarious (not really) adventure
---------------------------------------
-
-HedgewarsScriptLoad("/Scripts/Locale.lua")
-HedgewarsScriptLoad("/Scripts/Tracker.lua")
-
-local hhs = {}
-
-function onGameInit()
-
-	Seed = 0
-	GameFlags = gfInfAttack + gfPerHogAmmo +gfDisableWind
-	SuddenDeathTurns = 9999
-	TurnTime = 180000
-	CaseFreq = 0
-	MinesNum = 0
-	Explosives = 0
-	Map = "Bath"
-	Theme = "Nature"
-
-	AddTeam(loc("Nameless Heroes"), 14483456, "eyecross", "Wood", "HillBilly", "cm_birdy")
-	hhs[1] = AddHog(loc( "Hunter" ), 0, 1, "Skull")
-	SetGearPosition(hhs[1], 1267, 451)
-	hhs[2] = AddHog(loc("Drowner"), 0, 31, "mp3")
-	SetGearPosition(hhs[2], 1332, 451)
-
-	AddTeam(loc("Clowns"), 1175851, "Duck2", "Tank", "Mobster", "cm_spider")
-	hhs[3] = AddHog("Poison", 5, 100, "WhySoSerious")
-	SetGearPosition(hhs[3], 1133, 446)
-	hhs[4] = AddHog("Bobo", 5, 100, "clown")
-	SetGearPosition(hhs[4], 1215, 553)
-	hhs[5] = AddHog("Copper", 5, 10, "clown-copper")
-	SetGearPosition(hhs[5], 414, 376)
-	hhs[6] = AddHog("Derp", 5, 100, "clown-crossed")
-	SetGearPosition(hhs[6], 1590, 886)
-	hhs[7] = AddHog("Eckles", 5, 100, "clown-copper")
-	SetGearPosition(hhs[7], 772, 754)
-	hhs[8] = AddHog("Frank", 5, 50, "clown-copper")
-	SetGearPosition(hhs[8], 1688, 714)
-	hhs[9] = AddHog("Harry", 5, 50, "clown-copper")
-	SetGearPosition(hhs[9], 1932, 837)
-	hhs[10] = AddHog("Igmund", 5, 50, "WhySoSerious")
-	SetGearPosition(hhs[10], 1601, 733)
-
-end
-
-function onGameStart()
-
-	AddAmmo(enemy, amAirAttack, 100)
-
-	ShowMission(	loc("Nobody Laugh"),
-					loc("User Challenge"),
-					loc("Eliminate the enemy before the time runs out")
-					, 0, 0
-				)
-
-	-- GIRDERS
-	PlaceGirder(1212, 710, 7)
-	PlaceGirder(1215, 570, 4)
-	PlaceGirder(1288, 520, 2)
-	PlaceGirder(1184, 468, 4)
-	PlaceGirder(1344, 468, 4)
-	PlaceGirder(1247, 346, 4)
-
-	PlaceGirder(667, 438, 4)
-	PlaceGirder(507, 438, 4)
-	PlaceGirder(434, 487, 2)
-	PlaceGirder(505, 537, 4)
-	PlaceGirder(665, 537, 4)
-	PlaceGirder(737, 487, 2)
-
-	PlaceGirder(416, 465, 6)
-	PlaceGirder(1415, 378, 6)
-	PlaceGirder(1300, 625, 3)
-	PlaceGirder(1359, 566, 3)
-	PlaceGirder(1436, 538, 0)
-	PlaceGirder(1505, 468, 4)
-
-	------ AMMO CRATE LIST ------
-	tempG = SpawnAmmoCrate(1242, 315, amBaseballBat)
-	tempG = SpawnAmmoCrate(1309, 315, amAirAttack)
-	tempG = SpawnAmmoCrate(144, 895, amAirAttack)
-	tempG = SpawnAmmoCrate(664, 699, amIceGun)
-	tempG = SpawnAmmoCrate(1572, 444, amFirePunch)
-	tempG = SpawnAmmoCrate(1574, 382, amDynamite)
-
-	------ UTIL CRATE LIST ------
-	tempG = SpawnUtilityCrate(654, 513, amParachute)
-	tempG = SpawnUtilityCrate(1569, 413, amParachute)
-
-	-- HOG AMMO
-	AddAmmo(hhs[1],amParachute,1)
-	AddAmmo(hhs[1],amHammer,1)
-	AddAmmo(hhs[2],amWhip,1)
-
-	for i = 3, 10 do
-		AddAmmo(hhs[i], amDeagle, 100)
-		AddAmmo(hhs[i], amShotgun, 100)
-		AddAmmo(hhs[i], amGrenade, 100)
-		AddAmmo(hhs[i], amBazooka, 100)
-		AddAmmo(hhs[i], amDrill, 100)
-	end
-
-end
-
-function onNewTurn()
-	SetWind(100)
-end
-
-function onAmmoStoreInit()
-
-	SetAmmo(amBaseballBat, 0, 0, 0, 1)
-	SetAmmo(amAirAttack, 0, 0, 0, 1)
-	SetAmmo(amFirePunch, 0, 0, 0, 1)
-	SetAmmo(amDynamite, 0, 0, 0, 1)
-	SetAmmo(amHammer, 0, 0, 0, 1)
-	SetAmmo(amIceGun, 0, 0, 0, 1)
-
-	SetAmmo(amParachute, 0, 0, 0, 1)
-
-	SetAmmo(amSwitch, 9, 0, 0, 0)
-	SetAmmo(amSkip, 9, 0, 0, 0)
-
-end
-
-------------------------------
---                  I'm in         whitesppaaaaaaaaaacceeeee           :D
-------------------------------
+--------------------------------------
+-- NOBODY LAUGH
+-- a hilarious (not really) adventure
+--------------------------------------
+
+HedgewarsScriptLoad("/Scripts/Locale.lua")
+HedgewarsScriptLoad("/Scripts/Tracker.lua")
+
+local hhs = {}
+
+function onGameInit()
+
+	Seed = 0
+	GameFlags = gfInfAttack + gfPerHogAmmo +gfDisableWind
+	SuddenDeathTurns = 9999
+	TurnTime = 180000
+	CaseFreq = 0
+	MinesNum = 0
+	Explosives = 0
+	Map = "Bath"
+	Theme = "Nature"
+
+	AddTeam(loc("Nameless Heroes"), 14483456, "eyecross", "Wood", "HillBilly", "cm_birdy")
+	hhs[1] = AddHog(loc( "Hunter" ), 0, 1, "Skull")
+	SetGearPosition(hhs[1], 1267, 451)
+	hhs[2] = AddHog(loc("Drowner"), 0, 31, "mp3")
+	SetGearPosition(hhs[2], 1332, 451)
+
+	AddTeam(loc("Clowns"), 1175851, "Duck2", "Tank", "Mobster", "cm_spider")
+	hhs[3] = AddHog("Poison", 5, 100, "WhySoSerious")
+	SetGearPosition(hhs[3], 1133, 446)
+	hhs[4] = AddHog("Bobo", 5, 100, "clown")
+	SetGearPosition(hhs[4], 1215, 553)
+	hhs[5] = AddHog("Copper", 5, 10, "clown-copper")
+	SetGearPosition(hhs[5], 414, 376)
+	hhs[6] = AddHog("Derp", 5, 100, "clown-crossed")
+	SetGearPosition(hhs[6], 1590, 886)
+	hhs[7] = AddHog("Eckles", 5, 100, "clown-copper")
+	SetGearPosition(hhs[7], 772, 754)
+	hhs[8] = AddHog("Frank", 5, 50, "clown-copper")
+	SetGearPosition(hhs[8], 1688, 714)
+	hhs[9] = AddHog("Harry", 5, 50, "clown-copper")
+	SetGearPosition(hhs[9], 1932, 837)
+	hhs[10] = AddHog("Igmund", 5, 50, "WhySoSerious")
+	SetGearPosition(hhs[10], 1601, 733)
+
+end
+
+function onGameStart()
+
+	AddAmmo(enemy, amAirAttack, 100)
+
+	ShowMission(	loc("Nobody Laugh"),
+					loc("User Challenge"),
+					loc("Eliminate the enemy before the time runs out")
+					, 0, 0
+				)
+
+	-- GIRDERS
+	PlaceGirder(1212, 710, 7)
+	PlaceGirder(1215, 570, 4)
+	PlaceGirder(1288, 520, 2)
+	PlaceGirder(1184, 468, 4)
+	PlaceGirder(1344, 468, 4)
+	PlaceGirder(1247, 346, 4)
+
+	PlaceGirder(667, 438, 4)
+	PlaceGirder(507, 438, 4)
+	PlaceGirder(434, 487, 2)
+	PlaceGirder(505, 537, 4)
+	PlaceGirder(665, 537, 4)
+	PlaceGirder(737, 487, 2)
+
+	PlaceGirder(416, 465, 6)
+	PlaceGirder(1415, 378, 6)
+	PlaceGirder(1300, 625, 3)
+	PlaceGirder(1359, 566, 3)
+	PlaceGirder(1436, 538, 0)
+	PlaceGirder(1505, 468, 4)
+
+	------ AMMO CRATE LIST ------
+	tempG = SpawnAmmoCrate(1242, 315, amBaseballBat)
+	tempG = SpawnAmmoCrate(1309, 315, amAirAttack)
+	tempG = SpawnAmmoCrate(144, 895, amAirAttack)
+	tempG = SpawnAmmoCrate(664, 699, amIceGun)
+	tempG = SpawnAmmoCrate(1572, 444, amFirePunch)
+	tempG = SpawnAmmoCrate(1574, 382, amDynamite)
+
+	------ UTIL CRATE LIST ------
+	tempG = SpawnUtilityCrate(654, 513, amParachute)
+	tempG = SpawnUtilityCrate(1569, 413, amParachute)
+
+	-- HOG AMMO
+	AddAmmo(hhs[1],amParachute,1)
+	AddAmmo(hhs[1],amHammer,1)
+	AddAmmo(hhs[2],amWhip,1)
+
+	for i = 3, 10 do
+		AddAmmo(hhs[i], amDeagle, 100)
+		AddAmmo(hhs[i], amShotgun, 100)
+		AddAmmo(hhs[i], amGrenade, 100)
+		AddAmmo(hhs[i], amBazooka, 100)
+		AddAmmo(hhs[i], amDrill, 100)
+	end
+
+end
+
+function onNewTurn()
+	SetWind(100)
+end
+
+function onAmmoStoreInit()
+
+	SetAmmo(amBaseballBat, 0, 0, 0, 1)
+	SetAmmo(amAirAttack, 0, 0, 0, 1)
+	SetAmmo(amFirePunch, 0, 0, 0, 1)
+	SetAmmo(amDynamite, 0, 0, 0, 1)
+	SetAmmo(amHammer, 0, 0, 0, 1)
+	SetAmmo(amIceGun, 0, 0, 0, 1)
+
+	SetAmmo(amParachute, 0, 0, 0, 1)
+
+	SetAmmo(amSwitch, 9, 0, 0, 0)
+	SetAmmo(amSkip, 9, 0, 0, 0)
+
+end
+
+------------------------------
+--                  I'm in         whitesppaaaaaaaaaacceeeee           :D
+------------------------------
--- a/share/hedgewars/Data/Scripts/Multiplayer/Balanced_Random_Weapon.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Balanced_Random_Weapon.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -93,8 +93,7 @@
 end
 
 function onGameInit()
-    DisableGameFlags(gfPerHogAmmo)
-    EnableGameFlags(gfResetWeps)
+    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfPerHogAmmo))
     Goals = loc("Each turn you get 1-3 random weapons")
 end
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -444,9 +444,7 @@
 
 function onGameInit()
 
-	DisableGameFlags(gfKing, gfForts)
-	EnableGameFlags(gfDivideTeams)
-
+	GameFlags = band(bor(GameFlags, gfDivideTeams), bnot(gfKing + gfForts))
 	--SuddenDeathTurns = 999 -- suddendeath is off, effectively
 	WaterRise = 0
 	Delay = 10
--- a/share/hedgewars/Data/Scripts/Multiplayer/Frenzy.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Frenzy.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -1,142 +1,142 @@
--------------------------------------------
--- FRENZY
--- a hedgewars mode inspired by Hysteria
--------------------------------------------
-
-HedgewarsScriptLoad("/Scripts/Locale.lua")
-HedgewarsScriptLoad("/Scripts/Tracker.lua")
-
-local cTimer = 0
-local cn = 0
-
-function initialSetup(gear)
-	SetHealth(gear, 75) -- official is 80, but that assumes bazookas/grenades that do 50 damage
-end
-
-function showStartingInfo()
-
-	ruleSet = "" ..
-	loc("RULES") .. ": " .. "|" ..
-	loc("Each turn is only ONE SECOND!") .. "|" ..
-	loc("Use your ready time to think.") .. "|" ..
-	loc("Slot keys save time! (F1-F10 by default)") .. "|" ..
-	" |" ..
-	loc("SLOTS") .. ": " .. "|" ..
-	loc("Slot") .. " 1 - " .. loc("Bazooka") .. "|" ..
-	loc("Slot") .. " 2 - " .. loc("Grenade") .. "|" ..
-	loc("Slot") .. " 3 - " .. loc("Shotgun") .. "|" ..
-	loc("Slot") .. " 4 - " .. loc("Shoryuken") .. "|" ..
-	loc("Slot") .. " 5 - " .. loc("Mine") .. "|" ..
-	loc("Slot") .. " 6 - " .. loc("Teleport") .. "|" ..
-	loc("Slot") .. " 7 - " .. loc("Blowtorch") .. "|" ..
-	loc("Slot") .. " 8 - " .. loc("Flying Saucer") .. "|" ..
-	loc("Slot") .. " 9 - " .. loc("Molotov") .. "|" ..
-	loc("Slot") .. " 10 - " .. loc("Low Gravity")
-
-	ShowMission(loc("FRENZY"),
-                loc("a frenetic Hedgewars mini-game"),
-                ruleSet, 0, 4000)
-
-end
-
-function onGameInit()
-
-	if TurnTime > 10001 then
-		Ready = 8000
-	else
-		Ready = TurnTime
-	end
-
-	TurnTime = 1000
-
-	--These are the official settings, but I think I prefer allowing customization in this regard
-	--MinesNum = 8
-	--MinesTime = 3000
-	--MinesDudPercent = 30
-	--Explosives = 0
-
-	--Supposedly official settings
-	HealthCaseProb = 0
-	CrateFreq = 0
-
-	--Approximation of Official Settings
-	--SuddenDeathTurns = 10
-	--WaterRise = 47
-	--HealthDecrease = 0
-
-end
-
-function onGameStart()
-	showStartingInfo()
-	runOnHogs(initialSetup)
-end
-
-function onSlot(sln)
-	cTimer = 8
-	cn = sln
-end
-
-function onGameTick()
-	if cTimer ~= 0 then
-		cTimer = cTimer -1
-		if cTimer == 1 then
-			ChangeWep(cn)
-			cn = 0
-			cTimer = 0
-		end
-	end
-end
-
-function ChangeWep(s)
-
-	if s == 0 then
-		ParseCommand("setweap " .. string.char(amBazooka))
-	elseif s == 1 then
-		ParseCommand("setweap " .. string.char(amGrenade))
-	elseif s == 2 then
-		ParseCommand("setweap " .. string.char(amShotgun))
-	elseif s == 3 then
-		ParseCommand("setweap " .. string.char(amFirePunch))
-	elseif s == 4 then
-		ParseCommand("setweap " .. string.char(amMine))
-	elseif s == 5 then
-		ParseCommand("setweap " .. string.char(amTeleport))
-	elseif s == 6 then
-		ParseCommand("setweap " .. string.char(amBlowTorch))
-	elseif s == 7 then
-		ParseCommand("setweap " .. string.char(amJetpack))
-	elseif s == 8 then
-		ParseCommand("setweap " .. string.char(amMolotov))
-	elseif s == 9 then
-		ParseCommand("setweap " .. string.char(amLowGravity))
-	end
-
-end
-
-function onGearAdd(gear)
-	if GetGearType(gear) == gtHedgehog then
-		trackGear(gear)
-	end
-end
-
-function onGearDelete(gear)
-	if GetGearType(gear) == gtHedgehog then
-		trackDeletion(gear)
-	end
-end
-
-function onAmmoStoreInit()
-	SetAmmo(amBazooka, 9, 0, 0, 0)
-	SetAmmo(amGrenade, 9, 0, 0, 0)
-	SetAmmo(amMolotov, 9, 0, 0, 0)
-	SetAmmo(amShotgun, 9, 0, 0, 0)
-	--SetAmmo(amFlamethrower, 9, 0, 0, 0) -- this was suggested on hw.org but it's not present on base
-	SetAmmo(amFirePunch, 9, 0, 0, 0)
-	SetAmmo(amMine, 9, 0, 0, 0)
-	--SetAmmo(amCake, 1, 0, 2, 0) -- maybe it's beefcake?
-	SetAmmo(amJetpack, 9, 0, 0, 0)
-	SetAmmo(amBlowTorch, 9, 0, 0, 0)
-	SetAmmo(amTeleport, 9, 0, 0, 0)
-	SetAmmo(amLowGravity, 9, 0, 0, 0)
-	--SetAmmo(amSkipGo, 9, 0, 0, 0) -- not needed with 1s turn time
-end
+-------------------------------------------
+-- FRENZY
+-- a hedgewars mode inspired by Hysteria
+-------------------------------------------
+
+HedgewarsScriptLoad("/Scripts/Locale.lua")
+HedgewarsScriptLoad("/Scripts/Tracker.lua")
+
+local cTimer = 0
+local cn = 0
+
+function initialSetup(gear)
+	SetHealth(gear, 75) -- official is 80, but that assumes bazookas/grenades that do 50 damage
+end
+
+function showStartingInfo()
+
+	ruleSet = "" ..
+	loc("RULES") .. ": " .. "|" ..
+	loc("Each turn is only ONE SECOND!") .. "|" ..
+	loc("Use your ready time to think.") .. "|" ..
+	loc("Slot keys save time! (F1-F10 by default)") .. "|" ..
+	" |" ..
+	loc("SLOTS") .. ": " .. "|" ..
+	loc("Slot") .. " 1 - " .. loc("Bazooka") .. "|" ..
+	loc("Slot") .. " 2 - " .. loc("Grenade") .. "|" ..
+	loc("Slot") .. " 3 - " .. loc("Shotgun") .. "|" ..
+	loc("Slot") .. " 4 - " .. loc("Shoryuken") .. "|" ..
+	loc("Slot") .. " 5 - " .. loc("Mine") .. "|" ..
+	loc("Slot") .. " 6 - " .. loc("Teleport") .. "|" ..
+	loc("Slot") .. " 7 - " .. loc("Blowtorch") .. "|" ..
+	loc("Slot") .. " 8 - " .. loc("Flying Saucer") .. "|" ..
+	loc("Slot") .. " 9 - " .. loc("Molotov") .. "|" ..
+	loc("Slot") .. " 10 - " .. loc("Low Gravity")
+
+	ShowMission(loc("FRENZY"),
+                loc("a frenetic Hedgewars mini-game"),
+                ruleSet, 0, 4000)
+
+end
+
+function onGameInit()
+
+	if TurnTime > 10001 then
+		Ready = 8000
+	else
+		Ready = TurnTime
+	end
+
+	TurnTime = 1000
+
+	--These are the official settings, but I think I prefer allowing customization in this regard
+	--MinesNum = 8
+	--MinesTime = 3000
+	--MinesDudPercent = 30
+	--Explosives = 0
+
+	--Supposedly official settings
+	HealthCaseProb = 0
+	CrateFreq = 0
+
+	--Approximation of Official Settings
+	--SuddenDeathTurns = 10
+	--WaterRise = 47
+	--HealthDecrease = 0
+
+end
+
+function onGameStart()
+	showStartingInfo()
+	runOnHogs(initialSetup)
+end
+
+function onSlot(sln)
+	cTimer = 8
+	cn = sln
+end
+
+function onGameTick()
+	if cTimer ~= 0 then
+		cTimer = cTimer -1
+		if cTimer == 1 then
+			ChangeWep(cn)
+			cn = 0
+			cTimer = 0
+		end
+	end
+end
+
+function ChangeWep(s)
+
+	if s == 0 then
+		ParseCommand("setweap " .. string.char(amBazooka))
+	elseif s == 1 then
+		ParseCommand("setweap " .. string.char(amGrenade))
+	elseif s == 2 then
+		ParseCommand("setweap " .. string.char(amShotgun))
+	elseif s == 3 then
+		ParseCommand("setweap " .. string.char(amFirePunch))
+	elseif s == 4 then
+		ParseCommand("setweap " .. string.char(amMine))
+	elseif s == 5 then
+		ParseCommand("setweap " .. string.char(amTeleport))
+	elseif s == 6 then
+		ParseCommand("setweap " .. string.char(amBlowTorch))
+	elseif s == 7 then
+		ParseCommand("setweap " .. string.char(amJetpack))
+	elseif s == 8 then
+		ParseCommand("setweap " .. string.char(amMolotov))
+	elseif s == 9 then
+		ParseCommand("setweap " .. string.char(amLowGravity))
+	end
+
+end
+
+function onGearAdd(gear)
+	if GetGearType(gear) == gtHedgehog then
+		trackGear(gear)
+	end
+end
+
+function onGearDelete(gear)
+	if GetGearType(gear) == gtHedgehog then
+		trackDeletion(gear)
+	end
+end
+
+function onAmmoStoreInit()
+	SetAmmo(amBazooka, 9, 0, 0, 0)
+	SetAmmo(amGrenade, 9, 0, 0, 0)
+	SetAmmo(amMolotov, 9, 0, 0, 0)
+	SetAmmo(amShotgun, 9, 0, 0, 0)
+	--SetAmmo(amFlamethrower, 9, 0, 0, 0) -- this was suggested on hw.org but it's not present on base
+	SetAmmo(amFirePunch, 9, 0, 0, 0)
+	SetAmmo(amMine, 9, 0, 0, 0)
+	--SetAmmo(amCake, 1, 0, 2, 0) -- maybe it's beefcake?
+	SetAmmo(amJetpack, 9, 0, 0, 0)
+	SetAmmo(amBlowTorch, 9, 0, 0, 0)
+	SetAmmo(amTeleport, 9, 0, 0, 0)
+	SetAmmo(amLowGravity, 9, 0, 0, 0)
+	--SetAmmo(amSkipGo, 9, 0, 0, 0) -- not needed with 1s turn time
+end
--- a/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -203,7 +203,7 @@
 end
 
 function onGameInit()
-	EnableGameFlags(gfInfAttack, gfRandomOrder, gfPerHogAmmo)
+	GameFlags = bor(GameFlags,gfInfAttack + gfRandomOrder + gfPerHogAmmo)
 	HealthCaseProb = 100
 end
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -1,615 +1,615 @@
-local MUTANT_VERSION = "v0.9.5"
-
---[[                  ___                   ___
-                    (   )                 (   )
-___ .-. .-. ___  ___ | |_    .---. ___ .-. | |_
-(   )   '   (   )(   (   __) / .-, (   )   (   __)
-|  .-.  .-. | |  | | | |   (__) ; ||  .-. .| |
-| |  | |  | | |  | | | | ___ .'`  || |  | || | ___
-| |  | |  | | |  | | | |(   / .'| || |  | || |(   )
-| |  | |  | | |  | | | | | | /  | || |  | || | | |
-| |  | |  | | |  ; ' | ' | ; |  ; || |  | || ' | |
-| |  | |  | ' `-'  / ' `-' ' `-'  || |  | |' `-' ;
-(___)(___)(___'.__.'   `.__.`.__.'_(___)(___)`.__.
-
-
-----  Recommended settings:
-----    * one hedgehog per team
-----    * 'Small' one-island map
-
---]]
-
-HedgewarsScriptLoad("/Scripts/Locale.lua")
-HedgewarsScriptLoad("/Scripts/Tracker.lua")
-
---[[
-    MUTANT SCRIPT
-
-    To Do:  -Clean-up this fucking piece of code
-            -Debug
-            -Find a girlfriend
-            -Fix Sheepluva's hat  +[p]
-            -Cookies
------------------------]]
-
-local hhs = {}
-local numhhs = 0
-local meh = false
-
-local gameOver=false
-
-local mutant = nil
-local mutant_base_health = 200
-local mutant_base_disease = 25
-local disease_timer = 2000
-
-local kill_reward = nil
-local mt_hurt=false
-
-local killsCounter = 0
-
-local team_fire_punishment = 3
-local mutant_kill_reward = 2
-
-local hh_weapons = { amBazooka, amGrenade, amShotgun, amMine}
-
-local mt_weapons = {amWatermelon, amHellishBomb, amBallgun, amRCPlane, amTeleport}
-
-local disease=0
-local timer=0
-
-local winScore = 15
-local hogsLimit = 1
-
-local teams = {}
-
-local circles = {}
-local circleFrame = -1
-
-function showStartingInfo()
-
-	ruleSet = loc("RULES") .. ": " ..
-	" |" .. --" |" ..
-	loc("The first player to kill someone becomes the Mutant.") .. "|" ..
-	loc("The Mutant has super-weapons and a lot of health.") .. "|" ..
-	loc("The Mutant loses health quickly if he doesn't keep scoring kills.") .. "|" ..
-	" |" ..
-	loc("Normal players can only score points by killing the mutant.") .. "|" ..
-	" |" .. "" ..
-	loc("The player with least points (or most deaths) becomes the Bottom Feeder.") .. "|" ..
-	loc("The Bottom Feeder can score points by killing anyone.") .. "|" ..
-	" |" ..
-	loc("POINTS") .. ": " ..
-	" |" ..
-	loc("+2 for becoming a Mutant") .. "|" ..
-	loc("+1 to a Mutant for killing anyone") .. "|" ..
-	loc("+1 to a Bottom Feeder for killing anyone") .. "|" ..
-	loc("-1 to anyone for a suicide") .. "|" ..
-	loc("Other kills don't give you points.")
-
-	ShowMission(loc("Mutant"),
-                loc("a Hedgewars tag game"),
-                ruleSet, 0, 5000)
-
-end
-
-function onGameInit()
-    TurnTime = 20000
-    WaterRise = 0
-    EnableGameFlags(gfResetWeps, gfPerHogAmmo)
-    HealthCaseProb=0
-    HealthCaseAmount=0
-    MinesTime=1000
-    CaseFreq = 2
-end
-
-
-function limitHogs(gear)
-    cnthhs = cnthhs + 1
-        if cnthhs > 1 then
-            hogLimitHit = true
-            SetEffect(gear, heResurrectable, false)
-            --SetHealth(gear, 0)
-            SetGearPosition(gear, -100,LAND_HEIGHT)
-        end
-end
-
-function onGameStart()
-    trackTeams()
-    teamScan()
-    runOnHogs(saveStuff)
-    --local str = "/say " .. MUTANT_VERSION
-    --ParseCommand(str)
-
-    hogLimitHit = false
-    for i=0 , TeamsCount - 1 do
-        cnthhs = 0
-        runOnHogsInTeam(limitHogs, teams[i])
-    end
-    if hogLimitHit then
-        AddCaption(loc("ONE HOG PER TEAM! KILLING EXCESS HEDGES"))
-    end
-    showStartingInfo()
-end
-
-
-
-function giveWeapons(gear)
-    if gear == mutant then
-        AddAmmo(gear, amRope)
-        for i=1, #mt_weapons do
-            AddAmmo(gear, mt_weapons[i])
-        end
-
-    else
-        for i=1, #hh_weapons do
-            AddAmmo(gear,hh_weapons[i])
-        end
-    end
-end
-
-function onAmmoStoreInit()
-
-    SetAmmo(amSkip, 9, 0, 0, 0)
-    SetAmmo(amRope,0,1,0,5)
-    SetAmmo(amSnowball,0,1,0,1)
-
-    for i=1, #hh_weapons do
-        SetAmmo(hh_weapons[i], 0, 0, 0, 1)
-    end
-
-    for i=1, #mt_weapons do
-        SetAmmo(mt_weapons[i], 0, 3, 0, 1)
-    end
-
-end
-
-function drawCircles()
-    for i = 0, #hhs do
-        if circles[hhs[i]] ~= nil then
-            DeleteVisualGear(circles[hhs[i]])
-            circles[hhs[i]] = nil
-        end
-
-        if hhs[i] ~= CurrentHedgehog then
-            if mutant == nil then
-                circles[hhs[i]] = AddVisualGear(0, 0, vgtCircle, 0, false)
-                SetVisualGearValues(circles[hhs[i]], 0, 0, 0, 0, 0, 0, 0, 22, 5, 0xff000080)
-            elseif CurrentHedgehog == mutant then
-                circles[hhs[i]] = AddVisualGear(0, 0, vgtCircle, 0, false)
-                SetVisualGearValues(circles[hhs[i]], 0, 0, 0, 0, 0, 0, 0, 22, 3, 0xaa000070)
-            elseif getGearValue(CurrentHedgehog, "Feeder") and hhs[i] ~= mutant then
-                circles[hhs[i]] = AddVisualGear(0, 0, vgtCircle, 0, false)
-                SetVisualGearValues(circles[hhs[i]], 0, 0, 0, 0, 0, 0, 0, 22, 3, 0xaa000070)
-            elseif hhs[i] == mutant then
-                circles[hhs[i]] = AddVisualGear(0, 0, vgtCircle, 0, false)
-                SetVisualGearValues(circles[hhs[i]], 0, 0, 0, 0, 0, 0, 0, 22, 5, 0xff000080)
-            end
-        end
-    end
-    circleFrame = 0
-end
-
-function onNewTurn()
-
-    trackTeams()
-    killsCounter = 0
-
-    if mutant == nil then
-        AddCaption( loc("FIRST BLOOD MUTATES") )
-    end
-
-    checkScore()
-    giveWeapons(CurrentHedgehog)
-    drawCircles()
-    setAIHints()
-    kill_reward= numhhs*10
-
-    if CurrentHedgehog == mutant then
-        mt_hurt=true
-        disease= mutant_base_disease - numhhs
-    else
-        mt_hurt=false
-    end
-
-    setGearValue(CurrentHedgehog, "Alive", true)
-
-end
-
-function countBodies()
-        if killsCounter == 2 then
-            AddCaption(loc("DOUBLE KILL"))
-        elseif killsCounter == 3 then
-            AddCaption(loc("MEGA KILL"))
-            PlaySound(sndRegret)
-        elseif killsCounter == 4 then
-            AddCaption(loc("ULTRA KILL"))
-        elseif killsCounter == 5 then
-            AddCaption(loc("MONSTER KILL"))
-            PlaySound(sndIllGetYou)
-        elseif killsCounter == 6 then
-            AddCaption(loc("LUDICROUS KILL"))
-            PlaySound(sndNutter)
-        elseif killsCounter == 7 then
-            AddCaption(loc("HOLY SHYTE!"))
-            PlaySound(sndLaugh)
-        elseif killsCounter > 8 then
-            AddCaption(loc("INSANITY"))
-        end
-end
-
-function onGameTick()
-
-    if circleFrame > -1 then
-        for i = 0, #hhs do
-            if circles[hhs[i]] ~= nil and hhs[i]~= nil then
-                hhx, hhy = GetGearPosition(hhs[i])
-                X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint = GetVisualGearValues(circles[hhs[i]])
-                SetVisualGearValues(circles[hhs[i]], hhx + 1, hhy - 3, 0, 0, 0, 0, 0, 40 - (circleFrame % 25), Timer, Tint)
-            end
-        end
-
-        circleFrame = circleFrame + 0.06
-
-        if circleFrame >= 25 then
-            for i = 0, #hhs do
-                if circles[hhs[i]] ~= nil then
-                    DeleteVisualGear(circles[hhs[i]])
-                    circles[hhs[i]] = nil
-                end
-            end
-        end
-    end
-
-    if TurnTimeLeft==0 and mt_hurt then
-        mt_hurt = false
-    end
-
-    if mt_hurt and mutant~=nil then
-        timer = timer + 1
-            if timer > disease_timer then
-                timer = 0
-                SetHealth(mutant, GetHealth(mutant)-disease )
-                AddVisualGear(GetX(mutant), GetY(mutant)-5, vgtHealthTag, disease, true)
-                    if GetHealth(mutant)<=0 then
-                        SetHealth(mutant,0)
-                        mt_hurt= false
-                        setGearValue(mutant,"SelfDestruct",true)
-                        TurnTimeLeft = 0
-                    end
-            end
-    end
-
-end
-
-function saveStuff(gear)
-    setGearValue(gear,"Name",GetHogName(gear))
-    setGearValue(gear,"Hat",GetHogHat(gear))
-end
-
-function armageddon(gear)
-    SetState(gear, gstLoser)
-    SetEffect(gear, heResurrectable, false)
-    SetHealth(gear, 0)
-end
-
-function updateScore()
-
-    local showScore = ""
-
-    for i=0, TeamsCount-1 do
-        if teams[i]~= nil then
-
-            local curr_score = getTeamValue(teams[i], "Score")
-            showScore = showScore .. teams[i] .. ": " .. curr_score .. " (deaths: " .. getTeamValue(teams[i], "DeadHogs") .. ") " .. "|"
-
-        end
-    end
-
-    ShowMission(loc("Score"),
-                "-------",
-                showScore, 0, 200)
-
-    HideMission()
-
-end
-
-function checkScore()
-local showScore = ""
-local lowest_score_team = nil
-local min_score=nil
-local winTeam = nil
-
-local only_low_score = true
-
-    for i=0, TeamsCount-1 do
-        if teams[i]~=nil then
-            local curr_score = getTeamValue(teams[i], "Score")
-
-            runOnHogsInTeam(removeFeeder, teams[i])
-
-            showScore = showScore .. teams[i] ..": " .. curr_score .. " (deaths: " .. getTeamValue(teams[i], "DeadHogs") .. ") " .. "|"
-
-            if curr_score >= winScore then
-                gameOver = true
-                winTeam = teams[i]
-            end
-
-            if min_score==nil then
-                min_score= curr_score
-                lowest_score_team = teams[i]
-            else
-                if curr_score <= min_score then
-                    if curr_score == min_score then
-                        if getTeamValue(teams[i], "DeadHogs") == getTeamValue(lowest_score_team, "DeadHogs") then
-                            only_low_score = false
-                        else
-                            if getTeamValue(teams[i], "DeadHogs") > getTeamValue(lowest_score_team, "DeadHogs") then
-                                lowest_score_team = teams[i]
-                            end
-                            only_low_score = true
-                        end
-
-                    else
-                        min_score= curr_score
-                        lowest_score_team = teams[i]
-                        only_low_score = true
-                    end
-                end
-            end
-        end
-    end
-
-    if gameOver then
-        TurnTimeLeft = 0
-        for i=0, #teams do
-            if teams[i]~=winTeam then
-                runOnHogsInTeam(armageddon, teams[i])
-            end
-        end
-
-    ShowMission(    loc("WINNER IS ") .. winTeam,
-                    "~~~~~~~~~~~~~~~~~~~~~~~~~",
-                    showScore, 0, 200)
-    else
-
-    if only_low_score then
-        runOnHogsInTeam(setFeeder, lowest_score_team)
-    end
-
-    if meh == false then
-		meh = true
-	else
-		ShowMission(    loc("Score"),
-                    loc("-------"),
-                    showScore, 0, 200)
-	end
-
-    end
-end
-
-function backToNormal(gear)
-    SetHogName(gear, getGearValue(gear,"Name"))
-    SetHogHat(gear, 'NoHat')
-    SetHogHat(gear, getGearValue(gear,"Hat"))
-    setGearValue(mutant,"SelfDestruct",false)
-    mt_hurt=false
-    mutant=nil
-end
-
-function setAIHints()
-    for i = 0, #hhs do
-        if mutant == nil or hhs[i] == mutant or CurrentHedgehog == mutant then
-            SetGearAIHints(hhs[i], aihUsual)
-        else
-            SetGearAIHints(hhs[i], aihDoesntMatter)
-        end
-    end
-end
-
-function removeFeeder(gear)
-    if gear~=nil then
-        setGearValue(gear,"Feeder",false)
-        if gear~= mutant then
-            SetHogName(gear, getGearValue(gear,"Name") )
-            SetHogHat(gear, 'NoHat')
-            SetHogHat(gear, getGearValue(gear,"Hat"))
-        end
-    end
-end
-
-function setFeeder(gear)
-    if gear~= mutant and gear~= nil then
-        SetHogName(gear,"BOTTOM FEEDER")
-        SetHogHat(gear, 'poke_slowpoke')
-        setGearValue(gear,"Feeder", true)
-    end
-end
-
-function setMutantStuff(gear)
-    mutant = gear
-
-    SetHogName(gear,"MUTANT")
-    SetHogHat(gear,'WhySoSerious')
-    SetHealth(gear, ( mutant_base_health + numhhs*25) )
-    SetEffect(gear, hePoisoned, 1)
-    setGearValue(mutant,"SelfDestruct",false)
-    setGearValue(gear, "Feeder", false)
-
-    AddCaption(getGearValue(gear, "Name") .. loc(" HAS MUTATED"))
-
-    TurnTimeLeft=0
-
-    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
-    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
-    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
-    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
-    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
-    PlaySound(sndSuddenDeath)
-end
-
-function teamScan()
-
-        for i=0, TeamsCount-1 do --nil filling
-        teams[i]=nil
-        end
-
-        for i=0, #hhs do
-            for j=0, TeamsCount-1 do
-                if teams[j] ==nil and hhs[i]~=nil then
-                teams[j] = GetHogTeamName(hhs[i])
-                setTeamValue(teams[j],"Score",0)
-                setTeamValue(teams[j], "DeadHogs",0)
-                break
-                end
-
-                if teams[j] == GetHogTeamName(hhs[i]) then
-                    break
-                end
-            end
-        end
-
-        ---***---
-end
-
-function set_Mutant_and_Score(gear)
-
-local curr_team = GetHogTeamName(CurrentHedgehog)
-
-    if gear == CurrentHedgehog then
-        if CurrentHedgehog == mutant then
-            PlaySound(sndHomerun)
-            if getGearValue(gear, "SelfDestruct")==false then
-                decreaseTeamValue(curr_team,"Score")
-            end
-            backToNormal(gear)
-        else
-            decreaseTeamValue(curr_team,"Score")
-        end
-
-    else
-            if gear == mutant then
-                    backToNormal(mutant)
-                    if curr_team ~=GetHogTeamName(gear) then
-                            if  getGearValue(CurrentHedgehog, "Alive") then
-                            setMutantStuff(CurrentHedgehog)
-                            setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") + mutant_kill_reward))
-                            end
-                    else
-                        setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") - team_fire_punishment))
-                    end
-            else
-                if mutant==nil then
-                        if curr_team ~=GetHogTeamName(gear) then
-                            if getGearValue(CurrentHedgehog, "Alive") then
-                                    setMutantStuff(CurrentHedgehog)
-                                    setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") + mutant_kill_reward))
-                            else
-                                increaseTeamValue(curr_team,"Score")
-                            end
-                        else
-                            setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") - team_fire_punishment))
-                        end
-                else
-                    if curr_team ~=GetHogTeamName(gear) then
-                        if CurrentHedgehog==mutant and getGearValue(mutant,"SelfDestruct")==false then
-                            SetHealth(CurrentHedgehog, GetHealth(CurrentHedgehog)+kill_reward)
-                            AddCaption("+" .. kill_reward .. loc(" HP") )
-                            increaseTeamValue(curr_team,"Score")
-                        end
-                        if getGearValue(CurrentHedgehog,"Feeder") then
-                            increaseTeamValue(curr_team,"Score")
-                        end
-                    else
-                        setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") - team_fire_punishment))
-                    end
-                end
-            end
-    end
-end
-
-function onGearResurrect(gear)
-if not gameOver then
-    if GetGearType(gear) == gtHedgehog then
-
-        increaseTeamValue(GetHogTeamName(gear), "DeadHogs")
-
-        if gear==CurrentHedgehog then
-            setGearValue(CurrentHedgehog, "Alive", false)
-        end
-        set_Mutant_and_Score(gear)
-        if gear~=CurrentHedgehog then
-            killsCounter = killsCounter + 1
-            countBodies()
-        end
-        AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
-        PlaySound(sndWhack)
-        updateScore()
-    end
-end
-end
-
-function onGearAdd(gear)
-
-    -- Catch hedgehogs for the tracker
-    if GetGearType(gear) == gtHedgehog then
-        trackGear(gear)
-        hhs[numhhs] = gear
-        numhhs = numhhs + 1
-        SetEffect(gear, heResurrectable, 1)
-    end
-end
-
-function checkEmptyTeam (teamName)
-    for i=0 , #hhs do
-        if hhs[i]~=nil then
-            if teamName == GetHogTeamName(hhs[i]) then
-                return false
-            end
-        end
-    end
-    return true
-end
-
-function onGearDelete(gear)
-    -- Remove hogs that are gone
-    if GetGearType(gear) == gtHedgehog then
-        numhhs = numhhs - 1
-
-        local found
-        for i=0, #hhs do
-            if hhs[i] == gear then
-                found = i
-                break
-            end
-        end
-        for i = found, #hhs - 1 do
-            hhs[i] = hhs[i + 1]
-        end
-        hhs[#hhs] = nil
-
-        local t_name = GetHogTeamName(gear)
-        if checkEmptyTeam(t_name) then
-            for i = 0, TeamsCount - 1 do
-                if teams[i] == t_name then
-                    found = i
-                    break
-                end
-            end
-            for i = found, TeamsCount - 2 do
-                teams[i] = teams[i + 1]
-            end
-            teams[TeamsCount - 1] = nil
-            TeamsCount = TeamsCount - 1
-        end
-        AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false)
-        trackDeletion(gear)
-    end
-end
-
---[[
-S T A R R I N G
-    prof - Coding, implementing and evangelism
-    vos  - Initial idea and script improvements
-    mikade - Moving the `how to play` into the game so that people know `how to play`, and whitespace :D
---]]
+local MUTANT_VERSION = "v0.9.5"
+
+--[[                  ___                   ___
+                    (   )                 (   )
+___ .-. .-. ___  ___ | |_    .---. ___ .-. | |_
+(   )   '   (   )(   (   __) / .-, (   )   (   __)
+|  .-.  .-. | |  | | | |   (__) ; ||  .-. .| |
+| |  | |  | | |  | | | | ___ .'`  || |  | || | ___
+| |  | |  | | |  | | | |(   / .'| || |  | || |(   )
+| |  | |  | | |  | | | | | | /  | || |  | || | | |
+| |  | |  | | |  ; ' | ' | ; |  ; || |  | || ' | |
+| |  | |  | ' `-'  / ' `-' ' `-'  || |  | |' `-' ;
+(___)(___)(___'.__.'   `.__.`.__.'_(___)(___)`.__.
+
+
+----  Recommended settings:
+----    * one hedgehog per team
+----    * 'Small' one-island map
+
+--]]
+
+HedgewarsScriptLoad("/Scripts/Locale.lua")
+HedgewarsScriptLoad("/Scripts/Tracker.lua")
+
+--[[
+    MUTANT SCRIPT
+
+    To Do:  -Clean-up this fucking piece of code
+            -Debug
+            -Find a girlfriend
+            -Fix Sheepluva's hat  +[p]
+            -Cookies
+-----------------------]]
+
+local hhs = {}
+local numhhs = 0
+local meh = false
+
+local gameOver=false
+
+local mutant = nil
+local mutant_base_health = 200
+local mutant_base_disease = 25
+local disease_timer = 2000
+
+local kill_reward = nil
+local mt_hurt=false
+
+local killsCounter = 0
+
+local team_fire_punishment = 3
+local mutant_kill_reward = 2
+
+local hh_weapons = { amBazooka, amGrenade, amShotgun, amMine}
+
+local mt_weapons = {amWatermelon, amHellishBomb, amBallgun, amRCPlane, amTeleport}
+
+local disease=0
+local timer=0
+
+local winScore = 15
+local hogsLimit = 1
+
+local teams = {}
+
+local circles = {}
+local circleFrame = -1
+
+function showStartingInfo()
+
+	ruleSet = loc("RULES") .. ": " ..
+	" |" .. --" |" ..
+	loc("The first player to kill someone becomes the Mutant.") .. "|" ..
+	loc("The Mutant has super-weapons and a lot of health.") .. "|" ..
+	loc("The Mutant loses health quickly if he doesn't keep scoring kills.") .. "|" ..
+	" |" ..
+	loc("Normal players can only score points by killing the mutant.") .. "|" ..
+	" |" .. "" ..
+	loc("The player with least points (or most deaths) becomes the Bottom Feeder.") .. "|" ..
+	loc("The Bottom Feeder can score points by killing anyone.") .. "|" ..
+	" |" ..
+	loc("POINTS") .. ": " ..
+	" |" ..
+	loc("+2 for becoming a Mutant") .. "|" ..
+	loc("+1 to a Mutant for killing anyone") .. "|" ..
+	loc("+1 to a Bottom Feeder for killing anyone") .. "|" ..
+	loc("-1 to anyone for a suicide") .. "|" ..
+	loc("Other kills don't give you points.")
+
+	ShowMission(loc("Mutant"),
+                loc("a Hedgewars tag game"),
+                ruleSet, 0, 5000)
+
+end
+
+function onGameInit()
+    TurnTime = 20000
+    WaterRise = 0
+    GameFlags = GameFlags + gfResetWeps + gfPerHogAmmo
+    HealthCaseProb=0
+    HealthCaseAmount=0
+    MinesTime=1000
+    CaseFreq = 2
+end
+
+
+function limitHogs(gear)
+    cnthhs = cnthhs + 1
+        if cnthhs > 1 then
+            hogLimitHit = true
+            SetEffect(gear, heResurrectable, false)
+            --SetHealth(gear, 0)
+            SetGearPosition(gear, -100,LAND_HEIGHT)
+        end
+end
+
+function onGameStart()
+    trackTeams()
+    teamScan()
+    runOnHogs(saveStuff)
+    --local str = "/say " .. MUTANT_VERSION
+    --ParseCommand(str)
+
+    hogLimitHit = false
+    for i=0 , TeamsCount - 1 do
+        cnthhs = 0
+        runOnHogsInTeam(limitHogs, teams[i])
+    end
+    if hogLimitHit then
+        AddCaption(loc("ONE HOG PER TEAM! KILLING EXCESS HEDGES"))
+    end
+    showStartingInfo()
+end
+
+
+
+function giveWeapons(gear)
+    if gear == mutant then
+        AddAmmo(gear, amRope)
+        for i=1, #mt_weapons do
+            AddAmmo(gear, mt_weapons[i])
+        end
+
+    else
+        for i=1, #hh_weapons do
+            AddAmmo(gear,hh_weapons[i])
+        end
+    end
+end
+
+function onAmmoStoreInit()
+
+    SetAmmo(amSkip, 9, 0, 0, 0)
+    SetAmmo(amRope,0,1,0,5)
+    SetAmmo(amSnowball,0,1,0,1)
+
+    for i=1, #hh_weapons do
+        SetAmmo(hh_weapons[i], 0, 0, 0, 1)
+    end
+
+    for i=1, #mt_weapons do
+        SetAmmo(mt_weapons[i], 0, 3, 0, 1)
+    end
+
+end
+
+function drawCircles()
+    for i = 0, #hhs do
+        if circles[hhs[i]] ~= nil then
+            DeleteVisualGear(circles[hhs[i]])
+            circles[hhs[i]] = nil
+        end
+
+        if hhs[i] ~= CurrentHedgehog then
+            if mutant == nil then
+                circles[hhs[i]] = AddVisualGear(0, 0, vgtCircle, 0, false)
+                SetVisualGearValues(circles[hhs[i]], 0, 0, 0, 0, 0, 0, 0, 22, 5, 0xff000080)
+            elseif CurrentHedgehog == mutant then
+                circles[hhs[i]] = AddVisualGear(0, 0, vgtCircle, 0, false)
+                SetVisualGearValues(circles[hhs[i]], 0, 0, 0, 0, 0, 0, 0, 22, 3, 0xaa000070)
+            elseif getGearValue(CurrentHedgehog, "Feeder") and hhs[i] ~= mutant then
+                circles[hhs[i]] = AddVisualGear(0, 0, vgtCircle, 0, false)
+                SetVisualGearValues(circles[hhs[i]], 0, 0, 0, 0, 0, 0, 0, 22, 3, 0xaa000070)
+            elseif hhs[i] == mutant then
+                circles[hhs[i]] = AddVisualGear(0, 0, vgtCircle, 0, false)
+                SetVisualGearValues(circles[hhs[i]], 0, 0, 0, 0, 0, 0, 0, 22, 5, 0xff000080)
+            end
+        end
+    end
+    circleFrame = 0
+end
+
+function onNewTurn()
+
+    trackTeams()
+    killsCounter = 0
+
+    if mutant == nil then
+        AddCaption( loc("FIRST BLOOD MUTATES") )
+    end
+
+    checkScore()
+    giveWeapons(CurrentHedgehog)
+    drawCircles()
+    setAIHints()
+    kill_reward= numhhs*10
+
+    if CurrentHedgehog == mutant then
+        mt_hurt=true
+        disease= mutant_base_disease - numhhs
+    else
+        mt_hurt=false
+    end
+
+    setGearValue(CurrentHedgehog, "Alive", true)
+
+end
+
+function countBodies()
+        if killsCounter == 2 then
+            AddCaption(loc("DOUBLE KILL"))
+        elseif killsCounter == 3 then
+            AddCaption(loc("MEGA KILL"))
+            PlaySound(sndRegret)
+        elseif killsCounter == 4 then
+            AddCaption(loc("ULTRA KILL"))
+        elseif killsCounter == 5 then
+            AddCaption(loc("MONSTER KILL"))
+            PlaySound(sndIllGetYou)
+        elseif killsCounter == 6 then
+            AddCaption(loc("LUDICROUS KILL"))
+            PlaySound(sndNutter)
+        elseif killsCounter == 7 then
+            AddCaption(loc("HOLY SHYTE!"))
+            PlaySound(sndLaugh)
+        elseif killsCounter > 8 then
+            AddCaption(loc("INSANITY"))
+        end
+end
+
+function onGameTick()
+
+    if circleFrame > -1 then
+        for i = 0, #hhs do
+            if circles[hhs[i]] ~= nil and hhs[i]~= nil then
+                hhx, hhy = GetGearPosition(hhs[i])
+                X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint = GetVisualGearValues(circles[hhs[i]])
+                SetVisualGearValues(circles[hhs[i]], hhx + 1, hhy - 3, 0, 0, 0, 0, 0, 40 - (circleFrame % 25), Timer, Tint)
+            end
+        end
+
+        circleFrame = circleFrame + 0.06
+
+        if circleFrame >= 25 then
+            for i = 0, #hhs do
+                if circles[hhs[i]] ~= nil then
+                    DeleteVisualGear(circles[hhs[i]])
+                    circles[hhs[i]] = nil
+                end
+            end
+        end
+    end
+
+    if TurnTimeLeft==0 and mt_hurt then
+        mt_hurt = false
+    end
+
+    if mt_hurt and mutant~=nil then
+        timer = timer + 1
+            if timer > disease_timer then
+                timer = 0
+                SetHealth(mutant, GetHealth(mutant)-disease )
+                AddVisualGear(GetX(mutant), GetY(mutant)-5, vgtHealthTag, disease, true)
+                    if GetHealth(mutant)<=0 then
+                        SetHealth(mutant,0)
+                        mt_hurt= false
+                        setGearValue(mutant,"SelfDestruct",true)
+                        TurnTimeLeft = 0
+                    end
+            end
+    end
+
+end
+
+function saveStuff(gear)
+    setGearValue(gear,"Name",GetHogName(gear))
+    setGearValue(gear,"Hat",GetHogHat(gear))
+end
+
+function armageddon(gear)
+    SetState(gear, gstLoser)
+    SetEffect(gear, heResurrectable, false)
+    SetHealth(gear, 0)
+end
+
+function updateScore()
+
+    local showScore = ""
+
+    for i=0, TeamsCount-1 do
+        if teams[i]~= nil then
+
+            local curr_score = getTeamValue(teams[i], "Score")
+            showScore = showScore .. teams[i] .. ": " .. curr_score .. " (deaths: " .. getTeamValue(teams[i], "DeadHogs") .. ") " .. "|"
+
+        end
+    end
+
+    ShowMission(loc("Score"),
+                "-------",
+                showScore, 0, 200)
+
+    HideMission()
+
+end
+
+function checkScore()
+local showScore = ""
+local lowest_score_team = nil
+local min_score=nil
+local winTeam = nil
+
+local only_low_score = true
+
+    for i=0, TeamsCount-1 do
+        if teams[i]~=nil then
+            local curr_score = getTeamValue(teams[i], "Score")
+
+            runOnHogsInTeam(removeFeeder, teams[i])
+
+            showScore = showScore .. teams[i] ..": " .. curr_score .. " (deaths: " .. getTeamValue(teams[i], "DeadHogs") .. ") " .. "|"
+
+            if curr_score >= winScore then
+                gameOver = true
+                winTeam = teams[i]
+            end
+
+            if min_score==nil then
+                min_score= curr_score
+                lowest_score_team = teams[i]
+            else
+                if curr_score <= min_score then
+                    if curr_score == min_score then
+                        if getTeamValue(teams[i], "DeadHogs") == getTeamValue(lowest_score_team, "DeadHogs") then
+                            only_low_score = false
+                        else
+                            if getTeamValue(teams[i], "DeadHogs") > getTeamValue(lowest_score_team, "DeadHogs") then
+                                lowest_score_team = teams[i]
+                            end
+                            only_low_score = true
+                        end
+
+                    else
+                        min_score= curr_score
+                        lowest_score_team = teams[i]
+                        only_low_score = true
+                    end
+                end
+            end
+        end
+    end
+
+    if gameOver then
+        TurnTimeLeft = 0
+        for i=0, #teams do
+            if teams[i]~=winTeam then
+                runOnHogsInTeam(armageddon, teams[i])
+            end
+        end
+
+    ShowMission(    loc("WINNER IS ") .. winTeam,
+                    "~~~~~~~~~~~~~~~~~~~~~~~~~",
+                    showScore, 0, 200)
+    else
+
+    if only_low_score then
+        runOnHogsInTeam(setFeeder, lowest_score_team)
+    end
+
+    if meh == false then
+		meh = true
+	else
+		ShowMission(    loc("Score"),
+                    loc("-------"),
+                    showScore, 0, 200)
+	end
+
+    end
+end
+
+function backToNormal(gear)
+    SetHogName(gear, getGearValue(gear,"Name"))
+    SetHogHat(gear, 'NoHat')
+    SetHogHat(gear, getGearValue(gear,"Hat"))
+    setGearValue(mutant,"SelfDestruct",false)
+    mt_hurt=false
+    mutant=nil
+end
+
+function setAIHints()
+    for i = 0, #hhs do
+        if mutant == nil or hhs[i] == mutant or CurrentHedgehog == mutant then
+            SetGearAIHints(hhs[i], aihUsual)
+        else
+            SetGearAIHints(hhs[i], aihDoesntMatter)
+        end
+    end
+end
+
+function removeFeeder(gear)
+    if gear~=nil then
+        setGearValue(gear,"Feeder",false)
+        if gear~= mutant then
+            SetHogName(gear, getGearValue(gear,"Name") )
+            SetHogHat(gear, 'NoHat')
+            SetHogHat(gear, getGearValue(gear,"Hat"))
+        end
+    end
+end
+
+function setFeeder(gear)
+    if gear~= mutant and gear~= nil then
+        SetHogName(gear,"BOTTOM FEEDER")
+        SetHogHat(gear, 'poke_slowpoke')
+        setGearValue(gear,"Feeder", true)
+    end
+end
+
+function setMutantStuff(gear)
+    mutant = gear
+
+    SetHogName(gear,"MUTANT")
+    SetHogHat(gear,'WhySoSerious')
+    SetHealth(gear, ( mutant_base_health + numhhs*25) )
+    SetEffect(gear, hePoisoned, 1)
+    setGearValue(mutant,"SelfDestruct",false)
+    setGearValue(gear, "Feeder", false)
+
+    AddCaption(getGearValue(gear, "Name") .. loc(" HAS MUTATED"))
+
+    TurnTimeLeft=0
+
+    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
+    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
+    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
+    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
+    AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
+    PlaySound(sndSuddenDeath)
+end
+
+function teamScan()
+
+        for i=0, TeamsCount-1 do --nil filling
+        teams[i]=nil
+        end
+
+        for i=0, #hhs do
+            for j=0, TeamsCount-1 do
+                if teams[j] ==nil and hhs[i]~=nil then
+                teams[j] = GetHogTeamName(hhs[i])
+                setTeamValue(teams[j],"Score",0)
+                setTeamValue(teams[j], "DeadHogs",0)
+                break
+                end
+
+                if teams[j] == GetHogTeamName(hhs[i]) then
+                    break
+                end
+            end
+        end
+
+        ---***---
+end
+
+function set_Mutant_and_Score(gear)
+
+local curr_team = GetHogTeamName(CurrentHedgehog)
+
+    if gear == CurrentHedgehog then
+        if CurrentHedgehog == mutant then
+            PlaySound(sndHomerun)
+            if getGearValue(gear, "SelfDestruct")==false then
+                decreaseTeamValue(curr_team,"Score")
+            end
+            backToNormal(gear)
+        else
+            decreaseTeamValue(curr_team,"Score")
+        end
+
+    else
+            if gear == mutant then
+                    backToNormal(mutant)
+                    if curr_team ~=GetHogTeamName(gear) then
+                            if  getGearValue(CurrentHedgehog, "Alive") then
+                            setMutantStuff(CurrentHedgehog)
+                            setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") + mutant_kill_reward))
+                            end
+                    else
+                        setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") - team_fire_punishment))
+                    end
+            else
+                if mutant==nil then
+                        if curr_team ~=GetHogTeamName(gear) then
+                            if getGearValue(CurrentHedgehog, "Alive") then
+                                    setMutantStuff(CurrentHedgehog)
+                                    setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") + mutant_kill_reward))
+                            else
+                                increaseTeamValue(curr_team,"Score")
+                            end
+                        else
+                            setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") - team_fire_punishment))
+                        end
+                else
+                    if curr_team ~=GetHogTeamName(gear) then
+                        if CurrentHedgehog==mutant and getGearValue(mutant,"SelfDestruct")==false then
+                            SetHealth(CurrentHedgehog, GetHealth(CurrentHedgehog)+kill_reward)
+                            AddCaption("+" .. kill_reward .. loc(" HP") )
+                            increaseTeamValue(curr_team,"Score")
+                        end
+                        if getGearValue(CurrentHedgehog,"Feeder") then
+                            increaseTeamValue(curr_team,"Score")
+                        end
+                    else
+                        setTeamValue(curr_team,"Score",(getTeamValue(curr_team,"Score") - team_fire_punishment))
+                    end
+                end
+            end
+    end
+end
+
+function onGearResurrect(gear)
+if not gameOver then
+    if GetGearType(gear) == gtHedgehog then
+
+        increaseTeamValue(GetHogTeamName(gear), "DeadHogs")
+
+        if gear==CurrentHedgehog then
+            setGearValue(CurrentHedgehog, "Alive", false)
+        end
+        set_Mutant_and_Score(gear)
+        if gear~=CurrentHedgehog then
+            killsCounter = killsCounter + 1
+            countBodies()
+        end
+        AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
+        PlaySound(sndWhack)
+        updateScore()
+    end
+end
+end
+
+function onGearAdd(gear)
+
+    -- Catch hedgehogs for the tracker
+    if GetGearType(gear) == gtHedgehog then
+        trackGear(gear)
+        hhs[numhhs] = gear
+        numhhs = numhhs + 1
+        SetEffect(gear, heResurrectable, 1)
+    end
+end
+
+function checkEmptyTeam (teamName)
+    for i=0 , #hhs do
+        if hhs[i]~=nil then
+            if teamName == GetHogTeamName(hhs[i]) then
+                return false
+            end
+        end
+    end
+    return true
+end
+
+function onGearDelete(gear)
+    -- Remove hogs that are gone
+    if GetGearType(gear) == gtHedgehog then
+        numhhs = numhhs - 1
+
+        local found
+        for i=0, #hhs do
+            if hhs[i] == gear then
+                found = i
+                break
+            end
+        end
+        for i = found, #hhs - 1 do
+            hhs[i] = hhs[i + 1]
+        end
+        hhs[#hhs] = nil
+
+        local t_name = GetHogTeamName(gear)
+        if checkEmptyTeam(t_name) then
+            for i = 0, TeamsCount - 1 do
+                if teams[i] == t_name then
+                    found = i
+                    break
+                end
+            end
+            for i = found, TeamsCount - 2 do
+                teams[i] = teams[i + 1]
+            end
+            teams[TeamsCount - 1] = nil
+            TeamsCount = TeamsCount - 1
+        end
+        AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false)
+        trackDeletion(gear)
+    end
+end
+
+--[[
+S T A R R I N G
+    prof - Coding, implementing and evangelism
+    vos  - Initial idea and script improvements
+    mikade - Moving the `how to play` into the game so that people know `how to play`, and whitespace :D
+--]]
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -1,732 +1,720 @@
-
-------------------------------------------
--- RACER 0.6
--- map-independant racing script
--- by mikade
------------------------------------------
-
------------------------------------
---0.1: took all the code from crazy racer and scrapped most of it
------------------------------------
-
--- Removed tumbler system
--- Removed extra adds like boosters etc
--- Added experimental waypoint placement system
--- More user feedback
--- Reduced race complexity limit to 5 waypoints
--- stop placement at complexity limit reached and end turn
--- guys dont keep racing after dying
--- invulnerable feasibility
--- reverted time keeping method
--- reduced feedback display time
--- colour-coded addcaptions
--- cleaned up code
--- support for more players properly added
--- tardis fix
--- remove airstrikes
-
--- i think the remainder 0 .456 sec of the tracktime isnt getting reset on newturn
-
--- update feedback
-
--------
--- 0.2
--------
-
--- allow gameflags
--- extend time to 90s
--- remove other air-attack based weps
--- turn off water rise for sd
-
--------
--- 0.3
--------
-
--- prevent WP being placed in land
--- prevent waypoints being placed outside border
-
--------
--- 0.4
--------
-
--- update user feedback
--- add more sounds
-
--------
--- 0.5
--------
-
--- fix ghost disappearing if hog falls in water or somehow dies
--- lengthen ghost tracking interval to improve performance on slower machines
--- increase waypoint limit to 8
--- allow for persistent showmission information
-
--------
--- 0.6
--------
-
--- remove hogs from racing area as per request
-
------------------------------
--- SCRIPT BEGINS
------------------------------
-
-HedgewarsScriptLoad("/Scripts/Locale.lua")
-HedgewarsScriptLoad("/Scripts/OfficialChallenges.lua")
-
-------------------
--- Got Variables?
-------------------
-
-local fMod = 1000000 -- 1
-local roundLimit = 3
-local roundNumber = 0
-local firstClan = 10
-
-local fastX = {}
-local fastY = {}
-local fastCount = 0
-local fastIndex = 0
-local fastColour
-
-local currX = {}
-local currY = {}
-local currCount = 0
-
-local specialPointsX = {}
-local specialPointsY = {}
-local specialPointsCount = 0
-
---------------------------
--- hog and team tracking variales
---------------------------
-
-local numhhs = 0 -- store number of hedgehogs
-local hhs = {} -- store hedgehog gears
-
-local numTeams --  store the number of teams in the game
-local teamNameArr = {}  -- store the list of teams
-local teamClan = {}
-local teamSize = {}     -- store how many hogs per team
-local teamIndex = {} -- at what point in the hhs{} does each team begin
-
-local teamComment = {}
-local teamScore = {}
-
--------
--- racer vars
---------
-
-local cGear = nil
-
-local bestClan = nil
-local bestTime = nil
-
-local gameBegun = false
-local gameOver = false
-local racerActive = false
-local trackTime = 0
-
-local wpCirc = {}
-local wpX = {}
-local wpY = {}
-local wpCol = {}
-local wpActive = {}
-local wpRad = 450 --75
-local wpCount = 0
-local wpLimit = 8
-
-local roundN
-local lastRound
-local RoundHasChanged
-
--------------------
--- general methods
--------------------
-
-function RebuildTeamInfo()
-
-
-        -- make a list of individual team names
-        for i = 0, (TeamsCount-1) do
-                teamNameArr[i] = " " -- = i
-                teamSize[i] = 0
-                teamIndex[i] = 0
-                teamScore[i] = 100000
-        end
-        numTeams = 0
-
-        for i = 0, (numhhs-1) do
-
-                z = 0
-                unfinished = true
-                while(unfinished == true) do
-
-                        newTeam = true
-                        tempHogTeamName = GetHogTeamName(hhs[i]) -- this is the new name
-
-                        if tempHogTeamName == teamNameArr[z] then
-                                newTeam = false
-                                unfinished = false
-                        end
-
-                        z = z + 1
-
-                        if z == TeamsCount then
-                                unfinished = false
-                                if newTeam == true then
-                                        teamNameArr[numTeams] = tempHogTeamName
-                                        numTeams = numTeams + 1
-                                end
-                        end
-
-                end
-
-        end
-
-        -- find out how many hogs per team, and the index of the first hog in hhs
-        for i = 0, (numTeams-1) do
-                for z = 0, (numhhs-1) do
-                        if GetHogTeamName(hhs[z]) == teamNameArr[i] then
-                                teamClan[i] = GetHogClan(hhs[z])
-                                if teamSize[i] == 0 then
-                                        teamIndex[i] = z -- should give starting index
-                                end
-                                teamSize[i] = teamSize[i] + 1
-                                --add a pointer so this hog appears at i in hhs
-                        end
-                end
-
-        end
-
-end
-
-
------------------
--- RACER METHODS
------------------
-
-function CheckWaypoints()
-
-        trackFinished = true
-
-        for i = 0, (wpCount-1) do
-
-                g1X, g1Y = GetGearPosition(CurrentHedgehog)
-                g2X, g2Y = wpX[i], wpY[i]
-
-                g1X = g1X - g2X
-                g1Y = g1Y - g2Y
-                dist = (g1X*g1X) + (g1Y*g1Y)
-
-                --if i == 0 then
-                --      AddCaption(dist .. "/" .. (wpRad*wpRad) )
-                --end
-
-                NR = (48/100*wpRad)/2
-
-                if dist < (NR*NR) then
-                --if dist < (wpRad*wpRad) then
-                        --AddCaption("howdy")
-                        wpActive[i] = true
-                        wpCol[i] = GetClanColor(GetHogClan(CurrentHedgehog)) -- new                             --GetClanColor(1)
-                        SetVisualGearValues(wpCirc[i], wpX[i], wpY[i], 20, 100, 1, 10, 0, wpRad, 5, wpCol[i])
-
-                        wpRem = 0
-                        for k = 0, (wpCount-1) do
-                                if wpActive[k] == false then
-                                        wpRem = wpRem + 1
-                                end
-                        end
-
-                        AddCaption(loc("Way-Points Remaining") .. ": " .. wpRem,0xffba00ff,capgrpAmmoinfo)
-
-                end
-
-                if wpActive[i] == false then
-                        trackFinished = false
-                end
-
-        end
-
-        return(trackFinished)
-
-end
-
-function AdjustScores()
-
-        if bestTime == nil then
-                bestTime = 100000
-                bestClan = 10
-                bestTimeComment = "N/A"
-        end
-
-        newScore = false
-
-        -- update this clan's time if the new track is better
-        for i = 0, (numTeams-1) do
-                if teamClan[i] == GetHogClan(CurrentHedgehog) then
-                        if trackTime < teamScore[i] then
-                                teamScore[i] = trackTime
-                                newScore = true
-                        else
-                                newScore = false
-                        end
-                end
-        end
-
-        --bestTime = 100000
-        --bestClan = 10
-
-        -- find the best time out of those so far
-        for i = 0, (numTeams-1) do
-                if teamScore[i] < bestTime then
-                        bestTime = teamScore[i]
-                        bestClan = teamClan[i]
-                end
-        end
-
-        if bestTime ~= 100000 then
-                bestTimeComment = (bestTime/1000) ..loc("s")
-        end
-
-        if newScore == true then
-                if trackTime == bestTime then -- best time of the race
-                        ShowMission(loc("RACER"),
-                        loc("TRACK COMPLETED"),
-                        loc("NEW RACE RECORD: ") .. (trackTime/1000) ..loc("s") .. "|" ..
-                        loc("WINNING TIME: ") .. bestTimeComment, 0, 4000)
-                        PlaySound(sndHomerun)
-                else    -- best time for the clan
-                        ShowMission(loc("RACER"),
-                        loc("TRACK COMPLETED"),
-                        loc("NEW CLAN RECORD: ") .. (trackTime/1000) ..loc("s") .. "|" ..
-                        loc("WINNING TIME: ") .. bestTimeComment, 4, 4000)
-                end
-        else -- not any kind of new score
-                ShowMission(loc("RACER"),
-                loc("TRACK COMPLETED"),
-                loc("TIME: ") .. (trackTime/1000) ..loc("s") .. "|" ..
-                loc("WINNING TIME: ") .. bestTimeComment, -amSkip, 4000)
-                PlaySound(sndHellish)
-        end
-
-
-        --------
-        --new
-        --------
-
-        if bestTime == trackTime then
-                --AddCaption("wooooooooooooooooooooooooooooo")
-
-                fastColour = GetClanColor(GetHogClan(CurrentHedgehog))
-
-                for i = 0, (currCount-1) do
-                        fastX[i] = currX[i]
-                        fastY[i] = currY[i]
-                end
-
-                fastCount = currCount
-                fastIndex = 0
-
-                --currCount = 0 -- is this needed?
-
-        else
-                currCount = 0
-                fastIndex = 0
-        end
-
-
-end
-
-function onNewRound()
-
-        roundNumber = roundNumber + 1
-
-        totalComment = ""
-        for i = 0, (TeamsCount-1) do
-                        if teamNameArr[i] ~= " " then                           -- teamScore[teamClan[i]]
-                                teamComment[i] = teamNameArr[i] .. ": " .. (teamScore[i]/1000) .. loc("s|")
-                                totalComment = totalComment .. teamComment[i]
-                        elseif teamNameArr[i] == " " then
-                                teamComment[i] = "|"
-                        end
-        end
-
-        ShowMission(    loc("RACER"),
-                                        loc("STATUS UPDATE"),
-                                        loc("Rounds Complete: ") .. roundNumber .. "/" .. roundLimit .. "|" .. " " .. "|" ..
-                                        loc("Best Team Times: ") .. "|" .. totalComment, 0, 4000)
-
-        -- end game if its at round limit
-        if roundNumber == roundLimit then
-                for i = 0, (numhhs-1) do
-                        if GetHogClan(hhs[i]) ~= bestClan then
-                                SetEffect(hhs[i], heResurrectable, 0)
-                                SetHealth(hhs[i],0)
-                        end
-                end
-                gameOver = true
-                TurnTimeLeft = 1
-        end
-
-end
-
-function CheckForNewRound()
-
-        -------------
-        ------ new
-        -------------
-
-        --[[turnN = turnN + 1
-        if gameBegun == false then
-                if turnN == 2 then
-                        for i = 0, (numhhs-1) do
-                                if hhs[i] ~= nil then
-                                        SetEffect(hhs[i], heResurrectable, 0)
-                                        SetHealth(hhs[i],0)
-                                end
-                        end
-                        gameOver = true
-                        TurnTimeLeft = 1
-                end
-        else
-
-
-        end]]
-
-        --[[if roundBegun == true then
-
-                if RoundHasChanged == true then
-                        roundN = roundN + 1
-                        RoundHasChanged = false
-                        onNewRound()
-                end
-
-                if lastRound ~= TotalRounds then -- new round, but not really
-
-                        if RoundHasChanged == false then
-                                RoundHasChanged = true
-                        end
-
-                end
-
-                AddCaption("RoundN:" .. roundN .. "; " .. "TR: " .. TotalRounds)
-
-                lastRound = TotalRounds
-
-        end]]
-
-        ------------
-        ----- old
-        ------------
-
-        if GetHogClan(CurrentHedgehog) == firstClan then
-                onNewRound()
-        end
-
-end
-
-function DisableTumbler()
-        currCount = 0
-        fastIndex = 0
-        TurnTimeLeft = 0
-        racerActive = false -- newadd
-end
-
-function HandleGhost()
-
-        -- get the current xy of the racer at this point
-        currX[currCount] = GetX(CurrentHedgehog)
-        currY[currCount] = GetY(CurrentHedgehog)
-        currCount = currCount + 1
-
-        -- draw a ping of smoke where the fastest player was at this point
-        if (fastCount ~= 0) and (fastIndex < fastCount) then
-
-                fastIndex = fastIndex + 1
-
-                tempE = AddVisualGear(fastX[fastIndex], fastY[fastIndex], vgtSmoke, 0, false)
-                g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(tempE)
-                SetVisualGearValues(tempE, g1, g2, g3, g4, g5, g6, g7, g8, g9, fastColour )
-
-                --AddCaption("fC: " .. fastIndex .. " / " .. fastCount)
-
-        else
-
-                --AddCaption("excep fC: " .. fastIndex .. " / " .. fastCount)
-
-        end
-
-
-
-end
-
-function TryRepositionHogs()
-
-	if MapHasBorder() == true then
-
-		for i = 0, (numhhs-1) do
-			if hhs[i] ~= nil then
-				SetGearPosition(hhs[i],GetX(hhs[i]), TopY-10)
-			end
-		end
-
-	end
-
-end
-
-----------------------------------
--- GAME METHODS / EVENT HANDLERS
-----------------------------------
-
-function onGameInit()
-        EnableGameFlags(gfInfAttack, gfInvulnerable)
-        CaseFreq = 0
-        TurnTime = 90000
-        WaterRise = 0
-end
-
-
-function onGameStart()
-
-        roundN = 0
-        lastRound = TotalRounds
-        RoundHasChanged = false -- true
-
-        for i = 0, (specialPointsCount-1) do
-                PlaceWayPoint(specialPointsX[i], specialPointsY[i])
-        end
-
-        RebuildTeamInfo()
-
-        ShowMission     (
-                                loc("RACER"),
-                                loc("a Hedgewars mini-game"),
-
-                                loc("Build a track and race.") .. "|" ..
-                                loc("Round Limit:") .. " " .. roundLimit .. "|" ..
-
-                                "", 4, 4000
-                                )
-
-        TryRepositionHogs()
-
-end
-
-function PlaceWayPoint(x,y)
-
-        if (wpCount < wpLimit) then -- seems to not work with a hedgehog nil chek
-
-                wpX[wpCount] = x
-                wpY[wpCount] = y
-                wpCol[wpCount] = 0xffffffff
-                wpCirc[wpCount] = AddVisualGear(wpX[wpCount],wpY[wpCount],vgtCircle,0,true)
-                                                                                                                                                --100
-                SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], 20, 100, 1, 10, 0, wpRad, 5, wpCol[wpCount])
-
-                wpCount = wpCount + 1
-
-                AddCaption(loc("Waypoint placed.") .. " " .. loc("Available points remaining: ") .. (wpLimit-wpCount))
-
-        end
-
-end
-
-function onSpecialPoint(x,y,flag)
-    specialPointsX[specialPointsCount] = x
-    specialPointsY[specialPointsCount] = y
-    specialPointsCount = specialPointsCount + 1
-end
-
-function onNewTurn()
-
-        CheckForNewRound()
-        TryRepositionHogs()
-
-        racerActive = false
-
-        trackTime = 0
-
-        currCount = 0 -- hopefully this solves problem
-        AddAmmo(CurrentHedgehog, amAirAttack, 0)
-        gTimer = 0
-
-        -- Set the waypoints to unactive on new round
-        for i = 0,(wpCount-1) do
-                wpActive[i] = false
-                wpCol[i] = 0xffffffff
-                SetVisualGearValues(wpCirc[i], wpX[i], wpY[i], 20, 100, 1, 10, 0, wpRad, 5, wpCol[i])
-        end
-
-        -- Handle Starting Stage of Game
-        if (gameOver == false) and (gameBegun == false) then
-                if wpCount >= 3 then
-                        gameBegun = true
-                        roundNumber = 0
-                        firstClan = GetHogClan(CurrentHedgehog)
-                        ShowMission(loc("RACER"),
-                        loc("GAME BEGUN!!!"),
-                        loc("Complete the track as fast as you can!"), 2, 4000)
-                else
-                        ShowMission(loc("RACER"),
-                        loc("NOT ENOUGH WAYPOINTS"),
-                        loc("Place more waypoints using the 'Air Attack' weapon."), 2, 4000)
-                        AddAmmo(CurrentHedgehog, amAirAttack, 4000)
-            ParseCommand("setweap " .. string.char(amAirAttack))
-                end
-        end
-
-        if gameOver == true then
-                gameBegun = false
-                racerActive = false -- newadd
-        end
-
-        AddAmmo(CurrentHedgehog, amTardis, 0)
-        AddAmmo(CurrentHedgehog, amDrillStrike, 0)
-        AddAmmo(CurrentHedgehog, amMineStrike, 0)
-        AddAmmo(CurrentHedgehog, amNapalm, 0)
-        AddAmmo(CurrentHedgehog, amPiano, 0)
-
-end
-
-function onGameTick20()
-
-        -- airstrike detected, convert this into a potential waypoint spot
-        if cGear ~= nil then
-                x,y = GetGearPosition(cGear)
-        if x > -9000 then
-            x,y = GetGearTarget(cGear)
-
-
-            if TestRectForObstacle(x-20, y-20, x+20, y+20, true) then
-                AddCaption(loc("Please place the way-point in the open, within the map boundaries."))
-                PlaySound(sndDenied)
-            elseif (y > WaterLine-50) then
-                AddCaption(loc("Please place the way-point further from the waterline."))
-                PlaySound(sndDenied)
-            else
-                PlaceWayPoint(x, y)
-                if wpCount == wpLimit then
-                    AddCaption(loc("Race complexity limit reached."))
-                    DisableTumbler()
-                end
-            end
-        else
-            DeleteGear(cGear)
-        end
-        SetGearPosition(cGear, -10000, 0)
-        end
-
-
-        -- start the player tumbling with a boom once their turn has actually begun
-        if racerActive == false then
-
-                if (TurnTimeLeft > 0) and (TurnTimeLeft ~= TurnTime) then
-
-                        -- if the gamehas started put the player in the middle of the first
-                        --waypoint that was placed
-                        if gameBegun == true then
-                                AddCaption(loc("Good to go!"))
-                                racerActive = true
-                                trackTime = 0
-
-                                SetGearPosition(CurrentHedgehog, wpX[0], wpY[0])
-                                AddGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), gtGrenade, 0, 0, 0, 1)
-                                FollowGear(CurrentHedgehog)
-
-                                HideMission()
-
-                        else
-                                -- still in placement mode
-                        end
-
-                end
-        end
-
-
-
-        -- has the player started his tumbling spree?
-        if (CurrentHedgehog ~= nil) then
-
-                --airstrike conversion used to be here
-
-                -- if the RACE has started, show tracktimes and keep tabs on waypoints
-                if (racerActive == true) and (gameBegun == true) then
-
-                        --ghost
-                        if GameTime%40 == 0 then
-                                HandleGhost()
-                        end
-
-                        trackTime = trackTime + 20
-
-                        if GameTime%100 == 0 then
-
-                if trackTime%1000 == 0 then
-                    AddCaption((trackTime/1000)..'.0',GetClanColor(GetHogClan(CurrentHedgehog)),capgrpMessage2)
-                else
-                    AddCaption(trackTime/1000,GetClanColor(GetHogClan(CurrentHedgehog)),capgrpMessage2)
-                end
-
-                                if (CheckWaypoints() == true) then
-                                        AdjustScores()
-                                        racerActive = false
-                                        DisableTumbler()
-                                end
-
-                        end
-
-                end
-
-                -- if the player has expended his tunbling time, stop him tumbling
-                if TurnTimeLeft <= 20 then
-                        DisableTumbler()
-                end
-
-        end
-
-end
-
-function onGearResurrect(gear)
-
-        AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false)
-
-        if gear == CurrentHedgehog then
-                DisableTumbler()
-        end
-
-end
-
-function onGearAdd(gear)
-
-        if GetGearType(gear) == gtHedgehog then
-                hhs[numhhs] = gear
-                numhhs = numhhs + 1
-                SetEffect(gear, heResurrectable, 1)
-        end
-
-        if GetGearType(gear) == gtAirAttack then
-                cGear = gear
-        end
-
-end
-
-function onGearDelete(gear)
-
-        if GetGearType(gear) == gtAirAttack then
-                cGear = nil
-        end
-
-end
-
-
-function onAchievementsDeclaration()
-    map = detectMap()
-    
-    for i = 0, (numTeams-1) do
-        if teamScore[i] < 100000 then
-            DeclareAchievement("rope race", teamNameArr[i], map, teamScore[i])
-        end
-    end
-end
+
+------------------------------------------
+-- RACER 0.6
+-- map-independant racing script
+-- by mikade
+-----------------------------------------
+
+-----------------------------------
+--0.1: took all the code from crazy racer and scrapped most of it
+-----------------------------------
+
+-- Removed tumbler system
+-- Removed extra adds like boosters etc
+-- Added experimental waypoint placement system
+-- More user feedback
+-- Reduced race complexity limit to 5 waypoints
+-- stop placement at complexity limit reached and end turn
+-- guys dont keep racing after dying
+-- invulnerable feasibility
+-- reverted time keeping method
+-- reduced feedback display time
+-- colour-coded addcaptions
+-- cleaned up code
+-- support for more players properly added
+-- tardis fix
+-- remove airstrikes
+
+-- i think the remainder 0 .456 sec of the tracktime isnt getting reset on newturn
+
+-- update feedback
+
+-------
+-- 0.2
+-------
+
+-- allow gameflags
+-- extend time to 90s
+-- remove other air-attack based weps
+-- turn off water rise for sd
+
+-------
+-- 0.3
+-------
+
+-- prevent WP being placed in land
+-- prevent waypoints being placed outside border
+
+-------
+-- 0.4
+-------
+
+-- update user feedback
+-- add more sounds
+
+-------
+-- 0.5
+-------
+
+-- fix ghost disappearing if hog falls in water or somehow dies
+-- lengthen ghost tracking interval to improve performance on slower machines
+-- increase waypoint limit to 8
+-- allow for persistent showmission information
+
+-------
+-- 0.6
+-------
+
+-- remove hogs from racing area as per request
+
+-----------------------------
+-- SCRIPT BEGINS
+-----------------------------
+
+HedgewarsScriptLoad("/Scripts/Locale.lua")
+
+------------------
+-- Got Variables?
+------------------
+
+local fMod = 1000000 -- 1
+local roundLimit = 3
+local roundNumber = 0
+local firstClan = 10
+
+local fastX = {}
+local fastY = {}
+local fastCount = 0
+local fastIndex = 0
+local fastColour
+
+local currX = {}
+local currY = {}
+local currCount = 0
+
+local specialPointsX = {}
+local specialPointsY = {}
+local specialPointsCount = 0
+
+--------------------------
+-- hog and team tracking variales
+--------------------------
+
+local numhhs = 0 -- store number of hedgehogs
+local hhs = {} -- store hedgehog gears
+
+local numTeams --  store the number of teams in the game
+local teamNameArr = {}  -- store the list of teams
+local teamClan = {}
+local teamSize = {}     -- store how many hogs per team
+local teamIndex = {} -- at what point in the hhs{} does each team begin
+
+local teamComment = {}
+local teamScore = {}
+
+-------
+-- racer vars
+--------
+
+local cGear = nil
+
+local bestClan = nil
+local bestTime = nil
+
+local gameBegun = false
+local gameOver = false
+local racerActive = false
+local trackTime = 0
+
+local wpCirc = {}
+local wpX = {}
+local wpY = {}
+local wpCol = {}
+local wpActive = {}
+local wpRad = 450 --75
+local wpCount = 0
+local wpLimit = 8
+
+local roundN
+local lastRound
+local RoundHasChanged
+
+-------------------
+-- general methods
+-------------------
+
+function RebuildTeamInfo()
+
+
+        -- make a list of individual team names
+        for i = 0, (TeamsCount-1) do
+                teamNameArr[i] = " " -- = i
+                teamSize[i] = 0
+                teamIndex[i] = 0
+                teamScore[i] = 100000
+        end
+        numTeams = 0
+
+        for i = 0, (numhhs-1) do
+
+                z = 0
+                unfinished = true
+                while(unfinished == true) do
+
+                        newTeam = true
+                        tempHogTeamName = GetHogTeamName(hhs[i]) -- this is the new name
+
+                        if tempHogTeamName == teamNameArr[z] then
+                                newTeam = false
+                                unfinished = false
+                        end
+
+                        z = z + 1
+
+                        if z == TeamsCount then
+                                unfinished = false
+                                if newTeam == true then
+                                        teamNameArr[numTeams] = tempHogTeamName
+                                        numTeams = numTeams + 1
+                                end
+                        end
+
+                end
+
+        end
+
+        -- find out how many hogs per team, and the index of the first hog in hhs
+        for i = 0, (numTeams-1) do
+                for z = 0, (numhhs-1) do
+                        if GetHogTeamName(hhs[z]) == teamNameArr[i] then
+                                teamClan[i] = GetHogClan(hhs[z])
+                                if teamSize[i] == 0 then
+                                        teamIndex[i] = z -- should give starting index
+                                end
+                                teamSize[i] = teamSize[i] + 1
+                                --add a pointer so this hog appears at i in hhs
+                        end
+                end
+
+        end
+
+end
+
+
+-----------------
+-- RACER METHODS
+-----------------
+
+function CheckWaypoints()
+
+        trackFinished = true
+
+        for i = 0, (wpCount-1) do
+
+                g1X, g1Y = GetGearPosition(CurrentHedgehog)
+                g2X, g2Y = wpX[i], wpY[i]
+
+                g1X = g1X - g2X
+                g1Y = g1Y - g2Y
+                dist = (g1X*g1X) + (g1Y*g1Y)
+
+                --if i == 0 then
+                --      AddCaption(dist .. "/" .. (wpRad*wpRad) )
+                --end
+
+                NR = (48/100*wpRad)/2
+
+                if dist < (NR*NR) then
+                --if dist < (wpRad*wpRad) then
+                        --AddCaption("howdy")
+                        wpActive[i] = true
+                        wpCol[i] = GetClanColor(GetHogClan(CurrentHedgehog)) -- new                             --GetClanColor(1)
+                        SetVisualGearValues(wpCirc[i], wpX[i], wpY[i], 20, 100, 1, 10, 0, wpRad, 5, wpCol[i])
+
+                        wpRem = 0
+                        for k = 0, (wpCount-1) do
+                                if wpActive[k] == false then
+                                        wpRem = wpRem + 1
+                                end
+                        end
+
+                        AddCaption(loc("Way-Points Remaining") .. ": " .. wpRem,0xffba00ff,capgrpAmmoinfo)
+
+                end
+
+                if wpActive[i] == false then
+                        trackFinished = false
+                end
+
+        end
+
+        return(trackFinished)
+
+end
+
+function AdjustScores()
+
+        if bestTime == nil then
+                bestTime = 100000
+                bestClan = 10
+                bestTimeComment = "N/A"
+        end
+
+        newScore = false
+
+        -- update this clan's time if the new track is better
+        for i = 0, (numTeams-1) do
+                if teamClan[i] == GetHogClan(CurrentHedgehog) then
+                        if trackTime < teamScore[i] then
+                                teamScore[i] = trackTime
+                                newScore = true
+                        else
+                                newScore = false
+                        end
+                end
+        end
+
+        --bestTime = 100000
+        --bestClan = 10
+
+        -- find the best time out of those so far
+        for i = 0, (numTeams-1) do
+                if teamScore[i] < bestTime then
+                        bestTime = teamScore[i]
+                        bestClan = teamClan[i]
+                end
+        end
+
+        if bestTime ~= 100000 then
+                bestTimeComment = (bestTime/1000) ..loc("s")
+        end
+
+        if newScore == true then
+                if trackTime == bestTime then -- best time of the race
+                        ShowMission(loc("RACER"),
+                        loc("TRACK COMPLETED"),
+                        loc("NEW RACE RECORD: ") .. (trackTime/1000) ..loc("s") .. "|" ..
+                        loc("WINNING TIME: ") .. bestTimeComment, 0, 4000)
+                        PlaySound(sndHomerun)
+                else    -- best time for the clan
+                        ShowMission(loc("RACER"),
+                        loc("TRACK COMPLETED"),
+                        loc("NEW CLAN RECORD: ") .. (trackTime/1000) ..loc("s") .. "|" ..
+                        loc("WINNING TIME: ") .. bestTimeComment, 4, 4000)
+                end
+        else -- not any kind of new score
+                ShowMission(loc("RACER"),
+                loc("TRACK COMPLETED"),
+                loc("TIME: ") .. (trackTime/1000) ..loc("s") .. "|" ..
+                loc("WINNING TIME: ") .. bestTimeComment, -amSkip, 4000)
+                PlaySound(sndHellish)
+        end
+
+
+        --------
+        --new
+        --------
+
+        if bestTime == trackTime then
+                --AddCaption("wooooooooooooooooooooooooooooo")
+
+                fastColour = GetClanColor(GetHogClan(CurrentHedgehog))
+
+                for i = 0, (currCount-1) do
+                        fastX[i] = currX[i]
+                        fastY[i] = currY[i]
+                end
+
+                fastCount = currCount
+                fastIndex = 0
+
+                --currCount = 0 -- is this needed?
+
+        else
+                currCount = 0
+                fastIndex = 0
+        end
+
+
+end
+
+function onNewRound()
+
+        roundNumber = roundNumber + 1
+
+        totalComment = ""
+        for i = 0, (TeamsCount-1) do
+                        if teamNameArr[i] ~= " " then                           -- teamScore[teamClan[i]]
+                                teamComment[i] = teamNameArr[i] .. ": " .. (teamScore[i]/1000) .. loc("s|")
+                                totalComment = totalComment .. teamComment[i]
+                        elseif teamNameArr[i] == " " then
+                                teamComment[i] = "|"
+                        end
+        end
+
+        ShowMission(    loc("RACER"),
+                                        loc("STATUS UPDATE"),
+                                        loc("Rounds Complete: ") .. roundNumber .. "/" .. roundLimit .. "|" .. " " .. "|" ..
+                                        loc("Best Team Times: ") .. "|" .. totalComment, 0, 4000)
+
+        -- end game if its at round limit
+        if roundNumber == roundLimit then
+                for i = 0, (numhhs-1) do
+                        if GetHogClan(hhs[i]) ~= bestClan then
+                                SetEffect(hhs[i], heResurrectable, 0)
+                                SetHealth(hhs[i],0)
+                        end
+                end
+                gameOver = true
+                TurnTimeLeft = 1
+        end
+
+end
+
+function CheckForNewRound()
+
+        -------------
+        ------ new
+        -------------
+
+        --[[turnN = turnN + 1
+        if gameBegun == false then
+                if turnN == 2 then
+                        for i = 0, (numhhs-1) do
+                                if hhs[i] ~= nil then
+                                        SetEffect(hhs[i], heResurrectable, 0)
+                                        SetHealth(hhs[i],0)
+                                end
+                        end
+                        gameOver = true
+                        TurnTimeLeft = 1
+                end
+        else
+
+
+        end]]
+
+        --[[if roundBegun == true then
+
+                if RoundHasChanged == true then
+                        roundN = roundN + 1
+                        RoundHasChanged = false
+                        onNewRound()
+                end
+
+                if lastRound ~= TotalRounds then -- new round, but not really
+
+                        if RoundHasChanged == false then
+                                RoundHasChanged = true
+                        end
+
+                end
+
+                AddCaption("RoundN:" .. roundN .. "; " .. "TR: " .. TotalRounds)
+
+                lastRound = TotalRounds
+
+        end]]
+
+        ------------
+        ----- old
+        ------------
+
+        if GetHogClan(CurrentHedgehog) == firstClan then
+                onNewRound()
+        end
+
+end
+
+function DisableTumbler()
+        currCount = 0
+        fastIndex = 0
+        TurnTimeLeft = 0
+        racerActive = false -- newadd
+end
+
+function HandleGhost()
+
+        -- get the current xy of the racer at this point
+        currX[currCount] = GetX(CurrentHedgehog)
+        currY[currCount] = GetY(CurrentHedgehog)
+        currCount = currCount + 1
+
+        -- draw a ping of smoke where the fastest player was at this point
+        if (fastCount ~= 0) and (fastIndex < fastCount) then
+
+                fastIndex = fastIndex + 1
+
+                tempE = AddVisualGear(fastX[fastIndex], fastY[fastIndex], vgtSmoke, 0, false)
+                g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(tempE)
+                SetVisualGearValues(tempE, g1, g2, g3, g4, g5, g6, g7, g8, g9, fastColour )
+
+                --AddCaption("fC: " .. fastIndex .. " / " .. fastCount)
+
+        else
+
+                --AddCaption("excep fC: " .. fastIndex .. " / " .. fastCount)
+
+        end
+
+
+
+end
+
+function TryRepositionHogs()
+
+	if MapHasBorder() == true then
+
+		for i = 0, (numhhs-1) do
+			if hhs[i] ~= nil then
+				SetGearPosition(hhs[i],GetX(hhs[i]), TopY-10)
+			end
+		end
+
+	end
+
+end
+
+----------------------------------
+-- GAME METHODS / EVENT HANDLERS
+----------------------------------
+
+function onGameInit()
+        GameFlags = bor(GameFlags,gfInfAttack + gfInvulnerable)
+        CaseFreq = 0
+        TurnTime = 90000
+        WaterRise = 0
+end
+
+
+function onGameStart()
+
+        roundN = 0
+        lastRound = TotalRounds
+        RoundHasChanged = false -- true
+
+        for i = 0, (specialPointsCount-1) do
+                PlaceWayPoint(specialPointsX[i], specialPointsY[i])
+        end
+
+        RebuildTeamInfo()
+
+        ShowMission     (
+                                loc("RACER"),
+                                loc("a Hedgewars mini-game"),
+
+                                loc("Build a track and race.") .. "|" ..
+                                loc("Round Limit:") .. " " .. roundLimit .. "|" ..
+
+                                "", 4, 4000
+                                )
+
+        TryRepositionHogs()
+
+end
+
+function PlaceWayPoint(x,y)
+
+        if (wpCount < wpLimit) then -- seems to not work with a hedgehog nil chek
+
+                wpX[wpCount] = x
+                wpY[wpCount] = y
+                wpCol[wpCount] = 0xffffffff
+                wpCirc[wpCount] = AddVisualGear(wpX[wpCount],wpY[wpCount],vgtCircle,0,true)
+                                                                                                                                                --100
+                SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], 20, 100, 1, 10, 0, wpRad, 5, wpCol[wpCount])
+
+                wpCount = wpCount + 1
+
+                AddCaption(loc("Waypoint placed.") .. " " .. loc("Available points remaining: ") .. (wpLimit-wpCount))
+
+        end
+
+end
+
+function onSpecialPoint(x,y,flag)
+    specialPointsX[specialPointsCount] = x
+    specialPointsY[specialPointsCount] = y
+    specialPointsCount = specialPointsCount + 1
+end
+
+function onNewTurn()
+
+        CheckForNewRound()
+        TryRepositionHogs()
+
+        racerActive = false
+
+        trackTime = 0
+
+        currCount = 0 -- hopefully this solves problem
+        AddAmmo(CurrentHedgehog, amAirAttack, 0)
+        gTimer = 0
+
+        -- Set the waypoints to unactive on new round
+        for i = 0,(wpCount-1) do
+                wpActive[i] = false
+                wpCol[i] = 0xffffffff
+                SetVisualGearValues(wpCirc[i], wpX[i], wpY[i], 20, 100, 1, 10, 0, wpRad, 5, wpCol[i])
+        end
+
+        -- Handle Starting Stage of Game
+        if (gameOver == false) and (gameBegun == false) then
+                if wpCount >= 3 then
+                        gameBegun = true
+                        roundNumber = 0
+                        firstClan = GetHogClan(CurrentHedgehog)
+                        ShowMission(loc("RACER"),
+                        loc("GAME BEGUN!!!"),
+                        loc("Complete the track as fast as you can!"), 2, 4000)
+                else
+                        ShowMission(loc("RACER"),
+                        loc("NOT ENOUGH WAYPOINTS"),
+                        loc("Place more waypoints using the 'Air Attack' weapon."), 2, 4000)
+                        AddAmmo(CurrentHedgehog, amAirAttack, 4000)
+            ParseCommand("setweap " .. string.char(amAirAttack))
+                end
+        end
+
+        if gameOver == true then
+                gameBegun = false
+                racerActive = false -- newadd
+        end
+
+        AddAmmo(CurrentHedgehog, amTardis, 0)
+        AddAmmo(CurrentHedgehog, amDrillStrike, 0)
+        AddAmmo(CurrentHedgehog, amMineStrike, 0)
+        AddAmmo(CurrentHedgehog, amNapalm, 0)
+        AddAmmo(CurrentHedgehog, amPiano, 0)
+
+end
+
+function onGameTick20()
+
+        -- airstrike detected, convert this into a potential waypoint spot
+        if cGear ~= nil then
+                x,y = GetGearPosition(cGear)
+        if x > -9000 then
+            x,y = GetGearTarget(cGear)
+
+
+            if TestRectForObstacle(x-20, y-20, x+20, y+20, true) then
+                AddCaption(loc("Please place the way-point in the open, within the map boundaries."))
+                PlaySound(sndDenied)
+            elseif (y > WaterLine-50) then
+                AddCaption(loc("Please place the way-point further from the waterline."))
+                PlaySound(sndDenied)
+            else
+                PlaceWayPoint(x, y)
+                if wpCount == wpLimit then
+                    AddCaption(loc("Race complexity limit reached."))
+                    DisableTumbler()
+                end
+            end
+        else
+            DeleteGear(cGear)
+        end
+        SetGearPosition(cGear, -10000, 0)
+        end
+
+
+        -- start the player tumbling with a boom once their turn has actually begun
+        if racerActive == false then
+
+                if (TurnTimeLeft > 0) and (TurnTimeLeft ~= TurnTime) then
+
+                        -- if the gamehas started put the player in the middle of the first
+                        --waypoint that was placed
+                        if gameBegun == true then
+                                AddCaption(loc("Good to go!"))
+                                racerActive = true
+                                trackTime = 0
+
+                                SetGearPosition(CurrentHedgehog, wpX[0], wpY[0])
+                                AddGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), gtGrenade, 0, 0, 0, 1)
+                                FollowGear(CurrentHedgehog)
+
+                                HideMission()
+
+                        else
+                                -- still in placement mode
+                        end
+
+                end
+        end
+
+
+
+        -- has the player started his tumbling spree?
+        if (CurrentHedgehog ~= nil) then
+
+                --airstrike conversion used to be here
+
+                -- if the RACE has started, show tracktimes and keep tabs on waypoints
+                if (racerActive == true) and (gameBegun == true) then
+
+                        --ghost
+                        if GameTime%40 == 0 then
+                                HandleGhost()
+                        end
+
+                        trackTime = trackTime + 20
+
+                        if GameTime%100 == 0 then
+
+                if trackTime%1000 == 0 then
+                    AddCaption((trackTime/1000)..'.0',GetClanColor(GetHogClan(CurrentHedgehog)),capgrpMessage2)
+                else
+                    AddCaption(trackTime/1000,GetClanColor(GetHogClan(CurrentHedgehog)),capgrpMessage2)
+                end
+
+                                if (CheckWaypoints() == true) then
+                                        AdjustScores()
+                                        racerActive = false
+                                        DisableTumbler()
+                                end
+
+                        end
+
+                end
+
+                -- if the player has expended his tunbling time, stop him tumbling
+                if TurnTimeLeft <= 20 then
+                        DisableTumbler()
+                end
+
+        end
+
+end
+
+function onGearResurrect(gear)
+
+        AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false)
+
+        if gear == CurrentHedgehog then
+                DisableTumbler()
+        end
+
+end
+
+function onGearAdd(gear)
+
+        if GetGearType(gear) == gtHedgehog then
+                hhs[numhhs] = gear
+                numhhs = numhhs + 1
+                SetEffect(gear, heResurrectable, 1)
+        end
+
+        if GetGearType(gear) == gtAirAttack then
+                cGear = gear
+        end
+
+end
+
+function onGearDelete(gear)
+
+        if GetGearType(gear) == gtAirAttack then
+                cGear = nil
+        end
+
+end
--- a/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -46,8 +46,7 @@
 
 function onGameInit()
     -- Limit flags that can be set, but allow game schemes to be used
-    DisableGameFlags(gfInfAttack)
-    EnableGameFlags(gfResetWeps)
+    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack))
     -- Set a custom game goal that will show together with the scheme ones
     Goals = loc("Each turn you get one random weapon")
 end
--- a/share/hedgewars/Data/Scripts/Multiplayer/ShoppaMap.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/ShoppaMap.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -363,8 +363,8 @@
     local y = 0
     local w = 0
     local h = 0 
-    EnableGameFlags(gfShoppaBorder)
-    if not GetGameFlag(gfBottomBorder) and GetRandom(2) == 0 then
+    GameFlags = bor(GameFlags, gfShoppaBorder)
+    if band(GameFlags,gfBottomBorder) == 0 and GetRandom(2) == 0 then
         AddPoint(-50,2010,7)
         AddPoint(4150,2010)
         for i = 0,GetRandom(3) do
--- a/share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -1001,8 +1001,7 @@
 --------------------------
 
 function onGameInit()
-	ClearGameFlags()
-	EnableGameFlags(gfRandomOrder)
+	GameFlags = 0 + gfRandomOrder
 	Theme = "EarthRise"
 	CaseFreq = 0
 	HealthCaseProb = 0
--- a/share/hedgewars/Data/Scripts/Multiplayer/The_Specialists.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/The_Specialists.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -181,8 +181,7 @@
 end
 
 function onGameInit()
-	ClearGameFlags()
-	EnableGameFlags(gfRandomOrder, gfResetWeps, gfInfAttack, gfPlaceHog, gfPerHogAmmo)
+	GameFlags = gfRandomOrder + gfResetWeps + gfInfAttack + gfPlaceHog +gfPerHogAmmo
 	Delay = 10
 	HealthCaseProb = 100
 end
--- a/share/hedgewars/Data/Scripts/Multiplayer/WxW.lua	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/WxW.lua	Tue Jan 21 22:53:15 2014 +0100
@@ -521,8 +521,7 @@
 
 function onGameInit()
 
-	ClearGameFlags()
-	EnableGameFlags(gfRandomOrder, gfBorder, gfSolidLand) --, gfInfAttack
+	GameFlags = gfRandomOrder + gfBorder + gfSolidLand --+ gfInfAttack
 	HealthCaseProb = 0
 	CaseFreq = 0
 
--- a/share/hedgewars/Data/Scripts/OfficialChallenges.lua	Wed Jan 22 01:11:13 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-function detectMap()
-    if LandDigest == "M838018718Scripts/Multiplayer/Racer.lua" then
-        return("Racer Challenge #1")
-    end
-end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Shaders/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,7 @@
+file(GLOB vertshaders *.vs)
+file(GLOB fragshaders *.fs)
+
+install(FILES
+    ${vertshaders}
+    ${fragshaders}
+    DESTINATION ${SHAREPATH}Data/Shaders)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Shaders/default.fs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,15 @@
+uniform sampler2D tex0;
+uniform vec4 tint;
+uniform bool enableTexture;
+
+varying vec2 tex;
+
+
+void main()
+{
+    if(enableTexture){
+        gl_FragColor = texture2D(tex0, tex) * tint;
+    }else{
+        gl_FragColor = tint;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Shaders/default.vs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,16 @@
+
+
+attribute vec2 vertex;
+attribute vec2 texcoord;
+attribute vec4 colors;
+
+varying vec2 tex;
+
+uniform mat4 mvp;
+
+void main()
+{
+    vec4 p = mvp * vec4(vertex, 0.0, 1.0);
+    gl_Position = p;
+    tex = texcoord;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Shaders/water.fs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,8 @@
+
+varying vec4 vcolor;
+
+
+void main()
+{
+    gl_FragColor = vcolor;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Shaders/water.vs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,15 @@
+
+
+attribute vec2 vertex;
+attribute vec4 color;
+
+varying vec4 vcolor;
+
+uniform mat4 mvp;
+
+void main()
+{
+    vec4 p = mvp * vec4(vertex, 0.0, 1.0);
+    gl_Position = p;
+    vcolor = color;
+}
--- a/share/hedgewars/Data/Themes/Golf/theme.cfg	Wed Jan 22 01:11:13 2014 +0400
+++ b/share/hedgewars/Data/Themes/Golf/theme.cfg	Tue Jan 21 22:53:15 2014 +0100
@@ -1,23 +1,23 @@
-sky = 34, 67, 135
-border = 38, 114, 35
-water-top = 72, 105, 127
-water-bottom = 37, 76, 91
-water-opacity = 128
-music = Golf.ogg
-clouds = 9
-object = Hole, 2, 0, 31, 123, 1, 1, 31, 0, 40, 27
-object = Car, 1, 78, 320, 80, 30, 1, 0, 0, 330, 220
-object = Club, 3, 180, 175, 5, 1, 2, 189, 155, 15, 20, 0, 0, 100, 100
-object = Club2, 1, 126, 26, 1, 1, 2, 0, 0, 20, 30, 240, 23, 15, 10
-object = Flag1, 1, 0, 305, 15, 5, 1, 20, 0, 103, 260
-object = Flag2, 1, 40, 305, 10, 4, 1, 0, 0, 53, 270
-object = Flag3, 1, 0, 280, 12, 7, 1, 30, 0, 112, 260
-object = Flag4, 1, 275, 145, 8, 12, 1, 0, 0, 250, 158
-object = Tee, 2, 6, 20, 2, 2, 1, 0, 0, 12, 15
-object = Ball, 4, 8, 15, 2, 1, 1, 0, 0, 16, 8
-object = Ball, 3, 0, 0, 6, 16, 1, 10, 0, 6, 16
-object = Ball, 3, 10, 0, 6, 16, 1, 0, 0, 6, 16
-object = Bag, 1, 65, 0, 129, 44, 1, 0, 71, 234, 81
-spray = Balldirt, 5
-flakes = 55, 40, 99999999, 30, 200
-
+sky = 34, 67, 135
+border = 38, 114, 35
+water-top = 72, 105, 127
+water-bottom = 37, 76, 91
+water-opacity = 128
+music = Golf.ogg
+clouds = 9
+object = Hole, 2, 0, 31, 123, 1, 1, 31, 0, 40, 27
+object = Car, 1, 78, 320, 80, 30, 1, 0, 0, 330, 220
+object = Club, 3, 180, 175, 5, 1, 2, 189, 155, 15, 20, 0, 0, 100, 100
+object = Club2, 1, 126, 26, 1, 1, 2, 0, 0, 20, 30, 240, 23, 15, 10
+object = Flag1, 1, 0, 305, 15, 5, 1, 20, 0, 103, 260
+object = Flag2, 1, 40, 305, 10, 4, 1, 0, 0, 53, 270
+object = Flag3, 1, 0, 280, 12, 7, 1, 30, 0, 112, 260
+object = Flag4, 1, 275, 145, 8, 12, 1, 0, 0, 250, 158
+object = Tee, 2, 6, 20, 2, 2, 1, 0, 0, 12, 15
+object = Ball, 4, 8, 15, 2, 1, 1, 0, 0, 16, 8
+object = Ball, 3, 0, 0, 6, 16, 1, 10, 0, 6, 16
+object = Ball, 3, 10, 0, 6, 16, 1, 0, 0, 6, 16
+object = Bag, 1, 65, 0, 129, 44, 1, 0, 71, 234, 81
+spray = Balldirt, 5
+flakes = 55, 40, 99999999, 30, 200
+
--- a/tests/lua/drillrockets_boom.lua	Wed Jan 22 01:11:13 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-
- -- taken from http://code.google.com/p/hedgewars/wiki/LuaDrawing
- PointsBuffer = ''  -- A string to accumulate points in
- function AddPoint(x, y, width, erase)
-     PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff))
-     if width then
-         width = bor(width,0x80)
-         if erase then
-             width = bor(width,0x40)
-         end
-         PointsBuffer = PointsBuffer .. string.char(width)
-     else
-         PointsBuffer = PointsBuffer .. string.char(0)
-     end
-     if #PointsBuffer > 245 then
-         ParseCommand('draw '..PointsBuffer)
-         PointsBuffer = ''
-     end
- end
- function FlushPoints()
-     if #PointsBuffer > 0 then
-         ParseCommand('draw '..PointsBuffer)
-         PointsBuffer = ''
-     end
- end
-
-
-local ta_pointsize = 63
-local ta_radius = (ta_pointsize * 10 + 6) / 2
-
-local sqrttwo = math.sqrt(2)
-
--- creates round test area
-function AddTestArea(testarea)
-	step = 100
-	xstep = step * testarea["xdir"]
-	ystep = step * testarea["ydir"]
-	x = testarea["x"]
-	y = testarea["y"]
-	if xstep * ystep ~= 0 then
-		xstep = math.floor(xstep / sqrttwo)
-		ystep = math.floor(ystep / sqrttwo)
-	end
-	AddPoint(x, y, ta_pointsize);
-	AddPoint(x + xstep, y + ystep, ta_pointsize, true);
-end
-
--- vertical test areas
-local taa_v1 = {x= 350, y= 400, xdir= 0, ydir= 1}
-local taa_v2 = {x= 350, y=1500, xdir= 0, ydir=-1}
--- horizontal test areas
-local taa_h1 = {x=1150, y= 400, xdir= 1, ydir= 0}
-local taa_h2 = {x=1200, y=1100, xdir=-1, ydir= 0}
--- diagonal test areas
-local taa_d1 = {x=2200, y= 400, xdir= 1, ydir= 1}
-local taa_d2 = {x=2000, y=1500, xdir= 1, ydir=-1}
-local taa_d3 = {x=3300, y= 400, xdir=-1, ydir= 1}
-local taa_d4 = {x=3300, y=1500, xdir=-1, ydir=-1}
-
--- fail counter
-local nfailed = 0
-local nspawned = 0
-local ndied = 0
-
-function onGameInit()
-	-- At first we have to overwrite/set some global variables
-	-- that define the map, the game has to load, as well as
-	-- other things such as the game rules to use, etc.
-	-- Things we don't modify here will use their default values.
-
-	-- The base number for the random number generator
-	Seed = 1
-	-- The map to be played
-	MapGen = 2
-	-- The theme to be used
-	Theme = "Bamboo"
-	-- Game settings and rules
-	EnableGameFlags(gfOneClanMode, gfDisableWind, gfDisableLandObjects, gfDisableGirders, gfSolidLand)
-	CaseFreq = 0
-	MinesNum = 0
-	Explosives = 0
-
-	-- No damage please
-	DamagePercent = 1
-
-	-- Draw Map
-	AddPoint(10,30,0) -- hog spawn platform
-	-- test areas
-	AddTestArea(taa_v1)
-	AddTestArea(taa_v2)
-	AddTestArea(taa_h1)
-	AddTestArea(taa_h2)
-	AddTestArea(taa_d1)
-	AddTestArea(taa_d2)
-	AddTestArea(taa_d3)
-	AddTestArea(taa_d4)
-
-	FlushPoints()
-
-	-- Create the player team
-	AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default")
-	-- And add a hog to it
-	player = AddHog("Hunter", 0, 1, "NoHat")
-	-- place it on how spawn platform
-	SetGearPosition(player, 10, 10)
-end
-
--- xdir/ydir is direction in which to fire the drills
-function SpawnDrillRocketArray(testarea)
-	xdir = testarea["xdir"]
-	ydir = testarea["ydir"]
-	centerx = testarea["x"]
-	centery = testarea["y"]
-	distance = 23
-	d = distance
-	radius = ta_radius
-	speed = 900000;
-	local xmin, xmax, ymin, ymax
-	if (xdir ~= 0) and (ydir ~= 0) then
-		d = d / sqrttwo
-		radius = radius / sqrttwo
-		speed = math.floor(speed / sqrttwo)
-	end
-	centerx = centerx - (xdir * (radius + 20))
-	centery = centery - (ydir * (radius + 20))
-	radius = radius - 6
-	xn = ydir
-	yn = -xdir
-	startx = centerx - (radius * xn)
-	starty = centery - (radius * yn)
-	endx = centerx + (radius * xn)
-	endy = centery + (radius * yn)
-
-	-- spawn loop
-	x = startx
-	y = starty
-	xd = d * xn
-	yd = d * yn
-	if (xd < 0) and (startx < endx) then x = endx end
-	if (yd < 0) and (starty < endy) then y = endy end
-	nsteps = math.floor(math.max(math.abs(startx - endx),math.abs(starty - endy)) / d)
-	for i = 1, nsteps, 1 do
-		AddGear(math.floor(x), math.floor(y), gtDrill, gsttmpFlag * (i % 2), speed * xdir, speed * ydir, 0)
-		nspawned = nspawned + 1
-		x = x + xd
-		y = y + yd
-	end
-end
-
-function onGearDelete(gear)
-	if GetGearType(gear) == gtDrill then
-		-- the way to check state will change in API at some point
-		if band(GetState(gear), gsttmpFlag) == 0 then
-			-- regular drill rocket
-			if (GetTimer(gear) < 2000) or (GetTimer(gear) > 3000) then
-				nfailed = nfailed + 1
-			end
-		else
-			-- airstrike drill rocket
-			if GetTimer(gear) > 0 then
-				nfailed = nfailed + 1
-			end
-		end
-		ndied = ndied + 1
-		if ndied == nspawned then
-			WriteLnToConsole('TESTRESULT: ' .. nfailed .. ' of ' .. nspawned .. ' drill rockets did not explode as expected')
-			if (nfailed > 0) then
-				EndLuaTest(TEST_FAILED)
-			else
-				EndLuaTest(TEST_SUCCESSFUL)
-			end
-		end
-	end
-end
-
-function onGameStart()
-	SetGravity(1)
-
-	SpawnDrillRocketArray(taa_h1)
-	SpawnDrillRocketArray(taa_h2)
-	SpawnDrillRocketArray(taa_v1)
-	SpawnDrillRocketArray(taa_v2)
-	SpawnDrillRocketArray(taa_d1)
-	SpawnDrillRocketArray(taa_d2)
-	SpawnDrillRocketArray(taa_d3)
-	SpawnDrillRocketArray(taa_d4)
-end
-
--- a/tests/lua/drillrockets_drill.lua	Wed Jan 22 01:11:13 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-
- -- taken from http://code.google.com/p/hedgewars/wiki/LuaDrawing
- PointsBuffer = ''  -- A string to accumulate points in
- function AddPoint(x, y, width, erase)
-     PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff))
-     if width then
-         width = bor(width,0x80)
-         if erase then
-             width = bor(width,0x40)
-         end
-         PointsBuffer = PointsBuffer .. string.char(width)
-     else
-         PointsBuffer = PointsBuffer .. string.char(0)
-     end
-     if #PointsBuffer > 245 then
-         ParseCommand('draw '..PointsBuffer)
-         PointsBuffer = ''
-     end
- end
- function FlushPoints()
-     if #PointsBuffer > 0 then
-         ParseCommand('draw '..PointsBuffer)
-         PointsBuffer = ''
-     end
- end
-
-
-local ta_pointsize = 63
-local ta_radius = (ta_pointsize * 10 + 6) / 2
-
--- creates round test area
-function AddTestArea(testarea)
-	step = 200
-	xstep = step * testarea["xdir"]
-	ystep = step * testarea["ydir"]
-	x = testarea["x"]
-	y = testarea["y"]
-	AddPoint(x, y, ta_pointsize);
-	AddPoint(x + xstep, y + ystep);
-end
-
--- vertical test areas
-local taa_v1 = {x= 350, y= 400, xdir= 0, ydir= 1}
-local taa_v2 = {x= 350, y=1500, xdir= 0, ydir=-1}
--- horizontal test areas
-local taa_h1 = {x=1150, y= 400, xdir= 1, ydir= 0}
-local taa_h2 = {x=1200, y=1100, xdir=-1, ydir= 0}
--- diagonal test areas
-local taa_d1 = {x=2200, y= 400, xdir= 1, ydir= 1}
-local taa_d2 = {x=2000, y=1500, xdir= 1, ydir=-1}
-local taa_d3 = {x=3300, y= 400, xdir=-1, ydir= 1}
-local taa_d4 = {x=3300, y=1500, xdir=-1, ydir=-1}
-
--- fail counter
-local nfailed = 0
-local nspawned = 0
-local ndied = 0
-
-function onGameInit()
-	-- At first we have to overwrite/set some global variables
-	-- that define the map, the game has to load, as well as
-	-- other things such as the game rules to use, etc.
-	-- Things we don't modify here will use their default values.
-
-	-- The base number for the random number generator
-	Seed = 1
-	-- The map to be played
-	MapGen = 2
-	-- The theme to be used
-	Theme = "Bamboo"
-	-- Game settings and rules
-	EnableGameFlags(gfOneClanMode, gfDisableWind, gfDisableLandObjects, gfDisableGirders, gfSolidLand)
-	CaseFreq = 0
-	MinesNum = 0
-	Explosives = 0
-
-	-- No damage please
-	DamagePercent = 1
-
-	-- Draw Map
-	AddPoint(10,30,0) -- hog spawn platform
-	-- test areas
-	AddTestArea(taa_v1)
-	AddTestArea(taa_v2)
-	AddTestArea(taa_h1)
-	AddTestArea(taa_h2)
-	AddTestArea(taa_d1)
-	AddTestArea(taa_d2)
-	AddTestArea(taa_d3)
-	AddTestArea(taa_d4)
-
-	FlushPoints()
-
-	-- Create the player team
-	AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default")
-	-- And add a hog to it
-	player = AddHog("Hunter", 0, 1, "NoHat")
-	-- place it on how spawn platform
-	SetGearPosition(player, 10, 10)
-end
-
--- xdir/ydir is direction in which to fire the drills
-function SpawnDrillRocketArray(testarea)
-	xdir = testarea["xdir"]
-	ydir = testarea["ydir"]
-	centerx = testarea["x"]
-	centery = testarea["y"]
-	distance = 23
-	d = distance
-	radius = ta_radius
-	local xmin, xmax, ymin, ymax
-	speed = 900000;
-	local xmin, xmax, ymin, ymax
-	if (xdir ~= 0) and (ydir ~= 0) then
-		sqrttwo = math.sqrt(2)
-		d = d / sqrttwo
-		radius = radius / sqrttwo
-		speed = math.floor(speed / sqrttwo)
-	end
-	centerx = centerx - (xdir * (radius + 20))
-	centery = centery - (ydir * (radius + 20))
-	radius = radius - 6
-	xn = ydir
-	yn = -xdir
-	startx = centerx - (radius * xn)
-	starty = centery - (radius * yn)
-	endx = centerx + (radius * xn)
-	endy = centery + (radius * yn)
-
-	-- spawn loop
-	x = startx
-	y = starty
-	xd = d * xn
-	yd = d * yn
-	if (xd < 0) and (startx < endx) then x = endx end
-	if (yd < 0) and (starty < endy) then y = endy end
-	nsteps = math.floor(math.max(math.abs(startx - endx),math.abs(starty - endy)) / d)
-	for i = 1, nsteps, 1 do
-		AddGear(math.floor(x), math.floor(y), gtDrill, 0, speed * xdir, speed * ydir, 0)
-		nspawned = nspawned + 1
-		x = x + xd
-		y = y + yd
-	end
-end
-
-function onGearDelete(gear)
-	if GetGearType(gear) == gtDrill then
-		if GetTimer(gear) > 0 then
-			nfailed = nfailed + 1
-		end
-		ndied = ndied + 1
-		if ndied == nspawned then
-			WriteLnToConsole('TESTRESULT: ' .. nfailed .. ' of ' .. nspawned .. ' drill rockets exploded prematurely')
-			if (nfailed > 0) then
-				EndLuaTest(TEST_FAILED)
-			else
-				EndLuaTest(TEST_SUCCESSFUL)
-			end
-		end
-	end
-end
-
-function onGameStart()
-	SetGravity(1)
-
-	SpawnDrillRocketArray(taa_h1)
-	SpawnDrillRocketArray(taa_h2)
-	SpawnDrillRocketArray(taa_v1)
-	SpawnDrillRocketArray(taa_v2)
-	SpawnDrillRocketArray(taa_d1)
-	SpawnDrillRocketArray(taa_d2)
-	SpawnDrillRocketArray(taa_d3)
-	SpawnDrillRocketArray(taa_d4)
-end
-
--- a/tests/lua/luaAPI/gravity_get_set.lua	Wed Jan 22 01:11:13 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-
-
--- * let grenade fall
--- * after a second capture fall distance
--- * change gravity value every second and see if the fall distance in the
---   following second is about what we'd expect it to be
-
-local spawnX = 10
-local spawnY = -500
-
-local defaultG = nil
-local currentG = nil
-
-local defaultDY = nil
-local expectedY = nil
-
-local testGs = nil
-
-local nFails = 0
-
-function onGameInit()
-
-
-	-- The base number for the random number generator
-	Seed = 1
-	-- The map to be played
-	Map = "Ruler"
-	-- The theme to be used
-	Theme = "Bamboo"
-	-- Game settings and rules
-	EnableGameFlags(gfOneClanMode, gfInvulnerable)
-	CaseFreq = 0
-	MinesNum = 0
-	Explosives = 0
-
-	-- Create the player team
-	AddTeam("O_o", 14483456, "Simple", "Island", "Default")
-	-- And add a hog to it
-	player = AddHog("o_O", 0, 1, "NoHat")
-	SetGearPosition(player, 100, 100)
-end
-
-local tol = 0
-
-function IsKindaSame(a, b)
-	tol = 1 + math.max(1,math.abs(currentG) / 100)
-	return (a >= b-tol) and (a <= b+tol)
-end
-
-function SpawnGrenade()
-	AddGear(spawnX, spawnY, gtGrenade, 0, 0, 0, 1000)
-end
-
-local gIdx = 1
-
-function onGearDelete(gear)
-	if GetGearType(gear) ~= gtGrenade then
-		return
-	end
-
-	-- catch initial measuring drop
-	if defaultDY == nil then
-		defaultDY = GetY(gear) - spawnY
-	elseif not IsKindaSame(GetY(gear), expectedY) then
-		nFails = nFails + 1
-		WriteLnToConsole("FAIL: Unexpected Y position! " .. GetY(gear) .. " returned, expected " .. expectedY .. ' (max tolerated difference = ' .. tol .. ')')
-	else
-		WriteLnToConsole("Y position OK! " .. GetY(gear) .. " returned, expected " .. expectedY .. ' (max tolerated difference = ' .. tol .. ')')
-	end
-
-	returnedG = GetGravity()
-	if (returnedG ~= currentG) then
-		WriteLnToConsole("GetGravity did not return the value that we used with SetGravity! " .. returnedG .. " returned, expected " .. currentG)
-		nFails = nFails + 1
-	end
-
-	currentG = testGs[gIdx]
-	gIdx = gIdx + 1
-	-- after last test
-	if currentG == nil then
-		if (nFails > 0) then
-			EndLuaTest(TEST_FAILED)
-		else
-			EndLuaTest(TEST_SUCCESSFUL)
-		end
-	end
-
-	WriteLnToConsole("SetGravity(" .. currentG .. ") ...")
-	SetGravity(currentG)
-
-	SpawnGrenade()
-	expectedY = spawnY + math.floor(currentG * defaultDY / 100)
-end
-
-function onGameStart()
-	currentG = 100
-	defaultG = GetGravity()
-	if (defaultG ~= 100) then
-		WriteLnToConsole("GetGravity did not return 100 at game start")
-		nFails = 1
-	end
-
-	SpawnGrenade()
-
-	testGs = {150, 200, 300, 10, 1, 13, 15, 0, 27, -600, -10, nil}
-end
-
--- a/tools/build_windows.bat	Wed Jan 22 01:11:13 2014 +0400
+++ b/tools/build_windows.bat	Tue Jan 21 22:53:15 2014 +0100
@@ -1,65 +1,65 @@
-@echo off
-::edit these variables if you need
-set PASCAL=C:\FPC\2.6.0\bin\i386-win32\
-set QTDIR=C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin
-set PATH=%PATH%;%PASCAL%
-set BUILD_TYPE="Debug"
-
-:setup
-set CURRDIR="%CD%"
-cd ..
-
-echo Fetching all DLLs...
-if %BUILD_TYPE%=="Debug" (
-    for %%G in (QtCored4 QtGuid4 QtNetworkd4) do xcopy /d/y %QTDIR%\%%G.dll %CD%\bin\
-)
-:: should you libgcc dynamically you should try adding libgcc_s_dw2-1 and mingwm10
-for %%G in (QtCore4 QtGui4 QtNetwork4) do (
-    xcopy /d/y %QTDIR%\%%G.dll %CD%\bin\
-)
-
-if not exist %CD%\misc\winutils\bin\ mkdir %CD%\misc\winutils\bin\
-if not exist %CD%\misc\winutils\bin\SDL.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://www.libsdl.org/release/SDL-1.2.15-win32.zip %CD%\misc\winutils\bin
-if not exist %CD%\misc\winutils\bin\SDL_image.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.12-win32.zip %CD%\misc\winutils\bin
-if not exist %CD%\misc\winutils\bin\SDL_net.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://www.libsdl.org/projects/SDL_net/release/SDL_net-1.2.8-win32.zip %CD%\misc\winutils\bin
-if not exist %CD%\misc\winutils\bin\SDL_mixer.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-1.2.12-win32.zip %CD%\misc\winutils\bin
-if not exist %CD%\misc\winutils\bin\SDL_ttf.dll cscript %CD%\tools\w32DownloadUnzip.vbs  http://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.11-win32.zip %CD%\misc\winutils\bin
-
-::for video recording
-if not exist %CD%\misc\winutils\bin\avformat-54.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://hedgewars.googlecode.com/files/libav-win32-20121022-dll.zip %CD%\misc\winutils\bin
-if not exist %CD%\misc\winutils\bin\glut32.dll cscript %CD%\tools\w32DownloadUnzip.vbs https://user.xmission.com/~nate/glut/glut-3.7.6-bin.zip %CD%\misc\winutils\bin
-copy /y %CD%\misc\winutils\bin\glut-3.7.6-bin\glut32.dll %CD%\misc\winutils\bin\glut32.dll
-
-::this is needed because fpc png unit hardcodes libpng-1.2.12
-if not exist %CD%\misc\winutils\bin\libpng13.dll copy /y %CD%\misc\winutils\bin\libpng15-15.dll %CD%\misc\winutils\bin\libpng13.dll
-
-xcopy /d/y %CD%\misc\winutils\bin\*.dll %CD%\bin\
-
-::setting up the environment...
-call %QTDIR%\qtenv2.bat
-
-echo Running cmake...
-set ERRORLEVEL=
-cmake . -G "MinGW Makefiles" -DPNG_LIBRARY="%CD%\misc\winutils\bin\libpng13.dll" -DCMAKE_BUILD_TYPE="%BUILD_TYPE%" -DCMAKE_PREFIX_PATH="%CD%\misc\winutils\\"
-:: prefix should be last
-
-if %ERRORLEVEL% NEQ 0 goto exitpoint
-
-echo Running make...
-set ERRORLEVEL=
-mingw32-make VERBOSE=1
-if %ERRORLEVEL% NEQ 0 goto exitpoint
-
-echo Installing...
-set ERRORLEVEL=
-mingw32-make install > nul
-if %ERRORLEVEL% NEQ 0 goto exitpoint
-
-echo Creating commodity shortcut...
-copy /y %CD%\misc\winutils\Hedgewars.lnk C:%HOMEPATH%\Desktop\Hedgewars.lnk
-
-echo ALL DONE, Hedgewars has been successfully compiled and installed
-
-:exitpoint
-cd %CURRDIR%
-pause
+@echo off
+::edit these variables if you need
+set PASCAL=C:\FPC\2.6.0\bin\i386-win32\
+set QTDIR=C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin
+set PATH=%PATH%;%PASCAL%
+set BUILD_TYPE="Debug"
+
+:setup
+set CURRDIR="%CD%"
+cd ..
+
+echo Fetching all DLLs...
+if %BUILD_TYPE%=="Debug" (
+    for %%G in (QtCored4 QtGuid4 QtNetworkd4) do xcopy /d/y %QTDIR%\%%G.dll %CD%\bin\
+)
+:: should you libgcc dynamically you should try adding libgcc_s_dw2-1 and mingwm10
+for %%G in (QtCore4 QtGui4 QtNetwork4) do (
+    xcopy /d/y %QTDIR%\%%G.dll %CD%\bin\
+)
+
+if not exist %CD%\misc\winutils\bin\ mkdir %CD%\misc\winutils\bin\
+if not exist %CD%\misc\winutils\bin\SDL.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://www.libsdl.org/release/SDL-1.2.15-win32.zip %CD%\misc\winutils\bin
+if not exist %CD%\misc\winutils\bin\SDL_image.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.12-win32.zip %CD%\misc\winutils\bin
+if not exist %CD%\misc\winutils\bin\SDL_net.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://www.libsdl.org/projects/SDL_net/release/SDL_net-1.2.8-win32.zip %CD%\misc\winutils\bin
+if not exist %CD%\misc\winutils\bin\SDL_mixer.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-1.2.12-win32.zip %CD%\misc\winutils\bin
+if not exist %CD%\misc\winutils\bin\SDL_ttf.dll cscript %CD%\tools\w32DownloadUnzip.vbs  http://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.11-win32.zip %CD%\misc\winutils\bin
+
+::for video recording
+if not exist %CD%\misc\winutils\bin\avformat-54.dll cscript %CD%\tools\w32DownloadUnzip.vbs http://hedgewars.googlecode.com/files/libav-win32-20121022-dll.zip %CD%\misc\winutils\bin
+if not exist %CD%\misc\winutils\bin\glut32.dll cscript %CD%\tools\w32DownloadUnzip.vbs https://user.xmission.com/~nate/glut/glut-3.7.6-bin.zip %CD%\misc\winutils\bin
+copy /y %CD%\misc\winutils\bin\glut-3.7.6-bin\glut32.dll %CD%\misc\winutils\bin\glut32.dll
+
+::this is needed because fpc png unit hardcodes libpng-1.2.12
+if not exist %CD%\misc\winutils\bin\libpng13.dll copy /y %CD%\misc\winutils\bin\libpng15-15.dll %CD%\misc\winutils\bin\libpng13.dll
+
+xcopy /d/y %CD%\misc\winutils\bin\*.dll %CD%\bin\
+
+::setting up the environment...
+call %QTDIR%\qtenv2.bat
+
+echo Running cmake...
+set ERRORLEVEL=
+cmake . -G "MinGW Makefiles" -DPNG_LIBRARY="%CD%\misc\winutils\bin\libpng13.dll" -DCMAKE_BUILD_TYPE="%BUILD_TYPE%" -DCMAKE_PREFIX_PATH="%CD%\misc\winutils\\"
+:: prefix should be last
+
+if %ERRORLEVEL% NEQ 0 goto exitpoint
+
+echo Running make...
+set ERRORLEVEL=
+mingw32-make VERBOSE=1
+if %ERRORLEVEL% NEQ 0 goto exitpoint
+
+echo Installing...
+set ERRORLEVEL=
+mingw32-make install > nul
+if %ERRORLEVEL% NEQ 0 goto exitpoint
+
+echo Creating commodity shortcut...
+copy /y %CD%\misc\winutils\Hedgewars.lnk C:%HOMEPATH%\Desktop\Hedgewars.lnk
+
+echo ALL DONE, Hedgewars has been successfully compiled and installed
+
+:exitpoint
+cd %CURRDIR%
+pause
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/CMakeLists.txt	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,31 @@
+find_package(GHC REQUIRED)
+
+set(pas2c_sources
+        Main.hs
+        PascalBasics.hs
+        PascalParser.hs
+        PascalPreprocessor.hs
+        PascalUnitSyntaxTree.hs
+        Pas2C.hs
+    )
+
+set(pas2c_main ${CMAKE_SOURCE_DIR}/tools/pas2c/Main.hs)
+
+set(ghc_flags
+        --make ${pas2c_main}
+        -i${CMAKE_SOURCE_DIR}/tools/pas2c/
+        -o ${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}
+        -odir ${CMAKE_CURRENT_BINARY_DIR}
+        -hidir ${CMAKE_CURRENT_BINARY_DIR}
+        ${haskell_flags}
+    )
+
+add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}"
+        COMMAND "${GHC_EXECUTABLE}"
+        ARGS ${ghc_flags}
+        MAIN_DEPENDENCY ${hwserv_main}
+        DEPENDS ${hwserver_sources}
+        )
+
+add_custom_target(pas2c ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/pas2c${CMAKE_EXECUTABLE_SUFFIX}")
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/Main.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,82 @@
+module Main( main ) where
+
+import System.Console.GetOpt
+import System.Environment
+import System.Exit
+import System.IO
+import Data.Maybe( fromMaybe, isJust, fromJust )
+import Data.List (find, intercalate)
+import Control.Monad
+import Pas2C
+
+main = do
+    args <- getArgs
+    if length args == 0
+    then do
+        name <- getProgName
+        hPutStrLn stderr $ usageInfo header options
+        exitFailure
+    else do
+        case getOpt RequireOrder options args of
+          (flags, [],      []) | enoughFlags flags -> do
+                let m = flag flags isName
+                let i = flag flags isInput
+                let o = flag flags isOutput
+                let a = fromMaybe o $ liftM extractString $ find isAlt flags
+                let symbols = ["PAS2C", "FPC"] ++ (map extractString $ filter isSymbol flags)
+                hPutStrLn stdout $ "--------Pas2C Config--------"
+                hPutStrLn stdout $ "Main module: " ++ m
+                hPutStrLn stdout $ "Input path : " ++ i
+                hPutStrLn stdout $ "Output path: " ++ o
+                hPutStrLn stdout $ "Altern path: " ++ a
+                hPutStrLn stdout $ "Symbols defined: " ++ (intercalate ", " symbols)
+                hPutStrLn stdout $ "----------------------------"
+                pas2C m (i++"/") (o++"/") (a++"/") symbols
+                hPutStrLn stdout $ "----------------------------"
+                      | otherwise ->  error $ usageInfo header options
+          (_,     nonOpts, [])     -> error $ "unrecognized arguments: " ++ unwords nonOpts
+          (_,     _,       msgs)   -> error $ usageInfo header options
+    where
+        header = "Freepascal to C conversion! Please specify -n -i -o options.\n"
+        enoughFlags f = and $ map (isJust . flip find f) [isName, isInput, isOutput]
+        flag f = extractString . fromJust . flip find f
+
+
+data Flag = HelpMessage
+          | Name String
+          | Input String
+          | Output String
+          | Alternate String
+          | Symbol String
+
+
+extractString :: Flag -> String
+extractString (Name s) = s
+extractString (Input s) = s
+extractString (Output s) = s
+extractString (Alternate s) = s
+extractString (Symbol s) = s
+extractString _ = undefined
+
+isName, isInput, isOutput, isAlt, isSymbol :: Flag -> Bool
+isName (Name _) = True
+isName _ = False
+isInput (Input _) = True
+isInput _ = False
+isOutput (Output _) = True
+isOutput _ = False
+isAlt (Alternate _) = True
+isAlt _ = False
+isSymbol (Symbol _) = True
+isSymbol _ = False
+
+options :: [OptDescr Flag]
+options = [
+    Option ['h'] ["help"]      (NoArg HelpMessage)      "print this help message",
+    Option ['n'] ["name"]      (ReqArg Name "MAIN")     "name of the main Pascal module",
+    Option ['i'] ["input"]     (ReqArg Input "DIR")     "input directory, where .pas files will be read",
+    Option ['o'] ["output"]    (ReqArg Output "DIR")    "output directory, where .c/.h files will be written",
+    Option ['a'] ["alternate"] (ReqArg Alternate "DIR") "alternate input directory, for out of source builds",
+    Option ['d'] ["define"]    (ReqArg Symbol "SYMBOL") "define symbol"
+  ]
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/Pas2C.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,1174 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+module Pas2C where
+
+import Text.PrettyPrint.HughesPJ
+import Data.Maybe
+import Data.Char
+import Text.Parsec.Prim hiding (State)
+import Control.Monad.State
+import System.IO
+import System.Directory
+import Control.Monad.IO.Class
+import PascalPreprocessor
+import Control.Exception
+import System.IO.Error
+import qualified Data.Map as Map
+import qualified Data.Set as Set
+import Data.List (find)
+import Numeric
+
+import PascalParser(pascalUnit)
+import PascalUnitSyntaxTree
+
+
+data InsertOption =
+    IOInsert
+    | IOInsertWithType Doc
+    | IOLookup
+    | IOLookupLast
+    | IOLookupFunction Int
+    | IODeferred
+
+data Record = Record
+    {
+        lcaseId :: String,
+        baseType :: BaseType,
+        typeDecl :: Doc
+    }
+    deriving Show
+type Records = Map.Map String [Record]
+data RenderState = RenderState
+    {
+        currentScope :: Records,
+        lastIdentifier :: String,
+        lastType :: BaseType,
+        isFunctionType :: Bool, -- set to true if the current function parameter is functiontype
+        lastIdTypeDecl :: Doc,
+        stringConsts :: [(String, String)],
+        uniqCounter :: Int,
+        toMangle :: Set.Set String,
+        enums :: [(String, [String])], -- store all declared enums
+        currentUnit :: String,
+        currentFunctionResult :: String,
+        namespaces :: Map.Map String Records
+    }
+
+rec2Records = map (\(a, b) -> Record a b empty)
+
+emptyState = RenderState Map.empty "" BTUnknown False empty [] 0 Set.empty [] "" ""
+
+getUniq :: State RenderState Int
+getUniq = do
+    i <- gets uniqCounter
+    modify(\s -> s{uniqCounter = uniqCounter s + 1})
+    return i
+
+addStringConst :: String -> State RenderState Doc
+addStringConst str = do
+    strs <- gets stringConsts
+    let a = find ((==) str . snd) strs
+    if isJust a then
+        do
+        modify (\s -> s{lastType = BTString})
+        return . text . fst . fromJust $ a
+    else
+        do
+        i <- getUniq
+        let sn = "__str" ++ show i
+        modify (\s -> s{lastType = BTString, stringConsts = (sn, str) : strs})
+        return $ text sn
+
+escapeStr :: String -> String
+escapeStr = foldr escapeChar []
+
+escapeChar :: Char -> ShowS
+escapeChar '"' s = "\\\"" ++ s
+escapeChar '\\' s = "\\\\" ++ s
+escapeChar a s = a : s
+
+strInit :: String -> Doc
+strInit a = text "STRINIT" <> parens (doubleQuotes (text $ escapeStr a))
+
+renderStringConsts :: State RenderState Doc
+renderStringConsts = liftM (vcat . map (\(a, b) -> text "static const string255" <+> (text a) <+> text "=" <+> strInit b <> semi))
+    $ gets stringConsts
+
+docToLower :: Doc -> Doc
+docToLower = text . map toLower . render
+
+pas2C :: String -> String -> String -> String -> [String] -> IO ()
+pas2C fn inputPath outputPath alternateInputPath symbols = do
+    s <- flip execStateT initState $ f fn
+    renderCFiles s outputPath
+    where
+    printLn = liftIO . hPutStrLn stdout
+    print = liftIO . hPutStr stdout
+    initState = Map.empty
+    f :: String -> StateT (Map.Map String PascalUnit) IO ()
+    f fileName = do
+        processed <- gets $ Map.member fileName
+        unless processed $ do
+            print ("Preprocessing '" ++ fileName ++ ".pas'... ")
+            fc' <- liftIO
+                $ tryJust (guard . isDoesNotExistError)
+                $ preprocess inputPath alternateInputPath (fileName ++ ".pas") symbols
+            case fc' of
+                (Left a) -> do
+                    modify (Map.insert fileName (System []))
+                    printLn "doesn't exist"
+                (Right fc) -> do
+                    print "ok, parsing... "
+                    let ptree = parse pascalUnit fileName fc
+                    case ptree of
+                         (Left a) -> do
+                            liftIO $ writeFile (outputPath ++ "preprocess.out") fc
+                            printLn $ show a ++ "\nsee preprocess.out for preprocessed source"
+                            fail "stop"
+                         (Right a) -> do
+                            printLn "ok"
+                            modify (Map.insert fileName a)
+                            mapM_ f (usesFiles a)
+
+
+renderCFiles :: Map.Map String PascalUnit -> String -> IO ()
+renderCFiles units outputPath = do
+    let u = Map.toList units
+    let nss = Map.map (toNamespace nss) units
+    --hPutStrLn stderr $ "Units: " ++ (show . Map.keys . Map.filter (not . Map.null) $ nss)
+    --writeFile "pas2c.log" $ unlines . map (\t -> show (fst t) ++ "\n" ++ (unlines . map ((:) '\t' . show) . snd $ t)) . Map.toList $ nss
+    mapM_ (toCFiles outputPath nss) u
+    where
+    toNamespace :: Map.Map String Records -> PascalUnit -> Records
+    toNamespace nss (System tvs) =
+        currentScope $ execState f (emptyState nss)
+        where
+        f = do
+            checkDuplicateFunDecls tvs
+            mapM_ (tvar2C True False True False) tvs
+    toNamespace nss (Redo tvs) = -- functions that are re-implemented, add prefix to all of them
+        currentScope $ execState f (emptyState nss){currentUnit = "fpcrtl_"}
+        where
+        f = do
+            checkDuplicateFunDecls tvs
+            mapM_ (tvar2C True False True False) tvs
+    toNamespace _ (Program {}) = Map.empty
+    toNamespace nss (Unit (Identifier i _) interface _ _ _) =
+        currentScope $ execState (interface2C interface True) (emptyState nss){currentUnit = map toLower i ++ "_"}
+
+withState' :: (RenderState -> RenderState) -> State RenderState a -> State RenderState a
+withState' f sf = do
+    st <- liftM f get
+    let (a, s) = runState sf st
+    modify(\st -> st{
+        lastType = lastType s
+        , uniqCounter = uniqCounter s
+        , stringConsts = stringConsts s
+        })
+    return a
+
+withLastIdNamespace f = do
+    li <- gets lastIdentifier
+    nss <- gets namespaces
+    withState' (\st -> st{currentScope = fromMaybe Map.empty $ Map.lookup li (namespaces st)}) f
+
+withRecordNamespace :: String -> [Record] -> State RenderState Doc -> State RenderState Doc
+withRecordNamespace _ [] = error "withRecordNamespace: empty record"
+withRecordNamespace prefix recs = withState' f
+    where
+        f st = st{currentScope = Map.unionWith un records (currentScope st), currentUnit = ""}
+        records = Map.fromList $ map (\(Record a b d) -> (map toLower a, [Record (prefix ++ a) b d])) recs
+        un [a] b = a : b
+
+toCFiles :: String -> Map.Map String Records -> (String, PascalUnit) -> IO ()
+toCFiles _ _ (_, System _) = return ()
+toCFiles _ _ (_, Redo _) = return ()
+toCFiles outputPath ns p@(fn, pu) = do
+    hPutStrLn stdout $ "Rendering '" ++ fn ++ "'..."
+    toCFiles' p
+    where
+    toCFiles' (fn, p@(Program {})) = writeFile (outputPath ++ fn ++ ".c") $ "#include \"fpcrtl.h\"\n" ++ (render2C initialState . pascal2C) p
+    toCFiles' (fn, (Unit unitId@(Identifier i _) interface implementation _ _)) = do
+        let (a, s) = runState (id2C IOInsert (setBaseType BTUnit unitId) >> interface2C interface True) initialState{currentUnit = map toLower i ++ "_"}
+            (a', s') = runState (id2C IOInsert (setBaseType BTUnit unitId) >> interface2C interface False) initialState{currentUnit = map toLower i ++ "_"}
+            enumDecl = (renderEnum2Strs (enums s) False)
+            enumImpl = (renderEnum2Strs (enums s) True)
+        writeFile (outputPath ++ fn ++ ".h") $ "#pragma once\n\n#include \"pas2c.h\"\n\n" ++ (render (a $+$ text "")) ++ "\n" ++ enumDecl
+        writeFile (outputPath ++ fn ++ ".c") $ "#include \"fpcrtl.h\"\n\n#include \"" ++ fn ++ ".h\"\n" ++ render (a' $+$ text "") ++ (render2C s . implementation2C) implementation ++ "\n" ++ enumImpl
+    initialState = emptyState ns
+
+    render2C :: RenderState -> State RenderState Doc -> String
+    render2C st p =
+        let (a, s) = runState p st in
+        render a
+
+renderEnum2Strs :: [(String, [String])] -> Bool -> String
+renderEnum2Strs enums implement =
+    render $ foldl ($+$) empty $ map (\en -> let d = decl (fst en) in if implement then d $+$ enum2strBlock (snd en) else d <> semi) enums
+    where
+    decl id = text "string255 __attribute__((overloadable)) fpcrtl_GetEnumName" <> parens (text "int dummy, const" <+> text id <+> text "enumvar")
+    enum2strBlock en =
+            text "{"
+            $+$
+            (nest 4 $
+                text "switch(enumvar){"
+                $+$
+                (foldl ($+$) empty $ map (\e -> text "case" <+> text e <> colon $+$ (nest 4 $ text "return fpcrtl_make_string" <> (parens $ doubleQuotes $ text e) <> semi $+$ text "break;")) en)
+                $+$
+                text "default: assert(0);"
+                $+$
+                (nest 4 $ text "return fpcrtl_make_string(\"nonsense\");")
+                $+$
+                text "}"
+            )
+            $+$
+            text "}"
+
+usesFiles :: PascalUnit -> [String]
+usesFiles (Program _ (Implementation uses _) _) = ["pas2cSystem", "pas2cRedo"] ++ uses2List uses
+usesFiles (Unit _ (Interface uses1 _) (Implementation uses2 _) _ _) = ["pas2cSystem", "pas2cRedo"] ++ uses2List uses1 ++ uses2List uses2
+usesFiles (System {}) = []
+usesFiles (Redo {}) = []
+
+pascal2C :: PascalUnit -> State RenderState Doc
+pascal2C (Unit _ interface implementation init fin) =
+    liftM2 ($+$) (interface2C interface True) (implementation2C implementation)
+
+pascal2C (Program _ implementation mainFunction) = do
+    impl <- implementation2C implementation
+    [main] <- tvar2C True False True True (FunctionDeclaration (Identifier "main" (BTInt True)) False False (SimpleType $ Identifier "int" (BTInt True)) [VarDeclaration False False ([Identifier "argc" (BTInt True)], SimpleType (Identifier "Integer" (BTInt True))) Nothing, VarDeclaration False False ([Identifier "argv" BTUnknown], SimpleType (Identifier "PPChar" BTUnknown)) Nothing] (Just (TypesAndVars [], mainFunction)))
+
+    return $ impl $+$ main
+
+
+-- the second bool indicates whether do normal interface translation or generate variable declarations
+-- that will be inserted into implementation files
+interface2C :: Interface -> Bool -> State RenderState Doc
+interface2C (Interface uses tvars) True = do
+    u <- uses2C uses
+    tv <- typesAndVars2C True True True tvars
+    r <- renderStringConsts
+    return (u $+$ r $+$ tv)
+interface2C (Interface uses tvars) False = do
+    u <- uses2C uses
+    tv <- typesAndVars2C True False False tvars
+    r <- renderStringConsts
+    return tv
+
+implementation2C :: Implementation -> State RenderState Doc
+implementation2C (Implementation uses tvars) = do
+    u <- uses2C uses
+    tv <- typesAndVars2C True False True tvars
+    r <- renderStringConsts
+    return (u $+$ r $+$ tv)
+
+checkDuplicateFunDecls :: [TypeVarDeclaration] -> State RenderState ()
+checkDuplicateFunDecls tvs =
+    modify $ \s -> s{toMangle = Map.keysSet . Map.filter (> 1) . foldr ins initMap $ tvs}
+    where
+        initMap = Map.empty
+        --initMap = Map.fromList [("reset", 2)]
+        ins (FunctionDeclaration (Identifier i _) _ _ _ _ _) m = Map.insertWith (+) (map toLower i) 1 m
+        ins _ m = m
+
+-- the second bool indicates whether declare variable as extern or not
+-- the third bool indicates whether include types or not
+
+typesAndVars2C :: Bool -> Bool -> Bool -> TypesAndVars -> State RenderState Doc
+typesAndVars2C b externVar includeType(TypesAndVars ts) = do
+    checkDuplicateFunDecls ts
+    liftM (vcat . map (<> semi) . concat) $ mapM (tvar2C b externVar includeType False) ts
+
+setBaseType :: BaseType -> Identifier -> Identifier
+setBaseType bt (Identifier i _) = Identifier i bt
+
+uses2C :: Uses -> State RenderState Doc
+uses2C uses@(Uses unitIds) = do
+
+    mapM_ injectNamespace (Identifier "pas2cSystem" undefined : unitIds)
+    mapM_ injectNamespace (Identifier "pas2cRedo" undefined : unitIds)
+    mapM_ (id2C IOInsert . setBaseType BTUnit) unitIds
+    return $ vcat . map (\i -> text $ "#include \"" ++ i ++ ".h\"") $ uses2List uses
+    where
+    injectNamespace (Identifier i _) = do
+        getNS <- gets (flip Map.lookup . namespaces)
+        modify (\s -> s{currentScope = Map.unionWith (++) (fromMaybe Map.empty (getNS i)) $ currentScope s})
+
+uses2List :: Uses -> [String]
+uses2List (Uses ids) = map (\(Identifier i _) -> i) ids
+
+
+setLastIdValues vv = (\s -> s{lastType = baseType vv, lastIdentifier = lcaseId vv, lastIdTypeDecl = typeDecl vv})
+
+id2C :: InsertOption -> Identifier -> State RenderState Doc
+id2C IOInsert i = id2C (IOInsertWithType empty) i
+id2C (IOInsertWithType d) (Identifier i t) = do
+    ns <- gets currentScope
+    tom <- gets (Set.member n . toMangle)
+    cu <- gets currentUnit
+    let (i', t') = case (t, tom) of
+            (BTFunction _ p _, True) -> (cu ++ i ++ ('_' : show (length p)), t)
+            (BTFunction _ _ _, _) -> (cu ++ i, t)
+            (BTVarParam t', _) -> ('(' : '*' : i ++ ")" , t')
+            _ -> (i, t)
+    modify (\s -> s{currentScope = Map.insertWith (++) n [Record i' t' d] (currentScope s), lastIdentifier = n})
+    return $ text i'
+    where
+        n = map toLower i
+
+id2C IOLookup i = id2CLookup head i
+id2C IOLookupLast i = id2CLookup last i
+id2C (IOLookupFunction params) (Identifier i t) = do
+    let i' = map toLower i
+    v <- gets $ Map.lookup i' . currentScope
+    lt <- gets lastType
+    if isNothing v then
+        error $ "Not defined: '" ++ i' ++ "'\n" ++ show lt ++ "\nwith num of params = " ++ show params ++ "\n" ++ show v
+        else
+        let vv = fromMaybe (head $ fromJust v) . find checkParam $ fromJust v in
+            modify (setLastIdValues vv) >> (return . text . lcaseId $ vv)
+    where
+        checkParam (Record _ (BTFunction _ p _) _) = (length p) == params
+        checkParam _ = False
+id2C IODeferred (Identifier i t) = do
+    let i' = map toLower i
+    v <- gets $ Map.lookup i' . currentScope
+    if (isNothing v) then
+        modify (\s -> s{lastType = BTUnknown, lastIdentifier = i}) >> return (text i)
+        else
+        let vv = head $ fromJust v in modify (setLastIdValues vv) >> (return . text . lcaseId $ vv)
+
+id2CLookup :: ([Record] -> Record) -> Identifier -> State RenderState Doc
+id2CLookup f (Identifier i t) = do
+    let i' = map toLower i
+    v <- gets $ Map.lookup i' . currentScope
+    lt <- gets lastType
+    if isNothing v then
+        error $ "Not defined: '" ++ i' ++ "'\n" ++ show lt
+        else
+        let vv = f $ fromJust v in modify (setLastIdValues vv) >> (return . text . lcaseId $ vv)
+
+
+
+id2CTyped :: TypeDecl -> Identifier -> State RenderState Doc
+id2CTyped = id2CTyped2 Nothing
+
+id2CTyped2 :: Maybe Doc -> TypeDecl -> Identifier -> State RenderState Doc
+id2CTyped2 md t (Identifier i _) = do
+    tb <- resolveType t
+    case (t, tb) of
+        (_, BTUnknown) -> do
+            error $ "id2CTyped: type BTUnknown for " ++ show i ++ "\ntype: " ++ show t
+        (SimpleType {}, BTRecord _ r) -> do
+            ts <- type2C t
+            id2C (IOInsertWithType $ ts empty) (Identifier i (BTRecord (render $ ts empty) r))
+        (_, BTRecord _ r) -> do
+            ts <- type2C t
+            id2C (IOInsertWithType $ ts empty) (Identifier i (BTRecord i r))
+        _ -> case md of
+                Nothing -> id2C IOInsert (Identifier i tb)
+                Just ts -> id2C (IOInsertWithType ts) (Identifier i tb)
+
+typeVarDecl2BaseType :: [TypeVarDeclaration] -> State RenderState [(Bool, BaseType)]
+typeVarDecl2BaseType d = do
+    st <- get
+    result <- sequence $ concat $ map resolveType' d
+    put st -- restore state (not sure if necessary)
+    return result
+    where
+        resolveType' :: TypeVarDeclaration -> [State RenderState (Bool, BaseType)]
+        resolveType' (VarDeclaration isVar _ (ids, t) _) = replicate (length ids) (resolveTypeHelper' (resolveType t) isVar)
+        resolveType' _ = error "typeVarDecl2BaseType: not a VarDeclaration"
+        resolveTypeHelper' :: State RenderState BaseType -> Bool -> State RenderState (Bool, BaseType)
+        resolveTypeHelper' st b = do
+            bt <- st
+            return (b, bt)
+
+resolveType :: TypeDecl -> State RenderState BaseType
+resolveType st@(SimpleType (Identifier i _)) = do
+    let i' = map toLower i
+    v <- gets $ Map.lookup i' . currentScope
+    if isJust v then return . baseType . head $ fromJust v else return $ f i'
+    where
+    f "uinteger" = BTInt False
+    f "integer" = BTInt True
+    f "pointer" = BTPointerTo BTVoid
+    f "boolean" = BTBool
+    f "float" = BTFloat
+    f "char" = BTChar
+    f "string" = BTString
+    f _ = error $ "Unknown system type: " ++ show st
+resolveType (PointerTo (SimpleType (Identifier i _))) = return . BTPointerTo $ BTUnresolved (map toLower i)
+resolveType (PointerTo t) = liftM BTPointerTo $ resolveType t
+resolveType (RecordType tv mtvs) = do
+    tvs <- mapM f (concat $ tv : fromMaybe [] mtvs)
+    return . BTRecord "" . concat $ tvs
+    where
+        f :: TypeVarDeclaration -> State RenderState [(String, BaseType)]
+        f (VarDeclaration _ _ (ids, td) _) = mapM (\(Identifier i _) -> liftM ((,) i) $ resolveType td) ids
+resolveType (ArrayDecl (Just i) t) = do
+    t' <- resolveType t
+    return $ BTArray i (BTInt True) t'
+resolveType (ArrayDecl Nothing t) = liftM (BTArray RangeInfinite (BTInt True)) $ resolveType t
+resolveType (FunctionType t a) = do
+    bts <- typeVarDecl2BaseType a
+    liftM (BTFunction False bts) $ resolveType t
+resolveType (DeriveType (InitHexNumber _)) = return (BTInt True)
+resolveType (DeriveType (InitNumber _)) = return (BTInt True)
+resolveType (DeriveType (InitFloat _)) = return BTFloat
+resolveType (DeriveType (InitString _)) = return BTString
+resolveType (DeriveType (InitBinOp {})) = return (BTInt True)
+resolveType (DeriveType (InitPrefixOp _ e)) = initExpr2C e >> gets lastType
+resolveType (DeriveType (BuiltInFunction{})) = return (BTInt True)
+resolveType (DeriveType (InitReference (Identifier{}))) = return BTBool -- TODO: derive from actual type
+resolveType (DeriveType _) = return BTUnknown
+resolveType (String _) = return BTString
+resolveType VoidType = return BTVoid
+resolveType (Sequence ids) = return $ BTEnum $ map (\(Identifier i _) -> map toLower i) ids
+resolveType (RangeType _) = return $ BTVoid
+resolveType (Set t) = liftM BTSet $ resolveType t
+resolveType (VarParamType t) = liftM BTVarParam $ resolveType t
+
+
+resolve :: String -> BaseType -> State RenderState BaseType
+resolve s (BTUnresolved t) = do
+    v <- gets $ Map.lookup t . currentScope
+    if isJust v then
+        resolve s . baseType . head . fromJust $ v
+        else
+        error $ "Unknown type " ++ show t ++ "\n" ++ s
+resolve _ t = return t
+
+fromPointer :: String -> BaseType -> State RenderState BaseType
+fromPointer s (BTPointerTo t) = resolve s t
+fromPointer s t = do
+    error $ "Dereferencing from non-pointer type " ++ show t ++ "\n" ++ s
+
+
+functionParams2C params = liftM (hcat . punctuate comma . concat) $ mapM (tvar2C False False True True) params
+
+numberOfDeclarations :: [TypeVarDeclaration] -> Int
+numberOfDeclarations = sum . map cnt
+    where
+        cnt (VarDeclaration _ _ (ids, _) _) = length ids
+        cnt _ = 1
+
+hasPassByReference :: [TypeVarDeclaration] -> Bool
+hasPassByReference = or . map isVar
+    where
+        isVar (VarDeclaration v _ (_, _) _) = v
+        isVar _ = error $ "hasPassByReference called not on function parameters"
+
+toIsVarList :: [TypeVarDeclaration] -> [Bool]
+toIsVarList = concatMap isVar
+    where
+        isVar (VarDeclaration v _ (p, _) _) = replicate (length p) v
+        isVar _ = error $ "toIsVarList called not on function parameters"
+
+
+funWithVarsToDefine :: String -> [TypeVarDeclaration] -> Doc
+funWithVarsToDefine n params = text "#define" <+> text n <> parens abc <+> text (n ++ "__vars") <> parens cparams
+    where
+        abc = hcat . punctuate comma . map (char . fst) $ ps
+        cparams = hcat . punctuate comma . map (\(c, v) -> if v then char '&' <> parens (char c) else char c) $ ps
+        ps = zip ['a'..] (toIsVarList params)
+
+fun2C :: Bool -> String -> TypeVarDeclaration -> State RenderState [Doc]
+fun2C _ _ (FunctionDeclaration name inline overload returnType params Nothing) = do
+    t <- type2C returnType
+    t'<- gets lastType
+    bts <- typeVarDecl2BaseType params
+    p <- withState' id $ functionParams2C params
+    n <- liftM render . id2C IOInsert $ setBaseType (BTFunction False bts t') name
+    let decor = if overload then text "__attribute__((overloadable))" else empty
+    return [t empty <+> decor <+> text n <> parens p]
+
+fun2C True rv (FunctionDeclaration name@(Identifier i bt) inline overload returnType params (Just (tvars, phrase))) = do
+    let isVoid = case returnType of
+            VoidType -> True
+            _ -> False
+
+    let res = docToLower $ text rv <> if isVoid then empty else text "_result"
+    t <- type2C returnType
+    t' <- gets lastType
+
+    bts <- typeVarDecl2BaseType params
+    cu <- gets currentUnit
+    notDeclared <- liftM isNothing . gets $ Map.lookup (map toLower i) . currentScope
+
+    n <- liftM render . id2C IOInsert $ setBaseType (BTFunction hasVars bts t') name
+    let resultId = if isVoid
+                    then n -- void type doesn't have result, solving recursive procedure calls
+                    else (render res)
+
+    (p, ph) <- withState' (\st -> st{currentScope = Map.insertWith un (map toLower rv) [Record resultId (if isVoid then (BTFunction hasVars bts t') else t') empty] $ currentScope st
+            , currentFunctionResult = if isVoid then [] else render res}) $ do
+        p <- functionParams2C params
+        ph <- liftM2 ($+$) (typesAndVars2C False False True tvars) (phrase2C' phrase)
+        return (p, ph)
+
+    let phrasesBlock = if isVoid then ph else t empty <+> res <> semi $+$ ph $+$ text "return" <+> res <> semi
+    let define = if hasVars then text "#ifndef" <+> text n $+$ funWithVarsToDefine n params $+$ text "#endif" else empty
+    let inlineDecor = if inline then case notDeclared of
+                                    True -> text "static inline"
+                                    False -> text "inline"
+                          else empty
+        overloadDecor = if overload then text "__attribute__((overloadable))" else empty
+    return [
+        --define
+        -- $+$
+        --(if notDeclared && hasVars then funWithVarsToDefine n params else empty) $+$
+        inlineDecor <+> t empty <+> overloadDecor <+> text n <> parens p
+        $+$
+        text "{"
+        $+$
+        nest 4 phrasesBlock
+        $+$
+        text "}"]
+    where
+    phrase2C' (Phrases p) = liftM vcat $ mapM phrase2C p
+    phrase2C' p = phrase2C p
+    un [a] b = a : b
+    hasVars = hasPassByReference params
+
+fun2C False _ (FunctionDeclaration (Identifier name _) _ _ _ _ _) = error $ "nested functions not allowed: " ++ name
+fun2C _ tv _ = error $ "fun2C: I don't render " ++ show tv
+
+-- the second bool indicates whether declare variable as extern or not
+-- the third bool indicates whether include types or not
+-- the fourth bool indicates whether ignore initialization or not (basically for dynamic arrays since we cannot do initialization in function params)
+tvar2C :: Bool -> Bool -> Bool -> Bool -> TypeVarDeclaration -> State RenderState [Doc]
+tvar2C b _ includeType _ f@(FunctionDeclaration (Identifier name _) _ _ _ _ _) = do
+    t <- fun2C b name f
+    if includeType then return t else return []
+tvar2C _ _ includeType _ td@(TypeDeclaration i' t) = do
+    i <- id2CTyped t i'
+    tp <- type2C t
+    let res = if includeType then [text "typedef" <+> tp i] else []
+    case t of
+        (Sequence ids) -> do
+            modify(\s -> s{enums = (render i, map (\(Identifier i _) -> i) ids) : enums s})
+            return res
+        _ -> return res
+
+tvar2C _ _ _ _ (VarDeclaration True _ (ids, t) Nothing) = do
+    t' <- liftM ((empty <+>) . ) $ type2C t
+    liftM (map(\i -> t' i)) $ mapM (id2CTyped2 (Just $ t' empty) (VarParamType t)) ids
+
+tvar2C _ externVar includeType ignoreInit (VarDeclaration _ isConst (ids, t) mInitExpr) = do
+    t' <- liftM (((if isConst then text "static const" else if externVar
+                                                                then text "extern"
+                                                                else empty)
+                   <+>) . ) $ type2C t
+    ie <- initExpr mInitExpr
+    lt <- gets lastType
+    case (isConst, lt, ids, mInitExpr) of
+         (True, BTInt _, [i], Just _) -> do
+             i' <- id2CTyped t i
+             return $ if includeType then [text "enum" <> braces (i' <+> ie)] else []
+         (True, BTFloat, [i], Just e) -> do
+             i' <- id2CTyped t i
+             ie <- initExpr2C e
+             return $ if includeType then [text "#define" <+> i' <+> parens ie <> text "\n"] else []
+         (_, BTFunction{}, _, Nothing) -> liftM (map(\i -> t' i)) $ mapM (id2CTyped t) ids
+         (_, BTArray r _ _, [i], _) -> do
+            i' <- id2CTyped t i
+            ie' <- return $ case (r, mInitExpr, ignoreInit) of
+                (RangeInfinite, Nothing, False) -> text "= NULL" -- force dynamic array to be initialized as NULL if not initialized at all
+                (_, _, _) -> ie
+            result <- liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie')) $ mapM (id2CTyped t) ids
+            case (r, ignoreInit) of
+                (RangeInfinite, False) ->
+                    -- if the array is dynamic, add dimension info to it
+                    return $ [dimDecl] ++ result
+                    where
+                        arrayDimStr = show $ arrayDimension t
+                        arrayDimInitExp = text ("={" ++ ".dim = " ++ arrayDimStr ++ ", .a = {0, 0, 0, 0}}")
+                        dimDecl = varDeclDecision isConst includeType (text "fpcrtl_dimension_t" <+>  i' <> text "_dimension_info") arrayDimInitExp
+
+                (_, _) -> return result
+
+         _ -> liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie)) $ mapM (id2CTyped2 (Just $ t' empty) t) ids
+    where
+    initExpr Nothing = return $ empty
+    initExpr (Just e) = liftM (text "=" <+>) (initExpr2C e)
+    varDeclDecision True True varStr expStr = varStr <+> expStr
+    varDeclDecision False True varStr expStr = if externVar then varStr else varStr <+> expStr
+    varDeclDecision False False varStr expStr = varStr <+> expStr
+    varDeclDecision True False varStr expStr = empty
+    arrayDimension a = case a of
+        ArrayDecl Nothing t -> let a = arrayDimension t in if a > 3 then error "Dynamic array with dimension > 4 is not supported." else 1 + arrayDimension t
+        ArrayDecl _ _ -> error "Mixed dynamic array and static array are not supported."
+        _ -> 0
+
+tvar2C f _ _ _ (OperatorDeclaration op (Identifier i _) inline ret params body) = do
+    r <- op2CTyped op (extractTypes params)
+    fun2C f i (FunctionDeclaration r inline False ret params body)
+
+
+op2CTyped :: String -> [TypeDecl] -> State RenderState Identifier
+op2CTyped op t = do
+    t' <- liftM (render . hcat . punctuate (char '_') . map (\t -> t empty)) $ mapM type2C t
+    bt <- gets lastType
+    return $ Identifier (t' ++ "_op_" ++ opStr) bt
+    where
+    opStr = case op of
+                    "+" -> "add"
+                    "-" -> "sub"
+                    "*" -> "mul"
+                    "/" -> "div"
+                    "/(float)" -> "div"
+                    "=" -> "eq"
+                    "<" -> "lt"
+                    ">" -> "gt"
+                    "<>" -> "neq"
+                    _ -> error $ "op2CTyped: unknown op '" ++ op ++ "'"
+
+extractTypes :: [TypeVarDeclaration] -> [TypeDecl]
+extractTypes = concatMap f
+    where
+        f (VarDeclaration _ _ (ids, t) _) = replicate (length ids) t
+        f a = error $ "extractTypes: can't extract from " ++ show a
+
+initExpr2C, initExpr2C' :: InitExpression -> State RenderState Doc
+initExpr2C (InitArray values) = liftM (braces . vcat . punctuate comma) $ mapM initExpr2C values
+initExpr2C a = initExpr2C' a
+initExpr2C' InitNull = return $ text "NULL"
+initExpr2C' (InitAddress expr) = do
+    ie <- initExpr2C' expr
+    lt <- gets lastType
+    case lt of
+        BTFunction True _ _ -> return $ text "&" <> ie -- <> text "__vars"
+        _ -> return $ text "&" <> ie
+initExpr2C' (InitPrefixOp op expr) = liftM (text (op2C op) <>) (initExpr2C' expr)
+initExpr2C' (InitBinOp op expr1 expr2) = do
+    e1 <- initExpr2C' expr1
+    e2 <- initExpr2C' expr2
+    return $ parens $ e1 <+> text (op2C op) <+> e2
+initExpr2C' (InitNumber s) = do
+                                modify(\s -> s{lastType = (BTInt True)})
+                                return $ text s
+initExpr2C' (InitFloat s) = return $ text s
+initExpr2C' (InitHexNumber s) = return $ text "0x" <> (text . map toLower $ s)
+initExpr2C' (InitString [a]) = return . quotes $ text [a]
+initExpr2C' (InitString s) = return $ strInit s
+initExpr2C' (InitChar a) = return $ text "0x" <> text (showHex (read a) "")
+initExpr2C' (InitReference i) = id2C IOLookup i
+initExpr2C' (InitRecord fields) = do
+    (fs :: [Doc]) <- mapM (\(Identifier a _, b) -> liftM (text "." <> text a <+> equals <+>) $ initExpr2C b) fields
+    return $ lbrace $+$ (nest 4 . vcat . punctuate comma $ fs) $+$ rbrace
+--initExpr2C' (InitArray [InitRecord fields]) = do
+--    e <- initExpr2C $ InitRecord fields
+--    return $ braces $ e
+initExpr2C' r@(InitRange (Range i@(Identifier i' _))) = do
+    id2C IOLookup i
+    t <- gets lastType
+    case t of
+         BTEnum s -> return . int $ length s
+         BTInt _ -> case i' of
+                       "byte" -> return $ int 256
+                       _ -> error $ "InitRange identifier: " ++ i'
+         _ -> error $ "InitRange: " ++ show r
+initExpr2C' (InitRange (RangeFromTo (InitNumber "0") r)) = initExpr2C $ BuiltInFunction "succ" [r]
+initExpr2C' (InitRange (RangeFromTo (InitChar "0") (InitChar r))) = initExpr2C $ BuiltInFunction "succ" [InitNumber r]
+initExpr2C' (InitRange a) = error $ show a --return $ text "<<range>>"
+initExpr2C' (InitSet []) = return $ text "0"
+initExpr2C' (InitSet a) = return $ text "<<set>>"
+initExpr2C' (BuiltInFunction "low" [InitReference e]) = return $
+    case e of
+         (Identifier "LongInt" _) -> int (-2^31)
+         (Identifier "SmallInt" _) -> int (-2^15)
+         _ -> error $ "BuiltInFunction 'low': " ++ show e
+initExpr2C' (BuiltInFunction "high" [e]) = do
+    initExpr2C e
+    t <- gets lastType
+    case t of
+         (BTArray i _ _) -> initExpr2C' $ BuiltInFunction "pred" [InitRange i]
+         a -> error $ "BuiltInFunction 'high': " ++ show a
+initExpr2C' (BuiltInFunction "succ" [BuiltInFunction "pred" [e]]) = initExpr2C' e
+initExpr2C' (BuiltInFunction "pred" [BuiltInFunction "succ" [e]]) = initExpr2C' e
+initExpr2C' (BuiltInFunction "succ" [e]) = liftM (<> text " + 1") $ initExpr2C' e
+initExpr2C' (BuiltInFunction "pred" [e]) = liftM (<> text " - 1") $ initExpr2C' e
+initExpr2C' b@(BuiltInFunction _ _) = error $ show b
+initExpr2C' a = error $ "initExpr2C: don't know how to render " ++ show a
+
+
+range2C :: InitExpression -> State RenderState [Doc]
+range2C (InitString [a]) = return [quotes $ text [a]]
+range2C (InitRange (Range i)) = liftM (flip (:) []) $ id2C IOLookup i
+range2C (InitRange (RangeFromTo (InitString [a]) (InitString [b]))) = return $ map (\i -> quotes $ text [i]) [a..b]
+range2C a = liftM (flip (:) []) $ initExpr2C a
+
+baseType2C :: String -> BaseType -> Doc
+baseType2C _ BTFloat = text "float"
+baseType2C _ BTBool = text "bool"
+baseType2C _ BTString = text "string255"
+baseType2C s a = error $ "baseType2C: " ++ show a ++ "\n" ++ s
+
+type2C :: TypeDecl -> State RenderState (Doc -> Doc)
+type2C (SimpleType i) = liftM (\i a -> i <+> a) $ id2C IOLookup i
+type2C t = do
+    r <- type2C' t
+    rt <- resolveType t
+    modify (\st -> st{lastType = rt})
+    return r
+    where
+    type2C' VoidType = return (text "void" <+>)
+    type2C' (String l) = return (text "string255" <+>)--return (text ("string" ++ show l) <+>)
+    type2C' (PointerTo (SimpleType i)) = do
+        i' <- id2C IODeferred i
+        lt <- gets lastType
+        case lt of
+             BTRecord _ _ -> return $ \a -> text "struct __" <> i' <+> text "*" <+> a
+             BTUnknown -> return $ \a -> text "struct __" <> i' <+> text "*" <+> a
+             _ -> return $ \a -> i' <+> text "*" <+> a
+    type2C' (PointerTo t) = liftM (\t a -> t (parens $ text "*" <> a)) $ type2C t
+    type2C' (RecordType tvs union) = do
+        t <- withState' f $ mapM (tvar2C False False True False) tvs
+        u <- unions
+        return $ \i -> text "struct __" <> i <+> lbrace $+$ nest 4 ((vcat . map (<> semi) . concat $ t) $$ u) $+$ rbrace <+> i
+        where
+            f s = s{currentUnit = ""}
+            unions = case union of
+                     Nothing -> return empty
+                     Just a -> do
+                         structs <- mapM struct2C a
+                         return $ text "union" $+$ braces (nest 4 $ vcat structs) <> semi
+            struct2C tvs = do
+                t <- withState' f $ mapM (tvar2C False False True False) tvs
+                return $ text "struct" $+$ braces (nest 4 (vcat . map (<> semi) . concat $ t)) <> semi
+    type2C' (RangeType r) = return (text "int" <+>)
+    type2C' (Sequence ids) = do
+        is <- mapM (id2C IOInsert . setBaseType bt) ids
+        return (text "enum" <+> (braces . vcat . punctuate comma . map (\(a, b) -> a <+> equals <+> text "0x" <> text (showHex b "")) $ zip is [0..]) <+>)
+        where
+            bt = BTEnum $ map (\(Identifier i _) -> map toLower i) ids
+    type2C' (ArrayDecl Nothing t) = type2C (PointerTo t)
+    type2C' (ArrayDecl (Just r) t) = do
+        t' <- type2C t
+        lt <- gets lastType
+        ft <- case lt of
+                -- BTFunction {} -> type2C (PointerTo t)
+                _ -> return t'
+        r' <- initExpr2C (InitRange r)
+        return $ \i -> ft i <> brackets r'
+    type2C' (Set t) = return (text "<<set>>" <+>)
+    type2C' (FunctionType returnType params) = do
+        t <- type2C returnType
+        p <- withState' id $ functionParams2C params
+        return (\i -> (t empty <> (parens $ text "*" <> i) <> parens p))
+    type2C' (DeriveType (InitBinOp _ _ i)) = type2C' (DeriveType i)
+    type2C' (DeriveType (InitPrefixOp _ i)) = type2C' (DeriveType i)
+    type2C' (DeriveType (InitNumber _)) = return (text "int" <+>)
+    type2C' (DeriveType (InitHexNumber _)) = return (text "int" <+>)
+    type2C' (DeriveType (InitFloat _)) = return (text "float" <+>)
+    type2C' (DeriveType (BuiltInFunction {})) = return (text "int" <+>)
+    type2C' (DeriveType (InitString {})) = return (text "string255" <+>)
+    type2C' (DeriveType r@(InitReference {})) = do
+        initExpr2C r
+        t <- gets lastType
+        return (baseType2C (show r) t <+>)
+    type2C' (DeriveType a) = error $ "Can't derive type from " ++ show a
+
+phrase2C :: Phrase -> State RenderState Doc
+phrase2C (Phrases p) = do
+    ps <- mapM phrase2C p
+    return $ text "{" $+$ (nest 4 . vcat $ ps) $+$ text "}"
+phrase2C (ProcCall f@(FunCall {}) []) = liftM (<> semi) $ ref2C f
+phrase2C (ProcCall ref []) = liftM (<> semi) $ ref2CF ref True
+phrase2C (ProcCall ref params) = error $ "ProcCall"{-do
+    r <- ref2C ref
+    ps <- mapM expr2C params
+    return $ r <> parens (hsep . punctuate (char ',') $ ps) <> semi -}
+phrase2C (IfThenElse (expr) phrase1 mphrase2) = do
+    e <- expr2C expr
+    p1 <- (phrase2C . wrapPhrase) phrase1
+    el <- elsePart
+    return $
+        text "if" <> parens e $+$ p1 $+$ el
+    where
+    elsePart | isNothing mphrase2 = return $ empty
+             | otherwise = liftM (text "else" $$) $ (phrase2C . wrapPhrase) (fromJust mphrase2)
+phrase2C asgn@(Assignment ref expr) = do
+    r <- ref2C ref
+    t <- gets lastType
+    case (t, expr) of
+        (BTFunction {}, (Reference r')) -> do
+            e <- ref2C r'
+            return $ r <+> text "=" <+> e <> semi
+        (BTString, _) -> do
+            e <- expr2C expr
+            lt <- gets lastType
+            case lt of
+                -- assume pointer to char for simplicity
+                BTPointerTo _ -> do
+                    e <- expr2C $ Reference $ FunCall [Reference $ RefExpression expr] (SimpleReference (Identifier "pchar2str" BTUnknown))
+                    return $ r <+> text "=" <+> e <> semi
+                BTString -> do
+                    e <- expr2C expr
+                    return $ r <+> text "=" <+> e <> semi
+                _ -> error $ "Assignment to string from " ++ show asgn
+        (BTArray _ _ _, _) -> do
+            case expr of
+                Reference er -> do
+                    exprRef <- ref2C er
+                    exprT <- gets lastType
+                    case exprT of
+                        BTArray RangeInfinite _ _ ->
+                            return $ text "FIXME: assign a dynamic array to an array"
+                        BTArray _ _ _ -> phrase2C $
+                                ProcCall (FunCall
+                                    [
+                                    Reference $ ref
+                                    , Reference $ RefExpression expr
+                                    , Reference $ FunCall [expr] (SimpleReference (Identifier "sizeof" BTUnknown))
+                                    ]
+                                    (SimpleReference (Identifier "memcpy" BTUnknown))
+                                    ) []
+                        _ -> return $ text "FIXME: assign a non-specific value to an array"
+
+                _ -> return $ text "FIXME: dynamic array assignment 2"
+        _ -> do
+            e <- expr2C expr
+            return $ r <+> text "=" <+> e <> semi
+phrase2C (WhileCycle expr phrase) = do
+    e <- expr2C expr
+    p <- phrase2C $ wrapPhrase phrase
+    return $ text "while" <> parens e $$ p
+phrase2C (SwitchCase expr cases mphrase) = do
+    e <- expr2C expr
+    cs <- mapM case2C cases
+    d <- dflt
+    return $
+        text "switch" <> parens e $+$ braces (nest 4 . vcat $ cs ++ d)
+    where
+    case2C :: ([InitExpression], Phrase) -> State RenderState Doc
+    case2C (e, p) = do
+        ies <- mapM range2C e
+        ph <- phrase2C p
+        return $
+             vcat (map (\i -> text "case" <+> i <> colon) . concat $ ies) <> nest 4 (ph $+$ text "break;")
+    dflt | isNothing mphrase = return [text "default: break;"] -- avoid compiler warning
+         | otherwise = do
+             ph <- mapM phrase2C $ fromJust mphrase
+             return [text "default:" <+> nest 4 (vcat ph)]
+
+phrase2C wb@(WithBlock ref p) = do
+    r <- ref2C ref
+    t <- gets lastType
+    case t of
+        (BTRecord _ rs) -> withRecordNamespace (render r ++ ".") (rec2Records rs) $ phrase2C $ wrapPhrase p
+        a -> do
+            error $ "'with' block referencing non-record type " ++ show a ++ "\n" ++ show wb
+phrase2C (ForCycle i' e1' e2' p up) = do
+    i <- id2C IOLookup i'
+    iType <- gets lastIdTypeDecl
+    e1 <- expr2C e1'
+    e2 <- expr2C e2'
+    let inc = if up then "inc" else "dec"
+    let add = if up then "+ 1" else "- 1"
+    let iEnd = i <> text "__end__"
+    ph <- phrase2C . appendPhrase (BuiltInFunctionCall [Reference $ SimpleReference i'] (SimpleReference (Identifier inc BTUnknown))) $ wrapPhrase p
+    return . braces $
+        i <+> text "=" <+> e1 <> semi
+        $$
+        iType <+> iEnd <+> text "=" <+> e2 <> semi
+        $$
+        text "if" <+> (parens $ i <+> text (if up then "<=" else ">=") <+> iEnd) <+> text "do" <+> ph <+>
+        text "while" <> parens (i <+> text "!=" <+> iEnd <+> text add) <> semi
+    where
+        appendPhrase p (Phrases ps) = Phrases $ ps ++ [p]
+phrase2C (RepeatCycle e' p') = do
+    e <- expr2C e'
+    p <- phrase2C (Phrases p')
+    return $ text "do" <+> p <+> text "while" <> parens (text "!" <> parens e) <> semi
+
+phrase2C NOP = return $ text ";"
+
+phrase2C (BuiltInFunctionCall [] (SimpleReference (Identifier "exit" BTUnknown))) = do
+    f <- gets currentFunctionResult
+    if null f then
+        return $ text "return" <> semi
+        else
+        return $ text "return" <+> text f <> semi
+phrase2C (BuiltInFunctionCall [] (SimpleReference (Identifier "break" BTUnknown))) = return $ text "break" <> semi
+phrase2C (BuiltInFunctionCall [] (SimpleReference (Identifier "continue" BTUnknown))) = return $ text "continue" <> semi
+phrase2C (BuiltInFunctionCall [e] (SimpleReference (Identifier "exit" BTUnknown))) = liftM (\e -> text "return" <+> e <> semi) $ expr2C e
+phrase2C (BuiltInFunctionCall [e] (SimpleReference (Identifier "dec" BTUnknown))) = liftM (\e -> text "--" <> e <> semi) $ expr2C e
+phrase2C (BuiltInFunctionCall [e1, e2] (SimpleReference (Identifier "dec" BTUnknown))) = liftM2 (\a b -> a <> text " -= " <> b <> semi) (expr2C e1) (expr2C e2)
+phrase2C (BuiltInFunctionCall [e] (SimpleReference (Identifier "inc" BTUnknown))) = liftM (\e -> text "++" <> e <> semi) $ expr2C e
+phrase2C (BuiltInFunctionCall [e1, e2] (SimpleReference (Identifier "inc" BTUnknown))) = liftM2 (\a b -> a <+> text "+=" <+> b <> semi) (expr2C e1) (expr2C e2)
+phrase2C a = error $ "phrase2C: " ++ show a
+
+wrapPhrase p@(Phrases _) = p
+wrapPhrase p = Phrases [p]
+
+expr2C :: Expression -> State RenderState Doc
+expr2C (Expression s) = return $ text s
+expr2C b@(BinOp op expr1 expr2) = do
+    e1 <- expr2C expr1
+    t1 <- gets lastType
+    e2 <- expr2C expr2
+    t2 <- gets lastType
+    case (op2C op, t1, t2) of
+        ("+", BTString, BTString) -> expr2C $ BuiltInFunCall [expr1, expr2] (SimpleReference $ Identifier "_strconcat" (BTFunction False [(False, t1), (False, t2)] BTString))
+        ("+", BTString, BTChar) -> expr2C $ BuiltInFunCall [expr1, expr2] (SimpleReference $ Identifier "_strappend" (BTFunction False [(False, t1), (False, t2)] BTString))
+        ("+", BTChar, BTString) -> expr2C $ BuiltInFunCall [expr1, expr2] (SimpleReference $ Identifier "_strprepend" (BTFunction False [(False, t1), (False, t2)] BTString))
+        ("+", BTChar, BTChar) -> expr2C $ BuiltInFunCall [expr1, expr2] (SimpleReference $ Identifier "_chrconcat" (BTFunction False [(False, t1), (False, t2)] BTString))
+        ("==", BTString, BTChar) -> expr2C $ BuiltInFunCall [expr1, expr2] (SimpleReference $ Identifier "_strcomparec" (BTFunction False [(False, t1), (False, t2)] BTBool))
+
+        -- for function/procedure comparision
+        ("==", BTVoid, _) -> procCompare expr1 expr2 "=="
+        ("==", BTFunction _ _ _, _) -> procCompare expr1 expr2 "=="
+
+        ("!=", BTVoid, _) -> procCompare expr1 expr2 "!="
+        ("!=", BTFunction _ _ _, _) -> procCompare expr1 expr2 "!="
+
+        ("==", BTString, BTString) -> expr2C $ BuiltInFunCall [expr1, expr2] (SimpleReference $ Identifier "_strcompare" (BTFunction False [(False, t1), (False, t2)] BTBool))
+        ("!=", BTString, _) -> expr2C $ BuiltInFunCall [expr1, expr2] (SimpleReference $ Identifier "_strncompare" (BTFunction False [(False, t1), (False, t2)] BTBool))
+        ("&", BTBool, _) -> return $ parens e1 <+> text "&&" <+> parens e2
+        ("|", BTBool, _) -> return $ parens e1 <+> text "||" <+> parens e2
+        (_, BTRecord t1 _, BTRecord t2 _) -> do
+            i <- op2CTyped op [SimpleType (Identifier t1 undefined), SimpleType (Identifier t2 undefined)]
+            ref2C $ FunCall [expr1, expr2] (SimpleReference i)
+        (_, BTRecord t1 _, BTInt _) -> do
+            -- aw, "LongInt" here is hwengine-specific hack
+            i <- op2CTyped op [SimpleType (Identifier t1 undefined), SimpleType (Identifier "LongInt" undefined)]
+            ref2C $ FunCall [expr1, expr2] (SimpleReference i)
+        ("in", _, _) ->
+            case expr2 of
+                 SetExpression set -> do
+                     ids <- mapM (id2C IOLookup) set
+                     modify(\s -> s{lastType = BTBool})
+                     return . parens . hcat . punctuate (text " || ") . map (\i -> parens $ e1 <+> text "==" <+> i) $ ids
+                 _ -> error "'in' against not set expression"
+        (o, _, _) | o `elem` boolOps -> do
+                        modify(\s -> s{lastType = BTBool})
+                        return $ parens e1 <+> text o <+> parens e2
+                  | otherwise -> do
+                        o' <- return $ case o of
+                            "/(float)" -> text "/(float)" -- pascal returns real value
+                            _ -> text o
+                        e1' <- return $ case (o, t1, t2) of
+                                ("-", BTInt False, BTInt False) -> parens $ text "(int64_t)" <+> parens e1
+                                _ -> parens e1
+                        e2' <- return $ case (o, t1, t2) of
+                                ("-", BTInt False, BTInt False) -> parens $ text "(int64_t)" <+> parens e2
+                                _ -> parens e2
+                        return $ e1' <+> o' <+> e2'
+    where
+        boolOps = ["==", "!=", "<", ">", "<=", ">="]
+        procCompare expr1 expr2 op =
+            case (expr1, expr2) of
+                (Reference r1, Reference r2) -> do
+                    id1 <- ref2C r1
+                    id2 <- ref2C r2
+                    return $ (parens id1) <+> text op <+> (parens id2)
+                (_, _) -> error $ "Two non reference type vars are compared but they have type of BTVoid or BTFunction\n" ++ show expr1 ++ "\n" ++ show expr2
+
+expr2C (NumberLiteral s) = do
+    modify(\s -> s{lastType = BTInt True})
+    return $ text s
+expr2C (FloatLiteral s) = return $ text s
+expr2C (HexNumber s) = return $ text "0x" <> (text . map toLower $ s)
+{-expr2C (StringLiteral [a]) = do
+    modify(\s -> s{lastType = BTChar})
+    return . quotes . text $ escape a
+    where
+        escape '\'' = "\\\'"
+        escape a = [a]-}
+expr2C (StringLiteral s) = addStringConst s
+expr2C (PCharLiteral s) = return . doubleQuotes $ text s
+expr2C (Reference ref) = do
+   isfunc <- gets isFunctionType
+   modify(\s -> s{isFunctionType = False}) -- reset
+   if isfunc then ref2CF ref False else ref2CF ref True
+expr2C (PrefixOp op expr) = do
+    e <- expr2C expr
+    lt <- gets lastType
+    case lt of
+        BTRecord t _ -> do
+            i <- op2CTyped op [SimpleType (Identifier t undefined)]
+            ref2C $ FunCall [expr] (SimpleReference i)
+        BTBool -> do
+            o <- return $ case op of
+                     "not" -> text "!"
+                     _ -> text (op2C op)
+            return $ o <> parens e
+        _ -> return $ text (op2C op) <> parens e
+expr2C Null = return $ text "NULL"
+expr2C (CharCode a) = do
+    modify(\s -> s{lastType = BTChar})
+    return $ text "0x" <> text (showHex (read a) "")
+expr2C (HexCharCode a) = if length a <= 2 then return $ quotes $ text "\\x" <> text (map toLower a) else expr2C $ HexNumber a
+expr2C (SetExpression ids) = mapM (id2C IOLookup) ids >>= return . parens . hcat . punctuate (text " | ")
+
+expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "low" _))) = do
+    e' <- liftM (map toLower . render) $ expr2C e
+    lt <- gets lastType
+    case lt of
+         BTEnum a -> return $ int 0
+         BTInt _ -> case e' of
+                  "longint" -> return $ int (-2147483648)
+         BTArray {} -> return $ int 0
+         _ -> error $ "BuiltInFunCall 'low' from " ++ show e ++ "\ntype: " ++ show lt
+expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "high" _))) = do
+    e' <- liftM (map toLower . render) $ expr2C e
+    lt <- gets lastType
+    case lt of
+         BTEnum a -> return . int $ length a - 1
+         BTInt _ -> case e' of
+                  "longint" -> return $ int (2147483647)
+         BTString -> return $ int 255
+         BTArray (RangeFromTo _ n) _ _ -> initExpr2C n
+         _ -> error $ "BuiltInFunCall 'high' from " ++ show e ++ "\ntype: " ++ show lt
+expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "ord" _))) = liftM parens $ expr2C e
+expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "succ" _))) = liftM (<> text " + 1") $ expr2C e
+expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "pred" _))) = do
+    e'<- expr2C e
+    return $ text "(int)" <> parens e' <> text " - 1"
+expr2C (BuiltInFunCall [e] (SimpleReference (Identifier "length" _))) = do
+    e' <- expr2C e
+    lt <- gets lastType
+    modify (\s -> s{lastType = BTInt True})
+    case lt of
+         BTString -> return $ text "fpcrtl_Length" <> parens e'
+         BTArray RangeInfinite _ _ -> error $ "length() called on variable size array " ++ show e'
+         BTArray (RangeFromTo _ n) _ _ -> initExpr2C (BuiltInFunction "succ" [n])
+         _ -> error $ "length() called on " ++ show lt
+expr2C (BuiltInFunCall params ref) = do
+    r <- ref2C ref
+    t <- gets lastType
+    ps <- mapM expr2C params
+    case t of
+        BTFunction _ _ t' -> do
+            modify (\s -> s{lastType = t'})
+        _ -> error $ "BuiltInFunCall lastType: " ++ show t
+    return $
+        r <> parens (hsep . punctuate (char ',') $ ps)
+expr2C a = error $ "Don't know how to render " ++ show a
+
+ref2CF :: Reference -> Bool -> State RenderState Doc
+ref2CF (SimpleReference name) addParens = do
+    i <- id2C IOLookup name
+    t <- gets lastType
+    case t of
+         BTFunction _ _ rt -> do
+             modify(\s -> s{lastType = rt})
+             return $ if addParens then i <> parens empty else i --xymeng: removed parens
+         _ -> return $ i
+ref2CF r@(RecordField (SimpleReference _) (SimpleReference _)) addParens = do
+    i <- ref2C r
+    t <- gets lastType
+    case t of
+         BTFunction _ _ rt -> do
+             modify(\s -> s{lastType = rt})
+             return $ if addParens then i <> parens empty else i
+         _ -> return $ i
+ref2CF r _ = ref2C r
+
+ref2C :: Reference -> State RenderState Doc
+-- rewrite into proper form
+ref2C (RecordField ref1 (ArrayElement exprs ref2)) = ref2C $ ArrayElement exprs (RecordField ref1 ref2)
+ref2C (RecordField ref1 (Dereference ref2)) = ref2C $ Dereference (RecordField ref1 ref2)
+ref2C (RecordField ref1 (RecordField ref2 ref3)) = ref2C $ RecordField (RecordField ref1 ref2) ref3
+ref2C (RecordField ref1 (FunCall params ref2)) = ref2C $ FunCall params (RecordField ref1 ref2)
+ref2C (ArrayElement (a:b:xs) ref) = ref2C $ ArrayElement (b:xs) (ArrayElement [a] ref)
+-- conversion routines
+ref2C ae@(ArrayElement [expr] ref) = do
+    e <- expr2C expr
+    r <- ref2C ref
+    t <- gets lastType
+    case t of
+         (BTArray _ _ t') -> modify (\st -> st{lastType = t'})
+--         (BTFunctionReturn _ (BTArray _ _ t')) -> modify (\st -> st{lastType = t'})
+--         (BTFunctionReturn _ (BTString)) -> modify (\st -> st{lastType = BTChar})
+         (BTString) -> modify (\st -> st{lastType = BTChar})
+         (BTPointerTo t) -> do
+                t'' <- fromPointer (show t) =<< gets lastType
+                case t'' of
+                     BTChar -> modify (\st -> st{lastType = BTChar})
+                     a -> error $ "Getting element of " ++ show a ++ "\nReference: " ++ show ae
+         a -> error $ "Getting element of " ++ show a ++ "\nReference: " ++ show ae
+    case t of
+         BTString ->  return $ r <> text ".s" <> brackets e
+         _ -> return $ r <> brackets e
+ref2C (SimpleReference name) = id2C IOLookup name
+ref2C rf@(RecordField (Dereference ref1) ref2) = do
+    r1 <- ref2C ref1
+    t <- fromPointer (show ref1) =<< gets lastType
+    r2 <- case t of
+        BTRecord _ rs -> withRecordNamespace "" (rec2Records rs) $ ref2C ref2
+        BTUnit -> error "What??"
+        a -> error $ "dereferencing from " ++ show a ++ "\n" ++ show rf
+    return $
+        r1 <> text "->" <> r2
+ref2C rf@(RecordField ref1 ref2) = do
+    r1 <- ref2C ref1
+    t <- gets lastType
+    case t of
+        BTRecord _ rs -> do
+            r2 <- withRecordNamespace "" (rec2Records rs) $ ref2C ref2
+            return $ r1 <> text "." <> r2
+        BTUnit -> withLastIdNamespace $ ref2C ref2
+        a -> error $ "dereferencing from " ++ show a ++ "\n" ++ show rf
+ref2C d@(Dereference ref) = do
+    r <- ref2C ref
+    t <- fromPointer (show d) =<< gets lastType
+    modify (\st -> st{lastType = t})
+    return $ (parens $ text "*" <> r)
+ref2C f@(FunCall params ref) = do
+    r <- fref2C ref
+    t <- gets lastType
+    case t of
+        BTFunction _ bts t' -> do
+            ps <- liftM (parens . hsep . punctuate (char ',')) $
+                    if (length params) == (length bts) -- hot fix for pas2cSystem and pas2cRedo functions since they don't have params
+                    then
+                        mapM expr2CHelper (zip params bts)
+                    else mapM expr2C params
+            modify (\s -> s{lastType = t'})
+            return $ r <> ps
+        _ -> case (ref, params) of
+                  (SimpleReference i, [p]) -> ref2C $ TypeCast i p
+                  _ -> error $ "ref2C FunCall erroneous type cast detected: " ++ show f ++ "\nType detected: " ++ show t ++ "\n" ++ show ref ++ "\n" ++ show params ++ "\n" ++ show t
+    where
+    fref2C (SimpleReference name) = id2C (IOLookupFunction $ length params) name
+    fref2C a = ref2C a
+    expr2CHelper :: (Expression, (Bool, BaseType)) -> State RenderState Doc
+    expr2CHelper (e, (_, BTFunction _ _ _)) = do
+        modify (\s -> s{isFunctionType = True})
+        expr2C e
+    expr2CHelper (e, (isVar, _)) = if isVar then liftM (((<>) $ text "&") . parens) $ (expr2C e) else expr2C e
+
+ref2C (Address ref) = do
+    r <- ref2C ref
+    lt <- gets lastType
+    case lt of
+        BTFunction True _ _ -> return $ text "&" <> parens r
+        _ -> return $ text "&" <> parens r
+ref2C (TypeCast t'@(Identifier i _) expr) = do
+    lt <- expr2C expr >> gets lastType
+    case (map toLower i, lt) of
+        ("pchar", BTString) -> ref2C $ FunCall [expr] (SimpleReference (Identifier "_pchar" $ BTPointerTo BTChar))
+        ("shortstring", BTPointerTo _) -> ref2C $ FunCall [expr] (SimpleReference (Identifier "pchar2str" $ BTString))
+        (a, _) -> do
+            e <- expr2C expr
+            t <- id2C IOLookup t'
+            return . parens $ parens t <> e
+ref2C (RefExpression expr) = expr2C expr
+
+
+op2C :: String -> String
+op2C "or" = "|"
+op2C "and" = "&"
+op2C "not" = "~"
+op2C "xor" = "^"
+op2C "div" = "/"
+op2C "mod" = "%"
+op2C "shl" = "<<"
+op2C "shr" = ">>"
+op2C "<>" = "!="
+op2C "=" = "=="
+op2C "/" = "/(float)"
+op2C a = a
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/PascalBasics.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,70 @@
+{-# LANGUAGE FlexibleContexts #-}
+module PascalBasics where
+
+import Text.Parsec.Combinator
+import Text.Parsec.Char
+import Text.Parsec.Prim
+import Text.Parsec.Token
+import Text.Parsec.Language
+import Data.Char
+
+builtin = ["succ", "pred", "low", "high", "ord", "inc", "dec", "exit", "break", "continue", "length"]
+
+pascalLanguageDef
+    = emptyDef
+    { commentStart   = "(*"
+    , commentEnd     = "*)"
+    , commentLine    = "//"
+    , nestedComments = False
+    , identStart     = letter <|> oneOf "_"
+    , identLetter    = alphaNum <|> oneOf "_"
+    , opLetter       = letter
+    , reservedNames  = [
+            "begin", "end", "program", "unit", "interface"
+            , "implementation", "and", "or", "xor", "shl"
+            , "shr", "while", "do", "repeat", "until", "case", "of"
+            , "type", "var", "const", "out", "array", "packed"
+            , "procedure", "function", "with", "for", "to"
+            , "downto", "div", "mod", "record", "set", "nil"
+            , "cdecl", "external", "if", "then", "else"
+            ] -- ++ builtin
+    , caseSensitive  = False
+    }
+
+preprocessorSwitch :: Stream s m Char => ParsecT s u m String
+preprocessorSwitch = do
+    try $ string "{$"
+    s <- manyTill (noneOf "\n") $ char '}'
+    return s
+
+caseInsensitiveString s = do
+    mapM_ (\a -> satisfy (\b -> toUpper a == toUpper b)) s <?> s
+    return s
+
+pas = patch $ makeTokenParser pascalLanguageDef
+    where
+    patch tp = tp {stringLiteral = stringL}
+
+comment = choice [
+        char '{' >> notFollowedBy (char '$') >> manyTill anyChar (try $ char '}')
+        , (try $ string "(*") >> manyTill anyChar (try $ string "*)")
+        , (try $ string "//") >> manyTill anyChar (try newline)
+        ]
+
+comments = do
+    spaces
+    skipMany $ do
+        preprocessorSwitch <|> comment
+        spaces
+
+stringL = do
+    (char '\'')
+    s <- (many $ noneOf "'")
+    (char '\'')
+    ss <- many $ do
+        (char '\'')
+        s' <- (many $ noneOf "'")
+        (char '\'')
+        return $ '\'' : s'
+    comments
+    return $ concat (s:ss)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/PascalParser.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,676 @@
+module PascalParser where
+
+import Text.Parsec
+import Text.Parsec.Char
+import Text.Parsec.Token
+import Text.Parsec.Language
+import Text.Parsec.Expr
+import Text.Parsec.Prim
+import Text.Parsec.Combinator
+import Text.Parsec.String
+import Control.Monad
+import Data.Maybe
+import Data.Char
+
+import PascalBasics
+import PascalUnitSyntaxTree
+
+knownTypes = ["shortstring", "ansistring", "char", "byte"]
+
+pascalUnit = do
+    comments
+    u <- choice [program, unit, systemUnit, redoUnit]
+    comments
+    return u
+
+iD = do
+    i <- identifier pas
+    comments
+    when (i == "not") $ unexpected "'not' used as an identifier"
+    return $ Identifier i BTUnknown
+
+unit = do
+    string "unit" >> comments
+    name <- iD
+    semi pas
+    comments
+    int <- interface
+    impl <- implementation
+    comments
+    return $ Unit name int impl Nothing Nothing
+
+
+reference = buildExpressionParser table term <?> "reference"
+    where
+    term = comments >> choice [
+        parens pas (liftM RefExpression expression >>= postfixes) >>= postfixes
+        , try $ typeCast >>= postfixes
+        , char '@' >> liftM Address reference >>= postfixes
+        , liftM SimpleReference iD >>= postfixes
+        ] <?> "simple reference"
+
+    table = [
+        ]
+
+    postfixes r = many postfix >>= return . foldl (flip ($)) r
+    postfix = choice [
+            parens pas (option [] parameters) >>= return . FunCall
+          , char '^' >> return Dereference
+          , (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement
+          , (char '.' >> notFollowedBy (char '.')) >> liftM (flip RecordField) reference
+        ]
+
+    typeCast = do
+        t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes
+        e <- parens pas expression
+        comments
+        return $ TypeCast (Identifier t BTUnknown) e
+
+varsDecl1 = varsParser sepEndBy1
+varsDecl = varsParser sepEndBy
+varsParser m endsWithSemi = do
+    vs <- m (aVarDecl endsWithSemi) (semi pas)
+    return vs
+
+aVarDecl endsWithSemi = do
+    isVar <- liftM (== Just "var") $
+        if not endsWithSemi then
+            optionMaybe $ choice [
+                try $ string "var"
+                , try $ string "const"
+                , try $ string "out"
+                ]
+            else
+                return Nothing
+    comments
+    ids <- do
+        i <- (commaSep1 pas) $ (try iD <?> "variable declaration")
+        char ':'
+        return i
+    comments
+    t <- typeDecl <?> "variable type declaration"
+    comments
+    init <- option Nothing $ do
+        char '='
+        comments
+        e <- initExpression
+        comments
+        return (Just e)
+    return $ VarDeclaration isVar False (ids, t) init
+
+
+constsDecl = do
+    vs <- many1 (try (aConstDecl >>= \i -> semi pas >> return i) >>= \i -> comments >> return i)
+    comments
+    return vs
+    where
+    aConstDecl = do
+        comments
+        i <- iD
+        t <- optionMaybe $ do
+            char ':'
+            comments
+            t <- typeDecl
+            comments
+            return t
+        char '='
+        comments
+        e <- initExpression
+        comments
+        return $ VarDeclaration False (isNothing t) ([i], fromMaybe (DeriveType e) t) (Just e)
+
+typeDecl = choice [
+    char '^' >> typeDecl >>= return . PointerTo
+    , try (string "shortstring") >> return (String 255)
+    , try (string "string") >> optionMaybe (brackets pas $ integer pas) >>= return . String . fromMaybe 255
+    , try (string "ansistring") >> optionMaybe (brackets pas $ integer pas) >>= return . String . fromMaybe 255
+    , arrayDecl
+    , recordDecl
+    , setDecl
+    , functionType
+    , sequenceDecl >>= return . Sequence
+    , try iD >>= return . SimpleType
+    , rangeDecl >>= return . RangeType
+    ] <?> "type declaration"
+    where
+    arrayDecl = do
+        try $ do
+            optional $ (try $ string "packed") >> comments
+            string "array"
+        comments
+        r <- option [] $ do
+            char '['
+            r <- commaSep pas rangeDecl
+            char ']'
+            comments
+            return r
+        string "of"
+        comments
+        t <- typeDecl
+        if null r then
+            return $ ArrayDecl Nothing t
+            else
+            return $ foldr (\a b -> ArrayDecl (Just a) b) (ArrayDecl (Just $ head r) t) (tail r)
+    recordDecl = do
+        try $ do
+            optional $ (try $ string "packed") >> comments
+            string "record"
+        comments
+        vs <- varsDecl True
+        union <- optionMaybe $ do
+            string "case"
+            comments
+            iD
+            comments
+            string "of"
+            comments
+            many unionCase
+        string "end"
+        return $ RecordType vs union
+    setDecl = do
+        try $ string "set" >> space
+        comments
+        string "of"
+        comments
+        liftM Set typeDecl
+    unionCase = do
+        try $ commaSep pas $ (iD >> return ()) <|> (integer pas >> return ())
+        char ':'
+        comments
+        u <- parens pas $ varsDecl True
+        char ';'
+        comments
+        return u
+    sequenceDecl = (parens pas) $ (commaSep pas) (iD >>= \i -> optional (spaces >> char '=' >> spaces >> integer pas) >> return i)
+    functionType = do
+        fp <- try (string "function") <|> try (string "procedure")
+        comments
+        vs <- option [] $ parens pas $ varsDecl False
+        comments
+        ret <- if (fp == "function") then do
+            char ':'
+            comments
+            ret <- typeDecl
+            comments
+            return ret
+            else
+            return VoidType
+        optional $ try $ char ';' >> comments >> string "cdecl"
+        comments
+        return $ FunctionType ret vs
+
+typesDecl = many (aTypeDecl >>= \t -> comments >> return t)
+    where
+    aTypeDecl = do
+        i <- try $ do
+            i <- iD <?> "type declaration"
+            comments
+            char '='
+            return i
+        comments
+        t <- typeDecl
+        comments
+        semi pas
+        comments
+        return $ TypeDeclaration i t
+
+rangeDecl = choice [
+    try $ rangeft
+    , iD >>= return . Range
+    ] <?> "range declaration"
+    where
+    rangeft = do
+    e1 <- initExpression
+    string ".."
+    e2 <- initExpression
+    return $ RangeFromTo e1 e2
+
+typeVarDeclaration isImpl = (liftM concat . many . choice) [
+    varSection,
+    constSection,
+    typeSection,
+    funcDecl,
+    operatorDecl
+    ]
+    where
+
+    fixInit v = concat $ map (\x -> case x of
+                    VarDeclaration a b (ids, t) c ->
+                        let typeId = (Identifier ((\(Identifier i _) -> i) (head ids) ++ "_tt") BTUnknown) in
+                        let res =  [TypeDeclaration typeId t, VarDeclaration a b (ids, (SimpleType typeId)) c] in
+                        case t of
+                            RecordType _ _ -> res -- create a separated type declaration
+                            ArrayDecl _ _ -> res
+                            _ -> [x]
+                    _ -> error ("checkInit:\n" ++ (show v))) v
+
+    varSection = do
+        try $ string "var"
+        comments
+        v <- varsDecl1 True <?> "variable declaration"
+        comments
+        return $ fixInit v
+
+    constSection = do
+        try $ string "const"
+        comments
+        c <- constsDecl <?> "const declaration"
+        comments
+        return $ fixInit c
+
+    typeSection = do
+        try $ string "type"
+        comments
+        t <- typesDecl <?> "type declaration"
+        comments
+        return t
+
+    operatorDecl = do
+        try $ string "operator"
+        comments
+        i <- manyTill anyChar space
+        comments
+        vs <- parens pas $ varsDecl False
+        comments
+        rid <- iD
+        comments
+        char ':'
+        comments
+        ret <- typeDecl
+        comments
+        return ret
+        char ';'
+        comments
+        forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments)
+        inline <- liftM (any (== "inline;")) $ many functionDecorator
+        b <- if isImpl && (not forward) then
+                liftM Just functionBody
+                else
+                return Nothing
+        return $ [OperatorDeclaration i rid inline ret vs b]
+
+
+    funcDecl = do
+        fp <- try (string "function") <|> try (string "procedure")
+        comments
+        i <- iD
+        vs <- option [] $ parens pas $ varsDecl False
+        comments
+        ret <- if (fp == "function") then do
+            char ':'
+            comments
+            ret <- typeDecl
+            comments
+            return ret
+            else
+            return VoidType
+        char ';'
+        comments
+        forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments)
+        decorators <- many functionDecorator
+        let inline = any (== "inline;") decorators
+            overload = any (== "overload;") decorators
+        b <- if isImpl && (not forward) then
+                liftM Just functionBody
+                else
+                return Nothing
+        return $ [FunctionDeclaration i inline overload ret vs b]
+
+    functionDecorator = do
+        d <- choice [
+            try $ string "inline;"
+            , try $ caseInsensitiveString "cdecl;"
+            , try $ string "overload;"
+            , try $ string "export;"
+            , try $ string "varargs;"
+            , try (string "external") >> comments >> iD >> optional (string "name" >> comments >> stringLiteral pas)>> string ";"
+            ]
+        comments
+        return d
+
+
+program = do
+    string "program"
+    comments
+    name <- iD
+    (char ';')
+    comments
+    comments
+    u <- uses
+    comments
+    tv <- typeVarDeclaration True
+    comments
+    p <- phrase
+    comments
+    char '.'
+    comments
+    return $ Program name (Implementation u (TypesAndVars tv)) p
+
+interface = do
+    string "interface"
+    comments
+    u <- uses
+    comments
+    tv <- typeVarDeclaration False
+    comments
+    return $ Interface u (TypesAndVars tv)
+
+implementation = do
+    string "implementation"
+    comments
+    u <- uses
+    comments
+    tv <- typeVarDeclaration True
+    string "end."
+    comments
+    return $ Implementation u (TypesAndVars tv)
+
+expression = do
+    buildExpressionParser table term <?> "expression"
+    where
+    term = comments >> choice [
+        builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n BTUnknown))
+        , try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char '.') >> return e)
+        , brackets pas (commaSep pas iD) >>= return . SetExpression
+        , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i
+        , float pas >>= return . FloatLiteral . show
+        , try $ integer pas >>= return . NumberLiteral . show
+        , try (string "_S" >> stringLiteral pas) >>= return . StringLiteral
+        , try (string "_P" >> stringLiteral pas) >>= return . PCharLiteral
+        , stringLiteral pas >>= return . strOrChar
+        , try (string "#$") >> many hexDigit >>= \c -> comments >> return (HexCharCode c)
+        , char '#' >> many digit >>= \c -> comments >> return (CharCode c)
+        , char '$' >> many hexDigit >>=  \h -> comments >> return (HexNumber h)
+        --, char '-' >> expression >>= return . PrefixOp "-"
+        , char '-' >> reference >>= return . PrefixOp "-" . Reference
+        , (try $ string "not" >> notFollowedBy comments) >> unexpected "'not'"
+        , try $ string "nil" >> return Null
+        , reference >>= return . Reference
+        ] <?> "simple expression"
+
+    table = [
+          [  Prefix (reservedOp pas "not">> return (PrefixOp "not"))
+           , Prefix (try (char '-') >> return (PrefixOp "-"))]
+           ,
+          [  Infix (char '*' >> return (BinOp "*")) AssocLeft
+           , Infix (char '/' >> return (BinOp "/")) AssocLeft
+           , Infix (try (string "div") >> return (BinOp "div")) AssocLeft
+           , Infix (try (string "mod") >> return (BinOp "mod")) AssocLeft
+           , Infix (try (string "in") >> return (BinOp "in")) AssocNone
+           , Infix (try $ string "and" >> return (BinOp "and")) AssocLeft
+           , Infix (try $ string "shl" >> return (BinOp "shl")) AssocLeft
+           , Infix (try $ string "shr" >> return (BinOp "shr")) AssocLeft
+          ]
+        , [  Infix (char '+' >> return (BinOp "+")) AssocLeft
+           , Infix (char '-' >> return (BinOp "-")) AssocLeft
+           , Infix (try $ string "or" >> return (BinOp "or")) AssocLeft
+           , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft
+          ]
+        , [  Infix (try (string "<>") >> return (BinOp "<>")) AssocNone
+           , Infix (try (string "<=") >> return (BinOp "<=")) AssocNone
+           , Infix (try (string ">=") >> return (BinOp ">=")) AssocNone
+           , Infix (char '<' >> return (BinOp "<")) AssocNone
+           , Infix (char '>' >> return (BinOp ">")) AssocNone
+          ]
+        {-, [  Infix (try $ string "shl" >> return (BinOp "shl")) AssocNone
+             , Infix (try $ string "shr" >> return (BinOp "shr")) AssocNone
+          ]
+        , [
+             Infix (try $ string "or" >> return (BinOp "or")) AssocLeft
+           , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft
+          ]-}
+        , [
+             Infix (char '=' >> return (BinOp "=")) AssocNone
+          ]
+        ]
+    strOrChar [a] = CharCode . show . ord $ a
+    strOrChar a = StringLiteral a
+
+phrasesBlock = do
+    try $ string "begin"
+    comments
+    p <- manyTill phrase (try $ string "end" >> notFollowedBy alphaNum)
+    comments
+    return $ Phrases p
+
+phrase = do
+    o <- choice [
+        phrasesBlock
+        , ifBlock
+        , whileCycle
+        , repeatCycle
+        , switchCase
+        , withBlock
+        , forCycle
+        , (try $ reference >>= \r -> string ":=" >> return r) >>= \r -> comments >> expression >>= return . Assignment r
+        , builtInFunction expression >>= \(n, e) -> return $ BuiltInFunctionCall e (SimpleReference (Identifier n BTUnknown))
+        , procCall
+        , char ';' >> comments >> return NOP
+        ]
+    optional $ char ';'
+    comments
+    return o
+
+ifBlock = do
+    try $ string "if" >> notFollowedBy (alphaNum <|> char '_')
+    comments
+    e <- expression
+    comments
+    string "then"
+    comments
+    o1 <- phrase
+    comments
+    o2 <- optionMaybe $ do
+        try $ string "else" >> space
+        comments
+        o <- option NOP phrase
+        comments
+        return o
+    return $ IfThenElse e o1 o2
+
+whileCycle = do
+    try $ string "while"
+    comments
+    e <- expression
+    comments
+    string "do"
+    comments
+    o <- phrase
+    return $ WhileCycle e o
+
+withBlock = do
+    try $ string "with" >> space
+    comments
+    rs <- (commaSep1 pas) reference
+    comments
+    string "do"
+    comments
+    o <- phrase
+    return $ foldr WithBlock o rs
+
+repeatCycle = do
+    try $ string "repeat" >> space
+    comments
+    o <- many phrase
+    string "until"
+    comments
+    e <- expression
+    comments
+    return $ RepeatCycle e o
+
+forCycle = do
+    try $ string "for" >> space
+    comments
+    i <- iD
+    comments
+    string ":="
+    comments
+    e1 <- expression
+    comments
+    up <- liftM (== Just "to") $
+            optionMaybe $ choice [
+                try $ string "to"
+                , try $ string "downto"
+                ]
+    --choice [string "to", string "downto"]
+    comments
+    e2 <- expression
+    comments
+    string "do"
+    comments
+    p <- phrase
+    comments
+    return $ ForCycle i e1 e2 p up
+
+switchCase = do
+    try $ string "case"
+    comments
+    e <- expression
+    comments
+    string "of"
+    comments
+    cs <- many1 aCase
+    o2 <- optionMaybe $ do
+        try $ string "else" >> notFollowedBy alphaNum
+        comments
+        o <- many phrase
+        comments
+        return o
+    string "end"
+    comments
+    return $ SwitchCase e cs o2
+    where
+    aCase = do
+        e <- (commaSep pas) $ (liftM InitRange rangeDecl <|> initExpression)
+        comments
+        char ':'
+        comments
+        p <- phrase
+        comments
+        return (e, p)
+
+procCall = do
+    r <- reference
+    p <- option [] $ (parens pas) parameters
+    return $ ProcCall r p
+
+parameters = (commaSep pas) expression <?> "parameters"
+
+functionBody = do
+    tv <- typeVarDeclaration True
+    comments
+    p <- phrasesBlock
+    char ';'
+    comments
+    return (TypesAndVars tv, p)
+
+uses = liftM Uses (option [] u)
+    where
+        u = do
+            string "uses"
+            comments
+            u <- (iD >>= \i -> comments >> return i) `sepBy1` (char ',' >> comments)
+            char ';'
+            comments
+            return u
+
+initExpression = buildExpressionParser table term <?> "initialization expression"
+    where
+    term = comments >> choice [
+        liftM (uncurry BuiltInFunction) $ builtInFunction initExpression
+        , try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet
+        , try $ parens pas (commaSep pas $ initExpression) >>= \ia -> when ((notRecord $ head ia) && (null $ tail ia)) mzero >> return (InitArray ia)
+        , try $ parens pas (sepEndBy recField (char ';' >> comments)) >>= return . InitRecord
+        , parens pas initExpression
+        , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i
+        , try $ float pas >>= return . InitFloat . show
+        , try $ integer pas >>= return . InitNumber . show
+        , stringLiteral pas >>= return . InitString
+        , char '#' >> many digit >>= \c -> comments >> return (InitChar c)
+        , char '$' >> many hexDigit >>= \h -> comments >> return (InitHexNumber h)
+        , char '@' >> initExpression >>= \c -> comments >> return (InitAddress c)
+        , try $ string "nil" >> return InitNull
+        , itypeCast
+        , iD >>= return . InitReference
+        ]
+
+    notRecord (InitRecord _) = False
+    notRecord _ = True
+
+    recField = do
+        i <- iD
+        spaces
+        char ':'
+        spaces
+        e <- initExpression
+        spaces
+        return (i ,e)
+
+    table = [
+          [
+             Prefix (char '-' >> return (InitPrefixOp "-"))
+            ,Prefix (try (string "not") >> return (InitPrefixOp "not"))
+          ]
+        , [  Infix (char '*' >> return (InitBinOp "*")) AssocLeft
+           , Infix (char '/' >> return (InitBinOp "/")) AssocLeft
+           , Infix (try (string "div") >> return (InitBinOp "div")) AssocLeft
+           , Infix (try (string "mod") >> return (InitBinOp "mod")) AssocLeft
+           , Infix (try $ string "and" >> return (InitBinOp "and")) AssocLeft
+           , Infix (try $ string "shl" >> return (InitBinOp "shl")) AssocNone
+           , Infix (try $ string "shr" >> return (InitBinOp "shr")) AssocNone
+          ]
+        , [  Infix (char '+' >> return (InitBinOp "+")) AssocLeft
+           , Infix (char '-' >> return (InitBinOp "-")) AssocLeft
+           , Infix (try $ string "or" >> return (InitBinOp "or")) AssocLeft
+           , Infix (try $ string "xor" >> return (InitBinOp "xor")) AssocLeft
+          ]
+        , [  Infix (try (string "<>") >> return (InitBinOp "<>")) AssocNone
+           , Infix (try (string "<=") >> return (InitBinOp "<=")) AssocNone
+           , Infix (try (string ">=") >> return (InitBinOp ">=")) AssocNone
+           , Infix (char '<' >> return (InitBinOp "<")) AssocNone
+           , Infix (char '>' >> return (InitBinOp ">")) AssocNone
+           , Infix (char '=' >> return (InitBinOp "=")) AssocNone
+          ]
+        {--, [  Infix (try $ string "and" >> return (InitBinOp "and")) AssocLeft
+           , Infix (try $ string "or" >> return (InitBinOp "or")) AssocLeft
+           , Infix (try $ string "xor" >> return (InitBinOp "xor")) AssocLeft
+          ]
+        , [  Infix (try $ string "shl" >> return (InitBinOp "shl")) AssocNone
+           , Infix (try $ string "shr" >> return (InitBinOp "shr")) AssocNone
+          ]--}
+        --, [Prefix (try (string "not") >> return (InitPrefixOp "not"))]
+        ]
+
+    itypeCast = do
+        t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes
+        i <- parens pas initExpression
+        comments
+        return $ InitTypeCast (Identifier t BTUnknown) i
+
+builtInFunction e = do
+    name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin
+    spaces
+    exprs <- option [] $ parens pas $ option [] $ commaSep1 pas $ e
+    spaces
+    return (name, exprs)
+
+systemUnit = do
+    string "system;"
+    comments
+    string "type"
+    comments
+    t <- typesDecl
+    string "var"
+    v <- varsDecl True
+    return $ System (t ++ v)
+
+redoUnit = do
+    string "redo;"
+    comments
+    string "type"
+    comments
+    t <- typesDecl
+    string "var"
+    v <- varsDecl True
+    return $ Redo (t ++ v)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/PascalPreprocessor.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,130 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+module PascalPreprocessor where
+
+import Text.Parsec
+import Control.Monad.IO.Class
+import Control.Monad
+import System.IO
+import qualified Data.Map as Map
+import Control.Exception(catch, IOException)
+import Data.Char
+import Prelude hiding (catch)
+
+-- comments are removed
+comment = choice [
+        char '{' >> notFollowedBy (char '$') >> manyTill anyChar (try $ char '}') >> return ""
+        , (try $ string "(*") >> manyTill anyChar (try $ string "*)") >> return ""
+        , (try $ string "//") >> manyTill anyChar (try newline) >> return "\n"
+        ]
+
+preprocess :: String -> String -> String -> [String] -> IO String
+preprocess inputPath alternateInputPath fn symbols = do
+    r <- runParserT (preprocessFile (inputPath ++ fn)) (Map.fromList $ map (\s -> (s, "")) symbols, [True]) "" ""
+    case r of
+         (Left a) -> do
+             hPutStrLn stderr (show a)
+             return ""
+         (Right a) -> return a
+
+    where
+    preprocessFile fn = do
+        f <- liftIO (readFile fn)
+        setInput f
+        preprocessor
+
+    preprocessor, codeBlock, switch :: ParsecT String (Map.Map String String, [Bool]) IO String
+
+    preprocessor = chainr codeBlock (return (++)) ""
+
+    codeBlock = do
+        s <- choice [
+            switch
+            , comment
+            , char '\'' >> many (noneOf "'\n") >>= \s -> char '\'' >> return ('\'' : s ++ "'")
+            , identifier >>= replace
+            , noneOf "{" >>= \a -> return [a]
+            ]
+        (_, ok) <- getState
+        return $ if and ok then s else ""
+
+    --otherChar c = c `notElem` "{/('_" && not (isAlphaNum c)
+    identifier = do
+        c <- letter <|> oneOf "_"
+        s <- many (alphaNum <|> oneOf "_")
+        return $ c:s
+
+    switch = do
+        try $ string "{$"
+        s <- choice [
+            include
+            , ifdef
+            , if'
+            , elseSwitch
+            , endIf
+            , define
+            , unknown
+            ]
+        return s
+
+    include = do
+        try $ string "INCLUDE"
+        spaces
+        (char '"')
+        fn <- many1 $ noneOf "\"\n"
+        char '"'
+        spaces
+        char '}'
+        f <- liftIO (readFile (inputPath ++ fn) `catch` (\(exc :: IOException) -> readFile (alternateInputPath ++ fn) `catch` (\(_ :: IOException) -> error ("File not found: " ++ fn))))
+        c <- getInput
+        setInput $ f ++ c
+        return ""
+
+    ifdef = do
+        s <- try (string "IFDEF") <|> try (string "IFNDEF")
+        let f = if s == "IFNDEF" then not else id
+
+        spaces
+        d <- identifier
+        spaces
+        char '}'
+
+        updateState $ \(m, b) ->
+            (m, (f $ d `Map.member` m) : b)
+
+        return ""
+
+    if' = do
+        s <- try (string "IF" >> notFollowedBy alphaNum)
+
+        manyTill anyChar (char '}')
+        --char '}'
+
+        updateState $ \(m, b) ->
+            (m, False : b)
+
+        return ""
+
+    elseSwitch = do
+        try $ string "ELSE}"
+        updateState $ \(m, b:bs) -> (m, (not b):bs)
+        return ""
+    endIf = do
+        try $ string "ENDIF}"
+        updateState $ \(m, b:bs) -> (m, bs)
+        return ""
+    define = do
+        try $ string "DEFINE"
+        spaces
+        i <- identifier
+        d <- ((string ":=" >> return ()) <|> spaces) >> many (noneOf "}")
+        char '}'
+        updateState $ \(m, b) -> (if (and b) && (head i /= '_') then Map.insert i d m else m, b)
+        return ""
+    replace s = do
+        (m, _) <- getState
+        return $ Map.findWithDefault s s m
+
+    unknown = do
+        fn <- many1 $ noneOf "}\n"
+        char '}'
+        return $ "{$" ++ fn ++ "}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/PascalUnitSyntaxTree.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,119 @@
+module PascalUnitSyntaxTree where
+
+import Data.Maybe
+import Data.Char
+
+data PascalUnit =
+    Program Identifier Implementation Phrase
+    | Unit Identifier Interface Implementation (Maybe Initialize) (Maybe Finalize)
+    | System [TypeVarDeclaration]
+    | Redo [TypeVarDeclaration]
+    deriving Show
+data Interface = Interface Uses TypesAndVars
+    deriving Show
+data Implementation = Implementation Uses TypesAndVars
+    deriving Show
+data Identifier = Identifier String BaseType
+    deriving Show
+data TypesAndVars = TypesAndVars [TypeVarDeclaration]
+    deriving Show
+data TypeVarDeclaration = TypeDeclaration Identifier TypeDecl
+    | VarDeclaration Bool Bool ([Identifier], TypeDecl) (Maybe InitExpression)
+    | FunctionDeclaration Identifier Bool Bool TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
+    | OperatorDeclaration String Identifier Bool TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
+    deriving Show
+data TypeDecl = SimpleType Identifier
+    | RangeType Range
+    | Sequence [Identifier]
+    | ArrayDecl (Maybe Range) TypeDecl
+    | RecordType [TypeVarDeclaration] (Maybe [[TypeVarDeclaration]])
+    | PointerTo TypeDecl
+    | String Integer
+    | Set TypeDecl
+    | FunctionType TypeDecl [TypeVarDeclaration]
+    | DeriveType InitExpression
+    | VoidType
+    | VarParamType TypeDecl -- this is a hack
+    deriving Show
+data Range = Range Identifier
+           | RangeFromTo InitExpression InitExpression
+           | RangeInfinite
+    deriving Show
+data Initialize = Initialize String
+    deriving Show
+data Finalize = Finalize String
+    deriving Show
+data Uses = Uses [Identifier]
+    deriving Show
+data Phrase = ProcCall Reference [Expression]
+        | IfThenElse Expression Phrase (Maybe Phrase)
+        | WhileCycle Expression Phrase
+        | RepeatCycle Expression [Phrase]
+        | ForCycle Identifier Expression Expression Phrase Bool -- The last Boolean indicates wether it's up or down counting
+        | WithBlock Reference Phrase
+        | Phrases [Phrase]
+        | SwitchCase Expression [([InitExpression], Phrase)] (Maybe [Phrase])
+        | Assignment Reference Expression
+        | BuiltInFunctionCall [Expression] Reference
+        | NOP
+    deriving Show
+data Expression = Expression String
+    | BuiltInFunCall [Expression] Reference
+    | PrefixOp String Expression
+    | PostfixOp String Expression
+    | BinOp String Expression Expression
+    | StringLiteral String
+    | PCharLiteral String
+    | CharCode String
+    | HexCharCode String
+    | NumberLiteral String
+    | FloatLiteral String
+    | HexNumber String
+    | Reference Reference
+    | SetExpression [Identifier]
+    | Null
+    deriving Show
+data Reference = ArrayElement [Expression] Reference
+    | FunCall [Expression] Reference
+    | TypeCast Identifier Expression
+    | SimpleReference Identifier
+    | Dereference Reference
+    | RecordField Reference Reference
+    | Address Reference
+    | RefExpression Expression
+    deriving Show
+data InitExpression = InitBinOp String InitExpression InitExpression
+    | InitPrefixOp String InitExpression
+    | InitReference Identifier
+    | InitArray [InitExpression]
+    | InitRecord [(Identifier, InitExpression)]
+    | InitFloat String
+    | InitNumber String
+    | InitHexNumber String
+    | InitString String
+    | InitChar String
+    | BuiltInFunction String [InitExpression]
+    | InitSet [InitExpression]
+    | InitAddress InitExpression
+    | InitNull
+    | InitRange Range
+    | InitTypeCast Identifier InitExpression
+    deriving Show
+
+data BaseType = BTUnknown
+    | BTChar
+    | BTString
+    | BTInt Bool -- second param indicates whether signed or not
+    | BTBool
+    | BTFloat
+    | BTRecord String [(String, BaseType)]
+    | BTArray Range BaseType BaseType
+    | BTFunction Bool [(Bool, BaseType)] BaseType -- (Bool, BaseType), Bool indiciates whether var or not
+    | BTPointerTo BaseType
+    | BTUnresolved String
+    | BTSet BaseType
+    | BTEnum [String]
+    | BTVoid
+    | BTUnit
+    | BTVarParam BaseType
+    deriving Show
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/pas2c/unitCycles.hs	Tue Jan 21 22:53:15 2014 +0100
@@ -0,0 +1,46 @@
+module Main where
+
+import PascalParser
+import System
+import Control.Monad
+import Data.Either
+import Data.List
+import Data.Graph
+import Data.Maybe
+
+unident :: Identificator -> String
+unident (Identificator s) = s
+
+extractUnits :: PascalUnit -> (String, [String])
+extractUnits (Program (Identificator name) (Implementation (Uses idents) _ _) _) = ("program " ++ name, map unident idents)
+extractUnits (Unit (Identificator name) (Interface (Uses idents1) _) (Implementation (Uses idents2) _ _) _ _) = (name, map unident $ idents1 ++ idents2)
+
+f :: [(String, [String])] -> String
+f = unlines . map showSCC . stronglyConnComp . map (\(a, b) -> (a, a, b))
+    where
+    showSCC (AcyclicSCC v) = v
+    showSCC (CyclicSCC vs) = intercalate ", " vs
+
+myf :: [(String, [String])] -> String
+myf d = unlines . map (findCycle . fst) $ d
+    where
+    findCycle :: String -> String
+    findCycle searched = searched ++ ": " ++ (intercalate ", " $ fc searched [])
+        where
+        fc :: String -> [String] -> [String]
+        fc curSearch visited = let uses = curSearch `lookup` d; res = dropWhile null . map t $ fromJust uses in if isNothing uses || null res then [] else head res
+            where
+            t u =
+                if u == searched then
+                    [u]
+                    else
+                    if u `elem` visited then
+                        []
+                        else
+                        let chain = fc u (u:visited) in if null chain then [] else u:chain
+
+
+main = do
+    fileNames <- getArgs
+    files <- mapM readFile fileNames
+    putStrLn . myf . map extractUnits . rights . map parsePascalUnit $ files
--- a/tools/w32DownloadUnzip.vbs	Wed Jan 22 01:11:13 2014 +0400
+++ b/tools/w32DownloadUnzip.vbs	Tue Jan 21 22:53:15 2014 +0100
@@ -1,66 +1,66 @@
-' w32DownloadUnzip.vbs
-'   Download a zipfile and uncompress it with no external tools in Windows
-'
-' Copyright (c) 2012, Vittorio Giovara, <vittorio.giovara@gmail.com>
-' Redistribution and use is allowed according to the terms of the BSD license.
-'
-' References
-'   http://superuser.com/questions/59465/is-it-possible-to-download-using-the-windows-command-line
-'   http://stackoverflow.com/questions/1021557/how-to-unzip-a-file-using-the-command-line
-'   http://stackoverflow.com/questions/424331/get-the-current-temporary-directory-path-in-vbscript
-
-Set ArgObj = WScript.Arguments
-
-If (Wscript.Arguments.Count = 1) Then
-    strFileURL = ArgObj(0)
-    strOutputPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
-Else
-    If (Wscript.Arguments.Count = 2) Then
-        strFileURL = ArgObj(0)
-        strOutputPath = ArgObj(1)
-    Else
-        WScript.Echo ("Usage: csript.exe w32DownloadUnzip.vbs url output")
-        WScript.Quit
-    End if
-End if
-
-' Temporary directory
-strHDLocation = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2) + "\hwlibtemp.zip"
-
-' Fetch the file
-WScript.Echo ( "Trying to download from " & strFileURL)
-Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
-objXMLHTTP.open "GET", strFileURL, false
-objXMLHTTP.send()
-
-If objXMLHTTP.Status = 200 Then
-    Set objADOStream = CreateObject("ADODB.Stream")
-    objADOStream.Open
-    objADOStream.Type = 1 'adTypeBinary
-
-    objADOStream.Write objXMLHTTP.ResponseBody
-    objADOStream.Position = 0 'Set the stream position to the start
-
-    Set objFSO = Createobject("Scripting.FileSystemObject")
-    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
-    Set objFSO = Nothing
-
-    objADOStream.SaveToFile strHDLocation
-    objADOStream.Close
-    Set objADOStream = Nothing
-    Set objXMLHTTP = Nothing
-Else
-    WScript.Echo ("Error downloading file (error code: " & objXMLHTTP.Status & ")")
-    Set objXMLHTTP = Nothing
-    WScript.Quit
-End if
-
-WScript.Echo ( "Extracting file to " & strOutputPath)
-Set objShell = CreateObject( "Shell.Application" )
-Set objSource = objShell.NameSpace(strHDLocation).Items()
-Set objTarget = objShell.NameSpace(strOutputPath)
-intOptions = 16 'no user prompt
-objTarget.CopyHere objSource, intOptions
-
-WScript.Echo ( "Success!" )
-Set objShell = Nothing
+' w32DownloadUnzip.vbs
+'   Download a zipfile and uncompress it with no external tools in Windows
+'
+' Copyright (c) 2012, Vittorio Giovara, <vittorio.giovara@gmail.com>
+' Redistribution and use is allowed according to the terms of the BSD license.
+'
+' References
+'   http://superuser.com/questions/59465/is-it-possible-to-download-using-the-windows-command-line
+'   http://stackoverflow.com/questions/1021557/how-to-unzip-a-file-using-the-command-line
+'   http://stackoverflow.com/questions/424331/get-the-current-temporary-directory-path-in-vbscript
+
+Set ArgObj = WScript.Arguments
+
+If (Wscript.Arguments.Count = 1) Then
+    strFileURL = ArgObj(0)
+    strOutputPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
+Else
+    If (Wscript.Arguments.Count = 2) Then
+        strFileURL = ArgObj(0)
+        strOutputPath = ArgObj(1)
+    Else
+        WScript.Echo ("Usage: csript.exe w32DownloadUnzip.vbs url output")
+        WScript.Quit
+    End if
+End if
+
+' Temporary directory
+strHDLocation = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2) + "\hwlibtemp.zip"
+
+' Fetch the file
+WScript.Echo ( "Trying to download from " & strFileURL)
+Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
+objXMLHTTP.open "GET", strFileURL, false
+objXMLHTTP.send()
+
+If objXMLHTTP.Status = 200 Then
+    Set objADOStream = CreateObject("ADODB.Stream")
+    objADOStream.Open
+    objADOStream.Type = 1 'adTypeBinary
+
+    objADOStream.Write objXMLHTTP.ResponseBody
+    objADOStream.Position = 0 'Set the stream position to the start
+
+    Set objFSO = Createobject("Scripting.FileSystemObject")
+    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
+    Set objFSO = Nothing
+
+    objADOStream.SaveToFile strHDLocation
+    objADOStream.Close
+    Set objADOStream = Nothing
+    Set objXMLHTTP = Nothing
+Else
+    WScript.Echo ("Error downloading file (error code: " & objXMLHTTP.Status & ")")
+    Set objXMLHTTP = Nothing
+    WScript.Quit
+End if
+
+WScript.Echo ( "Extracting file to " & strOutputPath)
+Set objShell = CreateObject( "Shell.Application" )
+Set objSource = objShell.NameSpace(strHDLocation).Items()
+Set objTarget = objShell.NameSpace(strOutputPath)
+intOptions = 16 'no user prompt
+objTarget.CopyHere objSource, intOptions
+
+WScript.Echo ( "Success!" )
+Set objShell = Nothing