endless-sky/endless-sky

Government Modding Error with Reputation Keyword

xxxyyyqqq12345 opened this issue · 3 comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Creating a government with keyword reputation give an error.
Ex:

government "Test gov"
	reputation
		"player reputation" -1000
		min -1000
		max -1000

returns the following error:
Error: Requested token index (1) is out of bounds:
file (file location)
LXX: government "Test gov"
LXX: reputation

This is probably caused by error in Government.cpp (line 225), where during the handling of reputation "child" is used instead of "grand".
Code in question:
for(const DataNode &grand : child)
{
const string &grandKey = grand.Token(0);
bool hasGrandValue = grand.Size() >= 2;
if(grandKey == "player reputation" && hasGrandValue)
initialPlayerReputation = add ? initialPlayerReputation + child.Value(valueIndex) : child.Value(valueIndex);
...

This cause the code to look to a value that follows "reputation" instead of "player reputation". Consequently, the following code works with no error:

government "Test gov"
	reputation -1000
		"player reputation" -1000
		min -1000
		max -1000

Steps to Reproduce

  1. Make a mode using the following government:
government "Test gov"
	reputation
		"player reputation" -1000
		min -1000
		max -1000
  1. See error when loading the game

Expected Behavior

According to the wiki, the following is the expect behavior:
reputation
"player reputation" <initial-rep#>
min <minimum-rep#>
max <maximum-rep#>

Screenshots

No response

Link to save file

No response

Operating System

Windows

Game Source

GitHub Releases

Game Version

current

Additional Information

No response

I can reproduce with the test data provided.

Your proposed change makes sense, feel free to open a fix PR.

A new Pull Request have been made.
#9954

Nice find.