Pass hardcoded drawn map from frontend into engine \o/
authorunc0rr
Thu, 09 Dec 2010 11:59:07 +0300
changeset 4494 9585435e20f7
parent 4493 45db8e97d282
child 4495 1eea498d12e0
Pass hardcoded drawn map from frontend into engine \o/
QTfrontend/game.cpp
QTfrontend/gamecfgwidget.cpp
QTfrontend/gamecfgwidget.h
QTfrontend/hwmap.cpp
QTfrontend/mapContainer.cpp
QTfrontend/proto.cpp
QTfrontend/proto.h
hedgewars/uLand.pas
hedgewars/uLandPainted.pas
--- a/QTfrontend/game.cpp	Wed Dec 08 22:35:29 2010 +0100
+++ b/QTfrontend/game.cpp	Thu Dec 09 11:59:07 2010 +0300
@@ -78,7 +78,7 @@
     }
     HWProto::addStringToBuffer(buf, gt);
 
-    HWProto::addStringListToBuffer(buf, gamecfg->getFullConfig());
+    buf += gamecfg->getFullConfig();
 
     if (m_pTeamSelWidget)
     {
--- a/QTfrontend/gamecfgwidget.cpp	Wed Dec 08 22:35:29 2010 +0100
+++ b/QTfrontend/gamecfgwidget.cpp	Thu Dec 09 11:59:07 2010 +0300
@@ -30,6 +30,7 @@
 #include "igbox.h"
 #include "hwconsts.h"
 #include "ammoSchemeModel.h"
+#include "proto.h"
 
 GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) :
   QGroupBox(parent), mainLayout(this)
@@ -170,33 +171,33 @@
     return schemeData(26).toInt();
 }
 
-QStringList GameCFGWidget::getFullConfig() const
+QByteArray GameCFGWidget::getFullConfig() const
 {
-    QStringList sl;
+    QList<QByteArray> bcfg;
     int mapgen = pMapContainer->get_mapgen();
-    
-    sl.append("eseed " + pMapContainer->getCurrentSeed());
-    sl.append(QString("e$gmflags %1").arg(getGameFlags()));
-    sl.append(QString("e$damagepct %1").arg(schemeData(24).toInt()));
-    sl.append(QString("e$turntime %1").arg(schemeData(25).toInt() * 1000));
-    sl.append(QString("e$sd_turns %1").arg(schemeData(27).toInt()));
-    sl.append(QString("e$casefreq %1").arg(schemeData(28).toInt()));
-    sl.append(QString("e$minestime %1").arg(schemeData(29).toInt() * 1000));
-    sl.append(QString("e$minesnum %1").arg(schemeData(30).toInt()));
-    sl.append(QString("e$minedudpct %1").arg(schemeData(31).toInt()));
-    sl.append(QString("e$explosives %1").arg(schemeData(32).toInt()));
-    sl.append(QString("e$healthprob %1").arg(schemeData(33).toInt()));
-    sl.append(QString("e$hcaseamount %1").arg(schemeData(34).toInt()));
-    sl.append(QString("e$waterrise %1").arg(schemeData(35).toInt()));
-    sl.append(QString("e$healthdec %1").arg(schemeData(36).toInt()));
-    sl.append(QString("e$ropepct %1").arg(schemeData(37).toInt()));
-    sl.append(QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()));
-    sl.append(QString("e$mapgen %1").arg(mapgen));
+
+    bcfg << QString("eseed " + pMapContainer->getCurrentSeed()).toUtf8();
+    bcfg << QString("e$gmflags %1").arg(getGameFlags()).toUtf8();
+    bcfg << QString("e$damagepct %1").arg(schemeData(24).toInt()).toUtf8();
+    bcfg << QString("e$turntime %1").arg(schemeData(25).toInt() * 1000).toUtf8();
+    bcfg << QString("e$sd_turns %1").arg(schemeData(27).toInt()).toUtf8();
+    bcfg << QString("e$casefreq %1").arg(schemeData(28).toInt()).toUtf8();
+    bcfg << QString("e$minestime %1").arg(schemeData(29).toInt() * 1000).toUtf8();
+    bcfg << QString("e$minesnum %1").arg(schemeData(30).toInt()).toUtf8();
+    bcfg << QString("e$minedudpct %1").arg(schemeData(31).toInt()).toUtf8();
+    bcfg << QString("e$explosives %1").arg(schemeData(32).toInt()).toUtf8();
+    bcfg << QString("e$healthprob %1").arg(schemeData(33).toInt()).toUtf8();
+    bcfg << QString("e$hcaseamount %1").arg(schemeData(34).toInt()).toUtf8();
+    bcfg << QString("e$waterrise %1").arg(schemeData(35).toInt()).toUtf8();
+    bcfg << QString("e$healthdec %1").arg(schemeData(36).toInt()).toUtf8();
+    bcfg << QString("e$ropepct %1").arg(schemeData(37).toInt()).toUtf8();
+    bcfg << QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()).toUtf8();
+    bcfg << QString("e$mapgen %1").arg(mapgen).toUtf8();
 
     switch (mapgen)
     {
         case MAPGEN_MAZE:
-            sl.append(QString("e$maze_size %1").arg(pMapContainer->get_maze_size()));
+            bcfg << QString("e$maze_size %1").arg(pMapContainer->get_maze_size()).toUtf8();
 
         case MAPGEN_DRAWN:
         {
@@ -204,9 +205,10 @@
             while(data.size() > 0)
             {
                 QByteArray tmp = data;
-                tmp.truncate(230);
-                sl << QString("edraw %1").arg(QString(tmp));
-                data.remove(0, 230);
+                tmp.truncate(200);
+                tmp.prepend("edraw ");
+                bcfg << tmp;
+                data.remove(0, 200);
             }
         }
         default: ;
@@ -215,13 +217,18 @@
     QString currentMap = pMapContainer->getCurrentMap();
     if (currentMap.size() > 0)
     {
-        sl.append("emap " + currentMap);
+        bcfg << QString("emap " + currentMap).toUtf8();
         if(pMapContainer->getCurrentIsMission())
-            sl.append(QString("escript Maps/%1/map.lua")
-                .arg(currentMap));
+            bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8();
     }
-    sl.append("etheme " + pMapContainer->getCurrentTheme());
-    return sl;
+    bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8();
+
+    QByteArray result;
+
+    foreach(QByteArray ba, bcfg)
+        HWProto::addByteArrayToBuffer(result, ba);
+
+    return result;
 }
 
 void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
