hedgewars/uAIMisc.pas
changeset 75 d2b737858ff7
parent 74 42257fee61ae
child 79 29b477319854
equal deleted inserted replaced
74:42257fee61ae 75:d2b737858ff7
    41                end;
    41                end;
    42      TTargets = record
    42      TTargets = record
    43                 Count: Longword;
    43                 Count: Longword;
    44                 ar: array[0..cMaxHHIndex*5] of TTarget;
    44                 ar: array[0..cMaxHHIndex*5] of TTarget;
    45                 end;
    45                 end;
       
    46      TGoInfo = record
       
    47                Ticks: Longword;
       
    48                FallTicks: Longword;
       
    49                end;
    46 
    50 
    47 procedure FillTargets;
    51 procedure FillTargets;
    48 procedure FillBonuses(isAfterAttack: boolean);
    52 procedure FillBonuses(isAfterAttack: boolean);
    49 procedure AwareOfExplosion(x, y, r: integer);
    53 procedure AwareOfExplosion(x, y, r: integer);
    50 function RatePlace(Gear: PGear): integer;
    54 function RatePlace(Gear: PGear): integer;
    51 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
    55 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
    52 function TestColl(x, y, r: integer): boolean;
    56 function TestColl(x, y, r: integer): boolean;
    53 function RateExplosion(Me: PGear; x, y, r: integer): integer;
    57 function RateExplosion(Me: PGear; x, y, r: integer): integer;
    54 function HHGo(Gear: PGear): boolean;
    58 function HHGo(Gear: PGear; out GoInfo: TGoInfo): boolean;
    55 
    59 
    56 var ThinkingHH: PGear;
    60 var ThinkingHH: PGear;
    57     Targets: TTargets;
    61     Targets: TTargets;
    58 
    62 
    59 implementation
    63 implementation
   210             end;
   214             end;
   211          end;
   215          end;
   212 Result:= Result * 1024
   216 Result:= Result * 1024
   213 end;
   217 end;
   214 
   218 
   215 function HHGo(Gear: PGear): boolean;
   219 function HHGo(Gear: PGear; out GoInfo: TGoInfo): boolean;
   216 var pX, pY: integer;
   220 var pX, pY: integer;
   217 begin
   221 begin
   218 Result:= false;
   222 Result:= false;
       
   223 GoInfo.Ticks:= 0;
       
   224 GoInfo.FallTicks:= 0;
   219 repeat
   225 repeat
   220 pX:= round(Gear.X);
   226 pX:= round(Gear.X);
   221 pY:= round(Gear.Y);
   227 pY:= round(Gear.Y);
   222 if pY + cHHRadius >= cWaterLine then exit;
   228 if pY + cHHRadius >= cWaterLine then exit;
   223 if (Gear.State and gstFalling) <> 0 then
   229 if (Gear.State and gstFalling) <> 0 then
   224    begin
   230    begin
       
   231    inc(GoInfo.Ticks);
   225    Gear.dY:= Gear.dY + cGravity;
   232    Gear.dY:= Gear.dY + cGravity;
   226    if Gear.dY > 0.40 then exit;
   233    if Gear.dY > 0.40 then
       
   234       begin
       
   235       Goinfo.FallTicks:= 0;
       
   236       exit
       
   237       end;
   227    Gear.Y:= Gear.Y + Gear.dY;
   238    Gear.Y:= Gear.Y + Gear.dY;
       
   239    if round(Gear.Y) > pY then inc(GoInfo.FallTicks);
   228    if TestCollisionYwithGear(Gear, 1) then
   240    if TestCollisionYwithGear(Gear, 1) then
   229       begin
   241       begin
       
   242       inc(GoInfo.Ticks, 300);
   230       Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
   243       Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
   231       Gear.dY:= 0
   244       Gear.dY:= 0;
       
   245       Result:= true;
       
   246       exit
   232       end;
   247       end;
   233    continue
   248    continue
   234    end;
   249    end;
   235    {if ((Gear.Message and gm_LJump )<>0) then
   250    {if ((Gear.Message and gm_LJump )<>0) then
   236       begin
   251       begin
   263          or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   278          or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   264       if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
   279       if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
   265          or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   280          or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   266       end;
   281       end;
   267 
   282 
   268    if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX;
   283    if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
       
   284       begin
       
   285       Gear.X:= Gear.X + Gear.dX;
       
   286       inc(GoInfo.Ticks, cHHStepTicks)
       
   287       end;
   269    if not TestCollisionYwithGear(Gear, 1) then
   288    if not TestCollisionYwithGear(Gear, 1) then
   270    begin
   289    begin
   271    Gear.Y:= Gear.Y + 1;
   290    Gear.Y:= Gear.Y + 1;
   272    if not TestCollisionYwithGear(Gear, 1) then
   291    if not TestCollisionYwithGear(Gear, 1) then
   273    begin
   292    begin
   295    end
   314    end
   296    end
   315    end
   297    end
   316    end
   298    end
   317    end
   299    end;
   318    end;
   300 if (pX <> round(Gear.X))and ((Gear.State and gstFalling) = 0) then
   319 if (pX <> round(Gear.X)) and ((Gear.State and gstFalling) = 0) then
   301    begin
   320    begin
   302    Result:= true;
   321    Result:= true;
   303    exit
   322    exit
   304    end;
   323    end
   305 until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0);
   324 until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0);
   306 end;
   325 end;
   307 
   326 
   308 end.
   327 end.