Skip to content

Commit

Permalink
-Updated game libraries
Browse files Browse the repository at this point in the history
-Updated SEModAPI libraries
-Massively improved performance
-Damage/Range is now scaled by current power output of reactor
  • Loading branch information
chessmaster42 committed Jul 27, 2014
1 parent aee33f6 commit 50bb0b5
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 19 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 modified Libraries/VRage.Common.dll
Binary file not shown.
Binary file modified Libraries/VRage.Math.dll
Binary file not shown.
40 changes: 23 additions & 17 deletions ReactorRadiationPlugin/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Core : PluginBase, ICubeBlockEventHandler
protected TimeSpan m_timeSinceLastUpdate;
protected DateTime m_lastUpdate;
protected DateTime m_lastFullScan;
protected DateTime m_lastRadiationDamage;

#endregion

Expand All @@ -46,11 +47,12 @@ public Core()

m_isActive = false;

m_radiationRange = 10;
m_radiationRange = 5;
m_damageRate = 1;

m_lastUpdate = DateTime.Now;
m_lastFullScan = DateTime.Now;
m_lastRadiationDamage = DateTime.Now;
m_timeSinceLastUpdate = DateTime.Now - m_lastUpdate;
}

Expand Down Expand Up @@ -107,11 +109,19 @@ public override void Update()
m_timeSinceLastUpdate = DateTime.Now - m_lastUpdate;
m_lastUpdate = DateTime.Now;

foreach (var entry in m_reactorMap)
TimeSpan timeSinceLastRadiation = DateTime.Now - m_lastRadiationDamage;
if (timeSinceLastRadiation.TotalMilliseconds > 1000)
{
foreach (ReactorEntity reactor in entry.Value)
m_lastRadiationDamage = DateTime.Now;

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

foreach (var entry in m_reactorMap)
{
DoRadiationDamage(reactor);
foreach (ReactorEntity reactor in entry.Value)
{
DoRadiationDamage(characters, reactor);
}
}
}

Expand Down Expand Up @@ -241,7 +251,7 @@ private void FullScan()
}
}

private void DoRadiationDamage(ReactorEntity source)
private void DoRadiationDamage(List<CharacterEntity> targets, ReactorEntity source)
{
if (source == null)
return;
Expand All @@ -250,23 +260,19 @@ private void DoRadiationDamage(ReactorEntity source)
if (!source.Enabled)
return;

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

//TODO - Check if this is accurate at all for calculating the beacon's actual location
//The parent's position might not be at cubegrid 0,0,0 and might be at center of mass which is going to be hard to calculate
Vector3I beaconBlockPos = source.Min;
Vector3I blockGridPos = source.Min;
Matrix matrix = source.Parent.PositionAndOrientation.GetMatrix();
Matrix orientation = matrix.GetOrientation();
Vector3 rotatedBlockPos = Vector3.Transform((Vector3)beaconBlockPos * 2.5f, orientation);
Vector3 beaconPos = rotatedBlockPos + source.Parent.Position;
Vector3 rotatedBlockPos = Vector3.Transform((Vector3)blockGridPos * 2.5f, orientation);
Vector3 reactorPos = rotatedBlockPos + source.Parent.Position;

foreach (CharacterEntity character in characters)
foreach (CharacterEntity character in targets)
{
double distance = Vector3.Distance(character.Position, beaconPos);
if (distance < _RadiationRange)
double distance = Vector3.Distance(character.Position, reactorPos);
double range = 0.05 * source.Power * _RadiationRange;
if (distance < range)
{
//TODO - Scale the damage based on the current power output of the reactor
double damage = _DamageRate * m_timeSinceLastUpdate.TotalSeconds * (_RadiationRange - distance);
double damage = _DamageRate * m_timeSinceLastUpdate.TotalSeconds * (range - distance);
character.Health = character.Health - (float)damage;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ReactorRadiationPlugin/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.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyVersion("0.1.1.0")]
[assembly: AssemblyFileVersion("0.1.1.0")]

0 comments on commit 50bb0b5

Please sign in to comment.