Page 1 of 1
patch for growth-town and speed aircraft
Posted: 17 May 2005 19:24
by benben
Hello,
It's my first post on tt-forum

, and I don't speak very well english
But I try to explain.
I want to modify the growth of towns and the speed of aircraft. But I haven't find informations about that.
For the town growth :
I want that town grow only with the transported passengers.
I fund the function
UpdateTownGrowRate.
But I didn't understand the value of t->growth_rate.
I believe that :
- when the value is equal to 127, the cities keep the number of population.
- when the value is upper than 127, the population fall down.
- when the value is lower than 127,the towns grow.
Can you confirm that ?
For the speed aircrafts :
I fund the function
UpdateAircraftSpeed.
But I didn't understand this function.
I want to multiply the speed with 2 (speed*2)
Somebody can help me for give the information how to change the speed ?
I'm sorry if I make a mistake on forum... I'm beginner in tt-forum.
Of course, I give the patch when I finish it but it's maybe so specialy for general use.
Thanks.
PS : TTO is the best game I've never seen. I play wit this game since 1995 and I'm enjoy that the evolution continue with (in first time TTD and now) OpenTTD. It's a really good work.

Posted: 17 May 2005 20:36
by Gedemon
Hello !
for plane speed here's a diff from my version. have a look if you want but be warned that my code is surely pretty bad as i'm *really, really, really* not a good programmer...
it's a full diff, so you'll have to sort out what you need, just to help you, a list of my changes :
- planespeed ( 1 - 8 ) : doesn't work well du to a limitation somewhere when you set it higher than 3... but as you ask for 2x...
- crash condition : more chance of happening when big planes land on small airport, or any broken plane landing (and even more chance for a big broken plane on small airport - company is sued by passengers family when it happens... not really tested yet) - btw added in plane detail a line to show if the plane need a long runway
- loan based on "hypotheque" value of company (and value based only on "possessions", not your cash nor actual loan)
can't help you for towngrowth...
ps : sorry for my english too

Posted: 17 May 2005 22:54
by Korenn
to get planespeed working, you have to patch the update aircraft position function to return an integer instead of a boolean, since it's possible it travels more than an entire tile per tick. See the train update function for examples how this is done.
hope that helps.
Posted: 18 May 2005 02:00
by benben
Thank you very much Gedemon !
I understand better.
I add a line for the acceleration of plane become realist with the max speed.
Korenn wrote:to get planespeed working, you have to patch the update aircraft position function to return an integer instead of a boolean, since it's possible it travels more than an entire tile per tick. See the train update function for examples how this is done.
I try to it but I don't succes. But I continue to try.
there are many callers of
UpdateAircraftSpeed in
AircraftController function. Maybe, it's possible to create a new function for calling
AircraftController the number of times returned by
UpdateAircraftSpeed .
I'm not sur that I explain is comprehensible (

)
I send the last functional diff.
Is a documentation of OpenTTD source existing ? and where can I find it ?
Thanks for all the answers.
[Edit] Update the diff
Posted: 18 May 2005 19:55
by benben
For the problem of towngrowth, I've seen this topic (Boost city growth):
http://www.tt-forums.net/viewtopic.php? ... c&start=53
But I haven't fund how to decrease, block or increase the town's population...
I want to do something like that :
Rate_Pass_Transported is the division of transported passengers by max passengers.
If Rate_Pass_Transported lower than 25, the population fall between 2% and 5%.
If Rate_Pass_Transported between 25 and 50%, the population don't change.
If Rate_Pass_Transported between 50 and 75%, the population grow between 2% and 10%
If Rate_Pass_Transported upper than 75%, the population grow at 20%.
It's why I search how use the t->growth_rate.
For the problem of plane speed, I've try to resolve the error for number higher than 3 but I don't success.
thanks
Posted: 19 May 2005 22:41
by benben
I've worked on city grow.
I think that when
t->growth_rate is smaller then the city grow faster.
I believe when
t->time_until_rebuild=1 then the city may (generaly) destroy a house.
I made this code, but it doesn't work well.
(I didn't use C++ since some years and I havre probably make a mistake)
Code: Select all
static void UpdateTownGrowRate(Town *t)
{
[...]
uint Pass, Mail;
Pass = ((t->act_pass * 256) / t->max_pass + 1);// like pct_transported_passenger but work better
Mail = ((t->act_mail * 256) / t->max_mail + 1);
// Reset player ratings if they're low
FOR_ALL_PLAYERS(p) {
[...]
t->flags12 &= ~1;
if (_opt.landscape == LT_HILLY) {
if (TilePixelHeight(t->xy) >= _opt.snow_line && t->act_food == 0 && t->population > 90)
return;
} else if (_opt.landscape == LT_DESERT) {
if (GetMapExtraBits(t->xy) == 1 && (t->act_food==0 || t->act_water==0) && t->population > 60)
return;
}
if (Pass == 0)// if no transported passenger then no grow
return;
if (Pass < 102)
{
t->time_until_rebuild = 1; // for destroy a house. but don't work very well
t->flags12 |= 1;
return;
}
if ((Pass < 128) || ((Mail < 64) && (Mail!=0)))
m = 180;
else
{
if (Pass < 205)
m = 140;
else
{
if (Mail > 205)
m = 40;
else
m = 110;
}
}
if (t->fund_buildings_months!=0) // if new buildings then grow 2 times faster.
m = (m / 2) + 1;
t->growth_rate = m / (t->num_houses / 50 + 1);
if (m <= t->grow_counter)
t->grow_counter = m;
t->flags12 |= 1;
}
I want to show the t->growth_rate on the city window (for debug), but I don't know how to do...
Thanks.
Posted: 20 May 2005 03:32
by benben
I have make a new code (less bad...) for the growth of towns.
(For decrease the population, I have make a spirale for find the peripheral houses, and I destroy with ClearTownHouse(Town *t,uint tile))
It works like that (chronological orders):
If the town is small then boost the growth,
If there is no transported passenger, no change,
If only a few of passengers are transported, the population fall.
More a lot of passenger and mails are transported, more the city growth.
The fund new buildings increase by two the growth.
It works well but I'm sur the code is bad...
I give the path for only the city_growth.
Posted: 31 Jan 2007 14:45
by MildaIV
What about food and goods ? They should inflict town growth.