mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-11 14:49:24 +02:00
map junkyard wip
This commit is contained in:
parent
269890e22e
commit
cf905aba04
@ -1,2 +1,3 @@
|
||||
require "commands.misc"
|
||||
require "commands.decoratives"
|
||||
require "commands.decoratives"
|
||||
require "commands.effects"
|
43
commands/effects.lua
Normal file
43
commands/effects.lua
Normal file
@ -0,0 +1,43 @@
|
||||
local event = require 'utils.event'
|
||||
|
||||
local function spin(player)
|
||||
local d = player.character.direction
|
||||
d = d + 1
|
||||
if d > 7 then d = 0 end
|
||||
player.character.direction = d
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
commands.add_command("spin", "spins you",
|
||||
function(args)
|
||||
local player = game.players[args.player_index]
|
||||
|
||||
--if not args.parameter then player.print("Please add a player name.") return end
|
||||
local c = 25
|
||||
for t = 0, 600, 1 do
|
||||
if t % math.ceil(c) == 0 then
|
||||
local trigger_tick = game.tick + t
|
||||
if not global.on_tick_schedule[trigger_tick] then global.on_tick_schedule[trigger_tick] = {} end
|
||||
table.insert(global.on_tick_schedule[trigger_tick], {func = spin, args = {player}})
|
||||
|
||||
c = c - c * 0.05
|
||||
if c < 1 then c = 1 end
|
||||
end
|
||||
end
|
||||
|
||||
local c = 1
|
||||
for t = 600, 1200, 1 do
|
||||
if t % math.ceil(c) == 0 then
|
||||
local trigger_tick = game.tick + t
|
||||
if not global.on_tick_schedule[trigger_tick] then global.on_tick_schedule[trigger_tick] = {} end
|
||||
table.insert(global.on_tick_schedule[trigger_tick], {func = spin, args = {player}})
|
||||
|
||||
c = c + c * 0.05
|
||||
if c > 25 then c = 25 end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
@ -37,6 +37,7 @@ require "on_tick_schedule"
|
||||
--require "maps.biter_battles"
|
||||
--require "maps.cave_miner"
|
||||
--require "maps.labyrinth"
|
||||
require "maps.junkyard"
|
||||
--require "maps.spooky_forest"
|
||||
--require "maps.nightfall"
|
||||
--require "maps.atoll"
|
||||
|
@ -1223,7 +1223,7 @@ local function on_chunk_generated(event)
|
||||
end
|
||||
end
|
||||
|
||||
if left_top.x < -1024 then
|
||||
if left_top.x < -2048 then
|
||||
spawn_obstacles(left_top, surface)
|
||||
end
|
||||
|
||||
|
263
maps/junkyard.lua
Normal file
263
maps/junkyard.lua
Normal file
@ -0,0 +1,263 @@
|
||||
--junkyard-- mewmew made this --
|
||||
|
||||
require "maps.modules.dynamic_landfill"
|
||||
require "maps.modules.satellite_score"
|
||||
require "maps.modules.spawners_contain_biters"
|
||||
require "maps.modules.splice_double"
|
||||
require "maps.modules.biter_player_count_difficulty"
|
||||
require "maps.modules.mineable_wreckage_yields_scrap"
|
||||
|
||||
local simplex_noise = require 'utils.simplex_noise'
|
||||
simplex_noise = simplex_noise.d2
|
||||
local event = require 'utils.event'
|
||||
local table_insert = table.insert
|
||||
local math_random = math.random
|
||||
local map_functions = require "maps.tools.map_functions"
|
||||
|
||||
local function get_noise(name, pos)
|
||||
local seed = game.surfaces[1].map_gen_settings.seed
|
||||
local noise_seed_add = 25000
|
||||
seed = seed + noise_seed_add
|
||||
if name == 1 then
|
||||
local noise = {}
|
||||
noise[1] = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[3] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
|
||||
seed = seed + noise_seed_add
|
||||
noise[4] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
|
||||
local noise = noise[1] + noise[2] * 0.3 + noise[3] * 0.2 + noise[4] * 0.1
|
||||
--noise = noise * 0.5
|
||||
return noise
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if not global.map_init_done then
|
||||
game.surfaces["nauvis"].ticks_per_day = game.surfaces["nauvis"].ticks_per_day * 2
|
||||
game.surfaces["nauvis"].freeze_daytime = true
|
||||
global.map_init_done = true
|
||||
end
|
||||
|
||||
if player.online_time == 0 then
|
||||
--player.insert{name = 'iron-plate', count = 32}
|
||||
--player.insert{name = 'iron-gear-wheel', count = 16}
|
||||
end
|
||||
end
|
||||
|
||||
local tile_replacements = {
|
||||
["grass-1"] = "dirt-7",
|
||||
["grass-2"] = "dirt-6",
|
||||
["grass-3"] = "dirt-5",
|
||||
["grass-4"] = "dirt-4" ,
|
||||
["water"] = "water-green",
|
||||
["deepwater"] = "deepwater-green",
|
||||
["sand-1"] = "dirt-7",
|
||||
["sand-2"] = "dirt-6",
|
||||
["sand-3"] = "dirt-5"
|
||||
}
|
||||
|
||||
local entity_replacements = {
|
||||
["tree-01"] = "dead-dry-hairy-tree",
|
||||
["tree-02"] = "tree-06-brown",
|
||||
["tree-03"] = "dead-grey-trunk",
|
||||
["tree-04"] = "dry-hairy-tree",
|
||||
["tree-05"] = "dry-tree",
|
||||
["tree-06"] = "tree-06-brown",
|
||||
["tree-07"] = "dry-tree",
|
||||
["tree-08"] = "tree-08-brown",
|
||||
["tree-09"] = "tree-06-brown",
|
||||
["tree-02-red"] = "dry-tree",
|
||||
--["tree-06-brown"] = "dirt",
|
||||
--["tree-08-brown"] = "dirt",
|
||||
["tree-09-brown"] = "tree-06-brown",
|
||||
["tree-09-red"] = "tree-06-brown",
|
||||
["iron-ore"] = "mineable-wreckage",
|
||||
["copper-ore"] = "mineable-wreckage",
|
||||
["coal"] = "mineable-wreckage",
|
||||
["stone"] = "mineable-wreckage"
|
||||
}
|
||||
|
||||
local wrecks = {"big-ship-wreck-1", "big-ship-wreck-2", "big-ship-wreck-3"}
|
||||
local function create_shipwreck(surface, position)
|
||||
local raffle = {}
|
||||
local loot = {
|
||||
|
||||
{{name = "iron-gear-wheel", count = math_random(80,100)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
|
||||
{{name = "copper-cable", count = math_random(100,200)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
|
||||
{{name = "engine-unit", count = math_random(16,32)}, weight = 2, evolution_min = 0.1, evolution_max = 0.5},
|
||||
{{name = "electric-engine-unit", count = math_random(16,32)}, weight = 2, evolution_min = 0.4, evolution_max = 0.8},
|
||||
{{name = "battery", count = math_random(100,200)}, weight = 2, evolution_min = 0.3, evolution_max = 0.8},
|
||||
{{name = "advanced-circuit", count = math_random(100,200)}, weight = 3, evolution_min = 0.4, evolution_max = 1},
|
||||
{{name = "electronic-circuit", count = math_random(100,200)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4},
|
||||
{{name = "processing-unit", count = math_random(100,200)}, weight = 3, evolution_min = 0.7, evolution_max = 1},
|
||||
{{name = "explosives", count = math_random(25,50)}, weight = 1, evolution_min = 0.2, evolution_max = 0.6},
|
||||
{{name = "lubricant-barrel", count = math_random(4,10)}, weight = 1, evolution_min = 0.3, evolution_max = 0.5},
|
||||
{{name = "rocket-fuel", count = math_random(4,10)}, weight = 2, evolution_min = 0.3, evolution_max = 0.7},
|
||||
{{name = "computer", count = 1}, weight = 1, evolution_min = 0.2, evolution_max = 1},
|
||||
{{name = "steel-plate", count = math_random(50,100)}, weight = 2, evolution_min = 0.1, evolution_max = 0.3},
|
||||
{{name = "nuclear-fuel", count = 1}, weight = 2, evolution_min = 0.7, evolution_max = 1},
|
||||
|
||||
{{name = "burner-inserter", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1},
|
||||
{{name = "inserter", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4},
|
||||
{{name = "long-handed-inserter", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4},
|
||||
{{name = "fast-inserter", count = math_random(8,16)}, weight = 3, evolution_min = 0.1, evolution_max = 1},
|
||||
{{name = "filter-inserter", count = math_random(8,16)}, weight = 1, evolution_min = 0.2, evolution_max = 1},
|
||||
{{name = "stack-filter-inserter", count = math_random(4,8)}, weight = 1, evolution_min = 0.4, evolution_max = 1},
|
||||
{{name = "stack-inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
|
||||
{{name = "small-electric-pole", count = math_random(16,32)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
|
||||
{{name = "medium-electric-pole", count = math_random(8,16)}, weight = 3, evolution_min = 0.2, evolution_max = 1},
|
||||
{{name = "wooden-chest", count = math_random(25,50)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2},
|
||||
{{name = "iron-chest", count = math_random(4,8)}, weight = 3, evolution_min = 0.1, evolution_max = 0.4},
|
||||
{{name = "steel-chest", count = math_random(4,8)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
|
||||
{{name = "small-lamp", count = math_random(8,16)}, weight = 3, evolution_min = 0.1, evolution_max = 0.3},
|
||||
{{name = "rail", count = math_random(50,75)}, weight = 3, evolution_min = 0.1, evolution_max = 0.6},
|
||||
{{name = "assembling-machine-1", count = math_random(1,2)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
|
||||
{{name = "assembling-machine-2", count = math_random(1,2)}, weight = 3, evolution_min = 0.2, evolution_max = 0.8},
|
||||
{{name = "offshore-pump", count = 1}, weight = 2, evolution_min = 0.0, evolution_max = 0.1},
|
||||
{{name = "beacon", count = 1}, weight = 3, evolution_min = 0.7, evolution_max = 1},
|
||||
{{name = "boiler", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
|
||||
{{name = "steam-engine", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.5},
|
||||
{{name = "steam-turbine", count = math_random(1,2)}, weight = 2, evolution_min = 0.5, evolution_max = 1},
|
||||
--{{name = "nuclear-reactor", count = 1}, weight = 2, evolution_min = 0.5, evolution_max = 1},
|
||||
{{name = "centrifuge", count = math_random(1,2)}, weight = 2, evolution_min = 0.5, evolution_max = 1},
|
||||
{{name = "heat-pipe", count = math_random(8,12)}, weight = 2, evolution_min = 0.5, evolution_max = 1},
|
||||
{{name = "heat-exchanger", count = math_random(2,4)}, weight = 2, evolution_min = 0.5, evolution_max = 1},
|
||||
{{name = "arithmetic-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
|
||||
{{name = "constant-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
|
||||
{{name = "decider-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
|
||||
{{name = "power-switch", count = math_random(2,4)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
|
||||
{{name = "programmable-speaker", count = math_random(2,4)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
|
||||
{{name = "green-wire", count = math_random(50,100)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
|
||||
{{name = "red-wire", count = math_random(50,100)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
|
||||
{{name = "chemical-plant", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
|
||||
{{name = "burner-mining-drill", count = math_random(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2},
|
||||
{{name = "electric-mining-drill", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.6},
|
||||
{{name = "express-transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
|
||||
{{name = "express-underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
|
||||
{{name = "express-splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
|
||||
{{name = "fast-transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
|
||||
{{name = "fast-underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
|
||||
{{name = "fast-splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.3},
|
||||
{{name = "transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0, evolution_max = 0.3},
|
||||
{{name = "underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0, evolution_max = 0.3},
|
||||
{{name = "splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0, evolution_max = 0.3},
|
||||
{{name = "pipe", count = math_random(40,50)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
|
||||
{{name = "pipe-to-ground", count = math_random(8,16)}, weight = 1, evolution_min = 0.2, evolution_max = 0.5},
|
||||
{{name = "pumpjack", count = math_random(1,2)}, weight = 1, evolution_min = 0.3, evolution_max = 0.8},
|
||||
{{name = "pump", count = math_random(1,4)}, weight = 1, evolution_min = 0.3, evolution_max = 0.8},
|
||||
{{name = "steel-furnace", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
|
||||
{{name = "stone-furnace", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1},
|
||||
{{name = "radar", count = math_random(1,2)}, weight = 1, evolution_min = 0.1, evolution_max = 0.3},
|
||||
{{name = "rail-signal", count = math_random(8,16)}, weight = 2, evolution_min = 0.2, evolution_max = 0.8},
|
||||
{{name = "rail-chain-signal", count = math_random(8,16)}, weight = 2, evolution_min = 0.2, evolution_max = 0.8},
|
||||
{{name = "stone-wall", count = math_random(25,75)}, weight = 1, evolution_min = 0.1, evolution_max = 0.5},
|
||||
{{name = "gate", count = math_random(4,8)}, weight = 1, evolution_min = 0.1, evolution_max = 0.5},
|
||||
{{name = "storage-tank", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 0.6},
|
||||
{{name = "train-stop", count = math_random(1,2)}, weight = 1, evolution_min = 0.2, evolution_max = 0.7},
|
||||
{{name = "express-loader", count = math_random(1,2)}, weight = 1, evolution_min = 0.5, evolution_max = 1},
|
||||
{{name = "fast-loader", count = math_random(1,2)}, weight = 1, evolution_min = 0.2, evolution_max = 0.7},
|
||||
{{name = "loader", count = math_random(1,2)}, weight = 1, evolution_min = 0.0, evolution_max = 0.5},
|
||||
{{name = "lab", count = math_random(2,4)}, weight = 2, evolution_min = 0.0, evolution_max = 0.1}
|
||||
}
|
||||
|
||||
local distance_to_center = math.sqrt(position.x^2 + position.y^2)
|
||||
if distance_to_center < 1 then
|
||||
distance_to_center = 0.1
|
||||
else
|
||||
distance_to_center = distance_to_center / 5000
|
||||
end
|
||||
if distance_to_center > 1 then distance_to_center = 1 end
|
||||
|
||||
for _, t in pairs (loot) do
|
||||
for x = 1, t.weight, 1 do
|
||||
if t.evolution_min <= distance_to_center and t.evolution_max >= distance_to_center then
|
||||
table.insert(raffle, t[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
local e = surface.create_entity{name = wrecks[math_random(1,#wrecks)], position = position, force = "player"}
|
||||
for x = 1, math_random(2,3), 1 do
|
||||
local loot = raffle[math_random(1,#raffle)]
|
||||
e.insert(loot)
|
||||
end
|
||||
end
|
||||
|
||||
local function process_entity(e)
|
||||
if entity_replacements[e.name] then
|
||||
e.surface.create_entity({name = entity_replacements[e.name], position = e.position})
|
||||
e.destroy()
|
||||
return
|
||||
end
|
||||
|
||||
if e.force.name == "enemy" then
|
||||
e.destroy()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local function on_chunk_generated(event)
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
local tiles = {}
|
||||
local entities = {}
|
||||
|
||||
for _, e in pairs(surface.find_entities_filtered({area = event.area})) do
|
||||
process_entity(e)
|
||||
end
|
||||
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local tile_to_insert = false
|
||||
local pos = {x = left_top.x + x, y = left_top.y + y}
|
||||
|
||||
local tile = surface.get_tile(pos)
|
||||
if tile_replacements[tile.name] then
|
||||
table_insert(tiles, {name = tile_replacements[tile.name], position = pos})
|
||||
end
|
||||
|
||||
if not tile.collides_with("player-layer") then
|
||||
local noise = get_noise(1, pos)
|
||||
if noise > 0.5 or noise < -0.5 then
|
||||
if math_random(1,3) ~= 1 then
|
||||
surface.create_entity({name = "mineable-wreckage", position = pos})
|
||||
else
|
||||
if math_random(1,1024) == 1 then
|
||||
create_shipwreck(surface, pos)
|
||||
else
|
||||
if math_random(1,50000) == 1 then
|
||||
local e = surface.create_entity({name = "nuclear-reactor", position = pos, force = "enemy"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
|
||||
--for _, entity in pairs(entities) do
|
||||
--if surface.can_place_entity(entity) then
|
||||
--surface.create_entity(entity)
|
||||
--end
|
||||
--end
|
||||
|
||||
--if not global.spawn_generated and left_top.x <= -64 then
|
||||
--map_functions.draw_noise_tile_circle({x = 0, y = 0}, "concrete", surface, 5)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = -32, y = -32}, "copper-ore", surface, 15, 2500)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = -32, y = 32}, "iron-ore", surface, 15, 2500)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = 32, y = 32}, "coal", surface, 15, 2500)
|
||||
--map_functions.draw_smoothed_out_ore_circle({x = 32, y = -32}, "stone", surface, 15, 2500)
|
||||
--map_functions.draw_oil_circle({x = 0, y = 0}, "crude-oil", surface, 5, 200000)
|
||||
--global.spawn_generated = true
|
||||
--end
|
||||
end
|
||||
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
||||
event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
@ -1,7 +1,9 @@
|
||||
--labyrinth-- mewmew made this --
|
||||
require "maps.labyrinth_map_intro"
|
||||
require "maps.tools.teleporters"
|
||||
require "maps.tools.map_pregen"
|
||||
require "maps.modules.satellite_score"
|
||||
require "maps.modules.dynamic_landfill"
|
||||
|
||||
local map_functions = require "maps.tools.map_functions"
|
||||
local simplex_noise = require 'utils.simplex_noise'
|
||||
simplex_noise = simplex_noise.d2
|
||||
|
37
maps/modules/biter_player_count_difficulty.lua
Normal file
37
maps/modules/biter_player_count_difficulty.lua
Normal file
@ -0,0 +1,37 @@
|
||||
-- biters gain strength scaling with player amount in the game -- by mewmew
|
||||
|
||||
local event = require 'utils.event'
|
||||
|
||||
local function refresh_difficulty()
|
||||
global.connected_players = #game.connected_players
|
||||
if global.connected_players > 75 then global.connected_players = 75 end
|
||||
|
||||
local f = game.forces.enemy
|
||||
local m = #game.connected_players * 0.05
|
||||
|
||||
f.set_ammo_damage_modifier("melee", m)
|
||||
f.set_ammo_damage_modifier("biological", m * 0.5)
|
||||
f.set_ammo_damage_modifier("artillery-shell", m * 0.5)
|
||||
f.set_ammo_damage_modifier("flamethrower", m * 0.5)
|
||||
f.set_ammo_damage_modifier("laser-turret", m * 0.5)
|
||||
end
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
if not event.entity.valid then return end
|
||||
if event.entity.type ~= "unit" then return end
|
||||
if math.random(1,100) >= global.connected_players then return end
|
||||
if event.final_damage_amount > event.entity.prototype.max_health then return end
|
||||
event.entity.health = event.entity.health + event.final_damage_amount
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
refresh_difficulty()
|
||||
end
|
||||
|
||||
local function on_player_left_game(event)
|
||||
refresh_difficulty()
|
||||
end
|
||||
|
||||
event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
69
maps/modules/mineable_wreckage_yields_scrap.lua
Normal file
69
maps/modules/mineable_wreckage_yields_scrap.lua
Normal file
@ -0,0 +1,69 @@
|
||||
--destroying and mining rocks yields ore -- load as last module
|
||||
|
||||
local event = require 'utils.event'
|
||||
|
||||
local mining_chance_weights = {
|
||||
{name = "iron-plate", chance = 100},
|
||||
{name = "iron-gear-wheel", chance = 75},
|
||||
{name = "copper-plate", chance = 75},
|
||||
{name = "copper-cable", chance = 50},
|
||||
{name = "electronic-circuit", chance = 30},
|
||||
{name = "steel-plate", chance = 15},
|
||||
{name = "pipe", chance = 10},
|
||||
{name = "iron-stick", chance = 10},
|
||||
{name = "solid-fuel", chance = 10},
|
||||
{name = "empty-barrel", chance = 10},
|
||||
{name = "battery", chance = 1},
|
||||
{name = "land-mine", chance = 1}
|
||||
}
|
||||
|
||||
local scrap_yield_amounts = {
|
||||
["iron-plate"] = 16,
|
||||
["iron-gear-wheel"] = 8,
|
||||
["iron-stick"] = 16,
|
||||
["copper-plate"] = 16,
|
||||
["copper-cable"] = 24,
|
||||
["electronic-circuit"] = 8,
|
||||
["steel-plate"] = 4,
|
||||
["pipe"] = 8,
|
||||
["solid-fuel"] = 4,
|
||||
["empty-barrel"] = 2,
|
||||
["battery"] = 2,
|
||||
["land-mine"] = 1,
|
||||
}
|
||||
|
||||
local scrap_raffle = {}
|
||||
for _, t in pairs (mining_chance_weights) do
|
||||
for x = 1, t.chance, 1 do
|
||||
table.insert(scrap_raffle, t.name)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_mined_entity(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then return end
|
||||
if entity.name ~= "mineable-wreckage" then return end
|
||||
|
||||
event.buffer.clear()
|
||||
|
||||
local scrap = scrap_raffle[math.random(1, #scrap_raffle)]
|
||||
|
||||
local amount = math.random(math.ceil(scrap_yield_amounts[scrap] * 0.3), math.ceil(scrap_yield_amounts[scrap] * 1.7))
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local inserted_count = player.insert({name = scrap, count = amount})
|
||||
|
||||
if inserted_count ~= amount then
|
||||
local amount_to_spill = amount - inserted_count
|
||||
entity.surface.spill_item_stack(entity.position,{name = scrap, count = amount_to_spill}, true)
|
||||
end
|
||||
|
||||
entity.surface.create_entity({
|
||||
name = "flying-text",
|
||||
position = entity.position,
|
||||
text = "+" .. amount .. " [img=item/" .. scrap .. "]",
|
||||
color = {r=0.98, g=0.66, b=0.22}
|
||||
})
|
||||
end
|
||||
|
||||
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
@ -1,10 +1,18 @@
|
||||
local event = require 'utils.event'
|
||||
|
||||
local function trigger_function(schedule)
|
||||
if not schedule.args then schedule.func() return end
|
||||
if not schedule.args[2] then schedule.func(schedule.args[1]) return end
|
||||
if not schedule.args[3] then schedule.func(schedule.args[1], schedule.args[2]) return end
|
||||
if not schedule.args[4] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3]) return end
|
||||
if schedule.args[5] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4], schedule.args[5]) return end
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
if not global.on_tick_schedule[game.tick] then return end
|
||||
|
||||
for _, schedule in pairs(global.on_tick_schedule[game.tick]) do
|
||||
schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4], schedule.args[5])
|
||||
trigger_function(schedule)
|
||||
end
|
||||
|
||||
global.on_tick_schedule[game.tick] = nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user