hedgewars/uLand.pas
author Wuzzy <Wuzzy2@mail.ru>
Sun, 19 May 2019 21:14:53 +0200
changeset 15010 5d8068ee16fc
parent 14418 0281b80d366c
child 15139 adf6f9be8113
permissions -rw-r--r--
Give a more accurate hedgehog limit estimate for small drawn maps
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     1
(*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 955
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 11019
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    12
 * GNU General Public License for more details.
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 173
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10040
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    17
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
2599
c7153d2348f3 move compiler directives to standard pascal
koda
parents: 2592
diff changeset
    19
{$INCLUDE "options.inc"}
2587
0dfa56a8513c fix a segfault in the iphone simulator by moving options.inc at the beginning of the file
koda
parents: 2376
diff changeset
    20
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    21
unit uLand;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
interface
10249
b47ac2c19de3 get rid of fpc warnings/hints
sheepluva
parents: 10198
diff changeset
    23
uses SDLh, uLandTemplates, uConsts, uTypes, uAILandMarks;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    24
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 3017
diff changeset
    25
procedure initModule;
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 3017
diff changeset
    26
procedure freeModule;
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
    27
procedure DrawBottomBorder;
37
2b7f2a43b999 - Properly get seed in net game
unc0rr
parents: 35
diff changeset
    28
procedure GenMap;
7079
939f53515489 Learn hask^Wpascal, dudes!
unc0rr
parents: 7063
diff changeset
    29
procedure GenPreview(out Preview: TPreview);
10162
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
    30
procedure GenPreviewAlpha(out Preview: TPreviewAlpha);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    31
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    32
implementation
11826
7654e2357934 implement ExtraftFileDir and ExtractFileName in uUtils
sheepluva
parents: 11746
diff changeset
    33
uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture,
6626
a447993f2ad7 Further work on propagating types. Now it hopefully works fully, just need to annotate namespace with types first.
unc0rr
parents: 6580
diff changeset
    34
     uVariables, uUtils, uCommands, adler32, uDebug, uLandPainted, uTextures,
10249
b47ac2c19de3 get rid of fpc warnings/hints
sheepluva
parents: 10198
diff changeset
    35
     uLandGenMaze, uPhysFSLayer, uScript, uLandGenPerlin,
11649
1fd1525653d8 SDL blit wraps at 16,384 - not the first time that routine has disappointed us.
nemo
parents: 11539
diff changeset
    36
     uLandGenTemplateBased, uLandUtils, uRenderUtils;
365
a26cec847dd7 - New land generator feature: islands in the sky
unc0rr
parents: 364
diff changeset
    37
7028
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6982
diff changeset
    38
var digest: shortstring;
11019
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    39
    maskOnly: boolean;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    40
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
    41
10016
59a6d65fcb60 (experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents: 9998
diff changeset
    42
procedure PrettifyLandAlpha();
59a6d65fcb60 (experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents: 9998
diff changeset
    43
begin
59a6d65fcb60 (experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents: 9998
diff changeset
    44
    if (cReducedQuality and rqBlurryLand) <> 0 then
10018
bdf75f0350bd (experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents: 10016
diff changeset
    45
        PrettifyAlpha2D(LandPixels, LAND_HEIGHT div 2, LAND_WIDTH div 2)
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
    46
    else
10018
bdf75f0350bd (experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents: 10016
diff changeset
    47
        PrettifyAlpha2D(LandPixels, LAND_HEIGHT, LAND_WIDTH);
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
    48
end;
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
    49
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    50
procedure DrawBorderFromImage(Surface: PSDL_Surface);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    51
var tmpsurf: PSDL_Surface;
11650
573e79db6688 Use our copy for border too
nemo
parents: 11649
diff changeset
    52
    //r, rr: TSDL_Rect;
1182
e2e13aa055c1 Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents: 1181
diff changeset
    53
    x, yd, yu: LongInt;
11019
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    54
    targetMask: Word;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    55
begin
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
    56
    tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifColorKey);
11019
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    57
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    58
    // if mask only, all land gets filled with landtex and therefore needs borders
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    59
    if maskOnly then
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    60
        targetMask:= lfLandMask
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    61
    else
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    62
        targetMask:= lfBasic;
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    63
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    64
    for x:= 0 to LAND_WIDTH - 1 do
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    65
    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    66
        yd:= LAND_HEIGHT - 1;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    67
        repeat
11019
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    68
            while (yd > 0) and ((Land[yd, x] and targetMask) = 0) do dec(yd);
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2338
diff changeset
    69
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
    70
            if (yd < 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
    71
                yd:= 0;
1182
e2e13aa055c1 Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents: 1181
diff changeset
    72
11019
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    73
            while (yd < LAND_HEIGHT) and ((Land[yd, x] and targetMask) <> 0) do
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
    74
                inc(yd);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    75
            dec(yd);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    76
            yu:= yd;
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2338
diff changeset
    77
11019
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    78
            while (yu > 0  ) and ((Land[yu, x] and targetMask) <> 0) do dec(yu);
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
    79
            while (yu < yd ) and ((Land[yu, x] and targetMask) =  0) do inc(yu);
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2338
diff changeset
    80
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    81
            if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then
11650
573e79db6688 Use our copy for border too
nemo
parents: 11649
diff changeset
    82
                copyToXYFromRect(tmpsurf, Surface, x mod tmpsurf^.w, 16, 1, 16, x, yd - 15);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    83
            if (yu > 0) then
11650
573e79db6688 Use our copy for border too
nemo
parents: 11649
diff changeset
    84
                copyToXYFromRect(tmpsurf, Surface, x mod tmpsurf^.w, 0, 1, Min(16, yd - yu + 1), x, yu);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    85
            yd:= yu - 1;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    86
        until yd < 0;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    87
    end;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
    88
    SDL_FreeSurface(tmpsurf);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    89
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    90
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    91
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    92
procedure DrawShoppaBorder;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    93
var x, y, s, i: Longword;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    94
    c1, c2, c: Longword;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    95
begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    96
    c1:= AMask;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    97
    c2:= AMask or RMask or GMask;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    98
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
    99
    // vertical
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   100
    s:= LAND_HEIGHT;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   101
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   102
    for x:= 0 to LAND_WIDTH - 1 do
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   103
        for y:= 0 to LAND_HEIGHT - 1 do
9864
f7eb0d87c9b6 Oops, meant Land
unc0rr
parents: 9524
diff changeset
   104
            if Land[y, x] = 0 then
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   105
                if s < y then
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   106
                    begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   107
                    for i:= max(s, y - 8) to y - 1 do
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   108
                        begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   109
                        if ((x + i) and 16) = 0 then c:= c1 else c:= c2;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   110
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   111
                        if (cReducedQuality and rqBlurryLand) = 0 then
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   112
                            LandPixels[i, x]:= c
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   113
                        else
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   114
                            LandPixels[i div 2, x div 2]:= c
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   115
                        end;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   116
                    s:= LAND_HEIGHT
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   117
                    end
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   118
                else
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   119
            else
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   120
                begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   121
                if s > y then s:= y;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   122
                if s + 8 > y then
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   123
                    begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   124
                    if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   125
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   126
                    if (cReducedQuality and rqBlurryLand) = 0 then
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   127
                        LandPixels[y, x]:= c
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   128
                    else
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   129
                        LandPixels[y div 2, x div 2]:= c
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   130
                    end;
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   131
                end;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   132
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   133
    // horizontal
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   134
    s:= LAND_WIDTH;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   135
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   136
    for y:= 0 to LAND_HEIGHT - 1 do
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   137
        for x:= 0 to LAND_WIDTH - 1 do
9864
f7eb0d87c9b6 Oops, meant Land
unc0rr
parents: 9524
diff changeset
   138
            if Land[y, x] = 0 then
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   139
                if s < x then
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   140
                    begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   141
                    for i:= max(s, x - 8) to x - 1 do
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   142
                        begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   143
                        if ((y + i) and 16) = 0 then c:= c1 else c:= c2;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   144
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   145
                        if (cReducedQuality and rqBlurryLand) = 0 then
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   146
                            LandPixels[y, i]:= c
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   147
                        else
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   148
                            LandPixels[y div 2, i div 2]:= c
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   149
                        end;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   150
                    s:= LAND_WIDTH
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   151
                    end
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   152
                else
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   153
            else
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   154
                begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   155
                if s > x then s:= x;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   156
                if s + 8 > x then
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   157
                    begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   158
                    if ((x + y) and 16) = 0 then c:= c1 else c:= c2;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   159
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   160
                    if (cReducedQuality and rqBlurryLand) = 0 then
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   161
                        LandPixels[y, x]:= c
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   162
                    else
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   163
                        LandPixels[y div 2, x div 2]:= c
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   164
                    end;
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   165
                end
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   166
end;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   167
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   168
procedure ColorizeLandFast(mapsurf: PSDL_Surface);
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   169
var ltexsurf: PSDL_Surface;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   170
    i: LongInt;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   171
    ltlnp, srcp, dstp, stopp: Pointer;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   172
    c: SizeInt;
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   173
begin
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   174
    ltexsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps);
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   175
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   176
    // pointer to current line of ltexsurf pixels. will be moved from line to line
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   177
    ltlnp:= ltexsurf^.pixels;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   178
    // pointer to mapsurf pixels. will jump forward after every move()
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   179
    dstp:= mapsurf^.pixels;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   180
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   181
    // time to get serious
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   182
    SDL_LockSurface(mapsurf);
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   183
    SDL_LockSurface(ltexsurf);
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   184
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   185
    // for now only fill a row with the height of landtex. do vertical copies within mapsurf after
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   186
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   187
    // do this loop for each line of ltexsurf (unless we run out of map height first)
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   188
    for i:= 1 to min(ltexsurf^.h, mapsurf^.h) do
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   189
        begin
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   190
        // amount of pixels to write in first move()
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   191
        c:= ltexsurf^.pitch;
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   192
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   193
        // protect from odd cases where landtex wider than map
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   194
        if c > mapsurf^.pitch then
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   195
            c:= mapsurf^.pitch;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   196
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   197
        // write line of landtex to mapsurf
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   198
        move(ltlnp^, dstp^, c);
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   199
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   200
        // fill the rest of the line by copying left-to-right until full
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   201
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   202
        // new src is start of line that we've just written to
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   203
        srcp:= dstp;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   204
        // set stop pointer to start of next pixel line of mapsurf
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   205
        stopp:= dstp + mapsurf^.pitch;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   206
        // move dst pointer to after what we've just written
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   207
        inc(dstp, c);
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   208
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   209
        // loop until dstp went past end of line
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   210
        while dstp < stopp do
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   211
            begin
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   212
            // copy all from left of dstp to right of it (or just fill the gap if smaller)
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   213
            c:= min(dstp-srcp, stopp-dstp);
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   214
            move(srcp^, dstp^, c);
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   215
            inc(dstp, c);
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   216
            end;
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   217
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   218
        // move to next line in ltexsurf
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   219
        inc(ltlnp, ltexsurf^.pitch);
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   220
        end;
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   221
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   222
    // we don't need ltexsurf itself anymore -> cleanup
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   223
    ltlnp:= nil;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   224
    SDL_UnlockSurface(ltexsurf);
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   225
    SDL_FreeSurface(ltexsurf);
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   226
    ltexsurf:= nil;
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   227
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   228
    // from now on only copy pixels within mapsurf
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   229
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   230
    // copy all the already written lines at once for that get number of written bytes so far
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   231
    // already written pixels are between start and current dstp
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   232
    srcp:= mapsurf^.pixels;
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   233
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   234
    // first byte after end of pixels
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   235
    stopp:= srcp + (mapsurf^.pitch * mapsurf^.h);
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   236
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   237
    while dstp < stopp do
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   238
        begin
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   239
        // copy all from before dstp to after (or just fill the gap if smaller)
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   240
        c:= min(dstp-srcp, stopp-dstp);
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   241
        // worried about size of c with humongous maps? don't be:
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   242
        //  the OS wouldn't have allowed allocation of object with size > max of SizeInt anyway
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   243
        move(srcp^, dstp^, c);
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   244
        inc(dstp, c);
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   245
        end;
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   246
12104
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   247
    // cleanup
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   248
    srcp:= nil;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   249
    dstp:= nil;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   250
    stopp:= nil;
f61bd25b9f70 tweak landtex filling some more. cuz it's fun
sheepluva
parents: 12100
diff changeset
   251
    SDL_UnlockSurface(mapsurf);
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   252
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   253
    // freed in freeModule() below
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   254
    LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey);
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   255
    if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface);
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   256
end;
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   257
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   258
procedure ColorizeLand(Surface: PSDL_Surface);
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   259
var tmpsurf: PSDL_Surface;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   260
    r: TSDL_Rect;
10197
c57798251b55 Some optimizations
unc0rr
parents: 10189
diff changeset
   261
    y: LongInt; // stupid SDL 1.2 uses stupid SmallInt for y which limits us to 32767.  But is even worse if LandTex is large, can overflow on 32767 map.
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   262
begin
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   263
    tmpsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps);
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   264
    r.y:= 0;
9892
5a0a7ef7af2d allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents: 9864
diff changeset
   265
    y:= 0;
5a0a7ef7af2d allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents: 9864
diff changeset
   266
    while y < LAND_HEIGHT do
5a0a7ef7af2d allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents: 9864
diff changeset
   267
        begin
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   268
        r.x:= 0;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   269
        while r.x < LAND_WIDTH do
9892
5a0a7ef7af2d allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents: 9864
diff changeset
   270
            begin
11649
1fd1525653d8 SDL blit wraps at 16,384 - not the first time that routine has disappointed us.
nemo
parents: 11539
diff changeset
   271
            copyToXY(tmpsurf, Surface, r.x, r.y);
1fd1525653d8 SDL blit wraps at 16,384 - not the first time that routine has disappointed us.
nemo
parents: 11539
diff changeset
   272
            //SDL_UpperBlit(tmpsurf, nil, Surface, @r);
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   273
            inc(r.x, tmpsurf^.w)
9892
5a0a7ef7af2d allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents: 9864
diff changeset
   274
            end;
5a0a7ef7af2d allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents: 9864
diff changeset
   275
        inc(y, tmpsurf^.h);
5a0a7ef7af2d allow SDL 1.2 to at least do a 32767 map. We probably should add a TryDo somewhere to assert that limit on SDL 1.2 to avoid overflows. Ditto int version for SDL 2
nemo
parents: 9864
diff changeset
   276
        r.y:= y
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   277
        end;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   278
    SDL_FreeSurface(tmpsurf);
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   279
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   280
    // freed in freeModule() below
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   281
    LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey);
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   282
    if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface);
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   283
end;
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   284
23
16322d14f068 - Land generator uses templates to generate
unc0rr
parents: 22
diff changeset
   285
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   286
procedure GenDrawnMap;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   287
begin
15010
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   288
    if (cFeatureSize <= 6) then
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   289
        MaxHedgehogs:= 6 + (cFeatureSize-1) * 2
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   290
    else if (cFeatureSize < 11) then
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   291
        MaxHedgehogs:= 16 + (cFeatureSize-6) * 4
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   292
    else if (cFeatureSize = 11) then
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   293
        MaxHedgehogs:= 48
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   294
    else if (cFeatureSize = 12) then
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   295
        MaxHedgehogs:= 64
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   296
    else
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   297
        MaxHedgehogs:= cMaxHHs;
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   298
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   299
    if GameType = gmtLandPreview then
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   300
        cFeatureSize:= 3;
