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