hedgewars/uLand.pas
author unc0rr
Mon, 22 Aug 2005 13:35:41 +0000
changeset 1 30f2d1037d5d
child 4 bcbd7adb4e4b
permissions -rw-r--r--
Add current sources. hw, hwserv and runhelper are compilable under Windows and *nix with FreePascal (and use -Od option) and run well on these OSes Hedge.dpr can be run only in Windows... to be ported
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     1
(*
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     4
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     6
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     9
 * with the Software without restriction, including without limitation the
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    12
 * furnished to do so, subject to the following conditions:
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    13
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    15
 *    this list of conditions and the following disclaimer.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    18
 *    and/or other materials provided with the distribution.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    20
 *    derived from this software without specific prior written permission.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    21
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    32
 *)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    33
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    34
unit uLand;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    35
interface
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    36
uses SDLh;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    37
{$include options.inc}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    38
type TLandArray = packed array[0..1023, 0..2047] of LongWord;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    39
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    40
var  Land: TLandArray;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    41
     LandSurface: PSDL_Surface;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    42
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    43
procedure GenLandSurface;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    44
procedure MakeFortsMap;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    45
procedure AddHHPoint(_x, _y: integer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    46
procedure GetHHPoint(out _x, _y: integer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    47
procedure RandomizeHHPoints;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    48
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    49
implementation
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    50
uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    51
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    52
type TPixAr = record
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    53
              Count: Longword;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    54
              ar: array[word] of TPoint;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    55
              end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    56
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    57
var HHPoints: record
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    58
              First, Last: word;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    59
              ar: array[1..Pred(cMaxHHs)] of TPoint
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    60
              end = (First: 1);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    61
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    62
procedure BlitImageAndGenerateCollisionInfo(cpX, cpY: Longword; Image, Surface: PSDL_Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    63
var i, p: LongWord;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    64
    x, y: Longword;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    65
    bpp: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    66
    r: TSDL_Rect;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    67
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    68
r.x:= cpX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    69
r.y:= cpY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    70
SDL_UpperBlit(Image, nil, Surface, @r);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    71
WriteToConsole('Generating collision info... ');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    72
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    73
if SDL_MustLock(Image) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    74
   SDLTry(SDL_LockSurface(Image) >= 0, true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    75
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    76
bpp:= Image.format.BytesPerPixel;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    77
WriteToConsole('('+inttostr(bpp)+') ');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    78
p:= LongWord(Image.pixels);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    79
case bpp of
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    80
     1: OutError('We don''t work with 8 bit surfaces', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    81
     2: for y:= 0 to Pred(Image.h) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    82
            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    83
            i:= Longword(@Land[cpY + y, cpX]);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    84
            for x:= 0 to Pred(Image.w) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    85
                if PWord(p + x * 2)^ = 0 then PLongWord(i + x * 4)^:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    86
                                         else PLongWord(i + x * 4)^:= 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    87
            inc(p, Image.pitch);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    88
            end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    89
     3: for y:= 0 to Pred(Image.h) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    90
            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    91
            i:= Longword(@Land[cpY + y, cpX]);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    92
            for x:= 0 to Pred(Image.w) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    93
                if  (PByte(p + x * 3 + 0)^ = 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    94
                and (PByte(p + x * 3 + 1)^ = 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    95
                and (PByte(p + x * 3 + 2)^ = 0) then PLongWord(i + x * 4)^:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    96
                                                else PLongWord(i + x * 4)^:= 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    97
            inc(p, Image.pitch);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    98
            end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    99
     4: for y:= 0 to Pred(Image.h) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   100
            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   101
            i:= Longword(@Land[cpY + y, cpX]);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   102
            for x:= 0 to Pred(Image.w) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   103
                if PLongword(p + x * 4)^ = 0 then PLongWord(i + x * 4)^:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   104
                                             else PLongWord(i + x * 4)^:= 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   105
            inc(p, Image.pitch);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   106
            end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   107
     end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   108
if SDL_MustLock(Image) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   109
   SDL_UnlockSurface(Image);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   110
WriteLnToConsole(msgOK)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   111
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   112
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   113
procedure GenEdge(out pa: TPixAr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   114
var angle, r: real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   115
    len1: Longword;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   116
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   117
len1:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   118
angle:= 5*pi/6;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   119
r:= 410;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   120
repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   121
  angle:= angle + 0.1 + getrandom * 0.1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   122
  pa.ar[len1].X:= 544  + trunc(r*cos(angle));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   123
  pa.ar[len1].Y:= 1080 + trunc(1.5*r*sin(angle));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   124
  if r<380 then r:= r+getrandom*110
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   125
           else r:= r - getrandom*80;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   126
  inc(len1);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   127
until angle > 7/4*pi;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   128
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   129
angle:= -pi/6;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   130
r:= 510;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   131
pa.ar[len1].X:= 644 + trunc(r*cos(angle));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   132
pa.ar[len1].Y:= 1080 + trunc(r*sin(angle));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   133
angle:= -pi;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   134
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   135
repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   136
  angle:= angle + 0.1 + getrandom*0.1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   137
  pa.ar[len1].X:= 1504 + trunc(r*cos(angle));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   138
  pa.ar[len1].Y:= 880 + trunc(1.5*r*sin(angle));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   139
  if r<410 then r:= r + getrandom*80
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   140
           else r:= r - getrandom*110;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   141
  inc(len1);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   142
until angle > 1/4*pi;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   143
pa.ar[len1]:= pa.ar[0];
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   144
pa.Count:= Succ(len1)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   145
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   146
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   147
procedure DrawBezierBorder(var pa: TPixAr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   148
var x, y, i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   149
    tx, ty, vx, vy, vlen, t: real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   150
    r1, r2, r3, r4: real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   151
    x1, y1, x2, y2, cx1, cy1, cx2, cy2, tsq, tcb: real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   152
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   153
vx:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   154
vy:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   155
with pa do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   156
for i:= 0 to Count-2 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   157
    begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   158
    vlen:= sqrt(sqr(ar[i + 1].x - ar[i    ].X) + sqr(ar[i + 1].y - ar[i    ].y));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   159
    t:=    sqrt(sqr(ar[i + 1].x - ar[i + 2].X) + sqr(ar[i + 1].y - ar[i + 2].y));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   160
    if t<vlen then vlen:= t;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   161
    vlen:= vlen/3;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   162
    tx:= ar[i+2].X - ar[i].X;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   163
    ty:= ar[i+2].y - ar[i].y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   164
    t:= sqrt(sqr(tx)+sqr(ty));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   165
    if t = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   166
       begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   167
       tx:= -tx * 100000;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   168
       ty:= -ty * 100000;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   169
       end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   170
       begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   171
       tx:= -tx/t;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   172
       ty:= -ty/t;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   173
       end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   174
    t:= 1.0*vlen;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   175
    tx:= tx*t;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   176
    ty:= ty*t;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   177
    x1:= ar[i].x;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   178
    y1:= ar[i].y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   179
    x2:= ar[i + 1].x;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   180
    y2:= ar[i + 1].y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   181
    cx1:= ar[i].X   + trunc(vx);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   182
    cy1:= ar[i].y   + trunc(vy);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   183
    cx2:= ar[i+1].X + trunc(tx);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   184
    cy2:= ar[i+1].y + trunc(ty);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   185
    vx:= -tx;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   186
    vy:= -ty;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   187
    t:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   188
    while t <= 1.0 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   189
          begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   190
          tsq:= sqr(t);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   191
          tcb:= tsq * t;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   192
          r1:= (1 - 3*t + 3*tsq -   tcb) * x1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   193
          r2:= (    3*t - 6*tsq + 3*tcb) * cx1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   194
          r3:= (          3*tsq - 3*tcb) * cx2;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   195
          r4:= (                    tcb) * x2;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   196
          X:= round(r1 + r2 + r3 + r4);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   197
          r1:= (1 - 3*t + 3*tsq -   tcb) * y1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   198
          r2:= (    3*t - 6*tsq + 3*tcb) * cy1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   199
          r3:= (          3*tsq - 3*tcb) * cy2;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   200
          r4:= (                    tcb) * y2;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   201
          Y:= round(r1 + r2 + r3 + r4);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   202
          t:= t + 0.001;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   203
          if ((x and $FFFFF800) = 0) and ((y and $FFFFFC00) = 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   204
                Land[y, x]:= $FFFFFF;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   205
          end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   206
    end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   207
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   208
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   209
procedure FillLand(x, y: integer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   210
var Stack: record
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   211
           Count: Longword;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   212
           points: array[0..8192] of record
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   213
                                     xl, xr, y, dir: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   214
                                     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   215
           end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   216
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   217
    procedure Push(_xl, _xr, _y, _dir: integer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   218
    begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   219
    _y:= _y + _dir;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   220
    if (_y < 0) or (_y > 1023) then exit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   221
    with Stack.points[Stack.Count] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   222
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   223
         xl:= _xl;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   224
         xr:= _xr;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   225
         y:= _y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   226
         dir:= _dir
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   227
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   228
    inc(Stack.Count);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   229
    TryDo(Stack.Count < 8192, 'stack overflow', true)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   230
    end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   231
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   232
    procedure Pop(out _xl, _xr, _y, _dir: integer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   233
    begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   234
    dec(Stack.Count);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   235
    with Stack.points[Stack.Count] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   236
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   237
         _xl:= xl;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   238
         _xr:= xr;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   239
         _y:= y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   240
         _dir:= dir
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   241
         end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   242
    end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   243
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   244
var xl, xr, dir: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   245
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   246
Stack.Count:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   247
xl:= x - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   248
xr:= x;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   249
Push(xl, xr, 1024, -1);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   250
while Stack.Count > 0 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   251
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   252
      Pop(xl, xr, y, dir);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   253
      while (xl > 0) and (Land[y, xl] = 0) do dec(xl);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   254
      while (xr < 2047) and (Land[y, xr] = 0) do inc(xr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   255
      while (xl < xr) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   256
            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   257
            while (xl <= xr) and (Land[y, xl] <> 0) do inc(xl);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   258
            x:= xl;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   259
            while (xl <= xr) and (Land[y, xl] = 0) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   260
                  begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   261
                  Land[y, xl]:= $FFFFFF;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   262
                  inc(xl)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   263
                  end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   264
            if x < xl then Push(x, Pred(xl), y, dir)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   265
            end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   266
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   267
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   268
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   269
procedure ColorizeLand(Surface: PSDL_Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   270
var tmpsurf: PSDL_Surface;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   271
    r: TSDL_Rect;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   272
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   273
tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + 'LandTex.png');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   274
r.y:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   275
while r.y < 1024 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   276
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   277
      r.x:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   278
      while r.x < 2048 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   279
            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   280
            SDL_UpperBlit(tmpsurf, nil, Surface, @r);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   281
            inc(r.x, tmpsurf.w)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   282
            end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   283
      inc(r.y, tmpsurf.h)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   284
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   285
SDL_FreeSurface(tmpsurf);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   286
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   287
tmpsurf:= SDL_CreateRGBSurfaceFrom(@Land, 2048, 1024, 32, 2048*4, $FF0000, $FF00, $FF, 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   288
SDLTry(tmpsurf <> nil, true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   289
SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   290
SDL_UpperBlit(tmpsurf, nil, Surface, nil)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   291
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   292
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   293
procedure AddBorder(Surface: PSDL_Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   294
var tmpsurf: PSDL_Surface;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   295
    r, rr: TSDL_Rect;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   296
    x, yd, yu: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   297
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   298
tmpsurf:= LoadImage(Pathz[ptThemeCurrent] + 'Border.png');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   299
for x:= 0 to 2047 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   300
    begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   301
    yd:= 1023;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   302
    repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   303
      while (yd > 0   ) and (Land[yd, x] =  0) do dec(yd);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   304
      if (yd < 0) then yd:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   305
      while (yd < 1024) and (Land[yd, x] <> 0) do inc(yd);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   306
      dec(yd);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   307
      yu:= yd;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   308
      while (yu > 0  ) and (Land[yu, x] <> 0) do dec(yu);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   309
      while (yu < yd ) and (Land[yu, x] =  0) do inc(yu);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   310
      if (yd < 1023) and ((yd - yu) >= 16) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   311
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   312
         rr.x:= x;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   313
         rr.y:= yd - 15;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   314
         r.x:= x mod tmpsurf.w;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   315
         r.y:= 16;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   316
         r.w:= 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   317
         r.h:= 16;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   318
         SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   319
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   320
      if (yu > 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   321
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   322
         rr.x:= x;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   323
         rr.y:= yu;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   324
         r.x:= x mod tmpsurf.w;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   325
         r.y:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   326
         r.w:= 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   327
         r.h:= min(16, yd - yu + 1);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   328
         SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   329
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   330
      yd:= yu - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   331
    until yd < 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   332
    end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   333
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   334
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   335
procedure AddGirders(Surface: PSDL_Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   336
var tmpsurf: PSDL_Surface;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   337
    x1, x2, y, k, i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   338
    r, rr: TSDL_Rect;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   339
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   340
    function CountZeroz(x, y: integer): Longword;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   341
    var i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   342
    begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   343
    Result:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   344
    for i:= y to y + 15 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   345
        if Land[i, x] <> 0 then inc(Result)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   346
    end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   347
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   348
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   349
y:= 256;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   350
repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   351
  inc(y, 24);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   352
  x1:= 1024;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   353
  x2:= 1024;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   354
  while (x1 > 100) and (CountZeroz(x1, y) = 0) do dec(x1, 2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   355
  i:= x1 - 12;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   356
  repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   357
    k:= CountZeroz(x1, y);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   358
    dec(x1, 2)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   359
  until (x1 < 100) or (k = 0) or (k = 16) or (x1 < i);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   360
  inc(x1, 2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   361
  if k = 16 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   362
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   363
     while (x2 < 1900) and (CountZeroz(x2, y) = 0) do inc(x2, 2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   364
     i:= x2 + 12;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   365
     repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   366
       k:= CountZeroz(x2, y);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   367
       inc(x2, 2)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   368
     until (x2 > 1900) or (k = 0) or (k = 16) or (x2 > i);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   369
     if (x2 < 1900) and (k = 16) and (x2 - x1 > 250) then break;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   370
     end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   371
x1:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   372
until y > 900;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   373
if x1 > 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   374
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   375
   tmpsurf:= LoadImage(Pathz[ptGraphics] + 'Girder.png');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   376
   rr.x:= x1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   377
   rr.y:= y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   378
   while rr.x + 100 < x2 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   379
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   380
         SDL_UpperBlit(tmpsurf, nil, Surface, @rr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   381
         inc(rr.x, 100);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   382
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   383
   r.x:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   384
   r.y:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   385
   r.w:= x2 - rr.x;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   386
   r.h:= 16;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   387
   SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   388
   SDL_FreeSurface(tmpsurf);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   389
   for k:= y to y + 15 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   390
       for i:= x1 to x2 do Land[k, i]:= $FFFFFF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   391
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   392
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   393
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   394
procedure AddHHPoints;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   395
var i, x, y: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   396
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   397
for i:= 0 to 9 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   398
    begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   399
    y:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   400
    x:= i * 160 + 300;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   401
    repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   402
    inc(y, 2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   403
    until (y > 1023) or (Land[y, x - 6] <> 0) or (Land[y, x - 3] <> 0) or (Land[y, x] <> 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   404
                     or (Land[y, x + 3] <> 0) or (Land[y, x + 6] <> 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   405
    AddHHPoint(x, y - 12)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   406
    end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   407
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   408
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   409
procedure GenLandSurface;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   410
var pa: TPixAr;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   411
    tmpsurf: PSDL_Surface;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   412
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   413
GenEdge(pa);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   414
DrawBezierBorder(pa);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   415
FillLand(1023, 1023);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   416
AddProgress;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   417
with PixelFormat^ do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   418
     tmpsurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   419
ColorizeLand(tmpsurf);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   420
AddProgress;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   421
AddBorder(tmpsurf);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   422
with PixelFormat^ do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   423
     LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   424
SDL_FillRect(LandSurface, nil, 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   425
AddGirders(LandSurface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   426
SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   427
SDL_UpperBlit(tmpsurf, nil, LandSurface, nil);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   428
SDL_FreeSurface(tmpsurf);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   429
AddProgress;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   430
AddHHPoints;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   431
RandomizeHHPoints;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   432
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   433
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   434
procedure MakeFortsMap;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   435
var p: PTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   436
    tmpsurf: PSDL_Surface;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   437
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   438
p:= TeamsList;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   439
TryDo(p <> nil, 'No teams on map!', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   440
with PixelFormat^ do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   441
     LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   442
tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'L.png');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   443
BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   444
SDL_FreeSurface(tmpsurf);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   445
p:= p.Next;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   446
TryDo(p <> nil, 'Only one team on map!', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   447
tmpsurf:= LoadImage(Pathz[ptForts] + p.FortName + 'R.png');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   448
BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   449
SDL_FreeSurface(tmpsurf);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   450
p:= p.Next;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   451
TryDo(p = nil, 'More than 2 teams on map in forts mode!', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   452
AddHHPoints
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   453
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   454
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   455
procedure AddHHPoint(_x, _y: integer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   456
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   457
with HHPoints do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   458
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   459
     inc(Last);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   460
     TryDo(Last < cMaxHHs, 'HHs coords queue overflow', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   461
     with ar[Last] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   462
          begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   463
          x:= _x;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   464
          y:= _y
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   465
          end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   466
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   467
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   468
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   469
procedure GetHHPoint(out _x, _y: integer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   470
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   471
with HHPoints do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   472
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   473
     TryDo(First <= Last, 'HHs coords queue underflow ' + inttostr(First), true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   474
     with ar[First] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   475
          begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   476
          _x:= x;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   477
          _y:= y
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   478
          end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   479
     inc(First)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   480
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   481
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   482
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   483
procedure RandomizeHHPoints;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   484
var i, t: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   485
    p: TPoint;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   486
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   487
with HHPoints do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   488
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   489
     for i:= First to Last do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   490
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   491
         t:= GetRandom(Last - First + 1) + First;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   492
         if i <> t then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   493
            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   494
            p:= ar[i];
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   495
            ar[i]:= ar[t];
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   496
            ar[t]:= p
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   497
            end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   498
         end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   499
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   500
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   501
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   502
end.