hedgewars/uAIAmmoTests.pas
changeset 8887 539380a498e4
parent 8862 85eb1f4b4a5f
child 8895 95177c18e38c
equal deleted inserted replaced
8792:af4ab297b2b7 8887:539380a498e4
   195     EX, EY: LongInt;
   195     EX, EY: LongInt;
   196     valueResult: LongInt;
   196     valueResult: LongInt;
   197     x, y, dX, dY: real;
   197     x, y, dX, dY: real;
   198     t: LongInt;
   198     t: LongInt;
   199     value: LongInt;
   199     value: LongInt;
   200 begin
   200     t2: real;
       
   201     timer: Longint;
       
   202 begin
       
   203     if (Level > 3) then exit(BadTurn);
       
   204 
   201     mX:= hwFloat2Float(Me^.X);
   205     mX:= hwFloat2Float(Me^.X);
   202     mY:= hwFloat2Float(Me^.Y);
   206     mY:= hwFloat2Float(Me^.Y);
   203     ap.Time:= 0;
   207     ap.Time:= 0;
   204     rTime:= 350;
   208     rTime:= 350;
   205     ap.ExplR:= 0;
   209     ap.ExplR:= 0;
   222                 dX:= dX + windSpeed;
   226                 dX:= dX + windSpeed;
   223                 dY:= dY + cGravityf;
   227                 dY:= dY + cGravityf;
   224                 dec(t)
   228                 dec(t)
   225             until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or 
   229             until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or 
   226                    ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me, trunc(x), trunc(y), 5))) or (y > cWaterLine);
   230                    ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me, trunc(x), trunc(y), 5))) or (y > cWaterLine);
   227             
   231 
       
   232             if TestCollWithLand(trunc(x), trunc(y), 5) and (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) > 21) then
       
   233                 begin
       
   234                 timer := 500;
       
   235                 t2 := 0.5 / sqrt(sqr(dX) + sqr(dY));
       
   236                 dX := dX * t2;
       
   237                 dY := dY * t2;
       
   238                 repeat
       
   239                     x:= x + dX;
       
   240                     y:= y + dY;
       
   241                     dec(timer);
       
   242                 until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 22)
       
   243                     or (x < 0)
       
   244                     or (y < 0)
       
   245                     or (trunc(x) > LAND_WIDTH)
       
   246                     or (trunc(y) > LAND_HEIGHT)
       
   247                     or not TestCollWithLand(trunc(x), trunc(y), 5)
       
   248                     or (timer = 0)
       
   249                 end;
   228             EX:= trunc(x);
   250             EX:= trunc(x);
   229             EY:= trunc(y);
   251             EY:= trunc(y);
       
   252             // Try to prevent AI from thinking firing into water will cause a drowning
       
   253             if (EY < cWaterLine-5) and (Timer > 0) and (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) > 21) then exit(BadTurn);
   230             if Level = 1 then
   254             if Level = 1 then
   231                 value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   255                 value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   232             else value:= RateExplosion(Me, EX, EY, 101);
   256             else value:= RateExplosion(Me, EX, EY, 101);
   233             if value = 0 then
       
   234                 value:= 1024 - Metric(Targ.X, Targ.Y, EX, EY) div 64;
       
   235             if valueResult <= value then
   257             if valueResult <= value then
   236                 begin
   258                 begin
   237                 ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   259                 ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   238                 ap.Power:= trunc(sqrt(r) * cMaxPower) - random((Level - 1) * 17 + 1);
   260                 ap.Power:= trunc(sqrt(r) * cMaxPower) - random((Level - 1) * 17 + 1);
   239                 ap.ExplR:= 100;
   261                 ap.ExplR:= 100;
   240                 ap.ExplX:= EX;
   262                 ap.ExplX:= EX;
   241                 ap.ExplY:= EY;
   263                 ap.ExplY:= EY;
   242                 valueResult:= value
   264                 valueResult:= value-2500 // trying to make it slightly less attractive than a bazooka, to prevent waste.  AI could use awareness of weapon count
   243                 end;
   265                 end;
   244             end
   266             end
   245     until rTime > 4250;
   267     until rTime > 4250;
   246     TestDrillRocket:= valueResult
   268     TestDrillRocket:= valueResult
   247 end;
   269 end;