public void Clear() { SpeedModifier = 1.0f; Loft = 0.0f; Strength = 0.0f; CreatableId = Guid.Empty; Pronoun = PronounModifier.Pronouns.None; Reset = ResetModifier.Resets.None; Color = Classification.Colors.None; Pitch = PitchModifier.PitchDirections.None; Turn = TurnModifier.TurnDirections.None; Make = MakeObjectModifier.MakeObjects.None; Item = ObjectModifier.ModifierObjects.None; TaskId = TaskModifier.TaskIds.SIZEOF; Direction = Programming.Directions.None; Facial = Face.FaceState.NotApplicable; ExpressEmitter = ExpressModifier.Emitters.NotApplicable; Verb = GameThing.Verbs.None; MissileBehavior = MissileChassis.BehaviorFlags.TerrainFollowing; Constraints = ConstraintModifier.Constraints.None; SoundUpid = String.Empty; Points = 0; PlayerIndex = GamePadSensor.PlayerId.Dynamic; ScoreBucket = ScoreBucket.NotApplicable; }
} // end of Setup() /// <summary> /// c'tor for use when targetting a point in space rather than an object. /// </summary> /// <param name="position"></param> /// <param name="targetPosition"></param> /// <param name="launcher"></param> /// <param name="verbPayload"></param> /// <param name="trackingMode"></param> /// <param name="color"></param> /// <returns></returns> static public CruiseMissile Create( Vector3 position, // Starting position. Vector3 targetPosition, // Location we're trying to hit. GameActor launcher, // Actor that launched this missile. float initialRotation, // GameThing.Verbs verbPayload, int damage, MissileChassis.BehaviorFlags behavior, Classification.Colors color, float desiredSpeed, float missileLifetime, bool wantSmoke) { CruiseMissile cm = NextAvailable(); cm.Setup( position, launcher, initialRotation, verbPayload, damage, behavior, color, desiredSpeed, wantSmoke); //Vector3 forward = Vector3.Normalize(targetPosition - position); //Vector3 side = Vector3.Cross(Vector3.UnitZ, forward); //if (side.LengthSquared() < 0.01f) //{ // side = Vector3.Cross(Vector3.UnitY, forward); //} //side.Normalize(); //Vector3 up = Vector3.Normalize(Vector3.Cross(forward, side)); //Matrix l2w = Matrix.Identity; //l2w.Right = forward; //l2w.Up = up; //l2w.Forward = side; //l2w.Translation = position; //cm.Movement.LocalMatrix = l2w; MissileChassis missileChassis = cm.Chassis as MissileChassis; Vector3 direction = targetPosition - launcher.WorldCollisionCenter; Vector3 delta = Vector3.Normalize(direction); float desiredPitch = (float)(Math.Atan2(delta.Z, new Vector2(delta.X, delta.Y).Length())); missileChassis.PitchAngle = desiredPitch; missileChassis.DeathTime = Time.GameTimeTotalSeconds + missileLifetime * 1.1f; missileChassis.TargetPosition = position + delta * desiredSpeed * missileLifetime * 10f; missileChassis.TargetObject = null; return(cm); } // end of CruiseMissile Create
/// <summary> /// Fire a missile from the given shooter's position at the target position. /// </summary> /// <param name="shooter"></param> /// <param name="targetPos"></param> /// <param name="color"></param> /// <param name="verbPayload"></param> /// <returns></returns> public bool Fire(GameActor shooter, Vector3 targetPos, Classification.Colors color, GameThing.Verbs verbPayload, int damage) { if (numActiveBleeps < kMaxBleeps) { float speed = shooter.BlipSpeed; float time2Live = shooter.BlipRange / speed; Bleep bleep = new Bleep(); bleep.Position = shooter.WorldGlowPosition; bleep.StartHeight = bleep.Position.Z; bleep.Position.Z = shooter.WorldCollisionCenter.Z; bleep.Velocity = Vector3.Normalize(targetPos - bleep.Position) * speed; float vdotv = Vector3.Dot(bleep.Velocity, shooter.Movement.Velocity); if (vdotv > 0) { /// If the bullet is moving the same direction as the shooter, /// add in the shooter's speed in the bullet's direction. /// This will only speed up the bullet, not change it's firing /// direction. vdotv /= bleep.Velocity.LengthSquared(); bleep.Velocity += bleep.Velocity * vdotv; } bleep.Life = bleep.TTL = time2Live; bleep.VerbPayload = verbPayload; bleep.Damage = damage; Vector4 color4 = Classification.ColorVector4(color); /// Brighten up the color a bit. color4.X = MyMath.SmoothStep(0.0f, 1.0f, color4.X); color4.Y = MyMath.SmoothStep(0.0f, 1.0f, color4.Y); color4.Z = MyMath.SmoothStep(0.0f, 1.0f, color4.Z); bleep.Color = new Color(color4); bleep.TTTerraHit = CheckTerrainHit(bleep, speed); if (shooter.ActiveBleeps.Bleeps.Count == 0) { Shooters.Add(shooter); } shooter.ActiveBleeps.Bleeps.Add(bleep); // Increment the number of active bleeps. Without this, on the // current frame we can end up shooting enough new bleeps to // exceed the max. ++numActiveBleeps; return(true); } return(false); }
public override void InitDefaults() { base.InitDefaults(); // values here copied from member initializers above. maxPitchRate = DefaultMaxPitchRate; actualSpeed = 0f; desiredSpeed = DefaultDesiredSpeed; damage = 0; checkedForLand = false; verbPayload = GameThing.Verbs.Vaporize; turnAngle = 0f; rollAngle = 0f; pitchAngle = 0f; }
protected override bool IDoDirectObjectVerb(GameThing.Verbs verb, GameThing subject, Effector effector) { bool supports = false; switch (verb) { case GameThing.Verbs.Open: supports = DoOpen(); break; case GameThing.Verbs.Close: supports = DoClose(); break; default: supports = base.IDoDirectObjectVerb(verb, subject, effector); break; } return(supports); }
} // end of CruiseMissile Create /// <summary> /// c'tor to use when shooting at a particular object /// </summary> /// <param name="position"></param> /// <param name="targetPosition"></param> /// <param name="targetThing"></param> /// <param name="launcher"></param> /// <param name="verbPayload"></param> /// <param name="trackingMode"></param> /// <param name="color"></param> /// <returns></returns> static public CruiseMissile Create( Vector3 position, // Starting position. GameThing targetThing, // Object we're trying to hit. GameActor launcher, // Actor that launched this missile. float initialRotation, // GameThing.Verbs verbPayload, int damage, MissileChassis.BehaviorFlags behavior, Classification.Colors color, float desiredSpeed, float missileLifetime, bool wantSmoke) { CruiseMissile cm = NextAvailable(); cm.Setup( position, launcher, initialRotation, verbPayload, damage, behavior, color, desiredSpeed, wantSmoke); MissileChassis missileChassis = cm.Chassis as MissileChassis; // Set initial speed taking into account the velocity of the launcher. Vector3 missileVelocity = new Vector3((float)Math.Cos(initialRotation), (float)Math.Sin(initialRotation), 0); float dot = Vector3.Dot(missileVelocity, launcher.Movement.Velocity); missileChassis.Speed = Math.Max(desiredSpeed, dot); missileChassis.DeathTime = Time.GameTimeTotalSeconds + missileLifetime; missileChassis.TargetPosition = targetThing.WorldCollisionCenter; missileChassis.TargetObject = targetThing; return(cm); } // end of CruiseMissile Create
private void Setup(Vector3 position, // Starting position. GameActor launcher, // Actor that launched this missile. float initialRotation, GameThing.Verbs verbPayload, int damage, MissileChassis.BehaviorFlags behavior, Classification.Colors color, float desiredSpeed, bool wantSmoke) { smokeEnabled = wantSmoke; // Or, we could change the sound to something other than the rumble. if (!smokeEnabled) { XmlActorParams.IdleSoundName = null; } MissileChassis missileChassis = Chassis as MissileChassis; missileChassis.Missile = this; missileChassis.Launcher = launcher; missileChassis.VerbPayload = verbPayload; missileChassis.Damage = damage; missileChassis.Behavior = behavior; missileChassis.Rotation = initialRotation; missileChassis.DesiredSpeed = desiredSpeed; Mass = 10.0f; Movement.Position = position; // Calculate initial missile speed. float initialSpeed = desiredSpeed; Vector3 gunVel = launcher.Movement.Velocity; Vector3 shotVel = new Vector3((float)Math.Cos(initialRotation), (float)Math.Sin(initialRotation), 0f) * initialSpeed; if (gunVel.X != 0 || gunVel.Y != 0) { // Add in some of the launcher's velocity. Missile will // gradually adjust its speed to its desired velocity. Vector3 gunVelNorm = Vector3.Normalize(gunVel); Vector3 shotVelNorm = Vector3.Normalize(shotVel); float dot = Vector3.Dot(gunVelNorm, shotVelNorm); Vector3 proj = gunVel * dot; initialSpeed = proj.Length() * MyMath.Direction(dot); } // Don't allow initial speed to be negative because it looks odd. missileChassis.Speed = Math.Max(desiredSpeed, initialSpeed); classification.Color = color; InitSmokeEmitter(Classification.ColorVector4(classification.Color)); InitMuzzleFlash(Classification.ColorVector4(classification.Color), 2.0f, 8.0f); missileChassis.IgnoreGlassWalls = true; missileChassis.Feelers.Clear(); // Don't want missiles to hit glass walls. // Register for collisions. //InGame.inGame.RegisterCollide(this); } // end of Setup()