fix missions that give influence to no one
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using EDJournal;
|
||||
|
||||
namespace EliteBGS.BGS {
|
||||
/// <summary>
|
||||
@@ -8,14 +9,14 @@ namespace EliteBGS.BGS {
|
||||
/// </summary>
|
||||
public class InfluenceSupport : LogEntry {
|
||||
public string Influence { get; set; }
|
||||
public MissionCompleted RelevantMission { get; set; }
|
||||
public MissionCompletedEntry RelevantMission { get; set; }
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
string missionname;
|
||||
|
||||
if (RelevantMission != null) {
|
||||
missionname = RelevantMission.MissionName;
|
||||
missionname = RelevantMission.HumanReadableName;
|
||||
} else {
|
||||
missionname = "UNKNOWN MISSION";
|
||||
}
|
||||
|
||||
104
BGS/Report.cs
104
BGS/Report.cs
@@ -185,6 +185,11 @@ namespace EliteBGS.BGS {
|
||||
MissionCompletedEntry completed = e as MissionCompletedEntry;
|
||||
MissionAcceptedEntry accepted = null;
|
||||
MissionCompleted main_mission = null;
|
||||
ulong accepted_address;
|
||||
string accepted_system;
|
||||
|
||||
string target_faction_name = completed.TargetFaction;
|
||||
string source_faction_name = completed.Faction;
|
||||
|
||||
if (!acceptedMissions.TryGetValue(completed.MissionID, out accepted)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
@@ -194,7 +199,20 @@ namespace EliteBGS.BGS {
|
||||
continue;
|
||||
}
|
||||
|
||||
string mission_giver = completed.Faction;
|
||||
if (!acceptedSystems.TryGetValue(completed.MissionID, out accepted_address)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.HumanReadableName
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!systems.TryGetValue(accepted_address, out accepted_system)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.HumanReadableName
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (completed.HumanReadableNameWasGenerated) {
|
||||
/* If the human readable name was generated, we send a log message. Because the
|
||||
* generated names all sort of suck, we should have more human readable names in
|
||||
@@ -226,14 +244,53 @@ namespace EliteBGS.BGS {
|
||||
"If this assessment is wrong, just remove the entry from the objective list.",
|
||||
completed.HumanReadableName, faction
|
||||
));
|
||||
// Add empty entry
|
||||
other.Value.Add(current_system_address, "");
|
||||
|
||||
if (string.Compare(target_faction_name, faction, true) == 0) {
|
||||
/* here we assume that if the faction in question is the target faction,
|
||||
* that we gave said target faction no influence in the target system, aka
|
||||
* current system
|
||||
*/
|
||||
other.Value.Add(current_system_address, "");
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the target faction " +
|
||||
"of the mission, we assume the influence was gained in \"{2}\". " +
|
||||
"Please remove the entry if this assumption is wrong.",
|
||||
completed.HumanReadableName, faction, current_system
|
||||
));
|
||||
} else if (string.Compare(source_faction_name, faction, true) == 0) {
|
||||
/* source faction of the mission is not getting any influence. This could be because
|
||||
* the source faction is in an election state in its home system and cannot gain any
|
||||
* influence. It may also very well be that the source and target faction are the same
|
||||
* since the faction is present in both target and source system. In which case we add
|
||||
* both and hope for the best.
|
||||
*/
|
||||
other.Value.Add(accepted_address, "");
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the source faction " +
|
||||
"of the mission, we assume the influence was gained in \"{2}\". " +
|
||||
"Please remove the entry if this assumption is wrong.",
|
||||
completed.HumanReadableName, faction, accepted_system
|
||||
));
|
||||
|
||||
/* check if source/target faction are equal, in which case we also need an entry
|
||||
* for the target system. As said factions can be present in two systems, and can
|
||||
* give missions that target each other.
|
||||
*/
|
||||
if (string.Compare(source_faction_name, target_faction_name, true) == 0) {
|
||||
other.Value.Add(current_system_address, "");
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the source and target faction " +
|
||||
"of the mission, we assume the influence was also gained in target system \"{2}\". " +
|
||||
"Please remove the entry if this assumption is wrong.",
|
||||
completed.HumanReadableName, faction, current_system
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var influences in other.Value) {
|
||||
ulong system_address = influences.Key;
|
||||
ulong accepted_address = 0;
|
||||
string system, accepted_station, accepted_system;
|
||||
string system, accepted_station;
|
||||
|
||||
if (!systems.TryGetValue(system_address, out system)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
@@ -242,20 +299,6 @@ namespace EliteBGS.BGS {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedSystems.TryGetValue(completed.MissionID, out accepted_address)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.HumanReadableName
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!systems.TryGetValue(accepted_address, out accepted_system)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.HumanReadableName
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedStations.TryGetValue(completed.MissionID, out accepted_station)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which station mission \"{0}\" was accepted.", completed.HumanReadableName
|
||||
@@ -263,30 +306,18 @@ namespace EliteBGS.BGS {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (faction.Equals(mission_giver) && system_address == accepted_address) {
|
||||
if (faction.Equals(source_faction_name) && system_address == accepted_address) {
|
||||
/* This is the influence block for the origin of the mission.
|
||||
*/
|
||||
main_mission = new MissionCompleted(completed) {
|
||||
System = accepted_system,
|
||||
Faction = mission_giver,
|
||||
Faction = source_faction_name,
|
||||
SystemAddress = accepted_address,
|
||||
Station = accepted_station,
|
||||
};
|
||||
/* We might already have secondary missions, so update them.
|
||||
* We cannot rely on the order in which they are listed in the affected
|
||||
* factions.
|
||||
*/
|
||||
if (results.Count() > 0) {
|
||||
results
|
||||
.ForEach(x => {
|
||||
if (x.GetType() == typeof(InfluenceSupport)) {
|
||||
(x as InfluenceSupport).RelevantMission = main_mission;
|
||||
}
|
||||
});
|
||||
}
|
||||
results.Add(main_mission);
|
||||
} else if (!faction.Equals(mission_giver) ||
|
||||
(faction.Equals(mission_giver) && system_address != accepted_address)) {
|
||||
} else if (!faction.Equals(source_faction_name) ||
|
||||
(faction.Equals(source_faction_name) && system_address != accepted_address)) {
|
||||
/* This block is for secondary factions (first if), or if the secondary faction
|
||||
* is the same as the mission giver, but in another system (second if).
|
||||
*/
|
||||
@@ -295,8 +326,7 @@ namespace EliteBGS.BGS {
|
||||
Influence = influences.Value,
|
||||
System = system,
|
||||
SystemAddress = system_address,
|
||||
/* main mission might be null, and may be fixed later */
|
||||
RelevantMission = main_mission
|
||||
RelevantMission = completed
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user