// Rewinds the planets
 public void OnClick()
 {
     foreach (GameObject PlanetOrbit in PlanetOrbit.planetsAndMoons)
     {
         PlanetOrbit.GetComponent <PlanetOrbit>().orbitSpeed = PlanetOrbit.GetComponent <PlanetOrbit>().orbitSpeed * -1;
     }
 }
Esempio n. 2
0
    public void LandingCollision(Collider2D other)
    {
        if (_crashing)
        {
            return;
        }

        Vector2     planetSpeed = Vector2.zero;
        PlanetOrbit plan        = other.transform.gameObject.GetComponent <PlanetOrbit>();

        if (plan != null)
        {
            planetSpeed = other.transform.gameObject.GetComponent <PlanetOrbit>().currentSpeed;
        }

        Debug.Log((_playerRigidbody.velocity - planetSpeed).magnitude);

        if ((playerShip.GetComponent <ShipMovement>().lastSpeed - planetSpeed).magnitude <= maxVelocityWithoutCrashing && other.transform.tag != "crash")
        {
            _landing = true;
            Land(other.gameObject);
            StartCoroutine(ResetLandingBool());
        }
        else
        {
            Debug.Log("Crashed landing too quick");
            Crash();
        }
    }
Esempio n. 3
0
 public IEnumerable <IStellarEntity> GetColonizableWorlds(
     bool planetsOnly)
 {
     foreach (IStellarEntity stellarEntity in this.Objects)
     {
         PlanetOrbit planet = stellarEntity.Params as PlanetOrbit;
         if (planet != null && stellarEntity.Orbit != null && (!planetsOnly || stellarEntity.Orbit.Parent == this.Star.Params))
         {
             yield return(stellarEntity);
         }
     }
 }
Esempio n. 4
0
 internal void AssignEmptyPlanetParameters(Random random)
 {
     foreach (Kerberos.Sots.StarSystem starSystem in this.Objects.OfType <Kerberos.Sots.StarSystem>())
     {
         foreach (IStellarEntity stellarEntity in starSystem.Objects)
         {
             if (stellarEntity.Params is PlanetOrbit)
             {
                 PlanetOrbit planetOrbit = stellarEntity.Params as PlanetOrbit;
                 if (!planetOrbit.Suitability.HasValue)
                 {
                     planetOrbit.Suitability = new float?(StarSystemHelper.ChoosePlanetSuitability(random));
                 }
                 if (!planetOrbit.Resources.HasValue)
                 {
                     planetOrbit.Resources = new int?((int)StarSystemHelper.ChoosePlanetResources(random));
                 }
                 if (!planetOrbit.Biosphere.HasValue)
                 {
                     planetOrbit.Biosphere = new int?((int)StarSystemHelper.ChoosePlanetBiosphere(random));
                 }
                 if (!planetOrbit.Size.HasValue)
                 {
                     planetOrbit.Size = stellarEntity.Orbit == null || stellarEntity.Orbit.Parent != starSystem.Star.Params ? new int?(random.NextInclusive(StarSystemVars.Instance.HabitalMoonMinSize, StarSystemVars.Instance.HabitalMoonMaxSize)) : new int?((int)StarSystemHelper.ChooseSize(random, StarSystemVars.Instance.PlanetMinRadius, StarSystemVars.Instance.PlanetMaxRadius));
                 }
             }
             else if (stellarEntity.Params is GasGiantSmallOrbit)
             {
                 GasGiantSmallOrbit gasGiantSmallOrbit = stellarEntity.Params as GasGiantSmallOrbit;
                 if (!gasGiantSmallOrbit.Size.HasValue)
                 {
                     gasGiantSmallOrbit.Size = new float?(StarSystemHelper.ChooseSize(random, StarSystemVars.Instance.GasGiantMinRadiusSmall, StarSystemVars.Instance.GasGiantMaxRadiusSmall));
                 }
             }
             else if (stellarEntity.Params is GasGiantLargeOrbit)
             {
                 GasGiantLargeOrbit gasGiantLargeOrbit = stellarEntity.Params as GasGiantLargeOrbit;
                 if (!gasGiantLargeOrbit.Size.HasValue)
                 {
                     gasGiantLargeOrbit.Size = new float?(StarSystemHelper.ChooseSize(random, StarSystemVars.Instance.GasGiantMinRadiusLarge, StarSystemVars.Instance.GasGiantMaxRadiusLarge));
                 }
             }
             else if (stellarEntity.Params is MoonOrbit)
             {
                 MoonOrbit moonOrbit = stellarEntity.Params as MoonOrbit;
                 if (!moonOrbit.Size.HasValue)
                 {
                     moonOrbit.Size = new float?(StarSystemHelper.ChooseSize(random, StarSystemVars.Instance.MoonMinRadius, StarSystemVars.Instance.MoonMaxRadius));
                 }
             }
         }
     }
 }
