Patch: save company info

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
ever
Traffic Manager
Traffic Manager
Posts: 164
Joined: 26 Apr 2009 11:45

Re: Patch: save company info

Post by ever »

You mean like the player profile Idea I suggested two or so posts above.

You know how in modern games they get you to make a profile before you start playing and then all your save games and gamedata stats are for that profile only.

You could do the same thing where you name your company president chose your favorite colors etc. and THEN start a game whether it be singly player or multiplayer. Of course you could change this again during the game...

mattyspatty
Engineer
Engineer
Posts: 10
Joined: 26 Jul 2010 20:35
Location: Lancashire, UK

Re: Patch: save company info

Post by mattyspatty »

I have recreated this patch to work on the current revision.
The previously posted patch was a great starting point but it has been mostly re-written. Hope you all enjoy it :)

Has been tested in single player, and briefly in multiplayer. If you encounter any issues or have any suggestions, I'm all ears :)

To use it, simply open up your company window and click "Load Profile". You will need to save once before you can load in future games!


**Updated patch - 05/Aug**
Attachments
company_profile_20363_v02.patch
(12.2 KiB) Downloaded 74 times
Last edited by mattyspatty on 05 Aug 2010 12:31, edited 1 time in total.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4554
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Patch: save company info

Post by Zuu »

Hi,

I've first taken a look on the boring coding style parts. I would recommend you to re-reed the coding style document and change your code to match that. Most noticeable, but a space between 'if' and the bracket. In addition to that, open your patch file in your text editor of choice and look for unnecessary changes. You got some extra empty lines here and there.

Regarding the structure of your patch, I would think it is more logical to split out the part of CompanyLoadProfile that applies the loaded CompanyProfile object to the current company into a separate function. This would create a function similar to your GetCompanyProfile. Or is there a reason why Saving is split into two functions but not Loading?

When you continue to add window saving, try to make the two works as independent as possible. Or at least you should try hg queues or the git equivalent (I'm not a git user so I don't know what they call it). With hg queues you can maintain your changes into a series of patches that (usually) sequentially add more and more changes. Doing things in small steps makes it easier to review and in the end increases your chances of getting your patch included into OpenTTD.
Attachments
company_profile_20363_commented.patch
Look for 'Zuu:' in the file
(12.06 KiB) Downloaded 55 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

mattyspatty
Engineer
Engineer
Posts: 10
Joined: 26 Jul 2010 20:35
Location: Lancashire, UK

Re: Patch: save company info

Post by mattyspatty »

Firstly, thanks for the feedback. I'm a big newbie at the moment so constructive criticism is welcomed!

Zuu wrote:Hi,

I've first taken a look on the boring coding style parts. I would recommend you to re-reed the coding style document and change your code to match that. Most noticeable, but a space between 'if' and the bracket. In addition to that, open your patch file in your text editor of choice and look for unnecessary changes. You got some extra empty lines here and there.
I keep forgetting I need to adhere to styles other than what I learnt, I'll update and try to remember in future. I'll also clean up the patch files.

Regarding the structure of your patch, I would think it is more logical to split out the part of CompanyLoadProfile that applies the loaded CompanyProfile object to the current company into a separate function. This would create a function similar to your GetCompanyProfile. Or is there a reason why Saving is split into two functions but not Loading?
CompanyLoadProfile was condensed so that only 1 call is needed to load from the data file to having the data filled in, I put the saving in 2 parts so that GetCompanyProfile could be reused elsewhere.
In hindsight a SetCompanyProfile function would be logical. I shall add that now too

When you continue to add window saving, try to make the two works as independent as possible. Or at least you should try hg queues or the git equivalent (I'm not a git user so I don't know what they call it). With hg queues you can maintain your changes into a series of patches that (usually) sequentially add more and more changes. Doing things in small steps makes it easier to review and in the end increases your chances of getting your patch included into OpenTTD.
The window saving is a completely independant patch, hopefully I can take some experience from this and apply it (i.e. sticking to the coding styles). However, if I had any clue what a HG queue was I might consider it...

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4554
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Patch: save company info

