hedgewars/uGearsHandlersMess.pas
changeset 15681 a3f492e601dd
parent 15679 72173f800dc4
child 15682 5ce76c658c22
equal deleted inserted replaced
15680:d23ebe7c88f8 15681:a3f492e601dd
  7171     Gear^.doStep := @doStepBulletWork
  7171     Gear^.doStep := @doStepBulletWork
  7172 end;
  7172 end;
  7173 
  7173 
  7174 ////////////////////////////////////////////////////////////////////////////////
  7174 ////////////////////////////////////////////////////////////////////////////////
  7175 
  7175 
  7176 function MakeSentryStep(Sentry: PGear; maxYStep: LongInt): Boolean;
  7176 function MakeSentryStep(Sentry: PGear; maxYStep: LongInt; TestOnly: Boolean): Boolean;
  7177 var x, y, offset, direction: LongInt;
  7177 var x, y, offset, direction: LongInt;
  7178 begin
  7178 begin
  7179     MakeSentryStep := false;
  7179     MakeSentryStep := false;
  7180     x := hwRound(Sentry^.X);
  7180     x := hwRound(Sentry^.X);
  7181     y := hwRound(Sentry^.Y);
  7181     y := hwRound(Sentry^.Y);
  7187             break;
  7187             break;
  7188     end;
  7188     end;
  7189 
  7189 
  7190     if (offset >= -maxYStep) and (offset <= maxYStep) then
  7190     if (offset >= -maxYStep) and (offset <= maxYStep) then
  7191     begin
  7191     begin
  7192         Sentry^.X := Sentry^.X + signAs(_1, Sentry^.dX);
  7192         if not TestOnly then
  7193         Sentry^.Y := Sentry^.Y + int2hwFloat(offset);
  7193         begin
       
  7194             Sentry^.X := Sentry^.X + signAs(_1, Sentry^.dX);
       
  7195             Sentry^.Y := Sentry^.Y + int2hwFloat(offset);
       
  7196         end;
  7194         MakeSentryStep := true
  7197         MakeSentryStep := true
  7195     end
  7198     end
  7196 end;
  7199 end;
  7197 
  7200 
  7198 function TraceAttackPath(fromX, fromY, toX, toY, step: hwFloat; mask: Word): LongWord;
  7201 function TraceAttackPath(fromX, fromY, toX, toY, step: hwFloat; mask: Word): LongWord;
  7204         or ((hwRound(fromX) and LAND_WIDTH_MASK) <> 0)
  7207         or ((hwRound(fromX) and LAND_WIDTH_MASK) <> 0)
  7205         or ((hwRound(toX) and LAND_WIDTH_MASK) <> 0)
  7208         or ((hwRound(toX) and LAND_WIDTH_MASK) <> 0)
  7206         or ((hwRound(fromY) and LAND_HEIGHT_MASK) <> 0)
  7209         or ((hwRound(fromY) and LAND_HEIGHT_MASK) <> 0)
  7207         or ((hwRound(toY) and LAND_HEIGHT_MASK) <> 0) then
  7210         or ((hwRound(toY) and LAND_HEIGHT_MASK) <> 0) then
  7208         exit;
  7211         exit;
  7209 
       
  7210 
  7212 
  7211     distX := toX - fromX;
  7213     distX := toX - fromX;
  7212     distY := toY - fromY;
  7214     distY := toY - fromY;
  7213     dist := Distance(distX, distY);
  7215     dist := Distance(distX, distY);
  7214     count := hwRound(dist / step);
  7216     count := hwRound(dist / step);
  7265         if Gear^.Tag = sentry_Idle then
  7267         if Gear^.Tag = sentry_Idle then
  7266         begin
  7268         begin
  7267             Gear^.Tag := sentry_Walking;
  7269             Gear^.Tag := sentry_Walking;
  7268             Gear^.Timer := 1000 + GetRandom(3000);
  7270             Gear^.Timer := 1000 + GetRandom(3000);
  7269             Gear^.dX.isNegative := GetRandom(2) = 1;
  7271             Gear^.dX.isNegative := GetRandom(2) = 1;
       
  7272             if not MakeSentryStep(Gear, 6, true) then
       
  7273             begin
       
  7274                 Gear^.dX.isNegative := not Gear^.dX.isNegative;
       
  7275                 if not MakeSentryStep(Gear, 6, true) then
       
  7276                 begin
       
  7277                     Gear^.Tag := sentry_Idle;
       
  7278                     Gear^.Timer := 10000;
       
  7279                 end;
       
  7280             end
  7270         end
  7281         end
  7271         else if Gear^.Tag in [sentry_Walking, sentry_Reloading] then
  7282         else if Gear^.Tag in [sentry_Walking, sentry_Reloading] then
  7272         begin
  7283         begin
  7273             Gear^.Tag := sentry_Idle;
  7284             Gear^.Tag := sentry_Idle;
  7274             Gear^.Timer := 1000 + GetRandom(1000);
  7285             Gear^.Timer := 1000 + GetRandom(1000);
  7322         end;
  7333         end;
  7323     end;
  7334     end;
  7324 
  7335 
  7325     if (Gear^.Tag = sentry_Walking) and ((GameTicks and $1F) = 0) then
  7336     if (Gear^.Tag = sentry_Walking) and ((GameTicks and $1F) = 0) then
  7326     begin
  7337     begin
  7327         if not MakeSentryStep(Gear, 6) then
  7338         if not MakeSentryStep(Gear, 6, false) then
  7328             Gear^.Timer := 0
  7339             Gear^.Timer := 0
  7329     end;
  7340     end;
  7330 
  7341 
  7331     if ((GameTicks and $1F) = 0)
  7342     if ((GameTicks and $1F) = 0)
  7332         and (Gear^.Tag = sentry_Aiming)
  7343         and (Gear^.Tag = sentry_Aiming)