What are the possibilities of game scripts

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
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13235
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

What are the possibilities of game scripts

Post by Hyronymus »

After a few PM's with FooBar he came up with the idea to ask some stuff about script possibilities in public.

I was thinking about scripted events such as:
- offering of rare subtypes of vehicles if you have a set amount of that vehicle type active
- lower running costs if you have a set amount of vehicles from one type active
- higher revenue for vehicles if you have a set amount of vehicles from one type active
- subsidy offers to be achieved by a certain vehicle type
- reality-based news items
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: What are the possibilities of game scripts

Post by krinn »

You are limited by openttd, limited by the AI API (even if the GS API might allow a bit more, you'll be tied to that anyway), and limit to not cheat (one cheat exist already)
So, except the new items, all others choices from your list aren't doable.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: What are the possibilities of game scripts

Post by planetmaker »

krinn wrote:You are limited by openttd, limited by the AI API (even if the GS API might allow a bit more, you'll be tied to that anyway), and limit to not cheat (one cheat exist already)
So, except the new items, all others choices from your list aren't doable.
Game scripts and AI share a lot of the API, but they are different in what is accessible to them. Game scripts can act as COMPANY_DEITY, thus they *can* change things a company (human or AI) could not change ever (like towns growing or not growing).
You find the API documentation for GS here: http://nogo.openttd.org/api/trunk/

A lot more things are thinkable as of what game scripts could be given access to (they can react on subsidies and create news items so far).

Wrt vehicles being offered conditionally is something entirely new and GS cannot change availability of vehicles at all. That's at least a thorny and stony path to go as it basically means to break NewGRFs to some degree. It might possibly be part of NewGRFs domain rather (it's hard to define clear boundaries between GS and NewGRFs)
donchatryit
Transport Coordinator
Transport Coordinator
Posts: 259
Joined: 16 Mar 2009 21:00

Re: What are the possibilities of game scripts

Post by donchatryit »

I do like the idea of running costs being reduced once you have a number of the same vehicle types. Is this something that existing newGRFs could incorporate (after all, 2cc, I think, already reduced the running costs for some engines when you have them on double-headed trains)?
User avatar
SquireJames
Tycoon
Tycoon
Posts: 1863
Joined: 07 Aug 2004 11:56
Skype: squirejames5
Location: Stoke-on-Trent
Contact:

Re: What are the possibilities of game scripts

Post by SquireJames »

Digging up a slightly old post here, but I see that you have said that news items are doable?

Making a HUUUGE assumption here, but I am gathering the code is rather simple for such items, in psuedocode basically being "If date = 01-09-1939 then display news item 'War Declared!' " I will happily volunteer to make such a script, it's something i've been after for a while (I loved the real world items in Railroad Tycoon for example).

Beyond that, is it possible to trigger certain economic events with script also? What I am thinking is, as you might have gathered with the above example, is that during the First and Second World War, massively increase production, demand and payment for coal, iron, oil, steel etc, and have passenger income reduce. I know that even the original TTO had "Recession" events where payments dropped, but I am not sure if the scripting allows such precise managements of cargo as I am suggesting. I also imagine that i'd have to tailor the script to any industry set I was using. For example, I use FIRS, so I'd need to make a FIRS specific version which referred to FIRS cargos rather than vanilla.

Anyway, I'll have a search for a scripting tutorial and give it a go. Is it anything like LUA script? I use that a lot in other games I mod.
Image
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4765
Joined: 09 Sep 2007 05:03
Location: home

Re: What are the possibilities of game scripts

Post by Alberth »

People are just beginning to investigate how to use game scripts for games. News items is definitely possible, the other stuff may be more difficult.
While I don't like war as reason ("Upcoming super power Hawaii needs resources" would do just as well imho), I think the sort of things you want should be possible in some way.
If it is not currently, perhaps we should consider how to extend the scripting capabilities.

It is just a bit tricky, the system should function well both with and without game script, so it should be carefully considered what knobs the system should have, and who controls their settings.
Last but not least, imho it would be useful if your script is also useful for other industry sets. Again, nobody knows how feasible it is, it needs experimentation.
User avatar
SquireJames
Tycoon
Tycoon
Posts: 1863
Joined: 07 Aug 2004 11:56
Skype: squirejames5
Location: Stoke-on-Trent
Contact:

Re: What are the possibilities of game scripts

Post by SquireJames »

I know there has been a lot of discussion about war-related items in OTTD and the pros and cons to this. The good thing about a game script is that it's not forced on anyone. If you want historical news items, along with the economic factors (war, recession, rise and fall of personal transport) then you can download and install the script. If not, you don't have to. :) As mentioned I could make several versions, including one that omitted anything war-related.

I downloaded the tutorial script and examined how it was structured etc. So far I only foresee two issues with news items. First is that I can't find any code that brings up a news window (the tutorial uses messages windows, similar to the "we designed a new vehicle" windows). The second is that the AIDate callbacks seem to use relative dates rather than fixed dates. So, if you started on January 1st 1900, that would be day 1. If you started on January 1st 1950, that would also be day 1. There may be a different variable that calls the exact calendar date, much like how vehicles in GRFs do, but I've yet to find it. I am sure that the code is there though, I am just scratching the surface :)
Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: What are the possibilities of game scripts

Post by Zuu »

SquireJames wrote:I downloaded the tutorial script and examined how it was structured etc. So far I only foresee two issues with news items. First is that I can't find any code that brings up a news window (the tutorial uses messages windows, similar to the "we designed a new vehicle" windows).
Yes, the tutorial doesn't use the news popup. If you want to check a GS that does that, you could read the Split GS, TransportGoals, etc. Actually, most GS except the Tutorial use the news popup for at least one message.

You may also want to check the API docs for creating news:
http://nogo.openttd.org/api/1.2.1/classGSNews.html
SquireJames wrote:The second is that the AIDate callbacks seem to use relative dates rather than fixed dates. So, if you started on January 1st 1900, that would be day 1. If you started on January 1st 1950, that would also be day 1. There may be a different variable that calls the exact calendar date, much like how vehicles in GRFs do, but I've yet to find it. I am sure that the code is there though, I am just scratching the surface :)
Did you check the API docs?
http://nogo.openttd.org/api/1.2.1/classGSDate.html

GSDate::GetYear(GSDate::GetCurrentDate()) should give you the current year.

Is this the function that you tried to use?



Last, you may want to check some other Game Scripts for inspiration. The tutorial code is heavily engineered towards a linear step-by-step tutorial. Most other game scripts would probably not benefit from the structure used there.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
SquireJames
Tycoon
Tycoon
Posts: 1863
Joined: 07 Aug 2004 11:56
Skype: squirejames5
Location: Stoke-on-Trent
Contact:

Re: What are the possibilities of game scripts

Post by SquireJames »

I did check the API documentation, I didn't see anything related to dates. That code certainly seems to be the thing though :)

I'll download the split GS and find the code that brings up a news story. I am hoping this should be a fairly easy game script to code, as it's essentially just a huge series of linear checks that only hit once. I can start trying to add economic effects to these events later.
Image
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 24 guests