1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-22 03:38:48 +02:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
MaemiKozue 2019-11-05 17:27:40 +01:00
commit bde41e99e8
8 changed files with 239 additions and 61 deletions

View File

@ -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,11 +278,17 @@ 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 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)
for _, f in pairs({"north_biters", "south_biters"}) 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

View File

@ -20,6 +20,7 @@ local enemy_team_of = {
local minimum_modifier = 125
local maximum_modifier = 250
local player_amount_for_maximum_threat_gain = 20
@ -46,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
@ -63,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
@ -110,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"

View File

@ -284,7 +284,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 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

View File

@ -40,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
@ -128,7 +107,7 @@ 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 t = frame.add({type = "table", name = "team_manager_root_table", column_count = 5})
local i2 = 1
@ -215,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
@ -303,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

View File

@ -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?"})

View File

@ -1,5 +1,8 @@
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"
@ -11,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 = {}
@ -52,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},
@ -85,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()
@ -108,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)]
@ -124,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
@ -159,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)
@ -177,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()
@ -234,31 +263,42 @@ 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
local gui_str
if event.entity.force.name == "east" then
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 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 +308,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
@ -277,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

View File

@ -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

93
modules/map_score.lua Normal file
View File

@ -0,0 +1,93 @@
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.minimal_width = 780
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