[help] How to create global goal ?

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
hpfx
Engineer
Engineer
Posts: 43
Joined: 09 Nov 2013 00:19

[help] How to create global goal ?

Post by hpfx »

Hello,

I try to create a global goal, I start with API documentation http://nogo.openttd.org/api/1.4.0/class ... 0645b67467

Code: Select all

GSGoal.New(company, goal, type, destination)
But this is not enough to help me.
I can read that I must use GSCompany::COMPANY_INVALID as company, ok.
I'm not sure which GoalType I must use for "global goal", I pick GT_NONE.
but what is destination ? it's not clearly explained. I guess destination is a town when GoalType is GT_TOWN (same with industry) but other case ? I guess I must leave it zero... it's not explained.

Here is what I tried :

Code: Select all

GSGoal.New(GSCompany.COMPANY_INVALID,GSText.STR_GOAL1,GSGoal.GT_NONE, 0);

it does not gives any error, but I cannot see any goal.
I tried also this one :

Code: Select all

GSGoal.New(GSCompany.COMPANY_INVALID,GSText.STR_GOAL1,GSGoal.GT_COMPANY, 0);
still no goal...

I searched for "GSGoal.New" on wiki and in this forum, without any success... I'm wondering how you create goals ? are API texts enough for you ? please tell me what's wrong ?


Also this sentence makes me troubles :
Global goals can only reference global story pages

I guess story page are a part of story book.
But I don't want to have story book at all,
I played multiplayer games which had global goal without storybook. (I don't know the name of the script btw)
Then I think it's only relevant for GT_STORY_PAGE type, which is not what I want.

sorry, I feel too dummy.
than kyou for your help.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: [help] How to create global goal ?

Post by frosch »

Try

Code: Select all

GSGoal.New(GSCompany.COMPANY_INVALID, GSText(GSText.STR_GOAL1), GSGoal.GT_NONE, 0);
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
hpfx
Engineer
Engineer
Posts: 43
Joined: 09 Nov 2013 00:19

Re: [help] How to create global goal ?

Post by hpfx »

frosch wrote:Try

Code: Select all

GSGoal.New(GSCompany.COMPANY_INVALID, GSText(GSText.STR_GOAL1), GSGoal.GT_NONE, 0);
Well, now I feel dummy... it was so simple :)

thank you frosch.

but I have a question : is destination only used for GT_TILE, GT_INDUSTRY and GT_TOWN ?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [help] How to create global goal ?

Post by Zuu »

Destination is used by all types except for DT_NONE.

For the story page type, destination is the page id of a story book page. If you create a global goal it cannot reference company specific pages. Only global ones.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
hpfx
Engineer
Engineer
Posts: 43
Joined: 09 Nov 2013 00:19

Re: [help] How to create global goal ?

Post by hpfx »

thank you,

One more question about goals,
I used to return "1.3" in GetAPIVersion(), because my GS is supposed to be compatible with version 1.3 and 1.4

Code: Select all

class FMainClass extends GSInfo {
	function GetAPIVersion()	{ return "1.3"; }
...
}
And when I want to mark the goal as completed, I used this kind of code :

Code: Select all

if(isVersion14ormore()) // only for ottd 1.4+
{
 GSGoal.SetProgress(goalId,"OK");
 GSGoal.SetCompleted(goalId,true); // do nothing ?
}
But because GetAPIVersion() is returning "1.3", both SetProgress() and SetCompleted() were not proceed. (even if isVersion14ormore() returned true on ottd version 1.4)
Then I had to return "1.4" to make it work...

But then, obviously, only by returning "1.4" my script is no more available on ottd 1.3 (I cannot find it anymore on scripts selection)

Is it possible to have the script running on both version, but with progress function to work on 1.4 only ?

Last question : when I use GSGoal.SetCompleted(), nothing changes, don't you visually see the goal is completed ?
Thank you.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [help] How to create global goal ?

Post by Zuu »

Completed goals get a green colour in the progress column and a different icon when referenced from the story book.

In general it is possible to use newer APIs even if you return an older API version with the issue that you yourself have to safe guard or provide code for compatibility with more APIs. However this is not a promise from OpenTTD as far as I understand but more a side effect of how backwards compatibility is implemented. I do however not see (without inspecting code) see why it would fail in your case.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: [help] How to create global goal ?

Post by krinn »

hpfx wrote: But because GetAPIVersion() is returning "1.3", both SetProgress() and SetCompleted() were not proceed. (even if isVersion14ormore() returned true on ottd version 1.4)
Then I had to return "1.4" to make it work...

But then, obviously, only by returning "1.4" my script is no more available on ottd 1.3 (I cannot find it anymore on scripts selection)

Is it possible to have the script running on both version, but with progress function to work on 1.4 only ?
Easy to do, first set GetAPIVersion to return 1.3, as 1.3 or 1.4 will see it, else only 1.4 will see it.
Next to that, don't use GetAPIVersion for your checking, just build your own version check.

Code: Select all

function isVersion14ormore () { return ("SetProgress" in GSGoal); }
hpfx
Engineer
Engineer
Posts: 43
Joined: 09 Nov 2013 00:19

Re: [help] How to create global goal ?

Post by hpfx »

thank you very much,
you rocks, guys !
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 6 guests