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