hedgewars/uLandPainted.pas
branchhedgeroid
changeset 7855 ddcdedd3330b
parent 7583 8a9edc7cf98f
child 9080 9b42757d7e71
equal deleted inserted replaced
6350:41b0a9955c47 7855:ddcdedd3330b
     1 (*
     1 (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    25 procedure Draw;
    25 procedure Draw;
    26 procedure initModule;
    26 procedure initModule;
    27 procedure freeModule;
    27 procedure freeModule;
    28 
    28 
    29 implementation
    29 implementation
    30 uses uLandGraphics, uConsts, uUtils, SDLh, uCommands, uDebug;
    30 uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uDebug;
    31 
    31 
    32 type PointRec = packed record
    32 type PointRec = packed record
    33     X, Y: SmallInt;
    33     X, Y: SmallInt;
    34     flags: byte;
    34     flags: byte;
    35     end;
    35     end;
    41         next: PPointEntry;
    41         next: PPointEntry;
    42         end;
    42         end;
    43 
    43 
    44 var pointsListHead, pointsListLast: PPointEntry;
    44 var pointsListHead, pointsListLast: PPointEntry;
    45 
    45 
    46 procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt);
       
    47 var  eX, eY, dX, dY: LongInt;
       
    48     i, sX, sY, x, y, d: LongInt;
       
    49     b: boolean;
       
    50     len: LongWord;
       
    51 begin
       
    52     len:= 0;
       
    53     if (X1 = X2) and (Y1 = Y2) then
       
    54         begin
       
    55         exit
       
    56         end;
       
    57     eX:= 0;
       
    58     eY:= 0;
       
    59     dX:= X2 - X1;
       
    60     dY:= Y2 - Y1;
       
    61 
       
    62     if (dX > 0) then sX:= 1
       
    63     else
       
    64     if (dX < 0) then
       
    65         begin
       
    66         sX:= -1;
       
    67         dX:= -dX
       
    68         end else sX:= dX;
       
    69 
       
    70     if (dY > 0) then sY:= 1
       
    71     else
       
    72     if (dY < 0) then
       
    73         begin
       
    74         sY:= -1;
       
    75         dY:= -dY
       
    76         end else sY:= dY;
       
    77 
       
    78         if (dX > dY) then d:= dX
       
    79                     else d:= dY;
       
    80 
       
    81         x:= X1;
       
    82         y:= Y1;
       
    83 
       
    84         for i:= 0 to d do
       
    85             begin
       
    86             inc(eX, dX);
       
    87             inc(eY, dY);
       
    88             b:= false;
       
    89             if (eX > d) then
       
    90                 begin
       
    91                 dec(eX, d);
       
    92                 inc(x, sX);
       
    93                 b:= true
       
    94                 end;
       
    95             if (eY > d) then
       
    96                 begin
       
    97                 dec(eY, d);
       
    98                 inc(y, sY);
       
    99                 b:= true
       
   100                 end;
       
   101             if b then
       
   102                 begin
       
   103                 inc(len);
       
   104                 if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic)
       
   105                 end
       
   106         end
       
   107 end;
       
   108 
       
   109 procedure chDraw(var s: shortstring);
    46 procedure chDraw(var s: shortstring);
   110 var rec: PointRec;
    47 var rec: PointRec;
   111     prec: ^PointRec;
    48     prec: ^PointRec;
   112     pe: PPointEntry;
    49     pe: PPointEntry;
   113     i, l: byte;
    50     i, l: byte;
   118         begin
    55         begin
   119         prec:= @s[i];
    56         prec:= @s[i];
   120         rec:= prec^;
    57         rec:= prec^;
   121         rec.X:= SDLNet_Read16(@rec.X);
    58         rec.X:= SDLNet_Read16(@rec.X);
   122         rec.Y:= SDLNet_Read16(@rec.Y);
    59         rec.Y:= SDLNet_Read16(@rec.Y);
       
    60         if rec.X < -318 then rec.X:= -318;
       
    61         if rec.X > 4096+318 then rec.X:= 4096+318;
       
    62         if rec.Y < -318 then rec.Y:= -318;
       
    63         if rec.Y > 2048+318 then rec.Y:= 2048+318;
   123 
    64 
   124         pe:= new(PPointEntry);
    65         new(pe);
   125         if pointsListLast = nil then
    66         if pointsListLast = nil then
   126             pointsListHead:= pe
    67             pointsListHead:= pe
   127         else
    68         else
   128             pointsListLast^.next:= pe;
    69             pointsListLast^.next:= pe;
   129         pointsListLast:= pe;
    70         pointsListLast:= pe;
   136 end;
    77 end;
   137 
    78 
   138 procedure Draw;
    79 procedure Draw;
   139 var pe: PPointEntry;
    80 var pe: PPointEntry;
   140     prevPoint: PointRec;
    81     prevPoint: PointRec;
       
    82     radius: LongInt;
       
    83     color: Longword;
   141 begin
    84 begin
   142     // shutup compiler
    85     // shutup compiler
   143     prevPoint.X:= 0;
    86     prevPoint.X:= 0;
   144     prevPoint.Y:= 0;
    87     prevPoint.Y:= 0;
       
    88     radius:= 0;
   145 
    89 
   146     pe:= pointsListHead;
    90     pe:= pointsListHead;
   147     TryDo((pe = nil) or (pe^.point.flags and $80 <> 0), 'Corrupted draw data', true);
    91     TryDo((pe = nil) or (pe^.point.flags and $80 <> 0), 'Corrupted draw data', true);
   148 
    92 
   149     while(pe <> nil) do
    93     while(pe <> nil) do
   150         begin
    94         begin
   151         if (pe^.point.flags and $80 <> 0) then
    95         if (pe^.point.flags and $80 <> 0) then
   152             begin
    96             begin
   153             AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+')');
    97             if (pe^.point.flags and $40 <> 0) then
   154             FillRoundInLand(pe^.point.X, pe^.point.Y, 34, lfBasic)
    98                 color:= 0
       
    99                 else
       
   100                 color:= lfBasic;
       
   101             radius:= (pe^.point.flags and $3F) * 5 + 3;
       
   102             AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius));
       
   103             FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color)
   155             end
   104             end
   156             else
   105             else
   157             begin
   106             begin
   158             AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+')');
   107             AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius));
   159             DrawLineOnLand(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y);
   108             DrawThickLine(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y, radius, color);
       
   109             FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color)
   160             end;
   110             end;
   161 
   111 
   162         prevPoint:= pe^.point;
   112         prevPoint:= pe^.point;
   163         pe:= pe^.next;  
   113         pe:= pe^.next;  
   164         end;
   114         end;
   167 procedure initModule;
   117 procedure initModule;
   168 begin
   118 begin
   169     pointsListHead:= nil;
   119     pointsListHead:= nil;
   170     pointsListLast:= nil;
   120     pointsListLast:= nil;
   171 
   121 
   172     RegisterVariable('draw', vtCommand, @chDraw, false);
   122     RegisterVariable('draw', @chDraw, false);
   173 end;
   123 end;
   174 
   124 
   175 procedure freeModule;
   125 procedure freeModule;
   176 var pe, pp: PPointEntry;
   126 var pe, pp: PPointEntry;
   177 begin
   127 begin