author | alfadur |
Tue, 29 May 2018 19:12:53 -0400 | |
changeset 13413 | 419c5eab88eb |
parent 13173 | 0e7eddfbce8a |
child 13468 | f1d349a52bc7 |
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 |
|
12903 | 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; |
12903 | 26 |
const cMaxGearHitOrderInd = 1023; |
4 | 27 |
|
70 | 28 |
type PGearArray = ^TGearArray; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
29 |
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
|
30 |
ar: array[0..cMaxGearArrayInd] of PGear; |
12903 | 31 |
cX: array[0..cMaxGearArrayInd] of LongInt; |
32 |
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
|
33 |
Count: Longword |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
34 |
end; |
4 | 35 |
|
12903 | 36 |
type PGearHitOrder = ^TGearHitOrder; |
37 |
TGearHitOrder = record |
|
38 |
ar: array[0..cMaxGearHitOrderInd] of PGear; |
|
39 |
order: array[0..cMaxGearHitOrderInd] of LongInt; |
|
40 |
Count: Longword |
|
41 |
end; |
|
42 |
||
43 |
type TLineCollision = record |
|
44 |
hasCollision: Boolean; |
|
45 |
cX, cY: LongInt; //for visual effects only |
|
46 |
end; |
|
47 |
||
3038 | 48 |
procedure initModule; |
49 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
50 |
|
9291
15f7bb217b66
Make add/delete consistent (this has bugged me for so long)
nemo
parents:
9247
diff
changeset
|
51 |
procedure AddCI(Gear: PGear); |
53 | 52 |
procedure DeleteCI(Gear: PGear); |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
53 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
54 |
function CheckGearsCollision(Gear: PGear): PGearArray; |
12903 | 55 |
function CheckAllGearsCollision(SourceGear: PGear): PGearArray; |
56 |
||
57 |
function CheckGearsLineCollision(Gear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
58 |
function CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
59 |
||
60 |
function UpdateHitOrder(Gear: PGear; Order: LongInt): boolean; |
|
61 |
procedure ClearHitOrderLeq(MinOrder: LongInt); |
|
62 |
procedure ClearHitOrder(); |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
63 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
64 |
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
|
65 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
66 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
67 |
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
|
68 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
69 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
70 |
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
|
71 |
function TestCollisionY(Gear: PGear; Dir: LongInt): Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
72 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; |
4 | 77 |
|
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
|
78 |
function TestRectangleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; |
6124 | 79 |
|
10354 | 80 |
function CheckCoordInWater(X, Y: LongInt): boolean; inline; |
81 |
||
9248 | 82 |
// returns: negative sign if going downhill to left, value is steepness (noslope/error = _0, 45 = _0_5) |
6279 | 83 |
function CalcSlopeBelowGear(Gear: PGear): hwFloat; |
7754 | 84 |
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
|
85 |
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
|
86 |
|
4 | 87 |
implementation |
11537 | 88 |
uses uConsts, uLandGraphics, uVariables; |
4 | 89 |
|
53 | 90 |
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
|
91 |
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
|
92 |
cGear: PGear; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
93 |
end; |
351 | 94 |
|
5568 | 95 |
const MAXRECTSINDEX = 1023; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
96 |
var Count: Longword; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
97 |
cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
98 |
ga: TGearArray; |
12903 | 99 |
ordera: TGearHitOrder; |
4 | 100 |
|
9291
15f7bb217b66
Make add/delete consistent (this has bugged me for so long)
nemo
parents:
9247
diff
changeset
|
101 |
procedure AddCI(Gear: PGear); |
53 | 102 |
begin |
11537 | 103 |
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
|
104 |
((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
|
105 |
exit; |
11537 | 106 |
|
53 | 107 |
with cinfos[Count] do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
108 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
109 |
X:= hwRound(Gear^.X); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
110 |
Y:= hwRound(Gear^.Y); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
111 |
Radius:= Gear^.Radius; |
11594
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:
11537
diff
changeset
|
112 |
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
|
113 |
cGear:= Gear |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
114 |
end; |
511 | 115 |
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
|
116 |
inc(Count); |
4 | 117 |
end; |
118 |
||
53 | 119 |
procedure DeleteCI(Gear: PGear); |
4 | 120 |
begin |
511 | 121 |
if Gear^.CollisionIndex >= 0 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
122 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
123 |
with cinfos[Gear^.CollisionIndex] do |
11594
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:
11537
diff
changeset
|
124 |
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
|
125 |
cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
126 |
cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
127 |
Gear^.CollisionIndex:= -1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
128 |
dec(Count) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
129 |
end; |
4 | 130 |
end; |
131 |
||
10354 | 132 |
function CheckCoordInWater(X, Y: LongInt): boolean; inline; |
133 |
begin |
|
134 |
CheckCoordInWater:= (Y > cWaterLine) |
|
10494 | 135 |
or ((WorldEdge = weSea) and ((X < LongInt(leftX)) or (X > LongInt(rightX)))); |
10354 | 136 |
end; |
137 |
||
53 | 138 |
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
|
139 |
var mx, my, tr: LongInt; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
140 |
i: Longword; |
4 | 141 |
begin |
1506 | 142 |
CheckGearsCollision:= @ga; |
53 | 143 |
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
|
144 |
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
|
145 |
exit; |
351 | 146 |
mx:= hwRound(Gear^.X); |
147 |
my:= hwRound(Gear^.Y); |
|
4 | 148 |
|
4705
593ef1ad3cd3
ok. restore old [r + 1 + r] for gear width for a moment, and reset snowballs.
nemo
parents:
4684
diff
changeset
|
149 |
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
|
150 |
|
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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
(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
|
155 |
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
|
156 |
ga.ar[ga.Count]:= cinfos[i].cGear; |
12903 | 157 |
ga.cX[ga.Count]:= hwround(Gear^.X); |
158 |
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
|
159 |
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
|
160 |
end |
4 | 161 |
end; |
162 |
||
12903 | 163 |
function CheckAllGearsCollision(SourceGear: PGear): PGearArray; |
164 |
var mx, my, tr: LongInt; |
|
165 |
Gear: PGear; |
|
166 |
begin |
|
167 |
CheckAllGearsCollision:= @ga; |
|
168 |
ga.Count:= 0; |
|
169 |
||
170 |
mx:= hwRound(SourceGear^.X); |
|
171 |
my:= hwRound(SourceGear^.Y); |
|
172 |
||
173 |
tr:= SourceGear^.Radius + 2; |
|
174 |
||
175 |
Gear:= GearsList; |
|
176 |
||
177 |
while Gear <> nil do |
|
178 |
begin |
|
179 |
if (Gear <> SourceGear) and |
|
180 |
(sqr(mx - hwRound(Gear^.x)) + sqr(my - hwRound(Gear^.y)) <= sqr(Gear^.Radius + tr))then |
|
181 |
begin |
|
182 |
ga.ar[ga.Count]:= Gear; |
|
183 |
ga.cX[ga.Count]:= hwround(SourceGear^.X); |
|
184 |
ga.cY[ga.Count]:= hwround(SourceGear^.Y); |
|
185 |
inc(ga.Count) |
|
186 |
end; |
|
187 |
||
188 |
Gear := Gear^.NextGear |
|
189 |
end; |
|
190 |
end; |
|
191 |
||
192 |
function LineCollisionTest(oX, oY, dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
193 |
width: LongInt; Gear: PGear): |
|
194 |
TLineCollision; inline; |
|
195 |
var toCenterX, toCenterY, r, |
|
196 |
b, bSqr, c, desc, t: hwFloat; |
|
197 |
realT: extended; |
|
198 |
begin |
|
199 |
LineCollisionTest.hasCollision:= false; |
|
200 |
toCenterX:= (oX - Gear^.X); |
|
201 |
toCenterY:= (oY - Gear^.Y); |
|
202 |
r:= int2hwFloat(Gear^.Radius + width + 2); |
|
203 |
// Early cull to avoid multiplying large numbers |
|
204 |
if hwAbs(toCenterX) + hwAbs(toCenterY) > dirNormBound + r then |
|
205 |
exit; |
|
206 |
b:= dirX * toCenterX + dirY * toCenterY; |
|
207 |
c:= hwSqr(toCenterX) + hwSqr(toCenterY) - hwSqr(r); |
|
208 |
if (b > _0) and (c > _0) then |
|
209 |
exit; |
|
210 |
bSqr:= hwSqr(b); |
|
211 |
desc:= bSqr - dirNormSqr * c; |
|
212 |
if desc.isNegative then exit; |
|
213 |
||
214 |
t:= -b - hwSqrt(desc); |
|
215 |
if t.isNegative then t:= _0; |
|
216 |
if t < dirNormSqr then |
|
217 |
with LineCollisionTest do |
|
218 |
begin |
|
219 |
hasCollision:= true; |
|
220 |
realT := hwFloat2Float(t) / hwFloat2Float(dirNormSqr); |
|
221 |
cX:= round(hwFloat2Float(oX) + realT * hwFloat2Float(dirX)); |
|
222 |
cY:= round(hwFloat2Float(oY) + realT * hwFloat2Float(dirY)); |
|
223 |
end; |
|
224 |
end; |
|
225 |
||
226 |
function CheckGearsLineCollision(Gear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
227 |
var dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
228 |
test: TLineCollision; |
|
229 |
i: Longword; |
|
230 |
begin |
|
231 |
CheckGearsLineCollision:= @ga; |
|
232 |
ga.Count:= 0; |
|
233 |
if Count = 0 then |
|
234 |
exit; |
|
235 |
dirX:= (tX - oX); |
|
236 |
dirY:= (tY - oY); |
|
237 |
dirNormBound:= _1_5 * (hwAbs(dirX) + hwAbs(dirY)); |
|
238 |
dirNormSqr:= hwSqr(dirX) + hwSqr(dirY); |
|
239 |
if dirNormSqr.isNegative then |
|
240 |
exit; |
|
241 |
||
242 |
for i:= 0 to Pred(Count) do |
|
243 |
with cinfos[i] do if Gear <> cGear then |
|
244 |
begin |
|
245 |
test:= LineCollisionTest( |
|
246 |
oX, oY, dirX, dirY, dirNormSqr, dirNormBound, Gear^.Radius, cGear); |
|
247 |
if test.hasCollision then |
|
248 |
begin |
|
249 |
ga.ar[ga.Count] := cGear; |
|
250 |
ga.cX[ga.Count] := test.cX; |
|
251 |
ga.cY[ga.Count] := test.cY; |
|
252 |
inc(ga.Count) |
|
253 |
end |
|
254 |
end |
|
255 |
end; |
|
256 |
||
257 |
function CheckAllGearsLineCollision(SourceGear: PGear; oX, oY, tX, tY: hwFloat): PGearArray; |
|
258 |
var dirX, dirY, dirNormSqr, dirNormBound: hwFloat; |
|
259 |
test: TLineCollision; |
|
260 |
Gear: PGear; |
|
261 |
begin |
|
262 |
CheckAllGearsLineCollision:= @ga; |
|
263 |
ga.Count:= 0; |
|
264 |
dirX:= (tX - oX); |
|
265 |
dirY:= (tY - oY); |
|
266 |
dirNormBound:= _1_5 * (hwAbs(dirX) + hwAbs(dirY)); |
|
267 |
dirNormSqr:= hwSqr(dirX) + hwSqr(dirY); |
|
268 |
if dirNormSqr.isNegative then |
|
269 |
exit; |
|
270 |
||
271 |
Gear:= GearsList; |
|
272 |
while Gear <> nil do |
|
273 |
begin |
|
274 |
if SourceGear <> Gear then |
|
275 |
begin |
|
276 |
test:= LineCollisionTest( |
|
277 |
oX, oY, dirX, dirY, dirNormSqr, dirNormBound, SourceGear^.Radius, Gear); |
|
278 |
if test.hasCollision then |
|
279 |
begin |
|
280 |
ga.ar[ga.Count] := Gear; |
|
281 |
ga.cX[ga.Count] := test.cX; |
|
282 |
ga.cY[ga.Count] := test.cY; |
|
283 |
inc(ga.Count) |
|
284 |
end |
|
285 |
end; |
|
286 |
Gear := Gear^.NextGear |
|
287 |
end; |
|
288 |
end; |
|
289 |
||
290 |
function UpdateHitOrder(Gear: PGear; Order: LongInt): boolean; |
|
291 |
var i: LongInt; |
|
292 |
begin |
|
293 |
UpdateHitOrder:= true; |
|
13173
0e7eddfbce8a
Fix minigun bullets sometimes failing to hit when shooting same thing twice in row
alfadur
parents:
12903
diff
changeset
|
294 |
for i:= 0 to ordera.Count - 1 do |
12903 | 295 |
if ordera.ar[i] = Gear then |
296 |
begin |
|
297 |
if Order <= ordera.order[i] then UpdateHitOrder:= false; |
|
298 |
ordera.order[i]:= Max(ordera.order[i], order); |
|
299 |
exit; |
|
300 |
end; |
|
301 |
||
302 |
if ordera.Count > cMaxGearHitOrderInd then |
|
303 |
UpdateHitOrder:= false |
|
304 |
else |
|
305 |
begin |
|
306 |
ordera.ar[ordera.Count]:= Gear; |
|
307 |
ordera.order[ordera.Count]:= Order; |
|
308 |
Inc(ordera.Count); |
|
309 |
end |
|
310 |
end; |
|
311 |
||
312 |
procedure ClearHitOrderLeq(MinOrder: LongInt); |
|
313 |
var i, freeIndex: LongInt; |
|
314 |
begin; |
|
315 |
freeIndex:= 0; |
|
316 |
i:= 0; |
|
317 |
||
318 |
while i < ordera.Count do |
|
319 |
begin |
|
320 |
if ordera.order[i] <= MinOrder then |
|
321 |
Dec(ordera.Count) |
|
322 |
else |
|
323 |
begin |
|
324 |
if freeIndex < i then |
|
325 |
begin |
|
326 |
ordera.ar[freeIndex]:= ordera.ar[i]; |
|
327 |
ordera.order[freeIndex]:= ordera.order[i]; |
|
328 |
end; |
|
329 |
Inc(freeIndex); |
|
330 |
end; |
|
331 |
Inc(i) |
|
332 |
end |
|
333 |
end; |
|
334 |
||
335 |
procedure ClearHitOrder(); |
|
336 |
begin |
|
337 |
ordera.Count:= 0; |
|
338 |
end; |
|
339 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
340 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): Word; |
371 | 341 |
var x, y, i: LongInt; |
4 | 342 |
begin |
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
343 |
// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap |
8751
4609823efc94
More flagging of Land values. Also use less than for tests of non-terrain, instead of "and $FF00 = 0". Saves a couple of ops, which actually matters a small amount in a few places.
nemo
parents:
8744
diff
changeset
|
344 |
if (Gear^.CollisionMask = lfNotCurrentMask) and (Gear^.Kind <> gtHedgehog) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and |
7754 | 345 |
((hwRound(Gear^.Hedgehog^.Gear^.X) + Gear^.Hedgehog^.Gear^.Radius + 16 < hwRound(Gear^.X) - Gear^.Radius) or |
346 |
(hwRound(Gear^.Hedgehog^.Gear^.X) - Gear^.Hedgehog^.Gear^.Radius - 16 > hwRound(Gear^.X) + Gear^.Radius)) then |
|
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
347 |
Gear^.CollisionMask:= $FFFF; |
838 | 348 |
|
351 | 349 |
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
|
350 |
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
|
351 |
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
|
352 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
353 |
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
|
354 |
|
1753 | 355 |
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
|
356 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
357 |
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
|
358 |
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
|
359 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
inc(y) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
364 |
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
|
365 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
366 |
TestCollisionXwithGear:= 0 |
4 | 367 |
end; |
368 |
||
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
|
369 |
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
|
370 |
var x, y, i: LongInt; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
371 |
begin |
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
372 |
// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap |
8751
4609823efc94
More flagging of Land values. Also use less than for tests of non-terrain, instead of "and $FF00 = 0". Saves a couple of ops, which actually matters a small amount in a few places.
nemo
parents:
8744
diff
changeset
|
373 |
if (Gear^.CollisionMask = lfNotCurrentMask) and (Gear^.Kind <> gtHedgehog) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and |
7754 | 374 |
((hwRound(Gear^.Hedgehog^.Gear^.Y) + Gear^.Hedgehog^.Gear^.Radius + 16 < hwRound(Gear^.Y) - Gear^.Radius) or |
375 |
(hwRound(Gear^.Hedgehog^.Gear^.Y) - Gear^.Hedgehog^.Gear^.Radius - 16 > hwRound(Gear^.Y) + Gear^.Radius)) then |
|
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
376 |
Gear^.CollisionMask:= $FFFF; |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
377 |
|
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
378 |
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
|
379 |
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
|
380 |
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
|
381 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
382 |
y:= y + Gear^.Radius; |
7268 | 383 |
|
1753 | 384 |
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
|
385 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
389 |
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
|
390 |
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
|
391 |
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
|
392 |
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
|
393 |
end; |
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7270
diff
changeset
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
TestCollisionYwithGear:= 0 |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
398 |
end; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
399 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
400 |
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
|
401 |
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
|
402 |
pixel: Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
403 |
begin |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
404 |
pixel:= 0; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
405 |
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
|
406 |
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
|
407 |
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
|
408 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
409 |
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
|
410 |
|
1753 | 411 |
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
|
412 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
413 |
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
|
414 |
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
|
415 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
416 |
if (y and LAND_HEIGHT_MASK) = 0 then |
11077 | 417 |
begin |
418 |
if Land[y, x] and Gear^.CollisionMask <> 0 then |
|
419 |
begin |
|
420 |
if Land[y, x] and Gear^.CollisionMask > 255 then |
|
421 |
exit(Land[y, x] and Gear^.CollisionMask) |
|
422 |
else |
|
423 |
pixel:= Land[y, x] and Gear^.CollisionMask; |
|
424 |
end; |
|
425 |
end; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
426 |
inc(y) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
427 |
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
|
428 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
429 |
TestCollisionXKick:= pixel; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
430 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
431 |
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
|
432 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
433 |
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
|
434 |
exit; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
435 |
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
|
436 |
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
|
437 |
exit; |
967 | 438 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
439 |
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
|
440 |
my:= hwRound(Gear^.Y); |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
441 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
442 |
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
|
443 |
with cinfos[i] do |
10015 | 444 |
if (Gear <> cGear) and |
9305
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
445 |
((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
|
446 |
( |
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
|
447 |
((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
|
448 |
// 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
|
449 |
((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
|
450 |
) and |
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
451 |
(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
|
452 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
453 |
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
|
454 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
455 |
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
|
456 |
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
|
457 |
State:= State or gstMoving; |
7767 | 458 |
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
|
459 |
Active:= true |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
460 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
461 |
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
|
462 |
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
|
463 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
464 |
end |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
465 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
466 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
467 |
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
|
468 |
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
|
469 |
pixel: Word; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
470 |
begin |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
471 |
pixel:= 0; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
472 |
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
|
473 |
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
|
474 |
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
|
475 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
476 |
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
|
477 |
|
1753 | 478 |
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
|
479 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
480 |
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
|
481 |
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
|
482 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
483 |
if (x and LAND_WIDTH_MASK) = 0 then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
484 |
if Land[y, x] > 0 then |
11077 | 485 |
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
|
486 |
if Land[y, x] and Gear^.CollisionMask > 255 then |
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
|
487 |
exit(Land[y, x] and Gear^.CollisionMask) |
11077 | 488 |
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
|
489 |
pixel:= Land[y, x] and Gear^.CollisionMask; |
11077 | 490 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
491 |
inc(x) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
492 |
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
|
493 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
494 |
TestCollisionYKick:= pixel; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
495 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
496 |
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
|
497 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
498 |
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
|
499 |
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
|
500 |
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
|
501 |
exit; |
967 | 502 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
503 |
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
|
504 |
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
|
505 |
myr:= my+Gear^.Radius; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
506 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
507 |
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
|
508 |
with cinfos[i] do |
9305
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
509 |
if (Gear <> cGear) and |
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
510 |
((myr > y) xor (Dir > 0)) and |
8e5140875ab5
bug #668 + reorder conditions for kick slightly, to call the math last
nemo
parents:
9291
diff
changeset
|
511 |
(Gear^.State and gstNotKickable = 0) and |
10015 | 512 |
(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
|
513 |
(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
|
514 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
515 |
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
|
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 (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
|
518 |
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
|
519 |
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
|
520 |
State:= State or gstMoving; |
7767 | 521 |
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
|
522 |
Active:= true |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
523 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
524 |
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
|
525 |
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
|
526 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
527 |
end |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
528 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
529 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
530 |
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
|
531 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
532 |
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
|
533 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
534 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
535 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; |
4 | 536 |
begin |
351 | 537 |
Gear^.X:= Gear^.X + ShiftX; |
498 | 538 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
10015 | 539 |
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
|
540 |
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
|
541 |
else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir); |
351 | 542 |
Gear^.X:= Gear^.X - ShiftX; |
498 | 543 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
4 | 544 |
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
|
545 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
546 |
function TestCollisionX(Gear: PGear; Dir: LongInt): Word; |
4798 | 547 |
var x, y, i: LongInt; |
548 |
begin |
|
549 |
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
|
550 |
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
|
551 |
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
|
552 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
553 |
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
|
554 |
|
4798 | 555 |
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
|
556 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
557 |
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
|
558 |
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
|
559 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
560 |
if (y and LAND_HEIGHT_MASK) = 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
|
561 |
if Land[y, x] and Gear^.CollisionMask > 255 then |
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
|
562 |
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
|
563 |
inc(y) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
564 |
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
|
565 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
566 |
TestCollisionX:= 0 |
4798 | 567 |
end; |
4 | 568 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
569 |
function TestCollisionY(Gear: PGear; Dir: LongInt): Word; |
371 | 570 |
var x, y, i: LongInt; |
68 | 571 |
begin |
351 | 572 |
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
|
573 |
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
|
574 |
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
|
575 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
576 |
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
|
577 |
|
1753 | 578 |
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
|
579 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
580 |
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
|
581 |
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
|
582 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
583 |
if (x and LAND_WIDTH_MASK) = 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
|
584 |
if Land[y, x] and Gear^.CollisionMask > 255 then |
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
|
585 |
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
|
586 |
inc(x) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
587 |
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
|
588 |
end; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
589 |
TestCollisionY:= 0 |
68 | 590 |
end; |
591 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
592 |
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
|
593 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
594 |
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
|
595 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6700
diff
changeset
|
596 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9305
diff
changeset
|
597 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean): Word; |
4 | 598 |
begin |
498 | 599 |
Gear^.X:= Gear^.X + int2hwFloat(ShiftX); |
600 |
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
|
601 |
|
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
602 |
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
|
603 |
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
|
604 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
605 |
TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir); |
10015 | 606 |
|
498 | 607 |
Gear^.X:= Gear^.X - int2hwFloat(ShiftX); |
608 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
|
4 | 609 |
end; |
610 |
||
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
|
611 |
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
|
612 |
var x, y: LongInt; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
613 |
TestWord: LongWord; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
614 |
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
|
615 |
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
|
616 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
617 |
if landOnly then |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
618 |
TestWord:= 255 |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
619 |
else |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
620 |
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
|
621 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
622 |
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
|
623 |
begin |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
624 |
x := x1; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
625 |
x1 := x2; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
626 |
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
|
627 |
end; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
628 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
629 |
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
|
630 |
begin |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
631 |
y := y1; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
632 |
y1 := y2; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
633 |
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
|
634 |
end; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
635 |
|
5919
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
636 |
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
|
637 |
exit; |
5919
f737843dd331
TestRectForObstacle: areas outside map borders are not passable
sheepluva
parents:
5896
diff
changeset
|
638 |
|
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
639 |
for y := y1 to y2 do |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
640 |
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
|
641 |
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
|
642 |
exit; |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
643 |
|
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
|
644 |
TestRectangleForObstacle:= false |
5896
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
645 |
end; |
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
646 |
|
9ce1cf4e5a32
lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents:
5834
diff
changeset
|
647 |
function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; |
3408 | 648 |
var ldx, ldy, rdx, rdy: LongInt; |
6123 | 649 |
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
|
650 |
tmpx, tmpy: LongWord; |
3569 | 651 |
dx, dy, s: hwFloat; |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
652 |
offset: array[0..7,0..1] of ShortInt; |
6123 | 653 |
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
|
654 |
|
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
|
655 |
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
|
656 |
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
|
657 |
|
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
|
658 |
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
|
659 |
dy:= Gear^.dY; |
3408 | 660 |
|
3569 | 661 |
// we start searching from the direction the gear came from |
662 |
if (dx.QWordValue > _0_995.QWordValue ) |
|
663 |
or (dy.QWordValue > _0_995.QWordValue ) then |
|
664 |
begin // scale |
|
6279 | 665 |
s := _0_995 / Distance(dx,dy); |
3569 | 666 |
dx := s * dx; |
667 |
dy := s * dy; |
|
668 |
end; |
|
669 |
||
3408 | 670 |
mx:= hwRound(Gear^.X-dx) - hwRound(Gear^.X); |
671 |
my:= hwRound(Gear^.Y-dy) - hwRound(Gear^.Y); |
|
672 |
||
673 |
li:= -1; |
|
674 |
ri:= -1; |
|
3569 | 675 |
|
3408 | 676 |
// go around collision pixel, checking for first/last collisions |
677 |
// this will determinate what angles will be tried to crawl along |
|
678 |
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
|
679 |
begin |
3408 | 680 |
offset[i,0]:= mx; |
681 |
offset[i,1]:= my; |
|
3569 | 682 |
|
6123 | 683 |
// multiplicator k tries to skip small pixels/gaps when possible |
684 |
for k:= 4 downto 1 do |
|
685 |
begin |
|
686 |
tmpx:= collisionX + k * mx; |
|
687 |
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
|
688 |
|
6123 | 689 |
if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) then |
690 |
if (Land[tmpy,tmpx] > TestWord) then |
|
3408 | 691 |
begin |
6123 | 692 |
// remember the index belonging to the first and last collision (if in 1st half) |
693 |
if (i <> 0) then |
|
694 |
begin |
|
695 |
if (ri = -1) then |
|
696 |
ri:= i |
|
697 |
else |
|
698 |
li:= i; |
|
699 |
end; |
|
3408 | 700 |
end; |
6123 | 701 |
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
|
702 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
703 |
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
|
704 |
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
|
705 |
|
3408 | 706 |
// 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
|
707 |
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
|
708 |
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
|
709 |
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
|
710 |
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
|
711 |
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
|
712 |
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
|
713 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
714 |
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
|
715 |
|
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
|
716 |
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
|
717 |
|
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
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
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
|
722 |
|
3408 | 723 |
// edge-crawl |
724 |
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
|
725 |
begin |
3408 | 726 |
// using mx,my as temporary value buffer here |
3697 | 727 |
|
3408 | 728 |
jfr:= 8+li+1; |
729 |
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
|
730 |
|
6123 | 731 |
isColl:= false; |
3408 | 732 |
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
|
733 |
begin |
3408 | 734 |
tmpo:= j mod 8; |
6123 | 735 |
// multiplicator k tries to skip small pixels/gaps when possible |
736 |
for k:= 3 downto 1 do |
|
737 |
begin |
|
738 |
tmpx:= ldx + k * offset[tmpo,0]; |
|
739 |
tmpy:= ldy + k * offset[tmpo,1]; |
|
740 |
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
|
741 |
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
|
742 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
743 |
ldx:= tmpx; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
744 |
ldy:= tmpy; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
745 |
isColl:= true; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
746 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
747 |
end; |
6123 | 748 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
749 |
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
|
750 |
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
|
751 |
end; |
3408 | 752 |
|
753 |
jfr:= 8+ri-1; |
|
754 |
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
|
755 |
|
6123 | 756 |
isColl:= false; |
3408 | 757 |
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
|
758 |
begin |
3408 | 759 |
tmpo:= j mod 8; |
6123 | 760 |
for k:= 3 downto 1 do |
761 |
begin |
|
762 |
tmpx:= rdx + k * offset[tmpo,0]; |
|
763 |
tmpy:= rdy + k * offset[tmpo,1]; |
|
764 |
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
|
765 |
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
|
766 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
767 |
rdx:= tmpx; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
768 |
rdy:= tmpy; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
769 |
isColl:= true; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
770 |
break; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
771 |
end; |
6123 | 772 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
773 |
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
|
774 |
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
|
775 |
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
|
776 |
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
|
777 |
|
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
|
778 |
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
|
779 |
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
|
780 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
781 |
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
|
782 |
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
|
783 |
|
3414
b2f3bb44777e
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents:
3411
diff
changeset
|
784 |
outDeltaX:= ldx; |
b2f3bb44777e
some portal changes, warning: no loop prevention yet, note: entry angle not preserved yet
sheepluva
parents:
3411
diff
changeset
|
785 |
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
|
786 |
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
|
787 |
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
|
788 |
|
7754 | 789 |
function CalcSlopeNearGear(Gear: PGear; dirX, dirY: LongInt): hwFloat; |
790 |
var dx, dy: hwFloat; |
|
791 |
collX, collY, i, y, x, gx, gy, sdx, sdy: LongInt; |
|
792 |
isColl, bSucc: Boolean; |
|
793 |
begin |
|
794 |
||
10015 | 795 |
if dirY <> 0 then |
7754 | 796 |
begin |
797 |
y:= hwRound(Gear^.Y) + Gear^.Radius * dirY; |
|
798 |
gx:= hwRound(Gear^.X); |
|
799 |
collX := gx; |
|
800 |
isColl:= false; |
|
801 |
||
802 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
803 |
begin |
|
804 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
|
805 |
i:= x + Gear^.Radius * 2 - 2; |
|
806 |
repeat |
|
807 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
808 |
if Land[y, x] <> 0 then |
|
7767 | 809 |
if (not isColl) or (abs(x-gx) < abs(collX-gx)) then |
7754 | 810 |
begin |
811 |
isColl:= true; |
|
812 |
collX := x; |
|
813 |
end; |
|
814 |
inc(x) |
|
815 |
until (x > i); |
|
816 |
end; |
|
817 |
end |
|
818 |
else |
|
819 |
begin |
|
820 |
x:= hwRound(Gear^.X) + Gear^.Radius * dirX; |
|
821 |
gy:= hwRound(Gear^.Y); |
|
822 |
collY := gy; |
|
823 |
isColl:= false; |
|
824 |
||
825 |
if (x and LAND_WIDTH_MASK) = 0 then |
|
826 |
begin |
|
827 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
|
828 |
i:= y + Gear^.Radius * 2 - 2; |
|
829 |
repeat |
|
830 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
831 |
if Land[y, x] <> 0 then |
|
7767 | 832 |
if (not isColl) or (abs(y-gy) < abs(collY-gy)) then |
7754 | 833 |
begin |
834 |
isColl:= true; |
|
835 |
collY := y; |
|
836 |
end; |
|
837 |
inc(y) |
|
838 |
until (y > i); |
|
839 |
end; |
|
840 |
end; |
|
841 |
||
842 |
if isColl then |
|
843 |
begin |
|
844 |
// save original dx/dy |
|
845 |
dx := Gear^.dX; |
|
846 |
dy := Gear^.dY; |
|
847 |
||
848 |
if dirY <> 0 then |
|
849 |
begin |
|
850 |
Gear^.dX.QWordValue:= 0; |
|
851 |
Gear^.dX.isNegative:= (collX >= gx); |
|
852 |
Gear^.dY:= _1*dirY |
|
853 |
end |
|
854 |
else |
|
855 |
begin |
|
856 |
Gear^.dY.QWordValue:= 0; |
|
857 |
Gear^.dY.isNegative:= (collY >= gy); |
|
858 |
Gear^.dX:= _1*dirX |
|
859 |
end; |
|
860 |
||
861 |
sdx:= 0; |
|
862 |
sdy:= 0; |
|
863 |
if dirY <> 0 then |
|
864 |
bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 0) |
|
865 |
else bSucc := CalcSlopeTangent(Gear, x, collY, sdx, sdy, 0); |
|
866 |
||
867 |
// restore original dx/dy |
|
868 |
Gear^.dX := dx; |
|
869 |
Gear^.dY := dy; |
|
870 |
||
871 |
if bSucc and ((sdx <> 0) or (sdy <> 0)) then |
|
872 |
begin |
|
873 |
dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy)); |
|
874 |
dx.isNegative := (sdx * sdy) < 0; |
|
875 |
exit (dx); |
|
876 |
end |
|
877 |
end; |
|
878 |
||
879 |
CalcSlopeNearGear := _0; |
|
880 |
end; |
|
881 |
||
6279 | 882 |
function CalcSlopeBelowGear(Gear: PGear): hwFloat; |
6124 | 883 |
var dx, dy: hwFloat; |
6279 | 884 |
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
|
885 |
isColl, bSucc: Boolean; |
6124 | 886 |
begin |
887 |
||
888 |
||
889 |
y:= hwRound(Gear^.Y) + Gear^.Radius; |
|
890 |
gx:= hwRound(Gear^.X); |
|
891 |
collX := gx; |
|
892 |
isColl:= false; |
|
893 |
||
894 |
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
|
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 |
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
|
897 |
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
|
898 |
repeat |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
899 |
if (x and LAND_WIDTH_MASK) = 0 then |
6124 | 900 |
if Land[y, x] > 255 then |
7767 | 901 |
if (not isColl) or (abs(x-gx) < abs(collX-gx)) then |
6124 | 902 |
begin |
903 |
isColl:= true; |
|
904 |
collX := x; |
|
905 |
end; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
906 |
inc(x) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6543
diff
changeset
|
907 |
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
|
908 |
end; |
6124 | 909 |
|
910 |
if isColl then |
|
6279 | 911 |
begin |
912 |
// save original dx/dy |
|
913 |
dx := Gear^.dX; |
|
914 |
dy := Gear^.dY; |
|
915 |
||
916 |
Gear^.dX.QWordValue:= 0; |
|
917 |
Gear^.dX.isNegative:= (collX >= gx); |
|
918 |
Gear^.dY:= _1; |
|
919 |
||
920 |
sdx:= 0; |
|
921 |
sdy:= 0; |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
922 |
bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 255); |
6124 | 923 |
|
6279 | 924 |
// restore original dx/dy |
925 |
Gear^.dX := dx; |
|
926 |
Gear^.dY := dy; |
|
6124 | 927 |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6279
diff
changeset
|
928 |
if bSucc and (sdx <> 0) and (sdy <> 0) then |
6279 | 929 |
begin |
930 |
dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy)); |
|
931 |
dx.isNegative := (sdx * sdy) < 0; |
|
932 |
exit (dx); |
|
933 |
end; |
|
934 |
end; |
|
935 |
||
936 |
CalcSlopeBelowGear := _0; |
|
6124 | 937 |
end; |
938 |
||
3038 | 939 |
procedure initModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
940 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
941 |
Count:= 0; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
942 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
943 |
|
3038 | 944 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
945 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
946 |
|
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
947 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2630
diff
changeset
|
948 |
|
4 | 949 |
end. |