hedgewars/uCollisions.pas
author alfadur
Sun, 28 Jun 2020 20:34:06 +0300
changeset 15668 c2a1a34d1841
parent 15653 b2ed495a7fb1
child 15677 116307c752f6
permissions -rw-r--r--
refactor collision tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     1
(*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 967
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10818
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
    12
 * GNU General Public License for more details.
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
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: 10015
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    17
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    19
{$INCLUDE "options.inc"}
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    20
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    21
unit uCollisions;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
interface
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    23
uses uFloat, uTypes, uUtils;
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    24
5290
eea7570d345f This can afford to be a bit larger. Does not impact performance.
nemo
parents: 4976
diff changeset
    25
const cMaxGearArrayInd = 1023;
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    26
const cMaxGearHitOrderInd = 1023;
14027
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    27
const cMaxGearProximityCacheInd = 1023;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    28
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 68
diff changeset
    29
type PGearArray = ^TGearArray;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    30
    TGearArray = record
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
    31
        ar: array[0..cMaxGearArrayInd] of PGear;
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    32
        cX: array[0..cMaxGearArrayInd] of LongInt;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    33
        cY: array[0..cMaxGearArrayInd] of LongInt;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
    34
        Count: Longword
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
    35
        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    36
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    37
type PGearHitOrder = ^TGearHitOrder;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    38
    TGearHitOrder = record
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    39
        ar: array[0..cMaxGearHitOrderInd] of PGear;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    40
        order: array[0..cMaxGearHitOrderInd] of LongInt;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    41
        Count: Longword
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    42
        end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    43
14027
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    44
type PGearProximityCache = ^TGearProximityCache;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    45
    TGearProximityCache = record
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    46
        ar: array[0..cMaxGearProximityCacheInd] of PGear;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    47
        Count: Longword
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    48
        end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    49
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    50
type TLineCollision = record
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    51
        hasCollision: Boolean;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    52
        cX, cY: LongInt; //for visual effects only
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    53
        end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    54
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    55
type TKickTest = record
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    56
        kick: Boolean;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    57
        collisionMask: Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    58
    end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    59
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
    60
procedure initModule;
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
    61
procedure freeModule;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    62
9291
15f7bb217b66 Make add/delete consistent (this has bugged me for so long)
nemo
parents: 9247
diff changeset
    63
procedure AddCI(Gear: PGear);
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
    64
procedure DeleteCI(Gear: PGear);
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
    65
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    66
function  CheckGearsCollision(Gear: PGear): PGearArray;
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    67
function  CheckAllGearsCollision(SourceGear: PGear): PGearArray;
14027
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    68
function  CheckCacheCollision(SourceGear: PGear): PGearArray;
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    69
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    70
function  CheckGearsLineCollision(Gear: PGear; oX, oY, tX, tY: hwFloat): PGearArray;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    71
function  CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    72
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    73
function  UpdateHitOrder(Gear: PGear; Order: LongInt): boolean;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    74
procedure ClearHitOrderLeq(MinOrder: LongInt);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
    75
procedure ClearHitOrder();
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
    76
14027
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    77
procedure RefillProximityCache(SourceGear: PGear; radius: LongInt);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    78
procedure RemoveFromProximityCache(Gear: PGear);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    79
procedure ClearProximityCache();
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
    80
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    81
function  TestCollisionXImpl(centerX, centerY, radius, direction: LongInt; collisionMask: Word): Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    82
function  TestCollisionYImpl(centerX, centerY, radius, direction: LongInt; collisionMask: Word): Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    83
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    84
function  TestCollisionXwithGear(Gear: PGear; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    85
function  TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    86
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    87
function  TestCollisionX(Gear: PGear; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    88
function  TestCollisionY(Gear: PGear; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    89
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    90
function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    91
function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    92
function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    93
function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    94
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    95
function  TestCollisionXKickImpl(centerX, centerY, radius, direction: LongInt; collisionMask, kickMask: Word): TKickTest;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
    96
function  TestCollisionYKickImpl(centerX, centerY, radius, direction: LongInt; collisionMask, kickMask: Word): TKickTest;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
    97
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9305
diff changeset
    98
function  TestCollisionXKick(Gear: PGear; Dir: LongInt): Word;
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9305
diff changeset
    99
function  TestCollisionYKick(Gear: PGear; Dir: LongInt): Word;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   100
10818
f642a28cab0c Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents: 10635
diff changeset
   101
function  TestRectangleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
6124
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   102
10354
56bd029245fc WIP: weSea tweaks, functional and visual
sheepluva
parents: 10108
diff changeset
   103
function  CheckCoordInWater(X, Y: LongInt): boolean; inline;
56bd029245fc WIP: weSea tweaks, functional and visual
sheepluva
parents: 10108
diff changeset
   104
9248
3e8558dc285a BOM, pas2c only support ASCII
koda
parents: 9080
diff changeset
   105
// returns: negative sign if going downhill to left, value is steepness (noslope/error = _0, 45 = _0_5)
6279
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
   106
function  CalcSlopeBelowGear(Gear: PGear): hwFloat;
7754
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   107
function  CalcSlopeNearGear(Gear: PGear; dirX, dirY: LongInt): hwFloat;
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9305
diff changeset
   108
function  CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   109
15322
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
   110
function CheckGearsUnderSprite(Sprite: TSprite; sprX, sprY, Frame: LongInt): boolean;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
   111
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   112
implementation
15322
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
   113
uses uConsts, uLandGraphics, uVariables, SDLh, uLandTexture, uDebug;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   114
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
   115
type TCollisionEntry = record
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   116
    X, Y, Radius: LongInt;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   117
    cGear: PGear;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   118
    end;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   119
5568
badaac85f9d4 bump up max collision to 1024 entries
nemo
parents: 5290
diff changeset
   120
const MAXRECTSINDEX = 1023;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   121
var Count: Longword;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   122
    cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   123
    ga: TGearArray;
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   124
    ordera: TGearHitOrder;
14027
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   125
    proximitya: TGearProximityCache;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   126
9291
15f7bb217b66 Make add/delete consistent (this has bugged me for so long)
nemo
parents: 9247
diff changeset
   127
procedure AddCI(Gear: PGear);
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
   128
begin
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11077
diff changeset
   129
if (Gear^.CollisionIndex >= 0) or (Count > MAXRECTSINDEX) or
10551
4eefc711309e Skip checkin on collision for frequently spammed gear types if collision gets huge instead of trying to delete mines.
nemo
parents: 10494
diff changeset
   130
    ((Count > MAXRECTSINDEX-200) and ((Gear^.Kind = gtMine) or (Gear^.Kind = gtSMine) or (Gear^.Kind = gtKnife))) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   131
    exit;
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11077
diff changeset
   132
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
   133
with cinfos[Count] do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   134
    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   135
    X:= hwRound(Gear^.X);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   136
    Y:= hwRound(Gear^.Y);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   137
    Radius:= Gear^.Radius;
11589
c453620cc6d6 Break up the hog/object collision. Currently is $7F, allowing 128 overlapping objects accurately. Breaking it up into 15 for hogs, 7 for other objects. I'm thinking the overall accuracy should be just fine as far as people noticing even with a ton of overlapping hogs, and this way we can tell the difference between a hog and "something else". For experiment and rope-breaking purposes, make rope pass through hogs.
nemo
parents: 11532
diff changeset
   138
    ChangeRoundInLand(X, Y, Radius - 1, true,  ((CurrentHedgehog <> nil) and (Gear = CurrentHedgehog^.Gear)) or ((Gear^.Kind = gtCase) and (Gear^.State and gstFrozen = 0)), Gear^.Kind = gtHedgehog);
3608
c509bbc779e7 Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents: 3603
diff changeset
   139
    cGear:= Gear
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   140
    end;
511
2b5b9e00419d - Further work on new collisions implementation
unc0rr
parents: 505
diff changeset
   141
Gear^.CollisionIndex:= Count;
5569
8313952b2811 suggestion of mikade's - delete old mines if the collision array shows signs of filling up. This is kind of an edge case, esp now that array is up to 1024, but should prevent (easiest) way to crash by collision array overflow (endless mines/minestrikes).
nemo
parents: 5568
diff changeset
   142
inc(Count);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   143
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   144
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
   145
procedure DeleteCI(Gear: PGear);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   146
begin
511
2b5b9e00419d - Further work on new collisions implementation
unc0rr
parents: 505
diff changeset
   147
if Gear^.CollisionIndex >= 0 then
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   148
    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   149
    with cinfos[Gear^.CollisionIndex] do
11589
c453620cc6d6 Break up the hog/object collision. Currently is $7F, allowing 128 overlapping objects accurately. Breaking it up into 15 for hogs, 7 for other objects. I'm thinking the overall accuracy should be just fine as far as people noticing even with a ton of overlapping hogs, and this way we can tell the difference between a hog and "something else". For experiment and rope-breaking purposes, make rope pass through hogs.
nemo
parents: 11532
diff changeset
   150
        ChangeRoundInLand(X, Y, Radius - 1, false, ((CurrentHedgehog <> nil) and (Gear = CurrentHedgehog^.Gear)) or ((Gear^.Kind = gtCase) and (Gear^.State and gstFrozen = 0)), Gear^.Kind = gtHedgehog);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   151
    cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)];
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   152
    cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   153
    Gear^.CollisionIndex:= -1;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   154
    dec(Count)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   155
    end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   156
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   157
10354
56bd029245fc WIP: weSea tweaks, functional and visual
sheepluva
parents: 10108
diff changeset
   158
function CheckCoordInWater(X, Y: LongInt): boolean; inline;
56bd029245fc WIP: weSea tweaks, functional and visual
sheepluva
parents: 10108
diff changeset
   159
begin
56bd029245fc WIP: weSea tweaks, functional and visual
sheepluva
parents: 10108
diff changeset
   160
    CheckCoordInWater:= (Y > cWaterLine)
14303
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 14027
diff changeset
   161
        or ((WorldEdge = weSea) and ((X < leftX) or (X > rightX)));
10354
56bd029245fc WIP: weSea tweaks, functional and visual
sheepluva
parents: 10108
diff changeset
   162
end;
56bd029245fc WIP: weSea tweaks, functional and visual
sheepluva
parents: 10108
diff changeset
   163
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
   164
function CheckGearsCollision(Gear: PGear): PGearArray;
3609
bc63ed514b70 Minor fire tweak for readability and lethalness, remove exit condition that was hanging game (identified by jaylittle)
nemo
parents: 3608
diff changeset
   165
var mx, my, tr: LongInt;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   166
    i: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   167
begin
1506
a4ab75470ce1 - Some reformatting
unc0rr
parents: 1066
diff changeset
   168
CheckGearsCollision:= @ga;
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
   169
ga.Count:= 0;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   170
if Count = 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   171
    exit;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   172
mx:= hwRound(Gear^.X);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   173
my:= hwRound(Gear^.Y);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   174
4705
593ef1ad3cd3 ok. restore old [r + 1 + r] for gear width for a moment, and reset snowballs.
nemo
parents: 4684
diff changeset
   175
tr:= Gear^.Radius + 2;
3609
bc63ed514b70 Minor fire tweak for readability and lethalness, remove exit condition that was hanging game (identified by jaylittle)
nemo
parents: 3608
diff changeset
   176
3608
c509bbc779e7 Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents: 3603
diff changeset
   177
for i:= 0 to Pred(Count) do
c509bbc779e7 Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents: 3603
diff changeset
   178
    with cinfos[i] do
c509bbc779e7 Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents: 3603
diff changeset
   179
        if (Gear <> cGear) and
3609
bc63ed514b70 Minor fire tweak for readability and lethalness, remove exit condition that was hanging game (identified by jaylittle)
nemo
parents: 3608
diff changeset
   180
            (sqr(mx - x) + sqr(my - y) <= sqr(Radius + tr)) then
3608
c509bbc779e7 Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents: 3603
diff changeset
   181
                begin
c509bbc779e7 Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents: 3603
diff changeset
   182
                ga.ar[ga.Count]:= cinfos[i].cGear;
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   183
                ga.cX[ga.Count]:= hwround(Gear^.X);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   184
                ga.cY[ga.Count]:= hwround(Gear^.Y);
3608
c509bbc779e7 Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents: 3603
diff changeset
   185
                inc(ga.Count)
c509bbc779e7 Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents: 3603
diff changeset
   186
                end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   187
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   188
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   189
function CheckAllGearsCollision(SourceGear: PGear): PGearArray;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   190
var mx, my, tr: LongInt;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   191
    Gear: PGear;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   192
begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   193
    CheckAllGearsCollision:= @ga;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   194
    ga.Count:= 0;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   195
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   196
    mx:= hwRound(SourceGear^.X);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   197
    my:= hwRound(SourceGear^.Y);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   198
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   199
    tr:= SourceGear^.Radius + 2;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   200
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   201
    Gear:= GearsList;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   202
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   203
    while Gear <> nil do
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   204
        begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   205
            if (Gear <> SourceGear) and
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   206
               (sqr(mx - hwRound(Gear^.x)) + sqr(my - hwRound(Gear^.y)) <= sqr(Gear^.Radius + tr))then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   207
            begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   208
                ga.ar[ga.Count]:= Gear;
14027
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   209
                ga.cX[ga.Count]:= mx;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   210
                ga.cY[ga.Count]:= my;
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   211
                inc(ga.Count)
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   212
            end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   213
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   214
            Gear := Gear^.NextGear
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   215
        end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   216
end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   217
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   218
function LineCollisionTest(oX, oY, dirX, dirY, dirNormSqr, dirNormBound: hwFloat;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   219
        width: LongInt; Gear: PGear):
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   220
    TLineCollision; inline;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   221
var toCenterX, toCenterY, r,
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   222
    b, bSqr, c, desc, t: hwFloat;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   223
    realT: extended;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   224
begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   225
    LineCollisionTest.hasCollision:= false;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   226
    toCenterX:= (oX - Gear^.X);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   227
    toCenterY:= (oY - Gear^.Y);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   228
    r:= int2hwFloat(Gear^.Radius + width + 2);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   229
    // Early cull to avoid multiplying large numbers
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   230
    if hwAbs(toCenterX) + hwAbs(toCenterY) > dirNormBound + r then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   231
        exit;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   232
    b:= dirX * toCenterX + dirY * toCenterY;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   233
    c:= hwSqr(toCenterX) + hwSqr(toCenterY) - hwSqr(r);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   234
    if (b > _0) and (c > _0) then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   235
        exit;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   236
    bSqr:= hwSqr(b);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   237
    desc:= bSqr - dirNormSqr * c;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   238
    if desc.isNegative then exit;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   239
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   240
    t:= -b - hwSqrt(desc);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   241
    if t.isNegative then t:= _0;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   242
    if t < dirNormSqr then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   243
        with LineCollisionTest do
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   244
            begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   245
            hasCollision:= true;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   246
            realT := hwFloat2Float(t) / hwFloat2Float(dirNormSqr);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   247
            cX:= round(hwFloat2Float(oX) + realT * hwFloat2Float(dirX));
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   248
            cY:= round(hwFloat2Float(oY) + realT * hwFloat2Float(dirY));
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   249
            end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   250
end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   251
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   252
function CheckGearsLineCollision(Gear: PGear; oX, oY, tX, tY: hwFloat): PGearArray;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   253
var dirX, dirY, dirNormSqr, dirNormBound: hwFloat;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   254
    test: TLineCollision;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   255
    i: Longword;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   256
begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   257
    CheckGearsLineCollision:= @ga;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   258
    ga.Count:= 0;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   259
    if Count = 0 then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   260
        exit;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   261
    dirX:= (tX - oX);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   262
    dirY:= (tY - oY);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   263
    dirNormBound:= _1_5 * (hwAbs(dirX) + hwAbs(dirY));
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   264
    dirNormSqr:= hwSqr(dirX) + hwSqr(dirY);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   265
    if dirNormSqr.isNegative then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   266
        exit;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   267
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   268
    for i:= 0 to Pred(Count) do
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   269
        with cinfos[i] do if Gear <> cGear then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   270
            begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   271
            test:= LineCollisionTest(
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   272
                oX, oY, dirX, dirY, dirNormSqr, dirNormBound, Gear^.Radius, cGear);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   273
            if test.hasCollision then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   274
                begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   275
                ga.ar[ga.Count] := cGear;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   276
                ga.cX[ga.Count] := test.cX;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   277
                ga.cY[ga.Count] := test.cY;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   278
                inc(ga.Count)
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   279
                end
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   280
            end
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   281
end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   282
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   283
function CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   284
var dirX, dirY, dirNormSqr, dirNormBound: hwFloat;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   285
    test: TLineCollision;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   286
    Gear: PGear;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   287
begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   288
    CheckAllGearsLineCollision:= @ga;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   289
    ga.Count:= 0;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   290
    dirX:= (tX - oX);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   291
    dirY:= (tY - oY);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   292
    dirNormBound:= _1_5 * (hwAbs(dirX) + hwAbs(dirY));
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   293
    dirNormSqr:= hwSqr(dirX) + hwSqr(dirY);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   294
    if dirNormSqr.isNegative then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   295
        exit;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   296
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   297
    Gear:= GearsList;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   298
    while Gear <> nil do
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   299
    begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   300
        if SourceGear <> Gear then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   301
            begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   302
            test:= LineCollisionTest(
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   303
                oX, oY, dirX, dirY, dirNormSqr, dirNormBound, SourceGear^.Radius, Gear);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   304
            if test.hasCollision then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   305
                begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   306
                ga.ar[ga.Count] := Gear;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   307
                ga.cX[ga.Count] := test.cX;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   308
                ga.cY[ga.Count] := test.cY;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   309
                inc(ga.Count)
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   310
                end
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   311
            end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   312
        Gear := Gear^.NextGear
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   313
    end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   314
end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   315
14027
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   316
function CheckCacheCollision(SourceGear: PGear): PGearArray;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   317
var mx, my, tr, i: LongInt;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   318
    Gear: PGear;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   319
begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   320
    CheckCacheCollision:= @ga;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   321
    ga.Count:= 0;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   322
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   323
    mx:= hwRound(SourceGear^.X);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   324
    my:= hwRound(SourceGear^.Y);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   325
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   326
    tr:= SourceGear^.Radius + 2;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   327
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   328
    for i:= 0 to proximitya.Count - 1 do
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   329
    begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   330
        Gear:= proximitya.ar[i];
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   331
        // Assuming the cache has been filled correctly, it will not contain SourceGear
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   332
        // and other gears won't be far enough for sqr overflow
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   333
        if (sqr(mx - hwRound(Gear^.X)) + sqr(my - hwRound(Gear^.Y)) <= sqr(Gear^.Radius + tr)) then
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   334
        begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   335
            ga.ar[ga.Count]:= Gear;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   336
            ga.cX[ga.Count]:= mx;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   337
            ga.cY[ga.Count]:= my;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   338
            inc(ga.Count)
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   339
        end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   340
    end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   341
end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   342
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   343
function UpdateHitOrder(Gear: PGear; Order: LongInt): boolean;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   344
var i: LongInt;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   345
begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   346
UpdateHitOrder:= true;
13168
0e7eddfbce8a Fix minigun bullets sometimes failing to hit when shooting same thing twice in row
alfadur
parents: 12898
diff changeset
   347
for i:= 0 to ordera.Count - 1 do
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   348
    if ordera.ar[i] = Gear then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   349
        begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   350
        if Order <= ordera.order[i] then UpdateHitOrder:= false;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   351
        ordera.order[i]:= Max(ordera.order[i], order);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   352
        exit;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   353
        end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   354
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   355
if ordera.Count > cMaxGearHitOrderInd then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   356
    UpdateHitOrder:= false
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   357
else
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   358
    begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   359
    ordera.ar[ordera.Count]:= Gear;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   360
    ordera.order[ordera.Count]:= Order;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   361
    Inc(ordera.Count);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   362
    end
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   363
end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   364
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   365
procedure ClearHitOrderLeq(MinOrder: LongInt);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   366
var i, freeIndex: LongInt;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   367
begin;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   368
freeIndex:= 0;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   369
i:= 0;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   370
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   371
while i < ordera.Count do
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   372
    begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   373
        if ordera.order[i] <= MinOrder then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   374
            Dec(ordera.Count)
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   375
        else
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   376
            begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   377
                if freeIndex < i then
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   378
                begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   379
                ordera.ar[freeIndex]:= ordera.ar[i];
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   380
                ordera.order[freeIndex]:= ordera.order[i];
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   381
                end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   382
            Inc(freeIndex);
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   383
            end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   384
        Inc(i)
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   385
    end
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   386
end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   387
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   388
procedure ClearHitOrder();
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   389
begin
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   390
    ordera.Count:= 0;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   391
end;
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 11589
diff changeset
   392
14027
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   393
procedure RefillProximityCache(SourceGear: PGear; radius: LongInt);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   394
var cx, cy, dx, dy, r: LongInt;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   395
    Gear: PGear;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   396
begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   397
    proximitya.Count:= 0;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   398
    cx:= hwRound(SourceGear^.X);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   399
    cy:= hwRound(SourceGear^.Y);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   400
    Gear:= GearsList;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   401
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   402
    while (Gear <> nil) and (proximitya.Count <= cMaxGearProximityCacheInd) do
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   403
    begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   404
        dx:= abs(hwRound(Gear^.X) - cx);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   405
        dy:= abs(hwRound(Gear^.Y) - cy);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   406
        r:= radius + Gear^.radius + 2;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   407
        if (Gear <> SourceGear) and (max(dx, dy) <= r) and (sqr(dx) + sqr(dy) <= sqr(r)) then
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   408
        begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   409
            proximitya.ar[proximitya.Count]:= Gear;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   410
            inc(proximitya.Count)
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   411
        end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   412
        Gear := Gear^.NextGear
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   413
    end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   414
end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   415
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   416
procedure RemoveFromProximityCache(Gear: PGear);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   417
var i: LongInt;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   418
begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   419
    i := 0;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   420
    while i < proximitya.Count do
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   421
        begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   422
        if proximitya.ar[i] = Gear then
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   423
            begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   424
                proximitya.ar[i]:= proximitya.ar[proximitya.Count - 1];
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   425
                dec(proximitya.Count);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   426
            end
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   427
        else
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   428
            inc(i);
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   429
        end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   430
end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   431
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   432
procedure ClearProximityCache();
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   433
begin
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   434
    proximitya.Count:= 0;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   435
end;
105793e575d6 make firepunch hit moving gears (airmines are not amused)
alfadur
parents: 13470
diff changeset
   436
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   437
function TestCollisionXImpl(centerX, centerY, radius, direction: LongInt; collisionMask: Word): Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   438
var x, y, minY, maxY: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   439
begin
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   440
    if direction < 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   441
        x := centerX - radius
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   442
    else
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   443
        x := centerX + radius;
838
1faae19f2116 Remove tailing spaces in some places
unc0rr
parents: 542
diff changeset
   444
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   445
    if (x and LAND_WIDTH_MASK) = 0 then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   446
    begin
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   447
        minY := max(centerY - radius + 1, 0);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   448
        maxY := min(centerY + radius - 1, LAND_HEIGHT - 1);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   449
        for y := minY to maxY do
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   450
            if Land[y, x] and collisionMask <> 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   451
                exit(Land[y, x] and collisionMask);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   452
    end;
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   453
    TestCollisionXImpl := 0;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   454
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   455
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   456
function TestCollisionYImpl(centerX, centerY, radius, direction: LongInt; collisionMask: Word): Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   457
var x, y, minX, maxX: LongInt;
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   458
begin
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   459
    if direction < 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   460
        y := centerY - radius
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   461
    else
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   462
        y := centerY + radius;
7268
3a61c53346a8 - Fix cake bug introduced in r2ccfc93c6b5e
unc0rr
parents: 6992
diff changeset
   463
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   464
    if (y and LAND_HEIGHT_MASK) = 0 then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   465
    begin
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   466
        minX := max(centerX - radius + 1, 0);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   467
        maxX := min(centerX + radius - 1, LAND_WIDTH - 1);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   468
        for x := minX to maxX do
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   469
            if Land[y, x] and collisionMask <> 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   470
                exit(Land[y, x] and collisionMask);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   471
    end;
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   472
    TestCollisionYImpl := 0;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   473
end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   474
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   475
function TestCollisionX(Gear: PGear; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   476
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   477
    TestCollisionX := TestCollisionXImpl(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, Dir, Gear^.CollisionMask and lfLandMask);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   478
end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   479
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   480
function TestCollisionY(Gear: PGear; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   481
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   482
    TestCollisionY := TestCollisionYImpl(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, Dir, Gear^.CollisionMask and lfLandMask);
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   483
end;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   484
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   485
procedure LegacyFixupX(Gear: PGear);
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   486
begin
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   487
// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   488
    if (Gear^.CollisionMask = lfNotCurHogCrate) and (Gear^.Kind <> gtHedgehog) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   489
    ((hwRound(Gear^.Hedgehog^.Gear^.X) + Gear^.Hedgehog^.Gear^.Radius + 16 < hwRound(Gear^.X) - Gear^.Radius) or
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   490
    (hwRound(Gear^.Hedgehog^.Gear^.X) - Gear^.Hedgehog^.Gear^.Radius - 16 > hwRound(Gear^.X) + Gear^.Radius)) then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   491
        Gear^.CollisionMask:= lfAll;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   492
end;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   493
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   494
procedure LegacyFixupY(Gear: PGear);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   495
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   496
// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   497
    if (Gear^.CollisionMask = lfNotCurHogCrate) and (Gear^.Kind <> gtHedgehog) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   498
    ((hwRound(Gear^.Hedgehog^.Gear^.Y) + Gear^.Hedgehog^.Gear^.Radius + 16 < hwRound(Gear^.Y) - Gear^.Radius) or
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   499
    (hwRound(Gear^.Hedgehog^.Gear^.Y) - Gear^.Hedgehog^.Gear^.Radius - 16 > hwRound(Gear^.Y) + Gear^.Radius)) then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   500
        Gear^.CollisionMask:= lfAll;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   501
end;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   502
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   503
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   504
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   505
    LegacyFixupX(Gear);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   506
    TestCollisionXwithGear:= TestCollisionXImpl(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, Dir, Gear^.CollisionMask);
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   507
end;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   508
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   509
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; inline;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   510
begin
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   511
    LegacyFixupY(Gear);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   512
    TestCollisionYwithGear:= TestCollisionYImpl(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, Dir, Gear^.CollisionMask);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   513
end;
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   514
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   515
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   516
var collisionMask: Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   517
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   518
    if withGear then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   519
    begin
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   520
        LegacyFixupX(Gear);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   521
        collisionMask:= Gear^.CollisionMask;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   522
    end
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   523
    else
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   524
        collisionMask:= Gear^.CollisionMask and lfLandMask;
967
8be3938d73c2 Don't let jumping hedgehog to move others
unc0rr
parents: 906
diff changeset
   525
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   526
    TestCollisionXwithXYShift := TestCollisionXImpl(hwRound(Gear^.X + ShiftX), hwRound(Gear^.Y) + ShiftY, Gear^.Radius, Dir, collisionMask)
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   527
end;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   528
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   529
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; inline;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   530
var collisionMask: Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   531
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   532
    if withGear then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   533
    begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   534
        LegacyFixupY(Gear);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   535
        collisionMask:= Gear^.CollisionMask;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   536
    end
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   537
    else
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   538
        collisionMask:= Gear^.CollisionMask and lfLandMask;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   539
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   540
    TestCollisionYwithXYShift := TestCollisionYImpl(hwRound(Gear^.X) + ShiftX, hwRound(Gear^.Y) + ShiftY, Gear^.Radius, Dir, collisionMask)
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   541
end;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   542
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9305
diff changeset
   543
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): Word; inline;
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6700
diff changeset
   544
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6700
diff changeset
   545
    TestCollisionXwithXYShift:= TestCollisionXwithXYShift(Gear, ShiftX, ShiftY, Dir, true);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6700
diff changeset
   546
end;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6700
diff changeset
   547
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9305
diff changeset
   548
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): Word; inline;
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6700
diff changeset
   549
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6700
diff changeset
   550
    TestCollisionYwithXYShift:= TestCollisionYwithXYShift(Gear, ShiftX, ShiftY, Dir, true);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6700
diff changeset
   551
end;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6700
diff changeset
   552
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   553
function TestCollisionXKickImpl(centerX, centerY, radius, direction: LongInt; collisionMask, kickMask: Word): TKickTest;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   554
var x, y, minY, maxY: LongInt;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   555
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   556
    TestCollisionXKickImpl.kick := false;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   557
    TestCollisionXKickImpl.collisionMask := 0;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   558
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   559
    if direction < 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   560
        x := centerX - radius
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   561
    else
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   562
        x := centerX + radius;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   563
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   564
    if (x and LAND_WIDTH_MASK) = 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   565
    begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   566
        minY := max(centerY - radius + 1, 0);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   567
        maxY := min(centerY + radius - 1, LAND_HEIGHT - 1);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   568
        for y := minY to maxY do
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   569
            if Land[y, x] and collisionMask <> 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   570
            begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   571
                TestCollisionXKickImpl.kick := false;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   572
                TestCollisionXKickImpl.collisionMask := Land[y, x] and collisionMask;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   573
                exit
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   574
            end
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   575
            else if Land[y, x] and kickMask <> 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   576
            begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   577
                TestCollisionXKickImpl.kick := true;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   578
                TestCollisionXKickImpl.collisionMask := Land[y, x] and kickMask;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   579
            end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   580
    end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   581
end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   582
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   583
function TestCollisionYKickImpl(centerX, centerY, radius, direction: LongInt; collisionMask, kickMask: Word): TKickTest;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   584
var x, y, minX, maxX: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   585
begin
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   586
    TestCollisionYKickImpl.kick := false;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   587
    TestCollisionYKickImpl.collisionMask := 0;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   588
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   589
    if direction < 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   590
        y := centerY - radius
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   591
    else
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   592
        y := centerY + radius;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   593
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   594
    if (y and LAND_HEIGHT_MASK) = 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   595
    begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   596
        minX := max(centerX - radius + 1, 0);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   597
        maxX := min(centerX + radius - 1, LAND_WIDTH - 1);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   598
        for x := minX to maxX do
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   599
            if Land[y, x] and collisionMask <> 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   600
            begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   601
                TestCollisionYKickImpl.kick := false;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   602
                TestCollisionYKickImpl.collisionMask := Land[y, x] and collisionMask;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   603
                exit
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   604
            end
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   605
            else if Land[y, x] and kickMask <> 0 then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   606
            begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   607
                TestCollisionYKickImpl.kick := true;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   608
                TestCollisionYKickImpl.collisionMask := Land[y, x] and kickMask;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   609
            end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   610
    end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   611
end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   612
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   613
function TestCollisionXKick(Gear: PGear; Dir: LongInt): Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   614
var centerX, centerY, i: LongInt;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   615
    test: TKickTest;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   616
    info: TCollisionEntry;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   617
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   618
    test := TestCollisionXKickImpl(
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   619
        hwRound(Gear^.X), hwRound(Gear^.Y),
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   620
        Gear^.Radius, Dir,
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   621
        Gear^.CollisionMask and lfLandMask, Gear^.CollisionMask);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   622
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   623
    TestCollisionXKick := test.collisionMask;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   624
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   625
    if test.kick then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   626
    begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   627
        if hwAbs(Gear^.dX) < cHHKick then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   628
            exit;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   629
        if ((Gear^.State and gstHHJumping) <> 0) and (hwAbs(Gear^.dX) < _0_4) then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   630
            exit;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   631
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   632
        centerX := hwRound(Gear^.X);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   633
        centerY := hwRound(Gear^.Y);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   634
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   635
        for i:= 0 to Pred(Count) do
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   636
        begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   637
            info:= cinfos[i];
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   638
            if (Gear <> info.cGear)
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   639
                and ((centerX > info.X) xor (Dir > 0))
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   640
                and ((info.cGear^.State and gstNotKickable) = 0)
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   641
                and ((info.cGear^.Kind in [gtHedgehog, gtMine, gtKnife])
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   642
                    or (info.cGear^.Kind = gtExplosives) and ((info.cGear^.State and gsttmpflag) <> 0)) // only apply X kick if the barrel is knocked over
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   643
                and (sqr(centerX - info.X) + sqr(centerY - info.Y) <= sqr(info.Radius + Gear^.Radius + 2)) then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   644
            begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   645
                with info.cGear^ do
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   646
                begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   647
                    dX := Gear^.dX;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   648
                    dY := Gear^.dY * _0_5;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   649
                    State := State or gstMoving;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   650
                    if Kind = gtKnife then State := State and (not gstCollision);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   651
                    Active:= true
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   652
                end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   653
                DeleteCI(info.cGear);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   654
                exit(0)
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   655
            end
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   656
        end
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   657
    end
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   658
end;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9950
diff changeset
   659
15668
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   660
function TestCollisionYKick(Gear: PGear; Dir: LongInt): Word;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   661
var centerX, centerY, i: LongInt;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   662
    test: TKickTest;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   663
    info: TCollisionEntry;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   664
begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   665
    test := TestCollisionYKickImpl(
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   666
        hwRound(Gear^.X), hwRound(Gear^.Y),
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   667
        Gear^.Radius, Dir,
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   668
        Gear^.CollisionMask and lfLandMask, Gear^.CollisionMask);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   669
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   670
    TestCollisionYKick := test.collisionMask;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   671
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   672
    if test.kick then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   673
    begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   674
        if hwAbs(Gear^.dY) < cHHKick then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   675
            exit;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   676
        if ((Gear^.State and gstHHJumping) <> 0) and (not Gear^.dY.isNegative) and (Gear^.dY < _0_4) then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   677
            exit;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   678
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   679
        centerX := hwRound(Gear^.X);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   680
        centerY := hwRound(Gear^.Y);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   681
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   682
        for i := 0 to Pred(Count) do
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   683
        begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   684
            info := cinfos[i];
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   685
            if (Gear <> info.cGear)
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   686
                and ((centerY + Gear^.Radius > info.Y) xor (Dir > 0))
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   687
                and (info.cGear^.State and gstNotKickable = 0)
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   688
                and (info.cGear^.Kind in [gtHedgehog, gtMine, gtKnife, gtExplosives])
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   689
                and (sqr(centerX - info.X) + sqr(centerY - info.Y) <= sqr(info.Radius + Gear^.Radius + 2)) then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   690
            begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   691
                with info.cGear^ do
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   692
                begin
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   693
                    if (Kind <> gtExplosives) or ((State and gsttmpflag) <> 0) then
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   694
                        dX := Gear^.dX * _0_5;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   695
                    dY := Gear^.dY;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   696
                    State := State or gstMoving;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   697
                    if Kind = gtKnife then State:= State and (not gstCollision);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   698
                    Active := true
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   699
                end;
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   700
                DeleteCI(info.cGear);
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   701
                exit(0)
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   702
            end
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   703
        end
c2a1a34d1841 refactor collision tests
alfadur
parents: 15653
diff changeset
   704
    end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   705
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   706
10818
f642a28cab0c Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents: 10635
diff changeset
   707
function TestRectangleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   708
var x, y: LongInt;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   709
    TestWord: LongWord;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   710
begin
10818
f642a28cab0c Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents: 10635
diff changeset
   711
TestRectangleForObstacle:= true;
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   712
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   713
if landOnly then
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   714
    TestWord:= 255
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   715
else
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   716
    TestWord:= 0;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   717
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   718
if x1 > x2 then
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   719
begin
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   720
    x  := x1;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   721
    x1 := x2;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   722
    x2 := x;
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   723
end;
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   724
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   725
if y1 > y2 then
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   726
begin
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   727
    y  := y1;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   728
    y1 := y2;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   729
    y2 := y;
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   730
end;
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   731
5919
f737843dd331 TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents: 5896
diff changeset
   732
if (hasBorder and ((y1 < 0) or (x1 < 0) or (x2 > LAND_WIDTH))) then
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   733
    exit;
5919
f737843dd331 TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents: 5896
diff changeset
   734
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   735
for y := y1 to y2 do
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   736
    for x := x1 to x2 do
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   737
        if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] > TestWord) then
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   738
            exit;
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   739
10818
f642a28cab0c Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents: 10635
diff changeset
   740
