author | unC0Rr |
Tue, 13 Nov 2018 16:54:40 +0100 | |
changeset 14227 | 257b296169a8 |
parent 14027 | 105793e575d6 |
child 14303 | 6015b74eea55 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10015
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uCollisions; |
22 |
interface |
|
12898 | 23 |
uses uFloat, uTypes, uUtils; |
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; |
12898 | 26 |
const cMaxGearHitOrderInd = 1023; |
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
27 |
const cMaxGearProximityCacheInd = 1023; |
4 | 28 |
|
70 | 29 |
type PGearArray = ^TGearArray; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
30 |
TGearArray = record |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
31 |
ar: array[0..cMaxGearArrayInd] of PGear; |
12898 | 32 |
cX: array[0..cMaxGearArrayInd] of LongInt; |
33 |
cY: array[0..cMaxGearArrayInd] of LongInt; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
34 |
Count: Longword |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
35 |
end; |
4 | 36 |
|
12898 | 37 |
type PGearHitOrder = ^TGearHitOrder; |
38 |
TGearHitOrder = record |
|
39 |
ar: array[0..cMaxGearHitOrderInd] of PGear; |
|
40 |
order: array[0..cMaxGearHitOrderInd] of LongInt; |
|
41 |
Count: Longword |
|
42 |
end; |
|
43 |
||
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
44 |
type PGearProximityCache = ^TGearProximityCache; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
45 |
TGearProximityCache = record |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
46 |
ar: array[0..cMaxGearProximityCacheInd] of PGear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
47 |
Count: Longword |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
48 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
49 |
|
12898 | 50 |
type TLineCollision = record |
51 |
hasCollision: Boolean; |
|
52 |
cX, cY: LongInt; //for visual effects only |
|
53 |
end; |
|
54 |
||
3038 | 55 |
procedure initModule; |
56 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
57 |
|
9291
15f7bb217b66
Make add/delete consistent (this has bugged me for so long)
nemo
parents:
9247
diff
changeset
|
58 |
procedure AddCI(Gear: PGear); |
53 | 59 |
procedure DeleteCI(Gear: PGear); |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
60 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
61 |
function CheckGearsCollision(Gear: PGear): PGearArray; |
12898 | 62 |
function CheckAllGearsCollision(SourceGear: PGear): PGearArray; |
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
63 |
function CheckCacheCollision(SourceGear: PGear): PGearArray; |
12898 | 64 |
|
65 |
function CheckGearsLineCollision(Gear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
66 |
function CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
67 |
||
68 |
function UpdateHitOrder(Gear: PGear; Order: LongInt): boolean; |
|
69 |
procedure ClearHitOrderLeq(MinOrder: LongInt); |
|
70 |
procedure ClearHitOrder(); |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
71 |
|
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
72 |
procedure RefillProximityCache(SourceGear: PGear; radius: LongInt); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
73 |
procedure RemoveFromProximityCache(Gear: PGear); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
74 |
procedure ClearProximityCache(); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
75 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
76 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): Word; |
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
|
77 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
78 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
79 |
function TestCollisionXKick(Gear: PGear; Dir: LongInt): Word; |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
80 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
81 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
82 |
function TestCollisionX(Gear: PGear; Dir: LongInt): Word; |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
83 |
function TestCollisionY(Gear: PGear; Dir: LongInt): Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
84 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
85 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): Word; inline; |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
86 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
87 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): Word; inline; |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
88 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; |
4 | 89 |
|
10818
f642a28cab0c
Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents:
10635
diff
changeset
|
90 |
function TestRectangleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; |
6124 | 91 |
|
10354 | 92 |
function CheckCoordInWater(X, Y: LongInt): boolean; inline; |
93 |
||
9248 | 94 |
// returns: negative sign if going downhill to left, value is steepness (noslope/error = _0, 45 = _0_5) |
6279 | 95 |
function CalcSlopeBelowGear(Gear: PGear): hwFloat; |
7754 | 96 |
function CalcSlopeNearGear(Gear: PGear; dirX, dirY: LongInt): hwFloat; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
97 |
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
|
98 |
|
4 | 99 |
implementation |
11532 | 100 |
uses uConsts, uLandGraphics, uVariables; |
4 | 101 |
|
53 | 102 |
type TCollisionEntry = record |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
103 |
X, Y, Radius: LongInt; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
104 |
cGear: PGear; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
105 |
end; |
351 | 106 |
|
5568 | 107 |
const MAXRECTSINDEX = 1023; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
108 |
var Count: Longword; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
109 |
cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
110 |
ga: TGearArray; |
12898 | 111 |
ordera: TGearHitOrder; |
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
112 |
proximitya: TGearProximityCache; |
4 | 113 |
|
9291
15f7bb217b66
Make add/delete consistent (this has bugged me for so long)
nemo
parents:
9247
diff
changeset
|
114 |
procedure AddCI(Gear: PGear); |
53 | 115 |
begin |
11532 | 116 |
if (Gear^.CollisionIndex >= 0) or (Count > MAXRECTSINDEX) or |
10551
4eefc711309e
Skip checkin on collision for frequently spammed gear types if collision gets huge instead of trying to delete mines.
nemo
parents:
10494
diff
changeset
|
117 |
((Count > MAXRECTSINDEX-200) and ((Gear^.Kind = gtMine) or (Gear^.Kind = gtSMine) or (Gear^.Kind = gtKnife))) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
118 |
exit; |
11532 | 119 |
|
53 | 120 |
with cinfos[Count] do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
121 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
122 |
X:= hwRound(Gear^.X); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
123 |
Y:= hwRound(Gear^.Y); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
124 |
Radius:= Gear^.Radius; |
11589
c453620cc6d6
Break up the hog/object collision. Currently is $7F, allowing 128 overlapping objects accurately. Breaking it up into 15 for hogs, 7 for other objects. I'm thinking the overall accuracy should be just fine as far as people noticing even with a ton of overlapping hogs, and this way we can tell the difference between a hog and "something else". For experiment and rope-breaking purposes, make rope pass through hogs.
nemo
parents:
11532
diff
changeset
|
125 |
ChangeRoundInLand(X, Y, Radius - 1, true, ((CurrentHedgehog <> nil) and (Gear = CurrentHedgehog^.Gear)) or ((Gear^.Kind = gtCase) and (Gear^.State and gstFrozen = 0)), Gear^.Kind = gtHedgehog); |
3608
c509bbc779e7
Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents:
3603
diff
changeset
|
126 |
cGear:= Gear |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
127 |
end; |
511 | 128 |
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
|
129 |
inc(Count); |
4 | 130 |
end; |
131 |
||
53 | 132 |
procedure DeleteCI(Gear: PGear); |
4 | 133 |
begin |
511 | 134 |
if Gear^.CollisionIndex >= 0 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
135 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
136 |
with cinfos[Gear^.CollisionIndex] do |
11589
c453620cc6d6
Break up the hog/object collision. Currently is $7F, allowing 128 overlapping objects accurately. Breaking it up into 15 for hogs, 7 for other objects. I'm thinking the overall accuracy should be just fine as far as people noticing even with a ton of overlapping hogs, and this way we can tell the difference between a hog and "something else". For experiment and rope-breaking purposes, make rope pass through hogs.
nemo
parents:
11532
diff
changeset
|
137 |
ChangeRoundInLand(X, Y, Radius - 1, false, ((CurrentHedgehog <> nil) and (Gear = CurrentHedgehog^.Gear)) or ((Gear^.Kind = gtCase) and (Gear^.State and gstFrozen = 0)), Gear^.Kind = gtHedgehog); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
138 |
cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
139 |
cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
140 |
Gear^.CollisionIndex:= -1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
141 |
dec(Count) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
142 |
end; |
4 | 143 |
end; |
144 |
||
10354 | 145 |
function CheckCoordInWater(X, Y: LongInt): boolean; inline; |
146 |
begin |
|
147 |
CheckCoordInWater:= (Y > cWaterLine) |
|
10494 | 148 |
or ((WorldEdge = weSea) and ((X < LongInt(leftX)) or (X > LongInt(rightX)))); |
10354 | 149 |
end; |
150 |
||
53 | 151 |
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
|
152 |
var mx, my, tr: LongInt; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
153 |
i: Longword; |
4 | 154 |
begin |
1506 | 155 |
CheckGearsCollision:= @ga; |
53 | 156 |
ga.Count:= 0; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
157 |
if Count = 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
158 |
exit; |
351 | 159 |
mx:= hwRound(Gear^.X); |
160 |
my:= hwRound(Gear^.Y); |
|
4 | 161 |
|
4705
593ef1ad3cd3
ok. restore old [r + 1 + r] for gear width for a moment, and reset snowballs.
nemo
parents:
4684
diff
changeset
|
162 |
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
|
163 |
|
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
(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
|
168 |
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
|
169 |
ga.ar[ga.Count]:= cinfos[i].cGear; |
12898 | 170 |
ga.cX[ga.Count]:= hwround(Gear^.X); |
171 |
ga.cY[ga.Count]:= hwround(Gear^.Y); |
|
3608
c509bbc779e7
Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents:
3603
diff
changeset
|
172 |
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
|
173 |
end |
4 | 174 |
end; |
175 |
||
12898 | 176 |
function CheckAllGearsCollision(SourceGear: PGear): PGearArray; |
177 |
var mx, my, tr: LongInt; |
|
178 |
Gear: PGear; |
|
179 |
begin |
|
180 |
CheckAllGearsCollision:= @ga; |
|
181 |
ga.Count:= 0; |
|
182 |
||
183 |
mx:= hwRound(SourceGear^.X); |
|
184 |
my:= hwRound(SourceGear^.Y); |
|
185 |
||
186 |
tr:= SourceGear^.Radius + 2; |
|
187 |
||
188 |
Gear:= GearsList; |
|
189 |
||
190 |
while Gear <> nil do |
|
191 |
begin |
|
192 |
if (Gear <> SourceGear) and |
|
193 |
(sqr(mx - hwRound(Gear^.x)) + sqr(my - hwRound(Gear^.y)) <= sqr(Gear^.Radius + tr))then |
|
194 |
begin |
|
195 |
ga.ar[ga.Count]:= Gear; |
|
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
196 |
ga.cX[ga.Count]:= mx; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
197 |
ga.cY[ga.Count]:= my; |
12898 | 198 |
inc(ga.Count) |
199 |
end; |
|
200 |
||
201 |
Gear := Gear^.NextGear |
|
202 |
end; |
|
203 |
end; |
|
204 |
||
205 |
function LineCollisionTest(oX, oY, dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
206 |
width: LongInt; Gear: PGear): |
|
207 |
TLineCollision; inline; |
|
208 |
var toCenterX, toCenterY, r, |
|
209 |
b, bSqr, c, desc, t: hwFloat; |
|
210 |
realT: extended; |
|
211 |
begin |
|
212 |
LineCollisionTest.hasCollision:= false; |
|
213 |
toCenterX:= (oX - Gear^.X); |
|
214 |
toCenterY:= (oY - Gear^.Y); |
|
215 |
r:= int2hwFloat(Gear^.Radius + width + 2); |
|
216 |
// Early cull to avoid multiplying large numbers |
|
217 |
if hwAbs(toCenterX) + hwAbs(toCenterY) > dirNormBound + r then |
|
218 |
exit; |
|
219 |
b:= dirX * toCenterX + dirY * toCenterY; |
|
220 |
c:= hwSqr(toCenterX) + hwSqr(toCenterY) - hwSqr(r); |
|
221 |
if (b > _0) and (c > _0) then |
|
222 |
exit; |
|
223 |
bSqr:= hwSqr(b); |
|
224 |
desc:= bSqr - dirNormSqr * c; |
|
225 |
if desc.isNegative then exit; |
|
226 |
||
227 |
t:= -b - hwSqrt(desc); |
|
228 |
if t.isNegative then t:= _0; |
|
229 |
if t < dirNormSqr then |
|
230 |
with LineCollisionTest do |
|
231 |
begin |
|
232 |
hasCollision:= true; |
|
233 |
realT := hwFloat2Float(t) / hwFloat2Float(dirNormSqr); |
|
234 |
cX:= round(hwFloat2Float(oX) + realT * hwFloat2Float(dirX)); |
|
235 |
cY:= round(hwFloat2Float(oY) + realT * hwFloat2Float(dirY)); |
|
236 |
end; |
|
237 |
end; |
|
238 |
||
239 |
function CheckGearsLineCollision(Gear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
240 |
var dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
241 |
test: TLineCollision; |
|
242 |
i: Longword; |
|
243 |
begin |
|
244 |
CheckGearsLineCollision:= @ga; |
|
245 |
ga.Count:= 0; |
|
246 |
if Count = 0 then |
|
247 |
exit; |
|
248 |
dirX:= (tX - oX); |
|
249 |
dirY:= (tY - oY); |
|
250 |
dirNormBound:= _1_5 * (hwAbs(dirX) + hwAbs(dirY)); |
|
251 |
dirNormSqr:= hwSqr(dirX) + hwSqr(dirY); |
|
252 |
if dirNormSqr.isNegative then |
|
253 |
exit; |
|
254 |
||
255 |
for i:= 0 to Pred(Count) do |
|
256 |
with cinfos[i] do if Gear <> cGear then |
|
257 |
begin |
|
258 |
test:= LineCollisionTest( |
|
259 |
oX, oY, dirX, dirY, dirNormSqr, dirNormBound, Gear^.Radius, cGear); |
|
260 |
if test.hasCollision then |
|
261 |
begin |
|
262 |
ga.ar[ga.Count] := cGear; |
|
263 |
ga.cX[ga.Count] := test.cX; |
|
264 |
ga.cY[ga.Count] := test.cY; |
|
265 |
inc(ga.Count) |
|
266 |
end |
|
267 |
end |
|
268 |
end; |
|
269 |
||
270 |
function CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
271 |
var dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
272 |
test: TLineCollision; |
|
273 |
Gear: PGear; |
|
274 |
begin |
|
275 |
CheckAllGearsLineCollision:= @ga; |
|
276 |
ga.Count:= 0; |
|
277 |
dirX:= (tX - oX); |
|
278 |
dirY:= (tY - oY); |
|
279 |
dirNormBound:= _1_5 * (hwAbs(dirX) + hwAbs(dirY)); |
|
280 |
dirNormSqr:= hwSqr(dirX) + hwSqr(dirY); |
|
281 |
if dirNormSqr.isNegative then |
|
282 |
exit; |
|
283 |
||
284 |
Gear:= GearsList; |
|
285 |
while Gear <> nil do |
|
286 |
begin |
|
287 |
if SourceGear <> Gear then |
|
288 |
begin |
|
289 |
test:= LineCollisionTest( |
|
290 |
oX, oY, dirX, dirY, dirNormSqr, dirNormBound, SourceGear^.Radius, Gear); |
|
291 |
if test.hasCollision then |
|
292 |
begin |
|
293 |
ga.ar[ga.Count] := Gear; |
|
294 |
ga.cX[ga.Count] := test.cX; |
|
295 |
ga.cY[ga.Count] := test.cY; |
|
296 |
inc(ga.Count) |
|
297 |
end |
|
298 |
end; |
|
299 |
Gear := Gear^.NextGear |
|
300 |
end; |
|
301 |
end; |
|
302 |
||
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
303 |
function CheckCacheCollision(SourceGear: PGear): PGearArray; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
304 |
var mx, my, tr, i: LongInt; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
305 |
Gear: PGear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
306 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
307 |
CheckCacheCollision:= @ga; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
308 |
ga.Count:= 0; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
309 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
310 |
mx:= hwRound(SourceGear^.X); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
311 |
my:= hwRound(SourceGear^.Y); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
312 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
313 |
tr:= SourceGear^.Radius + 2; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
314 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
315 |
for i:= 0 to proximitya.Count - 1 do |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
316 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
317 |
Gear:= proximitya.ar[i]; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
318 |
// Assuming the cache has been filled correctly, it will not contain SourceGear |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
319 |
// and other gears won't be far enough for sqr overflow |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
320 |
if (sqr(mx - hwRound(Gear^.X)) + sqr(my - hwRound(Gear^.Y)) <= sqr(Gear^.Radius + tr)) then |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
321 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
322 |
ga.ar[ga.Count]:= Gear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
323 |
ga.cX[ga.Count]:= mx; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
324 |
ga.cY[ga.Count]:= my; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
325 |
inc(ga.Count) |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
326 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
327 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
328 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
329 |
|
12898 | 330 |
function UpdateHitOrder(Gear: PGear; Order: LongInt): boolean; |
331 |
var i: LongInt; |
|
332 |
begin |
|
333 |
UpdateHitOrder:= true; |
|
13168
0e7eddfbce8a
Fix minigun bullets sometimes failing to hit when shooting same thing twice in row
alfadur
parents:
12898
diff
changeset
|
334 |
for i:= 0 to ordera.Count - 1 do |
12898 | 335 |
if ordera.ar[i] = Gear then |
336 |
begin |
|
337 |
if Order <= ordera.order[i] then UpdateHitOrder:= false; |
|
338 |
ordera.order[i]:= Max(ordera.order[i], order); |
|
339 |
exit; |
|
340 |
end; |
|
341 |
||
342 |
if ordera.Count > cMaxGearHitOrderInd then |
|
343 |
UpdateHitOrder:= false |
|
344 |
else |
|
345 |
begin |
|
346 |
ordera.ar[ordera.Count]:= Gear; |
|
347 |
ordera.order[ordera.Count]:= Order; |
|
348 |
Inc(ordera.Count); |
|
349 |
end |
|
350 |
end; |
|
351 |
||
352 |
procedure ClearHitOrderLeq(MinOrder: LongInt); |
|
353 |
var i, freeIndex: LongInt; |
|
354 |
begin; |
|
355 |
freeIndex:= 0; |
|
356 |
i:= 0; |
|
357 |
||
358 |
while i < ordera.Count do |
|
359 |
begin |
|
360 |
if ordera.order[i] <= MinOrder then |
|
361 |
Dec(ordera.Count) |
|
362 |
else |
|
363 |
begin |
|
364 |
if freeIndex < i then |
|
365 |
begin |
|
366 |
ordera.ar[freeIndex]:= ordera.ar[i]; |
|
367 |
ordera.order[freeIndex]:= ordera.order[i]; |
|
368 |
end; |
|
369 |
Inc(freeIndex); |
|
370 |
end; |
|
371 |
Inc(i) |
|
372 |
end |
|
373 |
end; |
|
374 |
||
375 |
procedure ClearHitOrder(); |
|
376 |
begin |
|
377 |
ordera.Count:= 0; |
|
378 |
end; |
|
379 |
||
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
380 |
procedure RefillProximityCache(SourceGear: PGear; radius: LongInt); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
381 |
var cx, cy, dx, dy, r: LongInt; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
382 |
Gear: PGear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
383 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
384 |
proximitya.Count:= 0; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
385 |
cx:= hwRound(SourceGear^.X); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
386 |
cy:= hwRound(SourceGear^.Y); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
387 |
Gear:= GearsList; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
388 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
389 |
while (Gear <> nil) and (proximitya.Count <= cMaxGearProximityCacheInd) do |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
390 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
391 |
dx:= abs(hwRound(Gear^.X) - cx); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
392 |
dy:= abs(hwRound(Gear^.Y) - cy); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
393 |
r:= radius + Gear^.radius + 2; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
394 |
if (Gear <> SourceGear) and (max(dx, dy) <= r) and (sqr(dx) + sqr(dy) <= sqr(r)) then |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
395 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
396 |
proximitya.ar[proximitya.Count]:= Gear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
397 |
inc(proximitya.Count) |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
398 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
399 |
Gear := Gear^.NextGear |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
400 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
401 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
402 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
403 |
procedure RemoveFromProximityCache(Gear: PGear); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
404 |
var i: LongInt; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
405 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
406 |
i := 0; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
407 |
while i < proximitya.Count do |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
408 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
409 |
if proximitya.ar[i] = Gear then |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
410 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
411 |
proximitya.ar[i]:= proximitya.ar[proximitya.Count - 1]; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
412 |
dec(proximitya.Count); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
413 |
end |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
414 |
else |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
415 |
inc(i); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
416 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
417 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
418 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
419 |
procedure ClearProximityCache(); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
420 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
421 |
proximitya.Count:= 0; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
422 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
423 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
424 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): Word; |
371 | 425 |
var x, y, i: LongInt; |
4 | 426 |
begin |
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
427 |
// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap |
13469
f1d349a52bc7
Refactor: lfCurrentHog→lfCurHogCrate, lfNotCurrentMask→lfNotCurHogCrate
Wuzzy <Wuzzy2@mail.ru>
parents:
13168
diff
changeset
|
428 |
if (Gear^.CollisionMask = lfNotCurHogCrate) and (Gear^.Kind <> gtHedgehog) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and |
7754 | 429 |
((hwRound(Gear^.Hedgehog^.Gear^.X) + Gear^.Hedgehog^.Gear^.Radius + 16 < hwRound(Gear^.X) - Gear^.Radius) or |
430 |
(hwRound(Gear^.Hedgehog^.Gear^.X) - Gear^.Hedgehog^.Gear^.Radius - 16 > hwRound(Gear^.X) + Gear^.Radius)) then |
|
13470
7b4643ff60ea
Refactor collision mask checks, remove hardcoded numbers
Wuzzy <Wuzzy2@mail.ru>
parents:
13469
diff
changeset
|
431 |
Gear^.CollisionMask:= lfAll; |
838 | 432 |
|
351 | 433 |
x:= hwRound(Gear^.X); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
434 |
if Dir < 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
435 |
x:= x - Gear^.Radius |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
436 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
437 |
x:= x + Gear^.Radius; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
438 |
|
1753 | 439 |
if (x and LAND_WIDTH_MASK) = 0 then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
440 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
441 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
442 |
i:= y + Gear^.Radius * 2 - 2; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
443 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
444 |
if (y and LAND_HEIGHT_MASK) = 0 then |
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
445 |
if Land[y, x] and Gear^.CollisionMask <> 0 then |
9731
953197ac43d8
Make sticky mine respect lfBouncy, make hogs do same, kinda... make uCollisions return land w/ mask, restrict bouncy to advbounce gears only, which means piano doesn't bounce anymore
nemo
parents:
9708
diff
changeset
|
446 |
exit(Land[y, x] and Gear^.CollisionMask); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
447 |
inc(y) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
448 |
until (y > i); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
449 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
450 |
TestCollisionXwithGear:= 0 |
4 | 451 |
end; |
452 |
||
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
|
453 |
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
|
454 |
var x, y, i: LongInt; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
455 |
begin |
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
456 |
// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap |
13469
f1d349a52bc7
Refactor: lfCurrentHog→lfCurHogCrate, lfNotCurrentMask→lfNotCurHogCrate
Wuzzy <Wuzzy2@mail.ru>
parents:
13168
diff
changeset
|
457 |
if (Gear^.CollisionMask = lfNotCurHogCrate) and (Gear^.Kind <> gtHedgehog) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and |
7754 | 458 |
((hwRound(Gear^.Hedgehog^.Gear^.Y) + Gear^.Hedgehog^.Gear^.Radius + 16 < hwRound(Gear^.Y) - Gear^.Radius) or |
459 |
(hwRound(Gear^.Hedgehog^.Gear^.Y) - Gear^.Hedgehog^.Gear^.Radius - 16 > hwRound(Gear^.Y) + Gear^.Radius)) then |
|
13470
7b4643ff60ea
Refactor collision mask checks, remove hardcoded numbers
Wuzzy <Wuzzy2@mail.ru>
parents:
13469
diff
changeset
|
460 |
Gear^.CollisionMask:= lfAll; |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
461 |
|
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
462 |
y:= hwRound(Gear^.Y); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
463 |
if Dir < 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
464 |
y:= y - Gear^.Radius |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
465 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
466 |
y:= y + Gear^.Radius; |
7268 | 467 |
|
1753 | 468 |
if (y and LAND_HEIGHT_MASK) = 0 then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
469 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
470 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
471 |
i:= x + Gear^.Radius * 2 - 2; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
472 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
473 |
if (x and LAND_WIDTH_MASK) = 0 then |
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
474 |
if Land[y, x] and Gear^.CollisionMask <> 0 then |
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
475 |
begin |
9731
953197ac43d8
Make sticky mine respect lfBouncy, make hogs do same, kinda... make uCollisions return land w/ mask, restrict bouncy to advbounce gears only, which means piano doesn't bounce anymore
nemo
parents:
9708
diff
changeset
|
476 |
exit(Land[y, x] and Gear^.CollisionMask) |
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
477 |
end; |
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
478 |
inc(x) |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
479 |
until (x > i); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
480 |
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
|
481 |
TestCollisionYwithGear:= 0 |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
482 |
end; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
483 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
484 |
function TestCollisionXKick(Gear: PGear; Dir: LongInt): Word; |
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
|
485 |
var x, y, mx, my, i: LongInt; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
486 |
pixel: Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
487 |
begin |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
488 |
pixel:= 0; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
489 |
x:= hwRound(Gear^.X); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
490 |
if Dir < 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
491 |
x:= x - Gear^.Radius |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
492 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
493 |
x:= x + Gear^.Radius; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
494 |
|
1753 | 495 |
if (x and LAND_WIDTH_MASK) = 0 then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
496 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
497 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
498 |
i:= y + Gear^.Radius * 2 - 2; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
499 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
500 |
if (y and LAND_HEIGHT_MASK) = 0 then |
11077 | 501 |
begin |
502 |
if Land[y, x] and Gear^.CollisionMask <> 0 then |
|
503 |
begin |
|
13470
7b4643ff60ea
Refactor collision mask checks, remove hardcoded numbers
Wuzzy <Wuzzy2@mail.ru>
parents:
13469
diff
changeset
|
504 |
if ((Land[y, x] and Gear^.CollisionMask) and lfNotObjMask) <> 0 then |
11077 | 505 |
exit(Land[y, x] and Gear^.CollisionMask) |
506 |
else |
|
507 |
pixel:= Land[y, x] and Gear^.CollisionMask; |
|
508 |
end; |
|
509 |
end; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
510 |
inc(y) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
511 |
until (y > i); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
512 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
513 |
TestCollisionXKick:= pixel; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
514 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
515 |
if pixel <> 0 then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
516 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
517 |
if hwAbs(Gear^.dX) < cHHKick then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
518 |
exit; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
519 |
if (Gear^.State and gstHHJumping <> 0) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
520 |
and (hwAbs(Gear^.dX) < _0_4) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
521 |
exit; |
967 | 522 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
523 |
mx:= hwRound(Gear^.X); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
524 |
my:= hwRound(Gear^.Y); |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
525 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
526 |
for i:= 0 to Pred(Count) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
527 |
with cinfos[i] do |
10015 | 528 |
if (Gear <> cGear) and |
9305
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
529 |
((mx > x) xor (Dir > 0)) and |
7756
b89bd0ffb8aa
Try to prevent a situation where hogs embedded in other hogs/barrels/cleavers get stuck, by checking for gears overlapping on Y
nemo
parents:
7754
diff
changeset
|
530 |
( |
b89bd0ffb8aa
Try to prevent a situation where hogs embedded in other hogs/barrels/cleavers get stuck, by checking for gears overlapping on Y
nemo
parents:
7754
diff
changeset
|
531 |
((cGear^.Kind in [gtHedgehog, gtMine, gtKnife]) and ((Gear^.State and gstNotKickable) = 0)) or |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
532 |
// only apply X kick if the barrel is knocked over |
9305
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
533 |
((cGear^.Kind = gtExplosives) and ((cGear^.State and gsttmpflag) <> 0)) |
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
534 |
) and |
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
535 |
(sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
536 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
537 |
with cGear^ do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
538 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
539 |
dX:= Gear^.dX; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
540 |
dY:= Gear^.dY * _0_5; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
541 |
State:= State or gstMoving; |
7767 | 542 |
if Kind = gtKnife then State:= State and (not gstCollision); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
543 |
Active:= true |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
544 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
545 |
DeleteCI(cGear); |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
546 |
exit(0); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
547 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
548 |
end |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
549 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
550 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
551 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): Word; |
7756
b89bd0ffb8aa
Try to prevent a situation where hogs embedded in other hogs/barrels/cleavers get stuck, by checking for gears overlapping on Y
nemo
parents:
7754
diff
changeset
|
552 |
var x, y, mx, my, myr, i: LongInt; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
553 |
pixel: Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
554 |
begin |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
555 |
pixel:= 0; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
556 |
y:= hwRound(Gear^.Y); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
557 |
if Dir < 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
558 |
y:= y - Gear^.Radius |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
559 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
560 |
y:= y + Gear^.Radius; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
561 |
|
1753 | 562 |
if (y and LAND_HEIGHT_MASK) = 0 then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
563 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
564 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
565 |
i:= x + Gear^.Radius * 2 - 2; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
566 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
567 |
if (x and LAND_WIDTH_MASK) = 0 then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
568 |
if Land[y, x] > 0 then |
11077 | 569 |
begin |
13470
7b4643ff60ea
Refactor collision mask checks, remove hardcoded numbers
Wuzzy <Wuzzy2@mail.ru>
parents:
13469
diff
changeset
|
570 |
if ((Land[y, x] and Gear^.CollisionMask) and lfNotObjMask) <> 0 then |
9731
953197ac43d8
Make sticky mine respect lfBouncy, make hogs do same, kinda... make uCollisions return land w/ mask, restrict bouncy to advbounce gears only, which means piano doesn't bounce anymore
nemo
parents:
9708
diff
changeset
|
571 |
exit(Land[y, x] and Gear^.CollisionMask) |
11077 | 572 |
else // if Land[y, x] <> 0 then |
9731
953197ac43d8
Make sticky mine respect lfBouncy, make hogs do same, kinda... make uCollisions return land w/ mask, restrict bouncy to advbounce gears only, which means piano doesn't bounce anymore
nemo
parents:
9708
diff
changeset
|
573 |
pixel:= Land[y, x] and Gear^.CollisionMask; |
11077 | 574 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
575 |
inc(x) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
576 |
until (x > i); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
577 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
578 |
TestCollisionYKick:= pixel; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
579 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
580 |
if pixel <> 0 then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
581 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
582 |
if hwAbs(Gear^.dY) < cHHKick then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
583 |
exit; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
584 |
if (Gear^.State and gstHHJumping <> 0) and (not Gear^.dY.isNegative) and (Gear^.dY < _0_4) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
585 |
exit; |
967 | 586 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
587 |
mx:= hwRound(Gear^.X); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
588 |
my:= hwRound(Gear^.Y); |
7756
b89bd0ffb8aa
Try to prevent a situation where hogs embedded in other hogs/barrels/cleavers get stuck, by checking for gears overlapping on Y
nemo
parents:
7754
diff
changeset
|
589 |
myr:= my+Gear^.Radius; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
590 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
591 |
for i:= 0 to Pred(Count) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
592 |
with cinfos[i] do |
9305
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
593 |
if (Gear <> cGear) and |
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
594 |
((myr > y) xor (Dir > 0)) and |
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
595 |
(Gear^.State and gstNotKickable = 0) and |
10015 | 596 |
(cGear^.Kind in [gtHedgehog, gtMine, gtKnife, gtExplosives]) and |
9305
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
597 |
(sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
598 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
599 |
with cGear^ do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
600 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
601 |
if (Kind <> gtExplosives) or ((State and gsttmpflag) <> 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
602 |
dX:= Gear^.dX * _0_5; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
603 |
dY:= Gear^.dY; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
604 |
State:= State or gstMoving; |
7767 | 605 |
if Kind = gtKnife then State:= State and (not gstCollision); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
606 |
Active:= true |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
607 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
608 |
DeleteCI(cGear); |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
609 |
exit(0) |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
610 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
611 |
end |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
612 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
613 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
614 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): Word; inline; |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
615 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
616 |
TestCollisionXwithXYShift:= TestCollisionXwithXYShift(Gear, ShiftX, ShiftY, Dir, true); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
617 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
618 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
619 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; |
4 | 620 |
begin |
351 | 621 |
Gear^.X:= Gear^.X + ShiftX; |
498 | 622 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
10015 | 623 |
if withGear then |
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
|
624 |
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
|
625 |
else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir); |
351 | 626 |
Gear^.X:= Gear^.X - ShiftX; |
498 | 627 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
4 | 628 |
end; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
629 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
630 |
function TestCollisionX(Gear: PGear; Dir: LongInt): Word; |
4798 | 631 |
var x, y, i: LongInt; |
632 |
begin |
|
633 |
x:= hwRound(Gear^.X); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
634 |
if Dir < 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
635 |
x:= x - Gear^.Radius |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
636 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
637 |
x:= x + Gear^.Radius; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
638 |
|
4798 | 639 |
if (x and LAND_WIDTH_MASK) = 0 then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
640 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
641 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
642 |
i:= y + Gear^.Radius * 2 - 2; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
643 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
644 |
if (y and LAND_HEIGHT_MASK) = 0 then |
13470
7b4643ff60ea
Refactor collision mask checks, remove hardcoded numbers
Wuzzy <Wuzzy2@mail.ru>
parents:
13469
diff
changeset
|
645 |
if ((Land[y, x] and Gear^.CollisionMask) and lfNotObjMask) <> 0 then |
9731
953197ac43d8
Make sticky mine respect lfBouncy, make hogs do same, kinda... make uCollisions return land w/ mask, restrict bouncy to advbounce gears only, which means piano doesn't bounce anymore
nemo
parents:
9708
diff
changeset
|
646 |
exit(Land[y, x] and Gear^.CollisionMask); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
647 |
inc(y) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
648 |
until (y > i); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
649 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
650 |
TestCollisionX:= 0 |
4798 | 651 |
end; |
4 | 652 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
653 |
function TestCollisionY(Gear: PGear; Dir: LongInt): Word; |
371 | 654 |
var x, y, i: LongInt; |
68 | 655 |
begin |
351 | 656 |
y:= hwRound(Gear^.Y); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
657 |
if Dir < 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
658 |
y:= y - Gear^.Radius |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
659 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
660 |
y:= y + Gear^.Radius; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
661 |
|
1753 | 662 |
if (y and LAND_HEIGHT_MASK) = 0 then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
663 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
664 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
665 |
i:= x + Gear^.Radius * 2 - 2; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
666 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
667 |
if (x and LAND_WIDTH_MASK) = 0 then |
13470
7b4643ff60ea
Refactor collision mask checks, remove hardcoded numbers
Wuzzy <Wuzzy2@mail.ru>
parents:
13469
diff
changeset
|
668 |
if ((Land[y, x] and Gear^.CollisionMask) and lfNotObjMask) <> 0 then |
9731
953197ac43d8
Make sticky mine respect lfBouncy, make hogs do same, kinda... make uCollisions return land w/ mask, restrict bouncy to advbounce gears only, which means piano doesn't bounce anymore
nemo
parents:
9708
diff
changeset
|
669 |
exit(Land[y, x] and Gear^.CollisionMask); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
670 |
inc(x) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
671 |
until (x > i); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
672 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
673 |
TestCollisionY:= 0 |
68 | 674 |
end; |
675 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
676 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): Word; inline; |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
677 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
678 |
TestCollisionYwithXYShift:= TestCollisionYwithXYShift(Gear, ShiftX, ShiftY, Dir, true); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
679 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
680 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
681 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; |
4 | 682 |
begin |
498 | 683 |
Gear^.X:= Gear^.X + int2hwFloat(ShiftX); |
684 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
685 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
686 |
if withGear then |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
687 |
TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
688 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
689 |
TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir); |
10015 | 690 |
|
498 | 691 |
Gear^.X:= Gear^.X - int2hwFloat(ShiftX); |
692 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
|
4 | 693 |
end; |
694 |
||
10818
f642a28cab0c
Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents:
10635
diff
changeset
|
695 |
function TestRectangleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
696 |
var x, y: LongInt; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
697 |
TestWord: LongWord; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
698 |
begin |
10818
f642a28cab0c
Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents:
10635
diff
changeset
|
699 |
TestRectangleForObstacle:= true; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
700 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
701 |
if landOnly then |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
702 |
TestWord:= 255 |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
703 |
else |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
704 |
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
|
705 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
706 |
if x1 > x2 then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
707 |
begin |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
708 |
x := x1; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
709 |
x1 := x2; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
710 |
x2 := x; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
711 |
end; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
712 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
713 |
if y1 > y2 then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
714 |
begin |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
715 |
y := y1; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
716 |
y1 := y2; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
717 |
y2 := y; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
718 |
end; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
719 |
|
5919
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
720 |
if (hasBorder and ((y1 < 0) or (x1 < 0) or (x2 > LAND_WIDTH))) then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
721 |
exit; |
5919
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
722 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
723 |
for y := y1 to y2 do |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
724 |
for x := x1 to x2 do |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
725 |
if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] > TestWord) then |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
726 |
exit; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
727 |
|
10818
f642a28cab0c
Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents:
10635
diff
changeset
|
728 |
TestRectangleForObstacle:= false |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
729 |
end; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
730 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
731 |
function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; |
3408 | 732 |
var ldx, ldy, rdx, rdy: LongInt; |
6123 | 733 |
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
|
734 |
tmpx, tmpy: LongWord; |
3569 | 735 |
dx, dy, s: hwFloat; |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
736 |
offset: array[0..7,0..1] of ShortInt; |
6123 | 737 |
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
|
738 |
|
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
|
739 |
begin |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
740 |
CalcSlopeTangent:= false; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
741 |
|
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
|
742 |
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
|
743 |
dy:= Gear^.dY; |
3408 | 744 |
|
3569 | 745 |
// we start searching from the direction the gear came from |
746 |
if (dx.QWordValue > _0_995.QWordValue ) |
|
747 |
or (dy.QWordValue > _0_995.QWordValue ) then |
|
748 |
begin // scale |
|
6279 | 749 |
s := _0_995 / Distance(dx,dy); |
3569 | 750 |
dx := s * dx; |
751 |
dy := s * dy; |
|
752 |
end; |
|
753 |
||
3408 | 754 |
mx:= hwRound(Gear^.X-dx) - hwRound(Gear^.X); |
755 |
my:= hwRound(Gear^.Y-dy) - hwRound(Gear^.Y); |
|
756 |
||
757 |
li:= -1; |
|
758 |
ri:= -1; |
|
3569 | 759 |
|
3408 | 760 |
// go around collision pixel, checking for first/last collisions |
761 |
// this will determinate what angles will be tried to crawl along |
|
762 |
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
|
763 |
begin |
3408 | 764 |
offset[i,0]:= mx; |
765 |
offset[i,1]:= my; |
|
3569 | 766 |
|
6123 | 767 |
// multiplicator k tries to skip small pixels/gaps when possible |
768 |
for k:= 4 downto 1 do |
|
769 |
begin |
|
770 |
tmpx:= collisionX + k * mx; |
|
771 |
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
|
772 |
|
6123 | 773 |
if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) then |
774 |
if (Land[tmpy,tmpx] > TestWord) then |
|
3408 | 775 |
begin |
6123 | 776 |
// remember the index belonging to the first and last collision (if in 1st half) |
777 |
if (i <> 0) then |
|
778 |
begin |
|
779 |
if (ri = -1) then |
|
780 |
ri:= i |
|
781 |
else |
|
782 |
li:= i; |
|
783 |
end; |
|
3408 | 784 |
end; |
6123 | 785 |
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
|
786 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
787 |
if i = 7 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
788 |
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
|
789 |
|
3408 | 790 |
// prepare offset for next check (clockwise) |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
791 |
if (mx = -1) and (my <> -1) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
792 |
my:= my - 1 |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
793 |
else if (my = -1) and (mx <> 1) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
794 |
mx:= mx + 1 |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
795 |
else if (mx = 1) and (my <> 1) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
796 |
my:= my + 1 |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
797 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
798 |
mx:= mx - 1; |
3401
d5d31d16eccc
add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents:
3236
diff
changeset
|
799 |
|
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
|
800 |
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
|
801 |
|
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
|
802 |
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
|
803 |
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
|
804 |
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
|
805 |
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
|
806 |
|
3408 | 807 |
// edge-crawl |
808 |
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
|
809 |
begin |
3408 | 810 |
// using mx,my as temporary value buffer here |
3697 | 811 |
|
3408 | 812 |
jfr:= 8+li+1; |
813 |
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
|
814 |
|
6123 | 815 |
isColl:= false; |
3408 | 816 |
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
|
817 |
begin |
3408 | 818 |
tmpo:= j mod 8; |
6123 | 819 |
// multiplicator k tries to skip small pixels/gaps when possible |
820 |
for k:= 3 downto 1 do |
|
821 |
begin |
|
822 |
tmpx:= ldx + k * offset[tmpo,0]; |
|
823 |
tmpy:= ldy + k * offset[tmpo,1]; |
|
824 |
if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
825 |
and (Land[tmpy,tmpx] > TestWord) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
826 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
827 |
ldx:= tmpx; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
828 |
ldy:= tmpy; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
829 |
isColl:= true; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
830 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
831 |
end; |
6123 | 832 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
833 |
if isColl then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
834 |
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
|
835 |
end; |
3408 | 836 |
|
837 |
jfr:= 8+ri-1; |
|
838 |
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
|
839 |
|
6123 | 840 |
isColl:= false; |
3408 | 841 |
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
|
842 |
begin |
3408 | 843 |
tmpo:= j mod 8; |
6123 | 844 |
for k:= 3 downto 1 do |
845 |
begin |
|
846 |
tmpx:= rdx + k * offset[tmpo,0]; |
|
847 |
tmpy:= rdy + k * offset[tmpo,1]; |
|
848 |
if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
849 |
and (Land[tmpy,tmpx] > TestWord) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
850 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
851 |
rdx:= tmpx; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
852 |
rdy:= tmpy; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
853 |
isColl:= true; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
854 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
855 |
end; |
6123 | 856 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
857 |
if isColl then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
858 |
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
|
859 |
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
|
860 |
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
|
861 |
|
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
|
862 |
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
|
863 |
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
|
864 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
865 |
if ((ldx = 0) and (ldy = 0)) then |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
866 |
exit; |
3401
d5d31d16eccc
add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents:
3236
diff
changeset
|
867 |
|
3414
b2f3bb44777e
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents:
3411
diff
changeset
|
868 |
outDeltaX:= ldx; |
b2f3bb44777e
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents:
3411
diff
changeset
|
869 |
outDeltaY:= ldy; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
870 |
CalcSlopeTangent:= true; |
3401
d5d31d16eccc
add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents:
3236
diff
changeset
|
871 |
end; |
d5d31d16eccc
add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents:
3236
diff
changeset
|
872 |
|
7754 | 873 |
function CalcSlopeNearGear(Gear: PGear; dirX, dirY: LongInt): hwFloat; |
874 |
var dx, dy: hwFloat; |
|
875 |
collX, collY, i, y, x, gx, gy, sdx, sdy: LongInt; |
|
876 |
isColl, bSucc: Boolean; |
|
877 |
begin |
|
878 |
||
10015 | 879 |
if dirY <> 0 then |
7754 | 880 |
begin |
881 |
y:= hwRound(Gear^.Y) + Gear^.Radius * dirY; |
|
882 |
gx:= hwRound(Gear^.X); |
|
883 |
collX := gx; |
|
884 |
isColl:= false; |
|
885 |
||
886 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
887 |
begin |
|
888 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
|
889 |
i:= x + Gear^.Radius * 2 - 2; |
|
890 |
repeat |
|
891 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
892 |
if Land[y, x] <> 0 then |
|
7767 | 893 |
if (not isColl) or (abs(x-gx) < abs(collX-gx)) then |
7754 | 894 |
begin |
895 |
isColl:= true; |
|
896 |
collX := x; |
|
897 |
end; |
|
898 |
inc(x) |
|
899 |
until (x > i); |
|
900 |
end; |
|
901 |
end |
|
902 |
else |
|
903 |
begin |
|
904 |
x:= hwRound(Gear^.X) + Gear^.Radius * dirX; |
|
905 |
gy:= hwRound(Gear^.Y); |
|
906 |
collY := gy; |
|
907 |
isColl:= false; |
|
908 |
||
909 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
910 |
begin |
|
911 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
|
912 |
i:= y + Gear^.Radius * 2 - 2; |
|
913 |
repeat |
|
914 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
915 |
if Land[y, x] <> 0 then |
|
7767 | 916 |
if (not isColl) or (abs(y-gy) < abs(collY-gy)) then |
7754 | 917 |
begin |
918 |
isColl:= true; |
|
919 |
collY := y; |
|
920 |
end; |
|
921 |
inc(y) |
|
922 |
until (y > i); |
|
923 |
end; |
|
924 |
end; |
|
925 |
||
926 |
if isColl then |
|
927 |
begin |
|
928 |
// save original dx/dy |
|
929 |
dx := Gear^.dX; |
|
930 |
dy := Gear^.dY; |
|
931 |
||
932 |
if dirY <> 0 then |
|
933 |
begin |
|
934 |
Gear^.dX.QWordValue:= 0; |
|
935 |
Gear^.dX.isNegative:= (collX >= gx); |
|
936 |
Gear^.dY:= _1*dirY |
|
937 |
end |
|
938 |
else |
|
939 |
begin |
|
940 |
Gear^.dY.QWordValue:= 0; |
|
941 |
Gear^.dY.isNegative:= (collY >= gy); |
|
942 |
Gear^.dX:= _1*dirX |
|
943 |
end; |
|
944 |
||
945 |
sdx:= 0; |
|
946 |
sdy:= 0; |
|
947 |
if dirY <> 0 then |
|
948 |
bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 0) |
|
949 |
else bSucc := CalcSlopeTangent(Gear, x, collY, sdx, sdy, 0); |
|
950 |
||
951 |
// restore original dx/dy |
|
952 |
Gear^.dX := dx; |
|
953 |
Gear^.dY := dy; |
|
954 |
||
955 |
if bSucc and ((sdx <> 0) or (sdy <> 0)) then |
|
956 |
begin |
|
957 |
dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy)); |
|
958 |
dx.isNegative := (sdx * sdy) < 0; |
|
959 |
exit (dx); |
|
960 |
end |
|
961 |
end; |
|
962 |
||
963 |
CalcSlopeNearGear := _0; |
|
964 |
end; |
|
965 |
||
6279 | 966 |
function CalcSlopeBelowGear(Gear: PGear): hwFloat; |
6124 | 967 |
var dx, dy: hwFloat; |
6279 | 968 |
collX, i, y, x, gx, sdx, sdy: LongInt; |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
969 |
isColl, bSucc: Boolean; |
6124 | 970 |
begin |
971 |
||
972 |
||
973 |
y:= hwRound(Gear^.Y) + Gear^.Radius; |
|
974 |
gx:= hwRound(Gear^.X); |
|
975 |
collX := gx; |
|
976 |
isColl:= false; |
|
977 |
||
978 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
979 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
980 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
981 |
i:= x + Gear^.Radius * 2 - 2; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
982 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
983 |
if (x and LAND_WIDTH_MASK) = 0 then |
13470
7b4643ff60ea
Refactor collision mask checks, remove hardcoded numbers
Wuzzy <Wuzzy2@mail.ru>
parents:
13469
diff
changeset
|
984 |
if (Land[y, x] and lfNotObjMask) <> 0 then |
7767 | 985 |
if (not isColl) or (abs(x-gx) < abs(collX-gx)) then |
6124 | 986 |
begin |
987 |
isColl:= true; |
|
988 |
collX := x; |
|
989 |
end; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
990 |
inc(x) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
991 |
until (x > i); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
992 |
end; |
6124 | 993 |
|
994 |
if isColl then |
|
6279 | 995 |
begin |
996 |
// save original dx/dy |
|
997 |
dx := Gear^.dX; |
|
998 |
dy := Gear^.dY; |
|
999 |
||
1000 |
Gear^.dX.QWordValue:= 0; |
|
1001 |
Gear^.dX.isNegative:= (collX >= gx); |
|
1002 |
Gear^.dY:= _1; |
|
1003 |
||
1004 |
sdx:= 0; |
|
1005 |
sdy:= 0; |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
1006 |
bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 255); |
6124 | 1007 |
|
6279 | 1008 |
// restore original dx/dy |
1009 |
Gear^.dX := dx; |
|
1010 |
Gear^.dY := dy; |
|
6124 | 1011 |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
1012 |
if bSucc and (sdx <> 0) and (sdy <> 0) then |
6279 | 1013 |
begin |
1014 |
dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy)); |
|
1015 |
dx.isNegative := (sdx * sdy) < 0; |
|
1016 |
exit (dx); |
|
1017 |
end; |
|
1018 |
end; |
|
1019 |
||
1020 |
CalcSlopeBelowGear := _0; |
|
6124 | 1021 |
end; |
1022 |
||
3038 | 1023 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1024 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
1025 |
Count:= 0; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1026 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1027 |
|
3038 | 1028 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1029 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1030 |
|
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1031 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1032 |
|
4 | 1033 |
end. |