hedgewars/uGearsHandlersRope.pas
author Wuzzy <Wuzzy2@mail.ru>
Thu, 03 Jan 2019 19:46:48 +0100
changeset 14535 5ac181cb2396
parent 14303 6015b74eea55
child 14674 4aec7d17ef7d
permissions -rw-r--r--
Fix bee targeting fail across wrap world edge Previously, the bee always aimed for the light area, no matter where you actually put the target. It also got confused whenever it flew across the wrap world edge. How the bee works now: 1) The placed bee target is *not* recalculated when it was placed in the "gray" part of the wrap world edge. This allows for more fine-tuning. 1a) Place target in light area: bee aims for target light area 1b) Place target in gray area: bee aims for target, but flies to gray area first 2) Bee target is recalculated whenever bee passes the wrap world edge.
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10722
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
7660
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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10017
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7660
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,
13077
c213645ff848 Having chat mode as game state was a mistake
unc0rr
parents: 13069
diff changeset
    29
    uAmmos, uDebug, uUtils, uGearsHedgehog, uGearsRender;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    30
10684
d403fd2f9a6f merge'n'magic
sheepluva
parents: 10680 10681
diff changeset
    31
const
10722
37264e44ec0f Was not a good idea in the first place IMO
nemo
parents: 10684
diff changeset
    32
    IsNilHHFatal = false;
10684
d403fd2f9a6f merge'n'magic
sheepluva
parents: 10680 10681
diff changeset
    33
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    34
procedure doStepRopeAfterAttack(Gear: PGear);
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
    35
var
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    36
    HHGear: PGear;
9526
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
    37
    tX:     hwFloat;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    38
begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    39
    HHGear := Gear^.Hedgehog^.Gear;
10681
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
    40
    if HHGear = nil then
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
    41
        begin
10684
d403fd2f9a6f merge'n'magic
sheepluva
parents: 10680 10681
diff changeset
    42
        OutError('ERROR: doStepRopeAfterAttack called while HHGear = nil', IsNilHHFatal);
10681
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
    43
        DeleteGear(Gear);
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
    44
        exit()
11258
6d5505bff3f3 refocus camera on roping hog. totally untested.
nemo
parents: 11046
diff changeset
    45
        end
11266
31e0e38e703c Make camera refocus less aggressive. Only if there's a camera target already.
nemo
parents: 11258
diff changeset
    46
    else if not CurrentTeam^.ExtDriven and (FollowGear <> nil) then FollowGear := HHGear;
10681
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
    47
9526
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
    48
    tX:= HHGear^.X;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
    49
    if WorldWrap(HHGear) and (WorldEdge = weWrap) and
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
    50
       ((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0))  then
9526
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
    51
        begin
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
    52
        HHGear^.X:= tX;
14303
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13994
diff changeset
    53
        HHGear^.dX.isNegative:= hwRound(tX) > leftX + HHGear^.Radius * 2
9526
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
    54
        end;
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
    55
8680
5fe344cc8610 prevent an old abuse of parachute to land safely
nemo
parents: 8468
diff changeset
    56
    if (HHGear^.Hedgehog^.CurAmmoType = amParachute) and (HHGear^.dY > _0_39) then
5fe344cc8610 prevent an old abuse of parachute to land safely
nemo
parents: 8468
diff changeset
    57
        begin
5fe344cc8610 prevent an old abuse of parachute to land safely
nemo
parents: 8468
diff changeset
    58
        DeleteGear(Gear);
5fe344cc8610 prevent an old abuse of parachute to land safely
nemo
parents: 8468
diff changeset
    59
        ApplyAmmoChanges(HHGear^.Hedgehog^);
5fe344cc8610 prevent an old abuse of parachute to land safely
nemo
parents: 8468
diff changeset
    60
        HHGear^.Message:= HHGear^.Message or gmLJump;
5fe344cc8610 prevent an old abuse of parachute to land safely
nemo
parents: 8468
diff changeset
    61
        exit
