completely rework mission code

This commit is contained in:
Florian Stinglmayr 2022-02-14 18:11:11 +01:00
parent a11d3d10aa
commit 9d81a9ad7d
4 changed files with 934 additions and 13 deletions

View File

@ -5,7 +5,6 @@ namespace EliteBGS.BGS {
public class MissionCompleted : LogEntry {
public MissionCompleted(MissionCompletedEntry e) {
Entries.Add(e);
Faction = e.JSON.GetValue("Faction").ToString();
}
public string MissionName {

View File

@ -28,7 +28,7 @@ namespace EliteBGS.BGS {
return added;
}
private bool IsRelevant(Entry e) {
public static bool IsRelevant(Entry e) {
return e.Is(Events.CommitCrime) ||
e.Is(Events.Docked) ||
e.Is(Events.FactionKillBond) ||
@ -67,12 +67,17 @@ namespace EliteBGS.BGS {
.ToList()
;
Dictionary<int, MissionAcceptedEntry> acceptedMissions = new Dictionary<int, MissionAcceptedEntry>();
Dictionary<ulong, MissionAcceptedEntry> acceptedMissions = new Dictionary<ulong, MissionAcceptedEntry>();
Dictionary<string, long> buyCost = new Dictionary<string, long>();
Dictionary<ulong, string> systems = new Dictionary<ulong, string>();
Dictionary<string, string> npcfactions = new Dictionary<string, string>();
Dictionary<string, List<Faction>> system_factions = new Dictionary<string, List<Faction>>();
// A dictionary resolving to a station at which each mission was accepted
Dictionary<ulong, string> acceptedStations = new Dictionary<ulong, string>();
// A dictionary resolving to a system at which each mission was accepted
Dictionary<ulong, ulong> acceptedSystems = new Dictionary<ulong, ulong>();
string current_system = null;
ulong current_system_address = 0;
string current_station = null;
@ -177,12 +182,18 @@ namespace EliteBGS.BGS {
});
collate = true;
} else if (e.Is(Events.MissionCompleted)) {
var completed = e as MissionCompletedEntry;
results.Add(new MissionCompleted(completed) {
System = current_system,
Station = current_station,
SystemAddress = current_system_address,
});
MissionCompletedEntry completed = e as MissionCompletedEntry;
MissionAcceptedEntry accepted;
if (!acceptedMissions.TryGetValue(completed.MissionID, out accepted)) {
OnLog?.Invoke(string.Format(
"Unable to find mission acceptance for mission \"{0}\". " +
"Please extend range to include the mission acceptance.", completed.HumanReadableName
));
continue;
}
string mission_giver = completed.Faction;
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
@ -200,9 +211,51 @@ namespace EliteBGS.BGS {
}
foreach (var influences in other.Value) {
ulong system_address = influences.Key;
if (!faction.Equals(results[0].Faction) ||
(faction.Equals(results[0].Faction) && system_address != current_system_address)) {
string system = systems.TryGetValue(system_address, out string sys) ? sys : "";
ulong accepted_address = 0;
string system, accepted_station, accepted_system;
if (!systems.TryGetValue(system_address, out system)) {
OnLog?.Invoke(string.Format(
"Unknown system system \"{0}\" unable to assign that mission a target.", system_address
));
continue;
}
if (!acceptedSystems.TryGetValue(completed.MissionID, out accepted_address)) {
OnLog?.Invoke(string.Format(
"Unable to figure out in which system mission \"{0}\" was accepted.", system_address
));
continue;
}
if (!systems.TryGetValue(accepted_address, out accepted_system)) {
OnLog?.Invoke(string.Format(
"Unable to figure out in which system mission \"{0}\" was accepted.", system_address
));
continue;
}
if (!acceptedStations.TryGetValue(completed.MissionID, out accepted_station)) {
OnLog?.Invoke(string.Format(
"Unable to figure out in which station mission \"{0}\" was accepted.", system_address
));
continue;
}
if (faction.Equals(mission_giver) && system_address == accepted_address) {
/* This is the influence block for the origin of the mission.
*/
results.Add(new MissionCompleted(completed) {
System = accepted_system,
Faction = mission_giver,
SystemAddress = accepted_address,
Station = accepted_station,
});
} else if (!faction.Equals(results[0].Faction) ||
(faction.Equals(results[0].Faction) && 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).
*/
results.Add(new InfluenceSupport() {
Faction = faction,
Influence = influences.Value,
@ -215,7 +268,16 @@ namespace EliteBGS.BGS {
}
} else if (e.Is(Events.MissionAccepted)) {
MissionAcceptedEntry accepted = e as MissionAcceptedEntry;
acceptedMissions[accepted.MissionID] = accepted;
ulong id = accepted.MissionID;
if (!acceptedMissions.ContainsKey(id)) {
acceptedMissions[id] = accepted;
}
if (!acceptedStations.ContainsKey(id)) {
acceptedStations[id] = current_station;
}
if (!acceptedSystems.ContainsKey(id)) {
acceptedSystems[id] = current_system_address;
}
} else if (e.Is(Events.MissionFailed)) {
var failed = e as MissionFailedEntry;
MissionAcceptedEntry accepted = null;

View File

@ -202,6 +202,7 @@
<Content Include="main-objectives.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="TestData\DoubleSupport.txt" />
<None Include="TestData\MurderOtherThanControllingFaction.txt" />
<None Include="TestData\TestMurder.txt" />
<None Include="TestData\SellOrganicData.txt" />

859
TestData/DoubleSupport.txt Normal file

File diff suppressed because one or more lines are too long