hedgewars/uLandObjects.pas
author unc0rr
Fri, 23 Jun 2006 20:02:41 +0000
changeset 70 82d93eeecebe
parent 56 a29135563e94
child 74 42257fee61ae
permissions -rw-r--r--
- Many AI improvements - New 'spray objects' on generated land - Many small fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     1
(*
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     2
 * Hedgewars, a worms-like game
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     3
 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     4
 *
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     6
 *
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
     9
 * with the Software without restriction, including without limitation the
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    12
 * furnished to do so, subject to the following conditions:
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    13
 *
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    15
 *    this list of conditions and the following disclaimer.
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    18
 *    and/or other materials provided with the distribution.
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    20
 *    derived from this software without specific prior written permission.
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    21
 *
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    32
 *)
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 35
diff changeset
    33
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    34
unit uLandObjects;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    35
interface
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    36
uses SDLh;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    37
{$include options.inc}
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    38
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    39
procedure AddObjects(InSurface, Surface: PSDL_Surface);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    40
procedure BlitImageAndGenerateCollisionInfo(cpX, cpY: Longword; Image, Surface: PSDL_Surface);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    41
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    42
implementation
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    43
uses uLand, uStore, uConsts, uMisc, uConsole, uRandom;
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
    44
const MaxRects = 256;
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
    45
      MAXOBJECTRECTS = 16;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    46
      MAXTHEMEOBJECTS = 32;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    47
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    48
type PRectArray = ^TRectsArray;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    49
     TRectsArray = array[0..MaxRects] of TSDL_Rect;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    50
     TThemeObject = record
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    51
                    Surf: PSDL_Surface;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    52
                    inland: TSDL_Rect;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    53
                    outland: array[0..Pred(MAXOBJECTRECTS)] of TSDL_Rect;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    54
                    rectcnt: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    55
                    Width, Height: Longword;
56
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
    56
                    Maxcnt: Longword;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    57
                    end;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    58
     TThemeObjects = record
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    59
                     Count: integer;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    60
                     objs: array[0..Pred(MAXTHEMEOBJECTS)] of TThemeObject;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    61
                     end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    62
     TSprayObject = record
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    63
                    Surf: PSDL_Surface;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    64
                    Width, Height: Longword;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    65
                    Maxcnt: Longword;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    66
                    end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    67
     TSprayObjects = record
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    68
                     Count: integer;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    69
                     objs: array[0..Pred(MAXTHEMEOBJECTS)] of TSprayObject
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    70
                     end;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    71
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    72
var Rects: PRectArray;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    73
    RectCount: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    74
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    75
procedure BlitImageAndGenerateCollisionInfo(cpX, cpY: Longword; Image, Surface: PSDL_Surface);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    76
var i, p: LongWord;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    77
    x, y: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    78
    bpp: integer;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    79
    r: TSDL_Rect;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    80
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    81
r.x:= cpX;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    82
r.y:= cpY;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    83
SDL_UpperBlit(Image, nil, Surface, @r);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    84
WriteToConsole('Generating collision info... ');
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    85
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    86
if SDL_MustLock(Image) then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    87
   SDLTry(SDL_LockSurface(Image) >= 0, true);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    88
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    89
bpp:= Image.format.BytesPerPixel;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    90
WriteToConsole('('+inttostr(bpp)+') ');
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    91
p:= LongWord(Image.pixels);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    92
case bpp of
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    93
     1: OutError('We don''t work with 8 bit surfaces', true);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    94
     2: for y:= 0 to Pred(Image.h) do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    95
            begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    96
            i:= Longword(@Land[cpY + y, cpX]);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    97
            for x:= 0 to Pred(Image.w) do
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
    98
                if PWord(p + x * 2)^ <> 0 then PLongWord(i + x * 4)^:= COLOR_LAND;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    99
            inc(p, Image.pitch);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   100
            end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   101
     3: for y:= 0 to Pred(Image.h) do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   102
            begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   103
            i:= Longword(@Land[cpY + y, cpX]);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   104
            for x:= 0 to Pred(Image.w) do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   105
                if  (PByte(p + x * 3 + 0)^ <> 0)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   106
                 or (PByte(p + x * 3 + 1)^ <> 0)
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   107
                 or (PByte(p + x * 3 + 2)^ <> 0) then PLongWord(i + x * 4)^:= COLOR_LAND;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   108
            inc(p, Image.pitch);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   109
            end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   110
     4: for y:= 0 to Pred(Image.h) do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   111
            begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   112
            i:= Longword(@Land[cpY + y, cpX]);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   113
            for x:= 0 to Pred(Image.w) do
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   114
                if PLongword(p + x * 4)^ <> 0 then PLongWord(i + x * 4)^:= COLOR_LAND;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   115
            inc(p, Image.pitch);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   116
            end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   117
     end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   118