--- a/QTfrontend/gamecfgwidget.h	Wed Dec 08 22:35:29 2010 +0100
+++ b/QTfrontend/gamecfgwidget.h	Thu Dec 09 11:59:07 2010 +0300
@@ -39,7 +39,7 @@
     GameCFGWidget(QWidget* parent, bool externalControl=false);
     quint32 getGameFlags() const;
     quint32 getInitHealth() const;
-    QStringList getFullConfig() const;
+    QByteArray getFullConfig() const;
     QComboBox * GameSchemes;
     QComboBox * WeaponsName;
     HWMapContainer* pMapContainer;
--- a/QTfrontend/hwmap.cpp	Wed Dec 08 22:35:29 2010 +0100
+++ b/QTfrontend/hwmap.cpp	Thu Dec 09 11:59:07 2010 +0300
@@ -68,6 +68,7 @@
     {
         case MAPGEN_MAZE:
             SendIPC(QString("e$maze_size %1").arg(m_maze_size).toLatin1());
+            break;
 
         case MAPGEN_DRAWN:
         {
@@ -75,10 +76,11 @@
             while(data.size() > 0)
             {
                 QByteArray tmp = data;
-                tmp.truncate(230);
+                tmp.truncate(200);
                 SendIPC("edraw " + tmp);
-                data.remove(0, 230);
+                data.remove(0, 200);
             }
+            break;
         }
         default: ;
     }
--- a/QTfrontend/mapContainer.cpp	Wed Dec 08 22:35:29 2010 +0100
+++ b/QTfrontend/mapContainer.cpp	Thu Dec 09 11:59:07 2010 +0300
@@ -353,7 +353,7 @@
 
 QString HWMapContainer::getCurrentMap() const
 {
-    if(chooseMap->currentIndex() <= 1) return QString();
+    if(chooseMap->currentIndex() <= 2) return QString();
     return chooseMap->itemData(chooseMap->currentIndex()).toList()[0].toString();
 }
 
--- a/QTfrontend/proto.cpp	Wed Dec 08 22:35:29 2010 +0100
+++ b/QTfrontend/proto.cpp	Thu Dec 09 11:59:07 2010 +0300
@@ -23,14 +23,19 @@
 
 }
 
+QByteArray & HWProto::addByteArrayToBuffer(QByteArray & buf, const QByteArray & msg)
+{
+    QByteArray bmsg = msg;
+    bmsg = bmsg.left(250);
+    quint8 sz = bmsg.size();
+    buf.append(QByteArray((char *)&sz, 1));
+    buf.append(bmsg);
+    return buf;
+}
+
 QByteArray & HWProto::addStringToBuffer(QByteArray & buf, const QString & string)
 {
-    QByteArray strmsg = string.toUtf8();
-    strmsg = strmsg.left(250);
-    quint8 sz = strmsg.size();
-    buf.append(QByteArray((char *)&sz, 1));
-    buf.append(strmsg);
-    return buf;
+    return addByteArrayToBuffer(buf, string.toUtf8());
 }
 
 QByteArray & HWProto::addStringListToBuffer(QByteArray & buf, const QStringList & strList)
