hedgewars/uGearsHandlersRope.pas
author nemo
Sun, 26 Aug 2012 10:15:28 -0400
changeset 7609 7663a5c614cb
parent 7608 94d071054a23
child 7610 682e21112867
permissions -rw-r--r--
shoppa hack, take... 4?
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
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    76
procedure unstickHog(Gear, HHGear: PGear);
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    77
var i: LongInt;
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    78
    stuck: Boolean;
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    79
begin
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    80
    if (TestCollisionYwithGear(HHGear, 1) <> 0) and (TestCollisionYwithGear(HHGear, -1) = 0) then
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    81
        begin
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    82
        i:= 1;
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    83
        repeat
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    84
            begin
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    85
            inc(i);
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
    86
            stuck:= TestCollisionYwithGear(HHGear, 1) <> 0;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
    87
            if stuck then HHGear^.Y:= HHGear^.Y-_1
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    88
            end
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    89
        until (i = 8) or not stuck;
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    90
        // experiment in simulating something the shoppa players apparently expect
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
    91
        if Gear^.Message and gmDown <> 0 then
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
    92
            begin
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
    93
            //HHGear^.dY:= HHGear^.dY / 16;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
    94
            HHGear^.dY:= _0;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
    95
            HHGear^.dX:= HHGear^.dX * 2
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
    96
            end;
7606
adb1198ade36 another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents: 7605
diff changeset
    97
        if Gear^.Message and gmRight <> 0 then
adb1198ade36 another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents: 7605
diff changeset
    98
            HHGear^.dX.isNegative:= false
adb1198ade36 another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents: 7605
diff changeset
    99
        else if Gear^.Message and gmLeft <> 0 then
adb1198ade36 another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents: 7605
diff changeset
   100
            HHGear^.dX.isNegative:= true
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   101
        end
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   102
    else if (TestCollisionYwithGear(HHGear, -1) <> 0) and (TestCollisionYwithGear(HHGear, 1) = 0) then
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   103
        begin
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   104
        i:= 1;
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   105
        repeat
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   106
            begin
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   107
            inc(i);
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   108
            stuck:= TestCollisionYwithGear(HHGear, -1) <> 0;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   109
            if stuck then HHGear^.Y:= HHGear^.Y+_1
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   110
            end
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   111
        until (i = 8) or not stuck;
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   112
        if Gear^.Message and gmDown <> 0 then
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   113
            begin
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   114
            //HHGear^.dY:= HHGear^.dY / 16;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   115
            HHGear^.dY.QWordValue:= 0;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   116
            HHGear^.dX:= HHGear^.dX * 2
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   117
            end;
7606
adb1198ade36 another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents: 7605
diff changeset
   118
        if Gear^.Message and gmRight <> 0 then
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   119
            HHGear^.dX.isNegative:= true
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   120
        else if Gear^.Message and gmLeft <> 0 then
7606
adb1198ade36 another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents: 7605
diff changeset
   121
            HHGear^.dX.isNegative:= false
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   122
        end;
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   123
    if TestCollisionXwithGear(HHGear, 1) and not TestCollisionXwithGear(HHGear, -1) then
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   124
        begin
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   125
        i:= 1;
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   126
        repeat
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   127
            begin
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   128
            inc(i);
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   129
            stuck:= TestCollisionXwithGear(HHGear, 1);
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   130
            if stuck then HHGear^.X:= HHGear^.X-_1
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   131
            end
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   132
        until (i = 8) or not stuck;
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   133
        if Gear^.Message and gmDown <> 0 then
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   134
            begin
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   135
            //HHGear^.dX:= HHGear^.dX / 16;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   136
            HHGear^.dX.QWordValue:= 0;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   137
            HHGear^.dY:= HHGear^.dY * 2
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   138
            end;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   139
        if Gear^.Message and gmRight <> 0 then
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   140
            HHGear^.dX.isNegative:= true
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   141
        else if Gear^.Message and gmLeft <> 0 then
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   142
            HHGear^.dX.isNegative:= false
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   143
        end
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   144
    else if TestCollisionXwithGear(HHGear, -1) and not TestCollisionXwithGear(HHGear, 1) then
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   145
        begin
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   146
        i:= 1;
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   147
        repeat
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   148
            begin
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   149
            inc(i);
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   150
            stuck:= TestCollisionXwithGear(HHGear, -1);
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   151
            if stuck then HHGear^.X:= HHGear^.X+_1
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   152
            end
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   153
        until (i = 8) or not stuck;
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   154
        if Gear^.Message and gmDown <> 0 then
