hedgewars/GSHandlers.inc
changeset 7627 e1e112687fd6
parent 7623 addc5b262617
child 7649 df90970ae81a
equal deleted inserted replaced
7626:73b9a385f898 7627:e1e112687fd6
   167     //tmp: QWord;
   167     //tmp: QWord;
   168     tdX, tdY: hwFloat;
   168     tdX, tdY: hwFloat;
   169     collV, collH: LongInt;
   169     collV, collH: LongInt;
   170     land: word;
   170     land: word;
   171 begin
   171 begin
   172     // clip velocity at 1.9 - over 1 per pixel, but really shouldn't cause many actual problems.
   172     // clip velocity at 2 - over 1 per pixel, but really shouldn't cause many actual problems.
   173     if Gear^.dX.QWordValue > 8160437862 then
   173 {$IFNDEF WEB}
   174         Gear^.dX.QWordValue:= 8160437862;
   174     if Gear^.dX.Round > 2 then
   175     if Gear^.dY.QWordValue > 8160437862 then
   175         Gear^.dX.QWordValue:= 8589934592;
   176         Gear^.dY.QWordValue:= 8160437862;
   176     if Gear^.dY.Round > 2 then
       
   177         Gear^.dY.QWordValue:= 8589934592;
       
   178 {$ELSE}
       
   179     if Gear^.dX.Round > 2 then
       
   180         begin
       
   181         Gear^.dX.Round:= 2;
       
   182         Gear^.dX.Frac:= 0
       
   183         end;
       
   184     if Gear^.dY.QWordValue > 2 then
       
   185         begin
       
   186         Gear^.dY.Round:= 2;
       
   187         Gear^.dY.Frac:= 0
       
   188         end;
       
   189 {$ENDIF}
   177     Gear^.State := Gear^.State and (not gstCollision);
   190     Gear^.State := Gear^.State and (not gstCollision);
   178     collV := 0;
   191     collV := 0;
   179     collH := 0;
   192     collH := 0;
   180     tdX := Gear^.dX;
   193     tdX := Gear^.dX;
   181     tdY := Gear^.dY;
   194     tdY := Gear^.dY;
  3702             ny.isNegative := not ny.isNegative;
  3715             ny.isNegative := not ny.isNegative;
  3703 
  3716 
  3704         // calc gear offset in portal normal vector direction
  3717         // calc gear offset in portal normal vector direction
  3705         noffs:= (nx * ox + ny * oy);
  3718         noffs:= (nx * ox + ny * oy);
  3706 
  3719 
  3707         if isBullet and (hwRound(hwAbs(noffs)) >= Gear^.Radius) then
  3720         if isBullet and (noffs.Round >= Gear^.Radius) then
  3708             continue;
  3721             continue;
  3709 
  3722 
  3710         // avoid gravity related loops of not really moving gear
  3723         // avoid gravity related loops of not really moving gear
  3711         if not (iscake or isbullet)
  3724         if not (iscake or isbullet)
  3712         and (Gear^.dY.isNegative)
  3725         and (Gear^.dY.isNegative)
  5139         exit
  5152         exit
  5140         end;
  5153         end;
  5141     
  5154     
  5142 doStepFallingGear(Gear);
  5155 doStepFallingGear(Gear);
  5143 end;
  5156 end;
       
  5157 
       
  5158 procedure doStepCreeper(Gear: PGear);
       
  5159 var hogs: PGearArrayS;
       
  5160     HHGear: PGear;
       
  5161     tdX: hwFloat;
       
  5162     dir: LongInt;
       
  5163 begin
       
  5164 doStepFallingGear(Gear);
       
  5165 if Gear^.Timer > 0 then dec(Gear^.Timer);
       
  5166 // creeper sleep phase
       
  5167 if (Gear^.Hedgehog = nil) and (Gear^.Timer > 0) then exit;
       
  5168 
       
  5169 if Gear^.Hedgehog <> nil then HHGear:= Gear^.Hedgehog^.Gear
       
  5170 else HHGear:= nil;
       
  5171 
       
  5172 // creeper boom phase
       
  5173 if (Gear^.State and gstTmpFlag <> 0) then
       
  5174     begin
       
  5175     if (Gear^.Timer = 0) then
       
  5176         begin
       
  5177         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 300, CurrentHedgehog, EXPLAutoSound);
       
  5178         DeleteGear(Gear)
       
  5179         end;
       
  5180     // ssssss he essssscaped
       
  5181     if (Gear^.Timer > 250) and ((HHGear = nil) or 
       
  5182             (((abs(HHGear^.X.Round-Gear^.X.Round) + abs(HHGear^.Y.Round-Gear^.Y.Round) + 2) >  180) and
       
  5183             (Distance(HHGear^.X-Gear^.X,HHGear^.Y-Gear^.Y) > _180))) then
       
  5184         begin
       
  5185         Gear^.State:= Gear^.State and (not gstTmpFlag);
       
  5186         Gear^.Timer:= 0
       
  5187         end;
       
  5188     exit
       
  5189     end;
       
  5190 
       
  5191 // Search out a new target, as target seek time has expired, target is dead, target is out of range, or we didn't have a target
       
  5192 if (HHGear = nil) or (Gear^.Timer = 0) or 
       
  5193    (((abs(HHGear^.X.Round-Gear^.X.Round) + abs(HHGear^.Y.Round-Gear^.Y.Round) + 2) >  Gear^.Angle) and
       
  5194         (Distance(HHGear^.X-Gear^.X,HHGear^.Y-Gear^.Y) > int2hwFloat(Gear^.Angle)))
       
  5195     then
       
  5196     begin
       
  5197     hogs := GearsNear(Gear^.X, Gear^.Y, gtHedgehog, Gear^.Angle);
       
  5198     if hogs.size > 1 then
       
  5199         Gear^.Hedgehog:= hogs.ar^[GetRandom(hogs.size)]^.Hedgehog
       
  5200     else if hogs.size = 1 then Gear^.Hedgehog:= hogs.ar^[0]^.Hedgehog
       
  5201     else Gear^.Hedgehog:= nil;
       
  5202     if Gear^.Hedgehog <> nil then Gear^.Timer:= 5000;
       
  5203     exit
       
  5204     end;
       
  5205 
       
  5206 // we have a target. move the creeper.
       
  5207 if HHGear <> nil then
       
  5208     begin
       
  5209     // GOTCHA
       
  5210     if ((abs(HHGear^.X.Round-Gear^.X.Round) + abs(HHGear^.Y.Round-Gear^.Y.Round) + 2) <  50) and
       
  5211          (Distance(HHGear^.X-Gear^.X,HHGear^.Y-Gear^.Y) < _50) then
       
  5212         begin
       
  5213         // hisssssssssss
       
  5214         Gear^.State:= Gear^.State or gstTmpFlag;
       
  5215         Gear^.Timer:= 1500;
       
  5216         exit
       
  5217         end;
       
  5218     if (Gear^.State and gstMoving <> 0) then
       
  5219         begin
       
  5220         Gear^.dY:= _0;
       
  5221         Gear^.dX:= _0;
       
  5222         end
       
  5223     else if (GameTicks and $FF = 0) then
       
  5224         begin
       
  5225         tdX:= HHGear^.X-Gear^.X;
       
  5226         dir:= hwSign(tdX);
       
  5227         if not TestCollisionX(Gear, dir) then
       
  5228             Gear^.X:= Gear^.X + signAs(_1,tdX);
       
  5229         if TestCollisionXwithXYShift(Gear, signAs(_10,tdX), 0, dir) then
       
  5230             begin
       
  5231             Gear^.dX:= SignAs(_0_15, tdX);
       
  5232             Gear^.dY:= -_0_3;
       
  5233             Gear^.State:= Gear^.State or gstMoving
       
  5234             end
       
  5235         end;
       
  5236     end;
       
  5237 end;