The International Simutrans Forum

 

Author Topic: Factory connected with  (Read 325 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1448
    • Simutrans-BLOG
  • Languages: ES
Factory connected with
« 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:

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9992
  • Languages: De,EN,JP
Re: Factory connected with
« Reply #1 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.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4702
  • Languages: EN, DE, AT
Re: Factory connected with
« Reply #2 on: June 25, 2020, 10:29:16 AM »
tool_link_factory is there. Did you test your script?

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1448
    • Simutrans-BLOG
  • Languages: ES
Re: Factory connected with
« Reply #3 on: June 25, 2020, 11:43:23 AM »
tool_link_factory is there. Did you test your script?
Maybe i'm doing something wrong  ???

Code: [Select]
    local tool = command_x(tool_link_factory)
    tool.set_flags(2)           
    local err = tool.work(player_x(1), tile, tile_fact, "")

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4702
  • Languages: EN, DE, AT
Re: Factory connected with
« Reply #4 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.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1448
    • Simutrans-BLOG
  • Languages: ES
Re: Factory connected with
« Reply #5 on: June 26, 2020, 02:02:29 AM »
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.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4702
  • Languages: EN, DE, AT
Re: Factory connected with
« Reply #6 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.