hedgewars/uAI2.pas
author unC0Rr
Thu, 19 Dec 2024 14:18:55 +0100
branchtransitional_engine
changeset 16081 6633961698ad
parent 16078 db18f1a30b0c
permissions -rw-r--r--
Make wider range of numbers representable with FPNum on the cost of smaller precision
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
16078
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    13
type TAmmoCounts = array[TAmmoType] of Longword;
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    14
     PAmmoCounts = ^TAmmoCounts;
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    15
16068
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    16
function create_ai(game_field: pointer): pointer; cdecl; external;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    17
procedure ai_clear_team(ai: pointer); cdecl; external;
16078
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    18
procedure ai_add_team_hedgehog(ai: pointer; x, y: real; ammo_counts: PAmmoCounts); cdecl; external;
16068
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    19
procedure ai_think(ai: pointer); cdecl; external;
16069
6c5b3c576fc6 Add some progress on rust AI
unC0Rr
parents: 16068
diff changeset
    20
function ai_have_plan(): boolean; cdecl; external;
16068
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    21
procedure dispose_ai(ai: pointer); cdecl; external;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    22
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    23
var ai: pointer;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    24
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    25
procedure ProcessBot;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    26
var currHedgehogIndex, itHedgehog: Longword;
16078
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    27
    itAmmo: TAmmoType;
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    28
    ammoCounts: TAmmoCounts;
16068
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    29
begin
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    30
    if ai = nil then
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    31
    begin
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    32
        ai:= create_ai(gameField)
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    33
    end;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    34
    
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    35
    ai_clear_team(ai);
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    36
    
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    37
    currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    38
    itHedgehog:= currHedgehogIndex;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    39
    repeat
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    40
        with CurrentTeam^.Hedgehogs[itHedgehog] do
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    41
            if (Gear <> nil) and (Effects[heFrozen] = 0) then
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    42
            begin
16078
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    43
                for itAmmo:= Low(TAmmoType) to High(TAmmoType) do
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    44
                    ammoCounts[itAmmo]:= HHHasAmmo(CurrentTeam^.Hedgehogs[itHedgehog], itAmmo);
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    45
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    46
                ai_add_team_hedgehog(ai, hwFloat2float(Gear^.X), hwFloat2float(Gear^.Y), ammoCounts)
16068
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
        itHedgehog:= Succ(itHedgehog) mod CurrentTeam^.HedgehogsNumber;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    49
    until (itHedgehog = currHedgehogIndex);
16078
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    50
    
db18f1a30b0c Implement passing of available ammo to rust AI
unC0Rr
parents: 16069
diff changeset
    51
    ai_think(ai);
16068
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    52
end;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    53
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    54
procedure initModule;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    55
begin
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    56
    ai:= nil
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    57
end;
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    58
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    59
end.
a236360669cc Start on AI implementation in rust
unC0Rr
parents:
diff changeset
    60