hedgewars/uAIMisc.pas
branchwebgl
changeset 8833 c13ebed437cb
parent 8026 4a4f21070479
parent 8810 b885b995aa95
child 9127 e350500c4edb
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
    72 function  RatePlace(Gear: PGear): LongInt;
    72 function  RatePlace(Gear: PGear): LongInt;
    73 function  TestColl(x, y, r: LongInt): boolean; inline;
    73 function  TestColl(x, y, r: LongInt): boolean; inline;
    74 function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
    74 function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
    75 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    75 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    76 function  TraceShoveFall(x, y, dX, dY: Real): LongInt;
    76 function  TraceShoveFall(x, y, dX, dY: Real): LongInt;
       
    77 function TestCollWithLand(x, y, r: LongInt): boolean; inline;
    77 
    78 
    78 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    79 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    79 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
    80 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
    80 function  RateShove(x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
    81 function  RateShove(x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
    81 function  RateShotgun(Me: PGear; gdX, gdY: real; x, y: LongInt): LongInt;
    82 function  RateShotgun(Me: PGear; gdX, gdY: real; x, y: LongInt): LongInt;
   267     if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then
   268     if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then
   268     begin
   269     begin
   269         MeX:= hwRound(Me^.X);
   270         MeX:= hwRound(Me^.X);
   270         MeY:= hwRound(Me^.Y);
   271         MeY:= hwRound(Me^.Y);
   271         // We are still inside the hog. Skip radius test
   272         // We are still inside the hog. Skip radius test
   272         if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and ((Land[y, x] and $FF00) = 0) then
   273         if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and (Land[y, x] <= lfAllObjMask) and ((Land[y, x] and lfObjMask) < 2) then
   273             exit(false);
   274             exit(false);
   274     end;
   275     end;
   275     TestCollExcludingMe:= TestColl(x, y, r)
   276     TestCollExcludingMe:= TestColl(x, y, r)
   276 end;
   277 end;
   277 
   278 
   278 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
   279 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
   279 var b: boolean;
   280 var b: boolean;
   280 begin
   281 begin
   281     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] and $FF00 <> 0);
   282     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] > lfAllObjMask);
   282     if b then
   283     if b then
   283         exit(true);
   284         exit(true);
   284     
   285     
   285     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] and $FF00 <> 0);
   286     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] > lfAllObjMask);
   286     if b then
   287     if b then
   287         exit(true);
   288         exit(true);
   288     
   289     
   289     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] and $FF00 <> 0);
   290     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] > lfAllObjMask);
   290     if b then
   291     if b then
   291         exit(true);
   292         exit(true);
   292     
   293     
   293     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] and $FF00 <> 0);
   294     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] > lfAllObjMask);
   294     if b then
   295     if b then
   295         exit(true);
   296         exit(true);
   296     
   297     
   297     TestCollExcludingObjects:= false;
   298     TestCollExcludingObjects:= false;
   298 end;
   299 end;
   299 
   300 
   300 function TestColl(x, y, r: LongInt): boolean; inline;
   301 function TestColl(x, y, r: LongInt): boolean; inline;
   301 var b: boolean;
   302 var b: boolean;
   302 begin
   303 begin
   303     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] and $FF7F <> 0);
   304     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] and lfNotCurrentMask <> 0);
   304     if b then
   305     if b then
   305         exit(true);
   306         exit(true);
   306     
   307     
   307     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] and $FF7F <> 0);
   308     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] and lfNotCurrentMask <> 0);
   308     if b then
   309     if b then
   309         exit(true);
   310         exit(true);
   310     
   311     
   311     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] and $FF7F <> 0);
   312     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] and lfNotCurrentMask <> 0);
   312     if b then
   313     if b then
   313         exit(true);
   314         exit(true);
   314     
   315     
   315     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] and $FF7F <> 0);
   316     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] and lfNotCurrentMask <> 0);
   316     if b then
   317     if b then
   317         exit(true);
   318         exit(true);
   318     
   319     
   319     TestColl:= false;
   320     TestColl:= false;
   320 end;
   321 end;
   321 
   322 
   322 function TestCollWithLand(x, y, r: LongInt): boolean; inline;
   323 function TestCollWithLand(x, y, r: LongInt): boolean; inline;
   323 var b: boolean;
   324 var b: boolean;
   324 begin
   325 begin
   325     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] > 255);
   326     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] > lfAllObjMask);
   326     if b then
   327     if b then
   327         exit(true);
   328         exit(true);
   328         
   329         
   329     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] > 255);
   330     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] > lfAllObjMask);
   330     if b then
   331     if b then
   331         exit(true);
   332         exit(true);
   332         
   333         
   333     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] > 255);
   334     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] > lfAllObjMask);
   334     if b then
   335     if b then
   335         exit(true);
   336         exit(true);
   336         
   337         
   337     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] > 255);
   338     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] > lfAllObjMask);
   338     if b then
   339     if b then
   339         exit(true);
   340         exit(true);
   340 
   341 
   341     TestCollWithLand:= false;
   342     TestCollWithLand:= false;
   342 end;
   343 end;
   714 
   715 
   715 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
   716 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
   716 var pX, pY, tY: LongInt;
   717 var pX, pY, tY: LongInt;
   717 begin
   718 begin
   718 HHGo:= false;
   719 HHGo:= false;
   719 Gear^.CollisionMask:= $FF7F;
   720 Gear^.CollisionMask:= lfNotCurrentMask;
   720 AltGear^:= Gear^;
   721 AltGear^:= Gear^;
   721 
   722 
   722 GoInfo.Ticks:= 0;
   723 GoInfo.Ticks:= 0;
   723 GoInfo.FallPix:= 0;
   724 GoInfo.FallPix:= 0;
   724 GoInfo.JumpType:= jmpNone;
   725 GoInfo.JumpType:= jmpNone;