author | Guillaume Englert |
Tue, 11 Oct 2011 10:44:27 -0400 | |
changeset 6125 | 663e05d9cf66 |
parent 6124 | bee90df26109 |
child 6279 | 7f724835ea57 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4976 | 3 |
* Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uCollisions; |
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 | 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 | 26 |
|
70 | 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 | 32 |
|
3038 | 33 |
procedure initModule; |
34 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
35 |
|
53 | 36 |
procedure AddGearCI(Gear: PGear); |
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; |
6081
537bbd5c1a62
Basic test implementation of an ice flag. Allows for slick parts of terrain. Intended for ice gun, or "ice" mask on portions of land objects.
nemo
parents:
5919
diff
changeset
|
42 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; |
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 | 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 |
|
5750
6bbf7aee2cdf
Reenable a bunch of old portal play stuff, like dropping grenade into portal on hog, jumping through portal w/ hog on other end, collecting crate w/ portal etc. Also add cooldown to cake/portal interaction. It may still not do what you expect, but it probably shouldn't spin in place.
nemo
parents:
5572
diff
changeset
|
50 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; |
6bbf7aee2cdf
Reenable a bunch of old portal play stuff, like dropping grenade into portal on hog, jumping through portal w/ hog on other end, collecting crate w/ portal etc. Also add cooldown to cake/portal interaction. It may still not do what you expect, but it probably shouldn't spin in place.
nemo
parents:
5572
diff
changeset
|
51 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; |
4 | 52 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
53 |
function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; |
6124 | 54 |
|
55 |
function CalcSlopeTangentBelowGear(Gear: PGear; var outDeltaX, outDeltaY: LongInt): boolean; |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
56 |
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
|
57 |
|
4 | 58 |
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
|
59 |
uses uConsts, uLandGraphics, uVariables, uDebug, uGears; |
4 | 60 |
|
53 | 61 |
type TCollisionEntry = record |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
62 |
X, Y, Radius: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
63 |
cGear: PGear; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
64 |
end; |
351 | 65 |
|
5568 | 66 |
const MAXRECTSINDEX = 1023; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
67 |
var Count: Longword; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
68 |
cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
69 |
ga: TGearArray; |
4 | 70 |
|
53 | 71 |
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
|
72 |
var t: PGear; |
53 | 73 |
begin |
511 | 74 |
if Gear^.CollisionIndex >= 0 then exit; |
4 | 75 |
TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true); |
53 | 76 |
with cinfos[Count] do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
77 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
78 |
X:= hwRound(Gear^.X); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
79 |
Y:= hwRound(Gear^.Y); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
cGear:= Gear |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
83 |
end; |
511 | 84 |
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
|
85 |
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
|
86 |
// 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
|
87 |
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
|
88 |
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
|
89 |
t:= GearsList; |
5572 | 90 |
while (t <> nil) and (t^.Kind <> gtMine) do |
91 |
t:= t^.NextGear; |
|
92 |
if (t <> nil) then DeleteGear(t) |
|
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
|
93 |
end; |
4 | 94 |
end; |
95 |
||
53 | 96 |
procedure DeleteCI(Gear: PGear); |
4 | 97 |
begin |
511 | 98 |
if Gear^.CollisionIndex >= 0 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
99 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
100 |
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
|
101 |
ChangeRoundInLand(X, Y, Radius - 1, false); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
102 |
cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
103 |
cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
104 |
Gear^.CollisionIndex:= -1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
105 |
dec(Count) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
106 |
end; |
4 | 107 |
end; |
108 |
||
53 | 109 |
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
|
110 |
var mx, my, tr: LongInt; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
111 |
i: Longword; |
4 | 112 |
begin |
1506 | 113 |
CheckGearsCollision:= @ga; |
53 | 114 |
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
|
115 |
if Count = 0 then exit; |
351 | 116 |
mx:= hwRound(Gear^.X); |
117 |
my:= hwRound(Gear^.Y); |
|
4 | 118 |
|
4705
593ef1ad3cd3
ok. restore old [r + 1 + r] for gear width for a moment, and reset snowballs.
nemo
parents:
4684
diff
changeset
|
119 |
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
|
120 |
|
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 |
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
|
122 |
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
|
123 |
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
|
124 |
(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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
end |
4 | 129 |
end; |
130 |
||
371 | 131 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean; |
132 |
var x, y, i: LongInt; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
133 |
TestWord: LongWord; |
4 | 134 |
begin |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
135 |
if Gear^.IntersectGear <> nil then |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
136 |
with Gear^ do |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
137 |
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
|
138 |
(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
|
139 |
begin |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
140 |
IntersectGear:= nil; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
141 |
TestWord:= 0 |
838 | 142 |
end else |
1966 | 143 |
TestWord:= 255 |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
144 |
else TestWord:= 0; |
838 | 145 |
|
351 | 146 |
x:= hwRound(Gear^.X); |
147 |
if Dir < 0 then x:= x - Gear^.Radius |
|
148 |
else x:= x + Gear^.Radius; |
|
1753 | 149 |
if (x and LAND_WIDTH_MASK) = 0 then |
4 | 150 |
begin |
351 | 151 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
152 |
i:= y + Gear^.Radius * 2 - 2; |
|
4 | 153 |
repeat |
1753 | 154 |
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
|
155 |
if Land[y, x] > TestWord then exit(true); |
4 | 156 |
inc(y) |
351 | 157 |
until (y > i); |
158 |
end; |
|
159 |
TestCollisionXwithGear:= false |
|
4 | 160 |
end; |
161 |
||
6081
537bbd5c1a62
Basic test implementation of an ice flag. Allows for slick parts of terrain. Intended for ice gun, or "ice" mask on portions of land objects.
nemo
parents:
5919
diff
changeset
|
162 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
163 |
var x, y, i: LongInt; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
164 |
TestWord: LongWord; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
165 |
begin |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
166 |
if Gear^.IntersectGear <> nil then |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
167 |
with Gear^ do |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
168 |
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
|
169 |
(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
|
170 |
begin |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
171 |
IntersectGear:= nil; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
172 |
TestWord:= 0 |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
173 |
end else |
1966 | 174 |
TestWord:= 255 |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
175 |
else TestWord:= 0; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
176 |
|
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
177 |
y:= hwRound(Gear^.Y); |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
178 |
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
|
179 |
else y:= y + Gear^.Radius; |
1753 | 180 |
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
|
181 |
begin |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
182 |
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
|
183 |
i:= x + Gear^.Radius * 2 - 2; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
184 |
repeat |
1753 | 185 |
if (x and LAND_WIDTH_MASK) = 0 then |
6081
537bbd5c1a62
Basic test implementation of an ice flag. Allows for slick parts of terrain. Intended for ice gun, or "ice" mask on portions of land objects.
nemo
parents:
5919
diff
changeset
|
186 |
if Land[y, x] > TestWord then exit(Land[y, x]); |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
187 |
inc(x) |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
188 |
until (x > i); |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
189 |
end; |
6081
537bbd5c1a62
Basic test implementation of an ice flag. Allows for slick parts of terrain. Intended for ice gun, or "ice" mask on portions of land objects.
nemo
parents:
5919
diff
changeset
|
190 |
TestCollisionYwithGear:= 0 |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
191 |
end; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
192 |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
193 |
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
|
194 |
var x, y, mx, my, i: LongInt; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
195 |
flag: boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
196 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
197 |
flag:= false; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
198 |
x:= hwRound(Gear^.X); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
199 |
if Dir < 0 then x:= x - Gear^.Radius |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
200 |
else x:= x + Gear^.Radius; |
1753 | 201 |
if (x and LAND_WIDTH_MASK) = 0 then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
202 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
203 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
204 |
i:= y + Gear^.Radius * 2 - 2; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
205 |
repeat |
1753 | 206 |
if (y and LAND_HEIGHT_MASK) = 0 then |
1966 | 207 |
if Land[y, x] > 255 then exit(true) |
536 | 208 |
else if Land[y, x] <> 0 then flag:= true; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
209 |
inc(y) |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
210 |
until (y > i); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
211 |
end; |
538 | 212 |
TestCollisionXKick:= flag; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
213 |
|
536 | 214 |
if flag then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
215 |
begin |
538 | 216 |
if hwAbs(Gear^.dX) < cHHKick then exit; |
967 | 217 |
if (Gear^.State and gstHHJumping <> 0) |
218 |
and (hwAbs(Gear^.dX) < _0_4) then exit; |
|
219 |
||
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
220 |
mx:= hwRound(Gear^.X); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
221 |
my:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
222 |
|
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
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
(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
|
227 |
((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
|
228 |
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
|
229 |
// 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
|
230 |
((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
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
end |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
243 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
244 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
245 |
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
|
246 |
var x, y, mx, my, i: LongInt; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
247 |
flag: boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
248 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
249 |
flag:= false; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
250 |
y:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
251 |
if Dir < 0 then y:= y - Gear^.Radius |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
252 |
else y:= y + Gear^.Radius; |
1753 | 253 |
if (y and LAND_HEIGHT_MASK) = 0 then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
254 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
255 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
256 |
i:= x + Gear^.Radius * 2 - 2; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
257 |
repeat |
1753 | 258 |
if (x and LAND_WIDTH_MASK) = 0 then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
259 |
if Land[y, x] > 0 then |
1966 | 260 |
if Land[y, x] > 255 then exit(true) |
536 | 261 |
else if Land[y, x] <> 0 then flag:= true; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
262 |
inc(x) |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
263 |
until (x > i); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
264 |
end; |
538 | 265 |
TestCollisionYKick:= flag; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
266 |
|
536 | 267 |
if flag then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
268 |
begin |
839 | 269 |
if hwAbs(Gear^.dY) < cHHKick then exit(true); |
967 | 270 |
if (Gear^.State and gstHHJumping <> 0) |
271 |
and (not Gear^.dY.isNegative) |
|
272 |
and (Gear^.dY < _0_4) then exit; |
|
273 |
||
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
274 |
mx:= hwRound(Gear^.X); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
275 |
my:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
276 |
|
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
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
(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
|
281 |
((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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
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
|
294 |
end |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
295 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
296 |
|
5750
6bbf7aee2cdf
Reenable a bunch of old portal play stuff, like dropping grenade into portal on hog, jumping through portal w/ hog on other end, collecting crate w/ portal etc. Also add cooldown to cake/portal interaction. It may still not do what you expect, but it probably shouldn't spin in place.
nemo
parents:
5572
diff
changeset
|
297 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; |
4 | 298 |
begin |
351 | 299 |
Gear^.X:= Gear^.X + ShiftX; |
498 | 300 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
5750
6bbf7aee2cdf
Reenable a bunch of old portal play stuff, like dropping grenade into portal on hog, jumping through portal w/ hog on other end, collecting crate w/ portal etc. Also add cooldown to cake/portal interaction. It may still not do what you expect, but it probably shouldn't spin in place.
nemo
parents:
5572
diff
changeset
|
301 |
if withGear then |
6bbf7aee2cdf
Reenable a bunch of old portal play stuff, like dropping grenade into portal on hog, jumping through portal w/ hog on other end, collecting crate w/ portal etc. Also add cooldown to cake/portal interaction. It may still not do what you expect, but it probably shouldn't spin in place.
nemo
parents:
5572
diff
changeset
|
302 |
TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir) |
6bbf7aee2cdf
Reenable a bunch of old portal play stuff, like dropping grenade into portal on hog, jumping through portal w/ hog on other end, collecting crate w/ portal etc. Also add cooldown to cake/portal interaction. It may still not do what you expect, but it probably shouldn't spin in place.
nemo
parents:
5572
diff
changeset
|
303 |
else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir); |
351 | 304 |
Gear^.X:= Gear^.X - ShiftX; |
498 | 305 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
4 | 306 |
end; |
4798 | 307 |
function TestCollisionX(Gear: PGear; Dir: LongInt): boolean; |
308 |
var x, y, i: LongInt; |
|
309 |
begin |
|
310 |
x:= hwRound(Gear^.X); |
|
311 |
if Dir < 0 then x:= x - Gear^.Radius |
|
312 |
else x:= x + Gear^.Radius; |
|
313 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
314 |
begin |
|
315 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
|
316 |
i:= y + Gear^.Radius * 2 - 2; |
|
317 |
repeat |
|
318 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
319 |
if Land[y, x] > 255 then exit(true); |
|
320 |
inc(y) |
|
321 |
until (y > i); |
|
322 |
end; |
|
323 |
TestCollisionX:= false |
|
324 |
end; |
|
4 | 325 |
|
371 | 326 |
function TestCollisionY(Gear: PGear; Dir: LongInt): boolean; |
327 |
var x, y, i: LongInt; |
|
68 | 328 |
begin |
351 | 329 |
y:= hwRound(Gear^.Y); |
330 |
if Dir < 0 then y:= y - Gear^.Radius |
|
331 |
else y:= y + Gear^.Radius; |
|
1753 | 332 |
if (y and LAND_HEIGHT_MASK) = 0 then |
68 | 333 |
begin |
351 | 334 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
335 |
i:= x + Gear^.Radius * 2 - 2; |
|
68 | 336 |
repeat |
1753 | 337 |
if (x and LAND_WIDTH_MASK) = 0 then |
1966 | 338 |
if Land[y, x] > 255 then exit(true); |
68 | 339 |
inc(x) |
351 | 340 |
until (x > i); |
341 |
end; |
|
342 |
TestCollisionY:= false |
|
68 | 343 |
end; |
344 |
||
5750
6bbf7aee2cdf
Reenable a bunch of old portal play stuff, like dropping grenade into portal on hog, jumping through portal w/ hog on other end, collecting crate w/ portal etc. Also add cooldown to cake/portal interaction. It may still not do what you expect, but it probably shouldn't spin in place.
nemo
parents:
5572
diff
changeset
|
345 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; |
4 | 346 |
begin |
498 | 347 |
Gear^.X:= Gear^.X + int2hwFloat(ShiftX); |
348 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
|
6081
537bbd5c1a62
Basic test implementation of an ice flag. Allows for slick parts of terrain. Intended for ice gun, or "ice" mask on portions of land objects.
nemo
parents:
5919
diff
changeset
|
349 |
if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) <> 0 |
5750
6bbf7aee2cdf
Reenable a bunch of old portal play stuff, like dropping grenade into portal on hog, jumping through portal w/ hog on other end, collecting crate w/ portal etc. Also add cooldown to cake/portal interaction. It may still not do what you expect, but it probably shouldn't spin in place.
nemo
parents:
5572
diff
changeset
|
350 |
else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir); |
498 | 351 |
Gear^.X:= Gear^.X - int2hwFloat(ShiftX); |
352 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
|
4 | 353 |
end; |
354 |
||
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
355 |
function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
356 |
var x, y: LongInt; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
357 |
TestWord: LongWord; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
358 |
begin |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
359 |
if landOnly then |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
360 |
TestWord:= 255 |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
361 |
else |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
362 |
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
|
363 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
364 |
if x1 > x2 then |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
365 |
begin |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
366 |
x := x1; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
367 |
x1 := x2; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
368 |
x2 := x; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
369 |
end; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
370 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
371 |
if y1 > y2 then |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
372 |
begin |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
373 |
y := y1; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
374 |
y1 := y2; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
375 |
y2 := y; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
376 |
end; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
377 |
|
5919
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
378 |
if (hasBorder and ((y1 < 0) or (x1 < 0) or (x2 > LAND_WIDTH))) then |
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
379 |
exit(true); |
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
380 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
381 |
for y := y1 to y2 do |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
382 |
for x := x1 to x2 do |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
383 |
if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
384 |
and (Land[y, x] > TestWord) then |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
385 |
exit(true); |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
386 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
387 |
TestRectancleForObstacle:= false |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
388 |
end; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
389 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
390 |
function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; |
3408 | 391 |
var ldx, ldy, rdx, rdy: LongInt; |
6123 | 392 |
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
|
393 |
tmpx, tmpy: LongWord; |
3569 | 394 |
dx, dy, s: hwFloat; |
3408 | 395 |
offset: Array[0..7,0..1] of ShortInt; |
6123 | 396 |
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
|
397 |
|
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
|
398 |
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
|
399 |
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
|
400 |
dy:= Gear^.dY; |
3408 | 401 |
|
3569 | 402 |
// we start searching from the direction the gear came from |
403 |
if (dx.QWordValue > _0_995.QWordValue ) |
|
404 |
or (dy.QWordValue > _0_995.QWordValue ) then |
|
405 |
begin // scale |
|
406 |
s := _1 / Distance(dx,dy); |
|
407 |
dx := s * dx; |
|
408 |
dy := s * dy; |
|
409 |
end; |
|
410 |
||
3408 | 411 |
mx:= hwRound(Gear^.X-dx) - hwRound(Gear^.X); |
412 |
my:= hwRound(Gear^.Y-dy) - hwRound(Gear^.Y); |
|
413 |
||
414 |
li:= -1; |
|
415 |
ri:= -1; |
|
3569 | 416 |
|
3408 | 417 |
// go around collision pixel, checking for first/last collisions |
418 |
// this will determinate what angles will be tried to crawl along |
|
419 |
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
|
420 |
begin |
3408 | 421 |
offset[i,0]:= mx; |
422 |
offset[i,1]:= my; |
|
3569 | 423 |
|
6123 | 424 |
// multiplicator k tries to skip small pixels/gaps when possible |
425 |
for k:= 4 downto 1 do |
|
426 |
begin |
|
427 |
tmpx:= collisionX + k * mx; |
|
428 |
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
|
429 |
|
6123 | 430 |
if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) then |
431 |
if (Land[tmpy,tmpx] > TestWord) then |
|
3408 | 432 |
begin |
6123 | 433 |
// remember the index belonging to the first and last collision (if in 1st half) |
434 |
if (i <> 0) then |
|
435 |
begin |
|
436 |
if (ri = -1) then |
|
437 |
ri:= i |
|
438 |
else |
|
439 |
li:= i; |
|
440 |
end; |
|
3408 | 441 |
end; |
6123 | 442 |
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
|
443 |
|
3408 | 444 |
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
|
445 |
|
3408 | 446 |
// 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
|
447 |
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
|
448 |
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
|
449 |
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
|
450 |
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
|
451 |
|
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 |
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
|
453 |
|
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 |
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
|
455 |
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
|
456 |
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
|
457 |
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
|
458 |
|
3408 | 459 |
// edge-crawl |
460 |
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
|
461 |
begin |
3408 | 462 |
// using mx,my as temporary value buffer here |
3697 | 463 |
|
3408 | 464 |
jfr:= 8+li+1; |
465 |
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
|
466 |
|
6123 | 467 |
isColl:= false; |
3408 | 468 |
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
|
469 |
begin |
3408 | 470 |
tmpo:= j mod 8; |
6123 | 471 |
// multiplicator k tries to skip small pixels/gaps when possible |
472 |
for k:= 3 downto 1 do |
|
473 |
begin |
|
474 |
tmpx:= ldx + k * offset[tmpo,0]; |
|
475 |
tmpy:= ldy + k * offset[tmpo,1]; |
|
476 |
if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) |
|
477 |
and (Land[tmpy,tmpx] > TestWord) then |
|
478 |
begin |
|
479 |
ldx:= tmpx; |
|
480 |
ldy:= tmpy; |
|
481 |
isColl:= true; |
|
482 |
break; |
|
483 |
end; |
|
484 |
end; |
|
485 |
if isColl 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
|
486 |
end; |
3408 | 487 |
|
488 |
jfr:= 8+ri-1; |
|
489 |
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
|
490 |
|
6123 | 491 |
isColl:= false; |
3408 | 492 |
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
|
493 |
begin |
3408 | 494 |
tmpo:= j mod 8; |
6123 | 495 |
for k:= 3 downto 1 do |
496 |
begin |
|
497 |
tmpx:= rdx + k * offset[tmpo,0]; |
|
498 |
tmpy:= rdy + k * offset[tmpo,1]; |
|
499 |
if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) |
|
500 |
and (Land[tmpy,tmpx] > TestWord) then |
|
501 |
begin |
|
502 |
rdx:= tmpx; |
|
503 |
rdy:= tmpy; |
|
504 |
isColl:= true; |
|
505 |
break; |
|
506 |
end; |
|
507 |
end; |
|
508 |
if isColl 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
|
509 |
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
|
510 |
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
|
511 |
|
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
|
512 |
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
|
513 |
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
|
514 |
|
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
|
515 |
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
|
516 |
|
3414
b2f3bb44777e
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents:
3411
diff
changeset
|
517 |
outDeltaX:= ldx; |
b2f3bb44777e
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents:
3411
diff
changeset
|
518 |
outDeltaY:= ldy; |
3408 | 519 |
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
|
520 |
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
|
521 |
|
6124 | 522 |
function CalcSlopeTangentBelowGear(Gear: PGear; var outDeltaX, outDeltaY: LongInt): boolean; |
523 |
var dx, dy: hwFloat; |
|
524 |
collX, i, y, x, gx: LongInt; |
|
525 |
isColl, succ: Boolean; |
|
526 |
begin |
|
527 |
// save original dx/dy |
|
528 |
dx:= Gear^.dX; |
|
529 |
dy:= Gear^.dY; |
|
530 |
||
531 |
Gear^.dX.QWordValue:= 0; |
|
532 |
Gear^.dY:= _1; |
|
533 |
||
534 |
y:= hwRound(Gear^.Y) + Gear^.Radius; |
|
535 |
gx:= hwRound(Gear^.X); |
|
536 |
collX := gx; |
|
537 |
isColl:= false; |
|
538 |
||
539 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
540 |
begin |
|
541 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
|
542 |
i:= x + Gear^.Radius * 2 - 2; |
|
543 |
repeat |
|
544 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
545 |
if Land[y, x] > 255 then |
|
546 |
if not isColl or (abs(x-gx) < abs(collX-gx)) then |
|
547 |
begin |
|
548 |
isColl:= true; |
|
549 |
collX := x; |
|
550 |
end; |
|
551 |
inc(x) |
|
552 |
until (x > i); |
|
553 |
end; |
|
554 |
||
555 |
if isColl then |
|
556 |
succ := CalcSlopeTangent(Gear, collX, y, outDeltaX, outDeltaY, 255) |
|
557 |
else |
|
558 |
succ := false; |
|
559 |
||
560 |
// restore original dx/dy |
|
561 |
Gear^.dX:= dx; |
|
562 |
Gear^.dY:= dy; |
|
563 |
||
564 |
CalcSlopeTangentBelowGear := succ; |
|
565 |
end; |
|
566 |
||
3038 | 567 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
568 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
569 |
Count:= 0; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
570 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
571 |
|
3038 | 572 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
573 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
574 |
|
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
575 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
576 |
|
4 | 577 |
end. |