Esempio n. 5
0
 public static IEnumerable <IStellarEntity> CreatePlanet(
     Random random,
     PlanetOrbit orbiterParams,
     bool isOrbitingStar)
 {
     if (!orbiterParams.Size.HasValue)
     {
         orbiterParams.Size = !isOrbitingStar ? new int?(random.NextInclusive(StarSystemVars.Instance.HabitalMoonMinSize, StarSystemVars.Instance.HabitalMoonMaxSize)) : new int?((int)StarSystemHelper.ChooseSize(random, StarSystemVars.Instance.PlanetMinRadius, StarSystemVars.Instance.PlanetMaxRadius));
     }
     return((IEnumerable <IStellarEntity>) new IStellarEntity[1]
     {
         (IStellarEntity) new StellarEntity()
         {
             Params = (Kerberos.Sots.Data.StarMapFramework.Orbit)orbiterParams
         }
     });
 }
Esempio n. 6
0
 void OnEnable()
 {
     planet = (PlanetOrbit)target;
 }
Esempio n. 7
0
        private void AddProteanSystemInstance(GameDatabase gamedb, AssetDatabase assetdb, int SystemId)
        {
            GardenerInfo gi = new GardenerInfo();

            gi.SystemId = SystemId;
            List <PlanetInfo> list                = ((IEnumerable <PlanetInfo>)gamedb.GetStarSystemPlanetInfos(SystemId)).ToList <PlanetInfo>();
            int                num1               = 0;
            int                num2               = 0;
            float              num3               = gamedb.GetFactions().Average <FactionInfo>((Func <FactionInfo, float>)(x => x.IdealSuitability));
            Random             safeRandom         = App.GetSafeRandom();
            GardenerGlobalData globalGardenerData = assetdb.GlobalGardenerData;

            foreach (PlanetInfo planet in list)
            {
                if (!gamedb.GetOrbitalObjectInfo(planet.ID).ParentID.HasValue&& planet.Type != "barren" && planet.Type != "gaseous")
                {
                    planet.Biosphere   = safeRandom.Next(globalGardenerData.MinBiosphere, globalGardenerData.MaxBiosphere);
                    planet.Suitability = num3;
                    ++num1;
                    gamedb.UpdatePlanet(planet);
                }
            }
            if (num1 < globalGardenerData.MinPlanets)
            {
                int num4 = globalGardenerData.MinPlanets - num1;
                int num5 = gamedb.GetStarSystemOrbitalObjectInfos(SystemId).Where <OrbitalObjectInfo>((Func <OrbitalObjectInfo, bool>)(x => !x.ParentID.HasValue)).Count <OrbitalObjectInfo>() + 1;
                for (int index = 0; index < num4; ++index)
                {
                    PlanetOrbit planetOrbit = new PlanetOrbit();
                    planetOrbit.OrbitNumber = num5 + index;
                    planetOrbit.Biosphere   = new int?(safeRandom.Next(globalGardenerData.MinBiosphere, globalGardenerData.MaxBiosphere));
                    planetOrbit.Suitability = new float?(num3);
                    PlanetInfo pi = StarSystemHelper.InferPlanetInfo((Kerberos.Sots.Data.StarMapFramework.Orbit)planetOrbit);
                    gamedb.AddPlanetToSystem(SystemId, new int?(), null, pi, new int?(num5 + index));
                }
            }
            List <PlanetInfo> planetInfoList = new List <PlanetInfo>();

            foreach (PlanetInfo planetInfo in list)
            {
                if (planetInfo.Type != "barren" && planetInfo.Type != "gaseous")
                {
                    num2 += (int)planetInfo.Size;
                    planetInfoList.Add(planetInfo);
                }
            }
            int fleetID = gamedb.InsertFleet(this.PlayerId, 0, SystemId, SystemId, "Protean Pod", FleetType.FL_NORMAL);

            gi.FleetId = fleetID;
            gamedb.InsertGardenerInfo(gi);
            int encounterIdAtSystem = gamedb.GetEncounterIDAtSystem(EasterEgg.EE_GARDENERS, gi.SystemId);

            for (int index = 0; index < num2; ++index)
            {
                int shipId = gamedb.InsertShip(fleetID, this._proteanDesignId, null, (ShipParams)0, new int?(), 0);
                int num4   = 0;
                foreach (PlanetInfo planetInfo in planetInfoList)
                {
                    num4 += (int)planetInfo.Size;
                    if (index < num4)
                    {
                        gamedb.InsertProteanShipOrbitMap(encounterIdAtSystem, shipId, planetInfo.ID);
                        break;
                    }
                }
            }
        }
Esempio n. 8
0
        private static void GenerateIndependentRace(
            Random random,
            StarSystemInfo system,
            OrbitalObjectInfo orbit,
            GameDatabase gamedb,
            AssetDatabase assetdb)
        {
            List <Faction>    list    = assetdb.Factions.Where <Faction>((Func <Faction, bool>)(x => x.IsIndependent())).ToList <Faction>();
            List <PlayerInfo> players = gamedb.GetPlayerInfos().ToList <PlayerInfo>();

            players.RemoveAll((Predicate <PlayerInfo>)(x =>
            {
                if (!x.isStandardPlayer)
                {
                    return(!x.includeInDiplomacy);
                }
                return(true);
            }));
            list.RemoveAll((Predicate <Faction>)(x =>
            {
                if (x.IndyDescrition != null)
                {
                    return(players.Any <PlayerInfo>((Func <PlayerInfo, bool>)(y => y.Name == x.Name)));
                }
                return(true);
            }));
            if (list.Count == 0)
            {
                return;
            }
            Faction     faction1       = random.Choose <Faction>((IList <Faction>)list);
            IndyDesc    indyDescrition = faction1.IndyDescrition;
            double      num1           = indyDescrition.TechLevel != 1 ? (indyDescrition.TechLevel != 2 ? (indyDescrition.TechLevel != 3 ? (double)random.NextInclusive(1750, 10000) * (double)indyDescrition.BasePopulationMod * 1000000.0 : (double)random.NextInclusive(750, 2000) * (double)indyDescrition.BasePopulationMod * 1000000.0) : (double)random.NextInclusive(1, 750) * (double)indyDescrition.BasePopulationMod * 1000000.0) : (double)random.NextInclusive(30, 200) * (double)indyDescrition.BasePopulationMod * 1000.0;
            FactionInfo factionInfo    = gamedb.GetFactionInfo(faction1.ID);

            factionInfo.IdealSuitability = gamedb.GetFactionSuitability(indyDescrition.BaseFactionSuitability) + random.NextInclusive(-indyDescrition.Suitability, indyDescrition.Suitability);
            gamedb.UpdateFaction(factionInfo);
            gamedb.RemoveOrbitalObject(orbit.ID);
            PlanetOrbit planetOrbit = new PlanetOrbit();

            if (indyDescrition.MinPlanetSize != 0 && indyDescrition.MaxPlanetSize != 0)
            {
                planetOrbit.Size = new int?(random.NextInclusive(indyDescrition.MinPlanetSize, indyDescrition.MaxPlanetSize));
            }
            PlanetInfo pi1 = StarSystemHelper.InferPlanetInfo((Kerberos.Sots.Data.StarMapFramework.Orbit)planetOrbit);

            pi1.Suitability = factionInfo.IdealSuitability;
            pi1.Biosphere   = (int)((double)pi1.Biosphere * (double)indyDescrition.BiosphereMod);
            pi1.ID          = gamedb.InsertPlanet(orbit.ParentID, orbit.StarSystemID, orbit.OrbitalPath, orbit.Name, indyDescrition.StellarBodyType, new int?(), pi1.Suitability, pi1.Biosphere, pi1.Resources, pi1.Size);
            double num2       = Math.Min(num1 + (double)(1000 * pi1.Biosphere), Colony.GetMaxCivilianPop(gamedb, pi1));
            string avatarPath = "";

            if (((IEnumerable <string>)faction1.AvatarTexturePaths).Count <string>() > 0)
            {
                avatarPath = faction1.AvatarTexturePaths[0];
            }
            int insertIndyPlayerId = gamedb.GetOrInsertIndyPlayerId(gamedb, faction1.ID, faction1.Name, avatarPath);

            players = gamedb.GetPlayerInfos().ToList <PlayerInfo>();
            foreach (PlayerInfo playerInfo in players)
            {
                PlayerInfo pi       = playerInfo;
                Faction    faction2 = assetdb.Factions.FirstOrDefault <Faction>((Func <Faction, bool>)(x => x.ID == pi.FactionID));
                gamedb.InsertDiplomaticState(insertIndyPlayerId, pi.ID, pi.isStandardPlayer || pi.includeInDiplomacy ? DiplomacyState.NEUTRAL : DiplomacyState.WAR, faction1.GetDefaultReactionToFaction(faction2), false, true);
            }
            gamedb.InsertColony(pi1.ID, insertIndyPlayerId, num2 / 2.0, 0.5f, 0, 1f, true);
            gamedb.InsertColonyFaction(pi1.ID, faction1.ID, num2 / 2.0, 1f, 0);
            if (indyDescrition.TechLevel < 4)
            {
                return;
            }
            foreach (PlanetInfo systemPlanetInfo in gamedb.GetStarSystemPlanetInfos(system.ID))
            {
                if (systemPlanetInfo.ID != pi1.ID)
                {
                    PlanetInfo planetInfo = gamedb.GetPlanetInfo(systemPlanetInfo.ID);
                    float      num3       = Math.Abs(factionInfo.IdealSuitability - planetInfo.Suitability);
                    if ((double)num3 < 200.0)
                    {
                        double impPop = (double)(random.NextInclusive(100, 200) * 100) * (double)indyDescrition.BasePopulationMod;
                        gamedb.InsertColony(pi1.ID, insertIndyPlayerId, impPop, 0.5f, 0, 1f, true);
                        gamedb.InsertColonyFaction(pi1.ID, faction1.ID, impPop / 2.0, 1f, 0);
                    }
                    else if ((double)num3 < 600.0 && (double)planetInfo.Suitability != 0.0)
                    {
                        float num4 = 100f + (float)random.Next(150);
                        if (random.Next(2) == 0)
                        {
                            num4 *= -1f;
                        }
                        planetInfo.Suitability = factionInfo.IdealSuitability + num4;
                        gamedb.UpdatePlanet(planetInfo);
                        double num5 = (double)(random.NextInclusive(50, 100) * 100) * (double)indyDescrition.BasePopulationMod;
                        gamedb.InsertColony(pi1.ID, insertIndyPlayerId, num5 / 2.0, 0.5f, 0, 1f, true);
                        gamedb.InsertColonyFaction(pi1.ID, faction1.ID, num5 / 2.0, 1f, 0);
                    }
                }
            }
        }
Esempio n. 9
0
        public static PlanetInfo InferPlanetInfo(Kerberos.Sots.Data.StarMapFramework.Orbit orbit)
        {
            if (orbit is PlanetOrbit)
            {
                PlanetOrbit planetOrbit = orbit as PlanetOrbit;
                Random      safeRandom  = App.GetSafeRandom();
                float       num1        = planetOrbit.Size.HasValue ? (float)planetOrbit.Size.Value : (float)safeRandom.Next(1, 10);
                string      str         = !string.IsNullOrEmpty(planetOrbit.PlanetType) ? planetOrbit.PlanetType : (safeRandom.NextNormal(0.0, 1.0) > 0.75 ? StellarBodyTypes.Normal : StellarBodyTypes.SpecialTerrestrialTypes[safeRandom.Next(0, ((IEnumerable <string>)StellarBodyTypes.SpecialTerrestrialTypes).Count <string>())]);
                float       num2        = planetOrbit.Suitability.HasValue ? planetOrbit.Suitability.Value : (float)safeRandom.Next(-1000, 1000);
                int         num3        = planetOrbit.Biosphere.HasValue ? planetOrbit.Biosphere.Value : safeRandom.Next(500, 1500);
                int         num4        = planetOrbit.Resources.HasValue ? planetOrbit.Resources.Value : safeRandom.Next(1500, 8000);
                return(new PlanetInfo()
                {
                    Size = num1,
                    Type = str,
                    Suitability = num2,
                    Biosphere = num3,
                    Resources = num4
                });
            }
            if (orbit is MoonOrbit)
            {
                MoonOrbit moonOrbit  = orbit as MoonOrbit;
                Random    safeRandom = App.GetSafeRandom();
                float     num1       = moonOrbit.Size.HasValue ? moonOrbit.Size.Value : (float)(0.100000001490116 + (double)safeRandom.NextSingle() * 0.400000005960464);
                int       num2       = safeRandom.Next(1000, 7000);
                return(new PlanetInfo()
                {
                    Size = num1,
                    Resources = num2,
                    Type = StellarBodyTypes.Barren
                });
            }
            if (orbit is GasGiantSmallOrbit)
            {
                GasGiantSmallOrbit gasGiantSmallOrbit = orbit as GasGiantSmallOrbit;
                Random             safeRandom         = App.GetSafeRandom();
                float num = gasGiantSmallOrbit.Size.HasValue ? gasGiantSmallOrbit.Size.Value : (float)safeRandom.Next(13, 18);
                return(new PlanetInfo()
                {
                    Size = num,
                    Type = StellarBodyTypes.Gaseous
                });
            }
            if (!(orbit is GasGiantLargeOrbit))
            {
                return((PlanetInfo)null);
            }
            GasGiantLargeOrbit gasGiantLargeOrbit = orbit as GasGiantLargeOrbit;
            Random             safeRandom1        = App.GetSafeRandom();

            if (!gasGiantLargeOrbit.Size.HasValue)
            {
                safeRandom1.Next(19, 30);
            }
            else
            {
                double num5 = (double)gasGiantLargeOrbit.Size.Value;
            }
            return(new PlanetInfo()
            {
                Size = gasGiantLargeOrbit.Size.Value,
                Type = StellarBodyTypes.Gaseous
            });
        }