1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-26 22:56:43 +02:00

new module > area_unlocked_on_rotated_entity

This commit is contained in:
MewMew 2019-03-02 22:40:58 +01:00
parent 5845f958ca
commit 7f0bb9ae83
3 changed files with 94 additions and 6 deletions

View File

@ -13,8 +13,9 @@ require "poll"
require "score"
---- enable modules here ----
--require "maps.tools.cheat_mode"
require "maps.tools.cheat_mode"
--require "maps.modules.hunger"
require "maps.modules.area_unlocked_on_rotated_entity"
--require "maps.modules.fish_respawner"
--require "maps.modules.rocket_launch_always_yields_science"
--require "maps.modules.launch_fish_to_win"
@ -37,7 +38,7 @@ require "score"
--require "maps.labyrinth"
--require "maps.spooky_forest"
--require "maps.nightfall"
require "maps.atoll"
--require "maps.atoll"
--require "maps.tank_battles"
--require "maps.spiral_troopers"
--require "maps.fish_defender"

View File

@ -0,0 +1,87 @@
--unlocks areas when the entity at the position is rotated
--define the entities by position like this:
-- global.level_unlocks = {
-- ["x:0.5 y:0.5"] = {left_top = {x = 0,y = 0}, right_bottom = {x = 50, y = 50}, tile = "dirt-4", unlocked = false},
-- ["x:0.5 y:1.5"] = {left_top = {x = 0,y = 0}, right_bottom = {x = 50, y = 50}, tile = "grass-2", unlocked = false}
-- }
local event = require 'utils.event'
local math_random = math.random
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math_random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
local particles = {"coal-particle", "copper-ore-particle", "iron-ore-particle", "stone-particle"}
local function create_particles(surface, position)
local particle = particles[math_random(1, #particles)]
local m = math_random(10, 30)
local m2 = m * 0.005
for i = 1, 75, 1 do
surface.create_entity({
name = particle,
position = position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
})
end
end
local function on_player_rotated_entity(event)
if not global.level_unlocks then return end
local position_string = "x:" .. tostring(event.entity.position.x)
position_string = position_string .. " y:"
position_string = position_string .. tostring(event.entity.position.y)
if not global.level_unlocks[position_string] then return end
if global.level_unlocks[position_string].unlocked then return end
global.level_unlocks[position_string].unlocked = true
if not global.area_tiles_unlock_schedule then global.area_tiles_unlock_schedule = {} end
local level_unlocked = 0
for _, level in pairs(global.level_unlocks) do
if level.unlocked == true then level_unlocked = level_unlocked + 1 end
end
game.print(game.players[event.player_index].name .. " unlocked the path to Chapter " .. tostring(level_unlocked) .. "!")
for x = global.level_unlocks[position_string].left_top.x, global.level_unlocks[position_string].right_bottom.x, 1 do
for y = global.level_unlocks[position_string].left_top.y, global.level_unlocks[position_string].right_bottom.y, 1 do
global.area_tiles_unlock_schedule[#global.area_tiles_unlock_schedule + 1] = {
surface = event.entity.surface,
tile = {
name = global.level_unlocks[position_string].tile,
position = {x = event.entity.position.x + x, y = event.entity.position.y + y}
}
}
end
end
global.area_tiles_unlock_schedule = shuffle(global.area_tiles_unlock_schedule)
for _, player in pairs(game.connected_players) do
player.play_sound{path="utility/new_objective", volume_modifier=0.4}
end
end
local function on_tick(event)
if not global.area_tiles_unlock_schedule then return end
global.area_tiles_unlock_schedule[#global.area_tiles_unlock_schedule].surface.set_tiles({global.area_tiles_unlock_schedule[#global.area_tiles_unlock_schedule].tile}, true)
create_particles(global.area_tiles_unlock_schedule[#global.area_tiles_unlock_schedule].surface, global.area_tiles_unlock_schedule[#global.area_tiles_unlock_schedule].tile.position)
global.area_tiles_unlock_schedule[#global.area_tiles_unlock_schedule] = nil
if #global.area_tiles_unlock_schedule == 0 then global.area_tiles_unlock_schedule = nil end
end
event.add(defines.events.on_tick, on_tick)
event.add(defines.events.on_player_rotated_entity, on_player_rotated_entity)
--global.area_tiles_unlock_schedule[#global.area_tiles_unlock_schedule].surface.create_entity({name = "blood-explosion-huge", position = global.area_tiles_unlock_schedule[#global.area_tiles_unlock_schedule].tile.position})

View File

@ -566,10 +566,10 @@ local function on_player_joined_game(event)
["crude-oil"] = {frequency = "very-high", size = "very-big", richness = "normal"},
["trees"] = {frequency = "normal", size = "normal", richness = "normal"},
["enemy-base"] = {frequency = "very-high", size = "big", richness = "very-good"},
["grass"] = {frequency = "normal", size = "normal", richness = "normal"},
["sand"] = {frequency = "normal", size = "normal", richness = "normal"},
["desert"] = {frequency = "normal", size = "normal", richness = "normal"},
["dirt"] = {frequency = "normal", size = "normal", richness = "normal"}
--["grass"] = {frequency = "normal", size = "normal", richness = "normal"},
--["sand"] = {frequency = "normal", size = "normal", richness = "normal"},
--["desert"] = {frequency = "normal", size = "normal", richness = "normal"},
--["dirt"] = {frequency = "normal", size = "normal", richness = "normal"}
}
game.create_surface("nightfall", map_gen_settings)
local surface = game.surfaces["nightfall"]