hedgewars/GSHandlers.inc
changeset 6498 5678806aafca
parent 6491 736479f3d348
child 6507 e462a57f432e
equal deleted inserted replaced
6497:2359798a8dce 6498:5678806aafca
   195         isFalling := true;
   195         isFalling := true;
   196         land:= TestCollisionYwithGear(Gear, -1);
   196         land:= TestCollisionYwithGear(Gear, -1);
   197         if land <> 0 then
   197         if land <> 0 then
   198             begin
   198             begin
   199             collV := -1;
   199             collV := -1;
   200             if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_1 - (_1 - Gear^.Friction) / _10)
   200             if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
   201             else Gear^.dX := Gear^.dX * Gear^.Friction;
   201             else Gear^.dX := Gear^.dX * Gear^.Friction;
   202 
   202 
   203             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   203             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   204             Gear^.State := Gear^.State or gstCollision
   204             Gear^.State := Gear^.State or gstCollision
   205             end
   205             end
   206         else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then collV := 1;
   206         else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then collV := 1;
   207         end
   207         end
   208     else 
   208     else 
   209         begin
   209         begin // Gear^.dY.isNegative is false
   210         land:= TestCollisionYwithGear(Gear, 1);
   210         land:= TestCollisionYwithGear(Gear, 1);
   211         if land <> 0 then
   211         if land <> 0 then
   212             begin
   212             begin
   213             collV := 1;
   213             collV := 1;
   214             isFalling := false;
   214             isFalling := false;
   215             if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_1 - (_1 - Gear^.Friction) / _10)
   215             if land and lfIce <> 0 then 
   216             else Gear^.dX := Gear^.dX * Gear^.Friction;
   216                 Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
       
   217             else 
       
   218                 Gear^.dX := Gear^.dX * Gear^.Friction;
   217 
   219 
   218             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   220             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   219             Gear^.State := Gear^.State or gstCollision
   221             Gear^.State := Gear^.State or gstCollision
   220             end
   222             end
   221         else
   223         else
   222             begin
   224             begin
   223             isFalling := true;
   225             isFalling := true;
   224             if (Gear^.AdvBounce=1) and (not Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then
   226             if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, -1) <> 0) then
   225                 collV := -1
   227                 collV := -1
   226             end
   228             end
   227         end;
   229         end;
   228 
   230 
   229 
   231 
   259     Gear^.X := Gear^.X + Gear^.dX;
   261     Gear^.X := Gear^.X + Gear^.dX;
   260     Gear^.Y := Gear^.Y + Gear^.dY;
   262     Gear^.Y := Gear^.Y + Gear^.dY;
   261     if Gear^.Kind <> gtBee then
   263     if Gear^.Kind <> gtBee then
   262         CheckGearDrowning(Gear);
   264         CheckGearDrowning(Gear);
   263     //if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_0002) and
   265     //if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_0002) and
   264     if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) and
   266     if (not isFalling) and ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) then
   265        (not isFalling) then
       
   266         Gear^.State := Gear^.State and (not gstMoving)
   267         Gear^.State := Gear^.State and (not gstMoving)
   267     else
   268     else
   268         Gear^.State := Gear^.State or      gstMoving;
   269         Gear^.State := Gear^.State or      gstMoving;
   269 
   270 
   270     if (Gear^.nImpactSounds > 0) and 
   271     if (Gear^.nImpactSounds > 0) and 
   374                     end
   375                     end
   375                 end;
   376                 end;
   376         end;
   377         end;
   377     DeleteGear(Gear);
   378     DeleteGear(Gear);
   378     exit
   379     exit
   379 end;
   380     end;
   380 
   381 
   381 CalcRotationDirAngle(Gear);
   382     CalcRotationDirAngle(Gear);
   382 
   383 
   383 if Gear^.Kind = gtHellishBomb then
   384     if Gear^.Kind = gtHellishBomb then
   384 begin
   385     begin
   385 
   386 
   386     if Gear^.Timer = 3000 then
   387         if Gear^.Timer = 3000 then
   387     begin
   388         begin
   388         Gear^.nImpactSounds := 0;
   389             Gear^.nImpactSounds := 0;
   389         PlaySound(sndHellish);
   390             PlaySound(sndHellish);
   390     end;
   391         end;
   391 
   392 
   392     if (GameTicks and $3F) = 0 then
   393         if (GameTicks and $3F) = 0 then
   393         if (Gear^.State and gstCollision) = 0 then
   394             if (Gear^.State and gstCollision) = 0 then
   394             AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEvilTrace);
   395                 AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEvilTrace);
   395 end;
   396     end;
   396 end;
   397 end;
   397 
   398 
   398 ////////////////////////////////////////////////////////////////////////////////
   399 ////////////////////////////////////////////////////////////////////////////////
   399 procedure doStepMolotov(Gear: PGear);
   400 procedure doStepMolotov(Gear: PGear);
   400 var 
   401 var 
  1361     HHGear^.Y := HHGear^.Y + HHGear^.dY;
  1362     HHGear^.Y := HHGear^.Y + HHGear^.dY;
  1362     HHGear^.dY := HHGear^.dY + cGravity;
  1363     HHGear^.dY := HHGear^.dY + cGravity;
  1363     if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density;
  1364     if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density;
  1364 
  1365 
  1365     if (Gear^.Message and gmAttack) <> 0 then
  1366     if (Gear^.Message and gmAttack) <> 0 then
  1366     begin
  1367         begin
  1367         Gear^.X := HHGear^.X;
  1368         Gear^.X := HHGear^.X;
  1368         Gear^.Y := HHGear^.Y;
  1369         Gear^.Y := HHGear^.Y;
  1369 
  1370 
  1370         ApplyAngleBounds(Gear^.Hedgehog^, amRope);
  1371         ApplyAngleBounds(Gear^.Hedgehog^, amRope);
  1371 
  1372 
  1372         Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX);
  1373         Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX);
  1373         Gear^.dY := -AngleCos(HHGear^.Angle);
  1374         Gear^.dY := -AngleCos(HHGear^.Angle);
  1374         Gear^.Friction := _450 * _0_01 * cRopePercent;
  1375         Gear^.Friction := _4_5 * cRopePercent;
  1375         Gear^.Elasticity := _0;
  1376         Gear^.Elasticity := _0;
  1376         Gear^.State := Gear^.State and (not gsttmpflag);
  1377         Gear^.State := Gear^.State and (not gsttmpflag);
  1377         Gear^.doStep := @doStepRope;
  1378         Gear^.doStep := @doStepRope;
  1378     end
  1379         end
  1379 end;
  1380 end;
  1380 
  1381 
  1381 procedure RopeDeleteMe(Gear, HHGear: PGear);
  1382 procedure RopeDeleteMe(Gear, HHGear: PGear);
  1382 begin
  1383 begin
  1383     with HHGear^ do
  1384     with HHGear^ do
  1784             else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then
  1785             else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then
  1785                  inc(Gear^.Damage, hwRound(Gear^.dY * -_70))
  1786                  inc(Gear^.Damage, hwRound(Gear^.dY * -_70))
  1786             else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then
  1787             else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then
  1787                  inc(Gear^.Damage, hwRound(Gear^.dX * -_70));
  1788                  inc(Gear^.Damage, hwRound(Gear^.dX * -_70));
  1788         
  1789         
  1789         if (Gear^.Damage > random(30)) and ((GameTicks and $FF) = 0) then
  1790         if ((GameTicks and $FF) = 0) and (Gear^.Damage > random(30)) then
  1790             begin
  1791             begin
  1791             vg:= AddVisualGear(hwRound(Gear^.X) - 4  + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke);
  1792             vg:= AddVisualGear(hwRound(Gear^.X) - 4  + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke);
  1792             if vg <> nil then vg^.Scale:= 0.5
  1793             if vg <> nil then vg^.Scale:= 0.5
  1793             end;
  1794             end;
  1794 
  1795 
  1839 
  1840 
  1840 ////////////////////////////////////////////////////////////////////////////////
  1841 ////////////////////////////////////////////////////////////////////////////////
  1841 procedure doStepSMine(Gear: PGear);
  1842 procedure doStepSMine(Gear: PGear);
  1842 begin
  1843 begin
  1843     // TODO: do real calculation?
  1844     // TODO: do real calculation?
  1844     if TestCollisionXwithGear(Gear, 2) or (TestCollisionYwithGear(Gear, -2) <> 0) or TestCollisionXwithGear(Gear, -2) or (TestCollisionYwithGear(Gear, 2) <> 0) then
  1845     if TestCollisionXwithGear(Gear, 2) 
       
  1846         or (TestCollisionYwithGear(Gear, -2) <> 0) 
       
  1847         or TestCollisionXwithGear(Gear, -2) 
       
  1848         or (TestCollisionYwithGear(Gear, 2) <> 0) then
  1845     begin
  1849     begin
  1846         if (hwAbs(Gear^.dX) > _0) or (hwAbs(Gear^.dY) > _0) then
  1850         if (hwAbs(Gear^.dX) > _0) or (hwAbs(Gear^.dY) > _0) then
  1847         begin
  1851         begin
  1848             PlaySound(sndRopeAttach);
  1852             PlaySound(sndRopeAttach);
  1849             Gear^.dX:= _0;
  1853             Gear^.dX:= _0;
  1868                                                                                       gstAttacking
  1872                                                                                       gstAttacking
  1869         end
  1873         end
  1870         else // gstAttacking <> 0
  1874         else // gstAttacking <> 0
  1871         begin
  1875         begin
  1872             AllInactive := false;
  1876             AllInactive := false;
  1873             if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick);
       
  1874             if Gear^.Timer = 0 then
  1877             if Gear^.Timer = 0 then
  1875             begin
  1878             begin
  1876                 doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound);
  1879                 doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound);
  1877                 DeleteGear(Gear);
  1880                 DeleteGear(Gear);
  1878                 exit
  1881                 exit
  1879             end;
  1882             end else
       
  1883                 if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick);
       
  1884 
  1880             dec(Gear^.Timer);
  1885             dec(Gear^.Timer);
  1881         end
  1886         end
  1882     end
  1887     end
  1883     else // gsttmpFlag = 0
  1888     else // gsttmpFlag = 0
  1884         if (TurnTimeLeft = 0) or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) or (Gear^.Hedgehog^.Gear = nil) then Gear^.State := Gear^.State or gsttmpFlag;
  1889         if (TurnTimeLeft = 0) or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) or (Gear^.Hedgehog^.Gear = nil) then Gear^.State := Gear^.State or gsttmpFlag;