hedgewars/uLandGenPerlin.pas
branchqmlfrontend
changeset 10515 7705784902e1
parent 10510 9329dab04490
child 10702 528d899443ab
--- a/hedgewars/uLandGenPerlin.pas	Sun Nov 09 23:02:21 2014 +0300
+++ b/hedgewars/uLandGenPerlin.pas	Tue Nov 18 23:39:30 2014 +0300
@@ -10,11 +10,12 @@
     , uConsts
     , uRandom
     , uLandOutline // FillLand
+    , uUtils
     ;
 
 var p: array[0..511] of LongInt;
 
-const fadear: array[byte] of LongInt = 
+const fadear: array[byte] of LongInt =
 (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 4, 6, 7, 9, 10, 12,
 14, 17, 19, 22, 25, 29, 32, 36, 40, 45, 49, 54, 60, 65, 71,
 77, 84, 91, 98, 105, 113, 121, 130, 139, 148, 158, 167, 178,
@@ -43,7 +44,7 @@
 begin
     t0:= fadear[t shr 8];
 
-    if t0 = fadear[255] then 
+    if t0 = fadear[255] then
         t1:= t0
     else
         t1:= fadear[t shr 8 + 1];
@@ -54,7 +55,7 @@
 
 function lerp(t, a, b: LongInt) : LongInt; inline;
 begin
-    lerp:= a + (Int64(b - a) * t shr 12)
+    lerp:= a + ((Int64(b) - a) * t shr 12)
 end;
 
 
@@ -102,7 +103,7 @@
 end;
 
 procedure inoise_setup();
-var i, ii, t: LongInt;
+var i, ii, t: Longword;
 begin
     for i:= 0 to 254 do
         p[i]:= i + 1;
@@ -120,20 +121,21 @@
         p[256 + i]:= p[i];
 end;
 
-const detail = 150000;
-    width = 4096;
-    height = 2048;
-    minY = 500;
+const width = 4096;
+      height = 2048;
+      minY = 500;
 
     //bottomPlateHeight = 90;
     //bottomPlateMargin = 1200;
     margin = 200;
 
 procedure GenPerlin;
-var y, x, {dy, }di, dj, df, r, param1, param2: LongInt;
+var y, x, {dy, }di, dj, df, r, param1, param2, rCutoff, detail: LongInt;
 begin
     param1:= cTemplateFilter div 3;
     param2:= cTemplateFilter mod 3;
+    rCutoff:= min(max((26-cFeatureSize)*4,15),85);
+    detail:= (26-cFeatureSize)*16000+50000; // feature size is a slider from 1-25 at present. flip it for perlin
 
     df:= detail * (6 - param2 * 2);
 
@@ -169,8 +171,12 @@
             end;
             }
 
-            if r < 50 then Land[y, x]:= 0 else Land[y, x]:= lfObjMask;
-
+            if r < rCutoff then
+                Land[y, x]:= 0
+            else if param1 = 0 then
+                Land[y, x]:= lfObjMask
+            else
+                Land[y, x]:= lfBasic
         end;
     end;