author  unc0rr 
Fri, 02 May 2008 09:23:51 +0000  
changeset 900  5224ac938442 
parent 883  07a568ba44e0 
child 924  227f9fcdc2f4 
permissions  rwrr 
4  1 
(* 
2 
* Hedgewars, a wormslike game 

883  3 
* Copyright (c) 20042008 Andrey Korotaev <unC0Rr@gmail.com> 
4  4 
* 
183  5 
* This program is free software; you can redistribute it and/or modify 
6 
* it under the terms of the GNU General Public License as published by 

7 
* the Free Software Foundation; version 2 of the License 

4  8 
* 
183  9 
* This program is distributed in the hope that it will be useful, 
10 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 

11 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

12 
* GNU General Public License for more details. 

4  13 
* 
183  14 
* You should have received a copy of the GNU General Public License 
15 
* along with this program; if not, write to the Free Software 

16 
* Foundation, Inc., 59 Temple Place  Suite 330, Boston, MA 021111307, USA 

4  17 
*) 
18 

37  19 
//////////////////////////////////////////////////////////////////////////////// 
783  20 
procedure ChangeAmmo(Gear: PGear); 
21 
var slot: Longword; 

22 
caSlot, caAmmo: PLongword; 

23 
begin 

24 
slot:= Gear^.MsgParam; 

25 

26 
with PHedgehog(Gear^.Hedgehog)^ do 

27 
begin 

28 
if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0) 

29 
or ((Gear^.State and gstHHDriven) = 0) then exit; 

30 

31 
Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump or gm_Slot); 

32 

33 
if CurAmmoGear = nil then begin caSlot:= @CurSlot; caAmmo:= @CurAmmo end 

34 
else begin caSlot:= @AltSlot; caAmmo:= @AltAmmo end; 

35 

36 
if caSlot^ = slot then 

37 
begin 

38 
inc(caAmmo^); 

39 
if (caAmmo^ > cMaxSlotAmmoIndex) or (Ammo^[slot, caAmmo^].Count = 0) then caAmmo^:= 0 

40 
end else 

41 
if Ammo^[slot, 0].Count > 0 then 

42 
begin 

43 
caSlot^:= slot; 

44 
caAmmo^:= 0; 

45 
end; 

46 
end; 

47 
ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^) 

48 
end; 

49 

50 
procedure HHSetWeapon(Gear: PGear); 

51 
var t: LongInt; 

52 
weap: TAmmoType; 

53 
begin 

54 
weap:= TAmmoType(Gear^.MsgParam); 

55 
Gear^.MsgParam:= Ammoz[weap].Slot; 

56 

57 
t:= cMaxSlotAmmoIndex; 

58 

59 
Gear^.Message:= Gear^.Message and not gm_Weapon; 

60 

61 
with PHedgehog(Gear^.Hedgehog)^ do 

62 
while (Ammo^[CurSlot, CurAmmo].AmmoType <> weap) and (t >= 0) do 

63 
begin 

64 
ChangeAmmo(Gear); 

65 
dec(t) 

66 
end 

67 
end; 

68 

32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

69 
procedure Attack(Gear: PGear); 
351  70 
var xx, yy: hwFloat; 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

71 
begin 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

72 
with Gear^, 
351  73 
PHedgehog(Gear^.Hedgehog)^ do 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

74 
begin 
95  75 
if ((State and gstHHDriven) <> 0)and 
542  76 
((State and (gstAttacked or gstHHChooseTarget)) = 0)and 
836  77 
(((State and gstMoving) = 0) or ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_AttackInMove) <> 0))and 
78 
((TargetPoint.X <> NoPointX) or ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_NeedTarget) = 0)) then 

32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

79 
begin 
95  80 
State:= State or gstAttacking; 
81 
if Power = cMaxPower then Message:= Message and not gm_Attack 

351  82 
else if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Message:= Message and not gm_Attack 
95  83 
else begin 
84 
if Power = 0 then 

85 
begin 

351  86 
AttackBar:= CurrentTeam^.AttackBar; 
87 
PlaySound(sndThrowPowerUp, false) 

95  88 
end; 
89 
inc(Power) 

90 
end; 

91 
if ((Message and gm_Attack) <> 0) then exit; 

351  92 

93 
if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Power) <> 0 then 

32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

94 
begin 
282  95 
StopSound(sndThrowPowerUp); 
351  96 
PlaySound(sndThrowRelease, false); 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

97 
end; 
519  98 
xx:= SignAs(AngleSin(Angle), dX); 
900  99 
yy:= AngleCos(Angle); 
100 

101 
if ((Gear^.State and gstHHHJump) <> 0) then xx:=  xx; 

351  102 
case Ammo^[CurSlot, CurAmmo].AmmoType of 
103 
amGrenade: FollowGear:= AddGear(hwRound(X), hwRound(Y), gtAmmo_Bomb, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, Ammo^[CurSlot, CurAmmo].Timer); 

104 
amClusterBomb: FollowGear:= AddGear(hwRound(X), hwRound(Y), gtClusterBomb, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, Ammo^[CurSlot, CurAmmo].Timer); 

105 
amBazooka: FollowGear:= AddGear(hwRound(X), hwRound(Y), gtAmmo_Grenade, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, 0); 

106 
amUFO: FollowGear:= AddGear(hwRound(X), hwRound(Y), gtUFO, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, 0); 

32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

107 
amShotgun: begin 
351  108 
PlaySound(sndShotgunReload, false); 
109 
CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtShotgunShot, 0, xx * _0_5, yy * _0_5, 0); 

32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

110 
end; 
498  111 
amPickHammer: CurAmmoGear:= AddGear(hwRound(Gear^.X), hwRound(Gear^.Y) + cHHRadius, gtPickHammer, 0, _0, _0, 0); 
866  112 
amSkip: ParseCommand('/skip', true); 
351  113 
amRope: CurAmmoGear:= AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtRope, 0, xx, yy, 0); 
800  114 
amMine: begin 
115 
AddGear(hwRound(X) + hwSign(dX) * 7, hwRound(Y), gtMine, 0, SignAs(_0_02, dX), _0, 3000); 

116 
PlaySound(sndLaugh, false) 

117 
end; 

876  118 
amDEagle: CurAmmoGear:= AddGear(hwRound(X + xx * cHHRadius), hwRound(Y + yy * cHHRadius), gtDEagleShot, 0, xx * _0_5, yy * _0_5, 0); 
498  119 
amDynamite: AddGear(hwRound(X) + hwSign(dX) * 7, hwRound(Y), gtDynamite, 0, SignAs(_0_03, dX), _0, 5000); 
854  120 
amBaseballBat: CurAmmoGear:= AddGear(hwRound(X) + hwSign(dX) * 10, hwRound(Y), gtShover, 0, xx * _0_5, yy * _0_5, 0); 
498  121 
amFirePunch: CurAmmoGear:= AddGear(hwRound(X) + hwSign(dX) * 10, hwRound(Y), gtFirePunch, 0, _0, _0, 0); 
122 
amParachute: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtParachute, 0, _0, _0, 0); 

123 
amAirAttack: AddGear(Ammo^[CurSlot, CurAmmo].Pos, 0, gtAirAttack, 0, _0, _0, 0); 

124 
amMineStrike: AddGear(Ammo^[CurSlot, CurAmmo].Pos, 0, gtAirAttack, 1, _0, _0, 0); 

125 
amBlowTorch: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtBlowTorch, 0, SignAs(_0_5, dX), _0, 0); 

126 
amGirder: CurAmmoGear:= AddGear(0, 0, gtGirder, Ammo^[CurSlot, CurAmmo].Pos, _0, _0, 0); 

520  127 
amTeleport: CurAmmoGear:= AddGear(0, 0, gtTeleport, 0, _0, _0, 0); 
534  128 
amSwitch: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtSwitcher, 0, _0, _0, 0); 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

129 
end; 
829  130 

131 
uStats.AmmoUsed(Ammo^[CurSlot, CurAmmo].AmmoType); 

132 

32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

133 
Power:= 0; 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

134 
if CurAmmoGear <> nil then 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

135 
begin 
82  136 
Message:= Message or gm_Attack; 
351  137 
CurAmmoGear^.Message:= Message 
82  138 
end else begin 
351  139 
if not CurrentTeam^.ExtDriven and 
140 
((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Power) <> 0) then SendIPC('a'); 

82  141 
AfterAttack 
142 
end 

95  143 
end else Message:= Message and not gm_Attack 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

144 
end 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

145 
end; 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

146 

78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

147 
procedure AfterAttack; 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

148 
begin 
602  149 
with CurrentHedgehog^.Gear^, 
150 
CurrentHedgehog^ do 

32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

151 
begin 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

152 
Inc(AttacksNum); 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

153 
State:= State and not gstAttacking; 
614  154 
if (Ammo^[CurSlot, CurAmmo].NumPerTurn >= AttacksNum) or 
155 
((GameFlags and gfMultiWeapon) <> 0) then isInMultiShoot:= true 

32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

156 
else begin 
351  157 
TurnTimeLeft:= Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].TimeAfterTurn; 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

158 
State:= State or gstAttacked; 
602  159 
OnUsedAmmo(CurrentHedgehog^) 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

160 
end; 
95  161 
AttackBar:= 0; 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

162 
end 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

163 
end; 
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

164 

42  165 
//////////////////////////////////////////////////////////////////////////////// 
863  166 
procedure doStepHedgehogDead(Gear: PGear); 
868  167 
const frametime = 200; 
168 
timertime = frametime * 6; 

863  169 
begin 
170 
if Gear^.Timer > 1 then 

171 
begin 

172 
AllInactive:= false; 

868  173 
dec(Gear^.Timer); 
174 
if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos) 

863  175 
end else 
176 
if Gear^.Timer = 1 then 

177 
begin 

178 
Gear^.State:= Gear^.State or gstNoDamage; 

179 
doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, EXPLAutoSound); 

180 
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; 

181 
DeleteGear(Gear); 

182 
SetAllToActive 

183 
end else // Gear^.Timer = 0 

184 
begin 

185 
AllInactive:= false; 

868  186 
Gear^.Z:= cCurrHHZ; 
187 
RemoveGearFromList(Gear); 

188 
InsertGearToList(Gear); 

863  189 
PlaySound(sndByeBye, false); 
868  190 
Gear^.Pos:= 0; 
191 
Gear^.Timer:= timertime 

863  192 
end 
193 
end; 

194 

195 
//////////////////////////////////////////////////////////////////////////////// 

42  196 
procedure PickUp(HH, Gear: PGear); 
295  197 
var s: shortstring; 
198 
a: TAmmoType; 

42  199 
begin 
351  200 
Gear^.Message:= gm_Destroy; 
201 
case Gear^.Pos of 

295  202 
posCaseAmmo: begin 
351  203 
a:= TAmmoType(Gear^.State); 
553
5478386d935f
 Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
549
diff
changeset

204 
AddAmmo(PHedgehog(HH^.Hedgehog)^, a); 
836  205 
if not (PHedgehog(HH^.Hedgehog)^.Team^.ExtDriven 
206 
or (PHedgehog(HH^.Hedgehog)^.BotLevel > 0)) then 

207 
begin 

208 
s:= trammo[Ammoz[a].NameId] + '(+' + IntToStr(Ammoz[a].NumberInCase) + ')'; 

209 
AddCaption(s, PHedgehog(HH^.Hedgehog)^.Team^.Clan^.Color, capgrpAmmoinfo); 

210 
end 

295  211 
end; 
42  212 
posCaseHealth: begin 
351  213 
inc(HH^.Health, Gear^.Health); 
214 
str(Gear^.Health, s); 

295  215 
s:= '+' + s; 
549  216 
AddCaption(s, PHedgehog(HH^.Hedgehog)^.Team^.Clan^.Color, capgrpAmmoinfo); 
351  217 
RenderHealth(PHedgehog(HH^.Hedgehog)^); 
218 
RecountTeamHealth(PHedgehog(HH^.Hedgehog)^.Team) 

42  219 
end; 
435  220 
end 
42  221 
end; 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset

222 

4  223 
const StepTicks: LongWord = 0; 
224 

302  225 
procedure HedgehogStep(Gear: PGear); 
371  226 
var PrevdX: LongInt; 
302  227 
begin 
542  228 
if ((Gear^.State and (gstAttacking or gstMoving)) = 0) then 
4  229 
begin 
408  230 
if isCursorVisible then 
231 
with PHedgehog(Gear^.Hedgehog)^ do 

232 
with Ammo^[CurSlot, CurAmmo] do 

233 
begin 

