Esempio n. 1
0
        public override ProgrammingElement Clone()
        {
            ConstraintModifier clone = new ConstraintModifier();

            CopyTo(clone);
            return(clone);
        }
Esempio n. 2
0
        public override ActionSet ComposeActionSet(Reflex reflex, GameActor gameActor)
        {
            ClearActionSet(actionSet);
            UpdateCanBlend(reflex);

            if (!reflex.targetSet.AnyAction)
            {
                return(actionSet);
            }

            // Don't wander if we are immobilized. The effect is the bot randomly turning in place, which looks broken.
            ConstraintModifier constraintMod = reflex.GetModifierByType(typeof(ConstraintModifier)) as ConstraintModifier;

            if (constraintMod != null && constraintMod.ConstraintType == ConstraintModifier.Constraints.Immobile)
            {
                // We still need to add an attractor to the movement set so that the reflex will be considered acted on.
                // TODO (****) is thre a better way to indicate this?
                actionSet.AddActionTarget(Action.AllocTargetLocationAction(reflex, gameActor.Movement.Position, autoTurn: true));
                return(actionSet);
            }

            // Check if this target has timed out.
            if (Time.GameTimeTotalSeconds > this.wanderTimeout)
            {
                this.pickNewTarget = true;
            }

            // Calculate a vector toward target in 2d.
            Vector2 wanderTarget2d = new Vector2(this.wanderTarget.X, this.wanderTarget.Y);
            Vector2 value2d        = wanderTarget2d - new Vector2(gameActor.Movement.Position.X, gameActor.Movement.Position.Y);

            float distance = Vector3.Dot(wanderDir, gameActor.Movement.Position) - wanderDist + gameActor.BoundingSphere.Radius;

            if (distance > 0)
            {
                this.pickNewTarget = true;
            }

            if (this.pickNewTarget)
            {
                this.pickNewTarget = false;
                // we need to pick a random wander target
                this.wanderTarget  = RandomTargetLocation(gameActor);
                this.wanderTimeout = Time.GameTimeTotalSeconds + maxTimeOnTarget;
            }

            actionSet.AddActionTarget(Action.AllocTargetLocationAction(reflex, wanderTarget, autoTurn: true));

            /// For debugging, uncomment this line and enable Debug: Display Line of Sight
            /// on the character in question.
            gameActor.AddLOSLine(gameActor.Movement.Position,
                                 new Vector3(wanderTarget.X, wanderTarget.Y, gameActor.Movement.Position.Z),
                                 new Vector4(0.0f, 1.0f, 0.0f, 1.0f));

            return(actionSet);
        }
Esempio n. 3
0
 protected void CopyTo(ConstraintModifier clone)
 {
     base.CopyTo(clone);
     clone.ConstraintType = this.ConstraintType;
 }