hedgewars/uAIMisc.pas
changeset 8958 3818b38d72c0
parent 8957 bdeb52d57dae
child 8960 bc8295dc8970
equal deleted inserted replaced
8957:bdeb52d57dae 8958:3818b38d72c0
   308 function TestCollWithEverything(x, y, r: LongInt): boolean; inline;
   308 function TestCollWithEverything(x, y, r: LongInt): boolean; inline;
   309 begin
   309 begin
   310     if not CheckBounds(x, y, r) then
   310     if not CheckBounds(x, y, r) then
   311         exit(false);
   311         exit(false);
   312 
   312 
   313     if (Land[y-r, x] <> 0) or
   313     if (Land[y-r, x-r] <> 0) or
   314        (Land[y+r, x] <> 0) or
   314        (Land[y+r, x-r] <> 0) or
   315        (Land[y, x+r] <> 0) or
   315        (Land[y-r, x+r] <> 0) or
   316        (Land[y, x-r] <> 0) then
   316        (Land[y+r, x+r] <> 0) then
   317        exit(true);
   317        exit(true);
   318 
   318 
   319     TestCollWithEverything := false;
   319     TestCollWithEverything := false;
   320 end;
   320 end;
   321 
   321 
   322 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
   322 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
   323 begin
   323 begin
   324     if not CheckBounds(x, y, r) then
   324     if not CheckBounds(x, y, r) then
   325         exit(false);
   325         exit(false);
   326 
   326 
   327     if (Land[y-r, x] > lfAllObjMask) or
   327     if (Land[y-r, x-r] > lfAllObjMask) or
   328        (Land[y+r, x] > lfAllObjMask) or
   328        (Land[y+r, x-r] > lfAllObjMask) or
   329        (Land[y, x-r] > lfAllObjMask) or
   329        (Land[y-r, x-r] > lfAllObjMask) or
   330        (Land[y, x+r] > lfAllObjMask) then
   330        (Land[y+r, x+r] > lfAllObjMask) then
   331        exit(true);
   331        exit(true);
   332 
   332 
   333     TestCollExcludingObjects:= false;
   333     TestCollExcludingObjects:= false;
   334 end;
   334 end;
   335 
   335 
   336 function TestColl(x, y, r: LongInt): boolean; inline;
   336 function TestColl(x, y, r: LongInt): boolean; inline;
   337 begin
   337 begin
   338     if not CheckBounds(x, y, r) then
   338     if not CheckBounds(x, y, r) then
   339         exit(false);
   339         exit(false);
   340 
   340 
   341     if (Land[y-r, x] and lfNotCurrentMask <> 0) or
   341     if (Land[y-r, x-r] and lfNotCurrentMask <> 0) or
   342        (Land[y+r, x] and lfNotCurrentMask <> 0) or
   342        (Land[y+r, x-r] and lfNotCurrentMask <> 0) or
   343        (Land[y, x-r] and lfNotCurrentMask <> 0) or
   343        (Land[y+r, x-r] and lfNotCurrentMask <> 0) or
   344        (Land[y, x+r] and lfNotCurrentMask <> 0) then
   344        (Land[y+r, x+r] and lfNotCurrentMask <> 0) then
   345        exit(true);
   345        exit(true);
   346 
   346 
   347     TestColl:= false;
   347     TestColl:= false;
   348 end;
   348 end;
   349 
   349 
   366 
   366 
   367 
   367 
   368 
   368 
   369 function TraceFall(eX, eY: LongInt; var x, y: Real; dX, dY: Real; r: LongWord; Kind: TGearType): LongInt;
   369 function TraceFall(eX, eY: LongInt; var x, y: Real; dX, dY: Real; r: LongWord; Kind: TGearType): LongInt;
   370 var skipLandCheck: boolean;
   370 var skipLandCheck: boolean;
   371     rCorner: real;
   371     rCorner, dxdy: real;
   372     dmg, radius: LongInt;
   372     dmg, radius: LongInt;
   373 begin
   373 begin
   374     skipLandCheck:= true;
   374     skipLandCheck:= true;
   375     if x - eX < 0 then dX:= -dX;
   375     if x - eX < 0 then dX:= -dX;
   376     if y - eY < 0 then dY:= -dY;
   376     if y - eY < 0 then dY:= -dY;
   393             if (Kind = gtHedgehog) and (0.4 < dY) then
   393             if (Kind = gtHedgehog) and (0.4 < dY) then
   394                 begin
   394                 begin
   395                 dmg := 1 + trunc((abs(dY) - 0.4) * 70);
   395                 dmg := 1 + trunc((abs(dY) - 0.4) * 70);
   396                 if dmg >= 1 then exit(dmg)
   396                 if dmg >= 1 then exit(dmg)
   397                 end
   397                 end
   398 // 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.
       
   399             else 
   398             else 
   400                 begin
   399                 begin
   401                 if ((dY > 0.2) and (Land[trunc(y)+radius, trunc(x)] > lfAllObjMask)) or 
   400                 dxdy:= abs(dX)+abs(dY);
   402                    ((dY < -0.2) and (Land[trunc(y)-radius, trunc(x)] > lfAllObjMask)) then
       
   403                     begin
       
   404                     dmg := 1 + trunc(abs(dY) * 70);
       
   405                     if dmg >= 1 then exit(dmg)
       
   406                     end
       
   407 // so we don't know at present if a barrel is already rolling.  Would need to add that to target info I guess
   401 // so we don't know at present if a barrel is already rolling.  Would need to add that to target info I guess
   408                 else if ((Kind = gtMine) or (abs(dX) > 0.15) or ((abs(dY) > 0.15) and  (abs(dX) > 0.02))) and
   402 // a barrel oriented vertically only considers dY. however, AI doesn't know to use hammer, and could only bat vertically w/ bat, so probably shouldn't matter
   409                         (((dX > 0.2) and (Land[trunc(y), trunc(x)+radius] > lfAllObjMask)) or 
   403                 if (dxdy > 0.3) then
   410                          ((dX < -0.2) and (Land[trunc(y), trunc(x)-radius] > lfAllObjMask))) then
   404                     begin
   411                     begin
   405                     dmg := 1 + trunc(dxdy * 25);
   412                     dmg := 1 + trunc(abs(dX) * 70);
   406                     exit(dmg)
   413                     if dmg >= 1 then exit(dmg)
       
   414                     end
   407                     end
   415                 end;
   408                 end;
   416             exit(0)
   409             exit(0)
   417             end;
   410             end;
   418         if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(-1)
   411         if (y > cWaterLine) or (x > leftX) or (x < rightX) then exit(-1)
   419         end
   412         end
   420 end;
   413 end;
   421 
   414 
   422 function TraceShoveFall(var x, y: Real; dX, dY: Real; Kind: TGearType): LongInt;
   415 function TraceShoveFall(var x, y: Real; dX, dY: Real; Kind: TGearType): LongInt;
   423 var dmg, radius: LongInt;
   416 var dmg, radius: LongInt;
       
   417     dxdy: real;
   424 begin
   418 begin
   425 //v:= random($FFFFFFFF);
   419 //v:= random($FFFFFFFF);
   426     if Kind = gtHedgehog then 
   420     if Kind = gtHedgehog then 
   427         radius:= cHHRadius
   421         radius:= cHHRadius
   428     else if Kind = gtExplosives then
   422     else if Kind = gtExplosives then
   449                 begin
   443                 begin
   450                 dmg := 1 + trunc((abs(dY) - 0.4) * 70);
   444                 dmg := 1 + trunc((abs(dY) - 0.4) * 70);
   451                 if dmg >= 1 then
   445                 if dmg >= 1 then
   452                     exit(dmg);
   446                     exit(dmg);
   453                 end
   447                 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 
   448             else 
   456                 begin
   449                 begin
   457                 if ((dY > 0.2) and (Land[trunc(y)+radius, trunc(x)] > lfAllObjMask)) or 
   450                 dxdy:= abs(dX)+abs(dY);
   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
   451 // 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
   452 // a barrel oriented vertically only considers dY. however, AI doesn't know to use hammer, and could only bat vertically w/ bat, so probably shouldn't matter
   465                         (((dX > 0.2) and (Land[trunc(y), trunc(x)+radius] > lfAllObjMask)) or 
   453                 if (dxdy > 0.3) then
   466                          ((dX < -0.2) and (Land[trunc(y), trunc(x)-radius] > lfAllObjMask))) then
   454                     begin
   467                     begin
   455                     dmg := 1 + trunc(dxdy * 25);
   468                     dmg := 1 + trunc(abs(dX) * 70);
   456                     exit(dmg)
   469                     if dmg >= 1 then exit(dmg)
       
   470                     end
   457                     end
   471                 end;
   458                 end;
   472             exit(0)
   459             exit(0)
   473         end;
   460         end;
   474         if (y > cWaterLine) or (x > 4096) or (x < 0) then
   461         if (y > cWaterLine) or (x > leftX) or (x < rightX) then
   475             // returning -1 for drowning so it can be considered in the Rate routine
   462             // returning -1 for drowning so it can be considered in the Rate routine
   476             exit(-1)
   463             exit(-1)
   477     end;
   464     end;
   478 end;
   465 end;
   479 
   466