Exemple #1
0
        /// <summary>
        /// Give the actor hitting the other and the other a chance
        /// to respond to impact.
        /// </summary>
        /// <param name="mover"></param>
        /// <param name="hitInfo"></param>
        private void ApplyCollision(Mover mover, HitInfo hitInfo)
        {
            Debug.Assert(hitInfo.Other != null);
            if (mover.Owner.ActorHoldingThis == hitInfo.Other)
            {
                /// I'm touching what's holding me.
                return;
            }
            if (hitInfo.Other.ActorHoldingThis == mover.Owner)
            {
                /// I'm touching what I'm holding.
                return;
            }

            if (InGame.inGame.IsPickedUp(mover.Owner) && InGame.inGame.LastClonedThing == hitInfo.Other)
            {
                // Don't collide the selected object with the recent clone.
                clearLastClonedThing = false;
                return;
            }

            mover.Owner.ApplyCollisions(ref hitInfo);
            AdjustDelta(mover, hitInfo);

            GameActor other = hitInfo.Other;

            // The ordering of tests can change so we need to check if either of
            // the acotrs involved are missiles.
            if (mover.Owner is CruiseMissile || other is CruiseMissile)
            {
                // Actor has been hit by cruise missile.
                // Yes, it kind of sucks to have this here but none of the collision
                // information is stored on the Actor so we have to use it while we have it.
                // Note that we don't allow missiles to hit their launcher.
                if (other is CruiseMissile)
                {
                    MissileChassis mc = other.Chassis as MissileChassis;
                    if (mc != null && mc.Launcher != mover.Owner)
                    {
                        mc.HitTarget(mover.Owner, hitInfo);
                    }
                }
                else
                {
                    MissileChassis mc = mover.Owner.Chassis as MissileChassis;
                    if (mc != null && mc.Launcher != other)
                    {
                        mc.HitTarget(other, hitInfo);
                    }
                }
            }
            else
            {
                // Normal path that happens when two actors bump.
                hitInfo.Center = hitInfo.Struck;
                hitInfo.Normal = -hitInfo.Normal;
                hitInfo.Other  = mover.Owner;
                hitInfo.Offset = MakeOffset(hitInfo, other.CollisionRadius);
                other.ApplyCollisions(ref hitInfo);
                AdjustDelta(hitInfo.OtherMover, hitInfo);
            }
        }   // end of ApplyCollision()