hedgewars/GSHandlers.inc
changeset 2933 02af54eb7e1e
parent 2932 9bc0cf3c7ac1
child 2934 e0f2b0f97c2b
equal deleted inserted replaced
2932:9bc0cf3c7ac1 2933:02af54eb7e1e
  1241 ///////////////////////////////////////////////////////////////////////////////
  1241 ///////////////////////////////////////////////////////////////////////////////
  1242 procedure doStepCase(Gear: PGear);
  1242 procedure doStepCase(Gear: PGear);
  1243 var i, x, y: LongInt;
  1243 var i, x, y: LongInt;
  1244 	k: TGearType;
  1244 	k: TGearType;
  1245 	exBoom: boolean;
  1245 	exBoom: boolean;
  1246 	dX, dY: HWFloat;
  1246 	dX, dY, V: HWFloat;
  1247 begin
  1247 begin
       
  1248 k:= Gear^.Kind;
  1248 exBoom:= false;
  1249 exBoom:= false;
       
  1250 V:= _0;
  1249 
  1251 
  1250 if (Gear^.Message and gm_Destroy) > 0 then
  1252 if (Gear^.Message and gm_Destroy) > 0 then
  1251 	begin
  1253 	begin
  1252 	DeleteGear(Gear);
  1254 	DeleteGear(Gear);
  1253 	FreeActionsList;
  1255 	FreeActionsList;
  1255 	with CurrentHedgehog^ do
  1257 	with CurrentHedgehog^ do
  1256 		if Gear <> nil then Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
  1258 		if Gear <> nil then Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
  1257 	exit
  1259 	exit
  1258 	end;
  1260 	end;
  1259 
  1261 
  1260 if Gear^.Kind = gtExplosives then
  1262 if k = gtExplosives then
  1261 	begin
  1263 	begin
       
  1264     V:= hwSqr(Gear^.dX) + hwSqr(Gear^.dY);
       
  1265     if V > _0_03 then Gear^.State:= Gear^.State or gstAnimation;
       
  1266     if ((Gear^.State and gstAnimation) <> 0) and (Gear^.dX.QWordValue <> 0) and (Gear^.dY.QWordValue <> 0)  then
       
  1267         begin
       
  1268         AllInactive:= false;
       
  1269         doStepFallingGear(Gear);
       
  1270         CalcRotationDirAngle(Gear)
       
  1271         end;
       
  1272 	if V < _0_001 then Gear^.dX:= _0;
       
  1273     
  1262 	if ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then
  1274 	if ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then
  1263 		AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmoke);
  1275 		AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmoke);
  1264 	dec(Gear^.Health, Gear^.Damage);
  1276 	dec(Gear^.Health, Gear^.Damage);
  1265 	Gear^.Damage:= 0;
  1277 	Gear^.Damage:= 0;
  1266 	if Gear^.Health <= 0 then
  1278 	if Gear^.Health <= 0 then
  1269 
  1281 
  1270 if (Gear^.Damage > 0) or exBoom then
  1282 if (Gear^.Damage > 0) or exBoom then
  1271 	begin
  1283 	begin
  1272 	x:= hwRound(Gear^.X);
  1284 	x:= hwRound(Gear^.X);
  1273 	y:= hwRound(Gear^.Y);
  1285 	y:= hwRound(Gear^.Y);
  1274 	k:= Gear^.Kind;
       
  1275 	DeleteGear(Gear); // <-- delete gear!
  1286 	DeleteGear(Gear); // <-- delete gear!
  1276 
  1287 
  1277 	if k = gtCase then
  1288 	if k = gtCase then
  1278 		begin
  1289 		begin
  1279 		doMakeExplosion(x, y, 25, EXPLAutoSound);
  1290 		doMakeExplosion(x, y, 25, EXPLAutoSound);
  1295 	end;
  1306 	end;
  1296 
  1307 
  1297 if (Gear^.dY.QWordValue <> 0) or (not TestCollisionYwithGear(Gear, 1)) then
  1308 if (Gear^.dY.QWordValue <> 0) or (not TestCollisionYwithGear(Gear, 1)) then
  1298 	begin
  1309 	begin
  1299 	AllInactive:= false;
  1310 	AllInactive:= false;
  1300 	Gear^.dY:= Gear^.dY + cGravity;
  1311     if not ((k = gtExplosives) and ((Gear^.State and gstAnimation) <> 0)) then
  1301 	Gear^.Y:= Gear^.Y + Gear^.dY;
  1312         begin
  1302     if (not Gear^.dY.isNegative) and (Gear^.Kind = gtExplosives) then SetAllHHToActive;
  1313         Gear^.dY:= Gear^.dY + cGravity;
  1303 	if (Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0 else
  1314         Gear^.Y:= Gear^.Y + Gear^.dY;
       
  1315 	    if (Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0
       
  1316         end;
       
  1317     if V > _0_001 then SetAllHHToActive;
  1304 	if (not Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, 1) then
  1318 	if (not Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, 1) then
  1305 		begin
  1319 		begin
       
  1320         if (V > _0_02) and (k = gtExplosives) and ((Gear^.State and gstAnimation) <> 0) then
       
  1321             inc(Gear^.Damage, hwRound(V * _70));
       
  1322 
  1306 		if Gear^.dY > _0_2 then
  1323 		if Gear^.dY > _0_2 then
  1307 	        for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do 
  1324 	        for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do 
  1308 		        AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
  1325 		        AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
  1309 		Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
  1326 		Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
  1310 		if Gear^.dY > - _0_001 then Gear^.dY:= _0
  1327 		if Gear^.dY > - _0_001 then Gear^.dY:= _0