- 2 more Land templates
authorunc0rr
Tue, 20 Jun 2006 21:20:06 +0000
changeset 67 3101306251e5
parent 66 9643d75baf1e
child 68 cbb93eb90304
- 2 more Land templates - prevent generated land to be outbound
hedgewars/uLand.pas
hedgewars/uLandTemplates.pas
--- a/hedgewars/uLand.pas	Tue Jun 20 21:18:49 2006 +0000
+++ b/hedgewars/uLand.pas	Tue Jun 20 21:20:06 2006 +0000
@@ -427,6 +427,54 @@
     end;
 end;
 
+procedure NormalizePoints(var pa: TPixAr);
+const brd = 32;
+var isUP: boolean;  // HACK: transform for Y should be exact as one for X  
+    Left, Right, Top, Bottom,
+    OWidth, Width, OHeight, Height,
+    OLeft: integer;
+    i: integer;
+begin
+TryDo((pa.ar[0].y < 0) or (pa.ar[0].y > 1023), 'Bad land generated', true);
+isUP:= pa.ar[0].y > 0;
+Left:= 1023;
+Right:= Left;
+Top:= pa.ar[0].y;
+Bottom:= Top;
+
+for i:= 1 to Pred(pa.Count) do
+    with pa.ar[i] do
+         begin
+         if (y and $FFFFFC00) = 0 then
+            if x < Left then Left:= x else
+            if x > Right then Right:= x;
+         if y < Top then Top:= y else
+         if y > Bottom then Bottom:= y
+         end;
+
+if (Left < brd) or (Right > 2047 - brd) then
+   begin
+   OLeft:= Left;
+   OWidth:= Right - OLeft;
+   if Left < brd then Left:= brd;
+   if Right > 2047 - brd then Right:= 2047 - brd;
+   Width:= Right - Left;
+   for i:= 0 to Pred(pa.Count) do
+       with pa.ar[i] do
+            x:= round((x - OLeft) * Width div OWidth + Left)
+   end;
+
+if isUp then // FIXME: remove hack
+   if Top < brd then
+      begin
+      OHeight:= 1023 - Top;
+      Height:= 1023 - brd;
+      for i:= 0 to Pred(pa.Count) do
+          with pa.ar[i] do
+               y:= round((y - 1023) * Height div OHeight + 1023)
+   end;
+end;
+
 procedure GenBlank(var Template: TEdgeTemplate);
 var pa: TPixAr;
     i: Longword;
@@ -459,6 +507,7 @@
          BezierizeEdge(pa, 0.33333334);
 
      PointWave(Template, pa);
+     NormalizePoints(pa);
      DrawBezierEdge(pa);
 
      for i:= 0 to pred(FillPointsCount) do
@@ -479,11 +528,13 @@
 AddProgress;
 with PixelFormat^ do
      tmpsurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
+TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true);
 ColorizeLand(tmpsurf);
 AddProgress;
 AddBorder(tmpsurf);
 with PixelFormat^ do
      LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
+TryDo(LandSurface <> nil, 'Error creating land surface', true);
 SDL_FillRect(LandSurface, nil, 0);
 AddProgress;
 
--- a/hedgewars/uLandTemplates.pas	Tue Jun 20 21:18:49 2006 +0000
+++ b/hedgewars/uLandTemplates.pas	Tue Jun 20 21:20:06 2006 +0000
@@ -364,7 +364,47 @@
        (x: 1023; y:    0)
       );
 
-const EdgeTemplates: array[0..9] of TEdgeTemplate =
+const Template10Points: array[0..13] of TPoint =
+      (
+       (x:  336; y: 1476),
+       (x:  303; y: 1026),
+       (x:  225; y:  921),
+       (x:  216; y:  741),
+       (x:  774; y:  810),
+       (x:  687; y:  336),
+       (x:  975; y:  192),
+       (x: 1350; y:  324),
+       (x: 1230; y:  681),
+       (x: 1257; y:  855),
+       (x: 1623; y:  846),
+       (x: 1821; y:  657),
+       (x: 1911; y:  897),
+       (x: 1704; y: 1446)
+      );
+      Template10FPoints: array[0..0] of TPoint =
+      (
+       (x: 1023; y:    0)
+      );
+
+const Template11Points: array[0..9] of TPoint =
+      (
+       (x:  270; y: 1407),
+       (x:  180; y:  795),
+       (x:  453; y:  753),
+       (x:  537; y:  900),
+       (x:  822; y:  729),
+       (x: 1128; y:  882),
+       (x: 1269; y:  657),
+       (x: 1560; y:  915),
+       (x: 1812; y:  867),
+       (x: 1854; y: 1347)
+      );
+      Template11FPoints: array[0..0] of TPoint =
+      (
+       (x: 1023; y:    0)
+      );
+
+const EdgeTemplates: array[0..11] of TEdgeTemplate =
       (
        (BasePoints: @Template0Points;
         BasePointsCount: Succ(High(Template0Points));
@@ -457,7 +497,7 @@
        canMirror: true; canFlip: false;
       ),
       (BasePoints: @Template9Points;
-       BasePointsCount: Succ(High(Template8Points));
+       BasePointsCount: Succ(High(Template9Points));
        BezPassCnt: 4;
        PassMin: 17; PassDelta: 3;
        WaveAmplMin:    10; WaveAmplDelta: 10;
@@ -465,6 +505,26 @@
        FillPoints: @Template9FPoints;
        FillPointsCount: Succ(High(Template9FPoints));
        canMirror: true; canFlip: false;
+      ),
+      (BasePoints: @Template10Points;
+       BasePointsCount: Succ(High(Template10Points));
+       BezPassCnt: 4;
+       PassMin: 15; PassDelta: 2;
+       WaveAmplMin:    15; WaveAmplDelta: 10;
+       WaveFreqMin: 0.008; WaveFreqDelta: 0.002;
+       FillPoints: @Template10FPoints;
+       FillPointsCount: Succ(High(Template10FPoints));
+       canMirror: false; canFlip: false;
+      ),
+      (BasePoints: @Template11Points;
+       BasePointsCount: Succ(High(Template11Points));
+       BezPassCnt: 4;
+       PassMin: 15; PassDelta: 1;
+       WaveAmplMin:    10; WaveAmplDelta: 10;
+       WaveFreqMin: 0.008; WaveFreqDelta: 0.002;
+       FillPoints: @Template11FPoints;
+       FillPointsCount: Succ(High(Template11FPoints));
+       canMirror: true; canFlip: false;
       )
       );