public override ActionSet ComposeActionSet(Reflex reflex, GameActor gameActor)
        {
            ClearActionSet(actionSet);
            UpdateCanBlend(reflex);

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

            if (reflex.targetSet.Count > 0)
            {
                // falloff == Avoid, !falloff == Away
                if (falloff)
                {
                    // Avoid.
                    // We want to avoid all actors so we need to loop over the full set.
                    foreach (SensorTarget target in reflex.targetSet)
                    {
                        GameActor targetActor = target.GameThing as GameActor;
                        if (targetActor != null)
                        {
                            actionSet.AddAction(Action.AllocAvoidAction(reflex, targetActor));
                        }
                    }
                }
                else
                {
                    // Away.
                    Vector3 actorPos = gameActor.Movement.Position;
                    Vector3 dir      = Vector3.Zero; // The direction we want to flee.

                    // We want to move away from all actors so we need to loop over the full set.
                    foreach (SensorTarget target in reflex.targetSet)
                    {
                        GameActor targetActor = target.GameThing as GameActor;

                        if (targetActor != null)
                        {
                            Vector3 fromTarget = actorPos - targetActor.Movement.Position;
                            float   dist       = fromTarget.Length();
                            // Normalize fromTarget then divide again by dist.  This gives us a linear
                            // falloff of strength based on distance so that a target that is twice as
                            // close will have twice the weight on the flee direction.
                            dir += fromTarget / dist / dist;
                        }
                    }

                    bool apply = reflex.ModifyHeading(gameActor, Modifier.ReferenceFrames.World, ref dir);

                    if (apply)
                    {
                        dir.Normalize();
                        actionSet.AddAction(Action.AllocVelocityAction(reflex, dir, autoTurn: true));
                    }
                } // end else if falloff
            }     // end if targetSet not empty.

            return(actionSet);
        }
Пример #2
0
        public override void Fixup(Reflex reflex)
        {
            base.Fixup(reflex);

            radiusScale = 1.0f;
            for (int imod = 0; imod < reflex.Modifiers.Count; ++imod)
            {
                CircleDistanceModifier cdMod = reflex.Modifiers[imod] as CircleDistanceModifier;
                if (cdMod != null)
                {
                    radiusScale *= cdMod.radiusScale;
                }
            }

            Task task = reflex.Task;

            controlZ = true;
            for (int iref = 0; iref < task.reflexes.Count; ++iref)
            {
                Reflex otherReflex = task.reflexes[iref] as Reflex;
                if ((otherReflex != null) && (otherReflex != reflex))
                {
                    Selector otherSelector = otherReflex.Selector;
                    if ((otherSelector is MoveDownSelector) ||
                        (otherSelector is MoveUpDownSelector) ||
                        (otherSelector is MoveUpSelector) ||
                        (otherSelector is FollowWaypointsSelector))
                    {
                        controlZ = false;
                        break;
                    }
                }
            }
        }
Пример #3
0
        }   // end of Free()

        /// <summary>
        /// Old-style action.  Should be replaced?  TargetDirectionAction?
        ///
        /// We still use this for stuff like shooting.
        ///
        /// WHEN See Apple DO Shoot
        ///     gameThing is the nearest apple
        ///     direction is the direction to shoot
        ///     distance is distance to apple
        ///
        /// WHEN GamePad AButton DO Shoot
        ///     gameThing is null
        ///     direction is forward
        ///     distance is 1
        ///
        /// </summary>
        /// <param name="distance"></param>
        /// <param name="direction"></param>
        /// <param name="gameThing"></param>
        /// <param name="reflex"></param>
        /// <param name="canBlend"></param>
        /// <param name="specialInstruction"></param>
        /// <returns></returns>
        static public Attractor AllocAttractor(float distance,
                                               Vector3 direction,
                                               GameThing gameThing,
                                               Reflex reflex,
                                               bool canBlend = false,
                                               BaseAction.SpecialInstruction specialInstruction = BaseAction.SpecialInstruction.None)
        {
            Attractor attractor;

            // Recycle an attractor if possible.  If not, create a new one.
            if (AttractorFreeList.Count > 0)
            {
                attractor = AttractorFreeList[AttractorFreeList.Count - 1];
                AttractorFreeList.RemoveAt(AttractorFreeList.Count - 1);
            }
            else
            {
                attractor = new Attractor();
            }

            // Fill in the data.
            attractor.Init(distance, direction, gameThing, reflex, canBlend, specialInstruction);

            return(attractor);
        }   // end of AllocAttractor()
        public override ActionSet ComposeActionSet(Reflex reflex, GameActor gameActor)
        {
            ClearActionSet(actionSet);
            UpdateCanBlend(reflex);

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

            SensorTarget target = reflex.targetSet.Nearest;

            if (target != null)
            {
                // Calculate a vector toward target.
                Vector3 value = target.Direction;

                bool apply = reflex.ModifyHeading(gameActor, Modifier.ReferenceFrames.World, ref value);

                if (apply)
                {
                    actionSet.AddAction(Action.AllocTargetLocationAction(reflex, target.Position, autoTurn: true));
                }
            }

            return(actionSet);
        }
