Esempio n. 1
0
        public override void ThingUpdate(GameActor gameActor, GameThing gameThing, Vector3 direction, float range)
        {
            CruiseMissile missile = gameThing as CruiseMissile;

            // don't test missiles we have launched
            if ((missile == null || missile.Launcher != gameActor) &&
                (gameThing.ActorHoldingThis != gameActor))
            {
                float hearingRange = gameActor.HearingRange;

                if (range < hearingRange)
                {
                    senseSet.Add(gameThing, direction, range);
                }
            }
            if (senseSet.Count == 0)
            {
                senseSet.Clear();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Call update methods on Sensors for each GameActor.
        /// </summary>
        private void UpdateGameThingSensors(BrainCategories category)
        {
            if (sensorCount > 0)
            {
                for (int i = 0; i < reflexes.Count; ++i)
                {
                    if (reflexes[i] == null)
                    {
                        continue;
                    }

                    Sensor sensor = (reflexes[i] as Reflex).Sensor;

                    if (sensor == null)
                    {
                        continue;
                    }

                    if (category == BrainCategories.NotSpecified || sensor.Categories.Get((int)category))
                    {
                        sensor.StartUpdate(GameActor);
                    }
                }

                if (haveThingUpdateSensors)
                {
                    Vector3 actorCenter = Vector3.Transform(GameActor.BoundingSphere.Center, GameActor.Movement.LocalMatrix);
                    for (int indexGameThing = 0; indexGameThing < brain.GameThings.Count; indexGameThing++)
                    {
                        // There a number of objects we don't want to consider to testing...
                        GameThing gameThing = brain.GameThings[indexGameThing] as GameThing;

                        if (gameThing.Ignored)
                        {
                            continue;
                        }

                        /*
                         * // Handled lower down now...
                         * // Don't test self.
                         * if (this.GameActor == gameThing)
                         *  continue;
                         */

                        // Don't test dead things.  You know you can't see dead things.
                        if (!gameThing.IsAlive())
                        {
                            continue;
                        }

                        /*
                         * // Handled lower down now...
                         * // Also, don't sense things that are dead in another way (knocked-out).
                         * if (gameThing.CurrentState == GameThing.State.Dead)
                         *  continue;
                         */

                        // Don't test things we're holding.
                        if (gameThing == this.GameActor.ThingBeingHeldByThisActor)
                        {
                            continue;
                        }

                        // Don't test missiles we've fired.
                        CruiseMissile missile = gameThing as CruiseMissile;
                        if (missile != null && missile.Launcher == this.GameActor)
                        {
                            continue;
                        }

                        Vector3 thingCenter = Vector3.Transform(gameThing.BoundingSphere.Center, gameThing.Movement.LocalMatrix);

                        Vector3 direction = thingCenter - actorCenter;

                        float range = direction.Length();
                        if (range > 0.0f)
                        {
                            direction *= 1.0f / range; // Normalize.
                        }

                        for (int i = 0; i < reflexes.Count; ++i)
                        {
                            if (reflexes[i] == null)
                            {
                                continue;
                            }

                            Sensor sensor = (reflexes[i] as Reflex).Sensor;

                            if (sensor == null)
                            {
                                continue;
                            }

                            // Handle strangeness of me filter.  Basically this is adds an implicit "not me" filter
                            // except in the case where the user explicitely added the "me " filter.
                            Reflex reflex = (Reflex)reflexes[i];
                            if (reflex.hasMeFilter)
                            {
                                if (GameActor != gameThing)
                                {
                                    continue;
                                }
                                direction = GameActor.Movement.Facing;
                            }
                            else
                            {
                                if (GameActor == gameThing)
                                {
                                    continue;
                                }
                            }

                            // Ignore dead things unless explicitly looking for them.
                            if (reflex.hasDeadFilter)
                            {
                                // We're looking for dead things so continue if not dead.
                                if (gameThing.CurrentState != GameThing.State.Dead)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                // We're not looking for dead things so ignore them.
                                if (gameThing.CurrentState == GameThing.State.Dead)
                                {
                                    continue;
                                }
                            }

                            // Ignore squashed things unless explicitly looking for them.
                            if (reflex.hasSquashedFilter)
                            {
                                // We're looking for dead things so continue if not dead.
                                if (gameThing.CurrentState != GameThing.State.Squashed)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                // We're not looking for squashed things so ignore them.
                                if (gameThing.CurrentState == GameThing.State.Squashed)
                                {
                                    continue;
                                }
                            }

                            // Ignore missiles unless explicitly looking for them.
                            if (reflex.hasMissileFilter)
                            {
                                // We're looking for missiles, continue otherwise
                                if (!(gameThing is CruiseMissile))
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                // We're not looking for missiles so ignore them.
                                if (gameThing is CruiseMissile)
                                {
                                    continue;
                                }
                            }

                            if (sensor.WantThingUpdate && (category == BrainCategories.NotSpecified || sensor.Categories.Get((int)category)))
                            {
                                if (gameThing.CanBeSensed())
                                {
                                    sensor.ThingUpdate(GameActor, gameThing, direction, range);
                                }
                            }
                        }
                    } // foreach gamething
                }     // if haveThingUpdateSensors

                for (int i = 0; i < reflexes.Count; ++i)
                {
                    if (reflexes[i] == null)
                    {
                        continue;
                    }

                    Sensor sensor = reflexes[i].Sensor;

                    if (sensor == null)
                    {
                        continue;
                    }

                    if (category == BrainCategories.NotSpecified || sensor.Categories.Get((int)category))
                    {
                        sensor.FinishUpdate(GameActor);
                    }
                }
            } // if sensorCount > 0
        }