- Land generator uses templates to generate
authorunc0rr
Sun, 04 Dec 2005 19:06:56 +0000
changeset 23 16322d14f068
parent 22 517be8dc5b76
child 24 79c411363184
- Land generator uses templates to generate - Small fixes
hedgewars/GSHandlers.inc
hedgewars/hw.dpr
hedgewars/uLand.pas
hedgewars/uLandTemplates.pas
hedgewars/uWorld.pas
--- a/hedgewars/GSHandlers.inc	Sun Dec 04 15:28:31 2005 +0000
+++ b/hedgewars/GSHandlers.inc	Sun Dec 04 19:06:56 2005 +0000
@@ -405,8 +405,6 @@
          begin
          tx:= cc*len;
          ty:= cs*len;
-//         if   TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(HHGear.dX))
-///           or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(HHGear.dY)) then
          lx:= round(Gear.X + tx) + sign(HHGear.dX);
          ly:= round(Gear.Y + ty) + sign(HHGear.dY);
          if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then
@@ -573,7 +571,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepMine(Gear: PGear);
 begin
-if (Gear.dX <> 0) or (Gear.dY <> 0) then
+if (Gear.dX <> 0) or (Gear.dY <> 0) {or not TestCollisionY(Gear, 1)} then
    begin
    doStepFallingGear(Gear);
    if Gear.Active = false then
--- a/hedgewars/hw.dpr	Sun Dec 04 15:28:31 2005 +0000
+++ b/hedgewars/hw.dpr	Sun Dec 04 19:06:56 2005 +0000
@@ -52,7 +52,8 @@
   uAIMisc in 'uAIMisc.pas',
   uAIAmmoTests in 'uAIAmmoTests.pas',
   uCollisions in 'uCollisions.pas',
-  uLand in 'uLand.pas';
+  uLand in 'uLand.pas',
+  uLandTemplates in 'uLandTemplates.pas';
 
 {$INCLUDE options.inc}
 
--- a/hedgewars/uLand.pas	Sun Dec 04 15:28:31 2005 +0000
+++ b/hedgewars/uLand.pas	Sun Dec 04 19:06:56 2005 +0000
@@ -47,7 +47,7 @@
 procedure RandomizeHHPoints;
 
 implementation
-uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams, uIO;
+uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams, uIO, uLandTemplates;
 
 type TPixAr = record
               Count: Longword;
@@ -110,21 +110,6 @@
 WriteLnToConsole(msgOK)
 end;
 
-procedure GenEdge(TemplateType: Longword; out pa: TPixAr);
-const Template0: array[0..4] of TPoint = (
-                                         (x:  500; y: 1500),
-                                         (x:  350; y:  400),
-                                         (x: 1023; y:  800),
-                                         (x: 1700; y:  400),
-                                         (x: 1550; y: 1500)
-                                         );
-var i: integer;
-begin
-pa.Count:= Succ(High(Template0));
-for i:= 0 to High(Template0) do
-    pa.ar[i]:= Template0[i]
-end;
-
 procedure DrawBezierEdge(var pa: TPixAr);
 var x, y, i: integer;
     tx, ty, vx, vy, vlen, t: real;
@@ -294,7 +279,8 @@
 Stack.Count:= 0;
 xl:= x - 1;
 xr:= x;
-Push(xl, xr, 1024, -1);
+Push(xl, xr, y, -1);
+Push(xl, xr, y,  1);
 while Stack.Count > 0 do
       begin
       Pop(xl, xr, y, dir);
@@ -452,7 +438,7 @@
     begin
     Result:= 0;
     if (y and $FFFFFC00) <> 0 then exit;
-    for i:= max(x - 6, 0) to min(x + 6, 2043) do
+    for i:= max(x - 5, 0) to min(x + 5, 2043) do
         if Land[y, i] <> 0 then inc(Result)
     end;
 
@@ -494,28 +480,33 @@
    end;
 end;
 
-procedure PointWave(var pa: TPixAr; PassesNum: Longword);
-const MAXPASSES = 8;
-var ar: array[0..Pred(MAXPASSES) - 1, 0..5] of real;
+procedure PointWave(var Template: TEdgeTemplate; var pa: TPixAr);
+const MAXPASSES = 16;
+var ar: array[0..MAXPASSES, 0..5] of real;
     i, k: integer;
     rx, ry, oy: real;
+    PassesNum: Longword;
 begin
-TryDo(PassesNum < MAXPASSES, 'Passes number too big', true);
-for i:= 0 to Pred(PassesNum) do  // initialize random parameters
-    begin
-    ar[i, 0]:= 20 + getrandom(45);
-    ar[i, 1]:= 0.005 + getrandom * 0.015;
-    ar[i, 2]:= getrandom * pi * 2;
-    ar[i, 3]:= 20 + getrandom(45);
-    ar[i, 4]:= 0.005 + getrandom * 0.015;
-    ar[i, 5]:= getrandom * pi * 2;
-    end;
+with Template do
+     begin
+     PassesNum:= PassMin + getrandom(PassDelta);
+     TryDo(PassesNum < MAXPASSES, 'Passes number too big', true);
+     for i:= 1 to PassesNum do  // initialize random parameters
+         begin
+         ar[i, 0]:= WaveAmplMin + getrandom * WaveAmplDelta;
+         ar[i, 1]:= WaveFreqMin + getrandom * WaveFreqDelta;
+         ar[i, 2]:= getrandom * pi * 2;
+         ar[i, 3]:= WaveAmplMin + getrandom * WaveAmplDelta;
+         ar[i, 4]:= WaveFreqMin + getrandom * WaveFreqDelta;
+         ar[i, 5]:= getrandom * pi * 2;
+         end;
+     end;
 
 for k:= 0 to Pred(pa.Count) do  // apply transformation
     begin
     rx:= pa.ar[k].x;
     ry:= pa.ar[k].y;
-    for i:= 0 to Pred(PassesNum) do
+    for i:= 0 to PassesNum do
         begin
         oy:= ry;
         ry:= ry + ar[i, 0] * sin(ar[i, 1] * rx + ar[i, 2]);
@@ -526,17 +517,32 @@
         end;
 end;
 
-procedure GenLandSurface;
+procedure GenBlank(var Template: TEdgeTemplate);
 var pa: TPixAr;
-    tmpsurf: PSDL_Surface;
+    i: Longword;
 begin
-GenEdge(0, pa);
-BezierizeEdge(pa, 0.33334);
-BezierizeEdge(pa, 0.33334);
-BezierizeEdge(pa, 0.33334); 
-PointWave(pa, 3);
-DrawBezierEdge(pa);
-FillLand(1023, 1023);
+with Template do
+     begin
+     pa.Count:= BasePointsCount;
+     for i:= 0 to pred(pa.Count) do
+         pa.ar[i]:= BasePoints^[i];
+
+     for i:= 1 to BezPassCnt do
+         BezierizeEdge(pa, 0.33333334);
+
+     PointWave(Template, pa);
+     DrawBezierEdge(pa);
+
+     for i:= 0 to pred(FillPointsCount) do
+         with FillPoints^[i] do
+              FillLand(x, y)
+     end;
+end;
+
+procedure GenLandSurface;
+var tmpsurf: PSDL_Surface;
+begin
+GenBlank(EdgeTemplates[getrandom(Succ(High(EdgeTemplates)))]);
 
 AddProgress;
 with PixelFormat^ do
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uLandTemplates.pas	Sun Dec 04 19:06:56 2005 +0000
@@ -0,0 +1,108 @@
+unit uLandTemplates;
+interface
+uses SDLh;
+{$INCLUDE options.inc}
+
+type PPointArray = ^TPointArray;
+     TPointArray = array[0..0] of TPoint;
+     TEdgeTemplate = record
+                     BasePoints: PPointArray;
+                     BasePointsCount: Longword;
+                     BezPassCnt: Longword; 
+                     PassMin, PassDelta: Longword;
+                     WaveAmplMin, WaveAmplDelta: real;
+                     WaveFreqMin, WaveFreqDelta: real;
+                     FillPoints: PPointArray;
+                     FillPointsCount: Longword;
+                     end;
+
+const Template0Points: array[0..4] of TPoint =
+      (
+       (x:  500; y: 1500),
+       (x:  350; y:  400),
+       (x: 1023; y:  820),
+       (x: 1700; y:  400),
+       (x: 1550; y: 1500)
+      );
+      Template0FPoints: array[0..0] of TPoint =
+      (
+       (x: 1023; y: 1023)
+      );
+
+const Template1Points: array[0..6] of TPoint =
+      (
+       (x:  300; y: 1500),
+       (x:  300; y: 1000),
+       (x:  250; y:  750),
+       (x: 1023; y:  600),
+       (x: 1800; y:  750),
+       (x: 1750; y: 1000),
+       (x: 1750; y: 1500)
+      );
+      Template1FPoints: array[0..0] of TPoint =
+      (
+       (x: 1023; y: 1023)
+      );
+
+const Template2Points: array[0..18] of TPoint =
+      (
+       (x:  350; y: 1500),
+       (x:  350; y: 1000),
+       (x:  190; y:  650),
+       (x:  210; y:  260),
+       (x: 1650; y:  220),
+       (x: 1650; y:  460),
+       (x:  900; y:  410),
+       (x:  650; y:  400),
+       (x: 1200; y: 1000),
+       (x: 1200; y: 1200),
+       (x: 1400; y: 1200),
+       (x: 1400; y: 1000),
+       (x: 1280; y:  750),
+       (x: 1150; y:  530),
+       (x: 1700; y:  750),
+       (x: 1800; y:  600),
+       (x: 1900; y:  600),
+       (x: 1700; y: 1010),
+       (x: 1700; y: 1200)
+      );
+      Template2FPoints: array[0..1] of TPoint =
+      (
+       (x:  600; y: 1023),
+       (x: 1500; y: 1023)
+      );
+
+const EdgeTemplates: array[0..2] of TEdgeTemplate =
+      (
+       (BasePoints: @Template0Points;
+        BasePointsCount: Succ(High(Template0Points));
+        BezPassCnt: 4;
+        PassMin: 5; PassDelta: 1;
+        WaveAmplMin:    27; WaveAmplDelta: 22;
+        WaveFreqMin: 0.010; WaveFreqDelta: 0.015;
+        FillPoints: @Template0FPoints;
+        FillPointsCount: Succ(High(Template0FPoints));
+       ),
+       (BasePoints: @Template1Points;
+        BasePointsCount: Succ(High(Template1Points));
+        BezPassCnt: 4;
+        PassMin: 6; PassDelta: 2;
+        WaveAmplMin:    20; WaveAmplDelta: 10;
+        WaveFreqMin: 0.015; WaveFreqDelta: 0.020;
+        FillPoints: @Template1FPoints;
+        FillPointsCount: Succ(High(Template1FPoints));
+       ),
+       (BasePoints: @Template2Points;
+        BasePointsCount: Succ(High(Template2Points));
+        BezPassCnt: 2;
+        PassMin: 4; PassDelta: 1;
+        WaveAmplMin:    30; WaveAmplDelta: 15;
+        WaveFreqMin: 0.010; WaveFreqDelta: 0.015;
+        FillPoints: @Template2FPoints;
+        FillPointsCount: Succ(High(Template2FPoints));
+       )
+      );
+
+implementation
+
+end.
--- a/hedgewars/uWorld.pas	Sun Dec 04 15:28:31 2005 +0000
+++ b/hedgewars/uWorld.pas	Sun Dec 04 19:06:56 2005 +0000
@@ -108,6 +108,7 @@
 r.y:= WorldDy + cWaterLine + 32;
 if r.y < cScreenHeight then
    begin
+   if r.y < 0 then r.y:= 0;
    r.h:= cScreenHeight - r.y;
    r.x:= 0;
    r.w:= cScreenWidth;