Пример #5
0
        /// <summary>
        /// See if the gameActor
        /// </summary>
        /// <param name="gameActor"></param>
        /// <param name="reflex"></param>
        /// <returns></returns>
        public override void ComposeSensorTargetSet(GameActor gameActor, Reflex reflex)
        {
            // Unlike water or terrain sensors, we don't filter on specific path types
            // but we can filter on path color.
            bool match = gameActor.Chassis.OverPath && !gameActor.Chassis.Jumping;

            if (match)
            {
                List <Filter> filters = reflex.Filters;

                for (int indexFilter = 0; indexFilter < filters.Count; indexFilter++)
                {
                    Filter filter = filters[indexFilter] as Filter;
                    ClassificationFilter classificationFilter = filter as ClassificationFilter;
                    if (classificationFilter != null && classificationFilter.classification.Color != gameActor.Chassis.PathColor)
                    {
                        match = false;
                    }
                }
            }

            if (reflex.Data.GetFilterCountByType(typeof(NotFilter)) > 0)
            {
                match = !match;
            }

            reflex.targetSet.Action = match;
        }   // end of ComposeSensorTargetSet()
Пример #6
0
        public override void ComposeSensorTargetSet(GameActor gameActor, Reflex reflex)
        {
            List <Filter> filters = reflex.Filters;

            if (this.playerIndex == PlayerId.Dynamic)
            {
                PlayerId dynamicPlayerId = PlayerId.All;
                // check filters for the player
                for (int indexFilter = 0; indexFilter < filters.Count; indexFilter++)
                {
                    PlayerFilter filter = filters[indexFilter] as PlayerFilter;
                    object       param;
                    if (filter != null && filter.MatchAction(reflex, out param))
                    {
                        dynamicPlayerId = (PlayerId)param;
                        break;
                    }
                }
                reflex.targetSet.Param = dynamicPlayerId;
            }
            else
            {
                reflex.targetSet.Param = this.playerIndex;
            }

            reflex.targetSet.Action = TestObjectSet(reflex);
        }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            param = null;
            bool match = false;

            int curr = reflex.Task.Brain.GameActor.HitPoints;
            int prev = reflex.Task.Brain.GameActor.PrevHitPoints;

            switch (op)
            {
            case HealthCompare.Is:
                //match = (curr == triggerValue) && (prev != triggerValue);
                match = (curr == triggerValue);
                break;

            case HealthCompare.Above:
                //match = (curr > triggerValue) && (prev <= triggerValue);
                match = (curr > triggerValue);
                break;

            case HealthCompare.Below:
                //match = (curr < triggerValue) && (prev >= triggerValue);
                match = (curr < triggerValue);
                break;
            }

            return(match);
        }
        public static IObservable <TProp> WhenAny <TProp>(this IObservablePropertyChanged @this, Expression <Func <TProp> > prop)
        {
            var name = Reflex.PropertyName(prop);
            var func = prop.CompileFast();

            return(@this.PropertyChangedObservable.Where(s => s == name).Select(_ => func()));
        }
        /// <summary>
        /// Look at whether something else is controlling vertical height, in which
        /// case we become strictly 2D.
        /// </summary>
        /// <param name="myReflex"></param>
        public override void Fixup(Reflex myReflex)
        {
            base.Fixup(myReflex);

            /// Look over the reflex. If anything else wants to control vertical motion,
            /// then we won't.
            Task task = myReflex.Task;

            controlZ = true;
            for (int iref = 0; iref < task.reflexes.Count; ++iref)
            {
                Reflex otherReflex = task.reflexes[iref] as Reflex;
                if ((otherReflex != null) && (otherReflex != myReflex))
                {
                    Selector otherSelector = otherReflex.Selector;
                    if ((otherSelector is MoveDownSelector) ||
                        (otherSelector is MoveUpDownSelector) ||
                        (otherSelector is MoveUpSelector))
                    {
                        controlZ = false;
                        break;
                    }
                }
            }
        }
