hedgewars/uAILandMarks.pas
author Medo <smaxein@googlemail.com>
Fri, 27 Jul 2012 01:38:24 +0200
changeset 7444 2e31f114f57e
parent 7433 c7fff3e61d49
child 7483 d479b98d38f7
permissions -rw-r--r--
Hedgeroid: various improvements: - Improved main menu dialogs - Fixed hardware enter button not sending chat messages on Transformer - Fixed /me messages showing the /me as part of the message

unit uAILandMarks;

interface
const markWasHere = $01;

procedure addMark(X, Y: LongInt; mark: byte);
function  checkMark(X, Y: LongInt; mark: byte) : boolean;
procedure clearAllMarks;
procedure clearMarks(mark: byte);

procedure initModule;
procedure freeModule;

implementation
uses uVariables;

const gr = 2;

var marks: array of array of byte;
    WIDTH, HEIGHT: Longword;

procedure addMark(X, Y: LongInt; mark: byte);
begin
    if((X and LAND_WIDTH_MASK) = 0) and ((Y and LAND_HEIGHT_MASK) = 0) then
        begin
        X:= X shr gr;
        Y:= Y shr gr;
        marks[Y, X]:= marks[Y, X] or mark
        end
end;

function  checkMark(X, Y: LongInt; mark: byte) : boolean;
begin
    checkMark:= ((X and LAND_WIDTH_MASK) = 0) 
        and ((Y and LAND_HEIGHT_MASK) = 0) 
        and ((marks[Y shr gr, X shr gr] and mark) <> 0)
end;

procedure clearAllMarks;
var 
    Y, X: Longword;
begin
    for Y:= 0 to Pred(HEIGHT) do
        for X:= 0 to Pred(WIDTH) do
            marks[Y, X]:= 0
end;

procedure clearMarks(mark: byte);
var 
    Y, X: Longword;
begin
    for Y:= 0 to Pred(HEIGHT) do
        for X:= 0 to Pred(WIDTH) do
            marks[Y, X]:= marks[Y, X] and (not mark)
end;


procedure initModule;
begin
    WIDTH:= LAND_WIDTH shr gr;
    HEIGHT:= LAND_HEIGHT shr gr;
    
    SetLength(marks, HEIGHT, WIDTH);
end;

procedure freeModule;
begin
    SetLength(marks, 0, 0);
end;

end.