TestRectangleForObstacle:= false
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   741
end;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   742
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5834
diff changeset
   743
function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   744
var ldx, ldy, rdx, rdy: LongInt;
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   745
    i, j, k, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   746
    tmpx, tmpy: LongWord;
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   747
    dx, dy, s: hwFloat;
6453
11c578d30bd3 Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents: 6279
diff changeset
   748
    offset: array[0..7,0..1] of ShortInt;
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   749
    isColl: Boolean;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   750
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   751
begin
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   752
    CalcSlopeTangent:= false;
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   753
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   754
    dx:= Gear^.dX;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   755
    dy:= Gear^.dY;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   756
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   757
    // we start searching from the direction the gear came from
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   758
    if (dx.QWordValue > _0_995.QWordValue )
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   759
    or (dy.QWordValue > _0_995.QWordValue ) then
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   760
        begin // scale
6279
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
   761
        s := _0_995 / Distance(dx,dy);
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   762
        dx := s * dx;
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   763
        dy := s * dy;
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   764
        end;
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   765
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   766
    mx:= hwRound(Gear^.X-dx) - hwRound(Gear^.X);
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   767
    my:= hwRound(Gear^.Y-dy) - hwRound(Gear^.Y);
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   768
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   769
    li:= -1;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   770
    ri:= -1;
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   771
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   772
    // go around collision pixel, checking for first/last collisions
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   773
    // this will determinate what angles will be tried to crawl along
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   774
    for i:= 0 to 7 do
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   775
        begin
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   776
        offset[i,0]:= mx;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   777
        offset[i,1]:= my;
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   778
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   779
        // multiplicator k tries to skip small pixels/gaps when possible
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   780
        for k:= 4 downto 1 do
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   781
            begin
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   782
            tmpx:= collisionX + k * mx;
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   783
            tmpy:= collisionY + k * my;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   784
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   785
            if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) then
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   786
                if (Land[tmpy,tmpx] > TestWord) then
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   787
                    begin
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   788
                    // remember the index belonging to the first and last collision (if in 1st half)
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   789
                    if (i <> 0) then
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   790
                        begin
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   791
                        if (ri = -1) then
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   792
                            ri:= i
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   793
                        else
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   794
                            li:= i;
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   795
                        end;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   796
                    end;
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   797
            end;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   798
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   799
        if i = 7 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   800
            break;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   801
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   802
        // prepare offset for next check (clockwise)
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   803
        if (mx = -1) and (my <> -1) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   804
            my:= my - 1
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   805
        else if (my = -1) and (mx <> 1) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   806
            mx:= mx + 1
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   807
        else if (mx = 1) and (my <> 1) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   808
            my:= my + 1
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   809
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   810
            mx:= mx - 1;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   811
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   812
        end;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   813
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   814
    ldx:= collisionX;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   815
    ldy:= collisionY;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   816
    rdx:= collisionX;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   817
    rdy:= collisionY;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   818
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   819
    // edge-crawl
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   820
    for i:= 0 to 8 do
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   821
        begin
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   822
        // using mx,my as temporary value buffer here
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3609
diff changeset
   823
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   824
        jfr:= 8+li+1;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   825
        jto:= 8+li-1;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   826
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   827
        isColl:= false;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   828
        for j:= jfr downto jto do
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   829
            begin
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   830
            tmpo:= j mod 8;
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   831
            // multiplicator k tries to skip small pixels/gaps when possible
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   832
            for k:= 3 downto 1 do
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   833
                begin
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   834
                tmpx:= ldx + k * offset[tmpo,0];
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   835
                tmpy:= ldy + k * offset[tmpo,1];
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   836
                if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK)  = 0)
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   837
                and (Land[tmpy,tmpx] > TestWord) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   838
                    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   839
                    ldx:= tmpx;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   840
                    ldy:= tmpy;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   841
                    isColl:= true;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   842
                    break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   843
                    end;
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   844
                end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   845
            if isColl then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   846
                break;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   847
            end;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   848
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   849
        jfr:= 8+ri-1;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   850
        jto:= 8+ri+1;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   851
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   852
        isColl:= false;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   853
        for j:= jfr to jto do
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   854
            begin
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   855
            tmpo:= j mod 8;
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   856
            for k:= 3 downto 1 do
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   857
                begin
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   858
                tmpx:= rdx + k * offset[tmpo,0];
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   859
                tmpy:= rdy + k * offset[tmpo,1];
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   860
                if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK)  = 0)
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   861
                and (Land[tmpy,tmpx] > TestWord) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   862
                    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   863
                    rdx:= tmpx;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   864
                    rdy:= tmpy;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   865
                    isColl:= true;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   866
                    break;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   867
                    end;
