diff --git a/Libraries/SEModAPI.dll b/Libraries/SEModAPI.dll index d26bd3b..1d89965 100644 Binary files a/Libraries/SEModAPI.dll and b/Libraries/SEModAPI.dll differ diff --git a/Libraries/SEModAPIExtensions.dll b/Libraries/SEModAPIExtensions.dll index 0daa280..761a79e 100644 Binary files a/Libraries/SEModAPIExtensions.dll and b/Libraries/SEModAPIExtensions.dll differ diff --git a/Libraries/SEModAPIInternal.dll b/Libraries/SEModAPIInternal.dll index a1b7dbf..882a178 100644 Binary files a/Libraries/SEModAPIInternal.dll and b/Libraries/SEModAPIInternal.dll differ diff --git a/Libraries/VRage.Common.dll b/Libraries/VRage.Common.dll new file mode 100644 index 0000000..b11ecc5 Binary files /dev/null and b/Libraries/VRage.Common.dll differ diff --git a/WarpDrivePlugin/Core.cs b/WarpDrivePlugin/Core.cs index f25fe65..5996f70 100644 --- a/WarpDrivePlugin/Core.cs +++ b/WarpDrivePlugin/Core.cs @@ -3,18 +3,36 @@ using System.Linq; using System.Text; +using Sandbox.Common.ObjectBuilders; + +using SEModAPIExtensions.API.Plugin; using SEModAPIExtensions.API.Plugin.Events; +using SEModAPIInternal.API.Common; +using SEModAPIInternal.API.Entity; using SEModAPIInternal.API.Entity.Sector.SectorObject; +using SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid; +using SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock; + +using VRageMath; -namespace SEModAPIExtensions.API.Plugin +namespace WarpDrivePlugin { - public class Core : PluginBase + public class Core : PluginBase, ICubeGridHandler, IBaseEntityHandler { + #region "Attributes" + + private DateTime m_lastMovementTime; + private TimeSpan m_timeSinceLastMovement; + + #endregion + #region "Constructors and Initializers" public Core() { + m_timeSinceLastMovement = new TimeSpan(); + Console.WriteLine("WarpDrivePlugin '" + Id.ToString() + "' constructed!"); } @@ -29,7 +47,73 @@ public override void Init() public override void Update() { - //Console.WriteLine("WarpDrivePlugin '" + Id.ToString() + "' updated!"); + } + + public void OnCubeGridMoved(CubeGridEntity cubeGrid) + { + } + + public void OnCubeGridCreated(CubeGridEntity cubeGrid) + { + } + + public void OnCubeGridDeleted(CubeGridEntity cubeGrid) + { + } + + public void OnBaseEntityMoved(BaseEntity entity) + { + if (entity.GetType() == typeof(CubeGridEntity)) + { + CubeGridEntity cubeGrid = (CubeGridEntity)entity; + + Vector3 velocity = cubeGrid.LinearVelocity; + float speed = velocity.Length(); + + if (speed > 1) + { + if (speed > 100) + { + //if(SandboxGameAssemblyWrapper.IsDebugging) + //Console.WriteLine("WarpDrivePlugin - Ship '" + cubeGrid.Name + "' is moving very fast!"); + + m_timeSinceLastMovement = DateTime.Now - m_lastMovementTime; + + List cubeBlocks = cubeGrid.CubeBlocks; + if (cubeGrid.GridSizeEnum == MyCubeSize.Large) + { + //Search for a warp reactor on the ship + ReactorEntity warpReactor = null; + foreach (CubeBlockEntity cubeBlock in cubeBlocks) + { + if (cubeBlock.GetType() == typeof(ReactorEntity)) + { + ReactorEntity reactor = (ReactorEntity)cubeBlock; + if (reactor.Name == "WarpEngine") + { + warpReactor = reactor; + break; + } + } + } + + //If we found a warp reactor then run the warp procedure + if (warpReactor != null) + { + WarpEngine engine = new WarpEngine(warpReactor); + bool result = engine.Warp(); + } + } + } + else + { + //if (SandboxGameAssemblyWrapper.IsDebugging) + //Console.WriteLine("WarpDrivePlugin - Ship '" + cubeGrid.Name + "' is moving!"); + } + } + } + + m_lastMovementTime = DateTime.Now; } #endregion diff --git a/WarpDrivePlugin/Properties/AssemblyInfo.cs b/WarpDrivePlugin/Properties/AssemblyInfo.cs index 3ba3c71..e20ba42 100644 --- a/WarpDrivePlugin/Properties/AssemblyInfo.cs +++ b/WarpDrivePlugin/Properties/AssemblyInfo.cs @@ -20,7 +20,7 @@ [assembly: ComVisible(true)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("b0933c38-1234-4d18-b1dc-ef5a054a6ac2")] +[assembly: Guid("b0933c38-1234-5678-b1dc-ef5a054a6ac2")] // Version information for an assembly consists of the following four values: // diff --git a/WarpDrivePlugin/WarpDrivePlugin.csproj b/WarpDrivePlugin/WarpDrivePlugin.csproj index c42f852..9ed5244 100644 --- a/WarpDrivePlugin/WarpDrivePlugin.csproj +++ b/WarpDrivePlugin/WarpDrivePlugin.csproj @@ -44,6 +44,9 @@ + + ..\Libraries\Sandbox.Common.dll + ..\Libraries\Sandbox.Common.XmlSerializers.dll @@ -58,6 +61,12 @@ + + ..\Libraries\VRage.Common.dll + + + ..\Libraries\VRage.Math.dll +