Пример #10
0
        public override void Reset(Reflex reflex)
        {
            frame = 0;
            scores.Clear();

            base.Reset(reflex);
        }
Пример #11
0
        public override bool MatchAction(Reflex reflex, out object param)
        {
            param = null; // doesn't effect match action

            bool match = false;

            if (reflex.targetSet.Nearest != null)
            {
                match = reflex.targetSet.Nearest.GameThing == reflex.Task.GameActor;
            }

            if (reflex.Data.Sensor is TouchSensor)
            {
                match |= reflex.TouchActor == reflex.Task.GameActor;
            }
            else
            {
                match |= reflex.MouseActor == reflex.Task.GameActor;
            }

            if (!match)
            {
                reflex.MousePosition = null;
                reflex.TouchPosition = null;
            }

            return(match);
        }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            param = null;
            bool match = false;

            if (reflex.targetSet != null && reflex.targetSet.Param != null)
            {
                GameScoredSensor      sensor = reflex.Sensor as GameScoredSensor;
                Classification.Colors color  = (Classification.Colors)reflex.targetSet.Param;

                int curr = 0, prev;

                Scoreboard.Score score = sensor.GetScore(color);

                if (score != null)
                {
                    curr = score.Curr;
                    prev = score.Prev;

                    // If the score changed and jumped across or landed on the trigger score
                    if ((prev != curr) &&
                        ((prev < scoreTriggerValue && curr >= scoreTriggerValue) ||
                         (prev > scoreTriggerValue && curr <= scoreTriggerValue)))
                    {
                        match = true;
                    }
                }
            }
            return(match);
        }
Пример #13
0
        // helper method
        protected bool TestObjectSet(Reflex reflex)
        {
            List <Filter> filters = reflex.Filters;

            bool match = true;

            for (int indexFilter = 0; indexFilter < filters.Count; indexFilter++)
            {
                Filter filter = filters[indexFilter] as Filter;
                object param;
                if (!filter.MatchAction(reflex, out param))
                {
                    match = false;
                    break;
                }
                if (param != null)
                {
                    reflex.targetSet.Param = param;
                }
            }

            // After everything is done, apply the not filter,
            // if any, to negate the result.
            if (reflex.Data.FilterExists("filter.not"))
            {
                match = !match;
            }

            match = PostProcessAction(match, reflex);

            return(match);
        } // end TestObjectSet()
        public override ActionSet ComposeActionSet(Reflex reflex, GameActor gameActor)
        {
            ClearActionSet(actionSet);
            UpdateCanBlend(reflex);

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

            if (reflex.targetSet.Count > 0)
            {
                if (reflex.targetSet.CullToFurthest(gameActor, BlockedFrom))
                {
                    // the targetSet is in order by distance
                    SensorTarget target = reflex.targetSet.Furthest;

                    // calculate a vector toward target
                    Vector3 value = target.Direction;

                    bool apply = reflex.ModifyHeading(gameActor, Modifier.ReferenceFrames.World, ref value);

                    if (apply)
                    {
                        // radius should be from object
                        actionSet.AddAttractor(AllocAttractor(target.Range, value, target.GameThing, reflex), 0.4f);
                    }
                }
            }

            return(actionSet);
        }
Пример #15
0
        public void InsertReflexAfter(Reflex reflexRef, Reflex reflexNew)
        {
            int indexInsert = reflexes.IndexOf(reflexRef);

            indexInsert++;
            reflexes.Insert(indexInsert, reflexNew);
        }
Пример #16
0
        public override void ComposeSensorTargetSet(GameActor gameActor, Reflex reflex)
        {
            List <Filter> filters = reflex.Filters;

            _typeList.Clear();

            /// We never fire until we have valid data to base a trigger on.

            if (TerrainMaterial.IsValid(OverrideSenseMaterial, false, false))
            {
                _typeList.AddType(OverrideSenseMaterial);

                reflex.targetSet.Param = _typeList;

                reflex.targetSet.Action = TestObjectSet(reflex);
            }
            else if (gameActor.Chassis.TerrainDataValid)
            {
                gameActor.Chassis.GetTerrainMaterials(_typeList);

                reflex.targetSet.Param = _typeList;

                reflex.targetSet.Action = TestObjectSet(reflex);
            }
            else
            {
                reflex.targetSet.Action = false;
            }
        }   // end of ComposeSensorTargetSet()
Пример #17
0
 public override void Reset(Reflex reflex)
 {
     Fired      = false;
     applyCount = 0;
     fireCount  = 0;
     base.Reset(reflex);
 }
Пример #18
0
        public Neuron(ProcessorContainer pc)
        {
            if (pc == null)
            {
                throw new ArgumentNullException();
            }
            if (pc.Count > char.MaxValue)
            {
                throw new ArgumentException();
            }

            _procNames = new Dictionary <char, char>(pc.Count);
            ProcessorHandler ph = new ProcessorHandler();
            StringBuilder    sb = new StringBuilder(pc.Count);

            for (char k = char.MinValue; k < pc.Count; ++k)
            {
                if (!ph.Add(ProcessorHandler.RenameProcessor(pc[k], new string(k, 1))))
                {
                    continue;
                }
                char c = char.ToUpper(pc[k].Tag[0]);
                _procNames[c] = k;
                sb.Append(c);
            }

            _processorContainer = ph.Processors;
            _workReflex         = new Reflex(_processorContainer);
            _stringQuery        = sb.ToString();
        }
        public override ActionSet ComposeActionSet(Reflex reflex, GameActor gameActor)
        {
            ClearActionSet(actionSet);
            UpdateCanBlend(reflex);

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

            Vector2 valueStick = Vector2.Zero;

            if (reflex.targetSet.Param != null && reflex.targetSet.Param is Vector2)
            {
                // Read the gamepad input
                valueStick   = (Vector2)reflex.targetSet.Param;
                valueStick.X = 0;
            }
            else
            {
                valueStick = new Vector2(0, 1.0f);
            }

            actionSet.AddAction(Action.AllocVerticalRateAction(reflex, valueStick.Y));

            return(actionSet);
        }
Пример #20
0
 /// <summary>
 /// Look and see if the terrains touuched (cached in reflex.Param) match the terrain type we're looking for (cached
 /// in Reflex.MaterialType).
 /// </summary>
 /// <param name="reflex"></param>
 /// <param name="targetSet"></param>
 /// <param name="sensorCategory"></param>
 /// <param name="param"></param>
 /// <returns></returns>
 public override bool MatchAction(Reflex reflex, out object param)
 {
     if (reflex.targetSet.Param is Terrain.TypeList)
     {
         Terrain.TypeList typeList = reflex.targetSet.Param as Terrain.TypeList;
         if (typeList != null)
         {
             if (typeList.HasType(reflex.MaterialType))
             {
                 param = reflex.MaterialType;
                 return(true);
             }
         }
     }
     else if (reflex.targetSet.Param is int)
     {
         ushort type = (ushort)reflex.targetSet.Param;
         if (type == reflex.MaterialType)
         {
             param = reflex.MaterialType;
             return(true);
         }
     }
     param = null;
     return(false);
 }
