Example #1
0
        public override void Update(/* inout */ SteeringBlender steering, Actor owner, IAgentStateManager agent)
        {
            if (agent.HasProperty(AgentPropertyName.ActiveOpponent))
            {
                ZombieCombatState zcs = new ZombieCombatState();
                agent.CurrentState = zcs;
                return;
            }
            else if (agent.TimeInState.Ticks >= mDurationTicks)
            {
                ZombieWaitState zws = new ZombieWaitState(8.0f);
                agent.CurrentState = zws;
                return;
            }

            BipedControllerComponent bcc = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);
            Vector3 displacementFromHome = BepuConverter.Convert(bcc.Controller.Body.Position) - steering.Target;

            displacementFromHome.Y = 0.0f;

            float tr = agent.GetProperty <float>(AgentPropertyName.TerritoryRadius);

            steering.Weights[(int)SteeringBlender.WeightType.Seek] = Math.Min(Math.Max(displacementFromHome.Length() - tr * 0.75f, 0.0f)
                                                                              / tr, 1.0f);
            steering.Weights[(int)SteeringBlender.WeightType.Wander] = 1.0f - steering.Weights[(int)SteeringBlender.WeightType.Seek];
        }
Example #2
0
 public override void Update(SteeringBlender steering, Actor owner, IAgentStateManager agent)
 {
     if (agent.TimeInState.Ticks >= mDurationTicks)
     {
         ZombieCombatState zcs = new ZombieCombatState();
         agent.CurrentState = zcs;
     }
 }
Example #3
0
        public override void Enter(SteeringBlender steering, Actor owner, IAgentStateManager agent)
        {
            ZombieSkillSet zss = owner.GetBehaviorThatImplementsType <ZombieSkillSet>();
            //zss.RangedSkill.CurrentOperation = WeaponFunctions.Neutral;
            BipedControllerComponent bcc = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            zss.RangedSkill.UpdateInputState(false, bcc);
            zss.MeleeSkill.UpdateInputState(false, bcc);

            int   opponentId = agent.GetProperty <int>(AgentPropertyName.ActiveOpponent);
            Actor opponent   = GameResources.ActorManager.GetActorById(opponentId);
            BipedControllerComponent opponentBcc = opponent.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            BepuVec3 towardOpponent = opponentBcc.Controller.Body.Position - bcc.Controller.Body.Position;

            towardOpponent.Y = 0.0f;
            towardOpponent.Normalize();

            const float MOVE_SECS_MAX = 2.5f;
            const float MOVE_SECS_MIN = 0.5f;

            float moveRand = SlagMath.Get0To1UpperFloat(GameResources.ActorManager.Random);

            switch (mMovementType)
            {
            case MovementType.Lateral:
                BepuVec3 right = BepuVec3.Cross(towardOpponent, BepuVec3.Up);
                // Make the random symmetrical about 0.5f so that we can divide it into two equal segments for right and left.
                moveRand        = Math.Abs(moveRand - 0.5f);
                mDurationTicks  = (long)(TimeSpan.TicksPerSecond * (moveRand * 2.0f * (MOVE_SECS_MAX - MOVE_SECS_MIN) + MOVE_SECS_MIN));
                steering.Target = BepuConverter.Convert(bcc.Controller.Body.Position + (moveRand > 0.5f ? right : -right) * 100.0f);
                break;

            case MovementType.Close:
                steering.Target = BepuConverter.Convert(opponentBcc.Controller.Body.Position + towardOpponent * 100.0f);
                mDurationTicks  = (long)(TimeSpan.TicksPerSecond * (moveRand * (MOVE_SECS_MAX - MOVE_SECS_MIN) + MOVE_SECS_MIN));
                break;

            case MovementType.Retreat:
                steering.Target = BepuConverter.Convert(opponentBcc.Controller.Body.Position - towardOpponent * 100.0f);
                mDurationTicks  = (long)(TimeSpan.TicksPerSecond * (moveRand * (MOVE_SECS_MAX - MOVE_SECS_MIN) + MOVE_SECS_MIN));
                break;

            default:
                steering.Target = BepuConverter.Convert(towardOpponent * 100.0f);
                mDurationTicks  = 0;
                break;
            }

            steering.Weights[(int)SteeringBlender.WeightType.Arrive] = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Seek]   = 0.67f;
            steering.Weights[(int)SteeringBlender.WeightType.Wander] = 0.33f;
            steering.Weights[(int)SteeringBlender.WeightType.Wait]   = 0.0f;
            steering.Urgency    = 1.0f;
            steering.ForceScale = 1.0f;
        }
Example #4
0
 public Zombie(Actor owner)
     : base(owner)
 {
     mSteering        = new SteeringBlender();
     CurrentState     = null;
     TimeInState      = TimeSpan.Zero;
     mAgentProperties = new Dictionary <AgentPropertyName, object>();
     mMemory          = new Memory();
     VisionDistance   = 340.0f;
 }
Example #5
0
        public override void Enter(SteeringBlender steering, Actor owner, IAgentStateManager agent)
        {
            steering.Weights[(int)SteeringBlender.WeightType.Arrive] = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Wait]   = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Seek]   = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Wander] = 1.0f;
            steering.Urgency = 1.0f;
            IAgentStateManager asm = owner.GetBehaviorThatImplementsType <IAgentStateManager>();

            steering.Target     = asm.GetProperty <Vector3>(AgentPropertyName.HomePosition);
            steering.ForceScale = 0.5f;
        }
Example #6
0
        public override void Enter(SteeringBlender steering, Actor owner, IAgentStateManager agent)
        {
            float theta = SlagMath.Get0To1UpperFloat(GameResources.ActorManager.Random) * MathHelper.TwoPi;
            BipedControllerComponent bcc = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            steering.Weights[(int)SteeringBlender.WeightType.Arrive] = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Seek]   = 1.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Wander] = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Wait]   = 0.0f;
            steering.Urgency    = 1.0f;
            steering.Target     = BepuConverter.Convert(bcc.Controller.Body.Position) + new Vector3((float)(Math.Sin(theta)), 0.0f, (float)(Math.Cos(theta)));
            steering.ForceScale = Single.Epsilon;
        }
Example #7
0
 public override void Update(/* inout */ SteeringBlender steering, Actor owner, IAgentStateManager agent)
 {
     if (agent.HasProperty(AgentPropertyName.ActiveOpponent))
     {
         ZombieCombatState zcs = new ZombieCombatState();
         agent.CurrentState = zcs;
     }
     else if (agent.TimeInState.Ticks >= mDurationTicks)
     {
         ZombieTurnState zts = new ZombieTurnState();
         agent.CurrentState = zts;
     }
 }
Example #8
0
        public override void Enter(/* inout */ SteeringBlender steering, Actor owner, IAgentStateManager agent)
        {
            // We just want to change our facing to track our foe.
            steering.Weights[(int)SteeringBlender.WeightType.Arrive] = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Seek]   = 1.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Wander] = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Wait]   = 0.0f;
            steering.Urgency    = 1.0f;
            steering.ForceScale = 0.0001f;
            // Temporarily set the target directly ahead.
            BipedControllerComponent bcc = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            steering.Target = BepuConverter.Convert(bcc.Controller.Body.Position + bcc.Controller.HorizontalViewDirection);
        }
Example #9
0
        public override void Enter(SteeringBlender steering, Actor owner, IAgentStateManager agent)
        {
            steering.Weights[(int)SteeringBlender.WeightType.Arrive] = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Seek]   = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Wander] = 0.0f;
            steering.Weights[(int)SteeringBlender.WeightType.Wait]   = 1.0f;
            steering.Urgency = 1.0f;
            ZombieSkillSet zss = owner.GetBehaviorThatImplementsType <ZombieSkillSet>();
            //zss.RangedSkill.CurrentOperation = WeaponFunctions.Neutral;
            BipedControllerComponent bcc = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            zss.RangedSkill.UpdateInputState(false, bcc);
            zss.MeleeSkill.UpdateInputState(false, bcc);
        }
Example #10
0
        public override void Update(/* inout */ SteeringBlender steering, Actor owner, IAgentStateManager agent)
        {
            steering.ForceScale = (float)(agent.TimeInState.Ticks) / (float)mDurationTicks;

            if (agent.HasProperty(AgentPropertyName.ActiveOpponent))
            {
                ZombieCombatState zcs = new ZombieCombatState();
                agent.CurrentState = zcs;
            }
            else if (agent.TimeInState.Ticks >= mDurationTicks)
            {
                ZombieWanderState zws = new ZombieWanderState(8.0f);
                agent.CurrentState = zws;
            }
        }
