Skip to content

Commit

Permalink
Refactoring + Changes from Refactorio#996
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFlapse committed Oct 12, 2019
1 parent ac7d606 commit 6eb6574
Show file tree
Hide file tree
Showing 11 changed files with 803 additions and 646 deletions.
71 changes: 71 additions & 0 deletions map_gen/maps/space_race/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
local Config = {
version = 'v0.2',
players_needed_to_start_game = 4,
bootstrap_period = 60 * 60 * 10, -- 10 minutes
player_kill_reward = 25,
entity_kill_rewards = {
['default'] = 1,
['wooden-chest'] = 0,
['gun-turret'] = 5,
['laser-turret'] = 10,
['flamethrower-turret'] = 8,
['artillery-turret'] = 50,
['artillery-wagon'] = 30,
['locomotive'] = 10,
['cargo-wagon'] = 5,
['fluid-wagon'] = 5,
['radar'] = 5
},
disabled_research = {
['military'] = {player = 2, entity = 8},
['military-2'] = {player = 6, entity = 24, unlocks = 'military'},
['military-3'] = {player = 12, entity = 48, unlocks = 'military-2'},
['military-4'] = {player = 24, entity = 96, unlocks = 'military-3'},
['stone-walls'] = {player = 2, entity = 8, invert = true},
['heavy-armor'] = {player = 12, entity = 48, invert = true},
['artillery-shell-range-1'] = nil
},
disabled_recipes = {
'tank',
'rocket-silo'
},
entity_drop_amount = {
--NEEDS BALANCING!
['biter-spawner'] = {low = 2, high = 10, chance = 1},
['spitter-spawner'] = {low = 2, high = 10, chance = 1},
['small-worm-turret'] = {low = 2, high = 5, chance = 0.5},
['medium-worm-turret'] = {low = 5, high = 7, chance = 0.5},
['big-worm-turret'] = {low = 5, high = 10, chance = 0.5},
['behemoth-worm-turret'] = {low = 5, high = 15, chance = 0.4},
-- default is 0, no chance of coins dropping from biters/spitters
['small-biter'] = {low = 1, high = 2, chance = 0.05},
['small-spitter'] = {low = 2, high = 3, chance = 0.05},
['medium-spitter'] = {low = 3, high = 6, chance = 0.05},
['big-spitter'] = {low = 5, high = 15, chance = 0.05},
['behemoth-spitter'] = {low = 20, high = 30, chance = 0.05},
['medium-biter'] = {low = 3, high = 5, chance = 0.05},
['big-biter'] = {low = 3, high = 8, chance = 0.05},
['behemoth-biter'] = {low = 8, high = 10, chance = 0.05}
},
turret_active_delays = {
['ammo-turret'] = 60 * 3,
['electric-turret'] = 60 * 10,
['fluid-turret'] = 60 * 5,
['artillery-turret'] = 60 * 60
},
warning_on_built = {
['artillery-turret'] = true,
['artillery-wagon'] = true,
['tank'] = true
},
neutral_entities = {
['wooden-chest'] = true
},
snake = {
size = 45,
max_food = 8,
speed = 30
}
}

return Config
126 changes: 126 additions & 0 deletions map_gen/maps/space_race/gui/join_gui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
local Gui = require 'utils.gui'

local Public = {}

-- <Join GUI start>

local join_USA = Gui.uid_name()
local join_USSR = Gui.uid_name()

function Public.show_gui(event)
local frame
local player = game.get_player(event.player_index)
local center = player.gui.center
local gui = center['Space-Race-Lobby']
if (gui) then
Gui.destroy(gui)
end

frame = player.gui.center.add {name = 'Space-Race-Lobby', type = 'frame', direction = 'vertical', style = 'captionless_frame'}

frame.style.minimal_width = 300

--Header
local top_flow = frame.add {type = 'flow', direction = 'horizontal'}
top_flow.style.horizontal_align = 'center'
top_flow.style.horizontally_stretchable = true

local title_flow = top_flow.add {type = 'flow'}
title_flow.style.horizontal_align = 'center'
title_flow.style.top_padding = 8
title_flow.style.horizontally_stretchable = false