14416
96624a6cdb93 Allow scaling hand drawn maps
nemo
parents: 14286
diff changeset
   301
    ResizeLand((4096 * max(min(cFeatureSize,24),3)) div 12, (2048 * max(min(cFeatureSize,24),3)) div 12);
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   302
    uLandPainted.Draw;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   303
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   304
    hasGirders:= true;
14416
96624a6cdb93 Allow scaling hand drawn maps
nemo
parents: 14286
diff changeset
   305
    playHeight:= LAND_HEIGHT;
96624a6cdb93 Allow scaling hand drawn maps
nemo
parents: 14286
diff changeset
   306
    playWidth:= LAND_WIDTH;
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   307
    leftX:= ((LAND_WIDTH - playWidth) div 2);
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   308
    rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   309
    topY:= LAND_HEIGHT - playHeight;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   310
end;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4458
diff changeset
   311
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 368
diff changeset
   312
function SelectTemplate: LongInt;
9243
d8f6a396d98e First select group of templates, then pick template from selected group
unc0rr
parents: 9080
diff changeset
   313
var l: LongInt;
161
d8870bbf960e - AmmoMenu
unc0rr
parents: 160
diff changeset
   314
begin
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   315
    SelectTemplate:= 0;
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
   316
    if (cReducedQuality and rqLowRes) <> 0 then
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
   317
        SelectTemplate:= SmallTemplates[getrandom(Succ(High(SmallTemplates)))]
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
   318
    else
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   319
        begin
9243
d8f6a396d98e First select group of templates, then pick template from selected group
unc0rr
parents: 9080
diff changeset
   320
        if cTemplateFilter = 0 then
d8f6a396d98e First select group of templates, then pick template from selected group
unc0rr
parents: 9080
diff changeset
   321
            begin
d8f6a396d98e First select group of templates, then pick template from selected group
unc0rr
parents: 9080
diff changeset
   322
            l:= getRandom(GroupedTemplatesCount);
d8f6a396d98e First select group of templates, then pick template from selected group
unc0rr
parents: 9080
diff changeset
   323
            repeat
d8f6a396d98e First select group of templates, then pick template from selected group
unc0rr
parents: 9080
diff changeset
   324
                inc(cTemplateFilter);
d8f6a396d98e First select group of templates, then pick template from selected group
unc0rr
parents: 9080
diff changeset
   325
                dec(l, TemplateCounts[cTemplateFilter]);
d8f6a396d98e First select group of templates, then pick template from selected group
unc0rr
parents: 9080
diff changeset
   326
            until l < 0;
14284
a3531b520efb more uninitialised values
nemo
parents: 14282
diff changeset
   327
            end
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   328
            else getRandom(1);
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   329
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   330
            case cTemplateFilter of
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   331
            0: OutError('Error selecting TemplateFilter. Ask unC0Rr about what you did wrong', true);
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   332
            1: SelectTemplate:= SmallTemplates[getrandom(TemplateCounts[cTemplateFilter])];
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   333
            2: SelectTemplate:= MediumTemplates[getrandom(TemplateCounts[cTemplateFilter])];
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   334
            3: SelectTemplate:= LargeTemplates[getrandom(TemplateCounts[cTemplateFilter])];
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   335
            4: SelectTemplate:= CavernTemplates[getrandom(TemplateCounts[cTemplateFilter])];
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   336
            5: SelectTemplate:= WackyTemplates[getrandom(TemplateCounts[cTemplateFilter])];
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   337
    // For lua only!
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   338
            6: begin
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   339
               SelectTemplate:= min(LuaTemplateNumber,High(EdgeTemplates));
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   340
               GetRandom(2) // burn 1
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   341
               end
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   342
            end
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   343
        end;
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
   344
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
   345
    WriteLnToConsole('Selected template #'+inttostr(SelectTemplate)+' using filter #'+inttostr(cTemplateFilter));
161
d8870bbf960e - AmmoMenu
unc0rr
parents: 160
diff changeset
   346
end;
d8870bbf960e - AmmoMenu
unc0rr
parents: 160
diff changeset
   347
1182
e2e13aa055c1 Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents: 1181
diff changeset
   348
procedure LandSurface2LandPixels(Surface: PSDL_Surface);
e2e13aa055c1 Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents: 1181
diff changeset
   349
var x, y: LongInt;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   350
    p: PLongwordArray;
1180
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1085
diff changeset
   351
begin
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   352
if checkFails(Surface <> nil, 'Assert (LandSurface <> nil) failed', true) then exit;
1182
e2e13aa055c1 Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents: 1181
diff changeset
   353
e2e13aa055c1 Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents: 1181
diff changeset
   354
if SDL_MustLock(Surface) then
11507
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   355
    if SDLCheck(SDL_LockSurface(Surface) >= 0, 'SDL_LockSurface', true) then exit;
1180
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1085
diff changeset
   356
1182
e2e13aa055c1 Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents: 1181
diff changeset
   357
p:= Surface^.pixels;
1760
55a1edd97911 Fix nemo's large land patch
unc0rr
parents: 1754
diff changeset
   358
for y:= 0 to LAND_HEIGHT - 1 do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   359
    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   360
    for x:= 0 to LAND_WIDTH - 1 do
3598
a8aa06bae895 tiy new overlay graphics
koda
parents: 3595
diff changeset
   361
    if Land[y, x] <> 0 then
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3551
diff changeset
   362
        if (cReducedQuality and rqBlurryLand) = 0 then
11473
023db094b22d Some themers expressed desire to have translucent themes. While the current AA stuff in uLandGraphics won't really allow this to work with LandBackTex properly, seems to me it should be safe to allow alpha for LandTex. Our LandTex should all have alpha of 255 on the existing themes.
nemo
parents: 11362
diff changeset
   363
            LandPixels[y, x]:= p^[x]// or AMask
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3551
diff changeset
   364
        else
11473
023db094b22d Some themers expressed desire to have translucent themes. While the current AA stuff in uLandGraphics won't really allow this to work with LandBackTex properly, seems to me it should be safe to allow alpha for LandTex. Our LandTex should all have alpha of 255 on the existing themes.
nemo
parents: 11362
diff changeset
   365
            LandPixels[y div 2, x div 2]:= p^[x];// or AMask;
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2338
diff changeset
   366
10131
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10108
diff changeset
   367
    p:= PLongwordArray(@(p^[Surface^.pitch div 4]));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   368
    end;
1180
e56317fdf78d Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents: 1085
diff changeset
   369
1182
e2e13aa055c1 Step 3: Maps are rendered correctly, but without objects yet
unc0rr
parents: 1181
diff changeset
   370
if SDL_MustLock(Surface) then
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   371
    SDL_UnlockSurface(Surface);
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   372
end;
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   373
3133
1ab5f18f4df8 prg's maze generator
nemo
parents: 3058
diff changeset
   374
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   375
procedure GenLandSurface;
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   376
var tmpsurf: PSDL_Surface;
5225
d38211100f4d Experiment in making the land less jagg-y
nemo
parents: 4976
diff changeset
   377
    x,y: Longword;
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   378
begin
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   379
    AddProgress();
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   380
11473
023db094b22d Some themers expressed desire to have translucent themes. While the current AA stuff in uLandGraphics won't really allow this to work with LandBackTex properly, seems to me it should be safe to allow alpha for LandTex. Our LandTex should all have alpha of 255 on the existing themes.
nemo
parents: 11362
diff changeset
   381
    tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, AMask);
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   382
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   383
    if checkFails(tmpsurf <> nil, 'Error creating pre-land surface', true) then exit;
12100
166725555e57 GOTTA GO FAST! - speed up landtex filling
sheepluva
parents: 12087
diff changeset
   384
    ColorizeLandFast(tmpsurf);
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   385
    if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   386
    AddOnLandObjects(tmpsurf);
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   387
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   388
    LandSurface2LandPixels(tmpsurf);
5227
nemo
parents: 5225
diff changeset
   389
    SDL_FreeSurface(tmpsurf);
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   390
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9295
diff changeset
   391
    if gameFlags and gfShoppaBorder <> 0 then DrawShoppaBorder;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   392
14282
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13788
diff changeset
   393
    for x:= LongWord(leftX+2) to LongWord(rightX-2) do
14286
7a7c090f96f6 topY too
nemo
parents: 14284
diff changeset
   394
        for y:= LongWord(topY+2) to LAND_HEIGHT-3 do
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   395
            if (Land[y, x] = 0) and
5274
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   396
               (((Land[y, x-1] = lfBasic) and ((Land[y+1,x] = lfBasic)) or (Land[y-1,x] = lfBasic)) or
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   397
               ((Land[y, x+1] = lfBasic) and ((Land[y-1,x] = lfBasic) or (Land[y+1,x] = lfBasic)))) then
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   398
            begin
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   399
                if (cReducedQuality and rqBlurryLand) = 0 then
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   400
                    begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   401
                    if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   402
                        LandPixels[y, x]:= LandPixels[y, x-1]
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   403
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   404
                    else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   405
                        LandPixels[y, x]:= LandPixels[y, x+1]
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   406
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   407
                    else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   408
                        LandPixels[y, x]:= LandPixels[y-1, x]
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   409
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   410
                    else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   411
                        LandPixels[y, x]:= LandPixels[y+1, x];
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   412
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   413
                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   414
                        LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
5274
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   415
                    end;
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   416
                Land[y,x]:= lfObject
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   417
            end
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   418
            else if (Land[y, x] = 0) and
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   419
                    (((Land[y, x-1] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y+2,x] = lfBasic)) or
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   420
                    ((Land[y, x-1] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y-2,x] = lfBasic)) or
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   421
                    ((Land[y, x+1] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y+2,x] = lfBasic)) or
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   422
                    ((Land[y, x+1] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y-2,x] = lfBasic)) or
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   423
                    ((Land[y+1, x] = lfBasic) and (Land[y+1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   424
                    ((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   425
                    ((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   426
                    ((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   427
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   428
                begin
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   429
5274
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   430
                if (cReducedQuality and rqBlurryLand) = 0 then
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   431
5274
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   432
                    begin
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   433
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   434
                    if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   435
                        LandPixels[y, x]:= LandPixels[y, x-1]
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   436
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   437
                    else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   438
                        LandPixels[y, x]:= LandPixels[y, x+1]
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   439
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   440
                    else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   441
                        LandPixels[y, x]:= LandPixels[y+1, x]
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   442
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   443
                    else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   444
                        LandPixels[y, x]:= LandPixels[y-1, x];
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   445
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   446
                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   447
                        LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
5274
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   448
                    end;
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   449
                Land[y,x]:= lfObject
941da059472b Avoid desyncing on blurry land
nemo
parents: 5241
diff changeset
   450
            end;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   451
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   452
    AddProgress();
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   453
end;
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   454
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   455
procedure MakeFortsPreview;
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   456
var gap: LongInt;
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   457
    h1, h2, w1, w2, x, y, lastX, wbm, bmref: LongWord;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   458
const fortHeight = 960;
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   459
      fortWidth  = 704;
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   460
      bmHeight = 53;
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   461
      bmWidth = 64;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   462
begin
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   463
ResizeLand(4096,2048);
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   464
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   465
lastX:= LAND_WIDTH-1;
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   466
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   467
gap:= (1024 - fortWidth) + 60 + 20 * cFeatureSize;
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   468
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   469
h2:= LAND_HEIGHT-1;
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   470
h1:= h2 - fortHeight;
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   471
w2:= (LAND_WIDTH - gap) div 2;
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   472
w1:= w2 - fortWidth;
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   473
wbm:= h1 + bmHeight;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   474
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   475
// generate 2 forts in center
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   476
for y:= h1 to h2 do
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   477
    for x:= w1 to w2 do
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   478
        begin
11746
329ab1a0a750 tweak preview
sheepluva
parents: 11745
diff changeset
   479
        if x mod 4 <> 0 then
329ab1a0a750 tweak preview
sheepluva
parents: 11745
diff changeset
   480
            begin
329ab1a0a750 tweak preview
sheepluva
parents: 11745
diff changeset
   481
            if (y <= wbm) and ((x - w1) mod (bmWidth * 2) >= bmWidth) then
329ab1a0a750 tweak preview
sheepluva
parents: 11745
diff changeset
   482
                continue;
329ab1a0a750 tweak preview
sheepluva
parents: 11745
diff changeset
   483
            Land[y,x]:= lfBasic;
329ab1a0a750 tweak preview
sheepluva
parents: 11745
diff changeset
   484
            Land[y,lastX-x]:= lfBasic;
329ab1a0a750 tweak preview
sheepluva
parents: 11745
diff changeset
   485
            end;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   486
        end;
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   487
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   488
w2:= w1 - gap;
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   489
w1:= max(0, w2 - fortWidth);
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   490
wbm:= h1 + bmHeight;
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   491
bmref:= w2 + bmWidth;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   492
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   493
for y:= h1 to h2 do
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   494
    for x:= w1 to w2 do
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   495
        begin
11746
329ab1a0a750 tweak preview
sheepluva
parents: 11745
diff changeset
   496
        if ((y - x) mod 2) = 0 then
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   497
            begin
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   498
            // align battlement on inner edge, because real outer edge could be offscreen
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   499
            if (y <= wbm) and ((LAND_WIDTH + x - bmref) mod (bmWidth * 2) >= bmWidth) then
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   500
                continue;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   501
            Land[y,x]:= lfBasic;
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   502
            Land[y,lastX-x]:= lfBasic;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   503
            end;
11745
2ca312efcbb8 tweak preview
sheepluva
parents: 11744
diff changeset
   504
        end;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   505
end;
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   506
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   507
procedure MakeFortsMap;
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   508
var tmpsurf: PSDL_Surface;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   509
    sectionWidth, i, t, p: integer;
11705
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   510
    mirror: boolean;
11734
f48408dcea36 create forts in random order
sheepluva
parents: 11707
diff changeset
   511
    pc: PClan;
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   512
begin
11734
f48408dcea36 create forts in random order
sheepluva
parents: 11707
diff changeset
   513
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   514
// make the gaps between forts adjustable if fort map was selected
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   515
if cMapGen = mgForts then
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   516
    sectionWidth:= 1024 + 60 + 20 * cFeatureSize
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   517
else
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   518
    sectionWidth:= 1024 * 300;
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   519
11734
f48408dcea36 create forts in random order
sheepluva
parents: 11707
diff changeset
   520
// mix up spawn/fort order of clans
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   521
for i:= 0 to ClansCount - 1 do
11734
f48408dcea36 create forts in random order
sheepluva
parents: 11707
diff changeset
   522
    begin
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   523
    t:= GetRandom(ClansCount);
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   524
    p:= GetRandom(ClansCount);
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   525
    if t <> p then
11734
f48408dcea36 create forts in random order
sheepluva
parents: 11707
diff changeset
   526
        begin
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   527
        pc:= SpawnClansArray[t];
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   528
        SpawnClansArray[t]:= SpawnClansArray[p];
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   529
        SpawnClansArray[p]:= pc;
11734
f48408dcea36 create forts in random order
sheepluva
parents: 11707
diff changeset
   530
        end;
f48408dcea36 create forts in random order
sheepluva
parents: 11707
diff changeset
   531
    end;
f48408dcea36 create forts in random order
sheepluva
parents: 11707
diff changeset
   532
11705
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   533
// figure out how much space we need
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   534
playWidth:= sectionWidth * ClansCount;
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   535
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   536
// note: LAND_WIDTH might be bigger than specified below (rounded to next power of 2)
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   537
ResizeLand(playWidth, 2048);
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   538
2171
8208946331ba Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents: 2163
diff changeset
   539
// For now, defining a fort is playable area as 3072x1200 - there are no tall forts.  The extra height is to avoid triggering border with current code, also if user turns on a border, it will give a bit more maneuvering room.
1784
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   540
playHeight:= 1200;
11705
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   541
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   542
// center playable area in land array
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   543
leftX:= ((LAND_WIDTH - playWidth) div 2);
1776
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   544
rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1);
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   545
topY:= LAND_HEIGHT - playHeight;
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   546
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   547
WriteLnToConsole('Generating forts land...');
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   548
11705
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   549
for i := 0 to ClansCount - 1 do
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   550
    begin
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   551
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   552
    // face in random direction
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   553
    mirror:= (GetRandom(2) = 0);
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   554
    // make first/last fort face inwards
11707
ecbf5e6c2c37 also make forts face inwards in wrap mode, if there are only 2 teams
sheepluva
parents: 11706
diff changeset
   555
    if (WorldEdge <> weWrap) or (ClansCount = 2) then
11706
863e1a75ec99 fix last fort not facing left
sheepluva
parents: 11705
diff changeset
   556
        mirror:= (i <> 0) and (mirror or (i = ClansCount - 1));
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   557
11705
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   558
    if mirror then
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   559
        begin
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   560
        // not critical because if no R we can fallback to mirrored L
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   561
        tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'R', ifAlpha or ifColorKey or ifIgnoreCaps);
11705
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   562
        // fallback
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   563
        if tmpsurf = nil then
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   564
            begin
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   565
            tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps);
11705
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   566
            BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf, 0, true);
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   567
            end
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   568
        else
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   569
            BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   570
        SDL_FreeSurface(tmpsurf);
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   571
        end
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   572
    else
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   573
        begin
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   574
        tmpsurf:= LoadDataImage(ptForts, SpawnClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps);
11705
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   575
        BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   576
        SDL_FreeSurface(tmpsurf);
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   577
        end;
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   578
4b2179d9516c Fort Mode: allow more than 2 clans
sheepluva
parents: 11650
diff changeset
   579
    end;
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   580
end;
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   581
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   582
procedure LoadMapConfig;
8060
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   583
var f: PFSFile;
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   584
    s: shortstring;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   585
begin
8025
07862ab415c8 Get rid of Pathz and UserPathz
unc0rr
parents: 8011
diff changeset
   586
s:= cPathz[ptMapCurrent] + '/map.cfg';
07862ab415c8 Get rid of Pathz and UserPathz
unc0rr
parents: 8011
diff changeset
   587
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   588
WriteLnToConsole('Fetching map HH limit');
8060
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   589
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   590
f:= pfsOpenRead(s);
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   591
if f <> nil then
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   592
    begin
8060
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   593
    pfsReadLn(f, s);
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   594
    if not pfsEof(f) then
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   595
        begin
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   596
        pfsReadLn(f, s);
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   597
        val(s, MaxHedgehogs)
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   598
        end;
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   599
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   600
    pfsClose(f)
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   601
    end;
8060
341fa76d0749 Convert reading hedgehogs limit from map config
unc0rr
parents: 8025
diff changeset
   602
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   603
if (MaxHedgehogs = 0) then
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   604
    MaxHedgehogs:= 18;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   605
end;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   606
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5231
diff changeset
   607
// Loads Land[] from an image, allowing overriding standard collision
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   608
procedure LoadMask;
1792
c30c6944bd49 engine part of nemo's patch
unc0rr
parents: 1784
diff changeset
   609
var tmpsurf: PSDL_Surface;
c30c6944bd49 engine part of nemo's patch
unc0rr
parents: 1784
diff changeset
   610
    p: PLongwordArray;
c30c6944bd49 engine part of nemo's patch
unc0rr
parents: 1784
diff changeset
   611
    x, y, cpX, cpY: Longword;
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   612
    mapName: shortstring;
1792
c30c6944bd49 engine part of nemo's patch
unc0rr
parents: 1784
diff changeset
   613
begin
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   614
tmpsurf:= LoadDataImage(ptMapCurrent, 'mask', ifAlpha or ifColorKey or ifIgnoreCaps);
5770
022a18320f01 load mask from user path as well
nemo
parents: 5719
diff changeset
   615
if tmpsurf = nil then
022a18320f01 load mask from user path as well
nemo
parents: 5719
diff changeset
   616
    begin
8025
07862ab415c8 Get rid of Pathz and UserPathz
unc0rr
parents: 8011
diff changeset
   617
    mapName:= ExtractFileName(cPathz[ptMapCurrent]);
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   618
    tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/mask', ifAlpha or ifColorKey or ifIgnoreCaps);
5770
022a18320f01 load mask from user path as well
nemo
parents: 5719
diff changeset
   619
    end;
3920
a54ca6185307 updated lua loading in the ifrontend and also fixed masked maps
koda
parents: 3912
diff changeset
   620
6096
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   621
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   622
if (tmpsurf <> nil) and (tmpsurf^.format^.BytesPerPixel = 4) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   623
    begin
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   624
    if LAND_WIDTH = 0 then
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   625
        begin
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   626
        LoadMapConfig;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   627
        ResizeLand(tmpsurf^.w, tmpsurf^.h);
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   628
        playHeight:= tmpsurf^.h;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   629
        playWidth:= tmpsurf^.w;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   630
        leftX:= (LAND_WIDTH - playWidth) div 2;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   631
        rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   632
        topY:= LAND_HEIGHT - playHeight;
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   633
        end;
6096
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   634
    disableLandBack:= true;
2376
ece7b87f1334 Strip trailing spaces
nemo
parents: 2338
diff changeset
   635
6096
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   636
    cpX:= (LAND_WIDTH - tmpsurf^.w) div 2;
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   637
    cpY:= LAND_HEIGHT - tmpsurf^.h;
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   638
    if SDL_MustLock(tmpsurf) then
11507
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   639
        SDLCheck(SDL_LockSurface(tmpsurf) >= 0, 'SDL_LockSurface', true);
6096
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   640
11507
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   641
    if allOK then
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   642
    begin
6096
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   643
        p:= tmpsurf^.pixels;
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   644
        for y:= 0 to Pred(tmpsurf^.h) do
8848
e9ebd63f8a03 So. Some themes have objects that seem to be large natural extensions of the landscape. Masks allow maintaining that. Lemme know if it doesn't look good. If it doesn't, can still use for ice/bounce/indestructible. Indestructible bunker object for example.
nemo
parents: 8370
diff changeset
   645
            begin
6096
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   646
            for x:= 0 to Pred(tmpsurf^.w) do
8848
e9ebd63f8a03 So. Some themes have objects that seem to be large natural extensions of the landscape. Masks allow maintaining that. Lemme know if it doesn't look good. If it doesn't, can still use for ice/bounce/indestructible. Indestructible bunker object for example.
nemo
parents: 8370
diff changeset
   647
                SetLand(Land[cpY + y, cpX + x], p^[x]);
10131
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10108
diff changeset
   648
            p:= PLongwordArray(@(p^[tmpsurf^.pitch div 4]));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   649
            end;
2243
b4764993f833 additional touch support and nemo's reduced land array size
koda
parents: 2240
diff changeset
   650
11507
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   651
        if SDL_MustLock(tmpsurf) then
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   652
            SDL_UnlockSurface(tmpsurf);
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   653
        if not disableLandBack then
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   654
            begin
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   655
            // freed in freeModule() below
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   656
            LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifColorKey);
11507
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   657
            if (LandBackSurface <> nil) and GrayScale then
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   658
                Surface2GrayScale(LandBackSurface)
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   659
            end;
bd9a2f1b0080 SDLTry doesn't halt engine no more
unc0rr
parents: 11473
diff changeset
   660
    end;
6096
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   661
end;
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   662
if (tmpsurf <> nil) then
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   663
    SDL_FreeSurface(tmpsurf);
a00dbbf49d6c Add landbacktex to a few maps, just to see how it looks.
nemo
parents: 6082
diff changeset
   664
tmpsurf:= nil;
1792
c30c6944bd49 engine part of nemo's patch
unc0rr
parents: 1784
diff changeset
   665
end;
c30c6944bd49 engine part of nemo's patch
unc0rr
parents: 1784
diff changeset
   666
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   667
procedure LoadMap;
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   668
var tmpsurf: PSDL_Surface;
3920
a54ca6185307 updated lua loading in the ifrontend and also fixed masked maps
koda
parents: 3912
diff changeset
   669
    mapName: shortstring = '';
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   670
begin
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   671
WriteLnToConsole('Loading land from file...');
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   672
AddProgress;
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   673
tmpsurf:= LoadDataImage(ptMapCurrent, 'map', ifAlpha or ifColorKey or ifIgnoreCaps);
3912
e11df2de6af2 have engine try for a second position when map loading fails (in this way it's possible to move Missions data to any path)
koda
parents: 3836
diff changeset
   674
if tmpsurf = nil then
5770
022a18320f01 load mask from user path as well
nemo
parents: 5719
diff changeset
   675
    begin
8025
07862ab415c8 Get rid of Pathz and UserPathz
unc0rr
parents: 8011
diff changeset
   676
    mapName:= ExtractFileName(cPathz[ptMapCurrent]);
12592
00b539e6115d rename ifTransparent to ifColorKey
sheepluva
parents: 12104
diff changeset
   677
    tmpsurf:= LoadDataImage(ptMissionMaps, mapName + '/map', ifAlpha or ifCritical or ifColorKey or ifIgnoreCaps);
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   678
    if not allOK then exit;
5770
022a18320f01 load mask from user path as well
nemo
parents: 5719
diff changeset
   679
    end;
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   680
// (bare) Sanity check. Considering possible LongInt comparisons as well as just how much system memoery it would take
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   681
if checkFails((tmpsurf^.w < $40000000) and (tmpsurf^.h < $40000000) and (QWord(tmpsurf^.w) * tmpsurf^.h < 6*1024*1024*1024), 'Map dimensions too big!', true)
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   682
        then exit;
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   683
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   684
ResizeLand(tmpsurf^.w, tmpsurf^.h);
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   685
LoadMapConfig;
1792
c30c6944bd49 engine part of nemo's patch
unc0rr
parents: 1784
diff changeset
   686
1776
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   687
playHeight:= tmpsurf^.h;
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   688
playWidth:= tmpsurf^.w;
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   689
leftX:= (LAND_WIDTH - playWidth) div 2;
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   690
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1;
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   691
topY:= LAND_HEIGHT - playHeight;
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   692
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   693
if not checkFails(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true) then
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   694
    BlitImageAndGenerateCollisionInfo(
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   695
        (LAND_WIDTH - tmpsurf^.w) div 2,
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   696
        LAND_HEIGHT - tmpsurf^.h,
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   697
        tmpsurf^.w,
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   698
        tmpsurf);
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   699
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   700
SDL_FreeSurface(tmpsurf);
1792
c30c6944bd49 engine part of nemo's patch
unc0rr
parents: 1784
diff changeset
   701
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
   702
if allOK then LoadMask;
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   703
end;
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   704
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   705
procedure DrawBottomBorder; // broken out from other borders for doing a floor-only map, or possibly updating bottom during SD
12086
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   706
var x, w, c, y: Longword;
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   707
begin
5718
e74de0528ef4 Let's draw the bottom border thicker, so it is more visible
nemo
parents: 5717
diff changeset
   708
for w:= 0 to 23 do
14282
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13788
diff changeset
   709
    for x:= LongWord(leftX) to LongWord(rightX) do
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   710
        begin
12086
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   711
        y:= Longword(cWaterLine) - 1 - w;
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   712
        Land[y, x]:= lfIndestructible;
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   713
        if (x + y) mod 32 < 16 then
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   714
            c:= AMask
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   715
        else
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   716
            c:= AMask or RMask or GMask; // FF00FFFF
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   718
        if (cReducedQuality and rqBlurryLand) = 0 then
12086
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   719
            LandPixels[y, x]:= c
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   720
        else
12086
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   721
            LandPixels[y div 2, x div 2]:= c
5718
e74de0528ef4 Let's draw the bottom border thicker, so it is more visible
nemo
parents: 5717
diff changeset
   722
        end
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   723
end;
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   724
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   725
procedure GenMap;
12086
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   726
var x, y, w, c, c2: Longword;
8025
07862ab415c8 Get rid of Pathz and UserPathz
unc0rr
parents: 8011
diff changeset
   727
    map, mask: shortstring;
1754
a37392548124 Some fixes by nemo
unc0rr
parents: 1753
diff changeset
   728
begin
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3407
diff changeset
   729
    hasBorder:= false;
8011
ffd5eba8f7c2 objects too
nemo
parents: 8010
diff changeset
   730
    maskOnly:= false;
2891
e1f902eb0cfe Formerly "Draw Girders" by MrMfS - now "Disable Girders" to allow template prefs to still exist
nemo
parents: 2866
diff changeset
   731
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3407
diff changeset
   732
    LoadThemeConfig;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3632
diff changeset
   733
11881
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   734
    if cPathz[ptMapCurrent] <> '' then
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   735
        begin
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   736
        map:= cPathz[ptMapCurrent] + '/map.png';
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   737
        mask:= cPathz[ptMapCurrent] + '/mask.png';
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   738
        if (not(pfsExists(map)) and pfsExists(mask)) then
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   739
            begin
11881
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   740
            maskOnly:= true;
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   741
            LoadMask;
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   742
            GenLandSurface
8010
195677b0d06b something bender asked for. allow a mask without a map
nemo
parents: 8003
diff changeset
   743
            end
11881
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   744
        else LoadMap;
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   745
        end
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3407
diff changeset
   746
    else
11881
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   747
        begin
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   748
        WriteLnToConsole('Generating land...');
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   749
        case cMapGen of
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   750
            mgRandom: GenTemplated(EdgeTemplates[SelectTemplate]);
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   751
            mgMaze  : begin ResizeLand(4096,2048); GenMaze; end;
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   752
            mgPerlin: begin ResizeLand(4096,2048); GenPerlin; end;
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   753
            mgDrawn : GenDrawnMap;
13272
5984e8c6cbeb Add new game flag gfSwitchHog, enable hog switching at turn start
Wuzzy <Wuzzy2@mail.ru>
parents: 12758
diff changeset
   754
            mgForts : begin GameFlags:= (GameFlags or gfDivideTeams); MakeFortsMap(); end;
11881
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   755
        else
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   756
            OutError('Unknown mapgen', true);
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   757
        end;
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   758
        if cMapGen <> mgForts then
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   759
            GenLandSurface
34ede05e4d4f Remove old Fort Mode from frontend
Wuzzy <almikes@aol.com>
parents: 11826
diff changeset
   760
        end;
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3407
diff changeset
   761
23c50be687a9 update sdl functions to latest revision
koda
parents: 3407
diff changeset
   762
    AddProgress;
1760
55a1edd97911 Fix nemo's large land patch
unc0rr
parents: 1754
diff changeset
   763
1768
9f83102b11ca That was wrong place for the patch
unc0rr
parents: 1767
diff changeset
   764
// check for land near top
1784
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   765
c:= 0;
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   766
if (GameFlags and gfBorder) <> 0 then
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   767
    hasBorder:= true
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   768
else
14286
7a7c090f96f6 topY too
nemo
parents: 14284
diff changeset
   769
    for y:= LongWord(topY) to LongWord(topY + 5) do
14282
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13788
diff changeset
   770
        for x:= LongWord(leftX) to LongWord(rightX) do
1784
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   771
            if Land[y, x] <> 0 then
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   772
                begin
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   773
                inc(c);
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8266
diff changeset
   774
                if c > LongWord((LAND_WIDTH div 2)) then // avoid accidental triggering
1784
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   775
                    begin
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   776
                    hasBorder:= true;
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   777
                    break;
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   778
                    end;
dfe9bafb4590 Apply nemo's patch polished by me:
unc0rr
parents: 1779
diff changeset
   779
                end;
1768
9f83102b11ca That was wrong place for the patch
unc0rr
parents: 1767
diff changeset
   780
1776
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   781
if hasBorder then
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   782
    begin
10661
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   783
    if WorldEdge = weNone then
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   784
        begin
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   785
        for y:= 0 to LAND_HEIGHT - 1 do
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   786
            for x:= 0 to LAND_WIDTH - 1 do
14286
7a7c090f96f6 topY too
nemo
parents: 14284
diff changeset
   787
                if (y < LongWord(topY)) or (x < LongWord(leftX)) or (x > LongWord(rightX)) then
10661
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   788
                    Land[y, x]:= lfIndestructible;
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   789
        end
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   790
    else if topY > 0 then
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   791
        begin
14286
7a7c090f96f6 topY too
nemo
parents: 14284
diff changeset
   792
        for y:= 0 to LongWord(topY - 1) do
10661
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   793
            for x:= 0 to LAND_WIDTH - 1 do
3519
56cbc035b74b rename flags
nemo
parents: 3513
diff changeset
   794
                Land[y, x]:= lfIndestructible;
10661
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   795
        end;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   796
    // experiment hardcoding cave
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   797
    // also try basing cave dimensions on map/template dimensions, if they exist
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   798
    for w:= 0 to 5 do // width of 3 allowed hogs to be knocked through with grenade
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   799
        begin
9524
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   800
        if (WorldEdge <> weBounce) and (WorldEdge <> weWrap) then
14286
7a7c090f96f6 topY too
nemo
parents: 14284
diff changeset
   801
            for y:= LongWord(topY) to LAND_HEIGHT - 1 do
9524
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   802
                    begin
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   803
                    Land[y, leftX + w]:= lfIndestructible;
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   804
                    Land[y, rightX - w]:= lfIndestructible;
12086
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   805
                    if (y + leftX + w) mod 32 < 16 then
9524
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   806
                        c:= AMask
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   807
                    else
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   808
                        c:= AMask or RMask or GMask; // FF00FFFF
12087
78e9fbd52ffc simplify code of previous commit ( ba1807589eaa )
sheepluva
parents: 12086
diff changeset
   809
                    if (y + rightX - w) mod 32 < 16 then
12086
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   810
                        c2:= AMask
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   811
                    else
ba1807589eaa OCD-compatibility-patch: make border stripes consistent in direction and offset, seamless.
sheepluva
parents: 11881
diff changeset
   812
                        c2:= AMask or RMask or GMask; // FF00FFFF
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3551
diff changeset
   813
9524
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   814
                    if (cReducedQuality and rqBlurryLand) = 0 then
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   815
                        begin
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   816
                        LandPixels[y, leftX + w]:= c;
12087
78e9fbd52ffc simplify code of previous commit ( ba1807589eaa )
sheepluva
parents: 12086
diff changeset
   817
                        LandPixels[y, rightX - w]:= c2;
9524
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   818
                        end
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   819
                    else
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   820
                        begin
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   821
                        LandPixels[y div 2, (leftX + w) div 2]:= c;
12087
78e9fbd52ffc simplify code of previous commit ( ba1807589eaa )
sheepluva
parents: 12086
diff changeset
   822
                        LandPixels[y div 2, (rightX - w) div 2]:= c2;
9524
0a52c1dd9400 disable side borders if bounce or wrap
nemo
parents: 9387
diff changeset
   823
                        end;
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   824
                    end;
1768
9f83102b11ca That was wrong place for the patch
unc0rr
parents: 1767
diff changeset
   825
14282
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13788
diff changeset
   826
        for x:= LongWord(leftX) to LongWord(rightX) do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   827
            begin
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   828
            Land[topY + w, x]:= lfIndestructible;
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   829
            if (x + w) mod 32 < 16 then
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   830
                c:= AMask
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   831
            else
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   832
                c:= AMask or RMask or GMask; // FF00FFFF
3595
341e407e3754 partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents: 3551
diff changeset
   833
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   834
            if (cReducedQuality and rqBlurryLand) = 0 then
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   835
                LandPixels[topY + w, x]:= c
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   836
            else
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   837
                LandPixels[(topY + w) div 2, x div 2]:= c;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   838
            end;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   839
        end;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
   840
    end;
1768
9f83102b11ca That was wrong place for the patch
unc0rr
parents: 1767
diff changeset
   841
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   842
if (GameFlags and gfBottomBorder) <> 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   843
    DrawBottomBorder;
5717
6d513913b7a9 Add option for a bottom border. Needs testing.
nemo
parents: 5687
diff changeset
   844
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   845
if (GameFlags and gfDisableGirders) <> 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   846
    hasGirders:= false;
2891
e1f902eb0cfe Formerly "Draw Girders" by MrMfS - now "Disable Girders" to allow template prefs to still exist
nemo
parents: 2866
diff changeset
   847
13272
5984e8c6cbeb Add new game flag gfSwitchHog, enable hog switching at turn start
Wuzzy <Wuzzy2@mail.ru>
parents: 12758
diff changeset
   848
if (cMapGen <> mgForts) and (maskOnly or (cPathz[ptMapCurrent] = '')) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   849
    AddObjects
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   850
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   851
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   852
    AddProgress();
1776
dd5648e250e4 - nemo's patch for custom cave map dimensions
unc0rr
parents: 1773
diff changeset
   853
3058
2ebc20485344 Engine:
smxx
parents: 3055
diff changeset
   854
FreeLandObjects;
2ebc20485344 Engine:
smxx
parents: 3055
diff changeset
   855
11539
c22d292e7266 Fix possible crashes/hangs due to recent changes
unC0Rr
parents: 11532
diff changeset
   856
if not allOK then exit;
c22d292e7266 Fix possible crashes/hangs due to recent changes
unC0Rr
parents: 11532
diff changeset
   857
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6927
diff changeset
   858
if GrayScale then
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   859
    begin
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   860
    if (cReducedQuality and rqBlurryLand) = 0 then
14282
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13788
diff changeset
   861
        for x:= LongWord(leftX) to LongWord(rightX) do
14286
7a7c090f96f6 topY too
nemo
parents: 14284
diff changeset
   862
            for y:= LongWord(topY) to LAND_HEIGHT-1 do
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   863
                begin
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   864
                w:= LandPixels[y,x];
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   865
                w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   866
                      (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   867
                      (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   868
                if w > 255 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   869
                    w:= 255;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   870
                w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask);
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   871
                LandPixels[y,x]:= w or (LandPixels[y, x] and AMask)
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   872
                end
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   873
    else
14282
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13788
diff changeset
   874
        for x:= LongWord(leftX div 2) to LongWord(rightX div 2) do
14286
7a7c090f96f6 topY too
nemo
parents: 14284
diff changeset
   875
            for y:= LongWord(topY div 2) to LAND_HEIGHT-1 div 2 do
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   876
                begin
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   877
                w:= LandPixels[y div 2,x div 2];
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   878
                w:= ((w shr RShift and $FF) +  (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   879
                w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   880
                LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   881
                end
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5274
diff changeset
   882
    end;
10016
59a6d65fcb60 (experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents: 9998
diff changeset
   883
59a6d65fcb60 (experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents: 9998
diff changeset
   884
PrettifyLandAlpha();
10626
2562797ab3cf adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents: 10603
diff changeset
   885
10661
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   886
// adjust world edges for borderless maps
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   887
if (WorldEdge <> weNone) and (not hasBorder) then
0da243c01bde world edge tweakes/fixes
sheepluva
parents: 10626
diff changeset
   888
    InitWorldEdges();
10626
2562797ab3cf adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
sheepluva
parents: 10603
diff changeset
   889
13752
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13501
diff changeset
   890
ScriptSetMapGlobals;
37
2b7f2a43b999 - Properly get seed in net game
unc0rr
parents: 35
diff changeset
   891
end;
2b7f2a43b999 - Properly get seed in net game
unc0rr
parents: 35
diff changeset
   892
7079
939f53515489 Learn hask^Wpascal, dudes!
unc0rr
parents: 7063
diff changeset
   893
procedure GenPreview(out Preview: TPreview);
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   894
var rh, rw, ox, oy, x, y, xx, yy, t, bit, cbit, lh, lw: LongInt;
155
401f4ea24715 Engine can generate land preview and send it via IPC
unc0rr
parents: 109
diff changeset
   895
begin
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   896
    WriteLnToConsole('Generating preview...');
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   897
    case cMapGen of
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10490
diff changeset
   898
        mgRandom: GenTemplated(EdgeTemplates[SelectTemplate]);
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10490
diff changeset
   899
        mgMaze: begin ResizeLand(4096,2048); GenMaze; end;
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10490
diff changeset
   900
        mgPerlin: begin ResizeLand(4096,2048); GenPerlin; end;
15010
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   901
        mgDrawn: begin GenDrawnMap; end;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   902
        mgForts: MakeFortsPreview();
4562
b55f78fd2bf6 - Simplify map container code a bit
unc0rr
parents: 4559
diff changeset
   903
    else
b55f78fd2bf6 - Simplify map container code a bit
unc0rr
parents: 4559
diff changeset
   904
        OutError('Unknown mapgen', true);
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   905
    end;
155
401f4ea24715 Engine can generate land preview and send it via IPC
unc0rr
parents: 109
diff changeset
   906
13752
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13501
diff changeset
   907
    ScriptSetMapGlobals;
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13501
diff changeset
   908
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   909
    // strict scaling needed here since preview assumes a rectangle
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   910
    if (cMapGen <> mgDrawn) then
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   911
        begin
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   912
        rh:= max(LAND_HEIGHT, 2048);
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   913
        rw:= max(LAND_WIDTH, 4096);
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   914
        end
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   915
    else
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   916
        begin
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   917
        rh:= LAND_HEIGHT;
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   918
        rw:= LAND_WIDTH
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   919
        end;
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   920
    ox:= 0;
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   921
    if rw < rh*2 then
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   922
        begin
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   923
        rw:= rh*2;
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   924
        end;
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   925
    if rh < rw div 2 then rh:= rw * 2;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   926
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   927
    ox:= (rw-LAND_WIDTH) div 2;
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   928
    oy:= rh-LAND_HEIGHT;
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   929
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   930
    lh:= rh div 128;
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   931
    lw:= rw div 32;
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   932
    for y:= 0 to 127 do
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   933
        for x:= 0 to 31 do
155
401f4ea24715 Engine can generate land preview and send it via IPC
unc0rr
parents: 109
diff changeset
   934
        begin
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   935
            Preview[y, x]:= 0;
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   936
            for bit:= 0 to 7 do
155
401f4ea24715 Engine can generate land preview and send it via IPC
unc0rr
parents: 109
diff changeset
   937
            begin
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   938
                t:= 0;
3617
1df21e06b8ba a couple of fixes i missed previously
koda
parents: 3612
diff changeset
   939
                cbit:= bit * 8;
1df21e06b8ba a couple of fixes i missed previously
koda
parents: 3612
diff changeset
   940
                for yy:= y * lh to y * lh + 7 do
1df21e06b8ba a couple of fixes i missed previously
koda
parents: 3612
diff changeset
   941
                    for xx:= x * lw + cbit to x * lw + cbit + 7 do
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   942
                        if ((yy-oy) and LAND_HEIGHT_MASK = 0) and ((xx-ox) and LAND_WIDTH_MASK = 0)
7477
26706bf32ecf First pass at variable land size. For playing a small map (forced on rqLowRes), this should save 42MiB of RAM.
nemo
parents: 7293
diff changeset
   943
                           and (Land[yy-oy, xx-ox] <> 0) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6491
diff changeset
   944
                            inc(t);
3365
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   945
                if t > 8 then
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   946
                    Preview[y, x]:= Preview[y, x] or ($80 shr bit);
37ac593e9027 wow all these files only for land preview and seed generation
koda
parents: 3287
diff changeset
   947
            end;
566
1c1cb593cb81 Save some memory
unc0rr
parents: 561
diff changeset
   948
        end;
155
401f4ea24715 Engine can generate land preview and send it via IPC
unc0rr
parents: 109
diff changeset
   949
end;
401f4ea24715 Engine can generate land preview and send it via IPC
unc0rr
parents: 109
diff changeset
   950
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
   951
10162
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   952
procedure GenPreviewAlpha(out Preview: TPreviewAlpha);
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   953
var rh, rw, ox, oy, x, y, xx, yy, t, lh, lw: LongInt;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   954
begin
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   955
    WriteLnToConsole('Generating preview...');
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   956
    case cMapGen of
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10490
diff changeset
   957
        mgRandom: GenTemplated(EdgeTemplates[SelectTemplate]);
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10490
diff changeset
   958
        mgMaze: begin ResizeLand(4096,2048); GenMaze; end;
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10490
diff changeset
   959
        mgPerlin: begin ResizeLand(4096,2048); GenPerlin; end;
15010
5d8068ee16fc Give a more accurate hedgehog limit estimate for small drawn maps
Wuzzy <Wuzzy2@mail.ru>
parents: 14418
diff changeset
   960
        mgDrawn: begin GenDrawnMap; end;
11744
ac58a063d26a Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents: 11734
diff changeset
   961
        mgForts: MakeFortsPreview;
10162
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   962
    else
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   963
        OutError('Unknown mapgen', true);
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   964
    end;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   965
13752
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13501
diff changeset
   966
    ScriptSetMapGlobals;
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13501
diff changeset
   967
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   968
10162
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   969
    // strict scaling needed here since preview assumes a rectangle
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   970
    if (cMapGen <> mgDrawn) then
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   971
        begin
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   972
        rh:= max(LAND_HEIGHT, 2048);
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   973
        rw:= max(LAND_WIDTH, 4096);
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   974
        end
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   975
    else
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   976
        begin
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   977
        rh:= LAND_HEIGHT;
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   978
        rw:= LAND_WIDTH
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   979
        end;
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
   980
10162
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   981
    ox:= 0;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   982
    if rw < rh*2 then
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   983
        begin
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   984
        rw:= rh*2;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   985
        end;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   986
    if rh < rw div 2 then rh:= rw * 2;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   987
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   988
    ox:= (rw-LAND_WIDTH) div 2;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   989
    oy:= rh-LAND_HEIGHT;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   990
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   991
    lh:= rh div 128;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   992
    lw:= rw div 256;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   993
    for y:= 0 to 127 do
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   994
        for x:= 0 to 255 do
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   995
            begin
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   996
            t:= 0;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
   997
10165
e84f9b928ad3 Use all pixels, not only 8x8 areas
unc0rr
parents: 10163
diff changeset
   998
            for yy:= y * lh - oy to y * lh + lh - 1 - oy do
e84f9b928ad3 Use all pixels, not only 8x8 areas
unc0rr
parents: 10163
diff changeset
   999
                for xx:= x * lw - ox to x * lw + lw - 1 - ox do
10162
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
  1000
                    if (yy and LAND_HEIGHT_MASK = 0) and (xx and LAND_WIDTH_MASK = 0)
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
  1001
                        and (Land[yy, xx] <> 0) then
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
  1002
                        inc(t);
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
  1003
10165
e84f9b928ad3 Use all pixels, not only 8x8 areas
unc0rr
parents: 10163
diff changeset
  1004
            Preview[y, x]:= t * 255 div (lh * lw);
10162
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
  1005
            end;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
  1006
end;
38dbf26475d8 Add alpha channel to preview
unc0rr
parents: 10142
diff changeset
  1007
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1008
procedure chLandCheck(var s: shortstring);
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1009
begin
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1010
    AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest);
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1011
    if digest = '' then
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1012
        digest:= s
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1013
    else
13499
c41b16ac2e05 Clarify the wording of a few checkFails messages
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  1014
        checkFails(s = digest, 'Loaded map or other critical resource does not match across all players', true);
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1015
end;
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1016
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1017
procedure chSendLandDigest(var s: shortstring);
12711
20dbb3a03e61 extend land digest to all surfaces that could possibly be loaded into Land[] - i.e. ones that impact sync
nemo
parents: 12592
diff changeset
  1018
var i: LongInt;
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
  1019
    landPixelDigest  : LongInt;
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1020
begin
14418
0281b80d366c might as well render preview using smallest size to speed it up
nemo
parents: 14416
diff changeset
  1021
    landPixelDigest:= 1;
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1022
    for i:= 0 to LAND_HEIGHT-1 do
13788
381e37c6d5d9 Separate synced pixels from land digests - this is mostly to allow the official racer digests to remain unchanged.
nemo
parents: 13752
diff changeset
  1023
        landPixelDigest:= Adler32Update(landPixelDigest, @Land[i,0], LAND_WIDTH*2);
381e37c6d5d9 Separate synced pixels from land digests - this is mostly to allow the official racer digests to remain unchanged.
nemo
parents: 13752
diff changeset
  1024
    s:= 'M' + IntToStr(syncedPixelDigest)+'|'+IntToStr(landPixelDigest);
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1025
13788
381e37c6d5d9 Separate synced pixels from land digests - this is mostly to allow the official racer digests to remain unchanged.
nemo
parents: 13752
diff changeset
  1026
    ScriptSetString('LandDigest',IntToStr(landPixelDigest));
10022
eb981a03de90 - Make Racer report achievements
unc0rr
parents: 10018
diff changeset
  1027
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1028
    chLandCheck(s);
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11507
diff changeset
  1029
    if allOK then SendIPCRaw(@s[0], Length(s) + 1)
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1030
end;
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1031
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 3017
diff changeset
  1032
procedure initModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2692
diff changeset
  1033
begin
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6700
diff changeset
  1034
    RegisterVariable('landcheck', @chLandCheck, false);
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6700
diff changeset
  1035
    RegisterVariable('sendlanddigest', @chSendLandDigest, false);
4398
36d7e4b6ca81 Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents: 4389
diff changeset
  1036
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2905
diff changeset
  1037
    LandBackSurface:= nil;
3369
c7289e42f0ee add other controls for map preview, also fix a bug in digest
koda
parents: 3365
diff changeset
  1038
    digest:= '';
11019
67ef02300508 always draw border on terrain if there is only a map mask and no map image. this is a workaround for the fact that space campaign masks use white (lfObject) color instead of black (lfBasic)
sheepluva
parents: 11006
diff changeset
  1039
    maskOnly:= false;
7549
f6145d12bb17 Avoid a bit of a memory spike on small maps
nemo
parents: 7483
diff changeset
  1040
    LAND_WIDTH:= 0;
f6145d12bb17 Avoid a bit of a memory spike on small maps
nemo
parents: 7483
diff changeset
  1041
    LAND_HEIGHT:= 0;
f6145d12bb17 Avoid a bit of a memory spike on small maps
nemo
parents: 7483
diff changeset
  1042
(*
3612
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
  1043
    if (cReducedQuality and rqBlurryLand) = 0 then
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
  1044
        SetLength(LandPixels, LAND_HEIGHT, LAND_WIDTH)
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
  1045
    else
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
  1046
        SetLength(LandPixels, LAND_HEIGHT div 2, LAND_WIDTH div 2);
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
  1047
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
  1048
    SetLength(Land, LAND_HEIGHT, LAND_WIDTH);
b50215a8a43d land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents: 3608
diff changeset
  1049
    SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
7549
f6145d12bb17 Avoid a bit of a memory spike on small maps
nemo
parents: 7483
diff changeset
  1050
*)
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2692
diff changeset
  1051
end;
51
b6e3ae05857f - Get rid of hwserv and runhelper
unc0rr
parents: 37
diff changeset
  1052
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 3017
diff changeset
  1053
procedure freeModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2692
diff changeset
  1054
begin
7151
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7079
diff changeset
  1055
    SetLength(Land, 0, 0);
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7079
diff changeset
  1056
    SetLength(LandPixels, 0, 0);
ec15d9e1a7e3 pas2c stuff
unc0rr
parents: 7079
diff changeset
  1057
    SetLength(LandDirty, 0, 0);
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2692
diff changeset
  1058
end;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2692
diff changeset
  1059
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
  1060
end.