Example #11
0
 public abstract void Update(/* inout */ SteeringBlender steering, Actor owner, IAgentStateManager agent);
Example #12
0
        public override void Update(/* inout */ SteeringBlender steering, Actor owner, IAgentStateManager agent)
        {
            if (!agent.HasProperty(AgentPropertyName.ActiveOpponent))
            {
                ZombieWaitState zws = new ZombieWaitState(6.0f);
                agent.CurrentState = zws;
                return;
            }

            Actor opponent = GameResources.ActorManager.GetActorById(agent.GetProperty <int>(AgentPropertyName.ActiveOpponent));
            BipedControllerComponent opponentBcc = opponent.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            steering.Target = BepuConverter.Convert(opponentBcc.Controller.Body.Position);

            BipedControllerComponent bcc = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control);

            BepuVec3       toOpponent   = opponentBcc.Controller.Body.Position - bcc.Controller.Body.Position;
            float          distance     = toOpponent.Length();
            ZombieSkillSet zss          = owner.GetBehaviorThatImplementsType <ZombieSkillSet>();
            BipedWeapon    chosenAttack = distance <= zss.MeleeSkill.EffectiveRangeMax ? zss.MeleeSkill : zss.RangedSkill;

            Matrix attackTransform = Matrix.CreateTranslation(chosenAttack.MuzzleOffset) * Matrix.CreateWorld(
                BepuConverter.Convert(bcc.Controller.Body.Position), BepuConverter.Convert(bcc.Controller.ViewDirection), Vector3.Up);

            BepuVec3 bulletPath = opponentBcc.Controller.Body.Position - BepuConverter.Convert(attackTransform.Translation);

            // If we don't have a shot, we need to specify what kind of movement we need to remedy that.
            ZombieTacticalMovementState.MovementType movement = ZombieTacticalMovementState.MovementType.None;

            if (distance < chosenAttack.EffectiveRangeMin)
            {
                movement = ZombieTacticalMovementState.MovementType.Retreat;
            }
            else if (distance > chosenAttack.EffectiveRangeMax)
            {
                movement = ZombieTacticalMovementState.MovementType.Close;
            }
            else
            {
                BepuRay       loeRay = new BepuRay(BepuConverter.Convert(attackTransform.Translation), bulletPath);
                LOSFilter     filter = new LOSFilter(bcc.Controller.Body.CollisionInformation, opponentBcc.Controller.Body.CollisionInformation);
                RayCastResult loeResult;
                GameResources.ActorManager.SimSpace.RayCast(loeRay, chosenAttack.EffectiveRangeMax * 1.5f, filter.Test, out loeResult);

                EntityCollidable otherEntityCollidable = loeResult.HitObject as EntityCollidable;
                if (otherEntityCollidable != null &&
                    otherEntityCollidable.Entity != null &&
                    otherEntityCollidable.Entity.Tag != null &&
                    (int)(otherEntityCollidable.Entity.Tag) == opponent.Id)
                {
                    toOpponent.Y = 0.0f;
                    toOpponent.Normalize();
                    float       aimTheta         = (float)(Math.Acos(MathHelper.Clamp(BepuVec3.Dot(toOpponent, bcc.Controller.ViewDirection), 0.0f, 1.0f)));
                    const float AIM_CONE_RADIANS = MathHelper.Pi / 12.0f;
                    if (aimTheta <= AIM_CONE_RADIANS)
                    {
                        // TODO: P2: Add some wander to this value:
                        bcc.WorldAim = BepuConverter.Convert(bulletPath);
                        //chosenAttack.CurrentOperation = WeaponFunctions.TriggerPulled;
                        BipedWeapon otherAttack = chosenAttack == zss.MeleeSkill ? zss.RangedSkill : zss.MeleeSkill;
                        otherAttack.UpdateInputState(false, bcc);
                        chosenAttack.UpdateInputState(true, bcc);
                        return;
                    }
                }
                else
                {
                    movement = ZombieTacticalMovementState.MovementType.Lateral;
                }
            }

            if (movement != ZombieTacticalMovementState.MovementType.None)
            {
                ZombieTacticalMovementState ztms = new ZombieTacticalMovementState(movement);
                agent.CurrentState = ztms;
            }
        }
Example #13
0
 // Make sure the steering object can produce a usable movement immediately after Enter() is called.
 public abstract void Enter(/* inout */ SteeringBlender steering, Actor owner, IAgentStateManager agent);