예제 #1
0
        public string GetFaction(WorldManager world, string EntityFaction, FactionFilter EntityFactionFilter)
        {
            var factions = world.Factions.Factions.Where(f => f.Value.Race.IsIntelligent && !f.Value.IsRaceFaction &&
                                                         CanSpawnFaction(world, f.Value, EntityFaction, EntityFactionFilter)).Select(f => f.Value).ToList();

            factions.Sort((f1, f2) => f1.DistanceToCapital.CompareTo(f2.DistanceToCapital));

            if (factions.Count == 0)
            {
                return(EntityFaction);
            }

            float sumDistance = factions.Sum(f => 1.0f / (f.DistanceToCapital + 1.0f));
            float randPick    = MathFunctions.Rand(0, sumDistance);

            float dist = 0;

            foreach (var faction in factions)
            {
                dist += 1.0f / (1.0f + faction.DistanceToCapital);
                if (randPick < dist)
                {
                    return(faction.Name);
                }
            }

            return(EntityFaction);
        }
예제 #2
0
        public string GetFaction(WorldManager world, string EntityFaction, FactionFilter EntityFactionFilter)
        {
            var factions = world.Factions.Factions.Where(f => f.Value.Race.IsIntelligent && f.Value.ParentFaction.InteractiveFaction &&
                                                         CanSpawnFaction(world, f.Value, EntityFaction, EntityFactionFilter)).Select(f => f.Value).ToList();

            if (factions.Count == 0)
            {
                return(EntityFaction);
            }

            return(factions.SelectRandom().ParentFaction.Name);
        }
예제 #3
0
        private bool CanSpawnFaction(WorldManager world, Faction faction, string EntityFaction, FactionFilter filter)
        {
            if (filter.Specification != FactionSpecification.Player && faction == world.PlayerFaction)
            {
                return(false);
            }

            switch (filter.Specification)
            {
            case FactionSpecification.Motherland:
                return(faction.IsMotherland);

            case FactionSpecification.Player:
                return(faction == world.PlayerFaction);

            case FactionSpecification.Random:
                switch (filter.Claim)
                {
                case FactionClaimFilter.ClaimsTerritory:
                    if (!faction.ClaimsColony)
                    {
                        return(false);
                    }
                    break;

                case FactionClaimFilter.DoesNotClaimTerritory:
                    if (faction.ClaimsColony)
                    {
                        return(false);
                    }
                    break;

                case FactionClaimFilter.Any:
                    break;
                }
                var relationship = world.Diplomacy.GetPolitics(faction, world.PlayerFaction).GetCurrentRelationship();
                switch (filter.Hostility)
                {
                case FactionHostilityFilter.Ally:
                    return(relationship == Relationship.Loving);

                case FactionHostilityFilter.Neutral:
                    return(relationship == Relationship.Indifferent);

                case FactionHostilityFilter.Hostile:
                    return(relationship == Relationship.Hateful);

                case FactionHostilityFilter.NotHostile:
                    return(relationship != Relationship.Hateful);

                case FactionHostilityFilter.NotAlly:
                    return(relationship != Relationship.Loving);

                case FactionHostilityFilter.Any:
                    return(true);
                }
                return(true);

            case FactionSpecification.Specific:
                return(faction.Name == EntityFaction);
            }
            return(false);
        }
예제 #4
0
        private bool CanSpawnFaction(WorldManager World, Faction faction, string EntityFaction, FactionFilter filter)
        {
            if (filter.Specification != FactionSpecification.Player && faction == World.PlayerFaction)
            {
                return(false);
            }

            switch (filter.Specification)
            {
            case FactionSpecification.Corporate:
                return(faction.ParentFaction.IsCorporate);

            case FactionSpecification.Player:
                return(faction == World.PlayerFaction);

            case FactionSpecification.Random:

                var relationship = World.Overworld.GetPolitics(faction.ParentFaction, World.PlayerFaction.ParentFaction).GetCurrentRelationship();
                switch (filter.Hostility)
                {
                case FactionHostilityFilter.Ally:
                    return(relationship == Relationship.Loving);

                case FactionHostilityFilter.Neutral:
                    return(relationship == Relationship.Indifferent);

                case FactionHostilityFilter.Hostile:
                    return(relationship == Relationship.Hateful);

                case FactionHostilityFilter.NotHostile:
                    return(relationship != Relationship.Hateful);

                case FactionHostilityFilter.NotAlly:
                    return(relationship != Relationship.Loving);

                case FactionHostilityFilter.Any:
                    return(true);
                }
                return(true);

            case FactionSpecification.Specific:
                return(faction.ParentFaction.Name == EntityFaction);
            }
            return(false);
        }