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

Put into the AI company when loading savegame #6544

Closed
DorpsGek opened this issue Mar 16, 2017 · 5 comments · Fixed by #9794
Closed

Put into the AI company when loading savegame #6544

DorpsGek opened this issue Mar 16, 2017 · 5 comments · Fixed by #9794
Labels
bug Something isn't working flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) good first issue Good for newcomers stale Stale issues

Comments

@DorpsGek
Copy link
Member

Samu opened the ticket and wrote:

When starting a network game by loading a savegame, I'm put into Company # 1.

If Company # 1 of that savegame belongs to an AI, this shouldn't be happening.

My proposal would be that I would start as a Spectator after finishing loading the savegame.

Steps:

- Launch OpenTTD
- Click Multiplayer
- Click Start server
- Click Load Game
- Select the attached savegame
- Click Load

Attachments

Reported version: Version?
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/6544
@DorpsGek DorpsGek added flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) Network labels Apr 7, 2018
@TrueBrain TrueBrain added good first issue Good for newcomers bug Something isn't working and removed bug from FlySpray labels Apr 10, 2018
@James103
Copy link
Contributor

James103 commented Apr 19, 2018

Happens vice versa.

Steps:

  1. Start a new server.
  2. Join spectators, then start a new company (id 2).
  3. Remove the company with id 1 (execute console command: "resetcompany 1")
  4. Start a new AI. It will go into company id 1.
  5. Save the game.
  6. Load the game in singleplayer.
  7. Notice that I'm put into the AI company (company id 1).

Possible solution: In single player, you should start in the first human player company (company id 2) that is in the save game, or the game should automatically create a new human company if there is none in the savegame.

@andythenorth andythenorth added the stale Stale issues label Jan 5, 2019
@andythenorth
Copy link
Contributor

Thanks for this. There's been no activity on this for some time, and as it stands, it doesn't look likely that it will go any further. I'm closing it as we try to keep the issue count low for OpenTTD, it helps us focus on things that are important and fun. Feel free to discuss in irc or request re-opening if you disagree. Thanks for contributing!

SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Jan 20, 2021
SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Jan 20, 2021
SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Jan 20, 2021
SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Jan 20, 2021
SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Jan 21, 2021
SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Jan 21, 2021
@SamuXarick
Copy link
Contributor

SamuXarick commented Jan 21, 2021

I created master...SamuXarick:start/load-network-games-as-spectator and despite what the branch name implies, the following are the actual changes as suggested by @James103 :

  • In both single player and multiplayer, the player start in the first human player company that is in the savegame, or the game automatically create a new human company if there is none in the savegame.

Making it work for single player was easy. I just created a function called GetFirstAvailableCompany that when called in afterload.cpp, it would either create the missing company or not, should a human company already exist. It is then in openttd.cpp that when setting the local company that GetFirstAvailableCompany is called once again which should always return the same result as when it was used in afterload.cpp, even though there is no way to assert this.

For multiplayer, there is a problem. There is a third variable, the network client ID of the server. The client id, as of current openttd master, is initialized before any game load has happened. It tries to set the local company before I can use GetFirstAvailableCompany. I tried to solve it by making this client ID initialize after the game is loaded, or after a new game is started, to be able to use GetFirstAvailableCompany in a similar fashion as in single player.

I'm unsure if this was the right approach, I don't know of the importance of the client id of the server existing before any generation/loading is done. Is that going to break server listing? Need someone with more experience to take a look at this.

@LordAro LordAro reopened this Jan 21, 2021
SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Jan 21, 2021
SamuXarick added a commit to SamuXarick/OpenTTD that referenced this issue Jan 28, 2021
@2TallTyler
Copy link
Member

Is this fixed by #9467, which makes everyone a spectator upon joining a network game?

Of course, it doesn't solve the scenario described by @James103 and with a proposed fix by @SamuXarick, but I think it clears up the questions about client IDs in network games.

@glx22
Copy link
Contributor

glx22 commented Jan 19, 2022

The network game side is probably fixed yes. Single player still go in first company.

2TallTyler added a commit to 2TallTyler/OpenTTD that referenced this issue Jan 19, 2022
2TallTyler added a commit to 2TallTyler/OpenTTD that referenced this issue Feb 3, 2022
2TallTyler added a commit to 2TallTyler/OpenTTD that referenced this issue Mar 18, 2022
2TallTyler added a commit to 2TallTyler/OpenTTD that referenced this issue Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) good first issue Good for newcomers stale Stale issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants