hedgewars/uGears.pas
changeset 1753 2ccba26f1aa4
parent 1738 00e8dadce69a
child 1760 55a1edd97911
equal deleted inserted replaced
1752:769986d39202 1753:2ccba26f1aa4
  1178 
  1178 
  1179 if (GameFlags and gfForts) = 0 then
  1179 if (GameFlags and gfForts) = 0 then
  1180 	for i:= 0 to Pred(cLandAdditions) do
  1180 	for i:= 0 to Pred(cLandAdditions) do
  1181 		begin
  1181 		begin
  1182 		Gear:= AddGear(0, 0, gtMine, 0, _0, _0, 0);
  1182 		Gear:= AddGear(0, 0, gtMine, 0, _0, _0, 0);
  1183 		FindPlace(Gear, false, 0, 2048)
  1183 		FindPlace(Gear, false, 0, LAND_WIDTH+1)
  1184 		end
  1184 		end
  1185 end;
  1185 end;
  1186 
  1186 
  1187 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord);
  1187 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord);
  1188 var Gear: PGear;
  1188 var Gear: PGear;
  1369 		end;
  1369 		end;
  1370 
  1370 
  1371 	while (Count > 0) do
  1371 	while (Count > 0) do
  1372 		begin
  1372 		begin
  1373 		i:= GetRandom(Count);
  1373 		i:= GetRandom(Count);
  1374 		FindPlace(ar[i]^.Gear, false, 0, 2048);
  1374 		FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH+1);
  1375 		if ar[i]^.Gear <> nil then
  1375 		if ar[i]^.Gear <> nil then
  1376 			begin
  1376 			begin
  1377 			ar[i]^.Gear^.dX.isNegative:= ar[i]^.Gear^.X > _1024;
  1377 			ar[i]^.Gear^.dX.isNegative:= ar[i]^.Gear^.X > _4096; // LAND_WIDTH
  1378 			ar[i]^.Gear^.Pos:= GetRandom(19);
  1378 			ar[i]^.Gear^.Pos:= GetRandom(19);
  1379 			ar[i]:= ar[Count - 1]
  1379 			ar[i]:= ar[Count - 1]
  1380 			end;
  1380 			end;
  1381 		dec(Count)
  1381 		dec(Count)
  1382 		end
  1382 		end
  1480         PlaySound(sndReinforce, false, CurrentTeam^.voicepack);
  1480         PlaySound(sndReinforce, false, CurrentTeam^.voicepack);
  1481         FollowGear^.Pos:= posCaseAmmo;
  1481         FollowGear^.Pos:= posCaseAmmo;
  1482         FollowGear^.State:= Longword(i)
  1482         FollowGear^.State:= Longword(i)
  1483         end;
  1483         end;
  1484      end;
  1484      end;
  1485 FindPlace(FollowGear, true, 0, 2048)
  1485 FindPlace(FollowGear, true, 0, 4096)
  1486 end;
  1486 end;
  1487 
  1487 
  1488 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
  1488 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
  1489 
  1489 
  1490 	function CountNonZeroz(x, y, r: LongInt): LongInt;
  1490 	function CountNonZeroz(x, y, r: LongInt): LongInt;
  1491 	var i: LongInt;
  1491 	var i: LongInt;
  1492 		Result: LongInt;
  1492 		Result: LongInt;
  1493 	begin
  1493 	begin
  1494 	Result:= 0;
  1494 	Result:= 0;
  1495 	if (y and $FFFFFC00) = 0 then
  1495 	if (y and LAND_HEIGHT_MASK) = 0 then
  1496 		for i:= max(x - r, 0) to min(x + r, 2043) do
  1496 		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH-4) do
  1497 			if Land[y, i] <> 0 then inc(Result);
  1497 			if Land[y, i] <> 0 then inc(Result);
  1498 	CountNonZeroz:= Result
  1498 	CountNonZeroz:= Result
  1499 	end;
  1499 	end;
  1500 
  1500 
  1501 var x: LongInt;
  1501 var x: LongInt;
  1511 	x:= Left + LongInt(GetRandom(Delta));
  1511 	x:= Left + LongInt(GetRandom(Delta));
  1512 	repeat
  1512 	repeat
  1513 		inc(x, Delta);
  1513 		inc(x, Delta);
  1514 		cnt:= 0;
  1514 		cnt:= 0;
  1515 		y:= -Gear^.Radius * 2;
  1515 		y:= -Gear^.Radius * 2;
  1516 		while y < 1023 do
  1516 		while y < LAND_HEIGHT do
  1517 			begin
  1517 			begin
  1518 			repeat
  1518 			repeat
  1519 				inc(y, 2);
  1519 				inc(y, 2);
  1520 			until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0);
  1520 			until (y > LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0);
  1521 			
  1521 			
  1522 			sy:= y;
  1522 			sy:= y;
  1523 
  1523 
  1524 			repeat
  1524 			repeat
  1525 				inc(y);
  1525 				inc(y);
  1526 			until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0);
  1526 			until (y > LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0);
  1527 			
  1527 			
  1528 			if (y - sy > Gear^.Radius * 2)
  1528 			if (y - sy > Gear^.Radius * 2)
  1529 				and (y < 1023)
  1529 				and (y < LAND_HEIGHT)
  1530 				and (CheckGearsNear(x, y - Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then
  1530 				and (CheckGearsNear(x, y - Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then
  1531 				begin
  1531 				begin
  1532 				ar[cnt].X:= x;
  1532 				ar[cnt].X:= x;
  1533 				if withFall then ar[cnt].Y:= sy + Gear^.Radius
  1533 				if withFall then ar[cnt].Y:= sy + Gear^.Radius
  1534 							else ar[cnt].Y:= y - Gear^.Radius;
  1534 							else ar[cnt].Y:= y - Gear^.Radius;