hedgewars/uAIMisc.pas
changeset 15728 cc8882e46784
parent 15727 f9c2fd4bfb3e
child 15753 72f735c03fec
equal deleted inserted replaced
15727:f9c2fd4bfb3e 15728:cc8882e46784
    77 procedure AwareOfExplosion(x, y, r: LongInt); inline;
    77 procedure AwareOfExplosion(x, y, r: LongInt); inline;
    78 
    78 
    79 function  RatePlace(Gear: PGear): LongInt;
    79 function  RatePlace(Gear: PGear): LongInt;
    80 function  CheckWrap(x: real): real; inline;
    80 function  CheckWrap(x: real): real; inline;
    81 function  TestColl(x, y, r: LongInt): boolean; inline;
    81 function  TestColl(x, y, r: LongInt): boolean; inline;
       
    82 function  TestCollHogsOrObjects(x, y, r: LongInt): boolean; inline;
    82 function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
    83 function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
    83 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    84 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    84 
    85 
    85 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    86 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    86 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt; inline;
    87 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt; inline;
   379         (((y-r) and LAND_HEIGHT_MASK) = 0) and
   380         (((y-r) and LAND_HEIGHT_MASK) = 0) and
   380         (((y+r) and LAND_HEIGHT_MASK) = 0);
   381         (((y+r) and LAND_HEIGHT_MASK) = 0);
   381 end;
   382 end;
   382 
   383 
   383 
   384 
       
   385 // Check for collision with anything
   384 function TestCollWithEverything(x, y, r: LongInt): boolean; inline;
   386 function TestCollWithEverything(x, y, r: LongInt): boolean; inline;
   385 begin
   387 begin
   386     if not CheckBounds(x, y, r) then
   388     if not CheckBounds(x, y, r) then
   387         exit(false);
   389         exit(false);
   388 
   390 
   393        exit(true);
   395        exit(true);
   394 
   396 
   395     TestCollWithEverything := false;
   397     TestCollWithEverything := false;
   396 end;
   398 end;
   397 
   399 
       
   400 // Check for collision with non-objects
   398 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
   401 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
   399 begin
   402 begin
   400     if not CheckBounds(x, y, r) then
   403     if not CheckBounds(x, y, r) then
   401         exit(false);
   404         exit(false);
   402 
   405 
   407        exit(true);
   410        exit(true);
   408 
   411 
   409     TestCollExcludingObjects:= false;
   412     TestCollExcludingObjects:= false;
   410 end;
   413 end;
   411 
   414 
       
   415 // Check for collision with something other than current hedgehog or crate
   412 function TestColl(x, y, r: LongInt): boolean; inline;
   416 function TestColl(x, y, r: LongInt): boolean; inline;
   413 begin
   417 begin
   414     if not CheckBounds(x, y, r) then
   418     if not CheckBounds(x, y, r) then
   415         exit(false);
   419         exit(false);
   416 
   420 
   421        exit(true);
   425        exit(true);
   422 
   426 
   423     TestColl:= false;
   427     TestColl:= false;
   424 end;
   428 end;
   425 
   429 
   426 
   430 // Check for collision with hedgehog or object
       
   431 function TestCollHogsOrObjects(x, y, r: LongInt): boolean; inline;
       
   432 begin
       
   433     if not CheckBounds(x, y, r) then
       
   434         exit(false);
       
   435 
       
   436     if (Land[y-r, x-r] and lfAllObjMask <> 0) or
       
   437        (Land[y+r, x-r] and lfAllObjMask <> 0) or
       
   438        (Land[y-r, x+r] and lfAllObjMask <> 0) or
       
   439        (Land[y+r, x+r] and lfAllObjMask <> 0) then
       
   440        exit(true);
       
   441 
       
   442     TestCollHogsOrObjects:= false;
       
   443 end;
       
   444 
       
   445 // Check for collision with something other than the given "Me" gear.
   427 // Wrapper to test various approaches.  If it works reasonably, will just replace.
   446 // Wrapper to test various approaches.  If it works reasonably, will just replace.
   428 // Right now, converting to hwFloat is a tad inefficient since the x/y were hwFloat to begin with...
   447 // Right now, converting to hwFloat is a tad inefficient since the x/y were hwFloat to begin with...
   429 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
   448 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
   430 var MeX, MeY: LongInt;
   449 var MeX, MeY: LongInt;
   431 begin
   450 begin