Skip to content

Commit

Permalink
-Added 3 more types of warp engines
Browse files Browse the repository at this point in the history
-Added min ship power requirements for warp engines
-Added engine class names to beacon text
  • Loading branch information
chessmaster42 committed Sep 3, 2014
1 parent dafb829 commit 4877a70
Show file tree
Hide file tree
Showing 16 changed files with 545 additions and 55 deletions.
Binary file modified Libraries/SEModAPI.dll
Binary file not shown.
Binary file modified Libraries/SEModAPIExtensions.dll
Binary file not shown.
Binary file modified Libraries/SEModAPIInternal.dll
Binary file not shown.
Binary file modified Libraries/Sandbox.Common.XmlSerializers.dll
Binary file not shown.
Binary file modified Libraries/Sandbox.Common.dll
Binary file not shown.
Binary file added Libraries/Sandbox.Game.dll
Binary file not shown.
Binary file modified Libraries/VRage.Common.dll
Binary file not shown.
Binary file modified Libraries/VRage.Library.dll
Binary file not shown.
Binary file modified Libraries/VRage.Math.dll
Binary file not shown.
78 changes: 62 additions & 16 deletions WarpDrivePlugin/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ protected void MainUpdate()
//Check if ship is going fast enough to warp
Vector3 velocity = warpEngine.Parent.LinearVelocity;
float speed = velocity.Length();
if (!warpEngine.IsWarping && speed > m_speedThreshold && speed < 0.95 * m_speedFactor * 100)
if (!warpEngine.IsWarping && speed > m_speedThreshold)
{
if (warpEngine.CanWarp)
warpEngine.StartWarp();
Expand Down Expand Up @@ -341,29 +341,49 @@ protected void RemoveWarpEngine(CubeGridEntity cubeGrid)
engine.Dispose();
}

protected void CreateWarpEngine(CubeBlockEntity cubeBlock)
protected void CreateWarpEngine(CubeBlockEntity cubeBlock, int engineClass = 1)
{
if (cubeBlock == null || cubeBlock.IsDisposed)
return;

CubeGridEntity cubeGrid = cubeBlock.Parent;

if (m_warpEngineMap.ContainsKey(cubeGrid))
return;

WarpEngine warpEngine = new WarpEngine(cubeGrid);
WarpEngine warpEngine = null;
switch (engineClass)
{
case 0:
warpEngine = new WarpEngineClassZero(cubeGrid);
break;
case 1:
warpEngine = new WarpEngine(cubeGrid);
break;
case 2:
warpEngine = new WarpEngineClassTwo(cubeGrid);
break;
case 3:
warpEngine = new WarpEngineClassThree(cubeGrid);
break;
default:
warpEngine = new WarpEngine(cubeGrid);
break;
}
if (warpEngine == null)
return;

if (!warpEngine.IsDefinitionMatch(cubeBlock))
return;
warpEngine.LoadBlocksFromAnchor(cubeBlock.Min);
warpEngine.LoadBlocksFromAnchor(cubeBlock.Position);
if (warpEngine.Blocks.Count == 0)
{
LogManager.APILog.WriteLineAndConsole("Failed to create warp engine on cube grid '" + cubeGrid.Name + "' with anchor at " + ((Vector3I)cubeBlock.Min).ToString());
LogManager.APILog.WriteLineAndConsole("Failed to create warp engine on cube grid '" + cubeGrid.Name + "' with anchor at " + cubeBlock.Position.ToString());
return;
}

m_warpEngineMap.Add(cubeGrid, warpEngine);

LogManager.APILog.WriteLineAndConsole("Created warp engine on cube grid '" + cubeGrid.Name + "' with anchor at " + ((Vector3I)cubeBlock.Min).ToString());
LogManager.APILog.WriteLineAndConsole("Created warp engine on cube grid '" + cubeGrid.Name + "' with anchor at " + cubeBlock.Position.ToString());
}

protected bool CheckEngineForRemoval(WarpEngine engine)
Expand Down Expand Up @@ -415,10 +435,6 @@ protected void FullScan()
{
try
{
//Skip if not large cube grid
if (cubeGrid.GridSizeEnum != MyCubeSize.Large)
continue;

//Skip if cube grid already has engine
if (m_warpEngineMap.ContainsKey(cubeGrid))
continue;
Expand All @@ -430,12 +446,42 @@ protected void FullScan()
//Force a cube block refresh
List<CubeBlockEntity> cubeBlocks = cubeGrid.CubeBlocks;

//Scan cube grid for engines
WarpEngine dummyEngine = new WarpEngine(null);
List<Vector3I> matches = dummyEngine.GetDefinitionMatches(cubeGrid);
if (matches.Count > 0)
//Check for a class-0 engine on small ships
if (cubeGrid.GridSizeEnum != MyCubeSize.Large)
{
//Scan cube grid for class-0 engines
WarpEngineClassZero dummyEngine0 = new WarpEngineClassZero(null);
List<Vector3I> matches0 = dummyEngine0.GetDefinitionMatches(cubeGrid);
if (matches0.Count > 0 && cubeGrid.TotalPower >= dummyEngine0.ParentPowerRequirement)
{
CreateWarpEngine(dummyEngine0.AnchorBlock, 0);
}

continue;
}

//Scan cube grid for class-1 engines
WarpEngine dummyEngine1 = new WarpEngine(null);
List<Vector3I> matches = dummyEngine1.GetDefinitionMatches(cubeGrid);
if (matches.Count > 0 && cubeGrid.TotalPower >= dummyEngine1.ParentPowerRequirement)
{
CreateWarpEngine(dummyEngine1.AnchorBlock, 1);
}
/*
//Scan cube grid for class-2 engines
WarpEngineClassTwo dummyEngine2 = new WarpEngineClassTwo(null);
matches = dummyEngine2.GetDefinitionMatches(cubeGrid);
if (matches.Count > 0 && cubeGrid.TotalPower >= dummyEngine2.ParentPowerRequirement)
{
CreateWarpEngine(dummyEngine2.AnchorBlock, 2);
}
*/
//Scan cube grid for class-3 engines
WarpEngineClassThree dummyEngine3 = new WarpEngineClassThree(null);
matches = dummyEngine3.GetDefinitionMatches(cubeGrid);
if (matches.Count > 0 && cubeGrid.TotalPower >= dummyEngine3.ParentPowerRequirement)
{
CreateWarpEngine(dummyEngine.AnchorBlock);
CreateWarpEngine(dummyEngine3.AnchorBlock, 3);
}
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions WarpDrivePlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.2.1.7")]
[assembly: AssemblyFileVersion("0.2.1.7")]
[assembly: AssemblyVersion("0.2.2.5")]
[assembly: AssemblyFileVersion("0.2.2.5")]
6 changes: 6 additions & 0 deletions WarpDrivePlugin/WarpDrivePlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<Compile Include="Core.cs" />
<Compile Include="WarpEngine.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WarpEngineClassThree.cs" />
<Compile Include="WarpEngineClassTwo.cs" />
<Compile Include="WarpEngineClassZero.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Sandbox.Common">
Expand All @@ -50,6 +53,9 @@
<Reference Include="Sandbox.Common.XmlSerializers">
<HintPath>..\Libraries\Sandbox.Common.XmlSerializers.dll</HintPath>
</Reference>
<Reference Include="Sandbox.Game">
<HintPath>..\Libraries\Sandbox.Game.dll</HintPath>
</Reference>
<Reference Include="SEModAPI">
<HintPath>..\Libraries\SEModAPI.dll</HintPath>
</Reference>
Expand Down
112 changes: 75 additions & 37 deletions WarpDrivePlugin/WarpEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System.Text;
using System.Timers;

using Sandbox.Common.ObjectBuilders;
using Sandbox.Definitions;

using SEModAPIExtensions.API;

using SEModAPIInternal.API.Common;
Expand Down Expand Up @@ -92,10 +95,7 @@ public float PowerRequired
{
get
{
if (Parent.Mass > 0)
m_energyRequired = Core._BaseFuel + Core._FuelRate * (Parent.Mass / 100000);
else
m_energyRequired = Core._BaseFuel;
m_energyRequired = Core._BaseFuel + Core._FuelRate * (Parent.Mass / 100000) * (1.0f / Math.Max(0.1f, CoilEfficiency));

return m_energyRequired;
}
Expand Down Expand Up @@ -138,11 +138,43 @@ public float WarpDistance
{
get
{
float distance = Core._SpeedFactor * 100 * Core._Duration;
float distance = Core._SpeedFactor * 100 * EngineEfficiency * Core._Duration;
return distance;
}
}

public virtual float CoilEfficiency
{
get
{
return 1.0f;
}
}

public virtual float EngineEfficiency
{
get
{
return 1.0f;
}
}

public virtual string EngineName
{
get
{
return "Class I";
}
}

public virtual float ParentPowerRequirement
{
get
{
return 200.0f;
}
}

protected BeaconEntity Beacon
{
get
Expand Down Expand Up @@ -180,16 +212,16 @@ protected List<BatteryBlockEntity> BatteryBlocks
}
}

protected List<ReflectorLightEntity> Lights
protected List<LightEntity> Lights
{
get
{
List<ReflectorLightEntity> list = new List<ReflectorLightEntity>();
List<LightEntity> list = new List<LightEntity>();
foreach (CubeBlockEntity cubeBlock in Blocks)
{
if (cubeBlock is ReflectorLightEntity)
if (cubeBlock is LightEntity)
{
ReflectorLightEntity light = (ReflectorLightEntity)cubeBlock;
LightEntity light = (LightEntity)cubeBlock;
list.Add(light);
}
}
Expand Down Expand Up @@ -221,7 +253,7 @@ public override Dictionary<Vector3I, StructureEntry> GetMultiblockDefinition()
return m_definition;
}

private Dictionary<Vector3I, StructureEntry> WarpEngineDefinition()
protected virtual Dictionary<Vector3I, StructureEntry> WarpEngineDefinition()
{
Dictionary<Vector3I, StructureEntry> def = new Dictionary<Vector3I, StructureEntry>();
if (IsDisposed)
Expand Down Expand Up @@ -365,10 +397,12 @@ private void RestoreBatteries()
if (cubeBlock is BatteryBlockEntity)
{
BatteryBlockEntity battery = (BatteryBlockEntity)cubeBlock;
battery.MaxStoredPower = 1;
battery.RequiredPowerInput = 4;
battery.MaxPowerOutput = 4;
battery.CurrentStoredPower = Math.Min(battery.CurrentStoredPower, battery.MaxStoredPower);

MyBatteryBlockDefinition def = (MyBatteryBlockDefinition)battery.Definition;
battery.MaxStoredPower = def.MaxStoredPower;
battery.RequiredPowerInput = def.RequiredPowerInput;
battery.MaxPowerOutput = def.MaxPowerOutput;
battery.CurrentStoredPower = 0;
}
}

Expand All @@ -382,17 +416,21 @@ private void SetupBatteries()
if (m_isPowerSetup)
return;

if (SandboxGameAssemblyWrapper.IsDebugging)
LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Setting up batteries on '" + Parent.Name + " ...");

if (BatteryBlocks.Count < 4)
throw new Exception("Some batteries are missing!");

foreach (BatteryBlockEntity battery in BatteryBlocks)
{
battery.MaxStoredPower = 100;
battery.RequiredPowerInput = 40;
if (Parent.GridSizeEnum == MyCubeSize.Large)
{
battery.MaxStoredPower = 100;
battery.RequiredPowerInput = 40;
}
else
{
battery.MaxStoredPower = 20;
battery.RequiredPowerInput = 8;
}

battery.MaxPowerOutput = 0.001f;
battery.CustomName = "Warp Coil";
}

m_isPowerSetup = true;
Expand All @@ -407,17 +445,14 @@ private void UpdateLights()
{
try
{
if (Lights.Count < 13)
throw new Exception("Some lights are missing!");

if (PowerLevel < PowerRequired)
{
if (!m_lightMode)
{
if (SandboxGameAssemblyWrapper.IsDebugging)
LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Updating lights on '" + Parent.Name + " to low-energy ...");

foreach (ReflectorLightEntity light in Lights)
foreach (LightEntity light in Lights)
{
light.Color = new Color(198, 108, 66);
}
Expand All @@ -431,7 +466,7 @@ private void UpdateLights()
if (SandboxGameAssemblyWrapper.IsDebugging)
LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Updating lights on '" + Parent.Name + " to high-energy ...");

foreach (ReflectorLightEntity light in Lights)
foreach (LightEntity light in Lights)
{
light.Color = new Color(66, 108, 198);
}
Expand All @@ -457,10 +492,14 @@ private void DoRadiationDamage()

List<CharacterEntity> characters = SectorObjectManager.Instance.GetTypedInternalData<CharacterEntity>();

Vector3I beaconBlockPos = Beacon.Min;
float blockSize = 2.5f;
if (Parent.GridSizeEnum != MyCubeSize.Large)
blockSize = 0.5f;

Vector3I beaconBlockPos = Beacon.Position;
Matrix matrix = Parent.PositionAndOrientation.GetMatrix();
Matrix orientation = matrix.GetOrientation();
Vector3 rotatedBlockPos = Vector3.Transform((Vector3)beaconBlockPos * 2.5f, orientation);
Vector3 rotatedBlockPos = Vector3.Transform((Vector3)beaconBlockPos * blockSize, orientation);
Vector3 beaconPos = rotatedBlockPos + Parent.Position;

foreach (CharacterEntity character in characters)
Expand Down Expand Up @@ -488,6 +527,8 @@ public void Update()
{
if (!IsFunctional)
return;
if (Parent.TotalPower < ParentPowerRequirement)
return;

m_timeSinceLastUpdate = DateTime.Now - m_lastUpdate;
m_lastUpdate = DateTime.Now;
Expand Down Expand Up @@ -521,7 +562,7 @@ public void Update()
else
{
m_isCountdownRunning = false;
Beacon.CustomName = Core._BeaconText;
Beacon.CustomName = Core._BeaconText + " " + EngineName;
Beacon.BroadcastRadius = Core._BeaconRange;
}

Expand All @@ -533,7 +574,7 @@ public void Update()
float distanceWarped = Vector3.Distance(m_warpStartPosition, Parent.Position);

//Slow down if at speed, elapsed time is greater than duration, and warp distance is at least met
if (speed > (0.95 * Core._SpeedFactor * 100) && m_timeSinceWarpStart.TotalMilliseconds > Core._Duration * 1000 && distanceWarped > WarpDistance)
if (speed > (0.95 * Core._SpeedFactor * 100 * EngineEfficiency) && m_timeSinceWarpStart.TotalMilliseconds > Core._Duration * 1000 && distanceWarped > WarpDistance)
{
m_isSpeedingUp = false;
m_isAtWarpSpeed = false;
Expand Down Expand Up @@ -615,7 +656,7 @@ protected void Warp()
LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Ship '" + Parent.Name + "' consumed " + PowerRequired.ToString() + "MJ of power!");

//Set the ship's max speed
Parent.MaxLinearVelocity = 100 * Core._SpeedFactor;
Parent.MaxLinearVelocity = 100 * EngineEfficiency * Core._SpeedFactor;
Parent.IsDampenersEnabled = false;

//Start the acceleration procedure
Expand Down Expand Up @@ -643,7 +684,7 @@ protected void SpeedUp()

Vector3 velocity = (Vector3)Parent.LinearVelocity;
float speed = velocity.Length();
if (speed > (0.95 * Core._SpeedFactor * 100))
if (speed > (0.95 * Core._SpeedFactor * 100 * EngineEfficiency))
{
if (SandboxGameAssemblyWrapper.IsDebugging)
LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Ship '" + Parent.Name + "' is at warp speed!");
Expand Down Expand Up @@ -719,11 +760,8 @@ protected bool IsPlayerInCockpit()
if (cubeBlock.GetType() == typeof(CockpitEntity))
{
CockpitEntity cockpit = (CockpitEntity)cubeBlock;
if (cockpit.Pilot != null && !cockpit.IsPassengerSeat)
if (cockpit.PilotEntity != null && !cockpit.IsPassengerSeat)
{
//if (SandboxGameAssemblyWrapper.IsDebugging)
//LogManager.APILog.WriteLineAndConsole("WarpDrivePlugin - Ship '" + Parent.Name + "' cannot warp, player '" + cockpit.Pilot.DisplayName + "' is in a cockpit!");

isPlayerInCockpit = true;
break;
}
Expand Down
Loading

0 comments on commit 4877a70

Please sign in to comment.