hedgewars/uGearsHandlersMess.pas
changeset 15238 b189d6a2ecda
parent 15237 a9a1f5824076
child 15239 186c3f272187
equal deleted inserted replaced
15237:a9a1f5824076 15238:b189d6a2ecda
  3081 procedure doStepAirAttackWork(Gear: PGear);
  3081 procedure doStepAirAttackWork(Gear: PGear);
  3082 var uw, nuw: boolean;
  3082 var uw, nuw: boolean;
  3083     tmpFloat: hwFloat;
  3083     tmpFloat: hwFloat;
  3084 begin
  3084 begin
  3085     AllInactive := false;
  3085     AllInactive := false;
       
  3086     if (WorldEdge = weWrap) then
       
  3087         if (WorldWrap(Gear)) then
       
  3088             inc(Gear^.Power);
  3086     Gear^.X := Gear^.X + cAirPlaneSpeed * Gear^.Tag;
  3089     Gear^.X := Gear^.X + cAirPlaneSpeed * Gear^.Tag;
  3087     if (Gear^.Health > 0) and (not (Gear^.X < Gear^.dX)) and (Gear^.X < Gear^.dX + cAirPlaneSpeed) then
  3090     if (Gear^.Health > 0) and (Gear^.Power >= Gear^.WDTimer) and (((Gear^.Tag = 1) and (not (Gear^.X < Gear^.dX))) or ((Gear^.Tag = -1) and (not (Gear^.X > Gear^.dX)))) then
  3088         begin
  3091         begin
  3089         dec(Gear^.Health);
  3092         dec(Gear^.Health);
       
  3093         Gear^.FlightTime:= 0;
  3090         // Spawn missile
  3094         // Spawn missile
  3091         case Gear^.State of
  3095         case Gear^.State of
  3092             0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0);
  3096             0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0);
  3093             1: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtMine,    0, cBombsSpeed * Gear^.Tag, _0, 0);
  3097             1: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtMine,    0, cBombsSpeed * Gear^.Tag, _0, 0);
  3094             2: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtNapalmBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0);
  3098             2: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtNapalmBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0);
  3095             3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed * Gear^.Tag, _0, Gear^.Timer + 1);
  3099             3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed * Gear^.Tag, _0, Gear^.Timer + 1);
  3096         end;
  3100         end;
  3097         Gear^.dX := Gear^.dX + int2hwFloat(Gear^.Damage * Gear^.Tag);
  3101         Gear^.dX := Gear^.X + int2hwFloat(Gear^.Damage * Gear^.Tag);
       
  3102         if (WorldEdge = weWrap) then
       
  3103             begin
       
  3104             Gear^.dX := int2hwFloat(CalcWorldWrap(hwRound(Gear^.dX), 0));
       
  3105             if (((Gear^.Tag = 1) and (not (Gear^.X < Gear^.dX))) or ((Gear^.Tag = -1) and (not (Gear^.X > Gear^.dX)))) then
       
  3106                 inc(Gear^.WDTimer);
       
  3107             end;
       
  3108 
  3098         if CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
  3109         if CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
  3099             FollowGear^.State:= FollowGear^.State or gstSubmersible;
  3110             FollowGear^.State:= FollowGear^.State or gstSubmersible;
  3100         if (Gear^.SoundChannel <> -1) and (WorldEdge <> weSea) then
  3111         if (Gear^.SoundChannel <> -1) and (WorldEdge <> weSea) then
  3101             begin
  3112             begin
  3102             StopSoundChan(Gear^.SoundChannel, 4000);
  3113             StopSoundChan(Gear^.SoundChannel, 4000);
  3103             Gear^.SoundChannel := -1;
  3114             Gear^.SoundChannel := -1;
  3104             end;
  3115             end;
  3105         end;
  3116         end;
       
  3117 
       
  3118     if (Gear^.Health = 0) then
       
  3119         inc(Gear^.FlightTime);
  3106 
  3120 
  3107     // Particles
  3121     // Particles
  3108     if (GameTicks and $3F) = 0 then
  3122     if (GameTicks and $3F) = 0 then
  3109         if CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
  3123         if CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
  3110             AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBubble)
  3124             AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBubble)
  3111         else
  3125         else
  3112             AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
  3126             AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
  3113 
  3127 
  3114     // Get rid of gear and cleanup
  3128     // Get rid of gear and cleanup
  3115     if (hwRound(Gear^.X) > (max(LAND_WIDTH,4096)+2048)) or (hwRound(Gear^.X) < -2048) or ((Gear^.Message and gmDestroy) > 0) then
  3129     if ((WorldEdge = weWrap) and (Gear^.FlightTime >= 4000)) or
       
  3130         ((WorldEdge <> weWrap) and ((hwRound(Gear^.X) > (max(LAND_WIDTH,4096)+2048)) or (hwRound(Gear^.X) < -2048) or ((Gear^.Message and gmDestroy) > 0))) then
  3116         begin
  3131         begin
  3117         // fail-safe: instanly stop sound if it wasn't disabled before
  3132         // fail-safe: instanly stop sound if it wasn't disabled before
  3118         if (Gear^.SoundChannel <> -1) then
  3133         if (Gear^.SoundChannel <> -1) then
  3119             begin
  3134             begin
  3120             StopSoundChan(Gear^.SoundChannel);
  3135             StopSoundChan(Gear^.SoundChannel);
  3167     CurAmmoGear := nil;
  3182     CurAmmoGear := nil;
  3168 
  3183 
  3169     if Gear^.X.QWordValue = 0 then
  3184     if Gear^.X.QWordValue = 0 then
  3170         begin
  3185         begin
  3171         Gear^.Tag :=  1;
  3186         Gear^.Tag :=  1;
  3172         Gear^.X := -_2048;
  3187         if (WorldEdge = weWrap) then
       
  3188             Gear^.X := int2hwFloat(CalcWorldWrap(Gear^.Target.X + max(384, LAND_WIDTH shr 2), 0))
       
  3189         else
       
  3190             Gear^.X := -_2048;
  3173         end
  3191         end
  3174     else
  3192     else
  3175         begin
  3193         begin
  3176         Gear^.Tag := -1;
  3194         Gear^.Tag := -1;
  3177         Gear^.X := int2hwFloat(max(LAND_WIDTH,4096) + 2048);
  3195         if (WorldEdge = weWrap) then
       
  3196             Gear^.X := int2hwFloat(CalcWorldWrap(Gear^.Target.X - max(384, LAND_WIDTH shr 2), 0))
       
  3197         else
       
  3198             Gear^.X := int2hwFloat(max(LAND_WIDTH,4096) + 2048);
  3178         end;
  3199         end;
  3179 
  3200 
  3180     Gear^.Y := int2hwFloat(topY - 300);
  3201     Gear^.Y := int2hwFloat(topY - 300);
  3181 
  3202 
  3182     // Appear out of nowhere in wrap
  3203     // Appear out of nowhere in wrap
  3191     // calcs for regular falling gears
  3212     // calcs for regular falling gears
  3192     else if (int2hwFloat(Gear^.Target.Y) - Gear^.Y > _0) then
  3213     else if (int2hwFloat(Gear^.Target.Y) - Gear^.Y > _0) then
  3193             Gear^.dX := Gear^.dX - cBombsSpeed * hwSqrt((int2hwFloat(Gear^.Target.Y) - Gear^.Y) * 2 /
  3214             Gear^.dX := Gear^.dX - cBombsSpeed * hwSqrt((int2hwFloat(Gear^.Target.Y) - Gear^.Y) * 2 /
  3194                 cGravity) * Gear^.Tag;
  3215                 cGravity) * Gear^.Tag;
  3195 
  3216 
       
  3217     if (WorldEdge = weWrap) then
       
  3218         begin
       
  3219         Gear^.dX := int2hwFloat(CalcWorldWrap(hwRound(Gear^.dX), 0));
       
  3220         if (((Gear^.Tag = 1) and (not (Gear^.X < Gear^.dX))) or ((Gear^.Tag = -1) and (not (Gear^.X > Gear^.dX)))) then
       
  3221             Gear^.WDTimer:= 1;
       
  3222         end;
       
  3223 
  3196     Gear^.doStep := @doStepAirAttackWork;
  3224     Gear^.doStep := @doStepAirAttackWork;
  3197 
  3225 
  3198     if (WorldEdge = weSea) then
  3226     if (WorldEdge = weSea) then
  3199         begin
  3227         begin
  3200         Gear^.SoundChannel := LoopSound(sndPlaneWater, 4000);
  3228         Gear^.SoundChannel := LoopSound(sndPlaneWater, 4000);
  3201         Gear^.Karma := 1;
  3229         Gear^.Karma := 1;
       
  3230         end
       
  3231     else if  (WorldEdge = weWrap) then
       
  3232         begin
       
  3233         Gear^.SoundChannel := LoopSound(sndPlane);
       
  3234         Gear^.Karma := 0;
  3202         end
  3235         end
  3203     else
  3236     else
  3204         begin
  3237         begin
  3205         Gear^.SoundChannel := LoopSound(sndPlane, 4000);
  3238         Gear^.SoundChannel := LoopSound(sndPlane, 4000);
  3206         Gear^.Karma := 0;
  3239         Gear^.Karma := 0;