hedgewars/GSHandlers.inc
changeset 3404 d445798e5fe2
parent 3403 244382ea33c2
child 3406 f4bdebced042
equal deleted inserted replaced
3403:244382ea33c2 3404:d445798e5fe2
  3042 
  3042 
  3043 ////////////////////////////////////////////////////////////////////////////////
  3043 ////////////////////////////////////////////////////////////////////////////////
  3044 procedure doStepPortal(Gear: PGear);
  3044 procedure doStepPortal(Gear: PGear);
  3045 var tmpGear, iterator: PGear;
  3045 var tmpGear, iterator: PGear;
  3046 begin
  3046 begin
  3047     //if not AllInactive and (Gear^.IntersectGear <> nil) then
  3047     if (Land[hwRound(Gear^.Y), hwRound(Gear^.X)] and $FF00) = 0 then DeleteGear(Gear);
  3048     if (Gear^.IntersectGear <> nil) then
  3048     if not AllInactive and (Gear^.IntersectGear <> nil) then
       
  3049     //if (Gear^.IntersectGear <> nil) then
  3049         begin
  3050         begin
  3050         iterator:= GearsList;
  3051         iterator:= GearsList;
  3051         while iterator <> nil do
  3052         while iterator <> nil do
  3052             begin
  3053             begin
  3053             if iterator^.Active and (iterator^.Kind <> gtPortal) and 
  3054             if iterator^.Active and (iterator^.Kind <> gtPortal) and 
  3054                (hwRound(hwAbs(Gear^.X-iterator^.X)+hwAbs(Gear^.Y-iterator^.Y)) < Gear^.Radius) and 
  3055                (hwRound(hwAbs(Gear^.X-iterator^.X)+hwAbs(Gear^.Y-iterator^.Y)) < Gear^.Radius+iterator^.Radius) and 
  3055                ((hwAbs(Gear^.X-(iterator^.X+iterator^.dX))+hwAbs(Gear^.Y-(iterator^.Y+iterator^.dY))).QWordValue < (hwAbs(Gear^.X-iterator^.X)+hwAbs(Gear^.Y-iterator^.Y)).QWordValue) and
  3056                ((hwAbs(Gear^.X-(iterator^.X+iterator^.dX))+hwAbs(Gear^.Y-(iterator^.Y+iterator^.dY))).QWordValue < (hwAbs(Gear^.X-iterator^.X)+hwAbs(Gear^.Y-iterator^.Y)).QWordValue) and
  3056                (hwRound(Distance(Gear^.X-iterator^.X,Gear^.Y-iterator^.Y)) < Gear^.Radius) then // Let's check this one more closely
  3057                (hwRound(Distance(Gear^.X-iterator^.X,Gear^.Y-iterator^.Y)) < Gear^.Radius+iterator^.Radius) then // Let's check this one more closely
  3057                 begin
  3058                 begin
  3058                 iterator^.X:=Gear^.IntersectGear^.X+_128;
  3059                 iterator^.X:=Gear^.IntersectGear^.X+_128;
  3059                 iterator^.Y:=Gear^.IntersectGear^.Y+_128;
  3060                 iterator^.Y:=Gear^.IntersectGear^.Y+_128;
  3060                 iterator^.dX.isNegative:= not iterator^.dX.isNegative;
  3061                 iterator^.dX.isNegative:= not iterator^.dX.isNegative;
  3061                 end;
  3062                 end;
  3072 *)
  3073 *)
  3073 end;
  3074 end;
  3074 
  3075 
  3075 procedure doStepMovingPortal(Gear: PGear);
  3076 procedure doStepMovingPortal(Gear: PGear);
  3076 var x, y, tx, ty: LongInt;//, bx, by, tangle: LongInt;
  3077 var x, y, tx, ty: LongInt;//, bx, by, tangle: LongInt;
       
  3078     iterator: PGear;
  3077 begin
  3079 begin
  3078 Gear^.X:= Gear^.X + Gear^.dX;
  3080 Gear^.X:= Gear^.X + Gear^.dX;
  3079 Gear^.Y:= Gear^.Y + Gear^.dY;
  3081 Gear^.Y:= Gear^.Y + Gear^.dY;
  3080 x:= hwRound(Gear^.X);
  3082 x:= hwRound(Gear^.X);
  3081 y:= hwRound(Gear^.Y);
  3083 y:= hwRound(Gear^.Y);
  3124         inc(Gear^.Tag);
  3126         inc(Gear^.Tag);
  3125         Gear^.doStep:= @doStepPortal;
  3127         Gear^.doStep:= @doStepPortal;
  3126         if Gear^.IntersectGear <> nil then
  3128         if Gear^.IntersectGear <> nil then
  3127             begin
  3129             begin
  3128             Gear^.IntersectGear^.IntersectGear:= Gear;
  3130             Gear^.IntersectGear^.IntersectGear:= Gear;
  3129             SetAllToActive
  3131             AllInactive:= false;
       
  3132             // This jiggles gears, to ensure a portal connection just placed under a gear takes effect.
       
  3133             iterator:= GearsList;
       
  3134             while iterator <> nil do
       
  3135                 begin
       
  3136                 iterator^.Active:= true;
       
  3137                 if iterator^.dY.QWordValue = _0.QWordValue then iterator^.dY.isNegative:= false;
       
  3138                 iterator^.State:= iterator^.State or gstMoving;
       
  3139                 DeleteCI(iterator);
       
  3140                 inc(iterator^.dY.QWordValue,10);
       
  3141                 iterator:= iterator^.NextGear;
       
  3142                 end;
       
  3143             doStepPortal(Gear);
       
  3144             if Gear^.IntersectGear <> nil then doStepPortal(Gear^.IntersectGear);
  3130             end
  3145             end
  3131         end
  3146         end
  3132     end
  3147     end
  3133 else if (y > cWaterLine + cVisibleWater + Gear^.Radius) or (y < -LAND_WIDTH) or (x > LAND_WIDTH + LAND_WIDTH) or (x < -LAND_WIDTH) then
  3148 else if (y > cWaterLine + cVisibleWater + Gear^.Radius) or (y < -LAND_WIDTH) or (x > LAND_WIDTH + LAND_WIDTH) or (x < -LAND_WIDTH) then
  3134     begin
  3149     begin