コード例 #1
0
 public static bool CanMobSeeProp(
     NavMesh navMesh,
     Mob mob,
     EntityProp prop)
 {
     return(CanMobSeePoint(navMesh, mob, prop.GetPosition()));
 }
コード例 #2
0
        // -- Prop List Helpers --
        private static List <EntityProp> PropListsRefresh <TEnvironmentEntity>(
            Mob ownerMob,
            List <TEnvironmentEntity> currentEntities,
            List <EntityProp> oldProps)
            where TEnvironmentEntity : IEnvironmentEntity
        {
            List <EntityProp> updatedProps = new List <EntityProp>();

            // Mark/Add existing props and Create new props
            foreach (IEnvironmentEntity entity in currentEntities)
            {
                int        existingPropIndex = oldProps.FindIndex(prop => prop.target_object_id == entity.ID);
                EntityProp existingProp      = (existingPropIndex != -1) ? oldProps[existingPropIndex] : null;

                if (existingProp != null)
                {
                    updatedProps.Add(existingProp);
                }
                else
                {
                    updatedProps.Add(new EntityProp(ownerMob, entity));
                }
            }

            return(updatedProps);
        }
コード例 #3
0
        private static float SaliencePreferLowerHealth(
            Mob ownerMob,
            EntityProp prop)
        {
            float maxHealth = ownerMob.MobType.MaxHealth; // judge based off of my max energy

            return(Math.Max(Math.Min(1.0f - ((float)prop.health / maxHealth), 1.0f), 0.0f));
        }
コード例 #4
0
        private static float SaliencePreferLowerEnergy(
            Mob ownerMob,
            EntityProp prop)
        {
            float maxEnergy = ownerMob.MobType.MaxEnergy; // judge based off of my max energy

            return(Math.Max(Math.Min(1.0f - ((float)prop.energy / maxEnergy), 1.0f), 0.0f));
        }
コード例 #5
0
        private static float SaliencePreferCloserDistance(
            Mob ownerMob,
            EntityProp prop)
        {
            double maxDistance = ownerMob.MobType.VisionCone.distance;

            // judge based off of my max vision distance
            return((float)Math.Max(Math.Min(1.0 - (prop.distance / maxDistance), 1.0), 0.0));
        }
コード例 #6
0
        // -- Prop Salience Helpers --
        private static float ComputePropSalience(
            SalienceEvaluatorSet evaluatorSet,
            Mob ownerMob,
            EntityProp prop)
        {
            MobType mobType          = ownerMob.MobType;
            float   netSalienceScore = 0.0f;

            // Any prop that we don't know about automatically gets a score of zero
            if (prop.propStatus != EntityProp.ePropStatus.unacknowledged)
            {
                float weightTotal = 0.0f;

                // Distance
                {
                    float distanceScore = evaluatorSet.DistanceEvaluator(ownerMob, prop);

                    netSalienceScore += distanceScore * (float)mobType.Perception.saliance_distance_weight;
                    weightTotal      += (float)mobType.Perception.saliance_distance_weight;
                }

                // Energy
                {
                    float energyScore = evaluatorSet.EnergyEvaluator(ownerMob, prop);

                    netSalienceScore += energyScore * (float)mobType.Perception.saliance_energy_weight;
                    weightTotal      += (float)mobType.Perception.saliance_energy_weight;
                }

                // Health
                {
                    float healthScore = evaluatorSet.HealthEvaluator(ownerMob, prop);

                    netSalienceScore += healthScore * (float)mobType.Perception.saliance_health_weight;
                    weightTotal      += (float)mobType.Perception.saliance_health_weight;
                }

                // Status
                {
                    float statusScore = evaluatorSet.StatusEvaluator(ownerMob, prop);

                    netSalienceScore += statusScore * (float)mobType.Perception.saliance_status_weight;
                    weightTotal      += (float)mobType.Perception.saliance_status_weight;
                }

                if (weightTotal > 0.0f)
                {
                    netSalienceScore /= weightTotal;
                }
            }

            return(netSalienceScore);
        }
