The International Simutrans Forum

Development => Technical Documentation => Topic started by: jamespetts on December 15, 2013, 09:55:15 PM

Title: City growth code
Post by: jamespetts on December 15, 2013, 09:55:15 PM
I need to embark on some work in fixing and probably redesigning city growth code in Experimental's devel-new branch to prepare for the next major release. However, city growth is not an area of the code into which I have previously delved. Would any of the Standard developers be so kind to give me a brief overview of how the code is intended to work, and the main methods/functions (which exactly is the correct term for C++ in any event?) that handle city growth? I should be exceedingly grateful.
Title: Re: City growth code
Post by: prissi on December 15, 2013, 11:22:17 PM
THe calculations all happens in void stadt_t::step(long delta_t)
There are two functions then calc_growth() and step_grow_city(). There the actual magic happens. But I am not sure if experimetnal is still using the same.
Title: Re: City growth code
Post by: jamespetts on December 15, 2013, 11:36:38 PM
Thank you - that is helpful. Experimental has not made major changes to these yet. In general terms, how do calc_growth() and step_grow_city() work?
Title: Re: City growth code
Post by: Ters on December 16, 2013, 06:01:40 AM
Quote from: jamespetts on December 15, 2013, 09:55:15 PM
methods/functions (which exactly is the correct term for C++ in any event?)

Standalone functions (like main()) are a functions. Functions that are part of a class are member functions.
Title: Re: City growth code
Post by: jamespetts on December 16, 2013, 10:01:46 AM
Intriguing - I had originally thought that all object oriented languages used the term "method" for what are described here as "member functions". It is confusing that C++ is not a functional language yet has "functions"...
Title: Re: City growth code
Post by: wlindley on December 16, 2013, 11:51:23 AM
Even Microsoft BASIC in the early 1980s had functions (http://hwiegman.home.xs4all.nl/gw-man/DEFFN.html):  10 DEF FNFOO(X)=X^2
Title: Re: City growth code
Post by: Ters on December 16, 2013, 06:10:56 PM
Quote from: jamespetts on December 16, 2013, 10:01:46 AM
It is confusing that C++ is not a functional language yet has "functions"...

Well, you can do some simple functional programming with C++.
Title: Re: City growth code
Post by: jamespetts on December 16, 2013, 07:25:36 PM
Quote from: Ters on December 16, 2013, 06:10:56 PM
Well, you can do some simple functional programming with C++.

Yes, I suppose that that is also confusing, as is much about C++...
Title: Re: City growth code
Post by: kierongreen on December 16, 2013, 10:43:51 PM
Not really - C++ like many languages gives you a variety of tools to write your code in. As was pointed out many BASIC variants have functions as well as procedures.