hedgewars/uLandPainted.pas
branchsdl2transition
changeset 11362 ed5a6478e710
parent 11046 47a8c19ecb60
child 14416 96624a6cdb93
equal deleted inserted replaced
11361:31570b766315 11362:ed5a6478e710
     1 (*
     1 (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2015 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  *
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    12  * GNU General Public License for more details.
    13  *
    13  *
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    17  *)
    17  *)
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uLandPainted;
    21 unit uLandPainted;
    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, uVariables, uUtils, SDLh, uCommands, uDebug, uScript;
    30 uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uScript, uIO;
    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;
       
    36     PPointRec = ^PointRec;
    36 
    37 
    37 type
    38 type
    38     PPointEntry = ^PointEntry;
    39     PPointEntry = ^PointEntry;
    39     PointEntry = record
    40     PointEntry = record
    40         point: PointRec;
    41         point: PointRec;
    43 
    44 
    44 var pointsListHead, pointsListLast: PPointEntry;
    45 var pointsListHead, pointsListLast: PPointEntry;
    45 
    46 
    46 procedure chDraw(var s: shortstring);
    47 procedure chDraw(var s: shortstring);
    47 var rec: PointRec;
    48 var rec: PointRec;
    48     prec: ^PointRec;
    49     prec: PPointRec;
    49     pe: PPointEntry;
    50     pe: PPointEntry;
    50     i, l: byte;
    51     i, l: byte;
    51 begin
    52 begin
    52     i:= 1;
    53     i:= 1;
    53     l:= length(s);
    54     l:= length(s);
    54     while i < l do
    55     while i < l do
    55         begin
    56         begin
    56         prec:= @s[i];
    57         prec:= PPointRec(@s[i]);
    57         rec:= prec^;
    58         rec:= prec^;
    58         rec.X:= SDLNet_Read16(@rec.X);
    59         rec.X:= SDLNet_Read16(@rec.X);
    59         rec.Y:= SDLNet_Read16(@rec.Y);
    60         rec.Y:= SDLNet_Read16(@rec.Y);
    60         if rec.X < -318 then rec.X:= -318;
    61         if rec.X < -318 then rec.X:= -318;
    61         if rec.X > 4096+318 then rec.X:= 4096+318;
    62         if rec.X > 4096+318 then rec.X:= 4096+318;
    79 procedure Draw;
    80 procedure Draw;
    80 var pe: PPointEntry;
    81 var pe: PPointEntry;
    81     prevPoint: PointRec;
    82     prevPoint: PointRec;
    82     radius: LongInt;
    83     radius: LongInt;
    83     color: Longword;
    84     color: Longword;
       
    85     lineNumber, linePoints: Longword;
    84 begin
    86 begin
    85     // shutup compiler
    87     // shutup compiler
    86     prevPoint.X:= 0;
    88     prevPoint.X:= 0;
    87     prevPoint.Y:= 0;
    89     prevPoint.Y:= 0;
    88     radius:= 0;
    90     radius:= 0;
       
    91     linePoints:= 0;
    89 
    92 
    90     pe:= pointsListHead;
    93     pe:= pointsListHead;
    91     while (pe <> nil) and (pe^.point.flags and $80 = 0) do
    94     while (pe <> nil) and (pe^.point.flags and $80 = 0) do
    92         begin
    95         begin
    93         ScriptCall('onSpecialPoint', pe^.point.X, pe^.point.Y, pe^.point.flags);
    96         ScriptCall('onSpecialPoint', pe^.point.X, pe^.point.Y, pe^.point.flags);
    94         pe:= pe^.next;
    97         pe:= pe^.next;
    95         end;
    98         end;
    96 
    99 
       
   100     lineNumber:= 0;
       
   101 
    97     while(pe <> nil) do
   102     while(pe <> nil) do
    98         begin
   103         begin
    99         if (pe^.point.flags and $80 <> 0) then
   104         if (pe^.point.flags and $80 <> 0) then
   100             begin
   105             begin
       
   106             if (lineNumber > 0) and (linePoints = 0) and cAdvancedMapGenMode then
       
   107                     SendIPC('|' + inttostr(lineNumber - 1));
       
   108 
       
   109             inc(lineNumber);
       
   110 
   101             if (pe^.point.flags and $40 <> 0) then
   111             if (pe^.point.flags and $40 <> 0) then
   102                 color:= 0
   112                 color:= 0
   103                 else
   113                 else
   104                 color:= lfBasic;
   114                 color:= lfBasic;
   105             radius:= (pe^.point.flags and $3F) * 5 + 3;
   115             radius:= (pe^.point.flags and $3F) * 5 + 3;
   106             AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius));
   116             linePoints:= FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color);
   107             FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color)
       
   108             end
   117             end
   109             else
   118             else
   110             begin
   119             begin
   111             AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius));
   120             inc(linePoints, DrawThickLine(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y, radius, color));
   112             DrawThickLine(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y, radius, color);
       
   113             FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color)
       
   114             end;
   121             end;
   115 
   122 
   116         prevPoint:= pe^.point;
   123         prevPoint:= pe^.point;
   117         pe:= pe^.next;
   124         pe:= pe^.next;
   118         end;
   125         end;