hedgewars/uAIAmmoTests.pas
changeset 4580 bd43d9ac6e04
parent 4578 f3cf226fad16
child 4881 35e6269227b6
equal deleted inserted replaced
4578:f3cf226fad16 4580:bd43d9ac6e04
    29             ExplX, ExplY, ExplR: LongInt;
    29             ExplX, ExplY, ExplR: LongInt;
    30             AttackPutX, AttackPutY: LongInt;
    30             AttackPutX, AttackPutY: LongInt;
    31             end;
    31             end;
    32 
    32 
    33 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    33 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
       
    34 function TestSnowball(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    34 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    35 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    35 function TestMolotov(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    36 function TestMolotov(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    36 function TestClusterBomb(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    37 function TestClusterBomb(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    37 function TestWatermelon(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    38 function TestWatermelon(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    38 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    39 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   101             (proc: nil;              flags: 0), // amFlamethrower
   102             (proc: nil;              flags: 0), // amFlamethrower
   102             (proc: @TestGrenade;     flags: 0), // amSMine
   103             (proc: @TestGrenade;     flags: 0), // amSMine
   103             (proc: @TestFirePunch;   flags: 0), // amHammer
   104             (proc: @TestFirePunch;   flags: 0), // amHammer
   104             (proc: nil;              flags: 0), // amResurrector
   105             (proc: nil;              flags: 0), // amResurrector
   105             (proc: nil;              flags: 0),// amDrillStrike
   106             (proc: nil;              flags: 0),// amDrillStrike
   106             (proc: nil;              flags: 0) // amSnowball
   107             (proc: @TestSnowball;    flags: 0) // amSnowball
   107             );
   108             );
   108 
   109 
   109 const BadTurn = Low(LongInt) div 4;
   110 const BadTurn = Low(LongInt) div 4;
   110 
   111 
   111 implementation
   112 implementation
   169         valueResult:= Score
   170         valueResult:= Score
   170         end;
   171         end;
   171      end
   172      end
   172 until (rTime > 4250);
   173 until (rTime > 4250);
   173 TestBazooka:= valueResult
   174 TestBazooka:= valueResult
       
   175 end;
       
   176 
       
   177 function TestSnowball(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
       
   178 var Vx, Vy, r: hwFloat;
       
   179     rTime: LongInt;
       
   180     Score, EX, EY: LongInt;
       
   181     valueResult: LongInt;
       
   182 
       
   183     function CheckTrace: LongInt;
       
   184     var x, y, dX, dY: hwFloat;
       
   185         t: LongInt;
       
   186         value: LongInt;
       
   187     begin
       
   188     x:= Me^.X;
       
   189     y:= Me^.Y;
       
   190     dX:= Vx;
       
   191     dY:= -Vy;
       
   192     t:= rTime;
       
   193     repeat
       
   194       x:= x + dX;
       
   195       y:= y + dY;
       
   196       dX:= dX + cWindSpeed;
       
   197       dY:= dY + cGravity;
       
   198       dec(t)
       
   199     until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t <= 0);
       
   200     EX:= hwRound(x);
       
   201     EY:= hwRound(y);
       
   202     value:= RateExplosion(Me, EX, EY, 5);
       
   203     if value = 0 then value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
       
   204     CheckTrace:= value;
       
   205     end;
       
   206 
       
   207 begin
       
   208 ap.Time:= 0;
       
   209 rTime:= 350;
       
   210 ap.ExplR:= 0;
       
   211 valueResult:= BadTurn;
       
   212 repeat
       
   213   rTime:= rTime + 300 + Level * 50 + random(300);
       
   214   Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X + AIrndSign(2)) - Me^.X) / int2hwFloat(rTime);
       
   215   Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime);
       
   216   r:= Distance(Vx, Vy);
       
   217   if not (r > _1) then
       
   218      begin
       
   219      Score:= CheckTrace;
       
   220      if valueResult <= Score then
       
   221         begin
       
   222         ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
       
   223         ap.Power:= hwRound(r * cMaxPower) - random((Level - 1) * 17 + 1);
       
   224         ap.ExplR:= 100;
       
   225         ap.ExplX:= EX;
       
   226         ap.ExplY:= EY;
       
   227         valueResult:= Score
       
   228         end;
       
   229      end
       
   230 until (rTime > 4250);
       
   231 TestSnowball:= valueResult
   174 end;
   232 end;
   175 
   233 
   176 function TestMolotov(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   234 function TestMolotov(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   177 var Vx, Vy, r: hwFloat;
   235 var Vx, Vy, r: hwFloat;
   178     Score, EX, EY, valueResult: LongInt;
   236     Score, EX, EY, valueResult: LongInt;