hedgewars/uGearsUtils.pas
changeset 7628 bc7b1d228a2c
parent 7627 e1e112687fd6
child 7719 eeae1cb6b6bf
equal deleted inserted replaced
7533:7ee319134713 7628:bc7b1d228a2c
    36 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt); inline;
    36 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt); inline;
    37 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
    37 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
    38 
    38 
    39 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
    39 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
    40 function  CheckGearDrowning(Gear: PGear): boolean;
    40 function  CheckGearDrowning(Gear: PGear): boolean;
       
    41 procedure CheckCollision(Gear: PGear); inline;
       
    42 procedure CheckCollisionWithLand(Gear: PGear); inline;
    41 
    43 
    42 var doStepHandlers: array[TGearType] of TGearStepProcedure;
    44 var doStepHandlers: array[TGearType] of TGearStepProcedure;
    43 
    45 
    44 
    46 
    45 implementation
    47 implementation
   104                 gtExplosives,
   106                 gtExplosives,
   105                 gtStructure: begin
   107                 gtStructure: begin
   106 // Run the calcs only once we know we have a type that will need damage
   108 // Run the calcs only once we know we have a type that will need damage
   107                         tdX:= Gear^.X-fX;
   109                         tdX:= Gear^.X-fX;
   108                         tdY:= Gear^.Y-fY;
   110                         tdY:= Gear^.Y-fY;
   109                         if hwRound(hwAbs(tdX)+hwAbs(tdY)) < dmgBase then
   111                         if (tdX.Round + tdY.Round + 2) < dmgBase then
   110                             dmg:= dmgBase - hwRound(Distance(tdX, tdY));
   112                             dmg:= dmgBase - hwRound(Distance(tdX, tdY));
   111                         if dmg > 1 then
   113                         if dmg > 1 then
   112                             begin
   114                             begin
   113                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
   115                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
   114                             //AddFileLog('Damage: ' + inttostr(dmg));
   116                             //AddFileLog('Damage: ' + inttostr(dmg));
   138                         end;
   140                         end;
   139                 gtGrave: begin
   141                 gtGrave: begin
   140 // Run the calcs only once we know we have a type that will need damage
   142 // Run the calcs only once we know we have a type that will need damage
   141                         tdX:= Gear^.X-fX;
   143                         tdX:= Gear^.X-fX;
   142                         tdY:= Gear^.Y-fY;
   144                         tdY:= Gear^.Y-fY;
   143                         if hwRound(hwAbs(tdX)+hwAbs(tdY)) < dmgBase then
   145                         if (tdX.Round + tdY.Round + 2) < dmgBase then
   144                             dmg:= dmgBase - hwRound(Distance(tdX, tdY));
   146                             dmg:= dmgBase - hwRound(Distance(tdX, tdY));
   145                         if dmg > 1 then
   147                         if dmg > 1 then
   146                             begin
   148                             begin
   147                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
   149                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
   148                             Gear^.dY:= - _0_004 * dmg;
   150                             Gear^.dY:= - _0_004 * dmg;
   237             end;
   239             end;
   238         uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);    
   240         uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);    
   239         end;
   241         end;
   240     end
   242     end
   241     else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure
   243     else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure
   242         begin
       
   243         Gear^.Hedgehog:= AttackerHog;
   244         Gear^.Hedgehog:= AttackerHog;
   244         end;
       
   245     inc(Gear^.Damage, Damage);
   245     inc(Gear^.Damage, Damage);
   246     
   246     
   247     ScriptCall('onGearDamage', Gear^.UID, Damage);
   247     ScriptCall('onGearDamage', Gear^.UID, Damage);
   248 end;
   248 end;
   249 
   249 
   317 
   317 
   318 procedure CalcRotationDirAngle(Gear: PGear);
   318 procedure CalcRotationDirAngle(Gear: PGear);
   319 var 
   319 var 
   320     dAngle: real;
   320     dAngle: real;
   321 begin
   321 begin
   322     dAngle := (Gear^.dX.QWordValue + Gear^.dY.QWordValue) / $80000000;
   322 // Frac/Round to be kind to JS as of 2012-08-27 where there is yet no int64/uint64
       
   323     dAngle := (Gear^.dX.Round + Gear^.dY.Round) / 2 + (Gear^.dX.Frac+Gear^.dY.Frac) / $80000000;
   323     if not Gear^.dX.isNegative then
   324     if not Gear^.dX.isNegative then
   324         Gear^.DirAngle := Gear^.DirAngle + dAngle
   325         Gear^.DirAngle := Gear^.DirAngle + dAngle
   325     else
   326     else
   326         Gear^.DirAngle := Gear^.DirAngle - dAngle;
   327         Gear^.DirAngle := Gear^.DirAngle - dAngle;
   327 
   328 
   418                 with splash^ do
   419                 with splash^ do
   419                 begin
   420                 begin
   420                 Scale:= hwFloat2Float(Gear^.Density / _3 * Gear^.dY);
   421                 Scale:= hwFloat2Float(Gear^.Density / _3 * Gear^.dY);
   421                 if Scale > 1 then Scale:= power(Scale,0.3333)
   422                 if Scale > 1 then Scale:= power(Scale,0.3333)
   422                 else Scale:= Scale + ((1-Scale) / 2);
   423                 else Scale:= Scale + ((1-Scale) / 2);
   423                 if Scale > 1 then Timer:= round(max(Scale,3))
   424                 if Scale > 1 then Timer:= round(min(Scale*0.0005/cGravityf,4))
   424                 else Timer:= 1;
   425                 else Timer:= 1;
   425                 // Low Gravity
   426                 // Low Gravity
   426                 Timer:=round(0.0005/cGravityf);
       
   427                 FrameTicks:= FrameTicks*Timer;
   427                 FrameTicks:= FrameTicks*Timer;
   428                 end;
   428                 end;
   429 
   429 
   430             maxDrops := (hwRound(Gear^.Density) * 3) div 2 + round(vdX * hwRound(Gear^.Density) * 6) + round(vdY * hwRound(Gear^.Density) * 6);
   430             maxDrops := (hwRound(Gear^.Density) * 3) div 2 + round(vdX * hwRound(Gear^.Density) * 6) + round(vdY * hwRound(Gear^.Density) * 6);
   431             for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
   431             for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
   602                     else
   602                     else
   603                         ar[cnt].Y:= y - Gear^.Radius;
   603                         ar[cnt].Y:= y - Gear^.Radius;
   604                     inc(cnt)
   604                     inc(cnt)
   605                     end;
   605                     end;
   606 
   606 
   607                 inc(y, 45)
   607                 inc(y, 10)
   608                 end;
   608                 end;
   609 
   609 
   610             if cnt > 0 then
   610             if cnt > 0 then
   611                 with ar[GetRandom(cnt)] do
   611                 with ar[GetRandom(cnt)] do
   612                     begin
   612                     begin
   662     end;
   662     end;
   663 
   663 
   664 CheckGearNear:= nil
   664 CheckGearNear:= nil
   665 end;
   665 end;
   666 
   666 
       
   667 procedure CheckCollision(Gear: PGear); inline;
       
   668 begin
       
   669     if TestCollisionXwithGear(Gear, hwSign(Gear^.dX))
       
   670     or (TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) <> 0) then
       
   671         Gear^.State := Gear^.State or gstCollision
       
   672     else
       
   673         Gear^.State := Gear^.State and (not gstCollision)
       
   674 end;
       
   675 
       
   676 procedure CheckCollisionWithLand(Gear: PGear); inline;
       
   677 begin
       
   678     if TestCollisionX(Gear, hwSign(Gear^.dX))
       
   679     or TestCollisionY(Gear, hwSign(Gear^.dY)) then
       
   680         Gear^.State := Gear^.State or gstCollision
       
   681     else 
       
   682         Gear^.State := Gear^.State and (not gstCollision)
       
   683 end;
       
   684 
   667 end.
   685 end.