The International Simutrans Forum

 

Author Topic: Is the factory energized?  (Read 1169 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1822
    • Simutrans-BLOG
  • Languages: ES
Is the factory energized?
« on: September 19, 2019, 03:15:55 AM »

Hello how are you ?.

I have been working on a new chapter concerning the electrification of factories.

I would like a new function that allows me to know if the factory is being energized.

Example: factory_x.is_energized()

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4944
  • Languages: EN, DE, AT
Re: Is the factory energized?
« Reply #1 on: September 20, 2019, 02:18:37 PM »
the best would be to check factory method get_pwer() to check whether something was consumed in the current and last months

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1822
    • Simutrans-BLOG
  • Languages: ES
Re: Is the factory energized?
« Reply #2 on: September 20, 2019, 02:38:28 PM »
the best would be to check factory method get_pwer() to check whether something was consumed in the current and last months
It looks fine.

But there is still a small problem that I still cannot solve, I need to know if the transformer of a factory is connected to the power plant (if there is electricity).

Is that possible?.
 

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4944
  • Languages: EN, DE, AT
Re: Is the factory energized?
« Reply #3 on: September 20, 2019, 08:46:47 PM »
This is not possible currenly

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1822
    • Simutrans-BLOG
  • Languages: ES
Re: Is the factory energized?
« Reply #4 on: September 20, 2019, 09:49:53 PM »
Apparently there is an error when the energy values of the current month are obtained, by some they return to "0" before the month ends.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4944
  • Languages: EN, DE, AT
Re: Is the factory energized?
« Reply #5 on: September 21, 2019, 08:39:31 AM »
the entry
  • is the current power supply/production. Entries with higher index are the sums of production / demand of previous months

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1822
    • Simutrans-BLOG
  • Languages: ES
Re: Is the factory energized?
« Reply #6 on: September 22, 2019, 01:41:14 PM »
the entry
  • is the current power supply/production. Entries with higher index are the sums of production / demand of previous months
I understand that the index "0" corresponds to the current month, the problem I see is that the value returns to "0" for some reason.

Look at this:
Code: [Select]
                    local f_list = [coord(36, 4), coord(95, 39), coord(76, 26)]
                    f_power = 0
                    for(local j=0;j<f_list.len();j++){
                        local tile = square_x(f_list[j].x, f_list[j].y).get_ground_tile()
                        local factory = tile.find_object(mo_building).get_factory()
                        if (factory){
                            local power = factory.get_power()[0]
                            f_power += power

                        }
                    }
                    gui.add_message(""+f_power+"")