From 5987cb1df784b19fd7ad098cd08889b8ab2fcbb7 Mon Sep 17 00:00:00 2001 From: MewMew <=> Date: Sat, 9 Mar 2019 02:57:18 +0100 Subject: [PATCH] junkyard > tick_tack_traps --- functions/tick_tack_trap.lua | 74 +++++++++++++++++++++++++++++++++ maps/junkyard.lua | 14 +++---- maps/junkyard_map_intro.lua | 80 ++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 functions/tick_tack_trap.lua create mode 100644 maps/junkyard_map_intro.lua diff --git a/functions/tick_tack_trap.lua b/functions/tick_tack_trap.lua new file mode 100644 index 00000000..a3df0b81 --- /dev/null +++ b/functions/tick_tack_trap.lua @@ -0,0 +1,74 @@ +-- timer traps -- by mewmew + +local tick_tacks = {"*tick*", "*tick*", "*tak*", "*tack*", "*tik*"} + +local kaboom_weights = { + {name = "grenade", chance = 5}, + {name = "cluster-grenade", chance = 1}, + {name = "destroyer-capsule", chance = 4}, + {name = "defender-capsule", chance = 6}, + {name = "distractor-capsule", chance = 5}, + {name = "poison-capsule", chance = 5}, + {name = "explosive-uranium-cannon-projectile", chance = 1}, + {name = "explosive-cannon-projectile", chance = 3}, +} + +local kabooms = {} +for _, t in pairs (kaboom_weights) do + for x = 1, t.chance, 1 do + table.insert(kabooms, t.name) + end +end + +local function create_flying_text(surface, position, text) + surface.create_entity({ + name = "flying-text", + position = position, + text = text, + color = {r=0.8, g=0.8, b=0.8} + }) + if text == "..." then return end + surface.play_sound({path="utility/armor_insert", position=position, volume_modifier=0.5}) +end + +local function create_kaboom(surface, position, name) + surface.create_entity({ + name = name, + position = position, + force = enemy, + target = position, + speed = 0.5 + }) +end + +local function tick_tack_trap(surface, position) + if not surface then return end + if not position then return end + if not position.x then return end + if not position.y then return end + local tick_tack_count = math.random(4, 7) + for t = 60, tick_tack_count * 60, 60 do + if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end + + if t < tick_tack_count * 60 then + global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = { + func = create_flying_text, + args = {surface, {x = position.x, y = position.y}, tick_tacks[math.random(1, #tick_tacks)]} + } + else + if math.random(1, 10) == 1 then + global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = { + func = create_flying_text, + args = {surface, {x = position.x, y = position.y}, "..."} + } + else + global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = { + func = create_kaboom, + args = {surface, {x = position.x, y = position.y}, kabooms[math.random(1, #kabooms)]} + } + end + end + end +end + +return tick_tack_trap \ No newline at end of file diff --git a/maps/junkyard.lua b/maps/junkyard.lua index a5fe0996..28f8dcc4 100644 --- a/maps/junkyard.lua +++ b/maps/junkyard.lua @@ -9,8 +9,11 @@ require "maps.modules.fluids_are_explosive" require "maps.modules.explosives_are_explosive" require "maps.modules.dangerous_nights" +require "maps.junkyard_map_intro" + local unearthing_worm = require "functions.unearthing_worm" local unearthing_biters = require "functions.unearthing_biters" +local tick_tack_trap = require "functions.tick_tack_trap" local create_entity_chain = require "functions.create_entity_chain" local create_tile_chain = require "functions.create_tile_chain" @@ -383,7 +386,7 @@ local function on_chunk_charted(event) end surface.regenerate_decorative(decorative_names, {position}) - if math_random(1, 10) ~= 1 then return end + if math_random(1, 16) ~= 1 then return end local pos = {x = position.x * 32 + math_random(1,32), y = position.y * 32 + math_random(1,32)} local noise = get_noise(1, pos) if noise > 0.4 or noise < -0.4 then return end @@ -429,12 +432,9 @@ local function on_player_mined_entity(event) if not entity.valid then return end if entity.name == "mineable-wreckage" then - if math_random(1,32) == 1 then - unearthing_biters(entity.surface, entity.position, math_random(4,12)) - end - if math_random(1,64) == 1 then - unearthing_worm(entity.surface, entity.position) - end + if math_random(1,32) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,12)) end + if math_random(1,64) == 1 then unearthing_worm(entity.surface, entity.position) end + if math_random(1,128) == 1 then tick_tack_trap(entity.surface, entity.position) end end if entity.force.name ~= "scrap" then return end diff --git a/maps/junkyard_map_intro.lua b/maps/junkyard_map_intro.lua new file mode 100644 index 00000000..c7bd0995 --- /dev/null +++ b/maps/junkyard_map_intro.lua @@ -0,0 +1,80 @@ +local event = require 'utils.event' + +--local main_caption = " --Junkyard-- " +--local sub_caption = "Some may call this junk. Me, I call them treasures." +local info = [[ + Citizen Log #468-2A-3287, Freelancer Cole + + To whoever is reading this message, + i have most likely already left this doomed place, or... well.. + + I am stranded on this foreign world since months and i have given up on fixing my ships transceiver. + Yes, things are not looking too good, i must admit. + The rust and devastation tells a story of an advanced civilization, + which seems to have evacuated their home long time ago. + + Any natural resources are rare and the ones worth while are too hard for me to reach. + Luckily, the wrecks yield all kinds of useful scraps, but also various dangers. + Almost lost half a leg just some days ago while digging out a crate. + + The wildlife is extremely aggressive, especially at the time of night. + Most of these insect appearing like creatures seem to live underground. + Stay near your light sources!! + + ###Log End### +]] + +local function create_map_intro(player) + if player.gui.left["map_intro_frame"] then player.gui.left["map_intro_frame"].destroy() end + local frame = player.gui.left.add {type = "frame", name = "map_intro_frame", direction = "vertical"} + + local t = frame.add {type = "table", column_count = 1} + --[[ + local tt = t.add {type = "table", column_count = 3} + local l = tt.add {type = "label", caption = main_caption} + l.style.font = "heading-1" + l.style.font_color = {r=0.8, g=0.6, b=0.6} + l.style.top_padding = 6 + l.style.bottom_padding = 6 + + local l = tt.add {type = "label", caption = sub_caption} + l.style.font = "heading-2" + l.style.font_color = {r=0.5, g=0.8, b=0.1} + l.style.minimal_width = 280 + ]] + local b = frame.add {type = "button", caption = "Close", name = "close_map_intro_frame", align = "right"} + b.style.font = "default" + b.style.minimal_height = 30 + b.style.minimal_width = 30 + b.style.top_padding = 2 + b.style.left_padding = 4 + b.style.right_padding = 4 + b.style.bottom_padding = 2 + + --local tt = t.add {type = "table", column_count = 1} + local frame = t.add {type = "frame"} + local l = frame.add {type = "label", caption = info} + l.style.single_line = false + l.style.font = "heading-3" + l.style.font_color = {r=0.95, g=0.95, b=0.95} + + +end + +local function on_player_joined_game(event) + local player = game.players[event.player_index] + if player.online_time < 18000 then + create_map_intro(player) + end +end + +local function on_gui_click(event) + if not event then return end + if not event.element then return end + if not event.element.valid then return end + local player = game.players[event.element.player_index] + if event.element.name == "close_map_intro_frame" then player.gui.left["map_intro_frame"].destroy() end +end + +event.add(defines.events.on_player_joined_game, on_player_joined_game) +event.add(defines.events.on_gui_click, on_gui_click) \ No newline at end of file