Skip to content

Commit

Permalink
-Changed fuel consumption to be based on ship mass
Browse files Browse the repository at this point in the history
-Added method to check for players in cockpits (disabled for now)
-Updated SEModAPI libraries
  • Loading branch information
chessmaster42 committed Jul 7, 2014
1 parent 5e6e696 commit 817d89c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
Binary file modified Libraries/SEModAPIExtensions.dll
Binary file not shown.
Binary file modified Libraries/SEModAPIInternal.dll
Binary file not shown.
8 changes: 8 additions & 0 deletions WarpDrivePlugin/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public void OnBaseEntityMoved(BaseEntity entity)
}
}

public void OnBaseEntityCreated(BaseEntity entity)
{
}

public void OnBaseEntityDeleted(BaseEntity entity)
{
}

#endregion

protected List<ReactorEntity> GetCubeGridReactors(CubeGridEntity cubeGrid)
Expand Down
51 changes: 45 additions & 6 deletions WarpDrivePlugin/WarpEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Timers;

using SEModAPIInternal.API.Entity;
using SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid;
using SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock;
using SEModAPIInternal.Support;

Expand Down Expand Up @@ -36,7 +37,11 @@ public WarpEngine(ReactorEntity reactor)
{
m_linkedReactor = reactor;

m_warpFuelRequired = 100;
if (m_linkedReactor.Parent.Mass > 0)
m_warpFuelRequired = 25.0f + 0.00001f * m_linkedReactor.Parent.Mass;
else
m_warpFuelRequired = 100f;

m_warpDuration = 2000;
m_warpSpeedFactor = 100;

Expand Down Expand Up @@ -75,7 +80,7 @@ public bool IsWarping

public float WarpFuel
{
get { return m_warpFuelRequired; }
get { return m_warpFuelRequired; }
}

public float WarpDuration
Expand All @@ -92,11 +97,14 @@ public bool CanWarp
{
get
{
//These checks are arranged in order of least complex to most complex
//This is to ensure that the checks are going as fast as possible

if (m_isWarping) //Already warping
return false;
if (m_linkedReactor.Enabled == false) //Reactor is off
return false;
if (m_linkedReactor.Fuel < m_warpFuelRequired) //Not enough fuel
if (m_linkedReactor.Fuel < WarpFuel) //Not enough fuel
return false;

return true;
Expand All @@ -120,13 +128,15 @@ protected void Warp(Object source, ElapsedEventArgs e)

if (!CanWarp)
return;
if (IsPlayerInCockpit())
return;

LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Ship '" + m_linkedReactor.Parent.Name + "' is warping!");
LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Ship '" + m_linkedReactor.Parent.Name + "' is warping using " + WarpFuel.ToString() + " fuel!");

m_isWarping = true;

//Consume the fuel
float fuelRequired = m_warpFuelRequired;
float fuelRequired = WarpFuel;
float totalFuelRemoved = 0;
List<InventoryItemEntity> fuelItems = m_linkedReactor.Inventory.Items;
foreach (InventoryItemEntity fuelItem in fuelItems)
Expand Down Expand Up @@ -196,7 +206,7 @@ protected void SlowDown(Object source, ElapsedEventArgs e)

Vector3 velocity = (Vector3)m_linkedReactor.Parent.LinearVelocity;
float speed = velocity.Length();
if (speed < 100)
if (speed < 50)
{
m_linkedReactor.Parent.MaxLinearVelocity = (float)104.7;

Expand All @@ -223,6 +233,35 @@ protected void StopWarp(Object source, ElapsedEventArgs e)
LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Ship '" + m_linkedReactor.Parent.Name + "' is slowing back down!");
}

protected bool IsPlayerInCockpit()
{
bool isPlayerInCockpit = false;
try
{
List<CubeBlockEntity> cubeBlocks = m_linkedReactor.Parent.CubeBlocks;
foreach (var cubeBlock in cubeBlocks)
{
if (cubeBlock.GetType() == typeof(CockpitEntity))
{
CockpitEntity cockpit = (CockpitEntity)cubeBlock;
if (cockpit.Pilot != null)
{
//TODO - Find a way to distinguish between normal cockpits and passenger seats
//Disabled until the above is satisfied
//isPlayerInCockpit = true;
break;
}
}
}
}
catch (Exception ex)
{
LogManager.GameLog.WriteLine(ex);
}

return isPlayerInCockpit;
}

#endregion
}
}

0 comments on commit 817d89c

Please sign in to comment.