jessefjxm

Untitled

May 15th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. -- /c remote.call("cargo-ship","placeDeepOil",event)
  2. local interface = {}
  3.  
  4. -- creat deep sea oil
  5. function interface.placeDeepOil(e)
  6. deep_tiles = game.surfaces[1].count_tiles_filtered{area=e.area, name = "deepwater"}
  7. math.randomseed(e.tick)
  8. if deep_tiles == 1024 then
  9.  
  10. freq = 0.03
  11. if settings.global["oil_frequency"].value == choices.oil_freq.none then
  12. freq = 0
  13. elseif settings.global["oil_frequency"].value == choices.oil_freq.v_low then
  14. freq = 0.0075
  15. elseif settings.global["oil_frequency"].value == choices.oil_freq.low then
  16. freq = 0.015
  17. elseif settings.global["oil_frequency"].value == choices.oil_freq.high then
  18. freq = 0.06
  19. elseif settings.global["oil_frequency"].value == choices.oil_freq.v_high then
  20. freq = 0.12
  21. end
  22. freq = freq * 1.25
  23. mult = 1
  24. if settings.global["oil_richness"].value == choices.oil_rich.v_poor then
  25. mult = 0.3
  26. elseif settings.global["oil_richness"].value == choices.oil_rich.poor then
  27. mult = 0.7
  28. elseif settings.global["oil_richness"].value == choices.oil_rich.good then
  29. mult = 1.8
  30. elseif settings.global["oil_richness"].value == choices.oil_rich.v_good then
  31. mult = 3
  32. end
  33.  
  34. r = math.random()
  35. if r < freq then
  36. -- create oil in inner part of tile to avoid deep oil too close to land
  37. local x = math.random(-10,10)
  38. local y = math.random(-10,10)
  39. local pos = {e.area.left_top.x+16+x, e.area.left_top.y+16+y}
  40. local a = (1+freq/(r+(freq/50)))*750000*mult
  41. game.surfaces[1].create_entity{name="deep_oil", amount=a, position=pos}
  42. end
  43. end
  44. end
  45.  
  46. function init()
  47. if global.or_power_generator == nil then
  48. global.or_power_generator = {}
  49. end
  50. end
  51.  
  52. script.on_init(function()
  53. init()
  54. end)
  55. script.on_configuration_changed(function(data)
  56. init()
  57. end)
  58.  
  59. function on_creation(event)
  60. local name = event.created_entity.name
  61. if name == "or_power" then
  62. table.insert(global.or_power_generator, event.created_entity)
  63. end
  64. end
  65.  
  66. script.on_event(defines.events.on_built_entity, on_creation)
  67. script.on_event(defines.events.on_robot_built_entity, on_creation)
  68.  
  69. function powerOilRig(e)
  70. if e.tick % 60 == 0 then
  71. for _, generator in pairs(global.or_power_generator) do
  72. generator.fluidbox[1] = {name="steam", amount = 100, temperature=165}
  73. end
  74. end
  75. end
  76.  
  77. remote.add_interface("cargo-ship", interface)
  78.  
  79.  
  80.  
  81.  
  82.  
  83. script.on_event("enter_ship", OnEnterShip)
  84. script.on_event(defines.events.on_entity_died, OnDeleted)
  85. script.on_event(defines.events.on_player_mined_entity, OnDeleted)
  86. script.on_event(defines.events.on_robot_mined_entity, OnDeleted)
  87. script.on_event(defines.events.on_chunk_generated, interface.placeDeepOil)
  88. script.on_event(defines.events.on_built_entity, spawnInvisibles)
  89. script.on_event(defines.events.on_tick, powerOilRig)
  90. -- long reach
  91. script.on_event(defines.events.on_runtime_mod_setting_changed, applyChanges)
  92. script.on_event(defines.events.on_player_cursor_stack_changed, increaseReach)
  93. script.on_event(defines.events.on_player_died, deadReach)
Advertisement
Add Comment
Please, Sign In to add comment