patch for growth-town and speed aircraft

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

Post Reply
benben
Engineer
Engineer
Posts: 6
Joined: 17 May 2005 15:28

patch for growth-town and speed aircraft

Post by benben »

Hello,

It's my first post on tt-forum :D , 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. :D
benben
french developper
User avatar
Gedemon
Traffic Manager
Traffic Manager
Posts: 150
Joined: 29 Apr 2004 21:53

Post 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... :oops:

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 ;)
Attachments
plane_loan_crash.zip
(4.27 KiB) Downloaded 387 times
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

Post 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.
benben
Engineer
Engineer
Posts: 6
Joined: 17 May 2005 15:28

Post by benben »

Thank you very much Gedemon ! :D

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 ( :oops: )

I send the last functional diff.

Is a documentation of OpenTTD source existing ? and where can I find it ?

Thanks for all the answers. :D

[Edit] Update the diff
Attachments
plane_speed.diff
(6.25 KiB) Downloaded 496 times
benben
french developper
benben
Engineer
Engineer
Posts: 6
Joined: 17 May 2005 15:28

Post 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
benben
french developper
benben
Engineer
Engineer
Posts: 6
Joined: 17 May 2005 15:28

Post 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.
Attachments
grow_town_with_transp_pass.diff
It's the diff for the new gestion of city grow.
(1.74 KiB) Downloaded 334 times
benben
french developper
benben
Engineer
Engineer
Posts: 6
Joined: 17 May 2005 15:28

Post 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.
Attachments
city_growth.diff
For a growth with the transported passengers and mails.
(3.16 KiB) Downloaded 367 times
benben
french developper
MildaIV
Engineer
Engineer
Posts: 52
Joined: 11 Nov 2005 09:07
Location: Czech Republic
Contact:

Post by MildaIV »

What about food and goods ? They should inflict town growth.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Amazon [Bot] and 4 guests