protected override void UpdateFleet( StarMapFleet o, FleetInfo oi, StarMapBase.SyncContext context) { FleetLocation fleetLocation = this._db.GetFleetLocation(oi.ID, true); o.SetSystemID(fleetLocation.SystemID); o.SetPosition(fleetLocation.Coords); o.FleetID = oi.ID; if (fleetLocation.Direction.HasValue) { o.SetDirection(fleetLocation.Direction.Value); } MoveOrderInfo orderInfoByFleetId = this.App.GameDatabase.GetMoveOrderInfoByFleetID(oi.ID); if (orderInfoByFleetId != null && (double)orderInfoByFleetId.Progress <= 0.0) { StarSystemInfo starSystemInfo = this._db.GetStarSystemInfo(fleetLocation.SystemID); if (starSystemInfo != (StarSystemInfo)null) { o.SetPosition(starSystemInfo.Origin); } } o.SetIsInTransit(orderInfoByFleetId != null && ((double)orderInfoByFleetId.Progress > 0.0 || oi.Type == FleetType.FL_ACCELERATOR && (oi.SystemID == 0 || this._sim.GameDatabase.GetStarSystemInfo(oi.SystemID).IsDeepSpace))); o.SetPlayer(this._sim.GetPlayerObject(oi.PlayerID)); if (oi.PlayerID == this._sim.LocalPlayer.ID) { o.SetSensorRange(GameSession.GetFleetSensorRange(this.App.AssetDatabase, this._db, oi.ID)); } if (o.ObjectStatus == GameObjectStatus.Ready) { o.PostSetActive(true); } o.SetIsLoaGate(oi.Type == FleetType.FL_ACCELERATOR); }
public static Matrix GetSpawnTransform( App app, int fleetID, Kerberos.Sots.GameStates.StarSystem starSystem, OrbitalObjectInfo[] orbitalObjects) { DesignInfo designInfo = app.GameDatabase.GetDesignInfo(app.Game.ScriptModules.SystemKiller.SystemKillerDesignId); float val2 = 50000f; if (designInfo != null) { val2 = ((IEnumerable <DesignSectionInfo>)designInfo.DesignSections).Sum <DesignSectionInfo>((Func <DesignSectionInfo, float>)(x => x.ShipSectionAsset.Maneuvering.LinearSpeed)) * 120f; } float num1 = 0.0f; float num2 = 5000f; Vector3 vector3_1 = Vector3.Zero; Vector3 vector3_2 = -Vector3.UnitZ; int num3 = 0; foreach (OrbitalObjectInfo orbitalObject in orbitalObjects) { PlanetInfo planetInfo = app.GameDatabase.GetPlanetInfo(orbitalObject.ID); if (planetInfo != null) { Matrix orbitalTransform = app.GameDatabase.GetOrbitalTransform(orbitalObject.ID); float lengthSquared = orbitalTransform.Position.LengthSquared; if ((double)lengthSquared > (double)num1) { num1 = lengthSquared; vector3_1 = orbitalTransform.Position; vector3_2 = -orbitalTransform.Position; num2 = StarSystemVars.Instance.SizeToRadius(planetInfo.Size) + val2; num3 = orbitalObject.ID; } } } if (num3 == 0) { MoveOrderInfo orderInfoByFleetId = app.GameDatabase.GetMoveOrderInfoByFleetID(fleetID); if (orderInfoByFleetId != null) { Vector3 forward = orderInfoByFleetId.ToCoords - orderInfoByFleetId.FromCoords; forward.Y = 0.0f; if ((double)forward.Normalize() < 1.40129846432482E-45) { forward = -Vector3.UnitZ; } float num4 = 0.0f; if (starSystem != null) { num4 = Math.Min((float)(((double)starSystem.GetBaseOffset() + (double)Kerberos.Sots.GameStates.StarSystem.CombatZoneMapRadii[Math.Max(starSystem.GetFurthestRing() - 1, 1)]) * 5700.0), val2); } return(Matrix.CreateWorld(forward * -num4, forward, Vector3.UnitY)); } float num5 = starSystem != null?starSystem.GetStarRadius() : 5000f; Vector3 position = Vector3.UnitZ * (float)-((double)num5 + (double)val2); return(Matrix.CreateWorld(position, Vector3.Normalize(-position), Vector3.UnitY)); } double num6 = (double)vector3_2.Normalize(); IEnumerable <OrbitalObjectInfo> moons = app.GameDatabase.GetMoons(num3); if (moons.Count <OrbitalObjectInfo>() > 0) { float num4 = 5000f; Vector3 vector3_3 = Vector3.Zero; Vector3 forward = -Vector3.UnitZ; int num5 = 0; float num7 = 0.0f; foreach (OrbitalObjectInfo orbitalObjectInfo in moons) { PlanetInfo planetInfo = app.GameDatabase.GetPlanetInfo(orbitalObjectInfo.ID); if (planetInfo != null) { Matrix orbitalTransform = app.GameDatabase.GetOrbitalTransform(orbitalObjectInfo.ID); float lengthSquared = orbitalTransform.Position.LengthSquared; if ((double)lengthSquared > (double)num7) { num7 = lengthSquared; vector3_3 = orbitalTransform.Position; forward = -orbitalTransform.Position; num4 = StarSystemVars.Instance.SizeToRadius(planetInfo.Size) + val2; num5 = orbitalObjectInfo.ID; } } } if (num5 != 0) { Vector3 vector3_4 = Vector3.Normalize(vector3_3 - vector3_1); if ((double)Vector3.Dot(vector3_4, vector3_2) > 0.0) { double num8 = (double)forward.Normalize(); return(Matrix.CreateWorld(vector3_3 - forward * (num4 + val2), forward, Vector3.UnitY)); } Vector3 v0 = Vector3.Cross(vector3_2, Vector3.UnitY); float num9 = (double)Vector3.Dot(v0, vector3_4) > 0.0 ? 1f : -1f; return(Matrix.CreateWorld(vector3_3 + v0 * ((num4 + val2) * num9), forward, Vector3.UnitY)); } } Vector3 position1 = vector3_1 - vector3_2 * num2; if (starSystem != null) { Vector3 forward = -Vector3.UnitZ; float num4 = -1f; foreach (Ship ship in starSystem.GetStationsAroundPlanet(num3)) { Vector3 v0 = vector3_1 - ship.Maneuvering.Position; double num5 = (double)v0.Normalize(); float num7 = Vector3.Dot(v0, vector3_2); if ((double)num7 > 0.75 && (double)num7 > (double)num4) { num4 = num7; forward = v0; } } if ((double)num4 > 0.0) { Matrix world = Matrix.CreateWorld(Vector3.Zero, forward, Vector3.UnitY); Vector3 vector3_3 = vector3_1 + world.Right * num2; Vector3 vector3_4 = vector3_1 - world.Right * num2; vector3_2 = (double)(position1 - vector3_3).LengthSquared >= (double)(position1 - vector3_4).LengthSquared ? (forward - world.Right) * 0.5f : (forward + world.Right) * 0.5f; double num5 = (double)vector3_2.Normalize(); position1 = vector3_1 - vector3_2 * num2; } } return(Matrix.CreateWorld(position1, vector3_2, Vector3.UnitY)); }
public void HandleGardenerCaptured( GameSession game, GameDatabase gamedb, int playerId, int gardenerId) { GardenerInfo gardenerInfo = gamedb.GetGardenerInfo(gardenerId); if (gardenerInfo == null) { return; } FleetInfo fleetInfo = gamedb.GetFleetInfo(gardenerInfo.FleetId); if (fleetInfo == null) { return; } if (gardenerInfo.DeepSpaceSystemId.HasValue) { foreach (StationInfo stationInfo in game.GameDatabase.GetStationForSystem(gardenerInfo.DeepSpaceSystemId.Value).ToList <StationInfo>()) { game.GameDatabase.DestroyStation(game, stationInfo.ID, 0); } } fleetInfo.PlayerID = playerId; gamedb.UpdateFleetInfo(fleetInfo); FleetLocation fleetLocation = gamedb.GetFleetLocation(fleetInfo.ID, false); List <StarSystemInfo> closestStars = EncounterTools.GetClosestStars(gamedb, fleetLocation.Coords); StarSystemInfo starSystemInfo1 = (StarSystemInfo)null; foreach (StarSystemInfo starSystemInfo2 in closestStars) { int?systemOwningPlayer = gamedb.GetSystemOwningPlayer(starSystemInfo2.ID); if (systemOwningPlayer.HasValue && systemOwningPlayer.Value == playerId) { starSystemInfo1 = starSystemInfo2; break; } } if (!(starSystemInfo1 != (StarSystemInfo)null)) { return; } MissionInfo missionByFleetId = gamedb.GetMissionByFleetID(fleetInfo.ID); if (missionByFleetId != null) { gamedb.RemoveMission(missionByFleetId.ID); } MoveOrderInfo orderInfoByFleetId = gamedb.GetMoveOrderInfoByFleetID(fleetInfo.ID); if (orderInfoByFleetId != null) { gamedb.RemoveMoveOrder(orderInfoByFleetId.ID); } int missionID = gamedb.InsertMission(fleetInfo.ID, MissionType.RETURN, starSystemInfo1.ID, 0, 0, 0, false, new int?()); gamedb.InsertWaypoint(missionID, WaypointType.TravelTo, new int?(starSystemInfo1.ID)); gamedb.InsertMoveOrder(fleetInfo.ID, 0, fleetLocation.Coords, starSystemInfo1.ID, Vector3.Zero); this.SpawnProteanChaser(game, gardenerInfo); }