The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on June 24, 2020, 06:24:05 PM

Title: Factory connected with
Post by: Yona-TYT on June 24, 2020, 06:24:05 PM

Hello how are you ?.

I am experimenting with a script that will display a list of the "providers" and "consumers" of the factories with a "script link" that allows "Delete" or "Add" a connection to another factory.

I need to use the tool "tool_link_factory", is this implemented?

I enclose my experiment:
Title: Re: Factory connected with
Post by: prissi on June 25, 2020, 12:08:35 AM
Since it is a clickable tool in menucof.tab there is already a tool. I think a script can call any tool for which a menu entry exists.
Title: Re: Factory connected with
Post by: Dwachs on June 25, 2020, 10:29:16 AM
tool_link_factory is there. Did you test your script?
Title: Re: Factory connected with
Post by: Yona-TYT on June 25, 2020, 11:43:23 AM
Quote from: Dwachs on June 25, 2020, 10:29:16 AMtool_link_factory is there. Did you test your script?
Maybe i'm doing something wrong  ???

    local tool = command_x(tool_link_factory)
    tool.set_flags(2)           
    local err = tool.work(player_x(1), tile, tile_fact, "")

Title: Re: Factory connected with
Post by: Dwachs on June 25, 2020, 04:49:33 PM
There was indeed a bug, affecting scripted calls to this tool (and the stop mover tool). Please test again with r9154.
Title: Re: Factory connected with
Post by: Yona-TYT on June 26, 2020, 02:02:29 AM
Quote from: Dwachs on June 25, 2020, 04:49:33 PM
There was indeed a bug, affecting scripted calls to this tool (and the stop mover tool). Please test again with r9154.
I think it works!

Now for the list, I am going to need a function that tells me if the factory is contracted with another factory and if the factory is associable with another factory.

Example:
factory_x().is_connected_with(factory_x()) and factory_x()is_connectable_with(factory_x())

This will allow me to display a list of possible suppliers or consumers that can be connected to the selected factory.
Title: Re: Factory connected with
Post by: Dwachs on June 26, 2020, 05:13:26 AM
For the first, you can iterate through get_consumer and get_supplier. For the second, there is no function like this. You have to iterate through the list of all factories and search for matching input and output goods.