Company's Trading Post and Disaster spawn via GScript - is that viable ?

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
tyrins
Engineer
Engineer
Posts: 4
Joined: 08 May 2020 09:43

Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by tyrins »

Hi , I'm new here, I'm searched the forum for related answers but found none, so I made this thread.

Currently I'm modding a GameScript ( New Village Growth script ) in order to make an yet-another city builder script and some what achieved the desired effect along with FIRs Extreme set.

What I'm trying to do is to make a trading-post for each company (I 'm playing the game with my friends online), in which it would store the exceeding goods when stockpile reached its limit. Other player could then transport those goods for a fee for each ton of goods they bring back to their city and that fee is added to owner city's company balance.

Question here is : can I spawn Cargo of a given Id for a known amount ? Like, is there such a function -> GSStation.Spawn/Set/Add (StationId, CargoId, Amount ) available somewhere ?

And - I wondering if it would be possible to add customized options to the "Local Authority Actions" via a GameScript for each town like -> clicking Local Authority , Select "Steal Food from this town" - spending some in-game money for a chance to steal 30% stockpiled food of that town and transfer that to the action's owner town ?

Although above thing seems impossible without modding the game code, I really hope someone would shed me some light !

Thanks for reading :)

P.S : About the disaster - is there a way to add an action that spending in-game money to call Military's Airforce to bomb a UFO at a selected location ? - Thanks ^^
User avatar
jfs
Tycoon
Tycoon
Posts: 1249
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by jfs »

Unfortunately, none of your wishes exist right now. At least some of them should be possible to implement.

I'm not sure if custom local authority actions are entirely realistic to add, I think they'd have a lot of hidden complexity.
However I have been working on a feature for push-buttons for the Storybook: https://github.com/OpenTTD/OpenTTD/pull/7896
Those would let you have the player initiate actions in a relatively intuitive way. (Use a "select tile" type button and have the player click a tile belonging to the town they want to interact with.)

GS-spawned cargo could be interesting also for other purposes, for example "priority cargo" that needs to be delivered somewhere particular. It would probably need to be paired with some special cargo monitoring functions, and a way to delete cargo in transit if it "expires" for whatever reason.

GS-controlled disaster vehicles could also be interesting. I remember investigating it a bit some time ago. Right now disaster vehicles don't have a particular destination in mind when they spawn, they can end up just crossing over the map and not do anything, but it would probably be possible to give them a destination. It might even be possible to give them an orders list, so you could have a UFO follow a specific path or such. It will probably also be relatively involved to implement.
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by Korenn »

GameScript controlled cargo spawning could result in all sorts of interesting game-changing ideas.
tyrins
Engineer
Engineer
Posts: 4
Joined: 08 May 2020 09:43

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by tyrins »

Thanks for the quick reply @jfs and @Korenn :D ,

Those buttons on story book looks promising I must say !

So basically I could make a button to found a city's "Trading Post" - an Oil Rig at a selected tile, given the button could trigger an event in which GS could catch it and spawning cargoes (if available). I've just checked that the GSIndustry class has the function to get the last month transported cargo, so I could calculate the "income" for "owner" player of that "Trading Post" for each type of cargo transported.

Another button for Stealing something from opponent's town is also possible if the initiator player_id and town_id (via-tile nearest town) could be catch via event. Still haven't try so I wonder if could the button fire any arbitrary event with arbitrary data, or in-disguise of some known event with defined data.

And even some "Bomb this area" button could be done if GSTile.BombThisTile() is avail ^^~ I think if target tile could be sent to GS, then that could be done via GSTile.DemolishTile, but since no demolish animation is made, kinda weird for another player's perspective when suddenly seeing things vanished.. a magazine post with title like "Mystery Blackhole effect : Town X has its infrastructure banished into the Void" would made up for it I guess ....

I would take an in-depth dive in to the fork the next Monday and inform you back, happy weekend ! :)
agentw4b
Traffic Manager
Traffic Manager
Posts: 180
Joined: 14 Apr 2017 15:51
Location: Czech Republic

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by agentw4b »

jfs wrote: 08 May 2020 14:06
However I have been working on a feature for push-buttons for the Storybook: https://github.com/OpenTTD/OpenTTD/pull/7896
Those would let you have the player initiate actions in a relatively intuitive way. (Use a "select tile" type button and have the player click a tile belonging to the town they want to interact with.)

Is it likely that this modification of StoryBook will be included in the regular game? It would be very useful for me, I have been thinking for a long time about gamescript, where players could influence some settings of the game itself, for example by voting. However, this is prevented by the limited functionality of the buttons.
Owner and admin of servers:Experimental games 01 (92.63.57.152:3979), Experimental games 02 (92.63.57.152:3879), Experimental games 03 (92.63.57.152:3779), Experimental games 04 (92.63.57.152:3679), Experimental games 05 (92.63.57.152:3579).
My heightmaps: Flat Earth Map and United nations logo
My scenarios: Game Fallout 1,2,3 Map scenario
My gamescripts: City Founder GS
User avatar
jfs
Tycoon
Tycoon
Posts: 1249
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by jfs »

agentw4b wrote: 11 May 2020 13:56 Is it likely that this modification of StoryBook will be included in the regular game? It would be very useful for me, I have been thinking for a long time about gamescript, where players could influence some settings of the game itself, for example by voting. However, this is prevented by the limited functionality of the buttons.
Yes that's the intention. I'm just waiting for someone to do a code review and approve it. It will probably be in version 1.11 or whatever the next "major" version is numbered.
(I also need to do a bit of clean up in the commit history. Maybe I should do that.)
tyrins
Engineer
Engineer
Posts: 4
Joined: 08 May 2020 09:43

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by tyrins »

