private void FindNearbyStuff() { var bs = new BoundingSphereD(Ship.GetPosition(), ConquestMod.MaxEngagementRange); var ents = MyAPIGateway.Entities.GetEntitiesInSphere(ref bs); var closeBy = ents;//entitiesFiltered.Where(z => (z.GetPosition() - drone.GetPosition()).Length() < MaxEngagementRange).ToList(); //var closeAsteroids = asteroids.Where(z => (z.GetPosition() - drone.GetPosition()).Length() < MaxEngagementRange).ToList(); ClearNearbyObjects(); foreach (var closeItem in closeBy) { try { if (closeItem is IMyCubeGrid && !closeItem.Transparent && closeItem.Physics.Mass > 2000) { AddNearbyFloatingItem(closeItem); } if (closeItem is IMyVoxelBase) { ConquestDroneManager.GetInstance().AddDiscoveredAsteroid(closeItem as IMyVoxelBase); AddNearbyAsteroid((IMyVoxelBase)closeItem); } } catch { //This catches duplicate key entries being put in KnownEntities. } } }
public static ConquestDroneManager GetInstance() { if (_instance == null) { _instance = new ConquestDroneManager(); } return(_instance); }
public static ConquestDroneManager GetInstance() { if (_instance == null) { _instance = new ConquestDroneManager(); } return _instance; }
public void Update(int ticks) { try { if (cManager == null) { cManager = ConquestDroneManager.GetInstance(); pManager = PlayerDroneManager.GetInstance(); } if (ticks % _logSaveRate == 0) { Util.SaveLogs(); } if (ticks % _loadSaveSettingsRate == 0) { Util.GetInstance().LoadCustomGameSettings(); Util.GetInstance() .Log("[ConquestMod.Update] loaded game settings -> player droneCount:" + Util.GameSettings.MaxPlayerDroneCount + " conquest dronepersquad:" + Util.GameSettings.MaxNumDronesPerConquestSquad + " conquest numdronesquads:" + Util.GameSettings.MaxNumConquestSquads, "ConquestMod.txt"); if (!displayedHelp) { Util.GetInstance().Help(); displayedHelp = true; } } if (ticks % _conquestUpdateRate == 0) { FindAllDrones(); //CalculateDistances(); pManager.Update(); cManager.Update(); } if (ticks % _findDroneRate == 0) { Util.GetInstance() .Log( "[ConquestMod.Update] loaded game settings -> player Building drones:" + GetDrones().Count, "ConquestMod.txt"); cManager.RebuildLostDrones(); } } catch (Exception e) { Util.GetInstance().LogError(e.ToString()); } }
public void Update(int ticks) { try { if (cManager == null) { cManager = ConquestDroneManager.GetInstance(); pManager = PlayerDroneManager.GetInstance(); } if (ticks%_logSaveRate == 0) { Util.SaveLogs(); } if (ticks%_loadSaveSettingsRate == 0) { Util.GetInstance().LoadCustomGameSettings(); Util.GetInstance() .Log("[ConquestMod.Update] loaded game settings -> player droneCount:" + Util.GameSettings.MaxPlayerDroneCount + " conquest dronepersquad:" + Util.GameSettings.MaxNumDronesPerConquestSquad + " conquest numdronesquads:" + Util.GameSettings.MaxNumConquestSquads, "ConquestMod.txt"); if (!displayedHelp) { Util.GetInstance().Help(); displayedHelp = true; } } if (ticks%_conquestUpdateRate == 0) { FindAllDrones(); //CalculateDistances(); pManager.Update(); cManager.Update(); } if (ticks%_findDroneRate == 0) { Util.GetInstance() .Log( "[ConquestMod.Update] loaded game settings -> player Building drones:" + GetDrones().Count, "ConquestMod.txt"); cManager.RebuildLostDrones(); } } catch (Exception e) { Util.GetInstance().LogError(e.ToString()); } }
public ConquestDrone SpawnShip(ConquestDrones type, Vector3D location) { try { var t = MyDefinitionManager.Static.GetPrefabDefinition(map[type]); var customT = MyDefinitionManager.Static.GetPrefabDefinition(mapCustom[type]); if (customT != null) { t = customT; Util.GetInstance().Log("SPAWNING CUSTOM: " + mapCustom[type], "Spawner.txt"); } if (t == null) { Util.GetInstance().Log("Failed To Load Ship: " + map[type], "Spawner.txt"); return(null); } var s = t.CubeGrids; s = (MyObjectBuilder_CubeGrid[])s.Clone(); if (s.Length == 0) { return(null); } Vector3I min = Vector3I.MaxValue; Vector3I max = Vector3I.MinValue; s[0].CubeBlocks.ForEach(b => min = Vector3I.Min(b.Min, min)); s[0].CubeBlocks.ForEach(b => max = Vector3I.Max(b.Min, max)); float size = new Vector3(max - min).Length(); var freeplace = MyAPIGateway.Entities.FindFreePlace(location, size * 5f); if (freeplace == null) { return(null); } var newPosition = (Vector3D)freeplace; var grid = s[0]; if (grid == null) { Util.GetInstance().Log("A CubeGrid is null!", "Spawner.txt"); return(null); } List <IMyCubeGrid> shipMade = new List <IMyCubeGrid>(); var spawnpoint = GetPositionWithinAnyPlayerViewDistance(newPosition); var safespawnpoint = MyAPIGateway.Entities.FindFreePlace(spawnpoint, size * 5f); spawnpoint = safespawnpoint is Vector3D ? (Vector3D)safespawnpoint : new Vector3D(); //to - from var direction = newPosition - spawnpoint; var finalSpawnPoint = (direction / direction.Length()) * (MyAPIGateway.Session.SessionSettings.ViewDistance * .85); MyAPIGateway.PrefabManager.SpawnPrefab(shipMade, map[type], finalSpawnPoint, Vector3.Forward, Vector3.Up, Vector3.Zero, default(Vector3), null, SpawningOptions.None, 0L, true); //MyAPIGateway.PrefabManager.SpawnPrefab(shipMade, map[type], newPosition, Vector3.Forward, Vector3.Up); foreach (var ship in shipMade) { ship.Physics.ForceActivate(); ship.DisplayName = ""; ship.Name = ""; try { if (type != ConquestDrones.LargeOne) { ConquestDroneManager.GetInstance().AddDrone(new ConquestDrone(ship, BroadcastingTypes.Antenna)); } else { ConquestDroneManager.GetInstance().AddMothership(new MothershipDrone(ship, BroadcastingTypes.Antenna)); } Util.GetInstance().Log("Turning the grid to a drone was a success!!", "Spawner.txt"); } catch (Exception e) { MyAPIGateway.Entities.RemoveEntity(ship); Util.GetInstance().Log("The grid was a fake!!!", "Spawner.txt"); } } //var gridBuilder = (Sandbox.Common.ObjectBuilders.MyObjectBuilder_CubeGrid) grid.Clone(); //gridBuilder.PositionAndOrientation = // (new VRage.MyPositionAndOrientation(newPosition, // grid.PositionAndOrientation.Value.Forward, grid.PositionAndOrientation.Value.Up)); //MyAPIGateway.Entities.RemapObjectBuilder(grid); //var tmp = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(grid); ////MyAPIGateway.Entities.AddEntity(tmp); ////MyAPIGateway.Entities.RegisterForUpdate(tmp); ////MyAPIGateway.Entities.RegisterForDraw(tmp); //if(!tmp.InScene) // Util.GetInstance().Log("Not In Scene", "Spawner.txt"); //else // Util.GetInstance().Log("In Scene", "Spawner.txt"); //tmp.NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME; //ConquestDrone drone = new ConquestDrone(tmp, BroadcastingTypes.Antenna); return(null); } catch (Exception e) { Util.GetInstance().LogError(e.ToString()); } return(null); }