7175 //////////////////////////////////////////////////////////////////////////////// |
7175 //////////////////////////////////////////////////////////////////////////////// |
7176 |
7176 |
7177 procedure doStepSentry(Gear: PGear); |
7177 procedure doStepSentry(Gear: PGear); |
7178 var HHGear, bullet: PGear; |
7178 var HHGear, bullet: PGear; |
7179 distX, distY, invDistance: HwFloat; |
7179 distX, distY, invDistance: HwFloat; |
|
7180 const sentry_Idle = 0; |
|
7181 sentry_Walking = 1; |
|
7182 sentry_Aiming = 2; |
|
7183 sentry_Attacking = 3; |
|
7184 sentry_Reloading = 4; |
7180 begin |
7185 begin |
7181 HHGear:= nil; |
7186 HHGear:= nil; |
7182 |
7187 |
7183 if CheckGearDrowning(Gear) then |
7188 if CheckGearDrowning(Gear) then |
7184 exit; |
7189 exit; |
7185 |
7190 |
7186 if (TestCollisionYKick(Gear, 1) = 0) then |
7191 if TestCollisionYKick(Gear, 1) = 0 then |
7187 begin |
7192 begin |
7188 doStepFallingGear(Gear); |
7193 doStepFallingGear(Gear); |
|
7194 Gear^.Timer := 0; |
|
7195 Gear^.Tag := sentry_Idle; |
7189 exit; |
7196 exit; |
7190 end; |
7197 end; |
7191 |
7198 |
7192 if (Gear^.Timer > 0) then |
7199 if Gear^.Timer > 0 then dec(Gear^.Timer); |
7193 dec(Gear^.Timer); |
7200 |
7194 |
7201 if Gear^.Timer = 0 then |
7195 if (Gear^.Timer = 0) then |
|
7196 begin |
7202 begin |
7197 if Gear^.Tag <> 0 then |
7203 if Gear^.Tag = sentry_Idle then |
7198 begin |
7204 begin |
7199 Gear^.Tag := 0; |
7205 Gear^.Tag := sentry_Walking; |
|
7206 Gear^.Timer := 1000 + GetRandom(3000); |
|
7207 Gear^.dX.isNegative := GetRandom(2) = 1; |
|
7208 if TestCollisionX(Gear, hwSign(Gear^.dX)) <> 0 then |
|
7209 Gear^.dX.isNegative := not Gear^.dX.isNegative; |
|
7210 end |
|
7211 else if Gear^.Tag in [sentry_Walking, sentry_Reloading] then |
|
7212 begin |
|
7213 Gear^.Tag := sentry_Idle; |
7200 Gear^.Timer := 1000 + GetRandom(1000); |
7214 Gear^.Timer := 1000 + GetRandom(1000); |
7201 end |
7215 end |
7202 else |
7216 else if Gear^.Tag = sentry_Aiming then |
7203 begin |
7217 begin |
7204 Gear^.Tag := GetRandom(2) * 2 - 1; |
7218 Gear^.WDTimer := 5 + GetRandom(3); |
7205 Gear^.Timer := 1000 + GetRandom(3000); |
7219 Gear^.Tag := sentry_Attacking; |
7206 Gear^.dX.isNegative := Gear^.Tag < 0; |
7220 Gear^.Timer := 200; |
7207 if TestCollisionX(Gear, 1) <> 0 then |
7221 end |
7208 begin |
7222 else if Gear^.Tag = sentry_Attacking then |
7209 Gear^.Tag := not Gear^.Tag; |
7223 begin |
7210 Gear^.dX.isNegative := not Gear^.dX.isNegative; |
7224 distX := int2hwFloat(Gear^.Target.X) - Gear^.X; |
|
7225 distY := int2hwFloat(Gear^.Target.Y) - Gear^.Y; |
|
7226 invDistance := _1 / Distance(distX, distY); |
|
7227 distX := distX * invDistance; |
|
7228 distY := distY * invDistance; |
|
7229 |
|
7230 bullet := AddGear( |
|
7231 hwRound(Gear^.X), hwRound(Gear^.Y), |
|
7232 gtDEagleShot, 0, |
|
7233 distX, distY, 0); |
|
7234 |
|
7235 bullet^.PortalCounter := 1; |
|
7236 bullet^.Elasticity := Gear^.X; |
|
7237 bullet^.Friction := Gear^.Y; |
|
7238 bullet^.Data := Pointer(Gear); |
|
7239 |
|
7240 CreateShellForGear(Gear, Gear^.WDTimer and 1); |
|
7241 |
|
7242 if Gear^.WDTimer = 0 then |
|
7243 begin |
|
7244 Gear^.Target.X := 0; |
|
7245 Gear^.Target.Y := 0; |
|
7246 Gear^.Tag := sentry_Reloading; |
|
7247 Gear^.Timer := 6000 + GetRandom(2000); |
7211 end |
7248 end |
7212 end |
7249 else |
|
7250 begin |
|
7251 dec(Gear^.WDTimer); |
|
7252 Gear^.Timer := 200; |
|
7253 end |
|
7254 end; |
7213 end; |
7255 end; |
7214 |
7256 |
7215 if (Gear^.Tag <> 0) and ((GameTicks and $1F) = 0) then |
7257 if (Gear^.Tag = sentry_Walking) and ((GameTicks and $1F) = 0) then |
7216 begin |
7258 begin |
7217 MakeHedgehogsStep(Gear); |
7259 MakeHedgehogsStep(Gear); |
7218 if TestCollisionX(Gear, 1) <> 0 then |
7260 if TestCollisionX(Gear, hwSign(Gear^.dX)) <> 0 then |
7219 Gear^.Timer := 0 |
7261 Gear^.Timer := 0 |
7220 end; |
7262 end; |
7221 |
7263 |
7222 if ((GameTicks and $FF) = 0) |
7264 if ((GameTicks and $FF) = 0) |
|
7265 and (Gear^.Tag in [sentry_Idle, sentry_Walking]) |
7223 and (CurrentHedgehog <> nil) |
7266 and (CurrentHedgehog <> nil) |
7224 and (CurrentHedgehog^.Gear <> nil) |
7267 and (CurrentHedgehog^.Gear <> nil) |
7225 and ((CurrentHedgehog^.Gear^.State and (gstMoving or gstHHDriven)) = (gstMoving or gstHHDriven)) then |
7268 and ((CurrentHedgehog^.Gear^.State and (gstMoving or gstHHDriven)) = (gstMoving or gstHHDriven)) then |
7226 begin |
7269 begin |
7227 HHGear := CurrentHedgehog^.Gear; |
7270 HHGear := CurrentHedgehog^.Gear; |
7228 distX := HHGear^.X - Gear^.X; |
7271 distX := HHGear^.X - Gear^.X; |
7229 distY := HHGear^.Y - Gear^.Y; |
7272 distY := HHGear^.Y - Gear^.Y; |
7230 if (distX.isNegative = Gear^.dX.isNegative) |
7273 if (distX.isNegative = Gear^.dX.isNegative) |
7231 and (distX.Round > 32) |
7274 and (distX.Round > 32) |
7232 and (distX.Round < 1000) |
7275 and (distX.Round < 500) |
7233 and (hwAbs(distY) < hwAbs(distX)) then |
7276 and (hwAbs(distY) < hwAbs(distX)) then |
7234 begin |
7277 begin |
7235 invDistance := _1 / Distance(distX, distY); |
7278 Gear^.Target.X := hwRound(HHGear^.X); |
7236 |
7279 Gear^.Target.Y := hwRound(HHGear^.Y); |
7237 distX := distX * invDistance; |
7280 Gear^.Tag := sentry_Aiming; |
7238 distY := distY * invDistance; |
7281 Gear^.Timer := 1800 + GetRandom(400); |
7239 |
|
7240 bullet := AddGear( |
|
7241 hwRound(Gear^.X), hwRound(Gear^.Y), |
|
7242 gtDEagleShot, 0, |
|
7243 distX, |
|
7244 distY, |
|
7245 0); |
|
7246 |
|
7247 bullet^.PortalCounter := 1; |
|
7248 bullet^.Elasticity := Gear^.X; |
|
7249 bullet^.Friction := Gear^.Y; |
|
7250 bullet^.Data := Pointer(Gear); |
|
7251 inc(Gear^.WDTimer); |
|
7252 |
|
7253 CreateShellForGear(Gear, Gear^.WDTimer and 1); |
|
7254 end |
7282 end |
7255 end |
7283 end |
7256 end; |
7284 end; |
7257 |
7285 |
7258 end. |
7286 end. |