1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-24 03:47:58 +02:00

282 lines
8.1 KiB
Lua
Raw Normal View History

2019-09-21 15:01:19 +02:00
--map by mewmew and kyte
2019-09-21 11:47:09 +02:00
require "maps.island_troopers.map_intro"
2019-09-17 20:04:47 +02:00
require "functions.noise_vector_path"
2019-09-20 15:59:43 +02:00
require "modules.shopping_chests"
2019-09-20 22:28:34 +02:00
require "modules.no_turrets"
require "modules.dangerous_goods"
2019-10-12 02:19:37 +02:00
require "modules.rpg"
2019-09-21 11:47:09 +02:00
require "modules.difficulty_vote"
2019-09-20 21:23:20 +02:00
require "maps.island_troopers.enemies"
require "maps.island_troopers.terrain"
2019-09-23 02:40:57 +02:00
max_island_radius = 128
2019-09-20 21:23:20 +02:00
local function create_stage_gui(player)
if player.gui.top.stage_gui then return end
local element = player.gui.top.add({type = "frame", name = "stage_gui", caption = " "})
local style = element.style
style.minimal_height = 38
style.maximal_height = 38
style.minimal_width = 140
style.top_padding = 2
style.left_padding = 4
style.right_padding = 4
style.bottom_padding = 2
style.font_color = {r = 155, g = 85, b = 25}
style.font = "default-large-bold"
end
2019-09-21 11:47:09 +02:00
function update_stage_gui()
2019-10-04 20:38:02 +02:00
if not global.stages then return end
2019-09-20 21:23:20 +02:00
local caption = "Level: " .. global.current_level
2019-09-21 11:47:09 +02:00
caption = caption .. " | Stage: "
2019-09-21 15:01:19 +02:00
local stage = global.current_stage
if stage > #global.stages - 1 then stage = #global.stages - 1 end
caption = caption .. stage
caption = caption .. "/"
caption = caption .. #global.stages - 1
2019-09-21 11:47:09 +02:00
caption = caption .. " | Bugs remaining: "
caption = caption .. global.alive_enemies
2019-09-20 21:23:20 +02:00
for _, player in pairs(game.connected_players) do
if player.gui.top.stage_gui then
player.gui.top.stage_gui.caption = caption
end
end
end
2019-09-17 20:04:47 +02:00
2019-09-20 22:28:34 +02:00
local function bring_players()
local surface = game.surfaces[1]
for _, player in pairs(game.connected_players) do
if player.position.y < -1 then
if player.character then
if player.character.valid then
local p = surface.find_non_colliding_position("character", {0, 2}, 8, 0.5)
if not p then player.teleport({0, 2}, surface) end
player.teleport(p, surface)
end
end
end
end
end
2019-09-21 15:01:19 +02:00
local function drift_corpses_toward_beach()
local surface = game.surfaces[1]
for _, corpse in pairs(surface.find_entities_filtered({name = "character-corpse"})) do
if corpse.position.y < 0 then
if surface.get_tile(corpse.position).collides_with("resource-layer") then
2019-09-23 02:40:57 +02:00
corpse.clone{position={corpse.position.x, corpse.position.y + (math.random(50, 250) * 0.01)}, surface=surface, force=corpse.force.name}
2019-09-21 15:01:19 +02:00
corpse.destroy()
end
end
end
end
2019-09-23 02:40:57 +02:00
local function get_island_size()
local r_min = global.current_level + 16
if r_min > math.floor(max_island_radius * 0.5) then r_min = math.floor(max_island_radius * 0.5) end
local r_max = global.current_level * 2 + 32
2019-09-23 03:09:32 +02:00
if r_max > max_island_radius then r_max = max_island_radius end
2019-09-23 02:40:57 +02:00
return math.random(r_min, r_max)
end
2019-09-18 16:00:52 +02:00
local function set_next_level()
global.alive_enemies = 0
2019-09-20 21:23:20 +02:00
global.alive_boss_enemy_count = 0
2019-09-18 16:00:52 +02:00
2019-09-23 02:40:57 +02:00
global.current_level = global.current_level + 1
2019-09-20 22:28:34 +02:00
if global.current_level > 1 then bring_players() end
2019-09-23 02:40:57 +02:00
global.current_stage = 1
global.stage_amount = math.floor(global.current_level * 0.33) + 3
if global.stage_amount > 9 then global.stage_amount = 9 end
2019-09-18 16:00:52 +02:00
global.path_tiles = nil
2019-09-20 21:23:20 +02:00
2019-09-23 02:40:57 +02:00
local island_size = get_island_size()
2019-09-20 21:23:20 +02:00
2019-09-18 16:00:52 +02:00
global.stages = {}
global.stages[1] = {
2019-09-23 03:09:32 +02:00
path_length = 16 + island_size * 1.5,
2019-09-20 21:23:20 +02:00
size = island_size,
}
2019-09-23 02:40:57 +02:00
for i = 1, global.stage_amount - 1, 1 do
island_size = get_island_size()
2019-09-18 16:00:52 +02:00
global.stages[#global.stages + 1] = {
2019-09-23 03:09:32 +02:00
path_length = 16 + island_size * 1.5,
2019-09-20 21:23:20 +02:00
size = island_size,
2019-09-18 16:00:52 +02:00
}
end
global.stages[#global.stages + 1] = {
2019-09-23 02:40:57 +02:00
path_length = max_island_radius * 7,
2019-09-18 16:00:52 +02:00
size = false,
}
2019-09-21 11:47:09 +02:00
--game.print("Level " .. global.current_level)
update_stage_gui()
2019-09-18 16:00:52 +02:00
global.gamestate = 2
end
2019-09-17 20:04:47 +02:00
2019-09-20 21:23:20 +02:00
local function earn_credits(amount)
2019-09-21 11:47:09 +02:00
for _, player in pairs(game.connected_players) do
2019-09-22 11:13:32 +02:00
player.play_sound{path="utility/armor_insert", volume_modifier=0.85}
2019-09-21 11:47:09 +02:00
end
game.print(amount .. " credits have been transfered to the factory.", {r = 255, g = 215, b = 0})
2019-09-20 21:23:20 +02:00
global.credits = global.credits + amount
end
local function slowmo()
2019-09-21 15:01:19 +02:00
if not global.slowmo then global.slowmo = 0.15 end
2019-09-20 21:23:20 +02:00
game.speed = global.slowmo
global.slowmo = global.slowmo + 0.01
if game.speed < 1 then return end
for _, p in pairs(game.connected_players) do
if p.gui.left["slowmo_cam"] then p.gui.left["slowmo_cam"].destroy() end
end
global.slowmo = nil
global.gamestate = 4
end
2019-09-18 16:00:52 +02:00
local function wait_until_stage_is_beaten()
if global.alive_enemies > 0 then return end
2019-09-21 15:01:19 +02:00
local reward_amount = false
local gamestate = 2
2019-09-23 02:40:57 +02:00
local base_reward = 250 * global.current_level
2019-09-21 15:01:19 +02:00
2019-09-18 16:00:52 +02:00
if global.stages[global.current_stage].size then
2019-09-21 15:01:19 +02:00
if global.current_stage < #global.stages -1 then
2019-09-23 02:40:57 +02:00
reward_amount = base_reward + global.current_stage * global.current_level * 50
2019-09-21 15:01:19 +02:00
else
2019-09-23 02:40:57 +02:00
reward_amount = base_reward + global.current_stage * global.current_level * 150
2019-09-21 15:01:19 +02:00
end
else
game.print("Final Stage complete!")
game.print("Level is collapsing !!", {r = 255, g = 0, b = 0})
gamestate = 5
end
if reward_amount then
earn_credits(reward_amount)
2019-09-21 11:47:09 +02:00
update_stage_gui()
2019-09-18 16:00:52 +02:00
end
2019-09-21 15:01:19 +02:00
global.current_stage = global.current_stage + 1
global.gamestate = gamestate
2019-09-18 16:00:52 +02:00
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
2019-09-20 21:23:20 +02:00
create_stage_gui(player)
if player.gui.left["slowmo_cam"] then player.gui.left["slowmo_cam"].destroy() end
2019-09-23 02:40:57 +02:00
2019-09-29 18:51:47 +02:00
update_stage_gui()
2019-09-23 02:40:57 +02:00
if player.online_time > 0 then return end
2019-09-18 16:00:52 +02:00
player.insert({name = "pistol", count = 1})
player.insert({name = "firearm-magazine", count = 32})
end
2019-09-22 11:13:32 +02:00
2019-09-18 16:00:52 +02:00
local function on_init()
2019-09-26 20:07:19 +02:00
game.create_force("enemy_spawners")
game.forces.enemy_spawners.set_friend("enemy", true)
game.forces.enemy.set_friend("enemy_spawners", true)
2019-09-18 16:00:52 +02:00
local surface = game.surfaces[1]
2019-09-21 11:47:09 +02:00
surface.request_to_generate_chunks({x = 0, y = 0}, 16)
2019-09-18 16:00:52 +02:00
surface.force_generate_chunk_requests()
2019-09-23 02:40:57 +02:00
--global.tree_raffle = {}
--for _, e in pairs(game.entity_prototypes) do
-- if e.type == "tree" then
-- table.insert(global.tree_raffle, e.name)
-- end
--end
local blacklist = {
["dark-mud-decal"] = true,
["sand-dune-decal"] = true,
["light-mud-decal"] = true,
["puberty-decal"] = true,
["sand-decal"] = true,
["red-desert-decal"] = true,
}
global.decorative_names = {}
for k,v in pairs(game.decorative_prototypes) do
if not blacklist[k] then
if v.autoplace_specification then
global.decorative_names[#global.decorative_names+1] = k
end
end
2019-09-21 15:01:19 +02:00
end
2019-09-22 11:13:32 +02:00
global.difficulty_poll_closing_timeout = 3600 * 10
2019-09-18 16:00:52 +02:00
global.level_vectors = {}
2019-09-20 21:23:20 +02:00
global.alive_boss_enemy_entities = {}
2019-09-21 11:47:09 +02:00
global.current_level = 0
2019-09-18 16:00:52 +02:00
global.gamestate = 1
game.forces.player.set_spawn_position({0, 2}, surface)
end
2019-09-20 21:23:20 +02:00
local msg = {
"We got the brainbug!",
"Good job troopers!",
2019-09-21 15:01:19 +02:00
"I'm doing my part!",
2019-09-20 21:23:20 +02:00
}
2019-09-18 16:00:52 +02:00
local function on_entity_died(event)
2019-09-20 21:23:20 +02:00
local entity = event.entity
if not entity.valid then return end
2019-09-26 20:07:19 +02:00
if entity.force.name == "enemy_spawners" then
if entity.type == "unit" then return end
global.alive_enemies = global.alive_enemies - 1
return
end
2019-09-26 20:07:19 +02:00
if entity.force.name ~= "enemy" then return end
2019-09-20 21:23:20 +02:00
global.alive_enemies = global.alive_enemies - 1
2019-09-21 11:47:09 +02:00
update_stage_gui()
2019-09-20 21:23:20 +02:00
if entity.type ~= "unit" then return end
if not global.alive_boss_enemy_entities[entity.unit_number] then return end
2019-09-20 21:23:20 +02:00
global.alive_boss_enemy_entities[entity.unit_number] = nil
global.alive_boss_enemy_count = global.alive_boss_enemy_count - 1
if global.alive_boss_enemy_count == 0 then
for _, p in pairs(game.connected_players) do
if p.gui.left["slowmo_cam"] then p.gui.left["slowmo_cam"].destroy() end
local frame = p.gui.left.add({type = "frame", name = "slowmo_cam", caption = msg[math.random(1, #msg)]})
local camera = frame.add({type = "camera", name = "mini_cam_element", position = entity.position, zoom = 1.5, surface_index = 1})
camera.style.minimal_width = 400
camera.style.minimal_height = 400
end
global.gamestate = 8
end
2019-09-18 16:00:52 +02:00
end
local gamestate_functions = {
[1] = set_next_level,
[2] = draw_path_to_next_stage,
[3] = draw_the_island,
[4] = wait_until_stage_is_beaten,
[5] = kill_the_level,
2019-09-20 21:23:20 +02:00
[8] = slowmo,
2019-09-18 16:00:52 +02:00
}
2019-09-20 21:23:20 +02:00
local function on_tick()
2019-09-21 15:01:19 +02:00
gamestate_functions[global.gamestate]()
2019-09-26 20:07:19 +02:00
if game.tick % 150 == 0 then drift_corpses_toward_beach() end
2019-09-18 16:00:52 +02:00
end
local event = require 'utils.event'
event.on_init(on_init)
event.add(defines.events.on_tick, on_tick)
event.add(defines.events.on_entity_died, on_entity_died)
2019-09-20 21:23:20 +02:00
event.add(defines.events.on_player_joined_game, on_player_joined_game)
require "functions.boss_unit"