コード例 #7
0
        // -- Prop Target Helpers --
        public static int RefreshSalienceTarget(
            List <EntityProp> props)
        {
            int    bestTargetPropIndex = -1;
            double bestSalianceScore   = -1.0;

            for (int propIndex = 0; propIndex < props.Count; propIndex++)
            {
                EntityProp prop = props[propIndex];

                if (prop.propStatus != EntityProp.ePropStatus.unacknowledged &&
                    prop.salience > bestSalianceScore)
                {
                    bestTargetPropIndex = propIndex;
                    bestSalianceScore   = prop.salience;
                }
            }

            return(bestTargetPropIndex);
        }
コード例 #8
0
        private static float SaliencePreferMoreVisibleStatus(
            Mob ownerMob,
            EntityProp prop)
        {
            float statusScore = 0.0f;

            switch (prop.propStatus)
            {
            case EntityProp.ePropStatus.acknowledged:
                statusScore = 1.0f;
                break;

            case EntityProp.ePropStatus.assumed:
                statusScore = 0.75f;
                break;

            case EntityProp.ePropStatus.orphaned:
                statusScore = 0.5f;
                break;
            }

            return(statusScore);
        }
コード例 #9
0
        // -- Prop Status Helpers --
        static private void UpdatePropStatus(
            Mob mob,
            EntityProp prop)
        {
            MobType mobType = mob.MobType;

            EntityProp.ePropStatus newStatus = prop.propStatus;

            bool canSee       = prop.visibilityFlags.Test(EntityProp.ePropVisibilityFlags.canSee);
            bool caughtGlipse = prop.visibilityFlags.Test(EntityProp.ePropVisibilityFlags.caughtGlimpse);
            bool stationary   = prop.visibilityFlags.Test(EntityProp.ePropVisibilityFlags.stationary);

            switch (prop.propStatus)
            {
            case EntityProp.ePropStatus.unacknowledged:
                if (canSee)
                {
                    newStatus = EntityProp.ePropStatus.acknowledged;
                }
                else
                {
                    if (caughtGlipse)
                    {
                        newStatus = stationary ? EntityProp.ePropStatus.assumed : EntityProp.ePropStatus.unacknowledged;
                    }
                    else
                    {
                        newStatus = EntityProp.ePropStatus.unacknowledged;
                    }
                }
                break;

            case EntityProp.ePropStatus.orphaned:
                if (canSee)
                {
                    newStatus = EntityProp.ePropStatus.acknowledged;
                }
                else
                {
                    if (caughtGlipse)
                    {
                        // Still orphaned, but reset the orphan timeout
                        newStatus = EntityProp.ePropStatus.orphaned;
                        prop.propStatusTurnCount = 0;
                    }
                    else
                    {
                        if (prop.propStatusTurnCount >= mobType.Perception.orphan_turn_timeout)
                        {
                            newStatus = EntityProp.ePropStatus.unacknowledged;
                        }
                        else
                        {
                            newStatus = EntityProp.ePropStatus.orphaned;
                        }
                    }
                }
                break;

            case EntityProp.ePropStatus.assumed:
                // Don't care about catching glimpse because we assume we know where the prop is
                newStatus = canSee ? EntityProp.ePropStatus.acknowledged : EntityProp.ePropStatus.assumed;
                break;

            case EntityProp.ePropStatus.acknowledged:
                if (canSee)
                {
                    newStatus = EntityProp.ePropStatus.acknowledged;
                }
                else
                {
                    // Don't care about catching glimpse because we're going to orphaned or assumed regardless
                    newStatus = stationary ? EntityProp.ePropStatus.assumed : EntityProp.ePropStatus.orphaned;
                }
                break;
            }

            if (newStatus != prop.propStatus)
            {
                prop.propStatus          = newStatus;
                prop.propStatusTurnCount = 0;
            }
            else
            {
                prop.propStatusTurnCount++;
            }
        }
コード例 #10
0
 public static bool IsPropInMobVisionCone(
     Mob mob,
     EntityProp prop)
 {
     return(IsPointInMobVisionCone(mob, prop.GetPosition()));
 }