Closed Darkcyde13 closed 1 year ago
For the "and" point, I've changed the 'descriptions' to be two separate arrays, one for signals and one for bodies. Then at the end, just before the List() report, I've updated that IF check like this:
{if len(signalMaterials) > 0 && len(bodyMaterials) > 0: {set and to [" and"]}}
{set descriptions to cat(signalDescriptions, and, bodyDescriptions)}
This correctly adds "and" between the two sections if both are populated, but leaves it out if not. I guess you could also use the '...Descriptions' variables instead of '...Materials'. It should do the same job. :)
reportSystem.Faction.Allegiance.invariantName
.Otherwise, I generally agree and will update the script accordingly.
I did realise that my suggested code fix is slightly wrong in one situation. Using List() to report descriptions
after I put the two arrays together, if there is only one body to report in addition to any signal sources, then it says 'and' twice (so, ", and, and"), once for the above code and once for the List(). If there is more than one body, then the List() 'and' goes between the bodies, and the speech is correct.
I fixed this by making the second check bodyMaterials > 1
. So only the List() 'and' is used for a single body, and the additional 'and' is used correctly when there is more than one body.
That is, of course, if you decide to go with my suggestion. π
Hi @Tkael,
I've just tried out beta 5 and found the faction.ActiveStates
bug still appears to be present.
Also, as per my comment above, I screwed up a little with my intended fix for "and" between the two arrays. Sorry about that. π
The only other thing is the 'Proprietary Composites' also being available in Encoded Emissions. I have some ideas around this, but I'm not sure what will or won't work. I'm going to have to try some things out.
And thank you for the quick update, it is greatly appreciated! π
Hi again @Tkael,
I'm not sure if I should open a new ticket as this one is closed? Well, I'll post here and if needed I can open a new one (or you can copy this to a new one, whichever is best).
So, after a some trial and error trying to get this to do what I wanted, I have finally succeeded. My new code allows any signal source type to easily be added, along with any associated materials assigned to the type. It's similar to your original script in that respect. It will now report the Proprietary Composites as being available in both signal source types, and separately list the others under HGE's, like this:
Proprietary Composites may be found in Encoded Emissions and High Grade Emissions signal sources, Core Dynamics Composites may be found in High Grade Emissions signal sources, and Carbon, Phosphorus, and Sulphur are found on body 3 d a in this system.
I also tested by adding a third source type, "Testing", between EncE and HGE, and added a copy of the "Proto ..." materials, plus the proprietary composites. This produced:
Proprietary Composites may be found in Encoded Emissions, High Grade Emissions, and Testing signal sources, Core Dynamics Composites may be found in High Grade Emissions signal sources, Proto Heat Radiators, Proto Light Alloys, and Proto Radiolic Alloys may be found in Testing signal sources, and Carbon, Phosphorus, and Sulphur are found on body 3 d a in this system.
So this now collates all materials by source type, and alphabetizes everything too.
The code is:
{_ Get information about signal sources _}
{set sigMaterials to []}
{set signalsType to ["Encoded Emissions", "High Grade Emissions"]}
{for sigType in signalsType:
{if sigType = "Encoded Emissions":
{if reportSystem.Faction.Allegiance.invariantName = "Federation":
{set sigMaterials to cat(sigMaterials, ["Proprietary Composites"])}
}
|elif sigType = "High Grade Emissions":
{if reportSystem.Faction.Allegiance.invariantName = "Federation":
{set sigMaterials to cat(sigMaterials, ["Core Dynamics Composites"])}
{set sigMaterials to cat(sigMaterials, ["Proprietary Composites"])}
|elif reportSystem.Faction.Allegiance.invariantName = "Empire":
{set sigMaterials to cat(sigMaterials, ["Imperial Shielding"])}
}
{for faction in reportSystem.factions:
{for factionPresence in faction.presences:
{if reportSystem.name = factionPresence.systemName && factionPresence.influence >= 25:
{for state in faction.ActiveStates:
{if state.invariantName = "Civil Unrest":
{set sigMaterials to cat(sigMaterials, ["Improvised Components"])}
|elif state.invariantName = "Civil War" || state.invariantName = "War":
{set sigMaterials to cat(sigMaterials, ["Military Grade Alloys",
"Military Supercapacitors"])}
|elif state.invariantName = "Outbreak":
{set sigMaterials to cat(sigMaterials, ["Pharmaceutical Isolators"])}
|elif state.invariantName = "Boom":
{set sigMaterials to cat(sigMaterials, ["Proto Heat Radiators",
"Proto Light Alloys",
"Proto Radiolic Alloys"])}
}
}
}
}
}
}
{_ Add material if it is 'needed' and the signal type is not already added for it _}
{for invariantMaterial in sigMaterials:
{set details to MaterialDetails(invariantMaterial)}
{if isNeeded(inventory(details.localizedName)):
{if !has(signalMaterials[details.localizedName], sigType):
{addSignalMaterial(details.localizedName, sigType)}
}
}
}
{_ Reset sigMaterials array _}
{set sigMaterials to []}
}
{_ Reorganise signals array -> 'material':'sources' _}
{set signalsOrganised to []}
{for mat, sig in signalMaterials:
{set sig to List(sig)}
{set matList to []}
{if has(signalsOrganised, sig):
{set matList to cat(signalsOrganised[sig], [mat])}
{set signalsOrganised to union(signalsOrganised, [sig:matList])}
|else:
{set signalsOrganised to union(signalsOrganised, [sig:[mat]])}
}
}
{set signalMaterials to signalsOrganised}
{_ Sort materials into alphabetical order _}
{for signalType, mats in signalMaterials:
{set sortMats to []}
{for item in sort(mats, cmp(a, b)):
{set sortMats to cat(sortMats, [item])}
}
{set signalDescriptions to cat(signalDescriptions, [cat(List(sortMats),
" may be found in ", signalType, " signal sources")])}
}
While doing this, I also noticed I could make the 'add materials' subroutines more efficient, like this:
{set addBodyMaterial(details, bodyName) to:
{set bodyName to:
{if details.bodyname != details.bodyshortname: body} {details.bodyshortname}
}
{if has(bodyMaterials, bodyName):
{if find(bodyMaterials[bodyName], details.localizedName) = -1:
{set newMats to cat(bodyMaterials[bodyName], [details.localizedName])}
{set bodyMaterials to union(bodyMaterialsExcept, [bodyName: newMats])}
}
|else:
{set bodyMaterials to union(bodyMaterials, [bodyName: [details.localizedName]])}
}
}
{set addSignalMaterial(materialName, signalSourceType) to:
{if has(signalMaterials, materialName):
{if find(signalMaterials[materialName], signalSourceType) = -1:
{set locations to cat(signalMaterials[materialName], [signalSourceType])}
{set signalMaterials to union(signalMaterials, [materialName:locations])}
}
|else:
{set signalMaterials to union(signalMaterials, [materialName: [signalSourceType]])}
}
}
With these there is less processing of the data to achieve the same result. Well, you can use them if you wish. π
Edit: Sorry, I forgot to say, the updated signals code needs the updated addSignalMaterial()
function too, as I've swapped over the material and source to make it all work.
Thanks. I was able to find the issue.
Is: {for state in faction.ActiveStates:
Should be: {for state in factionPresence.ActiveStates:
FYI, I've also found that your updated 'add materials' subroutines seem to have some issues with reporting surface materials from multiple bodies?
Proprietary Composites may be found in Encoded Emissions and High Grade Emissions signal sources, Core Dynamics Composites, Proto Heat Radiators, Proto Light Alloys, and Proto Radiolic Alloys may be found in High Grade Emissions signal sources, also, Mercury is most prevalent on body 1 a, Antimony, Arsenic, Carbon, Iron, Nickel, Niobium, Phosphorus, Selenium, Sulphur, Tin, and Vanadium are most prevalent on body 1 b, Manganese is most prevalent on body 4 a, Tellurium is most prevalent on body 4 b, Ruthenium is most prevalent on body 4 c, Germanium and Polonium are most prevalent on body 4 d, Chromium, Molybdenum, and Yttrium are most prevalent on body 5 a, and Cadmium, Zinc, and Zirconium are most prevalent on body 5 b in this system.
Proprietary Composites may be found in Encoded Emissions and High Grade Emissions signal sources, Core Dynamics Composites, Proto Heat Radiators, Proto Light Alloys, and Proto Radiolic Alloys may be found in High Grade Emissions signal sources, and Carbon, Iron, Nickel, Phosphorus, and Sulphur are found on body 1 b in this system.
Ah, OK, the faction presence makes sense. π
As for the addBodyMaterials()
I found my error. I forgot to remove the word 'Except' from
{set bodyMaterials to union(bodyMaterialsExcept, [bodyName: newMats])}
After removing that, making it {set bodyMaterials to union(bodyMaterials, [bodyName: newMats])}
it seems to work as intended. Thank you for pointing it out. π
I tested with the Sol system, and setting both script options to 2, and both the original and my version give the same data. However, it doesn't seem to order the bodies alphabetically, which I'll need to look into. The Othime system, with bodies named as numbers, are ordered correctly. So it seems the sorting works for numbers but not words. π€
Ah, I figured it out.
I needed to change the 'token' lines in the declare check(a, b)
.
Using this, it now sorts correctly:
{declare check(a, b) as:
{set a to token(a, " on ", 1)}
{set b to token(b, " on ", 1)}
{return cmp(a, b)}
}
What's Wrong (please be as specific as possible)
Expected
The 'System materials report' to run correctly.
Observed
The section for signal sources does not work. (Explained below)
Steps to reproduce
Configuration
My Investigation
Investigation Notes
I was going over all my scripts after the beta 3 bug, and came across 'System materials report'. I hadn't looked at this one before, so I checked it out.
Looking over it, I have found some things that don't appear to be correct, mainly in the signal sources section...
(In no particular order)
The whole section requires you to have found a 'High Grade Emmissions' signal source before this section of code does anything. That doesn't make sense, as you really want to know before you start scanning, and the script is only called after a honk or full system scan, neither of which will detect signal sources. The script should really report what is possible if these signal sources are found later. As it is, the code only ever checks for HGE's anyway, so hardcoding it rather than checking all known signal sources would be preferable. It would make the script more efficient too. The only item in the script which can be found outside of an HGE, is 'Proprietary Composites', which can also be found in 'Encoded Emissions'. So, basically, this code can be removed (as it's irrelevant in the overall execution of the code in this section), and adjustments made to account for the signal type being an HGE:
(Edit: Sorry, I've deleted the line that was here regarding the 'continue' variable, as I realised why it exists, and I was wrong).
The variable 'reportSystem.Allegiance.invariantName' seems to always be empty/void. Maybe it doesn't exist or is broken? I tried multiple variations, but nothing worked. Only changing it to 'reportSystem.allegiance' made it work as expected (although only for English I guess?). I ask if it could exist, simply because it's not used in any other script. Everywhere else, it's just '.allegiance'.
For the check of 'factionPresence.influence', it is 100 times too big, and will never work. 25 should be 0.25 as that's how the variable is populated. When I checked a system faction in game, 9.7% was 0.097 in the variable. Other factions were represented the same way.
'faction.ActiveStates' seems to always be empty/void. The code that relies on this is never executed. I went to a Federation system in 'Civil War' (Othime, the main faction is in 'civil unrest', two others are in 'war', but the system is in 'civil war'), found an HGE, temporarily reduced the faction presence influence check to 1% (0.01, so it was under all the factions presences), and tested the script. The 'For Loop' code section for 'ActiveStates' was never run, so I guess the variable is always empty?
'details' should be 'detail' as that's how it's used in the following code (or an 's' added to the others to match the setup).
For setting up 'descriptions' for signal sources, signal type materials all end with 's', so should always use "are", not "is" as they are all plural. Also, it's better to say "can possibly be found" (or a variation thereof) rather than "are found" or "is found" as the chances are variable and it's not guaranteed to find them in an HGE (although the chance is very high), or that an HGE will appear.
The |else: in 'addSignalMaterial()' needs a second set of [] around the value to make it an array or it will not work correctly. The code will 'forget' the first item as the string is overwritten by an array after the first iteration. The line should be
{set signalMaterials to union(signalMaterials, [signalSourceType: [materialName]])}
.The IF check for signalMaterials & bodyMaterials to say "and" is redundant as it's in the wrong place to do anything useful. It will say "and" at the beginning of speech if both are > 0, while it looks like it should be between the two categories. Even then, it won't do anything as 'descriptions' is used. and this "and " would never appear between the sections.
The location description property of 'Proprietary Composites' is missing the word 'under' for 'systems under Federal control'.
I apologise if I've missed anything as to why some of these are the way they are, in case there are specific reasons I've not noticed.
I'm sorry this is so long, and also if some of them should have their own issue raised, but because they all relate to the one script I thought I'd report it all in one go.
EDDI Logs
N/A
Player journals
N/A