public StellarBody.Params GetStellarBodyParams(GameSession game, int orbitalId) { OrbitalObjectInfo orbitalObjectInfo = game.GameDatabase.GetOrbitalObjectInfo(orbitalId); ColonyInfo colonyInfoForPlanet = game.GameDatabase.GetColonyInfoForPlanet(orbitalId); PlanetInfo planetInfo = game.GameDatabase.GetPlanetInfo(orbitalId); SystemColonyType colonyType = SystemColonyType.Normal; int num; double population; PlayerInfo povPlayerInfo; if (colonyInfoForPlanet != null) { num = colonyInfoForPlanet.PlayerID; population = colonyInfoForPlanet.ImperialPop; povPlayerInfo = game.GameDatabase.GetPlayerInfo(num); if (orbitalObjectInfo != null && povPlayerInfo != null) { HomeworldInfo homeworldInfo = game.GameDatabase.GetHomeworlds().FirstOrDefault <HomeworldInfo>((Func <HomeworldInfo, bool>)(x => x.SystemID == orbitalObjectInfo.StarSystemID)); if (homeworldInfo != null && homeworldInfo.SystemID != 0 && homeworldInfo.PlayerID == povPlayerInfo.ID) { colonyType = SystemColonyType.Home; } else if (game.GameDatabase.GetProvinceInfos().Any <ProvinceInfo>((Func <ProvinceInfo, bool>)(x => { if (x.CapitalSystemID != orbitalObjectInfo.StarSystemID || x.PlayerID != povPlayerInfo.ID) { return(false); } int capitalSystemId = x.CapitalSystemID; int?homeworld = povPlayerInfo.Homeworld; if (capitalSystemId == homeworld.GetValueOrDefault()) { return(!homeworld.HasValue); } return(true); }))) { colonyType = SystemColonyType.Capital; } } } else { num = 0; population = 0.0; povPlayerInfo = game.GameDatabase.GetPlayerInfo(game.LocalPlayer.ID); } FactionInfo factionInfo = game.GameDatabase.GetFactionInfo(povPlayerInfo.FactionID); float hazard = Math.Abs(planetInfo.Suitability - factionInfo.IdealSuitability); float stratModifier = (float)game.App.GetStratModifier <int>(StratModifiers.MaxColonizableHazard, povPlayerInfo.ID); float radius = StarSystemVars.Instance.SizeToRadius(planetInfo.Size); Matrix transform = orbitalObjectInfo.OrbitalPath.GetTransform(0.0); return(this.GetStellarBodyParams(StarSystemMapUI.SelectIcon(planetInfo, game.GameDatabase.GetStarSystemOrbitalObjectInfos(orbitalObjectInfo.StarSystemID), (IEnumerable <PlanetInfo>)game.GameDatabase.GetStarSystemPlanetInfos(orbitalObjectInfo.StarSystemID)), transform.Position, radius, orbitalId, num, planetInfo.Type, hazard, stratModifier, factionInfo.Name, (float)planetInfo.Biosphere, population, new int?(), Colony.GetColonyStage(game.GameDatabase, num, (double)hazard), colonyType)); }
private void SyncSystemOwnershipEffect(string itemID, int systemid, bool cloaksystem) { StarSystemInfo starSystemInfo = this._app.GameDatabase.GetStarSystemInfo(systemid); if (starSystemInfo == (StarSystemInfo)null || starSystemInfo.IsDeepSpace) { this._app.UI.SetVisible(this._app.UI.GetGlobalID(this._app.UI.Path(itemID, "systemDeepspace")), true); this._app.UI.SetText(this._app.UI.Path(itemID, "title"), cloaksystem ? "Unknown" : starSystemInfo.Name); } else { this._systemWidgets.Add(new SystemWidget(this._app, itemID)); this._systemWidgets.Last<SystemWidget>().Sync(systemid); if (cloaksystem) this._app.UI.SetText(this._app.UI.Path(itemID, "title"), "Unknown"); HomeworldInfo homeworldInfo = this._app.GameDatabase.GetHomeworlds().ToList<HomeworldInfo>().FirstOrDefault<HomeworldInfo>((Func<HomeworldInfo, bool>)(x => x.SystemID == systemid)); int? systemOwningPlayer = this._app.GameDatabase.GetSystemOwningPlayer(systemid); PlayerInfo Owner = this._app.GameDatabase.GetPlayerInfo(systemOwningPlayer.HasValue ? systemOwningPlayer.Value : 0); if (homeworldInfo != null && homeworldInfo.SystemID != 0 && !cloaksystem) { string globalId = this._app.UI.GetGlobalID(this._app.UI.Path(itemID, "systemHome")); this._app.UI.SetVisible(globalId, true); this._app.UI.SetPropertyColor(globalId, "color", this._app.GameDatabase.GetPlayerInfo(homeworldInfo.PlayerID).PrimaryColor * (float)byte.MaxValue); } else if (!cloaksystem && Owner != null && this._app.GameDatabase.GetProvinceInfos().Where<ProvinceInfo>((Func<ProvinceInfo, bool>)(x => { if (x.CapitalSystemID != systemid || x.PlayerID != Owner.ID) return false; int capitalSystemId = x.CapitalSystemID; int? homeworld = Owner.Homeworld; if (capitalSystemId == homeworld.GetValueOrDefault()) return !homeworld.HasValue; return true; })).Any<ProvinceInfo>()) { string globalId = this._app.UI.GetGlobalID(this._app.UI.Path(itemID, "systemCapital")); this._app.UI.SetVisible(globalId, true); this._app.UI.SetPropertyColor(globalId, "color", Owner.PrimaryColor * (float)byte.MaxValue); } else { string globalId = this._app.UI.GetGlobalID(this._app.UI.Path(itemID, "systemOwnership")); this._app.UI.SetVisible(globalId, true); if (Owner == null || cloaksystem) return; this._app.UI.SetPropertyColor(globalId, "color", Owner.PrimaryColor * (float)byte.MaxValue); } } }
public void Enter(App app) { this._app = app; if (this._app.GameDatabase == null) { this._app.NewGame(); } app.Game.SetLocalPlayer(app.GetPlayer(1)); this._set = new GameObjectSet(app); this._postLoadedObjects = new List <IGameObject>(); this._set.Add((IGameObject) new Sky(app, SkyUsage.InSystem, new Random().Next())); if (ScriptHost.AllowConsole) { this._input = this._set.Add <CombatInput>(); } this._camera = this._set.Add <OrbitCameraController>(); this._camera.SetAttractMode(true); this._camera.TargetPosition = new Vector3(500000f, 0.0f, 0.0f); this._camera.MinDistance = 1f; this._camera.MaxDistance = 11000f; this._camera.DesiredDistance = 11000f; this._camera.DesiredPitch = MathHelper.DegreesToRadians(-2f); this._camera.DesiredYaw = MathHelper.DegreesToRadians(45f); int systemId = 0; IEnumerable <HomeworldInfo> homeworlds = this._app.GameDatabase.GetHomeworlds(); HomeworldInfo homeworldInfo = homeworlds.FirstOrDefault <HomeworldInfo>((Func <HomeworldInfo, bool>)(x => x.PlayerID == app.LocalPlayer.ID)); if (homeworldInfo != null) { systemId = homeworldInfo.SystemID; } else if (homeworlds.Count <HomeworldInfo>() > 0) { systemId = homeworlds.ElementAt <HomeworldInfo>(new Random().NextInclusive(0, homeworlds.Count <HomeworldInfo>() - 1)).SystemID; } this._starsystem = new StarSystem(this._app, 1f, systemId, new Vector3(0.0f, 0.0f, 0.0f), false, (CombatSensor)null, true, 0, false, true); this._set.Add((IGameObject)this._starsystem); this._starsystem.PostSetProp("InputEnabled", false); this._starsystem.PostSetProp("RenderSuroundingItems", false); Vector3 vector1 = new Vector3(); float num1 = 10000f; IEnumerable <PlanetInfo> infosOrbitingStar = this._app.GameDatabase.GetPlanetInfosOrbitingStar(systemId); bool flag1 = false; foreach (PlanetInfo planetInfo in infosOrbitingStar) { if (planetInfo != null) { ColonyInfo colonyInfoForPlanet = this._app.GameDatabase.GetColonyInfoForPlanet(planetInfo.ID); if (colonyInfoForPlanet != null && colonyInfoForPlanet.PlayerID == this._app.LocalPlayer.ID) { vector1 = this._app.GameDatabase.GetOrbitalTransform(planetInfo.ID).Position; num1 = StarSystemVars.Instance.SizeToRadius(planetInfo.Size); flag1 = true; break; } } } if (!flag1) { PlanetInfo[] array = infosOrbitingStar.ToArray <PlanetInfo>(); if (array.Length > 0) { PlanetInfo planetInfo = array[new Random().Next(array.Length)]; vector1 = this._app.GameDatabase.GetOrbitalTransform(planetInfo.ID).Position; num1 = StarSystemVars.Instance.SizeToRadius(planetInfo.Size); } } this._camera.DesiredYaw = -(float)Math.Atan2((double)vector1.Z, (double)vector1.X); this._camera.TargetPosition = vector1; Matrix rotationYpr = Matrix.CreateRotationYPR(this._camera.DesiredYaw, 0.0f, 0.0f); Vector3[] shuffledPlayerColors = Player.GetShuffledPlayerColors(this._rand); foreach (string index in this._players.Keys.ToList <string>()) { this._players[index] = new Player(app, app.Game, new PlayerInfo() { FactionID = app.GameDatabase.GetFactionIdFromName(index), AvatarAssetPath = string.Empty, BadgeAssetPath = app.AssetDatabase.GetRandomBadgeTexture(index, this._rand), PrimaryColor = shuffledPlayerColors[0], SecondaryColor = new Vector3(this._rand.NextSingle(), this._rand.NextSingle(), this._rand.NextSingle()) }, Player.ClientTypes.AI); this._set.Add((IGameObject)this._players[index]); } Vector3 zero = Vector3.Zero; double num2 = (double)Vector3.Cross(vector1, new Vector3(0.0f, 1f, 0.0f)).Normalize(); float num3 = 500f; int num4 = 4; float num5 = num3 * (float)num4; Vector3 vector3_1 = new Vector3(-num5, 0.0f, -num5); Vector3 vector3_2 = vector1 + -rotationYpr.Forward * (num1 + 2000f + num5); List <Vector3> vector3List1 = new List <Vector3>(); for (int index = 0; index < 81; ++index) { int num6 = index % 5; int num7 = index / 5; Vector3 vector3_3 = new Vector3(vector3_1.X + (float)num7 * num3, 0.0f, vector3_1.Z + (float)num6 * num3); vector3_3 += vector3_2; vector3List1.Add(vector3_3); } List <Vector3> vector3List2 = new List <Vector3>(); foreach (Vector3 pos in vector3List1) { if (this.PositionCollidesWithObject(pos, 400f)) { vector3List2.Add(pos); } } foreach (Vector3 vector3_3 in vector3List2) { vector3List1.Remove(vector3_3); } int num8 = this._rand.NextInclusive(6, 12); List <int> intList = new List <int>(); for (int index1 = 0; index1 < num8; ++index1) { int index2 = 0; bool flag2 = true; for (int index3 = 0; flag2 && index3 < vector3List1.Count; ++index3) { index2 = this._rand.NextInclusive(0, Math.Max(vector3List1.Count - 1, 0)); flag2 = intList.Contains(index2); if (intList.Count == vector3List1.Count) { break; } } Vector3 off = vector3List1.Count > 0 ? vector3List1[index2] : vector1; if (index1 < 3) { zero += this.CreateRandomShip(off, "loa", index1 == 0); } else { zero += this.CreateRandomShip(off, "", false); } if (!intList.Contains(index2)) { intList.Add(index2); } } if (num8 <= 0) { return; } Vector3 vector3_4 = zero / (float)num8; }
public void Sync(GameObjectSet gos) { StarMapBase.SyncContext context = new StarMapBase.SyncContext(this._db); List <StarSystemInfo> list1 = this._db.GetStarSystemInfos().ToList <StarSystemInfo>(); foreach (StarSystemInfo starSystemInfo in list1.Where <StarSystemInfo>((Func <StarSystemInfo, bool>)(x => !x.IsVisible)).ToList <StarSystemInfo>()) { if (!StarMap.IsInRange(this._db, this._sim.LocalPlayer.ID, starSystemInfo.ID)) { list1.Remove(starSystemInfo); } else { starSystemInfo.IsVisible = true; this._db.UpdateStarSystemVisible(starSystemInfo.ID, true); } } IEnumerable <StarMapTerrain> source1 = this.Terrain.Sync(gos, this._db.GetTerrainInfos(), context, false); IEnumerable <StarMapProvince> source2 = this.Provinces.Sync(gos, this._db.GetProvinceInfos(), context, false); IEnumerable <StarMapSystem> source3 = this.Systems.Sync(gos, (IEnumerable <StarSystemInfo>)list1, context, false); List <FleetInfo> list2 = this._db.GetFleetInfos(FleetType.FL_NORMAL | FleetType.FL_CARAVAN | FleetType.FL_ACCELERATOR).Where <FleetInfo>((Func <FleetInfo, bool>)(x => { if (!x.IsReserveFleet) { return(this._sim.GetPlayerObject(x.PlayerID) != null); } return(false); })).ToList <FleetInfo>(); int swarmerPlayer = this._sim.ScriptModules == null || this._sim.ScriptModules.Swarmers == null ? 0 : this._sim.ScriptModules.Swarmers.PlayerID; if (swarmerPlayer != 0) { foreach (FleetInfo fleetInfo in list2.Where <FleetInfo>((Func <FleetInfo, bool>)(x => { if (x.PlayerID == swarmerPlayer) { return(x.Name.Contains("Swarm")); } return(false); })).ToList <FleetInfo>()) { list2.Remove(fleetInfo); } } foreach (FleetInfo fleetInfo in list2.Where <FleetInfo>((Func <FleetInfo, bool>)(x => { if (this._db.GetMissionByFleetID(x.ID) != null) { return(this._db.GetMissionByFleetID(x.ID).Type == MissionType.PIRACY); } return(false); })).ToList <FleetInfo>()) { if (!this._db.PirateFleetVisibleToPlayer(fleetInfo.ID, this._sim.LocalPlayer.ID)) { list2.Remove(fleetInfo); } } IEnumerable <StarMapFleet> source4 = this.Fleets.Sync(gos, (IEnumerable <FleetInfo>)list2, context, true); this.PostObjectAddObjects((IGameObject[])source2.ToArray <StarMapProvince>()); this.PostObjectAddObjects((IGameObject[])source3.ToArray <StarMapSystem>()); this.PostObjectAddObjects((IGameObject[])source4.ToArray <StarMapFleet>()); if (this._sim.LocalPlayer.Faction.Name == "human") { this.PostObjectAddObjects((IGameObject[])this.NodeLines.Sync(gos, (IEnumerable <NodeLineInfo>) this._db.GetExploredNodeLines(this._sim.LocalPlayer.ID).Where <NodeLineInfo>((Func <NodeLineInfo, bool>)(x => x.IsPermenant)).ToList <NodeLineInfo>(), context, false).ToArray <StarMapNodeLine>()); } this.PostObjectAddObjects((IGameObject[])source1.ToArray <StarMapTerrain>()); Dictionary <int, int> dictionary1 = new Dictionary <int, int>(); List <StarMap.PlayerSystemPair> playerSystemPairList = new List <StarMap.PlayerSystemPair>(); foreach (StarMapFleet key in this.Fleets.Forward.Keys) { this._sim.GameDatabase.IsStealthFleet(key.FleetID); if (key.InTransit) { key.SetVisible(StarMap.IsInRange(this.App.Game.GameDatabase, this._sim.LocalPlayer.ID, key.Position, 1f, (Dictionary <int, List <ShipInfo> >)null)); } else { dictionary1[key.SystemID] = 0; bool flag = false; foreach (StarMap.PlayerSystemPair playerSystemPair in playerSystemPairList) { if (playerSystemPair.PlayerID == key.PlayerID && playerSystemPair.SystemID == key.SystemID) { flag = true; break; } } if (flag) { key.SetVisible(false); } else { key.SetVisible(StarMap.IsInRange(this.App.Game.GameDatabase, this._sim.LocalPlayer.ID, key.Position, 1f, (Dictionary <int, List <ShipInfo> >)null)); playerSystemPairList.Add(new StarMap.PlayerSystemPair() { PlayerID = key.PlayerID, SystemID = key.SystemID }); } } } foreach (StarMapFleet key in this.Fleets.Forward.Keys) { if (!key.InTransit && key.IsVisible) { key.SetSystemFleetIndex(dictionary1[key.SystemID]); Dictionary <int, int> dictionary2; int systemId; (dictionary2 = dictionary1)[systemId = key.SystemID] = dictionary2[systemId] + 1; } } foreach (StarMapFleet key in this.Fleets.Forward.Keys) { if (!key.InTransit && key.IsVisible) { key.SetSystemFleetCount(dictionary1[key.SystemID]); } } foreach (HomeworldInfo homeworld in this._db.GetHomeworlds()) { HomeworldInfo hw = homeworld; ColonyInfo hwci = this._db.GetColonyInfo(hw.ColonyID); if (hwci != null && list1.Any <StarSystemInfo>((Func <StarSystemInfo, bool>)(x => { if (x.ID == hw.SystemID) { return(hw.PlayerID == hwci.PlayerID); } return(false); }))) { this.PostSetProp("Homeworld", (object)this._sim.GetPlayerObject(hw.PlayerID).ObjectID, (object)this.Systems.Reverse[hw.SystemID].ObjectID); } } foreach (StarSystemInfo starSystemInfo in list1) { this.PostSetProp("ProvinceCapitalEffect", (object)false, (object)this.Systems.Reverse[starSystemInfo.ID].ObjectID); } foreach (ProvinceInfo provinceInfo in this._db.GetProvinceInfos().ToList <ProvinceInfo>()) { ProvinceInfo p = provinceInfo; if (list1.Any <StarSystemInfo>((Func <StarSystemInfo, bool>)(x => x.ID == p.CapitalSystemID))) { this.PostSetProp("ProvinceCapitalEffect", (object)true, (object)this.Systems.Reverse[p.CapitalSystemID].ObjectID); } } this.PostSetProp("RegenerateTerrain"); this.PostSetProp("RegenerateBorders"); this.PostSetProp("RegenerateFilters"); }