Page 1 of 1

API: Finances Infomation

Posted: 17 Jun 2008 22:15
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.

Re: API: Finances Infomation

Posted: 22 Jun 2008 23:10
by Zhall
Keep running tabs lol

Re: API: Finances Infomation

Posted: 22 Jun 2008 23:25
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!

Re: API: Finances Infomation

Posted: 23 Jun 2008 09:32
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?

Re: API: Finances Infomation

Posted: 23 Jun 2008 09:57
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

Re: API: Finances Infomation

Posted: 23 Jun 2008 09:58
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.

Re: API: Finances Infomation

Posted: 23 Jun 2008 14:37
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.

Re: API: Finances Infomation

Posted: 23 Jun 2008 14:54
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.

Re: API: Finances Infomation

Posted: 23 Jun 2008 19:45
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