542  234 
if (Gear^.Message and gm_Left ) <> 0 then 
408  235 
Pos:= (Pos + Ammoz[AmmoType].PosCount  1) mod Ammoz[AmmoType].PosCount 
236 
else 

542  237 
if (Gear^.Message and gm_Right ) <> 0 then 
408  238 
Pos:= (Pos + 1) mod Ammoz[AmmoType].PosCount 
239 
else exit; 

423  240 
StepTicks:= 200; 
408  241 
exit 
242 
end; 

505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

243 

351  244 
if ((Gear^.Message and gm_LJump ) <> 0) then 
4  245 
begin 
542  246 
Gear^.Message:= Gear^.Message and not gm_LJump; 
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

247 
DeleteCI(Gear); 
68  248 
if not TestCollisionYwithGear(Gear, 1) then 
498  249 
if not TestCollisionXwithXYShift(Gear, _0, 2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y  _2 else 
250 
if not TestCollisionXwithXYShift(Gear, _0, 1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y  _1; 

351  251 
if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) 
68  252 
or TestCollisionYwithGear(Gear, 1)) then 
4  253 
begin 
351  254 
Gear^.dY:= _0_15; 
498  255 
Gear^.dX:= SignAs(_0_15, Gear^.dX); 
542  256 
Gear^.State:= Gear^.State or gstMoving or gstHHJumping; 
799  257 
PlaySound(sndJump1, false); 
4  258 
exit 
259 
end; 

260 
end; 

505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

261 

351  262 
if ((Gear^.Message and gm_HJump ) <> 0) then 
4  263 
begin 
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

264 
DeleteCI(Gear); 
542  265 
Gear^.Message:= Gear^.Message and not gm_HJump; 
855
8842c71d16bf
 Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset

266 

8842c71d16bf
 Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset

267 
Gear^.dY:= _0_2; 
8842c71d16bf
 Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset

268 
SetLittle(Gear^.dX); 
8842c71d16bf
 Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset

269 
Gear^.State:= Gear^.State or gstMoving or gstHHJumping; 
8842c71d16bf
 Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset

270 
PlaySound(sndJump3, false); 
8842c71d16bf
 Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset

271 
exit 
4  272 
end; 
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

273 

351  274 
PrevdX:= hwSign(Gear^.dX); 
275 
if (Gear^.Message and gm_Left )<>0 then Gear^.dX:= cLittle else 

276 
if (Gear^.Message and gm_Right )<>0 then Gear^.dX:= cLittle else exit; 

505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

277 

74  278 
StepTicks:= cHHStepTicks; 
610  279 
if PrevdX <> hwSign(Gear^.dX) then 
280 
begin 

281 
FollowGear:= Gear; 

282 
exit 

283 
end; 

284 
DeleteCI(Gear); // must be after exit!! (see previous line) 

838  285 

351  286 
PHedgehog(Gear^.Hedgehog)^.visStepPos:= (PHedgehog(Gear^.Hedgehog)^.visStepPos + 1) and 7; 
287 
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then 

4  288 
begin 
498  289 
if not (TestCollisionXwithXYShift(Gear, _0, 6, hwSign(Gear^.dX)) 
290 
or TestCollisionYwithGear(Gear, 1)) then Gear^.Y:= Gear^.Y  _1; 

291 
if not (TestCollisionXwithXYShift(Gear, _0, 5, hwSign(Gear^.dX)) 

292 
or TestCollisionYwithGear(Gear, 1)) then Gear^.Y:= Gear^.Y  _1; 

293 
if not (TestCollisionXwithXYShift(Gear, _0, 4, hwSign(Gear^.dX)) 

294 
or TestCollisionYwithGear(Gear, 1)) then Gear^.Y:= Gear^.Y  _1; 

295 
if not (TestCollisionXwithXYShift(Gear, _0, 3, hwSign(Gear^.dX)) 

296 
or TestCollisionYwithGear(Gear, 1)) then Gear^.Y:= Gear^.Y  _1; 

297 
if not (TestCollisionXwithXYShift(Gear, _0, 2, hwSign(Gear^.dX)) 

298 
or TestCollisionYwithGear(Gear, 1)) then Gear^.Y:= Gear^.Y  _1; 

299 
if not (TestCollisionXwithXYShift(Gear, _0, 1, hwSign(Gear^.dX)) 

300 
or TestCollisionYwithGear(Gear, 1)) then Gear^.Y:= Gear^.Y  _1; 

4  301 
end; 
498  302 
if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then Gear^.X:= Gear^.X + SignAs(_1, Gear^.dX); 
300  303 

62  304 
SetAllHHToActive; 
37  305 

68  306 
if not TestCollisionYwithGear(Gear, 1) then 
4  307 
begin 
498  308 
Gear^.Y:= Gear^.Y + _1; 
68  309 
if not TestCollisionYwithGear(Gear, 1) then 
4  310 
begin 
498  311 
Gear^.Y:= Gear^.Y + _1; 
68  312 
if not TestCollisionYwithGear(Gear, 1) then 
4  313 
begin 
498  314 
Gear^.Y:= Gear^.Y + _1; 
68  315 
if not TestCollisionYwithGear(Gear, 1) then 
4  316 
begin 
498  317 
Gear^.Y:= Gear^.Y + _1; 
68  318 
if not TestCollisionYwithGear(Gear, 1) then 
4  319 
begin 
498  320 
Gear^.Y:= Gear^.Y + _1; 
68  321 
if not TestCollisionYwithGear(Gear, 1) then 
4  322 
begin 
498  323 
Gear^.Y:= Gear^.Y + _1; 
68  324 
if not TestCollisionYwithGear(Gear, 1) then 
4  325 
begin 
498  326 
Gear^.Y:= Gear^.Y  _6; 
327 
Gear^.dY:= _0; 

542  328 
Gear^.State:= Gear^.State or gstMoving; 
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

329 
exit 
4  330 
end; 
331 
end 

332 
end 

333 
end 

334 
end 

335 
end 

505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

336 
end; 
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

337 
AddGearCI(Gear) 
4  338 
end 
339 
end; 

340 

303
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset

341 
procedure HedgehogChAngle(Gear: PGear); 
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset

342 
begin 
542  343 
if ((Gear^.State and gstMoving) = 0) then 
351  344 
if (Gear^.Message and gm_Up )<>0 then if Gear^.Angle > CurMinAngle then dec(Gear^.Angle) 
303
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset

345 
else else 
351  346 
if (Gear^.Message and gm_Down )<>0 then if Gear^.Angle < CurMaxAngle then inc(Gear^.Angle); 
303
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset

347 
end; 
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset

348 

302  349 
procedure doStepHedgehog(Gear: PGear); forward; 
350 
//////////////////////////////////////////////////////////////////////////////// 

538  351 
procedure doStepHedgehogMoving(Gear: PGear); 
545  352 
var isFalling: boolean; 
538  353 
begin 
855
8842c71d16bf
 Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset

354 
isFalling:= (Gear^.dY.isNegative) or not TestCollisionYKick(Gear, 1); 
542  355 
if isFalling then 
538  356 
begin 
357 
if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, 1) then Gear^.dY:= _0; 

542  358 
Gear^.State:= Gear^.State or gstMoving; 
538  359 
Gear^.dY:= Gear^.dY + cGravity 
360 
end else 

361 
begin 

362 
if ((hwAbs(Gear^.dX) + hwAbs(Gear^.dY)) < _0_55) 

363 
and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX); 

364 

540  365 
if not Gear^.dY.isNegative then 
366 
begin 

367 
CheckHHDamage(Gear); 

790
a6f442173822
Make high jump behaviour like in worms (back somersault)
unc0rr
parents:
783
diff
changeset

368 

a6f442173822
Make high jump behaviour like in worms (back somersault)
unc0rr
parents:
783
diff
changeset

369 
if ((Gear^.State and gstHHHJump) <> 0) and 
a6f442173822
Make high jump behaviour like in worms (back somersault)
unc0rr
parents:
783
diff
changeset

370 
(Gear^.dX.QWordValue < _0_02.QWordValue) then Gear^.dX.isNegative:= not Gear^.dX.isNegative; // landing after high jump 
a6f442173822
Make high jump behaviour like in worms (back somersault)
unc0rr
parents:
783
diff
changeset

371 

542  372 
Gear^.State:= Gear^.State and not (gstHHJumping or gstHHHJump); 
540  373 
Gear^.dY:= _0; 
374 
end else Gear^.dY:= Gear^.dY + cGravity; 

538  375 

376 
if ((Gear^.State and gstMoving) <> 0) then Gear^.dX:= Gear^.dX * Gear^.Friction 

377 
end; 

378 

379 
if (Gear^.State <> 0) then DeleteCI(Gear); 

783  380 

538  381 
if (Gear^.State and gstMoving) <> 0 then 
382 
if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then 

542  383 
if not isFalling then 
538  384 
if hwAbs(Gear^.dX) > _0_01 then 
385 
if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX))  Gear^.dX, 1, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_96; Gear^.Y:= Gear^.Y  _1 end else 

386 
if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX))  Gear^.dX, 2, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_93; Gear^.Y:= Gear^.Y  _2 end else 

387 
if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX))  Gear^.dX, 3, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_9 ; Gear^.Y:= Gear^.Y  _3 end else 

388 
if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX))  Gear^.dX, 4, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_87; Gear^.Y:= Gear^.Y  _4 end else 

389 
if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX))  Gear^.dX, 5, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_84; Gear^.Y:= Gear^.Y  _5 end else 

390 
if hwAbs(Gear^.dX) > _0_02 then Gear^.dX:= Gear^.Elasticity * Gear^.dX 

391 
else begin 

392 
Gear^.State:= Gear^.State and not gstMoving; 

393 
SetLittle(Gear^.dX) 

394 
end 

395 
else begin 

396 
Gear^.State:= Gear^.State and not gstMoving; 

397 
SetLittle(Gear^.dX) 

398 
end 

399 
else if hwAbs(Gear^.dX) > cLittle then Gear^.dX:= Gear^.Elasticity * Gear^.dX 

400 
else SetLittle(Gear^.dX); 

401 

542  402 
if (not isFalling) and 
538  403 
(hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then 
404 
begin 

405 
Gear^.State:= Gear^.State and not gstMoving; 

406 
SetLittle(Gear^.dX); 

407 
Gear^.dY:= _0 

408 
end else Gear^.State:= Gear^.State or gstMoving; 

409 

410 
if (Gear^.State and gstMoving) <> 0 then 

411 
begin 

412 
Gear^.State:= Gear^.State and not gstAnimation; 

413 
Gear^.X:= Gear^.X + Gear^.dX; 

414 
Gear^.Y:= Gear^.Y + Gear^.dY; 

415 
if (not Gear^.dY.isNegative) and 

416 
(not TestCollisionYKick(Gear, 1)) and 

417 
TestCollisionYwithXYShift(Gear, 0, 1, 1) then 

418 
begin 

419 
CheckHHDamage(Gear); 

420 
Gear^.dY:= _0; 

421 
Gear^.Y:= Gear^.Y + _1 

422 
end; 

423 
CheckGearDrowning(Gear) 

424 
end 

425 
end; 

426 

302  427 
procedure doStepHedgehogDriven(Gear: PGear); 
428 
var t: PGear; 

429 
begin 

558
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

430 
if not isInMultiShoot then 
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

431 
AllInactive:= false 
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

432 
else 
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

433 
Gear^.Message:= 0; 
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

434 

351  435 
if (TurnTimeLeft = 0) or (Gear^.Damage > 0) then 
302  436 
begin 
437 
TurnTimeLeft:= 0; 

351  438 
Gear^.State:= Gear^.State and not gstHHDriven; 
439 
if Gear^.Damage > 0 then 

424  440 
Gear^.State:= Gear^.State and not (gstHHJumping or gstHHHJump); 
302  441 
exit 
442 
end; 

542  443 

836  444 
if ((Gear^.State and gstMoving) <> 0) 
445 
or (StepTicks = cHHStepTicks) 

835
6f567934cc44
Automatically use parachute when vertical speed is high enough
unc0rr
parents:
829
diff
changeset

446 
or (CurAmmoGear <> nil) then // we're moving 
836  447 
begin 
839  448 
with PHedgehog(Gear^.Hedgehog)^ do 
449 
if (CurAmmoGear = nil) 

450 
and (Gear^.dY > _0_39) 

451 
and (Ammo^[CurSlot, CurAmmo].AmmoType = amParachute) then Gear^.Message:= Gear^.Message or gm_Attack; 

836  452 
// check for case with ammo 
453 
t:= CheckGearNear(Gear, gtCase, 36, 36); 

454 
if t <> nil then 

455 
PickUp(Gear, t) 

855
8842c71d16bf
 Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset

456 
end; 
302  457 

458 
if CurAmmoGear <> nil then 

459 
begin 

351  460 
CurAmmoGear^.Message:= Gear^.Message; 
302  461 
exit 
462 
end; 

463 

783  464 
if ((Gear^.Message and gm_Slot) <> 0) then ChangeAmmo(Gear); 
465 

466 
if ((Gear^.Message and gm_Weapon) <> 0) then HHSetWeapon(Gear); 

467 

351  468 
if ((Gear^.Message and gm_Attack) <> 0) or 
542  469 
((Gear^.State and gstAttacking) <> 0) then Attack(Gear); 
302  470 

542  471 
if (Gear^.State and gstMoving) <> 0 then 
302  472 
begin 
424  473 
if ((Gear^.Message and gm_HJump) <> 0) and 
474 
((Gear^.State and gstHHJumping) <> 0) and 

475 
((Gear^.State and gstHHHJump) = 0) then 

476 
if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < _0_02) then 

302  477 
begin 
542  478 
Gear^.State:= Gear^.State or gstHHHJump or gstMoving; 
351  479 
Gear^.dY:= _0_25; 
799  480 
Gear^.dX:= SignAs(_0_02, Gear^.dX); 
481 
PlaySound(sndJump2, false) 

302  482 
end; 
351  483 
Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump); 
538  484 

485 
if ((Gear^.State and gstHHJumping) <> 0) and 

486 
TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX); 

487 

488 
doStepHedgehogMoving(Gear); 

542  489 

490 
if (Gear^.State and gstMoving) = 0 then 

302  491 
begin 
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
498
diff
changeset

492 
AddGearCI(Gear); 
542  493 
StepTicks:= 350 
302  494 
end; 
495 
exit 

538  496 
end; 
302  497 

558
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

498 
if not isInMultiShoot then 
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

499 
begin 
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

500 
HedgehogChAngle(Gear); 
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

501 
if StepTicks > 0 then dec(StepTicks); 
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

502 
if (StepTicks = 0) then HedgehogStep(Gear) 
b2b840eeb10a
Fix bug when hedgehog moves not right after it is kicked
unc0rr
parents:
553
diff
changeset

503 
end 
302  504 
end; 
505 

4  506 
//////////////////////////////////////////////////////////////////////////////// 
507 
procedure doStepHedgehogFree(Gear: PGear); 

511  508 
var prevState: Longword; 
4  509 
begin 
511  510 
prevState:= Gear^.State; 
4  511 

538  512 
doStepHedgehogMoving(Gear); 
4  513 

865  514 
if (Gear^.State and gstMoving) <> 0 then 
515 
begin 

516 
AllInactive:= false; 

517 
exit 

518 
end; 

4  519 

863  520 
if (Gear^.Health = 0) then 
521 
begin 

868  522 
if PrvInactive then 
864  523 
begin 
524 
Gear^.Timer:= 0; 

868  525 
Gear^.State:= Gear^.State or gstHHDeath; 
526 
Gear^.doStep:= @doStepHedgehogDead; 

527 
PrvInactive:= false; 

528 
AllInactive:= false 

864  529 
end; 
863  530 
exit 
531 
end; 

4  532 

863  533 
if ((Gear^.State and gstAnimation) = 0) and 
534 
(prevState <> Gear^.State) then 

535 
begin 

536 
Gear^.State:= gstAnimation; 

537 
Gear^.Timer:= 150 

538 
end else 

539 
begin 

540 
if Gear^.Timer = 0 then 

541 
begin 

542 
Gear^.State:= 0; 

543 
Gear^.Active:= false; 

544 
AddGearCI(Gear); 

545 
exit 

546 
end else dec(Gear^.Timer) 

547 
end; 

548 

549 
AllInactive:= false 

4  550 
end; 
551 

552 
//////////////////////////////////////////////////////////////////////////////// 

553 
procedure doStepHedgehog(Gear: PGear); 

554 
begin 

351  555 
if (Gear^.Message and gm_Destroy) <> 0 then 
4  556 
begin 
557 
DeleteGear(Gear); 

558 
exit 

559 
end; 

351  560 
if (Gear^.State and gstHHDriven) = 0 then doStepHedgehogFree(Gear) 
511  561 
else doStepHedgehogDriven(Gear) 
4  562 
end; 