1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-04 00:15:45 +02:00

Merge pull request #11 from M3wM3w/master

on_tick_schedule removed and refactored
This commit is contained in:
hanakocz 2020-06-15 07:55:42 +02:00 committed by GitHub
commit e358844f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 1695 additions and 1241 deletions

View File

@ -53,7 +53,7 @@ require 'modules.autostash'
--require 'modules.show_health'
--require 'modules.splice_double'
--require 'modules.ores_are_mixed'
--require 'modules.team_teleport' --(REQUIRES "on_tick_schedule" !)
--require 'modules.team_teleport'
--require 'modules.surrounded_by_worms'
--require 'modules.no_blueprint_library'
--require 'modules.explosives'

View File

@ -1,39 +1,76 @@
-------requires on_tick_schedule
-- by mewmew
-- modified by Gerkiz
local function create_projectile(surface, pos, projectile)
surface.create_entity({
name = projectile,
position = pos,
force = "enemy",
target = pos,
speed = 1
})
local Event = require 'utils.event'
local Global = require 'utils.global'
local traps = {}
Global.register(
traps,
function(t)
traps = t
end
)
local function create_projectile(surface, pos, projectile)
surface.create_entity(
{
name = projectile,
position = pos,
force = 'enemy',
target = pos,
speed = 1
}
)
end
local function omegakaboom(surface, center_pos, projectile, radius, density)
local positions = {}
for x = radius * -1, radius, 1 do
for y = radius * -1, radius, 1 do
local pos = {x = center_pos.x + x, y = center_pos.y + y}
local distance_to_center = math.ceil(math.sqrt((pos.x - center_pos.x)^2 + (pos.y - center_pos.y)^2))
if distance_to_center < radius and math.random(1,100) < density then
if not positions[distance_to_center] then positions[distance_to_center] = {} end
positions[distance_to_center][#positions[distance_to_center] + 1] = pos
end
end
end
if #positions == 0 then return end
local t = 1
for i1, pos_list in pairs(positions) do
for i2, pos in pairs(pos_list) 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_projectile,
args = {surface, pos, projectile}
}
end
t = t + 4
end
local positions = {}
for x = radius * -1, radius, 1 do
for y = radius * -1, radius, 1 do
local pos = {x = center_pos.x + x, y = center_pos.y + y}
local distance_to_center = math.ceil(math.sqrt((pos.x - center_pos.x) ^ 2 + (pos.y - center_pos.y) ^ 2))
if distance_to_center < radius and math.random(1, 100) < density then
if not positions[distance_to_center] then
positions[distance_to_center] = {}
end
positions[distance_to_center][#positions[distance_to_center] + 1] = pos
end
end
end
if #positions == 0 then
return
end
local t = 1
for _, pos_list in pairs(positions) do
for _, pos in pairs(pos_list) do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
end
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_projectile',
params = {surface, pos, projectile}
}
end
t = t + 4
end
end
return omegakaboom
local function on_tick()
if not traps[game.tick] then
return
end
for _, token in pairs(traps[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'create_projectile' then
create_projectile(params[1], params[2], params[3])
end
end
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
return omegakaboom

View File

@ -1,90 +1,148 @@
-- timer traps -- by mewmew
-- by mewmew
-- modified by Gerkiz
local tick_tacks = {"*tick*", "*tick*", "*tack*", "*tak*", "*tik*", "*tok*"}
local Event = require 'utils.event'
local Global = require 'utils.global'
local traps = {}
Global.register(
traps,
function(t)
traps = t
end
)
local tick_tacks = {'*tick*', '*tick*', '*tack*', '*tak*', '*tik*', '*tok*'}
local kaboom_weights = {
{name = "grenade", chance = 7},
{name = "cluster-grenade", chance = 1},
{name = "destroyer-capsule", chance = 1},
{name = "defender-capsule", chance = 4},
{name = "distractor-capsule", chance = 3},
{name = "poison-capsule", chance = 2},
{name = "explosive-uranium-cannon-projectile", chance = 3},
{name = "explosive-cannon-projectile", chance = 5},
{name = 'grenade', chance = 7},
{name = 'cluster-grenade', chance = 1},
{name = 'destroyer-capsule', chance = 1},
{name = 'defender-capsule', chance = 4},
{name = 'distractor-capsule', chance = 3},
{name = 'poison-capsule', chance = 2},
{name = 'explosive-uranium-cannon-projectile', chance = 3},
{name = 'explosive-cannon-projectile', chance = 5}
}
local kabooms = {}
for _, t in pairs (kaboom_weights) do
for x = 1, t.chance, 1 do
table.insert(kabooms, t.name)
end
local kabooms = {}
for _, t in pairs(kaboom_weights) do
for x = 1, t.chance, 1 do
table.insert(kabooms, t.name)
end
end
local function create_flying_text(surface, position, text)
if not surface.valid then return end
surface.create_entity({
name = "flying-text",
position = position,
text = text,
color = {r=0.75, g=0.75, b=0.75}
})
if text == "..." then return end
surface.play_sound({path="utility/armor_insert", position=position, volume_modifier=0.75})
if not surface.valid then
return
end
surface.create_entity(
{
name = 'flying-text',
position = position,
text = text,
color = {r = 0.75, g = 0.75, b = 0.75}
}
)
if text == '...' then
return
end
surface.play_sound({path = 'utility/armor_insert', position = position, volume_modifier = 0.75})
end
local function create_kaboom(surface, position, name)
if not surface.valid then return end
local target = position
local speed = 0.5
if name == "defender-capsule" or name == "destroyer-capsule" or name == "distractor-capsule" then
surface.create_entity({
name = "flying-text",
position = position,
text = "(((Sentries Engaging Target)))",
color = {r=0.8, g=0.0, b=0.0}
})
local nearest_player_unit = surface.find_nearest_enemy({position = position, max_distance=128, force="enemy"})
if nearest_player_unit then target = nearest_player_unit.position end
speed = 0.001
end
surface.create_entity({
name = name,
position = position,
force = "enemy",
target = target,
speed = speed
})
if not surface.valid then
return
end
local target = position
local speed = 0.5
if name == 'defender-capsule' or name == 'destroyer-capsule' or name == 'distractor-capsule' then
surface.create_entity(
{
name = 'flying-text',
position = position,
text = '(((Sentries Engaging Target)))',
color = {r = 0.8, g = 0.0, b = 0.0}
}
)
local nearest_player_unit =
surface.find_nearest_enemy({position = position, max_distance = 128, force = 'enemy'})
if nearest_player_unit then
target = nearest_player_unit.position
end
speed = 0.001
end
surface.create_entity(
{
name = name,
position = position,
force = 'enemy',
target = target,
speed = speed
}
)
end
local function tick_tack_trap(surface, position)
if not surface then return end
if not surface.valid then return end
if not position then return end
if not position.x then return end
if not position.y then return end
local tick_tack_count = math.random(5, 9)
for t = 60, tick_tack_count * 60, 60 do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
if t < tick_tack_count * 60 then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_flying_text,
args = {surface, {x = position.x, y = position.y}, tick_tacks[math.random(1, #tick_tacks)]}
}
else
if math.random(1, 10) == 1 then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_flying_text,
args = {surface, {x = position.x, y = position.y}, "..."}
}
else
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = create_kaboom,
args = {surface, {x = position.x, y = position.y}, kabooms[math.random(1, #kabooms)]}
}
end
end
end
if not surface then
return
end
if not surface.valid then
return
end
if not position then
return
end
if not position.x then
return
end
if not position.y then
return
end
local tick_tack_count = math.random(5, 9)
for t = 60, tick_tack_count * 60, 60 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
end
if t < tick_tack_count * 60 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_flying_text',
params = {surface, {x = position.x, y = position.y}, tick_tacks[math.random(1, #tick_tacks)]}
}
else
if math.random(1, 10) == 1 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_flying_text',
params = {surface, {x = position.x, y = position.y}, '...'}
}
else
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_kaboom',
params = {surface, {x = position.x, y = position.y}, kabooms[math.random(1, #kabooms)]}
}
end
end
end
end
local function on_tick()
if not traps[game.tick] then
return
end
for _, token in pairs(traps[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'create_kaboom' then
create_kaboom(params[1], params[2], params[3])
elseif callback == 'create_flying_text' then
create_flying_text(params[1], params[2], params[3])
end
end
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
return tick_tack_trap

View File

@ -1,83 +1,138 @@
-- by mewmew
-- modified by Gerkiz
local Event = require 'utils.event'
local Global = require 'utils.global'
local traps = {}
Global.register(
traps,
function(t)
traps = t
end
)
local function create_particles(surface, position, amount)
if not surface.valid then return end
local math_random = math.random
for i = 1, amount, 1 do
local m = math_random(6, 12)
local m2 = m * 0.005
surface.create_particle({
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
if not surface.valid then
return
end
local math_random = math.random
for i = 1, amount, 1 do
local m = math_random(6, 12)
local m2 = m * 0.005
surface.create_particle(
{
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, evolution)
if not surface.valid then return end
local evo = math.floor(evolution * 1000)
local biter_chances = {
{name = "small-biter", chance = math.floor(1000 - (evo * 1.6))},
{name = "small-spitter", chance = math.floor(500 - evo * 0.8)},
{name = "medium-biter", chance = -150 + evo},
{name = "medium-spitter", chance = -75 + math.floor(evo * 0.5)},
{name = "big-biter", chance = math.floor((evo - 500) * 3)},
{name = "big-spitter", chance = math.floor((evo - 500) * 2)},
{name = "behemoth-biter", chance = math.floor((evo - 800) * 6)},
{name = "behemoth-spitter", chance = math.floor((evo - 800) * 4)}
}
local max_chance = 0
for i = 1, 8, 1 do
if biter_chances[i].chance < 0 then biter_chances[i].chance = 0 end
max_chance = max_chance + biter_chances[i].chance
end
local r = math.random(1, max_chance)
local current_chance = 0
for i = 1, 8, 1 do
current_chance = current_chance + biter_chances[i].chance
if r <= current_chance then
local biter_name = biter_chances[i].name
local p = surface.find_non_colliding_position(biter_name, position, 10, 1)
if not p then return end
surface.create_entity({name = biter_name, position = p, force = "enemy"})
return
end
end
if not surface.valid then
return
end
local evo = math.floor(evolution * 1000)
local biter_chances = {
{name = 'small-biter', chance = math.floor(1000 - (evo * 1.6))},
{name = 'small-spitter', chance = math.floor(500 - evo * 0.8)},
{name = 'medium-biter', chance = -150 + evo},
{name = 'medium-spitter', chance = -75 + math.floor(evo * 0.5)},
{name = 'big-biter', chance = math.floor((evo - 500) * 3)},
{name = 'big-spitter', chance = math.floor((evo - 500) * 2)},
{name = 'behemoth-biter', chance = math.floor((evo - 800) * 6)},
{name = 'behemoth-spitter', chance = math.floor((evo - 800) * 4)}
}
local max_chance = 0
for i = 1, 8, 1 do
if biter_chances[i].chance < 0 then
biter_chances[i].chance = 0
end
max_chance = max_chance + biter_chances[i].chance
end
local r = math.random(1, max_chance)
local current_chance = 0
for i = 1, 8, 1 do
current_chance = current_chance + biter_chances[i].chance
if r <= current_chance then
local biter_name = biter_chances[i].name
local p = surface.find_non_colliding_position(biter_name, position, 10, 1)
if not p then
return
end
surface.create_entity({name = biter_name, position = p, force = 'enemy'})
return
end
end
end
local function unearthing_biters(surface, position, amount)
if not surface then return end
if not surface.valid then return end
if not position then return end
if not position.x then return end
if not position.y then return end
local evolution = game.forces.enemy.evolution_factor
local ticks = amount * 30
ticks = ticks + 90
for t = 1, ticks, 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, {x = position.x, y = position.y}, 4}
}
if t > 90 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, {x = position.x, y = position.y}, evolution}
}
end
end
end
if not surface then
return
end
if not surface.valid then
return
end
if not position then
return
end
if not position.x then
return
end
if not position.y then
return
end
local evolution = game.forces.enemy.evolution_factor
local ticks = amount * 30
ticks = ticks + 90
for t = 1, ticks, 1 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
end
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_particles',
params = {surface, {x = position.x, y = position.y}, 4}
}
if t > 90 then
if t % 30 == 29 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'spawn_biter',
params = {surface, {x = position.x, y = position.y}, evolution}
}
end
end
end
end
local function on_tick()
if not traps[game.tick] then
return
end
for _, token in pairs(traps[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'create_particles' then
create_particles(params[1], params[2], params[3])
elseif callback == 'spawn_biter' then
spawn_biter(params[1], params[2], params[3])
end
end
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
return unearthing_biters

View File

@ -1,65 +1,188 @@
local function create_particles(surface, position, amount)
if not surface.valid then return end
local math_random = math.random
for i = 1, amount, 1 do
local m = math_random(8, 24)
local m2 = m * 0.005
surface.create_particle({
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
-- by mewmew
-- modified by Gerkiz
local Event = require 'utils.event'
local Global = require 'utils.global'
local traps = {}
Global.register(
traps,
function(t)
traps = t
end
)
local function create_particles(surface, position, amount)
if not surface.valid then
return
end
local math_random = math.random
for i = 1, amount, 1 do
local m = math_random(8, 24)
local m2 = m * 0.005
surface.create_particle(
{
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_worm(surface, position, evolution_index)
if not surface.valid then return end
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})
if not surface.valid then
return
end
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
local function unearthing_worm(surface, position)
if not surface then return end
if not surface.valid then return end
if not position then return end
if not position.x 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, 330, 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, {x = position.x, y = position.y}, math.ceil(t * 0.05)}
}
if t == 330 then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = spawn_worm,
args = {surface, {x = position.x, y = position.y}, evolution_index}
}
end
end
if not surface then
return
end
if not surface.valid then
return
end
if not position then
return
end
if not position.x 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, 330, 1 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
end
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_particles',
params = {surface, {x = position.x, y = position.y}, math.ceil(t * 0.05)}
}
if t == 330 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'spawn_worm',
params = {surface, {x = position.x, y = position.y}, evolution_index}
}
end
end
end
local function on_tick()
if not traps[game.tick] then
return
end
for _, token in pairs(traps[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'create_particles' then
create_particles(params[1], params[2], params[3])
elseif callback == 'spawn_worm' then
spawn_worm(params[1], params[2], params[3])
end
end
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
return unearthing_worm

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
--choppy-- mewmew made this --
-- modified by gerkiz
require "on_tick_schedule"
require "modules.dynamic_landfill"
require "modules.satellite_score"
require "modules.spawners_contain_biters"
@ -15,7 +14,7 @@ local create_tile_chain = require "functions.create_tile_chain"
local Module = require "modules.infinity_chest"
local simplex_noise = require 'utils.simplex_noise'.d2
local event = require 'utils.event'
local event = require 'utils.event'
local table_insert = table.insert
local math_random = math.random
local map_functions = require "tools.map_functions"
@ -37,7 +36,7 @@ local tile_replacements = {
["sand-1"] = "grass-1",
["sand-2"] = "grass-2",
["sand-3"] = "grass-3",
["dry-dirt"] = "grass-2",
["dry-dirt"] = "grass-2",
["red-desert-0"] = "grass-1",
["red-desert-1"] = "grass-2",
["red-desert-2"] = "grass-3",
@ -110,19 +109,19 @@ local trees_to_remove = {
}
local info = [[
You are a lumberjack with a passion to chop.
Different kinds of trees, yield different kinds of ore and wood.
You are a lumberjack with a passion to chop.
Different kinds of trees, yield different kinds of ore and wood.
Yes, they seem to draw minerals out of the ground and manifesting it as "fruit".
Their yield increases with distance. Mining Productivity Research will increase chopping speed and backpack size.
Beware, sometimes there are some bugs hiding underneath the trees.
Even dangerous traps have been encountered before.
These mysterious ore trees don't burn very well, so do not worry if some of them catch on fire.
Also, there seems to be an elevator that goes down to the mine. Who knows what one can find down there...
Choppy Choppy Wood
]]
@ -148,53 +147,53 @@ local function create_map_intro_button(player)
b.style.bottom_padding = 2
end
local function create_choppy_stats_gui(player)
local function create_choppy_stats_gui(player)
if player.gui.top["choppy_stats_frame"] then player.gui.top["choppy_stats_frame"].destroy() end
local captions = {}
local caption_style = {{"font", "default-bold"}, {"font_color",{ r=0.63, g=0.63, b=0.63}}, {"top_padding",2}, {"left_padding",0},{"right_padding",0},{"minimal_width",0}}
local stat_numbers = {}
local stat_number_style = {{"font", "default-bold"}, {"font_color",{ r=0.77, g=0.77, b=0.77}}, {"top_padding",2}, {"left_padding",0},{"right_padding",0},{"minimal_width",0}}
local separators = {}
local separator_style = {{"font", "default-bold"}, {"font_color",{ r=0.15, g=0.15, b=0.89}}, {"top_padding",2}, {"left_padding",2},{"right_padding",2},{"minimal_width",0}}
local frame = player.gui.top.add { type = "frame", name = "choppy_stats_frame" }
local t = frame.add { type = "table", column_count = 16 }
local t = frame.add { type = "table", column_count = 16 }
captions[1] = t.add { type = "label", caption = '[img=item/iron-ore] :' }
global.total_ores_mined = global.stats_ores_found + game.forces.player.item_production_statistics.get_input_count("coal") + game.forces.player.item_production_statistics.get_input_count("iron-ore") + game.forces.player.item_production_statistics.get_input_count("copper-ore") + game.forces.player.item_production_statistics.get_input_count("uranium-ore")
global.total_ores_mined = global.stats_ores_found + game.forces.player.item_production_statistics.get_input_count("coal") + game.forces.player.item_production_statistics.get_input_count("iron-ore") + game.forces.player.item_production_statistics.get_input_count("copper-ore") + game.forces.player.item_production_statistics.get_input_count("uranium-ore")
stat_numbers[1] = t.add { type = "label", caption = global.total_ores_mined }
separators[1] = t.add { type = "label", caption = "|"}
captions[2] = t.add { type = "label", caption = '[img=entity.tree-04] :' }
stat_numbers[2] = t.add { type = "label", caption = global.stats_wood_chopped }
separators[2] = t.add { type = "label", caption = "|"}
captions[3] = t.add { type = "label", caption = '[img=item.productivity-module] :' }
local x = math.floor(game.forces.player.manual_mining_speed_modifier * 100)
local str = ""
if x > 0 then str = str .. "+" end
str = str .. tostring(x)
str = str .. "%"
str = str .. "%"
stat_numbers[3] = t.add { type = "label", caption = str }
if game.forces.player.manual_mining_speed_modifier > 0 or game.forces.player.mining_drill_productivity_bonus > 0 then
if game.forces.player.manual_mining_speed_modifier > 0 or game.forces.player.mining_drill_productivity_bonus > 0 then
separators[3] = t.add { type = "label", caption = "|"}
captions[3] = t.add { type = "label", caption = '[img=utility.hand] :' }
captions[3] = t.add { type = "label", caption = '[img=utility.hand] :' }
local str = "+"
str = str .. tostring(game.forces.player.mining_drill_productivity_bonus * 100)
str = str .. "%"
str = str .. "%"
stat_numbers[3] = t.add { type = "label", caption = str }
end
end
for _, s in pairs (caption_style) do
for _, l in pairs (captions) do
l.style[s[1]] = s[2]
@ -217,10 +216,10 @@ end
local function create_map_intro(player)
if player.gui.left["map_intro_frame"] then player.gui.left["map_intro_frame"].destroy() end
local frame = player.gui.left.add {type = "frame", name = "map_intro_frame", direction = "vertical"}
local t = frame.add {type = "table", column_count = 1}
local b = frame.add {type = "button", caption = "Close", name = "close_map_intro_frame", align = "right"}
local t = frame.add {type = "table", column_count = 1}
local b = frame.add {type = "button", caption = "Close", name = "close_map_intro_frame", align = "right"}
b.style.font = "default"
b.style.minimal_height = 30
b.style.minimal_width = 30
@ -228,31 +227,31 @@ local function create_map_intro(player)
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
local frame = t.add {type = "frame"}
local l = frame.add {type = "label", caption = info}
l.style.single_line = false
l.style.font = "heading-3"
l.style.font_color = {r=0.95, g=0.95, b=0.95}
l.style.font_color = {r=0.95, g=0.95, b=0.95}
end
local function on_gui_click(event)
if not event then return end
if not event.element then return end
if not event.element.valid then return end
if not event.element.valid then return end
local player = game.players[event.element.player_index]
local name = event.element.name
local frame = player.gui.top["choppy_stats_frame"]
local frame = player.gui.top["choppy_stats_frame"]
if name == "map_intro_button" and frame == nil then create_choppy_stats_gui(player) end
if name == "map_intro_button" and frame == nil then create_choppy_stats_gui(player) end
if name == "map_intro_button" and frame then
if player.gui.left["map_intro_frame"] then
frame.destroy()
player.gui.left["map_intro_frame"].destroy()
else
else
create_map_intro(player)
end
return
return
end
if name == "close_map_intro_frame" then player.gui.left["map_intro_frame"].destroy() end
end
@ -260,9 +259,9 @@ end
local function refresh_gui()
for _, player in pairs(game.connected_players) do
local frame = player.gui.top["choppy_stats_frame"]
if (frame) then
if (frame) then
create_choppy_stats_gui(player)
create_map_intro_button(player)
create_map_intro_button(player)
end
end
end
@ -281,21 +280,21 @@ local function process_entity(e)
end
local function process_tile(surface, pos, tile, seed)
if tile.collides_with("player-layer") then return end
if tile.collides_with("player-layer") then return end
if not surface.can_place_entity({name = "tree-01", position = pos}) then return end
if math_random(1, 100000) == 1 then
local wrecks = {"big-ship-wreck-1", "big-ship-wreck-2", "big-ship-wreck-3"}
local e = surface.create_entity{name = wrecks[math_random(1,#wrecks)], position = pos, force = "neutral"}
e.insert({name = "raw-fish", count = math_random(3, 25)})
if math_random(1, 3) == 1 then e.insert({name = "wood", count = math_random(11, 44)}) end
end
local noise_forest_location = get_noise("forest_location", pos, seed)
--local r = math.ceil(math.abs(get_noise("forest_density", pos, seed + 4096)) * 10)
--local r = 5 - math.ceil(math.abs(noise_forest_location) * 3)
--r = 2
--r = 2
if noise_forest_location > 0.095 then
if noise_forest_location > 0.6 then
if math_random(1,100) > 42 then surface.create_entity({name = "tree-08-brown", position = pos}) end
@ -305,7 +304,7 @@ local function process_tile(surface, pos, tile, seed)
surface.create_decoratives({check_collision=false, decoratives={{name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2)}}})
return
end
if noise_forest_location < -0.095 then
if noise_forest_location < -0.6 then
if math_random(1,100) > 42 then surface.create_entity({name = "tree-04", position = pos}) end
@ -315,7 +314,7 @@ local function process_tile(surface, pos, tile, seed)
surface.create_decoratives({check_collision=false, decoratives={{name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2)}}})
return
end
surface.create_decoratives({check_collision=false, decoratives={{name = decos[math_random(1, #decos)], position = pos, amount = math_random(1, 2)}}})
end
@ -324,49 +323,49 @@ local function on_chunk_generated(event)
if surface.name ~= "choppy" then return end
local left_top = event.area.left_top
local tiles = {}
local entities = {}
local entities = {}
local seed = game.surfaces[1].map_gen_settings.seed
--surface.destroy_decoratives({area = event.area})
for _, e in pairs(surface.find_entities_filtered({area = event.area})) do
process_entity(e)
process_entity(e)
end
for x = 0.5, 31.5, 1 do
for y = 0.5, 31.5, 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
process_tile(surface, pos, tile, seed)
end
end
surface.set_tiles(tiles, true)
for _, e in pairs(surface.find_entities_filtered({area = event.area, type = "unit-spawner"})) do
for _, entity in pairs (e.surface.find_entities_filtered({area = {{e.position.x - 7, e.position.y - 7},{e.position.x + 7, e.position.y + 7}}, force = "neutral"})) do
if entity.valid then entity.destroy() end
end
end
if global.spawn_generated then return end
if left_top.x < 96 then return end
if left_top.x < 96 then return end
for _, e in pairs (surface.find_entities_filtered({area = {{-50, -50},{50, 50}}})) do
local distance_to_center = math.sqrt(e.position.x^2 + e.position.y^2)
if e.valid then
if distance_to_center < 8 and e.type == "tree" and math_random(1,5) ~= 1 then e.destroy() end
end
end
end
global.spawn_generated = true
global.spawn_generated = true
end
local function on_marked_for_deconstruction(event)
local function on_marked_for_deconstruction(event)
if disabled_for_deconstruction[event.entity.name] then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
@ -375,17 +374,17 @@ local function on_marked_for_deconstruction(event)
end
end
local function on_player_joined_game(event)
local function on_player_joined_game(event)
local player = game.players[event.player_index]
local surface = player.surface
if global.map_choppy_init_done then return end
--game.map_settings.pollution.min_pollution_to_damage_trees = 1000000
--game.map_settings.pollution.pollution_per_tree_damage = 0
--game.map_settings.pollution.pollution_restored_per_tree_damage = 0
game.surfaces["choppy"].ticks_per_day = game.surfaces["choppy"].ticks_per_day * 2
global.entity_yield = {
["tree-01"] = {"iron-ore"},
["tree-02-red"] = {"copper-ore"},
@ -394,7 +393,7 @@ local function on_player_joined_game(event)
["rock-big"] = {"uranium-ore"},
["rock-huge"] = {"uranium-ore"}
}
if game.item_prototypes["angels-ore1"] then
global.entity_yield["tree-01"] = {"angels-ore1", "angels-ore2"}
global.entity_yield["tree-02-red"] = {"angels-ore5", "angels-ore6"}
@ -403,16 +402,16 @@ local function on_player_joined_game(event)
else
game.map_settings.pollution.ageing = 0
end
if game.item_prototypes["thorium-ore"] then
global.entity_yield["rock-big"] = {"uranium-ore", "thorium-ore"}
global.entity_yield["rock-huge"] = {"uranium-ore", "thorium-ore"}
end
global.map_choppy_init_done = true
end
local function changed_surface(event)
global.map_choppy_init_done = true
end
local function changed_surface(event)
local player = game.players[event.player_index]
local surface = player.surface
if surface.name ~= "choppy" then goto continue end
@ -428,20 +427,20 @@ local function changed_surface(event)
player.print(choppy_messages[math_random(1,#choppy_messages)], { r=0.10, g=0.75, b=0.5})
::continue::
end
end
local function get_amount(entity)
local distance_to_center = math.sqrt(entity.position.x^2 + entity.position.y^2)
local amount = 25 + (distance_to_center * 0.1)
if amount > 1000 then amount = 1000 end
amount = math.random(math.ceil(amount * 0.5), math.ceil(amount * 1.5))
amount = math.random(math.ceil(amount * 0.5), math.ceil(amount * 1.5))
return amount
end
local function trap(entity)
if math_random(1,1024) == 1 then tick_tack_trap(entity.surface, entity.position) return end
if math_random(1,256) == 1 then unearthing_worm(entity.surface, entity.position) end
if math_random(1,128) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,8)) end
if math_random(1,128) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,8)) end
end
local function on_player_mined_entity(event)
@ -449,51 +448,51 @@ local function on_player_mined_entity(event)
local surface = entity.surface
if surface ~= game.surfaces["choppy"] then return end
if not entity.valid then return end
if entity.type == "tree" then
if entity.type == "tree" then
trap(entity)
end
if global.entity_yield[entity.name] then
if event.buffer then event.buffer.clear() end
if global.entity_yield[entity.name] then
if event.buffer then event.buffer.clear() end
if not event.player_index then return end
local amount = get_amount(entity)
local second_item_amount = math_random(2,5)
local second_item = "wood"
if entity.type == "simple-entity" then
amount = amount * 2
second_item_amount = math_random(8,16)
second_item = "stone"
end
local main_item = global.entity_yield[entity.name][math_random(1,#global.entity_yield[entity.name])]
local amount_of_choppie = math.round(amount * 0.15,0)
entity.surface.create_entity({
name = "flying-text",
position = entity.position,
text = "+" .. amount .. " [item=" .. main_item .. "] +" .. second_item_amount .. " [item=" .. second_item .. "]",
color = {r=0.8,g=0.8,b=0.8}})
color = {r=0.8,g=0.8,b=0.8}})
global.stats_ores_found = global.stats_ores_found + amount
global.stats_wood_chopped = global.stats_wood_chopped + 1
refresh_gui()
local player = game.players[event.player_index]
local inserted_count = player.insert({name = main_item, count = amount})
local inserted_count = player.insert({name = main_item, count = amount})
amount = amount - inserted_count
if amount > 0 then
entity.surface.spill_item_stack(entity.position,{name = main_item, count = amount}, true)
end
local inserted_count = player.insert({name = second_item, count = second_item_amount})
local inserted_count = player.insert({name = second_item, count = second_item_amount})
second_item_amount = second_item_amount - inserted_count
if second_item_amount > 0 then
entity.surface.spill_item_stack(entity.position,{name = second_item, count = second_item_amount}, true)
end
end
end
end
end
local function on_research_finished(event)
@ -506,13 +505,13 @@ end
local function on_entity_died(event)
if event.entity.surface.name ~= "choppy" then return end
on_player_mined_entity(event)
if not event.entity.valid then return end
if event.entity.type == "tree" then
if event.entity.type == "tree" then
for _, entity in pairs (event.entity.surface.find_entities_filtered({area = {{event.entity.position.x - 4, event.entity.position.y - 4},{event.entity.position.x + 4, event.entity.position.y + 4}}, name = "fire-flame-on-tree"})) do
if entity.valid then entity.destroy() end
end
end
end
end
local function init_surface(surface)
@ -551,7 +550,7 @@ local function init()
global.surface_choppy_elevator.minable = false
global.surface_choppy_elevator.destructible = false
end
event.on_init(init)
event.add(defines.events.on_player_changed_surface, changed_surface)
event.add(defines.events.on_research_finished, on_research_finished)

View File

@ -1,6 +1,5 @@
--choppy-- mewmew made this --
require "on_tick_schedule"
require "modules.dynamic_landfill"
require "modules.satellite_score"
require "modules.spawners_contain_biters"
@ -12,7 +11,7 @@ local create_entity_chain = require "functions.create_entity_chain"
local create_tile_chain = require "functions.create_tile_chain"
local simplex_noise = require 'utils.simplex_noise'.d2
local event = require 'utils.event'
local event = require 'utils.event'
local table_insert = table.insert
local math_random = math.random
local map_functions = require "tools.map_functions"
@ -34,7 +33,7 @@ local tile_replacements = {
["sand-1"] = "grass-1",
["sand-2"] = "grass-2",
["sand-3"] = "grass-3",
["dry-dirt"] = "grass-2",
["dry-dirt"] = "grass-2",
["red-desert-0"] = "grass-1",
["red-desert-1"] = "grass-2",
["red-desert-2"] = "grass-3",
@ -120,21 +119,21 @@ local function process_entity(e)
end
local function process_tile(surface, pos, tile, seed)
if tile.collides_with("player-layer") then return end
if tile.collides_with("player-layer") then return end
if not surface.can_place_entity({name = "tree-01", position = pos}) then return end
if math_random(1, 100000) == 1 then
local wrecks = {"big-ship-wreck-1", "big-ship-wreck-2", "big-ship-wreck-3"}
local e = surface.create_entity{name = wrecks[math_random(1,#wrecks)], position = pos, force = "neutral"}
e.insert({name = "raw-fish", count = math_random(3, 25)})
if math_random(1, 3) == 1 then e.insert({name = "wood", count = math_random(11, 44)}) end
end
local noise_forest_location = get_noise("forest_location", pos, seed)
--local r = math.ceil(math.abs(get_noise("forest_density", pos, seed + 4096)) * 10)
--local r = 5 - math.ceil(math.abs(noise_forest_location) * 3)
--r = 2
--r = 2
if noise_forest_location > 0.095 then
if noise_forest_location > 0.6 then
if math_random(1,100) > 42 then surface.create_entity({name = "tree-08-brown", position = pos}) end
@ -144,7 +143,7 @@ local function process_tile(surface, pos, tile, seed)
surface.create_decoratives({check_collision=false, decoratives={{name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2)}}})
return
end
if noise_forest_location < -0.095 then
if noise_forest_location < -0.6 then
if math_random(1,100) > 42 then surface.create_entity({name = "tree-04", position = pos}) end
@ -154,7 +153,7 @@ local function process_tile(surface, pos, tile, seed)
surface.create_decoratives({check_collision=false, decoratives={{name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2)}}})
return
end
surface.create_decoratives({check_collision=false, decoratives={{name = decos[math_random(1, #decos)], position = pos, amount = math_random(1, 2)}}})
end
@ -162,49 +161,49 @@ local function on_chunk_generated(event)
local surface = event.surface
local left_top = event.area.left_top
local tiles = {}
local entities = {}
local entities = {}
local seed = game.surfaces[1].map_gen_settings.seed
--surface.destroy_decoratives({area = event.area})
for _, e in pairs(surface.find_entities_filtered({area = event.area})) do
process_entity(e)
process_entity(e)
end
for x = 0.5, 31.5, 1 do
for y = 0.5, 31.5, 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
process_tile(surface, pos, tile, seed)
end
end
surface.set_tiles(tiles, true)
for _, e in pairs(surface.find_entities_filtered({area = event.area, type = "unit-spawner"})) do
for _, entity in pairs (e.surface.find_entities_filtered({area = {{e.position.x - 7, e.position.y - 7},{e.position.x + 7, e.position.y + 7}}, force = "neutral"})) do
if entity.valid then entity.destroy() end
end
end
if global.spawn_generated then return end
if left_top.x < 96 then return end
if left_top.x < 96 then return end
for _, e in pairs (surface.find_entities_filtered({area = {{-50, -50},{50, 50}}})) do
local distance_to_center = math.sqrt(e.position.x^2 + e.position.y^2)
if e.valid then
if distance_to_center < 8 and e.type == "tree" and math_random(1,5) ~= 1 then e.destroy() end
end
end
end
global.spawn_generated = true
global.spawn_generated = true
end
local function on_marked_for_deconstruction(event)
local function on_marked_for_deconstruction(event)
if disabled_for_deconstruction[event.entity.name] then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
@ -213,21 +212,21 @@ local function on_marked_for_deconstruction(event)
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
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 = 8})
end
end
if global.map_init_done then return end
--game.map_settings.pollution.min_pollution_to_damage_trees = 1000000
--game.map_settings.pollution.pollution_per_tree_damage = 0
--game.map_settings.pollution.pollution_restored_per_tree_damage = 0
game.surfaces["nauvis"].ticks_per_day = game.surfaces["nauvis"].ticks_per_day * 2
global.entity_yield = {
["tree-01"] = {"iron-ore"},
["tree-02-red"] = {"copper-ore"},
@ -236,7 +235,7 @@ local function on_player_joined_game(event)
["rock-big"] = {"uranium-ore"},
["rock-huge"] = {"uranium-ore"}
}
if game.item_prototypes["angels-ore1"] then
global.entity_yield["tree-01"] = {"angels-ore1", "angels-ore2"}
global.entity_yield["tree-02-red"] = {"angels-ore5", "angels-ore6"}
@ -245,73 +244,73 @@ local function on_player_joined_game(event)
else
game.map_settings.pollution.ageing = 0
end
if game.item_prototypes["thorium-ore"] then
global.entity_yield["rock-big"] = {"uranium-ore", "thorium-ore"}
global.entity_yield["rock-huge"] = {"uranium-ore", "thorium-ore"}
end
global.map_init_done = true
end
end
local function get_amount(entity)
local distance_to_center = math.sqrt(entity.position.x^2 + entity.position.y^2)
local amount = 25 + (distance_to_center * 0.1)
if amount > 1000 then amount = 1000 end
amount = math.random(math.ceil(amount * 0.5), math.ceil(amount * 1.5))
amount = math.random(math.ceil(amount * 0.5), math.ceil(amount * 1.5))
return amount
end
local function trap(entity)
if math_random(1,1024) == 1 then tick_tack_trap(entity.surface, entity.position) return end
if math_random(1,256) == 1 then unearthing_worm(entity.surface, entity.position) end
if math_random(1,128) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,8)) end
if math_random(1,128) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,8)) end
end
local function on_player_mined_entity(event)
local entity = event.entity
if not entity.valid then return end
if entity.type == "tree" then
if entity.type == "tree" then
trap(entity)
end
if global.entity_yield[entity.name] then
if event.buffer then event.buffer.clear() end
if global.entity_yield[entity.name] then
if event.buffer then event.buffer.clear() end
if not event.player_index then return end
local amount = get_amount(entity)
local second_item_amount = math_random(2,5)
local second_item = "wood"
if entity.type == "simple-entity" then
amount = amount * 2
second_item_amount = math_random(8,16)
second_item = "stone"
end
local main_item = global.entity_yield[entity.name][math_random(1,#global.entity_yield[entity.name])]
entity.surface.create_entity({
name = "flying-text",
position = entity.position,
text = "+" .. amount .. " [item=" .. main_item .. "] +" .. second_item_amount .. " [item=" .. second_item .. "]",
color = {r=0.8,g=0.8,b=0.8}})
color = {r=0.8,g=0.8,b=0.8}})
local player = game.players[event.player_index]
local inserted_count = player.insert({name = main_item, count = amount})
local inserted_count = player.insert({name = main_item, count = amount})
amount = amount - inserted_count
if amount > 0 then
entity.surface.spill_item_stack(entity.position,{name = main_item, count = amount}, true)
end
local inserted_count = player.insert({name = second_item, count = second_item_amount})
local inserted_count = player.insert({name = second_item, count = second_item_amount})
second_item_amount = second_item_amount - inserted_count
if second_item_amount > 0 then
entity.surface.spill_item_stack(entity.position,{name = second_item, count = second_item_amount}, true)
end
end
end
end
local function on_research_finished(event)
@ -322,13 +321,13 @@ end
local function on_entity_died(event)
on_player_mined_entity(event)
if not event.entity.valid then return end
if event.entity.type == "tree" then
if event.entity.type == "tree" then
for _, entity in pairs (event.entity.surface.find_entities_filtered({area = {{event.entity.position.x - 4, event.entity.position.y - 4},{event.entity.position.x + 4, event.entity.position.y + 4}}, name = "fire-flame-on-tree"})) do
if entity.valid then entity.destroy() end
end
end
end
end
local on_init = function()
@ -336,17 +335,17 @@ local on_init = function()
T.main_caption = "Choppy"
T.sub_caption = ""
T.text = [[
You are a lumberjack with a passion to chop.
Different kinds of trees, yield different kinds of ore and wood.
You are a lumberjack with a passion to chop.
Different kinds of trees, yield different kinds of ore and wood.
Yes, they seem to draw minerals out of the ground and manifesting it as "fruit".
Their yield increases with distance. Mining Productivity Research will increase chopping speed and backpack size.
Beware, sometimes there are some bugs hiding underneath the trees.
Even dangerous traps have been encountered before.
Also, these mysterious ore trees don't burn very well, so do not worry if some of them catch on fire.
Choppy Choppy Wood
]]
@ -360,4 +359,4 @@ event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruct
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_chunk_generated, on_chunk_generated)
event.add(defines.events.on_chunk_generated, on_chunk_generated)

View File

@ -6,7 +6,6 @@ require "modules.no_deconstruction_of_neutral_entities"
--require "modules.no_solar"
require "maps.chronosphere.comfylatron"
require "maps.chronosphere.terrain"
require "on_tick_schedule"
require "modules.biter_noms_you"
-- require "modules.custom_death_messages"
local Server = require 'utils.server'

View File

@ -1,6 +1,5 @@
--junkyard-- mewmew made this --
require "on_tick_schedule"
require "modules.dynamic_landfill"
require "modules.satellite_score"
require "modules.mineable_wreckage_yields_scrap"
@ -21,7 +20,7 @@ local create_tile_chain = require "functions.create_tile_chain"
local simplex_noise = require 'utils.simplex_noise'
simplex_noise = simplex_noise.d2
local event = require 'utils.event'
local event = require 'utils.event'
local table_insert = table.insert
local math_random = math.random
local map_functions = require "tools.map_functions"
@ -40,26 +39,26 @@ local tile_replacements = {
["grass-3"] = "dirt-5",
["grass-4"] = "dirt-4" ,
["water"] = "water-green",
["deepwater"] = "deepwater-green",
["deepwater"] = "deepwater-green",
["sand-1"] = "dirt-7",
["sand-2"] = "dirt-6",
["sand-3"] = "dirt-5"
["sand-3"] = "dirt-5"
}
local entity_replacements = {
["tree-01"] = "dead-grey-trunk",
["tree-02"] = "tree-06-brown",
["tree-03"] = "dead-grey-trunk",
["tree-04"] = "dry-hairy-tree",
["tree-05"] = "dead-grey-trunk",
["tree-06"] = "tree-06-brown",
["tree-07"] = "dry-hairy-tree",
["tree-08"] = "dead-grey-trunk",
["tree-04"] = "dry-hairy-tree",
["tree-05"] = "dead-grey-trunk",
["tree-06"] = "tree-06-brown",
["tree-07"] = "dry-hairy-tree",
["tree-08"] = "dead-grey-trunk",
["tree-09"] = "tree-06-brown",
["tree-02-red"] = "dry-tree",
--["tree-06-brown"] = "dirt",
["tree-08-brown"] = "tree-06-brown",
["tree-09-brown"] = "tree-06-brown",
["tree-02-red"] = "dry-tree",
--["tree-06-brown"] = "dirt",
["tree-08-brown"] = "tree-06-brown",
["tree-09-brown"] = "tree-06-brown",
["tree-09-red"] = "tree-06-brown",
["iron-ore"] = "mineable-wreckage",
["copper-ore"] = "mineable-wreckage",
@ -67,12 +66,12 @@ local entity_replacements = {
["stone"] = "mineable-wreckage"
}
local wrecks = {"big-ship-wreck-1", "big-ship-wreck-2", "big-ship-wreck-3"}
local wrecks = {"big-ship-wreck-1", "big-ship-wreck-2", "big-ship-wreck-3"}
local scrap_buildings = {
"nuclear-reactor", "centrifuge", "beacon", "chemical-plant", "assembling-machine-1", "assembling-machine-2", "assembling-machine-3", "oil-refinery", "arithmetic-combinator", "constant-combinator", "decider-combinator", "programmable-speaker", "steam-turbine", "steam-engine", "chemical-plant", "assembling-machine-1", "assembling-machine-2", "assembling-machine-3", "oil-refinery", "arithmetic-combinator", "constant-combinator", "decider-combinator", "programmable-speaker", "steam-turbine", "steam-engine"
}
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
@ -82,7 +81,7 @@ local function shuffle(tbl)
return tbl
end
local function get_noise(name, pos)
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
@ -95,15 +94,15 @@ 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.35 + noise[3] * 0.23 + noise[4] * 0.11
local noise = noise[1] + noise[2] * 0.35 + noise[3] * 0.23 + noise[4] * 0.11
return noise
end
end
end
local function create_shipwreck(surface, position)
local raffle = {}
local loot = {
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},
@ -114,22 +113,22 @@ local function create_shipwreck(surface, position)
{{name = "processing-unit", count = math_random(30,60)}, 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 = "rocket-fuel", count = math_random(4,10)}, weight = 2, evolution_min = 0.3, evolution_max = 0.7},
{{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(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1},
{{name = "inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4},
{{name = "long-handed-inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4},
{{name = "long-handed-inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4},
{{name = "fast-inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.1, evolution_max = 1},
{{name = "filter-inserter", count = math_random(4,8)}, weight = 1, evolution_min = 0.2, evolution_max = 1},
{{name = "filter-inserter", count = math_random(4,8)}, weight = 1, evolution_min = 0.2, evolution_max = 1},
{{name = "stack-filter-inserter", count = math_random(2,4)}, weight = 1, evolution_min = 0.4, evolution_max = 1},
{{name = "stack-inserter", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
{{name = "stack-inserter", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
{{name = "small-electric-pole", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
{{name = "medium-electric-pole", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 1},
{{name = "medium-electric-pole", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 1},
{{name = "wooden-chest", count = math_random(16,24)}, 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 = "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},
@ -146,31 +145,31 @@ local function create_shipwreck(surface, position)
{{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 = "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(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 = "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-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 = "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 = "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 = "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},
@ -178,7 +177,7 @@ local function create_shipwreck(surface, position)
{{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}
--{{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)
@ -188,44 +187,44 @@ local function create_shipwreck(surface, position)
distance_to_center = distance_to_center / 2500
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
end
local e = surface.create_entity{name = wrecks[math_random(1,#wrecks)], position = position, force = "scrap"}
local e = surface.create_entity{name = wrecks[math_random(1,#wrecks)], position = position, force = "scrap"}
for x = 1, math_random(2,3), 1 do
local loot = raffle[math_random(1,#raffle)]
e.insert(loot)
end
end
end
local function secret_shop(pos, surface)
local secret_market_items = {
{price = {{"coin", math_random(30,60)}}, offer = {type = 'give-item', item = 'construction-robot'}},
local secret_market_items = {
{price = {{"coin", math_random(30,60)}}, offer = {type = 'give-item', item = 'construction-robot'}},
{price = {{"coin", math_random(100,200)}}, offer = {type = 'give-item', item = 'loader'}},
{price = {{"coin", math_random(200,300)}}, offer = {type = 'give-item', item = 'fast-loader'}},
{price = {{"coin", math_random(300,500)}}, offer = {type = 'give-item', item = 'express-loader'}},
{price = {{"coin", math_random(100,200)}}, offer = {type = 'give-item', item = 'locomotive'}},
{price = {{"coin", math_random(75,150)}}, offer = {type = 'give-item', item = 'cargo-wagon'}},
{price = {{"coin", math_random(75,150)}}, offer = {type = 'give-item', item = 'cargo-wagon'}},
{price = {{"coin", math_random(2,3)}}, offer = {type = 'give-item', item = 'rail'}},
{price = {{"coin", math_random(4,12)}}, offer = {type = 'give-item', item = 'small-lamp'}},
{price = {{"coin", math_random(4,12)}}, offer = {type = 'give-item', item = 'small-lamp'}},
{price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'car'}},
{price = {{"coin", math_random(300,600)}}, offer = {type = 'give-item', item = 'electric-furnace'}},
{price = {{"coin", math_random(300,600)}}, offer = {type = 'give-item', item = 'electric-furnace'}},
{price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'effectivity-module'}},
{price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'productivity-module'}},
{price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'speed-module'}},
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'wood', count = 50}},
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}},
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}},
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'stone', count = 50}},
{price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'coal', count = 50}},
{price = {{"coin", math_random(8,16)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}},
{price = {{'wood', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}},
{price = {{'iron-ore', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}},
{price = {{'copper-ore', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}},
@ -234,10 +233,10 @@ local function secret_shop(pos, surface)
{price = {{'uranium-ore', math_random(8,10)}}, offer = {type = 'give-item', item = "coin"}}
}
secret_market_items = shuffle(secret_market_items)
local market = surface.create_entity {name = "market", position = pos, force = "neutral"}
market.destructible = false
market.destructible = false
for i = 1, math.random(6, 8), 1 do
market.add_market_item(secret_market_items[i])
end
@ -246,7 +245,7 @@ end
local function place_random_scrap_entity(surface, position)
local r = math.random(1, 100)
if r < 15 then
local e = surface.create_entity({name = scrap_buildings[math.random(1, #scrap_buildings)], position = position, force = "scrap"})
local e = surface.create_entity({name = scrap_buildings[math.random(1, #scrap_buildings)], position = position, force = "scrap"})
if e.name == "nuclear-reactor" then
create_entity_chain(surface, {name = "heat-pipe", position = position, force = "player"}, math_random(16,32), 25)
end
@ -271,13 +270,13 @@ local function place_random_scrap_entity(surface, position)
e.insert({name = "piercing-rounds-magazine", count = math.random(8, 128)})
return
end
local e = surface.create_entity({name = "storage-tank", position = position, force = "scrap", direction = math.random(0, 3)})
local fluids = {"crude-oil", "lubricant", "heavy-oil", "light-oil", "petroleum-gas", "sulfuric-acid", "water"}
e.fluidbox[1] = {name = fluids[math.random(1, #fluids)], amount = math.random(15000, 25000)}
create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(6,8), 1)
create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(6,8), 1)
create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(15,30), 80)
create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(15,30), 80)
end
local function create_inner_content(surface, pos, noise)
@ -289,7 +288,7 @@ local function create_inner_content(surface, pos, noise)
map_functions.draw_noise_entity_ring(surface, pos, "substation", "scrap_defense", 3, 4)
map_functions.draw_noise_entity_ring(surface, pos, "solar-panel", "scrap_defense", 4, 6)
map_functions.draw_noise_entity_ring(surface, pos, "stone-wall", "scrap_defense", 6, 7)
create_tile_chain(surface, {name = "concrete", position = pos}, math_random(16, 32), 50)
create_tile_chain(surface, {name = "concrete", position = pos}, math_random(16, 32), 50)
create_tile_chain(surface, {name = "stone-path", position = pos}, math_random(16, 32), 50)
@ -297,7 +296,7 @@ local function create_inner_content(surface, pos, noise)
--create_entity_chain(surface, {name = "laser-turret", position = pos, force = "scrap_defense"}, 1, 25)
--create_entity_chain(surface, {name = "accumulator", position = pos, force = "scrap_defense"}, math_random(2, 4), 1)
--create_entity_chain(surface, {name = "substation", position = pos, force = "scrap_defense"}, math_random(6, 8), 1)
-- create_entity_chain(surface, {name = "solar-panel", position = pos, force = "scrap_defense"}, math_random(16, 24), 1)
-- create_entity_chain(surface, {name = "solar-panel", position = pos, force = "scrap_defense"}, math_random(16, 24), 1)
end
return
end
@ -308,13 +307,13 @@ local function create_inner_content(surface, pos, noise)
surface.create_entity({name = "biter-spawner", position = pos})
end
end
return
return
end
end
local function process_entity(e)
if not e.valid then return end
if entity_replacements[e.name] then
if entity_replacements[e.name] then
if e.type == "tree" then
if math_random(1,2) == 1 then
e.surface.create_entity({name = entity_replacements[e.name], position = e.position})
@ -325,8 +324,8 @@ local function process_entity(e)
e.destroy()
return
end
if e.type == "unit-spawner" then
if e.type == "unit-spawner" then
for _, wreck in pairs (e.surface.find_entities_filtered({area = {{e.position.x - 4, e.position.y - 4},{e.position.x + 4, e.position.y + 4}}, name = "mineable-wreckage"})) do
if wreck.valid then wreck.destroy() end
end
@ -338,21 +337,21 @@ local function on_chunk_generated(event)
local surface = event.surface
local left_top = event.area.left_top
local tiles = {}
local entities = {}
local entities = {}
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.43 or noise < -0.43 then
local noise = get_noise(1, pos)
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
@ -361,27 +360,27 @@ local function on_chunk_generated(event)
else
if math_random(1,512) == 1 then
place_random_scrap_entity(surface, pos)
end
end
end
end
else
create_inner_content(surface, pos, noise)
end
end
end
end
end
surface.set_tiles(tiles, true)
surface.set_tiles(tiles, true)
for _, e in pairs(surface.find_entities_filtered({area = event.area})) do
process_entity(e)
process_entity(e)
end
if global.spawn_generated then return end
if left_top.x < 96 then return end
if left_top.x < 96 then return end
map_functions.draw_rainbow_patch_v2({x = 0, y = 0}, surface, 12, 2500)
local p = surface.find_non_colliding_position("character-corpse", {2,-2}, 32, 2)
local e = surface.create_entity({name = "character-corpse", position = p})
local e = surface.create_entity({name = "character-corpse", position = p})
for _, e in pairs (surface.find_entities_filtered({area = {{-50, -50},{50, 50}}})) do
local distance_to_center = math.sqrt(e.position.x^2 + e.position.y^2)
if e.valid then
@ -391,7 +390,7 @@ local function on_chunk_generated(event)
if distance_to_center < 30 and e.name == "gun-turret" then e.destroy() end
end
end
global.spawn_generated = true
global.spawn_generated = true
end
local function on_chunk_charted(event)
@ -400,18 +399,18 @@ local function on_chunk_charted(event)
local position = event.position
if global.chunks_charted[tostring(position.x) .. tostring(position.y)] then return end
global.chunks_charted[tostring(position.x) .. tostring(position.y)] = true
local decorative_names = {}
for k,v in pairs(game.decorative_prototypes) do
if v.autoplace_specification then
decorative_names[#decorative_names+1] = k
end
end
surface.regenerate_decorative(decorative_names, {position})
surface.regenerate_decorative(decorative_names, {position})
if math_random(1, 16) ~= 1 then return end
local pos = {x = position.x * 32 + math_random(1,32), y = position.y * 32 + math_random(1,32)}
local noise = get_noise(1, pos)
local noise = get_noise(1, pos)
if noise > 0.4 or noise < -0.4 then return end
local distance_to_center = math.sqrt(pos.x^2 + pos.y^2)
local size = 7 + math.floor(distance_to_center * 0.0075)
@ -419,36 +418,36 @@ local function on_chunk_charted(event)
local amount = 500 + distance_to_center * 2
map_functions.draw_rainbow_patch_v2(pos, surface, size, amount)
end
local function on_marked_for_deconstruction(event)
local function on_marked_for_deconstruction(event)
if disabled_for_deconstruction[event.entity.name] then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
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 = 16})
end
end
if global.map_init_done then return end
game.forces["player"].technologies["optics"].researched = true
game.surfaces["nauvis"].ticks_per_day = game.surfaces["nauvis"].ticks_per_day * 2
game.surfaces["nauvis"].min_brightness = 0.08
game.surfaces["nauvis"].daytime = 0.7
game.create_force("scrap")
game.create_force("scrap_defense")
game.forces.player.set_friend('scrap', true)
game.forces.enemy.set_friend('scrap', true)
game.forces.scrap.set_friend('player', true)
game.forces.scrap.set_friend('enemy', true)
game.forces.scrap.share_chart = false
game.forces.scrap.set_friend('enemy', true)
game.forces.scrap.share_chart = false
global.map_init_done = true
end
@ -461,13 +460,13 @@ 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
if math_random(1,40) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,12)) end
if math_random(1,80) == 1 then unearthing_worm(entity.surface, entity.position) end
if entity.name == "mineable-wreckage" then
if math_random(1,40) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,12)) end
if math_random(1,80) == 1 then unearthing_worm(entity.surface, entity.position) end
if math_random(1,160) == 1 then tick_tack_trap(entity.surface, entity.position) end
end
if entity.force.name ~= "scrap" then return end
local positions = {}
local r = math.ceil(entity.prototype.max_health / 32)
@ -483,7 +482,7 @@ local function on_player_mined_entity(event)
unearthing_biters(entity.surface, positions[i], math_random(5,10))
else
unearthing_worm(entity.surface, positions[i])
end
end
end
end
@ -534,4 +533,4 @@ event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_chunk_generated, on_chunk_generated)
event.add(defines.events.on_chunk_charted, on_chunk_charted)
event.add(defines.events.on_chunk_charted, on_chunk_charted)

View File

@ -4,7 +4,6 @@ require 'maps.lumberjack.comfylatron'
require 'maps.lumberjack.commands'
require 'maps.lumberjack.corpse_util'
require 'on_tick_schedule'
require 'modules.dynamic_landfill'
require 'modules.shotgun_buff'
require 'modules.burden'

View File

@ -1,6 +1,5 @@
--overgrowth-- by mewmew --
require 'on_tick_schedule'
require 'modules.dynamic_landfill'
require 'modules.satellite_score'
require 'modules.spawners_contain_biters'

View File

@ -1,6 +1,5 @@
local event = require 'utils.event'
local simplex_noise = require 'utils.simplex_noise'.d2
require "on_tick_schedule"
require "modules.satellite_score"
require "modules.biter_noms_you"
require "modules.dangerous_goods"
@ -26,29 +25,29 @@ local function init_surface()
local map_gen_settings = {}
map_gen_settings.water = "0.12"
map_gen_settings.starting_area = "0.5"
map_gen_settings.cliff_settings = {cliff_elevation_interval = 7, cliff_elevation_0 = 7}
map_gen_settings.cliff_settings = {cliff_elevation_interval = 7, cliff_elevation_0 = 7}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = "0", size = "7", richness = "1"},
["stone"] = {frequency = "0", size = "2.0", richness = "0.5"},
["iron-ore"] = {frequency = "0", size = "2.0", richness = "0.5"},
["copper-ore"] = {frequency = "0", size = "2.0", richness = "0.5"},
["uranium-ore"] = {frequency = "0", size = "1", richness = "0.5"},
["uranium-ore"] = {frequency = "0", size = "1", richness = "0.5"},
["crude-oil"] = {frequency = "5", size = "1", richness = "1"},
["trees"] = {frequency = "3", size = "0.85", richness = "0.1"},
["enemy-base"] = {frequency = "5", size = "3", richness = "1"}
}
game.difficulty_settings.technology_price_multiplier = 2
local surface = game.create_surface("rocky_waste", map_gen_settings)
local surface = game.create_surface("rocky_waste", map_gen_settings)
surface.request_to_generate_chunks({x = 0, y = 0}, 3)
surface.force_generate_chunk_requests()
surface.daytime = 0.7
surface.ticks_per_day = surface.ticks_per_day * 2
surface.min_brightness = 0.1
game.forces["player"].set_spawn_position({0,0},game.surfaces["rocky_waste"])
return surface
end
@ -67,7 +66,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.35 + noise[3] * 0.23 + noise[4] * 0.11
local noise = noise[1] + noise[2] * 0.35 + noise[3] * 0.23 + noise[4] * 0.11
return noise
end
seed = seed + noise_seed_add * 5
@ -75,24 +74,24 @@ local function get_noise(name, pos)
local noise = {}
noise[1] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
local noise = noise[1] + noise[2] * 0.1
noise[2] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
local noise = noise[1] + noise[2] * 0.1
return noise
end
end
local function process_tile(surface, pos)
local tile = surface.get_tile(pos)
if tile.collides_with("player-layer") then return end
local noise = get_noise(1, pos)
local noise = get_noise(1, pos)
if noise < 0.09 and noise > -0.09 then
return
end
local noise_2 = get_noise(2, pos)
local noise_2 = get_noise(2, pos)
if noise_2 < 0.06 and noise_2 > -0.06 then
if math.random(1,6) ~= 1 then
surface.set_tiles({{name = "water", position = pos}})
@ -102,7 +101,7 @@ local function process_tile(surface, pos)
end
return
end
if math.random(1,6) ~= 1 then
surface.create_entity({name = "rock-big", position = pos, force = "neutral"})
end
@ -127,28 +126,28 @@ local function on_chunk_generated(event)
process_tile(surface, pos)
end
end
for _, e in pairs(surface.find_entities_filtered({type = "unit-spawner", area = event.area})) do
clear_entities_around_position(surface, 7, e.position, {"rock-big"})
end
for _, e in pairs(surface.find_entities_filtered({type = "cliff", area = event.area})) do
clear_entities_around_position(surface, 2.25, e.position, {"rock-big"})
end
for _, e in pairs(surface.find_entities_filtered({type = "tree", area = event.area})) do
clear_entities_around_position(surface, 1, e.position, {"rock-big"})
end
if left_top.x == 128 and left_top.y == 128 then
clear_entities_around_position(surface, 5, {x = 0, y = 0}, {"rock-big"})
end
end
local function on_player_joined_game(event)
local surface = init_surface()
local surface = init_surface()
local player = game.players[event.player_index]
if player.online_time == 0 then
if not spawn_pos then spawn_pos = {x = 0, y = 0} end
game.forces.player.set_spawn_position(spawn_pos, surface)
@ -164,17 +163,17 @@ local unearthing_biters = require "functions.unearthing_biters"
local function on_player_mined_entity(event)
local entity = event.entity
if not entity.valid then return end
if not entity.valid then return end
if entity.force.name ~= "neutral" then return end
if math.random(1,256) == 1 then unearthing_worm(entity.surface, entity.position) return end
if math.random(1,256) == 1 then unearthing_biters(entity.surface, entity.position, math.random(4,16)) return end
if math.random(1,256) == 1 then unearthing_biters(entity.surface, entity.position, math.random(4,16)) return end
end
local function on_init()
end
event.on_init(on_init)
event.add(defines.events.on_chunk_generated, on_chunk_generated)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)

View File

@ -1,7 +1,6 @@
-- territorial control by Gerkiz
local Map = require "modules.map_info"
require "on_tick_schedule"
require "modules.fish_respawner"
global.fish_respawner_water_tiles_per_fish = 16
@ -126,7 +125,7 @@ local function secret_shop(pos, surface)
{price = {{"coin", 1}}, offer = {type = 'give-item', item = 'iron-ore', count = math_random(25,75)}},
{price = {{"coin", 1}}, offer = {type = 'give-item', item = 'copper-ore', count = math_random(25,75)}},
{price = {{"coin", 1}}, offer = {type = 'give-item', item = 'stone', count = math_random(25,75)}},
{price = {{"coin", 1}}, offer = {type = 'give-item', item = 'coal', count = math_random(25,75)}},
{price = {{"coin", 1}}, offer = {type = 'give-item', item = 'coal', count = math_random(25,75)}},
{price = {{"coin", 1}}, offer = {type = 'give-item', item = 'uranium-ore', count = math_random(25,75)}}
}
secret_market_items = shuffle(secret_market_items)
@ -240,7 +239,7 @@ local function get_noise_tile(position)
local noise_2 = get_noise("water", position)
if noise_2 > 0.71 then
tile_name = "water"
tile_name = "water"
if noise_2 > 0.78 then
tile_name = "deepwater"
end
@ -259,7 +258,7 @@ local function uncover_map(surface, position, radius_min, radius_max)
local fishes = {}
for r = radius_min, radius_max, 1 do
for _, position_modifier in pairs(circles[r]) do
local pos = {x = position.x + position_modifier.x, y = position.y + position_modifier.y}
local pos = {x = position.x + position_modifier.x, y = position.y + position_modifier.y}
if surface.get_tile(pos).name == "out-of-map" then
local tile_name = get_noise_tile(pos)
insert(tiles, {name = tile_name, position = pos})
@ -292,7 +291,7 @@ local function uncover_map(surface, position, radius_min, radius_max)
surface.set_tiles(tiles, true)
end
for _, fish in pairs(fishes) do
surface.create_entity({name = "fish", position = fish})
surface.create_entity({name = "fish", position = fish})
end
end
@ -346,7 +345,7 @@ local function uncover_map_for_player(player)
uncover_map(surface, pos, 1, 16)
end
for _, fish in pairs(fishes) do
surface.create_entity({name = "fish", position = fish})
surface.create_entity({name = "fish", position = fish})
end
end
@ -405,7 +404,7 @@ local function on_player_joined_game(event)
end
local surface = game.surfaces["territorial_control"]
if player.online_time < 2 and surface.is_chunk_generated({0,0}) then
if player.online_time < 2 and surface.is_chunk_generated({0,0}) then
player.teleport(surface.find_non_colliding_position("character", {0, 0}, 50, 1), "territorial_control")
else
if player.online_time < 2 then
@ -591,4 +590,4 @@ Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)

View File

@ -1,139 +1,169 @@
-- all the kabooms -- by mewmew
-- modified by Gerkiz
local Event = require 'utils.event'
local Global = require 'utils.global'
local traps = {}
Global.register(
traps,
function(t)
traps = t
end
)
local event = require 'utils.event'
local math_random = math.random
local valid_container_types = {
["container"] = true,
["logistic-container"] = true,
["car"] = true,
["cargo-wagon"] = true
['container'] = true,
['logistic-container'] = true,
['car'] = true,
['cargo-wagon'] = true
}
local projectile_types = {
["explosives"] = {name = "grenade", count = 0.5, max_range = 32, tick_speed = 1},
["land-mine"] = {name = "grenade", count = 1, max_range = 32, tick_speed = 1},
["grenade"] = {name = "grenade", count = 1, max_range = 40, tick_speed = 1},
["cluster-grenade"] = {name = "cluster-grenade", count = 1, max_range = 40, tick_speed = 3},
["artillery-shell"] = {name = "artillery-projectile", count = 1, max_range = 60, tick_speed = 3},
["cannon-shell"] = {name = "cannon-projectile", count = 1, max_range = 60, tick_speed = 1},
["explosive-cannon-shell"] = {name = "explosive-cannon-projectile", count = 1, max_range = 60, tick_speed = 1},
["explosive-uranium-cannon-shell"] = {name = "explosive-uranium-cannon-projectile", count = 1, max_range = 60, tick_speed = 1},
["uranium-cannon-shell"] = {name = "uranium-cannon-projectile", count = 1, max_range = 60, tick_speed = 1},
["atomic-bomb"] = {name = "atomic-rocket", count = 1, max_range = 80, tick_speed = 20},
["explosive-rocket"] = {name = "explosive-rocket", count = 1, max_range = 48, tick_speed = 1},
["rocket"] = {name = "rocket", count = 1, max_range = 48, tick_speed = 1},
["flamethrower-ammo"] = {name = "flamethrower-fire-stream", count = 4, max_range = 28, tick_speed = 1},
["crude-oil-barrel"] = {name = "flamethrower-fire-stream", count = 3, max_range = 24, tick_speed = 1},
["petroleum-gas-barrel"] = {name = "flamethrower-fire-stream", count = 4, max_range = 24, tick_speed = 1},
["light-oil-barrel"] = {name = "flamethrower-fire-stream", count = 4, max_range = 24, tick_speed = 1},
["heavy-oil-barrel"] = {name = "flamethrower-fire-stream", count = 4, max_range = 24, tick_speed = 1},
["sulfuric-acid-barrel"] = {name = "acid-stream-spitter-big", count = 3, max_range = 16, tick_speed = 1, force = "enemy"},
["lubricant-barrel"] = {name = "acid-stream-spitter-big", count = 3, max_range = 16, tick_speed = 1},
["railgun-dart"] = {name = "railgun-beam", count = 5, max_range = 40, tick_speed = 5},
["shotgun-shell"] = {name = "shotgun-pellet", count = 16, max_range = 24, tick_speed = 1},
["piercing-shotgun-shell"] = {name = "piercing-shotgun-pellet", count = 16, max_range = 24, tick_speed = 1},
["firearm-magazine"] = {name = "shotgun-pellet", count = 16, max_range = 24, tick_speed = 1},
["piercing-rounds-magazine"] = {name = "piercing-shotgun-pellet", count = 16, max_range = 24, tick_speed = 1},
["uranium-rounds-magazine"] = {name = "piercing-shotgun-pellet", count = 32, max_range = 24, tick_speed = 1},
["cliff-explosives"] = {name = "cliff-explosives", count = 1, max_range = 48, tick_speed = 2},
['explosives'] = {name = 'grenade', count = 0.5, max_range = 32, tick_speed = 1},
['land-mine'] = {name = 'grenade', count = 1, max_range = 32, tick_speed = 1},
['grenade'] = {name = 'grenade', count = 1, max_range = 40, tick_speed = 1},
['cluster-grenade'] = {name = 'cluster-grenade', count = 1, max_range = 40, tick_speed = 3},
['artillery-shell'] = {name = 'artillery-projectile', count = 1, max_range = 60, tick_speed = 3},
['cannon-shell'] = {name = 'cannon-projectile', count = 1, max_range = 60, tick_speed = 1},
['explosive-cannon-shell'] = {name = 'explosive-cannon-projectile', count = 1, max_range = 60, tick_speed = 1},
['explosive-uranium-cannon-shell'] = {
name = 'explosive-uranium-cannon-projectile',
count = 1,
max_range = 60,
tick_speed = 1
},
['uranium-cannon-shell'] = {name = 'uranium-cannon-projectile', count = 1, max_range = 60, tick_speed = 1},
['atomic-bomb'] = {name = 'atomic-rocket', count = 1, max_range = 80, tick_speed = 20},
['explosive-rocket'] = {name = 'explosive-rocket', count = 1, max_range = 48, tick_speed = 1},
['rocket'] = {name = 'rocket', count = 1, max_range = 48, tick_speed = 1},
['flamethrower-ammo'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 28, tick_speed = 1},
['crude-oil-barrel'] = {name = 'flamethrower-fire-stream', count = 3, max_range = 24, tick_speed = 1},
['petroleum-gas-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1},
['light-oil-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1},
['heavy-oil-barrel'] = {name = 'flamethrower-fire-stream', count = 4, max_range = 24, tick_speed = 1},
['sulfuric-acid-barrel'] = {
name = 'acid-stream-spitter-big',
count = 3,
max_range = 16,
tick_speed = 1,
force = 'enemy'
},
['lubricant-barrel'] = {name = 'acid-stream-spitter-big', count = 3, max_range = 16, tick_speed = 1},
['railgun-dart'] = {name = 'railgun-beam', count = 5, max_range = 40, tick_speed = 5},
['shotgun-shell'] = {name = 'shotgun-pellet', count = 16, max_range = 24, tick_speed = 1},
['piercing-shotgun-shell'] = {name = 'piercing-shotgun-pellet', count = 16, max_range = 24, tick_speed = 1},
['firearm-magazine'] = {name = 'shotgun-pellet', count = 16, max_range = 24, tick_speed = 1},
['piercing-rounds-magazine'] = {name = 'piercing-shotgun-pellet', count = 16, max_range = 24, tick_speed = 1},
['uranium-rounds-magazine'] = {name = 'piercing-shotgun-pellet', count = 32, max_range = 24, tick_speed = 1},
['cliff-explosives'] = {name = 'cliff-explosives', count = 1, max_range = 48, tick_speed = 2}
}
local function create_projectile(surface, name, position, force, target, max_range)
surface.create_entity({
name = name,
position = position,
force = force,
source = position,
target = target,
max_range = max_range,
speed = 0.4
})
surface.create_entity(
{
name = name,
position = position,
force = force,
source = position,
target = target,
max_range = max_range,
speed = 0.4
}
)
end
local function get_near_range(range)
local r = math_random(1, math.floor(range * 2))
for i = 1, 2, 1 do
local r2 = math_random(1, math.floor(range * 2))
if r2 < r then r = r2 end
end
return r
local r = math_random(1, math.floor(range * 2))
for i = 1, 2, 1 do
local r2 = math_random(1, math.floor(range * 2))
if r2 < r then
r = r2
end
end
return r
end
local function get_near_coord_modifier(range)
local coord = {x = (range * -1) + math_random(0, range * 2), y = (range * -1) + math_random(0, range * 2)}
for i = 1, 5, 1 do
local new_coord = {x = (range * -1) + math_random(0, range * 2), y = (range * -1) + math_random(0, range * 2)}
if new_coord.x^2 + new_coord.y^2 < coord.x^2 + coord.y^2 then
coord = new_coord
end
end
return coord
local coord = {x = (range * -1) + math_random(0, range * 2), y = (range * -1) + math_random(0, range * 2)}
for i = 1, 5, 1 do
local new_coord = {x = (range * -1) + math_random(0, range * 2), y = (range * -1) + math_random(0, range * 2)}
if new_coord.x ^ 2 + new_coord.y ^ 2 < coord.x ^ 2 + coord.y ^ 2 then
coord = new_coord
end
end
return coord
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then return end
if not valid_container_types[entity.type] then return end
local inventory = defines.inventory.chest
if entity.type == "car" then inventory = defines.inventory.car_trunk end
local i = entity.get_inventory(inventory)
for key, projectile in pairs(projectile_types) do
local amount = i.get_item_count(key)
local force = entity.force.name
if projectile.force then force = projectile.force end
local projectile_count = amount * projectile.count
if amount > 0 then
for t = 0, amount * projectile.tick_speed, projectile.tick_speed do
if not global.dangerous_on_tick_schedule[game.tick + t + 1] then global.dangerous_on_tick_schedule[game.tick + t + 1] = {} end
for c = 1, math.ceil(projectile.count), 1 do
local coord_modifier = get_near_coord_modifier(projectile.max_range)
global.dangerous_on_tick_schedule[game.tick + t + 1][#global.dangerous_on_tick_schedule[game.tick + t + 1] + 1] = {
func = create_projectile,
args = {
entity.surface,
projectile.name,
{x = entity.position.x, y = entity.position.y},
force,
{entity.position.x + coord_modifier.x, entity.position.y + coord_modifier.y},
get_near_range(projectile.max_range)
}
}
projectile_count = projectile_count - 1
end
if projectile_count <= 0 then break end
end
end
end
local entity = event.entity
if not entity.valid then
return
end
if not valid_container_types[entity.type] then
return
end
local inventory = defines.inventory.chest
if entity.type == 'car' then
inventory = defines.inventory.car_trunk
end
local i = entity.get_inventory(inventory)
for key, projectile in pairs(projectile_types) do
local amount = i.get_item_count(key)
local force = entity.force.name
if projectile.force then
force = projectile.force
end
local projectile_count = amount * projectile.count
if amount > 0 then
for t = 0, amount * projectile.tick_speed, projectile.tick_speed do
if not traps[game.tick + t + 1] then
traps[game.tick + t + 1] = {}
end
for _ = 1, math.ceil(projectile.count), 1 do
local coord_modifier = get_near_coord_modifier(projectile.max_range)
traps[game.tick + t + 1][#traps[game.tick + t + 1] + 1] = {
callback = 'create_projectile',
params = {
entity.surface,
projectile.name,
{x = entity.position.x, y = entity.position.y},
force,
{entity.position.x + coord_modifier.x, entity.position.y + coord_modifier.y},
get_near_range(projectile.max_range)
}
}
projectile_count = projectile_count - 1
end
if projectile_count <= 0 then
break
end
end
end
end
end
local function on_tick()
if not global.dangerous_on_tick_schedule[game.tick] then return end
for _, schedule in pairs(global.dangerous_on_tick_schedule[game.tick]) do
schedule.func(unpack(schedule.args))
end
global.dangerous_on_tick_schedule[game.tick] = nil
local function on_tick()
if not traps[game.tick] then
return
end
for _, token in pairs(traps[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'create_projectile' then
create_projectile(params[1], params[2], params[3], params[4], params[5], params[6])
end
end
traps[game.tick] = nil
end
local function on_init(event)
if not global.dangerous_on_tick_schedule then global.dangerous_on_tick_schedule = {} end
end
event.on_init(on_init)
event.add(defines.events.on_tick, on_tick)
event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -1,229 +1,378 @@
local event = require 'utils.event'
-- by mewmew
-- modified by Gerkiz
local function teleport_player(surface, source_player, position)
local materializing_characters = source_player.surface.find_entities_filtered({
name = "character",
area = {{position.x - 1, position.y - 1},{position.x + 1, position.y + 1}},
force = "neutral"
})
for _, e in pairs(materializing_characters) do
if e.valid then e.destroy() end
end
if not source_player.character then return end
surface.create_entity({name = "character-corpse", position = source_player.position, force = source_player.force.name})
source_player.teleport(position, surface)
if source_player.character.health < 25 then source_player.character.health = 250 end
global.team_teleport_delay[source_player.name] = game.tick + 18000
local Event = require 'utils.event'
local Global = require 'utils.global'
local traps = {}
Global.register(
traps,
function(t)
traps = t
end
)
local function teleport_player(surface, source_player, position)
local materializing_characters =
source_player.surface.find_entities_filtered(
{
name = 'character',
area = {{position.x - 1, position.y - 1}, {position.x + 1, position.y + 1}},
force = 'neutral'
}
)
for _, e in pairs(materializing_characters) do
if e.valid then
e.destroy()
end
end
if not source_player.character then
return
end
surface.create_entity(
{name = 'character-corpse', position = source_player.position, force = source_player.force.name}
)
source_player.teleport(position, surface)
if source_player.character.health < 25 then
source_player.character.health = 250
end
global.team_teleport_delay[source_player.name] = game.tick + 18000
end
local function fix_player_position(source_player, original_position)
if not source_player.character then return end
if source_player.position.x == original_position.x and source_player.position.y == original_position.y then return end
source_player.teleport(original_position, source_player.surface)
if not source_player.character then
return
end
if source_player.position.x == original_position.x and source_player.position.y == original_position.y then
return
end
source_player.teleport(original_position, source_player.surface)
end
local function teleport_effects(surface, position)
local x = position.x + (4 - (math.random(1,80) * 0.1))
surface.create_entity({
name = "railgun-beam",
position = {x = position.x, y = position.y},
target = {x = x, y = position.y - math.random(6,13)}
})
for y = 0, 1, 1 do
surface.create_entity({
name = "water-splash",
position = {x = position.x, y = position.y + y},
})
end
if math.random(1,40) == 1 then surface.create_entity({name = "explosion", position = {x = position.x + (3 - (math.random(1,60) * 0.1)), y = position.y + (3 - (math.random(1,60) * 0.1))}}) end
if math.random(1,32) == 1 then surface.create_entity({name = "blood-explosion-huge", position = position}) end
if math.random(1,16) == 1 then surface.create_entity({name = "blood-explosion-big", position = position}) end
if math.random(1,8) == 1 then surface.create_entity({name = "blood-explosion-small", position = position}) end
local function teleport_effects(surface, position)
local x = position.x + (4 - (math.random(1, 80) * 0.1))
surface.create_entity(
{
name = 'railgun-beam',
position = {x = position.x, y = position.y},
target = {x = x, y = position.y - math.random(6, 13)}
}
)
for y = 0, 1, 1 do
surface.create_entity(
{
name = 'water-splash',
position = {x = position.x, y = position.y + y}
}
)
end
if math.random(1, 40) == 1 then
surface.create_entity(
{
name = 'explosion',
position = {
x = position.x + (3 - (math.random(1, 60) * 0.1)),
y = position.y + (3 - (math.random(1, 60) * 0.1))
}
}
)
end
if math.random(1, 32) == 1 then
surface.create_entity({name = 'blood-explosion-huge', position = position})
end
if math.random(1, 16) == 1 then
surface.create_entity({name = 'blood-explosion-big', position = position})
end
if math.random(1, 8) == 1 then
surface.create_entity({name = 'blood-explosion-small', position = position})
end
end
local function sync_health_and_direction(player, materializing_character)
if not player.character then return end
if not player.character.valid then return end
if not materializing_character then return end
if not materializing_character.valid then return end
materializing_character.health = materializing_character.health + 2
materializing_character.direction = player.character.direction
if player.character.health < 3 then player.character.health = 1 return end
if player.character.health == 250 then player.character.damage(2, "player") return end
if math.random(1,64) == 1 then player.character.damage(2, "player") return end
player.character.health = player.character.health - 2
if not player.character then
return
end
if not player.character.valid then
return
end
if not materializing_character then
return
end
if not materializing_character.valid then
return
end
materializing_character.health = materializing_character.health + 2
materializing_character.direction = player.character.direction
if player.character.health < 3 then
player.character.health = 1
return
end
if player.character.health == 250 then
player.character.damage(2, 'player')
return
end
if math.random(1, 64) == 1 then
player.character.damage(2, 'player')
return
end
player.character.health = player.character.health - 2
end
local function teleport(source_player, target_player)
source_player.teleport({x = math.floor(source_player.position.x), y = math.floor(source_player.position.y)})
local target_position = target_player.surface.find_non_colliding_position("character", target_player.position, 128, 1)
if not target_position then target_position = {x = target_player.position.x, y = target_player.position.y} end
local materializing_character = target_player.surface.create_entity({name = "character", position = target_position, force = "neutral", direction = source_player.character.direction})
materializing_character.destructible = false
materializing_character.color = source_player.color
materializing_character.damage(1, "player")
materializing_character.health = 1
source_player.teleport({x = math.floor(source_player.position.x), y = math.floor(source_player.position.y)})
local target_position =
target_player.surface.find_non_colliding_position('character', target_player.position, 128, 1)
if not target_position then
target_position = {x = target_player.position.x, y = target_player.position.y}
end
local materializing_character =
target_player.surface.create_entity(
{
name = 'character',
position = target_position,
force = 'neutral',
direction = source_player.character.direction
}
)
materializing_character.destructible = false
materializing_character.color = source_player.color
materializing_character.damage(1, 'player')
materializing_character.health = 1
local a = 20
for t = 0, 780, 1 do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
if t % a == 0 then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = teleport_effects,
args = {source_player.surface, {x = source_player.position.x, y = source_player.position.y}}
}
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = teleport_effects,
args = {source_player.surface, target_position}
}
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = sync_health_and_direction,
args = {source_player, materializing_character}
}
a = a - 0.5
if a < 5 then a = 5 end
end
if t % 2 == 0 then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = fix_player_position,
args = {source_player, {x = source_player.position.x, y = source_player.position.y}}
}
end
if t == 780 then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = teleport_player,
args = {target_player.surface, source_player, target_position}
}
end
end
local a = 20
for t = 0, 780, 1 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
end
if t % a == 0 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'teleport_effects',
params = {source_player.surface, {x = source_player.position.x, y = source_player.position.y}}
}
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'teleport_effects',
params = {source_player.surface, target_position}
}
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'sync_health_and_direction',
params = {source_player, materializing_character}
}
a = a - 0.5
if a < 5 then
a = 5
end
end
if t % 2 == 0 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'fix_player_position',
params = {source_player, {x = source_player.position.x, y = source_player.position.y}}
}
end
if t == 780 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'teleport_player',
params = {target_player.surface, source_player, target_position}
}
end
end
end
local function get_sorted_player_table(requesting_player)
local t = {}
for _, player in pairs(game.connected_players) do
if player.name ~= requesting_player.name and player.force == requesting_player.force then
local distance = math.ceil(math.sqrt((player.position.x - requesting_player.position.x)^2 + (player.position.y - requesting_player.position.y)^2) * 10) * 0.1
table.insert(t, {name = player.name, distance = distance})
end
end
for i = 1, #t, 1 do
for i2 = 1, #t, 1 do
if t[i].distance > t[i2].distance then
local k = t[i]
t[i] = t[i2]
t[i2] = k
end
end
end
return t
local t = {}
for _, player in pairs(game.connected_players) do
if player.name ~= requesting_player.name and player.force == requesting_player.force then
local distance =
math.ceil(
math.sqrt(
(player.position.x - requesting_player.position.x) ^ 2 +
(player.position.y - requesting_player.position.y) ^ 2
) * 10
) * 0.1
table.insert(t, {name = player.name, distance = distance})
end
end
for i = 1, #t, 1 do
for i2 = 1, #t, 1 do
if t[i].distance > t[i2].distance then
local k = t[i]
t[i] = t[i2]
t[i2] = k
end
end
end
return t
end
local function create_gui_toggle_button(player)
if player.gui.top["team_teleport_button"] then return end
local b = player.gui.top.add({type = "sprite-button", name = "team_teleport_button", caption = "TP", tooltip = "Teleport to a Team Member"})
b.style.font_color = {r = 0.55, g = 0.22, b = 0.77}
b.style.font = "heading-1"
b.style.minimal_height = 38
b.style.minimal_width = 38
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
if player.gui.top['team_teleport_button'] then
return
end
local b =
player.gui.top.add(
{type = 'sprite-button', name = 'team_teleport_button', caption = 'TP', tooltip = 'Teleport to a Team Member'}
)
b.style.font_color = {r = 0.55, g = 0.22, b = 0.77}
b.style.font = 'heading-1'
b.style.minimal_height = 38
b.style.minimal_width = 38
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
end
local function create_teleport_gui(player)
if player.gui.center["team_teleport"] then player.gui.center["team_teleport"].destroy() end
local frame = player.gui.center.add({type = "frame", name = "team_teleport", caption = "<< Teleport to player >>"})
frame.style.font_color = {r = 0.55, g = 0.22, b = 0.77}
frame.style.font = "heading-1"
local scroll_pane = frame.add({ type = "scroll-pane", name = "scroll_pane", direction = "vertical", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"})
scroll_pane.style.maximal_height = 320
scroll_pane.style.minimal_height = 320
local t = scroll_pane.add({type = "table", column_count = 3, name = "team_teleport_table"})
local player_table = get_sorted_player_table(player)
for _, k in pairs(player_table) do
local l = t.add({type = "button", name = k.name, caption = k.name})
l.style.font_color = {r = game.players[k.name].color.r * 0.5, g = game.players[k.name].color.g * 0.5, b = game.players[k.name].color.b * 0.5}
l.style.font = "heading-2"
l.style.minimal_width = 120
local l = t.add({type = "label", caption = " Distance: "})
l.style.font = "heading-2"
local l = t.add({type = "label", caption = tostring(k.distance)})
l.style.font_color = {r = 0.66, g = 0.66, b = 0.99}
l.style.font = "heading-2"
l.style.minimal_width = 100
end
if player.gui.center['team_teleport'] then
player.gui.center['team_teleport'].destroy()
end
local frame = player.gui.center.add({type = 'frame', name = 'team_teleport', caption = '<< Teleport to player >>'})
frame.style.font_color = {r = 0.55, g = 0.22, b = 0.77}
frame.style.font = 'heading-1'
local scroll_pane =
frame.add(
{
type = 'scroll-pane',
name = 'scroll_pane',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
)
scroll_pane.style.maximal_height = 320
scroll_pane.style.minimal_height = 320
local t = scroll_pane.add({type = 'table', column_count = 3, name = 'team_teleport_table'})
local player_table = get_sorted_player_table(player)
for _, k in pairs(player_table) do
local l = t.add({type = 'button', name = k.name, caption = k.name})
l.style.font_color = {
r = game.players[k.name].color.r * 0.5,
g = game.players[k.name].color.g * 0.5,
b = game.players[k.name].color.b * 0.5
}
l.style.font = 'heading-2'
l.style.minimal_width = 120
local l = t.add({type = 'label', caption = ' Distance: '})
l.style.font = 'heading-2'
local l = t.add({type = 'label', caption = tostring(k.distance)})
l.style.font_color = {r = 0.66, g = 0.66, b = 0.99}
l.style.font = 'heading-2'
l.style.minimal_width = 100
end
end
local function on_gui_click(event)
if not event then return end
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.player_index]
local name = event.element.name
if name == "team_teleport_button" then
if player.gui.center["team_teleport"] then
player.gui.center["team_teleport"].destroy()
return
else
create_teleport_gui(player)
return
end
end
if not game.players[name] then return end
if event.element.parent.name ~= "team_teleport_table" then return end
if not player.character then return end
if not game.players[name].character then return end
if player.character.driving then return end
if game.tick - global.team_teleport_delay[player.name] < 0 then
local recovery_time = math.ceil(math.abs(game.tick - global.team_teleport_delay[player.name]) / 3600)
if recovery_time == 1 then
player.print("You need one more minute to recover from the last teleport.")
else
player.print("You are not capable of handling another teleport yet, you need " .. tostring(recovery_time) .. " more minutes to recover.")
end
return
end
global.team_teleport_delay[player.name] = game.tick + 900
teleport(player, game.players[name])
player.gui.center["team_teleport"].destroy()
if not event then
return
end
if not event.element then
return
end
if not event.element.valid then
return
end
local player = game.players[event.player_index]
local name = event.element.name
if name == 'team_teleport_button' then
if player.gui.center['team_teleport'] then
player.gui.center['team_teleport'].destroy()
return
else
create_teleport_gui(player)
return
end
end
if not game.players[name] then
return
end
if event.element.parent.name ~= 'team_teleport_table' then
return
end
if not player.character then
return
end
if not game.players[name].character then
return
end
if player.character.driving then
return
end
if game.tick - global.team_teleport_delay[player.name] < 0 then
local recovery_time = math.ceil(math.abs(game.tick - global.team_teleport_delay[player.name]) / 3600)
if recovery_time == 1 then
player.print('You need one more minute to recover from the last teleport.')
else
player.print(
'You are not capable of handling another teleport yet, you need ' ..
tostring(recovery_time) .. ' more minutes to recover.'
)
end
return
end
global.team_teleport_delay[player.name] = game.tick + 900
teleport(player, game.players[name])
player.gui.center['team_teleport'].destroy()
end
local function refresh_gui()
for _, p in pairs(game.connected_players) do
if p.gui.center["team_teleport"] then
p.gui.center["team_teleport"].destroy()
create_teleport_gui(p)
end
end
for _, p in pairs(game.connected_players) do
if p.gui.center['team_teleport'] then
p.gui.center['team_teleport'].destroy()
create_teleport_gui(p)
end
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not global.team_teleport_delay then global.team_teleport_delay = {} end
if not global.team_teleport_delay[player.name] then global.team_teleport_delay[player.name] = 0 end
create_gui_toggle_button(player)
refresh_gui()
local player = game.players[event.player_index]
if not global.team_teleport_delay then
global.team_teleport_delay = {}
end
if not global.team_teleport_delay[player.name] then
global.team_teleport_delay[player.name] = 0
end
create_gui_toggle_button(player)
refresh_gui()
end
local function on_player_left_game(event)
refresh_gui()
local function on_player_left_game()
refresh_gui()
end
event.add(defines.events.on_gui_click, on_gui_click)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_left_game, on_player_left_game)
local function on_tick()
if not traps[game.tick] then
return
end
for _, token in pairs(traps[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'teleport_effects' then
teleport_effects(params[1], params[2])
elseif callback == 'sync_health_and_direction' then
sync_health_and_direction(params[1], params[2])
elseif callback == 'fix_player_position' then
fix_player_position(params[1], params[2])
elseif callback == 'teleport_player' then
teleport_player(params[1], params[2], params[3])
end
end
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_left_game, on_player_left_game)

View File

@ -1,15 +0,0 @@
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(unpack(schedule.args))
end
global.on_tick_schedule[game.tick] = nil
end
local function on_init(event)
if not global.on_tick_schedule then global.on_tick_schedule = {} end
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)