diff --git a/Core.cs b/Core.cs index 0da3bc3..b38ad92 100644 --- a/Core.cs +++ b/Core.cs @@ -6,10 +6,10 @@ using System.Threading; using System.IO; using System.Xml.Serialization; +using System.Runtime.InteropServices; -using Sandbox.Common.ObjectBuilders; using Sandbox; - +using SteamSDK; using SEModAPIExtensions.API.Plugin; using SEModAPIExtensions.API.Plugin.Events; @@ -18,6 +18,7 @@ using SEModAPIInternal.API.Common; using SEModAPIInternal.API.Server; +using Sandbox.Game.World; using Sandbox.ModAPI; using VRageMath; @@ -26,11 +27,6 @@ namespace SEDropship { - /*struct MaterialPositionData - { - public Vector3 Sum; - public int Count; - }*/ public class SEDropship : PluginBase, IChatEventHandler { @@ -43,7 +39,6 @@ public class SEDropship : PluginBase, IChatEventHandler private AsteroidCollection m_cache = new AsteroidCollection(); //bool m_running = true; bool m_loading = true; - List m_ignore = new List(); private bool m_debugging = false; private int m_debuglevel = 1; @@ -67,16 +62,24 @@ public override void Init() //m_running = true; m_loading = true; //build asteroid list - m_ignore.Clear(); + m_main = new Thread(mainloop); m_main.Start(); m_main.Priority = ThreadPriority.BelowNormal;//lower priority to make room for other tasks if needed. MyAPIGateway.Entities.OnEntityAdd -= OnEntityAdd; MyAPIGateway.Entities.OnEntityAdd += OnEntityAdd; + //pAM = new PersonalAsteroidManager(); + + //pAM.load(); + Console.WriteLine("SE Dropship Plugin '" + Id.ToString() + "' initialized!"); } + + + + #endregion #region "Properties" @@ -141,6 +144,23 @@ public bool requireMagnesium get { return settings.requireMagnesium; } set { settings.requireMagnesium = value; } } + [Category("Asteroid")] + [Description("Personal Roid System - Warning - could have a heavy system resource requirement!")] + [Browsable(true)] + [ReadOnly(true)]//disabled + public bool personalRoidEnabled + { + get + { + //return settings.personalRoid; + return false; + } + set + { + settings.personalRoid = false; //disabled + //settings.personalRoid = value; + } + } [Category("SE Dropship")] [Description("How fast the ship goes when it is near its target")] @@ -270,6 +290,14 @@ public int debugLevel get { return m_debuglevel; } set { m_debuglevel = value; } } + + private PersonalAsteroidManager pAM + { + get; + set; + } + + #endregion #endregion @@ -284,53 +312,43 @@ private void mainloop() m_cache.Clear(); //List asteroids = new List(); - do + + Thread.Sleep(1000); + try { - Thread.Sleep(1000); - try + if (m_loading == true) { - if (m_loading == true) - { - Console.WriteLine("Attempting to get asteroid list."); + //Console.WriteLine("Attempting to get asteroid list."); - HashSet entities = new HashSet(); - try - { + HashSet entities = new HashSet(); + MyAPIGateway.Entities.GetEntities(entities); + foreach (IMyEntity entity in entities) + { + if (!(entity is IMyVoxelMap)) + continue; + //Console.WriteLine("Found voxelmap"); + IMyVoxelMap tmpasteroid = (IMyVoxelMap)entity; - MyAPIGateway.Entities.GetEntities(entities); - } - catch + if (tmpasteroid.LocalAABB.Size.X > 120F) { - Console.WriteLine("Server busy, asteroid list unavailible, skipping"); - //asteroids.Clear(); - m_loading = true; + m_cache.Add(new SeDropshipAsteroids(tmpasteroid)); + Console.WriteLine("Adding to valid asteroid list"); } - foreach (IMyEntity entity in entities) + else { - if (!(entity is IMyVoxelMap)) - continue; - Console.WriteLine("Found voxelmap"); - IMyVoxelMap tmpasteroid = (IMyVoxelMap)entity; - - if (tmpasteroid.LocalAABB.Size.X > 120F) - { - m_cache.Add(new SeDropshipAsteroids(tmpasteroid)); - Console.WriteLine("Adding to valid asteroid list"); - } + Console.WriteLine("Asteroid too small, skipping."); + } - } } } - catch - { - Log.Info("Dropship - null reference trying again in 1 second."); - } - - } - while (m_cache.Count == 0); + catch + { + Log.Info("Dropship - null reference trying again in 1 second."); + } + refresh(); } @@ -344,13 +362,16 @@ private void refresh() foreach (SeDropshipAsteroids obj in m_cache) { //Thread.Sleep(1000); - Console.WriteLine("Inventory started on asteroid"); - //var obj = new SeDropshipAsteroids(voxelmap); bool vitalmats = false; bool has_mag = false; string name = obj.Name; + if (obj.Name.Contains("p-Roid-")) + continue; + + Console.WriteLine("Inventory started on asteroid"); try { + obj.Refresh();//refresh } catch @@ -443,9 +464,6 @@ private void OnEntityGridDetected(IMyEntity entity) } public void doDrop(IMyCubeGrid grid) { - - //if(isdebugging) - //Console.WriteLine("DoDrop called."); long Owner = 0; Thread.Sleep(1000); SandboxGameAssemblyWrapper.Instance.GameAction(() => @@ -453,42 +471,53 @@ public void doDrop(IMyCubeGrid grid) if(grid.BigOwners.Count > 0) Owner = grid.BigOwners.First(); }); - while (Loading) Thread.Sleep(1000); - //find target - - SeDropshipAsteroids asteroid = m_asteroids.First(); - if(anyAsteroid) - { - asteroid = m_asteroids.ElementAt(m_gen.Next(m_asteroids.Count)); - } - SandboxGameAssemblyWrapper.Instance.GameAction(() => - { - grid.Physics.Activate();//fixes a bug... - }); - //store target position. - Vector3D target = asteroid.center; - List steamlist = ServerNetworkManager.Instance.GetConnectedPlayers(); ulong steamid = 0; - foreach( ulong steam_id in steamlist) + foreach (ulong steam_id in steamlist) { - List playerids = PlayerMap.Instance.GetPlayerIdsFromSteamId(steam_id); + List playerids = PlayerMap.Instance.GetPlayerIdsFromSteamId(steam_id); foreach (long playerid in playerids) { - //Console.WriteLine("Connected playerid:" + playerid.ToString()); - if(playerid == Owner) + if (playerid == Owner) { steamid = steam_id; - //Console.WriteLine("Found match" + steamid.ToString()); } } } - if (m_asteroids.Count == 0) + + while (Loading && !personalRoidEnabled) Thread.Sleep(1000); + //find target + //SeDropshipAsteroids asteroid; + Vector3D target = Vector3D.Zero; + int halfextent = 0; + if (personalRoidEnabled) { - Log.Info("No asteroids, aborting drop"); - ChatManager.Instance.SendPrivateChatMessage(steamid, "Error: No valid asteroids exist within range, aborting drop."); - return; + target = pAM.targetpos(steamid); + halfextent = pAM.halfextent(steamid); + } + else + { + if( m_asteroids.Count > 0) + { + var asteroid = m_asteroids.First(); + if (anyAsteroid) + { + asteroid = m_asteroids.ElementAt(m_gen.Next(m_asteroids.Count)); + } + target = asteroid.center; + halfextent = asteroid.halfextent; + } + else + { + + Log.Info("No asteroids, aborting drop"); + ChatManager.Instance.SendPrivateChatMessage(steamid, "Error: No valid asteroids exist within range sending to 0,0,0."); + + + } + } + ChatManager.Instance.SendPrivateChatMessage(steamid, "Dropship booting up, please stay in your seat for insertion."); Thread.Sleep((int)(2000 * message_mult)); ChatManager.Instance.SendPrivateChatMessage(steamid, "If you exited your ship please return to the passenger seat before the countdown finishes."); @@ -508,30 +537,56 @@ public void doDrop(IMyCubeGrid grid) if (bootupMsg != "") ChatManager.Instance.SendPrivateChatMessage(steamid, bootupMsg); Vector3D position = Vector3D.Zero; - SandboxGameAssemblyWrapper.Instance.GameAction(() => - { - position = grid.Physics.CenterOfMassWorld; - }); - - + Console.WriteLine("getting center of mass"); + position = grid.GetPosition(); + + Console.WriteLine("calculating intercept"); Vector3D Vector3Intercept = FindInterceptVector(position, startSpeed, target, new Vector3D(0, 0, 0)); - int slowDist = slowDownDistance + asteroid.halfextent; + int slowDist = slowDownDistance + halfextent; float distance = Vector3.Distance(position,target) - slowDist; + //Console.WriteLine("moving ship!"); SandboxGameAssemblyWrapper.Instance.GameAction(() => { + //Console.WriteLine("In engine"); if (distance > teleportDistance) { + //Console.WriteLine("teleporting"); position = Vector3.Add(target, Vector3.Multiply(Vector3.Negate(Vector3.Normalize(Vector3Intercept)), teleportDistance)); - grid.SetPosition(position); + //Console.WriteLine("set grid pos"); + try + { + grid.SetPosition(position); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + Console.WriteLine(ex.StackTrace.ToString()); + + } + } + }); + + + Thread.Sleep(1000); + + SandboxGameAssemblyWrapper.Instance.GameAction(() => + { + try + { + position = grid.GetPosition(); distance = Vector3.Distance(position, target) - slowDist; + var matrix = grid.Physics.GetWorldMatrix(); + matrix.Forward = Vector3D.Normalize(Vector3Intercept); + grid.SetWorldMatrix(matrix); + grid.Physics.LinearVelocity = (Vector3)Vector3Intercept; } - //grid.Physics. - var matrix = grid.Physics.GetWorldMatrix(); - matrix.Forward = Vector3.Normalize(Vector3Intercept); - grid.SetWorldMatrix(matrix); - grid.Physics.LinearVelocity = (Vector3)Vector3Intercept; + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + }); - //LogManager.APILog.WriteLineAndConsole("Total Distance to target: " + distance.ToString()); + Console.WriteLine("out engine"); float timeToSlow = distance / startSpeed; float timeToCollision = Vector3.Distance(Vector3.Subtract(target, Vector3.Multiply(Vector3.Normalize(Vector3Intercept), slowDist)), target) / slowSpeed; @@ -558,7 +613,15 @@ public void doDrop(IMyCubeGrid grid) ChatManager.Instance.SendPrivateChatMessage(steamid, "Welcome to your destination, pod will attempt to land. If navigation calculations were off it will automatically stop the pod in " + ((int)timeToCollision*2).ToString() + " seconds. Have a nice day!"); SandboxGameAssemblyWrapper.Instance.GameAction(() => { - grid.Physics.LinearVelocity = (Vector3)Vector3D.Multiply(Vector3D.Normalize(Vector3Intercept), slowSpeed); + try + { + grid.Physics.LinearVelocity = (Vector3)Vector3D.Multiply(Vector3D.Normalize(Vector3Intercept), slowSpeed); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + }); Thread.Sleep(1000); @@ -568,12 +631,16 @@ public void doDrop(IMyCubeGrid grid) Thread.Sleep((int)timeToCollision * 2 * 1000); SandboxGameAssemblyWrapper.Instance.GameAction(() => { - grid.Physics.LinearVelocity = new Vector3(0, 0, 0); - grid.Physics.AngularVelocity = new Vector3(0, 0, 0); - //grid.SyncObject.UpdatesOnlyOnServer = updatesonserver; + try + { + grid.Physics.LinearVelocity = new Vector3(0, 0, 0); + grid.Physics.AngularVelocity = new Vector3(0, 0, 0); + } + catch (Exception ex) + { + Console.Write(ex.ToString()); + } }); - - } public void saveXML() { @@ -619,7 +686,7 @@ public void loadXML(bool defaults = false) try { Log.Warn("Could not load configuration: " + ex.ToString()); } catch { Console.WriteLine("Could not load and write to log: " + ex.ToString()); } } - + } #endregion @@ -633,6 +700,8 @@ public override void Update() public override void Shutdown() { //m_running = false; + + MyAPIGateway.Entities.OnEntityAdd -= OnEntityAdd; saveXML(); return; } @@ -641,7 +710,11 @@ public override void Shutdown() public void OnEntityAdd(IMyEntity entity) { OnEntityGridDetected(entity); - + /*if (entity is IMyVoxelMap) + { + IMyVoxelMap tmpasteroid = (IMyVoxelMap)entity; + Console.WriteLine(string.Format("N:{0} R:{1} E:{2}", tmpasteroid.StorageName.ToString(), Math.Floor(tmpasteroid.LocalVolume.Radius / 2), tmpasteroid.LocalAABB.HalfExtents.AbsMax().ToString())); + }*/ } public void OnChatReceived(ChatManager.ChatEvent chatEvent) @@ -656,7 +729,15 @@ public void OnChatSent(ChatManager.ChatEvent chatEvent) return; } + private void OnClientLeft(ulong arg1, ChatMemberStateChangeEnum arg2) + { + } + + private void OnClientJoined(ulong obj) + { + pAM.loadClient(obj); + } #endregion @@ -675,6 +756,12 @@ private void HandleChatMessage(ChatManager.ChatEvent _event) commandLoadDefaults(_event); if (words[0] == "/ds-refresh" && isadmin) commandRefresh(_event); + if (words[0] == "/ds-test") + { + Console.WriteLine("beginning test"); + commandTest(_event); + + } } @@ -728,7 +815,91 @@ public void commandRefresh(ChatManager.ChatEvent _event) //donothing } } + public void commandTest(ChatManager.ChatEvent _event) + { + //Thread T = new Thread(Experiment); + //T.Start(); + } + + private void Experiment() + { + int i = 0; + var pos = new Vector3D(10000, 10000, 10000); + SandboxGameAssemblyWrapper.Instance.GameAction(() => + { + MyWorldGenerator.AddAsteroidPrefab("AsteroidBase2", pos + new Vector3D(0,0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("AsteroidSpaceStation", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("Barths_moon_base", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("barths_moon_camp", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("Bioresearch", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("Chinese_Corridor_Tunnel_256x256x256", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("EacPrisonAsteroid", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("EngineersOutpost", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("hopebase512", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("Junkyard_RaceAsteroid_256x256x256", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("JunkYardToxic_128x128x128", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("PirateBaseStaticAsteroid_A_5000m_1", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("PirateBaseStaticAsteroid_A_5000m_2", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("Russian_Transmitter_2", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("ScratchedBoulder_128x128x128", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("small_overhang_flat", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("Small_Pirate_Base_Asteroid", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("TorusWithManyTunnels_256x128x256", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("TorusWithSmallTunnel_256x128x256", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("VangelisBase", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + MyWorldGenerator.AddAsteroidPrefab("VerticalIslandStorySector_128x256x128", pos + new Vector3D(0, 0, i++ * 10000), string.Format("p-Roid-{0}", i++)); + }); + /* +N:p-Roid-1 R:443 E:256 +N:p-Roid-3 R:221 E:128 +N:p-Roid-5 R:221 E:128 +N:p-Roid-7 R:221 E:128 +N:p-Roid-9 R:221 E:128 +N:p-Roid-11 R:221 E:128 +N:p-Roid-13 R:443 E:256 +N:p-Roid-15 R:221 E:128 +N:p-Roid-17 R:443 E:256 +N:p-Roid-19 R:221 E:128 +N:p-Roid-21 R:110 E:64 +N:p-Roid-23 R:443 E:256 +N:p-Roid-25 R:443 E:256 +N:p-Roid-27 R:221 E:128 +N:p-Roid-29 R:110 E:64 +N:p-Roid-31 R:110 E:64 +N:p-Roid-33 R:110 E:64 +N:p-Roid-35 R:221 E:128 +N:p-Roid-37 R:221 E:128 +N:p-Roid-39 R:221 E:128 +N:p-Roid-41 R:221 E:128 + */ + + } #endregion #endregion + + new public Guid Id + { + get + { + GuidAttribute guidAttr = (GuidAttribute)typeof(SEDropship).Assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0]; + return new Guid(guidAttr.Value); + } + } + + new public string Name + { + get + { + return "SE-Dropship"; + } + } + + new public Version Version + { + get + { + return typeof( SEDropship ).Assembly.GetName().Version; + } + } } } diff --git a/PersonalAsteroid.cs b/PersonalAsteroid.cs new file mode 100644 index 0000000..a05c844 --- /dev/null +++ b/PersonalAsteroid.cs @@ -0,0 +1,161 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using VRageMath; + +using SEModAPIInternal.API.Common; + +using Sandbox.Game.World; +using VRage.Utils; + +namespace SEDropship +{ + [Serializable()] + public class PersonalAsteroid + { + public Vector3I field; + public ulong user; + private Random m_rand; + private static readonly Dictionary LargePrefabs + = new Dictionary + { + + { "EacPrisonAsteroid", 222 }, + { "hopebase512", 222 }, + { "PirateBaseStaticAsteroid_A_5000m_1", 222 }, + { "PirateBaseStaticAsteroid_A_5000m_2", 222 } + + }; + + private static readonly Dictionary SmallPrefabs + = new Dictionary + { + { "AsteroidBase2", 111 }, + { "AsteroidSpaceStation", 111 }, + { "Barths_moon_base", 111 }, + { "barths_moon_camp", 111 }, + { "Bioresearch", 111 }, + { "Chinese_Corridor_Tunnel_256x256x256", 111 }, + { "EngineersOutpost", 111 }, + { "Junkyard_RaceAsteroid_256x256x256", 111 }, + { "Russian_Transmitter_2", 111 }, + { "TorusWithManyTunnels_256x128x256", 111 }, + { "TorusWithSmallTunnel_256x128x256", 111 }, + { "VangelisBase", 111 }, + { "VerticalIslandStorySector_128x256x128", 111 }, + { "JunkYardToxic_128x128x128", 55 }, + { "ScratchedBoulder_128x128x128", 55 }, + { "small_overhang_flat", 55 }, + { "Small_Pirate_Base_Asteroid", 55 } + + }; + + public Vector3D center { get; set; } + public int halfextent { get; set; } + internal PersonalAsteroid() + { + + } + public PersonalAsteroid(Vector3I newField, ulong uid) + { + m_rand = new Random((int)DateTime.UtcNow.ToBinary()); + user = uid; + this.field = newField; + generateField(); + } + + private void generateField() + { + int i = 0; + Console.WriteLine("Generating field"); + //spawn home asteroid + int pick = m_rand.Next(LargePrefabs.Count); + Vector3D pos = field; + //pos = pos * SEDropshipSettings.FieldSize;//home position + Console.WriteLine("Setting Home Position"); + pos.X = (pos.X * SEDropshipSettings.FieldSize) + (m_rand.NextDouble() * 40000 - 20000); + pos.Y = (pos.Y * SEDropshipSettings.FieldSize) + (m_rand.NextDouble() * 40000 - 20000); + pos.Z = (pos.Z * SEDropshipSettings.FieldSize) + (m_rand.NextDouble() * 40000 - 20000); + Console.WriteLine(pos.ToString()); + center = pos; + halfextent = LargePrefabs.ElementAt(pick).Value; + pos.X -= halfextent; + pos.Y -= halfextent; + pos.Z -= halfextent; + Console.WriteLine("Spawning home roid"); + SandboxGameAssemblyWrapper.Instance.GameAction(() => + { + try + { + MyWorldGenerator.AddAsteroidPrefab(LargePrefabs.First().Key, pos, string.Format("p-Roid-{0}_{1}", i, user)); + } + catch (Exception ex) + { + MyLog.Default.WriteLineAndConsole(ex.ToString()); + MyLog.Default.WriteLineAndConsole(ex.StackTrace.ToString()); + throw ex; + } + }); + + + //spawn second large asteroid + i++; + var randvector = Vector3.Multiply(Vector3.Normalize(new Vector3D(m_rand.NextDouble() - 0.5, m_rand.NextDouble() - 0.5, m_rand.NextDouble() - 0.5)), 1500); + var newpos = pos + randvector; + pick = m_rand.Next(SmallPrefabs.Count); + string _roid = SmallPrefabs.ElementAt(pick).Key; + int _halfextent = SmallPrefabs[_roid]; + newpos.X -= _halfextent; + newpos.Y -= _halfextent; + newpos.Z -= _halfextent; + Console.WriteLine("spawning second roid"); + SandboxGameAssemblyWrapper.Instance.GameAction(() => + { + try + { + MyWorldGenerator.AddAsteroidPrefab(_roid, newpos, string.Format("p-Roid-{0}_{1}", i, user)); + } + catch (Exception ex) + { + MyLog.Default.WriteLineAndConsole(ex.ToString()); + MyLog.Default.WriteLineAndConsole(ex.StackTrace.ToString()); + throw ex; + } + }); + + //spawn small asteroids + while (i < 5) + { + i++; + randvector = Vector3.Multiply(Vector3.Normalize(new Vector3D(m_rand.NextDouble()-0.5, m_rand.NextDouble() - 0.5, m_rand.NextDouble() - 0.5)), 1500 + i*500); + newpos = pos + randvector; + pick = m_rand.Next(LargePrefabs.Count); + _roid = SmallPrefabs.ElementAt(pick).Key; + _halfextent = SmallPrefabs[_roid]; + newpos.X -= _halfextent; + newpos.Y -= _halfextent; + newpos.Z -= _halfextent; + Console.WriteLine("Spawning " + i.ToString() + " + 2 roid."); + SandboxGameAssemblyWrapper.Instance.GameAction(() => + { + try + { + MyWorldGenerator.AddAsteroidPrefab(_roid, newpos, string.Format("p-Roid-{0}_{1}", i, user)); + } + catch (Exception ex) + { + MyLog.Default.WriteLineAndConsole(ex.ToString()); + MyLog.Default.WriteLineAndConsole(ex.StackTrace.ToString()); + throw ex; + } + }); + } + + + + } + + + } +} diff --git a/PersonalAsteroidClass.cs b/PersonalAsteroidClass.cs new file mode 100644 index 0000000..25eaa96 --- /dev/null +++ b/PersonalAsteroidClass.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Xml.Serialization; +using System.IO; + +using VRageMath; +using Sandbox; +using Sandbox.ModAPI; + +namespace SEDropship +{ + [Serializable()] + public class PersonalAsteroidManager + { + [NonSerialized] + private Dictionary m_cache = new Dictionary(); + //private List m_clients = new List(); + [NonSerialized] + private long m_pos = 2; + + internal PersonalAsteroidManager() { } + public List m_savedata + { + get; set; + } + public long pos + { + get + { + return m_pos; + + } + set + { + m_pos = value; + } + } + internal void load() + { + try + { + m_savedata = new List(); + if (File.Exists(Location + "SE-Personal-Asteroid.xml")) + { + + XmlSerializer x = new XmlSerializer(typeof(PersonalAsteroidManager)); + TextReader reader = new StreamReader(Location + "SE-Personal-Asteroid.xml"); + PersonalAsteroidManager obj = (PersonalAsteroidManager)x.Deserialize(reader); + pos = obj.pos; + m_savedata = obj.m_savedata; + reader.Close(); + sync(); + + return; + } + + } + catch (Exception) + { + //do nothin + Console.WriteLine("Exception thrown while loading."); + } + } + + private void sync() + { + foreach( var wrapper in m_savedata) + { + m_cache.Add(wrapper.id, wrapper.roid); + } + } + + internal void loadClient(ulong obj) + { + + //save(); + } + + private void save() + { + //save settings and trigger world save + XmlSerializer x = new XmlSerializer(typeof(PersonalAsteroidManager)); + TextWriter writer = new StreamWriter(Location + "SE-Personal-Asteroid.xml"); + x.Serialize(writer, this); + writer.Close(); + Console.WriteLine("Saving"); + MyAPIGateway.Session.Save(); + } + + + + public Vector3I getNewFieldLocation() + { + m_pos++; + + Vector3I val = Vector3I.Zero; + val.Z = (int)(m_pos % 3)-1; + long div = m_pos / 3; + long edge = (long)Math.Floor(Math.Sqrt(div)); + if ((edge % 2) == 0) + { + edge--; + } + edge = edge / 2; + edge++; + + //now we have our edge + val.X = (int)-edge; + val.Y = (int)-edge; + + int pos = (int)(div - ((edge*2-1) * (edge * 2 - 1))); + + + switch (pos % 4) + { + case 0: + val.X += pos / 4; + val.Y *= -1; + break; + case 1: + val.X *= -1; + val.Y *= -1; + val.Y -= pos / 4; + break; + case 2: + val.X *= -1; + val.X -= pos / 4; + val.Y += 0; + break; + case 3: + val.X += 0; + val.Y += pos / 4 ; + break; + } + + return val; + } + + internal Vector3D targetpos(ulong steamid) + { + if (!m_cache.ContainsKey(steamid)) + { + createEntry(steamid); + } + return m_cache[steamid].center; + } + + private void createEntry(ulong steamid) + { + Console.WriteLine("Creating roid"); + var roid = new PersonalAsteroid(getNewFieldLocation(), steamid); + Console.WriteLine("Adding to m_cache"); + m_cache.Add(steamid, roid); + Console.WriteLine("Adding to savedata"); + m_savedata.Add(new PersonalWrapper(steamid, roid)); + Console.WriteLine("Initiating save"); + save(); + } + + internal int halfextent(ulong steamid) + { + if (!m_cache.ContainsKey(steamid)) + { + createEntry(steamid); + save(); + } + return m_cache[steamid].halfextent; + } + + public string DefaultLocation + { + get { return System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\"; } + + } + + public string Location + { + get { return MySandboxGame.ConfigDedicated.LoadWorld + "\\"; } + } + + + } + [Serializable()] + public class PersonalWrapper + { + public PersonalWrapper(ulong steamid, PersonalAsteroid roid) + { + id = steamid; + this.roid = roid; + } + public PersonalWrapper() { } + + public ulong id { get; set; } + public PersonalAsteroid roid { get; set; } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 5c537da..6c61fea 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("0.5.4.4")] -[assembly: AssemblyFileVersion("0.5.4.4")] +[assembly: AssemblyVersion("0.5.5.0")] +[assembly: AssemblyFileVersion("0.5.5.0")] diff --git a/SE-Dropship.csproj b/SE-Dropship.csproj index 4a8f217..4f355ed 100644 --- a/SE-Dropship.csproj +++ b/SE-Dropship.csproj @@ -38,6 +38,8 @@ + + @@ -84,6 +86,10 @@ C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\SpaceEngineersDedicated.exe + + False + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\DedicatedServer64\SteamSDK.dll + diff --git a/SE-Dropship.sln b/SE-Dropship.sln index e0f50ed..b284176 100644 --- a/SE-Dropship.sln +++ b/SE-Dropship.sln @@ -1,7 +1,6 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SE-Dropship", "SE-Dropship.csproj", "{DBB92823-BD91-42CA-ADC5-5ABED872EF13}" EndProject diff --git a/SE-Dropship.v12.suo b/SE-Dropship.v12.suo index 43a766c..8253efb 100644 Binary files a/SE-Dropship.v12.suo and b/SE-Dropship.v12.suo differ diff --git a/SEDropshipSettings.cs b/SEDropshipSettings.cs index d9c6c15..d9439a9 100644 --- a/SEDropshipSettings.cs +++ b/SEDropshipSettings.cs @@ -10,6 +10,7 @@ public class SEDropshipSettings { private int m_slowDownDistance = 250; private bool m_anyAsteroid = true; + private bool m_personalRoid; private float m_slowSpeed = 5.0F; private float m_startSpeed = 104.4F; private int m_countdown = 10; @@ -23,6 +24,8 @@ public class SEDropshipSettings private double m_messageMult = 1.0d; private string m_whitelistKeyword = ""; + public static long FieldSize = 50000; + public int slowDownDistance { get { return m_slowDownDistance; } @@ -108,5 +111,17 @@ public string whitelistKeyword get { return m_whitelistKeyword; } set { m_whitelistKeyword = value; } } - } + + public bool personalRoid + { + get + { + return m_personalRoid; + } + set + { + m_personalRoid = value; + } + } + } } diff --git a/SeDropshipAsteroids.cs b/SeDropshipAsteroids.cs index ab99e74..964a3e4 100644 --- a/SeDropshipAsteroids.cs +++ b/SeDropshipAsteroids.cs @@ -232,18 +232,18 @@ public class SeDropshipAsteroids private string m_name; private int m_halfextent; - private static MyVoxelMaterialDefinition m_irondef = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Iron_01"); - private static MyVoxelMaterialDefinition m_irondef2 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Iron_02"); - private static MyVoxelMaterialDefinition m_nickeldef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Nickel_01"); - private static MyVoxelMaterialDefinition m_cobaltdef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Cobalt_01"); - private static MyVoxelMaterialDefinition m_magnesiumdef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Magnesium_01"); - private static MyVoxelMaterialDefinition m_silicondef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Silicon_01"); - private static MyVoxelMaterialDefinition m_silverdef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Silver_01"); - private static MyVoxelMaterialDefinition m_golddef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Gold_01"); - private static MyVoxelMaterialDefinition m_platinumdef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Platinum_01"); - private static MyVoxelMaterialDefinition m_uraniumdef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Uraninite_01"); - private static MyVoxelMaterialDefinition m_icedef1 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Ice_01"); - private static MyVoxelMaterialDefinition m_icedef2 = Sandbox.Definitions.MyDefinitionManager.Static.GetVoxelMaterialDefinition("Ice_02"); + private static MyVoxelMaterialDefinition m_irondef = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Iron_01"); + private static MyVoxelMaterialDefinition m_irondef2 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Iron_02"); + private static MyVoxelMaterialDefinition m_nickeldef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Nickel_01"); + private static MyVoxelMaterialDefinition m_cobaltdef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Cobalt_01"); + private static MyVoxelMaterialDefinition m_magnesiumdef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Magnesium_01"); + private static MyVoxelMaterialDefinition m_silicondef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Silicon_01"); + private static MyVoxelMaterialDefinition m_silverdef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Silver_01"); + private static MyVoxelMaterialDefinition m_golddef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Gold_01"); + private static MyVoxelMaterialDefinition m_platinumdef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Platinum_01"); + private static MyVoxelMaterialDefinition m_uraniumdef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Uraninite_01"); + private static MyVoxelMaterialDefinition m_icedef1 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Ice_01"); + private static MyVoxelMaterialDefinition m_icedef2 = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Ice_02"); @@ -255,6 +255,10 @@ public SeDropshipAsteroids(IMyVoxelMap asteroid) calculateSize(); } + public SeDropshipAsteroids() + { + } + private void calculateSize() { try