hedgewars/uLandObjects.pas
author unc0rr
Wed, 20 Sep 2006 15:33:47 +0000
changeset 154 5667e6f38704
parent 107 b08ce0293a51
child 183 57c2ef19f719
permissions -rw-r--r--
Network protocol uses integers in network byte order
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);
107
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
    76
var p: PByteArray;
24
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)+') ');
107
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
    91
p:= Image.pixels;
24
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
            for x:= 0 to Pred(Image.w) do
107
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
    97
                if PWord(@p[x * 2])^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND;
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
    98
            p:= @p[Image.pitch];
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
    99
            end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   100
     3: for y:= 0 to Pred(Image.h) do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   101
            begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   102
            for x:= 0 to Pred(Image.w) do
107
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
   103
                if  (p[x * 3 + 0] <> 0)
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
   104
                 or (p[x * 3 + 1] <> 0)
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
   105
                 or (p[x * 3 + 2] <> 0) then Land[cpY + y, cpX + x]:= COLOR_LAND;
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
   106
            p:= @p[Image.pitch];
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   107
            end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   108
     4: for y:= 0 to Pred(Image.h) do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   109
            begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   110
            for x:= 0 to Pred(Image.w) do
107
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
   111
                if PLongword(@p[x * 4])^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND;
b08ce0293a51 - Many type fixes
unc0rr
parents: 80
diff changeset
   112
            p:= @p[Image.pitch];
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   113
            end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   114
     end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   115
if SDL_MustLock(Image) then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   116
   SDL_UnlockSurface(Image);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   117
WriteLnToConsole(msgOK)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   118
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   119
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   120
procedure AddRect(x1, y1, w1, h1: integer);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   121
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   122
with Rects[RectCount] do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   123
     begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   124
     x:= x1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   125
     y:= y1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   126
     w:= w1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   127
     h:= h1
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   128
     end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   129
inc(RectCount);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   130
TryDo(RectCount < MaxRects, 'AddRect: overflow', true)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   131
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   132
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   133
procedure InitRects;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   134
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   135
RectCount:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   136
New(Rects)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   137
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   138
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   139
procedure FreeRects;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   140
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   141
Dispose(rects)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   142
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   143
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   144
function CheckIntersect(x1, y1, w1, h1: integer): boolean;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   145
var i: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   146
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   147
Result:= false;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   148
i:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   149
if RectCount > 0 then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   150
   repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   151
   with Rects[i] do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   152
        Result:= (x < x1 + w1) and (x1 < x + w) and
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   153
                 (y < y1 + h1) and (y1 < y + h);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   154
   inc(i)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   155
   until (i = RectCount) or (Result)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   156
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   157
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   158
function AddGirder(gX: integer; Surface: PSDL_Surface): boolean;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   159
var tmpsurf: PSDL_Surface;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   160
    x1, x2, y, k, i: integer;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   161
    r, rr: TSDL_Rect;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   162
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   163
    function CountNonZeroz(x, y: integer): Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   164
    var i: integer;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   165
    begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   166
    Result:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   167
    for i:= y to y + 15 do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   168
        if Land[i, x] <> 0 then inc(Result)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   169
    end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   170
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   171
begin
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   172
y:= 150;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   173
repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   174
  inc(y, 24);
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   175
  x1:= gX;
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   176
  x2:= gX;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   177
  while (x1 > 100) and (CountNonZeroz(x1, y) = 0) do dec(x1, 2);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   178
  i:= x1 - 12;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   179
  repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   180
    k:= CountNonZeroz(x1, y);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   181
    dec(x1, 2)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   182
  until (x1 < 100) or (k = 0) or (k = 16) or (x1 < i);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   183
  inc(x1, 2);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   184
  if k = 16 then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   185
     begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   186
     while (x2 < 1900) and (CountNonZeroz(x2, y) = 0) do inc(x2, 2);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   187
     i:= x2 + 12;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   188
     repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   189
       k:= CountNonZeroz(x2, y);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   190
       inc(x2, 2)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   191
     until (x2 > 1900) or (k = 0) or (k = 16) or (x2 > i);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   192
     if (x2 < 1900) and (k = 16) and (x2 - x1 > 250)
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 27
diff changeset
   193
        and not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144) then break;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   194
     end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   195
x1:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   196
until y > 900;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   197
if x1 > 0 then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   198
   begin
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   199
   Result:= true;
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 70
diff changeset
   200
   tmpsurf:= LoadImage(Pathz[ptGraphics] + '/Girder', false);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   201
   rr.x:= x1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   202
   rr.y:= y;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   203
   while rr.x + 100 < x2 do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   204
         begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   205
         SDL_UpperBlit(tmpsurf, nil, Surface, @rr);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   206
         inc(rr.x, 100);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   207
         end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   208
   r.x:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   209
   r.y:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   210
   r.w:= x2 - rr.x;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   211
   r.h:= 16;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   212
   SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   213
   SDL_FreeSurface(tmpsurf);
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 27
diff changeset
   214
   AddRect(x1 - 8, y - 32, x2 - x1 + 16, 80);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   215
   for k:= y to y + 15 do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   216
       for i:= x1 to x2 do Land[k, i]:= $FFFFFF
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   217
   end else Result:= false
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   218
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   219
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   220
function CheckLand(rect: TSDL_Rect; dX, dY, Color: Longword): boolean;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   221
var i: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   222
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   223
Result:= true;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   224
inc(rect.x, dX);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   225
inc(rect.y, dY);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   226
i:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   227
{$WARNINGS OFF}
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   228
while (i <= rect.w) and Result do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   229
      begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   230
      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
   231
      inc(i)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   232
      end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   233
i:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   234
while (i <= rect.h) and Result do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   235
      begin
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   236
      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
   237
      inc(i)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   238
      end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   239
{$WARNINGS ON}
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   240
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   241
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   242
function CheckCanPlace(x, y: Longword; var Obj: TThemeObject): boolean;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   243
var i: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   244
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   245
with Obj do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   246
     if CheckLand(inland, x, y, $FFFFFF) then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   247
        begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   248
        Result:= true;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   249
        i:= 1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   250
        while Result and (i <= rectcnt) do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   251
              begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   252
              Result:= CheckLand(outland[i], x, y, 0);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   253
              inc(i)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   254
              end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   255
        if Result then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   256
           Result:= not CheckIntersect(x, y, Width, Height)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   257
        end else
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   258
        Result:= false
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   259
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   260
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   261
function TryPut(var Obj: TThemeObject; Surface: PSDL_Surface): boolean; overload;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   262
const MaxPointsIndex = 2047;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   263
var x, y: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   264
    ar: array[0..MaxPointsIndex] of TPoint;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   265
    cnt, i: Longword;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   266
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   267
cnt:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   268
with Obj do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   269
     begin
56
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   270
     if Maxcnt = 0 then
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   271
        begin
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   272
        Result:= false;
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   273
        exit
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   274
        end;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   275
     x:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   276
     repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   277
         y:= 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   278
         repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   279
             if CheckCanPlace(x, y, Obj) then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   280
                begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   281
                ar[cnt].x:= x;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   282
                ar[cnt].y:= y;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   283
                inc(cnt);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   284
                if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   285
                   begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   286
                   y:= 5000;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   287
                   x:= 5000;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   288
                   end
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   289
                end;
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   290
             inc(y, 3);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   291
         until y > 1023 - Height;
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   292
         inc(x, getrandom(6) + 3)
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   293
     until x > 2047 - Width;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   294
     Result:= cnt <> 0;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   295
     if Result then
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   296
        begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   297
        i:= getrandom(cnt);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   298
        BlitImageAndGenerateCollisionInfo(ar[i].x, ar[i].y, Obj.Surf, Surface);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   299
        AddRect(ar[i].x, ar[i].y, Width, Height);
56
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   300
        dec(Maxcnt)
a29135563e94 - Replaced water sprite
unc0rr
parents: 54
diff changeset
   301
        end else Maxcnt:= 0
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   302
     end
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   303
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   304
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   305
function TryPut(var Obj: TSprayObject; Surface: PSDL_Surface): boolean; overload;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   306
const MaxPointsIndex = 8095;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   307
var x, y: Longword;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   308
    ar: array[0..MaxPointsIndex] of TPoint;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   309
    cnt, i: Longword;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   310
    r: TSDL_Rect;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   311
begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   312
cnt:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   313
with Obj do
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   314
     begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   315
     if Maxcnt = 0 then
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   316
        begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   317
        Result:= false;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   318
        exit
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   319
        end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   320
     x:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   321
     r.x:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   322
     r.y:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   323
     r.w:= Width;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   324
     r.h:= Height + 16;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   325
     repeat
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   326
         y:= 8;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   327
         repeat
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   328
             if CheckLand(r, x, y - 8, $FFFFFF)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   329
                and not CheckIntersect(x, y, Width, Height) then
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   330
                begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   331
                ar[cnt].x:= x;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   332
                ar[cnt].y:= y;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   333
                inc(cnt);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   334
                if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   335
                   begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   336
                   y:= 5000;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   337
                   x:= 5000;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   338
                   end
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   339
                end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   340
             inc(y, 12);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   341
         until y > 1023 - Height - 8;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   342
         inc(x, getrandom(12) + 12)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   343
     until x > 2047 - Width;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   344
     Result:= cnt <> 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   345
     if Result then
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   346
        begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   347
        i:= getrandom(cnt);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   348
        r.x:= ar[i].X;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   349
        r.y:= ar[i].Y;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   350
        r.w:= Width;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   351
        r.h:= Height;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   352
        SDL_UpperBlit(Obj.Surf, nil, Surface, @r);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   353
        AddRect(ar[i].x - 32, ar[i].y - 32, Width + 64, Height + 64);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   354
        dec(Maxcnt)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   355
        end else Maxcnt:= 0
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   356
     end
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   357
end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   358
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   359
procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   360
var s: string;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   361
    f: textfile;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   362
    i, ii: integer;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   363
begin
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 74
diff changeset
   364
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   365
WriteLnToConsole('Reading objects info...');
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   366
AssignFile(f, s);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   367
{$I-}
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   368
Reset(f);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   369
Readln(f, s); // skip color
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   370
Readln(f, ThemeObjects.Count);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   371
for i:= 0 to Pred(ThemeObjects.Count) do
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   372
    begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   373
    Readln(f, s); // filename
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   374
    with ThemeObjects.objs[i] do
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   375
         begin
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 74
diff changeset
   376
         Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + s, false);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   377
         Read(f, Width, Height);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   378
         with inland do Read(f, x, y, w, h);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   379
         Read(f, rectcnt);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   380
         for ii:= 1 to rectcnt do
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   381
             with outland[ii] do Read(f, x, y, w, h);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   382
         Maxcnt:= 3;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   383
         ReadLn(f)
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   384
         end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   385
    end;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   386
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   387
Readln(f, SprayObjects.Count);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   388
for i:= 0 to Pred(SprayObjects.Count) do
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   389
    begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   390
    Readln(f, s); // filename
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   391
    with SprayObjects.objs[i] do
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   392
         begin
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 74
diff changeset
   393
         Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + s, false);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   394
         Width:= Surf.w;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   395
         Height:= Surf.h;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   396
         ReadLn(f, Maxcnt)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   397
         end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   398
    end;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   399
Closefile(f);
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   400
{$I+}
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   401
TryDo(IOResult = 0, 'Bad data or cannot access file ' + cThemeCFGFilename, true)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   402
end;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   403
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   404
procedure AddThemeObjects(Surface: PSDL_Surface; var ThemeObjects: TThemeObjects; MaxCount: integer);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   405
var i, ii, t: integer;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   406
    b: boolean;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   407
begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   408
if ThemeObjects.Count = 0 then exit;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   409
WriteLnToConsole('Adding theme objects...');
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   410
i:= 1;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   411
repeat
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   412
    t:= getrandom(ThemeObjects.Count);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   413
    ii:= t;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   414
    repeat
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   415
      inc(ii);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   416
      if ii = ThemeObjects.Count then ii:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   417
      b:= TryPut(ThemeObjects.objs[ii], Surface)
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   418
    until b or (ii = t);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   419
    inc(i)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   420
until (i > MaxCount) or not b;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   421
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   422
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   423
procedure AddSprayObjects(Surface: PSDL_Surface; var SprayObjects: TSprayObjects; MaxCount: Longword);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   424
var i: Longword;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   425
    ii, t: integer;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   426
    b: boolean;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   427
begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   428
if SprayObjects.Count = 0 then exit;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   429
WriteLnToConsole('Adding spray objects...');
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   430
i:= 1;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   431
repeat
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   432
    t:= getrandom(SprayObjects.Count);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   433
    ii:= t;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   434
    repeat
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   435
      inc(ii);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   436
      if ii = SprayObjects.Count then ii:= 0;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   437
      b:= TryPut(SprayObjects.objs[ii], Surface)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   438
    until b or (ii = t);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   439
    inc(i)
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   440
until (i > MaxCount) or not b;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   441
end;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   442
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   443
procedure AddObjects(InSurface, Surface: PSDL_Surface);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   444
var ThemeObjects: TThemeObjects;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   445
    SprayObjects: TSprayObjects;
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   446
begin
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   447
InitRects;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   448
AddGirder(256, Surface);
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   449
AddGirder(512, Surface);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   450
AddGirder(768, Surface);
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   451
AddGirder(1024, Surface);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   452
AddGirder(1280, Surface);
27
c374fe590272 - improve land generation
unc0rr
parents: 24
diff changeset
   453
AddGirder(1536, Surface);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   454
AddGirder(1792, Surface);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   455
ReadThemeInfo(ThemeObjects, SprayObjects);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   456
AddThemeObjects(Surface, ThemeObjects, 8);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   457
AddProgress;
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   458
SDL_UpperBlit(InSurface, nil, Surface, nil);
82d93eeecebe - Many AI improvements
unc0rr
parents: 56
diff changeset
   459
AddSprayObjects(Surface, SprayObjects, 10);
24
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   460
FreeRects
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   461
end;
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   462
79c411363184 Add theme objects to land
unc0rr
parents:
diff changeset
   463
end.