1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00

Merge pull request #768 from SimonFlapse/Quadrants

Quadrants
This commit is contained in:
Matthew 2019-03-06 16:10:47 -05:00 committed by GitHub
commit 635bf89272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1599 additions and 0 deletions

61
locale/da/redmew_maps.cfg Normal file
View File

@ -0,0 +1,61 @@
# Denne fil indeholder alle lokaliseringsstrengene for specifikke baner
# Lokaliseringsstrenge tilhørende kvadrant scenariet (Oversættelse af SimonFlapse)
[quadrants]
on=TIL
off=FRA
compi_spawn_welcome=Velkommen til Redmew - Kvadranter!\n\nBrug vinduet i spilvinduets øverste venstre hjørne for at spille!
compi_spawn_cute=Jeg er nuttede
compi_common_transfer_item=Hvordan overfører man ting?\nDu kan bruge underjordiske bånd for at nå den anden siden\n\nDu kan også smide ting over ved at bruge ´Z´ tasten
compi_common_chat=Er du blevet stum?\nDu kan skrive beskeder ved at bruge knappen under ESC\n\nDu kan ændre dette i Settings (Indstillinger) -> Styring -> Slå Lua konsol til/fra
compi_common_market=Har du en mønt i overskud?\nDu kan bruge dine hårdt tjente penge here i markedet
compi_common_switch=Du kan skifte område!\nAlt det kræver er at du har en tom rygsæk\n\nDu skal stå i nærheden af mig og bruge vinduet øverst til venstre for at skifte
compi_common_chests=Problemer med at fjerne nogle kister?\nSpillere som skifter område kan efterlade en kiste med deres ting i\n\nDu skal tømme den for at fjerne den
compi_quadrant1_welcome=Velkommen til forsknings- og forsvarsområdet!\n\nDette er kommando centralen for alt militær og forskning
compi_quadrant1_science=Dette område er det eneste som kan forske\n\nDu er muligvis tvunget til at få teknologi pakker fra andre områder
compi_quadrant1_military=Du kan kun fremstille militære ting i dette område\n\nAndre områder er afhængig af at du sender militære ting til dem
compi_quadrant2_welcome=Velkommen til bearbejdnings- og minedriftsområdet!\n\nVi er de eneste producenter af stål og kredsløb!
compi_quadrant2_steel=Dette område er det eneste som kan fremstille stål\n\nAndre områder er afhængige af at du sender stål til dem!
compi_quadrant2_circuits=Dette område er det eneste som kan fremstille kredsløb\n\nAndre områder er afhængige af at du sender kredsløb til dem!
compi_quadrant2_resources=Rygterne siger at:\nDette områder har bedre rigdom i ressourcerne\n\nOmrådet er ideel til anlægning af miner
compi_quadrant3_welcome=Velkommen til oliebehandling- og teknologiområdet!\n\nHjemsted for al oliebehandling og produktion af teknologi
compi_quadrant3_oil=Dette område er det eneste som kan behandle råolie\n\nDu har måske brug for at få råolie fra andre områder
compi_quadrant3_tech=Dette område er det eneste som kan fremstille et større udvalg af teknologiske ting\n\nDu er måske tvunget til at få en masse bearbejdede materialer fra andre områder!
compi_quadrant3_rocket=Jeg har ladt mig fortælle at:\nDette område er en perfekt kandidate for at sende en rumraket i vejret\n\nAndre områder kan give dig de dele du har brug for
compi_quadrant4_welcome=Velkommen til logistik- og transportområdet!\n\nHjemsted for spaghetti og togbaner
compi_quadrant4_logistic=Dette område er det eneste som kan levere logistik ting\n\nHele regionen afhænger af dine ævner til at fremstille og levere disse til andre!
compi_quadrant4_born=Lad mig fortælle dig en hemmelighed:\nMine søskende og jeg er født her
popup_quadrant1_title=Forsking og kommando central
popup_quadrant2_title=Bearbejdede materialer og miner
popup_quadrant3_title=Oliebehanding og teknologi
popup_quadrant4_title=Logistiske løsninger
popup_quadrant1=Vores primære opgave er at forske til fordele for hele regionen\n\nSekundært er vi regionens kommando central\nVi leverer militært udstyr
popup_quadrant2=Vores primære opgave er at levere bearbejdet materiale til regionen\nVi specialiserer os i kredsløb af forskellig kompleksitet\nVi er også det område med certificeret stål!\nUndersøgelser viser at området har en øget righed af ressourcer
popup_quadrant3=Vores primære opgave er at levere olie produkter til regionen\nSekundært specialiserer vi os i høj teknologisk udstyr\nNoget af vores udstyr er klassificeret som radioaktivt
popup_quadrant4=Vores primære opgave er at levere logistiske løsninger til regionen\nVi specialiserer os i bånd- og robotbaserede løsninger\nVi har også en stor afdeling indenfor høj hastighedstoge!
switch_notice1=## - Din vægt er for høj til at kunne teleportere! Tøm venligst din rygsæk før du skifter område!
switch_notice2=## - Du skal muligvis træde væk fra grænsen
switch_quadrant1=Forskning og militær (__1__)
switch_quadrant1_tip=Dette er første kvadrant
switch_quadrant2=Materialer og miner (__1__)
switch_quadrant2_tip=Dette er anden kvadrant
switch_quadrant3=Olie og teknologi (__1__)
switch_quadrant3_tip=Dette er tredje kvadrant
switch_quadrant4=Logistik og transport (__1__)
switch_quadrant4_tip=Dette er fjedre kvadrant
switch_chest=Auto. tømning af rygsæk. Status: __1__
switch_chest_tip=Hvis slået til:\nDin rygsæk vil blive tømt til en kiste, når du skifter område
switch_welcome=Velkommen til Redmew - Kvadranter!
switch_desc=Mens du er i start området, så kan du skifte område!
switch_msg=Vælg et område du gerne vil hjælpe!
force_sync_research=[img=item/automation-science-pack] Ny teknologi forsket: [technology=__1__]

View File

@ -1 +1,60 @@
# This file holds all the locale strings for specific maps
# locale linked to the quadrants scenario
[quadrants]
on=ON
off=OFF
compi_spawn_welcome=Welcome to Redmew - Quadrants!\n\nUse the GUI in your top left corner to play!
compi_spawn_cute=I'm really cute
compi_common_transfer_item=How to transfer items?\nYou can use underground belts to reach the other side\n\nYou can also drop items across, just use the ´Z´ key
compi_common_chat=Have you been silenced?\nYou can chat using the key below ESC\n\nYou can change this in Settings -> Controls -> Toggle Lua console
compi_common_market=Spare some change?\nGo spend your hard-earned coins here at the market
compi_common_switch=You can switch area!\nAll it takes is that you have an empty inventory\n\nJust stand near me and use the gui in the top left corner to switch
compi_common_chests=Can't remove some chests?\nPlayers that switch area can leave behind a chest\n\nYou can empty it to remove it
compi_quadrant1_welcome=Welcome to Science and Military!\n\nCommand center of military and scientific advancement
compi_quadrant1_science=This area is the only one who can research\n\nYou would have to import some science packs from other areas
compi_quadrant1_military=You can only craft military items in this area\n\nOther areas depend on you sending military items to them
compi_quadrant2_welcome=Welcome to Intermediate and Mining!\n\nThe only producer of steel and electronic circuits!
compi_quadrant2_steel=This area is the only on who can produce steel\n\nOther areas depend on you sending steel to them
compi_quadrant2_circuits=This area is the only one who can produce circuits\n\nYou need to export them other areas!
compi_quadrant2_resources=Rumors say:\nThis area is extra rich in resources\n\nIt's ideal for mining operations
compi_quadrant3_welcome=Welcome to Oil and High Tech!\n\nHome of oil processing and technology
compi_quadrant3_oil=This area is the only one who can process crude oil\n\nYou may need to import crude oil from other areas
compi_quadrant3_tech=This area is the only one who can produce various high tech items\n\nYou may need to import a lot of intermediate products!
compi_quadrant3_rocket=I have heard:\nThis area is a perfect place to launch a rocket\n\nOther areas can provide you the parts you need
compi_quadrant4_welcome=Welcome to Logistics and Transport\n\nHome of spaghetti and trainyards
compi_quadrant4_logistic=This area is the only one who can deliver logistical solutions\n\nThe success of the region depends on you exporting these!
compi_quadrant4_born=Did you know?\nMy siblings and I were born here
popup_quadrant1_title=Research and command center
popup_quadrant2_title=Intermediate production and mining
popup_quadrant3_title=Oil and high tech production
popup_quadrant4_title=Logistical production
popup_quadrant1=Our main objective is to provide the region with new scientific discoveries\n\nSecondary we are the central command hub\nWe provide the region with military equipment
popup_quadrant2=Our main objective is to provide the region with intermediate products\nWe primarily supply electronic circuits in various densities\nWe're also the area with the highest quality steel!\nInitial survey shows increased resources in this area
popup_quadrant3=Our main objective is to provide the region with oil based products\nSecondary we are the regions technological leader\nWe provide the region with various high technology (and radioactive) products
popup_quadrant4=Our main objective is to provide the region with logistical solutions\nWe primarily supply belt and bot based solutions\nWe're also specialized in high performance train networks!
switch_notice1=## - You are too heavy for teleportation! Empty your inventory before switching quadrant!
switch_notice2=## - You may need to move away from the border
switch_quadrant1=Science and Military (__1__)
switch_quadrant1_tip=This is quadrant number 1
switch_quadrant2=Intermediate and Mining (__1__)
switch_quadrant2_tip=This is quadrant number 2
switch_quadrant3=Oil and High Tech (__1__)
switch_quadrant3_tip=This is quadrant number 3
switch_quadrant4=Logistics and Transport (__1__)
switch_quadrant4_tip=This is quadrant number 4
switch_chest=Auto. emptying of inventory. Currently: __1__
switch_chest_tip=If enabled:\nYour inventory will be emptied in a chest, when you switch quadrant
switch_welcome=Welcome to Redmew - Quadrants!
switch_desc=While in spawn, you can switch quadrant!
switch_msg=Go ahead and pick a quadrant you'd like to help out!
force_sync_research=[img=item/automation-science-pack] New research complete: [technology=__1__]

View File

@ -0,0 +1 @@
return require 'map_gen.maps.quadrants.scenario'

View File

@ -0,0 +1,129 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Task = require 'utils.task'
local Token = require 'utils.token'
local compilatrons = {}
local current_messages = {}
local messages = {
['spawn'] = {
{'quadrants.compi_spawn_welcome'},
{'quadrants.compi_common_transfer_item'},
{'quadrants.compi_spawn_welcome'},
{'quadrants.compi_spawn_cute'},
{'quadrants.compi_spawn_welcome'},
{'quadrants.compi_common_chat'}
},
['quadrant1'] = {
{'quadrants.compi_quadrant1_welcome'},
{'quadrants.compi_quadrant1_science'},
{'quadrants.compi_quadrant1_military'},
{'quadrants.compi_common_market'},
{'quadrants.compi_quadrant1_welcome'},
{'quadrants.compi_common_transfer_item'},
{'quadrants.compi_common_switch'},
{'quadrants.compi_common_chat'},
{'quadrants.compi_common_chests'}
},
['quadrant2'] = {
{'quadrants.compi_quadrant2_welcome'},
{'quadrants.compi_quadrant2_steel'},
{'quadrants.compi_quadrant2_circuits'},
{'quadrants.compi_quadrant2_resources'},
{'quadrants.compi_common_market'},
{'quadrants.compi_quadrant2_welcome'},
{'quadrants.compi_common_transfer_item'},
{'quadrants.compi_common_switch'},
{'quadrants.compi_common_chat'},
{'quadrants.compi_common_chests'}
},
['quadrant3'] = {
{'quadrants.compi_quadrant3_welcome'},
{'quadrants.compi_quadrant3_oil'},
{'quadrants.compi_quadrant3_tech'},
{'quadrants.compi_quadrant3_rocket'},
{'quadrants.compi_common_market'},
{'quadrants.compi_quadrant3_welcome'},
{'quadrants.compi_common_transfer_item'},
{'quadrants.compi_common_switch'},
{'quadrants.compi_common_chat'},
{'quadrants.compi_common_chests'}
},
['quadrant4'] = {
{'quadrants.compi_quadrant4_welcome'},
{'quadrants.compi_quadrant4_logistic'},
{'quadrants.compi_quadrant4_born'},
{'quadrants.compi_common_market'},
{'quadrants.compi_quadrant4_welcome'},
{'quadrants.compi_common_transfer_item'},
{'quadrants.compi_common_switch'},
{'quadrants.compi_common_chat'},
{'quadrants.compi_common_chests'}
}
}
local callback =
Token.register(
function(data)
local ent = data.ent
local name = data.name
local msg_number = data.msg_number
local message =
ent.surface.create_entity(
{name = 'compi-speech-bubble', text = messages[name][msg_number], position = {0, 0}, source = ent}
)
current_messages[name] = {message = message, msg_number = msg_number}
end
)
Global.register(
{
compilatrons = compilatrons,
current_messages = current_messages
},
function(tbl)
compilatrons = tbl.compilatrons
current_messages = tbl.current_messages
end
)
local function circle_messages()
for name, ent in pairs(compilatrons) do
local current_message = current_messages[name]
local msg_number
local message
if current_message ~= nil then
message = current_message.message
if message ~= nil then
message.destroy()
end
msg_number = current_message.msg_number
msg_number = (msg_number < #messages[name]) and msg_number + 1 or 1
else
msg_number = 1
end
Task.set_timeout_in_ticks(300, callback, {ent = ent, name = name, msg_number = msg_number})
end
end
Event.on_nth_tick(899 * 2, circle_messages)
local Public = {}
function Public.add_compilatron(entity, name)
if not entity and not entity.valid then
return
end
if name == nil then
return
end
compilatrons[name] = entity
local message =
entity.surface.create_entity(
{name = 'compi-speech-bubble', text = messages[name][1], position = {0, 0}, source = entity}
)
current_messages[name] = {message = message, msg_number = 1}
end
return Public

View File

@ -0,0 +1,241 @@
local recipes = {
default = {
recipe = {
['boiler'] = true,
['steam-engine'] = true,
['offshore-pump'] = true,
['stone-furnace'] = true,
['assembling-machine-1'] = true,
['copper-cable'] = true,
['iron-stick'] = true,
['iron-plate'] = true,
['copper-plate'] = true,
['stone-brick'] = true,
['burner-mining-drill'] = true,
['burner-inserter'] = true,
['transport-belt'] = true,
['small-electric-pole'] = true,
['wooden-chest'] = true,
['empty-crude-oil-barrel'] = true,
['empty-heavy-oil-barrel'] = true,
['empty-light-oil-barrel'] = true,
['empty-lubricant-barrel'] = true,
['empty-petroleum-gas-barrel'] = true,
['empty-sulfuric-acid-barrel'] = true,
['empty-water-barrel'] = true,
['medium-electric-pole'] = true,
['pipe'] = true,
['pipe-to-ground'] = true,
['small-lamp'] = true,
['repair-pack'] = true,
['pistol'] = true,
['firearm-magazine'] = true,
['light-armor'] = true,
['stone-wall'] = true,
['gate'] = true,
['gun-turret'] = true,
['iron-gear-wheel'] = true,
['iron-chest'] = true
}
},
quadrant1 = {
recipe = {
['automation-science-pack'] = true,
['military-science-pack'] = true,
['artillery-wagon'] = true,
['car'] = true,
['tank'] = true,
['lab'] = true,
['satellite'] = true,
['submachine-gun'] = true,
['shotgun'] = true,
['combat-shotgun'] = true,
['rocket-launcher'] = true,
['flamethrower'] = true,
['land-mine'] = true,
['piercing-rounds-magazine'] = true,
['uranium-rounds-magazine'] = true,
['shotgun-shells'] = true,
['piercing-shotgun-shells'] = true,
['cannon-shell'] = true,
['explosive-cannon-shell'] = true,
['uranium-cannon-shell'] = true,
['explosive-uranium-cannon-shell'] = true,
['artillery-shell'] = true,
['rocket'] = true,
['explosive-rocket'] = true,
['atomic-bomb'] = true,
['grenade'] = true,
['cluster-grenade'] = true,
['poison-capsule'] = true,
['slowdown-capsule'] = true,
['defender-capsule'] = true,
['distractor-capsule'] = true,
['destroyer-capsule'] = true,
['discharge-defense-remote'] = true,
['artillery-targeting-remote'] = true,
['heavy-armor'] = true,
['modular-armor'] = true,
['power-armor'] = true,
['power-armor-mk2'] = true,
['laser-turret'] = true,
['artillery-turret'] = true,
['radar'] = true,
['energy-shield-equipment'] = true,
['energy-shield-mk2-equipment'] = true,
['battery-equipment'] = true,
['battery-mk2-equipment'] = true,
['personal-laser-defense-equipment'] = true,
['discharge-defense-equipment'] = true,
['night-vision-equipment'] = true,
['railgun'] = true,
['railgun-dart'] = true
}
},
quadrant2 = {
recipe = {
['concrete'] = true,
['hazard-concrete'] = true,
['refined-concrete'] = true,
['refined-hazard-concrete'] = true,
['landfill'] = true,
['electric-mining-drill'] = true,
['solar-panel'] = true,
['accumulator'] = true,
['production-science-pack'] = true,
['low-density-structure'] = true,
['electronic-circuit'] = true,
['advanced-circuit'] = true,
['processing-unit'] = true,
['engine-unit'] = true,
['electric-engine-unit'] = true,
['steel-plate'] = true,
['solar-panel-equipment'] = true,
['chemical-science-pack'] = true
}
},
quadrant3 = {
recipe = {
['pump'] = true,
['fluid-wagon'] = true,
['red-wire'] = true,
['green-wire'] = true,
['arithmetic-combinator'] = true,
['decider-combinator'] = true,
['constant-combinator'] = true,
['power-switch'] = true,
['programmable-speaker'] = true,
['storage-tank'] = true,
['steam-turbine'] = true,
['nuclear-reactor'] = true,
['heat-exchanger'] = true,
['heat-pipe'] = true,
['pumpjack'] = true,
['electric-furnace'] = true,
['oil-refinery'] = true,
['chemical-plant'] = true,
['centrifuge'] = true,
['beacon'] = true,
['speed-module'] = true,
['speed-module-2'] = true,
['speed-module-3'] = true,
['effectivity-module'] = true,
['effectivity-module-2'] = true,
['effectivity-module-3'] = true,
['productivity-module'] = true,
['productivity-module-2'] = true,
['productivity-module-3'] = true,
['utility-science-pack'] = true,
['uranium-fuel-cell'] = true,
['nuclear-fuel-reprocessing'] = true,
['uranium-processing'] = true,
['kovarex-enrichment-process'] = true,
['rocket-control-unit'] = true,
['empty-barrel'] = true,
['fill-crude-oil-barrel'] = true,
['fill-heavy-oil-barrel'] = true,
['fill-light-oil-barrel'] = true,
['fill-lubricant-barrel'] = true,
['fill-petroleum-gas-barrel'] = true,
['fill-sulfuric-acid-barrel'] = true,
['fill-water-barrel'] = true,
['sulfuric-acid'] = true,
['basic-oil-processing'] = true,
['advanced-oil-processing'] = true,
['heavy-oil-cracking'] = true,
['light-oil-cracking'] = true,
['coal-liquefaction'] = true,
['solid-fuel-from-heavy-oil'] = true,
['solid-fuel-from-light-oil'] = true,
['solid-fuel-from-petroleum-gas'] = true,
['lubricant'] = true,
['sulfur'] = true,
['battery'] = true,
['explosives'] = true,
['plastic-bar'] = true,
['cliff-explosives'] = true,
['flamethrower-turret'] = true,
['flamethrower-ammo'] = true,
['flamethrower'] = true,
['fusion-reactor-equipment'] = true,
['rocket-silo'] = true,
['rocket-part'] = true,
['belt-immunity-equipment'] = true
}
},
quadrant4 = {
recipe = {
['steel-chest'] = true,
['fast-transport-belt'] = true,
['express-transport-belt'] = true,
['fast-underground-belt'] = true,
['express-underground-belt'] = true,
['underground-belt'] = true,
['splitter'] = true,
['fast-splitter'] = true,
['express-splitter'] = true,
['loader'] = true,
['fast-loader'] = true,
['express-loader'] = true,
['inserter'] = true,
['long-handed-inserter'] = true,
['fast-inserter'] = true,
['filter-inserter'] = true,
['stack-inserter'] = true,
['stack-filter-inserter'] = true,
['big-electric-pole'] = true,
['substation'] = true,
['rail'] = true,
['train-stop'] = true,
['rail-signal'] = true,
['rail-chain-signal'] = true,
['locomotive'] = true,
['cargo-wagon'] = true,
['logistic-robot'] = true,
['construction-robot'] = true,
['flying-robot-frame'] = true,
['logistic-chest-active-provider'] = true,
['logistic-chest-passive-provider'] = true,
['logistic-chest-storage'] = true,
['logistic-chest-buffer'] = true,
['logistic-chest-requester'] = true,
['roboport'] = true,
['electric-mining-drill'] = true,
['steel-furnace'] = true,
['assembling-machine-2'] = true,
['assembling-machine-3'] = true,
['logistic-science-pack'] = true,
['rocket-fuel'] = true,
['nuclear-fuel'] = true,
['exoskeleton-equipment'] = true,
['personal-roboport-equipment'] = true,
['personal-roboport-mk2-equipment'] = true
}
},
}
return recipes

View File

@ -0,0 +1,119 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Game = require 'utils.game'
local RS = require 'map_gen.shared.redmew_surface'
local chart_tags = {}
Global.register(
{
chart_tags = chart_tags
},
function(tbl)
chart_tags = tbl.chart_tags
end
)
local function console_chat(event)
if not event.player_index or event.player_index == nil then
return
end
local player = Game.get_player_by_index(event.player_index)
local player_force = player.force
for _, force in pairs(game.forces) do
if (string.find(force.name, 'quadrant')) ~= nil or force.name == 'player' then
if force.name ~= player_force.name then
if player.tag ~= '' then
force.print(player.name .. ' ' .. player.tag .. ': ' .. event.message, player.chat_color)
else
force.print(player.name .. ': ' .. event.message, player.chat_color)
end
end
end
end
end
local function create_tag(creating_force, data, remove)
local surface = RS.get_surface()
for _, force in pairs(game.forces) do
if (string.find(force.name, 'quadrant')) ~= nil then
if force.name ~= creating_force.name then
local old_tag =
force.find_chart_tags(
surface,
{{data.position.x - 0.5, data.position.y - 0.5}, {data.position.x + 0.5, data.position.y + 0.5}}
)[1]
if old_tag and old_tag.valid then
if remove then
old_tag.destroy()
else
if data.icon ~= nil then
old_tag.icon = data.icon
end
if data.last_user ~= nil then
old_tag.last_user = data.last_user
end
if data.text ~= nil then
old_tag.text = data.text
end
end
elseif not remove then
force.add_chart_tag(surface, data)
end
end
end
end
end
local function chart_tag_event(event, remove)
local tag = event.tag
local force = event.force
local modify = false
if remove ~= nil and not remove then
modify = true
end
remove = remove ~= nil and remove or false
if string.find(force.name, 'quadrant') == nil then
return
end
if chart_tags.position ~= nil and not modify and not remove then
if chart_tags.position.x == tag.position.x and chart_tags.position.y == tag.position.y then
return
end
elseif modify and chart_tags.text == tag.text and chart_tags.icon == tag.icon then
return
end
chart_tags = {icon = tag.icon, position = tag.position, text = tag.text, last_user = tag.last_user}
if remove then
chart_tags['remove'] = remove
end
create_tag(force, chart_tags, remove)
end
local function chart_tag_modified(event)
chart_tag_event(event, false)
end
local function chart_tag_remove(event)
chart_tag_event(event, true)
end
Event.add(defines.events.on_chart_tag_added, chart_tag_event)
Event.add(defines.events.on_chart_tag_modified, chart_tag_modified)
Event.add(defines.events.on_chart_tag_removed, chart_tag_remove)
local function research_finished(event)
if event.by_script then
return
end
local technology = event.research
for _, force in pairs(game.forces) do
if (string.find(force.name, 'quadrant')) ~= nil then
force.print({'quadrants.force_sync_research', technology.name}
)
end
end
end
Event.add(defines.events.on_console_chat, console_chat)
Event.add(defines.events.on_research_finished, research_finished)

View File

@ -0,0 +1,64 @@
local RS = require 'map_gen.shared.redmew_surface'
local Game = require 'utils.game'
local Event = require 'utils.event'
local Public = {}
local function create_chest(player, position)
local surface = RS.get_surface()
position = position ~= nil and position or player.position
local pos = surface.find_non_colliding_position('steel-chest', position, 0, 1)
local chest = surface.create_entity { name = 'steel-chest', position = pos, force = player.force }
chest.minable = false
return chest
end
function Public.transfer_inventory(player_index, inventories, position)
if inventories == nil or player_index == nil then
return 'You need to specify a player index and a table of define.inventory'
end
local player = Game.get_player_by_index(player_index)
local chest = create_chest(player, position)
for _, inventory in pairs(inventories) do
inventory = player.get_inventory(inventory)
for name, count in pairs(inventory.get_contents()) do
local ItemStack = { name = name, count = count }
inventory.remove(ItemStack)
while count > 0 do
if not chest.can_insert(ItemStack) then
chest = create_chest(player)
end
count = count - chest.insert(ItemStack)
ItemStack = { name = name, count = count }
end
end
end
return true
end
local function on_gui_closed(event)
local entity = event.entity
if entity == nil or not entity.valid then
return
end
if entity.name == 'steel-chest' and entity.minable == false and not entity.has_items_inside() then
entity.destroy()
end
end
local function ctrl_empty(event)
local entity = event.last_entity
if entity == nil or not entity.valid then
return
end
if entity.name == 'steel-chest' and not entity.minable then
event.entity = entity
on_gui_closed(event)
end
end
Event.add(defines.events.on_gui_closed, on_gui_closed)
Event.add(defines.events.on_selected_entity_changed, ctrl_empty)
Event.add(defines.events.on_pre_player_mined_item)
return Public

View File

@ -0,0 +1,87 @@
local Event = require 'utils.event'
local Game = require 'utils.game'
local abs = math.abs
local allowed_entities = {
['transport-belt'] = true,
['fast-transport-belt'] = true,
['express-transport-belt'] = true,
['underground-belt'] = true,
['fast-underground-belt'] = true,
['express-underground-belt'] = true,
['splitter'] = true,
['fast-splitter'] = true,
['express-splitter'] = true,
['stone-wall'] = true,
['pipe'] = true,
['pipe-to-ground'] = true
}
local quadrant_bounds = {
['quadrant1'] = {x = 24, y = -24},
['quadrant2'] = {x = -24, y = -24},
['quadrant3'] = {x = -24, y = 24},
['quadrant4'] = {x = 24, y = 24}
}
local function on_built_entity(event)
local entity = event.created_entity
local force = entity.force
if not entity or not entity.valid then
return
end
local s_box = entity.selection_box
local size_x = abs(s_box.left_top.x - s_box.right_bottom.x)
local size_y = abs(s_box.left_top.y - s_box.right_bottom.y)
local pos = {x = abs(entity.position.x) - (size_x / 2), y = abs(entity.position.y) - (size_y / 2)}
local entity_pos = entity.position
local within_range = false
if string.find(force.name, 'quadrant') then
local quadrant_bound = quadrant_bounds[force.name]
if (force.name == 'quadrant1') then
within_range = (entity_pos.x >= quadrant_bound.x and entity_pos.y <= quadrant_bound.y)
elseif (force.name == 'quadrant2') then
within_range = (entity_pos.x <= quadrant_bound.x and entity_pos.y <= quadrant_bound.y)
elseif (force.name == 'quadrant3') then
within_range = (entity_pos.x <= quadrant_bound.x and entity_pos.y >= quadrant_bound.y)
elseif (force.name == 'quadrant4') then
within_range = (entity_pos.x >= quadrant_bound.x and entity_pos.y >= quadrant_bound.y)
end
end
if not (pos.x <= 23 or pos.y <= 23) and (within_range) then
return
end
local name = entity.name
local ghost = false
if name == 'entity-ghost' then
name = entity.ghost_name
ghost = true
end
if name == 'tile-ghost' then
return
end
if allowed_entities[name] and not (pos.x < 2 or pos.y < 2) and (within_range or (pos.x <= 23 or pos.y <= 23)) then
return
end
local p = Game.get_player_by_index(event.player_index)
if not p or not p.valid then
return
end
entity.destroy()
if not ghost then
p.insert(event.stack)
end
end
Event.add(defines.events.on_built_entity, on_built_entity)

View File

@ -0,0 +1,444 @@
require 'map_gen.maps.quadrants.switch_team'
require 'map_gen.maps.quadrants.restrict_placement'
require 'map_gen.maps.quadrants.force_sync'
require 'map_gen.maps.quadrants.train_crossing'
local b = require('map_gen.shared.builders')
local Retailer = require('features.retailer')
local market_items = require 'resources.market_items'
local RS = require 'map_gen.shared.redmew_surface'
local Event = require 'utils.event'
local ScenarioInfo = require 'features.gui.info'
local Recipes = require 'map_gen.maps.quadrants.enabled_recipes'
local CompiHandler = require 'map_gen.maps.quadrants.compilatron_handler'
local Token = require 'utils.token'
local Task = require 'utils.task'
local abs = math.abs
local round = math.round
local redmew_config = global.config
ScenarioInfo.set_map_name('Quadrants')
ScenarioInfo.set_map_description('Take control over an area and work together as a region!')
ScenarioInfo.add_map_extra_info(
[[
This map is split in four quadrants.
Each quadrant has a main objective.
The following quadrants exists:
Science and Military, Intermediate and Mining,
Oil and High Tech, Logistics and Transport.
Common for all quadrants:
- Basic manufacturing and power
- Commercial super market present
- Teleportation between quadrants with empty inventory, excluding:
- Tools
- Utility Armor
- Weaponry
Science and Military
- Manages research for the entire region
- Supplies weaponry and security solutions to the entire region
Intermediate and Mining
- Only producer of steel
- High precision workers allowing for circuitry manufacturing
- Area found to have rich amount of minerals
Oil and High Tech
- Facilities for oil processing
- Facilities for nuclear handling
- Leading force in innovating products
- Rocket launch site
Logistics and Transport
- Leading force in logistical solutions
- Belt based
- Bot based
- Train based
Version: v1.0
]]
)
redmew_config.paint.enabled = false
redmew_config.player_create.starting_items = {
{name = 'iron-plate', count = 7},
{name = 'iron-gear-wheel', count = 3}
}
redmew_config.hail_hydra.enabled = true
redmew_config.hail_hydra.hydras = {
-- spitters
['small-spitter'] = {['small-worm-turret'] = {min = 0.2, max = 1}},
['medium-spitter'] = {['medium-worm-turret'] = {min = 0.2, max = 1}},
['big-spitter'] = {['big-worm-turret'] = {min = 0.2, max = 1}},
['behemoth-spitter'] = {['behemoth-worm-turret'] = {min = 0.2, max = 1}},
-- biters
['medium-biter'] = {['small-biter'] = {min = 1, max = 2}},
['big-biter'] = {['medium-biter'] = {min = 1, max = 2}},
['behemoth-biter'] = {['big-biter'] = {min = 1, max = 2}},
-- worms
['small-worm-turret'] = {['small-biter'] = {min = 1.5, max = 2.5}},
['medium-worm-turret'] = {['small-biter'] = {min = 2.5, max = 3.5}, ['medium-biter'] = {min = 1.0, max = 2}},
['big-worm-turret'] = {
['small-biter'] = {min = 2.5, max = 4.5},
['medium-biter'] = {min = 1.5, max = 2.2},
['big-biter'] = {min = 0.7, max = 1.5}
},
['behemoth-worm-turret'] = {
['small-biter'] = {min = 4.5, max = -1},
['medium-biter'] = {min = 2.5, max = 3.8},
['big-biter'] = {min = 1.2, max = 2.4},
['behemoth-biter'] = {min = 0.8, max = -1}
}
}
local function spawn_market(surface, position)
position.x = round(position.x)
position.y = round(position.y - 4)
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
pos = surface.find_non_colliding_position('compilatron', position, 10, 1)
local compi = surface.create_entity {name = 'compilatron', position = pos, force = game.forces.neutral}
local quadrant = 'quadrant'
if pos.x > 0 then
if pos.y > 0 then
quadrant = quadrant .. '4'
else
quadrant = quadrant .. '1'
end
else
if pos.y > 0 then
quadrant = quadrant .. '3'
else
quadrant = quadrant .. '2'
end
end
CompiHandler.add_compilatron(compi, quadrant)
end
local function reset_recipes()
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
end
end
end
end
local function on_init()
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()
for _, force in pairs(game.forces) do
if (string.find(force.name, 'quadrant')) ~= nil or force.name == 'player' then
force.share_chart = true
if force.name ~= 'quadrant1' then
force.disable_research()
end
for _, friend_force in pairs(game.forces) do
if (string.find(friend_force.name, 'quadrant')) ~= nil or friend_force.name == 'player' then
if friend_force ~= force then
force.set_friend(friend_force, true)
end
end
end
end
end
game.map_settings.enemy_evolution.time_factor = 0.000002
game.map_settings.enemy_evolution.destroy_factor = 0.000010
game.map_settings.enemy_evolution.pollution_factor = 0.000005
end
local function on_research_finished(event)
if event.research.force ~= game.forces['quadrant1'] then
return
end
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
end
end
reset_recipes()
end
local callback_token
local callback
local tile_numbers = {
[-26] = {22, -22, -21, -20, -19},
[-27] = {22, -22},
[-28] = {22, -22},
[-29] = {22, -22, -21, -20, -19},
[-30] = {22, -19},
[-31] = {22, -19},
[-32] = {22, -22, -21, -20, -19},
[25] = {19, 22, -22, -21, -20, -19},
[26] = {19, 22, -19},
[27] = {19, 22, -19},
[28] = {19, 20, 21, 22, -22, -21, -20, -19},
[29] = {22, -19},
[30] = {22, -19},
[31] = {22, -22, -21, -20, -19}
}
local function spawn_compilatron()
local pos = game.surfaces[2].find_non_colliding_position('compilatron', {-0.5, -0.5}, 1.5, 0.5)
local compi = game.surfaces[2].create_entity {name = 'compilatron', position = pos, force = game.forces.neutral}
CompiHandler.add_compilatron(compi, 'spawn')
for y, x_table in pairs(tile_numbers) do
for _, x in pairs(x_table) do
game.surfaces[2].set_tiles({{name = 'lab-white', position = {x = x, y = y}}}, true)
end
end
end
local function chunk_generated()
Event.remove_removable(defines.events.on_chunk_generated, callback_token)
Task.set_timeout_in_ticks(300, callback)
end
Event.on_init(on_init)
Event.add(defines.events.on_research_finished, on_research_finished)
callback_token = Token.register(chunk_generated)
callback = Token.register(spawn_compilatron)
Event.add_removable(defines.events.on_chunk_generated, callback_token)
local function rail_create(data)
local pos = data.pos
local direction = data.direction
local rail =
game.surfaces[2].create_entity {
name = 'straight-rail',
position = pos,
force = game.forces.neutral,
direction = direction
}
if rail and rail.valid then
rail.minable = false
rail.destructible = false
end
end
local rail_callback = Token.register(rail_create)
local function quadrants(x, y)
local abs_x = abs(x) - 0.5
local abs_y = abs(y) - 0.5
if true then
local pos = {x = x, y = y}
if x > -24 and x < 24 and (y == 211.5 or y == 205.5) then
Task.set_timeout_in_ticks(300, rail_callback, {pos = pos, direction = defines.direction.east})
elseif x > -24 and x < 24 and (y == -211.5 or y == -205.5) then
Task.set_timeout_in_ticks(300, rail_callback, {pos = pos, direction = defines.direction.east})
elseif y > -24 and y < 24 and (x == 211.5 or x == 205.5) then
Task.set_timeout_in_ticks(300, rail_callback, {pos = pos, direction = defines.direction.north})
elseif y > -24 and y < 24 and (x == -211.5 or x == -205.5) then
Task.set_timeout_in_ticks(300, rail_callback, {pos = pos, direction = defines.direction.north})
end
end
if (abs_x <= 200 and abs_y <= 200) then
if game.surfaces[2].get_tile(x, y).collides_with('water-tile') then
game.surfaces[2].set_tiles({{name = 'grass-1', position = {x, y}}}, true)
end
local entities = game.surfaces[2].find_entities({{x - 0.5, y - 0.5}, {x + 0.5, y + 0.5}})
for _, entity in ipairs(entities) do
if entity and entity.valid then
if entity.name ~= 'player' and entity.name ~= 'compilatron' and entity.name ~= 'straight-rail' then
entity.destroy()
end
end
end
end
if (x < 0 and y < 0) then
if not (abs_x <= 200 and abs_y <= 200) then
local resources =
game.surfaces[2].find_entities_filtered {
area = {{x - 0.5, y - 0.5}, {x + 0.5, y + 0.5}},
type = 'resource'
}
for _, resource in pairs(resources) do
if resource.name ~= 'crude-oil' then
local amount = b.euclidean_value(1, 0.002)
resource.amount = resource.amount * amount(x, y)
end
end
end
end
if (abs_x == 132) and (abs_y == 132) then
spawn_market(RS.get_surface(), {x = x, y = y})
end
if (abs_x >= 144 and abs_x <= 176 and abs_y >= 144 and abs_y <= 176) 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)
game.surfaces[2].destroy_decoratives {{x - 0.5, y - 0.5}, {x + 0.5, y + 0.5}}
local entities = game.surfaces[2].find_entities({{x - 0.5, y - 0.5}, {x + 0.5, y + 0.5}})
for _, entity in ipairs(entities) do
if entity and entity.valid then
if entity.name ~= 'player' then
entity.destroy()
end
end
end
if (abs_x <= 1 and abs_y <= 1) then
if abs_x == 1 and abs_y == 1 then
return false
end
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
end
if abs_x >= 384 or abs_y >= 384 then
return false
end
return true
end
return true
end
local rectangle = b.rectangle(32, 32)
local tree_rectangle = b.rectangle(64, 16)
local tree_rectangle_1 = b.throttle_world_xy(tree_rectangle, 1, 3, 1, 3)
local tree_rectangle_2 = b.rotate(tree_rectangle_1, math.pi / 2)
local oil_rectangle = b.throttle_world_xy(tree_rectangle, 1, 5, 1, 5)
local function constant(x)
return function()
return x
end
end
local base_x = 80
local base_y = 80
local start_iron = b.resource(rectangle, 'iron-ore', constant(600))
local start_copper = b.resource(rectangle, 'copper-ore', constant(450))
local start_stone = b.resource(rectangle, 'stone', constant(150))
local start_coal = b.resource(rectangle, 'coal', constant(300))
local start_tree_1 = b.entity(tree_rectangle_1, 'tree-01')
local start_oil = b.resource(oil_rectangle, 'crude-oil', b.exponential_value(50000, 0, 1))
local start_tree_2 = b.entity(tree_rectangle_2, 'tree-01')
start_iron =
b.any(
{
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)
}
)
base_x = base_x + 32
start_copper =
b.any(
{
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)
}
)
base_y = base_x
start_stone =
b.any(
{
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)
}
)
base_x = base_x - 32
start_coal =
b.any(
{
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)
}
)
base_x = 96
base_y = 160
start_tree_1 =
b.any(
{
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)
}
)
base_x = 160
base_y = 96
start_tree_2 =
b.any(
{
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)
}
)
local map = b.apply_entities(quadrants, {start_iron, start_copper, start_stone, start_coal, start_tree_1, start_tree_2})
return map