:D hi there, been weeks since last post but today I've dive in and made some progress, made some button and captured the event fired after selected a tile. Great work @nielsmh !!

Still wanted below things :roll: :

- Could some API document be made for the usage of the script API ? Right now I have to try-and-true with given source code and thanks god thing just works out-of-box :wink:
- The color of the buttons, currently is it defined by setting the refid when create the new story page element ? Or is there a way to set color for the button background manually ?

Ok so back to the main topic :
- I'm planning to make a "Resource Silo" or "City warehouse" to enable trading/stealing/sabotaging actions in story page. Like make a new industry called "City Warehouse" with that Water Tower sprite and the characteristic of an oil rig ( actually just the "tradable part"). I saw that was half-achieved in FIRs Industry set where they made city grocery store/hardware store with on-sea "Fish" industry (alter-the-oil-rig)...

So, I guess what should I must do next to achieve above things I asked is :
- Alter the FIRs newGRF, or making a new one - adding that new industry "Resource Silo".
- Fork @nielsmh branch so that a GSStation.SetCargo(station_id, cargo_id, cargo_amount) would be available.
- And due to the fact that modifying the OpenTTD
code base, make a feature for that "Resource Silo" that any company other than the owner, pay for the goods when picking them up ( and ideally no income for transporting cargoes from silos ).

Is that the right way ? Especially the newGRF part ?

P.S : Btw, I've made change to the GRVTS 1.4 32bpp newGRF by Zephyris to support Alcohol transport (trucks to refittable into Alcohol), if any one need that, please do tell I'll upload in the next post.

Thanks for your patient reading and regards :D
Attachments
Screen Shot 2020-05-21 at 10.01.50.png
Story_Page Screenshot
(915.08 KiB) Not downloaded yet
User avatar
jfs
Tycoon
Tycoon
Posts: 1249
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by jfs »

Yes you use the "reference" for the button element to set the background colour, and other possible flags. I did it this way since I didn't want to make several additional NewElement and UpdateElement functions. Instead there's the MakeXxxButtonReference functions to pack the "reference" value correctly.

Here's my own test script making buttons:

Code: Select all

	this._pageid = GSStoryPage.New(GSCompany.COMPANY_INVALID, "Hello");

	GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_TEXT, 0, "Some initial text.")

	this._button1 = GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_BUTTON_PUSH, GSStoryPage.MakePushButtonReference(GSStoryPage.SPBC_BROWN, GSStoryPage.SPBF_FLOAT_LEFT), "Push button!");
	GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_TEXT, 0, "Some more text, which is much longer and will most certainly wrap onto multiple lines, to demonstrate how the floating buttons feature works.");

	this._button2 = GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_BUTTON_TILE, GSStoryPage.MakeTileButtonReference(GSStoryPage.SPBC_PURPLE, GSStoryPage.SPBF_FLOAT_RIGHT, GSStoryPage.SPBC_TOWN), "Find a tile");
	GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_TEXT, 0, "Even more text.");

	this._button3 = GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_BUTTON_VEHICLE, GSStoryPage.MakeVehicleButtonReference(GSStoryPage.SPBC_GREEN, GSStoryPage.SPBF_NONE, GSStoryPage.SPBC_PICKSTATION, GSVehicle.VT_WATER), "Find a vehicle");
	GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_TEXT, 0, "Even better text.");

	GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_BUTTON_PUSH, GSStoryPage.MakePushButtonReference(GSStoryPage.SPBC_BROWN, GSStoryPage.SPBF_FLOAT_LEFT), "Another left button");
	GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_BUTTON_PUSH, GSStoryPage.MakePushButtonReference(GSStoryPage.SPBC_ORANGE, GSStoryPage.SPBF_FLOAT_LEFT), "Yet another");
	GSStoryPage.NewElement(this._pageid, GSStoryPage.SPET_BUTTON_PUSH, GSStoryPage.MakePushButtonReference(GSStoryPage.SPBC_BLUE, GSStoryPage.SPBF_NONE), "This one is in the main part");

	GSStoryPage.Show(this._pageid);

The neutral stations on oil rigs are probably not entirely usable for what you want to do, since they are specially coded to always be a water tile, and only able to support ships and VTOL aircraft. Having neutral stations that can support other vehicle types would be a massive change, and you should probably look into the existing infrastructure sharing patches for that. Alternatively, don't depend on neutral stations but do something else.
User avatar
jfs
Tycoon
Tycoon
Posts: 1249
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by jfs »

The storybook buttons feature has been merged now, so it should be in the next nightly build :) The documentation for it should also appear on https://docs.openttd.org/gs-api/ together with the nightly build.
tyrins
Engineer
Engineer
Posts: 4
Joined: 08 May 2020 09:43

Re: Company's Trading Post and Disaster spawn via GScript - is that viable ?

Post by tyrins »

Really :D, congrats on the merging, it has been months since you marked the branch if I'm not mistaken.

Current status :
I'm trying to make the first button : Demolish 11x11 tile button to work.

Calling the GSTile.DemolishTile(X,Y), despite noted in the document that it would "destroy any thing on the given tile", would not destroy stations, industries whereas trees, city building etc could be destroyed.

I reverse checking the *_cmd.cpp file to find out which function does really call the 'magic bulldozer' function, still diving.

The station's cargo's check amount is reading the value through masking cargo bits, a bit complicated so I guess I would try to do that after the magic bulldozer thing work.

Would inform back if anything made progress, but it would take some time I guess.

Cheers :D
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests