1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-26 03:52:00 +02:00

Merge branch 'develop_neko' of https://github.com/Valansch/RedMew into develop_neko

# Conflicts:
#	map_layout.lua
Im CONFUSED BY CONFLICTS
This commit is contained in:
NekoBaron 2017-08-09 23:10:46 +01:00
commit cba455de24
9 changed files with 445 additions and 12 deletions

View File

@ -1,3 +1,10 @@
local function apply_config()
if not global.scenario.config.enable_radar then
game.forces["player"].recipes["radar"].enabled = false
end
end
Event.register(-1, function()
global.scenario = {}
global.scenario.variables = {}
@ -15,7 +22,19 @@ Event.register(-1, function()
rorror = "",
Medival3 = "",
dpoba = "",
settdigger = ""
settdigger = "",
Cheeselicker = "",
cpaca0 = "",
UTIDI = "",
JokerOfTheZ = "",
saltlands = "",
Maniah = "",
COOL = "",
boail = "",
hunter117x = "",
TonyTroll = "",
rorror = "",
HighInFiberOptics = ""
}
global.scenario.variables.player_positions = {}
global.scenario.variables.player_walk_distances = {}
@ -25,10 +44,26 @@ Event.register(-1, function()
global.scenario.config.score_delay = 8 -- delay in seconds before hiding rocket score window (0 = never show)
global.scenario.config.autolaunch_default = false -- default autolaunch option
global.scenario.config.logistic_research_enabled = true -- if true then research for requesters and active providers will be enabled.
global.scenario.config.enable_radar = true
global.scenario.config.mapsettings = global.scenario.config.mapsettings or {}
global.scenario.config.mapsettings.cross_width = 200 -- total width of cross
global.scenario.config.mapsettings.spiral_land_width = 70 -- width of land in spiral
global.scenario.config.mapsettings.spiral_water_width = 70 -- width of water in spiral
global.scenario.custom_functions = {}
global.scenario.config.nuke_min_time_hours = 3 --how long a player must be on the server to be allowed to use the nuke
apply_config()
end)
local function on_research_started(event)
if not global.scenario.config.logistic_research_enabled then
if event.research.name == "logistic-robotics" then
game.forces["player"].current_research = nil
end
end
end
Event.register(defines.events.on_research_started, on_research_started)

View File

@ -17,6 +17,7 @@ require "custom_commands"
require "nuke_control"
require "walk_distance"
require "on_tick"
require "follow"

View File

@ -269,18 +269,37 @@ local function tag(cmd)
cant_run(cmd.name)
return
end
local params = {}
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
if #params ~= 2 then
game.player.print("Two arguments expect failed. Usage: <player> <tag> Sets a players tag.")
elseif game.players[params[1]] == nil then
game.player.print("Player does not exist.")
if cmd.parameter ~= nil then
local params = {}
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
if #params ~= 2 then
game.player.print("Two arguments expect failed. Usage: <player> <tag> Sets a players tag.")
elseif game.players[params[1]] == nil then
game.player.print("Player does not exist.")
else
game.players[params[1]].tag = "[" .. params[2] .. "]"
game.print(params[1] .. " joined [" .. params[2] .. "].")
end
else
game.players[params[1]].tag = "[" .. params[2] .. "]"
game.print(params[1] .. " joined [" .. params[2] .. "].")
game.player.print('Usage: /tag <player> <tag> Sets a players tag.')
end
end
local function follow(cmd)
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
game.player.print("Usage: /follow <player> makes you follow the player. Use /unfollow to stop following a player.")
end
end
local function unfollow(cmd)
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
commands.add_command("kill", "Will kill you.", kill)
@ -298,3 +317,5 @@ 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("afktime", '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)

64
follow.lua Normal file
View File

@ -0,0 +1,64 @@
global.follows = {}
global.follows.n_entries = 0
function get_direction(follower, target)
local delta_x = target.position.x - follower.position.x
local delta_y = follower.position.y - target.position.y --reversed x axis
local a = delta_y/delta_x
if a >= -1.5 and a < -0.5 then
--SE OR NW
if delta_x > 0 then
return defines.direction.southeast
else
return defines.direction.northwest
end
elseif a >= -0.5 and a < 0.5 then
--E OR W
if delta_x > 0 then
return defines.direction.east
else
return defines.direction.west
end
elseif a >= 0.5 and a < 1.5 then
--NE OR SW
if delta_x > 0 then
return defines.direction.northeast
else
return defines.direction.southwest
end
else
-- N or S
if a < 0 then delta_x = - delta_x end -- mirrow x axis if player is NNW or SSE
if delta_x > 0 then
return defines.direction.north
else
return defines.direction.south
end
end
end
local function distance(player_1, player_2)
local d_x = player_1.position.x - player_2.position.x
local d_y = player_1.position.y - player_2.position.y
return math.sqrt(d_x*d_x + d_y * d_y)
end
function walk_on_tick()
if global.follows.n_entries > 0 then
for k,v in pairs(global.follows) do
local follower = game.players[k]
local target = game.players[v]
if follower ~= nil and target ~= nil then
local d = distance(follower, target)
if follower.connected and target.connected and d < 32 then
if d > 5 then
direction = get_direction(follower, target)
follower.walking_state = {walking = true, direction = direction}
end
else
global.follows[follower.name] = nil
global.follows.n_entries = global.follows.n_entries - 1
end
end
end
end
end

View File

@ -0,0 +1,310 @@
--Author: Hexicube
--The size of each individual maze, in cells.
local maze_width = 17
local maze_height = 17
--The size of each cell within a maze, in tiles. This includes the border.
--This is also the thickness of passages between mazes.
local maze_tile_size = 80
--The thickness of cell borders (walls), in tiles.
local maze_tile_border = 2
--These two values are specifically chosen to only just allow train loops.
--If tile size is reduced or border size is increased, players will be forced to use 4-way crossings instead.
--Number of ore cells per maze, for each type.
local iron_ore_count = 8
local copper_ore_count = 6
local coal_ore_count = 4
local stone_ore_count = 2
local uranium_ore_count = 1
local resource_density_factor = 500
--Warning: Do not exceed the total number of cells in the maze, or it will break!
--DO NOT TOUCH BELOW THIS LINE--
local function get_random_maze_val(cur_seed)
local new_seed = bit32.bor(cur_seed + 0x9E3779B9, 0)
local return_val = bit32.bor(new_seed * 0xBF58476D, 0)
return_val = bit32.bor(return_val * 0x94D049BB, 0)
return new_seed, bit32.bor(return_val , 0)
end
local last_maze_x, last_maze_y, last_maze = nil, nil, nil
local function get_maze(x, y, seed, width, height)
if last_maze and last_maze_x == x and last_maze_y == y then return last_maze end
if not global.maze_data then global.maze_data = {} end
if not global.maze_data[x] then global.maze_data[x] = {} end
if global.maze_data[x][y] then
last_maze = global.maze_data[x][y]
last_maze_x = x
last_maze_y = y
return last_maze
end
local maze_data = {}
local grid = {}
for tx = 1,width do
maze_data[tx] = {}
grid[tx] = {}
for ty = 1,height do
maze_data[tx][ty] = 15
grid[tx][ty] = true
end
end
local maze_seed = bit32.bxor(bit32.lshift(x,16) + bit32.band(y,65535), seed)
local value = 0
local queue = {}
maze_seed, value = get_random_maze_val(maze_seed)
local pos = {0, 0}
pos[1] = value % width + 1
value = bit32.rshift(value,16)
pos[2] = value % height + 1
queue[#queue+1] = {pos[1], pos[2], pos[1]-1, pos[2] }
queue[#queue+1] = {pos[1], pos[2], pos[1]+1, pos[2] }
queue[#queue+1] = {pos[1], pos[2], pos[1] , pos[2]-1}
queue[#queue+1] = {pos[1], pos[2], pos[1] , pos[2]+1}
while #queue > 0 do
maze_seed, value = get_random_maze_val(maze_seed)
local connection = table.remove(queue, value % #queue + 1)
local sx, sy = connection[1], connection[2]
local tx, ty = connection[3], connection[4]
if tx > 0 and ty > 0 and tx <= width and ty <= height and grid[tx][ty] then
local dx, dy = sx - tx, sy - ty
local mod_s, mod_t = 3, 3
if dy == 1 then
mod_s = 1
elseif dy == -1 then
mod_t = 1
elseif dx == 1 then
mod_s = 2
else
mod_t = 2
end
maze_data[sx][sy] = bit32.band(maze_data[sx][sy], mod_s)
maze_data[tx][ty] = bit32.band(maze_data[tx][ty], mod_t)
grid[sx][sy] = false
grid[tx][ty] = false
queue[#queue+1] = {tx, ty, tx-1, ty }
queue[#queue+1] = {tx, ty, tx+1, ty }
queue[#queue+1] = {tx, ty, tx , ty-1}
queue[#queue+1] = {tx, ty, tx , ty+1}
end
end
maze_seed, value = get_random_maze_val(maze_seed)
maze_data[value % width + 1][1] = bit32.band(maze_data[value % width + 1][1], 1)
value = bit32.rshift(value, 16)
maze_data[1][value % height + 1] = bit32.band(maze_data[1][value % height + 1], 2)
maze_seed, value = get_random_maze_val(maze_seed)
maze_data[width+1] = {0, 0}
maze_data[width+1][1] = value % width + 1
value = bit32.rshift(value, 16)
maze_data[width+1][2] = value % height + 1
global.maze_data[x][y] = maze_data
last_maze = maze_data
last_maze_x = x
last_maze_y = y
return maze_data
end
local last_maze_ore_x, last_maze_ore_y, last_maze_ore = nil, nil, nil
local function get_maze_ore(x, y, seed, width, height)
if last_maze_ore and last_maze_ore_x == x and last_maze_ore_y == y then return last_maze_ore end
if not global.maze_data_ore then global.maze_data_ore = {} end
if not global.maze_data_ore[x] then global.maze_data_ore[x] = {} end
if global.maze_data_ore[x][y] then
last_maze_ore = global.maze_data_ore[x][y]
last_maze_ore_x = x
last_maze_ore_y = y
return last_maze_ore
end
local coord_list = {}
local maze_data = {}
for tx=1,width do
maze_data[tx] = {}
for ty=1,height do
maze_data[tx][ty] = nil
coord_list[#coord_list+1] = {tx,ty}
end
end
local maze_seed = bit32.bxor(bit32.lshift(x,16) + bit32.band(y,65535), seed)
local value = 0
for a=1,iron_ore_count do
maze_seed, value = get_random_maze_val(maze_seed)
local pos = table.remove(coord_list, value % #coord_list + 1)
maze_data[pos[1]][pos[2]] = "iron-ore"
end
for a=1,copper_ore_count do
maze_seed, value = get_random_maze_val(maze_seed)
local pos = table.remove(coord_list, value % #coord_list + 1)
maze_data[pos[1]][pos[2]] = "copper-ore"
end
for a=1,coal_ore_count do
maze_seed, value = get_random_maze_val(maze_seed)
local pos = table.remove(coord_list, value % #coord_list + 1)
maze_data[pos[1]][pos[2]] = "coal"
end
for a=1,stone_ore_count do
maze_seed, value = get_random_maze_val(maze_seed)
local pos = table.remove(coord_list, value % #coord_list + 1)
maze_data[pos[1]][pos[2]] = "stone"
end
for a=1,uranium_ore_count do
maze_seed, value = get_random_maze_val(maze_seed)
local pos = table.remove(coord_list, value % #coord_list + 1)
maze_data[pos[1]][pos[2]] = "uranium-ore"
end
global.maze_data_ore[x][y] = maze_data
last_maze_ore = maze_data
last_maze_ore_x = x
last_maze_ore_y = y
return maze_data
end
local function global_to_maze_pos(x, y)
--Ensures we start in the middle of a tile.
x = x + maze_tile_size/2
y = y + maze_tile_size/2
local maze_width_raw = (maze_width +1) * maze_tile_size
local maze_height_raw = (maze_height+1) * maze_tile_size
local global_maze_x = math.floor(x / maze_width_raw)
local global_maze_y = math.floor(y / maze_height_raw)
x = x - global_maze_x * maze_width_raw
y = y - global_maze_y * maze_height_raw
local inner_x, inner_y = x, y
local local_maze_x = math.floor(x / maze_tile_size)
local local_maze_y = math.floor(y / maze_tile_size)
x = x - local_maze_x * maze_tile_size
y = y - local_maze_y * maze_tile_size
return global_maze_x, global_maze_y, local_maze_x, local_maze_y, x, y
end
local function handle_maze_tile(x, y, surf, seed)
local orig_x, orig_y = x, y
local global_maze_x, global_maze_y, local_maze_x, local_maze_y = 0, 0, 0, 0
global_maze_x, global_maze_y, local_maze_x, local_maze_y, x, y = global_to_maze_pos(x, y)
local maze_data = get_maze(global_maze_x, global_maze_y, seed, maze_width, maze_height)
local maze_value = 0
if local_maze_x == 0 or local_maze_y == 0 then
if local_maze_x == 0 then
if local_maze_y ~= 0 then
if maze_data[maze_width+1][1] ~= local_maze_y then maze_value = 1 end
end
else
if maze_data[maze_width+1][2] ~= local_maze_x then maze_value = 2 end
end
else
maze_value = maze_data[local_maze_x][local_maze_y]
end
if x < maze_tile_border and y < maze_tile_border then return {name = "out-of-map", position = {orig_x, orig_y}} end
if x < maze_tile_border and bit32.btest(maze_value,1) then return {name = "out-of-map", position = {orig_x, orig_y}} end
if y < maze_tile_border and bit32.btest(maze_value,2) then return {name = "out-of-map", position = {orig_x, orig_y}} end
return nil
end
local function handle_maze_tile_ore(x, y, surf, seed)
local orig_x, orig_y = x, y
local spawn_distance_1k = math.sqrt(x*x + y*y) / 1000
local global_maze_x, global_maze_y, local_maze_x, local_maze_y = 0, 0, 0, 0
global_maze_x, global_maze_y, local_maze_x, local_maze_y, x, y = global_to_maze_pos(x, y)
if x < maze_tile_border or y < maze_tile_border then return end
local seed_x = global_maze_x * maze_width + local_maze_x
local seed_y = global_maze_x * maze_height + local_maze_y
local ore_name = nil
if local_maze_x == 0 or local_maze_y == 0 then
if global_maze_x == 0 and global_maze_y == 0 then
if local_maze_x == 1 and local_maze_y == 0 then ore_name = "iron-ore" end
if local_maze_x == 0 and local_maze_y == 1 then ore_name = "stone" end
elseif global_maze_x == -1 and global_maze_y == 0 and local_maze_x == maze_width and local_maze_y == 0 then ore_name = "copper-ore"
elseif global_maze_x == 0 and global_maze_y == -1 and local_maze_x == 0 and local_maze_y == maze_height then ore_name = "coal"
end
else
local maze_data = get_maze_ore(global_maze_x, global_maze_y, seed, maze_width, maze_height)
ore_name = maze_data[local_maze_x][local_maze_y]
end
if ore_name then
if surf.can_place_entity{name=ore_name, position={orig_x, orig_y}} then
local dist_x = math.abs(orig_x)
local dist_y = math.abs(orig_y)
dist = spawn_distance_1k
local resource_amount_max = math.floor(resource_density_factor * (dist * dist + 1))
local dist_x = maze_tile_size - x - 1
if (x - maze_tile_border) < dist_x then dist_x = (x - maze_tile_border) end
local dist_y = maze_tile_size - y - 1
if (y - maze_tile_border) < dist_y then dist_y = (y - maze_tile_border) end
dist = dist_x
if dist_y < dist then dist = dist_y end
dist = dist + 1
local resource_amount = resource_amount_max * dist / maze_tile_size * 2
if resource_amount > resource_amount_max / 2 then
surf.create_entity{name=ore_name, position={orig_x, orig_y}, amount=resource_amount}
end
end
end
end
local function on_chunk_generated_ore(event)
local entities = event.surface.find_entities(event.area)
for _, entity in pairs(entities) do
if entity.type == "resource" and entity.name ~= "crude-oil" then
entity.destroy()
end
end
local tx, ty = event.area.left_top.x, event.area.left_top.y
local ex, ey = event.area.right_bottom.x, event.area.right_bottom.y
for x=tx,ex do
for y=ty,ey do
handle_maze_tile_ore(x, y, game.surfaces[1], global.maze_seed)
end
end
end
function run_shape_module(event)
if not global.maze_seed then global.maze_seed = math.random(0, 65536 * 65536 - 1) end
local tiles = {}
local tx, ty = event.area.left_top.x, event.area.left_top.y
local ex, ey = event.area.right_bottom.x, event.area.right_bottom.y
for x=tx,ex do
for y=ty,ey do
local new_tile = handle_maze_tile(x, y, game.surfaces[1], global.maze_seed)
if new_tile then table.insert(tiles, new_tile) end
end
end
game.surfaces[1].set_tiles(tiles, true)
on_chunk_generated_ore(event)
end

View File

@ -1,7 +1,7 @@
--[[
This file is used to choose which styles you want.
You may choose up to one of each type shapes, terrain, ores and misc by removing uncommenting the line.
If you want to add your own module, just add it to the others
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.
--]]
@ -15,8 +15,9 @@ in this file and your run_*type*_module(event) function will be called.
--require "locale.gen_shape.spiral2"
--require "locale.gen_shape.donut"
--require "locale.gen_shape.rectangular_spiral"
--require "locale.gen_shape.x_map"
--require "locale.gen_shape.x_infinite"
--require "locale.gen_shape.lattice"
require "locale.gen_shape.infinite_mazes"
--terrain--

View File

@ -1,4 +1,5 @@
local function on_tick()
walk_on_tick()
if game.tick % 60 == 0 then
poll_on_second()
walk_distance_on_second()