Пример #21
0
        private new bool TestObjectSet(Reflex reflex)
        {
            List <Filter> filters = reflex.Filters;

            bool   match = true;
            object param;

            for (int indexFilter = 0; indexFilter < filters.Count; indexFilter++)
            {
                Filter filter = filters[indexFilter] as Filter;
                // skip player filter
                if (!(filter is PlayerFilter))
                {
                    if (!filter.MatchAction(reflex, out param))
                    {
                        match = false;
                        break;
                    }
                    if (param != null)
                    {
                        reflex.targetSet.Param = param;
                    }
                }
            }

            if (reflex.Data.GetFilterCountByType(typeof(NotFilter)) > 0)
            {
                match = !match;
            }

            match = PostProcessAction(match, reflex);

            return(match);
        }
        public override void ComposeSensorTargetSet(GameActor gameActor, Reflex reflex)
        {
            List <Filter> filters = reflex.Filters;

            SensorTargetSet.Enumerator senseSetIter = (SensorTargetSet.Enumerator)gameActor.GivenSet.GetEnumerator();
            senseSetIter.Reset();
            while (senseSetIter.MoveNext())
            {
                SensorTarget target = (SensorTarget)senseSetIter.Current;

                bool match = true;
                for (int indexFilter = 0; indexFilter < filters.Count; indexFilter++)
                {
                    Filter filter = filters[indexFilter] as Filter;
                    if (!filter.MatchTarget(reflex, target))
                    {
                        match = false;
                        break;
                    }
                }
                if (match)
                {
                    reflex.targetSet.Add(target);
                }
            }

            reflex.targetSet.Action = TestObjectSet(reflex);
        }
Пример #23
0
        public override bool MatchAction(Reflex reflex, out object param)
        {
            bool match = (reflex.targetSet == null || reflex.targetSet.Count == 0);

            param = null;
            return(match);
        }
Пример #24
0
        public override bool MatchAction(Reflex reflex, out object param)
        {
            param = null;

            bool match = Compare(reflex.targetSet.Count);

            return(match);
        }
Пример #25
0
 /// <summary>
 /// Remove all invalid elements from reflexes
 /// </summary>
 internal void Validate()
 {
     for (int i = 0; i < reflexes.Count; ++i)
     {
         Reflex reflex = reflexes[i] as Reflex;
         reflex.Validate();
     }
 }
Пример #26
0
        public Neuron(ProcessorContainer pc)
        {
            ProcessorHandler ph = FromProcessorContainer(pc);

            _workReflex = new Reflex(ph.Processors);
            _procNames  = ph.ToHashSet();
            _stringOriginalUniqueQuery = ph.ToString();
        }
Пример #27
0
        }   // end of FixUp()

        public void Reset()
        {
            for (int indexReflex = 0; indexReflex < reflexes.Count; indexReflex++)
            {
                Reflex reflex = reflexes[indexReflex] as Reflex;
                reflex.Reset();
            }
        }
        public override ActionSet ComposeActionSet(Reflex reflex, GameActor gameActor)
        {
            ClearActionSet(actionSet);
            UpdateCanBlend(reflex);

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

            Vector3 target        = Vector3.Zero;
            bool    approachPoint = true;

            if (!this.used)
            {
                approachPoint = FindClosestMatchingWaypointSetTarget(reflex, gameActor, out target);
            }

            if (approachPoint)
            {
                gameActor.followPathState.FollowTarget = target;

                // Calc 2d dist to target.
                Vector3 delta = gameActor.Movement.Position - target;
                delta.Z = 0;    // Force 2d.

                // Test if we are close enough that we reached our follow target.
                if (delta.Length() < accuracy)
                {
                    if (ClosestNodeIsTarget(gameActor))
                    {
                        bool validTarget = ReachedWaypoint(gameActor, ref target);
                        if (validTarget)
                        {
                            gameActor.followPathState.FollowTarget = target;
                        }
                        else
                        {
                            // No valid target so just bail.
                            return(actionSet);
                        }
                    }
                }

                target = gameActor.followPathState.FollowTarget;

                // If not controlling Z, we want movement to be 2D so set
                // the target Z value to match the actor's current Z value.
                if (!controlZ)
                {
                    target.Z = gameActor.Movement.Altitude;
                }

                actionSet.AddAction(Action.AllocTargetLocationAction(reflex, target, autoTurn: true));
            }

            return(actionSet);
        }   // end of ComposeActionSet()
Пример #29
0
        private new bool TestObjectSet(Reflex reflex)
        {
            bool match = true;

            if (reflex.Data.GetFilterCountByType(typeof(KeyBoardKeyFilter)) > 0)
            {
                List <Filter> filters = reflex.Filters;

                object param;
                for (int indexFilter = 0; indexFilter < filters.Count; indexFilter++)
                {
                    Filter filter = filters[indexFilter] as Filter;
                    if (!filter.MatchAction(reflex, out param))
                    {
                        match = false;
                        break;
                    }
                    if (param != null)
                    {
                        reflex.targetSet.Param = param;
                    }
                }
            }
            else if (reflex.Actuator is MovementActuator || reflex.Actuator is TurnActuator)
            {
                match = false;

                // TODO All this boxing can't be a good thing.  Try to refactor it out.

                // For the built in keyboard args we need to blend their input.  So, start with
                // 0,0 and add in each active key.  Finally, normalize the result.
                reflex.targetSet.Param = Vector2.Zero;
                object param;
                for (int indexFilter = 0; indexFilter < movementBuiltins.Count; indexFilter++)
                {
                    Filter filter = movementBuiltins[indexFilter] as Filter;
                    if (filter.MatchAction(reflex, out param))
                    {
                        match = true;
                        if (param != null)
                        {
                            reflex.targetSet.Param = (Vector2)(reflex.targetSet.Param) + (Vector2)param;
                        }
                    }
                }

                ((Vector2)reflex.targetSet.Param).Normalize();
            }

            if (reflex.Data.GetFilterCountByType(typeof(NotFilter)) > 0)
            {
                match = !match;
            }

            match = PostProcessAction(match, reflex);

            return(match);
        }
        public override bool MatchAction(Reflex reflex, out object param)
        {
            param = null;
            // Previously the default here was false.  But when I removed the hiddendefault comparison
            // this started causing timers with random times to fail.  HiddenDefault is evil and
            // should never exist.
            // At a deeper level there's something not quite right with the architecture if it doesn't
            // allow scores to be used as timer inputs without adding hidden tiles.  Need to understand
            // this better.
            bool match = true;

            if (reflex.targetSet != null && reflex.targetSet.Param != null)
            {
                GameScoredSensorResult sensorResult = (GameScoredSensorResult)reflex.targetSet.Param;

                Debug.Assert(sensorResult != null, "Why would this ever be null?");

                // Just looking to see if that bucket has changed.
                if (sensorResult.TestingForChange)
                {
                    match = sensorResult.ScoreChanged;
                }
                else
                {
                    // Actually doing a comparison.
                    switch (op)
                    {
                    case ScoreCompare.Is:
                        match = sensorResult.LeftValue == sensorResult.RightValue;
                        break;

                    case ScoreCompare.Above:
                        match = sensorResult.LeftValue > sensorResult.RightValue;
                        break;

                    case ScoreCompare.Below:
                        match = sensorResult.LeftValue < sensorResult.RightValue;
                        break;

                    case ScoreCompare.GTEQ:
                        match = sensorResult.LeftValue >= sensorResult.RightValue;
                        break;

                    case ScoreCompare.LTEQ:
                        match = sensorResult.LeftValue <= sensorResult.RightValue;
                        break;

                    case ScoreCompare.NotIs:
                        match = sensorResult.LeftValue != sensorResult.RightValue;
                        break;
                    }
                }
            }   // if not null target set

            return(match);
        }   // end of MatchAction()
Пример #31
0
    //-----------------------------------------------------
    public SceneModel()
    {
        m_cameraData = new List<Hlips>();
        m_lightData  = new List<Ahibp>();
        m_shadowData = new List<Ahibp>();

        m_redoCam = new List<Hlips>();
        m_redoLight = new List<Ahibp>();
        m_redoShadow = new List<Ahibp>();

        m_reflex = new Reflex(6,0);
        m_mode2D = new M2D();
        //m_originalState = new Hlips(0,0,0,0,0);
    }