7609
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   155
            begin
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   156
            //HHGear^.dX:= HHGear^.dX / 16;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   157
            HHGear^.dX.QWordValue:= 0;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   158
            HHGear^.dY:= HHGear^.dY * 2
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   159
            end;
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   160
        if Gear^.Message and gmRight <> 0 then
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   161
            HHGear^.dX.isNegative:= false
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   162
        else if Gear^.Message and gmLeft <> 0 then
7663a5c614cb shoppa hack, take... 4?
nemo
parents: 7608
diff changeset
   163
            HHGear^.dX.isNegative:= true
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   164
        end
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   165
end;
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   166
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   167
procedure RopeDeleteMe(Gear, HHGear: PGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   168
begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   169
    PlaySound(sndRopeRelease);
7602
a620319d377e Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents: 7601
diff changeset
   170
    HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue div Gear^.stepFreq;
a620319d377e Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents: 7601
diff changeset
   171
    HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue div Gear^.stepFreq;
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   172
    with HHGear^ do
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   173
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   174
        Message := Message and (not gmAttack);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   175
        State := (State or gstMoving) and (not gstWinner);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   176
        end;
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   177
    unstickHog(Gear, HHGear);
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   178
    DeleteGear(Gear)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   179
end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   180
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   181
procedure RopeWaitCollision(Gear, HHGear: PGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   182
begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   183
    PlaySound(sndRopeRelease);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   184
    with HHGear^ do
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   185
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   186
        Message := Message and (not gmAttack);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   187
        State := State or gstMoving;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   188
        end;
7605
10e88fbb5fdb hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents: 7604
diff changeset
   189
    unstickHog(Gear, HHGear);
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   190
    RopePoints.Count := 0;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   191
    Gear^.Elasticity := _0;
7602
a620319d377e Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents: 7601
diff changeset
   192
    Gear^.doStep := @doStepRopeAfterAttack;
a620319d377e Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents: 7601
diff changeset
   193
    HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue div Gear^.stepFreq;
a620319d377e Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents: 7601
diff changeset
   194
    HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue div Gear^.stepFreq;
a620319d377e Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents: 7601
diff changeset
   195
    Gear^.stepFreq := 1
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   196
end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   197
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   198
procedure doStepRopeWork(Gear: PGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   199
var 
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   200
    HHGear: PGear;
7595
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   201
    len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY, t: hwFloat;
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   202
    lx, ly, cd, i: LongInt;
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   203
    haveCollision,
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   204
    haveDivided: boolean;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   205
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   206
begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   207
    if GameTicks mod 8 <> 0 then exit;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   208
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   209
    HHGear := Gear^.Hedgehog^.Gear;
7595
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   210
    haveCollision:= false;
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   211
    if (Gear^.Message and gmLeft  <> 0) and (not TestCollisionXwithGear(HHGear, -1)) then
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   212
        HHGear^.dX := HHGear^.dX - _0_0128
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   213
    else haveCollision:= true;
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   214
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   215
    if (Gear^.Message and gmRight <> 0) and (not TestCollisionXwithGear(HHGear,  1)) then
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   216
        HHGear^.dX := HHGear^.dX + _0_0128
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   217
    else haveCollision:= true;
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   218
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   219
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   220
    if ((HHGear^.State and gstHHDriven) = 0)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   221
       or (CheckGearDrowning(HHGear)) or (Gear^.PortalCounter <> 0) then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   222
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   223
        RopeDeleteMe(Gear, HHGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   224
        exit
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   225
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   226
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   227
    // vector between hedgehog and rope attaching point
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   228
    ropeDx := HHGear^.X - Gear^.X;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   229
    ropeDy := HHGear^.Y - Gear^.Y;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   230
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   231
    if TestCollisionYwithGear(HHGear, 1) = 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   232
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   233
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   234
        // 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
   235
        // 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
   236
        if ropeDx.isNegative = RopeDy.IsNegative then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   237
            cd:= -1
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   238
        else
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   239
            cd:= 1;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   240
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   241
        // apply gravity if there is no obstacle
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   242
        if not TestCollisionXwithGear(HHGear, cd) then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   243
            HHGear^.dY := HHGear^.dY + cGravity * 64;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   244
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   245
        if (GameFlags and gfMoreWind) <> 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   246
            // apply wind if there's no obstacle
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   247
            if not TestCollisionXwithGear(HHGear, hwSign(cWindSpeed)) then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   248
                HHGear^.dX := HHGear^.dX + cWindSpeed * 64 / HHGear^.Density;
7595
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   249
        end
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   250
    else haveCollision:= true;
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   251
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   252
    if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   253
        if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx))
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   254
        or (TestCollisionYwithGear(HHGear, hwSign(ropeDy)) <> 0)) then
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   255
            Gear^.Elasticity := Gear^.Elasticity + _2_4
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   256
    else haveCollision:= true;
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   257
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   258
    if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   259
        if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx))
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   260
        or (TestCollisionYwithGear(HHGear, -hwSign(ropeDy)) <> 0)) then
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   261
            Gear^.Elasticity := Gear^.Elasticity - _2_4
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   262
    else haveCollision:= true;
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   263
7604
c143c942b5fe Hack to try and appease the shoppa players
nemo
parents: 7602
diff changeset
   264
