mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-24 03:47:58 +02:00
Merge pull request #86 from MaemiKozue/master
Biter Battles: Added technology view for spectators
This commit is contained in:
commit
950aa6febe
@ -1,7 +1,9 @@
|
||||
local event = require 'utils.event'
|
||||
local event = require 'utils.event'
|
||||
local spy_fish = require "maps.biter_battles_v2.spy_fish"
|
||||
local feed_the_biters = require "maps.biter_battles_v2.feeding"
|
||||
|
||||
require "maps.biter_battles_v2.spec_spy"
|
||||
|
||||
local food_names = {
|
||||
["automation-science-pack"] = true,
|
||||
["logistic-science-pack"] = true,
|
||||
@ -15,11 +17,13 @@ local food_names = {
|
||||
local gui_values = {
|
||||
["north"] = {force = "north", biter_force = "north_biters", c1 = bb_config.north_side_team_name, c2 = "JOIN ", n1 = "join_north_button",
|
||||
t1 = "Evolution of the North side biters. Can go beyond 100% for endgame modifiers.",
|
||||
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.55, g = 0.55, b = 0.99}, color2 = {r = 0.66, g = 0.66, b = 0.99}},
|
||||
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.55, g = 0.55, b = 0.99}, color2 = {r = 0.66, g = 0.66, b = 0.99},
|
||||
tech_spy = "spy-north-tech", prod_spy = "spy-north-prod"},
|
||||
["south"] = {force = "south", biter_force = "south_biters", c1 = bb_config.south_side_team_name, c2 = "JOIN ", n1 = "join_south_button",
|
||||
t1 = "Evolution of the South side biters. Can go beyond 100% for endgame modifiers.",
|
||||
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.99, g = 0.33, b = 0.33}, color2 = {r = 0.99, g = 0.44, b = 0.44}}
|
||||
}
|
||||
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.99, g = 0.33, b = 0.33}, color2 = {r = 0.99, g = 0.44, b = 0.44},
|
||||
tech_spy = "spy-south-tech", prod_spy = "spy-south-prod"}
|
||||
}
|
||||
|
||||
local map_gen_messages = {
|
||||
"Map is still generating, please get comfy.",
|
||||
@ -30,7 +34,7 @@ local map_gen_messages = {
|
||||
"Map is still generating, please pet the cat.",
|
||||
"Map is still generating, time to get a bowl of snacks :3"
|
||||
}
|
||||
|
||||
|
||||
local function create_sprite_button(player)
|
||||
if player.gui.top["bb_toggle_button"] then return end
|
||||
local button = player.gui.top.add({type = "sprite-button", name = "bb_toggle_button", sprite = "entity/big-spitter"})
|
||||
@ -40,7 +44,7 @@ local function create_sprite_button(player)
|
||||
button.style.top_padding = 2
|
||||
button.style.left_padding = 4
|
||||
button.style.right_padding = 4
|
||||
button.style.bottom_padding = 2
|
||||
button.style.bottom_padding = 2
|
||||
end
|
||||
|
||||
local function create_first_join_gui(player)
|
||||
@ -53,9 +57,9 @@ local function create_first_join_gui(player)
|
||||
local b = frame.add { type = "label", caption = "Feed the enemy team's biters to gain advantage!" }
|
||||
b.style.font = "heading-2"
|
||||
b.style.font_color = {r=0.98, g=0.66, b=0.22}
|
||||
|
||||
|
||||
frame.add { type = "label", caption = "-----------------------------------------------------------"}
|
||||
|
||||
|
||||
for _, gui_value in pairs(gui_values) do
|
||||
local t = frame.add { type = "table", column_count = 3 }
|
||||
local c = gui_value.c1
|
||||
@ -68,43 +72,65 @@ local function create_first_join_gui(player)
|
||||
local l = t.add { type = "label", caption = " - "}
|
||||
local l = t.add { type = "label", caption = #game.forces[gui_value.force].connected_players .. " Players "}
|
||||
l.style.font_color = { r=0.22, g=0.88, b=0.22}
|
||||
|
||||
local c = gui_value.c2
|
||||
|
||||
local c = gui_value.c2
|
||||
local font_color = gui_value.color1
|
||||
if global.game_lobby_active then
|
||||
font_color = {r=0.7, g=0.7, b=0.7}
|
||||
c = c .. " (waiting for players... "
|
||||
c = c .. math.ceil((global.game_lobby_timeout - game.tick)/60)
|
||||
c = c .. ")"
|
||||
end
|
||||
local t = frame.add { type = "table", column_count = 4 }
|
||||
c = c .. ")"
|
||||
end
|
||||
local t = frame.add { type = "table", column_count = 4 }
|
||||
for _, p in pairs(game.forces[gui_value.force].connected_players) do
|
||||
local l = t.add({type = "label", caption = p.name})
|
||||
l.style.font_color = {r = p.color.r * 0.6 + 0.4, g = p.color.g * 0.6 + 0.4, b = p.color.b * 0.6 + 0.4, a = 1}
|
||||
l.style.font = "heading-2"
|
||||
end
|
||||
end
|
||||
local b = frame.add { type = "sprite-button", name = gui_value.n1, caption = c }
|
||||
b.style.font = "default-large-bold"
|
||||
b.style.font_color = font_color
|
||||
b.style.minimal_width = 350
|
||||
frame.add { type = "label", caption = "-----------------------------------------------------------"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function add_tech_button(elem, gui_value)
|
||||
local tech_button = elem.add {
|
||||
type = "sprite-button",
|
||||
name = gui_value.tech_spy,
|
||||
sprite = "item/space-science-pack"
|
||||
}
|
||||
tech_button.style.height = 25
|
||||
tech_button.style.width = 25
|
||||
end
|
||||
|
||||
local function add_prod_button(elem, gui_value)
|
||||
local prod_button = elem.add {
|
||||
type = "sprite-button",
|
||||
name = gui_value.prod_spy,
|
||||
sprite = "item/assembling-machine-3"
|
||||
}
|
||||
prod_button.style.height = 25
|
||||
prod_button.style.width = 25
|
||||
end
|
||||
|
||||
local function create_main_gui(player)
|
||||
local is_spec = player.force.name == "spectator"
|
||||
if player.gui.left["bb_main_gui"] then player.gui.left["bb_main_gui"].destroy() end
|
||||
|
||||
|
||||
if global.bb_game_won_by_team then return end
|
||||
if not global.chosen_team[player.name] then
|
||||
if not global.tournament_mode then
|
||||
create_first_join_gui(player)
|
||||
create_first_join_gui(player)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local frame = player.gui.left.add { type = "frame", name = "bb_main_gui", direction = "vertical" }
|
||||
|
||||
if player.force.name ~= "spectator" then
|
||||
-- Science sending GUI
|
||||
if not is_spec then
|
||||
frame.add { type = "table", name = "biter_battle_table", column_count = 4 }
|
||||
local t = frame.biter_battle_table
|
||||
local foods = {"automation-science-pack","logistic-science-pack","military-science-pack","chemical-science-pack","production-science-pack","utility-science-pack","space-science-pack","raw-fish"}
|
||||
@ -121,10 +147,21 @@ local function create_main_gui(player)
|
||||
s.style.bottom_padding = 0
|
||||
x = x + 1
|
||||
end
|
||||
end
|
||||
|
||||
for _, gui_value in pairs(gui_values) do
|
||||
end
|
||||
|
||||
local first_team = true
|
||||
for _, gui_value in pairs(gui_values) do
|
||||
-- Line separator
|
||||
if not first_team then
|
||||
frame.add { type = "line", caption = "this line", direction = "horizontal" }
|
||||
else
|
||||
first_team = false
|
||||
end
|
||||
|
||||
-- Team name & Player count
|
||||
local t = frame.add { type = "table", column_count = 3 }
|
||||
|
||||
-- Team name
|
||||
local c = gui_value.c1
|
||||
if global.tm_custom_name[gui_value.force] then c = global.tm_custom_name[gui_value.force] end
|
||||
local l = t.add { type = "label", caption = c}
|
||||
@ -133,23 +170,28 @@ local function create_main_gui(player)
|
||||
l.style.single_line = false
|
||||
--l.style.minimal_width = 100
|
||||
l.style.maximal_width = 102
|
||||
|
||||
|
||||
-- Number of players
|
||||
local l = t.add { type = "label", caption = " - "}
|
||||
local c = #game.forces[gui_value.force].connected_players .. " Player"
|
||||
if #game.forces[gui_value.force].connected_players ~= 1 then c = c .. "s" end
|
||||
local l = t.add { type = "label", caption = c}
|
||||
l.style.font = "default"
|
||||
l.style.font_color = { r=0.22, g=0.88, b=0.22}
|
||||
|
||||
if global.bb_view_players[player.name] == true then
|
||||
local t = frame.add { type = "table", column_count = 4 }
|
||||
l.style.font_color = { r=0.22, g=0.88, b=0.22}
|
||||
|
||||
-- Player list
|
||||
if global.bb_view_players[player.name] == true then
|
||||
local t = frame.add { type = "table", column_count = 4 }
|
||||
for _, p in pairs(game.forces[gui_value.force].connected_players) do
|
||||
local l = t.add { type = "label", caption = p.name }
|
||||
l.style.font_color = {r = p.color.r * 0.6 + 0.4, g = p.color.g * 0.6 + 0.4, b = p.color.b * 0.6 + 0.4, a = 1}
|
||||
end
|
||||
end
|
||||
|
||||
local t = frame.add { type = "table", name = "stats_" .. gui_value.force, column_count = 4 }
|
||||
-- Statistics
|
||||
local t = frame.add { type = "table", name = "stats_" .. gui_value.force, column_count = 6 }
|
||||
|
||||
-- Evolution
|
||||
local l = t.add { type = "label", caption = "Evo:"}
|
||||
--l.style.minimal_width = 25
|
||||
l.tooltip = gui_value.t1
|
||||
@ -159,31 +201,44 @@ local function create_main_gui(player)
|
||||
l.style.font_color = gui_value.color2
|
||||
l.style.font = "default-bold"
|
||||
l.tooltip = gui_value.t1
|
||||
|
||||
|
||||
-- Threat
|
||||
local l = t.add {type = "label", caption = "Threat: "}
|
||||
l.style.minimal_width = 25
|
||||
l.tooltip = gui_value.t2
|
||||
local l = t.add {type = "label", name = "threat_" .. gui_value.force, caption = math.floor(global.bb_threat[gui_value.biter_force])}
|
||||
local l = t.add {type = "label", name = "threat_" .. gui_value.force, caption = math.floor(global.bb_threat[gui_value.biter_force])}
|
||||
l.style.font_color = gui_value.color2
|
||||
l.style.font = "default-bold"
|
||||
l.style.minimal_width = 25
|
||||
l.style.width = 50
|
||||
l.tooltip = gui_value.t2
|
||||
|
||||
frame.add { type = "label", caption = string.rep("-", 29)}
|
||||
|
||||
-- Tech button
|
||||
if is_spec then
|
||||
add_tech_button(t, gui_value)
|
||||
-- add_prod_button(t, gui_value)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Action frame
|
||||
local t = frame.add { type = "table", column_count = 2 }
|
||||
if player.force.name == "spectator" then
|
||||
|
||||
-- Spectate / Rejoin team
|
||||
if is_spec then
|
||||
local b = t.add { type = "sprite-button", name = "bb_leave_spectate", caption = "Join Team" }
|
||||
else
|
||||
local b = t.add { type = "sprite-button", name = "bb_spectate", caption = "Spectate" }
|
||||
end
|
||||
|
||||
|
||||
-- Playerlist button
|
||||
if global.bb_view_players[player.name] == true then
|
||||
local b = t.add { type = "sprite-button", name = "bb_hide_players", caption = "Playerlist" }
|
||||
else
|
||||
local b = t.add { type = "sprite-button", name = "bb_view_players", caption = "Playerlist" }
|
||||
end
|
||||
local b = t.add { type = "sprite-button", name = "bb_view_players", caption = "Playerlist" }
|
||||
end
|
||||
|
||||
|
||||
local b_width = is_spec and 97 or 86
|
||||
-- 111 when prod_spy button will be there
|
||||
for _, b in pairs(t.children) do
|
||||
b.style.font = "default-bold"
|
||||
b.style.font_color = { r=0.98, g=0.66, b=0.22}
|
||||
@ -192,14 +247,14 @@ local function create_main_gui(player)
|
||||
b.style.right_padding = 1
|
||||
b.style.bottom_padding = 1
|
||||
b.style.maximal_height = 30
|
||||
b.style.minimal_width = 86
|
||||
b.style.width = b_width
|
||||
end
|
||||
end
|
||||
|
||||
local function refresh_gui()
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.gui.left["bb_main_gui"] then
|
||||
create_main_gui(player)
|
||||
create_main_gui(player)
|
||||
end
|
||||
end
|
||||
global.gui_refresh_delay = game.tick + 5
|
||||
@ -221,14 +276,14 @@ end
|
||||
function join_team(player, force_name, forced_join)
|
||||
if not player.character then return end
|
||||
if not forced_join then
|
||||
if global.tournament_mode then player.print("The game is set to tournament mode. Teams can only be changed via team manager.", {r = 0.98, g = 0.66, b = 0.22}) return end
|
||||
if global.tournament_mode then player.print("The game is set to tournament mode. Teams can only be changed via team manager.", {r = 0.98, g = 0.66, b = 0.22}) return end
|
||||
end
|
||||
if not force_name then return end
|
||||
local surface = player.surface
|
||||
|
||||
|
||||
local enemy_team = "south"
|
||||
if force_name == "south" then enemy_team = "north" end
|
||||
|
||||
|
||||
if not global.training_mode and bb_config.team_balancing then
|
||||
if not forced_join then
|
||||
if #game.forces[force_name].connected_players > #game.forces[enemy_team].connected_players then
|
||||
@ -239,7 +294,7 @@ function join_team(player, force_name, forced_join)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if global.chosen_team[player.name] then
|
||||
if not forced_join then
|
||||
if game.tick - global.spectator_rejoin_delay[player.name] < 3600 then
|
||||
@ -251,7 +306,7 @@ function join_team(player, force_name, forced_join)
|
||||
end
|
||||
end
|
||||
local p = surface.find_non_colliding_position("character", game.forces[force_name].get_spawn_position(surface), 8, 0.5)
|
||||
player.teleport(p, surface)
|
||||
player.teleport(p, surface)
|
||||
player.force = game.forces[force_name]
|
||||
player.character.destructible = true
|
||||
refresh_gui()
|
||||
@ -275,7 +330,7 @@ function join_team(player, force_name, forced_join)
|
||||
i.clear()
|
||||
player.insert {name = 'pistol', count = 1}
|
||||
player.insert {name = 'raw-fish', count = 3}
|
||||
player.insert {name = 'firearm-magazine', count = 32}
|
||||
player.insert {name = 'firearm-magazine', count = 32}
|
||||
player.insert {name = 'iron-gear-wheel', count = 8}
|
||||
player.insert {name = 'iron-plate', count = 16}
|
||||
global.chosen_team[player.name] = force_name
|
||||
@ -286,37 +341,37 @@ end
|
||||
function spectate(player, forced_join)
|
||||
if not player.character then return end
|
||||
if not forced_join then
|
||||
if global.tournament_mode then player.print("The game is set to tournament mode. Teams can only be changed via team manager.", {r = 0.98, g = 0.66, b = 0.22}) return end
|
||||
if global.tournament_mode then player.print("The game is set to tournament mode. Teams can only be changed via team manager.", {r = 0.98, g = 0.66, b = 0.22}) return end
|
||||
end
|
||||
player.teleport(player.surface.find_non_colliding_position("character", {0,0}, 4, 1))
|
||||
player.teleport(player.surface.find_non_colliding_position("character", {0,0}, 4, 1))
|
||||
player.force = game.forces.spectator
|
||||
player.character.destructible = false
|
||||
if not forced_join then
|
||||
game.print(player.name .. " is spectating.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
end
|
||||
game.permissions.get_group("spectator").add_player(player)
|
||||
end
|
||||
game.permissions.get_group("spectator").add_player(player)
|
||||
global.spectator_rejoin_delay[player.name] = game.tick
|
||||
create_main_gui(player)
|
||||
player.spectator = true
|
||||
end
|
||||
|
||||
local function join_gui_click(name, player)
|
||||
local function join_gui_click(name, player)
|
||||
local team = {
|
||||
["join_north_button"] = "north",
|
||||
["join_south_button"] = "south"
|
||||
}
|
||||
|
||||
if not team[name] then return end
|
||||
|
||||
|
||||
-- JOIN PREVENTION IF MAP IS STILL GENERATING
|
||||
if not global.map_generation_complete then
|
||||
if not global.map_pregen_message_counter[player.name] then global.map_pregen_message_counter[player.name] = 1 end
|
||||
player.print(map_gen_messages[global.map_pregen_message_counter[player.name]], {r = 0.98, g = 0.66, b = 0.22})
|
||||
global.map_pregen_message_counter[player.name] = global.map_pregen_message_counter[player.name] + 1
|
||||
if global.map_pregen_message_counter[player.name] > #map_gen_messages then global.map_pregen_message_counter[player.name] = 1 end
|
||||
return
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if global.game_lobby_active then
|
||||
if player.admin then
|
||||
join_team(player, team[name])
|
||||
@ -324,7 +379,7 @@ local function join_gui_click(name, player)
|
||||
global.game_lobby_active = false
|
||||
return
|
||||
end
|
||||
player.print("Waiting for more players to join the game.", { r=0.98, g=0.66, b=0.22})
|
||||
player.print("Waiting for more players to join the game.", { r=0.98, g=0.66, b=0.22})
|
||||
return
|
||||
end
|
||||
join_team(player, team[name])
|
||||
@ -343,16 +398,16 @@ local function on_gui_click(event)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if name == "join_north_button" then join_gui_click(name, player) return end
|
||||
if name == "join_south_button" then join_gui_click(name, player) return end
|
||||
|
||||
|
||||
if name == "raw-fish" then spy_fish(player) return end
|
||||
|
||||
|
||||
if food_names[name] then feed_the_biters(player, name) return end
|
||||
|
||||
|
||||
if name == "bb_leave_spectate" then join_team(player, global.chosen_team[player.name]) end
|
||||
|
||||
|
||||
if name == "bb_spectate" then
|
||||
if player.position.y ^ 2 + player.position.x ^ 2 < 12000 then
|
||||
spectate(player)
|
||||
@ -367,25 +422,25 @@ local function on_gui_click(event)
|
||||
create_main_gui(player)
|
||||
end
|
||||
if name == "bb_view_players" then
|
||||
global.bb_view_players[player.name] = true
|
||||
global.bb_view_players[player.name] = true
|
||||
create_main_gui(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
|
||||
if not global.bb_view_players then global.bb_view_players = {} end
|
||||
if not global.chosen_team then global.chosen_team = {} end
|
||||
|
||||
|
||||
global.bb_view_players[player.name] = false
|
||||
|
||||
|
||||
if #game.connected_players > 1 then
|
||||
global.game_lobby_timeout = math.ceil(36000 / #game.connected_players)
|
||||
else
|
||||
global.game_lobby_timeout = 599940
|
||||
end
|
||||
|
||||
|
||||
--if not global.chosen_team[player.name] then
|
||||
-- if global.tournament_mode then
|
||||
-- player.force = game.forces.spectator
|
||||
@ -393,7 +448,7 @@ local function on_player_joined_game(event)
|
||||
-- player.force = game.forces.player
|
||||
-- end
|
||||
--end
|
||||
|
||||
|
||||
create_sprite_button(player)
|
||||
create_main_gui(player)
|
||||
end
|
||||
@ -401,4 +456,4 @@ end
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
|
||||
return refresh_gui
|
||||
return refresh_gui
|
||||
|
@ -3,17 +3,17 @@
|
||||
require 'utils.table'
|
||||
require "on_tick_schedule"
|
||||
require "maps.biter_battles_v2.config"
|
||||
require "modules.spawners_contain_biters"
|
||||
require "modules.spawners_contain_biters"
|
||||
require "modules.mineable_wreckage_yields_scrap"
|
||||
|
||||
local event = require 'utils.event'
|
||||
|
||||
local function init_surface()
|
||||
local function init_surface()
|
||||
local map_gen_settings = {}
|
||||
map_gen_settings.water = math.random(30, 40) * 0.01
|
||||
map_gen_settings.starting_area = 2.5
|
||||
map_gen_settings.terrain_segmentation = math.random(30, 40) * 0.1
|
||||
map_gen_settings.cliff_settings = {cliff_elevation_interval = math.random(16, 48), cliff_elevation_0 = math.random(16, 48)}
|
||||
map_gen_settings.terrain_segmentation = math.random(30, 40) * 0.1
|
||||
map_gen_settings.cliff_settings = {cliff_elevation_interval = math.random(16, 48), cliff_elevation_0 = math.random(16, 48)}
|
||||
map_gen_settings.autoplace_controls = {
|
||||
["coal"] = {frequency = math.random(10, 30) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(5, 15) * 0.1},
|
||||
["stone"] = {frequency = math.random(10, 30) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(5, 15) * 0.1},
|
||||
@ -22,15 +22,15 @@ local function init_surface()
|
||||
["uranium-ore"] = {frequency = math.random(10, 20) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(5, 15) * 0.1},
|
||||
["crude-oil"] = {frequency = math.random(15, 30) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(10, 20) * 0.1},
|
||||
["trees"] = {frequency = math.random(5, 25) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(3, 10) * 0.1},
|
||||
["enemy-base"] = {frequency = 256, size = 0.61, richness = 1}
|
||||
["enemy-base"] = {frequency = 256, size = 0.61, richness = 1}
|
||||
}
|
||||
game.create_surface("biter_battles", map_gen_settings)
|
||||
|
||||
|
||||
game.map_settings.enemy_evolution.time_factor = 0
|
||||
game.map_settings.enemy_evolution.destroy_factor = 0
|
||||
game.map_settings.enemy_evolution.pollution_factor = 0
|
||||
game.map_settings.pollution.enabled = false
|
||||
|
||||
|
||||
game.map_settings.enemy_expansion.enabled = true
|
||||
game.map_settings.enemy_expansion.settler_group_min_size = 8
|
||||
game.map_settings.enemy_expansion.settler_group_max_size = 16
|
||||
@ -40,27 +40,27 @@ end
|
||||
|
||||
local function init_forces()
|
||||
local surface = game.surfaces["biter_battles"]
|
||||
|
||||
|
||||
game.create_force("north")
|
||||
game.create_force("north_biters")
|
||||
game.create_force("south")
|
||||
game.create_force("south_biters")
|
||||
game.create_force("south_biters")
|
||||
game.create_force("spectator")
|
||||
|
||||
|
||||
local f = game.forces["north"]
|
||||
f.set_spawn_position({0, -32}, surface)
|
||||
f.set_cease_fire('player', true)
|
||||
f.set_friend("spectator", true)
|
||||
f.set_friend("south_biters", true)
|
||||
f.share_chart = true
|
||||
|
||||
|
||||
local f = game.forces["south"]
|
||||
f.set_spawn_position({0, 32}, surface)
|
||||
f.set_cease_fire('player', true)
|
||||
f.set_friend("spectator", true)
|
||||
f.set_friend("north_biters", true)
|
||||
f.share_chart = true
|
||||
|
||||
|
||||
local f = game.forces["north_biters"]
|
||||
f.set_friend("south_biters", true)
|
||||
f.set_friend("south", true)
|
||||
@ -68,7 +68,7 @@ local function init_forces()
|
||||
--f.set_friend("enemy", true)
|
||||
f.set_friend("spectator", true)
|
||||
f.share_chart = false
|
||||
|
||||
|
||||
local f = game.forces["south_biters"]
|
||||
f.set_friend("north_biters", true)
|
||||
f.set_friend("north", true)
|
||||
@ -76,23 +76,23 @@ local function init_forces()
|
||||
--f.set_friend("enemy", true)
|
||||
f.set_friend("spectator", true)
|
||||
f.share_chart = false
|
||||
|
||||
|
||||
--local f = game.forces["enemy"]
|
||||
--f.set_friend("spectator", true)
|
||||
--f.set_friend("player", true)
|
||||
--f.set_friend("north_biters", true)
|
||||
--f.set_friend("south_biters", true)
|
||||
|
||||
|
||||
local f = game.forces["spectator"]
|
||||
f.set_spawn_position({0,0},surface)
|
||||
f.technologies["toolbelt"].researched=true
|
||||
f.technologies["toolbelt"].researched=true
|
||||
f.set_cease_fire("north_biters", true)
|
||||
f.set_cease_fire("south_biters", true)
|
||||
f.set_friend("north", true)
|
||||
f.set_friend("south", true)
|
||||
f.set_cease_fire("player", true)
|
||||
f.share_chart = true
|
||||
|
||||
|
||||
local f = game.forces["player"]
|
||||
f.set_spawn_position({0,0},surface)
|
||||
f.set_cease_fire('spectator', true)
|
||||
@ -101,20 +101,20 @@ local function init_forces()
|
||||
f.set_cease_fire('north', true)
|
||||
f.set_cease_fire('south', true)
|
||||
f.share_chart = false
|
||||
|
||||
if not bb_config.blueprint_library_importing then
|
||||
|
||||
if not bb_config.blueprint_library_importing then
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.grab_blueprint_record, false)
|
||||
end
|
||||
if not bb_config.blueprint_string_importing then
|
||||
if not bb_config.blueprint_string_importing then
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint_string, false)
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint, false)
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint, false)
|
||||
end
|
||||
|
||||
|
||||
local p = game.permissions.create_group("spectator")
|
||||
for action_name, _ in pairs(defines.input_action) do
|
||||
p.set_allows_action(defines.input_action[action_name], false)
|
||||
end
|
||||
|
||||
|
||||
local defs = {
|
||||
defines.input_action.write_to_console,
|
||||
defines.input_action.gui_click,
|
||||
@ -129,10 +129,9 @@ local function init_forces()
|
||||
defines.input_action.edit_permission_group,
|
||||
defines.input_action.toggle_show_entity_info,
|
||||
defines.input_action.rotate_entity,
|
||||
defines.input_action.start_research
|
||||
}
|
||||
}
|
||||
for _, d in pairs(defs) do p.set_allows_action(d, true) end
|
||||
|
||||
|
||||
global.rocket_silo = {}
|
||||
global.spectator_rejoin_delay = {}
|
||||
global.spy_fish_timeout = {}
|
||||
@ -148,12 +147,12 @@ local function init_forces()
|
||||
global.bb_threat = {}
|
||||
global.chunks_to_mirror = {}
|
||||
global.map_pregen_message_counter = {}
|
||||
|
||||
|
||||
for _, force in pairs(game.forces) do
|
||||
game.forces[force.name].technologies["artillery"].enabled = false
|
||||
game.forces[force.name].technologies["artillery-shell-range-1"].enabled = false
|
||||
game.forces[force.name].technologies["artillery-shell-speed-1"].enabled = false
|
||||
game.forces[force.name].technologies["atomic-bomb"].enabled = false
|
||||
game.forces[force.name].technologies["artillery-shell-range-1"].enabled = false
|
||||
game.forces[force.name].technologies["artillery-shell-speed-1"].enabled = false
|
||||
game.forces[force.name].technologies["atomic-bomb"].enabled = false
|
||||
game.forces[force.name].set_ammo_damage_modifier("shotgun-shell", 1)
|
||||
game.forces[force.name].research_queue_enabled = true
|
||||
global.spy_fish_timeout[force.name] = 0
|
||||
@ -162,17 +161,17 @@ local function init_forces()
|
||||
global.bb_evolution[force.name] = 0
|
||||
global.bb_evasion[force.name] = false
|
||||
global.bb_threat_income[force.name] = 0
|
||||
global.bb_threat[force.name] = 0
|
||||
global.bb_threat[force.name] = 0
|
||||
end
|
||||
global.game_lobby_active = true
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local function on_player_joined_game(event)
|
||||
local surface = game.surfaces["biter_battles"]
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
|
||||
|
||||
|
||||
if player.online_time == 0 then
|
||||
player.spectator = true
|
||||
player.force = game.forces.spectator
|
||||
@ -183,7 +182,7 @@ local function on_player_joined_game(event)
|
||||
end
|
||||
player.character.destructible = false
|
||||
game.permissions.get_group("spectator").add_player(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init(surface)
|
||||
@ -196,6 +195,7 @@ end
|
||||
event.on_init(on_init)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
|
||||
require "maps.biter_battles_v2.spec_spy"
|
||||
require "maps.biter_battles_v2.on_tick"
|
||||
require "maps.biter_battles_v2.terrain"
|
||||
require "maps.biter_battles_v2.biters_landfill"
|
||||
@ -204,4 +204,4 @@ require "maps.biter_battles_v2.chat"
|
||||
require "maps.biter_battles_v2.bb_map_intro"
|
||||
require "maps.biter_battles_v2.difficulty_vote"
|
||||
require "maps.biter_battles_v2.team_manager"
|
||||
require "modules.custom_death_messages"
|
||||
require "modules.custom_death_messages"
|
||||
|
103
maps/biter_battles_v2/spec_spy.lua
Executable file
103
maps/biter_battles_v2/spec_spy.lua
Executable file
@ -0,0 +1,103 @@
|
||||
local Global = require "utils.global"
|
||||
|
||||
local this = {
|
||||
-- map player <> force
|
||||
initialForce = {}
|
||||
}
|
||||
|
||||
Global.register(this, function (t) this = t end)
|
||||
|
||||
local function is_spying(player)
|
||||
return this.initialForce[player.index] ~= nil
|
||||
end
|
||||
|
||||
local function switch_force(player, force)
|
||||
this.initialForce[player.index] = player.force
|
||||
player.force = force
|
||||
end
|
||||
|
||||
local function spy_production(player, force)
|
||||
if is_spying(player) then
|
||||
return
|
||||
end
|
||||
switch_force(player, force)
|
||||
player.opened = defines.gui_type.production
|
||||
end
|
||||
|
||||
local function spy_tech_tree(player, force)
|
||||
if is_spying(player) then
|
||||
return
|
||||
end
|
||||
switch_force(player, force)
|
||||
player.open_technology_gui()
|
||||
end
|
||||
|
||||
local function restore_force(player)
|
||||
if not is_spying(player) then
|
||||
return
|
||||
end
|
||||
player.force = this.initialForce[player.index]
|
||||
this.initialForce[player.index] = nil
|
||||
end
|
||||
|
||||
-- When a player clicks on a spying prod LuaGuiElement
|
||||
local function spy_prod_handler(event)
|
||||
if not event.element.valid then
|
||||
return
|
||||
end
|
||||
local elementToForce = {
|
||||
["spy-north-prod"] = "north",
|
||||
["spy-south-prod"] = "south"
|
||||
}
|
||||
local force = elementToForce[event.element.name]
|
||||
if force then
|
||||
local player = game.players[event.player_index]
|
||||
spy_production(player, force)
|
||||
end
|
||||
end
|
||||
|
||||
-- When a player clicks on a spying tech LuaGuiElement
|
||||
local function spy_tech_handler(event)
|
||||
if not event.element.valid then
|
||||
return
|
||||
end
|
||||
local elementToForce = {
|
||||
["spy-north-tech"] = "north",
|
||||
["spy-south-tech"] = "south"
|
||||
}
|
||||
local force = elementToForce[event.element.name]
|
||||
if force then
|
||||
local player = game.players[event.player_index]
|
||||
spy_tech_tree(player, force)
|
||||
end
|
||||
end
|
||||
|
||||
-- When a player closes the prod view while spying
|
||||
local function close_prod_handler(event)
|
||||
if event.gui_type ~= defines.gui_type.production then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
-- If the player was spying
|
||||
if is_spying(player) then
|
||||
restore_force(player)
|
||||
end
|
||||
end
|
||||
|
||||
-- When a player closes the tech view while spying
|
||||
local function close_tech_handler(event)
|
||||
if event.gui_type ~= defines.gui_type.research then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
-- If the player was spying
|
||||
if is_spying(player) then
|
||||
restore_force(player)
|
||||
end
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.add(defines.events.on_gui_click, spy_prod_handler)
|
||||
Event.add(defines.events.on_gui_click, spy_tech_handler)
|
||||
Event.add(defines.events.on_gui_closed, close_prod_handler)
|
||||
Event.add(defines.events.on_gui_closed, close_tech_handler)
|
Loading…
x
Reference in New Issue
Block a user