hedgewars/GSHandlers.inc
changeset 3396 e5b3e5f2818e
parent 3391 77161719ec3c
child 3397 c47af0694a7d
equal deleted inserted replaced
3395:095273ad0e08 3396:e5b3e5f2818e
   171 var isFalling: boolean;
   171 var isFalling: boolean;
   172     //tmp: QWord;
   172     //tmp: QWord;
   173     tdX, tdY: hwFloat;
   173     tdX, tdY: hwFloat;
   174     collV, collH: LongInt;
   174     collV, collH: LongInt;
   175 begin
   175 begin
       
   176 if Gear^.dX > _0_995 then Gear^.dX:= _0_995;
       
   177 if Gear^.dY > _0_995 then Gear^.dY:= _0_995;
   176 Gear^.State:= Gear^.State and not gstCollision;
   178 Gear^.State:= Gear^.State and not gstCollision;
   177 collV:= 0; 
   179 collV:= 0; 
   178 collH:= 0;
   180 collH:= 0;
   179 tdX:= Gear^.dX;
   181 tdX:= Gear^.dX;
   180 tdY:= Gear^.dY;
   182 tdY:= Gear^.dY;
  1826 begin
  1828 begin
  1827 HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
  1829 HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
  1828 
  1830 
  1829 DeleteCI(HHGear);
  1831 DeleteCI(HHGear);
  1830 
  1832 
  1831 OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
  1833 AfterAttack;
  1832 ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
       
  1833 
  1834 
  1834 HHGear^.State:= HHGear^.State and not (gstAttacking or gstAttacked or gstMoving);
  1835 HHGear^.State:= HHGear^.State and not (gstAttacking or gstAttacked or gstMoving);
  1835 HHGear^.Message:= HHGear^.Message and not gm_Attack;
  1836 HHGear^.Message:= HHGear^.Message and not gm_Attack;
  1836 
  1837 
  1837 Gear^.doStep:= @doStepParachuteWork;
  1838 Gear^.doStep:= @doStepParachuteWork;
  1933     DeleteGear(Gear)
  1934     DeleteGear(Gear)
  1934     end
  1935     end
  1935 else begin
  1936 else begin
  1936     PlaySound(sndPlaced);
  1937     PlaySound(sndPlaced);
  1937     DeleteGear(Gear);
  1938     DeleteGear(Gear);
  1938     OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
  1939     AfterAttack;
  1939     ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^)
       
  1940     end;
  1940     end;
  1941 
  1941 
  1942 HHGear^.State:= HHGear^.State and not (gstAttacking or gstAttacked);
  1942 HHGear^.State:= HHGear^.State and not (gstAttacking or gstAttacked);
  1943 HHGear^.Message:= HHGear^.Message and not gm_Attack;
  1943 HHGear^.Message:= HHGear^.Message and not gm_Attack;
  1944 TargetPoint.X:= NoPointX
  1944 TargetPoint.X:= NoPointX
  2017 if ((Gear^.Message and not gm_Switch) <> 0) or (TurnTimeLeft = 0) then
  2017 if ((Gear^.Message and not gm_Switch) <> 0) or (TurnTimeLeft = 0) then
  2018     begin
  2018     begin
  2019     HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
  2019     HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
  2020     Msg:= Gear^.Message and not gm_Switch;
  2020     Msg:= Gear^.Message and not gm_Switch;
  2021     DeleteGear(Gear);
  2021     DeleteGear(Gear);
  2022     OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
  2022     AfterAttack;
  2023     ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
       
  2024 
  2023 
  2025     HHGear:= CurrentHedgehog^.Gear;
  2024     HHGear:= CurrentHedgehog^.Gear;
  2026     ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
  2025     ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
  2027     HHGear^.Message:= Msg;
  2026     HHGear^.Message:= Msg;
  2028     exit
  2027     exit
  2796 begin
  2795 begin
  2797 Gear^.doStep:= @doStepJetpackWork;
  2796 Gear^.doStep:= @doStepJetpackWork;
  2798 
  2797 
  2799 HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
  2798 HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
  2800 FollowGear:= HHGear;
  2799 FollowGear:= HHGear;
  2801 OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
  2800 AfterAttack;
  2802 ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
       
  2803 with HHGear^ do
  2801 with HHGear^ do
  2804     begin
  2802     begin
  2805     State:= State and not gstAttacking;
  2803     State:= State and not gstAttacking;
  2806     Message:= Message and not (gm_Attack or gm_Up or gm_Precise or gm_Left or gm_Right);
  2804     Message:= Message and not (gm_Attack or gm_Up or gm_Precise or gm_Left or gm_Right);
  2807     if (dY < _0_1) and (dY > -_0_1) then
  2805     if (dY < _0_1) and (dY > -_0_1) then
  3040     end;
  3038     end;
  3041 end;
  3039 end;
  3042 
  3040 
  3043 procedure doStepPortal(Gear: PGear);
  3041 procedure doStepPortal(Gear: PGear);
  3044 begin
  3042 begin
       
  3043     if Gear^.IntersectGear <> nil then
       
  3044         begin
       
  3045 // do portal stuff
       
  3046         end
       
  3047 
  3045 (*
  3048 (*
  3046 A portal will have a few things it does.
       
  3047 1) At first, it will move through the air until it collides with a surface. Once it does, it will stop.  At this point we might try a check to verify there is enough terrain for it to be spawned against, and delete. Or we could just let it kinda stick out for now.
       
  3048 
  3049 
  3049 2) From then on, if doStepPortal is called and a gear of a radius less than or equal to the portal is within X pixels of the portal (we could also check on moving toward the portal I guess, depends how accurate this needs to be) the portal will then locate the first other portal of the opposite type (there should only be one other one), and move that gear's X/Y to that other portal's location, and modify dX/dY to be relative to that other portal's orientation relative to this portal's orientation.  This might require some tweaking with offsets of a few pixels to avoid getting gears stuck in land.
  3050 2) From then on, if doStepPortal is called and a gear of a radius less than or equal to the portal is within X pixels of the portal (we could also check on moving toward the portal I guess, depends how accurate this needs to be) the portal will then locate the first other portal of the opposite type (there should only be one other one), and move that gear's X/Y to that other portal's location, and modify dX/dY to be relative to that other portal's orientation relative to this portal's orientation.  This might require some tweaking with offsets of a few pixels to avoid getting gears stuck in land.
  3050 
  3051 
  3051 3) At end of turn, all gtPortal will be deleted.
       
  3052 
       
  3053 *)
  3052 *)
  3054 (*
       
  3055 Ok. Here's where I plan to go with this.
       
  3056 1) Restrict portal gun to X shots.
       
  3057 2) If on first shot, delete all existing gtPortal
       
  3058 3) On any other shot, delete any existing portals of type X%2, and spawn a new portal of type X%2 oriented at angle 180° from the portal gun.  It might possibly be worth linking portals with a Gear reference, to save time on scanning through the Gear list every time we need a portal.
       
  3059 *)
       
  3060 end;
  3053 end;
  3061 
  3054 
  3062 procedure doStepMovingPortal(Gear: PGear);
  3055 procedure doStepMovingPortal(Gear: PGear);
  3063 var i, x, y: LongInt;
  3056 var x, y: LongInt;//, tx, ty, bx, by, tangle: LongInt;
  3064     oX, oY: hwFloat;
  3057 begin
  3065 begin
       
  3066 oX:= Gear^.X;
       
  3067 oY:= Gear^.Y;
       
  3068 Gear^.X:= Gear^.X + Gear^.dX;
  3058 Gear^.X:= Gear^.X + Gear^.dX;
  3069 Gear^.Y:= Gear^.Y + Gear^.dY;
  3059 Gear^.Y:= Gear^.Y + Gear^.dY;
  3070 x:= hwRound(Gear^.X);
  3060 x:= hwRound(Gear^.X);
  3071 y:= hwRound(Gear^.Y);
  3061 y:= hwRound(Gear^.Y);
       
  3062 
       
  3063 if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and ((Land[y, x] and $FF00) <> 0) then
       
  3064     begin
  3072 (* 
  3065 (* 
  3073 Potential issue, portals embedded in land?
  3066 This is not quite doing what I want, but basically hoping to avoid portals just sitting out in midair
  3074 Also, will need checks on how well portal is placed
  3067 Works ok for right angles, aaaand that's about it.
  3075 Thought is possibly doing it based on midpoint and two ends, so a bit of rough terrain is still permitted, but not curves.
  3068 The opposite approach could be taken, we could determine the angle of the land using sheepluva's code and snap the Angle/DirAngle to it.
       
  3069 tangle:= Gear^.Angle+1024;
       
  3070 if tangle > 2048 then dec(tangle,2048);
       
  3071 tx:= hwRound(Gear^.X+SignAs(AngleSin(tangle), Gear^.dX)*_6);
       
  3072 ty:= hwRound(Gear^.Y-AngleCos(tangle)*_6);
       
  3073 bx:= hwRound(Gear^.X-SignAs(AngleSin(tangle), Gear^.dX)*_6);
       
  3074 by:= hwRound(Gear^.Y+AngleCos(tangle)*_6);
  3076 *)
  3075 *)
  3077 if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] <> 0) then
  3076     if ((Gear^.IntersectGear <> nil) and (hwRound(Distance(Gear^.X - Gear^.IntersectGear^.X,Gear^.Y-Gear^.IntersectGear^.Y)) < Gear^.Radius*2)) 
  3078     begin
  3077 (*or
  3079     inc(Gear^.Tag);
  3078 (((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and ((Land[ty, tx] and $FF00) = 0)) or
  3080     Gear^.doStep:= @doStepPortal;
  3079 (((by and LAND_HEIGHT_MASK) = 0) and ((bx and LAND_WIDTH_MASK) = 0) and ((Land[by, bx] and $FF00) = 0))*)
  3081 //    AfterAttack;
  3080     then
  3082     end
  3081         begin
  3083 // How laser checks for infinite
  3082         if CurrentHedgehog <> nil then
       
  3083             if Gear^.IntersectGear = nil then CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].Timer:= 1
       
  3084             else if Gear^.Tag = 2 then CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].Timer:= 2
       
  3085             else CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].Timer:= 1;
       
  3086         DeleteGear(Gear)
       
  3087         end
       
  3088     else
       
  3089         begin
       
  3090         if CurrentHedgehog <> nil then
       
  3091             if Gear^.Tag = 2 then CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].Timer:= 1
       
  3092             else CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].Timer:= 2;
       
  3093         inc(Gear^.Tag);
       
  3094         Gear^.doStep:= @doStepPortal
       
  3095         end
       
  3096     end
  3084 else if (y > cWaterLine + cVisibleWater + Gear^.Radius) or (y < -LAND_WIDTH) or (x > LAND_WIDTH + LAND_WIDTH) or (x < -LAND_WIDTH) then
  3097 else if (y > cWaterLine + cVisibleWater + Gear^.Radius) or (y < -LAND_WIDTH) or (x > LAND_WIDTH + LAND_WIDTH) or (x < -LAND_WIDTH) then
  3085     begin
  3098     begin
       
  3099     if CurrentHedgehog <> nil then
       
  3100         if Gear^.IntersectGear = nil then CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].Timer:= 1
       
  3101         else if Gear^.Tag = 2 then CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].Timer:= 2
       
  3102         else CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].Timer:= 1;
  3086     DeleteGear(Gear);
  3103     DeleteGear(Gear);
  3087 //    AfterAttack
       
  3088     end;
  3104     end;
  3089 end;
  3105 end;
  3090 
  3106 
  3091 procedure doStepPiano(Gear: PGear);
  3107 procedure doStepPiano(Gear: PGear);
  3092 var r0, r1: LongInt;
  3108 var r0, r1: LongInt;