hedgewars/uGearsHandlersMess.pas
changeset 15986 7125918637e9
parent 15938 4c0f8dbf6c13
child 16004 2146cb7be36f
equal deleted inserted replaced
15985:a4630009e733 15986:7125918637e9
  6408 *)
  6408 *)
  6409 
  6409 
  6410 procedure doStepTardisWarp(Gear: PGear);
  6410 procedure doStepTardisWarp(Gear: PGear);
  6411 var HH: PHedgehog;
  6411 var HH: PHedgehog;
  6412     i,j,cnt: LongWord;
  6412     i,j,cnt: LongWord;
       
  6413     restoreBottomY: LongInt;
  6413     s: ansistring;
  6414     s: ansistring;
  6414 begin
  6415 begin
  6415 HH:= Gear^.Hedgehog;
  6416 HH:= Gear^.Hedgehog;
  6416 if Gear^.Tag = 0 then
  6417 if Gear^.Tag = 0 then
  6417     begin
  6418     begin
  6504                 and ((Hedgehogs[i].Gear^.State and gstDrowning) = 0)
  6505                 and ((Hedgehogs[i].Gear^.State and gstDrowning) = 0)
  6505                 and (Hedgehogs[i].Gear^.Health > Hedgehogs[i].Gear^.Damage) then
  6506                 and (Hedgehogs[i].Gear^.Health > Hedgehogs[i].Gear^.Damage) then
  6506                     inc(cnt);
  6507                     inc(cnt);
  6507     if (cnt = 0) or SuddenDeathDmg or (Gear^.Timer = 0) then
  6508     if (cnt = 0) or SuddenDeathDmg or (Gear^.Timer = 0) then
  6508         begin
  6509         begin
       
  6510         // Place tardis
  6509         if HH^.GearHidden <> nil then
  6511         if HH^.GearHidden <> nil then
  6510             FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH, true, false);
  6512             begin
       
  6513             restoreBottomY:= cWaterLine;
       
  6514             // Place tardis at a random safe position
       
  6515             FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH, restoreBottomY, true, false);
       
  6516 
       
  6517             // If in Sudden Death, rise the minimum possible spawn position to make
       
  6518             // it less likely for the hog to drown before its turn
       
  6519             if SuddenDeathActive and (cWaterRise > 0) then
       
  6520                 begin
       
  6521                 // Enough space to survive the water rise of 1 round.
       
  6522                 // Also limit the highest spawn height to topY plus a small buffer zone
       
  6523                 restoreBottomY:= max(topY + cHHRadius * 5, cWaterLine - cWaterRise * (TeamsCount + 1));
       
  6524                 // If gear is below the safe spawn height, place it again,
       
  6525                 // but this time with the height limit in place
       
  6526                 if (HH^.GearHidden <> nil) and (hwRound(HH^.GearHidden^.Y) > restoreBottomY) then
       
  6527                     // Due to the reduced Y range, this one might fail for very aggressive SD water rise
       
  6528                     begin
       
  6529                     FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH, restoreBottomY, true, false);
       
  6530                     end;
       
  6531                 // Still unsafe? Relax the height limit to a third of the map height above cWaterLine
       
  6532                 if (HH^.GearHidden <> nil) and (hwRound(HH^.GearHidden^.Y) > restoreBottomY) then
       
  6533                     begin
       
  6534                     restoreBottomY:= cWaterLine - ((cWaterLine - topY) div 3);
       
  6535                     // Even this might fail, but it's much less likely. If it fails, we still have the
       
  6536                     // position of the first FindPlace as a fallback.
       
  6537                     FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH, restoreBottomY, true, false);
       
  6538                     end;
       
  6539                 end;
       
  6540             end;
  6511 
  6541 
  6512         if HH^.GearHidden <> nil then
  6542         if HH^.GearHidden <> nil then
  6513             begin
  6543             begin
  6514             Gear^.X:= HH^.GearHidden^.X;
  6544             Gear^.X:= HH^.GearHidden^.X;
  6515             Gear^.Y:= HH^.GearHidden^.Y;
  6545             Gear^.Y:= HH^.GearHidden^.Y;