Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: World generation seed from openttd.cfg is ignored #9433

Closed
Taschi120 opened this issue Jul 11, 2021 · 10 comments · Fixed by #11927
Closed

[Bug]: World generation seed from openttd.cfg is ignored #9433

Taschi120 opened this issue Jul 11, 2021 · 10 comments · Fixed by #11927

Comments

@Taschi120
Copy link
Contributor

Version of OpenTTD

master @ commit f4dd2d8, Windows 10 x64

Expected result

Setting the parameter "generation_seed" in the "game_creation" section of openttd.cfg should lead to OpenTTD using the provided seed for game creation.

Actual result

World generation ignores the "generation_seed" parameter.

Steps to reproduce

  1. Open openttd.cfg.
  2. Set "generation_seed" to any uint32 value, e. g. 42
  3. Start OpenTTD
  4. Start a new game
  5. Check world generation seed with the "get_seed" command in the in-game console. It will most likely not be 42.
  6. Exit OpenTTD
@Taschi120
Copy link
Contributor Author

The way I read genworld.cpp near line 95, the intended behavior is like this:

  • If the "generation_seed" is UINT32_MAX, the game will pick a random seed at world generation.
  • If the "generation_seed" is any other value, that value is used. This will only be the case when the user has manually changed openttd.cfg.

However, somehow, OpenTTD seems to rewrite the "generation_seed" on some occasions (game closing?), with a seemingly random value (which is not the previous seed value nor is it UINT32_MAX). This might be linked to this bug.

@TrueBrain
Copy link
Member

TrueBrain commented Jul 11, 2021

if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom();

That line is a bit weird .. we shouldn't be changing _settings_newgame, as .. that value should be "read"-only outside of human interaction. I guess that is what causes this problem :)

Edit: there are a few more places that set the _settings_newgame variant .. some make more sense than others. But it feels like this is a bit messy :)

@Taschi120
Copy link
Contributor Author

genworld_gui.cpp at line 980 seems to be the culprit, setting _settings_newgame.game_creation.generation_seed = InteractiveRandom(); without any regard for user settings. Commenting out this line results in the user-specified seed being used.

Unfortunately, if generation_seed is set to 4294967295 (i. e. UINT32_MAX), this will lead to a random seed being used for the next world generation (as intended) but the generation_seed will be overwritten after that, and from then on OpenTTD will spit out the same map over and over again.

@TrueBrain
Copy link
Member

TrueBrain commented Jul 11, 2021

Cross-post from #9435 for visibility:

The more I think about this, the more I think generation_seed shouldn't be stored in openttd.cfg. It makes very little sense to store it there to me. Let me explain my thinking:

You can use -G on startup to force a seed. This I can fully understand, as that is something people sometimes want to do.

Other than that .. there are very few usecases where you want to force a seed. I can understand that you want to enter a seed number when you start a game .. but other than that .. it should always be a random value.

Why storing it in openttd.cfg is weird to me: if you ever by accident put a number in there that is not GENERATE_NEW_SEED, and looking at this PR many people already have that now in their openttd.cfg, you will always get the same map over and over and over and over and over again, without clear feedback why this is the case.

So the more I think about it, the less sense it all makes.

Either way, that does result in a real problem with this PR: as many people have non-GENERATE_NEW_SEED in their openttd.cfg, this PR would make my example a reality: maps will be very static all of a sudden for a lot of people :)

Maybe we should approach this problem differently, and put the seed in the "New Game" menu as many games do. And a "randomize" next to it. And always randomize it on opening the GUI. That way people who want a fixed value can fill it in there.
And we should stop storing it in openttd.cfg in my opinion :)

But that is just one opinion; I would love to hear others :)

@Taschi120
Copy link
Contributor Author

As it is, -G apparently doesn't work either.

@TrueBrain
Copy link
Member

As it is, -G apparently doesn't work either.

-G only works and is only useful in combination with -g :)

@gh658804
Copy link

gh658804 commented Sep 25, 2021

@TrueBrain

The more I think about this, the more I think generation_seed shouldn't be stored in openttd.cfg. It makes very little sense to store it there to me. Let me explain my thinking:

Why storing it in openttd.cfg is weird to me: if you ever by accident put a number in there that is not GENERATE_NEW_SEED, and looking at this PR many people already have that now in their openttd.cfg, you will always get the same map over and over and over and over and over again, without clear feedback why this is the case.

Maybe we should approach this problem differently, and put the seed in the "New Game" menu as many games do. And a "randomize" next to it. And always randomize it on opening the GUI. That way people who want a fixed value can fill it in there.
And we should stop storing it in openttd.cfg in my opinion :)

All of these sound very logical to me too. My feeling is that this may one day become a reality in the game, so i'd like to add a small request here. It would be very useful if the seed given at startup would be visible somewhere after the game has started (perhaps in the About box?), so it would be easier for someone who wishes to replay the specific seed.

@troilus
Copy link

troilus commented Nov 29, 2021

Hi all, how to set the generation_seed that game always generate new seed map after restart a game on dedicated server? Thanks!

@chuggersgit
Copy link

I was having the same issue on my dedicated server, I fixed it by using the "on_dedicated.scr" script, with the command "newgame". Upon restarting, it will trigger the newgame command, which forces a random seed.

@James103
Copy link
Contributor

James103 commented Aug 4, 2022

Maybe we should approach this problem differently, and put the seed in the "New Game" menu as many games do.

As far as I can tell, that used to be the case in older versions of OpenTTD (before 775c96a or release 1.5).

@2TallTyler 2TallTyler added the needs triage This issue needs further investigation before it becomes actionable label Oct 19, 2022
@TrueBrain TrueBrain removed the needs triage This issue needs further investigation before it becomes actionable label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants