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

Merge pull request #980 from Jayefuu/branch

Added rail_grid map preset and preview
This commit is contained in:
grilledham 2019-10-05 11:45:11 +01:00 committed by GitHub
commit c6fd8ec4ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 197 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

View File

@ -0,0 +1,9 @@
-- Map by Jayefuu, grilledham, R.Nukem and Soggs
-- Notes:
-- - We recommend playing with RSO to force expansion by rail
-- - If playing with mods, do not use FARL, the rail placing mechanic will not work with this map
require 'map_gen.maps.rail_grid.scenario_setup'
require 'map_gen.maps.rail_grid.rail_grid_restrictions'
return require 'map_gen.maps.rail_grid.map'

View File

@ -0,0 +1,47 @@
local b = require 'map_gen.shared.builders'
local rad = math.rad
-- x and y must be even numbers else rail grid is misaligned.
local spawn_position = {x = 20, y = 20}
local function is_not_water_tile(_, _, world)
local gen_tile = world.surface.get_tile(world.x, world.y)
return not gen_tile.collides_with('water-tile')
end
local station_length = 40
local station =
b.any {
b.rectangle(station_length, 18),
b.translate(b.square_diamond(18), station_length / 2, 0), -- these just make it pretty
b.translate(b.square_diamond(18), station_length / -2, 0) -- these just make it pretty
}
local grid_size = 224
local path =
b.any {
b.square_diamond(40),
b.rectangle(grid_size, 6),
b.rectangle(6, grid_size),
b.circular_pattern(b.rotate(station, rad(90)), 4, grid_size / 3)
}
path = b.change_tile(path, true, 'landfill') -- MUST be landfill or the rail removal event doesn't work.
local grid = b.single_grid_pattern(path, grid_size, grid_size)
local no_water_grid = b.choose(is_not_water_tile, grid, b.full_shape)
local map = b.if_else(no_water_grid, b.full_shape)
-- replace grass tiles with dirt so that the rail grid is more clear.
local tile_map = {
['grass-1'] = 'dirt-1',
['grass-2'] = 'dirt-2',
['grass-3'] = 'dirt-3',
['grass-4'] = 'dirt-4'
}
map = b.change_map_gen_tiles(map, tile_map)
map = b.translate(map, 1 - spawn_position.x, 1 - spawn_position.y)
return map

View File

@ -0,0 +1,84 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local RestrictEntities = require 'map_gen.shared.entity_placement_restriction'
local Popup = require 'features.gui.popup'
local floor = math.floor
local players_popuped = {}
Global.register(
players_popuped,
function(tbl)
players_popuped = tbl
end
)
local rail_entities = {
['straight-rail'] = true,
['curved-rail'] = true
}
local function all_on_landfill(entity)
local get_tile = entity.surface.get_tile
local area = entity.bounding_box
local left_top = area.left_top
local right_bottom = area.right_bottom
for x = floor(left_top.x), floor(right_bottom.x) do
for y = floor(left_top.y), floor(right_bottom.y) do
if get_tile(x, y).name ~= 'landfill' then
return false
end
end
end
return true
end
RestrictEntities.set_keep_alive_callback(
function(entity)
local name = entity.name
if name == 'entity-ghost' then
name = entity.ghost_name
end
if not rail_entities[name] then
return true
end
return all_on_landfill(entity)
end
)
-- On first time player places rail entity on invalid tile, show popup explaining the rail mechanic.
local function restricted_entity_destroyed(event)
local p = event.player
if not p or not p.valid then
return
end
if players_popuped[p.index] then
return
end
Popup.player(p, 'Rails can only be built on green tiles.', nil, nil, 'rail_grid')
players_popuped[p.index] = true
end
-- On player join print a notice explaining the rail mechanic
local function player_joined_game(event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
player.print(
"Welcome to RedMew's Rail Grids Map. Rails can only be built on green tiles.",
{r = 0, g = 1, b = 0, a = 1}
)
end
Event.add(RestrictEntities.events.on_restricted_entity_destroyed, restricted_entity_destroyed)
Event.add(defines.events.on_player_joined_game, player_joined_game)

View File

@ -0,0 +1,31 @@
local ScenarioInfo = require 'features.gui.info'
local RS = require 'map_gen.shared.redmew_surface'
local MGSP = require 'resources.map_gen_settings'
-- Setup surface and map settings
RS.set_map_gen_settings(
{
MGSP.cliff_none,
MGSP.grass_disabled,
MGSP.enable_water
}
)
ScenarioInfo.set_map_name('Rail Grid')
ScenarioInfo.set_map_description(
[[
Nauvis' factory planners have been disappointed with the recent trend towards
rail spaghetti. As such they have enacted rules to enforce neat grid shaped
rails and crossings.
]]
)
ScenarioInfo.add_map_extra_info(
[[
This map has green "city blocks" to enforce construction of rail in a grid
pattern.
You cannot place rail on any tile type except landfill. There is space at the
grid intersections for junctions and turnarounds. There is space for
two stations on each side of the grid.
]]
)

View File

@ -1497,6 +1497,32 @@ function Builders.change_map_gen_tile(shape, old_tile, new_tile)
end
end
-- only changes tiles made by the factorio map generator.
function Builders.change_map_gen_tiles(shape, new_tile_map)
return function(x, y, world)
local function handle_tile(tile)
if type(tile) == 'boolean' and tile then
local gen_tile = world.surface.get_tile(world.x, world.y).name
local new_tile = new_tile_map[gen_tile]
if new_tile ~= nil then
return new_tile
end
end
return tile
end
local tile = shape(x, y, world)
if type(tile) == 'table' then
tile.tile = handle_tile(tile.tile)
else
tile = handle_tile(tile)
end
return tile
end
end
function Builders.change_map_gen_hidden_tile(shape, old_tile, hidden_tile)
return function(x, y, world)
local function is_collides()