hedgewars/uAIAmmoTests.pas
branchwebgl
changeset 8833 c13ebed437cb
parent 8444 75db7bb8dce8
parent 8824 fe9eacd390f2
child 8839 caa57115d7ea
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
   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;
   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);
   230             if Level = 1 then
   252             if Level = 1 then
   231                 value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   253                 value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
   232             else value:= RateExplosion(Me, EX, EY, 101);
   254             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
   255             if valueResult <= value then
   236                 begin
   256                 begin
   237                 ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   257                 ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   238                 ap.Power:= trunc(sqrt(r) * cMaxPower) - random((Level - 1) * 17 + 1);
   258                 ap.Power:= trunc(sqrt(r) * cMaxPower) - random((Level - 1) * 17 + 1);
   239                 ap.ExplR:= 100;
   259                 ap.ExplR:= 100;
   240                 ap.ExplX:= EX;
   260                 ap.ExplX:= EX;
   241                 ap.ExplY:= EY;
   261                 ap.ExplY:= EY;
   242                 valueResult:= value
   262                 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;
   263                 end;
   244             end
   264             end
   245     until rTime > 4250;
   265     until rTime > 4250;
   246     TestDrillRocket:= valueResult
   266     TestDrillRocket:= valueResult
   247 end;
   267 end;
  1169     ap.Time:= 0;
  1189     ap.Time:= 0;
  1170     ap.Power:= BadTurn; // use it as max score value in checkCakeWalk
  1190     ap.Power:= BadTurn; // use it as max score value in checkCakeWalk
  1171 
  1191 
  1172     //FillChar(cake, sizeof(cake), 0);
  1192     //FillChar(cake, sizeof(cake), 0);
  1173     cake.Radius:= 7;
  1193     cake.Radius:= 7;
  1174     cake.CollisionMask:= $FF7F;
  1194     cake.CollisionMask:= lfNotCurrentMask;
  1175     cake.Hedgehog:= Me^.Hedgehog;
  1195     cake.Hedgehog:= Me^.Hedgehog;
  1176 
  1196 
  1177     // check left direction
  1197     // check left direction
  1178     cake.Angle:= 3;
  1198     cake.Angle:= 3;
  1179     cake.dX.isNegative:= true;
  1199     cake.dX.isNegative:= true;