author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 07 Jul 2020 00:07:40 +0200 | |
changeset 15717 | eeab5b90c082 |
parent 15696 | f5b127ee3196 |
child 15744 | 498c1482dec2 |
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 |
||
15668 | 55 |
type TKickTest = record |
56 |
kick: Boolean; |
|
57 |
collisionMask: Word; |
|
58 |
end; |
|
59 |
||
3038 | 60 |
procedure initModule; |
61 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
62 |
|
9291
15f7bb217b66
Make add/delete consistent (this has bugged me for so long)
nemo
parents:
9247
diff
changeset
|
63 |
procedure AddCI(Gear: PGear); |
53 | 64 |
procedure DeleteCI(Gear: PGear); |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
65 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
66 |
function CheckGearsCollision(Gear: PGear): PGearArray; |
12898 | 67 |
function CheckAllGearsCollision(SourceGear: PGear): PGearArray; |
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
68 |
function CheckCacheCollision(SourceGear: PGear): PGearArray; |
12898 | 69 |
|
70 |
function CheckGearsLineCollision(Gear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
71 |
function CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
72 |
||
15677 | 73 |
function UpdateHitOrder(Gear: PGear; Order: LongInt): boolean; inline; |
15678 | 74 |
function UpdateHitOrder(Gear: PGear; Order: LongInt; Global: boolean): boolean; inline; |
15677 | 75 |
function UpdateGlobalHitOrder(Gear: PGear; Order: LongInt): boolean; inline; |
76 |
procedure ClearHitOrderLeq(MinOrder: LongInt); inline; |
|
77 |
procedure ClearGlobalHitOrderLeq(MinOrder: LongInt); inline; |
|
12898 | 78 |
procedure ClearHitOrder(); |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
79 |
|
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
80 |
procedure RefillProximityCache(SourceGear: PGear; radius: LongInt); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
81 |
procedure RemoveFromProximityCache(Gear: PGear); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
82 |
procedure ClearProximityCache(); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
83 |
|
15668 | 84 |
function TestCollisionXImpl(centerX, centerY, radius, direction: LongInt; collisionMask: Word): Word; |
85 |
function TestCollisionYImpl(centerX, centerY, radius, direction: LongInt; collisionMask: Word): Word; |
|
86 |
||
87 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): Word; inline; |
|
88 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; inline; |
|
89 |
||
90 |
function TestCollisionX(Gear: PGear; Dir: LongInt): Word; inline; |
|
91 |
function TestCollisionY(Gear: PGear; Dir: LongInt): Word; inline; |
|
92 |
||
93 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): Word; inline; |
|
94 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; inline; |
|
95 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): Word; inline; |
|
96 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; inline; |
|
97 |
||
98 |
function TestCollisionXKickImpl(centerX, centerY, radius, direction: LongInt; collisionMask, kickMask: Word): TKickTest; |
|
99 |
function TestCollisionYKickImpl(centerX, centerY, radius, direction: LongInt; collisionMask, kickMask: Word): TKickTest; |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
100 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
101 |
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
|
102 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
103 |
|
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
|
104 |
function TestRectangleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; |
6124 | 105 |
|
10354 | 106 |
function CheckCoordInWater(X, Y: LongInt): boolean; inline; |
107 |
||
9248 | 108 |
// returns: negative sign if going downhill to left, value is steepness (noslope/error = _0, 45 = _0_5) |
6279 | 109 |
function CalcSlopeBelowGear(Gear: PGear): hwFloat; |
7754 | 110 |
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
|
111 |
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
|
112 |
|
15322 | 113 |
function CheckGearsUnderSprite(Sprite: TSprite; sprX, sprY, Frame: LongInt): boolean; |
114 |
||
4 | 115 |
implementation |
15322 | 116 |
uses uConsts, uLandGraphics, uVariables, SDLh, uLandTexture, uDebug; |
4 | 117 |
|
53 | 118 |
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
|
119 |
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
|
120 |
cGear: PGear; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
121 |
end; |
351 | 122 |
|
5568 | 123 |
const MAXRECTSINDEX = 1023; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
124 |
var Count: Longword; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
125 |
cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
126 |
ga: TGearArray; |
12898 | 127 |
ordera: TGearHitOrder; |
15677 | 128 |
globalordera: TGearHitOrder; |
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
129 |
proximitya: TGearProximityCache; |
4 | 130 |
|
9291
15f7bb217b66
Make add/delete consistent (this has bugged me for so long)
nemo
parents:
9247
diff
changeset
|
131 |
procedure AddCI(Gear: PGear); |
53 | 132 |
begin |
11532 | 133 |
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
|
134 |
((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
|
135 |
exit; |
11532 | 136 |
|
53 | 137 |
with cinfos[Count] do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
138 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
139 |
X:= hwRound(Gear^.X); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
140 |
Y:= hwRound(Gear^.Y); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
cGear:= Gear |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
144 |
end; |
511 | 145 |
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
|
146 |
inc(Count); |
4 | 147 |
end; |
148 |
||
53 | 149 |
procedure DeleteCI(Gear: PGear); |
4 | 150 |
begin |
511 | 151 |
if Gear^.CollisionIndex >= 0 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
152 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
156 |
cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
157 |
Gear^.CollisionIndex:= -1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
158 |
dec(Count) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
159 |
end; |
4 | 160 |
end; |
161 |
||
10354 | 162 |
function CheckCoordInWater(X, Y: LongInt): boolean; inline; |
163 |
begin |
|
164 |
CheckCoordInWater:= (Y > cWaterLine) |
|
14303
6015b74eea55
overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents:
14027
diff
changeset
|
165 |
or ((WorldEdge = weSea) and ((X < leftX) or (X > rightX))); |
10354 | 166 |
end; |
167 |
||
53 | 168 |
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
|
169 |
var mx, my, tr: LongInt; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
170 |
i: Longword; |
4 | 171 |
begin |
1506 | 172 |
CheckGearsCollision:= @ga; |
53 | 173 |
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
|
174 |
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
|
175 |
exit; |
351 | 176 |
mx:= hwRound(Gear^.X); |
177 |
my:= hwRound(Gear^.Y); |
|
4 | 178 |
|
4705
593ef1ad3cd3
ok. restore old [r + 1 + r] for gear width for a moment, and reset snowballs.
nemo
parents:
4684
diff
changeset
|
179 |
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
|
180 |
|
3608
c509bbc779e7
Revert prior attempted optimisation. Gridding the land pays in some situations, but not all. Restricting to an upper bound might help, but overall, seems too fuzzy to be worth it. On one side is increased cost of Add/Delete + extra test on collision check, on the other is skipping the list iteration. Perhaps for large lists.
nemo
parents:
3603
diff
changeset
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
(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
|
185 |
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
|
186 |
ga.ar[ga.Count]:= cinfos[i].cGear; |
12898 | 187 |
ga.cX[ga.Count]:= hwround(Gear^.X); |
188 |
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
|
189 |
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
|
190 |
end |
4 | 191 |
end; |
192 |
||
12898 | 193 |
function CheckAllGearsCollision(SourceGear: PGear): PGearArray; |
194 |
var mx, my, tr: LongInt; |
|
195 |
Gear: PGear; |
|
196 |
begin |
|
197 |
CheckAllGearsCollision:= @ga; |
|
198 |
ga.Count:= 0; |
|
199 |
||
200 |
mx:= hwRound(SourceGear^.X); |
|
201 |
my:= hwRound(SourceGear^.Y); |
|
202 |
||
203 |
tr:= SourceGear^.Radius + 2; |
|
204 |
||
205 |
Gear:= GearsList; |
|
206 |
||
207 |
while Gear <> nil do |
|
208 |
begin |
|
209 |
if (Gear <> SourceGear) and |
|
210 |
(sqr(mx - hwRound(Gear^.x)) + sqr(my - hwRound(Gear^.y)) <= sqr(Gear^.Radius + tr))then |
|
211 |
begin |
|
212 |
ga.ar[ga.Count]:= Gear; |
|
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
213 |
ga.cX[ga.Count]:= mx; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
214 |
ga.cY[ga.Count]:= my; |
12898 | 215 |
inc(ga.Count) |
216 |
end; |
|
217 |
||
218 |
Gear := Gear^.NextGear |
|
219 |
end; |
|
220 |
end; |
|
221 |
||
222 |
function LineCollisionTest(oX, oY, dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
223 |
width: LongInt; Gear: PGear): |
|
224 |
TLineCollision; inline; |
|
225 |
var toCenterX, toCenterY, r, |
|
226 |
b, bSqr, c, desc, t: hwFloat; |
|
227 |
realT: extended; |
|
228 |
begin |
|
229 |
LineCollisionTest.hasCollision:= false; |
|
230 |
toCenterX:= (oX - Gear^.X); |
|
231 |
toCenterY:= (oY - Gear^.Y); |
|
232 |
r:= int2hwFloat(Gear^.Radius + width + 2); |
|
233 |
// Early cull to avoid multiplying large numbers |
|
234 |
if hwAbs(toCenterX) + hwAbs(toCenterY) > dirNormBound + r then |
|
235 |
exit; |
|
236 |
b:= dirX * toCenterX + dirY * toCenterY; |
|
237 |
c:= hwSqr(toCenterX) + hwSqr(toCenterY) - hwSqr(r); |
|
238 |
if (b > _0) and (c > _0) then |
|
239 |
exit; |
|
240 |
bSqr:= hwSqr(b); |
|
241 |
desc:= bSqr - dirNormSqr * c; |
|
242 |
if desc.isNegative then exit; |
|
243 |
||
244 |
t:= -b - hwSqrt(desc); |
|
245 |
if t.isNegative then t:= _0; |
|
246 |
if t < dirNormSqr then |
|
247 |
with LineCollisionTest do |
|
248 |
begin |
|
249 |
hasCollision:= true; |
|
250 |
realT := hwFloat2Float(t) / hwFloat2Float(dirNormSqr); |
|
251 |
cX:= round(hwFloat2Float(oX) + realT * hwFloat2Float(dirX)); |
|
252 |
cY:= round(hwFloat2Float(oY) + realT * hwFloat2Float(dirY)); |
|
253 |
end; |
|
254 |
end; |
|
255 |
||
256 |
function CheckGearsLineCollision(Gear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
257 |
var dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
258 |
test: TLineCollision; |
|
259 |
i: Longword; |
|
260 |
begin |
|
261 |
CheckGearsLineCollision:= @ga; |
|
262 |
ga.Count:= 0; |
|
263 |
if Count = 0 then |
|
264 |
exit; |
|
265 |
dirX:= (tX - oX); |
|
266 |
dirY:= (tY - oY); |
|
267 |
dirNormBound:= _1_5 * (hwAbs(dirX) + hwAbs(dirY)); |
|
268 |
dirNormSqr:= hwSqr(dirX) + hwSqr(dirY); |
|
269 |
if dirNormSqr.isNegative then |
|
270 |
exit; |
|
271 |
||
272 |
for i:= 0 to Pred(Count) do |
|
273 |
with cinfos[i] do if Gear <> cGear then |
|
274 |
begin |
|
275 |
test:= LineCollisionTest( |
|
276 |
oX, oY, dirX, dirY, dirNormSqr, dirNormBound, Gear^.Radius, cGear); |
|
277 |
if test.hasCollision then |
|
278 |
begin |
|
279 |
ga.ar[ga.Count] := cGear; |
|
280 |
ga.cX[ga.Count] := test.cX; |
|
281 |
ga.cY[ga.Count] := test.cY; |
|
282 |
inc(ga.Count) |
|
283 |
end |
|
284 |
end |
|
285 |
end; |
|
286 |
||
287 |
function CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
288 |
var dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
289 |
test: TLineCollision; |
|
290 |
Gear: PGear; |
|
291 |
begin |
|
292 |
CheckAllGearsLineCollision:= @ga; |
|
293 |
ga.Count:= 0; |
|
294 |
dirX:= (tX - oX); |
|
295 |
dirY:= (tY - oY); |
|
296 |
dirNormBound:= _1_5 * (hwAbs(dirX) + hwAbs(dirY)); |
|
297 |
dirNormSqr:= hwSqr(dirX) + hwSqr(dirY); |
|
298 |
if dirNormSqr.isNegative then |
|
299 |
exit; |
|
300 |
||
301 |
Gear:= GearsList; |
|
302 |
while Gear <> nil do |
|
303 |
begin |
|
304 |
if SourceGear <> Gear then |
|
305 |
begin |
|
306 |
test:= LineCollisionTest( |
|
307 |
oX, oY, dirX, dirY, dirNormSqr, dirNormBound, SourceGear^.Radius, Gear); |
|
308 |
if test.hasCollision then |
|
309 |
begin |
|
310 |
ga.ar[ga.Count] := Gear; |
|
311 |
ga.cX[ga.Count] := test.cX; |
|
312 |
ga.cY[ga.Count] := test.cY; |
|
313 |
inc(ga.Count) |
|
314 |
end |
|
315 |
end; |
|
316 |
Gear := Gear^.NextGear |
|
317 |
end; |
|
318 |
end; |
|
319 |
||
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
320 |
function CheckCacheCollision(SourceGear: PGear): PGearArray; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
321 |
var mx, my, tr, i: LongInt; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
322 |
Gear: PGear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
323 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
324 |
CheckCacheCollision:= @ga; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
325 |
ga.Count:= 0; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
326 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
327 |
mx:= hwRound(SourceGear^.X); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
328 |
my:= hwRound(SourceGear^.Y); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
329 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
330 |
tr:= SourceGear^.Radius + 2; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
331 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
332 |
for i:= 0 to proximitya.Count - 1 do |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
333 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
334 |
Gear:= proximitya.ar[i]; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
335 |
// 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
|
336 |
// 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
|
337 |
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
|
338 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
339 |
ga.ar[ga.Count]:= Gear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
340 |
ga.cX[ga.Count]:= mx; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
341 |
ga.cY[ga.Count]:= my; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
342 |
inc(ga.Count) |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
343 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
344 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
345 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
346 |
|
15677 | 347 |
function UpdateHitOrderImpl(HitOrder: PGearHitOrder; Gear: PGear; Order: LongInt): boolean; |
12898 | 348 |
var i: LongInt; |
349 |
begin |
|
15677 | 350 |
UpdateHitOrderImpl:= true; |
351 |
for i := 0 to HitOrder^.Count - 1 do |
|
352 |
if HitOrder^.ar[i] = Gear then |
|
12898 | 353 |
begin |
15677 | 354 |
if Order <= HitOrder^.order[i] then |
355 |
UpdateHitOrderImpl := false; |
|
356 |
HitOrder^.order[i] := Max(HitOrder^.order[i], Order); |
|
357 |
exit; |
|
12898 | 358 |
end; |
359 |
||
15677 | 360 |
if HitOrder^.Count > cMaxGearHitOrderInd then |
361 |
UpdateHitOrderImpl := false |
|
362 |
else |
|
12898 | 363 |
begin |
15677 | 364 |
HitOrder^.ar[HitOrder^.Count] := Gear; |
365 |
HitOrder^.order[HitOrder^.Count] := Order; |
|
366 |
Inc(HitOrder^.Count); |
|
12898 | 367 |
end |
368 |
end; |
|
369 |
||
15677 | 370 |
function UpdateHitOrder(Gear: PGear; Order: LongInt): boolean; inline; |
371 |
begin |
|
372 |
UpdateHitOrder := UpdateHitOrderImpl(@ordera, Gear, Order); |
|
373 |
end; |
|
374 |
||
15678 | 375 |
function UpdateHitOrder(Gear: PGear; Order: LongInt; Global: boolean): boolean; inline; |
376 |
begin |
|
377 |
if Global then |
|
15696 | 378 |
UpdateHitOrder := UpdateHitOrderImpl(@globalordera, Gear, Order) |
15678 | 379 |
else |
15696 | 380 |
UpdateHitOrder := UpdateHitOrderImpl(@ordera, Gear, Order) |
15678 | 381 |
end; |
382 |
||
15677 | 383 |
function UpdateGlobalHitOrder(Gear: PGear; Order: LongInt): boolean; inline; |
384 |
begin |
|
385 |
UpdateGlobalHitOrder := UpdateHitOrderImpl(@globalordera, Gear, Order); |
|
386 |
end; |
|
387 |
||
388 |
procedure ClearHitOrderLeqImpl(HitOrder: PGearHitOrder; MinOrder: LongInt); |
|
12898 | 389 |
var i, freeIndex: LongInt; |
390 |
begin; |
|
15677 | 391 |
freeIndex:= 0; |
392 |
i:= 0; |
|
12898 | 393 |
|
15678 | 394 |
while i < HitOrder^.Count do |
12898 | 395 |
begin |
15677 | 396 |
if HitOrder^.order[i] <= MinOrder then |
397 |
Dec(HitOrder^.Count) |
|
12898 | 398 |
else |
15677 | 399 |
begin |
400 |
if freeIndex < i then |
|
12898 | 401 |
begin |
15677 | 402 |
HitOrder^.ar[freeIndex]:= HitOrder^.ar[i]; |
403 |
HitOrder^.order[freeIndex]:= HitOrder^.order[i]; |
|
404 |
end; |
|
12898 | 405 |
Inc(freeIndex); |
15677 | 406 |
end; |
12898 | 407 |
Inc(i) |
408 |
end |
|
409 |
end; |
|
410 |
||
15677 | 411 |
procedure ClearHitOrderLeq(MinOrder: LongInt); inline; |
412 |
begin |
|
413 |
ClearHitOrderLeqImpl(@ordera, MinOrder); |
|
414 |
end; |
|
415 |
||
416 |
procedure ClearGlobalHitOrderLeq(MinOrder: LongInt); inline; |
|
417 |
begin |
|
418 |
ClearHitOrderLeqImpl(@globalordera, MinOrder); |
|
419 |
end; |
|
420 |
||
12898 | 421 |
procedure ClearHitOrder(); |
422 |
begin |
|
423 |
ordera.Count:= 0; |
|
424 |
end; |
|
425 |
||
14027
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
426 |
procedure RefillProximityCache(SourceGear: PGear; radius: LongInt); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
427 |
var cx, cy, dx, dy, r: LongInt; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
428 |
Gear: PGear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
429 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
430 |
proximitya.Count:= 0; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
431 |
cx:= hwRound(SourceGear^.X); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
432 |
cy:= hwRound(SourceGear^.Y); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
433 |
Gear:= GearsList; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
434 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
435 |
while (Gear <> nil) and (proximitya.Count <= cMaxGearProximityCacheInd) do |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
436 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
437 |
dx:= abs(hwRound(Gear^.X) - cx); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
438 |
dy:= abs(hwRound(Gear^.Y) - cy); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
439 |
r:= radius + Gear^.radius + 2; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
440 |
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
|
441 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
442 |
proximitya.ar[proximitya.Count]:= Gear; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
443 |
inc(proximitya.Count) |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
444 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
445 |
Gear := Gear^.NextGear |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
446 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
447 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
448 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
449 |
procedure RemoveFromProximityCache(Gear: PGear); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
450 |
var i: LongInt; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
451 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
452 |
i := 0; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
453 |
while i < proximitya.Count do |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
454 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
455 |
if proximitya.ar[i] = Gear then |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
456 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
457 |
proximitya.ar[i]:= proximitya.ar[proximitya.Count - 1]; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
458 |
dec(proximitya.Count); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
459 |
end |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
460 |
else |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
461 |
inc(i); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
462 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
463 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
464 |
|
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
465 |
procedure ClearProximityCache(); |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
466 |
begin |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
467 |
proximitya.Count:= 0; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
468 |
end; |
105793e575d6
make firepunch hit moving gears (airmines are not amused)
alfadur
parents:
13470
diff
changeset
|
469 |
|
15668 | 470 |
function TestCollisionXImpl(centerX, centerY, radius, direction: LongInt; collisionMask: Word): Word; |
471 |
var x, y, minY, maxY: LongInt; |
|
4 | 472 |
begin |
15668 | 473 |
if direction < 0 then |
474 |
x := centerX - radius |
|
475 |
else |
|
476 |
x := centerX + radius; |
|
838 | 477 |
|
15668 | 478 |
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
|
479 |
begin |
15668 | 480 |
minY := max(centerY - radius + 1, 0); |
481 |
maxY := min(centerY + radius - 1, LAND_HEIGHT - 1); |
|
482 |
for y := minY to maxY do |
|
483 |
if Land[y, x] and collisionMask <> 0 then |
|
484 |
exit(Land[y, x] and collisionMask); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
485 |
end; |
15668 | 486 |
TestCollisionXImpl := 0; |
4 | 487 |
end; |
488 |
||
15668 | 489 |
function TestCollisionYImpl(centerX, centerY, radius, direction: LongInt; collisionMask: Word): Word; |
490 |
var x, y, minX, maxX: LongInt; |
|
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
491 |
begin |
15668 | 492 |
if direction < 0 then |
493 |
y := centerY - radius |
|
494 |
else |
|
495 |
y := centerY + radius; |
|
7268 | 496 |
|
15668 | 497 |
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
|
498 |
begin |
15668 | 499 |
minX := max(centerX - radius + 1, 0); |
500 |
maxX := min(centerX + radius - 1, LAND_WIDTH - 1); |
|
501 |
for x := minX to maxX do |
|
502 |
if Land[y, x] and collisionMask <> 0 then |
|
503 |
exit(Land[y, x] and collisionMask); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
504 |
end; |
15668 | 505 |
TestCollisionYImpl := 0; |
506 |
end; |
|
507 |
||
508 |
function TestCollisionX(Gear: PGear; Dir: LongInt): Word; inline; |
|
509 |
begin |
|
510 |
TestCollisionX := TestCollisionXImpl(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, Dir, Gear^.CollisionMask and lfLandMask); |
|
511 |
end; |
|
512 |
||
513 |
function TestCollisionY(Gear: PGear; Dir: LongInt): Word; inline; |
|
514 |
begin |
|
515 |
TestCollisionY := TestCollisionYImpl(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, Dir, Gear^.CollisionMask and lfLandMask); |
|
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
516 |
end; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
517 |
|
15668 | 518 |
procedure LegacyFixupX(Gear: PGear); |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
519 |
begin |
15668 | 520 |
// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap |
521 |
if (Gear^.CollisionMask = lfNotCurHogCrate) and (Gear^.Kind <> gtHedgehog) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and |
|
522 |
((hwRound(Gear^.Hedgehog^.Gear^.X) + Gear^.Hedgehog^.Gear^.Radius + 16 < hwRound(Gear^.X) - Gear^.Radius) or |
|
523 |
(hwRound(Gear^.Hedgehog^.Gear^.X) - Gear^.Hedgehog^.Gear^.Radius - 16 > hwRound(Gear^.X) + Gear^.Radius)) then |
|
524 |
Gear^.CollisionMask:= lfAll; |
|
525 |
end; |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
526 |
|
15668 | 527 |
procedure LegacyFixupY(Gear: PGear); |
528 |
begin |
|
529 |
// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap |
|
530 |
if (Gear^.CollisionMask = lfNotCurHogCrate) and (Gear^.Kind <> gtHedgehog) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and |
|
531 |
((hwRound(Gear^.Hedgehog^.Gear^.Y) + Gear^.Hedgehog^.Gear^.Radius + 16 < hwRound(Gear^.Y) - Gear^.Radius) or |
|
532 |
(hwRound(Gear^.Hedgehog^.Gear^.Y) - Gear^.Hedgehog^.Gear^.Radius - 16 > hwRound(Gear^.Y) + Gear^.Radius)) then |
|
533 |
Gear^.CollisionMask:= lfAll; |
|
534 |
end; |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
535 |
|
15668 | 536 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): Word; inline; |
537 |
begin |
|
538 |
LegacyFixupX(Gear); |
|
539 |
TestCollisionXwithGear:= TestCollisionXImpl(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, Dir, Gear^.CollisionMask); |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
540 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
541 |
|
15668 | 542 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; inline; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
543 |
begin |
15668 | 544 |
LegacyFixupY(Gear); |
545 |
TestCollisionYwithGear:= TestCollisionYImpl(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, Dir, Gear^.CollisionMask); |
|
546 |
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
|
547 |
|
15668 | 548 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; inline; |
549 |
var collisionMask: Word; |
|
550 |
begin |
|
551 |
if withGear then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
552 |
begin |
15668 | 553 |
LegacyFixupX(Gear); |
554 |
collisionMask:= Gear^.CollisionMask; |
|
555 |
end |
|
556 |
else |
|
557 |
collisionMask:= Gear^.CollisionMask and lfLandMask; |
|
967 | 558 |
|
15668 | 559 |
TestCollisionXwithXYShift := TestCollisionXImpl(hwRound(Gear^.X + ShiftX), hwRound(Gear^.Y) + ShiftY, Gear^.Radius, Dir, collisionMask) |
560 |
end; |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
561 |
|
15668 | 562 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; inline; |
563 |
var collisionMask: Word; |
|
564 |
begin |
|
565 |
if withGear then |
|
566 |
begin |
|
567 |
LegacyFixupY(Gear); |
|
568 |
collisionMask:= Gear^.CollisionMask; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
569 |
end |
15668 | 570 |
else |
571 |
collisionMask:= Gear^.CollisionMask and lfLandMask; |
|
572 |
||
573 |
TestCollisionYwithXYShift := TestCollisionYImpl(hwRound(Gear^.X) + ShiftX, hwRound(Gear^.Y) + ShiftY, Gear^.Radius, Dir, collisionMask) |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
574 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
575 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
576 |
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
|
577 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
578 |
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
|
579 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
580 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
581 |
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
|
582 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
583 |
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
|
584 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
585 |
|
15668 | 586 |
function TestCollisionXKickImpl(centerX, centerY, radius, direction: LongInt; collisionMask, kickMask: Word): TKickTest; |
587 |
var x, y, minY, maxY: LongInt; |
|
588 |
begin |
|
589 |
TestCollisionXKickImpl.kick := false; |
|
590 |
TestCollisionXKickImpl.collisionMask := 0; |
|
591 |
||
592 |
if direction < 0 then |
|
593 |
x := centerX - radius |
|
594 |
else |
|
595 |
x := centerX + radius; |
|
596 |
||
597 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
598 |
begin |
|
599 |
minY := max(centerY - radius + 1, 0); |
|
600 |
maxY := min(centerY + radius - 1, LAND_HEIGHT - 1); |
|
601 |
for y := minY to maxY do |
|
602 |
if Land[y, x] and collisionMask <> 0 then |
|
603 |
begin |
|
604 |
TestCollisionXKickImpl.kick := false; |
|
605 |
TestCollisionXKickImpl.collisionMask := Land[y, x] and collisionMask; |
|
606 |
exit |
|
607 |
end |
|
608 |
else if Land[y, x] and kickMask <> 0 then |
|
609 |
begin |
|
610 |
TestCollisionXKickImpl.kick := true; |
|
611 |
TestCollisionXKickImpl.collisionMask := Land[y, x] and kickMask; |
|
612 |
end; |
|
613 |
end; |
|
614 |
end; |
|
615 |
||
616 |
function TestCollisionYKickImpl(centerX, centerY, radius, direction: LongInt; collisionMask, kickMask: Word): TKickTest; |
|
617 |
var x, y, minX, maxX: LongInt; |
|
4 | 618 |
begin |
15668 | 619 |
TestCollisionYKickImpl.kick := false; |
620 |
TestCollisionYKickImpl.collisionMask := 0; |
|
621 |
||
622 |
if direction < 0 then |
|
623 |
y := centerY - radius |
|
624 |
else |
|
625 |
y := centerY + radius; |
|
626 |
||
627 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
628 |
begin |
|
629 |
minX := max(centerX - radius + 1, 0); |
|
630 |
maxX := min(centerX + radius - 1, LAND_WIDTH - 1); |
|
631 |
for x := minX to maxX do |
|
632 |
if Land[y, x] and collisionMask <> 0 then |
|
633 |
begin |
|
634 |
TestCollisionYKickImpl.kick := false; |
|
635 |
TestCollisionYKickImpl.collisionMask := Land[y, x] and collisionMask; |
|
636 |
exit |
|
637 |
end |
|
638 |
else if Land[y, x] and kickMask <> 0 then |
|
639 |
begin |
|
640 |
TestCollisionYKickImpl.kick := true; |
|
641 |
TestCollisionYKickImpl.collisionMask := Land[y, x] and kickMask; |
|
642 |
end; |
|
643 |
end; |
|
644 |
end; |
|
645 |
||
646 |
function TestCollisionXKick(Gear: PGear; Dir: LongInt): Word; |
|
647 |
var centerX, centerY, i: LongInt; |
|
648 |
test: TKickTest; |
|
649 |
info: TCollisionEntry; |
|
650 |
begin |
|
651 |
test := TestCollisionXKickImpl( |
|
652 |
hwRound(Gear^.X), hwRound(Gear^.Y), |
|
653 |
Gear^.Radius, Dir, |
|
654 |
Gear^.CollisionMask and lfLandMask, Gear^.CollisionMask); |
|
655 |
||
656 |
TestCollisionXKick := test.collisionMask; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
657 |
|
15668 | 658 |
if test.kick then |
659 |
begin |
|
660 |
if hwAbs(Gear^.dX) < cHHKick then |
|
661 |
exit; |
|
662 |
if ((Gear^.State and gstHHJumping) <> 0) and (hwAbs(Gear^.dX) < _0_4) then |
|
663 |
exit; |
|
664 |
||
665 |
centerX := hwRound(Gear^.X); |
|
666 |
centerY := hwRound(Gear^.Y); |
|
667 |
||
668 |
for i:= 0 to Pred(Count) do |
|
669 |
begin |
|
670 |
info:= cinfos[i]; |
|
671 |
if (Gear <> info.cGear) |
|
672 |
and ((centerX > info.X) xor (Dir > 0)) |
|
673 |
and ((info.cGear^.State and gstNotKickable) = 0) |
|
674 |
and ((info.cGear^.Kind in [gtHedgehog, gtMine, gtKnife]) |
|
675 |
or (info.cGear^.Kind = gtExplosives) and ((info.cGear^.State and gsttmpflag) <> 0)) // only apply X kick if the barrel is knocked over |
|
676 |
and (sqr(centerX - info.X) + sqr(centerY - info.Y) <= sqr(info.Radius + Gear^.Radius + 2)) then |
|
677 |
begin |
|
678 |
with info.cGear^ do |
|
679 |
begin |
|
680 |
dX := Gear^.dX; |
|
681 |
dY := Gear^.dY * _0_5; |
|
682 |
State := State or gstMoving; |
|
683 |
if Kind = gtKnife then State := State and (not gstCollision); |
|
684 |
Active:= true |
|
685 |
end; |
|
686 |
DeleteCI(info.cGear); |
|
687 |
exit(0) |
|
688 |
end |
|
689 |
end |
|
690 |
end |
|
691 |
end; |
|
10015 | 692 |
|
15668 | 693 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): Word; |
694 |
var centerX, centerY, i: LongInt; |
|
695 |
test: TKickTest; |
|
696 |
info: TCollisionEntry; |
|
697 |
begin |
|
698 |
test := TestCollisionYKickImpl( |
|
699 |
hwRound(Gear^.X), hwRound(Gear^.Y), |
|
700 |
Gear^.Radius, Dir, |
|
701 |
Gear^.CollisionMask and lfLandMask, Gear^.CollisionMask); |
|
702 |
||
703 |
TestCollisionYKick := test.collisionMask; |
|
704 |
||
705 |
if test.kick then |
|
706 |
begin |
|
707 |
if hwAbs(Gear^.dY) < cHHKick then |
|
708 |
exit; |
|
709 |
if ((Gear^.State and gstHHJumping) <> 0) and (not Gear^.dY.isNegative) and (Gear^.dY < _0_4) then |
|
710 |
exit; |
|
711 |
||
712 |
centerX := hwRound(Gear^.X); |
|
713 |
centerY := hwRound(Gear^.Y); |
|
714 |
||
715 |
for i := 0 to Pred(Count) do |
|
716 |
begin |
|
717 |
info := cinfos[i]; |
|
718 |
if (Gear <> info.cGear) |
|
719 |
and ((centerY + Gear^.Radius > info.Y) xor (Dir > 0)) |
|
720 |
and (info.cGear^.State and gstNotKickable = 0) |
|
721 |
and (info.cGear^.Kind in [gtHedgehog, gtMine, gtKnife, gtExplosives]) |
|
722 |
and (sqr(centerX - info.X) + sqr(centerY - info.Y) <= sqr(info.Radius + Gear^.Radius + 2)) then |
|
723 |
begin |
|
724 |
with info.cGear^ do |
|
725 |
begin |
|
726 |
if (Kind <> gtExplosives) or ((State and gsttmpflag) <> 0) then |
|
727 |
dX := Gear^.dX * _0_5; |
|
728 |
dY := Gear^.dY; |
|
729 |
State := State or gstMoving; |
|
730 |
if Kind = gtKnife then State:= State and (not gstCollision); |
|
731 |
Active := true |
|
732 |
end; |
|
733 |
DeleteCI(info.cGear); |
|
734 |
exit(0) |
|
735 |
end |
|
736 |
end |
|
737 |
end |
|
4 | 738 |
end; |
739 |
||
10818
f642a28cab0c
Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents:
10635
diff
changeset
|
740 |
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
|
741 |
var x, y: LongInt; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
742 |
TestWord: LongWord; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
743 |
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
|
744 |
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
|
745 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
746 |
if landOnly then |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
747 |
TestWord:= 255 |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
748 |
else |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
749 |
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
|
750 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
751 |
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
|
752 |
begin |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
753 |
x := x1; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
754 |
x1 := x2; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
755 |
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
|
756 |
end; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
757 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
758 |
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
|
759 |
begin |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
760 |
y := y1; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
761 |
y1 := y2; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
762 |
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
|
763 |
end; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
764 |
|
5919
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
765 |
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
|
766 |
exit; |
5919
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
767 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
768 |
for y := y1 to y2 do |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
769 |
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
|
770 |
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
|
771 |
exit; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
772 |
|
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
|
773 |
TestRectangleForObstacle:= false |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
774 |
end; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
775 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
776 |
function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; |
3408 | 777 |
var ldx, ldy, rdx, rdy: LongInt; |
6123 | 778 |
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
|
779 |
tmpx, tmpy: LongWord; |
3569 | 780 |
dx, dy, s: hwFloat; |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
781 |
offset: array[0..7,0..1] of ShortInt; |
6123 | 782 |
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
|
783 |
|
d5d31d16eccc
add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents:
3236
diff
changeset
|
784 |
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
|
785 |
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
|
786 |
|
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
|
787 |
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
|
788 |
dy:= Gear^.dY; |
3408 | 789 |
|
3569 | 790 |
// we start searching from the direction the gear came from |
791 |
if (dx.QWordValue > _0_995.QWordValue ) |
|
792 |
or (dy.QWordValue > _0_995.QWordValue ) then |
|
793 |
begin // scale |
|
6279 | 794 |
s := _0_995 / Distance(dx,dy); |
3569 | 795 |
dx := s * dx; |
796 |
dy := s * dy; |
|
797 |
end; |
|
798 |
||
3408 | 799 |
mx:= hwRound(Gear^.X-dx) - hwRound(Gear^.X); |
800 |
my:= hwRound(Gear^.Y-dy) - hwRound(Gear^.Y); |
|
801 |
||
802 |
li:= -1; |
|
803 |
ri:= -1; |
|
3569 | 804 |
|
3408 | 805 |
// go around collision pixel, checking for first/last collisions |
806 |
// this will determinate what angles will be tried to crawl along |
|
807 |
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
|
808 |
begin |
3408 | 809 |
offset[i,0]:= mx; |
810 |
offset[i,1]:= my; |
|
3569 | 811 |
|
6123 | 812 |
// multiplicator k tries to skip small pixels/gaps when possible |
813 |
for k:= 4 downto 1 do |
|
814 |
begin |
|
815 |
tmpx:= collisionX + k * mx; |
|
816 |
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
|
817 |
|
6123 | 818 |
if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) then |
819 |
if (Land[tmpy,tmpx] > TestWord) then |
|
3408 | 820 |
begin |
6123 | 821 |
// remember the index belonging to the first and last collision (if in 1st half) |
822 |
if (i <> 0) then |
|
823 |
begin |
|
824 |
if (ri = -1) then |
|
825 |
ri:= i |
|
826 |
else |
|
827 |
li:= i; |
|
828 |
end; |
|
3408 | 829 |
end; |
6123 | 830 |
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
|
831 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
832 |
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
|
833 |
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
|
834 |
|
3408 | 835 |
// 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
|
836 |
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
|
837 |
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
|
838 |
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
|
839 |
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
|
840 |
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
|
841 |
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
|
842 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
843 |
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
|
844 |
|
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
|
845 |
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
|
846 |
|
d5d31d16eccc
add a part of my landslide vector collision and use if for the portal gun DirAngle, not flawless yet
sheepluva
parents:
3236
diff
changeset
|
847 |
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
|
848 |
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
|
849 |
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
|
850 |
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
|
851 |
|
3408 | 852 |
// edge-crawl |
853 |
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
|
854 |
begin |
3408 | 855 |
// using mx,my as temporary value buffer here |
3697 | 856 |
|
3408 | 857 |
jfr:= 8+li+1; |
858 |
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
|
859 |
|
6123 | 860 |
isColl:= false; |
3408 | 861 |
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
|
862 |
begin |
3408 | 863 |
tmpo:= j mod 8; |
6123 | 864 |
// multiplicator k tries to skip small pixels/gaps when possible |
865 |
for k:= 3 downto 1 do |
|
866 |
begin |
|
867 |
tmpx:= ldx + k * offset[tmpo,0]; |
|
868 |
tmpy:= ldy + k * offset[tmpo,1]; |
|
869 |
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
|
870 |
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
|
871 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
872 |
ldx:= tmpx; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
873 |
ldy:= tmpy; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
874 |
isColl:= true; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
875 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
876 |
end; |
6123 | 877 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
878 |
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
|
879 |
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
|
880 |
end; |
3408 | 881 |
|
882 |
jfr:= 8+ri-1; |
|
883 |
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
|
884 |
|
6123 | 885 |
isColl:= false; |
3408 | 886 |
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
|
887 |
begin |
3408 | 888 |
tmpo:= j mod 8; |
6123 | 889 |
for k:= 3 downto 1 do |
890 |
begin |
|
891 |
tmpx:= rdx + k * offset[tmpo,0]; |
|
892 |
tmpy:= rdy + k * offset[tmpo,1]; |
|
893 |
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
|
894 |
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
|
895 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
896 |
rdx:= tmpx; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
897 |
rdy:= tmpy; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
898 |
isColl:= true; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
899 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
900 |
end; |
6123 | 901 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
902 |
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
|
903 |
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
|
904 |
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
|
905 |
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
|
906 |
|
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
|
907 |
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
|
908 |
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
|
909 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
910 |
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
|
911 |
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
|
912 |
|
3414
b2f3bb44777e
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents:
3411
diff
changeset
|
913 |
outDeltaX:= ldx; |
b2f3bb44777e
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents:
3411
diff
changeset
|
914 |
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
|
915 |
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
|
916 |
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
|
917 |
|
7754 | 918 |
function CalcSlopeNearGear(Gear: PGear; dirX, dirY: LongInt): hwFloat; |
919 |
var dx, dy: hwFloat; |
|
920 |
collX, collY, i, y, x, gx, gy, sdx, sdy: LongInt; |
|
921 |
isColl, bSucc: Boolean; |
|
922 |
begin |
|
923 |
||
10015 | 924 |
if dirY <> 0 then |
7754 | 925 |
begin |
926 |
y:= hwRound(Gear^.Y) + Gear^.Radius * dirY; |
|
927 |
gx:= hwRound(Gear^.X); |
|
928 |
collX := gx; |
|
929 |
isColl:= false; |
|
930 |
||
931 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
932 |
begin |
|
933 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
|
934 |
i:= x + Gear^.Radius * 2 - 2; |
|
935 |
repeat |
|
936 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
937 |
if Land[y, x] <> 0 then |
|
7767 | 938 |
if (not isColl) or (abs(x-gx) < abs(collX-gx)) then |
7754 | 939 |
begin |
940 |
isColl:= true; |
|
941 |
collX := x; |
|
942 |
end; |
|
943 |
inc(x) |
|
944 |
until (x > i); |
|
945 |
end; |
|
946 |
end |
|
947 |
else |
|
948 |
begin |
|
949 |
x:= hwRound(Gear^.X) + Gear^.Radius * dirX; |
|
950 |
gy:= hwRound(Gear^.Y); |
|
951 |
collY := gy; |
|
952 |
isColl:= false; |
|
953 |
||
954 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
955 |
begin |
|
956 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
|
957 |
i:= y + Gear^.Radius * 2 - 2; |
|
958 |
repeat |
|
959 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
960 |
if Land[y, x] <> 0 then |
|
7767 | 961 |
if (not isColl) or (abs(y-gy) < abs(collY-gy)) then |
7754 | 962 |
begin |
963 |
isColl:= true; |
|
964 |
collY := y; |
|
965 |
end; |
|
966 |
inc(y) |
|
967 |
until (y > i); |
|
968 |
end; |
|
969 |
end; |
|
970 |
||
971 |
if isColl then |
|
972 |
begin |
|
973 |
// save original dx/dy |
|
974 |
dx := Gear^.dX; |
|
975 |
dy := Gear^.dY; |
|
976 |
||
977 |
if dirY <> 0 then |
|
978 |
begin |
|
979 |
Gear^.dX.QWordValue:= 0; |
|
980 |
Gear^.dX.isNegative:= (collX >= gx); |
|
981 |
Gear^.dY:= _1*dirY |
|
982 |
end |
|
983 |
else |
|
984 |
begin |
|
985 |
Gear^.dY.QWordValue:= 0; |
|
986 |
Gear^.dY.isNegative:= (collY >= gy); |
|
987 |
Gear^.dX:= _1*dirX |
|
988 |
end; |
|
989 |
||
990 |
sdx:= 0; |
|
991 |
sdy:= 0; |
|
992 |
if dirY <> 0 then |
|
993 |
bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 0) |
|
994 |
else bSucc := CalcSlopeTangent(Gear, x, collY, sdx, sdy, 0); |
|
995 |
||
996 |
// restore original dx/dy |
|
997 |
Gear^.dX := dx; |
|
998 |
Gear^.dY := dy; |
|
999 |
||
1000 |
if bSucc and ((sdx <> 0) or (sdy <> 0)) then |
|
1001 |
begin |
|
1002 |
dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy)); |
|
1003 |
dx.isNegative := (sdx * sdy) < 0; |
|
1004 |
exit (dx); |
|
1005 |
end |
|
1006 |
end; |
|
1007 |
||
1008 |
CalcSlopeNearGear := _0; |
|
1009 |
end; |
|
1010 |
||
6279 | 1011 |
function CalcSlopeBelowGear(Gear: PGear): hwFloat; |
6124 | 1012 |
var dx, dy: hwFloat; |
6279 | 1013 |
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
|
1014 |
isColl, bSucc: Boolean; |
6124 | 1015 |
begin |
1016 |
||
1017 |
||
1018 |
y:= hwRound(Gear^.Y) + Gear^.Radius; |
|
1019 |
gx:= hwRound(Gear^.X); |
|
1020 |
collX := gx; |
|
1021 |
isColl:= false; |
|
1022 |
||
1023 |
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
|
1024 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
1025 |
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
|
1026 |
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
|
1027 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
1028 |
if (x and LAND_WIDTH_MASK) = 0 then |
14552
e0af4ce7d8bc
fix incorrect mask set in r7b4643ff60ea - this causes ghost hog collisions and odd hog jumps on overlap with active hog
nemo
parents:
14303
diff
changeset
|
1029 |
if (Land[y, x] and lfLandMask) <> 0 then |
7767 | 1030 |
if (not isColl) or (abs(x-gx) < abs(collX-gx)) then |
6124 | 1031 |
begin |
1032 |
isColl:= true; |
|
1033 |
collX := x; |
|
1034 |
end; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
1035 |
inc(x) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
1036 |
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
|
1037 |
end; |
6124 | 1038 |
|
1039 |
if isColl then |
|
6279 | 1040 |
begin |
1041 |
// save original dx/dy |
|
1042 |
dx := Gear^.dX; |
|
1043 |
dy := Gear^.dY; |
|
1044 |
||
1045 |
Gear^.dX.QWordValue:= 0; |
|
1046 |
Gear^.dX.isNegative:= (collX >= gx); |
|
1047 |
Gear^.dY:= _1; |
|
1048 |
||
1049 |
sdx:= 0; |
|
1050 |
sdy:= 0; |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
1051 |
bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 255); |
6124 | 1052 |
|
6279 | 1053 |
// restore original dx/dy |
1054 |
Gear^.dX := dx; |
|
1055 |
Gear^.dY := dy; |
|
6124 | 1056 |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
1057 |
if bSucc and (sdx <> 0) and (sdy <> 0) then |
6279 | 1058 |
begin |
1059 |
dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy)); |
|
1060 |
dx.isNegative := (sdx * sdy) < 0; |
|
1061 |
exit (dx); |
|
1062 |
end; |
|
1063 |
end; |
|
1064 |
||
1065 |
CalcSlopeBelowGear := _0; |
|
6124 | 1066 |
end; |
1067 |
||
15322 | 1068 |
function CheckGearsUnderSprite(Sprite: TSprite; sprX, sprY, Frame: LongInt): boolean; |
1069 |
var x, y, bpp, h, w, row, col, gx, gy, r, numFramesFirstCol: LongInt; |
|
1070 |
p: PByteArray; |
|
1071 |
Image: PSDL_Surface; |
|
1072 |
Gear: PGear; |
|
1073 |
begin |
|
1074 |
CheckGearsUnderSprite := false; |
|
1075 |
if checkFails(SpritesData[Sprite].Surface <> nil, 'Assert SpritesData[Sprite].Surface failed', true) then exit; |
|
1076 |
||
1077 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
|
1078 |
Image:= SpritesData[Sprite].Surface; |
|
1079 |
||
1080 |
if SDL_MustLock(Image) then |
|
1081 |
if SDLCheck(SDL_LockSurface(Image) >= 0, 'CheckGearsUnderSprite', true) then exit; |
|
1082 |
||
1083 |
bpp:= Image^.format^.BytesPerPixel; |
|
1084 |
||
1085 |
if checkFails(bpp = 4, 'It should be 32 bpp sprite', true) then |
|
1086 |
begin |
|
1087 |
if SDL_MustLock(Image) then |
|
1088 |
SDL_UnlockSurface(Image); |
|
1089 |
exit |
|
1090 |
end; |
|
1091 |
||
1092 |
w:= SpritesData[Sprite].Width; |
|
1093 |
h:= SpritesData[Sprite].Height; |
|
1094 |
||
1095 |
row:= Frame mod numFramesFirstCol; |
|
1096 |
col:= Frame div numFramesFirstCol; |
|
1097 |
p:= PByteArray(@(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ])); |
|
1098 |
Gear:= GearsList; |
|
1099 |
||
1100 |
while Gear <> nil do |
|
1101 |
begin |
|
15325 | 1102 |
if (Gear^.Kind = gtAirMine) or |
1103 |
((Gear^.Kind in [gtCase, gtExplosives, gtTarget, gtKnife, gtMine, gtHedgehog, gtSMine]) and (Gear^.CollisionIndex = -1)) then |
|
15322 | 1104 |
begin |
1105 |
gx:= hwRound(Gear^.X); |
|
1106 |
gy:= hwRound(Gear^.Y); |
|
15323
9299f43ba0ec
disallow placing girders over airmines and moving hogs
alfadur
parents:
15322
diff
changeset
|
1107 |
r:= Gear^.Radius + 1; |
15322 | 1108 |
if (gx + r >= sprX) and (gx - r < sprX + w) and (gy + r >= sprY) and (gy - r < sprY + h) then |
1109 |
for y := gy - r to gy + r do |
|
1110 |
for x := gx - r to gx + r do |
|
1111 |
begin |
|
1112 |
if (x >= sprX) and (x < sprX + w) and (y >= sprY) and (y < sprY + h) |
|
15323
9299f43ba0ec
disallow placing girders over airmines and moving hogs
alfadur
parents:
15322
diff
changeset
|
1113 |
and (Sqr(x - gx) + Sqr(y - gy) <= Sqr(r)) |
9299f43ba0ec
disallow placing girders over airmines and moving hogs
alfadur
parents:
15322
diff
changeset
|
1114 |
and (((PLongword(@(p^[Image^.pitch * (y - sprY) + (x - sprX) * 4]))^) and AMask) <> 0) then |
15322 | 1115 |
begin |
1116 |
CheckGearsUnderSprite := true; |
|
1117 |
if SDL_MustLock(Image) then |
|
1118 |
SDL_UnlockSurface(Image); |
|
1119 |
exit |
|
1120 |
end |
|
1121 |
end |
|
1122 |
end; |
|
1123 |
||
1124 |
Gear := Gear^.NextGear |
|
1125 |
end; |
|
1126 |
end; |
|
1127 |
||
3038 | 1128 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1129 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
1130 |
Count:= 0; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1131 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1132 |
|
3038 | 1133 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1134 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1135 |
|
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1136 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
1137 |
|
4 | 1138 |
end. |