Skip to content

Commit

Permalink
Basic Messagelogging complete
Browse files Browse the repository at this point in the history
Combat data is printed to the faction message log, and on the temporary
event log in individual ship details.
  • Loading branch information
NathanH- committed Dec 15, 2013
1 parent 6c5641b commit b356174
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 74 deletions.
6 changes: 3 additions & 3 deletions Pulsar4X/Pulsar4X.Lib/Entities/Components/ActiveSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public OrdnanceTargetTN getTarget()
/// </summary>
/// <param name="TG">Taskgroup this MFC is in.</param>
/// <returns>to be decided upon.</returns>
public bool FireWeapons(TaskGroupTN TG)
public bool FireWeapons(TaskGroupTN TG, ShipTN FiredFrom)
{


Expand All @@ -595,7 +595,7 @@ public bool FireWeapons(TaskGroupTN TG)
{
if (TG.AttachedMissileGroups[loop2].missiles[0].missileDef.maxSpeed == LinkedWeapons[loop].loadedOrdnance.maxSpeed)
{
OrdnanceTN newMissile = new OrdnanceTN(this, LinkedWeapons[loop].loadedOrdnance);
OrdnanceTN newMissile = new OrdnanceTN(this, LinkedWeapons[loop].loadedOrdnance,FiredFrom);
TG.AttachedMissileGroups[loop].AddMissile(newMissile);

LinkedWeapons[loop].loadTime = LinkedWeapons[loop].missileLauncherDef.rateOfFire;
Expand All @@ -606,7 +606,7 @@ public bool FireWeapons(TaskGroupTN TG)

if (used == false)
{
OrdnanceTN newMissile = new OrdnanceTN(this, LinkedWeapons[loop].loadedOrdnance);
OrdnanceTN newMissile = new OrdnanceTN(this, LinkedWeapons[loop].loadedOrdnance, FiredFrom);
newMissile.target = Target;
OrdnanceGroupTN newMissileGroup = new OrdnanceGroupTN(TG, newMissile);
TG.AttachedMissileGroups.Add(newMissileGroup);
Expand Down
38 changes: 36 additions & 2 deletions Pulsar4X/Pulsar4X.Lib/Entities/Components/BeamFireControlTN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ public bool FireWeapons(float DistanceToTarget, Random RNG, int track, ShipTN Fi
{
if (DistanceToTarget > BeamFireControlDef.range || LinkedWeapons.Count == 0 || isDestroyed == true)
{
if (DistanceToTarget > BeamFireControlDef.range)
{
MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.FiringZeroHitChance, FiringShip.ShipsTaskGroup.Contact.CurrentSystem, FiringShip.ShipsTaskGroup.Contact,
GameState.Instance.GameDateTime, (GameState.SE.CurrentTick - GameState.SE.lastTick), (this.Name + " Zero % chance to hit."));

FiringShip.ShipsFaction.MessageLog.Add(NMsg);
}

return false;
}
else
Expand Down Expand Up @@ -524,16 +532,24 @@ public bool FireWeapons(float DistanceToTarget, Random RNG, int track, ShipTN Fi

if (weaponFired == true)
{

for (int loop2 = 0; loop2 < LinkedWeapons[loop].beamDef.shotCount; loop2++)
{

int Hit = RNG.Next(1, 100);

if (toHit >= Hit)
{

String WeaponFireS = String.Format("{0} hit {1} damage at {2}% tohit", LinkedWeapons[loop].Name, LinkedWeapons[loop].beamDef.damage[RangeIncrement],toHit);

MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.FiringHit, FiringShip.ShipsTaskGroup.Contact.CurrentSystem, FiringShip.ShipsTaskGroup.Contact,
GameState.Instance.GameDateTime, (GameState.SE.CurrentTick - GameState.SE.lastTick), WeaponFireS);

FiringShip.ShipsFaction.MessageLog.Add(NMsg);


ushort location = (ushort)RNG.Next(0, Columns);
bool ShipDest = Target.OnDamaged(LinkedWeapons[loop].beamDef.damageType, LinkedWeapons[loop].beamDef.damage[RangeIncrement], location);
bool ShipDest = Target.OnDamaged(LinkedWeapons[loop].beamDef.damageType, LinkedWeapons[loop].beamDef.damage[RangeIncrement], location, FiringShip);

if (ShipDest == true)
{
Expand All @@ -542,8 +558,26 @@ public bool FireWeapons(float DistanceToTarget, Random RNG, int track, ShipTN Fi
return weaponFired;
}
}
else
{
String WeaponFireS = String.Format("{0} missed at {2}% tohit", LinkedWeapons[loop].Name, LinkedWeapons[loop].beamDef.damage[RangeIncrement],toHit);

MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.FiringMissed, FiringShip.ShipsTaskGroup.Contact.CurrentSystem, FiringShip.ShipsTaskGroup.Contact,
GameState.Instance.GameDateTime, (GameState.SE.CurrentTick - GameState.SE.lastTick), WeaponFireS);

FiringShip.ShipsFaction.MessageLog.Add(NMsg);
}
}
}
else if(LinkedWeapons[loop].isDestroyed == false)
{
String WeaponFireS = String.Format("{0} Recharging {1}/{2} Power", LinkedWeapons[loop].Name, LinkedWeapons[loop].currentCapacitor, LinkedWeapons[loop].beamDef.weaponCapacitor);

MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.FiringRecharging, FiringShip.ShipsTaskGroup.Contact.CurrentSystem, FiringShip.ShipsTaskGroup.Contact,
GameState.Instance.GameDateTime, (GameState.SE.CurrentTick - GameState.SE.lastTick), WeaponFireS);

FiringShip.ShipsFaction.MessageLog.Add(NMsg);
}
}
}

Expand Down
16 changes: 14 additions & 2 deletions Pulsar4X/Pulsar4X.Lib/Entities/Components/OrdnanceTN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -804,17 +804,29 @@ public float fuel
set { Fuel = value; }
}

/// <summary>
/// Which ship fired this missile?
/// </summary>
private ShipTN FiringShip;
public ShipTN firingShip
{
get { return FiringShip; }
set { FiringShip = value; }
}

/// <summary>
/// Constructor for missiles.
/// </summary>
/// <param name="mfCtrl">MFC directing this missile.</param>
/// <param name="definition">definition of the missile.</param>
public OrdnanceTN(MissileFireControlTN mfCtrl, OrdnanceDefTN definition)
public OrdnanceTN(MissileFireControlTN mfCtrl, OrdnanceDefTN definition, ShipTN ShipFiredFrom)
{
MFC = mfCtrl;

Target = MFC.target;

FiringShip = ShipFiredFrom;

MissileDef = definition;

/// <summary>
Expand Down Expand Up @@ -1089,7 +1101,7 @@ public void ProcessOrder(uint TimeSlice, Random RNG)
///<summary>
///Missile damage type always? laser damage type if implemented will need to change this.
///</summary>
bool ShipDest = Missiles[loop].target.ship.OnDamaged(DamageTypeTN.Missile, (ushort)Missiles[loop].missileDef.warhead, location);
bool ShipDest = Missiles[loop].target.ship.OnDamaged(DamageTypeTN.Missile, (ushort)Missiles[loop].missileDef.warhead, location,Missiles[loop].firingShip);

/// <summary>
/// Handle ship destruction at the ship level, to inform all incoming missiles that they need a new target.
Expand Down
163 changes: 123 additions & 40 deletions Pulsar4X/Pulsar4X.Lib/Entities/Faction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FactionContact
/// <summary>
/// The detected ship.
/// </summary>
public ShipTN Ship{ get; set; }
public ShipTN ship{ get; set; }

/// <summary>
/// Detected via thermal.
Expand Down Expand Up @@ -58,20 +58,38 @@ public class FactionContact
/// <param name="em">Detection via EM?</param>
/// <param name="Active">Active detection?</param>
/// <param name="tick">What tick did this detection event occur on?</param>
public FactionContact(ShipTN DetectedShip, bool Thermal, bool em, bool Active, uint tick)
public FactionContact(Faction CurrentFaction, ShipTN DetectedShip, bool Thermal, bool em, bool Active, uint tick)
{
ship = DetectedShip;
thermal = Thermal;
EM = em;
active = Active;

String Contact = "New contact detected:";

if (thermal == true)
{
thermalTick = tick;
Contact = String.Format("{0} Thermal Signature {1}", Contact, DetectedShip.CurrentThermalSignature);
}

if (EM == true)
{
EMTick = tick;
Contact = String.Format("{0} EM Signature {1}", Contact, DetectedShip.CurrentEMSignature);
}

if (active == true)
{
activeTick = tick;
Contact = String.Format("{0} TCS {1}", Contact, DetectedShip.TotalCrossSection);
}

MessageEntry NMsg = new MessageEntry(MessageEntry.MessageType.ContactNew, DetectedShip.ShipsTaskGroup.Contact.CurrentSystem, DetectedShip.ShipsTaskGroup.Contact,
GameState.Instance.GameDateTime, (GameState.SE.CurrentTick - GameState.SE.lastTick), Contact);

CurrentFaction.MessageLog.Add(NMsg);

}

/// <summary>
Expand All @@ -81,50 +99,84 @@ public FactionContact(ShipTN DetectedShip, bool Thermal, bool em, bool Active, u
/// <param name="Em">Detected on EM?</param>
/// <param name="Active">Detected by actives?</param>
/// <param name="tick">Current tick.</param>
public void updateFactionContact(bool Thermal, bool Em, bool Active, uint tick)
public void updateFactionContact(Faction CurrentFaction, bool Thermal, bool Em, bool Active, uint tick)
{
if (thermal == false && Thermal == true)
if (thermal == Thermal && EM == Em && active == Active)
{
/// <summary>
/// New thermal detection event, message logic should be here.
/// </summary>
thermalTick = tick;
}
else if (thermal == true && Thermal == false)
{
/// <summary>
/// Thermal contact lost.
/// </summary>
return;
}

if (EM == false && Em == true)
{
/// <summary>
/// New EM detection event, message logic should be here.
/// </summary>
EMTick = tick;
}
if (EM == true && Em == false)
{
/// <summary>
/// EM contact lost.
/// </summary>
}
String Contact = "N/A";
MessageEntry.MessageType type = MessageEntry.MessageType.Count;

if (active == false && Active == true)
if (Thermal == false && Em == false && Active == false)
{
/// <summary>
/// New active detection event, message logic should be here.
/// </summary>
activeTick = tick;
Contact = "Existing contact lost";
type = MessageEntry.MessageType.ContactLost;
}
if (active == true && Active == false)
else
{
/// <summary>
/// Active contact lost.
/// </summary>
Contact = "Update on existing contact:";
type = MessageEntry.MessageType.ContactUpdate;

if (thermal == false && Thermal == true)
{
/// <summary>
/// New thermal detection event, message logic should be here.
/// </summary>
thermalTick = tick;

Contact = String.Format("{0} Thermal Signature {1}", Contact, ship.CurrentThermalSignature);
}
else if (thermal == true && Thermal == false)
{
/// <summary>
/// Thermal contact lost.
/// </summary>
Contact = String.Format("{0} Thermal contact lost", Contact);
}

if (EM == false && Em == true)
{
/// <summary>
/// New EM detection event, message logic should be here.
/// </summary>
EMTick = tick;

Contact = String.Format("{0} EM Signature {1}", Contact, ship.CurrentEMSignature);
}
if (EM == true && Em == false)
{
/// <summary>
/// EM contact lost.
/// </summary>
Contact = String.Format("{0} EM contact lost", Contact);
}

if (active == false && Active == true)
{
/// <summary>
/// New active detection event, message logic should be here.
/// </summary>
activeTick = tick;

Contact = String.Format("{0} TCS {1}", Contact, ship.TotalCrossSection);
}
if (active == true && Active == false)
{
/// <summary>
/// Active contact lost.
/// </summary>

Contact = String.Format("{0} Active contact lost", Contact);
}

}

MessageEntry NMsg = new MessageEntry(type, ship.ShipsTaskGroup.Contact.CurrentSystem, ship.ShipsTaskGroup.Contact,
GameState.Instance.GameDateTime, (GameState.SE.CurrentTick - GameState.SE.lastTick), Contact);

CurrentFaction.MessageLog.Add(NMsg);

thermal = Thermal;
EM = Em;
Expand Down Expand Up @@ -218,6 +270,37 @@ public void RemoveContact(int RemIndex)

public class MessageEntry
{
/// <summary>
/// Message types that will be printed to the event log.
/// </summary>
public enum MessageType
{
ContactNew,
ContactUpdate,
ContactLost,

FiringHit,
FiringMissed,
FiringRecharging,
FiringZeroHitChance,

OrdersCompleted,
OrdersNotCompleted,

ShieldRecharge,

ShipDamage,
ShipDamageReport,

Error,
Count
}

/// <summary>
/// What specific type of message is this?
/// </summary>
public MessageType TypeOf { get; set; }

/// <summary>
/// which starsystem does this message occur in.
/// </summary>
Expand All @@ -236,7 +319,6 @@ public class MessageEntry
/// <summary>
/// How long since the last time increment?
/// </summary>

public int TimeSlice { get; set; }
/// <summary>
/// Text of the message for the log.
Expand All @@ -252,8 +334,9 @@ public class MessageEntry
/// <param name="Time">Game time of message.</param>
/// <param name="timeSlice">Time since last increment.</param>
/// <param name="text">text of the message.</param>
public MessageEntry(StarSystem Loc, StarSystemEntity Ref, DateTime Time, int timeSlice, string text)
public MessageEntry(MessageType Type, StarSystem Loc, StarSystemEntity Ref, DateTime Time, int timeSlice, string text)
{
TypeOf = Type;
Location = Loc;
entity = Ref;
TimeOfMessage = Time;
Expand Down Expand Up @@ -1310,7 +1393,7 @@ public void SensorSweep(int YearTickValue)

if (inDict == true)
{
DetectedContacts[detectedShip].updateFactionContact(th, em, ac, (uint)YearTickValue);
DetectedContacts[detectedShip].updateFactionContact(this, th, em, ac, (uint)YearTickValue);

if (th == false && em == false && ac == false)
{
Expand All @@ -1319,7 +1402,7 @@ public void SensorSweep(int YearTickValue)
}
else if (inDict == false && (th == true || em == true || ac == true))
{
FactionContact newContact = new FactionContact(detectedShip, th, em, ac, (uint)YearTickValue);
FactionContact newContact = new FactionContact(this,detectedShip, th, em, ac, (uint)YearTickValue);
DetectedContacts.Add(detectedShip, newContact);
}
}
Expand Down
Loading

0 comments on commit b356174

Please sign in to comment.