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