if SDL_MustLock(Image) then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   119
   SDL_UnlockSurface(Image);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   120
WriteLnToConsole(msgOK)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   121
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   122
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   123
procedure AddRect(x1, y1, w1, h1: integer);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   124
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   125
with Rects[RectCount] do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   126
     begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   127
     x:= x1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   128
     y:= y1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   129
     w:= w1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   130
     h:= h1
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   131
     end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   132
inc(RectCount);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   133
TryDo(RectCount < MaxRects, 'AddRect: overflow', true)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   134
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   135
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   136
procedure InitRects;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   137
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   138
RectCount:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   139
New(Rects)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   140
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   141
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   142
procedure FreeRects;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   143
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   144
Dispose(rects)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   145
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   146
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   147
function CheckIntersect(x1, y1, w1, h1: integer): boolean;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   148
var i: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   149
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   150
Result:= false;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   151
i:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   152
if RectCount > 0 then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   153
   repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   154
   with Rects[i] do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   155
        Result:= (x < x1 + w1) and (x1 < x + w) and
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   156
                 (y < y1 + h1) and (y1 < y + h);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   157
   inc(i)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   158
   until (i = RectCount) or (Result)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   159
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   160
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   161
function AddGirder(gX: integer; Surface: PSDL_Surface): boolean;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   162
var tmpsurf: PSDL_Surface;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   163
    x1, x2, y, k, i: integer;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   164
    r, rr: TSDL_Rect;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   165
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   166
    function CountNonZeroz(x, y: integer): Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   167
    var i: integer;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   168
    begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   169
    Result:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   170
    for i:= y to y + 15 do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   171
        if Land[i, x] <> 0 then inc(Result)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   172
    end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   173
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   174
begin
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   175
y:= 150;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   176
repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   177
  inc(y, 24);
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   178
  x1:= gX;
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   179
  x2:= gX;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   180
  while (x1 > 100) and (CountNonZeroz(x1, y) = 0) do dec(x1, 2);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   181
  i:= x1 - 12;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   182
  repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   183
    k:= CountNonZeroz(x1, y);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   184
    dec(x1, 2)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   185
  until (x1 < 100) or (k = 0) or (k = 16) or (x1 < i);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   186
  inc(x1, 2);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   187
  if k = 16 then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   188
     begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   189
     while (x2 < 1900) and (CountNonZeroz(x2, y) = 0) do inc(x2, 2);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   190
     i:= x2 + 12;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   191
     repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   192
       k:= CountNonZeroz(x2, y);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   193
       inc(x2, 2)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   194
     until (x2 > 1900) or (k = 0) or (k = 16) or (x2 > i);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   195
     if (x2 < 1900) and (k = 16) and (x2 - x1 > 250)
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 27
diff changeset
   196
        and not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144) then break;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   197
     end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   198
x1:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   199
until y > 900;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   200
if x1 > 0 then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   201
   begin
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   202
   Result:= true;
54
839fd258ae6f - Fixed game loading
unc0rr
parents: 51
diff changeset
   203
   tmpsurf:= LoadImage(Pathz[ptGraphics] + '/Girder.png', false);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   204
   rr.x:= x1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   205
   rr.y:= y;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   206
   while rr.x + 100 < x2 do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   207
         begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   208
         SDL_UpperBlit(tmpsurf, nil, Surface, @rr);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   209
         inc(rr.x, 100);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   210
         end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   211
   r.x:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   212
   r.y:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   213
   r.w:= x2 - rr.x;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   214
   r.h:= 16;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   215
   SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   216
   SDL_FreeSurface(tmpsurf);
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 27
diff changeset
   217
   AddRect(x1 - 8, y - 32, x2 - x1 + 16, 80);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   218
   for k:= y to y + 15 do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   219
       for i:= x1 to x2 do Land[k, i]:= $FFFFFF
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   220
   end else Result:= false
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   221
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   222
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   223
function CheckLand(rect: TSDL_Rect; dX, dY, Color: Longword): boolean;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   224
var i: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   225
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   226
Result:= true;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   227
inc(rect.x, dX);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   228
inc(rect.y, dY);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   229
i:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   230
{$WARNINGS OFF}
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   231
while (i <= rect.w) and Result do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   232
      begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   233
      Result:= (Land[rect.y, rect.x + i] = Color) and (Land[rect.y + rect.h, rect.x + i] = Color);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   234
      inc(i)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   235
      end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   236
i:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   237
while (i <= rect.h) and Result do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   238
      begin
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   239
      Result:= (Land[rect.y + i, rect.x] = Color) and (Land[rect.y + i, rect.x + rect.w] = Color);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   240
      inc(i)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   241
      end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   242
{$WARNINGS ON}
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   243
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   244
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   245
function CheckCanPlace(x, y: Longword; var Obj: TThemeObject): boolean;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   246
var i: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   247
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   248
with Obj do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   249
     if CheckLand(inland, x, y, $FFFFFF) then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   250
        begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   251
        Result:= true;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   252
        i:= 1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   253
        while Result and (i <= rectcnt) do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   254
              begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   255
              Result:= CheckLand(outland[i], x, y, 0);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   256
              inc(i)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   257
              end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   258
        if Result then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   259
           Result:= not CheckIntersect(x, y, Width, Height)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   260
        end else
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   261
        Result:= false
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   262
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   263
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   264
function TryPut(var Obj: TThemeObject; Surface: PSDL_Surface): boolean; overload;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   265
const MaxPointsIndex = 2047;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   266
var x, y: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   267
    ar: array[0..MaxPointsIndex] of TPoint;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   268
    cnt, i: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   269
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   270
cnt:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   271
with Obj do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   272
     begin
56
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   273
     if Maxcnt = 0 then
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   274
        begin
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   275
        Result:= false;
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   276
        exit
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   277
        end;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   278
     x:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   279
     repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   280
         y:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   281
         repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   282
             if CheckCanPlace(x, y, Obj) then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   283
                begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   284
                ar[cnt].x:= x;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   285
                ar[cnt].y:= y;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   286
                inc(cnt);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   287
                if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   288
                   begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   289
                   y:= 5000;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   290
                   x:= 5000;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   291
                   end
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   292
                end;
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   293
             inc(y, 3);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   294
         until y > 1023 - Height;
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   295
         inc(x, getrandom(6) + 3)
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   296
     until x > 2047 - Width;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   297
     Result:= cnt <> 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   298
     if Result then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   299
        begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   300
        i:= getrandom(cnt);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   301
        BlitImageAndGenerateCollisionInfo(ar[i].x, ar[i].y, Obj.Surf, Surface);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   302
        AddRect(ar[i].x, ar[i].y, Width, Height);
56
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   303
        dec(Maxcnt)
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   304
        end else Maxcnt:= 0
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   305
     end
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   306
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   307
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   308
function TryPut(var Obj: TSprayObject; Surface: PSDL_Surface): boolean; overload;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   309
const MaxPointsIndex = 8095;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   310
var x, y: Longword;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   311
    ar: array[0..MaxPointsIndex] of TPoint;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   312
    cnt, i: Longword;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   313
    r: TSDL_Rect;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   314
begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   315
cnt:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   316
with Obj do
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   317
     begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   318
     if Maxcnt = 0 then
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   319
        begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   320
        Result:= false;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   321
        exit
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   322
        end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   323
     x:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   324
     r.x:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   325
     r.y:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   326
     r.w:= Width;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   327
     r.h:= Height + 16;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   328
     repeat
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   329
         y:= 8;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   330
         repeat
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   331
             if CheckLand(r, x, y - 8, $FFFFFF)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   332
                and not CheckIntersect(x, y, Width, Height) then
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   333
                begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   334
                ar[cnt].x:= x;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   335
                ar[cnt].y:= y;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   336
                inc(cnt);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   337
                if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   338
                   begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   339
                   y:= 5000;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   340
                   x:= 5000;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   341
                   end
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   342
                end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   343
             inc(y, 12);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   344
         until y > 1023 - Height - 8;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   345
         inc(x, getrandom(12) + 12)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   346
     until x > 2047 - Width;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   347
     Result:= cnt <> 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   348
     if Result then
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   349
        begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   350
        i:= getrandom(cnt);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   351
        r.x:= ar[i].X;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   352
        r.y:= ar[i].Y;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   353
        r.w:= Width;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   354
        r.h:= Height;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   355
        SDL_UpperBlit(Obj.Surf, nil, Surface, @r);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   356
        AddRect(ar[i].x - 32, ar[i].y - 32, Width + 64, Height + 64);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   357
        dec(Maxcnt)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   358
        end else Maxcnt:= 0
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   359
     end
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   360
end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   361
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   362
procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   363
var s: string;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   364
    f: textfile;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   365
    i, ii: integer;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   366