5fe344cc8610 prevent an old abuse of parachute to land safely
nemo
parents: 8468
diff changeset
    62
        end;
5fe344cc8610 prevent an old abuse of parachute to land safely
nemo
parents: 8468
diff changeset
    63
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    64
    if ((HHGear^.State and gstHHDriven) = 0)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    65
    or (CheckGearDrowning(HHGear))
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    66
    or (TestCollisionYwithGear(HHGear, 1) <> 0) then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    67
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    68
        DeleteGear(Gear);
13977
2568fa516733 Fix hog can drop more than 2 s. mines if first one was dropped from utility, then stop using that utility
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
    69
        if (TestCollisionYwithGear(HHGear, 1) <> 0) and (GetAmmoEntry(HHGear^.Hedgehog^, amRope)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
12821
f3e07e53460d Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents: 12819
diff changeset
    70
            HHGear^.Hedgehog^.CurAmmoType:= amRope;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    71
        isCursorVisible := false;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    72
        ApplyAmmoChanges(HHGear^.Hedgehog^);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    73
        exit
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
    HedgehogChAngle(HHGear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    77
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
    78
    if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) <> 0 then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    79
        SetLittle(HHGear^.dX);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    80
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    81
    if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    82
        HHGear^.dY := _0;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    83
    HHGear^.X := HHGear^.X + HHGear^.dX;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    84
    HHGear^.Y := HHGear^.Y + HHGear^.dY;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    85
    HHGear^.dY := HHGear^.dY + cGravity;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
    86
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    87
    if (GameFlags and gfMoreWind) <> 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    88
        HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    89
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    90
    if (Gear^.Message and gmAttack) <> 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    91
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    92
        Gear^.X := HHGear^.X;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    93
        Gear^.Y := HHGear^.Y;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    94
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    95
        ApplyAngleBounds(Gear^.Hedgehog^, amRope);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    96
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    97
        Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    98
        Gear^.dY := -AngleCos(HHGear^.Angle);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
    99
        Gear^.Friction := _4_5 * cRopePercent;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   100
        Gear^.Elasticity := _0;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   101
        Gear^.State := Gear^.State and (not gsttmpflag);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   102
        Gear^.doStep := @doStepRope;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   103
        end
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   104
end;
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
procedure RopeDeleteMe(Gear, HHGear: PGear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   107
begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   108
    with HHGear^ do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   109
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   110
        Message := Message and (not gmAttack);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   111
        State := (State or gstMoving) and (not gstWinner);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   112
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   113
    DeleteGear(Gear)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   114
end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   115
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   116
procedure RopeWaitCollision(Gear, HHGear: PGear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   117
begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   118
    with HHGear^ do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   119
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   120
        Message := Message and (not gmAttack);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   121
        State := State or gstMoving;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   122
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   123
    RopePoints.Count := 0;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   124
    Gear^.Elasticity := _0;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   125
    Gear^.doStep := @doStepRopeAfterAttack
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   126
end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   127
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   128
procedure doStepRopeWork(Gear: PGear);
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   129
var
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   130
    HHGear: PGear;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   131
    len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   132
    lx, ly, cd: LongInt;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   133
    haveCollision,
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   134
    haveDivided: boolean;
8733
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   135
    wrongSide: boolean;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   136
begin
10680
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   137
    HHGear := Gear^.Hedgehog^.Gear;
10681
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   138
    if HHGear = nil then
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   139
        begin
10684
d403fd2f9a6f merge'n'magic
sheepluva
parents: 10680 10681
diff changeset
   140
        OutError('ERROR: doStepRopeWork called while HHGear = nil', IsNilHHFatal);
10681
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   141
        DeleteGear(Gear);
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   142
        exit()
11258
6d5505bff3f3 refocus camera on roping hog. totally untested.
nemo
parents: 11046
diff changeset
   143
        end
11266
31e0e38e703c Make camera refocus less aggressive. Only if there's a camera target already.
nemo
parents: 11258
diff changeset
   144
    else if not CurrentTeam^.ExtDriven and (FollowGear <> nil) then FollowGear := HHGear;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   145
10680
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   146
    if ((HHGear^.State and gstHHDriven) = 0) or
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   147
        (CheckGearDrowning(HHGear)) or (Gear^.PortalCounter <> 0) then
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   148
        begin
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   149
        PlaySound(sndRopeRelease);
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   150
        RopeDeleteMe(Gear, HHGear);
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   151
        exit
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   152
        end;
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   153
4a4a82686e91 Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents: 10108
diff changeset
   154
    if GameTicks mod 4 <> 0 then exit;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   155
9526
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   156
    tX:= HHGear^.X;
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   157
    if WorldWrap(HHGear) and (WorldEdge = weWrap) and
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   158
       ((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0))  then
9526
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   159
        begin
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   160
        PlaySound(sndRopeRelease);
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   161
        RopeDeleteMe(Gear, HHGear);
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   162
        HHGear^.X:= tX;
14303
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13994
diff changeset
   163
        HHGear^.dX.isNegative:= hwRound(tX) > leftX + HHGear^.Radius * 2;
9526
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   164
        exit
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   165
        end;
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   166
2fd51591b260 make wrapping nicer when there's collision
nemo
parents: 9473
diff changeset
   167
    tX:= HHGear^.X;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   168
    HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue shl 2;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   169
    HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue shl 2;
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   170
    if (Gear^.Message and gmLeft  <> 0) and (TestCollisionXwithGear(HHGear, -1) = 0) then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   171
        HHGear^.dX := HHGear^.dX - _0_0032;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   172
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   173
    if (Gear^.Message and gmRight <> 0) and (TestCollisionXwithGear(HHGear,  1) = 0) then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   174
        HHGear^.dX := HHGear^.dX + _0_0032;
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
    // vector between hedgehog and rope attaching point
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   177
    ropeDx := HHGear^.X - Gear^.X;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   178
    ropeDy := HHGear^.Y - Gear^.Y;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   179
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   180
    if TestCollisionYwithXYShift(HHGear, 0, 1, 1) = 0 then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   181
        begin
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
        // 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
   184
        // 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
   185
        if ropeDx.isNegative = RopeDy.IsNegative then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   186
            cd:= -1
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   187
        else
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   188
            cd:= 1;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   189
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   190
        // apply gravity if there is no obstacle
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   191
        if TestCollisionXwithXYShift(HHGear, _2*cd, 0, cd, true) = 0 then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   192
            HHGear^.dY := HHGear^.dY + cGravity * 16;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   193
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   194
        if (GameFlags and gfMoreWind) <> 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   195
            // apply wind if there's no obstacle
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   196
            if TestCollisionXwithGear(HHGear, hwSign(cWindSpeed)) = 0 then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   197
                HHGear^.dX := HHGear^.dX + cWindSpeed * 16 / HHGear^.Density;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   198
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   199
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   200
    mdX := ropeDx + HHGear^.dX;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   201
    mdY := ropeDy + HHGear^.dY;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   202
    len := _1 / Distance(mdX, mdY);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   203
    // rope vector plus hedgehog direction vector normalized
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   204
    mdX := mdX * len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   205
    mdY := mdY * len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   206
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   207
    // for visual purposes only
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   208
    Gear^.dX := mdX;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   209
    Gear^.dY := mdY;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   210
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   211
    /////
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   212
    tx := HHGear^.X;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   213
    ty := HHGear^.Y;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   214
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   215
    if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   216
        if not ((TestCollisionXwithXYShift(HHGear, _2*hwSign(ropeDx), 0, hwSign(ropeDx), true) <> 0)
13994
818969052920 Fix bug 651: sliding hog firing rope could end up stuck in land right after the rope has attached
unc0rr
parents: 13977
diff changeset
   217
        or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, hwSign(ropeDy), hwSign(ropeDy)) <> 0))) then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   218
            Gear^.Elasticity := Gear^.Elasticity + _1_2;
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
    if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   221
        if not ((TestCollisionXwithXYShift(HHGear, -_2*hwSign(ropeDx), 0, -hwSign(ropeDx), true) <> 0)
13994
818969052920 Fix bug 651: sliding hog firing rope could end up stuck in land right after the rope has attached
unc0rr
parents: 13977
diff changeset
   222
        or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, -hwSign(ropeDy), -hwSign(ropeDy)) <> 0))) then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   223
            Gear^.Elasticity := Gear^.Elasticity - _1_2;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   224
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   225
    HHGear^.X := Gear^.X + mdX * Gear^.Elasticity;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   226
    HHGear^.Y := Gear^.Y + mdY * Gear^.Elasticity;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   227
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   228
    HHGear^.dX := HHGear^.X - tx;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   229
    HHGear^.dY := HHGear^.Y - ty;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   230
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   231
    haveDivided := false;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   232
    // check whether rope needs dividing
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   233
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   234
    len := Gear^.Elasticity - _5;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   235
    nx := Gear^.X + mdX * len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   236
    ny := Gear^.Y + mdY * len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   237
    tx := mdX * _1_2; // should be the same as increase step
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   238
    ty := mdY * _1_2;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   239
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   240
    while len > _3 do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   241
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   242
        lx := hwRound(nx);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   243
        ly := hwRound(ny);
8751
4609823efc94 More flagging of Land values. Also use less than for tests of non-terrain, instead of "and $FF00 = 0". Saves a couple of ops, which actually matters a small amount in a few places.
nemo
parents: 8744
diff changeset
   244
        if ((ly and LAND_HEIGHT_MASK) = 0) and ((lx and LAND_WIDTH_MASK) = 0) and (Land[ly, lx] > lfAllObjMask) then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   245
            begin
8397
5b273af3ac95 Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents: 7674
diff changeset
   246
            tx := _1 / Distance(ropeDx, ropeDy);
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   247
            // old rope pos
8397
5b273af3ac95 Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents: 7674
diff changeset
   248
            nx := ropeDx * tx;
5b273af3ac95 Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents: 7674
diff changeset
   249
            ny := ropeDy * tx;
7660
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
            with RopePoints.ar[RopePoints.Count] do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   252
                begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   253
                X := Gear^.X;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   254
                Y := Gear^.Y;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   255
                if RopePoints.Count = 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   256
                    RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   257
                b := (nx * HHGear^.dY) > (ny * HHGear^.dX);
8733
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   258
                sx:= Gear^.dX.isNegative;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   259
                sy:= Gear^.dY.isNegative;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   260
                sb:= Gear^.dX.QWordValue < Gear^.dY.QWordValue;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   261
                dLen := len
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   262
                end;
8397
5b273af3ac95 Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents: 7674
diff changeset
   263
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   264
            with RopePoints.rounded[RopePoints.Count] do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   265
                begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   266
                X := hwRound(Gear^.X);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   267
                Y := hwRound(Gear^.Y);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   268
                end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   269
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   270
            Gear^.X := Gear^.X + nx * len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   271
            Gear^.Y := Gear^.Y + ny * len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   272
            inc(RopePoints.Count);
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11266
diff changeset
   273
            if checkFails(RopePoints.Count <= MAXROPEPOINTS, 'Rope points overflow', true) then exit;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   274
            Gear^.Elasticity := Gear^.Elasticity - len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   275
            Gear^.Friction := Gear^.Friction - len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   276
            haveDivided := true;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   277
            break
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   278
            end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   279
        nx := nx - tx;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   280
        ny := ny - ty;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   281
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   282
        // len := len - _1_2 // should be the same as increase step
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   283
        len.QWordValue := len.QWordValue - _1_2.QWordValue;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   284
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   285
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   286
    if not haveDivided then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   287
        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
   288
            begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   289
            tx := RopePoints.ar[Pred(RopePoints.Count)].X;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   290
            ty := RopePoints.ar[Pred(RopePoints.Count)].Y;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   291
            mdX := tx - Gear^.X;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   292
            mdY := ty - Gear^.Y;
8733
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   293
            ropeDx:= tx - HHGear^.X;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   294
            ropeDy:= ty - HHGear^.Y;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   295
            if RopePoints.ar[Pred(RopePoints.Count)].b xor (mdX * ropeDy > ropeDx * mdY) then
7660
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
                dec(RopePoints.Count);
8733
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   298
                Gear^.X := tx;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   299
                Gear^.Y := ty;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   300
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   301
                // oops, opposite quadrant, don't restore hog position in such case, just remove the point
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   302
                wrongSide:= (ropeDx.isNegative = RopePoints.ar[RopePoints.Count].sx)
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   303
                    and (ropeDy.isNegative = RopePoints.ar[RopePoints.Count].sy);
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   304
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   305
                // previous check could be inaccurate in vertical/horizontal rope positions,
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   306
                // so perform this check also, even though odds are 1 to 415927 to hit this
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   307
                if (not wrongSide)
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   308
                    and ((ropeDx.isNegative = RopePoints.ar[RopePoints.Count].sx)
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   309
                      <> (ropeDy.isNegative = RopePoints.ar[RopePoints.Count].sy)) then
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   310
                    if RopePoints.ar[RopePoints.Count].sb then
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   311
                        wrongSide:= ropeDy.isNegative = RopePoints.ar[RopePoints.Count].sy
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   312
                        else
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   313
                        wrongSide:= ropeDx.isNegative = RopePoints.ar[RopePoints.Count].sx;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   314
8733
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   315
                if wrongSide then
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   316
                    begin
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   317
                    Gear^.Elasticity := Gear^.Elasticity - RopePoints.ar[RopePoints.Count].dLen;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   318
                    Gear^.Friction := Gear^.Friction - RopePoints.ar[RopePoints.Count].dLen;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   319
                    end else
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   320
                    begin
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   321
                    Gear^.Elasticity := Gear^.Elasticity + RopePoints.ar[RopePoints.Count].dLen;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   322
                    Gear^.Friction := Gear^.Friction + RopePoints.ar[RopePoints.Count].dLen;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   323
8733
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   324
                    // restore hog position
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   325
                    len := _1 / Distance(mdX, mdY);
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   326
                    mdX := mdX * len;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   327
                    mdY := mdY * len;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   328
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   329
                    HHGear^.X := Gear^.X - mdX * Gear^.Elasticity;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   330
                    HHGear^.Y := Gear^.Y - mdY * Gear^.Elasticity;
b6002f1956d5 Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents: 8680
diff changeset
   331
                    end;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   332
                end
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   333
            end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   334
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   335
    haveCollision := false;
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   336
    if TestCollisionXwithXYShift(HHGear, _2*hwSign(HHGear^.dX), 0, hwSign(HHGear^.dX), true) <> 0 then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   337
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   338
        HHGear^.dX := -_0_6 * HHGear^.dX;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   339
        haveCollision := true
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   340
        end;
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9683
diff changeset
   341
    if TestCollisionYwithXYShift(HHGear, 0, 1*hwSign(HHGear^.dY), hwSign(HHGear^.dY)) <> 0 then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   342
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   343
        HHGear^.dY := -_0_6 * HHGear^.dY;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   344
        haveCollision := true
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   345
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   346
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   347
    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
   348
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   349
        HHGear^.dX := SignAs(hwAbs(HHGear^.dX) + _0_8, HHGear^.dX);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   350
        HHGear^.dY := SignAs(hwAbs(HHGear^.dY) + _0_8, HHGear^.dY)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   351
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   352
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   353
    len := hwSqr(HHGear^.dX) + hwSqr(HHGear^.dY);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   354
    if len > _10 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   355
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   356
        len := _3_2 / hwSqrt(len);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   357
        HHGear^.dX := HHGear^.dX * len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   358
        HHGear^.dY := HHGear^.dY * len;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   359
        end;
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
    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
   362
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   363
    if not haveCollision then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   364
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   365
        // backup gear location
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   366
        tx:= Gear^.X;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   367
        ty:= Gear^.Y;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   368
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   369
        if RopePoints.Count > 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   370
            begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   371
            // 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
   372
            Gear^.X:= RopePoints.ar[0].X;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   373
            Gear^.Y:= RopePoints.ar[0].Y;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   374
            end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   375
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   376
        CheckCollision(Gear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   377
        // 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
   378
        if (Gear^.State and gstCollision) = 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   379
            begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   380
            Gear^.dX.isNegative:= not Gear^.dX.isNegative;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   381
            Gear^.dY.isNegative:= not Gear^.dY.isNegative;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   382
            CheckCollision(Gear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   383
            Gear^.dX.isNegative:= not Gear^.dX.isNegative;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   384
            Gear^.dY.isNegative:= not Gear^.dY.isNegative;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   385
            end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   386
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   387
        haveCollision:= (Gear^.State and gstCollision) <> 0;
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
        // restore gear location
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   390
        Gear^.X:= tx;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   391
        Gear^.Y:= ty;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   392
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   393
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   394
    // if the attack key is pressed, lose rope contact as well
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   395
    if (Gear^.Message and gmAttack) <> 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   396
        haveCollision:= false;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   397
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   398
    HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue shr 2;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   399
    HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue shr 2;
7674
aead327f1e1a fix for issue 293 : "rope stuck after picking crate"
sheepluva
parents: 7662
diff changeset
   400
    if (not haveCollision) and ((Gear^.State and gsttmpFlag) <> 0) then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   401
        begin
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
            PlaySound(sndRopeRelease);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   404
            if Gear^.Hedgehog^.CurAmmoType <> amParachute then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   405
                RopeWaitCollision(Gear, HHGear)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   406
            else
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   407
                RopeDeleteMe(Gear, HHGear)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   408
            end
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   409
        end
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   410
    else
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   411
        if (Gear^.State and gsttmpFlag) = 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   412
            Gear^.State := Gear^.State or gsttmpFlag;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   413
end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   414
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   415
procedure RopeRemoveFromAmmo(Gear, HHGear: PGear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   416
begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   417
    if (Gear^.State and gstAttacked) = 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   418
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   419
        OnUsedAmmo(HHGear^.Hedgehog^);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   420
        Gear^.State := Gear^.State or gstAttacked
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   421
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   422
    ApplyAmmoChanges(HHGear^.Hedgehog^)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   423
end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   424
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   425
procedure doStepRopeAttach(Gear: PGear);
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9998
diff changeset
   426
var
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   427
    HHGear: PGear;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   428
    tx, ty, tt: hwFloat;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   429
begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   430
    Gear^.X := Gear^.X - Gear^.dX;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   431
    Gear^.Y := Gear^.Y - Gear^.dY;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   432
    Gear^.Elasticity := Gear^.Elasticity + _1;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   433
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   434
    HHGear := Gear^.Hedgehog^.Gear;
10681
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   435
    if HHGear = nil then
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   436
        begin
10684
d403fd2f9a6f merge'n'magic
sheepluva
parents: 10680 10681
diff changeset
   437
        OutError('ERROR: doStepRopeAttach called while HHGear = nil', IsNilHHFatal);
10681
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   438
        DeleteGear(Gear);
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   439
        exit()
11258
6d5505bff3f3 refocus camera on roping hog. totally untested.
nemo
parents: 11046
diff changeset
   440
        end
11266
31e0e38e703c Make camera refocus less aggressive. Only if there's a camera target already.
nemo
parents: 11258
diff changeset
   441
    else if not CurrentTeam^.ExtDriven and (FollowGear <> nil) then FollowGear := HHGear;
10681
474d418a34c5 Add nil checks on HHGear to rope steps.
nemo
parents: 10108
diff changeset
   442
12651
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   443
    // Destroy rope if it touched bouncy or world wrap world edge.
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   444
    // TODO: Allow to shoot rope through the world wrap edge and rope normally.
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   445
    if (WorldWrap(Gear) and (WorldEdge = weWrap)) or
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   446
       ((WorldEdge = weBounce) and ((hwRound(Gear^.X) <= LeftX) or (hwRound(Gear^.X) >= RightX))) then
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   447
        begin
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   448
        HHGear^.State := HHGear^.State and (not (gstAttacking or gstHHJumping or gstHHHJump));
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   449
        HHGear^.Message := HHGear^.Message and (not gmAttack);
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   450
        DeleteGear(Gear);
13977
2568fa516733 Fix hog can drop more than 2 s. mines if first one was dropped from utility, then stop using that utility
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
   451
        if (GetAmmoEntry(HHGear^.Hedgehog^, amRope)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
12821
f3e07e53460d Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents: 12819
diff changeset
   452
            HHGear^.Hedgehog^.CurAmmoType:= amRope;
f3e07e53460d Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents: 12819
diff changeset
   453
        isCursorVisible := false;
f3e07e53460d Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents: 12819
diff changeset
   454
        ApplyAmmoChanges(HHGear^.Hedgehog^);
12651
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   455
        exit()
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   456
        end;
5e115ed19e27 Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents: 11831
diff changeset
   457
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   458
    DeleteCI(HHGear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   459
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   460
    if (HHGear^.State and gstMoving) <> 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   461
        begin
13069
ba7ac61c7668 falling hogs using rope were ignoring a few things (for example taking damage from rubber)
nemo
parents: 12821
diff changeset
   462
        doStepHedgehogMoving(HHGear);
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   463
        Gear^.X := Gear^.X + HHGear^.dX;
13069
ba7ac61c7668 falling hogs using rope were ignoring a few things (for example taking damage from rubber)
nemo
parents: 12821
diff changeset
   464
        Gear^.Y := Gear^.Y + HHGear^.dY;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   465
13994
818969052920 Fix bug 651: sliding hog firing rope could end up stuck in land right after the rope has attached
unc0rr
parents: 13977
diff changeset
   466
        // hedgehog can teleport up to 5 pixels upwards when sliding,
818969052920 Fix bug 651: sliding hog firing rope could end up stuck in land right after the rope has attached
unc0rr
parents: 13977
diff changeset
   467
        // so we have to give up the maintained rope length
818969052920 Fix bug 651: sliding hog firing rope could end up stuck in land right after the rope has attached
unc0rr
parents: 13977
diff changeset
   468
        // after doStepHedgehogMoving() call and recalculate
818969052920 Fix bug 651: sliding hog firing rope could end up stuck in land right after the rope has attached
unc0rr
parents: 13977
diff changeset
   469
        // it based on the gear and current hedgehog positions
818969052920 Fix bug 651: sliding hog firing rope could end up stuck in land right after the rope has attached
unc0rr
parents: 13977
diff changeset
   470
        Gear^.Elasticity:= int2hwFloat(hwRound(Distance(Gear^.X - HHGear^.X, Gear^.Y - HHGear^.Y) + _0_001));
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   471
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   472
        tt := Gear^.Elasticity;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   473
        tx := _0;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   474
        ty := _0;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   475
        while tt > _20 do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   476
            begin
8751
4609823efc94 More flagging of Land values. Also use less than for tests of non-terrain, instead of "and $FF00 = 0". Saves a couple of ops, which actually matters a small amount in a few places.
nemo
parents: 8744
diff changeset
   477
            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)] > lfAllObjMask) then
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   478
                begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   479
                Gear^.X := Gear^.X + tx;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   480
                Gear^.Y := Gear^.Y + ty;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   481
                Gear^.Elasticity := tt;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   482
                Gear^.doStep := @doStepRopeWork;
13994
818969052920 Fix bug 651: sliding hog firing rope could end up stuck in land right after the rope has attached
unc0rr
parents: 13977
diff changeset
   483
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   484
                PlaySound(sndRopeAttach);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   485
                with HHGear^ do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   486
                    begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   487
                    State := State and (not (gstAttacking or gstHHJumping or gstHHHJump));
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   488
                    Message := Message and (not gmAttack)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   489
                    end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   490
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   491
                RopeRemoveFromAmmo(Gear, HHGear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   492
                exit
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   493
                end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   494
            tx := tx + Gear^.dX + Gear^.dX;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   495
            ty := ty + Gear^.dY + Gear^.dY;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   496
            tt := tt - _2;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   497
            end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   498
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   499
8751
4609823efc94 More flagging of Land values. Also use less than for tests of non-terrain, instead of "and $FF00 = 0". Saves a couple of ops, which actually matters a small amount in a few places.
nemo
parents: 8744
diff changeset
   500
    if Gear^.Elasticity < _20 then Gear^.CollisionMask:= lfLandMask
13469
f1d349a52bc7 Refactor: lfCurrentHog→lfCurHogCrate, lfNotCurrentMask→lfNotCurHogCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 13077
diff changeset
   501
    else Gear^.CollisionMask:= lfNotCurHogCrate; //lfNotObjMask or lfNotHHObjMask;
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   502
    CheckCollision(Gear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   503
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   504
    if (Gear^.State and gstCollision) <> 0 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   505
        if Gear^.Elasticity < _10 then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   506
            Gear^.Elasticity := _10000
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   507
    else
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   508
        begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   509
        Gear^.doStep := @doStepRopeWork;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   510
        PlaySound(sndRopeAttach);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   511
        with HHGear^ do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   512
            begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   513
            State := State and (not (gstAttacking or gstHHJumping or gstHHHJump));
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   514
            Message := Message and (not gmAttack)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   515
            end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   516
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   517
        RopeRemoveFromAmmo(Gear, HHGear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   518
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   519
        exit
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   520
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   521
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   522
    if (Gear^.Elasticity > Gear^.Friction)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   523
        or ((Gear^.Message and gmAttack) = 0)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   524
        or ((HHGear^.State and gstHHDriven) = 0)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   525
        or (HHGear^.Damage > 0) then
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   526
            begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   527
            with Gear^.Hedgehog^.Gear^ do
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   528
                begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   529
                State := State and (not gstAttacking);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   530
                Message := Message and (not gmAttack)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   531
                end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   532
        DeleteGear(Gear);
13977
2568fa516733 Fix hog can drop more than 2 s. mines if first one was dropped from utility, then stop using that utility
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
   533
        if (GetAmmoEntry(HHGear^.Hedgehog^, amRope)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
12821
f3e07e53460d Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents: 12819
diff changeset
   534
            HHGear^.Hedgehog^.CurAmmoType:= amRope;
f3e07e53460d Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents: 12819
diff changeset
   535
        isCursorVisible := false;
f3e07e53460d Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents: 12819
diff changeset
   536
        ApplyAmmoChanges(HHGear^.Hedgehog^);
7660
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   537
        exit;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   538
        end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   539
    if CheckGearDrowning(HHGear) then DeleteGear(Gear)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   540
end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   541
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   542
procedure doStepRope(Gear: PGear);
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   543
begin
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   544
    Gear^.dX := - Gear^.dX;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   545
    Gear^.dY := - Gear^.dY;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   546
    Gear^.doStep := @doStepRopeAttach;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   547
    PlaySound(sndRopeShot)
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   548
end;
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   549
8398faa1e628 Fix line endings, add missing amMine entry
nemo
parents: 7658
diff changeset
   550
end.