6123
0cb751caf0ac make slope calcs skip small gaps
sheepluva
parents: 6081
diff changeset
   868
                end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   869
            if isColl then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   870
                break;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   871
            end;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   872
        end;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   873
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   874
    ldx:= rdx - ldx;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   875
    ldy:= rdy - ldy;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   876
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   877
    if ((ldx = 0) and (ldy = 0)) then
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   878
        exit;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   879
3414
b2f3bb44777e some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents: 3411
diff changeset
   880
outDeltaX:= ldx;
b2f3bb44777e some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents: 3411
diff changeset
   881
outDeltaY:= ldy;
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6986
diff changeset
   882
CalcSlopeTangent:= true;
3401
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   883
end;
d5d31d16eccc add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents: 3236
diff changeset
   884
7754
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   885
function CalcSlopeNearGear(Gear: PGear; dirX, dirY: LongInt): hwFloat;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   886
var dx, dy: hwFloat;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   887
    collX, collY, i, y, x, gx, gy, sdx, sdy: LongInt;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   888
    isColl, bSucc: Boolean;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   889
begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   890
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9950
diff changeset
   891
if dirY <> 0 then
7754
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   892
    begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   893
    y:= hwRound(Gear^.Y) + Gear^.Radius * dirY;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   894
    gx:= hwRound(Gear^.X);
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   895
    collX := gx;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   896
    isColl:= false;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   897
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   898
    if (y and LAND_HEIGHT_MASK) = 0 then
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   899
        begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   900
        x:= hwRound(Gear^.X) - Gear^.Radius + 1;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   901
        i:= x + Gear^.Radius * 2 - 2;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   902
        repeat
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   903
        if (x and LAND_WIDTH_MASK) = 0 then
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   904
            if Land[y, x] <> 0 then
7767
d1ea9b3f543e damn nots
nemo
parents: 7756
diff changeset
   905
                if (not isColl) or (abs(x-gx) < abs(collX-gx)) then
7754
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   906
                    begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   907
                    isColl:= true;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   908
                    collX := x;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   909
                    end;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   910
        inc(x)
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   911
        until (x > i);
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   912
        end;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   913
    end
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   914
else
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   915
    begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   916
    x:= hwRound(Gear^.X) + Gear^.Radius * dirX;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   917
    gy:= hwRound(Gear^.Y);
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   918
    collY := gy;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   919
    isColl:= false;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   920
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   921
    if (x and LAND_WIDTH_MASK) = 0 then
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   922
        begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   923
        y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   924
        i:= y + Gear^.Radius * 2 - 2;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   925
        repeat
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   926
        if (y and LAND_HEIGHT_MASK) = 0 then
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   927
            if Land[y, x] <> 0 then
7767
d1ea9b3f543e damn nots
nemo
parents: 7756
diff changeset
   928
                if (not isColl) or (abs(y-gy) < abs(collY-gy)) then
7754
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   929
                    begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   930
                    isColl:= true;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   931
                    collY := y;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   932
                    end;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   933
        inc(y)
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   934
        until (y > i);
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   935
        end;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   936
    end;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   937
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   938
if isColl then
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   939
    begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   940
    // save original dx/dy
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   941
    dx := Gear^.dX;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   942
    dy := Gear^.dY;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   943
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   944
    if dirY <> 0 then
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   945
        begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   946
        Gear^.dX.QWordValue:= 0;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   947
        Gear^.dX.isNegative:= (collX >= gx);
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   948
        Gear^.dY:= _1*dirY
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   949
        end
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   950
    else
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   951
        begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   952
        Gear^.dY.QWordValue:= 0;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   953
        Gear^.dY.isNegative:= (collY >= gy);
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   954
        Gear^.dX:= _1*dirX
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   955
        end;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   956
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   957
    sdx:= 0;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   958
    sdy:= 0;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   959
    if dirY <> 0 then
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   960
         bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 0)
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   961
    else bSucc := CalcSlopeTangent(Gear, x, collY, sdx, sdy, 0);
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   962
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   963
    // restore original dx/dy
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   964
    Gear^.dX := dx;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   965
    Gear^.dY := dy;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   966
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   967
    if bSucc and ((sdx <> 0) or (sdy <> 0)) then
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   968
        begin
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   969
        dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy));
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   970
        dx.isNegative := (sdx * sdy) < 0;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   971
        exit (dx);
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   972
        end
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   973
    end;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   974
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   975
CalcSlopeNearGear := _0;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   976
end;
e81dc9bef8b8 First pass at cleaver.
nemo
parents: 7489
diff changeset
   977
6279
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
   978
function CalcSlopeBelowGear(Gear: PGear): hwFloat;
6124
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   979
var dx, dy: hwFloat;
6279
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
   980
    collX, i, y, x, gx, sdx, sdy: LongInt;
6453
11c578d30bd3 Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents: 6279
diff changeset
   981
    isColl, bSucc: Boolean;
6124
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   982
begin
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   983
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   984
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   985
y:= hwRound(Gear^.Y) + Gear^.Radius;
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   986
gx:= hwRound(Gear^.X);
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   987
collX := gx;
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   988
isColl:= false;
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   989
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   990
if (y and LAND_HEIGHT_MASK) = 0 then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   991
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   992
    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   993
    i:= x + Gear^.Radius * 2 - 2;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   994
    repeat
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   995
    if (x and LAND_WIDTH_MASK) = 0 then
14552
e0af4ce7d8bc fix incorrect mask set in r7b4643ff60ea - this causes ghost hog collisions and odd hog jumps on overlap with active hog
nemo
parents: 14303
diff changeset
   996
        if (Land[y, x] and lfLandMask) <> 0 then
7767
d1ea9b3f543e damn nots
nemo
parents: 7756
diff changeset
   997
            if (not isColl) or (abs(x-gx) < abs(collX-gx)) then
6124
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   998
                begin
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
   999
                isColl:= true;
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
  1000
                collX := x;
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
  1001
                end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
  1002
    inc(x)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
  1003
    until (x > i);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
  1004
    end;
6124
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
  1005
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
  1006
if isColl then
6279
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1007
    begin
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1008
    // save original dx/dy
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1009
    dx := Gear^.dX;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1010
    dy := Gear^.dY;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1011
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1012
    Gear^.dX.QWordValue:= 0;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1013
    Gear^.dX.isNegative:= (collX >= gx);
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1014
    Gear^.dY:= _1;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1015
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1016
    sdx:= 0;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1017
    sdy:= 0;
6453
11c578d30bd3 Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents: 6279
diff changeset
  1018
    bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 255);
6124
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
  1019
6279
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1020
    // restore original dx/dy
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1021
    Gear^.dX := dx;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1022
    Gear^.dY := dy;
6124
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
  1023
6453
11c578d30bd3 Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents: 6279
diff changeset
  1024
    if bSucc and (sdx <> 0) and (sdy <> 0) then
6279
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1025
    begin
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1026
        dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy));
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1027
        dx.isNegative := (sdx * sdy) < 0;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1028
        exit (dx);
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1029
    end;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1030
    end;
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1031
7f724835ea57 I hope this helps...
sheepluva
parents: 6124
diff changeset
  1032
