From 69f122147a240521e34d0ed17206cfcc596dd16a Mon Sep 17 00:00:00 2001 From: muppet9010 <40836017+muppet9010@users.noreply.github.com> Date: Sun, 27 Oct 2019 15:06:30 +0000 Subject: [PATCH 1/5] Initial training mode to allow 1 or more players to train against their own biter feeding. Disabled South team from options and GUIs to avoid confusion. --- maps/biter_battles_v2/ai.lua | 8 ++++++-- maps/biter_battles_v2/config.lua | 1 + maps/biter_battles_v2/feeding.lua | 3 +++ maps/biter_battles_v2/gui.lua | 7 +++++-- maps/biter_battles_v2/main.lua | 2 +- maps/biter_battles_v2/team_manager.lua | 7 ++++++- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/maps/biter_battles_v2/ai.lua b/maps/biter_battles_v2/ai.lua index de65ea00..2f343d26 100644 --- a/maps/biter_battles_v2/ai.lua +++ b/maps/biter_battles_v2/ai.lua @@ -275,9 +275,13 @@ end ai.raise_evo = function() if global.freeze_players then return end - if #game.forces.north.connected_players == 0 or #game.forces.south.connected_players == 0 then return end + if #game.forces.north.connected_players == 0 or (not bb_config.training_mode and #game.forces.south.connected_players == 0) then return end local amount = math.ceil(global.difficulty_vote_value * global.evo_raise_counter) - for _, f in pairs({"north_biters", "south_biters"}) do + local biter_teams = {["north_biters"] = true, ["south_biters"] = true} + if bb_config.training_mode then + biter_teams["south_biters"] = nil + end + for f in pairs(biter_teams) do set_evo_and_threat(amount, "automation-science-pack", f) end global.evo_raise_counter = global.evo_raise_counter + (1 * 0.50) diff --git a/maps/biter_battles_v2/config.lua b/maps/biter_battles_v2/config.lua index de225ce8..cf1d4fda 100644 --- a/maps/biter_battles_v2/config.lua +++ b/maps/biter_battles_v2/config.lua @@ -4,6 +4,7 @@ bb_config = { --TEAM SETTINGS-- ["team_balancing"] = true, --Should players only be able to join a team that has less or equal members than the opposing team? ["only_admins_vote"] = false, --Are only admins able to vote on the global difficulty? + ['training_mode'] = true, --Players must join north team and all feeding affects their own biters. Southern team is disabled. Designed for 1 or more players to train aginst themselves. --Optional custom team names, can also be modified via "Team Manager" ["north_side_team_name"] = "Team North", diff --git a/maps/biter_battles_v2/feeding.lua b/maps/biter_battles_v2/feeding.lua index 9b392b6b..2e098214 100644 --- a/maps/biter_battles_v2/feeding.lua +++ b/maps/biter_battles_v2/feeding.lua @@ -17,6 +17,9 @@ local enemy_team_of = { ["north"] = "south", ["south"] = "north" } +if bb_config.training_mode then + enemy_team_of["north"] = "north" +end diff --git a/maps/biter_battles_v2/gui.lua b/maps/biter_battles_v2/gui.lua index 8c8aa9d5..586b8aff 100644 --- a/maps/biter_battles_v2/gui.lua +++ b/maps/biter_battles_v2/gui.lua @@ -19,7 +19,10 @@ local gui_values = { ["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}} - } +} +if bb_config.training_mode then + gui_values["south"] = nil +end local map_gen_messages = { "Map is still generating, please get comfy.", @@ -229,7 +232,7 @@ function join_team(player, force_name, forced_join) local enemy_team = "south" if force_name == "south" then enemy_team = "north" end - if bb_config.team_balancing then + if not bb_config.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 if not global.chosen_team[player.name] then diff --git a/maps/biter_battles_v2/main.lua b/maps/biter_battles_v2/main.lua index 99d45e64..66eb6dd2 100644 --- a/maps/biter_battles_v2/main.lua +++ b/maps/biter_battles_v2/main.lua @@ -164,7 +164,7 @@ local function init_forces() global.bb_threat_income[force.name] = 0 global.bb_threat[force.name] = 0 end - global.game_lobby_active = true + global.game_lobby_active = not bb_config.training_mode end local function on_player_joined_game(event) diff --git a/maps/biter_battles_v2/team_manager.lua b/maps/biter_battles_v2/team_manager.lua index 87e84dc3..5183325a 100644 --- a/maps/biter_battles_v2/team_manager.lua +++ b/maps/biter_battles_v2/team_manager.lua @@ -3,6 +3,9 @@ local forces = { {name = "spectator", color = {r = 111, g = 111, b = 111}}, {name = "south", color = {r = 200, g = 0, b = 0}}, } +if bb_config.training_mode then + forces[3] = nil +end local function get_player_array(force_name) local a = {} @@ -129,7 +132,8 @@ local function draw_manager_gui(player) local frame = player.gui.center.add({type = "frame", name = "team_manager_gui", caption = "Manage Teams", direction = "vertical"}) - local t = frame.add({type = "table", name = "team_manager_root_table", column_count = 5}) + local column_count = (#forces * 2) - 1 + local t = frame.add({type = "table", name = "team_manager_root_table", column_count = column_count}) local i2 = 1 for i = 1, #forces * 2 - 1, 1 do @@ -152,6 +156,7 @@ local function draw_manager_gui(player) list_box.style.minimal_height = 360 list_box.style.minimal_width = 160 list_box.style.maximal_height = 480 + list_box.style.maximal_width = 160 i2 = i2 + 1 else local tt = t.add({type = "table", column_count = 1}) From 94f94165984934516fa02f4fccf11adfd58214a3 Mon Sep 17 00:00:00 2001 From: muppet9010 <40836017+muppet9010@users.noreply.github.com> Date: Sun, 27 Oct 2019 15:16:11 +0000 Subject: [PATCH 2/5] return config to previous defaults & clarify comment on config option --- maps/biter_battles_v2/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maps/biter_battles_v2/config.lua b/maps/biter_battles_v2/config.lua index cf1d4fda..b341e56f 100644 --- a/maps/biter_battles_v2/config.lua +++ b/maps/biter_battles_v2/config.lua @@ -4,7 +4,7 @@ bb_config = { --TEAM SETTINGS-- ["team_balancing"] = true, --Should players only be able to join a team that has less or equal members than the opposing team? ["only_admins_vote"] = false, --Are only admins able to vote on the global difficulty? - ['training_mode'] = true, --Players must join north team and all feeding affects their own biters. Southern team is disabled. Designed for 1 or more players to train aginst themselves. + ['training_mode'] = false, --Designed for 1 or more players to train aginst themselves. Players must join north team and all feeding affects their own biters. Southern team is disabled. --Optional custom team names, can also be modified via "Team Manager" ["north_side_team_name"] = "Team North", From d5f92eb5bd5ecdd2a7d4a6cf6a93f4ff543c6bfa Mon Sep 17 00:00:00 2001 From: muppet9010 <40836017+muppet9010@users.noreply.github.com> Date: Sun, 3 Nov 2019 21:26:34 +0000 Subject: [PATCH 3/5] undo the GUI blocking of joining team south made previously in this pull and all affects of Training mode will affect both north and south. remove the ghost-spectate button from Team Manager and the functionaility it triggered added Training Mode button to Team manager to toggle on/off behaviour. When turned on: Teams will feed themselves instead of the enemy while enabled (messages updated for this). Empty teams will not get sent any attacking groups and won't get threat & evo increases (as it looks odd) Team balance and Lobby minimum player counts not active --- maps/biter_battles_v2/ai.lua | 33 ++++++------ maps/biter_battles_v2/config.lua | 1 - maps/biter_battles_v2/feeding.lua | 26 +++++++--- maps/biter_battles_v2/gui.lua | 5 +- maps/biter_battles_v2/main.lua | 2 +- maps/biter_battles_v2/team_manager.lua | 70 ++++++++++++-------------- 6 files changed, 71 insertions(+), 66 deletions(-) diff --git a/maps/biter_battles_v2/ai.lua b/maps/biter_battles_v2/ai.lua index 2f343d26..48d09364 100644 --- a/maps/biter_battles_v2/ai.lua +++ b/maps/biter_battles_v2/ai.lua @@ -256,15 +256,18 @@ end ai.main_attack = function() local surface = game.surfaces["biter_battles"] local force_name = global.next_attack - local biter_force_name = force_name .. "_biters" - local wave_amount = math.ceil(get_threat_ratio(biter_force_name) * 7) - set_biter_raffle_table(surface, biter_force_name) - - for c = 1, wave_amount, 1 do - create_attack_group(surface, force_name, biter_force_name) + if not global.training_mode or (global.training_mode and #game.forces[force_name].connected_players > 0) then + local biter_force_name = force_name .. "_biters" + local wave_amount = math.ceil(get_threat_ratio(biter_force_name) * 7) + + set_biter_raffle_table(surface, biter_force_name) + + for c = 1, wave_amount, 1 do + create_attack_group(surface, force_name, biter_force_name) + end + if global.bb_debug then game.print(wave_amount .. " unit groups designated for " .. force_name .. " biters.") end end - if global.bb_debug then game.print(wave_amount .. " unit groups designated for " .. force_name .. " biters.") end if global.next_attack == "north" then global.next_attack = "south" @@ -275,15 +278,17 @@ end ai.raise_evo = function() if global.freeze_players then return end - if #game.forces.north.connected_players == 0 or (not bb_config.training_mode and #game.forces.south.connected_players == 0) then return end + if not global.training_mode and (#game.forces.north.connected_players == 0 or #game.forces.south.connected_players == 0) then return end local amount = math.ceil(global.difficulty_vote_value * global.evo_raise_counter) - local biter_teams = {["north_biters"] = true, ["south_biters"] = true} - if bb_config.training_mode then - biter_teams["south_biters"] = nil - end - for f in pairs(biter_teams) do - set_evo_and_threat(amount, "automation-science-pack", f) + local biter_teams = {["north_biters"] = "north", ["south_biters"] = "south"} + local a_team_has_players = false + for bf, pf in pairs(biter_teams) do + if #game.forces[pf].connected_players > 0 then + set_evo_and_threat(amount, "automation-science-pack", bf) + a_team_has_players = true + end end + if not a_team_has_players then return end global.evo_raise_counter = global.evo_raise_counter + (1 * 0.50) end diff --git a/maps/biter_battles_v2/config.lua b/maps/biter_battles_v2/config.lua index b341e56f..de225ce8 100644 --- a/maps/biter_battles_v2/config.lua +++ b/maps/biter_battles_v2/config.lua @@ -4,7 +4,6 @@ bb_config = { --TEAM SETTINGS-- ["team_balancing"] = true, --Should players only be able to join a team that has less or equal members than the opposing team? ["only_admins_vote"] = false, --Are only admins able to vote on the global difficulty? - ['training_mode'] = false, --Designed for 1 or more players to train aginst themselves. Players must join north team and all feeding affects their own biters. Southern team is disabled. --Optional custom team names, can also be modified via "Team Manager" ["north_side_team_name"] = "Team North", diff --git a/maps/biter_battles_v2/feeding.lua b/maps/biter_battles_v2/feeding.lua index 2e098214..3fc1086a 100644 --- a/maps/biter_battles_v2/feeding.lua +++ b/maps/biter_battles_v2/feeding.lua @@ -17,9 +17,7 @@ local enemy_team_of = { ["north"] = "south", ["south"] = "north" } -if bb_config.training_mode then - enemy_team_of["north"] = "north" -end + @@ -49,8 +47,16 @@ local function set_biter_endgame_modifiers(force) global.bb_evasion[force.name] = evasion_mod end +local function get_enemy_team_of(team) + if global.training_mode then + return team + else + return enemy_team_of[team] + end +end + local function print_feeding_msg(player, food, flask_amount) - if not enemy_team_of[player.force.name] then return end + if not get_enemy_team_of(player.force.name) then return end local n = bb_config.north_side_team_name local s = bb_config.south_side_team_name @@ -66,12 +72,16 @@ local function print_feeding_msg(player, food, flask_amount) local formatted_amount = table.concat({"[font=heading-1][color=255,255,255]" .. flask_amount .. "[/color][/font]"}) if flask_amount >= 20 then - game.print(colored_player_name .. " fed " .. formatted_amount .. " flasks of " .. formatted_food .. " to team " .. team_strings[enemy_team_of[player.force.name]] .. " biters!", {r = 0.9, g = 0.9, b = 0.9}) + game.print(colored_player_name .. " fed " .. formatted_amount .. " flasks of " .. formatted_food .. " to team " .. team_strings[get_enemy_team_of(player.force.name)] .. " biters!", {r = 0.9, g = 0.9, b = 0.9}) else + local target_team_text = "the enemy" + if global.training_mode then + target_team_text = "your own" + end if flask_amount == 1 then - player.print("You fed one flask of " .. formatted_food .. " to the enemy team's biters.", {r = 0.98, g = 0.66, b = 0.22}) + player.print("You fed one flask of " .. formatted_food .. " to " .. target_team_text .. " team's biters.", {r = 0.98, g = 0.66, b = 0.22}) else - player.print("You fed " .. formatted_amount .. " flasks of " .. formatted_food .. " to the enemy team's biters.", {r = 0.98, g = 0.66, b = 0.22}) + player.print("You fed " .. formatted_amount .. " flasks of " .. formatted_food .. " to " .. target_team_text .. " team's biters.", {r = 0.98, g = 0.66, b = 0.22}) end end end @@ -113,7 +123,7 @@ function set_evo_and_threat(flask_amount, food, biter_force_name) end local function feed_biters(player, food) - local enemy_force_name = enemy_team_of[player.force.name] --------------- + local enemy_force_name = get_enemy_team_of(player.force.name) --------------- --enemy_force_name = player.force.name local biter_force_name = enemy_force_name .. "_biters" diff --git a/maps/biter_battles_v2/gui.lua b/maps/biter_battles_v2/gui.lua index 586b8aff..d4d53f48 100644 --- a/maps/biter_battles_v2/gui.lua +++ b/maps/biter_battles_v2/gui.lua @@ -20,9 +20,6 @@ local gui_values = { 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}} } -if bb_config.training_mode then - gui_values["south"] = nil -end local map_gen_messages = { "Map is still generating, please get comfy.", @@ -232,7 +229,7 @@ function join_team(player, force_name, forced_join) local enemy_team = "south" if force_name == "south" then enemy_team = "north" end - if not bb_config.training_mode and bb_config.team_balancing then + 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 if not global.chosen_team[player.name] then diff --git a/maps/biter_battles_v2/main.lua b/maps/biter_battles_v2/main.lua index 66eb6dd2..99d45e64 100644 --- a/maps/biter_battles_v2/main.lua +++ b/maps/biter_battles_v2/main.lua @@ -164,7 +164,7 @@ local function init_forces() global.bb_threat_income[force.name] = 0 global.bb_threat[force.name] = 0 end - global.game_lobby_active = not bb_config.training_mode + global.game_lobby_active = true end local function on_player_joined_game(event) diff --git a/maps/biter_battles_v2/team_manager.lua b/maps/biter_battles_v2/team_manager.lua index 5183325a..2575b1ef 100644 --- a/maps/biter_battles_v2/team_manager.lua +++ b/maps/biter_battles_v2/team_manager.lua @@ -3,9 +3,6 @@ local forces = { {name = "spectator", color = {r = 111, g = 111, b = 111}}, {name = "south", color = {r = 200, g = 0, b = 0}}, } -if bb_config.training_mode then - forces[3] = nil -end local function get_player_array(force_name) local a = {} @@ -43,27 +40,6 @@ local function unfreeze_players() end end -local function toggle_ghost_spectate(player) - if player.character then - player.character.destroy() - player.character = nil - player.set_controller({type=defines.controllers.spectator}) - game.print(player.name .. " has turned into a spectator ghost.") - else - local spawn = player.force.get_spawn_position(player.surface) - player.character = nil - player.set_controller({type=defines.controllers.god}) - local pos = player.surface.find_non_colliding_position("character", spawn, 3, 0.5) - if pos then - player.teleport(pos, player.surface) - else - player.teleport(spawn, player.surface) - end - player.create_character() - game.print(player.name .. " has stopped being a spectator ghost.") - end -end - local function leave_corpse(player) if not player.character then return end @@ -131,9 +107,8 @@ local function draw_manager_gui(player) if player.gui.center["team_manager_gui"] then player.gui.center["team_manager_gui"].destroy() end local frame = player.gui.center.add({type = "frame", name = "team_manager_gui", caption = "Manage Teams", direction = "vertical"}) - - local column_count = (#forces * 2) - 1 - local t = frame.add({type = "table", name = "team_manager_root_table", column_count = column_count}) + + local t = frame.add({type = "table", name = "team_manager_root_table", column_count = 5}) local i2 = 1 for i = 1, #forces * 2 - 1, 1 do @@ -156,7 +131,6 @@ local function draw_manager_gui(player) list_box.style.minimal_height = 360 list_box.style.minimal_width = 160 list_box.style.maximal_height = 480 - list_box.style.maximal_width = 160 i2 = i2 + 1 else local tt = t.add({type = "table", column_count = 1}) @@ -220,13 +194,23 @@ local function draw_manager_gui(player) end button.style.font = "heading-2" - button = t.add({ - type = "button", - name = "team_manager_turn_ghost", - caption = "Ghost-Spectate", - tooltip = "Turn yourself into a spooky spectator ghost." - }) - button.style.font_color = {r = 88, g = 88, b = 88} + if global.training_mode then + button = t.add({ + type = "button", + name = "team_manager_activate_training", + caption = "Training Mode Activated", + tooltip = "Feed your own team's biters and only teams with players gain threat & evo." + }) + button.style.font_color = {r = 222, g = 22, b = 22} + else + button = t.add({ + type = "button", + name = "team_manager_activate_training", + caption = "Training Mode Disabled", + tooltip = "Feed your own team's biters and only teams with players gain threat & evo." + }) + button.style.font_color = {r = 55, g = 55, b = 55} + end button.style.font = "heading-2" end @@ -308,9 +292,19 @@ local function team_manager_gui_click(event) return end - if name == "team_manager_turn_ghost" then - if not player.admin then player.print("Only admins can become spooky spectator ghosts.", {r = 175, g = 0, b = 0}) return end - toggle_ghost_spectate(player) + if name == "team_manager_activate_training" then + if not player.admin then player.print("Only admins can switch training mode.", {r = 175, g = 0, b = 0}) return end + if global.training_mode then + global.training_mode = false + global.game_lobby_active = true + draw_manager_gui(player) + game.print(">>> Training Mode has been disabled.", {r = 111, g = 111, b = 111}) + return + end + global.training_mode = true + global.game_lobby_active = false + draw_manager_gui(player) + game.print(">>> Training Mode has been enabled!", {r = 225, g = 0, b = 0}) return end From 486f9958721b9a5bd1ef6df2711c5fe58f581937 Mon Sep 17 00:00:00 2001 From: MewMew Date: Mon, 4 Nov 2019 19:57:02 +0100 Subject: [PATCH 4/5] added highscores --- maps/biter_hatchery/main.lua | 16 +++++-- modules/map_score.lua | 92 ++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 modules/map_score.lua diff --git a/maps/biter_hatchery/main.lua b/maps/biter_hatchery/main.lua index 77ea2819..dfa69b6c 100644 --- a/maps/biter_hatchery/main.lua +++ b/maps/biter_hatchery/main.lua @@ -1,5 +1,7 @@ require "modules.no_turrets" local RPG = require "modules.rpg" +local Tabs = require 'comfy_panel.main' +local Map_score = require "modules.map_score" local unit_raffle = require "maps.biter_hatchery.raffle_tables" local map_functions = require "tools.map_functions" local Terrain = require "maps.biter_hatchery.terrain" @@ -238,27 +240,30 @@ local function on_entity_died(event) if global.game_reset_tick then return end if event.entity.type ~= "unit-spawner" then return end - local gui_str + local str if event.entity.force.name == "east" then game.print("East lost their Hatchery.", {100, 100, 100}) - gui_str = ">>>> West team has won the game!!! <<<<" + str = ">>>> West team has won the game!!! <<<<" for _, player in pairs(game.forces.east.connected_players) do player.play_sound{path="utility/game_lost", volume_modifier=0.85} end for _, player in pairs(game.forces.west.connected_players) do - player.play_sound{path="utility/game_won", volume_modifier=0.85} + player.play_sound{path="utility/game_won", volume_modifier=0.85} + Map_score.set_score(player, Map_score.get_score(player) + 1) end else game.print("West lost their Hatchery.", {100, 100, 100}) - gui_str = ">>>> East team has won the game!!! <<<<" + str = ">>>> East team has won the game!!! <<<<" for _, player in pairs(game.forces.west.connected_players) do player.play_sound{path="utility/game_lost", volume_modifier=0.85} end for _, player in pairs(game.forces.east.connected_players) do player.play_sound{path="utility/game_won", volume_modifier=0.85} + Map_score.set_score(player, Map_score.get_score(player) + 1) end end + game.print(string.upper(str), {250, 120, 0}) game.print("Next round starting in 30 seconds..", {150, 150, 150}) for _, player in pairs(game.forces.spectator.connected_players) do @@ -268,7 +273,8 @@ local function on_entity_died(event) for _, player in pairs(game.connected_players) do for _, child in pairs(player.gui.left.children) do child.destroy() end - player.gui.left.add({type = "frame", name = "biter_hatchery_game_won", caption = gui_str}) + Tabs.comfy_panel_call_tab(player, "Map Scores") + --player.gui.left.add({type = "frame", name = "biter_hatchery_game_won", caption = str}) end end diff --git a/modules/map_score.lua b/modules/map_score.lua new file mode 100644 index 00000000..44c10192 --- /dev/null +++ b/modules/map_score.lua @@ -0,0 +1,92 @@ +local Public = {} + +local function get_sorted_score() + local list = {} + for player_index, score_points in pairs(global.custom_highscore.score_list) do + table.insert(list, {name = game.players[player_index].name, points = score_points}) + end + local list_size = #list + if list_size == 0 then return list end + table.sort(list, function (a, b) return a.points > b.points end) + return list +end + +local score_list = (function (player, frame) + local highscore = global.custom_highscore + + frame.clear() + frame.style.padding = 4 + frame.style.margin = 0 + + local line = frame.add { type = "line"} + line.style.top_margin = 4 + line.style.bottom_margin = 4 + + local label = frame.add ({ type = "label", caption = highscore.caption}) + label.style.font = "heading-1" + label.style.minimal_width = 780 + label.style.horizontal_align = "center" + label.style.vertical_align = "center" + + local line = frame.add { type = "line"} + line.style.top_margin = 4 + line.style.bottom_margin = 4 + + local scroll_pane = frame.add { type = "scroll-pane", name = "scroll_pane", direction = "vertical", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"} + scroll_pane.style.maximal_height = 320 + scroll_pane.style.minimal_height = 320 + + local t = scroll_pane.add {type = "table", column_count = 3} + + local label = t.add ({ type = "label", caption = "#"}) + label.style.minimal_width = 30 + label.style.font = "heading-2" + label.style.padding = 3 + local label = t.add ({ type = "label", caption = "Player:"}) + label.style.minimal_width = 160 + label.style.font = "heading-2" + label.style.padding = 3 + local label = t.add ({ type = "label", caption = "Won rounds:"}) + label.style.minimal_width = 160 + label.style.font = "heading-2" + label.style.padding = 3 + + for key, score in pairs(get_sorted_score()) do + local label = t.add ({ type = "label", caption = key}) + label.style.font = "heading-2" + label.style.padding = 1 + local label = t.add ({ type = "label", caption = score.name}) + label.style.font = "heading-2" + label.style.padding = 1 + label.style.font_color = game.players[score.name].chat_color + local label = t.add ({ type = "label", caption = score.points}) + label.style.font = "heading-2" + label.style.padding = 1 + end +end +) + +function Public.set_score(player, count) + local score_list = global.custom_highscore.score_list + score_list[player.index] = count +end + +function Public.get_score(player) + local score_list = global.custom_highscore.score_list + if not score_list[player.index] then score_list[player.index] = 0 end + return score_list[player.index] +end + +local function on_init() + global.custom_highscore = { + caption = "Highscores of the session:", + score_list = {}, + } +end + +comfy_panel_tabs["Map Scores"] = score_list + +local event = require 'utils.event' +event.on_init(on_init) + +return Public \ No newline at end of file From 3ca5c77950d40d1f062939be2a32f45b20624e9e Mon Sep 17 00:00:00 2001 From: MewMew Date: Tue, 5 Nov 2019 00:52:50 +0100 Subject: [PATCH 5/5] unit and turret limit, unit health boost + gui --- maps/biter_hatchery/gui.lua | 22 ++++++++++++++ maps/biter_hatchery/main.lua | 51 +++++++++++++++++++++++++++----- modules/biter_health_booster.lua | 1 - modules/map_score.lua | 1 + 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/maps/biter_hatchery/gui.lua b/maps/biter_hatchery/gui.lua index 41db161a..b895e2f7 100644 --- a/maps/biter_hatchery/gui.lua +++ b/maps/biter_hatchery/gui.lua @@ -14,6 +14,28 @@ function Public.spectate_button(player) button.style.bottom_padding = 2 end +function Public.unit_health_buttons(player) + if player.gui.top.health_boost_west then return end + local button = player.gui.top.add({type = "sprite-button", name = "health_boost_west", caption = 1, tooltip = "Health increase of west side biters."}) + button.style.font = "heading-1" + button.style.font_color = {r = 0, g = 180, b = 0} + button.style.minimal_height = 38 + button.style.minimal_width = 78 + button.style.padding = 2 + local button = player.gui.top.add({type = "sprite-button", name = "health_boost_east", caption = 1, tooltip = "Health increase of east side biters."}) + button.style.font = "heading-1" + button.style.font_color = {r = 180, g = 180, b = 0} + button.style.minimal_height = 38 + button.style.minimal_width = 78 + button.style.padding = 2 +end + +function Public.update_health_boost_buttons(player) + local gui = player.gui.top + gui.health_boost_west.caption = math.round(global.map_forces.west.unit_health_boost * 100, 2) .. "%" + gui.health_boost_east.caption = math.round(global.map_forces.east.unit_health_boost * 100, 2) .. "%" +end + local function create_spectate_confirmation(player) if player.gui.center.spectate_confirmation_frame then return end local frame = player.gui.center.add({type = "frame", name = "spectate_confirmation_frame", caption = "Are you sure you want to spectate this round?"}) diff --git a/maps/biter_hatchery/main.lua b/maps/biter_hatchery/main.lua index dfa69b6c..e2c8e7b9 100644 --- a/maps/biter_hatchery/main.lua +++ b/maps/biter_hatchery/main.lua @@ -2,6 +2,7 @@ require "modules.no_turrets" local RPG = require "modules.rpg" local Tabs = require 'comfy_panel.main' local Map_score = require "modules.map_score" +local Unit_health_booster = require "modules.biter_health_booster" local unit_raffle = require "maps.biter_hatchery.raffle_tables" local map_functions = require "tools.map_functions" local Terrain = require "maps.biter_hatchery.terrain" @@ -13,6 +14,17 @@ local Map = require "modules.map_info" local math_random = math.random local Public = {} +local m = 4 +local health_boost_food_values = { + ["automation-science-pack"] = 0.000001 * m, + ["logistic-science-pack"] = 0.0000025 * m, + ["military-science-pack"] = 0.0000096 * m, + ["chemical-science-pack"] = 0.0000264 * m, + ["production-science-pack"] = 0.00008874 * m, + ["utility-science-pack"] = 0.00009943 * m, + ["space-science-pack"] = 0.00028957 * m, +} + local worm_turret_spawn_radius = 18 local worm_turret_vectors = {} worm_turret_vectors.west = {} @@ -54,8 +66,8 @@ function Public.reset_map() map_gen_settings.autoplace_controls = { ["coal"] = {frequency = 100, size = 0.5, richness = 0.5,}, ["stone"] = {frequency = 100, size = 0.5, richness = 0.5,}, - ["copper-ore"] = {frequency = 100, size = 0.5, richness = 0.5,}, - ["iron-ore"] = {frequency = 100, size = 0.5, richness = 0.5,}, + ["copper-ore"] = {frequency = 200, size = 0.6, richness = 0.5,}, + ["iron-ore"] = {frequency = 200, size = 0.6, richness = 0.5,}, ["uranium-ore"] = {frequency = 50, size = 0.5, richness = 0.5,}, ["crude-oil"] = {frequency = 50, size = 0.5, richness = 0.5,}, ["trees"] = {frequency = math_random(5, 10) * 0.1, size = math_random(5, 10) * 0.1, richness = math_random(3, 10) * 0.1}, @@ -87,6 +99,13 @@ function Public.reset_map() global.map_forces.east.hatchery = e global.map_forces.west.target = e + global.map_forces.east.unit_health_boost = 1 + global.map_forces.west.unit_health_boost = 1 + global.map_forces.east.unit_count = 0 + global.map_forces.west.unit_count = 0 + global.map_forces.east.max_unit_count = 1024 + global.map_forces.west.max_unit_count = 1024 + draw_spawn_ores(surface) RPG.rpg_reset_all_players() @@ -110,6 +129,7 @@ end local function spawn_worm_turret(surface, force_name, food_item) local r_max = surface.count_entities_filtered({type = "turret", force = force_name}) + 1 + if r_max > 8 then return end if math_random(1, r_max) ~= 1 then return end local vectors = worm_turret_vectors[force_name] local vector = vectors[math_random(1, #vectors)] @@ -126,11 +146,16 @@ end local function spawn_units(belt, food_item, removed_item_count) local count_per_flask = unit_raffle[food_item][2] local raffle = unit_raffle[food_item][1] - for _ = 1, removed_item_count, 1 do + local team = global.map_forces[belt.force.name] + team.unit_health_boost = team.unit_health_boost + (health_boost_food_values[food_item] * removed_item_count) + for _ = 1, removed_item_count, 1 do for _ = 1, count_per_flask, 1 do - local unit = belt.surface.create_entity({name = raffle[math_random(1, #raffle)], position = belt.position, force = belt.force}) + local name = raffle[math_random(1, #raffle)] + local unit = belt.surface.create_entity({name = name, position = belt.position, force = belt.force}) unit.ai_settings.allow_destroy_when_commands_fail = false unit.ai_settings.allow_try_return_to_spawner = false + Unit_health_booster.add_unit(unit, team.unit_health_boost) + team.unit_count = team.unit_count + 1 end end if math_random(1, 32) == 1 then spawn_worm_turret(belt.surface, belt.force.name, food_item) end @@ -161,6 +186,7 @@ local function eat_food_from_belt(belt) for i = 1, 2, 1 do local line = belt.get_transport_line(i) for food_item, raffle in pairs(unit_raffle) do + if global.map_forces[belt.force.name].unit_count > global.map_forces[belt.force.name].max_unit_count then return end local removed_item_count = line.remove_item({name = food_item, count = 8}) if removed_item_count > 0 then feed_floaty_text(belt) @@ -179,6 +205,7 @@ local function nom() eat_food_from_belt(belt) end end + for _, player in pairs(game.connected_players) do Gui.update_health_boost_buttons(player) end end local function send_unit_groups() @@ -236,12 +263,20 @@ local function on_player_changed_position(event) end local function on_entity_died(event) - if not event.entity.valid then return end + local entity = event.entity + if not entity.valid then return end if global.game_reset_tick then return end - if event.entity.type ~= "unit-spawner" then return end + + if entity.type == "unit" then + local team = global.map_forces[entity.force.name] + team.unit_count = team.unit_count - 1 + return + end + + if entity.type ~= "unit-spawner" then return end local str - if event.entity.force.name == "east" then + if entity.force.name == "east" then game.print("East lost their Hatchery.", {100, 100, 100}) str = ">>>> West team has won the game!!! <<<<" for _, player in pairs(game.forces.east.connected_players) do @@ -283,6 +318,8 @@ local function on_player_joined_game(event) local surface = game.surfaces[global.active_surface_index] Gui.spectate_button(player) + Gui.unit_health_buttons(player) + Gui.update_health_boost_buttons(player) if player.gui.left.biter_hatchery_game_won then player.gui.left.biter_hatchery_game_won.destroy() end diff --git a/modules/biter_health_booster.lua b/modules/biter_health_booster.lua index bb369646..7213e064 100644 --- a/modules/biter_health_booster.lua +++ b/modules/biter_health_booster.lua @@ -71,7 +71,6 @@ end local function on_entity_damaged(event) local biter = event.entity if not (biter and biter.valid) then return end - if biter.force.index ~= 2 then return end if biter.type ~= "unit" then return end local biter_health_boost_units = global.biter_health_boost_units diff --git a/modules/map_score.lua b/modules/map_score.lua index 44c10192..445c0f8f 100644 --- a/modules/map_score.lua +++ b/modules/map_score.lua @@ -33,6 +33,7 @@ local score_list = (function (player, frame) line.style.bottom_margin = 4 local scroll_pane = frame.add { type = "scroll-pane", name = "scroll_pane", direction = "vertical", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"} + scroll_pane.style.minimal_width = 780 scroll_pane.style.maximal_height = 320 scroll_pane.style.minimal_height = 320