hedgewars/uAIMisc.pas
changeset 10015 4feced261c68
parent 9998 736015b847e3
parent 9950 2759212a27de
child 10108 c68cf030eded
equal deleted inserted replaced
10014:56d2f2d5aad8 10015:4feced261c68
    51     end;
    51     end;
    52 TBonus = record
    52 TBonus = record
    53     X, Y: LongInt;
    53     X, Y: LongInt;
    54     Radius: LongInt;
    54     Radius: LongInt;
    55     Score: LongInt;
    55     Score: LongInt;
    56     end;
    56      end;
       
    57 
       
    58 Tbonuses = record
       
    59           Count : Longword;
       
    60           ar    : array[0..Pred(MAXBONUS)] of TBonus;
       
    61        end;
       
    62 
       
    63 Twalkbonuses =  record
       
    64         Count: Longword;
       
    65         ar: array[0..Pred(MAXBONUS div 8)] of TBonus;  // don't use too many
       
    66         end;
    57 
    67 
    58 procedure initModule;
    68 procedure initModule;
    59 procedure freeModule;
    69 procedure freeModule;
    60 
    70 
    61 procedure FillTargets;
    71 procedure FillTargets;
    80 function  AIrndSign(num: LongInt): LongInt;
    90 function  AIrndSign(num: LongInt): LongInt;
    81 
    91 
    82 var ThinkingHH: PGear;
    92 var ThinkingHH: PGear;
    83     Targets: TTargets;
    93     Targets: TTargets;
    84 
    94 
    85     bonuses: record
    95     bonuses: Tbonuses;
    86         Count: Longword;
    96 
    87         ar: array[0..Pred(MAXBONUS)] of TBonus;
    97     walkbonuses: Twalkbonuses;
    88         end;
       
    89 
       
    90     walkbonuses: record
       
    91         Count: Longword;
       
    92         ar: array[0..Pred(MAXBONUS div 8)] of TBonus;  // don't use too many
       
    93         end;
       
    94 
    98 
    95 const KillScore = 200;
    99 const KillScore = 200;
    96 var friendlyfactor: LongInt = 300;
   100 var friendlyfactor: LongInt = 300;
    97 var dmgMod: real = 1.0;
   101 var dmgMod: real = 1.0;
    98 
   102 
    99 implementation
   103 implementation
   100 uses uCollisions, uVariables, uUtils, uLandTexture, uGearsUtils;
   104 uses uCollisions, uVariables, uUtils, uGearsUtils;
   101 
   105 
   102 var
   106 var
   103     KnownExplosion: record
   107     KnownExplosion: record
   104         X, Y, Radius: LongInt
   108         X, Y, Radius: LongInt
   105         end = (X: 0; Y: 0; Radius: 0);
   109         end = (X: 0; Y: 0; Radius: 0);
   125 while Gear <> nil do
   129 while Gear <> nil do
   126     begin
   130     begin
   127     if  (((Gear^.Kind = gtHedgehog) and
   131     if  (((Gear^.Kind = gtHedgehog) and
   128             (Gear <> ThinkingHH) and
   132             (Gear <> ThinkingHH) and
   129             (Gear^.Health > Gear^.Damage) and
   133             (Gear^.Health > Gear^.Damage) and
   130             not(Gear^.Hedgehog^.Team^.hasgone)) or
   134             (not Gear^.Hedgehog^.Team^.hasgone)) or
   131         ((Gear^.Kind = gtExplosives) and
   135         ((Gear^.Kind = gtExplosives) and
   132             (Gear^.Health > Gear^.Damage)) or
   136             (Gear^.Health > Gear^.Damage)) or
   133         ((Gear^.Kind = gtMine) and
   137         ((Gear^.Kind = gtMine) and
   134             (Gear^.Health = 0) and
   138             (Gear^.Health = 0) and
   135              (Gear^.Damage < 35))
   139              (Gear^.Damage < 35))
   136              )  and 
   140              )  and
   137         (Targets.Count < 256) then
   141         (Targets.Count < 256) then
   138         begin
   142         begin
   139         with Targets.ar[Targets.Count] do
   143         with Targets.ar[Targets.Count] do
   140             begin
   144             begin
   141             skip:= false;
   145             skip:= false;
   153                 if (Gear^.Hedgehog^.Team^.Clan = CurrentTeam^.Clan) then
   157                 if (Gear^.Hedgehog^.Team^.Clan = CurrentTeam^.Clan) then
   154                     begin
   158                     begin
   155                     Score:= Gear^.Damage - Gear^.Health;
   159                     Score:= Gear^.Damage - Gear^.Health;
   156                     inc(f)
   160                     inc(f)
   157                     end
   161                     end
   158                 else 
   162                 else
   159                     begin
   163                     begin
   160                     Score:= Gear^.Health - Gear^.Damage;
   164                     Score:= Gear^.Health - Gear^.Damage;
   161                     inc(e)
   165                     inc(e)
   162                     end;
   166                     end;
   163                 end
   167                 end
   164             else if Gear^.Kind = gtExplosives then
   168             else if Gear^.Kind = gtExplosives then
   165                 Score:= Gear^.Health - Gear^.Damage
   169                 Score:= Gear^.Health - Gear^.Damage
   166             else if Gear^.Kind = gtMine then 
   170             else if Gear^.Kind = gtMine then
   167                 Score:= max(0,35-Gear^.Damage);
   171                 Score:= max(0,35-Gear^.Damage);
   168             end;
   172             end;
   169         inc(Targets.Count)
   173         inc(Targets.Count)
   170         end;
   174         end;
   171     Gear:= Gear^.NextGear
   175     Gear:= Gear^.NextGear
   382                 if (Kind = gtHedgehog) and (0.4 < dY) then
   386                 if (Kind = gtHedgehog) and (0.4 < dY) then
   383                     begin
   387                     begin
   384                     dmg := 1 + trunc((dY - 0.4) * 70);
   388                     dmg := 1 + trunc((dY - 0.4) * 70);
   385                     exit(dmg)
   389                     exit(dmg)
   386                     end
   390                     end
   387                 else 
   391                 else
   388                     begin
   392                     begin
   389                     dxdy:= abs(dX)+abs(dY);
   393                     dxdy:= abs(dX)+abs(dY);
   390                     if ((Kind = gtMine) and (dxdy > 0.35)) or 
   394                     if ((Kind = gtMine) and (dxdy > 0.35)) or
   391                        ((Kind = gtExplosives) and 
   395                        ((Kind = gtExplosives) and
   392                             (((State and gstTmpFlag <> 0) and (dxdy > 0.35)) or
   396                             (((State and gstTmpFlag <> 0) and (dxdy > 0.35)) or
   393                              ((State and gstTmpFlag = 0) and 
   397                              ((State and gstTmpFlag = 0) and
   394                                 ((abs(odX) > 0.15) or ((abs(odY) > 0.15) and 
   398                                 ((abs(odX) > 0.15) or ((abs(odY) > 0.15) and
   395                                 (abs(odX) > 0.02))) and (dxdy > 0.35)))) then
   399                                 (abs(odX) > 0.02))) and (dxdy > 0.35)))) then
   396                         begin
   400                         begin
   397                         dmg := trunc(dxdy * 25);
   401                         dmg := trunc(dxdy * 25);
   398                         exit(dmg)
   402                         exit(dmg)
   399                         end
   403                         end
   400                     else if (Kind = gtExplosives) and not((abs(odX) > 0.15) or ((abs(odY) > 0.15) and (abs(odX) > 0.02))) and (dY > 0.2) then
   404                     else if (Kind = gtExplosives) and (not(abs(odX) > 0.15) or ((abs(odY) > 0.15) and (abs(odX) > 0.02))) and (dY > 0.2) then
   401                         begin
   405                         begin
   402                         dmg := trunc(dy * 70);
   406                         dmg := trunc(dy * 70);
   403                         exit(dmg)
   407                         exit(dmg)
   404                         end
   408                         end
   405                     end;
   409                     end;
   434                 if (Kind = gtHedgehog) and (0.4 < dY) then
   438                 if (Kind = gtHedgehog) and (0.4 < dY) then
   435                     begin
   439                     begin
   436                     dmg := trunc((dY - 0.4) * 70);
   440                     dmg := trunc((dY - 0.4) * 70);
   437                     exit(dmg);
   441                     exit(dmg);
   438                     end
   442                     end
   439                 else 
   443                 else
   440                     begin
   444                     begin
   441                     dxdy:= abs(dX)+abs(dY);
   445                     dxdy:= abs(dX)+abs(dY);
   442                     if ((Kind = gtMine) and (dxdy > 0.4)) or 
   446                     if ((Kind = gtMine) and (dxdy > 0.4)) or
   443                        ((Kind = gtExplosives) and 
   447                        ((Kind = gtExplosives) and
   444                             (((State and gstTmpFlag <> 0) and (dxdy > 0.4)) or
   448                             (((State and gstTmpFlag <> 0) and (dxdy > 0.4)) or
   445                              ((State and gstTmpFlag = 0) and 
   449                              ((State and gstTmpFlag = 0) and
   446                                 ((abs(odX) > 0.15) or ((abs(odY) > 0.15) and 
   450                                 ((abs(odX) > 0.15) or ((abs(odY) > 0.15) and
   447                                 (abs(odX) > 0.02))) and (dxdy > 0.35)))) then
   451                                 (abs(odX) > 0.02))) and (dxdy > 0.35)))) then
   448                         begin
   452                         begin
   449                         dmg := trunc(dxdy * 50);
   453                         dmg := trunc(dxdy * 50);
   450                         exit(dmg)
   454                         exit(dmg)
   451                         end
   455                         end
   452                     else if (Kind = gtExplosives) and not((abs(odX) > 0.15) or ((abs(odY) > 0.15) and (abs(odX) > 0.02))) and (dY > 0.2) then
   456                     else if (Kind = gtExplosives) and (not(abs(odX) > 0.15) or ((abs(odY) > 0.15) and (abs(odX) > 0.02))) and (dY > 0.2) then
   453                         begin
   457                         begin
   454                         dmg := trunc(dy * 70);
   458                         dmg := trunc(dy * 70);
   455                         exit(dmg)
   459                         exit(dmg)
   456                         end
   460                         end
   457                     end;
   461                     end;
   518                 fallDmg:= 0;
   522                 fallDmg:= 0;
   519                 if (Flags and afTrackFall <> 0) and (Score > 0) and (dmg < Score) then
   523                 if (Flags and afTrackFall <> 0) and (Score > 0) and (dmg < Score) then
   520                     begin
   524                     begin
   521                     dX:= (0.005 * dmg + 0.01) / Density;
   525                     dX:= (0.005 * dmg + 0.01) / Density;
   522                     dY:= dX;
   526                     dY:= dX;
   523                     if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and 
   527                     if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and
   524                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
   528                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
   525                         ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then
   529                         ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then
   526                         dX:= 0;
   530                         dX:= 0;
   527 
   531 
   528                     if pX - x < 0 then dX:= -dX;
   532                     if pX - x < 0 then dX:= -dX;
   604                 begin
   608                 begin
   605                 pX:= Point.x;
   609                 pX:= Point.x;
   606                 pY:= Point.y-2;
   610                 pY:= Point.y-2;
   607                 fallDmg:= 0;
   611                 fallDmg:= 0;
   608                 if (Flags and afSetSkip <> 0) then skip:= true;
   612                 if (Flags and afSetSkip <> 0) then skip:= true;
   609                 if not(dead) and (Flags and afTrackFall <> 0) and (Score > 0) and (power < Score) then
   613                 if (not dead) and (Flags and afTrackFall <> 0) and (Score > 0) and (power < Score) then
   610                     if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and 
   614                     if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and
   611                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
   615                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
   612                         ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then
   616                         ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then
   613                         fallDmg:= trunc(TraceShoveFall(pX, pY, 0, dY, Targets.ar[i]) * dmgMod)
   617                         fallDmg:= trunc(TraceShoveFall(pX, pY, 0, dY, Targets.ar[i]) * dmgMod)
   614                     else
   618                     else
   615                         fallDmg:= trunc(TraceShoveFall(pX, pY, dX, dY, Targets.ar[i]) * dmgMod);
   619                         fallDmg:= trunc(TraceShoveFall(pX, pY, dX, dY, Targets.ar[i]) * dmgMod);
   699                 dmg:= min(baseDmg - trunc(sqrt(sqr(Point.x - x)+sqr(Point.y - y))), 25);
   703                 dmg:= min(baseDmg - trunc(sqrt(sqr(Point.x - x)+sqr(Point.y - y))), 25);
   700                 dmg:= trunc(dmg * dmgMod);
   704                 dmg:= trunc(dmg * dmgMod);
   701                 end;
   705                 end;
   702             if dmg > 0 then
   706             if dmg > 0 then
   703                 begin
   707                 begin
   704                 if not(dead) and (Score > 0) and (dmg < Score) then
   708                 if (not dead) and (Score > 0) and (dmg < Score) then
   705                     begin
   709                     begin
   706                     pX:= Point.x;
   710                     pX:= Point.x;
   707                     pY:= Point.y;
   711                     pY:= Point.y;
   708                     dX:= gdX * dmg / Density;
   712                     dX:= gdX * dmg / Density;
   709                     dY:= gdY * dmg / Density;
   713                     dY:= gdY * dmg / Density;
   710                     if dX < 0 then dX:= dX - 0.01
   714                     if dX < 0 then dX:= dX - 0.01
   711                     else dX:= dX + 0.01;
   715                     else dX:= dX + 0.01;
   712                     if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and 
   716                     if (Kind = gtExplosives) and (State and gstTmpFlag = 0) and
   713                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
   717                        (((abs(dY) > 0.15) and (abs(dX) < 0.02)) or
   714                         ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then 
   718                         ((abs(dY) < 0.15) and (abs(dX) < 0.15))) then
   715                        dX:= 0;
   719                        dX:= 0;
   716                     if (x and LAND_WIDTH_MASK = 0) and ((y+cHHRadius+2) and LAND_HEIGHT_MASK = 0) and
   720                     if (x and LAND_WIDTH_MASK = 0) and ((y+cHHRadius+2) and LAND_HEIGHT_MASK = 0) and
   717                        (Land[y+cHHRadius+2, x] and lfIndestructible <> 0) then
   721                        (Land[y+cHHRadius+2, x] and lfIndestructible <> 0) then
   718                          fallDmg:= trunc(TraceFall(x, y, pX, pY, dX, dY, 0, Targets.ar[i]) * dmgMod)
   722                          fallDmg:= trunc(TraceFall(x, y, pX, pY, dX, dY, 0, Targets.ar[i]) * dmgMod)
   719                     else fallDmg:= trunc(TraceFall(x, y, pX, pY, dX, dY, erasure, Targets.ar[i]) * dmgMod)
   723                     else fallDmg:= trunc(TraceFall(x, y, pX, pY, dX, dY, erasure, Targets.ar[i]) * dmgMod)