(*
c143c942b5fe Hack to try and appease the shoppa players
nemo
parents: 7602
diff changeset
   265
I am not so sure this is useful. Disabling
7595
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   266
    if haveCollision then
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   267
        begin
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   268
        if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) and not TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   269
            HHGear^.dX.isNegative:= not HHGear^.dX.isNegative;
bbac3c0f0c68 Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents: 7594
diff changeset
   270
        if (TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0) and (TestCollisionYwithGear(HHGear, -hwSign(HHGear^.dY)) = 0) then
7596
nemo
parents: 7595
diff changeset
   271
            HHGear^.dY.isNegative:= not HHGear^.dY.isNegative;
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   272
        end;
7604
c143c942b5fe Hack to try and appease the shoppa players
nemo
parents: 7602
diff changeset
   273
*)
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   274
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   275
    mdX := ropeDx + HHGear^.dX;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   276
    mdY := ropeDy + HHGear^.dY;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   277
    len := _1 / Distance(mdX, mdY);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   278
    // rope vector plus hedgehog direction vector normalized
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   279
    mdX := mdX * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   280
    mdY := mdY * len;
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
    // for visual purposes only
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   283
    Gear^.dX := mdX;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   284
    Gear^.dY := mdY;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   285
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   286
    /////
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   287
    tx := HHGear^.X;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   288
    ty := HHGear^.Y;
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
    HHGear^.X := Gear^.X + mdX * Gear^.Elasticity;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   291
    HHGear^.Y := Gear^.Y + mdY * Gear^.Elasticity;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   292
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   293
    HHGear^.dX := HHGear^.X - tx;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   294
    HHGear^.dY := HHGear^.Y - ty;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   295
    ////
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   296
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
    haveDivided := false;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   299
    // check whether rope needs dividing
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   300
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   301
    len := Gear^.Elasticity - _5;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   302
    nx := Gear^.X + mdX * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   303
    ny := Gear^.Y + mdY * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   304
    tx := mdX * _2_4; // should be the same as increase step
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   305
    ty := mdY * _2_4;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   306
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   307
    while len > _3 do
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
        lx := hwRound(nx);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   310
        ly := hwRound(ny);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   311
        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
   312
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   313
            ny := _1 / Distance(ropeDx, ropeDy);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   314
            // old rope pos
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   315
            nx := ropeDx * ny;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   316
            ny := ropeDy * ny;
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
            with RopePoints.ar[RopePoints.Count] do
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   319
                begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   320
                X := Gear^.X;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   321
                Y := Gear^.Y;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   322
                if RopePoints.Count = 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   323
                    RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   324
                b := (nx * HHGear^.dY) > (ny * HHGear^.dX);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   325
                dLen := len
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   326
                end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   327
                
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   328
            with RopePoints.rounded[RopePoints.Count] do
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   329
                begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   330
                X := hwRound(Gear^.X);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   331
                Y := hwRound(Gear^.Y);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   332
                end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   333
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   334
            Gear^.X := Gear^.X + nx * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   335
            Gear^.Y := Gear^.Y + ny * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   336
            inc(RopePoints.Count);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   337
            TryDo(RopePoints.Count <= MAXROPEPOINTS, 'Rope points overflow', true);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   338
            Gear^.Elasticity := Gear^.Elasticity - len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   339
            Gear^.Friction := Gear^.Friction - len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   340
            haveDivided := true;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   341
            break
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   342
            end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   343
        nx := nx - tx;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   344
        ny := ny - ty;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   345
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   346
        // len := len - _2_4 // should be the same as increase step
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   347
        len.QWordValue := len.QWordValue - _2_4.QWordValue;
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
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   350
    if not haveDivided then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   351
        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
   352
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   353
            tx := RopePoints.ar[Pred(RopePoints.Count)].X;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   354
            ty := RopePoints.ar[Pred(RopePoints.Count)].Y;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   355
            mdX := tx - Gear^.X;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   356
            mdY := ty - Gear^.Y;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   357
            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
   358
                begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   359
                dec(RopePoints.Count);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   360
                Gear^.X := RopePoints.ar[RopePoints.Count].X;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   361
                Gear^.Y := RopePoints.ar[RopePoints.Count].Y;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   362
                Gear^.Elasticity := Gear^.Elasticity + RopePoints.ar[RopePoints.Count].dLen;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   363
                Gear^.Friction := Gear^.Friction + RopePoints.ar[RopePoints.Count].dLen;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   364
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   365
                // restore hog position
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   366
                len := _1 / Distance(mdX, mdY);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   367
                mdX := mdX * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   368
                mdY := mdY * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   369
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   370
                HHGear^.X := Gear^.X - mdX * Gear^.Elasticity;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   371
                HHGear^.Y := Gear^.Y - mdY * Gear^.Elasticity;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   372
                end
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   373
            end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   374
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   375
    haveCollision := false;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   376
    if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   377
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   378
        HHGear^.dX := -_0_6 * HHGear^.dX;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   379
        haveCollision := true
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   380
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   381
    if TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   382
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   383
        HHGear^.dY := -_0_6 * HHGear^.dY;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   384
        haveCollision := true
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   385
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   386
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   387
    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
   388
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   389
        HHGear^.dX := SignAs(hwAbs(HHGear^.dX) + _1_6, HHGear^.dX);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   390
        HHGear^.dY := SignAs(hwAbs(HHGear^.dY) + _1_6, HHGear^.dY)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   391
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   392
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   393
    len := hwSqr(HHGear^.dX) + hwSqr(HHGear^.dY);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   394
    if len > _49 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
        len := _7 / hwSqrt(len);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   397
        HHGear^.dX := HHGear^.dX * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   398
        HHGear^.dY := HHGear^.dY * len;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   399
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   400
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   401
    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
   402
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   403
    if not haveCollision then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   404
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   405
        // backup gear location
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   406
        tx:= Gear^.X;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   407
        ty:= Gear^.Y;
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
        if RopePoints.Count > 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   410
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   411
            // 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
   412
            Gear^.X:= RopePoints.ar[0].X;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   413
            Gear^.Y:= RopePoints.ar[0].Y;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   414
            end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   415
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   416
        CheckCollision(Gear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   417
        // 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
   418
        if (Gear^.State and gstCollision) = 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   419
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   420
            Gear^.dX.isNegative:= not Gear^.dX.isNegative;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   421
            Gear^.dY.isNegative:= not Gear^.dY.isNegative;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   422
            CheckCollision(Gear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   423
            Gear^.dX.isNegative:= not Gear^.dX.isNegative;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   424
            Gear^.dY.isNegative:= not Gear^.dY.isNegative;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   425
            end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   426
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   427
        haveCollision:= (Gear^.State and gstCollision) <> 0;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   428
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   429
        // restore gear location
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   430
        Gear^.X:= tx;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   431
        Gear^.Y:= ty;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   432
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   433
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   434
    // if the attack key is pressed, lose rope contact as well
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   435
    if (Gear^.Message and gmAttack) <> 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   436
        haveCollision:= false;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   437
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   438
    if not haveCollision then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   439
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   440
        if (Gear^.State and gsttmpFlag) <> 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   441
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   442
            if Gear^.Hedgehog^.CurAmmoType <> amParachute then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   443
                RopeWaitCollision(Gear, HHGear)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   444
            else
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   445
                RopeDeleteMe(Gear, HHGear)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   446
            end
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   447
        end
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   448
    else
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   449
        if (Gear^.State and gsttmpFlag) = 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   450
            Gear^.State := Gear^.State or gsttmpFlag;
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
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   453
procedure RopeRemoveFromAmmo(Gear, HHGear: PGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   454
begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   455
    if (Gear^.State and gstAttacked) = 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   456
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   457
        OnUsedAmmo(HHGear^.Hedgehog^);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   458
        Gear^.State := Gear^.State or gstAttacked
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   459
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   460
    ApplyAmmoChanges(HHGear^.Hedgehog^)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   461
end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   462
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   463
procedure doStepRopeAttach(Gear: PGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   464
var 
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   465
    HHGear: PGear;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   466
    tx, ty, tt: hwFloat;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   467
begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   468
    Gear^.X := Gear^.X - Gear^.dX;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   469
    Gear^.Y := Gear^.Y - Gear^.dY;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   470
    Gear^.Elasticity := Gear^.Elasticity + _1;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   471
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   472
    HHGear := Gear^.Hedgehog^.Gear;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   473
    DeleteCI(HHGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   474
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   475
    if (HHGear^.State and gstMoving) <> 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   476
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   477
        if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   478
            SetLittle(HHGear^.dX);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   479
        if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   480
            HHGear^.dY := _0;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   481
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   482
        HHGear^.X := HHGear^.X + HHGear^.dX;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   483
        Gear^.X := Gear^.X + HHGear^.dX;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   484
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   485
        if TestCollisionYwithGear(HHGear, 1) <> 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   486
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   487
            CheckHHDamage(HHGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   488
            HHGear^.dY := _0
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   489
            //HHGear^.State:= HHGear^.State and (not (gstHHJumping or gstHHHJump));
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   490
            end
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   491
        else
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   492
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   493
            HHGear^.Y := HHGear^.Y + HHGear^.dY;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   494
            Gear^.Y := Gear^.Y + HHGear^.dY;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   495
            HHGear^.dY := HHGear^.dY + cGravity;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   496
            if (GameFlags and gfMoreWind) <> 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   497
                HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   498
            end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   499
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   500
        tt := Gear^.Elasticity;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   501
        tx := _0;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   502
        ty := _0;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   503
        while tt > _20 do
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   504
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   505
            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
   506
                begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   507
                Gear^.X := Gear^.X + tx;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   508
                Gear^.Y := Gear^.Y + ty;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   509
                Gear^.Elasticity := tt;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   510
                Gear^.doStep := @doStepRopeWork;
7602
a620319d377e Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents: 7601
diff changeset
   511
                Gear^.stepFreq:= 8;
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   512
                PlaySound(sndRopeAttach);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   513
                with HHGear^ do
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   514
                    begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   515
                    dX.QWordValue:= dX.QWordValue shl 3;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   516
                    dY.QWordValue:= dY.QWordValue shl 3;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   517
                    State := State and (not (gstAttacking or gstHHJumping or gstHHHJump));
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   518
                    Message := Message and (not gmAttack)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   519
                    end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   520
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   521
                RopeRemoveFromAmmo(Gear, HHGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   522
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   523
                tt := _0;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   524
                exit
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   525
                end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   526
            tx := tx + Gear^.dX + Gear^.dX;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   527
            ty := ty + Gear^.dY + Gear^.dY;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   528
            tt := tt - _2;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   529
            end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   530
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   531
7601
c96ff1a053d0 Allow escaping from tight spots
nemo
parents: 7596
diff changeset
   532
    if Gear^.Elasticity < _20 then Gear^.CollisionMask:= $FF00
c96ff1a053d0 Allow escaping from tight spots
nemo
parents: 7596
diff changeset
   533
    else Gear^.CollisionMask:= $FF7F;
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   534
    CheckCollision(Gear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   535
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   536
    if (Gear^.State and gstCollision) <> 0 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   537
        if Gear^.Elasticity < _10 then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   538
            Gear^.Elasticity := _10000
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   539
    else
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   540
        begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   541
        Gear^.doStep := @doStepRopeWork;
7602
a620319d377e Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents: 7601
diff changeset
   542
        Gear^.stepFreq:= 8;
7594
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   543
        PlaySound(sndRopeAttach);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   544
        with HHGear^ do
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   545
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   546
            dX.QWordValue:= dX.QWordValue shl 3;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   547
            dY.QWordValue:= dY.QWordValue shl 3;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   548
            State := State and (not (gstAttacking or gstHHJumping or gstHHHJump));
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   549
            Message := Message and (not gmAttack)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   550
            end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   551
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   552
        RopeRemoveFromAmmo(Gear, HHGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   553
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   554
        exit
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   555
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   556
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   557
    if (Gear^.Elasticity > Gear^.Friction)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   558
        or ((Gear^.Message and gmAttack) = 0)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   559
        or ((HHGear^.State and gstHHDriven) = 0)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   560
        or (HHGear^.Damage > 0) then
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   561
            begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   562
            with Gear^.Hedgehog^.Gear^ do
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   563
                begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   564
                State := State and (not gstAttacking);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   565
                Message := Message and (not gmAttack)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   566
                end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   567
        DeleteGear(Gear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   568
        exit;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   569
        end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   570
    if CheckGearDrowning(HHGear) then DeleteGear(Gear)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   571
end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   572
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   573
procedure doStepRope(Gear: PGear);
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   574
begin
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   575
    Gear^.dX := - Gear^.dX;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   576
    Gear^.dY := - Gear^.dY;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   577
    Gear^.doStep := @doStepRopeAttach;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   578
    PlaySound(sndRopeShot)
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   579
end;
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   580
5f03595335e6 fromdos + fix end of turn velocity
nemo
parents: 7593
diff changeset
   581
end.