hedgewars/uCollisions.pas
author nemo
Sun, 14 Aug 2011 23:52:45 -0400
changeset 5569 8313952b2811
parent 5568 badaac85f9d4
child 5572 47cc28299baa
permissions -rw-r--r--
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).
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
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4798
diff changeset
     3
 * Copyright (c) 2004-2011 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
57c2ef19f719 Relicense to GPL
unc0rr
parents: 107
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
4357
a1fcfc341a52 Introduce unit uTypes in order to remove some cyclic unit dependencies
unC0Rr
parents: 3697
diff changeset
    23
uses uFloat, uTypes;
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;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    26
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 68
diff changeset
    27
type PGearArray = ^TGearArray;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    28
    TGearArray = record
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    29
            ar: array[0..cMaxGearArrayInd] of PGear;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    30
            Count: Longword
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    31
            end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    32
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
    33
procedure initModule;
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
    34
procedure freeModule;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    35
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
    36
procedure AddGearCI(Gear: PGear);
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
    37
procedure DeleteCI(Gear: PGear);
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
    38
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    39
function  CheckGearsCollision(Gear: PGear): PGearArray;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
    40
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    41
function  TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    42
function  TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
    43
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    44
function  TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    45
function  TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
    46
4798
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
    47
function  TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    48
function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
    49
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    50
function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    51
function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    52
3414
b2f3bb44777e some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents: 3411
diff changeset
    53
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
    54
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    55
implementation
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
    56
uses uConsts, uLandGraphics, uVariables, uDebug, uGears;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    57
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
    58
type TCollisionEntry = record
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    59
            X, Y, Radius: LongInt;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    60
            cGear: PGear;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    61
            end;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
    62
5568
badaac85f9d4 bump up max collision to 1024 entries
nemo
parents: 5290
diff changeset
    63
const MAXRECTSINDEX = 1023;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    64
var Count: Longword;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    65
    cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
    66
    ga: TGearArray;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    67
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
    68
procedure AddGearCI(Gear: PGear);
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
    69
var t: PGear;
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
    70
begin
511
2b5b9e00419d - Further work on new collisions implementation
unc0rr
parents: 505
diff changeset
    71
if Gear^.CollisionIndex >= 0 then exit;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    72
TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true);
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
    73
with cinfos[Count] do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    74
    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    75
    X:= hwRound(Gear^.X);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    76
    Y:= hwRound(Gear^.Y);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    77
    Radius:= Gear^.Radius;
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
    78
    ChangeRoundInLand(X, Y, Radius - 1, true);
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
    79
    cGear:= Gear
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    80
    end;
511
2b5b9e00419d - Further work on new collisions implementation
unc0rr
parents: 505
diff changeset
    81
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
    82
inc(Count);
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
    83
// mines are the easiest way to overflow collision
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
    84
if (Count > (MAXRECTSINDEX-20)) then
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
    85
    begin
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
    86
    t:= GearsList;
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
    87
    while (t <> nil) and (t^.Kind <> gtMine) do t:= t^.NextGear;
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
    88
    if (t <> nil) and (t^.Kind = gtMine) then DeleteGear(t)
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
    89
    end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    90
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    91
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
    92
procedure DeleteCI(Gear: PGear);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    93
begin
511
2b5b9e00419d - Further work on new collisions implementation
unc0rr
parents: 505
diff changeset
    94
if Gear^.CollisionIndex >= 0 then
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    95
    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    96
    with cinfos[Gear^.CollisionIndex] do
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
    97
        ChangeRoundInLand(X, Y, Radius - 1, false);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    98
    cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)];
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
    99
    cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   100
    Gear^.CollisionIndex:= -1;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   101
    dec(Count)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   102
    end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   103
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   104
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
   105
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
   106
var mx, my, tr: LongInt;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   107
    i: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   108
begin
1506
a4ab75470ce1 - Some reformatting
unc0rr
parents: 1066
diff changeset
   109
CheckGearsCollision:= @ga;
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 38
diff changeset
   110
ga.Count:= 0;
12
366adfa1a727 Fix reading out of bounds of the collisions array. This fixes flying hedgehogs and not moving after explosion
unc0rr
parents: 4
diff changeset
   111
