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

Migrate diggy DO to use DO modules

This commit is contained in:
RedRafe 2024-12-02 14:27:57 +01:00
parent 93c36fe9bf
commit 30d7e924ab
3 changed files with 45 additions and 123 deletions

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

@ -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)