Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. if not self.source_entity or not self.source_entity.valid then
  2. control = self.counter.get_or_create_control_behavior()
  3. control.set_signal(1, {signal = _CONFIG._SIGNAL_TRAIN_COUNT, count = -1})
  4. control.set_signal(2, {signal = _CONFIG._SIGNAL_TRAIN_STOPPED, count = -1})
  5. control.set_signal(3, {signal = _CONFIG._SIGNAL_TRAIN_NEXTSTOP, count = -1})
  6. goto done
  7. end
  8.  
  9. count = #self.source_entity.get_train_stop_trains()
  10. stopped_count = 0
  11. nextstop_count = 0
  12.  
  13. control = self.counter.get_or_create_control_behavior()
  14. if control then
  15. control.set_signal(1, {signal = _CONFIG._SIGNAL_TRAIN_COUNT, count = count})
  16.  
  17. -- look though each train that the combinator is linked too
  18. for _, train in ipairs(self.source_entity.get_train_stop_trains()) do
  19.  
  20. -- If a train is stopped at a station add to the counter if its a station we care about.
  21. if train.station ~= nil then
  22. if self.source_entity.backer_name == train.station.backer_name then stopped_count = stopped_count + 1 end
  23. util.print(train.station.backer_name .. "\n")
  24. end
  25.  
  26. -- if a train has a schedule and the next stop is the target station we will increase the counter
  27. if train.schedule and #train.schedule.records > 0 then
  28. current = train.schedule.current
  29. next_station = train.schedule.records[current].station
  30. if train.station == nil and next_station == self.source_entity.backer_name then nextstop_count = nextstop_count + 1 end
  31. end
  32. end
  33.  
  34. control.set_signal(2, {signal = _CONFIG._SIGNAL_TRAIN_STOPPED, count = stopped_count})
  35. control.set_signal(3, {signal = _CONFIG._SIGNAL_TRAIN_NEXTSTOP, count = nextstop_count})
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement