1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-30 04:30:58 +02:00

Merge pull request #1006 from Zahir-Khan/crashsite-cutscene

Crashsite cutscene
This commit is contained in:
theorangeangle 2019-12-04 21:51:31 -06:00 committed by GitHub
commit 8be717d4bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 416 additions and 5 deletions

View File

@ -348,7 +348,7 @@ local reconnect_character =
player.exit_cutscene()
player.set_controller {type = defines.controllers.character, character = character}
if func then
Token.get(func)(player_index)
Token.get(func)(player_index, params.skip_btn_flag)
end
Token.get(remove_renderings)(running_cutscene.rendering)
running_cutscene.btn.destroy()
@ -357,20 +357,25 @@ local reconnect_character =
end
)
function Public.terminate_cutscene(player_index, ticks)
function Public.terminate_cutscene(player_index, ticks,skip_btn_flag)
local running_cutscene = running_cutscenes[player_index]
if not running_cutscene then
return
end
ticks = ticks and ticks or 1
debug_print('Terminating cutscene in ' .. ticks .. ' Ticks')
if skip_btn_flag == nil then
skip_btn_flag = false
end
debug_print('Is terminate_func ignored = ' .. tostring(skip_btn_flag))
set_timeout_in_ticks(
ticks,
reconnect_character,
{
player_index = player_index,
running_cutscene = running_cutscene
running_cutscene = running_cutscene,
skip_btn_flag = skip_btn_flag
}
)
end
@ -460,7 +465,7 @@ function Public.goTo(player_index, waypoint_index)
end
local function restore(event)
Public.terminate_cutscene(event.player_index)
Public.terminate_cutscene(event.player_index, 1, true)
end
Event.add(defines.events.on_cutscene_waypoint_reached, handler)
@ -497,7 +502,7 @@ local function skip_cutscene(_, player)
return
end
if player.controller_type == defines.controllers.cutscene then
Public.terminate_cutscene(player.index)
Public.terminate_cutscene(player.index, 1, true)
end
end

View File

@ -65,6 +65,34 @@ cutscene_case7_line1=This concludes the introduction
cutscene_case7_line3=Have fun and keep digging!
replay_cutscene=To replay the introduction, use the __1__ command
# locale linked to the crashsite scenario
[crashsite]
cutscene1_case_line2=Welcome to __1__
cutscene1_case_line4=This is a custom scenario developed by __1__
cutscene1_case_line5=Join us at __1__
cutscene1_case_line6=The following introduction will help you get started playing!
cutscene1_case0_line3=This is our toolbar!
cutscene1_case0_line4=Here you'll find a wide range of tools and informations about us!
cutscene1_case0_line5=Hover your mouse over them for more information
cutscene1_case0_line6=You can toggle our toolbar with this button
cutscene1_case1_line1=This is the starting area. It has a market and a coin mint.
cutscene1_case1_line2=The coin mint produces coins at a limited rate, upgradable at the market.
cutscene1_case1_line3=Coins can also be obtained by killing biters, spitters, worms and spawners.
cutscene1_case2_line1=Coins are used to buy items at the market.
cutscene1_case3_line1=This, along with the ore patches and wall, is your spawn. Onto the outposts.
cutscene2_case_line1=This is an "Outpost". They come in many shapes and sizes, with everything from Iron Plates to MK2 Armor.
cutscene2_case_line2=You will find many structures similar to this dotted across the map.
cutscene2_case0_line1=Outposts are defended by enemy turrets and walls. Turret strength scales with the rewards inside.
cutscene2_case0_line2=To "capture" an outpost, you must destroy all turrets.
cutscene2_case1_line1=The Outpost contains a Market, Loot Chests and Magic Crafters (assemblers, chemical plants, etc).
cutscene2_case2_line1=Magic Crafters require no input or electricity, it will produce items for free. (This one makes Iron Plates.)
cutscene2_case3_line1=You can upgrade the crafting speed at the (local) market with coins. Some markets contain additional items.
cutscene2_case4_line1=Biters evolve fast (and sometimes multiply when killed!). Tip: keep pollution to a minimum by utilizing the free items.
cutscene2_case5_line1=The goal of this scenario is to eliminate all biters and launch a rocket on the limited size map.
cutscene2_case5_line2=This concludes the tour. Good luck and have fun!
replay_cutscene=To replay the introduction, use the __1__ command. You can also press the information icon for a text summary.
# locale linked to the quadrants scenario
[quadrants]
on=ON

View File

