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