mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-11 14:49:24 +02:00
soft reset addition, fixes
This commit is contained in:
parent
639dc4c399
commit
c6a9e4009d
39
functions/omegakaboom.lua
Normal file
39
functions/omegakaboom.lua
Normal file
@ -0,0 +1,39 @@
|
||||
-------requires on_tick_schedule
|
||||
|
||||
local function create_projectile(surface, pos, projectile)
|
||||
surface.create_entity({
|
||||
name = projectile,
|
||||
position = pos,
|
||||
force = "enemy",
|
||||
target = pos,
|
||||
speed = 1
|
||||
})
|
||||
end
|
||||
|
||||
local function omegakaboom(surface, center_pos, projectile, radius, density)
|
||||
local positions = {}
|
||||
for x = radius * -1, radius, 1 do
|
||||
for y = radius * -1, radius, 1 do
|
||||
local pos = {x = center_pos.x + x, y = center_pos.y + y}
|
||||
local distance_to_center = math.ceil(math.sqrt((pos.x - center_pos.x)^2 + (pos.y - center_pos.y)^2))
|
||||
if distance_to_center < radius and math.random(1,100) < density then
|
||||
if not positions[distance_to_center] then positions[distance_to_center] = {} end
|
||||
positions[distance_to_center][#positions[distance_to_center] + 1] = pos
|
||||
end
|
||||
end
|
||||
end
|
||||
if #positions == 0 then return end
|
||||
local t = 1
|
||||
for i1, pos_list in pairs(positions) do
|
||||
for i2, pos in pairs(pos_list) do
|
||||
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
|
||||
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
|
||||
func = create_projectile,
|
||||
args = {surface, pos, projectile}
|
||||
}
|
||||
end
|
||||
t = t + 4
|
||||
end
|
||||
end
|
||||
|
||||
return omegakaboom
|
61
functions/soft_reset.lua
Normal file
61
functions/soft_reset.lua
Normal file
@ -0,0 +1,61 @@
|
||||
local function reset_forces()
|
||||
for _, f in pairs(game.forces) do
|
||||
f.reset()
|
||||
end
|
||||
end
|
||||
|
||||
local function set_spawn_positions(new_surface, old_surface)
|
||||
for _, f in pairs(game.forces) do
|
||||
f.set_spawn_position(f.get_spawn_position(old_surface), new_surface)
|
||||
end
|
||||
end
|
||||
|
||||
local function teleport_players(surface)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local spawn = player.force.get_spawn_position(surface)
|
||||
local chunk = {math.floor(spawn.x / 32), math.floor(spawn.y / 32)}
|
||||
if not surface.is_chunk_generated(chunk) then
|
||||
surface.request_to_generate_chunks(spawn, 2)
|
||||
surface.force_generate_chunk_requests()
|
||||
end
|
||||
local pos = surface.find_non_colliding_position("character", spawn, 1, 0.5)
|
||||
player.teleport(pos, surface)
|
||||
end
|
||||
end
|
||||
|
||||
local function equip_players(player_starting_items)
|
||||
for k, player in pairs(game.connected_players) do
|
||||
if player.character then player.character.destroy() end
|
||||
player.character = nil
|
||||
player.set_controller({type=defines.controllers.god})
|
||||
player.create_character()
|
||||
for item, amount in pairs(player_starting_items) do
|
||||
player.insert({name = item, count = amount})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function soft_reset_map(old_surface, map_gen_settings, player_starting_items)
|
||||
if not global.soft_reset_counter then global.soft_reset_counter = 0 end
|
||||
if not global.original_surface_name then global.original_surface_name = old_surface.name end
|
||||
global.soft_reset_counter = global.soft_reset_counter + 1
|
||||
|
||||
local new_surface = game.create_surface(global.original_surface_name .. "_" .. tostring(global.soft_reset_counter), map_gen_settings)
|
||||
new_surface.request_to_generate_chunks({0,0}, 3)
|
||||
new_surface.force_generate_chunk_requests()
|
||||
|
||||
reset_forces()
|
||||
set_spawn_positions(new_surface, old_surface)
|
||||
teleport_players(new_surface)
|
||||
equip_players(player_starting_items)
|
||||
|
||||
game.delete_surface(old_surface)
|
||||
|
||||
if global.soft_reset_counter > 1 then
|
||||
game.print(">> The world has been reshaped, welcome to " .. global.original_surface_name .. " number " .. tostring(global.soft_reset_counter) .. "!", {r=0.98, g=0.66, b=0.22})
|
||||
else
|
||||
game.print(">> Welcome to " .. global.original_surface_name .. "!", {r=0.98, g=0.66, b=0.22})
|
||||
end
|
||||
|
||||
return new_surface
|
||||
end
|
@ -1,4 +1,5 @@
|
||||
local function create_particles(surface, position, amount)
|
||||
local function create_particles(surface, position, amount)
|
||||
if not surface.valid then return end
|
||||
local math_random = math.random
|
||||
for i = 1, amount, 1 do
|
||||
local m = math_random(6, 12)
|
||||
@ -15,7 +16,8 @@ local function create_particles(surface, position, amount)
|
||||
end
|
||||
end
|
||||
|
||||
local function spawn_biter(surface, position, evolution)
|
||||
local function spawn_biter(surface, position, evolution)
|
||||
if not surface.valid then return end
|
||||
local evo = math.floor(evolution * 1000)
|
||||
|
||||
local biter_chances = {
|
||||
|
@ -1,4 +1,5 @@
|
||||
local function create_particles(surface, position, amount)
|
||||
if not surface.valid then return end
|
||||
local math_random = math.random
|
||||
for i = 1, amount, 1 do
|
||||
local m = math_random(8, 24)
|
||||
@ -16,6 +17,7 @@ local function create_particles(surface, position, amount)
|
||||
end
|
||||
|
||||
local function spawn_worm(surface, position, evolution_index)
|
||||
if not surface.valid then return end
|
||||
local worm_raffle_table = {
|
||||
[1] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret"},
|
||||
[2] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret"},
|
||||
|
@ -2,8 +2,8 @@ local event = require 'utils.event'
|
||||
|
||||
local difficulties = {
|
||||
[1] = {name = "Peaceful", str = "25%", value = 0.25, color = {r=0.00, g=0.45, b=0.00}, print_color = {r=0.00, g=0.9, b=0.00}},
|
||||
[2] = {name = "Easy", str = "50%", value = 0.5, color = {r=0.00, g=0.35, b=0.00}, print_color = {r=0.00, g=0.7, b=0.00}},
|
||||
[3] = {name = "Piece of cake", str = "75%", value = 0.75, color = {r=0.00, g=0.25, b=0.00}, print_color = {r=0.00, g=0.5, b=0.00}},
|
||||
[2] = {name = "Piece of cake", str = "50%", value = 0.5, color = {r=0.00, g=0.35, b=0.00}, print_color = {r=0.00, g=0.7, b=0.00}},
|
||||
[3] = {name = "Easy", str = "75%", value = 0.75, color = {r=0.00, g=0.25, b=0.00}, print_color = {r=0.00, g=0.5, b=0.00}},
|
||||
[4] = {name = "Normal", str = "100%", value = 1, color = {r=0.00, g=0.00, b=0.25}, print_color = {r=0.0, g=0.0, b=0.7}},
|
||||
[5] = {name = "Hard", str = "150%", value = 1.5, color = {r=0.25, g=0.00, b=0.00}, print_color = {r=0.5, g=0.0, b=0.00}},
|
||||
[6] = {name = "Nightmare", str = "200%", value = 2, color = {r=0.35, g=0.00, b=0.00}, print_color = {r=0.7, g=0.0, b=0.00}},
|
||||
|
@ -11,12 +11,15 @@ require "modules.ores_are_mixed"
|
||||
require "modules.surrounded_by_worms"
|
||||
global.average_worm_amount_per_chunk = 1.5
|
||||
require "modules.biters_attack_moving_players"
|
||||
|
||||
require "modules.market_friendly_fire_protection"
|
||||
require "modules.trees_grow"
|
||||
require "modules.trees_randomly_die"
|
||||
|
||||
require "maps.overgrowth_map_info"
|
||||
|
||||
require "functions.soft_reset"
|
||||
local kaboom = require "functions.omegakaboom"
|
||||
|
||||
require "modules.difficulty_vote"
|
||||
|
||||
local unearthing_biters = require "functions.unearthing_biters"
|
||||
@ -44,6 +47,11 @@ local difficulties_votes_evo = {
|
||||
[7] = 0.000064
|
||||
}
|
||||
|
||||
local starting_items = {
|
||||
["pistol"] = 1,
|
||||
["firearm-magazine"] = 8
|
||||
}
|
||||
|
||||
local function create_particles(surface, name, position, amount, cause_position)
|
||||
local math_random = math.random
|
||||
|
||||
@ -75,7 +83,7 @@ end
|
||||
|
||||
local function spawn_market(surface, position)
|
||||
local market = surface.create_entity({name = "market", position = position, force = "neutral"})
|
||||
market.destructible = false
|
||||
--market.destructible = false
|
||||
market.add_market_item({price = {{'coin', 1}}, offer = {type = 'give-item', item = "wood", count = 50}})
|
||||
market.add_market_item({price = {{"coin", 3}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}})
|
||||
market.add_market_item({price = {{"coin", 3}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}})
|
||||
@ -88,6 +96,7 @@ local function spawn_market(surface, position)
|
||||
market.add_market_item({price = {{'coin', 1}}, offer = {type = 'give-item', item = "firearm-magazine", count = 1}})
|
||||
market.add_market_item({price = {{'coin', 16}}, offer = {type = 'give-item', item = "submachine-gun", count = 1}})
|
||||
market.add_market_item({price = {{'coin', 32}}, offer = {type = 'give-item', item = "car", count = 1}})
|
||||
return market
|
||||
end
|
||||
|
||||
local caption_style = {{"font", "default-bold"}, {"font_color",{ r=0.63, g=0.63, b=0.63}}, {"top_padding",2}, {"left_padding",0},{"right_padding",0},{"minimal_width",0}}
|
||||
@ -102,18 +111,56 @@ local function tree_gui()
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local function get_surface_settings()
|
||||
local map_gen_settings = {}
|
||||
map_gen_settings.seed = math_random(1, 1000000)
|
||||
map_gen_settings.water = "2"
|
||||
map_gen_settings.starting_area = "2.5"
|
||||
map_gen_settings.cliff_settings = {cliff_elevation_interval = 38, cliff_elevation_0 = 38}
|
||||
map_gen_settings.autoplace_controls = {
|
||||
["coal"] = {frequency = "2", size = "1", richness = "1"},
|
||||
["stone"] = {frequency = "2", size = "1", richness = "1"},
|
||||
["copper-ore"] = {frequency = "2", size = "1", richness = "1"},
|
||||
["iron-ore"] = {frequency = "2.5", size = "1.1", richness = "1"},
|
||||
["uranium-ore"] = {frequency = "2", size = "1", richness = "1"},
|
||||
["crude-oil"] = {frequency = "3", size = "1", richness = "1.5"},
|
||||
["trees"] = {frequency = "1", size = "1", richness = "0.5"},
|
||||
["enemy-base"] = {frequency = "256", size = "0.61", richness = "1"}
|
||||
}
|
||||
return map_gen_settings
|
||||
end
|
||||
|
||||
function reset_map()
|
||||
global.trees_grow_chunk_next_visit = {}
|
||||
global.trees_grow_chunk_raffle = {}
|
||||
global.trees_grow_chunk_position = {}
|
||||
global.trees_grow_chunks_charted = {}
|
||||
global.trees_grow_chunks_charted_counter = 0
|
||||
|
||||
local surface = game.connected_players[1].surface
|
||||
local surface = soft_reset_map(surface, get_surface_settings(), starting_items)
|
||||
|
||||
reset_difficulty_poll()
|
||||
|
||||
global.trees_defeated = 0
|
||||
tree_gui()
|
||||
|
||||
global.market = spawn_market(surface, {x = 0, y = -8})
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
if player.online_time == 0 then
|
||||
player.insert({name = "pistol", count = 1})
|
||||
player.insert({name = "firearm-magazine", count = 8})
|
||||
for item, amount in pairs(starting_items) do
|
||||
player.insert({name = item, count = amount})
|
||||
end
|
||||
end
|
||||
|
||||
if not global.market then
|
||||
spawn_market(player.surface, {x = 0, y = -8})
|
||||
game.map_settings.enemy_evolution.time_factor = 0.00003
|
||||
global.trees_defeated = 0
|
||||
global.market = true
|
||||
local surface = game.create_surface("overgrowth", get_surface_settings())
|
||||
game.forces["player"].set_spawn_position({x = 0, y = 0}, surface)
|
||||
player.teleport({0,0}, surface)
|
||||
reset_map()
|
||||
end
|
||||
|
||||
tree_gui()
|
||||
@ -121,10 +168,7 @@ end
|
||||
|
||||
local function trap(entity)
|
||||
local r = 8
|
||||
if global.difficulty_vote_index then
|
||||
r = difficulties_votes[global.difficulty_vote_index]
|
||||
game.map_settings.enemy_evolution.time_factor = difficulties_votes_evo[global.difficulty_vote_index]
|
||||
end
|
||||
if global.difficulty_vote_index then r = difficulties_votes[global.difficulty_vote_index] end
|
||||
if math_random(1,r) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,8)) end
|
||||
end
|
||||
|
||||
@ -155,8 +199,57 @@ end
|
||||
|
||||
local function on_entity_died(event)
|
||||
on_player_mined_entity(event)
|
||||
if event.entity == global.market then
|
||||
global.map_reset_timeout = game.tick + 900
|
||||
game.print("The market has been overrun.", {r = 1, g = 0, b = 0})
|
||||
kaboom(event.entity.surface, event.entity.position, "explosive-cannon-projectile", 24, 12)
|
||||
kaboom(event.entity.surface, event.entity.position, "explosive-uranium-cannon-projectile", 24, 12)
|
||||
global.market = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function attack_market()
|
||||
local c = 8
|
||||
if global.difficulty_vote_index then
|
||||
c = global.difficulty_vote_index * 2
|
||||
game.map_settings.enemy_evolution.time_factor = difficulties_votes_evo[global.difficulty_vote_index]
|
||||
end
|
||||
game.connected_players[1].surface.set_multi_command({
|
||||
command={
|
||||
type=defines.command.attack,
|
||||
target=global.market,
|
||||
distraction=defines.distraction.by_enemy
|
||||
},
|
||||
unit_count = math_random(c, c * 2),
|
||||
force = "enemy",
|
||||
unit_search_distance=1024
|
||||
})
|
||||
game.connected_players[1].surface.set_multi_command({
|
||||
command={
|
||||
type=defines.command.attack,
|
||||
target=global.market,
|
||||
distraction=defines.distraction.none
|
||||
},
|
||||
unit_count = math_random(1, c),
|
||||
force = "enemy",
|
||||
unit_search_distance=1024
|
||||
})
|
||||
end
|
||||
|
||||
local function tick()
|
||||
if global.market then
|
||||
if math_random(1, 60) == 1 then
|
||||
attack_market()
|
||||
end
|
||||
return
|
||||
end
|
||||
if not global.map_reset_timeout then return end
|
||||
if game.tick < global.map_reset_timeout then return end
|
||||
reset_map()
|
||||
global.map_reset_timeout = nil
|
||||
end
|
||||
|
||||
event.on_nth_tick(60, tick)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
@ -7,12 +7,14 @@ local info = [[
|
||||
|
||||
Brick and other solid tiles are resistant to the wild growth.
|
||||
Concrete has double the durability of bricks.
|
||||
Refined Concrete has four times the resistance of concrete.
|
||||
Refined Concrete has three times the resistance of concrete.
|
||||
|
||||
For your effort to colonize this overgrown planet,
|
||||
we pay you a coin for each tree you defeat.
|
||||
the Choppy Co. pays you a coin for each tree you defeat.
|
||||
|
||||
Good Luck
|
||||
Also, do not loose the market..
|
||||
|
||||
Good Luck & Much Chop
|
||||
]]
|
||||
|
||||
local function create_map_intro_button(player)
|
||||
|
@ -2,8 +2,8 @@ local event = require 'utils.event'
|
||||
|
||||
local difficulties = {
|
||||
[1] = {name = "Peaceful", value = 0.25, color = {r=0.00, g=0.45, b=0.00}, print_color = {r=0.00, g=0.8, b=0.00}},
|
||||
[2] = {name = "Easy", value = 0.5, color = {r=0.00, g=0.35, b=0.00}, print_color = {r=0.00, g=0.6, b=0.00}},
|
||||
[3] = {name = "Piece of cake", value = 0.75, color = {r=0.00, g=0.25, b=0.00}, print_color = {r=0.00, g=0.4, b=0.00}},
|
||||
[2] = {name = "Piece of cake", value = 0.5, color = {r=0.00, g=0.35, b=0.00}, print_color = {r=0.00, g=0.6, b=0.00}},
|
||||
[3] = {name = "Easy", value = 0.75, color = {r=0.00, g=0.25, b=0.00}, print_color = {r=0.00, g=0.4, b=0.00}},
|
||||
[4] = {name = "Normal", value = 1, color = {r=0.00, g=0.00, b=0.25}, print_color = {r=0.0, g=0.0, b=0.5}},
|
||||
[5] = {name = "Hard", value = 1.5, color = {r=0.25, g=0.00, b=0.00}, print_color = {r=0.4, g=0.0, b=0.00}},
|
||||
[6] = {name = "Nightmare", value = 3, color = {r=0.35, g=0.00, b=0.00}, print_color = {r=0.6, g=0.0, b=0.00}},
|
||||
@ -65,6 +65,18 @@ local function set_difficulty()
|
||||
global.difficulty_vote_value = difficulties[new_index].value
|
||||
end
|
||||
|
||||
function reset_difficulty_poll()
|
||||
global.difficulty_vote_value = 1
|
||||
global.difficulty_vote_index = 4
|
||||
global.difficulty_player_votes = {}
|
||||
global.difficulty_poll_closing_timeout = game.tick + 54000
|
||||
for _, p in pairs(game.connected_players) do
|
||||
if p.gui.center["difficulty_poll"] then p.gui.center["difficulty_poll"].destroy() end
|
||||
poll_difficulty(p)
|
||||
end
|
||||
difficulty_gui()
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
if player.online_time == 0 then
|
||||
|
12
modules/market_friendly_fire_protection.lua
Normal file
12
modules/market_friendly_fire_protection.lua
Normal file
@ -0,0 +1,12 @@
|
||||
local event = require 'utils.event'
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
if event.entity.name ~= "market" then return false end
|
||||
if event.cause then
|
||||
if event.cause.force.name == "enemy" then return false end
|
||||
end
|
||||
event.entity.health = event.entity.health + event.final_damage_amount
|
||||
return true
|
||||
end
|
||||
|
||||
event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
@ -17,9 +17,9 @@ local resistant_tiles = {
|
||||
["concrete"] = 8,
|
||||
["hazard-concrete-left"] = 8,
|
||||
["hazard-concrete-right"] = 8,
|
||||
["refined-concrete"] = 32,
|
||||
["refined-hazard-concrete-left"] = 32,
|
||||
["refined-hazard-concrete-right"] = 32,
|
||||
["refined-concrete"] = 24,
|
||||
["refined-hazard-concrete-left"] = 24,
|
||||
["refined-hazard-concrete-right"] = 24,
|
||||
["stone-path"] = 4
|
||||
}
|
||||
|
||||
@ -110,8 +110,6 @@ local function on_init(event)
|
||||
|
||||
global.trees_grow_chunks_charted = {}
|
||||
global.trees_grow_chunks_charted_counter = 0
|
||||
global.trees_grow_factor = 40
|
||||
global.trees_grow_max_count = 16
|
||||
end
|
||||
|
||||
event.on_init(on_init)
|
||||
|
Loading…
x
Reference in New Issue
Block a user