Help with cargo supply values and payment

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
CaesiumFarmer
Engineer
Engineer
Posts: 21
Joined: 25 Jun 2012 03:35

Help with cargo supply values and payment

Post by CaesiumFarmer »

I may have mis-titled this post, or put it in the wrong section. If so please let me know.

Here is my first question:
What determines the cargo output of an industry or group of houses?
I have been looking through the source code and wiki, but I can't seem to find it. Either that or I am glazing over it. I have already looked through this but it doesn't seem to have the answer. Or I am glazing over it like I said. That did partially answer my second problem though.

On to my second problem:
The function 'GetTransportedGoodsIncome' references the "price factor" of the cargo:

Code: Select all

/* "The result should be a signed multiplier that gets multiplied
			 * by the amount of cargo moved and the price factor, then gets
			 * divided by 8192." */
			return result * num_pieces * cs->current_payment / 8192;
What is the price factor and what determines it? Is that the factor 'cs->current_payment'?

Thanks!

Edit: The reason I wanted answers to these questions was for AI development, but I looked into the NoAI API more and found AITile::GetCargoAcceptance, and AITile::GetCargoProduction. They will do what I need, but it would still be nice to know where the numbers are coming from in the first place if someone knows.
User avatar
FLHerne
Tycoon
Tycoon
Posts: 1543
Joined: 12 Jul 2011 12:09
Location: St Ives, Cambs, UK

Re: Help with cargo supply values and payment

Post by FLHerne »

The wiki page on game mechanics has a section on industry production. Probably doesn't apply to NewGRF sets.
Temporary Permanent signature filling text. Content coming soon delayed indefinitely! Oh, and I have had a screenshot thread.
Linux user (XMonad DWM/KDE, Arch), IRC obsessive and rail enthusiast. No longer building robots; now I ring church bells.
Author of an incredibly boring stickied post about NewGRFs.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Help with cargo supply values and payment

Post by frosch »

The API function AITile::GetCargoAcceptance, and AITile::GetCargoProduction do NOT tell you the AMOUNT of cargo, which is produced or accepted.

For payment you are best off using AICargo::GetCargoIncome.

Industries, esp. NewGRF industries can change production any month depending on an basically unlimited number of criterions. For industries you are usually best off using AIIndustry::GetLastMonthProduction to get an idea about the production. There is no way in the API to detect whether an industry has limited acceptance.

Houses otoh always have unlimited acceptance. If AITile::GetCargoAcceptance returns a value >= 8, then the cargo is accepted independent of the amount. For the production of houses there is no reliable method though. You can determine the number of houses in the catchment area using AITile::GetCargoProduction, but that does not tell you how much those houses produce. So you have to make some assumptions about the average house production using AITown::GetLastMonthProduction and AITown::GetHouseCount.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
CaesiumFarmer
Engineer
Engineer
Posts: 21
Joined: 25 Jun 2012 03:35

Re: Help with cargo supply values and payment

Post by CaesiumFarmer »

That makes sense now. The only way of telling roughly how much cargo you are going to receive at a station is by AIIndustry::GetLastMonthProduction? Does that work on houses as well? If not, how do you tell the number of passengers that are going to be at a station?
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Help with cargo supply values and payment

Post by Kogut »

For houses I use AITile.GetCargoAcceptance and assume that it is correlated with production.

AIIndustry::GetLastMonthProduction is defined as GetLastMonthProduction (IndustryID industry_id, CargoID cargo_id) - so there is absolutely no way to get any values related to towns.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
CaesiumFarmer
Engineer
Engineer
Posts: 21
Joined: 25 Jun 2012 03:35

Re: Help with cargo supply values and payment

Post by CaesiumFarmer »

Ok let me just ask the fundamental question I realize I have:
How do I have an AI determine the best place to build a bus station in or around a town to have the highest amount of passengers?

Would I use AITile::GetCargoProduction? That would only return the number of producers, not how much they are producing.

Edit: Thank you for responding I really do appreciate it. I suppose I didn't know exactly what I was looking for in the first place.
Also, may be this should have been posted in the AI section. A mod might want to move it there, I don't know.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 9 guests