hedgewars/GSHandlers.inc
changeset 5612 2638dec1b323
parent 5606 75916086afa3
child 5624 b6f70f6335ee
equal deleted inserted replaced
5610:f8bdc789ac60 5612:2638dec1b323
   793 
   793 
   794     if (GameTicks and $F) = 0 then
   794     if (GameTicks and $F) = 0 then
   795     begin
   795     begin
   796         if (GameTicks and $30) = 0 then
   796         if (GameTicks and $30) = 0 then
   797             AddVisualGear(gX, gY, vgtBeeTrace);
   797             AddVisualGear(gX, gY, vgtBeeTrace);
   798         Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (Gear^.TargetX - gX));
   798         Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (Gear^.Target.X - gX));
   799         Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000064 * (Gear^.TargetY - gY));
   799         Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000064 * (Gear^.Target.Y - gY));
   800         // make sure new speed isn't higher than original one (which we stored in Friction variable)
   800         // make sure new speed isn't higher than original one (which we stored in Friction variable)
   801         t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY);
   801         t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY);
   802         Gear^.dX := Gear^.dX * t;
   802         Gear^.dX := Gear^.dX * t;
   803         Gear^.dY := Gear^.dY * t;
   803         Gear^.dY := Gear^.dY * t;
   804     end;
   804     end;
  2371 begin
  2371 begin
  2372     AllInactive := false;
  2372     AllInactive := false;
  2373     Gear^.X := Gear^.X + cAirPlaneSpeed * Gear^.Tag;
  2373     Gear^.X := Gear^.X + cAirPlaneSpeed * Gear^.Tag;
  2374 
  2374 
  2375     if (Gear^.Health > 0)and(not (Gear^.X < Gear^.dX))and(Gear^.X < Gear^.dX + cAirPlaneSpeed) then
  2375     if (Gear^.Health > 0)and(not (Gear^.X < Gear^.dX))and(Gear^.X < Gear^.dX + cAirPlaneSpeed) then
  2376     begin
  2376         begin
  2377         dec(Gear^.Health);
  2377         dec(Gear^.Health);
  2378         case Gear^.State of 
  2378         case Gear^.State of 
  2379             0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed *
  2379             0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed *
  2380                              Gear^.Tag, _0, 0);
  2380                              Gear^.Tag, _0, 0);
  2381             1: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtMine,    0, cBombsSpeed *
  2381             1: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtMine,    0, cBombsSpeed *
  2384                              Gear^.Tag, _0, 0);
  2384                              Gear^.Tag, _0, 0);
  2385             3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed *
  2385             3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed *
  2386                              Gear^.Tag, _0, Gear^.Timer + 1);
  2386                              Gear^.Tag, _0, Gear^.Timer + 1);
  2387             //4: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtWaterMelon, 0, cBombsSpeed *
  2387             //4: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtWaterMelon, 0, cBombsSpeed *
  2388             //                 Gear^.Tag, _0, 5000);
  2388             //                 Gear^.Tag, _0, 5000);
  2389         end;
  2389             end;
  2390         Gear^.dX := Gear^.dX + int2hwFloat(30 * Gear^.Tag);
  2390         Gear^.dX := Gear^.dX + int2hwFloat(30 * Gear^.Tag);
  2391         StopSound(Gear^.SoundChannel, 4000);
  2391         StopSound(Gear^.SoundChannel, 4000);
  2392     end;
  2392         end;
  2393 
  2393 
  2394     if (GameTicks and $3F) = 0 then
  2394     if (GameTicks and $3F) = 0 then
  2395         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
  2395         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
  2396 
  2396 
  2397     if (hwRound(Gear^.X) > (LAND_WIDTH+2048)) or (hwRound(Gear^.X) < -2048) then
  2397     if (hwRound(Gear^.X) > (LAND_WIDTH+2048)) or (hwRound(Gear^.X) < -2048) then
  2416         Gear^.Tag := -1;
  2416         Gear^.Tag := -1;
  2417         Gear^.X := int2hwFloat(LAND_WIDTH + 2048);
  2417         Gear^.X := int2hwFloat(LAND_WIDTH + 2048);
  2418     end;
  2418     end;
  2419 
  2419 
  2420     Gear^.Y := int2hwFloat(topY-300);
  2420     Gear^.Y := int2hwFloat(topY-300);
  2421     Gear^.dX := int2hwFloat(Gear^.TargetX - 5 * Gear^.Tag * 15);
  2421     Gear^.dX := int2hwFloat(Gear^.Target.X - 5 * Gear^.Tag * 15);
  2422 
  2422 
  2423     // calcs for Napalm Strike, so that it will hit the target (without wind at least :P)
  2423     // calcs for Napalm Strike, so that it will hit the target (without wind at least :P)
  2424     if (Gear^.State = 2) then
  2424     if (Gear^.State = 2) then
  2425         Gear^.dX := Gear^.dX - cBombsSpeed * Gear^.Tag * 900 
  2425         Gear^.dX := Gear^.dX - cBombsSpeed * Gear^.Tag * 900 
  2426     // calcs for regular falling gears
  2426     // calcs for regular falling gears
  2427     else if (int2hwFloat(Gear^.TargetY) - Gear^.Y > _0) then
  2427     else if (int2hwFloat(Gear^.Target.Y) - Gear^.Y > _0) then
  2428             Gear^.dX := Gear^.dX - cBombsSpeed * hwSqrt((int2hwFloat(Gear^.TargetY) - Gear^.Y) * 2 /
  2428             Gear^.dX := Gear^.dX - cBombsSpeed * hwSqrt((int2hwFloat(Gear^.Target.Y) - Gear^.Y) * 2 /
  2429                 cGravity) * Gear^.Tag;
  2429                 cGravity) * Gear^.Tag;
  2430 
  2430 
  2431     Gear^.Health := 6;
  2431     Gear^.Health := 6;
  2432     Gear^.doStep := @doStepAirAttackWork;
  2432     Gear^.doStep := @doStepAirAttackWork;
  2433     Gear^.SoundChannel := LoopSound(sndPlane, 4000);
  2433     Gear^.SoundChannel := LoopSound(sndPlane, 4000);
  2459     x, y, tx, ty: hwFloat;
  2459     x, y, tx, ty: hwFloat;
  2460 begin
  2460 begin
  2461     AllInactive := false;
  2461     AllInactive := false;
  2462 
  2462 
  2463     HHGear := Gear^.Hedgehog^.Gear;
  2463     HHGear := Gear^.Hedgehog^.Gear;
  2464     tx := int2hwFloat(Gear^.TargetX);
  2464     tx := int2hwFloat(Gear^.Target.X);
  2465     ty := int2hwFloat(Gear^.TargetY);
  2465     ty := int2hwFloat(Gear^.Target.Y);
  2466     x := HHGear^.X;
  2466     x := HHGear^.X;
  2467     y := HHGear^.Y;
  2467     y := HHGear^.Y;
  2468 
  2468 
  2469     if (Distance(tx - x, ty - y) > _256) or
  2469     if (Distance(tx - x, ty - y) > _256) or
  2470        not TryPlaceOnLand(Gear^.TargetX - SpritesData[sprAmGirder].Width div 2,
  2470        not TryPlaceOnLand(Gear^.Target.X - SpritesData[sprAmGirder].Width div 2,
  2471        Gear^.TargetY - SpritesData[sprAmGirder].Height div 2,
  2471        Gear^.Target.Y - SpritesData[sprAmGirder].Height div 2,
  2472        sprAmGirder, Gear^.State, true, false) then
  2472        sprAmGirder, Gear^.State, true, false) then
  2473     begin
  2473     begin
  2474         PlaySound(sndDenied);
  2474         PlaySound(sndDenied);
  2475         HHGear^.Message := HHGear^.Message and not gmAttack;
  2475         HHGear^.Message := HHGear^.Message and not gmAttack;
  2476         HHGear^.State := HHGear^.State and not gstAttacking;
  2476         HHGear^.State := HHGear^.State and not gstAttacking;
  2525     HHGear: PGear;
  2525     HHGear: PGear;
  2526 begin
  2526 begin
  2527     AllInactive := false;
  2527     AllInactive := false;
  2528 
  2528 
  2529     HHGear := Gear^.Hedgehog^.Gear;
  2529     HHGear := Gear^.Hedgehog^.Gear;
  2530     if not TryPlaceOnLand(Gear^.TargetX - SpritesData[sprHHTelepMask].Width div 2,
  2530     if not TryPlaceOnLand(Gear^.Target.X - SpritesData[sprHHTelepMask].Width div 2,
  2531        Gear^.TargetY - SpritesData[sprHHTelepMask].Height div 2,
  2531        Gear^.Target.Y - SpritesData[sprHHTelepMask].Height div 2,
  2532        sprHHTelepMask, 0, false, false) then
  2532        sprHHTelepMask, 0, false, false) then
  2533     begin
  2533     begin
  2534         HHGear^.Message := HHGear^.Message and not gmAttack;
  2534         HHGear^.Message := HHGear^.Message and not gmAttack;
  2535         HHGear^.State := HHGear^.State and not gstAttacking;
  2535         HHGear^.State := HHGear^.State and not gstAttacking;
  2536         HHGear^.State := HHGear^.State or gstHHChooseTarget;
  2536         HHGear^.State := HHGear^.State or gstHHChooseTarget;
  2548         Gear^.dX := HHGear^.dX;
  2548         Gear^.dX := HHGear^.dX;
  2549         // retrieve the cursor direction (it was previously copied to X so it doesn't get lost)
  2549         // retrieve the cursor direction (it was previously copied to X so it doesn't get lost)
  2550         HHGear^.dX.isNegative := (Gear^.X.QWordValue <> 0);
  2550         HHGear^.dX.isNegative := (Gear^.X.QWordValue <> 0);
  2551         Gear^.X := HHGear^.X;
  2551         Gear^.X := HHGear^.X;
  2552         Gear^.Y := HHGear^.Y;
  2552         Gear^.Y := HHGear^.Y;
  2553         HHGear^.X := int2hwFloat(Gear^.TargetX);
  2553         HHGear^.X := int2hwFloat(Gear^.Target.X);
  2554         HHGear^.Y := int2hwFloat(Gear^.TargetY);
  2554         HHGear^.Y := int2hwFloat(Gear^.Target.Y);
  2555         HHGear^.State := HHGear^.State or gstMoving;
  2555         HHGear^.State := HHGear^.State or gstMoving;
  2556         playSound(sndWarp)
  2556         playSound(sndWarp)
  2557     end;
  2557     end;
  2558     Gear^.TargetX:= NoPointX
  2558     Gear^.Target.X:= NoPointX
  2559 end;
  2559 end;
  2560 
  2560 
  2561 ////////////////////////////////////////////////////////////////////////////////
  2561 ////////////////////////////////////////////////////////////////////////////////
  2562 procedure doStepSwitcherWork(Gear: PGear);
  2562 procedure doStepSwitcherWork(Gear: PGear);
  2563 var 
  2563 var