How would I create Gamelogic with GSes AND NewGRFs?

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

Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

How would I create Gamelogic with GSes AND NewGRFs?

Post by Openend »

Hello, in my previous thread I figured out, that for what I intend to do (industry / city value change, custom triggers etc) probably requires a patch.

This seems like a daring endeavour, but I am willing to try.

One questions I have left after taking a look into the repository.
Would I be able to develop in C# and compile a working binary using Mono/dot Net? Or is there any method to create code in C# and get a working copy of openttd after compiling? Thanks!

This may be a very dumb question, some of you may cringe :), but I want to know.
Last edited by Openend on 08 Jul 2015 10:00, edited 1 time in total.
User avatar
FLHerne
Tycoon
Tycoon
Posts: 1543
Joined: 12 Jul 2011 12:09
Location: St Ives, Cambs, UK

Re: Converter / Mono usable for source modification?

Post by FLHerne »

No.

OpenTTD is in C++. While it might be possible to automatically convert it to C# (there are working demos of conversion to in-browser javascript) the output of tools like that tends to be rather unreadable by humans. You'd also be unable to create a standalone patch (reverse conversion would end up with almost every line being different), which would make updating against newer OTTD versions or applying other patches a case of rewriting the whole thing each time.
Temporary Permanent signature filling text. Content coming soon delayed indefinitely! Oh, and I have had a screenshot thread.
Linux user (XMonad DWM/KDE, Arch), IRC obsessive and rail enthusiast. No longer building robots; now I ring church bells.
Author of an incredibly boring stickied post about NewGRFs.
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Re: Converter / Mono usable for source modification?

Post by Openend »

Well, that means I'll have to use c++?

Is there any sort of flow chart for the repository? I can understand the basic structure, but it would be very nice to have an overview, how the code is executed. Thanks anyway!
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Converter / Mono usable for source modification?

Post by planetmaker »

Openend wrote:Well, that means I'll have to use c++?

Is there any sort of flow chart for the repository? I can understand the basic structure, but it would be very nice to have an overview, how the code is executed. Thanks anyway!
Of course it means to use C/C++. Or can you write an English text in Chinese?

There is no flow chart. Start with openttd.cpp and continue from the main loop found within. Also make use of the doxygen documentation: http://docs.openttd.org/classGame.html
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Converter / Mono usable for source modification?

Post by Alberth »

The "overview" concept is overrated probably, I'd start at files that look city-ish or industry-ish, and go from there.
Being a retired OpenTTD developer does not mean I know what I am doing.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Converter / Mono usable for source modification?

Post by Eddi »

depending on how sophisticated your IDE is, it could generate you a call graph or similar for you to navigate through
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Re: Converter / Mono usable for source modification?

Post by Openend »

@planetmaker
Thanks for the warm welcome and the info provided!

At the moment I am really torn between digging into it, and developing a standalone (related, but no clone) game in Unity.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Converter / Mono usable for source modification?

Post by Alberth »

OpenTTD is 300K+ lines, assuming you can do 20K / year, that will take 15 years. Maybe you can skip some functionality, but you'll soon need a decade or so if you know how to build a program like that at that scale.
Being a retired OpenTTD developer does not mean I know what I am doing.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Converter / Mono usable for source modification?

Post by planetmaker »

Openend wrote:@planetmaker
Thanks for the warm welcome and the info provided!

At the moment I am really torn between digging into it, and developing a standalone (related, but no clone) game in Unity.
In order to add to Alberth's reasoning: the road to a functional game at this scale is very lengthy. On the other hand, if you know how to programme in any programming language, then programming in another is a comparatively small step. Most concepts stay the same, mostly only syntax varies slightly.
lukasz1985
Route Supervisor
Route Supervisor
Posts: 429
Joined: 27 Mar 2013 08:58
Location: Strumien
Contact:

Re: Converter / Mono usable for source modification?

Post by lukasz1985 »

Alberth wrote:OpenTTD is 300K+ lines, assuming you can do 20K / year, that will take 15 years. Maybe you can skip some functionality, but you'll soon need a decade or so if you know how to build a program like that at that scale.
OpenTTD is 300k LOC but most of this code is implementing low level functionality, like blitters, sound and music drivers. I guess that effectively there is maybe 50k LOC that are used for the real game-logic. I've also found that OTTD code is not the best quality and could be optimized away, cutting another 10k of LOC.

Another thing is that 20k LOC/year is 50 lines a day. That's pretty low. When I was actively programming, sometimes I've got from 200-300 LOC a day.

So your calculations are pretty bad and inaccurate.
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Converter / Mono usable for source modification?

Post by Alberth »

lukasz1985 wrote:OpenTTD is 300k LOC but most of this code is implementing low level functionality, like blitters, sound and music drivers. I guess that effectively there is maybe 50k LOC that are used for the real game-logic.
Please point me to the 250K lines of driver stuff.
The 300K lines is all in trunk/src, I didn't count SDL, and other libraries that we use.
lukasz1985 wrote:I've also found that OTTD code is not the best quality and could be optimized away, cutting another 10k of LOC.
Like you always write top-most quality in a language at all times. You will mess up in a program of this scale, and get less than optimal quality. It's not a problem, but claiming you will not at that complexity seems very unlikely to me.
lukasz1985 wrote:Another thing is that 20k LOC/year is 50 lines a day. That's pretty low. When I was actively programming, sometimes I've got from 200-300 LOC a day.
It's quite realistic, perhaps even optimistic, depending on how you are counting. In the about 4 years I am writing FreeRCT, I managed to produce around 80K lines, and deleted 30K lines again (this also includes changes in the lines, so not everything is deleting). So I have about 50K lines as a result after 4 years.

When you typing away, sure it's easy to produce a 1000 lines a day. But you cannot type 24/7. There is this thing called Real Life (work/study/parents/etc) so your time is the weekend alone mostly, also you need time to think about what to do next, debug your code, and take the occasional day off from it all.
lukasz1985 wrote:So your calculations are pretty bad and inaccurate.
Not so sure about that, but feel free to ignore my calculations, and proof prove me wrong. I'd be happy for you.
In general though, people grossly underestimate the amount of effort and dedication that it takes to pull it off. FreeRCT isn't close to being playable after 4 years.

Edit: As another reference (thanks planetmaker): https://www.openhub.net/p/openttd claims even less lines / year than both you and me (241K reall code lines with 63 year of work according to the COCOMO model). My 300K lines is really everything, they probably skip comments and blank lines.
Being a retired OpenTTD developer does not mean I know what I am doing.
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Re: Converter / Mono usable for source modification?

Post by Openend »

Well I am not talking about cloning the game. I would try to distill, what I really like in Openttd and recreate it in another context. This is still a large project for the two of us (hobbyists)
And I wouldnt have the build the engine.

But first Ill have another look at gamescripts. If there would only be a way to influence industries by using GSes....
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: Converter / Mono usable for source modification?

Post by Wahazar »

Openend wrote: But first Ill have another look at gamescripts. If there would only be a way to influence industries by using GSes....
Maybe you should point out exactly (in your previous thread), which new features you want to achieve? That should help to show proper path.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Converter / Mono usable for source modification?

Post by Eddi »

lukasz1985 wrote:Another thing is that 20k LOC/year is 50 lines a day. That's pretty low. When I was actively programming, sometimes I've got from 200-300 LOC a day.
your calculation has a lot of flaws, but maybe let me point out these two major ones:
  1. if you're writing more than 10 lines per hour, you've not spent enough time thinking about how to solve the problem with as few lines as possible. programming is not a contest of who can write the most lines in the shortest time. a bad programmer can easily write 100 lines per hour. a good programmer writes 10 lines per hour doing the exact same stuff, but it probably runs 10 times faster and is maintainable in the future.
  2. you can't expect to work full time (8h/day) for a whole year on a hobby project
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Re: Converter / Mono usable for source modification?

Post by Openend »

@mcZapkie
I'll do it because
Edit: That was meant to be: Ill do it here because...
Last edited by Openend on 07 Jul 2015 21:39, edited 1 time in total.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: Converter / Mono usable for source modification?

Post by Wahazar »

Openend wrote:@mcZapkie

I'll do it because it is quite simple: I want to control the production of industries via Gamescript. From what I heard so far, it is not possible.
OK, but more general - why you want to control it. What is a whole idea?
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Re: Converter / Mono usable for source modification?

Post by Openend »

The basic idea is to reward the player (like in BusyBee) with City Growth and Industrial Growth when some conditions are fulfilled. City Growth should be no problem, but afaik you cannot influence industrial production from Gamescripts, or can you? Thanks a lot for your help, by the way :)
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Converter / Mono usable for source modification?

Post by Alberth »

No you cannot.

The reason is that NewGRF specifications do not allow it. The only thing that OpenTTD can do within the specification is ask a NewGRF to open a new industry at some spot. If it doesn't like the spot or it doesn't like the terrain, you're out of luck.
You cannot ask the industry what terrain (shape) it wants.

Once created, industries themselves decide to increase or decrease production.
Once created, industries themselves decide whether or not to close.

You cannot inform industries of the world status. Something like "He, there are 54 of your kind, while the map chance indicates there should be only 28". You cannot ask an industry to close down.

Total control like you may want is even further away.
Being a retired OpenTTD developer does not mean I know what I am doing.
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Re: Converter / Mono usable for source modification?

Post by Openend »

Thank you for the information. Ive been told, that GSes cannot rely on specific NEWGRF's presence. But may it be possible to combine a NEWGRF and a Gamescript to achieve this effect, and write a warning into the readme's that both need to be present?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Converter / Mono usable for source modification?

Post by planetmaker »

Openend wrote:Thank you for the information. Ive been told, that GSes cannot rely on specific NEWGRF's presence. But may it be possible to combine a NEWGRF and a Gamescript to achieve this effect, and write a warning into the readme's that both need to be present?
An industry can get many information about cargo being transported away from it or being delivered and of course it can adjust its production based on it or even close down.
And a game script can check the amount of industries, the stations and the cargo delivered / transported and try to found new industries.

While documentation can be shipped with both, GS and NewGRF, and even be viewed ingame, it's a good idea to prepare one. However experience has it that any documentation you provide, is usually written for yourself and usually only serves the purpose so that the developer (aka you) can tell the users "you could have known, if you had read the documentation" ;)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 32 guests