hedgewars/uLandPainted.pas
author koda
Thu, 13 Jan 2011 04:17:51 +0100
branch0.9.15
changeset 4736 b4b44ae480c2
parent 4730 bd74fd83929a
child 4779 53f7e964a338
child 4900 8ad0e23e6d63
permissions -rw-r--r--
merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     1
(*
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2010 Andrey Korotaev <unC0Rr@gmail.com>
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     4
 *
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     8
 *
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    13
 *
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    17
 *)
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    18
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    20
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    21
unit uLandPainted;
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    22
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    23
interface
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    24
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    25
procedure Draw;
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
    26
procedure initModule;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    27
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    28
implementation
4648
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
    29
uses uLandGraphics, uConsts, uUtils, SDLh, uCommands, uDebug;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    30
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    31
type PointRec = packed record
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    32
    X, Y: SmallInt;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    33
    flags: byte;
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    34
    end;
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    35
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    36
type
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    37
    PPointEntry = ^PointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    38
    PointEntry = record
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    39
        point: PointRec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    40
        next: PPointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    41
        end;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    42
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    43
var pointsListHead, pointsListLast: PPointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    44
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    45
procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    46
var  eX, eY, dX, dY: LongInt;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    47
    i, sX, sY, x, y, d: LongInt;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    48
    b: boolean;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    49
    len: LongWord;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    50
begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    51
    len:= 0;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    52
    if (X1 = X2) and (Y1 = Y2) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    53
        begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    54
        exit
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    55
        end;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    56
    eX:= 0;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    57
    eY:= 0;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    58
    dX:= X2 - X1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    59
    dY:= Y2 - Y1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    60
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    61
    if (dX > 0) then sX:= 1
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    62
    else
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    63
    if (dX < 0) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    64
        begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    65
        sX:= -1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    66
        dX:= -dX
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    67
        end else sX:= dX;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    68
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    69
    if (dY > 0) then sY:= 1
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    70
    else
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    71
    if (dY < 0) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    72
        begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    73
        sY:= -1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    74
        dY:= -dY
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    75
        end else sY:= dY;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    76
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    77
        if (dX > dY) then d:= dX
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    78
                    else d:= dY;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    79
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    80
        x:= X1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    81
        y:= Y1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    82
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    83
        for i:= 0 to d do
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    84
            begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    85
            inc(eX, dX);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    86
            inc(eY, dY);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    87
            b:= false;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    88
            if (eX > d) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    89
                begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    90
                dec(eX, d);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    91
                inc(x, sX);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    92
                b:= true
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    93
                end;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    94
            if (eY > d) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    95
                begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    96
                dec(eY, d);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    97
                inc(y, sY);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    98
                b:= true
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    99
                end;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   100
            if b then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   101
                begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   102
                inc(len);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   103
                if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic)
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   104
                end
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   105
        end
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   106
end;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   107
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   108
procedure chDraw(var s: shortstring);
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   109
var rec: PointRec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   110
    prec: ^PointRec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   111
    pe: PPointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   112
    i, l: byte;
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   113
begin
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   114
    i:= 1;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   115
    l:= length(s);
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   116
    while i < l do
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   117
        begin
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   118
        prec:= @s[i];
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   119
        rec:= prec^;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   120
        rec.X:= SDLNet_Read16(@rec.X);
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   121
        rec.Y:= SDLNet_Read16(@rec.Y);
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   122
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   123
        pe:= new(PPointEntry);
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   124
        if pointsListLast = nil then
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   125
            pointsListHead:= pe
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   126
        else
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   127
            pointsListLast^.next:= pe;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   128
        pointsListLast:= pe;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   129
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   130
        pe^.point:= rec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   131
        pe^.next:= nil;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   132
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   133
        inc(i, 5)
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   134
        end;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   135
end;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   136
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   137
procedure Draw;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   138
var pe: PPointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   139
    prevPoint: PointRec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   140
begin
4648
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
   141
    // shutup compiler
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
   142
    prevPoint.X:= 0;
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
   143
    prevPoint.Y:= 0;
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
   144
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   145
    pe:= pointsListHead;
4648
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
   146
    TryDo((pe = nil) or (pe^.point.flags and $80 <> 0), 'Corrupted draw data', true);
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   147
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   148
    while(pe <> nil) do
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   149
        begin
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   150
        if (pe^.point.flags and $80 <> 0) then
4649
82bf0a0fa8b0 Add logging of map drawing process
unc0rr
parents: 4648
diff changeset
   151
            begin
4730
koda
parents: 4728
diff changeset
   152
            {$IFDEF DEBUGFILE}AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+')');{$ENDIF}
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   153
            FillRoundInLand(pe^.point.X, pe^.point.Y, 34, lfBasic)
4649
82bf0a0fa8b0 Add logging of map drawing process
unc0rr
parents: 4648
diff changeset
   154
            end
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   155
            else
4649
82bf0a0fa8b0 Add logging of map drawing process
unc0rr
parents: 4648
diff changeset
   156
            begin
4728
3d808af10ea0 AddFileLogs
koda
parents: 4649
diff changeset
   157
            {$IFDEF DEBUGFILE}AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+')');{$ENDIF}
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   158
            DrawLineOnLand(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y);
4649
82bf0a0fa8b0 Add logging of map drawing process
unc0rr
parents: 4648
diff changeset
   159
            end;
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   160
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   161
        prevPoint:= pe^.point;
4648
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
   162
        pe:= pe^.next;  
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   163
        end;
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   164
end;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   165
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   166
procedure initModule;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   167
begin
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   168
    pointsListHead:= nil;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   169
    pointsListLast:= nil;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   170
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   171
    RegisterVariable('draw', vtCommand, @chDraw, false);
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   172
end;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   173
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   174
end.