Esempio n. 1
0
        /// <summary>
        /// Create a new entity, naked and squirming
        /// Created with no equipment, knowledge, family, etc
        /// </summary>
        /// <param name="template"></param>
        /// <param name="needs"></param>
        /// <param name="level"></param>
        /// <param name="job"></param>
        /// <param name="sex"></param>
        /// <param name="sexuality"></param>
        /// <param name="position"></param>
        /// <param name="icons"></param>
        /// <param name="world"></param>
        public Entity(EntityTemplate template, Dictionary <NeedIndex, EntityNeed> needs, int level, JobType job, Sex sex, Sexuality sexuality,
                      Vector2Int position, List <Sprite> sprites, WorldInstance world) :
            base(NameProvider.GetRandomName(template.CreatureType, sex), template.Statistics[StatisticIndex.Endurance].Value * 2, position, sprites, template.JoyType, true)
        {
            this.CreatureType = template.CreatureType;

            this.m_Size = template.Size;
            this.Slots  = template.Slots;

            this.m_JobLevels       = new Dictionary <string, int>();
            this.m_Sexuality       = sexuality;
            this.m_IdentifiedItems = new List <string>();
            this.m_Statistics      = template.Statistics;

            if (template.Skills.Count == 0)
            {
                this.m_Skills = EntitySkillHandler.GetSkillBlock(needs);
            }
            else
            {
                this.m_Skills = template.Skills;
            }
            this.m_Needs     = needs;
            this.m_Abilities = template.Abilities;
            this.m_Level     = level;
            for (int i = 1; i < level; i++)
            {
                this.LevelUp();
            }
            this.m_Experience     = 0;
            this.m_CurrentJob     = job;
            this.m_Sentient       = template.Sentient;
            this.m_NaturalWeapons = NaturalWeaponHelper.MakeNaturalWeapon(template.Size);
            this.m_Equipment      = new Dictionary <string, ItemInstance>();
            this.m_Backpack       = new List <ItemInstance>();
            this.m_Relationships  = new Dictionary <long, int>();
            this.Sex          = sex;
            this.m_Family     = new Dictionary <long, RelationshipStatus>();
            this.m_VisionType = template.VisionType;

            this.m_Tileset = template.Tileset;

            this.CalculateDerivatives();

            this.m_Vision = new bool[1, 1];

            this.m_Pathfinder      = new Pathfinder();
            this.m_PathfindingData = new Queue <Vector2Int>();

            this.m_FulfillingNeed    = (NeedIndex)(-1);
            this.m_FulfilmentCounter = 0;

            this.RegenTicker = RNG.Roll(0, REGEN_TICK_TIME - 1);

            this.MyWorld = world;

            SetFOVHandler();
            SetCurrentTarget();
        }
Esempio n. 2
0
        public static PSystem GenerateStarsystem(int numberOfPlanets, int ID, GalaxyManager galaxyManager, LocalIDManager idManager, GalaxyRegistrationManager rm, LocatorService ls)
        {
            bool hasPort = false;

            // Add sun

            float size         = r.Next(100, 255) / 100f;
            float mass         = r.Next(50, 255) / 10f;
            float innerGravity = mass / 1875f;
            float outerGravity = innerGravity / 6f;

            var s    = (SunTypes[])Enum.GetValues(typeof(SunTypes));
            int type = r.Next(0, s.Length);

            var star = new Star(size, mass, innerGravity, outerGravity, s[type]);

            var system = new PSystem(star, ID, ls);

            system.AreaSize = baseBorder + r.Next(0, borderVariation);


            // Add Name
            system.AreaName = NameProvider.GetRandomName();


            rm.RegisterObject(system);


            for (int i = 0; i < numberOfPlanets; i++)
            {
                Planet planet;
                bool   SatisfiedWithResults = false;
                int    numAttempts          = MaxAttempts;
                system.IsCluster = false;
                int clusterType = 0;



                planet = new Planet(system, 0, ls);

                planet.AreaName = system.AreaName + " " + ToRoman(i + 1);

                if (r.Next(0, 101) > (100 - chanceOfCluster)) // Chance for planets to cluster
                {
                    system.IsCluster = true;
                    clusterType      = r.Next(0, clusterRadii.Count()); // Get which type of cluster
                }

                planet.Init(i, moonChance, minDistance, incrementOfOrbit, variationOfOrbit, 0,
                            r.Next());
                SatisfiedWithResults = !CheckForCollisions(system, planet); // True if we find any collisions.



                while (!SatisfiedWithResults)// While we're not content with the generation
                {
                    planet.Init(i, moonChance, minDistance, incrementOfOrbit, variationOfOrbit, 0,
                                r.Next());

                    SatisfiedWithResults = !CheckForCollisions(system, planet); // True if we find any collisions.

                    if (SatisfiedWithResults && system.IsCluster && i > 0)
                    {
                        SatisfiedWithResults = CheckForCollisions(system, planet, clusterRadii[clusterType]); // Cluster planets
                    }

                    numAttempts++;

                    if (numAttempts >= MaxAttempts && !system.IsCluster)
                    {
                        break; // Breaks out of infinite pass if it ever occurs
                    }
                    else if (numAttempts >= MaxAttempts && system.IsCluster)
                    {
                        i = 0; // Reset the whole operation because there's a bad system being generated.
                        foreach (Planet pll in system.GetPlanets())
                        {
                            system.RemovePlanet(pll);
                            rm.DeRegisterObject(pll);
                        }
                        break;
                    }
                }

                if (SatisfiedWithResults == false) // Don't add a colliding planet!
                {
                    //Logger.log(Log_Type.WARNING, "Skipped adding a planet due to MaxAttempts being too much");
                    continue;
                }
                planet.Id = idManager.PopFreeID();
                system.AddPlanet(planet);
                planet.ParentAreaID = system.Id;
                rm.RegisterObject(planet);

                if (system.AreaSize < planet.Distance - baseBorder) // If we're skinny, throw in a little extra space
                {
                    system.AreaSize = planet.Distance + baseBorder + r.Next(0, borderVariation);
                }
            }


            foreach (Planet p in system.GetPlanets())
            {
                _generateMoons(system, p, galaxyManager, idManager, rm, ls);
            }

            foreach (Planet m in system.GetMoons())
            {
                if (system.AreaSize < ls.AreaLocator.GetArea(m.IDToOrbit).Distance + m.Distance + baseBorder)
                {
                    // If we're skinny, throw in a little extra space
                    system.AreaSize = ls.AreaLocator.GetArea(m.IDToOrbit).Distance + m.Distance + baseBorder + r.Next(0, borderVariation);
                }
            }

            // Port Generation
            if (r.Next(0, 100) > 100 - portChance && !hasPort)
            {
                if (system.MoonCount > 0)
                {
                    for (int i = 0; i < system.MoonCount; i++)
                    {
                    }
                    int cr          = r.Next(0, system.MoonCount + 1); // Finds moon to turn into port.
                    int currentMoon = 0;                               // Used to get the moon

                    foreach (Planet m in system.GetMoons())
                    {
                        if (currentMoon == cr)
                        {
                            Planet moonToPort = m;
                            moonToPort.ParentAreaID = system.Id;
                            system.RemoveMoon(m);
                            rm.DeRegisterObject(m);

                            Port por = new Port(idManager.PopFreeID(), moonToPort, system.AreaName, ShipStatManager.StatShipList.ToList <ShipStats>(), ls); // Converts a moon into a port.
                            system.AddPort(por);
                            rm.RegisterObject(por);

                            hasPort = true;
                            break;
                        }
                        currentMoon++;
                    }
                }
            }


            return(system);
        }