local title = title_flow.add {type = 'label', caption = 'Welcome to Space Race'}
title.style.font = 'default-large-bold'

--Body

local content_flow = frame.add {type = 'flow', direction = 'horizontal'}
content_flow.style.top_padding = 8
content_flow.style.bottom_padding = 16
content_flow.style.left_padding = 24
content_flow.style.right_padding = 24
content_flow.style.horizontal_align = 'center'
content_flow.style.horizontally_stretchable = true

local label_flow = content_flow.add {type = 'flow'}
label_flow.style.horizontal_align = 'center'
label_flow.style.horizontally_stretchable = true

local label = label_flow.add {type = 'label', caption = 'Feel free to pick a side!'}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'

--Footer
local button_flow = frame.add {type = 'flow'}
button_flow.style.horizontal_align = 'center'
button_flow.style.horizontally_stretchable = true

local usa_button_flow = button_flow.add {type = 'flow', direction = 'vertical'}
usa_button_flow.style.horizontally_stretchable = true
usa_button_flow.style.horizontal_align = 'center'

local ussr_button_flow = button_flow.add {type = 'flow', direction = 'vertical'}
ussr_button_flow.style.horizontally_stretchable = true
ussr_button_flow.style.horizontal_align = 'center'

local teams = remote.call('space-race', 'get_teams')

local force_USSR = teams[2]
local force_USA = teams[1]

local usa_players = #force_USA.players
local ussr_players = #force_USSR.players

local usa_connected = #force_USA.connected_players
local ussr_connected = #force_USSR.connected_players

label = usa_button_flow.add {type = 'label', caption = usa_connected .. ' online / ' .. usa_players .. ' total'}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'

local join_usa_button = usa_button_flow.add {type = 'button', name = join_USA, caption = 'Join United Factory Workers'}

label = ussr_button_flow.add {type = 'label', caption = ussr_connected .. ' online / ' .. ussr_players .. ' total'}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'
local join_ussr_button = ussr_button_flow.add {type = 'button', name = join_USSR, caption = 'Join Union of Factory Employees'}

Gui.set_data(join_usa_button, frame)
Gui.set_data(join_ussr_button, frame)
end

Gui.on_click(
join_USA,
function(event)
local frame = Gui.get_data(event.element)
local player = event.player

if remote.call('space-race', 'join_usa', nil, player) then
Gui.remove_data_recursively(frame)
frame.destroy()
Public.update_gui()
end
end
)

Gui.on_click(
join_USSR,
function(event)
local frame = Gui.get_data(event.element)
local player = event.player

if remote.call('space-race', 'join_ussr', nil, player) then
Gui.remove_data_recursively(frame)
frame.destroy()
Public.update_gui()
end
end
)

-- <Join GUI end>

return Public
90 changes: 90 additions & 0 deletions map_gen/maps/space_race/gui/load_gui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
local Gui = require 'utils.gui'
local Color = require 'resources.color_presets'

local Public = {}

-- <Load GUI start>

function Public.show_gui(event)
local frame
local player = game.get_player(event.player_index)
local center = player.gui.center
local gui = center['Space-Race-Waiting']
if (gui) then
Gui.destroy(gui)
end

frame = player.gui.center.add {name = 'Space-Race-Waiting', type = 'frame', direction = 'vertical', style = 'captionless_frame'}

frame.style.minimal_width = 300

--Header
local top_flow = frame.add {type = 'flow', direction = 'horizontal'}
top_flow.style.horizontal_align = 'center'
top_flow.style.horizontally_stretchable = true

local title_flow = top_flow.add {type = 'flow'}
title_flow.style.horizontal_align = 'center'
title_flow.style.top_padding = 8
title_flow.style.horizontally_stretchable = false

local title = title_flow.add {type = 'label', caption = 'Welcome to Space Race'}
title.style.font = 'default-large-bold'

--Body

local content_flow = frame.add {type = 'flow'}
content_flow.style.top_padding = 8
content_flow.style.horizontal_align = 'center'
content_flow.style.horizontally_stretchable = true

local label_flow = content_flow.add {type = 'flow', direction = 'vertical'}
label_flow.style.horizontal_align = 'center'

label_flow.style.horizontally_stretchable = true
local label = label_flow.add {type = 'label', caption = 'Waiting for map to generate\nPlease wait\n'}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'
label.style.font_color = Color.yellow

local started_tick = remote.call('space-race', 'get_started_tick')
local time = game.tick - started_tick

if time > 60 then
local minutes = (time / 3600)
minutes = minutes - minutes % 1
time = time - (minutes * 3600)
local seconds = (time / 60)
seconds = seconds - seconds % 1
time = minutes .. ' minutes and ' .. seconds .. ' seconds'
else
local seconds = (time - (time % 60)) / 60
time = seconds .. ' seconds'
end

label = label_flow.add {type = 'label', caption = '[color=blue]Time elapsed: ' .. time .. ' [/color]'}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'
end

-- <Load GUI end>

function Public.show_gui_to_all()
for _, player in pairs(game.connected_players) do
Public.show_gui({player_index = player.index})
end
end

function Public.remove_gui()
for _, player in pairs(game.connected_players) do
local center = player.gui.center
local gui = center['Space-Race-Waiting']
if (gui) then
Gui.destroy(gui)
end
end
end

return Public
92 changes: 92 additions & 0 deletions map_gen/maps/space_race/gui/wait_gui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
local Gui = require 'utils.gui'
local snake_game = require 'features.snake.game'

local config = require 'map_gen.maps.space_race.config'
local players_needed = config.players_needed_to_start_game

local Public = {}

-- <Waiting GUI start>

local waiting_close_name = Gui.uid_name()

function Public.show_gui(event)
local frame
local player = game.get_player(event.player_index)
local center = player.gui.center
local gui = center['Space-Race-Lobby']
if (gui) then
Gui.destroy(gui)
end

local snake_button_text

if snake_game.is_running() then
snake_button_text = 'Play Snake'
else
snake_button_text = '... Loading Snake ...'
end
frame = player.gui.center.add {name = 'Space-Race-Lobby', type = 'frame', direction = 'vertical', style = 'captionless_frame'}

frame.style.minimal_width = 300

--Header
local top_flow = frame.add {type = 'flow', direction = 'horizontal'}
top_flow.style.horizontal_align = 'center'
top_flow.style.horizontally_stretchable = true

local title_flow = top_flow.add {type = 'flow'}
title_flow.style.horizontal_align = 'center'
title_flow.style.top_padding = 8
title_flow.style.horizontally_stretchable = false

local title = title_flow.add {type = 'label', caption = 'Welcome to Space Race'}
title.style.font = 'default-large-bold'

--Body

local content_flow = frame.add {type = 'flow', direction = 'horizontal'}
content_flow.style.top_padding = 8
content_flow.style.bottom_padding = 16
content_flow.style.left_padding = 24
content_flow.style.right_padding = 24
content_flow.style.horizontal_align = 'center'
content_flow.style.horizontally_stretchable = true

local label_flow = content_flow.add {type = 'flow'}
label_flow.style.horizontal_align = 'center'

label_flow.style.horizontally_stretchable = true
local label = label_flow.add {type = 'label', caption = #game.connected_players .. ' out of ' .. players_needed .. ' players needed to begin!'}
label.style.horizontal_align = 'center'
label.style.single_line = false
label.style.font = 'default'

--Footer
local ok_button_flow = frame.add {type = 'flow'}
ok_button_flow.style.horizontally_stretchable = true
ok_button_flow.style.horizontal_align = 'center'

local ok_button = ok_button_flow.add {type = 'button', name = waiting_close_name, caption = snake_button_text}
Gui.set_data(ok_button, frame)
end

Gui.on_click(
waiting_close_name,
function(event)
if snake_game.is_running() then
local frame = Gui.get_data(event.element)
local player = event.player

game.permissions.get_group('lobby').remove_player(player)
snake_game.new_snake(player)

Gui.remove_data_recursively(frame)
frame.destroy()
end
end
)

-- <Waiting GUI end>

return Public
Loading

0 comments on commit 6eb6574

Please sign in to comment.