API: Finances Infomation
Moderator: OpenTTD Developers
API: Finances Infomation
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.
- Zhall
- Tycoon
- Posts: 1237
- Joined: 17 Jul 2007 01:36
- Skype: moonray_zdo
- Location: Teh matrix, duh.
- Contact:
Re: API: Finances Infomation
Keep running tabs lol
Formerly known as Sapphire United.
Learn Openttd
Learn Planetary Annihilation
Learn Orbit
Whose poo?
Learn Openttd
Learn Planetary Annihilation
Learn Orbit
Whose poo?
Re: API: Finances Infomation
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!
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

The only thing necessary for the triumph of evil is for good men to do nothing.
-
- Engineer
- Posts: 70
- Joined: 05 Jun 2008 15:51
Re: API: Finances Infomation
In the same category: how is the company value calculated?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 financesWe will work on it!
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Re: API: Finances Infomation
http://hg.openttd.org:8000/trunk.hg/fil ... conomy.cppwilco_moerman wrote: In the same category: how is the company value calculated?
a function named CalculateCompanyValue
Re: API: Finances Infomation
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
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.Noldo wrote:http://hg.openttd.org:8000/trunk.hg/fil ... conomy.cppwilco_moerman wrote: In the same category: how is the company value calculated?
a function named CalculateCompanyValue
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);
}
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
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.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?
In other terms, multiplied by 1,5.Then for vehicles, the value of each vehicle is taken, multiplied by 3, bitshifted right(??),
Then your loan is subtracted and current cash is added, finally if the result is negative, its set to 1.
Re: API: Finances Infomation
...rounded down.Yexo wrote:In other terms, multiplied by 1,5.Then for vehicles, the value of each vehicle is taken, multiplied by 3, bitshifted right(??),

Who is online
Users browsing this forum: No registered users and 8 guests