hedgewars/GSHandlers.inc
changeset 2941 566f967ec22f
parent 2939 58d811e0d41c
child 2944 e8a891bf6660
equal deleted inserted replaced
2940:c02119eee12a 2941:566f967ec22f
  1237 	end;
  1237 	end;
  1238 dec(Gear^.Timer);
  1238 dec(Gear^.Timer);
  1239 end;
  1239 end;
  1240 
  1240 
  1241 ///////////////////////////////////////////////////////////////////////////////
  1241 ///////////////////////////////////////////////////////////////////////////////
       
  1242 
       
  1243 (*
       
  1244 TODO
       
  1245 Increase damage as barrel smokes?
       
  1246 Try tweaking friction some more
       
  1247 *)
       
  1248 procedure doStepRollingBarrel(Gear: PGear);
       
  1249 var i: LongInt;
       
  1250 	particle: PVisualGear;
       
  1251 begin
       
  1252 Gear^.State:= Gear^.State or gstAnimation;
       
  1253 if ((Gear^.dX.QWordValue <> 0) or (Gear^.dY.QWordValue <> 0))  then
       
  1254     begin
       
  1255     DeleteCI(Gear);
       
  1256     AllInactive:= false;
       
  1257     if Gear^.dY.isNegative and (Gear^.dY < -_0_02) and TestCollisionYwithGear(Gear, -1) then
       
  1258         inc(Gear^.Damage, hwRound(Gear^.dY * _70) * -1);
       
  1259     if not Gear^.dY.isNegative and (Gear^.dY > _0_02) and TestCollisionYwithGear(Gear, 1) then
       
  1260         begin
       
  1261         inc(Gear^.Damage, hwRound(Gear^.dY * _70));
       
  1262 	    for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do 
       
  1263             begin
       
  1264 		    particle:= AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
       
  1265             if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX / 5)
       
  1266             end
       
  1267         end;
       
  1268     if Gear^.dX.isNegative and (Gear^.dX < -_0_02) and TestCollisionXwithGear(Gear, -1) then
       
  1269         inc(Gear^.Damage, hwRound(Gear^.dX * _70)*-1);
       
  1270     if not Gear^.dX.isNegative and (Gear^.dX > _0_02) and TestCollisionYwithGear(Gear, 1) then
       
  1271         inc(Gear^.Damage, hwRound(Gear^.dX * _70));
       
  1272     if Gear^.Damage <> 0 then PlaySound(sndGraveImpact);
       
  1273     doStepFallingGear(Gear);
       
  1274     CalcRotationDirAngle(Gear);
       
  1275 	CheckGearDrowning(Gear)
       
  1276     end
       
  1277 else AddGearCI(Gear);
       
  1278     
       
  1279 if ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then
       
  1280     if (cBarrelHealth div Gear^.Health) > 2 then 
       
  1281         AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmoke)
       
  1282     else
       
  1283         AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmokeWhite);
       
  1284 dec(Gear^.Health, Gear^.Damage);
       
  1285 Gear^.Damage:= 0;
       
  1286 if Gear^.Health <= 0 then Gear^.doStep:= @doStepCase; // Hand off to doStepCase for the explosion
       
  1287 
       
  1288 end;
       
  1289 
  1242 procedure doStepCase(Gear: PGear);
  1290 procedure doStepCase(Gear: PGear);
  1243 var i, x, y: LongInt;
  1291 var i, x, y: LongInt;
  1244 	k: TGearType;
  1292 	k: TGearType;
  1245 	exBoom: boolean;
  1293 	exBoom: boolean;
  1246 	dX, dY, V: HWFloat;
  1294 	dX, dY: HWFloat;
  1247 begin
  1295 begin
  1248 k:= Gear^.Kind;
  1296 k:= Gear^.Kind;
  1249 exBoom:= false;
  1297 exBoom:= false;
  1250 V:= _0;
       
  1251 
  1298 
  1252 if (Gear^.Message and gm_Destroy) > 0 then
  1299 if (Gear^.Message and gm_Destroy) > 0 then
  1253 	begin
  1300 	begin
  1254 	DeleteGear(Gear);
  1301 	DeleteGear(Gear);
  1255 	FreeActionsList;
  1302 	FreeActionsList;
  1259 	exit
  1306 	exit
  1260 	end;
  1307 	end;
  1261 
  1308 
  1262 if k = gtExplosives then
  1309 if k = gtExplosives then
  1263 	begin
  1310 	begin
  1264     V:= hwSqr(Gear^.dX) + hwSqr(Gear^.dY);
       
  1265     //if V > _0_03 then Gear^.State:= Gear^.State or gstAnimation;
  1311     //if V > _0_03 then Gear^.State:= Gear^.State or gstAnimation;
  1266     if hwAbs(Gear^.dX) > _0_15 then Gear^.State:= Gear^.State or gstAnimation;
  1312     if hwAbs(Gear^.dX) > _0_15 then Gear^.doStep:= @doStepRollingBarrel;
  1267     if ((Gear^.State and gstAnimation) <> 0) and ((Gear^.dX.QWordValue <> 0) or (Gear^.dY.QWordValue <> 0))  then
       
  1268         begin
       
  1269         AllInactive:= false;
       
  1270         doStepFallingGear(Gear);
       
  1271         CalcRotationDirAngle(Gear)
       
  1272         end;
       
  1273     
  1313     
  1274 	if ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then
  1314     if ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then
  1275 		AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmoke);
  1315         if (cBarrelHealth div Gear^.Health) > 2 then 
       
  1316             AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmoke)
       
  1317         else
       
  1318             AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmokeWhite);
  1276 	dec(Gear^.Health, Gear^.Damage);
  1319 	dec(Gear^.Health, Gear^.Damage);
  1277 	Gear^.Damage:= 0;
  1320 	Gear^.Damage:= 0;
  1278 	if Gear^.Health <= 0 then
  1321 	if Gear^.Health <= 0 then
  1279 		exBoom:= true;
  1322 		exBoom:= true;
  1280 	end;
  1323 	end;
  1281 if ((Gear^.State and gstAnimation) = 0) or (hwAbs(Gear^.dX) < _0_001) then Gear^.dX:= _0;
       
  1282 
  1324 
  1283 if (Gear^.Damage > 0) or exBoom then
  1325 if (Gear^.Damage > 0) or exBoom then
  1284 	begin
  1326 	begin
  1285 	x:= hwRound(Gear^.X);
  1327 	x:= hwRound(Gear^.X);
  1286 	y:= hwRound(Gear^.Y);
  1328 	y:= hwRound(Gear^.Y);
  1307 	end;
  1349 	end;
  1308 
  1350 
  1309 if (Gear^.dY.QWordValue <> 0) or (not TestCollisionYwithGear(Gear, 1)) then
  1351 if (Gear^.dY.QWordValue <> 0) or (not TestCollisionYwithGear(Gear, 1)) then
  1310 	begin
  1352 	begin
  1311 	AllInactive:= false;
  1353 	AllInactive:= false;
  1312     if not ((k = gtExplosives) and ((Gear^.State and gstAnimation) <> 0)) then
  1354     Gear^.dY:= Gear^.dY + cGravity;
  1313         begin
  1355     Gear^.Y:= Gear^.Y + Gear^.dY;
  1314         Gear^.dY:= Gear^.dY + cGravity;
       
  1315         Gear^.Y:= Gear^.Y + Gear^.dY;
       
  1316 	    if (Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0
       
  1317         end;
       
  1318     if (not Gear^.dY.isNegative) and (Gear^.dY > _0_001) then SetAllHHToActive;
  1356     if (not Gear^.dY.isNegative) and (Gear^.dY > _0_001) then SetAllHHToActive;
       
  1357 	if (Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0;
  1319 	if (not Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, 1) then
  1358 	if (not Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, 1) then
  1320 		begin
  1359 		begin
  1321         if (V > _0_02) and (k = gtExplosives) then
  1360         if (Gear^.dY > _0_02) and (k = gtExplosives) then
  1322             inc(Gear^.Damage, hwRound(V * _70));
  1361             inc(Gear^.Damage, hwRound(Gear^.dY * _70));
  1323 
  1362 
  1324 		if Gear^.dY > _0_2 then
  1363 		if Gear^.dY > _0_2 then
  1325 	        for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do 
  1364 	        for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do 
  1326 		        AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
  1365 		        AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
  1327 		Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
  1366 		Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
  1330 		end;
  1369 		end;
  1331 	//if Gear^.dY > - _0_001 then Gear^.dY:= _0
  1370 	//if Gear^.dY > - _0_001 then Gear^.dY:= _0
  1332 	CheckGearDrowning(Gear);
  1371 	CheckGearDrowning(Gear);
  1333 	end;
  1372 	end;
  1334 
  1373 
  1335 if (Gear^.dX.QWordValue = 0) and (Gear^.dY.QWordValue = 0) then AddGearCI(Gear)
  1374 if (Gear^.dY.QWordValue = 0) then AddGearCI(Gear)
  1336 	else DeleteCI(Gear)
  1375        else if (Gear^.dY.QWordValue <> 0) then DeleteCI(Gear)
  1337 end;
  1376 end;
  1338 
  1377 
  1339 ////////////////////////////////////////////////////////////////////////////////
  1378 ////////////////////////////////////////////////////////////////////////////////
  1340 
  1379 
  1341 procedure doStepTarget(Gear: PGear);
  1380 procedure doStepTarget(Gear: PGear);