hedgewars/uAIMisc.pas
changeset 8957 bdeb52d57dae
parent 8956 e0e914642e73
child 8958 3818b38d72c0
equal deleted inserted replaced
8956:e0e914642e73 8957:bdeb52d57dae
    65 
    65 
    66 function  RatePlace(Gear: PGear): LongInt;
    66 function  RatePlace(Gear: PGear): LongInt;
    67 function  TestColl(x, y, r: LongInt): boolean; inline;
    67 function  TestColl(x, y, r: LongInt): boolean; inline;
    68 function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
    68 function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
    69 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    69 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    70 function  TraceShoveFall(x, y, dX, dY: Real; Kind: TGearType): LongInt;
       
    71 
    70 
    72 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    71 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    73 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt; inline;
    72 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt; inline;
    74 function  RealRateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
    73 function  RealRateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
    75 function  RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
    74 function  RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
   309 function TestCollWithEverything(x, y, r: LongInt): boolean; inline;
   308 function TestCollWithEverything(x, y, r: LongInt): boolean; inline;
   310 begin
   309 begin
   311     if not CheckBounds(x, y, r) then
   310     if not CheckBounds(x, y, r) then
   312         exit(false);
   311         exit(false);
   313 
   312 
   314     if (Land[y-r, x-r] <> 0) or
   313     if (Land[y-r, x] <> 0) or
   315        (Land[y+r, x-r] <> 0) or
   314        (Land[y+r, x] <> 0) or
   316        (Land[y-r, x+r] <> 0) or
   315        (Land[y, x+r] <> 0) or
   317        (Land[y+r, x+r] <> 0) then
   316        (Land[y, x-r] <> 0) then
   318        exit(true);
   317        exit(true);
   319 
   318 
   320     TestCollWithEverything := false;
   319     TestCollWithEverything := false;
   321 end;
   320 end;
   322 
   321 
   323 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
   322 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
   324 begin
   323 begin
   325     if not CheckBounds(x, y, r) then
   324     if not CheckBounds(x, y, r) then
   326         exit(false);
   325         exit(false);
   327 
   326 
   328     if (Land[y-r, x-r] > lfAllObjMask) or
   327     if (Land[y-r, x] > lfAllObjMask) or
   329        (Land[y+r, x-r] > lfAllObjMask) or
   328        (Land[y+r, x] > lfAllObjMask) or
   330        (Land[y-r, x+r] > lfAllObjMask) or
   329        (Land[y, x-r] > lfAllObjMask) or
   331        (Land[y+r, x+r] > lfAllObjMask) then
   330        (Land[y, x+r] > lfAllObjMask) then
   332        exit(true);
   331        exit(true);
   333 
   332 
   334     TestCollExcludingObjects:= false;
   333     TestCollExcludingObjects:= false;
   335 end;
   334 end;
   336 
   335 
   337 function TestColl(x, y, r: LongInt): boolean; inline;
   336 function TestColl(x, y, r: LongInt): boolean; inline;
   338 begin
   337 begin
   339     if not CheckBounds(x, y, r) then
   338     if not CheckBounds(x, y, r) then
   340         exit(false);
   339         exit(false);
   341 
   340 
   342     if (Land[y-r, x-r] and lfNotCurrentMask <> 0) or
   341     if (Land[y-r, x] and lfNotCurrentMask <> 0) or
   343        (Land[y+r, x-r] and lfNotCurrentMask <> 0) or
   342        (Land[y+r, x] and lfNotCurrentMask <> 0) or
   344        (Land[y-r, x+r] and lfNotCurrentMask <> 0) or
   343        (Land[y, x-r] and lfNotCurrentMask <> 0) or
   345        (Land[y+r, x+r] and lfNotCurrentMask <> 0) then
   344        (Land[y, x+r] and lfNotCurrentMask <> 0) then
   346        exit(true);
   345        exit(true);
   347 
   346 
   348     TestColl:= false;
   347     TestColl:= false;
   349 end;
   348 end;
   350 
   349 
   418             end;
   417             end;
   419         if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(-1)
   418         if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(-1)
   420         end
   419         end
   421 end;
   420 end;
   422 
   421 
   423 function TraceShoveFall(x, y, dX, dY: Real; Kind: TGearType): LongInt;
   422 function TraceShoveFall(var x, y: Real; dX, dY: Real; Kind: TGearType): LongInt;
   424 var dmg: LongInt;
   423 var dmg, radius: LongInt;
   425 begin
   424 begin
   426 //v:= random($FFFFFFFF);
   425 //v:= random($FFFFFFFF);
       
   426     if Kind = gtHedgehog then 
       
   427         radius:= cHHRadius
       
   428     else if Kind = gtExplosives then
       
   429         radius:= 16
       
   430     else if Kind = gtMine then
       
   431         radius:= 2;
   427     while true do
   432     while true do
   428     begin
   433         begin
   429         x:= x + dX;
   434         x:= x + dX;
   430         y:= y + dY;
   435         y:= y + dY;
   431         dY:= dY + cGravityf;
   436         dY:= dY + cGravityf;
   432 
   437 
   433 {        if ((trunc(y) and LAND_HEIGHT_MASK) = 0) and ((trunc(x) and LAND_WIDTH_MASK) = 0) then
   438 {        if ((trunc(y) and LAND_HEIGHT_MASK) = 0) and ((trunc(x) and LAND_WIDTH_MASK) = 0) then
   437             end;}
   442             end;}
   438 
   443 
   439 
   444 
   440         // consider adding dX/dY calc here for fall damage
   445         // consider adding dX/dY calc here for fall damage
   441         if TestCollExcludingObjects(trunc(x), trunc(y), cHHRadius) then
   446         if TestCollExcludingObjects(trunc(x), trunc(y), cHHRadius) then
   442         begin
   447             begin
   443             if 0.4 < dY then
   448             if (Kind = gtHedgehog) and (0.4 < dY) then
   444             begin
   449                 begin
   445                 dmg := 1 + trunc((abs(dY) - 0.4) * 70);
   450                 dmg := 1 + trunc((abs(dY) - 0.4) * 70);
   446                 if dmg >= 1 then
   451                 if dmg >= 1 then
   447                     exit(dmg);
   452                     exit(dmg);
   448             end;
   453                 end
       
   454 // so. the problem w/ explosives is it only uses dX or dY depending on impact, and we don't know which we hit.  Maybe we didn't even hit, given TestColl check corners.
       
   455             else 
       
   456                 begin
       
   457                 if ((dY > 0.2) and (Land[trunc(y)+radius, trunc(x)] > lfAllObjMask)) or 
       
   458                    ((dY < -0.2) and (Land[trunc(y)-radius, trunc(x)] > lfAllObjMask)) then
       
   459                     begin
       
   460                     dmg := 1 + trunc(abs(dY) * 70);
       
   461                     if dmg >= 1 then exit(dmg)
       
   462                     end
       
   463 // so we don't know at present if a barrel is already rolling.  Would need to add that to target info I guess
       
   464                 else if ((Kind = gtMine) or (abs(dX) > 0.15) or ((abs(dY) > 0.15) and  (abs(dX) > 0.02))) and
       
   465                         (((dX > 0.2) and (Land[trunc(y), trunc(x)+radius] > lfAllObjMask)) or 
       
   466                          ((dX < -0.2) and (Land[trunc(y), trunc(x)-radius] > lfAllObjMask))) then
       
   467                     begin
       
   468                     dmg := 1 + trunc(abs(dX) * 70);
       
   469                     if dmg >= 1 then exit(dmg)
       
   470                     end
       
   471                 end;
   449             exit(0)
   472             exit(0)
   450         end;
   473         end;
   451         if (y > cWaterLine) or (x > 4096) or (x < 0) then
   474         if (y > cWaterLine) or (x > 4096) or (x < 0) then
   452             // returning -1 for drowning so it can be considered in the Rate routine
   475             // returning -1 for drowning so it can be considered in the Rate routine
   453             exit(-1)
   476             exit(-1)
   583             dmg:= r - trunc(sqrt(sqr(Point.x - x)+sqr(Point.y - y)));
   606             dmg:= r - trunc(sqrt(sqr(Point.x - x)+sqr(Point.y - y)));
   584 
   607 
   585         if dmg > 0 then
   608         if dmg > 0 then
   586             begin
   609             begin
   587             pX:= Point.x;
   610             pX:= Point.x;
   588             pY:= Point.y;
   611             pY:= Point.y-2;
   589             if (Flags and afSetSkip <> 0) then skip:= true;
   612             if (Flags and afSetSkip <> 0) then skip:= true;
   590             if (Flags and afTrackFall <> 0) and (Score > 0) then
   613             if (Flags and afTrackFall <> 0) and (Score > 0) then
   591                 fallDmg:= trunc(TraceShoveFall(pX, pY - 2, dX, dY, Kind) * dmgMod);
   614                 fallDmg:= trunc(TraceShoveFall(pX, pY, dX, dY, Kind) * dmgMod);
   592             if Kind = gtHedgehog then
   615             if Kind = gtHedgehog then
   593                 begin
   616                 begin
   594                 if fallDmg < 0 then // drowning. score healthier hogs higher, since their death is more likely to benefit the AI
   617                 if fallDmg < 0 then // drowning. score healthier hogs higher, since their death is more likely to benefit the AI
   595                     begin
   618                     begin
   596                     if Score > 0 then
   619                     if Score > 0 then