API: Finances Infomation

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

API: Finances Infomation

Post by Ralph »

I may be being a bit blind here and just not seeing it, but is there a way to access information from the finances display? Things like profit last year would be useful in deciding when to pay back a loan or judge the general state of a company.
User avatar
Zhall
Tycoon
Tycoon
Posts: 1237
Joined: 17 Jul 2007 01:36
Skype: moonray_zdo
Location: Teh matrix, duh.
Contact:

Re: API: Finances Infomation

Post by Zhall »

Keep running tabs lol
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: API: Finances Infomation

Post by TrueBrain »

Yes, glad you took your pills.

On the positive side, I totally forgot about this post. There should be added some functions to AICompany indeed to query a few basics about the finances :) We will work on it!
The only thing necessary for the triumph of evil is for good men to do nothing.
wilco_moerman
Engineer
Engineer
Posts: 70
Joined: 05 Jun 2008 15:51

Re: API: Finances Infomation

Post by wilco_moerman »

TrueLight wrote:Yes, glad you took your pills.

On the positive side, I totally forgot about this post. There should be added some functions to AICompany indeed to query a few basics about the finances :) We will work on it!
In the same category: how is the company value calculated?
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Noldo
Engineer
Engineer
Posts: 75
Joined: 16 Jun 2005 13:17
Location: Lappeenranta, Finland

Re: API: Finances Infomation

Post by Noldo »

wilco_moerman wrote: In the same category: how is the company value calculated?
http://hg.openttd.org:8000/trunk.hg/fil ... conomy.cpp

a function named CalculateCompanyValue
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: API: Finances Infomation

Post by Rubidium »

Company value is the sum of the station values (some number created from the amount of facilities) of all stations plus a fairly big percentage of the value of all vehicles plus the amount of money on the bank account minus the loan.
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: API: Finances Infomation

Post by Ralph »

Noldo wrote:
wilco_moerman wrote: In the same category: how is the company value calculated?
http://hg.openttd.org:8000/trunk.hg/fil ... conomy.cpp

a function named CalculateCompanyValue
This is an AI discussion forum, but not everyone who searches the forums for how company value is calculated will want to poke through C code.

The function is:

Code: Select all

Money CalculateCompanyValue(const Player* p)
{
	PlayerID owner = p->index;
	Money value = 0;

	Station *st;
	uint num = 0;

	FOR_ALL_STATIONS(st) {
		if (st->owner == owner) num += CountBits(st->facilities);
	}

	value += num * _price.station_value * 25;

	Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		if (v->owner != owner) continue;

		if (v->type == VEH_TRAIN ||
				v->type == VEH_ROAD ||
				(v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) ||
				v->type == VEH_SHIP) {
			value += v->value * 3 >> 1;
		}
	}

	/* Add real money value */
	value -= p->current_loan;
	value += p->player_money;

	return max(value, (Money)1);
}
From my understanding:

For every station the player owns, add the number of bits set in the facilities byte, this I assume will be a number between 1 and 8 for every station, this sum is then multiplied by some station value constant then 25. Exactly what the facilities byte represents I don't know, but guess its a bitmap for various services offered?

Then for vehicles, the value of each vehicle is taken, multiplied by 3, bitshifted right(??), and added to the total for the stations.

Then your loan is subtracted and current cash is added, finally if the result is negative, its set to 1.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: API: Finances Infomation

Post by Yexo »

Ralph wrote: From my understanding:

For every station the player owns, add the number of bits set in the facilities byte, this I assume will be a number between 1 and 8 for every station, this sum is then multiplied by some station value constant then 25. Exactly what the facilities byte represents I don't know, but guess its a bitmap for various services offered?
It contains one bit if there is a busstop in the station, one bit for a truck stop, one bit for a train station and one bit for an airport.
Then for vehicles, the value of each vehicle is taken, multiplied by 3, bitshifted right(??),
In other terms, multiplied by 1,5.
Then your loan is subtracted and current cash is added, finally if the result is negative, its set to 1.
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: API: Finances Infomation

Post by Roujin »

Yexo wrote:
Then for vehicles, the value of each vehicle is taken, multiplied by 3, bitshifted right(??),
In other terms, multiplied by 1,5.
...rounded down. :P
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 41 guests