Пример #1
0
        public MobType PickRandomMobType(Random rng)
        {
            MobType result          = null;
            float   random_variable = (float)rng.NextDouble();

            for (int entry_index = 0; entry_index < m_entries.Length; entry_index++)
            {
                MobSpawnTableEntry entry = m_entries[entry_index];

                if (random_variable <= entry.cumulative_weight)
                {
                    if (entry.mob_spawn_table != null)
                    {
                        result = entry.mob_spawn_table.PickRandomMobType(rng);
                    }
                    else
                    {
                        result = entry.mob_type;
                    }

                    break;
                }
            }

            return(result);
        }
Пример #2
0
 public Mob()
 {
     m_room_key = new RoomKey();
     m_mob_id   = -1;
     m_position = new Point3d();
     m_angle    = 0f;
     m_mob_type = null;
     m_health   = 0;
     m_energy   = 0;
     m_ai_data  = null;
 }
Пример #3
0
 public Mob()
 {
     m_room_key = new RoomKey();
     m_mob_id= -1;
     m_position = new Point3d();
     m_angle = 0f;
     m_mob_type = null;
     m_health= 0;
     m_energy= 0;
     m_ai_data = null;
 }
Пример #4
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);
        }
Пример #5
0
        public static Mob CreateMob(MobSpawner spawner, MobType mobType)
        {
            Mob mob = new Mob();

            mob.m_room_key = new RoomKey(spawner.RoomKey);
            mob.m_mob_id   = -1; // mob ID not set until this gets saved into the DB
            mob.m_mob_type = mobType;
            mob.m_position = new Point3d(spawner.Position);
            mob.m_angle    = 0f; //TODO: Add a spawn facing to the mob spawner
            mob.m_health   = mobType.MaxHealth;
            mob.m_energy   = mobType.MaxEnergy;
            mob.m_ai_data  = new MobAIState(spawner);

            return(mob);
        }
Пример #6
0
        public Mob SpawnRandomMob()
        {
            Mob result = null;

            if (RemainingSpawnCount > 0)
            {
                Random  rng     = new Random(m_random_seed);
                MobType mobType = m_spawn_table.PickRandomMobType(rng);

                m_random_seed           = rng.Next();
                m_remaining_spawn_count = Math.Max(m_remaining_spawn_count - 1, 0);

                result = Mob.CreateMob(this, mobType);
            }

            return(result);
        }
Пример #7
0
        public static bool IsPointInMobVisionCone(
            Mob mob,
            Point3d point)
        {
            MobType mobType = mob.MobType;

            Vector2d mobToPoint   = (point - mob.Position).ToVector2d();
            Vector2d facingVector = MathConstants.GetUnitVectorForAngle(mob.Angle);

            float cosHalfAngle                   = (float)Math.Cos(mob.MobType.VisionCone.GetHalfAngle());
            float cosAngleToProp                 = facingVector.Dot(mobToPoint);
            float pointDistanceSquared           = Point2d.DistanceSquared(point, mob.Position);
            float minVisionCircleDistanceSquared = WorldConstants.ROOM_TILE_SIZE * WorldConstants.ROOM_TILE_SIZE;
            float minVisionConeDistanceSquared   = (float)(mobType.VisionCone.distance * mobType.VisionCone.distance);

            bool isInVisionCone =
                (pointDistanceSquared <= minVisionCircleDistanceSquared) ||
                ((cosAngleToProp > cosHalfAngle) && (pointDistanceSquared <= minVisionConeDistanceSquared));

            return(isInVisionCone);
        }
Пример #8
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++;
            }
        }
Пример #9
0
        public static Mob CreateMob(MobSpawner spawner, MobType mobType)
        {
            Mob mob = new Mob();

            mob.m_room_key = new RoomKey(spawner.RoomKey);
            mob.m_mob_id= -1; // mob ID not set until this gets saved into the DB
            mob.m_mob_type= mobType;
            mob.m_position = new Point3d(spawner.Position);
            mob.m_angle = 0f; //TODO: Add a spawn facing to the mob spawner
            mob.m_health= mobType.MaxHealth;
            mob.m_energy= mobType.MaxEnergy;
            mob.m_ai_data = new MobAIState(spawner);

            return mob;
        }