2019-02-18 00:10:41 +02:00
|
|
|
require 'map_gen.maps.quadrants.switch_team'
|
|
|
|
require 'map_gen.maps.quadrants.restrict_placement'
|
|
|
|
|
2019-02-13 09:48:15 +02:00
|
|
|
local b = require('map_gen.shared.builders')
|
2019-02-18 00:10:41 +02:00
|
|
|
local Retailer = require('features.retailer')
|
|
|
|
local market_items = require 'resources.market_items'
|
|
|
|
local RS = require 'map_gen.shared.redmew_surface'
|
2019-02-13 09:48:15 +02:00
|
|
|
local Event = require 'utils.event'
|
2019-02-18 00:10:41 +02:00
|
|
|
local ScenarioInfo = require 'features.gui.info'
|
|
|
|
local Recipes = require 'map_gen.maps.quadrants.enabled_recipes'
|
2019-02-18 10:33:05 +02:00
|
|
|
local Global = require 'utils.global'
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
local abs = math.abs
|
2019-02-18 00:10:41 +02:00
|
|
|
local round = math.round
|
|
|
|
local redmew_config = global.config
|
|
|
|
|
|
|
|
ScenarioInfo.set_map_name('[WIP] Quadrants')
|
|
|
|
ScenarioInfo.set_map_description('Teamwork based map')
|
2019-02-18 10:33:05 +02:00
|
|
|
ScenarioInfo.add_map_extra_info([[
|
2019-02-18 00:10:41 +02:00
|
|
|
- Restricted research
|
|
|
|
- Restricted recipes
|
|
|
|
- Restricted teleport between quadrants
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
|
|
|
|
redmew_config.paint.enabled = false
|
|
|
|
|
|
|
|
redmew_config.player_create.starting_items = {
|
2019-02-18 10:33:05 +02:00
|
|
|
{ name = 'iron-plate', count = 7 },
|
|
|
|
{ name = 'iron-gear-wheel', count = 3 }
|
2019-02-18 00:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
redmew_config.player_create.join_messages = {
|
2019-02-18 10:33:05 +02:00
|
|
|
'Welcome to this map created by the RedMew team. You can join our discord at: redmew.com/discord',
|
|
|
|
'Click the question mark in the top left corner for server information and map details.',
|
|
|
|
'----',
|
|
|
|
'Quadrants is a different take on a teamwork based map. Be sure to read the map details!',
|
|
|
|
'--------'
|
2019-02-18 00:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local function spawn_market(surface, force, position)
|
2019-02-13 09:48:15 +02:00
|
|
|
|
2019-02-18 00:10:41 +02:00
|
|
|
position.y = round(position.y - 4)
|
|
|
|
position.x = round(position.x)
|
2019-02-13 09:48:15 +02:00
|
|
|
|
2019-02-18 00:10:41 +02:00
|
|
|
local pos = surface.find_non_colliding_position('market', position, 10, 1)
|
|
|
|
|
|
|
|
local market = surface.create_entity({ name = 'market', position = pos })
|
|
|
|
market.destructible = false
|
|
|
|
|
|
|
|
Retailer.add_market(pos.x .. 'fish_market' .. pos.y, market)
|
|
|
|
|
|
|
|
if table.size(Retailer.get_items(pos.x .. 'fish_market' .. pos.y)) == 0 then
|
|
|
|
for _, prototype in pairs(market_items) do
|
|
|
|
Retailer.set_item(pos.x .. 'fish_market' .. pos.y, prototype)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
force.add_chart_tag(surface, { icon = { type = 'item', name = 'coin' }, position = pos, text = 'Market' })
|
|
|
|
end
|
|
|
|
|
|
|
|
local function reset_recipes()
|
2019-02-18 10:33:05 +02:00
|
|
|
for _, force in pairs(game.forces) do
|
|
|
|
if (string.find(force.name, 'quadrant')) ~= nil then
|
|
|
|
for _, recipe in pairs(force.recipes) do
|
|
|
|
if not (Recipes[force.name].recipe[recipe.name] or Recipes.default.recipe[recipe.name]) then
|
|
|
|
recipe.enabled = false
|
|
|
|
end
|
2019-02-18 00:10:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
local function on_init()
|
2019-02-18 00:10:41 +02:00
|
|
|
local surface = RS.get_surface()
|
|
|
|
|
|
|
|
local q1 = game.create_force('quadrant1')
|
|
|
|
q1.set_spawn_position({ 64, -64 }, surface)
|
|
|
|
local q2 = game.create_force('quadrant2')
|
|
|
|
q2.set_spawn_position({ -64, -64 }, surface)
|
|
|
|
local q3 = game.create_force('quadrant3')
|
|
|
|
q3.set_spawn_position({ -64, 64 }, surface)
|
|
|
|
local q4 = game.create_force('quadrant4')
|
|
|
|
q4.set_spawn_position({ 64, 64 }, surface)
|
|
|
|
|
|
|
|
reset_recipes()
|
2019-02-18 10:33:05 +02:00
|
|
|
for _, force in pairs(game.forces) do
|
|
|
|
if (string.find(force.name, 'quadrant')) ~= nil then
|
|
|
|
force.share_chart = true
|
2019-02-18 00:10:41 +02:00
|
|
|
|
2019-02-18 10:33:05 +02:00
|
|
|
if force.name ~= 'quadrant1' then
|
|
|
|
force.disable_research()
|
|
|
|
end
|
2019-02-18 10:59:36 +02:00
|
|
|
for _, friend_force in pairs(game.forces) do
|
|
|
|
if (string.find(friend_force.name, 'quadrant')) ~= nil then
|
|
|
|
if friend_force ~= force then
|
|
|
|
force.set_friend(friend_force, true)
|
|
|
|
end
|
2019-02-18 10:33:05 +02:00
|
|
|
end
|
2019-02-18 00:10:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_research_finished(event)
|
2019-02-18 10:33:05 +02:00
|
|
|
if event.research.force ~= game.forces['quadrant1'] then
|
2019-02-18 00:10:41 +02:00
|
|
|
return
|
|
|
|
end
|
2019-02-18 10:33:05 +02:00
|
|
|
for _, force in pairs(game.forces) do
|
|
|
|
if (string.find(force.name, 'quadrant')) ~= nil then
|
|
|
|
if force.name ~= 'quadrant1' then
|
|
|
|
force.technologies[event.research.name].researched = true
|
|
|
|
end
|
2019-02-18 00:10:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
reset_recipes()
|
2019-02-13 09:48:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
Event.on_init(on_init)
|
2019-02-18 00:10:41 +02:00
|
|
|
Event.add(defines.events.on_research_finished, on_research_finished)
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
local function quadrants(x, y)
|
|
|
|
local abs_x = abs(x) - 0.5
|
|
|
|
local abs_y = abs(y) - 0.5
|
|
|
|
|
|
|
|
if (abs_x <= 200 and abs_y <= 200) then
|
|
|
|
if game.surfaces[2].get_tile(x, y).collides_with('water-tile') then
|
2019-02-18 00:10:41 +02:00
|
|
|
game.surfaces[2].set_tiles({ { name = "grass-1", position = { x, y } } }, true)
|
2019-02-13 09:48:15 +02:00
|
|
|
end
|
2019-02-18 00:10:41 +02:00
|
|
|
local entities = game.surfaces[2].find_entities({ { x - 0.5, y - 0.5 }, { x + 0.5, y + 0.5 } })
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
for _, entity in ipairs(entities) do
|
|
|
|
if entity.name ~= 'player' then
|
|
|
|
entity.destroy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-18 00:10:41 +02:00
|
|
|
if (abs_x == 100) and (abs_y == 100) then
|
|
|
|
spawn_market(RS.get_surface(), game.forces.player, { x = x, y = y })
|
2019-02-13 09:48:15 +02:00
|
|
|
end
|
|
|
|
|
2019-02-18 00:10:41 +02:00
|
|
|
if (abs_x >= 112 and abs_x <= 144 and abs_y >= 112 and abs_y <= 144) then
|
|
|
|
game.surfaces[2].set_tiles({ { name = "water", position = { x, y } } }, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
if (abs_x <= 23 or abs_y <= 23) then
|
|
|
|
-- Between quadrants create land
|
|
|
|
game.surfaces[2].set_tiles({ { name = "tutorial-grid", position = { x, y } } }, true)
|
|
|
|
local entities = game.surfaces[2].find_entities({ { x - 0.5, y - 0.5 }, { x + 0.5, y + 0.5 } })
|
2019-02-13 09:48:15 +02:00
|
|
|
|
2019-02-18 00:10:41 +02:00
|
|
|
for _, entity in ipairs(entities) do
|
|
|
|
if entity.name ~= 'player' then
|
|
|
|
entity.destroy()
|
2019-02-13 09:48:15 +02:00
|
|
|
end
|
2019-02-18 00:10:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if (abs_x <= 1 and abs_y <= 1) then
|
|
|
|
if abs_x == 1 and abs_y == 1 then
|
2019-02-13 09:48:15 +02:00
|
|
|
return false
|
|
|
|
end
|
2019-02-18 00:10:41 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if (abs_x <= 23 and abs_y <= 23) then
|
|
|
|
-- Around spawn, in between the quadrants
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if (abs_x < 2 or abs_y < 2) then
|
|
|
|
return false
|
2019-02-13 09:48:15 +02:00
|
|
|
end
|
2019-02-18 00:10:41 +02:00
|
|
|
|
|
|
|
return true
|
2019-02-13 09:48:15 +02:00
|
|
|
end
|
|
|
|
return true
|
2019-02-18 00:10:41 +02:00
|
|
|
|
2019-02-13 09:48:15 +02:00
|
|
|
end
|
|
|
|
|
2019-02-18 00:10:41 +02:00
|
|
|
local rectangle = b.rectangle(32, 32)
|
2019-02-13 09:48:15 +02:00
|
|
|
local tree_rectangle = b.rectangle(64, 16)
|
2019-02-18 00:10:41 +02:00
|
|
|
local tree_rectangle_1 = b.throttle_xy(tree_rectangle, 1, 3, 1, 3)
|
|
|
|
local tree_rectangle_2 = b.rotate(tree_rectangle_1, math.pi / 2)
|
2019-02-18 10:59:36 +02:00
|
|
|
local oil_rectangle = b.throttle_xy(tree_rectangle, 1, 5, 1, 5)
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
local function constant(x)
|
|
|
|
return function()
|
|
|
|
return x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local base_x = 48
|
|
|
|
local base_y = 48
|
|
|
|
|
|
|
|
local start_iron = b.resource(rectangle, 'iron-ore', constant(750))
|
|
|
|
local start_copper = b.resource(rectangle, 'copper-ore', constant(600))
|
|
|
|
local start_stone = b.resource(rectangle, 'stone', constant(600))
|
|
|
|
local start_coal = b.resource(rectangle, 'coal', constant(600))
|
|
|
|
local start_tree_1 = b.entity(tree_rectangle_1, 'tree-01')
|
2019-02-18 10:59:36 +02:00
|
|
|
local start_oil = b.resource(oil_rectangle, 'crude-oil', b.exponential_value(100000, 0, 1))
|
2019-02-13 09:48:15 +02:00
|
|
|
local start_tree_2 = b.entity(tree_rectangle_2, 'tree-01')
|
|
|
|
|
2019-02-18 00:10:41 +02:00
|
|
|
start_iron = b.combine({ b.translate(start_iron, base_x, base_y), b.translate(start_iron, -base_x, -base_y), b.translate(start_iron, base_x, -base_y), b.translate(start_iron, -base_x, base_y) })
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
base_x = base_x + 32
|
2019-02-18 00:10:41 +02:00
|
|
|
start_copper = b.combine({ b.translate(start_copper, base_x, base_y), b.translate(start_copper, -base_x, -base_y), b.translate(start_copper, base_x, -base_y), b.translate(start_copper, -base_x, base_y) })
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
base_y = base_x
|
2019-02-18 00:10:41 +02:00
|
|
|
start_stone = b.combine({ b.translate(start_stone, base_x, base_y), b.translate(start_stone, -base_x, -base_y), b.translate(start_stone, base_x, -base_y), b.translate(start_stone, -base_x, base_y) })
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
base_x = base_x - 32
|
2019-02-18 00:10:41 +02:00
|
|
|
start_coal = b.combine({ b.translate(start_coal, base_x, base_y), b.translate(start_coal, -base_x, -base_y), b.translate(start_coal, base_x, -base_y), b.translate(start_coal, -base_x, base_y) })
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
base_x = 64
|
|
|
|
base_y = 128
|
2019-02-18 10:59:36 +02:00
|
|
|
start_tree_1 = b.combine({ b.translate(start_tree_1, base_x, base_y), b.translate(start_tree_1, -base_x, -base_y), b.translate(start_tree_1, base_x, -base_y), b.translate(start_oil, -base_x, base_y) })
|
2019-02-13 09:48:15 +02:00
|
|
|
|
|
|
|
base_x = 128
|
|
|
|
base_y = 64
|
2019-02-18 00:10:41 +02:00
|
|
|
start_tree_2 = b.combine({ b.translate(start_tree_2, base_x, base_y), b.translate(start_tree_2, -base_x, -base_y), b.translate(start_tree_2, base_x, -base_y), b.translate(start_tree_2, -base_x, base_y) })
|
2019-02-13 09:48:15 +02:00
|
|
|
|
2019-02-18 10:59:36 +02:00
|
|
|
local map = b.apply_entities(quadrants, { start_iron, start_copper, start_stone, start_coal, start_tree_1, start_tree_2})
|
2019-02-18 10:38:41 +02:00
|
|
|
return map
|