1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Merge pull request #1465 from RedRafe/updates/diggy_20

Update Diggy scenario
This commit is contained in:
grilledham 2024-12-02 19:06:38 +00:00 committed by GitHub
commit 0b09adf7e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 70 additions and 132 deletions

View File

@ -61,7 +61,7 @@ local function get_valid_force(lua_force_or_name)
return force
end
if type(lua_force_or_name) ~= 'table' or not lua_force_or_name.valid then
if type(lua_force_or_name) ~= 'userdata' or not lua_force_or_name.valid then
return
end

View File

@ -16,7 +16,9 @@ Global.register(
end
)
return function(config)
local Public = {}
Public.register = function(config)
local entity_name = config.entity_name or 'coal'
Event.add(
defines.events.on_entity_died,
@ -100,3 +102,5 @@ return function(config)
end
)
end
return Public

View File

@ -6,7 +6,9 @@ local function starts_with(str, pattern)
return str:sub(1, #pattern) == pattern
end
return function(config)
local Public = {}
Public.register = function(config)
if config.replace then
Event.add(defines.events.on_research_finished, function(event)
local tech = event.research
@ -51,3 +53,5 @@ return function(config)
end)
end
end
return Public

View File

@ -42,9 +42,9 @@ Config.reactor_meltdown.enabled = false
local allowed_entities = require 'map_gen.maps.danger_ores.modules.allowed_entities'.register
local concrete_on_landfill = require 'map_gen.maps.danger_ores.modules.concrete_on_landfill'
local container_dump = require 'map_gen.maps.danger_ores.modules.container_dump'
local container_dump = require 'map_gen.maps.danger_ores.modules.container_dump'.register
local map_builder = require 'map_gen.maps.danger_ores.modules.map'
local mining_productivity = require 'map_gen.maps.danger_ores.modules.mining_productivity'
local mining_productivity = require 'map_gen.maps.danger_ores.modules.mining_productivity'.register
local restart_command = require 'map_gen.maps.danger_ores.modules.restart_command'
local rocket_launched = require 'map_gen.maps.danger_ores.modules.rocket_launched_simple'
local technologies = require 'map_gen.maps.danger_ores.modules.technologies'

View File

@ -1,69 +0,0 @@
-- This module prevents all but the allowed items from being built on top of resources
local RestrictEntities = require 'map_gen.shared.entity_placement_restriction'
local Event = require 'utils.event'
local Token = require 'utils.token'
local ScenarioInfo = require 'features.gui.info'
local Global = require 'utils.global'
local DangerOre = {}
local last_warning_time = {}
Global.register({
last_warning_time = last_warning_time,
}, function(tbl)
last_warning_time = tbl.last_warning_time
end)
local function banned_entities(allowed_entities, warning_timeout)
--- Items explicitly allowed on ores
RestrictEntities.add_allowed(allowed_entities)
--- The logic for checking that there are resources under the entity's position
RestrictEntities.set_keep_alive_callback(
Token.register(
function(entity)
-- Some entities have a bounding_box area of zero, eg robots.
local area = entity.bounding_box
local left_top, right_bottom = area.left_top, area.right_bottom
if left_top.x == right_bottom.x and left_top.y == right_bottom.y then
return true
end
local count = entity.surface.count_entities_filtered {area = area, name = {'coal', 'copper-ore', 'iron-ore', 'stone', 'uranium-ore'}, limit = 1}
if count == 0 then
return true
end
end
)
)
--- Warning for players when their entities are destroyed
--- Note: Edit to limit warning once per minute per player produced with help from ChatGPT & grilledham
local function on_destroy(event)
local p = event.player
local current_time = game.tick
if p and p.valid then
if not last_warning_time[p.index] then
last_warning_time[p.index] = -(warning_timeout + 1)
end
if current_time > last_warning_time[p.index] + warning_timeout then
last_warning_time[p.index] = current_time
p.print('You cannot build that on top of ores, only belts, mining drills, and power poles are allowed.')
end
end
end
Event.add(RestrictEntities.events.on_restricted_entity_destroyed, on_destroy)
end
function DangerOre.register (config)
local allowed_entities = config.allowed_entities
local warning_timeout = config.warning_timeout
banned_entities(allowed_entities, warning_timeout)
ScenarioInfo.add_map_extra_info([[Danger! Ores are generally unstable to build upon.
Only the following entities have been strengthened for building upon the ores:
[item=burner-mining-drill] [item=electric-mining-drill] [item=pumpjack] [item=small-electric-pole] [item=medium-electric-pole] [item=big-electric-pole] [item=substation] [item=car] [item=tank] [item=spidertron]
[item=stone-wall][item=small-lamp][item=transport-belt] [item=fast-transport-belt] [item=express-transport-belt] [item=underground-belt] [item=fast-underground-belt] [item=express-underground-belt] [item=pipe] [item=pipe-to-ground]
]])
end
return DangerOre

View File

@ -178,6 +178,7 @@ local function collapse(args)
create_collapse_alert(surface, position)
template_insert(surface, {}, {{ name = 'big-explosion', position = position }})
template_insert(surface, {}, create_collapse_template(positions, surface))
raise_event(DiggyCaveCollapse.events.on_collapse, args)

View File

@ -316,7 +316,7 @@ local function on_entity_died(event)
end
local exp = config.XP['enemy_killed'] * (config.alien_experience_modifiers[entity.name] or 1)
cause.player.create_local_flying_text { text = {'', '[img=entity/' .. entity_name .. '] ', {'diggy.float_xp_gained_kill', exp}}, color = gain_xp_color }
cause.player.create_local_flying_text { position = cause.player.position, text = {'', '[img=entity/' .. entity_name .. '] ', {'diggy.float_xp_gained_kill', exp}}, color = gain_xp_color }
add_experience(force, exp)
end
@ -327,7 +327,7 @@ local function on_player_respawned(event)
local exp = remove_experience_percentage(player.force, config.XP['death-penalty'], 50)
local text = {'', '[img=entity.character]', {'diggy.float_xp_drain', exp}}
game.print({'diggy.player_drained_xp', player.name, exp}, {color = lose_xp_color})
Game.create_local_flying_text { text = text, color = lose_xp_color, create_at_cursor = true }
Game.create_local_flying_text { surface = player.surface, text = text, color = lose_xp_color, create_at_cursor = true }
ScoreTracker.change_for_global(experience_lost_name, exp)
end

View File

@ -51,7 +51,7 @@ function NightTime.on_init()
local surface = RS.get_surface()
surface.daytime = 0.5
surface.freeze_daytime = 1
surface.freeze_daytime = true
end
return NightTime

View File

@ -446,39 +446,34 @@ local config = {
enabled = true,
load = function() return require('map_gen.maps.diggy.feature.weapon_balance') end
},
danger_ore = {
allowed_entities = {
enabled = true,
load = function() return require('map_gen.maps.diggy.feature.danger_ore') end,
allowed_entities = {
'transport-belt',
'fast-transport-belt',
'express-transport-belt',
'underground-belt',
'fast-underground-belt',
'express-underground-belt',
'small-electric-pole',
'medium-electric-pole',
'big-electric-pole',
'substation',
'electric-mining-drill',
'burner-mining-drill',
'pumpjack',
'car',
'tank',
'spidertron',
'stone-wall',
'small-lamp',
'pipe',
'pipe-to-ground',
'wooden-chest'
},
warning_timeout = 60 * 60 -- In game ticks -> 1 minute
}
refund = true,
load = function() return require 'map_gen.maps.danger_ores.modules.allowed_entities' end,
types = require 'map_gen.maps.danger_ores.config.vanilla_allowed_entities',
allowed_entities = { ['stone-wall'] = true },
banned_entities = {},
},
container_dump = {
enabled = true,
load = function() return require 'map_gen.maps.danger_ores.modules.container_dump' end,
entity_name = 'coal',
},
disable_mining_productivity = {
enabled = true,
load = function() return require 'map_gen.maps.danger_ores.modules.mining_productivity' end,
replace = true, -- replace mining productivity with robot cargo capacity
},
}
}
ScenarioInfo.set_map_name('Diggy Danger Ores')
ScenarioInfo.set_map_description('Dig your way through!')
ScenarioInfo.add_map_extra_info([[Danger! Ores are generally unstable to build upon.
Only the following entities have been strengthened for building upon the ores:
[item=burner-mining-drill] [item=electric-mining-drill] [item=pumpjack] [item=small-electric-pole] [item=medium-electric-pole] [item=big-electric-pole] [item=substation] [item=car] [item=tank] [item=spidertron] [item=stone-wall]
[item=stone-wall][item=small-lamp][item=transport-belt] [item=fast-transport-belt] [item=express-transport-belt] [item=underground-belt] [item=fast-underground-belt] [item=express-underground-belt] [item=pipe] [item=pipe-to-ground]
]])
local diggy = require 'map_gen.maps.diggy.scenario'
return diggy.register(config)

View File

@ -446,33 +446,24 @@ local config = {
enabled = true,
load = function() return require('map_gen.maps.diggy.feature.weapon_balance') end
},
danger_ore = {
enabled = true,
load = function() return require('map_gen.maps.diggy.feature.danger_ore') end,
allowed_entities = {
'transport-belt',
'fast-transport-belt',
'express-transport-belt',
'underground-belt',
'fast-underground-belt',
'express-underground-belt',
'small-electric-pole',
'medium-electric-pole',
'big-electric-pole',
'substation',
'electric-mining-drill',
'burner-mining-drill',
'pumpjack',
'car',
'tank',
'spidertron',
'stone-wall',
'small-lamp',
'pipe',
'pipe-to-ground',
'wooden-chest'
}
},
allowed_entities = {
enabled = true,
refund = true,
load = function() return require 'map_gen.maps.danger_ores.modules.allowed_entities' end,
types = require 'map_gen.maps.danger_ores.config.vanilla_allowed_entities',
allowed_entities = { ['stone-wall'] = true },
banned_entities = {},
},
container_dump = {
enabled = true,
load = function() return require 'map_gen.maps.danger_ores.modules.container_dump' end,
entity_name = 'coal',
},
disable_mining_productivity = {
enabled = true,
load = function() return require 'map_gen.maps.danger_ores.modules.mining_productivity' end,
replace = true, -- replace mining productivity with robot cargo capacity
},
belts_n_bullets = {
enabled = true,
load = function () return require('map_gen.maps.diggy.feature.belts_n_bullets') end,
@ -502,6 +493,11 @@ local config = {
ScenarioInfo.set_map_name('Diggy Danger Ores BnB')
ScenarioInfo.set_map_description('Dig your way through!')
ScenarioInfo.add_map_extra_info([[Danger! Ores are generally unstable to build upon.
Only the following entities have been strengthened for building upon the ores:
[item=burner-mining-drill] [item=electric-mining-drill] [item=pumpjack] [item=small-electric-pole] [item=medium-electric-pole] [item=big-electric-pole] [item=substation] [item=car] [item=tank] [item=spidertron] [item=stone-wall]
[item=stone-wall][item=small-lamp][item=transport-belt] [item=fast-transport-belt] [item=express-transport-belt] [item=underground-belt] [item=fast-underground-belt] [item=express-underground-belt] [item=pipe] [item=pipe-to-ground]
]])
local diggy = require 'map_gen.maps.diggy.scenario'
return diggy.register(config)

View File

@ -45,7 +45,14 @@ end
---@param params table
---@field surface LuaSurfaceIdentification will create the text only for those on the same surface
function Game.create_local_flying_text(params)
local surface = game.get_surface(params.surface.name or params.surface.index or params.surface)
local surface_id = params.surface
if type(surface_id) == 'userdata' then
surface_id = surface_id.name or surface_id.index
end
if not surface_id then
return
end
local surface = game.get_surface(surface_id)
if not surface then
return
end