hedgewars/uGearsHandlersRope.pas
author unc0rr
Fri, 24 Aug 2012 14:51:12 +0400
changeset 7593 b966e2d833f2
parent 7592 cf67e58313ea
child 7594 5f03595335e6
permissions -rw-r--r--
An attempt to run main rope code only every 8th tick: - A big win for inner loop which is O(n^2) and thus it takes 64 times less cpu now. - Look and feel is almost identical (well, to my non-pro view) - Yes, the speed is limited to 7 px per accounting tick which is potentially very bad to collisions - Ruin shoppa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     1
(*
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     4
 *
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     8
 *
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    13
 *
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    17
 *)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    18
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    20
unit uGearsHandlersRope;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    21
interface
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    22
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    23
uses uTypes;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    24
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    25
procedure doStepRope(Gear: PGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    26
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    27
implementation
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    28
uses uConsts, uFloat, uCollisions, uVariables, uGearsList, uSound, uGearsUtils,
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    29
    uAmmos, uDebug, uUtils, uGearsHedgehog, uGearsRender;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    30
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    31
procedure doStepRopeAfterAttack(Gear: PGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    32
var 
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    33
    HHGear: PGear;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    34
begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    35
    HHGear := Gear^.Hedgehog^.Gear;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    36
    if ((HHGear^.State and gstHHDriven) = 0)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    37
    or (CheckGearDrowning(HHGear))
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    38
    or (TestCollisionYwithGear(HHGear, 1) <> 0) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    39
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    40
        DeleteGear(Gear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    41
        isCursorVisible := false;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    42
        ApplyAmmoChanges(HHGear^.Hedgehog^);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    43
        exit
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    44
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    45
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    46
    HedgehogChAngle(HHGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    47
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    48
    if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    49
        SetLittle(HHGear^.dX);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    50
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    51
    if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    52
        HHGear^.dY := _0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    53
    HHGear^.X := HHGear^.X + HHGear^.dX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    54
    HHGear^.Y := HHGear^.Y + HHGear^.dY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    55
    HHGear^.dY := HHGear^.dY + cGravity;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    56
    
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    57
    if (GameFlags and gfMoreWind) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    58
        HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    59
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    60
    if (Gear^.Message and gmAttack) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    61
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    62
        Gear^.X := HHGear^.X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    63
        Gear^.Y := HHGear^.Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    64
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    65
        ApplyAngleBounds(Gear^.Hedgehog^, amRope);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    66
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    67
        Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    68
        Gear^.dY := -AngleCos(HHGear^.Angle);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    69
        Gear^.Friction := _4_5 * cRopePercent;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    70
        Gear^.Elasticity := _0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    71
        Gear^.State := Gear^.State and (not gsttmpflag);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    72
        Gear^.doStep := @doStepRope;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    73
        end
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    74
end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    75
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    76
procedure RopeDeleteMe(Gear, HHGear: PGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    77
begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    78
    with HHGear^ do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    79
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    80
        Message := Message and (not gmAttack);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    81
        State := (State or gstMoving) and (not gstWinner);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    82
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    83
    DeleteGear(Gear)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    84
end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    85
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    86
procedure RopeWaitCollision(Gear, HHGear: PGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    87
begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    88
    with HHGear^ do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    89
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    90
        Message := Message and (not gmAttack);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    91
        State := State or gstMoving;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    92
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    93
    RopePoints.Count := 0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    94
    Gear^.Elasticity := _0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    95
    Gear^.doStep := @doStepRopeAfterAttack
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    96
end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    97
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    98
procedure doStepRopeWork(Gear: PGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
    99
var 
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   100
    HHGear: PGear;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   101
    len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   102
    lx, ly, cd: LongInt;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   103
    haveCollision,
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   104
    haveDivided: boolean;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   105
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   106
begin
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   107
    if GameTicks mod 8 <> 0 then exit;
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   108
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   109
    HHGear := Gear^.Hedgehog^.Gear;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   110
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   111
    if ((HHGear^.State and gstHHDriven) = 0)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   112
       or (CheckGearDrowning(HHGear)) or (Gear^.PortalCounter <> 0) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   113
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   114
        PlaySound(sndRopeRelease);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   115
        RopeDeleteMe(Gear, HHGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   116
        exit
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   117
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   118
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   119
    if (Gear^.Message and gmLeft  <> 0) and (not TestCollisionXwithGear(HHGear, -1)) then
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   120
        HHGear^.dX := HHGear^.dX - _0_0128;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   121
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   122
    if (Gear^.Message and gmRight <> 0) and (not TestCollisionXwithGear(HHGear,  1)) then
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   123
        HHGear^.dX := HHGear^.dX + _0_0128;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   124
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   125
    // vector between hedgehog and rope attaching point
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   126
    ropeDx := HHGear^.X - Gear^.X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   127
    ropeDy := HHGear^.Y - Gear^.Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   128
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   129
    if TestCollisionYwithGear(HHGear, 1) = 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   130
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   131
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   132
        // depending on the rope vector we know which X-side to check for collision
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   133
        // in order to find out if the hog can still be moved by gravity
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   134
        if ropeDx.isNegative = RopeDy.IsNegative then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   135
            cd:= -1
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   136
        else
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   137
            cd:= 1;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   138
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   139
        // apply gravity if there is no obstacle
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   140
        if not TestCollisionXwithGear(HHGear, cd) then
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   141
            HHGear^.dY := HHGear^.dY + cGravity * 64;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   142
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   143
        if (GameFlags and gfMoreWind) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   144
            // apply wind if there's no obstacle
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   145
            if not TestCollisionXwithGear(HHGear, hwSign(cWindSpeed)) then
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   146
                HHGear^.dX := HHGear^.dX + cWindSpeed * 64 / HHGear^.Density;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   147
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   148
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   149
    mdX := ropeDx + HHGear^.dX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   150
    mdY := ropeDy + HHGear^.dY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   151
    len := _1 / Distance(mdX, mdY);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   152
    // rope vector plus hedgehog direction vector normalized
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   153
    mdX := mdX * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   154
    mdY := mdY * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   155
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   156
    // for visual purposes only
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   157
    Gear^.dX := mdX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   158
    Gear^.dY := mdY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   159
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   160
    /////
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   161
    tx := HHGear^.X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   162
    ty := HHGear^.Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   163
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   164
    if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   165
        if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx))
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   166
        or (TestCollisionYwithGear(HHGear, hwSign(ropeDy)) <> 0)) then
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   167
            Gear^.Elasticity := Gear^.Elasticity + _2_4;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   168
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   169
    if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   170
        if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx))
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   171
        or (TestCollisionYwithGear(HHGear, -hwSign(ropeDy)) <> 0)) then
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   172
            Gear^.Elasticity := Gear^.Elasticity - _2_4;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   173
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   174
    HHGear^.X := Gear^.X + mdX * Gear^.Elasticity;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   175
    HHGear^.Y := Gear^.Y + mdY * Gear^.Elasticity;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   176
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   177
    HHGear^.dX := HHGear^.X - tx;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   178
    HHGear^.dY := HHGear^.Y - ty;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   179
    ////
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   180
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   181
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   182
    haveDivided := false;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   183
    // check whether rope needs dividing
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   184
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   185
    len := Gear^.Elasticity - _5;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   186
    nx := Gear^.X + mdX * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   187
    ny := Gear^.Y + mdY * len;
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   188
    tx := mdX * _2_4; // should be the same as increase step
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   189
    ty := mdY * _2_4;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   190
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   191
    while len > _3 do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   192
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   193
        lx := hwRound(nx);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   194
        ly := hwRound(ny);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   195
        if ((ly and LAND_HEIGHT_MASK) = 0) and ((lx and LAND_WIDTH_MASK) = 0) and ((Land[ly, lx] and $FF00) <> 0) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   196
            begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   197
            ny := _1 / Distance(ropeDx, ropeDy);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   198
            // old rope pos
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   199
            nx := ropeDx * ny;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   200
            ny := ropeDy * ny;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   201
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   202
            with RopePoints.ar[RopePoints.Count] do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   203
                begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   204
                X := Gear^.X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   205
                Y := Gear^.Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   206
                if RopePoints.Count = 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   207
                    RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   208
                b := (nx * HHGear^.dY) > (ny * HHGear^.dX);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   209
                dLen := len
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   210
                end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   211
                
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   212
            with RopePoints.rounded[RopePoints.Count] do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   213
                begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   214
                X := hwRound(Gear^.X);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   215
                Y := hwRound(Gear^.Y);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   216
                end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   217
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   218
            Gear^.X := Gear^.X + nx * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   219
            Gear^.Y := Gear^.Y + ny * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   220
            inc(RopePoints.Count);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   221
            TryDo(RopePoints.Count <= MAXROPEPOINTS, 'Rope points overflow', true);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   222
            Gear^.Elasticity := Gear^.Elasticity - len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   223
            Gear^.Friction := Gear^.Friction - len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   224
            haveDivided := true;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   225
            break
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   226
            end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   227
        nx := nx - tx;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   228
        ny := ny - ty;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   229
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   230
        // len := len - _2_4 // should be the same as increase step
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   231
        len.QWordValue := len.QWordValue - _2_4.QWordValue;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   232
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   233
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   234
    if not haveDivided then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   235
        if RopePoints.Count > 0 then // check whether the last dividing point could be removed
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   236
            begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   237
            tx := RopePoints.ar[Pred(RopePoints.Count)].X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   238
            ty := RopePoints.ar[Pred(RopePoints.Count)].Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   239
            mdX := tx - Gear^.X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   240
            mdY := ty - Gear^.Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   241
            if RopePoints.ar[Pred(RopePoints.Count)].b xor (mdX * (ty - HHGear^.Y) > (tx - HHGear^.X) * mdY) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   242
                begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   243
                dec(RopePoints.Count);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   244
                Gear^.X := RopePoints.ar[RopePoints.Count].X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   245
                Gear^.Y := RopePoints.ar[RopePoints.Count].Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   246
                Gear^.Elasticity := Gear^.Elasticity + RopePoints.ar[RopePoints.Count].dLen;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   247
                Gear^.Friction := Gear^.Friction + RopePoints.ar[RopePoints.Count].dLen;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   248
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   249
                // restore hog position
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   250
                len := _1 / Distance(mdX, mdY);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   251
                mdX := mdX * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   252
                mdY := mdY * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   253
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   254
                HHGear^.X := Gear^.X - mdX * Gear^.Elasticity;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   255
                HHGear^.Y := Gear^.Y - mdY * Gear^.Elasticity;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   256
                end
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   257
            end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   258
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   259
    haveCollision := false;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   260
    if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   261
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   262
        HHGear^.dX := -_0_6 * HHGear^.dX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   263
        haveCollision := true
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   264
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   265
    if TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   266
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   267
        HHGear^.dY := -_0_6 * HHGear^.dY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   268
        haveCollision := true
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   269
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   270
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   271
    if haveCollision and (Gear^.Message and (gmLeft or gmRight) <> 0) and (Gear^.Message and (gmUp or gmDown) <> 0) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   272
        begin
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   273
        HHGear^.dX := SignAs(hwAbs(HHGear^.dX) + _1_6, HHGear^.dX);
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   274
        HHGear^.dY := SignAs(hwAbs(HHGear^.dY) + _1_6, HHGear^.dY)
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   275
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   276
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   277
    len := hwSqr(HHGear^.dX) + hwSqr(HHGear^.dY);
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   278
    if len > _49 then
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   279
        begin
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   280
        len := _7 / hwSqrt(len);
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   281
        HHGear^.dX := HHGear^.dX * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   282
        HHGear^.dY := HHGear^.dY * len;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   283
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   284
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   285
    haveCollision:= ((hwRound(Gear^.Y) and LAND_HEIGHT_MASK) = 0) and ((hwRound(Gear^.X) and LAND_WIDTH_MASK) = 0) and ((Land[hwRound(Gear^.Y), hwRound(Gear^.X)]) <> 0);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   286
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   287
    if not haveCollision then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   288
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   289
        // backup gear location
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   290
        tx:= Gear^.X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   291
        ty:= Gear^.Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   292
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   293
        if RopePoints.Count > 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   294
            begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   295
            // set gear location to the remote end of the rope, the attachment point
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   296
            Gear^.X:= RopePoints.ar[0].X;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   297
            Gear^.Y:= RopePoints.ar[0].Y;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   298
            end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   299
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   300
        CheckCollision(Gear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   301
        // if we haven't found any collision yet then check the other side too
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   302
        if (Gear^.State and gstCollision) = 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   303
            begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   304
            Gear^.dX.isNegative:= not Gear^.dX.isNegative;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   305
            Gear^.dY.isNegative:= not Gear^.dY.isNegative;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   306
            CheckCollision(Gear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   307
            Gear^.dX.isNegative:= not Gear^.dX.isNegative;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   308
            Gear^.dY.isNegative:= not Gear^.dY.isNegative;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   309
            end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   310
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   311
        haveCollision:= (Gear^.State and gstCollision) <> 0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   312
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   313
        // restore gear location
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   314
        Gear^.X:= tx;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   315
        Gear^.Y:= ty;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   316
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   317
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   318
    // if the attack key is pressed, lose rope contact as well
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   319
    if (Gear^.Message and gmAttack) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   320
        haveCollision:= false;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   321
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   322
    if not haveCollision then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   323
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   324
        if (Gear^.State and gsttmpFlag) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   325
            begin
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   326
            HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue shr 3;
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   327
            HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue shr 3;
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   328
            
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   329
            PlaySound(sndRopeRelease);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   330
            if Gear^.Hedgehog^.CurAmmoType <> amParachute then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   331
                RopeWaitCollision(Gear, HHGear)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   332
            else
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   333
                RopeDeleteMe(Gear, HHGear)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   334
            end
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   335
        end
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   336
    else
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   337
        if (Gear^.State and gsttmpFlag) = 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   338
            Gear^.State := Gear^.State or gsttmpFlag;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   339
end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   340
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   341
procedure RopeRemoveFromAmmo(Gear, HHGear: PGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   342
begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   343
    if (Gear^.State and gstAttacked) = 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   344
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   345
        OnUsedAmmo(HHGear^.Hedgehog^);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   346
        Gear^.State := Gear^.State or gstAttacked
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   347
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   348
    ApplyAmmoChanges(HHGear^.Hedgehog^)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   349
end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   350
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   351
procedure doStepRopeAttach(Gear: PGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   352
var 
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   353
    HHGear: PGear;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   354
    tx, ty, tt: hwFloat;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   355
begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   356
    Gear^.X := Gear^.X - Gear^.dX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   357
    Gear^.Y := Gear^.Y - Gear^.dY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   358
    Gear^.Elasticity := Gear^.Elasticity + _1;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   359
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   360
    HHGear := Gear^.Hedgehog^.Gear;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   361
    DeleteCI(HHGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   362
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   363
    if (HHGear^.State and gstMoving) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   364
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   365
        if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   366
            SetLittle(HHGear^.dX);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   367
        if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   368
            HHGear^.dY := _0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   369
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   370
        HHGear^.X := HHGear^.X + HHGear^.dX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   371
        Gear^.X := Gear^.X + HHGear^.dX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   372
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   373
        if TestCollisionYwithGear(HHGear, 1) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   374
            begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   375
            CheckHHDamage(HHGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   376
            HHGear^.dY := _0
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   377
            //HHGear^.State:= HHGear^.State and (not (gstHHJumping or gstHHHJump));
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   378
            end
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   379
        else
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   380
            begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   381
            HHGear^.Y := HHGear^.Y + HHGear^.dY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   382
            Gear^.Y := Gear^.Y + HHGear^.dY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   383
            HHGear^.dY := HHGear^.dY + cGravity;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   384
            if (GameFlags and gfMoreWind) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   385
                HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   386
            end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   387
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   388
        tt := Gear^.Elasticity;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   389
        tx := _0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   390
        ty := _0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   391
        while tt > _20 do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   392
            begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   393
            if ((hwRound(Gear^.Y+ty) and LAND_HEIGHT_MASK) = 0) and ((hwRound(Gear^.X+tx) and LAND_WIDTH_MASK) = 0) and ((Land[hwRound(Gear^.Y+ty), hwRound(Gear^.X+tx)] and $FF00) <> 0) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   394
                begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   395
                Gear^.X := Gear^.X + tx;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   396
                Gear^.Y := Gear^.Y + ty;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   397
                Gear^.Elasticity := tt;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   398
                Gear^.doStep := @doStepRopeWork;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   399
                PlaySound(sndRopeAttach);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   400
                with HHGear^ do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   401
                    begin
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   402
                    dX.QWordValue:= dX.QWordValue shl 3;
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   403
                    dY.QWordValue:= dY.QWordValue shl 3;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   404
                    State := State and (not (gstAttacking or gstHHJumping or gstHHHJump));
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   405
                    Message := Message and (not gmAttack)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   406
                    end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   407
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   408
                RopeRemoveFromAmmo(Gear, HHGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   409
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   410
                tt := _0;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   411
                exit
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   412
                end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   413
            tx := tx + Gear^.dX + Gear^.dX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   414
            ty := ty + Gear^.dY + Gear^.dY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   415
            tt := tt - _2;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   416
            end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   417
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   418
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   419
    CheckCollision(Gear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   420
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   421
    if (Gear^.State and gstCollision) <> 0 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   422
        if Gear^.Elasticity < _10 then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   423
            Gear^.Elasticity := _10000
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   424
    else
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   425
        begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   426
        Gear^.doStep := @doStepRopeWork;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   427
        PlaySound(sndRopeAttach);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   428
        with HHGear^ do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   429
            begin
7593
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   430
            dX.QWordValue:= dX.QWordValue shl 3;
b966e2d833f2 An attempt to run main rope code only every 8th tick:
unc0rr
parents: 7592
diff changeset
   431
            dY.QWordValue:= dY.QWordValue shl 3;
7592
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   432
            State := State and (not (gstAttacking or gstHHJumping or gstHHHJump));
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   433
            Message := Message and (not gmAttack)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   434
            end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   435
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   436
        RopeRemoveFromAmmo(Gear, HHGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   437
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   438
        exit
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   439
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   440
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   441
    if (Gear^.Elasticity > Gear^.Friction)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   442
        or ((Gear^.Message and gmAttack) = 0)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   443
        or ((HHGear^.State and gstHHDriven) = 0)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   444
        or (HHGear^.Damage > 0) then
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   445
            begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   446
            with Gear^.Hedgehog^.Gear^ do
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   447
                begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   448
                State := State and (not gstAttacking);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   449
                Message := Message and (not gmAttack)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   450
                end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   451
        DeleteGear(Gear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   452
        exit;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   453
        end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   454
    if CheckGearDrowning(HHGear) then DeleteGear(Gear)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   455
end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   456
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   457
procedure doStepRope(Gear: PGear);
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   458
begin
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   459
    Gear^.dX := - Gear^.dX;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   460
    Gear^.dY := - Gear^.dY;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   461
    Gear^.doStep := @doStepRopeAttach;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   462
    PlaySound(sndRopeShot)
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   463
end;
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   464
cf67e58313ea Move rope code to separate unit
unc0rr
parents:
diff changeset
   465
end.