mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-07 13:31:40 +02:00
Add files via upload
This commit is contained in:
parent
7b47c7c9f4
commit
45323c528c
461
maps/native_war/gui.lua
Normal file
461
maps/native_war/gui.lua
Normal file
@ -0,0 +1,461 @@
|
||||
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 button_science_name={}
|
||||
for _ ,nbw in pairs(nb_of_waves) do
|
||||
for k,sp in pairs(Public.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")
|
||||
local player_green_science_pack = player_inventory.get_item_count("logistic-science-pack")
|
||||
local player_grey_science_pack = player_inventory.get_item_count("military-science-pack")
|
||||
local player_blue_science_pack = player_inventory.get_item_count("chemical-science-pack")
|
||||
local player_purple_science_pack = player_inventory.get_item_count("production-science-pack")
|
||||
local player_yellow_science_pack = player_inventory.get_item_count("utility-science-pack")
|
||||
local player_white_science_pack = player_inventory.get_item_count("space-science-pack")
|
||||
|
||||
|
||||
local root = player.gui.screen
|
||||
local frame = root.add({type = "frame", name = "market_frame", caption = "Market",direction = "vertical"})
|
||||
frame.style.font = "default"
|
||||
frame.style.font_color = {r = 0.3, g = 0.65, b = 0.3}
|
||||
frame.style.horizontal_align = "center"
|
||||
frame.add({type = "label", caption="Buy waves of biter/spitter"})
|
||||
local line = frame.add({type = "line", direction = "horizontal"})
|
||||
local table = frame.add({type = "table", column_count = 5, draw_horizontal_lines = true, draw_vertical_lines = true})
|
||||
local case = table.add({type = "sprite", sprite="file/graphics/vide.png"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite = "entity/small-biter"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite = "entity/medium-biter"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite = "entity/big-biter"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite = "entity/behemoth-biter"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
|
||||
for _, nb in pairs(nb_of_waves) do
|
||||
local wave_nb = nb
|
||||
local text_wave =""
|
||||
if wave_nd == 1 then
|
||||
text_wave = wave_nb.." wave"
|
||||
else
|
||||
text_wave = wave_nb.." waves"
|
||||
end
|
||||
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.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.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.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.style.right_padding = 12
|
||||
case.style.left_padding = 12
|
||||
end
|
||||
|
||||
local line = frame.add({type = "line", direction = "horizontal"})
|
||||
frame.add({type = "label", caption="Buy/ugrade worm turret"})
|
||||
|
||||
local table = frame.add({type = "table", column_count = 5, draw_horizontal_lines = true, draw_vertical_lines = true})
|
||||
local case = table.add({type = "sprite", sprite="file/graphics/vide.png"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite = "entity/small-worm-turret"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite = "entity/medium-worm-turret"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite = "entity/big-worm-turret"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite = "entity/behemoth-worm-turret"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
|
||||
for _, dist in pairs(worm_dist) do
|
||||
local turret = ""
|
||||
if dist == "all" then
|
||||
turret = "turrets"
|
||||
else
|
||||
turret = "turret"
|
||||
end
|
||||
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.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.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.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.style.right_padding = 12
|
||||
case.style.left_padding = 12
|
||||
end
|
||||
|
||||
local line = frame.add({type = "line", direction = "horizontal"})
|
||||
frame.add({type = "label", caption="Upgrade biter"})
|
||||
local table = frame.add({type = "table", column_count = 5, draw_horizontal_lines = true, draw_vertical_lines = true})
|
||||
local case = table.add({type = "sprite", sprite="file/graphics/vide.png"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite="file/graphics/Splash.png"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite="file/graphics/resist.png"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite="file/graphics/griffe.png"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
local case = table.add({type = "sprite", sprite="file/graphics/life.png"})
|
||||
case.style.horizontal_align = "center"
|
||||
case.style.right_padding = 30
|
||||
case.style.left_padding = 30
|
||||
|
||||
local xp_t = XP.get_table()
|
||||
local xp_available = xp_t[player.index].xp
|
||||
|
||||
local case = table.add({type = "flow", direction = "vertical"})
|
||||
case.add({type = "label", caption="Available XP :"})
|
||||
case.add({type = "label", caption=math.floor(xp_available)})
|
||||
local case = table.add({type = "flow", direction = "horizontal"})
|
||||
local b = case.add({type = "button", name = "xp_splash", caption = "10 XP",tooltip = "Increase spitters splash damage.\nPrice: 10 XP."})
|
||||
b.style.minimal_width = 50
|
||||
case.style.top_padding = 5
|
||||
case.style.left_padding = 20
|
||||
local case = table.add({type = "flow", direction = "horizontal"})
|
||||
local b = case.add({type = "button", name = "xp_resistance", caption = "10 XP",tooltip = "Increase resistance of all your biter/spitter.\nPrice: 10 XP."})
|
||||
b.style.minimal_width = 50
|
||||
case.style.top_padding = 5
|
||||
case.style.left_padding = 20
|
||||
local case = table.add({type = "flow", direction = "horizontal"})
|
||||
local b = case.add({type = "button", name = "xp_damage", caption = "10 XP",tooltip = "Increase biter melee damage.\nPrice: 10 XP."})
|
||||
b.style.minimal_width = 50
|
||||
case.style.top_padding = 5
|
||||
case.style.left_padding = 20
|
||||
local case = table.add({type = "flow", direction = "horizontal"})
|
||||
case.add({type = "sprite-button", name = "add_life", sprite = "item/space-science-pack",tooltip = "Buy extra life for all your biter/spitter.\nPrice: 1000 [item=space-science-pack].", number = math.floor(player_white_science_pack/1000)})
|
||||
case.style.left_padding = 30
|
||||
case.style.right_padding = 30
|
||||
|
||||
local line = frame.add({type = "line", direction = "horizontal"})
|
||||
frame.add({type = "button", name = "cancel_market", caption = "Close"})
|
||||
end
|
||||
|
||||
local function on_gui_opened(event)
|
||||
if not event then return end
|
||||
if not event.entity then return end
|
||||
if event.entity.name == "market" then
|
||||
local player = game.players[event.player_index]
|
||||
event.entity.operable =false
|
||||
create_new_gui_for_market(player,event.entity)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_gui_click(event)
|
||||
if not event then return end
|
||||
if not event.element then return end
|
||||
if not event.element.valid then return end
|
||||
local player = game.players[event.element.player_index]
|
||||
local player_inventory = player.get_main_inventory()
|
||||
|
||||
--[[if event.element.name == "confirm_rejoin" then
|
||||
player.gui.center["rejoin_question_frame"].destroy()
|
||||
Team.assign_force_to_player(player)
|
||||
Team.teleport_player_to_active_surface(player)
|
||||
Team.put_player_into_random_team(player)
|
||||
game.print(player.name .. " has rejoined the game!")
|
||||
return
|
||||
end
|
||||
if event.element.name == "cancel_rejoin" then player.gui.center["rejoin_question_frame"].destroy() return end
|
||||
if player.force.name == "spectator" then return end
|
||||
if event.element.name == "cancel_spectate" then player.gui.center["spectate_confirmation_frame"].destroy() return end
|
||||
|
||||
if event.element.name == "cancel_spectate" then player.gui.center["spectate_confirmation_frame"].destroy() return end]]
|
||||
|
||||
if event.element.name == "cancel_market" then
|
||||
player.gui.screen["market_frame"].destroy()
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
if player.force.name == "west" then
|
||||
local market = surface.find_entities_filtered{position = {-197,0}, radius = 5, type = "market"}
|
||||
market[1].operable = true
|
||||
elseif player.force.name == "east" then
|
||||
local market = surface.find_entities_filtered{position = {197,0}, radius = 5, type = "market"}
|
||||
market[1].operable = true
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
--[[if event.element.name == "confirm_spectate" then
|
||||
player.gui.screen["spectate_confirmation_frame"].destroy()
|
||||
Team.set_player_to_spectator(player)
|
||||
game.print(player.name .. " has turned into a spectator ghost.")
|
||||
return
|
||||
end
|
||||
|
||||
if event.element.name == "spectate_button" then
|
||||
if player.gui.screen["spectate_confirmation_frame"] then
|
||||
player.gui.screen["spectate_confirmation_frame"].destroy()
|
||||
else
|
||||
create_spectate_confirmation(player)
|
||||
end
|
||||
return
|
||||
end]]
|
||||
local xp_t = XP.get_table()
|
||||
local xp_available = xp_t[player.index].xp
|
||||
local amount = 10
|
||||
if event.element.name == "xp_splash" and xp_available >= amount then
|
||||
XP.lost_xp(player, amount)
|
||||
global.map_forces[player.force.name].modifier.splash = global.map_forces[player.force.name].modifier.splash + 0.001
|
||||
player.gui.screen["market_frame"].destroy()
|
||||
create_new_gui_for_market(player,event.entity)
|
||||
end
|
||||
if event.element.name == "xp_damage" and xp_available >= amount then
|
||||
XP.lost_xp(player, amount)
|
||||
global.map_forces[player.force.name].modifier.damage = global.map_forces[player.force.name].modifier.damage + 0.001
|
||||
player.gui.screen["market_frame"].destroy()
|
||||
create_new_gui_for_market(player,event.entity)
|
||||
end
|
||||
if event.element.name == "xp_resistance" and xp_available >= amount then
|
||||
XP.lost_xp(player, amount)
|
||||
global.map_forces[player.force.name].modifier.resistance = global.map_forces[player.force.name].modifier.resistance - 0.001
|
||||
player.gui.screen["market_frame"].destroy()
|
||||
create_new_gui_for_market(player,event.entity)
|
||||
end
|
||||
if event.element.name == "add_life" and player_inventory.get_item_count("space-science-pack") >= 1000 then
|
||||
XP.buy_extra_life(player.force.name)
|
||||
player.remove_item({name="space-science-pack", count=1000})
|
||||
player.gui.screen["market_frame"].destroy()
|
||||
create_new_gui_for_market(player,event.entity)
|
||||
end
|
||||
|
||||
|
||||
for _, button in pairs(button_science_name) do
|
||||
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})
|
||||
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])
|
||||
else
|
||||
game.print(player.name.." buy "..count.." wave of biter/spitters using [item="..button.sp.."]", color[button.sp])
|
||||
end
|
||||
end
|
||||
player.gui.screen["market_frame"].destroy()
|
||||
create_new_gui_for_market(player,event.entity)
|
||||
break
|
||||
end
|
||||
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
|
||||
if event.element.name == k then
|
||||
if player_inventory.get_item_count(button.sp) >= 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
|
||||
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.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
|
||||
player.gui.screen["market_frame"].destroy()
|
||||
create_new_gui_for_market(player,event.entity)
|
||||
break
|
||||
else
|
||||
local table_upgrade = {
|
||||
["medium"] = "small",
|
||||
["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.gui.screen["market_frame"].destroy()
|
||||
create_new_gui_for_market(player,event.entity)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
||||
event.add(defines.events.on_gui_opened, on_gui_opened)
|
||||
|
||||
return Public
|
669
maps/native_war/main.lua
Normal file
669
maps/native_war/main.lua
Normal file
@ -0,0 +1,669 @@
|
||||
require "modules.biter_reanimator"
|
||||
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 Reset = require "functions.soft_reset"
|
||||
local Map = require "modules.map_info"
|
||||
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
|
||||
for y = worm_turret_spawn_radius * -1, worm_turret_spawn_radius, 1 do
|
||||
local d = math.sqrt(x ^ 2 + y ^ 2)
|
||||
if d <= worm_turret_spawn_radius and d > 3 then table.insert(worm_turret_vectors.west, {x, y}) end
|
||||
end
|
||||
end
|
||||
worm_turret_vectors.east = {}
|
||||
for x = worm_turret_spawn_radius * -1, 0, 1 do
|
||||
for y = worm_turret_spawn_radius * -1, worm_turret_spawn_radius, 1 do
|
||||
local d = math.sqrt(x ^ 2 + y ^ 2)
|
||||
if d <= worm_turret_spawn_radius and d > 3 then table.insert(worm_turret_vectors.east, {x, y}) end
|
||||
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"}
|
||||
for _, e in pairs(beams) do
|
||||
e.destroy()
|
||||
end
|
||||
local beams = surface.find_entities_filtered{area = {{-30,20},{30,100}}, name = "electric-beam"}
|
||||
for _, e in pairs(beams) do
|
||||
e.destroy()
|
||||
end
|
||||
global.map_forces[force].spawn = {x=-137,y=0}
|
||||
if energy >=6 and energy < 12 then
|
||||
surface.create_entity({name = "electric-beam", position = {-120, -35}, source = {-120, -35}, target = {-137,-35}})
|
||||
surface.create_entity({name = "electric-beam", position = {-120, -35}, source = {-120, -35}, target = {-102,-35}})
|
||||
global.map_forces[force].spawn = {x=-120,y=-32}
|
||||
end
|
||||
if energy >=12 and energy < 18 then
|
||||
surface.create_entity({name = "electric-beam", position = {-120, -98}, source = {-120, -98}, target = {-137,-98}})
|
||||
surface.create_entity({name = "electric-beam", position = {-120, -98}, source = {-120, -98}, target = {-102,-98}})
|
||||
global.map_forces[force].spawn = {x=-120,y=-96}
|
||||
end
|
||||
if energy >=18 and energy < 24 then
|
||||
surface.create_entity({name = "electric-beam", position = {-60, -98}, source = {-60, -98}, target = {-77,-98}})
|
||||
surface.create_entity({name = "electric-beam", position = {-60, -98}, source = {-60, -98}, target = {-42,-98}})
|
||||
global.map_forces[force].spawn = {x=-60,y=-100}
|
||||
end
|
||||
if energy >=24 and energy < 30 then
|
||||
surface.create_entity({name = "electric-beam", position = {-60, -35}, source = {-60, -35}, target = {-77,-35}})
|
||||
surface.create_entity({name = "electric-beam", position = {-60, -35}, source = {-60, -35}, target = {-42,-35}})
|
||||
global.map_forces[force].spawn = {x=-60,y=-37}
|
||||
end
|
||||
if energy >=30 and energy < 36 then
|
||||
surface.create_entity({name = "electric-beam", position = {-60, 30}, source = {-60, 30}, target = {-77, 30}})
|
||||
surface.create_entity({name = "electric-beam", position = {-60, 30}, source = {-60, 30}, target = {-42, 30}})
|
||||
global.map_forces[force].spawn = {x=-60,y=28}
|
||||
end
|
||||
if energy >=36 and energy < 42 then
|
||||
surface.create_entity({name = "electric-beam", position = {-60, 93}, source = {-60, 93}, target = {-77,93}})
|
||||
surface.create_entity({name = "electric-beam", position = {-60, 93}, source = {-60, 93}, target = {-42,93}})
|
||||
global.map_forces[force].spawn = {x=-60,y=91}
|
||||
end
|
||||
if energy >=42 and energy < 48 then
|
||||
surface.create_entity({name = "electric-beam", position = {0, 93}, source = {0, 93}, target = {-17,93}})
|
||||
surface.create_entity({name = "electric-beam", position = {0, 93}, source = {0, 93}, target = {18,93}})
|
||||
global.map_forces[force].spawn = {x=0,y=95}
|
||||
end
|
||||
if energy >=48 then
|
||||
surface.create_entity({name = "electric-beam", position = {0, -35}, source = {0, 30}, target = {-17, 30}})
|
||||
surface.create_entity({name = "electric-beam", position = {0, -35}, source = {0, 30}, target = {18, 30}})
|
||||
global.map_forces[force].spawn = {x=0,y=-33}
|
||||
end
|
||||
elseif force == "east" then
|
||||
local beams2 = surface.find_entities_filtered{area = {{30,-100},{140,100}}, name = "electric-beam"}
|
||||
for _, e in pairs(beams2) do
|
||||
e.destroy()
|
||||
end
|
||||
local beams2 = surface.find_entities_filtered{area = {{-30,-100},{30,-20}}, name = "electric-beam"}
|
||||
for _, e in pairs(beams2) do
|
||||
e.destroy()
|
||||
end
|
||||
global.map_forces[force].spawn = {x=137,y=0}
|
||||
if energy >=6 and energy < 12 then
|
||||
surface.create_entity({name = "electric-beam", position = {120, -35}, source = {120, 30}, target = {103, 30}})
|
||||
surface.create_entity({name = "electric-beam", position = {120, -35}, source = {120, 30}, target = {138, 30}})
|
||||
global.map_forces[force].spawn = {x=120,y=32}
|
||||
end
|
||||
if energy >=12 and energy < 18 then
|
||||
surface.create_entity({name = "electric-beam", position = {120, 93}, source = {120, 93}, target = {103,93}})
|
||||
surface.create_entity({name = "electric-beam", position = {120, 93}, source = {120, 93}, target = {138,93}})
|
||||
global.map_forces[force].spawn = {x=120,y=96}
|
||||
end
|
||||
if energy >=18 and energy < 24 then
|
||||
surface.create_entity({name = "electric-beam", position = {60, 93}, source = {60, 93}, target = {43,93}})
|
||||
surface.create_entity({name = "electric-beam", position = {60, 93}, source = {60, 93}, target = {78,93}})
|
||||
global.map_forces[force].spawn = {x=60,y=100}
|
||||
end
|
||||
if energy >=24 and energy < 30 then
|
||||
surface.create_entity({name = "electric-beam", position = {60, 30}, source = {60, 30}, target = {43, 30}})
|
||||
surface.create_entity({name = "electric-beam", position = {60, 30}, source = {60, 30}, target = {78, 30}})
|
||||
global.map_forces[force].spawn = {x=60,y=37}
|
||||
end
|
||||
if energy >=30 and energy < 36 then
|
||||
surface.create_entity({name = "electric-beam", position = {60, -35}, source = {60, -35}, target = {43,-35}})
|
||||
surface.create_entity({name = "electric-beam", position = {60, -35}, source = {60, -35}, target = {78,-35}})
|
||||
global.map_forces[force].spawn = {x=60,y=-28}
|
||||
end
|
||||
if energy >=36 and energy < 42 then
|
||||
surface.create_entity({name = "electric-beam", position = {60, -98}, source = {60, -98}, target = {43,-98}})
|
||||
surface.create_entity({name = "electric-beam", position = {60, -98}, source = {60, -98}, target = {78,-98}})
|
||||
global.map_forces[force].spawn = {x=60,y=-91}
|
||||
end
|
||||
if energy >=42 and energy < 48 then
|
||||
surface.create_entity({name = "electric-beam", position = {0, -98}, source = {0, -98}, target = {-17,-98}})
|
||||
surface.create_entity({name = "electric-beam", position = {0, -98}, source = {0, -98}, target = {18,-98}})
|
||||
global.map_forces[force].spawn = {x=0,y=-95}
|
||||
end
|
||||
if energy >=48 then
|
||||
surface.create_entity({name = "electric-beam", position = {0, -35}, source = {0, -35}, target = {-17,-35}})
|
||||
surface.create_entity({name = "electric-beam", position = {0, -35}, source = {0, -35}, target = {18,-35}})
|
||||
global.map_forces[force].spawn = {x=0,y=33}
|
||||
end
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
local function initial_worm_turret(surface)
|
||||
for _, force_name in pairs({"west", "east"}) do
|
||||
for k , pos in pairs(global.map_forces[force_name].worm_turrets_positions) do
|
||||
surface.create_entity({name = "small-worm-turret", position = pos, force = force_name})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[local function spawn_one_unit(belt, food_item)
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
local random_biter = math.random(0,9)
|
||||
local i = math.random(0, 10)-5
|
||||
if food_item == "automation-science-pack" or food_item == "logistic-science-pack" then
|
||||
if random_biter <= 5 then
|
||||
local unit = surface.create_entity{name = "small-biter", position = {global.map_forces[belt.force.name].spawn.x + i,global.map_forces[belt.force.name].spawn.y} , force = game.forces[belt.force.name]}
|
||||
global.map_forces[belt.force.name].units[unit.unit_number] = unit
|
||||
else
|
||||
local unit = surface.create_entity{name = "small-spitter", position = {global.map_forces[belt.force.name].spawn.x + i,global.map_forces[belt.force.name].spawn.y}, force = game.forces[belt.force.name]}
|
||||
global.map_forces[belt.force.name].units[unit.unit_number] = unit
|
||||
end
|
||||
return
|
||||
end
|
||||
if food_item == "military-science-pack" then
|
||||
if random_biter <= 5 then
|
||||
local unit = surface.create_entity{name = "medium-biter", position = {global.map_forces[belt.force.name].spawn.x + i,global.map_forces[belt.force.name].spawn.y} , force = game.forces[belt.force.name]}
|
||||
global.map_forces[belt.force.name].units[unit.unit_number] = unit
|
||||
else
|
||||
local unit = surface.create_entity{name = "medium-spitter", position = {global.map_forces[belt.force.name].spawn.x + i,global.map_forces[belt.force.name].spawn.y}, force = game.forces[belt.force.name]}
|
||||
global.map_forces[belt.force.name].units[unit.unit_number] = unit
|
||||
end
|
||||
return
|
||||
end
|
||||
if food_item == "chemical-science-pack" then
|
||||
if random_biter <= 5 then
|
||||
local unit = surface.create_entity{name = "big-biter", position = {global.map_forces[belt.force.name].spawn.x + i,global.map_forces[belt.force.name].spawn.y} , force = game.forces[belt.force.name]}
|
||||
global.map_forces[belt.force.name].units[unit.unit_number] = unit
|
||||
else
|
||||
local unit = surface.create_entity{name = "big-spitter", position = {global.map_forces[belt.force.name].spawn.x + i,global.map_forces[belt.force.name].spawn.y}, force = game.forces[belt.force.name]}
|
||||
global.map_forces[belt.force.name].units[unit.unit_number] = unit
|
||||
end
|
||||
return
|
||||
end
|
||||
if food_item == "production-science-pack" or food_item == "utility-science-pack" then
|
||||
if random_biter <= 5 then
|
||||
local unit = surface.create_entity{name = "behemoth-biter", position = {global.map_forces[belt.force.name].spawn.x + i,global.map_forces[belt.force.name].spawn.y} , force = game.forces[belt.force.name]}
|
||||
global.map_forces[belt.force.name].units[unit.unit_number] = unit
|
||||
else
|
||||
local unit = surface.create_entity{name = "behemoth-spitter", position = {global.map_forces[belt.force.name].spawn.x + i,global.map_forces[belt.force.name].spawn.y}, force = game.forces[belt.force.name]}
|
||||
global.map_forces[belt.force.name].units[unit.unit_number] = unit
|
||||
end
|
||||
return
|
||||
end
|
||||
--unit.ai_settings.allow_destroy_when_commands_fail = false
|
||||
--unit.ai_settings.allow_try_return_to_spawner = false
|
||||
--team.unit_count = team.unit_count + 1
|
||||
end]]
|
||||
|
||||
local function get_belts(market)
|
||||
local belts = market.surface.find_entities_filtered({
|
||||
type = "transport-belt",
|
||||
area = {{market.position.x - 2, market.position.y - 1},{market.position.x +2 , market.position.y + 1}},
|
||||
force = market.force,
|
||||
})
|
||||
return belts
|
||||
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
|
||||
--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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function spawn_wave_from_belt(force_name)
|
||||
for _, science_name in pairs(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)
|
||||
global.map_forces[force_name].ate_buffer_potion[science_name] = global.map_forces[force_name].ate_buffer_potion[science_name] - Gui.wave_price[science_name].price
|
||||
--if global.map_forces[belt.force.name].ate_buffer_potion[science_name] < 0 then global.map_forces[belt.force.name].ate_buffer_potion[science_name] =0 end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function nom()
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
for key, force in pairs(global.map_forces) do
|
||||
if not force.hatchery then return end
|
||||
force.hatchery.health = force.hatchery.health + 5
|
||||
local belts = get_belts(force.hatchery)
|
||||
for _, belt in pairs(belts) do
|
||||
eat_food_from_belt(belt)
|
||||
end
|
||||
spawn_wave_from_belt(key)
|
||||
end
|
||||
for _, player in pairs(game.connected_players) do Gui.update_health_boost_buttons(player) end
|
||||
end
|
||||
|
||||
local function get_units(force_name)
|
||||
local units = {}
|
||||
local count = 1
|
||||
for _, unit in pairs(global.map_forces[force_name].units) do
|
||||
if not unit.unit_group then
|
||||
--if math_random(1, 3) ~= 1 then
|
||||
units[count] = unit
|
||||
count = count + 1
|
||||
-- end
|
||||
end
|
||||
end
|
||||
return units
|
||||
end
|
||||
|
||||
local function send_unit_groups()
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
for key, force in pairs(global.map_forces) do
|
||||
local units = get_units(key)
|
||||
if #units > 0 then
|
||||
--alert_bubble(key, units[1])
|
||||
local vectors = worm_turret_vectors[key]
|
||||
local vector = vectors[math_random(1, #vectors)]
|
||||
local position = {x = global.map_forces[key].spawn.x + 10 + vector[1], y = global.map_forces[key].spawn.y + vector[2]}
|
||||
local unit_group = surface.create_unit_group({position = position, force = key})
|
||||
for _, unit in pairs(units) do unit_group.add_member(unit) end
|
||||
if not force.target then return end
|
||||
if not force.target.valid then return end
|
||||
--unit.ai_settings.allow_destroy_when_commands_fail = false
|
||||
--unit.ai_settings.allow_try_return_to_spawner = false
|
||||
unit_group.set_command({
|
||||
type = defines.command.compound,
|
||||
structure_type = defines.compound_command.return_last,
|
||||
commands = {
|
||||
{
|
||||
type = defines.command.attack_area,
|
||||
destination = {x = force.target.position.x, y = force.target.position.y},
|
||||
radius = 6,
|
||||
distraction = defines.distraction.by_anything
|
||||
},
|
||||
{
|
||||
type = defines.command.attack,
|
||||
target = force.target,
|
||||
distraction = defines.distraction.by_enemy,
|
||||
},
|
||||
}
|
||||
})
|
||||
unit_group.start_moving()
|
||||
end
|
||||
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])
|
||||
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])
|
||||
end
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then return end
|
||||
if global.game_reset_tick then return end
|
||||
|
||||
if entity.type == "unit" then
|
||||
local team = global.map_forces[entity.force.name]
|
||||
team.unit_count = team.unit_count - 1
|
||||
team.units[entity.unit_number] = nil
|
||||
return
|
||||
end
|
||||
if entity.name == "radar" then global.map_forces[entity.force.name].radar[entity.unit_number] = nil end
|
||||
if entity.type ~= "market" then return end
|
||||
|
||||
if entity.force.name == "east" then
|
||||
game.print("East lost their Hatchery.", {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})
|
||||
game.forces.west.play_sound{path="utility/game_won", volume_modifier=0.85}
|
||||
|
||||
for _, player in pairs(game.forces.west.connected_players) do
|
||||
if global.map_forces.east.player_count > 0 then
|
||||
Map_score.set_score(player, Map_score.get_score(player) + 1)
|
||||
end
|
||||
end
|
||||
else
|
||||
game.print("West lost their Hatchery.", {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})
|
||||
game.forces.east.play_sound{path="utility/game_won", volume_modifier=0.85}
|
||||
|
||||
for _, player in pairs(game.forces.east.connected_players) do
|
||||
if global.map_forces.west.player_count > 0 then
|
||||
Map_score.set_score(player, Map_score.get_score(player) + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
game.print("Next round starting in 60 seconds..", {150, 150, 150})
|
||||
|
||||
game.forces.spectator.play_sound{path="utility/game_won", volume_modifier=0.85}
|
||||
|
||||
global.game_reset_tick = game.tick + 3600
|
||||
game.delete_surface("mirror_terrain")
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
for _, child in pairs(player.gui.left.children) do child.destroy() end
|
||||
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
|
||||
local unit_number = event.created_entity.unit_number
|
||||
local entity = event.created_entity
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
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
|
||||
end
|
||||
Team.assign_force_to_player(player)
|
||||
Team.teleport_player_to_active_surface(player)
|
||||
Team.put_player_into_random_team(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function reveal_map(surface, force_name)
|
||||
local actif_radar_count = 0
|
||||
local radar_range_x = 16
|
||||
if force_name == "east" then
|
||||
-- find_entities_filtered{name="radar", force="east"}
|
||||
for k, ent in pairs(global.map_forces["east"].radar) do
|
||||
if ent.energy >= 5000 then
|
||||
actif_radar_count = actif_radar_count +1
|
||||
end
|
||||
end
|
||||
if actif_radar_count == 0 then return end
|
||||
local x_east =-224+actif_radar_count*radar_range_x*-1
|
||||
game.forces.east.chart(surface, {{x_east,(x_east)*0.5},{-224 ,(-x_east)*0.5}})
|
||||
end
|
||||
if force_name == "west" then
|
||||
for k, ent in pairs(global.map_forces["west"].radar) do
|
||||
if ent.energy >= 5000 then
|
||||
actif_radar_count = actif_radar_count +1
|
||||
end
|
||||
end
|
||||
if actif_radar_count == 0 then return end
|
||||
local x_west =224+actif_radar_count*radar_range_x
|
||||
game.forces.west.chart(surface, {{224, (-x_west)*0.5 }, {x_west, (x_west)*0.5 }})
|
||||
end
|
||||
end
|
||||
|
||||
local function reset_operable_market(surface)
|
||||
local market = surface.find_entities_filtered{position = {-197,0}, radius = 5, type = "market"}
|
||||
market[1].operable = true
|
||||
local market = surface.find_entities_filtered{position = {197,0}, radius = 5, type = "market"}
|
||||
market[1].operable = true
|
||||
end
|
||||
|
||||
local function tick()
|
||||
local game_tick = game.tick
|
||||
|
||||
if game_tick == 120 then
|
||||
initial_worm_turret(game.surfaces[global.active_surface_index])
|
||||
end
|
||||
|
||||
if game_tick % 240 == 0 then --400 ou 200
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
reset_operable_market(surface)
|
||||
local area = {{-224, -150}, {224, 150}}
|
||||
game.forces.west.chart(surface, area)
|
||||
game.forces.east.chart(surface, area)
|
||||
end
|
||||
|
||||
if game_tick % 480 == 0 then -- was 600
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
reveal_map(surface, "east")
|
||||
end
|
||||
if (game_tick+240) % 480 == 0 then -- was +300 % 600
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
reveal_map(surface, "west")
|
||||
end
|
||||
|
||||
if game_tick % 900 == 0 then
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
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 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
|
||||
if new_global_energy <= 0 then new_global_energy = 0 end
|
||||
game.print(force_name..' recule son beam')
|
||||
create_beams(surface, new_global_energy, force_name)
|
||||
global.map_forces[force_name].energy = new_global_energy
|
||||
end
|
||||
end
|
||||
end
|
||||
if game_tick % 1800 == 0 then
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
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 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
|
||||
if new_global_energy >= 48 then new_global_energy = 48 end
|
||||
game.print(force_name..' avance son beam')
|
||||
create_beams(surface, new_global_energy, force_name)
|
||||
global.map_forces[force_name].energy = new_global_energy
|
||||
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
|
||||
local robot_build_restriction = {
|
||||
["east"] = function(x,y)
|
||||
if x < 170 then return true end
|
||||
if (x-160)*(x-160) + y*y <= 40*40 then return true end
|
||||
end,
|
||||
["west"] = function(x,y)
|
||||
if x > -170 then return true end
|
||||
if (x+160)*(x+160) + y*y <= 40*40 then return true end
|
||||
|
||||
|
||||
end
|
||||
}
|
||||
|
||||
local function on_robot_built_entity(event)
|
||||
if not robot_build_restriction[event.robot.force.name] then return end
|
||||
if not robot_build_restriction[event.robot.force.name](event.created_entity.position.x,event.created_entity.position.y) then
|
||||
if event.created_entity.name == "radar" then
|
||||
local unit_number = event.created_entity.unit_number
|
||||
local entity = event.created_entity
|
||||
global.map_forces[event.robot.force.name].radar[unit_number] = entity
|
||||
end
|
||||
return
|
||||
end
|
||||
local inventory = event.robot.get_inventory(defines.inventory.robot_cargo)
|
||||
inventory.insert({name = event.created_entity.name, count = 1})
|
||||
event.robot.surface.create_entity({name = "explosion", position = event.created_entity.position})
|
||||
game.print("Team " .. event.robot.force.name .. "'s construction drone had an accident.", {r = 200, g = 50, b = 100})
|
||||
event.created_entity.destroy()
|
||||
end
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
local entity = event.entity
|
||||
local cause = event.cause
|
||||
if not entity.valid then return end
|
||||
if entity.type == "unit" or entity.type == "turret" then
|
||||
if cause.type == "unit" then
|
||||
if cause.name == "small-biter" or cause.name == "medium-biter" or cause.name == "big-biter" or cause.name == "behemoth-biter" then
|
||||
local modified_damage = event.original_damage_amount * global.map_forces[cause.force.name].modifier.damage * global.map_forces[entity.force.name].modifier.resistance
|
||||
entity.health = entity.health - modified_damage
|
||||
elseif cause.name == "small-spitter" or cause.name == "medium-spitter" or cause.name == "big-spitter" or cause.name == "behemoth-spitter" then
|
||||
local modified_damage = event.original_damage_amount * global.map_forces[cause.force.name].modifier.splash * global.map_forces[entity.force.name].modifier.resistance
|
||||
entity.health = entity.health - modified_damage
|
||||
end
|
||||
end
|
||||
end
|
||||
if entity.type ~= "market" then return end
|
||||
if cause then
|
||||
if cause.valid then
|
||||
if cause.type == "unit" then
|
||||
if math_random(1,5) == 1 then return end
|
||||
end
|
||||
end
|
||||
end
|
||||
entity.health = entity.health + event.final_damage_amount
|
||||
|
||||
end
|
||||
|
||||
local function show_color_force()
|
||||
local force_name1= "east"
|
||||
local force_name2= "west"
|
||||
for _, unit in pairs(global.map_forces[force_name1].units) do
|
||||
rendering.draw_circle{color = {255, 1, 1 }, radius = 0.1, filled = true, target = unit, target_offset = {-0.1,-0.1} ,surface = unit.surface , time_to_live = 60, only_in_alt_mode=true }
|
||||
end
|
||||
for _, unit in pairs(global.map_forces[force_name2].units) do
|
||||
rendering.draw_circle{color = {1, 1, 255 }, radius = 0.1, filled = true, target = unit, target_offset = {-0.1,-0.1} ,surface = unit.surface , time_to_live = 60, only_in_alt_mode=true }
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
game.difficulty_settings.technology_price_multiplier = 0.5
|
||||
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()
|
||||
|
||||
end
|
||||
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_init(on_init)
|
||||
event.on_nth_tick(60, tick)
|
||||
event.on_nth_tick(60, show_color_force)
|
||||
event.on_nth_tick(30, nom)
|
||||
event.on_nth_tick(300,send_unit_groups)
|
||||
event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
||||
event.add(defines.events.on_built_entity, on_built_entity)
|
||||
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
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)
|
149
maps/native_war/mineable_wreckage_yields_scrap.lua
Normal file
149
maps/native_war/mineable_wreckage_yields_scrap.lua
Normal file
@ -0,0 +1,149 @@
|
||||
--mineable-wreckage yields scrap -- by mewmew
|
||||
|
||||
local mining_chance_weights = {
|
||||
{name = "iron-plate", chance = 1000},
|
||||
{name = "iron-gear-wheel", chance = 750},
|
||||
{name = "copper-plate", chance = 750},
|
||||
{name = "copper-cable", chance = 500},
|
||||
{name = "electronic-circuit", chance = 300},
|
||||
{name = "steel-plate", chance = 200},
|
||||
{name = "solid-fuel", chance = 150},
|
||||
{name = "pipe", chance = 100},
|
||||
{name = "iron-stick", chance = 50},
|
||||
{name = "battery", chance = 20},
|
||||
{name = "empty-barrel", chance = 10},
|
||||
{name = "crude-oil-barrel", chance = 30},
|
||||
{name = "lubricant-barrel", chance = 20},
|
||||
{name = "petroleum-gas-barrel", chance = 15},
|
||||
{name = "sulfuric-acid-barrel", chance = 15},
|
||||
{name = "heavy-oil-barrel", chance = 15},
|
||||
{name = "light-oil-barrel", chance = 15},
|
||||
{name = "water-barrel", chance = 10},
|
||||
{name = "green-wire", chance = 10},
|
||||
{name = "red-wire", chance = 10},
|
||||
{name = "explosives", chance = 5},
|
||||
{name = "advanced-circuit", chance = 5},
|
||||
{name = "nuclear-fuel", chance = 1},
|
||||
{name = "pipe-to-ground", chance = 10},
|
||||
{name = "plastic-bar", chance = 5},
|
||||
{name = "processing-unit", chance = 2},
|
||||
{name = "used-up-uranium-fuel-cell", chance = 1},
|
||||
{name = "uranium-fuel-cell", chance = 1},
|
||||
{name = "rocket-fuel", chance = 3},
|
||||
{name = "rocket-control-unit", chance = 1},
|
||||
{name = "low-density-structure", chance = 1},
|
||||
{name = "heat-pipe", chance = 1},
|
||||
{name = "engine-unit", chance = 4},
|
||||
{name = "electric-engine-unit", chance = 2},
|
||||
{name = "logistic-robot", chance = 1},
|
||||
{name = "construction-robot", chance = 1},
|
||||
|
||||
{name = "land-mine", chance = 3},
|
||||
{name = "grenade", chance = 10},
|
||||
{name = "rocket", chance = 3},
|
||||
{name = "explosive-rocket", chance = 3},
|
||||
{name = "cannon-shell", chance = 2},
|
||||
{name = "explosive-cannon-shell", chance = 2},
|
||||
{name = "uranium-cannon-shell", chance = 1},
|
||||
{name = "explosive-uranium-cannon-shell", chance = 1},
|
||||
{name = "artillery-shell", chance = 1},
|
||||
{name = "cluster-grenade", chance = 2},
|
||||
{name = "defender-capsule", chance = 5},
|
||||
{name = "destroyer-capsule", chance = 1},
|
||||
{name = "distractor-capsule", chance = 2}
|
||||
}
|
||||
|
||||
local scrap_yield_amounts = {
|
||||
["iron-plate"] = 16,
|
||||
["iron-gear-wheel"] = 8,
|
||||
["iron-stick"] = 16,
|
||||
["copper-plate"] = 16,
|
||||
["copper-cable"] = 24,
|
||||
["electronic-circuit"] = 8,
|
||||
["steel-plate"] = 4,
|
||||
["pipe"] = 8,
|
||||
["solid-fuel"] = 4,
|
||||
["empty-barrel"] = 3,
|
||||
["crude-oil-barrel"] = 3,
|
||||
["lubricant-barrel"] = 3,
|
||||
["petroleum-gas-barrel"] = 3,
|
||||
["sulfuric-acid-barrel"] = 3,
|
||||
["heavy-oil-barrel"] = 3,
|
||||
["light-oil-barrel"] = 3,
|
||||
["water-barrel"] = 3,
|
||||
["battery"] = 2,
|
||||
["explosives"] = 4,
|
||||
["advanced-circuit"] = 2,
|
||||
["nuclear-fuel"] = 0.1,
|
||||
["pipe-to-ground"] = 1,
|
||||
["plastic-bar"] = 4,
|
||||
["processing-unit"] = 1,
|
||||
["used-up-uranium-fuel-cell"] = 1,
|
||||
["uranium-fuel-cell"] = 0.3,
|
||||
["rocket-fuel"] = 0.3,
|
||||
["rocket-control-unit"] = 0.3,
|
||||
["low-density-structure"] = 0.3,
|
||||
["heat-pipe"] = 1,
|
||||
["green-wire"] = 8,
|
||||
["red-wire"] = 8,
|
||||
["engine-unit"] = 2,
|
||||
["electric-engine-unit"] = 2,
|
||||
["logistic-robot"] = 0.3,
|
||||
["construction-robot"] = 0.3,
|
||||
|
||||
["land-mine"] = 1,
|
||||
["grenade"] = 2,
|
||||
["rocket"] = 2,
|
||||
["explosive-rocket"] = 2,
|
||||
["cannon-shell"] = 2,
|
||||
["explosive-cannon-shell"] = 2,
|
||||
["uranium-cannon-shell"] = 2,
|
||||
["explosive-uranium-cannon-shell"] = 2,
|
||||
["artillery-shell"] = 0.3,
|
||||
["cluster-grenade"] = 0.3,
|
||||
["defender-capsule"] = 2,
|
||||
["destroyer-capsule"] = 0.3,
|
||||
["distractor-capsule"] = 0.3
|
||||
}
|
||||
|
||||
local scrap_raffle = {}
|
||||
for _, t in pairs (mining_chance_weights) do
|
||||
for x = 1, t.chance, 1 do
|
||||
table.insert(scrap_raffle, t.name)
|
||||
end
|
||||
end
|
||||
|
||||
local size_of_scrap_raffle = #scrap_raffle
|
||||
|
||||
local function on_player_mined_entity(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then return end
|
||||
if entity.name ~= "mineable-wreckage" then return end
|
||||
|
||||
event.buffer.clear()
|
||||
|
||||
local scrap = scrap_raffle[math.random(1, size_of_scrap_raffle)]
|
||||
|
||||
local amount_bonus = (game.forces.enemy.evolution_factor * 2) + (game.forces.player.mining_drill_productivity_bonus * 2)
|
||||
local r1 = math.ceil(scrap_yield_amounts[scrap] * (0.3 + (amount_bonus * 0.3)))
|
||||
local r2 = math.ceil(scrap_yield_amounts[scrap] * (1.7 + (amount_bonus * 1.7)))
|
||||
local amount = math.random(r1, r2)
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local inserted_count = player.insert({name = scrap, count = amount})
|
||||
|
||||
if inserted_count ~= amount then
|
||||
local amount_to_spill = amount - inserted_count
|
||||
entity.surface.spill_item_stack(entity.position,{name = scrap, count = amount_to_spill}, true)
|
||||
end
|
||||
|
||||
entity.surface.create_entity({
|
||||
name = "flying-text",
|
||||
position = entity.position,
|
||||
text = "+" .. amount .. " [img=item/" .. scrap .. "]",
|
||||
color = {r=0.98, g=0.66, b=0.22}
|
||||
})
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
27
maps/native_war/share_chat.lua
Normal file
27
maps/native_war/share_chat.lua
Normal file
@ -0,0 +1,27 @@
|
||||
----------share chat with spectator force-------------------
|
||||
local function on_console_chat(event)
|
||||
if not event.message then return end
|
||||
if not event.player_index then return end
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
local color = {}
|
||||
color = player.color
|
||||
color.r = color.r * 0.6 + 0.35
|
||||
color.g = color.g * 0.6 + 0.35
|
||||
color.b = color.b * 0.6 + 0.35
|
||||
color.a = 1
|
||||
|
||||
if player.force.name == "west" then
|
||||
game.forces.spectator.print(player.name .. " (west): ".. event.message, color)
|
||||
end
|
||||
if player.force.name == "east" then
|
||||
game.forces.spectator.print(player.name .. " (east): ".. event.message, color)
|
||||
end
|
||||
if player.force.name == "spectator" then
|
||||
game.forces.west.print(player.name .. " (spectator): ".. event.message, color)
|
||||
game.forces.east.print(player.name .. " (spectator): ".. event.message, color)
|
||||
end
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.add(defines.events.on_console_chat, on_console_chat)
|
350
maps/native_war/team.lua
Normal file
350
maps/native_war/team.lua
Normal file
@ -0,0 +1,350 @@
|
||||
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
|
||||
local random_biter = math.random(5,9)
|
||||
for i = 1, random_biter, 1 do
|
||||
local unit = game.surfaces[surface].create_entity{name = "small-biter", position = {global.map_forces[force].spawn.x + i, global.map_forces[force].spawn.y} , force = game.forces[force]}
|
||||
global.map_forces[force].units[unit.unit_number] = unit
|
||||
end
|
||||
for i = 1, 10-random_biter, 1 do
|
||||
local unit = game.surfaces[surface].create_entity{name = "small-spitter", position = {global.map_forces[force].spawn.x + i,global.map_forces[force].spawn.y}, force = game.forces[force]}
|
||||
global.map_forces[force].units[unit.unit_number] = unit
|
||||
end
|
||||
return
|
||||
end
|
||||
if tier=="grey" then
|
||||
local random_biter=math.random(5,9)
|
||||
for i = 1, random_biter, 1 do
|
||||
local unit = game.surfaces[surface].create_entity{name = "medium-biter", position = {global.map_forces[force].spawn.x + i,global.map_forces[force].spawn.y}, force = game.forces[force]}
|
||||
global.map_forces[force].units[unit.unit_number] = unit
|
||||
end
|
||||
for i = 1, 10-random_biter, 1 do
|
||||
local unit = game.surfaces[surface].create_entity{name = "medium-spitter", position = {global.map_forces[force].spawn.x + i,global.map_forces[force].spawn.y}, force = game.forces[force]}
|
||||
global.map_forces[force].units[unit.unit_number] = unit
|
||||
end
|
||||
return
|
||||
end
|
||||
if tier=="blue" then
|
||||
local random_biter = math.random(5,9)
|
||||
for i = 1, random_biter, 1 do
|
||||
local unit = game.surfaces[surface].create_entity{name = "big-biter", position = {global.map_forces[force].spawn.x + i,global.map_forces[force].spawn.y}, force = game.forces[force]}
|
||||
global.map_forces[force].units[unit.unit_number] = unit
|
||||
end
|
||||
for i = 1, 10-random_biter, 1 do
|
||||
local unit = game.surfaces[surface].create_entity{name = "big-spitter", position = {global.map_forces[force].spawn.x + i,global.map_forces[force].spawn.y}, force = game.forces[force]}
|
||||
global.map_forces[force].units[unit.unit_number] = unit
|
||||
end
|
||||
return
|
||||
end
|
||||
if tier=="purple" or tier=="yellow" then
|
||||
local random_biter = math.random(5,9)
|
||||
for i = 1, random_biter, 1 do
|
||||
local unit = game.surfaces[surface].create_entity{name = "-biter", position = {global.map_forces[force].spawn.x + i,global.map_forces[force].spawn.y}, force = game.forces[force]}
|
||||
global.map_forces[force].units[unit.unit_number] = unit
|
||||
end
|
||||
for i = 1, 10-random_biter, 1 do
|
||||
local unit = game.surfaces[surface].create_entity{name = "behemoth-spitter", position = {global.map_forces[force].spawn.x + i,global.map_forces[force].spawn.y}, force = game.forces[force]}
|
||||
global.map_forces[force].units[unit.unit_number] = unit
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
function Public.buy_worm_turret(surface,force_name, dist, player, player_nb_sp, nb_sp_price, sp)
|
||||
local size_table_turret = #global.map_forces[force_name].worm_turrets_positions
|
||||
if dist == "All" then
|
||||
local player_sp_count = player_nb_sp
|
||||
count = 0
|
||||
for k, pos in pairs(global.map_forces[force_name].worm_turrets_positions) do
|
||||
local turret = surface.find_entity('small-worm-turret',{pos.x,pos.y})
|
||||
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})
|
||||
player.remove_item({name=sp, count=nb_sp_price})
|
||||
player_sp_count = player_sp_count - nb_sp_price
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
if count == 0 then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
elseif dist == "Farthest" then
|
||||
for i=size_table_turret,1,-1 do
|
||||
local pos = global.map_forces[force_name].worm_turrets_positions[i]
|
||||
local turret = surface.find_entity('small-worm-turret',{pos.x,pos.y})
|
||||
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})
|
||||
player.remove_item({name=sp, count=nb_sp_price})
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
elseif dist == "Closest" then
|
||||
for i=1,size_table_turret,1 do
|
||||
local pos = global.map_forces[force_name].worm_turrets_positions[i]
|
||||
local turret = surface.find_entity('small-worm-turret',{pos.x,pos.y})
|
||||
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})
|
||||
player.remove_item({name=sp, count=nb_sp_price})
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function Public.upgrade_worm_turret(surface, force_name, dist, player, player_nb_sp, nb_sp_price, sp, tier)
|
||||
local table_upgrade = {
|
||||
["medium-worm-turret"] = "small-worm-turret",
|
||||
["big-worm-turret"] = "medium-worm-turret",
|
||||
["behemoth-worm-turret"] = "big-worm-turret"
|
||||
}
|
||||
local size_table_turret = #global.map_forces[force_name].worm_turrets_positions
|
||||
print(size_table_turret)
|
||||
if dist == "All" then
|
||||
local player_sp_count = player_nb_sp
|
||||
count = 0
|
||||
for k, pos in pairs(global.map_forces[force_name].worm_turrets_positions) do
|
||||
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})
|
||||
player.remove_item({name=sp, count=nb_sp_price})
|
||||
player_sp_count = player_sp_count - nb_sp_price
|
||||
count = count + 1
|
||||
else end
|
||||
end
|
||||
if count == 0 then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
elseif dist == "Farthest" then
|
||||
for i = #global.map_forces[force_name].worm_turrets_positions, 1, -1 do
|
||||
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})
|
||||
player.remove_item({name=sp, count=nb_sp_price})
|
||||
return true
|
||||
else end
|
||||
end
|
||||
return false
|
||||
elseif dist == "Closest" then
|
||||
for k, pos in pairs(global.map_forces[force_name].worm_turrets_positions) do
|
||||
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})
|
||||
player.remove_item({name=sp, count=nb_sp_price})
|
||||
return true
|
||||
else end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function Public.buy_extra_life(force_name)
|
||||
local force_index = game.forces[force_name].index
|
||||
global.biter_reanimator.forces[force_index] = global.biter_reanimator.forces[force_index] +1
|
||||
end
|
||||
|
||||
return Public
|
715
maps/native_war/terrain.lua
Normal file
715
maps/native_war/terrain.lua
Normal file
@ -0,0 +1,715 @@
|
||||
local math_abs = math.abs
|
||||
local math_random = math.random
|
||||
local Map_functions = require "tools.map_functions"
|
||||
local simplex_noise = require 'utils.simplex_noise'.d2
|
||||
local Public = {}
|
||||
|
||||
local hatchery_position = {x = 200, y = 0}
|
||||
local table_tiles = {
|
||||
[1] = "concrete",
|
||||
[2] = "refined-concrete",
|
||||
[3] = "stone-path",
|
||||
}
|
||||
local function get_replacement_tile(surface, position)
|
||||
for i = 1, 128, 1 do
|
||||
local vectors = {{0, i}, {0, i * -1}, {i, 0}, {i * -1, 0}}
|
||||
table.shuffle_table(vectors)
|
||||
for k, v in pairs(vectors) do
|
||||
local tile = surface.get_tile(position.x + v[1], position.y + v[2])
|
||||
if not tile.collides_with("resource-layer") then return tile.name end
|
||||
end
|
||||
end
|
||||
return "grass-1"
|
||||
end
|
||||
|
||||
local function place_market(surface, position, team_force)
|
||||
local market = surface.create_entity({name = "market", position = position, force = team_force})
|
||||
market.minable = false
|
||||
return market
|
||||
end
|
||||
|
||||
local function kill_entities_combat_zone(surface, table_area)
|
||||
for _, ent in pairs(surface.find_entities_filtered{area = table_area, type = "resource"}) do ent.destroy() end
|
||||
for _, entity in ipairs(surface.find_entities_filtered{ area= table_area, type="tree"}) do entity.destroy() end
|
||||
end
|
||||
|
||||
local function create_markets(surface)
|
||||
local wall = surface.create_entity({name = "stone-wall", position = {-15, -174}, force = "spectator"})
|
||||
wall.destructible=false
|
||||
wall.minable=false
|
||||
local wall = surface.create_entity({name = "stone-wall", position = {15, -174}, force = "spectator"})
|
||||
wall.destructible=false
|
||||
wall.minable=false
|
||||
local wall = surface.create_entity({name = "stone-wall", position = {-15, 174}, force = "spectator"})
|
||||
wall.destructible=false
|
||||
wall.minable=false
|
||||
local wall = surface.create_entity({name = "stone-wall", position = {15, 174}, force = "spectator"})
|
||||
wall.destructible=false
|
||||
wall.minable=false
|
||||
surface.create_entity({name = "electric-beam", position = {-15, -174}, source = {-15, -174}, target = {15,-174}})
|
||||
surface.create_entity({name = "electric-beam", position = {-15, 174}, source = {-15, 174}, target = {15,174}})
|
||||
local x = hatchery_position.x
|
||||
local y = hatchery_position.y
|
||||
for i=169, 200, 1 do
|
||||
for j=1, 100, 1 do
|
||||
if math.sqrt((i*-1+160)*(i*-1+160)+(j-50)*(j-50))>=38 and math.sqrt((i*-1+160)*(i*-1+160)+(j-50)*(j-50))<=40 then
|
||||
if j== 50 or j== 49 or j==51 then else
|
||||
local wall = surface.create_entity({name = "stone-wall", position = {i*-1, j-50}, force = "west"})
|
||||
wall.destructible=false
|
||||
wall.minable=false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for i=169, 200, 1 do
|
||||
for j=1, 100, 1 do
|
||||
if math.sqrt((i-160)*(i-160)+(j-50)*(j-50))>=38 and math.sqrt((i-160)*(i-160)+(j-50)*(j-50))<=40 then
|
||||
if j== 50 or j== 49 or j==51 then else
|
||||
local wall = surface.create_entity({name = "stone-wall", position = {i, j-50}, force = "east"})
|
||||
wall.destructible=false
|
||||
wall.minable=false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local position = {(x * -1)+2, 0}
|
||||
local e = place_market(surface, position, "west")
|
||||
global.market1=e
|
||||
|
||||
local energy_source = {type = "electric", buffer_capacity = "10GJ", usage_priority = "tertiary", input_flow_limit = "1GW", output_flow_limit = "0W", drain="0W"}
|
||||
local eei = surface.create_entity({type = "electric-energy-interface", name = "electric-energy-interface", energy_source = energy_source, position = {-200,-2}, force = "west"})
|
||||
local ep = surface.create_entity({name = "small-electric-pole", position = {-200,-5}, force = "west"})
|
||||
|
||||
ep.destructible=false
|
||||
ep.minable=false
|
||||
eei.operable = false
|
||||
eei.destructible=false
|
||||
eei.minable=false
|
||||
eei.electric_buffer_size = 100000000
|
||||
eei.power_usage = 48000000
|
||||
eei.power_production = 1
|
||||
|
||||
--surface.create_entity({name = "small-worm-turret", position = {x * -1 + 6, 0}, force = "west"})
|
||||
|
||||
global.map_forces.west.hatchery = e
|
||||
global.map_forces.east.target = e
|
||||
|
||||
local position = {x-2, 0}
|
||||
local f = place_market(surface, position, "east")
|
||||
global.market=f
|
||||
|
||||
local energy_source = {type = "electric", buffer_capacity = "10GJ", usage_priority = "tertiary", input_flow_limit = "1GW", output_flow_limit = "0W", drain="0W"}
|
||||
local eei2 = surface.create_entity({type = "electric-energy-interface", name = "electric-energy-interface", energy_source = energy_source, position = {201,-2}, force = "east"})
|
||||
local ep2 = surface.create_entity({name = "small-electric-pole", position = {200,-5}, force = "east"})
|
||||
|
||||
ep2.destructible=false
|
||||
ep2.minable=false
|
||||
eei2.operable = false
|
||||
eei2.destructible=false
|
||||
eei2.minable=false
|
||||
eei2.electric_buffer_size = 100000000
|
||||
eei2.power_usage = 48000000
|
||||
eei2.power_production = 1
|
||||
--surface.create_entity({name = "small-worm-turret", position = {x - 6, 0}, force = "east"})
|
||||
global.map_forces.east.hatchery = f
|
||||
global.map_forces.west.target = f
|
||||
|
||||
--global.map_forces.east.spawn = {x=137,y=0}
|
||||
--global.map_forces.west.spawn = {x=-137,y=0}
|
||||
|
||||
local area ={{-174,-150},{174,150}}
|
||||
kill_entities_combat_zone(surface, area)
|
||||
|
||||
local te = surface.create_entity({name = "tree-09-red", position = {137,0}, force = "neutral"})
|
||||
local tw = surface.create_entity({name = "tree-04", position = {-137,0}, force = "neutral"})
|
||||
te.minable =false
|
||||
tw.minable = false
|
||||
te.destructible = false
|
||||
tw.destructible = false
|
||||
end
|
||||
|
||||
local function draw_noise_ore_patch(position, name, surface, radius, richness)
|
||||
if not position then return end
|
||||
if not name then return end
|
||||
if not surface then return end
|
||||
if not radius then return end
|
||||
if not richness then return end
|
||||
local seed = game.surfaces[1].map_gen_settings.seed
|
||||
local noise_seed_add = 25000
|
||||
local richness_part = richness / radius
|
||||
for y = radius * -3, radius * 3, 1 do
|
||||
for x = radius * -3, radius * 3, 1 do
|
||||
local pos = {x = x + position.x + 0.5, y = y + position.y + 0.5}
|
||||
local noise_1 = simplex_noise(pos.x * 0.0125, pos.y * 0.0125, seed)
|
||||
local noise_2 = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed + 25000)
|
||||
local noise = noise_1 + noise_2 * 0.12
|
||||
local distance_to_center = math.sqrt(x^2 + y^2)
|
||||
local a = richness - richness_part * distance_to_center
|
||||
if distance_to_center < radius - math.abs(noise * radius * 0.85) and a > 1 then
|
||||
if surface.can_place_entity({name = name, position = pos, amount = a}) then
|
||||
|
||||
surface.create_entity{name = name, position = pos, amount = a}
|
||||
|
||||
local mirror_pos = {x = pos.x * -1, y = pos.y }
|
||||
surface.create_entity{name = name, position = mirror_pos, amount = a}
|
||||
|
||||
for _, e in pairs(surface.find_entities_filtered({position = pos, name = {"wooden-chest", "gun-turret"}})) do
|
||||
e.destroy()
|
||||
end
|
||||
for _, e in pairs(surface.find_entities_filtered({position = mirror_pos, name = {"wooden-chest", "gun-turret"}})) do
|
||||
e.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function first_ore_generate(surface)
|
||||
local area = {{250, -50}, {300, 50}}
|
||||
local ores = {}
|
||||
ores["iron-ore"] = surface.count_entities_filtered({name = "iron-ore", area = area})
|
||||
ores["copper-ore"] = surface.count_entities_filtered({name = "copper-ore", area = area})
|
||||
ores["coal"] = surface.count_entities_filtered({name = "coal", area = area})
|
||||
ores["stone"] = surface.count_entities_filtered({name = "stone", area = area})
|
||||
for ore, ore_count in pairs(ores) do
|
||||
if ore_count < 1000 or ore_count == nil then
|
||||
local pos = {}
|
||||
for a = 1, 32, 1 do
|
||||
pos = {x = math_random(250, 300), y = math_random(-50, 50)}
|
||||
if surface.can_place_entity({name = "coal", position = pos, amount = 1}) then
|
||||
break
|
||||
end
|
||||
end
|
||||
draw_noise_ore_patch(pos, ore, surface, math_random(18, 24), math_random(1500, 2000))
|
||||
end
|
||||
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
|
||||
local offset = 0
|
||||
if x_modifier == -1 then offset = 32 end
|
||||
local mirror_left_top = {x = left_top.x * x_modifier - offset, y = left_top.y}
|
||||
|
||||
source_surface.request_to_generate_chunks(mirror_left_top, 1)
|
||||
source_surface.force_generate_chunk_requests()
|
||||
|
||||
local mirror_area = {{mirror_left_top.x , mirror_left_top.y}, {mirror_left_top.x + 32, mirror_left_top.y + 32}}
|
||||
|
||||
for _, tile in pairs(source_surface.find_tiles_filtered({area = mirror_area})) do
|
||||
surface.set_tiles({{name = tile.name, position = {x = tile.position.x * x_modifier, y = tile.position.y}}}, true)
|
||||
end
|
||||
for _, entity in pairs(source_surface.find_entities_filtered({area = mirror_area})) do
|
||||
if surface.can_place_entity({name = entity.name, position = {x = entity.position.x * x_modifier, y = entity.position.y}}) then
|
||||
entity.clone({position = {x = entity.position.x * x_modifier, y = entity.position.y}, surface = surface, force = "neutral"})
|
||||
end
|
||||
end
|
||||
for _, decorative in pairs(source_surface.find_decoratives_filtered{area = mirror_area}) do
|
||||
surface.create_decoratives{
|
||||
check_collision=false,
|
||||
decoratives={{name = decorative.decorative.name, position = {x = decorative.position.x * x_modifier, y = decorative.position.y}, amount = decorative.amount}}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local function combat_area(event)
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
|
||||
if left_top.y >= 15 then return end
|
||||
if left_top.y < -15 then return end
|
||||
|
||||
local replacement_tile = "landfill"
|
||||
local tile = surface.get_tile({8,0})
|
||||
if tile then replacement_tile = tile.name end
|
||||
|
||||
for _, tile in pairs(surface.find_tiles_filtered({area = event.area})) do
|
||||
-- if tile.name == "water" or tile.name == "deepwater" then
|
||||
-- surface.set_tiles({{name = replacement_tile, position = tile.position}}, true)
|
||||
-- end
|
||||
-- if tile.position.x >= -4 and tile.position.x < 4 then
|
||||
-- surface.set_tiles({{name = "water-shallow", position = tile.position}}, true)
|
||||
-- end
|
||||
end
|
||||
--[[
|
||||
for _, entity in pairs(surface.find_entities_filtered({type = {"resource", "cliff"}, area = event.area})) do
|
||||
entity.destroy()
|
||||
end
|
||||
]]
|
||||
end
|
||||
|
||||
local function is_out_of_map(p)
|
||||
--if math.sqrt((p.x*p.x)+(p.y*p.y))<30 then return end
|
||||
--if math.sqrt((p.x*p.x)+(p.y*p.y))<30 then return end
|
||||
if math.sqrt((p.x+90)*(p.x+90)+(p.y+100)*(p.y+100))<15 then return true end
|
||||
if math.sqrt((p.x+90)*(p.x+90)+(p.y+100)*(p.y+100))<45 and p.y <=-100 then return end
|
||||
if math.sqrt((p.x-30)*(p.x-30)+(p.y+100)*(p.y+100))<15 then return true end
|
||||
if math.sqrt((p.x-30)*(p.x-30)+(p.y+100)*(p.y+100))<45 and p.y <=-100 then return end
|
||||
if math.sqrt((p.x-90)*(p.x-90)+(p.y-100)*(p.y-100))<15 then return true end
|
||||
if math.sqrt((p.x-90)*(p.x-90)+(p.y-100)*(p.y-100))<45 and p.y >=100 then return end
|
||||
if math.sqrt((p.x+30)*(p.x+30)+(p.y-100)*(p.y-100))<15 then return true end
|
||||
if math.sqrt((p.x+30)*(p.x+30)+(p.y-100)*(p.y-100))<45 and p.y >=100 then return end
|
||||
if math.sqrt((p.x+135)*(p.x+135)+(p.y)*(p.y))<30 and p.y >=0 and p.x >= -135 then return end
|
||||
if math.sqrt((p.x-135)*(p.x-135)+(p.y)*(p.y))<30 and p.y <=0 and p.x <= 135 then return end
|
||||
if p.x >= -15 and p.x <= 15 and ( p.y<=100 and p.y >= -100) then return end
|
||||
if p.x >= -75 and p.x <= -45 and ( p.y<=100 and p.y >= -100) then return end
|
||||
if p.x >= 45 and p.x <= 75 and ( p.y<=100 and p.y >= -100) then return end
|
||||
if p.x >= -135 and p.x <= -105 and ( p.y<=0 and p.y >= -100) then return end
|
||||
if p.x >= 105 and p.x <= 135 and ( p.y<=100 and p.y >= 0) then return end
|
||||
if p.x > -105 and p.x <= -75 and ( p.y>=-15 and p.y <= 15) then return true end
|
||||
if p.x >= 75 and p.x < 105 and ( p.y>=-15 and p.y <= 15) then return true end
|
||||
if p.y < 30 and p.y >= -30 and p.x >= 135 then return end
|
||||
if p.y < 30 and p.y >= -30 and p.x <= -135 then return end
|
||||
if p.x * 0.5 >= math_abs(p.y)+50 then return end
|
||||
if p.x * -0.5 > math_abs(p.y)+50 then return end
|
||||
return true
|
||||
end
|
||||
|
||||
local function out_of_map_area(event)
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
|
||||
for x = -1, 32, 1 do
|
||||
for y = -1, 32, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
if is_out_of_map(p) then
|
||||
if (p.x == -137 or p.x == -138 or p.x == -102 or p.x == -103 or p.x == -78 or p.x == -77 or p.x == -42 or p.x == -43 or p.x == -17 or p.x == -18 or p.x == 17 or p.x == 18 or p.x == 42 or p.x == 43 or p.x == 77 or p.x == 78) and (p.y == -32 or p.y == -33 or p.y == -95 or p.y == -96) then
|
||||
surface.set_tiles({{name = "hazard-concrete-right", position = p}}, true)
|
||||
if (p.x == -137 and p.y == -32) and surface.can_place_entity({name="substation", position = {p.x,p.y}, force = 'neutral'}) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -137 and p.y == -95) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -102 and p.y == -32) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -102 and p.y == -95) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -77 and p.y == -32) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -77 and p.y == -95) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -42 and p.y == -32) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -42 and p.y == -95) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -17 and p.y == -32) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -17 and p.y == -95) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 18 and p.y == -32) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 18 and p.y == -95) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 43 and p.y == -32) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 43 and p.y == -95) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 78 and p.y == -32) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 78 and p.y == -95) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
elseif (p.x == 137 or p.x == 138 or p.x == 102 or p.x == 103 or p.x == 78 or p.x == 77 or p.x == 42 or p.x == 43 or p.x == 17 or p.x == 18 or p.x == -17 or p.x == -18 or p.x == -42 or p.x == -43 or p.x == -77 or p.x == -78) and (p.y == 32 or p.y == 33 or p.y == 95 or p.y == 96) then
|
||||
surface.set_tiles({{name = "hazard-concrete-right", position = p}}, true)
|
||||
if (p.x == 138 and p.y == 33) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 138 and p.y == 96) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 103 and p.y == 33) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 103 and p.y == 96) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 78 and p.y == 33) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 78 and p.y == 96) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 43 and p.y == 33) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 43 and p.y == 96) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 18 and p.y == 33) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == 18 and p.y == 96) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -17 and p.y == 33) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -17 and p.y == 96) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -42 and p.y == 33) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -42 and p.y == 96) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -77 and p.y == 33) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
if (p.x == -77 and p.y == 96) then
|
||||
local e = surface.create_entity({name="substation", position = {p.x,p.y}, force = 'neutral'})
|
||||
e.destructible=false
|
||||
e.minable=false
|
||||
end
|
||||
else
|
||||
surface.set_tiles({{name = "out-of-map", position = p}}, true)
|
||||
end
|
||||
else
|
||||
if p.x >=-210 and p.x <=210 then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local replacement_tile = "landfill"
|
||||
if this_tile.name == "water" or this_tile.name == "deepwater" then
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if( p.x ==-135 or p.x == 75 ) and (p.y >= -200 and p.y <= -175 ) then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local replacement_tile = "hazard-concrete-right"
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
if( p.x >=-135 and p.x <= 75 ) and (p.y == -200 or p.y == -175 ) then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local replacement_tile = "hazard-concrete-right"
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
if( p.x >=-15 and p.x <= 15 ) and p.y == -174 then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local replacement_tile = "hazard-concrete-right"
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
if p.x >-135 and p.x < 75 and p.y>-200 and p.y<-175 then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local nb_rand=math.random(3)
|
||||
local replacement_tile = table_tiles[nb_rand]
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
|
||||
|
||||
if( p.x == -75 or p.x == 135 ) and (p.y <= 200 and p.y >= 175 ) then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local replacement_tile = "hazard-concrete-left"
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
if( p.x >=-75 and p.x <= 135 ) and (p.y == 200 or p.y == 175 ) then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local replacement_tile = "hazard-concrete-left"
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
if( p.x >=-15 and p.x <= 15 ) and p.y == 174 then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local replacement_tile = "hazard-concrete-left"
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
if p.x >-75 and p.x < 135 and p.y<200 and p.y>175 then
|
||||
local this_tile = surface.get_tile(p)
|
||||
local nb_rand=math.random(3)
|
||||
local replacement_tile = table_tiles[nb_rand]
|
||||
surface.set_tiles({{name = replacement_tile, position = this_tile.position}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local scrap_vectors = {}
|
||||
for x = -5, 5, 1 do
|
||||
for y = -5, 5, 1 do
|
||||
if math.sqrt(x^2 + y^2) <= 5 then
|
||||
scrap_vectors[#scrap_vectors + 1] = {x, y}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function generate_scrap(event)
|
||||
local distance_to_center = math.sqrt(event.area.left_top.x ^ 2 + event.area.left_top.y ^ 2)
|
||||
|
||||
local worms = event.surface.find_entities_filtered({area = event.area, type = "turret"})
|
||||
if #worms == 0 then return end
|
||||
|
||||
for _, e in pairs(worms) do
|
||||
if math_random(1,2) == 1 then
|
||||
for c = 1, math_random(2,12), 1 do
|
||||
local vector = scrap_vectors[math_random(1, #scrap_vectors)]
|
||||
local position = {e.position.x + vector[1], e.position.y + vector[2]}
|
||||
if e.surface.can_place_entity({name = "mineable-wreckage", position = position, force = "neutral"}) then
|
||||
e.surface.create_entity({name = "mineable-wreckage", position = position, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function on_chunk_generated(event)
|
||||
local source_surface = game.surfaces["mirror_terrain"]
|
||||
if not source_surface then return end
|
||||
if not source_surface.valid then return end
|
||||
if event.surface.index == source_surface.index then return end
|
||||
local left_top = event.area.left_top
|
||||
if left_top.x >= 0 then
|
||||
mirror_chunk(event, source_surface, 1)
|
||||
else
|
||||
mirror_chunk(event, source_surface, -1)
|
||||
end
|
||||
|
||||
out_of_map_area(event)
|
||||
|
||||
if left_top.x >= -150 and left_top.x < 150 then combat_area(event) end
|
||||
if left_top.x == 256 and left_top.y == 256 then
|
||||
create_markets(event.surface)
|
||||
first_ore_generate(event.surface)
|
||||
end
|
||||
if left_top.x <= -500 and left_top.x >= -1500 then
|
||||
local density = -0.003 * left_top.x -0.5
|
||||
local floor_density = math.floor(density)
|
||||
for i = 0, floor_density, 1 do
|
||||
if math.random(100)<=10 then
|
||||
local rand_x = math.random(33)-1
|
||||
local rand_y = math.random(33)-1
|
||||
local pos = {x =left_top.x + rand_x, y = left_top.y + rand_y}
|
||||
--local position = envent.surface.find_non_colliding_position("big-worm-turret", pos, 8, 1)
|
||||
if pos.x * -0.5 > math_abs(pos.y)+50 and event.surface.can_place_entity({name = "small-worm-turret", position = pos, force = "east"}) then
|
||||
event.surface.create_entity({name = "small-worm-turret", position = pos, force = "east"})
|
||||
generate_scrap(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if left_top.x <= -1500 and left_top.x >= -2500 then
|
||||
local density = -0.003 * left_top.x -2.5
|
||||
local floor_density = math.floor(density)
|
||||
for i = 0, floor_density, 1 do
|
||||
if math.random(100)<=10 then
|
||||
local rand_x = math.random(33)-1
|
||||
local rand_y = math.random(33)-1
|
||||
local pos = {x =left_top.x + rand_x, y = left_top.y + rand_y}
|
||||
--local position = envent.surface.find_non_colliding_position("big-worm-turret", pos, 8, 1)
|
||||
if pos.x * -0.5 > math_abs(pos.y)+50 and event.surface.can_place_entity({name = "medium-worm-turret", position = pos, force = "east"}) then
|
||||
event.surface.create_entity({name = "medium-worm-turret", position = pos, force = "east"})
|
||||
generate_scrap(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if left_top.x <= -2500 then
|
||||
local density = -0.003 * left_top.x -5.5
|
||||
local floor_density = math.floor(density)
|
||||
if floor_density > 4 then floor_density = 4 end
|
||||
for i = 0, floor_density, 1 do
|
||||
if math.random(100)<=10 then
|
||||
local rand_x = math.random(33)-1
|
||||
local rand_y = math.random(33)-1
|
||||
local pos = {x =left_top.x + rand_x, y = left_top.y + rand_y}
|
||||
--local position = envent.surface.find_non_colliding_position("big-worm-turret", pos, 8, 1)
|
||||
if pos.x * -0.5 > math_abs(pos.y)+50 and event.surface.can_place_entity({name = "big-worm-turret", position = pos, force = "east"}) then
|
||||
event.surface.create_entity({name = "big-worm-turret", position = pos, force = "east"})
|
||||
generate_scrap(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if left_top.x >= 500 and left_top.x <= 1500 then
|
||||
local density = 0.003 * left_top.x -0.5
|
||||
local floor_density = math.floor(density)
|
||||
for i = 0, floor_density, 1 do
|
||||
if math.random(100)<=10 then
|
||||
local rand_x = math.random(33)-1
|
||||
local rand_y = math.random(33)-1
|
||||
local pos = {x =left_top.x + rand_x, y = left_top.y + rand_y}
|
||||
--local position = envent.surface.find_non_colliding_position("big-worm-turret", pos, 8, 1)
|
||||
if pos.x * 0.5 > math_abs(pos.y)+50 and event.surface.can_place_entity({name = "small-worm-turret", position = pos, force = "west"}) then
|
||||
event.surface.create_entity({name = "small-worm-turret", position = pos, force = "west"})
|
||||
generate_scrap(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if left_top.x >= 1500 and left_top.x <= 2500 then
|
||||
local density = 0.003 * left_top.x -2.5
|
||||
local floor_density = math.floor(density)
|
||||
for i = 0, floor_density, 1 do
|
||||
if math.random(100)<=10 then
|
||||
local rand_x = math.random(33)-1
|
||||
local rand_y = math.random(33)-1
|
||||
local pos = {x =left_top.x + rand_x, y = left_top.y + rand_y}
|
||||
--local position = envent.surface.find_non_colliding_position("big-worm-turret", pos, 8, 1)
|
||||
if pos.x * 0.5 > math_abs(pos.y)+50 and event.surface.can_place_entity({name = "medium-worm-turret", position = pos, force = "west"}) then
|
||||
event.surface.create_entity({name = "medium-worm-turret", position = pos, force = "west"})
|
||||
generate_scrap(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if left_top.x >= 2500 then
|
||||
local density = 0.003 * left_top.x -5.5
|
||||
local floor_density = math.floor(density)
|
||||
if floor_density > 4 then floor_density=4 end
|
||||
for i = 0, floor_density, 1 do
|
||||
if math.random(100)<=10 then
|
||||
local rand_x = math.random(33)-1
|
||||
local rand_y = math.random(33)-1
|
||||
local pos = {x =left_top.x + rand_x, y = left_top.y + rand_y}
|
||||
--local position = envent.surface.find_non_colliding_position("big-worm-turret", pos, 8, 1)
|
||||
if pos.x * 0.5 > math_abs(pos.y)+50 and event.surface.can_place_entity({name = "big-worm-turret", position = pos, force = "west"}) then
|
||||
event.surface.create_entity({name = "big-worm-turret", position = pos, force = "west"})
|
||||
generate_scrap(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if left_top.x > 320 then return end
|
||||
if left_top.x < -320 then return end
|
||||
if left_top.y > 320 then return end
|
||||
if left_top.y < -320 then return end
|
||||
|
||||
game.forces.west.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}})
|
||||
game.forces.east.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}})
|
||||
end
|
||||
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
||||
|
||||
return Public
|
223
maps/native_war/xp.lua
Normal file
223
maps/native_war/xp.lua
Normal file
@ -0,0 +1,223 @@
|
||||
local math_random = math.random
|
||||
local Global = require 'utils.global'
|
||||
local visuals_delay = 1800
|
||||
local level_up_floating_text_color = {0, 205, 0}
|
||||
local xp_floating_text_color = {157, 157, 157}
|
||||
local experience_levels = {0}
|
||||
|
||||
local xp_t = {}
|
||||
local last_built_entities = {}
|
||||
|
||||
Global.register(
|
||||
{xp_t=xp_t},
|
||||
function(tbl)
|
||||
xp_t = tbl.xp_t
|
||||
last_built_entities = tbl.last_built_entities
|
||||
end
|
||||
)
|
||||
|
||||
local Public = {}
|
||||
|
||||
function Public.get_table()
|
||||
return xp_t
|
||||
end
|
||||
function Public.lost_xp(player, amount)
|
||||
xp_t[player.index].xp = xp_t[player.index].xp - amount
|
||||
end
|
||||
local xp_yield = {
|
||||
["behemoth-biter"] = 16,
|
||||
["behemoth-spitter"] = 16,
|
||||
["behemoth-worm-turret"] = 64,
|
||||
["big-biter"] = 8,
|
||||
["big-spitter"] = 8,
|
||||
["big-worm-turret"] = 48,
|
||||
["biter-spawner"] = 64,
|
||||
["character"] = 16,
|
||||
["gun-turret"] = 8,
|
||||
["laser-turret"] = 16,
|
||||
["medium-biter"] = 4,
|
||||
["medium-spitter"] = 4,
|
||||
["medium-worm-turret"] = 32,
|
||||
["small-biter"] = 1,
|
||||
["small-spitter"] = 1,
|
||||
["small-worm-turret"] = 16,
|
||||
["spitter-spawner"] = 64,
|
||||
}
|
||||
|
||||
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
|
||||
end
|
||||
function Public.xp_reset_player(player)
|
||||
if not player.character then
|
||||
player.set_controller({type=defines.controllers.god})
|
||||
player.create_character()
|
||||
end
|
||||
xp_t[player.index] = {
|
||||
xp = 0, points_to_distribute = 0, last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0,
|
||||
rotated_entity_delay = 0, last_mined_entity_position = {x = 0, y = 0},
|
||||
}
|
||||
end
|
||||
|
||||
function Public.xp_reset_all_players()
|
||||
for _, p in pairs(game.players) do
|
||||
rpg_t[p.index] = nil
|
||||
end
|
||||
for _, p in pairs(game.connected_players) do
|
||||
Public.xp_reset_player(p)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
if not event.entity.valid then return end
|
||||
|
||||
--Grant XP for hand placed land mines
|
||||
if event.entity.last_user then
|
||||
if event.entity.type == "land-mine" then
|
||||
if event.cause then
|
||||
if event.cause.valid then
|
||||
if event.cause.force.index == event.entity.force.index then return end
|
||||
end
|
||||
end
|
||||
gain_xp(event.entity.last_user, 1)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if not event.cause then return end
|
||||
if not event.cause.valid then return end
|
||||
if event.cause.force.index == event.entity.force.index then return end
|
||||
if not get_cause_player[event.cause.type] then return end
|
||||
|
||||
local players = get_cause_player[event.cause.type](event.cause)
|
||||
if not players then return end
|
||||
if not players[1] then return end
|
||||
|
||||
--Grant modified XP for health boosted units
|
||||
if global.biter_health_boost then
|
||||
if event.entity.type == "unit" then
|
||||
for _, player in pairs(players) do
|
||||
if xp_yield[event.entity.name] then
|
||||
gain_xp(player, xp_yield[event.entity.name] * global.biter_health_boost)
|
||||
else
|
||||
gain_xp(player, 0.5 * global.biter_health_boost)
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
--Grant normal XP
|
||||
for _, player in pairs(players) do
|
||||
if xp_yield[event.entity.name] then
|
||||
gain_xp(player, xp_yield[event.entity.name])
|
||||
else
|
||||
gain_xp(player, 0.5)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function on_player_repaired_entity(event)
|
||||
if math_random(1, 4) ~= 1 then return end
|
||||
local player = game.players[event.player_index]
|
||||
if not player.character then return end
|
||||
gain_xp(player, 0.40)
|
||||
end
|
||||
|
||||
local function on_player_rotated_entity(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not player.character then return end
|
||||
if xp_t[player.index].rotated_entity_delay > game.tick then return end
|
||||
xp_t[player.index].rotated_entity_delay = game.tick + 20
|
||||
gain_xp(player, 0.20)
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
if math_random(1, 64) ~= 1 then return end
|
||||
local player = game.players[event.player_index]
|
||||
if not player.character then return end
|
||||
if player.character.driving then return end
|
||||
gain_xp(player, 1.0)
|
||||
end
|
||||
|
||||
local building_and_mining_blacklist = {
|
||||
["tile-ghost"] = true,
|
||||
["entity-ghost"] = true,
|
||||
["item-entity"] = true,
|
||||
}
|
||||
|
||||
local function is_replaced_entity(entity)
|
||||
if not last_built_entities[entity.position.x .. "_" .. entity.position.y] then return end
|
||||
for key, tick in pairs(last_built_entities) do
|
||||
if tick < game.tick then last_built_entities[key] = nil end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function on_pre_player_mined_item(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then return end
|
||||
if building_and_mining_blacklist[entity.type] then return end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if is_replaced_entity(entity) then
|
||||
gain_xp(player, -0.1)
|
||||
return
|
||||
end
|
||||
|
||||
if xp_t[player.index].last_mined_entity_position.x == event.entity.position.x and xp_t[player.index].last_mined_entity_position.y == event.entity.position.y then return end
|
||||
xp_t[player.index].last_mined_entity_position.x = entity.position.x
|
||||
xp_t[player.index].last_mined_entity_position.y = entity.position.y
|
||||
if entity.type == "resource" then gain_xp(player, 0.5) return end
|
||||
if entity.force.name == "neutral" then gain_xp(player, 1.5 + event.entity.prototype.max_health * 0.0035) return end
|
||||
gain_xp(player, 0.1 + event.entity.prototype.max_health * 0.0005)
|
||||
end
|
||||
|
||||
local function on_built_entity(event)
|
||||
local created_entity = event.created_entity
|
||||
if not created_entity.valid then return end
|
||||
if building_and_mining_blacklist[created_entity.type] then return end
|
||||
last_built_entities[created_entity.position.x .. "_" .. created_entity.position.y] = game.tick + 1800
|
||||
local player = game.players[event.player_index]
|
||||
gain_xp(player, 0.1)
|
||||
end
|
||||
|
||||
local function on_player_crafted_item(event)
|
||||
if not event.recipe.energy then return end
|
||||
local player = game.players[event.player_index]
|
||||
gain_xp(player, event.recipe.energy * 0.20)
|
||||
end
|
||||
|
||||
local function on_player_respawned(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not xp_t[player.index] then Public.xp_reset_player(player) return end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not xp_t[player.index] then Public.xp_reset_player(player) end
|
||||
end
|
||||
|
||||
local function on_init(event)
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_init(on_init)
|
||||
event.add(defines.events.on_built_entity, on_built_entity)
|
||||
event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
||||
event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
event.add(defines.events.on_player_crafted_item, on_player_crafted_item)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
|
||||
event.add(defines.events.on_player_respawned, on_player_respawned)
|
||||
event.add(defines.events.on_player_rotated_entity, on_player_rotated_entity)
|
||||
event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)
|
||||
|
||||
return Public
|
Loading…
x
Reference in New Issue
Block a user