hedgewars/HHHandlers.inc
changeset 53 0e27949850e3
parent 49 3afe33c1cf06
child 56 a29135563e94
equal deleted inserted replaced
52:ae2950c5465c 53:0e27949850e3
    28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    32  *)
    32  *)
    33 
       
    34 procedure AddIntersectorsCR(Gear: PGear);
       
    35 var t: PGear;
       
    36     x, xw, y, yh: real;
       
    37     ar: array[0..Pred(cMaxHHs)] of PGear;
       
    38     cnt: Longword;
       
    39     b: boolean;
       
    40 begin
       
    41 x:= Gear.X - Gear.HalfWidth;
       
    42 xw:= Gear.X + Gear.HalfWidth;
       
    43 y:= Gear.Y - Gear.HalfHeight;
       
    44 yh:= Gear.Y + Gear.HalfHeight;
       
    45 t:= GearsList;
       
    46 b:= false;
       
    47 cnt:= 0;
       
    48 while (t <> nil) do
       
    49       begin
       
    50       if (t <> Gear) and not (t.Kind in [gtGrave, gtMine]) then
       
    51          if (x < t.X + t.HalfWidth ) and (t.X - t.HalfWidth  < xw) and
       
    52             (y < t.Y + t.HalfHeight) and (t.Y - t.HalfHeight < yh) then
       
    53             if t.Kind = gtHedgehog then
       
    54                begin
       
    55                ar[cnt]:= t;
       
    56                inc(cnt)
       
    57                end else b:= true;
       
    58       t:= t.NextGear
       
    59       end;
       
    60 ar[cnt]:= Gear;
       
    61 inc(cnt);
       
    62 if b then
       
    63    begin
       
    64    repeat
       
    65      dec(cnt);
       
    66      if ar[cnt].CollIndex < High(Longword) then DeleteCR(ar[cnt])
       
    67    until cnt = 0;
       
    68    end else
       
    69    begin
       
    70    repeat
       
    71      dec(cnt);
       
    72      if ar[cnt].CollIndex = High(Longword) then AddGearCR(ar[cnt])
       
    73    until cnt = 0
       
    74    end
       
    75 end;
       
    76 
       
    77 procedure RemoveIntersectorsCR(Gear: PGear);
       
    78 var t: PGear;
       
    79     x, xw, y, yh: real;
       
    80 begin
       
    81 x:= Gear.X - Gear.HalfWidth;
       
    82 xw:= Gear.X + Gear.HalfWidth;
       
    83 y:= Gear.Y - Gear.HalfHeight;
       
    84 yh:= Gear.Y + Gear.HalfHeight;
       
    85 t:= GearsList;
       
    86 while (t <> nil) do
       
    87       begin
       
    88       if (t <> Gear) then
       
    89          if (x < t.X + t.HalfWidth ) and (t.X - t.HalfWidth  < xw) and
       
    90             (y < t.Y + t.HalfHeight) and (t.Y - t.HalfHeight < yh) then
       
    91                if t.CollIndex < High(Longword) then DeleteCR(t);
       
    92       t:= t.NextGear
       
    93       end;
       
    94 if Gear.CollIndex < High(Longword) then DeleteCR(Gear);
       
    95 end;
       
    96 
    33 
    97 ////////////////////////////////////////////////////////////////////////////////
    34 ////////////////////////////////////////////////////////////////////////////////
    98 procedure Attack(Gear: PGear);
    35 procedure Attack(Gear: PGear);
    99 var xx, yy: real;
    36 var xx, yy: real;
   100 begin
    37 begin
   130                                  end;
    67                                  end;
   131                        amDEagle: begin
    68                        amDEagle: begin
   132                                  FollowGear:= AddGear(round(X), round(Y), gtDEagleShot,   0, xx * 0.5, yy * 0.5);
    69                                  FollowGear:= AddGear(round(X), round(Y), gtDEagleShot,   0, xx * 0.5, yy * 0.5);
   133                                  end;
    70                                  end;
   134                          amSkip: TurnTimeLeft:= 0;
    71                          amSkip: TurnTimeLeft:= 0;
   135                    amPickHammer: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y) + cHHHalfHeight, gtPickHammer, 0);
    72                    amPickHammer: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y) + cHHRadius, gtPickHammer, 0);
   136                          amRope: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y), gtRope, 0, xx, yy);
    73                          amRope: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y), gtRope, 0, xx, yy);
   137                          amMine: AddGear(round(X) + Sign(dX) * 7, round(Y), gtMine, 0, Sign(dX) * 0.01, 0, 3000);
    74                          amMine: AddGear(round(X) + Sign(dX) * 7, round(Y), gtMine, 0, Sign(dX) * 0.01, 0, 3000);
   138                      amDynamite: AddGear(round(X) + Sign(dX) * 7, round(Y), gtDynamite, 0, Sign(dX) * 0.01, 0, 5000); 
    75                      amDynamite: AddGear(round(X) + Sign(dX) * 7, round(Y), gtDynamite, 0, Sign(dX) * 0.01, 0, 5000); 
   139                   end;
    76                   end;
   140         Power:= 0;
    77         Power:= 0;
   189       cStepTicks = 38;
   126       cStepTicks = 38;
   190 var t: PGear;
   127 var t: PGear;
   191 begin
   128 begin
   192 if isinMultiShoot and (Gear.Damage = 0) then
   129 if isinMultiShoot and (Gear.Damage = 0) then
   193    begin
   130    begin
   194    if Gear.CollIndex = High(Longword) then AddIntersectorsCR(Gear);
       
   195    exit
   131    exit
   196    end;
   132    end;
   197 AllInactive:= false;
   133 AllInactive:= false;
       
   134 DeleteCI(Gear);
   198 if (TurnTimeLeft = 0) or (Gear.Damage > 0) then
   135 if (TurnTimeLeft = 0) or (Gear.Damage > 0) then
   199    begin
   136    begin
   200    if ((Gear.State and (gstMoving or gstFalling)) = 0)
   137    if ((Gear.State and (gstMoving or gstFalling)) = 0)
   201       and (CurAmmoGear = nil) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
   138       and (CurAmmoGear = nil) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
   202    Gear.State:= Gear.State and not gstHHDriven;
   139    Gear.State:= Gear.State and not gstHHDriven;
   242             end
   179             end
   243       else Gear.Message:= Gear.Message and not gm_Attack;
   180       else Gear.Message:= Gear.Message and not gm_Attack;
   244 
   181 
   245 if ((Gear.State and gstAttacking) <> 0) and ((Gear.Message and gm_Attack) = 0) then
   182 if ((Gear.State and gstAttacking) <> 0) and ((Gear.Message and gm_Attack) = 0) then
   246    begin
   183    begin
   247    RemoveIntersectorsCR(Gear);
       
   248    Attack(Gear);
   184    Attack(Gear);
   249    StepTicks:= 40
   185    StepTicks:= 40
   250    end;
   186    end;
   251 
   187 
   252 if (Gear.State and gstFalling) <> 0 then
   188 if (Gear.State and gstFalling) <> 0 then
   274       StepTicks:= 300; 
   210       StepTicks:= 300; 
   275       Gear.dY:= 0
   211       Gear.dY:= 0
   276       end;
   212       end;
   277    CheckGearDrowning(Gear);
   213    CheckGearDrowning(Gear);
   278    exit
   214    exit
   279    end else if Gear.CollIndex = High(Longword) then AddIntersectorsCR(Gear);
   215    end ;//else if Gear.CollIndex = High(Longword) then AddIntersectorsCR(Gear);
   280 
   216 
   281 if StepTicks > 0 then dec(StepTicks);
   217 if StepTicks > 0 then dec(StepTicks);
   282 
   218 
   283 if ((Gear.State and (gstMoving or gstFalling)) = 0) then
   219 if ((Gear.State and (gstMoving or gstFalling)) = 0) then
   284    if (Gear.Message and gm_Up    )<>0 then if Gear.Angle > 0         then dec(Gear.Angle)
   220    if (Gear.Message and gm_Up    )<>0 then if Gear.Angle > 0         then dec(Gear.Angle)
   288 if ((Gear.State and (gstAttacking or gstMoving or gstFalling)) = 0)and(StepTicks = 0) then
   224 if ((Gear.State and (gstAttacking or gstMoving or gstFalling)) = 0)and(StepTicks = 0) then
   289    begin
   225    begin
   290    if ((Gear.Message and gm_LJump )<>0) then
   226    if ((Gear.Message and gm_LJump )<>0) then
   291       begin
   227       begin
   292       Gear.Message:= 0;
   228       Gear.Message:= 0;
   293       RemoveIntersectorsCR(Gear);
       
   294       if not HHTestCollisionYwithGear(Gear, -1) then
   229       if not HHTestCollisionYwithGear(Gear, -1) then
   295          if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else
   230          if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else
   296          if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1;
   231          if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1;
   297       if not (TestCollisionXwithGear(Gear, Sign(Gear.dX))
   232       if not (TestCollisionXwithGear(Gear, Sign(Gear.dX))
   298          or   HHTestCollisionYwithGear(Gear, -1)) then
   233          or   HHTestCollisionYwithGear(Gear, -1)) then
   304          end;
   239          end;
   305       end;
   240       end;
   306    if ((Gear.Message and gm_HJump )<>0) then
   241    if ((Gear.Message and gm_HJump )<>0) then
   307       begin
   242       begin
   308       Gear.Message:= 0;
   243       Gear.Message:= 0;
   309       RemoveIntersectorsCR(Gear);
       
   310       if not HHTestCollisionYwithGear(Gear, -1) then
   244       if not HHTestCollisionYwithGear(Gear, -1) then
   311          begin
   245          begin
   312          Gear.dY:= -0.20;
   246          Gear.dY:= -0.20;
   313          Gear.dX:= 0.0000001 * Sign(Gear.dX);
   247          Gear.dX:= 0.0000001 * Sign(Gear.dX);
   314          Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // компенсация сдвига %)
   248          Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // компенсация сдвига %)
   318       end;
   252       end;
   319    if (Gear.Message and gm_Left  )<>0 then Gear.dX:= -1.0 else
   253    if (Gear.Message and gm_Left  )<>0 then Gear.dX:= -1.0 else
   320    if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
   254    if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
   321    PHedgehog(Gear.Hedgehog).visStepPos:= (PHedgehog(Gear.Hedgehog).visStepPos + 1) and 7;
   255    PHedgehog(Gear.Hedgehog).visStepPos:= (PHedgehog(Gear.Hedgehog).visStepPos + 1) and 7;
   322    StepTicks:= cStepTicks;
   256    StepTicks:= cStepTicks;
   323    RemoveIntersectorsCR(Gear);
       
   324    if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
   257    if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
   325       begin
   258       begin
   326       if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
   259       if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
   327          or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   260          or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   328       if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
   261       if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
   336       if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
   269       if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
   337          or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   270          or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   338       end;
   271       end;
   339    if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX;
   272    if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX;
   340 
   273 
   341    AddIntersectorsCR(Gear);
       
   342    if not HHTestCollisionYwithGear(Gear, 1) then
   274    if not HHTestCollisionYwithGear(Gear, 1) then
   343    begin
   275    begin
   344    Gear.Y:= Gear.Y + 1;
   276    Gear.Y:= Gear.Y + 1;
   345    if not HHTestCollisionYwithGear(Gear, 1) then
   277    if not HHTestCollisionYwithGear(Gear, 1) then
   346    begin
   278    begin
   389    Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
   321    Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
   390    if Gear.dY > 0    then Gear.dY:= 0;
   322    if Gear.dY > 0    then Gear.dY:= 0;
   391    if ((Gear.State and gstMoving) <> 0) then Gear.dX:= Gear.dX * Gear.Friction
   323    if ((Gear.State and gstMoving) <> 0) then Gear.dX:= Gear.dX * Gear.Friction
   392    end;
   324    end;
   393 
   325 
   394 if (Gear.State <> 0) and (Gear.CollIndex < High(Longword)) then DeleteCR(Gear);
   326 if (Gear.State <> 0) then DeleteCI(Gear);
   395 
       
   396 
   327 
   397 if (Gear.State and gstMoving) <> 0 then
   328 if (Gear.State and gstMoving) <> 0 then
   398    if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
   329    if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
   399       if ((Gear.State and gstFalling) = 0) then
   330       if ((Gear.State and gstFalling) = 0) then
   400          if abs(Gear.dX) > 0.01 then
   331          if abs(Gear.dX) > 0.01 then
   445 if (not CheckGearDrowning(Gear)) and
   376 if (not CheckGearDrowning(Gear)) and
   446    ((Gear.State and gstMoving) = 0) then
   377    ((Gear.State and gstMoving) = 0) then
   447       begin
   378       begin
   448       Gear.State:= 0;
   379       Gear.State:= 0;
   449       Gear.Active:= false;
   380       Gear.Active:= false;
   450       AddIntersectorsCR(Gear);
   381       AddGearCI(Gear);
   451       exit
   382       exit
   452       end
   383       end
   453 end;
   384 end;
   454 
   385 
   455 ////////////////////////////////////////////////////////////////////////////////
   386 ////////////////////////////////////////////////////////////////////////////////