hedgewars/uAILandMarks.pas
author sheepluva
Fri, 26 Oct 2012 20:37:18 +0200
changeset 7830 72e52da6ea7f
parent 7787 67c96b9c179c
child 7850 fcbb024090a4
permissions -rw-r--r--
fix for issue #441 ("Cannot overwrite default weapon set 'Default'!" message when no change to weapon set was made)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7483
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     1
unit uAILandMarks;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     2
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     3
interface
7787
67c96b9c179c Mark places where tried to jump, avoid too much of thinking
unc0rr
parents: 7483
diff changeset
     4
const 
67c96b9c179c Mark places where tried to jump, avoid too much of thinking
unc0rr
parents: 7483
diff changeset
     5
    markWalkedHere = $01;
67c96b9c179c Mark places where tried to jump, avoid too much of thinking
unc0rr
parents: 7483
diff changeset
     6
    markHJumped    = $02;
67c96b9c179c Mark places where tried to jump, avoid too much of thinking
unc0rr
parents: 7483
diff changeset
     7
    markLJumped    = $04;
7483
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     8
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     9
procedure addMark(X, Y: LongInt; mark: byte);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    10
function  checkMark(X, Y: LongInt; mark: byte) : boolean;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    11
procedure clearAllMarks;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    12
procedure clearMarks(mark: byte);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    13
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    14
procedure initModule;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    15
procedure freeModule;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    16
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    17
implementation
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    18
uses uVariables;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    19
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    20
const gr = 2;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    21
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    22
var marks: array of array of byte;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    23
    WIDTH, HEIGHT: Longword;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    24
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    25
procedure addMark(X, Y: LongInt; mark: byte);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    26
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    27
    if((X and LAND_WIDTH_MASK) = 0) and ((Y and LAND_HEIGHT_MASK) = 0) then
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    28
        begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    29
        X:= X shr gr;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    30
        Y:= Y shr gr;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    31
        marks[Y, X]:= marks[Y, X] or mark
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    32
        end
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    33
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    34
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    35
function  checkMark(X, Y: LongInt; mark: byte) : boolean;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    36
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    37
    checkMark:= ((X and LAND_WIDTH_MASK) = 0) 
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    38
        and ((Y and LAND_HEIGHT_MASK) = 0) 
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    39
        and ((marks[Y shr gr, X shr gr] and mark) <> 0)
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    40
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    41
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    42
procedure clearAllMarks;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    43
var 
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    44
    Y, X: Longword;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    45
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    46
    for Y:= 0 to Pred(HEIGHT) do
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    47
        for X:= 0 to Pred(WIDTH) do
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    48
            marks[Y, X]:= 0
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    49
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    50
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    51
procedure clearMarks(mark: byte);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    52
var 
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    53
    Y, X: Longword;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    54
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    55
    for Y:= 0 to Pred(HEIGHT) do
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    56
        for X:= 0 to Pred(WIDTH) do
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    57
            marks[Y, X]:= marks[Y, X] and (not mark)
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    58
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    59
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    60
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    61
procedure initModule;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    62
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    63
    WIDTH:= LAND_WIDTH shr gr;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    64
    HEIGHT:= LAND_HEIGHT shr gr;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    65
    
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    66
    SetLength(marks, HEIGHT, WIDTH);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    67
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    68
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    69
procedure freeModule;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    70
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    71
    SetLength(marks, 0, 0);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    72
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    73
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    74
end.