hedgewars/uLandPainted.pas
author unc0rr
Wed, 08 Dec 2010 22:25:30 +0300
changeset 4490 f6840f7e2f60
parent 4458 7351e6f1ee28
child 4494 9585435e20f7
permissions -rw-r--r--
Stub to recieve /draw command
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
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    25
procedure LoadFromFile(fileName: shortstring);
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
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
    29
uses uLandGraphics, uConsts, uUtils, SDLh, uCommands;
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
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    36
procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    37
var  eX, eY, dX, dY: LongInt;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    38
    i, sX, sY, x, y, d: LongInt;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    39
    b: boolean;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    40
    len: LongWord;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    41
begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    42
    len:= 0;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    43
    if (X1 = X2) and (Y1 = Y2) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    44
        begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    45
        exit
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    46
        end;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    47
    eX:= 0;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    48
    eY:= 0;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    49
    dX:= X2 - X1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    50
    dY:= Y2 - Y1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    51
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    52
    if (dX > 0) then sX:= 1
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    53
    else
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    54
    if (dX < 0) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    55
        begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    56
        sX:= -1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    57
        dX:= -dX
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    58
        end else sX:= dX;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    59
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    60
    if (dY > 0) then sY:= 1
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    61
    else
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    62
    if (dY < 0) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    63
        begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    64
        sY:= -1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    65
        dY:= -dY
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    66
        end else sY:= dY;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    67
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    68
        if (dX > dY) then d:= dX
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    69
                    else d:= dY;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    70
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    71
        x:= X1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    72
        y:= Y1;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    73
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    74
        for i:= 0 to d do
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    75
            begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    76
            inc(eX, dX);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    77
            inc(eY, dY);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    78
            b:= false;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    79
            if (eX > d) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    80
                begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    81
                dec(eX, d);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    82
                inc(x, sX);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    83
                b:= true
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    84
                end;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    85
            if (eY > d) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    86
                begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    87
                dec(eY, d);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    88
                inc(y, sY);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    89
                b:= true
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    90
                end;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    91
            if b then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    92
                begin
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    93
                inc(len);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    94
                if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic)
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    95
                end
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    96
        end
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    97
end;
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    98
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    99
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   100
procedure LoadFromFile(fileName: shortstring);
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   101
var
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   102
    f: file of PointRec;
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   103
    rec, prevRec: PointRec;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   104
begin
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   105
    fileMode:= 0;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   106
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   107
    assignFile(f, fileName);
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   108
    reset(f);
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   109
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   110
    while not eof(f) do
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   111
        begin
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   112
        read(f, rec);
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   113
        rec.X:= SDLNet_Read16(@rec.X);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   114
        rec.Y:= SDLNet_Read16(@rec.Y);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   115
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   116
        // FIXME: handle single point
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   117
        if eof(f) or (rec.flags and $80 <> 0) then
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   118
            else
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   119
            DrawLineOnLand(prevRec.X, prevRec.Y, rec.X, rec.Y);
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   120
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
   121
        prevRec:= rec;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   122
        end;
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   123
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   124
    closeFile(f);
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   125
end;
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   126
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   127
procedure chDraw(var s: shortstring);
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   128
begin
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   129
end;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   130
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   131
procedure initModule;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   132
begin
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   133
    RegisterVariable('draw', vtCommand, @chDraw, false);
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   134
end;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   135
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   136
end.