hedgewars/uLandPainted.pas
author sheepluva
Thu, 23 Jan 2014 13:56:53 +0100
changeset 10061 b7161f00a6ca
parent 10015 4feced261c68
child 10108 c68cf030eded
permissions -rw-r--r--
hide complete IP of other users, when non-admin requests player info. showing the first two parts of the IP was kinda pointless to begin with (what for?) and has recently lead to increased abuse and lobby flooding due to bots collecting/posting IP tracking information
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
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9472
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
4457
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;
5066
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
    27
procedure freeModule;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    28
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    29
implementation
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998
diff changeset
    30
uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uScript;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    31
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    32
type PointRec = packed record
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4457
diff changeset
    33
    X, Y: SmallInt;
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    34
    flags: byte;
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    35
    end;
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
    36
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    37
type
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    38
    PPointEntry = ^PointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    39
    PointEntry = record
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    40
        point: PointRec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    41
        next: PPointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    42
        end;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    43
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    44
var pointsListHead, pointsListLast: PPointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    45
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
    46
procedure chDraw(var s: shortstring);
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    47
var rec: PointRec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    48
    prec: ^PointRec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    49
    pe: PPointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    50
    i, l: byte;
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
    51
begin
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    52
    i:= 1;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    53
    l:= length(s);
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    54
    while i < l do
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    55
        begin
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    56
        prec:= @s[i];
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    57
        rec:= prec^;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    58
        rec.X:= SDLNet_Read16(@rec.X);
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    59
        rec.Y:= SDLNet_Read16(@rec.Y);
7287
nemo
parents: 7277
diff changeset
    60
        if rec.X < -318 then rec.X:= -318;
7583
8a9edc7cf98f drawn maps have a fixed 4096x2048 area right now
nemo
parents: 7287
diff changeset
    61
        if rec.X > 4096+318 then rec.X:= 4096+318;
7287
nemo
parents: 7277
diff changeset
    62
        if rec.Y < -318 then rec.Y:= -318;
7583
8a9edc7cf98f drawn maps have a fixed 4096x2048 area right now
nemo
parents: 7287
diff changeset
    63
        if rec.Y > 2048+318 then rec.Y:= 2048+318;
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    64
7043
7c080e5ac8d0 Some work to make more units compile after conversion to c
unc0rr
parents: 6898
diff changeset
    65
        new(pe);
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    66
        if pointsListLast = nil then
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    67
            pointsListHead:= pe
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    68
        else
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    69
            pointsListLast^.next:= pe;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    70
        pointsListLast:= pe;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    71
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    72
        pe^.point:= rec;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    73
        pe^.next:= nil;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    74
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    75
        inc(i, 5)
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    76
        end;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    77
end;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    78
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    79
procedure Draw;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    80
var pe: PPointEntry;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    81
    prevPoint: PointRec;
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
    82
    radius: LongInt;
6873
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
    83
    color: Longword;
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    84
begin
4648
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
    85
    // shutup compiler
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
    86
    prevPoint.X:= 0;
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
    87
    prevPoint.Y:= 0;
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
    88
    radius:= 0;
4648
d8e1b43482d2 - Remove loading from file procedure
unc0rr
parents: 4494
diff changeset
    89
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    90
    pe:= pointsListHead;
9472
265e5997580e Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents: 9080
diff changeset
    91
    while (pe <> nil) and (pe^.point.flags and $80 = 0) do
265e5997580e Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents: 9080
diff changeset
    92
        begin
265e5997580e Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents: 9080
diff changeset
    93
        ScriptCall('onSpecialPoint', pe^.point.X, pe^.point.Y, pe^.point.flags);
265e5997580e Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents: 9080
diff changeset
    94
        pe:= pe^.next;
265e5997580e Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents: 9080
diff changeset
    95
        end;
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    96
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    97
    while(pe <> nil) do
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    98
        begin
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
    99
        if (pe^.point.flags and $80 <> 0) then
4649
82bf0a0fa8b0 Add logging of map drawing process
unc0rr
parents: 4648
diff changeset
   100
            begin
6873
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
   101
            if (pe^.point.flags and $40 <> 0) then
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
   102
                color:= 0
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
   103
                else
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
   104
                color:= lfBasic;
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
   105
            radius:= (pe^.point.flags and $3F) * 5 + 3;
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
   106
            AddFileLog('[DRAW] Move to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius));
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
   107
            FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color)
4649
82bf0a0fa8b0 Add logging of map drawing process
unc0rr
parents: 4648
diff changeset
   108
            end
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   109
            else
4649
82bf0a0fa8b0 Add logging of map drawing process
unc0rr
parents: 4648
diff changeset
   110
            begin
6873
30840365af0a Eraser tool
unc0rr
parents: 6781
diff changeset
   111
            AddFileLog('[DRAW] Line to: ('+inttostr(pe^.point.X)+','+inttostr(pe^.point.Y)+'), radius = '+inttostr(radius));
7147
11b7b12e2b85 Render drawn maps 10-500 times faster
unc0rr
parents: 7043
diff changeset
   112
            DrawThickLine(prevPoint.X, prevPoint.Y, pe^.point.X, pe^.point.Y, radius, color);
11b7b12e2b85 Render drawn maps 10-500 times faster
unc0rr
parents: 7043
diff changeset
   113
            FillRoundInLand(pe^.point.X, pe^.point.Y, radius, color)
4649
82bf0a0fa8b0 Add logging of map drawing process
unc0rr
parents: 4648
diff changeset
   114
            end;
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   115
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   116
        prevPoint:= pe^.point;
9472
265e5997580e Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents: 9080
diff changeset
   117
        pe:= pe^.next;
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   118
        end;
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   119
end;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   120
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   121
procedure initModule;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   122
begin
4494
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   123
    pointsListHead:= nil;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   124
    pointsListLast:= nil;
9585435e20f7 Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents: 4490
diff changeset
   125
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6873
diff changeset
   126
    RegisterVariable('draw', @chDraw, false);
4490
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   127
end;
f6840f7e2f60 Stub to recieve /draw command
unc0rr
parents: 4458
diff changeset
   128
5066
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   129
procedure freeModule;
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   130
var pe, pp: PPointEntry;
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   131
begin
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   132
    pe:= pointsListHead;
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   133
    while(pe <> nil) do
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   134
        begin
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   135
        pp:= pe;
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   136
        pe:= pe^.next;
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   137
        dispose(pp);
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   138
        end;
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   139
end;
d2684b6f02ce fix leaking of hand-drawn maps
sheepluva
parents: 4976
diff changeset
   140
4457
ffb766e85150 - Change painted map file format
unc0rr
parents:
diff changeset
   141
end.