hedgewars/uGears.pas
changeset 7754 e81dc9bef8b8
parent 7733 a1476c09403f
child 7755 b8958e64e68d
equal deleted inserted replaced
7753:dda33caa609d 7754:e81dc9bef8b8
   728 end;
   728 end;
   729 
   729 
   730 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt);
   730 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt);
   731 var t: PGearArray;
   731 var t: PGearArray;
   732     Gear: PGear;
   732     Gear: PGear;
   733     i, tmpDmg: LongInt;
   733     i, j, tmpDmg: LongInt;
   734     VGear: PVisualGear;
   734     VGear: PVisualGear;
   735 begin
   735 begin
   736 t:= CheckGearsCollision(Ammo);
   736 t:= CheckGearsCollision(Ammo);
   737 // Just to avoid hogs on rope dodging fire.
   737 // Just to avoid hogs on rope dodging fire.
   738 if (CurAmmoGear <> nil) and ((CurAmmoGear^.Kind = gtRope) or (CurAmmoGear^.Kind = gtJetpack) or (CurAmmoGear^.Kind = gtBirdy))
   738 if (CurAmmoGear <> nil) and ((CurAmmoGear^.Kind = gtRope) or (CurAmmoGear^.Kind = gtJetpack) or (CurAmmoGear^.Kind = gtBirdy))
   767 
   767 
   768         case Gear^.Kind of
   768         case Gear^.Kind of
   769             gtHedgehog,
   769             gtHedgehog,
   770             gtMine,
   770             gtMine,
   771             gtSMine,
   771             gtSMine,
       
   772             gtKnife,
   772             gtTarget,
   773             gtTarget,
   773             gtCase,
   774             gtCase,
   774             gtExplosives,
   775             gtExplosives,
   775             gtStructure:
   776             gtStructure:
   776             begin
   777             begin
   778                 begin
   779                 begin
   779                 Ammo^.Timer:= 0;
   780                 Ammo^.Timer:= 0;
   780                 exit;
   781                 exit;
   781                 end;
   782                 end;
   782             if (not Gear^.Invulnerable) then
   783             if (not Gear^.Invulnerable) then
       
   784                 begin
       
   785                 if (Ammo^.Kind = gtKnife) and (tmpDmg > 0) then
       
   786                     for j:= 1 to max(1,min(3,tmpDmg div 5)) do
       
   787                         begin
       
   788                         VGear:= AddVisualGear(hwRound(Ammo^.X-((Ammo^.X-Gear^.X)/_2)), hwRound(Ammo^.Y-((Ammo^.Y-Gear^.Y)/_2)), vgtStraightShot);
       
   789                         if VGear <> nil then
       
   790                             with VGear^ do
       
   791                                 begin
       
   792                                 Tint:= $FFCC00FF;
       
   793                                 Angle:= random(360);
       
   794                                 dx:= 0.0005 * (random(100));
       
   795                                 dy:= 0.0005 * (random(100));
       
   796                                 if random(2) = 0 then
       
   797                                     dx := -dx;
       
   798                                 if random(2) = 0 then
       
   799                                     dy := -dy;
       
   800                                 FrameTicks:= 600+random(200);
       
   801                                 State:= ord(sprStar)
       
   802                                 end
       
   803                         end;
   783                 ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove)
   804                 ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove)
       
   805                 end
   784             else
   806             else
   785                 Gear^.State:= Gear^.State or gstWinner;
   807                 Gear^.State:= Gear^.State or gstWinner;
   786             if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then 
   808             if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then 
   787                 begin
   809                 begin
   788                 if (Ammo^.Hedgehog^.Gear <> nil) then
   810                 if (Ammo^.Hedgehog^.Gear <> nil) then
   789                     Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable);
   811                     Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable);
   790                 ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
   812                 ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
   791                 end;
   813                 end;
   792 
   814 
   793             DeleteCI(Gear);
       
   794             if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
   815             if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
   795                 begin
   816                 begin
   796                 Gear^.dX:= Ammo^.dX * Power * _0_005;
   817                 Gear^.dX:= Ammo^.dX * Power * _0_005;
   797                 Gear^.dY:= Ammo^.dY * Power * _0_005
   818                 Gear^.dY:= Ammo^.dY * Power * _0_005
   798                 end
   819                 end
   799             else
   820             else if (Ammo^.Kind <> gtFlame) or (Gear^.Kind = gtHedgehog) then
   800                 begin
   821                 begin
   801                 Gear^.dX:= Ammo^.dX * Power * _0_01;
   822                 Gear^.dX:= Ammo^.dX * Power * _0_01;
   802                 Gear^.dY:= Ammo^.dY * Power * _0_01
   823                 Gear^.dY:= Ammo^.dY * Power * _0_01
   803                 end;
   824                 end;
   804 
   825 
   805             Gear^.Active:= true;
   826             if (not isZero(Gear^.dX)) or (not isZero(Gear^.dY)) then
   806             Gear^.State:= Gear^.State or gstMoving;
   827                 begin
   807 
   828                 Gear^.Active:= true;
   808             // move the gear upwards a bit to throw it over tiny obstacles at start
   829                 DeleteCI(Gear);
   809             if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   830                 Gear^.State:= Gear^.State or gstMoving;
   810                 begin
   831                 if Gear^.Kind = gtKnife then Gear^.State:= Gear^.State and not gstCollision;
   811                 if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
   832                 // move the gear upwards a bit to throw it over tiny obstacles at start
   812                 or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   833                 if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   813                     Gear^.Y:= Gear^.Y - _1;
   834                     begin
   814                 if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
   835                     if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
   815                 or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   836                     or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   816                     Gear^.Y:= Gear^.Y - _1;
   837                         Gear^.Y:= Gear^.Y - _1;
   817                 if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
   838                     if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
   818                 or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   839                     or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   819                     Gear^.Y:= Gear^.Y - _1;
   840                         Gear^.Y:= Gear^.Y - _1;
       
   841                     if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
       
   842                     or (TestCollisionYwithGear(Gear, -1) <> 0)) then
       
   843                         Gear^.Y:= Gear^.Y - _1;
       
   844                     end
   820                 end;
   845                 end;
       
   846 
   821 
   847 
   822             if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then
   848             if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then
   823                 FollowGear:= Gear
   849                 FollowGear:= Gear
   824             end;
   850             end;
   825         end
   851         end