hedgewars/uGearsUtils.pas
changeset 15181 d13a38548112
parent 15178 d3998dcc076f
child 15195 7d41e7889123
equal deleted inserted replaced
15180:061a3085d6d8 15181:d13a38548112
   310                 end;
   310                 end;
   311             end;
   311             end;
   312 
   312 
   313         uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);
   313         uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);
   314 
   314 
   315 	if AprilOne and (Gear^.Hedgehog^.Hat = 'fr_tomato') and (Damage > 2) then
   315     if AprilOne and (Gear^.Hedgehog^.Hat = 'fr_tomato') and (Damage > 2) then
   316 	    for i := 0 to random(min(Damage,20))+5 do
   316         for i := 0 to random(min(Damage,20))+5 do
   317 		begin
   317         begin
   318 		vg:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot);
   318         vg:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot);
   319 		if vg <> nil then
   319         if vg <> nil then
   320 		    with vg^ do
   320             with vg^ do
   321 			begin
   321             begin
   322 			dx:= 0.001 * (random(100)+10);
   322             dx:= 0.001 * (random(100)+10);
   323 			dy:= 0.001 * (random(100)+10);
   323             dy:= 0.001 * (random(100)+10);
   324 			tdy:= -cGravityf;
   324             tdy:= -cGravityf;
   325 			if random(2) = 0 then
   325             if random(2) = 0 then
   326 			    dx := -dx;
   326                 dx := -dx;
   327 			FrameTicks:= random(500) + 1000;
   327             FrameTicks:= random(500) + 1000;
   328 			State:= ord(sprBubbles);
   328             State:= ord(sprBubbles);
   329 			Tint:= $ff0000ff
   329             Tint:= $ff0000ff
   330 			end
   330             end
   331 	end
   331     end
   332     end else
   332     end else
   333         Gear^.Hedgehog:= AttackerHog;
   333         Gear^.Hedgehog:= AttackerHog;
   334     inc(Gear^.Damage, Damage);
   334     inc(Gear^.Damage, Damage);
   335 
   335 
   336     ScriptCall('onGearDamage', Gear^.UID, Damage);
   336     ScriptCall('onGearDamage', Gear^.UID, Damage);
  1058 
  1058 
  1059 function CheckGearNearImpl(Kind: TGearType; X, Y: hwFloat; rX, rY: LongInt; exclude: PGear): PGear;
  1059 function CheckGearNearImpl(Kind: TGearType; X, Y: hwFloat; rX, rY: LongInt; exclude: PGear): PGear;
  1060 var t: PGear;
  1060 var t: PGear;
  1061     width, bound, dX, dY: hwFloat;
  1061     width, bound, dX, dY: hwFloat;
  1062     isHit: Boolean;
  1062     isHit: Boolean;
  1063 begin
  1063     i, j: LongWord;
  1064     t:= GearsList;
  1064 begin
  1065     bound:= _1_5 * int2hwFloat(max(rX, rY));
  1065     bound:= _1_5 * int2hwFloat(max(rX, rY));
  1066     rX:= sqr(rX);
  1066     rX:= sqr(rX);
  1067     rY:= sqr(rY);
  1067     rY:= sqr(rY);
  1068     width:= int2hwFloat(RightX - LeftX);
  1068     width:= int2hwFloat(RightX - LeftX);
  1069 
  1069     if (Kind = gtHedgehog) then
  1070     while t <> nil do
  1070         begin
  1071     begin
  1071         for j:= 0 to Pred(TeamsCount) do
  1072         if (t <> exclude) and (t^.Kind = Kind) then
  1072             if TeamsArray[j]^.TeamHealth > 0 then // it's impossible for a team to have hogs in game and zero health right?
  1073         begin
  1073                 with TeamsArray[j]^ do
  1074             dX := X - t^.X;
  1074                     for i:= 0 to cMaxHHIndex do
  1075             dY := Y - t^.Y;
  1075                         with Hedgehogs[i] do
  1076             isHit := (hwAbs(dX) + hwAbs(dY) < bound)
  1076                             if (Gear <> nil) and (Gear <> exclude) then
  1077                 and (not ((hwSqr(dX) / rX + hwSqr(dY) / rY) > _1));
  1077                                 begin
  1078 
  1078                                 // code duplication - could throw into an inline function I guess
  1079             if (not isHit) and (WorldEdge = weWrap) then
  1079                                 dX := X - Gear^.X;
  1080             begin
  1080                                 dY := Y - Gear^.Y;
  1081                 if (hwAbs(dX - width) + hwAbs(dY) < bound)
  1081                                 isHit := (hwAbs(dX) + hwAbs(dY) < bound)
  1082                     and (not ((hwSqr(dX - width) / rX + hwSqr(dY) / rY) > _1)) then
  1082                                     and (not ((hwSqr(dX) / rX + hwSqr(dY) / rY) > _1));
  1083                     isHit := true
  1083 
  1084                 else if (hwAbs(dX + width) + hwAbs(dY) < bound)
  1084                                 if (not isHit) and (WorldEdge = weWrap) then
  1085                     and (not ((hwSqr(dX + width) / rX + hwSqr(dY) / rY) > _1)) then
  1085                                     begin
  1086                     isHit := true
  1086                                     if (hwAbs(dX - width) + hwAbs(dY) < bound)
  1087             end;
  1087                                         and (not ((hwSqr(dX - width) / rX + hwSqr(dY) / rY) > _1)) then
  1088 
  1088                                         isHit := true
  1089             if isHit then
  1089                                     else if (hwAbs(dX + width) + hwAbs(dY) < bound)
  1090             begin
  1090                                         and (not ((hwSqr(dX + width) / rX + hwSqr(dY) / rY) > _1)) then
  1091                 CheckGearNearImpl:= t;
  1091                                         isHit := true
  1092                 exit;
  1092                                     end;
  1093             end;
  1093 
  1094         end;
  1094                                 if isHit then
  1095         t:= t^.NextGear
  1095                                     begin
       
  1096                                     CheckGearNearImpl:= Gear;
       
  1097                                     exit;
       
  1098                                     end
       
  1099                                 end;
       
  1100         end
       
  1101     else
       
  1102         begin
       
  1103         t:= GearsList;
       
  1104 
       
  1105         while t <> nil do
       
  1106             begin
       
  1107             if (t <> exclude) and (t^.Kind = Kind) then
       
  1108                 begin
       
  1109                 dX := X - t^.X;
       
  1110                 dY := Y - t^.Y;
       
  1111                 isHit := (hwAbs(dX) + hwAbs(dY) < bound)
       
  1112                     and (not ((hwSqr(dX) / rX + hwSqr(dY) / rY) > _1));
       
  1113 
       
  1114                 if (not isHit) and (WorldEdge = weWrap) then
       
  1115                     begin
       
  1116                     if (hwAbs(dX - width) + hwAbs(dY) < bound)
       
  1117                         and (not ((hwSqr(dX - width) / rX + hwSqr(dY) / rY) > _1)) then
       
  1118                         isHit := true
       
  1119                     else if (hwAbs(dX + width) + hwAbs(dY) < bound)
       
  1120                         and (not ((hwSqr(dX + width) / rX + hwSqr(dY) / rY) > _1)) then
       
  1121                         isHit := true
       
  1122                     end;
       
  1123 
       
  1124                 if isHit then
       
  1125                     begin
       
  1126                     CheckGearNearImpl:= t;
       
  1127                     exit;
       
  1128                     end;
       
  1129                 end;
       
  1130             t:= t^.NextGear
       
  1131             end
  1096     end;
  1132     end;
  1097 
  1133 
  1098     CheckGearNearImpl:= nil
  1134     CheckGearNearImpl:= nil
  1099 end;
  1135 end;
  1100 
  1136