Documentation on how the game was ported to C/C++
Moderator: OpenTTD Developers
-
- Engineer
- Posts: 4
- Joined: 31 Oct 2011 01:30
Documentation on how the game was ported to C/C++
Dear All,
I am planning to make a presentation about openTTD at our local LUG (Beijing) this month and I would like to talk a little about how the game has been created.
Do you have any documentation available on how (using which tools and what process) the game has been ported to C/C++?
Cheers,
Julien
I am planning to make a presentation about openTTD at our local LUG (Beijing) this month and I would like to talk a little about how the game has been created.
Do you have any documentation available on how (using which tools and what process) the game has been ported to C/C++?
Cheers,
Julien
Re: Documentation on how the game was ported to C/C++
well, here is the c++ branch merge commit:
http://vcs.openttd.org/svn/changeset/8038
http://vcs.openttd.org/svn/changeset/8038
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Documentation on how the game was ported to C/C++
This game is a re-implementation of TTD and is already originally written in C (thus no porting needed) and slowly more and more elements were and are moved to C++.blug_julien wrote:Dear All,
I am planning to make a presentation about openTTD at our local LUG (Beijing) this month and I would like to talk a little about how the game has been created.
Do you have any documentation available on how (using which tools and what process) the game has been ported to C/C++?
Cheers,
Julien
Thus all you need is an editor of your choice and a C/C++ compiler (and the required libraries). Of course other tools like Valgrind etc have been of great use as well.
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
-
- Engineer
- Posts: 4
- Joined: 31 Oct 2011 01:30
Re: Documentation on how the game was ported to C/C++
Thanks for your replies, I think I got confused somewhere so I did a little more reading and I am back with some more questions
My understanding is it goes like this:
(1) Transport Tycoon Deluxe was originally coded in Assembly and released in 94 as an MS DOS game
(2) The game was then ported to C to run on Windows 95 in the late 90s
(3) Then OpenTTD was started 2003.
What confuses me is the wikipedia page says the following:
I hope I am making more sense, and that the wikipedia page is accurate
Julien
Edit: found some good info in the first release forum thread: http://www.tt-forums.net/viewtopic.php?f=29&t=6559

My understanding is it goes like this:
(1) Transport Tycoon Deluxe was originally coded in Assembly and released in 94 as an MS DOS game
(2) The game was then ported to C to run on Windows 95 in the late 90s
(3) Then OpenTTD was started 2003.
What confuses me is the wikipedia page says the following:
I would like to know if this re-engineering was done from the original assembly code or from the C Windows 95 port. And most importantly, if there is any information on how it was done and (as a bonus) if it is similar to the work done with openDune.In 2003 Ludvig Strigeus announced he was intending to reverse engineer Transport Tycoon Deluxe and convert the game to C. In 2004 this re-engineered Transport Tycoon Deluxe was released and christened "OpenTTD".[10][11]
I hope I am making more sense, and that the wikipedia page is accurate

Julien
Edit: found some good info in the first release forum thread: http://www.tt-forums.net/viewtopic.php?f=29&t=6559
-
- Tycoon
- Posts: 5954
- Joined: 27 Apr 2005 07:09
- Contact:
Re: Documentation on how the game was ported to C/C++
Much information has been drawn from Marcin´s documentation of the Transport Tycoon Deluxe savegame internals which had been originally prepared for the development of TTDPatch.blug_julien wrote: I would like to know [...] if there is any information on how it was done
regards
Michael
Re: Documentation on how the game was ported to C/C++
That AFAIK is not correct. Yes, the game was made to run on Win95, but not ported to C. The graphics palette was changed to allow for the Windows system colours and a loader was added. But the game itself is still ASM.blug_julien wrote:(2) The game was then ported to C to run on Windows 95 in the late 90s
Re: Documentation on how the game was ported to C/C++
How OpenTTD was exactly reconstructed from Transport Tycoon Deluxe only Ludde most likely knows. At a certain point it just was. By the looks of pre-releases, he build it from the ground up, looking closely to how TTD did things. But this process has never been written down (or shared) to my knowledge, and all information you read on the web about it are most likely guessed by people who weren't involvedblug_julien wrote:(..)
I would like to know if this re-engineering was done from the original assembly code or from the C Windows 95 port. And most importantly, if there is any information on how it was done and (as a bonus) if it is similar to the work done with openDune.In 2003 Ludvig Strigeus announced he was intending to reverse engineer Transport Tycoon Deluxe and convert the game to C. In 2004 this re-engineered Transport Tycoon Deluxe was released and christened "OpenTTD".[10][11]
(..)


Also, what FooBar already said: as far as I am aware, there was never created any C port for Windows 95. It just was made compatible enough to run on those systems.
In relation to OpenDUNE, nothing is comparable. The process of OpenDUNE is highly unique (if I say so myself) and has not been attempted on any other project of such scale (in the Open Source world). OpenDUNE could only be done like this, because Dune2 was compiled by a real compiler (Borland C compiler), where TTD was written in assembly. The same process would be impossible to apply on TTD. (it highly depends on the existence and consistency of function-frames).
Hope this helps you a bit. Make sure to share your presentation with us, I am sure a few people would be interested in it. Good luck.
The only thing necessary for the triumph of evil is for good men to do nothing.
Re: Documentation on how the game was ported to C/C++
If you read Swedish, there was a quite long (8 pages) article about Ludvig in a Swedish magazine this summer. The article is in the "jun/jul 2011" issue and the magazine is called "Filter". The article is about Ludvig and his programming projects.
It doesn't provide any fundamental new information but it is still a good article that is not too shallow.
Edit: According to the magazine website it appears that the article is in issue #20 (you still need to obtain a copy via eg. a library or contacting them)
It doesn't provide any fundamental new information but it is still a good article that is not too shallow.
Edit: According to the magazine website it appears that the article is in issue #20 (you still need to obtain a copy via eg. a library or contacting them)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
-
- Engineer
- Posts: 4
- Joined: 31 Oct 2011 01:30
Re: Documentation on how the game was ported to C/C++
Thanks again for all the answers, I unfortunately do not read any Swedish so I will keep the mystery around the port
It is a pity that the process has not been more documented as the output is quite remarkable and I am curious to know if it could be done for other old games / applications
And also, as this is the development board, thanks for the great work
It is a pity that the process has not been more documented as the output is quite remarkable and I am curious to know if it could be done for other old games / applications
And also, as this is the development board, thanks for the great work

Re: Documentation on how the game was ported to C/C++
I am not sure whether switching to another programming language would still be 'porting', it sounds a bit at the edge the definition.blug_julien wrote:... I am curious to know if it could be done for other old games / applications
Aside from that technicality, I am quite sure you *could* do it for other programs too. There may be legal problems though, many programs explicitly forbid reverse engineering in their license.
On the other hand, there are several other possibilities too, like: de-compile, get the actual source code, or write from scratch with or without use of the original game data. Each of these (and no doubt more options exist) has its advantages and disadvantages. I'd say it all depends on what the person(s) doing the actual work prefer, together with legal implications and technical expertise.
Re: Documentation on how the game was ported to C/C++
however, german copyright states, that for any license stating that, this part is void.Alberth wrote:There may be legal problems though, many programs explicitly forbid reverse engineering in their license.
in general, there are two kinds of reverse engineering, the first, more legally lenient, way is to "watch" the operations of the program, then you can freely write your own program that does something similar. the second is to decompile/disassemble/other automatically and modify the program directly this way, this method may only be used for "compatibility with another program" (e.g. porting to a different OS) and "bug fixes", but this may only be distributed to people which have a licensed copy of the original.
-
- Engineer
- Posts: 4
- Joined: 31 Oct 2011 01:30
Re: Documentation on how the game was ported to C/C++
I also believe that for some of these old games/app from the 80s or early 90s, nobody actually as any clue of who owns the game 

Re: Documentation on how the game was ported to C/C++
Given that Transport Tycoon was written in assembly, the decompiled code was largely human readable (or at least more so than if a compiler would've had its way with it). The original "porter", Ludde, then basically retranslated all the assembly code back to C, made it logical in the parts he could figure out what was going on.
I remember for quite a long time how the AI was just a black big box. unk0 - unkXXX variables everywhere, unfollowable code, etc. Ludde had no idea - nor the desire - what was going on in there
. We spent most of the time in the beginning figuring out what the code was doing, rewriting it and documenting functionality.
After this a gradual C++ translation was started. I believe one of the first structures was Vehicle.
I remember for quite a long time how the AI was just a black big box. unk0 - unkXXX variables everywhere, unfollowable code, etc. Ludde had no idea - nor the desire - what was going on in there

After this a gradual C++ translation was started. I believe one of the first structures was Vehicle.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Who is online
Users browsing this forum: Baidu [Spider] and 1 guest