1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-26 22:56:43 +02:00
This commit is contained in:
MewMew 2019-05-05 16:17:33 +02:00
parent a99bb935cd
commit 554479a106
11 changed files with 464 additions and 0 deletions

View File

@ -0,0 +1,41 @@
-- Mapcodes made by MewMew, Idea and Map-painting by Kyte
-- Coding-Time by MewMew: 24.04.19 from 11am to 5pm = 6+ Hours !!
-- code for reading coordinates ingame: /silent-command game.players[1].print(game.player.selected.position)
require "maps.wave_of_death.intro"
local event = require 'utils.event'
local init = require "maps.wave_of_death.init"
local on_chunk_generated = require "maps.wave_of_death.terrain"
local ai = require "maps.wave_of_death.ai"
local function on_player_joined_game(event)
local player = game.players[event.player_index]
player.teleport({x = -32, y = 0}, player.surface)
--local radius = 256
--game.forces.player.chart(player.surface, {{x = -1 * radius, y = -1 * radius}, {x = radius, y = radius}})
init()
end
local function on_entity_died(event)
if not event.entity.valid then return end
ai.spawn_spread_wave(event)
end
local function on_player_rotated_entity(event)
ai.trigger_new_wave(event)
end
local function on_tick(event)
--if game.tick % 15 ~= 0 then return end
--ai.send_wave_command()
end
event.add(defines.events.on_tick, on_tick)
event.add(defines.events.on_chunk_generated, on_chunk_generated)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_rotated_entity, on_player_rotated_entity)

BIN
maps/wave_of_death/WoD.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

88
maps/wave_of_death/ai.lua Normal file
View File

@ -0,0 +1,88 @@
local biter_waves = require "maps.wave_of_death.biter_waves"
local ai = {}
ai.send_wave_command = function(lane_number)
local surface = game.surfaces["nauvis"]
for _, unit in pairs(global.wod_biters) do
if unit.entity.valid then
if unit.lane_number == lane_number then
unit.entity.set_command({
type = defines.command.attack_area,
destination = global.loaders[lane_number].position,
radius = 32,
distraction = defines.distraction.by_anything,
})
end
end
end
end
ai.spawn_wave = function(surface, lane_number, amount_modifier)
local wave_number = global.wod_lane[lane_number].current_wave
if not biter_waves[wave_number] then wave_number = #biter_waves end
local is_spread_wave = true
if amount_modifier == 1 then is_spread_wave = false end
if not global.loaders[lane_number].valid then return end
local spawn_position = {x = global.loaders[lane_number].position.x, y = global.loaders[lane_number].position.y - 96}
for _, biter_type in pairs(biter_waves[wave_number]) do
for count = 1, math.floor(biter_type.amount * amount_modifier), 1 do
local pos = surface.find_non_colliding_position(biter_type.name, spawn_position, 96, 2)
local biter = surface.create_entity({name = biter_type.name, position = pos, force = "enemy"})
global.wod_biters[biter.unit_number] = {entity = biter, lane_number = lane_number, spread_wave = is_spread_wave}
if not is_spread_wave then
global.wod_lane[lane_number].alive_biters = global.wod_lane[lane_number].alive_biters + 1
end
end
end
if is_spread_wave then return end
global.wod_lane[lane_number].current_wave = global.wod_lane[lane_number].current_wave + 1
end
--on_entity_died event
ai.spawn_spread_wave = function(event)
local entity = event.entity
if not entity.unit_number then return end
if not global.wod_biters[entity.unit_number] then return end
if global.wod_biters[entity.unit_number].spread_wave then global.wod_biters[entity.unit_number] = nil return end
local trigger_lane_number = global.wod_biters[entity.unit_number].lane_number
global.wod_lane[trigger_lane_number].alive_biters = global.wod_lane[trigger_lane_number].alive_biters - 1
if global.wod_lane[trigger_lane_number].alive_biters ~= 0 then return end
for lane_number = 1, 4, 1 do
if lane_number ~= trigger_lane_number then
ai.spawn_wave(entity.surface, lane_number, global.spread_amount_modifier)
ai.send_wave_command(lane_number)
end
end
game.print("Lane #" .. trigger_lane_number .. " has spread biters.")
end
--on_entity_rotated event
ai.trigger_new_wave = function(event)
local entity = event.entity
if entity.name ~= "loader" then return end
local lane_number = tonumber(entity.force.name)
if not global.wod_lane[lane_number] then return end
if global.wod_lane[lane_number].alive_biters > 0 then
entity.force.print("There are " .. global.wod_lane[lane_number].alive_biters .. " spawned biters left.", {r = 180, g = 0, b = 0})
return
end
ai.spawn_wave(entity.surface, lane_number, 1)
ai.send_wave_command(lane_number)
for _, player in pairs(game.connected_players) do
player.play_sound{path="utility/new_objective", volume_modifier=0.3} --dont know if a sound would be annoying in a game with 10 lanes playing ^^ maybe a short sound
end
game.print("Lane #" .. entity.force.name .. " has summoned wave ")
end
return ai

View File

@ -0,0 +1,35 @@
local waves = {
[1] = {{name = "small-biter", amount = 10}},
[2] = {{name = "small-biter", amount = 20}},
[3] = {{name = "small-biter", amount = 40}},
[4] = {{name = "small-biter", amount = 80}, {name = "small-spitter", amount = 10}},
[5] = {{name = "small-biter", amount = 80}, {name = "small-spitter", amount = 20}},
[6] = {{name = "small-biter", amount = 80}, {name = "small-spitter", amount = 40}},
[7] = {{name = "small-biter", amount = 80}, {name = "small-spitter", amount = 80}},
[8] = {{name = "medium-biter", amount = 10}, {name = "small-spitter", amount = 80}},
[9] = {{name = "medium-biter", amount = 20}, {name = "small-spitter", amount = 80}},
[10] = {{name = "medium-biter", amount = 40}, {name = "small-spitter", amount = 80}},
[11] = {{name = "medium-biter", amount = 80}, {name = "small-spitter", amount = 80}},
[12] = {{name = "medium-biter", amount = 80}, {name = "medium-spitter", amount = 10}},
[13] = {{name = "medium-biter", amount = 80}, {name = "medium-spitter", amount = 20}},
[14] = {{name = "medium-biter", amount = 80}, {name = "medium-spitter", amount = 40}},
[15] = {{name = "medium-biter", amount = 80}, {name = "medium-spitter", amount = 80}},
[16] = {{name = "big-biter", amount = 10}, {name = "medium-spitter", amount = 80}},
[17] = {{name = "big-biter", amount = 20}, {name = "medium-spitter", amount = 80}},
[18] = {{name = "big-biter", amount = 40}, {name = "medium-spitter", amount = 80}},
[19] = {{name = "big-biter", amount = 80}, {name = "medium-spitter", amount = 80}},
[20] = {{name = "big-biter", amount = 80}, {name = "big-spitter", amount = 10}},
[21] = {{name = "big-biter", amount = 80}, {name = "big-spitter", amount = 20}},
[22] = {{name = "big-biter", amount = 80}, {name = "big-spitter", amount = 40}},
[23] = {{name = "big-biter", amount = 80}, {name = "big-spitter", amount = 80}},
[24] = {{name = "behemoth-biter", amount = 10}, {name = "big-spitter", amount = 80}},
[25] = {{name = "behemoth-biter", amount = 20}, {name = "big-spitter", amount = 80}},
[26] = {{name = "behemoth-biter", amount = 40}, {name = "big-spitter", amount = 80}},
[27] = {{name = "behemoth-biter", amount = 80}, {name = "big-spitter", amount = 80}},
[28] = {{name = "behemoth-biter", amount = 80}, {name = "behemoth-spitter", amount = 10}},
[29] = {{name = "behemoth-biter", amount = 80}, {name = "behemoth-spitter", amount = 20}},
[30] = {{name = "behemoth-biter", amount = 80}, {name = "behemoth-spitter", amount = 40}},
[31] = {{name = "behemoth-biter", amount = 80}, {name = "behemoth-spitter", amount = 80}}
}
return waves

View File

View File

@ -0,0 +1,77 @@
local function init_surface()
local map_gen_settings = {}
map_gen_settings.water = "0.35"
map_gen_settings.starting_area = "5"
map_gen_settings.cliff_settings = {cliff_elevation_interval = 12, cliff_elevation_0 = 32}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = "3", size = "1.2", richness = "1"},
["stone"] = {frequency = "3", size = "1.2", richness = "1"},
["copper-ore"] = {frequency = "3", size = "1.2", richness = "1"},
["iron-ore"] = {frequency = "3", size = "1.2", richness = "1"},
["uranium-ore"] = {frequency = "2", size = "1", richness = "1"},
["crude-oil"] = {frequency = "3", size = "1.2", richness = "1.5"},
["trees"] = {frequency = "1.25", size = "0.5", richness = "0.65"},
["enemy-base"] = {frequency = "5.5", size = "2", richness = "2"}
}
game.create_surface("wave_of_death", map_gen_settings)
game.map_settings.enemy_evolution.time_factor = 0
game.map_settings.enemy_evolution.destroy_factor = 0
game.map_settings.enemy_evolution.pollution_factor = 0
game.map_settings.pollution.enabled = false
game.map_settings.enemy_expansion.enabled = false
end
local function init_forces()
game.create_force(1)
game.create_force(2)
game.create_force(3)
game.create_force(4)
for _, force in pairs(game.forces) do
if force.name ~= "enemy" then
force.technologies["landfill"].enabled = false
force.technologies["artillery"].enabled = false
force.technologies["artillery-shell-range-1"].enabled = false
force.technologies["artillery-shell-speed-1"].enabled = false
force.technologies["atomic-bomb"].enabled = false
force.set_ammo_damage_modifier("shotgun-shell", 1)
force.research_queue_enabled = true
force.share_chart = true
for _, force_2 in pairs(game.forces) do
if force.name ~= "enemy" then
force.set_friend(force_2.name, true)
end
end
end
end
for i = 1, 4, 1 do
game.forces[i].set_spawn_position({0,0}, game.surfaces["wave_of_death"])
end
end
local function init_globals()
global.spread_amount_modifier = 0.75 --percentage of a cleared wave to spawn at all other teams
--local wave_spawn_y = -128
--local wave_spawn_x = -64
global.wod_lane = {}
global.wod_biters = {}
for i = 1, 4, 1 do
global.wod_lane[i] = {}
global.wod_lane[i].current_wave = 1
global.wod_lane[i].alive_biters = 0
--global.wod_lane[i].wave_spawn_point = {x = wave_spawn_x + (32 * i), y = wave_spawn_y}
--global.wod_lane[i].target = {x = wave_spawn_x + (32 * i), y = wave_spawn_y + 96}
end
end
local function init()
if global.spread_amount_modifier then return end
init_surface()
init_globals()
init_forces()
end
return init

View File

@ -0,0 +1,83 @@
local event = require 'utils.event'
local info = [[
Hello Players,
on this map you battle with your team against up to 3 other teams.
Each team can call its own wave of biters and spitters at any time and they get stronger with each wave.
Each wave, when defeated, sends a percentage of their enemys to all other teams.
To call a wave, you have to rotate the loader under the marketplace.
But remember that you must also be able to defeat the enemy.
Each team has a main building, the marketplace, which is the main target of the biters.
Your task is to defend the main building. If the main building is destroyed, you have lost!
A round is over when only one team has its main building left.
Credits:
Map made by MewMew and Kyte
]]
local function create_map_intro_button(player)
if player.gui.top["map_intro_button"] then return end
local b = player.gui.top.add({type = "sprite-button", caption = "?", name = "map_intro_button", tooltip = "Map Info"})
b.style.font_color = {r = 0.1, g = 0.8, b = 0.1}
b.style.font = "heading-1"
b.style.minimal_height = 38
b.style.minimal_width = 38
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
end
local function create_map_intro(player)
if player.gui.left["map_intro_frame"] then player.gui.left["map_intro_frame"].destroy() end
local frame = player.gui.left.add {type = "frame", name = "map_intro_frame", direction = "vertical"}
local t = frame.add {type = "table", column_count = 1}
local b = frame.add {type = "button", caption = "Close", name = "close_map_intro_frame", align = "right"}
b.style.font = "default"
b.style.minimal_height = 30
b.style.minimal_width = 30
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
local frame = t.add {type = "frame"}
local l = frame.add {type = "label", caption = info}
l.style.single_line = false
l.style.font = "heading-3"
l.style.font_color = {r=0.95, g=0.95, b=0.95}
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
create_map_intro_button(player)
if player.online_time == 0 then
create_map_intro(player)
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]
if event.element.name == "close_map_intro_frame" then player.gui.left["map_intro_frame"].destroy() return end
if event.element.name == "map_intro_button" then
if player.gui.left["map_intro_frame"] then
player.gui.left["map_intro_frame"].destroy()
else
create_map_intro(player)
end
return
end
end
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_gui_click, on_gui_click)

View File

View File

View File

@ -0,0 +1,82 @@
local event = require 'utils.event'
local function set_chunk_coords(radius)
global.chunk_gen_coords = {}
for r = radius, 1, -1 do
for x = r * -1, r - 1, 1 do
local pos = {x = x, y = r * -1}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(global.chunk_gen_coords, pos) end
end
for y = r * -1, r - 1, 1 do
local pos = {x = r, y = y}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(global.chunk_gen_coords, pos) end
end
for x = r, r * -1 + 1, -1 do
local pos = {x = x, y = r}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(global.chunk_gen_coords, pos) end
end
for y = r, r * -1 + 1, -1 do
local pos = {x = r * -1, y = y}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(global.chunk_gen_coords, pos) end
end
end
end
local function draw_gui()
for _, player in pairs(game.connected_players) do
if global.map_generation_complete then
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
else
local caption = "Map is generating... " .. #global.chunk_gen_coords .. " chunks left. Please get comfy."
if player.gui.left["map_pregen"] then
player.gui.left["map_pregen"].caption = caption
else
local frame = player.gui.left.add({
type = "frame",
caption = caption,
name = "map_pregen"
})
frame.style.font_color = {r = 150, g = 100, b = 255}
frame.style.font = "heading-1"
frame.style.maximal_height = 36
end
end
end
end
local function process_chunk()
if global.map_generation_complete then return end
if game.tick < 300 then return end
if not global.chunk_gen_coords then set_chunk_coords(10) end
if #global.chunk_gen_coords == 0 then
global.map_generation_complete = true
draw_gui()
for _, player in pairs(game.connected_players) do
player.play_sound{path="utility/new_objective", volume_modifier=0.75}
end
return
end
if not game then return end
local surface = game.surfaces["wave_of_death"]
if not surface then return end
local force_chunk_requests = 3
for i = #global.chunk_gen_coords, 1, -1 do
if surface.is_chunk_generated(global.chunk_gen_coords[i]) then
global.chunk_gen_coords[i] = nil
else
surface.request_to_generate_chunks({x = (global.chunk_gen_coords[i].x * 32) - 16, y = (global.chunk_gen_coords[i].y * 32) - 16}, 1)
surface.force_generate_chunk_requests()
global.chunk_gen_coords[i] = nil
force_chunk_requests = force_chunk_requests - 1
if force_chunk_requests <= 0 then
break
end
end
end
draw_gui()
end
return process_chunk

View File

@ -0,0 +1,58 @@
local function init(surface, left_top)
if left_top.x ~= 96 then return end
if left_top.y ~= 96 then return end
surface.request_to_generate_chunks({x = 0, y = 0}, 9)
surface.force_generate_chunk_requests()
global.loaders = {}
for i = 1, 4, 1 do
global.loaders[i] = surface.create_entity({name = "loader", position = {x = -240 + 192*(i - 1), y = 0}, force = i})
global.loaders[i].minable = false
end
rendering.draw_sprite({sprite = "file/maps/wave_of_death/WoD.png", target = {32, 0}, surface = game.surfaces.nauvis, orientation = 0, x_scale = 2, y_scale = 2, render_layer = "ground-tile"})
end
local function draw_lanes(surface, left_top)
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local position = {x = left_top.x + x, y = left_top.y + y}
surface.set_tiles({{name = "grass-2", position = position}})
end
end
end
local function draw_void(surface, left_top)
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local position = {x = left_top.x + x, y = left_top.y + y}
surface.set_tiles({{name = "out-of-map", position = position}})
end
end
end
local function clear_chunk(surface, area)
surface.destroy_decoratives{area = area}
for _, e in pairs(surface.find_entities_filtered({area = area})) do
if e.name ~= "character" then
e.destroy()
end
end
end
local function on_chunk_generated(event)
local surface = game.surfaces["nauvis"]
if event.surface.index ~= surface.index then return end
local left_top = event.area.left_top
if left_top.x % 192 < 96 or left_top.x > 256 or left_top.x < - 256 then
draw_void(surface, left_top)
else
clear_chunk(surface, event.area)
draw_lanes(surface, left_top)
end
init(surface, left_top)
end
return on_chunk_generated