Post by Zuu »

My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

mattyspatty
Engineer
Engineer
Posts: 10
Joined: 26 Jul 2010 20:35
Location: Lancashire, UK

Re: Patch: save company info

Post by mattyspatty »

I think I'll pass on that, it's a bit overkill for my needs.

I have updated the patch however, I'm confident it meets the coding style this time and I double checked for extra lines in the .patch :)

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4554
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Patch: save company info

Post by Zuu »

Looks better.

You still have two lines of code that has been commented out. These has to be removed before the patch can get accepted. (Note that I don't have the rights to accept or reject any patches, but I can tell that generally you are not allowed to have commented out lines of code in patches that are to be approved for trunk inclusion)

You might want to comment the members in your new CompanyProfile struct. What is the purpose of for example the error_id member?

I've noticed you use strcpy and sprintf. IIRC OpenTTD use the safer variants of those where you specify maximum buffer lengths. Take a look on existing code to see exactly which functions that are used.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
Muzzly
Traffic Manager
Traffic Manager
Posts: 226
Joined: 09 Jun 2010 20:54
Location: Vilnius, LT

Re: Patch: save company info

Post by Muzzly »

Hello Antdovu and other Tycoones

I have modified your patch a bit.
I added Advanced Settings option to load profile by default for every new game. It is located in Interface section, named "Load preferred company profile". Default value is false(disabled). Enable it to have same face and color for every game :-) (See image)

Also I have found "copy paste type" error in company_gui.cpp (line 1980).
Instead of calling
this->LowerWidget(CW_WIDGET_RELOCATE_HQ);
you called
this->LowerWidget(CW_WIDGET_BUILD_HQ);

The same copy paste mistake was made for CW_WIDGET_PROFILE_SAVE button ( down few lines ).

One thing where I am a bit confused . In line 1984 (file company_gui.cpp) I do not understand why with uncommented following lines patch works ?(

Code: Select all

//this->RaiseWidget(CW_WIDGET_PROFILE_LOAD);
//this->SetWidgetDirty(CW_WIDGET_PROFILE_LOAD);
Normally we should raise buttons again. Maybe buttons is raised somewhere else by some other function ?( Anyway not important, patch is doing what it suppose to do :)

I have not tested this patch under Linux or Mac.
Attachments
company_profile_v4_20441.patch
Company profile patch. Version4 for revision 20441
(15.08 KiB) Downloaded 60 times
image_4_v4_20441.png
image_4_v4_20441.png (12.61 KiB) Viewed 1214 times

mattyspatty
Engineer
Engineer
Posts: 10
Joined: 26 Jul 2010 20:35
Location: Lancashire, UK

Re: Patch: save company info

Post by mattyspatty »

Reviving this, again!
I recently started playing OpenTTD again and decided I wanted to try and get this feature into the game.
I have reworked the last patch (Muzzly's) to work with a more recent version (22470), the features are unchanged.
#Tested in multiplayer; However, this patch changes your name, company name, face and then colour scheme, if it fails changing the colour scheme your name, company name and face WILL have changed, similarly if somoene has the same company name, your manager will change but the company name, face and colour scheme will not. Though, I am not sure if this is a bad thing at the moment!
#Untested on Mac or Linux
#Livery specialisation does not seem to be working (e.g. Red main scheme with Blue Road Vehicles), I think this requires dual company colours (which I can't seem to find, was this feature removed?)

As always, I am open to, and welcome, constructive criticism!


I have also included the Windows executables as I know some people don't like patching manually! (Plus it seemed to take me about 5 minutes to create the library :/)
Attachments
company_profile_v5_r22470.patch
(14.07 KiB) Downloaded 78 times
openttd.zip
Use this version if you are unsure you have 64bit
(3.15 MiB) Downloaded 51 times
openttd64.zip
64bit version
(3.73 MiB) Downloaded 53 times

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 1 guest