hedgewars/uAI2.pas
author unC0Rr
Fri, 22 Nov 2024 17:30:45 +0100
branchtransitional_engine
changeset 16071 14b83df1832b
parent 16069 6c5b3c576fc6
permissions -rw-r--r--
Merge tip
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16068
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     1
unit uAI2;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     2
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     3
interface
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     4
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     5
procedure ProcessBot;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     6
procedure initModule;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     7
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     8
implementation
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
     9
uses uLandUtils, uFloat, uVariables, uTypes;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    10
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    11
{$linklib hwengine_future}
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    12
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    13
function create_ai(game_field: pointer): pointer; cdecl; external;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    14
procedure ai_clear_team(ai: pointer); cdecl; external;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    15
procedure ai_add_team_hedgehog(ai: pointer; x, y: real); cdecl; external;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    16
procedure ai_think(ai: pointer); cdecl; external;
16069
6c5b3c576fc6 Add some progress on rust AI
unC0Rr
parents: 16068
diff changeset
    17
function ai_have_plan(): boolean; cdecl; external;
16068
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    18
procedure dispose_ai(ai: pointer); cdecl; external;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    19
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    20
var ai: pointer;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    21
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    22
procedure ProcessBot;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    23
var currHedgehogIndex, itHedgehog: Longword;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    24
begin
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    25
    if ai = nil then
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    26
    begin
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    27
        ai:= create_ai(gameField)
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    28
    end;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    29
    
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    30
    ai_clear_team(ai);
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    31
    
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    32
    currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    33
    itHedgehog:= currHedgehogIndex;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    34
    repeat
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    35
        with CurrentTeam^.Hedgehogs[itHedgehog] do
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    36
            if (Gear <> nil) and (Effects[heFrozen] = 0) then
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    37
            begin
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    38
                ai_add_team_hedgehog(ai, hwFloat2float(Gear^.X), hwFloat2float(Gear^.Y))
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    39
            end;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    40
        itHedgehog:= Succ(itHedgehog) mod CurrentTeam^.HedgehogsNumber;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    41
    until (itHedgehog = currHedgehogIndex);
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    42
end;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    43
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    44
procedure initModule;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    45
begin
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    46
    ai:= nil
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    47
end;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    48
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    49
end.
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    50