-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed crash bugs - prepwork for new feature (currently disabled)
- Loading branch information
1 parent
63fcc49
commit ec6bb5e
Showing
9 changed files
with
665 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, int> LargePrefabs | ||
= new Dictionary<string, int> | ||
{ | ||
|
||
{ "EacPrisonAsteroid", 222 }, | ||
{ "hopebase512", 222 }, | ||
{ "PirateBaseStaticAsteroid_A_5000m_1", 222 }, | ||
{ "PirateBaseStaticAsteroid_A_5000m_2", 222 } | ||
|
||
}; | ||
|
||
private static readonly Dictionary<string, int> SmallPrefabs | ||
= new Dictionary<string, int> | ||
{ | ||
{ "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; | ||
} | ||
}); | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ulong, PersonalAsteroid> m_cache = new Dictionary<ulong, PersonalAsteroid>(); | ||
//private List<ulong> m_clients = new List<ulong>(); | ||
[NonSerialized] | ||
private long m_pos = 2; | ||
|
||
internal PersonalAsteroidManager() { } | ||
public List<PersonalWrapper> m_savedata | ||
{ | ||
get; set; | ||
} | ||
public long pos | ||
{ | ||
get | ||
{ | ||
return m_pos; | ||
|
||
} | ||
set | ||
{ | ||
m_pos = value; | ||
} | ||
} | ||
internal void load() | ||
{ | ||
try | ||
{ | ||
m_savedata = new List<PersonalWrapper>(); | ||
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.