Add separate option for perlin gen
authorunc0rr
Fri, 22 Aug 2014 00:37:26 +0400
changeset 10391 ce3ccc45d790
parent 10390 13bfbade06a5
child 10392 5012e1f9e893
Add separate option for perlin gen
QTfrontend/model/MapModel.cpp
QTfrontend/model/MapModel.h
QTfrontend/model/roomslistmodel.cpp
QTfrontend/net/hwmap.cpp
QTfrontend/net/hwmap.h
QTfrontend/ui/widget/mapContainer.cpp
hedgewars/uLand.pas
hedgewars/uLandGenPerlin.pas
--- a/QTfrontend/model/MapModel.cpp	Thu Aug 21 15:01:19 2014 +0200
+++ b/QTfrontend/model/MapModel.cpp	Fri Aug 22 00:37:26 2014 +0400
@@ -30,6 +30,7 @@
 
 MapModel::MapInfo MapModel::MapInfoRandom = {MapModel::GeneratedMap, "+rnd+", "", 0, "", "", "", false};
 MapModel::MapInfo MapModel::MapInfoMaze = {MapModel::GeneratedMaze, "+maze+", "", 0, "", "", "", false};
+MapModel::MapInfo MapModel::MapInfoPerlin = {MapModel::GeneratedMaze, "+perlin+", "", 0, "", "", "", false};
 MapModel::MapInfo MapModel::MapInfoDrawn = {MapModel::HandDrawnMap, "+drawn+", "", 0, "", "", "", false};
 
 
--- a/QTfrontend/model/MapModel.h	Thu Aug 21 15:01:19 2014 +0200
+++ b/QTfrontend/model/MapModel.h	Fri Aug 22 00:37:26 2014 +0400
@@ -49,6 +49,7 @@
             Invalid,
             GeneratedMap,
             GeneratedMaze,
+            GeneratedPerlin,
             HandDrawnMap,
             MissionMap,
             StaticMap
@@ -98,7 +99,7 @@
         QStandardItem * getMap(const QString & map);
 
         // Static MapInfos for drawn and generated maps
-        static MapInfo MapInfoRandom, MapInfoMaze, MapInfoDrawn;
+        static MapInfo MapInfoRandom, MapInfoMaze, MapInfoPerlin, MapInfoDrawn;
 
         /// Loads the maps
         bool loadMaps();
--- a/QTfrontend/model/roomslistmodel.cpp	Thu Aug 21 15:01:19 2014 +0200
+++ b/QTfrontend/model/roomslistmodel.cpp	Fri Aug 22 00:37:26 2014 +0400
@@ -132,6 +132,7 @@
             {
                 if (content == "+rnd+") return tr("Random Map");
                 if (content == "+maze+") return tr("Random Maze");
+                if (content == "+perlin+") return tr("Random Perlin");
                 if (content == "+drawn+") return tr("Hand-drawn");
             }
 
@@ -149,6 +150,7 @@
     {
         if (content == "+rnd+" ||
             content == "+maze+" ||
+            content == "+perlin+" ||
             content == "+drawn+" ||
             m_staticMapModel->mapExists(content) ||
             m_missionMapModel->mapExists(content))
--- a/QTfrontend/net/hwmap.cpp	Thu Aug 21 15:01:19 2014 +0200
+++ b/QTfrontend/net/hwmap.cpp	Fri Aug 22 00:37:26 2014 +0400
@@ -127,6 +127,7 @@
     switch (m_mapgen)
     {
         case MAPGEN_MAZE:
+        case MAPGEN_PERLIN:
             SendIPC(QString("e$maze_size %1").arg(m_maze_size).toUtf8());
             break;
 
--- a/QTfrontend/net/hwmap.h	Thu Aug 21 15:01:19 2014 +0200
+++ b/QTfrontend/net/hwmap.h	Fri Aug 22 00:37:26 2014 +0400
@@ -28,10 +28,11 @@
 
 enum MapGenerator
 {
-    MAPGEN_REGULAR,
-    MAPGEN_MAZE,
-    MAPGEN_DRAWN,
-    MAPGEN_MAP
+    MAPGEN_REGULAR = 0,
+    MAPGEN_MAZE = 1,
+    MAPGEN_PERLIN = 2,
+    MAPGEN_DRAWN = 3,
+    MAPGEN_MAP = 4
 };
 
 class HWMap : public TCPBase
--- a/QTfrontend/ui/widget/mapContainer.cpp	Thu Aug 21 15:01:19 2014 +0200
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Fri Aug 22 00:37:26 2014 +0400
@@ -105,6 +105,7 @@
     cType->insertItem(2, tr("Hand-drawn"), MapModel::HandDrawnMap);
     cType->insertItem(3, tr("Randomly generated"), MapModel::GeneratedMap);
     cType->insertItem(4, tr("Random maze"), MapModel::GeneratedMaze);
+    cType->insertItem(5, tr("Random perlin"), MapModel::GeneratedPerlin);
     connect(cType, SIGNAL(currentIndexChanged(int)), this, SLOT(mapTypeChanged(int)));
     m_childWidgets << cType;
 
@@ -401,14 +402,19 @@
 void HWMapContainer::setSeed(const QString & seed)
 {
     intSetSeed(seed);
-    if ((m_mapInfo.type == MapModel::GeneratedMap) || (m_mapInfo.type == MapModel::GeneratedMaze))
+    if ((m_mapInfo.type == MapModel::GeneratedMap)
+            || (m_mapInfo.type == MapModel::GeneratedMaze)
+            || (m_mapInfo.type == MapModel::GeneratedPerlin))
         updatePreview();
 }
 
 void HWMapContainer::setScript(const QString & script)
 {
     m_script = script;
-    if ((m_mapInfo.type == MapModel::GeneratedMap) || (m_mapInfo.type == MapModel::GeneratedMaze) || (m_mapInfo.type == MapModel::HandDrawnMap))
+    if ((m_mapInfo.type == MapModel::GeneratedMap)
+            || (m_mapInfo.type == MapModel::GeneratedMaze)
+            || (m_mapInfo.type == MapModel::GeneratedPerlin)
+            || (m_mapInfo.type == MapModel::HandDrawnMap))
         updatePreview();
 }
 
@@ -422,6 +428,10 @@
     {
         //changeMapType(MapModel::GeneratedMaze);
     }
+    else if (map == "+perlin+")
+    {
+        //changeMapType(MapModel::GeneratedPerlin);
+    }
     else if (map == "+drawn+")
     {
         //changeMapType(MapModel::HandDrawnMap);
@@ -464,6 +474,7 @@
     {
         case MapModel::GeneratedMap:
         case MapModel::GeneratedMaze:
+        case MapModel::GeneratedPerlin:
             setRandomTheme();
             break;
         case MapModel::MissionMap:
@@ -541,6 +552,9 @@
             case MAPGEN_MAZE:
                 m_mapInfo.type = MapModel::GeneratedMaze;
                 break;
+            case MAPGEN_PERLIN:
+                m_mapInfo.type = MapModel::GeneratedPerlin;
+                break;
             case MAPGEN_DRAWN:
                 m_mapInfo.type = MapModel::HandDrawnMap;
                 break;
@@ -549,6 +563,7 @@
                 {
                     case MapModel::GeneratedMap:
                     case MapModel::GeneratedMaze:
+                    case MapModel::GeneratedPerlin:
                     case MapModel::HandDrawnMap:
                         m_mapInfo.type = MapModel::Invalid;
                     default:
@@ -630,11 +645,8 @@
             mapPreview->setIconSize(failIcon.size());
             break;
         case MapModel::GeneratedMap:
-            askForGeneratedPreview();
-            break;
         case MapModel::GeneratedMaze:
-            askForGeneratedPreview();
-            break;
+        case MapModel::GeneratedPerlin:
         case MapModel::HandDrawnMap:
             askForGeneratedPreview();
             break;
@@ -722,6 +734,13 @@
             lblMapList->show();
             mazeStyles->show();
             break;
+        case MapModel::GeneratedPerlin:
+            mapgen = MAPGEN_PERLIN;
+            setMapInfo(MapModel::MapInfoPerlin);
+            lblMapList->setText(tr("Style:"));
+            lblMapList->show();
+            mazeStyles->show();
+            break;
         case MapModel::HandDrawnMap:
             mapgen = MAPGEN_DRAWN;
             setMapInfo(MapModel::MapInfoDrawn);
--- a/hedgewars/uLand.pas	Thu Aug 21 15:01:19 2014 +0200
+++ b/hedgewars/uLand.pas	Fri Aug 22 00:37:26 2014 +0400
@@ -547,8 +547,8 @@
             case cMapGen of
                 0: GenTemplated(EdgeTemplates[SelectTemplate]);
                 1: begin ResizeLand(4096,2048); GenMaze; end;
-                //1: begin ResizeLand(4096,2048); GenPerlin; end;
-                2: GenDrawnMap;
+                2: begin ResizeLand(4096,2048); GenPerlin; end;
+                3: GenDrawnMap;
             else
                 OutError('Unknown mapgen', true);
             end;
@@ -676,8 +676,8 @@
     case cMapGen of
         0: GenTemplated(EdgeTemplates[SelectTemplate]);
         1: begin ResizeLand(4096,2048); GenMaze; end;
-        //1: begin ResizeLand(4096,2048); GenPerlin; end;
-        2: GenDrawnMap;
+        2: begin ResizeLand(4096,2048); GenPerlin; end;
+        3: GenDrawnMap;
     else
         OutError('Unknown mapgen', true);
     end;
@@ -724,8 +724,8 @@
     case cMapGen of
         0: GenTemplated(EdgeTemplates[SelectTemplate]);
         1: begin ResizeLand(4096,2048); GenMaze; end;
-        //1: begin ResizeLand(4096,2048); GenPerlin; end;
-        2: GenDrawnMap;
+        2: begin ResizeLand(4096,2048); GenPerlin; end;
+        3: GenDrawnMap;
     else
         OutError('Unknown mapgen', true);
     end;
--- a/hedgewars/uLandGenPerlin.pas	Thu Aug 21 15:01:19 2014 +0200
+++ b/hedgewars/uLandGenPerlin.pas	Fri Aug 22 00:37:26 2014 +0400
@@ -121,8 +121,6 @@
 end;
 
 const detail = 150000;
-    field = 3;
-    df = detail * field;
     width = 4096;
     height = 2048;
     minY = 500;
@@ -132,8 +130,13 @@
     margin = 200;
 
 procedure GenPerlin;
-var y, x, {dy, }di, dj, r: LongInt;
+var y, x, {dy, }di, dj, df, r, param1, param2: LongInt;
 begin
+    param1:= cTemplateFilter div 3;
+    param2:= cTemplateFilter mod 3;
+
+    df:= detail * (6 - param2 * 2);
+
     inoise_setup();
 
     for y:= minY to pred(height) do
@@ -171,15 +174,17 @@
         end;
     end;
 
-    for x:= 0 to width do
-        if Land[height - 1, x] = lfObjMask then FillLand(x, height - 1, 0, lfBasic);
-    //FillLand(0, minY, lfBasic, lfObjMask);
+    if param1 = 0 then
+        begin
+        for x:= 0 to width do
+            if Land[height - 1, x] = lfObjMask then FillLand(x, height - 1, 0, lfBasic);
 
-    // strip all lfObjMask pixels
-    for y:= minY to LAND_HEIGHT - 1 do
-        for x:= 0 to LAND_WIDTH - 1 do
-            if Land[y, x] = lfObjMask then
-                Land[y, x]:= 0;
+        // strip all lfObjMask pixels
+        for y:= minY to LAND_HEIGHT - 1 do
+            for x:= 0 to LAND_WIDTH - 1 do
+                if Land[y, x] = lfObjMask then
+                    Land[y, x]:= 0;
+        end;
 
     leftX:= 0;
     rightX:= 4095;