View File

@ -0,0 +1,295 @@
local Event = require 'utils.event'
local Gui = require 'utils.gui'
local Game = require 'utils.game'
local abs = math.abs
local Color = require 'resources.color_presets'
local Popup = require 'features.gui.popup'
local RS = require 'map_gen.shared.redmew_surface'
local Item_to_chest = require 'map_gen.maps.quadrants.item_to_chest'
local Global = require 'utils.global'
local gui = {}
local spawn_locations = {
quadrant_1 = {64, -64},
quadrant_2 = {-64, -64},
quadrant_3 = {-64, 64},
quadrant_4 = {64, 64}
}
local toggle_chest_status = {}
Global.register(
{
toggle_chest_status = toggle_chest_status
},
function(tbl)
toggle_chest_status = tbl.toggle_chest_status
end
)
local quadrant_message = {
{
title = {'quadrants.popup_quadrant1_title'},
msg = {'quadrants.popup_quadrant1'}
},
{
title = {'quadrants.popup_quadrant2_title'},
msg = {'quadrants.popup_quadrant2'}
},
{
title = {'quadrants.popup_quadrant3_title'},
msg = {'quadrants.popup_quadrant3'}
},
{
title = {'quadrants.popup_quadrant4_title'},
msg = {'quadrants.popup_quadrant4'}
}
}
local function teleport(event, quadrant)
local player = event.player
local toggle_status = toggle_chest_status[player.index]
if
(abs(player.position.x) <= 4 and abs(player.position.y) <= 4) or
(player.get_inventory(defines.inventory.player_main).is_empty() and
player.get_inventory(defines.inventory.player_trash).is_empty()) or
((abs(player.position.x) >= 23 and (abs(player.position.y) >= 23)) and toggle_status and
Item_to_chest.transfer_inventory(
player.index,
{defines.inventory.player_main, defines.inventory.player_trash}
))
then
local pos =
RS.get_surface().find_non_colliding_position('player', spawn_locations['quadrant_' .. quadrant], 5, 1)
player.teleport(pos)
player.force = game.forces['quadrant' .. quadrant]
Popup.player(
player,
quadrant_message[quadrant].msg,
quadrant_message[quadrant].title,
nil,
'Quadrants.quadrant_description'
)
else
player.print({'quadrants.switch_notice1'}, Color.red)
player.print({'quadrants.switch_notice1'}, Color.red)
end
end
local function redraw_quadrant_button(data)
local left_flow = data.left_flow_btn1
local right_flow = data.right_flow_btn1
Gui.clear(left_flow)
Gui.clear(right_flow)
left_flow.add(
{
type = 'button',
name = 'Quadrants.Button.2',
caption = {'quadrants.switch_quadrant2', #game.forces['quadrant2'].connected_players},
tooltip = {'quadrants.switch_quadrant2_tip'}
}
)
right_flow.add(
{
type = 'button',
name = 'Quadrants.Button.1',
caption = {'quadrants.switch_quadrant1', #game.forces['quadrant1'].connected_players},
tooltip = {'quadrants.switch_quadrant1_tip'}
}
)
left_flow = data.left_flow_btn2
right_flow = data.right_flow_btn2
Gui.clear(left_flow)
Gui.clear(right_flow)
left_flow.add(
{
type = 'button',
name = 'Quadrants.Button.3',
caption = {'quadrants.switch_quadrant3', #game.forces['quadrant3'].connected_players},
tooltip = {'quadrants.switch_quadrant3_tip'}
}
)
right_flow.add(
{
type = 'button',
name = 'Quadrants.Button.4',
caption = {'quadrants.switch_quadrant4', #game.forces['quadrant4'].connected_players},
tooltip = {'quadrants.switch_quadrant4_tip'}
}
)
end
local function redraw_chest_button(data, player)
local left_flow = data.chest_button_left_flow
local toggle_status = toggle_chest_status[player.index] and {'quadrants.on'} or {'quadrants.off'}
Gui.clear(left_flow)
local button =
left_flow.add(
{
type = 'button',
name = 'Quadrants.Button.Toggle',
caption = {'quadrants.switch_chest', toggle_status},
tooltip = {'quadrants.switch_chest_tip'}
}
)
button.style.font = 'default'
end
local function toggle(event)
local player = event.player
local left = player.gui.left
local frame = left['Quadrants.Switch_Team']
if (frame and event.trigger == nil) then
Gui.destroy(frame)
return
elseif (frame) then
local data = Gui.get_data(frame)
redraw_quadrant_button(data, player)
redraw_chest_button(data, player)
return
end
frame = left.add({name = 'Quadrants.Switch_Team', type = 'frame', direction = 'vertical'})
local content_flow = frame.add {type = 'flow', direction = 'vertical'}
local label_flow = content_flow.add {type = 'flow'}
label_flow.style.horizontally_stretchable = false
local label = label_flow.add {type = 'label', caption = {'quadrants.switch_welcome'}}
label.style.single_line = false
label.style.font = 'default-large-bold'
label_flow = content_flow.add {type = 'flow'}
label = label_flow.add {type = 'label', caption = {'quadrants.switch_desc'}}
label.style.single_line = false
label.style.font = 'default'
label_flow = content_flow.add {type = 'flow'}
label = label_flow.add {type = 'label', caption = {'quadrants.switch_msg'}}
label.style.single_line = false
label.style.font = 'default'
content_flow = frame.add {type = 'flow', direction = 'horizontal'}
local left_flow_btn1 = content_flow.add {type = 'flow', direction = 'horizontal'}
left_flow_btn1.style.horizontal_align = 'left'
left_flow_btn1.style.horizontally_stretchable = false
local right_flow_btn1 = content_flow.add {type = 'flow', direction = 'horizontal'}
right_flow_btn1.style.horizontal_align = 'right'
right_flow_btn1.style.horizontally_stretchable = false
content_flow = frame.add {type = 'flow', direction = 'horizontal'}
local left_flow_btn2 = content_flow.add {type = 'flow', direction = 'horizontal'}
left_flow_btn2.style.horizontal_align = 'left'
left_flow_btn2.style.horizontally_stretchable = false
local right_flow_btn2 = content_flow.add {type = 'flow', direction = 'horizontal'}
right_flow_btn2.style.horizontal_align = 'right'
right_flow_btn2.style.horizontally_stretchable = false
content_flow = frame.add {type = 'flow', direction = 'horizontal'}
local chest_button_left_flow = content_flow.add {type = 'flow', direction = 'horizontal'}
chest_button_left_flow.style.horizontal_align = 'left'
chest_button_left_flow.style.horizontally_stretchable = false
chest_button_left_flow.style.top_padding = 12
local data = {
frame = frame,
left_flow_btn1 = left_flow_btn1,
right_flow_btn1 = right_flow_btn1,
left_flow_btn2 = left_flow_btn2,
right_flow_btn2 = right_flow_btn2,
chest_button_left_flow = chest_button_left_flow
}
redraw_quadrant_button(data)
redraw_chest_button(data, player)
Gui.set_data(frame, data)
end
local function update_gui(force_update)
local players = game.connected_players
for i = #players, 1, -1 do
local p = players[i]
local frame = p.gui.left['Quadrants.Switch_Team']
local data = {player = p}
if frame and frame.valid and (abs(p.position.x) >= 160 or abs(p.position.y) >= 160) then
toggle(data)
elseif not frame and not (abs(p.position.x) > 160 or abs(p.position.y) > 160) then
toggle(data)
elseif frame and frame.valid and force_update then
data['trigger'] = true
toggle(data)
end
end
end
local function toggle_chest(event)
local toggle_status = toggle_chest_status[event.player.index]
if not toggle_status then
toggle_chest_status[event.player.index] = true
else
toggle_chest_status[event.player.index] = false
end
event.trigger = true
toggle(event)
end
Gui.on_click(
'Quadrants.Button.1',
function(event)
teleport(event, 1)
end
)
Gui.on_click(
'Quadrants.Button.2',
function(event)
teleport(event, 2)
end
)
Gui.on_click(
'Quadrants.Button.3',
function(event)
teleport(event, 3)
end
)
Gui.on_click(
'Quadrants.Button.4',
function(event)
teleport(event, 4)
end
)
Gui.on_click(
'Quadrants.Button.Toggle',
function(event)
toggle_chest(event)
end
)
local function on_player_created(event)
event.player = Game.get_player_by_index(event.player_index)
toggle_chest_status[event.player_index] = true
toggle(event)
end
local function changed_force()
update_gui(true)
end
Event.add(defines.events.on_player_created, on_player_created)
Event.on_nth_tick(61, update_gui)
Event.add(defines.events.on_player_changed_force, changed_force)
return gui

View File

@ -0,0 +1,99 @@
local Event = require 'utils.event'
local Game = require 'utils.game'
local Item_to_chest = require 'map_gen.maps.quadrants.item_to_chest'
local pow = math.pow
local rail_locations = {26, 208}
local function clear_inventory_train(event)
local player = Game.get_player_by_index(event.player_index)
if (not player.driving and event.trigger == nil) or (player.driving and event.trigger) then
return false
end
local pos = player.position
local force = player.force
local within_range = false
local rail_location
if string.find(force.name, 'quadrant') then
if (force.name == 'quadrant1') then
within_range = (pos.x >= 0 and pos.y <= 0)
rail_location = {
{x = rail_locations[1], y = -rail_locations[2]},
{x = rail_locations[2], y = -rail_locations[1]}
}
elseif (force.name == 'quadrant2') then
within_range = (pos.x <= 0 and pos.y <= 0)
rail_location = {
{x = -rail_locations[1], y = -rail_locations[2]},
{x = -rail_locations[2], y = -rail_locations[1]}
}
elseif (force.name == 'quadrant3') then
within_range = (pos.x <= 0 and pos.y >= 0)
rail_location = {
{x = -rail_locations[1], y = rail_locations[2]},
{x = -rail_locations[2], y = rail_locations[1]}
}
elseif (force.name == 'quadrant4') then
within_range = (pos.x >= 0 and pos.y >= 0)
rail_location = {
{x = rail_locations[1], y = rail_locations[2]},
{x = rail_locations[2], y = rail_locations[1]}
}
end
end
if within_range then
return false
end
player.clean_cursor()
if
player.get_inventory(defines.inventory.player_main).is_empty() and
player.get_inventory(defines.inventory.player_trash).is_empty()
then
return true
end
local distance1 = pow(pow(rail_location[1].x - pos.x, 2) + pow(rail_location[1].y - pos.y, 2), 0.5)
local distance2 = pow(pow(rail_location[2].x - pos.x, 2) + pow(rail_location[2].y - pos.y, 2), 0.5)
if distance1 <= distance2 then
Item_to_chest.transfer_inventory(
event.player_index,
{defines.inventory.player_main, defines.inventory.player_trash},
rail_location[1]
)
else
Item_to_chest.transfer_inventory(
event.player_index,
{defines.inventory.player_main, defines.inventory.player_trash},
rail_location[2]
)
end
return true
end
local function clear_inventory(event)
event.trigger = true
if not clear_inventory_train(event) then
return
end
local player = Game.get_player_by_index(event.player_index)
local pos = player.position
local quadrant
if (pos.x >= 0 and pos.y <= 0) then
quadrant = 1
elseif (pos.x <= 0 and pos.y <= 0) then
quadrant = 2
elseif (pos.x <= 0 and pos.y >= 0) then
quadrant = 3
elseif (pos.x >= 0 and pos.y >= 0) then
quadrant = 4
end
player.force = game.forces['quadrant' .. quadrant]
end
Event.add(defines.events.on_player_driving_changed_state, clear_inventory)
Event.add(defines.events.on_player_dropped_item, clear_inventory_train)
Event.add(defines.events.on_player_fast_transferred, clear_inventory_train)
Event.add(defines.events.on_gui_opened, clear_inventory_train)