hedgewars/uGearsHandlersMess.pas
changeset 15670 47a6929b819e
parent 15669 0da235387ad3
child 15674 3d8c2ab2b98b
equal deleted inserted replaced
15669:0da235387ad3 15670:47a6929b819e
  7194         Sentry^.Y := Sentry^.Y + int2hwFloat(offset);
  7194         Sentry^.Y := Sentry^.Y + int2hwFloat(offset);
  7195         MakeSentryStep := true
  7195         MakeSentryStep := true
  7196     end
  7196     end
  7197 end;
  7197 end;
  7198 
  7198 
       
  7199 function TraceAttackPath(fromX, fromY, toX, toY, step: hwFloat; mask: Word): LongWord;
       
  7200 var distX, distY, dist, invDistance: HwFloat;
       
  7201     i, count: LongInt;
       
  7202 begin
       
  7203     TraceAttackPath := 0;
       
  7204     if (step < _1)
       
  7205         or ((hwRound(fromX) and LAND_WIDTH_MASK) <> 0)
       
  7206         or ((hwRound(toX) and LAND_WIDTH_MASK) <> 0)
       
  7207         or ((hwRound(fromY) and LAND_HEIGHT_MASK) <> 0)
       
  7208         or ((hwRound(toY) and LAND_HEIGHT_MASK) <> 0) then
       
  7209         exit;
       
  7210 
       
  7211 
       
  7212     distX := toX - fromX;
       
  7213     distY := toY - fromY;
       
  7214     dist := Distance(distX, distY);
       
  7215     count := hwRound(dist / step);
       
  7216 
       
  7217     invDistance := step / dist;
       
  7218     distX := distX * invDistance;
       
  7219     distY := distY * invDistance;
       
  7220 
       
  7221     for i := 0 to count - 1 do
       
  7222     begin
       
  7223         if (Land[hwRound(fromY), hwRound(fromX)] and mask) <> 0 then
       
  7224             Inc(TraceAttackPath);
       
  7225         fromX := fromX + distX;
       
  7226         fromY := fromY + distY;
       
  7227     end
       
  7228 end;
       
  7229 
  7199 procedure doStepSentry(Gear: PGear);
  7230 procedure doStepSentry(Gear: PGear);
  7200 var HHGear, bullet: PGear;
  7231 var HHGear, bullet: PGear;
  7201     distX, distY, invDistance: HwFloat;
  7232     distX, distY, invDistance: HwFloat;
  7202 const sentry_Idle = 0;
  7233 const sentry_Idle = 0;
  7203     sentry_Walking = 1;
  7234     sentry_Walking = 1;
  7213     if TestCollisionY(Gear, 1) = 0 then
  7244     if TestCollisionY(Gear, 1) = 0 then
  7214     begin
  7245     begin
  7215         doStepFallingGear(Gear);
  7246         doStepFallingGear(Gear);
  7216         Gear^.Timer := 0;
  7247         Gear^.Timer := 0;
  7217         Gear^.Tag := sentry_Idle;
  7248         Gear^.Tag := sentry_Idle;
       
  7249         Gear^.Target.X := 0;
       
  7250         Gear^.Target.Y := 0;
  7218         exit;
  7251         exit;
  7219     end;
  7252     end;
  7220 
  7253 
  7221     if Gear^.Timer > 0 then dec(Gear^.Timer);
  7254     if Gear^.Timer > 0 then dec(Gear^.Timer);
  7222 
  7255 
  7251                 hwRound(Gear^.X), hwRound(Gear^.Y),
  7284                 hwRound(Gear^.X), hwRound(Gear^.Y),
  7252                 gtDEagleShot, 0,
  7285                 gtDEagleShot, 0,
  7253                 distX, distY, 0);
  7286                 distX, distY, 0);
  7254 
  7287 
  7255             bullet^.Boom := 4;
  7288             bullet^.Boom := 4;
       
  7289             bullet^.Health := 15;
  7256             bullet^.PortalCounter := 1;
  7290             bullet^.PortalCounter := 1;
  7257             bullet^.Elasticity := Gear^.X;
  7291             bullet^.Elasticity := Gear^.X;
  7258             bullet^.Friction := Gear^.Y;
  7292             bullet^.Friction := Gear^.Y;
  7259             bullet^.Data := Pointer(Gear);
  7293             bullet^.Data := Pointer(Gear);
  7260 
  7294 
  7291         distX := HHGear^.X - Gear^.X;
  7325         distX := HHGear^.X - Gear^.X;
  7292         distY := HHGear^.Y - Gear^.Y;
  7326         distY := HHGear^.Y - Gear^.Y;
  7293         if (distX.isNegative = Gear^.dX.isNegative)
  7327         if (distX.isNegative = Gear^.dX.isNegative)
  7294             and (distX.Round > 24)
  7328             and (distX.Round > 24)
  7295             and (distX.Round < 500)
  7329             and (distX.Round < 500)
  7296             and (hwAbs(distY) < hwAbs(distX)) then
  7330             and (hwAbs(distY) < hwAbs(distX))
       
  7331             and (TraceAttackPath(Gear^.X, Gear^.Y, HHGear^.X, HHGear^.Y, _4, lfLandMask) <= 18 ) then
  7297         begin
  7332         begin
  7298             Gear^.Target.X := hwRound(HHGear^.X);
  7333             Gear^.Target.X := hwRound(HHGear^.X);
  7299             Gear^.Target.Y := hwRound(HHGear^.Y);
  7334             Gear^.Target.Y := hwRound(HHGear^.Y);
  7300             Gear^.Tag := sentry_Aiming;
  7335             Gear^.Tag := sentry_Aiming;
  7301             Gear^.Timer := 1800 + GetRandom(400);
  7336             Gear^.Timer := 1800 + GetRandom(400);