--- a/QTfrontend/proto.h	Wed Dec 08 22:35:29 2010 +0100
+++ b/QTfrontend/proto.h	Thu Dec 09 11:59:07 2010 +0300
@@ -31,6 +31,7 @@
 public:
     HWProto();
     static QByteArray & addStringToBuffer(QByteArray & buf, const QString & string);
+    static QByteArray & addByteArrayToBuffer(QByteArray & buf, const QByteArray & msg);
     static QByteArray & addStringListToBuffer(QByteArray & buf, const QStringList & strList);
     static QString formatChatMsg(const QString & nick, const QString & msg);
 };
--- a/hedgewars/uLand.pas	Wed Dec 08 22:35:29 2010 +0100
+++ b/hedgewars/uLand.pas	Thu Dec 09 11:59:07 2010 +0300
@@ -549,6 +549,19 @@
         end;
 end;
 
+procedure GenDrawnMap;
+begin
+    uLandPainted.Draw;
+
+    MaxHedgehogs:= 18;
+    hasGirders:= true;
+    playHeight:= 2048;
+    playWidth:= 4096;
+    leftX:= ((LAND_WIDTH - playWidth) div 2);
+    rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
+    topY:= LAND_HEIGHT - playHeight;
+end;
+
 function SelectTemplate: LongInt;
 begin
     if (cReducedQuality and rqLowRes) <> 0 then
@@ -1031,6 +1044,7 @@
     case cMapGen of
         0: GenBlank(EdgeTemplates[SelectTemplate]);
         1: GenMaze;
+        2: GenDrawnMap;
     end;
     AddProgress();
 
@@ -1271,6 +1285,7 @@
     case cMapGen of
         0: GenBlank(EdgeTemplates[SelectTemplate]);
         1: GenMaze;
+        2: GenDrawnMap;
     end;
 
     lh:= LAND_HEIGHT div 128;
--- a/hedgewars/uLandPainted.pas	Wed Dec 08 22:35:29 2010 +0100
+++ b/hedgewars/uLandPainted.pas	Thu Dec 09 11:59:07 2010 +0300
@@ -23,6 +23,7 @@
 interface
 
 procedure LoadFromFile(fileName: shortstring);
+procedure Draw;
 procedure initModule;
 
 implementation
@@ -33,6 +34,15 @@
     flags: byte;
     end;
 
+type
+    PPointEntry = ^PointEntry;
+    PointEntry = record
+        point: PointRec;
+        next: PPointEntry;
+        end;
+
+var pointsListHead, pointsListLast: PPointEntry;
+
 procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt);
 var  eX, eY, dX, dY: LongInt;
     i, sX, sY, x, y, d: LongInt;
@@ -125,11 +135,57 @@
 end;
 
 procedure chDraw(var s: shortstring);
+var rec: PointRec;
+    prec: ^PointRec;
+    pe: PPointEntry;
+    i, l: byte;
 begin
+    i:= 1;
+    l:= length(s);
+    while i < l do
+        begin
+        prec:= @s[i];
+        rec:= prec^;
+        rec.X:= SDLNet_Read16(@rec.X);
+        rec.Y:= SDLNet_Read16(@rec.Y);
+
+        pe:= new(PPointEntry);
+        if pointsListLast = nil then
+            pointsListHead:= pe
+        else
+            pointsListLast^.next:= pe;
+        pointsListLast:= pe;
+
+        pe^.point:= rec;
+        pe^.next:= nil;
+
+        inc(i, 5)
+        end;
+end;
+
+procedure Draw;
+var pe: PPointEntry;
+    prevPoint: PointRec;
+begin
+    pe:= pointsListHead;
+
+    while(pe <> nil) do
+        begin
+        if (pe^.point.flags and $80 <> 0) then
+            FillRoundInLand(pe^.point.X, pe^.point.Y, 34, lfBasic)
+            else
+            DrawLineOnLand(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y);
+
+        prevPoint:= pe^.point;
+        pe:= pe^.next;
+        end;
 end;
 
 procedure initModule;
 begin
+    pointsListHead:= nil;
+    pointsListLast:= nil;
+
     RegisterVariable('draw', vtCommand, @chDraw, false);
 end;