hedgewars/uCollisions.pas
changeset 5569 8313952b2811
parent 5568 badaac85f9d4
child 5572 47cc28299baa
equal deleted inserted replaced
5568:badaac85f9d4 5569:8313952b2811
    51 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean;
    51 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean;
    52 
    52 
    53 function  calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
    53 function  calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
    54 
    54 
    55 implementation
    55 implementation
    56 uses uConsts, uLandGraphics, uVariables, uDebug;
    56 uses uConsts, uLandGraphics, uVariables, uDebug, uGears;
    57 
    57 
    58 type TCollisionEntry = record
    58 type TCollisionEntry = record
    59             X, Y, Radius: LongInt;
    59             X, Y, Radius: LongInt;
    60             cGear: PGear;
    60             cGear: PGear;
    61             end;
    61             end;
    64 var Count: Longword;
    64 var Count: Longword;
    65     cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry;
    65     cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry;
    66     ga: TGearArray;
    66     ga: TGearArray;
    67 
    67 
    68 procedure AddGearCI(Gear: PGear);
    68 procedure AddGearCI(Gear: PGear);
       
    69 var t: PGear;
    69 begin
    70 begin
    70 if Gear^.CollisionIndex >= 0 then exit;
    71 if Gear^.CollisionIndex >= 0 then exit;
    71 TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true);
    72 TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true);
    72 with cinfos[Count] do
    73 with cinfos[Count] do
    73     begin
    74     begin
    76     Radius:= Gear^.Radius;
    77     Radius:= Gear^.Radius;
    77     ChangeRoundInLand(X, Y, Radius - 1, true);
    78     ChangeRoundInLand(X, Y, Radius - 1, true);
    78     cGear:= Gear
    79     cGear:= Gear
    79     end;
    80     end;
    80 Gear^.CollisionIndex:= Count;
    81 Gear^.CollisionIndex:= Count;
    81 inc(Count)
    82 inc(Count);
       
    83 // mines are the easiest way to overflow collision
       
    84 if (Count > (MAXRECTSINDEX-20)) then
       
    85     begin
       
    86     t:= GearsList;
       
    87     while (t <> nil) and (t^.Kind <> gtMine) do t:= t^.NextGear;
       
    88     if (t <> nil) and (t^.Kind = gtMine) then DeleteGear(t)
       
    89     end;
    82 end;
    90 end;
    83 
    91 
    84 procedure DeleteCI(Gear: PGear);
    92 procedure DeleteCI(Gear: PGear);
    85 begin
    93 begin
    86 if Gear^.CollisionIndex >= 0 then
    94 if Gear^.CollisionIndex >= 0 then