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

Open
DorpsGek opened this issue Mar 16, 2017 · 3 comments
Open

Put into the AI company when loading savegame #6544

DorpsGek opened this issue Mar 16, 2017 · 3 comments

Comments

@DorpsGek
Copy link

@DorpsGek DorpsGek commented Mar 16, 2017

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
@James103
Copy link
Contributor

@James103 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
Copy link
Contributor

@andythenorth andythenorth commented Jan 5, 2019

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants