1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-11 14:49:24 +02:00

junkyard > desync fix

This commit is contained in:
MewMew 2019-03-07 19:54:33 +01:00
parent 01786d531d
commit 8fb7649919
5 changed files with 138 additions and 77 deletions

View File

@ -1,7 +1,22 @@
local math_random = math.random
local table_insert = table.insert
local function create_particles(surface, position, amount)
local math_random = math.random
for i = 1, amount, 1 do
local m = math_random(6, 12)
local m2 = m * 0.005
surface.create_entity({
name = "stone-particle",
position = position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
})
end
end
local biter_table = {
local function spawn_biter(surface, position, evolution_index)
local biter_table = {
[1] = {"small-biter"},
[2] = {"small-biter","small-biter","small-biter","small-biter","small-biter","medium-biter"},
[3] = {"small-biter","small-biter","small-biter","small-biter","medium-biter","medium-biter"},
@ -23,26 +38,7 @@ local biter_table = {
[19] = {"behemoth-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-spitter"},
[20] = {"behemoth-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-spitter","behemoth-spitter"}
}
local function create_particles(surface, position, amount)
for i = 1, amount, 1 do
local m = math_random(6, 12)
local m2 = m * 0.005
surface.create_entity({
name = "stone-particle",
position = position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
})
end
end
local function spawn_biter(surface, position)
local evolution = math.ceil(game.forces.enemy.evolution_factor * 20)
local raffle = biter_table[evolution]
local raffle = biter_table[evolution_index]
local biter_name = raffle[math.random(1,#raffle)]
local p = surface.find_non_colliding_position(biter_name, position, 8, 0.5)
if not p then p = {x = position.x, y = position.y} end
@ -53,7 +49,10 @@ local function unearthing_biters(surface, position, amount)
if not surface then return end
if not position then return end
if not position.x then return end
if not position.y then return end
if not position.y then return end
local evolution_index = math.ceil(game.forces.enemy.evolution_factor * 20)
if evolution_index < 1 then evolution_index = 1 end
local ticks = amount * 30
ticks = ticks + 120
@ -62,14 +61,14 @@ local function unearthing_biters(surface, position, amount)
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_particles,
args = {surface, position, 5}
args = {surface, {x = position.x, y = position.y}, 5}
}
if t > 120 then
if t % 30 == 29 then
if t % 30 == 29 then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = spawn_biter,
args = {surface, position}
args = {surface, {x = position.x, y = position.y}, evolution_index}
}
end
end

View File

@ -1,20 +1,5 @@
local math_random = math.random
local table_insert = table.insert
local worm_raffle_table = {
[1] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret"},
[2] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret"},
[3] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret"},
[4] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret"},
[5] = {"small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret"},
[6] = {"small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret"},
[7] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret"},
[8] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret"},
[9] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"},
[10] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"}
}
local function create_particles(surface, position, amount)
local function create_particles(surface, position, amount)
local math_random = math.random
for i = 1, amount, 1 do
local m = math_random(8, 24)
local m2 = m * 0.005
@ -30,9 +15,20 @@ local function create_particles(surface, position, amount)
end
end
local function spawn_worm(surface, position)
local evolution = math.ceil(game.forces.enemy.evolution_factor * 10)
local raffle = worm_raffle_table[evolution]
local function spawn_worm(surface, position, evolution_index)
local worm_raffle_table = {
[1] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret"},
[2] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret"},
[3] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret"},
[4] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret"},
[5] = {"small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret"},
[6] = {"small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret"},
[7] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret"},
[8] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret"},
[9] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"},
[10] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"}
}
local raffle = worm_raffle_table[evolution_index]
local worm_name = raffle[math.random(1,#raffle)]
surface.create_entity({name = worm_name, position = position})
end
@ -41,20 +37,23 @@ local function unearthing_worm(surface, position)
if not surface then return end
if not position then return end
if not position.x then return end
if not position.y then return end
if not position.y then return end
local evolution_index = math.ceil(game.forces.enemy.evolution_factor * 10)
if evolution_index < 1 then evolution_index = 1 end
for t = 1, 360, 1 do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_particles,
args = {surface, position, math.ceil(t * 0.07)}
args = {surface, {x = position.x, y = position.y}, math.ceil(t * 0.07)}
}
if t == 360 then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = spawn_worm,
args = {surface, position}
args = {surface, {x = position.x, y = position.y}, evolution_index}
}
end
end

View File

@ -81,7 +81,7 @@ local function get_noise(name, pos)
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
local noise = noise[1] + noise[2] * 0.35 + noise[3] * 0.23 + noise[4] * 0.11
return noise
end
end
@ -137,8 +137,8 @@ local function create_shipwreck(surface, position)
{{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 = "burner-mining-drill", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2},
{{name = "electric-mining-drill", count = math_random(2,4)}, 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},
@ -263,7 +263,7 @@ local function on_chunk_generated(event)
if not tile.collides_with("player-layer") then
local noise = get_noise(1, pos)
if noise > 0.5 or noise < -0.5 then
if noise > 0.43 or noise < -0.43 then
if math_random(1,3) ~= 1 then
surface.create_entity({name = "mineable-wreckage", position = pos})
else
@ -334,7 +334,7 @@ local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.online_time == 0 then
player.insert({name = "pistol", count = 1})
player.insert({name = "firearm-magazine", count = 32})
player.insert({name = "firearm-magazine", count = 16})
end
if global.map_init_done then return end
@ -351,7 +351,7 @@ local function on_player_mined_entity(event)
unearthing_biters(entity.surface, entity.position, math_random(4,12))
end
if math_random(1,64) == 1 then
if math_random(1,64) == 1 then
unearthing_worm(entity.surface, entity.position)
end
end

View File

@ -1,27 +1,58 @@
--destroying and mining rocks yields ore -- load as last module
--mineable-wreckage yields scrap -- by mewmew
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 = 20},
{name = "solid-fuel", chance = 15},
{name = "pipe", chance = 10},
{name = "iron-stick", chance = 10},
{name = "empty-barrel", chance = 3},
{name = "crude-oil-barrel", chance = 3},
{name = "lubricant-barrel", chance = 3},
{name = "petroleum-gas-barrel", chance = 3},
{name = "sulfuric-acid-barrel", chance = 3},
{name = "heavy-oil-barrel", chance = 3},
{name = "light-oil-barrel", chance = 3},
{name = "water-barrel", chance = 3},
{name = "battery", chance = 1},
{name = "land-mine", chance = 1}
{name = "iron-plate", chance = 1000},
{name = "iron-gear-wheel", chance = 750},
{name = "copper-plate", chance = 750},
{name = "copper-cable", chance = 500},
{name = "electronic-circuit", chance = 300},
{name = "steel-plate", chance = 200},
{name = "solid-fuel", chance = 150},
{name = "pipe", chance = 100},
{name = "iron-stick", chance = 50},
{name = "empty-barrel", chance = 10},
{name = "crude-oil-barrel", chance = 30},
{name = "lubricant-barrel", chance = 20},
{name = "petroleum-gas-barrel", chance = 15},
{name = "sulfuric-acid-barrel", chance = 15},
{name = "heavy-oil-barrel", chance = 15},
{name = "light-oil-barrel", chance = 15},
{name = "water-barrel", chance = 10},
{name = "battery", chance = 10},
{name = "green-wire", chance = 10},
{name = "red-wire", chance = 10},
{name = "explosives", chance = 5},
{name = "advanced-circuit", chance = 5},
{name = "nuclear-fuel", chance = 1},
{name = "pipe-to-ground", chance = 5},
{name = "plastic-bar", chance = 4},
{name = "processing-unit", chance = 2},
{name = "used-up-uranium-fuel-cell", chance = 1},
{name = "uranium-fuel-cell", chance = 1},
{name = "rocket-fuel", chance = 3},
{name = "rocket-control-unit", chance = 1},
{name = "low-density-structure", chance = 1},
{name = "heat-pipe", chance = 1},
{name = "engine-unit", chance = 3},
{name = "electric-engine-unit", chance = 2},
{name = "logistic-robot", chance = 1},
{name = "construction-robot", chance = 1},
{name = "land-mine", chance = 10},
{name = "grenade", chance = 10},
{name = "rocket", chance = 5},
{name = "explosive-rocket", chance = 5},
{name = "cannon-shell", chance = 2},
{name = "explosive-cannon-shell", chance = 2},
{name = "uranium-cannon-shell", chance = 2},
{name = "explosive-uranium-cannon-shell", chance = 2},
{name = "artillery-shell", chance = 1},
{name = "cluster-grenade", chance = 2},
{name = "defender-capsule", chance = 5},
{name = "destroyer-capsule", chance = 1},
{name = "distractor-capsule", chance = 2}
}
local scrap_yield_amounts = {
@ -43,7 +74,38 @@ local scrap_yield_amounts = {
["light-oil-barrel"] = 3,
["water-barrel"] = 3,
["battery"] = 2,
["land-mine"] = 1
["explosives"] = 8,
["advanced-circuit"] = 2,
["nuclear-fuel"] = 0.1,
["pipe-to-ground"] = 1,
["plastic-bar"] = 4,
["processing-unit"] = 1,
["used-up-uranium-fuel-cell"] = 1,
["uranium-fuel-cell"] = 0.1,
["rocket-fuel"] = 0.1,
["rocket-control-unit"] = 0.1,
["low-density-structure"] = 0.1,
["heat-pipe"] = 1,
["green-wire"] = 8,
["red-wire"] = 8,
["engine-unit"] = 2,
["electric-engine-unit"] = 2,
["logistic-robot"] = 0.1,
["construction-robot"] = 0.1,
["land-mine"] = 1,
["grenade"] = 2,
["rocket"] = 2,
["explosive-rocket"] = 2,
["cannon-shell"] = 2,
["explosive-cannon-shell"] = 2,
["uranium-cannon-shell"] = 2,
["explosive-uranium-cannon-shell"] = 2,
["artillery-shell"] = 0.1,
["cluster-grenade"] = 0.1,
["defender-capsule"] = 2,
["destroyer-capsule"] = 0.1,
["distractor-capsule"] = 0.1
}
local scrap_raffle = {}

View File

@ -5,6 +5,7 @@ local function trigger_function(schedule)
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 not schedule.args[5] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4]) 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