if Count = 0 then exit;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   112
mx:= hwRound(Gear^.X);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   113
my:= hwRound(Gear^.Y);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   114
4705
593ef1ad3cd3 ok. restore old [r + 1 + r] for gear width for a moment, and reset snowballs.
nemo
parents: 4684
diff changeset
   115
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
   116
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
   117
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
   118
    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
   119
        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
   120
            (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
   121
                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
   122
                ga.ar[ga.Count]:= cinfos[i].cGear;
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
   123
                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
   124
                end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   125
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   126
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   127
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean;
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   128
var x, y, i: LongInt;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   129
    TestWord: LongWord;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   130
begin
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   131
if Gear^.IntersectGear <> nil then
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   132
   with Gear^ do
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   133
        if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius) or
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   134
           (hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   135
           begin
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   136
           IntersectGear:= nil;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   137
           TestWord:= 0
838
1faae19f2116 Remove tailing spaces in some places
unc0rr
parents: 542
diff changeset
   138
           end else
1966
31e449e1d9dd nemo's patch + ropes ammo scheme hack
unc0rr
parents: 1753
diff changeset
   139
           TestWord:= 255
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   140
   else TestWord:= 0;
838
1faae19f2116 Remove tailing spaces in some places
unc0rr
parents: 542
diff changeset
   141
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   142
x:= hwRound(Gear^.X);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   143
if Dir < 0 then x:= x - Gear^.Radius
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   144
           else x:= x + Gear^.Radius;
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   145
if (x and LAND_WIDTH_MASK) = 0 then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   146
   begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   147
   y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   148
   i:= y + Gear^.Radius * 2 - 2;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   149
   repeat
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   150
     if (y and LAND_HEIGHT_MASK) = 0 then
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   151
        if Land[y, x] > TestWord then exit(true);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   152
     inc(y)
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   153
   until (y > i);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   154
   end;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   155
TestCollisionXwithGear:= false
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
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   158
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   159
var x, y, i: LongInt;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   160
    TestWord: LongWord;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   161
begin
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   162
if Gear^.IntersectGear <> nil then
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   163
   with Gear^ do
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   164
        if (hwRound(IntersectGear^.Y) + IntersectGear^.Radius < hwRound(Y) - Radius) or
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   165
           (hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   166
           begin
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   167
           IntersectGear:= nil;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   168
           TestWord:= 0
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   169
           end else
1966
31e449e1d9dd nemo's patch + ropes ammo scheme hack
unc0rr
parents: 1753
diff changeset
   170
           TestWord:= 255
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   171
   else TestWord:= 0;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   172
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   173
y:= hwRound(Gear^.Y);
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   174
if Dir < 0 then y:= y - Gear^.Radius
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   175
           else y:= y + Gear^.Radius;
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   176
if (y and LAND_HEIGHT_MASK) = 0 then
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   177
   begin
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   178
   x:= hwRound(Gear^.X) - Gear^.Radius + 1;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   179
   i:= x + Gear^.Radius * 2 - 2;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   180
   repeat
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   181
     if (x and LAND_WIDTH_MASK) = 0 then
505
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   182
        if Land[y, x] > TestWord then exit(true);
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   183
     inc(x)
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   184
   until (x > i);
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   185
   end;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   186
TestCollisionYwithGear:= false
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   187
end;
fcba7d7aea0d Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents: 504
diff changeset
   188
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   189
function TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean;
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
   190
var x, y, mx, my, i: LongInt;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   191
    flag: boolean;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   192
begin
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   193
flag:= false;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   194
x:= hwRound(Gear^.X);
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   195
if Dir < 0 then x:= x - Gear^.Radius
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   196
           else x:= x + Gear^.Radius;
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   197
if (x and LAND_WIDTH_MASK) = 0 then
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   198
   begin
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   199
   y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   200
   i:= y + Gear^.Radius * 2 - 2;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   201
   repeat
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   202
     if (y and LAND_HEIGHT_MASK) = 0 then
1966
31e449e1d9dd nemo's patch + ropes ammo scheme hack
unc0rr
parents: 1753
diff changeset
   203
           if Land[y, x] > 255 then exit(true)
536
33538aadb4e7 - Fix some stupid bugs in collisions detecting code
unc0rr
parents: 521
diff changeset
   204
           else if Land[y, x] <> 0 then flag:= true;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   205
     inc(y)
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   206
   until (y > i);
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   207
   end;
538
74219eadab5e - Various small fixes
unc0rr
parents: 536
diff changeset
   208
TestCollisionXKick:= flag;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   209
536
33538aadb4e7 - Fix some stupid bugs in collisions detecting code
unc0rr
parents: 521
diff changeset
   210
if flag then
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   211
   begin
538
74219eadab5e - Various small fixes
unc0rr
parents: 536
diff changeset
   212
   if hwAbs(Gear^.dX) < cHHKick then exit;
967
8be3938d73c2 Don't let jumping hedgehog to move others
unc0rr
parents: 906
diff changeset
   213
   if (Gear^.State and gstHHJumping <> 0)
8be3938d73c2 Don't let jumping hedgehog to move others
unc0rr
parents: 906
diff changeset
   214
   and (hwAbs(Gear^.dX) < _0_4) then exit;
8be3938d73c2 Don't let jumping hedgehog to move others
unc0rr
parents: 906
diff changeset
   215
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   216
   mx:= hwRound(Gear^.X);
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   217
   my:= hwRound(Gear^.Y);
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   218
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
   219
   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
   220
    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
   221
      if (Gear <> cGear) and
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
   222
         (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) and
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
   223
         ((mx > x) xor (Dir > 0)) then
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
   224
         if ((cGear^.Kind in [gtHedgehog, gtMine]) and ((Gear^.State and gstNotKickable) = 0)) or
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
   225
            // only apply X kick if the barrel is knocked over
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
   226
            ((cGear^.Kind = gtExplosives) and ((cGear^.State and gsttmpflag) <> 0)) then
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
   227
             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
   228
             with cGear^ 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
   229
                  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
   230
                  dX:= Gear^.dX;
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
   231
                  dY:= Gear^.dY * _0_5;
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
   232
                  State:= State or gstMoving;
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
   233
                  Active:= true
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
   234
                  end;
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
   235
             DeleteCI(cGear);
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
   236
             exit(false)
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
   237
             end
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
   238
   end
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   239
end;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   240
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   241
function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean;
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
   242
var x, y, mx, my, i: LongInt;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   243
    flag: boolean;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   244
begin
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   245
flag:= false;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   246
y:= hwRound(Gear^.Y);
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   247
if Dir < 0 then y:= y - Gear^.Radius
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   248
           else y:= y + Gear^.Radius;
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   249
if (y and LAND_HEIGHT_MASK) = 0 then
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   250
   begin
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   251
   x:= hwRound(Gear^.X) - Gear^.Radius + 1;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   252
   i:= x + Gear^.Radius * 2 - 2;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   253
   repeat
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   254
     if (x and LAND_WIDTH_MASK) = 0 then
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   255
        if Land[y, x] > 0 then
1966
31e449e1d9dd nemo's patch + ropes ammo scheme hack
unc0rr
parents: 1753
diff changeset
   256
           if Land[y, x] > 255 then exit(true)
536
33538aadb4e7 - Fix some stupid bugs in collisions detecting code
unc0rr
parents: 521
diff changeset
   257
           else if Land[y, x] <> 0 then flag:= true;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   258
     inc(x)
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   259
   until (x > i);
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   260
   end;
538
74219eadab5e - Various small fixes
unc0rr
parents: 536
diff changeset
   261
TestCollisionYKick:= flag;
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   262
536
33538aadb4e7 - Fix some stupid bugs in collisions detecting code
unc0rr
parents: 521
diff changeset
   263
if flag then
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   264
   begin
839
1493f697d1bb Fix broken logic for the new parachute feature
unc0rr
parents: 838
diff changeset
   265
   if hwAbs(Gear^.dY) < cHHKick then exit(true);
967
8be3938d73c2 Don't let jumping hedgehog to move others
unc0rr
parents: 906
diff changeset
   266
   if (Gear^.State and gstHHJumping <> 0)
8be3938d73c2 Don't let jumping hedgehog to move others
unc0rr
parents: 906
diff changeset
   267
   and (not Gear^.dY.isNegative)
8be3938d73c2 Don't let jumping hedgehog to move others
unc0rr
parents: 906
diff changeset
   268
   and (Gear^.dY < _0_4) then exit;
8be3938d73c2 Don't let jumping hedgehog to move others
unc0rr
parents: 906
diff changeset
   269
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   270
   mx:= hwRound(Gear^.X);
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   271
   my:= hwRound(Gear^.Y);
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   272
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
   273
   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
   274
    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
   275
      if (Gear <> cGear) and
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
   276
         (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) and
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
   277
         ((my > y) xor (Dir > 0)) then
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
   278
         if (cGear^.Kind in [gtHedgehog, gtMine, gtExplosives]) and ((Gear^.State and gstNotKickable) = 0) then
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
   279
             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
   280
             with cGear^ 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
   281
                  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
   282
                  if (Kind <> gtExplosives) or ((State and gsttmpflag) <> 0) then dX:= Gear^.dX * _0_5;
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
   283
                  dY:= Gear^.dY;
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
   284
                  State:= State or gstMoving;
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
   285
                  Active:= true
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
   286
                  end;
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
   287
             DeleteCI(cGear);
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
   288
             exit(false)
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
   289
             end
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
   290
   end
513
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   291
end;
69e06d710d46 Moving hedgehog could get another hedgehog moving forward
unc0rr
parents: 511
diff changeset
   292
498
9c8b385dc9a1 - Get rid of operator := to have GPC support
unc0rr
parents: 393
diff changeset
   293
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   294
begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   295
Gear^.X:= Gear^.X + ShiftX;
498
9c8b385dc9a1 - Get rid of operator := to have GPC support
unc0rr
parents: 393
diff changeset
   296
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   297
TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   298
Gear^.X:= Gear^.X - ShiftX;
498
9c8b385dc9a1 - Get rid of operator := to have GPC support
unc0rr
parents: 393
diff changeset
   299
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   300
end;
4798
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   301
function TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   302
var x, y, i: LongInt;
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   303
begin
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   304
x:= hwRound(Gear^.X);
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   305
if Dir < 0 then x:= x - Gear^.Radius
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   306
           else x:= x + Gear^.Radius;
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   307
if (x and LAND_WIDTH_MASK) = 0 then
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   308
   begin
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   309
   y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   310
   i:= y + Gear^.Radius * 2 - 2;
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   311
   repeat
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   312
     if (y and LAND_HEIGHT_MASK) = 0 then
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   313
        if Land[y, x] > 255 then exit(true);
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   314
     inc(y)
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   315
   until (y > i);
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   316
   end;
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   317
TestCollisionX:= false
84fb1ff0a1c0 fix sticky rope issue
sheepluva
parents: 4705
diff changeset
   318
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   319
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   320
function TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   321
var x, y, i: LongInt;
68
cbb93eb90304 Collision-related stuff
unc0rr
parents: 64
diff changeset
   322
begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   323
y:= hwRound(Gear^.Y);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   324
if Dir < 0 then y:= y - Gear^.Radius
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   325
           else y:= y + Gear^.Radius;
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   326
if (y and LAND_HEIGHT_MASK) = 0 then
68
cbb93eb90304 Collision-related stuff
unc0rr
parents: 64
diff changeset
   327
   begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   328
   x:= hwRound(Gear^.X) - Gear^.Radius + 1;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   329
   i:= x + Gear^.Radius * 2 - 2;
68
cbb93eb90304 Collision-related stuff
unc0rr
parents: 64
diff changeset
   330
   repeat
1753
2ccba26f1aa4 Apply nemo's world resize patch
unc0rr
parents: 1528
diff changeset
   331
     if (x and LAND_WIDTH_MASK) = 0 then
1966
31e449e1d9dd nemo's patch + ropes ammo scheme hack
unc0rr
parents: 1753
diff changeset
   332
        if Land[y, x] > 255 then exit(true);
68
cbb93eb90304 Collision-related stuff
unc0rr
parents: 64
diff changeset
   333
     inc(x)
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   334
   until (x > i);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   335
   end;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   336
TestCollisionY:= false
68
cbb93eb90304 Collision-related stuff
unc0rr
parents: 64
diff changeset
   337
end;
cbb93eb90304 Collision-related stuff
unc0rr
parents: 64
diff changeset
   338
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   339
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   340
begin
498
9c8b385dc9a1 - Get rid of operator := to have GPC support
unc0rr
parents: 393
diff changeset
   341
Gear^.X:= Gear^.X + int2hwFloat(ShiftX);
9c8b385dc9a1 - Get rid of operator := to have GPC support
unc0rr
parents: 393
diff changeset
   342
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 183
diff changeset
   343
TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir);
498
9c8b385dc9a1 - Get rid of operator := to have GPC support
unc0rr
parents: 393
diff changeset
   344
Gear^.X:= Gear^.X - int2hwFloat(ShiftX);
9c8b385dc9a1 - Get rid of operator := to have GPC support
unc0rr
parents: 393
diff changeset
   345
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   346
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   347
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
   348
3414
b2f3bb44777e some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents: 3411
diff changeset
   349
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
   350
var ldx, ldy, rdx, rdy: LongInt;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   351
    i, j, 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
   352
    tmpx, tmpy: LongWord;
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   353
    dx, dy, s: hwFloat;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   354
    offset: Array[0..7,0..1] of 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
   355
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
   356
begin
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
   357
    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
   358
    dy:= Gear^.dY;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   359
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   360
    // we start searching from the direction the gear came from
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   361
    if (dx.QWordValue > _0_995.QWordValue )
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   362
    or (dy.QWordValue > _0_995.QWordValue ) then
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   363
        begin // scale
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   364
        s := _1 / Distance(dx,dy);
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   365
        dx := s * dx;
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   366
        dy := s * dy;
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   367
        end;
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   368
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   369
    mx:= hwRound(Gear^.X-dx) - hwRound(Gear^.X);
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   370
    my:= hwRound(Gear^.Y-dy) - hwRound(Gear^.Y);
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   371
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   372
    li:= -1;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   373
    ri:= -1;
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   374
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   375
    // go around collision pixel, checking for first/last collisions
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   376
    // this will determinate what angles will be tried to crawl along
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   377
    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
   378
        begin
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   379
        offset[i,0]:= mx;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   380
        offset[i,1]:= my;
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   381
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   382
        tmpx:= collisionX + mx;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   383
        tmpy:= collisionY + 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
   384
3569
27b0ec683572 portal / slope detection:
sheepluva
parents: 3474
diff changeset
   385
        if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) then
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   386
            if (Land[tmpy,tmpx] > TestWord) then
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   387
                begin
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   388
                // remember the index belonging to the first and last collision (if in 1st half)
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   389
                if (i <> 0) then
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   390
                    begin
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   391
                    if (ri = -1) then
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   392
                        ri:= i
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   393
                    else
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   394
                        li:= i;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   395
                    end;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   396
                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
   397
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   398
        if i = 7 then 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
   399
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   400
        // prepare offset for next check (clockwise)
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
   401
        if (mx = -1) and (my <> -1) then my:= my - 1
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
   402
        else if (my = -1) and (mx <> 1) then mx:= mx + 1
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
   403
        else if (mx = 1) and (my <> 1) then my:= my + 1
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
   404
        else mx:= mx - 1;
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
   405
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
   406
        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
   407
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
   408
    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
   409
    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
   410
    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
   411
    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
   412
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   413
    // edge-crawl
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   414
    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
   415
        begin
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   416
        // using mx,my as temporary value buffer here
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3609
diff changeset
   417
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   418
        jfr:= 8+li+1;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   419
        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
   420
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   421
        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
   422
            begin
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   423
            tmpo:= j mod 8;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   424
            tmpx:= ldx + offset[tmpo,0];
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   425
            tmpy:= ldy + offset[tmpo,1];
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   426
            if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK)  = 0)
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   427
                and (Land[tmpy,tmpx] > TestWord) then
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
   428
                    begin
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
   429
                    ldx:= tmpx;
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
   430
                    ldy:= tmpy;
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
   431
                    break;
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
   432
                    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
   433
            end;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   434
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   435
        jfr:= 8+ri-1;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   436
        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
   437
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   438
        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
   439
            begin
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   440
            tmpo:= j mod 8;
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   441
            tmpx:= rdx + offset[tmpo,0];
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   442
            tmpy:= rdy + offset[tmpo,1];
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   443
            if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK)  = 0)
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   444
                and (Land[tmpy,tmpx] > TestWord) then
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
   445
                    begin
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
   446
                    rdx:= tmpx;
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
   447
                    rdy:= tmpy;
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
   448
                    break;
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
   449
                    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
   450
            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
   451
        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
   452
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
   453
    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
   454
    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
   455
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
   456
    if ((ldx = 0) and (ldy = 0)) then EXIT(false);
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
   457
3414
b2f3bb44777e some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents: 3411
diff changeset
   458
outDeltaX:= ldx;
b2f3bb44777e some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents: 3411
diff changeset
   459
outDeltaY:= ldy;
3408
56e636b83cb4 tweak land angle detection/portal a bit
sheepluva
parents: 3407
diff changeset
   460
exit(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
   461
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
   462
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
   463
procedure initModule;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   464
begin
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2716
diff changeset
   465
    Count:= 0;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   466
end;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   467
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
   468
procedure freeModule;
2716
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   469
begin
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   470
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   471
end;
b9ca1bfca24f complete the replacement of init/free wrappers for every unit
koda
parents: 2630
diff changeset
   472
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   473
end.