begin
54
839fd258ae6f - Fixed game loading
unc0rr
parents: 51
diff changeset
   367
s:= Pathz[ptThemeCurrent] + '/' + cThemeCFGFilename;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   368
WriteLnToConsole('Reading objects info...');
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   369
AssignFile(f, s);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   370
{$I-}
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   371
Reset(f);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   372
Readln(f, s); // skip color
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   373
Readln(f, ThemeObjects.Count);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   374
for i:= 0 to Pred(ThemeObjects.Count) do
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   375
    begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   376
    Readln(f, s); // filename
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   377
    with ThemeObjects.objs[i] do
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   378
         begin
54
839fd258ae6f - Fixed game loading
unc0rr
parents: 51
diff changeset
   379
         Surf:= LoadImage(Pathz[ptThemeCurrent] + '/' + s + '.png', false);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   380
         Read(f, Width, Height);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   381
         with inland do Read(f, x, y, w, h);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   382
         Read(f, rectcnt);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   383
         for ii:= 1 to rectcnt do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   384
             with outland[ii] do Read(f, x, y, w, h);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   385
         Maxcnt:= 3;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   386
         ReadLn(f)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   387
         end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   388
    end;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   389
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   390
Readln(f, SprayObjects.Count);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   391
for i:= 0 to Pred(SprayObjects.Count) do
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   392
    begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   393
    Readln(f, s); // filename
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   394
    with SprayObjects.objs[i] do
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   395
         begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   396
         Surf:= LoadImage(Pathz[ptThemeCurrent] + '/' + s + '.png', false);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   397
         Width:= Surf.w;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   398
         Height:= Surf.h;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   399
         ReadLn(f, Maxcnt)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   400
         end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   401
    end;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   402
Closefile(f);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   403
{$I+}
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   404
TryDo(IOResult = 0, 'Bad data or cannot access file ' + cThemeCFGFilename, true)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   405
end;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   406
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   407
procedure AddThemeObjects(Surface: PSDL_Surface; var ThemeObjects: TThemeObjects; MaxCount: integer);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   408
var i, ii, t: integer;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   409
    b: boolean;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   410
begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   411
if ThemeObjects.Count = 0 then exit;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   412
WriteLnToConsole('Adding theme objects...');
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   413
i:= 1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   414
repeat
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   415
    t:= getrandom(ThemeObjects.Count);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   416
    ii:= t;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   417
    repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   418
      inc(ii);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   419
      if ii = ThemeObjects.Count then ii:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   420
      b:= TryPut(ThemeObjects.objs[ii], Surface)
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   421
    until b or (ii = t);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   422
    inc(i)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   423
until (i > MaxCount) or not b;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   424
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   425
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   426
procedure AddSprayObjects(Surface: PSDL_Surface; var SprayObjects: TSprayObjects; MaxCount: Longword);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   427
var i: Longword;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   428
    ii, t: integer;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   429
    b: boolean;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   430
begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   431
if SprayObjects.Count = 0 then exit;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   432
WriteLnToConsole('Adding spray objects...');
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   433
i:= 1;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   434
repeat
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   435
    t:= getrandom(SprayObjects.Count);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   436
    ii:= t;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   437
    repeat
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   438
      inc(ii);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   439
      if ii = SprayObjects.Count then ii:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   440
      b:= TryPut(SprayObjects.objs[ii], Surface)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   441
    until b or (ii = t);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   442
    inc(i)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   443
until (i > MaxCount) or not b;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   444
end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   445
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   446
procedure AddObjects(InSurface, Surface: PSDL_Surface);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   447
var ThemeObjects: TThemeObjects;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   448
    SprayObjects: TSprayObjects;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   449
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   450
InitRects;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   451
AddGirder(256, Surface);
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   452
AddGirder(512, Surface);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   453
AddGirder(768, Surface);
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   454
AddGirder(1024, Surface);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   455
AddGirder(1280, Surface);
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   456
AddGirder(1536, Surface);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   457
AddGirder(1792, Surface);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   458
ReadThemeInfo(ThemeObjects, SprayObjects);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   459
AddThemeObjects(Surface, ThemeObjects, 8);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   460
AddProgress;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   461
SDL_UpperBlit(InSurface, nil, Surface, nil);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   462
AddSprayObjects(Surface, SprayObjects, 10);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   463
FreeRects
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   464
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   465
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   466
end.