local crash_site = require("crash-site") -- Transition from Lignumis to Nauvis with the provisional rocket silo local ToNauvis = { events = {} } -- Chart the starting area for the player local function chart_starting_area(surface, player) local r = 200 local force = player.force local origin = force.get_spawn_position(surface) force.chart(surface, { { origin.x - r, origin.y - r }, { origin.x + r, origin.y + r } }) end -- Initialize Nauvis local function init_nauvis() if storage.nauvis_visited then return end local nauvis = game.planets[storage.target_planet].create_surface() nauvis.request_to_generate_chunks({ 0, 0 }, 3) nauvis.force_generate_chunk_requests() nauvis.daytime = 0.7 end -- Teleport player to Nauvis and show welcome message local function teleport_player(player) local nauvis = game.planets[storage.target_planet].surface if player.surface.name == "lignumis" then local position = nauvis.find_non_colliding_position("character", { 2, 2 }, 100, 1) or { 0, 0 } player.teleport(position, storage.target_planet) chart_starting_area(nauvis, player) end end -- Initialize the Nauvis freeplay scenario local function init_freeplay() if storage.crashed_ship_nauvis then return end if not remote.interfaces.freeplay then return end storage.crashed_ship_nauvis = true local nauvis = game.planets[storage.target_planet].surface local ship_items = { ["burner-mining-drill"] = 2, ["stone-furnace"] = 2, ["burner-assembling-machine"] = 2, ["burner-agricultural-tower"] = 2, ["wood-lab"] = 2 } local debris_items = { ["wood-darts-magazine"] = 20, ["wood"] = 20, ["lumber"] = 20 } local crashed_ship_parts = remote.call("freeplay", "get_ship_parts") crash_site.create_crash_site(nauvis, { -5, -6 }, ship_items, debris_items, table.deepcopy(crashed_ship_parts)) end local function transit_player(player_index) local player = game.get_player(player_index) local transition = storage.transitions[player_index] if transition.rocket_entry.cargo_pod then transition.rocket_entry.cargo_pod.set_passenger(nil) transition.rocket_entry.cargo_pod.destroy() end init_nauvis() teleport_player(player) init_freeplay() -- Give the player the content of the rocket if transition.rocket_entry.rocket_content then local inventory = player.get_main_inventory() for _, item in pairs(transition.rocket_entry.rocket_content) do inventory.insert(item) end inventory.sort_and_merge() end table.remove(storage.rocket_silos, transition.rocket_entry_index) end local function explode_silo(silo) silo.die() end local get_random_position = function(box, x_scale, y_scale) x_scale = x_scale or 1 y_scale = y_scale or 1 local x1 = box.left_top.x local y1 = box.left_top.y local x2 = box.right_bottom.x local y2 = box.right_bottom.y local x = ((x2 - x1) * x_scale * (math.random() - 0.5)) + ((x1 + x2) / 2) local y = ((y2 - y1) * y_scale * (math.random() - 0.5)) + ((y1 + y2) / 2) return { x, y } end local function burn_silo(silo) local surface = silo.surface local box = silo.bounding_box for k = 1, 6 do local position = get_random_position(box, 0.8, 0.5) surface.create_entity { name = "crash-site-fire-flame", position = position } local fire = surface.create_entity { name = "crash-site-fire-smoke", position = position } fire.time_to_live = math.random(59 * 9, 59 * 14 - 1) fire.time_to_next_effect = math.random(59 * 2) end end local function pre_explode_silo(silo) local surface = silo.surface local box = silo.bounding_box for k = 1, 3 do local explosions = surface.create_entity { name = "crash-site-explosion-smoke", position = get_random_position(box, 0.8, 0.5) } explosions.time_to_live = math.random(59 * 6, 59 * 11 - 1) explosions.time_to_next_effect = math.random(59 * 3) end end ToNauvis.events[defines.events.on_rocket_launch_ordered] = function(event) if not event.rocket_silo or event.rocket_silo.name ~= "provisional-rocket-silo" then return end local player for i, entry in pairs(storage.rocket_silos) do if entry.real_silo == event.rocket_silo then if not storage.transitions then storage.transitions = {} end player = entry.player and game.get_player(entry.player) or game.players[1] storage.transitions[player.index] = { rocket_entry = entry, rocket_entry_index = i } break end end local burn_tick = game.tick + (14 * 59) local pre_explode_tick = game.tick + (17 * 59) local transit_tick = game.tick + (23 * 59) local explode_tick = game.tick + (28 * 59) script.on_nth_tick(burn_tick, function() burn_silo(event.rocket_silo) script.on_nth_tick(burn_tick, nil) end) script.on_nth_tick(pre_explode_tick, function() pre_explode_silo(event.rocket_silo) script.on_nth_tick(pre_explode_tick, nil) end) script.on_nth_tick(transit_tick, function() transit_player(player.index) script.on_nth_tick(transit_tick, nil) end) script.on_nth_tick(explode_tick, function() explode_silo(event.rocket_silo) script.on_nth_tick(explode_tick, nil) end) end ToNauvis.events[defines.events.on_post_entity_died] = function(event) if not event.ghost or event.prototype.name ~= "provisional-rocket-silo" then return end event.ghost.destroy() end return ToNauvis