hedgewars/uAILandMarks.pas
author nemo
Wed, 22 Aug 2012 22:10:47 -0400
changeset 7581 ea509b70e03d
parent 7483 d479b98d38f7
child 7787 67c96b9c179c
permissions -rw-r--r--
move this section back to the connection code, and add an exclusion for air attack. probably should play a few portal games just in case
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
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     4
const markWasHere = $01;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     5
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     6
procedure addMark(X, Y: LongInt; mark: byte);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     7
function  checkMark(X, Y: LongInt; mark: byte) : boolean;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     8
procedure clearAllMarks;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
     9
procedure clearMarks(mark: byte);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    10
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    11
procedure initModule;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    12
procedure freeModule;
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
implementation
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    15
uses uVariables;
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
const gr = 2;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    18
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    19
var marks: array of array of byte;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    20
    WIDTH, HEIGHT: Longword;
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
procedure addMark(X, Y: LongInt; mark: byte);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    23
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    24
    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
    25
        begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    26
        X:= X shr gr;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    27
        Y:= Y shr gr;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    28
        marks[Y, X]:= marks[Y, X] or mark
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    29
        end
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    30
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    31
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    32
function  checkMark(X, Y: LongInt; mark: byte) : boolean;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    33
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    34
    checkMark:= ((X and LAND_WIDTH_MASK) = 0) 
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    35
        and ((Y and LAND_HEIGHT_MASK) = 0) 
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    36
        and ((marks[Y shr gr, X shr gr] and mark) <> 0)
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    37
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    38
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    39
procedure clearAllMarks;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    40
var 
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    41
    Y, X: Longword;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    42
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    43
    for Y:= 0 to Pred(HEIGHT) do
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    44
        for X:= 0 to Pred(WIDTH) do
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    45
            marks[Y, X]:= 0
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    46
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    47
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    48
procedure clearMarks(mark: byte);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    49
var 
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    50
    Y, X: Longword;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    51
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    52
    for Y:= 0 to Pred(HEIGHT) do
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    53
        for X:= 0 to Pred(WIDTH) do
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    54
            marks[Y, X]:= marks[Y, X] and (not mark)
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    55
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    56
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    57
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    58
procedure initModule;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    59
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    60
    WIDTH:= LAND_WIDTH shr gr;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    61
    HEIGHT:= LAND_HEIGHT shr gr;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    62
    
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    63
    SetLength(marks, HEIGHT, WIDTH);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    64
end;
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
procedure freeModule;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    67
begin
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    68
    SetLength(marks, 0, 0);
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    69
end;
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    70
d479b98d38f7 unbreak AI. remove inits from uLand
nemo
parents: 7433
diff changeset
    71
end.