TownEffects

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
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

TownEffects

Post by fabca2 »

Hi,

I've a question, sorry if it look stupid, I could not get clear answer from wiki or GS api
What are TownEffects ?

I suppose it's the effect a given cargo provides to a town,
for example, Good cargo in temperate provides TE_PASSENGERS, TE_MAIL, TE_GOODS and TE_FOOD effects.
But what does it means : "goods provide Food effect to town" ?
What usage ottd can makes of that ? probably growing town ?
I don't see the internal behind : Good cargo provide 4 different effects here, do all these 4 effects behave the same ? maybe with a different rate ? if yes, can we know each rate ?

I'm a little bit in the dark with the concept of TownEffect, it would be helpfull if someone could explain,
Thank you.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: TownEffects

Post by krinn »

It help you determine what the cargo does :

If a newGRF provide a new cargo : says "Beef". What you're AI will do with "Beef" now ?

Beef with town effect as "TE_FOOD" will allow your AI to treat "Beef" as food. So your AI now knows town "can" accept it (so your AI will search a station in a town to drop beef".

As another example : providing "Football supporters" with effect "TE_PASSENGERS", you're AI can send them in town or platform, but if you want make a town grow, better gives them to a town and not to a platform.

It's good to note that until we have "TE_DUMB" you cannot see any "PSG Fooball supporters" cargo.

look at http://wiki.openttd.org/Towns#Climate-R ... own_Growth
edit: seeing frosch comment, i see i gave you AI pov, and you were seeking GS, sorry :(
Last edited by krinn on 12 Nov 2013 15:01, edited 1 time in total.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: TownEffects

Post by frosch »

For scripts the relevant functions which deal with town effects are:
  • GS/AITown::GetLastMonthReceived
  • GS/AITown::GetCargoGoal
  • GSTown::SetCargoCoal
So, they are *some* method for GameScripts to define growth conditions for towns using cargos, which NewGRF defined to be meaningful for town growth.
  • GameScripts can set growth conditions depending on the amount of TownEffect being delivered.
  • When not using GameScripts, the default arctic and tropic climate require food and water effects for growth.
  • NewGRF define which cargos supply a certain TownEffect, which can include an efficiency-factor. (n units of cargo A may supply more of a town effect than n units of a different cargo B)
All this stuff is somewhat tricky because it is influenced by both GameScripts and NewGRFs. Basically NewGRF define which cargos supply which town effects, that is also which town effects exist at all. GameScripts otoh then define what the TownEffects really do.

Sorry, if this is confusing you even more :)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Re: TownEffects

Post by fabca2 »

Thank you,
frosch wrote:Sorry, if this is confusing you even more :)
Let's check if I understood correctly, here are statments of what I understood. Please let me know if I'm wrong :

Statements :

S1: cargo can have zero to many town_effect.

S2: every cargo that can be delivered to a town have at least one town_effect.

S3: every cargo that have (at least one) town_effect can be delivered to a town.

S4: when a cargo is delivered to a town, the delivered quantity is splitted to each cargo town_effect

S5: town_effect is took into account for town growing process. For this, each town_effect have a factor. (F_TEpass, F_TEmail, F_TEgood,F_TEwater, F_TEfood)

S6: Factors and cargo acceptance can be changed by newGRF (like TTRS for example, that allow FOOD to be accepted by town)

S7: Cargo town_effect can be changed by newGRF (like FIRS for example, it changes GOOD town_effect to TE_Food and TE_Water only)

S8: in temperate (without any newGRF) town can only accept PASS, MAIL, GOOD and VALU cargo

S9: in temperate GOOD delivering does ont make town to grow. (I don't know for VALU)

S10: with statements S8+S9+S5 it imply that Factor F_TEgood=0 (in temperate mode, without any newGRF)


Now it brings to me one question :
Do we have an api (or another way) to get these in game towneffect factors ? (I mean the one modified by newGRF)
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: TownEffects

Post by planetmaker »

fabca2 wrote:Thank you,
frosch wrote:Sorry, if this is confusing you even more :)
Let's check if I understood correctly, here are statments of what I understood. Please let me know if I'm wrong :

Statements :

S1: cargo can have zero to many town_effect.

S2: every cargo that can be delivered to a town have at least one town_effect.

S3: every cargo that have (at least one) town_effect can be delivered to a town.

S4: when a cargo is delivered to a town, the delivered quantity is splitted to each cargo town_effect

S5: town_effect is took into account for town growing process. For this, each town_effect have a factor. (F_TEpass, F_TEmail, F_TEgood,F_TEwater, F_TEfood)

S6: Factors and cargo acceptance can be changed by newGRF (like TTRS for example, that allow FOOD to be accepted by town)

S7: Cargo town_effect can be changed by newGRF (like FIRS for example, it changes GOOD town_effect to TE_Food and TE_Water only)

S8: in temperate (without any newGRF) town can only accept PASS, MAIL, GOOD and VALU cargo

S9: in temperate GOOD delivering does ont make town to grow. (I don't know for VALU)

S10: with statements S8+S9+S5 it imply that Factor F_TEgood=0 (in temperate mode, without any newGRF)


Now it brings to me one question :
Do we have an api (or another way) to get these in game towneffect factors ? (I mean the one modified by newGRF)
A town is a rather abstract concept or a meta-object and cannot accept anything on its own. A town consists of houses and industries within its influence area. And it will note which cargos are accepted by each of the individual entities in its influence area. Each house and industry decides on its own what it accepts or not. And it will only report accepted quantities to the local authority (aka town) for statistics reasons.

S2 doesn't make sense as a town itself doesn't accept anything. A cargo can be accepted and have no effect other than giving you money. For instance coal.
S3 is undetermined. It requires a house or industry accepting the cargo which is not necessarily guaranteed
S8 doesn't make sense for the same reason as S2 but isn't wrong either. Those are the goods accepted by town houses and town industries (banks) in temperate climate w/o any NewGRFs.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: TownEffects

Post by frosch »

fabca2 wrote:S1: cargo can have zero to many town_effect.
A cargo can have zero or one town effect.
S2: every cargo that can be delivered to a town have at least one town_effect.
Cargos with and without town effect can be delivered to both industries or houses. There are no implications between any of these properties.
S3: every cargo that have (at least one) town_effect can be delivered to a town.
Delivering to a town means delivering to a house or a industry of that town. This is the case for all cargos.
S4: when a cargo is delivered to a town, the delivered quantity is splitted to each cargo town_effect
Yes. TownEffectAmount = sum_{cargo} EffectFactor_{cargo} * CargoAmount_{cargo}
S5: town_effect is took into account for town growing process. For this, each town_effect have a factor. (F_TEpass, F_TEmail, F_TEgood,F_TEwater, F_TEfood)
Usually the amount delivered does not affect the speed of growth. Only whether the town growth.
GameScripts may set certain monthly amounts as precondition for growth. For default climates without GameScript this amount is 1 per month.
S6: Factors and cargo acceptance can be changed by newGRF (like TTRS for example, that allow FOOD to be accepted by town)
Yes. But industry acceptance also counts.
S7: Cargo town_effect can be changed by newGRF (like FIRS for example, it changes GOOD town_effect to TE_Food and TE_Water only)
Yes.
S8: in temperate (without any newGRF) town can only accept PASS, MAIL, GOOD and VALU cargo
VALU has no town effect by default.
S9: in temperate GOOD delivering does ont make town to grow. (I don't know for VALU)
In temperate no cargos are required for town growth. Cargos have town effects, but the town effects have no effect on the town by default. These restrictions only exist in arctic above snowline, and in tropic desert, or when using a GameScript.
Do we have an api (or another way) to get these in game towneffect factors ? (I mean the one modified by newGRF)
  • AI/GSTownEffectList gives you a list of all potentially existing town effect (which is a superset of the town effects that actually exist).
  • AI/GSCargo::GetTownEffect tells you the town effect a cargo has, resp. whether it has any.
  • AI/GSTown::GetCargoGoal tells you how much of a certain town effect is required for growth.
  • There is currently no API to tell you how much town effect a certain cargo actually supplies. So, you only have a qualitative information, no quantity.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: TownEffects

Post by Zuu »

You can determine a list of all cargos X1..Xn that supply cargo effect Y. You can then use GSCargoMonitor to detect how much cargo supply there is for cargo X1..Xn if you for any reason need to detect the supply of cargo for some town effect. However, you still need to have your own idea on how much each town effect should affect the town.

Usually, if you only want "deliver at least Z of some cargo effect" to grow town, a GS will not need to track the delivery amounts. Only use the GS API to set the growth limits. However, if you want to implement stock piles etc. then you will need track delivery using GSCargoMonitor.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Re: TownEffects

Post by fabca2 »

Thank you,

That's incredible to see how far from reality I was !
It makes about 9 years I play ottd... and most of my statements were wrong !
I feel ashamed :oops:
frosch wrote:
fabca2 wrote:S1: cargo can have zero to many town_effect.
A cargo can have zero or one town effect.
That was one of the base of my mistake, thank you !
frosch wrote:Usually the amount delivered does not affect the speed of growth. Only whether the town growth.
GameScripts may set certain monthly amounts as precondition for growth. For default climates without GameScript this amount is 1 per month.
But when I play (temperate without any newgrf) I can see "town is growing every 15 days" and later "every 7 days" and then "every 5 days" while delivering more and more passengers. that's what I felt. that's what I called the speed of growth, it's maybe inappropriate.


planetmaker wrote:A town is a rather abstract concept or a meta-object and cannot accept anything on its own. A town consists of houses and industries within its influence area.
That's right, I was fooled by the name of the function I use to monitor cargo delivering :

Code: Select all

GSCargoMonitor.GetTownDeliveryAmount(company_id, cargo_id, town_id, true);
in fact, this returns the amount of cargo delivered to houses and industries within influence area of the town.


Zuu wrote:Only use the GS API to set the growth limits.
Yes, and I tried already to use Goals, which is very nice (because it take into account displaying of the goal progress in town windows), but it was for testing purpose.
In fact I want to handle myself (maybe stockpiling...), and then I use GSCargoMonitor. But I've doubt about how to correctly make town growing,
shall I use GSTown.SetGrowthRate or GSTown.ExpandTown ?
I started to use GSTown.SetGrowthRate with a number of days (for example 10), but then when I need to stop growing, I tried value 365 * 1000 as I could see in other scripts, but it remains "every 10 days" instead of "not growing".
Do you have a link that explain best practices for script-driven town growing ?

wow, I got 3 ottd dev replies in a raw !
by the way : thank you for what you do on that game !

edit : removed stupid question
Last edited by fabca2 on 14 Nov 2013 06:36, edited 1 time in total.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: TownEffects

Post by Zuu »

365 * 1000 = 365 000, which overflows the maximum. In the API docs there is now a documented max value of 30 000 days.

If you got the 365 000 value from Neighbours are important, that is an error in my script that frosch noticed and will be corrected in its next release.


If you want to support both 1.3 and trunk, use 30 000 days as 'infinity', that is 8 years. Or, if you only care about trunk, use the new special value for infinity GSTown.TOWN_GROWTH_NONE. Or use TOWN_GROWTH_NONE when available:

Code: Select all

local infinity = "TOWN_GROWTH_NONE" in GSTown ? GSTown.TOWN_GROWTH_NONE : 30000;
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Re: TownEffects

Post by fabca2 »

you rocks !
thanks.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 19 guests