Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not self.source_entity or not self.source_entity.valid then
- control = self.counter.get_or_create_control_behavior()
- control.set_signal(1, {signal = _CONFIG._SIGNAL_TRAIN_COUNT, count = -1})
- control.set_signal(2, {signal = _CONFIG._SIGNAL_TRAIN_STOPPED, count = -1})
- control.set_signal(3, {signal = _CONFIG._SIGNAL_TRAIN_NEXTSTOP, count = -1})
- goto done
- end
- count = #self.source_entity.get_train_stop_trains()
- stopped_count = 0
- nextstop_count = 0
- control = self.counter.get_or_create_control_behavior()
- if control then
- control.set_signal(1, {signal = _CONFIG._SIGNAL_TRAIN_COUNT, count = count})
- -- look though each train that the combinator is linked too
- for _, train in ipairs(self.source_entity.get_train_stop_trains()) do
- -- If a train is stopped at a station add to the counter if its a station we care about.
- if train.station ~= nil then
- if self.source_entity.backer_name == train.station.backer_name then stopped_count = stopped_count + 1 end
- util.print(train.station.backer_name .. "\n")
- end
- -- if a train has a schedule and the next stop is the target station we will increase the counter
- if train.schedule and #train.schedule.records > 0 then
- current = train.schedule.current
- next_station = train.schedule.records[current].station
- if train.station == nil and next_station == self.source_entity.backer_name then nextstop_count = nextstop_count + 1 end
- end
- end
- control.set_signal(2, {signal = _CONFIG._SIGNAL_TRAIN_STOPPED, count = stopped_count})
- control.set_signal(3, {signal = _CONFIG._SIGNAL_TRAIN_NEXTSTOP, count = nextstop_count})
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement