1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-30 04:30:58 +02:00
This commit is contained in:
grilledham 2018-05-24 19:09:46 +01:00
commit 62ddc353a7
8 changed files with 851 additions and 1015 deletions

View File

@ -1,5 +1,6 @@
local Event = require 'utils.event'
local Task = require 'utils.Task'
local Token = require 'utils.global_token'
local function on_init()
global.corpse_util_corpses = {}
@ -68,11 +69,14 @@ local function corpse_expired(event)
end
end
function corpse_util_mined_entity(data)
if not data.entity.valid then
remove_tag(data.position)
local corpse_util_mined_entity =
Token.register(
function(data)
if not data.entity.valid then
remove_tag(data.position)
end
end
end
)
local function mined_entity(event)
local entity = event.entity
@ -80,7 +84,7 @@ local function mined_entity(event)
if entity and entity.valid and entity.name == 'character-corpse' then
-- The corpse may be mined but not removed (if player doesn't have inventory space)
-- so we wait one tick to see if the corpse is gone.
Task.set_timeout_in_ticks(1, 'corpse_util_mined_entity', {entity = entity, position = entity.position})
Task.set_timeout_in_ticks(1, corpse_util_mined_entity, {entity = entity, position = entity.position})
end
end

View File

@ -1,16 +1,17 @@
local Task = require "utils.Task"
local Event = require "utils.event"
local Task = require 'utils.Task'
local Event = require 'utils.event'
local Token = require 'utils.global_token'
function player_print(str)
if game.player then
game.player.print(str)
else
log(str)
end
if game.player then
game.player.print(str)
else
log(str)
end
end
function cant_run(name)
player_print("Can't run command (" .. name .. ") - insufficient permission.")
player_print("Can't run command (" .. name .. ') - insufficient permission.')
end
local function invoke(cmd)
@ -18,14 +19,14 @@ local function invoke(cmd)
cant_run(cmd.name)
return
end
local target = cmd["parameter"]
local target = cmd['parameter']
if target == nil or game.players[target] == nil then
player_print("Unknown player.")
player_print('Unknown player.')
return
end
local pos = game.player.surface.find_non_colliding_position("player", game.player.position, 0, 1)
local pos = game.player.surface.find_non_colliding_position('player', game.player.position, 0, 1)
game.players[target].teleport({pos.x, pos.y}, game.player.surface)
game.print(target .. ", get your ass over here!")
game.print(target .. ', get your ass over here!')
end
local function teleport_player(cmd)
@ -33,13 +34,13 @@ local function teleport_player(cmd)
cant_run(cmd.name)
return
end
local target = cmd["parameter"]
local target = cmd['parameter']
if target == nil or game.players[target] == nil then
player_print("Unknown player.")
player_print('Unknown player.')
return
end
local surface = game.players[target].surface
local pos = surface.find_non_colliding_position("player", game.players[target].position, 0, 1)
local pos = surface.find_non_colliding_position('player', game.players[target].position, 0, 1)
game.player.teleport(pos, surface)
game.print(target .. "! watcha doin'?!")
end
@ -50,434 +51,541 @@ local function teleport_location(cmd)
return
end
if game.player.selected == nil then
player_print("Nothing selected.")
player_print('Nothing selected.')
return
end
local pos = game.player.surface.find_non_colliding_position("player", game.player.selected.position, 0, 1)
local pos = game.player.surface.find_non_colliding_position('player', game.player.selected.position, 0, 1)
game.player.teleport(pos)
end
local function kill()
if game.player and game.player.character then
game.player.character.die()
end
if game.player and game.player.character then
game.player.character.die()
end
end
global.walking = {}
local custom_commands_return_player =
Token.register(
function(args)
global.walking[args.player.name:lower()] = false
args.player.character.destroy()
local character = args.player.surface.find_entity('player', args.position)
if character ~= nil and character.valid then
args.player.character = character
else
args.player.create_character()
end
args.player.force = args.force
args.player.teleport(args.position)
game.print(args.player.name .. ' came back from his walkabout.')
end
)
local function walkabout(cmd)
if not ((not game.player) or game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
local params = {}
if cmd.parameter == nil then
player_print("Walkabout failed.")
return
end
for param in string.gmatch(cmd.parameter, "%S+") do table.insert(params, param) end
local player_name = params[1]
local duration = 60
if #params > 2 then
player_print("Walkabout failed, check /help walkabout.")
return
elseif #params == 2 and tonumber(params[2]) == nil then
player_print(params[2] .. " is not a number.")
return
elseif #params == 2 and tonumber(params[2]) then
duration = tonumber(params[2])
end
if duration < 15 then duration = 15 end
if not ((not game.player) or game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
local params = {}
if cmd.parameter == nil then
player_print('Walkabout failed.')
return
end
for param in string.gmatch(cmd.parameter, '%S+') do
table.insert(params, param)
end
local player_name = params[1]
local duration = 60
if #params > 2 then
player_print('Walkabout failed, check /help walkabout.')
return
elseif #params == 2 and tonumber(params[2]) == nil then
player_print(params[2] .. ' is not a number.')
return
elseif #params == 2 and tonumber(params[2]) then
duration = tonumber(params[2])
end
if duration < 15 then
duration = 15
end
local player = game.players[player_name]
if type(player) ~= "table" or global.walking[player_name:lower()] then
player_print(player_name .. " could not go on a walkabout.")
return
end
local chunks = {}
for chunk in player.surface.get_chunks() do
table.insert(chunks, chunk)
end
local player = game.players[player_name]
if type(player) ~= 'table' or global.walking[player_name:lower()] then
player_print(player_name .. ' could not go on a walkabout.')
return
end
local chunks = {}
for chunk in player.surface.get_chunks() do
table.insert(chunks, chunk)
end
local chunk = chunks[math.random(#chunks)]
if not chunk then
return
end
local pos = {x=chunk.x * 32, y=chunk.y * 32}
local non_colliding_pos = player.surface.find_non_colliding_position("player", pos, 100, 1)
local chunk = chunks[math.random(#chunks)]
if not chunk then
return
end
local pos = {x = chunk.x * 32, y = chunk.y * 32}
local non_colliding_pos = player.surface.find_non_colliding_position('player', pos, 100, 1)
if non_colliding_pos then
game.print(player_name .. " went on a walkabout, to find himself.")
Task.set_timeout(duration, "custom_commands_return_player", {player = player, force = player.force, position = {x = player.position.x, y = player.position.y}})
player.character = nil
player.create_character()
player.teleport(non_colliding_pos)
player.force = "enemy"
global.walking[player_name:lower()] = true
else
player_print("Walkabout failed: count find non colliding position")
end
end
function custom_commands_return_player(args)
global.walking[args.player.name:lower()] = false
args.player.character.destroy()
local character = args.player.surface.find_entity('player', args.position)
if character ~= nil and character.valid then
args.player.character = character
else
args.player.create_character()
end
args.player.force = args.force
args.player.teleport(args.position)
game.print(args.player.name .. " came back from his walkabout.")
if non_colliding_pos then
game.print(player_name .. ' went on a walkabout, to find himself.')
Task.set_timeout(
duration,
custom_commands_return_player,
{player = player, force = player.force, position = {x = player.position.x, y = player.position.y}}
)
player.character = nil
player.create_character()
player.teleport(non_colliding_pos)
player.force = 'enemy'
global.walking[player_name:lower()] = true
else
player_print('Walkabout failed: count find non colliding position')
end
end
local function regular(cmd)
if not ((not game.player) or game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
if not ((not game.player) or game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
if cmd.parameter == nil then
player_print("Command failed. Usage: /regular <promote, demote>, <player>")
return
end
local params = {}
for param in string.gmatch(cmd.parameter, "%S+") do table.insert(params, param) end
if params[2] == nil then
player_print("Command failed. Usage: /regular <promote, demote>, <player>")
return
elseif (params[1] == "promote") then
add_regular(params[2])
elseif (params[1] == "demote") then
remove_regular(params[2])
else
player_print("Command failed. Usage: /regular <promote, demote>, <player>")
end
if cmd.parameter == nil then
player_print('Command failed. Usage: /regular <promote, demote>, <player>')
return
end
local params = {}
for param in string.gmatch(cmd.parameter, '%S+') do
table.insert(params, param)
end
if params[2] == nil then
player_print('Command failed. Usage: /regular <promote, demote>, <player>')
return
elseif (params[1] == 'promote') then
add_regular(params[2])
elseif (params[1] == 'demote') then
remove_regular(params[2])
else
player_print('Command failed. Usage: /regular <promote, demote>, <player>')
end
end
local function mod(cmd)
if game.player and not game.player.admin then
cant_run(cmd.name)
return
end
if game.player and not game.player.admin then
cant_run(cmd.name)
return
end
if cmd.parameter == nil then
player_print("Command failed. Usage: /mod <promote, demote>, <player>")
return
end
local params = {}
for param in string.gmatch(cmd.parameter, "%S+") do table.insert(params, param) end
if params[2] == nil then
player_print("Command failed. Usage: /mod <promote, demote>, <player>")
return
elseif (params[1] == "promote") then
add_mod(params[2])
elseif (params[1] == "demote") then
remove_mod(params[2])
else
player_print("Command failed. Usage: /mod <promote, demote>, <player>")
end
if cmd.parameter == nil then
player_print('Command failed. Usage: /mod <promote, demote>, <player>')
return
end
local params = {}
for param in string.gmatch(cmd.parameter, '%S+') do
table.insert(params, param)
end
if params[2] == nil then
player_print('Command failed. Usage: /mod <promote, demote>, <player>')
return
elseif (params[1] == 'promote') then
add_mod(params[2])
elseif (params[1] == 'demote') then
remove_mod(params[2])
else
player_print('Command failed. Usage: /mod <promote, demote>, <player>')
end
end
local function afk()
for _,v in pairs (game.players) do
if v.afk_time > 300 then
local time = " "
if v.afk_time > 21600 then
time = time .. math.floor(v.afk_time / 216000) .. " hours "
end
if v.afk_time > 3600 then
time = time .. math.floor(v.afk_time / 3600) % 60 .. " minutes and "
end
time = time .. math.floor(v.afk_time / 60) % 60 .. " seconds."
player_print(v.name .. " has been afk for" .. time)
for _, v in pairs(game.players) do
if v.afk_time > 300 then
local time = ' '
if v.afk_time > 21600 then
time = time .. math.floor(v.afk_time / 216000) .. ' hours '
end
if v.afk_time > 3600 then
time = time .. math.floor(v.afk_time / 3600) % 60 .. ' minutes and '
end
time = time .. math.floor(v.afk_time / 60) % 60 .. ' seconds.'
player_print(v.name .. ' has been afk for' .. time)
end
end
end
end
local function tag(cmd)
if game.player and not game.player.admin then
cant_run(cmd.name)
return
end
if cmd.parameter ~= nil then
local params = {}
for param in string.gmatch(cmd.parameter, "%S+") do table.insert(params, param) end
if #params < 2 then
player_print("Usage: <player> <tag> Sets a players tag.")
elseif game.players[params[1]] == nil then
player_print("Player does not exist.")
else
local tag = string.sub(cmd.parameter, params[1]:len() + 2)
game.players[params[1]].tag = "[" .. tag .. "]"
game.print(params[1] .. " joined [" .. tag .. "].")
if game.player and not game.player.admin then
cant_run(cmd.name)
return
end
if cmd.parameter ~= nil then
local params = {}
for param in string.gmatch(cmd.parameter, '%S+') do
table.insert(params, param)
end
if #params < 2 then
player_print('Usage: <player> <tag> Sets a players tag.')
elseif game.players[params[1]] == nil then
player_print('Player does not exist.')
else
local tag = string.sub(cmd.parameter, params[1]:len() + 2)
game.players[params[1]].tag = '[' .. tag .. ']'
game.print(params[1] .. ' joined [' .. tag .. '].')
end
else
player_print('Usage: /tag <player> <tag> Sets a players tag.')
end
else
player_print('Usage: /tag <player> <tag> Sets a players tag.')
end
end
local function follow(cmd)
if not game.player then
log("<Server can't do that.")
return
end
if cmd.parameter ~= nil and game.players[cmd.parameter] ~= nil then
global.follows[game.player.name] = cmd.parameter
global.follows.n_entries = global.follows.n_entries + 1
else
player_print("Usage: /follow <player> makes you follow the player. Use /unfollow to stop following a player.")
end
if not game.player then
log("<Server can't do that.")
return
end
if cmd.parameter ~= nil and game.players[cmd.parameter] ~= nil then
global.follows[game.player.name] = cmd.parameter
global.follows.n_entries = global.follows.n_entries + 1
else
player_print('Usage: /follow <player> makes you follow the player. Use /unfollow to stop following a player.')
end
end
local function unfollow(cmd)
if not game.player then
log("<Server can't do that.")
return
end
if global.follows[game.player.name] ~= nil then
global.follows[game.player.name] = nil
global.follows.n_entries = global.follows.n_entries - 1
end
if not game.player then
log("<Server can't do that.")
return
end
if global.follows[game.player.name] ~= nil then
global.follows[game.player.name] = nil
global.follows.n_entries = global.follows.n_entries - 1
end
end
global.tp_players = {}
local function built_entity(event)
local index = event.player_index
local index = event.player_index
if global.tp_players[index] then
local entity = event.created_entity
if global.tp_players[index] then
local entity = event.created_entity
if entity.type ~= "entity-ghost" then return end
if entity.type ~= 'entity-ghost' then
return
end
game.players[index].teleport(entity.position)
entity.destroy()
end
game.players[index].teleport(entity.position)
entity.destroy()
end
end
Event.add(defines.events.on_built_entity, built_entity)
local function toggle_tp_mode(cmd)
if not game.player or not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
if not game.player or not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
local index = game.player.index
local toggled = global.tp_players[index]
local index = game.player.index
local toggled = global.tp_players[index]
if toggled then
global.tp_players[index] = nil
player_print("tp mode is now off")
else
global.tp_players[index] = true
player_print("tp mode is now on - place a ghost entity to teleport there.")
end
if toggled then
global.tp_players[index] = nil
player_print('tp mode is now off')
else
global.tp_players[index] = true
player_print('tp mode is now on - place a ghost entity to teleport there.')
end
end
global.old_force = {}
global.force_toggle_init = true
local function forcetoggle(cmd)
if not game.player or not (game.player.admin or is_mod(game.player.name)) or (not game.player.character) then
cant_run(cmd.name)
return
end
if not game.player or not (game.player.admin or is_mod(game.player.name)) or (not game.player.character) then
cant_run(cmd.name)
return
end
if global.force_toggle_init then
game.forces.enemy.research_all_technologies() --avoids losing logstics slot configuration
global.force_toggle_init = false
end
if global.force_toggle_init then
game.forces.enemy.research_all_technologies() --avoids losing logstics slot configuration
global.force_toggle_init = false
end
-- save the logistics slots
local slots = {}
local slot_counts = game.player.character.request_slot_count
if game.player.character.request_slot_count > 0 then
for i = 1, slot_counts do
slot = game.player.character.get_request_slot(i)
if slot ~= nil then
table.insert(slots, slot)
end
end
end
if game.player.force.name == "enemy" then
local old_force = global.old_force[game.player.name]
if not old_force then
game.player.force = "player"
game.player.print("You're are now on the player force.")
else
if game.forces[old_force] then
game.player.force = old_force
else
game.player.force = "player"
end
end
else
--Put roboports into inventory
inv = game.player.get_inventory(defines.inventory.player_armor)
if inv[1].valid_for_read
then
local name = inv[1].name
if name:match("power") or name:match("modular") then
local equips = inv[1].grid.equipment
for _,equip in pairs(equips) do
if equip.name == "personal-roboport-equipment"
or equip.name == "personal-roboport-mk2-equipment"
or equip.name == "personal-laser-defense-equipment" then
if game.player.insert{name = equip.name} == 0 then
game.player.surface.spill_item_stack(game.player.position, {name = equip.name})
end
inv[1].grid.take(equip)
end
-- save the logistics slots
local slots = {}
local slot_counts = game.player.character.request_slot_count
if game.player.character.request_slot_count > 0 then
for i = 1, slot_counts do
slot = game.player.character.get_request_slot(i)
if slot ~= nil then
table.insert(slots, slot)
end
end
end
end
end
global.old_force[game.player.name] = game.player.force.name
game.player.force = "enemy"
end
game.player.print("You are now on the " .. game.player.force.name .. " force.")
if game.player.force.name == 'enemy' then
local old_force = global.old_force[game.player.name]
if not old_force then
game.player.force = 'player'
game.player.print("You're are now on the player force.")
else
if game.forces[old_force] then
game.player.force = old_force
else
game.player.force = 'player'
end
end
else
--Put roboports into inventory
inv = game.player.get_inventory(defines.inventory.player_armor)
if inv[1].valid_for_read then
local name = inv[1].name
if name:match('power') or name:match('modular') then
local equips = inv[1].grid.equipment
for _, equip in pairs(equips) do
if
equip.name == 'personal-roboport-equipment' or equip.name == 'personal-roboport-mk2-equipment' or
equip.name == 'personal-laser-defense-equipment'
then
if game.player.insert {name = equip.name} == 0 then
game.player.surface.spill_item_stack(game.player.position, {name = equip.name})
end
inv[1].grid.take(equip)
end
end
end
end
-- Attempt to rebuild the request slots
slot_counts = game.player.character.request_slot_count
if game.player.character.request_slot_count > 0 then
for _,slot in ipairs(slots) do
game.player.character.set_request_slot(slot, _)
end
end
global.old_force[game.player.name] = game.player.force.name
game.player.force = 'enemy'
end
game.player.print('You are now on the ' .. game.player.force.name .. ' force.')
-- Attempt to rebuild the request slots
slot_counts = game.player.character.request_slot_count
if game.player.character.request_slot_count > 0 then
for _, slot in ipairs(slots) do
game.player.character.set_request_slot(slot, _)
end
end
end
local function get_group()
local group = game.permissions.get_group("Banned")
if not group then
game.permissions.create_group("Banned")
group = game.permissions.get_group("Banned")
if group then
for i=2,174 do
group.set_allows_action(i, false)
local group = game.permissions.get_group('Banned')
if not group then
game.permissions.create_group('Banned')
group = game.permissions.get_group('Banned')
if group then
for i = 2, 174 do
group.set_allows_action(i, false)
end
else
game.print(
'This would have nearly crashed the server, please consult the next best scenario dev (valansch or TWLtriston).'
)
end
else
game.print("This would have nearly crashed the server, please consult the next best scenario dev (valansch or TWLtriston).")
end
end
return group
return group
end
function custom_commands_untempban(param)
game.print(param.name .. " is out of timeout.")
game.permissions.get_group("Default").add_player(param.name)
end
local custom_commands_untempban =
Token.register(
function(param)
game.print(param.name .. ' is out of timeout.')
game.permissions.get_group('Default').add_player(param.name)
end
)
local function tempban(cmd)
if (not game.player) or not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
if cmd.parameter == nil then
player_print("Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.")
return
if (not game.player) or not (game.player.admin or is_mod(game.player.name)) then
cant_run(cmd.name)
return
end
local params = {}
for param in string.gmatch(cmd.parameter, "%S+") do table.insert(params, param) end
if #params < 2 or not tonumber(params[2]) then
player_print("Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.")
return
end
if not game.players[params[1]] then
player_print("Player doesn't exist.")
return
end
local group = get_group()
game.print(get_actor() .. " put " .. params[1] .. " in timeout for " .. params[2] .. " minutes.")
if group then
group.add_player(params[1])
if not tonumber(cmd.parameter) then
Task.set_timeout(60 * tonumber(params[2]), "custom_commands_untempban", {name = params[1]})
if cmd.parameter == nil then
player_print('Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.')
return
end
local params = {}
for param in string.gmatch(cmd.parameter, '%S+') do
table.insert(params, param)
end
if #params < 2 or not tonumber(params[2]) then
player_print('Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.')
return
end
if not game.players[params[1]] then
player_print("Player doesn't exist.")
return
end
local group = get_group()
game.print(get_actor() .. ' put ' .. params[1] .. ' in timeout for ' .. params[2] .. ' minutes.')
if group then
group.add_player(params[1])
if not tonumber(cmd.parameter) then
Task.set_timeout(60 * tonumber(params[2]), custom_commands_untempban, {name = params[1]})
end
end
end
end
function custom_commands_replace_ghosts(param)
for _,ghost in pairs(param.ghosts) do
local new_ghost = game.surfaces[param.surface_index].create_entity{name = "entity-ghost", position = ghost.position, inner_name = ghost.ghost_name, expires = false, force = "enemy", direction = ghost.direction}
new_ghost.last_user = ghost.last_user
end
end
local custom_commands_replace_ghosts =
Token.register(
function(param)
for _, ghost in pairs(param.ghosts) do
local new_ghost =
game.surfaces[param.surface_index].create_entity {
name = 'entity-ghost',
position = ghost.position,
inner_name = ghost.ghost_name,
expires = false,
force = 'enemy',
direction = ghost.direction
}
new_ghost.last_user = ghost.last_user
end
end
)
local function spyshot(cmd)
if not cmd then return 0 end
local player_name = cmd.parameter
if player_name and game.players[player_name] then
for _,spy in pairs(global.spys) do
if game.players[spy] and game.players[spy].connected then
local pos = game.players[player_name].position
pseudo_ghosts = {}
for _,ghost in pairs(game.players[player_name].surface.find_entities_filtered{area = {{pos.x - 60, pos.y - 35},{pos.x + 60, pos.y + 35}},name = "entity-ghost", force = enemy}) do
local pseudo_ghost = {position = ghost.position, ghost_name = ghost.ghost_name, expires = false, force = "enemy", direction = ghost.direction, last_user = ghost.last_user}
table.insert(pseudo_ghosts, pseudo_ghost)
ghost.destroy()
end
game.take_screenshot{by_player = spy, position = pos, show_gui = false, show_entity_info = true, resolution = {1920, 1080}, anti_alias = true, zoom = 0.5, path ="spyshot.png"}
game.players[spy].print("You just took a screenshot!")
Task.set_timeout(2, "custom_commands_replace_ghosts", {ghosts = pseudo_ghosts, surface_index = game.players[player_name].surface.index}) --delay replacements for the screenshot to render
return
end
if not cmd then
return 0
end
local player_name = cmd.parameter
if player_name and game.players[player_name] then
for _, spy in pairs(global.spys) do
if game.players[spy] and game.players[spy].connected then
local pos = game.players[player_name].position
pseudo_ghosts = {}
for _, ghost in pairs(
game.players[player_name].surface.find_entities_filtered {
area = {{pos.x - 60, pos.y - 35}, {pos.x + 60, pos.y + 35}},
name = 'entity-ghost',
force = enemy
}
) do
local pseudo_ghost = {
position = ghost.position,
ghost_name = ghost.ghost_name,
expires = false,
force = 'enemy',
direction = ghost.direction,
last_user = ghost.last_user
}
table.insert(pseudo_ghosts, pseudo_ghost)
ghost.destroy()
end
game.take_screenshot {
by_player = spy,
position = pos,
show_gui = false,
show_entity_info = true,
resolution = {1920, 1080},
anti_alias = true,
zoom = 0.5,
path = 'spyshot.png'
}
game.players[spy].print('You just took a screenshot!')
Task.set_timeout(
2,
custom_commands_replace_ghosts,
{ghosts = pseudo_ghosts, surface_index = game.players[player_name].surface.index}
) --delay replacements for the screenshot to render
return
end
end
player_print('No spy online!')
end
player_print("No spy online!")
end
end
local function zoom(cmd)
if game.player and cmd and cmd.parameter and tonumber(cmd.parameter) then
game.player.zoom = tonumber(cmd.parameter)
end
if game.player and cmd and cmd.parameter and tonumber(cmd.parameter) then
game.player.zoom = tonumber(cmd.parameter)
end
end
local function pool()
if game.player and game.player.admin then
local t = {} p = game.player.position
for x = p.x - 3, p.x + 3 do
for y = p.y + 2, p.y + 7 do
table.insert(t, {name="water", position={x,y}})
end
if game.player and game.player.admin then
local t = {}
p = game.player.position
for x = p.x - 3, p.x + 3 do
for y = p.y + 2, p.y + 7 do
table.insert(t, {name = 'water', position = {x, y}})
end
end
game.player.surface.set_tiles(t)
game.player.surface.create_entity {name = 'fish', position = {p.x + 0.5, p.y + 5}}
end
game.player.surface.set_tiles(t)
game.player.surface.create_entity{name = "fish", position = {p.x + 0.5, p.y + 5}}
end
end
if not _DEBUG then
local old_add_command = commands.add_command
commands.add_command = function(name, desc, func)
old_add_command(name, desc, function(cmd)
local success, error = pcall(func, cmd)
if not success then
log(error)
end
end)
end
local old_add_command = commands.add_command
commands.add_command =
function(name, desc, func)
old_add_command(
name,
desc,
function(cmd)
local success, error = pcall(func, cmd)
if not success then
log(error)
end
end
)
end
end
commands.add_command("kill", "Will kill you.", kill)
commands.add_command("tpplayer", "<player> - Teleports you to the player. (Admins and moderators)", teleport_player)
commands.add_command("invoke", "<player> - Teleports the player to you. (Admins and moderators)", invoke)
commands.add_command("tppos", "Teleports you to a selected entity. (Admins only)", teleport_location)
commands.add_command("walkabout", '<player> <duration> - Send someone on a walk. (Admins and moderators)', walkabout)
commands.add_command("regulars", 'Prints a list of game regulars.', print_regulars)
commands.add_command("regular", '<promote, demote>, <player> Change regular status of a player. (Admins and moderators)', regular)
commands.add_command("mods", 'Prints a list of game mods.', print_mods)
commands.add_command("mod", '<promote, demote>, <player> Changes moderator status of a player. (Admins only)', mod)
commands.add_command("afk", 'Shows how long players have been afk.', afk)
commands.add_command('kill', 'Will kill you.', kill)
commands.add_command('tpplayer', '<player> - Teleports you to the player. (Admins and moderators)', teleport_player)
commands.add_command('invoke', '<player> - Teleports the player to you. (Admins and moderators)', invoke)
commands.add_command('tppos', 'Teleports you to a selected entity. (Admins only)', teleport_location)
commands.add_command('walkabout', '<player> <duration> - Send someone on a walk. (Admins and moderators)', walkabout)
commands.add_command('regulars', 'Prints a list of game regulars.', print_regulars)
commands.add_command(
'regular',
'<promote, demote>, <player> Change regular status of a player. (Admins and moderators)',
regular
)
commands.add_command('mods', 'Prints a list of game mods.', print_mods)
commands.add_command('mod', '<promote, demote>, <player> Changes moderator status of a player. (Admins only)', mod)
commands.add_command('afk', 'Shows how long players have been afk.', afk)
--commands.add_command("tag", '<player> <tag> Sets a players tag. (Admins only)', tag)
commands.add_command("follow", '<player> makes you follow the player. Use /unfollow to stop following a player.', follow)
commands.add_command("unfollow", 'stops following a player.', unfollow)
commands.add_command("tpmode", "Toggles tp mode. When on place a ghost entity to teleport there (Admins and moderators)", toggle_tp_mode)
commands.add_command("forcetoggle", "Toggles the players force between player and enemy (Admins and moderators)", forcetoggle)
commands.add_command("tempban", "<player> <minutes> Temporarily bans a player (Admins and moderators)", tempban)
commands.add_command("spyshot", "<player> Sends a screenshot of player to discord. (If a host is online. If no host is online, you can become one yourself. Ask on discord :))", spyshot)
commands.add_command("zoom", "<number> Sets your zoom.", zoom)
commands.add_command("all-tech", "researches all technologies", function() if game.player and game.player.admin then game.player.force.research_all_technologies() end end)
commands.add_command("hax", "Toggles your hax", function() if game.player and game.player.admin then game.player.cheat_mode = not game.player.cheat_mode end end)
commands.add_command("pool", "Spawns a pool", pool)
commands.add_command(
'follow',
'<player> makes you follow the player. Use /unfollow to stop following a player.',
follow
)
commands.add_command('unfollow', 'stops following a player.', unfollow)
commands.add_command(
'tpmode',
'Toggles tp mode. When on place a ghost entity to teleport there (Admins and moderators)',
toggle_tp_mode
)
commands.add_command(
'forcetoggle',
'Toggles the players force between player and enemy (Admins and moderators)',
forcetoggle
)
commands.add_command('tempban', '<player> <minutes> Temporarily bans a player (Admins and moderators)', tempban)
commands.add_command(
'spyshot',
'<player> Sends a screenshot of player to discord. (If a host is online. If no host is online, you can become one yourself. Ask on discord :))',
spyshot
)
commands.add_command('zoom', '<number> Sets your zoom.', zoom)
commands.add_command(
'all-tech',
'researches all technologies',
function()
if game.player and game.player.admin then
game.player.force.research_all_technologies()
end
end
)
commands.add_command(
'hax',
'Toggles your hax',
function()
if game.player and game.player.admin then
game.player.cheat_mode = not game.player.cheat_mode
end
end
)
commands.add_command('pool', 'Spawns a pool', pool)

View File

@ -2,10 +2,9 @@
-- !! ATTENTION !!
-- Use water only in starting area as map setting!!!
local perlin = require 'map_gen.shared.perlin_noise'
local Task = require 'utils.Task'
local Token = require 'utils.global_token'
wreck_item_pool = {}
wreck_item_pool = {
local wreck_item_pool = {
{name = 'iron-gear-wheel', count = 32},
{name = 'iron-plate', count = 64},
{name = 'rocket-control-unit', count = 1},
@ -35,586 +34,240 @@ wreck_item_pool = {
{name = 'explosive-rocket', count = 32}
}
local function place_entities(surface, entity_list)
local directions = {
defines.direction.north,
defines.direction.east,
defines.direction.south,
defines.direction.west
}
for _, entity in pairs(entity_list) do
local r = math.random(1, entity.chance)
if r == 1 then
if not entity.force then
entity.force = 'player'
end
local r = math.random(1, 4)
if
surface.can_place_entity {
name = entity.name,
position = entity.pos,
direction = directions[r],
force = entity.force
}
then
local e =
surface.create_entity {
name = entity.name,
position = entity.pos,
direction = directions[r],
force = entity.force
}
if entity.health then
if entity.health == 'low' then
e.health = ((e.health / 1000) * math.random(33, 330))
end
if entity.health == 'medium' then
e.health = ((e.health / 1000) * math.random(333, 666))
end
if entity.health == 'high' then
e.health = ((e.health / 1000) * math.random(666, 999))
end
if entity.health == 'random' then
e.health = ((e.health / 1000) * math.random(1, 1000))
end
end
return true, e
end
end
end
return false
end
local ship_callback =
Token.register(
function(entity)
entity.health = math.random(entity.health)
local function find_tile_placement_spot_around_target_position(tilename, position, mode, density)
local x = position.x
local y = position.y
if not surface then
surface = game.surfaces[1]
entity.insert(wreck_item_pool[math.random(#wreck_item_pool)])
entity.insert(wreck_item_pool[math.random(#wreck_item_pool)])
entity.insert(wreck_item_pool[math.random(#wreck_item_pool)])
end
local scan_radius = 50
if not tilename then
return
end
if not mode then
mode = 'ball'
end
if not density then
density = 1
end
local cluster_tiles = {}
local auto_correct = true
)
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
local clear_types = {'simple-entity', 'tree'}
local i = 2
local r = 1
if mode == 'ball' then
if math.random(1, 2) == 1 then
density = density * -1
end
r = math.random(1, 4)
end
if mode == 'line' then
density = 1
r = math.random(1, 4)
end
if mode == 'line_down' then
density = density * -1
r = math.random(1, 4)
end
if mode == 'line_up' then
density = 1
r = math.random(1, 4)
end
if mode == 'block' then
r = 1
density = 1
end
if r == 1 then
--start placing at -1,-1
while i <= scan_radius do
y = y - density
x = x - density
for a = 1, i, 1 do
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
x = x + density
end
for a = 1, i, 1 do
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
y = y + density
end
for a = 1, i, 1 do
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
x = x - density
end
for a = 1, i, 1 do
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
y = y - density
end
i = i + 2
end
end
if r == 2 then
--start placing at 0,-1
while i <= scan_radius do
y = y - density
x = x - density
for a = 1, i, 1 do
x = x + density
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
end
for a = 1, i, 1 do
y = y + density
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
end
for a = 1, i, 1 do
x = x - density
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
end
for a = 1, i, 1 do
y = y - density
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
end
i = i + 2
end
end
if r == 3 then
--start placing at 1,-1
while i <= scan_radius do
y = y - density
x = x + density
for a = 1, i, 1 do
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
y = y + density
end
for a = 1, i, 1 do
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
x = x - density
end
for a = 1, i, 1 do
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
y = y - density
end
for a = 1, i, 1 do
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
x = x + density
end
i = i + 2
end
end
if r == 4 then
--start placing at 1,0
while i <= scan_radius do
y = y - density
x = x + density
for a = 1, i, 1 do
y = y + density
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
end
for a = 1, i, 1 do
x = x - density
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
end
for a = 1, i, 1 do
y = y - density
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
end
for a = 1, i, 1 do
x = x + density
local scanned_tile = surface.get_tile(x, y)
if scanned_tile.name ~= tilename then
table.insert(cluster_tiles, {name = tilename, position = {x, y}})
surface.set_tiles(cluster_tiles, auto_correct)
return true, x, y
end
end
i = i + 2
end
end
return false
end
local function create_tile_cluster(tilename, position, amount)
local mode = 'ball'
local cluster_tiles = {}
local surface = game.surfaces[1]
local pos = position
local x = pos.x
local y = pos.y
for i = 1, amount, 1 do
local b, x, y = find_tile_placement_spot_around_target_position(tilename, pos, mode)
if b == true then
if 1 == math.random(1, 2) then
pos.x = x
pos.y = y
end
end
if b == false then
return false, x, y
end
if i >= amount then
return true, x, y
end
local function do_clear_entities(world)
local entities = world.surface.find_entities_filtered({area = world.area, type = clear_types})
for _, entity in ipairs(entities) do
entity.destroy()
end
end
function run_combined_module(event)
local area = event.area
local surface = event.surface
local random_health =
Token.register(
function(e)
e.health = math.random(e.health)
end
)
local entities = surface.find_entities(area)
for _, entity in pairs(entities) do
if entity.type == 'simple-entity' or entity.type == 'tree' then
if entity.name ~= 'dry-tree' then
entity.destroy()
local medium_health =
Token.register(
function(e)
e.health = math.random(math.floor(e.health * 0.333), math.floor(e.health * 0.666))
end
)
local low_health =
Token.register(
function(e)
e.health = math.random(math.floor(e.health * 0.033), math.floor(e.health * 0.330))
end
)
local turrent_callback =
Token.register(
function(e)
if math.random(1, 3) == 1 then
e.insert('piercing-rounds-magazine')
else
e.insert('firearm-magazine')
end
end
)
return function(x, y, world)
local entities = {}
local area = world.area
local surface = world.surface
if not world.island_resort_cleared then
world.island_resort_cleared = true
do_clear_entities(world)
end
local tile_to_insert = 'sand-1'
local seed_increment_number = 10000
local seed = surface.map_gen_settings.seed
local noise_borg_defense_1 = perlin:noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_borg_defense_2 = perlin:noise(((world.x + seed) / 20), ((world.y + seed) / 20), 0)
seed = seed + seed_increment_number
local noise_borg_defense = noise_borg_defense_1 + noise_borg_defense_2 * 0.15
local noise_trees_1 = perlin:noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_trees_2 = perlin:noise(((world.x + seed) / 15), ((world.y + seed) / 15), 0)
seed = seed + seed_increment_number
local noise_trees = noise_trees_1 + noise_trees_2 * 0.3
local noise_walls_1 = perlin:noise(((world.x + seed) / 150), ((world.y + seed) / 150), 0)
seed = seed + seed_increment_number
local noise_walls_2 = perlin:noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_walls_3 = perlin:noise(((world.x + seed) / 20), ((world.y + seed) / 20), 0)
seed = seed + seed_increment_number
local noise_walls = noise_walls_1 + noise_walls_2 * 0.1 + noise_walls_3 * 0.03
if noise_borg_defense > 0.66 then
if math.random(25) == 1 then
table.insert(entities, {name = 'big-ship-wreck-1', force = 'player', callback = ship_callback})
elseif math.random(25) == 1 then
table.insert(entities, {name = 'big-ship-wreck-2', force = 'player', callback = ship_callback})
elseif math.random(25) == 1 then
table.insert(entities, {name = 'big-ship-wreck-3', force = 'player', callback = ship_callback})
end
end
if noise_trees > 0.17 then
tile_to_insert = 'sand-3'
end
if noise_borg_defense > 0.4 then
tile_to_insert = 'concrete'
end
if noise_borg_defense > 0.35 and noise_borg_defense < 0.4 then
tile_to_insert = 'stone-path'
end
if noise_borg_defense > 0.65 and noise_borg_defense < 0.66 then
table.insert(entities, {name = 'substation', force = 'enemy'})
end
if noise_borg_defense >= 0.54 and noise_borg_defense < 0.65 then
table.insert(entities, {name = 'solar-panel', force = 'enemy'})
end
if noise_borg_defense > 0.53 and noise_borg_defense < 0.54 then
table.insert(entities, {name = 'substation', force = 'enemy'})
end
if noise_borg_defense >= 0.51 and noise_borg_defense < 0.53 then
table.insert(entities, {name = 'accumulator', force = 'enemy'})
end
if noise_borg_defense >= 0.50 and noise_borg_defense < 0.51 then
table.insert(entities, {name = 'substation', force = 'enemy'})
end
if noise_borg_defense >= 0.487 and noise_borg_defense < 0.50 then
table.insert(entities, {name = 'laser-turret', force = 'enemy'})
end
if noise_borg_defense >= 0.485 and noise_borg_defense < 0.487 then
table.insert(entities, {name = 'substation', force = 'enemy'})
end
if noise_borg_defense >= 0.45 and noise_borg_defense < 0.484 then
table.insert(entities, {name = 'stone-wall', force = 'enemy'})
end
if noise_trees > 0.2 and tile_to_insert == 'sand-3' then
if math.random(1, 15) == 1 then
if math.random(1, 5) == 1 then
table.insert(entities, {name = 'dry-hairy-tree'})
else
table.insert(entities, {name = 'dry-tree'})
end
end
end
for x = 0, 31, 1 do
Task.queue_task('run_borg', {area = event.area, surface = event.surface, x = x})
if math.random(35000) == 1 then
table.insert(entities, {name = 'big-ship-wreck-1', force = 'player', callback = ship_callback})
elseif math.random(45000) == 1 then
table.insert(entities, {name = 'big-ship-wreck-2', force = 'player', callback = ship_callback})
elseif math.random(55000) == 1 then
table.insert(entities, {name = 'big-ship-wreck-3', force = 'player', callback = ship_callback})
elseif noise_walls > -0.03 and noise_walls < 0.03 and math.random(40) == 1 then
table.insert(entities, {name = 'gun-turret', force = 'enemy', callback = turrent_callback})
elseif noise_borg_defense > 0.41 and noise_borg_defense < 0.45 and math.random(15) == 1 then
table.insert(entities, {name = 'gun-turret', force = 'enemy', callback = turrent_callback})
elseif math.random(7500) == 1 then
table.insert(entities, {name = 'pipe-to-ground', force = 'enemy'})
elseif tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and math.random(1500) == 1 then
table.insert(entities, {name = 'dead-dry-hairy-tree'})
elseif tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and math.random(1500) == 1 then
table.insert(entities, {name = 'dead-grey-trunk'})
elseif math.random(25000) == 1 then
table.insert(entities, {name = 'medium-ship-wreck', force = 'player', callback = medium_health})
elseif math.random(15000) == 1 then
table.insert(entities, {name = 'small-ship-wreck', force = 'player', callback = medium_health})
elseif math.random(150000) == 1 then
table.insert(entities, {name = 'car', force = 'player', callback = low_health})
elseif math.random(100000) == 1 then
table.insert(entities, {name = 'laser-turret', force = 'enemy', callback = low_health})
elseif math.random(1000000) == 1 then
table.insert(entities, {name = 'nuclear-reactor', force = 'enemy', callback = medium_health})
end
end
function run_borg(params)
local tiles = {}
local decoratives = {}
if noise_trees < -0.5 and (tile_to_insert == 'sand-3' or tile_to_insert == 'sand-1') and math.random(15) == 1 then
table.insert(entities, {name = 'rock-big'})
end
local area = params.area
local surface = params.surface
local noise_water_1 = perlin:noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
seed = seed + seed_increment_number
local noise_water_2 = perlin:noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_water_3 = perlin:noise(((world.x + seed) / 25), ((world.y + seed) / 25), 0)
seed = seed + seed_increment_number
local noise_water_4 = perlin:noise(((world.x + seed) / 10), ((world.y + seed) / 10), 0)
seed = seed + seed_increment_number
local noise_water = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
local x = params.x
local pos_x = area.left_top.x + x
noise_water_1 = perlin:noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
seed = seed + seed_increment_number
noise_water_2 = perlin:noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
seed = seed + seed_increment_number
noise_water_3 = perlin:noise(((world.x + seed) / 25), ((world.y + seed) / 25), 0)
seed = seed + seed_increment_number
noise_water_4 = perlin:noise(((world.x + seed) / 10), ((world.y + seed) / 10), 0)
seed = seed + seed_increment_number
noise_water_2 = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
for y = 0, 31, 1 do
local pos_y = area.left_top.y + y
local pos = {x = pos_x, y = pos_y}
local tile = surface.get_tile(pos_x, pos_y)
local tile_to_insert = 'sand-1'
local entity_placed = false
if
tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and noise_water > -0.15 and noise_water < 0.15 and
noise_water_2 > 0.5
then
tile_to_insert = 'water-green'
end
local seed_increment_number = 10000
local seed = surface.map_gen_settings.seed
local noise_borg_defense_1 = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_borg_defense_2 = perlin:noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
seed = seed + seed_increment_number
local noise_borg_defense = noise_borg_defense_1 + noise_borg_defense_2 * 0.15
local noise_trees_1 = perlin:noise(((pos_x + seed) / 50), ((pos_y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_trees_2 = perlin:noise(((pos_x + seed) / 15), ((pos_y + seed) / 15), 0)
seed = seed + seed_increment_number
local noise_trees = noise_trees_1 + noise_trees_2 * 0.3
local noise_walls_1 = perlin:noise(((pos_x + seed) / 150), ((pos_y + seed) / 150), 0)
seed = seed + seed_increment_number
local noise_walls_2 = perlin:noise(((pos_x + seed) / 50), ((pos_y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_walls_3 = perlin:noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
seed = seed + seed_increment_number
local noise_walls = noise_walls_1 + noise_walls_2 * 0.1 + noise_walls_3 * 0.03
if noise_borg_defense > 0.66 then
local entity_list = {}
table.insert(entity_list, {name = 'big-ship-wreck-1', pos = {pos_x, pos_y}, chance = 25})
table.insert(entity_list, {name = 'big-ship-wreck-2', pos = {pos_x, pos_y}, chance = 25})
table.insert(entity_list, {name = 'big-ship-wreck-3', pos = {pos_x, pos_y}, chance = 25})
local b, placed_entity = place_entities(surface, entity_list)
if b == true then
if
placed_entity.name == 'big-ship-wreck-1' or placed_entity.name == 'big-ship-wreck-2' or
placed_entity.name == 'big-ship-wreck-3'
then
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
end
end
if noise_borg_defense <= 0.45 and tile_to_insert ~= 'water-green' then
local a = -0.01
local b = 0.01
if noise_walls > a and noise_walls < b then
table.insert(entities, {name = 'stone-wall', force = 'enemy'})
end
if noise_trees > 0.17 then
tile_to_insert = 'sand-3'
end
if noise_borg_defense > 0.4 then
if noise_walls >= a and noise_walls <= b then
tile_to_insert = 'concrete'
end
if noise_borg_defense > 0.35 and noise_borg_defense < 0.4 then
tile_to_insert = 'stone-path'
end
if noise_borg_defense > 0.65 and noise_borg_defense < 0.66 then
if surface.can_place_entity {name = 'substation', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'substation', position = {pos_x, pos_y}, force = 'enemy'}
if noise_borg_defense < 0.40 then
if noise_walls > b and noise_walls < b + 0.03 then
tile_to_insert = 'stone-path'
end
if noise_walls > a - 0.03 and noise_walls < a then
tile_to_insert = 'stone-path'
end
end
if noise_borg_defense >= 0.54 and noise_borg_defense < 0.65 then
if surface.can_place_entity {name = 'solar-panel', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'solar-panel', position = {pos_x, pos_y}, force = 'enemy'}
end
end
if noise_borg_defense > 0.53 and noise_borg_defense < 0.54 then
if surface.can_place_entity {name = 'substation', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'substation', position = {pos_x, pos_y}, force = 'enemy'}
end
end
if noise_borg_defense >= 0.51 and noise_borg_defense < 0.53 then
if surface.can_place_entity {name = 'accumulator', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'accumulator', position = {pos_x, pos_y}, force = 'enemy'}
end
end
if noise_borg_defense >= 0.50 and noise_borg_defense < 0.51 then
if surface.can_place_entity {name = 'substation', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'substation', position = {pos_x, pos_y}, force = 'enemy'}
end
end
if noise_borg_defense >= 0.487 and noise_borg_defense < 0.50 then
if surface.can_place_entity {name = 'laser-turret', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'laser-turret', position = {pos_x, pos_y}, force = 'enemy'}
end
end
if noise_borg_defense >= 0.485 and noise_borg_defense < 0.487 then
if surface.can_place_entity {name = 'substation', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'substation', position = {pos_x, pos_y}, force = 'enemy'}
end
end
if noise_borg_defense >= 0.45 and noise_borg_defense < 0.484 then
if surface.can_place_entity {name = 'stone-wall', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'stone-wall', position = {pos_x, pos_y}, force = 'enemy'}
end
end
if noise_trees > 0.2 and tile_to_insert == 'sand-3' then
if math.random(1, 15) == 1 then
if math.random(1, 5) == 1 then
if surface.can_place_entity {name = 'dry-hairy-tree', position = {pos_x, pos_y}} then
surface.create_entity {name = 'dry-hairy-tree', position = {pos_x, pos_y}}
end
else
if surface.can_place_entity {name = 'dry-tree', position = {pos_x, pos_y}} then
surface.create_entity {name = 'dry-tree', position = {pos_x, pos_y}}
end
end
end
end
local entity_list = {}
table.insert(entity_list, {name = 'big-ship-wreck-1', pos = {pos_x, pos_y}, chance = 35000, health = 'random'})
table.insert(entity_list, {name = 'big-ship-wreck-2', pos = {pos_x, pos_y}, chance = 45000, health = 'random'})
table.insert(entity_list, {name = 'big-ship-wreck-3', pos = {pos_x, pos_y}, chance = 55000, health = 'random'})
if noise_walls > -0.03 and noise_walls < 0.03 then
table.insert(entity_list, {name = 'gun-turret', pos = {pos_x, pos_y}, force = 'enemy', chance = 40})
end
if noise_borg_defense > 0.41 and noise_borg_defense < 0.45 then
table.insert(entity_list, {name = 'gun-turret', pos = {pos_x, pos_y}, force = 'enemy', chance = 15})
end
table.insert(entity_list, {name = 'pipe-to-ground', pos = {pos_x, pos_y}, force = 'enemy', chance = 7500})
if tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' then
table.insert(
entity_list,
{name = 'dead-dry-hairy-tree', pos = {pos_x, pos_y}, force = 'enemy', chance = 1500}
)
table.insert(entity_list, {name = 'dead-grey-trunk', pos = {pos_x, pos_y}, force = 'enemy', chance = 1500})
end
table.insert(entity_list, {name = 'medium-ship-wreck', pos = {pos_x, pos_y}, chance = 25000, health = 'medium'})
table.insert(entity_list, {name = 'small-ship-wreck', pos = {pos_x, pos_y}, chance = 15000, health = 'medium'})
table.insert(entity_list, {name = 'car', pos = {pos_x, pos_y}, chance = 150000, health = 'low'})
table.insert(
entity_list,
{name = 'laser-turret', pos = {pos_x, pos_y}, chance = 100000, force = 'enemy', health = 'low'}
)
table.insert(
entity_list,
{name = 'nuclear-reactor', pos = {pos_x, pos_y}, chance = 1000000, force = 'enemy', health = 'medium'}
)
local b, placed_entity = place_entities(surface, entity_list)
if b == true then
if
placed_entity.name == 'big-ship-wreck-1' or placed_entity.name == 'big-ship-wreck-2' or
placed_entity.name == 'big-ship-wreck-3'
then
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
placed_entity.insert(wreck_item_pool[math.random(1, #wreck_item_pool)])
end
if placed_entity.name == 'gun-turret' then
if math.random(1, 3) == 1 then
placed_entity.insert('piercing-rounds-magazine')
else
placed_entity.insert('firearm-magazine')
end
end
end
if noise_trees < -0.5 then
if tile_to_insert == 'sand-3' or tile_to_insert == 'sand-1' then
if math.random(1, 15) == 1 then
if surface.can_place_entity {name = 'rock-big', position = {pos_x, pos_y}} then
surface.create_entity {name = 'rock-big', position = {pos_x, pos_y}}
end
end
end
end
local noise_water_1 = perlin:noise(((pos_x + seed) / 200), ((pos_y + seed) / 200), 0)
seed = seed + seed_increment_number
local noise_water_2 = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_water_3 = perlin:noise(((pos_x + seed) / 25), ((pos_y + seed) / 25), 0)
seed = seed + seed_increment_number
local noise_water_4 = perlin:noise(((pos_x + seed) / 10), ((pos_y + seed) / 10), 0)
seed = seed + seed_increment_number
local noise_water = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
local noise_water_1 = perlin:noise(((pos_x + seed) / 200), ((pos_y + seed) / 200), 0)
seed = seed + seed_increment_number
local noise_water_2 = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_water_3 = perlin:noise(((pos_x + seed) / 25), ((pos_y + seed) / 25), 0)
seed = seed + seed_increment_number
local noise_water_4 = perlin:noise(((pos_x + seed) / 10), ((pos_y + seed) / 10), 0)
seed = seed + seed_increment_number
local noise_water_2 = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
if tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' then
if noise_water > -0.15 and noise_water < 0.15 and noise_water_2 > 0.5 then
tile_to_insert = 'water-green'
local a = pos_x + 1
table.insert(tiles, {name = tile_to_insert, position = {a, pos_y}})
local a = pos_y + 1
table.insert(tiles, {name = tile_to_insert, position = {pos_x, a}})
local a = pos_x - 1
table.insert(tiles, {name = tile_to_insert, position = {a, pos_y}})
local a = pos_y - 1
table.insert(tiles, {name = tile_to_insert, position = {pos_x, a}})
table.insert(tiles, {name = tile_to_insert, position = {pos_x, pos_y}})
end
end
if noise_borg_defense <= 0.45 and tile_to_insert ~= 'water-green' then
local a = -0.01
local b = 0.01
if noise_walls > a and noise_walls < b then
if surface.can_place_entity {name = 'stone-wall', position = {pos_x, pos_y}, force = 'enemy'} then
surface.create_entity {name = 'stone-wall', position = {pos_x, pos_y}, force = 'enemy'}
end
end
if noise_walls >= a and noise_walls <= b then
tile_to_insert = 'concrete'
end
if noise_borg_defense < 0.40 then
if noise_walls > b and noise_walls < b + 0.03 then
tile_to_insert = 'stone-path'
end
if noise_walls > a - 0.03 and noise_walls < a then
tile_to_insert = 'stone-path'
end
end
end
local noise_decoratives_1 = perlin:noise(((pos_x + seed) / 50), ((pos_y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_decoratives_2 = perlin:noise(((pos_x + seed) / 15), ((pos_y + seed) / 15), 0)
seed = seed + seed_increment_number
local noise_decoratives = noise_decoratives_1 + noise_decoratives_2 * 0.3
if noise_decoratives > 0.3 and noise_decoratives < 0.5 then
if tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and tile_to_insert ~= 'water-green' then
if math.random(1, 10) == 1 then
table.insert(decoratives, {name = 'red-desert-bush', position = {pos_x, pos_y}, amount = 1})
end
end
end
table.insert(tiles, {name = tile_to_insert, position = {pos_x, pos_y}})
end
surface.set_tiles(tiles, true)
for _, deco in pairs(decoratives) do
surface.create_decoratives {check_collision = false, decoratives = {deco}}
local noise_decoratives_1 = perlin:noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_decoratives_2 = perlin:noise(((world.x + seed) / 15), ((world.y + seed) / 15), 0)
local noise_decoratives = noise_decoratives_1 + noise_decoratives_2 * 0.3
local decoratives
if noise_decoratives > 0.3 and noise_decoratives < 0.5 then
if
tile_to_insert ~= 'stone-path' and tile_to_insert ~= 'concrete' and tile_to_insert ~= 'water-green' and
math.random(10) == 1
then
decoratives = {name = 'red-desert-bush', amount = 1}
end
end
return {tile = tile_to_insert, entities = entities, decoratives = decoratives}
end

View File

@ -4,9 +4,23 @@ local perlin = require 'map_gen.shared.perlin_noise'
local radius = 129
local radsquare = radius * radius
local clear_types = {'simple-entity', 'resource', 'tree'}
local function do_clear_entities(world)
local entities = world.surface.find_entities_filtered({area = world.area, type = clear_types})
for _, entity in ipairs(entities) do
entity.destroy()
end
end
return function(x, y, world)
local surface = world.surface
if not world.island_resort_cleared then
world.island_resort_cleared = true
do_clear_entities(world)
end
local entities = {}
local decoratives = {}

View File

@ -3,8 +3,11 @@ local Token = require 'utils.global_token'
local Event = require 'utils.event'
local shape
local tiles_per_tick
local regen_decoratives
local total_calls
local function do_row(row, data)
local function do_tile(tile, pos)
if not tile then
@ -21,7 +24,7 @@ local function do_row(row, data)
for x = top_x, top_x + 31 do
data.x = x
local pos = {data.x, data.y}
local pos = {x, y}
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile = shape(x + 0.5, y + 0.5, data)
@ -51,6 +54,44 @@ local function do_row(row, data)
end
end
local function do_tile(y, x, data)
local function do_tile_inner(tile, pos)
if not tile then
table.insert(data.tiles, {name = 'out-of-map', position = pos})
elseif type(tile) == 'string' then
table.insert(data.tiles, {name = tile, position = pos})
end
end
local pos = {x, y}
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile = shape(x + 0.5, y + 0.5, data)
if type(tile) == 'table' then
do_tile_inner(tile.tile, pos)
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
table.insert(data.entities, entity)
end
end
local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
table.insert(data.decoratives, decorative)
end
end
else
do_tile_inner(tile, pos)
end
end
local function do_place_tiles(data)
data.surface.set_tiles(data.tiles, true)
end
@ -79,7 +120,7 @@ local function do_place_decoratives(data)
end
local dec = data.decoratives
if dec then
if #dec > 0 then
data.surface.create_decoratives({check_collision = true, decoratives = dec})
end
end
@ -112,23 +153,49 @@ local function run_chart_update(data)
end
end
function map_gen_action(data)
local state = data.state
local function map_gen_action(data)
local state = data.y
if state < 32 then
do_row(state, data)
data.state = state + 1
local count = tiles_per_tick
local y = state + data.top_y
local x = data.x
local max_x = data.top_x + 32
data.y = y
repeat
count = count - 1
do_tile(y, x, data)
x = x + 1
if x == max_x then
y = y + 1
if y == data.top_y + 32 then
break
end
x = data.top_x
data.y = y
end
data.x = x
until count == 0
data.y = y - data.top_y
return true
elseif state == 32 then
do_place_tiles(data)
data.state = 33
data.y = 33
return true
elseif state == 33 then
do_place_entities(data)
data.state = 34
data.y = 34
return true
elseif state == 34 then
do_place_decoratives(data)
data.state = 35
data.y = 35
return true
elseif state == 35 then
run_chart_update(data)
@ -136,11 +203,15 @@ function map_gen_action(data)
end
end
local map_gen_action_token = Token.register(map_gen_action)
local function on_chunk(event)
local area = event.area
local data = {
state = 0,
y = 0,
x = area.left_top.x,
area = area,
top_x = area.left_top.x,
top_y = area.left_top.y,
surface = event.surface,
@ -148,13 +219,17 @@ local function on_chunk(event)
entities = {},
decoratives = {}
}
Task.queue_task('map_gen_action', data, 36)
Task.queue_task(map_gen_action_token, data, total_calls)
end
local function init(args)
shape = args.shape
tiles_per_tick = args.tiles_per_tick or 32
regen_decoratives = args.regen_decoratives or false
total_calls = math.ceil(1024 / tiles_per_tick) + 4
Event.add(defines.events.on_chunk_generated, on_chunk)
end

View File

@ -78,7 +78,7 @@ local function do_place_decoratives(data)
end
local dec = data.decoratives
if dec then
if #dec > 0 then
data.surface.create_decoratives({check_collision = true, decoratives = dec})
end
end
@ -100,6 +100,7 @@ local function on_chunk(event)
local area = event.area
local data = {
area = area,
top_x = area.left_top.x,
top_y = area.left_top.y,
surface = event.surface,

View File

@ -4,15 +4,17 @@ You may choose up to one of each type shapes, terrain, ores and misc or one of t
If you want to add your own module, just add it to the others
in this file and your run_*type*_module(event) function will be called.
--]]
local Event = require "utils.event"
local b = require "map_gen.shared.builders"
local b = require 'map_gen.shared.builders'
local shape = nil
local regen_decoratives = false
local tiles_per_tick = 32
--combined--
--shape = require "map_gen.combined.island_resort"
--require "map_gen.combined.red_planet_v2"
--require "map_gen.combined.borg_planet_v2"
--shape = require 'map_gen.combined.borg_planet_v2'
--require "map_gen.combined.dimensions"
--require "map_gen.combined.dagobah_swamp"
--require "map_gen.combined.meteor_strike" --unfinished
@ -84,7 +86,6 @@ local shape = nil
--ores--
--require "map_gen.ores.rso.rso_control"
-- modules that only return max one entity per tile
local entity_modules = {
--require "map_gen.ores.glitter_ores",
@ -97,7 +98,7 @@ local entity_modules = {
--require "map_gen.ores.resource_clustertruck"
}
local terrain_modules ={
local terrain_modules = {
--require "map_gen.misc.tris_chunk_grid",
}
@ -106,43 +107,21 @@ miscs = {}
--require "map_gen.misc.rusky_pvp"
--table.insert(miscs, require("map_gen.misc.rail_grid")) -- used for map_gen.presets.UK
local regen_decoratives = false
if #entity_modules > 0 then
shape = shape or b.full_shape
shape = shape or b.full_shape
shape = b.apply_entities(shape, entity_modules)
shape = b.apply_entities(shape, entity_modules)
end
if #terrain_modules > 0 then
shape = shape or b.full_shape
shape = shape or b.full_shape
for _, m in ipairs(terrain_modules) do
shape = b.overlay_tile_land(shape, m)
end
for _, m in ipairs(terrain_modules) do
shape = b.overlay_tile_land(shape, m)
end
end
if shape then
require ("map_gen.shared.generate")({shape = shape, regen_decoratives = regen_decoratives})
if shape then
require('map_gen.shared.generate')({shape = shape, regen_decoratives = regen_decoratives, tiles_per_tick = tiles_per_tick})
--require ("map_gen.shared.generate_not_threaded")({shape = shape, regen_decoratives = regen_decoratives})
end
--[[ local on_chunk_generated = function(event)
if run_combined_module ~= nil then
run_combined_module(event)
end
if run_shape_module ~= nil then
run_shape_module(event)
end
if run_terrain_module ~= nil then
run_terrain_module(event)
end
if run_ores_module ~= nil then
run_ores_module(event)
end
for _,v in pairs(miscs) do
v.on_chunk_generated(event)
end
end
Event.add(defines.events.on_chunk_generated, on_chunk_generated) ]]

View File

@ -4,9 +4,10 @@
-- github: https://github.com/Valansch/RedMew
-- ======================================================= --
local Queue = require "utils.Queue"
local PriorityQueue = require "utils.PriorityQueue"
local Event = require "utils.event"
local Queue = require 'utils.Queue'
local PriorityQueue = require 'utils.PriorityQueue'
local Event = require 'utils.event'
local Token = require 'utils.global_token'
local Task = {}
@ -17,64 +18,65 @@ global.total_task_weight = 0
global.task_queue_speed = 1
local function comp(a, b)
return a.time < b.time
return a.time < b.time
end
local function on_tick()
local queue = global.task_queue
for i = 1, get_task_per_tick() do
local task = Queue.peek(queue)
if task ~= nil then
local success, result = pcall(_G[task.func_name], task.params) -- result is error if not success else result is a boolean for if the task should stay in the queue.
if not success then
log(result)
Queue.pop(queue)
global.total_task_weight = global.total_task_weight - task.weight
elseif not result then
Queue.pop(queue)
global.total_task_weight = global.total_task_weight - task.weight
end
local queue = global.task_queue
for i = 1, get_task_per_tick() do
local task = Queue.peek(queue)
if task ~= nil then
-- result is error if not success else result is a boolean for if the task should stay in the queue.
local success, result = pcall(Token.get(task.func_token), task.params)
if not success then
log(result)
Queue.pop(queue)
global.total_task_weight = global.total_task_weight - task.weight
elseif not result then
Queue.pop(queue)
global.total_task_weight = global.total_task_weight - task.weight
end
end
end
end
local callbacks = global.callbacks
local callback = PriorityQueue.peek(callbacks)
while callback ~= nil and game.tick >= callback.time do
local success, error = pcall(_G[callback.func_name], callback.params)
if not success then
log(error)
end
PriorityQueue.pop(callbacks, comp)
callback = PriorityQueue.peek(callbacks)
end
local callbacks = global.callbacks
local callback = PriorityQueue.peek(callbacks)
while callback ~= nil and game.tick >= callback.time do
local success, error = pcall(Token.get(callback.func_token), callback.params)
if not success then
log(error)
end
PriorityQueue.pop(callbacks, comp)
callback = PriorityQueue.peek(callbacks)
end
end
global.tpt = global.task_queue_speed
function get_task_per_tick()
if game.tick % 300 == 0 then
local size = global.total_task_weight
global.tpt = math.floor(math.log10(size + 1)) * global.task_queue_speed
if global.tpt < 1 then
global.tpt = 1
function get_task_per_tick()
if game.tick % 300 == 0 then
local size = global.total_task_weight
global.tpt = math.floor(math.log10(size + 1)) * global.task_queue_speed
if global.tpt < 1 then
global.tpt = 1
end
end
end
return global.tpt
return global.tpt
end
function Task.set_timeout_in_ticks(ticks, func_name, params)
local time = game.tick + ticks
local callback = {time = time, func_name = func_name, params = params}
PriorityQueue.push(global.callbacks, callback, comp)
function Task.set_timeout_in_ticks(ticks, func_token, params)
local time = game.tick + ticks
local callback = {time = time, func_token = func_token, params = params}
PriorityQueue.push(global.callbacks, callback, comp)
end
function Task.set_timeout(sec, func_name, params)
Task.set_timeout_in_ticks(60 * sec, func_name, params)
function Task.set_timeout(sec, func_token, params)
Task.set_timeout_in_ticks(60 * sec, func_token, params)
end
function Task.queue_task(func_name, params, weight)
weight = weight or 1
global.total_task_weight = global.total_task_weight + weight
Queue.push(global.task_queue, {func_name = func_name, params = params, weight = weight})
function Task.queue_task(func_token, params, weight)
weight = weight or 1
global.total_task_weight = global.total_task_weight + weight
Queue.push(global.task_queue, {func_token = func_token, params = params, weight = weight})
end
Event.add(defines.events.on_tick, on_tick)