hedgewars/HHHandlers.inc
author unc0rr
Tue, 23 Aug 2005 16:17:53 +0000
changeset 4 bcbd7adb4e4b
parent 1 30f2d1037d5d
child 7 b472e4b1a106
permissions -rw-r--r--
- set svn:eol-style to native - Fixes for compilation and run on *nix - Read hedgehogs spawn points from fort's config
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     1
(*
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     2
 * Hedgewars, a worms-like game
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     3
 * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     6
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     9
 * with the Software without restriction, including without limitation the
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    12
 * furnished to do so, subject to the following conditions:
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    13
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    15
 *    this list of conditions and the following disclaimer.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
 *    and/or other materials provided with the distribution.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    20
 *    derived from this software without specific prior written permission.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    21
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    32
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    33
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    34
procedure doStepHedgehog(Gear: PGear); forward;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    35
////////////////////////////////////////////////////////////////////////////////
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    36
procedure doStepHedgehogDriven(Gear: PGear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    37
const StepTicks: LongWord = 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    38
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    39
if isinMultiShoot and (Gear.Damage = 0) then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    40
AllInactive:= false;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    41
if (TurnTimeLeft = 0) or (Gear.Damage > 0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    42
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    43
   if ((Gear.State and (gstMoving or gstFalling)) = 0)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    44
      and (CurAmmoGear = nil) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    45
   {$WARNINGS OFF}Gear.State:= Gear.State and not gstHHDriven;{$WARNINGS ON}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    46
   exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    47
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    48
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    49
if CurAmmoGear <> nil then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    50
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    51
   CurAmmoGear.Message:= Gear.Message;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    52
   exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    53
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    54
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    55
if (Gear.Message and gm_Attack)<>0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    56
   if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0)and(CurAmmoGear = nil) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    57
      with PHedgehog(Gear.Hedgehog)^ do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    58
//        if ((Gear.State and gstFalling  ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    59
//        and((Gear.State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    60
            begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    61
            Gear.State:= Gear.State or gstAttacking;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    62
            if Gear.Power = cMaxPower then ParseCommand('-attack')
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    63
               else begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    64
               if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Gear.Power:= cMaxPower
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    65
                  else begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    66
                  if Gear.Power = 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    67
                     begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    68
                     AttackBar:= CurrentTeam.AttackBar;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    69
                     PlaySound(sndThrowPowerUp)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    70
                     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    71
                  inc(Gear.Power)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    72
                  end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    73
               end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    74
            end else Gear.Message:= Gear.Message and not gm_Attack;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    75
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    76
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    77
if (Gear.State and gstFalling) <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    78
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    79
   if ((Gear.Message and gm_HJump) <> 0) and ((Gear.State and gstHHJumping) <> 0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    80
      if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    81
         begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    82
         Gear.dY:= -0.25;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    83
         Gear.dX:= Sign(Gear.dX) * 0.02
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    84
         end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    85
   Gear.Message:= Gear.Message and not (gm_LJump or gm_HJump);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    86
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    87
   Gear.X:= Gear.X + Gear.dX;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    88
   Gear.dY:= Gear.dY + cGravity;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    89
   if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; 
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    90
   Gear.Y:= Gear.Y + Gear.dY;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    91
   if (Gear.dY >= 0)and HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    92
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    93
      CheckHHDamage(Gear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    94
      if ((abs(Gear.dX) + abs(Gear.dY)) < 0.55)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    95
         and ((Gear.State and gstHHJumping) <> 0) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    96
      Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    97
      StepTicks:= 200;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    98
      Gear.dY:= 0
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    99
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   100
   CheckGearDrowning(Gear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   101
   exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   102
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   103
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   104
if StepTicks > 0 then dec(StepTicks);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   105
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   106
if ((Gear.State and (gstMoving or gstFalling)) = 0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   107
   if (Gear.Message and gm_Up    )<>0 then if Gear.Angle > 0         then dec(Gear.Angle)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   108
      else else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   109
   if (Gear.Message and gm_Down  )<>0 then if Gear.Angle < cMaxAngle then inc(Gear.Angle);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   110
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   111
if ((Gear.State and (gstAttacking or gstMoving or gstFalling)) = 0)and(StepTicks = 0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   112
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   113
   if ((Gear.Message and gm_LJump )<>0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   114
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   115
      Gear.Message:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   116
      if not HHTestCollisionYwithGear(Gear, -1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   117
         if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   118
         if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   119
      if not (TestCollisionXwithGear(Gear, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   120
         or   HHTestCollisionYwithGear(Gear, -1)) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   121
         begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   122
         Gear.dY:= -0.15;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   123
         Gear.dX:= Sign(Gear.dX) * 0.15;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   124
         Gear.State:= Gear.State or gstFalling or gstHHJumping;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   125
         exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   126
         end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   127
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   128
   if ((Gear.Message and gm_HJump )<>0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   129
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   130
      Gear.Message:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   131
      if not HHTestCollisionYwithGear(Gear, -1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   132
         begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   133
         Gear.dY:= -0.20;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   134
         Gear.dX:= 0.0000001 * Sign(Gear.dX);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   135
         Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // компенсация сдвига %)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   136
         Gear.State:= Gear.State or gstFalling or gstHHJumping;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   137
         exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   138
         end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   139
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   140
   if (Gear.Message and gm_Left  )<>0 then Gear.dX:= -1.0 else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   141
   if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   142
   PHedgehog(Gear.Hedgehog).visStepPos:= (PHedgehog(Gear.Hedgehog).visStepPos + 1) and 7;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   143
   StepTicks:= 40;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   144
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   145
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   146
      if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   147
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   148
      if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   149
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   150
      if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   151
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   152
      if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   153
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   154
      if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   155
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   156
      if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   157
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   158
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   159
   if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   160
   
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   161
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   162
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   163
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   164
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   165
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   166
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   167
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   168
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   169
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   170
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   171
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   172
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   173
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   174
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   175
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   176
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   177
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   178
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   179
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   180
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   181
      Gear.Y:= Gear.Y - 6;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   182
      Gear.dY:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   183
      Gear.dX:= 0.0000001 * Sign(Gear.dX);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   184
      Gear.State:= Gear.State or gstFalling
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   185
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   186
   SetAllHHToActive
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   187
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   188
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   189
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   190
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   191
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   192
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   193
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   194
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   195
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   196
////////////////////////////////////////////////////////////////////////////////
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   197
procedure doStepHedgehogFree(Gear: PGear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   198
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   199
if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   200
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   201
   if (Gear.dY < 0) and HHTestCollisionYwithGear(Gear, -1) then Gear.dY:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   202
   Gear.State:= Gear.State or gstFalling or gstMoving;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   203
   Gear.dY:= Gear.dY + cGravity
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   204
   end else begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   205
   CheckHHDamage(Gear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   206
   if Gear.dY > 0    then Gear.dY:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   207
   Gear.State:= Gear.State and not gstFalling;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   208
   if ((Gear.State and gstMoving) <> 0) then Gear.dX:= Gear.dX * Gear.Friction
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   209
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   210
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   211
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   212
if (Gear.State and gstMoving) <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   213
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   214
      if ((Gear.State and gstFalling) = 0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   215
         if abs(Gear.dX) > 0.01 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   216
            if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 1 end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   217
            if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 2 end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   218
            if not TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 3 end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   219
            if not TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 4 end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   220
            if not TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.3; Gear.Y:= Gear.Y - 5 end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   221
            if abs(Gear.dX) > 0.02 then Gear.dX:= -0.5 * Gear.dX
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   222
                                   else begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   223
                                        Gear.State:= Gear.State and not gstMoving;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   224
                                        Gear.dX:= 0.0000001 * Sign(Gear.dX)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   225
                                        end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   226
                                   else begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   227
                                        Gear.State:= Gear.State and not gstMoving;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   228
                                        Gear.dX:= 0.0000001 * Sign(Gear.dX)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   229
                                        end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   230
         else Gear.dX:= -0.8 * Gear.dX;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   231
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   232
if ((Gear.State and gstFalling) = 0)and
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   233
   (sqr(Gear.dX) + sqr(Gear.dY) < 0.0008) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   234
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   235
   Gear.State:= Gear.State and not gstMoving;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   236
   Gear.dX:= 0.0000001 * Sign(Gear.dX);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   237
   Gear.dY:= 0
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   238
   end else Gear.State:= Gear.State or      gstMoving;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   239
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   240
if (Gear.State and gstMoving) <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   241
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   242
   Gear.X:= Gear.X + Gear.dX;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   243
   Gear.Y:= Gear.Y + Gear.dY
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   244
   end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   245
   if Gear.Health = 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   246
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   247
      if AllInactive then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   248
         begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   249
         doMakeExplosion(round(Gear.X), round(Gear.Y), 30, EXPLAutoSound);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   250
         AddGear(round(Gear.X), round(Gear.Y), gtGrave, 0).Hedgehog:= Gear.Hedgehog;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   251
         DeleteGear(Gear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   252
         SetAllToActive
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   253
         end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   254
      AllInactive:= false;  (* почему этого тут не было? *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   255
      exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   256
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   257
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   258
AllInactive:= false;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   259
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   260
if (not CheckGearDrowning(Gear)) and
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   261
   ((Gear.State and gstMoving) = 0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   262
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   263
      Gear.State:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   264
      Gear.Active:= false;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   265
      AddGearCR(Gear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   266
      exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   267
      end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   268
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   269
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   270
////////////////////////////////////////////////////////////////////////////////
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   271
procedure doStepHedgehog(Gear: PGear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   272
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   273
if (Gear.Message and gm_Destroy) <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   274
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   275
   DeleteGear(Gear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   276
   exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   277
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   278
if Gear.CollIndex < High(Longword) then DeleteCR(Gear);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   279
if (Gear.State and gstHHDriven) = 0 then doStepHedgehogFree(Gear)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   280
                                    else doStepHedgehogDriven(Gear)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   281
end;