From de87998299a70e02d1d13b37224c5650fda72eb8 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Mon, 26 Nov 2018 01:49:18 -0500 Subject: [PATCH 01/10] Break chat_trigger functions apart --- features/chat_triggers.lua | 218 ++++++++++++---------------- map_gen/misc/naughty_words.lua | 27 ++++ map_gen/misc/silly_player_names.lua | 8 +- map_layout.lua | 7 +- resources/naughty_words.lua | 41 ++++++ 5 files changed, 173 insertions(+), 128 deletions(-) create mode 100644 map_gen/misc/naughty_words.lua create mode 100644 resources/naughty_words.lua diff --git a/features/chat_triggers.lua b/features/chat_triggers.lua index fe62b923..242748cc 100644 --- a/features/chat_triggers.lua +++ b/features/chat_triggers.lua @@ -7,8 +7,6 @@ local Hodor = require 'resources.hodor_messages' local prefix = '## - ' -global.mention_enabled = true - local auto_replies = { ['discord'] = {'Did you ask about our discord server?', 'You can find it here: redmew.com/discord'}, ['patreon'] = {'Did you ask about our patreon?', 'You can find it here: patreon.com/redmew'}, @@ -16,69 +14,37 @@ local auto_replies = { ['grief'] = {'To report grief please use the /report function.', 'If no admins are online use #moderation-requests on the discord and make sure the @mention the appropriate role.'} } -global.naughty_words_enabled = false -global.naughty_words = { - ['ass'] = true, - ['bugger'] = true, - ['butt'] = true, - ['bum'] = true, - ['bummer'] = true, - ['christ'] = true, - ['crikey'] = true, - ['darn'] = true, - ['dam'] = true, - ['damn'] = true, - ['dang'] = true, - ['dagnabit'] = true, - ['dagnabbit'] = true, - ['drat'] = true, - ['fart'] = true, - ['feck'] = true, - ['frack'] = true, - ['freaking'] = true, - ['frick'] = true, - ['gay'] = true, - ['gee'] = true, - ['geez'] = true, - ['git'] = true, - ['god'] = true, - ['golly'] = true, - ['gosh'] = true, - ['heavens'] = true, - ['heck'] = true, - ['hell'] = true, - ['holy'] = true, - ['jerk'] = true, - ['jesus'] = true, - ['petes'] = true, - ["pete's"] = true, - ['poo'] = true, - ['satan'] = true, - ['willy'] = true, - ['wee'] = true, - ['yikes'] = true -} - -local function hodor(event) - local message = event.message:lower() - - if message:match('hodor') then - game.print('Hodor: ' .. table.get_random_weighted(Hodor, 1, 2)) - end - +--- Check for player and get player +local function get_player(event) -- player_index is nil if the message came from the server, -- and indexing Game.players with nil is apparently an error. local player_index = event.player_index if not player_index then - return + return false end local player = Game.get_player_by_index(event.player_index) if not player or not player.valid then - return + return false end + return player +end - if not player.admin then +--- Emulates the discord bot hodor's reaction to his name +local function hodor(event) + -- first check for a match, since 99% of messages aren't a match for 'hodor' + local message = event.message:lower() + if message:match('hodor') then + game.print('Hodor: ' .. table.get_random_weighted(Hodor, 1, 2)) + end +end + +--- Automatically responds to preset trigger words +local function auto_respond(event) + local message = event.message:lower() + local player = get_player(event) + + if player and not player.admin then for trigger, replies in pairs(auto_replies) do if message:match(trigger) then for _, reply in pairs(replies) do @@ -87,85 +53,93 @@ local function hodor(event) end end end +end - if global.naughty_words_enabled then - local naughty_words = global.naughty_words - for word in message:gmatch('%S+') do - if naughty_words[word] then - game.print(player.name .. ' this is a Christian Factorio server, no swearing please!') - break - end - end +--- Create notifications when a player's name is mentioned +local function mentions(event) + -- Gives a sound notification to a mentioned player using #[player-name], [player-name]#, @[player-name], [player-name]@ or to admins with moderator or admin without prefix or postfix + + local missing_player_string + local not_found = 0 + local cannot_mention = {} + local player = get_player(event) + if not player or not player.valid then + return end - -- Gives a sound notification to a mentioned player using #[player-name], [player-name]#, @[player-name], [player-name]@ or to admins with moderator or admin without prefix or postfix - if global.mention_enabled then - local missing_player_string - local not_found = 0 - local cannot_mention = {} - for w in event.message:gmatch('%S+') do - local word = w:lower() - local trimmed_word = string.sub(word, 0, string.len(word)-1) - local first_char = string.sub(word, 0, 1) - local last_char = string.sub(word, string.len(word)) - local success = false - local admin_call = false - if word == 'admin' or word == 'moderator' or trimmed_word == 'admin' or trimmed_word == 'moderator' then - admin_call = true - elseif (first_char ~= '#' and last_char ~= '#') and (first_char ~= '@' and last_char ~= '@') then - success = true - end - if not success then - for _, p in ipairs(game.connected_players) do - local word_front_trim = string.sub(word, 2, string.len(word)) - local word_back_trim = trimmed_word - local word_front_back_trim = string.sub(word_front_trim, 0, string.len(word_front_trim)-1) - local word_back_double_trim = string.sub(word_back_trim, 0, string.len(word_back_trim)-1) - word = (trimmed_word == 'admin' or trimmed_word == 'moderator') and trimmed_word or word - if admin_call and p.admin then - p.print(prefix..Game.get_player_by_index(event.player_index).name..' mentioned '..word..'!', {r = 1, g = 1, b = 0, a = 1}) - p.play_sound{path='utility/new_objective', volume_modifier = 1 } - success = true - end - if not admin_call and (p.name:lower() == word_front_trim or p.name:lower() == word_back_trim or p.name:lower() == word_back_double_trim or p.name:lower() == word_front_back_trim) then - if p.name == player.name then - if _DEBUG then - player.print(prefix..'Can\'t mention yourself!', {r = 1, g = 0, b = 0, a = 1}) - end - success = true - break; - end - p.print(prefix..Game.get_player_by_index(event.player_index).name..' mentioned you!', {r = 1, g = 1, b = 0, a = 1}) - p.play_sound{path='utility/new_objective', volume_modifier = 1 } - success = true + for w in event.message:gmatch('%S+') do + local word = w:lower() + local trimmed_word = string.sub(word, 0, string.len(word) - 1) + local first_char = string.sub(word, 0, 1) + local last_char = string.sub(word, string.len(word)) + local success = false + local admin_call = false + if word == 'admin' or word == 'moderator' or trimmed_word == 'admin' or trimmed_word == 'moderator' then + admin_call = true + elseif (first_char ~= '#' and last_char ~= '#') and (first_char ~= '@' and last_char ~= '@') then + success = true + end + if not success then + for _, p in ipairs(game.connected_players) do + local word_front_trim = string.sub(word, 2, string.len(word)) + local word_back_trim = trimmed_word + local word_front_back_trim = string.sub(word_front_trim, 0, string.len(word_front_trim) - 1) + local word_back_double_trim = string.sub(word_back_trim, 0, string.len(word_back_trim) - 1) + word = (trimmed_word == 'admin' or trimmed_word == 'moderator') and trimmed_word or word + if admin_call and p.admin then + p.print(prefix .. Game.get_player_by_index(event.player_index).name .. ' mentioned ' .. word .. '!', {r = 1, g = 1, b = 0, a = 1}) + p.play_sound {path = 'utility/new_objective', volume_modifier = 1} + success = true + end + if not admin_call and (p.name:lower() == word_front_trim or p.name:lower() == word_back_trim or p.name:lower() == word_back_double_trim or p.name:lower() == word_front_back_trim) then + if p.name == player.name then if _DEBUG then - player.print(prefix..'Successful mentioned '..p.name, {r = 0, g = 1, b = 0, a = 1}) + player.print(prefix .. "Can't mention yourself!", {r = 1, g = 0, b = 0, a = 1}) end - break; + success = true + break end + p.print(prefix .. Game.get_player_by_index(event.player_index).name .. ' mentioned you!', {r = 1, g = 1, b = 0, a = 1}) + p.play_sound {path = 'utility/new_objective', volume_modifier = 1} + success = true + if _DEBUG then + player.print(prefix .. 'Successful mentioned ' .. p.name, {r = 0, g = 1, b = 0, a = 1}) + end + break end end - if not success then - if admin_call then - word = 'no '.. word .. 's online!' - end - not_found = not_found + 1 - table.insert(cannot_mention, (word .. ', ')) - end end - for _, pname in ipairs(cannot_mention) do - missing_player_string = missing_player_string~=nil and missing_player_string .. pname or pname - end - if missing_player_string ~= nil then - missing_player_string = string.sub(missing_player_string, 1, (string.len(missing_player_string)-2)) - if not_found > 1 then - player.print(prefix..'Players not found: ' .. missing_player_string, {r = 1, g = 1, b = 0, a = 1}) - else - player.print(prefix..'Player not found: ' .. missing_player_string, {r = 1, g = 1, b = 0, a = 1}) + if not success then + if admin_call then + word = 'no ' .. word .. 's online!' end + not_found = not_found + 1 + table.insert(cannot_mention, (word .. ', ')) + end + end + for _, pname in ipairs(cannot_mention) do + missing_player_string = missing_player_string ~= nil and missing_player_string .. pname or pname + end + if missing_player_string ~= nil then + missing_player_string = string.sub(missing_player_string, 1, (string.len(missing_player_string) - 2)) + if not_found > 1 then + player.print(prefix .. 'Players not found: ' .. missing_player_string, {r = 1, g = 1, b = 0, a = 1}) + else + player.print(prefix .. 'Player not found: ' .. missing_player_string, {r = 1, g = 1, b = 0, a = 1}) end end end +local function on_console_chat(event) + if global.config.hodor then + hodor(event) + end + if global.config.auto_respond then + auto_respond(event) + end + if global.config.mentions then + mentions(event) + end +end -Event.add(defines.events.on_console_chat, hodor) +Event.add(defines.events.on_console_chat, on_console_chat) diff --git a/map_gen/misc/naughty_words.lua b/map_gen/misc/naughty_words.lua new file mode 100644 index 00000000..1dd8d26b --- /dev/null +++ b/map_gen/misc/naughty_words.lua @@ -0,0 +1,27 @@ +local Game = require 'utils.game' +local Event = require 'utils.event' + +global.naughty_words = require('resources.naughty_words') + +local function admonish_blasphemy(event) +-- player_index is nil if the message came from the server, + -- and indexing Game.players with nil is apparently an error. + if not event.player_index then + return + end + local message = event.message:lower() + local player = Game.get_player_by_index(event.player_index) + if not player or not player.valid then + return + end + + local naughty_words = global.naughty_words + for word in message:gmatch('%S+') do + if naughty_words[word] then + game.print(player.name .. ' this is a Christian Factorio server, no swearing please!') + break + end + end +end + +Event.add(defines.events.on_console_chat, admonish_blasphemy) diff --git a/map_gen/misc/silly_player_names.lua b/map_gen/misc/silly_player_names.lua index 1ee1c187..64816c61 100644 --- a/map_gen/misc/silly_player_names.lua +++ b/map_gen/misc/silly_player_names.lua @@ -6,6 +6,8 @@ local Utils = require('utils.utils') global.actual_name = {} global.silly_names = {} global.silly_names.count = 0 +global.config.players_assigned_names = true -- assigns players random names when they first join +global.config.players_roll_names = true -- allows players to roll random names local name_combinations = #naming_words.adverbs * #naming_words.adjectives * #naming_words.nouns @@ -144,15 +146,15 @@ local function get_player_id(cmd) Game.player_print(target_name .. ' -- ' .. target_index) end -if global.scenario.config.players_assigned_names == true then +if global.config.players_assigned_names == true then Event.add(defines.events.on_player_created, name_player_event) end -if global.scenario.config.players_roll_names == true then +if global.config.players_roll_names == true then commands.add_command('name-roll', 'Assigns you a random, silly name', name_player_command) end -if global.scenario.config.players_roll_names == true or global.scenario.config.players_assigned_names == true then +if global.config.players_roll_names == true or global.config.players_assigned_names == true then commands.add_command('name-restore', 'Removes your fun name and gives you back your actual name', restore_name) commands.add_command('name-check', ' Check the original name of a player', check_name) commands.add_command('get-player-id', 'Gets the ID of a player (Admin only)', get_player_id) diff --git a/map_layout.lua b/map_layout.lua index 1de4a7ef..e923e422 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -136,10 +136,11 @@ local terrain_modules = { --require ('map_gen.misc.danger_ore_banned_entities') --require ('map_gen.misc.restrict_landfill_tile')({['water'] = true}) --require "map_gen.ores.rso.rso_control" ---require 'map_gen.misc.nightfall' +--require 'map_gen.misc.nightfall' -- forces idle biters to attack at night --require 'map_gen.misc.creep_spread' ---require 'map_gen.misc.car_body' ---require 'features.silly_player_names' +--require 'map_gen.misc.car_body' -- gives players cars instead of characters +--require 'features.silly_player_names' -- assigns players random names when they first join +--require 'map_gen.misc.naughty_words' -- admonishes players for cursing if #entity_modules > 0 then shape = shape or b.full_shape diff --git a/resources/naughty_words.lua b/resources/naughty_words.lua new file mode 100644 index 00000000..b5890bd3 --- /dev/null +++ b/resources/naughty_words.lua @@ -0,0 +1,41 @@ +return { + ['ass'] = true, + ['bugger'] = true, + ['butt'] = true, + ['bum'] = true, + ['bummer'] = true, + ['christ'] = true, + ['crikey'] = true, + ['darn'] = true, + ['dam'] = true, + ['damn'] = true, + ['dang'] = true, + ['dagnabit'] = true, + ['dagnabbit'] = true, + ['drat'] = true, + ['fart'] = true, + ['feck'] = true, + ['frack'] = true, + ['freaking'] = true, + ['frick'] = true, + ['gay'] = true, + ['gee'] = true, + ['geez'] = true, + ['git'] = true, + ['god'] = true, + ['golly'] = true, + ['gosh'] = true, + ['heavens'] = true, + ['heck'] = true, + ['hell'] = true, + ['holy'] = true, + ['jerk'] = true, + ['jesus'] = true, + ['petes'] = true, + ["pete's"] = true, + ['poo'] = true, + ['satan'] = true, + ['willy'] = true, + ['wee'] = true, + ['yikes'] = true +} From 17af2498f86c9f424618dedfaa5cdd7b9ed1b9ce Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Mon, 26 Nov 2018 10:50:06 -0500 Subject: [PATCH 02/10] Have get_player return nil if no index/player --- features/chat_triggers.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/features/chat_triggers.lua b/features/chat_triggers.lua index 242748cc..02d1b233 100644 --- a/features/chat_triggers.lua +++ b/features/chat_triggers.lua @@ -20,12 +20,11 @@ local function get_player(event) -- and indexing Game.players with nil is apparently an error. local player_index = event.player_index if not player_index then - return false + return nil end - local player = Game.get_player_by_index(event.player_index) if not player or not player.valid then - return false + return nil end return player end From c8507bddb9c7b7de0ff4462993955b069bf62781 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Mon, 26 Nov 2018 19:23:12 -0500 Subject: [PATCH 03/10] Use string.format --- features/chat_triggers.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/chat_triggers.lua b/features/chat_triggers.lua index 02d1b233..76e40c9e 100644 --- a/features/chat_triggers.lua +++ b/features/chat_triggers.lua @@ -86,7 +86,8 @@ local function mentions(event) local word_back_double_trim = string.sub(word_back_trim, 0, string.len(word_back_trim) - 1) word = (trimmed_word == 'admin' or trimmed_word == 'moderator') and trimmed_word or word if admin_call and p.admin then - p.print(prefix .. Game.get_player_by_index(event.player_index).name .. ' mentioned ' .. word .. '!', {r = 1, g = 1, b = 0, a = 1}) + local message = string.format('%s%s mentioned %s!', prefix, Game.get_player_by_index(event.player_index).name, word ) + p.print(message, {r = 1, g = 1, b = 0, a = 1}) p.play_sound {path = 'utility/new_objective', volume_modifier = 1} success = true end From 40f20bd2d373410ce83b6cbf6b3b1bc4cdaccf65 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Mon, 26 Nov 2018 19:23:12 -0500 Subject: [PATCH 04/10] Use string.format --- features/chat_triggers.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/chat_triggers.lua b/features/chat_triggers.lua index 02d1b233..76e40c9e 100644 --- a/features/chat_triggers.lua +++ b/features/chat_triggers.lua @@ -86,7 +86,8 @@ local function mentions(event) local word_back_double_trim = string.sub(word_back_trim, 0, string.len(word_back_trim) - 1) word = (trimmed_word == 'admin' or trimmed_word == 'moderator') and trimmed_word or word if admin_call and p.admin then - p.print(prefix .. Game.get_player_by_index(event.player_index).name .. ' mentioned ' .. word .. '!', {r = 1, g = 1, b = 0, a = 1}) + local message = string.format('%s%s mentioned %s!', prefix, Game.get_player_by_index(event.player_index).name, word ) + p.print(message, {r = 1, g = 1, b = 0, a = 1}) p.play_sound {path = 'utility/new_objective', volume_modifier = 1} success = true end From d971075da07c6361ace76bd9efa8e6319b07aa3f Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Tue, 27 Nov 2018 20:12:50 +0100 Subject: [PATCH 05/10] admin mentions now require pre, or postfix --- features/chat_triggers.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/features/chat_triggers.lua b/features/chat_triggers.lua index 76e40c9e..2d009e74 100644 --- a/features/chat_triggers.lua +++ b/features/chat_triggers.lua @@ -56,7 +56,7 @@ end --- Create notifications when a player's name is mentioned local function mentions(event) - -- Gives a sound notification to a mentioned player using #[player-name], [player-name]#, @[player-name], [player-name]@ or to admins with moderator or admin without prefix or postfix + -- Gives a sound notification to a mentioned player using #[player-name], [player-name]#, @[player-name], [player-name]@ or to admins with admin with prefix or postfix local missing_player_string local not_found = 0 @@ -73,9 +73,7 @@ local function mentions(event) local last_char = string.sub(word, string.len(word)) local success = false local admin_call = false - if word == 'admin' or word == 'moderator' or trimmed_word == 'admin' or trimmed_word == 'moderator' then - admin_call = true - elseif (first_char ~= '#' and last_char ~= '#') and (first_char ~= '@' and last_char ~= '@') then + if (first_char ~= '#' and last_char ~= '#') and (first_char ~= '@' and last_char ~= '@') then success = true end if not success then @@ -84,7 +82,10 @@ local function mentions(event) local word_back_trim = trimmed_word local word_front_back_trim = string.sub(word_front_trim, 0, string.len(word_front_trim) - 1) local word_back_double_trim = string.sub(word_back_trim, 0, string.len(word_back_trim) - 1) - word = (trimmed_word == 'admin' or trimmed_word == 'moderator') and trimmed_word or word + if word_front_trim == 'admin' or word_back_trim == 'admin' or word_back_double_trim == 'admin' or word_front_back_trim == 'admin' then + admin_call = true + word = 'admin' + end if admin_call and p.admin then local message = string.format('%s%s mentioned %s!', prefix, Game.get_player_by_index(event.player_index).name, word ) p.print(message, {r = 1, g = 1, b = 0, a = 1}) From 1e1b3855377e95b2d953ed249abfd678be022562 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Tue, 27 Nov 2018 14:25:59 -0500 Subject: [PATCH 06/10] Remove on_server_started from luacheckrc --- .luacheckrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index 23895768..e20c87a0 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -625,7 +625,7 @@ stds.factorio_defines = { "on_gui_closed", "on_gui_value_changed", "on_player_muted", "on_player_unmuted", "on_player_cheat_mode_enabled", "on_player_cheat_mode_disabled", "on_character_corpse_expired", "on_pre_ghost_deconstructed", "on_player_pipette", "on_player_display_resolution_changed", "on_player_display_scale_changed", "on_pre_player_crafted_item", "on_player_cancelled_crafting", "on_chunk_charted", "on_technology_effects_reset", "on_land_mine_armed", "on_forces_merged", - "on_player_trash_inventory_changed", "on_server_started" + "on_player_trash_inventory_changed", }, }, alert_type = { From fa4560fdcb3e66cb1d6c1659a2034b9031c3ef8f Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 26 Nov 2018 21:37:41 +0100 Subject: [PATCH 07/10] Fixed a bunch of performance issues and bugs --- map_gen/Diggy/Config.lua | 24 +++-- map_gen/Diggy/Debug.lua | 13 +-- map_gen/Diggy/Feature/AlienSpawner.lua | 87 ++++++++++--------- map_gen/Diggy/Feature/ArtefactHunting.lua | 10 ++- map_gen/Diggy/Feature/DiggyCaveCollapse.lua | 5 +- map_gen/Diggy/Feature/DiggyHole.lua | 13 +-- map_gen/Diggy/Feature/Experience.lua | 23 +++-- map_gen/Diggy/Feature/RefreshMap.lua | 17 ++-- map_gen/Diggy/Feature/ScatteredResources.lua | 9 +- map_gen/Diggy/Feature/SetupPlayer.lua | 4 +- map_gen/Diggy/Feature/SimpleRoomGenerator.lua | 12 ++- 11 files changed, 126 insertions(+), 91 deletions(-) diff --git a/map_gen/Diggy/Config.lua b/map_gen/Diggy/Config.lua index 277a92ac..14ea32cd 100644 --- a/map_gen/Diggy/Config.lua +++ b/map_gen/Diggy/Config.lua @@ -1,4 +1,5 @@ -- dependencies +local abs = math.abs -- this local Config = { @@ -146,13 +147,13 @@ local Config = { alien_coin_modifiers = { ['small-biter'] = 2, ['small-spitter'] = 2, - ['small-worm'] = 2, + ['small-worm-turret'] = 2, ['medium-biter'] = 3, ['medium-spitter'] = 3, - ['medium-worm'] = 3, + ['medium-worm-turret'] = 3, ['big-biter'] = 5, ['big-spitter'] = 5, - ['big-worm'] = 5, + ['big-worm-turret'] = 5, ['behemoth-biter'] = 7, ['behemoth-spitter'] = 7, }, @@ -209,7 +210,7 @@ local Config = { enabled = true, -- determines how distance is measured - distance = function (x, y) return math.abs(x) + math.abs(y) end, + distance = function (x, y) return abs(x) + abs(y) end, --distance = function (x, y) return math.sqrt(x * x + y * y) end, -- defines the weights of which resource_richness_value to spawn @@ -416,8 +417,21 @@ local Config = { {level = 73, price = 2000, name = 'satellite'}, {level = 100, price = 1, name = 'iron-stick'}, }, + -- modifies the experience per alien type, higher is more xp + alien_experience_modifiers = { + ['small-biter'] = 2, + ['small-spitter'] = 2, + ['small-worm-turret'] = 2, + ['medium-biter'] = 3, + ['medium-spitter'] = 3, + ['medium-worm-turret'] = 3, + ['big-biter'] = 5, + ['big-spitter'] = 5, + ['big-worm-turret'] = 5, + ['behemoth-biter'] = 7, + ['behemoth-spitter'] = 7, + }, }, - }, } diff --git a/map_gen/Diggy/Debug.lua b/map_gen/Diggy/Debug.lua index 51f940ca..83b21740 100644 --- a/map_gen/Diggy/Debug.lua +++ b/map_gen/Diggy/Debug.lua @@ -7,6 +7,9 @@ local abs = math.abs -- this local Debug = {} +local default_base_color = {r = 1, g = 1, b = 1} +local default_delta_color = {r = 0, g = 0, b = 0} + -- private state local debug = false local cheats = false @@ -91,8 +94,8 @@ end ]] function Debug.print_grid_value(value, surface, position, scale, offset, immutable) local is_string = type(value) == 'string' - local color = {r = 1, g = 1, b = 1} - text = value + local color = default_base_color + local text = value if type(immutable) ~= 'boolean' then immutable = false @@ -170,8 +173,8 @@ function Debug.print_colored_grid_value(value, surface, position, scale, offset, color_value, base_color, delta_color, under_bound, over_bound) local is_string = type(value) == 'string' -- default values: - local color = base_color or {r = 1, g = 1, b = 1} - local d_color = delta_color or {r = 0, g = 0, b = 0} + local color = base_color or default_base_color + local d_color = delta_color or default_delta_color local u_color = under_bound or color local o_color = over_bound or color @@ -185,7 +188,7 @@ function Debug.print_colored_grid_value(value, surface, position, scale, offset, b = color.b + color_value * d_color.b } end - text = value + local text = value if type(immutable) ~= 'boolean' then immutable = false diff --git a/map_gen/Diggy/Feature/AlienSpawner.lua b/map_gen/Diggy/Feature/AlienSpawner.lua index 8a3f31bb..06c124ce 100644 --- a/map_gen/Diggy/Feature/AlienSpawner.lua +++ b/map_gen/Diggy/Feature/AlienSpawner.lua @@ -21,6 +21,12 @@ local raise_event = script.raise_event local AlienSpawner = {} local alien_size_chart = {} +local locations_to_scan = { + {x = 0, y = -1.5}, -- up + {x = 1.5, y = 0}, -- right + {x = 0, y = 1.5}, -- bottom + {x = -1.5, y = 0}, -- left +} Global.register_init({ alien_size_chart = alien_size_chart, @@ -37,37 +43,43 @@ end, function(tbl) alien_size_chart = tbl.alien_size_chart end) +local rocks_to_find = {'sand-rock-big', 'rock-huge'} + ---Triggers mining at the collision_box of the alien, to free it local do_alien_mining = Token.register(function(params) local surface = params.surface local create_entity = surface.create_entity local find_non_colliding_position = surface.find_non_colliding_position - local find_entities_filtered = surface.find_entities_filtered - for _, area in ipairs(params.positions_to_mine) do - local rocks = find_entities_filtered({area = area, name = {'sand-rock-big', 'rock-huge'}}) + local rocks = surface.find_entities_filtered({area = params.clear_area, name = rocks_to_find}) - if (0 == #rocks) then - break + local rock_count = #rocks + if rock_count > 0 then + -- with multiple rocks opening at once, it will spawn less particles in total per rock + local particle_count + if rock_count == 1 then + particle_count = 15 + elseif rock_count == 2 then + particle_count = 10 + else + particle_count = 5 end - -- with multiple rocks opening at once, it will spawn less particles in total per rock - local particle_count = 16 - ((#rocks - 1) * 5) - for _, rock in pairs(rocks) do + for rock_index = rock_count, 1, -1 do + local rock = rocks[rock_index] raise_event(defines.events.on_entity_died, {entity = rock}) CreateParticles.destroy_rock(create_entity, particle_count, rock.position) rock.destroy() end end - for _, prototype in ipairs(params.locations_to_spawn) do - -- amount is not used for aliens prototypes, it just carries along in the params - local amount = prototype.amount - while amount > 0 do - prototype.position = find_non_colliding_position(prototype.name, prototype.position, 2, 0.4) or prototype.position - create_entity(prototype) - amount = amount - 1 - end + local spawn_location = params.spawn_location + -- amount is not used for aliens prototypes, it just carries along in the params + local amount = spawn_location.amount + while amount > 0 do + spawn_location.position = find_non_colliding_position(spawn_location.name, spawn_location.position, 2, 0.4) or spawn_location.position + create_entity(spawn_location) + amount = amount - 1 end end) @@ -80,9 +92,8 @@ end) local function spawn_aliens(aliens, force, surface, x, y) local position = {x = x, y = y} local count_tiles_filtered = surface.count_tiles_filtered - local areas_to_mine = {} - local locations_to_spawn = {} + local spawn_count = 0 for name, amount in pairs(aliens) do local size_data = alien_size_chart[name] if not size_data then @@ -90,20 +101,14 @@ local function spawn_aliens(aliens, force, surface, x, y) break end - local locations_to_scan = { - {x = 0, y = -1.5}, -- up - {x = 1.5, y = 0}, -- right - {x = 0, y = 1.5}, -- bottom - {x = -1.5, y = 0}, -- left - } - local collision_box = size_data.collision_box local left_top_x = collision_box.left_top.x * 1.6 local left_top_y = collision_box.left_top.y * 1.6 local right_bottom_x = collision_box.right_bottom.x * 1.6 local right_bottom_y = collision_box.right_bottom.y * 1.6 - for _, direction in ipairs(locations_to_scan) do + for i = #locations_to_scan, 1, -1 do + local direction = locations_to_scan[i] local x_center = direction.x + x local y_center = direction.y + y @@ -122,22 +127,21 @@ local function spawn_aliens(aliens, force, surface, x, y) -- can't spawn properly if void is present if count_tiles_filtered({area = offset_area, name = 'out-of-map'}) == 0 then - insert(areas_to_mine, offset_area) - insert(locations_to_spawn, {name = name, position = {x = x_center, y = y_center}, force = force, amount = amount}) + spawn_count = spawn_count + 1 + Task.set_timeout_in_ticks(spawn_count, do_alien_mining, { + surface = surface, + clear_area = offset_area, + spawn_location = { + name = name, + position = {x = x_center, y = y_center}, + force = force, + amount = amount + }, + }) break end end end - - -- can't do mining in the same tick as it would invalidate the rock just mined and there - -- is no way to distinguish them as multiple can occupy the same position - if #locations_to_spawn > 0 then - Task.set_timeout_in_ticks(1, do_alien_mining, { - surface = surface, - positions_to_mine = areas_to_mine, - locations_to_spawn = locations_to_spawn, - }) - end end --[[-- @@ -176,8 +180,11 @@ function AlienSpawner.register(config) position = position or entity.position surface = surface or entity.surface create_entity = create_entity or surface.create_entity - find_non_colliding_position = find_non_colliding_position or surface.find_non_colliding_position - position = find_non_colliding_position(hydra_spawn, position, 2, 0.4) or position + -- always spawn worms on their designated position + if not hydra_spawn:match('worm-turret') then + find_non_colliding_position = find_non_colliding_position or surface.find_non_colliding_position + position = find_non_colliding_position(hydra_spawn, position, 2, 0.4) or position + end create_entity({name = hydra_spawn, force = force, position = position}) amount = amount - 1 end diff --git a/map_gen/Diggy/Feature/ArtefactHunting.lua b/map_gen/Diggy/Feature/ArtefactHunting.lua index e549dd63..dd359994 100644 --- a/map_gen/Diggy/Feature/ArtefactHunting.lua +++ b/map_gen/Diggy/Feature/ArtefactHunting.lua @@ -17,6 +17,8 @@ local utils = require 'utils.utils' -- this local ArtefactHunting = {} +local coin_color = {r = 255, g = 215, b = 0} + -- some GUI stuff local function redraw_table(data) local list = data.list @@ -81,7 +83,7 @@ Gui.on_custom_close('Diggy.ArtefactHunting.Frame', function (event) end) function ArtefactHunting.update_gui() - for _, p in ipairs(game.connected_players) do + for _, p in pairs(game.connected_players) do local frame = p.gui.left['Diggy.ArtefactHunting.Frame'] if frame and frame.valid then @@ -137,9 +139,10 @@ function ArtefactHunting.register(config) return end + local insert = chest.insert for name, prototype in pairs(config.treasure_chest_raffle) do if random() <= prototype.chance then - chest.insert({name = name, count = random(prototype.min, prototype.max)}) + insert({name = name, count = random(prototype.min, prototype.max)}) end end end) @@ -156,7 +159,7 @@ function ArtefactHunting.register(config) ScoreTable.add('Collected coins', count) end - Game.print_player_floating_text(player_index, text, {r = 255, g = 215, b = 0}) + Game.print_player_floating_text(player_index, text, coin_color) end ScoreTable.reset('Collected coins') @@ -166,7 +169,6 @@ function ArtefactHunting.register(config) Event.add(defines.events.on_entity_died, function (event) local entity = event.entity local force = entity.force - if force.name ~= 'enemy' or random() > alien_coin_drop_chance then return end diff --git a/map_gen/Diggy/Feature/DiggyCaveCollapse.lua b/map_gen/Diggy/Feature/DiggyCaveCollapse.lua index 080dbbd3..b843a0b2 100644 --- a/map_gen/Diggy/Feature/DiggyCaveCollapse.lua +++ b/map_gen/Diggy/Feature/DiggyCaveCollapse.lua @@ -350,13 +350,14 @@ function DiggyCaveCollapse.register(cfg) Event.add(defines.events.on_surface_created, on_surface_created) Event.add(defines.events.on_marked_for_deconstruction, function (event) - local name = event.entity.name + local entity = event.entity + local name = entity.name if name == 'sand-rock-big' or name == 'rock-huge' then return end if name == 'deconstructible-tile-proxy' or nil ~= support_beam_entities[name] then - event.entity.cancel_deconstruction(Game.get_player_by_index(event.player_index).force) + entity.cancel_deconstruction(Game.get_player_by_index(event.player_index).force) end end) diff --git a/map_gen/Diggy/Feature/DiggyHole.lua b/map_gen/Diggy/Feature/DiggyHole.lua index 3459bb5a..fae20bc9 100644 --- a/map_gen/Diggy/Feature/DiggyHole.lua +++ b/map_gen/Diggy/Feature/DiggyHole.lua @@ -59,12 +59,13 @@ local function diggy_hole(entity) local out_of_map_found = Scanner.scan_around_position(surface, position, 'out-of-map'); - for _, void_position in ipairs(out_of_map_found) do - insert(tiles, {name = 'dirt-' .. random(1, 7), position = void_position }) + for i = #out_of_map_found, 1, -1 do + local void_position = out_of_map_found[i] + tiles[i] = {name = 'dirt-' .. random(1, 7), position = void_position} if random() < 0.35 then - insert(rocks, {name = 'rock-huge', position = void_position }) + rocks[i] = {name = 'rock-huge', position = void_position} else - insert(rocks, {name = 'sand-rock-big', position = void_position }) + rocks[i] = {name = 'sand-rock-big', position = void_position} end end @@ -100,7 +101,7 @@ end function DiggyHole.register(config) robot_mining.damage = config.robot_initial_mining_damage ScoreTable.set('Robot mining damage', robot_mining.damage) - ScoreTable.reset('Void removed') + ScoreTable.reset('Mine size') Event.add(defines.events.on_entity_died, function (event) local entity = event.entity @@ -184,7 +185,7 @@ function DiggyHole.register(config) end) Event.add(Template.events.on_void_removed, function () - ScoreTable.increment('Void removed') + ScoreTable.increment('Mine size') end) Event.add(defines.events.on_research_finished, function (event) diff --git a/map_gen/Diggy/Feature/Experience.lua b/map_gen/Diggy/Feature/Experience.lua index 1206a19d..7f311774 100644 --- a/map_gen/Diggy/Feature/Experience.lua +++ b/map_gen/Diggy/Feature/Experience.lua @@ -14,9 +14,6 @@ local floor = math.floor local log = math.log local insert = table.insert --- hack -local alien_coin_modifiers = require 'map_gen.Diggy.Config'.features.ArtefactHunting.alien_coin_modifiers - -- this local Experience = {} @@ -85,7 +82,7 @@ end) function Experience.update_market_contents(force) local current_level = ForceControl.get_force_data(force).current_level local force_name = force.name - for _, prototype in ipairs(config.unlockables) do + for _, prototype in pairs(config.unlockables) do if (current_level >= prototype.level) then Retailer.set_item(force_name, prototype.name, {coin = prototype.price}) end @@ -244,7 +241,7 @@ local function on_entity_died (event) local exp if force and force.name == 'player' then if cause and (cause.name == 'artillery-turret' or cause.name == 'gun-turret' or cause.name == 'laser-turret' or cause.name == 'flamethrower-turret') then - exp = config.XP['enemy_killed'] * alien_coin_modifiers[entity.name] + exp = config.XP['enemy_killed'] * config.alien_experience_modifiers[entity.name] local text = string_format('+ %d XP', exp) Game.print_floating_text(cause.surface, cause.position, text, gain_xp_color) ForceControl.add_experience(force, exp) @@ -271,7 +268,7 @@ local function on_entity_died (event) if entity.force.name ~= 'enemy' then return end - local exp = config.XP['enemy_killed'] * alien_coin_modifiers[entity.name] + local exp = config.XP['enemy_killed'] * config.alien_experience_modifiers[entity.name] local text = string_format('+ %d XP', exp) local player_index = cause.player.index Game.print_player_floating_text_position(player_index, text, gain_xp_color,-1, -0.5) @@ -324,7 +321,7 @@ local function redraw_heading(data, header) Gui.clear(frame) local heading_table = frame.add({type = 'table', column_count = 2}) - apply_heading_style(heading_table.add({ type = 'label', caption = 'Requirement'}).style, 100) + apply_heading_style(heading_table.add({type = 'label', caption = 'Requirement'}).style, 100) apply_heading_style(heading_table.add({type = 'label', caption = header_caption}).style, 220) end @@ -349,7 +346,7 @@ local function redraw_table(data) local last_level = 0 local current_force_level = force_control.get_force_data('player').current_level - for _, prototype in ipairs(config.unlockables) do + for _, prototype in pairs(config.unlockables) do local current_item_level = prototype.level local first_item_for_level = current_item_level ~= last_level local color @@ -417,7 +414,7 @@ local function redraw_buff(data) buff_caption = format('+ %d %s', effect_value, name) end - local buffs_label = list.add({ type = 'label', caption = buff_caption}) + local buffs_label = list.add({type = 'label', caption = buff_caption}) buffs_label.style.minimal_width = 220 buffs_label.style.font_color = unlocked_color end @@ -441,10 +438,10 @@ local function toggle(event) frame = left.add({name = 'Diggy.Experience.Frame', type = 'frame', direction = 'vertical'}) - local experience_progressbars = frame.add({ type = 'flow', direction = 'vertical'}) + local experience_progressbars = frame.add({type = 'flow', direction = 'vertical'}) local experience_list_heading = frame.add({type = 'flow', direction = 'horizontal'}) - local experience_scroll_pane = frame.add({ type = 'scroll-pane'}) + local experience_scroll_pane = frame.add({type = 'scroll-pane'}) experience_scroll_pane.style.maximal_height = 300 local buff_list_heading = frame.add({type = 'flow', direction = 'horizontal'}) @@ -487,7 +484,9 @@ end) ---Updates the experience progress gui for every player that has it open local function update_gui() - for _, p in ipairs(game.connected_players) do + local players = game.connected_players + for i = #players, 1, -1 do + local p = players[i] local frame = p.gui.left['Diggy.Experience.Frame'] if frame and frame.valid then diff --git a/map_gen/Diggy/Feature/RefreshMap.lua b/map_gen/Diggy/Feature/RefreshMap.lua index 51822d14..facd9606 100644 --- a/map_gen/Diggy/Feature/RefreshMap.lua +++ b/map_gen/Diggy/Feature/RefreshMap.lua @@ -4,7 +4,6 @@ -- dependencies local Event = require 'utils.event' -local insert = table.insert -- this local RefreshMap = {} @@ -16,20 +15,26 @@ function RefreshMap.register(config) Event.add(defines.events.on_chunk_generated, function (event) local tiles = {} + local left_top = event.area.left_top + local left_top_x = left_top.x + local left_top_y = left_top.y + + local count = 0 for x = 0, 31, 1 do for y = 0, 31, 1 do - local target_x = event.area.left_top.x + x - local target_y = event.area.left_top.y + y + local target_x = left_top_x + x + local target_y = left_top_y + y local tile = 'out-of-map' - if (target_x < 1 and target_y < 1 and target_x > -2 and target_y > -2) then + if target_x > -2 and target_x < 1 and target_y > -2 and target_y < 1 then tile = 'lab-dark-1' end - insert(tiles, { + count = count + 1 + tiles[count] = { name = tile, position = {x = target_x, y = target_y} - }) + } end end diff --git a/map_gen/Diggy/Feature/ScatteredResources.lua b/map_gen/Diggy/Feature/ScatteredResources.lua index 202fe801..61c2918b 100644 --- a/map_gen/Diggy/Feature/ScatteredResources.lua +++ b/map_gen/Diggy/Feature/ScatteredResources.lua @@ -11,7 +11,6 @@ local Simplex = require 'map_gen.shared.simplex_noise' local random = math.random local sqrt = math.sqrt local ceil = math.ceil -local floor = math.floor -- this local ScatteredResources = {} @@ -44,7 +43,7 @@ function ScatteredResources.register(config) local function seeded_noise(surface, x, y, index, sources) base_seed = base_seed or surface.map_gen_settings.seed + surface.index + 4000 local noise = 0 - for _, settings in ipairs(sources) do + for _, settings in pairs(sources) do settings.type = settings.type or 'perlin' settings.offset = settings.offset or 0 if settings.type == 'zero' then @@ -101,7 +100,7 @@ function ScatteredResources.register(config) error('ore_pattern invalid') end local c_count = 0 - for _, cluster in ipairs(c_clusters) do + for _, cluster in pairs(c_clusters) do c_count = c_count + 1 cluster.weights_sum = 0 -- ensure the cluster colors are valid otherwise it fails silently @@ -154,7 +153,7 @@ function ScatteredResources.register(config) local distance = config.distance(x, y) if c_mode then - for index,cluster in ipairs(c_clusters) do + for index,cluster in pairs(c_clusters) do if distance >= cluster.min_distance and cluster.noise_settings.type ~= 'skip' then if cluster.noise_settings.type == "connected_tendril" then local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources) @@ -224,7 +223,7 @@ function ScatteredResources.register(config) for x = area.left_top.x, area.left_top.x + 31 do for y = area.left_top.y, area.left_top.y + 31 do - for index,cluster in ipairs(c_clusters) do + for index,cluster in pairs(c_clusters) do if cluster.noise_settings.type == "connected_tendril" then local noise = seeded_noise(surface, x, y, index, cluster.noise_settings.sources) if -1 * cluster.noise_settings.threshold < noise and noise < cluster.noise_settings.threshold then diff --git a/map_gen/Diggy/Feature/SetupPlayer.lua b/map_gen/Diggy/Feature/SetupPlayer.lua index a57a11a4..e085bf22 100644 --- a/map_gen/Diggy/Feature/SetupPlayer.lua +++ b/map_gen/Diggy/Feature/SetupPlayer.lua @@ -25,7 +25,7 @@ function SetupPlayer.register(config) local position = {0, 0} local surface = player.surface - for _, item in ipairs(config.starting_items) do + for _, item in pairs(config.starting_items) do player_insert(item) end @@ -50,7 +50,7 @@ function SetupPlayer.register(config) force.research_all_technologies() end - for _, item in ipairs(cheats.starting_items) do + for _, item in pairs(cheats.starting_items) do player_insert(item) end end) diff --git a/map_gen/Diggy/Feature/SimpleRoomGenerator.lua b/map_gen/Diggy/Feature/SimpleRoomGenerator.lua index a6431ac8..637b2dad 100644 --- a/map_gen/Diggy/Feature/SimpleRoomGenerator.lua +++ b/map_gen/Diggy/Feature/SimpleRoomGenerator.lua @@ -18,16 +18,20 @@ local do_spawn_tile = Token.register(function(params) Template.insert(params.surface, {params.tile}, {}) end) +local rocks_lookup = {'sand-rock-big', 'rock-huge'} + local do_mine = Token.register(function(params) local surface = params.surface local position = params.position - local rocks = surface.find_entities_filtered({ position = position, name = { 'sand-rock-big', 'rock-huge'}}) + local rocks = surface.find_entities_filtered({position = position, name = rocks_lookup}) - if (0 == #rocks) then + local rock_count = #rocks + if rock_count == 0 then return end - for _, rock in pairs(rocks) do + for i = rock_count, 1, -1 do + local rock = rocks[i] raise_event(defines.events.on_entity_died, {entity = rock}) rock.destroy() end @@ -38,7 +42,7 @@ local function handle_noise(name, surface, position) if ('water' == name) then -- water is slower because for some odd reason it doesn't always want to mine it properly - Task.set_timeout_in_ticks(4, do_spawn_tile, { surface = surface, tile = { name = 'deepwater-green', position = position}}) + Task.set_timeout_in_ticks(4, do_spawn_tile, { surface = surface, tile = {name = 'deepwater-green', position = position}}) return end From 67616ad330c5a90b9c0372892ea2eb85582eea54 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 26 Nov 2018 22:07:53 +0100 Subject: [PATCH 08/10] Improved scanner performance --- map_gen/Diggy/Feature/DiggyHole.lua | 42 +++++++++++++++++++++-------- map_gen/Diggy/Scanner.lua | 42 ----------------------------- 2 files changed, 31 insertions(+), 53 deletions(-) delete mode 100644 map_gen/Diggy/Scanner.lua diff --git a/map_gen/Diggy/Feature/DiggyHole.lua b/map_gen/Diggy/Feature/DiggyHole.lua index fae20bc9..7d86c726 100644 --- a/map_gen/Diggy/Feature/DiggyHole.lua +++ b/map_gen/Diggy/Feature/DiggyHole.lua @@ -6,12 +6,10 @@ -- dependencies local Event = require 'utils.event' local Global = require 'utils.global' -local Scanner = require 'map_gen.Diggy.Scanner' local Template = require 'map_gen.Diggy.Template' local ScoreTable = require 'map_gen.Diggy.ScoreTable' local Debug = require 'map_gen.Diggy.Debug' local CreateParticles = require 'features.create_particles' -local insert = table.insert local random = math.random local raise_event = script.raise_event @@ -56,8 +54,30 @@ local function diggy_hole(entity) local rocks = {} local surface = entity.surface local position = entity.position + local x = position.x + local y = position.y + local get_tile = surface.get_tile + local out_of_map_found = {} + local count = 0 - local out_of_map_found = Scanner.scan_around_position(surface, position, 'out-of-map'); + if (get_tile(x, y - 1).name == 'out-of-map') then + count = count + 1 + out_of_map_found[count] = {x = x, y = y - 1} + end + + if (get_tile(x + 1, y).name == 'out-of-map') then + count = count + 1 + out_of_map_found[count] = {x = x + 1, y = y} + end + + if (get_tile(x, y + 1).name == 'out-of-map') then + count = count + 1 + out_of_map_found[count] = {x = x, y = y + 1} + end + + if (get_tile(x - 1, y).name == 'out-of-map') then + out_of_map_found[count + 1] = {x = x - 1, y = y} + end for i = #out_of_map_found, 1, -1 do local void_position = out_of_map_found[i] @@ -85,10 +105,11 @@ local artificial_tiles = { local function on_mined_tile(surface, tiles) local new_tiles = {} - + local count = 0 for _, tile in pairs(tiles) do if (artificial_tiles[tile.old_tile.name]) then - insert(new_tiles, { name = 'dirt-' .. random(1, 7), position = tile.position}) + count = count + 1 + new_tiles[count] = {name = 'dirt-' .. random(1, 7), position = tile.position} end end @@ -219,17 +240,16 @@ function DiggyHole.register(config) local height = tonumber(params[4]) local surface_index = params[5] local tiles = {} - local entities = {} - + local count = 0 for x = 0, width do for y = 0, height do - insert(tiles, {name = 'dirt-' .. random(1, 7), position = {x = x + left_top_x, y = y + left_top_y}}) + count = count + 1 + tiles[count] = {name = 'dirt-' .. random(1, 7), position = {x = x + left_top_x, y = y + left_top_y}} end end - Template.insert(game.surfaces[surface_index], tiles, entities) - end - ) + Template.insert(game.surfaces[surface_index], tiles, {}) + end) end end diff --git a/map_gen/Diggy/Scanner.lua b/map_gen/Diggy/Scanner.lua deleted file mode 100644 index 40fa2a93..00000000 --- a/map_gen/Diggy/Scanner.lua +++ /dev/null @@ -1,42 +0,0 @@ --- dependencies -local insert = table.insert - --- this -local Scanner = {} - ---[[-- - returns a list with all direct positions that contain tile_search. - - @param surface LuaSurface - @param position Position - @param tile_search string name of the tile to search for - @return table with 0~4 directions of which have the tile searched for adjacent -]] -function Scanner.scan_around_position(surface, position, tile_search) - local tile_found = {} - local get_tile = surface.get_tile - - -- north - if (tile_search == get_tile(position.x, position.y - 1).name) then - insert(tile_found, {x = position.x, y = position.y - 1}) - end - - -- east - if (tile_search == get_tile(position.x + 1, position.y).name) then - insert(tile_found, {x = position.x + 1, y = position.y}) - end - - -- south - if (tile_search == get_tile(position.x, position.y + 1).name) then - insert(tile_found, {x = position.x, y = position.y + 1}) - end - - -- west - if (tile_search == get_tile(position.x - 1, position.y).name) then - insert(tile_found, {x = position.x - 1, y = position.y}) - end - - return tile_found; -end - -return Scanner From d4e1890445bc5bf9ff3a7342d092b081054311d3 Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 27 Nov 2018 20:48:05 +0100 Subject: [PATCH 09/10] Slimmed down enemy killed comments --- map_gen/Diggy/Config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map_gen/Diggy/Config.lua b/map_gen/Diggy/Config.lua index 14ea32cd..9c304d95 100644 --- a/map_gen/Diggy/Config.lua +++ b/map_gen/Diggy/Config.lua @@ -371,7 +371,7 @@ local Config = { ['production-science-pack'] = 25, ['high-tech-science-pack'] = 50, ['space-science-pack'] = 10, - ['enemy_killed'] = 10, -- Base XP for killing biters and spitters. This value is multiplied by the alien_coin_modifiers from ArtefactHunting + ['enemy_killed'] = 10, -- Base XP for killing biters and spitters. ['death-penalty'] = 0.002, -- XP deduct in percentage of total experience when a player dies (Diggy default: 0.002 which equals 0.2%) }, From ccab45a8a64a891b1339471c962b1d32e1afefe5 Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 27 Nov 2018 21:10:08 +0100 Subject: [PATCH 10/10] Fixed the cause --- map_gen/Diggy/Feature/DiggyCaveCollapse.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/map_gen/Diggy/Feature/DiggyCaveCollapse.lua b/map_gen/Diggy/Feature/DiggyCaveCollapse.lua index b843a0b2..3a4bfa73 100644 --- a/map_gen/Diggy/Feature/DiggyCaveCollapse.lua +++ b/map_gen/Diggy/Feature/DiggyCaveCollapse.lua @@ -124,7 +124,6 @@ local function collapse(args) local surface = args.surface local positions = {} local strength = config.collapse_threshold_total_strength - local player_index = args.player_index create_collapse_alert(surface, position) mask_disc_blur( position.x, position.y, @@ -240,12 +239,13 @@ local function on_mined_entity(event) end end +local no_player_cause = {index = 0} local function on_entity_died(event) local entity = event.entity local name = entity.name local strength = support_beam_entities[name] if strength then - local cause = event.cause or {} + local cause = event.cause or no_player_cause stress_map_add(entity.surface, entity.position, strength, false, (not (name == "sand-rock-big" or name == "rock-huge")) and cause.index) end end