CalcSlopeBelowGear := _0;
6124
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
  1033
end;
bee90df26109 something for nemo to play around with
sheepluva
parents: 6123
diff changeset
  1034
15322
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1035
function CheckGearsUnderSprite(Sprite: TSprite; sprX, sprY, Frame: LongInt): boolean;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1036
var x, y, bpp, h, w, row, col, gx, gy, r, numFramesFirstCol: LongInt;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1037
    p: PByteArray;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1038
    Image: PSDL_Surface;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1039
    Gear: PGear;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1040
begin
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1041
    CheckGearsUnderSprite := false;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1042
    if checkFails(SpritesData[Sprite].Surface <> nil, 'Assert SpritesData[Sprite].Surface failed', true) then exit;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1043
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1044
    numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1045
    Image:= SpritesData[Sprite].Surface;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1046
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1047
    if SDL_MustLock(Image) then
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1048
        if SDLCheck(SDL_LockSurface(Image) >= 0, 'CheckGearsUnderSprite', true) then exit;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1049
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1050
    bpp:= Image^.format^.BytesPerPixel;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1051
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1052
    if checkFails(bpp = 4, 'It should be 32 bpp sprite', true) then
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1053
        begin
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1054
        if SDL_MustLock(Image) then
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1055
            SDL_UnlockSurface(Image);
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1056
        exit
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1057
        end;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1058
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1059
    w:= SpritesData[Sprite].Width;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1060
    h:= SpritesData[Sprite].Height;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1061
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1062
    row:= Frame mod numFramesFirstCol;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1063
    col:= Frame div numFramesFirstCol;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1064
    p:= PByteArray(@(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]));
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1065
    Gear:= GearsList;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1066
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1067
    while Gear <> nil do
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1068
        begin
15325
b043b5d5219a fix check for static gears
alfadur
parents: 15324
diff changeset
  1069
        if (Gear^.Kind = gtAirMine) or
b043b5d5219a fix check for static gears
alfadur
parents: 15324
diff changeset
  1070
            ((Gear^.Kind in [gtCase, gtExplosives, gtTarget, gtKnife, gtMine, gtHedgehog, gtSMine]) and (Gear^.CollisionIndex = -1)) then
15322
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1071
            begin
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1072
            gx:= hwRound(Gear^.X);
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1073
            gy:= hwRound(Gear^.Y);
15323
9299f43ba0ec disallow placing girders over airmines and moving hogs
alfadur
parents: 15322
diff changeset
  1074
            r:= Gear^.Radius + 1;
15322
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1075
            if (gx + r >= sprX) and (gx - r < sprX + w) and (gy + r >= sprY) and (gy - r < sprY + h) then
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1076
                for y := gy - r to gy + r do
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1077
                    for x := gx - r to gx + r do
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1078
                        begin
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1079
                        if (x >= sprX) and (x < sprX + w) and (y >= sprY) and (y < sprY + h)
15323
9299f43ba0ec disallow placing girders over airmines and moving hogs
alfadur
parents: 15322
diff changeset
  1080
                        and (Sqr(x - gx) + Sqr(y - gy) <= Sqr(r))
9299f43ba0ec disallow placing girders over airmines and moving hogs
alfadur
parents: 15322
diff changeset
  1081
                        and (((PLongword(@(p^[Image^.pitch * (y - sprY) + (x - sprX) * 4]))^) and AMask) <> 0) then
15322
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1082
                            begin
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1083
                            CheckGearsUnderSprite := true;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1084
                            if SDL_MustLock(Image) then
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1085
                                SDL_UnlockSurface(Image);
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1086
                            exit
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1087
                            end
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1088
                        end
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1089
            end;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1090
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1091
        Gear := Gear^.NextGear
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1092
        end;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1093
end;
361e79c6c428 add helper to find if a spite intersects gears
alfadur
parents: 14552
diff changeset
  1094
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
  1095
procedure initModule;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
  1096
begin
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
  1097
    Count:= 0;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
  1098
end;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
  1099
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
  1100
procedure freeModule;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
  1101
begin
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
  1102
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
  1103
end;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
  1104
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
  1105
end.