hedgewars/uAIMisc.pas
changeset 5425 862c194a1a1c
parent 5422 0daf3d8e4b70
child 5604 d81727c49617
equal deleted inserted replaced
5422:0daf3d8e4b70 5425:862c194a1a1c
   368 until false
   368 until false
   369 end;
   369 end;
   370 
   370 
   371 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
   371 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
   372 var pX, pY: LongInt;
   372 var pX, pY: LongInt;
   373     bRes: boolean;
   373 begin
   374 begin
       
   375 bRes:= false;
       
   376 AltGear^:= Gear^;
   374 AltGear^:= Gear^;
   377 
   375 
   378 GoInfo.Ticks:= 0;
   376 GoInfo.Ticks:= 0;
   379 GoInfo.FallPix:= 0;
   377 GoInfo.FallPix:= 0;
   380 GoInfo.JumpType:= jmpNone;
   378 GoInfo.JumpType:= jmpNone;
   388    Gear^.dY:= Gear^.dY + cGravity;
   386    Gear^.dY:= Gear^.dY + cGravity;
   389    if Gear^.dY > _0_4 then
   387    if Gear^.dY > _0_4 then
   390       begin
   388       begin
   391       Goinfo.FallPix:= 0;
   389       Goinfo.FallPix:= 0;
   392       HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage
   390       HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage
   393       exit(bRes)
   391       exit(false)
   394       end;
   392       end;
   395    Gear^.Y:= Gear^.Y + Gear^.dY;
   393    Gear^.Y:= Gear^.Y + Gear^.dY;
   396    if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix);
   394    if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix);
   397    if TestCollisionYwithGear(Gear, 1) then
   395    if TestCollisionYwithGear(Gear, 1) then
   398       begin
   396       begin
   399       inc(GoInfo.Ticks, 410);
   397       inc(GoInfo.Ticks, 410);
   400       Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
   398       Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
   401       Gear^.dY:= _0;
   399       Gear^.dY:= _0;
   402       bRes:= true;
       
   403       HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall
   400       HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall
   404       exit(bRes)
   401       exit(true)
   405       end;
   402       end;
   406    continue
   403    continue
   407    end;
   404    end;
   408    if (Gear^.Message and gmLeft  )<>0 then Gear^.dX:= -cLittle else
   405    if (Gear^.Message and gmLeft  )<>0 then Gear^.dX:= -cLittle else
   409    if (Gear^.Message and gmRight )<>0 then Gear^.dX:=  cLittle else exit(bRes);
   406    if (Gear^.Message and gmRight )<>0 then Gear^.dX:=  cLittle else exit(false);
   410    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   407    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   411       begin
   408       begin
   412       if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
   409       if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
   413          or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1;
   410          or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1;
   414       if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
   411       if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
   460    end;
   457    end;
   461 if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then
   458 if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then
   462    exit(true);
   459    exit(true);
   463 until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0);
   460 until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0);
   464 HHJump(AltGear, jmpHJump, GoInfo);
   461 HHJump(AltGear, jmpHJump, GoInfo);
   465 HHGo:= bRes;
   462 HHGo:= false;
   466 end;
   463 end;
   467 
   464 
   468 function AIrndSign(num: LongInt): LongInt;
   465 function AIrndSign(num: LongInt): LongInt;
   469 begin
   466 begin
   470 if random(2) = 0 then AIrndSign:=   num
   467 if random(2) = 0 then AIrndSign:=   num