@ -0,0 +1,328 @@
local Event = require 'utils.event'
local Token = require 'utils.token'
local Task = require 'utils.task'
local Cutscene = require 'features.cutscene.cutscene_controller'
local CS_Rendering = require 'features.cutscene.rendering'
local Color = require 'resources.color_presets'
local PC = require 'features.player_create'
local register_rendering = Cutscene.register_rendering_id
local play_sound = Cutscene.play_sound
local draw_text = CS_Rendering.draw_text
local draw_multi_line = CS_Rendering.draw_multi_line_text
local rad = math.rad
local Rendering = require 'utils.rendering'
local CrashsiteCutscene = {}
local function valid(entity)
return entity and entity.valid
end
local delayed_draw_text =
Token.register(
function(params)
local player = params.player
if (not valid(player)) then
return
end
local tick = params.tick
if params.play_sound > 1 then
play_sound(tick, player, 'utility/list_box_click', 1)
end
register_rendering(player.index, tick, draw_text(params.settings, params.offset, params.text, params.player, params.params, params.draw_background, params.fit_to_edge))
end
)
local function draw_text_auto_replacing(tick, settings, offset, texts, player, params, draw_background, fit_to_edge, time, between_time)
time = time or 400
time = time / #texts
between_time = between_time or 30
params.time_to_live = time - between_time
if params.background then
params.background.time_to_live = time - between_time
end
for i = 1, #texts do
if texts[i] ~= '' then
Task.set_timeout_in_ticks(time * (i - 1), delayed_draw_text, {tick = tick, settings = settings, offset = offset, text = texts[i], player = player, params = params, draw_background = draw_background, fit_to_edge = fit_to_edge, play_sound = i})
end
end
end
local delayed_draw_arrow =
Token.register(
function(params)
local player = params.player
if (not valid(player)) then
return
end
local tick = params.tick
params = params.params
local rendering_parmas = params.params
local id = CS_Rendering.draw_arrow(params.settings, params.offset, player, rendering_parmas, params.fit_to_edge)
register_rendering(player.index, tick, id)
Rendering.blink(id, 20, rendering_parmas.time_to_live)
end
)
local function delayed_function(func, player, tick, params, offset_time)
if (not valid(player)) then
return
end
Task.set_timeout_in_ticks(offset_time, func, {player = player, tick = tick, params = params})
end
local original_resolution = {height = 1440, width = 2560}
local original_zoom = 1
local function cutscene_function_redmew(player_index, waypoint_index, params)
local player = game.players[player_index]
if (not valid(player)) then
return
end
local cases = {}
local ttw = params.time_to_wait
local zoom = params.zoom
local tick = params.tick
local settings = {original_resolution = original_resolution, original_zoom = original_zoom, player_zoom = zoom}
player.game_view_settings.show_entity_info = true
if waypoint_index ~= -1 then
play_sound(tick, player, 'utility/list_box_click', 1)
end
cases[-1] = function()
play_sound(tick, player, 'ambient/pollution', 1, 550)
register_rendering(player_index, tick, CS_Rendering.blackout(player, zoom, ttw + 10))
register_rendering(player_index, tick, draw_text(settings, {x = 0, y = -16}, 'Crashsite', player, {scale = 10, time_to_live = ttw, color = Color.red}, false, false))
register_rendering(
player_index,
tick,
draw_multi_line(settings, {x = 0, y = -5}, {{'crashsite.cutscene1_case_line2', 'Crashsite'}, '---------------------', {'crashsite.cutscene1_case_line4', 'Redmew'}, {'crashsite.cutscene1_case_line5', 'www.redmew.com/discord'}}, player, {scale = 5, time_to_live = ttw}, false)
)
draw_text_auto_replacing(tick, settings, {x = 0, y = 10}, {'', {'crashsite.cutscene1_case_line6'}}, player, {scale = 3}, false, false, ttw, 0)
end
cases[0] = function()
register_rendering(player_index, tick, CS_Rendering.blackout(player, zoom, ttw + 1))
register_rendering(player_index, tick, draw_text(settings, {x = 0, y = 0}, 'Redmew - Crashsite', player, {scale = 10, time_to_live = ttw - 60, color = Color.red}, false, false))
register_rendering(player_index, tick, draw_text(settings, {x = 0, y = -5}, 'Introduction', player, {scale = 5, time_to_live = ttw - 60}, false, false))
delayed_function(delayed_draw_arrow, player, tick, {settings = settings, offset = {x = 7, y = 2.5}, params = {rotation = rad(-45), time_to_live = 275 * 3 - 30}, fit_to_edge = true}, 0)
draw_text_auto_replacing(tick, settings, {x = 8.5, y = 3}, {{'crashsite.cutscene1_case0_line3'}}, player, {scale = 2.5, alignment = 'left'}, false, true, 275)
draw_text_auto_replacing(tick, settings, {x = 8.5, y = 3}, {'', {'crashsite.cutscene1_case0_line4'}}, player, {scale = 2.5, alignment = 'left'}, false, true, 275 * 2)
draw_text_auto_replacing(tick, settings, {x = 8.5, y = 3}, {'', '', {'crashsite.cutscene1_case0_line5'}}, player, {scale = 2.5, alignment = 'left'}, false, true, 275 * 3)
delayed_function(delayed_draw_arrow, player, tick, {settings = settings, offset = {x = 1, y = 2.5}, params = {rotation = rad(-45), time_to_live = 275 - 30}, fit_to_edge = true}, 275 * 3)
draw_text_auto_replacing(tick, settings, {x = 2.5, y = 3}, {'', '', '', {'crashsite.cutscene1_case0_line6'}}, player, {scale = 2.5, alignment = 'left'}, false, true, 275 * 4)
end
cases[1] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene1_case1_line1'}, {'crashsite.cutscene1_case1_line2'}, {'crashsite.cutscene1_case1_line3'}}, player, {scale = 2.5}, true, false, 400 * 3)
end
cases[2] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene1_case2_line1'}}, player, {scale = 2.5}, true, false, 300)
end
cases[3] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene1_case3_line1'}}, player, {scale = 3}, true, false, 400)
end
local case = cases[waypoint_index]
if case then
case()
end
end
local waypoints_redmew = {
{
-- case -1
position = {x = 0, y = 0},
transition_time = 60,
time_to_wait = 600,
zoom = 0.5
},
{
-- case 0
position = {x = 0, y = 0},
transition_time = 0,
time_to_wait = 300 * 4,
zoom = 0.5
},
{
-- case 1
position = {x = 0, y = -5},
transition_time = 120,
time_to_wait = 400 * 3,
zoom = 1.2
},
{
-- case 2
position = {x = -3, y = -5},
transition_time = 90,
time_to_wait = 300,
zoom = 1.6
},
{
-- case 3
position = {x = 0, y = 0},
transition_time = 90,
time_to_wait = 400,
zoom = 0.2
}
}
local function cutscene_function_outpost(player_index, waypoint_index, params)
local player = game.players[player_index]
if (not valid(player)) then
return
end
local cases = {}
local zoom = params.zoom
local tick = params.tick
local settings = {original_resolution = original_resolution, original_zoom = original_zoom, player_zoom = zoom}
player.game_view_settings.show_entity_info = true
if waypoint_index ~= -1 then
play_sound(tick, player, 'utility/list_box_click', 1)
end
cases[-1] = function()
play_sound(tick, player, 'utility/scenario_message')
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene2_case_line1'}, {'crashsite.cutscene2_case_line2'}}, player, {scale = 2.5, surface = "cutscene"}, true, false, 375 * 2)
end
cases[0] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene2_case0_line1'}, {'crashsite.cutscene2_case0_line2'}}, player, {scale = 2.5, surface = "cutscene"}, true, false, 375 * 2)
end
cases[1] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene2_case1_line1'}}, player, {scale = 2.5, surface = "cutscene"}, true, false, 500)
end
cases[2] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene2_case2_line1'}}, player, {scale = 2.5, surface = "cutscene"}, true, false, 600)
end
cases[3] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene2_case3_line1'}}, player, {scale = 2.5, surface = "cutscene"}, true, false, 500)
end
cases[4] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene2_case4_line1'}}, player, {scale = 2.5, surface = "cutscene"}, true, false, 600)
end
cases[5] = function()
draw_text_auto_replacing(tick, settings, {x = 0, y = 18}, {{'crashsite.cutscene2_case5_line1'}, {'crashsite.cutscene2_case5_line2'}}, player, {scale = 2.5, surface = "cutscene"}, true, false, 400 * 2)
end
local case = cases[waypoint_index]
if case then
case()
end
end
local waypoints_outpost = {
{
-- case -1
position = {x = 0, y = 0},
transition_time = 90,
time_to_wait = 375 * 2,
zoom = 0.5
},
{
-- case 0
position = {x = 0, y = -10},
transition_time = 120,
time_to_wait = 375 * 2,
zoom = 1.5
},
{
-- case 1
position = {x = 0, y = 0},
transition_time = 120,
time_to_wait = 500,
zoom = 1
},
{
-- case 2
position = {x = 4, y = 0},
transition_time = 90,
time_to_wait = 600,
zoom = 2.5
},
{
-- case 3
position = {x = -4, y = 0},
transition_time = 90,
time_to_wait = 500,
zoom = 2.5
},
{
-- case 4
position = {x = 0, y = 0},
transition_time = 60,
time_to_wait = 600,
zoom = 2
},
{
-- case 5
position = {x = 0, y = 25},
transition_time = 60,
time_to_wait = 400 * 2,
zoom = 1.5
}
}
local start_cutscene_outpost =
Token.register(
function(player_index)
local player = game.get_player(player_index)
if (not valid(player)) then
return
end
local pos = game.surfaces.cutscene.find_non_colliding_position('character', {0, 30}, 0, 1)
player.teleport(pos, 'cutscene')
Cutscene.register_running_cutscene(player_index, 'Crashsite_Outpost', 60)
end
)
local function terminate_function_redmew(player_index,skip_btn_flag)
if skip_btn_flag then
local player = game.get_player(player_index)
if (not valid(player)) then
return
end
PC.show_start_up(player)
player.print({'crashsite.replay_cutscene', '/replay'}, Color.yellow)
return
end
Task.set_timeout_in_ticks(1, start_cutscene_outpost, player_index)
end
local function terminate_function_outpost(player_index)
local player = game.get_player(player_index)
if (not valid(player)) then
return
end
local pos = game.surfaces.redmew.find_non_colliding_position('character', {0, 0}, 0, 1)
player.teleport(pos, 'redmew')
PC.show_start_up(player)
player.print({'crashsite.replay_cutscene', '/replay'}, Color.yellow)
end
Cutscene.register_cutscene_function('Crashsite_Welcome', waypoints_redmew, Token.register(cutscene_function_redmew), Token.register(terminate_function_redmew))
Cutscene.register_cutscene_function('Crashsite_Outpost', waypoints_outpost, Token.register(cutscene_function_outpost), Token.register(terminate_function_outpost))
Cutscene.register_replay('Crashsite_Welcome', 120)
local start_cutscene =
Token.register(
function(params)
Cutscene.register_running_cutscene(params.event.player_index, 'Crashsite_Welcome', 120)
end
)
function CrashsiteCutscene.on_init()
global.config.player_create.cutscene = true
CrashsiteCutscene.on_load()
end
function CrashsiteCutscene.on_load()
Event.add(
defines.events.on_player_created,
function(event)
Task.set_timeout_in_ticks(60, start_cutscene, {event = event})
end
)
end
return CrashsiteCutscene

View File

@ -14,6 +14,7 @@ local table = require 'utils.table'
local RS = require 'map_gen.shared.redmew_surface'
local MGSP = require 'resources.map_gen_settings'
local RedmewConfig = require 'config'
local Cutscene = require 'map_gen.maps.crash_site.cutscene'
local degrees = math.degrees
@ -135,6 +136,45 @@ local spawn_callback =
end
)
local function cutscene_builder(name, x, y)
return game.surfaces.cutscene.create_entity{name = name, position = {x, y}, force = game.forces.enemy}
end
local function cutscene_outpost()
local tiles = {}
for i = -11, 12 do
for j = -11, 12 do
table.insert(tiles, {name = "stone-path", position = {i, j}})
end
end
for i = 0, 22 do
cutscene_builder('stone-wall', -11, -10 + i)
cutscene_builder('stone-wall', -12, -10 + i)
cutscene_builder('stone-wall', -12 + i, -11)
cutscene_builder('stone-wall', -12 + i, -12)
cutscene_builder('stone-wall', 11, -12 + i)
cutscene_builder('stone-wall', 12, -12 + i)
cutscene_builder('stone-wall', -10 + i, 11)
cutscene_builder('stone-wall', -10 + i, 12)
if i % 4 == 0 and i ~= 20 and i ~= 0 then
cutscene_builder('gun-turret', -8, -8 + i)
cutscene_builder('gun-turret', 10, -8 + i)
cutscene_builder('gun-turret', -9 + i, -8)
cutscene_builder('gun-turret', -9 + i, 10)
end
end
for i = -2, 2 do
for j = 3, 5 do
local loot_box = cutscene_builder('steel-chest', i, j)
loot_box.insert{name = "iron-plate", count = 50}
end
end
cutscene_builder('market', -4, 0)
local furnace = cutscene_builder('electric-furnace', 4, 0)
furnace.insert('iron-ore')
game.surfaces.cutscene.set_tiles(tiles)
end
local function init()
local on_init = (_LIFECYCLE == _STAGE.init)
@ -142,6 +182,16 @@ local function init()
local outpost_builder = OutpostBuilder.new(outpost_random)
if on_init then
game.create_surface('cutscene')
game.surfaces.cutscene.request_to_generate_chunks({0,0}, 2)
game.surfaces.cutscene.force_generate_chunk_requests()
cutscene_outpost()
Cutscene.on_init()
else
Cutscene.on_load()
end
local stage1a = {
small_iron_plate_factory,
small_gear_factory,