Skip to content

Conversation

@ritinae
Copy link

@ritinae ritinae commented Jun 27, 2025

Use case

We had this great idea to customize the lang files to replace the "Cause of death:" on the first line of the report with "Skill issue:". However, as not all deaths are necessarily skill issues (although some of them surely are), we found the thought of randomly picking either of those very amusing. Making one of the options a rare/easter-egg kind of thing would be next level, but let's not get ahead of ourselves. Just being able to randomize the first line of the report would be great!

The issue

To our great disappointment, it turns out, the report only ever uses the first UINotes or UICauseOfDeath defined in the language XML. A somewhat of a major setback, as this prevents any chance of randomizing the darn thing.

The solution

Being a persistent bunch of idiots, we didn't let this stop us! When there's a will there's a way!

Rundown of the changes in this PR:

  • I could have copy-pasted the logic behind StringifyCauseOfDeath/SelectCauseOfDeath and called it a day, but that would have been a bit messy.
  • Instead, as randomizing the first line and randomizing the note/cause of death is essentially the same logic, it made sense to generalize the pick-translation-value-at-random logic.
  • To achieve this, I added a new method LanguageHandler.GetRandomValueByTag (similar to LanguageHandler.GetFirstValueByTag)
  • The current implementation of SelectCauseOfDeath happened to get the full list of translation values, which was somewhat incompatible with the idea of generalizing the logic. I needed to tweak this to work only with the language tags instead of getting the full list of values.
  • Then, the StringifyCauseOfDeath can simply call either GetRandomValueByTag or GetFirstValueByTag, depending on the value of shouldRandomize. The result.Length > 1 check is now an implementation detail of GetRandomValueByTag, so it could be removed from here.
  • With those out of the way, the actual changes to the HUDManagerPatch.cs are very simple: Instead of always calling GetFirstValueByTag with the TAG_UI_DEATH and TAG_UI_NOTES, use the new GetRandomValueByTag.
  • To keep things consistent, I added a check for serious notes, which disables the randomization in case serious death messages are enabled.

I tested the changes by adding a bunch of translation variations for TAG_UI_DEATH and TAG_UI_NOTES, and then proceeding to die in various ways. Seemed to work like a charm, the reports were properly randomized, the first line included.

Comment on lines +236 to +248
// NOTE: obtaining a random number is skipped if there is only one result. This may be relavant for synced randoms.
if (result.Length > 1)
{
var index = random.Next(result.Length);
return result[index];
}

// NOTE: Assumes GetValuesByTag always returns a non-empty array.
return result[0];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the superfluous length check in to better match the old behaviour, just in case there is some effect to synced randoms that I missed.

If skipping the random isn't critical for synced randoms, then as we anyway assume that GetValuesByTag returns a non-empty array, this could be simplified down to just:

var index = random.Next(result.Length);
return result[index];

@ritinae ritinae force-pushed the customizable-report-first-line branch from fb2bfcf to 8a10c89 Compare July 3, 2025 20:35
ritinae added 2 commits August 2, 2025 15:31
Refactor the language string randomization to be a feature of the
LanguageHander instead of being tied to the AdvancedDeathTracker. This
allows re-using the same code for randomizing strings that are not death
messages or funny notes.
Tweak the report generating code to pick a random first line for the
report, in case there are multiple available. This makes the reports
slightly more customizable.

I am likely going to use this as a hack to get rare alternative titles
for the reports by e.g. copy-pasting the default "Cause of death" a
few times in the xml file and adding rare variants after those. No need
to implement e.g. weighted random or anything more sophisticated, this
works good enough.
@ritinae ritinae force-pushed the customizable-report-first-line branch from b59708d to 39d09b8 Compare August 2, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant