1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-04 00:15:45 +02:00

Add files via upload

This commit is contained in:
manolck 2020-02-23 04:02:58 +01:00 committed by GitHub
parent 1fd56a8df6
commit 19c442c77d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1174 additions and 520 deletions

View File

@ -1,134 +1,15 @@
local Public = {}
local Team = require "maps.native_war.team"
local XP = require "maps.native_war.xp"
Public.wave_price = {
["automation-science-pack"] ={price = 100},
["logistic-science-pack"] ={price = 60},
["military-science-pack"] ={price = 100},
["chemical-science-pack"] ={price = 100},
["production-science-pack"] ={price = 100},
["utility-science-pack"] ={price = 80},
}
local upgrade_turret_price = {
["automation-science-pack"] ={price = 200},
["logistic-science-pack"] ={price = 120},
["military-science-pack"] ={price = 200},
["chemical-science-pack"] ={price = 200},
["production-science-pack"] ={price = 200},
["utility-science-pack"] ={price = 160},
}
local nb_of_waves = {1,5,10}
local turret_upgrade_science_pack= {
["automation-science-pack"] = {short = "red", t = "small"},
["logistic-science-pack"] = {short = "green", t = "small"},
["military-science-pack"] = {short = "grey", t = "medium"},
["chemical-science-pack"] = {short = "blue", t = "big"},
["production-science-pack"] = {short = "purple", t = "behemoth"},
["utility-science-pack"] = {short = "yellow", t = "behemoth"},
}
Public.science_pack = {
["automation-science-pack"] = {short = "red"},
["logistic-science-pack"] = {short = "green"},
["military-science-pack"] = {short = "grey"},
["chemical-science-pack"] = {short = "blue"},
["production-science-pack"] = {short = "purple"},
["utility-science-pack"] = {short = "yellow"},
}
local color = {
["automation-science-pack"] = {r=255, g=50, b=50},
["logistic-science-pack"] = {r=50, g=255, b=50},
["military-science-pack"] = {r=105, g=105, b=105},
["chemical-science-pack"] = {r=100, g=200, b=255},
["production-science-pack"] = {r=150, g=25, b=255},
["utility-science-pack"] = {r=210, g=210, b=60},
["space-science-pack"] = {r=255, g=255, b=255},
["message"] = {r=255, g=108, b=0},
}
local worm_dist = {"Closest","Farthest","All"}
local Settings = require "maps.native_war.settings"
local button_science_name={}
for _ ,nbw in pairs(nb_of_waves) do
for k,sp in pairs(Public.science_pack) do
for _ ,nbw in pairs(Settings.nb_of_waves) do
for k,sp in pairs(Settings.science_pack) do
table.insert(button_science_name , {sp = k, spc = sp.short, button_name = sp.short.."_"..nbw, nbw = nbw})
end
end
local button_upgrade_name={
["red_Closest"] = {sp = "automation-science-pack", spc = "red", dist = "Closest", type_worm = "small"},
["green_Closest"] = {sp = "logistic-science-pack", spc = "green", dist = "Closest", type_worm = "small"},
["grey_Closest"] = {sp = "military-science-pack", spc = "grey", dist = "Closest", type_worm = "medium"},
["blue_Closest"] = {sp = "chemical-science-pack", spc = "blue", dist = "Closest", type_worm = "big"},
["purple_Closest"] = {sp = "production-science-pack", spc = "purple", dist = "Closest", type_worm = "behemoth"},
["yellow_Closest"] = {sp = "utility-science-pack", spc = "yellow", dist = "Closest", type_worm = "behemoth"},
["red_Farthest"] = {sp = "automation-science-pack", spc = "red", dist = "Farthest", type_worm = "small"},
["green_Farthest"] = {sp = "logistic-science-pack", spc = "green", dist = "Furthest", type_worm = "small"},
["grey_Farthest"] = {sp = "military-science-pack", spc = "grey", dist = "Farthest", type_worm = "medium"},
["blue_Farthest"] = {sp = "chemical-science-pack", spc = "blue", dist = "Furthest", type_worm = "big"},
["purple_Farthest"] = {sp = "production-science-pack", spc = "purple", dist = "Farthest", type_worm = "behemoth"},
["yellow_Farthest"] = {sp = "utility-science-pack", spc = "yellow", dist = "Furthest", type_worm = "behemoth"},
["red_All"] = {sp = "automation-science-pack", spc = "red", dist = "All", type_worm = "small"},
["green_All"] = {sp = "logistic-science-pack", spc = "green", dist = "All", type_worm = "small"},
["grey_All"] = {sp = "military-science-pack", spc = "grey", dist = "All", type_worm = "medium"},
["blue_All"] = {sp = "chemical-science-pack", spc = "blue", dist = "All", type_worm = "big"},
["purple_All"] = {sp = "production-science-pack", spc = "purple", dist = "All", type_worm = "behemoth"},
["yellow_All"] = {sp = "utility-science-pack", spc = "yellow", dist = "All", type_worm = "behemoth"},
}
--[[function Public.spectate_button(player)
if player.gui.top.spectate_button then return end
local button = player.gui.top.add({type = "button", name = "spectate_button", caption = "Spectate"})
button.style.font = "default-bold"
button.style.font_color = {r = 0.0, g = 0.0, b = 0.0}
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.top_padding = 2
button.style.left_padding = 4
button.style.right_padding = 4
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 modfier of west side biters.\nIncreases by feeding."})
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 modfier of east side biters.\nIncreases by feeding."})
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?"})
frame.style.font = "default"
frame.style.font_color = {r = 0.3, g = 0.65, b = 0.3}
frame.add({type = "button", name = "confirm_spectate", caption = "Spectate"})
frame.add({type = "button", name = "cancel_spectate", caption = "Cancel"})
end
function Public.rejoin_question(player)
if player.gui.center.rejoin_question_frame then return end
local frame = player.gui.center.add({type = "frame", name = "rejoin_question_frame", caption = "Rejoin the game?"})
frame.style.font = "default"
frame.style.font_color = {r = 0.3, g = 0.65, b = 0.3}
frame.add({type = "button", name = "confirm_rejoin", caption = "Rejoin"})
frame.add({type = "button", name = "cancel_rejoin", caption = "Cancel"})
end]]
local function create_new_gui_for_market(player,market)
local player_inventory = player.get_main_inventory()
local player_red_science_pack = player_inventory.get_item_count("automation-science-pack")
@ -169,7 +50,7 @@ local function create_new_gui_for_market(player,market)
case.style.right_padding = 30
case.style.left_padding = 30
for _, nb in pairs(nb_of_waves) do
for _, nb in pairs(Settings.nb_of_waves) do
local wave_nb = nb
local text_wave =""
if wave_nd == 1 then
@ -180,21 +61,21 @@ local function create_new_gui_for_market(player,market)
local case = table.add({type = "label", caption= text_wave})
case.style.right_padding = 30
local case = table.add({type = "flow", direction = "horizontal"})
case.add({type = "sprite-button", sprite = "item/automation-science-pack", name = "red_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of small biter/spitter.\nPrice: "..wave_nb*Public.wave_price["automation-science-pack"].price.." [item=automation-science-pack].", number = math.floor((player_red_science_pack/Public.wave_price["automation-science-pack"].price)/wave_nb)})
case.add({type = "sprite-button", sprite = "item/logistic-science-pack", name = "green_"..wave_nb, tooltip = "Buy 1 wave of small biter/spitter.\nPrice: "..wave_nb*Public.wave_price["logistic-science-pack"].price.." [item=logistic-science-pack].", number = math.floor((player_green_science_pack/Public.wave_price["logistic-science-pack"].price)/wave_nb)})
case.add({type = "sprite-button", sprite = "item/automation-science-pack", name = "red_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of small biter/spitter.\nPrice: "..wave_nb*Settings.wave_price["automation-science-pack"].price.." [item=automation-science-pack].", number = math.floor((player_red_science_pack/Settings.wave_price["automation-science-pack"].price)/wave_nb)})
case.add({type = "sprite-button", sprite = "item/logistic-science-pack", name = "green_"..wave_nb, tooltip = "Buy 1 wave of small biter/spitter.\nPrice: "..wave_nb*Settings.wave_price["logistic-science-pack"].price.." [item=logistic-science-pack].", number = math.floor((player_green_science_pack/Settings.wave_price["logistic-science-pack"].price)/wave_nb)})
case.style.right_padding = 12
case.style.left_padding = 12
local case = table.add({type = "flow", direction = "horizontal"})
case.add({type = "sprite-button", sprite = "item/military-science-pack", name = "grey_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of medium biter/spitter.\nPrice: "..wave_nb*Public.wave_price["military-science-pack"].price.." [item=military-science-pack].", number = math.floor((player_grey_science_pack/Public.wave_price["military-science-pack"].price)/wave_nb)})
case.add({type = "sprite-button", sprite = "item/military-science-pack", name = "grey_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of medium biter/spitter.\nPrice: "..wave_nb*Settings.wave_price["military-science-pack"].price.." [item=military-science-pack].", number = math.floor((player_grey_science_pack/Settings.wave_price["military-science-pack"].price)/wave_nb)})
case.style.left_padding = 30
case.style.right_padding = 30
local case = table.add({type = "flow", direction = "horizontal"})
case.add({type = "sprite-button", sprite = "item/chemical-science-pack", name = "blue_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of big biter/spitter.\nPrice: "..wave_nb*Public.wave_price["chemical-science-pack"].price.." [item=chemical-science-pack].", number = math.floor((player_blue_science_pack/Public.wave_price["chemical-science-pack"].price)/wave_nb)})
case.add({type = "sprite-button", sprite = "item/chemical-science-pack", name = "blue_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of big biter/spitter.\nPrice: "..wave_nb*Settings.wave_price["chemical-science-pack"].price.." [item=chemical-science-pack].", number = math.floor((player_blue_science_pack/Settings.wave_price["chemical-science-pack"].price)/wave_nb)})
case.style.left_padding = 30
case.style.right_padding = 30
local case = table.add({type = "flow", direction = "horizontal"})
case.add({type = "sprite-button", sprite = "item/production-science-pack", name = "purple_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of behemoth biter/spitter.\nPrice: "..wave_nb*Public.wave_price["production-science-pack"].price.." [item=production-science-pack].", number = math.floor((player_purple_science_pack/Public.wave_price["production-science-pack"].price)/wave_nb)})
case.add({type = "sprite-button", sprite = "item/utility-science-pack", name = "yellow_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of behemoth biter/spitter.\nPrice: "..wave_nb*Public.wave_price["utility-science-pack"].price.." [item=utility-science-pack].", number = math.floor((player_yellow_science_pack/Public.wave_price["utility-science-pack"].price)/wave_nb)})
case.add({type = "sprite-button", sprite = "item/production-science-pack", name = "purple_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of behemoth biter/spitter.\nPrice: "..wave_nb*Settings.wave_price["production-science-pack"].price.." [item=production-science-pack].", number = math.floor((player_purple_science_pack/Settings.wave_price["production-science-pack"].price)/wave_nb)})
case.add({type = "sprite-button", sprite = "item/utility-science-pack", name = "yellow_"..wave_nb, tooltip = "Buy "..wave_nb.." wave of behemoth biter/spitter.\nPrice: "..wave_nb*Settings.wave_price["utility-science-pack"].price.." [item=utility-science-pack].", number = math.floor((player_yellow_science_pack/Settings.wave_price["utility-science-pack"].price)/wave_nb)})
case.style.right_padding = 12
case.style.left_padding = 12
end
@ -224,7 +105,7 @@ local function create_new_gui_for_market(player,market)
case.style.right_padding = 30
case.style.left_padding = 30
for _, dist in pairs(worm_dist) do
for _, dist in pairs(Settings.worm_dist) do
local turret = ""
if dist == "all" then
turret = "turrets"
@ -234,21 +115,21 @@ local function create_new_gui_for_market(player,market)
local case = table.add({type = "label", caption=dist})
case.style.right_padding = 30
local case = table.add({type = "flow", direction = "horizontal"})
case.add({type = "sprite-button", sprite = "item/automation-science-pack", name = "red_"..dist, tooltip = "Buy "..dist.." worm "..turret..".\nPrice: "..upgrade_turret_price["automation-science-pack"].price.." [item=automation-science-pack].", number = math.floor(player_red_science_pack/upgrade_turret_price["automation-science-pack"].price)})
case.add({type = "sprite-button", sprite = "item/logistic-science-pack", name = "green_"..dist, tooltip = "Buy "..dist.." worm "..turret..".\nPrice: "..upgrade_turret_price["logistic-science-pack"].price.." [item=logistic-science-pack].", number = math.floor(player_green_science_pack/upgrade_turret_price["logistic-science-pack"].price)})
case.add({type = "sprite-button", sprite = "item/automation-science-pack", name = "red_"..dist, tooltip = "Buy "..dist.." worm "..turret..".\nPrice: "..Settings.upgrade_turret_price["automation-science-pack"].price.." [item=automation-science-pack].", number = math.floor(player_red_science_pack/Settings.upgrade_turret_price["automation-science-pack"].price)})
case.add({type = "sprite-button", sprite = "item/logistic-science-pack", name = "green_"..dist, tooltip = "Buy "..dist.." worm "..turret..".\nPrice: "..Settings.upgrade_turret_price["logistic-science-pack"].price.." [item=logistic-science-pack].", number = math.floor(player_green_science_pack/Settings.upgrade_turret_price["logistic-science-pack"].price)})
case.style.right_padding = 12
case.style.left_padding = 12
local case = table.add({type = "flow", direction = "horizontal"})
case.add({type = "sprite-button", sprite = "item/military-science-pack", name = "grey_"..dist, tooltip = "Upgrade "..dist.." worm "..turret..".\nPrice: "..upgrade_turret_price["military-science-pack"].price.." [item=military-science-pack].", number = math.floor(player_grey_science_pack/upgrade_turret_price["military-science-pack"].price)})
case.add({type = "sprite-button", sprite = "item/military-science-pack", name = "grey_"..dist, tooltip = "Upgrade "..dist.." worm "..turret..".\nPrice: "..Settings.upgrade_turret_price["military-science-pack"].price.." [item=military-science-pack].", number = math.floor(player_grey_science_pack/Settings.upgrade_turret_price["military-science-pack"].price)})
case.style.left_padding = 30
case.style.right_padding = 30
local case = table.add({type = "flow", direction = "horizontal"})
case.add({type = "sprite-button", sprite = "item/chemical-science-pack", name = "blue_"..dist, tooltip = "Upgrade "..dist.." worm "..turret..".\nPrice: "..upgrade_turret_price["chemical-science-pack"].price.." [item=chemical-science-pack].", number = math.floor(player_blue_science_pack/upgrade_turret_price["chemical-science-pack"].price)})
case.add({type = "sprite-button", sprite = "item/chemical-science-pack", name = "blue_"..dist, tooltip = "Upgrade "..dist.." worm "..turret..".\nPrice: "..Settings.upgrade_turret_price["chemical-science-pack"].price.." [item=chemical-science-pack].", number = math.floor(player_blue_science_pack/Settings.upgrade_turret_price["chemical-science-pack"].price)})
case.style.left_padding = 30
case.style.right_padding = 30
local case = table.add({type = "flow", direction = "horizontal"})
case.add({type = "sprite-button", sprite = "item/production-science-pack", name = "purple_"..dist, tooltip = "Upgrade "..dist.." worm "..turret..".\nPrice: "..upgrade_turret_price["production-science-pack"].price.." [item=production-science-pack].", number = math.floor(player_purple_science_pack/upgrade_turret_price["production-science-pack"].price)})
case.add({type = "sprite-button", sprite = "item/utility-science-pack", name = "yellow_"..dist, tooltip = "Upgrade "..dist.." worm "..turret..".\nPrice: "..upgrade_turret_price["utility-science-pack"].price.." [item=utility-science-pack].", number = math.floor(player_yellow_science_pack/upgrade_turret_price["utility-science-pack"].price)})
case.add({type = "sprite-button", sprite = "item/production-science-pack", name = "purple_"..dist, tooltip = "Upgrade "..dist.." worm "..turret..".\nPrice: "..Settings.upgrade_turret_price["production-science-pack"].price.." [item=production-science-pack].", number = math.floor(player_purple_science_pack/Settings.upgrade_turret_price["production-science-pack"].price)})
case.add({type = "sprite-button", sprite = "item/utility-science-pack", name = "yellow_"..dist, tooltip = "Upgrade "..dist.." worm "..turret..".\nPrice: "..Settings.upgrade_turret_price["utility-science-pack"].price.." [item=utility-science-pack].", number = math.floor(player_yellow_science_pack/Settings.upgrade_turret_price["utility-science-pack"].price)})
case.style.right_padding = 12
case.style.left_padding = 12
end
@ -340,7 +221,7 @@ local function on_gui_click(event)
if event.element.name == "cancel_market" then
player.gui.screen["market_frame"].destroy()
local surface = game.surfaces[global.active_surface_index]
local surface = game.surfaces["native_war"]
if player.force.name == "west" then
local market = surface.find_entities_filtered{position = {-197,0}, radius = 5, type = "market"}
market[1].operable = true
@ -399,16 +280,16 @@ local function on_gui_click(event)
if event.element.name == button.button_name then
local count = 0
for i = 1, button.nbw, 1 do
if player_inventory.get_item_count(button.sp) < Public.wave_price[button.sp].price then break end
player.remove_item({name=button.sp, count=Public.wave_price[button.sp].price})
if player_inventory.get_item_count(button.sp) < Settings.wave_price[button.sp].price then break end
player.remove_item({name=button.sp, count=Settings.wave_price[button.sp].price})
Team.on_buy_wave("native_war", player.force.name, button.spc)
count = count + 1
end
if count > 0 then
if button.nbw > 1 then
game.print(player.name.." buy "..count.." waves of biter/spitters using [item="..button.sp.."]", color[button.sp])
game.print(player.name.." buy "..count.." waves of biter/spitters using [item="..button.sp.."]", Settings.color[button.sp])
else
game.print(player.name.." buy "..count.." wave of biter/spitters using [item="..button.sp.."]", color[button.sp])
game.print(player.name.." buy "..count.." wave of biter/spitters using [item="..button.sp.."]", Settings.color[button.sp])
end
end
player.gui.screen["market_frame"].destroy()
@ -418,22 +299,22 @@ local function on_gui_click(event)
end
for k, button in pairs(button_upgrade_name) do --sp = k, spc = sp.short, button_name = sp.short.."_"..dist, dist = dist, type_worm = sp.t
for k, button in pairs(Settings.button_upgrade_name) do --sp = k, spc = sp.short, button_name = sp.short.."_"..dist, dist = dist, type_worm = sp.t
if event.element.name == k then
if player_inventory.get_item_count(button.sp) >= upgrade_turret_price[button.sp].price then
if player_inventory.get_item_count(button.sp) >= Settings.upgrade_turret_price[button.sp].price then
if button.sp == "automation-science-pack" or button.sp == "logistic-science-pack" then
if Team.buy_worm_turret(game.surfaces["native_war"], player.force.name, button.dist, player, player_inventory.get_item_count(button.sp),upgrade_turret_price[button.sp].price, button.sp) then
if Team.buy_worm_turret(game.surfaces["native_war"], player.force.name, button.dist, player, player_inventory.get_item_count(button.sp),Settings.upgrade_turret_price[button.sp].price, button.sp) then
player.gui.screen["market_frame"].destroy()
create_new_gui_for_market(player,event.entity)
break
else
player.print("All small worm turrets are already buy", color["message"])
player.print("All small worm turrets are already buy", Settings.color["message"])
player.gui.screen["market_frame"].destroy()
create_new_gui_for_market(player,event.entity)
break
end
else
if Team.upgrade_worm_turret(game.surfaces["native_war"], player.force.name, button.dist, player, player_inventory.get_item_count(button.sp),upgrade_turret_price[button.sp].price, button.sp, button.type_worm.."-worm-turret") then
if Team.upgrade_worm_turret(game.surfaces["native_war"], player.force.name, button.dist, player, player_inventory.get_item_count(button.sp),Settings.upgrade_turret_price[button.sp].price, button.sp, button.type_worm.."-worm-turret") then
player.gui.screen["market_frame"].destroy()
create_new_gui_for_market(player,event.entity)
break
@ -443,7 +324,7 @@ local function on_gui_click(event)
["big"] = "medium",
["behemoth"] = "big"
}
player.print("There is no more "..table_upgrade[button.type_worm].." worm turrets to upgrade with [item="..button.sp.."].", color["message"])
player.print("There is no more "..table_upgrade[button.type_worm].." worm turrets to upgrade with [item="..button.sp.."].", Settings.color["message"])
player.gui.screen["market_frame"].destroy()
create_new_gui_for_market(player,event.entity)
break

254
maps/native_war/init.lua Normal file
View File

@ -0,0 +1,254 @@
local Public = {}
function Public.settings()
global.gui_refresh_delay = 0
global.game_lobby_active = true
global.bb_debug = false
global.combat_balance = {}
global.nv_settings = {
--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?
--GENERAL SETTINGS--
["blueprint_library_importing"] = false, --Allow the importing of blueprints from the blueprint library?
["blueprint_string_importing"] = false, --Allow the importing of blueprints via blueprint strings?
}
end
function Public.surface()
local map_gen_settings = {}
map_gen_settings.seed = math.random(1, 99999999)
map_gen_settings.water = math.random(5, 10) * 0.025
map_gen_settings.starting_area = 1
map_gen_settings.terrain_segmentation = 8
map_gen_settings.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["stone"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["copper-ore"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["iron-ore"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["uranium-ore"] = {frequency = 2, size = 1, richness = 1},
["crude-oil"] = {frequency = 3, size = 1, richness = 0.75},
["trees"] = {frequency = math.random(5, 12) * 0.1, size = math.random(5, 12) * 0.1, richness = math.random(1, 10) * 0.1},
["enemy-base"] = {frequency = 0, size = 0, richness = 0}
}
local surface = game.create_surface("mirror_terrain", map_gen_settings)
local hatchery_position = {x = 200, y = 0}
local x = hatchery_position.x - 16
local offset = 38
surface.request_to_generate_chunks({x, 0}, 5)
surface.force_generate_chunk_requests()
local positions = {{x = x, y = offset}, {x = x, y = offset * -1}, {x = x, y = offset * -2}, {x = x, y = offset * 2}}
table.shuffle_table(positions)
local r = 32
for x = r * -1, r, 1 do
for y = r * -1, r, 1 do
local p = {x = hatchery_position.x + x, y = hatchery_position.y + y}
if math.sqrt(x ^ 2 + y ^ 2) < r then
local tile = surface.get_tile(p)
if tile.name == "water" or tile.name == "deepwater" then
surface.set_tiles({{name = "landfill", position = p}}, true)
end
end
end
end
local map_gen_settings2 = {
["seed"] = 1,
["water"] = 1,
["starting_area"] = 1,
["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
["default_enable_all_autoplace_controls"] = false,
["autoplace_settings"] = {
["entity"] = {treat_missing_as_default = false},
["tile"] = {treat_missing_as_default = false},
["decorative"] = {treat_missing_as_default = false},
},
}
global.active_surface_index = game.create_surface("native_war", map_gen_settings2)
local surface = game.surfaces["native_war"]
surface.request_to_generate_chunks({0,0}, 8)
surface.force_generate_chunk_requests()
end
function Public.forces()
local surface = game.surfaces["native_war"]
game.create_force("west")
game.create_force("east")
game.create_force("spectator")
game.forces.west.set_friend("spectator", true)
game.forces.west.set_spawn_position({-205, 0}, surface)
game.forces.west.share_chart = true
game.forces.east.set_friend("spectator", true)
game.forces.east.set_spawn_position({205, 0}, surface)
game.forces.east.share_chart = true
game.forces.spectator.set_friend("west", true)
game.forces.spectator.set_friend("east", true)
game.forces.spectator.set_spawn_position({0,-190},surface)
game.forces.spectator.share_chart = false
if not global.nv_settings.blueprint_library_importing then
game.permissions.get_group("Default").set_allows_action(defines.input_action.grab_blueprint_record, false)
end
if not global.nv_settings.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)
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.activate_copy,
defines.input_action.activate_cut,
defines.input_action.activate_paste,
defines.input_action.clean_cursor_stack,
defines.input_action.edit_permission_group,
defines.input_action.gui_click,
defines.input_action.gui_confirmed,
defines.input_action.gui_elem_changed,
defines.input_action.gui_location_changed,
defines.input_action.gui_selected_tab_changed,
defines.input_action.gui_selection_state_changed,
defines.input_action.gui_switch_state_changed,
defines.input_action.gui_text_changed,
defines.input_action.gui_value_changed,
defines.input_action.open_character_gui,
defines.input_action.open_kills_gui,
defines.input_action.rotate_entity,
defines.input_action.start_walking,
defines.input_action.toggle_show_entity_info,
defines.input_action.write_to_console,
}
for _, d in pairs(defs) do p.set_allows_action(d, true) end
global.rocket_silo = {}
global.spectator_rejoin_delay = {}
global.spy_fish_timeout = {}
global.force_area = {}
global.unit_spawners = {}
global.unit_spawners.north_biters = {}
global.unit_spawners.south_biters = {}
global.active_biters = {}
global.biter_raffle = {}
global.evo_raise_counter = 1
global.next_attack = "north"
if math.random(1,2) == 1 then global.next_attack = "south" end
global.bb_evolution = {}
global.bb_threat_income = {}
global.bb_threat = {}
global.chunks_to_mirror = {}
global.map_pregen_message_counter = {}
for _, force_name in pairs({"west", "east"}) do
game.forces[force_name].share_chart = true
game.forces[force_name].research_queue_enabled = true
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["land-mine"].enabled = false
game.forces[force_name].technologies["atomic-bomb"].enabled = false
game.forces[force_name].research_queue_enabled = true
game.forces[force_name].share_chart = true
local force_index = game.forces[force_name].index
global.map_forces[force_name].unit_health_boost = 1
global.map_forces[force_name].unit_count = 0
global.map_forces[force_name].units = {}
global.map_forces[force_name].radar = {}
global.map_forces[force_name].max_unit_count = 768
global.map_forces[force_name].player_count = 0
global.biter_reanimator.forces[force_index] = 0
global.map_forces[force_name].energy = 0
global.map_forces[force_name].modifier ={damage = 1, resistance = 1, splash = 1}
global.map_forces[force_name].ate_buffer_potion = {
["automation-science-pack"] = 0,
["logistic-science-pack"]= 0,
["military-science-pack"]= 0,
["chemical-science-pack"]= 0,
["production-science-pack"]= 0,
["utility-science-pack"]= 0
}
if force_name == "west" then
global.map_forces[force_name].worm_turrets_positions = {
[1] = {x=-127,y=-38},
[2] = {x=-112,y=-38},
[3] = {x=-127,y=-70},
[4] = {x=-112,y=-70},
[5] = {x=-127,y=-102},
[6] = {x=-112,y=-102},
[7] = {x=-90,y=-119},
[8] = {x=-90,y=-136},
[9] = {x=-70,y=-90},
[10] = {x=-50,y=-90},
[11] = {x=-70,y=-58},
[12] = {x=-50,y=-58},
[13] = {x=-70,y=-26},
[14] = {x=-50,y=-26},
[15] = {x=-70,y=0},
[16] = {x=-50,y=0},
[17] = {x=-70,y=36},
[18] = {x=-50,y=36},
[19] = {x=-70,y=68},
[20] = {x=-50,y=68},
[21] = {x=-70,y=100},
[22] = {x=-50,y=100},
[23] = {x=-30,y=119},
[24] = {x=-30,y=136},
[25] = {x=-9,y=90},
[26] = {x=9,y=90},
[27] = {x=-9,y=59},
[28] = {x=9,y=59},
[29] = {x=-9,y=27},
[30] = {x=9,y=27}
}
global.map_forces[force_name].spawn = {x=-137,y=0}
global.map_forces[force_name].eei = {x=-200,y=0}
else
global.map_forces[force_name].worm_turrets_positions ={
[1] = {x=127,y=38},
[2] = {x=112,y=38},
[3] = {x=127,y=70},
[4] = {x=112,y=70},
[5] = {x=127,y=102},
[6] = {x=112,y=102},
[7] = {x=90,y=119},
[8] = {x=90,y=136},
[9] = {x=70,y=90},
[10] = {x=50,y=90},
[11] = {x=70,y=58},
[12] = {x=50,y=58},
[13] = {x=70,y=26},
[14] = {x=50,y=26},
[15] = {x=70,y=0},
[16] = {x=50,y=0},
[17] = {x=70,y=-36},
[18] = {x=50,y=-36},
[19] = {x=70,y=-68},
[20] = {x=50,y=-68},
[21] = {x=70,y=-100},
[22] = {x=50,y=-100},
[23] = {x=30,y=-119},
[24] = {x=30,y=-136},
[25] = {x=-9,y=-90},
[26] = {x=9,y=-90},
[27] = {x=9,y=-59},
[28] = {x=-9,y=-59},
[29] = {x=9,y=-27},
[30] = {x=-9,y=-27}
}
global.map_forces[force_name].spawn = {x=137,y=0}
global.map_forces[force_name].eei = {x=201,y=0}
end
global.active_biters[force_name] = {}
global.biter_raffle[force_name] = {}
end
end
return Public

View File

@ -1,43 +1,22 @@
require "modules.biter_reanimator"
require "maps.native_war.share_chat"
require "maps.native_war.mineable_wreckage_yields_scrap"
local Global = require 'utils.global'
local Tabs = require 'comfy_panel.main'
local Map_score = require "modules.map_score"
local Team = require "maps.native_war.team"
local Terrain = require "maps.native_war.terrain"
local Gui = require "maps.native_war.gui"
require "maps.native_war.share_chat"
require "maps.native_war.mineable_wreckage_yields_scrap"
local Init = require "maps.native_war.init"
local Settings = require "maps.native_war.settings"
local Reset = require "functions.soft_reset"
local Map = require "modules.map_info"
local Map = require "maps.native_war.map_info"
local Team_manager = require "maps.native_war.team_manager"
local math_random = math.random
local Public = {}
local science_pack_name = {"automation-science-pack", "logistic-science-pack", "military-science-pack", "chemical-science-pack", "production-science-pack", "utility-science-pack"}
local map_gen_settings = {
["seed"] = 1,
["water"] = 1,
["starting_area"] = 1,
["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
["default_enable_all_autoplace_controls"] = false,
["autoplace_settings"] = {
["entity"] = {treat_missing_as_default = false},
["tile"] = {treat_missing_as_default = false},
["decorative"] = {treat_missing_as_default = false},
},
}
local m = 5
local health_boost_food_values = {
["automation-science-pack"] = 0.000001 * m,
["logistic-science-pack"] = 0.000003 * m,
["military-science-pack"] = 0.00000822 * m,
["chemical-science-pack"] = 0.00002271 * m,
["production-science-pack"] = 0.00009786 * m,
["utility-science-pack"] = 0.00010634 * m,
["space-science-pack"] = 0.00041828 * m,
}
local worm_turret_spawn_radius = 18
local worm_turret_vectors = {}
worm_turret_vectors.west = {}
for x = 0, worm_turret_spawn_radius, 1 do
@ -54,42 +33,6 @@ for x = worm_turret_spawn_radius * -1, 0, 1 do
end
end
function Public.reset_map()
Terrain.create_mirror_surface()
if not global.active_surface_index then
global.active_surface_index = game.create_surface("native_war", map_gen_settings).index
else
global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, Team.starting_items).index
end
local surface = game.surfaces[global.active_surface_index]
surface.request_to_generate_chunks({0,0}, 8)
surface.force_generate_chunk_requests()
game.forces.spectator.set_spawn_position({0, -190}, surface)
game.forces.west.set_spawn_position({-205, 0}, surface)
game.forces.east.set_spawn_position({205, 0}, surface)
XP.xp_reset_all_players()
Team.set_force_attributes()
Team.assign_random_force_to_active_players()
for _, player in pairs(game.connected_players) do
Team.teleport_player_to_active_surface(player)
end
for _, player in pairs(game.forces.spectator.connected_players) do
player.character.destroy()
Team.set_player_to_spectator(player)
end
for _, player in pairs(game.forces.spectator.players) do
Gui.rejoin_question(player)
end
kill_entities_combat_zone(surface)
end
function create_beams(surface, energy, force)
if force == "west" then
local beams = surface.find_entities_filtered{area = {{-140,-100},{-30,100}}, name = "electric-beam"}
@ -203,7 +146,6 @@ local function initial_worm_turret(surface)
end
end
local function get_belts(market)
local belts = market.surface.find_entities_filtered({
type = "transport-belt",
@ -216,7 +158,7 @@ end
local function eat_food_from_belt(belt)
for i = 1, 2, 1 do
local line = belt.get_transport_line(i)
for _, science_name in pairs(science_pack_name) do
for _, science_name in pairs(Settings.science_pack_name) 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 = science_name, count = 8})
global.map_forces[belt.force.name].ate_buffer_potion[science_name] = global.map_forces[belt.force.name].ate_buffer_potion[science_name] + removed_item_count
@ -225,7 +167,7 @@ local function eat_food_from_belt(belt)
end
local function spawn_wave_from_belt(force_name)
for _, science_name in pairs(science_pack_name) do
for _, science_name in pairs(Settings.science_pack_name) do
local nb_science = global.map_forces[force_name].ate_buffer_potion[science_name]
if nb_science >= Gui.wave_price[science_name].price then
Team.on_buy_wave("native_war", force_name, Gui.science_pack[science_name].short)
@ -236,7 +178,7 @@ local function spawn_wave_from_belt(force_name)
end
local function nom()
local surface = game.surfaces[global.active_surface_index]
local surface = game.surfaces["native_war"]
for key, force in pairs(global.map_forces) do
if not force.hatchery then return end
force.hatchery.health = force.hatchery.health + 5
@ -263,7 +205,7 @@ local function get_units(force_name)
end
local function send_unit_groups()
local surface = game.surfaces[global.active_surface_index]
local surface = game.surfaces["native_war"]
for key, force in pairs(global.map_forces) do
local units = get_units(key)
if #units > 0 then
@ -298,14 +240,27 @@ local function send_unit_groups()
end
end
end
local function randomize_worms()
for k, pos in pairs(global.map_forces["west"].worm_turrets_positions) do
local vx=math.random(0, 8)-4
local vy=math.random(0, 8)-4
global.map_forces["west"].worm_turrets_positions[k].x = pos.x + vx
global.map_forces["west"].worm_turrets_positions[k].y = pos.y + vy
global.map_forces["east"].worm_turrets_positions[k].x = global.map_forces["east"].worm_turrets_positions[k].x - vx
global.map_forces["east"].worm_turrets_positions[k].y = global.map_forces["east"].worm_turrets_positions[k].y - vy
end
end
local function on_player_changed_position(event)
local player = game.players[event.player_index]
if player.position.y > -175 and player.position.y < -173 and player.position.x <= 15 and player.position.x >= -15 then
player.teleport({player.position.x , 175}, game.surfaces[global.active_surface_index])
player.teleport({player.position.x , 175}, game.surfaces["native_war"])
end
if player.position.y < 175 and player.position.y > 173 and player.position.x <= 15 and player.position.x >= -15 then
player.teleport({player.position.x , -175}, game.surfaces[global.active_surface_index])
player.teleport({player.position.x , -175}, game.surfaces["native_war"])
end
if math.abs(player.position.x) > 256 then
if player.gui.screen["market_frame"] then player.gui.screen["market_frame"].destroy() end
end
end
@ -324,7 +279,7 @@ local function on_entity_died(event)
if entity.type ~= "market" then return end
if entity.force.name == "east" then
game.print("East lost their Hatchery.", {100, 100, 100})
game.print("East lost their Market.", {100, 100, 100})
game.forces.east.play_sound{path="utility/game_lost", volume_modifier=0.85}
game.print(">>>> WEST TEAM HAS WON THE GAME!!! <<<<", {250, 120, 0})
@ -336,7 +291,7 @@ local function on_entity_died(event)
end
end
else
game.print("West lost their Hatchery.", {100, 100, 100})
game.print("West lost their Market.", {100, 100, 100})
game.forces.west.play_sound{path="utility/game_lost", volume_modifier=0.85}
game.print(">>>> EAST TEAM HAS WON THE GAME!!! <<<<", {250, 120, 0})
@ -361,6 +316,7 @@ local function on_entity_died(event)
Tabs.comfy_panel_call_tab(player, "Map Scores")
end
end
local function on_built_entity(event)
local player = game.players[event.player_index]
if event.created_entity.name == "radar" then
@ -369,12 +325,14 @@ local function on_built_entity(event)
global.map_forces[player.force.name].radar[unit_number] = entity
end
end
local function on_player_mined_entity(event)
local player = game.players[event.player_index]
if event.entity.name == "radar" then
global.map_forces[player.force.name].radar[event.entity.unit_number] = nil
end
end
local function on_robot_mined_entity(event)
if event.entity.name == "radar" then
global.map_forces[event.robot.force.name].radar[event.entity.unit_number] = nil
@ -382,23 +340,33 @@ local function on_robot_mined_entity(event)
end
local function on_player_joined_game(event)
local surface = game.surfaces["native_war"]
local player = game.players[event.player_index]
local surface = game.surfaces[global.active_surface_index]
--Gui.unit_health_buttons(player)
--Gui.spectate_button(player)
--Gui.update_health_boost_buttons(player)
if player.surface.index ~= global.active_surface_index then
if player.force.name == "spectator" then
Team.set_player_to_spectator(player)
Team.teleport_player_to_active_surface(player)
return
if player.online_time == 0 then
player.spectator = true
player.force = game.forces.spectator
if surface.is_chunk_generated({0,-190}) then
player.teleport(surface.find_non_colliding_position("character", {0,-190}, 3, 0.5), surface)
else
player.teleport({0,-190}, surface)
end
Team.assign_force_to_player(player)
Team.teleport_player_to_active_surface(player)
Team.put_player_into_random_team(player)
player.character.destructible = false
game.permissions.get_group("spectator").add_player(player)
end
Map.player_joined_game(player)
Team_manager.draw_top_toggle_button(player)
end
local function on_gui_click(event)
local player = game.players[event.player_index]
local element = event.element
if not element then return end
if not element.valid then return end
if Map.gui_click(player, element) then return end
Team_manager.gui_click(event)
end
local function reveal_map(surface, force_name)
@ -436,32 +404,32 @@ end
local function tick()
local game_tick = game.tick
if game_tick == 120 then
initial_worm_turret(game.surfaces[global.active_surface_index])
randomize_worms()
initial_worm_turret(game.surfaces["native_war"])
end
if game_tick % 240 == 0 then --400 ou 200
local surface = game.surfaces[global.active_surface_index]
local surface = game.surfaces["native_war"]
reset_operable_market(surface)
local area = {{-224, -150}, {224, 150}}
game.forces.west.chart(surface, area)
game.forces.east.chart(surface, area)
Team_manager.refresh()
end
if game_tick % 480 == 0 then -- was 600
local surface = game.surfaces[global.active_surface_index]
local surface = game.surfaces["native_war"]
reveal_map(surface, "east")
end
if (game_tick+240) % 480 == 0 then -- was +300 % 600
local surface = game.surfaces[global.active_surface_index]
local surface = game.surfaces["native_war"]
reveal_map(surface, "west")
end
if game_tick % 900 == 0 then
local surface = game.surfaces[global.active_surface_index]
local surface = game.surfaces["native_war"]
for _, force_name in pairs({"west", "east"}) do
local structs = game.surfaces[global.active_surface_index].find_entities_filtered{position = global.map_forces[force_name].eei, radius = 5, type = "electric-energy-interface"}
local structs = game.surfaces["native_war"].find_entities_filtered{position = global.map_forces[force_name].eei, radius = 5, type = "electric-energy-interface"}
local energy = structs[1].energy/100000
if energy < global.map_forces[force_name].energy then
local new_global_energy = global.map_forces[force_name].energy -6
@ -473,9 +441,9 @@ local function tick()
end
end
if game_tick % 1800 == 0 then
local surface = game.surfaces[global.active_surface_index]
local surface = game.surfaces["native_war"]
for _, force_name in pairs({"west", "east"}) do
local structs = game.surfaces[global.active_surface_index].find_entities_filtered{position = global.map_forces[force_name].eei, radius = 5, type = "electric-energy-interface"}
local structs = game.surfaces["native_war"].find_entities_filtered{position = global.map_forces[force_name].eei, radius = 5, type = "electric-energy-interface"}
local energy = structs[1].energy/100000
if energy >= global.map_forces[force_name].energy + 6 then
local new_global_energy = global.map_forces[force_name].energy + 6
@ -486,15 +454,6 @@ local function tick()
end
end
end
if global.game_reset_tick then
if global.game_reset_tick < game_tick then
global.game_reset_tick = nil
Public.reset_map()
end
return
end
end
--Construction Robot Restriction
@ -567,40 +526,21 @@ local function show_color_force()
end
local function on_init()
game.difficulty_settings.technology_price_multiplier = 0.5
game.difficulty_settings.technology_price_multiplier = 1
game.map_settings.enemy_evolution.destroy_factor = 0
game.map_settings.enemy_evolution.pollution_factor = 0
game.map_settings.enemy_evolution.time_factor = 0
game.map_settings.enemy_expansion.enabled = false
game.map_settings.pollution.enabled = false
global.map_forces = {
["west"] = {},
["east"] = {},
}
local T = Map.Pop_info()
T.main_caption = "Native War"
T.sub_caption = "..nibble nibble nom nom.."
T.text = table.concat({
"Defeat the enemy teams Market.\n",
"Buy wave of biters with science on the Market!\n",
"They will soon after swarm to the opposing teams Market!\n",
"\n",
"The path is stewn with worms.\n",
"Buy new worms and upgrade them to stem the opposing waves!\n",
"\n",
--"Player turrets are disabled.\n",
"Use your experience to improve damage and resistance of your biters.\n",
"Space science pack give extra life to your biters.\n",
"Construction robots may not build over the wall.\n",
})
T.main_caption_color = {r = 150, g = 0, b = 255}
T.sub_caption_color = {r = 0, g = 250, b = 150}
Team.create_forces()
Team.set_force_attributes()
Public.reset_map()
Init.settings()
Init.surface()
Init.forces()
kill_entities_combat_zone(surface)
end
@ -618,3 +558,4 @@ event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_changed_position, on_player_changed_position)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_gui_click, on_gui_click)

View File

@ -0,0 +1,48 @@
local Public = {}
local function create_map_intro_button(player)
if player.gui.top["map_intro_button"] then return end
local b = player.gui.top.add({type = "sprite-button", caption = "?", name = "map_intro_button", tooltip = "Map Info"})
b.style.font_color = {r=0.5, g=0.3, b=0.99}
b.style.font = "heading-1"
b.style.minimal_height = 38
b.style.minimal_width = 38
b.style.top_padding = 1
b.style.left_padding = 1
b.style.right_padding = 1
b.style.bottom_padding = 1
end
local function create_map_intro(player)
if player.gui.center["map_intro_frame"] then player.gui.center["map_intro_frame"].destroy() end
local frame = player.gui.center.add {type = "frame", name = "map_intro_frame", direction = "vertical"}
local frame = frame.add {type = "frame"}
local l = frame.add {type = "label", caption = {"native_war.map_info"}, name = "native_war_map_intro"}
l.style.single_line = false
l.style.font = "heading-2"
l.style.font_color = {r=0.7, g=0.6, b=0.99}
end
function Public.player_joined_game(player)
create_map_intro_button(player)
player.print("Check the question mark button \"?\" for basic information", {255,0,0})
if player.online_time == 0 then
--create_map_intro(player)
end
end
function Public.gui_click(player, element)
if element.name == "close_map_intro_frame" then player.gui.center["map_intro_frame"].destroy() return true end
if element.name == "native_war_map_intro" then player.gui.center["map_intro_frame"].destroy() return true end
if element.name == "map_intro_button" then
if player.gui.center["map_intro_frame"] then
player.gui.center["map_intro_frame"].destroy()
return true
else
create_map_intro(player)
return true
end
end
end
return Public

View File

@ -0,0 +1,60 @@
local Public = {}
Public.wave_price = {
["automation-science-pack"] ={price = 100},
["logistic-science-pack"] ={price = 60},
["military-science-pack"] ={price = 100},
["chemical-science-pack"] ={price = 100},
["production-science-pack"] ={price = 100},
["utility-science-pack"] ={price = 80},
}
Public.upgrade_turret_price = {
["automation-science-pack"] ={price = 200},
["logistic-science-pack"] ={price = 120},
["military-science-pack"] ={price = 200},
["chemical-science-pack"] ={price = 200},
["production-science-pack"] ={price = 200},
["utility-science-pack"] ={price = 160},
}
Public.nb_of_waves = {1,5,10}
Public.science_pack = {
["automation-science-pack"] = {short = "red"},
["logistic-science-pack"] = {short = "green"},
["military-science-pack"] = {short = "grey"},
["chemical-science-pack"] = {short = "blue"},
["production-science-pack"] = {short = "purple"},
["utility-science-pack"] = {short = "yellow"},
}
Public.color = {
["automation-science-pack"] = {r=255, g=50, b=50},
["logistic-science-pack"] = {r=50, g=255, b=50},
["military-science-pack"] = {r=105, g=105, b=105},
["chemical-science-pack"] = {r=100, g=200, b=255},
["production-science-pack"] = {r=150, g=25, b=255},
["utility-science-pack"] = {r=210, g=210, b=60},
["space-science-pack"] = {r=255, g=255, b=255},
["message"] = {r = 0.98, g = 0.66, b = 0.22},
}
Public.worm_dist = {"Closest","Farthest","All"}
Public.button_upgrade_name={
["red_Closest"] = {sp = "automation-science-pack", spc = "red", dist = "Closest", type_worm = "small"},
["green_Closest"] = {sp = "logistic-science-pack", spc = "green", dist = "Closest", type_worm = "small"},
["grey_Closest"] = {sp = "military-science-pack", spc = "grey", dist = "Closest", type_worm = "medium"},
["blue_Closest"] = {sp = "chemical-science-pack", spc = "blue", dist = "Closest", type_worm = "big"},
["purple_Closest"] = {sp = "production-science-pack", spc = "purple", dist = "Closest", type_worm = "behemoth"},
["yellow_Closest"] = {sp = "utility-science-pack", spc = "yellow", dist = "Closest", type_worm = "behemoth"},
["red_Farthest"] = {sp = "automation-science-pack", spc = "red", dist = "Farthest", type_worm = "small"},
["green_Farthest"] = {sp = "logistic-science-pack", spc = "green", dist = "Furthest", type_worm = "small"},
["grey_Farthest"] = {sp = "military-science-pack", spc = "grey", dist = "Farthest", type_worm = "medium"},
["blue_Farthest"] = {sp = "chemical-science-pack", spc = "blue", dist = "Furthest", type_worm = "big"},
["purple_Farthest"] = {sp = "production-science-pack", spc = "purple", dist = "Farthest", type_worm = "behemoth"},
["yellow_Farthest"] = {sp = "utility-science-pack", spc = "yellow", dist = "Furthest", type_worm = "behemoth"},
["red_All"] = {sp = "automation-science-pack", spc = "red", dist = "All", type_worm = "small"},
["green_All"] = {sp = "logistic-science-pack", spc = "green", dist = "All", type_worm = "small"},
["grey_All"] = {sp = "military-science-pack", spc = "grey", dist = "All", type_worm = "medium"},
["blue_All"] = {sp = "chemical-science-pack", spc = "blue", dist = "All", type_worm = "big"},
["purple_All"] = {sp = "production-science-pack", spc = "purple", dist = "All", type_worm = "behemoth"},
["yellow_All"] = {sp = "utility-science-pack", spc = "yellow", dist = "All", type_worm = "behemoth"},
}
Public.science_pack_name = {"automation-science-pack", "logistic-science-pack", "military-science-pack", "chemical-science-pack", "production-science-pack", "utility-science-pack"}
return Public

View File

@ -1,191 +1,10 @@
local Public = {}
local math_random = math.random
Public.starting_items = {['iron-plate'] = 32, ['iron-gear-wheel'] = 16, ['stone'] = 25, ['radar'] = 25, ["automation-science-pack"]= 2000, ["logistic-science-pack"]= 2000, ["military-science-pack"]= 2000, ["chemical-science-pack"]= 2000}
function Public.set_force_attributes()
game.forces.west.set_friend("spectator", true)
game.forces.east.set_friend("spectator", true)
game.forces.spectator.set_friend("west", true)
game.forces.spectator.set_friend("east", true)
for _, force_name in pairs({"west", "east"}) do
game.forces[force_name].share_chart = true
game.forces[force_name].research_queue_enabled = true
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["land-mine"].enabled = false
local force_index = game.forces[force_name].index
global.map_forces[force_name].unit_health_boost = 1
global.map_forces[force_name].unit_count = 0
global.map_forces[force_name].units = {}
global.map_forces[force_name].radar = {}
global.map_forces[force_name].max_unit_count = 768
global.map_forces[force_name].player_count = 0
global.map_forces[force_name].ate_buffer_potion = {
["automation-science-pack"] = 0,
["logistic-science-pack"]= 0,
["military-science-pack"]= 0,
["chemical-science-pack"]= 0,
["production-science-pack"]= 0,
["utility-science-pack"]= 0
}
if force_name == "west" then
global.map_forces[force_name].worm_turrets_positions = {
[1] = {x=-127,y=-38},
[2] = {x=-112,y=-38},
[3] = {x=-127,y=-70},
[4] = {x=-112,y=-70},
[5] = {x=-127,y=-102},
[6] = {x=-112,y=-102},
[7] = {x=-90,y=-119},
[8] = {x=-90,y=-136},
[9] = {x=-70,y=-90},
[10] = {x=-50,y=-90},
[11] = {x=-70,y=-58},
[12] = {x=-50,y=-58},
[13] = {x=-70,y=-26},
[14] = {x=-50,y=-26},
[15] = {x=-70,y=0},
[16] = {x=-50,y=0},
[17] = {x=-70,y=36},
[18] = {x=-50,y=36},
[19] = {x=-70,y=68},
[20] = {x=-50,y=68},
[21] = {x=-70,y=100},
[22] = {x=-50,y=100},
[23] = {x=-30,y=119},
[24] = {x=-30,y=136},
[25] = {x=-9,y=90},
[26] = {x=9,y=90},
[27] = {x=-9,y=59},
[28] = {x=9,y=59},
[29] = {x=-9,y=27},
[30] = {x=9,y=27}
}
global.map_forces[force_name].modifier ={damage = 1, resistance = 1, splash = 1}
global.map_forces[force_name].spawn = {x=-137,y=0}
global.biter_reanimator.forces[force_index] = 0
global.map_forces[force_name].eei = {x=-200,y=0}
global.map_forces[force_name].energy = 0
else
global.map_forces[force_name].worm_turrets_positions ={
[1] = {x=127,y=38},
[2] = {x=112,y=38},
[3] = {x=127,y=70},
[4] = {x=112,y=70},
[5] = {x=127,y=102},
[6] = {x=112,y=102},
[7] = {x=90,y=119},
[8] = {x=90,y=136},
[9] = {x=70,y=90},
[10] = {x=50,y=90},
[11] = {x=70,y=58},
[12] = {x=50,y=58},
[13] = {x=70,y=26},
[14] = {x=50,y=26},
[15] = {x=70,y=0},
[16] = {x=50,y=0},
[17] = {x=70,y=-36},
[18] = {x=50,y=-36},
[19] = {x=70,y=-68},
[20] = {x=50,y=-68},
[21] = {x=70,y=-100},
[22] = {x=50,y=-100},
[23] = {x=30,y=-119},
[24] = {x=30,y=-136},
[25] = {x=-9,y=-90},
[26] = {x=9,y=-90},
[27] = {x=9,y=-59},
[28] = {x=-9,y=-59},
[29] = {x=9,y=-27},
[30] = {x=-9,y=-27}
}
global.map_forces[force_name].modifier ={damage = 1, resistance = 1, splash = 1}
global.map_forces[force_name].spawn = {x=137,y=0}
global.map_forces[force_name].eei = {x=201,y=0}
global.biter_reanimator.forces[force_index] = 0
global.map_forces[force_name].energy = 0
end
end
end
function Public.create_forces()
game.create_force("west")
game.create_force("east")
game.create_force("spectator")
end
function Public.add_unit(force_name,unit_number, unit)
global.map_forces[force_name].units[unit_number] = unit
end
function Public.assign_random_force_to_active_players()
local player_indexes = {}
for _, player in pairs(game.connected_players) do
if player.force.name ~= "spectator" then player_indexes[#player_indexes + 1] = player.index end
end
if #player_indexes > 1 then table.shuffle_table(player_indexes) end
local a = math_random(0, 1)
for key, player_index in pairs(player_indexes) do
if key % 2 == a then
game.players[player_index].force = game.forces.west
else
game.players[player_index].force = game.forces.east
end
end
end
function Public.assign_force_to_player(player)
player.spectator = false
if math_random(1, 2) == 1 then
if #game.forces.east.connected_players > #game.forces.west.connected_players then
player.force = game.forces.west
else
player.force = game.forces.east
end
else
if #game.forces.east.connected_players < #game.forces.west.connected_players then
player.force = game.forces.east
else
player.force = game.forces.west
end
end
end
function Public.teleport_player_to_active_surface(player)
local surface = game.surfaces[global.active_surface_index]
local position
if player.force.name == "spectator" then
position = player.force.get_spawn_position(surface)
position = {x = (position.x - 160) + math_random(0, 320), y = (position.y - 16) + math_random(0, 32)}
else
position = surface.find_non_colliding_position("character", player.force.get_spawn_position(surface), 48, 1)
if not position then position = player.force.get_spawn_position(surface) end
end
player.teleport(position, surface)
end
function Public.put_player_into_random_team(player)
if player.character then
if player.character.valid then
player.character.destroy()
end
end
player.character = nil
player.set_controller({type=defines.controllers.god})
player.create_character()
for item, amount in pairs(Public.starting_items) do
player.insert({name = item, count = amount})
end
global.map_forces[player.force.name].player_count = global.map_forces[player.force.name].player_count + 1
end
function Public.set_player_to_spectator(player)
if player.character then player.character.die() end
player.force = game.forces.spectator
player.character = nil
player.spectator = true
player.set_controller({type=defines.controllers.spectator})
end
function Public.on_buy_wave(surface, force, tier)
if tier == "red" or tier == "green" then
@ -248,7 +67,9 @@ function Public.buy_worm_turret(surface,force_name, dist, player, player_nb_sp,
if turret == nil and player_sp_count >= nb_sp_price then
local turrets = surface.find_entities_filtered{position = {pos.x,pos.y}, name ={'medium-worm-turret','big-worm-turret','behemoth-worm-turret'}}
if #turrets ==0 then
surface.create_entity({name = "small-worm-turret", position = {pos.x,pos.y}, force = force_name})
local position = surface.find_non_colliding_position("big-worm-turret", {pos.x,pos.y}, 5, 1)
if not position then position = {pos.x,pos.y} end
surface.create_entity({name = "small-worm-turret", position = {position.x,position.y}, force = force_name})
player.remove_item({name=sp, count=nb_sp_price})
player_sp_count = player_sp_count - nb_sp_price
count = count + 1
@ -267,7 +88,9 @@ function Public.buy_worm_turret(surface,force_name, dist, player, player_nb_sp,
if turret == nil and player_nb_sp >= nb_sp_price then
local turrets = surface.find_entities_filtered{position = {pos.x,pos.y}, name ={'medium-worm-turret','big-worm-turret','behemoth-worm-turret'}}
if #turrets ==0 then
surface.create_entity({name = "small-worm-turret", position = {pos.x,pos.y}, force = force_name})
local position = surface.find_non_colliding_position("big-worm-turret", {pos.x,pos.y}, 5, 1)
if not position then position = {pos.x,pos.y} end
surface.create_entity({name = "small-worm-turret", position = {position.x,position.y}, force = force_name})
player.remove_item({name=sp, count=nb_sp_price})
return true
end
@ -281,7 +104,9 @@ function Public.buy_worm_turret(surface,force_name, dist, player, player_nb_sp,
if turret == nil and player_nb_sp >= nb_sp_price then
local turrets = surface.find_entities_filtered{position = {pos.x,pos.y}, name ={'medium-worm-turret','big-worm-turret','behemoth-worm-turret'}}
if #turrets ==0 then
surface.create_entity({name = "small-worm-turret", position = {pos.x,pos.y}, force = force_name})
local position = surface.find_non_colliding_position("big-worm-turret", {pos.x,pos.y}, 5, 1)
if not position then position = {pos.x,pos.y} end
surface.create_entity({name = "small-worm-turret", position = {position.x,position.y}, force = force_name})
player.remove_item({name=sp, count=nb_sp_price})
return true
end
@ -306,7 +131,9 @@ function Public.upgrade_worm_turret(surface, force_name, dist, player, player_nb
local turret = surface.find_entity(table_upgrade[tier],{pos.x,pos.y})
if turret ~= nil and player_nb_sp >= nb_sp_price then
turret.destroy()
surface.create_entity({name = tier, position = {pos.x,pos.y}, force = force_name})
local position = surface.find_non_colliding_position("big-worm-turret", {pos.x,pos.y}, 5, 1)
if not position then position = {pos.x,pos.y} end
surface.create_entity({name = tier, position = {position.x,position.y}, force = force_name})
player.remove_item({name=sp, count=nb_sp_price})
player_sp_count = player_sp_count - nb_sp_price
count = count + 1
@ -322,7 +149,9 @@ function Public.upgrade_worm_turret(surface, force_name, dist, player, player_nb
local turret = surface.find_entity(table_upgrade[tier],{global.map_forces[force_name].worm_turrets_positions[i].x,global.map_forces[force_name].worm_turrets_positions[i].y})
if turret ~= nil and player_nb_sp >= nb_sp_price then
turret.destroy()
surface.create_entity({name = tier, position = {global.map_forces[force_name].worm_turrets_positions[i].x,global.map_forces[force_name].worm_turrets_positions[i].y}, force = force_name})
local position = surface.find_non_colliding_position("big-worm-turret", {global.map_forces[force_name].worm_turrets_positions[i].x,global.map_forces[force_name].worm_turrets_positions[i].y}, 5, 1)
if not position then position = {pos.x,pos.y} end
surface.create_entity({name = tier, position = {position.x,position.y}, force = force_name})
player.remove_item({name=sp, count=nb_sp_price})
return true
else end
@ -333,7 +162,9 @@ function Public.upgrade_worm_turret(surface, force_name, dist, player, player_nb
local turret = surface.find_entity(table_upgrade[tier],{pos.x,pos.y})
if turret ~= nil and player_nb_sp >= nb_sp_price then
turret.destroy()
surface.create_entity({name = tier, position = {pos.x,pos.y}, force = force_name})
local position = surface.find_non_colliding_position("big-worm-turret", {pos.x,pos.y}, 5, 1)
if not position then position = {pos.x,pos.y} end
surface.create_entity({name = tier, position = {position.x,position.y}, force = force_name})
player.remove_item({name=sp, count=nb_sp_price})
return true
else end

View File

@ -0,0 +1,686 @@
local Public = {}
local wait_messages = {
"please get comfy.",
"get comfy!!",
"go and grab a drink.",
"take a short healthy break.",
"go and stretch your legs.",
"please pet the cat.",
"time to get a bowl of snacks :3",
"send love to Mewmew",
}
local forces = {
{name = "west", color = {r = 1, g = 1, b = 255}},
{name = "spectator", color = {r = 111, g = 111, b = 111}},
{name = "east", color = {r = 255, g = 1, b = 1}},
}
local gui_values = {
["west"] = {force = "west", c1 = "west", c2 = "JOIN ", n1 = "join_west_button",
color1 = {r = 1, g = 1, b = 255}, color2 = {r = 0.66, g = 0.66, b = 0.99}}, --tech_spy = "spy-north-tech", prod_spy = "spy-north-prod"
["east"] = {force = "east", c1 = "east", c2 = "JOIN ", n1 = "join_east_button",
color1 = {r = 255, g = 1, b = 1}, color2 = {r = 0.99, g = 0.44, b = 0.44}} --tech_spy = "spy-north-tech", prod_spy = "spy-north-prod"
}
starting_items = {['iron-plate'] = 32, ['iron-gear-wheel'] = 16, ['stone'] = 25}
local function get_player_array(force_name)
local a = {}
for _, p in pairs(game.forces[force_name].connected_players) do a[#a + 1] = p.name end
return a
end
local function freeze_players()
if not global.freeze_players then return end
global.team_manager_default_permissions = {}
local p = game.permissions.get_group("Default")
for action_name, _ in pairs(defines.input_action) do
global.team_manager_default_permissions[action_name] = p.allows_action(defines.input_action[action_name])
p.set_allows_action(defines.input_action[action_name], false)
end
local defs = {
defines.input_action.write_to_console,
defines.input_action.gui_click,
defines.input_action.gui_selection_state_changed,
defines.input_action.gui_checked_state_changed ,
defines.input_action.gui_elem_changed,
defines.input_action.gui_text_changed,
defines.input_action.gui_value_changed,
defines.input_action.edit_permission_group,
}
for _, d in pairs(defs) do p.set_allows_action(d, true) end
end
local function unfreeze_players()
local p = game.permissions.get_group("Default")
for action_name, _ in pairs(defines.input_action) do
if global.team_manager_default_permissions[action_name] then
p.set_allows_action(defines.input_action[action_name], true)
end
end
end
local function leave_corpse(player)
if not player.character then return end
local inventories = {
player.get_inventory(defines.inventory.character_main),
player.get_inventory(defines.inventory.character_guns),
player.get_inventory(defines.inventory.character_ammo),
player.get_inventory(defines.inventory.character_armor),
player.get_inventory(defines.inventory.character_vehicle),
player.get_inventory(defines.inventory.character_trash),
}
local corpse = false
for _, i in pairs(inventories) do
for index = 1, #i, 1 do
if not i[index].valid then break end
corpse = true
break
end
if corpse then
player.character.die()
break
end
end
if player.character then player.character.destroy() end
player.character = nil
player.set_controller({type=defines.controllers.god})
player.create_character()
end
local function switch_force(player_name, force_name)
if not game.players[player_name] then game.print("Team Manager >> Player " .. player_name .. " does not exist.", {r=0.98, g=0.66, b=0.22}) return end
if not game.forces[force_name] then game.print("Team Manager >> Force " .. force_name .. " does not exist.", {r=0.98, g=0.66, b=0.22}) return end
local player = game.players[player_name]
player.force = game.forces[force_name]
game.print(player_name .. " has been switched into team " .. force_name .. ".", {r=0.98, g=0.66, b=0.22})
leave_corpse(player)
global.chosen_team[player_name] = nil
if force_name == "spectator" then
spectate(player, true)
else
join_team(player, force_name, true)
end
end
local function create_first_join_gui(player)
if not global.game_lobby_timeout then global.game_lobby_timeout = 10 end --[[5999940]]
if global.game_lobby_timeout - game.tick < 0 then global.game_lobby_active = false end
local frame = player.gui.left.add { type = "frame", name = "nv_main_gui", direction = "vertical" }
local b = frame.add{ type = "label", caption = "Defend your Market!" }
b.style.font = "heading-1"
b.style.font_color = {r=0.98, g=0.66, b=0.22}
local b = frame.add { type = "label", caption = "Feed the market with science to send native waves!" }
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
--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}
l.style.font = "heading-2"
l.style.font_color = gui_value.color1
l.style.single_line = false
l.style.maximal_width = 290
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_color = { r=0.22, g=0.88, b=0.22}
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 }
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
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
local function create_main_gui(player)
local is_spec = player.force.name == "spectator"
if player.gui.left["nv_main_gui"] then player.gui.left["nv_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)
return
end
end
local frame = player.gui.left.add { type = "frame", name = "nv_main_gui", direction = "vertical" }
-- Science sending GUI
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}
l.style.font = "default-bold"
l.style.font_color = gui_value.color1
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}
-- Player list
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
-- Statistics
--local t = frame.add { type = "table", name = "stats_" .. gui_value.force, column_count = 6 }
-- 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 }
-- Spectate / Rejoin team
if is_spec then
local b = t.add { type = "sprite-button", name = "nv_leave_spectate", caption = "Join Team" }
else
local b = t.add { type = "sprite-button", name = "nv_spectate", caption = "Spectate" }
end
-- Playerlist button
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}
b.style.top_padding = 1
b.style.left_padding = 1
b.style.right_padding = 1
b.style.bottom_padding = 1
b.style.maximal_height = 30
b.style.width = b_width
end
end
function Public.refresh()
for _, player in pairs(game.connected_players) do
if player.gui.left["nv_main_gui"] then
create_main_gui(player)
end
end
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
end
if not force_name then return end
local surface = player.surface
local enemy_team = "west"
if force_name == "west" then enemy_team = "east" end
if not global.training_mode and global.nv_settings.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
player.print("Team " .. force_name .. " has too many players currently.", {r = 0.98, g = 0.66, b = 0.22})
return
end
end
end
end
if global.chosen_team[player.name] then
if not forced_join then
if game.tick - global.spectator_rejoin_delay[player.name] < 7200 then
player.print(
"Not ready to return to your team yet. Please wait " .. 120-(math.floor((game.tick - global.spectator_rejoin_delay[player.name])/60)) .. " seconds.",
{r = 0.98, g = 0.66, b = 0.22}
)
return
end
end
local p = surface.find_non_colliding_position("character", game.forces[force_name].get_spawn_position(surface), 8, 1)
player.teleport(p, surface)
player.force = game.forces[force_name]
player.character.destructible = true
Public.refresh()
game.permissions.get_group("Default").add_player(player)
local msg = table.concat({"Team ", player.force.name, " player ", player.name, " is no longer spectating."})
game.print(msg, {r = 0.98, g = 0.66, b = 0.22})
--Server.to_discord_bold(msg)
player.spectator = false
return
end
local pos = surface.find_non_colliding_position("character", game.forces[force_name].get_spawn_position(surface), 8, 1)
if not pos then pos = game.forces[force_name].get_spawn_position(surface) end
player.teleport(pos)
player.force = game.forces[force_name]
player.character.destructible = true
game.permissions.get_group("Default").add_player(player)
if not forced_join then
local c = player.force.name
--if global.tm_custom_name[player.force.name] then c = global.tm_custom_name[player.force.name] end
local message = table.concat({player.name, " has joined team ", c, "!"})
game.print(message, {r = 0.98, g = 0.66, b = 0.22})
--Server.to_discord_bold(message)
end
local i = player.get_inventory(defines.inventory.character_main)
i.clear()
for item, amount in pairs(starting_items) do
player.insert({name = item, count = amount})
end
global.chosen_team[player.name] = force_name
player.spectator = false
Public.refresh()
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
end
player.teleport(player.surface.find_non_colliding_position("character", {0,-190}, 4, 1))
player.force = game.forces.spectator
player.character.destructible = false
if not forced_join then
local msg = player.name .. " is spectating."
game.print(msg, {r = 0.98, g = 0.66, b = 0.22})
--Server.to_discord_bold(msg)
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
function Public.draw_top_toggle_button(player)
if player.gui.top["team_manager_toggle_button"] then player.gui.top["team_manager_toggle_button"].destroy() end
local button = player.gui.top.add({type = "sprite-button", name = "team_manager_toggle_button", caption = "Team Manager", tooltip = tooltip})
button.style.font = "heading-2"
button.style.font_color = {r = 0.88, g = 0.55, b = 0.11}
button.style.minimal_height = 38
button.style.minimal_width = 120
button.style.top_padding = 2
button.style.left_padding = 0
button.style.right_padding = 0
button.style.bottom_padding = 2
end
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
for i = 1, #forces * 2 - 1, 1 do
if i % 2 == 1 then
local l = t.add({type = "sprite-button", caption = string.upper(forces[i2].name), name = forces[i2].name})
l.style.minimal_width = 160
l.style.maximal_width = 160
l.style.font_color = forces[i2].color
l.style.font = "heading-1"
i2 = i2 + 1
else
local tt = t.add({type = "label", caption = " "})
end
end
local i2 = 1
for i = 1, #forces * 2 - 1, 1 do
if i % 2 == 1 then
local list_box = t.add({type = "list-box", name = "team_manager_list_box_" .. i2, items = get_player_array(forces[i2].name)})
list_box.style.minimal_height = 360
list_box.style.minimal_width = 160
list_box.style.maximal_height = 480
i2 = i2 + 1
else
local tt = t.add({type = "table", column_count = 1})
local b = tt.add({type = "sprite-button", name = i2 - 1, caption = ""})
b.style.font = "heading-1"
b.style.maximal_height = 38
b.style.maximal_width = 38
local b = tt.add({type = "sprite-button", name = i2, caption = ""})
b.style.font = "heading-1"
b.style.maximal_height = 38
b.style.maximal_width = 38
end
end
frame.add({type = "label", caption = ""})
local t = frame.add({type = "table", name = "team_manager_bottom_buttons", column_count = 4})
local button = t.add({
type = "button",
name = "team_manager_close",
caption = "Close",
tooltip = "Close this window."
})
button.style.font = "heading-2"
if global.tournament_mode then
button = t.add({
type = "button",
name = "team_manager_activate_tournament",
caption = "Tournament Mode Enabled",
tooltip = "Only admins can move players and vote for difficulty.\nActive players can no longer go spectate.\nNew joining players are spectators."
})
button.style.font_color = {r = 222, g = 22, b = 22}
else
button = t.add({
type = "button",
name = "team_manager_activate_tournament",
caption = "Tournament Mode Disabled",
tooltip = "Only admins can move players. Active players can no longer go spectate. New joining players are spectators."
})
button.style.font_color = {r = 55, g = 55, b = 55}
end
button.style.font = "heading-2"
if global.freeze_players then
button = t.add({
type = "button",
name = "team_manager_freeze_players",
caption = "Unfreeze Players",
tooltip = "Releases all players."
})
button.style.font_color = {r = 222, g = 22, b = 22}
else
button = t.add({
type = "button",
name = "team_manager_freeze_players",
caption = "Freeze Players",
tooltip = "Freezes all players, unable to perform actions, until released."
})
button.style.font_color = {r = 55, g = 55, b = 222}
end
button.style.font = "heading-2"
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
local function set_custom_team_name(force_name, team_name)
if team_name == "" then global.tm_custom_name[force_name] = nil return end
if not team_name then global.tm_custom_name[force_name] = nil return end
global.tm_custom_name[force_name] = tostring(team_name)
end
local function custom_team_name_gui(player, force_name)
if player.gui.center["custom_team_name_gui"] then player.gui.center["custom_team_name_gui"].destroy() return end
local frame = player.gui.center.add({type = "frame", name = "custom_team_name_gui", caption = "Set custom team name:", direction = "vertical"})
local text = force_name
if global.tm_custom_name[force_name] then text = global.tm_custom_name[force_name] end
local textfield = frame.add({ type = "textfield", name = force_name, text = text })
local t = frame.add({type = "table", column_count = 2})
local button = t.add({
type = "button",
name = "custom_team_name_gui_set",
caption = "Set",
tooltip = "Set custom team name."
})
button.style.font = "heading-2"
local button = t.add({
type = "button",
name = "custom_team_name_gui_close",
caption = "Close",
tooltip = "Close this window."
})
button.style.font = "heading-2"
end
local function team_manager_gui_click(event)
local player = game.players[event.player_index]
local name = event.element.name
if game.forces[name] then
if not player.admin then player.print("Only admins can change team names.", {r = 175, g = 0, b = 0}) return end
custom_team_name_gui(player, name)
player.gui.center["team_manager_gui"].destroy()
return
end
if name == "team_manager_close" then
player.gui.center["team_manager_gui"].destroy()
return
end
if name == "team_manager_activate_tournament" then
if not player.admin then player.print("Only admins can switch tournament mode.", {r = 175, g = 0, b = 0}) return end
if global.tournament_mode then
global.tournament_mode = false
draw_manager_gui(player)
game.print(">>> Tournament Mode has been disabled.", {r = 111, g = 111, b = 111})
return
end
global.tournament_mode = true
draw_manager_gui(player)
game.print(">>> Tournament Mode has been enabled!", {r = 225, g = 0, b = 0})
return
end
if name == "team_manager_freeze_players" then
if global.freeze_players then
if not player.admin then player.print("Only admins can unfreeze players.", {r = 175, g = 0, b = 0}) return end
global.freeze_players = false
draw_manager_gui(player)
game.print(">>> Players have been unfrozen!", {r = 255, g = 77, b = 77})
unfreeze_players()
return
end
if not player.admin then player.print("Only admins can freeze players.", {r = 175, g = 0, b = 0}) return end
global.freeze_players = true
draw_manager_gui(player)
game.print(">>> Players have been frozen!", {r = 111, g = 111, b = 255})
freeze_players()
return
end
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
if not event.element.parent then return end
local element = event.element.parent
if not element.parent then return end
local element = element.parent
if element.name ~= "team_manager_root_table" then return end
if not player.admin then player.print("Only admins can manage teams.", {r = 175, g = 0, b = 0}) return end
local listbox = player.gui.center["team_manager_gui"]["team_manager_root_table"]["team_manager_list_box_" .. tonumber(name)]
local selected_index = listbox.selected_index
if selected_index == 0 then player.print("No player selected.", {r = 175, g = 0, b = 0}) return end
local player_name = listbox.items[selected_index]
local m = -1
if event.element.caption == "" then m = 1 end
local force_name = forces[tonumber(name) + m].name
switch_force(player_name, force_name)
draw_manager_gui(player)
end
local function create_sprite_button(player)
if player.gui.top["nv_toggle_button"] then return end
local button = player.gui.top.add({type = "sprite-button", name = "nv_toggle_button", sprite = "item/splitter"})
button.style.font = "default-bold"
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.top_padding = 2
button.style.left_padding = 4
button.style.right_padding = 4
button.style.bottom_padding = 2
end
local function join_gui_click(name, player)
local team = {
["join_west_button"] = "west",
["join_east_button"] = "east"
}
if not team[name] then return end
if global.game_lobby_active then
if player.admin then
join_team(player, team[name])
game.print("Lobby disabled, admin override.", { r=0.98, g=0.66, b=0.22})
global.game_lobby_active = false
return
end
player.print("Waiting for more players, " .. wait_messages[math_random(1, #wait_messages)], { r=0.98, g=0.66, b=0.22})
return
end
join_team(player, team[name])
end
function Public.gui_click(event)
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.player_index]
local name = event.element.name
if name == "team_manager_toggle_button" then
if player.gui.center["team_manager_gui"] then player.gui.center["team_manager_gui"].destroy() return end
draw_manager_gui(player)
return
end
if player.gui.center["team_manager_gui"] then team_manager_gui_click(event) end
--[[if player.gui.center["custom_team_name_gui"] then
if name == "custom_team_name_gui_set" then
local custom_name = player.gui.center["custom_team_name_gui"].children[1].text
local force_name = player.gui.center["custom_team_name_gui"].children[1].name
set_custom_team_name(force_name, custom_name)
player.gui.center["custom_team_name_gui"].destroy()
draw_manager_gui(player)
return
end
if name == "custom_team_name_gui_close" then
player.gui.center["custom_team_name_gui"].destroy()
draw_manager_gui(player)
return
end
end]]
end
local function on_gui_click(event)
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.player_index]
local name = event.element.name
if name == "nv_toggle_button" then
if player.gui.left["nv_main_gui"] then
player.gui.left["nv_main_gui"].destroy()
else
create_main_gui(player)
end
return
end
if name == "join_west_button" then join_gui_click(name, player) return end
if name == "join_east_button" then join_gui_click(name, player) return end
if name == "nv_leave_spectate" then join_team(player, global.chosen_team[player.name]) end
if name == "nv_spectate" then spectate(player) return 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(1 / #game.connected_players) --EVL
--global.game_lobby_timeout = math.ceil(36000 / #game.connected_players)
else
global.game_lobby_timeout = 1 --EVL
--global.game_lobby_timeout = 599940
end
if not global.chosen_team[player.name] then
if global.tournament_mode then
player.force = game.forces.spectator
else
player.force = game.forces.player
end
end
create_sprite_button(player)
create_main_gui(player)
end
function Public.init()
global.tm_custom_name = {}
end
local event = require 'utils.event'
event.add(defines.events.on_gui_click, on_gui_click)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
return Public

View File

@ -186,55 +186,6 @@ local function first_ore_generate(surface)
end
end
function Public.create_mirror_surface()
if game.surfaces["mirror_terrain"] then return end
local map_gen_settings = {}
map_gen_settings.seed = math_random(1, 99999999)
map_gen_settings.water = math.random(5, 10) * 0.025
map_gen_settings.starting_area = 1
map_gen_settings.terrain_segmentation = 8
map_gen_settings.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["stone"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["copper-ore"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["iron-ore"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["uranium-ore"] = {frequency = 2, size = 1, richness = 1},
["crude-oil"] = {frequency = 3, size = 1, richness = 0.75},
["trees"] = {frequency = math_random(5, 12) * 0.1, size = math_random(5, 12) * 0.1, richness = math_random(1, 10) * 0.1},
["enemy-base"] = {frequency = 0, size = 0, richness = 0}
}
local surface = game.create_surface("mirror_terrain", map_gen_settings)
local x = hatchery_position.x - 16
local offset = 38
surface.request_to_generate_chunks({x, 0}, 5)
surface.force_generate_chunk_requests()
local positions = {{x = x, y = offset}, {x = x, y = offset * -1}, {x = x, y = offset * -2}, {x = x, y = offset * 2}}
table.shuffle_table(positions)
for key, ore in pairs({"copper-ore", "iron-ore", "coal", "stone"}) do
Map_functions.draw_smoothed_out_ore_circle(surface.find_non_colliding_position("coal", positions[key], 128, 1), ore, surface, 15, 2500)
end
local r = 32
for x = r * -1, r, 1 do
for y = r * -1, r, 1 do
local p = {x = hatchery_position.x + x, y = hatchery_position.y + y}
if math.sqrt(x ^ 2 + y ^ 2) < r then
local tile = surface.get_tile(p)
if tile.name == "water" or tile.name == "deepwater" then
surface.set_tiles({{name = "landfill", position = p}}, true)
end
end
end
end
end
local function mirror_chunk(event, source_surface, x_modifier)
local surface = event.surface
local left_top = event.area.left_top

View File

@ -45,13 +45,15 @@ local xp_yield = {
}
local function gain_xp(player, amount)
amount = math.round(amount, 2)
xp_t[player.index].xp = xp_t[player.index].xp + amount
xp_t[player.index].xp_since_last_floaty_text = xp_t[player.index].xp_since_last_floaty_text + amount
if xp_t[player.index].last_floaty_text > game.tick then return end
player.create_local_flying_text{text="+" .. xp_t[player.index].xp_since_last_floaty_text .. " xp", position=player.position, color=xp_floating_text_color, time_to_live=120, speed=2}
xp_t[player.index].xp_since_last_floaty_text = 0
xp_t[player.index].last_floaty_text = game.tick + visuals_delay
if not player.force == "spectator" then
amount = math.round(amount, 2)
xp_t[player.index].xp = xp_t[player.index].xp + amount
xp_t[player.index].xp_since_last_floaty_text = xp_t[player.index].xp_since_last_floaty_text + amount
if xp_t[player.index].last_floaty_text > game.tick then return end
player.create_local_flying_text{text="+" .. xp_t[player.index].xp_since_last_floaty_text .. " xp", position=player.position, color=xp_floating_text_color, time_to_live=120, speed=2}
xp_t[player.index].xp_since_last_floaty_text = 0
xp_t[player.index].last_floaty_text = game.tick + visuals_delay
end
end
function Public.xp_reset_player(player)
if not player.character then